2020-04-02 23:48:16 +02:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2007-04-22 21:08:13 +02:00
|
|
|
|
2003-04-22 21:02:15 +02:00
|
|
|
#include <console/console.h>
|
2003-04-24 08:25:08 +02:00
|
|
|
#include <device/device.h>
|
2003-09-02 05:36:25 +02:00
|
|
|
#include <device/path.h>
|
2014-02-12 13:18:50 +01:00
|
|
|
#include <device/pci_def.h>
|
2004-10-30 10:05:41 +02:00
|
|
|
#include <device/resource.h>
|
2019-06-23 06:57:53 +02:00
|
|
|
#include <stdlib.h>
|
2003-09-02 05:36:25 +02:00
|
|
|
#include <string.h>
|
|
|
|
|
2011-07-18 19:41:36 +02:00
|
|
|
/**
|
|
|
|
* Given a Local APIC ID, find the device structure.
|
|
|
|
*
|
|
|
|
* @param apic_id The Local APIC ID number.
|
|
|
|
* @return Pointer to the device structure (if found), 0 otherwise.
|
|
|
|
*/
|
2019-10-24 05:41:00 +02:00
|
|
|
struct device *dev_find_lapic(unsigned int apic_id)
|
2011-07-18 19:41:36 +02:00
|
|
|
{
|
2017-11-10 18:47:54 +01:00
|
|
|
struct device *dev;
|
|
|
|
struct device *result = NULL;
|
2011-07-18 19:41:36 +02:00
|
|
|
|
|
|
|
for (dev = all_devices; dev; dev = dev->next) {
|
|
|
|
if (dev->path.type == DEVICE_PATH_APIC &&
|
|
|
|
dev->path.apic.apic_id == apic_id) {
|
|
|
|
result = dev;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-10-17 21:01:48 +02:00
|
|
|
/**
|
|
|
|
* Find a device of a given vendor and type.
|
|
|
|
*
|
|
|
|
* @param vendor A PCI vendor ID (e.g. 0x8086 for Intel).
|
|
|
|
* @param device A PCI device ID.
|
2010-11-05 00:23:47 +01:00
|
|
|
* @param from Pointer to the device structure, used as a starting point in
|
|
|
|
* the linked list of all_devices, which can be 0 to start at the
|
|
|
|
* head of the list (i.e. all_devices).
|
2010-10-17 21:01:48 +02:00
|
|
|
* @return Pointer to the device struct.
|
2003-04-22 21:02:15 +02:00
|
|
|
*/
|
2010-11-05 00:23:47 +01:00
|
|
|
struct device *dev_find_device(u16 vendor, u16 device, struct device *from)
|
2003-04-22 21:02:15 +02:00
|
|
|
{
|
|
|
|
if (!from)
|
|
|
|
from = all_devices;
|
|
|
|
else
|
|
|
|
from = from->next;
|
2010-11-05 00:23:47 +01:00
|
|
|
|
|
|
|
while (from && (from->vendor != vendor || from->device != device))
|
2003-04-22 21:02:15 +02:00
|
|
|
from = from->next;
|
2010-11-05 00:23:47 +01:00
|
|
|
|
2003-04-22 21:02:15 +02:00
|
|
|
return from;
|
|
|
|
}
|
|
|
|
|
2010-10-17 21:01:48 +02:00
|
|
|
/**
|
|
|
|
* Find a device of a given class.
|
|
|
|
*
|
|
|
|
* @param class Class of the device.
|
2010-11-05 00:23:47 +01:00
|
|
|
* @param from Pointer to the device structure, used as a starting point in
|
|
|
|
* the linked list of all_devices, which can be 0 to start at the
|
|
|
|
* head of the list (i.e. all_devices).
|
2010-10-17 21:01:48 +02:00
|
|
|
* @return Pointer to the device struct.
|
2003-04-22 21:02:15 +02:00
|
|
|
*/
|
|
|
|
struct device *dev_find_class(unsigned int class, struct device *from)
|
|
|
|
{
|
|
|
|
if (!from)
|
|
|
|
from = all_devices;
|
|
|
|
else
|
|
|
|
from = from->next;
|
2010-11-05 00:23:47 +01:00
|
|
|
|
2003-12-17 18:39:53 +01:00
|
|
|
while (from && (from->class & 0xffffff00) != class)
|
2003-04-22 21:02:15 +02:00
|
|
|
from = from->next;
|
2010-11-05 00:23:47 +01:00
|
|
|
|
2003-04-22 21:02:15 +02:00
|
|
|
return from;
|
|
|
|
}
|
|
|
|
|
2013-06-10 18:59:17 +02:00
|
|
|
/**
|
|
|
|
* Encode the device path into 3 bytes for logging to CMOS.
|
|
|
|
*
|
|
|
|
* @param dev The device path to encode.
|
|
|
|
* @return Device path encoded into lower 3 bytes of dword.
|
|
|
|
*/
|
2018-05-02 06:57:36 +02:00
|
|
|
u32 dev_path_encode(const struct device *dev)
|
2013-06-10 18:59:17 +02:00
|
|
|
{
|
|
|
|
u32 ret;
|
|
|
|
|
|
|
|
if (!dev)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Store the device type in 3rd byte. */
|
|
|
|
ret = dev->path.type << 16;
|
|
|
|
|
|
|
|
/* Encode the device specific path in the low word. */
|
|
|
|
switch (dev->path.type) {
|
|
|
|
case DEVICE_PATH_ROOT:
|
|
|
|
break;
|
|
|
|
case DEVICE_PATH_PCI:
|
|
|
|
ret |= dev->bus->secondary << 8 | dev->path.pci.devfn;
|
|
|
|
break;
|
|
|
|
case DEVICE_PATH_PNP:
|
|
|
|
ret |= dev->path.pnp.port << 8 | dev->path.pnp.device;
|
|
|
|
break;
|
|
|
|
case DEVICE_PATH_I2C:
|
2016-05-08 04:49:37 +02:00
|
|
|
ret |= dev->path.i2c.mode_10bit << 8 | dev->path.i2c.device;
|
2013-06-10 18:59:17 +02:00
|
|
|
break;
|
|
|
|
case DEVICE_PATH_APIC:
|
|
|
|
ret |= dev->path.apic.apic_id;
|
|
|
|
break;
|
|
|
|
case DEVICE_PATH_DOMAIN:
|
|
|
|
ret |= dev->path.domain.domain;
|
|
|
|
break;
|
|
|
|
case DEVICE_PATH_CPU_CLUSTER:
|
|
|
|
ret |= dev->path.cpu_cluster.cluster;
|
|
|
|
break;
|
|
|
|
case DEVICE_PATH_CPU:
|
|
|
|
ret |= dev->path.cpu.id;
|
|
|
|
break;
|
|
|
|
case DEVICE_PATH_CPU_BUS:
|
|
|
|
ret |= dev->path.cpu_bus.id;
|
|
|
|
break;
|
|
|
|
case DEVICE_PATH_IOAPIC:
|
|
|
|
ret |= dev->path.ioapic.ioapic_id;
|
|
|
|
break;
|
2016-05-08 05:01:34 +02:00
|
|
|
case DEVICE_PATH_GENERIC:
|
|
|
|
ret |= dev->path.generic.subid << 8 | dev->path.generic.id;
|
|
|
|
break;
|
2017-02-11 19:57:23 +01:00
|
|
|
case DEVICE_PATH_SPI:
|
|
|
|
ret |= dev->path.spi.cs;
|
|
|
|
break;
|
2018-05-07 23:18:13 +02:00
|
|
|
case DEVICE_PATH_USB:
|
2019-07-11 20:23:35 +02:00
|
|
|
ret |= dev->path.usb.port_type << 8 | dev->path.usb.port_id;
|
2018-05-07 23:18:13 +02:00
|
|
|
break;
|
2013-06-10 18:59:17 +02:00
|
|
|
case DEVICE_PATH_NONE:
|
2018-01-18 01:36:30 +01:00
|
|
|
case DEVICE_PATH_MMIO: /* don't care */
|
2013-06-10 18:59:17 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-10-17 21:01:48 +02:00
|
|
|
/*
|
|
|
|
* Warning: This function uses a static buffer. Don't call it more than once
|
|
|
|
* from the same print statement!
|
|
|
|
*/
|
2018-04-26 00:00:22 +02:00
|
|
|
const char *dev_path(const struct device *dev)
|
2003-09-02 05:36:25 +02:00
|
|
|
{
|
|
|
|
static char buffer[DEVICE_PATH_MAX];
|
2010-10-17 21:01:48 +02:00
|
|
|
|
2003-09-02 05:36:25 +02:00
|
|
|
buffer[0] = '\0';
|
|
|
|
if (!dev) {
|
|
|
|
memcpy(buffer, "<null>", 7);
|
2010-11-05 00:23:47 +01:00
|
|
|
} else {
|
2018-11-13 10:03:31 +01:00
|
|
|
switch (dev->path.type) {
|
2017-11-01 11:33:00 +01:00
|
|
|
case DEVICE_PATH_NONE:
|
|
|
|
memcpy(buffer, "NONE", 5);
|
|
|
|
break;
|
2003-10-11 08:20:25 +02:00
|
|
|
case DEVICE_PATH_ROOT:
|
|
|
|
memcpy(buffer, "Root Device", 12);
|
|
|
|
break;
|
2003-09-02 05:36:25 +02:00
|
|
|
case DEVICE_PATH_PCI:
|
2018-05-16 12:58:19 +02:00
|
|
|
snprintf(buffer, sizeof(buffer),
|
2013-11-26 02:41:26 +01:00
|
|
|
"PCI: %02x:%02x.%01x",
|
|
|
|
dev->bus->secondary,
|
|
|
|
PCI_SLOT(dev->path.pci.devfn),
|
|
|
|
PCI_FUNC(dev->path.pci.devfn));
|
2003-09-02 05:36:25 +02:00
|
|
|
break;
|
|
|
|
case DEVICE_PATH_PNP:
|
2018-05-16 12:58:19 +02:00
|
|
|
snprintf(buffer, sizeof(buffer), "PNP: %04x.%01x",
|
2013-11-26 02:41:26 +01:00
|
|
|
dev->path.pnp.port, dev->path.pnp.device);
|
2003-09-02 05:36:25 +02:00
|
|
|
break;
|
|
|
|
case DEVICE_PATH_I2C:
|
2018-05-16 12:58:19 +02:00
|
|
|
snprintf(buffer, sizeof(buffer), "I2C: %02x:%02x",
|
2013-11-26 02:41:26 +01:00
|
|
|
dev->bus->secondary,
|
|
|
|
dev->path.i2c.device);
|
2003-09-02 05:36:25 +02:00
|
|
|
break;
|
2004-10-14 23:25:53 +02:00
|
|
|
case DEVICE_PATH_APIC:
|
2018-05-16 12:58:19 +02:00
|
|
|
snprintf(buffer, sizeof(buffer), "APIC: %02x",
|
2013-11-26 02:41:26 +01:00
|
|
|
dev->path.apic.apic_id);
|
2004-10-14 23:25:53 +02:00
|
|
|
break;
|
2012-06-21 22:19:48 +02:00
|
|
|
case DEVICE_PATH_IOAPIC:
|
2018-05-16 12:58:19 +02:00
|
|
|
snprintf(buffer, sizeof(buffer), "IOAPIC: %02x",
|
2013-11-26 02:41:26 +01:00
|
|
|
dev->path.ioapic.ioapic_id);
|
2012-06-21 22:19:48 +02:00
|
|
|
break;
|
2013-02-12 23:17:15 +01:00
|
|
|
case DEVICE_PATH_DOMAIN:
|
2018-05-16 12:58:19 +02:00
|
|
|
snprintf(buffer, sizeof(buffer), "DOMAIN: %04x",
|
2013-02-12 23:17:15 +01:00
|
|
|
dev->path.domain.domain);
|
2004-10-16 08:20:29 +02:00
|
|
|
break;
|
2013-02-13 00:20:54 +01:00
|
|
|
case DEVICE_PATH_CPU_CLUSTER:
|
2018-05-16 12:58:19 +02:00
|
|
|
snprintf(buffer, sizeof(buffer), "CPU_CLUSTER: %01x",
|
2013-02-13 00:20:54 +01:00
|
|
|
dev->path.cpu_cluster.cluster);
|
2004-10-16 08:20:29 +02:00
|
|
|
break;
|
2004-11-18 23:38:08 +01:00
|
|
|
case DEVICE_PATH_CPU:
|
2018-05-16 12:58:19 +02:00
|
|
|
snprintf(buffer, sizeof(buffer),
|
2013-11-26 02:41:26 +01:00
|
|
|
"CPU: %02x", dev->path.cpu.id);
|
2004-11-18 23:38:08 +01:00
|
|
|
break;
|
|
|
|
case DEVICE_PATH_CPU_BUS:
|
2018-05-16 12:58:19 +02:00
|
|
|
snprintf(buffer, sizeof(buffer),
|
2013-11-26 02:41:26 +01:00
|
|
|
"CPU_BUS: %02x", dev->path.cpu_bus.id);
|
2004-11-18 23:38:08 +01:00
|
|
|
break;
|
2016-05-08 05:01:34 +02:00
|
|
|
case DEVICE_PATH_GENERIC:
|
2018-05-16 12:58:19 +02:00
|
|
|
snprintf(buffer, sizeof(buffer),
|
2016-05-08 05:01:34 +02:00
|
|
|
"GENERIC: %d.%d", dev->path.generic.id,
|
|
|
|
dev->path.generic.subid);
|
|
|
|
break;
|
2017-02-11 19:57:23 +01:00
|
|
|
case DEVICE_PATH_SPI:
|
2018-05-16 12:58:19 +02:00
|
|
|
snprintf(buffer, sizeof(buffer), "SPI: %02x",
|
2017-02-11 19:57:23 +01:00
|
|
|
dev->path.spi.cs);
|
|
|
|
break;
|
2018-05-07 23:18:13 +02:00
|
|
|
case DEVICE_PATH_USB:
|
2018-05-16 12:58:19 +02:00
|
|
|
snprintf(buffer, sizeof(buffer), "USB%u port %u",
|
2018-05-07 23:18:13 +02:00
|
|
|
dev->path.usb.port_type, dev->path.usb.port_id);
|
|
|
|
break;
|
2018-01-18 01:36:30 +01:00
|
|
|
case DEVICE_PATH_MMIO:
|
2019-07-16 20:55:00 +02:00
|
|
|
snprintf(buffer, sizeof(buffer), "MMIO: %08lx",
|
2018-01-18 01:36:30 +01:00
|
|
|
dev->path.mmio.addr);
|
2020-05-06 19:47:04 +02:00
|
|
|
break;
|
|
|
|
case DEVICE_PATH_ESPI:
|
|
|
|
snprintf(buffer, sizeof(buffer), "ESPI: %08lx",
|
|
|
|
dev->path.espi.addr);
|
|
|
|
break;
|
|
|
|
case DEVICE_PATH_LPC:
|
|
|
|
snprintf(buffer, sizeof(buffer), "LPC: %08lx",
|
|
|
|
dev->path.lpc.addr);
|
2018-01-18 01:36:30 +01:00
|
|
|
break;
|
2003-09-02 05:36:25 +02:00
|
|
|
default:
|
2010-11-05 00:23:47 +01:00
|
|
|
printk(BIOS_ERR, "Unknown device path type: %d\n",
|
|
|
|
dev->path.type);
|
2003-09-02 05:36:25 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
2020-04-25 06:31:35 +02:00
|
|
|
const char *dev_name(const struct device *dev)
|
2012-10-07 14:57:15 +02:00
|
|
|
{
|
2012-10-10 22:14:28 +02:00
|
|
|
if (dev->name)
|
|
|
|
return dev->name;
|
|
|
|
else if (dev->chip_ops && dev->chip_ops->name)
|
2012-10-07 14:57:15 +02:00
|
|
|
return dev->chip_ops->name;
|
|
|
|
else
|
|
|
|
return "unknown";
|
|
|
|
}
|
|
|
|
|
2005-07-08 04:49:49 +02:00
|
|
|
const char *bus_path(struct bus *bus)
|
|
|
|
{
|
|
|
|
static char buffer[BUS_PATH_MAX];
|
2018-05-16 12:58:19 +02:00
|
|
|
snprintf(buffer, sizeof(buffer),
|
2013-11-26 02:41:26 +01:00
|
|
|
"%s,%d", dev_path(bus->dev), bus->link_num);
|
2005-07-08 04:49:49 +02:00
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
2010-05-21 16:33:48 +02:00
|
|
|
/**
|
|
|
|
* Allocate 64 more resources to the free list.
|
2010-10-17 21:01:48 +02:00
|
|
|
*
|
|
|
|
* @return TODO.
|
2010-05-21 16:33:48 +02:00
|
|
|
*/
|
|
|
|
static int allocate_more_resources(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct resource *new_res_list;
|
2010-11-05 00:23:47 +01:00
|
|
|
|
2010-05-21 16:33:48 +02:00
|
|
|
new_res_list = malloc(64 * sizeof(*new_res_list));
|
|
|
|
|
|
|
|
if (new_res_list == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
memset(new_res_list, 0, 64 * sizeof(*new_res_list));
|
|
|
|
|
2010-11-05 00:23:47 +01:00
|
|
|
for (i = 0; i < 64 - 1; i++)
|
2010-05-21 16:33:48 +02:00
|
|
|
new_res_list[i].next = &new_res_list[i+1];
|
|
|
|
|
|
|
|
free_resources = new_res_list;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove resource res from the device's list and add it to the free list.
|
2010-10-17 21:01:48 +02:00
|
|
|
*
|
|
|
|
* @param dev TODO
|
|
|
|
* @param res TODO
|
|
|
|
* @param prev TODO
|
|
|
|
* @return TODO.
|
2010-05-21 16:33:48 +02:00
|
|
|
*/
|
2017-11-10 18:47:54 +01:00
|
|
|
static void free_resource(struct device *dev, struct resource *res,
|
2010-10-17 21:01:48 +02:00
|
|
|
struct resource *prev)
|
2010-05-21 16:33:48 +02:00
|
|
|
{
|
|
|
|
if (prev)
|
|
|
|
prev->next = res->next;
|
|
|
|
else
|
|
|
|
dev->resource_list = res->next;
|
2010-11-05 00:23:47 +01:00
|
|
|
|
2010-05-21 16:33:48 +02:00
|
|
|
res->next = free_resources;
|
|
|
|
free_resources = res;
|
|
|
|
}
|
|
|
|
|
2004-03-11 16:01:31 +01:00
|
|
|
/**
|
|
|
|
* See if we have unused but allocated resource structures.
|
2010-11-05 00:23:47 +01:00
|
|
|
*
|
2004-03-11 16:01:31 +01:00
|
|
|
* If so remove the allocation.
|
2010-10-17 21:01:48 +02:00
|
|
|
*
|
|
|
|
* @param dev The device to find the resource on.
|
2004-03-11 16:01:31 +01:00
|
|
|
*/
|
2017-11-10 18:47:54 +01:00
|
|
|
void compact_resources(struct device *dev)
|
2004-03-11 16:01:31 +01:00
|
|
|
{
|
2010-05-21 16:33:48 +02:00
|
|
|
struct resource *res, *next, *prev = NULL;
|
2010-11-05 00:23:47 +01:00
|
|
|
|
2004-03-11 16:01:31 +01:00
|
|
|
/* Move all of the free resources to the end */
|
2010-06-10 00:41:35 +02:00
|
|
|
for (res = dev->resource_list; res; res = next) {
|
2010-05-21 16:33:48 +02:00
|
|
|
next = res->next;
|
|
|
|
if (!res->flags)
|
|
|
|
free_resource(dev, res, prev);
|
|
|
|
else
|
|
|
|
prev = res;
|
2004-03-11 16:01:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-10-17 21:01:48 +02:00
|
|
|
* See if a resource structure already exists for a given index.
|
|
|
|
*
|
|
|
|
* @param dev The device to find the resource on.
|
|
|
|
* @param index The index of the resource on the device.
|
|
|
|
* @return The resource, if it already exists.
|
2004-03-11 16:01:31 +01:00
|
|
|
*/
|
2019-10-24 05:41:00 +02:00
|
|
|
struct resource *probe_resource(const struct device *dev, unsigned int index)
|
2004-03-11 16:01:31 +01:00
|
|
|
{
|
2010-05-21 16:33:48 +02:00
|
|
|
struct resource *res;
|
2010-10-17 21:01:48 +02:00
|
|
|
|
2004-03-11 16:01:31 +01:00
|
|
|
/* See if there is a resource with the appropriate index */
|
2010-06-10 00:41:35 +02:00
|
|
|
for (res = dev->resource_list; res; res = res->next) {
|
2010-05-21 16:33:48 +02:00
|
|
|
if (res->index == index)
|
2004-03-11 16:01:31 +01:00
|
|
|
break;
|
|
|
|
}
|
2010-11-05 00:23:47 +01:00
|
|
|
|
2010-05-21 16:33:48 +02:00
|
|
|
return res;
|
2004-10-14 23:25:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-10-17 21:01:48 +02:00
|
|
|
* See if a resource structure already exists for a given index and if not
|
|
|
|
* allocate one.
|
|
|
|
*
|
2014-06-07 13:31:29 +02:00
|
|
|
* Then initialize the resource to default values.
|
2010-10-17 21:01:48 +02:00
|
|
|
*
|
|
|
|
* @param dev The device to find the resource on.
|
|
|
|
* @param index The index of the resource on the device.
|
|
|
|
* @return TODO.
|
2004-10-14 23:25:53 +02:00
|
|
|
*/
|
2019-10-24 05:41:00 +02:00
|
|
|
struct resource *new_resource(struct device *dev, unsigned int index)
|
2004-10-14 23:25:53 +02:00
|
|
|
{
|
2010-05-21 16:33:48 +02:00
|
|
|
struct resource *resource, *tail;
|
2004-10-14 23:25:53 +02:00
|
|
|
|
2010-11-05 00:23:47 +01:00
|
|
|
/* First move all of the free resources to the end. */
|
2004-10-14 23:25:53 +02:00
|
|
|
compact_resources(dev);
|
|
|
|
|
2010-11-05 00:23:47 +01:00
|
|
|
/* See if there is a resource with the appropriate index. */
|
2004-10-14 23:25:53 +02:00
|
|
|
resource = probe_resource(dev, index);
|
2004-03-11 16:01:31 +01:00
|
|
|
if (!resource) {
|
2010-05-21 16:33:48 +02:00
|
|
|
if (free_resources == NULL && !allocate_more_resources())
|
|
|
|
die("Couldn't allocate more resources.");
|
|
|
|
|
|
|
|
resource = free_resources;
|
|
|
|
free_resources = free_resources->next;
|
2004-03-11 16:01:31 +01:00
|
|
|
memset(resource, 0, sizeof(*resource));
|
2010-05-21 16:33:48 +02:00
|
|
|
resource->next = NULL;
|
|
|
|
tail = dev->resource_list;
|
|
|
|
if (tail) {
|
|
|
|
while (tail->next) tail = tail->next;
|
|
|
|
tail->next = resource;
|
2010-11-05 00:23:47 +01:00
|
|
|
} else {
|
2010-05-21 16:33:48 +02:00
|
|
|
dev->resource_list = resource;
|
2010-11-05 00:23:47 +01:00
|
|
|
}
|
2004-03-11 16:01:31 +01:00
|
|
|
}
|
2010-11-05 00:23:47 +01:00
|
|
|
|
|
|
|
/* Initialize the resource values. */
|
2004-03-11 16:01:31 +01:00
|
|
|
if (!(resource->flags & IORESOURCE_FIXED)) {
|
|
|
|
resource->flags = 0;
|
|
|
|
resource->base = 0;
|
|
|
|
}
|
|
|
|
resource->size = 0;
|
|
|
|
resource->limit = 0;
|
|
|
|
resource->index = index;
|
|
|
|
resource->align = 0;
|
|
|
|
resource->gran = 0;
|
|
|
|
|
|
|
|
return resource;
|
|
|
|
}
|
|
|
|
|
2004-10-14 23:25:53 +02:00
|
|
|
/**
|
|
|
|
* Return an existing resource structure for a given index.
|
2010-10-17 21:01:48 +02:00
|
|
|
*
|
|
|
|
* @param dev The device to find the resource on.
|
|
|
|
* @param index The index of the resource on the device.
|
|
|
|
* return TODO.
|
2004-10-14 23:25:53 +02:00
|
|
|
*/
|
2019-10-24 05:41:00 +02:00
|
|
|
struct resource *find_resource(const struct device *dev, unsigned int index)
|
2004-10-14 23:25:53 +02:00
|
|
|
{
|
|
|
|
struct resource *resource;
|
|
|
|
|
2010-11-05 00:23:47 +01:00
|
|
|
/* See if there is a resource with the appropriate index. */
|
2004-10-14 23:25:53 +02:00
|
|
|
resource = probe_resource(dev, index);
|
|
|
|
if (!resource) {
|
2010-03-22 12:42:32 +01:00
|
|
|
printk(BIOS_EMERG, "%s missing resource: %02x\n",
|
2010-11-05 00:23:47 +01:00
|
|
|
dev_path(dev), index);
|
2004-10-14 23:25:53 +02:00
|
|
|
die("");
|
|
|
|
}
|
|
|
|
return resource;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-10-17 21:01:48 +02:00
|
|
|
* Round a number up to the next multiple of gran.
|
|
|
|
*
|
|
|
|
* @param val The starting value.
|
|
|
|
* @param gran Granularity we are aligning the number to.
|
|
|
|
* @return The aligned value.
|
2004-10-14 23:25:53 +02:00
|
|
|
*/
|
|
|
|
static resource_t align_up(resource_t val, unsigned long gran)
|
|
|
|
{
|
|
|
|
resource_t mask;
|
|
|
|
mask = (1ULL << gran) - 1ULL;
|
|
|
|
val += mask;
|
|
|
|
val &= ~mask;
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-10-17 21:01:48 +02:00
|
|
|
* Round a number up to the previous multiple of gran.
|
|
|
|
*
|
|
|
|
* @param val The starting value.
|
|
|
|
* @param gran Granularity we are aligning the number to.
|
|
|
|
* @return The aligned value.
|
2004-10-14 23:25:53 +02:00
|
|
|
*/
|
|
|
|
static resource_t align_down(resource_t val, unsigned long gran)
|
|
|
|
{
|
|
|
|
resource_t mask;
|
|
|
|
mask = (1ULL << gran) - 1ULL;
|
|
|
|
val &= ~mask;
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-10-17 21:01:48 +02:00
|
|
|
* Compute the maximum address that is part of a resource.
|
|
|
|
*
|
|
|
|
* @param resource The resource whose limit is desired.
|
|
|
|
* @return The end.
|
2004-10-14 23:25:53 +02:00
|
|
|
*/
|
|
|
|
resource_t resource_end(struct resource *resource)
|
|
|
|
{
|
|
|
|
resource_t base, end;
|
2010-11-05 00:23:47 +01:00
|
|
|
|
|
|
|
/* Get the base address. */
|
2004-10-14 23:25:53 +02:00
|
|
|
base = resource->base;
|
|
|
|
|
2010-11-05 00:23:47 +01:00
|
|
|
/*
|
|
|
|
* For a non bridge resource granularity and alignment are the same.
|
2004-10-14 23:25:53 +02:00
|
|
|
* For a bridge resource align is the largest needed alignment below
|
2010-11-05 00:23:47 +01:00
|
|
|
* the bridge. While the granularity is simply how many low bits of
|
|
|
|
* the address cannot be set.
|
2004-10-14 23:25:53 +02:00
|
|
|
*/
|
2010-04-27 08:56:47 +02:00
|
|
|
|
2010-11-05 00:23:47 +01:00
|
|
|
/* Get the end (rounded up). */
|
2004-10-14 23:25:53 +02:00
|
|
|
end = base + align_up(resource->size, resource->gran) - 1;
|
|
|
|
|
|
|
|
return end;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-10-17 21:01:48 +02:00
|
|
|
* Compute the maximum legal value for resource->base.
|
|
|
|
*
|
|
|
|
* @param resource The resource whose maximum is desired.
|
|
|
|
* @return The maximum.
|
2004-10-14 23:25:53 +02:00
|
|
|
*/
|
|
|
|
resource_t resource_max(struct resource *resource)
|
|
|
|
{
|
|
|
|
resource_t max;
|
|
|
|
|
|
|
|
max = align_down(resource->limit - resource->size + 1, resource->align);
|
|
|
|
|
|
|
|
return max;
|
|
|
|
}
|
|
|
|
|
2005-07-08 04:49:49 +02:00
|
|
|
/**
|
2010-10-17 21:01:48 +02:00
|
|
|
* Return the resource type of a resource.
|
|
|
|
*
|
|
|
|
* @param resource The resource type to decode.
|
|
|
|
* @return TODO.
|
2005-07-08 04:49:49 +02:00
|
|
|
*/
|
|
|
|
const char *resource_type(struct resource *resource)
|
|
|
|
{
|
|
|
|
static char buffer[RESOURCE_TYPE_MAX];
|
2018-05-16 12:58:19 +02:00
|
|
|
snprintf(buffer, sizeof(buffer), "%s%s%s%s",
|
2013-11-26 02:41:26 +01:00
|
|
|
((resource->flags & IORESOURCE_READONLY) ? "ro" : ""),
|
|
|
|
((resource->flags & IORESOURCE_PREFETCH) ? "pref" : ""),
|
|
|
|
((resource->flags == 0) ? "unused" :
|
|
|
|
(resource->flags & IORESOURCE_IO) ? "io" :
|
|
|
|
(resource->flags & IORESOURCE_DRQ) ? "drq" :
|
|
|
|
(resource->flags & IORESOURCE_IRQ) ? "irq" :
|
|
|
|
(resource->flags & IORESOURCE_MEM) ? "mem" : "??????"),
|
|
|
|
((resource->flags & IORESOURCE_PCI64) ? "64" : ""));
|
2005-07-08 04:49:49 +02:00
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
2004-10-14 23:25:53 +02:00
|
|
|
/**
|
2010-10-17 21:01:48 +02:00
|
|
|
* Print the resource that was just stored.
|
|
|
|
*
|
2013-07-09 00:24:19 +02:00
|
|
|
* @param dev The device the stored resource lives on.
|
2010-10-17 21:01:48 +02:00
|
|
|
* @param resource The resource that was just stored.
|
|
|
|
* @param comment TODO
|
2004-10-14 23:25:53 +02:00
|
|
|
*/
|
2017-11-10 18:47:54 +01:00
|
|
|
void report_resource_stored(struct device *dev, struct resource *resource,
|
2010-10-17 21:01:48 +02:00
|
|
|
const char *comment)
|
2004-10-14 23:25:53 +02:00
|
|
|
{
|
2010-11-05 00:23:47 +01:00
|
|
|
char buf[10];
|
|
|
|
unsigned long long base, end;
|
|
|
|
|
|
|
|
if (!(resource->flags & IORESOURCE_STORED))
|
|
|
|
return;
|
|
|
|
|
|
|
|
base = resource->base;
|
|
|
|
end = resource_end(resource);
|
|
|
|
buf[0] = '\0';
|
|
|
|
|
|
|
|
if (resource->flags & IORESOURCE_PCI_BRIDGE) {
|
2018-05-16 12:58:19 +02:00
|
|
|
snprintf(buf, sizeof(buf),
|
2013-11-26 02:41:26 +01:00
|
|
|
"bus %02x ", dev->link_list->secondary);
|
2004-10-14 23:25:53 +02:00
|
|
|
}
|
2012-03-11 19:31:03 +01:00
|
|
|
printk(BIOS_DEBUG, "%s %02lx <- [0x%010llx - 0x%010llx] size 0x%08llx "
|
2010-11-05 00:23:47 +01:00
|
|
|
"gran 0x%02x %s%s%s\n", dev_path(dev), resource->index,
|
|
|
|
base, end, resource->size, resource->gran, buf,
|
|
|
|
resource_type(resource), comment);
|
2004-10-14 23:25:53 +02:00
|
|
|
}
|
2004-10-30 10:05:41 +02:00
|
|
|
|
2010-11-05 00:23:47 +01:00
|
|
|
void search_bus_resources(struct bus *bus, unsigned long type_mask,
|
|
|
|
unsigned long type, resource_search_t search,
|
|
|
|
void *gp)
|
2004-10-30 10:05:41 +02:00
|
|
|
{
|
|
|
|
struct device *curdev;
|
2010-11-05 00:23:47 +01:00
|
|
|
|
2010-06-10 00:41:35 +02:00
|
|
|
for (curdev = bus->children; curdev; curdev = curdev->sibling) {
|
2010-05-21 16:33:48 +02:00
|
|
|
struct resource *res;
|
2010-11-05 00:23:47 +01:00
|
|
|
|
|
|
|
/* Ignore disabled devices. */
|
|
|
|
if (!curdev->enabled)
|
|
|
|
continue;
|
|
|
|
|
2010-06-10 00:41:35 +02:00
|
|
|
for (res = curdev->resource_list; res; res = res->next) {
|
2010-11-05 00:23:47 +01:00
|
|
|
/* If it isn't the right kind of resource ignore it. */
|
|
|
|
if ((res->flags & type_mask) != type)
|
2004-10-30 10:05:41 +02:00
|
|
|
continue;
|
2010-11-05 00:23:47 +01:00
|
|
|
|
|
|
|
/* If it is a subtractive resource recurse. */
|
2010-05-21 16:33:48 +02:00
|
|
|
if (res->flags & IORESOURCE_SUBTRACTIVE) {
|
2004-10-30 10:05:41 +02:00
|
|
|
struct bus * subbus;
|
2010-11-05 00:23:47 +01:00
|
|
|
for (subbus = curdev->link_list; subbus;
|
|
|
|
subbus = subbus->next)
|
|
|
|
if (subbus->link_num
|
|
|
|
== IOINDEX_SUBTRACTIVE_LINK(res->index))
|
2010-06-10 00:41:35 +02:00
|
|
|
break;
|
2011-05-12 00:57:07 +02:00
|
|
|
if (!subbus) /* Why can subbus be NULL? */
|
|
|
|
break;
|
2010-11-05 00:23:47 +01:00
|
|
|
search_bus_resources(subbus, type_mask, type,
|
|
|
|
search, gp);
|
2004-10-30 10:05:41 +02:00
|
|
|
continue;
|
|
|
|
}
|
2010-05-21 16:33:48 +02:00
|
|
|
search(gp, curdev, res);
|
2004-10-30 10:05:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-05 00:23:47 +01:00
|
|
|
void search_global_resources(unsigned long type_mask, unsigned long type,
|
|
|
|
resource_search_t search, void *gp)
|
2004-10-30 10:05:41 +02:00
|
|
|
{
|
|
|
|
struct device *curdev;
|
2010-11-05 00:23:47 +01:00
|
|
|
|
2010-06-10 00:41:35 +02:00
|
|
|
for (curdev = all_devices; curdev; curdev = curdev->next) {
|
2010-05-21 16:33:48 +02:00
|
|
|
struct resource *res;
|
2010-11-05 00:23:47 +01:00
|
|
|
|
|
|
|
/* Ignore disabled devices. */
|
|
|
|
if (!curdev->enabled)
|
|
|
|
continue;
|
|
|
|
|
2010-06-10 00:41:35 +02:00
|
|
|
for (res = curdev->resource_list; res; res = res->next) {
|
2010-11-05 00:23:47 +01:00
|
|
|
/* If it isn't the right kind of resource ignore it. */
|
|
|
|
if ((res->flags & type_mask) != type)
|
2004-10-30 10:05:41 +02:00
|
|
|
continue;
|
2010-11-05 00:23:47 +01:00
|
|
|
|
|
|
|
/* If it is a subtractive resource ignore it. */
|
|
|
|
if (res->flags & IORESOURCE_SUBTRACTIVE)
|
2004-10-30 10:05:41 +02:00
|
|
|
continue;
|
2010-11-05 00:23:47 +01:00
|
|
|
|
2010-05-21 16:33:48 +02:00
|
|
|
search(gp, curdev, res);
|
2004-10-30 10:05:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-07-08 04:49:49 +02:00
|
|
|
|
2017-11-10 18:47:54 +01:00
|
|
|
void dev_set_enabled(struct device *dev, int enable)
|
2005-07-08 04:49:49 +02:00
|
|
|
{
|
2010-11-05 00:23:47 +01:00
|
|
|
if (dev->enabled == enable)
|
2005-07-08 04:49:49 +02:00
|
|
|
return;
|
2010-11-05 00:23:47 +01:00
|
|
|
|
2005-07-08 04:49:49 +02:00
|
|
|
dev->enabled = enable;
|
|
|
|
if (dev->ops && dev->ops->enable) {
|
|
|
|
dev->ops->enable(dev);
|
2010-11-05 00:23:47 +01:00
|
|
|
} else if (dev->chip_ops && dev->chip_ops->enable_dev) {
|
2005-07-08 04:49:49 +02:00
|
|
|
dev->chip_ops->enable_dev(dev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void disable_children(struct bus *bus)
|
|
|
|
{
|
2017-11-10 18:47:54 +01:00
|
|
|
struct device *child;
|
2010-11-05 00:23:47 +01:00
|
|
|
|
2010-06-10 00:41:35 +02:00
|
|
|
for (child = bus->children; child; child = child->sibling) {
|
|
|
|
struct bus *link;
|
2010-11-05 00:23:47 +01:00
|
|
|
for (link = child->link_list; link; link = link->next)
|
2010-06-10 00:41:35 +02:00
|
|
|
disable_children(link);
|
2005-07-08 04:49:49 +02:00
|
|
|
dev_set_enabled(child, 0);
|
|
|
|
}
|
|
|
|
}
|
2009-05-12 00:45:35 +02:00
|
|
|
|
2017-05-22 18:30:27 +02:00
|
|
|
/*
|
|
|
|
* Returns true if the device is an enabled bridge that has at least
|
2019-04-24 09:35:51 +02:00
|
|
|
* one enabled device on its secondary bus that is not of type NONE.
|
2017-05-22 18:30:27 +02:00
|
|
|
*/
|
2017-11-10 18:47:54 +01:00
|
|
|
bool dev_is_active_bridge(struct device *dev)
|
2017-05-22 18:30:27 +02:00
|
|
|
{
|
|
|
|
struct bus *link;
|
2017-11-10 18:47:54 +01:00
|
|
|
struct device *child;
|
2017-05-22 18:30:27 +02:00
|
|
|
|
|
|
|
if (!dev || !dev->enabled)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!dev->link_list || !dev->link_list->children)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for (link = dev->link_list; link; link = link->next) {
|
|
|
|
for (child = link->children; child; child = child->sibling) {
|
2019-04-24 09:35:51 +02:00
|
|
|
if (child->path.type == DEVICE_PATH_NONE)
|
|
|
|
continue;
|
|
|
|
|
2017-05-22 18:30:27 +02:00
|
|
|
if (child->enabled)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-06-06 01:03:30 +02:00
|
|
|
/**
|
|
|
|
* Ensure the device has a minimum number of bus links.
|
|
|
|
*
|
|
|
|
* @param dev The device to add links to.
|
|
|
|
* @param total_links The minimum number of links to have.
|
|
|
|
*/
|
|
|
|
void add_more_links(struct device *dev, unsigned int total_links)
|
2019-06-06 00:32:28 +02:00
|
|
|
{
|
|
|
|
struct bus *link, *last = NULL;
|
|
|
|
int link_num = -1;
|
|
|
|
|
|
|
|
for (link = dev->link_list; link; link = link->next) {
|
|
|
|
if (link_num < link->link_num)
|
|
|
|
link_num = link->link_num;
|
|
|
|
last = link;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (last) {
|
|
|
|
int links = total_links - (link_num + 1);
|
|
|
|
if (links > 0) {
|
2019-06-06 01:03:30 +02:00
|
|
|
link = malloc(links * sizeof(*link));
|
2019-06-06 00:32:28 +02:00
|
|
|
if (!link)
|
|
|
|
die("Couldn't allocate more links!\n");
|
2019-06-06 01:03:30 +02:00
|
|
|
memset(link, 0, links * sizeof(*link));
|
2019-06-06 00:32:28 +02:00
|
|
|
last->next = link;
|
2019-06-06 01:03:30 +02:00
|
|
|
} else {
|
|
|
|
/* No more links to add */
|
|
|
|
return;
|
2019-06-06 00:32:28 +02:00
|
|
|
}
|
|
|
|
} else {
|
2019-06-06 01:03:30 +02:00
|
|
|
link = malloc(total_links * sizeof(*link));
|
|
|
|
if (!link)
|
|
|
|
die("Couldn't allocate more links!\n");
|
|
|
|
memset(link, 0, total_links * sizeof(*link));
|
2019-06-06 00:32:28 +02:00
|
|
|
dev->link_list = link;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (link_num = link_num + 1; link_num < total_links; link_num++) {
|
|
|
|
link->link_num = link_num;
|
|
|
|
link->dev = dev;
|
|
|
|
link->next = link + 1;
|
|
|
|
last = link;
|
|
|
|
link = link->next;
|
|
|
|
}
|
|
|
|
last->next = NULL;
|
|
|
|
}
|
|
|
|
|
2018-04-26 00:00:22 +02:00
|
|
|
static void resource_tree(const struct device *root, int debug_level, int depth)
|
2009-05-12 00:45:35 +02:00
|
|
|
{
|
2010-06-10 00:41:35 +02:00
|
|
|
int i = 0;
|
2009-05-12 00:45:35 +02:00
|
|
|
struct device *child;
|
2010-06-10 00:41:35 +02:00
|
|
|
struct bus *link;
|
2010-05-21 16:33:48 +02:00
|
|
|
struct resource *res;
|
2009-05-12 00:45:35 +02:00
|
|
|
char indent[30]; /* If your tree has more levels, it's wrong. */
|
|
|
|
|
|
|
|
for (i = 0; i < depth + 1 && i < 29; i++)
|
|
|
|
indent[i] = ' ';
|
|
|
|
indent[i] = '\0';
|
|
|
|
|
2017-07-24 00:22:25 +02:00
|
|
|
do_printk(BIOS_DEBUG, "%s%s", indent, dev_path(root));
|
|
|
|
if (root->link_list && root->link_list->children)
|
|
|
|
do_printk(BIOS_DEBUG, " child on link 0 %s",
|
|
|
|
dev_path(root->link_list->children));
|
|
|
|
do_printk(BIOS_DEBUG, "\n");
|
2010-06-10 00:41:35 +02:00
|
|
|
|
2010-05-21 16:33:48 +02:00
|
|
|
for (res = root->resource_list; res; res = res->next) {
|
2010-11-05 00:23:47 +01:00
|
|
|
do_printk(debug_level, "%s%s resource base %llx size %llx "
|
|
|
|
"align %d gran %d limit %llx flags %lx index %lx\n",
|
|
|
|
indent, dev_path(root), res->base, res->size,
|
|
|
|
res->align, res->gran, res->limit, res->flags,
|
|
|
|
res->index);
|
2009-05-12 00:45:35 +02:00
|
|
|
}
|
|
|
|
|
2010-06-10 00:41:35 +02:00
|
|
|
for (link = root->link_list; link; link = link->next) {
|
|
|
|
for (child = link->children; child; child = child->sibling)
|
2009-05-12 00:45:35 +02:00
|
|
|
resource_tree(child, debug_level, depth + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-06 20:32:23 +02:00
|
|
|
void print_resource_tree(const struct device *root, int debug_level,
|
|
|
|
const char *msg)
|
2009-05-12 00:45:35 +02:00
|
|
|
{
|
|
|
|
/* Bail if root is null. */
|
|
|
|
if (!root) {
|
|
|
|
do_printk(debug_level, "%s passed NULL for root!\n", __func__);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Bail if not printing to screen. */
|
|
|
|
if (!do_printk(debug_level, "Show resources in subtree (%s)...%s\n",
|
2010-11-05 00:23:47 +01:00
|
|
|
dev_path(root), msg))
|
2009-05-12 00:45:35 +02:00
|
|
|
return;
|
2010-11-05 00:23:47 +01:00
|
|
|
|
2009-05-12 00:45:35 +02:00
|
|
|
resource_tree(root, debug_level, 0);
|
|
|
|
}
|
|
|
|
|
2018-04-26 00:00:22 +02:00
|
|
|
void show_devs_tree(const struct device *dev, int debug_level, int depth)
|
2009-05-12 00:45:35 +02:00
|
|
|
{
|
2014-02-15 00:42:49 +01:00
|
|
|
char depth_str[20];
|
2009-05-12 00:45:35 +02:00
|
|
|
int i;
|
|
|
|
struct device *sibling;
|
2010-06-10 00:41:35 +02:00
|
|
|
struct bus *link;
|
|
|
|
|
2009-05-12 00:45:35 +02:00
|
|
|
for (i = 0; i < depth; i++)
|
|
|
|
depth_str[i] = ' ';
|
|
|
|
depth_str[i] = '\0';
|
2010-11-05 00:23:47 +01:00
|
|
|
|
2010-05-21 16:33:48 +02:00
|
|
|
do_printk(debug_level, "%s%s: enabled %d\n",
|
|
|
|
depth_str, dev_path(dev), dev->enabled);
|
2010-11-05 00:23:47 +01:00
|
|
|
|
2010-06-10 00:41:35 +02:00
|
|
|
for (link = dev->link_list; link; link = link->next) {
|
|
|
|
for (sibling = link->children; sibling;
|
2009-05-12 00:45:35 +02:00
|
|
|
sibling = sibling->sibling)
|
2016-08-15 09:04:21 +02:00
|
|
|
show_devs_tree(sibling, debug_level, depth + 1);
|
2009-05-12 00:45:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void show_all_devs_tree(int debug_level, const char *msg)
|
|
|
|
{
|
|
|
|
/* Bail if not printing to screen. */
|
2015-02-12 00:29:32 +01:00
|
|
|
if (!do_printk(debug_level, "Show all devs in tree form... %s\n", msg))
|
2009-05-12 00:45:35 +02:00
|
|
|
return;
|
2016-08-15 09:04:21 +02:00
|
|
|
show_devs_tree(all_devices, debug_level, 0);
|
2009-05-12 00:45:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void show_devs_subtree(struct device *root, int debug_level, const char *msg)
|
|
|
|
{
|
|
|
|
/* Bail if not printing to screen. */
|
2015-02-12 00:29:32 +01:00
|
|
|
if (!do_printk(debug_level, "Show all devs in subtree %s... %s\n",
|
2010-11-05 00:23:47 +01:00
|
|
|
dev_path(root), msg))
|
2009-05-12 00:45:35 +02:00
|
|
|
return;
|
|
|
|
do_printk(debug_level, "%s\n", msg);
|
2016-08-15 09:04:21 +02:00
|
|
|
show_devs_tree(root, debug_level, 0);
|
2009-05-12 00:45:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void show_all_devs(int debug_level, const char *msg)
|
|
|
|
{
|
|
|
|
struct device *dev;
|
|
|
|
|
|
|
|
/* Bail if not printing to screen. */
|
2015-02-12 00:29:32 +01:00
|
|
|
if (!do_printk(debug_level, "Show all devs... %s\n", msg))
|
2009-05-12 00:45:35 +02:00
|
|
|
return;
|
|
|
|
for (dev = all_devices; dev; dev = dev->next) {
|
2010-05-21 16:33:48 +02:00
|
|
|
do_printk(debug_level, "%s: enabled %d\n",
|
|
|
|
dev_path(dev), dev->enabled);
|
2009-05-12 00:45:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void show_one_resource(int debug_level, struct device *dev,
|
|
|
|
struct resource *resource, const char *comment)
|
|
|
|
{
|
|
|
|
char buf[10];
|
|
|
|
unsigned long long base, end;
|
|
|
|
base = resource->base;
|
|
|
|
end = resource_end(resource);
|
|
|
|
buf[0] = '\0';
|
2010-11-05 00:23:47 +01:00
|
|
|
|
|
|
|
do_printk(debug_level, "%s %02lx <- [0x%010llx - 0x%010llx] "
|
2012-03-11 19:31:03 +01:00
|
|
|
"size 0x%08llx gran 0x%02x %s%s%s\n", dev_path(dev),
|
2010-11-05 00:23:47 +01:00
|
|
|
resource->index, base, end, resource->size, resource->gran,
|
|
|
|
buf, resource_type(resource), comment);
|
2009-05-12 00:45:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void show_all_devs_resources(int debug_level, const char* msg)
|
|
|
|
{
|
|
|
|
struct device *dev;
|
|
|
|
|
2015-02-12 00:29:32 +01:00
|
|
|
if (!do_printk(debug_level, "Show all devs with resources... %s\n", msg))
|
2009-05-12 00:45:35 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
for (dev = all_devices; dev; dev = dev->next) {
|
2010-05-21 16:33:48 +02:00
|
|
|
struct resource *res;
|
|
|
|
do_printk(debug_level, "%s: enabled %d\n",
|
|
|
|
dev_path(dev), dev->enabled);
|
|
|
|
for (res = dev->resource_list; res; res = res->next)
|
|
|
|
show_one_resource(debug_level, dev, res, "");
|
2009-05-12 00:45:35 +02:00
|
|
|
}
|
|
|
|
}
|
2010-10-11 21:36:13 +02:00
|
|
|
|
2017-11-10 18:47:54 +01:00
|
|
|
void fixed_mem_resource(struct device *dev, unsigned long index,
|
2018-05-06 20:32:23 +02:00
|
|
|
unsigned long basek, unsigned long sizek,
|
|
|
|
unsigned long type)
|
2010-10-11 21:36:13 +02:00
|
|
|
{
|
|
|
|
struct resource *resource;
|
|
|
|
|
|
|
|
if (!sizek)
|
|
|
|
return;
|
|
|
|
|
|
|
|
resource = new_resource(dev, index);
|
|
|
|
resource->base = ((resource_t)basek) << 10;
|
|
|
|
resource->size = ((resource_t)sizek) << 10;
|
2012-07-27 07:37:12 +02:00
|
|
|
resource->flags = IORESOURCE_MEM | IORESOURCE_FIXED |
|
|
|
|
IORESOURCE_STORED | IORESOURCE_ASSIGNED;
|
2012-07-10 12:27:26 +02:00
|
|
|
|
2012-07-27 07:37:12 +02:00
|
|
|
resource->flags |= type;
|
2012-07-10 12:27:26 +02:00
|
|
|
}
|
|
|
|
|
2019-03-15 12:48:44 +01:00
|
|
|
void fixed_io_resource(struct device *dev, unsigned long index,
|
|
|
|
unsigned long base, unsigned long size)
|
|
|
|
{
|
|
|
|
struct resource *resource;
|
|
|
|
|
|
|
|
resource = new_resource(dev, index);
|
|
|
|
resource->base = (resource_t)base;
|
|
|
|
resource->size = (resource_t)size;
|
|
|
|
resource->limit = resource->base + resource->size - 1;
|
|
|
|
resource->flags = IORESOURCE_IO | IORESOURCE_FIXED |
|
|
|
|
IORESOURCE_STORED | IORESOURCE_ASSIGNED |
|
|
|
|
IORESOURCE_RESERVE;
|
|
|
|
}
|
|
|
|
|
2016-12-02 07:56:05 +01:00
|
|
|
void mmconf_resource_init(struct resource *resource, resource_t base,
|
|
|
|
int buses)
|
|
|
|
{
|
|
|
|
resource->base = base;
|
|
|
|
resource->size = buses * MiB;
|
|
|
|
resource->flags = IORESOURCE_MEM | IORESOURCE_RESERVE |
|
|
|
|
IORESOURCE_FIXED | IORESOURCE_STORED | IORESOURCE_ASSIGNED;
|
|
|
|
|
|
|
|
printk(BIOS_DEBUG, "Adding PCIe enhanced config space BAR "
|
|
|
|
"0x%08lx-0x%08lx.\n", (unsigned long)(resource->base),
|
|
|
|
(unsigned long)(resource->base + resource->size));
|
|
|
|
}
|
|
|
|
|
|
|
|
void mmconf_resource(struct device *dev, unsigned long index)
|
|
|
|
{
|
|
|
|
struct resource *resource = new_resource(dev, index);
|
|
|
|
mmconf_resource_init(resource, CONFIG_MMCONF_BASE_ADDRESS,
|
|
|
|
CONFIG_MMCONF_BUS_NUMBER);
|
|
|
|
}
|
|
|
|
|
2010-10-11 21:36:13 +02:00
|
|
|
void tolm_test(void *gp, struct device *dev, struct resource *new)
|
|
|
|
{
|
|
|
|
struct resource **best_p = gp;
|
|
|
|
struct resource *best;
|
|
|
|
|
|
|
|
best = *best_p;
|
|
|
|
|
2020-05-19 01:00:53 +02:00
|
|
|
/*
|
|
|
|
* If resource is not allocated any space i.e. size is zero,
|
|
|
|
* then do not consider this resource in tolm calculations.
|
|
|
|
*/
|
|
|
|
if (new->size == 0)
|
|
|
|
return;
|
|
|
|
|
2010-10-11 21:36:13 +02:00
|
|
|
if (!best || (best->base > new->base))
|
|
|
|
best = new;
|
|
|
|
|
|
|
|
*best_p = best;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 find_pci_tolm(struct bus *bus)
|
|
|
|
{
|
|
|
|
struct resource *min = NULL;
|
|
|
|
u32 tolm;
|
2020-05-19 01:00:53 +02:00
|
|
|
unsigned long mask_match = IORESOURCE_MEM | IORESOURCE_ASSIGNED;
|
2010-10-11 21:36:13 +02:00
|
|
|
|
2020-05-19 01:00:53 +02:00
|
|
|
search_bus_resources(bus, mask_match, mask_match, tolm_test, &min);
|
2010-10-11 21:36:13 +02:00
|
|
|
|
|
|
|
tolm = 0xffffffffUL;
|
|
|
|
|
|
|
|
if (min && tolm > min->base)
|
|
|
|
tolm = min->base;
|
|
|
|
|
|
|
|
return tolm;
|
|
|
|
}
|
2012-03-30 22:52:58 +02:00
|
|
|
|
|
|
|
/* Count of enabled CPUs */
|
|
|
|
int dev_count_cpu(void)
|
|
|
|
{
|
2017-11-10 18:47:54 +01:00
|
|
|
struct device *cpu;
|
2012-03-30 22:52:58 +02:00
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
for (cpu = all_devices; cpu; cpu = cpu->next) {
|
|
|
|
if ((cpu->path.type != DEVICE_PATH_APIC) ||
|
2013-02-13 00:20:54 +01:00
|
|
|
(cpu->bus->dev->path.type != DEVICE_PATH_CPU_CLUSTER))
|
2012-03-30 22:52:58 +02:00
|
|
|
continue;
|
|
|
|
if (!cpu->enabled)
|
|
|
|
continue;
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
2016-02-13 15:10:04 +01:00
|
|
|
|
|
|
|
/* Get device path name */
|
|
|
|
const char *dev_path_name(enum device_path_type type)
|
|
|
|
{
|
|
|
|
static const char *const type_names[] = DEVICE_PATH_NAMES;
|
|
|
|
const char *type_name = "Unknown";
|
|
|
|
|
|
|
|
/* Translate the type value into a string */
|
|
|
|
if (type < ARRAY_SIZE(type_names))
|
|
|
|
type_name = type_names[type];
|
|
|
|
return type_name;
|
|
|
|
}
|