diff --git a/device/agp_device.c b/device/agp_device.c index 9c28b5d7ee..9da262973a 100644 --- a/device/agp_device.c +++ b/device/agp_device.c @@ -26,23 +26,22 @@ static void agp_tune_dev(device_t dev) { - unsigned cap; + unsigned int cap; cap = pci_find_capability(dev, PCI_CAP_ID_AGP); if (!cap) { return; } - /* The OS is responsible for AGP tuning so do nothing here */ + /* The OS is responsible for AGP tuning so do nothing here. */ } -unsigned int agp_scan_bus(struct bus *bus, - unsigned min_devfn, unsigned max_devfn, unsigned int max) +unsigned int agp_scan_bus(struct bus *bus, unsigned int min_devfn, + unsigned int max_devfn, unsigned int max) { device_t child; max = pci_scan_bus(bus, min_devfn, max_devfn, max); - for(child = bus->children; child; child = child->sibling) { - if ( (child->path.u.pci.devfn < min_devfn) || - (child->path.u.pci.devfn > max_devfn)) - { + for (child = bus->children; child; child = child->sibling) { + if ((child->path.u.pci.devfn < min_devfn) || + (child->path.u.pci.devfn > max_devfn)) { continue; } agp_tune_dev(child); @@ -55,7 +54,7 @@ unsigned int agp_scan_bridge(device_t dev, unsigned int max) return do_pci_scan_bridge(dev, max, agp_scan_bus); } -/** Default device operations for AGP bridges */ +/** Default device operations for AGP bridges. */ static struct pci_operations agp_bus_ops_pci = { .set_subsystem = 0, }; @@ -64,8 +63,8 @@ struct device_operations default_agp_ops_bus = { .read_resources = pci_bus_read_resources, .set_resources = pci_dev_set_resources, .enable_resources = pci_bus_enable_resources, - .init = 0, - .scan_bus = agp_scan_bridge, + .init = 0, + .scan_bus = agp_scan_bridge, .enable = 0, .reset_bus = pci_bus_reset, .ops_pci = &agp_bus_ops_pci, diff --git a/device/cardbus_device.c b/device/cardbus_device.c index 7f770cde67..4cbb585540 100644 --- a/device/cardbus_device.c +++ b/device/cardbus_device.c @@ -30,18 +30,18 @@ * to make it usable quickly. -- Eric Biederman 24 March 2005 */ -/* - * IO should be max 256 bytes. However, since we may +/** + * I/O should be max. 256 bytes. However, since we may * have a P2P bridge below a cardbus bridge, we need 4K. */ #define CARDBUS_IO_SIZE (4096) #define CARDBUS_MEM_SIZE (32*1024*1024) -static void cardbus_record_bridge_resource( - device_t dev, resource_t moving, resource_t min_size, - unsigned index, unsigned long type) +static void cardbus_record_bridge_resource(device_t dev, resource_t moving, + resource_t min_size, unsigned int index, + unsigned long type) { - /* Initiliaze the constraints on the current bus */ + /* Initiliaze the constraints on the current bus. */ struct resource *resource; resource = 0; if (moving) { @@ -51,7 +51,7 @@ static void cardbus_record_bridge_resource( resource->size = 0; gran = 0; step = 1; - while((moving & step) == 0) { + while ((moving & step) == 0) { gran += 1; step <<= 1; } @@ -70,16 +70,16 @@ static void cardbus_record_bridge_resource( return; } -static void cardbus_size_bridge_resource(device_t dev, unsigned index) +static void cardbus_size_bridge_resource(device_t dev, unsigned int index) { struct resource *resource; resource_t min_size; resource = find_resource(dev, index); if (resource) { min_size = resource->size; - compute_allocate_resource(&dev->link[0], resource, - resource->flags, resource->flags); - /* Allways allocate at least the miniumum size to a + compute_allocate_resource(&dev->link[0], resource, + resource->flags, resource->flags); + /* Always allocate at least the minimum size to a * cardbus bridge in case a new card is plugged in. */ if (resource->size < min_size) { @@ -93,34 +93,34 @@ void cardbus_read_resources(device_t dev) resource_t moving_base, moving_limit, moving; unsigned long type; u16 ctl; - unsigned long index; + unsigned long index; - /* See if needs a card control registers base address */ + /* See if needs a card control registers base address. */ pci_get_resource(dev, PCI_BASE_ADDRESS_0); compact_resources(dev); - /* See which bridge I/O resources are implemented */ - moving_base = pci_moving_config32(dev, PCI_CB_IO_BASE_0); + /* See which bridge I/O resources are implemented. */ + moving_base = pci_moving_config32(dev, PCI_CB_IO_BASE_0); moving_limit = pci_moving_config32(dev, PCI_CB_IO_LIMIT_0); moving = moving_base & moving_limit; - /* Initialize the io space constraints on the current bus */ + /* Initialize the I/O space constraints on the current bus. */ cardbus_record_bridge_resource(dev, moving, CARDBUS_IO_SIZE, - PCI_CB_IO_BASE_0, IORESOURCE_IO); + PCI_CB_IO_BASE_0, IORESOURCE_IO); cardbus_size_bridge_resource(dev, PCI_CB_IO_BASE_0); - /* See which bridge I/O resources are implemented */ - moving_base = pci_moving_config32(dev, PCI_CB_IO_BASE_1); + /* See which bridge I/O resources are implemented. */ + moving_base = pci_moving_config32(dev, PCI_CB_IO_BASE_1); moving_limit = pci_moving_config32(dev, PCI_CB_IO_LIMIT_1); moving = moving_base & moving_limit; - /* Initialize the io space constraints on the current bus */ + /* Initialize the I/O space constraints on the current bus. */ cardbus_record_bridge_resource(dev, moving, CARDBUS_IO_SIZE, - PCI_CB_IO_BASE_1, IORESOURCE_IO); + PCI_CB_IO_BASE_1, IORESOURCE_IO); - /* If I can enable prefetch for mem0 */ + /* If I can enable prefetch for mem0. */ ctl = pci_read_config16(dev, PCI_CB_BRIDGE_CONTROL); ctl &= ~PCI_CB_BRIDGE_CTL_PREFETCH_MEM0; ctl &= ~PCI_CB_BRIDGE_CTL_PREFETCH_MEM1; @@ -128,30 +128,30 @@ void cardbus_read_resources(device_t dev) pci_write_config16(dev, PCI_CB_BRIDGE_CONTROL, ctl); ctl = pci_read_config16(dev, PCI_CB_BRIDGE_CONTROL); - /* See which bridge memory resources are implemented */ - moving_base = pci_moving_config32(dev, PCI_CB_MEMORY_BASE_0); + /* See which bridge memory resources are implemented. */ + moving_base = pci_moving_config32(dev, PCI_CB_MEMORY_BASE_0); moving_limit = pci_moving_config32(dev, PCI_CB_MEMORY_LIMIT_0); moving = moving_base & moving_limit; - /* Initialize the memory space constraints on the current bus */ + /* Initialize the memory space constraints on the current bus. */ type = IORESOURCE_MEM; if (ctl & PCI_CB_BRIDGE_CTL_PREFETCH_MEM0) { type |= IORESOURCE_PREFETCH; } cardbus_record_bridge_resource(dev, moving, CARDBUS_MEM_SIZE, - PCI_CB_MEMORY_BASE_0, type); + PCI_CB_MEMORY_BASE_0, type); if (type & IORESOURCE_PREFETCH) { cardbus_size_bridge_resource(dev, PCI_CB_MEMORY_BASE_0); } - /* See which bridge memory resources are implemented */ - moving_base = pci_moving_config32(dev, PCI_CB_MEMORY_BASE_1); + /* See which bridge memory resources are implemented. */ + moving_base = pci_moving_config32(dev, PCI_CB_MEMORY_BASE_1); moving_limit = pci_moving_config32(dev, PCI_CB_MEMORY_LIMIT_1); moving = moving_base & moving_limit; - /* Initialize the memory space constraints on the current bus */ + /* Initialize the memory space constraints on the current bus. */ cardbus_record_bridge_resource(dev, moving, CARDBUS_MEM_SIZE, - PCI_CB_MEMORY_BASE_1, IORESOURCE_MEM); + PCI_CB_MEMORY_BASE_1, IORESOURCE_MEM); cardbus_size_bridge_resource(dev, PCI_CB_MEMORY_BASE_1); compact_resources(dev); @@ -161,14 +161,16 @@ void cardbus_enable_resources(device_t dev) { u16 ctrl; ctrl = pci_read_config16(dev, PCI_CB_BRIDGE_CONTROL); - ctrl |= (dev->link[0].bridge_ctrl & ( - PCI_BRIDGE_CTL_PARITY | - PCI_BRIDGE_CTL_SERR | - PCI_BRIDGE_CTL_NO_ISA | - PCI_BRIDGE_CTL_VGA | - PCI_BRIDGE_CTL_MASTER_ABORT | - PCI_BRIDGE_CTL_BUS_RESET)); - ctrl |= (PCI_CB_BRIDGE_CTL_PARITY + PCI_CB_BRIDGE_CTL_SERR); /* error check */ + ctrl |= (dev->link[0].bridge_ctrl & (PCI_BRIDGE_CTL_PARITY | + PCI_BRIDGE_CTL_SERR | + PCI_BRIDGE_CTL_NO_ISA | + PCI_BRIDGE_CTL_VGA | + PCI_BRIDGE_CTL_MASTER_ABORT | + PCI_BRIDGE_CTL_BUS_RESET)); + + /* Error check. */ + ctrl |= (PCI_CB_BRIDGE_CTL_PARITY + PCI_CB_BRIDGE_CTL_SERR); + printk_debug("%s bridge ctrl <- %04x\n", dev_path(dev), ctrl); pci_write_config16(dev, PCI_BRIDGE_CONTROL, ctrl); @@ -177,14 +179,12 @@ void cardbus_enable_resources(device_t dev) enable_childrens_resources(dev); } -unsigned int cardbus_scan_bus(struct bus *bus, - unsigned min_devfn, unsigned max_devfn, - unsigned int max) +unsigned int cardbus_scan_bus(struct bus *bus, unsigned int min_devfn, + unsigned int max_devfn, unsigned int max) { return pci_scan_bus(bus, min_devfn, max_devfn, max); } - unsigned int cardbus_scan_bridge(device_t dev, unsigned int max) { struct bus *bus; @@ -209,8 +209,7 @@ unsigned int cardbus_scan_bridge(device_t dev, unsigned int max) pci_write_config16(dev, PCI_COMMAND, 0x0000); pci_write_config16(dev, PCI_STATUS, 0xffff); - /* - * Read the existing primary/secondary/subordinate bus + /* Read the existing primary/secondary/subordinate bus * number configuration. */ buses = pci_read_config32(dev, PCI_CB_PRIMARY_BUS); @@ -220,12 +219,12 @@ unsigned int cardbus_scan_bridge(device_t dev, unsigned int max) * correctly configured. */ buses &= 0xff000000; - buses |= (((unsigned int) (dev->bus->secondary) << 0) | - ((unsigned int) (bus->secondary) << 8) | - ((unsigned int) (bus->subordinate) << 16)); + buses |= (((unsigned int)(dev->bus->secondary) << 0) | + ((unsigned int)(bus->secondary) << 8) | + ((unsigned int)(bus->subordinate) << 16)); pci_write_config32(dev, PCI_CB_PRIMARY_BUS, buses); - /* Now we can scan all subordinate buses + /* Now we can scan all subordinate buses * i.e. the bus behind the bridge. */ max = cardbus_scan_bus(bus, 0x00, 0xff, max); @@ -234,11 +233,10 @@ unsigned int cardbus_scan_bridge(device_t dev, unsigned int max) * bus number to its real value. */ bus->subordinate = max; - buses = (buses & 0xff00ffff) | - ((unsigned int) (bus->subordinate) << 16); + buses = (buses & 0xff00ffff) | ((unsigned int)(bus->subordinate) << 16); pci_write_config32(dev, PCI_CB_PRIMARY_BUS, buses); pci_write_config16(dev, PCI_COMMAND, cr); - + printk_spew("%s returns max %d\n", __func__, max); return max; } @@ -247,8 +245,8 @@ struct device_operations default_cardbus_ops_bus = { .read_resources = cardbus_read_resources, .set_resources = pci_dev_set_resources, .enable_resources = cardbus_enable_resources, - .init = 0, - .scan_bus = cardbus_scan_bridge, + .init = 0, + .scan_bus = cardbus_scan_bridge, .enable = 0, .reset_bus = pci_bus_reset, }; diff --git a/device/device.c b/device/device.c index ccbd71536e..686bfad717 100644 --- a/device/device.c +++ b/device/device.c @@ -39,55 +39,58 @@ #warning Do we need spinlocks in device/device.c? //#include -/** Linked list of ALL devices */ +/** Linked list of all devices. */ struct device *all_devices = &dev_root; -/** Pointer to the last device -- computed at run time -- no more config tool magic */ + +/** + * Pointer to the last device -- computed at run time. + * No more config tool magic. + */ struct device **last_dev_p; -/** The upper limit of MEM resource of the devices. - * Reserve 20M for the system */ +/** + * The upper limit of MEM resource of the devices. + * Reserve 20M for the system. + */ #define DEVICE_MEM_HIGH 0xFEBFFFFFUL -/** The lower limit of IO resource of the devices. - * Reserve 4k for ISA/Legacy devices */ + +/** + * The lower limit of I/O resource of the devices. + * Reserve 4K for ISA/Legacy devices. + */ #define DEVICE_IO_START 0x1000 /** - * @brief Initialization tasks for the device tree code. + * Initialization tasks for the device tree code. * - * At present, merely sets up last_dev_p, which used to be done by Fucking Magic (FM) in config tool - * @return none - * + * At present, merely sets up last_dev_p, which used to be done by + * Fucking Magic (FM) in the config tool. */ - -void -dev_init(void) +void dev_init(void) { struct device *dev; - for(dev = all_devices; dev; dev = dev->next) { + for (dev = all_devices; dev; dev = dev->next) { last_dev_p = &dev->next; } } /** - * @brief The default constructor, which simply allocates and sets the ops pointer + * The default constructor, which simply allocates and sets the ops pointer. * - * Allocte a new device structure and initalize device->ops. + * Allocte a new device structure and initialize device->ops. * - * @param A pointer to a struct constructor - * - * @return pointer to the newly created device structure. - * - * @see + * @param constructor A pointer to a struct constructor. + * @return Pointer to the newly created device structure. */ - -struct device *default_device_constructor(struct constructor *constructor){ +struct device *default_device_constructor(struct constructor *constructor) +{ struct device *dev; dev = malloc(sizeof(*dev)); - // FIXME: This is overkill. Our malloc will never return with + // FIXME: This is overkill. Our malloc() will never return with // a return value of NULL. So this is dead code (and thus would - // drop code coverage and usability in safety critical environments + // drop code coverage and usability in safety critical environments. if (dev == NULL) { die("DEV: out of memory.\n"); } @@ -97,33 +100,31 @@ struct device *default_device_constructor(struct constructor *constructor){ } /** - * @brief Given a path, find a constructor - * - * Given a path, locate the constructor for it from all_constructors - * - * @param path path to the device to be created. - * - * @return pointer to the constructor or 0, if none found + * Given a path, locate the constructor for it from all_constructors. * + * @param path Path to the device to be created. + * @return Pointer to the constructor or 0, if none found. * @see device_path */ -struct constructor *find_constructor(struct device_id *id){ +struct constructor *find_constructor(struct device_id *id) +{ extern struct constructor *all_constructors[]; struct constructor *c; int i; printk(BIOS_SPEW, "%s: find %s\n", __func__, dev_id_string(id)); - for(i = 0; all_constructors[i]; i++) { - printk(BIOS_SPEW, "%s: check all_constructors[i] 0x%lx\n", - __func__, all_constructors[i]); - for(c = all_constructors[i]; c->ops; c++) { + for (i = 0; all_constructors[i]; i++) { + printk(BIOS_SPEW, "%s: check all_constructors[i] 0x%lx\n", + __func__, all_constructors[i]); + for (c = all_constructors[i]; c->ops; c++) { printk(BIOS_SPEW, "%s: cons 0x%lx, cons id %s\n", - __func__, c, dev_id_string(&c->id)); - if ((! c->ops) || (!c->ops->constructor)) { - printk(BIOS_INFO, "Constructor for %s with missing ops or ops->constructor!\n", - dev_id_string(&c->id)); + __func__, c, dev_id_string(&c->id)); + if ((!c->ops) || (!c->ops->constructor)) { + printk(BIOS_INFO, + "Constructor for %s with missing ops or ops->constructor!\n", + dev_id_string(&c->id)); continue; } - if (id_eq(&c->id, id)){ + if (id_eq(&c->id, id)) { printk(BIOS_SPEW, "%s: match\n", __func__); return c; } @@ -134,25 +135,24 @@ struct constructor *find_constructor(struct device_id *id){ } /** - * @brief Given a path, find a constructor, and run it + * Given a path, find a constructor, and run it. * - * Given a path, call find_constructor to find it call that - * constructor via constructor->ops->constructor, with itself as a parameter; - * return the result. - * - * @param path path to the device to be created. - * - * @return pointer to the newly created device structure. + * Given a path, call find_constructor to find the constructor for it. + * Call that constructor via constructor->ops->constructor, with itself as + * a parameter; return the result. * + * @param path Path to the device to be created. + * @return Pointer to the newly created device structure. * @see device_path */ -struct device *constructor(struct device_id *id){ +struct device *constructor(struct device_id *id) +{ struct constructor *c; - struct device *dev = 0; + struct device *dev = 0; c = find_constructor(id); printk(BIOS_DEBUG, "%s constructor is 0x%lx\n", __func__, c); - if (! c) + if (!c) return 0; dev = c->ops->constructor(c); @@ -160,37 +160,33 @@ struct device *constructor(struct device_id *id){ return dev; } - /** - * @brief Allocate a new device structure. - * - * Allocate a new device structure and attached it to the device tree as a + * Allocate a new device structure and attach it to the device tree as a * child of the parent bus. * - * @param parent parent bus the newly created device attached to. - * @param path path to the device to be created. - * - * @return pointer to the newly created device structure. - * + * @param parent Parent bus the newly created device is attached to. + * @param path Path to the device to be created. + * @return Pointer to the newly created device structure. * @see device_path */ -//static spinlock_t dev_lock = SPIN_LOCK_UNLOCKED; -struct device * alloc_dev(struct bus *parent, struct device_path *path, struct device_id *devid) +// static spinlock_t dev_lock = SPIN_LOCK_UNLOCKED; +struct device *alloc_dev(struct bus *parent, struct device_path *path, + struct device_id *devid) { - struct device * dev, *child; + struct device *dev, *child; int link; -// spin_lock(&dev_lock); +// spin_lock(&dev_lock); - /* Find the last child of our parent */ - for (child = parent->children; child && child->sibling; ) { + /* Find the last child of our parent. */ + for (child = parent->children; child && child->sibling; /* */) { child = child->sibling; } dev = constructor(devid); if (!dev) - printk(BIOS_DEBUG, "%s: No constructor, going with empty dev", - dev_id_string(devid)); + printk(BIOS_DEBUG, "%s: No constructor, going with empty dev", + dev_id_string(devid)); dev = malloc(sizeof(*dev)); if (dev == NULL) { @@ -200,13 +196,13 @@ struct device * alloc_dev(struct bus *parent, struct device_path *path, struct d memcpy(&dev->path, path, sizeof(*path)); - /* Initialize the back pointers in the link fields */ + /* Initialize the back pointers in the link fields. */ for (link = 0; link < MAX_LINKS; link++) { - dev->link[link].dev = dev; + dev->link[link].dev = dev; dev->link[link].link = link; } - /* By default devices are enabled */ + /* By default devices are enabled. */ dev->enabled = 1; /* Add the new device to the list of children of the bus. */ @@ -223,22 +219,23 @@ struct device * alloc_dev(struct bus *parent, struct device_path *path, struct d *last_dev_p = dev; last_dev_p = &dev->next; - /* give the device a name */ - dev -> dtsname = malloc(32); - if (dev->dtsname == NULL) { - die("DEV: out of memory.\n"); - } + /* Give the device a name. */ + dev->dtsname = malloc(32); + if (dev->dtsname == NULL) { + die("DEV: out of memory.\n"); + } sprintf(dev->dtsname, "dynamic %s", dev_path(dev)); -// spin_unlock(&dev_lock); + // spin_unlock(&dev_lock); return dev; } /** - * @brief round a number up to an alignment. - * @param val the starting value - * @param roundup Alignment as a power of two - * @returns rounded up number + * Round a number up to an alignment. + * + * @param val The starting value. + * @param roundup Alignment as a power of two. + * @returns Rounded up number. */ static resource_t round(resource_t val, unsigned long pow) { @@ -249,23 +246,26 @@ static resource_t round(resource_t val, unsigned long pow) return val; } -/** Read the resources on all devices of a given bus. - * @param bus bus to read the resources on. +/** + * Read the resources on all devices of a given bus. + * + * @param bus Bus to read the resources on. */ static void read_resources(struct bus *bus) { struct device *curdev; - printk(BIOS_SPEW, "%s: %s(%s) read_resources bus %d link: %d\n", - __func__, bus->dev->dtsname, dev_path(bus->dev), - bus->secondary, bus->link); + printk(BIOS_SPEW, "%s: %s(%s) read_resources bus %d link: %d\n", + __func__, bus->dev->dtsname, dev_path(bus->dev), + bus->secondary, bus->link); - /* Walk through all of the devices and find which resources they need. */ - for(curdev = bus->children; curdev; curdev = curdev->sibling) { - unsigned links; + /* Walk through all devices and find which resources they need. */ + for (curdev = bus->children; curdev; curdev = curdev->sibling) { + unsigned int links; int i; - printk(BIOS_SPEW, "%s: %s(%s) have_resources %d enabled %d\n", __func__, bus->dev->dtsname, - dev_path(bus->dev), curdev->have_resources, curdev->enabled); + printk(BIOS_SPEW, "%s: %s(%s) have_resources %d enabled %d\n", + __func__, bus->dev->dtsname, dev_path(bus->dev), + curdev->have_resources, curdev->enabled); if (curdev->have_resources) { continue; } @@ -273,24 +273,27 @@ static void read_resources(struct bus *bus) continue; } if (!curdev->ops || !curdev->ops->phase4_read_resources) { - printk(BIOS_ERR, "%s: %s(%s) missing phase4_read_resources\n", __func__, - curdev->dtsname, dev_path(curdev)); + printk(BIOS_ERR, + "%s: %s(%s) missing phase4_read_resources\n", + __func__, curdev->dtsname, dev_path(curdev)); continue; } curdev->ops->phase4_read_resources(curdev); curdev->have_resources = 1; - /* Read in subtractive resources behind the current device */ + + /* Read in subtractive resources behind the current device. */ links = 0; - for(i = 0; i < curdev->resources; i++) { + for (i = 0; i < curdev->resources; i++) { struct resource *resource; - unsigned link; + unsigned int link; resource = &curdev->resource[i]; - if (!(resource->flags & IORESOURCE_SUBTRACTIVE)) + if (!(resource->flags & IORESOURCE_SUBTRACTIVE)) continue; link = IOINDEX_SUBTRACTIVE_LINK(resource->index); if (link > MAX_LINKS) { - printk(BIOS_ERR, "%s subtractive index on link: %d\n", - dev_path(curdev), link); + printk(BIOS_ERR, + "%s subtractive index on link: %d\n", + dev_path(curdev), link); continue; } if (!(links & (1 << link))) { @@ -299,50 +302,52 @@ static void read_resources(struct bus *bus) } } } - printk(BIOS_SPEW, "%s: %s(%s) read_resources bus %d link: %d done\n", __func__, bus->dev->dtsname, - dev_path(bus->dev), bus->secondary, bus->link); + printk(BIOS_SPEW, "%s: %s(%s) read_resources bus %d link: %d done\n", + __func__, bus->dev->dtsname, dev_path(bus->dev), bus->secondary, + bus->link); } struct pick_largest_state { struct resource *last; - struct device *result_dev; + struct device *result_dev; struct resource *result; int seen_last; }; -static void pick_largest_resource(void *gp, - struct device *dev, struct resource *resource) +static void pick_largest_resource(void *gp, struct device *dev, + struct resource *resource) { struct pick_largest_state *state = gp; struct resource *last; + last = state->last; - /* Be certain to pick the successor to last */ + + /* Be certain to pick the successor to last. */ if (resource == last) { state->seen_last = 1; return; } - if (resource->flags & IORESOURCE_FIXED ) return; //skip it - if (last && ( - (last->align < resource->align) || - ((last->align == resource->align) && - (last->size < resource->size)) || - ((last->align == resource->align) && - (last->size == resource->size) && - (!state->seen_last)))) { + if (resource->flags & IORESOURCE_FIXED) + return; // Skip it. + if (last && ((last->align < resource->align) || + ((last->align == resource->align) && + (last->size < resource->size)) || + ((last->align == resource->align) && + (last->size == resource->size) && (!state->seen_last)))) { return; } - if (!state->result || - (state->result->align < resource->align) || - ((state->result->align == resource->align) && - (state->result->size < resource->size))) - { + if (!state->result || + (state->result->align < resource->align) || + ((state->result->align == resource->align) && + (state->result->size < resource->size))) { state->result_dev = dev; state->result = resource; - } + } } -static struct device *largest_resource(struct bus *bus, struct resource - **result_res, unsigned long type_mask, unsigned long type) +static struct device *largest_resource(struct bus *bus, struct resource + **result_res, unsigned long type_mask, + unsigned long type) { struct pick_largest_state state; @@ -351,46 +356,47 @@ static struct device *largest_resource(struct bus *bus, struct resource state.result = 0; state.seen_last = 0; - search_bus_resources(bus, type_mask, type, pick_largest_resource, &state); + search_bus_resources(bus, type_mask, type, pick_largest_resource, + &state); *result_res = state.result; return state.result_dev; } -/* Compute allocate resources is the guts of the resource allocator. +/** + * This function is the guts of the resource allocator. * * The problem. - * - Allocate resources locations for every device. + * - Allocate resource locations for every device. * - Don't overlap, and follow the rules of bridges. * - Don't overlap with resources in fixed locations. * - Be efficient so we don't have ugly strategies. * * The strategy. * - Devices that have fixed addresses are the minority so don't - * worry about them too much. Instead only use part of the address - * space for devices with programmable addresses. This easily handles + * worry about them too much. Instead only use part of the address + * space for devices with programmable addresses. This easily handles * everything except bridges. * - * - PCI devices are required to have thier sizes and their alignments - * equal. In this case an optimal solution to the packing problem - * exists. Allocate all devices from highest alignment to least - * alignment or vice versa. Use this. + * - PCI devices are required to have their sizes and their alignments + * equal. In this case an optimal solution to the packing problem + * exists. Allocate all devices from highest alignment to least + * alignment or vice versa. Use this. * - * - So we can handle more than PCI run two allocation passes on - * bridges. The first to see how large the resources are behind - * the bridge, and what their alignment requirements are. The - * second to assign a safe address to the devices behind the - * bridge. This allows me to treat a bridge as just a device with - * a couple of resources, and not need to special case it in the - * allocator. Also this allows handling of other types of bridges. + * - So we can handle more than PCI run two allocation passes on bridges. The + * first to see how large the resources are behind the bridge, and what + * their alignment requirements are. The second to assign a safe address to + * the devices behind the bridge. This allows us to treat a bridge as just + * a device with a couple of resources, and not need to special case it in + * the allocator. Also this allows handling of other types of bridges. * + * @param bus TODO + * @param bridge TODO + * @param type_mask TODO + * @param type TODO */ - -void compute_allocate_resource( - struct bus *bus, - struct resource *bridge, - unsigned long type_mask, - unsigned long type) +void compute_allocate_resource(struct bus *bus, struct resource *bridge, + unsigned long type_mask, unsigned long type) { struct device *dev; struct resource *resource; @@ -399,15 +405,11 @@ void compute_allocate_resource( min_align = 0; base = bridge->base; - printk(BIOS_SPEW, "%s compute_allocate_%s: base: %08Lx size: %08Lx align: %d gran: %d\n", - dev_path(bus->dev), - (bridge->flags & IORESOURCE_IO)? "io": - (bridge->flags & IORESOURCE_PREFETCH)? "prefmem" : "mem", - base, bridge->size, bridge->align, bridge->gran); + printk(BIOS_SPEW, "%s compute_allocate_%s: base: %08Lx size: %08Lx align: %d gran: %d\n", dev_path(bus->dev), (bridge->flags & IORESOURCE_IO) ? "io" : (bridge->flags & IORESOURCE_PREFETCH) ? "prefmem" : "mem", base, bridge->size, bridge->align, bridge->gran); /* We want different minimum alignments for different kinds of - * resources. These minimums are not device type specific - * but resource type specific. + * resources. These minimums are not device type specific but + * resource type specific. */ if (bridge->flags & IORESOURCE_IO) { min_align = log2(DEVICE_IO_ALIGN); @@ -416,28 +418,30 @@ void compute_allocate_resource( min_align = log2(DEVICE_MEM_ALIGN); } - /* Make certain I have read in all of the resources */ + /* Make certain we have read in all of the resources. */ read_resources(bus); - /* Remember I haven't found anything yet. */ + /* Remember we haven't found anything yet. */ resource = 0; /* Walk through all the devices on the current bus and * compute the addresses. */ - while((dev = largest_resource(bus, &resource, type_mask, type))) { + while ((dev = largest_resource(bus, &resource, type_mask, type))) { resource_t size; - /* Do NOT I repeat do not ignore resources which have zero size. - * If they need to be ignored dev->read_resources should not even - * return them. Some resources must be set even when they have - * no size. PCI bridge resources are a good example of this. + + /* Do NOT, I repeat do not, ignore resources which have zero + * size. If they need to be ignored dev->read_resources should + * not even return them. Some resources must be set even when + * they have no size. PCI bridge resources are a good example + * of this. */ - /* Propogate the resource alignment to the bridge register */ + /* Propagate the resource alignment to the bridge register. */ if (resource->align > bridge->align) { bridge->align = resource->align; } - /* Make certain we are dealing with a good minimum size */ + /* Make certain we are dealing with a good minimum size. */ size = resource->size; align = resource->align; if (align < min_align) { @@ -448,77 +452,73 @@ void compute_allocate_resource( continue; } - /* Propogate the resource limit to the bridge register */ + /* Propagate the resource limit to the bridge register. */ if (bridge->limit > resource->limit) { bridge->limit = resource->limit; } - /* Artificially deny limits between DEVICE_MEM_HIGH and 0xffffffff */ - if ((bridge->limit > DEVICE_MEM_HIGH) && (bridge->limit <= 0xffffffff)) { + + /* Artificially deny limits between DEVICE_MEM_HIGH and 0xffffffff. */ + if ((bridge->limit > DEVICE_MEM_HIGH) + && (bridge->limit <= 0xffffffff)) { bridge->limit = DEVICE_MEM_HIGH; } if (resource->flags & IORESOURCE_IO) { - /* Don't allow potential aliases over the - * legacy pci expansion card addresses. - * The legacy pci decodes only 10 bits, - * uses 100h - 3ffh. Therefor, only 0 - ff - * can be used out of each 400h block of io - * space. + /* Don't allow potential aliases over the legacy PCI + * expansion card addresses. The legacy PCI decodes + * only 10 bits, uses 0x100 - 0x3ff. Therefore, only + * 0x00 - 0xff can be used out of each 0x400 block of + * I/O space. */ if ((base & 0x300) != 0) { base = (base & ~0x3ff) + 0x400; } - /* Don't allow allocations in the VGA IO range. + /* Don't allow allocations in the VGA I/O range. * PCI has special cases for that. */ else if ((base >= 0x3b0) && (base <= 0x3df)) { base = 0x3e0; } } - if (((round(base, align) + size) -1) <= resource->limit) { - /* base must be aligned to size */ + if (((round(base, align) + size) - 1) <= resource->limit) { + /* Base must be aligned to size. */ base = round(base, align); resource->base = base; resource->flags |= IORESOURCE_ASSIGNED; resource->flags &= ~IORESOURCE_STORED; base += size; - - printk(BIOS_SPEW, - "%s %02x * [0x%08Lx - 0x%08Lx] %s\n", - dev_path(dev), - resource->index, - resource->base, - resource->base + resource->size - 1, - (resource->flags & IORESOURCE_IO)? "io": - (resource->flags & IORESOURCE_PREFETCH)? "prefmem": "mem"); + + printk(BIOS_SPEW, + "%s %02x * [0x%08Lx - 0x%08Lx] %s\n", + dev_path(dev), + resource->index, + resource->base, + resource->base + resource->size - 1, + (resource->flags & IORESOURCE_IO) ? "io" : + (resource-> + flags & IORESOURCE_PREFETCH) ? "prefmem" : + "mem"); } } - /* A pci bridge resource does not need to be a power - * of two size, but it does have a minimum granularity. - * Round the size up to that minimum granularity so we - * know not to place something else at an address postitively - * decoded by the bridge. + /* A PCI bridge resource does not need to be a power of two size, but + * it does have a minimum granularity. Round the size up to that + * minimum granularity so we know not to place something else at an + * address postitively decoded by the bridge. */ bridge->size = round(base, bridge->gran) - bridge->base; - printk(BIOS_SPEW, "%s compute_allocate_%s: base: %08Lx size: %08Lx align: %d gran: %d done\n", - dev_path(bus->dev), - (bridge->flags & IORESOURCE_IO)? "io": - (bridge->flags & IORESOURCE_PREFETCH)? "prefmem" : "mem", - base, bridge->size, bridge->align, bridge->gran); - - + printk(BIOS_SPEW, "%s compute_allocate_%s: base: %08Lx size: %08Lx align: %d gran: %d done\n", dev_path(bus->dev), (bridge->flags & IORESOURCE_IO) ? "io" : (bridge->flags & IORESOURCE_PREFETCH) ? "prefmem" : "mem", base, bridge->size, bridge->align, bridge->gran); } #if defined(CONFIG_PCI_OPTION_ROM_RUN) && CONFIG_PCI_OPTION_ROM_RUN == 1 -struct device * vga_pri = 0; +struct device *vga_pri = 0; int vga_inited = 0; static void allocate_vga_resource(void) { -#warning Modify allocate_vga_resource so it is less pci centric. - // FIXME: This function knows to much about PCI stuff, +#warning Modify allocate_vga_resource so it is less PCI centric. + // FIXME: This function knows too much about PCI stuff, // it should just be an iterator/visitor. - /* FIXME: handle the VGA pallette snooping */ + /* FIXME: Handle the VGA pallette snooping. */ struct device *dev, *vga, *vga_onboard, *vga_first, *vga_last; struct bus *bus; bus = 0; @@ -526,71 +526,67 @@ static void allocate_vga_resource(void) vga_onboard = 0; vga_first = 0; vga_last = 0; - for(dev = all_devices; dev; dev = dev->next) { - if (!dev->enabled) continue; + for (dev = all_devices; dev; dev = dev->next) { + if (!dev->enabled) + continue; if (((dev->class >> 16) == PCI_BASE_CLASS_DISPLAY) && - ((dev->class >> 8) != PCI_CLASS_DISPLAY_OTHER)) - { - if (!vga_first) { - if (dev->on_mainboard) { - vga_onboard = dev; - } else { - vga_first = dev; - } - } else { - if (dev->on_mainboard) { - vga_onboard = dev; - } else { - vga_last = dev; - } - } + ((dev->class >> 8) != PCI_CLASS_DISPLAY_OTHER)) { + if (!vga_first) { + if (dev->on_mainboard) { + vga_onboard = dev; + } else { + vga_first = dev; + } + } else { + if (dev->on_mainboard) { + vga_onboard = dev; + } else { + vga_last = dev; + } + } - /* It isn't safe to enable other VGA cards */ + /* It isn't safe to enable other VGA cards. */ dev->command &= ~(PCI_COMMAND_MEMORY | PCI_COMMAND_IO); } } - - vga = vga_last; - if(!vga) { - vga = vga_first; - } + vga = vga_last; + if (!vga) { + vga = vga_first; + } #if defined(CONFIG_INITIALIZE_ONBOARD_VGA_FIRST) && \ CONFIG_INITIALIZE_ONBOARD_VGA_FIRST == 1 - if (vga_onboard) // will use on board vga as pri + if (vga_onboard) // Will use on board VGA as pri. #else - if (!vga) // will use last add on adapter as pri + if (!vga) // Will use last add on adapter as pri. #endif - { - vga = vga_onboard; - } + { + vga = vga_onboard; + } - if (vga) { - /* vga is first add on card or the only onboard vga */ - printk(BIOS_DEBUG, "Allocating VGA resource %s\n", dev_path(vga)); - /* All legacy VGA cards have MEM & I/O space registers */ + /* VGA is first add on card or the only onboard VGA. */ + printk(BIOS_DEBUG, "Allocating VGA resource %s\n", + dev_path(vga)); + /* All legacy VGA cards have MEM & I/O space registers. */ vga->command |= (PCI_COMMAND_MEMORY | PCI_COMMAND_IO); vga_pri = vga; bus = vga->bus; } - /* Now walk up the bridges setting the VGA enable */ - while(bus) { + /* Now walk up the bridges setting the VGA enable. */ + while (bus) { printk(BIOS_DEBUG, "Setting PCI_BRIDGE_CTL_VGA for bridge %s\n", - dev_path(bus->dev)); + dev_path(bus->dev)); bus->bridge_ctrl |= PCI_BRIDGE_CTL_VGA; - bus = (bus == bus->dev->bus)? 0 : bus->dev->bus; - } + bus = (bus == bus->dev->bus) ? 0 : bus->dev->bus; + } } #endif - /** - * @brief Assign the computed resources to the devices on the bus. - * - * @param bus Pointer to the structure for this bus + * Assign the computed resources to the devices on the bus. * * Use the device specific set_resources method to store the computed * resources to hardware. For bridge devices, the set_resources() method @@ -599,51 +595,54 @@ static void allocate_vga_resource(void) * Mutual recursion: * assign_resources() -> device_operation::set_resources() * device_operation::set_resources() -> assign_resources() + * + * @param bus Pointer to the structure for this bus. */ void phase4_assign_resources(struct bus *bus) { struct device *curdev; - printk(BIOS_SPEW, "%s(%s) assign_resources, bus %d link: %d\n", - bus->dev->dtsname, dev_path(bus->dev), bus->secondary, bus->link); + printk(BIOS_SPEW, "%s(%s) assign_resources, bus %d link: %d\n", + bus->dev->dtsname, dev_path(bus->dev), bus->secondary, + bus->link); - for(curdev = bus->children; curdev; curdev = curdev->sibling) { + for (curdev = bus->children; curdev; curdev = curdev->sibling) { if (!curdev->enabled || !curdev->resources) { continue; } if (!curdev->ops) { printk(BIOS_WARNING, "%s(%s) missing ops\n", - curdev->dtsname, dev_path(curdev)); + curdev->dtsname, dev_path(curdev)); continue; } if (!curdev->ops->phase4_set_resources) { - printk(BIOS_WARNING, "%s(%s) ops has no missing phase4_set_resources\n", - curdev->dtsname, dev_path(curdev)); + printk(BIOS_WARNING, + "%s(%s) ops has no missing phase4_set_resources\n", + curdev->dtsname, dev_path(curdev)); continue; } curdev->ops->phase4_set_resources(curdev); } - printk(BIOS_SPEW, "%s(%s) assign_resources, bus %d link: %d\n", - bus->dev->dtsname, dev_path(bus->dev), bus->secondary, bus->link); + printk(BIOS_SPEW, "%s(%s) assign_resources, bus %d link: %d\n", + bus->dev->dtsname, dev_path(bus->dev), bus->secondary, + bus->link); } /** - * @brief Enable the resources for a specific device - * - * @param dev the device whose resources are to be enabled - * - * Enable resources of the device by calling the device specific + * Enable the resources of the device by calling the device specific * phase5() method. * * The parent's resources should be enabled first to avoid having enabling - * order problem. This is done by calling the parent's phase5() - * method and let that method to call it's children's phase5() - * method via the (global) phase5_children(). + * order problem. This is done by calling the parent's phase5() method and + * let that method to call it's children's phase5() method via the (global) + * phase5_children(). * * Indirect mutual recursion: * dev_phase5() -> device_operations::phase5() * device_operations::phase5() -> phase5_children() * phase5_children() -> dev_phase5() + * + * @param dev The device whose resources are to be enabled. */ void dev_phase5(struct device *dev) { @@ -651,12 +650,14 @@ void dev_phase5(struct device *dev) return; } if (!dev->ops) { - printk(BIOS_WARNING, "%s: %s(%s) missing ops\n", - __FUNCTION__, dev->dtsname, dev_path(dev)); + printk(BIOS_WARNING, "%s: %s(%s) missing ops\n", + __FUNCTION__, dev->dtsname, dev_path(dev)); return; } if (!dev->ops->phase5_enable_resources) { - printk(BIOS_WARNING, "%s: %s(%s) ops are missing phase5_enable_resources\n", __FUNCTION__, dev->dtsname, dev_path(dev)); + printk(BIOS_WARNING, + "%s: %s(%s) ops are missing phase5_enable_resources\n", + __FUNCTION__, dev->dtsname, dev_path(dev)); return; } @@ -664,19 +665,14 @@ void dev_phase5(struct device *dev) } /** - * @brief Reset all of the devices a bus - * * Reset all of the devices on a bus and clear the bus's reset_needed flag. * - * @param bus pointer to the bus structure - * + * @param bus Pointer to the bus structure. * @return 1 if the bus was successfully reset, 0 otherwise. - * */ int reset_bus(struct bus *bus) { - if (bus && bus->dev && bus->dev->ops && bus->dev->ops->reset_bus) - { + if (bus && bus->dev && bus->dev->ops && bus->dev->ops->reset_bus) { bus->dev->ops->reset_bus(bus); bus->reset_needed = 0; return 1; @@ -685,21 +681,20 @@ int reset_bus(struct bus *bus) } /** - * @brief Do very early setup for all devices in the global device list. + * Do very early setup for all devices in the global device list. * * Starting at the first device on the global device link list, * walk the list and call the device's phase1() method to do very - * early setup. phase1 should only used for devices that CAN NOT use printk, - * or that are part of making printk work. + * early setup. phase1 should only be used for devices that CAN NOT use + * printk(), or that are part of making printk() work. */ void dev_phase1(void) { struct device *dev; post_code(0x31); - for(dev = all_devices; dev; dev = dev->next) { - if (dev->ops && dev->ops->phase1_set_device_operations) - { + for (dev = all_devices; dev; dev = dev->next) { + if (dev->ops && dev->ops->phase1_set_device_operations) { dev->ops->phase1_set_device_operations(dev); } } @@ -709,7 +704,7 @@ void dev_phase1(void) } /** - * @brief Do early setup for all devices in the global device list. + * Do early setup for all devices in the global device list. * * Starting at the first device on the global device link list, * walk the list and call the device's phase2() method to do @@ -721,10 +716,11 @@ void dev_phase2(void) post_code(0x41); printk(BIOS_DEBUG, "Phase 2: Early setup...\n"); - for(dev = all_devices; dev; dev = dev->next) { + for (dev = all_devices; dev; dev = dev->next) { printk(BIOS_SPEW, "%s: dev %s: ", __FUNCTION__, dev->dtsname); if (dev->ops && dev->ops->phase2_setup_scan_bus) { - printk(BIOS_SPEW, "Calling phase2 phase2_setup_scan_bus .."); + printk(BIOS_SPEW, + "Calling phase2 phase2_setup_scan_bus..."); dev->ops->phase2_setup_scan_bus(dev); printk(BIOS_SPEW, " DONE"); } @@ -737,32 +733,29 @@ void dev_phase2(void) } /** - * @brief Scan for devices on a bus. + * Scan for devices on a bus. * - * If there are bridges on the bus, recursively scan the buses behind the bridges. - * If the setting up and tuning of the bus causes a reset to be required, - * reset the bus and scan it again. + * If there are bridges on the bus, recursively scan the buses behind the + * bridges. If the setting up and tuning of the bus causes a reset to be + * required, reset the bus and scan it again. * - * @param bus pointer to the bus device - * @param max current bus number - * - * @return The maximum bus number found, after scanning all subordinate busses + * @param bus Pointer to the bus device. + * @param max Current bus number. + * @return The maximum bus number found, after scanning all subordinate buses. */ -unsigned int dev_phase3_scan(struct device * busdevice, unsigned int max) +unsigned int dev_phase3_scan(struct device *busdevice, unsigned int max) { unsigned int new_max; int do_phase3; post_code(0x42); - if ( !busdevice || - !busdevice->enabled || - !busdevice->ops || - !busdevice->ops->phase3_scan) - { - printk(BIOS_INFO, "%s: %s: busdevice %p enabled %d ops %p\n" , __FUNCTION__, - busdevice->dtsname, - busdevice, busdevice ? busdevice->enabled : 0, - busdevice ? busdevice->ops : NULL); - printk(BIOS_INFO, "%s: can not scan from here, returning %d\n", __FUNCTION__, max); + if (!busdevice || !busdevice->enabled || + !busdevice->ops || !busdevice->ops->phase3_scan) { + printk(BIOS_INFO, "%s: %s: busdevice %p enabled %d ops %p\n", + __FUNCTION__, busdevice->dtsname, busdevice, + busdevice ? busdevice->enabled : 0, + busdevice ? busdevice->ops : NULL); + printk(BIOS_INFO, "%s: can not scan from here, returning %d\n", + __FUNCTION__, max); return max; } @@ -770,12 +763,13 @@ unsigned int dev_phase3_scan(struct device * busdevice, unsigned int max) busdevice->ops->phase3_enable_scan(busdevice); do_phase3 = 1; - while(do_phase3) { + while (do_phase3) { int link; - printk(BIOS_INFO, "%s: scanning %s(%s)\n", __FUNCTION__, busdevice->dtsname, dev_path(busdevice)); + printk(BIOS_INFO, "%s: scanning %s(%s)\n", __FUNCTION__, + busdevice->dtsname, dev_path(busdevice)); new_max = busdevice->ops->phase3_scan(busdevice, max); do_phase3 = 0; - for(link = 0; link < busdevice->links; link++) { + for (link = 0; link < busdevice->links; link++) { if (busdevice->link[link].reset_needed) { if (reset_bus(&busdevice->link[link])) { do_phase3 = 1; @@ -790,15 +784,15 @@ unsigned int dev_phase3_scan(struct device * busdevice, unsigned int max) return new_max; } - /** - * @brief Determine the existence of devices and extend the device tree. + * Determine the existence of devices and extend the device tree. * * Most of the devices in the system are listed in the mainboard Config.lb * file. The device structures for these devices are generated at compile * time by the config tool and are organized into the device tree. This * function determines if the devices created at compile time actually exist * in the physical system. + * TODO: Fix comment, v3 doesn't have Config.lb files. * * For devices in the physical system but not listed in the Config.lb file, * the device structures have to be created at run time and attached to the @@ -816,7 +810,8 @@ unsigned int dev_phase3_scan(struct device * busdevice, unsigned int max) void dev_root_phase3(void) { struct device *root; - unsigned subordinate; + unsigned int subordinate; + printk(BIOS_INFO, "Phase 3: Enumerating buses...\n"); root = &dev_root; @@ -825,11 +820,13 @@ void dev_root_phase3(void) } post_code(0x41); if (!root->ops) { - printk(BIOS_ERR, "dev_root_phase3 missing 'ops' initialization\nPhase 3: Failed.\n"); + printk(BIOS_ERR, + "dev_root_phase3 missing 'ops' initialization\nPhase 3: Failed.\n"); return; } if (!root->ops->phase3_scan) { - printk(BIOS_ERR, "dev_root ops struct missing 'phase3' initialization in ops structure\nPhase 3: Failed."); + printk(BIOS_ERR, + "dev_root ops struct missing 'phase3' initialization in ops structure\nPhase 3: Failed."); return; } subordinate = dev_phase3_scan(root, 0); @@ -837,11 +834,11 @@ void dev_root_phase3(void) } /** - * @brief Configure devices on the devices tree. + * Configure devices on the device tree. * * Starting at the root of the device tree, travel it recursively in two * passes. In the first pass, we compute and allocate resources (ranges) - * requried by each device. In the second pass, the resources ranges are + * required by each device. In the second pass, the resources ranges are * relocated to their final position and stored to the hardware. * * I/O resources start at DEVICE_IO_START and grow upward. MEM resources start @@ -859,16 +856,19 @@ void dev_phase4(void) root = &dev_root; if (!root->ops) { - printk(BIOS_ERR, "Phase 4: dev_root missing ops initialization\nPhase 4: Failed.\n"); + printk(BIOS_ERR, + "Phase 4: dev_root missing ops initialization\nPhase 4: Failed.\n"); return; - } + } if (!root->ops->phase4_read_resources) { - printk(BIOS_ERR, "dev_root ops missing read_resources\nPhase 4: Failed.\n"); + printk(BIOS_ERR, + "dev_root ops missing read_resources\nPhase 4: Failed.\n"); return; } if (!root->ops->phase4_set_resources) { - printk(BIOS_ERR, "dev_root ops missing set_resources\nPhase 4: Failed.\n"); + printk(BIOS_ERR, + "dev_root ops missing set_resources\nPhase 4: Failed.\n"); return; } @@ -876,14 +876,16 @@ void dev_phase4(void) root->ops->phase4_read_resources(root); printk(BIOS_INFO, "Phase 4: Done reading resources.\n"); - /* Get the resources */ - io = &root->resource[0]; + /* Get the resources. */ + io = &root->resource[0]; mem = &root->resource[1]; - /* Make certain the io devices are allocated somewhere safe. */ + + /* Make certain the I/O devices are allocated somewhere safe. */ io->base = DEVICE_IO_START; io->flags |= IORESOURCE_ASSIGNED; io->flags &= ~IORESOURCE_STORED; - /* Now reallocate the pci resources memory with the + + /* Now reallocate the PCI resources memory with the * highest addresses I can manage. */ mem->base = resource_max(&root->resource[1]); @@ -891,11 +893,11 @@ void dev_phase4(void) mem->flags &= ~IORESOURCE_STORED; #if defined(CONFIG_PCI_OPTION_ROM_RUN) && CONFIG_PCI_OPTION_ROM_RUN == 1 - /* Allocate the VGA I/O resource.. */ - allocate_vga_resource(); + /* Allocate the VGA I/O resource. */ + allocate_vga_resource(); #endif - /* Store the computed resource allocations into device registers ... */ + /* Store the computed resource allocations into device registers. */ printk(BIOS_INFO, "Phase 4: Setting resources...\n"); root->ops->phase4_set_resources(root); printk(BIOS_INFO, "Phase 4: Done setting resources.\n"); @@ -908,7 +910,7 @@ void dev_phase4(void) } /** - * @brief Enable devices on the device tree. + * Enable devices on the device tree. * * Starting at the root, walk the tree and enable all devices/bridges by * calling the device's enable_resources() method. @@ -917,33 +919,32 @@ void dev_root_phase5(void) { printk(BIOS_INFO, "Phase 5: Enabling resources...\n"); - /* now enable everything. */ + /* Now enable everything. */ dev_phase5(&dev_root); printk(BIOS_INFO, "Phase 5: Done.\n"); } /** - * @brief Initialize all devices in the global device list. + * Initialize all devices in the global device list. * - * Starting at the first device on the global device link list, - * walk the list and call the device's init() method to do deivce - * specific setup. + * Starting at the first device on the global device link list, walk the list + * and call the device's init() method to do device specific setup. */ void dev_phase6(void) { struct device *dev; printk(BIOS_INFO, "Phase 6: Initializing devices...\n"); - for(dev = all_devices; dev; dev = dev->next) { - if (dev->enabled && !dev->initialized && - dev->ops && dev->ops->phase6_init) - { + for (dev = all_devices; dev; dev = dev->next) { + if (dev->enabled && !dev->initialized && + dev->ops && dev->ops->phase6_init) { if (dev->path.type == DEVICE_PATH_I2C) { - printk(BIOS_DEBUG, "Phase 6: smbus: %s[%d]->", - dev_path(dev->bus->dev), dev->bus->link); + printk(BIOS_DEBUG, "Phase 6: smbus: %s[%d]->", + dev_path(dev->bus->dev), dev->bus->link); } - printk(BIOS_DEBUG, "Phase 6: %s init.\n", dev_path(dev)); + printk(BIOS_DEBUG, "Phase 6: %s init.\n", + dev_path(dev)); dev->initialized = 1; dev->ops->phase6_init(dev); } @@ -951,15 +952,15 @@ void dev_phase6(void) printk(BIOS_INFO, "Phase 6: Devices initialized.\n"); } +void show_all_devs(void) +{ + struct device *dev; -void show_all_devs(void) { - - struct device *dev; - - printk(BIOS_INFO, "Show all devs...\n"); - for(dev = all_devices; dev; dev = dev->next) { - printk(BIOS_SPEW, "%s(%s): enabled %d have_resources %d initialized %d\n", - dev->dtsname, dev_path(dev), dev->enabled, dev->have_resources, dev->initialized); - } + printk(BIOS_INFO, "Show all devs...\n"); + for (dev = all_devices; dev; dev = dev->next) { + printk(BIOS_SPEW, + "%s(%s): enabled %d have_resources %d initialized %d\n", + dev->dtsname, dev_path(dev), dev->enabled, + dev->have_resources, dev->initialized); + } } - diff --git a/device/device_util.c b/device/device_util.c index d99ccc548a..fb012aebc9 100644 --- a/device/device_util.c +++ b/device/device_util.c @@ -31,17 +31,17 @@ #include /** - * @brief See if a device structure exists for path + * See if a device structure exists for path. * - * @param bus The bus to find the device on - * @param path The relative path from the bus to the appropriate device - * @return pointer to a device structure for the device on bus at path - * or 0/NULL if no device is found + * @param bus The bus to find the device on. + * @param path The relative path from the bus to the appropriate device. + * @return Pointer to a device structure for the device on bus at path + * or 0/NULL if no device is found. */ -struct device * find_dev_path(struct bus *parent, struct device_path *path) +struct device *find_dev_path(struct bus *parent, struct device_path *path) { - struct device * child; - for(child = parent->children; child; child = child->sibling) { + struct device *child; + for (child = parent->children; child; child = child->sibling) { if (path_eq(path, &child->path)) { break; } @@ -50,15 +50,16 @@ struct device * find_dev_path(struct bus *parent, struct device_path *path) } /** - * @brief See if a device structure already exists and if not allocate it + * See if a device structure already exists and if not allocate it. * - * @param bus The bus to find the device on - * @param path The relative path from the bus to the appropriate device - * @return pointer to a device structure for the device on bus at path + * @param bus The bus to find the device on. + * @param path The relative path from the bus to the appropriate device. + * @return Pointer to a device structure for the device on bus at path. */ -struct device * alloc_find_dev(struct bus *parent, struct device_path *path, struct device_id *id) +struct device *alloc_find_dev(struct bus *parent, struct device_path *path, + struct device_id *id) { - struct device * child; + struct device *child; child = find_dev_path(parent, path); if (!child) { child = alloc_dev(parent, path, id); @@ -67,11 +68,11 @@ struct device * alloc_find_dev(struct bus *parent, struct device_path *path, str } /** - * @brief Given a PCI bus and a devfn number, find the device structure + * Given a PCI bus and a devfn number, find the device structure. * - * @param bus The bus number - * @param devfn a device/function number - * @return pointer to the device structure + * @param bus The bus number. + * @param devfn A device/function number. + * @return Pointer to the device structure. */ struct device *dev_find_slot(unsigned int bus, unsigned int devfn) { @@ -80,8 +81,8 @@ struct device *dev_find_slot(unsigned int bus, unsigned int devfn) result = 0; for (dev = all_devices; dev; dev = dev->next) { if ((dev->path.type == DEVICE_PATH_PCI) && - (dev->bus->secondary == bus) && - (dev->path.u.pci.devfn == devfn)) { + (dev->bus->secondary == bus) && + (dev->path.u.pci.devfn == devfn)) { result = dev; break; } @@ -90,37 +91,40 @@ struct device *dev_find_slot(unsigned int bus, unsigned int devfn) } /** - * @brief Given a smbus bus and a device number, find the device structure + * Given a smbus bus and a device number, find the device structure. * - * @param bus The bus number - * @param addr a device number - * @return pointer to the device structure + * @param bus The bus number. + * @param addr A device number. + * @return Pointer to the device structure. */ struct device *dev_find_slot_on_smbus(unsigned int bus, unsigned int addr) { - struct device *dev, *result; - - result = 0; - for (dev = all_devices; dev; dev = dev->next) { - if ((dev->path.type == DEVICE_PATH_I2C) && - (dev->bus->secondary == bus) && - (dev->path.u.i2c.device == addr)) { - result = dev; - break; - } - } - return result; -} + struct device *dev, *result; -/** Find a device of a given vendor and type + result = 0; + for (dev = all_devices; dev; dev = dev->next) { + if ((dev->path.type == DEVICE_PATH_I2C) && + (dev->bus->secondary == bus) && + (dev->path.u.i2c.device == addr)) { + result = dev; + break; + } + } + return result; +} + +/** + * Find a device of a given vendor and type. + * * @param vendor Vendor ID (e.g. 0x8086 for Intel) * @param device Device ID * @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 + * 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(unsigned int vendor, unsigned int device, + struct device *from) { if (!from) from = all_devices; @@ -132,12 +136,14 @@ struct device *dev_find_device(unsigned int vendor, unsigned int device, struct return from; } -/** Find a device of a given class - * @param class Class of the device +/** + * Find a device of a given class. + * + * @param class Class of the device. * @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 + * 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_class(unsigned int class, struct device *from) { @@ -150,29 +156,30 @@ struct device *dev_find_class(unsigned int class, struct device *from) return from; } - -/* WARNING: NOT SMP-safe!*/ -const char *dev_path(struct device * dev) +/* WARNING: NOT SMP-safe! */ +const char *dev_path(struct device *dev) { static char buffer[DEVICE_PATH_MAX]; buffer[0] = '\0'; if (!dev) { memcpy(buffer, "", 7); - } - else { - switch(dev->path.type) { + } else { + switch (dev->path.type) { case DEVICE_PATH_ROOT: memcpy(buffer, "Root Device", 12); break; case DEVICE_PATH_PCI: #if PCI_BUS_SEGN_BITS sprintf(buffer, "PCI: %04x:%02x:%02x.%01x", - dev->bus->secondary>>8, dev->bus->secondary & 0xff, - PCI_SLOT(dev->path.u.pci.devfn), PCI_FUNC(dev->path.u.pci.devfn)); + dev->bus->secondary >> 8, + dev->bus->secondary & 0xff, + PCI_SLOT(dev->path.u.pci.devfn), + PCI_FUNC(dev->path.u.pci.devfn)); #else sprintf(buffer, "PCI: %02x:%02x.%01x", - dev->bus->secondary, - PCI_SLOT(dev->path.u.pci.devfn), PCI_FUNC(dev->path.u.pci.devfn)); + dev->bus->secondary, + PCI_SLOT(dev->path.u.pci.devfn), + PCI_FUNC(dev->path.u.pci.devfn)); #endif break; case DEVICE_PATH_PNP: @@ -181,12 +188,10 @@ const char *dev_path(struct device * dev) break; case DEVICE_PATH_I2C: sprintf(buffer, "I2C: %02x:%02x", - dev->bus->secondary, - dev->path.u.i2c.device); + dev->bus->secondary, dev->path.u.i2c.device); break; case DEVICE_PATH_APIC: - sprintf(buffer, "APIC: %02x", - dev->path.u.apic.apic_id); + sprintf(buffer, "APIC: %02x", dev->path.u.apic.apic_id); break; case DEVICE_PATH_PCI_DOMAIN: sprintf(buffer, "PCI_DOMAIN: %04x", @@ -200,31 +205,33 @@ const char *dev_path(struct device * dev) sprintf(buffer, "CPU: %02x", dev->path.u.cpu.id); break; case DEVICE_PATH_CPU_BUS: - sprintf(buffer, "CPU_BUS: %02x", dev->path.u.cpu_bus.id); + sprintf(buffer, "CPU_BUS: %02x", + dev->path.u.cpu_bus.id); break; default: - printk(BIOS_ERR, "%s: Unknown device path type: %d\n", dev->dtsname, dev->path.type); + printk(BIOS_ERR, "%s: Unknown device path type: %d\n", + dev->dtsname, dev->path.type); break; } } return buffer; } -/* WARNING: NOT SMP-safe!*/ +/* WARNING: NOT SMP-safe! */ const char *dev_id_string(struct device_id *id) { static char buffer[DEVICE_ID_MAX]; buffer[0] = '\0'; if (!id) { memcpy(buffer, "", 7); - } - else { - switch(id->type) { + } else { + switch (id->type) { case DEVICE_ID_ROOT: memcpy(buffer, "Root Device", 12); break; case DEVICE_ID_PCI: - sprintf(buffer, "PCI: %02x:%02x",id->u.pci.vendor, id->u.pci.device); + sprintf(buffer, "PCI: %02x:%02x", id->u.pci.vendor, + id->u.pci.device); break; case DEVICE_ID_PNP: sprintf(buffer, "PNP: %04x", id->u.pnp.device); @@ -233,22 +240,30 @@ const char *dev_id_string(struct device_id *id) sprintf(buffer, "I2C: %04x", id->u.i2c.id); break; case DEVICE_ID_APIC: - sprintf(buffer, "APIC: %02x:%02x",id->u.apic.vendor, id->u.apic.device); + sprintf(buffer, "APIC: %02x:%02x", id->u.apic.vendor, + id->u.apic.device); break; case DEVICE_ID_PCI_DOMAIN: - sprintf(buffer, "PCI_DOMAIN: %02x:%02x",id->u.pci_domain.vendor, id->u.pci_domain.device); + sprintf(buffer, "PCI_DOMAIN: %02x:%02x", + id->u.pci_domain.vendor, + id->u.pci_domain.device); break; case DEVICE_ID_APIC_CLUSTER: - sprintf(buffer, "APIC_CLUSTER: %02x:%02x",id->u.apic_cluster.vendor, id->u.apic_cluster.device); + sprintf(buffer, "APIC_CLUSTER: %02x:%02x", + id->u.apic_cluster.vendor, + id->u.apic_cluster.device); break; case DEVICE_ID_CPU: - sprintf(buffer, "CPU", id->u.cpu.cpuid[0], id->u.cpu.cpuid[1], id->u.cpu.cpuid[2]); + sprintf(buffer, "CPU", id->u.cpu.cpuid[0], + id->u.cpu.cpuid[1], id->u.cpu.cpuid[2]); break; case DEVICE_ID_CPU_BUS: - sprintf(buffer, "CPU_BUS: %02x:%02x",id->u.cpu_bus.vendor, id->u.cpu_bus.device); + sprintf(buffer, "CPU_BUS: %02x:%02x", + id->u.cpu_bus.vendor, id->u.cpu_bus.device); break; default: - printk(BIOS_ERR, "%s: Unknown device id type: %d\n", __func__, id->type); + printk(BIOS_ERR, "%s: Unknown device ID type: %d\n", + __func__, id->type); memcpy(buffer, "Unknown", 8); break; } @@ -256,13 +271,10 @@ const char *dev_id_string(struct device_id *id) return buffer; } - - const char *bus_path(struct bus *bus) { static char buffer[BUS_PATH_MAX]; - sprintf(buffer, "%s,%d", - dev_path(bus->dev), bus->link); + sprintf(buffer, "%s,%d", dev_path(bus->dev), bus->link); return buffer; } @@ -270,7 +282,7 @@ int path_eq(struct device_path *path1, struct device_path *path2) { int equal = 0; if (path1->type == path2->type) { - switch(path1->type) { + switch (path1->type) { case DEVICE_PATH_NONE: break; case DEVICE_PATH_ROOT: @@ -281,19 +293,24 @@ int path_eq(struct device_path *path1, struct device_path *path2) break; case DEVICE_PATH_PNP: equal = (path1->u.pnp.port == path2->u.pnp.port) && - (path1->u.pnp.device == path2->u.pnp.device); + (path1->u.pnp.device == path2->u.pnp.device); break; case DEVICE_PATH_I2C: equal = (path1->u.i2c.device == path2->u.i2c.device); break; case DEVICE_PATH_APIC: - equal = (path1->u.apic.apic_id == path2->u.apic.apic_id); + equal = + (path1->u.apic.apic_id == path2->u.apic.apic_id); break; case DEVICE_PATH_PCI_DOMAIN: - equal = (path1->u.pci_domain.domain == path2->u.pci_domain.domain); + equal = + (path1->u.pci_domain.domain == + path2->u.pci_domain.domain); break; case DEVICE_PATH_APIC_CLUSTER: - equal = (path1->u.apic_cluster.cluster == path2->u.apic_cluster.cluster); + equal = + (path1->u.apic_cluster.cluster == + path2->u.apic_cluster.cluster); break; case DEVICE_PATH_CPU: equal = (path1->u.cpu.id == path2->u.cpu.id); @@ -302,7 +319,8 @@ int path_eq(struct device_path *path1, struct device_path *path2) equal = (path1->u.cpu_bus.id == path2->u.cpu_bus.id); break; default: - printk(BIOS_ERR, "Unknown device type: %d\n", path1->type); + printk(BIOS_ERR, "Unknown device type: %d\n", + path1->type); break; } } @@ -313,14 +331,15 @@ int id_eq(struct device_id *path1, struct device_id *path2) { int equal = 0; if (path1->type == path2->type) { - switch(path1->type) { + switch (path1->type) { case DEVICE_ID_NONE: break; case DEVICE_ID_ROOT: equal = 1; break; case DEVICE_ID_PCI: - equal = (path1->u.pci.vendor == path2->u.pci.vendor) && (path1->u.pci.device == path2->u.pci.device); + equal = (path1->u.pci.vendor == path2->u.pci.vendor) + && (path1->u.pci.device == path2->u.pci.device); break; case DEVICE_ID_PNP: equal = (path1->u.pnp.device == path2->u.pnp.device); @@ -329,66 +348,82 @@ int id_eq(struct device_id *path1, struct device_id *path2) equal = (path1->u.i2c.id == path2->u.i2c.id); break; case DEVICE_ID_APIC: - equal = (path1->u.apic.vendor == path2->u.apic.vendor) && (path1->u.apic.device == path2->u.apic.device); + equal = (path1->u.apic.vendor == path2->u.apic.vendor) + && (path1->u.apic.device == path2->u.apic.device); break; case DEVICE_ID_PCI_DOMAIN: - equal = (path1->u.pci_domain.vendor == path2->u.pci_domain.vendor) && (path1->u.pci_domain.device == path2->u.pci_domain.device); + equal = + (path1->u.pci_domain.vendor == + path2->u.pci_domain.vendor) + && (path1->u.pci_domain.device == + path2->u.pci_domain.device); break; case DEVICE_ID_APIC_CLUSTER: - equal = (path1->u.apic_cluster.vendor == path2->u.apic_cluster.vendor) && (path1->u.apic_cluster.device == path2->u.apic_cluster.device); + equal = + (path1->u.apic_cluster.vendor == + path2->u.apic_cluster.vendor) + && (path1->u.apic_cluster.device == + path2->u.apic_cluster.device); break; case DEVICE_ID_CPU: equal = (path1->u.cpu.cpuid == path2->u.cpu.cpuid); break; case DEVICE_ID_CPU_BUS: - equal = (path1->u.cpu_bus.vendor == path2->u.cpu_bus.vendor) && (path1->u.cpu_bus.device == path2->u.cpu_bus.device); + equal = + (path1->u.cpu_bus.vendor == path2->u.cpu_bus.vendor) + && (path1->u.cpu_bus.device == + path2->u.cpu_bus.device); break; default: - printk(BIOS_ERR, "Unknown device type: %d\n", path1->type); + printk(BIOS_ERR, "Unknown device type: %d\n", + path1->type); break; } } return equal; } - /** * See if we have unused but allocated resource structures. * If so remove the allocation. - * @param dev The device to find the resource on + * + * @param dev The device to find the resource on. */ -void compact_resources(struct device * dev) +void compact_resources(struct device *dev) { struct resource *resource; int i; - /* Move all of the free resources to the end */ - for(i = 0; i < dev->resources;) { + /* Move all of the free resources to the end. */ + for (i = 0; i < dev->resources;) { resource = &dev->resource[i]; if (!resource->flags) { - /* note: memmove was used here. But this can never overlap, right? */ + /* Note: memmove() was used here. But this can never + * overlap, right? + */ memcpy(resource, resource + 1, dev->resources - i); dev->resources -= 1; - memset(&dev->resource[dev->resources], 0, sizeof(*resource)); + memset(&dev->resource[dev->resources], 0, + sizeof(*resource)); } else { i++; } } } - /** - * See if a resource structure already exists for a given index - * @param dev The device to find the resource on - * @param index The index of the resource on the device. - * @return the resource if it already exists + * See if a resource structure already exists for a given index. + * + * @param dev The device to find the resource on. + * @param index The index of the resource on the device. + * @return The resource if it already exists. */ -struct resource *probe_resource(struct device * dev, unsigned index) +struct resource *probe_resource(struct device *dev, unsigned int index) { struct resource *resource; int i; - /* See if there is a resource with the appropriate index */ + /* See if there is a resource with the appropriate index. */ resource = 0; - for(i = 0; i < dev->resources; i++) { + for (i = 0; i < dev->resources; i++) { if (dev->resource[i].index == index) { resource = &dev->resource[i]; break; @@ -399,19 +434,19 @@ struct resource *probe_resource(struct device * dev, unsigned index) /** * See if a resource structure already exists for a given index and if - * not allocate one. Then initialize the initialize the resource - * to default values. - * @param dev The device to find the resource on - * @param index The index of the resource on the device. + * not allocate one. Then initialize the resource to default values. + * + * @param dev The device to find the resource on. + * @param index The index of the resource on the device. */ -struct resource *new_resource(struct device * dev, unsigned index) +struct resource *new_resource(struct device *dev, unsigned int index) { struct resource *resource; - /* First move all of the free resources to the end */ + /* First move all of the free resources to the end. */ compact_resources(dev); - /* See if there is a resource with the appropriate index */ + /* See if there is a resource with the appropriate index. */ resource = probe_resource(dev, index); if (!resource) { if (dev->resources == MAX_RESOURCES) { @@ -421,45 +456,46 @@ struct resource *new_resource(struct device * dev, unsigned index) memset(resource, 0, sizeof(*resource)); dev->resources++; } - /* Initialize the resource values */ + /* Initialize the resource values. */ if (!(resource->flags & IORESOURCE_FIXED)) { resource->flags = 0; resource->base = 0; } - resource->size = 0; + resource->size = 0; resource->limit = 0; resource->index = index; resource->align = 0; - resource->gran = 0; + resource->gran = 0; return resource; } /** * Return an existing resource structure for a given index. - * @param dev The device to find the resource on - * @param index The index of the resource on the device. + * + * @param dev The device to find the resource on. + * @param index The index of the resource on the device. */ -struct resource *find_resource(struct device * dev, unsigned index) +struct resource *find_resource(struct device *dev, unsigned int index) { struct resource *resource; - /* See if there is a resource with the appropriate index */ + /* See if there is a resource with the appropriate index. */ resource = probe_resource(dev, index); if (!resource) { printk(BIOS_EMERG, "%s missing resource: %02x\n", - dev_path(dev), index); + dev_path(dev), index); die(""); } return resource; } - /** - * @brief round a number up to the next multiple of gran - * @param val the starting value - * @param gran granularity we are aligning the number to. - * @returns aligned value + * Round a number up to the next multiple of gran. + * + * @param val The starting value. + * @param gran Granularity we are aligning the number to. + * @returns The aligned value. */ static resource_t align_up(resource_t val, unsigned long gran) { @@ -471,10 +507,11 @@ static resource_t align_up(resource_t val, unsigned long gran) } /** - * @brief round a number up to the previous multiple of gran - * @param val the starting value - * @param gran granularity we are aligning the number to. - * @returns aligned value + * Round a number up to the previous multiple of gran. + * + * @param val The starting value. + * @param gran Granularity we are aligning the number to. + * @returns The aligned value. */ static resource_t align_down(resource_t val, unsigned long gran) { @@ -485,67 +522,71 @@ static resource_t align_down(resource_t val, unsigned long gran) } /** - * @brief Compute the maximum address that is part of a resource - * @param resource the resource whose limit is desired - * @returns the end + * Compute the maximum address that is part of a resource. + * + * @param resource The resource whose limit is desired. + * @returns The end. */ resource_t resource_end(struct resource *resource) { resource_t base, end; - /* get the base address */ + + /* Get the base address. */ base = resource->base; - /* For a non bridge resource granularity and alignment are the same. + /* For a non-bridge resource granularity and alignment are the same. * For a bridge resource align is the largest needed alignment below - * the bridge. While the granularity is simply how many low bits of the - * address cannot be set. + * the bridge. While the granularity is simply how many low bits of + * the address cannot be set. */ - - /* Get the end (rounded up) */ + + /* Get the end (rounded up). */ end = base + align_up(resource->size, resource->gran) - 1; return end; } /** - * @brief Compute the maximum legal value for resource->base - * @param resource the resource whose maximum is desired - * @returns the maximum + * Compute the maximum legal value for resource->base. + * + * @param resource The resource whose maximum is desired. + * @returns The maximum. */ resource_t resource_max(struct resource *resource) { resource_t max; - max = align_down(resource->limit - resource->size + 1, resource->align); - return max; } /** - * @brief return the resource type of a resource - * @param resource the resource type to decode. + * Return the resource type of a resource. + * + * @param resource The resource type to decode. */ const char *resource_type(struct resource *resource) { static char buffer[RESOURCE_TYPE_MAX]; sprintf(buffer, "%s%s%s%s", - ((resource->flags & IORESOURCE_READONLY)? "ro": ""), - ((resource->flags & IORESOURCE_PREFETCH)? "pref":""), - ((resource->flags == 0)? "unused": - (resource->flags & IORESOURCE_IO)? "io": - (resource->flags & IORESOURCE_DRQ)? "drq": - (resource->flags & IORESOURCE_IRQ)? "irq": - (resource->flags & IORESOURCE_MEM)? "mem":"??????"), - ((resource->flags & IORESOURCE_PCI64)?"64":"")); + ((resource->flags & IORESOURCE_READONLY) ? "ro" : ""), + ((resource->flags & IORESOURCE_PREFETCH) ? "pref" : ""), + ((resource->flags == 0) ? "unused" : + (resource->flags & IORESOURCE_IO) ? "io" : + (resource->flags & IORESOURCE_DRQ) ? "drq" : + (resource->flags & IORESOURCE_IRQ) ? "irq" : + (resource->flags & IORESOURCE_MEM) ? "mem" : "??????"), + ((resource->flags & IORESOURCE_PCI64) ? "64" : "")); return buffer; } /** - * @brief print the resource that was just stored. - * @param dev the device the stored resorce lives on - * @param resource the resource that was just stored. + * Print the resource that was just stored. + * + * @param dev The device the stored resorce lives on. + * @param resource The resource that was just stored. */ -void report_resource_stored(struct device * dev, struct resource *resource, const char *comment) +void report_resource_stored(struct device *dev, struct resource *resource, + const char *comment) { if (resource->flags & IORESOURCE_STORED) { char buf[10]; @@ -555,42 +596,43 @@ void report_resource_stored(struct device * dev, struct resource *resource, cons buf[0] = '\0'; if (resource->flags & IORESOURCE_PCI_BRIDGE) { #if PCI_BUS_SEGN_BITS - sprintf(buf, "bus %04x:%02x ", dev->bus->secondary>>8, dev->link[0].secondary & 0xff); + sprintf(buf, "bus %04x:%02x ", dev->bus->secondary >> 8, + dev->link[0].secondary & 0xff); #else sprintf(buf, "bus %02x ", dev->link[0].secondary); #endif } - printk(BIOS_DEBUG, - "%s %02x <- [0x%010Lx - 0x%010Lx] %s%s%s\n", - dev_path(dev), - resource->index, - base, end, - buf, - resource_type(resource), - comment); + printk(BIOS_DEBUG, + "%s %02x <- [0x%010Lx - 0x%010Lx] %s%s%s\n", + dev_path(dev), + resource->index, + base, end, buf, resource_type(resource), comment); } } void search_bus_resources(struct bus *bus, - unsigned long type_mask, unsigned long type, - resource_search_t search, void *gp) + unsigned long type_mask, unsigned long type, + resource_search_t search, void *gp) { struct device *curdev; - for(curdev = bus->children; curdev; curdev = curdev->sibling) { + for (curdev = bus->children; curdev; curdev = curdev->sibling) { int i; - /* Ignore disabled devices */ - if (!curdev->have_resources) continue; - for(i = 0; i < curdev->resources; i++) { + /* Ignore disabled devices. */ + if (!curdev->have_resources) + continue; + for (i = 0; i < curdev->resources; i++) { struct resource *resource = &curdev->resource[i]; - /* If it isn't the right kind of resource ignore it */ + /* If it isn't the right kind of resource ignore it. */ if ((resource->flags & type_mask) != type) { continue; } - /* If it is a subtractive resource recurse */ + /* If it is a subtractive resource recurse. */ if (resource->flags & IORESOURCE_SUBTRACTIVE) { - struct bus * subbus; - subbus = &curdev->link[IOINDEX_SUBTRACTIVE_LINK(resource->index)]; - search_bus_resources(subbus, type_mask, type, search, gp); + struct bus *subbus; + subbus = &curdev->link[IOINDEX_SUBTRACTIVE_LINK + (resource->index)]; + search_bus_resources(subbus, type_mask, type, + search, gp); continue; } search(gp, curdev, resource); @@ -598,27 +640,31 @@ void search_bus_resources(struct bus *bus, } } -void search_global_resources( - unsigned long type_mask, unsigned long type, - resource_search_t search, void *gp) +void search_global_resources(unsigned long type_mask, unsigned long type, + resource_search_t search, void *gp) { struct device *curdev; printk(BIOS_SPEW, "%s: mask %x type %x \n", __func__, type_mask, type); - for(curdev = all_devices; curdev; curdev = curdev->next) { + for (curdev = all_devices; curdev; curdev = curdev->next) { int i; - printk(BIOS_SPEW, "%s: dev %s, have_resources %d #resources %d\n", __func__, curdev->dtsname, - curdev->have_resources, curdev->resources); - /* Ignore disabled devices */ - if (!curdev->have_resources) continue; - for(i = 0; i < curdev->resources; i++) { + printk(BIOS_SPEW, + "%s: dev %s, have_resources %d #resources %d\n", + __func__, curdev->dtsname, curdev->have_resources, + curdev->resources); + /* Ignore disabled devices. */ + if (!curdev->have_resources) + continue; + for (i = 0; i < curdev->resources; i++) { struct resource *resource = &curdev->resource[i]; - printk(BIOS_SPEW, "%s: dev %s, resource %d, flags %x base 0x%lx size 0x%lx\n", __func__, curdev->dtsname, - i, resource->flags, (u32) resource->base, (u32)resource->size); - /* If it isn't the right kind of resource ignore it */ + printk(BIOS_SPEW, + "%s: dev %s, resource %d, flags %x base 0x%lx size 0x%lx\n", + __func__, curdev->dtsname, i, resource->flags, + (u32) resource->base, (u32) resource->size); + /* If it isn't the right kind of resource ignore it. */ if ((resource->flags & type_mask) != type) { continue; } - /* If it is a subtractive resource ignore it */ + /* If it is a subtractive resource ignore it. */ if (resource->flags & IORESOURCE_SUBTRACTIVE) { continue; } @@ -627,7 +673,7 @@ void search_global_resources( } } -void dev_set_enabled(struct device * dev, int enable) +void dev_set_enabled(struct device *dev, int enable) { if (dev->enabled == enable) { return; @@ -640,10 +686,10 @@ void dev_set_enabled(struct device * dev, int enable) void disable_children(struct bus *bus) { - struct device * child; - for(child = bus->children; child; child = child->sibling) { + struct device *child; + for (child = bus->children; child; child = child->sibling) { int link; - for(link = 0; link < child->links; link++) { + for (link = 0; link < child->links; link++) { disable_children(&child->link[link]); } dev_set_enabled(child, 0); diff --git a/device/hypertransport.c b/device/hypertransport.c index b93d49db31..a16b85af9c 100644 --- a/device/hypertransport.c +++ b/device/hypertransport.c @@ -23,10 +23,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -/* - 2005.11 yhlu add let the real sb to use small uintid -*/ - #include #include #include @@ -38,7 +34,7 @@ #include #define OPT_HT_LINK 0 - + #if OPT_HT_LINK == 1 #include #endif @@ -48,25 +44,24 @@ static device_t ht_scan_get_devs(device_t *old_devices) device_t first, last; first = *old_devices; last = first; + /* Extract the chain of devices to (first through last) * for the next hypertransport device. */ - while(last && last->sibling && - (last->sibling->path.type == DEVICE_PATH_PCI) && - (last->sibling->path.u.pci.devfn > last->path.u.pci.devfn)) - { + while (last && last->sibling && + (last->sibling->path.type == DEVICE_PATH_PCI) && + (last->sibling->path.u.pci.devfn > last->path.u.pci.devfn)) { last = last->sibling; } if (first) { device_t child; - /* Unlink the chain from the list of old devices */ + /* Unlink the chain from the list of old devices. */ *old_devices = last->sibling; last->sibling = 0; - /* Now add the device to the list of devices on the bus. - */ - /* Find the last child of our parent */ - for(child = first->bus->children; child && child->sibling; ) { + /* Now add the device to the list of devices on the bus. */ + /* Find the last child of our parent. */ + for (child = first->bus->children; child && child->sibling;) { child = child->sibling; } /* Place the chain on the list of children of their parent. */ @@ -82,30 +77,30 @@ static device_t ht_scan_get_devs(device_t *old_devices) #if OPT_HT_LINK == 1 static unsigned ht_read_freq_cap(device_t dev, unsigned pos) { - /* Handle bugs in valid hypertransport frequency reporting */ + /* Handle bugs in valid hypertransport frequency reporting. */ unsigned freq_cap; freq_cap = pci_read_config16(dev, pos); - freq_cap &= ~(1 << HT_FREQ_VENDOR); /* Ignore Vendor HT frequencies */ + freq_cap &= ~(1 << HT_FREQ_VENDOR); /* Ignore vendor HT frequencies. */ - /* AMD 8131 Errata 48 */ + /* AMD 8131 Errata 48. */ if ((dev->vendor == PCI_VENDOR_ID_AMD) && - (dev->device == PCI_DEVICE_ID_AMD_8131_PCIX)) { + (dev->device == PCI_DEVICE_ID_AMD_8131_PCIX)) { freq_cap &= ~(1 << HT_FREQ_800Mhz); } - /* AMD 8151 Errata 23 */ + /* AMD 8151 Errata 23. */ if ((dev->vendor == PCI_VENDOR_ID_AMD) && - (dev->device == PCI_DEVICE_ID_AMD_8151_SYSCTRL)) { + (dev->device == PCI_DEVICE_ID_AMD_8151_SYSCTRL)) { freq_cap &= ~(1 << HT_FREQ_800Mhz); } - /* AMD K8 Unsupported 1Ghz? */ + /* AMD K8 unsupported 1GHz? */ if ((dev->vendor == PCI_VENDOR_ID_AMD) && (dev->device == 0x1100)) { -#if K8_HT_FREQ_1G_SUPPORT == 1 - #if K8_REV_F_SUPPORT == 0 - if (is_cpu_pre_e0()) { // only e0 later suupport 1GHz HT +#if K8_HT_FREQ_1G_SUPPORT == 1 +#if K8_REV_F_SUPPORT == 0 + if (is_cpu_pre_e0()) { // Only e0 later suupport 1GHz HT. freq_cap &= ~(1 << HT_FREQ_1000Mhz); - } - #endif + } +#endif #else freq_cap &= ~(1 << HT_FREQ_1000Mhz); #endif @@ -117,158 +112,174 @@ static unsigned ht_read_freq_cap(device_t dev, unsigned pos) struct ht_link { struct device *dev; - unsigned pos; + unsigned int pos; unsigned char ctrl_off, config_off, freq_off, freq_cap_off; }; -static int ht_setup_link(struct ht_link *prev, device_t dev, unsigned pos) +static int ht_setup_link(struct ht_link *prev, device_t dev, unsigned int pos) { - static const u8 link_width_to_pow2[]= { 3, 4, 0, 5, 1, 2, 0, 0 }; + static const u8 link_width_to_pow2[] = { 3, 4, 0, 5, 1, 2, 0, 0 }; static const u8 pow2_to_link_width[] = { 0x7, 4, 5, 0, 1, 3 }; struct ht_link cur[1]; - unsigned present_width_cap, upstream_width_cap; - unsigned present_freq_cap, upstream_freq_cap; - unsigned ln_present_width_in, ln_upstream_width_in; - unsigned ln_present_width_out, ln_upstream_width_out; - unsigned freq, old_freq; - unsigned present_width, upstream_width, old_width; + unsigned int present_width_cap, upstream_width_cap; + unsigned int present_freq_cap, upstream_freq_cap; + unsigned int ln_present_width_in, ln_upstream_width_in; + unsigned int ln_present_width_out, ln_upstream_width_out; + unsigned int freq, old_freq; + unsigned int present_width, upstream_width, old_width; int reset_needed; int linkb_to_host; - /* Set the hypertransport link width and frequency */ + /* Set the hypertransport link width and frequency. */ reset_needed = 0; /* See which side of the device our previous write to * set the unitid came from. */ cur->dev = dev; cur->pos = pos; - linkb_to_host = (pci_read_config16(cur->dev, cur->pos + PCI_CAP_FLAGS) >> 10) & 1; + linkb_to_host = + (pci_read_config16(cur->dev, cur->pos + PCI_CAP_FLAGS) >> 10) & 1; if (!linkb_to_host) { - cur->ctrl_off = PCI_HT_CAP_SLAVE_CTRL0; - cur->config_off = PCI_HT_CAP_SLAVE_WIDTH0; - cur->freq_off = PCI_HT_CAP_SLAVE_FREQ0; + cur->ctrl_off = PCI_HT_CAP_SLAVE_CTRL0; + cur->config_off = PCI_HT_CAP_SLAVE_WIDTH0; + cur->freq_off = PCI_HT_CAP_SLAVE_FREQ0; cur->freq_cap_off = PCI_HT_CAP_SLAVE_FREQ_CAP0; - } - else { - cur->ctrl_off = PCI_HT_CAP_SLAVE_CTRL1; - cur->config_off = PCI_HT_CAP_SLAVE_WIDTH1; - cur->freq_off = PCI_HT_CAP_SLAVE_FREQ1; + } else { + cur->ctrl_off = PCI_HT_CAP_SLAVE_CTRL1; + cur->config_off = PCI_HT_CAP_SLAVE_WIDTH1; + cur->freq_off = PCI_HT_CAP_SLAVE_FREQ1; cur->freq_cap_off = PCI_HT_CAP_SLAVE_FREQ_CAP1; } #if OPT_HT_LINK == 1 - /* Read the capabilities */ - present_freq_cap = ht_read_freq_cap(cur->dev, cur->pos + cur->freq_cap_off); - upstream_freq_cap = ht_read_freq_cap(prev->dev, prev->pos + prev->freq_cap_off); - present_width_cap = pci_read_config8(cur->dev, cur->pos + cur->config_off); - upstream_width_cap = pci_read_config8(prev->dev, prev->pos + prev->config_off); - - /* Calculate the highest useable frequency */ + /* Read the capabilities. */ + present_freq_cap = + ht_read_freq_cap(cur->dev, cur->pos + cur->freq_cap_off); + upstream_freq_cap = + ht_read_freq_cap(prev->dev, prev->pos + prev->freq_cap_off); + present_width_cap = + pci_read_config8(cur->dev, cur->pos + cur->config_off); + upstream_width_cap = + pci_read_config8(prev->dev, prev->pos + prev->config_off); + + /* Calculate the highest useable frequency. */ freq = log2(present_freq_cap & upstream_freq_cap); - /* Calculate the highest width */ + /* Calculate the highest width. */ ln_upstream_width_in = link_width_to_pow2[upstream_width_cap & 7]; ln_present_width_out = link_width_to_pow2[(present_width_cap >> 4) & 7]; if (ln_upstream_width_in > ln_present_width_out) { ln_upstream_width_in = ln_present_width_out; } upstream_width = pow2_to_link_width[ln_upstream_width_in]; - present_width = pow2_to_link_width[ln_upstream_width_in] << 4; + present_width = pow2_to_link_width[ln_upstream_width_in] << 4; - ln_upstream_width_out = link_width_to_pow2[(upstream_width_cap >> 4) & 7]; - ln_present_width_in = link_width_to_pow2[present_width_cap & 7]; + ln_upstream_width_out = + link_width_to_pow2[(upstream_width_cap >> 4) & 7]; + ln_present_width_in = link_width_to_pow2[present_width_cap & 7]; if (ln_upstream_width_out > ln_present_width_in) { ln_upstream_width_out = ln_present_width_in; } upstream_width |= pow2_to_link_width[ln_upstream_width_out] << 4; - present_width |= pow2_to_link_width[ln_upstream_width_out]; + present_width |= pow2_to_link_width[ln_upstream_width_out]; - /* Set the current device */ + /* Set the current device. */ old_freq = pci_read_config8(cur->dev, cur->pos + cur->freq_off); old_freq &= 0x0f; if (freq != old_freq) { - unsigned new_freq; + unsigned int new_freq; pci_write_config8(cur->dev, cur->pos + cur->freq_off, freq); reset_needed = 1; - printk_spew("HyperT FreqP old %x new %x\n",old_freq,freq); + printk_spew("HyperT FreqP old %x new %x\n", old_freq, freq); new_freq = pci_read_config8(cur->dev, cur->pos + cur->freq_off); new_freq &= 0x0f; if (new_freq != freq) { - printk_err("%s Hypertransport frequency would not set wanted: %x got: %x\n", - dev_path(dev), freq, new_freq); + printk_err + ("%s Hypertransport frequency would not set wanted: %x got: %x\n", + dev_path(dev), freq, new_freq); } } old_width = pci_read_config8(cur->dev, cur->pos + cur->config_off + 1); if (present_width != old_width) { - unsigned new_width; + unsigned int new_width; pci_write_config8(cur->dev, cur->pos + cur->config_off + 1, - present_width); + present_width); reset_needed = 1; - printk_spew("HyperT widthP old %x new %x\n",old_width, present_width); - new_width = pci_read_config8(cur->dev, cur->pos + cur->config_off + 1); + printk_spew("HyperT widthP old %x new %x\n", old_width, + present_width); + new_width = + pci_read_config8(cur->dev, cur->pos + cur->config_off + 1); if (new_width != present_width) { - printk_err("%s Hypertransport width would not set wanted: %x got: %x\n", - dev_path(dev), present_width, new_width); + printk_err + ("%s Hypertransport width would not set wanted: %x got: %x\n", + dev_path(dev), present_width, new_width); } } - /* Set the upstream device */ + /* Set the upstream device. */ old_freq = pci_read_config8(prev->dev, prev->pos + prev->freq_off); old_freq &= 0x0f; if (freq != old_freq) { - unsigned new_freq; + unsigned int new_freq; pci_write_config8(prev->dev, prev->pos + prev->freq_off, freq); reset_needed = 1; printk_spew("HyperT freqU old %x new %x\n", old_freq, freq); - new_freq = pci_read_config8(prev->dev, prev->pos + prev->freq_off); + new_freq = + pci_read_config8(prev->dev, prev->pos + prev->freq_off); new_freq &= 0x0f; if (new_freq != freq) { - printk_err("%s Hypertransport frequency would not set wanted: %x got: %x\n", - dev_path(prev->dev), freq, new_freq); + printk_err + ("%s Hypertransport frequency would not set wanted: %x got: %x\n", + dev_path(prev->dev), freq, new_freq); } } - old_width = pci_read_config8(prev->dev, prev->pos + prev->config_off + 1); + old_width = + pci_read_config8(prev->dev, prev->pos + prev->config_off + 1); if (upstream_width != old_width) { - unsigned new_width; - pci_write_config8(prev->dev, prev->pos + prev->config_off + 1, upstream_width); + unsigned int new_width; + pci_write_config8(prev->dev, prev->pos + prev->config_off + 1, + upstream_width); reset_needed = 1; - printk_spew("HyperT widthU old %x new %x\n", old_width, upstream_width); - new_width = pci_read_config8(prev->dev, prev->pos + prev->config_off + 1); + printk_spew("HyperT widthU old %x new %x\n", old_width, + upstream_width); + new_width = + pci_read_config8(prev->dev, + prev->pos + prev->config_off + 1); if (new_width != upstream_width) { - printk_err("%s Hypertransport width would not set wanted: %x got: %x\n", - dev_path(prev->dev), upstream_width, new_width); + printk_err + ("%s Hypertransport width would not set wanted: %x got: %x\n", + dev_path(prev->dev), upstream_width, new_width); } } #endif - + /* Remember the current link as the previous link, - * But look at the other offsets. + * but look at the other offsets. */ prev->dev = cur->dev; prev->pos = cur->pos; if (cur->ctrl_off == PCI_HT_CAP_SLAVE_CTRL0) { - prev->ctrl_off = PCI_HT_CAP_SLAVE_CTRL1; - prev->config_off = PCI_HT_CAP_SLAVE_WIDTH1; - prev->freq_off = PCI_HT_CAP_SLAVE_FREQ1; + prev->ctrl_off = PCI_HT_CAP_SLAVE_CTRL1; + prev->config_off = PCI_HT_CAP_SLAVE_WIDTH1; + prev->freq_off = PCI_HT_CAP_SLAVE_FREQ1; prev->freq_cap_off = PCI_HT_CAP_SLAVE_FREQ_CAP1; } else { - prev->ctrl_off = PCI_HT_CAP_SLAVE_CTRL0; - prev->config_off = PCI_HT_CAP_SLAVE_WIDTH0; - prev->freq_off = PCI_HT_CAP_SLAVE_FREQ0; + prev->ctrl_off = PCI_HT_CAP_SLAVE_CTRL0; + prev->config_off = PCI_HT_CAP_SLAVE_WIDTH0; + prev->freq_off = PCI_HT_CAP_SLAVE_FREQ0; prev->freq_cap_off = PCI_HT_CAP_SLAVE_FREQ_CAP0; } return reset_needed; - } -static unsigned ht_lookup_slave_capability(struct device *dev) +static unsigned int ht_lookup_slave_capability(struct device *dev) { - unsigned pos; + unsigned int pos; pos = 0; do { pos = pci_find_next_capability(dev, PCI_CAP_ID_HT, pos); if (pos) { - unsigned flags; + unsigned int flags; flags = pci_read_config16(dev, pos + PCI_CAP_FLAGS); printk_spew("Flags: 0x%04x\n", flags); if ((flags >> 13) == 0) { @@ -276,320 +287,346 @@ static unsigned ht_lookup_slave_capability(struct device *dev) break; } } - } while(pos); + } while (pos); return pos; } -static void ht_collapse_early_enumeration(struct bus *bus, unsigned offset_unitid) +static void ht_collapse_early_enumeration(struct bus *bus, + unsigned int offset_unitid) { - unsigned int devfn; + unsigned int devfn, ctrl; struct ht_link prev; - unsigned ctrl; - /* Initialize the hypertransport enumeration state */ + /* Initialize the hypertransport enumeration state. */ prev.dev = bus->dev; prev.pos = bus->cap; - prev.ctrl_off = PCI_HT_CAP_HOST_CTRL; - prev.config_off = PCI_HT_CAP_HOST_WIDTH; - prev.freq_off = PCI_HT_CAP_HOST_FREQ; + prev.ctrl_off = PCI_HT_CAP_HOST_CTRL; + prev.config_off = PCI_HT_CAP_HOST_WIDTH; + prev.freq_off = PCI_HT_CAP_HOST_FREQ; prev.freq_cap_off = PCI_HT_CAP_HOST_FREQ_CAP; - /* Wait until the link initialization is complete */ + /* Wait until the link initialization is complete. */ do { ctrl = pci_read_config16(prev.dev, prev.pos + prev.ctrl_off); - /* Is this the end of the hypertransport chain */ + /* Is this the end of the hypertransport chain? */ if (ctrl & (1 << 6)) { return; } /* Has the link failed? */ if (ctrl & (1 << 4)) { - /* - * Either the link has failed, or we have - * a CRC error. - * Sometimes this can happen due to link - * retrain, so lets knock it down and see - * if its transient + /* Either the link has failed, or we have a CRC error. + * Sometimes this can happen due to link retrain, so + * lets knock it down and see if its transient. */ - ctrl |= ((1 << 4) | (1 <<8)); // Link fail + Crc - pci_write_config16(prev.dev, prev.pos + prev.ctrl_off, ctrl); - ctrl = pci_read_config16(prev.dev, prev.pos + prev.ctrl_off); + ctrl |= ((1 << 4) | (1 << 8)); // Link fail + CRC. + pci_write_config16(prev.dev, prev.pos + prev.ctrl_off, + ctrl); + ctrl = pci_read_config16(prev.dev, + prev.pos + prev.ctrl_off); if (ctrl & ((1 << 4) | (1 << 8))) { - printk_alert("Detected error on Hypertransport Link\n"); + printk_alert + ("Detected error on Hypertransport Link\n"); return; } } - } while((ctrl & (1 << 5)) == 0); + } while ((ctrl & (1 << 5)) == 0); - //actually, only for one HT device HT chain, and unitid is 0 + /* Actually, only for one HT device HT chain, and unitid is 0. */ #if HT_CHAIN_UNITID_BASE == 0 - if(offset_unitid) { - return; - } + if (offset_unitid) { + return; + } #endif - /* Check if is already collapsed */ - if((!offset_unitid)|| (offset_unitid && (!((HT_CHAIN_END_UNITID_BASE == 0) && (HT_CHAIN_END_UNITID_BASE > 16) & 0xffff; dummy.hdr_type = pci_read_config8(&dummy, PCI_HEADER_TYPE); pos = ht_lookup_slave_capability(&dummy); - if (!pos){ + if (!pos) { continue; } - /* Clear the unitid */ + /* Clear the unitid. */ flags = pci_read_config16(&dummy, pos + PCI_CAP_FLAGS); flags &= ~0x1f; pci_write_config16(&dummy, pos + PCI_CAP_FLAGS, flags); - printk_spew("Collapsing %s [%04x/%04x]\n", - dev_path(&dummy), dummy.vendor, dummy.device); + printk_spew("Collapsing %s [%04x/%04x]\n", + dev_path(&dummy), dummy.vendor, dummy.device); } } -unsigned int hypertransport_scan_chain(struct bus *bus, - unsigned min_devfn, unsigned max_devfn, unsigned int max, unsigned *ht_unitid_base, unsigned offset_unitid) +unsigned int hypertransport_scan_chain(struct bus *bus, unsigned int min_devfn, + unsigned int max_devfn, + unsigned int max, + unsigned int *ht_unitid_base, + unsigned int offset_unitid) { - //even HT_CHAIN_UNITID_BASE == 0, we still can go through this function, because of end_of_chain check, also We need it to optimize link - unsigned next_unitid, last_unitid; + /* Even HT_CHAIN_UNITID_BASE == 0, we still can go through this + * function, because of end_of_chain check, also we need it to + * optimize link. + */ + unsigned int next_unitid, last_unitid; device_t old_devices, dev, func; - unsigned min_unitid = (offset_unitid) ? HT_CHAIN_UNITID_BASE:1; + unsigned int min_unitid = (offset_unitid) ? HT_CHAIN_UNITID_BASE : 1; struct ht_link prev; device_t last_func = 0; int ht_dev_num = 0; #if HT_CHAIN_END_UNITID_BASE < HT_CHAIN_UNITID_BASE - //let't record the device of last ht device, So we can set the Unitid to HT_CHAIN_END_UNITID_BASE - unsigned real_last_unitid; - u8 real_last_pos; + /* Let't record the device of last HT device, so we can set the + * unitid to HT_CHAIN_END_UNITID_BASE. + */ + unsigned int real_last_unitid; + u8 real_last_pos; device_t real_last_dev; #endif - /* Restore the hypertransport chain to it's unitialized state */ + /* Restore the hypertransport chain to its unitialized state. */ ht_collapse_early_enumeration(bus, offset_unitid); - /* See which static device nodes I have */ + /* See which static device nodes I have. */ old_devices = bus->children; bus->children = 0; - /* Initialize the hypertransport enumeration state */ + /* Initialize the hypertransport enumeration state. */ prev.dev = bus->dev; prev.pos = bus->cap; - prev.ctrl_off = PCI_HT_CAP_HOST_CTRL; - prev.config_off = PCI_HT_CAP_HOST_WIDTH; - prev.freq_off = PCI_HT_CAP_HOST_FREQ; + prev.ctrl_off = PCI_HT_CAP_HOST_CTRL; + prev.config_off = PCI_HT_CAP_HOST_WIDTH; + prev.freq_off = PCI_HT_CAP_HOST_FREQ; prev.freq_cap_off = PCI_HT_CAP_HOST_FREQ_CAP; - - /* If present assign unitid to a hypertransport chain */ - last_unitid = min_unitid -1; + + /* If present assign unitid to a hypertransport chain. */ + last_unitid = min_unitid - 1; next_unitid = min_unitid; do { u8 pos; u16 flags; - unsigned count, static_count; - unsigned ctrl; + unsigned int count, static_count, ctrl; last_unitid = next_unitid; - /* Wait until the link initialization is complete */ + /* Wait until the link initialization is complete. */ do { - ctrl = pci_read_config16(prev.dev, prev.pos + prev.ctrl_off); + ctrl = pci_read_config16(prev.dev, + prev.pos + prev.ctrl_off); if (ctrl & (1 << 6)) - goto end_of_chain; // End of chain + goto end_of_chain; // End of chain. if (ctrl & ((1 << 4) | (1 << 8))) { - /* - * Either the link has failed, or we have - * a CRC error. - * Sometimes this can happen due to link - * retrain, so lets knock it down and see - * if its transient + /* Either the link has failed, or we have a + * CRC error. Sometimes this can happen due to + * link retrain, so lets knock it down and see + * if its transient. */ - ctrl |= ((1 << 4) | (1 <<8)); // Link fail + Crc - pci_write_config16(prev.dev, prev.pos + prev.ctrl_off, ctrl); - ctrl = pci_read_config16(prev.dev, prev.pos + prev.ctrl_off); + ctrl |= ((1 << 4) | (1 << 8)); /* Link fail + CRC */ + pci_write_config16(prev.dev, + prev.pos + prev.ctrl_off, + ctrl); + ctrl = pci_read_config16(prev.dev, + prev.pos + prev.ctrl_off); if (ctrl & ((1 << 4) | (1 << 8))) { - printk_alert("Detected error on Hypertransport Link\n"); + printk_alert + ("Detected error on Hypertransport Link\n"); goto end_of_chain; } } - } while((ctrl & (1 << 5)) == 0); - + } while ((ctrl & (1 << 5)) == 0); - /* Get and setup the device_structure */ + /* Get and setup the device_structure. */ dev = ht_scan_get_devs(&old_devices); - /* See if a device is present and setup the - * device structure. - */ + /* See if a device is present and setup the device structure. */ dev = pci_probe_dev(dev, bus, 0); if (!dev || !dev->enabled) { break; } - /* Find the hypertransport link capability */ + /* Find the hypertransport link capability. */ pos = ht_lookup_slave_capability(dev); if (pos == 0) { - printk_err("%s Hypertransport link capability not found", - dev_path(dev)); + printk_err + ("%s Hypertransport link capability not found", + dev_path(dev)); break; } - - /* Update the Unitid of the current device */ + + /* Update the unitid of the current device. */ flags = pci_read_config16(dev, pos + PCI_CAP_FLAGS); - - /* If the devices has a unitid set and is at devfn 0 we are done. - * This can happen with shadow hypertransport devices, - * or if we have reached the bottom of a - * hypertransport device chain. + + /* If the devices has a unitid set and is at devfn 0 we are + * done. This can happen with shadow hypertransport devices, + * or if we have reached the bottom of a hypertransport + * device chain. */ if (flags & 0x1f) { break; } - flags &= ~0x1f; /* mask out base Unit ID */ - flags |= next_unitid & 0x1f; - pci_write_config16(dev, pos + PCI_CAP_FLAGS, flags); + flags &= ~0x1f; /* Mask out base Unit ID. */ + flags |= next_unitid & 0x1f; + pci_write_config16(dev, pos + PCI_CAP_FLAGS, flags); - /* Update the Unitd id in the device structure */ + /* Update the Unitd id in the device structure. */ static_count = 1; - for(func = dev; func; func = func->sibling) { + for (func = dev; func; func = func->sibling) { func->path.u.pci.devfn += (next_unitid << 3); - static_count = (func->path.u.pci.devfn >> 3) - - (dev->path.u.pci.devfn >> 3) + 1; + static_count = (func->path.u.pci.devfn >> 3) + - (dev->path.u.pci.devfn >> 3) + 1; last_func = func; } - /* Compute the number of unitids consumed */ - count = (flags >> 5) & 0x1f; /* get unit count */ - printk_spew("%s count: %04x static_count: %04x\n", - dev_path(dev), count, static_count); + /* Compute the number of unitids consumed. */ + count = (flags >> 5) & 0x1f; /* Get unit count. */ + printk_spew("%s count: %04x static_count: %04x\n", + dev_path(dev), count, static_count); if (count < static_count) { count = static_count; } - /* Update the Unitid of the next device */ + /* Update the unitid of the next device. */ ht_unitid_base[ht_dev_num] = next_unitid; ht_dev_num++; #if HT_CHAIN_END_UNITID_BASE < HT_CHAIN_UNITID_BASE - if(offset_unitid) { - real_last_unitid = next_unitid; - real_last_pos = pos; + if (offset_unitid) { + real_last_unitid = next_unitid; + real_last_pos = pos; real_last_dev = dev; } #endif next_unitid += count; - /* Setup the hypetransport link */ + /* Setup the hypetransport link. */ bus->reset_needed |= ht_setup_link(&prev, dev, pos); printk_debug("%s [%04x/%04x] %s next_unitid: %04x\n", - dev_path(dev), - dev->vendor, dev->device, - (dev->enabled? "enabled": "disabled"), next_unitid); + dev_path(dev), + dev->vendor, dev->device, + (dev->enabled ? "enabled" : "disabled"), + next_unitid); - } while((last_unitid != next_unitid) && (next_unitid <= (max_devfn >> 3))); - end_of_chain: + } while ((last_unitid != next_unitid) + && (next_unitid <= (max_devfn >> 3))); + end_of_chain: #if OPT_HT_LINK == 1 - if(bus->reset_needed) { + if (bus->reset_needed) { printk_info("HyperT reset needed\n"); - } - else { + } else { printk_debug("HyperT reset not needed\n"); } #endif #if HT_CHAIN_END_UNITID_BASE < HT_CHAIN_UNITID_BASE - if(offset_unitid && (ht_dev_num>0)) { - u16 flags; - int i; + if (offset_unitid && (ht_dev_num > 0)) { + u16 flags; + int i; device_t last_func = 0; - flags = pci_read_config16(real_last_dev, real_last_pos + PCI_CAP_FLAGS); - flags &= ~0x1f; - flags |= HT_CHAIN_END_UNITID_BASE & 0x1f; - pci_write_config16(real_last_dev, real_last_pos + PCI_CAP_FLAGS, flags); + flags = pci_read_config16(real_last_dev, + real_last_pos + PCI_CAP_FLAGS); + flags &= ~0x1f; + flags |= HT_CHAIN_END_UNITID_BASE & 0x1f; + pci_write_config16(real_last_dev, real_last_pos + PCI_CAP_FLAGS, + flags); - for(func = real_last_dev; func; func = func->sibling) { - func->path.u.pci.devfn -= ((real_last_unitid - HT_CHAIN_END_UNITID_BASE) << 3); + for (func = real_last_dev; func; func = func->sibling) { + func->path.u.pci.devfn -= + ((real_last_unitid - + HT_CHAIN_END_UNITID_BASE) << 3); last_func = func; - } - - ht_unitid_base[ht_dev_num-1] = HT_CHAIN_END_UNITID_BASE; // update last one - - next_unitid = real_last_unitid; - } + } + + /* Update last one. */ + ht_unitid_base[ht_dev_num - 1] = HT_CHAIN_END_UNITID_BASE; + + next_unitid = real_last_unitid; + } #endif if (next_unitid > 0x1f) { next_unitid = 0x1f; } - /* Die if any leftover Static devices are are found. + /* Die if any leftover static devices are found. * There's probably a problem in the Config.lb. + * TODO: No more Config.lb in LinuxBIOSv3. */ - if(old_devices) { + if (old_devices) { device_t left; - for(left = old_devices; left; left = left->sibling) { + for (left = old_devices; left; left = left->sibling) { printk_debug("%s\n", dev_path(left)); } - printk_err("HT: Left over static devices. Check your Config.lb\n"); - if(last_func && !last_func->sibling) // put back the left over static device, and let pci_scan_bus disable it - last_func->sibling = old_devices; + printk_err("HT: Left over static devices.\n"); + /* Put back the left over static device, and let + * pci_scan_bus() disable it. + */ + if (last_func && !last_func->sibling) + last_func->sibling = old_devices; } /* Now that nothing is overlapping it is safe to scan the - * children. + * children. */ - max = pci_scan_bus(bus, 0x00, (next_unitid << 3)|7, max); - return max; + max = pci_scan_bus(bus, 0x00, (next_unitid << 3) | 7, max); + return max; } /** - * @brief Scan a PCI bridge and the buses behind the bridge. + * Scan a PCI bridge and the buses behind the bridge. * * Determine the existence of buses behind the bridge. Set up the bridge * according to the result of the scan. * * This function is the default scan_bus() method for PCI bridge devices. * - * @param dev pointer to the bridge device - * @param max the highest bus number assgined up to now + * TODO: This comment in copy+pasted from elsewhere and probably incorrect. * - * @return The maximum bus number found, after scanning all subordinate busses + * @param dev Pointer to the bridge device. + * @param max The highest bus number assigned up to now. + * @return The maximum bus number found, after scanning all subordinate buses. */ unsigned int hypertransport_scan_chain_x(struct bus *bus, - unsigned min_devfn, unsigned max_devfn, unsigned int max) + unsigned int min_devfn, + unsigned int max_devfn, + unsigned int max) { - unsigned ht_unitid_base[4]; - unsigned offset_unitid = 1; - return hypertransport_scan_chain(bus, min_devfn, max_devfn, max, ht_unitid_base, offset_unitid); + unsigned int ht_unitid_base[4]; + unsigned int offset_unitid = 1; + return hypertransport_scan_chain(bus, min_devfn, max_devfn, max, + ht_unitid_base, offset_unitid); } unsigned int ht_scan_bridge(struct device *dev, unsigned int max) @@ -597,8 +634,7 @@ unsigned int ht_scan_bridge(struct device *dev, unsigned int max) return do_pci_scan_bridge(dev, max, hypertransport_scan_chain_x); } - -/** Default device operations for hypertransport bridges */ +/** Default device operations for hypertransport bridges. */ static struct pci_operations ht_bus_ops_pci = { .set_subsystem = 0, }; @@ -607,8 +643,8 @@ struct device_operations default_ht_ops_bus = { .read_resources = pci_bus_read_resources, .set_resources = pci_dev_set_resources, .enable_resources = pci_bus_enable_resources, - .init = 0, - .scan_bus = ht_scan_bridge, + .init = 0, + .scan_bus = ht_scan_bridge, .enable = 0, .reset_bus = pci_bus_reset, .ops_pci = &ht_bus_ops_pci, diff --git a/device/pci_device.c b/device/pci_device.c index 389c5bb7a3..44f0e60635 100644 --- a/device/pci_device.c +++ b/device/pci_device.c @@ -26,9 +26,7 @@ #include #include #include - #include - #include #include #include @@ -53,11 +51,11 @@ #include #endif -u8 pci_moving_config8(struct device *dev, unsigned reg) +u8 pci_moving_config8(struct device *dev, unsigned int reg) { u8 value, ones, zeroes; value = pci_read_config8(dev, reg); - + pci_write_config8(dev, reg, 0xff); ones = pci_read_config8(dev, reg); @@ -69,11 +67,11 @@ u8 pci_moving_config8(struct device *dev, unsigned reg) return ones ^ zeroes; } -u16 pci_moving_config16(struct device *dev, unsigned reg) +u16 pci_moving_config16(struct device *dev, unsigned int reg) { u16 value, ones, zeroes; value = pci_read_config16(dev, reg); - + pci_write_config16(dev, reg, 0xffff); ones = pci_read_config16(dev, reg); @@ -85,11 +83,11 @@ u16 pci_moving_config16(struct device *dev, unsigned reg) return ones ^ zeroes; } -u32 pci_moving_config32(struct device *dev, unsigned reg) +u32 pci_moving_config32(struct device *dev, unsigned int reg) { u32 value, ones, zeroes; value = pci_read_config32(dev, reg); - + pci_write_config32(dev, reg, 0xffffffff); ones = pci_read_config32(dev, reg); @@ -101,17 +99,18 @@ u32 pci_moving_config32(struct device *dev, unsigned reg) return ones ^ zeroes; } -unsigned pci_find_next_capability(struct device * dev, unsigned cap, unsigned last) +unsigned int pci_find_next_capability(struct device *dev, unsigned int cap, + unsigned int last) { - unsigned pos; - unsigned status; - unsigned reps = 48; + unsigned int pos; + unsigned int status; + unsigned int reps = 48; pos = 0; status = pci_read_config16(dev, PCI_STATUS); if (!(status & PCI_STATUS_CAP_LIST)) { return 0; } - switch(dev->hdr_type & 0x7f) { + switch (dev->hdr_type & 0x7f) { case PCI_HEADER_TYPE_NORMAL: case PCI_HEADER_TYPE_BRIDGE: pos = PCI_CAPABILITY_LIST; @@ -123,7 +122,7 @@ unsigned pci_find_next_capability(struct device * dev, unsigned cap, unsigned la return 0; } pos = pci_read_config8(dev, pos); - while(reps-- && (pos >= 0x40)) { /* loop through the linked list */ + while (reps-- && (pos >= 0x40)) { /* Loop through the linked list. */ int this_cap; pos &= ~3; this_cap = pci_read_config8(dev, pos + PCI_CAP_LIST_ID); @@ -142,64 +141,66 @@ unsigned pci_find_next_capability(struct device * dev, unsigned cap, unsigned la return 0; } -unsigned pci_find_capability(struct device * dev, unsigned cap) +unsigned int pci_find_capability(struct device *dev, unsigned int cap) { return pci_find_next_capability(dev, cap, 0); - } -/** Given a device and register, read the size of the BAR for that register. - * @param dev Pointer to the device structure - * @param resource Pointer to the resource structure - * @param index Address of the pci configuration register +/** + * Given a device and register, read the size of the BAR for that register. + * + * @param dev Pointer to the device structure. + * @param resource Pointer to the resource structure. + * @param index Address of the PCI configuration register. */ struct resource *pci_get_resource(struct device *dev, unsigned long index) { struct resource *resource; unsigned long value, attr; - resource_t moving, limit; + resource_t moving, limit; - /* Initialize the resources to nothing */ + /* Initialize the resources to nothing. */ resource = new_resource(dev, index); - /* Get the initial value */ + /* Get the initial value. */ value = pci_read_config32(dev, index); - /* See which bits move */ + /* See which bits move. */ moving = pci_moving_config32(dev, index); - /* Initialize attr to the bits that do not move */ + /* Initialize attr to the bits that do not move. */ attr = value & ~moving; - /* If it is a 64bit resource look at the high half as well */ + /* If it is a 64bit resource look at the high half as well. */ if (((attr & PCI_BASE_ADDRESS_SPACE_IO) == 0) && - ((attr & PCI_BASE_ADDRESS_MEM_LIMIT_MASK) == PCI_BASE_ADDRESS_MEM_LIMIT_64)) - { - /* Find the high bits that move */ - moving |= ((resource_t)pci_moving_config32(dev, index + 4)) << 32; + ((attr & PCI_BASE_ADDRESS_MEM_LIMIT_MASK) == + PCI_BASE_ADDRESS_MEM_LIMIT_64)) { + /* Find the high bits that move. */ + moving |= + ((resource_t) pci_moving_config32(dev, index + 4)) << 32; } - /* Find the resource constraints. - * + + /* Find the resource constraints. * Start by finding the bits that move. From there: * - Size is the least significant bit of the bits that move. * - Limit is all of the bits that move plus all of the lower bits. - * See PCI Spec 6.2.5.1 ... + * See PCI Spec 6.2.5.1. */ limit = 0; if (moving) { resource->size = 1; resource->align = resource->gran = 0; - while(!(moving & resource->size)) { + while (!(moving & resource->size)) { resource->size <<= 1; resource->align += 1; - resource->gran += 1; + resource->gran += 1; } resource->limit = limit = moving | (resource->size - 1); } - /* - * some broken hardware has read-only registers that do not + + /* Some broken hardware has read-only registers that do not * really size correctly. - * Example: the acer m7229 has BARs 1-4 normally read-only. + * Example: the Acer M7229 has BARs 1-4 normally read-only. * so BAR1 at offset 0x10 reads 0x1f1. If you size that register * by writing 0xffffffff to it, it will read back as 0x1f1 -- a * violation of the spec. @@ -210,20 +211,18 @@ struct resource *pci_get_resource(struct device *dev, unsigned long index) if (moving == 0) { if (value != 0) { printk(BIOS_DEBUG, - "%s register %02x(%08x), read-only ignoring it\n", - dev_path(dev), index, value); + "%s register %02x(%08x), read-only ignoring it\n", + dev_path(dev), index, value); } resource->flags = 0; - } - else if (attr & PCI_BASE_ADDRESS_SPACE_IO) { - /* An I/O mapped base address */ + } else if (attr & PCI_BASE_ADDRESS_SPACE_IO) { + /* An I/O mapped base address. */ attr &= PCI_BASE_ADDRESS_IO_ATTR_MASK; resource->flags |= IORESOURCE_IO; - /* I don't want to deal with 32bit I/O resources */ + /* I don't want to deal with 32bit I/O resources. */ resource->limit = 0xffff; - } - else { - /* A Memory mapped base address */ + } else { + /* A Memory mapped base address. */ attr &= PCI_BASE_ADDRESS_MEM_ATTR_MASK; resource->flags |= IORESOURCE_MEM; if (attr & PCI_BASE_ADDRESS_MEM_PREFETCH) { @@ -231,39 +230,35 @@ struct resource *pci_get_resource(struct device *dev, unsigned long index) } attr &= PCI_BASE_ADDRESS_MEM_LIMIT_MASK; if (attr == PCI_BASE_ADDRESS_MEM_LIMIT_32) { - /* 32bit limit */ + /* 32bit limit. */ resource->limit = 0xffffffffUL; - } - else if (attr == PCI_BASE_ADDRESS_MEM_LIMIT_1M) { - /* 1MB limit */ + } else if (attr == PCI_BASE_ADDRESS_MEM_LIMIT_1M) { + /* 1MB limit. */ resource->limit = 0x000fffffUL; - } - else if (attr == PCI_BASE_ADDRESS_MEM_LIMIT_64) { - /* 64bit limit */ + } else if (attr == PCI_BASE_ADDRESS_MEM_LIMIT_64) { + /* 64bit limit. */ resource->limit = 0xffffffffffffffffULL; resource->flags |= IORESOURCE_PCI64; - } - else { - /* Invalid value */ + } else { + /* Invalid value. */ resource->flags = 0; } } - /* Don't let the limit exceed which bits can move */ + /* Don't let the limit exceed which bits can move. */ if (resource->limit > limit) { resource->limit = limit; } #if 0 if (resource->flags) { - printk(BIOS_DEBUG,"%s %02x ->", - dev_path(dev), resource->index); - printk(BIOS_DEBUG," value: 0x%08Lx zeroes: 0x%08Lx ones: 0x%08Lx attr: %08lx\n", - value, zeroes, ones, attr); + printk(BIOS_DEBUG, "%s %02x ->", + dev_path(dev), resource->index); printk(BIOS_DEBUG, - "%s %02x -> size: 0x%08Lx max: 0x%08Lx %s\n ", - dev_path(dev), - resource->index, - resource->size, resource->limit, - resource_type(resource)); + " value: 0x%08Lx zeroes: 0x%08Lx ones: 0x%08Lx attr: %08lx\n", + value, zeroes, ones, attr); + printk(BIOS_DEBUG, + "%s %02x -> size: 0x%08Lx max: 0x%08Lx %s\n ", + dev_path(dev), resource->index, resource->size, + resource->limit, resource_type(resource)); } #endif @@ -274,30 +269,30 @@ static void pci_get_rom_resource(struct device *dev, unsigned long index) { struct resource *resource; unsigned long value; - resource_t moving, limit; + resource_t moving, limit; - if ((dev->on_mainboard) && (dev->rom_address == 0)) { - //skip it if rom_address is not set in MB Config.lb - return; - } + if ((dev->on_mainboard) && (dev->rom_address == 0)) { + // Skip it if rom_address is not set in MB Config.lb. + // TODO: No more Config.lb in LinuxBIOSv3. + return; + } - /* Initialize the resources to nothing */ + /* Initialize the resources to nothing. */ resource = new_resource(dev, index); - /* Get the initial value */ + /* Get the initial value. */ value = pci_read_config32(dev, index); - /* See which bits move */ + /* See which bits move. */ moving = pci_moving_config32(dev, index); - /* clear the Enable bit */ + /* Clear the Enable bit. */ moving = moving & ~PCI_ROM_ADDRESS_ENABLE; /* Find the resource constraints. - * * Start by finding the bits that move. From there: * - Size is the least significant bit of the bits that move. * - Limit is all of the bits that move plus all of the lower bits. - * See PCI Spec 6.2.5.1 ... + * See PCI Spec 6.2.5.1. */ limit = 0; @@ -307,45 +302,50 @@ static void pci_get_rom_resource(struct device *dev, unsigned long index) while (!(moving & resource->size)) { resource->size <<= 1; resource->align += 1; - resource->gran += 1; + resource->gran += 1; } resource->limit = limit = moving | (resource->size - 1); } if (moving == 0) { if (value != 0) { - printk(BIOS_DEBUG,"%s register %02x(%08x), read-only ignoring it\n", - dev_path(dev), index, value); + printk(BIOS_DEBUG, + "%s register %02x(%08x), read-only ignoring it\n", + dev_path(dev), index, value); } resource->flags = 0; } else { resource->flags |= IORESOURCE_MEM | IORESOURCE_READONLY; } - /* for on board device with embedded ROM image, the ROM image is at + /* For on board device with embedded ROM image, the ROM image is at * fixed address specified in the Config.lb, the dev->rom_address is * inited by driver_pci_onboard_ops::enable_dev() */ + /* TODO: No more Config.lb in LinuxBIOSv3. */ if ((dev->on_mainboard) && (dev->rom_address != 0)) { - resource->base = dev->rom_address; + resource->base = dev->rom_address; resource->flags |= IORESOURCE_MEM | IORESOURCE_READONLY | - IORESOURCE_ASSIGNED | IORESOURCE_FIXED; - } + IORESOURCE_ASSIGNED | IORESOURCE_FIXED; + } compact_resources(dev); } -/** Read the base address registers for a given device. - * @param dev Pointer to the dev structure - * @param howmany How many registers to read (6 for device, 2 for bridge) +/** + * Read the base address registers for a given device. + * + * @param dev Pointer to the dev structure. + * @param howmany How many registers to read (6 for device, 2 for bridge). */ static void pci_read_bases(struct device *dev, unsigned int howmany) { unsigned long index; - for(index = PCI_BASE_ADDRESS_0; (index < PCI_BASE_ADDRESS_0 + (howmany << 2)); ) { + for (index = PCI_BASE_ADDRESS_0; + (index < PCI_BASE_ADDRESS_0 + (howmany << 2));) { struct resource *resource; resource = pci_get_resource(dev, index); - index += (resource->flags & IORESOURCE_PCI64)?8:4; + index += (resource->flags & IORESOURCE_PCI64) ? 8 : 4; } compact_resources(dev); @@ -353,11 +353,11 @@ static void pci_read_bases(struct device *dev, unsigned int howmany) static void pci_set_resource(struct device *dev, struct resource *resource); -static void pci_record_bridge_resource( - struct device *dev, resource_t moving, - unsigned index, unsigned long mask, unsigned long type) +static void pci_record_bridge_resource(struct device *dev, resource_t moving, + unsigned int index, unsigned long mask, + unsigned long type) { - /* Initiliaze the constraints on the current bus */ + /* Initiliaze the constraints on the current bus. */ struct resource *resource; resource = 0; if (moving) { @@ -367,7 +367,7 @@ static void pci_record_bridge_resource( resource->size = 0; gran = 0; step = 1; - while((moving & step) == 0) { + while ((moving & step) == 0) { gran += 1; step <<= 1; } @@ -394,47 +394,45 @@ static void pci_bridge_read_bases(struct device *dev) { resource_t moving_base, moving_limit, moving; - /* See if the bridge I/O resources are implemented */ - moving_base = ((u32)pci_moving_config8(dev, PCI_IO_BASE)) << 8; - moving_base |= ((u32)pci_moving_config16(dev, PCI_IO_BASE_UPPER16)) << 16; + /* See if the bridge I/O resources are implemented. */ + moving_base = ((u32) pci_moving_config8(dev, PCI_IO_BASE)) << 8; + moving_base |= + ((u32) pci_moving_config16(dev, PCI_IO_BASE_UPPER16)) << 16; - moving_limit = ((u32)pci_moving_config8(dev, PCI_IO_LIMIT)) << 8; - moving_limit |= ((u32)pci_moving_config16(dev, PCI_IO_LIMIT_UPPER16)) << 16; + moving_limit = ((u32) pci_moving_config8(dev, PCI_IO_LIMIT)) << 8; + moving_limit |= + ((u32) pci_moving_config16(dev, PCI_IO_LIMIT_UPPER16)) << 16; moving = moving_base & moving_limit; - /* Initialize the io space constraints on the current bus */ - pci_record_bridge_resource( - dev, moving, PCI_IO_BASE, - IORESOURCE_IO, IORESOURCE_IO); + /* Initialize the I/O space constraints on the current bus. */ + pci_record_bridge_resource(dev, moving, PCI_IO_BASE, + IORESOURCE_IO, IORESOURCE_IO); + /* See if the bridge prefmem resources are implemented. */ + moving_base = + ((resource_t) pci_moving_config16(dev, PCI_PREF_MEMORY_BASE)) << 16; + moving_base |= ((resource_t) pci_moving_config32(dev, PCI_PREF_BASE_UPPER32)) << 32; - /* See if the bridge prefmem resources are implemented */ - moving_base = ((resource_t)pci_moving_config16(dev, PCI_PREF_MEMORY_BASE)) << 16; - moving_base |= ((resource_t)pci_moving_config32(dev, PCI_PREF_BASE_UPPER32)) << 32; + moving_limit = ((resource_t) pci_moving_config16(dev, PCI_PREF_MEMORY_LIMIT)) << 16; + moving_limit |= ((resource_t) pci_moving_config32(dev, PCI_PREF_LIMIT_UPPER32)) << 32; - moving_limit = ((resource_t)pci_moving_config16(dev, PCI_PREF_MEMORY_LIMIT)) << 16; - moving_limit |= ((resource_t)pci_moving_config32(dev, PCI_PREF_LIMIT_UPPER32)) << 32; - moving = moving_base & moving_limit; - /* Initiliaze the prefetchable memory constraints on the current bus */ - pci_record_bridge_resource( - dev, moving, PCI_PREF_MEMORY_BASE, - IORESOURCE_MEM | IORESOURCE_PREFETCH, - IORESOURCE_MEM | IORESOURCE_PREFETCH); - + /* Initialize the prefetchable memory constraints on the current bus. */ + pci_record_bridge_resource(dev, moving, PCI_PREF_MEMORY_BASE, + IORESOURCE_MEM | IORESOURCE_PREFETCH, + IORESOURCE_MEM | IORESOURCE_PREFETCH); - /* See if the bridge mem resources are implemented */ - moving_base = ((u32)pci_moving_config16(dev, PCI_MEMORY_BASE)) << 16; - moving_limit = ((u32)pci_moving_config16(dev, PCI_MEMORY_LIMIT)) << 16; + /* See if the bridge mem resources are implemented. */ + moving_base = ((u32) pci_moving_config16(dev, PCI_MEMORY_BASE)) << 16; + moving_limit = ((u32) pci_moving_config16(dev, PCI_MEMORY_LIMIT)) << 16; moving = moving_base & moving_limit; - /* Initialize the memory resources on the current bus */ - pci_record_bridge_resource( - dev, moving, PCI_MEMORY_BASE, - IORESOURCE_MEM | IORESOURCE_PREFETCH, - IORESOURCE_MEM); + /* Initialize the memory resources on the current bus. */ + pci_record_bridge_resource(dev, moving, PCI_MEMORY_BASE, + IORESOURCE_MEM | IORESOURCE_PREFETCH, + IORESOURCE_MEM); compact_resources(dev); } @@ -456,30 +454,30 @@ static void pci_set_resource(struct device *dev, struct resource *resource) { resource_t base, end; - /* Make certain the resource has actually been set */ + /* Make certain the resource has actually been set. */ if (!(resource->flags & IORESOURCE_ASSIGNED)) { - printk(BIOS_ERR,"ERROR: %s %02x %s size: 0x%010Lx not assigned\n", - dev_path(dev), resource->index, - resource_type(resource), - resource->size); + printk(BIOS_ERR, + "ERROR: %s %02x %s size: 0x%010Lx not assigned\n", + dev_path(dev), resource->index, resource_type(resource), + resource->size); return; } - /* If I have already stored this resource don't worry about it */ + /* If I have already stored this resource don't worry about it. */ if (resource->flags & IORESOURCE_STORED) { return; } - /* If the resources is substractive don't worry about it */ + /* If the resource is substractive don't worry about it. */ if (resource->flags & IORESOURCE_SUBTRACTIVE) { return; } - /* Only handle PCI memory and IO resources for now */ - if (!(resource->flags & (IORESOURCE_MEM |IORESOURCE_IO))) + /* Only handle PCI memory and I/O resources for now. */ + if (!(resource->flags & (IORESOURCE_MEM | IORESOURCE_IO))) return; - /* Enable the resources in the command register */ + /* Enable the resources in the command register. */ if (resource->size) { if (resource->flags & IORESOURCE_MEM) { dev->command |= PCI_COMMAND_MEMORY; @@ -491,19 +489,18 @@ static void pci_set_resource(struct device *dev, struct resource *resource) dev->command |= PCI_COMMAND_MASTER; } } - /* Get the base address */ + /* Get the base address. */ base = resource->base; - /* Get the end */ + /* Get the end. */ end = resource_end(resource); - - /* Now store the resource */ + + /* Now store the resource. */ resource->flags |= IORESOURCE_STORED; if (!(resource->flags & IORESOURCE_PCI_BRIDGE)) { unsigned long base_lo, base_hi; - /* - * some chipsets allow us to set/clear the IO bit. - * (e.g. VIA 82c686a.) So set it to be safe) + /* Some chipsets allow us to set/clear the I/O bit + * (e.g. VIA 82c686a). So set it to be safe. */ base_lo = base & 0xffffffff; base_hi = (base >> 32) & 0xffffffff; @@ -514,39 +511,35 @@ static void pci_set_resource(struct device *dev, struct resource *resource) if (resource->flags & IORESOURCE_PCI64) { pci_write_config32(dev, resource->index + 4, base_hi); } - } - else if (resource->index == PCI_IO_BASE) { - /* set the IO ranges */ - compute_allocate_resource(&dev->link[0], resource, - IORESOURCE_IO, IORESOURCE_IO); - pci_write_config8(dev, PCI_IO_BASE, base >> 8); - pci_write_config16(dev, PCI_IO_BASE_UPPER16, base >> 16); - pci_write_config8(dev, PCI_IO_LIMIT, end >> 8); - pci_write_config16(dev, PCI_IO_LIMIT_UPPER16, end >> 16); - } - else if (resource->index == PCI_MEMORY_BASE) { - /* set the memory range */ + } else if (resource->index == PCI_IO_BASE) { + /* Set the I/O ranges. */ compute_allocate_resource(&dev->link[0], resource, - IORESOURCE_MEM | IORESOURCE_PREFETCH, - IORESOURCE_MEM); + IORESOURCE_IO, IORESOURCE_IO); + pci_write_config8(dev, PCI_IO_BASE, base >> 8); + pci_write_config16(dev, PCI_IO_BASE_UPPER16, base >> 16); + pci_write_config8(dev, PCI_IO_LIMIT, end >> 8); + pci_write_config16(dev, PCI_IO_LIMIT_UPPER16, end >> 16); + } else if (resource->index == PCI_MEMORY_BASE) { + /* Set the memory range. */ + compute_allocate_resource(&dev->link[0], resource, + IORESOURCE_MEM | IORESOURCE_PREFETCH, + IORESOURCE_MEM); pci_write_config16(dev, PCI_MEMORY_BASE, base >> 16); pci_write_config16(dev, PCI_MEMORY_LIMIT, end >> 16); - } - else if (resource->index == PCI_PREF_MEMORY_BASE) { - /* set the prefetchable memory range */ + } else if (resource->index == PCI_PREF_MEMORY_BASE) { + /* Set the prefetchable memory range. */ compute_allocate_resource(&dev->link[0], resource, - IORESOURCE_MEM | IORESOURCE_PREFETCH, - IORESOURCE_MEM | IORESOURCE_PREFETCH); + IORESOURCE_MEM | IORESOURCE_PREFETCH, + IORESOURCE_MEM | IORESOURCE_PREFETCH); pci_write_config16(dev, PCI_PREF_MEMORY_BASE, base >> 16); pci_write_config32(dev, PCI_PREF_BASE_UPPER32, base >> 32); pci_write_config16(dev, PCI_PREF_MEMORY_LIMIT, end >> 16); pci_write_config32(dev, PCI_PREF_LIMIT_UPPER32, end >> 32); - } - else { - /* Don't let me think I stored the resource */ + } else { + /* Don't let me think I stored the resource. */ resource->flags &= ~IORESOURCE_STORED; - printk(BIOS_ERR,"ERROR: invalid resource->index %x\n", - resource->index); + printk(BIOS_ERR, "ERROR: invalid resource->index %x\n", + resource->index); } report_resource_stored(dev, resource, ""); return; @@ -555,15 +548,15 @@ static void pci_set_resource(struct device *dev, struct resource *resource) void pci_dev_set_resources(struct device *dev) { struct resource *resource, *last; - unsigned link; + unsigned int link; u8 line; last = &dev->resource[dev->resources]; - for(resource = &dev->resource[0]; resource < last; resource++) { + for (resource = &dev->resource[0]; resource < last; resource++) { pci_set_resource(dev, resource); } - for(link = 0; link < dev->links; link++) { + for (link = 0; link < dev->links; link++) { struct bus *bus; bus = &dev->link[link]; if (bus->children) { @@ -571,20 +564,20 @@ void pci_dev_set_resources(struct device *dev) } } - /* set a default latency timer */ + /* Set a default latency timer. */ pci_write_config8(dev, PCI_LATENCY_TIMER, 0x40); - /* set a default secondary latency timer */ + /* Set a default secondary latency timer. */ if ((dev->hdr_type & 0x7f) == PCI_HEADER_TYPE_BRIDGE) { pci_write_config8(dev, PCI_SEC_LATENCY_TIMER, 0x40); } - /* zero the irq settings */ + /* Zero the IRQ settings. */ line = pci_read_config8(dev, PCI_INTERRUPT_PIN); if (line) { pci_write_config8(dev, PCI_INTERRUPT_LINE, 0); } - /* set the cache line size, so far 64 bytes is good for everyone */ + /* Set the cache line size, so far 64 bytes is good for everyone. */ pci_write_config8(dev, PCI_CACHE_LINE_SIZE, 64 >> 2); } @@ -593,44 +586,46 @@ void pci_dev_enable_resources(struct device *dev) const struct pci_operations *ops; u16 command; - /* Set the subsystem vendor and device id for mainboard devices */ + /* Set the subsystem vendor and device ID for mainboard devices. */ ops = ops_pci(dev); #if defined(CONFIG_MAINBOARD_PCI_SUBSYSTEM_VENDOR_ID) && \ defined(CONFIG_MAINBOARD_PCI_SUBSYSTEM_DEVICE_ID) if (dev->on_mainboard && ops && ops->set_subsystem) { - printk(BIOS_DEBUG,"%s: Setting subsystem VID/DID to %02x/%02x\n", - dev_path(dev), - CONFIG_MAINBOARD_PCI_SUBSYSTEM_VENDOR_ID, - CONFIG_MAINBOARD_PCI_SUBSYSTEM_DEVICE_ID); + printk(BIOS_DEBUG, + "%s: Setting subsystem VID/DID to %02x/%02x\n", + dev_path(dev), CONFIG_MAINBOARD_PCI_SUBSYSTEM_VENDOR_ID, + CONFIG_MAINBOARD_PCI_SUBSYSTEM_DEVICE_ID); - ops->set_subsystem(dev, - CONFIG_MAINBOARD_PCI_SUBSYSTEM_VENDOR_ID, - CONFIG_MAINBOARD_PCI_SUBSYSTEM_DEVICE_ID); + ops->set_subsystem(dev, + CONFIG_MAINBOARD_PCI_SUBSYSTEM_VENDOR_ID, + CONFIG_MAINBOARD_PCI_SUBSYSTEM_DEVICE_ID); } #endif command = pci_read_config16(dev, PCI_COMMAND); command |= dev->command; - command |= (PCI_COMMAND_PARITY + PCI_COMMAND_SERR); /* error check */ - printk(BIOS_DEBUG,"%s: %s(%s) cmd <- %02x\n", __func__, dev->dtsname, dev_path(dev), command); + command |= (PCI_COMMAND_PARITY + PCI_COMMAND_SERR); // Error check. + printk(BIOS_DEBUG, "%s: %s(%s) cmd <- %02x\n", __func__, dev->dtsname, + dev_path(dev), command); pci_write_config16(dev, PCI_COMMAND, command); } void pci_bus_enable_resources(struct device *dev) { u16 ctrl; - /* enable IO in command register if there is VGA card - * connected with (even it does not claim IO resource) */ + + /* Enable I/O in command register if there is VGA card + * connected with (even it does not claim I/O resource). + */ if (dev->link[0].bridge_ctrl & PCI_BRIDGE_CTL_VGA) dev->command |= PCI_COMMAND_IO; ctrl = pci_read_config16(dev, PCI_BRIDGE_CONTROL); ctrl |= dev->link[0].bridge_ctrl; - ctrl |= (PCI_BRIDGE_CTL_PARITY + PCI_BRIDGE_CTL_SERR); /* error check */ - printk(BIOS_DEBUG,"%s bridge ctrl <- %04x\n", dev_path(dev), ctrl); + ctrl |= (PCI_BRIDGE_CTL_PARITY + PCI_BRIDGE_CTL_SERR); // Error check. + printk(BIOS_DEBUG, "%s bridge ctrl <- %04x\n", dev_path(dev), ctrl); pci_write_config16(dev, PCI_BRIDGE_CONTROL, ctrl); pci_dev_enable_resources(dev); - enable_childrens_resources(dev); } @@ -646,20 +641,21 @@ void pci_bus_reset(struct bus *bus) delay(1); } -void pci_dev_set_subsystem(struct device * dev, unsigned vendor, unsigned device) +void pci_dev_set_subsystem(struct device *dev, unsigned int vendor, + unsigned int device) { - pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, - ((device & 0xffff) << 16) | (vendor & 0xffff)); + pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, + ((device & 0xffff) << 16) | (vendor & 0xffff)); } void pci_dev_init(struct device *dev) { #if defined(CONFIG_PCI_OPTION_ROM_RUN) && CONFIG_PCI_OPTION_ROM_RUN == 1 - void run_bios(struct device * dev, unsigned long addr); + void run_bios(struct device *dev, unsigned long addr); void do_vgabios(void); struct rom_header *rom, *ram; - printk(BIOS_INFO, "Probing for option rom\n"); + printk(BIOS_INFO, "Probing for option ROM\n"); rom = pci_rom_probe(dev); if (rom == NULL) return; @@ -677,7 +673,7 @@ void pci_dev_init(struct device *dev) #endif } -/** Default device operation for PCI devices */ +/** Default device operation for PCI devices. */ struct pci_operations pci_dev_ops_pci = { .set_subsystem = pci_dev_set_subsystem, }; @@ -686,13 +682,13 @@ struct device_operations default_pci_ops_dev = { .phase4_read_resources = pci_dev_read_resources, .phase4_set_resources = pci_dev_set_resources, .phase5_enable_resources = pci_dev_enable_resources, - .phase6_init = pci_dev_init, - .phase3_scan = 0, - .phase4_enable_disable = 0, - .ops_pci = &pci_dev_ops_pci, + .phase6_init = pci_dev_init, + .phase3_scan = 0, + .phase4_enable_disable = 0, + .ops_pci = &pci_dev_ops_pci, }; -/** Default device operations for PCI bridges */ +/** Default device operations for PCI bridges. */ struct pci_operations pci_bus_ops_pci = { .set_subsystem = 0, }; @@ -701,38 +697,36 @@ struct device_operations default_pci_ops_bus = { .phase4_read_resources = pci_bus_read_resources, .phase4_set_resources = pci_dev_set_resources, .phase5_enable_resources = pci_bus_enable_resources, - .phase6_init = 0, - .phase3_scan = pci_scan_bridge, - .phase4_enable_disable = 0, - .reset_bus = pci_bus_reset, - .ops_pci = &pci_bus_ops_pci, + .phase6_init = 0, + .phase3_scan = pci_scan_bridge, + .phase4_enable_disable = 0, + .reset_bus = pci_bus_reset, + .ops_pci = &pci_bus_ops_pci, }; /** - * @brief Detect the type of downstream bridge + * Detect the type of downstream bridge. * - * This function is a heuristic to detect which type - * of bus is downstream of a pci to pci bridge. This - * functions by looking for various capability blocks - * to figure out the type of downstream bridge. PCI-X - * PCI-E, and Hypertransport all seem to have appropriate - * capabilities. + * This function is a heuristic to detect which type of bus is downstream + * of a PCI-to-PCI bridge. This functions by looking for various capability + * blocks to figure out the type of downstream bridge. PCI-X, PCI-E, and + * Hypertransport all seem to have appropriate capabilities. * * When only a PCI-Express capability is found the type * is examined to see which type of bridge we have. * - * @param dev - * - * @return appropriate bridge operations + * @param dev TODO + * @return Appropriate bridge operations. */ -static struct device_operations *get_pci_bridge_ops(struct device * dev) +static struct device_operations *get_pci_bridge_ops(struct device *dev) { - // unsigned pos; + // unsigned int pos; #if CONFIG_PCIX_PLUGIN_SUPPORT == 1 pos = pci_find_capability(dev, PCI_CAP_ID_PCIX); if (pos) { - printk(BIOS_DEBUG,"%s subbordinate bus PCI-X\n", dev_path(dev)); + printk(BIOS_DEBUG, "%s subbordinate bus PCI-X\n", + dev_path(dev)); return &default_pcix_ops_bus; } #endif @@ -741,13 +735,14 @@ static struct device_operations *get_pci_bridge_ops(struct device * dev) #endif #if CONFIG_HYPERTRANSPORT_PLUGIN_SUPPORT == 1 pos = 0; - while((pos = pci_find_next_capability(dev, PCI_CAP_ID_HT, pos))) { - unsigned flags; + while ((pos = pci_find_next_capability(dev, PCI_CAP_ID_HT, pos))) { + unsigned int flags; flags = pci_read_config16(dev, pos + PCI_CAP_FLAGS); if ((flags >> 13) == 1) { - /* Host or Secondary Interface */ - printk(BIOS_DEBUG,"%s subbordinate bus Hypertransport\n", - dev_path(dev)); + /* Host or Secondary Interface. */ + printk(BIOS_DEBUG, + "%s subbordinate bus Hypertransport\n", + dev_path(dev)); return &default_ht_ops_bus; } } @@ -755,18 +750,18 @@ static struct device_operations *get_pci_bridge_ops(struct device * dev) #if CONFIG_PCIEXP_PLUGIN_SUPPORT == 1 pos = pci_find_capability(dev, PCI_CAP_ID_PCIE); if (pos) { - unsigned flags; + unsigned int flags; flags = pci_read_config16(dev, pos + PCI_EXP_FLAGS); - switch((flags & PCI_EXP_FLAGS_TYPE) >> 4) { + switch ((flags & PCI_EXP_FLAGS_TYPE) >> 4) { case PCI_EXP_TYPE_ROOT_PORT: case PCI_EXP_TYPE_UPSTREAM: case PCI_EXP_TYPE_DOWNSTREAM: - printk(BIOS_DEBUG,"%s subbordinate bus PCI Express\n", - dev_path(dev)); + printk(BIOS_DEBUG, "%s subbordinate bus PCI Express\n", + dev_path(dev)); return &default_pciexp_ops_bus; case PCI_EXP_TYPE_PCI_BRIDGE: - printk(BIOS_DEBUG,"%s subbordinate PCI\n", - dev_path(dev)); + printk(BIOS_DEBUG, "%s subbordinate PCI\n", + dev_path(dev)); return &default_pci_ops_bus; default: break; @@ -777,41 +772,41 @@ static struct device_operations *get_pci_bridge_ops(struct device * dev) } /** - * @brief Set up PCI device operation - * - * - * @param dev + * Set up PCI device operation. * + * @param dev TODO * @see pci_drivers */ static void set_pci_ops(struct device *dev) { struct constructor *c; - struct device_id id = {.type = DEVICE_ID_PCI}; + struct device_id id = {.type = DEVICE_ID_PCI }; if (dev->ops) { - printk(BIOS_SPEW, "%s: dev %p(%s) already has ops %p\n", __func__, dev, dev->dtsname, dev->ops); + printk(BIOS_SPEW, "%s: dev %p(%s) already has ops %p\n", + __func__, dev, dev->dtsname, dev->ops); return; } - /* we need to make the id in the device a device_id type ... */ + /* 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; + /* Look through the list of setup drivers and find one for - * this pci device + * this PCI device. */ 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 [%04x/%04x] %sops\n", + dev_path(dev), dev_id_string(&id), dev->vendor, + dev->device, (dev->ops->phase3_scan ? "bus " : "")); return; } - /* If I don't have a specific driver use the default operations */ - switch(dev->hdr_type & 0x7f) { /* header type */ - case PCI_HEADER_TYPE_NORMAL: /* standard header */ + /* If I don't have a specific driver use the default operations. */ + switch (dev->hdr_type & 0x7f) { /* Header type. */ + case PCI_HEADER_TYPE_NORMAL: /* Standard header. */ if ((dev->class >> 8) == PCI_CLASS_BRIDGE_PCI) goto bad; dev->ops = &default_pci_ops_dev; @@ -827,67 +822,71 @@ static void set_pci_ops(struct device *dev) break; #endif default: - bad: + bad: if (dev->enabled) { - printk(BIOS_ERR,"%s [%04x/%04x/%06x] has unknown header " - "type %02x, ignoring.\n", - dev_path(dev), - dev->vendor, dev->device, - dev->class >> 8, dev->hdr_type); + printk(BIOS_ERR, + "%s [%04x/%04x/%06x] has unknown header " + "type %02x, ignoring.\n", dev_path(dev), + dev->vendor, dev->device, dev->class >> 8, + dev->hdr_type); } } - printk(BIOS_INFO, "%s: dev %p(%s) set ops to %p\n", __func__, dev, dev->dtsname, dev->ops); + printk(BIOS_INFO, "%s: dev %p(%s) set ops to %p\n", __func__, dev, + dev->dtsname, dev->ops); return; } - - /** - * @brief See if we have already allocated a device structure for a given devfn. + * See if we have already allocated a device structure for a given devfn. * * Given a linked list of PCI device structures and a devfn number, find the * device structure correspond to the devfn, if present. This function also * removes the device structure from the linked list. * - * @param list the device structure list - * @param devfn a device/function number - * - * @return pointer to the device structure found or null of we have not + * @param list The device structure list. + * @param devfn A device/function number. + * @return Pointer to the device structure found or NULL of we have not * allocated a device for this devfn yet. */ static struct device *pci_scan_get_dev(struct device **list, unsigned int devfn) { struct device *dev; dev = 0; - printk(BIOS_SPEW, "%s: list is %p, *list is %p\n", __func__, list, *list); - for(; *list; list = &(*list)->sibling) { - printk(BIOS_SPEW, "%s: check dev %s \n", __func__, (*list)->dtsname); + printk(BIOS_SPEW, "%s: list is %p, *list is %p\n", __func__, list, + *list); + for (/* */; *list; list = &(*list)->sibling) { + printk(BIOS_SPEW, "%s: check dev %s \n", __func__, + (*list)->dtsname); if ((*list)->path.type != DEVICE_PATH_PCI) { - printk(BIOS_ERR,"%s: child %s(%s) not a pci device: it's type %d\n", __FUNCTION__, - (*list)->dtsname, dev_path(*list), (*list)->path.type); + printk(BIOS_ERR, + "%s: child %s(%s) not a pci device: it's type %d\n", + __FUNCTION__, (*list)->dtsname, dev_path(*list), + (*list)->path.type); continue; } - printk(BIOS_SPEW, "%s: check dev %s it has devfn 0x%x\n", __func__, (*list)->dtsname, (*list)->path.u.pci.devfn); + printk(BIOS_SPEW, "%s: check dev %s it has devfn 0x%x\n", + __func__, (*list)->dtsname, (*list)->path.u.pci.devfn); if ((*list)->path.u.pci.devfn == devfn) { - /* Unlink from the list */ + /* Unlink from the list. */ dev = *list; *list = (*list)->sibling; dev->sibling = 0; break; } } - /* Just like alloc_dev add the device to the list of device on the bus. - * When the list of devices was formed we removed all of the parents - * children, and now we are interleaving static and dynamic devices in - * order on the bus. + + /* Just like alloc_dev() add the device to the list of devices on the + * bus. When the list of devices was formed we removed all of the + * parents children, and now we are interleaving static and dynamic + * devices in order on the bus. */ if (dev) { - struct device * child; - /* Find the last child of our parent */ - for(child = dev->bus->children; child && child->sibling; ) { + struct device *child; + /* Find the last child of our parent. */ + for (child = dev->bus->children; child && child->sibling;) { child = child->sibling; } - /* Place the device on the list of children of it's parent. */ + /* Place the device on the list of children of its parent. */ if (child) { child->sibling = dev; } else { @@ -899,7 +898,7 @@ static struct device *pci_scan_get_dev(struct device **list, unsigned int devfn) } /** - * @brief Scan a PCI bus. + * Scan a PCI bus. * * Determine the existence of a given PCI device. * @@ -909,117 +908,108 @@ static struct device *pci_scan_get_dev(struct device **list, unsigned int devfn) * @return The device structure for hte device (if found) * or the NULL if no device is found. */ -struct device * pci_probe_dev(struct device * dev, struct bus *bus, unsigned devfn) +struct device *pci_probe_dev(struct device *dev, struct bus *bus, + unsigned int devfn) { u32 id, class; u8 hdr_type; - /* Detect if a device is present */ + /* Detect if a device is present. */ if (!dev) { struct device dummy; struct device_id devid; - dummy.bus = bus; - dummy.path.type = DEVICE_PATH_PCI; + dummy.bus = bus; + dummy.path.type = DEVICE_PATH_PCI; dummy.path.u.pci.devfn = devfn; id = pci_read_config32(&dummy, PCI_VENDOR_ID); /* Have we found somthing? * Some broken boards return 0 if a slot is empty. */ - if ( (id == 0xffffffff) || (id == 0x00000000) || - (id == 0x0000ffff) || (id == 0xffff0000)) - { - printk(BIOS_SPEW,"PCI: devfn 0x%x, bad id 0x%x\n", devfn, id); + if ((id == 0xffffffff) || (id == 0x00000000) || + (id == 0x0000ffff) || (id == 0xffff0000)) { + printk(BIOS_SPEW, "PCI: devfn 0x%x, bad id 0x%x\n", + devfn, id); return NULL; } devid.type = DEVICE_PATH_PCI; devid.u.pci.vendor = id & 0xffff; devid.u.pci.device = id >> 16; dev = alloc_dev(bus, &dummy.path, &devid); - } - else { - /* Enable/disable the device. Once we have - * found the device specific operations this - * operations we will disable the device with - * those as well. + } else { + /* Enable/disable the device. Once we have found the device + * specific operations this operations we will disable the + * device with those as well. * * This is geared toward devices that have subfunctions * that do not show up by default. * * If a device is a stuff option on the motherboard - * it may be absent and enable_dev must cope. - * + * it may be absent and enable_dev() must cope. */ - /* Run the magice enable sequence for the device */ + /* Run the magic enable sequence for the device. */ if (dev->ops && dev->ops->phase3_enable_scan) { dev->ops->phase3_enable_scan(dev); } - /* Now read the vendor and device id */ + /* Now read the vendor and device ID. */ id = pci_read_config32(dev, PCI_VENDOR_ID); - - - /* If the device does not have a pci id disable it. - * Possibly this is because we have already disabled - * the device. But this also handles optional devices - * that may not always show up. + + /* If the device does not have a PCI ID disable it. Possibly + * this is because we have already disabled the device. But + * this also handles optional devices that may not always + * show up. */ - /* If the chain is fully enumerated quit */ - if ( (id == 0xffffffff) || (id == 0x00000000) || - (id == 0x0000ffff) || (id == 0xffff0000)) - { + /* If the chain is fully enumerated quit. */ + if ((id == 0xffffffff) || (id == 0x00000000) || + (id == 0x0000ffff) || (id == 0xffff0000)) { if (dev->enabled) { - printk(BIOS_INFO,"Disabling static device: %s\n", - dev_path(dev)); + printk(BIOS_INFO, + "Disabling static device: %s\n", + dev_path(dev)); dev->enabled = 0; } return dev; } } - /* Read the rest of the pci configuration information */ + /* Read the rest of the PCI configuration information. */ hdr_type = pci_read_config8(dev, PCI_HEADER_TYPE); class = pci_read_config32(dev, PCI_CLASS_REVISION); - - /* Store the interesting information in the device structure */ + + /* Store the interesting information in the device structure. */ dev->vendor = id & 0xffff; dev->device = (id >> 16) & 0xffff; dev->hdr_type = hdr_type; - /* class code, the upper 3 bytes of PCI_CLASS_REVISION */ + /* Class code, the upper 3 bytes of PCI_CLASS_REVISION. */ dev->class = class >> 8; - - /* Architectural/System devices always need to - * be bus masters. - */ + /* Architectural/System devices always need to be bus masters. */ if ((dev->class >> 16) == PCI_BASE_CLASS_SYSTEM) { dev->command |= PCI_COMMAND_MASTER; } - /* Look at the vendor and device id, or at least the - * header type and class and figure out which set of - * configuration methods to use. Unless we already - * have some pci ops. + /* Look at the vendor and device ID, or at least the header type and + * class and figure out which set of configuration methods to use. + * Unless we already have some PCI ops. */ set_pci_ops(dev); - /* Now run the magic enable/disable sequence for the device */ + /* Now run the magic enable/disable sequence for the device. */ if (dev->ops && dev->ops->phase4_enable_disable) { dev->ops->phase4_enable_disable(dev); } - - /* Display the device and error if we don't have some pci operations + /* 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, - dev->enabled?"enabled": "disabled", - dev->ops?"" : " No operations" - ); + printk(BIOS_DEBUG, "%s [%04x/%04x] %s%s\n", + dev_path(dev), + dev->vendor, dev->device, + dev->enabled ? "enabled" : "disabled", + dev->ops ? "" : " No operations"); return dev; } /** - * @brief Scan a PCI bus. + * Scan a PCI bus. * * Determine the existence of devices and bridges on a PCI bus. If there are * bridges on the bus, recursively scan the buses behind the bridges. @@ -1027,118 +1017,119 @@ struct device * pci_probe_dev(struct device * dev, struct bus *bus, unsigned dev * This function is the default scan_bus() method for the root device * 'dev_root'. * - * @param bus pointer to the bus structure - * @param min_devfn minimum devfn to look at in the scan usually 0x00 - * @param max_devfn maximum devfn to look at in the scan usually 0xff - * @param max current bus number - * - * @return The maximum bus number found, after scanning all subordinate busses + * @param bus Pointer to the bus structure. + * @param min_devfn Minimum devfn to look at in the scan usually 0x00. + * @param max_devfn Maximum devfn to look at in the scan usually 0xff. + * @param max Current bus number. + * @return The maximum bus number found, after scanning all subordinate buses. */ -unsigned int pci_scan_bus(struct bus *bus, - unsigned min_devfn, unsigned max_devfn, - unsigned int max) +unsigned int pci_scan_bus(struct bus *bus, unsigned int min_devfn, + unsigned int max_devfn, unsigned int max) { unsigned int devfn; - struct device * old_devices; - struct device * child; + struct device *old_devices; + struct device *child; - printk(BIOS_DEBUG, "%s start bus %p, bus->dev %p\n", __func__, bus, bus->dev); + printk(BIOS_DEBUG, "%s start bus %p, bus->dev %p\n", __func__, bus, + bus->dev); #if PCI_BUS_SEGN_BITS - printk(BIOS_DEBUG,"PCI: pci_scan_bus for bus %04x:%02x\n", bus->secondary >> 8, bus->secondary & 0xff); + printk(BIOS_DEBUG, "PCI: pci_scan_bus for bus %04x:%02x\n", + bus->secondary >> 8, bus->secondary & 0xff); #else - printk(BIOS_DEBUG,"PCI: pci_scan_bus for bus %02x\n", bus->secondary); + printk(BIOS_DEBUG, "PCI: pci_scan_bus for bus %02x\n", bus->secondary); #endif old_devices = bus->children; - printk(BIOS_DEBUG, "%s: old_devices %p, dev for this bus %p(%s)\n", __func__, old_devices, bus->dev, bus->dev->dtsname); + printk(BIOS_DEBUG, "%s: old_devices %p, dev for this bus %p(%s)\n", + __func__, old_devices, bus->dev, bus->dev->dtsname); bus->children = 0; post_code(0x24); - printk(BIOS_SPEW,"PCI: scan devfn 0x%x to 0x%x\n", min_devfn, max_devfn); - /* probe all devices/functions on this bus with some optimization for - * non-existence and single funcion devices + printk(BIOS_SPEW, "PCI: scan devfn 0x%x to 0x%x\n", min_devfn, + max_devfn); + /* Probe all devices/functions on this bus with some optimization for + * non-existence and single function devices. */ for (devfn = min_devfn; devfn <= max_devfn; devfn++) { - struct device * dev; - printk(BIOS_SPEW,"PCI: devfn 0x%x\n", devfn); + struct device *dev; + printk(BIOS_SPEW, "PCI: devfn 0x%x\n", devfn); - /* First thing setup the device structure */ + /* First thing setup the device structure. */ dev = pci_scan_get_dev(&old_devices, devfn); - printk(BIOS_SPEW,"PCI: pci_scan_bus pci_scan_get_dev returns dev %s\n", dev ? dev->dtsname :"None (no dev in tree yet)"); - /* See if a device is present and setup the device - * structure. - */ - dev = pci_probe_dev(dev, bus, devfn); - printk(BIOS_SPEW,"PCI: pci_scan_bus pci_probe_dev returns dev %p(%s)\n", dev, dev->dtsname); + printk(BIOS_SPEW, + "PCI: pci_scan_bus pci_scan_get_dev returns dev %s\n", + dev ? dev->dtsname : "None (no dev in tree yet)"); + /* See if a device is present and setup the device structure. */ + dev = pci_probe_dev(dev, bus, devfn); + printk(BIOS_SPEW, + "PCI: pci_scan_bus pci_probe_dev returns dev %p(%s)\n", + dev, dev->dtsname); - /* if this is not a multi function device, - * or the device is not present don't waste - * time probing another function. - * Skip to next device. + /* If this is not a multi function device, or the device is + * not present don't waste time probing another function. + * Skip to next device. */ - if ((PCI_FUNC(devfn) == 0x00) && - (!dev || (dev->enabled && ((dev->hdr_type & 0x80) != 0x80)))) - { + if ((PCI_FUNC(devfn) == 0x00) && + (!dev + || (dev->enabled && ((dev->hdr_type & 0x80) != 0x80)))) { devfn += 0x07; } } - printk(BIOS_SPEW,"PCI: Done for loop\n"); + printk(BIOS_SPEW, "PCI: Done for loop\n"); post_code(0x25); - /* Die if any leftover Static devices are are found. + /* Die if any leftover static devices are are found. * There's probably a problem in the Config.lb. - */ - if(old_devices) { - struct device * left; - for(left = old_devices; left; left = left->sibling) { - printk(BIOS_ERR,"%s\n", dev_path(left)); + * TODO: No more Config.lb in LinuxBIOSv3. + */ + if (old_devices) { + struct device *left; + for (left = old_devices; left; left = left->sibling) { + printk(BIOS_ERR, "%s\n", dev_path(left)); } - die("PCI: Left over static devices. Check your Config.lb\n"); + die("PCI: Left over static devices.\n"); } - /* For all children that implement scan_bus (i.e. bridges) + /* For all children that implement scan_bus() (i.e. bridges) * scan the bus behind that child. */ - for(child = bus->children; child; child = child->sibling) { + for (child = bus->children; child; child = child->sibling) { max = dev_phase3_scan(child, max); } - /* - * We've scanned the bus and so we know all about what's on - * the other side of any bridges that may be on this bus plus - * any devices. - * + /* We've scanned the bus and so we know all about what's on the other + * side of any bridges that may be on this bus plus any devices. * Return how far we've got finding sub-buses. */ - printk(BIOS_DEBUG,"PCI: pci_scan_bus returning with max=%03x\n", max); + printk(BIOS_DEBUG, "PCI: pci_scan_bus returning with max=%03x\n", max); post_code(0x55); return max; } - /** - * @brief Scan a PCI bridge and the buses behind the bridge. + * Scan a PCI bridge and the buses behind the bridge. * * Determine the existence of buses behind the bridge. Set up the bridge * according to the result of the scan. * * This function is the default scan_bus() method for PCI bridge devices. * - * @param dev pointer to the bridge device - * @param max the highest bus number assgined up to now - * - * @return The maximum bus number found, after scanning all subordinate busses + * @param dev Pointer to the bridge device. + * @param max The highest bus number assigned up to now. + * @return The maximum bus number found, after scanning all subordinate buses. */ -unsigned int do_pci_scan_bridge(struct device *dev, unsigned int max, - unsigned int (*do_scan_bus)(struct bus *bus, - unsigned min_devfn, unsigned max_devfn, unsigned int max)) +unsigned int do_pci_scan_bridge(struct device *dev, unsigned int max, + unsigned int (*do_scan_bus) (struct bus * bus, + unsigned int min_devfn, + unsigned int max_devfn, + unsigned int max)) { struct bus *bus; u32 buses; u16 cr; - printk(BIOS_SPEW,"%s for %s\n", __func__, dev_path(dev)); + printk(BIOS_SPEW, "%s for %s\n", __func__, dev_path(dev)); bus = &dev->link[0]; bus->dev = dev; @@ -1156,8 +1147,7 @@ unsigned int do_pci_scan_bridge(struct device *dev, unsigned int max, pci_write_config16(dev, PCI_COMMAND, 0x0000); pci_write_config16(dev, PCI_STATUS, 0xffff); - /* - * Read the existing primary/secondary/subordinate bus + /* Read the existing primary/secondary/subordinate bus * number configuration. */ buses = pci_read_config32(dev, PCI_PRIMARY_BUS); @@ -1167,9 +1157,9 @@ unsigned int do_pci_scan_bridge(struct device *dev, unsigned int max, * correctly configured. */ buses &= 0xff000000; - buses |= (((unsigned int) (dev->bus->secondary) << 0) | - ((unsigned int) (bus->secondary) << 8) | - ((unsigned int) (bus->subordinate) << 16)); + buses |= (((unsigned int)(dev->bus->secondary) << 0) | + ((unsigned int)(bus->secondary) << 8) | + ((unsigned int)(bus->subordinate) << 16)); pci_write_config32(dev, PCI_PRIMARY_BUS, buses); /* Now we can scan all subordinate buses @@ -1181,108 +1171,119 @@ unsigned int do_pci_scan_bridge(struct device *dev, unsigned int max, * bus number to its real value. */ bus->subordinate = max; - buses = (buses & 0xff00ffff) | - ((unsigned int) (bus->subordinate) << 16); + buses = (buses & 0xff00ffff) | ((unsigned int)(bus->subordinate) << 16); pci_write_config32(dev, PCI_PRIMARY_BUS, buses); pci_write_config16(dev, PCI_COMMAND, cr); - + printk(BIOS_DEBUG, "%s DONE\n", __func__); - printk(BIOS_SPEW,"%s returns max %d\n", __func__, max); + printk(BIOS_SPEW, "%s returns max %d\n", __func__, max); return max; } /** - * @brief Scan a PCI bridge and the buses behind the bridge. + * Scan a PCI bridge and the buses behind the bridge. * * Determine the existence of buses behind the bridge. Set up the bridge * according to the result of the scan. * * This function is the default scan_bus() method for PCI bridge devices. * - * @param dev pointer to the bridge device - * @param max the highest bus number assgined up to now - * - * @return The maximum bus number found, after scanning all subordinate busses + * @param dev Pointer to the bridge device. + * @param max The highest bus number assgined up to now. + * @return The maximum bus number found, after scanning all subordinate buses. */ unsigned int pci_scan_bridge(struct device *dev, unsigned int max) { return do_pci_scan_bridge(dev, max, pci_scan_bus); } -/* - Tell the EISA int controller this int must be level triggered - THIS IS A KLUDGE -- sorry, this needs to get cleaned up. -*/ +/** + * Tell the EISA int controller this int must be level triggered. + * + * THIS IS A KLUDGE -- sorry, this needs to get cleaned up. + * + * @param intNum TODO + */ void pci_level_irq(unsigned char intNum) { - unsigned short intBits = inb(0x4d0) | (((unsigned) inb(0x4d1)) << 8); + unsigned short intBits = inb(0x4d0) | (((unsigned)inb(0x4d1)) << 8); - printk(BIOS_SPEW,"%s: current ints are 0x%x\n", __func__, intBits); + printk(BIOS_SPEW, "%s: current ints are 0x%x\n", __func__, intBits); intBits |= (1 << intNum); - printk(BIOS_SPEW,"%s: try to set ints 0x%x\n", __func__, intBits); + printk(BIOS_SPEW, "%s: try to set ints 0x%x\n", __func__, intBits); - // Write new values - outb((unsigned char) intBits, 0x4d0); - outb((unsigned char) (intBits >> 8), 0x4d1); + /* Write new values. */ + outb((unsigned char)intBits, 0x4d0); + outb((unsigned char)(intBits >> 8), 0x4d1); - /* this seems like an error but is not ... */ + /* This seems like an error but is not. */ #if 1 if (inb(0x4d0) != (intBits & 0xff)) { - printk(BIOS_ERR,"%s: lower order bits are wrong: want 0x%x, got 0x%x\n", - __func__, intBits &0xff, inb(0x4d0)); + printk(BIOS_ERR, + "%s: lower order bits are wrong: want 0x%x, got 0x%x\n", + __func__, intBits & 0xff, inb(0x4d0)); } if (inb(0x4d1) != ((intBits >> 8) & 0xff)) { - printk(BIOS_ERR,"%s: lower order bits are wrong: want 0x%x, got 0x%x\n", - __func__, (intBits>>8) &0xff, inb(0x4d1)); + printk(BIOS_ERR, + "%s: lower order bits are wrong: want 0x%x, got 0x%x\n", + __func__, (intBits >> 8) & 0xff, inb(0x4d1)); } #endif } -/* - This function assigns IRQs for all functions contained within - the indicated device address. If the device does not exist or does - not require interrupts then this function has no effect. - - This function should be called for each PCI slot in your system. - - pIntAtoD is an array of IRQ #s that are assigned to PINTA through PINTD of - this slot. - The particular irq #s that are passed in depend on the routing inside - your southbridge and on your motherboard. - - -kevinh@ispiri.com -*/ -void pci_assign_irqs(unsigned bus, unsigned slot, - const unsigned char pIntAtoD[4]) +/** + * This function assigns IRQs for all functions contained within the + * indicated device address. If the device does not exist or does not + * require interrupts then this function has no effect. + * + * This function should be called for each PCI slot in your system. + * + * pIntAtoD is an array of IRQ #s that are assigned to PINTA through PINTD of + * this slot. + * + * The particular irq #s that are passed in depend on the routing inside + * your southbridge and on your motherboard. + * + * -kevinh@ispiri.com + * + * @param bus TODO + * @param slot TODO + * @param pIntAtoD TODO + */ +void pci_assign_irqs(unsigned int bus, unsigned int slot, + const unsigned char pIntAtoD[4]) { - unsigned functNum; - struct device * pdev; + unsigned int functNum; + struct device *pdev; unsigned char line; unsigned char irq; unsigned char readback; - /* Each slot may contain up to eight functions */ + /* Each slot may contain up to eight functions. */ for (functNum = 0; functNum < 8; functNum++) { pdev = dev_find_slot(bus, (slot << 3) + functNum); if (pdev) { - line = pci_read_config8(pdev, PCI_INTERRUPT_PIN); + line = pci_read_config8(pdev, PCI_INTERRUPT_PIN); - // PCI spec says all other values are reserved + // PCI spec says all other values are reserved. if ((line >= 1) && (line <= 4)) { irq = pIntAtoD[line - 1]; - printk(BIOS_DEBUG,"Assigning IRQ %d to %d:%x.%d\n", \ - irq, bus, slot, functNum); + printk(BIOS_DEBUG, + "Assigning IRQ %d to %d:%x.%d\n", irq, + bus, slot, functNum); - pci_write_config8(pdev, PCI_INTERRUPT_LINE,\ - pIntAtoD[line - 1]); + pci_write_config8(pdev, PCI_INTERRUPT_LINE, + pIntAtoD[line - 1]); - readback = pci_read_config8(pdev, PCI_INTERRUPT_LINE); - printk(BIOS_DEBUG," Readback = %d\n", readback); + readback = + pci_read_config8(pdev, PCI_INTERRUPT_LINE); + printk(BIOS_DEBUG, " Readback = %d\n", + readback); - // Change to level triggered + // Change to level triggered. pci_level_irq(pIntAtoD[line - 1]); } } diff --git a/device/pci_ops.c b/device/pci_ops.c index 25b7c90756..80cb8f7199 100644 --- a/device/pci_ops.c +++ b/device/pci_ops.c @@ -26,54 +26,65 @@ #include #include -/* walk up the tree from the current dev, in an attempt to find a bus that has ops_pci_bus set */ -/* the assumption here being that if it has ops_pci_bus set, then it can do bus operations */ -static struct bus *get_pbus(struct device * dev) +/** + * Walk up the tree from the current dev, in an attempt to find a + * bus that has ops_pci_bus set. The assumption here being that if it + * has ops_pci_bus set, then it can do bus operations. + */ +static struct bus *get_pbus(struct device *dev) { struct bus *pbus = dev->bus; - while(pbus && pbus->dev && !ops_pci_bus(pbus)) { + while (pbus && pbus->dev && !ops_pci_bus(pbus)) { pbus = pbus->dev->bus; } - if (!pbus || !pbus->dev || !pbus->dev->ops || !pbus->dev->ops->ops_pci_bus) { - printk(BIOS_ALERT,"%s: %s(%s) Cannot find PCI bus operations", __func__, dev->dtsname, dev_path(dev)); + if (!pbus || !pbus->dev || !pbus->dev->ops + || !pbus->dev->ops->ops_pci_bus) { + printk(BIOS_ALERT, "%s: %s(%s) Cannot find PCI bus operations", + __func__, dev->dtsname, dev_path(dev)); die(""); - for(;;); + for (;;) ; } return pbus; } -u8 pci_read_config8(struct device * dev, unsigned where) +u8 pci_read_config8(struct device *dev, unsigned int where) { struct bus *pbus = get_pbus(dev); - return ops_pci_bus(pbus)->read8(pbus, dev->bus->secondary, dev->path.u.pci.devfn, where); + return ops_pci_bus(pbus)->read8(pbus, dev->bus->secondary, + dev->path.u.pci.devfn, where); } -u16 pci_read_config16(struct device * dev, unsigned where) +u16 pci_read_config16(struct device *dev, unsigned int where) { struct bus *pbus = get_pbus(dev); - return ops_pci_bus(pbus)->read16(pbus, dev->bus->secondary, dev->path.u.pci.devfn, where); + return ops_pci_bus(pbus)->read16(pbus, dev->bus->secondary, + dev->path.u.pci.devfn, where); } -u32 pci_read_config32(struct device * dev, unsigned where) +u32 pci_read_config32(struct device *dev, unsigned int where) { struct bus *pbus = get_pbus(dev); - return ops_pci_bus(pbus)->read32(pbus, dev->bus->secondary, dev->path.u.pci.devfn, where); + return ops_pci_bus(pbus)->read32(pbus, dev->bus->secondary, + dev->path.u.pci.devfn, where); } -void pci_write_config8(struct device * dev, unsigned where, u8 val) +void pci_write_config8(struct device *dev, unsigned int where, u8 val) { struct bus *pbus = get_pbus(dev); - ops_pci_bus(pbus)->write8(pbus, dev->bus->secondary, dev->path.u.pci.devfn, where, val); + ops_pci_bus(pbus)->write8(pbus, dev->bus->secondary, + dev->path.u.pci.devfn, where, val); } -void pci_write_config16(struct device * dev, unsigned where, u16 val) +void pci_write_config16(struct device *dev, unsigned int where, u16 val) { struct bus *pbus = get_pbus(dev); - ops_pci_bus(pbus)->write16(pbus, dev->bus->secondary, dev->path.u.pci.devfn, where, val); + ops_pci_bus(pbus)->write16(pbus, dev->bus->secondary, + dev->path.u.pci.devfn, where, val); } -void pci_write_config32(struct device * dev, unsigned where, u32 val) +void pci_write_config32(struct device *dev, unsigned int where, u32 val) { struct bus *pbus = get_pbus(dev); - ops_pci_bus(pbus)->write32(pbus, dev->bus->secondary, dev->path.u.pci.devfn, where, val); + ops_pci_bus(pbus)->write32(pbus, dev->bus->secondary, + dev->path.u.pci.devfn, where, val); } diff --git a/device/pci_rom.c b/device/pci_rom.c index e814cc398d..36b4e0c478 100644 --- a/device/pci_rom.c +++ b/device/pci_rom.c @@ -28,16 +28,18 @@ #include #include -struct rom_header * pci_rom_probe(struct device *dev) +struct rom_header *pci_rom_probe(struct device *dev) { unsigned long rom_address; struct rom_header *rom_header; struct pci_data *rom_data; - if (dev->on_mainboard) { - // in case some device PCI_ROM_ADDRESS can not be set or readonly + if (dev->on_mainboard) { + /* In case some device PCI_ROM_ADDRESS can not be set + * or readonly. + */ rom_address = dev->rom_address; - } else { + } else { rom_address = pci_read_config32(dev, PCI_ROM_ADDRESS); } @@ -45,42 +47,47 @@ struct rom_header * pci_rom_probe(struct device *dev) return NULL; } - printk(BIOS_DEBUG, "ROM address for %s = %x\n", dev_path(dev), rom_address); - - if(!dev->on_mainboard) { - /* enable expansion ROM address decoding */ + printk(BIOS_DEBUG, "ROM address for %s = %x\n", dev_path(dev), + rom_address); + + if (!dev->on_mainboard) { + /* Enable expansion ROM address decoding. */ pci_write_config32(dev, PCI_ROM_ADDRESS, - rom_address|PCI_ROM_ADDRESS_ENABLE); + rom_address | PCI_ROM_ADDRESS_ENABLE); } rom_header = (struct rom_header *)rom_address; - printk(BIOS_SPEW, "PCI Expansion ROM, signature 0x%04x, INIT size 0x%04x, data ptr 0x%04x\n", - le32_to_cpu(rom_header->signature), - rom_header->size * 512, le32_to_cpu(rom_header->data)); + printk(BIOS_SPEW, + "PCI Expansion ROM, signature 0x%04x, INIT size 0x%04x, data ptr 0x%04x\n", + le32_to_cpu(rom_header->signature), rom_header->size * 512, + le32_to_cpu(rom_header->data)); if (le32_to_cpu(rom_header->signature) != PCI_ROM_HDR) { - printk(BIOS_ERR, "Incorrect Expansion ROM Header Signature %04x\n", - le32_to_cpu(rom_header->signature)); + printk(BIOS_ERR, + "Incorrect Expansion ROM Header Signature %04x\n", + le32_to_cpu(rom_header->signature)); return NULL; } - rom_data = (struct pci_data *)((unsigned char *) rom_header + - le32_to_cpu(rom_header->data)); + rom_data = (struct pci_data *)((unsigned char *)rom_header + + le32_to_cpu(rom_header->data)); printk(BIOS_SPEW, "PCI ROM Image, Vendor %04x, Device %04x,\n", - rom_data->vendor, rom_data->device); + rom_data->vendor, rom_data->device); if (dev->vendor != rom_data->vendor || dev->device != rom_data->device) { - printk(BIOS_ERR, "Device or Vendor ID mismatch Vendor %04x, Device %04x\n", - rom_data->vendor, rom_data->device); + printk(BIOS_ERR, + "Device or Vendor ID mismatch Vendor %04x, Device %04x\n", + rom_data->vendor, rom_data->device); return NULL; } - printk(BIOS_SPEW, "PCI ROM Image, Class Code %04x%02x, Code Type %02x\n", - rom_data->class_hi, rom_data->class_lo, - rom_data->type); + printk(BIOS_SPEW, + "PCI ROM Image, Class Code %04x%02x, Code Type %02x\n", + rom_data->class_hi, rom_data->class_lo, rom_data->type); if (dev->class != ((rom_data->class_hi << 8) | rom_data->class_lo)) { - printk(BIOS_DEBUG, "Class Code mismatch ROM %08x, dev %08x\n", - (rom_data->class_hi << 8) | rom_data->class_lo, dev->class); - //return NULL; + printk(BIOS_DEBUG, "Class Code mismatch ROM %08x, dev %08x\n", + (rom_data->class_hi << 8) | rom_data->class_lo, + dev->class); + // return NULL; } return rom_header; @@ -89,53 +96,58 @@ struct rom_header * pci_rom_probe(struct device *dev) static void *pci_ram_image_start = (void *)PCI_RAM_IMAGE_START; #if defined(CONFIG_PCI_OPTION_ROM_RUN) && CONFIG_PCI_OPTION_ROM_RUN == 1 -extern int vga_inited; // defined in vga_console.c +extern int vga_inited; // Defined in vga_console.c. #ifndef CONFIG_MULTIPLE_VGA_INIT -extern struct device *vga_pri; // the primary vga device, defined in device.c +extern struct device *vga_pri; // The primary VGA device, defined in device.c. #endif #endif -struct rom_header *pci_rom_load(struct device *dev, struct rom_header *rom_header) +struct rom_header *pci_rom_load(struct device *dev, + struct rom_header *rom_header) { - struct pci_data * rom_data; + struct pci_data *rom_data; unsigned long rom_address; unsigned int rom_size; - unsigned int image_size=0; + unsigned int image_size = 0; rom_address = pci_read_config32(dev, PCI_ROM_ADDRESS); do { - rom_header = (struct rom_header *)((unsigned char *)rom_header - + image_size); // get next image - rom_data = (struct pci_data *)((unsigned char *) rom_header + - le32_to_cpu(rom_header->data)); - image_size = le32_to_cpu(rom_data->ilen) * 512; - } while ((rom_data->type!=0) && (rom_data->indicator!=0)); // make sure we got x86 version + rom_header = (struct rom_header *)((unsigned char *)rom_header + image_size); // Get next image. + rom_data = (struct pci_data *)((unsigned char *)rom_header + + le32_to_cpu(rom_header->data)); + image_size = le32_to_cpu(rom_data->ilen) * 512; + } while ((rom_data->type != 0) && (rom_data->indicator != 0)); // Make sure we got x86 version. - if(rom_data->type!=0) return NULL; + if (rom_data->type != 0) + return NULL; rom_size = rom_header->size * 512; if (PCI_CLASS_DISPLAY_VGA == rom_data->class_hi) { #if defined(CONFIG_PCI_OPTION_ROM_RUN) && CONFIG_PCI_OPTION_ROM_RUN == 1 - #ifndef CONFIG_MULTIPLE_VGA_INIT - if (dev != vga_pri) return NULL; // only one VGA supported - #endif - printk(BIOS_DEBUG, "Copying VGA ROM image from 0x%x to 0x%x, 0x%x bytes\n", - rom_header, PCI_VGA_RAM_IMAGE_START, rom_size); +#ifndef CONFIG_MULTIPLE_VGA_INIT + if (dev != vga_pri) + return NULL; // Only one VGA supported. +#endif + printk(BIOS_DEBUG, + "Copying VGA ROM image from 0x%x to 0x%x, 0x%x bytes\n", + rom_header, PCI_VGA_RAM_IMAGE_START, rom_size); memcpy((void *)PCI_VGA_RAM_IMAGE_START, rom_header, rom_size); vga_inited = 1; - return (struct rom_header *) (PCI_VGA_RAM_IMAGE_START); + return (struct rom_header *)(PCI_VGA_RAM_IMAGE_START); #endif } else { - printk(BIOS_DEBUG, "Copying non-VGA ROM image from 0x%x to 0x%x, 0x%x bytes\n", - rom_header, pci_ram_image_start, rom_size); + printk(BIOS_DEBUG, + "Copying non-VGA ROM image from 0x%x to 0x%x, 0x%x bytes\n", + rom_header, pci_ram_image_start, rom_size); memcpy(pci_ram_image_start, rom_header, rom_size); pci_ram_image_start += rom_size; - return (struct rom_header *) (pci_ram_image_start-rom_size); + return (struct rom_header *)(pci_ram_image_start - rom_size); } - /* disable expansion ROM address decoding */ - pci_write_config32(dev, PCI_ROM_ADDRESS, rom_address & ~PCI_ROM_ADDRESS_ENABLE); - + /* Disable expansion ROM address decoding. */ + pci_write_config32(dev, PCI_ROM_ADDRESS, + rom_address & ~PCI_ROM_ADDRESS_ENABLE); + return NULL; } diff --git a/device/pciexp_device.c b/device/pciexp_device.c index 47358aab65..574372c5d5 100644 --- a/device/pciexp_device.c +++ b/device/pciexp_device.c @@ -24,30 +24,26 @@ #include #include - static void pciexp_tune_dev(device_t dev) { - unsigned cap; - + unsigned int cap; cap = pci_find_capability(dev, PCI_CAP_ID_PCIE); if (!cap) { /* error... */ return; } - printk_debug("PCIEXP: tunning %s\n", dev_path(dev)); + printk_debug("PCIEXP: tuning %s\n", dev_path(dev)); #warning "IMPLEMENT PCI EXPRESS TUNING" } -unsigned int pciexp_scan_bus(struct bus *bus, - unsigned min_devfn, unsigned max_devfn, - unsigned int max) +unsigned int pciexp_scan_bus(struct bus *bus, unsigned int min_devfn, + unsigned int max_devfn, unsigned int max) { device_t child; max = pci_scan_bus(bus, min_devfn, max_devfn, max); - for(child = bus->children; child; child = child->sibling) { - if ( (child->path.u.pci.devfn < min_devfn) || - (child->path.u.pci.devfn > max_devfn)) - { + for (child = bus->children; child; child = child->sibling) { + if ((child->path.u.pci.devfn < min_devfn) || + (child->path.u.pci.devfn > max_devfn)) { continue; } pciexp_tune_dev(child); @@ -55,13 +51,12 @@ unsigned int pciexp_scan_bus(struct bus *bus, return max; } - unsigned int pciexp_scan_bridge(device_t dev, unsigned int max) { return do_pci_scan_bridge(dev, max, pciexp_scan_bus); } -/** Default device operations for PCI Express bridges */ +/** Default device operations for PCI Express bridges. */ static struct pci_operations pciexp_bus_ops_pci = { .set_subsystem = 0, }; @@ -70,8 +65,8 @@ struct device_operations default_pciexp_ops_bus = { .read_resources = pci_bus_read_resources, .set_resources = pci_dev_set_resources, .enable_resources = pci_bus_enable_resources, - .init = 0, - .scan_bus = pciexp_scan_bridge, + .init = 0, + .scan_bus = pciexp_scan_bridge, .enable = 0, .reset_bus = pci_bus_reset, .ops_pci = &pciexp_bus_ops_pci, diff --git a/device/pcix_device.c b/device/pcix_device.c index e4040cf617..635b9db246 100644 --- a/device/pcix_device.c +++ b/device/pcix_device.c @@ -24,12 +24,11 @@ #include #include - static void pcix_tune_dev(device_t dev) { - unsigned cap; - unsigned status, orig_cmd, cmd; - unsigned max_read, max_tran; + unsigned int cap; + unsigned int status, orig_cmd, cmd; + unsigned int max_read, max_tran; if (dev->hdr_type != PCI_HEADER_TYPE_NORMAL) { return; @@ -40,7 +39,7 @@ static void pcix_tune_dev(device_t dev) } printk_debug("%s PCI-X tuning\n", dev_path(dev)); status = pci_read_config32(dev, cap + PCI_X_STATUS); - orig_cmd = cmd = pci_read_config16(dev,cap + PCI_X_CMD); + orig_cmd = cmd = pci_read_config16(dev, cap + PCI_X_CMD); max_read = (status & PCI_X_STATUS_MAX_READ) >> 21; max_tran = (status & PCI_X_STATUS_MAX_SPLIT) >> 23; @@ -52,24 +51,23 @@ static void pcix_tune_dev(device_t dev) cmd &= ~PCI_X_CMD_MAX_SPLIT; cmd |= max_tran << 4; } - /* Don't attempt to handle PCI-X errors */ + /* Don't attempt to handle PCI-X errors. */ cmd &= ~PCI_X_CMD_DPERR_E; - /* Enable Relaxed Ordering */ + /* Enable Relaxed Ordering. */ cmd |= PCI_X_CMD_ERO; if (orig_cmd != cmd) { pci_write_config16(dev, cap + PCI_X_CMD, cmd); } } -unsigned int pcix_scan_bus(struct bus *bus, - unsigned min_devfn, unsigned max_devfn, unsigned int max) +unsigned int pcix_scan_bus(struct bus *bus, unsigned int min_devfn, + unsigned int max_devfn, unsigned int max) { device_t child; max = pci_scan_bus(bus, min_devfn, max_devfn, max); - for(child = bus->children; child; child = child->sibling) { - if ( (child->path.u.pci.devfn < min_devfn) || - (child->path.u.pci.devfn > max_devfn)) - { + for (child = bus->children; child; child = child->sibling) { + if ((child->path.u.pci.devfn < min_devfn) || + (child->path.u.pci.devfn > max_devfn)) { continue; } pcix_tune_dev(child); @@ -77,7 +75,7 @@ unsigned int pcix_scan_bus(struct bus *bus, return max; } -const char *pcix_speed(unsigned sstatus) +const char *pcix_speed(unsigned int sstatus) { static const char conventional[] = "Conventional PCI"; static const char pcix_66mhz[] = "66MHz PCI-X"; @@ -86,12 +84,12 @@ const char *pcix_speed(unsigned sstatus) static const char pcix_266mhz[] = "266MHz PCI-X"; static const char pcix_533mhz[] = "533MHZ PCI-X"; static const char unknown[] = "Unknown"; - const char *result; + result = unknown; - switch(PCI_X_SSTATUS_MFREQ(sstatus)) { - case PCI_X_SSTATUS_CONVENTIONAL_PCI: - result = conventional; + switch (PCI_X_SSTATUS_MFREQ(sstatus)) { + case PCI_X_SSTATUS_CONVENTIONAL_PCI: + result = conventional; break; case PCI_X_SSTATUS_MODE1_66MHZ: result = pcix_66mhz; @@ -99,17 +97,14 @@ const char *pcix_speed(unsigned sstatus) case PCI_X_SSTATUS_MODE1_100MHZ: result = pcix_100mhz; break; - case PCI_X_SSTATUS_MODE1_133MHZ: result = pcix_133mhz; break; - case PCI_X_SSTATUS_MODE2_266MHZ_REF_66MHZ: case PCI_X_SSTATUS_MODE2_266MHZ_REF_100MHZ: case PCI_X_SSTATUS_MODE2_266MHZ_REF_133MHZ: result = pcix_266mhz; break; - case PCI_X_SSTATUS_MODE2_533MHZ_REF_66MHZ: case PCI_X_SSTATUS_MODE2_533MHZ_REF_100MHZ: case PCI_X_SSTATUS_MODE2_533MHZ_REF_133MHZ: @@ -121,10 +116,9 @@ const char *pcix_speed(unsigned sstatus) unsigned int pcix_scan_bridge(device_t dev, unsigned int max) { - unsigned pos; - unsigned sstatus; + unsigned int pos, status; - /* Find the PCI-X capability */ + /* Find the PCI-X capability. */ pos = pci_find_capability(dev, PCI_CAP_ID_PCIX); sstatus = pci_read_config16(dev, pos + PCI_X_SEC_STATUS); @@ -134,14 +128,14 @@ unsigned int pcix_scan_bridge(device_t dev, unsigned int max) max = do_pci_scan_bridge(dev, max, pcix_scan_bus); } - /* Print the PCI-X bus speed */ - printk_debug("PCI: %02x: %s\n", dev->link[0].secondary, pcix_speed(sstatus)); + /* Print the PCI-X bus speed. */ + printk_debug("PCI: %02x: %s\n", dev->link[0].secondary, + pcix_speed(sstatus)); return max; } - -/** Default device operations for PCI-X bridges */ +/** Default device operations for PCI-X bridges. */ static struct pci_operations pcix_bus_ops_pci = { .set_subsystem = 0, }; @@ -150,8 +144,8 @@ struct device_operations default_pcix_ops_bus = { .read_resources = pci_bus_read_resources, .set_resources = pci_dev_set_resources, .enable_resources = pci_bus_enable_resources, - .init = 0, - .scan_bus = pcix_scan_bridge, + .init = 0, + .scan_bus = pcix_scan_bridge, .enable = 0, .reset_bus = pci_bus_reset, .ops_pci = &pcix_bus_ops_pci, diff --git a/device/pnp_device.c b/device/pnp_device.c index aaf720364b..6455117d4a 100644 --- a/device/pnp_device.c +++ b/device/pnp_device.c @@ -24,91 +24,88 @@ #include #include #include -//#include -//#include +// #include +// #include #include #include #include #include -/* PNP fundamental operations */ +/* PNP fundamental operations: */ -void pnp_write_config(struct device * dev, u8 reg, u8 value) +void pnp_write_config(struct device *dev, u8 reg, u8 value) { outb(reg, dev->path.u.pnp.port); outb(value, dev->path.u.pnp.port + 1); } -u8 pnp_read_config(struct device * dev, u8 reg) +u8 pnp_read_config(struct device *dev, u8 reg) { outb(reg, dev->path.u.pnp.port); return inb(dev->path.u.pnp.port + 1); } -void pnp_set_logical_device(struct device * dev) +void pnp_set_logical_device(struct device *dev) { pnp_write_config(dev, 0x07, dev->path.u.pnp.device); } -void pnp_set_enable(struct device * dev, int enable) +void pnp_set_enable(struct device *dev, int enable) { - pnp_write_config(dev, 0x30, enable?0x1:0x0); + pnp_write_config(dev, 0x30, enable ? 0x1 : 0x0); } -int pnp_read_enable(struct device * dev) +int pnp_read_enable(struct device *dev) { return !!pnp_read_config(dev, 0x30); } -void pnp_set_iobase(struct device * dev, unsigned index, unsigned iobase) +void pnp_set_iobase(struct device *dev, unsigned int index, unsigned int iobase) { /* Index == 0x60 or 0x62 */ pnp_write_config(dev, index + 0, (iobase >> 8) & 0xff); pnp_write_config(dev, index + 1, iobase & 0xff); } -void pnp_set_irq(struct device * dev, unsigned index, unsigned irq) +void pnp_set_irq(struct device *dev, unsigned int index, unsigned int irq) { /* Index == 0x70 or 0x72 */ pnp_write_config(dev, index, irq); } -void pnp_set_drq(struct device * dev, unsigned index, unsigned drq) +void pnp_set_drq(struct device *dev, unsigned int index, unsigned int drq) { /* Index == 0x74 */ pnp_write_config(dev, index, drq & 0xff); } -/* PNP device operations */ +/* PNP device operations: */ -void pnp_read_resources(struct device * dev) +void pnp_read_resources(struct device *dev) { return; } -static void pnp_set_resource(struct device * dev, struct resource *resource) +static void pnp_set_resource(struct device *dev, struct resource *resource) { if (!(resource->flags & IORESOURCE_ASSIGNED)) { - printk(BIOS_ERR, "ERROR: %s %02x %s size: 0x%010Lx not assigned\n", - dev_path(dev), resource->index, - resource_type(resource), - resource->size); + printk(BIOS_ERR, + "ERROR: %s %02x %s size: 0x%010Lx not assigned\n", + dev_path(dev), resource->index, resource_type(resource), + resource->size); return; } - /* Now store the resource */ + /* Now store the resource. */ if (resource->flags & IORESOURCE_IO) { pnp_set_iobase(dev, resource->index, resource->base); - } - else if (resource->flags & IORESOURCE_DRQ) { + } else if (resource->flags & IORESOURCE_DRQ) { pnp_set_drq(dev, resource->index, resource->base); - } - else if (resource->flags & IORESOURCE_IRQ) { + } else if (resource->flags & IORESOURCE_IRQ) { pnp_set_irq(dev, resource->index, resource->base); - } - else { + } else { printk(BIOS_ERR, "ERROR: %s %02x unknown resource type\n", - dev_path(dev), resource->index); + dev_path(dev), resource->index); return; } resource->flags |= IORESOURCE_STORED; @@ -116,26 +113,26 @@ static void pnp_set_resource(struct device * dev, struct resource *resource) report_resource_stored(dev, resource, ""); } -void pnp_set_resources(struct device * dev) +void pnp_set_resources(struct device *dev) { int i; - /* Select the device */ + /* Select the device. */ pnp_set_logical_device(dev); /* Paranoia says I should disable the device here... */ - for(i = 0; i < dev->resources; i++) { + for (i = 0; i < dev->resources; i++) { pnp_set_resource(dev, &dev->resource[i]); } } -void pnp_enable_resources(struct device * dev) +void pnp_enable_resources(struct device *dev) { pnp_set_logical_device(dev); pnp_set_enable(dev, 1); } -void pnp_enable(struct device * dev) +void pnp_enable(struct device *dev) { if (!dev->enabled) { pnp_set_logical_device(dev); @@ -147,37 +144,41 @@ struct device_operations pnp_ops = { .phase4_read_resources = pnp_read_resources, .phase4_set_resources = pnp_set_resources, .phase5_enable_resources = pnp_enable_resources, - //.enable = pnp_enable, + // .enable = pnp_enable, // FIXME }; -/* PNP chip operations */ +/* PNP chip operations: */ -static void pnp_get_ioresource(struct device * dev, unsigned index, struct io_info *info) +static void pnp_get_ioresource(struct device *dev, unsigned int index, + struct io_info *info) { struct resource *resource; - unsigned moving, gran, step; + unsigned int moving, gran, step; resource = new_resource(dev, index); - - /* Initilize the resource */ + + /* Initilize the resource. */ resource->limit = 0xffff; resource->flags |= IORESOURCE_IO; - - /* Get the resource size */ + + /* Get the resource size. */ moving = info->mask; gran = 15; step = 1 << gran; - /* Find the first bit that moves */ - while((moving & step) == 0) { + + /* Find the first bit that moves. */ + while ((moving & step) == 0) { gran--; step >>= 1; } - /* Now find the first bit that does not move */ - while((moving & step) != 0) { + + /* Now find the first bit that does not move. */ + while ((moving & step) != 0) { gran--; step >>= 1; } + /* Of the moving bits the last bit in the first group, * tells us the size of this resource. */ @@ -185,14 +186,15 @@ static void pnp_get_ioresource(struct device * dev, unsigned index, struct io_in gran++; step <<= 1; } - /* Set the resource size and alignment */ - resource->gran = gran; + + /* Set the resource size and alignment. */ + resource->gran = gran; resource->align = gran; resource->limit = info->mask | (step - 1); - resource->size = 1 << gran; + resource->size = 1 << gran; } -static void get_resources(struct device * dev, struct pnp_info *info) +static void get_resources(struct device *dev, struct pnp_info *info) { struct resource *resource; @@ -227,27 +229,27 @@ static void get_resources(struct device * dev, struct pnp_info *info) resource = new_resource(dev, PNP_IDX_DRQ1); resource->size = 1; resource->flags |= IORESOURCE_DRQ; - } -} + } +} -void pnp_enable_devices(struct device * base_dev, struct device_operations *ops, - unsigned functions, struct pnp_info *info) +void pnp_enable_devices(struct device *base_dev, struct device_operations *ops, + unsigned int functions, struct pnp_info *info) { struct device_path path; - struct device_id id = {.type = DEVICE_ID_PNP}; - struct device * dev; + struct device_id id = {.type = DEVICE_ID_PNP }; + struct device *dev; int i; - path.type = DEVICE_PATH_PNP; + path.type = DEVICE_PATH_PNP; path.u.pnp.port = base_dev->path.u.pnp.port; - - /* Setup the ops and resources on the newly allocated devices */ - for(i = 0; i < functions; i++) { + + /* Setup the ops and resources on the newly allocated devices. */ + for (i = 0; i < functions; i++) { path.u.pnp.device = info[i].function; dev = alloc_find_dev(base_dev->bus, &path, &id); - - /* Don't initialize a device multiple times */ - if (dev->ops) + + /* Don't initialize a device multiple times. */ + if (dev->ops) continue; if (info[i].ops == 0) { diff --git a/device/root_device.c b/device/root_device.c index 8749257870..0ac1562d20 100644 --- a/device/root_device.c +++ b/device/root_device.c @@ -25,61 +25,62 @@ #include #include #include -//#include +// #include /** * Read the resources for the root device, * that encompass the resources for the entire system. - * @param root Pointer to the device structure for the system root device + * + * @param root Pointer to the device structure for the system root device. */ -void root_dev_read_resources(struct device * root) +void root_dev_read_resources(struct device *root) { struct resource *resource; - /* Initialize the system wide io space constraints */ + /* Initialize the system wide I/O space constraints. */ resource = new_resource(root, 0); - resource->base = 0x400; - resource->size = 0; + resource->base = 0x400; + resource->size = 0; resource->align = 0; - resource->gran = 0; + resource->gran = 0; resource->limit = 0xffffUL; resource->flags = IORESOURCE_IO; - compute_allocate_resource(&root->link[0], resource, - IORESOURCE_IO, IORESOURCE_IO); + compute_allocate_resource(&root->link[0], resource, + IORESOURCE_IO, IORESOURCE_IO); - /* Initialize the system wide memory resources constraints */ + /* Initialize the system wide memory resources constraints. */ resource = new_resource(root, 1); - resource->base = 0; - resource->size = 0; + resource->base = 0; + resource->size = 0; resource->align = 0; - resource->gran = 0; + resource->gran = 0; resource->limit = 0xffffffffUL; resource->flags = IORESOURCE_MEM; compute_allocate_resource(&root->link[0], resource, - IORESOURCE_MEM, IORESOURCE_MEM); + IORESOURCE_MEM, IORESOURCE_MEM); } /** - * @brief Write the resources for every device - * * Write the resources for the root device, * and every device under it which are all of the devices. - * @param root Pointer to the device structure for the system root device + * + * @param root Pointer to the device structure for the system root device. */ -void root_dev_set_resources(struct device * root) +void root_dev_set_resources(struct device *root) { struct bus *bus; bus = &root->link[0]; compute_allocate_resource(bus, - &root->resource[0], IORESOURCE_IO, IORESOURCE_IO); - compute_allocate_resource(bus, - &root->resource[1], IORESOURCE_MEM, IORESOURCE_MEM); + &root->resource[0], IORESOURCE_IO, + IORESOURCE_IO); + compute_allocate_resource(bus, &root->resource[1], IORESOURCE_MEM, + IORESOURCE_MEM); phase4_assign_resources(bus); } /** - * @brief Scan devices on static buses. + * Scan devices on static buses. * * The enumeration of certain buses is purely static. The existence of * devices on those buses can be completely determined at compile time @@ -96,58 +97,65 @@ void root_dev_set_resources(struct device * root) * This function is the default scan_bus() method for the root device and * LPC bridges. * - * @param bus Pointer to the device structure which the static buses are attached - * @param max Maximum bus number currently used before scanning. + * @param busdevice Pointer to the device structure which the static + * buses are attached. + * @param max Maximum bus number currently used before scanning. * @return Largest bus number used. */ static int smbus_max = 0; -unsigned int scan_static_bus(struct device * busdevice, unsigned int max) +unsigned int scan_static_bus(struct device *busdevice, unsigned int max) { - struct device * child; - unsigned link; + struct device *child; + unsigned int link; - printk(BIOS_INFO, "%s for %s(%s)\n", __func__, busdevice->dtsname, dev_path(busdevice)); + printk(BIOS_INFO, "%s for %s(%s)\n", __func__, busdevice->dtsname, + dev_path(busdevice)); - for(link = 0; link < busdevice->links; link++) { - /* for smbus bus enumerate */ + for (link = 0; link < busdevice->links; link++) { + /* For smbus bus enumerate. */ child = busdevice->link[link].children; - if(child && child->path.type == DEVICE_PATH_I2C) { + if (child && child->path.type == DEVICE_PATH_I2C) { busdevice->link[link].secondary = ++smbus_max; } - for(child = busdevice->link[link].children; child; child = child->sibling) { + for (child = busdevice->link[link].children; child; + child = child->sibling) { if (child->ops && child->ops->phase3_enable_scan) { child->ops->phase3_enable_scan(child); } - /* sigh. Have to enable to scan ... */ + /* Sigh. Have to enable to scan... */ if (child->ops && child->ops->phase5_enable_resources) { child->ops->phase5_enable_resources(child); } - if (child->path.type == DEVICE_PATH_I2C) { - printk(BIOS_DEBUG, "smbus: %s(%s)[%d]->", - child->dtsname, dev_path(child->bus->dev), child->bus->link ); + if (child->path.type == DEVICE_PATH_I2C) { + printk(BIOS_DEBUG, "smbus: %s(%s)[%d]->", + child->dtsname, + dev_path(child->bus->dev), + child->bus->link); } printk(BIOS_DEBUG, "%s(%s) %s\n", - child->dtsname, dev_path(child), child->enabled?"enabled": "disabled"); + child->dtsname, dev_path(child), + child->enabled ? "enabled" : "disabled"); } } - for(link = 0; link < busdevice->links; link++) { - for(child = busdevice->link[link].children; child; child = child->sibling) { + for (link = 0; link < busdevice->links; link++) { + for (child = busdevice->link[link].children; child; + child = child->sibling) { if (!child->ops || !child->ops->phase3_scan) continue; - printk(BIOS_INFO, "%s(%s) scanning...\n", child->dtsname, dev_path(child)); + printk(BIOS_INFO, "%s(%s) scanning...\n", + child->dtsname, dev_path(child)); max = dev_phase3_scan(child, max); } } - printk(BIOS_INFO, "%s for %s(%s) done\n", __func__, busdevice->dtsname, dev_path(busdevice)); + printk(BIOS_INFO, "%s for %s(%s) done\n", __func__, busdevice->dtsname, + dev_path(busdevice)); return max; } /** - * @brief Enable resources for children devices - * - * @param dev the device whos children's resources are to be enabled + * Enable resources for children devices. * * This function is called by the global enable_resource() indirectly via the * device_operation::enable_resources() method of devices. @@ -156,65 +164,69 @@ unsigned int scan_static_bus(struct device * busdevice, unsigned int max) * enable_childrens_resources() -> enable_resources() * enable_resources() -> device_operation::enable_resources() * device_operation::enable_resources() -> enable_children_resources() + * + * @param dev The device whose children's resources are to be enabled. */ -void enable_childrens_resources(struct device * dev) +void enable_childrens_resources(struct device *dev) { - unsigned link; - for(link = 0; link < dev->links; link++) { - struct device * child; - for(child = dev->link[link].children; child; child = child->sibling) { + unsigned int link; + for (link = 0; link < dev->links; link++) { + struct device *child; + for (child = dev->link[link].children; child; + child = child->sibling) { dev_phase5(child); } } } -void root_dev_enable_resources(struct device * dev) +void root_dev_enable_resources(struct device *dev) { enable_childrens_resources(dev); } /** - * @brief Scan root bus for generic systems - * - * @param root The root device structure - * @param max The current bus number scanned so far, usually 0x00 + * Scan root bus for generic systems. * * This function is the default scan_bus() method of the root device. + * + * @param root The root device structure. + * @param max The current bus number scanned so far, usually 0x00. + * @return TODO */ -unsigned int root_dev_scan_bus(struct device * root, unsigned int max) +unsigned int root_dev_scan_bus(struct device *root, unsigned int max) { return scan_static_bus(root, max); } -void root_dev_init(struct device * root) +void root_dev_init(struct device *root) { } void root_dev_reset(struct bus *bus) { - printk(BIOS_INFO, "Reseting board... NOT! Define hard_reset please\n"); -// hard_reset(); + printk(BIOS_INFO, "Resetting board... NOT! Define hard_reset please\n"); + // hard_reset(); } /** - * @brief Default device operation for root device + * Default device operation for root device. * * This is the default device operation for root devices. These operations - * should be fully usable as is. If you need something else, set up your own ops - * in (e.g.) the mainboard, and initialize it in the dts in the mainboard directory. - * + * should be fully usable as is. If you need something else, set up your + * own ops in (e.g.) the mainboard, and initialize it in the dts in the + * mainboard directory. */ struct device_operations default_dev_ops_root = { .phase4_read_resources = root_dev_read_resources, .phase4_set_resources = root_dev_set_resources, .phase5_enable_resources = root_dev_enable_resources, .phase6_init = root_dev_init, - .phase3_scan = root_dev_scan_bus, - .reset_bus = root_dev_reset, + .phase3_scan = root_dev_scan_bus, + .reset_bus = root_dev_reset, }; /** - * @brief The root of device tree. + * The root of device tree. * * This is the root of the device tree. The device tree is defined in the * static.c file and is generated by config tool during compile time. diff --git a/device/smbus_ops.c b/device/smbus_ops.c index aff098f60a..5dfad0ea48 100644 --- a/device/smbus_ops.c +++ b/device/smbus_ops.c @@ -31,85 +31,99 @@ struct bus *get_pbus_smbus(device_t dev) while (pbus && pbus->dev && !ops_smbus_bus(pbus)) { pbus = pbus->dev->bus; } - if (!pbus || !pbus->dev || !pbus->dev->ops || !pbus->dev->ops->ops_smbus_bus) { - printk_alert("%s Cannot find smbus bus operations", dev_path(dev)); + if (!pbus || !pbus->dev || !pbus->dev->ops + || !pbus->dev->ops->ops_smbus_bus) { + printk_alert("%s Cannot find smbus bus operations", + dev_path(dev)); die(""); - for(;;); + for (;;) ; } return pbus; } -/*multi level i2c MUX??? may need to find the first i2c device and then set link - * down to current dev - 1 store get_pbus_smbus list link - 2 reverse the link and call set link */ - +/** + * Multi-level i2c MUX? May need to find the first i2c device and then + * set link down to current dev. + * 1 store get_pbus_smbus list link + * 2 reverse the link and call set link + */ int smbus_set_link(device_t dev) { - struct bus *pbus_a[4]; // 4 level mux only. Enough? - struct bus *pbus = dev->bus; - int pbus_num=0; + struct bus *pbus_a[4]; // 4 level mux only. Enough? + struct bus *pbus = dev->bus; + int pbus_num = 0; int i; - while(pbus && pbus->dev && (pbus->dev->path.type==DEVICE_PATH_I2C)) { + while (pbus && pbus->dev && (pbus->dev->path.type == DEVICE_PATH_I2C)) { pbus_a[pbus_num++] = pbus; - pbus = pbus->dev->bus; - } -// printk_info("smbus_set_link: "); - for (i=pbus_num-1; i>=0; i--) { -// printk_info(" %s[%d] -> ", dev_path(pbus_a[i]->dev), pbus_a[i]->link); - if (ops_smbus_bus(get_pbus_smbus(pbus_a[i]->dev))) { - if (pbus_a[i]->dev->ops && pbus_a[i]->dev->ops->set_link) - pbus_a[i]->dev->ops->set_link(pbus_a[i]->dev, pbus_a[i]->link); + pbus = pbus->dev->bus; + } +// printk_info("smbus_set_link: "); + for (i = pbus_num - 1; i >= 0; i--) { +// printk_info(" %s[%d] -> ", dev_path(pbus_a[i]->dev), pbus_a[i]->link); + if (ops_smbus_bus(get_pbus_smbus(pbus_a[i]->dev))) { + if (pbus_a[i]->dev->ops + && pbus_a[i]->dev->ops->set_link) + pbus_a[i]->dev->ops->set_link(pbus_a[i]->dev, + pbus_a[i]->link); } } -// printk_info(" %s\n", dev_path(dev)); +// printk_info(" %s\n", dev_path(dev)); - return pbus_num; + return pbus_num; } int smbus_quick_read(device_t dev) { return ops_smbus_bus(get_pbus_smbus(dev))->quick_read(dev); } + int smbus_quick_write(device_t dev) { return ops_smbus_bus(get_pbus_smbus(dev))->quick_write(dev); } + int smbus_recv_byte(device_t dev) { return ops_smbus_bus(get_pbus_smbus(dev))->recv_byte(dev); } + int smbus_send_byte(device_t dev, u8 byte) { return ops_smbus_bus(get_pbus_smbus(dev))->send_byte(dev, byte); } + int smbus_read_byte(device_t dev, u8 addr) { return ops_smbus_bus(get_pbus_smbus(dev))->read_byte(dev, addr); } + int smbus_write_byte(device_t dev, u8 addr, u8 val) { return ops_smbus_bus(get_pbus_smbus(dev))->write_byte(dev, addr, val); } + int smbus_read_word(device_t dev, u8 addr) { return ops_smbus_bus(get_pbus_smbus(dev))->read_word(dev, addr); } + int smbus_write_word(device_t dev, u8 addr, u16 val) { return ops_smbus_bus(get_pbus_smbus(dev))->write_word(dev, addr, val); } + int smbus_process_call(device_t dev, u8 cmd, u16 data) { return ops_smbus_bus(get_pbus_smbus(dev))->process_call(dev, cmd, data); } + int smbus_block_read(device_t dev, u8 cmd, u8 bytes, u8 *buffer) { - return ops_smbus_bus(get_pbus_smbus(dev))->block_read(dev, cmd, bytes, buffer); + return ops_smbus_bus(get_pbus_smbus(dev))->block_read(dev, cmd, bytes, + buffer); } int smbus_block_write(device_t dev, u8 cmd, u8 bytes, const u8 *buffer) { - return ops_smbus_bus(get_pbus_smbus(dev))->block_write(dev, cmd, bytes, buffer); + return ops_smbus_bus(get_pbus_smbus(dev))->block_write(dev, cmd, bytes, + buffer); } - -