All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vladimir Olovyannikov <vladimir.olovyannikov@broadcom.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 3/3] drivers: pci: pci-uclass: Get PCI dma regions support
Date: Fri, 22 Nov 2019 14:23:23 -0800	[thread overview]
Message-ID: <20191122222323.28898-4-vladimir.olovyannikov@broadcom.com> (raw)
In-Reply-To: <20191122222323.28898-1-vladimir.olovyannikov@broadcom.com>

From: Srinath Mannam <srinath.mannam@broadcom.com>

Add API to parse dma-regions given in PCIe host controller
DT node.

Signed-off-by: Srinath Mannam <srinath.mannam@broadcom.com>
Signed-off-by: Vladimir Olovyannikov <vladimir.olovyannikov@broadcom.com>
---
 drivers/pci/pci-uclass.c | 41 ++++++++++++++++++++++++++++++++++++++++
 include/pci.h            |  2 ++
 2 files changed, 43 insertions(+)

diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c
index eb7a01fd55..ddc2d5cf2c 100644
--- a/drivers/pci/pci-uclass.c
+++ b/drivers/pci/pci-uclass.c
@@ -1166,6 +1166,47 @@ 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) {
+		dev_err(dev, "%s: Cannot decode dma-ranges\n", __func__);
+		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 ff59ac0e69..ef55f54ea5 100644
--- a/include/pci.h
+++ b/include/pci.h
@@ -1284,6 +1284,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
  *
-- 
2.17.1

  parent reply	other threads:[~2019-11-22 22:23 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-22 22:23 [U-Boot] [PATCH 0/3] Introduce APIs for multi PCIe host controller platforms Vladimir Olovyannikov
2019-11-22 22:23 ` [U-Boot] [PATCH 1/3] drivers: pci: Fix Host bridge bus number issue Vladimir Olovyannikov
2019-11-23 12:54   ` Bin Meng
2019-11-22 22:23 ` [U-Boot] [PATCH 2/3] drivers: core: uclass: Get next device fail with driver probe fail Vladimir Olovyannikov
2019-11-23 12:54   ` Bin Meng
2019-11-22 22:23 ` Vladimir Olovyannikov [this message]
2019-11-23 12:54   ` [U-Boot] [PATCH 3/3] drivers: pci: pci-uclass: Get PCI dma regions support Bin Meng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191122222323.28898-4-vladimir.olovyannikov@broadcom.com \
    --to=vladimir.olovyannikov@broadcom.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.