drivers: pci: add map_bar support for Enhanced Allocation
Subsystems (3)
PATCH 1/2 drivers: pci: add map_bar support for Enhanced Allocation
Makes dm_pci_map_bar function available for integrated PCI devices that support Enhanced Allocation instead of original PCI BAR mechanism.
--- drivers/pci/pci-uclass.c | 47 ++++++++++++++++++++++++++++++++++++++++ include/pci.h | 2 +- 2 files changed, 48 insertions(+), 1 deletion(-)
drivers/pci/pci-uclass.c +47 -0
@@ -1341,11 +1341,58 @@ pci_addr_t dm_pci_phys_to_bus(struct udevice *dev, phys_addr_t phys_addr,return bus_addr; } +static void *dm_pci_map_ea_bar (struct udevice *dev,int bar,int flags) +{ +int ea_off, ea_cnt, i, entry_size =0 ; +int bar_id = bar -PCI_BASE_ADDRESS_0 ; +u32 ea_entry; +u64 addr; + +/* handle PCI functions that use Enhanced Allocation */ + ea_off =dm_pci_find_capability (dev,PCI_CAP_ID_EA ); + +if (!ea_off) +return 0 ; + +/* EA capability structure header */ +dm_pci_read_config32 (dev, ea_off, &ea_entry); + ea_cnt = (ea_entry >>16 ) &0x3f ; + ea_off +=4 ; + +for (i =0 ; i < ea_cnt; i++, ea_off += entry_size) { +/* Entry header */ +dm_pci_read_config32 (dev, ea_off, &ea_entry); + entry_size = (ea_entry &0x7 ) *4 ; + +if (((ea_entry >>4 ) &0xf ) != bar_id) +continue ; + +/* Base address, 1st DW */ +dm_pci_read_config32 (dev, ea_off +4 , &ea_entry); + addr = ea_entry & ~0x3 ; +if (ea_entry &0x2 ) { +dm_pci_read_config32 (dev, ea_off +12 , &ea_entry); + addr |= (u64 )ea_entry <<32 ; + } + +/* size ignored for now */ +return map_physmem (addr, flags,0 ); + } +return 0 ; +} +void *dm_pci_map_bar (struct udevice *dev,int bar,int flags) {pci_addr_t pci_bus_addr;u32 bar_response; +/* +* if the function supports Enhanced Allocation use that instead of +* BARs +*/ +if (dm_pci_find_capability (dev,PCI_CAP_ID_EA )) +return dm_pci_map_ea_bar (dev, bar, flags); +/* read BAR address */ dm_pci_read_config32 (dev, bar, &bar_response); pci_bus_addr = (pci_addr_t)(bar_response & ~0xf );
include/pci.h +1 -1
@@ -1314,7 +1314,7 @@ pci_addr_t dm_pci_phys_to_bus(struct udevice *dev, phys_addr_t addr,* @dev: Device to check * @bar: Bar number to read (numbered from 0) * @flags: Flags for the region type (PCI_REGION_...) -* @return: pointer to the virtual address to use +* @return: pointer to the virtual address to use or 0 on error */ void *dm_pci_map_bar (struct udevice *dev,int bar,int flags);
Signature · 1 line
2.17.1
PATCH 2/2 drivers: pci: add API to issue FLR on a PCI function, if supported
--- drivers/pci/pci-uclass.c | 25 +++++++++++++++++++++++++ include/pci.h | 11 +++++++++++ 2 files changed, 36 insertions(+)
drivers/pci/pci-uclass.c +25 -0
@@ -1495,6 +1495,31 @@ int dm_pci_find_ext_capability(struct udevice *dev, int cap)return dm_pci_find_next_ext_capability (dev,0 , cap); } +int dm_pci_flr (struct udevice *dev) +{ +int pcie_off; +u32 cap; +u16 cmd; + +/* look for PCI Express Capability */ + pcie_off =dm_pci_find_capability (dev,PCI_CAP_ID_EXP ); +if (!pcie_off) +return -ENOENT ; + +/* check FLR capability */ +dm_pci_read_config32 (dev, pcie_off +4 , &cap); +if (!(cap &PCI_X_CAP_FLR )) +return -ENOENT ; + +dm_pci_read_config16 (dev, pcie_off +8 , &cmd); +dm_pci_write_config16 (dev, pcie_off +8 , cmd |PCI_X_CMD_FLR ); + +/* wait 100ms, per PCI spec */ +mdelay (100 ); + +return 0 ; +} +UCLASS_DRIVER (pci) = { .id =UCLASS_PCI , .name ="pci" ,
include/pci.h +11 -0
@@ -384,11 +384,14 @@/* PCI-X registers */ +#define PCI_X_CAP_FLR 0x10000000/* Function Level Reset capability */ +#define PCI_X_CMD_DPERR_E 0x0001/* Data Parity Error Recovery Enable */ #define PCI_X_CMD_ERO 0x0002/* Enable Relaxed Ordering */ #define PCI_X_CMD_MAX_READ 0x0000/* Max Memory Read Byte Count */ #define PCI_X_CMD_MAX_SPLIT 0x0030/* Max Outstanding Split Transactions */ #define PCI_X_CMD_VERSION (x) (((x) >> 12) & 3)/* Version */ +#define PCI_X_CMD_FLR 0x8000/* EP Function Level Reset */ /* Slot Identification */
@@ -1411,6 +1414,14 @@ int dm_pci_find_next_ext_capability(struct udevice *dev, int start, int cap);*/ int dm_pci_find_ext_capability (struct udevice *dev,int cap); +/** +* dm_pci_flr() - Perform FLR if the device suppoorts it +* +* @dev: PCI device to reset +* @return: 0 if OK, -ENOENT if FLR is not supported by dev +*/ +int dm_pci_flr (struct udevice *dev); +#define dm_pci_virt_to_bus (dev, addr, flags) \ dm_pci_phys_to_bus(dev, (virt_to_phys(addr)), (flags))#define dm_pci_bus_to_virt (dev, addr, flags, len, map_flags) \
Signature · 1 line
2.17.1
PATCH 1/2 drivers: net: add NXP ENETC ethernet driver
Adds a driver for NXP ENETC ethernet controller currently integrated in LS1028a. ENETC is a fairly straight-forward BD ring device and interfaces are presented as PCI EPs on the SoC ECAM.
--- configs/ls1028aqds_tfa_defconfig | 1 + configs/ls1028ardb_tfa_defconfig | 1 + drivers/net/Kconfig | 7 + drivers/net/Makefile | 1 + drivers/net/fsl_enetc.c | 345 +++++++++++++++++++++++++++++++ drivers/net/fsl_enetc.h | 176 ++++++++++++++++ include/pci_ids.h | 1 + 7 files changed, 532 insertions(+) create mode 100644 drivers/net/fsl_enetc.c create mode 100644 drivers/net/fsl_enetc.h
configs/ls1028aqds_tfa_defconfig +1 -0
@@ -45,6 +45,7 @@ CONFIG_PHY_ATHEROS=y CONFIG_DM_ETH=y CONFIG_PHY_GIGE=y CONFIG_E1000=y +CONFIG_FSL_ENETC=y CONFIG_PCI=y CONFIG_DM_PCI=y CONFIG_DM_PCI_COMPAT=y
configs/ls1028ardb_tfa_defconfig +1 -0
@@ -45,6 +45,7 @@ CONFIG_PHY_ATHEROS=y CONFIG_DM_ETH=y CONFIG_PHY_GIGE=y CONFIG_E1000=y +CONFIG_FSL_ENETC=y CONFIG_PCI=y CONFIG_DM_PCI=y CONFIG_DM_PCI_COMPAT=y
drivers/net/Kconfig +7 -0
@@ -556,4 +556,11 @@ config HIGMACV300_ETH This driver supports HIGMACV300 Ethernet controller found on HiSilicon SoCs. +config FSL_ENETC + bool "NXP ENETC Ethernet controller" + depends on DM_PCI && DM_ETH + help + This driver supports the NXP ENETC Ethernet controller found on some + of the NXP SoCs. + endif # NETDEVICES
drivers/net/Makefile +1 -0
@@ -77,3 +77,4 @@ obj-y += ti/ obj-$(CONFIG_MEDIATEK_ETH) += mtk_eth.o obj-y += mscc_eswitch/ obj-$(CONFIG_HIGMACV300_ETH) += higmacv300.o +obj-$(CONFIG_FSL_ENETC) += fsl_enetc.o
drivers/net/fsl_enetc.c new file +345 -0
345 lines not on this page · raw message
drivers/net/fsl_enetc.h new file +176 -0
176 lines not on this page · raw message
include/pci_ids.h +1 -0
@@ -2483,6 +2483,7 @@#define PCI_DEVICE_ID_MPC8641 0x7010#define PCI_DEVICE_ID_MPC8641D 0x7011#define PCI_DEVICE_ID_MPC8610 0x7018 +#define PCI_DEVICE_ID_ENETC_PF_V1 0xE100#define PCI_VENDOR_ID_PASEMI 0x1959
Signature · 1 line
2.17.1
PATCH 2/2 drivers: net: add NXP ENETC MDIO driver
Adds a driver for the MDIO interface currently integrated in LS1028a SoC. This MDIO interface is shared by multiple ethernet interfaces and is presented as a stand-alone PCI function on the SoC ECAM.
--- configs/ls1028aqds_tfa_defconfig | 1 + configs/ls1028ardb_tfa_defconfig | 1 + drivers/net/fsl_enetc.c | 169 +++++++++++++++++++++++++++++++ drivers/net/fsl_enetc.h | 13 +++ include/pci_ids.h | 1 + 5 files changed, 185 insertions(+)
configs/ls1028aqds_tfa_defconfig +1 -0
@@ -43,6 +43,7 @@ CONFIG_SPI_FLASH_STMICRO=y CONFIG_PHYLIB=y CONFIG_PHY_ATHEROS=y CONFIG_DM_ETH=y +CONFIG_DM_MDIO=y CONFIG_PHY_GIGE=y CONFIG_E1000=y CONFIG_FSL_ENETC=y
configs/ls1028ardb_tfa_defconfig +1 -0
@@ -43,6 +43,7 @@ CONFIG_SPI_FLASH_STMICRO=y CONFIG_PHYLIB=y CONFIG_PHY_ATHEROS=y CONFIG_DM_ETH=y +CONFIG_DM_MDIO=y CONFIG_PHY_GIGE=y CONFIG_E1000=y CONFIG_FSL_ENETC=y
drivers/net/fsl_enetc.c +169 -0
190 lines not on this page · raw message
drivers/net/fsl_enetc.h +13 -0
@@ -173,4 +173,17 @@ struct enetc_devfn {#define enetc_bdr_write (hw, t, n, off, val) \ enetc_write(hw, ENETC_BDR(t, n, off), val) +#define ENETC_MDIO_CFG 0x1c00 +#define ENETC_EMDIO_CFG_C22 0x00009508 +#define ENETC_EMDIO_CFG_C45 0x00009548 +#define ENETC_MDIO_CTL 0x1c04 +#define ENETC_MDIO_DATA 0x1c08 +#define ENETC_MDIO_STAT 0x1c0c + +#define ENETC_MDIO_READ_ERR 0xffff + +struct enetc_mdio_devfn { +void *regs_base; +}; +#endif /* _ENETC_H */
include/pci_ids.h +1 -0
@@ -2484,6 +2484,7 @@#define PCI_DEVICE_ID_MPC8641D 0x7011#define PCI_DEVICE_ID_MPC8610 0x7018#define PCI_DEVICE_ID_ENETC_PF_V1 0xE100 +#define PCI_DEVICE_ID_MDIO_V1 0xEE01#define PCI_VENDOR_ID_PASEMI 0x1959
Signature · 1 line
2.17.1
PATCH 2/2 drivers: pci: add API to issue FLR on a PCI function, if supported
In reply to Alex Marginean+Simon
Hi Alex,
Quoted 1 line · Alex Marginean
Please add a commit message to explain the changes.
Also a nits in the commit tile: please remove the ,
Quoted 17 lines
Signed-off-by Alex Marginean <[email protected]>--- drivers/pci/pci-uclass.c | 25 +++++++++++++++++++++++++ include/pci.h | 11 +++++++++++ 2 files changed, 36 insertions(+)drivers/pci/pci-uclass.c +3
-0@@ -1495,6 +1495,31 @@ int dm_pci_find_ext_capability(struct udevice *dev, int cap)return dm_pci_find_next_ext_capability (dev,0 , cap); } +int dm_pci_flr (struct udevice *dev) +{ +int pcie_off;
drivers/pci/pci-uclass.c int dm_pci_find_ext_capability(struct udevice *dev, int cap) · line 1510
Quoted 10 lines
drivers/pci/pci-uclass.c +10
-0+u32 cap; +u16 cmd; + +/* look for PCI Express Capability */ + pcie_off =dm_pci_find_capability (dev,PCI_CAP_ID_EXP ); +if (!pcie_off) +return -ENOENT ; + +/* check FLR capability */ +dm_pci_read_config32 (dev, pcie_off +4 , &cap);
Please use macros for offset 4
drivers/pci/pci-uclass.c int dm_pci_find_ext_capability(struct udevice *dev, int cap) · line 1514
Quoted 4 lines
drivers/pci/pci-uclass.c +4
-0+if (!(cap &PCI_X_CAP_FLR )) +return -ENOENT ; + +dm_pci_read_config16 (dev, pcie_off +8 , &cmd);
ditto
Quoted 16 lines
drivers/pci/pci-uclass.c +8
-0+dm_pci_write_config16 (dev, pcie_off +8 , cmd |PCI_X_CMD_FLR ); + +/* wait 100ms, per PCI spec */ +mdelay (100 ); + +return 0 ; +} +UCLASS_DRIVER (pci) = { .id =UCLASS_PCI , .name ="pci" ,include/pci.h +0
-0
include/pci.h line 387
Quoted 4 lines
include/pci.h +1
-0@@ -384,11 +384,14 @@/* PCI-X registers */ +#define PCI_X_CAP_FLR 0x10000000/* Function Level Reset capability */
This is not PCI_X, but PCI express.
include/pci.h line 394
Quoted 7 lines
include/pci.h +2
-0+#define PCI_X_CMD_DPERR_E 0x0001/* Data Parity Error Recovery Enable */ #define PCI_X_CMD_ERO 0x0002/* Enable Relaxed Ordering */ #define PCI_X_CMD_MAX_READ 0x0000/* Max Memory Read Byte Count */ #define PCI_X_CMD_MAX_SPLIT 0x0030/* Max Outstanding Split Transactions */ #define PCI_X_CMD_VERSION (x) (((x) >> 12) & 3)/* Version */ +#define PCI_X_CMD_FLR 0x8000/* EP Function Level Reset */
Ditto. Please import appropriate macros from Linux for above magic numbers too.
Quoted 9 lines
include/pci.h +2
-0/* Slot Identification */ @@ -1411,6 +1414,14 @@ int dm_pci_find_next_ext_capability(struct udevice *dev, int start, int cap);*/ int dm_pci_find_ext_capability (struct udevice *dev,int cap); +/** +* dm_pci_flr() - Perform FLR if the device suppoorts it
include/pci.h int dm_pci_find_next_ext_capability(struct udevice *dev, int start, int cap);
Quoted 10 lines
include/pci.h +6
-1+* +* @dev: PCI device to reset +* @return: 0 if OK, -ENOENT if FLR is not supported by dev +*/ +int dm_pci_flr (struct udevice *dev); +#define dm_pci_virt_to_bus (dev, addr, flags) \ dm_pci_phys_to_bus(dev, (virt_to_phys(addr)), (flags))#define dm_pci_bus_to_virt (dev, addr, flags, len, map_flags) \ --
Regards,
Bin
PATCH 1/2 drivers: pci: add map_bar support for Enhanced Allocation
In reply to Alex Marginean+Simon,
Hi Alex,
Quoted 15 lines · Alex Marginean
Makes
dm_pci_map_barfunction available for integrated PCI devices that support Enhanced Allocation instead of original PCI BAR mechanism.Signed-off-by Alex Marginean <[email protected]>--- drivers/pci/pci-uclass.c | 47 ++++++++++++++++++++++++++++++++++++++++ include/pci.h | 2 +- 2 files changed, 48 insertions(+), 1 deletion(-)drivers/pci/pci-uclass.c +0
-0
drivers/pci/pci-uclass.c pci_addr_t dm_pci_phys_to_bus(struct udevice *dev, phys_addr_t phys_addr, · line 1346
Quoted 6 lines
drivers/pci/pci-uclass.c +3
-0@@ -1341,11 +1341,58 @@ pci_addr_t dm_pci_phys_to_bus(struct udevice *dev, phys_addr_t phys_addr,return bus_addr; } +static void *dm_pci_map_ea_bar (struct udevice *dev,int bar,int flags) +{ +int ea_off, ea_cnt, i, entry_size =0 ;
nits: no need to initialize entry_size here.
drivers/pci/pci-uclass.c pci_addr_t dm_pci_phys_to_bus(struct udevice *dev, phys_addr_t phys_addr, · line 1347
Quoted 1 line
drivers/pci/pci-uclass.c +1
-0+int bar_id = bar -PCI_BASE_ADDRESS_0 ;
This does not work for anything other than BAR0. It should be (bar - PCI_BASE_ADDRESS_0) >> 2;
drivers/pci/pci-uclass.c pci_addr_t dm_pci_phys_to_bus(struct udevice *dev, phys_addr_t phys_addr, · line 1349
Quoted 2 lines
drivers/pci/pci-uclass.c +2
-0+u32 ea_entry; +u64 addr;
This should be: pci_addr_t addr
drivers/pci/pci-uclass.c pci_addr_t dm_pci_phys_to_bus(struct udevice *dev, phys_addr_t phys_addr, · line 1355
Quoted 6 lines
drivers/pci/pci-uclass.c +6
-0+ +/* handle PCI functions that use Enhanced Allocation */ + ea_off =dm_pci_find_capability (dev,PCI_CAP_ID_EA ); + +if (!ea_off) +return 0 ;
Above codes are not necessary. EA offset is already known when calling dm_pci_map_ea_bar() from dm_pci_map_bar(). We can pass the offset to this function.
drivers/pci/pci-uclass.c pci_addr_t dm_pci_phys_to_bus(struct udevice *dev, phys_addr_t phys_addr, · line 1359
Quoted 4 lines
drivers/pci/pci-uclass.c +4
-0+ +/* EA capability structure header */ +dm_pci_read_config32 (dev, ea_off, &ea_entry); + ea_cnt = (ea_entry >>16 ) &0x3f ;
Avoid using magic numbers, instead use a macro PCI_EA_NUM_ENT_MASK. In fact, Linux has several macros for EA capability (include/uapi/linux/pci_regs.h) and we can just import these macros in U-Boot too.
drivers/pci/pci-uclass.c pci_addr_t dm_pci_phys_to_bus(struct udevice *dev, phys_addr_t phys_addr, · line 1362
Quoted 3 lines
drivers/pci/pci-uclass.c +3
-0+ ea_off +=4 ; + +for (i =0 ; i < ea_cnt; i++, ea_off += entry_size) {
nits: two spaces before entry_size
drivers/pci/pci-uclass.c pci_addr_t dm_pci_phys_to_bus(struct udevice *dev, phys_addr_t phys_addr, · line 1365
Quoted 3 lines
drivers/pci/pci-uclass.c +3
-0+/* Entry header */ +dm_pci_read_config32 (dev, ea_off, &ea_entry); + entry_size = (ea_entry &0x7 ) *4 ;
Per the spec, entry size is number of DW following the initial DW in this entry. So it should really be: ((ea_entry & 0x7) + 1) * 4. Again like the bar_id comments above, we can use << 2 here instead of * 4.
Quoted 5 lines
drivers/pci/pci-uclass.c +5
-0+ +if (((ea_entry >>4 ) &0xf ) != bar_id) +continue ; + +/* Base address, 1st DW */
drivers/pci/pci-uclass.c pci_addr_t dm_pci_phys_to_bus(struct udevice *dev, phys_addr_t phys_addr, · line 1380
Quoted 10 lines
drivers/pci/pci-uclass.c +10
-0+dm_pci_read_config32 (dev, ea_off +4 , &ea_entry); + addr = ea_entry & ~0x3 ; +if (ea_entry &0x2 ) { +dm_pci_read_config32 (dev, ea_off +12 , &ea_entry); + addr |= (u64 )ea_entry <<32 ; + } + +/* size ignored for now */ +return map_physmem (addr, flags,0 ); + }
nits: should have one blank line here
Quoted 23 lines
drivers/pci/pci-uclass.c +10
-0+return 0 ; +} +void *dm_pci_map_bar (struct udevice *dev,int bar,int flags) {pci_addr_t pci_bus_addr;u32 bar_response; +/* +* if the function supports Enhanced Allocation use that instead of +* BARs +*/ +if (dm_pci_find_capability (dev,PCI_CAP_ID_EA )) +return dm_pci_map_ea_bar (dev, bar, flags); +/* read BAR address */ dm_pci_read_config32 (dev, bar, &bar_response); pci_bus_addr = (pci_addr_t)(bar_response & ~0xf );include/pci.h +0
-0
include/pci.h pci_addr_t dm_pci_phys_to_bus(struct udevice *dev, phys_addr_t addr, · line 1315
Quoted 2 lines
include/pci.h +0
-0@@ -1314,7 +1314,7 @@ pci_addr_t dm_pci_phys_to_bus(struct udevice *dev, phys_addr_t addr,* @dev: Device to check * @bar: Bar number to read (numbered from 0)
This one is confusing. It it not bar number (0/1/...), but bar register offset. Suggest a separate patch to correct it. And this function seems to only handle BAR0-BAR0 for header type 0. Please also comment that.
include/pci.h pci_addr_t dm_pci_phys_to_bus(struct udevice *dev, phys_addr_t addr, · line 1317
Quoted 3 lines
include/pci.h +1
-1* @flags: Flags for the region type (PCI_REGION_...) -* @return: pointer to the virtual address to use +* @return: pointer to the virtual address to use or 0 on error
This should be separate patch to correct the comments. Together with the bar comments above.
include/pci.h pci_addr_t dm_pci_phys_to_bus(struct udevice *dev, phys_addr_t addr, · line 1319
Quoted 2 lines
include/pci.h +0
-0*/ void *dm_pci_map_bar (struct udevice *dev,int bar,int flags);
Please create test cases in test/dm/pci.c to cover the EA capability test. Especially since there are some bugs in the for loop in dm_pci_map_ea_bar(), we should create case to get something like BAR3 instead of BAR0. I suspect why you did not see the issue was because you only covered the BAR0 hence only one iteration of the for loop was executed.
Regards,
Bin
PATCH 1/2 drivers: pci: add map_bar support for Enhanced Allocation
Hi Bin,
Quoted 29 lines · Bin Meng
+Simon,
Hi Alex,
Quoted 15 lines · Alex Marginean
Makes
dm_pci_map_barfunction available for integrated PCI devices that support Enhanced Allocation instead of original PCI BAR mechanism.Signed-off-by Alex Marginean <[email protected]>--- drivers/pci/pci-uclass.c | 47 ++++++++++++++++++++++++++++++++++++++++ include/pci.h | 2 +- 2 files changed, 48 insertions(+), 1 deletion(-)drivers/pci/pci-uclass.c +0
-0drivers/pci/pci-uclass.c pci_addr_t dm_pci_phys_to_bus(struct udevice *dev, phys_addr_t phys_addr, · line 1346
Quoted 6 lines
drivers/pci/pci-uclass.c +3
-0@@ -1341,11 +1341,58 @@ pci_addr_t dm_pci_phys_to_bus(struct udevice *dev, phys_addr_t phys_addr,return bus_addr; } +static void *dm_pci_map_ea_bar (struct udevice *dev,int bar,int flags) +{ +int ea_off, ea_cnt, i, entry_size =0 ;nits: no need to initialize
entry_sizehere.
Quoted 4 lines
drivers/pci/pci-uclass.c pci_addr_t dm_pci_phys_to_bus(struct udevice *dev, phys_addr_t phys_addr, · line 1347
Quoted 1 line
drivers/pci/pci-uclass.c +1
-0+int bar_id = bar -PCI_BASE_ADDRESS_0 ;This does not work for anything other than BAR0. It should be (bar -
PCI_BASE_ADDRESS_0) >> 2;
Good find, you're right, I did use it only for BAR0 and missed this.
Quoted 5 lines
drivers/pci/pci-uclass.c pci_addr_t dm_pci_phys_to_bus(struct udevice *dev, phys_addr_t phys_addr, · line 1349
Quoted 3 lines
drivers/pci/pci-uclass.c +2
-0+u32 ea_entry; +u64 addr;This should be:
pci_addr_taddr
I think maybe phys_addr_t is more appropriate, EA functions are supposed to be integrated and their BAR equivalent addresses map into system address space. In the end this goes to map_physmem, which takes a phys_addr_t.
Quoted 17 lines
drivers/pci/pci-uclass.c pci_addr_t dm_pci_phys_to_bus(struct udevice *dev, phys_addr_t phys_addr, · line 1355
Quoted 7 lines
drivers/pci/pci-uclass.c +6
-0+ +/* handle PCI functions that use Enhanced Allocation */ + ea_off =dm_pci_find_capability (dev,PCI_CAP_ID_EA ); + +if (!ea_off) +return 0 ;Above codes are not necessary. EA offset is already known when calling
dm_pci_map_ea_bar()fromdm_pci_map_bar(). We can pass the offset to this function.drivers/pci/pci-uclass.c pci_addr_t dm_pci_phys_to_bus(struct udevice *dev, phys_addr_t phys_addr, · line 1359
Quoted 4 lines
drivers/pci/pci-uclass.c +4
-0+ +/* EA capability structure header */ +dm_pci_read_config32 (dev, ea_off, &ea_entry); + ea_cnt = (ea_entry >>16 ) &0x3f ;
Quoted 4 lines
Avoid using magic numbers, instead use a macro
PCI_EA_NUM_ENT_MASK. In fact, Linux has several macros for EA capability (include/uapi/linux/pci_regs.h) and we can just import these macros in U-Boot too.
That's a good suggestion, I will do that.
Quoted 55 lines
drivers/pci/pci-uclass.c pci_addr_t dm_pci_phys_to_bus(struct udevice *dev, phys_addr_t phys_addr, · line 1362
Quoted 4 lines
drivers/pci/pci-uclass.c +3
-0+ ea_off +=4 ; + +for (i =0 ; i < ea_cnt; i++, ea_off += entry_size) {nits: two spaces before
entry_sizedrivers/pci/pci-uclass.c pci_addr_t dm_pci_phys_to_bus(struct udevice *dev, phys_addr_t phys_addr, · line 1365
Quoted 3 lines
drivers/pci/pci-uclass.c +3
-0+/* Entry header */ +dm_pci_read_config32 (dev, ea_off, &ea_entry); + entry_size = (ea_entry &0x7 ) *4 ;Per the spec, entry size is number of DW following the initial DW in this entry. So it should really be: ((
ea_entry&0x7) + 1) * 4. Again like thebar_idcomments above, we can use << 2 here instead of * 4.Quoted 5 lines
drivers/pci/pci-uclass.c +5
-0+ +if (((ea_entry >>4 ) &0xf ) != bar_id) +continue ; + +/* Base address, 1st DW */ drivers/pci/pci-uclass.c pci_addr_t dm_pci_phys_to_bus(struct udevice *dev, phys_addr_t phys_addr, · line 1380
Quoted 10 lines
drivers/pci/pci-uclass.c +10
-0+dm_pci_read_config32 (dev, ea_off +4 , &ea_entry); + addr = ea_entry & ~0x3 ; +if (ea_entry &0x2 ) { +dm_pci_read_config32 (dev, ea_off +12 , &ea_entry); + addr |= (u64 )ea_entry <<32 ; + } + +/* size ignored for now */ +return map_physmem (addr, flags,0 ); + }nits: should have one blank line here
Quoted 22 lines
drivers/pci/pci-uclass.c +10
-0+return 0 ; +} +void *dm_pci_map_bar (struct udevice *dev,int bar,int flags) {pci_addr_t pci_bus_addr;u32 bar_response; +/* +* if the function supports Enhanced Allocation use that instead of +* BARs +*/ +if (dm_pci_find_capability (dev,PCI_CAP_ID_EA )) +return dm_pci_map_ea_bar (dev, bar, flags); +/* read BAR address */ dm_pci_read_config32 (dev, bar, &bar_response); pci_bus_addr = (pci_addr_t)(bar_response & ~0xf );include/pci.h +0
-0
Quoted 8 lines
include/pci.h pci_addr_t dm_pci_phys_to_bus(struct udevice *dev, phys_addr_t addr, · line 1315
Quoted 3 lines
include/pci.h +0
-0@@ -1314,7 +1314,7 @@ pci_addr_t dm_pci_phys_to_bus(struct udevice *dev, phys_addr_t addr,* @dev: Device to check * @bar: Bar number to read (numbered from 0) This one is confusing. It it not bar number (0/1/...), but bar register offset. Suggest a separate patch to correct it. And this function seems to only handle BAR0-BAR0 for header type 0. Please also comment that.
I suppose it works for BARs0-5 on type 0. I'm not clear if it also works for type 1 though, type 1 defines a couple of BARs at offset 0x10 too.
Quoted 11 lines
include/pci.h pci_addr_t dm_pci_phys_to_bus(struct udevice *dev, phys_addr_t addr, · line 1317
Quoted 4 lines
include/pci.h +1
-1* @flags: Flags for the region type (PCI_REGION_...) -* @return: pointer to the virtual address to use +* @return: pointer to the virtual address to use or 0 on error This should be separate patch to correct the comments. Together with the bar comments above.
include/pci.h pci_addr_t dm_pci_phys_to_bus(struct udevice *dev, phys_addr_t addr, · line 1319
Quoted 2 lines
include/pci.h +0
-0*/ void *dm_pci_map_bar (struct udevice *dev,int bar,int flags);
Quoted 6 lines
Please create test cases in
test/dm/pci.cto cover the EA capability test. Especially since there are some bugs in the for loop indm_pci_map_ea_bar(), we should create case to get something like BAR3 instead of BAR0. I suspect why you did not see the issue was because you only covered the BAR0 hence only one iteration of the for loop was executed.
Yes, that's precisely what I did..
Quoted 4 lines
Regards,
Bin
Thank you!
Alex
PATCH 1/2 drivers: pci: add map_bar support for Enhanced Allocation
Hi Alex,
Quoted 44 lines · Alex Marginean
Hi Bin,
Quoted 29 lines · Bin Meng
+Simon,
Hi Alex,
Quoted 15 lines · Alex Marginean
Makes
dm_pci_map_barfunction available for integrated PCI devices that support Enhanced Allocation instead of original PCI BAR mechanism.Signed-off-by Alex Marginean <[email protected]>--- drivers/pci/pci-uclass.c | 47 ++++++++++++++++++++++++++++++++++++++++ include/pci.h | 2 +- 2 files changed, 48 insertions(+), 1 deletion(-)drivers/pci/pci-uclass.c +0
-0drivers/pci/pci-uclass.c pci_addr_t dm_pci_phys_to_bus(struct udevice *dev, phys_addr_t phys_addr, · line 1346
Quoted 6 lines
drivers/pci/pci-uclass.c +3
-0@@ -1341,11 +1341,58 @@ pci_addr_t dm_pci_phys_to_bus(struct udevice *dev, phys_addr_t phys_addr,return bus_addr; } +static void *dm_pci_map_ea_bar (struct udevice *dev,int bar,int flags) +{ +int ea_off, ea_cnt, i, entry_size =0 ;nits: no need to initialize
entry_sizehere.Quoted 4 lines
drivers/pci/pci-uclass.c pci_addr_t dm_pci_phys_to_bus(struct udevice *dev, phys_addr_t phys_addr, · line 1347
Quoted 1 line
drivers/pci/pci-uclass.c +1
-0+int bar_id = bar -PCI_BASE_ADDRESS_0 ;This does not work for anything other than BAR0. It should be (bar -
PCI_BASE_ADDRESS_0) >> 2;Good find, you're right, I did use it only for BAR0 and missed this.
Quoted 4 lines
Quoted 3 lines
drivers/pci/pci-uclass.c +2
-0+u32 ea_entry; +u64 addr;
Quoted 7 lines
Quoted 1 line
This should be:
pci_addr_taddrI think maybe
phys_addr_tis more appropriate, EA functions are supposed to be integrated and their BAR equivalent addresses map into system address space. In the end this goes tomap_physmem, which takes aphys_addr_t.
Makes sense.
Quoted 88 lines
Quoted 17 lines
drivers/pci/pci-uclass.c pci_addr_t dm_pci_phys_to_bus(struct udevice *dev, phys_addr_t phys_addr, · line 1355
Quoted 7 lines
drivers/pci/pci-uclass.c +6
-0+ +/* handle PCI functions that use Enhanced Allocation */ + ea_off =dm_pci_find_capability (dev,PCI_CAP_ID_EA ); + +if (!ea_off) +return 0 ;Above codes are not necessary. EA offset is already known when calling
dm_pci_map_ea_bar()fromdm_pci_map_bar(). We can pass the offset to this function.drivers/pci/pci-uclass.c pci_addr_t dm_pci_phys_to_bus(struct udevice *dev, phys_addr_t phys_addr, · line 1359
Quoted 4 lines
drivers/pci/pci-uclass.c +4
-0+ +/* EA capability structure header */ +dm_pci_read_config32 (dev, ea_off, &ea_entry); + ea_cnt = (ea_entry >>16 ) &0x3f ;Quoted 4 lines
Avoid using magic numbers, instead use a macro
PCI_EA_NUM_ENT_MASK. In fact, Linux has several macros for EA capability (include/uapi/linux/pci_regs.h) and we can just import these macros in U-Boot too.That's a good suggestion, I will do that.
Quoted 55 lines
drivers/pci/pci-uclass.c pci_addr_t dm_pci_phys_to_bus(struct udevice *dev, phys_addr_t phys_addr, · line 1362
Quoted 4 lines
drivers/pci/pci-uclass.c +3
-0+ ea_off +=4 ; + +for (i =0 ; i < ea_cnt; i++, ea_off += entry_size) {nits: two spaces before
entry_sizedrivers/pci/pci-uclass.c pci_addr_t dm_pci_phys_to_bus(struct udevice *dev, phys_addr_t phys_addr, · line 1365
Quoted 3 lines
drivers/pci/pci-uclass.c +3
-0+/* Entry header */ +dm_pci_read_config32 (dev, ea_off, &ea_entry); + entry_size = (ea_entry &0x7 ) *4 ;Per the spec, entry size is number of DW following the initial DW in this entry. So it should really be: ((
ea_entry&0x7) + 1) * 4. Again like thebar_idcomments above, we can use << 2 here instead of * 4.Quoted 5 lines
drivers/pci/pci-uclass.c +5
-0+ +if (((ea_entry >>4 ) &0xf ) != bar_id) +continue ; + +/* Base address, 1st DW */ drivers/pci/pci-uclass.c pci_addr_t dm_pci_phys_to_bus(struct udevice *dev, phys_addr_t phys_addr, · line 1380
Quoted 10 lines
drivers/pci/pci-uclass.c +10
-0+dm_pci_read_config32 (dev, ea_off +4 , &ea_entry); + addr = ea_entry & ~0x3 ; +if (ea_entry &0x2 ) { +dm_pci_read_config32 (dev, ea_off +12 , &ea_entry); + addr |= (u64 )ea_entry <<32 ; + } + +/* size ignored for now */ +return map_physmem (addr, flags,0 ); + }nits: should have one blank line here
Quoted 22 lines
drivers/pci/pci-uclass.c +10
-0+return 0 ; +} +void *dm_pci_map_bar (struct udevice *dev,int bar,int flags) {pci_addr_t pci_bus_addr;u32 bar_response; +/* +* if the function supports Enhanced Allocation use that instead of +* BARs +*/ +if (dm_pci_find_capability (dev,PCI_CAP_ID_EA )) +return dm_pci_map_ea_bar (dev, bar, flags); +/* read BAR address */ dm_pci_read_config32 (dev, bar, &bar_response); pci_bus_addr = (pci_addr_t)(bar_response & ~0xf );include/pci.h +0
-0Quoted 8 lines
include/pci.h pci_addr_t dm_pci_phys_to_bus(struct udevice *dev, phys_addr_t addr, · line 1315
Quoted 3 lines
include/pci.h +0
-0@@ -1314,7 +1314,7 @@ pci_addr_t dm_pci_phys_to_bus(struct udevice *dev, phys_addr_t addr,* @dev: Device to check * @bar: Bar number to read (numbered from 0) This one is confusing. It it not bar number (0/1/...), but bar register offset. Suggest a separate patch to correct it. And this function seems to only handle BAR0-BAR0 for header type 0. Please also comment that.
Quoted 4 lines
I suppose it works for BARs0-5 on type 0. I'm not clear if it also works for type 1 though, type 1 defines a couple of BARs at offset
0x10too.
Yes, I think type 1's BAR0/BAR1 are also supported.
Quoted 11 lines
Quoted 11 lines
include/pci.h pci_addr_t dm_pci_phys_to_bus(struct udevice *dev, phys_addr_t addr, · line 1317
Quoted 4 lines
include/pci.h +1
-1* @flags: Flags for the region type (PCI_REGION_...) -* @return: pointer to the virtual address to use +* @return: pointer to the virtual address to use or 0 on error This should be separate patch to correct the comments. Together with the bar comments above.
Quoted 2 lines
include/pci.h +0
-0*/ void *dm_pci_map_bar (struct udevice *dev,int bar,int flags);
Quoted 9 lines
Quoted 6 lines
Please create test cases in
test/dm/pci.cto cover the EA capability test. Especially since there are some bugs in the for loop indm_pci_map_ea_bar(), we should create case to get something like BAR3 instead of BAR0. I suspect why you did not see the issue was because you only covered the BAR0 hence only one iteration of the for loop was executed.Yes, that's precisely what I did..
Regards,
Bin
PATCH v2 1/4 pci: fixed dm_pci_map_bar comment
In reply to Bin MengThe comment now indicates that the input argument bar is a register offset, not a BAR index.
It also mentions which BARs are supported for type 0/1 and that the function can return 0 on error.
---
Changes in v2:
- new patch
include/pci.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
include/pci.h +5 -3
@@ -1309,12 +1309,14 @@ pci_addr_t dm_pci_phys_to_bus(struct udevice *dev, phys_addr_t addr,* dm_pci_map_bar() - get a virtual address associated with a BAR region * * Looks up a base address register and finds the physical memory address -* that corresponds to it +* that corresponds to it. +* Can be used for 32b BARs 0-5 on type 0 functions and for 32b BARs 0-1 on +* type 1 functions. * * @dev: Device to check -* @bar: Bar number to read (numbered from 0) +* @bar: Bar register offset (PCI_BASE_ADDRESS_...) * @flags: Flags for the region type (PCI_REGION_...) -* @return: pointer to the virtual address to use +* @return: pointer to the virtual address to use or 0 on error */ void *dm_pci_map_bar (struct udevice *dev,int bar,int flags);
Signature · 1 line
2.17.1
PATCH v2 2/4 drivers: pci: add map_bar support for Enhanced Allocation
Makes dm_pci_map_bar API available for integrated PCI devices that support Enhanced Allocation instead of the original PCI BAR mechanism.
---
Changes in v2:
- fixed parsing for BAR1+
- fixed an issue with EA entry size
- don't look up EA capability structure twice
- use phys_addr_t for EA addresses
- use kernel MACROS for EA registers
drivers/pci/pci-uclass.c | 46 ++++++++++++++++++++++++++++++++++++++++ include/pci.h | 13 ++++++++++++ 2 files changed, 59 insertions(+)
drivers/pci/pci-uclass.c +46 -0
@@ -1341,10 +1341,56 @@ pci_addr_t dm_pci_phys_to_bus(struct udevice *dev, phys_addr_t phys_addr,return bus_addr; } +static void *dm_pci_map_ea_bar (struct udevice *dev,int bar,int flags, +int ea_off) +{ +int ea_cnt, i, entry_size; +int bar_id = (bar -PCI_BASE_ADDRESS_0 ) >>2 ; +u32 ea_entry; +phys_addr_t addr; + +/* EA capability structure header */ +dm_pci_read_config32 (dev, ea_off, &ea_entry); + ea_cnt = (ea_entry >>16 ) &PCI_EA_NUM_ENT_MASK ; + ea_off +=PCI_EA_FIRST_ENT ; + +for (i =0 ; i < ea_cnt; i++, ea_off += entry_size) { +/* Entry header */ +dm_pci_read_config32 (dev, ea_off, &ea_entry); + entry_size = ((ea_entry &PCI_EA_ES ) +1 ) <<2 ; + +if (((ea_entry &PCI_EA_BEI ) >>4 ) != bar_id) +continue ; + +/* Base address, 1st DW */ +dm_pci_read_config32 (dev, ea_off +4 , &ea_entry); + addr = ea_entry &PCI_EA_FIELD_MASK ; +if (ea_entry &PCI_EA_IS_64 ) { +/* Base address, 2nd DW, skip over 4B MaxOffset */ +dm_pci_read_config32 (dev, ea_off +12 , &ea_entry); + addr |= ((u64 )ea_entry) <<32 ; + } + +/* size ignored for now */ +return map_physmem (addr, flags,0 ); + } + +return 0 ; +} +void *dm_pci_map_bar (struct udevice *dev,int bar,int flags) {pci_addr_t pci_bus_addr;u32 bar_response; +int ea_off; + +/* +* if the function supports Enhanced Allocation use that instead of +* BARs +*/ + ea_off =dm_pci_find_capability (dev,PCI_CAP_ID_EA ); +if (ea_off) +return dm_pci_map_ea_bar (dev, bar, flags, ea_off);/* read BAR address */ dm_pci_read_config32 (dev, bar, &bar_response);
include/pci.h +13 -0
@@ -455,6 +455,17 @@#define PCI_EXT_CAP_ID_PTM 0x1F/* Precision Time Measurement */ #define PCI_EXT_CAP_ID_MAX PCI_EXT_CAP_ID_PTM +/* Enhanced Allocation Registers */ +#define PCI_EA_NUM_ENT 2/* Number of Capability Entries */ +#define PCI_EA_NUM_ENT_MASK 0x3f/* Num Entries Mask */ +#define PCI_EA_FIRST_ENT 4/* First EA Entry in List */ +#define PCI_EA_ES 0x00000007/* Entry Size */ +#define PCI_EA_BEI 0x000000f0/* BAR Equivalent Indicator */ +/* Base, MaxOffset registers */ +/* bit 0 is reserved */ +#define PCI_EA_IS_64 0x00000002/* 64-bit field flag */ +#define PCI_EA_FIELD_MASK 0xfffffffc/* For Base & Max Offset */ +/* Include the ID list */ #include <pci_ids.h>
@@ -1312,6 +1323,8 @@ pci_addr_t dm_pci_phys_to_bus(struct udevice *dev, phys_addr_t addr,* that corresponds to it. * Can be used for 32b BARs 0-5 on type 0 functions and for 32b BARs 0-1 on * type 1 functions. +* Can also be used on type 0 functions that support Enhanced Allocation for +* 32b/64b BARs. Note that duplicate BEI entries are not supported. * * @dev: Device to check * @bar: Bar register offset (PCI_BASE_ADDRESS_...)
Signature · 1 line
2.17.1
PATCH v2 2/4 drivers: pci: add map_bar support for Enhanced Allocation
Quoted 14 lines · Alex Marginean
Makes
dm_pci_map_barAPI available for integrated PCI devices that support Enhanced Allocation instead of the original PCI BAR mechanism.Signed-off-by Alex Marginean <[email protected]>---
Changes in v2:
- fixed parsing for BAR1+
- fixed an issue with EA entry size
- don't look up EA capability structure twice
- usephys_addr_tfor EA addresses
- use kernel MACROS for EA registers
Quoted 4 lines
drivers/pci/pci-uclass.c | 46 ++++++++++++++++++++++++++++++++++++++++ include/pci.h | 13 ++++++++++++ 2 files changed, 59 insertions(+)
PATCH v2 3/4 test: dm: Add a test for PCI Enhanced Allocation
In reply to Alex MargineanThis test is built on top of the existing swap_case driver. It adds EA capability structure support to swap_case and uses that to map BARs. BAR1 works as it used to, swapping upper/lower case. BARs 2,4 map to a couple of magic values.
---
Changes in v2:
- new patch, v1 didn't have a test
arch/sandbox/dts/test.dts | 8 +++ arch/sandbox/include/asm/test.h | 13 ++++ drivers/misc/swap_case.c | 102 +++++++++++++++++++++++++++++++- test/dm/pci.c | 50 ++++++++++++++++ 4 files changed, 172 insertions(+), 1 deletion(-)
arch/sandbox/dts/test.dts +8 -0
@@ -434,6 +434,14 @@ compatible = "sandbox,swap-case"; }; }; + pci at 1,0 { + compatible = "pci-generic"; + reg = <0x0800 0 0 0 0>; + emul at 0,0 { + compatible = "sandbox,swap-case"; + use-ea; + }; + }; pci at 1f,0 { compatible = "pci-generic"; reg = <0xf800 0 0 0 0>;
arch/sandbox/include/asm/test.h +13 -0
@@ -19,6 +19,7 @@#define PCI_CAP_ID_PM_OFFSET 0x50#define PCI_CAP_ID_EXP_OFFSET 0x60#define PCI_CAP_ID_MSIX_OFFSET 0x70 +#define PCI_CAP_ID_EA_OFFSET 0x80#define PCI_EXT_CAP_ID_ERR_OFFSET 0x100#define PCI_EXT_CAP_ID_VC_OFFSET 0x200
@@ -30,6 +31,18 @@#define SANDBOX_CLK_RATE 32768 +/* Macros used to test PCI EA capability structure */ +#define PCI_CAP_EA_BASE_LO0 0x00100000 +#define PCI_CAP_EA_BASE_LO1 0x00110000 +#define PCI_CAP_EA_BASE_LO2 0x00120000 +#define PCI_CAP_EA_BASE_LO4 0x00140000 +#define PCI_CAP_EA_BASE_HI2 0x00020000ULL +#define PCI_CAP_EA_BASE_HI4 0x00040000ULL +#define PCI_CAP_EA_SIZE_LO 0x0000ffff +#define PCI_CAP_EA_SIZE_HI 0x00000010ULL +#define PCI_EA_BAR2_MAGIC 0x72727272 +#define PCI_EA_BAR4_MAGIC 0x74747474 +/* System controller driver data */ enum {SYSCON0 =32 ,
drivers/misc/swap_case.c +101 -1
136 lines not on this page · raw message
test/dm/pci.c +50 -0
53 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v2 3/4 test: dm: Add a test for PCI Enhanced Allocation
Hi Alex,
Quoted 9 lines · Alex Marginean
This test is built on top of the existing
swap_casedriver. It adds EA capability structure support toswap_caseand uses that to map BARs. BAR1 works as it used to, swapping upper/lower case. BARs 2,4 map to a couple of magic values.Signed-off-by Alex Marginean <[email protected]>---
Quoted 9 lines
Changes in v2:
- new patch, v1 didn't have a testarch/sandbox/dts/test.dts | 8 +++ arch/sandbox/include/asm/test.h | 13 ++++ drivers/misc/swap_case.c | 102 +++++++++++++++++++++++++++++++- test/dm/pci.c | 50 ++++++++++++++++ 4 files changed, 172 insertions(+), 1 deletion(-)
Well done!
But please see some nits below:
Quoted 55 lines
arch/sandbox/dts/test.dts +8
-0@@ -434,6 +434,14 @@ compatible = "sandbox,swap-case"; }; }; + pci at 1,0 { + compatible = "pci-generic"; + reg = <0x0800 0 0 0 0>; + emul at 0,0 { + compatible = "sandbox,swap-case"; + use-ea; + }; + }; pci at 1f,0 { compatible = "pci-generic"; reg = <0xf800 0 0 0 0>;arch/sandbox/include/asm/test.h +13
-0@@ -19,6 +19,7 @@#define PCI_CAP_ID_PM_OFFSET 0x50#define PCI_CAP_ID_EXP_OFFSET 0x60#define PCI_CAP_ID_MSIX_OFFSET 0x70 +#define PCI_CAP_ID_EA_OFFSET 0x80#define PCI_EXT_CAP_ID_ERR_OFFSET 0x100#define PCI_EXT_CAP_ID_VC_OFFSET 0x200@@ -30,6 +31,18 @@#define SANDBOX_CLK_RATE 32768 +/* Macros used to test PCI EA capability structure */ +#define PCI_CAP_EA_BASE_LO0 0x00100000 +#define PCI_CAP_EA_BASE_LO1 0x00110000 +#define PCI_CAP_EA_BASE_LO2 0x00120000 +#define PCI_CAP_EA_BASE_LO4 0x00140000 +#define PCI_CAP_EA_BASE_HI2 0x00020000ULL +#define PCI_CAP_EA_BASE_HI4 0x00040000ULL +#define PCI_CAP_EA_SIZE_LO 0x0000ffff +#define PCI_CAP_EA_SIZE_HI 0x00000010ULL +#define PCI_EA_BAR2_MAGIC 0x72727272 +#define PCI_EA_BAR4_MAGIC 0x74747474 +/* System controller driver data */ enum {SYSCON0 =32 ,drivers/misc/swap_case.c +0
-0
drivers/misc/swap_case.c static int sandbox_swap_case_get_devfn(struct udevice *dev) · line 64
Quoted 4 lines
drivers/misc/swap_case.c +1
-0@@ -61,11 +61,63 @@ static int sandbox_swap_case_get_devfn(struct udevice *dev)return plat->devfn; } +static int sandbox_swap_use_ea (struct udevice *dev)
nits: for consistency, name it as "sandbox_swap_case_use_ea"
Quoted 13 lines
drivers/misc/swap_case.c +13
-0+{ +return !!ofnode_get_property (dev->node,"use-ea" ,NULL ); +} + +/* Please keep these macros in sync with ea_regs below */ +#define PCI_CAP_ID_EA_SIZE (sizeof(ea_regs) + 4) +#define PCI_CAP_ID_EA_ENTRY_CNT 4 +/* Hardcoded EA structure, excluding 1st DW. */ +static const u32 ea_regs[] = { +/* BEI=0, ES=2, BAR0 32b Base + 32b MaxOffset, I/O space */ + (2 <<8 ) |2 , +PCI_CAP_EA_BASE_LO0 , +0 ,
drivers/misc/swap_case.c static int sandbox_swap_case_get_devfn(struct udevice *dev) · line 87
Quoted 10 lines
drivers/misc/swap_case.c +10
-0+/* BEI=1, ES=2, BAR1 32b Base + 32b MaxOffset */ + (1 <<4 ) |2 , +PCI_CAP_EA_BASE_LO1 , +MEM_TEXT_SIZE -1 , +/* BEI=2, ES=3, BAR2 64b Base + 32b MaxOffset */ + (2 <<4 ) |3 , +PCI_CAP_EA_BASE_LO2 |PCI_EA_IS_64 , +PCI_CAP_EA_SIZE_LO , + PCI_CAP_EA_BASE_HI2, +/* BEI=4, ES=4, BAR4 63b Base + 64b MaxOffset */
nits: typo of '63b'
Quoted 17 lines
drivers/misc/swap_case.c +17
-0+ (4 <<4 ) |4 , +PCI_CAP_EA_BASE_LO4 |PCI_EA_IS_64 , +PCI_CAP_EA_SIZE_LO |PCI_EA_IS_64 , +PCI_CAP_EA_BASE_HI4 , + PCI_CAP_EA_SIZE_HI, +}; + +static int sandbox_swap_case_read_ea (struct udevice *emul,uint offset, +ulong *valuep,enum pci_size_t size) +{ +u32 reg; + + offset = offset -PCI_CAP_ID_EA_OFFSET -4 ; + reg = ea_regs[offset >>2 ]; + reg >>= (offset %4 ) *8 ; + + *valuep = reg;
drivers/misc/swap_case.c static int sandbox_swap_case_get_devfn(struct udevice *dev) · line 114
Quoted 10 lines
drivers/misc/swap_case.c +5
-0+return 0 ; +} +static int sandbox_swap_case_read_config (struct udevice *emul,uint offset,ulong *valuep,enum pci_size_t size) {struct swap_case_platdata *plat =dev_get_platdata (emul); +/* +* The content of the EA capability structure is handled elseware to
nits: elsewhere
Quoted 132 lines
drivers/misc/swap_case.c +55
-1+* keep the switch/case below sane +*/ +if (offset >PCI_CAP_ID_EA_OFFSET +PCI_CAP_LIST_NEXT && + offset <PCI_CAP_ID_EA_OFFSET +PCI_CAP_ID_EA_SIZE ) +return sandbox_swap_case_read_ea (emul, offset, valuep, size); +switch (offset) {case PCI_COMMAND : *valuep = plat->command;@@ -134,9 +186,21 @@ static int sandbox_swap_case_read_config(struct udevice *emul, uint offset, *valuep =PCI_CAP_ID_MSIX_OFFSET ;break ;case PCI_CAP_ID_MSIX_OFFSET : - *valuep =PCI_CAP_ID_MSIX ; +if (sandbox_swap_use_ea (emul)) + *valuep = (PCI_CAP_ID_EA_OFFSET <<8 ) |PCI_CAP_ID_MSIX ; +else + *valuep =PCI_CAP_ID_MSIX ;break ;case PCI_CAP_ID_MSIX_OFFSET +PCI_CAP_LIST_NEXT : +if (sandbox_swap_use_ea (emul)) + *valuep =PCI_CAP_ID_EA_OFFSET ; +else + *valuep =0 ; +break ; +case PCI_CAP_ID_EA_OFFSET : + *valuep = (PCI_CAP_ID_EA_ENTRY_CNT <<16 ) |PCI_CAP_ID_EA ; +break ; +case PCI_CAP_ID_EA_OFFSET +PCI_CAP_LIST_NEXT : *valuep =0 ;break ;case PCI_EXT_CAP_ID_ERR_OFFSET :@@ -257,6 +321,9 @@ int sandbox_swap_case_write_io(struct udevice *dev, unsigned int addr,return 0 ; } +static int pci_ea_bar2_magic =PCI_EA_BAR2_MAGIC ; +static int pci_ea_bar4_magic =PCI_EA_BAR4_MAGIC ; +static int sandbox_swap_case_map_physmem (struct udevice *dev,phys_addr_t addr,unsigned long *lenp,void **ptrp) {@@ -265,9 +332,42 @@ static int sandbox_swap_case_map_physmem(struct udevice *dev,int barnum;int ret; +if (sandbox_swap_use_ea (dev)) { +/* +* only support mapping base address in EA test for now, we +* don't handle mapping an offset inside a BAR. Seems good +* enough for the current test. +*/ +switch (addr) { +case (phys_addr_t )PCI_CAP_EA_BASE_LO0 : + *ptrp = &priv->op; + *lenp =4 ; +break ; +case (phys_addr_t )PCI_CAP_EA_BASE_LO1 : + *ptrp = priv->mem_text; + *lenp = barinfo[1 ].size -1 ; +break ; +case (phys_addr_t)((PCI_CAP_EA_BASE_HI2 <<32 ) | +PCI_CAP_EA_BASE_LO2 ): + *ptrp = &pci_ea_bar2_magic; + *lenp =PCI_CAP_EA_SIZE_LO ; +break ; +case (phys_addr_t)((PCI_CAP_EA_BASE_HI4 <<32 ) | +PCI_CAP_EA_BASE_LO4 ): + *ptrp = &pci_ea_bar4_magic; + *lenp = (PCI_CAP_EA_SIZE_HI <<32 ) | +PCI_CAP_EA_SIZE_LO ; +break ; +default : +return -ENOENT ; + } +return 0 ; + } + ret =sandbox_swap_case_find_bar (dev, addr, &barnum, &offset);if (ret)return ret; +if (barnum ==1 ) { *ptrp = priv->mem_text + offset; avail = barinfo[1 ].size - offset;test/dm/pci.c +39
-0@@ -245,3 +245,53 @@ static int dm_test_pci_cap(struct unit_test_state *uts)return 0 ; }DM_TEST (dm_test_pci_cap,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT ); + +/* Test looking up BARs in EA capability structure */ +static int dm_test_pci_ea (struct unit_test_state *uts) +{ +struct udevice *bus, *swap; +void *bar; +int cap; + +/* +* use emulated device mapping function, we're not using real physical +* addresses in this test +*/ +sandbox_set_enable_pci_map (true); + +ut_assertok (uclass_get_device_by_seq (UCLASS_PCI ,0 , &bus)); +ut_assertok (dm_pci_bus_find_bdf (PCI_BDF (0 ,0x01 ,0 ), &swap)); + +/* look up PCI_CAP_ID_EA */ + cap =dm_pci_find_capability (swap,PCI_CAP_ID_EA ); +ut_asserteq (PCI_CAP_ID_EA_OFFSET , cap); + +/* test swap case in BAR 1 */ + bar =dm_pci_map_bar (swap,PCI_BASE_ADDRESS_0 ,0 ); +ut_assertnonnull (bar); + *(int *)bar =2 ;/* swap upper/lower */ + + bar =dm_pci_map_bar (swap,PCI_BASE_ADDRESS_1 ,0 ); +ut_assertnonnull (bar); +strcpy (bar,"ea TEST" ); +unmap_sysmem (bar); + bar =dm_pci_map_bar (swap,PCI_BASE_ADDRESS_1 ,0 ); +ut_assertnonnull (bar); +ut_asserteq_str ("EA test" , bar); + +/* test magic values in BARs2, 4; BAR 3 is n/a */ + bar =dm_pci_map_bar (swap,PCI_BASE_ADDRESS_2 ,0 ); +ut_assertnonnull (bar); +ut_asserteq (PCI_EA_BAR2_MAGIC , *(u32 *)bar); +
test/dm/pci.c static int dm_test_pci_cap(struct unit_test_state *uts) · line 296
Quoted 10 lines
test/dm/pci.c +10
-0+ bar =dm_pci_map_bar (swap,PCI_BASE_ADDRESS_3 ,0 ); +ut_assertnull (bar); + + bar =dm_pci_map_bar (swap,PCI_BASE_ADDRESS_4 ,0 ); +ut_assertnonnull (bar); +ut_asserteq (PCI_EA_BAR4_MAGIC , *(u32 *)bar); + +return 0 ; +} +
nits: remove this blank line
test/dm/pci.c static int dm_test_pci_cap(struct unit_test_state *uts)
Quoted 2 lines
test/dm/pci.c +1
-1+DM_TEST (dm_test_pci_ea,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT ); --
Regards,
Bin
PATCH v2 3/4 test: dm: Add a test for PCI Enhanced Allocation
Hi Bin,
Quoted 22 lines · Bin Meng
Hi Alex,
Quoted 9 lines · Alex Marginean
This test is built on top of the existing
swap_casedriver. It adds EA capability structure support toswap_caseand uses that to map BARs. BAR1 works as it used to, swapping upper/lower case. BARs 2,4 map to a couple of magic values.Signed-off-by Alex Marginean <[email protected]>---
Quoted 9 lines
Changes in v2:
- new patch, v1 didn't have a testarch/sandbox/dts/test.dts | 8 +++ arch/sandbox/include/asm/test.h | 13 ++++ drivers/misc/swap_case.c | 102 +++++++++++++++++++++++++++++++- test/dm/pci.c | 50 ++++++++++++++++ 4 files changed, 172 insertions(+), 1 deletion(-)
Quoted 6 lines
Well done!
Reviewed-by Bin Meng <[email protected]>Tested-by Bin Meng <[email protected]>But please see some nits below:
I'm replying from the nxp account, apparently google decided this is just spam and it's not worth sending out through gmail.
I'll send a v3 with fixes for you comments, should I keep either of your two tags on this patch?
Thank you!
Alex
Quoted 270 lines
Quoted 56 lines
arch/sandbox/dts/test.dts +8
-0@@ -434,6 +434,14 @@ compatible = "sandbox,swap-case"; }; }; + pci at 1,0 { + compatible = "pci-generic"; + reg = <0x0800 0 0 0 0>; + emul at 0,0 { + compatible = "sandbox,swap-case"; + use-ea; + }; + }; pci at 1f,0 { compatible = "pci-generic"; reg = <0xf800 0 0 0 0>;arch/sandbox/include/asm/test.h +13
-0@@ -19,6 +19,7 @@#define PCI_CAP_ID_PM_OFFSET 0x50#define PCI_CAP_ID_EXP_OFFSET 0x60#define PCI_CAP_ID_MSIX_OFFSET 0x70 +#define PCI_CAP_ID_EA_OFFSET 0x80#define PCI_EXT_CAP_ID_ERR_OFFSET 0x100#define PCI_EXT_CAP_ID_VC_OFFSET 0x200@@ -30,6 +31,18 @@#define SANDBOX_CLK_RATE 32768 +/* Macros used to test PCI EA capability structure */ +#define PCI_CAP_EA_BASE_LO0 0x00100000 +#define PCI_CAP_EA_BASE_LO1 0x00110000 +#define PCI_CAP_EA_BASE_LO2 0x00120000 +#define PCI_CAP_EA_BASE_LO4 0x00140000 +#define PCI_CAP_EA_BASE_HI2 0x00020000ULL +#define PCI_CAP_EA_BASE_HI4 0x00040000ULL +#define PCI_CAP_EA_SIZE_LO 0x0000ffff +#define PCI_CAP_EA_SIZE_HI 0x00000010ULL +#define PCI_EA_BAR2_MAGIC 0x72727272 +#define PCI_EA_BAR4_MAGIC 0x74747474 +/* System controller driver data */ enum {SYSCON0 =32 ,drivers/misc/swap_case.c +0
-0drivers/misc/swap_case.c static int sandbox_swap_case_get_devfn(struct udevice *dev) · line 64
Quoted 4 lines
drivers/misc/swap_case.c +1
-0@@ -61,11 +61,63 @@ static int sandbox_swap_case_get_devfn(struct udevice *dev)return plat->devfn; } +static int sandbox_swap_use_ea (struct udevice *dev)nits: for consistency, name it as "
sandbox_swap_case_use_ea"Quoted 13 lines
drivers/misc/swap_case.c +13
-0+{ +return !!ofnode_get_property (dev->node,"use-ea" ,NULL ); +} + +/* Please keep these macros in sync with ea_regs below */ +#define PCI_CAP_ID_EA_SIZE (sizeof(ea_regs) + 4) +#define PCI_CAP_ID_EA_ENTRY_CNT 4 +/* Hardcoded EA structure, excluding 1st DW. */ +static const u32 ea_regs[] = { +/* BEI=0, ES=2, BAR0 32b Base + 32b MaxOffset, I/O space */ + (2 <<8 ) |2 , +PCI_CAP_EA_BASE_LO0 , +0 ,drivers/misc/swap_case.c static int sandbox_swap_case_get_devfn(struct udevice *dev) · line 87
Quoted 10 lines
drivers/misc/swap_case.c +10
-0+/* BEI=1, ES=2, BAR1 32b Base + 32b MaxOffset */ + (1 <<4 ) |2 , +PCI_CAP_EA_BASE_LO1 , +MEM_TEXT_SIZE -1 , +/* BEI=2, ES=3, BAR2 64b Base + 32b MaxOffset */ + (2 <<4 ) |3 , +PCI_CAP_EA_BASE_LO2 |PCI_EA_IS_64 , +PCI_CAP_EA_SIZE_LO , + PCI_CAP_EA_BASE_HI2, +/* BEI=4, ES=4, BAR4 63b Base + 64b MaxOffset */ nits: typo of '63b'
Quoted 17 lines
drivers/misc/swap_case.c +17
-0+ (4 <<4 ) |4 , +PCI_CAP_EA_BASE_LO4 |PCI_EA_IS_64 , +PCI_CAP_EA_SIZE_LO |PCI_EA_IS_64 , +PCI_CAP_EA_BASE_HI4 , + PCI_CAP_EA_SIZE_HI, +}; + +static int sandbox_swap_case_read_ea (struct udevice *emul,uint offset, +ulong *valuep,enum pci_size_t size) +{ +u32 reg; + + offset = offset -PCI_CAP_ID_EA_OFFSET -4 ; + reg = ea_regs[offset >>2 ]; + reg >>= (offset %4 ) *8 ; + + *valuep = reg;drivers/misc/swap_case.c static int sandbox_swap_case_get_devfn(struct udevice *dev) · line 114
Quoted 10 lines
drivers/misc/swap_case.c +5
-0+return 0 ; +} +static int sandbox_swap_case_read_config (struct udevice *emul,uint offset,ulong *valuep,enum pci_size_t size) {struct swap_case_platdata *plat =dev_get_platdata (emul); +/* +* The content of the EA capability structure is handled elseware to nits: elsewhere
Quoted 132 lines
drivers/misc/swap_case.c +55
-1+* keep the switch/case below sane +*/ +if (offset >PCI_CAP_ID_EA_OFFSET +PCI_CAP_LIST_NEXT && + offset <PCI_CAP_ID_EA_OFFSET +PCI_CAP_ID_EA_SIZE ) +return sandbox_swap_case_read_ea (emul, offset, valuep, size); +switch (offset) {case PCI_COMMAND : *valuep = plat->command;@@ -134,9 +186,21 @@ static int sandbox_swap_case_read_config(struct udevice *emul, uint offset, *valuep =PCI_CAP_ID_MSIX_OFFSET ;break ;case PCI_CAP_ID_MSIX_OFFSET : - *valuep =PCI_CAP_ID_MSIX ; +if (sandbox_swap_use_ea (emul)) + *valuep = (PCI_CAP_ID_EA_OFFSET <<8 ) |PCI_CAP_ID_MSIX ; +else + *valuep =PCI_CAP_ID_MSIX ;break ;case PCI_CAP_ID_MSIX_OFFSET +PCI_CAP_LIST_NEXT : +if (sandbox_swap_use_ea (emul)) + *valuep =PCI_CAP_ID_EA_OFFSET ; +else + *valuep =0 ; +break ; +case PCI_CAP_ID_EA_OFFSET : + *valuep = (PCI_CAP_ID_EA_ENTRY_CNT <<16 ) |PCI_CAP_ID_EA ; +break ; +case PCI_CAP_ID_EA_OFFSET +PCI_CAP_LIST_NEXT : *valuep =0 ;break ;case PCI_EXT_CAP_ID_ERR_OFFSET :@@ -257,6 +321,9 @@ int sandbox_swap_case_write_io(struct udevice *dev, unsigned int addr,return 0 ; } +static int pci_ea_bar2_magic =PCI_EA_BAR2_MAGIC ; +static int pci_ea_bar4_magic =PCI_EA_BAR4_MAGIC ; +static int sandbox_swap_case_map_physmem (struct udevice *dev,phys_addr_t addr,unsigned long *lenp,void **ptrp) {@@ -265,9 +332,42 @@ static int sandbox_swap_case_map_physmem(struct udevice *dev,int barnum;int ret; +if (sandbox_swap_use_ea (dev)) { +/* +* only support mapping base address in EA test for now, we +* don't handle mapping an offset inside a BAR. Seems good +* enough for the current test. +*/ +switch (addr) { +case (phys_addr_t )PCI_CAP_EA_BASE_LO0 : + *ptrp = &priv->op; + *lenp =4 ; +break ; +case (phys_addr_t )PCI_CAP_EA_BASE_LO1 : + *ptrp = priv->mem_text; + *lenp = barinfo[1 ].size -1 ; +break ; +case (phys_addr_t)((PCI_CAP_EA_BASE_HI2 <<32 ) | +PCI_CAP_EA_BASE_LO2 ): + *ptrp = &pci_ea_bar2_magic; + *lenp =PCI_CAP_EA_SIZE_LO ; +break ; +case (phys_addr_t)((PCI_CAP_EA_BASE_HI4 <<32 ) | +PCI_CAP_EA_BASE_LO4 ): + *ptrp = &pci_ea_bar4_magic; + *lenp = (PCI_CAP_EA_SIZE_HI <<32 ) | +PCI_CAP_EA_SIZE_LO ; +break ; +default : +return -ENOENT ; + } +return 0 ; + } + ret =sandbox_swap_case_find_bar (dev, addr, &barnum, &offset);if (ret)return ret; +if (barnum ==1 ) { *ptrp = priv->mem_text + offset; avail = barinfo[1 ].size - offset;test/dm/pci.c +39
-0@@ -245,3 +245,53 @@ static int dm_test_pci_cap(struct unit_test_state *uts)return 0 ; }DM_TEST (dm_test_pci_cap,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT ); + +/* Test looking up BARs in EA capability structure */ +static int dm_test_pci_ea (struct unit_test_state *uts) +{ +struct udevice *bus, *swap; +void *bar; +int cap; + +/* +* use emulated device mapping function, we're not using real physical +* addresses in this test +*/ +sandbox_set_enable_pci_map (true); + +ut_assertok (uclass_get_device_by_seq (UCLASS_PCI ,0 , &bus)); +ut_assertok (dm_pci_bus_find_bdf (PCI_BDF (0 ,0x01 ,0 ), &swap)); + +/* look up PCI_CAP_ID_EA */ + cap =dm_pci_find_capability (swap,PCI_CAP_ID_EA ); +ut_asserteq (PCI_CAP_ID_EA_OFFSET , cap); + +/* test swap case in BAR 1 */ + bar =dm_pci_map_bar (swap,PCI_BASE_ADDRESS_0 ,0 ); +ut_assertnonnull (bar); + *(int *)bar =2 ;/* swap upper/lower */ + + bar =dm_pci_map_bar (swap,PCI_BASE_ADDRESS_1 ,0 ); +ut_assertnonnull (bar); +strcpy (bar,"ea TEST" ); +unmap_sysmem (bar); + bar =dm_pci_map_bar (swap,PCI_BASE_ADDRESS_1 ,0 ); +ut_assertnonnull (bar); +ut_asserteq_str ("EA test" , bar); + +/* test magic values in BARs2, 4; BAR 3 is n/a */ + bar =dm_pci_map_bar (swap,PCI_BASE_ADDRESS_2 ,0 ); +ut_assertnonnull (bar); +ut_asserteq (PCI_EA_BAR2_MAGIC , *(u32 *)bar); +test/dm/pci.c static int dm_test_pci_cap(struct unit_test_state *uts) · line 296
Quoted 10 lines
test/dm/pci.c +10
-0+ bar =dm_pci_map_bar (swap,PCI_BASE_ADDRESS_3 ,0 ); +ut_assertnull (bar); + + bar =dm_pci_map_bar (swap,PCI_BASE_ADDRESS_4 ,0 ); +ut_assertnonnull (bar); +ut_asserteq (PCI_EA_BAR4_MAGIC , *(u32 *)bar); + +return 0 ; +} +nits: remove this blank line
test/dm/pci.c static int dm_test_pci_cap(struct unit_test_state *uts)
Quoted 2 lines
test/dm/pci.c +1
-1+DM_TEST (dm_test_pci_ea,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT ); --Regards,
Bin
PATCH v2 3/4 test: dm: Add a test for PCI Enhanced Allocation
Hi Alex,
Quoted 31 lines · Alexandru Marginean
Hi Bin,
Quoted 27 lines · Bin Meng
Hi Alex,
Quoted 9 lines · Alex Marginean
This test is built on top of the existing
swap_casedriver. It adds EA capability structure support toswap_caseand uses that to map BARs. BAR1 works as it used to, swapping upper/lower case. BARs 2,4 map to a couple of magic values.Signed-off-by Alex Marginean <[email protected]>---
Quoted 9 lines
Changes in v2:
- new patch, v1 didn't have a testarch/sandbox/dts/test.dts | 8 +++ arch/sandbox/include/asm/test.h | 13 ++++ drivers/misc/swap_case.c | 102 +++++++++++++++++++++++++++++++- test/dm/pci.c | 50 ++++++++++++++++ 4 files changed, 172 insertions(+), 1 deletion(-)Well done!
Reviewed-by Bin Meng <[email protected]>Tested-by Bin Meng <[email protected]>
Quoted 7 lines
Quoted 1 line
But please see some nits below:
I'm replying from the nxp account, apparently google decided this is just spam and it's not worth sending out through gmail.
I'll send a v3 with fixes for you comments, should I keep either of your two tags on this patch?
Yes, please keep the two tags in the v3. thanks!
Regards,
Bin
PATCH v3 1/4 pci: fixed dm_pci_map_bar comment
The comment now indicates that the input argument bar is a register offset, not a BAR index.
It also mentions which BARs are supported for type 0/1 and that the function can return 0 on error.
---
Changes in v2:
- new patch
Changes in v3:
- none
include/pci.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
include/pci.h +5 -3
@@ -1309,12 +1309,14 @@ pci_addr_t dm_pci_phys_to_bus(struct udevice *dev, phys_addr_t addr,* dm_pci_map_bar() - get a virtual address associated with a BAR region * * Looks up a base address register and finds the physical memory address -* that corresponds to it +* that corresponds to it. +* Can be used for 32b BARs 0-5 on type 0 functions and for 32b BARs 0-1 on +* type 1 functions. * * @dev: Device to check -* @bar: Bar number to read (numbered from 0) +* @bar: Bar register offset (PCI_BASE_ADDRESS_...) * @flags: Flags for the region type (PCI_REGION_...) -* @return: pointer to the virtual address to use +* @return: pointer to the virtual address to use or 0 on error */ void *dm_pci_map_bar (struct udevice *dev,int bar,int flags);
Signature · 1 line
2.17.1
PATCH v3 2/4 drivers: pci: add map_bar support for Enhanced Allocation
Makes dm_pci_map_bar API available for integrated PCI devices that support Enhanced Allocation instead of the original PCI BAR mechanism.
---
Changes in v2:
- fixed parsing for BAR1+
- fixed an issue with EA entry size
- don't look up EA capability structure twice
- use phys_addr_t for EA addresses
- use kernel MACROS for EA registers
Changes in v3:
- none
drivers/pci/pci-uclass.c | 46 ++++++++++++++++++++++++++++++++++++++++ include/pci.h | 13 ++++++++++++ 2 files changed, 59 insertions(+)
drivers/pci/pci-uclass.c +46 -0
@@ -1341,10 +1341,56 @@ pci_addr_t dm_pci_phys_to_bus(struct udevice *dev, phys_addr_t phys_addr,return bus_addr; } +static void *dm_pci_map_ea_bar (struct udevice *dev,int bar,int flags, +int ea_off) +{ +int ea_cnt, i, entry_size; +int bar_id = (bar -PCI_BASE_ADDRESS_0 ) >>2 ; +u32 ea_entry; +phys_addr_t addr; + +/* EA capability structure header */ +dm_pci_read_config32 (dev, ea_off, &ea_entry); + ea_cnt = (ea_entry >>16 ) &PCI_EA_NUM_ENT_MASK ; + ea_off +=PCI_EA_FIRST_ENT ; + +for (i =0 ; i < ea_cnt; i++, ea_off += entry_size) { +/* Entry header */ +dm_pci_read_config32 (dev, ea_off, &ea_entry); + entry_size = ((ea_entry &PCI_EA_ES ) +1 ) <<2 ; + +if (((ea_entry &PCI_EA_BEI ) >>4 ) != bar_id) +continue ; + +/* Base address, 1st DW */ +dm_pci_read_config32 (dev, ea_off +4 , &ea_entry); + addr = ea_entry &PCI_EA_FIELD_MASK ; +if (ea_entry &PCI_EA_IS_64 ) { +/* Base address, 2nd DW, skip over 4B MaxOffset */ +dm_pci_read_config32 (dev, ea_off +12 , &ea_entry); + addr |= ((u64 )ea_entry) <<32 ; + } + +/* size ignored for now */ +return map_physmem (addr, flags,0 ); + } + +return 0 ; +} +void *dm_pci_map_bar (struct udevice *dev,int bar,int flags) {pci_addr_t pci_bus_addr;u32 bar_response; +int ea_off; + +/* +* if the function supports Enhanced Allocation use that instead of +* BARs +*/ + ea_off =dm_pci_find_capability (dev,PCI_CAP_ID_EA ); +if (ea_off) +return dm_pci_map_ea_bar (dev, bar, flags, ea_off);/* read BAR address */ dm_pci_read_config32 (dev, bar, &bar_response);
include/pci.h +13 -0
@@ -455,6 +455,17 @@#define PCI_EXT_CAP_ID_PTM 0x1F/* Precision Time Measurement */ #define PCI_EXT_CAP_ID_MAX PCI_EXT_CAP_ID_PTM +/* Enhanced Allocation Registers */ +#define PCI_EA_NUM_ENT 2/* Number of Capability Entries */ +#define PCI_EA_NUM_ENT_MASK 0x3f/* Num Entries Mask */ +#define PCI_EA_FIRST_ENT 4/* First EA Entry in List */ +#define PCI_EA_ES 0x00000007/* Entry Size */ +#define PCI_EA_BEI 0x000000f0/* BAR Equivalent Indicator */ +/* Base, MaxOffset registers */ +/* bit 0 is reserved */ +#define PCI_EA_IS_64 0x00000002/* 64-bit field flag */ +#define PCI_EA_FIELD_MASK 0xfffffffc/* For Base & Max Offset */ +/* Include the ID list */ #include <pci_ids.h>
@@ -1312,6 +1323,8 @@ pci_addr_t dm_pci_phys_to_bus(struct udevice *dev, phys_addr_t addr,* that corresponds to it. * Can be used for 32b BARs 0-5 on type 0 functions and for 32b BARs 0-1 on * type 1 functions. +* Can also be used on type 0 functions that support Enhanced Allocation for +* 32b/64b BARs. Note that duplicate BEI entries are not supported. * * @dev: Device to check * @bar: Bar register offset (PCI_BASE_ADDRESS_...)
Signature · 1 line
2.17.1
PATCH v3 2/4 drivers: pci: add map_bar support for Enhanced Allocation
Quoted 17 lines · Alex Marginean
Makes
dm_pci_map_barAPI available for integrated PCI devices that support Enhanced Allocation instead of the original PCI BAR mechanism.Signed-off-by Alex Marginean <[email protected]>Reviewed-by Bin Meng <[email protected]>---
Changes in v2:
- fixed parsing for BAR1+
- fixed an issue with EA entry size
- don't look up EA capability structure twice
- usephys_addr_tfor EA addresses
- use kernel MACROS for EA registers
Changes in v3:
- none
Quoted 3 lines
drivers/pci/pci-uclass.c | 46 ++++++++++++++++++++++++++++++++++++++++ include/pci.h | 13 ++++++++++++ 2 files changed, 59 insertions(+)
Applied to u-boot-dm/next, thanks!
PATCH v3 3/4 test: dm: Add a test for PCI Enhanced Allocation
In reply to Alex MargineanThis test is built on top of the existing swap_case driver. It adds EA capability structure support to swap_case and uses that to map BARs. BAR1 works as it used to, swapping upper/lower case. BARs 2,4 map to a couple of magic values.
---
Changes in v2:
- new patch, v1 didn't have a test
Changes in v3:
- renamed sandbox_swap_use_ea function for consistency
- fixed several typos and styling issues
arch/sandbox/dts/test.dts | 8 +++ arch/sandbox/include/asm/test.h | 13 ++++ drivers/misc/swap_case.c | 102 +++++++++++++++++++++++++++++++- test/dm/pci.c | 49 +++++++++++++++ 4 files changed, 171 insertions(+), 1 deletion(-)
arch/sandbox/dts/test.dts +8 -0
@@ -434,6 +434,14 @@ compatible = "sandbox,swap-case"; }; }; + pci at 1,0 { + compatible = "pci-generic"; + reg = <0x0800 0 0 0 0>; + emul at 0,0 { + compatible = "sandbox,swap-case"; + use-ea; + }; + }; pci at 1f,0 { compatible = "pci-generic"; reg = <0xf800 0 0 0 0>;
arch/sandbox/include/asm/test.h +13 -0
@@ -19,6 +19,7 @@#define PCI_CAP_ID_PM_OFFSET 0x50#define PCI_CAP_ID_EXP_OFFSET 0x60#define PCI_CAP_ID_MSIX_OFFSET 0x70 +#define PCI_CAP_ID_EA_OFFSET 0x80#define PCI_EXT_CAP_ID_ERR_OFFSET 0x100#define PCI_EXT_CAP_ID_VC_OFFSET 0x200
@@ -30,6 +31,18 @@#define SANDBOX_CLK_RATE 32768 +/* Macros used to test PCI EA capability structure */ +#define PCI_CAP_EA_BASE_LO0 0x00100000 +#define PCI_CAP_EA_BASE_LO1 0x00110000 +#define PCI_CAP_EA_BASE_LO2 0x00120000 +#define PCI_CAP_EA_BASE_LO4 0x00140000 +#define PCI_CAP_EA_BASE_HI2 0x00020000ULL +#define PCI_CAP_EA_BASE_HI4 0x00040000ULL +#define PCI_CAP_EA_SIZE_LO 0x0000ffff +#define PCI_CAP_EA_SIZE_HI 0x00000010ULL +#define PCI_EA_BAR2_MAGIC 0x72727272 +#define PCI_EA_BAR4_MAGIC 0x74747474 +/* System controller driver data */ enum {SYSCON0 =32 ,
drivers/misc/swap_case.c +101 -1
136 lines not on this page · raw message
test/dm/pci.c +49 -0
52 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v3 3/4 test: dm: Add a test for PCI Enhanced Allocation
Quoted 17 lines · Alex Marginean
This test is built on top of the existing
swap_casedriver. It adds EA capability structure support toswap_caseand uses that to map BARs. BAR1 works as it used to, swapping upper/lower case. BARs 2,4 map to a couple of magic values.Signed-off-by Alex Marginean <[email protected]>Reviewed-by Bin Meng <[email protected]>Tested-by Bin Meng <[email protected]>---
Changes in v2:
- new patch, v1 didn't have a test
Changes in v3:
- renamedsandbox_swap_use_eafunction for consistency
- fixed several typos and styling issues
Quoted 5 lines
arch/sandbox/dts/test.dts | 8 +++ arch/sandbox/include/asm/test.h | 13 ++++ drivers/misc/swap_case.c | 102 +++++++++++++++++++++++++++++++- test/dm/pci.c | 49 +++++++++++++++ 4 files changed, 171 insertions(+), 1 deletion(-)
Applied to u-boot-dm/next, thanks!
PATCH v3 4/4 drivers: pci: add API to issue FLR on a PCI function if supported
In reply to Alex MargineanAdds dm_pci_flr API that issues a Function Level reset on a PCI-e function, if FLR is supported.
---
Changes in v2:
- Use kernel PCI_EXP macros for register offsets
Changes in v3:
- none
drivers/pci/pci-uclass.c | 24 ++++++++++++++++++++++++ include/pci.h | 14 ++++++++++++++ 2 files changed, 38 insertions(+)
drivers/pci/pci-uclass.c +24 -0
@@ -1494,6 +1494,30 @@ int dm_pci_find_ext_capability(struct udevice *dev, int cap)return dm_pci_find_next_ext_capability (dev,0 , cap); } +int dm_pci_flr (struct udevice *dev) +{ +int pcie_off; +u32 cap; + +/* look for PCI Express Capability */ + pcie_off =dm_pci_find_capability (dev,PCI_CAP_ID_EXP ); +if (!pcie_off) +return -ENOENT ; + +/* check FLR capability */ +dm_pci_read_config32 (dev, pcie_off +PCI_EXP_DEVCAP , &cap); +if (!(cap &PCI_EXP_DEVCAP_FLR )) +return -ENOENT ; + +dm_pci_clrset_config16 (dev, pcie_off +PCI_EXP_DEVCTL ,0 , +PCI_EXP_DEVCTL_BCR_FLR ); + +/* wait 100ms, per PCI spec */ +mdelay (100 ); + +return 0 ; +} +UCLASS_DRIVER (pci) = { .id =UCLASS_PCI , .name ="pci" ,
include/pci.h +14 -0
@@ -466,6 +466,12 @@#define PCI_EA_IS_64 0x00000002/* 64-bit field flag */ #define PCI_EA_FIELD_MASK 0xfffffffc/* For Base & Max Offset */ +/* PCI Express capabilities */ +#define PCI_EXP_DEVCAP 4/* Device capabilities */ +#define PCI_EXP_DEVCAP_FLR 0x10000000/* Function Level Reset */ +#define PCI_EXP_DEVCTL 8/* Device Control */ +#define PCI_EXP_DEVCTL_BCR_FLR 0x8000/* Bridge Configuration Retry / FLR */ +/* Include the ID list */ #include <pci_ids.h>
@@ -1426,6 +1432,14 @@ int dm_pci_find_next_ext_capability(struct udevice *dev, int start, int cap);*/ int dm_pci_find_ext_capability (struct udevice *dev,int cap); +/** +* dm_pci_flr() - Perform FLR if the device suppoorts it +* +* @dev: PCI device to reset +* @return: 0 if OK, -ENOENT if FLR is not supported by dev +*/ +int dm_pci_flr (struct udevice *dev); +#define dm_pci_virt_to_bus (dev, addr, flags) \ dm_pci_phys_to_bus(dev, (virt_to_phys(addr)), (flags))#define dm_pci_bus_to_virt (dev, addr, flags, len, map_flags) \
Signature · 1 line
2.17.1
PATCH v3 4/4 drivers: pci: add API to issue FLR on a PCI function if supported
Quoted 8 lines · Alex Marginean
Adds
dm_pci_flrAPI that issues a Function Level reset on a PCI-e function, if FLR is supported.Signed-off-by Alex Marginean <[email protected]>Reviewed-by Bin Meng <[email protected]>---
Quoted 8 lines
Changes in v2:
- Use kernelPCI_EXPmacros for register offsets
Changes in v3:
- nonedrivers/pci/pci-uclass.c | 24 ++++++++++++++++++++++++ include/pci.h | 14 ++++++++++++++ 2 files changed, 38 insertions(+)
Applied to u-boot-dm/next, thanks!
PATCH v2 4/4 drivers: pci: add API to issue FLR on a PCI function if supported
In reply to Alex MargineanAdds dm_pci_flr API that issues a Function Level reset on a PCI-e function, if FLR is supported.
---
Changes in v2:
- Use kernel PCI_EXP macros for register offsets
drivers/pci/pci-uclass.c | 24 ++++++++++++++++++++++++ include/pci.h | 14 ++++++++++++++ 2 files changed, 38 insertions(+)
drivers/pci/pci-uclass.c +24 -0
@@ -1494,6 +1494,30 @@ int dm_pci_find_ext_capability(struct udevice *dev, int cap)return dm_pci_find_next_ext_capability (dev,0 , cap); } +int dm_pci_flr (struct udevice *dev) +{ +int pcie_off; +u32 cap; + +/* look for PCI Express Capability */ + pcie_off =dm_pci_find_capability (dev,PCI_CAP_ID_EXP ); +if (!pcie_off) +return -ENOENT ; + +/* check FLR capability */ +dm_pci_read_config32 (dev, pcie_off +PCI_EXP_DEVCAP , &cap); +if (!(cap &PCI_EXP_DEVCAP_FLR )) +return -ENOENT ; + +dm_pci_clrset_config16 (dev, pcie_off +PCI_EXP_DEVCTL ,0 , +PCI_EXP_DEVCTL_BCR_FLR ); + +/* wait 100ms, per PCI spec */ +mdelay (100 ); + +return 0 ; +} +UCLASS_DRIVER (pci) = { .id =UCLASS_PCI , .name ="pci" ,
include/pci.h +14 -0
@@ -466,6 +466,12 @@#define PCI_EA_IS_64 0x00000002/* 64-bit field flag */ #define PCI_EA_FIELD_MASK 0xfffffffc/* For Base & Max Offset */ +/* PCI Express capabilities */ +#define PCI_EXP_DEVCAP 4/* Device capabilities */ +#define PCI_EXP_DEVCAP_FLR 0x10000000/* Function Level Reset */ +#define PCI_EXP_DEVCTL 8/* Device Control */ +#define PCI_EXP_DEVCTL_BCR_FLR 0x8000/* Bridge Configuration Retry / FLR */ +/* Include the ID list */ #include <pci_ids.h>
@@ -1426,6 +1432,14 @@ int dm_pci_find_next_ext_capability(struct udevice *dev, int start, int cap);*/ int dm_pci_find_ext_capability (struct udevice *dev,int cap); +/** +* dm_pci_flr() - Perform FLR if the device suppoorts it +* +* @dev: PCI device to reset +* @return: 0 if OK, -ENOENT if FLR is not supported by dev +*/ +int dm_pci_flr (struct udevice *dev); +#define dm_pci_virt_to_bus (dev, addr, flags) \ dm_pci_phys_to_bus(dev, (virt_to_phys(addr)), (flags))#define dm_pci_bus_to_virt (dev, addr, flags, len, map_flags) \
Signature · 1 line
2.17.1
PATCH v2 4/4 drivers: pci: add API to issue FLR on a PCI function if supported
Quoted 5 lines · Alex Marginean
Adds
dm_pci_flrAPI that issues a Function Level reset on a PCI-e function, if FLR is supported.Signed-off-by Alex Marginean <[email protected]>
Quoted 9 lines
---
Changes in v2:
- Use kernelPCI_EXPmacros for register offsetsdrivers/pci/pci-uclass.c | 24 ++++++++++++++++++++++++ include/pci.h | 14 ++++++++++++++ 2 files changed, 38 insertions(+)
PATCH v2 1/4 pci: fixed dm_pci_map_bar comment
In reply to Alex MargineanQuoted 6 lines · Alex Marginean
The comment now indicates that the input argument bar is a register offset, not a BAR index.
It also mentions which BARs are supported for type 0/1 and that the function can return 0 on error.
Quoted 9 lines
Signed-off-by Alex Marginean <[email protected]>---
Changes in v2:
- new patchinclude/pci.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
PATCH v2 1/4 pci: fixed dm_pci_map_bar comment
Quoted 11 lines · Bin Meng
Quoted 9 lines · Alex Marginean
The comment now indicates that the input argument bar is a register offset, not a BAR index.
It also mentions which BARs are supported for type 0/1 and that the function can return 0 on error.Signed-off-by Alex Marginean <[email protected]>---
Quoted 8 lines
Quoted 6 lines
Changes in v2:
- new patchinclude/pci.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)Reviewed-by Bin Meng <[email protected]>
Applied to u-boot-dm/next, thanks!