From 7c1623aec36c4a29ae23a327f99cc4e7c1f26c6f Mon Sep 17 00:00:00 2001 From: "Ronald G. Minnich" Date: Sat, 19 Jan 2008 06:29:14 +0000 Subject: [PATCH] include/device/device.h: Change the ID constants so they are more useful for debugging. Instead of simple 1,2,3 they now are a 4-byte value which can be more useful when looking at memory with a debugger. Lots of variables can be '1', but fewer variables will match to 'PCID'. include/device/pci.h: Include pci_ids.h in pci.h device/device.c: remove silly comment. Change memcpy to struct assign, this makes it possible for the C compiler to do type checking. Add assign for the dev->id. flattree.c: Support the use of 'domainid' and 'pciid' in the per-chip dts. These IDs will be assigned to the static tree device struct. In conjunction with the earlier patch, this change removes the need for users to assign the ops struct member in the dts by hand, as it is done in the qemu port today. The ops struct member will automatically be assigned by the dev_init function, which is run in stage2 before any actual device code is run. (This change to dev_init was in the previous patch). Added two comments that document what is going on. Signed-off-by: Ronald G. Minnich Acked-by: Carl-Daniel Hailfinger git-svn-id: svn://coreboot.org/repository/coreboot-v3@557 f3766cd6-281f-0410-b1cd-43a5c92072e9 --- device/device.c | 5 +++-- include/device/device.h | 30 ++++++++++++++++++++---------- include/device/pci.h | 1 + util/dtc/flattree.c | 26 ++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 12 deletions(-) diff --git a/device/device.c b/device/device.c index 3246193f80..3a2d94e382 100644 --- a/device/device.c +++ b/device/device.c @@ -209,11 +209,12 @@ struct device *alloc_dev(struct bus *parent, struct device_path *path, } dev = new_device(); - if (!dev) /* Please don't do this at home */ + if (!dev) goto out; memset(dev, 0, sizeof(*dev)); - memcpy(&dev->path, path, sizeof(*path)); + dev->path = *path; + dev->id = *devid; /* Initialize the back pointers in the link fields. */ for (link = 0; link < MAX_LINKS; link++) { diff --git a/include/device/device.h b/include/device/device.h index 37b8379915..3b3718c7f7 100644 --- a/include/device/device.h +++ b/include/device/device.h @@ -25,18 +25,28 @@ #include #include +/** + * Create a 32-bit value from four characters. This is better + * than the usual enum values when using (JTAG) debuggers. + * It also makes it harder for accidentally assigned type values + * to be mistaken for a real value -- e.g. it is more likely in the event + * of a programming error that a '1' is somehow assigned + * to the type field, whereas these values are more complex. + * Thus errors may be easier to find. + */ +#define TYPENAME(a,b,c,d) ((a<<24)|(b<<16)|(c<<8)|(d)) #define DEVICE_ID_MAX 64 enum device_id_type { - DEVICE_ID_NONE = 0, - DEVICE_ID_ROOT, - DEVICE_ID_PCI, - DEVICE_ID_PNP, - DEVICE_ID_I2C, - DEVICE_ID_APIC, - DEVICE_ID_PCI_DOMAIN, - DEVICE_ID_APIC_CLUSTER, - DEVICE_ID_CPU, - DEVICE_ID_CPU_BUS, + DEVICE_ID_NONE = 0, + DEVICE_ID_ROOT = TYPENAME('R','O','O','T'), + DEVICE_ID_PCI = TYPENAME(' ','P','C','I'), + DEVICE_ID_PNP = TYPENAME(' ','P','N','P'), + DEVICE_ID_I2C = TYPENAME(' ','I','2','C'), + DEVICE_ID_APIC = TYPENAME('A','P','I','C'), + DEVICE_ID_PCI_DOMAIN = TYPENAME('P','C','I','D'), + DEVICE_ID_APIC_CLUSTER = TYPENAME('A','P','C','C'), + DEVICE_ID_CPU = TYPENAME(' ','C','P','U'), + DEVICE_ID_CPU_BUS = TYPENAME(' ','B','U','S'), }; struct device; diff --git a/include/device/pci.h b/include/device/pci.h index 9d6eba3a72..ce9a347406 100644 --- a/include/device/pci.h +++ b/include/device/pci.h @@ -29,6 +29,7 @@ #include #include #include +#include /* * For more information, please consult the following manuals (look at diff --git a/util/dtc/flattree.c b/util/dtc/flattree.c index 828b1ed175..8243454f26 100644 --- a/util/dtc/flattree.c +++ b/util/dtc/flattree.c @@ -532,7 +532,33 @@ static void linuxbios_emit_special(FILE *e, struct node *tree) if (tree->config){ configname = clean(tree->label, 0); printf("\t.device_configuration = &%s,\n", configname); + /* The config property list for a device is derived from the + * device dts, e.g. northbridge/intel/i440bx/dts, not the + * mainboard dts. + * Almost all of these properties are specific to the device. + * Some, such as the device id, are part of the common + * device struct. Check the config properties and + * pull out those properties that are for the common + * (a.k.a. generic) device struct. + */ + /* get the properties out that are generic device props */ + for_each_config(tree, prop) { + if (streq(prop->name, "domainid")){ + fprintf(f, "\t.id = {.type=DEVICE_ID_PCI_DOMAIN,.u={.pci_domain={ %s }}},\n", + prop->val.val); + } + if (streq(prop->name, "pciid")){ + fprintf(f, "\t.id = {.type=DEVICE_ID_PCI,.u={.pci={ %s }}},\n", + prop->val.val); + } + } } + /* Process the properties specified in the mainboard dts. + * Some of these properties require special initialization + * (e.g. the path); some are flags, i.e. if the property exists + * then a variable is set to 1 (e.g. on_mainboard); + * and some are just set directly into the code (e.g. ops_pci). + */ for_each_property(tree, prop) { if (streq(prop->name, "pcidomain")){ fprintf(f, "\t.path = {.type=DEVICE_PATH_PCI_DOMAIN,.u={.pci_domain={ .domain = %s }}},\n",