blob: ac18538a1b1211a26e8b8f1d9c8309652446f411 [file] [log] [blame]
Uwe Hermannb80dbf02007-04-22 19:08:13 +00001/*
Stefan Reinauer7e61e452008-01-18 10:35:56 +00002 * This file is part of the coreboot project.
Uwe Hermannb80dbf02007-04-22 19:08:13 +00003 *
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 Hermannb80dbf02007-04-22 19:08:13 +000019 */
20
Eric Biederman8ca8d762003-04-22 19:02:15 +000021#include <console/console.h>
Eric Biederman5899fd82003-04-24 06:25:08 +000022#include <device/device.h>
Eric Biedermane9a271e32003-09-02 03:36:25 +000023#include <device/path.h>
Kyösti Mälkki318066f2014-02-12 14:18:50 +020024#include <device/pci_def.h>
Eric Biedermanf8a2ddd2004-10-30 08:05:41 +000025#include <device/resource.h>
Eric Biedermane9a271e32003-09-02 03:36:25 +000026#include <string.h>
27
Eric Biederman03acab62004-10-14 21:25:53 +000028/**
Uwe Hermannc1ee4292010-10-17 19:01:48 +000029 * See if a device structure exists for path.
Eric Biederman03acab62004-10-14 21:25:53 +000030 *
Uwe Hermannc1ee4292010-10-17 19:01:48 +000031 * @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 Biederman03acab62004-10-14 21:25:53 +000035 */
36device_t find_dev_path(struct bus *parent, struct device_path *path)
37{
38 device_t child;
Myles Watson894a3472010-06-09 22:41:35 +000039 for (child = parent->children; child; child = child->sibling) {
Uwe Hermanne4870472010-11-04 23:23:47 +000040 if (path_eq(path, &child->path))
Eric Biederman03acab62004-10-14 21:25:53 +000041 break;
Eric Biederman03acab62004-10-14 21:25:53 +000042 }
43 return child;
44}
Eric Biedermane9a271e32003-09-02 03:36:25 +000045
46/**
Uwe Hermannc1ee4292010-10-17 19:01:48 +000047 * Given a PCI bus and a devfn number, find the device structure.
Li-Ta Loe8b1c9d2004-12-27 04:25:41 +000048 *
Uwe Hermannc1ee4292010-10-17 19:01:48 +000049 * @param bus The bus number.
50 * @param devfn A device/function number.
51 * @return Pointer to the device structure (if found), 0 otherwise.
Eric Biederman8ca8d762003-04-22 19:02:15 +000052 */
53struct device *dev_find_slot(unsigned int bus, unsigned int devfn)
54{
Eric Biederman83b991a2003-10-11 06:20:25 +000055 struct device *dev, *result;
Eric Biederman8ca8d762003-04-22 19:02:15 +000056
Eric Biederman83b991a2003-10-11 06:20:25 +000057 result = 0;
Eric Biedermane9a271e32003-09-02 03:36:25 +000058 for (dev = all_devices; dev; dev = dev->next) {
Eric Biederman5cd81732004-03-11 15:01:31 +000059 if ((dev->path.type == DEVICE_PATH_PCI) &&
Uwe Hermanne4870472010-11-04 23:23:47 +000060 (dev->bus->secondary == bus) &&
61 (dev->path.pci.devfn == devfn)) {
Eric Biederman83b991a2003-10-11 06:20:25 +000062 result = dev;
Eric Biederman8ca8d762003-04-22 19:02:15 +000063 break;
Eric Biedermane9a271e32003-09-02 03:36:25 +000064 }
65 }
Eric Biederman83b991a2003-10-11 06:20:25 +000066 return result;
Eric Biederman8ca8d762003-04-22 19:02:15 +000067}
68
arch import user (historical)98d0d302005-07-06 17:13:46 +000069/**
Uwe Hermannc1ee4292010-10-17 19:01:48 +000070 * Given an SMBus bus and a device number, find the device structure.
arch import user (historical)98d0d302005-07-06 17:13:46 +000071 *
Uwe Hermannc1ee4292010-10-17 19:01:48 +000072 * @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)98d0d302005-07-06 17:13:46 +000075 */
76struct device *dev_find_slot_on_smbus(unsigned int bus, unsigned int addr)
77{
Uwe Hermanne4870472010-11-04 23:23:47 +000078 struct device *dev, *result;
Stefan Reinauer14e22772010-04-27 06:56:47 +000079
Uwe Hermanne4870472010-11-04 23:23:47 +000080 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 Reinauer14e22772010-04-27 06:56:47 +000090}
arch import user (historical)98d0d302005-07-06 17:13:46 +000091
Uwe Hermannc1ee4292010-10-17 19:01:48 +000092/**
Vladimir Serbinenko400c05c2014-02-04 14:34:11 +010093 * 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 Serbinenkob33384a2014-02-08 18:58:39 +010099struct device *dev_find_slot_pnp(u16 port, u16 device)
Vladimir Serbinenko400c05c2014-02-04 14:34:11 +0100100{
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 Laurie6f88a6e2011-07-18 10:41:36 -0700114 * 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 */
119device_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/**
Uwe Hermannc1ee4292010-10-17 19:01:48 +0000134 * Find a device of a given vendor and type.
135 *
136 * @param vendor A PCI vendor ID (e.g. 0x8086 for Intel).
137 * @param device A PCI device ID.
Uwe Hermanne4870472010-11-04 23:23:47 +0000138 * @param from Pointer to the device structure, used as a starting point in
139 * the linked list of all_devices, which can be 0 to start at the
140 * head of the list (i.e. all_devices).
Uwe Hermannc1ee4292010-10-17 19:01:48 +0000141 * @return Pointer to the device struct.
Eric Biederman8ca8d762003-04-22 19:02:15 +0000142 */
Uwe Hermanne4870472010-11-04 23:23:47 +0000143struct device *dev_find_device(u16 vendor, u16 device, struct device *from)
Eric Biederman8ca8d762003-04-22 19:02:15 +0000144{
145 if (!from)
146 from = all_devices;
147 else
148 from = from->next;
Uwe Hermanne4870472010-11-04 23:23:47 +0000149
150 while (from && (from->vendor != vendor || from->device != device))
Eric Biederman8ca8d762003-04-22 19:02:15 +0000151 from = from->next;
Uwe Hermanne4870472010-11-04 23:23:47 +0000152
Eric Biederman8ca8d762003-04-22 19:02:15 +0000153 return from;
154}
155
Uwe Hermannc1ee4292010-10-17 19:01:48 +0000156/**
157 * Find a device of a given class.
158 *
159 * @param class Class of the device.
Uwe Hermanne4870472010-11-04 23:23:47 +0000160 * @param from Pointer to the device structure, used as a starting point in
161 * the linked list of all_devices, which can be 0 to start at the
162 * head of the list (i.e. all_devices).
Uwe Hermannc1ee4292010-10-17 19:01:48 +0000163 * @return Pointer to the device struct.
Eric Biederman8ca8d762003-04-22 19:02:15 +0000164 */
165struct device *dev_find_class(unsigned int class, struct device *from)
166{
167 if (!from)
168 from = all_devices;
169 else
170 from = from->next;
Uwe Hermanne4870472010-11-04 23:23:47 +0000171
Greg Watson59651692003-12-17 17:39:53 +0000172 while (from && (from->class & 0xffffff00) != class)
Eric Biederman8ca8d762003-04-22 19:02:15 +0000173 from = from->next;
Uwe Hermanne4870472010-11-04 23:23:47 +0000174
Eric Biederman8ca8d762003-04-22 19:02:15 +0000175 return from;
176}
177
Duncan Laurie5f5d9142013-06-10 09:59:17 -0700178/**
179 * Encode the device path into 3 bytes for logging to CMOS.
180 *
181 * @param dev The device path to encode.
182 * @return Device path encoded into lower 3 bytes of dword.
183 */
184u32 dev_path_encode(device_t dev)
185{
186 u32 ret;
187
188 if (!dev)
189 return 0;
190
191 /* Store the device type in 3rd byte. */
192 ret = dev->path.type << 16;
193
194 /* Encode the device specific path in the low word. */
195 switch (dev->path.type) {
196 case DEVICE_PATH_ROOT:
197 break;
198 case DEVICE_PATH_PCI:
199 ret |= dev->bus->secondary << 8 | dev->path.pci.devfn;
200 break;
201 case DEVICE_PATH_PNP:
202 ret |= dev->path.pnp.port << 8 | dev->path.pnp.device;
203 break;
204 case DEVICE_PATH_I2C:
205 ret |= dev->bus->secondary << 8 | dev->path.pnp.device;
206 break;
207 case DEVICE_PATH_APIC:
208 ret |= dev->path.apic.apic_id;
209 break;
210 case DEVICE_PATH_DOMAIN:
211 ret |= dev->path.domain.domain;
212 break;
213 case DEVICE_PATH_CPU_CLUSTER:
214 ret |= dev->path.cpu_cluster.cluster;
215 break;
216 case DEVICE_PATH_CPU:
217 ret |= dev->path.cpu.id;
218 break;
219 case DEVICE_PATH_CPU_BUS:
220 ret |= dev->path.cpu_bus.id;
221 break;
222 case DEVICE_PATH_IOAPIC:
223 ret |= dev->path.ioapic.ioapic_id;
224 break;
225 case DEVICE_PATH_NONE:
226 default:
227 break;
228 }
229
230 return ret;
231}
232
Uwe Hermannc1ee4292010-10-17 19:01:48 +0000233/*
234 * Warning: This function uses a static buffer. Don't call it more than once
235 * from the same print statement!
236 */
Eric Biedermane9a271e32003-09-02 03:36:25 +0000237const char *dev_path(device_t dev)
238{
239 static char buffer[DEVICE_PATH_MAX];
Uwe Hermannc1ee4292010-10-17 19:01:48 +0000240
Eric Biedermane9a271e32003-09-02 03:36:25 +0000241 buffer[0] = '\0';
242 if (!dev) {
243 memcpy(buffer, "<null>", 7);
Uwe Hermanne4870472010-11-04 23:23:47 +0000244 } else {
Eric Biedermane9a271e32003-09-02 03:36:25 +0000245 switch(dev->path.type) {
Eric Biederman83b991a2003-10-11 06:20:25 +0000246 case DEVICE_PATH_ROOT:
247 memcpy(buffer, "Root Device", 12);
248 break;
Eric Biedermane9a271e32003-09-02 03:36:25 +0000249 case DEVICE_PATH_PCI:
Vladimir Serbinenkoa37383d2013-11-26 02:41:26 +0100250 snprintf(buffer, sizeof (buffer),
251 "PCI: %02x:%02x.%01x",
252 dev->bus->secondary,
253 PCI_SLOT(dev->path.pci.devfn),
254 PCI_FUNC(dev->path.pci.devfn));
Eric Biedermane9a271e32003-09-02 03:36:25 +0000255 break;
256 case DEVICE_PATH_PNP:
Vladimir Serbinenkoa37383d2013-11-26 02:41:26 +0100257 snprintf(buffer, sizeof (buffer), "PNP: %04x.%01x",
258 dev->path.pnp.port, dev->path.pnp.device);
Eric Biedermane9a271e32003-09-02 03:36:25 +0000259 break;
260 case DEVICE_PATH_I2C:
Vladimir Serbinenkoa37383d2013-11-26 02:41:26 +0100261 snprintf(buffer, sizeof (buffer), "I2C: %02x:%02x",
262 dev->bus->secondary,
263 dev->path.i2c.device);
Eric Biedermane9a271e32003-09-02 03:36:25 +0000264 break;
Eric Biederman03acab62004-10-14 21:25:53 +0000265 case DEVICE_PATH_APIC:
Vladimir Serbinenkoa37383d2013-11-26 02:41:26 +0100266 snprintf(buffer, sizeof (buffer), "APIC: %02x",
267 dev->path.apic.apic_id);
Eric Biederman03acab62004-10-14 21:25:53 +0000268 break;
Sven Schnelle0fa50a12012-06-21 22:19:48 +0200269 case DEVICE_PATH_IOAPIC:
Vladimir Serbinenkoa37383d2013-11-26 02:41:26 +0100270 snprintf(buffer, sizeof (buffer), "IOAPIC: %02x",
271 dev->path.ioapic.ioapic_id);
Sven Schnelle0fa50a12012-06-21 22:19:48 +0200272 break;
Stefan Reinauer4aff4452013-02-12 14:17:15 -0800273 case DEVICE_PATH_DOMAIN:
Vladimir Serbinenkoa37383d2013-11-26 02:41:26 +0100274 snprintf(buffer, sizeof (buffer), "DOMAIN: %04x",
Stefan Reinauer4aff4452013-02-12 14:17:15 -0800275 dev->path.domain.domain);
Eric Biederman7003ba42004-10-16 06:20:29 +0000276 break;
Stefan Reinauer0aa37c42013-02-12 15:20:54 -0800277 case DEVICE_PATH_CPU_CLUSTER:
Vladimir Serbinenkoa37383d2013-11-26 02:41:26 +0100278 snprintf(buffer, sizeof (buffer), "CPU_CLUSTER: %01x",
Stefan Reinauer0aa37c42013-02-12 15:20:54 -0800279 dev->path.cpu_cluster.cluster);
Eric Biederman7003ba42004-10-16 06:20:29 +0000280 break;
Eric Biedermana9e632c2004-11-18 22:38:08 +0000281 case DEVICE_PATH_CPU:
Vladimir Serbinenkoa37383d2013-11-26 02:41:26 +0100282 snprintf(buffer, sizeof (buffer),
283 "CPU: %02x", dev->path.cpu.id);
Eric Biedermana9e632c2004-11-18 22:38:08 +0000284 break;
285 case DEVICE_PATH_CPU_BUS:
Vladimir Serbinenkoa37383d2013-11-26 02:41:26 +0100286 snprintf(buffer, sizeof (buffer),
287 "CPU_BUS: %02x", dev->path.cpu_bus.id);
Eric Biedermana9e632c2004-11-18 22:38:08 +0000288 break;
Eric Biedermane9a271e32003-09-02 03:36:25 +0000289 default:
Uwe Hermanne4870472010-11-04 23:23:47 +0000290 printk(BIOS_ERR, "Unknown device path type: %d\n",
291 dev->path.type);
Eric Biedermane9a271e32003-09-02 03:36:25 +0000292 break;
293 }
294 }
295 return buffer;
296}
297
Kyösti Mälkki7baadac2012-10-07 14:57:15 +0200298const char *dev_name(device_t dev)
299{
Kyösti Mälkki7d54eb82012-10-10 23:14:28 +0300300 if (dev->name)
301 return dev->name;
302 else if (dev->chip_ops && dev->chip_ops->name)
Kyösti Mälkki7baadac2012-10-07 14:57:15 +0200303 return dev->chip_ops->name;
304 else
305 return "unknown";
306}
307
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000308const char *bus_path(struct bus *bus)
309{
310 static char buffer[BUS_PATH_MAX];
Vladimir Serbinenkoa37383d2013-11-26 02:41:26 +0100311 snprintf(buffer, sizeof (buffer),
312 "%s,%d", dev_path(bus->dev), bus->link_num);
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000313 return buffer;
314}
315
Eric Biedermane9a271e32003-09-02 03:36:25 +0000316int path_eq(struct device_path *path1, struct device_path *path2)
317{
318 int equal = 0;
Uwe Hermanne4870472010-11-04 23:23:47 +0000319
320 if (path1->type != path2->type)
321 return 0;
322
323 switch (path1->type) {
324 case DEVICE_PATH_NONE:
325 break;
326 case DEVICE_PATH_ROOT:
327 equal = 1;
328 break;
329 case DEVICE_PATH_PCI:
330 equal = (path1->pci.devfn == path2->pci.devfn);
331 break;
332 case DEVICE_PATH_PNP:
333 equal = (path1->pnp.port == path2->pnp.port) &&
334 (path1->pnp.device == path2->pnp.device);
335 break;
336 case DEVICE_PATH_I2C:
337 equal = (path1->i2c.device == path2->i2c.device);
338 break;
339 case DEVICE_PATH_APIC:
340 equal = (path1->apic.apic_id == path2->apic.apic_id);
341 break;
Stefan Reinauer4aff4452013-02-12 14:17:15 -0800342 case DEVICE_PATH_DOMAIN:
343 equal = (path1->domain.domain == path2->domain.domain);
Uwe Hermanne4870472010-11-04 23:23:47 +0000344 break;
Stefan Reinauer0aa37c42013-02-12 15:20:54 -0800345 case DEVICE_PATH_CPU_CLUSTER:
346 equal = (path1->cpu_cluster.cluster
347 == path2->cpu_cluster.cluster);
Uwe Hermanne4870472010-11-04 23:23:47 +0000348 break;
349 case DEVICE_PATH_CPU:
350 equal = (path1->cpu.id == path2->cpu.id);
351 break;
352 case DEVICE_PATH_CPU_BUS:
353 equal = (path1->cpu_bus.id == path2->cpu_bus.id);
354 break;
355 default:
Martin Roth63373ed2013-07-08 16:24:19 -0600356 printk(BIOS_ERR, "Unknown device type: %d\n", path1->type);
Uwe Hermanne4870472010-11-04 23:23:47 +0000357 break;
Eric Biedermane9a271e32003-09-02 03:36:25 +0000358 }
Uwe Hermanne4870472010-11-04 23:23:47 +0000359
Eric Biedermane9a271e32003-09-02 03:36:25 +0000360 return equal;
361}
Eric Biederman5cd81732004-03-11 15:01:31 +0000362
363/**
Myles Watsonc25cc112010-05-21 14:33:48 +0000364 * Allocate 64 more resources to the free list.
Uwe Hermannc1ee4292010-10-17 19:01:48 +0000365 *
366 * @return TODO.
Myles Watsonc25cc112010-05-21 14:33:48 +0000367 */
368static int allocate_more_resources(void)
369{
370 int i;
371 struct resource *new_res_list;
Uwe Hermanne4870472010-11-04 23:23:47 +0000372
Myles Watsonc25cc112010-05-21 14:33:48 +0000373 new_res_list = malloc(64 * sizeof(*new_res_list));
374
375 if (new_res_list == NULL)
376 return 0;
377
378 memset(new_res_list, 0, 64 * sizeof(*new_res_list));
379
Uwe Hermanne4870472010-11-04 23:23:47 +0000380 for (i = 0; i < 64 - 1; i++)
Myles Watsonc25cc112010-05-21 14:33:48 +0000381 new_res_list[i].next = &new_res_list[i+1];
382
383 free_resources = new_res_list;
384 return 1;
385}
386
387/**
388 * Remove resource res from the device's list and add it to the free list.
Uwe Hermannc1ee4292010-10-17 19:01:48 +0000389 *
390 * @param dev TODO
391 * @param res TODO
392 * @param prev TODO
393 * @return TODO.
Myles Watsonc25cc112010-05-21 14:33:48 +0000394 */
Uwe Hermannc1ee4292010-10-17 19:01:48 +0000395static void free_resource(device_t dev, struct resource *res,
396 struct resource *prev)
Myles Watsonc25cc112010-05-21 14:33:48 +0000397{
398 if (prev)
399 prev->next = res->next;
400 else
401 dev->resource_list = res->next;
Uwe Hermanne4870472010-11-04 23:23:47 +0000402
Myles Watsonc25cc112010-05-21 14:33:48 +0000403 res->next = free_resources;
404 free_resources = res;
405}
406
407/**
Eric Biederman5cd81732004-03-11 15:01:31 +0000408 * See if we have unused but allocated resource structures.
Uwe Hermanne4870472010-11-04 23:23:47 +0000409 *
Eric Biederman5cd81732004-03-11 15:01:31 +0000410 * If so remove the allocation.
Uwe Hermannc1ee4292010-10-17 19:01:48 +0000411 *
412 * @param dev The device to find the resource on.
Eric Biederman5cd81732004-03-11 15:01:31 +0000413 */
414void compact_resources(device_t dev)
415{
Myles Watsonc25cc112010-05-21 14:33:48 +0000416 struct resource *res, *next, *prev = NULL;
Uwe Hermanne4870472010-11-04 23:23:47 +0000417
Eric Biederman5cd81732004-03-11 15:01:31 +0000418 /* Move all of the free resources to the end */
Myles Watson894a3472010-06-09 22:41:35 +0000419 for (res = dev->resource_list; res; res = next) {
Myles Watsonc25cc112010-05-21 14:33:48 +0000420 next = res->next;
421 if (!res->flags)
422 free_resource(dev, res, prev);
423 else
424 prev = res;
Eric Biederman5cd81732004-03-11 15:01:31 +0000425 }
426}
427
428/**
Uwe Hermannc1ee4292010-10-17 19:01:48 +0000429 * See if a resource structure already exists for a given index.
430 *
431 * @param dev The device to find the resource on.
432 * @param index The index of the resource on the device.
433 * @return The resource, if it already exists.
Eric Biederman5cd81732004-03-11 15:01:31 +0000434 */
Eric Biederman03acab62004-10-14 21:25:53 +0000435struct resource *probe_resource(device_t dev, unsigned index)
Eric Biederman5cd81732004-03-11 15:01:31 +0000436{
Myles Watsonc25cc112010-05-21 14:33:48 +0000437 struct resource *res;
Uwe Hermannc1ee4292010-10-17 19:01:48 +0000438
Eric Biederman5cd81732004-03-11 15:01:31 +0000439 /* See if there is a resource with the appropriate index */
Myles Watson894a3472010-06-09 22:41:35 +0000440 for (res = dev->resource_list; res; res = res->next) {
Myles Watsonc25cc112010-05-21 14:33:48 +0000441 if (res->index == index)
Eric Biederman5cd81732004-03-11 15:01:31 +0000442 break;
Eric Biederman5cd81732004-03-11 15:01:31 +0000443 }
Uwe Hermanne4870472010-11-04 23:23:47 +0000444
Myles Watsonc25cc112010-05-21 14:33:48 +0000445 return res;
Eric Biederman03acab62004-10-14 21:25:53 +0000446}
447
448/**
Uwe Hermannc1ee4292010-10-17 19:01:48 +0000449 * See if a resource structure already exists for a given index and if not
450 * allocate one.
451 *
Paul Menzel20923872014-06-07 13:31:29 +0200452 * Then initialize the resource to default values.
Uwe Hermannc1ee4292010-10-17 19:01:48 +0000453 *
454 * @param dev The device to find the resource on.
455 * @param index The index of the resource on the device.
456 * @return TODO.
Eric Biederman03acab62004-10-14 21:25:53 +0000457 */
458struct resource *new_resource(device_t dev, unsigned index)
459{
Myles Watsonc25cc112010-05-21 14:33:48 +0000460 struct resource *resource, *tail;
Eric Biederman03acab62004-10-14 21:25:53 +0000461
Uwe Hermanne4870472010-11-04 23:23:47 +0000462 /* First move all of the free resources to the end. */
Eric Biederman03acab62004-10-14 21:25:53 +0000463 compact_resources(dev);
464
Uwe Hermanne4870472010-11-04 23:23:47 +0000465 /* See if there is a resource with the appropriate index. */
Eric Biederman03acab62004-10-14 21:25:53 +0000466 resource = probe_resource(dev, index);
Eric Biederman5cd81732004-03-11 15:01:31 +0000467 if (!resource) {
Myles Watsonc25cc112010-05-21 14:33:48 +0000468 if (free_resources == NULL && !allocate_more_resources())
469 die("Couldn't allocate more resources.");
470
471 resource = free_resources;
472 free_resources = free_resources->next;
Eric Biederman5cd81732004-03-11 15:01:31 +0000473 memset(resource, 0, sizeof(*resource));
Myles Watsonc25cc112010-05-21 14:33:48 +0000474 resource->next = NULL;
475 tail = dev->resource_list;
476 if (tail) {
477 while (tail->next) tail = tail->next;
478 tail->next = resource;
Uwe Hermanne4870472010-11-04 23:23:47 +0000479 } else {
Myles Watsonc25cc112010-05-21 14:33:48 +0000480 dev->resource_list = resource;
Uwe Hermanne4870472010-11-04 23:23:47 +0000481 }
Eric Biederman5cd81732004-03-11 15:01:31 +0000482 }
Uwe Hermanne4870472010-11-04 23:23:47 +0000483
484 /* Initialize the resource values. */
Eric Biederman5cd81732004-03-11 15:01:31 +0000485 if (!(resource->flags & IORESOURCE_FIXED)) {
486 resource->flags = 0;
487 resource->base = 0;
488 }
489 resource->size = 0;
490 resource->limit = 0;
491 resource->index = index;
492 resource->align = 0;
493 resource->gran = 0;
494
495 return resource;
496}
497
Eric Biederman03acab62004-10-14 21:25:53 +0000498/**
499 * Return an existing resource structure for a given index.
Uwe Hermannc1ee4292010-10-17 19:01:48 +0000500 *
501 * @param dev The device to find the resource on.
502 * @param index The index of the resource on the device.
503 * return TODO.
Eric Biederman03acab62004-10-14 21:25:53 +0000504 */
505struct resource *find_resource(device_t dev, unsigned index)
506{
507 struct resource *resource;
508
Uwe Hermanne4870472010-11-04 23:23:47 +0000509 /* See if there is a resource with the appropriate index. */
Eric Biederman03acab62004-10-14 21:25:53 +0000510 resource = probe_resource(dev, index);
511 if (!resource) {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000512 printk(BIOS_EMERG, "%s missing resource: %02x\n",
Uwe Hermanne4870472010-11-04 23:23:47 +0000513 dev_path(dev), index);
Eric Biederman03acab62004-10-14 21:25:53 +0000514 die("");
515 }
516 return resource;
517}
518
Eric Biederman03acab62004-10-14 21:25:53 +0000519/**
Uwe Hermannc1ee4292010-10-17 19:01:48 +0000520 * Round a number up to the next multiple of gran.
521 *
522 * @param val The starting value.
523 * @param gran Granularity we are aligning the number to.
524 * @return The aligned value.
Eric Biederman03acab62004-10-14 21:25:53 +0000525 */
526static resource_t align_up(resource_t val, unsigned long gran)
527{
528 resource_t mask;
529 mask = (1ULL << gran) - 1ULL;
530 val += mask;
531 val &= ~mask;
532 return val;
533}
534
535/**
Uwe Hermannc1ee4292010-10-17 19:01:48 +0000536 * Round a number up to the previous multiple of gran.
537 *
538 * @param val The starting value.
539 * @param gran Granularity we are aligning the number to.
540 * @return The aligned value.
Eric Biederman03acab62004-10-14 21:25:53 +0000541 */
542static resource_t align_down(resource_t val, unsigned long gran)
543{
544 resource_t mask;
545 mask = (1ULL << gran) - 1ULL;
546 val &= ~mask;
547 return val;
548}
549
550/**
Uwe Hermannc1ee4292010-10-17 19:01:48 +0000551 * Compute the maximum address that is part of a resource.
552 *
553 * @param resource The resource whose limit is desired.
554 * @return The end.
Eric Biederman03acab62004-10-14 21:25:53 +0000555 */
556resource_t resource_end(struct resource *resource)
557{
558 resource_t base, end;
Uwe Hermanne4870472010-11-04 23:23:47 +0000559
560 /* Get the base address. */
Eric Biederman03acab62004-10-14 21:25:53 +0000561 base = resource->base;
562
Uwe Hermanne4870472010-11-04 23:23:47 +0000563 /*
564 * For a non bridge resource granularity and alignment are the same.
Eric Biederman03acab62004-10-14 21:25:53 +0000565 * For a bridge resource align is the largest needed alignment below
Uwe Hermanne4870472010-11-04 23:23:47 +0000566 * the bridge. While the granularity is simply how many low bits of
567 * the address cannot be set.
Eric Biederman03acab62004-10-14 21:25:53 +0000568 */
Stefan Reinauer14e22772010-04-27 06:56:47 +0000569
Uwe Hermanne4870472010-11-04 23:23:47 +0000570 /* Get the end (rounded up). */
Eric Biederman03acab62004-10-14 21:25:53 +0000571 end = base + align_up(resource->size, resource->gran) - 1;
572
573 return end;
574}
575
576/**
Uwe Hermannc1ee4292010-10-17 19:01:48 +0000577 * Compute the maximum legal value for resource->base.
578 *
579 * @param resource The resource whose maximum is desired.
580 * @return The maximum.
Eric Biederman03acab62004-10-14 21:25:53 +0000581 */
582resource_t resource_max(struct resource *resource)
583{
584 resource_t max;
585
586 max = align_down(resource->limit - resource->size + 1, resource->align);
587
588 return max;
589}
590
591/**
Uwe Hermannc1ee4292010-10-17 19:01:48 +0000592 * Return the resource type of a resource.
593 *
594 * @param resource The resource type to decode.
595 * @return TODO.
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000596 */
597const char *resource_type(struct resource *resource)
598{
599 static char buffer[RESOURCE_TYPE_MAX];
Vladimir Serbinenkoa37383d2013-11-26 02:41:26 +0100600 snprintf(buffer, sizeof (buffer), "%s%s%s%s",
601 ((resource->flags & IORESOURCE_READONLY) ? "ro" : ""),
602 ((resource->flags & IORESOURCE_PREFETCH) ? "pref" : ""),
603 ((resource->flags == 0) ? "unused" :
604 (resource->flags & IORESOURCE_IO) ? "io" :
605 (resource->flags & IORESOURCE_DRQ) ? "drq" :
606 (resource->flags & IORESOURCE_IRQ) ? "irq" :
607 (resource->flags & IORESOURCE_MEM) ? "mem" : "??????"),
608 ((resource->flags & IORESOURCE_PCI64) ? "64" : ""));
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000609 return buffer;
610}
611
612/**
Uwe Hermannc1ee4292010-10-17 19:01:48 +0000613 * Print the resource that was just stored.
614 *
Martin Roth63373ed2013-07-08 16:24:19 -0600615 * @param dev The device the stored resource lives on.
Uwe Hermannc1ee4292010-10-17 19:01:48 +0000616 * @param resource The resource that was just stored.
617 * @param comment TODO
Eric Biederman03acab62004-10-14 21:25:53 +0000618 */
Uwe Hermannc1ee4292010-10-17 19:01:48 +0000619void report_resource_stored(device_t dev, struct resource *resource,
620 const char *comment)
Eric Biederman03acab62004-10-14 21:25:53 +0000621{
Uwe Hermanne4870472010-11-04 23:23:47 +0000622 char buf[10];
623 unsigned long long base, end;
624
625 if (!(resource->flags & IORESOURCE_STORED))
626 return;
627
628 base = resource->base;
629 end = resource_end(resource);
630 buf[0] = '\0';
631
632 if (resource->flags & IORESOURCE_PCI_BRIDGE) {
Vladimir Serbinenkoa37383d2013-11-26 02:41:26 +0100633 snprintf(buf, sizeof (buf),
634 "bus %02x ", dev->link_list->secondary);
Eric Biederman03acab62004-10-14 21:25:53 +0000635 }
Patrick Georgi51615092012-03-11 19:31:03 +0100636 printk(BIOS_DEBUG, "%s %02lx <- [0x%010llx - 0x%010llx] size 0x%08llx "
Uwe Hermanne4870472010-11-04 23:23:47 +0000637 "gran 0x%02x %s%s%s\n", dev_path(dev), resource->index,
638 base, end, resource->size, resource->gran, buf,
639 resource_type(resource), comment);
Eric Biederman03acab62004-10-14 21:25:53 +0000640}
Eric Biedermanf8a2ddd2004-10-30 08:05:41 +0000641
Uwe Hermanne4870472010-11-04 23:23:47 +0000642void search_bus_resources(struct bus *bus, unsigned long type_mask,
643 unsigned long type, resource_search_t search,
644 void *gp)
Eric Biedermanf8a2ddd2004-10-30 08:05:41 +0000645{
646 struct device *curdev;
Uwe Hermanne4870472010-11-04 23:23:47 +0000647
Myles Watson894a3472010-06-09 22:41:35 +0000648 for (curdev = bus->children; curdev; curdev = curdev->sibling) {
Myles Watsonc25cc112010-05-21 14:33:48 +0000649 struct resource *res;
Uwe Hermanne4870472010-11-04 23:23:47 +0000650
651 /* Ignore disabled devices. */
652 if (!curdev->enabled)
653 continue;
654
Myles Watson894a3472010-06-09 22:41:35 +0000655 for (res = curdev->resource_list; res; res = res->next) {
Uwe Hermanne4870472010-11-04 23:23:47 +0000656 /* If it isn't the right kind of resource ignore it. */
657 if ((res->flags & type_mask) != type)
Eric Biedermanf8a2ddd2004-10-30 08:05:41 +0000658 continue;
Uwe Hermanne4870472010-11-04 23:23:47 +0000659
660 /* If it is a subtractive resource recurse. */
Myles Watsonc25cc112010-05-21 14:33:48 +0000661 if (res->flags & IORESOURCE_SUBTRACTIVE) {
Eric Biedermanf8a2ddd2004-10-30 08:05:41 +0000662 struct bus * subbus;
Uwe Hermanne4870472010-11-04 23:23:47 +0000663 for (subbus = curdev->link_list; subbus;
664 subbus = subbus->next)
665 if (subbus->link_num
666 == IOINDEX_SUBTRACTIVE_LINK(res->index))
Myles Watson894a3472010-06-09 22:41:35 +0000667 break;
Stefan Reinauer58075552011-05-11 15:57:07 -0700668 if (!subbus) /* Why can subbus be NULL? */
669 break;
Uwe Hermanne4870472010-11-04 23:23:47 +0000670 search_bus_resources(subbus, type_mask, type,
671 search, gp);
Eric Biedermanf8a2ddd2004-10-30 08:05:41 +0000672 continue;
673 }
Myles Watsonc25cc112010-05-21 14:33:48 +0000674 search(gp, curdev, res);
Eric Biedermanf8a2ddd2004-10-30 08:05:41 +0000675 }
676 }
677}
678
Uwe Hermanne4870472010-11-04 23:23:47 +0000679void search_global_resources(unsigned long type_mask, unsigned long type,
680 resource_search_t search, void *gp)
Eric Biedermanf8a2ddd2004-10-30 08:05:41 +0000681{
682 struct device *curdev;
Uwe Hermanne4870472010-11-04 23:23:47 +0000683
Myles Watson894a3472010-06-09 22:41:35 +0000684 for (curdev = all_devices; curdev; curdev = curdev->next) {
Myles Watsonc25cc112010-05-21 14:33:48 +0000685 struct resource *res;
Uwe Hermanne4870472010-11-04 23:23:47 +0000686
687 /* Ignore disabled devices. */
688 if (!curdev->enabled)
689 continue;
690
Myles Watson894a3472010-06-09 22:41:35 +0000691 for (res = curdev->resource_list; res; res = res->next) {
Uwe Hermanne4870472010-11-04 23:23:47 +0000692 /* If it isn't the right kind of resource ignore it. */
693 if ((res->flags & type_mask) != type)
Eric Biedermanf8a2ddd2004-10-30 08:05:41 +0000694 continue;
Uwe Hermanne4870472010-11-04 23:23:47 +0000695
696 /* If it is a subtractive resource ignore it. */
697 if (res->flags & IORESOURCE_SUBTRACTIVE)
Eric Biedermanf8a2ddd2004-10-30 08:05:41 +0000698 continue;
Uwe Hermanne4870472010-11-04 23:23:47 +0000699
Myles Watsonc25cc112010-05-21 14:33:48 +0000700 search(gp, curdev, res);
Eric Biedermanf8a2ddd2004-10-30 08:05:41 +0000701 }
702 }
703}
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000704
705void dev_set_enabled(device_t dev, int enable)
706{
Uwe Hermanne4870472010-11-04 23:23:47 +0000707 if (dev->enabled == enable)
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000708 return;
Uwe Hermanne4870472010-11-04 23:23:47 +0000709
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000710 dev->enabled = enable;
711 if (dev->ops && dev->ops->enable) {
712 dev->ops->enable(dev);
Uwe Hermanne4870472010-11-04 23:23:47 +0000713 } else if (dev->chip_ops && dev->chip_ops->enable_dev) {
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000714 dev->chip_ops->enable_dev(dev);
715 }
716}
717
718void disable_children(struct bus *bus)
719{
720 device_t child;
Uwe Hermanne4870472010-11-04 23:23:47 +0000721
Myles Watson894a3472010-06-09 22:41:35 +0000722 for (child = bus->children; child; child = child->sibling) {
723 struct bus *link;
Uwe Hermanne4870472010-11-04 23:23:47 +0000724 for (link = child->link_list; link; link = link->next)
Myles Watson894a3472010-06-09 22:41:35 +0000725 disable_children(link);
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000726 dev_set_enabled(child, 0);
727 }
728}
Myles Watsonbb3d8122009-05-11 22:45:35 +0000729
Maciej Pijankaea921852009-10-27 14:29:29 +0000730static void resource_tree(struct device *root, int debug_level, int depth)
Myles Watsonbb3d8122009-05-11 22:45:35 +0000731{
Myles Watson894a3472010-06-09 22:41:35 +0000732 int i = 0;
Myles Watsonbb3d8122009-05-11 22:45:35 +0000733 struct device *child;
Myles Watson894a3472010-06-09 22:41:35 +0000734 struct bus *link;
Myles Watsonc25cc112010-05-21 14:33:48 +0000735 struct resource *res;
Myles Watsonbb3d8122009-05-11 22:45:35 +0000736 char indent[30]; /* If your tree has more levels, it's wrong. */
737
738 for (i = 0; i < depth + 1 && i < 29; i++)
739 indent[i] = ' ';
740 indent[i] = '\0';
741
Myles Watson894a3472010-06-09 22:41:35 +0000742 do_printk(BIOS_DEBUG, "%s%s", indent, dev_path(root));
743 if (root->link_list && root->link_list->children)
744 do_printk(BIOS_DEBUG, " child on link 0 %s",
745 dev_path(root->link_list->children));
746 do_printk(BIOS_DEBUG, "\n");
747
Myles Watsonc25cc112010-05-21 14:33:48 +0000748 for (res = root->resource_list; res; res = res->next) {
Uwe Hermanne4870472010-11-04 23:23:47 +0000749 do_printk(debug_level, "%s%s resource base %llx size %llx "
750 "align %d gran %d limit %llx flags %lx index %lx\n",
751 indent, dev_path(root), res->base, res->size,
752 res->align, res->gran, res->limit, res->flags,
753 res->index);
Myles Watsonbb3d8122009-05-11 22:45:35 +0000754 }
755
Myles Watson894a3472010-06-09 22:41:35 +0000756 for (link = root->link_list; link; link = link->next) {
757 for (child = link->children; child; child = child->sibling)
Myles Watsonbb3d8122009-05-11 22:45:35 +0000758 resource_tree(child, debug_level, depth + 1);
759 }
760}
761
Uwe Hermanne4870472010-11-04 23:23:47 +0000762void print_resource_tree(struct device *root, int debug_level, const char *msg)
Myles Watsonbb3d8122009-05-11 22:45:35 +0000763{
764 /* Bail if root is null. */
765 if (!root) {
766 do_printk(debug_level, "%s passed NULL for root!\n", __func__);
767 return;
768 }
769
770 /* Bail if not printing to screen. */
771 if (!do_printk(debug_level, "Show resources in subtree (%s)...%s\n",
Uwe Hermanne4870472010-11-04 23:23:47 +0000772 dev_path(root), msg))
Myles Watsonbb3d8122009-05-11 22:45:35 +0000773 return;
Uwe Hermanne4870472010-11-04 23:23:47 +0000774
Myles Watsonbb3d8122009-05-11 22:45:35 +0000775 resource_tree(root, debug_level, 0);
776}
777
778void show_devs_tree(struct device *dev, int debug_level, int depth, int linknum)
779{
Marcelo Povoa8404dca2014-02-14 15:42:49 -0800780 char depth_str[20];
Myles Watsonbb3d8122009-05-11 22:45:35 +0000781 int i;
782 struct device *sibling;
Myles Watson894a3472010-06-09 22:41:35 +0000783 struct bus *link;
784
Myles Watsonbb3d8122009-05-11 22:45:35 +0000785 for (i = 0; i < depth; i++)
786 depth_str[i] = ' ';
787 depth_str[i] = '\0';
Uwe Hermanne4870472010-11-04 23:23:47 +0000788
Myles Watsonc25cc112010-05-21 14:33:48 +0000789 do_printk(debug_level, "%s%s: enabled %d\n",
790 depth_str, dev_path(dev), dev->enabled);
Uwe Hermanne4870472010-11-04 23:23:47 +0000791
Myles Watson894a3472010-06-09 22:41:35 +0000792 for (link = dev->link_list; link; link = link->next) {
793 for (sibling = link->children; sibling;
Myles Watsonbb3d8122009-05-11 22:45:35 +0000794 sibling = sibling->sibling)
795 show_devs_tree(sibling, debug_level, depth + 1, i);
796 }
797}
798
799void show_all_devs_tree(int debug_level, const char *msg)
800{
801 /* Bail if not printing to screen. */
Paul Menzeleb605d72015-02-12 00:29:32 +0100802 if (!do_printk(debug_level, "Show all devs in tree form... %s\n", msg))
Myles Watsonbb3d8122009-05-11 22:45:35 +0000803 return;
804 show_devs_tree(all_devices, debug_level, 0, -1);
805}
806
807void show_devs_subtree(struct device *root, int debug_level, const char *msg)
808{
809 /* Bail if not printing to screen. */
Paul Menzeleb605d72015-02-12 00:29:32 +0100810 if (!do_printk(debug_level, "Show all devs in subtree %s... %s\n",
Uwe Hermanne4870472010-11-04 23:23:47 +0000811 dev_path(root), msg))
Myles Watsonbb3d8122009-05-11 22:45:35 +0000812 return;
813 do_printk(debug_level, "%s\n", msg);
814 show_devs_tree(root, debug_level, 0, -1);
815}
816
817void show_all_devs(int debug_level, const char *msg)
818{
819 struct device *dev;
820
821 /* Bail if not printing to screen. */
Paul Menzeleb605d72015-02-12 00:29:32 +0100822 if (!do_printk(debug_level, "Show all devs... %s\n", msg))
Myles Watsonbb3d8122009-05-11 22:45:35 +0000823 return;
824 for (dev = all_devices; dev; dev = dev->next) {
Myles Watsonc25cc112010-05-21 14:33:48 +0000825 do_printk(debug_level, "%s: enabled %d\n",
826 dev_path(dev), dev->enabled);
Myles Watsonbb3d8122009-05-11 22:45:35 +0000827 }
828}
829
830void show_one_resource(int debug_level, struct device *dev,
831 struct resource *resource, const char *comment)
832{
833 char buf[10];
834 unsigned long long base, end;
835 base = resource->base;
836 end = resource_end(resource);
837 buf[0] = '\0';
Uwe Hermanne4870472010-11-04 23:23:47 +0000838
Uwe Hermanne4870472010-11-04 23:23:47 +0000839 do_printk(debug_level, "%s %02lx <- [0x%010llx - 0x%010llx] "
Patrick Georgi51615092012-03-11 19:31:03 +0100840 "size 0x%08llx gran 0x%02x %s%s%s\n", dev_path(dev),
Uwe Hermanne4870472010-11-04 23:23:47 +0000841 resource->index, base, end, resource->size, resource->gran,
842 buf, resource_type(resource), comment);
Myles Watsonbb3d8122009-05-11 22:45:35 +0000843}
844
845void show_all_devs_resources(int debug_level, const char* msg)
846{
847 struct device *dev;
848
Paul Menzeleb605d72015-02-12 00:29:32 +0100849 if (!do_printk(debug_level, "Show all devs with resources... %s\n", msg))
Myles Watsonbb3d8122009-05-11 22:45:35 +0000850 return;
851
852 for (dev = all_devices; dev; dev = dev->next) {
Myles Watsonc25cc112010-05-21 14:33:48 +0000853 struct resource *res;
854 do_printk(debug_level, "%s: enabled %d\n",
855 dev_path(dev), dev->enabled);
856 for (res = dev->resource_list; res; res = res->next)
857 show_one_resource(debug_level, dev, res, "");
Myles Watsonbb3d8122009-05-11 22:45:35 +0000858 }
859}
Uwe Hermann4b42a622010-10-11 19:36:13 +0000860
Kyösti Mälkkiecf1ed42012-07-27 08:37:12 +0300861void fixed_mem_resource(device_t dev, unsigned long index,
862 unsigned long basek, unsigned long sizek, unsigned long type)
Uwe Hermann4b42a622010-10-11 19:36:13 +0000863{
864 struct resource *resource;
865
866 if (!sizek)
867 return;
868
869 resource = new_resource(dev, index);
870 resource->base = ((resource_t)basek) << 10;
871 resource->size = ((resource_t)sizek) << 10;
Kyösti Mälkkiecf1ed42012-07-27 08:37:12 +0300872 resource->flags = IORESOURCE_MEM | IORESOURCE_FIXED |
873 IORESOURCE_STORED | IORESOURCE_ASSIGNED;
Uwe Hermann4b42a622010-10-11 19:36:13 +0000874
Kyösti Mälkkiecf1ed42012-07-27 08:37:12 +0300875 resource->flags |= type;
Kyösti Mälkki63f8c082012-07-10 13:27:26 +0300876}
877
Uwe Hermann4b42a622010-10-11 19:36:13 +0000878void tolm_test(void *gp, struct device *dev, struct resource *new)
879{
880 struct resource **best_p = gp;
881 struct resource *best;
882
883 best = *best_p;
884
885 if (!best || (best->base > new->base))
886 best = new;
887
888 *best_p = best;
889}
890
891u32 find_pci_tolm(struct bus *bus)
892{
893 struct resource *min = NULL;
894 u32 tolm;
895
896 search_bus_resources(bus, IORESOURCE_MEM, IORESOURCE_MEM,
897 tolm_test, &min);
898
899 tolm = 0xffffffffUL;
900
901 if (min && tolm > min->base)
902 tolm = min->base;
903
904 return tolm;
905}
Stefan Reinauerdc8448fd2012-03-30 13:52:58 -0700906
907/* Count of enabled CPUs */
908int dev_count_cpu(void)
909{
910 device_t cpu;
911 int count = 0;
912
913 for (cpu = all_devices; cpu; cpu = cpu->next) {
914 if ((cpu->path.type != DEVICE_PATH_APIC) ||
Stefan Reinauer0aa37c42013-02-12 15:20:54 -0800915 (cpu->bus->dev->path.type != DEVICE_PATH_CPU_CLUSTER))
Stefan Reinauerdc8448fd2012-03-30 13:52:58 -0700916 continue;
917 if (!cpu->enabled)
918 continue;
919 count++;
920 }
921
922 return count;
923}