public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Becky Bruce <beckyb@kernel.crashing.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 2/8] drivers/pci: Create pci_map_bar function
Date: Tue,  3 Feb 2009 18:10:50 -0600	[thread overview]
Message-ID: <1233706256-13878-3-git-send-email-beckyb@kernel.crashing.org> (raw)
In-Reply-To: <1233706256-13878-1-git-send-email-beckyb@kernel.crashing.org>

It is no longer always true that the pci bus address can be
used as the virtual address for pci accesses.  pci_map_bar()
is created to return the virtual address for a pci region.

Signed-off-by: Becky Bruce <beckyb@kernel.crashing.org>
---
 drivers/pci/pci.c |   19 +++++++++++++++++++
 include/pci.h     |   28 ++++++++++++++++++++++++----
 2 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index e2b05d8..cb1217f 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -116,6 +116,25 @@ PCI_READ_VIA_DWORD_OP(word, u16 *, 0x02)
 PCI_WRITE_VIA_DWORD_OP(byte, u8, 0x03, 0x000000ff)
 PCI_WRITE_VIA_DWORD_OP(word, u16, 0x02, 0x0000ffff)
 
+/* Get a virtual address associated with a BAR region */
+void *pci_map_bar(pci_dev_t pdev, int bar, int flags)
+{
+	pci_addr_t pci_bus_addr;
+	u32 bar_response;
+
+	/* read BAR address */
+	pci_read_config_dword(pdev, bar, &bar_response);
+	pci_bus_addr = (pci_addr_t)(bar_response & ~0xf);
+
+	/*
+	 * Pass "0" as the length argument to pci_bus_to_virt.  The arg
+	 * isn't actualy used on any platform because u-boot assumes a static
+	 * linear mapping.  In the future, this could read the BAR size
+	 * and pass that as the size if needed.
+	 */
+	return pci_bus_to_virt(pdev, pci_bus_addr, flags, 0, MAP_NOCACHE);
+}
+
 /*
  *
  */
