Run indent on all the code in device/ to fix the coding style.

Various additional cosmetic fixes and corrected typos (trivial).

Signed-off-by: Uwe Hermann <uwe@hermann-uwe.de>
Acked-by: Uwe Hermann <uwe@hermann-uwe.de>



git-svn-id: svn://coreboot.org/repository/LinuxBIOSv3@297 f3766cd6-281f-0410-b1cd-43a5c92072e9
This commit is contained in:
Uwe Hermann 2007-05-01 20:52:09 +00:00
commit 31fa35e06a
13 changed files with 1676 additions and 1555 deletions

View file

@ -26,23 +26,22 @@
static void agp_tune_dev(device_t dev)
{
unsigned cap;
unsigned int cap;
cap = pci_find_capability(dev, PCI_CAP_ID_AGP);
if (!cap) {
return;
}
/* The OS is responsible for AGP tuning so do nothing here */
/* The OS is responsible for AGP tuning so do nothing here. */
}
unsigned int agp_scan_bus(struct bus *bus,
unsigned min_devfn, unsigned max_devfn, unsigned int max)
unsigned int agp_scan_bus(struct bus *bus, unsigned int min_devfn,
unsigned int max_devfn, unsigned int max)
{
device_t child;
max = pci_scan_bus(bus, min_devfn, max_devfn, max);
for(child = bus->children; child; child = child->sibling) {
if ( (child->path.u.pci.devfn < min_devfn) ||
(child->path.u.pci.devfn > max_devfn))
{
for (child = bus->children; child; child = child->sibling) {
if ((child->path.u.pci.devfn < min_devfn) ||
(child->path.u.pci.devfn > max_devfn)) {
continue;
}
agp_tune_dev(child);
@ -55,7 +54,7 @@ unsigned int agp_scan_bridge(device_t dev, unsigned int max)
return do_pci_scan_bridge(dev, max, agp_scan_bus);
}
/** Default device operations for AGP bridges */
/** Default device operations for AGP bridges. */
static struct pci_operations agp_bus_ops_pci = {
.set_subsystem = 0,
};
@ -64,8 +63,8 @@ struct device_operations default_agp_ops_bus = {
.read_resources = pci_bus_read_resources,
.set_resources = pci_dev_set_resources,
.enable_resources = pci_bus_enable_resources,
.init = 0,
.scan_bus = agp_scan_bridge,
.init = 0,
.scan_bus = agp_scan_bridge,
.enable = 0,
.reset_bus = pci_bus_reset,
.ops_pci = &agp_bus_ops_pci,

View file

@ -30,18 +30,18 @@
* to make it usable quickly. -- Eric Biederman 24 March 2005
*/
/*
* IO should be max 256 bytes. However, since we may
/**
* I/O should be max. 256 bytes. However, since we may
* have a P2P bridge below a cardbus bridge, we need 4K.
*/
#define CARDBUS_IO_SIZE (4096)
#define CARDBUS_MEM_SIZE (32*1024*1024)
static void cardbus_record_bridge_resource(
device_t dev, resource_t moving, resource_t min_size,
unsigned index, unsigned long type)
static void cardbus_record_bridge_resource(device_t dev, resource_t moving,
resource_t min_size, unsigned int index,
unsigned long type)
{
/* Initiliaze the constraints on the current bus */
/* Initiliaze the constraints on the current bus. */
struct resource *resource;
resource = 0;
if (moving) {
@ -51,7 +51,7 @@ static void cardbus_record_bridge_resource(
resource->size = 0;
gran = 0;
step = 1;
while((moving & step) == 0) {
while ((moving & step) == 0) {
gran += 1;
step <<= 1;
}
@ -70,16 +70,16 @@ static void cardbus_record_bridge_resource(
return;
}
static void cardbus_size_bridge_resource(device_t dev, unsigned index)
static void cardbus_size_bridge_resource(device_t dev, unsigned int index)
{
struct resource *resource;
resource_t min_size;
resource = find_resource(dev, index);
if (resource) {
min_size = resource->size;
compute_allocate_resource(&dev->link[0], resource,
resource->flags, resource->flags);
/* Allways allocate at least the miniumum size to a
compute_allocate_resource(&dev->link[0], resource,
resource->flags, resource->flags);
/* Always allocate at least the minimum size to a
* cardbus bridge in case a new card is plugged in.
*/
if (resource->size < min_size) {
@ -93,34 +93,34 @@ void cardbus_read_resources(device_t dev)
resource_t moving_base, moving_limit, moving;
unsigned long type;
u16 ctl;
unsigned long index;
unsigned long index;
/* See if needs a card control registers base address */
/* See if needs a card control registers base address. */
pci_get_resource(dev, PCI_BASE_ADDRESS_0);
compact_resources(dev);
/* See which bridge I/O resources are implemented */
moving_base = pci_moving_config32(dev, PCI_CB_IO_BASE_0);
/* See which bridge I/O resources are implemented. */
moving_base = pci_moving_config32(dev, PCI_CB_IO_BASE_0);
moving_limit = pci_moving_config32(dev, PCI_CB_IO_LIMIT_0);
moving = moving_base & moving_limit;
/* Initialize the io space constraints on the current bus */
/* Initialize the I/O space constraints on the current bus. */
cardbus_record_bridge_resource(dev, moving, CARDBUS_IO_SIZE,
PCI_CB_IO_BASE_0, IORESOURCE_IO);
PCI_CB_IO_BASE_0, IORESOURCE_IO);
cardbus_size_bridge_resource(dev, PCI_CB_IO_BASE_0);
/* See which bridge I/O resources are implemented */
moving_base = pci_moving_config32(dev, PCI_CB_IO_BASE_1);
/* See which bridge I/O resources are implemented. */
moving_base = pci_moving_config32(dev, PCI_CB_IO_BASE_1);
moving_limit = pci_moving_config32(dev, PCI_CB_IO_LIMIT_1);
moving = moving_base & moving_limit;
/* Initialize the io space constraints on the current bus */
/* Initialize the I/O space constraints on the current bus. */
cardbus_record_bridge_resource(dev, moving, CARDBUS_IO_SIZE,
PCI_CB_IO_BASE_1, IORESOURCE_IO);
PCI_CB_IO_BASE_1, IORESOURCE_IO);
/* If I can enable prefetch for mem0 */
/* If I can enable prefetch for mem0. */
ctl = pci_read_config16(dev, PCI_CB_BRIDGE_CONTROL);
ctl &= ~PCI_CB_BRIDGE_CTL_PREFETCH_MEM0;
ctl &= ~PCI_CB_BRIDGE_CTL_PREFETCH_MEM1;
@ -128,30 +128,30 @@ void cardbus_read_resources(device_t dev)
pci_write_config16(dev, PCI_CB_BRIDGE_CONTROL, ctl);
ctl = pci_read_config16(dev, PCI_CB_BRIDGE_CONTROL);
/* See which bridge memory resources are implemented */
moving_base = pci_moving_config32(dev, PCI_CB_MEMORY_BASE_0);
/* See which bridge memory resources are implemented. */
moving_base = pci_moving_config32(dev, PCI_CB_MEMORY_BASE_0);
moving_limit = pci_moving_config32(dev, PCI_CB_MEMORY_LIMIT_0);
moving = moving_base & moving_limit;
/* Initialize the memory space constraints on the current bus */
/* Initialize the memory space constraints on the current bus. */
type = IORESOURCE_MEM;
if (ctl & PCI_CB_BRIDGE_CTL_PREFETCH_MEM0) {
type |= IORESOURCE_PREFETCH;
}
cardbus_record_bridge_resource(dev, moving, CARDBUS_MEM_SIZE,
PCI_CB_MEMORY_BASE_0, type);
PCI_CB_MEMORY_BASE_0, type);
if (type & IORESOURCE_PREFETCH) {
cardbus_size_bridge_resource(dev, PCI_CB_MEMORY_BASE_0);
}
/* See which bridge memory resources are implemented */
moving_base = pci_moving_config32(dev, PCI_CB_MEMORY_BASE_1);
/* See which bridge memory resources are implemented. */
moving_base = pci_moving_config32(dev, PCI_CB_MEMORY_BASE_1);
moving_limit = pci_moving_config32(dev, PCI_CB_MEMORY_LIMIT_1);
moving = moving_base & moving_limit;
/* Initialize the memory space constraints on the current bus */
/* Initialize the memory space constraints on the current bus. */
cardbus_record_bridge_resource(dev, moving, CARDBUS_MEM_SIZE,
PCI_CB_MEMORY_BASE_1, IORESOURCE_MEM);
PCI_CB_MEMORY_BASE_1, IORESOURCE_MEM);
cardbus_size_bridge_resource(dev, PCI_CB_MEMORY_BASE_1);
compact_resources(dev);
@ -161,14 +161,16 @@ void cardbus_enable_resources(device_t dev)
{
u16 ctrl;
ctrl = pci_read_config16(dev, PCI_CB_BRIDGE_CONTROL);
ctrl |= (dev->link[0].bridge_ctrl & (
PCI_BRIDGE_CTL_PARITY |
PCI_BRIDGE_CTL_SERR |
PCI_BRIDGE_CTL_NO_ISA |
PCI_BRIDGE_CTL_VGA |
PCI_BRIDGE_CTL_MASTER_ABORT |
PCI_BRIDGE_CTL_BUS_RESET));
ctrl |= (PCI_CB_BRIDGE_CTL_PARITY + PCI_CB_BRIDGE_CTL_SERR); /* error check */
ctrl |= (dev->link[0].bridge_ctrl & (PCI_BRIDGE_CTL_PARITY |
PCI_BRIDGE_CTL_SERR |
PCI_BRIDGE_CTL_NO_ISA |
PCI_BRIDGE_CTL_VGA |
PCI_BRIDGE_CTL_MASTER_ABORT |
PCI_BRIDGE_CTL_BUS_RESET));
/* Error check. */
ctrl |= (PCI_CB_BRIDGE_CTL_PARITY + PCI_CB_BRIDGE_CTL_SERR);
printk_debug("%s bridge ctrl <- %04x\n", dev_path(dev), ctrl);
pci_write_config16(dev, PCI_BRIDGE_CONTROL, ctrl);
@ -177,14 +179,12 @@ void cardbus_enable_resources(device_t dev)
enable_childrens_resources(dev);
}
unsigned int cardbus_scan_bus(struct bus *bus,
unsigned min_devfn, unsigned max_devfn,
unsigned int max)
unsigned int cardbus_scan_bus(struct bus *bus, unsigned int min_devfn,
unsigned int max_devfn, unsigned int max)
{
return pci_scan_bus(bus, min_devfn, max_devfn, max);
}
unsigned int cardbus_scan_bridge(device_t dev, unsigned int max)
{
struct bus *bus;
@ -209,8 +209,7 @@ unsigned int cardbus_scan_bridge(device_t dev, unsigned int max)
pci_write_config16(dev, PCI_COMMAND, 0x0000);
pci_write_config16(dev, PCI_STATUS, 0xffff);
/*
* Read the existing primary/secondary/subordinate bus
/* Read the existing primary/secondary/subordinate bus
* number configuration.
*/
buses = pci_read_config32(dev, PCI_CB_PRIMARY_BUS);
@ -220,12 +219,12 @@ unsigned int cardbus_scan_bridge(device_t dev, unsigned int max)
* correctly configured.
*/
buses &= 0xff000000;
buses |= (((unsigned int) (dev->bus->secondary) << 0) |
((unsigned int) (bus->secondary) << 8) |
((unsigned int) (bus->subordinate) << 16));
buses |= (((unsigned int)(dev->bus->secondary) << 0) |
((unsigned int)(bus->secondary) << 8) |
((unsigned int)(bus->subordinate) << 16));
pci_write_config32(dev, PCI_CB_PRIMARY_BUS, buses);
/* Now we can scan all subordinate buses
/* Now we can scan all subordinate buses
* i.e. the bus behind the bridge.
*/
max = cardbus_scan_bus(bus, 0x00, 0xff, max);
@ -234,11 +233,10 @@ unsigned int cardbus_scan_bridge(device_t dev, unsigned int max)
* bus number to its real value.
*/
bus->subordinate = max;
buses = (buses & 0xff00ffff) |
((unsigned int) (bus->subordinate) << 16);
buses = (buses & 0xff00ffff) | ((unsigned int)(bus->subordinate) << 16);
pci_write_config32(dev, PCI_CB_PRIMARY_BUS, buses);
pci_write_config16(dev, PCI_COMMAND, cr);
printk_spew("%s returns max %d\n", __func__, max);
return max;
}
@ -247,8 +245,8 @@ struct device_operations default_cardbus_ops_bus = {
.read_resources = cardbus_read_resources,
.set_resources = pci_dev_set_resources,
.enable_resources = cardbus_enable_resources,
.init = 0,
.scan_bus = cardbus_scan_bridge,
.init = 0,
.scan_bus = cardbus_scan_bridge,
.enable = 0,
.reset_bus = pci_bus_reset,
};

File diff suppressed because it is too large Load diff

View file

@ -31,17 +31,17 @@
#include <string.h>
/**
* @brief See if a device structure exists for path
* See if a device structure exists for path.
*
* @param bus The bus to find the device on
* @param path The relative path from the bus to the appropriate device
* @return pointer to a device structure for the device on bus at path
* or 0/NULL if no device is found
* @param bus The bus to find the device on.
* @param path The relative path from the bus to the appropriate device.
* @return Pointer to a device structure for the device on bus at path
* or 0/NULL if no device is found.
*/
struct device * find_dev_path(struct bus *parent, struct device_path *path)
struct device *find_dev_path(struct bus *parent, struct device_path *path)
{
struct device * child;
for(child = parent->children; child; child = child->sibling) {
struct device *child;
for (child = parent->children; child; child = child->sibling) {
if (path_eq(path, &child->path)) {
break;
}
@ -50,15 +50,16 @@ struct device * find_dev_path(struct bus *parent, struct device_path *path)
}
/**
* @brief See if a device structure already exists and if not allocate it
* See if a device structure already exists and if not allocate it.
*
* @param bus The bus to find the device on
* @param path The relative path from the bus to the appropriate device
* @return pointer to a device structure for the device on bus at path
* @param bus The bus to find the device on.
* @param path The relative path from the bus to the appropriate device.
* @return Pointer to a device structure for the device on bus at path.
*/
struct device * alloc_find_dev(struct bus *parent, struct device_path *path, struct device_id *id)
struct device *alloc_find_dev(struct bus *parent, struct device_path *path,
struct device_id *id)
{
struct device * child;
struct device *child;
child = find_dev_path(parent, path);
if (!child) {
child = alloc_dev(parent, path, id);
@ -67,11 +68,11 @@ struct device * alloc_find_dev(struct bus *parent, struct device_path *path, str
}
/**
* @brief Given a PCI bus and a devfn number, find the device structure
* Given a PCI bus and a devfn number, find the device structure.
*
* @param bus The bus number
* @param devfn a device/function number
* @return pointer to the device structure
* @param bus The bus number.
* @param devfn A device/function number.
* @return Pointer to the device structure.
*/
struct device *dev_find_slot(unsigned int bus, unsigned int devfn)
{
@ -80,8 +81,8 @@ struct device *dev_find_slot(unsigned int bus, unsigned int devfn)
result = 0;
for (dev = all_devices; dev; dev = dev->next) {
if ((dev->path.type == DEVICE_PATH_PCI) &&
(dev->bus->secondary == bus) &&
(dev->path.u.pci.devfn == devfn)) {
(dev->bus->secondary == bus) &&
(dev->path.u.pci.devfn == devfn)) {
result = dev;
break;
}
@ -90,37 +91,40 @@ struct device *dev_find_slot(unsigned int bus, unsigned int devfn)
}
/**
* @brief Given a smbus bus and a device number, find the device structure
* Given a smbus bus and a device number, find the device structure.
*
* @param bus The bus number
* @param addr a device number
* @return pointer to the device structure
* @param bus The bus number.
* @param addr A device number.
* @return Pointer to the device structure.
*/
struct device *dev_find_slot_on_smbus(unsigned int bus, unsigned int addr)
{
struct device *dev, *result;
result = 0;
for (dev = all_devices; dev; dev = dev->next) {
if ((dev->path.type == DEVICE_PATH_I2C) &&
(dev->bus->secondary == bus) &&
(dev->path.u.i2c.device == addr)) {
result = dev;
break;
}
}
return result;
}
struct device *dev, *result;
/** Find a device of a given vendor and type
result = 0;
for (dev = all_devices; dev; dev = dev->next) {
if ((dev->path.type == DEVICE_PATH_I2C) &&
(dev->bus->secondary == bus) &&
(dev->path.u.i2c.device == addr)) {
result = dev;
break;
}
}
return result;
}
/**
* Find a device of a given vendor and type.
*
* @param vendor Vendor ID (e.g. 0x8086 for Intel)
* @param device Device ID
* @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)
* @return Pointer to the device struct
* in the linked list of all_devices, which can be 0 to start
* at the head of the list (i.e. all_devices).
* @return Pointer to the device struct.
*/
struct device *dev_find_device(unsigned int vendor, unsigned int device, struct device *from)
struct device *dev_find_device(unsigned int vendor, unsigned int device,
struct device *from)
{
if (!from)
from = all_devices;
@ -132,12 +136,14 @@ struct device *dev_find_device(unsigned int vendor, unsigned int device, struct
return from;
}
/** Find a device of a given class
* @param class Class of the device
/**
* Find a device of a given class.
*
* @param class Class of the device.
* @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)
* @return Pointer to the device struct
* in the linked list of all_devices, which can be 0 to start
* at the head of the list (i.e. all_devices).
* @return Pointer to the device struct.
*/
struct device *dev_find_class(unsigned int class, struct device *from)
{
@ -150,29 +156,30 @@ struct device *dev_find_class(unsigned int class, struct device *from)
return from;
}
/* WARNING: NOT SMP-safe!*/
const char *dev_path(struct device * dev)
/* WARNING: NOT SMP-safe! */
const char *dev_path(struct device *dev)
{
static char buffer[DEVICE_PATH_MAX];
buffer[0] = '\0';
if (!dev) {
memcpy(buffer, "<null>", 7);
}
else {
switch(dev->path.type) {
} else {
switch (dev->path.type) {
case DEVICE_PATH_ROOT:
memcpy(buffer, "Root Device", 12);
break;
case DEVICE_PATH_PCI:
#if PCI_BUS_SEGN_BITS
sprintf(buffer, "PCI: %04x:%02x:%02x.%01x",
dev->bus->secondary>>8, dev->bus->secondary & 0xff,
PCI_SLOT(dev->path.u.pci.devfn), PCI_FUNC(dev->path.u.pci.devfn));
dev->bus->secondary >> 8,
dev->bus->secondary & 0xff,
PCI_SLOT(dev->path.u.pci.devfn),
PCI_FUNC(dev->path.u.pci.devfn));
#else
sprintf(buffer, "PCI: %02x:%02x.%01x",
dev->bus->secondary,
PCI_SLOT(dev->path.u.pci.devfn), PCI_FUNC(dev->path.u.pci.devfn));
dev->bus->secondary,
PCI_SLOT(dev->path.u.pci.devfn),
PCI_FUNC(dev->path.u.pci.devfn));
#endif
break;
case DEVICE_PATH_PNP:
@ -181,12 +188,10 @@ const char *dev_path(struct device * dev)
break;
case DEVICE_PATH_I2C:
sprintf(buffer, "I2C: %02x:%02x",
dev->bus->secondary,
dev->path.u.i2c.device);
dev->bus->secondary, dev->path.u.i2c.device);
break;
case DEVICE_PATH_APIC:
sprintf(buffer, "APIC: %02x",
dev->path.u.apic.apic_id);
sprintf(buffer, "APIC: %02x", dev->path.u.apic.apic_id);
break;
case DEVICE_PATH_PCI_DOMAIN:
sprintf(buffer, "PCI_DOMAIN: %04x",
@ -200,31 +205,33 @@ const char *dev_path(struct device * dev)
sprintf(buffer, "CPU: %02x", dev->path.u.cpu.id);
break;
case DEVICE_PATH_CPU_BUS:
sprintf(buffer, "CPU_BUS: %02x", dev->path.u.cpu_bus.id);
sprintf(buffer, "CPU_BUS: %02x",
dev->path.u.cpu_bus.id);
break;
default:
printk(BIOS_ERR, "%s: Unknown device path type: %d\n", dev->dtsname, dev->path.type);
printk(BIOS_ERR, "%s: Unknown device path type: %d\n",
dev->dtsname, dev->path.type);
break;
}
}
return buffer;
}
/* WARNING: NOT SMP-safe!*/
/* WARNING: NOT SMP-safe! */
const char *dev_id_string(struct device_id *id)
{
static char buffer[DEVICE_ID_MAX];
buffer[0] = '\0';
if (!id) {
memcpy(buffer, "<null>", 7);
}
else {
switch(id->type) {
} else {
switch (id->type) {
case DEVICE_ID_ROOT:
memcpy(buffer, "Root Device", 12);
break;
case DEVICE_ID_PCI:
sprintf(buffer, "PCI: %02x:%02x",id->u.pci.vendor, id->u.pci.device);
sprintf(buffer, "PCI: %02x:%02x", id->u.pci.vendor,
id->u.pci.device);
break;
case DEVICE_ID_PNP:
sprintf(buffer, "PNP: %04x", id->u.pnp.device);
@ -233,22 +240,30 @@ const char *dev_id_string(struct device_id *id)
sprintf(buffer, "I2C: %04x", id->u.i2c.id);
break;
case DEVICE_ID_APIC:
sprintf(buffer, "APIC: %02x:%02x",id->u.apic.vendor, id->u.apic.device);
sprintf(buffer, "APIC: %02x:%02x", id->u.apic.vendor,
id->u.apic.device);
break;
case DEVICE_ID_PCI_DOMAIN:
sprintf(buffer, "PCI_DOMAIN: %02x:%02x",id->u.pci_domain.vendor, id->u.pci_domain.device);
sprintf(buffer, "PCI_DOMAIN: %02x:%02x",
id->u.pci_domain.vendor,
id->u.pci_domain.device);
break;
case DEVICE_ID_APIC_CLUSTER:
sprintf(buffer, "APIC_CLUSTER: %02x:%02x",id->u.apic_cluster.vendor, id->u.apic_cluster.device);
sprintf(buffer, "APIC_CLUSTER: %02x:%02x",
id->u.apic_cluster.vendor,
id->u.apic_cluster.device);
break;
case DEVICE_ID_CPU:
sprintf(buffer, "CPU", id->u.cpu.cpuid[0], id->u.cpu.cpuid[1], id->u.cpu.cpuid[2]);
sprintf(buffer, "CPU", id->u.cpu.cpuid[0],
id->u.cpu.cpuid[1], id->u.cpu.cpuid[2]);
break;
case DEVICE_ID_CPU_BUS:
sprintf(buffer, "CPU_BUS: %02x:%02x",id->u.cpu_bus.vendor, id->u.cpu_bus.device);
sprintf(buffer, "CPU_BUS: %02x:%02x",
id->u.cpu_bus.vendor, id->u.cpu_bus.device);
break;
default:
printk(BIOS_ERR, "%s: Unknown device id type: %d\n", __func__, id->type);
printk(BIOS_ERR, "%s: Unknown device ID type: %d\n",
__func__, id->type);
memcpy(buffer, "Unknown", 8);
break;
}
@ -256,13 +271,10 @@ const char *dev_id_string(struct device_id *id)
return buffer;
}
const char *bus_path(struct bus *bus)
{
static char buffer[BUS_PATH_MAX];
sprintf(buffer, "%s,%d",
dev_path(bus->dev), bus->link);
sprintf(buffer, "%s,%d", dev_path(bus->dev), bus->link);
return buffer;
}
@ -270,7 +282,7 @@ int path_eq(struct device_path *path1, struct device_path *path2)
{
int equal = 0;
if (path1->type == path2->type) {
switch(path1->type) {
switch (path1->type) {
case DEVICE_PATH_NONE:
break;
case DEVICE_PATH_ROOT:
@ -281,19 +293,24 @@ int path_eq(struct device_path *path1, struct device_path *path2)
break;
case DEVICE_PATH_PNP:
equal = (path1->u.pnp.port == path2->u.pnp.port) &&
(path1->u.pnp.device == path2->u.pnp.device);
(path1->u.pnp.device == path2->u.pnp.device);
break;
case DEVICE_PATH_I2C:
equal = (path1->u.i2c.device == path2->u.i2c.device);
break;
case DEVICE_PATH_APIC:
equal = (path1->u.apic.apic_id == path2->u.apic.apic_id);
equal =
(path1->u.apic.apic_id == path2->u.apic.apic_id);
break;
case DEVICE_PATH_PCI_DOMAIN:
equal = (path1->u.pci_domain.domain == path2->u.pci_domain.domain);
equal =
(path1->u.pci_domain.domain ==
path2->u.pci_domain.domain);
break;
case DEVICE_PATH_APIC_CLUSTER:
equal = (path1->u.apic_cluster.cluster == path2->u.apic_cluster.cluster);
equal =
(path1->u.apic_cluster.cluster ==
path2->u.apic_cluster.cluster);
break;
case DEVICE_PATH_CPU:
equal = (path1->u.cpu.id == path2->u.cpu.id);
@ -302,7 +319,8 @@ int path_eq(struct device_path *path1, struct device_path *path2)
equal = (path1->u.cpu_bus.id == path2->u.cpu_bus.id);
break;
default:
printk(BIOS_ERR, "Unknown device type: %d\n", path1->type);
printk(BIOS_ERR, "Unknown device type: %d\n",
path1->type);
break;
}
}
@ -313,14 +331,15 @@ int id_eq(struct device_id *path1, struct device_id *path2)
{
int equal = 0;
if (path1->type == path2->type) {
switch(path1->type) {
switch (path1->type) {
case DEVICE_ID_NONE:
break;
case DEVICE_ID_ROOT:
equal = 1;
break;
case DEVICE_ID_PCI:
equal = (path1->u.pci.vendor == path2->u.pci.vendor) && (path1->u.pci.device == path2->u.pci.device);
equal = (path1->u.pci.vendor == path2->u.pci.vendor)
&& (path1->u.pci.device == path2->u.pci.device);
break;
case DEVICE_ID_PNP:
equal = (path1->u.pnp.device == path2->u.pnp.device);
@ -329,66 +348,82 @@ int id_eq(struct device_id *path1, struct device_id *path2)
equal = (path1->u.i2c.id == path2->u.i2c.id);
break;
case DEVICE_ID_APIC:
equal = (path1->u.apic.vendor == path2->u.apic.vendor) && (path1->u.apic.device == path2->u.apic.device);
equal = (path1->u.apic.vendor == path2->u.apic.vendor)
&& (path1->u.apic.device == path2->u.apic.device);
break;
case DEVICE_ID_PCI_DOMAIN:
equal = (path1->u.pci_domain.vendor == path2->u.pci_domain.vendor) && (path1->u.pci_domain.device == path2->u.pci_domain.device);
equal =
(path1->u.pci_domain.vendor ==
path2->u.pci_domain.vendor)
&& (path1->u.pci_domain.device ==
path2->u.pci_domain.device);
break;
case DEVICE_ID_APIC_CLUSTER:
equal = (path1->u.apic_cluster.vendor == path2->u.apic_cluster.vendor) && (path1->u.apic_cluster.device == path2->u.apic_cluster.device);
equal =
(path1->u.apic_cluster.vendor ==
path2->u.apic_cluster.vendor)
&& (path1->u.apic_cluster.device ==
path2->u.apic_cluster.device);
break;
case DEVICE_ID_CPU:
equal = (path1->u.cpu.cpuid == path2->u.cpu.cpuid);
break;
case DEVICE_ID_CPU_BUS:
equal = (path1->u.cpu_bus.vendor == path2->u.cpu_bus.vendor) && (path1->u.cpu_bus.device == path2->u.cpu_bus.device);
equal =
(path1->u.cpu_bus.vendor == path2->u.cpu_bus.vendor)
&& (path1->u.cpu_bus.device ==
path2->u.cpu_bus.device);
break;
default:
printk(BIOS_ERR, "Unknown device type: %d\n", path1->type);
printk(BIOS_ERR, "Unknown device type: %d\n",
path1->type);
break;
}
}
return equal;
}
/**
* See if we have unused but allocated resource structures.
* If so remove the allocation.
* @param dev The device to find the resource on
*
* @param dev The device to find the resource on.
*/
void compact_resources(struct device * dev)
void compact_resources(struct device *dev)
{
struct resource *resource;
int i;
/* Move all of the free resources to the end */
for(i = 0; i < dev->resources;) {
/* Move all of the free resources to the end. */
for (i = 0; i < dev->resources;) {
resource = &dev->resource[i];
if (!resource->flags) {
/* note: memmove was used here. But this can never overlap, right? */
/* Note: memmove() was used here. But this can never
* overlap, right?
*/
memcpy(resource, resource + 1, dev->resources - i);
dev->resources -= 1;
memset(&dev->resource[dev->resources], 0, sizeof(*resource));
memset(&dev->resource[dev->resources], 0,
sizeof(*resource));
} else {
i++;
}
}
}
/**
* 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
* 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.
*/
struct resource *probe_resource(struct device * dev, unsigned index)
struct resource *probe_resource(struct device *dev, unsigned int index)
{
struct resource *resource;
int i;
/* See if there is a resource with the appropriate index */
/* See if there is a resource with the appropriate index. */
resource = 0;
for(i = 0; i < dev->resources; i++) {
for (i = 0; i < dev->resources; i++) {
if (dev->resource[i].index == index) {
resource = &dev->resource[i];
break;
@ -399,19 +434,19 @@ struct resource *probe_resource(struct device * dev, unsigned index)
/**
* See if a resource structure already exists for a given index and if
* not allocate one. Then initialize the initialize the resource
* to default values.
* @param dev The device to find the resource on
* @param index The index of the resource on the device.
* not allocate one. Then initialize the resource to default values.
*
* @param dev The device to find the resource on.
* @param index The index of the resource on the device.
*/
struct resource *new_resource(struct device * dev, unsigned index)
struct resource *new_resource(struct device *dev, unsigned int index)
{
struct resource *resource;
/* First move all of the free resources to the end */
/* First move all of the free resources to the end. */
compact_resources(dev);
/* See if there is a resource with the appropriate index */
/* See if there is a resource with the appropriate index. */
resource = probe_resource(dev, index);
if (!resource) {
if (dev->resources == MAX_RESOURCES) {
@ -421,45 +456,46 @@ struct resource *new_resource(struct device * dev, unsigned index)
memset(resource, 0, sizeof(*resource));
dev->resources++;
}
/* Initialize the resource values */
/* Initialize the resource values. */
if (!(resource->flags & IORESOURCE_FIXED)) {
resource->flags = 0;
resource->base = 0;
}
resource->size = 0;
resource->size = 0;
resource->limit = 0;
resource->index = index;
resource->align = 0;
resource->gran = 0;
resource->gran = 0;
return resource;
}
/**
* Return an existing resource structure for a given index.
* @param dev The device to find the resource on
* @param index The index of the resource on the device.
*
* @param dev The device to find the resource on.
* @param index The index of the resource on the device.
*/
struct resource *find_resource(struct device * dev, unsigned index)
struct resource *find_resource(struct device *dev, unsigned int index)
{
struct resource *resource;
/* See if there is a resource with the appropriate index */
/* See if there is a resource with the appropriate index. */
resource = probe_resource(dev, index);
if (!resource) {
printk(BIOS_EMERG, "%s missing resource: %02x\n",
dev_path(dev), index);
dev_path(dev), index);
die("");
}
return resource;
}
/**
* @brief round a number up to the next multiple of gran
* @param val the starting value
* @param gran granularity we are aligning the number to.
* @returns aligned value
* Round a number up to the next multiple of gran.
*
* @param val The starting value.
* @param gran Granularity we are aligning the number to.
* @returns The aligned value.
*/
static resource_t align_up(resource_t val, unsigned long gran)
{
@ -471,10 +507,11 @@ static resource_t align_up(resource_t val, unsigned long gran)
}
/**
* @brief round a number up to the previous multiple of gran
* @param val the starting value
* @param gran granularity we are aligning the number to.
* @returns aligned value
* Round a number up to the previous multiple of gran.
*
* @param val The starting value.
* @param gran Granularity we are aligning the number to.
* @returns The aligned value.
*/
static resource_t align_down(resource_t val, unsigned long gran)
{
@ -485,67 +522,71 @@ static resource_t align_down(resource_t val, unsigned long gran)
}
/**
* @brief Compute the maximum address that is part of a resource
* @param resource the resource whose limit is desired
* @returns the end
* Compute the maximum address that is part of a resource.
*
* @param resource The resource whose limit is desired.
* @returns The end.
*/
resource_t resource_end(struct resource *resource)
{
resource_t base, end;
/* get the base address */
/* Get the base address. */
base = resource->base;
/* For a non bridge resource granularity and alignment are the same.
/* For a non-bridge resource granularity and alignment are the same.
* For a bridge resource align is the largest needed alignment below
* the bridge. While the granularity is simply how many low bits of the
* address cannot be set.
* the bridge. While the granularity is simply how many low bits of
* the address cannot be set.
*/
/* Get the end (rounded up) */
/* Get the end (rounded up). */
end = base + align_up(resource->size, resource->gran) - 1;
return end;
}
/**
* @brief Compute the maximum legal value for resource->base
* @param resource the resource whose maximum is desired
* @returns the maximum
* Compute the maximum legal value for resource->base.
*
* @param resource The resource whose maximum is desired.
* @returns The maximum.
*/
resource_t resource_max(struct resource *resource)
{
resource_t max;
max = align_down(resource->limit - resource->size + 1, resource->align);
return max;
}
/**
* @brief return the resource type of a resource
* @param resource the resource type to decode.
* Return the resource type of a resource.
*
* @param resource The resource type to decode.
*/
const char *resource_type(struct resource *resource)
{
static char buffer[RESOURCE_TYPE_MAX];
sprintf(buffer, "%s%s%s%s",
((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":""));
((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" : ""));
return buffer;
}
/**
* @brief print the resource that was just stored.
* @param dev the device the stored resorce lives on
* @param resource the resource that was just stored.
* Print the resource that was just stored.
*
* @param dev The device the stored resorce lives on.
* @param resource The resource that was just stored.
*/
void report_resource_stored(struct device * dev, struct resource *resource, const char *comment)
void report_resource_stored(struct device *dev, struct resource *resource,
const char *comment)
{
if (resource->flags & IORESOURCE_STORED) {
char buf[10];
@ -555,42 +596,43 @@ void report_resource_stored(struct device * dev, struct resource *resource, cons
buf[0] = '\0';
if (resource->flags & IORESOURCE_PCI_BRIDGE) {
#if PCI_BUS_SEGN_BITS
sprintf(buf, "bus %04x:%02x ", dev->bus->secondary>>8, dev->link[0].secondary & 0xff);
sprintf(buf, "bus %04x:%02x ", dev->bus->secondary >> 8,
dev->link[0].secondary & 0xff);
#else
sprintf(buf, "bus %02x ", dev->link[0].secondary);
#endif
}
printk(BIOS_DEBUG,
"%s %02x <- [0x%010Lx - 0x%010Lx] %s%s%s\n",
dev_path(dev),
resource->index,
base, end,
buf,
resource_type(resource),
comment);
printk(BIOS_DEBUG,
"%s %02x <- [0x%010Lx - 0x%010Lx] %s%s%s\n",
dev_path(dev),
resource->index,
base, end, buf, resource_type(resource), comment);
}
}
void search_bus_resources(struct bus *bus,
unsigned long type_mask, unsigned long type,
resource_search_t search, void *gp)
unsigned long type_mask, unsigned long type,
resource_search_t search, void *gp)
{
struct device *curdev;
for(curdev = bus->children; curdev; curdev = curdev->sibling) {
for (curdev = bus->children; curdev; curdev = curdev->sibling) {
int i;
/* Ignore disabled devices */
if (!curdev->have_resources) continue;
for(i = 0; i < curdev->resources; i++) {
/* Ignore disabled devices. */
if (!curdev->have_resources)
continue;
for (i = 0; i < curdev->resources; i++) {
struct resource *resource = &curdev->resource[i];
/* If it isn't the right kind of resource ignore it */
/* If it isn't the right kind of resource ignore it. */
if ((resource->flags & type_mask) != type) {
continue;
}
/* If it is a subtractive resource recurse */
/* If it is a subtractive resource recurse. */
if (resource->flags & IORESOURCE_SUBTRACTIVE) {
struct bus * subbus;
subbus = &curdev->link[IOINDEX_SUBTRACTIVE_LINK(resource->index)];
search_bus_resources(subbus, type_mask, type, search, gp);
struct bus *subbus;
subbus = &curdev->link[IOINDEX_SUBTRACTIVE_LINK
(resource->index)];
search_bus_resources(subbus, type_mask, type,
search, gp);
continue;
}
search(gp, curdev, resource);
@ -598,27 +640,31 @@ void search_bus_resources(struct bus *bus,
}
}
void search_global_resources(
unsigned long type_mask, unsigned long type,
resource_search_t search, void *gp)
void search_global_resources(unsigned long type_mask, unsigned long type,
resource_search_t search, void *gp)
{
struct device *curdev;
printk(BIOS_SPEW, "%s: mask %x type %x \n", __func__, type_mask, type);
for(curdev = all_devices; curdev; curdev = curdev->next) {
for (curdev = all_devices; curdev; curdev = curdev->next) {
int i;
printk(BIOS_SPEW, "%s: dev %s, have_resources %d #resources %d\n", __func__, curdev->dtsname,
curdev->have_resources, curdev->resources);
/* Ignore disabled devices */
if (!curdev->have_resources) continue;
for(i = 0; i < curdev->resources; i++) {
printk(BIOS_SPEW,
"%s: dev %s, have_resources %d #resources %d\n",
__func__, curdev->dtsname, curdev->have_resources,
curdev->resources);
/* Ignore disabled devices. */
if (!curdev->have_resources)
continue;
for (i = 0; i < curdev->resources; i++) {
struct resource *resource = &curdev->resource[i];
printk(BIOS_SPEW, "%s: dev %s, resource %d, flags %x base 0x%lx size 0x%lx\n", __func__, curdev->dtsname,
i, resource->flags, (u32) resource->base, (u32)resource->size);
/* If it isn't the right kind of resource ignore it */
printk(BIOS_SPEW,
"%s: dev %s, resource %d, flags %x base 0x%lx size 0x%lx\n",
__func__, curdev->dtsname, i, resource->flags,
(u32) resource->base, (u32) resource->size);
/* If it isn't the right kind of resource ignore it. */
if ((resource->flags & type_mask) != type) {
continue;
}
/* If it is a subtractive resource ignore it */
/* If it is a subtractive resource ignore it. */
if (resource->flags & IORESOURCE_SUBTRACTIVE) {
continue;
}
@ -627,7 +673,7 @@ void search_global_resources(
}
}
void dev_set_enabled(struct device * dev, int enable)
void dev_set_enabled(struct device *dev, int enable)
{
if (dev->enabled == enable) {
return;
@ -640,10 +686,10 @@ void dev_set_enabled(struct device * dev, int enable)
void disable_children(struct bus *bus)
{
struct device * child;
for(child = bus->children; child; child = child->sibling) {
struct device *child;
for (child = bus->children; child; child = child->sibling) {
int link;
for(link = 0; link < child->links; link++) {
for (link = 0; link < child->links; link++) {
disable_children(&child->link[link]);
}
dev_set_enabled(child, 0);

View file

@ -23,10 +23,6 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
2005.11 yhlu add let the real sb to use small uintid
*/
#include <bitops.h>
#include <console/console.h>
#include <device/device.h>
@ -38,7 +34,7 @@
#include <part/fallback_boot.h>
#define OPT_HT_LINK 0
#if OPT_HT_LINK == 1
#include <cpu/amd/model_fxx_rev.h>
#endif
@ -48,25 +44,24 @@ static device_t ht_scan_get_devs(device_t *old_devices)
device_t first, last;
first = *old_devices;
last = first;
/* Extract the chain of devices to (first through last)
* for the next hypertransport device.
*/
while(last && last->sibling &&
(last->sibling->path.type == DEVICE_PATH_PCI) &&
(last->sibling->path.u.pci.devfn > last->path.u.pci.devfn))
{
while (last && last->sibling &&
(last->sibling->path.type == DEVICE_PATH_PCI) &&
(last->sibling->path.u.pci.devfn > last->path.u.pci.devfn)) {
last = last->sibling;
}
if (first) {
device_t child;
/* Unlink the chain from the list of old devices */
/* Unlink the chain from the list of old devices. */
*old_devices = last->sibling;
last->sibling = 0;
/* Now add the device to the list of devices on the bus.
*/
/* Find the last child of our parent */
for(child = first->bus->children; child && child->sibling; ) {
/* Now add the device to the list of devices on the bus. */
/* Find the last child of our parent. */
for (child = first->bus->children; child && child->sibling;) {
child = child->sibling;
}
/* Place the chain on the list of children of their parent. */
@ -82,30 +77,30 @@ static device_t ht_scan_get_devs(device_t *old_devices)
#if OPT_HT_LINK == 1
static unsigned ht_read_freq_cap(device_t dev, unsigned pos)
{
/* Handle bugs in valid hypertransport frequency reporting */
/* Handle bugs in valid hypertransport frequency reporting. */
unsigned freq_cap;
freq_cap = pci_read_config16(dev, pos);
freq_cap &= ~(1 << HT_FREQ_VENDOR); /* Ignore Vendor HT frequencies */
freq_cap &= ~(1 << HT_FREQ_VENDOR); /* Ignore vendor HT frequencies. */
/* AMD 8131 Errata 48 */
/* AMD 8131 Errata 48. */
if ((dev->vendor == PCI_VENDOR_ID_AMD) &&
(dev->device == PCI_DEVICE_ID_AMD_8131_PCIX)) {
(dev->device == PCI_DEVICE_ID_AMD_8131_PCIX)) {
freq_cap &= ~(1 << HT_FREQ_800Mhz);
}
/* AMD 8151 Errata 23 */
/* AMD 8151 Errata 23. */
if ((dev->vendor == PCI_VENDOR_ID_AMD) &&
(dev->device == PCI_DEVICE_ID_AMD_8151_SYSCTRL)) {
(dev->device == PCI_DEVICE_ID_AMD_8151_SYSCTRL)) {
freq_cap &= ~(1 << HT_FREQ_800Mhz);
}
/* AMD K8 Unsupported 1Ghz? */
/* AMD K8 unsupported 1GHz? */
if ((dev->vendor == PCI_VENDOR_ID_AMD) && (dev->device == 0x1100)) {
#if K8_HT_FREQ_1G_SUPPORT == 1
#if K8_REV_F_SUPPORT == 0
if (is_cpu_pre_e0()) { // only e0 later suupport 1GHz HT
#if K8_HT_FREQ_1G_SUPPORT == 1
#if K8_REV_F_SUPPORT == 0
if (is_cpu_pre_e0()) { // Only e0 later suupport 1GHz HT.
freq_cap &= ~(1 << HT_FREQ_1000Mhz);
}
#endif
}
#endif
#else
freq_cap &= ~(1 << HT_FREQ_1000Mhz);
#endif
@ -117,158 +112,174 @@ static unsigned ht_read_freq_cap(device_t dev, unsigned pos)
struct ht_link {
struct device *dev;
unsigned pos;
unsigned int pos;
unsigned char ctrl_off, config_off, freq_off, freq_cap_off;
};
static int ht_setup_link(struct ht_link *prev, device_t dev, unsigned pos)
static int ht_setup_link(struct ht_link *prev, device_t dev, unsigned int pos)
{
static const u8 link_width_to_pow2[]= { 3, 4, 0, 5, 1, 2, 0, 0 };
static const u8 link_width_to_pow2[] = { 3, 4, 0, 5, 1, 2, 0, 0 };
static const u8 pow2_to_link_width[] = { 0x7, 4, 5, 0, 1, 3 };
struct ht_link cur[1];
unsigned present_width_cap, upstream_width_cap;
unsigned present_freq_cap, upstream_freq_cap;
unsigned ln_present_width_in, ln_upstream_width_in;
unsigned ln_present_width_out, ln_upstream_width_out;
unsigned freq, old_freq;
unsigned present_width, upstream_width, old_width;
unsigned int present_width_cap, upstream_width_cap;
unsigned int present_freq_cap, upstream_freq_cap;
unsigned int ln_present_width_in, ln_upstream_width_in;
unsigned int ln_present_width_out, ln_upstream_width_out;
unsigned int freq, old_freq;
unsigned int present_width, upstream_width, old_width;
int reset_needed;
int linkb_to_host;
/* Set the hypertransport link width and frequency */
/* Set the hypertransport link width and frequency. */
reset_needed = 0;
/* See which side of the device our previous write to
* set the unitid came from.
*/
cur->dev = dev;
cur->pos = pos;
linkb_to_host = (pci_read_config16(cur->dev, cur->pos + PCI_CAP_FLAGS) >> 10) & 1;
linkb_to_host =
(pci_read_config16(cur->dev, cur->pos + PCI_CAP_FLAGS) >> 10) & 1;
if (!linkb_to_host) {
cur->ctrl_off = PCI_HT_CAP_SLAVE_CTRL0;
cur->config_off = PCI_HT_CAP_SLAVE_WIDTH0;
cur->freq_off = PCI_HT_CAP_SLAVE_FREQ0;
cur->ctrl_off = PCI_HT_CAP_SLAVE_CTRL0;
cur->config_off = PCI_HT_CAP_SLAVE_WIDTH0;
cur->freq_off = PCI_HT_CAP_SLAVE_FREQ0;
cur->freq_cap_off = PCI_HT_CAP_SLAVE_FREQ_CAP0;
}
else {
cur->ctrl_off = PCI_HT_CAP_SLAVE_CTRL1;
cur->config_off = PCI_HT_CAP_SLAVE_WIDTH1;
cur->freq_off = PCI_HT_CAP_SLAVE_FREQ1;
} else {
cur->ctrl_off = PCI_HT_CAP_SLAVE_CTRL1;
cur->config_off = PCI_HT_CAP_SLAVE_WIDTH1;
cur->freq_off = PCI_HT_CAP_SLAVE_FREQ1;
cur->freq_cap_off = PCI_HT_CAP_SLAVE_FREQ_CAP1;
}
#if OPT_HT_LINK == 1
/* Read the capabilities */
present_freq_cap = ht_read_freq_cap(cur->dev, cur->pos + cur->freq_cap_off);
upstream_freq_cap = ht_read_freq_cap(prev->dev, prev->pos + prev->freq_cap_off);
present_width_cap = pci_read_config8(cur->dev, cur->pos + cur->config_off);
upstream_width_cap = pci_read_config8(prev->dev, prev->pos + prev->config_off);
/* Calculate the highest useable frequency */
/* Read the capabilities. */
present_freq_cap =
ht_read_freq_cap(cur->dev, cur->pos + cur->freq_cap_off);
upstream_freq_cap =
ht_read_freq_cap(prev->dev, prev->pos + prev->freq_cap_off);
present_width_cap =
pci_read_config8(cur->dev, cur->pos + cur->config_off);
upstream_width_cap =
pci_read_config8(prev->dev, prev->pos + prev->config_off);
/* Calculate the highest useable frequency. */
freq = log2(present_freq_cap & upstream_freq_cap);
/* Calculate the highest width */
/* Calculate the highest width. */
ln_upstream_width_in = link_width_to_pow2[upstream_width_cap & 7];
ln_present_width_out = link_width_to_pow2[(present_width_cap >> 4) & 7];
if (ln_upstream_width_in > ln_present_width_out) {
ln_upstream_width_in = ln_present_width_out;
}
upstream_width = pow2_to_link_width[ln_upstream_width_in];
present_width = pow2_to_link_width[ln_upstream_width_in] << 4;
present_width = pow2_to_link_width[ln_upstream_width_in] << 4;
ln_upstream_width_out = link_width_to_pow2[(upstream_width_cap >> 4) & 7];
ln_present_width_in = link_width_to_pow2[present_width_cap & 7];
ln_upstream_width_out =
link_width_to_pow2[(upstream_width_cap >> 4) & 7];
ln_present_width_in = link_width_to_pow2[present_width_cap & 7];
if (ln_upstream_width_out > ln_present_width_in) {
ln_upstream_width_out = ln_present_width_in;
}
upstream_width |= pow2_to_link_width[ln_upstream_width_out] << 4;
present_width |= pow2_to_link_width[ln_upstream_width_out];
present_width |= pow2_to_link_width[ln_upstream_width_out];
/* Set the current device */
/* Set the current device. */
old_freq = pci_read_config8(cur->dev, cur->pos + cur->freq_off);
old_freq &= 0x0f;
if (freq != old_freq) {
unsigned new_freq;
unsigned int new_freq;
pci_write_config8(cur->dev, cur->pos + cur->freq_off, freq);
reset_needed = 1;
printk_spew("HyperT FreqP old %x new %x\n",old_freq,freq);
printk_spew("HyperT FreqP old %x new %x\n", old_freq, freq);
new_freq = pci_read_config8(cur->dev, cur->pos + cur->freq_off);
new_freq &= 0x0f;
if (new_freq != freq) {
printk_err("%s Hypertransport frequency would not set wanted: %x got: %x\n",
dev_path(dev), freq, new_freq);
printk_err
("%s Hypertransport frequency would not set wanted: %x got: %x\n",
dev_path(dev), freq, new_freq);
}
}
old_width = pci_read_config8(cur->dev, cur->pos + cur->config_off + 1);
if (present_width != old_width) {
unsigned new_width;
unsigned int new_width;
pci_write_config8(cur->dev, cur->pos + cur->config_off + 1,
present_width);
present_width);
reset_needed = 1;
printk_spew("HyperT widthP old %x new %x\n",old_width, present_width);
new_width = pci_read_config8(cur->dev, cur->pos + cur->config_off + 1);
printk_spew("HyperT widthP old %x new %x\n", old_width,
present_width);
new_width =
pci_read_config8(cur->dev, cur->pos + cur->config_off + 1);
if (new_width != present_width) {
printk_err("%s Hypertransport width would not set wanted: %x got: %x\n",
dev_path(dev), present_width, new_width);
printk_err
("%s Hypertransport width would not set wanted: %x got: %x\n",
dev_path(dev), present_width, new_width);
}
}
/* Set the upstream device */
/* Set the upstream device. */
old_freq = pci_read_config8(prev->dev, prev->pos + prev->freq_off);
old_freq &= 0x0f;
if (freq != old_freq) {
unsigned new_freq;
unsigned int new_freq;
pci_write_config8(prev->dev, prev->pos + prev->freq_off, freq);
reset_needed = 1;
printk_spew("HyperT freqU old %x new %x\n", old_freq, freq);
new_freq = pci_read_config8(prev->dev, prev->pos + prev->freq_off);
new_freq =
pci_read_config8(prev->dev, prev->pos + prev->freq_off);
new_freq &= 0x0f;
if (new_freq != freq) {
printk_err("%s Hypertransport frequency would not set wanted: %x got: %x\n",
dev_path(prev->dev), freq, new_freq);
printk_err
("%s Hypertransport frequency would not set wanted: %x got: %x\n",
dev_path(prev->dev), freq, new_freq);
}
}
old_width = pci_read_config8(prev->dev, prev->pos + prev->config_off + 1);
old_width =
pci_read_config8(prev->dev, prev->pos + prev->config_off + 1);
if (upstream_width != old_width) {
unsigned new_width;
pci_write_config8(prev->dev, prev->pos + prev->config_off + 1, upstream_width);
unsigned int new_width;
pci_write_config8(prev->dev, prev->pos + prev->config_off + 1,
upstream_width);
reset_needed = 1;
printk_spew("HyperT widthU old %x new %x\n", old_width, upstream_width);
new_width = pci_read_config8(prev->dev, prev->pos + prev->config_off + 1);
printk_spew("HyperT widthU old %x new %x\n", old_width,
upstream_width);
new_width =
pci_read_config8(prev->dev,
prev->pos + prev->config_off + 1);
if (new_width != upstream_width) {
printk_err("%s Hypertransport width would not set wanted: %x got: %x\n",
dev_path(prev->dev), upstream_width, new_width);
printk_err
("%s Hypertransport width would not set wanted: %x got: %x\n",
dev_path(prev->dev), upstream_width, new_width);
}
}
#endif
/* Remember the current link as the previous link,
* But look at the other offsets.
* but look at the other offsets.
*/
prev->dev = cur->dev;
prev->pos = cur->pos;
if (cur->ctrl_off == PCI_HT_CAP_SLAVE_CTRL0) {
prev->ctrl_off = PCI_HT_CAP_SLAVE_CTRL1;
prev->config_off = PCI_HT_CAP_SLAVE_WIDTH1;
prev->freq_off = PCI_HT_CAP_SLAVE_FREQ1;
prev->ctrl_off = PCI_HT_CAP_SLAVE_CTRL1;
prev->config_off = PCI_HT_CAP_SLAVE_WIDTH1;
prev->freq_off = PCI_HT_CAP_SLAVE_FREQ1;
prev->freq_cap_off = PCI_HT_CAP_SLAVE_FREQ_CAP1;
} else {
prev->ctrl_off = PCI_HT_CAP_SLAVE_CTRL0;
prev->config_off = PCI_HT_CAP_SLAVE_WIDTH0;
prev->freq_off = PCI_HT_CAP_SLAVE_FREQ0;
prev->ctrl_off = PCI_HT_CAP_SLAVE_CTRL0;
prev->config_off = PCI_HT_CAP_SLAVE_WIDTH0;
prev->freq_off = PCI_HT_CAP_SLAVE_FREQ0;
prev->freq_cap_off = PCI_HT_CAP_SLAVE_FREQ_CAP0;
}
return reset_needed;
}
static unsigned ht_lookup_slave_capability(struct device *dev)
static unsigned int ht_lookup_slave_capability(struct device *dev)
{
unsigned pos;
unsigned int pos;
pos = 0;
do {
pos = pci_find_next_capability(dev, PCI_CAP_ID_HT, pos);
if (pos) {
unsigned flags;
unsigned int flags;
flags = pci_read_config16(dev, pos + PCI_CAP_FLAGS);
printk_spew("Flags: 0x%04x\n", flags);
if ((flags >> 13) == 0) {
@ -276,320 +287,346 @@ static unsigned ht_lookup_slave_capability(struct device *dev)
break;
}
}
} while(pos);
} while (pos);
return pos;
}
static void ht_collapse_early_enumeration(struct bus *bus, unsigned offset_unitid)
static void ht_collapse_early_enumeration(struct bus *bus,
unsigned int offset_unitid)
{
unsigned int devfn;
unsigned int devfn, ctrl;
struct ht_link prev;
unsigned ctrl;
/* Initialize the hypertransport enumeration state */
/* Initialize the hypertransport enumeration state. */
prev.dev = bus->dev;
prev.pos = bus->cap;
prev.ctrl_off = PCI_HT_CAP_HOST_CTRL;
prev.config_off = PCI_HT_CAP_HOST_WIDTH;
prev.freq_off = PCI_HT_CAP_HOST_FREQ;
prev.ctrl_off = PCI_HT_CAP_HOST_CTRL;
prev.config_off = PCI_HT_CAP_HOST_WIDTH;
prev.freq_off = PCI_HT_CAP_HOST_FREQ;
prev.freq_cap_off = PCI_HT_CAP_HOST_FREQ_CAP;
/* Wait until the link initialization is complete */
/* Wait until the link initialization is complete. */
do {
ctrl = pci_read_config16(prev.dev, prev.pos + prev.ctrl_off);
/* Is this the end of the hypertransport chain */
/* Is this the end of the hypertransport chain? */
if (ctrl & (1 << 6)) {
return;
}
/* Has the link failed? */
if (ctrl & (1 << 4)) {
/*
* Either the link has failed, or we have
* a CRC error.
* Sometimes this can happen due to link
* retrain, so lets knock it down and see
* if its transient
/* Either the link has failed, or we have a CRC error.
* Sometimes this can happen due to link retrain, so
* lets knock it down and see if its transient.
*/
ctrl |= ((1 << 4) | (1 <<8)); // Link fail + Crc
pci_write_config16(prev.dev, prev.pos + prev.ctrl_off, ctrl);
ctrl = pci_read_config16(prev.dev, prev.pos + prev.ctrl_off);
ctrl |= ((1 << 4) | (1 << 8)); // Link fail + CRC.
pci_write_config16(prev.dev, prev.pos + prev.ctrl_off,
ctrl);
ctrl = pci_read_config16(prev.dev,
prev.pos + prev.ctrl_off);
if (ctrl & ((1 << 4) | (1 << 8))) {
printk_alert("Detected error on Hypertransport Link\n");
printk_alert
("Detected error on Hypertransport Link\n");
return;
}
}
} while((ctrl & (1 << 5)) == 0);
} while ((ctrl & (1 << 5)) == 0);
//actually, only for one HT device HT chain, and unitid is 0
/* Actually, only for one HT device HT chain, and unitid is 0. */
#if HT_CHAIN_UNITID_BASE == 0
if(offset_unitid) {
return;
}
if (offset_unitid) {
return;
}
#endif
/* Check if is already collapsed */
if((!offset_unitid)|| (offset_unitid && (!((HT_CHAIN_END_UNITID_BASE == 0) && (HT_CHAIN_END_UNITID_BASE <HT_CHAIN_UNITID_BASE))))) {
struct device dummy;
u32 id;
dummy.bus = bus;
dummy.path.type = DEVICE_PATH_PCI;
dummy.path.u.pci.devfn = PCI_DEVFN(0, 0);
id = pci_read_config32(&dummy, PCI_VENDOR_ID);
if ( ! ( (id == 0xffffffff) || (id == 0x00000000) ||
(id == 0x0000ffff) || (id == 0xffff0000) ) ) {
return;
}
}
/* Check if is already collapsed. */
if ((!offset_unitid)
|| (offset_unitid
&&
(!((HT_CHAIN_END_UNITID_BASE == 0)
&& (HT_CHAIN_END_UNITID_BASE < HT_CHAIN_UNITID_BASE))))) {
struct device dummy;
u32 id;
dummy.bus = bus;
dummy.path.type = DEVICE_PATH_PCI;
dummy.path.u.pci.devfn = PCI_DEVFN(0, 0);
id = pci_read_config32(&dummy, PCI_VENDOR_ID);
if (!((id == 0xffffffff) || (id == 0x00000000) ||
(id == 0x0000ffff) || (id == 0xffff0000))) {
return;
}
}
/* Spin through the devices and collapse any early
* hypertransport enumeration.
*/
for(devfn = PCI_DEVFN(1, 0); devfn <= 0xff; devfn += 8) {
for (devfn = PCI_DEVFN(1, 0); devfn <= 0xff; devfn += 8) {
struct device dummy;
u32 id;
unsigned pos, flags;
dummy.bus = bus;
dummy.path.type = DEVICE_PATH_PCI;
unsigned int pos, flags;
dummy.bus = bus;
dummy.path.type = DEVICE_PATH_PCI;
dummy.path.u.pci.devfn = devfn;
id = pci_read_config32(&dummy, PCI_VENDOR_ID);
if ( (id == 0xffffffff) || (id == 0x00000000) ||
(id == 0x0000ffff) || (id == 0xffff0000)) {
if ((id == 0xffffffff) || (id == 0x00000000) ||
(id == 0x0000ffff) || (id == 0xffff0000)) {
continue;
}
dummy.vendor = id & 0xffff;
dummy.device = (id >> 16) & 0xffff;
dummy.hdr_type = pci_read_config8(&dummy, PCI_HEADER_TYPE);
pos = ht_lookup_slave_capability(&dummy);
if (!pos){
if (!pos) {
continue;
}
/* Clear the unitid */
/* Clear the unitid. */
flags = pci_read_config16(&dummy, pos + PCI_CAP_FLAGS);
flags &= ~0x1f;
pci_write_config16(&dummy, pos + PCI_CAP_FLAGS, flags);
printk_spew("Collapsing %s [%04x/%04x]\n",
dev_path(&dummy), dummy.vendor, dummy.device);
printk_spew("Collapsing %s [%04x/%04x]\n",
dev_path(&dummy), dummy.vendor, dummy.device);
}
}
unsigned int hypertransport_scan_chain(struct bus *bus,
unsigned min_devfn, unsigned max_devfn, unsigned int max, unsigned *ht_unitid_base, unsigned offset_unitid)
unsigned int hypertransport_scan_chain(struct bus *bus, unsigned int min_devfn,
unsigned int max_devfn,
unsigned int max,
unsigned int *ht_unitid_base,
unsigned int offset_unitid)
{
//even HT_CHAIN_UNITID_BASE == 0, we still can go through this function, because of end_of_chain check, also We need it to optimize link
unsigned next_unitid, last_unitid;
/* Even HT_CHAIN_UNITID_BASE == 0, we still can go through this
* function, because of end_of_chain check, also we need it to
* optimize link.
*/
unsigned int next_unitid, last_unitid;
device_t old_devices, dev, func;
unsigned min_unitid = (offset_unitid) ? HT_CHAIN_UNITID_BASE:1;
unsigned int min_unitid = (offset_unitid) ? HT_CHAIN_UNITID_BASE : 1;
struct ht_link prev;
device_t last_func = 0;
int ht_dev_num = 0;
#if HT_CHAIN_END_UNITID_BASE < HT_CHAIN_UNITID_BASE
//let't record the device of last ht device, So we can set the Unitid to HT_CHAIN_END_UNITID_BASE
unsigned real_last_unitid;
u8 real_last_pos;
/* Let't record the device of last HT device, so we can set the
* unitid to HT_CHAIN_END_UNITID_BASE.
*/
unsigned int real_last_unitid;
u8 real_last_pos;
device_t real_last_dev;
#endif
/* Restore the hypertransport chain to it's unitialized state */
/* Restore the hypertransport chain to its unitialized state. */
ht_collapse_early_enumeration(bus, offset_unitid);
/* See which static device nodes I have */
/* See which static device nodes I have. */
old_devices = bus->children;
bus->children = 0;
/* Initialize the hypertransport enumeration state */
/* Initialize the hypertransport enumeration state. */
prev.dev = bus->dev;
prev.pos = bus->cap;
prev.ctrl_off = PCI_HT_CAP_HOST_CTRL;
prev.config_off = PCI_HT_CAP_HOST_WIDTH;
prev.freq_off = PCI_HT_CAP_HOST_FREQ;
prev.ctrl_off = PCI_HT_CAP_HOST_CTRL;
prev.config_off = PCI_HT_CAP_HOST_WIDTH;
prev.freq_off = PCI_HT_CAP_HOST_FREQ;
prev.freq_cap_off = PCI_HT_CAP_HOST_FREQ_CAP;
/* If present assign unitid to a hypertransport chain */
last_unitid = min_unitid -1;
/* If present assign unitid to a hypertransport chain. */
last_unitid = min_unitid - 1;
next_unitid = min_unitid;
do {
u8 pos;
u16 flags;
unsigned count, static_count;
unsigned ctrl;
unsigned int count, static_count, ctrl;
last_unitid = next_unitid;
/* Wait until the link initialization is complete */
/* Wait until the link initialization is complete. */
do {
ctrl = pci_read_config16(prev.dev, prev.pos + prev.ctrl_off);
ctrl = pci_read_config16(prev.dev,
prev.pos + prev.ctrl_off);
if (ctrl & (1 << 6))
goto end_of_chain; // End of chain
goto end_of_chain; // End of chain.
if (ctrl & ((1 << 4) | (1 << 8))) {
/*
* Either the link has failed, or we have
* a CRC error.
* Sometimes this can happen due to link
* retrain, so lets knock it down and see
* if its transient
/* Either the link has failed, or we have a
* CRC error. Sometimes this can happen due to
* link retrain, so lets knock it down and see
* if its transient.
*/
ctrl |= ((1 << 4) | (1 <<8)); // Link fail + Crc
pci_write_config16(prev.dev, prev.pos + prev.ctrl_off, ctrl);
ctrl = pci_read_config16(prev.dev, prev.pos + prev.ctrl_off);
ctrl |= ((1 << 4) | (1 << 8)); /* Link fail + CRC */
pci_write_config16(prev.dev,
prev.pos + prev.ctrl_off,
ctrl);
ctrl = pci_read_config16(prev.dev,
prev.pos + prev.ctrl_off);
if (ctrl & ((1 << 4) | (1 << 8))) {
printk_alert("Detected error on Hypertransport Link\n");
printk_alert
("Detected error on Hypertransport Link\n");
goto end_of_chain;
}
}
} while((ctrl & (1 << 5)) == 0);
} while ((ctrl & (1 << 5)) == 0);
/* Get and setup the device_structure */
/* Get and setup the device_structure. */
dev = ht_scan_get_devs(&old_devices);
/* See if a device is present and setup the
* device structure.
*/
/* See if a device is present and setup the device structure. */
dev = pci_probe_dev(dev, bus, 0);
if (!dev || !dev->enabled) {
break;
}
/* Find the hypertransport link capability */
/* Find the hypertransport link capability. */
pos = ht_lookup_slave_capability(dev);
if (pos == 0) {
printk_err("%s Hypertransport link capability not found",
dev_path(dev));
printk_err
("%s Hypertransport link capability not found",
dev_path(dev));
break;
}
/* Update the Unitid of the current device */
/* Update the unitid of the current device. */
flags = pci_read_config16(dev, pos + PCI_CAP_FLAGS);
/* If the devices has a unitid set and is at devfn 0 we are done.
* This can happen with shadow hypertransport devices,
* or if we have reached the bottom of a
* hypertransport device chain.
/* If the devices has a unitid set and is at devfn 0 we are
* done. This can happen with shadow hypertransport devices,
* or if we have reached the bottom of a hypertransport
* device chain.
*/
if (flags & 0x1f) {
break;
}
flags &= ~0x1f; /* mask out base Unit ID */
flags |= next_unitid & 0x1f;
pci_write_config16(dev, pos + PCI_CAP_FLAGS, flags);
flags &= ~0x1f; /* Mask out base Unit ID. */
flags |= next_unitid & 0x1f;
pci_write_config16(dev, pos + PCI_CAP_FLAGS, flags);
/* Update the Unitd id in the device structure */
/* Update the Unitd id in the device structure. */
static_count = 1;
for(func = dev; func; func = func->sibling) {
for (func = dev; func; func = func->sibling) {
func->path.u.pci.devfn += (next_unitid << 3);
static_count = (func->path.u.pci.devfn >> 3)
- (dev->path.u.pci.devfn >> 3) + 1;
static_count = (func->path.u.pci.devfn >> 3)
- (dev->path.u.pci.devfn >> 3) + 1;
last_func = func;
}
/* Compute the number of unitids consumed */
count = (flags >> 5) & 0x1f; /* get unit count */
printk_spew("%s count: %04x static_count: %04x\n",
dev_path(dev), count, static_count);
/* Compute the number of unitids consumed. */
count = (flags >> 5) & 0x1f; /* Get unit count. */
printk_spew("%s count: %04x static_count: %04x\n",
dev_path(dev), count, static_count);
if (count < static_count) {
count = static_count;
}
/* Update the Unitid of the next device */
/* Update the unitid of the next device. */
ht_unitid_base[ht_dev_num] = next_unitid;
ht_dev_num++;
#if HT_CHAIN_END_UNITID_BASE < HT_CHAIN_UNITID_BASE
if(offset_unitid) {
real_last_unitid = next_unitid;
real_last_pos = pos;
if (offset_unitid) {
real_last_unitid = next_unitid;
real_last_pos = pos;
real_last_dev = dev;
}
#endif
next_unitid += count;
/* Setup the hypetransport link */
/* Setup the hypetransport link. */
bus->reset_needed |= ht_setup_link(&prev, dev, pos);
printk_debug("%s [%04x/%04x] %s next_unitid: %04x\n",
dev_path(dev),
dev->vendor, dev->device,
(dev->enabled? "enabled": "disabled"), next_unitid);
dev_path(dev),
dev->vendor, dev->device,
(dev->enabled ? "enabled" : "disabled"),
next_unitid);
} while((last_unitid != next_unitid) && (next_unitid <= (max_devfn >> 3)));
end_of_chain:
} while ((last_unitid != next_unitid)
&& (next_unitid <= (max_devfn >> 3)));
end_of_chain:
#if OPT_HT_LINK == 1
if(bus->reset_needed) {
if (bus->reset_needed) {
printk_info("HyperT reset needed\n");
}
else {
} else {
printk_debug("HyperT reset not needed\n");
}
#endif
#if HT_CHAIN_END_UNITID_BASE < HT_CHAIN_UNITID_BASE
if(offset_unitid && (ht_dev_num>0)) {
u16 flags;
int i;
if (offset_unitid && (ht_dev_num > 0)) {
u16 flags;
int i;
device_t last_func = 0;
flags = pci_read_config16(real_last_dev, real_last_pos + PCI_CAP_FLAGS);
flags &= ~0x1f;
flags |= HT_CHAIN_END_UNITID_BASE & 0x1f;
pci_write_config16(real_last_dev, real_last_pos + PCI_CAP_FLAGS, flags);
flags = pci_read_config16(real_last_dev,
real_last_pos + PCI_CAP_FLAGS);
flags &= ~0x1f;
flags |= HT_CHAIN_END_UNITID_BASE & 0x1f;
pci_write_config16(real_last_dev, real_last_pos + PCI_CAP_FLAGS,
flags);
for(func = real_last_dev; func; func = func->sibling) {
func->path.u.pci.devfn -= ((real_last_unitid - HT_CHAIN_END_UNITID_BASE) << 3);
for (func = real_last_dev; func; func = func->sibling) {
func->path.u.pci.devfn -=
((real_last_unitid -
HT_CHAIN_END_UNITID_BASE) << 3);
last_func = func;
}
ht_unitid_base[ht_dev_num-1] = HT_CHAIN_END_UNITID_BASE; // update last one
next_unitid = real_last_unitid;
}
}
/* Update last one. */
ht_unitid_base[ht_dev_num - 1] = HT_CHAIN_END_UNITID_BASE;
next_unitid = real_last_unitid;
}
#endif
if (next_unitid > 0x1f) {
next_unitid = 0x1f;
}
/* Die if any leftover Static devices are are found.
/* Die if any leftover static devices are found.
* There's probably a problem in the Config.lb.
* TODO: No more Config.lb in LinuxBIOSv3.
*/
if(old_devices) {
if (old_devices) {
device_t left;
for(left = old_devices; left; left = left->sibling) {
for (left = old_devices; left; left = left->sibling) {
printk_debug("%s\n", dev_path(left));
}
printk_err("HT: Left over static devices. Check your Config.lb\n");
if(last_func && !last_func->sibling) // put back the left over static device, and let pci_scan_bus disable it
last_func->sibling = old_devices;
printk_err("HT: Left over static devices.\n");
/* Put back the left over static device, and let
* pci_scan_bus() disable it.
*/
if (last_func && !last_func->sibling)
last_func->sibling = old_devices;
}
/* Now that nothing is overlapping it is safe to scan the
* children.
* children.
*/
max = pci_scan_bus(bus, 0x00, (next_unitid << 3)|7, max);
return max;
max = pci_scan_bus(bus, 0x00, (next_unitid << 3) | 7, max);
return max;
}
/**
* @brief Scan a PCI bridge and the buses behind the bridge.
* Scan a PCI bridge and the buses behind the bridge.
*
* Determine the existence of buses behind the bridge. Set up the bridge
* according to the result of the scan.
*
* This function is the default scan_bus() method for PCI bridge devices.
*
* @param dev pointer to the bridge device
* @param max the highest bus number assgined up to now
* TODO: This comment in copy+pasted from elsewhere and probably incorrect.
*
* @return The maximum bus number found, after scanning all subordinate busses
* @param dev Pointer to the bridge device.
* @param max The highest bus number assigned up to now.
* @return The maximum bus number found, after scanning all subordinate buses.
*/
unsigned int hypertransport_scan_chain_x(struct bus *bus,
unsigned min_devfn, unsigned max_devfn, unsigned int max)
unsigned int min_devfn,
unsigned int max_devfn,
unsigned int max)
{
unsigned ht_unitid_base[4];
unsigned offset_unitid = 1;
return hypertransport_scan_chain(bus, min_devfn, max_devfn, max, ht_unitid_base, offset_unitid);
unsigned int ht_unitid_base[4];
unsigned int offset_unitid = 1;
return hypertransport_scan_chain(bus, min_devfn, max_devfn, max,
ht_unitid_base, offset_unitid);
}
unsigned int ht_scan_bridge(struct device *dev, unsigned int max)
@ -597,8 +634,7 @@ unsigned int ht_scan_bridge(struct device *dev, unsigned int max)
return do_pci_scan_bridge(dev, max, hypertransport_scan_chain_x);
}
/** Default device operations for hypertransport bridges */
/** Default device operations for hypertransport bridges. */
static struct pci_operations ht_bus_ops_pci = {
.set_subsystem = 0,
};
@ -607,8 +643,8 @@ struct device_operations default_ht_ops_bus = {
.read_resources = pci_bus_read_resources,
.set_resources = pci_dev_set_resources,
.enable_resources = pci_bus_enable_resources,
.init = 0,
.scan_bus = ht_scan_bridge,
.init = 0,
.scan_bus = ht_scan_bridge,
.enable = 0,
.reset_bus = pci_bus_reset,
.ops_pci = &ht_bus_ops_pci,

File diff suppressed because it is too large Load diff

View file

@ -26,54 +26,65 @@
#include <device/pci_ops.h>
#include <arch/types.h>
/* walk up the tree from the current dev, in an attempt to find a bus that has ops_pci_bus set */
/* the assumption here being that if it has ops_pci_bus set, then it can do bus operations */
static struct bus *get_pbus(struct device * dev)
/**
* Walk up the tree from the current dev, in an attempt to find a
* bus that has ops_pci_bus set. The assumption here being that if it
* has ops_pci_bus set, then it can do bus operations.
*/
static struct bus *get_pbus(struct device *dev)
{
struct bus *pbus = dev->bus;
while(pbus && pbus->dev && !ops_pci_bus(pbus)) {
while (pbus && pbus->dev && !ops_pci_bus(pbus)) {
pbus = pbus->dev->bus;
}
if (!pbus || !pbus->dev || !pbus->dev->ops || !pbus->dev->ops->ops_pci_bus) {
printk(BIOS_ALERT,"%s: %s(%s) Cannot find PCI bus operations", __func__, dev->dtsname, dev_path(dev));
if (!pbus || !pbus->dev || !pbus->dev->ops
|| !pbus->dev->ops->ops_pci_bus) {
printk(BIOS_ALERT, "%s: %s(%s) Cannot find PCI bus operations",
__func__, dev->dtsname, dev_path(dev));
die("");
for(;;);
for (;;) ;
}
return pbus;
}
u8 pci_read_config8(struct device * dev, unsigned where)
u8 pci_read_config8(struct device *dev, unsigned int where)
{
struct bus *pbus = get_pbus(dev);
return ops_pci_bus(pbus)->read8(pbus, dev->bus->secondary, dev->path.u.pci.devfn, where);
return ops_pci_bus(pbus)->read8(pbus, dev->bus->secondary,
dev->path.u.pci.devfn, where);
}
u16 pci_read_config16(struct device * dev, unsigned where)
u16 pci_read_config16(struct device *dev, unsigned int where)
{
struct bus *pbus = get_pbus(dev);
return ops_pci_bus(pbus)->read16(pbus, dev->bus->secondary, dev->path.u.pci.devfn, where);
return ops_pci_bus(pbus)->read16(pbus, dev->bus->secondary,
dev->path.u.pci.devfn, where);
}
u32 pci_read_config32(struct device * dev, unsigned where)
u32 pci_read_config32(struct device *dev, unsigned int where)
{
struct bus *pbus = get_pbus(dev);
return ops_pci_bus(pbus)->read32(pbus, dev->bus->secondary, dev->path.u.pci.devfn, where);
return ops_pci_bus(pbus)->read32(pbus, dev->bus->secondary,
dev->path.u.pci.devfn, where);
}
void pci_write_config8(struct device * dev, unsigned where, u8 val)
void pci_write_config8(struct device *dev, unsigned int where, u8 val)
{
struct bus *pbus = get_pbus(dev);
ops_pci_bus(pbus)->write8(pbus, dev->bus->secondary, dev->path.u.pci.devfn, where, val);
ops_pci_bus(pbus)->write8(pbus, dev->bus->secondary,
dev->path.u.pci.devfn, where, val);
}
void pci_write_config16(struct device * dev, unsigned where, u16 val)
void pci_write_config16(struct device *dev, unsigned int where, u16 val)
{
struct bus *pbus = get_pbus(dev);
ops_pci_bus(pbus)->write16(pbus, dev->bus->secondary, dev->path.u.pci.devfn, where, val);
ops_pci_bus(pbus)->write16(pbus, dev->bus->secondary,
dev->path.u.pci.devfn, where, val);
}
void pci_write_config32(struct device * dev, unsigned where, u32 val)
void pci_write_config32(struct device *dev, unsigned int where, u32 val)
{
struct bus *pbus = get_pbus(dev);
ops_pci_bus(pbus)->write32(pbus, dev->bus->secondary, dev->path.u.pci.devfn, where, val);
ops_pci_bus(pbus)->write32(pbus, dev->bus->secondary,
dev->path.u.pci.devfn, where, val);
}

View file

@ -28,16 +28,18 @@
#include <device/pci_ops.h>
#include <string.h>
struct rom_header * pci_rom_probe(struct device *dev)
struct rom_header *pci_rom_probe(struct device *dev)
{
unsigned long rom_address;
struct rom_header *rom_header;
struct pci_data *rom_data;
if (dev->on_mainboard) {
// in case some device PCI_ROM_ADDRESS can not be set or readonly
if (dev->on_mainboard) {
/* In case some device PCI_ROM_ADDRESS can not be set
* or readonly.
*/
rom_address = dev->rom_address;
} else {
} else {
rom_address = pci_read_config32(dev, PCI_ROM_ADDRESS);
}
@ -45,42 +47,47 @@ struct rom_header * pci_rom_probe(struct device *dev)
return NULL;
}
printk(BIOS_DEBUG, "ROM address for %s = %x\n", dev_path(dev), rom_address);
if(!dev->on_mainboard) {
/* enable expansion ROM address decoding */
printk(BIOS_DEBUG, "ROM address for %s = %x\n", dev_path(dev),
rom_address);
if (!dev->on_mainboard) {
/* Enable expansion ROM address decoding. */
pci_write_config32(dev, PCI_ROM_ADDRESS,
rom_address|PCI_ROM_ADDRESS_ENABLE);
rom_address | PCI_ROM_ADDRESS_ENABLE);
}
rom_header = (struct rom_header *)rom_address;
printk(BIOS_SPEW, "PCI Expansion ROM, signature 0x%04x, INIT size 0x%04x, data ptr 0x%04x\n",
le32_to_cpu(rom_header->signature),
rom_header->size * 512, le32_to_cpu(rom_header->data));
printk(BIOS_SPEW,
"PCI Expansion ROM, signature 0x%04x, INIT size 0x%04x, data ptr 0x%04x\n",
le32_to_cpu(rom_header->signature), rom_header->size * 512,
le32_to_cpu(rom_header->data));
if (le32_to_cpu(rom_header->signature) != PCI_ROM_HDR) {
printk(BIOS_ERR, "Incorrect Expansion ROM Header Signature %04x\n",
le32_to_cpu(rom_header->signature));
printk(BIOS_ERR,
"Incorrect Expansion ROM Header Signature %04x\n",
le32_to_cpu(rom_header->signature));
return NULL;
}
rom_data = (struct pci_data *)((unsigned char *) rom_header +
le32_to_cpu(rom_header->data));
rom_data = (struct pci_data *)((unsigned char *)rom_header +
le32_to_cpu(rom_header->data));
printk(BIOS_SPEW, "PCI ROM Image, Vendor %04x, Device %04x,\n",
rom_data->vendor, rom_data->device);
rom_data->vendor, rom_data->device);
if (dev->vendor != rom_data->vendor || dev->device != rom_data->device) {
printk(BIOS_ERR, "Device or Vendor ID mismatch Vendor %04x, Device %04x\n",
rom_data->vendor, rom_data->device);
printk(BIOS_ERR,
"Device or Vendor ID mismatch Vendor %04x, Device %04x\n",
rom_data->vendor, rom_data->device);
return NULL;
}
printk(BIOS_SPEW, "PCI ROM Image, Class Code %04x%02x, Code Type %02x\n",
rom_data->class_hi, rom_data->class_lo,
rom_data->type);
printk(BIOS_SPEW,
"PCI ROM Image, Class Code %04x%02x, Code Type %02x\n",
rom_data->class_hi, rom_data->class_lo, rom_data->type);
if (dev->class != ((rom_data->class_hi << 8) | rom_data->class_lo)) {
printk(BIOS_DEBUG, "Class Code mismatch ROM %08x, dev %08x\n",
(rom_data->class_hi << 8) | rom_data->class_lo, dev->class);
//return NULL;
printk(BIOS_DEBUG, "Class Code mismatch ROM %08x, dev %08x\n",
(rom_data->class_hi << 8) | rom_data->class_lo,
dev->class);
// return NULL;
}
return rom_header;
@ -89,53 +96,58 @@ struct rom_header * pci_rom_probe(struct device *dev)
static void *pci_ram_image_start = (void *)PCI_RAM_IMAGE_START;
#if defined(CONFIG_PCI_OPTION_ROM_RUN) && CONFIG_PCI_OPTION_ROM_RUN == 1
extern int vga_inited; // defined in vga_console.c
extern int vga_inited; // Defined in vga_console.c.
#ifndef CONFIG_MULTIPLE_VGA_INIT
extern struct device *vga_pri; // the primary vga device, defined in device.c
extern struct device *vga_pri; // The primary VGA device, defined in device.c.
#endif
#endif
struct rom_header *pci_rom_load(struct device *dev, struct rom_header *rom_header)
struct rom_header *pci_rom_load(struct device *dev,
struct rom_header *rom_header)
{
struct pci_data * rom_data;
struct pci_data *rom_data;
unsigned long rom_address;
unsigned int rom_size;
unsigned int image_size=0;
unsigned int image_size = 0;
rom_address = pci_read_config32(dev, PCI_ROM_ADDRESS);
do {
rom_header = (struct rom_header *)((unsigned char *)rom_header
+ image_size); // get next image
rom_data = (struct pci_data *)((unsigned char *) rom_header +
le32_to_cpu(rom_header->data));
image_size = le32_to_cpu(rom_data->ilen) * 512;
} while ((rom_data->type!=0) && (rom_data->indicator!=0)); // make sure we got x86 version
rom_header = (struct rom_header *)((unsigned char *)rom_header + image_size); // Get next image.
rom_data = (struct pci_data *)((unsigned char *)rom_header +
le32_to_cpu(rom_header->data));
image_size = le32_to_cpu(rom_data->ilen) * 512;
} while ((rom_data->type != 0) && (rom_data->indicator != 0)); // Make sure we got x86 version.
if(rom_data->type!=0) return NULL;
if (rom_data->type != 0)
return NULL;
rom_size = rom_header->size * 512;
if (PCI_CLASS_DISPLAY_VGA == rom_data->class_hi) {
#if defined(CONFIG_PCI_OPTION_ROM_RUN) && CONFIG_PCI_OPTION_ROM_RUN == 1
#ifndef CONFIG_MULTIPLE_VGA_INIT
if (dev != vga_pri) return NULL; // only one VGA supported
#endif
printk(BIOS_DEBUG, "Copying VGA ROM image from 0x%x to 0x%x, 0x%x bytes\n",
rom_header, PCI_VGA_RAM_IMAGE_START, rom_size);
#ifndef CONFIG_MULTIPLE_VGA_INIT
if (dev != vga_pri)
return NULL; // Only one VGA supported.
#endif
printk(BIOS_DEBUG,
"Copying VGA ROM image from 0x%x to 0x%x, 0x%x bytes\n",
rom_header, PCI_VGA_RAM_IMAGE_START, rom_size);
memcpy((void *)PCI_VGA_RAM_IMAGE_START, rom_header, rom_size);
vga_inited = 1;
return (struct rom_header *) (PCI_VGA_RAM_IMAGE_START);
return (struct rom_header *)(PCI_VGA_RAM_IMAGE_START);
#endif
} else {
printk(BIOS_DEBUG, "Copying non-VGA ROM image from 0x%x to 0x%x, 0x%x bytes\n",
rom_header, pci_ram_image_start, rom_size);
printk(BIOS_DEBUG,
"Copying non-VGA ROM image from 0x%x to 0x%x, 0x%x bytes\n",
rom_header, pci_ram_image_start, rom_size);
memcpy(pci_ram_image_start, rom_header, rom_size);
pci_ram_image_start += rom_size;
return (struct rom_header *) (pci_ram_image_start-rom_size);
return (struct rom_header *)(pci_ram_image_start - rom_size);
}
/* disable expansion ROM address decoding */
pci_write_config32(dev, PCI_ROM_ADDRESS, rom_address & ~PCI_ROM_ADDRESS_ENABLE);
/* Disable expansion ROM address decoding. */
pci_write_config32(dev, PCI_ROM_ADDRESS,
rom_address & ~PCI_ROM_ADDRESS_ENABLE);
return NULL;
}

View file

@ -24,30 +24,26 @@
#include <device/pci_ids.h>
#include <device/pciexp.h>
static void pciexp_tune_dev(device_t dev)
{
unsigned cap;
unsigned int cap;
cap = pci_find_capability(dev, PCI_CAP_ID_PCIE);
if (!cap) {
/* error... */
return;
}
printk_debug("PCIEXP: tunning %s\n", dev_path(dev));
printk_debug("PCIEXP: tuning %s\n", dev_path(dev));
#warning "IMPLEMENT PCI EXPRESS TUNING"
}
unsigned int pciexp_scan_bus(struct bus *bus,
unsigned min_devfn, unsigned max_devfn,
unsigned int max)
unsigned int pciexp_scan_bus(struct bus *bus, unsigned int min_devfn,
unsigned int max_devfn, unsigned int max)
{
device_t child;
max = pci_scan_bus(bus, min_devfn, max_devfn, max);
for(child = bus->children; child; child = child->sibling) {
if ( (child->path.u.pci.devfn < min_devfn) ||
(child->path.u.pci.devfn > max_devfn))
{
for (child = bus->children; child; child = child->sibling) {
if ((child->path.u.pci.devfn < min_devfn) ||
(child->path.u.pci.devfn > max_devfn)) {
continue;
}
pciexp_tune_dev(child);
@ -55,13 +51,12 @@ unsigned int pciexp_scan_bus(struct bus *bus,
return max;
}
unsigned int pciexp_scan_bridge(device_t dev, unsigned int max)
{
return do_pci_scan_bridge(dev, max, pciexp_scan_bus);
}
/** Default device operations for PCI Express bridges */
/** Default device operations for PCI Express bridges. */
static struct pci_operations pciexp_bus_ops_pci = {
.set_subsystem = 0,
};
@ -70,8 +65,8 @@ struct device_operations default_pciexp_ops_bus = {
.read_resources = pci_bus_read_resources,
.set_resources = pci_dev_set_resources,
.enable_resources = pci_bus_enable_resources,
.init = 0,
.scan_bus = pciexp_scan_bridge,
.init = 0,
.scan_bus = pciexp_scan_bridge,
.enable = 0,
.reset_bus = pci_bus_reset,
.ops_pci = &pciexp_bus_ops_pci,

View file

@ -24,12 +24,11 @@
#include <device/pci_ids.h>
#include <device/pcix.h>
static void pcix_tune_dev(device_t dev)
{
unsigned cap;
unsigned status, orig_cmd, cmd;
unsigned max_read, max_tran;
unsigned int cap;
unsigned int status, orig_cmd, cmd;
unsigned int max_read, max_tran;
if (dev->hdr_type != PCI_HEADER_TYPE_NORMAL) {
return;
@ -40,7 +39,7 @@ static void pcix_tune_dev(device_t dev)
}
printk_debug("%s PCI-X tuning\n", dev_path(dev));
status = pci_read_config32(dev, cap + PCI_X_STATUS);
orig_cmd = cmd = pci_read_config16(dev,cap + PCI_X_CMD);
orig_cmd = cmd = pci_read_config16(dev, cap + PCI_X_CMD);
max_read = (status & PCI_X_STATUS_MAX_READ) >> 21;
max_tran = (status & PCI_X_STATUS_MAX_SPLIT) >> 23;
@ -52,24 +51,23 @@ static void pcix_tune_dev(device_t dev)
cmd &= ~PCI_X_CMD_MAX_SPLIT;
cmd |= max_tran << 4;
}
/* Don't attempt to handle PCI-X errors */
/* Don't attempt to handle PCI-X errors. */
cmd &= ~PCI_X_CMD_DPERR_E;
/* Enable Relaxed Ordering */
/* Enable Relaxed Ordering. */
cmd |= PCI_X_CMD_ERO;
if (orig_cmd != cmd) {
pci_write_config16(dev, cap + PCI_X_CMD, cmd);
}
}
unsigned int pcix_scan_bus(struct bus *bus,
unsigned min_devfn, unsigned max_devfn, unsigned int max)
unsigned int pcix_scan_bus(struct bus *bus, unsigned int min_devfn,
unsigned int max_devfn, unsigned int max)
{
device_t child;
max = pci_scan_bus(bus, min_devfn, max_devfn, max);
for(child = bus->children; child; child = child->sibling) {
if ( (child->path.u.pci.devfn < min_devfn) ||
(child->path.u.pci.devfn > max_devfn))
{
for (child = bus->children; child; child = child->sibling) {
if ((child->path.u.pci.devfn < min_devfn) ||
(child->path.u.pci.devfn > max_devfn)) {
continue;
}
pcix_tune_dev(child);
@ -77,7 +75,7 @@ unsigned int pcix_scan_bus(struct bus *bus,
return max;
}
const char *pcix_speed(unsigned sstatus)
const char *pcix_speed(unsigned int sstatus)
{
static const char conventional[] = "Conventional PCI";
static const char pcix_66mhz[] = "66MHz PCI-X";
@ -86,12 +84,12 @@ const char *pcix_speed(unsigned sstatus)
static const char pcix_266mhz[] = "266MHz PCI-X";
static const char pcix_533mhz[] = "533MHZ PCI-X";
static const char unknown[] = "Unknown";
const char *result;
result = unknown;
switch(PCI_X_SSTATUS_MFREQ(sstatus)) {
case PCI_X_SSTATUS_CONVENTIONAL_PCI:
result = conventional;
switch (PCI_X_SSTATUS_MFREQ(sstatus)) {
case PCI_X_SSTATUS_CONVENTIONAL_PCI:
result = conventional;
break;
case PCI_X_SSTATUS_MODE1_66MHZ:
result = pcix_66mhz;
@ -99,17 +97,14 @@ const char *pcix_speed(unsigned sstatus)
case PCI_X_SSTATUS_MODE1_100MHZ:
result = pcix_100mhz;
break;
case PCI_X_SSTATUS_MODE1_133MHZ:
result = pcix_133mhz;
break;
case PCI_X_SSTATUS_MODE2_266MHZ_REF_66MHZ:
case PCI_X_SSTATUS_MODE2_266MHZ_REF_100MHZ:
case PCI_X_SSTATUS_MODE2_266MHZ_REF_133MHZ:
result = pcix_266mhz;
break;
case PCI_X_SSTATUS_MODE2_533MHZ_REF_66MHZ:
case PCI_X_SSTATUS_MODE2_533MHZ_REF_100MHZ:
case PCI_X_SSTATUS_MODE2_533MHZ_REF_133MHZ:
@ -121,10 +116,9 @@ const char *pcix_speed(unsigned sstatus)
unsigned int pcix_scan_bridge(device_t dev, unsigned int max)
{
unsigned pos;
unsigned sstatus;
unsigned int pos, status;
/* Find the PCI-X capability */
/* Find the PCI-X capability. */
pos = pci_find_capability(dev, PCI_CAP_ID_PCIX);
sstatus = pci_read_config16(dev, pos + PCI_X_SEC_STATUS);
@ -134,14 +128,14 @@ unsigned int pcix_scan_bridge(device_t dev, unsigned int max)
max = do_pci_scan_bridge(dev, max, pcix_scan_bus);
}
/* Print the PCI-X bus speed */
printk_debug("PCI: %02x: %s\n", dev->link[0].secondary, pcix_speed(sstatus));
/* Print the PCI-X bus speed. */
printk_debug("PCI: %02x: %s\n", dev->link[0].secondary,
pcix_speed(sstatus));
return max;
}
/** Default device operations for PCI-X bridges */
/** Default device operations for PCI-X bridges. */
static struct pci_operations pcix_bus_ops_pci = {
.set_subsystem = 0,
};
@ -150,8 +144,8 @@ struct device_operations default_pcix_ops_bus = {
.read_resources = pci_bus_read_resources,
.set_resources = pci_dev_set_resources,
.enable_resources = pci_bus_enable_resources,
.init = 0,
.scan_bus = pcix_scan_bridge,
.init = 0,
.scan_bus = pcix_scan_bridge,
.enable = 0,
.reset_bus = pci_bus_reset,
.ops_pci = &pcix_bus_ops_pci,

View file

@ -24,91 +24,88 @@
#include <arch/types.h>
#include <console/console.h>
#include <stdlib.h>
//#include <stdint.h>
//#include <bitops.h>
// #include <stdint.h>
// #include <bitops.h>
#include <string.h>
#include <arch/io.h>
#include <device/device.h>
#include <device/pnp.h>
/* PNP fundamental operations */
/* PNP fundamental operations: */
void pnp_write_config(struct device * dev, u8 reg, u8 value)
void pnp_write_config(struct device *dev, u8 reg, u8 value)
{
outb(reg, dev->path.u.pnp.port);
outb(value, dev->path.u.pnp.port + 1);
}
u8 pnp_read_config(struct device * dev, u8 reg)
u8 pnp_read_config(struct device *dev, u8 reg)
{
outb(reg, dev->path.u.pnp.port);
return inb(dev->path.u.pnp.port + 1);
}
void pnp_set_logical_device(struct device * dev)
void pnp_set_logical_device(struct device *dev)
{
pnp_write_config(dev, 0x07, dev->path.u.pnp.device);
}
void pnp_set_enable(struct device * dev, int enable)
void pnp_set_enable(struct device *dev, int enable)
{
pnp_write_config(dev, 0x30, enable?0x1:0x0);
pnp_write_config(dev, 0x30, enable ? 0x1 : 0x0);
}
int pnp_read_enable(struct device * dev)
int pnp_read_enable(struct device *dev)
{
return !!pnp_read_config(dev, 0x30);
}
void pnp_set_iobase(struct device * dev, unsigned index, unsigned iobase)
void pnp_set_iobase(struct device *dev, unsigned int index, unsigned int iobase)
{
/* Index == 0x60 or 0x62 */
pnp_write_config(dev, index + 0, (iobase >> 8) & 0xff);
pnp_write_config(dev, index + 1, iobase & 0xff);
}
void pnp_set_irq(struct device * dev, unsigned index, unsigned irq)
void pnp_set_irq(struct device *dev, unsigned int index, unsigned int irq)
{
/* Index == 0x70 or 0x72 */
pnp_write_config(dev, index, irq);
}
void pnp_set_drq(struct device * dev, unsigned index, unsigned drq)
void pnp_set_drq(struct device *dev, unsigned int index, unsigned int drq)
{
/* Index == 0x74 */
pnp_write_config(dev, index, drq & 0xff);
}
/* PNP device operations */
/* PNP device operations: */
void pnp_read_resources(struct device * dev)
void pnp_read_resources(struct device *dev)
{
return;
}
static void pnp_set_resource(struct device * dev, struct resource *resource)
static void pnp_set_resource(struct device *dev, struct resource *resource)
{
if (!(resource->flags & IORESOURCE_ASSIGNED)) {
printk(BIOS_ERR, "ERROR: %s %02x %s size: 0x%010Lx not assigned\n",
dev_path(dev), resource->index,
resource_type(resource),
resource->size);
printk(BIOS_ERR,
"ERROR: %s %02x %s size: 0x%010Lx not assigned\n",
dev_path(dev), resource->index, resource_type(resource),
resource->size);
return;
}
/* Now store the resource */
/* Now store the resource. */
if (resource->flags & IORESOURCE_IO) {
pnp_set_iobase(dev, resource->index, resource->base);
}
else if (resource->flags & IORESOURCE_DRQ) {
} else if (resource->flags & IORESOURCE_DRQ) {
pnp_set_drq(dev, resource->index, resource->base);
}
else if (resource->flags & IORESOURCE_IRQ) {
} else if (resource->flags & IORESOURCE_IRQ) {
pnp_set_irq(dev, resource->index, resource->base);
}
else {
} else {
printk(BIOS_ERR, "ERROR: %s %02x unknown resource type\n",
dev_path(dev), resource->index);
dev_path(dev), resource->index);
return;
}
resource->flags |= IORESOURCE_STORED;
@ -116,26 +113,26 @@ static void pnp_set_resource(struct device * dev, struct resource *resource)
report_resource_stored(dev, resource, "");
}
void pnp_set_resources(struct device * dev)
void pnp_set_resources(struct device *dev)
{
int i;
/* Select the device */
/* Select the device. */
pnp_set_logical_device(dev);
/* Paranoia says I should disable the device here... */
for(i = 0; i < dev->resources; i++) {
for (i = 0; i < dev->resources; i++) {
pnp_set_resource(dev, &dev->resource[i]);
}
}
void pnp_enable_resources(struct device * dev)
void pnp_enable_resources(struct device *dev)
{
pnp_set_logical_device(dev);
pnp_set_enable(dev, 1);
}
void pnp_enable(struct device * dev)
void pnp_enable(struct device *dev)
{
if (!dev->enabled) {
pnp_set_logical_device(dev);
@ -147,37 +144,41 @@ struct device_operations pnp_ops = {
.phase4_read_resources = pnp_read_resources,
.phase4_set_resources = pnp_set_resources,
.phase5_enable_resources = pnp_enable_resources,
//.enable = pnp_enable,
// .enable = pnp_enable,
// FIXME
};
/* PNP chip operations */
/* PNP chip operations: */
static void pnp_get_ioresource(struct device * dev, unsigned index, struct io_info *info)
static void pnp_get_ioresource(struct device *dev, unsigned int index,
struct io_info *info)
{
struct resource *resource;
unsigned moving, gran, step;
unsigned int moving, gran, step;
resource = new_resource(dev, index);
/* Initilize the resource */
/* Initilize the resource. */
resource->limit = 0xffff;
resource->flags |= IORESOURCE_IO;
/* Get the resource size */
/* Get the resource size. */
moving = info->mask;
gran = 15;
step = 1 << gran;
/* Find the first bit that moves */
while((moving & step) == 0) {
/* Find the first bit that moves. */
while ((moving & step) == 0) {
gran--;
step >>= 1;
}
/* Now find the first bit that does not move */
while((moving & step) != 0) {
/* Now find the first bit that does not move. */
while ((moving & step) != 0) {
gran--;
step >>= 1;
}
/* Of the moving bits the last bit in the first group,
* tells us the size of this resource.
*/
@ -185,14 +186,15 @@ static void pnp_get_ioresource(struct device * dev, unsigned index, struct io_in
gran++;
step <<= 1;
}
/* Set the resource size and alignment */
resource->gran = gran;
/* Set the resource size and alignment. */
resource->gran = gran;
resource->align = gran;
resource->limit = info->mask | (step - 1);
resource->size = 1 << gran;
resource->size = 1 << gran;
}
static void get_resources(struct device * dev, struct pnp_info *info)
static void get_resources(struct device *dev, struct pnp_info *info)
{
struct resource *resource;
@ -227,27 +229,27 @@ static void get_resources(struct device * dev, struct pnp_info *info)
resource = new_resource(dev, PNP_IDX_DRQ1);
resource->size = 1;
resource->flags |= IORESOURCE_DRQ;
}
}
}
}
void pnp_enable_devices(struct device * base_dev, struct device_operations *ops,
unsigned functions, struct pnp_info *info)
void pnp_enable_devices(struct device *base_dev, struct device_operations *ops,
unsigned int functions, struct pnp_info *info)
{
struct device_path path;
struct device_id id = {.type = DEVICE_ID_PNP};
struct device * dev;
struct device_id id = {.type = DEVICE_ID_PNP };
struct device *dev;
int i;
path.type = DEVICE_PATH_PNP;
path.type = DEVICE_PATH_PNP;
path.u.pnp.port = base_dev->path.u.pnp.port;
/* Setup the ops and resources on the newly allocated devices */
for(i = 0; i < functions; i++) {
/* Setup the ops and resources on the newly allocated devices. */
for (i = 0; i < functions; i++) {
path.u.pnp.device = info[i].function;
dev = alloc_find_dev(base_dev->bus, &path, &id);
/* Don't initialize a device multiple times */
if (dev->ops)
/* Don't initialize a device multiple times. */
if (dev->ops)
continue;
if (info[i].ops == 0) {

View file

@ -25,61 +25,62 @@
#include <console/console.h>
#include <device/device.h>
#include <device/pci.h>
//#include <part/hard_reset.h>
// #include <part/hard_reset.h>
/**
* Read the resources for the root device,
* that encompass the resources for the entire system.
* @param root Pointer to the device structure for the system root device
*
* @param root Pointer to the device structure for the system root device.
*/
void root_dev_read_resources(struct device * root)
void root_dev_read_resources(struct device *root)
{
struct resource *resource;
/* Initialize the system wide io space constraints */
/* Initialize the system wide I/O space constraints. */
resource = new_resource(root, 0);
resource->base = 0x400;
resource->size = 0;
resource->base = 0x400;
resource->size = 0;
resource->align = 0;
resource->gran = 0;
resource->gran = 0;
resource->limit = 0xffffUL;
resource->flags = IORESOURCE_IO;
compute_allocate_resource(&root->link[0], resource,
IORESOURCE_IO, IORESOURCE_IO);
compute_allocate_resource(&root->link[0], resource,
IORESOURCE_IO, IORESOURCE_IO);
/* Initialize the system wide memory resources constraints */
/* Initialize the system wide memory resources constraints. */
resource = new_resource(root, 1);
resource->base = 0;
resource->size = 0;
resource->base = 0;
resource->size = 0;
resource->align = 0;
resource->gran = 0;
resource->gran = 0;
resource->limit = 0xffffffffUL;
resource->flags = IORESOURCE_MEM;
compute_allocate_resource(&root->link[0], resource,
IORESOURCE_MEM, IORESOURCE_MEM);
IORESOURCE_MEM, IORESOURCE_MEM);
}
/**
* @brief Write the resources for every device
*
* Write the resources for the root device,
* and every device under it which are all of the devices.
* @param root Pointer to the device structure for the system root device
*
* @param root Pointer to the device structure for the system root device.
*/
void root_dev_set_resources(struct device * root)
void root_dev_set_resources(struct device *root)
{
struct bus *bus;
bus = &root->link[0];
compute_allocate_resource(bus,
&root->resource[0], IORESOURCE_IO, IORESOURCE_IO);
compute_allocate_resource(bus,
&root->resource[1], IORESOURCE_MEM, IORESOURCE_MEM);
&root->resource[0], IORESOURCE_IO,
IORESOURCE_IO);
compute_allocate_resource(bus, &root->resource[1], IORESOURCE_MEM,
IORESOURCE_MEM);
phase4_assign_resources(bus);
}
/**
* @brief Scan devices on static buses.
* Scan devices on static buses.
*
* The enumeration of certain buses is purely static. The existence of
* devices on those buses can be completely determined at compile time
@ -96,58 +97,65 @@ void root_dev_set_resources(struct device * root)
* This function is the default scan_bus() method for the root device and
* LPC bridges.
*
* @param bus Pointer to the device structure which the static buses are attached
* @param max Maximum bus number currently used before scanning.
* @param busdevice Pointer to the device structure which the static
* buses are attached.
* @param max Maximum bus number currently used before scanning.
* @return Largest bus number used.
*/
static int smbus_max = 0;
unsigned int scan_static_bus(struct device * busdevice, unsigned int max)
unsigned int scan_static_bus(struct device *busdevice, unsigned int max)
{
struct device * child;
unsigned link;
struct device *child;
unsigned int link;
printk(BIOS_INFO, "%s for %s(%s)\n", __func__, busdevice->dtsname, dev_path(busdevice));
printk(BIOS_INFO, "%s for %s(%s)\n", __func__, busdevice->dtsname,
dev_path(busdevice));
for(link = 0; link < busdevice->links; link++) {
/* for smbus bus enumerate */
for (link = 0; link < busdevice->links; link++) {
/* For smbus bus enumerate. */
child = busdevice->link[link].children;
if(child && child->path.type == DEVICE_PATH_I2C) {
if (child && child->path.type == DEVICE_PATH_I2C) {
busdevice->link[link].secondary = ++smbus_max;
}
for(child = busdevice->link[link].children; child; child = child->sibling) {
for (child = busdevice->link[link].children; child;
child = child->sibling) {
if (child->ops && child->ops->phase3_enable_scan) {
child->ops->phase3_enable_scan(child);
}
/* sigh. Have to enable to scan ... */
/* Sigh. Have to enable to scan... */
if (child->ops && child->ops->phase5_enable_resources) {
child->ops->phase5_enable_resources(child);
}
if (child->path.type == DEVICE_PATH_I2C) {
printk(BIOS_DEBUG, "smbus: %s(%s)[%d]->",
child->dtsname, dev_path(child->bus->dev), child->bus->link );
if (child->path.type == DEVICE_PATH_I2C) {
printk(BIOS_DEBUG, "smbus: %s(%s)[%d]->",
child->dtsname,
dev_path(child->bus->dev),
child->bus->link);
}
printk(BIOS_DEBUG, "%s(%s) %s\n",
child->dtsname, dev_path(child), child->enabled?"enabled": "disabled");
child->dtsname, dev_path(child),
child->enabled ? "enabled" : "disabled");
}
}
for(link = 0; link < busdevice->links; link++) {
for(child = busdevice->link[link].children; child; child = child->sibling) {
for (link = 0; link < busdevice->links; link++) {
for (child = busdevice->link[link].children; child;
child = child->sibling) {
if (!child->ops || !child->ops->phase3_scan)
continue;
printk(BIOS_INFO, "%s(%s) scanning...\n", child->dtsname, dev_path(child));
printk(BIOS_INFO, "%s(%s) scanning...\n",
child->dtsname, dev_path(child));
max = dev_phase3_scan(child, max);
}
}
printk(BIOS_INFO, "%s for %s(%s) done\n", __func__, busdevice->dtsname, dev_path(busdevice));
printk(BIOS_INFO, "%s for %s(%s) done\n", __func__, busdevice->dtsname,
dev_path(busdevice));
return max;
}
/**
* @brief Enable resources for children devices
*
* @param dev the device whos children's resources are to be enabled
* Enable resources for children devices.
*
* This function is called by the global enable_resource() indirectly via the
* device_operation::enable_resources() method of devices.
@ -156,65 +164,69 @@ unsigned int scan_static_bus(struct device * busdevice, unsigned int max)
* enable_childrens_resources() -> enable_resources()
* enable_resources() -> device_operation::enable_resources()
* device_operation::enable_resources() -> enable_children_resources()
*
* @param dev The device whose children's resources are to be enabled.
*/
void enable_childrens_resources(struct device * dev)
void enable_childrens_resources(struct device *dev)
{
unsigned link;
for(link = 0; link < dev->links; link++) {
struct device * child;
for(child = dev->link[link].children; child; child = child->sibling) {
unsigned int link;
for (link = 0; link < dev->links; link++) {
struct device *child;
for (child = dev->link[link].children; child;
child = child->sibling) {
dev_phase5(child);
}
}
}
void root_dev_enable_resources(struct device * dev)
void root_dev_enable_resources(struct device *dev)
{
enable_childrens_resources(dev);
}
/**
* @brief Scan root bus for generic systems
*
* @param root The root device structure
* @param max The current bus number scanned so far, usually 0x00
* Scan root bus for generic systems.
*
* This function is the default scan_bus() method of the root device.
*
* @param root The root device structure.
* @param max The current bus number scanned so far, usually 0x00.
* @return TODO
*/
unsigned int root_dev_scan_bus(struct device * root, unsigned int max)
unsigned int root_dev_scan_bus(struct device *root, unsigned int max)
{
return scan_static_bus(root, max);
}
void root_dev_init(struct device * root)
void root_dev_init(struct device *root)
{
}
void root_dev_reset(struct bus *bus)
{
printk(BIOS_INFO, "Reseting board... NOT! Define hard_reset please\n");
// hard_reset();
printk(BIOS_INFO, "Resetting board... NOT! Define hard_reset please\n");
// hard_reset();
}
/**
* @brief Default device operation for root device
* Default device operation for root device.
*
* This is the default device operation for root devices. These operations
* should be fully usable as is. If you need something else, set up your own ops
* in (e.g.) the mainboard, and initialize it in the dts in the mainboard directory.
*
* should be fully usable as is. If you need something else, set up your
* own ops in (e.g.) the mainboard, and initialize it in the dts in the
* mainboard directory.
*/
struct device_operations default_dev_ops_root = {
.phase4_read_resources = root_dev_read_resources,
.phase4_set_resources = root_dev_set_resources,
.phase5_enable_resources = root_dev_enable_resources,
.phase6_init = root_dev_init,
.phase3_scan = root_dev_scan_bus,
.reset_bus = root_dev_reset,
.phase3_scan = root_dev_scan_bus,
.reset_bus = root_dev_reset,
};
/**
* @brief The root of device tree.
* The root of device tree.
*
* This is the root of the device tree. The device tree is defined in the
* static.c file and is generated by config tool during compile time.

View file

@ -31,85 +31,99 @@ struct bus *get_pbus_smbus(device_t dev)
while (pbus && pbus->dev && !ops_smbus_bus(pbus)) {
pbus = pbus->dev->bus;
}
if (!pbus || !pbus->dev || !pbus->dev->ops || !pbus->dev->ops->ops_smbus_bus) {
printk_alert("%s Cannot find smbus bus operations", dev_path(dev));
if (!pbus || !pbus->dev || !pbus->dev->ops
|| !pbus->dev->ops->ops_smbus_bus) {
printk_alert("%s Cannot find smbus bus operations",
dev_path(dev));
die("");
for(;;);
for (;;) ;
}
return pbus;
}
/*multi level i2c MUX??? may need to find the first i2c device and then set link
* down to current dev
1 store get_pbus_smbus list link
2 reverse the link and call set link */
/**
* Multi-level i2c MUX? May need to find the first i2c device and then
* set link down to current dev.
* 1 store get_pbus_smbus list link
* 2 reverse the link and call set link
*/
int smbus_set_link(device_t dev)
{
struct bus *pbus_a[4]; // 4 level mux only. Enough?
struct bus *pbus = dev->bus;
int pbus_num=0;
struct bus *pbus_a[4]; // 4 level mux only. Enough?
struct bus *pbus = dev->bus;
int pbus_num = 0;
int i;
while(pbus && pbus->dev && (pbus->dev->path.type==DEVICE_PATH_I2C)) {
while (pbus && pbus->dev && (pbus->dev->path.type == DEVICE_PATH_I2C)) {
pbus_a[pbus_num++] = pbus;
pbus = pbus->dev->bus;
}
// printk_info("smbus_set_link: ");
for (i=pbus_num-1; i>=0; i--) {
// printk_info(" %s[%d] -> ", dev_path(pbus_a[i]->dev), pbus_a[i]->link);
if (ops_smbus_bus(get_pbus_smbus(pbus_a[i]->dev))) {
if (pbus_a[i]->dev->ops && pbus_a[i]->dev->ops->set_link)
pbus_a[i]->dev->ops->set_link(pbus_a[i]->dev, pbus_a[i]->link);
pbus = pbus->dev->bus;
}
// printk_info("smbus_set_link: ");
for (i = pbus_num - 1; i >= 0; i--) {
// printk_info(" %s[%d] -> ", dev_path(pbus_a[i]->dev), pbus_a[i]->link);
if (ops_smbus_bus(get_pbus_smbus(pbus_a[i]->dev))) {
if (pbus_a[i]->dev->ops
&& pbus_a[i]->dev->ops->set_link)
pbus_a[i]->dev->ops->set_link(pbus_a[i]->dev,
pbus_a[i]->link);
}
}
// printk_info(" %s\n", dev_path(dev));
// printk_info(" %s\n", dev_path(dev));
return pbus_num;
return pbus_num;
}
int smbus_quick_read(device_t dev)
{
return ops_smbus_bus(get_pbus_smbus(dev))->quick_read(dev);
}
int smbus_quick_write(device_t dev)
{
return ops_smbus_bus(get_pbus_smbus(dev))->quick_write(dev);
}
int smbus_recv_byte(device_t dev)
{
return ops_smbus_bus(get_pbus_smbus(dev))->recv_byte(dev);
}
int smbus_send_byte(device_t dev, u8 byte)
{
return ops_smbus_bus(get_pbus_smbus(dev))->send_byte(dev, byte);
}
int smbus_read_byte(device_t dev, u8 addr)
{
return ops_smbus_bus(get_pbus_smbus(dev))->read_byte(dev, addr);
}
int smbus_write_byte(device_t dev, u8 addr, u8 val)
{
return ops_smbus_bus(get_pbus_smbus(dev))->write_byte(dev, addr, val);
}
int smbus_read_word(device_t dev, u8 addr)
{
return ops_smbus_bus(get_pbus_smbus(dev))->read_word(dev, addr);
}
int smbus_write_word(device_t dev, u8 addr, u16 val)
{
return ops_smbus_bus(get_pbus_smbus(dev))->write_word(dev, addr, val);
}
int smbus_process_call(device_t dev, u8 cmd, u16 data)
{
return ops_smbus_bus(get_pbus_smbus(dev))->process_call(dev, cmd, data);
}
int smbus_block_read(device_t dev, u8 cmd, u8 bytes, u8 *buffer)
{
return ops_smbus_bus(get_pbus_smbus(dev))->block_read(dev, cmd, bytes, buffer);
return ops_smbus_bus(get_pbus_smbus(dev))->block_read(dev, cmd, bytes,
buffer);
}
int smbus_block_write(device_t dev, u8 cmd, u8 bytes, const u8 *buffer)
{
return ops_smbus_bus(get_pbus_smbus(dev))->block_write(dev, cmd, bytes, buffer);
return ops_smbus_bus(get_pbus_smbus(dev))->block_write(dev, cmd, bytes,
buffer);
}