@@ -294,11 +294,25 @@ static void mvebu_pcie_setup_hw(struct mvebu_pcie_port *port)
294294 mvebu_writel (port , mask , PCIE_MASK_OFF );
295295}
296296
297- static int mvebu_pcie_hw_rd_conf (struct mvebu_pcie_port * port ,
298- struct pci_bus * bus ,
299- u32 devfn , int where , int size , u32 * val )
297+ static struct mvebu_pcie_port * mvebu_pcie_find_port (struct mvebu_pcie * pcie ,
298+ struct pci_bus * bus ,
299+ int devfn );
300+
301+ static int mvebu_pcie_child_rd_conf (struct pci_bus * bus , u32 devfn , int where ,
302+ int size , u32 * val )
300303{
301- void __iomem * conf_data = port -> base + PCIE_CONF_DATA_OFF ;
304+ struct mvebu_pcie * pcie = bus -> sysdata ;
305+ struct mvebu_pcie_port * port ;
306+ void __iomem * conf_data ;
307+
308+ port = mvebu_pcie_find_port (pcie , bus , devfn );
309+ if (!port )
310+ return PCIBIOS_DEVICE_NOT_FOUND ;
311+
312+ if (!mvebu_pcie_link_up (port ))
313+ return PCIBIOS_DEVICE_NOT_FOUND ;
314+
315+ conf_data = port -> base + PCIE_CONF_DATA_OFF ;
302316
303317 mvebu_writel (port , PCIE_CONF_ADDR (bus -> number , devfn , where ),
304318 PCIE_CONF_ADDR_OFF );
@@ -314,18 +328,27 @@ static int mvebu_pcie_hw_rd_conf(struct mvebu_pcie_port *port,
314328 * val = readl_relaxed (conf_data );
315329 break ;
316330 default :
317- * val = 0xffffffff ;
318331 return PCIBIOS_BAD_REGISTER_NUMBER ;
319332 }
320333
321334 return PCIBIOS_SUCCESSFUL ;
322335}
323336
324- static int mvebu_pcie_hw_wr_conf (struct mvebu_pcie_port * port ,
325- struct pci_bus * bus ,
326- u32 devfn , int where , int size , u32 val )
337+ static int mvebu_pcie_child_wr_conf (struct pci_bus * bus , u32 devfn ,
338+ int where , int size , u32 val )
327339{
328- void __iomem * conf_data = port -> base + PCIE_CONF_DATA_OFF ;
340+ struct mvebu_pcie * pcie = bus -> sysdata ;
341+ struct mvebu_pcie_port * port ;
342+ void __iomem * conf_data ;
343+
344+ port = mvebu_pcie_find_port (pcie , bus , devfn );
345+ if (!port )
346+ return PCIBIOS_DEVICE_NOT_FOUND ;
347+
348+ if (!mvebu_pcie_link_up (port ))
349+ return PCIBIOS_DEVICE_NOT_FOUND ;
350+
351+ conf_data = port -> base + PCIE_CONF_DATA_OFF ;
329352
330353 mvebu_writel (port , PCIE_CONF_ADDR (bus -> number , devfn , where ),
331354 PCIE_CONF_ADDR_OFF );
@@ -347,6 +370,11 @@ static int mvebu_pcie_hw_wr_conf(struct mvebu_pcie_port *port,
347370 return PCIBIOS_SUCCESSFUL ;
348371}
349372
373+ static struct pci_ops mvebu_pcie_child_ops = {
374+ .read = mvebu_pcie_child_rd_conf ,
375+ .write = mvebu_pcie_child_wr_conf ,
376+ };
377+
350378/*
351379 * Remove windows, starting from the largest ones to the smallest
352380 * ones.
@@ -862,25 +890,12 @@ static int mvebu_pcie_wr_conf(struct pci_bus *bus, u32 devfn,
862890{
863891 struct mvebu_pcie * pcie = bus -> sysdata ;
864892 struct mvebu_pcie_port * port ;
865- int ret ;
866893
867894 port = mvebu_pcie_find_port (pcie , bus , devfn );
868895 if (!port )
869896 return PCIBIOS_DEVICE_NOT_FOUND ;
870897
871- /* Access the emulated PCI-to-PCI bridge */
872- if (bus -> number == 0 )
873- return pci_bridge_emul_conf_write (& port -> bridge , where ,
874- size , val );
875-
876- if (!mvebu_pcie_link_up (port ))
877- return PCIBIOS_DEVICE_NOT_FOUND ;
878-
879- /* Access the real PCIe interface */
880- ret = mvebu_pcie_hw_wr_conf (port , bus , devfn ,
881- where , size , val );
882-
883- return ret ;
898+ return pci_bridge_emul_conf_write (& port -> bridge , where , size , val );
884899}
885900
886901/* PCI configuration space read function */
@@ -889,25 +904,12 @@ static int mvebu_pcie_rd_conf(struct pci_bus *bus, u32 devfn, int where,
889904{
890905 struct mvebu_pcie * pcie = bus -> sysdata ;
891906 struct mvebu_pcie_port * port ;
892- int ret ;
893907
894908 port = mvebu_pcie_find_port (pcie , bus , devfn );
895909 if (!port )
896910 return PCIBIOS_DEVICE_NOT_FOUND ;
897911
898- /* Access the emulated PCI-to-PCI bridge */
899- if (bus -> number == 0 )
900- return pci_bridge_emul_conf_read (& port -> bridge , where ,
901- size , val );
902-
903- if (!mvebu_pcie_link_up (port ))
904- return PCIBIOS_DEVICE_NOT_FOUND ;
905-
906- /* Access the real PCIe interface */
907- ret = mvebu_pcie_hw_rd_conf (port , bus , devfn ,
908- where , size , val );
909-
910- return ret ;
912+ return pci_bridge_emul_conf_read (& port -> bridge , where , size , val );
911913}
912914
913915static struct pci_ops mvebu_pcie_ops = {
@@ -1416,6 +1418,7 @@ static int mvebu_pcie_probe(struct platform_device *pdev)
14161418
14171419 bridge -> sysdata = pcie ;
14181420 bridge -> ops = & mvebu_pcie_ops ;
1421+ bridge -> child_ops = & mvebu_pcie_child_ops ;
14191422 bridge -> align_resource = mvebu_pcie_align_resource ;
14201423 bridge -> map_irq = mvebu_pcie_map_irq ;
14211424
0 commit comments