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