diff --git a/include/pci.h b/include/pci.h
index 072273b..058b943 100644
--- a/include/pci.h
+++ b/include/pci.h
@@ -454,10 +454,29 @@ extern pci_addr_t pci_hose_phys_to_bus(struct pci_controller* hose,
 #define pci_bus_to_phys(dev, addr, flags) \
 	pci_hose_bus_to_phys(pci_bus_to_hose(PCI_BUS(dev)), (addr), (flags))
 
-#define pci_phys_to_mem(dev, addr)	pci_phys_to_bus((dev), (addr), PCI_REGION_MEM)
-#define pci_mem_to_phys(dev, addr)	pci_bus_to_phys((dev), (addr), PCI_REGION_MEM)
-#define pci_phys_to_io(dev, addr)	pci_phys_to_bus((dev), (addr), PCI_REGION_IO)
-#define pci_io_to_phys(dev, addr)	pci_bus_to_phys((dev), (addr), PCI_REGION_IO)
+#define pci_virt_to_bus(dev, addr, flags) \
+	pci_hose_phys_to_bus(pci_bus_to_hose(PCI_BUS(dev)), \
+			     (virt_to_phys(addr)), (flags))
+#define pci_bus_to_virt(dev, addr, flags, len, map_flags) \
+	map_physmem(pci_hose_bus_to_phys(pci_bus_to_hose(PCI_BUS(dev)), \
+					 (addr), (flags)), \
+		    (len), (map_flags))
+
+#define pci_phys_to_mem(dev, addr) \
+	pci_phys_to_bus((dev), (addr), PCI_REGION_MEM)
+#define pci_mem_to_phys(dev, addr) \
+	pci_bus_to_phys((dev), (addr), PCI_REGION_MEM)
+#define pci_phys_to_io(dev, addr)  pci_phys_to_bus((dev), (addr), PCI_REGION_IO)
+#define pci_io_to_phys(dev, addr)  pci_bus_to_phys((dev), (addr), PCI_REGION_IO)
+
+#define pci_virt_to_mem(dev, addr) \
+	pci_virt_to_bus((dev), (addr), PCI_REGION_MEM)
+#define pci_mem_to_virt(dev, addr, len, map_flags) \
+	pci_bus_to_virt((dev), (addr), PCI_REGION_MEM, (len), (map_flags))
+#define pci_virt_to_io(dev, addr) \
+	pci_virt_to_bus((dev), (addr), PCI_REGION_IO)
+#define pci_io_to_virt(dev, addr, len, map_flags) \
+	pci_bus_to_virt((dev), (addr), PCI_REGION_IO, (len), (map_flags))
 
 extern int pci_hose_read_config_byte(struct pci_controller *hose,
 				     pci_dev_t dev, int where, u8 *val);
@@ -488,6 +507,7 @@ extern int pci_hose_write_config_byte_via_dword(struct pci_controller *hose,
 extern int pci_hose_write_config_word_via_dword(struct pci_controller *hose,
 						pci_dev_t dev, int where, u16 val);
 
+extern void *pci_map_bar(pci_dev_t pdev, int bar, int flags);
 extern void pci_register_hose(struct pci_controller* hose);
 extern struct pci_controller* pci_bus_to_hose(int bus);
 
-- 
1.5.6.6

  parent reply	other threads:[~2009-02-04  0:10 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-04  0:10 [U-Boot] [PATCH 00/08 V2] Allow PCI bus address, PA, and VA to differ Becky Bruce
2009-02-04  0:10 ` [U-Boot] [PATCH 1/8] mpc8641hpcn: Set up outbound pci windows before inbound Becky Bruce
2009-02-04 19:38   ` Jon Loeliger
2009-02-05  5:52     ` [U-Boot] 86xx maintainership change? Kumar Gala
2009-02-05  7:51       ` Wolfgang Denk
2009-02-09 15:50   ` [U-Boot] [PATCH 1/8] mpc8641hpcn: Set up outbound pci windows before inbound Kumar Gala
2009-02-09 19:14     ` Becky Bruce
2009-02-09 23:32   ` Wolfgang Denk
2009-02-04  0:10 ` Becky Bruce [this message]
2009-02-09 23:32   ` [U-Boot] [PATCH 2/8] drivers/pci: Create pci_map_bar function Wolfgang Denk
2009-02-04  0:10 ` [U-Boot] [PATCH 3/8] powerpc: Move duplicated BAT defines to mmu.h Becky Bruce
2009-02-09 23:32   ` Wolfgang Denk
2009-02-04  0:10 ` [U-Boot] [PATCH 4/8] mpc86xx: Add support to populate addr map based on BATs Becky Bruce
2009-02-04 19:35   ` Jon Loeliger
2009-02-09 23:32   ` Wolfgang Denk
2009-02-04  0:10 ` [U-Boot] [PATCH 5/8] mpc8641hpcn: Clean up PCI mapping concepts Becky Bruce
2009-02-04 19:36   ` Jon Loeliger
2009-02-09 23:32   ` Wolfgang Denk
2009-02-04  0:10 ` [U-Boot] [PATCH 6/8] MPC8641HPCN: Enable CONFIG_ADDR_MAP Becky Bruce
2009-02-04 19:43   ` Jon Loeliger
2009-02-09 23:32   ` Wolfgang Denk
2009-02-04  0:10 ` [U-Boot] [PATCH 7/8] drivers/block/ahci: Fix pci mapping bug Becky Bruce
2009-02-09 23:32   ` Wolfgang Denk
2009-02-04  0:10 ` [U-Boot] [PATCH 8/8] mpc8641hpcn: Change PCI MEM pci bus address Becky Bruce
2009-02-04 19:37   ` Jon Loeliger
2009-02-09 23:32   ` Wolfgang Denk

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=1233706256-13878-3-git-send-email-beckyb@kernel.crashing.org \
    --to=beckyb@kernel.crashing.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox