@@ -501,6 +501,24 @@ static int tce_setrange_multi_pSeriesLP_walk(unsigned long start_pfn,
501
501
return tce_setrange_multi_pSeriesLP (start_pfn , num_pfn , arg );
502
502
}
503
503
504
+ static void iommu_table_setparms_common (struct iommu_table * tbl , unsigned long busno ,
505
+ unsigned long liobn , unsigned long win_addr ,
506
+ unsigned long window_size , unsigned long page_shift ,
507
+ void * base , struct iommu_table_ops * table_ops )
508
+ {
509
+ tbl -> it_busno = busno ;
510
+ tbl -> it_index = liobn ;
511
+ tbl -> it_offset = win_addr >> page_shift ;
512
+ tbl -> it_size = window_size >> page_shift ;
513
+ tbl -> it_page_shift = page_shift ;
514
+ tbl -> it_base = (unsigned long )base ;
515
+ tbl -> it_blocksize = 16 ;
516
+ tbl -> it_type = TCE_PCI ;
517
+ tbl -> it_ops = table_ops ;
518
+ }
519
+
520
+ struct iommu_table_ops iommu_table_pseries_ops ;
521
+
504
522
static void iommu_table_setparms (struct pci_controller * phb ,
505
523
struct device_node * dn ,
506
524
struct iommu_table * tbl )
@@ -509,8 +527,13 @@ static void iommu_table_setparms(struct pci_controller *phb,
509
527
const unsigned long * basep ;
510
528
const u32 * sizep ;
511
529
512
- node = phb -> dn ;
530
+ /* Test if we are going over 2GB of DMA space */
531
+ if (phb -> dma_window_base_cur + phb -> dma_window_size > SZ_2G ) {
532
+ udbg_printf ("PCI_DMA: Unexpected number of IOAs under this PHB.\n" );
533
+ panic ("PCI_DMA: Unexpected number of IOAs under this PHB.\n" );
534
+ }
513
535
536
+ node = phb -> dn ;
514
537
basep = of_get_property (node , "linux,tce-base" , NULL );
515
538
sizep = of_get_property (node , "linux,tce-size" , NULL );
516
539
if (basep == NULL || sizep == NULL ) {
@@ -519,33 +542,18 @@ static void iommu_table_setparms(struct pci_controller *phb,
519
542
return ;
520
543
}
521
544
522
- tbl -> it_base = (unsigned long )__va (* basep );
545
+ iommu_table_setparms_common (tbl , phb -> bus -> number , 0 , phb -> dma_window_base_cur ,
546
+ phb -> dma_window_size , IOMMU_PAGE_SHIFT_4K ,
547
+ __va (* basep ), & iommu_table_pseries_ops );
523
548
524
549
if (!is_kdump_kernel ())
525
550
memset ((void * )tbl -> it_base , 0 , * sizep );
526
551
527
- tbl -> it_busno = phb -> bus -> number ;
528
- tbl -> it_page_shift = IOMMU_PAGE_SHIFT_4K ;
529
-
530
- /* Units of tce entries */
531
- tbl -> it_offset = phb -> dma_window_base_cur >> tbl -> it_page_shift ;
532
-
533
- /* Test if we are going over 2GB of DMA space */
534
- if (phb -> dma_window_base_cur + phb -> dma_window_size > 0x80000000ul ) {
535
- udbg_printf ("PCI_DMA: Unexpected number of IOAs under this PHB.\n" );
536
- panic ("PCI_DMA: Unexpected number of IOAs under this PHB.\n" );
537
- }
538
-
539
552
phb -> dma_window_base_cur += phb -> dma_window_size ;
540
-
541
- /* Set the tce table size - measured in entries */
542
- tbl -> it_size = phb -> dma_window_size >> tbl -> it_page_shift ;
543
-
544
- tbl -> it_index = 0 ;
545
- tbl -> it_blocksize = 16 ;
546
- tbl -> it_type = TCE_PCI ;
547
553
}
548
554
555
+ struct iommu_table_ops iommu_table_lpar_multi_ops ;
556
+
549
557
/*
550
558
* iommu_table_setparms_lpar
551
559
*
@@ -557,17 +565,13 @@ static void iommu_table_setparms_lpar(struct pci_controller *phb,
557
565
struct iommu_table_group * table_group ,
558
566
const __be32 * dma_window )
559
567
{
560
- unsigned long offset , size ;
568
+ unsigned long offset , size , liobn ;
561
569
562
- of_parse_dma_window (dn , dma_window , & tbl -> it_index , & offset , & size );
570
+ of_parse_dma_window (dn , dma_window , & liobn , & offset , & size );
571
+
572
+ iommu_table_setparms_common (tbl , phb -> bus -> number , liobn , offset , size , IOMMU_PAGE_SHIFT_4K , NULL ,
573
+ & iommu_table_lpar_multi_ops );
563
574
564
- tbl -> it_busno = phb -> bus -> number ;
565
- tbl -> it_page_shift = IOMMU_PAGE_SHIFT_4K ;
566
- tbl -> it_base = 0 ;
567
- tbl -> it_blocksize = 16 ;
568
- tbl -> it_type = TCE_PCI ;
569
- tbl -> it_offset = offset >> tbl -> it_page_shift ;
570
- tbl -> it_size = size >> tbl -> it_page_shift ;
571
575
572
576
table_group -> tce32_start = offset ;
573
577
table_group -> tce32_size = size ;
@@ -647,7 +651,7 @@ static void pci_dma_bus_setup_pSeries(struct pci_bus *bus)
647
651
tbl = pci -> table_group -> tables [0 ];
648
652
649
653
iommu_table_setparms (pci -> phb , dn , tbl );
650
- tbl -> it_ops = & iommu_table_pseries_ops ;
654
+
651
655
if (!iommu_init_table (tbl , pci -> phb -> node , 0 , 0 ))
652
656
panic ("Failed to initialize iommu table" );
653
657
@@ -730,7 +734,7 @@ static void pci_dma_bus_setup_pSeriesLP(struct pci_bus *bus)
730
734
tbl = ppci -> table_group -> tables [0 ];
731
735
iommu_table_setparms_lpar (ppci -> phb , pdn , tbl ,
732
736
ppci -> table_group , dma_window );
733
- tbl -> it_ops = & iommu_table_lpar_multi_ops ;
737
+
734
738
if (!iommu_init_table (tbl , ppci -> phb -> node , 0 , 0 ))
735
739
panic ("Failed to initialize iommu table" );
736
740
iommu_register_group (ppci -> table_group ,
@@ -760,7 +764,7 @@ static void pci_dma_dev_setup_pSeries(struct pci_dev *dev)
760
764
PCI_DN (dn )-> table_group = iommu_pseries_alloc_group (phb -> node );
761
765
tbl = PCI_DN (dn )-> table_group -> tables [0 ];
762
766
iommu_table_setparms (phb , dn , tbl );
763
- tbl -> it_ops = & iommu_table_pseries_ops ;
767
+
764
768
if (!iommu_init_table (tbl , phb -> node , 0 , 0 ))
765
769
panic ("Failed to initialize iommu table" );
766
770
@@ -1461,7 +1465,7 @@ static void pci_dma_dev_setup_pSeriesLP(struct pci_dev *dev)
1461
1465
tbl = pci -> table_group -> tables [0 ];
1462
1466
iommu_table_setparms_lpar (pci -> phb , pdn , tbl ,
1463
1467
pci -> table_group , dma_window );
1464
- tbl -> it_ops = & iommu_table_lpar_multi_ops ;
1468
+
1465
1469
iommu_init_table (tbl , pci -> phb -> node , 0 , 0 );
1466
1470
iommu_register_group (pci -> table_group ,
1467
1471
pci_domain_nr (pci -> phb -> bus ), 0 );
0 commit comments