#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 parent 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.
*/
device_t find_dev_path(struct bus *parent, struct device_path *path)
{
device_t child;
- for(child = parent->children; child; child = child->sibling) {
+ for (child = parent->children; child; child = child->sibling) {
if (path_eq(path, &child->path)) {
break;
}
}
/**
- * @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 parent 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.
*/
device_t alloc_find_dev(struct bus *parent, struct device_path *path)
{
}
/**
- * @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 (if found), 0 otherwise.
*/
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 an 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 (if found), 0 otherwise.
*/
struct device *dev_find_slot_on_smbus(unsigned int bus, unsigned int addr)
{
return result;
}
-/** Find a device of a given vendor and type
- * @param vendor Vendor ID (e.g. 0x8086 for Intel)
- * @param device Device ID
+/**
+ * Find a device of a given vendor and type.
+ *
+ * @param vendor A PCI vendor ID (e.g. 0x8086 for Intel).
+ * @param device A PCI device ID.
* @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
+ * 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;
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
+ * 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)
{
return from;
}
-/* Warning: This function uses a static buffer. Don't call it more than once
- * from the same print statement! */
-
+/*
+ * Warning: This function uses a static buffer. Don't call it more than once
+ * from the same print statement!
+ */
const char *dev_path(device_t dev)
{
static char buffer[DEVICE_PATH_MAX];
+
buffer[0] = '\0';
if (!dev) {
memcpy(buffer, "<null>", 7);
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_num);
return buffer;
}
/**
* Allocate 64 more resources to the free list.
+ *
+ * @return TODO.
*/
static int allocate_more_resources(void)
{
/**
* Remove resource res from the device's list and add it to the free list.
+ *
+ * @param dev TODO
+ * @param res TODO
+ * @param prev TODO
+ * @return TODO.
*/
-static void free_resource(device_t dev, struct resource *res, struct resource *prev)
+static void free_resource(device_t dev, struct resource *res,
+ struct resource *prev)
{
if (prev)
prev->next = res->next;
/**
* 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(device_t dev)
{
struct resource *res, *next, *prev = NULL;
/* Move all of the free resources to the end */
- for(res = dev->resource_list; res; res = next) {
+ for (res = dev->resource_list; res; res = next) {
next = res->next;
if (!res->flags)
free_resource(dev, res, prev);
}
}
-
/**
- * 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(device_t dev, unsigned index)
{
struct resource *res;
+
/* See if there is a resource with the appropriate index */
- for(res = dev->resource_list; res; res = res->next) {
+ for (res = dev->resource_list; res; res = res->next) {
if (res->index == index)
break;
}
}
/**
- * 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.
+ * 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.
+ * @return TODO.
*/
struct resource *new_resource(device_t dev, unsigned index)
{
/**
* 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.
+ * return TODO.
*/
struct resource *find_resource(device_t dev, unsigned index)
{
/**
- * @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.
+ * @return The aligned value.
*/
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.
+ * @return The aligned value.
*/
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.
+ * @return The end.
*/
resource_t resource_end(struct resource *resource)
{
}
/**
- * @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.
+ * @return The maximum.
*/
resource_t resource_max(struct resource *resource)
{
}
/**
- * @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.
+ * @return TODO.
*/
const char *resource_type(struct resource *resource)
{
}
/**
- * @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.
+ * @param comment TODO
*/
-void report_resource_stored(device_t dev, struct resource *resource, const char *comment)
+void report_resource_stored(device_t dev, struct resource *resource,
+ const char *comment)
{
if (resource->flags & IORESOURCE_STORED) {
char buf[10];
buf[0] = '\0';
if (resource->flags & IORESOURCE_PCI_BRIDGE) {
#if CONFIG_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_list->secondary & 0xff);
#else
- sprintf(buf, "bus %02x ", dev->link[0].secondary);
+ sprintf(buf, "bus %02x ", dev->link_list->secondary);
#endif
}
printk(BIOS_DEBUG,
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) {
struct resource *res;
/* Ignore disabled devices */
if (!curdev->enabled) continue;
- for(res = curdev->resource_list; res; res = res->next) {
+ for (res = curdev->resource_list; res; res = res->next) {
/* If it isn't the right kind of resource ignore it */
if ((res->flags & type_mask) != type) {
continue;
/* If it is a subtractive resource recurse */
if (res->flags & IORESOURCE_SUBTRACTIVE) {
struct bus * subbus;
- subbus = &curdev->link[IOINDEX_SUBTRACTIVE_LINK(res->index)];
+ for (subbus = curdev->link_list; subbus; subbus = subbus->next)
+ if (subbus->link_num == IOINDEX_SUBTRACTIVE_LINK(res->index))
+ break;
search_bus_resources(subbus, type_mask, type, search, gp);
continue;
}
resource_search_t search, void *gp)
{
struct device *curdev;
- for(curdev = all_devices; curdev; curdev = curdev->next) {
+ for (curdev = all_devices; curdev; curdev = curdev->next) {
struct resource *res;
/* Ignore disabled devices */
if (!curdev->enabled) continue;
- for(res = curdev->resource_list; res; res = res->next) {
+ for (res = curdev->resource_list; res; res = res->next) {
/* If it isn't the right kind of resource ignore it */
if ((res->flags & type_mask) != type) {
continue;
void disable_children(struct bus *bus)
{
device_t child;
- for(child = bus->children; child; child = child->sibling) {
- int link;
- for(link = 0; link < child->links; link++) {
- disable_children(&child->link[link]);
+ for (child = bus->children; child; child = child->sibling) {
+ struct bus *link;
+ for (link = child->link_list; link; link = link->next) {
+ disable_children(link);
}
dev_set_enabled(child, 0);
}
static void resource_tree(struct device *root, int debug_level, int depth)
{
- int i = 0, link = 0;
+ int i = 0;
struct device *child;
+ struct bus *link;
struct resource *res;
char indent[30]; /* If your tree has more levels, it's wrong. */
indent[i] = ' ';
indent[i] = '\0';
- do_printk(debug_level, "%s%s links %x child on link 0", indent,
- dev_path(root), root->links);
- do_printk(debug_level, " %s\n", root->link[0].children ?
- dev_path(root->link[0].children) : "NULL");
+ do_printk(BIOS_DEBUG, "%s%s", indent, dev_path(root));
+ if (root->link_list && root->link_list->children)
+ do_printk(BIOS_DEBUG, " child on link 0 %s",
+ dev_path(root->link_list->children));
+ do_printk(BIOS_DEBUG, "\n");
+
for (res = root->resource_list; res; res = res->next) {
do_printk(debug_level,
"%s%s resource base %llx size %llx align %d gran %d limit %llx flags %lx index %lx\n",
res->flags, res->index);
}
- for (link = 0; link < root->links; link++) {
- for (child = root->link[link].children; child;
- child = child->sibling)
+ for (link = root->link_list; link; link = link->next) {
+ for (child = link->children; child; child = child->sibling)
resource_tree(child, debug_level, depth + 1);
}
}
char depth_str[20] = "";
int i;
struct device *sibling;
+ struct bus *link;
+
for (i = 0; i < depth; i++)
depth_str[i] = ' ';
depth_str[i] = '\0';
do_printk(debug_level, "%s%s: enabled %d\n",
depth_str, dev_path(dev), dev->enabled);
- for (i = 0; i < dev->links; i++) {
- for (sibling = dev->link[i].children; sibling;
+ for (link = dev->link_list; link; link = link->next) {
+ for (sibling = link->children; sibling;
sibling = sibling->sibling)
show_devs_tree(sibling, debug_level, depth + 1, i);
}
show_one_resource(debug_level, dev, res, "");
}
}
+
+void ram_resource(device_t dev, unsigned long index,
+ unsigned long basek, unsigned long sizek)
+{
+ struct resource *resource;
+
+ if (!sizek)
+ return;
+
+ resource = new_resource(dev, index);
+ resource->base = ((resource_t)basek) << 10;
+ resource->size = ((resource_t)sizek) << 10;
+ resource->flags = IORESOURCE_MEM | IORESOURCE_CACHEABLE | \
+ IORESOURCE_FIXED | IORESOURCE_STORED | IORESOURCE_ASSIGNED;
+}
+
+void tolm_test(void *gp, struct device *dev, struct resource *new)
+{
+ struct resource **best_p = gp;
+ struct resource *best;
+
+ best = *best_p;
+
+ if (!best || (best->base > new->base))
+ best = new;
+
+ *best_p = best;
+}
+
+u32 find_pci_tolm(struct bus *bus)
+{
+ struct resource *min = NULL;
+ u32 tolm;
+
+ search_bus_resources(bus, IORESOURCE_MEM, IORESOURCE_MEM,
+ tolm_test, &min);
+
+ tolm = 0xffffffffUL;
+
+ if (min && tolm > min->base)
+ tolm = min->base;
+
+ return tolm;
+}