summaryrefslogtreecommitdiff
path: root/src/devices
diff options
context:
space:
mode:
authorEric Biederman <ebiederm@xmission.com>2004-10-14 20:54:17 +0000
committerEric Biederman <ebiederm@xmission.com>2004-10-14 20:54:17 +0000
commitb78c1972feed4c57eebba8f94de86a91e32c3fa7 (patch)
tree2ba60cfe9866f4d1e2de1d9727d0e548139afb35 /src/devices
parentcadfd4c462673bcb44cdb1f193e52c95a888762a (diff)
- First pass through with with device tree enhancement merge. Most of the mechanisms should
be in place but don't expect anything to quite work yet. git-svn-id: svn://svn.coreboot.org/coreboot/trunk@1662 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
Diffstat (limited to 'src/devices')
-rw-r--r--src/devices/chip.c28
-rw-r--r--src/devices/device.c146
-rw-r--r--src/devices/device_util.c4
-rw-r--r--src/devices/pci_device.c285
-rw-r--r--src/devices/pnp_device.c49
-rw-r--r--src/devices/root_device.c59
6 files changed, 309 insertions, 262 deletions
diff --git a/src/devices/chip.c b/src/devices/chip.c
index 4c74949e46..8315fab674 100644
--- a/src/devices/chip.c
+++ b/src/devices/chip.c
@@ -69,7 +69,7 @@ void chip_enumerate(struct chip *chip)
printk_debug("Enumerating: %s\n", chip->control->name);
}
- for (i = 0; i < MAX_CHIP_PATHS; i++) {
+ for(i = 0; i < MAX_CHIP_PATHS; i++) {
int identical_paths;
identical_paths =
(i > 0) &&
@@ -90,7 +90,7 @@ void chip_enumerate(struct chip *chip)
device_t dev;
int i = 1;
dev = chip->dev;
- while (dev && (i != bus)) {
+ while(dev && (i != bus)) {
dev = dev->next;
i++;
}
@@ -103,21 +103,21 @@ void chip_enumerate(struct chip *chip)
dev = alloc_dev(parent, &chip->path[i].path);
break;
}
- } else {
+ }
+ else {
link += 1;
}
if (dev) {
struct chip_resource *res, *res_limit;
- printk_spew("path (%p) %s %s",
- dev, dev_path(dev),
- identical_paths?"identical":"");
+ printk_spew("path (%p) %s %s",
+ dev, dev_path(dev), identical_paths?"identical":"");
printk_spew(" parent: (%p) %s\n",
- dev->bus->dev, dev_path(dev->bus->dev));
+ dev->bus->dev, dev_path(dev->bus->dev));
dev->chip = chip;
dev->enabled = chip->path[i].enabled;
dev->links = link + 1;
- for (child = chip->children; child; child = child->next) {
+ for(child = chip->children; child; child = child->next) {
if (!child->bus && child->link == i) {
child->bus = &dev->link[link];
}
@@ -138,8 +138,10 @@ void chip_enumerate(struct chip *chip)
chip->dev = dev;
}
}
-
- for (child = chip->children; child; child = child->next) {
+ if (chip->children && !chip->dev) {
+ die("No device but children?");
+ }
+ for(child = chip->children; child; child = child->next) {
if (!child->bus) {
child->bus = &chip->dev->link[0];
}
@@ -167,8 +169,7 @@ void chip_enumerate(struct chip *chip)
static void enumerate_static_device_chain(struct chip *root)
{
struct chip *chip;
-
- for (chip = root; chip; chip = chip->next) {
+ for(chip = root; chip; chip = chip->next) {
void (*enumerate)(struct chip *chip);
enumerate = chip_enumerate;
if (chip->control && chip->control->enumerate) {
@@ -177,7 +178,7 @@ static void enumerate_static_device_chain(struct chip *root)
enumerate(chip);
}
- for (chip = root; chip; chip = chip->next) {
+ for(chip = root; chip; chip = chip->next) {
if (chip->children) {
enumerate_static_device_chain(chip->children);
}
@@ -208,5 +209,6 @@ static void enumerate_static_device_chain(struct chip *root)
void enumerate_static_devices(void)
{
printk_info("Enumerating static devices...\n");
+ static_root.dev = &dev_root;
enumerate_static_device_chain(&static_root);
}
diff --git a/src/devices/device.c b/src/devices/device.c
index 01aca4844f..4b7d8728fd 100644
--- a/src/devices/device.c
+++ b/src/devices/device.c
@@ -54,10 +54,9 @@ device_t alloc_dev(struct bus *parent, struct device_path *path)
int link;
/* Find the last child of our parent */
- for (child = parent->children; child && child->sibling; ) {
+ for(child = parent->children; child && child->sibling; ) {
child = child->sibling;
}
-
dev = malloc(sizeof(*dev));
if (dev == 0) {
die("DEV: out of memory.\n");
@@ -72,19 +71,18 @@ device_t alloc_dev(struct bus *parent, struct device_path *path)
last_dev_p = &dev->next;
/* Initialize the back pointers in the link fields */
- for (link = 0; link < MAX_LINKS; link++) {
+ for(link = 0; link < MAX_LINKS; link++) {
dev->link[link].dev = dev;
dev->link[link].link = link;
}
- /* Add the new device as a children of the bus. */
+ /* Add the new device to the list of children of the bus. */
dev->bus = parent;
if (child) {
child->sibling = dev;
} else {
parent->children = dev;
}
-
/* If we don't have any other information about a device enable it */
dev->enabled = 1;
@@ -125,7 +123,7 @@ static void read_resources(struct bus *bus)
struct device *curdev;
/* Walk through all of the devices and find which resources they need. */
- for (curdev = bus->children; curdev; curdev = curdev->sibling) {
+ for(curdev = bus->children; curdev; curdev = curdev->sibling) {
unsigned links;
int i;
if (curdev->resources > 0) {
@@ -133,22 +131,20 @@ static void read_resources(struct bus *bus)
}
if (!curdev->ops || !curdev->ops->read_resources) {
printk_err("%s missing read_resources\n",
- dev_path(curdev));
+ dev_path(curdev));
continue;
}
if (!curdev->enabled) {
continue;
}
-
curdev->ops->read_resources(curdev);
-
/* 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;
resource = &curdev->resource[i];
if ((resource->flags & IORESOURCE_SUBTRACTIVE) &&
- (!(links & (1 << resource->index))))
+ (!(links & (1 << resource->index))))
{
links |= (1 << resource->index);
read_resources(&curdev->link[resource->index]);
@@ -165,8 +161,8 @@ struct pick_largest_state {
int seen_last;
};
-static void pick_largest_resource(struct pick_largest_state *state,
- struct device *dev, struct resource *resource)
+static void pick_largest_resource(struct pick_largest_state *state,
+ struct device *dev, struct resource *resource)
{
struct resource *last;
last = state->last;
@@ -175,33 +171,31 @@ static void pick_largest_resource(struct pick_largest_state *state,
state->seen_last = 1;
return;
}
- 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 (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 void find_largest_resource(struct pick_largest_state *state,
- struct bus *bus, unsigned long type_mask,
- unsigned long type)
+ struct bus *bus, unsigned long type_mask, unsigned long type)
{
struct device *curdev;
-
- for (curdev = bus->children; curdev; curdev = curdev->sibling) {
+ for(curdev = bus->children; curdev; curdev = curdev->sibling) {
int i;
- for (i = 0; i < curdev->resources; i++) {
+ 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 ((resource->flags & type_mask) != type) {
@@ -211,8 +205,7 @@ static void find_largest_resource(struct pick_largest_state *state,
if (resource->flags & IORESOURCE_SUBTRACTIVE) {
struct bus *subbus;
subbus = &curdev->link[resource->index];
- find_largest_resource(state, subbus,
- type_mask, type);
+ find_largest_resource(state, subbus, type_mask, type);
continue;
}
/* See if this is the largest resource */
@@ -281,12 +274,12 @@ void compute_allocate_resource(
min_align = 0;
base = bridge->base;
- printk_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_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
@@ -305,9 +298,10 @@ void compute_allocate_resource(
/* Remember I 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))) {
+ /* Walk through all the devices on the current bus and
+ * compute the addresses.
+ */
+ while((dev = largest_resource(bus, &resource, type_mask, type))) {
unsigned long 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
@@ -355,12 +349,13 @@ void compute_allocate_resource(
resource->flags &= ~IORESOURCE_STORED;
base += size;
- printk_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_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
@@ -372,10 +367,10 @@ void compute_allocate_resource(
bridge->size = round(base, 1UL << bridge->gran) - bridge->base;
printk_spew("%s compute_allocate_%s: base: %08lx size: %08lx align: %d gran: %d done\n",
- dev_path(dev),
- (bridge->flags & IORESOURCE_IO)? "io":
- (bridge->flags & IORESOURCE_PREFETCH)? "prefmem" : "mem",
- base, bridge->size, bridge->align, bridge->gran);
+ dev_path(dev),
+ (bridge->flags & IORESOURCE_IO)? "io":
+ (bridge->flags & IORESOURCE_PREFETCH)? "prefmem" : "mem",
+ base, bridge->size, bridge->align, bridge->gran);
}
@@ -386,14 +381,16 @@ static void allocate_vga_resource(void)
#warning "This function knows to much about PCI stuff, it should be just a ietrator/visitor."
/* FIXME handle the VGA pallette snooping */
- struct device *dev, *vga = 0;
- struct bus *bus = 0;
-
- for (dev = all_devices; dev; dev = dev->next) {
+ struct device *dev, *vga;
+ struct bus *bus;
+ bus = 0;
+ vga = 0;
+ for(dev = all_devices; dev; dev = dev->next) {
if (((dev->class >> 16) == PCI_BASE_CLASS_DISPLAY) &&
((dev->class >> 8) != PCI_CLASS_DISPLAY_OTHER)) {
if (!vga) {
- printk_debug("Allocating VGA resource %s\n", dev_path(dev));
+ printk_debug("Allocating VGA resource %s\n",
+ dev_path(dev));
vga = dev;
}
if (vga == dev) {
@@ -408,9 +405,8 @@ static void allocate_vga_resource(void)
if (vga) {
bus = vga->bus;
}
-
/* Now walk up the bridges setting the VGA enable */
- while (bus) {
+ while(bus) {
bus->bridge_ctrl |= PCI_BRIDGE_CTL_VGA;
bus = (bus == bus->dev->bus)? 0 : bus->dev->bus;
}
@@ -432,7 +428,7 @@ void assign_resources(struct bus *bus)
for (curdev = bus->children; curdev; curdev = curdev->sibling) {
if (!curdev->ops || !curdev->ops->set_resources) {
printk_err("%s missing set_resources\n",
- dev_path(curdev));
+ dev_path(curdev));
continue;
}
if (!curdev->enabled) {
@@ -474,25 +470,26 @@ void enable_resources(struct device *dev)
* @brief Determine the existence of dynamic devices and construct dynamic
* device tree.
*
- * Start form the root device 'dev_root', scan the buses in the system
+ * Start from the root device 'dev_root', scan the buses in the system
* recursively, build the dynamic device tree according to the result
* of the probe.
*
* This function has no idea how to scan and probe buses and devices at all.
* It depends on the bus/device specific scan_bus() method to do it. The
- * scan_bus() function also have to create the device structure and attach
+ * scan_bus() function also has to create the device structure and attach
* it to the device tree.
*/
void dev_enumerate(void)
{
struct device *root;
unsigned subordinate;
-
printk_info("Enumerating buses...\n");
-
root = &dev_root;
+ if (!root->ops || !root->ops->scan_bus) {
+ printk_err("dev_root missing scan_bus operation");
+ return;
+ }
subordinate = root->ops->scan_bus(root, 0);
-
printk_info("done\n");
}
@@ -510,29 +507,38 @@ void dev_enumerate(void)
*/
void dev_configure(void)
{
- struct device *root = &dev_root;
+ struct device *root;
printk_info("Allocating resources...\n");
+ root = &dev_root;
+ if (!root->ops || !root->ops->read_resources) {
+ printk_err("dev_root missing read_resources\n");
+ return;
+ }
+ if (!root->ops || !root->ops->set_resources) {
+ printk_err("dev_root missing set_resources\n");
+ return;
+ }
root->ops->read_resources(root);
/* Make certain the io devices are allocated somewhere safe. */
root->resource[0].base = DEVICE_IO_START;
root->resource[0].flags |= IORESOURCE_ASSIGNED;
root->resource[0].flags &= ~IORESOURCE_STORED;
-
- /* Now reallocate the pci resources memory with the highest
- * addresses I can manage.*/
+ /* Now reallocate the pci resources memory with the
+ * highest addresses I can manage.
+ */
root->resource[1].base =
round_down(DEVICE_MEM_HIGH - root->resource[1].size,
- 1UL << root->resource[1].align);
+ 1UL << root->resource[1].align);
root->resource[1].flags |= IORESOURCE_ASSIGNED;
root->resource[1].flags &= ~IORESOURCE_STORED;
/* Allocate the VGA I/O resource.. */
allocate_vga_resource();
- /* now just set things into registers ... we hope ... */
+ /* Store the computed resource allocations into device registers ... */
root->ops->set_resources(root);
printk_info("done.\n");
@@ -565,13 +571,11 @@ void dev_initialize(void)
struct device *dev;
printk_info("Initializing devices...\n");
-
for (dev = all_devices; dev; dev = dev->next) {
if (dev->enabled && dev->ops && dev->ops->init) {
printk_debug("%s init\n", dev_path(dev));
dev->ops->init(dev);
}
}
-
printk_info("Devices initialized\n");
}
diff --git a/src/devices/device_util.c b/src/devices/device_util.c
index 93a8a5cd96..f5f8bb4482 100644
--- a/src/devices/device_util.c
+++ b/src/devices/device_util.c
@@ -15,7 +15,7 @@
device_t alloc_find_dev(struct bus *parent, struct device_path *path)
{
device_t child;
- for (child = parent->children; child; child = child->sibling) {
+ for(child = parent->children; child; child = child->sibling) {
if (path_eq(path, &child->path)) {
return child;
}
@@ -184,7 +184,7 @@ struct resource *get_resource(device_t dev, unsigned 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;
diff --git a/src/devices/pci_device.c b/src/devices/pci_device.c
index f87a590d0e..6f7fabf67b 100644
--- a/src/devices/pci_device.c
+++ b/src/devices/pci_device.c
@@ -151,7 +151,7 @@ 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;
@@ -173,7 +173,7 @@ static void pci_bridge_read_bases(struct device *dev)
resource->limit = 0xffffUL;
resource->flags |= IORESOURCE_IO | IORESOURCE_PCI_BRIDGE;
compute_allocate_resource(&dev->link[0], resource,
- IORESOURCE_IO, IORESOURCE_IO);
+ IORESOURCE_IO, IORESOURCE_IO);
/* Initiliaze the prefetchable memory constraints on the current bus */
resource = get_resource(dev, PCI_PREF_MEMORY_BASE);
@@ -184,8 +184,8 @@ static void pci_bridge_read_bases(struct device *dev)
resource->flags = IORESOURCE_MEM | IORESOURCE_PREFETCH | IORESOURCE_PCI_BRIDGE;
resource->index = PCI_PREF_MEMORY_BASE;
compute_allocate_resource(&dev->link[0], resource,
- IORESOURCE_MEM | IORESOURCE_PREFETCH,
- IORESOURCE_MEM | IORESOURCE_PREFETCH);
+ IORESOURCE_MEM | IORESOURCE_PREFETCH,
+ IORESOURCE_MEM | IORESOURCE_PREFETCH);
/* Initialize the memory resources on the current bus */
resource = get_resource(dev, PCI_MEMORY_BASE);
@@ -195,8 +195,8 @@ static void pci_bridge_read_bases(struct device *dev)
resource->limit = 0xffffffffUL;
resource->flags = IORESOURCE_MEM | IORESOURCE_PCI_BRIDGE;
compute_allocate_resource(&dev->link[0], resource,
- IORESOURCE_MEM | IORESOURCE_PREFETCH,
- IORESOURCE_MEM);
+ IORESOURCE_MEM | IORESOURCE_PREFETCH,
+ IORESOURCE_MEM);
compact_resources(dev);
}
@@ -223,18 +223,18 @@ void pci_bus_read_resources(struct device *dev)
}
/**
- * @brief round a number up to an alignment.
+ * @brief round a number up to the next multiple of gran
* @param val the starting value
- * @param roundup Alignment as a power of two
- * @returns rounded up number
+ * @param gran granularity we are aligning the number to.
+ * @returns aligned value
*/
-static unsigned long round(unsigned long val, unsigned long roundup)
+static unsigned long align(unsigned long val, unsigned long gran)
{
- /* ROUNDUP MUST BE A POWER OF TWO. */
- unsigned long inverse;
- inverse = ~(roundup - 1);
- val += (roundup - 1);
- val &= inverse;
+ /* GRAN MUST BE A POWER OF TWO. */
+ unsigned long mask;
+ mask = ~(gran - 1);
+ val += (gran - 1);
+ val &= mask;
return val;
}
@@ -245,10 +245,9 @@ static void pci_set_resource(struct device *dev, struct resource *resource)
unsigned long gran;
/* Make certain the resource has actually been set */
-
if (!(resource->flags & IORESOURCE_ASSIGNED)) {
printk_err("ERROR: %s %02x not allocated\n",
- dev_path(dev), resource->index);
+ dev_path(dev), resource->index);
return;
}
@@ -270,10 +269,8 @@ static void pci_set_resource(struct device *dev, struct resource *resource)
if (resource->flags & IORESOURCE_PCI_BRIDGE) {
dev->command |= PCI_COMMAND_MASTER;
}
-
/* Get the base address */
base = resource->base;
-
/* Get the resource granularity */
gran = 1UL << resource->gran;
@@ -284,13 +281,15 @@ static void pci_set_resource(struct device *dev, struct resource *resource)
*/
/* Get the limit (rounded up) */
- limit = base + round(resource->size, gran) - 1UL;
+ limit = base + align(resource->size, gran) - 1UL;
/* Now store the resource */
resource->flags |= IORESOURCE_STORED;
if (!(resource->flags & IORESOURCE_PCI_BRIDGE)) {
- /* 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 IO bit.
+ * (e.g. VIA 82c686a.) So set it to be safe)
+ */
limit = base + resource->size -1;
if (resource->flags & IORESOURCE_IO) {
base |= PCI_BASE_ADDRESS_SPACE_IO;
@@ -300,50 +299,58 @@ static void pci_set_resource(struct device *dev, struct resource *resource)
/* FIXME handle real 64bit base addresses */
pci_write_config32(dev, resource->index + 4, 0);
}
- } else if (resource->index == PCI_IO_BASE) {
+ }
+ else if (resource->index == PCI_IO_BASE) {
/* set the IO ranges
* WARNING: we don't really do 32-bit addressing for IO yet!
*/
compute_allocate_resource(&dev->link[0], resource,
- IORESOURCE_IO, IORESOURCE_IO);
+ IORESOURCE_IO, IORESOURCE_IO);
pci_write_config8(dev, PCI_IO_BASE, base >> 8);
pci_write_config8(dev, PCI_IO_LIMIT, limit >> 8);
pci_write_config16(dev, PCI_IO_BASE_UPPER16, 0);
pci_write_config16(dev, PCI_IO_LIMIT_UPPER16, 0);
- } else if (resource->index == PCI_MEMORY_BASE) {
- /* set the memory range */
+ }
+ else if (resource->index == PCI_MEMORY_BASE) {
+ /* set the memory range
+ */
compute_allocate_resource(&dev->link[0], resource,
- IORESOURCE_MEM | IORESOURCE_PREFETCH,
- IORESOURCE_MEM);
+ IORESOURCE_MEM | IORESOURCE_PREFETCH,
+ IORESOURCE_MEM);
pci_write_config16(dev, PCI_MEMORY_BASE, base >> 16);
pci_write_config16(dev, PCI_MEMORY_LIMIT, limit >> 16);
- } else if (resource->index == PCI_PREF_MEMORY_BASE) {
+ }
+ else if (resource->index == PCI_PREF_MEMORY_BASE) {
/* set the prefetchable memory range
- * WARNING: we don't really do 64-bit addressing for
- * prefetchable memory yet! */
+ * WARNING: we don't really do 64-bit addressing
+ * for prefetchable memory yet!
+ */
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_config16(dev, PCI_PREF_MEMORY_LIMIT, limit >> 16);
pci_write_config32(dev, PCI_PREF_BASE_UPPER32, 0);
pci_write_config32(dev, PCI_PREF_LIMIT_UPPER32, 0);
- } else {
+ }
+ else {
/* Don't let me think I stored the resource */
resource->flags &= ~IORESOURCE_STORED;
printk_err("ERROR: invalid resource->index %x\n",
- resource->index);
+ resource->index);
}
-
buf[0] = '\0';
if (resource->flags & IORESOURCE_PCI_BRIDGE) {
sprintf(buf, "bus %d ", dev->link[0].secondary);
}
- printk_debug("%s %02x <- [0x%08lx - 0x%08lx] %s%s\n",
- dev_path(dev), resource->index, resource->base,
- limit, buf,
- (resource->flags & IORESOURCE_IO)? "io":
- (resource->flags & IORESOURCE_PREFETCH)? "prefmem": "mem");
+ printk_debug(
+ "%s %02x <- [0x%08lx - 0x%08lx] %s%s\n",
+ dev_path(dev),
+ resource->index,
+ (unsigned long)(resource->base), limit,
+ buf,
+ (resource->flags & IORESOURCE_IO)? "io":
+ (resource->flags & IORESOURCE_PREFETCH)? "prefmem": "mem");
return;
}
@@ -354,11 +361,11 @@ void pci_dev_set_resources(struct device *dev)
uint8_t 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) {
@@ -442,16 +449,17 @@ static void set_pci_ops(struct device *dev)
}
/* Look through the list of setup drivers and find one for
- * this pci device */
- for (driver = &pci_drivers[0]; driver != &epci_drivers[0]; driver++) {
+ * this pci device
+ */
+ for(driver = &pci_drivers[0]; driver != &epci_drivers[0]; driver++) {
if ((driver->vendor == dev->vendor) &&
- (driver->device == dev->device)) {
+ (driver->device == dev->device))
+ {
dev->ops = driver->ops;
-
- printk_debug("%s [%04x/%04x] %sops\n", dev_path(dev),
- driver->vendor, driver->device,
- (driver->ops->scan_bus?"bus ":""));
-
+ printk_debug("%s [%04x/%04x] %sops\n",
+ dev_path(dev),
+ driver->vendor, driver->device,
+ (driver->ops->scan_bus?"bus ":""));
return;
}
}
@@ -483,10 +491,10 @@ static void set_pci_ops(struct device *dev)
bad:
if (dev->enabled) {
printk_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);
+ "type %02x, ignoring.\n",
+ dev_path(dev),
+ dev->vendor, dev->device,
+ dev->class >> 8, dev->hdr_type);
}
}
return;
@@ -496,24 +504,25 @@ static void set_pci_ops(struct device *dev)
* @brief Find a specific device structure on a list of device structures
*
* Given a linked list of PCI device structures and a devfn number, find the
- * device structure correspond to the devfn.
+ * device structure correspond to the devfn, if present.
*
* @param list the device structure list
* @param devfn a device/function number
*
- * @return pointer to the device structure found
+ * @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)
+static struct device *pci_scan_get_dev(struct device **list, unsigned int devfn)
{
- struct device *dev = 0;
+ struct device *dev;
- printk_debug("%s, looking for devfn: %02x.%01x\n", __FUNCTION__,
- devfn >> 3, devfn & 7);
- for (; *list; list = &(*list)->sibling) {
+ printk_spew("%s, looking for devfn: %02x.%01x\n", __FUNCTION__,
+ devfn >> 3, devfn & 7);
+ dev = 0;
+ for(; *list; list = &(*list)->sibling) {
if ((*list)->path.type != DEVICE_PATH_PCI) {
printk_err("child %s not a pci device\n",
- dev_path(*list));
+ dev_path(*list));
continue;
}
if ((*list)->path.u.pci.devfn == devfn) {
@@ -524,15 +533,16 @@ static struct device *pci_scan_get_dev(struct device **list,
break;
}
}
-
- printk_debug("%s, found dev %08x\n", __FUNCTION__, dev);
-
- /* FIXME: why are we doing this ? Isn't there some order between the
- * structures before ? */
+ /* 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.
+ */
+ printk_spew("%s, found dev %08x\n", __FUNCTION__, dev);
if (dev) {
device_t child;
/* Find the last child of our parent */
- for (child = dev->bus->children; child && child->sibling; ) {
+ for(child = dev->bus->children; child && child->sibling; ) {
child = child->sibling;
}
/* Place the device on the list of children of it's parent. */
@@ -546,8 +556,8 @@ static struct device *pci_scan_get_dev(struct device **list,
return dev;
}
-/**
- * @brief Scan a PCI bus
+/**
+ * @brief 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.
@@ -562,8 +572,9 @@ static struct device *pci_scan_get_dev(struct device **list,
*
* @return The maximum bus number found, after scanning all subordinate busses
*/
-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 min_devfn, unsigned max_devfn,
+ unsigned int max)
{
unsigned int devfn;
device_t dev;
@@ -578,7 +589,8 @@ unsigned int pci_scan_bus(struct bus *bus, unsigned min_devfn,
post_code(0x24);
/* probe all devices/functions on this bus with some optimization for
- * non-existence and single funcion devices */
+ * non-existence and single funcion devices
+ */
for (devfn = min_devfn; devfn <= max_devfn; devfn++) {
uint32_t id, class;
uint8_t hdr_type;
@@ -597,31 +609,39 @@ unsigned int pci_scan_bus(struct bus *bus, unsigned min_devfn,
dummy.path.u.pci.devfn = devfn;
id = pci_read_config32(&dummy, PCI_VENDOR_ID);
/* some broken boards return 0 if a slot is empty: */
- if ((id == 0xffffffff) || (id == 0x00000000) ||
- (id == 0x0000ffff) || (id == 0xffff0000)) {
- printk_spew("PCI: devfn 0x%x, bad id 0x%x\n",
- devfn, id);
+ if ( (id == 0xffffffff) || (id == 0x00000000) ||
+ (id == 0x0000ffff) || (id == 0xffff0000))
+ {
+ printk_spew("PCI: devfn 0x%x, bad id 0x%x\n", devfn, id);
if (PCI_FUNC(devfn) == 0x00) {
- /* if this is a function 0 device and
- * it is not present, skip to next
- * device */
+ /* if this is a function 0 device and
+ * it is not present,
+ * skip to next device
+ */
devfn += 0x07;
}
- /* this function in a multi function device is
- * not present, skip to next function */
+ /* This function in a multi function device is
+ * not present, skip to the next function.
+ */
continue;
}
dev = alloc_dev(bus, &dummy.path);
- } else {
- /* Run the magic enable/disable sequence for the
- * device */
- /* FIXME: What happen if this PCI device listed as
- * static device but does not exist ? This calls
- * some arbitray code without any justification
- * Also, it calls the enable function regardlessly
- * the value of dev->enabled */
- if (dev->chip && dev->chip->control &&
- dev->chip->control->enable_dev) {
+ }
+ else {
+ /* If at all possible enable the device, if desired
+ * we will disable the device later, once we have
+ * found it's device specific operations.
+ *
+ * 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.
+ *
+ */
+ if ( dev->chip && dev->chip->control &&
+ dev->chip->control->enable_dev)
+ {
int enabled = dev->enabled;
dev->enabled = 1;
dev->chip->control->enable_dev(dev);
@@ -650,15 +670,17 @@ unsigned int pci_scan_bus(struct bus *bus, unsigned min_devfn,
/* Error if we don't have some pci operations for it */
if (!dev->ops) {
printk_err("%s No device operations\n",
- dev_path(dev));
+ dev_path(dev));
continue;
}
/* Now run the magic enable/disable sequence for the device */
if (dev->ops && dev->ops->enable) {
dev->ops->enable(dev);
- } else if (dev->chip && dev->chip->control &&
- dev->chip->control->enable_dev) {
+ }
+ else if (dev->chip && dev->chip->control &&
+ dev->chip->control->enable_dev)
+ {
dev->chip->control->enable_dev(dev);
}
@@ -668,22 +690,23 @@ unsigned int pci_scan_bus(struct bus *bus, unsigned min_devfn,
dev->enabled?"enabled": "disabled");
if (PCI_FUNC(devfn) == 0x00 && (hdr_type & 0x80) != 0x80) {
- /* if this is not a multi function device, don't
- * waste time probe another function.
- * Skip to next device. */
+ /* if this is not a multi function device,
+ * don't waste time probing another function.
+ * Skip to next device.
+ */
devfn += 0x07;
}
}
post_code(0x25);
- /* if a child provides scan_bus(), for example a bridge, scan
- * buses behind that child */
- for (child = bus->children; child; child = child->sibling) {
- // make sure that we have an ops structure
- if (!child->ops) {
- continue;
- }
- if (!child->ops->scan_bus) {
+ /* For all children that implement scan_bus (i.e. bridges)
+ * scan the bus behind that child.
+ */
+ for(child = bus->children; child; child = child->sibling) {
+ if (!child->enabled ||
+ !child->ops ||
+ !child->ops->scan_bus)
+ {
continue;
}
max = child->ops->scan_bus(child, max);
@@ -725,7 +748,8 @@ unsigned int pci_scan_bridge(struct device *dev, unsigned int max)
/* Set up the primary, secondary and subordinate bus numbers. We have
* no idea how many buses are behind this bridge yet, so we set the
- * subordinate bus number to 0xff for the moment. */
+ * subordinate bus number to 0xff for the moment.
+ */
bus->secondary = ++max;
bus->subordinate = 0xff;
@@ -734,32 +758,37 @@ unsigned int 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
- * number configuration. */
+ /*
+ * Read the existing primary/secondary/subordinate bus
+ * number configuration.
+ */
buses = pci_read_config32(dev, PCI_PRIMARY_BUS);
/* Configure the bus numbers for this bridge: the configuration
* transactions will not be propagated by the bridge if it is not
- * correctly configured */
+ * correctly configured.
+ */
buses &= 0xff000000;
buses |= (((unsigned int) (dev->bus->secondary) << 0) |
- ((unsigned int) (bus->secondary) << 8) |
- ((unsigned int) (bus->subordinate) << 16));
+ ((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 i.e. the buses behind the
- * bridge */
+
+ /* Now we can scan all subordinate buses
+ * i.e. the bus behind the bridge.
+ */
max = pci_scan_bus(bus, 0x00, 0xff, max);
-
+
/* We know the number of buses behind this bridge. Set the subordinate
- * bus number to its real value */
+ * bus number to its real value.
+ */
bus->subordinate = max;
buses = (buses & 0xff00ffff) |
((unsigned int) (bus->subordinate) << 16);
pci_write_config32(dev, PCI_PRIMARY_BUS, buses);
pci_write_config16(dev, PCI_COMMAND, cr);
-
- printk_spew("%s returns max %d\n", __FUNCTION__, max);
+
+ printk_spew("%s returns max %d\n", __func__, max);
return max;
}
@@ -771,10 +800,18 @@ static void pci_level_irq(unsigned char intNum)
{
unsigned short intBits = inb(0x4d0) | (((unsigned) inb(0x4d1)) << 8);
+<<<<<<< pci_device.c
+ printk_spew("%s: current ints are 0x%x\n", __func__, intBits);
+=======
printk_debug("%s: current ints are 0x%x\n", __FUNCTION__, intBits);
+>>>>>>> 1.25
intBits |= (1 << intNum);
+<<<<<<< pci_device.c
+ printk_spew("%s: try to set ints 0x%x\n", __func__, intBits);
+=======
printk_debug("%s: try to set ints 0x%x\n", __FUNCTION__, intBits);
+>>>>>>> 1.25
// Write new values
outb((unsigned char) intBits, 0x4d0);
@@ -784,11 +821,11 @@ static void pci_level_irq(unsigned char intNum)
#if 1
if (inb(0x4d0) != (intBits & 0xf)) {
printk_err("%s: lower order bits are wrong: want 0x%x, got 0x%x\n",
- __FUNCTION__, intBits &0xf, inb(0x4d0));
+ __func__, intBits &0xf, inb(0x4d0));
}
if (inb(0x4d1) != ((intBits >> 8) & 0xf)) {
printk_err("%s: lower order bits are wrong: want 0x%x, got 0x%x\n",
- __FUNCTION__, (intBits>>8) &0xf, inb(0x4d1));
+ __func__, (intBits>>8) &0xf, inb(0x4d1));
}
#endif
}
diff --git a/src/devices/pnp_device.c b/src/devices/pnp_device.c
index 5f4ede1ec4..4bdb67e4aa 100644
--- a/src/devices/pnp_device.c
+++ b/src/devices/pnp_device.c
@@ -76,25 +76,30 @@ static void pnp_set_resource(device_t dev, struct resource *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_err("ERROR: %s %02x unknown resource type\n",
- dev_path(dev), resource->index);
+ dev_path(dev), resource->index);
return;
}
resource->flags |= IORESOURCE_STORED;
- printk_debug("%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_DRQ)? "drq":
- (resource->flags & IORESOURCE_IRQ)? "irq":
- (resource->flags & IORESOURCE_MEM)? "mem":
- "???");
+ printk_debug(
+ "%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_DRQ)? "drq":
+ (resource->flags & IORESOURCE_IRQ)? "irq":
+ (resource->flags & IORESOURCE_MEM)? "mem":
+ "???");
}
void pnp_set_resources(device_t dev)
@@ -105,7 +110,7 @@ void pnp_set_resources(device_t dev)
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]);
}
}
@@ -133,8 +138,7 @@ struct device_operations pnp_ops = {
/* PNP chip opertations */
-static void pnp_get_ioresource(device_t dev, unsigned index,
- struct io_info *info)
+static void pnp_get_ioresource(device_t dev, unsigned index, struct io_info *info)
{
struct resource *resource;
uint32_t size;
@@ -156,14 +160,18 @@ static void get_resources(device_t dev, struct pnp_info *info)
{
struct resource *resource;
-// pnp_set_logical_device(dev); // coment out by LYH
-
if (info->flags & PNP_IO0) {
pnp_get_ioresource(dev, PNP_IDX_IO0, &info->io0);
}
if (info->flags & PNP_IO1) {
pnp_get_ioresource(dev, PNP_IDX_IO1, &info->io1);
}
+ if (info->flags & PNP_IO2) {
+ pnp_get_ioresource(dev, PNP_IDX_IO2, &info->io2);
+ }
+ if (info->flags & PNP_IO3) {
+ pnp_get_ioresource(dev, PNP_IDX_IO3, &info->io3);
+ }
if (info->flags & PNP_IRQ0) {
resource = get_resource(dev, PNP_IDX_IRQ0);
resource->size = 1;
@@ -187,7 +195,7 @@ static void get_resources(device_t dev, struct pnp_info *info)
}
void pnp_enumerate(struct chip *chip, unsigned functions,
- struct device_operations *ops, struct pnp_info *info)
+ struct device_operations *ops, struct pnp_info *info)
{
struct device_path path;
device_t dev;
@@ -199,14 +207,13 @@ void pnp_enumerate(struct chip *chip, unsigned functions,
path.u.pnp.port = chip->dev->path.u.pnp.port;
/* Setup the ops and resources on the newly allocated devices */
- for (i = 0; i < functions; i++) {
+ for(i = 0; i < functions; i++) {
path.u.pnp.device = info[i].function;
-
dev = alloc_find_dev(chip->bus, &path);
if (info[i].ops == 0) {
dev->ops = ops;
- } else {
+ } else {
dev->ops = info[i].ops;
}
get_resources(dev, &info[i]);
diff --git a/src/devices/root_device.c b/src/devices/root_device.c
index 10cebbaf38..04c96770fe 100644
--- a/src/devices/root_device.c
+++ b/src/devices/root_device.c
@@ -11,7 +11,6 @@ void root_dev_read_resources(device_t root)
{
int res = 0;
- printk_spew("%s . Root is %p\n", __FUNCTION__, dev_path(root));
/* Initialize the system wide io space constraints */
root->resource[res].base = 0x400;
root->resource[res].size = 0;
@@ -20,10 +19,8 @@ void root_dev_read_resources(device_t root)
root->resource[res].limit = 0xffffUL;
root->resource[res].flags = IORESOURCE_IO;
root->resource[res].index = 0;
- printk_spew("%s . link %p, resource %p\n", __FUNCTION__,
- &root->link[0], &root->resource[res]);
compute_allocate_resource(&root->link[0], &root->resource[res],
- IORESOURCE_IO, IORESOURCE_IO);
+ IORESOURCE_IO, IORESOURCE_IO);
res++;
/* Initialize the system wide memory resources constraints */
@@ -34,14 +31,12 @@ void root_dev_read_resources(device_t root)
root->resource[res].limit = 0xffffffffUL;
root->resource[res].flags = IORESOURCE_MEM;
root->resource[res].index = 1;
- printk_spew("%s . link %p, resource %p\n", __FUNCTION__,
- &root->link[0], &root->resource[res]);
compute_allocate_resource(&root->link[0], &root->resource[res],
- IORESOURCE_MEM, IORESOURCE_MEM);
+ IORESOURCE_MEM, IORESOURCE_MEM);
res++;
root->resources = res;
- printk_spew("%s DONE\n", __FUNCTION__);
+ printk_spew("%s DONE\n", __func__);
}
/**
@@ -51,12 +46,13 @@ void root_dev_read_resources(device_t root)
*/
void root_dev_set_resources(device_t root)
{
- struct bus *bus = &root->link[0];
+ struct bus *bus;
- compute_allocate_resource(bus, &root->resource[0],
- IORESOURCE_IO, IORESOURCE_IO);
- compute_allocate_resource(bus, &root->resource[1],
- IORESOURCE_MEM, IORESOURCE_MEM);
+ 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);
assign_resources(bus);
}
@@ -80,20 +76,21 @@ unsigned int scan_static_bus(device_t bus, unsigned int max)
{
device_t child;
unsigned link;
+
+ printk_debug("%s for %s\n", __func__, dev_path(bus));
- printk_debug("%s for %s\n", __FUNCTION__, dev_path(bus));
-
- for (link = 0; link < bus->links; link++) {
- for (child = bus->link[link].children; child; child = child->sibling) {
+ for(link = 0; link < bus->links; link++) {
+ for(child = bus->link[link].children; child; child = child->sibling) {
if (child->ops && child->ops->enable) {
child->ops->enable(child);
}
- printk_debug("%s %s\n", dev_path(child),
- child->enabled?"enabled": "disabled");
+ printk_debug("%s %s\n",
+ dev_path(child),
+ child->enabled?"enabled": "disabled");
}
}
- for (link = 0; link < bus->links; link++) {
- for (child = bus->link[link].children; child; child = child->sibling) {
+ for(link = 0; link < bus->links; link++) {
+ for(child = bus->link[link].children; child; child = child->sibling) {
if (!child->ops || !child->ops->scan_bus)
continue;
printk_debug("%s scanning...\n", dev_path(child));
@@ -101,7 +98,7 @@ unsigned int scan_static_bus(device_t bus, unsigned int max)
}
}
- printk_debug("%s done\n", __FUNCTION__);
+ printk_debug("%s done\n", __func__);
return max;
}
@@ -119,9 +116,9 @@ unsigned int scan_static_bus(device_t bus, unsigned int max)
void enable_childrens_resources(device_t dev)
{
unsigned link;
- for (link = 0; link < dev->links; link++) {
+ for(link = 0; link < dev->links; link++) {
device_t child;
- for (child = dev->link[link].children; child; child = child->sibling) {
+ for(child = dev->link[link].children; child; child = child->sibling) {
enable_resources(child);
}
}
@@ -172,11 +169,11 @@ struct device dev_root = {
.bus = &dev_root.link[0],
.path = { .type = DEVICE_PATH_ROOT },
.enabled = 1,
- .links = 1,
- .link = {
- [0] = {
- .dev = &dev_root,
- .link = 0,
- },
- },
+ .links = 1,
+ .link = {
+ [0] = {
+ .dev = &dev_root,
+ .link = 0,
+ },
+ },
};