PCI: brcmstb: Add Broadcom Settopbox PCIe support
Subsystems (7)
This patch series adds support for the Broadcom Settopbox PCIe host controller. It is targeted to Broadcom Settopbox chips running on ARM, ARM64, and MIPS platforms. As the HW of the controller is intimately tied to the memory subsystem, there are some patches required that are not typical of a PCIe host controller driver.
pci-brcmstb.c -- is the core functionality of the RC driver. pci-brcmstb-msi.c -- provides the driver for the PCIe's built-in
MSI controller.pci-brcmstb-dma.c -- provides the non-standard mapping between
system memory and the PCIe address space.drivers/soc/bcm/brcmstb/memory.c -- provides a single call to inform
the PCIe controller about the size of populated memory in the memory controllers.
PATCH 1/9 SOC: brcmstb: add memory API
From: Florian Fainelli <[email protected]>
This commit adds a memory API suitable for ascertaining the sizes of each of the N memory controllers in a Broadcom STB chip. Its first user will be the Broadcom STB PCIe root complex driver, which needs to know these sizes to properly set up DMA mappings for inbound regions.
We cannot use memblock here or anything like what Linux provides because it collapses adjacent regions within a larger block, and here we actually need per-memory controller addresses and sizes, which is why we resort to manual DT parsing.
--- drivers/soc/bcm/brcmstb/Makefile | 2 +- drivers/soc/bcm/brcmstb/memory.c | 183 +++++++++++++++++++++++++++++++++++++++ include/soc/brcmstb/memory_api.h | 25 ++++++ 3 files changed, 209 insertions(+), 1 deletion(-) create mode 100644 drivers/soc/bcm/brcmstb/memory.c create mode 100644 include/soc/brcmstb/memory_api.h
drivers/soc/bcm/brcmstb/Makefile +1 -1
@@ -1 +1 @@ -obj-y += common.o biuctrl.o +obj-y += common.o biuctrl.o memory.o
drivers/soc/bcm/brcmstb/memory.c new file +183 -0
183 lines not on this page · raw message
include/soc/brcmstb/memory_api.h new file +25 -0
@@ -0,0 +1,25 @@ +#ifndef __MEMORY_API_H +#define __MEMORY_API_H + +/* +* Bus Interface Unit control register setup, must happen early during boot, +* before SMP is brought up, called by machine entry point. +*/ +void brcmstb_biuctrl_init (void ); + +#ifdef CONFIG_SOC_BRCMSTB +int brcmstb_memory_phys_addr_to_memc (phys_addr_t pa); +u64 brcmstb_memory_memc_size (int memc); +#else +static inline int brcmstb_memory_phys_addr_to_memc (phys_addr_t pa) +{ +return -EINVAL ; +} + +static inline u64 brcmstb_memory_memc_size (int memc) +{ +return -1 ; +} +#endif + +#endif /* __MEMORY_API_H */
Signature · 1 line
1.9.0.138.g2de3478
Re: [PATCH 1/9] SOC: brcmstb: add memory API
Hi Jim,
Quoted 61 lines · Jim Quinlan
From: Florian Fainelli <[email protected]>
This commit adds a memory API suitable for ascertaining the sizes of each of the N memory controllers in a Broadcom STB chip. Its first user will be the Broadcom STB PCIe root complex driver, which needs to know these sizes to properly set up DMA mappings for inbound regions.
We cannot use memblock here or anything like what Linux provides because it collapses adjacent regions within a larger block, and here we actually need per-memory controller addresses and sizes, which is why we resort to manual DT parsing.
Signed-off-by Jim Quinlan <[email protected]>--- drivers/soc/bcm/brcmstb/Makefile | 2 +- drivers/soc/bcm/brcmstb/memory.c | 183 +++++++++++++++++++++++++++++++++++++++ include/soc/brcmstb/memory_api.h | 25 ++++++ 3 files changed, 209 insertions(+), 1 deletion(-)create mode 100644
drivers/soc/bcm/brcmstb/memory.ccreate mode 100644include/soc/brcmstb/memory_api.hdrivers/soc/bcm/brcmstb/Makefile +1
-1@@ -1 +1 @@ -obj-y += common.o biuctrl.o +obj-y += common.o biuctrl.o memory.odrivers/soc/bcm/brcmstb/memory.c new file +26
-0@@ -0,0 +1,183 @@ +/* +* Copyright ? 2015-2017 Broadcom +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* A copy of the GPL is available at +* http://www.broadcom.com/licenses/GPLv2.php or from the Free Software +* Foundation at https://www.gnu.org/licenses/ . +*/ + +#include <linux/device.h> +#include <linux/io.h> +#include <linux/libfdt.h> +#include <linux/of_address.h> +#include <linux/of_fdt.h> +#include <linux/sizes.h> +#include <soc/brcmstb/memory_api.h> + +/* -------------------- Constants -------------------- */
drivers/soc/bcm/brcmstb/memory.c line 36
Quoted 10 lines
drivers/soc/bcm/brcmstb/memory.c new file +10
-0+ +/* Macros to help extract property data */ +#define U8TOU32 (b, offs) \ + ((((u32)b[0 + offs] << 0) & 0x000000ff) | \ + (((u32)b[1 + offs] << 8) & 0x0000ff00) | \ + (((u32)b[2 + offs] << 16) & 0x00ff0000) | \ + (((u32)b[3 + offs] << 24) & 0xff000000)) + +#define DT_PROP_DATA_TO_U32 (b, offs) (fdt32_to_cpu(U8TOU32(b, offs))) +
I fail to understand why this is not:
#define DT_PROP_DATA_TO_U32(b, offs) (fdt32_to_cpu(*(u32*)(b + offs)))
If I understand correctly, fdt data is in big endian, the macro U8TOU32 reads it as little endian. My guess is that this won't work on big endian kernels but should work on little endian since fdt32_to_cpu will revert the bytes again.
Am I missing something?
Cheers,
Quoted 179 lines
drivers/soc/bcm/brcmstb/memory.c new file +147
-0+/* Constants used when retrieving memc info */ +#define NUM_BUS_RANGES 10 +#define BUS_RANGE_ULIMIT_SHIFT 4 +#define BUS_RANGE_LLIMIT_SHIFT 4 +#define BUS_RANGE_PA_SHIFT 12 + +enum { +BUSNUM_MCP0 =0x4 , +BUSNUM_MCP1 =0x5 , +BUSNUM_MCP2 =0x6 , +}; + +/* -------------------- Functions -------------------- */ + +/* +* If the DT nodes are handy, determine which MEMC holds the specified +* physical address. +*/ +#ifdef CONFIG_ARCH_BRCMSTB +int __brcmstb_memory_phys_addr_to_memc (phys_addr_t pa,void __iomem *base) +{ +int memc =-1 ; +int i; + +for (i =0 ; i <NUM_BUS_RANGES ; i++, base +=8 ) { +const u64 ulimit_raw =readl (base); +const u64 llimit_raw =readl (base +4 ); +const u64 ulimit = + ((ulimit_raw >>BUS_RANGE_ULIMIT_SHIFT ) + <<BUS_RANGE_PA_SHIFT ) |0xfff ; +const u64 llimit = (llimit_raw >>BUS_RANGE_LLIMIT_SHIFT ) + <<BUS_RANGE_PA_SHIFT ; +const u32 busnum = (u32)(ulimit_raw &0xf ); + +if (pa >= llimit && pa <= ulimit) { +if (busnum >=BUSNUM_MCP0 && busnum <=BUSNUM_MCP2 ) { + memc = busnum -BUSNUM_MCP0 ; +break ; + } + } + } + +return memc; +} + +int brcmstb_memory_phys_addr_to_memc (phys_addr_t pa) +{ +int memc =-1 ; +struct device_node *np; +void __iomem *cpubiuctrl; + + np =of_find_compatible_node (NULL ,NULL ,"brcm,brcmstb-cpu-biu-ctrl" ); +if (!np) +return memc; + + cpubiuctrl =of_iomap (np,0 ); +if (!cpubiuctrl) + goto cleanup; + + memc =__brcmstb_memory_phys_addr_to_memc (pa, cpubiuctrl); +iounmap (cpubiuctrl); + +cleanup: +of_node_put (np); + +return memc; +} + +#elif defined(CONFIG_MIPS ) +int brcmstb_memory_phys_addr_to_memc (phys_addr_t pa) +{ +/* The logic here is fairly simple and hardcoded: if pa <= 0x5000_0000, +* then this is MEMC0, else MEMC1. +* +* For systems with 2GB on MEMC0, MEMC1 starts at 9000_0000, with 1GB +* on MEMC0, MEMC1 starts at 6000_0000. +*/ +if (pa >=0x50000000ULL ) +return 1 ; +else +return 0 ; +} +#endif +EXPORT_SYMBOL (brcmstb_memory_phys_addr_to_memc); + +u64 brcmstb_memory_memc_size (int memc) +{ +const void *fdt = initial_boot_params; +const int mem_offset =fdt_path_offset (fdt,"/memory" ); +int addr_cells =1 , size_cells =1 ; +const struct fdt_property *prop; +int proplen, cellslen; +u64 memc_size =0 ; +int i; + +/* Get root size and address cells if specified */ + prop =fdt_get_property (fdt,0 ,"#size-cells" , &proplen); +if (prop) + size_cells =DT_PROP_DATA_TO_U32 (prop->data,0 ); + + prop =fdt_get_property (fdt,0 ,"#address-cells" , &proplen); +if (prop) + addr_cells =DT_PROP_DATA_TO_U32 (prop->data,0 ); + +if (mem_offset <0 ) +return -1 ; + + prop =fdt_get_property (fdt, mem_offset,"reg" , &proplen); + cellslen = (int )sizeof (u32) * (addr_cells + size_cells); +if ((proplen % cellslen) !=0 ) +return -1 ; + +for (i =0 ; i < proplen / cellslen; ++i) { +u64 addr =0 ; +u64 size =0 ; +int memc_idx; +int j; + +for (j =0 ; j < addr_cells; ++j) { +int offset = (cellslen * i) + (sizeof (u32) * j); + + addr |= (u64 )DT_PROP_DATA_TO_U32 (prop->data, offset) << + ((addr_cells - j -1 ) *32 ); + } +for (j =0 ; j < size_cells; ++j) { +int offset = (cellslen * i) + + (sizeof (u32) * (j + addr_cells)); + + size |= (u64 )DT_PROP_DATA_TO_U32 (prop->data, offset) << + ((size_cells - j -1 ) *32 ); + } + +if ((phys_addr_t )addr != addr) { +pr_err ("phys_addr_t is smaller than provided address 0x%llx!\n" , + addr); +return -1 ; + } + + memc_idx =brcmstb_memory_phys_addr_to_memc ((phys_addr_t )addr); +if (memc_idx == memc) + memc_size += size; + } + +return memc_size; +} +EXPORT_SYMBOL (brcmstb_memory_memc_size); +include/soc/brcmstb/memory_api.h new file +25
-0@@ -0,0 +1,25 @@ +#ifndef __MEMORY_API_H +#define __MEMORY_API_H + +/* +* Bus Interface Unit control register setup, must happen early during boot, +* before SMP is brought up, called by machine entry point. +*/ +void brcmstb_biuctrl_init (void ); + +#ifdef CONFIG_SOC_BRCMSTB +int brcmstb_memory_phys_addr_to_memc (phys_addr_t pa); +u64 brcmstb_memory_memc_size (int memc); +#else +static inline int brcmstb_memory_phys_addr_to_memc (phys_addr_t pa) +{ +return -EINVAL ; +} + +static inline u64 brcmstb_memory_memc_size (int memc) +{ +return -1 ; +} +#endif + +#endif /* __MEMORY_API_H */
Signature · 1 line
Julien Thierry
Re: [PATCH 1/9] SOC: brcmstb: add memory API
Quoted 83 lines · Julien Thierry
Hi Jim,
Quoted 64 lines · Jim Quinlan
From: Florian Fainelli <[email protected]>
This commit adds a memory API suitable for ascertaining the sizes of each of the N memory controllers in a Broadcom STB chip. Its first user will be the Broadcom STB PCIe root complex driver, which needs to know these sizes to properly set up DMA mappings for inbound regions.
We cannot use memblock here or anything like what Linux provides because it collapses adjacent regions within a larger block, and here we actually need per-memory controller addresses and sizes, which is why we resort to manual DT parsing.
Signed-off-by Jim Quinlan <[email protected]>--- drivers/soc/bcm/brcmstb/Makefile | 2 +- drivers/soc/bcm/brcmstb/memory.c | 183 +++++++++++++++++++++++++++++++++++++++ include/soc/brcmstb/memory_api.h | 25 ++++++ 3 files changed, 209 insertions(+), 1 deletion(-)create mode 100644
drivers/soc/bcm/brcmstb/memory.ccreate mode 100644include/soc/brcmstb/memory_api.hdrivers/soc/bcm/brcmstb/Makefile +1
-1@@ -1 +1 @@ -obj-y += common.o biuctrl.o +obj-y += common.o biuctrl.o memory.odrivers/soc/bcm/brcmstb/memory.c new file +26
-0@@ -0,0 +1,183 @@ +/* +* Copyright ? 2015-2017 Broadcom +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* A copy of the GPL is available at +* http://www.broadcom.com/licenses/GPLv2.php or from the Free Software +* Foundation at https://www.gnu.org/licenses/ . +*/ + +#include <linux/device.h> +#include <linux/io.h> +#include <linux/libfdt.h> +#include <linux/of_address.h> +#include <linux/of_fdt.h> +#include <linux/sizes.h> +#include <soc/brcmstb/memory_api.h> + +/* -------------------- Constants -------------------- */ drivers/soc/bcm/brcmstb/memory.c line 36
Quoted 10 lines
drivers/soc/bcm/brcmstb/memory.c new file +10
-0+ +/* Macros to help extract property data */ +#define U8TOU32 (b, offs) \ + ((((u32)b[0 + offs] << 0) & 0x000000ff) | \ + (((u32)b[1 + offs] << 8) & 0x0000ff00) | \ + (((u32)b[2 + offs] << 16) & 0x00ff0000) | \ + (((u32)b[3 + offs] << 24) & 0xff000000)) + +#define DT_PROP_DATA_TO_U32 (b, offs) (fdt32_to_cpu(U8TOU32(b, offs))) +I fail to understand why this is not:
#define
DT_PROP_DATA_TO_U32(b, offs)(fdt32_to_cpu(*(u32*)(b + offs)))
Quoted 6 lines
If I understand correctly, fdt data is in big endian, the macro U8TOU32 reads it as little endian. My guess is that this won't work on big endian kernels but should work on little endian since
fdt32_to_cpuwill revert the bytes again.Am I missing something?
No, your point is valid, there is no reason why this cannot be fdt32_to_cpu() here.
Signature · 1 line
Florian
Re: [PATCH 1/9] SOC: brcmstb: add memory API
In reply to Jim Quinlandrivers/soc/bcm/brcmstb/memory.c line 33
Quoted 6 lines
drivers/soc/bcm/brcmstb/memory.c new file +6
-0+/* Macros to help extract property data */ +#define U8TOU32 (b, offs) \ + ((((u32)b[0 + offs] << 0) & 0x000000ff) | \ + (((u32)b[1 + offs] << 8) & 0x0000ff00) | \ + (((u32)b[2 + offs] << 16) & 0x00ff0000) | \ + (((u32)b[3 + offs] << 24) & 0xff000000))
Please us helpers like get_unaligned_le32 instead opencoding them.
Quoted 1 line
+#define
DT_PROP_DATA_TO_U32(b, offs)(fdt32_to_cpu(U8TOU32(b, offs)))
And together with this it looks really whacky. So you're converting from le to native first and then do another conversion from be to cpu?
Something doesn't work out here.
Quoted 1 line
+/* -------------------- Functions -------------------- */
Please remove pointless comments like this one.
drivers/soc/bcm/brcmstb/memory.c line 56
Quoted 7 lines
drivers/soc/bcm/brcmstb/memory.c new file +7
-0+ +/* +* If the DT nodes are handy, determine which MEMC holds the specified +* physical address. +*/ +#ifdef CONFIG_ARCH_BRCMSTB +int __brcmstb_memory_phys_addr_to_memc (phys_addr_t pa,void __iomem *base)
Please move this into the arm arch code.
Quoted 1 line
+#elif
defined(CONFIG_MIPS)
And this into the mips arch code.
drivers/soc/bcm/brcmstb/memory.c line 182
Quoted 3 lines
drivers/soc/bcm/brcmstb/memory.c new file +2
-0+EXPORT_SYMBOL (brcmstb_memory_phys_addr_to_memc); +EXPORT_SYMBOL (brcmstb_memory_memc_size);
Why is this exported?
Re: [PATCH 1/9] SOC: brcmstb: add memory API
Quoted 20 lines · Christoph Hellwig
drivers/soc/bcm/brcmstb/memory.c line 33
Quoted 6 lines
drivers/soc/bcm/brcmstb/memory.c new file +6
-0+/* Macros to help extract property data */ +#define U8TOU32 (b, offs) \ + ((((u32)b[0 + offs] << 0) & 0x000000ff) | \ + (((u32)b[1 + offs] << 8) & 0x0000ff00) | \ + (((u32)b[2 + offs] << 16) & 0x00ff0000) | \ + (((u32)b[3 + offs] << 24) & 0xff000000))Please us helpers like
get_unaligned_le32instead opencoding them.Quoted 1 line
+#define
DT_PROP_DATA_TO_U32(b, offs)(fdt32_to_cpu(U8TOU32(b, offs)))And together with this it looks really whacky. So you're converting from le to native first and then do another conversion from be to cpu?
Something doesn't work out here.
Quoted 1 line
+/* -------------------- Functions -------------------- */
Please remove pointless comments like this one.
Quoted 9 lines
drivers/soc/bcm/brcmstb/memory.c line 56
Quoted 7 lines
drivers/soc/bcm/brcmstb/memory.c new file +7
-0+ +/* +* If the DT nodes are handy, determine which MEMC holds the specified +* physical address. +*/ +#ifdef CONFIG_ARCH_BRCMSTB +int __brcmstb_memory_phys_addr_to_memc (phys_addr_t pa,void __iomem *base)Please move this into the arm arch code.
No, this needs to work on both ARM and ARM64, hence the reason why this is in a reasonably architecture neutral place.
Quoted 4 lines
Quoted 2 lines
+#elif
defined(CONFIG_MIPS)And this into the mips arch code.
Same reason as above.
Quoted 6 lines
drivers/soc/bcm/brcmstb/memory.c line 182
Quoted 4 lines
drivers/soc/bcm/brcmstb/memory.c new file +2
-0+EXPORT_SYMBOL (brcmstb_memory_phys_addr_to_memc); +EXPORT_SYMBOL (brcmstb_memory_memc_size);Why is this exported?
Because the PCIE RC driver can be built as a module.
Signature · 1 line
Florian
Re: [PATCH 1/9] SOC: brcmstb: add memory API
Quoted 4 lines · Florian Fainelli
Quoted 1 line
Please move this into the arm arch code.
No, this needs to work on both ARM and ARM64, hence the reason why this is in a reasonably architecture neutral place.
So there is no other shared code between the ARM and ARM64 ports for this SOC?
Quoted 7 lines
Quoted 5 lines
drivers/soc/bcm/brcmstb/memory.c line 182
Quoted 3 lines
drivers/soc/bcm/brcmstb/memory.c new file +2
-0+EXPORT_SYMBOL (brcmstb_memory_phys_addr_to_memc); +EXPORT_SYMBOL (brcmstb_memory_memc_size);Why is this exported?
Because the PCIE RC driver can be built as a module.
Hmm, supporting PCIE RC as module sounds odd, but it seems like there are a few others like that. At least make it EXPORT_SYMBOL_GPL() then to document the internal nature.
Re: [PATCH 1/9] SOC: brcmstb: add memory API
Quoted 8 lines · Christoph Hellwig
Quoted 4 lines · Florian Fainelli
Quoted 1 line
Please move this into the arm arch code.
No, this needs to work on both ARM and ARM64, hence the reason why this is in a reasonably architecture neutral place.
So there is no other shared code between the ARM and ARM64 ports for this SOC?
The biuctrl.c file is also shared, and there are pending changes for v4.15-rc1 that also bring more shared files to this directory.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
drivers/soc/bcm/brcmstb/memory.c new file +2
-0+EXPORT_SYMBOL (brcmstb_memory_phys_addr_to_memc); +EXPORT_SYMBOL (brcmstb_memory_memc_size);
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Why is this exported?
Because the PCIE RC driver can be built as a module.
Hmm, supporting PCIE RC as module sounds odd, but it seems like there are a few others like that. At least make it
EXPORT_SYMBOL_GPL()then to document the internal nature.
Fair enough. Thanks
Signature · 2 lines
-- Florian
PATCH 2/9 PCI: host: brcmstb: add DT docs for Brcmstb PCIe device
In reply to Jim QuinlanThe DT bindings description of the Brcmstb PCIe device is described. This node can be used by almost all Broadcom settop box chips, using ARM, ARM64, or MIPS CPU architectures.
--- .../devicetree/bindings/pci/brcmstb-pci.txt | 106 +++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 Documentation/devicetree/bindings/pci/brcmstb-pci.txt
Documentation/devicetree/bindings/pci/brcmstb-pci.txt new file +106 -0
@@ -0,0 +1,106 @@ +Brcmstb PCIe Host Controller Device Tree Bindings + +Introduction: + The brcmstb host controller closely follows the example set in + + [1] http://devicetree.org/Device_Tree_Usage#PCI_Host_Bridge + + The rest of this document explains some added customizations and + offers an example Brcmstb PCIe host controller DT node. + +Required Properties: + reg -- the register start address and length for the PCIe block. + Additional start,length pairs may be specified for clock addresses. + interrupts -- two interrupts are specified; the first interrupt is for + the PCI host controller and the second is for MSI if the built-in + MSI controller is to be used. + interrupt-names -- names of the interrupts (above): "pcie" and "msi". + compatible -- must be one of: "brcm,bcm7425-pcie", "brcm,bcm7435-pcie", + or "brcm,bcm7278-pcie". + #address-cells -- the number of address cells for PCI-space. + #size-cells -- the number of size cells for PCI-space. + ranges -- See [1]; a specification of the outbound windows for the host + controller. Each outbound window is described by a n-tuple: + (3 cells) -- PCIe space start address; one cell for attributes + and two cells for the 64-bit PCIe address. + (x cells) -- CPU/System start address, number of cells is determined + by the parent node's #address-cells. + (y cells) -- Size of region, number of cells determined by the + parent node's #size-cells. + Due to hardware limitations, there may be a maximum of four + non-contiguous ranges specified. + #interrupt-cells -- number of cells used to describe the interrupt. + interrupt-map-mask -- see [1]; four cells, the first three are zero + for our uses and the fourth cell is the mask (val = 0x7) for + the legacy interrupt number [1..4]. + interrupt-map -- See [1]; there are four interrupts (INTA, INTB, + INTC, and INTD) to be mapped; each interrupt requires 5 cells + plus the size of the interrupt specifier. + linux,pci-domain -- the domain of the host controller. + +Optional Properties: + clocks -- list of clock phandles. If specified, this should list one + clock. + clock-names -- the "local" names of the clocks specified in 'clocks'. Note + that if the 'clocks' property is given, 'clock-names' is mandatory, + and the name of the clock is expected to be "sw_pcie". + dma-ranges -- Similar in structure to ranges, each dma region is + specified with a n-tuple. Dma-regions describe the inbound + accesses from EP to RC; it translates the pci address that the + EP "sees" to the CPU address in memory. This property is needed + because the design of the Brcmstb memory subsystem often precludes + idenity-mapping between CPU address space and PCIe address space. + Each range is described by a n-tuple: + (3 cells) -- PCIe space start address; one cell for attributes + and two cells for the 64-bit PCIe address. + (x cells) -- CPU/System start address, number of cells is determined + by the parent node's #address-cells. + (y cells) -- Size of region, number of cells determined by the + parent node's #size-cells. + msi-parent -- if MSI is to be used, this must be a phandle to the + msi-parent. If this prop is set to the phandle of the PCIe + node, or if the msi-parent prop is missing, the PCIE controller + will attempt to use its built in MSI controller. + msi-controller -- this property should only be specified if the + PCIe controller is using its internal MSI controller. + brcm,ssc -- (boolean) indicates usage of spread-spectrum clocking. + brcm,gen -- (integer) indicates desired generation of link: + 1 => 2.5 Gbps, 2 => 5.0 Gbps, 3 => 8.0 Gbps. + supply-names -- the names of voltage regulators that the root + complex should turn off/on/on on suspend/resume/boot. This + is a string list. + supplies -- A collection of phandles to a regulator nodes, see + Documentation/devicetree/bindings/regulator/ for specific + bindings. The number and order of phandles must match + exactly the number of strings in the "supply-names" property. + +Example Node: + +pcie0: pcie at f0460000 { + reg = <0x0 0xf0460000 0x0 0x9310>; + interrupts = <0x0 0x0 0x4>; + compatible = "brcm,pci-plat-dev"; + #address-cells = <3>; + #size-cells = <2>; + ranges = <0x02000000 0x00000000 0x00000000 0x00000000 0xc0000000 0x00000000 0x08000000 + 0x02000000 0x00000000 0x08000000 0x00000000 0xc8000000 0x00000000 0x08000000>; + #interrupt-cells = <1>; + interrupt-map-mask = <0 0 0 7>; + interrupt-map = <0 0 0 1 &intc 0 47 3 + 0 0 0 2 &intc 0 48 3 + 0 0 0 3 &intc 0 49 3 + 0 0 0 4 &intc 0 50 3>; + interrupt-names = "pcie_0_inta", + "pcie_0_intb", + "pcie_0_intc", + "pcie_0_intd"; + clocks = <&sw_pcie0>; + clock-names = "sw_pcie"; + msi-parent = <&pcie0>; /* use PCIe's internal MSI controller */ + msi-controller; /* use PCIe's internal MSI controller */ + brcm,ssc; + brcm,gen = <1>; + supply-names = "vreg-wifi-pwr"; + supplies = <&vreg-wifi-pwr>; + linux,pci-domain = <0>; + };
Signature · 1 line
1.9.0.138.g2de3478
Re: [PATCH 2/9] PCI: host: brcmstb: add DT docs for Brcmstb PCIe device
Hi Jim,
Quoted 74 lines · Jim Quinlan
The DT bindings description of the Brcmstb PCIe device is described. This node can be used by almost all Broadcom settop box chips, using ARM, ARM64, or MIPS CPU architectures.
Signed-off-by Jim Quinlan <[email protected]>--- .../devicetree/bindings/pci/brcmstb-pci.txt | 106 +++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 Documentation/devicetree/bindings/pci/brcmstb-pci.txtDocumentation/devicetree/bindings/pci/brcmstb-pci.txt new file +58
-0@@ -0,0 +1,106 @@ +Brcmstb PCIe Host Controller Device Tree Bindings + +Introduction: + The brcmstb host controller closely follows the example set in + + [1] http://devicetree.org/Device_Tree_Usage#PCI_Host_Bridge + + The rest of this document explains some added customizations and + offers an example Brcmstb PCIe host controller DT node. + +Required Properties: + reg -- the register start address and length for the PCIe block. + Additional start,length pairs may be specified for clock addresses. + interrupts -- two interrupts are specified; the first interrupt is for + the PCI host controller and the second is for MSI if the built-in + MSI controller is to be used. + interrupt-names -- names of the interrupts (above): "pcie" and "msi". + compatible -- must be one of: "brcm,bcm7425-pcie", "brcm,bcm7435-pcie", + or "brcm,bcm7278-pcie". + #address-cells -- the number of address cells for PCI-space. + #size-cells -- the number of size cells for PCI-space. + ranges -- See [1]; a specification of the outbound windows for the host + controller. Each outbound window is described by a n-tuple: + (3 cells) -- PCIe space start address; one cell for attributes + and two cells for the 64-bit PCIe address. + (x cells) -- CPU/System start address, number of cells is determined + by the parent node's #address-cells. + (y cells) -- Size of region, number of cells determined by the + parent node's #size-cells. + Due to hardware limitations, there may be a maximum of four + non-contiguous ranges specified. + #interrupt-cells -- number of cells used to describe the interrupt. + interrupt-map-mask -- see [1]; four cells, the first three are zero + for our uses and the fourth cell is the mask (val = 0x7) for + the legacy interrupt number [1..4]. + interrupt-map -- See [1]; there are four interrupts (INTA, INTB, + INTC, and INTD) to be mapped; each interrupt requires 5 cells + plus the size of the interrupt specifier. + linux,pci-domain -- the domain of the host controller. + +Optional Properties: + clocks -- list of clock phandles. If specified, this should list one + clock. + clock-names -- the "local" names of the clocks specified in 'clocks'. Note + that if the 'clocks' property is given, 'clock-names' is mandatory, + and the name of the clock is expected to be "sw_pcie". + dma-ranges -- Similar in structure to ranges, each dma region is + specified with a n-tuple. Dma-regions describe the inbound + accesses from EP to RC; it translates the pci address that the + EP "sees" to the CPU address in memory. This property is needed + because the design of the Brcmstb memory subsystem often precludes + idenity-mapping between CPU address space and PCIe address space. + Each range is described by a n-tuple: + (3 cells) -- PCIe space start address; one cell for attributes + and two cells for the 64-bit PCIe address. + (x cells) -- CPU/System start address, number of cells is determined + by the parent node's #address-cells. + (y cells) -- Size of region, number of cells determined by the
Documentation/devicetree/bindings/pci/brcmstb-pci.txt line 68
Quoted 10 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt new file +10
-0+ parent node's #size-cells. + msi-parent -- if MSI is to be used, this must be a phandle to the + msi-parent. If this prop is set to the phandle of the PCIe + node, or if the msi-parent prop is missing, the PCIE controller + will attempt to use its built in MSI controller. + msi-controller -- this property should only be specified if the + PCIe controller is using its internal MSI controller. + brcm,ssc -- (boolean) indicates usage of spread-spectrum clocking. + brcm,gen -- (integer) indicates desired generation of link: + 1 => 2.5 Gbps, 2 => 5.0 Gbps, 3 => 8.0 Gbps.
Does this differ from the 'max-link-speed' now documented in Documentation/devicetree/bindings/pci/pci.txt? If not, might as well use it, and of_pci_get_max_link_speed().
Documentation/devicetree/bindings/pci/brcmstb-pci.txt line 79
Quoted 11 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt new file +11
-0+ supply-names -- the names of voltage regulators that the root + complex should turn off/on/on on suspend/resume/boot. This + is a string list. + supplies -- A collection of phandles to a regulator nodes, see + Documentation/devicetree/bindings/regulator/ for specific + bindings. The number and order of phandles must match + exactly the number of strings in the "supply-names" property. + +Example Node: + +pcie0: pcie at f0460000 {
^^ You've got a tab after the colon. Makes this look funky in my vim/mutt :)
Brian
Quoted 30 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt new file +27
-0+ reg = <0x0 0xf0460000 0x0 0x9310>; + interrupts = <0x0 0x0 0x4>; + compatible = "brcm,pci-plat-dev"; + #address-cells = <3>; + #size-cells = <2>; + ranges = <0x02000000 0x00000000 0x00000000 0x00000000 0xc0000000 0x00000000 0x08000000 + 0x02000000 0x00000000 0x08000000 0x00000000 0xc8000000 0x00000000 0x08000000>; + #interrupt-cells = <1>; + interrupt-map-mask = <0 0 0 7>; + interrupt-map = <0 0 0 1 &intc 0 47 3 + 0 0 0 2 &intc 0 48 3 + 0 0 0 3 &intc 0 49 3 + 0 0 0 4 &intc 0 50 3>; + interrupt-names = "pcie_0_inta", + "pcie_0_intb", + "pcie_0_intc", + "pcie_0_intd"; + clocks = <&sw_pcie0>; + clock-names = "sw_pcie"; + msi-parent = <&pcie0>; /* use PCIe's internal MSI controller */ + msi-controller; /* use PCIe's internal MSI controller */ + brcm,ssc; + brcm,gen = <1>; + supply-names = "vreg-wifi-pwr"; + supplies = <&vreg-wifi-pwr>; + linux,pci-domain = <0>; + };Signature · 1 line
1.9.0.138.g2de3478
Re: [PATCH 2/9] PCI: host: brcmstb: add DT docs for Brcmstb PCIe device
Quoted 3 lines · Brian Norris
Hi Jim,
On Wed, Oct 11, 2017 at 06:34:22PM -0400, Jim Quinlan wrote:
pcie->gen = 0;
Quoted 80 lines
Quoted 80 lines
The DT bindings description of the Brcmstb PCIe device is described. This node can be used by almost all Broadcom settop box chips, using ARM, ARM64, or MIPS CPU architectures.
Signed-off-by Jim Quinlan <[email protected]>--- .../devicetree/bindings/pci/brcmstb-pci.txt | 106 +++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 Documentation/devicetree/bindings/pci/brcmstb-pci.txtDocumentation/devicetree/bindings/pci/brcmstb-pci.txt new file +64
-0@@ -0,0 +1,106 @@ +Brcmstb PCIe Host Controller Device Tree Bindings + +Introduction: + The brcmstb host controller closely follows the example set in + + [1] http://devicetree.org/Device_Tree_Usage#PCI_Host_Bridge + + The rest of this document explains some added customizations and + offers an example Brcmstb PCIe host controller DT node. + +Required Properties: + reg -- the register start address and length for the PCIe block. + Additional start,length pairs may be specified for clock addresses. + interrupts -- two interrupts are specified; the first interrupt is for + the PCI host controller and the second is for MSI if the built-in + MSI controller is to be used. + interrupt-names -- names of the interrupts (above): "pcie" and "msi". + compatible -- must be one of: "brcm,bcm7425-pcie", "brcm,bcm7435-pcie", + or "brcm,bcm7278-pcie". + #address-cells -- the number of address cells for PCI-space. + #size-cells -- the number of size cells for PCI-space. + ranges -- See [1]; a specification of the outbound windows for the host + controller. Each outbound window is described by a n-tuple: + (3 cells) -- PCIe space start address; one cell for attributes + and two cells for the 64-bit PCIe address. + (x cells) -- CPU/System start address, number of cells is determined + by the parent node's #address-cells. + (y cells) -- Size of region, number of cells determined by the + parent node's #size-cells. + Due to hardware limitations, there may be a maximum of four + non-contiguous ranges specified. + #interrupt-cells -- number of cells used to describe the interrupt. + interrupt-map-mask -- see [1]; four cells, the first three are zero + for our uses and the fourth cell is the mask (val = 0x7) for + the legacy interrupt number [1..4]. + interrupt-map -- See [1]; there are four interrupts (INTA, INTB, + INTC, and INTD) to be mapped; each interrupt requires 5 cells + plus the size of the interrupt specifier. + linux,pci-domain -- the domain of the host controller. + +Optional Properties: + clocks -- list of clock phandles. If specified, this should list one + clock. + clock-names -- the "local" names of the clocks specified in 'clocks'. Note + that if the 'clocks' property is given, 'clock-names' is mandatory, + and the name of the clock is expected to be "sw_pcie". + dma-ranges -- Similar in structure to ranges, each dma region is + specified with a n-tuple. Dma-regions describe the inbound + accesses from EP to RC; it translates the pci address that the + EP "sees" to the CPU address in memory. This property is needed + because the design of the Brcmstb memory subsystem often precludes + idenity-mapping between CPU address space and PCIe address space. + Each range is described by a n-tuple: + (3 cells) -- PCIe space start address; one cell for attributes + and two cells for the 64-bit PCIe address. + (x cells) -- CPU/System start address, number of cells is determined + by the parent node's #address-cells. + (y cells) -- Size of region, number of cells determined by the + parent node's #size-cells. + msi-parent -- if MSI is to be used, this must be a phandle to the + msi-parent. If this prop is set to the phandle of the PCIe + node, or if the msi-parent prop is missing, the PCIE controller + will attempt to use its built in MSI controller. + msi-controller -- this property should only be specified if the
Quoted 9 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt line 68
Quoted 4 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt new file +4
-0+ PCIe controller is using its internal MSI controller. + brcm,ssc -- (boolean) indicates usage of spread-spectrum clocking. + brcm,gen -- (integer) indicates desired generation of link: + 1 => 2.5 Gbps, 2 => 5.0 Gbps, 3 => 8.0 Gbps.Does this differ from the 'max-link-speed' now documented in
Documentation/devicetree/bindings/pci/pci.txt? If not, might as well use it, andof_pci_get_max_link_speed().
Hi Brian, yes that's what it is, will fix.
Quoted 15 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt line 79
Quoted 11 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt new file +11
-0+ supply-names -- the names of voltage regulators that the root + complex should turn off/on/on on suspend/resume/boot. This + is a string list. + supplies -- A collection of phandles to a regulator nodes, see + Documentation/devicetree/bindings/regulator/ for specific + bindings. The number and order of phandles must match + exactly the number of strings in the "supply-names" property. + +Example Node: + +pcie0: pcie at f0460000 {^^ You've got a tab after the colon. Makes this look funky in my vim/mutt :)
Quoted 2 lines
Brian
Will fix.
Quoted 30 lines
Quoted 30 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt new file +27
-1+ reg = <0x0 0xf0460000 0x0 0x9310>; + interrupts = <0x0 0x0 0x4>; + compatible = "brcm,pci-plat-dev"; + #address-cells = <3>; + #size-cells = <2>; + ranges = <0x02000000 0x00000000 0x00000000 0x00000000 0xc0000000 0x00000000 0x08000000 + 0x02000000 0x00000000 0x08000000 0x00000000 0xc8000000 0x00000000 0x08000000>; + #interrupt-cells = <1>; + interrupt-map-mask = <0 0 0 7>; + interrupt-map = <0 0 0 1 &intc 0 47 3 + 0 0 0 2 &intc 0 48 3 + 0 0 0 3 &intc 0 49 3 + 0 0 0 4 &intc 0 50 3>; + interrupt-names = "pcie_0_inta", + "pcie_0_intb", + "pcie_0_intc", + "pcie_0_intd"; + clocks = <&sw_pcie0>; + clock-names = "sw_pcie"; + msi-parent = <&pcie0>; /* use PCIe's internal MSI controller */ + msi-controller; /* use PCIe's internal MSI controller */ + brcm,ssc; + brcm,gen = <1>; + supply-names = "vreg-wifi-pwr"; + supplies = <&vreg-wifi-pwr>; + linux,pci-domain = <0>; + }; --1.9.0.138.g2de3478
Rob Herring
maintainerRe: [PATCH 2/9] PCI: host: brcmstb: add DT docs for Brcmstb PCIe device
In reply to Jim QuinlanQuoted 19 lines · Jim Quinlan
The DT bindings description of the Brcmstb PCIe device is described. This node can be used by almost all Broadcom settop box chips, using ARM, ARM64, or MIPS CPU architectures.
Signed-off-by Jim Quinlan <[email protected]>--- .../devicetree/bindings/pci/brcmstb-pci.txt | 106 +++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 Documentation/devicetree/bindings/pci/brcmstb-pci.txtDocumentation/devicetree/bindings/pci/brcmstb-pci.txt new file +3
-0@@ -0,0 +1,106 @@ +Brcmstb PCIe Host Controller Device Tree Bindings + +Introduction:
Documentation/devicetree/bindings/pci/brcmstb-pci.txt line 13
Quoted 10 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt new file +10
-0+ The brcmstb host controller closely follows the example set in + + [1] http://devicetree.org/Device_Tree_Usage#PCI_Host_Bridge + + The rest of this document explains some added customizations and + offers an example Brcmstb PCIe host controller DT node. + +Required Properties: + reg -- the register start address and length for the PCIe block. + Additional start,length pairs may be specified for clock addresses.
Kind of vague and why do you need clock addresses and the clock binding?
Also, typically the config space is defined here? Is that missing or you don't support memory mapped config space?
Documentation/devicetree/bindings/pci/brcmstb-pci.txt line 19
Quoted 6 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt new file +6
-0+ interrupts -- two interrupts are specified; the first interrupt is for + the PCI host controller and the second is for MSI if the built-in + MSI controller is to be used. + interrupt-names -- names of the interrupts (above): "pcie" and "msi". + compatible -- must be one of: "brcm,bcm7425-pcie", "brcm,bcm7435-pcie", + or "brcm,bcm7278-pcie".
One compatible per line.
Documentation/devicetree/bindings/pci/brcmstb-pci.txt line 32
Quoted 13 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt new file +13
-0+ #address-cells -- the number of address cells for PCI-space. + #size-cells -- the number of size cells for PCI-space. + ranges -- See [1]; a specification of the outbound windows for the host + controller. Each outbound window is described by a n-tuple: + (3 cells) -- PCIe space start address; one cell for attributes + and two cells for the 64-bit PCIe address. + (x cells) -- CPU/System start address, number of cells is determined + by the parent node's #address-cells. + (y cells) -- Size of region, number of cells determined by the + parent node's #size-cells. + Due to hardware limitations, there may be a maximum of four + non-contiguous ranges specified. + #interrupt-cells -- number of cells used to describe the interrupt.
How many cells?
Quoted 17 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt new file +17
-0+ interrupt-map-mask -- see [1]; four cells, the first three are zero + for our uses and the fourth cell is the mask (val = 0x7) for + the legacy interrupt number [1..4]. + interrupt-map -- See [1]; there are four interrupts (INTA, INTB, + INTC, and INTD) to be mapped; each interrupt requires 5 cells + plus the size of the interrupt specifier. + linux,pci-domain -- the domain of the host controller. + +Optional Properties: + clocks -- list of clock phandles. If specified, this should list one + clock. + clock-names -- the "local" names of the clocks specified in 'clocks'. Note + that if the 'clocks' property is given, 'clock-names' is mandatory, + and the name of the clock is expected to be "sw_pcie". + dma-ranges -- Similar in structure to ranges, each dma region is + specified with a n-tuple. Dma-regions describe the inbound + accesses from EP to RC; it translates the pci address that the
Documentation/devicetree/bindings/pci/brcmstb-pci.txt line 59
Quoted 10 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt new file +10
-0+ EP "sees" to the CPU address in memory. This property is needed + because the design of the Brcmstb memory subsystem often precludes + idenity-mapping between CPU address space and PCIe address space. + Each range is described by a n-tuple: + (3 cells) -- PCIe space start address; one cell for attributes + and two cells for the 64-bit PCIe address. + (x cells) -- CPU/System start address, number of cells is determined + by the parent node's #address-cells. + (y cells) -- Size of region, number of cells determined by the + parent node's #size-cells.
There's no need to describe standard properties. Just put whatever is specific to your platform. That applies throughout this doc.
Documentation/devicetree/bindings/pci/brcmstb-pci.txt line 68
Quoted 9 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt new file +9
-0+ msi-parent -- if MSI is to be used, this must be a phandle to the + msi-parent. If this prop is set to the phandle of the PCIe + node, or if the msi-parent prop is missing, the PCIE controller + will attempt to use its built in MSI controller. + msi-controller -- this property should only be specified if the + PCIe controller is using its internal MSI controller. + brcm,ssc -- (boolean) indicates usage of spread-spectrum clocking. + brcm,gen -- (integer) indicates desired generation of link: + 1 => 2.5 Gbps, 2 => 5.0 Gbps, 3 => 8.0 Gbps.
We have a standard property for this IIRC.
Documentation/devicetree/bindings/pci/brcmstb-pci.txt line 75
Quoted 7 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt new file +7
-0+ supply-names -- the names of voltage regulators that the root + complex should turn off/on/on on suspend/resume/boot. This + is a string list. + supplies -- A collection of phandles to a regulator nodes, see + Documentation/devicetree/bindings/regulator/ for specific + bindings. The number and order of phandles must match + exactly the number of strings in the "supply-names" property.
This is not the regulator binding. Use the standard binding.
Quoted 39 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt new file +31
-0+ +Example Node: + +pcie0: pcie at f0460000 { + reg = <0x0 0xf0460000 0x0 0x9310>; + interrupts = <0x0 0x0 0x4>; + compatible = "brcm,pci-plat-dev"; + #address-cells = <3>; + #size-cells = <2>; + ranges = <0x02000000 0x00000000 0x00000000 0x00000000 0xc0000000 0x00000000 0x08000000 + 0x02000000 0x00000000 0x08000000 0x00000000 0xc8000000 0x00000000 0x08000000>; + #interrupt-cells = <1>; + interrupt-map-mask = <0 0 0 7>; + interrupt-map = <0 0 0 1 &intc 0 47 3 + 0 0 0 2 &intc 0 48 3 + 0 0 0 3 &intc 0 49 3 + 0 0 0 4 &intc 0 50 3>; + interrupt-names = "pcie_0_inta", + "pcie_0_intb", + "pcie_0_intc", + "pcie_0_intd"; + clocks = <&sw_pcie0>; + clock-names = "sw_pcie"; + msi-parent = <&pcie0>; /* use PCIe's internal MSI controller */ + msi-controller; /* use PCIe's internal MSI controller */ + brcm,ssc; + brcm,gen = <1>; + supply-names = "vreg-wifi-pwr"; + supplies = <&vreg-wifi-pwr>; + linux,pci-domain = <0>; + };Signature · 7 lines
1.9.0.138.g2de3478 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel at lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH 2/9] PCI: host: brcmstb: add DT docs for Brcmstb PCIe device
Quoted 24 lines · Rob Herring
Quoted 23 lines · Jim Quinlan
The DT bindings description of the Brcmstb PCIe device is described. This node can be used by almost all Broadcom settop box chips, using ARM, ARM64, or MIPS CPU architectures.
Signed-off-by Jim Quinlan <[email protected]>--- .../devicetree/bindings/pci/brcmstb-pci.txt | 106 +++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 Documentation/devicetree/bindings/pci/brcmstb-pci.txtDocumentation/devicetree/bindings/pci/brcmstb-pci.txt new file +7
-0@@ -0,0 +1,106 @@ +Brcmstb PCIe Host Controller Device Tree Bindings +We don't; this line is erroneous. +Introduction: + The brcmstb host controller closely follows the example set in + + [1] http://devicetree.org/Device_Tree_Usage#PCI_Host_Bridge +
Quoted 9 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt line 13
Quoted 6 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt new file +6
-0+ The rest of this document explains some added customizations and + offers an example Brcmstb PCIe host controller DT node. + +Required Properties: + reg -- the register start address and length for the PCIe block. + Additional start,length pairs may be specified for clock addresses.Kind of vague and why do you need clock addresses and the clock binding?
We don't; this line is erroneous and will be removed.
Quoted 3 lines
Also, typically the config space is defined here? Is that missing or you don't support memory mapped config space?
We do not support memory mapped config space.
Quoted 9 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt line 19
Quoted 6 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt new file +6
-0+ interrupts -- two interrupts are specified; the first interrupt is for + the PCI host controller and the second is for MSI if the built-in + MSI controller is to be used. + interrupt-names -- names of the interrupts (above): "pcie" and "msi". + compatible -- must be one of: "brcm,bcm7425-pcie", "brcm,bcm7435-pcie", + or "brcm,bcm7278-pcie".One compatible per line.
Will fix.
Quoted 14 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt line 32
Quoted 13 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt new file +13
-0+ #address-cells -- the number of address cells for PCI-space. + #size-cells -- the number of size cells for PCI-space. + ranges -- See [1]; a specification of the outbound windows for the host + controller. Each outbound window is described by a n-tuple: + (3 cells) -- PCIe space start address; one cell for attributes + and two cells for the 64-bit PCIe address. + (x cells) -- CPU/System start address, number of cells is determined + by the parent node's #address-cells. + (y cells) -- Size of region, number of cells determined by the + parent node's #size-cells. + Due to hardware limitations, there may be a maximum of four + non-contiguous ranges specified.We don't; this line is erroneous. + #interrupt-cells -- number of cells used to describe the interrupt.
Quoted 2 lines
How many cells?
This line will be removed.
Quoted 22 lines
Quoted 22 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt new file +22
-0+ interrupt-map-mask -- see [1]; four cells, the first three are zero + for our uses and the fourth cell is the mask (val = 0x7) for + the legacy interrupt number [1..4]. + interrupt-map -- See [1]; there are four interrupts (INTA, INTB, + INTC, and INTD) to be mapped; each interrupt requires 5 cells + plus the size of the interrupt specifier. + linux,pci-domain -- the domain of the host controller. + +Optional Properties: + clocks -- list of clock phandles. If specified, this should list one + clock. + clock-names -- the "local" names of the clocks specified in 'clocks'. Note + that if the 'clocks' property is given, 'clock-names' is mandatory, + and the name of the clock is expected to be "sw_pcie". + dma-ranges -- Similar in structure to ranges, each dma region is + specified with a n-tuple. Dma-regions describe the inbound + accesses from EP to RC; it translates the pci address that the + EP "sees" to the CPU address in memory. This property is needed + because the design of the Brcmstb memory subsystem often precludes + idenity-mapping between CPU address space and PCIe address space. + Each range is described by a n-tuple: + (3 cells) -- PCIe space start address; one cell for attributes
Quoted 9 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt line 29
Quoted 5 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt new file +5
-0+ and two cells for the 64-bit PCIe address. + (x cells) -- CPU/System start address, number of cells is determined + by the parent node's #address-cells. + (y cells) -- Size of region, number of cells determined by the + parent node's #size-cells.There's no need to describe standard properties. Just put whatever is specific to your platform. That applies throughout this doc.
Will fix.
Quoted 10 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt line 68
Quoted 9 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt new file +9
-0+ msi-parent -- if MSI is to be used, this must be a phandle to the + msi-parent. If this prop is set to the phandle of the PCIe + node, or if the msi-parent prop is missing, the PCIE controller + will attempt to use its built in MSI controller. + msi-controller -- this property should only be specified if the + PCIe controller is using its internal MSI controller. + brcm,ssc -- (boolean) indicates usage of spread-spectrum clocking. + brcm,gen -- (integer) indicates desired generation of link: + 1 => 2.5 Gbps, 2 => 5.0 Gbps, 3 => 8.0 Gbps.
Quoted 2 lines
We have a standard property for this IIRC.
Yes, BrianN pointed that out and it will be fixed.
Quoted 10 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt line 75
Quoted 7 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt new file +7
-0+ supply-names -- the names of voltage regulators that the root + complex should turn off/on/on on suspend/resume/boot. This + is a string list. + supplies -- A collection of phandles to a regulator nodes, see + Documentation/devicetree/bindings/regulator/ for specificWe don't; this line is erroneous. + bindings. The number and order of phandles must match + exactly the number of strings in the "supply-names" property.This is not the regulator binding. Use the standard binding.
The reason we do it this way is because the PCIe controller does not know or care what the names of the supplies are, or how many there will be. The list of regulators can be different for each board we support, as these regulators turn on/off the downstream EP device. All the PCIe controller does is turn on/off this list of regulators when booting,resuming/suspending.
An alternative would have the node specifying the standard properties
xyz-supply = <&xyz_reg>;
abc-supply = <&abc_reg>;
pdq-supply = <&pdq_reg>;
...
and then have this driver search all of the properties in the PCIe node for names matching /-supply$/, and then create a list of phandles from that. Is that what you would like?
Thanks, Jim
Quoted 39 lines
Quoted 39 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt new file +31
-1+ +Example Node: + +pcie0: pcie at f0460000 { + reg = <0x0 0xf0460000 0x0 0x9310>; + interrupts = <0x0 0x0 0x4>; + compatible = "brcm,pci-plat-dev"; + #address-cells = <3>; + #size-cells = <2>; + ranges = <0x02000000 0x00000000 0x00000000 0x00000000 0xc0000000 0x00000000 0x08000000 + 0x02000000 0x00000000 0x08000000 0x00000000 0xc8000000 0x00000000 0x08000000>; + #interrupt-cells = <1>; + interrupt-map-mask = <0 0 0 7>; + interrupt-map = <0 0 0 1 &intc 0 47 3 + 0 0 0 2 &intc 0 48 3 + 0 0 0 3 &intc 0 49 3 + 0 0 0 4 &intc 0 50 3>; + interrupt-names = "pcie_0_inta", + "pcie_0_intb", + "pcie_0_intc", + "pcie_0_intd"; + clocks = <&sw_pcie0>; + clock-names = "sw_pcie"; + msi-parent = <&pcie0>; /* use PCIe's internal MSI controller */ + msi-controller; /* use PCIe's internal MSI controller */ + brcm,ssc; + brcm,gen = <1>; + supply-names = "vreg-wifi-pwr"; + supplies = <&vreg-wifi-pwr>; + linux,pci-domain = <0>; + }; --1.9.0.138.g2de3478
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Rob Herring
maintainerRe: [PATCH 2/9] PCI: host: brcmstb: add DT docs for Brcmstb PCIe device
Quoted 66 lines · Jim Quinlan
Quoted 24 lines · Rob Herring
Quoted 23 lines · Jim Quinlan
The DT bindings description of the Brcmstb PCIe device is described. This node can be used by almost all Broadcom settop box chips, using ARM, ARM64, or MIPS CPU architectures.
Signed-off-by Jim Quinlan <[email protected]>--- .../devicetree/bindings/pci/brcmstb-pci.txt | 106 +++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 Documentation/devicetree/bindings/pci/brcmstb-pci.txtDocumentation/devicetree/bindings/pci/brcmstb-pci.txt new file +7
-0@@ -0,0 +1,106 @@ +Brcmstb PCIe Host Controller Device Tree Bindings +We don't; this line is erroneous. +Introduction: + The brcmstb host controller closely follows the example set in + + [1] http://devicetree.org/Device_Tree_Usage#PCI_Host_Bridge +Quoted 9 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt line 13
Quoted 6 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt new file +6
-0+ The rest of this document explains some added customizations and + offers an example Brcmstb PCIe host controller DT node. + +Required Properties: + reg -- the register start address and length for the PCIe block. + Additional start,length pairs may be specified for clock addresses.Kind of vague and why do you need clock addresses and the clock binding?
We don't; this line is erroneous and will be removed.
Quoted 3 lines
Also, typically the config space is defined here? Is that missing or you don't support memory mapped config space?
We do not support memory mapped config space.
Quoted 9 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt line 19
Quoted 6 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt new file +6
-0+ interrupts -- two interrupts are specified; the first interrupt is for + the PCI host controller and the second is for MSI if the built-in + MSI controller is to be used. + interrupt-names -- names of the interrupts (above): "pcie" and "msi". + compatible -- must be one of: "brcm,bcm7425-pcie", "brcm,bcm7435-pcie", + or "brcm,bcm7278-pcie".One compatible per line.
Will fix.
Quoted 14 lines
Quoted 13 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt new file +13
-0+ #address-cells -- the number of address cells for PCI-space. + #size-cells -- the number of size cells for PCI-space. + ranges -- See [1]; a specification of the outbound windows for the host + controller. Each outbound window is described by a n-tuple: + (3 cells) -- PCIe space start address; one cell for attributes + and two cells for the 64-bit PCIe address. + (x cells) -- CPU/System start address, number of cells is determined + by the parent node's #address-cells. + (y cells) -- Size of region, number of cells determined by the + parent node's #size-cells. + Due to hardware limitations, there may be a maximum of four + non-contiguous ranges specified.We don't; this line is erroneous. + #interrupt-cells -- number of cells used to describe the interrupt.
Quoted 3 lines
Quoted 2 lines
How many cells?
This line will be removed.
Humm, why? You need it to have interrupt-map. You just need to say what the value is, not what the property is.
Quoted 66 lines
Quoted 22 lines
Quoted 22 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt new file +22
-0+ interrupt-map-mask -- see [1]; four cells, the first three are zero + for our uses and the fourth cell is the mask (val = 0x7) for + the legacy interrupt number [1..4]. + interrupt-map -- See [1]; there are four interrupts (INTA, INTB, + INTC, and INTD) to be mapped; each interrupt requires 5 cells + plus the size of the interrupt specifier. + linux,pci-domain -- the domain of the host controller. + +Optional Properties: + clocks -- list of clock phandles. If specified, this should list one + clock. + clock-names -- the "local" names of the clocks specified in 'clocks'. Note + that if the 'clocks' property is given, 'clock-names' is mandatory, + and the name of the clock is expected to be "sw_pcie". + dma-ranges -- Similar in structure to ranges, each dma region is + specified with a n-tuple. Dma-regions describe the inbound + accesses from EP to RC; it translates the pci address that the + EP "sees" to the CPU address in memory. This property is needed + because the design of the Brcmstb memory subsystem often precludes + idenity-mapping between CPU address space and PCIe address space. + Each range is described by a n-tuple: + (3 cells) -- PCIe space start address; one cell for attributesQuoted 9 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt line 29
Quoted 5 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt new file +5
-0+ and two cells for the 64-bit PCIe address. + (x cells) -- CPU/System start address, number of cells is determined + by the parent node's #address-cells. + (y cells) -- Size of region, number of cells determined by the + parent node's #size-cells.There's no need to describe standard properties. Just put whatever is specific to your platform. That applies throughout this doc.
Will fix.
Quoted 10 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt line 68
Quoted 9 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt new file +9
-0+ msi-parent -- if MSI is to be used, this must be a phandle to the + msi-parent. If this prop is set to the phandle of the PCIe + node, or if the msi-parent prop is missing, the PCIE controller + will attempt to use its built in MSI controller. + msi-controller -- this property should only be specified if the + PCIe controller is using its internal MSI controller. + brcm,ssc -- (boolean) indicates usage of spread-spectrum clocking. + brcm,gen -- (integer) indicates desired generation of link: + 1 => 2.5 Gbps, 2 => 5.0 Gbps, 3 => 8.0 Gbps.Quoted 2 lines
We have a standard property for this IIRC.
Yes, BrianN pointed that out and it will be fixed.
Quoted 10 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt line 75
Quoted 7 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt new file +7
-0+ supply-names -- the names of voltage regulators that the root + complex should turn off/on/on on suspend/resume/boot. This + is a string list. + supplies -- A collection of phandles to a regulator nodes, see + Documentation/devicetree/bindings/regulator/ for specificWe don't; this line is erroneous. + bindings. The number and order of phandles must match + exactly the number of strings in the "supply-names" property.This is not the regulator binding. Use the standard binding.
The reason we do it this way is because the PCIe controller does not know or care what the names of the supplies are, or how many there will be. The list of regulators can be different for each board we support, as these regulators turn on/off the downstream EP device. All the PCIe controller does is turn on/off this list of regulators when booting,resuming/suspending.
An alternative would have the node specifying the standard properties
Quoted 8 lines
xyz-supply = <
&xyz_reg>;
abc-supply = <&abc_reg>;
pdq-supply = <&pdq_reg>;
...and then have this driver search all of the properties in the PCIe node for names matching /-supply$/, and then create a list of phandles from that. Is that what you would like?
Really, you should have child nodes of the PCIe devices and have the supplies in there.
The driver could do what you describe, but you've still got to define the names here.
Rob
Re: [PATCH 2/9] PCI: host: brcmstb: add DT docs for Brcmstb PCIe device
Quoted 145 lines · Rob Herring
Quoted 66 lines · Jim Quinlan
Quoted 24 lines · Rob Herring
Quoted 23 lines · Jim Quinlan
The DT bindings description of the Brcmstb PCIe device is described. This node can be used by almost all Broadcom settop box chips, using ARM, ARM64, or MIPS CPU architectures.
Signed-off-by Jim Quinlan <[email protected]>--- .../devicetree/bindings/pci/brcmstb-pci.txt | 106 +++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 Documentation/devicetree/bindings/pci/brcmstb-pci.txtDocumentation/devicetree/bindings/pci/brcmstb-pci.txt new file +7
-0@@ -0,0 +1,106 @@ +Brcmstb PCIe Host Controller Device Tree Bindings +We don't; this line is erroneous. +Introduction: + The brcmstb host controller closely follows the example set in + + [1] http://devicetree.org/Device_Tree_Usage#PCI_Host_Bridge +Quoted 9 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt line 13
Quoted 6 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt new file +6
-0+ The rest of this document explains some added customizations and + offers an example Brcmstb PCIe host controller DT node. + +Required Properties: + reg -- the register start address and length for the PCIe block. + Additional start,length pairs may be specified for clock addresses.Kind of vague and why do you need clock addresses and the clock binding?
We don't; this line is erroneous and will be removed.
Quoted 3 lines
Also, typically the config space is defined here? Is that missing or you don't support memory mapped config space?
We do not support memory mapped config space.
Quoted 9 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt line 19
Quoted 6 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt new file +6
-0+ interrupts -- two interrupts are specified; the first interrupt is for + the PCI host controller and the second is for MSI if the built-in + MSI controller is to be used. + interrupt-names -- names of the interrupts (above): "pcie" and "msi". + compatible -- must be one of: "brcm,bcm7425-pcie", "brcm,bcm7435-pcie", + or "brcm,bcm7278-pcie".One compatible per line.
Will fix.
Quoted 14 lines
Quoted 13 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt new file +13
-0+ #address-cells -- the number of address cells for PCI-space. + #size-cells -- the number of size cells for PCI-space. + ranges -- See [1]; a specification of the outbound windows for the host + controller. Each outbound window is described by a n-tuple: + (3 cells) -- PCIe space start address; one cell for attributes + and two cells for the 64-bit PCIe address. + (x cells) -- CPU/System start address, number of cells is determined + by the parent node's #address-cells. + (y cells) -- Size of region, number of cells determined by the + parent node's #size-cells. + Due to hardware limitations, there may be a maximum of four + non-contiguous ranges specified.We don't; this line is erroneous. + #interrupt-cells -- number of cells used to describe the interrupt.Quoted 3 lines
Quoted 2 lines
How many cells?
This line will be removed.
Humm, why? You need it to have interrupt-map. You just need to say what the value is, not what the property is.
Quoted 71 lines
Quoted 22 lines
Quoted 22 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt new file +22
-0+ interrupt-map-mask -- see [1]; four cells, the first three are zero + for our uses and the fourth cell is the mask (val = 0x7) for + the legacy interrupt number [1..4]. + interrupt-map -- See [1]; there are four interrupts (INTA, INTB, + INTC, and INTD) to be mapped; each interrupt requires 5 cells + plus the size of the interrupt specifier. + linux,pci-domain -- the domain of the host controller. + +Optional Properties: + clocks -- list of clock phandles. If specified, this should list one + clock. + clock-names -- the "local" names of the clocks specified in 'clocks'. Note + that if the 'clocks' property is given, 'clock-names' is mandatory, + and the name of the clock is expected to be "sw_pcie". + dma-ranges -- Similar in structure to ranges, each dma region is + specified with a n-tuple. Dma-regions describe the inbound + accesses from EP to RC; it translates the pci address that the + EP "sees" to the CPU address in memory. This property is needed + because the design of the Brcmstb memory subsystem often precludes + idenity-mapping between CPU address space and PCIe address space. + Each range is described by a n-tuple: + (3 cells) -- PCIe space start address; one cell for attributesQuoted 9 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt line 29
Quoted 5 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt new file +5
-0+ and two cells for the 64-bit PCIe address. + (x cells) -- CPU/System start address, number of cells is determined + by the parent node's #address-cells. + (y cells) -- Size of region, number of cells determined by the + parent node's #size-cells.There's no need to describe standard properties. Just put whatever is specific to your platform. That applies throughout this doc.
Will fix.
Quoted 10 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt line 68
Quoted 9 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt new file +9
-0+ msi-parent -- if MSI is to be used, this must be a phandle to the + msi-parent. If this prop is set to the phandle of the PCIe + node, or if the msi-parent prop is missing, the PCIE controller + will attempt to use its built in MSI controller. + msi-controller -- this property should only be specified if the + PCIe controller is using its internal MSI controller. + brcm,ssc -- (boolean) indicates usage of spread-spectrum clocking. + brcm,gen -- (integer) indicates desired generation of link: + 1 => 2.5 Gbps, 2 => 5.0 Gbps, 3 => 8.0 Gbps.Quoted 2 lines
We have a standard property for this IIRC.
Yes, BrianN pointed that out and it will be fixed.
Quoted 10 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt line 75
Quoted 7 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt new file +7
-0+ supply-names -- the names of voltage regulators that the root + complex should turn off/on/on on suspend/resume/boot. This + is a string list. + supplies -- A collection of phandles to a regulator nodes, see + Documentation/devicetree/bindings/regulator/ for specificWe don't; this line is erroneous. + bindings. The number and order of phandles must match + exactly the number of strings in the "supply-names" property.This is not the regulator binding. Use the standard binding.
The reason we do it this way is because the PCIe controller does not know or care what the names of the supplies are, or how many there will be. The list of regulators can be different for each board we support, as these regulators turn on/off the downstream EP device. All the PCIe controller does is turn on/off this list of regulators when booting,resuming/suspending.
An alternative would have the node specifying the standard properties
xyz-supply = <
&xyz_reg>;
abc-supply = <&abc_reg>;
pdq-supply = <&pdq_reg>;
...
Quoted 6 lines
Quoted 3 lines
and then have this driver search all of the properties in the PCIe node for names matching /-supply$/, and then create a list of phandles from that. Is that what you would like?
Really, you should have child nodes of the PCIe devices and have the supplies in there.
While that would be technically more correct this poses a number of issues:
- there is precedence in that area, and you already Acked binding documents proposing the same thing:
* Documentation/devicetree/bindings/pci/fsl,imx6q-pcie.txt (commitc26ebe98a103479dae9284fe0a86a95af4a5cd46)
* Documentation/devicetree/bindings/pci/rockchip-pcie.txt (commit828bdcfbdb98eeb97facb05fe6c96ba0aed65c4a and before)
(which may indicate those should also be corrected, at the possible expense of creating incompatibilities)
- there is a chicken and egg problem, you can't detect the EP without turning its regulator on, and if you can't create a pci_device, you certainly won't be able to associate it with an device_node counterpart
- PCIe being dynamic by nature, can you have "wildcard" PCIE EP DT node that would be guaranteed to match any physically attached PCIE EP which is discovered by the PCI bus layer (and then back to issue #2)
If we can solve #2 and #3, it would be reasonable to move the regulator to a PCIE EP node. Ideally, we may want the generic PCI layer to be responsible for managing regulators within pci_enable_device() and pci_disable_device() for instance?
Quoted 6 lines
The driver could do what you describe, but you've still got to define the names here.
Rob
Signature · 1 line
Florian
Re: [PATCH 2/9] PCI: host: brcmstb: add DT docs for Brcmstb PCIe device
Hi,
Quoted 26 lines · Florian Fainelli
Quoted 18 lines · Rob Herring
Quoted 17 lines · Jim Quinlan
Quoted 2 lines · Rob Herring
This is not the regulator binding. Use the standard binding.
The reason we do it this way is because the PCIe controller does not know or care what the names of the supplies are, or how many there will be. The list of regulators can be different for each board we support, as these regulators turn on/off the downstream EP device. All the PCIe controller does is turn on/off this list of regulators when booting,resuming/suspending.
An alternative would have the node specifying the standard properties
xyz-supply = <
&xyz_reg>;
abc-supply = <&abc_reg>;
pdq-supply = <&pdq_reg>;
...Quoted 6 lines
Quoted 3 lines
and then have this driver search all of the properties in the PCIe node for names matching /-supply$/, and then create a list of phandles from that. Is that what you would like?
Really, you should have child nodes of the PCIe devices and have the supplies in there.
Quoted 8 lines
While that would be technically more correct this poses a number of issues:
- there is precedence in that area, and you already Acked binding documents proposing the same thing:
*Documentation/devicetree/bindings/pci/fsl,imx6q-pcie.txt(commitc26ebe98a103479dae9284fe0a86a95af4a5cd46)
*Documentation/devicetree/bindings/pci/rockchip-pcie.txt(commit828bdcfbdb98eeb97facb05fe6c96ba0aed65c4aand before)
I can actually speak to the Rockchip binding a bit :)
It actually has a mixture of true controller regulators (e.g., the 1.8V and 0.9V regulators power analog portions of the SoC's PCIe logic) and controls for the PCIe endpoints (e.g., 12V). Additionally, some of these have been misused to represent a little of both, since the regulator framework is actually quite flexible ;)
That may or may not help, but they are at least partially correct.
The Freescale one does look like it's plainly *not* about the root controller.
Also, those rails *are* all fairly well defined by the various PCIe electromechanical specifications, so isn't it reasonable to expect that a controller can optionally control power for 1 of each of the standard power types? Or do we really want to represent the flexibility that there can be up to N of each type for N endpoints?
As a side note: it's also been pretty tough to get the power sequencing requirements represented correctly for some PCIe endpoints. I've tried to make use of this previously, but the series took so long (>1 year and counting!) my team lost interest:
[PATCH v16 2/7] power: add power sequence library
https://www.spinics.net/lists/linux-usb/msg158452.html
It doesn't really solve all of this problem, but it could be worth looking at.
Quoted 2 lines
(which may indicate those should also be corrected, at the possible expense of creating incompatibilities)
If a better way is developed, we can always augment the bindings. The current bindings aren't that hard to maintain as "deprecated backups."
Quoted 3 lines
- there is a chicken and egg problem, you can't detect the EP without turning its regulator on, and if you can't create a
pci_device, you certainly won't be able to associate it with andevice_nodecounterpart
That's definitely a major problem driving some of the current bindings. We're just not set up to walk the child devices if we can't probe them.
Quoted 3 lines
- PCIe being dynamic by nature, can you have "wildcard" PCIE EP DT node that would be guaranteed to match any physically attached PCIE EP which is discovered by the PCI bus layer (and then back to issue #2)
Technically, you *can* walk the DT (i.e., 'device_node's) without having pci_dev's for each yet. Something like of_pci_find_child_device() would do it. But that still seems kind of wonky, and it's currently neither precise enough nor flexible enough for this, I don't think.
Brian
Quoted 15 lines
If we can solve #2 and #3, it would be reasonable to move the regulator to a PCIE EP node. Ideally, we may want the generic PCI layer to be responsible for managing regulators within
pci_enable_device()andpci_disable_device()for instance?Quoted 6 lines
The driver could do what you describe, but you've still got to define the names here.
Rob
Signature · 1 line
Florian
Rob Herring
maintainerRe: [PATCH 2/9] PCI: host: brcmstb: add DT docs for Brcmstb PCIe device
Quoted 46 lines · Brian Norris
Hi,
Quoted 26 lines · Florian Fainelli
Quoted 18 lines · Rob Herring
Quoted 17 lines · Jim Quinlan
Quoted 2 lines · Rob Herring
This is not the regulator binding. Use the standard binding.
The reason we do it this way is because the PCIe controller does not know or care what the names of the supplies are, or how many there will be. The list of regulators can be different for each board we support, as these regulators turn on/off the downstream EP device. All the PCIe controller does is turn on/off this list of regulators when booting,resuming/suspending.
An alternative would have the node specifying the standard properties
xyz-supply = <
&xyz_reg>;
abc-supply = <&abc_reg>;
pdq-supply = <&pdq_reg>;
...Quoted 6 lines
Quoted 3 lines
and then have this driver search all of the properties in the PCIe node for names matching /-supply$/, and then create a list of phandles from that. Is that what you would like?
Really, you should have child nodes of the PCIe devices and have the supplies in there.
Quoted 8 lines
While that would be technically more correct this poses a number of issues:
- there is precedence in that area, and you already Acked binding documents proposing the same thing:
*Documentation/devicetree/bindings/pci/fsl,imx6q-pcie.txt(commitc26ebe98a103479dae9284fe0a86a95af4a5cd46)
*Documentation/devicetree/bindings/pci/rockchip-pcie.txt(commit828bdcfbdb98eeb97facb05fe6c96ba0aed65c4aand before)I can actually speak to the Rockchip binding a bit :)
It actually has a mixture of true controller regulators (e.g., the 1.8V and 0.9V regulators power analog portions of the SoC's PCIe logic) and controls for the PCIe endpoints (e.g., 12V). Additionally, some of these have been misused to represent a little of both, since the regulator framework is actually quite flexible ;)
Quoted 4 lines
That may or may not help, but they are at least partially correct.
The Freescale one does look like it's plainly *not* about the root controller.
Maybe not. I don't find that to be obvious reading the binding.
Quoted 4 lines
Also, those rails *are* all fairly well defined by the various PCIe electromechanical specifications, so isn't it reasonable to expect that a controller can optionally control power for 1 of each of the standard power types?
That seems okay. The MMC binding is done that way.
I never said you can't just put things in the host node. That's just not an ideal match to the h/w and there's a limit to what makes sense.
Quoted 2 lines
Or do we really want to represent the flexibility that there can be up to N of each type for N endpoints?
No, then you need to describe the topology.
Quoted 17 lines
As a side note: it's also been pretty tough to get the power sequencing requirements represented correctly for some PCIe endpoints. I've tried to make use of this previously, but the series took so long (>1 year and counting!) my team lost interest:
[PATCH v16 2/7] power: add power sequence library
https://www.spinics.net/lists/linux-usb/msg158452.htmlIt doesn't really solve all of this problem, but it could be worth looking at.
Quoted 2 lines
(which may indicate those should also be corrected, at the possible expense of creating incompatibilities)
If a better way is developed, we can always augment the bindings. The current bindings aren't that hard to maintain as "deprecated backups."
Quoted 6 lines
Quoted 3 lines
- there is a chicken and egg problem, you can't detect the EP without turning its regulator on, and if you can't create a
pci_device, you certainly won't be able to associate it with andevice_nodecounterpartThat's definitely a major problem driving some of the current bindings. We're just not set up to walk the child devices if we can't probe them.
It's common to all the probeable buses that still need DT additions.
Quoted 8 lines
Quoted 3 lines
- PCIe being dynamic by nature, can you have "wildcard" PCIE EP DT node that would be guaranteed to match any physically attached PCIE EP which is discovered by the PCI bus layer (and then back to issue #2)
Technically, you *can* walk the DT (i.e., 'device_node's) without having pci_dev's for each yet. Something like
of_pci_find_child_device()would do it. But that still seems kind of wonky, and it's currently neither precise enough nor flexible enough for this, I don't think.
That's essentially what the generic power seq stuff tries to do. I said early on we need some sort of pre-probe hook for drivers. Trying to handle things generically only gets you so far. There will always be that special case that needs specific handling.
Rob
Re: [PATCH 2/9] PCI: host: brcmstb: add DT docs for Brcmstb PCIe device
In reply to Rob HerringQuoted 67 lines · Rob Herring
Quoted 66 lines · Jim Quinlan
Quoted 24 lines · Rob Herring
Quoted 23 lines · Jim Quinlan
The DT bindings description of the Brcmstb PCIe device is described. This node can be used by almost all Broadcom settop box chips, using ARM, ARM64, or MIPS CPU architectures.
Signed-off-by Jim Quinlan <[email protected]>--- .../devicetree/bindings/pci/brcmstb-pci.txt | 106 +++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 Documentation/devicetree/bindings/pci/brcmstb-pci.txtDocumentation/devicetree/bindings/pci/brcmstb-pci.txt new file +7
-0@@ -0,0 +1,106 @@ +Brcmstb PCIe Host Controller Device Tree Bindings +We don't; this line is erroneous. +Introduction: + The brcmstb host controller closely follows the example set in + + [1] http://devicetree.org/Device_Tree_Usage#PCI_Host_Bridge +Quoted 9 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt line 13
Quoted 6 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt new file +6
-0+ The rest of this document explains some added customizations and + offers an example Brcmstb PCIe host controller DT node. + +Required Properties: + reg -- the register start address and length for the PCIe block. + Additional start,length pairs may be specified for clock addresses.Kind of vague and why do you need clock addresses and the clock binding?
We don't; this line is erroneous and will be removed.
Quoted 3 lines
Also, typically the config space is defined here? Is that missing or you don't support memory mapped config space?
We do not support memory mapped config space.
Quoted 9 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt line 19
Quoted 6 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt new file +6
-0+ interrupts -- two interrupts are specified; the first interrupt is for + the PCI host controller and the second is for MSI if the built-in + MSI controller is to be used. + interrupt-names -- names of the interrupts (above): "pcie" and "msi". + compatible -- must be one of: "brcm,bcm7425-pcie", "brcm,bcm7435-pcie", + or "brcm,bcm7278-pcie".One compatible per line.
Will fix.
Quoted 14 lines
Quoted 13 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt new file +13
-0+ #address-cells -- the number of address cells for PCI-space. + #size-cells -- the number of size cells for PCI-space. + ranges -- See [1]; a specification of the outbound windows for the host + controller. Each outbound window is described by a n-tuple: + (3 cells) -- PCIe space start address; one cell for attributes + and two cells for the 64-bit PCIe address. + (x cells) -- CPU/System start address, number of cells is determined + by the parent node's #address-cells. + (y cells) -- Size of region, number of cells determined by the + parent node's #size-cells. + Due to hardware limitations, there may be a maximum of four + non-contiguous ranges specified.We don't; this line is erroneous. + #interrupt-cells -- number of cells used to describe the interrupt.
Quoted 6 lines
Quoted 3 lines
Quoted 2 lines
How many cells?
This line will be removed.
Humm, why? You need it to have interrupt-map. You just need to say what the value is, not what the property is.
Okay, I got this from
https://elinux.org/Device_Tree_Usage#Advanced_Interrupt_Mapping which says that
"First you'll notice that PCI interrupt numbers use only one cell, unlike the system interrupt controller which uses 2 cells; one for the irq number, and one for flags. PCI only needs one cell for interrupts because PCI interrupts are specified to always be level-low sensitive." Is that not the convention for legacy PCI interrupts?
Quoted 83 lines
Quoted 67 lines
Quoted 23 lines
Quoted 23 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt new file +22
-0+ interrupt-map-mask -- see [1]; four cells, the first three are zero + for our uses and the fourth cell is the mask (val = 0x7) for + the legacy interrupt number [1..4]. + interrupt-map -- See [1]; there are four interrupts (INTA, INTB, + INTC, and INTD) to be mapped; each interrupt requires 5 cells + plus the size of the interrupt specifier. + linux,pci-domain -- the domain of the host controller. + +Optional Properties: + clocks -- list of clock phandles. If specified, this should list one + clock. + clock-names -- the "local" names of the clocks specified in 'clocks'. Note + that if the 'clocks' property is given, 'clock-names' is mandatory, + and the name of the clock is expected to be "sw_pcie". + dma-ranges -- Similar in structure to ranges, each dma region is + specified with a n-tuple. Dma-regions describe the inbound + accesses from EP to RC; it translates the pci address that the + EP "sees" to the CPU address in memory. This property is needed + because the design of the Brcmstb memory subsystem often precludes + idenity-mapping between CPU address space and PCIe address space. + Each range is described by a n-tuple: + (3 cells) -- PCIe space start address; one cell for attributesQuoted 9 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt line 29
Quoted 5 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt new file +5
-0+ and two cells for the 64-bit PCIe address. + (x cells) -- CPU/System start address, number of cells is determined + by the parent node's #address-cells. + (y cells) -- Size of region, number of cells determined by the + parent node's #size-cells.There's no need to describe standard properties. Just put whatever is specific to your platform. That applies throughout this doc.
Will fix.
Quoted 10 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt line 68
Quoted 9 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt new file +9
-0+ msi-parent -- if MSI is to be used, this must be a phandle to the + msi-parent. If this prop is set to the phandle of the PCIe + node, or if the msi-parent prop is missing, the PCIE controller + will attempt to use its built in MSI controller. + msi-controller -- this property should only be specified if the + PCIe controller is using its internal MSI controller. + brcm,ssc -- (boolean) indicates usage of spread-spectrum clocking. + brcm,gen -- (integer) indicates desired generation of link: + 1 => 2.5 Gbps, 2 => 5.0 Gbps, 3 => 8.0 Gbps.Quoted 2 lines
We have a standard property for this IIRC.
Yes, BrianN pointed that out and it will be fixed.
Quoted 10 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt line 75
Quoted 7 lines
Documentation/devicetree/bindings/pci/brcmstb-pci.txt new file +7
-0+ supply-names -- the names of voltage regulators that the root + complex should turn off/on/on on suspend/resume/boot. This + is a string list. + supplies -- A collection of phandles to a regulator nodes, see + Documentation/devicetree/bindings/regulator/ for specificWe don't; this line is erroneous. + bindings. The number and order of phandles must match + exactly the number of strings in the "supply-names" property.This is not the regulator binding. Use the standard binding.
The reason we do it this way is because the PCIe controller does not know or care what the names of the supplies are, or how many there will be. The list of regulators can be different for each board we support, as these regulators turn on/off the downstream EP device. All the PCIe controller does is turn on/off this list of regulators when booting,resuming/suspending.
An alternative would have the node specifying the standard properties
Quoted 8 lines
xyz-supply = <
&xyz_reg>;
abc-supply = <&abc_reg>;
pdq-supply = <&pdq_reg>;
...and then have this driver search all of the properties in the PCIe node for names matching /-supply$/, and then create a list of phandles from that. Is that what you would like?
Really, you should have child nodes of the PCIe devices and have the supplies in there.
The driver could do what you describe, but you've still got to define the names here.
Rob
PATCH 3/9 PCI: host: brcmstb: Broadcom PCIe Host Controller
In reply to Jim QuinlanThis commit adds the basic Broadcom STB PCIe controller. Missing is the ability to process MSI and also handle dma-ranges for inbound memory accesses. These two functionalities are added in subsequent commits.
The PCIe block contains an MDIO interface. This is a local interface only accessible by the PCIe controller. It cannot be used or shared by any other HW. As such, the small amount of code for this controller is included in this driver as there is little upside to put it elsewhere.
--- drivers/pci/host/Kconfig | 8 + drivers/pci/host/Makefile | 1 + drivers/pci/host/pci-brcmstb.c | 1191 ++++++++++++++++++++++++++++++++++++++++ drivers/pci/host/pci-brcmstb.h | 33 ++ 4 files changed, 1233 insertions(+) create mode 100644 drivers/pci/host/pci-brcmstb.c create mode 100644 drivers/pci/host/pci-brcmstb.h
drivers/pci/host/Kconfig +8 -0
@@ -220,4 +220,12 @@ config VMD To compile this driver as a module, choose M here: the module will be called vmd. +config PCI_BRCMSTB + tristate "Broadcom Brcmstb PCIe platform host driver" + depends on ARCH_BRCMSTB || BMIPS_GENERIC + depends on OF + depends on SOC_BRCMSTB + default ARCH_BRCMSTB || BMIPS_GENERIC + help + Adds support for Broadcom Settop Box PCIe host controller. endmenu
drivers/pci/host/Makefile +1 -0
@@ -21,6 +21,7 @@ obj-$(CONFIG_PCIE_ROCKCHIP) += pcie-rockchip.o obj-$(CONFIG_PCIE_MEDIATEK) += pcie-mediatek.o obj-$(CONFIG_PCIE_TANGO_SMP8759) += pcie-tango.o obj-$(CONFIG_VMD) += vmd.o +obj-$(CONFIG_PCI_BRCMSTB) += pci-brcmstb.o # The following drivers are for devices that use the generic ACPI # pci_root.c driver but don't support standard ECAM config access.
drivers/pci/host/pci-brcmstb.c new file +1191 -0
1,191 lines not on this page · raw message
drivers/pci/host/pci-brcmstb.h new file +33 -0
@@ -0,0 +1,33 @@ +#ifndef __BRCMSTB_PCI_H +#define __BRCMSTB_PCI_H + +/* +* Copyright (C) 2015 - 2017 Broadcom +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#define BRCM_PCIE_NAME_SIZE 8 +#define BRCM_INT_PCI_MSI_NR 32 +#define BRCM_PCIE_HW_REV_33 0x0303 + +/* Broadcom PCIE Offsets */ +#define PCIE_INTR2_CPU_BASE 0x4300 + +#if defined(CONFIG_MIPS ) +/* Broadcom MIPs HW implicitly does the swapping if necessary */ +#define bcm_readl (a) __raw_readl(a) +#define bcm_writel (d, a) __raw_writel(d, a) +#else +#define bcm_readl (a) readl(a) +#define bcm_writel (d, a) writel(d, a) +#endif + +#endif /* __BRCMSTB_PCI_H */
Signature · 1 line
1.9.0.138.g2de3478
PATCH 4/9 arm64: dma-mapping: export symbol arch_setup_dma_ops
In reply to Jim QuinlanThe BrcmSTB driver needs to get ahold of a pointer to swiotlb_dma_ops. However, that variable is defined as static. Instead, we use arch_setup_dma_ops() to get the pointer to swiotlb_dma_ops. Since we also want our driver to be a separate module, we need to export this function.
--- arch/arm64/mm/dma-mapping.c | 1 + 1 file changed, 1 insertion(+)
arch/arm64/mm/dma-mapping.c +1 -0
@@ -936,3 +936,4 @@ void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size, }#endif } +EXPORT_SYMBOL (arch_setup_dma_ops);
Signature · 1 line
1.9.0.138.g2de3478
Re: [PATCH 4/9] arm64: dma-mapping: export symbol arch_setup_dma_ops
Quoted 5 lines · Jim Quinlan
The BrcmSTB driver needs to get ahold of a pointer to
swiotlb_dma_ops. However, that variable is defined as static. Instead, we usearch_setup_dma_ops()to get the pointer toswiotlb_dma_ops. Since we also want our driver to be a separate module, we need to export this function.
NAK. Retrieve the platform-assigned ops from the device via get_dma_ops() and stash them in your drvdata or wherever before you replace them. Don't go poking around arch code internals directly from a driver.
Robin.
Quoted 15 lines
Signed-off-by Jim Quinlan <[email protected]>--- arch/arm64/mm/dma-mapping.c | 1 + 1 file changed, 1 insertion(+)arch/arm64/mm/dma-mapping.c +1
-0@@ -936,3 +936,4 @@ void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size, }#endif } +EXPORT_SYMBOL (arch_setup_dma_ops);
Re: [PATCH 4/9] arm64: dma-mapping: export symbol arch_setup_dma_ops
Quoted 11 lines · Robin Murphy
Quoted 5 lines · Jim Quinlan
The BrcmSTB driver needs to get ahold of a pointer to
swiotlb_dma_ops. However, that variable is defined as static. Instead, we usearch_setup_dma_ops()to get the pointer toswiotlb_dma_ops. Since we also want our driver to be a separate module, we need to export this function.NAK. Retrieve the platform-assigned ops from the device via
get_dma_ops()and stash them in your drvdata or wherever before you replace them. Don't go poking around arch code internals directly from a driver.
Will fix (and drop the commit).
Quoted 19 lines
Robin.
Quoted 15 lines
Signed-off-by Jim Quinlan <[email protected]>--- arch/arm64/mm/dma-mapping.c | 1 + 1 file changed, 1 insertion(+)arch/arm64/mm/dma-mapping.c +1
-0@@ -936,3 +936,4 @@ void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size, }#endif } +EXPORT_SYMBOL (arch_setup_dma_ops);
PATCH 5/9 PCI: host: brcmstb: add dma-ranges for inbound traffic
In reply to Jim QuinlanThe Broadcom STB PCIe host controller is intimately related to the memory subsystem. This close relationship adds complexity to how cpu system memory is mapped to PCIe memory. Ideally, this mapping is an identity mapping, or an identity mapping off by a constant. Not so in this case.
Consider the Broadcom reference board BCM97445LCC_4X8 which has 6 GB of system memory. Here is how the PCIe controller maps the system memory to PCIe memory:
memc0-a@[ 0....3fffffff] <=> pci@[ 0....3fffffff]
memc0-b@[100000000...13fffffff] <=> pci@[ 40000000....7fffffff] memc1-a@[ 40000000....7fffffff] <=> pci@[ 80000000....bfffffff] memc1-b@[300000000...33fffffff] <=> pci@[ c0000000....ffffffff] memc2-a@[ 80000000....bfffffff] <=> pci@[100000000...13fffffff] memc2-b@[c00000000...c3fffffff] <=> pci@[140000000...17fffffff]
Although there are some "gaps" that can be added between the individual mappings by software, the permutation of memory regions for the most part is fixed by HW. The solution of having something close to an identity mapping is not possible.
The idea behind this HW design is that the same PCIe module can act as an RC or EP, and if it acts as an EP it concatenates all of system memory into a BAR so anything can be accessed. Unfortunately, when the PCIe block is in the role of an RC it also presents this "BAR" to downstream PCIe devices, rather than offering an identity map between its system memory and PCIe space.
Suppose that an endpoint driver allocs some DMA memory. Suppose this memory is located at 0x6000_0000, which is in the middle of memc1-a. The driver wants a dma_addr_t value that it can pass on to the EP to use. Without doing any custom mapping, the EP will use this value for
DMA: the driver will get a dma_addr_t equal to 0x6000_0000. But this won't work; the device needs a dma_addr_t that reflects the PCIe space address, namely 0xa000_0000.
So, essentially the solution to this problem must modify the dma_addr_t returned by the DMA routines routines. There are two ways (I know of) of doing this:
(a) overriding/redefining the dma_to_phys() and phys_to_dma() calls that are used by the dma_ops routines. This is the approach of
arch/mips/cavium-octeon/dma-octeon.c
In ARM and ARM64 these two routines are defiend in asm/dma-mapping.h as static inline functions.
(b) Subscribe to a notifier that notifies when a device is added to a bus. When this happens, set_dma_ops() can be called for the device. This method is mentioned in:
http://lxr.free-electrons.com/source/drivers/of/platform.c?v=3.16#L152
where it says as a comment
"In case if platform code need to use own special DMA configuration, it can use Platform bus notifier and handle BUS_NOTIFY_ADD_DEVICE event to fix up DMA configuration."
Solution (b) is what this commit does. It uses the native dma_ops as the base set of operations, and overrides some with custom functions that translate the address and then call the base function.
--- drivers/pci/host/Makefile | 3 +- drivers/pci/host/pci-brcmstb-dma.c | 219 +++++++++++++++++++++++++++++++++++++ drivers/pci/host/pci-brcmstb.c | 150 +++++++++++++++++++++++-- drivers/pci/host/pci-brcmstb.h | 7 ++ 4 files changed, 368 insertions(+), 11 deletions(-) create mode 100644 drivers/pci/host/pci-brcmstb-dma.c
drivers/pci/host/Makefile +2 -1
@@ -21,7 +21,8 @@ obj-$(CONFIG_PCIE_ROCKCHIP) += pcie-rockchip.o obj-$(CONFIG_PCIE_MEDIATEK) += pcie-mediatek.o obj-$(CONFIG_PCIE_TANGO_SMP8759) += pcie-tango.o obj-$(CONFIG_VMD) += vmd.o -obj-$(CONFIG_PCI_BRCMSTB) += pci-brcmstb.o +obj-$(CONFIG_PCI_BRCMSTB) += brcmstb-pci.o +brcmstb-pci-objs := pci-brcmstb.o pci-brcmstb-dma.o # The following drivers are for devices that use the generic ACPI # pci_root.c driver but don't support standard ECAM config access.
drivers/pci/host/pci-brcmstb-dma.c new file +219 -0
219 lines not on this page · raw message
drivers/pci/host/pci-brcmstb.c +140 -10
199 lines not on this page · raw message
drivers/pci/host/pci-brcmstb.h +7 -0
@@ -21,6 +21,13 @@/* Broadcom PCIE Offsets */ #define PCIE_INTR2_CPU_BASE 0x4300 +dma_addr_t brcm_to_pci (dma_addr_t addr); +dma_addr_t brcm_to_cpu (dma_addr_t addr); + +extern struct notifier_block brcmstb_platform_nb; + +#define BRCMSTB_ERROR_CODE (~(dma_addr_t)0x0) +#if defined(CONFIG_MIPS )/* Broadcom MIPs HW implicitly does the swapping if necessary */ #define bcm_readl (a) __raw_readl(a)
Signature · 1 line
1.9.0.138.g2de3478
Re: [PATCH 5/9] PCI: host: brcmstb: add dma-ranges for inbound traffic
[+DMA API maintainers]
Quoted 179 lines · Jim Quinlan
The Broadcom STB PCIe host controller is intimately related to the memory subsystem. This close relationship adds complexity to how cpu system memory is mapped to PCIe memory. Ideally, this mapping is an identity mapping, or an identity mapping off by a constant. Not so in this case.
Consider the Broadcom reference board
BCM97445LCC_4X8which has 6 GB of system memory. Here is how the PCIe controller maps the system memory to PCIe memory:memc0-a@[ 0....3fffffff] <=> pci@[ 0....3fffffff]
memc0-b@[100000000...13fffffff] <=> pci@[ 40000000....7fffffff] memc1-a@[ 40000000....7fffffff] <=> pci@[ 80000000....bfffffff] memc1-b@[300000000...33fffffff] <=> pci@[ c0000000....ffffffff] memc2-a@[ 80000000....bfffffff] <=> pci@[100000000...13fffffff] memc2-b@[c00000000...c3fffffff] <=> pci@[140000000...17fffffff]Although there are some "gaps" that can be added between the individual mappings by software, the permutation of memory regions for the most part is fixed by HW. The solution of having something close to an identity mapping is not possible.
The idea behind this HW design is that the same PCIe module can act as an RC or EP, and if it acts as an EP it concatenates all of system memory into a BAR so anything can be accessed. Unfortunately, when the PCIe block is in the role of an RC it also presents this "BAR" to downstream PCIe devices, rather than offering an identity map between its system memory and PCIe space.
Suppose that an endpoint driver allocs some DMA memory. Suppose this memory is located at 0x6000_0000, which is in the middle of memc1-a. The driver wants a
dma_addr_tvalue that it can pass on to the EP to use. Without doing any custom mapping, the EP will use this value for
DMA: the driver will get adma_addr_tequal to 0x6000_0000. But this won't work; the device needs adma_addr_tthat reflects the PCIe space address, namely 0xa000_0000.So, essentially the solution to this problem must modify the
dma_addr_treturned by the DMA routines routines. There are two ways (I know of) of doing this:(a) overriding/redefining the
dma_to_phys()andphys_to_dma()calls that are used by thedma_opsroutines. This is the approach of
arch/mips/cavium-octeon/dma-octeon.cIn ARM and ARM64 these two routines are defiend in
asm/dma-mapping.has static inline functions.(b) Subscribe to a notifier that notifies when a device is added to a bus. When this happens,
set_dma_ops()can be called for the device. This method is mentioned in:http://lxr.free-electrons.com/source/drivers/of/platform.c?v=3.16#L152where it says as a comment
"In case if platform code need to use own special DMA configuration, it can use Platform bus notifier and handle
BUS_NOTIFY_ADD_DEVICEevent to fix up DMA configuration."Solution (b) is what this commit does. It uses the native
dma_opsas the base set of operations, and overrides some with custom functions that translate the address and then call the base function.Signed-off-by Jim Quinlan <[email protected]>--- drivers/pci/host/Makefile | 3 +- drivers/pci/host/pci-brcmstb-dma.c | 219 +++++++++++++++++++++++++++++++++++++ drivers/pci/host/pci-brcmstb.c | 150 +++++++++++++++++++++++-- drivers/pci/host/pci-brcmstb.h | 7 ++ 4 files changed, 368 insertions(+), 11 deletions(-) create mode 100644 drivers/pci/host/pci-brcmstb-dma.cdrivers/pci/host/Makefile +2
-1@@ -21,7 +21,8 @@ obj-$(CONFIG_PCIE_ROCKCHIP) += pcie-rockchip.o obj-$(CONFIG_PCIE_MEDIATEK) += pcie-mediatek.o obj-$(CONFIG_PCIE_TANGO_SMP8759) += pcie-tango.o obj-$(CONFIG_VMD) += vmd.o -obj-$(CONFIG_PCI_BRCMSTB) += pci-brcmstb.o +obj-$(CONFIG_PCI_BRCMSTB) += brcmstb-pci.o +brcmstb-pci-objs := pci-brcmstb.o pci-brcmstb-dma.o # The following drivers are for devices that use the generic ACPI # pci_root.c driver but don't support standard ECAM config access.drivers/pci/host/pci-brcmstb-dma.c new file +83
-0@@ -0,0 +1,219 @@ +/* +* Copyright (C) 2015-2017 Broadcom +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +*/ +#include <linux/dma-mapping.h> +#include <linux/init.h> +#include <linux/io.h> +#include <linux/kernel.h> +#include <linux/of_address.h> +#include <linux/pci.h> +#include <linux/platform_device.h> +#include <linux/smp.h> + +#include "pci-brcmstb.h" + +static const struct dma_map_ops *arch_dma_ops; +static struct dma_map_ops brcm_dma_ops; + +static void *brcm_dma_alloc (struct device *dev,size_t size,dma_addr_t *handle, +gfp_t gfp,unsigned long attrs) +{ +void *ret; + + ret = arch_dma_ops->alloc (dev, size, handle, gfp, attrs); +if (ret) + *handle =brcm_to_pci (*handle); +return ret; +} + +static void brcm_dma_free (struct device *dev,size_t size,void *cpu_addr, +dma_addr_t handle,unsigned long attrs) +{ + handle =brcm_to_cpu (handle); + arch_dma_ops->free (dev, size, cpu_addr, handle, attrs); +} + +static int brcm_dma_mmap (struct device *dev,struct vm_area_struct *vma, +void *cpu_addr,dma_addr_t dma_addr,size_t size, +unsigned long attrs) +{ + dma_addr =brcm_to_cpu (dma_addr); +return arch_dma_ops->mmap (dev, vma, cpu_addr, dma_addr, size, attrs); +} + +static int brcm_dma_get_sgtable (struct device *dev,struct sg_table *sgt, +void *cpu_addr,dma_addr_t handle,size_t size, +unsigned long attrs) +{ + handle =brcm_to_cpu (handle); +return arch_dma_ops->get_sgtable (dev, sgt, cpu_addr, handle, size, + attrs); +} + +static dma_addr_t brcm_dma_map_page (struct device *dev,struct page *page, +unsigned long offset,size_t size, +enum dma_data_direction dir, +unsigned long attrs) +{ +return brcm_to_pci (arch_dma_ops->map_page (dev, page, offset, size, + dir, attrs)); +} + +static void brcm_dma_unmap_page (struct device *dev,dma_addr_t handle, +size_t size,enum dma_data_direction dir, +unsigned long attrs) +{ + handle =brcm_to_cpu (handle); + arch_dma_ops->unmap_page (dev, handle, size, dir, attrs); +} + +static int brcm_dma_map_sg (struct device *dev,struct scatterlist *sgl, +int nents,enum dma_data_direction dir, +unsigned long attrs) +{
drivers/pci/host/pci-brcmstb-dma.c line 93
Quoted 10 lines
drivers/pci/host/pci-brcmstb-dma.c new file +10
-0+int ret, i; +struct scatterlist *sg; + + ret = arch_dma_ops->map_sg (dev, sgl, nents, dir, attrs); +/* The ARM and MIPS implementations of map_sg and unmap_sg +* make calls to ops->map_page(), which we already intercept. +* The ARM64 does not, so we must iterate through the SG list +* and convert each dma_address to one that is compatible +* with our PCI RC implementation. +*/
That's a pretty fragile assumption given that arch code is free to change, and anyone doing so is unlikely to be aware of your driver. You'd be better off implementing these in terms of {brcm_dma_}map_page directly.
Quoted 31 lines
drivers/pci/host/pci-brcmstb-dma.c new file +31
-0+if (IS_ENABLED (CONFIG_ARM64 )) +for_each_sg (sgl, sg, ret, i) + sg->dma_address =brcm_to_pci (sg->dma_address); +return ret; +} + +static void brcm_dma_unmap_sg (struct device *dev, +struct scatterlist *sgl,int nents, +enum dma_data_direction dir, +unsigned long attrs) +{ +int i; +struct scatterlist *sg; + +/* The ARM and MIPS implementations of map_sg and unmap_sg +* make calls to ops->map_page(), which we already intercept. +* The ARM64 does not, so we must iterate through the SG list +* and convert each dma_address to one that is compatible +* with our PCI RC implementation. +*/ +if (IS_ENABLED (CONFIG_ARM64 )) +for_each_sg (sgl, sg, nents, i) + sg->dma_address =brcm_to_cpu (sg->dma_address); + arch_dma_ops->map_sg (dev, sgl, nents, dir, attrs); +} + +static void brcm_dma_sync_single_for_cpu (struct device *dev, +dma_addr_t handle,size_t size, +enum dma_data_direction dir) +{ + handle =brcm_to_cpu (handle);
drivers/pci/host/pci-brcmstb-dma.c line 134
Quoted 10 lines
drivers/pci/host/pci-brcmstb-dma.c new file +10
-0+ arch_dma_ops->sync_single_for_cpu (dev, handle, size, dir); +} + +static void brcm_dma_sync_single_for_device (struct device *dev, +dma_addr_t handle,size_t size, +enum dma_data_direction dir) +{ + handle =brcm_to_cpu (handle); + arch_dma_ops->sync_single_for_device (dev, handle, size, dir); +}
And sync_sg_*()? They might not be that commonly used by in-tree drivers, but who knows what lurks beyond?
Quoted 11 lines
drivers/pci/host/pci-brcmstb-dma.c new file +11
-0+ +static dma_addr_t brcm_dma_map_resource (struct device *dev,phys_addr_t phys, +size_t size, +enum dma_data_direction dir, +unsigned long attrs) +{ +return brcm_to_pci (arch_dma_ops->map_resource + (dev, phys, size, dir, attrs)); +} + +static void brcm_dma_unmap_resource(struct device *dev, dma_addr_t handle,
drivers/pci/host/pci-brcmstb-dma.c line 155
Quoted 10 lines
drivers/pci/host/pci-brcmstb-dma.c new file +10
-0+ size_t size, enum dma_data_direction dir, + unsigned long attrs) +{ + handle =brcm_to_cpu (handle); + arch_dma_ops->unmap_resource (dev, handle, size, dir, attrs); +} + +static int brcm_mapping_error (struct device *dev,dma_addr_t dma_addr) +{ +return dma_addr ==BRCMSTB_ERROR_CODE ;
Huh? How do you know this will work correctly with every platform's ->map_page implementation (hint: it doesn't).
Quoted 7 lines
drivers/pci/host/pci-brcmstb-dma.c new file +7
-0+} + +static const struct dma_map_ops *brcm_get_arch_dma_ops (struct device *dev) +{ +#if defined(CONFIG_MIPS ) +return mips_dma_map_ops; +#elif defined(CONFIG_ARM )
drivers/pci/host/pci-brcmstb-dma.c line 172
Quoted 10 lines
drivers/pci/host/pci-brcmstb-dma.c new file +10
-0+return &arm_dma_ops; +#elif defined(CONFIG_ARM64 ) +/* swiotlb_dma_ops is a static var, so we get ahold +* of it by calling arch_setup_dma_ops(...). +*/ +arch_setup_dma_ops (dev,0 ,0 ,NULL , false); +return dev->dma_ops; +#endif +return 0 ; +}
As mentioned earlier, no. There are theoretical cases where it might not be true, but in practice you can assume all PCI devices are going to get the same DMA ops as their associated host controller (and that's still a better assumption that what you have here), so you can just grab those at the point you install the notifier.
Quoted 20 lines
drivers/pci/host/pci-brcmstb-dma.c new file +20
-0+ +static void brcm_set_dma_ops (struct device *dev) +{ + arch_dma_ops =brcm_get_arch_dma_ops (dev); +if (!arch_dma_ops) +return ; + +/* Set all of the base operations; some will be overridden */ + brcm_dma_ops = *arch_dma_ops; + +/* Insert the Brcm-specific override operations */ + brcm_dma_ops.alloc = brcm_dma_alloc; + brcm_dma_ops.free = brcm_dma_free; + brcm_dma_ops.mmap = brcm_dma_mmap; + brcm_dma_ops.get_sgtable = brcm_dma_get_sgtable; + brcm_dma_ops.map_page = brcm_dma_map_page; + brcm_dma_ops.unmap_page = brcm_dma_unmap_page; + brcm_dma_ops.sync_single_for_cpu = brcm_dma_sync_single_for_cpu; + brcm_dma_ops.sync_single_for_device = brcm_dma_sync_single_for_device; + brcm_dma_ops.map_sg = brcm_dma_map_sg;
drivers/pci/host/pci-brcmstb-dma.c line 202
Quoted 10 lines
drivers/pci/host/pci-brcmstb-dma.c new file +10
-0+ brcm_dma_ops.unmap_sg = brcm_dma_unmap_sg; +if (arch_dma_ops->map_resource) + brcm_dma_ops.map_resource = brcm_dma_map_resource; +if (arch_dma_ops->unmap_resource) + brcm_dma_ops.unmap_resource = brcm_dma_unmap_resource; + brcm_dma_ops.mapping_error = brcm_mapping_error; + +/* Use our brcm_dma_ops for this driver */ +set_dma_ops (dev, &brcm_dma_ops); +}
Just have a static const set of ops like everyone else - you can handle the conditionality of ->{map,unmap}_resource inside the brcm_* wrappers.
Quoted 63 lines
drivers/pci/host/pci-brcmstb-dma.c new file +17
-0+ +static int brcmstb_platform_notifier (struct notifier_block *nb, +unsigned long event,void *__dev) +{ +struct device *dev = __dev; + +if (event !=BUS_NOTIFY_ADD_DEVICE ) +return NOTIFY_DONE ; + +brcm_set_dma_ops (dev); +return NOTIFY_OK ; +} + +struct notifier_block brcmstb_platform_nb = { + .notifier_call = brcmstb_platform_notifier, +}; +EXPORT_SYMBOL (brcmstb_platform_nb);drivers/pci/host/pci-brcmstb.c +15
-1@@ -343,6 +343,8 @@ struct brcm_pcie {static struct list_head brcm_pcie =LIST_HEAD_INIT (brcm_pcie);static phys_addr_t scb_size[BRCM_MAX_SCB ]; +static struct of_pci_range *dma_ranges; +static int num_dma_ranges;static int num_memc;static DEFINE_MUTEX (brcm_pcie_lock);@@ -362,6 +364,8 @@ static int brcm_pcie_add_controller(struct brcm_pcie *pcie) {mutex_lock (&brcm_pcie_lock);snprintf (pcie->name,sizeof (pcie->name) -1 ,"PCIe%d" , pcie->id); +if (list_empty (&brcm_pcie)) +bus_register_notifier (&pci_bus_type, &brcmstb_platform_nb);list_add_tail (&pcie->list, &brcm_pcie);mutex_unlock (&brcm_pcie_lock);@@ -378,8 +382,14 @@ static void brcm_pcie_remove_controller(struct brcm_pcie *pcie) tmp = list_entry(pos, struct brcm_pcie, list);if (tmp == pcie) {list_del (pos); -if (list_empty (&brcm_pcie)) +if (list_empty (&brcm_pcie)) { +bus_unregister_notifier (&pci_bus_type, + &brcmstb_platform_nb); +kfree (dma_ranges); + dma_ranges =NULL ; + num_dma_ranges =0 ; num_memc =0 ; + }break ; } }@@ -403,6 +413,35 @@ int encode_ibar_size(u64 size)return 0 ; } +dma_addr_t brcm_to_pci (dma_addr_t addr) +{ +struct of_pci_range *p; +
drivers/pci/host/pci-brcmstb.c int encode_ibar_size(u64 size) · line 429
Quoted 10 lines
drivers/pci/host/pci-brcmstb.c +10
-0+if (!num_dma_ranges) +return addr; + +for (p = dma_ranges; p < &dma_ranges[num_dma_ranges]; p++) +if (addr >= p->cpu_addr && addr < (p->cpu_addr + p->size)) +return addr - p->cpu_addr + p->pci_addr; + +return BRCMSTB_ERROR_CODE ; +} +EXPORT_SYMBOL (brcm_to_pci);
AFAICS it doesn't make much sense for anyone outside this driver to ever be calling these.
Quoted 29 lines
drivers/pci/host/pci-brcmstb.c +22
-0+dma_addr_t brcm_to_cpu (dma_addr_t addr) +{ +struct of_pci_range *p; + +if (!num_dma_ranges) +return addr; +for (p = dma_ranges; p < &dma_ranges[num_dma_ranges]; p++) +if (addr >= p->pci_addr && addr < (p->pci_addr + p->size)) +return addr - p->pci_addr + p->cpu_addr; + +return addr; +} +EXPORT_SYMBOL (brcm_to_cpu); +static u32 mdio_form_pkt (int port,int regad,int cmd) {u32 pkt =0 ;@@ -652,6 +691,74 @@ static int brcm_parse_ranges(struct brcm_pcie *pcie)return 0 ; } +static int brcm_pci_dma_range_parser_init (struct of_pci_range_parser *parser, +struct device_node *node) +{ +const int na =3 , ns =2 ; +int rlen; + + parser->node = node; + parser->pna =of_n_addr_cells (node);
drivers/pci/host/pci-brcmstb.c static int brcm_parse_ranges(struct brcm_pcie *pcie) · line 711
Quoted 10 lines
drivers/pci/host/pci-brcmstb.c +10
-0+ parser->np = parser->pna + na + ns; + + parser->range =of_get_property (node,"dma-ranges" , &rlen); +if (!parser->range) +return -ENOENT ; + + parser->end = parser->range + rlen /sizeof (__be32); + +return 0 ; +}
Note that we've got a factored-out helper for this queued in -next already - see here:
Quoted 120 lines
drivers/pci/host/pci-brcmstb.c +82
-9+ +static int brcm_parse_dma_ranges (struct brcm_pcie *pcie) +{ +int i, ret =0 ; +struct of_pci_range_parser parser; +struct device_node *dn = pcie->dn; + +mutex_lock (&brcm_pcie_lock); +if (dma_ranges) + goto done; + +/* Parse dma-ranges property if present. If there are multiple +* PCI controllers, we only have to parse from one of them since +* the others will have an identical mapping. +*/ +if (!brcm_pci_dma_range_parser_init (&parser, dn)) { +unsigned int max_ranges + = (parser.end - parser.range) / parser.np; + + dma_ranges =kcalloc (max_ranges,sizeof (struct of_pci_range ), +GFP_KERNEL ); +if (!dma_ranges) { + ret = -ENOMEM ; + goto done; + } +for (i =0 ;of_pci_range_parser_one (&parser, dma_ranges + i); + i++) + num_dma_ranges++; + } + +for (i =0 , num_memc =0 ; i <BRCM_MAX_SCB ; i++) { +u64 size =brcmstb_memory_memc_size (i); + +if (size == (u64)-1 ) { +dev_err (pcie->dev,"cannot get memc%d size" , i); + ret = -EINVAL ; + goto done; + }else if (size) { + scb_size[i] =roundup_pow_of_two_64 (size); + num_memc++; + }else { +break ; + } + } + +done: +mutex_unlock (&brcm_pcie_lock); +return ret; +} +static void set_regulators (struct brcm_pcie *pcie,bool on) {struct list_head *pos;@@ -728,10 +835,34 @@ static void brcm_pcie_setup_prep(struct brcm_pcie *pcie)*/ rc_bar2_size =roundup_pow_of_two_64 (total_mem_size); -/* Set simple configuration based on memory sizes -* only. We always start the viewport at address 0. -*/ - rc_bar2_offset =0 ; +if (dma_ranges) { +/* The best-case scenario is to place the inbound +* region in the first 4GB of pci-space, as some +* legacy devices can only address 32bits. +* We would also like to put the MSI under 4GB +* as well, since some devices require a 32bit +* MSI target address. +*/ +if (total_mem_size <=0xc0000000ULL && + rc_bar2_size <=0x100000000ULL ) { + rc_bar2_offset =0 ; + }else { +/* The system memory is 4GB or larger so we +* cannot start the inbound region at location +* 0 (since we have to allow some space for +* outbound memory @ 3GB). So instead we +* start it at the 1x multiple of its size +*/ + rc_bar2_offset = rc_bar2_size; + } + + }else { +/* Set simple configuration based on memory sizes +* only. We always start the viewport at address 0, +* and set the MSI target address accordingly. +*/ + rc_bar2_offset =0 ; + } tmp =lower_32_bits (rc_bar2_offset); tmp = INSERT_FIELD(tmp, PCIE_MISC_RC_BAR2_CONFIG_LO, SIZE,@@ -1040,11 +1171,6 @@ static int brcm_pcie_probe(struct platform_device *pdev)return -EINVAL ; } -if (of_property_read_u32 (dn,"dma-ranges" , &tmp) ==0 ) { -pr_err ("cannot yet handle dma-ranges\n" ); -return -EINVAL ; - } - data = of_id->data; pcie->reg_offsets = data->offsets; pcie->reg_field_info = data->reg_field_info;@@ -1113,6 +1239,10 @@ static int brcm_pcie_probe(struct platform_device *pdev)if (ret)return ret; + ret =brcm_parse_dma_ranges (pcie); +if (ret) +return ret; + ret =clk_prepare_enable (pcie->clk);if (ret) {dev_err (&pdev->dev,"could not enable clock\n" );drivers/pci/host/pci-brcmstb.h +0
-0
drivers/pci/host/pci-brcmstb.h line 27
Quoted 7 lines
drivers/pci/host/pci-brcmstb.h +4
-0@@ -21,6 +21,13 @@/* Broadcom PCIE Offsets */ #define PCIE_INTR2_CPU_BASE 0x4300 +dma_addr_t brcm_to_pci (dma_addr_t addr); +dma_addr_t brcm_to_cpu (dma_addr_t addr); + +extern struct notifier_block brcmstb_platform_nb;
It seems a bit weird to have the notifier code split across two compilation units in the way which requires this - it seems more reasonable to have it all together on one side or the other, with the common interface being either the callback for setting the ops or a function for installing the notifier, depending on where things fall.
Robin.
Quoted 7 lines
drivers/pci/host/pci-brcmstb.h +3
-0+ +#define BRCMSTB_ERROR_CODE (~(dma_addr_t)0x0) +#if defined(CONFIG_MIPS )/* Broadcom MIPs HW implicitly does the swapping if necessary */ #define bcm_readl (a) __raw_readl(a)
Re: [PATCH 5/9] PCI: host: brcmstb: add dma-ranges for inbound traffic
Quoted 189 lines · Robin Murphy
[+DMA API maintainers]
Quoted 186 lines · Jim Quinlan
The Broadcom STB PCIe host controller is intimately related to the memory subsystem. This close relationship adds complexity to how cpu system memory is mapped to PCIe memory. Ideally, this mapping is an identity mapping, or an identity mapping off by a constant. Not so in this case.
Consider the Broadcom reference board
BCM97445LCC_4X8which has 6 GB of system memory. Here is how the PCIe controller maps the system memory to PCIe memory:memc0-a@[ 0....3fffffff] <=> pci@[ 0....3fffffff]
memc0-b@[100000000...13fffffff] <=> pci@[ 40000000....7fffffff] memc1-a@[ 40000000....7fffffff] <=> pci@[ 80000000....bfffffff] memc1-b@[300000000...33fffffff] <=> pci@[ c0000000....ffffffff] memc2-a@[ 80000000....bfffffff] <=> pci@[100000000...13fffffff] memc2-b@[c00000000...c3fffffff] <=> pci@[140000000...17fffffff]Although there are some "gaps" that can be added between the individual mappings by software, the permutation of memory regions for the most part is fixed by HW. The solution of having something close to an identity mapping is not possible.
The idea behind this HW design is that the same PCIe module can act as an RC or EP, and if it acts as an EP it concatenates all of system memory into a BAR so anything can be accessed. Unfortunately, when the PCIe block is in the role of an RC it also presents this "BAR" to downstream PCIe devices, rather than offering an identity map between its system memory and PCIe space.
Suppose that an endpoint driver allocs some DMA memory. Suppose this memory is located at 0x6000_0000, which is in the middle of memc1-a. The driver wants a
dma_addr_tvalue that it can pass on to the EP to use. Without doing any custom mapping, the EP will use this value for
DMA: the driver will get adma_addr_tequal to 0x6000_0000. But this won't work; the device needs adma_addr_tthat reflects the PCIe space address, namely 0xa000_0000.So, essentially the solution to this problem must modify the
dma_addr_treturned by the DMA routines routines. There are two ways (I know of) of doing this:(a) overriding/redefining the
dma_to_phys()andphys_to_dma()calls that are used by thedma_opsroutines. This is the approach of
arch/mips/cavium-octeon/dma-octeon.cIn ARM and ARM64 these two routines are defiend in
asm/dma-mapping.has static inline functions.(b) Subscribe to a notifier that notifies when a device is added to a bus. When this happens,
set_dma_ops()can be called for the device. This method is mentioned in:http://lxr.free-electrons.com/source/drivers/of/platform.c?v=3.16#L152where it says as a comment
"In case if platform code need to use own special DMA configuration, it can use Platform bus notifier and handle
BUS_NOTIFY_ADD_DEVICEevent to fix up DMA configuration."Solution (b) is what this commit does. It uses the native
dma_opsas the base set of operations, and overrides some with custom functions that translate the address and then call the base function.Signed-off-by Jim Quinlan <[email protected]>--- drivers/pci/host/Makefile | 3 +- drivers/pci/host/pci-brcmstb-dma.c | 219 +++++++++++++++++++++++++++++++++++++ drivers/pci/host/pci-brcmstb.c | 150 +++++++++++++++++++++++-- drivers/pci/host/pci-brcmstb.h | 7 ++ 4 files changed, 368 insertions(+), 11 deletions(-) create mode 100644 drivers/pci/host/pci-brcmstb-dma.cdrivers/pci/host/Makefile +2
-1@@ -21,7 +21,8 @@ obj-$(CONFIG_PCIE_ROCKCHIP) += pcie-rockchip.o obj-$(CONFIG_PCIE_MEDIATEK) += pcie-mediatek.o obj-$(CONFIG_PCIE_TANGO_SMP8759) += pcie-tango.o obj-$(CONFIG_VMD) += vmd.o -obj-$(CONFIG_PCI_BRCMSTB) += pci-brcmstb.o +obj-$(CONFIG_PCI_BRCMSTB) += brcmstb-pci.o +brcmstb-pci-objs := pci-brcmstb.o pci-brcmstb-dma.o # The following drivers are for devices that use the generic ACPI # pci_root.c driver but don't support standard ECAM config access.drivers/pci/host/pci-brcmstb-dma.c new file +90
-0@@ -0,0 +1,219 @@ +/* +* Copyright (C) 2015-2017 Broadcom +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +*/ +#include <linux/dma-mapping.h> +#include <linux/init.h> +#include <linux/io.h> +#include <linux/kernel.h> +#include <linux/of_address.h> +#include <linux/pci.h> +#include <linux/platform_device.h> +#include <linux/smp.h> + +#include "pci-brcmstb.h" + +static const struct dma_map_ops *arch_dma_ops; +static struct dma_map_ops brcm_dma_ops; + +static void *brcm_dma_alloc (struct device *dev,size_t size,dma_addr_t *handle, +gfp_t gfp,unsigned long attrs) +{ +void *ret; + + ret = arch_dma_ops->alloc (dev, size, handle, gfp, attrs); +if (ret) + *handle =brcm_to_pci (*handle); +return ret; +} + +static void brcm_dma_free (struct device *dev,size_t size,void *cpu_addr, +dma_addr_t handle,unsigned long attrs) +{ + handle =brcm_to_cpu (handle); + arch_dma_ops->free (dev, size, cpu_addr, handle, attrs); +} + +static int brcm_dma_mmap (struct device *dev,struct vm_area_struct *vma, +void *cpu_addr,dma_addr_t dma_addr,size_t size, +unsigned long attrs) +{ + dma_addr =brcm_to_cpu (dma_addr); +return arch_dma_ops->mmap (dev, vma, cpu_addr, dma_addr, size, attrs); +} + +static int brcm_dma_get_sgtable (struct device *dev,struct sg_table *sgt, +void *cpu_addr,dma_addr_t handle,size_t size, +unsigned long attrs) +{ + handle =brcm_to_cpu (handle); +return arch_dma_ops->get_sgtable (dev, sgt, cpu_addr, handle, size, + attrs); +} + +static dma_addr_t brcm_dma_map_page (struct device *dev,struct page *page, +unsigned long offset,size_t size, +enum dma_data_direction dir, +unsigned long attrs) +{ +return brcm_to_pci (arch_dma_ops->map_page (dev, page, offset, size, + dir, attrs)); +} + +static void brcm_dma_unmap_page (struct device *dev,dma_addr_t handle, +size_t size,enum dma_data_direction dir, +unsigned long attrs) +{ + handle =brcm_to_cpu (handle); + arch_dma_ops->unmap_page (dev, handle, size, dir, attrs); +} + +static int brcm_dma_map_sg (struct device *dev,struct scatterlist *sgl, +int nents,enum dma_data_direction dir, +unsigned long attrs) +{ +int ret, i; +struct scatterlist *sg; + + ret = arch_dma_ops->map_sg (dev, sgl, nents, dir, attrs); +/* The ARM and MIPS implementations of map_sg and unmap_sg +* make calls to ops->map_page(), which we already intercept. +* The ARM64 does not, so we must iterate through the SG list
Quoted 9 lines
drivers/pci/host/pci-brcmstb-dma.c line 93
Quoted 3 lines
drivers/pci/host/pci-brcmstb-dma.c new file +3
-0+* and convert each dma_address to one that is compatible +* with our PCI RC implementation. +*/ That's a pretty fragile assumption given that arch code is free to change, and anyone doing so is unlikely to be aware of your driver. You'd be better off implementing these in terms of {brcm_dma_}map_page directly.
Will fix.
Quoted 36 lines
Quoted 36 lines
drivers/pci/host/pci-brcmstb-dma.c new file +36
-0+if (IS_ENABLED (CONFIG_ARM64 )) +for_each_sg (sgl, sg, ret, i) + sg->dma_address =brcm_to_pci (sg->dma_address); +return ret; +} + +static void brcm_dma_unmap_sg (struct device *dev, +struct scatterlist *sgl,int nents, +enum dma_data_direction dir, +unsigned long attrs) +{ +int i; +struct scatterlist *sg; + +/* The ARM and MIPS implementations of map_sg and unmap_sg +* make calls to ops->map_page(), which we already intercept. +* The ARM64 does not, so we must iterate through the SG list +* and convert each dma_address to one that is compatible +* with our PCI RC implementation. +*/ +if (IS_ENABLED (CONFIG_ARM64 )) +for_each_sg (sgl, sg, nents, i) + sg->dma_address =brcm_to_cpu (sg->dma_address); + arch_dma_ops->map_sg (dev, sgl, nents, dir, attrs); +} + +static void brcm_dma_sync_single_for_cpu (struct device *dev, +dma_addr_t handle,size_t size, +enum dma_data_direction dir) +{ + handle =brcm_to_cpu (handle); + arch_dma_ops->sync_single_for_cpu (dev, handle, size, dir); +} + +static void brcm_dma_sync_single_for_device(struct device *dev, + dma_addr_t handle, size_t size,
Quoted 9 lines
drivers/pci/host/pci-brcmstb-dma.c line 134
Quoted 5 lines
drivers/pci/host/pci-brcmstb-dma.c new file +5
-0+ enum dma_data_direction dir) +{ + handle =brcm_to_cpu (handle); + arch_dma_ops->sync_single_for_device (dev, handle, size, dir); +}And sync_sg_*()? They might not be that commonly used by in-tree drivers, but who knows what lurks beyond?
Will fix.
Quoted 16 lines
Quoted 16 lines
drivers/pci/host/pci-brcmstb-dma.c new file +16
-0+ +static dma_addr_t brcm_dma_map_resource (struct device *dev,phys_addr_t phys, +size_t size, +enum dma_data_direction dir, +unsigned long attrs) +{ +return brcm_to_pci (arch_dma_ops->map_resource + (dev, phys, size, dir, attrs)); +} + +static void brcm_dma_unmap_resource (struct device *dev,dma_addr_t handle, +size_t size,enum dma_data_direction dir, +unsigned long attrs) +{ + handle =brcm_to_cpu (handle); + arch_dma_ops->unmap_resource (dev, handle, size, dir, attrs);
Quoted 9 lines
drivers/pci/host/pci-brcmstb-dma.c line 155
Quoted 5 lines
drivers/pci/host/pci-brcmstb-dma.c new file +5
-0+} + +static int brcm_mapping_error (struct device *dev,dma_addr_t dma_addr) +{ +return dma_addr ==BRCMSTB_ERROR_CODE ;Huh? How do you know this will work correctly with every platform's ->map_page implementation (hint: it doesn't).
Will fix.
Quoted 15 lines
Quoted 15 lines
drivers/pci/host/pci-brcmstb-dma.c new file +15
-0+} + +static const struct dma_map_ops *brcm_get_arch_dma_ops (struct device *dev) +{ +#if defined(CONFIG_MIPS ) +return mips_dma_map_ops; +#elif defined(CONFIG_ARM ) +return &arm_dma_ops; +#elif defined(CONFIG_ARM64 ) +/* swiotlb_dma_ops is a static var, so we get ahold +* of it by calling arch_setup_dma_ops(...). +*/ +arch_setup_dma_ops (dev,0 ,0 ,NULL , false); +return dev->dma_ops; +#endif
Quoted 9 lines
drivers/pci/host/pci-brcmstb-dma.c line 172
Quoted 2 lines
drivers/pci/host/pci-brcmstb-dma.c new file +2
-0+return 0 ; +}As mentioned earlier, no. There are theoretical cases where it might not be true, but in practice you can assume all PCI devices are going to get the same DMA ops as their associated host controller (and that's still a better assumption that what you have here), so you can just grab those at the point you install the notifier.
Yes, for some reason I did not know of get_dma_ops() and I wrote my own, poorly. Will fix.
Quoted 25 lines
Quoted 25 lines
drivers/pci/host/pci-brcmstb-dma.c new file +25
-0+ +static void brcm_set_dma_ops (struct device *dev) +{ + arch_dma_ops =brcm_get_arch_dma_ops (dev); +if (!arch_dma_ops) +return ; + +/* Set all of the base operations; some will be overridden */ + brcm_dma_ops = *arch_dma_ops; + +/* Insert the Brcm-specific override operations */ + brcm_dma_ops.alloc = brcm_dma_alloc; + brcm_dma_ops.free = brcm_dma_free; + brcm_dma_ops.mmap = brcm_dma_mmap; + brcm_dma_ops.get_sgtable = brcm_dma_get_sgtable; + brcm_dma_ops.map_page = brcm_dma_map_page; + brcm_dma_ops.unmap_page = brcm_dma_unmap_page; + brcm_dma_ops.sync_single_for_cpu = brcm_dma_sync_single_for_cpu; + brcm_dma_ops.sync_single_for_device = brcm_dma_sync_single_for_device; + brcm_dma_ops.map_sg = brcm_dma_map_sg; + brcm_dma_ops.unmap_sg = brcm_dma_unmap_sg; +if (arch_dma_ops->map_resource) + brcm_dma_ops.map_resource = brcm_dma_map_resource; +if (arch_dma_ops->unmap_resource) + brcm_dma_ops.unmap_resource = brcm_dma_unmap_resource;
Quoted 9 lines
drivers/pci/host/pci-brcmstb-dma.c line 202
Quoted 5 lines
drivers/pci/host/pci-brcmstb-dma.c new file +5
-0+ brcm_dma_ops.mapping_error = brcm_mapping_error; + +/* Use our brcm_dma_ops for this driver */ +set_dma_ops (dev, &brcm_dma_ops); +}Just have a static const set of ops like everyone else - you can handle the conditionality of ->{map,unmap}_resource inside the brcm_* wrappers.
Will fix.
Quoted 68 lines
Quoted 68 lines
drivers/pci/host/pci-brcmstb-dma.c new file +17
-0+ +static int brcmstb_platform_notifier (struct notifier_block *nb, +unsigned long event,void *__dev) +{ +struct device *dev = __dev; + +if (event !=BUS_NOTIFY_ADD_DEVICE ) +return NOTIFY_DONE ; + +brcm_set_dma_ops (dev); +return NOTIFY_OK ; +} + +struct notifier_block brcmstb_platform_nb = { + .notifier_call = brcmstb_platform_notifier, +}; +EXPORT_SYMBOL (brcmstb_platform_nb);drivers/pci/host/pci-brcmstb.c +20
-1@@ -343,6 +343,8 @@ struct brcm_pcie {static struct list_head brcm_pcie =LIST_HEAD_INIT (brcm_pcie);static phys_addr_t scb_size[BRCM_MAX_SCB ]; +static struct of_pci_range *dma_ranges; +static int num_dma_ranges;static int num_memc;static DEFINE_MUTEX (brcm_pcie_lock);@@ -362,6 +364,8 @@ static int brcm_pcie_add_controller(struct brcm_pcie *pcie) {mutex_lock (&brcm_pcie_lock);snprintf (pcie->name,sizeof (pcie->name) -1 ,"PCIe%d" , pcie->id); +if (list_empty (&brcm_pcie)) +bus_register_notifier (&pci_bus_type, &brcmstb_platform_nb);list_add_tail (&pcie->list, &brcm_pcie);mutex_unlock (&brcm_pcie_lock);@@ -378,8 +382,14 @@ static void brcm_pcie_remove_controller(struct brcm_pcie *pcie) tmp = list_entry(pos, struct brcm_pcie, list);if (tmp == pcie) {list_del (pos); -if (list_empty (&brcm_pcie)) +if (list_empty (&brcm_pcie)) { +bus_unregister_notifier (&pci_bus_type, + &brcmstb_platform_nb); +kfree (dma_ranges); + dma_ranges =NULL ; + num_dma_ranges =0 ; num_memc =0 ; + }break ; } }@@ -403,6 +413,35 @@ int encode_ibar_size(u64 size)return 0 ; } +dma_addr_t brcm_to_pci (dma_addr_t addr) +{ +struct of_pci_range *p; + +if (!num_dma_ranges) +return addr; + +for (p = dma_ranges; p < &dma_ranges[num_dma_ranges]; p++) +if (addr >= p->cpu_addr && addr < (p->cpu_addr + p->size))
Quoted 9 lines
drivers/pci/host/pci-brcmstb.c int encode_ibar_size(u64 size) · line 429
Quoted 5 lines
drivers/pci/host/pci-brcmstb.c +5
-0+return addr - p->cpu_addr + p->pci_addr; + +return BRCMSTB_ERROR_CODE ; +} +EXPORT_SYMBOL (brcm_to_pci);AFAICS it doesn't make much sense for anyone outside this driver to ever be calling these.
Will fix.
Quoted 43 lines
Quoted 29 lines
drivers/pci/host/pci-brcmstb.c +22
-0+dma_addr_t brcm_to_cpu (dma_addr_t addr) +{ +struct of_pci_range *p; + +if (!num_dma_ranges) +return addr; +for (p = dma_ranges; p < &dma_ranges[num_dma_ranges]; p++) +if (addr >= p->pci_addr && addr < (p->pci_addr + p->size)) +return addr - p->pci_addr + p->cpu_addr; + +return addr; +} +EXPORT_SYMBOL (brcm_to_cpu); +static u32 mdio_form_pkt (int port,int regad,int cmd) {u32 pkt =0 ;@@ -652,6 +691,74 @@ static int brcm_parse_ranges(struct brcm_pcie *pcie)return 0 ; } +static int brcm_pci_dma_range_parser_init (struct of_pci_range_parser *parser, +struct device_node *node) +{ +const int na =3 , ns =2 ; +int rlen; + + parser->node = node; + parser->pna =of_n_addr_cells (node);drivers/pci/host/pci-brcmstb.c static int brcm_parse_ranges(struct brcm_pcie *pcie) · line 711
Quoted 10 lines
drivers/pci/host/pci-brcmstb.c +10
-0+ parser->np = parser->pna + na + ns; + + parser->range =of_get_property (node,"dma-ranges" , &rlen); +if (!parser->range) +return -ENOENT ; + + parser->end = parser->range + rlen /sizeof (__be32); + +return 0 ; +}Note that we've got a factored-out helper for this queued in -next already - see here:
Quoted 2 lines
I will submit a change when it gets merged.
Quoted 123 lines
Quoted 123 lines
drivers/pci/host/pci-brcmstb.c +82
-9+ +static int brcm_parse_dma_ranges (struct brcm_pcie *pcie) +{ +int i, ret =0 ; +struct of_pci_range_parser parser; +struct device_node *dn = pcie->dn; + +mutex_lock (&brcm_pcie_lock); +if (dma_ranges) + goto done; + +/* Parse dma-ranges property if present. If there are multiple +* PCI controllers, we only have to parse from one of them since +* the others will have an identical mapping. +*/ +if (!brcm_pci_dma_range_parser_init (&parser, dn)) { +unsigned int max_ranges + = (parser.end - parser.range) / parser.np; + + dma_ranges =kcalloc (max_ranges,sizeof (struct of_pci_range ), +GFP_KERNEL ); +if (!dma_ranges) { + ret = -ENOMEM ; + goto done; + } +for (i =0 ;of_pci_range_parser_one (&parser, dma_ranges + i); + i++) + num_dma_ranges++; + } + +for (i =0 , num_memc =0 ; i <BRCM_MAX_SCB ; i++) { +u64 size =brcmstb_memory_memc_size (i); + +if (size == (u64)-1 ) { +dev_err (pcie->dev,"cannot get memc%d size" , i); + ret = -EINVAL ; + goto done; + }else if (size) { + scb_size[i] =roundup_pow_of_two_64 (size); + num_memc++; + }else { +break ; + } + } + +done: +mutex_unlock (&brcm_pcie_lock); +return ret; +} +static void set_regulators (struct brcm_pcie *pcie,bool on) {struct list_head *pos;@@ -728,10 +835,34 @@ static void brcm_pcie_setup_prep(struct brcm_pcie *pcie)*/ rc_bar2_size =roundup_pow_of_two_64 (total_mem_size); -/* Set simple configuration based on memory sizes -* only. We always start the viewport at address 0. -*/ - rc_bar2_offset =0 ; +if (dma_ranges) { +/* The best-case scenario is to place the inbound +* region in the first 4GB of pci-space, as some +* legacy devices can only address 32bits. +* We would also like to put the MSI under 4GB +* as well, since some devices require a 32bit +* MSI target address. +*/ +if (total_mem_size <=0xc0000000ULL && + rc_bar2_size <=0x100000000ULL ) { + rc_bar2_offset =0 ; + }else { +/* The system memory is 4GB or larger so we +* cannot start the inbound region at location +* 0 (since we have to allow some space for +* outbound memory @ 3GB). So instead we +* start it at the 1x multiple of its size +*/ + rc_bar2_offset = rc_bar2_size; + } + + }else { +/* Set simple configuration based on memory sizes +* only. We always start the viewport at address 0, +* and set the MSI target address accordingly. +*/ + rc_bar2_offset =0 ; + } tmp =lower_32_bits (rc_bar2_offset); tmp = INSERT_FIELD(tmp, PCIE_MISC_RC_BAR2_CONFIG_LO, SIZE,@@ -1040,11 +1171,6 @@ static int brcm_pcie_probe(struct platform_device *pdev)return -EINVAL ; } -if (of_property_read_u32 (dn,"dma-ranges" , &tmp) ==0 ) { -pr_err ("cannot yet handle dma-ranges\n" ); -return -EINVAL ; - } - data = of_id->data; pcie->reg_offsets = data->offsets; pcie->reg_field_info = data->reg_field_info;@@ -1113,6 +1239,10 @@ static int brcm_pcie_probe(struct platform_device *pdev)if (ret)return ret; + ret =brcm_parse_dma_ranges (pcie); +if (ret) +return ret; + ret =clk_prepare_enable (pcie->clk);if (ret) {dev_err (&pdev->dev,"could not enable clock\n" );drivers/pci/host/pci-brcmstb.h +0
-0@@ -21,6 +21,13 @@/* Broadcom PCIE Offsets */ #define PCIE_INTR2_CPU_BASE 0x4300
Quoted 10 lines
drivers/pci/host/pci-brcmstb.h line 27
Quoted 4 lines
drivers/pci/host/pci-brcmstb.h +4
-0+dma_addr_t brcm_to_pci (dma_addr_t addr); +dma_addr_t brcm_to_cpu (dma_addr_t addr); + +extern struct notifier_block brcmstb_platform_nb;It seems a bit weird to have the notifier code split across two compilation units in the way which requires this - it seems more reasonable to have it all together on one side or the other, with the common interface being either the callback for setting the ops or a function for installing the notifier, depending on where things fall.
Okay, I'll try to rework this.
Thanks Robin,
Jim
Quoted 11 lines
Robin.
Quoted 7 lines
drivers/pci/host/pci-brcmstb.h +3
-0+ +#define BRCMSTB_ERROR_CODE (~(dma_addr_t)0x0) +#if defined(CONFIG_MIPS )/* Broadcom MIPs HW implicitly does the swapping if necessary */ #define bcm_readl (a) __raw_readl(a)
Re: [PATCH 5/9] PCI: host: brcmstb: add dma-ranges for inbound traffic
In reply to Robin MurphyJust took a quick look over this and I basically agree with the comments from Robin.
What I don't understand is why you're even trying to do all these hacky things.
It seems like the controller should simply set dma_pfn_offset for each device hanging off it, and all the supported architectures should be updated to obey that if they don't do so yet, and you're done without needing this giant mess.
Re: [PATCH 5/9] PCI: host: brcmstb: add dma-ranges for inbound traffic
Quoted 10 lines · Christoph Hellwig
Just took a quick look over this and I basically agree with the comments from Robin.
What I don't understand is why you're even trying to do all these hacky things.
It seems like the controller should simply set
dma_pfn_offsetfor each device hanging off it, and all the supported architectures should be updated to obey that if they don't do so yet, and you're done without needing this giant mess.
My understanding is that dma_pfn_offset is that it is a single constant offset from RAM, in our case, to map to PCIe space. But in my commit message I detail how our PCIe controller presents memory with multiple regions with multiple different offsets. If an EP device maps to a region on the host memory, yes we can set the dma_pfn_offset for that device for that location within that range,. But if the device then unmaps and allocates from another region with a different offset, it won't work. If I set dma_pfn_offset I have to assume that the device is using only one region of memory only, not more than one, and that it is not unmapping that region and mapping another (with a different offset). Can I make those assumptions?
Re: [PATCH 5/9] PCI: host: brcmstb: add dma-ranges for inbound traffic
Quoted 2 lines · Jim Quinlan
My understanding is that
dma_pfn_offsetis that it is a single constant offset from RAM, in our case, to map to PCIe space.
Yes.
Quoted 10 lines
But in
my commit message I detail how our PCIe controller presents memory with multiple regions with multiple different offsets. If an EP device maps to a region on the host memory, yes we can set thedma_pfn_offsetfor that device for that location within that range,. But if the device then unmaps and allocates from another region with a different offset, it won't work. If I setdma_pfn_offsetI have to assume that the device is using only one region of memory only, not more than one, and that it is not unmapping that region and mapping another (with a different offset). Can I make those assumptions?
No, we can't make that assumption unfortunately. But how is your code going to work if the mapping spans multiple of your translation regions?
Also I really don't think the stacking of dma_ops as in this patch is a good idea. For MIPS you should do the variant suggested in the patch description and hook into dma_to_phys/phys_to_dma helpers, and for ARM/ARM64 you should talk to the maintainers on how they want the translation integrated.
Re: [PATCH 5/9] PCI: host: brcmstb: add dma-ranges for inbound traffic
Quoted 17 lines · Christoph Hellwig
Quoted 2 lines · Jim Quinlan
My understanding is that
dma_pfn_offsetis that it is a single constant offset from RAM, in our case, to map to PCIe space.Yes.
Quoted 10 lines
But in
my commit message I detail how our PCIe controller presents memory with multiple regions with multiple different offsets. If an EP device maps to a region on the host memory, yes we can set thedma_pfn_offsetfor that device for that location within that range,. But if the device then unmaps and allocates from another region with a different offset, it won't work. If I setdma_pfn_offsetI have to assume that the device is using only one region of memory only, not more than one, and that it is not unmapping that region and mapping another (with a different offset). Can I make those assumptions?
Quoted 3 lines
No, we can't make that assumption unfortunately. But how is your code going to work if the mapping spans multiple of your translation regions?
That's what brcm_to_{pci,cpu} are for -- they keep a list of the dma-ranges given in the PCIe DT node, and translate from system memory addresses to pci-space addresses, and vice versa. As long as people are using the DMA API it should work. It works for all of the ARM, ARM64, and MIPS Broadcom systems I've tested, using eight different EP devices. Note that I am not thrilled to be advocating this mechanism but it seemed the best alternative.
Quoted 6 lines
memorymaintiners
Also I really don't think the stacking ofdma_opsas in this patch is a good idea. For MIPS you should do the variant suggested in the patch description and hook into dma_to_phys/phys_to_dma helpers, and for ARM/ARM64 you should talk to the maintainers on how they want the translation integrated.
I would prefer that the same code work for all three architectures. What I would like from ARM/ARM64 is the ability to override phys_to_dma() and dma_to_phys(); I thought the chances of that being accepted would be slim. But you are right, I should ask the maintainers.
Re: [PATCH 5/9] PCI: host: brcmstb: add dma-ranges for inbound traffic
Quoted 7 lines · Jim Quinlan
That's what brcm_to_{pci,cpu} are for -- they keep a list of the dma-ranges given in the PCIe DT node, and translate from system memory addresses to pci-space addresses, and vice versa. As long as people are using the DMA API it should work. It works for all of the ARM, ARM64, and MIPS Broadcom systems I've tested, using eight different EP devices. Note that I am not thrilled to be advocating this mechanism but it seemed the best alternative.
Say we are using your original example ranges:
memc0-a@[ 0....3fffffff] <=> pci@[ 0....3fffffff]
memc0-b@[100000000...13fffffff] <=> pci@[ 40000000....7fffffff] memc1-a@[ 40000000....7fffffff] <=> pci@[ 80000000....bfffffff] memc1-b@[300000000...33fffffff] <=> pci@[ c0000000....ffffffff] memc2-a@[ 80000000....bfffffff] <=> pci@[100000000...13fffffff] memc2-b@[c00000000...c3fffffff] <=> pci@[140000000...17fffffff]
and now you get a dma mapping request for physical addresses 3fffff00 to 4000000f, which would span two of your ranges. How is this going to work?
Quoted 5 lines
I would prefer that the same code work for all three architectures. What I would like from ARM/ARM64 is the ability to override
phys_to_dma()anddma_to_phys(); I thought the chances of that being accepted would be slim. But you are right, I should ask the maintainers.
It is still better than trying to stack dma ops, which is a receipe for problems down the road.
Re: [PATCH 5/9] PCI: host: brcmstb: add dma-ranges for inbound traffic
Quoted 18 lines · Christoph Hellwig
Quoted 7 lines · Jim Quinlan
That's what brcm_to_{pci,cpu} are for -- they keep a list of the dma-ranges given in the PCIe DT node, and translate from system memory addresses to pci-space addresses, and vice versa. As long as people are using the DMA API it should work. It works for all of the ARM, ARM64, and MIPS Broadcom systems I've tested, using eight different EP devices. Note that I am not thrilled to be advocating this mechanism but it seemed the best alternative.
Say we are using your original example ranges:
memc0-a@[ 0....3fffffff] <=> pci@[ 0....3fffffff]
memc0-b@[100000000...13fffffff] <=> pci@[ 40000000....7fffffff] memc1-a@[ 40000000....7fffffff] <=> pci@[ 80000000....bfffffff] memc1-b@[300000000...33fffffff] <=> pci@[ c0000000....ffffffff] memc2-a@[ 80000000....bfffffff] <=> pci@[100000000...13fffffff] memc2-b@[c00000000...c3fffffff] <=> pci@[140000000...17fffffff]
Quoted 3 lines
and now you get a dma mapping request for physical addresses
3fffff00to4000000f, which would span two of your ranges. How is this going to work?
The only way to prevent this is to reserve a single page at the end of the first memory region of any pair that are adjacent in physical memory. A hack, yes, but I don't see an easier way out of this. Many if not most of our boards do not have adjacent regions and would not need this.
Overriding phys_to_dma/dma_to_phys comes with the same overlap problem (MIPS solution and possible ARM/ARM64 solution).
Quoted 9 lines
Quoted 6 lines
I would prefer that the same code work for all three architectures. What I would like from ARM/ARM64 is the ability to override
phys_to_dma()anddma_to_phys(); I thought the chances of that being accepted would be slim. But you are right, I should ask the maintainers.It is still better than trying to stack dma ops, which is a receipe for problems down the road.
Let me send out V2 of my patchset and also send it to the ARM/ARM64 maintainers as you suggested; perhaps there is an alternative.
Re: [PATCH 5/9] PCI: host: brcmstb: add dma-ranges for inbound traffic
Quoted 5 lines · Jim Quinlan
The only way to prevent this is to reserve a single page at the end of the first memory region of any pair that are adjacent in physical memory. A hack, yes, but I don't see an easier way out of this. Many if not most of our boards do not have adjacent regions and would not need this.
dma mappings can be much larger than a single page. For the block world take a look at __blk_segment_map_sg which does the merging of contiguous pages into a single SG segment. You'd have to override BIOVEC_PHYS_MERGEABLE to prevent this from happening in your supported architectures for the block layer.
Re: [PATCH 5/9] PCI: host: brcmstb: add dma-ranges for inbound traffic
Quoted 7 lines · Christoph Hellwig
Quoted 5 lines · Jim Quinlan
The only way to prevent this is to reserve a single page at the end of the first memory region of any pair that are adjacent in physical memory. A hack, yes, but I don't see an easier way out of this. Many if not most of our boards do not have adjacent regions and would not need this.
Quoted 5 lines
dma mappings can be much larger than a single page. For the block world take a look at
__blk_segment_map_sgwhich does the merging of contiguous pages into a single SG segment. You'd have to overrideBIOVEC_PHYS_MERGEABLEto prevent this from happening in your supported architectures for the block layer.
I am not sure I understand your comment -- the size of the request shouldn't be a factor. Let's look at your example of the DMA request of 3fffff00 to 4000000f (physical memory). Lets say it is for 15 pages. If we block out the last page [0x3ffff000..0x3fffffff] from what is available, there is no 15 page span that can happen across the 0x40000000 boundary. For SG, there can be no merge that connects a page from one region to another region. Can you give an example of the scenario you are thinking of?
Re: [PATCH 5/9] PCI: host: brcmstb: add dma-ranges for inbound traffic
Quoted 8 lines · Jim Quinlan
I am not sure I understand your comment -- the size of the request shouldn't be a factor. Let's look at your example of the DMA request of
3fffff00to4000000f(physical memory). Lets say it is for 15 pages. If we block out the last page [0x3ffff000..0x3fffffff] from what is available, there is no 15 page span that can happen across the0x40000000boundary. For SG, there can be no merge that connects a page from one region to another region. Can you give an example of the scenario you are thinking of?
What prevents a merge from say the regions of
0....3fffffff and 40000000....7fffffff?
Re: [PATCH 5/9] PCI: host: brcmstb: add dma-ranges for inbound traffic
Quoted 10 lines · Christoph Hellwig
Quoted 8 lines · Jim Quinlan
I am not sure I understand your comment -- the size of the request shouldn't be a factor. Let's look at your example of the DMA request of
3fffff00to4000000f(physical memory). Lets say it is for 15 pages. If we block out the last page [0x3ffff000..0x3fffffff] from what is available, there is no 15 page span that can happen across the0x40000000boundary. For SG, there can be no merge that connects a page from one region to another region. Can you give an example of the scenario you are thinking of?
Quoted 2 lines
What prevents a merge from say the regions of
0....3fffffff and 40000000....7fffffff?
Huh? [0x3ffff000...x3ffffff] is not available to be used. Drawing from the original example, we now have to tell Linux that these are now our effective memory regions:
memc0-a@[ 0....3fffefff] <=> pci@[ 0....3fffefff]
memc0-b@[100000000...13fffefff] <=> pci@[ 40000000....7fffefff]
memc1-a@[ 40000000....7fffefff] <=> pci@[ 80000000....bfffefff]
memc1-b@[300000000...33fffefff] <=> pci@[ c0000000....ffffefff]
memc2-a@[ 80000000....bfffefff] <=> pci@[100000000...13fffefff]
memc2-b@[c00000000...c3fffffff] <=> pci@[140000000...17fffffff]This leaves a one-page gap between phsyical memory regions which would normally be contiguous. One cannot have a dma alloc that spans any two regions. This is a drastic step, but I don't see an alternative. Perhaps I may be missing what you are saying...
Re: [PATCH 5/9] PCI: host: brcmstb: add dma-ranges for inbound traffic
Quoted 11 lines · Jim Quinlan
memc0-a@[ 0....3fffefff] <=> pci@[ 0....3fffefff] memc0-b@[100000000...13fffefff] <=> pci@[ 40000000....7fffefff] memc1-a@[ 40000000....7fffefff] <=> pci@[ 80000000....bfffefff] memc1-b@[300000000...33fffefff] <=> pci@[ c0000000....ffffefff] memc2-a@[ 80000000....bfffefff] <=> pci@[100000000...13fffefff] memc2-b@[c00000000...c3fffffff] <=> pci@[140000000...17fffffff]This leaves a one-page gap between phsyical memory regions which would normally be contiguous. One cannot have a dma alloc that spans any two regions. This is a drastic step, but I don't see an alternative. Perhaps I may be missing what you are saying...
Ok, IFF we are guranteed to always have a gap between physical memory locations we are fine indeed.
RE: [PATCH 5/9] PCI: host: brcmstb: add dma-ranges for inbound traffic
In reply to Jim QuinlanFrom: Jim Quinlan
Quoted 26 lines
Sent: 20 October 2017 16:28
Quoted 10 lines · Christoph Hellwig
Quoted 8 lines · Jim Quinlan
I am not sure I understand your comment -- the size of the request shouldn't be a factor. Let's look at your example of the DMA request of
3fffff00to4000000f(physical memory). Lets say it is for 15 pages. If we block out the last page [0x3ffff000..0x3fffffff] from what is available, there is no 15 page span that can happen across the0x40000000boundary. For SG, there can be no merge that connects a page from one region to another region. Can you give an example of the scenario you are thinking of?Quoted 2 lines
What prevents a merge from say the regions of
0....3fffffff and 40000000....7fffffff?Huh? [0x3ffff000...x3ffffff] is not available to be used. Drawing from the original example, we now have to tell Linux that these are now our effective memory regions:
memc0-a@[ 0....3fffefff] <=> pci@[ 0....3fffefff] memc0-b@[100000000...13fffefff] <=> pci@[ 40000000....7fffefff] memc1-a@[ 40000000....7fffefff] <=> pci@[ 80000000....bfffefff] memc1-b@[300000000...33fffefff] <=> pci@[ c0000000....ffffefff] memc2-a@[ 80000000....bfffefff] <=> pci@[100000000...13fffefff] memc2-b@[c00000000...c3fffffff] <=> pci@[140000000...17fffffff]
Quoted 4 lines
This leaves a one-page gap between phsyical memory regions which would normally be contiguous. One cannot have a dma alloc that spans any two regions. This is a drastic step, but I don't see an alternative. Perhaps I may be missing what you are saying...
Isn't this all unnecessary?
Both kmalloc() and dma_alloc() are constrained to allocate memory that doesn't cross an address boundary that is larger than the size. So if you allocate 16k it won't cross a 16k physical address boundary.
David
Re: [PATCH 5/9] PCI: host: brcmstb: add dma-ranges for inbound traffic
Quoted 32 lines · David Laight
From: Jim Quinlan
Quoted 26 lines
Sent: 20 October 2017 16:28
Quoted 10 lines · Christoph Hellwig
Quoted 8 lines · Jim Quinlan
I am not sure I understand your comment -- the size of the request shouldn't be a factor. Let's look at your example of the DMA request of
3fffff00to4000000f(physical memory). Lets say it is for 15 pages. If we block out the last page [0x3ffff000..0x3fffffff] from what is available, there is no 15 page span that can happen across the0x40000000boundary. For SG, there can be no merge that connects a page from one region to another region. Can you give an example of the scenario you are thinking of?Quoted 2 lines
What prevents a merge from say the regions of
0....3fffffff and 40000000....7fffffff?Huh? [0x3ffff000...x3ffffff] is not available to be used. Drawing from the original example, we now have to tell Linux that these are now our effective memory regions:
memc0-a@[ 0....3fffefff] <=> pci@[ 0....3fffefff] memc0-b@[100000000...13fffefff] <=> pci@[ 40000000....7fffefff] memc1-a@[ 40000000....7fffefff] <=> pci@[ 80000000....bfffefff] memc1-b@[300000000...33fffefff] <=> pci@[ c0000000....ffffefff] memc2-a@[ 80000000....bfffefff] <=> pci@[100000000...13fffefff] memc2-b@[c00000000...c3fffffff] <=> pci@[140000000...17fffffff]Quoted 4 lines
This leaves a one-page gap between phsyical memory regions which would normally be contiguous. One cannot have a dma alloc that spans any two regions. This is a drastic step, but I don't see an alternative. Perhaps I may be missing what you are saying...
Quoted 7 lines
Isn't this all unnecessary?
Bothkmalloc()anddma_alloc()are constrained to allocate memory that doesn't cross an address boundary that is larger than the size. So if you allocate 16k it won't cross a 16k physical address boundary.David
Hi David, Christoph was also concerned about this:
"For the block world take a look at __blk_segment_map_sg which does the merging of contiguous pages into a single SG segment. You'd have to override BIOVEC_PHYS_MERGEABLE to prevent this from happening in your supported architectures for the block layer."
Do you consider this a non-issue as well or can this happen and span memory regions?
RE: [PATCH 5/9] PCI: host: brcmstb: add dma-ranges for inbound traffic
From: Jim Quinla
Quoted 1 line
Sent: 24 October 2017 19:08
...
Quoted 9 lines
Hi David, Christoph was also concerned about this:
"For the block world take a look at
__blk_segment_map_sgwhich does the merging of contiguous pages into a single SG segment. You'd have to overrideBIOVEC_PHYS_MERGEABLEto prevent this from happening in your supported architectures for the block layer."Do you consider this a non-issue as well or can this happen and span memory regions?
Probably easiest to have an architecture limit on the addresses that can be merged.
My guess is that this code only really ever merges pages that were allocated contiguously, but have got converted to a list of VA. So stopping merging over even 1MB boundaries would have minimal effect (even if done unconditionally).
I even wonder if the merging is actually worthwhile at all? Maybe if any code has limits on the SG list length. (or reducing the number of cache lines the get dirtied...)
David
PATCH 6/9 PCI/MSI: Enable PCI_MSI_IRQ_DOMAIN support for MIPS
In reply to Jim QuinlanAdd MIPS as an arch that supports PCI_MSI_IRQ_DOMAIN and add generation of msi.h in the MIPS arch.
--- arch/mips/include/asm/Kbuild | 1 + drivers/pci/Kconfig | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)
arch/mips/include/asm/Kbuild +1 -0
@@ -9,6 +9,7 @@ generic-y += irq_work.h generic-y += local64.h generic-y += mcs_spinlock.h generic-y += mm-arch-hooks.h +generic-y += msi.h generic-y += parport.h generic-y += percpu.h generic-y += preempt.h
drivers/pci/Kconfig +1 -1
@@ -25,7 +25,7 @@ config PCI_MSI If you don't know what to do here, say Y. config PCI_MSI_IRQ_DOMAIN - def_bool ARC || ARM || ARM64 || X86 + def_bool ARC || ARM || ARM64 || MIPS || X86 depends on PCI_MSI select GENERIC_MSI_IRQ_DOMAIN
Signature · 1 line
1.9.0.138.g2de3478
PATCH 7/9 PCI: host: brcmstb: add MSI capability
In reply to Jim QuinlanThis commit adds MSI to the Broadcom STB PCIe host controller. It does not add MSIX since that functionality is not in the HW. The MSI controller is physically located within the PCIe block, however, there is no reason why the MSI controller could not be moved elsewhere in the future.
Since the internal Brcmstb MSI controller is intertwined with the PCIe controller, it is not its own platform device but rather part of the PCIe platform device.
--- drivers/pci/host/Kconfig | 12 ++ drivers/pci/host/Makefile | 1 + drivers/pci/host/pci-brcmstb-msi.c | 318 +++++++++++++++++++++++++++++++++++++ drivers/pci/host/pci-brcmstb.c | 72 +++++++-- drivers/pci/host/pci-brcmstb.h | 26 +++ 5 files changed, 419 insertions(+), 10 deletions(-) create mode 100644 drivers/pci/host/pci-brcmstb-msi.c
drivers/pci/host/Kconfig +12 -0
@@ -228,4 +228,16 @@ config PCI_BRCMSTB default ARCH_BRCMSTB || BMIPS_GENERIC help Adds support for Broadcom Settop Box PCIe host controller. + To compile this driver as a module, choose m here. + +config PCI_BRCMSTB_MSI + bool "Broadcom Brcmstb PCIe MSI support" + depends on ARCH_BRCMSTB || BMIPS_GENERIC + depends on OF + depends on PCI_MSI + default PCI_BRCMSTB + help + Say Y here if you want to enable MSI support for Broadcom's iProc + PCIe controller + endmenu
drivers/pci/host/Makefile +1 -0
@@ -23,6 +23,7 @@ obj-$(CONFIG_PCIE_TANGO_SMP8759) += pcie-tango.o obj-$(CONFIG_VMD) += vmd.o obj-$(CONFIG_PCI_BRCMSTB) += brcmstb-pci.o brcmstb-pci-objs := pci-brcmstb.o pci-brcmstb-dma.o +obj-$(CONFIG_PCI_BRCMSTB_MSI) += pci-brcmstb-msi.o # The following drivers are for devices that use the generic ACPI # pci_root.c driver but don't support standard ECAM config access.
drivers/pci/host/pci-brcmstb-msi.c new file +318 -0
318 lines not on this page · raw message
drivers/pci/host/pci-brcmstb.c +62 -10
144 lines not on this page · raw message
drivers/pci/host/pci-brcmstb.h +26 -0
@@ -21,11 +21,37 @@/* Broadcom PCIE Offsets */ #define PCIE_INTR2_CPU_BASE 0x4300 +struct brcm_msi ; +struct brcm_info ; +struct platform_device ; +dma_addr_t brcm_to_pci (dma_addr_t addr);dma_addr_t brcm_to_cpu (dma_addr_t addr);extern struct notifier_block brcmstb_platform_nb; +#ifdef CONFIG_PCI_BRCMSTB_MSI +int brcm_msi_probe (struct platform_device *pdev,struct brcm_info *info); +void brcm_msi_set_regs (struct brcm_msi *chip); +void brcm_msi_remove (struct brcm_msi *chip); +#else +static inline int brcm_msi_probe (struct platform_device *pdev, +struct brcm_info *info) +{ +return -ENODEV ; +} + +static inline void brcm_msi_set_regs (struct brcm_msi *chip) {} +static inline void brcm_msi_remove (struct brcm_msi *chip) {} +#endif /* CONFIG_PCI_BRCMSTB_MSI */ + +struct brcm_info { +int rev; +u64 msi_target_addr; +void __iomem *base; +struct brcm_msi *msi; +}; +#define BRCMSTB_ERROR_CODE (~(dma_addr_t)0x0)#if defined(CONFIG_MIPS )
Signature · 1 line
1.9.0.138.g2de3478
PATCH 8/9 MIPS: BMIPS: add PCI bindings for 7425, 7435
In reply to Jim QuinlanAdds the PCIe nodes for the Broadcom STB PCIe root complex.
--- arch/mips/boot/dts/brcm/bcm7425.dtsi | 25 +++++++++++++++++++++++++ arch/mips/boot/dts/brcm/bcm7435.dtsi | 26 ++++++++++++++++++++++++++ arch/mips/boot/dts/brcm/bcm97425svmb.dts | 4 ++++ arch/mips/boot/dts/brcm/bcm97435svmb.dts | 4 ++++ 4 files changed, 59 insertions(+)
arch/mips/boot/dts/brcm/bcm7425.dtsi +25 -0
@@ -494,4 +494,29 @@ status = "disabled"; }; }; + + pcie: pcie at 10410000 { + reg = <0x10410000 0x830c>; + compatible = "brcm,bcm7425-pcie", "brcm,pci-plat-dev"; + interrupts = <37>, <37>; + interrupt-names = "pcie", "msi"; + interrupt-parent = <&periph_intc>; + #address-cells = <3>; + #size-cells = <2>; + linux,pci-domain = <0>; + brcm,ssc; + msi-controller; + #interrupt-cells = <1>; + /* 4x128mb windows */ + ranges = <0x2000000 0x0 0xd0000000 0xd0000000 0 0x08000000>, + <0x2000000 0x0 0xd8000000 0xd8000000 0 0x08000000>, + <0x2000000 0x0 0xe0000000 0xe0000000 0 0x08000000>, + <0x2000000 0x0 0xe8000000 0xe8000000 0 0x08000000>; + interrupt-map-mask = <0 0 0 7>; + interrupt-map = <0 0 0 1 &periph_intc 33 + 0 0 0 2 &periph_intc 34 + 0 0 0 3 &periph_intc 35 + 0 0 0 4 &periph_intc 36>; + }; + };
arch/mips/boot/dts/brcm/bcm7435.dtsi +26 -0
@@ -509,4 +509,30 @@ status = "disabled"; }; }; + + pcie: pcie at 10410000 { + reg = <0x10410000 0x930c>; + interrupts = <0x27>, <0x27>; + interrupt-names = "pcie", "msi"; + interrupt-parent = <&periph_intc>; + compatible = "brcm,bcm7435-pcie", "brcm,pci-plat-dev"; + #address-cells = <3>; + #size-cells = <2>; + linux,pci-domain = <0>; + brcm,ssc; + msi-controller; + #interrupt-cells = <1>; + /* 4x128mb windows */ + ranges = <0x2000000 0x0 0xd0000000 0xd0000000 0 0x08000000>, + <0x2000000 0x0 0xd8000000 0xd8000000 0 0x08000000>, + <0x2000000 0x0 0xe0000000 0xe0000000 0 0x08000000>, + <0x2000000 0x0 0xe8000000 0xe8000000 0 0x08000000>; + interrupt-map-mask = <0 0 0 7>; + interrupt-map = <0 0 0 1 &periph_intc 35 + 0 0 0 2 &periph_intc 36 + 0 0 0 3 &periph_intc 37 + 0 0 0 4 &periph_intc 38>; + status = "disabled"; + }; + };
arch/mips/boot/dts/brcm/bcm97425svmb.dts +4 -0
@@ -143,3 +143,7 @@ &mspi { status = "okay"; }; + +&pcie { + status = "okay"; +};
arch/mips/boot/dts/brcm/bcm97435svmb.dts +4 -0
@@ -119,3 +119,7 @@ &mspi { status = "okay"; }; + +&pcie { + status = "okay"; +};
Signature · 1 line
1.9.0.138.g2de3478
PATCH 9/9 MIPS: BMIPS: enable PCI
In reply to Jim QuinlanAdds the Kconfig hooks to enable the Broadcom STB PCIe root complex driver for Broadcom MIPS systems.
--- arch/mips/Kconfig | 3 +++ 1 file changed, 3 insertions(+)
arch/mips/Kconfig +3 -0
@@ -209,6 +209,9 @@ config BMIPS_GENERIC select BOOT_RAW select NO_EXCEPT_FILL select USE_OF + select HW_HAS_PCI + select PCI_DRIVERS_GENERIC + select PCI select CEVT_R4K select CSRC_R4K select SYNC_R4K
Signature · 1 line
1.9.0.138.g2de3478