linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: thomas.petazzoni@free-electrons.com (Thomas Petazzoni)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 21/32] arm: mvebu: add functions to alloc/free PCIe decoding windows
Date: Tue, 12 Feb 2013 17:28:55 +0100	[thread overview]
Message-ID: <1360686546-24277-22-git-send-email-thomas.petazzoni@free-electrons.com> (raw)
In-Reply-To: <1360686546-24277-1-git-send-email-thomas.petazzoni@free-electrons.com>

This commit adds two functions armada_370_xp_alloc_pcie_window() and
armada_370_xp_free_pcie_window() that respectively allocate and free
an address decoding window pointing to either a memory or I/O region
of a PCIe device.

Those functions will be used by the PCIe driver to create and remove
those regions depending on the PCIe devices that are detected.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
---
 arch/arm/mach-mvebu/addr-map.c              |   87 +++++++++++++++++++++++++--
 arch/arm/mach-mvebu/common.h                |    1 +
 arch/arm/mach-mvebu/include/mach/addr-map.h |   10 +++
 3 files changed, 94 insertions(+), 4 deletions(-)
 create mode 100644 arch/arm/mach-mvebu/include/mach/addr-map.h

diff --git a/arch/arm/mach-mvebu/addr-map.c b/arch/arm/mach-mvebu/addr-map.c
index 77c807b..6f9dda7 100644
--- a/arch/arm/mach-mvebu/addr-map.c
+++ b/arch/arm/mach-mvebu/addr-map.c
@@ -24,14 +24,10 @@
 #define ARMADA_XP_TARGET_DEV_BUS	1
 #define   ARMADA_XP_ATTR_DEV_BOOTROM    0x1D
 #define ARMADA_XP_TARGET_ETH1		3
-#define ARMADA_XP_TARGET_PCIE_0_2	4
 #define ARMADA_XP_TARGET_ETH0		7
-#define ARMADA_XP_TARGET_PCIE_1_3	8
 
 #define ARMADA_370_TARGET_DEV_BUS       1
 #define   ARMADA_370_ATTR_DEV_BOOTROM   0x1D
-#define ARMADA_370_TARGET_PCIE_0        4
-#define ARMADA_370_TARGET_PCIE_1        8
 
 #define ARMADA_WINDOW_8_PLUS_OFFSET       0x90
 #define ARMADA_SDRAM_ADDR_DECODING_OFFSET 0x180
@@ -89,6 +85,89 @@ static struct __initdata orion_addr_map_cfg addr_map_cfg = {
 	.win_cfg_base = armada_cfg_base,
 };
 
