PCI: mvebu: allocate ports with pcie struct
Subsystems (3)
PATCH 1/1 PCI: mvebu: allocate ports with pcie struct
Use a flexible array member to combine allocations and simplify slightly.
Add __counted_by for extra runtime analysis.
Needed to move mvebu_pcie struct below others as flexible array members require full definitions.
--- drivers/pci/controller/pci-mvebu.c | 33 ++++++++++++------------------ 1 file changed, 13 insertions(+), 20 deletions(-)
drivers/pci/controller/pci-mvebu.c +13 -20
@@ -78,18 +78,6 @@#define PCIE_DEBUG_CTRL 0x1a60#define PCIE_DEBUG_SOFT_RESET BIT(20) -struct mvebu_pcie_port ; - -/* Structure representing all PCIe interfaces */ -struct mvebu_pcie { -struct platform_device *pdev; -struct mvebu_pcie_port *ports; -struct resource io; -struct resource realio; -struct resource mem; -int nports; -}; -struct mvebu_pcie_window {phys_addr_t base;phys_addr_t remap;
@@ -125,6 +113,16 @@ struct mvebu_pcie_port {int intx_irq; }; +/* Structure representing all PCIe interfaces */ +struct mvebu_pcie { +struct platform_device *pdev; +struct resource io; +struct resource realio; +struct resource mem; +int nports; + struct mvebu_pcie_port ports[] __counted_by(nports); +}; +static inline void mvebu_writel (struct mvebu_pcie_port *port,u32 val,u32 reg) {writel (val, port->base + reg);
@@ -1455,11 +1453,13 @@ static int mvebu_pcie_probe(struct platform_device *pdev)struct device_node *child;int num, i, ret; - bridge =devm_pci_alloc_host_bridge (dev,sizeof (struct mvebu_pcie )); + num =of_get_available_child_count (np); + bridge =devm_pci_alloc_host_bridge (dev,struct_size (pcie, ports, num));if (!bridge)return -ENOMEM ; pcie =pci_host_bridge_priv (bridge); + pcie->nports = num; pcie->pdev = pdev;platform_set_drvdata (pdev, pcie);
@@ -1467,12 +1467,6 @@ static int mvebu_pcie_probe(struct platform_device *pdev)if (ret)return ret; - num =of_get_available_child_count (np); - - pcie->ports =devm_kcalloc (dev, num,sizeof (*pcie->ports),GFP_KERNEL ); -if (!pcie->ports) -return -ENOMEM ; - i =0 ;for_each_available_child_of_node (np, child) {struct mvebu_pcie_port *port = &pcie->ports[i];
@@ -1488,7 +1482,6 @@ static int mvebu_pcie_probe(struct platform_device *pdev) port->dn = child; i++; } - pcie->nports = i;for (i =0 ; i < pcie->nports; i++) {struct mvebu_pcie_port *port = &pcie->ports[i];
Signature · 1 line
2.53.0
Manivannan Sadhasivam
maintainerQuoted 82 lines · Rosen Penev
Use a flexible array member to combine allocations and simplify slightly.
Add
__counted_byfor extra runtime analysis.Needed to move
mvebu_pciestruct below others as flexible array members require full definitions.Signed-off-by Rosen Penev <[email protected]>--- drivers/pci/controller/pci-mvebu.c | 33 ++++++++++++------------------ 1 file changed, 13 insertions(+), 20 deletions(-)drivers/pci/controller/pci-mvebu.c +13
-19@@ -78,18 +78,6 @@#define PCIE_DEBUG_CTRL 0x1a60#define PCIE_DEBUG_SOFT_RESET BIT(20) -struct mvebu_pcie_port ; - -/* Structure representing all PCIe interfaces */ -struct mvebu_pcie { -struct platform_device *pdev; -struct mvebu_pcie_port *ports; -struct resource io; -struct resource realio; -struct resource mem; -int nports; -}; -struct mvebu_pcie_window {phys_addr_t base;phys_addr_t remap;@@ -125,6 +113,16 @@ struct mvebu_pcie_port {int intx_irq; }; +/* Structure representing all PCIe interfaces */ +struct mvebu_pcie { +struct platform_device *pdev; +struct resource io; +struct resource realio; +struct resource mem; +int nports; + struct mvebu_pcie_port ports[] __counted_by(nports); +}; +static inline void mvebu_writel (struct mvebu_pcie_port *port,u32 val,u32 reg) {writel (val, port->base + reg);@@ -1455,11 +1453,13 @@ static int mvebu_pcie_probe(struct platform_device *pdev)struct device_node *child;int num, i, ret; - bridge =devm_pci_alloc_host_bridge (dev,sizeof (struct mvebu_pcie )); + num =of_get_available_child_count (np); + bridge =devm_pci_alloc_host_bridge (dev,struct_size (pcie, ports, num));if (!bridge)return -ENOMEM ; pcie =pci_host_bridge_priv (bridge); + pcie->nports = num; pcie->pdev = pdev;platform_set_drvdata (pdev, pcie);@@ -1467,12 +1467,6 @@ static int mvebu_pcie_probe(struct platform_device *pdev)if (ret)return ret; - num =of_get_available_child_count (np); - - pcie->ports =devm_kcalloc (dev, num,sizeof (*pcie->ports),GFP_KERNEL ); -if (!pcie->ports) -return -ENOMEM ; - i =0 ;for_each_available_child_of_node (np, child) {struct mvebu_pcie_port *port = &pcie->ports[i];
drivers/pci/controller/pci-mvebu.c static int mvebu_pcie_probe(struct platform_device *pdev) · line 1491
Quoted 4 lines
drivers/pci/controller/pci-mvebu.c +0
-1@@ -1488,7 +1482,6 @@ static int mvebu_pcie_probe(struct platform_device *pdev) port->dn = child; i++; } - pcie->nports = i;
So now, nports stays with of_get_available_child_count()?
- Mani
Signature · 1 line
மணிவண்ணன் சதாசிவம்
Quoted 74 lines · Manivannan Sadhasivam
Quoted 72 lines · Rosen Penev
Use a flexible array member to combine allocations and simplify slightly.
Add
__counted_byfor extra runtime analysis.Needed to move
mvebu_pciestruct below others as flexible array members require full definitions.Signed-off-by Rosen Penev <[email protected]>--- drivers/pci/controller/pci-mvebu.c | 33 ++++++++++++------------------ 1 file changed, 13 insertions(+), 20 deletions(-)drivers/pci/controller/pci-mvebu.c +13
-13@@ -78,18 +78,6 @@#define PCIE_DEBUG_CTRL 0x1a60#define PCIE_DEBUG_SOFT_RESET BIT(20) -struct mvebu_pcie_port ; - -/* Structure representing all PCIe interfaces */ -struct mvebu_pcie { -struct platform_device *pdev; -struct mvebu_pcie_port *ports; -struct resource io; -struct resource realio; -struct resource mem; -int nports; -}; -struct mvebu_pcie_window {phys_addr_t base;phys_addr_t remap;@@ -125,6 +113,16 @@ struct mvebu_pcie_port {int intx_irq; }; +/* Structure representing all PCIe interfaces */ +struct mvebu_pcie { +struct platform_device *pdev; +struct resource io; +struct resource realio; +struct resource mem; +int nports; + struct mvebu_pcie_port ports[] __counted_by(nports); +}; +static inline void mvebu_writel (struct mvebu_pcie_port *port,u32 val,u32 reg) {writel (val, port->base + reg);@@ -1455,11 +1453,13 @@ static int mvebu_pcie_probe(struct platform_device *pdev)struct device_node *child;int num, i, ret; - bridge =devm_pci_alloc_host_bridge (dev,sizeof (struct mvebu_pcie )); + num =of_get_available_child_count (np); + bridge =devm_pci_alloc_host_bridge (dev,struct_size (pcie, ports, num));if (!bridge)return -ENOMEM ; pcie =pci_host_bridge_priv (bridge); + pcie->nports = num; pcie->pdev = pdev;platform_set_drvdata (pdev, pcie);@@ -1467,12 +1467,6 @@ static int mvebu_pcie_probe(struct platform_device *pdev)if (ret)return ret;
Quoted 16 lines
Quoted 10 lines
drivers/pci/controller/pci-mvebu.c +0
-6- num =of_get_available_child_count (np); - - pcie->ports =devm_kcalloc (dev, num,sizeof (*pcie->ports),GFP_KERNEL ); -if (!pcie->ports) -return -ENOMEM ; - i =0 ;for_each_available_child_of_node (np, child) {struct mvebu_pcie_port *port = &pcie->ports[i];drivers/pci/controller/pci-mvebu.c static int mvebu_pcie_probe(struct platform_device *pdev) · line 1491
Quoted 4 lines
drivers/pci/controller/pci-mvebu.c +0
-1@@ -1488,7 +1482,6 @@ static int mvebu_pcie_probe(struct platform_device *pdev) port->dn = child; i++; } - pcie->nports = i;So now, nports stays with
of_get_available_child_count()?
yes.
Quoted 5 lines
- Mani
--
மணிவண்ணன் சதாசிவம்
Manivannan Sadhasivam
maintainerQuoted 91 lines · Rosen Penev
Quoted 74 lines · Manivannan Sadhasivam
Quoted 72 lines · Rosen Penev
Use a flexible array member to combine allocations and simplify slightly.
Add
__counted_byfor extra runtime analysis.Needed to move
mvebu_pciestruct below others as flexible array members require full definitions.Signed-off-by Rosen Penev <[email protected]>--- drivers/pci/controller/pci-mvebu.c | 33 ++++++++++++------------------ 1 file changed, 13 insertions(+), 20 deletions(-)drivers/pci/controller/pci-mvebu.c +13
-13@@ -78,18 +78,6 @@#define PCIE_DEBUG_CTRL 0x1a60#define PCIE_DEBUG_SOFT_RESET BIT(20) -struct mvebu_pcie_port ; - -/* Structure representing all PCIe interfaces */ -struct mvebu_pcie { -struct platform_device *pdev; -struct mvebu_pcie_port *ports; -struct resource io; -struct resource realio; -struct resource mem; -int nports; -}; -struct mvebu_pcie_window {phys_addr_t base;phys_addr_t remap;@@ -125,6 +113,16 @@ struct mvebu_pcie_port {int intx_irq; }; +/* Structure representing all PCIe interfaces */ +struct mvebu_pcie { +struct platform_device *pdev; +struct resource io; +struct resource realio; +struct resource mem; +int nports; + struct mvebu_pcie_port ports[] __counted_by(nports); +}; +static inline void mvebu_writel (struct mvebu_pcie_port *port,u32 val,u32 reg) {writel (val, port->base + reg);@@ -1455,11 +1453,13 @@ static int mvebu_pcie_probe(struct platform_device *pdev)struct device_node *child;int num, i, ret; - bridge =devm_pci_alloc_host_bridge (dev,sizeof (struct mvebu_pcie )); + num =of_get_available_child_count (np); + bridge =devm_pci_alloc_host_bridge (dev,struct_size (pcie, ports, num));if (!bridge)return -ENOMEM ; pcie =pci_host_bridge_priv (bridge); + pcie->nports = num; pcie->pdev = pdev;platform_set_drvdata (pdev, pcie);@@ -1467,12 +1467,6 @@ static int mvebu_pcie_probe(struct platform_device *pdev)if (ret)return ret;Quoted 16 lines
Quoted 10 lines
drivers/pci/controller/pci-mvebu.c +0
-6- num =of_get_available_child_count (np); - - pcie->ports =devm_kcalloc (dev, num,sizeof (*pcie->ports),GFP_KERNEL ); -if (!pcie->ports) -return -ENOMEM ; - i =0 ;for_each_available_child_of_node (np, child) {struct mvebu_pcie_port *port = &pcie->ports[i];drivers/pci/controller/pci-mvebu.c static int mvebu_pcie_probe(struct platform_device *pdev) · line 1491
Quoted 4 lines
drivers/pci/controller/pci-mvebu.c +0
-1@@ -1488,7 +1482,6 @@ static int mvebu_pcie_probe(struct platform_device *pdev) port->dn = child; i++; } - pcie->nports = i;So now, nports stays with
of_get_available_child_count()?
Quoted 1 line
yes.
But do you really want to configure disabled ports as well? I wouldn't want to do that.
- Mani
Signature · 1 line
மணிவண்ணன் சதாசிவம்
Quoted 93 lines · Manivannan Sadhasivam
Quoted 91 lines · Rosen Penev
Quoted 90 lines · Manivannan Sadhasivam
Quoted 82 lines · Rosen Penev
Use a flexible array member to combine allocations and simplify slightly.
Add
__counted_byfor extra runtime analysis.Needed to move
mvebu_pciestruct below others as flexible array members require full definitions.Signed-off-by Rosen Penev <[email protected]>--- drivers/pci/controller/pci-mvebu.c | 33 ++++++++++++------------------ 1 file changed, 13 insertions(+), 20 deletions(-)drivers/pci/controller/pci-mvebu.c +13
-19@@ -78,18 +78,6 @@#define PCIE_DEBUG_CTRL 0x1a60#define PCIE_DEBUG_SOFT_RESET BIT(20) -struct mvebu_pcie_port ; - -/* Structure representing all PCIe interfaces */ -struct mvebu_pcie { -struct platform_device *pdev; -struct mvebu_pcie_port *ports; -struct resource io; -struct resource realio; -struct resource mem; -int nports; -}; -struct mvebu_pcie_window {phys_addr_t base;phys_addr_t remap;@@ -125,6 +113,16 @@ struct mvebu_pcie_port {int intx_irq; }; +/* Structure representing all PCIe interfaces */ +struct mvebu_pcie { +struct platform_device *pdev; +struct resource io; +struct resource realio; +struct resource mem; +int nports; + struct mvebu_pcie_port ports[] __counted_by(nports); +}; +static inline void mvebu_writel (struct mvebu_pcie_port *port,u32 val,u32 reg) {writel (val, port->base + reg);@@ -1455,11 +1453,13 @@ static int mvebu_pcie_probe(struct platform_device *pdev)struct device_node *child;int num, i, ret; - bridge =devm_pci_alloc_host_bridge (dev,sizeof (struct mvebu_pcie )); + num =of_get_available_child_count (np); + bridge =devm_pci_alloc_host_bridge (dev,struct_size (pcie, ports, num));if (!bridge)return -ENOMEM ; pcie =pci_host_bridge_priv (bridge); + pcie->nports = num; pcie->pdev = pdev;platform_set_drvdata (pdev, pcie);@@ -1467,12 +1467,6 @@ static int mvebu_pcie_probe(struct platform_device *pdev)if (ret)return ret; - num =of_get_available_child_count (np); - - pcie->ports =devm_kcalloc (dev, num,sizeof (*pcie->ports),GFP_KERNEL ); -if (!pcie->ports) -return -ENOMEM ; - i =0 ;for_each_available_child_of_node (np, child) {struct mvebu_pcie_port *port = &pcie->ports[i];drivers/pci/controller/pci-mvebu.c static int mvebu_pcie_probe(struct platform_device *pdev) · line 1491
Quoted 4 lines
drivers/pci/controller/pci-mvebu.c +0
-1@@ -1488,7 +1482,6 @@ static int mvebu_pcie_probe(struct platform_device *pdev) port->dn = child; i++; } - pcie->nports = i;So now, nports stays with
of_get_available_child_count()?
Quoted 4 lines
Quoted 1 line
yes.
But do you really want to configure disabled ports as well? I wouldn't want to do that.
Wait this calls of_get_available_child_count and for_each_available_child_of_node. disabled nodes are not handled.
Quoted 5 lines
- Mani
--
மணிவண்ணன் சதாசிவம்
Manivannan Sadhasivam
maintainerQuoted 94 lines · Rosen Penev
Quoted 93 lines · Manivannan Sadhasivam
Quoted 91 lines · Rosen Penev
Quoted 90 lines · Manivannan Sadhasivam
Quoted 82 lines · Rosen Penev
Use a flexible array member to combine allocations and simplify slightly.
Add
__counted_byfor extra runtime analysis.Needed to move
mvebu_pciestruct below others as flexible array members require full definitions.Signed-off-by Rosen Penev <[email protected]>--- drivers/pci/controller/pci-mvebu.c | 33 ++++++++++++------------------ 1 file changed, 13 insertions(+), 20 deletions(-)drivers/pci/controller/pci-mvebu.c +13
-19@@ -78,18 +78,6 @@#define PCIE_DEBUG_CTRL 0x1a60#define PCIE_DEBUG_SOFT_RESET BIT(20) -struct mvebu_pcie_port ; - -/* Structure representing all PCIe interfaces */ -struct mvebu_pcie { -struct platform_device *pdev; -struct mvebu_pcie_port *ports; -struct resource io; -struct resource realio; -struct resource mem; -int nports; -}; -struct mvebu_pcie_window {phys_addr_t base;phys_addr_t remap;@@ -125,6 +113,16 @@ struct mvebu_pcie_port {int intx_irq; }; +/* Structure representing all PCIe interfaces */ +struct mvebu_pcie { +struct platform_device *pdev; +struct resource io; +struct resource realio; +struct resource mem; +int nports; + struct mvebu_pcie_port ports[] __counted_by(nports); +}; +static inline void mvebu_writel (struct mvebu_pcie_port *port,u32 val,u32 reg) {writel (val, port->base + reg);@@ -1455,11 +1453,13 @@ static int mvebu_pcie_probe(struct platform_device *pdev)struct device_node *child;int num, i, ret; - bridge =devm_pci_alloc_host_bridge (dev,sizeof (struct mvebu_pcie )); + num =of_get_available_child_count (np); + bridge =devm_pci_alloc_host_bridge (dev,struct_size (pcie, ports, num));if (!bridge)return -ENOMEM ; pcie =pci_host_bridge_priv (bridge); + pcie->nports = num; pcie->pdev = pdev;platform_set_drvdata (pdev, pcie);@@ -1467,12 +1467,6 @@ static int mvebu_pcie_probe(struct platform_device *pdev)if (ret)return ret; - num =of_get_available_child_count (np); - - pcie->ports =devm_kcalloc (dev, num,sizeof (*pcie->ports),GFP_KERNEL ); -if (!pcie->ports) -return -ENOMEM ; - i =0 ;for_each_available_child_of_node (np, child) {struct mvebu_pcie_port *port = &pcie->ports[i];drivers/pci/controller/pci-mvebu.c static int mvebu_pcie_probe(struct platform_device *pdev) · line 1491
Quoted 4 lines
drivers/pci/controller/pci-mvebu.c +0
-1@@ -1488,7 +1482,6 @@ static int mvebu_pcie_probe(struct platform_device *pdev) port->dn = child; i++; } - pcie->nports = i;So now, nports stays with
of_get_available_child_count()?
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
yes.
But do you really want to configure disabled ports as well? I wouldn't want to do that.
Wait this calls
of_get_available_child_countandfor_each_available_child_of_node. disabled nodes are not handled.
What I meant was, previously when mvebu_pcie_parse_port() returned 0, that port was skipped from further configurations. But with this logic of reusing of_get_available_child_count(), that will no longer happen and the driver will attempt to configure any failed ports as well.
- Mani
Signature · 1 line
மணிவண்ணன் சதாசிவம்