From 21ccce1ba52253d776ecd7003e14910eed93160b Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 29 Nov 2015 13:17:47 -0700 Subject: dm: pci: Add a dm_ prefix to pci_get_bdf() Most driver model PCI functions have a dm_ prefix. At some point, when the old code is converted to driver model and the old functions are removed, we will drop that prefix. For consistency, we should use the dm_ prefix for all driver model functions. Update pci_get_bdf() accordingly. Signed-off-by: Simon Glass Reviewed-by: Bin Meng --- include/pci.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/pci.h b/include/pci.h index 2adca850b4..5d45cdc093 100644 --- a/include/pci.h +++ b/include/pci.h @@ -862,12 +862,12 @@ struct dm_pci_ops { #define pci_get_ops(dev) ((struct dm_pci_ops *)(dev)->driver->ops) /** - * pci_get_bdf() - Get the BDF value for a device + * dm_pci_get_bdf() - Get the BDF value for a device * * @dev: Device to check * @return bus/device/function value (see PCI_BDF()) */ -pci_dev_t pci_get_bdf(struct udevice *dev); +pci_dev_t dm_pci_get_bdf(struct udevice *dev); /** * pci_bind_bus_devices() - scan a PCI bus and bind devices -- cgit v1.2.1 From f3f1faefcc25c7cce2babe944aa39178b498cd7f Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 29 Nov 2015 13:17:48 -0700 Subject: dm: pci: Add a dm_ prefix to pci_bus_find_bdf() Most driver model PCI functions have a dm_ prefix. At some point, when the old code is converted to driver model and the old functions are removed, we will drop that prefix. For consistency, we should use the dm_ prefix for all driver model functions. Update pci_bus_find_bdf() accordingly. Signed-off-by: Simon Glass Reviewed-by: Bin Meng --- include/pci.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/pci.h b/include/pci.h index 5d45cdc093..586197610b 100644 --- a/include/pci.h +++ b/include/pci.h @@ -902,13 +902,13 @@ int pci_bind_bus_devices(struct udevice *bus); int pci_auto_config_devices(struct udevice *bus); /** - * pci_bus_find_bdf() - Find a device given its PCI bus address + * dm_pci_bus_find_bdf() - Find a device given its PCI bus address * * @bdf: PCI device address: bus, device and function -see PCI_BDF() * @devp: Returns the device for this address, if found * @return 0 if OK, -ENODEV if not found */ -int pci_bus_find_bdf(pci_dev_t bdf, struct udevice **devp); +int dm_pci_bus_find_bdf(pci_dev_t bdf, struct udevice **devp); /** * pci_bus_find_devfn() - Find a device on a bus -- cgit v1.2.1 From 5e23b8b4a4a63178015432a94617d937d8eb42cd Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 29 Nov 2015 13:17:49 -0700 Subject: dm: pci: Use driver model PCI API in auto-config At present we are using legacy functions even in the auto-configuration code used by driver model. Add a new pci_auto.c version which uses the correct API. Create a new pci_internal.h header to hold functions that are used within the PCI subsystem, but are not exported to other drivers. Signed-off-by: Simon Glass Reviewed-by: Bin Meng Tested-by: Bin Meng --- include/pci.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/pci.h b/include/pci.h index 586197610b..182290c3c2 100644 --- a/include/pci.h +++ b/include/pci.h @@ -995,7 +995,7 @@ int pci_find_device_id(struct pci_device_id *ids, int index, * @bdf: PCI bus address to scan (PCI_BUS(bdf) is the bus number) * @return 0 if OK, -ve on error */ -int dm_pci_hose_probe_bus(struct pci_controller *hose, pci_dev_t bdf); +int dm_pci_hose_probe_bus(struct udevice *bus); /** * pci_bus_read_config() - Read a configuration value from a device -- cgit v1.2.1 From 5c0bf647c4e1659fdeb83a66f56ec27add72b561 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 29 Nov 2015 13:17:50 -0700 Subject: dm: pci: Add a driver-model version of pci_find_device() Add a function which scans the driver model device information rather than scanning the PCI bus again. Signed-off-by: Simon Glass Reviewed-by: Bin Meng Tested-by: Bin Meng --- include/pci.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'include') diff --git a/include/pci.h b/include/pci.h index 182290c3c2..347dd0af59 100644 --- a/include/pci.h +++ b/include/pci.h @@ -1166,6 +1166,18 @@ struct udevice *pci_get_controller(struct udevice *dev); int pci_get_regions(struct udevice *dev, struct pci_region **iop, struct pci_region **memp, struct pci_region **prefp); +/** + * dm_pci_find_device() - find a device by vendor/device ID + * + * @vendor: Vendor ID + * @device: Device ID + * @index: 0 to find the first match, 1 for second, etc. + * @devp: Returns pointer to the device, if found + * @return 0 if found, -ve on error + */ +int dm_pci_find_device(unsigned int vendor, unsigned int device, int index, + struct udevice **devp); + /** * struct dm_pci_emul_ops - PCI device emulator operations */ -- cgit v1.2.1 From a0eb835635abe0952529e3eb5207a24ac36fa000 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 29 Nov 2015 13:17:52 -0700 Subject: dm: pci: Add a driver-model version of pci_find_class() Add a function which scans the driver model device information rather than scanning the PCI bus again. Signed-off-by: Simon Glass Reviewed-by: Bin Meng Tested-by: Bin Meng --- include/pci.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'include') diff --git a/include/pci.h b/include/pci.h index 347dd0af59..443af839b6 100644 --- a/include/pci.h +++ b/include/pci.h @@ -1178,6 +1178,16 @@ int pci_get_regions(struct udevice *dev, struct pci_region **iop, int dm_pci_find_device(unsigned int vendor, unsigned int device, int index, struct udevice **devp); +/** + * dm_pci_find_class() - find a device by class + * + * @find_class: 3-byte (24-bit) class value to find + * @index: 0 to find the first match, 1 for second, etc. + * @devp: Returns pointer to the device, if found + * @return 0 if found, -ve on error + */ +int dm_pci_find_class(uint find_class, int index, struct udevice **devp); + /** * struct dm_pci_emul_ops - PCI device emulator operations */ -- cgit v1.2.1 From bab17cf143c4888d03eb51f20aa6b86210448608 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 29 Nov 2015 13:17:53 -0700 Subject: dm: pci: Add a function to read a PCI BAR Add a driver-model function for reading the PCI BAR from a device. Signed-off-by: Simon Glass Reviewed-by: Bin Meng --- include/pci.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'include') diff --git a/include/pci.h b/include/pci.h index 443af839b6..dcbe9787a3 100644 --- a/include/pci.h +++ b/include/pci.h @@ -1166,6 +1166,15 @@ struct udevice *pci_get_controller(struct udevice *dev); int pci_get_regions(struct udevice *dev, struct pci_region **iop, struct pci_region **memp, struct pci_region **prefp); +/** + * dm_pci_read_bar32() - read a base address register from a device + * + * @dev: Device to check + * @barnum: Bar number to read (numbered from 0) + * @return: value of BAR + */ +u32 dm_pci_read_bar32(struct udevice *dev, int barnum); + /** * dm_pci_find_device() - find a device by vendor/device ID * -- cgit v1.2.1 From fcc0a8774bb78a601a0d6d4e1f73dcfc07b3d4a4 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 29 Nov 2015 13:17:54 -0700 Subject: dm: serial: Convert ns16550 driver to use driver model PCI API Use the driver model version of the function to find the BAR. This updates the fdtdec function, of which ns16550 is the only user. The fdtdec_get_pci_bdf() function is dropped for several reasons: - with driver model we should use 'struct udevice *' rather than passing the device tree offset explicitly - there are no other users in the tree - the function parses for information which is already available in the PCI device structure (specifically struct pci_child_platdata which is available at dev_get_parent_platdata(dev) Signed-off-by: Simon Glass Reviewed-by: Bin Meng Tested-by: Bin Meng --- include/fdtdec.h | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) (limited to 'include') diff --git a/include/fdtdec.h b/include/fdtdec.h index d82dc35073..7a1450c576 100644 --- a/include/fdtdec.h +++ b/include/fdtdec.h @@ -443,34 +443,17 @@ int fdtdec_get_pci_addr(const void *blob, int node, enum fdt_pci_space type, int fdtdec_get_pci_vendev(const void *blob, int node, u16 *vendor, u16 *device); -/** - * Look at the pci address of a device node that represents a PCI device - * and parse the bus, device and function number from it. For some cases - * like the bus number encoded in reg property is not correct after pci - * enumeration, this function looks through the node's compatible strings - * to get these numbers extracted instead. - * - * @param blob FDT blob - * @param node node to examine - * @param addr pci address in the form of fdt_pci_addr - * @param bdf returns bus, device, function triplet - * @return 0 if ok, negative on error - */ -int fdtdec_get_pci_bdf(const void *blob, int node, - struct fdt_pci_addr *addr, pci_dev_t *bdf); - /** * Look at the pci address of a device node that represents a PCI device * and return base address of the pci device's registers. * - * @param blob FDT blob - * @param node node to examine + * @param dev device to examine * @param addr pci address in the form of fdt_pci_addr * @param bar returns base address of the pci device's registers * @return 0 if ok, negative on error */ -int fdtdec_get_pci_bar32(const void *blob, int node, - struct fdt_pci_addr *addr, u32 *bar); +int fdtdec_get_pci_bar32(struct udevice *dev, struct fdt_pci_addr *addr, + u32 *bar); /** * Look up a 32-bit integer property in a node and return it. The property -- cgit v1.2.1 From 3f4e1e8efc5b700473f1920e92b521cb0945a6e3 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 29 Nov 2015 13:17:57 -0700 Subject: dm: pci: video: Convert video and pci_rom to use DM PCI API Adjust these files to use the driver-model PCI API instead of the legacy functions. Signed-off-by: Simon Glass Acked-by: Anatolij Gustschin Reviewed-by: Bin Meng Tested-by: Bin Meng --- include/pci_rom.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/pci_rom.h b/include/pci_rom.h index 2f1665d17a..95c6d079fb 100644 --- a/include/pci_rom.h +++ b/include/pci_rom.h @@ -44,14 +44,14 @@ enum pci_rom_emul { }; /** - * pci_run_vga_bios() - Run the VGA BIOS in an x86 PC + * dm_pci_run_vga_bios() - Run the VGA BIOS in an x86 PC * * @dev: Video device containing the BIOS * @int15_handler: Function to call to handle int 0x15 * @exec_method: flags from enum pci_rom_emul */ -int pci_run_vga_bios(pci_dev_t dev, int (*int15_handler)(void), - int exec_method); +int dm_pci_run_vga_bios(struct udevice *dev, int (*int15_handler)(void), + int exec_method); /** * board_map_oprom_vendev() - map several PCI IDs to the one the ROM expects -- cgit v1.2.1 From 8beb0bda9c59146df70b960ce69ecfbd6f744028 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 29 Nov 2015 13:17:58 -0700 Subject: dm: x86: pci: Adjust bios_run_on_x86() to use the DM PCI API This function should take a struct udevice rather than pci_dev_t. Update it. Signed-off-by: Simon Glass Reviewed-by: Bin Meng Tested-by: Bin Meng --- include/bios_emul.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/bios_emul.h b/include/bios_emul.h index 3643b82b3a..80979edd04 100644 --- a/include/bios_emul.h +++ b/include/bios_emul.h @@ -42,7 +42,7 @@ struct vbe_mode_info; int BootVideoCardBIOS(pci_dev_t pcidev, BE_VGAInfo **pVGAInfo, int cleanUp); /* Run a BIOS ROM natively (only supported on x86 machines) */ -void bios_run_on_x86(pci_dev_t pcidev, unsigned long addr, int vesa_mode, +void bios_run_on_x86(struct udevice *dev, unsigned long addr, int vesa_mode, struct vbe_mode_info *mode_info); /** -- cgit v1.2.1 From 21d1fe7ec249bd298f40fb17142d4dee27fdbb1a Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 29 Nov 2015 13:18:03 -0700 Subject: dm: pci: Add driver model API functions for address mapping At present the PCI address map functions use the old API. Add new functions for this so that drivers can be converted. Signed-off-by: Simon Glass Reviewed-by: Bin Meng --- include/pci.h | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'include') diff --git a/include/pci.h b/include/pci.h index dcbe9787a3..b61f7605a1 100644 --- a/include/pci.h +++ b/include/pci.h @@ -1175,6 +1175,65 @@ int pci_get_regions(struct udevice *dev, struct pci_region **iop, */ u32 dm_pci_read_bar32(struct udevice *dev, int barnum); +/** + * dm_pci_bus_to_phys() - convert a PCI bus address to a physical address + * + * @dev: Device containing the PCI address + * @addr: PCI address to convert + * @flags: Flags for the region type (PCI_REGION_...) + * @return physical address corresponding to that PCI bus address + */ +phys_addr_t dm_pci_bus_to_phys(struct udevice *dev, pci_addr_t addr, + unsigned long flags); + +/** + * dm_pci_phys_to_bus() - convert a physical address to a PCI bus address + * + * @dev: Device containing the bus address + * @addr: Physical address to convert + * @flags: Flags for the region type (PCI_REGION_...) + * @return PCI bus address corresponding to that physical address + */ +pci_addr_t dm_pci_phys_to_bus(struct udevice *dev, phys_addr_t addr, + unsigned long flags); + +/** + * dm_pci_map_bar() - get a virtual address associated with a BAR region + * + * Looks up a base address register and finds the physical memory address + * that corresponds to it + * + * @dev: Device to check + * @bar: Bar number to read (numbered from 0) + * @flags: Flags for the region type (PCI_REGION_...) + * @return: pointer to the virtual address to use + */ +void *dm_pci_map_bar(struct udevice *dev, int bar, int flags); + +#define dm_pci_virt_to_bus(dev, addr, flags) \ + dm_pci_phys_to_bus(dev, (virt_to_phys(addr)), (flags)) +#define dm_pci_bus_to_virt(dev, addr, flags, len, map_flags) \ + map_physmem(dm_pci_bus_to_phys(dev, (addr), (flags)), \ + (len), (map_flags)) + +#define dm_pci_phys_to_mem(dev, addr) \ + dm_pci_phys_to_bus((dev), (addr), PCI_REGION_MEM) +#define dm_pci_mem_to_phys(dev, addr) \ + dm_pci_bus_to_phys((dev), (addr), PCI_REGION_MEM) +#define dm_pci_phys_to_io(dev, addr) \ + dm_pci_phys_to_bus((dev), (addr), PCI_REGION_IO) +#define dm_pci_io_to_phys(dev, addr) \ + dm_pci_bus_to_phys((dev), (addr), PCI_REGION_IO) + +#define dm_pci_virt_to_mem(dev, addr) \ + dm_pci_virt_to_bus((dev), (addr), PCI_REGION_MEM) +#define dm_pci_mem_to_virt(dev, addr, len, map_flags) \ + dm_pci_bus_to_virt((dev), (addr), PCI_REGION_MEM, (len), (map_flags)) +#define dm_pci_virt_to_io(dev, addr) \ + dm_dm_pci_virt_to_bus((dev), (addr), PCI_REGION_IO) +#define dm_pci_io_to_virt(dev, addr, len, map_flags) \ + dm_dm_pci_bus_to_virt((dev), (addr), PCI_REGION_IO, (len), (map_flags)) + /** * dm_pci_find_device() - find a device by vendor/device ID * -- cgit v1.2.1 From 7e78b9ef2c9f263214adf7e2f7be9912a1af564b Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 29 Nov 2015 13:18:05 -0700 Subject: dm: pci: Switch to DM API for PCI address mapping We should use the new address mapping functions unless we are in compatibility mode. Disable the old functions by default. Signed-off-by: Simon Glass Reviewed-by: Bin Meng --- include/pci.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/pci.h b/include/pci.h index b61f7605a1..cb2562f109 100644 --- a/include/pci.h +++ b/include/pci.h @@ -621,6 +621,7 @@ static inline void pci_set_ops(struct pci_controller *hose, extern void pci_setup_indirect(struct pci_controller* hose, u32 cfg_addr, u32 cfg_data); #endif +#if !defined(CONFIG_DM_PCI) || defined(CONFIG_DM_PCI_COMPAT) extern phys_addr_t pci_hose_bus_to_phys(struct pci_controller* hose, pci_addr_t addr, unsigned long flags); extern pci_addr_t pci_hose_phys_to_bus(struct pci_controller* hose, @@ -656,7 +657,6 @@ extern pci_addr_t pci_hose_phys_to_bus(struct pci_controller* hose, pci_bus_to_virt((dev), (addr), PCI_REGION_IO, (len), (map_flags)) /* For driver model these are defined in macros in pci_compat.c */ -#if !defined(CONFIG_DM_PCI) || defined(CONFIG_DM_PCI_COMPAT) extern int pci_hose_read_config_byte(struct pci_controller *hose, pci_dev_t dev, int where, u8 *val); extern int pci_hose_read_config_word(struct pci_controller *hose, -- cgit v1.2.1 From ff758ccc8a237f7a4b14be7271b55b1d611b1250 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 29 Nov 2015 13:18:06 -0700 Subject: dm: ahci: Convert to use new DM PCI API Convert this driver to use the new driver model PCI API. Signed-off-by: Simon Glass Reviewed-by: Bin Meng --- include/ahci.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'include') diff --git a/include/ahci.h b/include/ahci.h index 0bdedac187..a956c6ff5d 100644 --- a/include/ahci.h +++ b/include/ahci.h @@ -145,7 +145,11 @@ struct ahci_ioports { }; struct ahci_probe_ent { +#ifdef CONFIG_DM_PCI + struct udevice *dev; +#else pci_dev_t dev; +#endif struct ahci_ioports port[AHCI_MAX_PORTS]; u32 n_ports; u32 hard_port_no; -- cgit v1.2.1 From 4abe8e40a73146bbe9fe825c53c70076ccc9544f Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 29 Nov 2015 13:18:08 -0700 Subject: dm: Convert PCI MMC over to use DM PCI API At present pci_mmc_init() does not correctly use the PCI function since the list it passes is not terminated. The array size passed to pci_mmc_init() is actually not used correctly. Fix this and adjust the pci_mmc_init() to scan all available MMC devices. Adjust this code to use the new driver model PCI API. This should move over to the new MMC uclass at some point. Signed-off-by: Simon Glass Reviewed-by: Bin Meng --- include/mmc.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/mmc.h b/include/mmc.h index b89962a562..9254b716b9 100644 --- a/include/mmc.h +++ b/include/mmc.h @@ -489,11 +489,9 @@ struct pci_device_id; * This finds all the matching PCI IDs and sets them up as MMC devices. * * @name: Name to use for devices - * @mmc_supported: PCI IDs to search for - * @num_ids: Number of elements in @mmc_supported + * @mmc_supported: PCI IDs to search for, terminated by {0, 0} */ -int pci_mmc_init(const char *name, struct pci_device_id *mmc_supported, - int num_ids); +int pci_mmc_init(const char *name, struct pci_device_id *mmc_supported); /* Set block count limit because of 16 bit register limit on some hardware*/ #ifndef CONFIG_SYS_MMC_MAX_BLK_COUNT -- cgit v1.2.1 From 9b20519887ab39b389cd3e178c11d5bdb19c92e6 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 13 Dec 2015 21:37:00 -0700 Subject: rockchip: Use the debug UART on rk3036 Rather than using a new debug UART implementation, use the standard one provided by U-Boot. Signed-off-by: Simon Glass Reviewed-by: Thomas Chou --- include/configs/rk3036_common.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') diff --git a/include/configs/rk3036_common.h b/include/configs/rk3036_common.h index f753e684a6..d22ea74136 100644 --- a/include/configs/rk3036_common.h +++ b/include/configs/rk3036_common.h @@ -24,6 +24,8 @@ #define CONFIG_SYS_TIMER_BASE 0x200440a0 /* TIMER5 */ #define CONFIG_SYS_TIMER_COUNTER (CONFIG_SYS_TIMER_BASE + 8) +#define CONFIG_SPL_SERIAL_SUPPORT + #define CONFIG_SYS_NS16550 #define CONFIG_SYS_NS16550_MEM32 -- cgit v1.2.1 From 66eaea6cd152a0dae5964930483f68d92047b2f5 Mon Sep 17 00:00:00 2001 From: Stefan Roese Date: Mon, 14 Dec 2015 16:18:15 +0100 Subject: dm: core: Add option to configure an offset for the address translation Some platforms need to ability to configure an offset to the standard addresses extracted from the device-tree. This patch allows this by adding a function to DM to configure this offset (if needed). Signed-off-by: Stefan Roese Acked-by: Simon Glass Cc: Simon Glass Fixed space before tab: Signed-off-by: Simon Glass --- include/dm/device.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'include') diff --git a/include/dm/device.h b/include/dm/device.h index 7fb99356be..d9fc7fb953 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -776,4 +776,25 @@ static inline void devm_kfree(struct udevice *dev, void *ptr) #endif /* ! CONFIG_DEVRES */ +/** + * dm_set_translation_offset() - Set translation offset + * @offs: Translation offset + * + * Some platforms need a special address translation. Those + * platforms (e.g. mvebu in SPL) can configure a translation + * offset in the DM by calling this function. It will be + * added to all addresses returned in dev_get_addr(). + */ +void dm_set_translation_offset(fdt_addr_t offs); + +/** + * dm_get_translation_offset() - Get translation offset + * + * This function returns the translation offset that can + * be configured by calling dm_set_translation_offset(). + * + * @return translation offset for the device address (0 as default). + */ +fdt_addr_t dm_get_translation_offset(void); + #endif -- cgit v1.2.1