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. |
Uwe Hermann | b80dbf0 | 2007-04-22 19:08:13 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 21 | #include <console/console.h> |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 22 | #include <device/device.h> |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 23 | #include <device/path.h> |
Kyösti Mälkki | 318066f | 2014-02-12 14:18:50 +0200 | [diff] [blame] | 24 | #include <device/pci_def.h> |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 25 | #include <device/resource.h> |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 26 | #include <string.h> |
| 27 | |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 28 | /** |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 29 | * See if a device structure exists for path. |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 30 | * |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 31 | * @param parent The bus to find the device on. |
| 32 | * @param path The relative path from the bus to the appropriate device. |
| 33 | * @return Pointer to a device structure for the device on bus at path |
| 34 | * or 0/NULL if no device is found. |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 35 | */ |
| 36 | device_t find_dev_path(struct bus *parent, struct device_path *path) |
| 37 | { |
| 38 | device_t child; |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 39 | for (child = parent->children; child; child = child->sibling) { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 40 | if (path_eq(path, &child->path)) |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 41 | break; |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 42 | } |
| 43 | return child; |
| 44 | } |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 45 | |
| 46 | /** |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 47 | * Given a PCI bus and a devfn number, find the device structure. |
Li-Ta Lo | e8b1c9d | 2004-12-27 04:25:41 +0000 | [diff] [blame] | 48 | * |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 49 | * @param bus The bus number. |
| 50 | * @param devfn A device/function number. |
| 51 | * @return Pointer to the device structure (if found), 0 otherwise. |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 52 | */ |
| 53 | struct device *dev_find_slot(unsigned int bus, unsigned int devfn) |
| 54 | { |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 55 | struct device *dev, *result; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 56 | |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 57 | result = 0; |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 58 | for (dev = all_devices; dev; dev = dev->next) { |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 59 | if ((dev->path.type == DEVICE_PATH_PCI) && |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 60 | (dev->bus->secondary == bus) && |
| 61 | (dev->path.pci.devfn == devfn)) { |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 62 | result = dev; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 63 | break; |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 64 | } |
| 65 | } |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 66 | return result; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 67 | } |
| 68 | |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 69 | /** |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 70 | * Given an SMBus bus and a device number, find the device structure. |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 71 | * |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 72 | * @param bus The bus number. |
| 73 | * @param addr A device number. |
| 74 | * @return Pointer to the device structure (if found), 0 otherwise. |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 75 | */ |
| 76 | struct device *dev_find_slot_on_smbus(unsigned int bus, unsigned int addr) |
| 77 | { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 78 | struct device *dev, *result; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 79 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 80 | result = 0; |
| 81 | for (dev = all_devices; dev; dev = dev->next) { |
| 82 | if ((dev->path.type == DEVICE_PATH_I2C) && |
| 83 | (dev->bus->secondary == bus) && |
| 84 | (dev->path.i2c.device == addr)) { |
| 85 | result = dev; |
| 86 | break; |
| 87 | } |
| 88 | } |
| 89 | return result; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 90 | } |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 91 | |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 92 | /** |
Vladimir Serbinenko | 400c05c | 2014-02-04 14:34:11 +0100 | [diff] [blame] | 93 | * Given a PnP port and a device number, find the device structure. |
| 94 | * |
| 95 | * @param port The I/O port. |
| 96 | * @param device Logical device number. |
| 97 | * @return Pointer to the device structure (if found), 0 otherwise. |
| 98 | */ |
Vladimir Serbinenko | b33384a | 2014-02-08 18:58:39 +0100 | [diff] [blame] | 99 | struct device *dev_find_slot_pnp(u16 port, u16 device) |
Vladimir Serbinenko | 400c05c | 2014-02-04 14:34:11 +0100 | [diff] [blame] | 100 | { |
| 101 | struct device *dev; |
| 102 | |
| 103 | for (dev = all_devices; dev; dev = dev->next) { |
| 104 | if ((dev->path.type == DEVICE_PATH_PNP) && |
| 105 | (dev->path.pnp.port == port) && |
| 106 | (dev->path.pnp.device == device)) { |
| 107 | return dev; |
| 108 | } |
| 109 | } |
| 110 | return 0; |
| 111 | } |
| 112 | |
| 113 | /** |
Duncan Laurie | 6f88a6e | 2011-07-18 10:41:36 -0700 | [diff] [blame] | 114 | * Given a Local APIC ID, find the device structure. |
| 115 | * |
| 116 | * @param apic_id The Local APIC ID number. |
| 117 | * @return Pointer to the device structure (if found), 0 otherwise. |
| 118 | */ |
| 119 | device_t dev_find_lapic(unsigned apic_id) |
| 120 | { |
| 121 | device_t dev, result = NULL; |
| 122 | |
| 123 | for (dev = all_devices; dev; dev = dev->next) { |
| 124 | if (dev->path.type == DEVICE_PATH_APIC && |
| 125 | dev->path.apic.apic_id == apic_id) { |
| 126 | result = dev; |
| 127 | break; |
| 128 | } |
| 129 | } |
| 130 | return result; |
| 131 | } |
| 132 | |
| 133 | /** |
Subrata Banik | fe204fe | 2016-12-06 18:06:30 +0530 | [diff] [blame^] | 134 | * Given a Device Path Type, find the device structure. |
| 135 | * |
| 136 | * @param prev_match The previously matched device instance. |
| 137 | * @param path_type The Device Path Type. |
| 138 | * @return Pointer to the device structure (if found), 0 otherwise. |
| 139 | */ |
| 140 | device_t dev_find_path(device_t prev_match, enum device_path_type path_type) |
| 141 | { |
| 142 | device_t dev, result = NULL; |
| 143 | |
| 144 | if (prev_match == NULL) |
| 145 | prev_match = all_devices; |
| 146 | else |
| 147 | prev_match = prev_match->next; |
| 148 | |
| 149 | for (dev = prev_match; dev; dev = dev->next) { |
| 150 | if (dev->path.type == path_type) { |
| 151 | result = dev; |
| 152 | break; |
| 153 | } |
| 154 | } |
| 155 | return result; |
| 156 | } |
| 157 | |
| 158 | /** |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 159 | * Find a device of a given vendor and type. |
| 160 | * |
| 161 | * @param vendor A PCI vendor ID (e.g. 0x8086 for Intel). |
| 162 | * @param device A PCI device ID. |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 163 | * @param from Pointer to the device structure, used as a starting point in |
| 164 | * the linked list of all_devices, which can be 0 to start at the |
| 165 | * head of the list (i.e. all_devices). |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 166 | * @return Pointer to the device struct. |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 167 | */ |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 168 | struct device *dev_find_device(u16 vendor, u16 device, struct device *from) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 169 | { |
| 170 | if (!from) |
| 171 | from = all_devices; |
| 172 | else |
| 173 | from = from->next; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 174 | |
| 175 | while (from && (from->vendor != vendor || from->device != device)) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 176 | from = from->next; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 177 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 178 | return from; |
| 179 | } |
| 180 | |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 181 | /** |
| 182 | * Find a device of a given class. |
| 183 | * |
| 184 | * @param class Class of the device. |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 185 | * @param from Pointer to the device structure, used as a starting point in |
| 186 | * the linked list of all_devices, which can be 0 to start at the |
| 187 | * head of the list (i.e. all_devices). |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 188 | * @return Pointer to the device struct. |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 189 | */ |
| 190 | struct device *dev_find_class(unsigned int class, struct device *from) |
| 191 | { |
| 192 | if (!from) |
| 193 | from = all_devices; |
| 194 | else |
| 195 | from = from->next; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 196 | |
Greg Watson | 5965169 | 2003-12-17 17:39:53 +0000 | [diff] [blame] | 197 | while (from && (from->class & 0xffffff00) != class) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 198 | from = from->next; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 199 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 200 | return from; |
| 201 | } |
| 202 | |
Duncan Laurie | 5f5d914 | 2013-06-10 09:59:17 -0700 | [diff] [blame] | 203 | /** |
| 204 | * Encode the device path into 3 bytes for logging to CMOS. |
| 205 | * |
| 206 | * @param dev The device path to encode. |
| 207 | * @return Device path encoded into lower 3 bytes of dword. |
| 208 | */ |
| 209 | u32 dev_path_encode(device_t dev) |
| 210 | { |
| 211 | u32 ret; |
| 212 | |
| 213 | if (!dev) |
| 214 | return 0; |
| 215 | |
| 216 | /* Store the device type in 3rd byte. */ |
| 217 | ret = dev->path.type << 16; |
| 218 | |
| 219 | /* Encode the device specific path in the low word. */ |
| 220 | switch (dev->path.type) { |
| 221 | case DEVICE_PATH_ROOT: |
| 222 | break; |
| 223 | case DEVICE_PATH_PCI: |
| 224 | ret |= dev->bus->secondary << 8 | dev->path.pci.devfn; |
| 225 | break; |
| 226 | case DEVICE_PATH_PNP: |
| 227 | ret |= dev->path.pnp.port << 8 | dev->path.pnp.device; |
| 228 | break; |
| 229 | case DEVICE_PATH_I2C: |
Duncan Laurie | b7ce5fe | 2016-05-07 19:49:37 -0700 | [diff] [blame] | 230 | ret |= dev->path.i2c.mode_10bit << 8 | dev->path.i2c.device; |
Duncan Laurie | 5f5d914 | 2013-06-10 09:59:17 -0700 | [diff] [blame] | 231 | break; |
| 232 | case DEVICE_PATH_APIC: |
| 233 | ret |= dev->path.apic.apic_id; |
| 234 | break; |
| 235 | case DEVICE_PATH_DOMAIN: |
| 236 | ret |= dev->path.domain.domain; |
| 237 | break; |
| 238 | case DEVICE_PATH_CPU_CLUSTER: |
| 239 | ret |= dev->path.cpu_cluster.cluster; |
| 240 | break; |
| 241 | case DEVICE_PATH_CPU: |
| 242 | ret |= dev->path.cpu.id; |
| 243 | break; |
| 244 | case DEVICE_PATH_CPU_BUS: |
| 245 | ret |= dev->path.cpu_bus.id; |
| 246 | break; |
| 247 | case DEVICE_PATH_IOAPIC: |
| 248 | ret |= dev->path.ioapic.ioapic_id; |
| 249 | break; |
Duncan Laurie | 4650f5b | 2016-05-07 20:01:34 -0700 | [diff] [blame] | 250 | case DEVICE_PATH_GENERIC: |
| 251 | ret |= dev->path.generic.subid << 8 | dev->path.generic.id; |
| 252 | break; |
Duncan Laurie | 5f5d914 | 2013-06-10 09:59:17 -0700 | [diff] [blame] | 253 | case DEVICE_PATH_NONE: |
| 254 | default: |
| 255 | break; |
| 256 | } |
| 257 | |
| 258 | return ret; |
| 259 | } |
| 260 | |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 261 | /* |
| 262 | * Warning: This function uses a static buffer. Don't call it more than once |
| 263 | * from the same print statement! |
| 264 | */ |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 265 | const char *dev_path(device_t dev) |
| 266 | { |
| 267 | static char buffer[DEVICE_PATH_MAX]; |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 268 | |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 269 | buffer[0] = '\0'; |
| 270 | if (!dev) { |
| 271 | memcpy(buffer, "<null>", 7); |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 272 | } else { |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 273 | switch(dev->path.type) { |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 274 | case DEVICE_PATH_ROOT: |
| 275 | memcpy(buffer, "Root Device", 12); |
| 276 | break; |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 277 | case DEVICE_PATH_PCI: |
Vladimir Serbinenko | a37383d | 2013-11-26 02:41:26 +0100 | [diff] [blame] | 278 | snprintf(buffer, sizeof (buffer), |
| 279 | "PCI: %02x:%02x.%01x", |
| 280 | dev->bus->secondary, |
| 281 | PCI_SLOT(dev->path.pci.devfn), |
| 282 | PCI_FUNC(dev->path.pci.devfn)); |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 283 | break; |
| 284 | case DEVICE_PATH_PNP: |
Vladimir Serbinenko | a37383d | 2013-11-26 02:41:26 +0100 | [diff] [blame] | 285 | snprintf(buffer, sizeof (buffer), "PNP: %04x.%01x", |
| 286 | dev->path.pnp.port, dev->path.pnp.device); |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 287 | break; |
| 288 | case DEVICE_PATH_I2C: |
Vladimir Serbinenko | a37383d | 2013-11-26 02:41:26 +0100 | [diff] [blame] | 289 | snprintf(buffer, sizeof (buffer), "I2C: %02x:%02x", |
| 290 | dev->bus->secondary, |
| 291 | dev->path.i2c.device); |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 292 | break; |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 293 | case DEVICE_PATH_APIC: |
Vladimir Serbinenko | a37383d | 2013-11-26 02:41:26 +0100 | [diff] [blame] | 294 | snprintf(buffer, sizeof (buffer), "APIC: %02x", |
| 295 | dev->path.apic.apic_id); |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 296 | break; |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 297 | case DEVICE_PATH_IOAPIC: |
Vladimir Serbinenko | a37383d | 2013-11-26 02:41:26 +0100 | [diff] [blame] | 298 | snprintf(buffer, sizeof (buffer), "IOAPIC: %02x", |
| 299 | dev->path.ioapic.ioapic_id); |
Sven Schnelle | 0fa50a1 | 2012-06-21 22:19:48 +0200 | [diff] [blame] | 300 | break; |
Stefan Reinauer | 4aff445 | 2013-02-12 14:17:15 -0800 | [diff] [blame] | 301 | case DEVICE_PATH_DOMAIN: |
Vladimir Serbinenko | a37383d | 2013-11-26 02:41:26 +0100 | [diff] [blame] | 302 | snprintf(buffer, sizeof (buffer), "DOMAIN: %04x", |
Stefan Reinauer | 4aff445 | 2013-02-12 14:17:15 -0800 | [diff] [blame] | 303 | dev->path.domain.domain); |
Eric Biederman | 7003ba4 | 2004-10-16 06:20:29 +0000 | [diff] [blame] | 304 | break; |
Stefan Reinauer | 0aa37c4 | 2013-02-12 15:20:54 -0800 | [diff] [blame] | 305 | case DEVICE_PATH_CPU_CLUSTER: |
Vladimir Serbinenko | a37383d | 2013-11-26 02:41:26 +0100 | [diff] [blame] | 306 | snprintf(buffer, sizeof (buffer), "CPU_CLUSTER: %01x", |
Stefan Reinauer | 0aa37c4 | 2013-02-12 15:20:54 -0800 | [diff] [blame] | 307 | dev->path.cpu_cluster.cluster); |
Eric Biederman | 7003ba4 | 2004-10-16 06:20:29 +0000 | [diff] [blame] | 308 | break; |
Eric Biederman | a9e632c | 2004-11-18 22:38:08 +0000 | [diff] [blame] | 309 | case DEVICE_PATH_CPU: |
Vladimir Serbinenko | a37383d | 2013-11-26 02:41:26 +0100 | [diff] [blame] | 310 | snprintf(buffer, sizeof (buffer), |
| 311 | "CPU: %02x", dev->path.cpu.id); |
Eric Biederman | a9e632c | 2004-11-18 22:38:08 +0000 | [diff] [blame] | 312 | break; |
| 313 | case DEVICE_PATH_CPU_BUS: |
Vladimir Serbinenko | a37383d | 2013-11-26 02:41:26 +0100 | [diff] [blame] | 314 | snprintf(buffer, sizeof (buffer), |
| 315 | "CPU_BUS: %02x", dev->path.cpu_bus.id); |
Eric Biederman | a9e632c | 2004-11-18 22:38:08 +0000 | [diff] [blame] | 316 | break; |
Duncan Laurie | 4650f5b | 2016-05-07 20:01:34 -0700 | [diff] [blame] | 317 | case DEVICE_PATH_GENERIC: |
| 318 | snprintf(buffer, sizeof (buffer), |
| 319 | "GENERIC: %d.%d", dev->path.generic.id, |
| 320 | dev->path.generic.subid); |
| 321 | break; |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 322 | default: |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 323 | printk(BIOS_ERR, "Unknown device path type: %d\n", |
| 324 | dev->path.type); |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 325 | break; |
| 326 | } |
| 327 | } |
| 328 | return buffer; |
| 329 | } |
| 330 | |
Kyösti Mälkki | 7baadac | 2012-10-07 14:57:15 +0200 | [diff] [blame] | 331 | const char *dev_name(device_t dev) |
| 332 | { |
Kyösti Mälkki | 7d54eb8 | 2012-10-10 23:14:28 +0300 | [diff] [blame] | 333 | if (dev->name) |
| 334 | return dev->name; |
| 335 | else if (dev->chip_ops && dev->chip_ops->name) |
Kyösti Mälkki | 7baadac | 2012-10-07 14:57:15 +0200 | [diff] [blame] | 336 | return dev->chip_ops->name; |
| 337 | else |
| 338 | return "unknown"; |
| 339 | } |
| 340 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 341 | const char *bus_path(struct bus *bus) |
| 342 | { |
| 343 | static char buffer[BUS_PATH_MAX]; |
Vladimir Serbinenko | a37383d | 2013-11-26 02:41:26 +0100 | [diff] [blame] | 344 | snprintf(buffer, sizeof (buffer), |
| 345 | "%s,%d", dev_path(bus->dev), bus->link_num); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 346 | return buffer; |
| 347 | } |
| 348 | |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 349 | int path_eq(struct device_path *path1, struct device_path *path2) |
| 350 | { |
| 351 | int equal = 0; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 352 | |
| 353 | if (path1->type != path2->type) |
| 354 | return 0; |
| 355 | |
| 356 | switch (path1->type) { |
| 357 | case DEVICE_PATH_NONE: |
| 358 | break; |
| 359 | case DEVICE_PATH_ROOT: |
| 360 | equal = 1; |
| 361 | break; |
| 362 | case DEVICE_PATH_PCI: |
| 363 | equal = (path1->pci.devfn == path2->pci.devfn); |
| 364 | break; |
| 365 | case DEVICE_PATH_PNP: |
| 366 | equal = (path1->pnp.port == path2->pnp.port) && |
| 367 | (path1->pnp.device == path2->pnp.device); |
| 368 | break; |
| 369 | case DEVICE_PATH_I2C: |
Duncan Laurie | b7ce5fe | 2016-05-07 19:49:37 -0700 | [diff] [blame] | 370 | equal = (path1->i2c.device == path2->i2c.device) && |
| 371 | (path1->i2c.mode_10bit == path2->i2c.mode_10bit); |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 372 | break; |
| 373 | case DEVICE_PATH_APIC: |
| 374 | equal = (path1->apic.apic_id == path2->apic.apic_id); |
| 375 | break; |
Stefan Reinauer | 4aff445 | 2013-02-12 14:17:15 -0800 | [diff] [blame] | 376 | case DEVICE_PATH_DOMAIN: |
| 377 | equal = (path1->domain.domain == path2->domain.domain); |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 378 | break; |
Stefan Reinauer | 0aa37c4 | 2013-02-12 15:20:54 -0800 | [diff] [blame] | 379 | case DEVICE_PATH_CPU_CLUSTER: |
| 380 | equal = (path1->cpu_cluster.cluster |
| 381 | == path2->cpu_cluster.cluster); |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 382 | break; |
| 383 | case DEVICE_PATH_CPU: |
| 384 | equal = (path1->cpu.id == path2->cpu.id); |
| 385 | break; |
| 386 | case DEVICE_PATH_CPU_BUS: |
| 387 | equal = (path1->cpu_bus.id == path2->cpu_bus.id); |
| 388 | break; |
Duncan Laurie | 4650f5b | 2016-05-07 20:01:34 -0700 | [diff] [blame] | 389 | case DEVICE_PATH_GENERIC: |
| 390 | equal = (path1->generic.id == path2->generic.id) && |
| 391 | (path1->generic.subid == path2->generic.subid); |
| 392 | break; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 393 | default: |
Martin Roth | 63373ed | 2013-07-08 16:24:19 -0600 | [diff] [blame] | 394 | printk(BIOS_ERR, "Unknown device type: %d\n", path1->type); |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 395 | break; |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 396 | } |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 397 | |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 398 | return equal; |
| 399 | } |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 400 | |
| 401 | /** |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 402 | * Allocate 64 more resources to the free list. |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 403 | * |
| 404 | * @return TODO. |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 405 | */ |
| 406 | static int allocate_more_resources(void) |
| 407 | { |
| 408 | int i; |
| 409 | struct resource *new_res_list; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 410 | |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 411 | new_res_list = malloc(64 * sizeof(*new_res_list)); |
| 412 | |
| 413 | if (new_res_list == NULL) |
| 414 | return 0; |
| 415 | |
| 416 | memset(new_res_list, 0, 64 * sizeof(*new_res_list)); |
| 417 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 418 | for (i = 0; i < 64 - 1; i++) |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 419 | new_res_list[i].next = &new_res_list[i+1]; |
| 420 | |
| 421 | free_resources = new_res_list; |
| 422 | return 1; |
| 423 | } |
| 424 | |
| 425 | /** |
| 426 | * Remove resource res from the device's list and add it to the free list. |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 427 | * |
| 428 | * @param dev TODO |
| 429 | * @param res TODO |
| 430 | * @param prev TODO |
| 431 | * @return TODO. |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 432 | */ |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 433 | static void free_resource(device_t dev, struct resource *res, |
| 434 | struct resource *prev) |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 435 | { |
| 436 | if (prev) |
| 437 | prev->next = res->next; |
| 438 | else |
| 439 | dev->resource_list = res->next; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 440 | |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 441 | res->next = free_resources; |
| 442 | free_resources = res; |
| 443 | } |
| 444 | |
| 445 | /** |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 446 | * See if we have unused but allocated resource structures. |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 447 | * |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 448 | * If so remove the allocation. |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 449 | * |
| 450 | * @param dev The device to find the resource on. |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 451 | */ |
| 452 | void compact_resources(device_t dev) |
| 453 | { |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 454 | struct resource *res, *next, *prev = NULL; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 455 | |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 456 | /* Move all of the free resources to the end */ |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 457 | for (res = dev->resource_list; res; res = next) { |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 458 | next = res->next; |
| 459 | if (!res->flags) |
| 460 | free_resource(dev, res, prev); |
| 461 | else |
| 462 | prev = res; |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 463 | } |
| 464 | } |
| 465 | |
| 466 | /** |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 467 | * See if a resource structure already exists for a given index. |
| 468 | * |
| 469 | * @param dev The device to find the resource on. |
| 470 | * @param index The index of the resource on the device. |
| 471 | * @return The resource, if it already exists. |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 472 | */ |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 473 | struct resource *probe_resource(device_t dev, unsigned index) |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 474 | { |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 475 | struct resource *res; |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 476 | |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 477 | /* See if there is a resource with the appropriate index */ |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 478 | for (res = dev->resource_list; res; res = res->next) { |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 479 | if (res->index == index) |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 480 | break; |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 481 | } |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 482 | |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 483 | return res; |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | /** |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 487 | * See if a resource structure already exists for a given index and if not |
| 488 | * allocate one. |
| 489 | * |
Paul Menzel | 2092387 | 2014-06-07 13:31:29 +0200 | [diff] [blame] | 490 | * Then initialize the resource to default values. |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 491 | * |
| 492 | * @param dev The device to find the resource on. |
| 493 | * @param index The index of the resource on the device. |
| 494 | * @return TODO. |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 495 | */ |
| 496 | struct resource *new_resource(device_t dev, unsigned index) |
| 497 | { |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 498 | struct resource *resource, *tail; |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 499 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 500 | /* First move all of the free resources to the end. */ |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 501 | compact_resources(dev); |
| 502 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 503 | /* See if there is a resource with the appropriate index. */ |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 504 | resource = probe_resource(dev, index); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 505 | if (!resource) { |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 506 | if (free_resources == NULL && !allocate_more_resources()) |
| 507 | die("Couldn't allocate more resources."); |
| 508 | |
| 509 | resource = free_resources; |
| 510 | free_resources = free_resources->next; |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 511 | memset(resource, 0, sizeof(*resource)); |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 512 | resource->next = NULL; |
| 513 | tail = dev->resource_list; |
| 514 | if (tail) { |
| 515 | while (tail->next) tail = tail->next; |
| 516 | tail->next = resource; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 517 | } else { |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 518 | dev->resource_list = resource; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 519 | } |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 520 | } |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 521 | |
| 522 | /* Initialize the resource values. */ |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 523 | if (!(resource->flags & IORESOURCE_FIXED)) { |
| 524 | resource->flags = 0; |
| 525 | resource->base = 0; |
| 526 | } |
| 527 | resource->size = 0; |
| 528 | resource->limit = 0; |
| 529 | resource->index = index; |
| 530 | resource->align = 0; |
| 531 | resource->gran = 0; |
| 532 | |
| 533 | return resource; |
| 534 | } |
| 535 | |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 536 | /** |
| 537 | * Return an existing resource structure for a given index. |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 538 | * |
| 539 | * @param dev The device to find the resource on. |
| 540 | * @param index The index of the resource on the device. |
| 541 | * return TODO. |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 542 | */ |
| 543 | struct resource *find_resource(device_t dev, unsigned index) |
| 544 | { |
| 545 | struct resource *resource; |
| 546 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 547 | /* See if there is a resource with the appropriate index. */ |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 548 | resource = probe_resource(dev, index); |
| 549 | if (!resource) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 550 | printk(BIOS_EMERG, "%s missing resource: %02x\n", |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 551 | dev_path(dev), index); |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 552 | die(""); |
| 553 | } |
| 554 | return resource; |
| 555 | } |
| 556 | |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 557 | /** |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 558 | * Round a number up to the next multiple of gran. |
| 559 | * |
| 560 | * @param val The starting value. |
| 561 | * @param gran Granularity we are aligning the number to. |
| 562 | * @return The aligned value. |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 563 | */ |
| 564 | static resource_t align_up(resource_t val, unsigned long gran) |
| 565 | { |
| 566 | resource_t mask; |
| 567 | mask = (1ULL << gran) - 1ULL; |
| 568 | val += mask; |
| 569 | val &= ~mask; |
| 570 | return val; |
| 571 | } |
| 572 | |
| 573 | /** |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 574 | * Round a number up to the previous multiple of gran. |
| 575 | * |
| 576 | * @param val The starting value. |
| 577 | * @param gran Granularity we are aligning the number to. |
| 578 | * @return The aligned value. |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 579 | */ |
| 580 | static resource_t align_down(resource_t val, unsigned long gran) |
| 581 | { |
| 582 | resource_t mask; |
| 583 | mask = (1ULL << gran) - 1ULL; |
| 584 | val &= ~mask; |
| 585 | return val; |
| 586 | } |
| 587 | |
| 588 | /** |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 589 | * Compute the maximum address that is part of a resource. |
| 590 | * |
| 591 | * @param resource The resource whose limit is desired. |
| 592 | * @return The end. |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 593 | */ |
| 594 | resource_t resource_end(struct resource *resource) |
| 595 | { |
| 596 | resource_t base, end; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 597 | |
| 598 | /* Get the base address. */ |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 599 | base = resource->base; |
| 600 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 601 | /* |
| 602 | * For a non bridge resource granularity and alignment are the same. |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 603 | * For a bridge resource align is the largest needed alignment below |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 604 | * the bridge. While the granularity is simply how many low bits of |
| 605 | * the address cannot be set. |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 606 | */ |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 607 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 608 | /* Get the end (rounded up). */ |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 609 | end = base + align_up(resource->size, resource->gran) - 1; |
| 610 | |
| 611 | return end; |
| 612 | } |
| 613 | |
| 614 | /** |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 615 | * Compute the maximum legal value for resource->base. |
| 616 | * |
| 617 | * @param resource The resource whose maximum is desired. |
| 618 | * @return The maximum. |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 619 | */ |
| 620 | resource_t resource_max(struct resource *resource) |
| 621 | { |
| 622 | resource_t max; |
| 623 | |
| 624 | max = align_down(resource->limit - resource->size + 1, resource->align); |
| 625 | |
| 626 | return max; |
| 627 | } |
| 628 | |
| 629 | /** |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 630 | * Return the resource type of a resource. |
| 631 | * |
| 632 | * @param resource The resource type to decode. |
| 633 | * @return TODO. |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 634 | */ |
| 635 | const char *resource_type(struct resource *resource) |
| 636 | { |
| 637 | static char buffer[RESOURCE_TYPE_MAX]; |
Vladimir Serbinenko | a37383d | 2013-11-26 02:41:26 +0100 | [diff] [blame] | 638 | snprintf(buffer, sizeof (buffer), "%s%s%s%s", |
| 639 | ((resource->flags & IORESOURCE_READONLY) ? "ro" : ""), |
| 640 | ((resource->flags & IORESOURCE_PREFETCH) ? "pref" : ""), |
| 641 | ((resource->flags == 0) ? "unused" : |
| 642 | (resource->flags & IORESOURCE_IO) ? "io" : |
| 643 | (resource->flags & IORESOURCE_DRQ) ? "drq" : |
| 644 | (resource->flags & IORESOURCE_IRQ) ? "irq" : |
| 645 | (resource->flags & IORESOURCE_MEM) ? "mem" : "??????"), |
| 646 | ((resource->flags & IORESOURCE_PCI64) ? "64" : "")); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 647 | return buffer; |
| 648 | } |
| 649 | |
| 650 | /** |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 651 | * Print the resource that was just stored. |
| 652 | * |
Martin Roth | 63373ed | 2013-07-08 16:24:19 -0600 | [diff] [blame] | 653 | * @param dev The device the stored resource lives on. |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 654 | * @param resource The resource that was just stored. |
| 655 | * @param comment TODO |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 656 | */ |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 657 | void report_resource_stored(device_t dev, struct resource *resource, |
| 658 | const char *comment) |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 659 | { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 660 | char buf[10]; |
| 661 | unsigned long long base, end; |
| 662 | |
| 663 | if (!(resource->flags & IORESOURCE_STORED)) |
| 664 | return; |
| 665 | |
| 666 | base = resource->base; |
| 667 | end = resource_end(resource); |
| 668 | buf[0] = '\0'; |
| 669 | |
| 670 | if (resource->flags & IORESOURCE_PCI_BRIDGE) { |
Vladimir Serbinenko | a37383d | 2013-11-26 02:41:26 +0100 | [diff] [blame] | 671 | snprintf(buf, sizeof (buf), |
| 672 | "bus %02x ", dev->link_list->secondary); |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 673 | } |
Patrick Georgi | 5161509 | 2012-03-11 19:31:03 +0100 | [diff] [blame] | 674 | printk(BIOS_DEBUG, "%s %02lx <- [0x%010llx - 0x%010llx] size 0x%08llx " |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 675 | "gran 0x%02x %s%s%s\n", dev_path(dev), resource->index, |
| 676 | base, end, resource->size, resource->gran, buf, |
| 677 | resource_type(resource), comment); |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 678 | } |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 679 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 680 | void search_bus_resources(struct bus *bus, unsigned long type_mask, |
| 681 | unsigned long type, resource_search_t search, |
| 682 | void *gp) |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 683 | { |
| 684 | struct device *curdev; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 685 | |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 686 | for (curdev = bus->children; curdev; curdev = curdev->sibling) { |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 687 | struct resource *res; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 688 | |
| 689 | /* Ignore disabled devices. */ |
| 690 | if (!curdev->enabled) |
| 691 | continue; |
| 692 | |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 693 | for (res = curdev->resource_list; res; res = res->next) { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 694 | /* If it isn't the right kind of resource ignore it. */ |
| 695 | if ((res->flags & type_mask) != type) |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 696 | continue; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 697 | |
| 698 | /* If it is a subtractive resource recurse. */ |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 699 | if (res->flags & IORESOURCE_SUBTRACTIVE) { |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 700 | struct bus * subbus; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 701 | for (subbus = curdev->link_list; subbus; |
| 702 | subbus = subbus->next) |
| 703 | if (subbus->link_num |
| 704 | == IOINDEX_SUBTRACTIVE_LINK(res->index)) |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 705 | break; |
Stefan Reinauer | 5807555 | 2011-05-11 15:57:07 -0700 | [diff] [blame] | 706 | if (!subbus) /* Why can subbus be NULL? */ |
| 707 | break; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 708 | search_bus_resources(subbus, type_mask, type, |
| 709 | search, gp); |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 710 | continue; |
| 711 | } |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 712 | search(gp, curdev, res); |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 713 | } |
| 714 | } |
| 715 | } |
| 716 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 717 | void search_global_resources(unsigned long type_mask, unsigned long type, |
| 718 | resource_search_t search, void *gp) |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 719 | { |
| 720 | struct device *curdev; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 721 | |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 722 | for (curdev = all_devices; curdev; curdev = curdev->next) { |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 723 | struct resource *res; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 724 | |
| 725 | /* Ignore disabled devices. */ |
| 726 | if (!curdev->enabled) |
| 727 | continue; |
| 728 | |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 729 | for (res = curdev->resource_list; res; res = res->next) { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 730 | /* If it isn't the right kind of resource ignore it. */ |
| 731 | if ((res->flags & type_mask) != type) |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 732 | continue; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 733 | |
| 734 | /* If it is a subtractive resource ignore it. */ |
| 735 | if (res->flags & IORESOURCE_SUBTRACTIVE) |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 736 | continue; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 737 | |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 738 | search(gp, curdev, res); |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 739 | } |
| 740 | } |
| 741 | } |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 742 | |
| 743 | void dev_set_enabled(device_t dev, int enable) |
| 744 | { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 745 | if (dev->enabled == enable) |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 746 | return; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 747 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 748 | dev->enabled = enable; |
| 749 | if (dev->ops && dev->ops->enable) { |
| 750 | dev->ops->enable(dev); |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 751 | } else if (dev->chip_ops && dev->chip_ops->enable_dev) { |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 752 | dev->chip_ops->enable_dev(dev); |
| 753 | } |
| 754 | } |
| 755 | |
| 756 | void disable_children(struct bus *bus) |
| 757 | { |
| 758 | device_t child; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 759 | |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 760 | for (child = bus->children; child; child = child->sibling) { |
| 761 | struct bus *link; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 762 | for (link = child->link_list; link; link = link->next) |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 763 | disable_children(link); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 764 | dev_set_enabled(child, 0); |
| 765 | } |
| 766 | } |
Myles Watson | bb3d812 | 2009-05-11 22:45:35 +0000 | [diff] [blame] | 767 | |
Maciej Pijanka | ea92185 | 2009-10-27 14:29:29 +0000 | [diff] [blame] | 768 | static void resource_tree(struct device *root, int debug_level, int depth) |
Myles Watson | bb3d812 | 2009-05-11 22:45:35 +0000 | [diff] [blame] | 769 | { |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 770 | int i = 0; |
Myles Watson | bb3d812 | 2009-05-11 22:45:35 +0000 | [diff] [blame] | 771 | struct device *child; |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 772 | struct bus *link; |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 773 | struct resource *res; |
Myles Watson | bb3d812 | 2009-05-11 22:45:35 +0000 | [diff] [blame] | 774 | char indent[30]; /* If your tree has more levels, it's wrong. */ |
| 775 | |
| 776 | for (i = 0; i < depth + 1 && i < 29; i++) |
| 777 | indent[i] = ' '; |
| 778 | indent[i] = '\0'; |
| 779 | |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 780 | do_printk(BIOS_DEBUG, "%s%s", indent, dev_path(root)); |
| 781 | if (root->link_list && root->link_list->children) |
| 782 | do_printk(BIOS_DEBUG, " child on link 0 %s", |
| 783 | dev_path(root->link_list->children)); |
| 784 | do_printk(BIOS_DEBUG, "\n"); |
| 785 | |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 786 | for (res = root->resource_list; res; res = res->next) { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 787 | do_printk(debug_level, "%s%s resource base %llx size %llx " |
| 788 | "align %d gran %d limit %llx flags %lx index %lx\n", |
| 789 | indent, dev_path(root), res->base, res->size, |
| 790 | res->align, res->gran, res->limit, res->flags, |
| 791 | res->index); |
Myles Watson | bb3d812 | 2009-05-11 22:45:35 +0000 | [diff] [blame] | 792 | } |
| 793 | |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 794 | for (link = root->link_list; link; link = link->next) { |
| 795 | for (child = link->children; child; child = child->sibling) |
Myles Watson | bb3d812 | 2009-05-11 22:45:35 +0000 | [diff] [blame] | 796 | resource_tree(child, debug_level, depth + 1); |
| 797 | } |
| 798 | } |
| 799 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 800 | void print_resource_tree(struct device *root, int debug_level, const char *msg) |
Myles Watson | bb3d812 | 2009-05-11 22:45:35 +0000 | [diff] [blame] | 801 | { |
| 802 | /* Bail if root is null. */ |
| 803 | if (!root) { |
| 804 | do_printk(debug_level, "%s passed NULL for root!\n", __func__); |
| 805 | return; |
| 806 | } |
| 807 | |
| 808 | /* Bail if not printing to screen. */ |
| 809 | if (!do_printk(debug_level, "Show resources in subtree (%s)...%s\n", |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 810 | dev_path(root), msg)) |
Myles Watson | bb3d812 | 2009-05-11 22:45:35 +0000 | [diff] [blame] | 811 | return; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 812 | |
Myles Watson | bb3d812 | 2009-05-11 22:45:35 +0000 | [diff] [blame] | 813 | resource_tree(root, debug_level, 0); |
| 814 | } |
| 815 | |
| 816 | void show_devs_tree(struct device *dev, int debug_level, int depth, int linknum) |
| 817 | { |
Marcelo Povoa | 8404dca | 2014-02-14 15:42:49 -0800 | [diff] [blame] | 818 | char depth_str[20]; |
Myles Watson | bb3d812 | 2009-05-11 22:45:35 +0000 | [diff] [blame] | 819 | int i; |
| 820 | struct device *sibling; |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 821 | struct bus *link; |
| 822 | |
Myles Watson | bb3d812 | 2009-05-11 22:45:35 +0000 | [diff] [blame] | 823 | for (i = 0; i < depth; i++) |
| 824 | depth_str[i] = ' '; |
| 825 | depth_str[i] = '\0'; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 826 | |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 827 | do_printk(debug_level, "%s%s: enabled %d\n", |
| 828 | depth_str, dev_path(dev), dev->enabled); |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 829 | |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 830 | for (link = dev->link_list; link; link = link->next) { |
| 831 | for (sibling = link->children; sibling; |
Myles Watson | bb3d812 | 2009-05-11 22:45:35 +0000 | [diff] [blame] | 832 | sibling = sibling->sibling) |
| 833 | show_devs_tree(sibling, debug_level, depth + 1, i); |
| 834 | } |
| 835 | } |
| 836 | |
| 837 | void show_all_devs_tree(int debug_level, const char *msg) |
| 838 | { |
| 839 | /* Bail if not printing to screen. */ |
Paul Menzel | eb605d7 | 2015-02-12 00:29:32 +0100 | [diff] [blame] | 840 | if (!do_printk(debug_level, "Show all devs in tree form... %s\n", msg)) |
Myles Watson | bb3d812 | 2009-05-11 22:45:35 +0000 | [diff] [blame] | 841 | return; |
| 842 | show_devs_tree(all_devices, debug_level, 0, -1); |
| 843 | } |
| 844 | |
| 845 | void show_devs_subtree(struct device *root, int debug_level, const char *msg) |
| 846 | { |
| 847 | /* Bail if not printing to screen. */ |
Paul Menzel | eb605d7 | 2015-02-12 00:29:32 +0100 | [diff] [blame] | 848 | if (!do_printk(debug_level, "Show all devs in subtree %s... %s\n", |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 849 | dev_path(root), msg)) |
Myles Watson | bb3d812 | 2009-05-11 22:45:35 +0000 | [diff] [blame] | 850 | return; |
| 851 | do_printk(debug_level, "%s\n", msg); |
| 852 | show_devs_tree(root, debug_level, 0, -1); |
| 853 | } |
| 854 | |
| 855 | void show_all_devs(int debug_level, const char *msg) |
| 856 | { |
| 857 | struct device *dev; |
| 858 | |
| 859 | /* Bail if not printing to screen. */ |
Paul Menzel | eb605d7 | 2015-02-12 00:29:32 +0100 | [diff] [blame] | 860 | if (!do_printk(debug_level, "Show all devs... %s\n", msg)) |
Myles Watson | bb3d812 | 2009-05-11 22:45:35 +0000 | [diff] [blame] | 861 | return; |
| 862 | for (dev = all_devices; dev; dev = dev->next) { |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 863 | do_printk(debug_level, "%s: enabled %d\n", |
| 864 | dev_path(dev), dev->enabled); |
Myles Watson | bb3d812 | 2009-05-11 22:45:35 +0000 | [diff] [blame] | 865 | } |
| 866 | } |
| 867 | |
| 868 | void show_one_resource(int debug_level, struct device *dev, |
| 869 | struct resource *resource, const char *comment) |
| 870 | { |
| 871 | char buf[10]; |
| 872 | unsigned long long base, end; |
| 873 | base = resource->base; |
| 874 | end = resource_end(resource); |
| 875 | buf[0] = '\0'; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 876 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 877 | do_printk(debug_level, "%s %02lx <- [0x%010llx - 0x%010llx] " |
Patrick Georgi | 5161509 | 2012-03-11 19:31:03 +0100 | [diff] [blame] | 878 | "size 0x%08llx gran 0x%02x %s%s%s\n", dev_path(dev), |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 879 | resource->index, base, end, resource->size, resource->gran, |
| 880 | buf, resource_type(resource), comment); |
Myles Watson | bb3d812 | 2009-05-11 22:45:35 +0000 | [diff] [blame] | 881 | } |
| 882 | |
| 883 | void show_all_devs_resources(int debug_level, const char* msg) |
| 884 | { |
| 885 | struct device *dev; |
| 886 | |
Paul Menzel | eb605d7 | 2015-02-12 00:29:32 +0100 | [diff] [blame] | 887 | if (!do_printk(debug_level, "Show all devs with resources... %s\n", msg)) |
Myles Watson | bb3d812 | 2009-05-11 22:45:35 +0000 | [diff] [blame] | 888 | return; |
| 889 | |
| 890 | for (dev = all_devices; dev; dev = dev->next) { |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 891 | struct resource *res; |
| 892 | do_printk(debug_level, "%s: enabled %d\n", |
| 893 | dev_path(dev), dev->enabled); |
| 894 | for (res = dev->resource_list; res; res = res->next) |
| 895 | show_one_resource(debug_level, dev, res, ""); |
Myles Watson | bb3d812 | 2009-05-11 22:45:35 +0000 | [diff] [blame] | 896 | } |
| 897 | } |
Uwe Hermann | 4b42a62 | 2010-10-11 19:36:13 +0000 | [diff] [blame] | 898 | |
Kyösti Mälkki | ecf1ed4 | 2012-07-27 08:37:12 +0300 | [diff] [blame] | 899 | void fixed_mem_resource(device_t dev, unsigned long index, |
| 900 | unsigned long basek, unsigned long sizek, unsigned long type) |
Uwe Hermann | 4b42a62 | 2010-10-11 19:36:13 +0000 | [diff] [blame] | 901 | { |
| 902 | struct resource *resource; |
| 903 | |
| 904 | if (!sizek) |
| 905 | return; |
| 906 | |
| 907 | resource = new_resource(dev, index); |
| 908 | resource->base = ((resource_t)basek) << 10; |
| 909 | resource->size = ((resource_t)sizek) << 10; |
Kyösti Mälkki | ecf1ed4 | 2012-07-27 08:37:12 +0300 | [diff] [blame] | 910 | resource->flags = IORESOURCE_MEM | IORESOURCE_FIXED | |
| 911 | IORESOURCE_STORED | IORESOURCE_ASSIGNED; |
Uwe Hermann | 4b42a62 | 2010-10-11 19:36:13 +0000 | [diff] [blame] | 912 | |
Kyösti Mälkki | ecf1ed4 | 2012-07-27 08:37:12 +0300 | [diff] [blame] | 913 | resource->flags |= type; |
Kyösti Mälkki | 63f8c08 | 2012-07-10 13:27:26 +0300 | [diff] [blame] | 914 | } |
| 915 | |
Kyösti Mälkki | e25b5ef | 2016-12-02 08:56:05 +0200 | [diff] [blame] | 916 | void mmconf_resource_init(struct resource *resource, resource_t base, |
| 917 | int buses) |
| 918 | { |
| 919 | resource->base = base; |
| 920 | resource->size = buses * MiB; |
| 921 | resource->flags = IORESOURCE_MEM | IORESOURCE_RESERVE | |
| 922 | IORESOURCE_FIXED | IORESOURCE_STORED | IORESOURCE_ASSIGNED; |
| 923 | |
| 924 | printk(BIOS_DEBUG, "Adding PCIe enhanced config space BAR " |
| 925 | "0x%08lx-0x%08lx.\n", (unsigned long)(resource->base), |
| 926 | (unsigned long)(resource->base + resource->size)); |
| 927 | } |
| 928 | |
| 929 | void mmconf_resource(struct device *dev, unsigned long index) |
| 930 | { |
| 931 | struct resource *resource = new_resource(dev, index); |
| 932 | mmconf_resource_init(resource, CONFIG_MMCONF_BASE_ADDRESS, |
| 933 | CONFIG_MMCONF_BUS_NUMBER); |
| 934 | } |
| 935 | |
Uwe Hermann | 4b42a62 | 2010-10-11 19:36:13 +0000 | [diff] [blame] | 936 | void tolm_test(void *gp, struct device *dev, struct resource *new) |
| 937 | { |
| 938 | struct resource **best_p = gp; |
| 939 | struct resource *best; |
| 940 | |
| 941 | best = *best_p; |
| 942 | |
| 943 | if (!best || (best->base > new->base)) |
| 944 | best = new; |
| 945 | |
| 946 | *best_p = best; |
| 947 | } |
| 948 | |
| 949 | u32 find_pci_tolm(struct bus *bus) |
| 950 | { |
| 951 | struct resource *min = NULL; |
| 952 | u32 tolm; |
| 953 | |
| 954 | search_bus_resources(bus, IORESOURCE_MEM, IORESOURCE_MEM, |
| 955 | tolm_test, &min); |
| 956 | |
| 957 | tolm = 0xffffffffUL; |
| 958 | |
| 959 | if (min && tolm > min->base) |
| 960 | tolm = min->base; |
| 961 | |
| 962 | return tolm; |
| 963 | } |
Stefan Reinauer | dc8448fd | 2012-03-30 13:52:58 -0700 | [diff] [blame] | 964 | |
| 965 | /* Count of enabled CPUs */ |
| 966 | int dev_count_cpu(void) |
| 967 | { |
| 968 | device_t cpu; |
| 969 | int count = 0; |
| 970 | |
| 971 | for (cpu = all_devices; cpu; cpu = cpu->next) { |
| 972 | if ((cpu->path.type != DEVICE_PATH_APIC) || |
Stefan Reinauer | 0aa37c4 | 2013-02-12 15:20:54 -0800 | [diff] [blame] | 973 | (cpu->bus->dev->path.type != DEVICE_PATH_CPU_CLUSTER)) |
Stefan Reinauer | dc8448fd | 2012-03-30 13:52:58 -0700 | [diff] [blame] | 974 | continue; |
| 975 | if (!cpu->enabled) |
| 976 | continue; |
| 977 | count++; |
| 978 | } |
| 979 | |
| 980 | return count; |
| 981 | } |
Lee Leahy | a95baf9 | 2016-02-13 06:10:04 -0800 | [diff] [blame] | 982 | |
| 983 | /* Get device path name */ |
| 984 | const char *dev_path_name(enum device_path_type type) |
| 985 | { |
| 986 | static const char *const type_names[] = DEVICE_PATH_NAMES; |
| 987 | const char *type_name = "Unknown"; |
| 988 | |
| 989 | /* Translate the type value into a string */ |
| 990 | if (type < ARRAY_SIZE(type_names)) |
| 991 | type_name = type_names[type]; |
| 992 | return type_name; |
| 993 | } |