Add Cadence PCIe endpoint driver with new uclass
v2 cover Add Cadence PCIe endpoint driver with new uclass
This patchset adds support for new uclass, UCLASS_PCI_EP allowing new set of PCI endpoint drivers.
Included in the patch is also a driver for Cadence PCIe endpoint.
Changes in V2:
- Removed "pci.h: add missing maskbit" as it was already merged by Simon.
- Added PCI endpoint sandbox driver
- Added testing for sandbox driver
- Addressed issues raised by Simon in UCLASS_PCI_EP class implementation
Ramon Fried (4):
drivers: pci_ep: Introduce UCLASS_PCI_EP uclass
pci_ep: add Cadence PCIe endpoint driver
pci_ep: add pci_ep sandbox driver
test: pci_ep: add basic pci_ep tests
arch/sandbox/dts/test.dts | 4 + configs/sandbox64_defconfig | 2 + configs/sandbox_defconfig | 2 + .../pci_endpoint/cdns,cdns-pcie-ep.txt | 18 + drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/pci_endpoint/Kconfig | 32 ++ drivers/pci_endpoint/Makefile | 8 + drivers/pci_endpoint/pci_ep-uclass.c | 189 +++++++++ drivers/pci_endpoint/pcie-cadence-ep.c | 177 ++++++++ drivers/pci_endpoint/pcie-cadence.h | 309 ++++++++++++++ drivers/pci_endpoint/sandbox-pci_ep.c | 176 ++++++++ include/dm/uclass-id.h | 1 + include/pci_ep.h | 388 ++++++++++++++++++ test/dm/Makefile | 1 + test/dm/pci_ep.c | 45 ++ 16 files changed, 1355 insertions(+) create mode 100644 doc/device-tree-bindings/pci_endpoint/cdns,cdns-pcie-ep.txt create mode 100644 drivers/pci_endpoint/Kconfig create mode 100644 drivers/pci_endpoint/Makefile create mode 100644 drivers/pci_endpoint/pci_ep-uclass.c create mode 100644 drivers/pci_endpoint/pcie-cadence-ep.c create mode 100644 drivers/pci_endpoint/pcie-cadence.h create mode 100644 drivers/pci_endpoint/sandbox-pci_ep.c create mode 100644 include/pci_ep.h create mode 100644 test/dm/pci_ep.c
Signature · 1 line
2.21.0
PATCH v2 1/4 drivers: pci_ep: Introduce UCLASS_PCI_EP uclass
Introduce new UCLASS_PCI_EP class for handling PCI endpoint devices, allowing to set various attributes of the PCI endpoint device, such as:
* configuration space header
* BAR definitions
* outband memory mapping
* start/stop PCI link
---
Changes in V2:
- Changed u8/u16... to uint
- Changed EINVAL to ENOSYS
- Changed void funcs to int
- Added a bit more info in comments
drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/pci_endpoint/Kconfig | 17 ++ drivers/pci_endpoint/Makefile | 6 + drivers/pci_endpoint/pci_ep-uclass.c | 189 +++++++++++++ include/dm/uclass-id.h | 1 + include/pci_ep.h | 388 +++++++++++++++++++++++++++ 7 files changed, 604 insertions(+) create mode 100644 drivers/pci_endpoint/Kconfig create mode 100644 drivers/pci_endpoint/Makefile create mode 100644 drivers/pci_endpoint/pci_ep-uclass.c create mode 100644 include/pci_ep.h
drivers/Kconfig +2 -0
@@ -64,6 +64,8 @@ source "drivers/nvme/Kconfig" source "drivers/pci/Kconfig" +source "drivers/pci_endpoint/Kconfig" + source "drivers/pch/Kconfig" source "drivers/pcmcia/Kconfig"
drivers/Makefile +1 -0
@@ -85,6 +85,7 @@ obj-$(CONFIG_FPGA) += fpga/ obj-y += misc/ obj-$(CONFIG_MMC) += mmc/ obj-$(CONFIG_NVME) += nvme/ +obj-$(CONFIG_PCI_ENDPOINT) += pci_endpoint/ obj-y += pcmcia/ obj-y += dfu/ obj-$(CONFIG_PCH) += pch/
drivers/pci_endpoint/Kconfig new file +17 -0
@@ -0,0 +1,17 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# PCI Endpoint Support +# + +menu "PCI Endpoint" + +config PCI_ENDPOINT + bool "PCI Endpoint Support" + depends on DM + help + Enable this configuration option to support configurable PCI + endpoints. This should be enabled if the platform has a PCI + controllers that can operate in endpoint mode (as a device + connected to PCI host or bridge). + +endmenu
drivers/pci_endpoint/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# (C) Copyright 2019 +# Ramon Fried <[email protected]> + +obj-y += pci_ep-uclass.o
drivers/pci_endpoint/pci_ep-uclass.c new file +189 -0
189 lines not on this page · raw message
include/dm/uclass-id.h +1 -0
@@ -67,6 +67,7 @@ enum uclass_id {UCLASS_PANEL_BACKLIGHT ,/* Backlight controller for panel */ UCLASS_PCH ,/* x86 platform controller hub */ UCLASS_PCI ,/* PCI bus */ +UCLASS_PCI_EP ,/* PCI endpoint device */ UCLASS_PCI_GENERIC ,/* Generic PCI bus device */ UCLASS_PHY ,/* Physical Layer (PHY) device */ UCLASS_PINCONFIG, /* Pin configuration node device */
include/pci_ep.h new file +388 -0
388 lines not on this page · raw message
Signature · 1 line
2.21.0
PATCH v2 1/4 drivers: pci_ep: Introduce UCLASS_PCI_EP uclass
Hi Ramon,
Quoted 9 lines · Ramon Fried
Introduce new
UCLASS_PCI_EPclass for handling PCI endpoint devices, allowing to set various attributes of the PCI endpoint device, such as:
* configuration space header
* BAR definitions
* outband memory mapping
* start/stop PCI link
Quoted 8 lines
Signed-off-by Ramon Fried <[email protected]>---
Changes in V2:
- Changed u8/u16... to uint
- Changed EINVAL to ENOSYS
- Changed void funcs to int
- Added a bit more info in comments
The only thing I see here is that unmap_addr should return an int, and encode_int should be uint, not u8.
Quoted 14 lines
drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/pci_endpoint/Kconfig | 17 ++ drivers/pci_endpoint/Makefile | 6 + drivers/pci_endpoint/pci_ep-uclass.c | 189 +++++++++++++ include/dm/uclass-id.h | 1 + include/pci_ep.h | 388 +++++++++++++++++++++++++++ 7 files changed, 604 insertions(+) create mode 100644 drivers/pci_endpoint/Kconfig create mode 100644 drivers/pci_endpoint/Makefile create mode 100644 drivers/pci_endpoint/pci_ep-uclass.c create mode 100644 include/pci_ep.h
Regards,
Simon
PATCH v2 2/4 pci_ep: add Cadence PCIe endpoint driver
In reply to Ramon FriedAdd Cadence PCIe endpoint driver supporting configuration of header, bars and MSI for device.
---
.../pci_endpoint/cdns,cdns-pcie-ep.txt | 18 + drivers/pci_endpoint/Kconfig | 8 + drivers/pci_endpoint/Makefile | 1 + drivers/pci_endpoint/pcie-cadence-ep.c | 177 ++++++++++ drivers/pci_endpoint/pcie-cadence.h | 309 ++++++++++++++++++ 5 files changed, 513 insertions(+) create mode 100644 doc/device-tree-bindings/pci_endpoint/cdns,cdns-pcie-ep.txt create mode 100644 drivers/pci_endpoint/pcie-cadence-ep.c create mode 100644 drivers/pci_endpoint/pcie-cadence.h
doc/device-tree-bindings/pci_endpoint/cdns,cdns-pcie-ep.txt new file +18 -0
@@ -0,0 +1,18 @@ +* Cadence PCIe endpoint controller + +Required properties: +- compatible: Should contain "cdns,cdns-pcie-ep" to identify the IP used. +- reg: Should contain the controller register base address. + +Optional properties: +- max-functions: Maximum number of functions that can be configured (default 1). +- cdns,max-outbound-regions: Set to maximum number of outbound regions (default 8) + +Example: + +pcie_ep at fc000000 { + compatible = "cdns,cdns-pcie-ep"; + reg = <0x0 0xfc000000 0x0 0x01000000>; + cdns,max-outbound-regions = <16>; + max-functions = /bits/ 8 <8>; +};
drivers/pci_endpoint/Kconfig +8 -0
@@ -14,4 +14,12 @@ config PCI_ENDPOINT controllers that can operate in endpoint mode (as a device connected to PCI host or bridge). +config PCIE_CADENCE_EP + bool "Cadence PCIe endpoint controller" + depends on PCI_ENDPOINT + help + Say Y here if you want to support the Cadence PCIe controller in + endpoint mode. This PCIe controller may be embedded into many + different vendors SoCs. + endmenu
drivers/pci_endpoint/Makefile +1 -0
@@ -4,3 +4,4 @@ # Ramon Fried <[email protected]> obj-y += pci_ep-uclass.o +obj-$(CONFIG_PCIE_CADENCE_EP) += pcie-cadence-ep.o
drivers/pci_endpoint/pcie-cadence-ep.c new file +177 -0
177 lines not on this page · raw message
drivers/pci_endpoint/pcie-cadence.h new file +309 -0
309 lines not on this page · raw message
Signature · 1 line
2.21.0
PATCH v2 2/4 pci_ep: add Cadence PCIe endpoint driver
Hi Ramon,
Quoted 7 lines · Ramon Fried
Add Cadence PCIe endpoint driver supporting configuration of header, bars and MSI for device.
Signed-off-by Ramon Fried <[email protected]>---
Quoted 9 lines
.../pci_endpoint/cdns,cdns-pcie-ep.txt | 18 + drivers/pci_endpoint/Kconfig | 8 + drivers/pci_endpoint/Makefile | 1 + drivers/pci_endpoint/pcie-cadence-ep.c | 177 ++++++++++ drivers/pci_endpoint/pcie-cadence.h | 309 ++++++++++++++++++ 5 files changed, 513 insertions(+) create mode 100644 doc/device-tree-bindings/pci_endpoint/cdns,cdns-pcie-ep.txt create mode 100644 drivers/pci_endpoint/pcie-cadence-ep.c create mode 100644 drivers/pci_endpoint/pcie-cadence.h
This looks OK to me.
Regards,
Simon
PATCH v2 3/4 pci_ep: add pci_ep sandbox driver
In reply to Ramon Fried---
arch/sandbox/dts/test.dts | 4 + configs/sandbox64_defconfig | 2 + configs/sandbox_defconfig | 2 + drivers/pci_endpoint/Kconfig | 7 + drivers/pci_endpoint/Makefile | 1 + drivers/pci_endpoint/sandbox-pci_ep.c | 176 ++++++++++++++++++++++++++ 6 files changed, 192 insertions(+) create mode 100644 drivers/pci_endpoint/sandbox-pci_ep.c
arch/sandbox/dts/test.dts +4 -0
@@ -475,6 +475,10 @@ }; }; + pci_ep: pci_ep { + compatible = "sandbox,pci_ep"; + }; + probing { compatible = "simple-bus"; test1 {
configs/sandbox64_defconfig +2 -0
@@ -127,9 +127,11 @@ CONFIG_SPI_FLASH_WINBOND=y CONFIG_DM_ETH=y CONFIG_NVME=y CONFIG_PCI=y +CONFIG_PCI_ENDPOINT=y CONFIG_DM_PCI=y CONFIG_DM_PCI_COMPAT=y CONFIG_PCI_SANDBOX=y +CONFIG_PCI_SANDBOX_EP=y CONFIG_PHY=y CONFIG_PHY_SANDBOX=y CONFIG_PINCTRL=y
configs/sandbox_defconfig +2 -0
@@ -142,9 +142,11 @@ CONFIG_SPI_FLASH_WINBOND=y CONFIG_DM_ETH=y CONFIG_NVME=y CONFIG_PCI=y +CONFIG_PCI_ENDPOINT=y CONFIG_DM_PCI=y CONFIG_DM_PCI_COMPAT=y CONFIG_PCI_SANDBOX=y +CONFIG_PCI_SANDBOX_EP=y CONFIG_PHY=y CONFIG_PHY_SANDBOX=y CONFIG_PINCTRL=y
drivers/pci_endpoint/Kconfig +7 -0
@@ -22,4 +22,11 @@ config PCIE_CADENCE_EP endpoint mode. This PCIe controller may be embedded into many different vendors SoCs. +config PCI_SANDBOX_EP + bool "Sandbox PCIe endpoint controller" + depends on PCI_ENDPOINT + help + Say Y here if you want to support the Sandbox PCIe controller in + endpoint mode. + endmenu
drivers/pci_endpoint/Makefile +1 -0
@@ -5,3 +5,4 @@ obj-y += pci_ep-uclass.o obj-$(CONFIG_PCIE_CADENCE_EP) += pcie-cadence-ep.o +obj-$(CONFIG_PCI_SANDBOX_EP) += sandbox-pci_ep.o
drivers/pci_endpoint/sandbox-pci_ep.c new file +176 -0
176 lines not on this page · raw message
Signature · 1 line
2.21.0
PATCH v2 3/4 pci_ep: add pci_ep sandbox driver
Hi Ramon,
On Wed, 24 Apr 2019 at 12:54, Ramon Fried <[email protected]> wrote:
Please add a commit message.
Quoted 33 lines
Signed-off-by Ramon Fried <[email protected]>---
arch/sandbox/dts/test.dts | 4 + configs/sandbox64_defconfig | 2 + configs/sandbox_defconfig | 2 + drivers/pci_endpoint/Kconfig | 7 + drivers/pci_endpoint/Makefile | 1 + drivers/pci_endpoint/sandbox-pci_ep.c | 176 ++++++++++++++++++++++++++ 6 files changed, 192 insertions(+) create mode 100644 drivers/pci_endpoint/sandbox-pci_ep.carch/sandbox/dts/test.dts +4
-0@@ -475,6 +475,10 @@ }; }; + pci_ep: pci_ep { + compatible = "sandbox,pci_ep"; + }; + probing { compatible = "simple-bus"; test1 {configs/sandbox64_defconfig +0
-0
configs/sandbox64_defconfig CONFIG_SPI_FLASH_WINBOND=y · line 130
Quoted 4 lines
configs/sandbox64_defconfig +1
-0@@ -127,9 +127,11 @@ CONFIG_SPI_FLASH_WINBOND=y CONFIG_DM_ETH=y CONFIG_NVME=y CONFIG_PCI=y +CONFIG_PCI_ENDPOINT=y
It might be better to 'imply' this in the sandbox Kconfig file.
Quoted 28 lines
configs/sandbox64_defconfig +1
-0CONFIG_DM_PCI=y CONFIG_DM_PCI_COMPAT=y CONFIG_PCI_SANDBOX=y +CONFIG_PCI_SANDBOX_EP=y CONFIG_PHY=y CONFIG_PHY_SANDBOX=y CONFIG_PINCTRL=yconfigs/sandbox_defconfig +2
-0@@ -142,9 +142,11 @@ CONFIG_SPI_FLASH_WINBOND=y CONFIG_DM_ETH=y CONFIG_NVME=y CONFIG_PCI=y +CONFIG_PCI_ENDPOINT=y CONFIG_DM_PCI=y CONFIG_DM_PCI_COMPAT=y CONFIG_PCI_SANDBOX=y +CONFIG_PCI_SANDBOX_EP=y CONFIG_PHY=y CONFIG_PHY_SANDBOX=y CONFIG_PINCTRL=ydrivers/pci_endpoint/Kconfig +0
-0
drivers/pci_endpoint/Kconfig config PCIE_CADENCE_EP · line 29
Quoted 8 lines
drivers/pci_endpoint/Kconfig +5
-0@@ -22,4 +22,11 @@ config PCIE_CADENCE_EP endpoint mode. This PCIe controller may be embedded into many different vendors SoCs. +config PCI_SANDBOX_EP + bool "Sandbox PCIe endpoint controller" + depends on PCI_ENDPOINT + help + Say Y here if you want to support the Sandbox PCIe controller in
Use single space after PCIe
drivers/pci_endpoint/Kconfig config PCIE_CADENCE_EP · line 30
Quoted 1 line
drivers/pci_endpoint/Kconfig +1
-0+ endpoint mode.
How about another few sentences saying what the driver does?
Quoted 17 lines
drivers/pci_endpoint/Kconfig +1
-0+ endmenudrivers/pci_endpoint/Makefile +1
-0@@ -5,3 +5,4 @@ obj-y += pci_ep-uclass.o obj-$(CONFIG_PCIE_CADENCE_EP) += pcie-cadence-ep.o +obj-$(CONFIG_PCI_SANDBOX_EP) += sandbox-pci_ep.odrivers/pci_endpoint/sandbox-pci_ep.c new file +0
-0
drivers/pci_endpoint/sandbox-pci_ep.c line 8
Quoted 8 lines
drivers/pci_endpoint/sandbox-pci_ep.c new file +8
-0@@ -0,0 +1,176 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright (c) 2019 Ramon Fried <[email protected]> +*/ + +#include <common.h> +#include <dm.h> +#include <errno.h>
I think you can drop this
drivers/pci_endpoint/sandbox-pci_ep.c line 12
Quoted 4 lines
drivers/pci_endpoint/sandbox-pci_ep.c new file +4
-0+#include <pci.h> +#include <pci_ep.h> +#include <asm/test.h> +
struct comment, explaining each member.
Quoted 32 lines
drivers/pci_endpoint/sandbox-pci_ep.c new file +32
-0+struct sandbox_pci_ep_priv { +struct pci_ep_header hdr; +int msix; +int msi; +}; + +static const struct udevice_id sandbox_pci_ep_ids[] = { + { .compatible ="sandbox,pci_ep" }, + { } +}; + +static int sandbox_write_header (struct udevice *dev,uint fn, +struct pci_ep_header *hdr) +{ +struct sandbox_pci_ep_priv *priv =dev_get_priv (dev); + +if (fn >0 ) +return -ENODEV ; + +memcpy (&priv->hdr, hdr,sizeof (*hdr)); + +return 0 ; +} + +static int sandbox_read_header (struct udevice *dev,uint fn, +struct pci_ep_header *hdr) +{ +struct sandbox_pci_ep_priv *priv =dev_get_priv (dev); + +if (fn >0 ) +return -ENODEV ; +
drivers/pci_endpoint/sandbox-pci_ep.c line 54
Quoted 10 lines
drivers/pci_endpoint/sandbox-pci_ep.c new file +10
-0+memcpy (hdr, &priv->hdr,sizeof (*hdr)); + +return 0 ; +} + +static int sandbox_set_bar (struct udevice *dev,uint fn, +struct pci_bar *ep_bar) +{ +if (fn >0 ) +return -ENODEV ;
blank line before return. Please fix globally.
drivers/pci_endpoint/sandbox-pci_ep.c line 58
Quoted 4 lines
drivers/pci_endpoint/sandbox-pci_ep.c new file +4
-0+return 0 ; +} + +int sandbox_clear_bar(struct udevice *dev, uint fn,
static int?
Quoted 7 lines
drivers/pci_endpoint/sandbox-pci_ep.c new file +7
-0+ enum pci_barno bar) +{ +if (fn >0 ) +return -ENODEV ; +return 0 ; +} +
drivers/pci_endpoint/sandbox-pci_ep.c line 75
Quoted 10 lines
drivers/pci_endpoint/sandbox-pci_ep.c new file +10
-0+static int sandbox_map_addr (struct udevice *dev,uint fn,phys_addr_t addr, +u64 pci_addr,size_t size) +{ +if (fn >0 ) +return -ENODEV ; + +return 0 ; +} + +static void sandbox_unmap_addr (struct udevice *dev,uint fn,phys_addr_t addr)
This should have a return value
Quoted 92 lines
drivers/pci_endpoint/sandbox-pci_ep.c new file +92
-0+{ +if (fn >0 ) +return ; +} + +static int sandbox_set_msi (struct udevice *dev,uint fn,uint interrupts) +{ +struct sandbox_pci_ep_priv *priv =dev_get_priv (dev); + +if (fn >0 ) +return -ENODEV ; + + priv->msi = interrupts; + +return 0 ; +} + +static int sandbox_get_msi (struct udevice *dev,uint fn) +{ +struct sandbox_pci_ep_priv *priv =dev_get_priv (dev); + +if (fn >0 ) +return -ENODEV ; + +return priv->msi; +} + +static int sandbox_set_msix (struct udevice *dev,uint fn,uint interrupts) +{ +struct sandbox_pci_ep_priv *priv =dev_get_priv (dev); + +if (fn >0 ) +return -ENODEV ; + + priv->msix = interrupts; + +return 0 ; +} + +static int sandbox_get_msix (struct udevice *dev,uint fn) +{ +struct sandbox_pci_ep_priv *priv =dev_get_priv (dev); + +if (fn >0 ) +return -ENODEV ; + +return priv->msix; +} + +static int sandbox_raise_irq (struct udevice *dev,uint fn, +enum pci_ep_irq_type type,uint interrupt_num) +{ +if (fn >0 ) +return -ENODEV ; + +return 0 ; +} + +static int sandbox_start (struct udevice *dev) +{ +return 0 ; +} + +static int sandbox_stop (struct udevice *dev) +{ +return 0 ; +} + +static int sandbox_pci_ep_probe (struct udevice *dev) +{ +struct sandbox_pci_ep_priv *priv =dev_get_priv (dev); + +memset (priv,0 ,sizeof (*priv)); + +return 0 ; +} + +static struct pci_ep_ops sandbox_pci_ep_ops = { + .write_header = sandbox_write_header, + .read_header = sandbox_read_header, + .set_bar = sandbox_set_bar, + .clear_bar = sandbox_clear_bar, + .map_addr = sandbox_map_addr, + .unmap_addr = sandbox_unmap_addr, + .set_msi = sandbox_set_msi, + .get_msi = sandbox_get_msi, + .set_msix = sandbox_set_msix, + .get_msix = sandbox_get_msix, + .raise_irq = sandbox_raise_irq, + .start = sandbox_start, + .stop = sandbox_stop, +};
drivers/pci_endpoint/sandbox-pci_ep.c
Quoted 10 lines
drivers/pci_endpoint/sandbox-pci_ep.c new file +9
-1+ +U_BOOT_DRIVER (pci_ep_sandbox) = { + .name ="pci_ep_sandbox" , + .id =UCLASS_PCI_EP , + .of_match = sandbox_pci_ep_ids, + .probe = sandbox_pci_ep_probe, + .ops = &sandbox_pci_ep_ops, + .priv_auto_alloc_size =sizeof (struct sandbox_pci_ep_priv ), +}; --
You also need an actual test here, perhaps in test/dm/pci.c, which calls each of these methods and checks (perhaps via a back-channel direct call into the driver) that they work. You don't have to be exhaustive, just a basic test for each method.
Regards,
Simon
PATCH v2 3/4 pci_ep: add pci_ep sandbox driver
Quoted 38 lines · Simon Glass
Hi Ramon,
On Wed, 24 Apr 2019 at 12:54, Ramon Fried <[email protected]> wrote:
Please add a commit message.
Quoted 31 lines
Signed-off-by Ramon Fried <[email protected]>---
arch/sandbox/dts/test.dts | 4 + configs/sandbox64_defconfig | 2 + configs/sandbox_defconfig | 2 + drivers/pci_endpoint/Kconfig | 7 + drivers/pci_endpoint/Makefile | 1 + drivers/pci_endpoint/sandbox-pci_ep.c | 176 ++++++++++++++++++++++++++ 6 files changed, 192 insertions(+) create mode 100644 drivers/pci_endpoint/sandbox-pci_ep.carch/sandbox/dts/test.dts +4
-0@@ -475,6 +475,10 @@ }; }; + pci_ep: pci_ep { + compatible = "sandbox,pci_ep"; + }; + probing { compatible = "simple-bus"; test1 {configs/sandbox64_defconfig +0
-1--- a/configs/sandbox64_defconfig
Quoted 8 lines
configs/sandbox64_defconfig CONFIG_SPI_FLASH_WINBOND=y · line 130
Quoted 6 lines
+++ b/configs/sandbox64_defconfig
configs/sandbox64_defconfig +1
-0@@ -127,9 +127,11 @@ CONFIG_SPI_FLASH_WINBOND=y CONFIG_DM_ETH=y CONFIG_NVME=y CONFIG_PCI=y +CONFIG_PCI_ENDPOINT=yIt might be better to 'imply' this in the sandbox
Kconfigfile.
arch/sandbox/Kconfig doesn't include any implies or selects for drivers, am I looking at the wrong file ?
Quoted 143 lines
Quoted 30 lines
configs/sandbox64_defconfig +1
-0CONFIG_DM_PCI=y CONFIG_DM_PCI_COMPAT=y CONFIG_PCI_SANDBOX=y +CONFIG_PCI_SANDBOX_EP=y CONFIG_PHY=y CONFIG_PHY_SANDBOX=y CONFIG_PINCTRL=yconfigs/sandbox_defconfig +2
-0@@ -142,9 +142,11 @@ CONFIG_SPI_FLASH_WINBOND=y CONFIG_DM_ETH=y CONFIG_NVME=y CONFIG_PCI=y +CONFIG_PCI_ENDPOINT=y CONFIG_DM_PCI=y CONFIG_DM_PCI_COMPAT=y CONFIG_PCI_SANDBOX=y +CONFIG_PCI_SANDBOX_EP=y CONFIG_PHY=y CONFIG_PHY_SANDBOX=y CONFIG_PINCTRL=ydrivers/pci_endpoint/Kconfig +0
-0drivers/pci_endpoint/Kconfig config PCIE_CADENCE_EP · line 29
Quoted 8 lines
drivers/pci_endpoint/Kconfig +5
-0@@ -22,4 +22,11 @@ config PCIE_CADENCE_EP endpoint mode. This PCIe controller may be embedded into many different vendors SoCs. +config PCI_SANDBOX_EP + bool "Sandbox PCIe endpoint controller" + depends on PCI_ENDPOINT + help + Say Y here if you want to support the Sandbox PCIe controller inUse single space after PCIe
drivers/pci_endpoint/Kconfig config PCIE_CADENCE_EP · line 30
Quoted 1 line
drivers/pci_endpoint/Kconfig +1
-0+ endpoint mode.How about another few sentences saying what the driver does?
Quoted 17 lines
drivers/pci_endpoint/Kconfig +1
-0+ endmenudrivers/pci_endpoint/Makefile +1
-0@@ -5,3 +5,4 @@ obj-y += pci_ep-uclass.o obj-$(CONFIG_PCIE_CADENCE_EP) += pcie-cadence-ep.o +obj-$(CONFIG_PCI_SANDBOX_EP) += sandbox-pci_ep.odrivers/pci_endpoint/sandbox-pci_ep.c new file +0
-0drivers/pci_endpoint/sandbox-pci_ep.c line 8
Quoted 8 lines
drivers/pci_endpoint/sandbox-pci_ep.c new file +8
-0@@ -0,0 +1,176 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright (c) 2019 Ramon Fried <[email protected]> +*/ + +#include <common.h> +#include <dm.h> +#include <errno.h> I think you can drop this
drivers/pci_endpoint/sandbox-pci_ep.c line 12
Quoted 4 lines
drivers/pci_endpoint/sandbox-pci_ep.c new file +4
-0+#include <pci.h> +#include <pci_ep.h> +#include <asm/test.h> +struct comment, explaining each member.
Quoted 32 lines
drivers/pci_endpoint/sandbox-pci_ep.c new file +32
-0+struct sandbox_pci_ep_priv { +struct pci_ep_header hdr; +int msix; +int msi; +}; + +static const struct udevice_id sandbox_pci_ep_ids[] = { + { .compatible ="sandbox,pci_ep" }, + { } +}; + +static int sandbox_write_header (struct udevice *dev,uint fn, +struct pci_ep_header *hdr) +{ +struct sandbox_pci_ep_priv *priv =dev_get_priv (dev); + +if (fn >0 ) +return -ENODEV ; + +memcpy (&priv->hdr, hdr,sizeof (*hdr)); + +return 0 ; +} + +static int sandbox_read_header (struct udevice *dev,uint fn, +struct pci_ep_header *hdr) +{ +struct sandbox_pci_ep_priv *priv =dev_get_priv (dev); + +if (fn >0 ) +return -ENODEV ; +drivers/pci_endpoint/sandbox-pci_ep.c line 54
Quoted 10 lines
drivers/pci_endpoint/sandbox-pci_ep.c new file +10
-0+memcpy (hdr, &priv->hdr,sizeof (*hdr)); + +return 0 ; +} + +static int sandbox_set_bar (struct udevice *dev,uint fn, +struct pci_bar *ep_bar) +{ +if (fn >0 ) +return -ENODEV ;blank line before return. Please fix globally.
drivers/pci_endpoint/sandbox-pci_ep.c line 58
Quoted 4 lines
drivers/pci_endpoint/sandbox-pci_ep.c new file +4
-0+return 0 ; +} + +int sandbox_clear_bar(struct udevice *dev, uint fn,static int?
Quoted 11 lines
drivers/pci_endpoint/sandbox-pci_ep.c new file +11
-0+ enum pci_barno bar) +{ +if (fn >0 ) +return -ENODEV ; +return 0 ; +} + +static int sandbox_map_addr (struct udevice *dev,uint fn,phys_addr_t addr, +u64 pci_addr,size_t size) +{ +if (fn >0 )
Quoted 8 lines
drivers/pci_endpoint/sandbox-pci_ep.c line 75
Quoted 6 lines
drivers/pci_endpoint/sandbox-pci_ep.c new file +6
-0+return -ENODEV ; + +return 0 ; +} + +static void sandbox_unmap_addr (struct udevice *dev,uint fn,phys_addr_t addr)This should have a return value
this practically behaves like free(), why should it have a return value ?
Quoted 100 lines
Quoted 100 lines
drivers/pci_endpoint/sandbox-pci_ep.c new file +99
-0+{ +if (fn >0 ) +return ; +} + +static int sandbox_set_msi (struct udevice *dev,uint fn,uint interrupts) +{ +struct sandbox_pci_ep_priv *priv =dev_get_priv (dev); + +if (fn >0 ) +return -ENODEV ; + + priv->msi = interrupts; + +return 0 ; +} + +static int sandbox_get_msi (struct udevice *dev,uint fn) +{ +struct sandbox_pci_ep_priv *priv =dev_get_priv (dev); + +if (fn >0 ) +return -ENODEV ; + +return priv->msi; +} + +static int sandbox_set_msix (struct udevice *dev,uint fn,uint interrupts) +{ +struct sandbox_pci_ep_priv *priv =dev_get_priv (dev); + +if (fn >0 ) +return -ENODEV ; + + priv->msix = interrupts; + +return 0 ; +} + +static int sandbox_get_msix (struct udevice *dev,uint fn) +{ +struct sandbox_pci_ep_priv *priv =dev_get_priv (dev); + +if (fn >0 ) +return -ENODEV ; + +return priv->msix; +} + +static int sandbox_raise_irq (struct udevice *dev,uint fn, +enum pci_ep_irq_type type,uint interrupt_num) +{ +if (fn >0 ) +return -ENODEV ; + +return 0 ; +} + +static int sandbox_start (struct udevice *dev) +{ +return 0 ; +} + +static int sandbox_stop (struct udevice *dev) +{ +return 0 ; +} + +static int sandbox_pci_ep_probe (struct udevice *dev) +{ +struct sandbox_pci_ep_priv *priv =dev_get_priv (dev); + +memset (priv,0 ,sizeof (*priv)); + +return 0 ; +} + +static struct pci_ep_ops sandbox_pci_ep_ops = { + .write_header = sandbox_write_header, + .read_header = sandbox_read_header, + .set_bar = sandbox_set_bar, + .clear_bar = sandbox_clear_bar, + .map_addr = sandbox_map_addr, + .unmap_addr = sandbox_unmap_addr, + .set_msi = sandbox_set_msi, + .get_msi = sandbox_get_msi, + .set_msix = sandbox_set_msix, + .get_msix = sandbox_get_msix, + .raise_irq = sandbox_raise_irq, + .start = sandbox_start, + .stop = sandbox_stop, +}; + +U_BOOT_DRIVER (pci_ep_sandbox) = { + .name ="pci_ep_sandbox" , + .id =UCLASS_PCI_EP , + .of_match = sandbox_pci_ep_ids, + .probe = sandbox_pci_ep_probe, + .ops = &sandbox_pci_ep_ops,
Quoted 8 lines
drivers/pci_endpoint/sandbox-pci_ep.c
Quoted 3 lines
drivers/pci_endpoint/sandbox-pci_ep.c new file +2
-1+ .priv_auto_alloc_size = sizeof(struct sandbox_pci_ep_priv), +}; --You also need an actual test here, perhaps in
test/dm/pci.c, which calls each of these methods and checks (perhaps via a back-channel direct call into the driver) that they work. You don't have to be exhaustive, just a basic test for each method.
Not sure I understand, how do you back-channel a driver (removing static ?).
Quoted 3 lines
Regards,
Simon
PATCH v2 3/4 pci_ep: add pci_ep sandbox driver
Hi Ramon,
Quoted 49 lines · Ramon Fried
Quoted 38 lines · Simon Glass
Hi Ramon,
On Wed, 24 Apr 2019 at 12:54, Ramon Fried <[email protected]> wrote:
Please add a commit message.
Quoted 31 lines
Signed-off-by Ramon Fried <[email protected]>---
arch/sandbox/dts/test.dts | 4 + configs/sandbox64_defconfig | 2 + configs/sandbox_defconfig | 2 + drivers/pci_endpoint/Kconfig | 7 + drivers/pci_endpoint/Makefile | 1 + drivers/pci_endpoint/sandbox-pci_ep.c | 176 ++++++++++++++++++++++++++ 6 files changed, 192 insertions(+) create mode 100644 drivers/pci_endpoint/sandbox-pci_ep.carch/sandbox/dts/test.dts +4
-0@@ -475,6 +475,10 @@ }; }; + pci_ep: pci_ep { + compatible = "sandbox,pci_ep"; + }; + probing { compatible = "simple-bus"; test1 {configs/sandbox64_defconfig +0
-1--- a/configs/sandbox64_defconfigQuoted 8 lines
configs/sandbox64_defconfig CONFIG_SPI_FLASH_WINBOND=y · line 130
Quoted 6 lines
+++ b/configs/sandbox64_defconfig
configs/sandbox64_defconfig +1
-0@@ -127,9 +127,11 @@ CONFIG_SPI_FLASH_WINBOND=y CONFIG_DM_ETH=y CONFIG_NVME=y CONFIG_PCI=y +CONFIG_PCI_ENDPOINT=yIt might be better to 'imply' this in the sandbox
Kconfigfile.
Quoted 2 lines
arch/sandbox/Kconfigdoesn't include any implies or selects for drivers, am I looking at the wrong file ?
See arch/Kconfig
Quoted 152 lines
Quoted 144 lines
Quoted 31 lines
configs/sandbox64_defconfig +1
-0CONFIG_DM_PCI=y CONFIG_DM_PCI_COMPAT=y CONFIG_PCI_SANDBOX=y +CONFIG_PCI_SANDBOX_EP=y CONFIG_PHY=y CONFIG_PHY_SANDBOX=y CONFIG_PINCTRL=yconfigs/sandbox_defconfig +2
-0@@ -142,9 +142,11 @@ CONFIG_SPI_FLASH_WINBOND=y CONFIG_DM_ETH=y CONFIG_NVME=y CONFIG_PCI=y +CONFIG_PCI_ENDPOINT=y CONFIG_DM_PCI=y CONFIG_DM_PCI_COMPAT=y CONFIG_PCI_SANDBOX=y +CONFIG_PCI_SANDBOX_EP=y CONFIG_PHY=y CONFIG_PHY_SANDBOX=y CONFIG_PINCTRL=ydrivers/pci_endpoint/Kconfig +0
-0drivers/pci_endpoint/Kconfig config PCIE_CADENCE_EP · line 29
Quoted 8 lines
drivers/pci_endpoint/Kconfig +5
-0@@ -22,4 +22,11 @@ config PCIE_CADENCE_EP endpoint mode. This PCIe controller may be embedded into many different vendors SoCs. +config PCI_SANDBOX_EP + bool "Sandbox PCIe endpoint controller" + depends on PCI_ENDPOINT + help + Say Y here if you want to support the Sandbox PCIe controller inUse single space after PCIe
drivers/pci_endpoint/Kconfig config PCIE_CADENCE_EP · line 30
Quoted 1 line
drivers/pci_endpoint/Kconfig +1
-0+ endpoint mode.How about another few sentences saying what the driver does?
Quoted 17 lines
drivers/pci_endpoint/Kconfig +1
-0+ endmenudrivers/pci_endpoint/Makefile +1
-0@@ -5,3 +5,4 @@ obj-y += pci_ep-uclass.o obj-$(CONFIG_PCIE_CADENCE_EP) += pcie-cadence-ep.o +obj-$(CONFIG_PCI_SANDBOX_EP) += sandbox-pci_ep.odrivers/pci_endpoint/sandbox-pci_ep.c new file +0
-0drivers/pci_endpoint/sandbox-pci_ep.c line 8
Quoted 8 lines
drivers/pci_endpoint/sandbox-pci_ep.c new file +8
-0@@ -0,0 +1,176 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright (c) 2019 Ramon Fried <[email protected]> +*/ + +#include <common.h> +#include <dm.h> +#include <errno.h> I think you can drop this
drivers/pci_endpoint/sandbox-pci_ep.c line 12
Quoted 4 lines
drivers/pci_endpoint/sandbox-pci_ep.c new file +4
-0+#include <pci.h> +#include <pci_ep.h> +#include <asm/test.h> +struct comment, explaining each member.
Quoted 32 lines
drivers/pci_endpoint/sandbox-pci_ep.c new file +32
-0+struct sandbox_pci_ep_priv { +struct pci_ep_header hdr; +int msix; +int msi; +}; + +static const struct udevice_id sandbox_pci_ep_ids[] = { + { .compatible ="sandbox,pci_ep" }, + { } +}; + +static int sandbox_write_header (struct udevice *dev,uint fn, +struct pci_ep_header *hdr) +{ +struct sandbox_pci_ep_priv *priv =dev_get_priv (dev); + +if (fn >0 ) +return -ENODEV ; + +memcpy (&priv->hdr, hdr,sizeof (*hdr)); + +return 0 ; +} + +static int sandbox_read_header (struct udevice *dev,uint fn, +struct pci_ep_header *hdr) +{ +struct sandbox_pci_ep_priv *priv =dev_get_priv (dev); + +if (fn >0 ) +return -ENODEV ; +drivers/pci_endpoint/sandbox-pci_ep.c line 54
Quoted 10 lines
drivers/pci_endpoint/sandbox-pci_ep.c new file +10
-0+memcpy (hdr, &priv->hdr,sizeof (*hdr)); + +return 0 ; +} + +static int sandbox_set_bar (struct udevice *dev,uint fn, +struct pci_bar *ep_bar) +{ +if (fn >0 ) +return -ENODEV ;blank line before return. Please fix globally.
drivers/pci_endpoint/sandbox-pci_ep.c line 58
Quoted 4 lines
drivers/pci_endpoint/sandbox-pci_ep.c new file +4
-0+return 0 ; +} + +int sandbox_clear_bar(struct udevice *dev, uint fn,static int?
Quoted 11 lines
drivers/pci_endpoint/sandbox-pci_ep.c new file +11
-0+ enum pci_barno bar) +{ +if (fn >0 ) +return -ENODEV ; +return 0 ; +} + +static int sandbox_map_addr (struct udevice *dev,uint fn,phys_addr_t addr, +u64 pci_addr,size_t size) +{ +if (fn >0 )Quoted 8 lines
drivers/pci_endpoint/sandbox-pci_ep.c line 75
Quoted 6 lines
drivers/pci_endpoint/sandbox-pci_ep.c new file +6
-0+return -ENODEV ; + +return 0 ; +} + +static void sandbox_unmap_addr (struct udevice *dev,uint fn,phys_addr_t addr)This should have a return value
Quoted 1 line
this practically behaves like
free(), why should it have a return value ?
Well you have the answer two lines below. It should return -EINVAL, not void:
Quoted 108 lines
Quoted 100 lines
Quoted 100 lines
drivers/pci_endpoint/sandbox-pci_ep.c new file +99
-0+{ +if (fn >0 ) +return ; +} + +static int sandbox_set_msi (struct udevice *dev,uint fn,uint interrupts) +{ +struct sandbox_pci_ep_priv *priv =dev_get_priv (dev); + +if (fn >0 ) +return -ENODEV ; + + priv->msi = interrupts; + +return 0 ; +} + +static int sandbox_get_msi (struct udevice *dev,uint fn) +{ +struct sandbox_pci_ep_priv *priv =dev_get_priv (dev); + +if (fn >0 ) +return -ENODEV ; + +return priv->msi; +} + +static int sandbox_set_msix (struct udevice *dev,uint fn,uint interrupts) +{ +struct sandbox_pci_ep_priv *priv =dev_get_priv (dev); + +if (fn >0 ) +return -ENODEV ; + + priv->msix = interrupts; + +return 0 ; +} + +static int sandbox_get_msix (struct udevice *dev,uint fn) +{ +struct sandbox_pci_ep_priv *priv =dev_get_priv (dev); + +if (fn >0 ) +return -ENODEV ; + +return priv->msix; +} + +static int sandbox_raise_irq (struct udevice *dev,uint fn, +enum pci_ep_irq_type type,uint interrupt_num) +{ +if (fn >0 ) +return -ENODEV ; + +return 0 ; +} + +static int sandbox_start (struct udevice *dev) +{ +return 0 ; +} + +static int sandbox_stop (struct udevice *dev) +{ +return 0 ; +} + +static int sandbox_pci_ep_probe (struct udevice *dev) +{ +struct sandbox_pci_ep_priv *priv =dev_get_priv (dev); + +memset (priv,0 ,sizeof (*priv)); + +return 0 ; +} + +static struct pci_ep_ops sandbox_pci_ep_ops = { + .write_header = sandbox_write_header, + .read_header = sandbox_read_header, + .set_bar = sandbox_set_bar, + .clear_bar = sandbox_clear_bar, + .map_addr = sandbox_map_addr, + .unmap_addr = sandbox_unmap_addr, + .set_msi = sandbox_set_msi, + .get_msi = sandbox_get_msi, + .set_msix = sandbox_set_msix, + .get_msix = sandbox_get_msix, + .raise_irq = sandbox_raise_irq, + .start = sandbox_start, + .stop = sandbox_stop, +}; + +U_BOOT_DRIVER (pci_ep_sandbox) = { + .name ="pci_ep_sandbox" , + .id =UCLASS_PCI_EP , + .of_match = sandbox_pci_ep_ids, + .probe = sandbox_pci_ep_probe, + .ops = &sandbox_pci_ep_ops,Quoted 8 lines
drivers/pci_endpoint/sandbox-pci_ep.c
Quoted 3 lines
drivers/pci_endpoint/sandbox-pci_ep.c new file +2
-1+ .priv_auto_alloc_size = sizeof(struct sandbox_pci_ep_priv), +}; --You also need an actual test here, perhaps in
test/dm/pci.c, which calls each of these methods and checks (perhaps via a back-channel direct call into the driver) that they work. You don't have to be exhaustive, just a basic test for each method.
Quoted 1 line
Not sure I understand, how do you back-channel a driver (removing static ?).
Yes that's right. Because it is sandbox this is acceptable, and you can add a prototype to arch/sandbox/include/asm/test.h
See test/dm/sound.c for an example.
It is also possible to add the platdata struct to that header, include it in the test and access the platdata (or priv data) from the test to check that things are ending up their correctly. Another way that I'm trying to get away from is to put things in struct sandbox_state.
Regards,
Simon
PATCH v2 4/4 test: pci_ep: add basic pci_ep tests
In reply to Ramon FriedAdd basic PCI endpoint sandbox testing.
---
test/dm/Makefile | 1 + test/dm/pci_ep.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 test/dm/pci_ep.c
test/dm/Makefile +1 -0
@@ -30,6 +30,7 @@ obj-y += ofnode.o obj-$(CONFIG_OSD) += osd.o obj-$(CONFIG_DM_VIDEO) += panel.o obj-$(CONFIG_DM_PCI) += pci.o +obj-$(CONFIG_PCI_ENDPOINT) += pci_ep.o obj-$(CONFIG_PCH) += pch.o obj-$(CONFIG_PHY) += phy.o obj-$(CONFIG_POWER_DOMAIN) += power-domain.o
test/dm/pci_ep.c new file +45 -0
45 lines not on this page · raw message
Signature · 1 line
2.21.0