17
17
#include <linux/mutex.h>
18
18
#include <linux/random.h>
19
19
#include <linux/slab.h>
20
+ #include <linux/uaccess.h>
20
21
#include <linux/pci.h>
21
22
#include <linux/pci_ids.h>
22
23
52
53
#define STATUS_SRC_ADDR_INVALID BIT(7)
53
54
#define STATUS_DST_ADDR_INVALID BIT(8)
54
55
56
+ #define PCI_ENDPOINT_TEST_STATUS 0x8
55
57
#define PCI_ENDPOINT_TEST_LOWER_SRC_ADDR 0x0c
56
58
#define PCI_ENDPOINT_TEST_UPPER_SRC_ADDR 0x10
57
59
64
66
#define PCI_ENDPOINT_TEST_IRQ_TYPE 0x24
65
67
#define PCI_ENDPOINT_TEST_IRQ_NUMBER 0x28
66
68
69
+ #define PCI_ENDPOINT_TEST_FLAGS 0x2c
70
+ #define FLAG_USE_DMA BIT(0)
71
+
67
72
#define PCI_DEVICE_ID_TI_AM654 0xb00c
68
73
69
74
#define is_am654_pci_dev (pdev ) \
@@ -315,11 +320,16 @@ static bool pci_endpoint_test_msi_irq(struct pci_endpoint_test *test,
315
320
return false;
316
321
}
317
322
318
- static bool pci_endpoint_test_copy (struct pci_endpoint_test * test , size_t size )
323
+ static bool pci_endpoint_test_copy (struct pci_endpoint_test * test ,
324
+ unsigned long arg )
319
325
{
326
+ struct pci_endpoint_test_xfer_param param ;
320
327
bool ret = false;
321
328
void * src_addr ;
322
329
void * dst_addr ;
330
+ u32 flags = 0 ;
331
+ bool use_dma ;
332
+ size_t size ;
323
333
dma_addr_t src_phys_addr ;
324
334
dma_addr_t dst_phys_addr ;
325
335
struct pci_dev * pdev = test -> pdev ;
@@ -332,10 +342,22 @@ static bool pci_endpoint_test_copy(struct pci_endpoint_test *test, size_t size)
332
342
size_t alignment = test -> alignment ;
333
343
u32 src_crc32 ;
334
344
u32 dst_crc32 ;
345
+ int err ;
346
+
347
+ err = copy_from_user (& param , (void __user * )arg , sizeof (param ));
348
+ if (err ) {
349
+ dev_err (dev , "Failed to get transfer param\n" );
350
+ return false;
351
+ }
335
352
353
+ size = param .size ;
336
354
if (size > SIZE_MAX - alignment )
337
355
goto err ;
338
356
357
+ use_dma = !!(param .flags & PCITEST_FLAGS_USE_DMA );
358
+ if (use_dma )
359
+ flags |= FLAG_USE_DMA ;
360
+
339
361
if (irq_type < IRQ_TYPE_LEGACY || irq_type > IRQ_TYPE_MSIX ) {
340
362
dev_err (dev , "Invalid IRQ type option\n" );
341
363
goto err ;
@@ -406,6 +428,7 @@ static bool pci_endpoint_test_copy(struct pci_endpoint_test *test, size_t size)
406
428
pci_endpoint_test_writel (test , PCI_ENDPOINT_TEST_SIZE ,
407
429
size );
408
430
431
+ pci_endpoint_test_writel (test , PCI_ENDPOINT_TEST_FLAGS , flags );
409
432
pci_endpoint_test_writel (test , PCI_ENDPOINT_TEST_IRQ_TYPE , irq_type );
410
433
pci_endpoint_test_writel (test , PCI_ENDPOINT_TEST_IRQ_NUMBER , 1 );
411
434
pci_endpoint_test_writel (test , PCI_ENDPOINT_TEST_COMMAND ,
@@ -434,9 +457,13 @@ static bool pci_endpoint_test_copy(struct pci_endpoint_test *test, size_t size)
434
457
return ret ;
435
458
}
436
459
437
- static bool pci_endpoint_test_write (struct pci_endpoint_test * test , size_t size )
460
+ static bool pci_endpoint_test_write (struct pci_endpoint_test * test ,
461
+ unsigned long arg )
438
462
{
463
+ struct pci_endpoint_test_xfer_param param ;
439
464
bool ret = false;
465
+ u32 flags = 0 ;
466
+ bool use_dma ;
440
467
u32 reg ;
441
468
void * addr ;
442
469
dma_addr_t phys_addr ;
@@ -446,11 +473,24 @@ static bool pci_endpoint_test_write(struct pci_endpoint_test *test, size_t size)
446
473
dma_addr_t orig_phys_addr ;
447
474
size_t offset ;
448
475
size_t alignment = test -> alignment ;
476
+ size_t size ;
449
477
u32 crc32 ;
478
+ int err ;
450
479
480
+ err = copy_from_user (& param , (void __user * )arg , sizeof (param ));
481
+ if (err != 0 ) {
482
+ dev_err (dev , "Failed to get transfer param\n" );
483
+ return false;
484
+ }
485
+
486
+ size = param .size ;
451
487
if (size > SIZE_MAX - alignment )
452
488
goto err ;
453
489
490
+ use_dma = !!(param .flags & PCITEST_FLAGS_USE_DMA );
491
+ if (use_dma )
492
+ flags |= FLAG_USE_DMA ;
493
+
454
494
if (irq_type < IRQ_TYPE_LEGACY || irq_type > IRQ_TYPE_MSIX ) {
455
495
dev_err (dev , "Invalid IRQ type option\n" );
456
496
goto err ;
@@ -493,6 +533,7 @@ static bool pci_endpoint_test_write(struct pci_endpoint_test *test, size_t size)
493
533
494
534
pci_endpoint_test_writel (test , PCI_ENDPOINT_TEST_SIZE , size );
495
535
536
+ pci_endpoint_test_writel (test , PCI_ENDPOINT_TEST_FLAGS , flags );
496
537
pci_endpoint_test_writel (test , PCI_ENDPOINT_TEST_IRQ_TYPE , irq_type );
497
538
pci_endpoint_test_writel (test , PCI_ENDPOINT_TEST_IRQ_NUMBER , 1 );
498
539
pci_endpoint_test_writel (test , PCI_ENDPOINT_TEST_COMMAND ,
@@ -514,9 +555,14 @@ static bool pci_endpoint_test_write(struct pci_endpoint_test *test, size_t size)
514
555
return ret ;
515
556
}
516
557
517
- static bool pci_endpoint_test_read (struct pci_endpoint_test * test , size_t size )
558
+ static bool pci_endpoint_test_read (struct pci_endpoint_test * test ,
559
+ unsigned long arg )
518
560
{
561
+ struct pci_endpoint_test_xfer_param param ;
519
562
bool ret = false;
563
+ u32 flags = 0 ;
564
+ bool use_dma ;
565
+ size_t size ;
520
566
void * addr ;
521
567
dma_addr_t phys_addr ;
522
568
struct pci_dev * pdev = test -> pdev ;
@@ -526,10 +572,22 @@ static bool pci_endpoint_test_read(struct pci_endpoint_test *test, size_t size)
526
572
size_t offset ;
527
573
size_t alignment = test -> alignment ;
528
574
u32 crc32 ;
575
+ int err ;
529
576
577
+ err = copy_from_user (& param , (void __user * )arg , sizeof (param ));
578
+ if (err ) {
579
+ dev_err (dev , "Failed to get transfer param\n" );
580
+ return false;
581
+ }
582
+
583
+ size = param .size ;
530
584
if (size > SIZE_MAX - alignment )
531
585
goto err ;
532
586
587
+ use_dma = !!(param .flags & PCITEST_FLAGS_USE_DMA );
588
+ if (use_dma )
589
+ flags |= FLAG_USE_DMA ;
590
+
533
591
if (irq_type < IRQ_TYPE_LEGACY || irq_type > IRQ_TYPE_MSIX ) {
534
592
dev_err (dev , "Invalid IRQ type option\n" );
535
593
goto err ;
@@ -566,6 +624,7 @@ static bool pci_endpoint_test_read(struct pci_endpoint_test *test, size_t size)
566
624
567
625
pci_endpoint_test_writel (test , PCI_ENDPOINT_TEST_SIZE , size );
568
626
627
+ pci_endpoint_test_writel (test , PCI_ENDPOINT_TEST_FLAGS , flags );
569
628
pci_endpoint_test_writel (test , PCI_ENDPOINT_TEST_IRQ_TYPE , irq_type );
570
629
pci_endpoint_test_writel (test , PCI_ENDPOINT_TEST_IRQ_NUMBER , 1 );
571
630
pci_endpoint_test_writel (test , PCI_ENDPOINT_TEST_COMMAND ,
0 commit comments