clean up VGA and Expansion ROM support

git-svn-id: svn://svn.coreboot.org/coreboot/trunk@1831 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
This commit is contained in:
Li-Ta Lo 2004-12-27 04:25:41 +00:00
parent 5b772cca55
commit e8b1c9dbd1
3 changed files with 87 additions and 96 deletions

View File

@ -16,7 +16,7 @@
device_t find_dev_path(struct bus *parent, struct device_path *path) device_t find_dev_path(struct bus *parent, struct device_path *path)
{ {
device_t child; 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)) { if (path_eq(path, &child->path)) {
break; break;
} }
@ -42,7 +42,8 @@ device_t alloc_find_dev(struct bus *parent, struct device_path *path)
} }
/** /**
* Given a bus and a devfn number, find the device structure * @brief Given a PCI bus and a devfn number, find the device structure
*
* @param bus The bus number * @param bus The bus number
* @param devfn a device/function number * @param devfn a device/function number
* @return pointer to the device structure * @return pointer to the device structure
@ -369,7 +370,8 @@ resource_t resource_max(struct resource *resource)
* @param dev the device the stored resorce lives on * @param dev the device the stored resorce lives on
* @param resource the resource that was just stored. * @param resource the resource that was just stored.
*/ */
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) { if (resource->flags & IORESOURCE_STORED) {
unsigned char buf[10]; unsigned char buf[10];
@ -390,6 +392,7 @@ void report_resource_stored(device_t dev, struct resource *resource, const char
(resource->flags & IORESOURCE_IO)? "io": (resource->flags & IORESOURCE_IO)? "io":
(resource->flags & IORESOURCE_DRQ)? "drq": (resource->flags & IORESOURCE_DRQ)? "drq":
(resource->flags & IORESOURCE_IRQ)? "irq": (resource->flags & IORESOURCE_IRQ)? "irq":
(resource->flags & IORESOURCE_READONLY)? "rom":
(resource->flags & IORESOURCE_MEM)? "mem": (resource->flags & IORESOURCE_MEM)? "mem":
"????", "????",
comment); comment);

View File

@ -53,6 +53,7 @@ static uint16_t pci_moving_config16(struct device *dev, unsigned reg)
return ones ^ zeroes; return ones ^ zeroes;
} }
static uint32_t pci_moving_config32(struct device *dev, unsigned reg) static uint32_t pci_moving_config32(struct device *dev, unsigned reg)
{ {
uint32_t value, ones, zeroes; uint32_t value, ones, zeroes;
@ -92,7 +93,6 @@ unsigned pci_find_capability(device_t dev, unsigned cap)
return 0; return 0;
} }
/** Given a device and register, read the size of the BAR for that register. /** Given a device and register, read the size of the BAR for that register.
* @param dev Pointer to the device structure * @param dev Pointer to the device structure
* @param resource Pointer to the resource structure * @param resource Pointer to the resource structure
@ -134,7 +134,7 @@ struct resource *pci_get_resource(struct device *dev, unsigned long index)
if (moving) { if (moving) {
resource->size = 1; resource->size = 1;
resource->align = resource->gran = 0; resource->align = resource->gran = 0;
while(!(moving & resource->size)) { while (!(moving & resource->size)) {
resource->size <<= 1; resource->size <<= 1;
resource->align += 1; resource->align += 1;
resource->gran += 1; resource->gran += 1;
@ -158,15 +158,13 @@ struct resource *pci_get_resource(struct device *dev, unsigned long index)
dev_path(dev), index, value); dev_path(dev), index, value);
} }
resource->flags = 0; resource->flags = 0;
} } else if (attr & PCI_BASE_ADDRESS_SPACE_IO) {
else if (attr & PCI_BASE_ADDRESS_SPACE_IO) {
/* An I/O mapped base address */ /* An I/O mapped base address */
attr &= PCI_BASE_ADDRESS_IO_ATTR_MASK; attr &= PCI_BASE_ADDRESS_IO_ATTR_MASK;
resource->flags |= IORESOURCE_IO; resource->flags |= IORESOURCE_IO;
/* I don't want to deal with 32bit I/O resources */ /* I don't want to deal with 32bit I/O resources */
resource->limit = 0xffff; resource->limit = 0xffff;
} } else {
else {
/* A Memory mapped base address */ /* A Memory mapped base address */
attr &= PCI_BASE_ADDRESS_MEM_ATTR_MASK; attr &= PCI_BASE_ADDRESS_MEM_ATTR_MASK;
resource->flags |= IORESOURCE_MEM; resource->flags |= IORESOURCE_MEM;
@ -177,17 +175,14 @@ struct resource *pci_get_resource(struct device *dev, unsigned long index)
if (attr == PCI_BASE_ADDRESS_MEM_LIMIT_32) { if (attr == PCI_BASE_ADDRESS_MEM_LIMIT_32) {
/* 32bit limit */ /* 32bit limit */
resource->limit = 0xffffffffUL; resource->limit = 0xffffffffUL;
} } else if (attr == PCI_BASE_ADDRESS_MEM_LIMIT_1M) {
else if (attr == PCI_BASE_ADDRESS_MEM_LIMIT_1M) {
/* 1MB limit */ /* 1MB limit */
resource->limit = 0x000fffffUL; resource->limit = 0x000fffffUL;
} } else if (attr == PCI_BASE_ADDRESS_MEM_LIMIT_64) {
else if (attr == PCI_BASE_ADDRESS_MEM_LIMIT_64) {
/* 64bit limit */ /* 64bit limit */
resource->limit = 0xffffffffffffffffULL; resource->limit = 0xffffffffffffffffULL;
resource->flags |= IORESOURCE_PCI64; resource->flags |= IORESOURCE_PCI64;
} } else {
else {
/* Invalid value */ /* Invalid value */
resource->flags = 0; resource->flags = 0;
} }
@ -217,26 +212,10 @@ struct resource *pci_get_resource(struct device *dev, unsigned long index)
return resource; return resource;
} }
/** Read the base address registers for a given device. static void pci_get_rom_resource(struct device *dev, unsigned long index)
* @param dev Pointer to the dev structure
* @param howmany How many registers to read (6 for device, 2 for bridge)
*/
static void pci_read_bases(struct device *dev, unsigned int howmany)
{
unsigned long index;
for (index = PCI_BASE_ADDRESS_0; (index < PCI_BASE_ADDRESS_0 + (howmany << 2)); ) {
struct resource *resource;
resource = pci_get_resource(dev, index);
index += (resource->flags & IORESOURCE_PCI64)?8:4;
}
compact_resources(dev);
}
static void pci_read_rom_resource(struct device *dev, unsigned long index)
{ {
struct resource *resource; struct resource *resource;
unsigned long value, attr; unsigned long value;
resource_t moving, limit; resource_t moving, limit;
/* Initialize the resources to nothing */ /* Initialize the resources to nothing */
@ -248,7 +227,7 @@ static void pci_read_rom_resource(struct device *dev, unsigned long index)
/* See which bits move */ /* See which bits move */
moving = pci_moving_config32(dev, index); moving = pci_moving_config32(dev, index);
/* clear the Enable bit */ /* clear the Enable bit */
moving = moving & 0xffffffffe; moving = moving & ~PCI_ROM_ADDRESS_ENABLE;
/* Find the resource constraints. /* Find the resource constraints.
* *
@ -262,14 +241,12 @@ static void pci_read_rom_resource(struct device *dev, unsigned long index)
if (moving) { if (moving) {
resource->size = 1; resource->size = 1;
resource->align = resource->gran = 0; resource->align = resource->gran = 0;
while(!(moving & resource->size)) { while (!(moving & resource->size)) {
resource->size <<= 1; resource->size <<= 1;
resource->align += 1; resource->align += 1;
resource->gran += 1; resource->gran += 1;
} }
resource->limit = limit = moving | (resource->size - 1); resource->limit = limit = moving | (resource->size - 1);
printk_debug("%s, rom size: %x, limit: %x\n",
dev_path(dev), resource->size, limit);
} }
if (moving == 0) { if (moving == 0) {
@ -281,8 +258,25 @@ static void pci_read_rom_resource(struct device *dev, unsigned long index)
} else { } else {
resource->flags |= IORESOURCE_MEM | IORESOURCE_READONLY; resource->flags |= IORESOURCE_MEM | IORESOURCE_READONLY;
} }
compact_resources(dev); }
/** Read the base address registers for a given device.
* @param dev Pointer to the dev structure
* @param howmany How many registers to read (6 for device, 2 for bridge)
*/
static void pci_read_bases(struct device *dev, unsigned int howmany, unsigned long rom)
{
unsigned long index;
for (index = PCI_BASE_ADDRESS_0; (index < PCI_BASE_ADDRESS_0 + (howmany << 2)); ) {
struct resource *resource;
resource = pci_get_resource(dev, index);
index += (resource->flags & IORESOURCE_PCI64)?8:4;
}
if (rom)
pci_get_rom_resource(dev, rom);
compact_resources(dev);
} }
static void pci_set_resource(struct device *dev, struct resource *resource); static void pci_set_resource(struct device *dev, struct resource *resource);
@ -328,7 +322,6 @@ static void pci_bridge_read_bases(struct device *dev)
{ {
resource_t moving_base, moving_limit, moving; resource_t moving_base, moving_limit, moving;
/* See if the bridge I/O resources are implemented */ /* See if the bridge I/O resources are implemented */
moving_base = ((uint32_t)pci_moving_config8(dev, PCI_IO_BASE)) << 8; moving_base = ((uint32_t)pci_moving_config8(dev, PCI_IO_BASE)) << 8;
moving_base |= ((uint32_t)pci_moving_config16(dev, PCI_IO_BASE_UPPER16)) << 16; moving_base |= ((uint32_t)pci_moving_config16(dev, PCI_IO_BASE_UPPER16)) << 16;
@ -339,10 +332,8 @@ static void pci_bridge_read_bases(struct device *dev)
moving = moving_base & moving_limit; moving = moving_base & moving_limit;
/* Initialize the io space constraints on the current bus */ /* Initialize the io space constraints on the current bus */
pci_record_bridge_resource( pci_record_bridge_resource(dev, moving, PCI_IO_BASE,
dev, moving, PCI_IO_BASE, IORESOURCE_IO, IORESOURCE_IO);
IORESOURCE_IO, IORESOURCE_IO);
/* See if the bridge prefmem resources are implemented */ /* See if the bridge prefmem resources are implemented */
moving_base = ((resource_t)pci_moving_config16(dev, PCI_PREF_MEMORY_BASE)) << 16; moving_base = ((resource_t)pci_moving_config16(dev, PCI_PREF_MEMORY_BASE)) << 16;
@ -353,11 +344,9 @@ static void pci_bridge_read_bases(struct device *dev)
moving = moving_base & moving_limit; moving = moving_base & moving_limit;
/* Initiliaze the prefetchable memory constraints on the current bus */ /* Initiliaze the prefetchable memory constraints on the current bus */
pci_record_bridge_resource( pci_record_bridge_resource(dev, moving, PCI_PREF_MEMORY_BASE,
dev, moving, PCI_PREF_MEMORY_BASE, IORESOURCE_MEM | IORESOURCE_PREFETCH,
IORESOURCE_MEM | IORESOURCE_PREFETCH, IORESOURCE_MEM | IORESOURCE_PREFETCH);
IORESOURCE_MEM | IORESOURCE_PREFETCH);
/* See if the bridge mem resources are implemented */ /* See if the bridge mem resources are implemented */
moving_base = ((uint32_t)pci_moving_config16(dev, PCI_MEMORY_BASE)) << 16; moving_base = ((uint32_t)pci_moving_config16(dev, PCI_MEMORY_BASE)) << 16;
@ -366,10 +355,9 @@ static void pci_bridge_read_bases(struct device *dev)
moving = moving_base & moving_limit; moving = moving_base & moving_limit;
/* Initialize the memory resources on the current bus */ /* Initialize the memory resources on the current bus */
pci_record_bridge_resource( pci_record_bridge_resource(dev, moving, PCI_MEMORY_BASE,
dev, moving, PCI_MEMORY_BASE, IORESOURCE_MEM | IORESOURCE_PREFETCH,
IORESOURCE_MEM | IORESOURCE_PREFETCH, IORESOURCE_MEM);
IORESOURCE_MEM);
compact_resources(dev); compact_resources(dev);
} }
@ -378,9 +366,7 @@ void pci_dev_read_resources(struct device *dev)
{ {
uint32_t addr; uint32_t addr;
pci_read_bases(dev, 6); pci_read_bases(dev, 6, PCI_ROM_ADDRESS);
pci_read_rom_resource(dev, PCI_ROM_ADDRESS);
} }
void pci_bus_read_resources(struct device *dev) void pci_bus_read_resources(struct device *dev)
@ -388,9 +374,7 @@ void pci_bus_read_resources(struct device *dev)
uint32_t addr; uint32_t addr;
pci_bridge_read_bases(dev); pci_bridge_read_bases(dev);
pci_read_bases(dev, 2); pci_read_bases(dev, 2, PCI_ROM_ADDRESS1);
pci_read_rom_resource(dev, PCI_ROM_ADDRESS1);
} }
static void pci_set_resource(struct device *dev, struct resource *resource) static void pci_set_resource(struct device *dev, struct resource *resource)
@ -722,9 +706,8 @@ static struct device *pci_scan_get_dev(struct device **list, unsigned int devfn)
* *
* @return The maximum bus number found, after scanning all subordinate busses * @return The maximum bus number found, after scanning all subordinate busses
*/ */
unsigned int pci_scan_bus(struct bus *bus, unsigned int pci_scan_bus(struct bus *bus, unsigned min_devfn, unsigned max_devfn,
unsigned min_devfn, unsigned max_devfn, unsigned int max)
unsigned int max)
{ {
unsigned int devfn; unsigned int devfn;
device_t dev; device_t dev;
@ -1000,8 +983,7 @@ static void pci_level_irq(unsigned char intNum)
-kevinh@ispiri.com -kevinh@ispiri.com
*/ */
void pci_assign_irqs(unsigned bus, unsigned slot, void pci_assign_irqs(unsigned bus, unsigned slot, const unsigned char pIntAtoD[4])
const unsigned char pIntAtoD[4])
{ {
unsigned functNum; unsigned functNum;
device_t pdev; device_t pdev;

View File

@ -196,8 +196,8 @@ static unsigned int amdk8_scan_chains(device_t dev, unsigned int max)
return max; return max;
} }
static int reg_useable(unsigned reg, static int reg_useable(unsigned reg, device_t goal_dev, unsigned goal_nodeid,
device_t goal_dev, unsigned goal_nodeid, unsigned goal_link) unsigned goal_link)
{ {
struct resource *res; struct resource *res;
unsigned nodeid, link; unsigned nodeid, link;
@ -221,9 +221,7 @@ static int reg_useable(unsigned reg,
} }
#if 0 #if 0
printk_debug("reg: %02x result: %d gnodeid: %u glink: %u nodeid: %u link: %u\n", printk_debug("reg: %02x result: %d gnodeid: %u glink: %u nodeid: %u link: %u\n",
reg, result, reg, result, goal_nodeid, goal_link, nodeid, link);
goal_nodeid, goal_link,
nodeid, link);
#endif #endif
return result; return result;
} }
@ -420,28 +418,36 @@ static void amdk8_set_resource(device_t dev, struct resource *resource, unsigned
report_resource_stored(dev, resource, buf); report_resource_stored(dev, resource, buf);
} }
/**
*
* I tried to reuse the resource allocation code in amdk8_set_resource()
* but it is too diffcult to deal with the resource allocation magic.
*/
static void amdk8_create_vga_resource(device_t dev, unsigned nodeid) static void amdk8_create_vga_resource(device_t dev, unsigned nodeid)
{ {
struct resource *resource; struct resource *resource;
unsigned link; unsigned link;
uint32_t base, limit; uint32_t base, limit;
unsigned reg; unsigned reg;
/* find out which link the VGA card is connected,
* we only deal with the 'first' vga card */
for (link = 0; link < dev->links; link++) { for (link = 0; link < dev->links; link++) {
if (dev->link[link].bridge_ctrl & PCI_BRIDGE_CTL_VGA) { if (dev->link[link].bridge_ctrl & PCI_BRIDGE_CTL_VGA) {
printk_info("%s: bridge on link %d has VGA device\n", break;
dev_path(dev), link);
printk_info("creating MEM pair for VGA memory\n");
/* Initialize the io space constraints on the current bus */
resource = amdk8_find_mempair(dev, nodeid, link);
printk_info("MEM pair register %x\n", resource->index - 0x100);
resource->base = 0xa0000;
resource->size = 0x20000;
resource->gran = 16;
resource->align = 16;
resource->flags = IORESOURCE_MEM | IORESOURCE_FIXED | IORESOURCE_ASSIGNED;
} }
} }
#if 1
/* no VGA card installed */
if (link == dev->links)
return;
/* allocate a temp resrouce for legacy VGA buffer */
resource = amdk8_find_mempair(dev, nodeid, link);
resource->base = 0xa0000;
resource->size = 0x20000;
/* write the resource to the hardware */
reg = resource->index & 0xfc; reg = resource->index & 0xfc;
base = f1_read_config32(reg); base = f1_read_config32(reg);
limit = f1_read_config32(reg + 0x4); limit = f1_read_config32(reg + 0x4);
@ -455,10 +461,10 @@ static void amdk8_create_vga_resource(device_t dev, unsigned nodeid)
f1_write_config32(reg + 0x4, limit); f1_write_config32(reg + 0x4, limit);
f1_write_config32(reg, base); f1_write_config32(reg, base);
/* release the resource */ /* release the temp resource */
resource->flags = 0; resource->flags = 0;
#endif
} }
static void amdk8_set_resources(device_t dev) static void amdk8_set_resources(device_t dev)
{ {
unsigned nodeid, link; unsigned nodeid, link;
@ -474,7 +480,7 @@ static void amdk8_set_resources(device_t dev)
amdk8_set_resource(dev, &dev->resource[i], nodeid); amdk8_set_resource(dev, &dev->resource[i], nodeid);
} }
for(link = 0; link < dev->links; link++) { for (link = 0; link < dev->links; link++) {
struct bus *bus; struct bus *bus;
bus = &dev->link[link]; bus = &dev->link[link];
if (bus->children) { if (bus->children) {
@ -549,7 +555,7 @@ static void pci_domain_read_resources(device_t dev)
/* Find the already assigned resource pairs */ /* Find the already assigned resource pairs */
get_fx_devs(); get_fx_devs();
for(reg = 0x80; reg <= 0xd8; reg+= 0x08) { for (reg = 0x80; reg <= 0xd8; reg+= 0x08) {
uint32_t base, limit; uint32_t base, limit;
base = f1_read_config32(reg); base = f1_read_config32(reg);
limit = f1_read_config32(reg + 0x04); limit = f1_read_config32(reg + 0x04);
@ -584,7 +590,7 @@ static void pci_domain_read_resources(device_t dev)
} }
static void ram_resource(device_t dev, unsigned long index, static void ram_resource(device_t dev, unsigned long index,
unsigned long basek, unsigned long sizek) unsigned long basek, unsigned long sizek)
{ {
struct resource *resource; struct resource *resource;
@ -642,7 +648,7 @@ static void pci_domain_set_resources(device_t dev)
#endif #endif
idx = 10; idx = 10;
for(i = 0; i < 8; i++) { for (i = 0; i < 8; i++) {
uint32_t base, limit; uint32_t base, limit;
unsigned basek, limitk, sizek; unsigned basek, limitk, sizek;
base = f1_read_config32(0x40 + (i << 3)); base = f1_read_config32(0x40 + (i << 3));
@ -689,7 +695,7 @@ static unsigned int pci_domain_scan_bus(device_t dev, unsigned int max)
{ {
unsigned reg; unsigned reg;
/* Unmap all of the HT chains */ /* Unmap all of the HT chains */
for(reg = 0xe0; reg <= 0xec; reg += 4) { for (reg = 0xe0; reg <= 0xec; reg += 4) {
f1_write_config32(reg, 0); f1_write_config32(reg, 0);
} }
max = pci_scan_bus(&dev->link[0], PCI_DEVFN(0x18, 0), 0xff, max); max = pci_scan_bus(&dev->link[0], PCI_DEVFN(0x18, 0), 0xff, max);
@ -712,7 +718,7 @@ static unsigned int cpu_bus_scan(device_t dev, unsigned int max)
/* Find which cpus are present */ /* Find which cpus are present */
cpu_bus = &dev->link[0]; cpu_bus = &dev->link[0];
for(i = 0; i < 8; i++) { for (i = 0; i < 8; i++) {
device_t dev, cpu; device_t dev, cpu;
struct device_path cpu_path; struct device_path cpu_path;
@ -743,8 +749,8 @@ static unsigned int cpu_bus_scan(device_t dev, unsigned int max)
/* Report what I have done */ /* Report what I have done */
if (cpu) { if (cpu) {
printk_debug("CPU: %s %s\n", printk_debug("CPU: %s %s\n", dev_path(cpu),
dev_path(cpu), cpu->enabled?"enabled":"disabled"); cpu->enabled?"enabled":"disabled");
} }
} }
return max; return max;