From 68b97a6034073b0b3e856f580e9cf2f72d3f73cf Mon Sep 17 00:00:00 2001 From: Carl-Daniel Hailfinger Date: Sun, 20 Jan 2008 23:03:40 +0000 Subject: [PATCH] include/device/device.h Remove old vendor,device struct members since we are now using the device_id struct. Change declaration of dev_find_device to use device_id struct. device/device_util.c Change dev_find_device to use device_id struct instead of vendor, device parameters. Add convenience function, dev_find_pci_device, to make it easier for users. device/pci_device.c Change uses of dev->vendor and dev->device to dev->id. Change prints of dev->vendor, dev->device to use the dev_id_string function. device/pci_rom.c Change uses of dev->vendor and dev->device to dev->id. southbridge/amd/cs5536/cs5536.c Change uses of dev_find_device to dev_find_pci_device southbridge/amd/cs5536/dts Add pciid of the cs5536 northbridge/amd/geodelx/dts add pciid of the geodelx northbridge. util/x86emu/vm86.c Change uses of dev_find_device to dev_find_pci_device With these changes, the chipsetinit function now finds the southbridge in the static tree, which is the first time this has worked in v3. This success in turn means that the chipsetinit code is running for the first time. We are still failing in "Finding PCI configuration type" Signed-off-by: Ronald G. Minnich Acked-by: Carl-Daniel Hailfinger git-svn-id: svn://coreboot.org/repository/coreboot-v3@558 f3766cd6-281f-0410-b1cd-43a5c92072e9 --- device/device_util.c | 37 +++++++++++++++++++++++++++------ device/pci_device.c | 26 +++++++++++------------ device/pci_rom.c | 2 +- include/device/device.h | 6 ++---- northbridge/amd/geodelx/dts | 3 ++- southbridge/amd/cs5536/cs5536.c | 16 +++++++------- southbridge/amd/cs5536/dts | 1 + util/x86emu/vm86.c | 2 +- 8 files changed, 58 insertions(+), 35 deletions(-) diff --git a/device/device_util.c b/device/device_util.c index 3002778fd0..4b0781a018 100644 --- a/device/device_util.c +++ b/device/device_util.c @@ -115,26 +115,51 @@ struct device *dev_find_slot_on_smbus(unsigned int bus, unsigned int addr) /** * Find a device of a given vendor and type. * - * @param vendor Vendor ID (e.g. 0x8086 for Intel) - * @param device Device ID + * @param devid Pointer to device_id struct * @param from Pointer to the device structure, used as a starting point * in the linked list of all_devices, which can be 0 to start * at the head of the list (i.e. all_devices). * @return Pointer to the device struct. */ -struct device *dev_find_device(unsigned int vendor, unsigned int device, - struct device *from) +struct device *dev_find_device(struct device_id *devid, struct device *from) { + printk(BIOS_SPEW, "%s: find %s\n", __FUNCTION__, dev_id_string(devid)); + if (!from) from = all_devices; else from = from->next; - while (from && (from->vendor != vendor || from->device != device)) { - from = from->next; + for(;from;from = from->next){ + printk(BIOS_SPEW, "Check %s\n", dev_id_string(&from->id)); + if (id_eq(devid, &from->id)) + break; } + printk(BIOS_SPEW, "%sfound\n", from ? "" : "not "); return from; } +/** + * Find a PCI device of a given vendor and type. + * This is a convenience function since PCI device searches + * are by far the most common. + * + * @param vendor vendor number + * @param device device number + * @param from Pointer to the device structure, used as a starting point + * in the linked list of all_devices, which can be 0 to start + * at the head of the list (i.e. all_devices). + * @return Pointer to the device struct. + */ +struct device *dev_find_pci_device(u16 vendor, u16 device, struct device *from) +{ + struct device_id id; + + id.type = DEVICE_ID_PCI; + id.u.pci.vendor = vendor; + id.u.pci.device = device; + return dev_find_device(&id, from); +} + /** * Find a device of a given class. * diff --git a/device/pci_device.c b/device/pci_device.c index 3767ec7985..df6b2e0a4f 100644 --- a/device/pci_device.c +++ b/device/pci_device.c @@ -824,7 +824,7 @@ static struct device_operations *get_pci_bridge_ops(struct device *dev) static void set_pci_ops(struct device *dev) { struct constructor *c; - struct device_id id = {.type = DEVICE_ID_PCI }; + struct device_id id; if (dev->ops) { printk(BIOS_SPEW, "%s: dev %p(%s) already has ops %p\n", @@ -832,9 +832,7 @@ static void set_pci_ops(struct device *dev) return; } - /* We need to make the ID in the device a device_id type. */ - id.u.pci.vendor = dev->vendor; - id.u.pci.device = dev->device; + id = dev->id; /* Look through the list of setup drivers and find one for * this PCI device. @@ -842,9 +840,9 @@ static void set_pci_ops(struct device *dev) c = find_constructor(&id); if (c) { dev->ops = c->ops; - printk(BIOS_SPEW, "%s id %s [%04x/%04x] %sops\n", - dev_path(dev), dev_id_string(&id), dev->vendor, - dev->device, (dev->ops->phase3_scan ? "bus " : "")); + printk(BIOS_SPEW, "%s id %s %sops\n", + dev_path(dev), dev_id_string(&id), + (dev->ops->phase3_scan ? "bus " : "")); return; } @@ -869,9 +867,9 @@ static void set_pci_ops(struct device *dev) bad: if (dev->enabled) { printk(BIOS_ERR, - "%s [%04x/%04x/%06x] has unknown header " + "%s [%s/%06x] has unknown header " "type %02x, ignoring.\n", dev_path(dev), - dev->vendor, dev->device, dev->class >> 8, + dev_id_string(&dev->id), dev->class >> 8, dev->hdr_type); } } @@ -1027,8 +1025,9 @@ struct device *pci_probe_dev(struct device *dev, struct bus *bus, dev->subsystem_device = pci_read_config16(dev, PCI_SUBSYSTEM_ID); /* Store the interesting information in the device structure. */ - dev->vendor = id & 0xffff; - dev->device = (id >> 16) & 0xffff; + dev->id.type = DEVICE_ID_PCI; + dev->id.u.pci.vendor = id & 0xffff; + dev->id.u.pci.device = (id >> 16) & 0xffff; dev->hdr_type = hdr_type; /* Class code, the upper 3 bytes of PCI_CLASS_REVISION. */ dev->class = class >> 8; @@ -1051,9 +1050,8 @@ struct device *pci_probe_dev(struct device *dev, struct bus *bus, /* Display the device and error if we don't have some PCI operations * for it. */ - printk(BIOS_DEBUG, "%s [%04x/%04x] %s%s\n", - dev_path(dev), - dev->vendor, dev->device, + printk(BIOS_DEBUG, "%s [%s] %s%s\n", + dev_path(dev), dev_id_string(&dev->id), dev->enabled ? "enabled" : "disabled", dev->ops ? "" : " No operations"); diff --git a/device/pci_rom.c b/device/pci_rom.c index c721fcf459..a223b89c94 100644 --- a/device/pci_rom.c +++ b/device/pci_rom.c @@ -83,7 +83,7 @@ struct rom_header *pci_rom_probe(struct device *dev) printk(BIOS_SPEW, "PCI ROM Image, Vendor %04x, Device %04x,\n", rom_data->vendor, rom_data->device); - if (dev->vendor != rom_data->vendor || dev->device != rom_data->device) { + if (dev->id.u.pci.vendor != rom_data->vendor || dev->id.u.pci.device != rom_data->device) { printk(BIOS_ERR, "Device or Vendor ID mismatch Vendor %04x, Device %04x\n", rom_data->vendor, rom_data->device); diff --git a/include/device/device.h b/include/device/device.h index 3b3718c7f7..66f5807428 100644 --- a/include/device/device.h +++ b/include/device/device.h @@ -197,9 +197,6 @@ struct device { struct device_path path; struct device_id id; char dtsname[MAX_DTSNAME_SIZE]; /* the name from the dts */ - /* XXX remove this soon */ - unsigned device, vendor; - /* XXX */ u16 status; u8 revision; u8 cache_line; @@ -266,7 +263,8 @@ void disable_children(struct bus *bus); /* Helper functions */ struct device * find_dev_path(struct bus *parent, struct device_path *path); struct device * alloc_find_dev(struct bus *parent, struct device_path *path, struct device_id *id); -struct device * dev_find_device (unsigned int vendor, unsigned int device, struct device * from); +struct device * dev_find_device (struct device_id *devid, struct device * from); +struct device *dev_find_pci_device(u16 vendor, u16 device, struct device *from); struct device * dev_find_class (unsigned int class, struct device * from); struct device * dev_find_slot (unsigned int bus, unsigned int devfn); struct device * dev_find_slot_on_smbus (unsigned int bus, unsigned int addr); diff --git a/northbridge/amd/geodelx/dts b/northbridge/amd/geodelx/dts index cea881616b..3d86fb0add 100644 --- a/northbridge/amd/geodelx/dts +++ b/northbridge/amd/geodelx/dts @@ -19,6 +19,7 @@ */ { - constructor = "geodelx_north_constructors"; + constructor = "geodelx_north_constructors"; + domainid = "PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_LXBRIDGE"; }; diff --git a/southbridge/amd/cs5536/cs5536.c b/southbridge/amd/cs5536/cs5536.c index 73e46241a9..29c7e0a384 100644 --- a/southbridge/amd/cs5536/cs5536.c +++ b/southbridge/amd/cs5536/cs5536.c @@ -227,7 +227,7 @@ static void uarts_init(struct southbridge_amd_cs5536_config *sb) u32 gpio_addr; struct device *dev; - dev = dev_find_device(PCI_VENDOR_ID_AMD, + dev = dev_find_pci_device(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_ISA, 0); gpio_addr = pci_read_config32(dev, PCI_BASE_ADDRESS_1); @@ -389,7 +389,7 @@ static void enable_USB_port4(struct southbridge_amd_cs5536_config *sb) struct msr msr; struct device *dev; - dev = dev_find_device(PCI_VENDOR_ID_AMD, + dev = dev_find_pci_device(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_EHCI, 0); if (dev) { /* Serial short detect enable */ @@ -409,7 +409,7 @@ static void enable_USB_port4(struct southbridge_amd_cs5536_config *sb) *(bar + HCCPARAMS) = 0x00005012; } - dev = dev_find_device(PCI_VENDOR_ID_AMD, + dev = dev_find_pci_device(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_OTG, 0); if (dev) { bar = (u32 *) pci_read_config32(dev, PCI_BASE_ADDRESS_0); @@ -434,14 +434,14 @@ static void enable_USB_port4(struct southbridge_amd_cs5536_config *sb) * - Set APU bit in uoc register */ if (sb->enable_USBP4_device) { - dev = dev_find_device(PCI_VENDOR_ID_AMD, + dev = dev_find_pci_device(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_UDC, 0); if (dev) { bar = (u32 *)pci_read_config32(dev, PCI_BASE_ADDRESS_0); *(bar + UDCDEVCTL) |= UDC_SD_SET; } - dev = dev_find_device(PCI_VENDOR_ID_AMD, + dev = dev_find_pci_device(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_OTG, 0); if (dev) { bar = (u32 *)pci_read_config32(dev, PCI_BASE_ADDRESS_0); @@ -451,12 +451,12 @@ static void enable_USB_port4(struct southbridge_amd_cs5536_config *sb) } /* Disable virtual PCI UDC and OTG headers. */ - dev = dev_find_device(PCI_VENDOR_ID_AMD, + dev = dev_find_pci_device(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_UDC, 0); if (dev) pci_write_config32(dev, 0x7C, 0xDEADBEEF); - dev = dev_find_device(PCI_VENDOR_ID_AMD, + dev = dev_find_pci_device(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_OTG, 0); if (dev) pci_write_config32(dev, 0x7C, 0xDEADBEEF); @@ -479,7 +479,7 @@ void chipsetinit(void) const struct msrinit *csi; post_code(P80_CHIPSET_INIT); - dev = dev_find_device(PCI_VENDOR_ID_AMD, + dev = dev_find_pci_device(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_ISA, 0); if (!dev) { printk(BIOS_ERR, "%s: Could not find the south bridge!\n", diff --git a/southbridge/amd/cs5536/dts b/southbridge/amd/cs5536/dts index 8761249fd4..3082fad265 100644 --- a/southbridge/amd/cs5536/dts +++ b/southbridge/amd/cs5536/dts @@ -20,6 +20,7 @@ { constructor = "cs5536_constructors"; + pciid = "PCI_VENDOR_ID_AMD,PCI_DEVICE_ID_AMD_CS5536_ISA"; /* Interrupt enables for LPC bus. Each bit is an IRQ 0-15. */ lpc_serirq_enable = "0"; diff --git a/util/x86emu/vm86.c b/util/x86emu/vm86.c index 1f95309576..5fc6f4de63 100644 --- a/util/x86emu/vm86.c +++ b/util/x86emu/vm86.c @@ -645,7 +645,7 @@ pcibios(unsigned long *pedi, unsigned long *pesi, unsigned long *pebp, vendorid = *pedx; devindex = *pesi; dev = 0; - while ((dev = dev_find_device(vendorid, devid, dev))) { + while ((dev = dev_find_pci_device(vendorid, devid, dev))) { if (devindex <= 0) break; devindex--;