Message ID | 20200512075950.924-2-rayagonda.kokatanur@broadcom.com |
---|---|
State | Accepted |
Commit | 143eb5b1caf1d2f3f37dd9f2c26936df5949d367 |
Headers | show |
Series | add brcm iproc pcie driver | expand |
Hi Rayagonda, On Tue, 12 May 2020 at 02:00, Rayagonda Kokatanur <rayagonda.kokatanur at broadcom.com> wrote: > > Add api to get dma regions. > > Signed-off-by: Rayagonda Kokatanur <rayagonda.kokatanur at broadcom.com> > --- > drivers/pci/pci-uclass.c | 42 ++++++++++++++++++++++++++++++++++++++++ > include/pci.h | 3 ++- > 2 files changed, 44 insertions(+), 1 deletion(-) > Please can you add a test in test/dm/pci.c > diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c > index 7f46e901fb..f5a87f74a7 100644 > --- a/drivers/pci/pci-uclass.c > +++ b/drivers/pci/pci-uclass.c > @@ -1176,6 +1176,48 @@ ulong pci_conv_size_to_32(ulong old, ulong value, uint offset, > return value; > } > > +int pci_get_dma_regions(struct udevice *dev, struct pci_region *memp, int index) > +{ > + int pci_addr_cells, addr_cells, size_cells; > + int cells_per_record; > + const u32 *prop; > + int len; > + int i = 0; > + > + prop = ofnode_get_property(dev_ofnode(dev), "dma-ranges", &len); dev_read_prop > + if (!prop) { > + log_err("PCI: Device '%s': Cannot decode dma-ranges\n", > + dev->name); > + return -EINVAL; > + } > + > + pci_addr_cells = ofnode_read_simple_addr_cells(dev_ofnode(dev)); > + addr_cells = ofnode_read_simple_addr_cells(dev_ofnode(dev->parent)); > + size_cells = ofnode_read_simple_size_cells(dev_ofnode(dev)); Use dev_... versions > + > + /* PCI addresses are always 3-cells */ > + len /= sizeof(u32); > + cells_per_record = pci_addr_cells + addr_cells + size_cells; > + debug("%s: len=%d, cells_per_record=%d\n", __func__, len, > + cells_per_record); > + > + while (len) { > + memp->bus_start = fdtdec_get_number(prop + 1, 2); > + prop += pci_addr_cells; > + memp->phys_start = fdtdec_get_number(prop, addr_cells); > + prop += addr_cells; > + memp->size = fdtdec_get_number(prop, size_cells); > + prop += size_cells; > + Can you look at how to share code with decode_regions()? > + if (i == index) > + return 0; > + i++; > + len -= cells_per_record; > + } > + > + return -EINVAL; > +} > + > int pci_get_regions(struct udevice *dev, struct pci_region **iop, > struct pci_region **memp, struct pci_region **prefp) > { > diff --git a/include/pci.h b/include/pci.h > index aff56b24f9..bcc699e257 100644 > --- a/include/pci.h > +++ b/include/pci.h > @@ -1297,7 +1297,8 @@ struct udevice *pci_get_controller(struct udevice *dev); > */ > int pci_get_regions(struct udevice *dev, struct pci_region **iop, > struct pci_region **memp, struct pci_region **prefp); > - > +int > +pci_get_dma_regions(struct udevice *dev, struct pci_region *memp, int index); put 'int' on the same line. Also please add a function comment. > /** > * dm_pci_write_bar32() - Write the address of a BAR > * > -- > 2.17.1 > Regards, Simon
On Tue, May 12, 2020 at 01:29:49PM +0530, Rayagonda Kokatanur wrote: > Add api to get dma regions. > > Signed-off-by: Rayagonda Kokatanur <rayagonda.kokatanur@broadcom.com> Applied to u-boot/master, thanks! -- Tom
diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c index 7f46e901fb..f5a87f74a7 100644 --- a/drivers/pci/pci-uclass.c +++ b/drivers/pci/pci-uclass.c @@ -1176,6 +1176,48 @@ ulong pci_conv_size_to_32(ulong old, ulong value, uint offset, return value; } +int pci_get_dma_regions(struct udevice *dev, struct pci_region *memp, int index) +{ + int pci_addr_cells, addr_cells, size_cells; + int cells_per_record; + const u32 *prop; + int len; + int i = 0; + + prop = ofnode_get_property(dev_ofnode(dev), "dma-ranges", &len); + if (!prop) { + log_err("PCI: Device '%s': Cannot decode dma-ranges\n", + dev->name); + return -EINVAL; + } + + pci_addr_cells = ofnode_read_simple_addr_cells(dev_ofnode(dev)); + addr_cells = ofnode_read_simple_addr_cells(dev_ofnode(dev->parent)); + size_cells = ofnode_read_simple_size_cells(dev_ofnode(dev)); + + /* PCI addresses are always 3-cells */ + len /= sizeof(u32); + cells_per_record = pci_addr_cells + addr_cells + size_cells; + debug("%s: len=%d, cells_per_record=%d\n", __func__, len, + cells_per_record); + + while (len) { + memp->bus_start = fdtdec_get_number(prop + 1, 2); + prop += pci_addr_cells; + memp->phys_start = fdtdec_get_number(prop, addr_cells); + prop += addr_cells; + memp->size = fdtdec_get_number(prop, size_cells); + prop += size_cells; + + if (i == index) + return 0; + i++; + len -= cells_per_record; + } + + return -EINVAL; +} + int pci_get_regions(struct udevice *dev, struct pci_region **iop, struct pci_region **memp, struct pci_region **prefp) { diff --git a/include/pci.h b/include/pci.h index aff56b24f9..bcc699e257 100644 --- a/include/pci.h +++ b/include/pci.h @@ -1297,7 +1297,8 @@ struct udevice *pci_get_controller(struct udevice *dev); */ int pci_get_regions(struct udevice *dev, struct pci_region **iop, struct pci_region **memp, struct pci_region **prefp); - +int +pci_get_dma_regions(struct udevice *dev, struct pci_region *memp, int index); /** * dm_pci_write_bar32() - Write the address of a BAR *
Add api to get dma regions. Signed-off-by: Rayagonda Kokatanur <rayagonda.kokatanur at broadcom.com> --- drivers/pci/pci-uclass.c | 42 ++++++++++++++++++++++++++++++++++++++++ include/pci.h | 3 ++- 2 files changed, 44 insertions(+), 1 deletion(-)