Uwe Hermann | b80dbf0 | 2007-04-22 19:08:13 +0000 | [diff] [blame] | 1 | /* |
Stefan Reinauer | 7e61e45 | 2008-01-18 10:35:56 +0000 | [diff] [blame] | 2 | * This file is part of the coreboot project. |
Uwe Hermann | b80dbf0 | 2007-04-22 19:08:13 +0000 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2003-2004 Linux Networx |
| 5 | * (Written by Eric Biederman <ebiederman@lnxi.com> for Linux Networx) |
| 6 | * Copyright (C) 2003 Greg Watson <jarrah@users.sourceforge.net> |
| 7 | * Copyright (C) 2004 Li-Ta Lo <ollie@lanl.gov> |
| 8 | * Copyright (C) 2005-2006 Tyan |
| 9 | * (Written by Yinghai Lu <yhlu@tyan.com> for Tyan) |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; version 2 of the License. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 23 | */ |
| 24 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 25 | #include <console/console.h> |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 26 | #include <device/device.h> |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 27 | #include <device/path.h> |
| 28 | #include <device/pci.h> |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 29 | #include <device/resource.h> |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 30 | #include <string.h> |
| 31 | |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 32 | /** |
| 33 | * @brief See if a device structure exists for path |
| 34 | * |
| 35 | * @param bus The bus to find the device on |
| 36 | * @param path The relative path from the bus to the appropriate device |
| 37 | * @return pointer to a device structure for the device on bus at path |
| 38 | * or 0/NULL if no device is found |
| 39 | */ |
| 40 | device_t find_dev_path(struct bus *parent, struct device_path *path) |
| 41 | { |
| 42 | device_t child; |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 43 | for (child = parent->children; child; child = child->sibling) { |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 44 | if (path_eq(path, &child->path)) { |
| 45 | break; |
| 46 | } |
| 47 | } |
| 48 | return child; |
| 49 | } |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 50 | |
| 51 | /** |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 52 | * @brief See if a device structure already exists and if not allocate it |
| 53 | * |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 54 | * @param bus The bus to find the device on |
| 55 | * @param path The relative path from the bus to the appropriate device |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 56 | * @return pointer to a device structure for the device on bus at path |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 57 | */ |
| 58 | device_t alloc_find_dev(struct bus *parent, struct device_path *path) |
| 59 | { |
| 60 | device_t child; |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 61 | child = find_dev_path(parent, path); |
| 62 | if (!child) { |
| 63 | child = alloc_dev(parent, path); |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 64 | } |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 65 | return child; |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 66 | } |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 67 | |
| 68 | /** |
Li-Ta Lo | e8b1c9d | 2004-12-27 04:25:41 +0000 | [diff] [blame] | 69 | * @brief Given a PCI bus and a devfn number, find the device structure |
| 70 | * |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 71 | * @param bus The bus number |
| 72 | * @param devfn a device/function number |
| 73 | * @return pointer to the device structure |
| 74 | */ |
| 75 | struct device *dev_find_slot(unsigned int bus, unsigned int devfn) |
| 76 | { |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 77 | struct device *dev, *result; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 78 | |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 79 | result = 0; |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 80 | for (dev = all_devices; dev; dev = dev->next) { |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 81 | if ((dev->path.type == DEVICE_PATH_PCI) && |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 82 | (dev->bus->secondary == bus) && |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 83 | (dev->path.pci.devfn == devfn)) { |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 84 | result = dev; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 85 | break; |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 86 | } |
| 87 | } |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 88 | return result; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 89 | } |
| 90 | |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 91 | /** |
| 92 | * @brief Given a smbus bus and a device number, find the device structure |
| 93 | * |
| 94 | * @param bus The bus number |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 95 | * @param addr a device number |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 96 | * @return pointer to the device structure |
| 97 | */ |
| 98 | struct device *dev_find_slot_on_smbus(unsigned int bus, unsigned int addr) |
| 99 | { |
| 100 | struct device *dev, *result; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 101 | |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 102 | result = 0; |
| 103 | for (dev = all_devices; dev; dev = dev->next) { |
| 104 | if ((dev->path.type == DEVICE_PATH_I2C) && |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 105 | (dev->bus->secondary == bus) && |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 106 | (dev->path.i2c.device == addr)) { |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 107 | result = dev; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 108 | break; |
| 109 | } |
| 110 | } |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 111 | return result; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 112 | } |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 113 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 114 | /** Find a device of a given vendor and type |
| 115 | * @param vendor Vendor ID (e.g. 0x8086 for Intel) |
| 116 | * @param device Device ID |
| 117 | * @param from Pointer to the device structure, used as a starting point |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 118 | * in the linked list of all_devices, which can be 0 to start at the |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 119 | * head of the list (i.e. all_devices) |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 120 | * @return Pointer to the device struct |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 121 | */ |
| 122 | struct device *dev_find_device(unsigned int vendor, unsigned int device, struct device *from) |
| 123 | { |
| 124 | if (!from) |
| 125 | from = all_devices; |
| 126 | else |
| 127 | from = from->next; |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 128 | while (from && (from->vendor != vendor || from->device != device)) { |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 129 | from = from->next; |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 130 | } |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 131 | return from; |
| 132 | } |
| 133 | |
| 134 | /** Find a device of a given class |
| 135 | * @param class Class of the device |
| 136 | * @param from Pointer to the device structure, used as a starting point |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 137 | * in the linked list of all_devices, which can be 0 to start at the |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 138 | * head of the list (i.e. all_devices) |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 139 | * @return Pointer to the device struct |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 140 | */ |
| 141 | struct device *dev_find_class(unsigned int class, struct device *from) |
| 142 | { |
| 143 | if (!from) |
| 144 | from = all_devices; |
| 145 | else |
| 146 | from = from->next; |
Greg Watson | 5965169 | 2003-12-17 17:39:53 +0000 | [diff] [blame] | 147 | while (from && (from->class & 0xffffff00) != class) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 148 | from = from->next; |
| 149 | return from; |
| 150 | } |
| 151 | |
Myles Watson | 8f6354b | 2009-10-29 21:27:43 +0000 | [diff] [blame] | 152 | /* Warning: This function uses a static buffer. Don't call it more than once |
| 153 | * from the same print statement! */ |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 154 | |
| 155 | const char *dev_path(device_t dev) |
| 156 | { |
| 157 | static char buffer[DEVICE_PATH_MAX]; |
| 158 | buffer[0] = '\0'; |
| 159 | if (!dev) { |
| 160 | memcpy(buffer, "<null>", 7); |
| 161 | } |
| 162 | else { |
| 163 | switch(dev->path.type) { |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 164 | case DEVICE_PATH_ROOT: |
| 165 | memcpy(buffer, "Root Device", 12); |
| 166 | break; |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 167 | case DEVICE_PATH_PCI: |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 168 | #if CONFIG_PCI_BUS_SEGN_BITS |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 169 | sprintf(buffer, "PCI: %04x:%02x:%02x.%01x", |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 170 | dev->bus->secondary>>8, dev->bus->secondary & 0xff, |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 171 | PCI_SLOT(dev->path.pci.devfn), PCI_FUNC(dev->path.pci.devfn)); |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 172 | #else |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 173 | sprintf(buffer, "PCI: %02x:%02x.%01x", |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 174 | dev->bus->secondary, |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 175 | PCI_SLOT(dev->path.pci.devfn), PCI_FUNC(dev->path.pci.devfn)); |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 176 | #endif |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 177 | break; |
| 178 | case DEVICE_PATH_PNP: |
| 179 | sprintf(buffer, "PNP: %04x.%01x", |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 180 | dev->path.pnp.port, dev->path.pnp.device); |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 181 | break; |
| 182 | case DEVICE_PATH_I2C: |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 183 | sprintf(buffer, "I2C: %02x:%02x", |
| 184 | dev->bus->secondary, |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 185 | dev->path.i2c.device); |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 186 | break; |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 187 | case DEVICE_PATH_APIC: |
| 188 | sprintf(buffer, "APIC: %02x", |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 189 | dev->path.apic.apic_id); |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 190 | break; |
Eric Biederman | 7003ba4 | 2004-10-16 06:20:29 +0000 | [diff] [blame] | 191 | case DEVICE_PATH_PCI_DOMAIN: |
| 192 | sprintf(buffer, "PCI_DOMAIN: %04x", |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 193 | dev->path.pci_domain.domain); |
Eric Biederman | 7003ba4 | 2004-10-16 06:20:29 +0000 | [diff] [blame] | 194 | break; |
| 195 | case DEVICE_PATH_APIC_CLUSTER: |
| 196 | sprintf(buffer, "APIC_CLUSTER: %01x", |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 197 | dev->path.apic_cluster.cluster); |
Eric Biederman | 7003ba4 | 2004-10-16 06:20:29 +0000 | [diff] [blame] | 198 | break; |
Eric Biederman | a9e632c | 2004-11-18 22:38:08 +0000 | [diff] [blame] | 199 | case DEVICE_PATH_CPU: |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 200 | sprintf(buffer, "CPU: %02x", dev->path.cpu.id); |
Eric Biederman | a9e632c | 2004-11-18 22:38:08 +0000 | [diff] [blame] | 201 | break; |
| 202 | case DEVICE_PATH_CPU_BUS: |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 203 | sprintf(buffer, "CPU_BUS: %02x", dev->path.cpu_bus.id); |
Eric Biederman | a9e632c | 2004-11-18 22:38:08 +0000 | [diff] [blame] | 204 | break; |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 205 | default: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 206 | printk(BIOS_ERR, "Unknown device path type: %d\n", dev->path.type); |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 207 | break; |
| 208 | } |
| 209 | } |
| 210 | return buffer; |
| 211 | } |
| 212 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 213 | const char *bus_path(struct bus *bus) |
| 214 | { |
| 215 | static char buffer[BUS_PATH_MAX]; |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 216 | sprintf(buffer, "%s,%d", dev_path(bus->dev), bus->link_num); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 217 | return buffer; |
| 218 | } |
| 219 | |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 220 | int path_eq(struct device_path *path1, struct device_path *path2) |
| 221 | { |
| 222 | int equal = 0; |
| 223 | if (path1->type == path2->type) { |
| 224 | switch(path1->type) { |
| 225 | case DEVICE_PATH_NONE: |
| 226 | break; |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 227 | case DEVICE_PATH_ROOT: |
| 228 | equal = 1; |
| 229 | break; |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 230 | case DEVICE_PATH_PCI: |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 231 | equal = (path1->pci.devfn == path2->pci.devfn); |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 232 | break; |
| 233 | case DEVICE_PATH_PNP: |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 234 | equal = (path1->pnp.port == path2->pnp.port) && |
| 235 | (path1->pnp.device == path2->pnp.device); |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 236 | break; |
| 237 | case DEVICE_PATH_I2C: |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 238 | equal = (path1->i2c.device == path2->i2c.device); |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 239 | break; |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 240 | case DEVICE_PATH_APIC: |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 241 | equal = (path1->apic.apic_id == path2->apic.apic_id); |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 242 | break; |
Eric Biederman | 7003ba4 | 2004-10-16 06:20:29 +0000 | [diff] [blame] | 243 | case DEVICE_PATH_PCI_DOMAIN: |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 244 | equal = (path1->pci_domain.domain == path2->pci_domain.domain); |
Eric Biederman | 7003ba4 | 2004-10-16 06:20:29 +0000 | [diff] [blame] | 245 | break; |
| 246 | case DEVICE_PATH_APIC_CLUSTER: |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 247 | equal = (path1->apic_cluster.cluster == path2->apic_cluster.cluster); |
Eric Biederman | 7003ba4 | 2004-10-16 06:20:29 +0000 | [diff] [blame] | 248 | break; |
Eric Biederman | a9e632c | 2004-11-18 22:38:08 +0000 | [diff] [blame] | 249 | case DEVICE_PATH_CPU: |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 250 | equal = (path1->cpu.id == path2->cpu.id); |
Eric Biederman | a9e632c | 2004-11-18 22:38:08 +0000 | [diff] [blame] | 251 | break; |
| 252 | case DEVICE_PATH_CPU_BUS: |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 253 | equal = (path1->cpu_bus.id == path2->cpu_bus.id); |
Eric Biederman | a9e632c | 2004-11-18 22:38:08 +0000 | [diff] [blame] | 254 | break; |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 255 | default: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 256 | printk(BIOS_ERR, "Uknown device type: %d\n", path1->type); |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 257 | break; |
| 258 | } |
| 259 | } |
| 260 | return equal; |
| 261 | } |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 262 | |
| 263 | /** |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 264 | * Allocate 64 more resources to the free list. |
| 265 | */ |
| 266 | static int allocate_more_resources(void) |
| 267 | { |
| 268 | int i; |
| 269 | struct resource *new_res_list; |
| 270 | new_res_list = malloc(64 * sizeof(*new_res_list)); |
| 271 | |
| 272 | if (new_res_list == NULL) |
| 273 | return 0; |
| 274 | |
| 275 | memset(new_res_list, 0, 64 * sizeof(*new_res_list)); |
| 276 | |
| 277 | for (i = 0; i < 64-1; i++) |
| 278 | new_res_list[i].next = &new_res_list[i+1]; |
| 279 | |
| 280 | free_resources = new_res_list; |
| 281 | return 1; |
| 282 | } |
| 283 | |
| 284 | /** |
| 285 | * Remove resource res from the device's list and add it to the free list. |
| 286 | */ |
| 287 | static void free_resource(device_t dev, struct resource *res, struct resource *prev) |
| 288 | { |
| 289 | if (prev) |
| 290 | prev->next = res->next; |
| 291 | else |
| 292 | dev->resource_list = res->next; |
| 293 | res->next = free_resources; |
| 294 | free_resources = res; |
| 295 | } |
| 296 | |
| 297 | /** |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 298 | * See if we have unused but allocated resource structures. |
| 299 | * If so remove the allocation. |
| 300 | * @param dev The device to find the resource on |
| 301 | */ |
| 302 | void compact_resources(device_t dev) |
| 303 | { |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 304 | struct resource *res, *next, *prev = NULL; |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 305 | /* Move all of the free resources to the end */ |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 306 | for (res = dev->resource_list; res; res = next) { |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 307 | next = res->next; |
| 308 | if (!res->flags) |
| 309 | free_resource(dev, res, prev); |
| 310 | else |
| 311 | prev = res; |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 312 | } |
| 313 | } |
| 314 | |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 315 | |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 316 | /** |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 317 | * See if a resource structure already exists for a given index |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 318 | * @param dev The device to find the resource on |
| 319 | * @param index The index of the resource on the device. |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 320 | * @return the resource if it already exists |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 321 | */ |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 322 | struct resource *probe_resource(device_t dev, unsigned index) |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 323 | { |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 324 | struct resource *res; |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 325 | /* See if there is a resource with the appropriate index */ |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 326 | for (res = dev->resource_list; res; res = res->next) { |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 327 | if (res->index == index) |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 328 | break; |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 329 | } |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 330 | return res; |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | /** |
| 334 | * See if a resource structure already exists for a given index and if |
| 335 | * not allocate one. Then initialize the initialize the resource |
| 336 | * to default values. |
| 337 | * @param dev The device to find the resource on |
| 338 | * @param index The index of the resource on the device. |
| 339 | */ |
| 340 | struct resource *new_resource(device_t dev, unsigned index) |
| 341 | { |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 342 | struct resource *resource, *tail; |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 343 | |
| 344 | /* First move all of the free resources to the end */ |
| 345 | compact_resources(dev); |
| 346 | |
| 347 | /* See if there is a resource with the appropriate index */ |
| 348 | resource = probe_resource(dev, index); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 349 | if (!resource) { |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 350 | if (free_resources == NULL && !allocate_more_resources()) |
| 351 | die("Couldn't allocate more resources."); |
| 352 | |
| 353 | resource = free_resources; |
| 354 | free_resources = free_resources->next; |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 355 | memset(resource, 0, sizeof(*resource)); |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 356 | resource->next = NULL; |
| 357 | tail = dev->resource_list; |
| 358 | if (tail) { |
| 359 | while (tail->next) tail = tail->next; |
| 360 | tail->next = resource; |
| 361 | } |
| 362 | else |
| 363 | dev->resource_list = resource; |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 364 | } |
| 365 | /* Initialize the resource values */ |
| 366 | if (!(resource->flags & IORESOURCE_FIXED)) { |
| 367 | resource->flags = 0; |
| 368 | resource->base = 0; |
| 369 | } |
| 370 | resource->size = 0; |
| 371 | resource->limit = 0; |
| 372 | resource->index = index; |
| 373 | resource->align = 0; |
| 374 | resource->gran = 0; |
| 375 | |
| 376 | return resource; |
| 377 | } |
| 378 | |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 379 | /** |
| 380 | * Return an existing resource structure for a given index. |
| 381 | * @param dev The device to find the resource on |
| 382 | * @param index The index of the resource on the device. |
| 383 | */ |
| 384 | struct resource *find_resource(device_t dev, unsigned index) |
| 385 | { |
| 386 | struct resource *resource; |
| 387 | |
| 388 | /* See if there is a resource with the appropriate index */ |
| 389 | resource = probe_resource(dev, index); |
| 390 | if (!resource) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 391 | printk(BIOS_EMERG, "%s missing resource: %02x\n", |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 392 | dev_path(dev), index); |
| 393 | die(""); |
| 394 | } |
| 395 | return resource; |
| 396 | } |
| 397 | |
| 398 | |
| 399 | /** |
| 400 | * @brief round a number up to the next multiple of gran |
| 401 | * @param val the starting value |
| 402 | * @param gran granularity we are aligning the number to. |
| 403 | * @returns aligned value |
| 404 | */ |
| 405 | static resource_t align_up(resource_t val, unsigned long gran) |
| 406 | { |
| 407 | resource_t mask; |
| 408 | mask = (1ULL << gran) - 1ULL; |
| 409 | val += mask; |
| 410 | val &= ~mask; |
| 411 | return val; |
| 412 | } |
| 413 | |
| 414 | /** |
| 415 | * @brief round a number up to the previous multiple of gran |
| 416 | * @param val the starting value |
| 417 | * @param gran granularity we are aligning the number to. |
| 418 | * @returns aligned value |
| 419 | */ |
| 420 | static resource_t align_down(resource_t val, unsigned long gran) |
| 421 | { |
| 422 | resource_t mask; |
| 423 | mask = (1ULL << gran) - 1ULL; |
| 424 | val &= ~mask; |
| 425 | return val; |
| 426 | } |
| 427 | |
| 428 | /** |
| 429 | * @brief Compute the maximum address that is part of a resource |
| 430 | * @param resource the resource whose limit is desired |
| 431 | * @returns the end |
| 432 | */ |
| 433 | resource_t resource_end(struct resource *resource) |
| 434 | { |
| 435 | resource_t base, end; |
| 436 | /* get the base address */ |
| 437 | base = resource->base; |
| 438 | |
| 439 | /* For a non bridge resource granularity and alignment are the same. |
| 440 | * For a bridge resource align is the largest needed alignment below |
| 441 | * the bridge. While the granularity is simply how many low bits of the |
| 442 | * address cannot be set. |
| 443 | */ |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 444 | |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 445 | /* Get the end (rounded up) */ |
| 446 | end = base + align_up(resource->size, resource->gran) - 1; |
| 447 | |
| 448 | return end; |
| 449 | } |
| 450 | |
| 451 | /** |
| 452 | * @brief Compute the maximum legal value for resource->base |
| 453 | * @param resource the resource whose maximum is desired |
| 454 | * @returns the maximum |
| 455 | */ |
| 456 | resource_t resource_max(struct resource *resource) |
| 457 | { |
| 458 | resource_t max; |
| 459 | |
| 460 | max = align_down(resource->limit - resource->size + 1, resource->align); |
| 461 | |
| 462 | return max; |
| 463 | } |
| 464 | |
| 465 | /** |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 466 | * @brief return the resource type of a resource |
| 467 | * @param resource the resource type to decode. |
| 468 | */ |
| 469 | const char *resource_type(struct resource *resource) |
| 470 | { |
| 471 | static char buffer[RESOURCE_TYPE_MAX]; |
| 472 | sprintf(buffer, "%s%s%s%s", |
| 473 | ((resource->flags & IORESOURCE_READONLY)? "ro": ""), |
| 474 | ((resource->flags & IORESOURCE_PREFETCH)? "pref":""), |
| 475 | ((resource->flags == 0)? "unused": |
| 476 | (resource->flags & IORESOURCE_IO)? "io": |
| 477 | (resource->flags & IORESOURCE_DRQ)? "drq": |
| 478 | (resource->flags & IORESOURCE_IRQ)? "irq": |
| 479 | (resource->flags & IORESOURCE_MEM)? "mem":"??????"), |
| 480 | ((resource->flags & IORESOURCE_PCI64)?"64":"")); |
| 481 | return buffer; |
| 482 | } |
| 483 | |
| 484 | /** |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 485 | * @brief print the resource that was just stored. |
| 486 | * @param dev the device the stored resorce lives on |
| 487 | * @param resource the resource that was just stored. |
| 488 | */ |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 489 | void report_resource_stored(device_t dev, struct resource *resource, const char *comment) |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 490 | { |
| 491 | if (resource->flags & IORESOURCE_STORED) { |
Stefan Reinauer | 0dff6e3 | 2007-10-23 22:17:45 +0000 | [diff] [blame] | 492 | char buf[10]; |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 493 | unsigned long long base, end; |
| 494 | base = resource->base; |
| 495 | end = resource_end(resource); |
| 496 | buf[0] = '\0'; |
| 497 | if (resource->flags & IORESOURCE_PCI_BRIDGE) { |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 498 | #if CONFIG_PCI_BUS_SEGN_BITS |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 499 | sprintf(buf, "bus %04x:%02x ", dev->bus->secondary>>8, dev->link_list->secondary & 0xff); |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 500 | #else |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 501 | sprintf(buf, "bus %02x ", dev->link_list->secondary); |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 502 | #endif |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 503 | } |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 504 | printk(BIOS_DEBUG, |
Myles Watson | c4ddbff | 2009-02-09 17:52:54 +0000 | [diff] [blame] | 505 | "%s %02lx <- [0x%010Lx - 0x%010Lx] size 0x%08Lx gran 0x%02x %s%s%s\n", |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 506 | dev_path(dev), |
| 507 | resource->index, |
| 508 | base, end, |
Carl-Daniel Hailfinger | 52bc993 | 2007-10-16 18:21:22 +0000 | [diff] [blame] | 509 | resource->size, resource->gran, |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 510 | buf, |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 511 | resource_type(resource), |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 512 | comment); |
| 513 | } |
| 514 | } |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 515 | |
| 516 | void search_bus_resources(struct bus *bus, |
| 517 | unsigned long type_mask, unsigned long type, |
| 518 | resource_search_t search, void *gp) |
| 519 | { |
| 520 | struct device *curdev; |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 521 | for (curdev = bus->children; curdev; curdev = curdev->sibling) { |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 522 | struct resource *res; |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 523 | /* Ignore disabled devices */ |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 524 | if (!curdev->enabled) continue; |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 525 | for (res = curdev->resource_list; res; res = res->next) { |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 526 | /* If it isn't the right kind of resource ignore it */ |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 527 | if ((res->flags & type_mask) != type) { |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 528 | continue; |
| 529 | } |
| 530 | /* If it is a subtractive resource recurse */ |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 531 | if (res->flags & IORESOURCE_SUBTRACTIVE) { |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 532 | struct bus * subbus; |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 533 | for (subbus = curdev->link_list; subbus; subbus = subbus->next) |
| 534 | if (subbus->link_num == IOINDEX_SUBTRACTIVE_LINK(res->index)) |
| 535 | break; |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 536 | search_bus_resources(subbus, type_mask, type, search, gp); |
| 537 | continue; |
| 538 | } |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 539 | search(gp, curdev, res); |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 540 | } |
| 541 | } |
| 542 | } |
| 543 | |
| 544 | void search_global_resources( |
| 545 | unsigned long type_mask, unsigned long type, |
| 546 | resource_search_t search, void *gp) |
| 547 | { |
| 548 | struct device *curdev; |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 549 | for (curdev = all_devices; curdev; curdev = curdev->next) { |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 550 | struct resource *res; |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 551 | /* Ignore disabled devices */ |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 552 | if (!curdev->enabled) continue; |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 553 | for (res = curdev->resource_list; res; res = res->next) { |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 554 | /* If it isn't the right kind of resource ignore it */ |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 555 | if ((res->flags & type_mask) != type) { |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 556 | continue; |
| 557 | } |
| 558 | /* If it is a subtractive resource ignore it */ |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 559 | if (res->flags & IORESOURCE_SUBTRACTIVE) { |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 560 | continue; |
| 561 | } |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 562 | search(gp, curdev, res); |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 563 | } |
| 564 | } |
| 565 | } |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 566 | |
| 567 | void dev_set_enabled(device_t dev, int enable) |
| 568 | { |
| 569 | if (dev->enabled == enable) { |
| 570 | return; |
| 571 | } |
| 572 | dev->enabled = enable; |
| 573 | if (dev->ops && dev->ops->enable) { |
| 574 | dev->ops->enable(dev); |
| 575 | } |
| 576 | else if (dev->chip_ops && dev->chip_ops->enable_dev) { |
| 577 | dev->chip_ops->enable_dev(dev); |
| 578 | } |
| 579 | } |
| 580 | |
| 581 | void disable_children(struct bus *bus) |
| 582 | { |
| 583 | device_t child; |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 584 | for (child = bus->children; child; child = child->sibling) { |
| 585 | struct bus *link; |
| 586 | for (link = child->link_list; link; link = link->next) { |
| 587 | disable_children(link); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 588 | } |
| 589 | dev_set_enabled(child, 0); |
| 590 | } |
| 591 | } |
Myles Watson | bb3d812 | 2009-05-11 22:45:35 +0000 | [diff] [blame] | 592 | |
Maciej Pijanka | ea92185 | 2009-10-27 14:29:29 +0000 | [diff] [blame] | 593 | static void resource_tree(struct device *root, int debug_level, int depth) |
Myles Watson | bb3d812 | 2009-05-11 22:45:35 +0000 | [diff] [blame] | 594 | { |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 595 | int i = 0; |
Myles Watson | bb3d812 | 2009-05-11 22:45:35 +0000 | [diff] [blame] | 596 | struct device *child; |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 597 | struct bus *link; |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 598 | struct resource *res; |
Myles Watson | bb3d812 | 2009-05-11 22:45:35 +0000 | [diff] [blame] | 599 | char indent[30]; /* If your tree has more levels, it's wrong. */ |
| 600 | |
| 601 | for (i = 0; i < depth + 1 && i < 29; i++) |
| 602 | indent[i] = ' '; |
| 603 | indent[i] = '\0'; |
| 604 | |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 605 | do_printk(BIOS_DEBUG, "%s%s", indent, dev_path(root)); |
| 606 | if (root->link_list && root->link_list->children) |
| 607 | do_printk(BIOS_DEBUG, " child on link 0 %s", |
| 608 | dev_path(root->link_list->children)); |
| 609 | do_printk(BIOS_DEBUG, "\n"); |
| 610 | |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 611 | for (res = root->resource_list; res; res = res->next) { |
Myles Watson | 5f06701 | 2010-06-02 21:13:44 +0000 | [diff] [blame] | 612 | do_printk(debug_level, |
Myles Watson | bb3d812 | 2009-05-11 22:45:35 +0000 | [diff] [blame] | 613 | "%s%s resource base %llx size %llx align %d gran %d limit %llx flags %lx index %lx\n", |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 614 | indent, dev_path(root), res->base, |
| 615 | res->size, res->align, |
| 616 | res->gran, res->limit, |
| 617 | res->flags, res->index); |
Myles Watson | bb3d812 | 2009-05-11 22:45:35 +0000 | [diff] [blame] | 618 | } |
| 619 | |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 620 | for (link = root->link_list; link; link = link->next) { |
| 621 | for (child = link->children; child; child = child->sibling) |
Myles Watson | bb3d812 | 2009-05-11 22:45:35 +0000 | [diff] [blame] | 622 | resource_tree(child, debug_level, depth + 1); |
| 623 | } |
| 624 | } |
| 625 | |
| 626 | void print_resource_tree(struct device * root, int debug_level, |
| 627 | const char *msg) |
| 628 | { |
| 629 | /* Bail if root is null. */ |
| 630 | if (!root) { |
| 631 | do_printk(debug_level, "%s passed NULL for root!\n", __func__); |
| 632 | return; |
| 633 | } |
| 634 | |
| 635 | /* Bail if not printing to screen. */ |
| 636 | if (!do_printk(debug_level, "Show resources in subtree (%s)...%s\n", |
| 637 | dev_path(root), msg)) |
| 638 | return; |
| 639 | resource_tree(root, debug_level, 0); |
| 640 | } |
| 641 | |
| 642 | void show_devs_tree(struct device *dev, int debug_level, int depth, int linknum) |
| 643 | { |
| 644 | char depth_str[20] = ""; |
| 645 | int i; |
| 646 | struct device *sibling; |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 647 | struct bus *link; |
| 648 | |
Myles Watson | bb3d812 | 2009-05-11 22:45:35 +0000 | [diff] [blame] | 649 | for (i = 0; i < depth; i++) |
| 650 | depth_str[i] = ' '; |
| 651 | depth_str[i] = '\0'; |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 652 | do_printk(debug_level, "%s%s: enabled %d\n", |
| 653 | depth_str, dev_path(dev), dev->enabled); |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 654 | for (link = dev->link_list; link; link = link->next) { |
| 655 | for (sibling = link->children; sibling; |
Myles Watson | bb3d812 | 2009-05-11 22:45:35 +0000 | [diff] [blame] | 656 | sibling = sibling->sibling) |
| 657 | show_devs_tree(sibling, debug_level, depth + 1, i); |
| 658 | } |
| 659 | } |
| 660 | |
| 661 | void show_all_devs_tree(int debug_level, const char *msg) |
| 662 | { |
| 663 | /* Bail if not printing to screen. */ |
| 664 | if (!do_printk(debug_level, "Show all devs in tree form...%s\n", msg)) |
| 665 | return; |
| 666 | show_devs_tree(all_devices, debug_level, 0, -1); |
| 667 | } |
| 668 | |
| 669 | void show_devs_subtree(struct device *root, int debug_level, const char *msg) |
| 670 | { |
| 671 | /* Bail if not printing to screen. */ |
| 672 | if (!do_printk(debug_level, "Show all devs in subtree %s...%s\n", |
| 673 | dev_path(root), msg)) |
| 674 | return; |
| 675 | do_printk(debug_level, "%s\n", msg); |
| 676 | show_devs_tree(root, debug_level, 0, -1); |
| 677 | } |
| 678 | |
| 679 | void show_all_devs(int debug_level, const char *msg) |
| 680 | { |
| 681 | struct device *dev; |
| 682 | |
| 683 | /* Bail if not printing to screen. */ |
| 684 | if (!do_printk(debug_level, "Show all devs...%s\n", msg)) |
| 685 | return; |
| 686 | for (dev = all_devices; dev; dev = dev->next) { |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 687 | do_printk(debug_level, "%s: enabled %d\n", |
| 688 | dev_path(dev), dev->enabled); |
Myles Watson | bb3d812 | 2009-05-11 22:45:35 +0000 | [diff] [blame] | 689 | } |
| 690 | } |
| 691 | |
| 692 | void show_one_resource(int debug_level, struct device *dev, |
| 693 | struct resource *resource, const char *comment) |
| 694 | { |
| 695 | char buf[10]; |
| 696 | unsigned long long base, end; |
| 697 | base = resource->base; |
| 698 | end = resource_end(resource); |
| 699 | buf[0] = '\0'; |
| 700 | /* |
| 701 | if (resource->flags & IORESOURCE_BRIDGE) { |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 702 | #if CONFIG_PCI_BUS_SEGN_BITS |
Myles Watson | bb3d812 | 2009-05-11 22:45:35 +0000 | [diff] [blame] | 703 | sprintf(buf, "bus %04x:%02x ", dev->bus->secondary >> 8, |
| 704 | dev->link[0].secondary & 0xff); |
| 705 | #else |
| 706 | sprintf(buf, "bus %02x ", dev->link[0].secondary); |
| 707 | #endif |
| 708 | } |
| 709 | */ |
| 710 | do_printk(debug_level, "%s %02lx <- [0x%010llx - 0x%010llx] " |
| 711 | "size 0x%08Lx gran 0x%02x %s%s%s\n", |
| 712 | dev_path(dev), resource->index, base, end, |
| 713 | resource->size, resource->gran, buf, |
| 714 | resource_type(resource), comment); |
| 715 | |
| 716 | } |
| 717 | |
| 718 | void show_all_devs_resources(int debug_level, const char* msg) |
| 719 | { |
| 720 | struct device *dev; |
| 721 | |
| 722 | if(!do_printk(debug_level, "Show all devs with resources...%s\n", msg)) |
| 723 | return; |
| 724 | |
| 725 | for (dev = all_devices; dev; dev = dev->next) { |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 726 | struct resource *res; |
| 727 | do_printk(debug_level, "%s: enabled %d\n", |
| 728 | dev_path(dev), dev->enabled); |
| 729 | for (res = dev->resource_list; res; res = res->next) |
| 730 | show_one_resource(debug_level, dev, res, ""); |
Myles Watson | bb3d812 | 2009-05-11 22:45:35 +0000 | [diff] [blame] | 731 | } |
| 732 | } |