Add driver model support for PCI
Subsystems (15)
v2 cover Add driver model support for PCI
This series is a collection of changes in core DM, sandbox, x86 and PCI code to implement a PCI uclass and associated operations. Some basic tests are provided as well.
As is becoming common with DM conversions, the existing structure (here struct pci_controller) becomes per-bus uclass data. This allows the concept of a 'hose' (generally a PCI host controller and a bus) to continue to exist in the interim, even if it should not be needed in the end. This makes it much easier to convert over existing code.
PCI buses are not scanned in the bind() method but only later when probe() is called. This will be automatic if you access a bus, but it does mean that if PCI is not used it will not be touched, in keeping with U-Boot's lazy- init philosophy.
The existing 'pciauto' bus configuration code is still used, although it now uses DM underneath. It works exclusively by reading and writing PCI config and does not refer to DM data structures. The one change is to drop use of the hose->current_busno field which is no longer required. The fact that file works largely as before is an indication that a good level of compatibility is achieved between DM and legacy PCI.
In order to support testing of PCI I/O and memory space, support has been added to sandbox to allow mapping of these. This allows commands like 'md' and 'iod' to display data from mapped PCI devices. Similarly, it is possible to make changes to this space. This support relies on the existing map_sysmem() and unmap_sysmem() calls which are now fairly widespread in U-Boot.
Apart from the driver model tests (run with ./test/dm/test-dm.sh) you can try out these commands which use the new 'swap_case' test device:
../u-boot -d b/sandbox/u-boot.dtb
....
=> iow.b 20000000 2
=> iod.b 20000000
0000: 02
=> mw.l 10000000 64436241
=> md.l 10000000 1
10000000: 44634261 aBcD
=>
This shows an I/O access to 20000000, setting the value 2 which means to swap the case. Then 'AbCd' is written to the memory space at 10000000 and 'aBcD' is read back.
The 'pci' command can be used as before.
Most existing PCI functions (in pci.h) still work, but route through driver model. The file drivers/pci/pci.c is replaced when driver model is enabled so not everything is present. A new pci_common.c file holds functions common to driver model and the old system, and pci_compat.c contains functions I would like to eventually deprecate.
Two x86 boards (coreboot and chromebook_link) are converted over to use driver model for PCI.
Core driver model changes include:
- Addition of a new pre_probe() method for the uclass to set up devices just before the device's probe() method is called
- A change in the ordering of when a device is marked as probed
- A dev_get_uclass_priv() accessor
- A tweak to the 'dm uclass' command to improve sequence number display
Notably missing from this series are functions to access PCI devices using a 'struct udevice *'. Where there is no device tree entry for a bus device, a generic PCI device is created in driver model to mirror the device, as with I2C and SPI. Future work could add more real devices to x86 and create a demand for these sorts of functions. Also we might store things like the PCI base address registers (BARs) in data structures if there is a need. These things are probably best developed as a need arises to avoid creating infrastructure and overhead that may not be used.
This series is available at u-boot-dm.git branch pci-working.
Changes in v2:
- Update root node #size=cells to 1 in this patch
- Add a new patch with a CPU init function which can use driver model
- Use the new arch_cpu_init_dm() function instead of something x86-specific
- Add -ve sign before ENXIO
Simon Glass (22):
sandbox: Update device tree 'reg' properties for I2C and SPI
fdt: Export fdtdec_get_number() for general use
x86: Add a x86_ prefix to the x86-specific PCI functions
dm: Add a new CPU init function which can use driver model
x86: Split up arch_cpu_init()
Correct map_sysmem() logic in do_mem_mw()
fdt: Tighten up error handling in fdtdec_get_pci_addr()
dm: core: Add dev_get_uclass_priv() to access uclass private data
dm: core: Mark device as active before calling its probe() method
dm: core: Add a uclass pre_probe() method for devices
dm: Show both allocated and requested seq numbers in 'dm uclass'
dm: pci: Move common PCI functions into their own file
dm: pci: Add a uclass for PCI
dm: sandbox: pci: Add PCI support for sandbox
dm: sandbox: Add a simple PCI driver
dm: sandbox: pci: Add a PCI emulation uclass
dm: sandbox: Add a emulated PCI device as an example
dm: sandbox: pci: Enable PCI for sandbox
dm: x86: pci: Add a PCI driver for driver model
dm: x86: pci: Convert coreboot to use driver model for pci
dm: x86: pci: Convert chromebook_link to use driver model for pci
dm: pci: Add driver model tests for PCI
arch/sandbox/Kconfig | 7 + arch/sandbox/cpu/cpu.c | 37 +- arch/sandbox/dts/sandbox.dts | 26 +- arch/sandbox/include/asm/io.h | 16 +- arch/sandbox/include/asm/processor.h | 12 + arch/sandbox/include/asm/test.h | 7 +- arch/sandbox/include/asm/u-boot-sandbox.h | 48 ++ arch/sandbox/lib/Makefile | 2 +- arch/sandbox/lib/pci_io.c | 138 ++++++ arch/x86/cpu/baytrail/early_uart.c | 5 +- arch/x86/cpu/coreboot/pci.c | 63 +-- arch/x86/cpu/ivybridge/bd82x6x.c | 56 ++- arch/x86/cpu/ivybridge/cpu.c | 62 +-- arch/x86/cpu/ivybridge/early_init.c | 58 +-- arch/x86/cpu/ivybridge/early_me.c | 12 +- arch/x86/cpu/ivybridge/gma.c | 4 +- arch/x86/cpu/ivybridge/lpc.c | 75 +-- arch/x86/cpu/ivybridge/northbridge.c | 6 +- arch/x86/cpu/ivybridge/pch.c | 4 +- arch/x86/cpu/ivybridge/pci.c | 85 ++-- arch/x86/cpu/ivybridge/report_platform.c | 4 +- arch/x86/cpu/ivybridge/sata.c | 61 +-- arch/x86/cpu/ivybridge/sdram.c | 20 +- arch/x86/cpu/ivybridge/usb_ehci.c | 4 +- arch/x86/cpu/ivybridge/usb_xhci.c | 8 +- arch/x86/cpu/pci.c | 52 ++- arch/x86/cpu/quark/quark.c | 4 +- arch/x86/cpu/queensbay/tnc.c | 4 +- arch/x86/dts/chromebook_link.dts | 10 +- arch/x86/include/asm/arch-ivybridge/bd82x6x.h | 1 - arch/x86/include/asm/pci.h | 20 +- arch/x86/lib/Makefile | 2 + arch/x86/lib/bios_interrupts.c | 12 +- board/google/chromebook_link/link.c | 9 + common/board_f.c | 6 + common/board_r.c | 2 + common/cmd_mem.c | 7 +- common/cmd_pci.c | 14 +- common/cmd_sf.c | 2 +- common/cros_ec.c | 2 +- configs/chromebook_link_defconfig | 1 + configs/chromebox_panther_defconfig | 1 + configs/coreboot-x86_defconfig | 1 + configs/sandbox_defconfig | 3 + doc/driver-model/pci-info.txt | 70 +++ drivers/core/device.c | 19 +- drivers/core/uclass.c | 10 +- drivers/gpio/at91_gpio.c | 2 +- drivers/gpio/bcm2835_gpio.c | 2 +- drivers/gpio/gpio-uclass.c | 22 +- drivers/gpio/intel_ich6_gpio.c | 18 +- drivers/gpio/mxc_gpio.c | 2 +- drivers/gpio/omap_gpio.c | 2 +- drivers/gpio/s5p_gpio.c | 2 +- drivers/gpio/sandbox.c | 6 +- drivers/gpio/sunxi_gpio.c | 2 +- drivers/gpio/tegra_gpio.c | 2 +- drivers/i2c/i2c-uclass.c | 6 +- drivers/i2c/sandbox_i2c.c | 2 +- drivers/misc/Makefile | 1 + drivers/misc/cros_ec.c | 6 +- drivers/misc/cros_ec_i2c.c | 2 +- drivers/misc/cros_ec_sandbox.c | 2 +- drivers/misc/cros_ec_spi.c | 4 +- drivers/misc/swap_case.c | 285 ++++++++++++ drivers/mtd/spi/sf-uclass.c | 2 +- drivers/mtd/spi/sf_probe.c | 8 +- drivers/pci/Kconfig | 22 + drivers/pci/Makefile | 11 +- drivers/pci/pci-emul-uclass.c | 67 +++ drivers/pci/pci-uclass.c | 639 ++++++++++++++++++++++++++ drivers/pci/pci.c | 281 +---------- drivers/pci/pci_auto.c | 16 +- drivers/pci/pci_common.c | 292 ++++++++++++ drivers/pci/pci_compat.c | 43 ++ drivers/pci/pci_sandbox.c | 79 ++++ drivers/pci/pci_x86.c | 24 + drivers/serial/serial-uclass.c | 4 +- drivers/spi/spi-uclass.c | 4 +- include/common.h | 11 + include/configs/sandbox.h | 4 + include/dm/device.h | 10 + include/dm/test.h | 1 + include/dm/uclass-id.h | 4 + include/dm/uclass-internal.h | 7 +- include/dm/uclass.h | 2 + include/fdtdec.h | 15 +- include/i2c.h | 8 +- include/pci.h | 411 ++++++++++++++++- lib/fdtdec.c | 8 +- test/dm/Makefile | 1 + test/dm/cmd_dm.c | 4 +- test/dm/core.c | 9 +- test/dm/pci.c | 59 +++ test/dm/test-uclass.c | 16 +- test/dm/test.dts | 17 + 96 files changed, 2842 insertions(+), 677 deletions(-) create mode 100644 arch/sandbox/include/asm/processor.h create mode 100644 arch/sandbox/lib/pci_io.c create mode 100644 doc/driver-model/pci-info.txt create mode 100644 drivers/misc/swap_case.c create mode 100644 drivers/pci/pci-emul-uclass.c create mode 100644 drivers/pci/pci-uclass.c create mode 100644 drivers/pci/pci_common.c create mode 100644 drivers/pci/pci_compat.c create mode 100644 drivers/pci/pci_sandbox.c create mode 100644 drivers/pci/pci_x86.c create mode 100644 test/dm/pci.c
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH v2 1/22 sandbox: Update device tree 'reg' properties for I2C and SPI
We should have a size value for these. Add one in each case. This will be needed for PCI.
---
Changes in v2:
- Update root node #size=cells to 1 in this patch
arch/sandbox/dts/sandbox.dts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/sandbox/dts/sandbox.dts +3 -3
@@ -2,7 +2,7 @@ / { #address-cells = <1>; - #size-cells = <0>; + #size-cells = <1>; chosen { stdout-path = "/serial";
@@ -144,7 +144,7 @@ i2c at 0 { #address-cells = <1>; #size-cells = <0>; - reg = <0>; + reg = <0 0>; compatible = "sandbox,i2c"; clock-frequency = <400000>; eeprom at 2c {
@@ -161,7 +161,7 @@ spi at 0 { #address-cells = <1>; #size-cells = <0>; - reg = <0>; + reg = <0 0>; compatible = "sandbox,spi"; cs-gpios = <0>, <&gpio_a 0>; flash at 0 {
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH v2 1/22 sandbox: Update device tree 'reg' properties for I2C and SPI
Quoted 35 lines · Simon Glass
We should have a size value for these. Add one in each case. This will be needed for PCI.
Signed-off-by Simon Glass <[email protected]>---
Changes in v2:
- Update root node #size=cells to 1 in this patcharch/sandbox/dts/sandbox.dts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)arch/sandbox/dts/sandbox.dts +2
-2@@ -2,7 +2,7 @@ / { #address-cells = <1>; - #size-cells = <0>; + #size-cells = <1>; chosen { stdout-path = "/serial";@@ -144,7 +144,7 @@ i2c at 0 { #address-cells = <1>; #size-cells = <0>; - reg = <0>; + reg = <0 0>; compatible = "sandbox,i2c"; clock-frequency = <400000>; eeprom at 2c {
arch/sandbox/dts/sandbox.dts
Quoted 9 lines
arch/sandbox/dts/sandbox.dts +1
-2@@ -161,7 +161,7 @@ spi at 0 { #address-cells = <1>; #size-cells = <0>; - reg = <0>; + reg = <0 0>; compatible = "sandbox,spi"; cs-gpios = <0>, <&gpio_a 0>; flash at 0 { --
PATCH v2 1/22 sandbox: Update device tree 'reg' properties for I2C and SPI
Quoted 39 lines · Bin Meng
Quoted 38 lines · Simon Glass
We should have a size value for these. Add one in each case. This will be needed for PCI.
Signed-off-by Simon Glass <[email protected]>---
Changes in v2:
- Update root node #size=cells to 1 in this patcharch/sandbox/dts/sandbox.dts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)arch/sandbox/dts/sandbox.dts +2
-2@@ -2,7 +2,7 @@ / { #address-cells = <1>; - #size-cells = <0>; + #size-cells = <1>; chosen { stdout-path = "/serial";@@ -144,7 +144,7 @@ i2c at 0 { #address-cells = <1>; #size-cells = <0>; - reg = <0>; + reg = <0 0>; compatible = "sandbox,i2c"; clock-frequency = <400000>; eeprom at 2c {@@ -161,7 +161,7 @@ spi at 0 { #address-cells = <1>; #size-cells = <0>;
Quoted 8 lines
arch/sandbox/dts/sandbox.dts
Quoted 6 lines
arch/sandbox/dts/sandbox.dts +1
-2- reg = <0>; + reg = <0 0>; compatible = "sandbox,spi"; cs-gpios = <0>, <&gpio_a 0>; flash at 0 { --Reviewed-by Bin Meng <[email protected]>
Applied to u-boot-dm/next.
PATCH v2 2/22 fdt: Export fdtdec_get_number() for general use
In reply to Simon GlassThis function is missing a prototype but is more widey useful. Add it.
---
Changes in v2: None
include/fdtdec.h | 11 +++++++++++ lib/fdtdec.c | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-)
include/fdtdec.h +11 -0
@@ -386,6 +386,17 @@ s32 fdtdec_get_int(const void *blob, int node, const char *prop_name, s32 default_val);/** +* Get a variable-sized number from a property +* +* This reads a number from one or more cells. +* +* @param ptr Pointer to property +* @param cells Number of cells containing the number +* @return the value in the cells +*/ +u64 fdtdec_get_number (const fdt32_t *ptr,unsigned int cells); + +/** * Look up a 64-bit integer property in a node and return it. The property * must have at least 8 bytes of data (2 cells). The first two cells are * concatenated to form a 8 bytes value, where the first cell is top half and
lib/fdtdec.c +1 -1
@@ -918,7 +918,7 @@ int fdtdec_read_fmap_entry(const void *blob, int node, const char *name,return 0 ; } -static u64 fdtdec_get_number (const fdt32_t *ptr,unsigned int cells) +u64 fdtdec_get_number (const fdt32_t *ptr,unsigned int cells) {u64 number =0 ;
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH v2 2/22 fdt: Export fdtdec_get_number() for general use
Quoted 3 lines · Simon Glass
This function is missing a prototype but is more widey useful. Add it.
Signed-off-by Simon Glass <[email protected]>
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150306/f1020dea/attachment.sig>
PATCH v2 2/22 fdt: Export fdtdec_get_number() for general use
Quoted 7 lines · Tom Rini
Quoted 3 lines · Simon Glass
This function is missing a prototype but is more widey useful. Add it.
Signed-off-by Simon Glass <[email protected]>Reviewed-by Tom Rini <[email protected]>
Applied to u-boot-dm/next.
PATCH v2 3/22 x86: Add a x86_ prefix to the x86-specific PCI functions
In reply to Simon GlassThese functions currently use a generic name, but they are for x86 only. This may introduce confusion and prevents U-Boot from using these names more widely.
In fact it should be possible to remove these at some point and use generic functions, but for now, rename them.
---
Changes in v2: None
arch/x86/cpu/baytrail/early_uart.c | 5 ++- arch/x86/cpu/ivybridge/bd82x6x.c | 32 +++++++------- arch/x86/cpu/ivybridge/cpu.c | 38 ++++++++-------- arch/x86/cpu/ivybridge/early_init.c | 58 +++++++++++++------------ arch/x86/cpu/ivybridge/early_me.c | 12 +++--- arch/x86/cpu/ivybridge/gma.c | 4 +- arch/x86/cpu/ivybridge/lpc.c | 74 ++++++++++++++++---------------- arch/x86/cpu/ivybridge/northbridge.c | 6 +-- arch/x86/cpu/ivybridge/pch.c | 4 +- arch/x86/cpu/ivybridge/pci.c | 4 +- arch/x86/cpu/ivybridge/report_platform.c | 4 +- arch/x86/cpu/ivybridge/sata.c | 61 +++++++++++++------------- arch/x86/cpu/ivybridge/sdram.c | 20 ++++----- arch/x86/cpu/ivybridge/usb_ehci.c | 4 +- arch/x86/cpu/ivybridge/usb_xhci.c | 8 ++-- arch/x86/cpu/pci.c | 12 +++--- arch/x86/cpu/quark/quark.c | 4 +- arch/x86/cpu/queensbay/tnc.c | 4 +- arch/x86/include/asm/pci.h | 12 +++--- arch/x86/lib/bios_interrupts.c | 12 +++--- drivers/gpio/intel_ich6_gpio.c | 16 +++---- 21 files changed, 199 insertions(+), 195 deletions(-)
arch/x86/cpu/baytrail/early_uart.c +3 -2
@@ -50,7 +50,7 @@ static void score_select_func(int pad, int func)writel (reg, pconf0_addr); } -static void pci_write_config32 (int dev,unsigned int where,u32 value) +static void x86_pci_write_config32 (int dev,unsigned int where,u32 value) {unsigned long addr;
@@ -62,7 +62,8 @@ static void pci_write_config32(int dev, unsigned int where, u32 value)int setup_early_uart (void ) {/* Enable the legacy UART hardware. */ -pci_write_config32 (PCI_DEV_CONFIG (0 ,LPC_DEV ,LPC_FUNC ),UART_CONT ,1 ); +x86_pci_write_config32 (PCI_DEV_CONFIG (0 ,LPC_DEV ,LPC_FUNC ),UART_CONT , +1 );/* * Set up the pads to the UART function. This allows the signals to
arch/x86/cpu/ivybridge/bd82x6x.c +16 -16
@@ -22,36 +22,36 @@ void bd82x6x_pci_init(pci_dev_t dev)debug ("bd82x6x PCI init.\n" );/* Enable Bus Master */ - reg16 =pci_read_config16 (dev,PCI_COMMAND ); + reg16 =x86_pci_read_config16 (dev,PCI_COMMAND ); reg16 |=PCI_COMMAND_MASTER ; -pci_write_config16 (dev,PCI_COMMAND , reg16); +x86_pci_write_config16 (dev,PCI_COMMAND , reg16);/* This device has no interrupt */ -pci_write_config8 (dev,INTR ,0xff ); +x86_pci_write_config8 (dev,INTR ,0xff );/* disable parity error response and SERR */ - reg16 =pci_read_config16 (dev,BCTRL ); + reg16 =x86_pci_read_config16 (dev,BCTRL ); reg16 &= ~(1 <<0 ); reg16 &= ~(1 <<1 ); -pci_write_config16 (dev,BCTRL , reg16); +x86_pci_write_config16 (dev,BCTRL , reg16);/* Master Latency Count must be set to 0x04! */ - reg8 =pci_read_config8 (dev,SMLT ); + reg8 =x86_pci_read_config8 (dev,SMLT ); reg8 &=0x07 ; reg8 |= (0x04 <<3 ); -pci_write_config8 (dev,SMLT , reg8); +x86_pci_write_config8 (dev,SMLT , reg8);/* Will this improve throughput of bus masters? */ -pci_write_config8 (dev,PCI_MIN_GNT ,0x06 ); +x86_pci_write_config8 (dev,PCI_MIN_GNT ,0x06 );/* Clear errors in status registers */ - reg16 =pci_read_config16 (dev,PSTS ); + reg16 =x86_pci_read_config16 (dev,PSTS );/* reg16 |= 0xf900; */ -pci_write_config16 (dev,PSTS , reg16); +x86_pci_write_config16 (dev,PSTS , reg16); - reg16 =pci_read_config16 (dev,SECSTS ); + reg16 =x86_pci_read_config16 (dev,SECSTS );/* reg16 |= 0xf900; */ -pci_write_config16 (dev,SECSTS , reg16); +x86_pci_write_config16 (dev,SECSTS , reg16); }#define PCI_BRIDGE_UPDATE_COMMAND
@@ -59,7 +59,7 @@ void bd82x6x_pci_dev_enable_resources(pci_dev_t dev) {uint16_t command; - command =pci_read_config16 (dev,PCI_COMMAND ); + command =x86_pci_read_config16 (dev,PCI_COMMAND ); command |=PCI_COMMAND_IO ;#ifdef PCI_BRIDGE_UPDATE_COMMAND /*
@@ -67,7 +67,7 @@ void bd82x6x_pci_dev_enable_resources(pci_dev_t dev)* ROM and APICs to become invisible. */ debug ("%x cmd <- %02x\n" , dev, command); -pci_write_config16 (dev,PCI_COMMAND , command); +x86_pci_write_config16 (dev,PCI_COMMAND , command);#else printf ("%s cmd <- %02x (NOT WRITTEN!)\n" ,dev_path (dev), command);#endif
@@ -77,11 +77,11 @@ void bd82x6x_pci_bus_enable_resources(pci_dev_t dev) {uint16_t ctrl; - ctrl =pci_read_config16 (dev,PCI_BRIDGE_CONTROL ); + ctrl =x86_pci_read_config16 (dev,PCI_BRIDGE_CONTROL ); ctrl |=PCI_COMMAND_IO ; ctrl |=PCI_BRIDGE_CTL_VGA ;debug ("%x bridge ctrl <- %04x\n" , dev, ctrl); -pci_write_config16 (dev,PCI_BRIDGE_CONTROL , ctrl); +x86_pci_write_config16 (dev,PCI_BRIDGE_CONTROL , ctrl);bd82x6x_pci_dev_enable_resources (dev); }
arch/x86/cpu/ivybridge/cpu.c +19 -19
@@ -167,21 +167,21 @@ static int enable_smbus(void) dev =PCI_BDF (0x0 ,0x1f ,0x3 );/* Check to make sure we've got the right device. */ - value =pci_read_config16 (dev,0x0 ); + value =x86_pci_read_config16 (dev,0x0 );if (value !=0x8086 ) {printf ("SMBus controller not found\n" );return -ENOSYS ; }/* Set SMBus I/O base. */ -pci_write_config32 (dev,SMB_BASE , -SMBUS_IO_BASE |PCI_BASE_ADDRESS_SPACE_IO ); +x86_pci_write_config32 (dev,SMB_BASE , +SMBUS_IO_BASE |PCI_BASE_ADDRESS_SPACE_IO );/* Set SMBus enable. */ -pci_write_config8 (dev,HOSTC ,HST_EN ); +x86_pci_write_config8 (dev,HOSTC ,HST_EN );/* Set SMBus I/O space enable. */ -pci_write_config16 (dev,PCI_COMMAND ,PCI_COMMAND_IO ); +x86_pci_write_config16 (dev,PCI_COMMAND ,PCI_COMMAND_IO );/* Disable interrupt generation. */ outb (0 ,SMBUS_IO_BASE +SMBHSTCTL );
@@ -214,25 +214,25 @@ static void enable_usb_bar(void)u32 cmd;/* USB Controller 1 */ -pci_write_config32 (usb0,PCI_BASE_ADDRESS_0 , -PCH_EHCI0_TEMP_BAR0 ); - cmd =pci_read_config32 (usb0,PCI_COMMAND ); +x86_pci_write_config32 (usb0,PCI_BASE_ADDRESS_0 , +PCH_EHCI0_TEMP_BAR0 ); + cmd =x86_pci_read_config32 (usb0,PCI_COMMAND ); cmd |=PCI_COMMAND_MASTER |PCI_COMMAND_MEMORY ; -pci_write_config32 (usb0,PCI_COMMAND , cmd); +x86_pci_write_config32 (usb0,PCI_COMMAND , cmd);/* USB Controller 1 */ -pci_write_config32 (usb1,PCI_BASE_ADDRESS_0 , -PCH_EHCI1_TEMP_BAR0 ); - cmd =pci_read_config32 (usb1,PCI_COMMAND ); +x86_pci_write_config32 (usb1,PCI_BASE_ADDRESS_0 , +PCH_EHCI1_TEMP_BAR0 ); + cmd =x86_pci_read_config32 (usb1,PCI_COMMAND ); cmd |=PCI_COMMAND_MASTER |PCI_COMMAND_MEMORY ; -pci_write_config32 (usb1,PCI_COMMAND , cmd); +x86_pci_write_config32 (usb1,PCI_COMMAND , cmd);/* USB3 Controller */ -pci_write_config32 (usb3,PCI_BASE_ADDRESS_0 , -PCH_XHCI_TEMP_BAR0 ); - cmd =pci_read_config32 (usb3,PCI_COMMAND ); +x86_pci_write_config32 (usb3,PCI_BASE_ADDRESS_0 , +PCH_XHCI_TEMP_BAR0 ); + cmd =x86_pci_read_config32 (usb3,PCI_COMMAND ); cmd |=PCI_COMMAND_MASTER |PCI_COMMAND_MEMORY ; -pci_write_config32 (usb3,PCI_COMMAND , cmd); +x86_pci_write_config32 (usb3,PCI_COMMAND , cmd); }static int report_bist_failure (void )
@@ -320,8 +320,8 @@ int print_cpuinfo(void) gd->arch.pei_boot_mode = boot_mode;/* TODO: Move this to the board or driver */ -pci_write_config32 (PCH_LPC_DEV ,GPIO_BASE ,DEFAULT_GPIOBASE |1 ); -pci_write_config32 (PCH_LPC_DEV ,GPIO_CNTL ,0x10 ); +x86_pci_write_config32 (PCH_LPC_DEV ,GPIO_BASE ,DEFAULT_GPIOBASE |1 ); +x86_pci_write_config32 (PCH_LPC_DEV ,GPIO_CNTL ,0x10 );/* Print processor name */ name =cpu_get_name (processor_name);
arch/x86/cpu/ivybridge/early_init.c +30 -28
114 lines not on this page · raw message
arch/x86/cpu/ivybridge/early_me.c +6 -6
@@ -29,7 +29,7 @@ static inline void pci_read_dword_ptr(void *ptr, int offset) {u32 dword; - dword =pci_read_config32 (PCH_ME_DEV , offset); + dword =x86_pci_read_config32 (PCH_ME_DEV , offset);memcpy (ptr, &dword,sizeof (dword)); }
@@ -37,7 +37,7 @@ static inline void pci_write_dword_ptr(void *ptr, int offset) {u32 dword =0 ;memcpy (&dword, ptr,sizeof (dword)); -pci_write_config32 (PCH_ME_DEV , offset, dword); +x86_pci_write_config32 (PCH_ME_DEV , offset, dword); }void intel_early_me_status (void )
@@ -101,7 +101,7 @@ static inline void set_global_reset(int enable) {u32 etr3; - etr3 =pci_read_config32 (PCH_LPC_DEV ,ETR3 ); + etr3 =x86_pci_read_config32 (PCH_LPC_DEV ,ETR3 );/* Clear CF9 Without Resume Well Reset Enable */ etr3 &= ~ETR3_CWORWRE ;
@@ -112,7 +112,7 @@ static inline void set_global_reset(int enable)else etr3 &= ~ETR3_CF9GR ; -pci_write_config32 (PCH_LPC_DEV ,ETR3 , etr3); +x86_pci_write_config32 (PCH_LPC_DEV ,ETR3 , etr3); }int intel_early_me_init_done (u8 status)
@@ -127,8 +127,8 @@ int intel_early_me_init_done(u8 status) };/* MEBASE from MESEG_BASE[35:20] */ - mebase_l =pci_read_config32 (PCH_DEV ,PCI_CPU_MEBASE_L ); - mebase_h =pci_read_config32 (PCH_DEV ,PCI_CPU_MEBASE_H ); + mebase_l =x86_pci_read_config32 (PCH_DEV ,PCI_CPU_MEBASE_L ); + mebase_h =x86_pci_read_config32 (PCH_DEV ,PCI_CPU_MEBASE_H ); mebase_h &=0xf ; did.uma_base = (mebase_l >>20 ) | (mebase_h <<12 );
arch/x86/cpu/ivybridge/gma.c +2 -2
@@ -741,9 +741,9 @@ int gma_func0_init(pci_dev_t dev, struct pci_controller *hose,int ret;/* IGD needs to be Bus Master */ - reg32 =pci_read_config32 (dev,PCI_COMMAND ); + reg32 =x86_pci_read_config32 (dev,PCI_COMMAND ); reg32 |=PCI_COMMAND_MASTER |PCI_COMMAND_MEMORY |PCI_COMMAND_IO ; -pci_write_config32 (dev,PCI_COMMAND , reg32); +x86_pci_write_config32 (dev,PCI_COMMAND , reg32);/* Use write-combining for the graphics memory, 256MB */ base =pci_read_bar32 (hose, dev,2 );
arch/x86/cpu/ivybridge/lpc.c +37 -37
210 lines not on this page · raw message
arch/x86/cpu/ivybridge/northbridge.c +3 -3
@@ -30,7 +30,7 @@ int bridge_silicon_revision(void) result =cpuid (1 ); stepping = result.eax &0xf ; dev =PCI_BDF (0 ,0 ,0 ); - bridge_id =pci_read_config16 (dev,PCI_DEVICE_ID ) &0xf0 ; + bridge_id =x86_pci_read_config16 (dev,PCI_DEVICE_ID ) &0xf0 ; bridge_revision_id = bridge_id | stepping; }
@@ -55,7 +55,7 @@ static int get_pcie_bar(u32 *base, u32 *len) *base =0 ; *len =0 ; - pciexbar_reg =pci_read_config32 (dev,PCIEXBAR ); + pciexbar_reg =x86_pci_read_config32 (dev,PCIEXBAR );if (!(pciexbar_reg & (1 <<0 )))return 0 ;
@@ -170,7 +170,7 @@ void northbridge_init(pci_dev_t dev)void northbridge_enable (pci_dev_t dev) {#if CONFIG_HAVE_ACPI_RESUME -switch (pci_read_config32 (dev,SKPAD )) { +switch (x86_pci_read_config32 (dev,SKPAD )) {case 0xcafebabe :debug ("Normal boot.\n" );apci_set_slp_type (0 );
arch/x86/cpu/ivybridge/pch.c +2 -2
@@ -21,7 +21,7 @@ int pch_silicon_revision(void) dev =PCH_LPC_DEV ;if (pch_revision_id <0 ) - pch_revision_id =pci_read_config8 (dev,PCI_REVISION_ID ); + pch_revision_id =x86_pci_read_config8 (dev,PCI_REVISION_ID );return pch_revision_id; }
@@ -32,7 +32,7 @@ int pch_silicon_type(void) dev =PCH_LPC_DEV ;if (pch_type <0 ) - pch_type =pci_read_config8 (dev,PCI_DEVICE_ID +1 ); + pch_type =x86_pci_read_config8 (dev,PCI_DEVICE_ID +1 );return pch_type; }
arch/x86/cpu/ivybridge/pci.c +2 -2
@@ -70,9 +70,9 @@ int board_pci_pre_scan(struct pci_controller *hose) reg16 =0xff ; dev =PCH_DEV ; - reg16 =pci_read_config16 (dev,PCI_COMMAND ); + reg16 =x86_pci_read_config16 (dev,PCI_COMMAND ); reg16 |=PCI_COMMAND_SERR |PCI_COMMAND_MASTER |PCI_COMMAND_MEMORY ; -pci_write_config16 (dev,PCI_COMMAND , reg16); +x86_pci_write_config16 (dev,PCI_COMMAND , reg16);/* * Clear non-reserved bits in status register.
arch/x86/cpu/ivybridge/report_platform.c +2 -2
@@ -70,14 +70,14 @@ static void report_pch_info(void)u16 dev_id;uint8_t rev_id; - dev_id =pci_read_config16 (PCH_LPC_DEV ,2 ); + dev_id =x86_pci_read_config16 (PCH_LPC_DEV ,2 );for (i =0 ; i <ARRAY_SIZE (pch_table); i++) {if (pch_table[i].dev_id == dev_id) { pch_type = pch_table[i].dev_name;break ; } } - rev_id =pci_read_config8 (PCH_LPC_DEV ,8 ); + rev_id =x86_pci_read_config8 (PCH_LPC_DEV ,8 );debug ("PCH type: %s, device id: %x, rev id %x\n" , pch_type, dev_id, rev_id); }
arch/x86/cpu/ivybridge/sata.c +31 -30
145 lines not on this page · raw message
arch/x86/cpu/ivybridge/sdram.c +10 -10
@@ -444,7 +444,7 @@ int sdram_initialise(struct pei_data *pei_data)* Send ME init done for SandyBridge here. This is done inside the * SystemAgent binary on IvyBridge */ - done =pci_read_config32 (PCH_DEV ,PCI_DEVICE_ID ); + done =x86_pci_read_config32 (PCH_DEV ,PCI_DEVICE_ID ); done &=BASE_REV_MASK ;if (BASE_REV_SNB == done)intel_early_me_init_done (ME_INIT_STATUS_SUCCESS );
@@ -615,24 +615,24 @@ static int sdram_find(pci_dev_t dev)*/ /* Top of Upper Usable DRAM, including remap */ - touud =pci_read_config32 (dev,TOUUD +4 ); + touud =x86_pci_read_config32 (dev,TOUUD +4 ); touud <<=32 ; - touud |=pci_read_config32 (dev,TOUUD ); + touud |=x86_pci_read_config32 (dev,TOUUD );/* Top of Lower Usable DRAM */ - tolud =pci_read_config32 (dev,TOLUD ); + tolud =x86_pci_read_config32 (dev,TOLUD );/* Top of Memory - does not account for any UMA */ - tom =pci_read_config32 (dev,0xa4 ); + tom =x86_pci_read_config32 (dev,0xa4 ); tom <<=32 ; - tom |=pci_read_config32 (dev,0xa0 ); + tom |=x86_pci_read_config32 (dev,0xa0 );debug ("TOUUD %llx TOLUD %08x TOM %llx\n" , touud, tolud, tom);/* ME UMA needs excluding if total memory <4GB */ - me_base =pci_read_config32 (dev,0x74 ); + me_base =x86_pci_read_config32 (dev,0x74 ); me_base <<=32 ; - me_base |=pci_read_config32 (dev,0x70 ); + me_base |=x86_pci_read_config32 (dev,0x70 );debug ("MEBASE %llx\n" , me_base);
@@ -650,7 +650,7 @@ static int sdram_find(pci_dev_t dev) }/* Graphics memory comes next */ - ggc =pci_read_config16 (dev,GGC ); + ggc =x86_pci_read_config16 (dev,GGC );if (!(ggc &2 )) {debug ("IGD decoded, subtracting " );
@@ -670,7 +670,7 @@ static int sdram_find(pci_dev_t dev) }/* Calculate TSEG size from its base which must be below GTT */ - tseg_base =pci_read_config32 (dev,0xb8 ); + tseg_base =x86_pci_read_config32 (dev,0xb8 ); uma_size = (uma_memory_base - tseg_base) >>10 ; tomk -= uma_size; uma_memory_base = tomk *1024ULL ;
arch/x86/cpu/ivybridge/usb_ehci.c +2 -2
@@ -20,10 +20,10 @@ void bd82x6x_usb_ehci_init(pci_dev_t dev)writel (reg32,RCB_REG (0x35b0 ));debug ("EHCI: Setting up controller.. " ); - reg32 =pci_read_config32 (dev,PCI_COMMAND ); + reg32 =x86_pci_read_config32 (dev,PCI_COMMAND ); reg32 |=PCI_COMMAND_MASTER ;/* reg32 |= PCI_COMMAND_SERR; */ -pci_write_config32 (dev,PCI_COMMAND , reg32); +x86_pci_write_config32 (dev,PCI_COMMAND , reg32);debug ("done.\n" ); }
arch/x86/cpu/ivybridge/usb_xhci.c +4 -4
@@ -16,17 +16,17 @@ void bd82x6x_usb_xhci_init(pci_dev_t dev)debug ("XHCI: Setting up controller.. " );/* lock overcurrent map */ - reg32 =pci_read_config32 (dev,0x44 ); + reg32 =x86_pci_read_config32 (dev,0x44 ); reg32 |=1 ; -pci_write_config32 (dev,0x44 , reg32); +x86_pci_write_config32 (dev,0x44 , reg32);/* Enable clock gating */ - reg32 =pci_read_config32 (dev,0x40 ); + reg32 =x86_pci_read_config32 (dev,0x40 ); reg32 &= ~((1 <<20 ) | (1 <<21 )); reg32 |= (1 <<19 ) | (1 <<18 ) | (1 <<17 ); reg32 |= (1 <<10 ) | (1 <<9 ) | (1 <<8 ); reg32 |= (1 <<31 );/* lock */ -pci_write_config32 (dev,0x40 , reg32); +x86_pci_write_config32 (dev,0x40 , reg32);debug ("done.\n" ); }
arch/x86/cpu/pci.c +6 -6
@@ -70,7 +70,7 @@ static struct pci_controller *get_hose(void)return pci_bus_to_hose (0 ); } -unsigned int pci_read_config8 (pci_dev_t dev,unsigned where) +unsigned int x86_pci_read_config8 (pci_dev_t dev,unsigned where) {uint8_t value;
@@ -79,7 +79,7 @@ unsigned int pci_read_config8(pci_dev_t dev, unsigned where)return value; } -unsigned int pci_read_config16 (pci_dev_t dev,unsigned where) +unsigned int x86_pci_read_config16 (pci_dev_t dev,unsigned where) {uint16_t value;
@@ -88,7 +88,7 @@ unsigned int pci_read_config16(pci_dev_t dev, unsigned where)return value; } -unsigned int pci_read_config32 (pci_dev_t dev,unsigned where) +unsigned int x86_pci_read_config32 (pci_dev_t dev,unsigned where) {uint32_t value;
@@ -97,17 +97,17 @@ unsigned int pci_read_config32(pci_dev_t dev, unsigned where)return value; } -void pci_write_config8 (pci_dev_t dev,unsigned where,unsigned value) +void x86_pci_write_config8 (pci_dev_t dev,unsigned where,unsigned value) {pci_hose_write_config_byte (get_hose (), dev, where, value); } -void pci_write_config16 (pci_dev_t dev,unsigned where,unsigned value) +void x86_pci_write_config16 (pci_dev_t dev,unsigned where,unsigned value) {pci_hose_write_config_word (get_hose (), dev, where, value); } -void pci_write_config32 (pci_dev_t dev,unsigned where,unsigned value) +void x86_pci_write_config32 (pci_dev_t dev,unsigned where,unsigned value) {pci_hose_write_config_dword (get_hose (), dev, where, value); }
arch/x86/cpu/quark/quark.c +2 -2
@@ -28,9 +28,9 @@ static void unprotect_spi_flash(void) {u32 bc; - bc =pci_read_config32 (QUARK_LEGACY_BRIDGE ,0xd8 ); + bc =x86_pci_read_config32 (QUARK_LEGACY_BRIDGE ,0xd8 ); bc |=0x1 ;/* unprotect the flash */ -pci_write_config32 (QUARK_LEGACY_BRIDGE ,0xd8 , bc); +x86_pci_write_config32 (QUARK_LEGACY_BRIDGE ,0xd8 , bc); }static void quark_setup_bars (void )
arch/x86/cpu/queensbay/tnc.c +2 -2
@@ -16,9 +16,9 @@ static void unprotect_spi_flash(void) {u32 bc; - bc =pci_read_config32 (PCH_LPC_DEV ,0xd8 ); + bc =x86_pci_read_config32 (PCH_LPC_DEV ,0xd8 ); bc |=0x1 ;/* unprotect the flash */ -pci_write_config32 (PCH_LPC_DEV ,0xd8 , bc); +x86_pci_write_config32 (PCH_LPC_DEV ,0xd8 , bc); }int arch_cpu_init (void )
arch/x86/include/asm/pci.h +6 -6
@@ -48,13 +48,13 @@ int board_pci_post_scan(struct pci_controller *hose);* Simple PCI access routines - these work from either the early PCI hose * or the 'real' one, created after U-Boot has memory available */ -unsigned int pci_read_config8 (pci_dev_t dev,unsigned where); -unsigned int pci_read_config16 (pci_dev_t dev,unsigned where); -unsigned int pci_read_config32 (pci_dev_t dev,unsigned where); +unsigned int x86_pci_read_config8 (pci_dev_t dev,unsigned where); +unsigned int x86_pci_read_config16 (pci_dev_t dev,unsigned where); +unsigned int x86_pci_read_config32 (pci_dev_t dev,unsigned where); -void pci_write_config8 (pci_dev_t dev,unsigned where,unsigned value); -void pci_write_config16 (pci_dev_t dev,unsigned where,unsigned value); -void pci_write_config32 (pci_dev_t dev,unsigned where,unsigned value); +void x86_pci_write_config8 (pci_dev_t dev,unsigned where,unsigned value); +void x86_pci_write_config16 (pci_dev_t dev,unsigned where,unsigned value); +void x86_pci_write_config32 (pci_dev_t dev,unsigned where,unsigned value);#endif /* __ASSEMBLY__ */
arch/x86/lib/bios_interrupts.c +6 -6
@@ -172,28 +172,28 @@ int int1a_handler(void) }switch (func) {case 0xb108 :/* Read Config Byte */ - byte =pci_read_config8 (dev, reg); + byte =x86_pci_read_config8 (dev, reg);M .x86.R_ECX = byte;break ;case 0xb109 :/* Read Config Word */ - word =pci_read_config16 (dev, reg); + word =x86_pci_read_config16 (dev, reg);M .x86.R_ECX = word;break ;case 0xb10a :/* Read Config Dword */ - dword =pci_read_config32 (dev, reg); + dword =x86_pci_read_config32 (dev, reg);M .x86.R_ECX = dword;break ;case 0xb10b :/* Write Config Byte */ byte =M .x86.R_ECX; -pci_write_config8 (dev, reg, byte); +x86_pci_write_config8 (dev, reg, byte);break ;case 0xb10c :/* Write Config Word */ word =M .x86.R_ECX; -pci_write_config16 (dev, reg, word); +x86_pci_write_config16 (dev, reg, word);break ;case 0xb10d :/* Write Config Dword */ dword =M .x86.R_ECX; -pci_write_config32 (dev, reg, dword); +x86_pci_write_config32 (dev, reg, dword);break ; }
drivers/gpio/intel_ich6_gpio.c +8 -8
@@ -64,13 +64,13 @@ static int gpio_ich6_ofdata_to_platdata(struct udevice *dev) pci_dev =PCI_BDF (0 ,0x1f ,0 );/* Is the device present? */ - tmpword =pci_read_config16 (pci_dev,PCI_VENDOR_ID ); + tmpword =x86_pci_read_config16 (pci_dev,PCI_VENDOR_ID );if (tmpword !=PCI_VENDOR_ID_INTEL ) {debug ("%s: wrong VendorID\n" , __func__);return -ENODEV ; } - tmpword =pci_read_config16 (pci_dev,PCI_DEVICE_ID ); + tmpword =x86_pci_read_config16 (pci_dev,PCI_DEVICE_ID );debug ("Found %04x:%04x\n" ,PCI_VENDOR_ID_INTEL , tmpword);/* * We'd like to validate the Device ID too, but pretty much any
@@ -80,34 +80,34 @@ static int gpio_ich6_ofdata_to_platdata(struct udevice *dev)*/ /* I/O should already be enabled (it's a RO bit). */ - tmpword =pci_read_config16 (pci_dev,PCI_COMMAND ); + tmpword =x86_pci_read_config16 (pci_dev,PCI_COMMAND );if (!(tmpword &PCI_COMMAND_IO )) {debug ("%s: device IO not enabled\n" , __func__);return -ENODEV ; }/* Header Type must be normal (bits 6-0 only; see spec.) */ - tmpbyte =pci_read_config8 (pci_dev,PCI_HEADER_TYPE ); + tmpbyte =x86_pci_read_config8 (pci_dev,PCI_HEADER_TYPE );if ((tmpbyte &0x7f ) !=PCI_HEADER_TYPE_NORMAL ) {debug ("%s: invalid Header type\n" , __func__);return -ENODEV ; }/* Base Class must be a bridge device */ - tmpbyte =pci_read_config8 (pci_dev,PCI_CLASS_CODE ); + tmpbyte =x86_pci_read_config8 (pci_dev,PCI_CLASS_CODE );if (tmpbyte !=PCI_CLASS_CODE_BRIDGE ) {debug ("%s: invalid class\n" , __func__);return -ENODEV ; }/* Sub Class must be ISA */ - tmpbyte =pci_read_config8 (pci_dev,PCI_CLASS_SUB_CODE ); + tmpbyte =x86_pci_read_config8 (pci_dev,PCI_CLASS_SUB_CODE );if (tmpbyte !=PCI_CLASS_SUB_CODE_BRIDGE_ISA ) {debug ("%s: invalid subclass\n" , __func__);return -ENODEV ; }/* Programming Interface must be 0x00 (no others exist) */ - tmpbyte =pci_read_config8 (pci_dev,PCI_CLASS_PROG ); + tmpbyte =x86_pci_read_config8 (pci_dev,PCI_CLASS_PROG );if (tmpbyte !=0x00 ) {debug ("%s: invalid interface type\n" , __func__);return -ENODEV ;
@@ -123,7 +123,7 @@ static int gpio_ich6_ofdata_to_platdata(struct udevice *dev)* while on the Ivybridge the bit0 is used to indicate it is an * I/O space. */ - tmplong =pci_read_config32 (pci_dev,PCI_CFG_GPIOBASE ); + tmplong =x86_pci_read_config32 (pci_dev,PCI_CFG_GPIOBASE );if (tmplong ==0x00000000 || tmplong ==0xffffffff ) {debug ("%s: unexpected GPIOBASE value\n" , __func__);return -ENODEV ;
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH v2 3/22 x86: Add a x86_ prefix to the x86-specific PCI functions
Quoted 4 lines · Simon Glass
These functions currently use a generic name, but they are for x86 only. This may introduce confusion and prevents U-Boot from using these names more widely.
Quoted 8 lines
In fact it should be possible to remove these at some point and use generic functions, but for now, rename them.
Signed-off-by Simon Glass <[email protected]>Reviewed-by Bin Meng <[email protected]>---
Changes in v2: None
Applied to u-boot-dm/next.
PATCH v2 4/22 dm: Add a new CPU init function which can use driver model
In reply to Simon GlassSince driver model is set up after arch_cpu_init(), that function cannot use drivers. Add a new arch_cpu_init_dm() function which is called immediately after driver model is ready, and can reference devices.
This can be used to probe essential devices for the CPU.
---
Changes in v2:
- Add a new patch with a CPU init function which can use driver model
common/board_f.c | 6 ++++++ include/common.h | 11 +++++++++++ 2 files changed, 17 insertions(+)
common/board_f.c +6 -0
@@ -787,6 +787,11 @@ __weak int reserve_arch(void)return 0 ; } +__weak int arch_cpu_init_dm (void ) +{ +return 0 ; +} + static init_fnc_t init_sequence_f[] = {#ifdef CONFIG_SANDBOX setup_ram_buf,
@@ -807,6 +812,7 @@ static init_fnc_t init_sequence_f[] = { fdtdec_check_fdt, #endif initf_dm, + arch_cpu_init_dm, #if defined(CONFIG_BOARD_EARLY_INIT_F) board_early_init_f,#endif
include/common.h +11 -0
@@ -253,6 +253,17 @@ int update_flash_size(int flash_size);int arch_early_init_r (void );/** +* arch_cpu_init_dm() - init CPU after driver model is available +* +* This is called immediately after driver model is available before +* relocation. This is similar to arch_cpu_init() but is able to reference +* devices +* +* @return 0 if OK, -ve on error +*/ +int arch_cpu_init_dm (void ); + +/** * Reserve all necessary stacks * * This is used in generic board init sequence in common/board_f.c. Each
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH v2 4/22 dm: Add a new CPU init function which can use driver model
Quoted 53 lines · Simon Glass
Since driver model is set up after
arch_cpu_init(), that function cannot use drivers. Add a newarch_cpu_init_dm()function which is called immediately after driver model is ready, and can reference devices.This can be used to probe essential devices for the CPU.
Signed-off-by Simon Glass <[email protected]>---
Changes in v2:
- Add a new patch with a CPU init function which can use driver modelcommon/board_f.c | 6 ++++++ include/common.h | 11 +++++++++++ 2 files changed, 17 insertions(+)common/board_f.c +6
-0@@ -787,6 +787,11 @@ __weak int reserve_arch(void)return 0 ; } +__weak int arch_cpu_init_dm (void ) +{ +return 0 ; +} + static init_fnc_t init_sequence_f[] = {#ifdef CONFIG_SANDBOX setup_ram_buf,@@ -807,6 +812,7 @@ static init_fnc_t init_sequence_f[] = { fdtdec_check_fdt, #endif initf_dm, + arch_cpu_init_dm, #if defined(CONFIG_BOARD_EARLY_INIT_F) board_early_init_f,#endif include/common.h +5
-0@@ -253,6 +253,17 @@ int update_flash_size(int flash_size);int arch_early_init_r (void );/** +* arch_cpu_init_dm() - init CPU after driver model is available +* +* This is called immediately after driver model is available before +* relocation. This is similar to arch_cpu_init() but is able to reference +* devices
include/common.h int update_flash_size(int flash_size);
Quoted 10 lines
include/common.h +6
-1+* +* @return 0 if OK, -ve on error +*/ +int arch_cpu_init_dm (void ); + +/** * Reserve all necessary stacks * * This is used in generic board init sequence in common/board_f.c. Each --
PATCH v2 4/22 dm: Add a new CPU init function which can use driver model
Quoted 58 lines · Bin Meng
Quoted 57 lines · Simon Glass
Since driver model is set up after
arch_cpu_init(), that function cannot use drivers. Add a newarch_cpu_init_dm()function which is called immediately after driver model is ready, and can reference devices.This can be used to probe essential devices for the CPU.
Signed-off-by Simon Glass <[email protected]>---
Changes in v2:
- Add a new patch with a CPU init function which can use driver modelcommon/board_f.c | 6 ++++++ include/common.h | 11 +++++++++++ 2 files changed, 17 insertions(+)common/board_f.c +6
-0@@ -787,6 +787,11 @@ __weak int reserve_arch(void)return 0 ; } +__weak int arch_cpu_init_dm (void ) +{ +return 0 ; +} + static init_fnc_t init_sequence_f[] = {#ifdef CONFIG_SANDBOX setup_ram_buf,@@ -807,6 +812,7 @@ static init_fnc_t init_sequence_f[] = { fdtdec_check_fdt, #endif initf_dm, + arch_cpu_init_dm, #if defined(CONFIG_BOARD_EARLY_INIT_F) board_early_init_f,#endif include/common.h +9
-0@@ -253,6 +253,17 @@ int update_flash_size(int flash_size);int arch_early_init_r (void );/** +* arch_cpu_init_dm() - init CPU after driver model is available +* +* This is called immediately after driver model is available before +* relocation. This is similar to arch_cpu_init() but is able to reference +* devices +* +* @return 0 if OK, -ve on error +*/ +int arch_cpu_init_dm (void );
Quoted 8 lines
include/common.h int update_flash_size(int flash_size);
Quoted 6 lines
include/common.h +2
-1+ +/** * Reserve all necessary stacks * * This is used in generic board init sequence in common/board_f.c. Each -- Reviewed-by Bin Meng <[email protected]>
Applied to u-boot-dm/next.
PATCH v2 5/22 x86: Split up arch_cpu_init()
In reply to Simon GlassAt present we do more in this function than we should. Split out the post-driver-model part into a separate function.
---
Changes in v2:
- Use the new arch_cpu_init_dm() function instead of something x86-specific
arch/x86/cpu/ivybridge/cpu.c | 8 ++++++++ 1 file changed, 8 insertions(+)
arch/x86/cpu/ivybridge/cpu.c +8 -0
@@ -116,6 +116,14 @@ static void set_spi_speed(void)int arch_cpu_init (void ) { +post_code (POST_CPU_INIT ); +timer_set_base (rdtsc ()); + +return x86_cpu_init_f (); +} + +int arch_cpu_init_dm (void ) +{const void *blob = gd->fdt_blob;struct pci_controller *hose;int node;
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH v2 5/22 x86: Split up arch_cpu_init()
Quoted 22 lines · Simon Glass
At present we do more in this function than we should. Split out the post-driver-model part into a separate function.
Signed-off-by Simon Glass <[email protected]>---
Changes in v2:
- Use the newarch_cpu_init_dm()function instead of something x86-specificarch/x86/cpu/ivybridge/cpu.c | 8 ++++++++ 1 file changed, 8 insertions(+)arch/x86/cpu/ivybridge/cpu.c +2
-0@@ -116,6 +116,14 @@ static void set_spi_speed(void)int arch_cpu_init (void ) { +post_code (POST_CPU_INIT ); +timer_set_base (rdtsc ());
arch/x86/cpu/ivybridge/cpu.c static void set_spi_speed(void)
Quoted 10 lines
arch/x86/cpu/ivybridge/cpu.c +6
-1+ +return x86_cpu_init_f (); +} + +int arch_cpu_init_dm (void ) +{const void *blob = gd->fdt_blob;struct pci_controller *hose;int node; --
PATCH v2 5/22 x86: Split up arch_cpu_init()
Quoted 19 lines · Bin Meng
Quoted 18 lines · Simon Glass
At present we do more in this function than we should. Split out the post-driver-model part into a separate function.
Signed-off-by Simon Glass <[email protected]>---
Changes in v2:
- Use the newarch_cpu_init_dm()function instead of something x86-specificarch/x86/cpu/ivybridge/cpu.c | 8 ++++++++ 1 file changed, 8 insertions(+)arch/x86/cpu/ivybridge/cpu.c +0
-0@@ -116,6 +116,14 @@ static void set_spi_speed(void)
Quoted 16 lines
Quoted 4 lines
arch/x86/cpu/ivybridge/cpu.c +2
-0int arch_cpu_init (void ) { +post_code (POST_CPU_INIT ); +timer_set_base (rdtsc ());arch/x86/cpu/ivybridge/cpu.c static void set_spi_speed(void)
Quoted 10 lines
arch/x86/cpu/ivybridge/cpu.c +6
-1+ +return x86_cpu_init_f (); +} + +int arch_cpu_init_dm (void ) +{const void *blob = gd->fdt_blob;struct pci_controller *hose;int node; --Reviewed-by Bin Meng <[email protected]>
Applied to u-boot-dm/next.
PATCH v2 6/22 Correct map_sysmem() logic in do_mem_mw()
In reply to Simon GlassThis function does not unmap what it maps. Correct it.
---
Changes in v2: None
common/cmd_mem.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
common/cmd_mem.c +4 -3
@@ -165,7 +165,7 @@ static int do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])#endif ulong addr, count;int size; -void *buf; +void *buf, *start;ulong bytes;if ((argc <3 ) || (argc >4 ))
@@ -197,7 +197,8 @@ static int do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) } bytes = size * count; - buf =map_sysmem (addr, bytes); + start =map_sysmem (addr, bytes); + buf = start;while (count-- >0 ) {if (size ==4 ) *((u32 *)buf) = (u32 )writeval;
@@ -211,7 +212,7 @@ static int do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) *((u8 *)buf) = (u8 )writeval; buf += size; } -unmap_sysmem (buf); +unmap_sysmem (start);return 0 ; }
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH v2 6/22 Correct map_sysmem() logic in do_mem_mw()
Quoted 34 lines · Simon Glass
This function does not unmap what it maps. Correct it.
Signed-off-by Simon Glass <[email protected]>---
Changes in v2: None
common/cmd_mem.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)common/cmd_mem.c +3
-2@@ -165,7 +165,7 @@ static int do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])#endif ulong addr, count;int size; -void *buf; +void *buf, *start;ulong bytes;if ((argc <3 ) || (argc >4 ))@@ -197,7 +197,8 @@ static int do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) } bytes = size * count; - buf =map_sysmem (addr, bytes); + start =map_sysmem (addr, bytes); + buf = start;while (count-- >0 ) {if (size ==4 ) *((u32 *)buf) = (u32 )writeval;
common/cmd_mem.c static int do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Quoted 9 lines
common/cmd_mem.c +1
-2@@ -211,7 +212,7 @@ static int do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) *((u8 *)buf) = (u8 )writeval; buf += size; } -unmap_sysmem (buf); +unmap_sysmem (start);return 0 ; } --
PATCH v2 6/22 Correct map_sysmem() logic in do_mem_mw()
Quoted 43 lines · Bin Meng
Quoted 42 lines · Simon Glass
This function does not unmap what it maps. Correct it.
Signed-off-by Simon Glass <[email protected]>---
Changes in v2: None
common/cmd_mem.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)common/cmd_mem.c +4
-3@@ -165,7 +165,7 @@ static int do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])#endif ulong addr, count;int size; -void *buf; +void *buf, *start;ulong bytes;if ((argc <3 ) || (argc >4 ))@@ -197,7 +197,8 @@ static int do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) } bytes = size * count; - buf =map_sysmem (addr, bytes); + start =map_sysmem (addr, bytes); + buf = start;while (count-- >0 ) {if (size ==4 ) *((u32 *)buf) = (u32 )writeval;@@ -211,7 +212,7 @@ static int do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) *((u8 *)buf) = (u8 )writeval; buf += size; } -unmap_sysmem (buf); +unmap_sysmem (start);return 0 ; }
Quoted 3 lines
Quoted 1 line
--
Reviewed-by Bin Meng <[email protected]>
Applied to u-boot-dm/next.
PATCH v2 7/22 fdt: Tighten up error handling in fdtdec_get_pci_addr()
In reply to Simon GlassThis function returns -ENOENT when the property is missing (which the caller might forgive) and also when the property is present but incorrectly formatted (which many callers would like to report).
Update the error return value to allow these different situations to be distinguished.
---
Changes in v2:
- Add -ve sign before ENXIO
include/fdtdec.h | 4 +++- lib/fdtdec.c | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-)
include/fdtdec.h +3 -1
@@ -327,7 +327,9 @@ fdt_addr_t fdtdec_get_addr_size(const void *blob, int node,* @param type pci address type (FDT_PCI_SPACE_xxx) * @param prop_name name of property to find * @param addr returns pci address in the form of fdt_pci_addr -* @return 0 if ok, negative on error +* @return 0 if ok, -ENOENT if the property did not exist, -EINVAL if the +* format of the property was invalid, -ENXIO if the requested +* address type was not found */ int fdtdec_get_pci_addr (const void *blob,int node,enum fdt_pci_space type,const char *prop_name,struct fdt_pci_addr *addr);
lib/fdtdec.c +3 -1
@@ -160,8 +160,10 @@ int fdtdec_get_pci_addr(const void *blob, int node, enum fdt_pci_space type, } } -if (i == num) +if (i == num) { + ret = -ENXIO ; goto fail; + }return 0 ; }else {
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH v2 7/22 fdt: Tighten up error handling in fdtdec_get_pci_addr()
Quoted 8 lines · Simon Glass
This function returns
-ENOENTwhen the property is missing (which the caller might forgive) and also when the property is present but incorrectly formatted (which many callers would like to report).Update the error return value to allow these different situations to be distinguished.
Signed-off-by Simon Glass <[email protected]>
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150306/2dc530d7/attachment.sig>
PATCH v2 7/22 fdt: Tighten up error handling in fdtdec_get_pci_addr()
In reply to Simon GlassQuoted 39 lines · Simon Glass
This function returns
-ENOENTwhen the property is missing (which the caller might forgive) and also when the property is present but incorrectly formatted (which many callers would like to report).Update the error return value to allow these different situations to be distinguished.
Signed-off-by Simon Glass <[email protected]>---
Changes in v2:
- Add -ve sign before ENXIOinclude/fdtdec.h | 4 +++- lib/fdtdec.c | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-)include/fdtdec.h +3
-1@@ -327,7 +327,9 @@ fdt_addr_t fdtdec_get_addr_size(const void *blob, int node,* @param type pci address type (FDT_PCI_SPACE_xxx) * @param prop_name name of property to find * @param addr returns pci address in the form of fdt_pci_addr -* @return 0 if ok, negative on error +* @return 0 if ok, -ENOENT if the property did not exist, -EINVAL if the +* format of the property was invalid, -ENXIO if the requested +* address type was not found */ int fdtdec_get_pci_addr (const void *blob,int node,enum fdt_pci_space type,const char *prop_name,struct fdt_pci_addr *addr);lib/fdtdec.c +0
-0@@ -160,8 +160,10 @@ int fdtdec_get_pci_addr(const void *blob, int node, enum fdt_pci_space type, } }
lib/fdtdec.c int fdtdec_get_pci_addr(const void *blob, int node, enum fdt_pci_space type,
Quoted 10 lines
lib/fdtdec.c +3
-2-if (i == num) +if (i == num) { + ret = -ENXIO ; goto fail; + }return 0 ; }else { --
PATCH v2 7/22 fdt: Tighten up error handling in fdtdec_get_pci_addr()
Quoted 47 lines · Bin Meng
Quoted 46 lines · Simon Glass
This function returns
-ENOENTwhen the property is missing (which the caller might forgive) and also when the property is present but incorrectly formatted (which many callers would like to report).Update the error return value to allow these different situations to be distinguished.
Signed-off-by Simon Glass <[email protected]>---
Changes in v2:
- Add -ve sign before ENXIOinclude/fdtdec.h | 4 +++- lib/fdtdec.c | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-)include/fdtdec.h +3
-1@@ -327,7 +327,9 @@ fdt_addr_t fdtdec_get_addr_size(const void *blob, int node,* @param type pci address type (FDT_PCI_SPACE_xxx) * @param prop_name name of property to find * @param addr returns pci address in the form of fdt_pci_addr -* @return 0 if ok, negative on error +* @return 0 if ok, -ENOENT if the property did not exist, -EINVAL if the +* format of the property was invalid, -ENXIO if the requested +* address type was not found */ int fdtdec_get_pci_addr (const void *blob,int node,enum fdt_pci_space type,const char *prop_name,struct fdt_pci_addr *addr);lib/fdtdec.c +3
-1@@ -160,8 +160,10 @@ int fdtdec_get_pci_addr(const void *blob, int node, enum fdt_pci_space type, } } -if (i == num) +if (i == num) { + ret = -ENXIO ; goto fail; + }
Quoted 5 lines
lib/fdtdec.c int fdtdec_get_pci_addr(const void *blob, int node, enum fdt_pci_space type,
Quoted 3 lines
lib/fdtdec.c +0
-1return 0 ; }else { --Reviewed-by Bin Meng <[email protected]>
Applied to u-boot-dm/next.
PATCH v2 8/22 dm: core: Add dev_get_uclass_priv() to access uclass private data
In reply to Simon GlassAdd a convenience function to access the private data that a uclass stores for each of its devices. Convert over most existing uses for consistency and to provide an example for others.
---
Changes in v2: None
common/cmd_sf.c | 2 +- common/cros_ec.c | 2 +- drivers/core/device.c | 10 ++++++++++ drivers/gpio/at91_gpio.c | 2 +- drivers/gpio/bcm2835_gpio.c | 2 +- drivers/gpio/gpio-uclass.c | 22 +++++++++++----------- drivers/gpio/intel_ich6_gpio.c | 2 +- drivers/gpio/mxc_gpio.c | 2 +- drivers/gpio/omap_gpio.c | 2 +- drivers/gpio/s5p_gpio.c | 2 +- drivers/gpio/sandbox.c | 6 +++--- drivers/gpio/sunxi_gpio.c | 2 +- drivers/gpio/tegra_gpio.c | 2 +- drivers/i2c/i2c-uclass.c | 6 +++--- drivers/i2c/sandbox_i2c.c | 2 +- drivers/misc/cros_ec.c | 6 +++--- drivers/misc/cros_ec_i2c.c | 2 +- drivers/misc/cros_ec_sandbox.c | 2 +- drivers/misc/cros_ec_spi.c | 4 ++-- drivers/mtd/spi/sf-uclass.c | 2 +- drivers/mtd/spi/sf_probe.c | 8 ++++---- drivers/serial/serial-uclass.c | 4 ++-- drivers/spi/spi-uclass.c | 4 ++-- include/dm/device.h | 10 ++++++++++ include/i2c.h | 8 ++++---- test/dm/core.c | 2 +- test/dm/test-uclass.c | 4 ++-- 27 files changed, 71 insertions(+), 51 deletions(-)
common/cmd_sf.c +1 -1
@@ -130,7 +130,7 @@ static int do_spi_flash_probe(int argc, char * const argv[]) return 1; } - flash = new->uclass_priv; + flash =dev_get_uclass_priv (new);#else new =spi_flash_probe (bus, cs, speed, mode);if (!new) {
common/cros_ec.c +1 -1
@@ -35,7 +35,7 @@ struct cros_ec_dev *board_get_cros_ec_dev(void)debug ("%s: Error %d\n" , __func__, ret); return NULL; } -return dev->uclass_priv; +return dev_get_uclass_priv (dev);#else return local.cros_ec_dev;#endif
drivers/core/device.c +10 -0
@@ -305,6 +305,16 @@ void *dev_get_priv(struct udevice *dev)return dev->priv; } +void *dev_get_uclass_priv (struct udevice *dev) +{ +if (!dev) { +dm_warn ("%s: null device\n" , __func__); +return NULL ; + } + +return dev->uclass_priv; +} +void *dev_get_parentdata (struct udevice *dev) {if (!dev) {
drivers/gpio/at91_gpio.c +1 -1
@@ -511,7 +511,7 @@ static int at91_gpio_probe(struct udevice *dev) {struct at91_port_priv *port =dev_get_priv (dev);struct at91_port_platdata *plat =dev_get_platdata (dev); -struct gpio_dev_priv *uc_priv = dev->uclass_priv; +struct gpio_dev_priv *uc_priv =dev_get_uclass_priv (dev); uc_priv->bank_name = plat->bank_name; uc_priv->gpio_count =GPIO_PER_BANK ;
drivers/gpio/bcm2835_gpio.c +1 -1
@@ -105,7 +105,7 @@ static int bcm2835_gpio_probe(struct udevice *dev) {struct bcm2835_gpios *gpios =dev_get_priv (dev);struct bcm2835_gpio_platdata *plat =dev_get_platdata (dev); -struct gpio_dev_priv *uc_priv = dev->uclass_priv; +struct gpio_dev_priv *uc_priv =dev_get_uclass_priv (dev); uc_priv->bank_name ="GPIO" ; uc_priv->gpio_count =BCM2835_GPIO_COUNT ;
drivers/gpio/gpio-uclass.c +11 -11
@@ -34,7 +34,7 @@ static int gpio_to_device(unsigned int gpio, struct gpio_desc *desc)for (ret =uclass_first_device (UCLASS_GPIO , &dev); dev; ret =uclass_next_device (&dev)) { - uc_priv = dev->uclass_priv; + uc_priv =dev_get_uclass_priv (dev);if (gpio >= uc_priv->gpio_base && gpio < uc_priv->gpio_base + uc_priv->gpio_count) { desc->dev = dev;
@@ -65,7 +65,7 @@ int gpio_lookup_name(const char *name, struct udevice **devp, ret = uclass_next_device(&dev)) {int len; - uc_priv = dev->uclass_priv; + uc_priv =dev_get_uclass_priv (dev);if (numeric !=-1 ) { offset = numeric - uc_priv->gpio_base;/* Allow GPIOs to be numbered from 0 */
@@ -116,7 +116,7 @@ static int dm_gpio_request(struct gpio_desc *desc, const char *label)char *str;int ret; - uc_priv = dev->uclass_priv; + uc_priv =dev_get_uclass_priv (dev);if (uc_priv->name[desc->offset])return -EBUSY ; str =strdup (label);
@@ -195,7 +195,7 @@ int _dm_gpio_free(struct udevice *dev, uint offset)struct gpio_dev_priv *uc_priv;int ret; - uc_priv = dev->uclass_priv; + uc_priv =dev_get_uclass_priv (dev);if (!uc_priv->name[offset])return -ENXIO ;if (gpio_get_ops (dev)->free) {
@@ -232,7 +232,7 @@ int gpio_free(unsigned gpio)static int check_reserved (struct gpio_desc *desc,const char *func) { -struct gpio_dev_priv *uc_priv = desc->dev->uclass_priv; +struct gpio_dev_priv *uc_priv =dev_get_uclass_priv (desc->dev);if (!uc_priv->name[desc->offset]) { printf("%s: %s: error: gpio %s%d not reserved\n",
@@ -402,7 +402,7 @@ const char *gpio_get_bank_info(struct udevice *dev, int *bit_count)struct gpio_dev_priv *priv;/* Must be called on an active device */ - priv = dev->uclass_priv; + priv =dev_get_uclass_priv (dev);assert (priv); *bit_count = priv->gpio_count;
@@ -420,7 +420,7 @@ static const char * const gpio_function[GPIOF_COUNT] = {int get_function (struct udevice *dev,int offset,bool skip_unused,const char **namep) { -struct gpio_dev_priv *uc_priv = dev->uclass_priv; +struct gpio_dev_priv *uc_priv =dev_get_uclass_priv (dev);struct dm_gpio_ops *ops =gpio_get_ops (dev);BUILD_BUG_ON (GPIOF_COUNT !=ARRAY_SIZE (gpio_function));
@@ -468,7 +468,7 @@ int gpio_get_status(struct udevice *dev, int offset, char *buf, int buffsize)BUILD_BUG_ON (GPIOF_COUNT !=ARRAY_SIZE (gpio_function)); *buf =0 ; - priv = dev->uclass_priv; + priv =dev_get_uclass_priv (dev); ret =gpio_get_raw_function (dev, offset,NULL );if (ret <0 )return ret;
@@ -680,7 +680,7 @@ static int gpio_renumber(struct udevice *removed_dev) base =0 ; uclass_foreach_dev(dev, uc) {if (device_active (dev) && dev != removed_dev) { - uc_priv = dev->uclass_priv; + uc_priv =dev_get_uclass_priv (dev); uc_priv->gpio_base = base; base += uc_priv->gpio_count; }
@@ -691,7 +691,7 @@ static int gpio_renumber(struct udevice *removed_dev)static int gpio_post_probe (struct udevice *dev) { -struct gpio_dev_priv *uc_priv = dev->uclass_priv; +struct gpio_dev_priv *uc_priv =dev_get_uclass_priv (dev); uc_priv->name =calloc (uc_priv->gpio_count,sizeof (char *));if (!uc_priv->name)
@@ -702,7 +702,7 @@ static int gpio_post_probe(struct udevice *dev)static int gpio_pre_remove (struct udevice *dev) { -struct gpio_dev_priv *uc_priv = dev->uclass_priv; +struct gpio_dev_priv *uc_priv =dev_get_uclass_priv (dev);int i;for (i =0 ; i < uc_priv->gpio_count; i++) {
drivers/gpio/intel_ich6_gpio.c +1 -1
@@ -151,7 +151,7 @@ static int gpio_ich6_ofdata_to_platdata(struct udevice *dev)static int ich6_gpio_probe (struct udevice *dev) {struct ich6_bank_platdata *plat =dev_get_platdata (dev); -struct gpio_dev_priv *uc_priv = dev->uclass_priv; +struct gpio_dev_priv *uc_priv =dev_get_uclass_priv (dev);struct ich6_bank_priv *bank =dev_get_priv (dev);if (gd->arch.gpio_map) {
drivers/gpio/mxc_gpio.c +1 -1
@@ -266,7 +266,7 @@ static int mxc_gpio_probe(struct udevice *dev) {struct mxc_bank_info *bank =dev_get_priv (dev);struct mxc_gpio_plat *plat =dev_get_platdata (dev); -struct gpio_dev_priv *uc_priv = dev->uclass_priv; +struct gpio_dev_priv *uc_priv =dev_get_uclass_priv (dev);int banknum;char name[18 ], *str;
drivers/gpio/omap_gpio.c +1 -1
@@ -309,7 +309,7 @@ static int omap_gpio_probe(struct udevice *dev) {struct gpio_bank *bank =dev_get_priv (dev);struct omap_gpio_platdata *plat =dev_get_platdata (dev); -struct gpio_dev_priv *uc_priv = dev->uclass_priv; +struct gpio_dev_priv *uc_priv =dev_get_uclass_priv (dev);char name[18 ], *str;sprintf (name,"GPIO%d_" , plat->bank_index);
drivers/gpio/s5p_gpio.c +1 -1
@@ -296,7 +296,7 @@ static const struct dm_gpio_ops gpio_exynos_ops = {static int gpio_exynos_probe (struct udevice *dev) { -struct gpio_dev_priv *uc_priv = dev->uclass_priv; +struct gpio_dev_priv *uc_priv =dev_get_uclass_priv (dev);struct exynos_bank_info *priv = dev->priv;struct exynos_gpio_platdata *plat = dev->platdata;
drivers/gpio/sandbox.c +3 -3
@@ -24,7 +24,7 @@ struct gpio_state {/* Access routines for GPIO state */ static u8 *get_gpio_flags (struct udevice *dev,unsigned offset) { -struct gpio_dev_priv *uc_priv = dev->uclass_priv; +struct gpio_dev_priv *uc_priv =dev_get_uclass_priv (dev);struct gpio_state *state =dev_get_priv (dev);if (offset >= uc_priv->gpio_count) {
@@ -160,7 +160,7 @@ static const struct dm_gpio_ops gpio_sandbox_ops = {static int sandbox_gpio_ofdata_to_platdata (struct udevice *dev) { -struct gpio_dev_priv *uc_priv = dev->uclass_priv; +struct gpio_dev_priv *uc_priv =dev_get_uclass_priv (dev); uc_priv->gpio_count =fdtdec_get_int (gd->fdt_blob, dev->of_offset,"num-gpios" ,0 );
@@ -172,7 +172,7 @@ static int sandbox_gpio_ofdata_to_platdata(struct udevice *dev)static int gpio_sandbox_probe (struct udevice *dev) { -struct gpio_dev_priv *uc_priv = dev->uclass_priv; +struct gpio_dev_priv *uc_priv =dev_get_uclass_priv (dev);if (dev->of_offset ==-1 ) {/* Tell the uclass how many GPIOs we have */
drivers/gpio/sunxi_gpio.c +1 -1
@@ -238,7 +238,7 @@ static char *gpio_bank_name(int bank)static int gpio_sunxi_probe (struct udevice *dev) {struct sunxi_gpio_platdata *plat =dev_get_platdata (dev); -struct gpio_dev_priv *uc_priv = dev->uclass_priv; +struct gpio_dev_priv *uc_priv =dev_get_uclass_priv (dev);/* Tell the uclass how many GPIOs we have */ if (plat) {
drivers/gpio/tegra_gpio.c +1 -1
@@ -295,7 +295,7 @@ static const struct udevice_id tegra_gpio_ids[] = {static int gpio_tegra_probe (struct udevice *dev) { -struct gpio_dev_priv *uc_priv = dev->uclass_priv; +struct gpio_dev_priv *uc_priv =dev_get_uclass_priv (dev);struct tegra_port_info *priv = dev->priv;struct tegra_gpio_platdata *plat = dev->platdata;
drivers/i2c/i2c-uclass.c +3 -3
@@ -330,7 +330,7 @@ int dm_i2c_probe(struct udevice *bus, uint chip_addr, uint chip_flags,int dm_i2c_set_bus_speed (struct udevice *bus,unsigned int speed) {struct dm_i2c_ops *ops =i2c_get_ops (bus); -struct dm_i2c_bus *i2c = bus->uclass_priv; +struct dm_i2c_bus *i2c =dev_get_uclass_priv (bus);int ret;/*
@@ -351,7 +351,7 @@ int dm_i2c_set_bus_speed(struct udevice *bus, unsigned int speed)int dm_i2c_get_bus_speed (struct udevice *bus) {struct dm_i2c_ops *ops =i2c_get_ops (bus); -struct dm_i2c_bus *i2c = bus->uclass_priv; +struct dm_i2c_bus *i2c =dev_get_uclass_priv (bus);if (!ops->get_bus_speed)return i2c->speed_hz;
@@ -432,7 +432,7 @@ int i2c_chip_ofdata_to_platdata(const void *blob, int node,static int i2c_post_probe (struct udevice *dev) { -struct dm_i2c_bus *i2c = dev->uclass_priv; +struct dm_i2c_bus *i2c =dev_get_uclass_priv (dev); i2c->speed_hz =fdtdec_get_int (gd->fdt_blob, dev->of_offset,"clock-frequency" ,100000 );
drivers/i2c/sandbox_i2c.c +1 -1
@@ -50,7 +50,7 @@ static int get_emul(struct udevice *dev, struct udevice **devp,static int sandbox_i2c_xfer (struct udevice *bus,struct i2c_msg *msg,int nmsgs) { -struct dm_i2c_bus *i2c = bus->uclass_priv; +struct dm_i2c_bus *i2c =dev_get_uclass_priv (bus);struct dm_i2c_ops *ops;struct udevice *emul, *dev;bool is_read;
drivers/misc/cros_ec.c +3 -3
@@ -1087,7 +1087,7 @@ static int cros_ec_decode_fdt(const void *blob, int node,#ifdef CONFIG_DM_CROS_EC int cros_ec_register (struct udevice *dev) { -struct cros_ec_dev *cdev = dev->uclass_priv; +struct cros_ec_dev *cdev =dev_get_uclass_priv (dev);const void *blob = gd->fdt_blob;int node = dev->of_offset;char id[MSG_BYTES ];
@@ -1128,7 +1128,7 @@ int cros_ec_init(const void *blob, struct cros_ec_dev **cros_ecp) ret =uclass_get_device (UCLASS_CROS_EC ,0 , &udev);if (ret)return ret; - dev = udev->uclass_priv; + dev =dev_get_uclass_priv (udev);return 0 ;#else int node =0 ;
@@ -1610,7 +1610,7 @@ static int do_cros_ec(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])printf ("Cannot get cros-ec device (err=%d)\n" , ret); return 1; } - dev = udev->uclass_priv; + dev =dev_get_uclass_priv (udev);#else /* Just use the last allocated device; there should be only one */ if (!last_dev) {
drivers/misc/cros_ec_i2c.c +1 -1
@@ -28,7 +28,7 @@ static int cros_ec_i2c_command(struct udevice *udev, uint8_t cmd, int cmd_version, const uint8_t *dout, int dout_len, uint8_t **dinp, int din_len) { - struct cros_ec_dev *dev = udev->uclass_priv; + struct cros_ec_dev *dev = dev_get_uclass_priv(udev);/* version8, cmd8, arglen8, out8[dout_len], csum8 */ int out_bytes = dout_len +4 ;/* response8, arglen8, in8[din_len], checksum8 */
drivers/misc/cros_ec_sandbox.c +1 -1
@@ -470,7 +470,7 @@ static int process_cmd(struct ec_state *ec,#ifdef CONFIG_DM_CROS_EC int cros_ec_sandbox_packet (struct udevice *udev,int out_bytes,int in_bytes) { -struct cros_ec_dev *dev = udev->uclass_priv; +struct cros_ec_dev *dev =dev_get_uclass_priv (udev);struct ec_state *ec =dev_get_priv (dev->dev);#else int cros_ec_sandbox_packet(struct cros_ec_dev *dev, int out_bytes,
drivers/misc/cros_ec_spi.c +2 -2
@@ -23,7 +23,7 @@ DECLARE_GLOBAL_DATA_PTR;int cros_ec_spi_packet (struct udevice *udev,int out_bytes,int in_bytes) { -struct cros_ec_dev *dev = udev->uclass_priv; +struct cros_ec_dev *dev =dev_get_uclass_priv (udev);struct spi_slave *slave =dev_get_parentdata (dev->dev);int rv;
@@ -66,7 +66,7 @@ int cros_ec_spi_command(struct udevice *udev, uint8_t cmd, int cmd_version, const uint8_t *dout, int dout_len, uint8_t **dinp, int din_len) { - struct cros_ec_dev *dev = udev->uclass_priv; + struct cros_ec_dev *dev = dev_get_uclass_priv(udev);struct spi_slave *slave =dev_get_parentdata (dev->dev);int in_bytes = din_len +4 ;/* status, length, checksum, trailer */ uint8_t *out;
drivers/mtd/spi/sf-uclass.c +1 -1
@@ -23,7 +23,7 @@ struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,if (spi_flash_probe_bus_cs (bus, cs, max_hz, spi_mode, &dev))return NULL ; -return dev->uclass_priv; +return dev_get_uclass_priv (dev); }void spi_flash_free (struct spi_flash *flash)
drivers/mtd/spi/sf_probe.c +4 -4
@@ -458,7 +458,7 @@ void spi_flash_free(struct spi_flash *flash)static int spi_flash_std_read (struct udevice *dev,u32 offset,size_t len,void *buf) { -struct spi_flash *flash = dev->uclass_priv; +struct spi_flash *flash =dev_get_uclass_priv (dev);return spi_flash_cmd_read_ops (flash, offset, len, buf); }
@@ -466,14 +466,14 @@ static int spi_flash_std_read(struct udevice *dev, u32 offset, size_t len,int spi_flash_std_write (struct udevice *dev,u32 offset,size_t len,const void *buf) { -struct spi_flash *flash = dev->uclass_priv; +struct spi_flash *flash =dev_get_uclass_priv (dev);return spi_flash_cmd_write_ops (flash, offset, len, buf); }int spi_flash_std_erase (struct udevice *dev,u32 offset,size_t len) { -struct spi_flash *flash = dev->uclass_priv; +struct spi_flash *flash =dev_get_uclass_priv (dev);return spi_flash_cmd_erase_ops (flash, offset, len); }
@@ -484,7 +484,7 @@ int spi_flash_std_probe(struct udevice *dev)struct dm_spi_slave_platdata *plat =dev_get_parent_platdata (dev);struct spi_flash *flash; - flash = dev->uclass_priv; + flash =dev_get_uclass_priv (dev); flash->dev = dev;debug ("%s: slave=%p, cs=%d\n" , __func__, slave, plat->cs);return spi_flash_probe_slave (slave, flash);
drivers/serial/serial-uclass.c +2 -2
@@ -253,7 +253,7 @@ static int serial_post_probe(struct udevice *dev) {struct dm_serial_ops *ops =serial_get_ops (dev);#ifdef CONFIG_DM_STDIO -struct serial_dev_priv *upriv = dev->uclass_priv; +struct serial_dev_priv *upriv =dev_get_uclass_priv (dev);struct stdio_dev sdev;#endif int ret;
@@ -301,7 +301,7 @@ static int serial_post_probe(struct udevice *dev)static int serial_pre_remove (struct udevice *dev) {#ifdef CONFIG_SYS_STDIO_DEREGISTER -struct serial_dev_priv *upriv = dev->uclass_priv; +struct serial_dev_priv *upriv =dev_get_uclass_priv (dev);if (stdio_deregister_dev (upriv->sdev,0 ))return -EPERM ;
drivers/spi/spi-uclass.c +2 -2
@@ -50,7 +50,7 @@ int spi_claim_bus(struct spi_slave *slave)struct udevice *dev = slave->dev;struct udevice *bus = dev->parent;struct dm_spi_ops *ops =spi_get_ops (bus); -struct dm_spi_bus *spi = bus->uclass_priv; +struct dm_spi_bus *spi =dev_get_uclass_priv (bus);int speed;int ret;
@@ -110,7 +110,7 @@ int spi_child_post_bind(struct udevice *dev)int spi_post_probe (struct udevice *bus) { -struct dm_spi_bus *spi = bus->uclass_priv; +struct dm_spi_bus *spi =dev_get_uclass_priv (bus); spi->max_hz =fdtdec_get_int (gd->fdt_blob, bus->of_offset,"spi-max-frequency" ,0 );
include/dm/device.h +10 -0
@@ -238,6 +238,16 @@ void *dev_get_priv(struct udevice *dev);struct udevice *dev_get_parent (struct udevice *child);/** +* dev_get_uclass_priv() - Get the private uclass data for a device +* +* This checks that dev is not NULL, but no other checks for now +* +* @dev Device to check +* @return private uclass data for this device, or NULL if none +*/ +void *dev_get_uclass_priv (struct udevice *dev); + +/** * dev_get_of_data() - get the device tree data used to bind a device * * When a device is bound using a device tree node, it matches a
include/i2c.h +4 -4
@@ -64,8 +64,8 @@ struct dm_i2c_chip {* bus can operate at different speeds (measured in Hz, typically 100KHz * or 400KHz). * -* To obtain this structure, use bus->uclass_priv where bus is the I2C -* bus udevice. +* To obtain this structure, use dev_get_uclass_priv(bus) where bus is the +* I2C bus udevice. * * @speed_hz: Bus speed in hertz (typically 100000) */
@@ -340,7 +340,7 @@ struct dm_i2c_ops {* The bus speed value will be updated by the uclass if this function * does not return an error. This method is optional - if it is not * provided then the driver can read the speed from -* bus->uclass_priv->speed_hz +* dev_get_uclass_priv(bus)->speed_hz * * @bus: Bus to adjust * @speed: Requested speed in Hz
@@ -354,7 +354,7 @@ struct dm_i2c_ops {* Normally this can be provided by the uclass, but if you want your * driver to check the bus speed by looking at the hardware, you can * implement that here. This method is optional. This method would -* normally be expected to return bus->uclass_priv->speed_hz. +* normally be expected to return dev_get_uclass_priv(bus)->speed_hz. * * @bus: Bus to check * @return speed of selected I2C bus in Hz, -ve on error
test/dm/core.c +1 -1
@@ -179,7 +179,7 @@ static int dm_test_autoprobe(struct dm_test_state *dms)ut_assertok (uclass_find_device (UCLASS_TEST , i, &dev));ut_assert (dev); - priv = dev->uclass_priv; + priv =dev_get_uclass_priv (dev);ut_assert (priv);ut_asserteq (expected_base_add, priv->base_add);
test/dm/test-uclass.c +2 -2
@@ -47,7 +47,7 @@ static int test_post_probe(struct udevice *dev)struct udevice *prev =list_entry (dev->uclass_node.prev, struct udevice, uclass_node); -struct dm_test_uclass_perdev_priv *priv = dev->uclass_priv; +struct dm_test_uclass_perdev_priv *priv =dev_get_uclass_priv (dev);struct uclass *uc = dev->uclass; dm_testdrv_op_count[DM_TEST_OP_POST_PROBE ]++;
@@ -58,7 +58,7 @@ static int test_post_probe(struct udevice *dev)return 0 ;if (&prev->uclass_node != &uc->dev_head) {struct dm_test_uclass_perdev_priv *prev_uc_priv - = prev->uclass_priv; + =dev_get_uclass_priv (prev);struct dm_test_pdata *pdata = prev->platdata;ut_assert (pdata);
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH v2 8/22 dm: core: Add dev_get_uclass_priv() to access uclass private data
Quoted 29 lines · Simon Glass
Add a convenience function to access the private data that a uclass stores for each of its devices. Convert over most existing uses for consistency and to provide an example for others.
Signed-off-by Simon Glass <[email protected]>---
Changes in v2: None
common/cmd_sf.c | 2 +- common/cros_ec.c | 2 +- drivers/core/device.c | 10 ++++++++++ drivers/gpio/at91_gpio.c | 2 +- drivers/gpio/bcm2835_gpio.c | 2 +- drivers/gpio/gpio-uclass.c | 22 +++++++++++----------- drivers/gpio/intel_ich6_gpio.c | 2 +- drivers/gpio/mxc_gpio.c | 2 +- drivers/gpio/omap_gpio.c | 2 +- drivers/gpio/s5p_gpio.c | 2 +- drivers/gpio/sandbox.c | 6 +++--- drivers/gpio/sunxi_gpio.c | 2 +- drivers/gpio/tegra_gpio.c | 2 +- drivers/i2c/i2c-uclass.c | 6 +++--- drivers/i2c/sandbox_i2c.c | 2 +- drivers/misc/cros_ec.c | 6 +++--- drivers/misc/cros_ec_i2c.c | 2 +- drivers/misc/cros_ec_sandbox.c | 2 +- drivers/misc/cros_ec_spi.c | 4 ++-- drivers/mtd/spi/sf-uclass.c | 2 +-
Quoted 8 lines
drivers/mtd/spi/sf_probe.c | 8 ++++---- drivers/serial/serial-uclass.c | 4 ++-- drivers/spi/spi-uclass.c | 4 ++-- include/dm/device.h | 10 ++++++++++ include/i2c.h | 8 ++++---- test/dm/core.c | 2 +- test/dm/test-uclass.c | 4 ++-- 27 files changed, 71 insertions(+), 51 deletions(-)
Applied to u-boot-dm/next.
PATCH v2 9/22 dm: core: Mark device as active before calling its probe() method
In reply to Simon GlassAt present the device is not active when the probe() method is called. But some probe() methods want to set up the device and this can involve accessing it through normal methods. For example a PCI bus may wish to set up its PCI parameters using calls to pci_hose_write_config_dword() and similar.
At present this does not work because every such call within the probe() method sees that the device is not active and attempts to probe it.
Already we mark the device as probed before calling the uclass post_probe() method. This is a subtle change but I believe the new approach is better. Since the scope of the change is only the probe() method and all its callees it should still be within the control of the board author.
---
Changes in v2: None
drivers/core/device.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/core/device.c +4 -3
@@ -243,14 +243,15 @@ int device_probe_child(struct udevice *dev, void *parent_priv) goto fail; } + dev->flags |=DM_FLAG_ACTIVATED ;if (drv->probe) { ret = drv->probe (dev); -if (ret) +if (ret) { + dev->flags &= ~DM_FLAG_ACTIVATED ; goto fail; + } } - dev->flags |=DM_FLAG_ACTIVATED ; - ret =uclass_post_probe_device (dev);if (ret) { dev->flags &= ~DM_FLAG_ACTIVATED ;
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH v2 9/22 dm: core: Mark device as active before calling its probe() method
Quoted 14 lines · Simon Glass
At present the device is not active when the
probe()method is called. But someprobe()methods want to set up the device and this can involve accessing it through normal methods. For example a PCI bus may wish to set up its PCI parameters using calls topci_hose_write_config_dword()and similar.At present this does not work because every such call within the
probe()method sees that the device is not active and attempts to probe it.Already we mark the device as probed before calling the uclass
post_probe()method. This is a subtle change but I believe the new approach is better. Since the scope of the change is only theprobe()method and all its callees it should still be within the control of the board author.
Quoted 7 lines
Signed-off-by Simon Glass <[email protected]>---
Changes in v2: None
drivers/core/device.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
Applied to u-boot-dm/next.
PATCH v2 10/22 dm: core: Add a uclass pre_probe() method for devices
In reply to Simon GlassSome uclasses want to set up a device before it is probed. Add a method for this.
An example is with PCI, where a PCI uclass wants to set up its private data for later use. This allows the device's uclass() method to make calls whcih use that data (for example, read PCI memory regions from device tree, set up bus numbers).
---
Changes in v2: None
drivers/core/device.c | 2 +- drivers/core/uclass.c | 10 +++++++++- include/dm/test.h | 1 + include/dm/uclass-internal.h | 7 ++++--- include/dm/uclass.h | 2 ++ test/dm/core.c | 7 ++++++- test/dm/test-uclass.c | 12 ++++++++++++ 7 files changed, 35 insertions(+), 6 deletions(-)
drivers/core/device.c +1 -1
@@ -227,7 +227,7 @@ int device_probe_child(struct udevice *dev, void *parent_priv) } dev->seq = seq; - ret =uclass_pre_probe_child (dev); + ret =uclass_pre_probe_device (dev);if (ret) goto fail;
drivers/core/uclass.c +9 -1
@@ -391,9 +391,17 @@ int uclass_resolve_seq(struct udevice *dev)return seq; } -int uclass_pre_probe_child (struct udevice *dev) +int uclass_pre_probe_device (struct udevice *dev) {struct uclass_driver *uc_drv; +int ret; + + uc_drv = dev->uclass->uc_drv; +if (uc_drv->pre_probe) { + ret = uc_drv->pre_probe (dev); +if (ret) +return ret; + }if (!dev->parent)return 0 ;
include/dm/test.h +1 -0
@@ -44,6 +44,7 @@ enum {/* For uclass */ DM_TEST_OP_POST_BIND ,DM_TEST_OP_PRE_UNBIND , +DM_TEST_OP_PRE_PROBE ,DM_TEST_OP_POST_PROBE ,DM_TEST_OP_PRE_REMOVE , DM_TEST_OP_INIT,
include/dm/uclass-internal.h +4 -3
@@ -44,15 +44,16 @@ int uclass_bind_device(struct udevice *dev);int uclass_unbind_device (struct udevice *dev);/** -* uclass_pre_probe_child() - Deal with a child that is about to be probed +* uclass_pre_probe_device() - Deal with a device that is about to be probed * * Perform any pre-processing that is needed by the uclass before it can be -* probed. +* probed. This includes the uclass' pre-probe() method and the parent +* uclass' child_pre_probe() method. * * @dev: Pointer to the device * #return 0 on success, -ve on error */ -int uclass_pre_probe_child (struct udevice *dev); +int uclass_pre_probe_device (struct udevice *dev);/** * uclass_post_probe_device() - Deal with a device that has just been probed
include/dm/uclass.h +2 -0
@@ -53,6 +53,7 @@ struct udevice;* @id: ID number of this uclass * @post_bind: Called after a new device is bound to this uclass * @pre_unbind: Called before a device is unbound from this uclass +* @pre_probe: Called before a new device is probed * @post_probe: Called after a new device is probed * @pre_remove: Called before a device is removed * @child_post_bind: Called after a child is bound to a device in this uclass
@@ -80,6 +81,7 @@ struct uclass_driver {enum uclass_id id;int (*post_bind)(struct udevice *dev);int (*pre_unbind)(struct udevice *dev); +int (*pre_probe)(struct udevice *dev);int (*post_probe)(struct udevice *dev);int (*pre_remove)(struct udevice *dev);int (*child_post_bind)(struct udevice *dev);
test/dm/core.c +6 -1
@@ -141,6 +141,7 @@ static int dm_test_autoprobe(struct dm_test_state *dms)ut_assert (uc);ut_asserteq (1 , dm_testdrv_op_count[DM_TEST_OP_INIT ]); +ut_asserteq (0 , dm_testdrv_op_count[DM_TEST_OP_PRE_PROBE ]);ut_asserteq (0 , dm_testdrv_op_count[DM_TEST_OP_POST_PROBE ]);/* The root device should not be activated until needed */
@@ -167,8 +168,12 @@ static int dm_test_autoprobe(struct dm_test_state *dms)ut_assert (dms->root->flags &DM_FLAG_ACTIVATED ); } -/* Our 3 dm_test_infox children should be passed to post_probe */ +/* +* Our 3 dm_test_info children should be passed to pre_probe and +* post_probe +*/ ut_asserteq (3 , dm_testdrv_op_count[DM_TEST_OP_POST_PROBE ]); +ut_asserteq (3 , dm_testdrv_op_count[DM_TEST_OP_PRE_PROBE ]);/* Also we can check the per-device data */ expected_base_add =0 ;
test/dm/test-uclass.c +12 -0
@@ -42,6 +42,17 @@ static int test_pre_unbind(struct udevice *dev)return 0 ; } +static int test_pre_probe (struct udevice *dev) +{ +struct dm_test_uclass_perdev_priv *priv =dev_get_uclass_priv (dev); + + dm_testdrv_op_count[DM_TEST_OP_PRE_PROBE ]++; +ut_assert (priv); +ut_assert (!device_active (dev)); + +return 0 ; +} +static int test_post_probe (struct udevice *dev) { struct udevice *prev = list_entry(dev->uclass_node.prev,
@@ -96,6 +107,7 @@ UCLASS_DRIVER(test) = { .id = UCLASS_TEST, .post_bind = test_post_bind, .pre_unbind = test_pre_unbind, + .pre_probe = test_pre_probe, .post_probe = test_post_probe, .pre_remove = test_pre_remove, .init = test_init,
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH v2 10/22 dm: core: Add a uclass pre_probe() method for devices
Quoted 8 lines · Simon Glass
Some uclasses want to set up a device before it is probed. Add a method for this.
An example is with PCI, where a PCI uclass wants to set up its private data for later use. This allows the device's
uclass()method to make calls whcih use that data (for example, read PCI memory regions from device tree, set up bus numbers).
Quoted 4 lines
Signed-off-by Simon Glass <[email protected]>---
Changes in v2: None
Applied to u-boot-dm/next.
PATCH v2 11/22 dm: Show both allocated and requested seq numbers in 'dm uclass'
In reply to Simon GlassBoth of these values are useful for understanding what is going on, so show them both.
The requested number comes from a device tree alias. The allocated one is set up when the device is activated, and is unique throughout the uclass.
---
Changes in v2: None
test/dm/cmd_dm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
test/dm/cmd_dm.c +2 -2
@@ -77,8 +77,8 @@ static void dm_display_line(struct udevice *dev)printf ("- %c %s @ %08lx" , dev->flags &DM_FLAG_ACTIVATED ?'*' :' ' , dev->name, (ulong )map_to_sysmem (dev)); -if (dev->req_seq !=-1 ) -printf (", %d" , dev->req_seq); +if (dev->seq !=-1 || dev->req_seq !=-1 ) +printf (", seq-%d, (req=%d)" , dev->seq, dev->req_seq);puts ("\n" ); }
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH v2 11/22 dm: Show both allocated and requested seq numbers in 'dm uclass'
Quoted 6 lines · Simon Glass
Both of these values are useful for understanding what is going on, so show them both.
The requested number comes from a device tree alias. The allocated one is set up when the device is activated, and is unique throughout the uclass.
Quoted 7 lines
Signed-off-by Simon Glass <[email protected]>---
Changes in v2: None
test/dm/cmd_dm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Applied to u-boot-dm/next.
PATCH v2 12/22 dm: pci: Move common PCI functions into their own file
In reply to Simon GlassDriver model will share many functions with the existing PCI implementation. Move these into their own file to avoid duplication and confusion.
---
Changes in v2: None
drivers/pci/Makefile | 2 +- drivers/pci/pci.c | 281 +-------------------------------------------- drivers/pci/pci_common.c | 292 +++++++++++++++++++++++++++++++++++++++++++++++ include/pci.h | 14 +++ 4 files changed, 313 insertions(+), 276 deletions(-) create mode 100644 drivers/pci/pci_common.c
drivers/pci/Makefile +1 -1
@@ -6,7 +6,7 @@ # obj-$(CONFIG_FSL_PCI_INIT) += fsl_pci_init.o -obj-$(CONFIG_PCI) += pci.o pci_auto.o pci_rom.o +obj-$(CONFIG_PCI) += pci.o pci_common.o pci_auto.o pci_rom.o obj-$(CONFIG_PCI_INDIRECT_BRIDGE) += pci_indirect.o obj-$(CONFIG_PCI_GT64120) += pci_gt64120.o obj-$(CONFIG_PCI_MSC01) += pci_msc01.o
drivers/pci/pci.c +6 -275
315 lines not on this page · raw message
drivers/pci/pci_common.c new file +292 -0
292 lines not on this page · raw message
include/pci.h +14 -0
@@ -705,5 +705,19 @@ u32 pci_read_bar32(struct pci_controller *hose, pci_dev_t dev, int barnum);*/ int pciauto_setup_rom (struct pci_controller *hose,pci_dev_t dev); +/** +* pci_hose_find_devices() - Find devices by vendor/device ID +* +* @hose: PCI hose to search +* @busnum: Bus number to search +* @ids: PCI vendor/device IDs to look for, terminated by 0, 0 record +* @indexp: Pointer to device index to find. To find the first matching +* device, pass 0; to find the second, pass 1, etc. This +* parameter is decremented for each non-matching device so +* can be called repeatedly. +*/ +pci_dev_t pci_hose_find_devices (struct pci_controller *hose,int busnum, +struct pci_device_id *ids,int *indexp); +#endif /* __ASSEMBLY__ */ #endif /* _PCI_H */
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH v2 12/22 dm: pci: Move common PCI functions into their own file
Quoted 6 lines · Simon Glass
Driver model will share many functions with the existing PCI implementation. Move these into their own file to avoid duplication and confusion.
Signed-off-by Simon Glass <[email protected]>---
Quoted 8 lines
Changes in v2: None
drivers/pci/Makefile | 2 +- drivers/pci/pci.c | 281 +-------------------------------------------- drivers/pci/pci_common.c | 292 +++++++++++++++++++++++++++++++++++++++++++++++ include/pci.h | 14 +++ 4 files changed, 313 insertions(+), 276 deletions(-) create mode 100644 drivers/pci/pci_common.c
Applied to u-boot-dm/next.
PATCH v2 13/22 dm: pci: Add a uclass for PCI
In reply to Simon GlassAdd a uclass for PCI controllers and a generic one for PCI devices. Adjust the 'pci' command and the existing PCI support to work with this new uclass. Keep most of the compatibility code in a separate file so that it can be removed one day.
TODO: Add more header file comments to the new parts of pci.h
---
Changes in v2: None
common/board_r.c | 2 + common/cmd_pci.c | 14 +- doc/driver-model/pci-info.txt | 70 +++++ drivers/pci/Kconfig | 12 + drivers/pci/Makefile | 8 +- drivers/pci/pci-uclass.c | 639 ++++++++++++++++++++++++++++++++++++++++++ drivers/pci/pci_auto.c | 16 +- drivers/pci/pci_compat.c | 43 +++ include/dm/uclass-id.h | 2 + include/pci.h | 289 ++++++++++++++++++- 10 files changed, 1081 insertions(+), 14 deletions(-) create mode 100644 doc/driver-model/pci-info.txt create mode 100644 drivers/pci/pci-uclass.c create mode 100644 drivers/pci/pci_compat.c
common/board_r.c +2 -0
@@ -227,7 +227,9 @@ static int initr_unlock_ram_in_cache(void)#ifdef CONFIG_PCI static int initr_pci (void ) { +#ifndef CONFIG_DM_PCI pci_init (); +#endif return 0 ; }
common/cmd_pci.c +11 -3
@@ -48,6 +48,7 @@ void pciinfo(int BusNum, int ShortPCIListing)unsigned char HeaderType;unsigned short VendorID;pci_dev_t dev; +int ret;if (!hose)return ;
@@ -74,7 +75,10 @@ void pciinfo(int BusNum, int ShortPCIListing)if (pci_skip_dev (hose, dev))continue ; -pci_read_config_word (dev,PCI_VENDOR_ID , &VendorID); + ret =pci_read_config_word (dev,PCI_VENDOR_ID , + &VendorID); +if (ret) + goto error;if ((VendorID ==0xFFFF ) || (VendorID ==0x0000 ))continue ;
@@ -91,8 +95,12 @@ void pciinfo(int BusNum, int ShortPCIListing) BusNum, Device, Function);pci_header_show (dev); } - } - } + } + } + +return ; +error: +printf ("Cannot read bus configuration: %d\n" , ret); }
doc/driver-model/pci-info.txt new file +70 -0
70 lines not on this page · raw message
drivers/pci/Kconfig +12 -0
@@ -0,0 +1,12 @@ +menu "PCI" + +config DM_PCI + bool "Enable driver mode for PCI" + depends on DM + help + Use driver model for PCI. Driver model is the new method for + orgnising devices in U-Boot. For PCI, driver model keeps track of + available PCI devices, allows scanning of PCI buses and provides + device configuration support. + +endmenu
drivers/pci/Makefile +7 -1
@@ -5,8 +5,14 @@ # SPDX-License-Identifier: GPL-2.0+ # +ifneq ($(CONFIG_DM_PCI),) +obj-$(CONFIG_PCI) += pci-uclass.o pci_compat.o +else +obj-$(CONFIG_PCI) += pci.o +endif +obj-$(CONFIG_PCI) += pci_common.o pci_auto.o pci_rom.o + obj-$(CONFIG_FSL_PCI_INIT) += fsl_pci_init.o -obj-$(CONFIG_PCI) += pci.o pci_common.o pci_auto.o pci_rom.o obj-$(CONFIG_PCI_INDIRECT_BRIDGE) += pci_indirect.o obj-$(CONFIG_PCI_GT64120) += pci_gt64120.o obj-$(CONFIG_PCI_MSC01) += pci_msc01.o
drivers/pci/pci-uclass.c new file +639 -0
639 lines not on this page · raw message
drivers/pci/pci_auto.c +13 -3
@@ -432,13 +432,20 @@ int pciauto_config_device(struct pci_controller *hose, pci_dev_t dev)switch (class) {case PCI_CLASS_BRIDGE_PCI : - hose->current_busno++; +DEBUGF ("PCI Autoconfig: Found P2P bridge, device %d\n" , +PCI_DEV (dev)); +pciauto_setup_device (hose, dev,2 , hose->pci_mem, hose->pci_prefetch, hose->pci_io); -DEBUGF ("PCI Autoconfig: Found P2P bridge, device %d\n" ,PCI_DEV (dev)); - +#ifdef CONFIG_DM_PCI + n =dm_pci_hose_probe_bus (hose, dev); +if (n <0 ) +return n; + sub_bus = (unsigned int )n; +#else /* Passing in current_busno allows for sibling P2P bridges */ + hose->current_busno++;pciauto_prescan_setup_bridge (hose, dev, hose->current_busno);/* * need to figure out if this is a subordinate bridge on the bus
@@ -451,6 +458,7 @@ int pciauto_config_device(struct pci_controller *hose, pci_dev_t dev)pciauto_postscan_setup_bridge (hose, dev, sub_bus); sub_bus = hose->current_busno; +#endif break ;case PCI_CLASS_STORAGE_IDE :
@@ -475,7 +483,9 @@ int pciauto_config_device(struct pci_controller *hose, pci_dev_t dev)DEBUGF ("PCI Autoconfig: Found P2CardBus bridge, device %d\n" ,PCI_DEV (dev)); +#ifndef CONFIG_DM_PCI hose->current_busno++; +#endif break ;#if defined(CONFIG_PCIAUTO_SKIP_HOST_BRIDGE )
drivers/pci/pci_compat.c new file +43 -0
43 lines not on this page · raw message
include/dm/uclass-id.h +2 -0
@@ -34,6 +34,8 @@ enum uclass_id {UCLASS_I2C_GENERIC ,/* Generic I2C device */ UCLASS_I2C_EEPROM ,/* I2C EEPROM device */ UCLASS_MOD_EXP ,/* RSA Mod Exp device */ +UCLASS_PCI ,/* PCI bus */ +UCLASS_PCI_GENERIC ,/* Generic PCI bus device */ UCLASS_COUNT , UCLASS_INVALID = -1,
include/pci.h +282 -7
348 lines not on this page · raw message
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH v2 13/22 dm: pci: Add a uclass for PCI
Quoted 12 lines · Simon Glass
Add a uclass for PCI controllers and a generic one for PCI devices. Adjust the 'pci' command and the existing PCI support to work with this new uclass. Keep most of the compatibility code in a separate file so that it can be removed one day.
TODO: Add more header file comments to the new parts of
pci.hSigned-off-by Simon Glass <[email protected]>---
Changes in v2: None
Quoted 14 lines
common/board_r.c | 2 + common/cmd_pci.c | 14 +- doc/driver-model/pci-info.txt | 70 +++++ drivers/pci/Kconfig | 12 + drivers/pci/Makefile | 8 +- drivers/pci/pci-uclass.c | 639 ++++++++++++++++++++++++++++++++++++++++++ drivers/pci/pci_auto.c | 16 +- drivers/pci/pci_compat.c | 43 +++ include/dm/uclass-id.h | 2 + include/pci.h | 289 ++++++++++++++++++- 10 files changed, 1081 insertions(+), 14 deletions(-) create mode 100644 doc/driver-model/pci-info.txt create mode 100644 drivers/pci/pci-uclass.c create mode 100644 drivers/pci/pci_compat.c
Applied to u-boot-dm/next.
PATCH v2 14/22 dm: sandbox: pci: Add PCI support for sandbox
In reply to Simon GlassAdd the required header information, device tree nodes and I/O accessor functions to support PCI on sandbox. All devices are emulated by drivers which can be added as required for testing or development.
---
Changes in v2: None
arch/sandbox/Kconfig | 7 ++ arch/sandbox/cpu/cpu.c | 37 +++++++- arch/sandbox/dts/sandbox.dts | 20 +++++ arch/sandbox/include/asm/io.h | 16 +++- arch/sandbox/include/asm/processor.h | 12 +++ arch/sandbox/include/asm/test.h | 7 +- arch/sandbox/include/asm/u-boot-sandbox.h | 48 +++++++++++ arch/sandbox/lib/Makefile | 2 +- arch/sandbox/lib/pci_io.c | 138 ++++++++++++++++++++++++++++++ 9 files changed, 280 insertions(+), 7 deletions(-) create mode 100644 arch/sandbox/include/asm/processor.h create mode 100644 arch/sandbox/lib/pci_io.c
arch/sandbox/Kconfig +7 -0
@@ -34,4 +34,11 @@ config DM_I2C config DM_TEST default y +config PCI + bool "PCI support" + help + Enable support for PCI (Peripheral Interconnect Bus), a type of bus + used on some devices to allow the CPU to communicate with its + peripherals. + endmenu
arch/sandbox/cpu/cpu.c +36 -1
@@ -2,7 +2,7 @@* Copyright (c) 2011 The Chromium OS Authors. * SPDX-License-Identifier: GPL-2.0+ */ - +#define DEBUG #include <common.h> #include <dm/root.h> #include <os.h>
@@ -10,6 +10,13 @@DECLARE_GLOBAL_DATA_PTR ; +/* Enable access to PCI memory with map_sysmem() */ +static bool enable_pci_map; + +/* Last device that was mapped into memory, and length of mapping */ +static struct udevice *map_dev; +unsigned long map_len; +void reset_cpu (ulong ignored) {if (state_uninit ())
@@ -59,9 +66,37 @@ int cleanup_before_linux(void)void *map_physmem (phys_addr_t paddr,unsigned long len,unsigned long flags) { +#ifdef CONFIG_PCI +unsigned long plen = len; +void *ptr; + + map_dev =NULL ; +if (enable_pci_map && !pci_map_physmem (paddr, &len, &map_dev, &ptr)) { +if (plen != len) { +printf ("%s: Warning: partial map at %x, wanted %lx, got %lx\n" , + __func__, paddr, len, plen); + } + map_len = len; +return ptr; + } +#endif +return (void *)(gd->arch.ram_buf + paddr); } +void unmap_physmem (const void *vaddr,unsigned long flags) +{ +if (map_dev) { +pci_unmap_physmem (vaddr, map_len, map_dev); + map_dev =NULL ; + } +} + +void sandbox_set_enable_pci_map (int enable) +{ + enable_pci_map = enable; +} +phys_addr_t map_to_sysmem (const void *ptr) {return (u8 *)ptr - gd->arch.ram_buf;
arch/sandbox/dts/sandbox.dts +20 -0
@@ -4,6 +4,10 @@ #address-cells = <1>; #size-cells = <1>; + aliases { + pci0 = &pci; + }; + chosen { stdout-path = "/serial"; };
@@ -181,4 +185,20 @@ }; }; + pci: pci-controller { + compatible = "sandbox,pci"; + device_type = "pci"; + #address-cells = <3>; + #size-cells = <2>; + ranges = <0x02000000 0 0x10000000 0x10000000 0 0x2000 + 0x01000000 0 0x20000000 0x20000000 0 0x2000>; + pci at 1f,0 { + compatible = "pci-generic"; + reg = <0xf800 0 0 0 0>; + emul at 1f,0 { + compatible = "sandbox,swap-case"; + }; + }; + }; + };
arch/sandbox/include/asm/io.h +12 -4
@@ -22,10 +22,7 @@ void *map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags);/* * Take down a mapping set up by map_physmem(). */ -static inline void unmap_physmem (void *vaddr,unsigned long flags) -{ - -} +void unmap_physmem (const void *vaddr,unsigned long flags);/* For sandbox, we want addresses to point into our RAM buffer */ static inline void *map_sysmem (phys_addr_t paddr,unsigned long len)
@@ -33,8 +30,10 @@ static inline void *map_sysmem(phys_addr_t paddr, unsigned long len)return map_physmem (paddr, len,MAP_WRBACK ); } +/* Remove a previous mapping */ static inline void unmap_sysmem (const void *vaddr) { +unmap_physmem (vaddr,MAP_WRBACK ); }/* Map from a pointer to our RAM buffer */
@@ -48,6 +47,15 @@ phys_addr_t map_to_sysmem(const void *ptr);#define writew (v, addr)#define writel (v, addr) +/* I/O access functions */ +int inl (unsigned int addr); +int inw (unsigned int addr); +int inb (unsigned int addr); + +void outl (unsigned int value,unsigned int addr); +void outw (unsigned int value,unsigned int addr); +void outb (unsigned int value,unsigned int addr); +#include <iotrace.h> #endif
arch/sandbox/include/asm/processor.h new file +12 -0
@@ -0,0 +1,12 @@ +/* +* Copyright (c) 2014 Google, Inc +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#ifndef _ASM_PROCESSOR_H +#define _ASM_PROCESSOR_H + +/* This file is required for PCI */ + +#endif
arch/sandbox/include/asm/test.h +6 -1
@@ -10,7 +10,12 @@#define __ASM_TEST_H/* The sandbox driver always permits an I2C device with this address */ -#define SANDBOX_I2C_TEST_ADDR 0x59 +#define SANDBOX_I2C_TEST_ADDR 0x59 + +#define SANDBOX_PCI_VENDOR_ID 0x1234 +#define SANDBOX_PCI_DEVICE_ID 0x5678 +#define SANDBOX_PCI_CLASS_CODE PCI_CLASS_CODE_COMM +#define SANDBOX_PCI_CLASS_SUB_CODE PCI_CLASS_SUB_CODE_COMM_SERIALenum sandbox_i2c_eeprom_test_mode {SIE_TEST_MODE_NONE ,
arch/sandbox/include/asm/u-boot-sandbox.h +48 -0
52 lines not on this page · raw message
arch/sandbox/lib/Makefile +1 -1
@@ -7,5 +7,5 @@ # SPDX-License-Identifier: GPL-2.0+ # - obj-y += interrupts.o +obj-$(CONFIG_PCI) += pci_io.o
arch/sandbox/lib/pci_io.c new file +138 -0
138 lines not on this page · raw message
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH v2 14/22 dm: sandbox: pci: Add PCI support for sandbox
Quoted 8 lines · Simon Glass
Add the required header information, device tree nodes and I/O accessor functions to support PCI on sandbox. All devices are emulated by drivers which can be added as required for testing or development.
Signed-off-by Simon Glass <[email protected]>---
Changes in v2: None
Applied to u-boot-dm/next.
PATCH v2 15/22 dm: sandbox: Add a simple PCI driver
In reply to Simon GlassAdd a driver which can access emulations of devices and make them available in sandbox.
---
Changes in v2: None
drivers/pci/Kconfig | 10 ++++++ drivers/pci/Makefile | 1 + drivers/pci/pci_sandbox.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 drivers/pci/pci_sandbox.c
drivers/pci/Kconfig +10 -0
@@ -9,4 +9,14 @@ config DM_PCI available PCI devices, allows scanning of PCI buses and provides device configuration support. +config PCI_SANDBOX + bool "Sandbox PCI support" + depends on SANDBOX && DM_PCI + help + Support PCI on sandbox, as an emulated bus. This permits testing of + PCI feature such as bus scanning, device configuration and device + access. The available (emulated) devices are defined statically in + the device tree but the normal PCI scan technique is used to find + then. + endmenu
drivers/pci/Makefile +1 -0
@@ -7,6 +7,7 @@ ifneq ($(CONFIG_DM_PCI),) obj-$(CONFIG_PCI) += pci-uclass.o pci_compat.o +obj-$(CONFIG_PCI_SANDBOX) += pci_sandbox.o else obj-$(CONFIG_PCI) += pci.o endif
drivers/pci/pci_sandbox.c new file +79 -0
79 lines not on this page · raw message
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH v2 15/22 dm: sandbox: Add a simple PCI driver
Quoted 6 lines · Simon Glass
Add a driver which can access emulations of devices and make them available in sandbox.
Signed-off-by Simon Glass <[email protected]>---
Quoted 7 lines
Changes in v2: None
drivers/pci/Kconfig | 10 ++++++ drivers/pci/Makefile | 1 + drivers/pci/pci_sandbox.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 drivers/pci/pci_sandbox.c
Applied to u-boot-dm/next.
PATCH v2 16/22 dm: sandbox: pci: Add a PCI emulation uclass
In reply to Simon GlassSince sandbox does not have real devices (unless it borrows those from the host) it must use emulations. Provide a uclass which permits PCI operations to be passed through to an emulation device.
---
Changes in v2: None
drivers/pci/Makefile | 1 + drivers/pci/pci-emul-uclass.c | 67 ++++++++++++++++++++++++++ include/dm/uclass-id.h | 1 + include/pci.h | 108 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 177 insertions(+) create mode 100644 drivers/pci/pci-emul-uclass.c
drivers/pci/Makefile +1 -0
@@ -8,6 +8,7 @@ ifneq ($(CONFIG_DM_PCI),) obj-$(CONFIG_PCI) += pci-uclass.o pci_compat.o obj-$(CONFIG_PCI_SANDBOX) += pci_sandbox.o +obj-$(CONFIG_SANDBOX) += pci-emul-uclass.o else obj-$(CONFIG_PCI) += pci.o endif
drivers/pci/pci-emul-uclass.c new file +67 -0
67 lines not on this page · raw message
include/dm/uclass-id.h +1 -0
@@ -20,6 +20,7 @@ enum uclass_id {UCLASS_TEST_BUS ,UCLASS_SPI_EMUL ,/* sandbox SPI device emulator */ UCLASS_I2C_EMUL ,/* sandbox I2C device emulator */ +UCLASS_PCI_EMUL ,/* sandbox PCI device emulator */ UCLASS_SIMPLE_BUS,/* U-Boot uclasses start here */
include/pci.h +108 -0
114 lines not on this page · raw message
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH v2 16/22 dm: sandbox: pci: Add a PCI emulation uclass
Quoted 7 lines · Simon Glass
Since sandbox does not have real devices (unless it borrows those from the host) it must use emulations. Provide a uclass which permits PCI operations to be passed through to an emulation device.
Signed-off-by Simon Glass <[email protected]>---
Quoted 8 lines
Changes in v2: None
drivers/pci/Makefile | 1 + drivers/pci/pci-emul-uclass.c | 67 ++++++++++++++++++++++++++ include/dm/uclass-id.h | 1 + include/pci.h | 108 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 177 insertions(+) create mode 100644 drivers/pci/pci-emul-uclass.c
Applied to u-boot-dm/next.
PATCH v2 17/22 dm: sandbox: Add a emulated PCI device as an example
In reply to Simon GlassThis device sits on the sandbox PCI bus and provides a case-swapping service for sandbox. It illustrates the use of both PCI I/O and PCI memory accesses.
---
Changes in v2: None
drivers/misc/Makefile | 1 + drivers/misc/swap_case.c | 285 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 286 insertions(+) create mode 100644 drivers/misc/swap_case.c
drivers/misc/Makefile +1 -0
@@ -26,5 +26,6 @@ obj-$(CONFIG_SANDBOX) += i2c_eeprom_emul.o endif obj-$(CONFIG_SMSC_LPC47M) += smsc_lpc47m.o obj-$(CONFIG_STATUS_LED) += status_led.o +obj-$(CONFIG_SANDBOX) += swap_case.o obj-$(CONFIG_TWL4030_LED) += twl4030_led.o obj-$(CONFIG_FSL_IFC) += fsl_ifc.o
drivers/misc/swap_case.c new file +285 -0
285 lines not on this page · raw message
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH v2 17/22 dm: sandbox: Add a emulated PCI device as an example
Quoted 5 lines · Simon Glass
This device sits on the sandbox PCI bus and provides a case-swapping service for sandbox. It illustrates the use of both PCI I/O and PCI memory accesses.
Signed-off-by Simon Glass <[email protected]>
Quoted 8 lines
---
Changes in v2: None
drivers/misc/Makefile | 1 + drivers/misc/swap_case.c | 285 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 286 insertions(+) create mode 100644 drivers/misc/swap_case.c
Applied to u-boot-dm/next.
PATCH v2 18/22 dm: sandbox: pci: Enable PCI for sandbox
In reply to Simon GlassEnable PCI options so that sandbox can be used for testing this bus with driver model.
---
Changes in v2: None
configs/sandbox_defconfig | 3 +++ include/configs/sandbox.h | 4 ++++ 2 files changed, 7 insertions(+)
configs/sandbox_defconfig +3 -0
@@ -12,3 +12,6 @@ CONFIG_DM_CROS_EC=y CONFIG_CROS_EC_SANDBOX=y CONFIG_CROS_EC_KEYB=y CONFIG_CMD_CROS_EC=y +CONFIG_PCI=y +CONFIG_DM_PCI=y +CONFIG_PCI_SANDBOX=y
include/configs/sandbox.h +4 -0
@@ -34,6 +34,10 @@#define CONFIG_CMD_FDT #define CONFIG_ANDROID_BOOT_IMAGE +#define CONFIG_CMD_PCI +#define CONFIG_PCI_PNP +#define CONFIG_CMD_IO +#define CONFIG_FS_FAT #define CONFIG_FAT_WRITE #define CONFIG_FS_EXT4
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH v2 18/22 dm: sandbox: pci: Enable PCI for sandbox
Quoted 11 lines · Simon Glass
Enable PCI options so that sandbox can be used for testing this bus with driver model.
Signed-off-by Simon Glass <[email protected]>---
Changes in v2: None
configs/sandbox_defconfig | 3 +++ include/configs/sandbox.h | 4 ++++ 2 files changed, 7 insertions(+)
Applied to u-boot-dm/next.
PATCH v2 19/22 dm: x86: pci: Add a PCI driver for driver model
In reply to Simon GlassAdd a simple x86 PCI driver which uses standard functions provided by the architecture.
---
Changes in v2: None
arch/x86/cpu/pci.c | 40 ++++++++++++++++++++++++++++++++++++++++ arch/x86/include/asm/pci.h | 8 ++++++++ arch/x86/lib/Makefile | 2 ++ drivers/pci/Makefile | 1 + drivers/pci/pci_x86.c | 24 ++++++++++++++++++++++++ 5 files changed, 75 insertions(+) create mode 100644 drivers/pci/pci_x86.c
arch/x86/cpu/pci.c +40 -0
@@ -10,9 +10,11 @@*/ #include <common.h> +#include <dm.h> #include <errno.h> #include <malloc.h> #include <pci.h> +#include <asm/io.h> #include <asm/pci.h> DECLARE_GLOBAL_DATA_PTR ;
@@ -111,3 +113,41 @@ void x86_pci_write_config32(pci_dev_t dev, unsigned where, unsigned value) {pci_hose_write_config_dword (get_hose (), dev, where, value); } + +int pci_x86_read_config (struct udevice *bus,pci_dev_t bdf,uint offset, +ulong *valuep,enum pci_size_t size) +{ +outl (bdf | (offset &0xfc ) |PCI_CFG_EN ,PCI_REG_ADDR ); +switch (size) { +case PCI_SIZE_8 : + *valuep =inb (PCI_REG_DATA + (offset &3 )); +break ; +case PCI_SIZE_16 : + *valuep =inw (PCI_REG_DATA + (offset &2 )); +break ; +case PCI_SIZE_32 : + *valuep =inl (PCI_REG_DATA ); +break ; + } + +return 0 ; +} + +int pci_x86_write_config (struct udevice *bus,pci_dev_t bdf,uint offset, +ulong value,enum pci_size_t size) +{ +outl (bdf | (offset &0xfc ) |PCI_CFG_EN ,PCI_REG_ADDR ); +switch (size) { +case PCI_SIZE_8 : +outb (value,PCI_REG_DATA + (offset &3 )); +break ; +case PCI_SIZE_16 : +outw (value,PCI_REG_DATA + (offset &2 )); +break ; +case PCI_SIZE_32 : +outl (value,PCI_REG_DATA ); +break ; + } + +return 0 ; +}
arch/x86/include/asm/pci.h +8 -0
@@ -8,6 +8,8 @@#ifndef _PCI_I386_H_#define _PCI_I386_H_ +#include <pci.h> +/* bus mapping constants (used for PCI core initialization) */ #define PCI_REG_ADDR 0xcf8#define PCI_REG_DATA 0xcfc
@@ -56,6 +58,12 @@ void x86_pci_write_config8(pci_dev_t dev, unsigned where, unsigned value);void x86_pci_write_config16 (pci_dev_t dev,unsigned where,unsigned value);void x86_pci_write_config32 (pci_dev_t dev,unsigned where,unsigned value); +int pci_x86_read_config (struct udevice *bus,pci_dev_t bdf,uint offset, +ulong *valuep,enum pci_size_t size); + +int pci_x86_write_config (struct udevice *bus,pci_dev_t bdf,uint offset, +ulong value,enum pci_size_t size); +#endif /* __ASSEMBLY__ */ #endif /* _PCI_I386_H_ */
arch/x86/lib/Makefile +2 -0
@@ -17,7 +17,9 @@ obj-y += interrupts.o obj-y += cmd_mtrr.o obj-$(CONFIG_SYS_PCAT_INTERRUPTS) += pcat_interrupts.o obj-$(CONFIG_SYS_PCAT_TIMER) += pcat_timer.o +ifndef CONFIG_DM_PCI obj-$(CONFIG_PCI) += pci_type1.o +endif obj-y += relocate.o obj-y += physmem.o obj-$(CONFIG_X86_RAMTEST) += ramtest.o
drivers/pci/Makefile +1 -0
@@ -9,6 +9,7 @@ ifneq ($(CONFIG_DM_PCI),) obj-$(CONFIG_PCI) += pci-uclass.o pci_compat.o obj-$(CONFIG_PCI_SANDBOX) += pci_sandbox.o obj-$(CONFIG_SANDBOX) += pci-emul-uclass.o +obj-$(CONFIG_X86) += pci_x86.o else obj-$(CONFIG_PCI) += pci.o endif
drivers/pci/pci_x86.c new file +24 -0
@@ -0,0 +1,24 @@ +/* +* Copyright (c) 2015 Google, Inc +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#include <common.h> +#include <dm.h> +#include <pci.h> + +static const struct dm_pci_ops x86_pci_ops = { +}; + +static const struct udevice_id x86_pci_ids[] = { + { .compatible ="x86,pci" }, + { } +}; + +U_BOOT_DRIVER (pci_x86) = { + .name ="pci_x86" , + .id =UCLASS_PCI , + .of_match = x86_pci_ids, + .ops = &x86_pci_ops, +};
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH v2 19/22 dm: x86: pci: Add a PCI driver for driver model
Quoted 8 lines · Simon Glass
Add a simple x86 PCI driver which uses standard functions provided by the architecture.
Signed-off-by Simon Glass <[email protected]>---
Changes in v2: None
Quoted 7 lines
arch/x86/cpu/pci.c | 40 ++++++++++++++++++++++++++++++++++++++++ arch/x86/include/asm/pci.h | 8 ++++++++ arch/x86/lib/Makefile | 2 ++ drivers/pci/Makefile | 1 + drivers/pci/pci_x86.c | 24 ++++++++++++++++++++++++ 5 files changed, 75 insertions(+) create mode 100644 drivers/pci/pci_x86.c
Applied to u-boot-dm/next.
PATCH v2 20/22 dm: x86: pci: Convert coreboot to use driver model for pci
In reply to Simon GlassMove coreboot-x86 over to driver model for PCI.
---
Changes in v2: None
arch/x86/cpu/coreboot/pci.c | 63 ++++++++++--------------------------- arch/x86/dts/chromebook_link.dts | 7 +++++ board/google/chromebook_link/link.c | 9 ++++++ configs/coreboot-x86_defconfig | 1 + include/dm/uclass-id.h | 1 + 5 files changed, 34 insertions(+), 47 deletions(-)
arch/x86/cpu/coreboot/pci.c +16 -47
@@ -10,58 +10,27 @@*/ #include <common.h> +#include <dm.h> +#include <errno.h> #include <pci.h> +#include <asm/io.h> #include <asm/pci.h> DECLARE_GLOBAL_DATA_PTR ; -static void config_pci_bridge (struct pci_controller *hose,pci_dev_t dev, -struct pci_config_table *table) -{ -u8 secondary; - hose->read_byte (hose, dev,PCI_SECONDARY_BUS , &secondary); - hose->last_busno =max (hose->last_busno, (int )secondary); -pci_hose_scan_bus (hose, secondary); -} - -static struct pci_config_table pci_coreboot_config_table[] = { -/* vendor, device, class, bus, dev, func */ - {PCI_ANY_ID ,PCI_ANY_ID ,PCI_CLASS_BRIDGE_PCI , -PCI_ANY_ID ,PCI_ANY_ID ,PCI_ANY_ID , &config_pci_bridge }, - {} +static const struct dm_pci_ops pci_x86_ops = { + .read_config = pci_x86_read_config, + .write_config = pci_x86_write_config, }; -void board_pci_setup_hose (struct pci_controller *hose) -{ - hose->config_table = pci_coreboot_config_table; - hose->first_busno =0 ; - hose->last_busno =0 ; - -/* PCI memory space */ -pci_set_region (hose->regions +0 , -CONFIG_PCI_MEM_BUS , -CONFIG_PCI_MEM_PHYS , -CONFIG_PCI_MEM_SIZE , -PCI_REGION_MEM ); - -/* PCI IO space */ -pci_set_region (hose->regions +1 , -CONFIG_PCI_IO_BUS , -CONFIG_PCI_IO_PHYS , -CONFIG_PCI_IO_SIZE , -PCI_REGION_IO ); - -pci_set_region (hose->regions +2 , -CONFIG_PCI_PREF_BUS , -CONFIG_PCI_PREF_PHYS , -CONFIG_PCI_PREF_SIZE , -PCI_REGION_PREFETCH ); - -pci_set_region (hose->regions +3 , -0 , -0 , - gd->ram_size, -PCI_REGION_MEM |PCI_REGION_SYS_MEMORY ); +static const struct udevice_id pci_x86_ids[] = { + { .compatible ="pci-x86" }, + { } +}; - hose->region_count =4 ; -} +U_BOOT_DRIVER (pci_x86_drv) = { + .name ="pci_x86" , + .id =UCLASS_PCI , + .of_match = pci_x86_ids, + .ops = &pci_x86_ops, +};
arch/x86/dts/chromebook_link.dts +7 -0
@@ -172,6 +172,13 @@ }; pci { + compatible = "intel,pci-ivybridge", "pci-x86"; + #address-cells = <3>; + #size-cells = <2>; + u-boot,dm-pre-reloc; + ranges = <0x02000000 0x0 0xe0000000 0xe0000000 0 0x10000000 + 0x42000000 0x0 0xd0000000 0xd0000000 0 0x10000000 + 0x01000000 0x0 0x1000 0x1000 0 0xefff>; sata { compatible = "intel,pantherpoint-ahci"; intel,sata-mode = "ahci";
board/google/chromebook_link/link.c +9 -0
@@ -6,6 +6,7 @@#include <common.h> #include <cros_ec.h> +#include <dm.h> #include <asm/gpio.h> #include <asm/io.h> #include <asm/pci.h>
@@ -13,6 +14,14 @@int arch_early_init_r (void ) { +struct udevice *dev; +int ret; + +/* Make sure the platform controller hub is up and running */ + ret =uclass_get_device (UCLASS_PCH ,0 , &dev); +if (ret) +return ret; +if (cros_ec_board_init ())return -1 ;
configs/coreboot-x86_defconfig +1 -0
@@ -2,3 +2,4 @@ CONFIG_SYS_EXTRA_OPTIONS="SYS_TEXT_BASE=0x01110000" CONFIG_X86=y CONFIG_TARGET_COREBOOT=y CONFIG_OF_CONTROL=y +CONFIG_DM_PCI=y
include/dm/uclass-id.h +1 -0
@@ -37,6 +37,7 @@ enum uclass_id {UCLASS_MOD_EXP ,/* RSA Mod Exp device */ UCLASS_PCI ,/* PCI bus */ UCLASS_PCI_GENERIC ,/* Generic PCI bus device */ +UCLASS_PCH ,/* x86 platform controller hub */ UCLASS_COUNT , UCLASS_INVALID = -1,
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH v2 20/22 dm: x86: pci: Convert coreboot to use driver model for pci
Quoted 5 lines · Simon Glass
Move coreboot-x86 over to driver model for PCI.
Signed-off-by Simon Glass <[email protected]>---
Quoted 8 lines
Changes in v2: None
arch/x86/cpu/coreboot/pci.c | 63 ++++++++++--------------------------- arch/x86/dts/chromebook_link.dts | 7 +++++ board/google/chromebook_link/link.c | 9 ++++++ configs/coreboot-x86_defconfig | 1 + include/dm/uclass-id.h | 1 + 5 files changed, 34 insertions(+), 47 deletions(-)
Applied to u-boot-dm/next.
PATCH v2 21/22 dm: x86: pci: Convert chromebook_link to use driver model for pci
In reply to Simon GlassMove chromebook_link over to driver model for PCI.
This involves:
- adding a uclass for platform controller hub
- removing most of the existing PCI driver
- adjusting how CPU init works to use driver model instead
- rename the lpc compatible string (it will be removed later)
This does not really take advantage of driver model fully, but it does work. Furture work will improve the code structure to remove many of the explicit calls to init the board.
---
Changes in v2: None
arch/x86/cpu/ivybridge/bd82x6x.c | 24 +++++++- arch/x86/cpu/ivybridge/cpu.c | 16 +++--- arch/x86/cpu/ivybridge/lpc.c | 1 + arch/x86/cpu/ivybridge/pci.c | 81 ++++++++------------------- arch/x86/dts/chromebook_link.dts | 3 +- arch/x86/include/asm/arch-ivybridge/bd82x6x.h | 1 - configs/chromebook_link_defconfig | 1 + configs/chromebox_panther_defconfig | 1 + lib/fdtdec.c | 2 +- 9 files changed, 62 insertions(+), 68 deletions(-)
arch/x86/cpu/ivybridge/bd82x6x.c +23 -1
@@ -5,6 +5,7 @@*/ #include <common.h> +#include <dm.h> #include <errno.h> #include <fdtdec.h> #include <malloc.h>
@@ -86,7 +87,7 @@ void bd82x6x_pci_bus_enable_resources(pci_dev_t dev)bd82x6x_pci_dev_enable_resources (dev); } -int bd82x6x_init_pci_devices (void ) +static int bd82x6x_probe (struct udevice *dev) {const void *blob = gd->fdt_blob;struct pci_controller *hose;
@@ -144,3 +145,24 @@ int bd82x6x_init(void)return 0 ; } + +static const struct udevice_id bd82x6x_ids[] = { + { .compatible ="intel,bd82x6x" }, + { } +}; + +U_BOOT_DRIVER (bd82x6x_drv) = { + .name ="bd82x6x" , + .id =UCLASS_PCH , + .of_match = bd82x6x_ids, + .probe = bd82x6x_probe, +}; + +/* +* TODO(sjg at chromium.org): Move this to arch/x86/lib or similar when other +* boards also use a PCH +*/ +UCLASS_DRIVER (pch) = { + .id =UCLASS_PCH , + .name ="pch" , +};
arch/x86/cpu/ivybridge/cpu.c +9 -7
@@ -12,6 +12,7 @@*/ #include <common.h> +#include <dm.h> #include <errno.h> #include <fdtdec.h> #include <asm/cpu.h>
@@ -126,19 +127,20 @@ int arch_cpu_init_dm(void) {const void *blob = gd->fdt_blob;struct pci_controller *hose; +struct udevice *bus;int node;int ret; -post_code (POST_CPU_INIT ); -timer_set_base (rdtsc ()); - - ret =x86_cpu_init_f (); +post_code (0x70 ); + ret =uclass_get_device (UCLASS_PCI ,0 , &bus); +post_code (0x71 );if (ret)return ret; +post_code (0x72 ); + hose =dev_get_uclass_priv (bus); - ret =pci_early_init_hose (&hose); -if (ret) -return ret; +/* TODO(sjg at chromium.org): Get rid of gd->hose */ + gd->hose = hose; node =fdtdec_next_compatible (blob,0 ,COMPAT_INTEL_LPC );if (node <0 )
arch/x86/cpu/ivybridge/lpc.c +1 -0
@@ -7,6 +7,7 @@*/ #include <common.h> +#include <dm.h> #include <errno.h> #include <fdtdec.h> #include <rtc.h>
arch/x86/cpu/ivybridge/pci.c +24 -57
106 lines not on this page · raw message
arch/x86/dts/chromebook_link.dts +2 -1
@@ -200,7 +200,8 @@ }; lpc { - compatible = "intel,lpc"; + reg = <0x0000f800 0 0 0 0>; + compatible = "intel,bd82x6x"; #address-cells = <1>; #size-cells = <1>; gen-dec = <0x800 0xfc 0x900 0xfc>;
arch/x86/include/asm/arch-ivybridge/bd82x6x.h +0 -1
@@ -12,7 +12,6 @@ void bd82x6x_sata_enable(pci_dev_t dev, const void *blob, int node);void bd82x6x_pci_init (pci_dev_t dev);void bd82x6x_usb_ehci_init (pci_dev_t dev);void bd82x6x_usb_xhci_init (pci_dev_t dev); -int bd82x6x_init_pci_devices (void );int gma_func0_init (pci_dev_t dev,struct pci_controller *hose,const void *blob,int node);int bd82x6x_init (void );
configs/chromebook_link_defconfig +1 -0
@@ -9,3 +9,4 @@ CONFIG_SMM_TSEG_SIZE=0x800000 CONFIG_VIDEO_VESA=y CONFIG_FRAMEBUFFER_SET_VESA_MODE=y CONFIG_FRAMEBUFFER_VESA_MODE_11A=y +CONFIG_DM_PCI=y
configs/chromebox_panther_defconfig +1 -0
@@ -9,3 +9,4 @@ CONFIG_SMM_TSEG_SIZE=0x800000 CONFIG_VIDEO_VESA=y CONFIG_FRAMEBUFFER_SET_VESA_MODE=y CONFIG_FRAMEBUFFER_VESA_MODE_11A=y +CONFIG_DM_PCI=y
lib/fdtdec.c +1 -1
@@ -67,7 +67,7 @@ static const char * const compat_names[COMPAT_COUNT] = {COMPAT (COMPAT_NXP_PTN3460 ,"nxp,ptn3460" ),COMPAT (SAMSUNG_EXYNOS_SYSMMU ,"samsung,sysmmu-v3.3" ),COMPAT (PARADE_PS8625 ,"parade,ps8625" ), -COMPAT (COMPAT_INTEL_LPC ,"intel,lpc" ), +COMPAT (COMPAT_INTEL_LPC ,"intel,bd82x6x" ),COMPAT (INTEL_MICROCODE ,"intel,microcode" ),COMPAT (MEMORY_SPD ,"memory-spd" ), COMPAT(INTEL_PANTHERPOINT_AHCI, "intel,pantherpoint-ahci"),
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH v2 21/22 dm: x86: pci: Convert chromebook_link to use driver model for pci
Quoted 8 lines · Simon Glass
Move
chromebook_linkover to driver model for PCI.This involves:
- adding a uclass for platform controller hub
- removing most of the existing PCI driver
- adjusting how CPU init works to use driver model instead
- rename the lpc compatible string (it will be removed later)
Quoted 5 lines
This does not really take advantage of driver model fully, but it does work. Furture work will improve the code structure to remove many of the explicit calls to init the board.
Signed-off-by Simon Glass <[email protected]>
Applied to u-boot-dm/next.
PATCH v2 22/22 dm: pci: Add driver model tests for PCI
In reply to Simon GlassAdd some basic tests to check that things work as expected with sandbox.
---
Changes in v2: None
test/dm/Makefile | 1 + test/dm/pci.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/dm/test.dts | 17 ++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 test/dm/pci.c
test/dm/Makefile +1 -0
@@ -21,4 +21,5 @@ obj-$(CONFIG_DM_GPIO) += gpio.o obj-$(CONFIG_DM_SPI) += spi.o obj-$(CONFIG_DM_SPI_FLASH) += sf.o obj-$(CONFIG_DM_I2C) += i2c.o +obj-$(CONFIG_DM_PCI) += pci.o endif
test/dm/pci.c new file +59 -0
59 lines not on this page · raw message
test/dm/test.dts +17 -0
@@ -10,6 +10,7 @@ console = &uart0; i2c0 = "/i2c at 0"; spi0 = "/spi at 0"; + pci0 = &pci; testfdt6 = "/e-test"; testbus3 = "/some-bus"; testfdt0 = "/some-bus/c-test at 0";
@@ -135,6 +136,22 @@ }; }; + pci: pci-controller { + compatible = "sandbox,pci"; + device_type = "pci"; + #address-cells = <3>; + #size-cells = <2>; + ranges = <0x02000000 0 0x10000000 0x10000000 0 0x2000 + 0x01000000 0 0x20000000 0x20000000 0 0x2000>; + pci at 1f,0 { + compatible = "pci-generic"; + reg = <0xf800 0 0 0 0>; + emul at 1f,0 { + compatible = "sandbox,swap-case"; + }; + }; + }; + spi at 0 { #address-cells = <1>; #size-cells = <0>;
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH v2 22/22 dm: pci: Add driver model tests for PCI
Quoted 5 lines · Simon Glass
Add some basic tests to check that things work as expected with sandbox.
Signed-off-by Simon Glass <[email protected]>---
Quoted 7 lines
Changes in v2: None
test/dm/Makefile | 1 + test/dm/pci.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/dm/test.dts | 17 ++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 test/dm/pci.c
Applied to u-boot-dm/next.
v2 cover Add driver model support for PCI
In reply to Simon GlassHi,
Quoted 74 lines · Simon Glass
This series is a collection of changes in core DM, sandbox, x86 and PCI code to implement a PCI uclass and associated operations. Some basic tests are provided as well.
As is becoming common with DM conversions, the existing structure (here struct
pci_controller) becomes per-bus uclass data. This allows the concept of a 'hose' (generally a PCI host controller and a bus) to continue to exist in the interim, even if it should not be needed in the end. This makes it much easier to convert over existing code.PCI buses are not scanned in the
bind()method but only later whenprobe()is called. This will be automatic if you access a bus, but it does mean that if PCI is not used it will not be touched, in keeping with U-Boot's lazy- init philosophy.The existing 'pciauto' bus configuration code is still used, although it now uses DM underneath. It works exclusively by reading and writing PCI config and does not refer to DM data structures. The one change is to drop use of the
hose->current_busnofield which is no longer required. The fact that file works largely as before is an indication that a good level of compatibility is achieved between DM and legacy PCI.In order to support testing of PCI I/O and memory space, support has been added to sandbox to allow mapping of these. This allows commands like 'md' and 'iod' to display data from mapped PCI devices. Similarly, it is possible to make changes to this space. This support relies on the existing
map_sysmem()andunmap_sysmem()calls which are now fairly widespread in U-Boot.Apart from the driver model tests (run with
./test/dm/test-dm.sh) you can try out these commands which use the new 'swap_case' test device:../u-boot -d b/sandbox/u-boot.dtb
....
=> iow.b 20000000 2
=> iod.b 20000000
0000: 02
=> mw.l 10000000 64436241
=> md.l 10000000 1
10000000: 44634261 aBcD
=>This shows an I/O access to 20000000, setting the value 2 which means to swap the case. Then 'AbCd' is written to the memory space at 10000000 and 'aBcD' is read back.
The 'pci' command can be used as before.
Most existing PCI functions (in
pci.h) still work, but route through driver model. The filedrivers/pci/pci.cis replaced when driver model is enabled so not everything is present. A newpci_common.cfile holds functions common to driver model and the old system, andpci_compat.ccontains functions I would like to eventually deprecate.Two x86 boards (coreboot and
chromebook_link) are converted over to use driver model for PCI.Core driver model changes include:
- Addition of a newpre_probe()method for the uclass to set up devices just before the device'sprobe()method is called
- A change in the ordering of when a device is marked as probed
- Adev_get_uclass_priv()accessor
- A tweak to the 'dm uclass' command to improve sequence number displayNotably missing from this series are functions to access PCI devices using a 'struct udevice *'. Where there is no device tree entry for a bus device, a generic PCI device is created in driver model to mirror the device, as with I2C and SPI. Future work could add more real devices to x86 and create a demand for these sorts of functions. Also we might store things like the PCI base address registers (BARs) in data structures if there is a need. These things are probably best developed as a need arises to avoid creating infrastructure and overhead that may not be used.
Quoted 7 lines
This series is available at u-boot-dm.git branch pci-working.
Changes in v2:
- Update root node #size=cells to 1 in this patch
- Add a new patch with a CPU init function which can use driver model
- Use the newarch_cpu_init_dm()function instead of something x86-specific
- Add -ve sign before ENXIO
I'm going to go ahead and apply this to u-boot-dm/next along with the x86 panther series (which it depends on).
Quoted 134 lines
Simon Glass (22):
sandbox: Update device tree 'reg' properties for I2C and SPI
fdt: Exportfdtdec_get_number()for general use
x86: Add ax86_prefix to the x86-specific PCI functions
dm: Add a new CPU init function which can use driver model
x86: Split uparch_cpu_init()
Correctmap_sysmem()logic indo_mem_mw()
fdt: Tighten up error handling infdtdec_get_pci_addr()
dm: core: Adddev_get_uclass_priv()to access uclass private data
dm: core: Mark device as active before calling itsprobe()method
dm: core: Add a uclasspre_probe()method for devices
dm: Show both allocated and requested seq numbers in 'dm uclass'
dm: pci: Move common PCI functions into their own file
dm: pci: Add a uclass for PCI
dm: sandbox: pci: Add PCI support for sandbox
dm: sandbox: Add a simple PCI driver
dm: sandbox: pci: Add a PCI emulation uclass
dm: sandbox: Add a emulated PCI device as an example
dm: sandbox: pci: Enable PCI for sandbox
dm: x86: pci: Add a PCI driver for driver model
dm: x86: pci: Convert coreboot to use driver model for pci
dm: x86: pci: Convertchromebook_linkto use driver model for pci
dm: pci: Add driver model tests for PCIarch/sandbox/Kconfig | 7 + arch/sandbox/cpu/cpu.c | 37 +- arch/sandbox/dts/sandbox.dts | 26 +- arch/sandbox/include/asm/io.h | 16 +- arch/sandbox/include/asm/processor.h | 12 + arch/sandbox/include/asm/test.h | 7 +- arch/sandbox/include/asm/u-boot-sandbox.h | 48 ++ arch/sandbox/lib/Makefile | 2 +- arch/sandbox/lib/pci_io.c | 138 ++++++ arch/x86/cpu/baytrail/early_uart.c | 5 +- arch/x86/cpu/coreboot/pci.c | 63 +-- arch/x86/cpu/ivybridge/bd82x6x.c | 56 ++- arch/x86/cpu/ivybridge/cpu.c | 62 +-- arch/x86/cpu/ivybridge/early_init.c | 58 +-- arch/x86/cpu/ivybridge/early_me.c | 12 +- arch/x86/cpu/ivybridge/gma.c | 4 +- arch/x86/cpu/ivybridge/lpc.c | 75 +-- arch/x86/cpu/ivybridge/northbridge.c | 6 +- arch/x86/cpu/ivybridge/pch.c | 4 +- arch/x86/cpu/ivybridge/pci.c | 85 ++-- arch/x86/cpu/ivybridge/report_platform.c | 4 +- arch/x86/cpu/ivybridge/sata.c | 61 +-- arch/x86/cpu/ivybridge/sdram.c | 20 +- arch/x86/cpu/ivybridge/usb_ehci.c | 4 +- arch/x86/cpu/ivybridge/usb_xhci.c | 8 +- arch/x86/cpu/pci.c | 52 ++- arch/x86/cpu/quark/quark.c | 4 +- arch/x86/cpu/queensbay/tnc.c | 4 +- arch/x86/dts/chromebook_link.dts | 10 +- arch/x86/include/asm/arch-ivybridge/bd82x6x.h | 1 - arch/x86/include/asm/pci.h | 20 +- arch/x86/lib/Makefile | 2 + arch/x86/lib/bios_interrupts.c | 12 +- board/google/chromebook_link/link.c | 9 + common/board_f.c | 6 + common/board_r.c | 2 + common/cmd_mem.c | 7 +- common/cmd_pci.c | 14 +- common/cmd_sf.c | 2 +- common/cros_ec.c | 2 +- configs/chromebook_link_defconfig | 1 + configs/chromebox_panther_defconfig | 1 + configs/coreboot-x86_defconfig | 1 + configs/sandbox_defconfig | 3 + doc/driver-model/pci-info.txt | 70 +++ drivers/core/device.c | 19 +- drivers/core/uclass.c | 10 +- drivers/gpio/at91_gpio.c | 2 +- drivers/gpio/bcm2835_gpio.c | 2 +- drivers/gpio/gpio-uclass.c | 22 +- drivers/gpio/intel_ich6_gpio.c | 18 +- drivers/gpio/mxc_gpio.c | 2 +- drivers/gpio/omap_gpio.c | 2 +- drivers/gpio/s5p_gpio.c | 2 +- drivers/gpio/sandbox.c | 6 +- drivers/gpio/sunxi_gpio.c | 2 +- drivers/gpio/tegra_gpio.c | 2 +- drivers/i2c/i2c-uclass.c | 6 +- drivers/i2c/sandbox_i2c.c | 2 +- drivers/misc/Makefile | 1 + drivers/misc/cros_ec.c | 6 +- drivers/misc/cros_ec_i2c.c | 2 +- drivers/misc/cros_ec_sandbox.c | 2 +- drivers/misc/cros_ec_spi.c | 4 +- drivers/misc/swap_case.c | 285 ++++++++++++ drivers/mtd/spi/sf-uclass.c | 2 +- drivers/mtd/spi/sf_probe.c | 8 +- drivers/pci/Kconfig | 22 + drivers/pci/Makefile | 11 +- drivers/pci/pci-emul-uclass.c | 67 +++ drivers/pci/pci-uclass.c | 639 ++++++++++++++++++++++++++ drivers/pci/pci.c | 281 +---------- drivers/pci/pci_auto.c | 16 +- drivers/pci/pci_common.c | 292 ++++++++++++ drivers/pci/pci_compat.c | 43 ++ drivers/pci/pci_sandbox.c | 79 ++++ drivers/pci/pci_x86.c | 24 + drivers/serial/serial-uclass.c | 4 +- drivers/spi/spi-uclass.c | 4 +- include/common.h | 11 + include/configs/sandbox.h | 4 + include/dm/device.h | 10 + include/dm/test.h | 1 + include/dm/uclass-id.h | 4 + include/dm/uclass-internal.h | 7 +- include/dm/uclass.h | 2 + include/fdtdec.h | 15 +- include/i2c.h | 8 +- include/pci.h | 411 ++++++++++++++++- lib/fdtdec.c | 8 +- test/dm/Makefile | 1 + test/dm/cmd_dm.c | 4 +- test/dm/core.c | 9 +- test/dm/pci.c | 59 +++ test/dm/test-uclass.c | 16 +- test/dm/test.dts | 17 + 96 files changed, 2842 insertions(+), 677 deletions(-) create mode 100644 arch/sandbox/include/asm/processor.h create mode 100644 arch/sandbox/lib/pci_io.c create mode 100644 doc/driver-model/pci-info.txt create mode 100644 drivers/misc/swap_case.c create mode 100644 drivers/pci/pci-emul-uclass.c create mode 100644 drivers/pci/pci-uclass.c create mode 100644 drivers/pci/pci_common.c create mode 100644 drivers/pci/pci_compat.c create mode 100644 drivers/pci/pci_sandbox.c create mode 100644 drivers/pci/pci_x86.c create mode 100644 test/dm/pci.c
Quoted 3 lines
--
2.2.0.rc0.207.ga3a616c
Regards,
Simon