2003-09-02 05:36:25 +02:00
|
|
|
#include <console/console.h>
|
|
|
|
#include <device/device.h>
|
|
|
|
#include <device/pci.h>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Read the resources for the root device,
|
2004-05-05 23:15:42 +02:00
|
|
|
* that encompass the resources for the entire system.
|
2003-09-02 05:36:25 +02:00
|
|
|
* @param root Pointer to the device structure for the system root device
|
|
|
|
*/
|
|
|
|
void root_dev_read_resources(device_t root)
|
|
|
|
{
|
|
|
|
int res = 0;
|
|
|
|
|
|
|
|
/* Initialize the system wide io space constraints */
|
|
|
|
root->resource[res].base = 0x400;
|
|
|
|
root->resource[res].size = 0;
|
|
|
|
root->resource[res].align = 0;
|
|
|
|
root->resource[res].gran = 0;
|
|
|
|
root->resource[res].limit = 0xffffUL;
|
|
|
|
root->resource[res].flags = IORESOURCE_IO;
|
|
|
|
root->resource[res].index = 0;
|
|
|
|
compute_allocate_resource(&root->link[0], &root->resource[res],
|
2004-10-14 22:54:17 +02:00
|
|
|
IORESOURCE_IO, IORESOURCE_IO);
|
2003-09-02 05:36:25 +02:00
|
|
|
res++;
|
|
|
|
|
|
|
|
/* Initialize the system wide memory resources constraints */
|
|
|
|
root->resource[res].base = 0;
|
|
|
|
root->resource[res].size = 0;
|
|
|
|
root->resource[res].align = 0;
|
|
|
|
root->resource[res].gran = 0;
|
|
|
|
root->resource[res].limit = 0xffffffffUL;
|
|
|
|
root->resource[res].flags = IORESOURCE_MEM;
|
|
|
|
root->resource[res].index = 1;
|
|
|
|
compute_allocate_resource(&root->link[0], &root->resource[res],
|
2004-10-14 22:54:17 +02:00
|
|
|
IORESOURCE_MEM, IORESOURCE_MEM);
|
2003-09-02 05:36:25 +02:00
|
|
|
res++;
|
|
|
|
|
|
|
|
root->resources = res;
|
2004-10-14 22:54:17 +02:00
|
|
|
printk_spew("%s DONE\n", __func__);
|
2003-09-02 05:36:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
void root_dev_set_resources(device_t root)
|
|
|
|
{
|
2004-10-14 22:54:17 +02:00
|
|
|
struct bus *bus;
|
2004-03-23 22:28:05 +01:00
|
|
|
|
2004-10-14 22:54:17 +02:00
|
|
|
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);
|
2003-09-02 05:36:25 +02:00
|
|
|
assign_resources(bus);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2004-05-07 23:52:47 +02:00
|
|
|
* @brief Scan devices on static buses.
|
|
|
|
*
|
2004-05-10 18:05:16 +02:00
|
|
|
* The enumeration of certain buses is purely static. The existence of
|
|
|
|
* devices on those buses can be completely determined at compile time
|
|
|
|
* by the config file. Typical expamles are the 'PNP' devices on a legacy
|
|
|
|
* ISA/LPC bus. There is no need of probing of any kind, the only thing
|
|
|
|
* we have to do is to walk through the bus and enable or disable devices
|
|
|
|
* as indicated in the config file.
|
2004-05-07 23:52:47 +02:00
|
|
|
*
|
|
|
|
* This function is the default scan_bus() method for LPC bridges.
|
|
|
|
*
|
2003-09-02 05:36:25 +02:00
|
|
|
* @param root Pointer to the device structure for the system root device
|
|
|
|
* @param max Maximum bus number allowed in the system.
|
|
|
|
* @return Largest bus number used.
|
|
|
|
*/
|
2004-05-07 23:52:47 +02:00
|
|
|
unsigned int scan_static_bus(device_t bus, unsigned int max)
|
2003-09-02 05:36:25 +02:00
|
|
|
{
|
|
|
|
device_t child;
|
|
|
|
unsigned link;
|
2004-10-14 22:54:17 +02:00
|
|
|
|
|
|
|
printk_debug("%s for %s\n", __func__, dev_path(bus));
|
2004-03-23 22:28:05 +01:00
|
|
|
|
2004-10-14 22:54:17 +02:00
|
|
|
for(link = 0; link < bus->links; link++) {
|
|
|
|
for(child = bus->link[link].children; child; child = child->sibling) {
|
2003-09-02 05:36:25 +02:00
|
|
|
if (child->ops && child->ops->enable) {
|
|
|
|
child->ops->enable(child);
|
|
|
|
}
|
2004-10-14 22:54:17 +02:00
|
|
|
printk_debug("%s %s\n",
|
|
|
|
dev_path(child),
|
|
|
|
child->enabled?"enabled": "disabled");
|
2003-09-02 05:36:25 +02:00
|
|
|
}
|
|
|
|
}
|
2004-10-14 22:54:17 +02:00
|
|
|
for(link = 0; link < bus->links; link++) {
|
|
|
|
for(child = bus->link[link].children; child; child = child->sibling) {
|
2003-09-02 05:36:25 +02:00
|
|
|
if (!child->ops || !child->ops->scan_bus)
|
|
|
|
continue;
|
|
|
|
printk_debug("%s scanning...\n", dev_path(child));
|
|
|
|
max = child->ops->scan_bus(child, max);
|
|
|
|
}
|
|
|
|
}
|
2004-05-07 23:52:47 +02:00
|
|
|
|
2004-10-14 22:54:17 +02:00
|
|
|
printk_debug("%s done\n", __func__);
|
2004-05-07 23:52:47 +02:00
|
|
|
|
2003-09-02 05:36:25 +02:00
|
|
|
return max;
|
|
|
|
}
|
|
|
|
|
2004-05-05 23:15:42 +02:00
|
|
|
/**
|
|
|
|
* @brief Enable resources for children devices
|
|
|
|
*
|
2004-05-07 23:52:47 +02:00
|
|
|
* @param dev the device whos children's resources are to be enabled
|
2004-05-05 23:15:42 +02:00
|
|
|
*
|
2004-05-10 18:05:16 +02:00
|
|
|
* This function is call by the enable_resource() indirectly via the
|
|
|
|
* enable_resources() method of devices.
|
|
|
|
*
|
|
|
|
* Indirect mutual recursion:
|
2004-05-05 23:15:42 +02:00
|
|
|
*/
|
2003-09-02 05:36:25 +02:00
|
|
|
void enable_childrens_resources(device_t dev)
|
|
|
|
{
|
|
|
|
unsigned link;
|
2004-10-14 22:54:17 +02:00
|
|
|
for(link = 0; link < dev->links; link++) {
|
2003-09-02 05:36:25 +02:00
|
|
|
device_t child;
|
2004-10-14 22:54:17 +02:00
|
|
|
for(child = dev->link[link].children; child; child = child->sibling) {
|
2003-09-02 05:36:25 +02:00
|
|
|
enable_resources(child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-05 23:15:42 +02:00
|
|
|
/**
|
|
|
|
* @brief Scan root bus for generic PCI systems
|
|
|
|
*
|
2004-05-07 23:52:47 +02:00
|
|
|
* @param root The root device structure
|
|
|
|
* @param max The current bus number scanned so fat, usually 0x00
|
2004-05-05 23:15:42 +02:00
|
|
|
*
|
2004-05-07 23:52:47 +02:00
|
|
|
* This function is the default scan_bus() method of the dynamic root device.
|
|
|
|
* The bus heirachy is rooted at the host/northbridge. The northbridge of a
|
|
|
|
* generic PCI bus system is at Bus 0, Dev 0, Fun 0 so we scan the whole PCI
|
|
|
|
* buses from there.
|
2004-05-05 23:15:42 +02:00
|
|
|
*/
|
2003-09-02 05:36:25 +02:00
|
|
|
unsigned int root_dev_scan_pci_bus(device_t root, unsigned int max)
|
|
|
|
{
|
|
|
|
return pci_scan_bus(&root->link[0], 0, 0xff, max);
|
|
|
|
}
|
|
|
|
|
2004-05-05 23:15:42 +02:00
|
|
|
/**
|
|
|
|
* @brief Default device operation for root device
|
|
|
|
*
|
|
|
|
* This is the default device operation for root devices in PCI based systems.
|
|
|
|
* The static enumeration code chip_control::enumerate() of mainboards usually
|
2004-05-10 18:05:16 +02:00
|
|
|
* override this operation with their own device operations. An notable
|
|
|
|
* example is mainboard operations for AMD K8 mainboards. They replace the
|
|
|
|
* scan_bus() method with amdk8_scan_root_bus() due to the special device
|
|
|
|
* layout of AMD K8 systems.
|
2004-05-05 23:15:42 +02:00
|
|
|
*/
|
2003-09-02 05:36:25 +02:00
|
|
|
struct device_operations default_dev_ops_root = {
|
|
|
|
.read_resources = root_dev_read_resources,
|
|
|
|
.set_resources = root_dev_set_resources,
|
|
|
|
.enable_resources = enable_childrens_resources,
|
|
|
|
.init = 0,
|
|
|
|
.scan_bus = root_dev_scan_pci_bus,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2004-05-07 23:52:47 +02:00
|
|
|
* @brief The root of dynamic device tree.
|
|
|
|
*
|
|
|
|
* This is the root of the dynamic device tree. A PCI tree always has
|
2003-09-02 05:36:25 +02:00
|
|
|
* one bus, bus 0. Bus 0 contains devices and bridges.
|
|
|
|
*/
|
|
|
|
struct device dev_root = {
|
|
|
|
.ops = &default_dev_ops_root,
|
|
|
|
.bus = &dev_root.link[0],
|
2003-10-11 08:20:25 +02:00
|
|
|
.path = { .type = DEVICE_PATH_ROOT },
|
2004-04-29 22:08:54 +02:00
|
|
|
.enabled = 1,
|
2004-10-14 22:54:17 +02:00
|
|
|
.links = 1,
|
|
|
|
.link = {
|
|
|
|
[0] = {
|
|
|
|
.dev = &dev_root,
|
|
|
|
.link = 0,
|
|
|
|
},
|
|
|
|
},
|
2003-09-02 05:36:25 +02:00
|
|
|
};
|