+#ifdef CONFIG_PCI
+/*
+ * This structure and the following arrays allow to map a PCIe (port,
+ * lane) tuple to the corresponding (target, attribute) tuple needed
+ * to configure an address decoding window for the given PCIe (port,
+ * lane).
+ */
+struct pcie_mapping {
+	int port;
+	int lane;
+	u8  target;
+	u8  attr;
+};
+
+struct pcie_mapping armada_xp_pcie_mappings[] = {
+	{ .port = 0, .lane = 0, .target = 4, .attr = 0xE0 },
+	{ .port = 0, .lane = 1, .target = 4, .attr = 0xD0 },
+	{ .port = 0, .lane = 2, .target = 4, .attr = 0xB0 },
+	{ .port = 0, .lane = 3, .target = 4, .attr = 0x70 },
+	{ .port = 1, .lane = 0, .target = 8, .attr = 0xE0 },
+	{ .port = 1, .lane = 1, .target = 8, .attr = 0xD0 },
+	{ .port = 1, .lane = 2, .target = 8, .attr = 0xB0 },
+	{ .port = 1, .lane = 3, .target = 8, .attr = 0x70 },
+	{ .port = 2, .lane = 0, .target = 4, .attr = 0xF0 },
+	{ .port = 3, .lane = 0, .target = 8, .attr = 0xF0 },
+	{ .port = -1 },
+};
+
+struct pcie_mapping armada_370_pcie_mappings[] = {
+	{ .port = 0, .lane = 0, .target = 4, .attr = 0xE0 },
+	{ .port = 1, .lane = 0, .target = 8, .attr = 0xE0 },
+	{ .port = -1 },
+};
+
+/*
+ * This function sets up a new address decoding window at the given
+ * base address, pointing to the given PCIe interface (through
+ * pcie_port and pcie_lane).
+ */
+int armada_370_xp_alloc_pcie_window(int pcie_port, int pcie_lane,
+				    u32 base, u32 remap, u32 size,
+				    int type)
+{
+	struct pcie_mapping *mapping, *mappings;
+	u8 target, attr;
+
+	if (of_machine_is_compatible("marvell,armadaxp"))
+		mappings = armada_xp_pcie_mappings;
+	else if (of_machine_is_compatible("marvell,armada370"))
+		mappings = armada_370_pcie_mappings;
+	else
+		return -ENODEV;
+
+	for (mapping = mappings; mapping->port != -1; mapping++)
+		if (mapping->port == pcie_port && mapping->lane == pcie_lane)
+			break;
+
+	if (mapping->port == -1)
+		return -ENODEV;
+
+	target = mapping->target;
+	attr = mapping->attr;
+
+	/*
+	 * Bit 3 of the attributes indicates that it is a
+	 * memory region, as opposed to an I/O region
+	 */
+	if (type == IORESOURCE_MEM)
+		attr |= (1 << 3);
+
+	return orion_alloc_cpu_win(&addr_map_cfg, base, size, target, attr, remap);
+}
+
+/*
+ * Frees an address decoding window previously set up by
+ * armada_370_xp_setup_pcie_window().
+ */
+int armada_370_xp_free_pcie_window(u32 base)
+{
+	return orion_free_cpu_win(&addr_map_cfg, base);
+}
+#endif
+
 static int __init armada_setup_cpu_mbus(void)
 {
 	struct device_node *np;
diff --git a/arch/arm/mach-mvebu/common.h b/arch/arm/mach-mvebu/common.h
index aa27bc2..77c078c 100644
--- a/arch/arm/mach-mvebu/common.h
+++ b/arch/arm/mach-mvebu/common.h
@@ -25,4 +25,5 @@ int armada_370_xp_coherency_init(void);
 int armada_370_xp_pmsu_init(void);
 void armada_xp_secondary_startup(void);
 extern struct smp_operations armada_xp_smp_ops;
+
 #endif
diff --git a/arch/arm/mach-mvebu/include/mach/addr-map.h b/arch/arm/mach-mvebu/include/mach/addr-map.h
new file mode 100644
index 0000000..e2d29cd
--- /dev/null
+++ b/arch/arm/mach-mvebu/include/mach/addr-map.h
@@ -0,0 +1,10 @@
+#ifndef MVEBU_ADDR_MAP_H
+#define MVEBU_ADDR_MAP_H
+
+#include <plat/addr-map.h>
+
+int armada_370_xp_alloc_pcie_window(int pcie_port, int pcie_lane,
+				    u32 base, u32 remap, u32 size, int type);
+int armada_370_xp_free_pcie_window(unsigned long base);
+
+#endif /* MVEBU_ADDR_MAP_H */
-- 
1.7.9.5

  parent reply	other threads:[~2013-02-12 16:28 UTC|newest]

Thread overview: 135+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-12 16:28 [PATCH v3] PCIe support for the Armada 370 and Armada XP SoCs Thomas Petazzoni
2013-02-12 16:28 ` [PATCH 01/32] of/pci: Provide support for parsing PCI DT ranges property Thomas Petazzoni
2013-02-12 16:28 ` [PATCH 02/32] of/pci: Add of_pci_get_devfn() function Thomas Petazzoni
2013-02-12 16:28 ` [PATCH 03/32] of/pci: Add of_pci_parse_bus_range() function Thomas Petazzoni
2013-02-12 16:28 ` [PATCH 04/32] ARM: pci: Allow passing per-controller private data Thomas Petazzoni
2013-02-12 16:28 ` [PATCH 05/32] lib: devres: don't enclose pcim_*() functions in CONFIG_HAS_IOPORT Thomas Petazzoni
2013-02-12 18:00   ` Arnd Bergmann
2013-02-12 18:58     ` Thomas Petazzoni
2013-02-12 22:36       ` Arnd Bergmann
2013-03-04 16:28         ` Thomas Petazzoni
2013-03-04 20:30           ` Arnd Bergmann
2013-02-12 16:28 ` [PATCH 06/32] arm: pci: add a align_resource hook Thomas Petazzoni
2013-02-12 18:03   ` Arnd Bergmann
2013-02-12 19:01     ` Thomas Petazzoni
2013-02-12 19:49       ` Russell King - ARM Linux
2013-02-12 16:28 ` [PATCH 07/32] arm: mvebu: fix address-cells in mpic DT node Thomas Petazzoni
2013-02-12 16:28 ` [PATCH 08/32] clk: mvebu: create parent-child relation for PCIe clocks on Armada 370 Thomas Petazzoni
2013-02-12 16:28 ` [PATCH 09/32] clk: mvebu: add more PCIe clocks for Armada XP Thomas Petazzoni
2013-02-12 16:28 ` [PATCH 10/32] arm: plat-orion: introduce WIN_CTRL_ENABLE in address mapping code Thomas Petazzoni
2013-02-12 16:28 ` [PATCH 11/32] arm: plat-orion: refactor the orion_disable_wins() function Thomas Petazzoni
2013-02-12 16:28 ` [PATCH 12/32] plat-orion: introduce ORION_ADDR_MAP_NO_REMAP Thomas Petazzoni
2013-02-12 16:28 ` [PATCH 13/32] arm: mach-dove: use ORION_ADDR_MAP_NO_REMAP Thomas Petazzoni
2013-02-12 16:28 ` [PATCH 14/32] arm: mach-kirkwood: " Thomas Petazzoni
2013-02-12 16:28 ` [PATCH 15/32] arm: mach-mvebu: " Thomas Petazzoni
2013-02-12 16:28 ` [PATCH 16/32] arm: mach-orion5x: " Thomas Petazzoni
2013-02-12 16:28 ` [PATCH 17/32] arm: plat-orion: convert 'int remap' to 'u32 remap' Thomas Petazzoni
2013-02-12 16:28 ` [PATCH 18/32] arm: plat-orion: remove __init from addr-map functions needed after boot time Thomas Petazzoni
2013-02-12 16:28 ` [PATCH 19/32] arm: plat-orion: introduce orion_{alloc, free}_cpu_win() functions Thomas Petazzoni
2013-02-12 16:28 ` [PATCH 20/32] arm: plat-orion: remove __init from PCIe functions needed after boot time Thomas Petazzoni
2013-02-12 16:28 ` Thomas Petazzoni [this message]
2013-02-12 16:28 ` [PATCH 22/32] arm: plat-orion: make common PCIe code usable on mvebu Thomas Petazzoni
2013-02-12 16:28 ` [PATCH 23/32] pci: infrastructure to add drivers in drivers/pci/host Thomas Petazzoni
2013-02-12 16:28 ` [PATCH 24/32] pci: PCIe driver for Marvell Armada 370/XP systems Thomas Petazzoni
2013-02-12 18:30   ` Arnd Bergmann
2013-02-12 19:22     ` Thomas Petazzoni
2013-02-12 19:49       ` Jason Gunthorpe
2013-02-12 22:59       ` Arnd Bergmann
2013-02-13  0:41         ` Jason Gunthorpe
2013-02-13  9:18           ` Arnd Bergmann
2013-02-13  9:31             ` Thomas Petazzoni
2013-02-13 10:23               ` Arnd Bergmann
2013-02-13  8:23         ` Thomas Petazzoni
2013-02-13  9:29           ` Arnd Bergmann
2013-02-13  9:40             ` Thomas Petazzoni
2013-02-13 10:37               ` Arnd Bergmann
2013-03-06  9:50                 ` Thomas Petazzoni
2013-03-06 10:43                   ` Arnd Bergmann
2013-02-12 22:35   ` Jason Gunthorpe
2013-02-13  8:57     ` Thomas Petazzoni
2013-02-13 18:04       ` Jason Gunthorpe
2013-02-13 19:33         ` Arnd Bergmann
2013-03-06  9:54     ` Thomas Petazzoni
2013-03-06 12:11       ` Thierry Reding
2013-03-06 18:09         ` Jason Gunthorpe
2013-03-07  8:08           ` Thierry Reding
2013-03-07 17:49             ` Jason Gunthorpe
2013-03-07 19:48               ` Thierry Reding
2013-03-07 20:02                 ` Jason Gunthorpe
2013-03-07 20:47                   ` Thierry Reding
2013-03-08  0:05                     ` Rob Herring
2013-03-08  7:14                       ` Thierry Reding
2013-03-08 16:52                         ` Jason Gunthorpe
2013-03-08 19:12                           ` Thierry Reding
2013-03-08 19:43                             ` Mitch Bradley
2013-03-08 20:02                               ` Jason Gunthorpe
2013-03-08 20:13                                 ` Thierry Reding
2013-03-10 15:09                                   ` Thomas Petazzoni
2013-03-11  8:08                                     ` Thierry Reding
2013-03-08 23:46                                 ` Mitch Bradley
2013-03-09  1:31                                   ` Jason Gunthorpe
2013-03-10  4:52                                     ` Mitch Bradley
2013-03-10  6:55                                       ` Jason Gunthorpe
2013-03-11  5:46                                         ` Mitch Bradley
2013-03-11  7:46                                           ` Thierry Reding
2013-03-11 18:04                                             ` Mitch Bradley
2013-03-11 18:23                                               ` Jason Gunthorpe
2013-03-11 19:49                                                 ` Mitch Bradley
2013-03-11 18:15                                           ` Jason Gunthorpe
2013-03-11 21:50                                             ` Mitch Bradley
2013-03-11 23:25                                               ` Jason Gunthorpe
2013-03-11 23:38                                                 ` Mitch Bradley
2013-03-12  7:08                                                   ` Thierry Reding
2013-03-12 15:57                                                     ` Jason Gunthorpe
2013-03-12 20:38                                                       ` Thierry Reding
2013-03-12 21:03                                                         ` Jason Gunthorpe
2013-03-12 21:30                                                           ` Thierry Reding
2013-03-12 22:08                                                             ` Jason Gunthorpe
2013-03-12 23:25                                                               ` Mitch Bradley
2013-03-13  8:18                                                               ` Thierry Reding
2013-03-13 17:02                                                                 ` Jason Gunthorpe
2013-03-13 19:26                                                                   ` Thierry Reding
2013-03-13 19:59                                                                     ` Jason Gunthorpe
2013-03-13 20:54                                                                       ` Thierry Reding
2013-03-13 20:58                                                                     ` Mitch Bradley
2013-03-13 21:33                                                                       ` Thierry Reding
2013-03-13 22:48                                                                         ` Mitch Bradley
2013-03-14  0:43                                                                           ` Rob Herring
2013-03-14  1:20                                                                             ` Mitch Bradley
2013-03-14  7:11                                                                           ` Thierry Reding
2013-03-14  4:56                                                                         ` Stephen Warren
2013-03-13 22:02                                                                       ` Thierry Reding
2013-03-13 22:21                                                                         ` Jason Gunthorpe
2013-03-14  9:01                                                                           ` Thierry Reding
2013-03-14 17:25                                                                             ` Jason Gunthorpe
2013-03-14 20:38                                                                               ` Thierry Reding
2013-03-14 21:05                                                                                 ` Jason Gunthorpe
2013-03-14 21:10                                                                                 ` Mitch Bradley
2013-03-14 21:09                                                                               ` Thierry Reding
2013-03-14 21:29                                                                                 ` Jason Gunthorpe
2013-03-14 21:37                                                                                   ` Thierry Reding
2013-03-13 22:22                                                                       ` Jason Gunthorpe
2013-03-09  8:58                             ` Thomas Petazzoni
2013-03-08 23:12                         ` Rob Herring
2013-03-09 11:10                           ` Thierry Reding
2013-03-10  5:04                           ` Mitch Bradley
2013-03-10 15:06                             ` Thomas Petazzoni
2013-03-10 18:33                               ` Mitch Bradley
2013-02-15  0:36   ` Bjorn Helgaas
2013-02-15  5:06     ` Thomas Petazzoni
2013-02-15 16:26       ` Bjorn Helgaas
2013-02-15 16:44         ` Jason Gunthorpe
2013-02-12 16:28 ` [PATCH 25/32] arm: mvebu: PCIe support is now available on mvebu Thomas Petazzoni
2013-02-12 16:29 ` [PATCH 26/32] arm: mvebu: add PCIe Device Tree informations for Armada 370 Thomas Petazzoni
2013-02-12 16:29 ` [PATCH 27/32] arm: mvebu: add PCIe Device Tree informations for Armada XP Thomas Petazzoni
2013-02-12 16:29 ` [PATCH 28/32] arm: mvebu: PCIe Device Tree informations for OpenBlocks AX3-4 Thomas Petazzoni
2013-02-12 16:29 ` [PATCH 29/32] arm: mvebu: PCIe Device Tree informations for Armada XP DB Thomas Petazzoni
2013-02-12 16:29 ` [PATCH 30/32] arm: mvebu: PCIe Device Tree informations for Armada 370 Mirabox Thomas Petazzoni
2013-02-12 16:29 ` [PATCH 31/32] arm: mvebu: PCIe Device Tree informations for Armada 370 DB Thomas Petazzoni
2013-02-12 16:29 ` [PATCH 32/32] arm: mvebu: update defconfig with PCI and USB support Thomas Petazzoni
2013-02-12 18:12 ` [PATCH v3] PCIe support for the Armada 370 and Armada XP SoCs Arnd Bergmann
2013-02-12 19:04   ` Thomas Petazzoni
2013-02-13  8:50   ` Thomas Petazzoni
2013-02-13  9:37     ` Arnd Bergmann
2013-02-13 15:27 ` Christophe Vu-Brugier
2013-02-13 15:30   ` Thomas Petazzoni

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=1360686546-24277-22-git-send-email-thomas.petazzoni@free-electrons.com \
    --to=thomas.petazzoni@free-electrons.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /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;
as well as URLs for NNTP newsgroup(s).