69
69
#define PCIE_ATU_FUNC (x ) (((x) & 0x7) << 16)
70
70
#define PCIE_ATU_UPPER_TARGET 0x91C
71
71
72
- static struct hw_pci dw_pci ;
73
-
74
- static unsigned long global_io_offset ;
75
-
76
- static inline struct pcie_port * sys_to_pcie (struct pci_sys_data * sys )
77
- {
78
- BUG_ON (!sys -> private_data );
79
-
80
- return sys -> private_data ;
81
- }
72
+ static struct pci_ops dw_pcie_ops ;
82
73
83
74
int dw_pcie_cfg_read (void __iomem * addr , int size , u32 * val )
84
75
{
@@ -267,7 +258,7 @@ static void dw_pcie_msi_set_irq(struct pcie_port *pp, int irq)
267
258
static int assign_irq (int no_irqs , struct msi_desc * desc , int * pos )
268
259
{
269
260
int irq , pos0 , i ;
270
- struct pcie_port * pp = sys_to_pcie ( msi_desc_to_pci_sysdata (desc ) );
261
+ struct pcie_port * pp = ( struct pcie_port * ) msi_desc_to_pci_sysdata (desc );
271
262
272
263
pos0 = bitmap_find_free_region (pp -> msi_irq_in_use , MAX_MSI_IRQS ,
273
264
order_base_2 (no_irqs ));
@@ -333,7 +324,7 @@ static int dw_msi_setup_irq(struct msi_controller *chip, struct pci_dev *pdev,
333
324
struct msi_desc * desc )
334
325
{
335
326
int irq , pos ;
336
- struct pcie_port * pp = sys_to_pcie ( pdev -> bus -> sysdata ) ;
327
+ struct pcie_port * pp = pdev -> bus -> sysdata ;
337
328
338
329
if (desc -> msi_attrib .is_msix )
339
330
return - EINVAL ;
@@ -353,7 +344,7 @@ static int dw_msi_setup_irqs(struct msi_controller *chip, struct pci_dev *pdev,
353
344
#ifdef CONFIG_PCI_MSI
354
345
int irq , pos ;
355
346
struct msi_desc * desc ;
356
- struct pcie_port * pp = sys_to_pcie ( pdev -> bus -> sysdata ) ;
347
+ struct pcie_port * pp = pdev -> bus -> sysdata ;
357
348
358
349
/* MSI-X interrupts are not supported */
359
350
if (type == PCI_CAP_ID_MSIX )
@@ -378,7 +369,7 @@ static void dw_msi_teardown_irq(struct msi_controller *chip, unsigned int irq)
378
369
{
379
370
struct irq_data * data = irq_get_irq_data (irq );
380
371
struct msi_desc * msi = irq_data_get_msi_desc (data );
381
- struct pcie_port * pp = sys_to_pcie ( msi_desc_to_pci_sysdata (msi ) );
372
+ struct pcie_port * pp = ( struct pcie_port * ) msi_desc_to_pci_sysdata (msi );
382
373
383
374
clear_irq_range (pp , irq , 1 , data -> hwirq );
384
375
}
@@ -414,6 +405,7 @@ int dw_pcie_host_init(struct pcie_port *pp)
414
405
{
415
406
struct device_node * np = pp -> dev -> of_node ;
416
407
struct platform_device * pdev = to_platform_device (pp -> dev );
408
+ struct pci_bus * bus , * child ;
417
409
struct resource * cfg_res ;
418
410
u32 val ;
419
411
int i , ret ;
@@ -442,14 +434,13 @@ int dw_pcie_host_init(struct pcie_port *pp)
442
434
pp -> io -> name = "I/O" ;
443
435
pp -> io_size = resource_size (pp -> io );
444
436
pp -> io_bus_addr = pp -> io -> start - win -> offset ;
445
- pp -> io -> start = max_t ( resource_size_t , PCIBIOS_MIN_IO ,
446
- pp -> io_bus_addr +
447
- global_io_offset );
448
- pp -> io -> end = min_t ( resource_size_t , IO_SPACE_LIMIT ,
449
- pp -> io_bus_addr + pp -> io_size +
450
- global_io_offset - 1 );
437
+ ret = pci_remap_iospace ( pp -> io , pp -> io_base );
438
+ if ( ret ) {
439
+ dev_warn ( pp -> dev , "error %d: failed to map resource %pR\n" ,
440
+ ret , pp -> io );
441
+ continue ;
442
+ }
451
443
pp -> io_base = pp -> io -> start ;
452
- pp -> io_base_tmp = pp -> io -> start ;
453
444
break ;
454
445
case IORESOURCE_MEM :
455
446
pp -> mem = win -> res ;
@@ -541,15 +532,35 @@ int dw_pcie_host_init(struct pcie_port *pp)
541
532
val |= PORT_LOGIC_SPEED_CHANGE ;
542
533
dw_pcie_wr_own_conf (pp , PCIE_LINK_WIDTH_SPEED_CONTROL , 4 , val );
543
534
544
- #ifdef CONFIG_PCI_MSI
545
- dw_pcie_msi_chip .dev = pp -> dev ;
535
+ pp -> root_bus_nr = pp -> busn -> start ;
536
+ if (IS_ENABLED (CONFIG_PCI_MSI )) {
537
+ bus = pci_scan_root_bus_msi (pp -> dev , pp -> root_bus_nr ,
538
+ & dw_pcie_ops , pp , & res ,
539
+ & dw_pcie_msi_chip );
540
+ dw_pcie_msi_chip .dev = pp -> dev ;
541
+ } else
542
+ bus = pci_scan_root_bus (pp -> dev , pp -> root_bus_nr , & dw_pcie_ops ,
543
+ pp , & res );
544
+ if (!bus )
545
+ return - ENOMEM ;
546
+
547
+ if (pp -> ops -> scan_bus )
548
+ pp -> ops -> scan_bus (pp );
549
+
550
+ #ifdef CONFIG_ARM
551
+ /* support old dtbs that incorrectly describe IRQs */
552
+ pci_fixup_irqs (pci_common_swizzle , of_irq_parse_and_map_pci );
546
553
#endif
547
554
548
- dw_pci .nr_controllers = 1 ;
549
- dw_pci .private_data = (void * * )& pp ;
555
+ if (!pci_has_flag (PCI_PROBE_ONLY )) {
556
+ pci_bus_size_bridges (bus );
557
+ pci_bus_assign_resources (bus );
550
558
551
- pci_common_init_dev (pp -> dev , & dw_pci );
559
+ list_for_each_entry (child , & bus -> children , node )
560
+ pcie_bus_configure_settings (child );
561
+ }
552
562
563
+ pci_bus_add_devices (bus );
553
564
return 0 ;
554
565
}
555
566
@@ -647,7 +658,7 @@ static int dw_pcie_valid_config(struct pcie_port *pp,
647
658
static int dw_pcie_rd_conf (struct pci_bus * bus , u32 devfn , int where ,
648
659
int size , u32 * val )
649
660
{
650
- struct pcie_port * pp = sys_to_pcie ( bus -> sysdata ) ;
661
+ struct pcie_port * pp = bus -> sysdata ;
651
662
int ret ;
652
663
653
664
if (dw_pcie_valid_config (pp , bus , PCI_SLOT (devfn )) == 0 ) {
@@ -671,7 +682,7 @@ static int dw_pcie_rd_conf(struct pci_bus *bus, u32 devfn, int where,
671
682
static int dw_pcie_wr_conf (struct pci_bus * bus , u32 devfn ,
672
683
int where , int size , u32 val )
673
684
{
674
- struct pcie_port * pp = sys_to_pcie ( bus -> sysdata ) ;
685
+ struct pcie_port * pp = bus -> sysdata ;
675
686
int ret ;
676
687
677
688
if (dw_pcie_valid_config (pp , bus , PCI_SLOT (devfn )) == 0 )
@@ -695,69 +706,6 @@ static struct pci_ops dw_pcie_ops = {
695
706
.write = dw_pcie_wr_conf ,
696
707
};
697
708
698
- static int dw_pcie_setup (int nr , struct pci_sys_data * sys )
699
- {
700
- struct pcie_port * pp ;
701
-
702
- pp = sys_to_pcie (sys );
703
-
704
- if (global_io_offset < SZ_1M && pp -> io_size > 0 ) {
705
- sys -> io_offset = global_io_offset - pp -> io_bus_addr ;
706
- pci_ioremap_io (global_io_offset , pp -> io_base_tmp );
707
- global_io_offset += SZ_64K ;
708
- pci_add_resource_offset (& sys -> resources , pp -> io ,
709
- sys -> io_offset );
710
- }
711
-
712
- sys -> mem_offset = pp -> mem -> start - pp -> mem_bus_addr ;
713
- pci_add_resource_offset (& sys -> resources , pp -> mem , sys -> mem_offset );
714
- pci_add_resource (& sys -> resources , pp -> busn );
715
-
716
- return 1 ;
717
- }
718
-
719
- static struct pci_bus * dw_pcie_scan_bus (int nr , struct pci_sys_data * sys )
720
- {
721
- struct pci_bus * bus ;
722
- struct pcie_port * pp = sys_to_pcie (sys );
723
-
724
- pp -> root_bus_nr = sys -> busnr ;
725
-
726
- if (IS_ENABLED (CONFIG_PCI_MSI ))
727
- bus = pci_scan_root_bus_msi (pp -> dev , sys -> busnr , & dw_pcie_ops ,
728
- sys , & sys -> resources ,
729
- & dw_pcie_msi_chip );
730
- else
731
- bus = pci_scan_root_bus (pp -> dev , sys -> busnr , & dw_pcie_ops ,
732
- sys , & sys -> resources );
733
-
734
- if (!bus )
735
- return NULL ;
736
-
737
- if (bus && pp -> ops -> scan_bus )
738
- pp -> ops -> scan_bus (pp );
739
-
740
- return bus ;
741
- }
742
-
743
- static int dw_pcie_map_irq (const struct pci_dev * dev , u8 slot , u8 pin )
744
- {
745
- struct pcie_port * pp = sys_to_pcie (dev -> bus -> sysdata );
746
- int irq ;
747
-
748
- irq = of_irq_parse_and_map_pci (dev , slot , pin );
749
- if (!irq )
750
- irq = pp -> irq ;
751
-
752
- return irq ;
753
- }
754
-
755
- static struct hw_pci dw_pci = {
756
- .setup = dw_pcie_setup ,
757
- .scan = dw_pcie_scan_bus ,
758
- .map_irq = dw_pcie_map_irq ,
759
- };
760
-
761
709
void dw_pcie_setup_rc (struct pcie_port * pp )
762
710
{
763
711
u32 val ;
0 commit comments