Doxidization, reformat

git-svn-id: svn://svn.coreboot.org/coreboot/trunk@1469 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
This commit is contained in:
Li-Ta Lo 2004-03-23 21:28:05 +00:00
parent 9f46132e96
commit e52666931a
22 changed files with 572 additions and 289 deletions

View File

@ -1,6 +1,9 @@
/* -*- asm -*- */
jmp cpu_reset_out jmp cpu_reset_out
__cpu_reset: __cpu_reset:
/* set the boot_complete flag */
movl $0xffffffff, %ebp movl $0xffffffff, %ebp
jmp __main jmp __main

View File

@ -37,9 +37,6 @@ it with the version available from LANL.
#include <device/pci.h> #include <device/pci.h>
#include <device/chip.h> #include <device/chip.h>
#include <delay.h> #include <delay.h>
#if 0
#include <part/mainboard.h>
#endif
#include <part/hard_reset.h> #include <part/hard_reset.h>
#include <smp/atomic.h> #include <smp/atomic.h>
#include <boot/elf.h> #include <boot/elf.h>
@ -81,6 +78,12 @@ static struct mem_range *get_ramsize(void)
/* Number of cpus that are currently running in linuxbios */ /* Number of cpus that are currently running in linuxbios */
static atomic_t active_cpus = ATOMIC_INIT(1); static atomic_t active_cpus = ATOMIC_INIT(1);
/**
* @brief Initialize secondary processors.
*
*
* @todo move this into a method of per cpu data structure.
*/
void secondary_cpu_init(void) void secondary_cpu_init(void)
{ {
struct mem_range *mem; struct mem_range *mem;
@ -88,12 +91,14 @@ void secondary_cpu_init(void)
int index; int index;
atomic_inc(&active_cpus); atomic_inc(&active_cpus);
printk_debug("%s\n", __FUNCTION__); printk_debug("%s\n", __FUNCTION__);
mem = get_ramsize(); mem = get_ramsize();
id = cpu_initialize(mem); id = cpu_initialize(mem);
index = processor_index(id); index = processor_index(id);
printk_debug("%s %d/%u\n", __FUNCTION__ , index, id); printk_debug("%s %d/%u\n", __FUNCTION__ , index, id);
processor_map[index] = CPU_ENABLED; processor_map[index] = CPU_ENABLED;
atomic_dec(&active_cpus); atomic_dec(&active_cpus);
stop_cpu(id); stop_cpu(id);
} }
@ -105,20 +110,22 @@ static void wait_for_other_cpus(void)
old_active_count = 1; old_active_count = 1;
active_count = atomic_read(&active_cpus); active_count = atomic_read(&active_cpus);
while(active_count > 1) { while (active_count > 1) {
if (active_count != old_active_count) { if (active_count != old_active_count) {
printk_info("Waiting for %d CPUS to stop\n", active_count); printk_info("Waiting for %d CPUS to stop\n",
active_count);
old_active_count = active_count; old_active_count = active_count;
} }
active_count = atomic_read(&active_cpus); active_count = atomic_read(&active_cpus);
} }
for(i = 0; i < CONFIG_MAX_CPUS; i++) {
for (i = 0; i < CONFIG_MAX_CPUS; i++) {
if (!(processor_map[i] & CPU_ENABLED)) { if (!(processor_map[i] & CPU_ENABLED)) {
printk_err("CPU %d did not initialize!\n", i); printk_err("CPU %d did not initialize!\n", i);
processor_map[i] = 0; processor_map[i] = 0;
#warning "FIXME do I need a mainboard_cpu_fixup function?"
} }
} }
printk_debug("All AP CPUs stopped\n"); printk_debug("All AP CPUs stopped\n");
} }
@ -126,20 +133,16 @@ static void wait_for_other_cpus(void)
#define wait_for_other_cpus() do {} while(0) #define wait_for_other_cpus() do {} while(0)
#endif /* CONFIG_SMP */ #endif /* CONFIG_SMP */
/**
* @brief Main program of LinuxBIOS
*
* @param boot_complete
*/
void hardwaremain(int boot_complete) void hardwaremain(int boot_complete)
{ {
/* Processor ID of the BOOT cpu (i.e. the one running this code) */ /* Processor ID of the BOOT cpu (i.e. the one running this code) */
unsigned long boot_cpu; unsigned long boot_cpu;
int boot_index; int boot_index;
/* the order here is a bit tricky. We don't want to do much of
* anything that uses config registers until after PciAllocateResources
* since that function also figures out what kind of config strategy
* to use (type 1 or type 2).
* so we turn on cache, then worry about PCI setup, then do other
* things, so that the other work can use the PciRead* and PciWrite*
* functions.
*/
struct mem_range *mem, *tmem; struct mem_range *mem, *tmem;
struct lb_memory *lb_mem; struct lb_memory *lb_mem;
unsigned long totalmem; unsigned long totalmem;
@ -153,8 +156,8 @@ void hardwaremain(int boot_complete)
post_code(0x39); post_code(0x39);
printk_notice("LinuxBIOS-%s%s %s %s...\n", printk_notice("LinuxBIOS-%s%s %s %s...\n",
linuxbios_version, linuxbios_extra_version, linuxbios_build, linuxbios_version, linuxbios_extra_version,
(boot_complete)?"rebooting":"booting"); linuxbios_build, (boot_complete)?"rebooting":"booting");
post_code(0x40); post_code(0x40);
@ -162,57 +165,68 @@ void hardwaremain(int boot_complete)
if (boot_complete) { if (boot_complete) {
hard_reset(); hard_reset();
} }
CONFIGURE(CONF_PASS_PRE_PCI); CONFIGURE(CONF_PASS_PRE_PCI);
/* pick how to scan the bus. This is first so we can get at memory size. */ /* determine how software can generate PCI configuration transactions
* in this system */
printk_info("Finding PCI configuration type.\n"); printk_info("Finding PCI configuration type.\n");
pci_set_method(); pci_set_method();
post_code(0x5f); post_code(0x5f);
/* convert static device structures into dynamic device structures
* before probing dynamic devices. */
enumerate_static_devices(); enumerate_static_devices();
/* probe the existence of dynamic devices and construct the dynamic
* device tree. */
dev_enumerate(); dev_enumerate();
post_code(0x66); post_code(0x66);
/* Now do the real bus.
* We round the total ram up a lot for thing like the SISFB, which /* probe and assign the resources required by the dynamic devices */
* shares high memory with the CPU.
*/
dev_configure(); dev_configure();
post_code(0x88); post_code(0x88);
/* enable the resources probed and assigned in dev_configure() */
dev_enable(); dev_enable();
/* do the device specific init in additional to simple resources
* allocation performed in dev_enable() */
dev_initialize(); dev_initialize();
post_code(0x89); post_code(0x89);
CONFIGURE(CONF_PASS_POST_PCI); CONFIGURE(CONF_PASS_POST_PCI);
/* this is done last because some devices may 'steal' memory from
* the system during device initialization. */
mem = get_ramsize(); mem = get_ramsize();
post_code(0x70); post_code(0x70);
totalmem = 0; for (totalmem = 0, tmem = mem; tmem->sizek; tmem++) {
for(tmem = mem; tmem->sizek; tmem++) {
totalmem += tmem->sizek; totalmem += tmem->sizek;
} }
printk_info("totalram: %ldM\n", /* Round to the nearest mega */
(totalmem + 512) >> 10); /* Round to the nearest meg */ printk_info("totalram: %ldM\n", (totalmem + 512) >> 10);
/* Fully initialize the cpu before configuring the bus */ /* fully initialize the boot processor */
boot_cpu = cpu_initialize(mem); boot_cpu = cpu_initialize(mem);
boot_index = processor_index(boot_cpu); boot_index = processor_index(boot_cpu);
printk_spew("BOOT CPU is %d\n", boot_cpu); printk_spew("BOOT CPU is %d\n", boot_cpu);
processor_map[boot_index] = CPU_BOOTPROCESSOR|CPU_ENABLED; processor_map[boot_index] = CPU_BOOTPROCESSOR|CPU_ENABLED;
/* Now start the other cpus initializing /* start up other processors, it works like a pthread_create() or
* The sooner they start the sooner they stop. * fork(), instead of running the initialization code for all devices
*/ * as the boot processor, they start from secondary_cpu_init(), doing
* cpu initialization only. */
post_code(0x75); post_code(0x75);
startup_other_cpus(processor_map); startup_other_cpus(processor_map);
post_code(0x77);
/* make certain we are the only cpu running in linuxBIOS */ /* like pthread_join() or wait(), wait other processors finishing
* their execution of secondary_cpu_init() and make certain we are
* the only cpu running in LinuxBIOS */
wait_for_other_cpus(); wait_for_other_cpus();
/* Now that we have collected all of our information /* Now that we have collected all of our information, write our
* write our configuration tables. * configuration tables. */
*/
lb_mem = write_tables(mem, processor_map); lb_mem = write_tables(mem, processor_map);
CONFIGURE(CONF_PASS_PRE_BOOT); CONFIGURE(CONF_PASS_PRE_BOOT);

View File

@ -717,6 +717,11 @@ define HAVE_ACPI_TABLES
comment "Define to build ACPI tables" comment "Define to build ACPI tables"
end end
define AGP_APERTURE_SIZE
default none
export used
comment "AGP graphics virtual memory aperture size"
end
############################################### ###############################################
# Board specific options # Board specific options

View File

@ -1,3 +1,6 @@
# How does the config tool pick the correct
# cpufixup.c to generate cupfixup.o ?
uses k8 uses k8
uses CPU_FIXUP uses CPU_FIXUP
default k8=1 default k8=1

View File

@ -428,5 +428,5 @@ void k8_enable(struct chip *chip, enum chip_pass pass)
struct chip_control cpu_k8_control = { struct chip_control cpu_k8_control = {
.enable = k8_enable, .enable = k8_enable,
.name = "AMD K8", .name = "AMD K8 CPU",
}; };

View File

@ -27,13 +27,24 @@ static void early_mtrr_init(void)
msr_t msr; msr_t msr;
const unsigned long *msr_addr; const unsigned long *msr_addr;
/* Enable the access to AMD RdDram and WrDram extension bits */
msr = rdmsr(SYSCFG_MSR);
msr.lo |= SYSCFG_MSR_MtrrFixDramModEn;
wrmsr(msr);
/* Inialize all of the relevant msrs to 0 */ /* Inialize all of the relevant msrs to 0 */
msr.lo = 0; msr.lo = 0;
msr.hi = 0; msr.hi = 0;
for(msr_addr = mtrr_msrs; *msr_addr; msr_addr++) {
for (msr_addr = mtrr_msrs; *msr_addr; msr_addr++) {
wrmsr(*msr_addr, msr); wrmsr(*msr_addr, msr);
} }
/* Disable the access to AMD RdDram and WrDram extension bits */
msr = rdmsr(SYSCFG_MSR);
msr.lo &= ~SYSCFG_MSR_MtrrFixDramModEn;
wrmsr(msr);
/* Enable memory access for 0 - 1MB using top_mem */ /* Enable memory access for 0 - 1MB using top_mem */
msr.hi = 0; msr.hi = 0;
msr.lo = ((CONFIG_LB_MEM_TOPK << 10) + TOP_MEM_MASK) & ~TOP_MEM_MASK; msr.lo = ((CONFIG_LB_MEM_TOPK << 10) + TOP_MEM_MASK) & ~TOP_MEM_MASK;

View File

@ -13,6 +13,13 @@ earlymtrr_start:
xorl %edx, %edx # xorl %edx, %edx #
movl $fixed_mtrr_msr, %esi movl $fixed_mtrr_msr, %esi
enable_fixed_mtrr_dram_modify:
/* Enable the access to AMD RdDram and WrDram extension bits */
movl $SYSCFG_MSR, %ecx
rdmsr
orl $SYSCFG_MSR_MtrrFixDramModEn, %eax
wrmsr
clear_fixed_var_mtrr: clear_fixed_var_mtrr:
lodsl (%esi), %eax lodsl (%esi), %eax
testl %eax, %eax testl %eax, %eax
@ -25,7 +32,14 @@ clear_fixed_var_mtrr:
jmp clear_fixed_var_mtrr jmp clear_fixed_var_mtrr
clear_fixed_var_mtrr_out: clear_fixed_var_mtrr_out:
/* enable memory access for 0 - 1MB using top_mem */ disable_fixed_mtrr_dram_modify:
/* Disable the access to AMD RdDram and WrDram extension bits */
movl $SYSCFG_MSR, %ecx
rdmsr
andl $(~SYSCFG_MSR_MtrrFixDramModEn), %eax
wrmsr
/* enable memory access for 0 - 1MB using top_mem */
movl $TOP_MEM, %ecx movl $TOP_MEM, %ecx
xorl %edx, %edx xorl %edx, %edx
movl $(((CONFIG_LB_MEM_TOPK << 10) + TOP_MEM_MASK) & ~TOP_MEM_MASK) , %eax movl $(((CONFIG_LB_MEM_TOPK << 10) + TOP_MEM_MASK) & ~TOP_MEM_MASK) , %eax
@ -72,9 +86,10 @@ enable_mtrr:
movl $0x00000800, %eax movl $0x00000800, %eax
wrmsr wrmsr
/* Enable the MTRRs in SYSCFG */ /* Enable the MTRRs and IORRs in SYSCFG */
movl $SYSCFG_MSR, %ecx movl $SYSCFG_MSR, %ecx
rdmsr rdmsr
/* Don't enable SYSCFG_MSR_MtrrFixDramEn) untill we have done with VGA BIOS */
orl $(SYSCFG_MSR_MtrrVarDramEn), %eax orl $(SYSCFG_MSR_MtrrVarDramEn), %eax
wrmsr wrmsr

View File

@ -99,7 +99,7 @@ static void intel_set_var_mtrr(unsigned int reg, unsigned long basek, unsigned l
base.hi = basek >> 22; base.hi = basek >> 22;
base.lo = basek << 10; base.lo = basek << 10;
//printk_debug("ADDRESS_MASK_HIGH=%#x\n", ADDRESS_MASK_HIGH); //printk_debug("ADDRESS_MASK_HIGH=%#x\n", ADDRESS_MASK_HIGH);
if (sizek < 4*1024*1024) { if (sizek < 4*1024*1024) {
mask.hi = ADDRESS_MASK_HIGH; mask.hi = ADDRESS_MASK_HIGH;
@ -219,7 +219,7 @@ static void set_fixed_mtrrs(unsigned int first, unsigned int last, unsigned char
unsigned int fixed_msr = NUM_FIXED_RANGES >> 3; unsigned int fixed_msr = NUM_FIXED_RANGES >> 3;
msr_t msr; msr_t msr;
msr.lo = msr.hi = 0; /* Shut up gcc */ msr.lo = msr.hi = 0; /* Shut up gcc */
for(i = first; i < last; i++) { for (i = first; i < last; i++) {
/* When I switch to a new msr read it in */ /* When I switch to a new msr read it in */
if (fixed_msr != i >> 3) { if (fixed_msr != i >> 3) {
/* But first write out the old msr */ /* But first write out the old msr */
@ -304,12 +304,12 @@ void setup_mtrrs(struct mem_range *mem)
printk_debug("\n"); printk_debug("\n");
/* Initialized the fixed_mtrrs to uncached */ /* Initialized the fixed_mtrrs to uncached */
printk_debug("Setting fixed MTRRs(%d-%d) type: UC\n", printk_debug("Setting fixed MTRRs(%d-%d) type: UC\n",
0, NUM_FIXED_RANGES); 0, NUM_FIXED_RANGES);
set_fixed_mtrrs(0, NUM_FIXED_RANGES, MTRR_TYPE_UNCACHEABLE); set_fixed_mtrrs(0, NUM_FIXED_RANGES, MTRR_TYPE_UNCACHEABLE);
/* Now see which of the fixed mtrrs cover ram. /* Now see which of the fixed mtrrs cover ram.
*/ */
for(memp = mem; memp->sizek; memp++) { for (memp = mem; memp->sizek; memp++) {
unsigned int start_mtrr; unsigned int start_mtrr;
unsigned int last_mtrr; unsigned int last_mtrr;
start_mtrr = fixed_mtrr_index(memp->basek); start_mtrr = fixed_mtrr_index(memp->basek);
@ -317,11 +317,17 @@ void setup_mtrrs(struct mem_range *mem)
if (start_mtrr >= NUM_FIXED_RANGES) { if (start_mtrr >= NUM_FIXED_RANGES) {
break; break;
} }
#if defined(k7) || defined(k8)
#warning "FIXME: dealing with RdMEM/WrMEM for Athlon/Opteron"
#endif
printk_debug("Setting fixed MTRRs(%d-%d) type: WB\n", printk_debug("Setting fixed MTRRs(%d-%d) type: WB\n",
start_mtrr, last_mtrr); start_mtrr, last_mtrr);
set_fixed_mtrrs(start_mtrr, last_mtrr, MTRR_TYPE_WRBACK); set_fixed_mtrrs(start_mtrr, last_mtrr, MTRR_TYPE_WRBACK);
} }
printk_debug("DONE fixed MTRRs\n"); printk_debug("DONE fixed MTRRs\n");
/* Cache as many memory areas as possible */ /* Cache as many memory areas as possible */
/* FIXME is there an algorithm for computing the optimal set of mtrrs? /* FIXME is there an algorithm for computing the optimal set of mtrrs?
* In some cases it is definitely possible to do better. * In some cases it is definitely possible to do better.

View File

@ -9,8 +9,22 @@
#include <device/chip.h> #include <device/chip.h>
#include <device/pci.h> #include <device/pci.h>
void /**
chip_configure(struct chip *root, enum chip_pass pass) * @brief Configure static devices
*
* Starting from the static device 'root', walk the tree and configure each
* device by calling the device specific chip_control::enable().
*
* This function is only an iterator, the exact definition of 'configure'
* depends on the device specific implementation of chip_control::enable().
*
* @param root root of the static device tree to be configured.
* @param pass pass of the configuration operation to be perfromed.
*
* @see chip_pass
* @see chip_control::enable
*/
void chip_configure(struct chip *root, enum chip_pass pass)
{ {
struct chip *c; struct chip *c;
@ -25,24 +39,37 @@ chip_configure(struct chip *root, enum chip_pass pass)
} }
} }
/** Convert a static struct chip structure to a set of dynamic device structures. /**
* @param chip Static chip structure to start with. * @brief Convert static device structures to dynamic structures.
*
* A static device may contain one or more dynamic devices. Dynamic device
* structures of these devices have to be generated before the enumeration
* of dynamic devices. This function converts a static chip structure to a
* set of dynamic device structures.
*
* This function is the generic method called by enumerate_static_device_chain()
* for static devices. Devices extend this default behavior by defining their
* own chip_controll::enumerate(). Generally, device specific
* chip_control::enumerate() method calls this function as its last operation.
*
* @param chip static chip structure to be converted.
*
*/ */
void chip_enumerate(struct chip *chip) void chip_enumerate(struct chip *chip)
{ {
struct chip *child; struct chip *child;
device_t dev; device_t dev;
int link; int link;
int i; int i;
dev = 0; dev = 0;
link = 0; link = 0;
#if 1
if (chip->control && chip->control->name) { if (chip->control && chip->control->name) {
printk_debug("Enumerating: %s\n", chip->control->name); printk_debug("Enumerating: %s\n", chip->control->name);
} }
#endif
for(i = 0; i < MAX_CHIP_PATHS; i++) { for (i = 0; i < MAX_CHIP_PATHS; i++) {
int identical_paths; int identical_paths;
identical_paths = identical_paths =
(i > 0) && (i > 0) &&
@ -55,6 +82,7 @@ void chip_enumerate(struct chip *chip)
parent = chip->bus; parent = chip->bus;
switch(chip->path[i].path.type) { switch(chip->path[i].path.type) {
case DEVICE_PATH_NONE: case DEVICE_PATH_NONE:
/* no dynamic device associated */
break; break;
case DEVICE_PATH_PCI: case DEVICE_PATH_PCI:
bus = chip->path[i].path.u.pci.bus; bus = chip->path[i].path.u.pci.bus;
@ -62,7 +90,7 @@ void chip_enumerate(struct chip *chip)
device_t dev; device_t dev;
int i = 1; int i = 1;
dev = chip->dev; dev = chip->dev;
while(dev && (i != bus)) { while (dev && (i != bus)) {
dev = dev->next; dev = dev->next;
i++; i++;
} }
@ -75,18 +103,21 @@ void chip_enumerate(struct chip *chip)
dev = alloc_dev(parent, &chip->path[i].path); dev = alloc_dev(parent, &chip->path[i].path);
break; break;
} }
} } else {
else {
link += 1; link += 1;
} }
if (dev) { if (dev) {
struct chip_resource *res, *res_limit; struct chip_resource *res, *res_limit;
printk_spew("path (%p) %s %s", dev, dev_path(dev), identical_paths?"identical":""); printk_spew("path (%p) %s %s",
printk_spew(" parent: (%p) %s\n",dev->bus->dev, dev_path(dev->bus->dev)); dev, dev_path(dev),
identical_paths?"identical":"");
printk_spew(" parent: (%p) %s\n",
dev->bus->dev, dev_path(dev->bus->dev));
dev->chip = chip; dev->chip = chip;
dev->enable = chip->path[i].enable; dev->enable = chip->path[i].enable;
dev->links = link + 1; dev->links = link + 1;
for(child = chip->children; child; child = child->next) { for (child = chip->children; child; child = child->next) {
if (!child->bus && child->link == i) { if (!child->bus && child->link == i) {
child->bus = &dev->link[link]; child->bus = &dev->link[link];
} }
@ -102,21 +133,42 @@ void chip_enumerate(struct chip *chip)
} }
} }
} }
if (dev && !chip->dev) { if (dev && !chip->dev) {
chip->dev = dev; chip->dev = dev;
} }
} }
for(child = chip->children; child; child = child->next) {
for (child = chip->children; child; child = child->next) {
if (!child->bus) { if (!child->bus) {
child->bus = &chip->dev->link[0]; child->bus = &chip->dev->link[0];
} }
} }
} }
/**
* @brief Enumerate a static device tree.
*
* A static device chain is a linked list of static device structures which are
* on the same branch of the static device tree. This function does not only
* enumerate the devices on a single chain, as its name suggest, it also walks
* into the subordinary chains. It calls the device specific
* chip_control::enumerate() of the device if one exists or calls the generic
* chip_enumerate().
*
* This function is only an iterator, the exact definition of 'enumerate'
* depends on the implementation of the generic chip_enumerate() and/or device
* specific chip_control::enumerate().
*
* @param root static chip structure to start with.
*
* @see chip_control::enumerate()
*/
static void enumerate_static_device_chain(struct chip *root) static void enumerate_static_device_chain(struct chip *root)
{ {
struct chip *chip; struct chip *chip;
for(chip = root; chip; chip = chip->next) {
for (chip = root; chip; chip = chip->next) {
void (*enumerate)(struct chip *chip); void (*enumerate)(struct chip *chip);
enumerate = chip_enumerate; enumerate = chip_enumerate;
if (chip->control && chip->control->enumerate) { if (chip->control && chip->control->enumerate) {
@ -125,13 +177,30 @@ static void enumerate_static_device_chain(struct chip *root)
enumerate(chip); enumerate(chip);
} }
for(chip = root; chip; chip = chip->next) { for (chip = root; chip; chip = chip->next) {
if (chip->children) { if (chip->children) {
enumerate_static_device_chain(chip->children); enumerate_static_device_chain(chip->children);
} }
} }
} }
/**
* @brief Enumerate static devices in the system.
*
* \note The definition of 'enumerate' is not clear in this context. Does it mean
* probe ?
*
* \note How do we determine the existence of the static devices ? Static
* devices are listed in the config file and generated at compile time by config
* tool. This function is called at certain point in the early stage of
* LinuxBIOS. It uses the chip_enumerate() function to convert the static
* structures into dynamic ones. What if the static devices listed in the config
* file does actually not exist in the system ? Is there any side effect of
* these 'phantom' device structures
*
* The static device does not necesarry conform to the dynamic device tree in
* the system.
*/
void enumerate_static_devices(void) void enumerate_static_devices(void)
{ {
enumerate_static_device_chain(&static_root); enumerate_static_device_chain(&static_root);

View File

@ -22,24 +22,41 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
/* Linked list of ALL devices */ /** Linked list of ALL devices */
struct device *all_devices = &dev_root; struct device *all_devices = &dev_root;
/* pointer to the last device */ /** Pointer to the last device */
static struct device **last_dev_p = &dev_root.next; static struct device **last_dev_p = &dev_root.next;
#define DEVICE_MEM_HIGH 0xFEC00000UL /* Reserve 20M for the system */ /** The upper limit of MEM resource of the devices.
* Reserve 20M for the system */
#define DEVICE_MEM_HIGH 0xFEC00000UL
/** The lower limit of IO resource of the devices.
* Reserve 4k for ISA/Legacy devices */
#define DEVICE_IO_START 0x1000 #define DEVICE_IO_START 0x1000
/** Allocate a new device structure /**
* @brief Allocate a new device structure.
*
* Allocte a new device structure and attached it to the device tree as a child
* of the parent bus.
*
* @param parent parent bus the newly created device attached to.
* @param path path to the device to be created.
*
* @return pointer to the newly created device structure.
*
* @see device_path
*/ */
device_t alloc_dev(struct bus *parent, struct device_path *path) device_t alloc_dev(struct bus *parent, struct device_path *path)
{ {
device_t dev, child; device_t dev, child;
int link; int link;
/* Find the last child of our parent */ /* Find the last child of our parent */
for(child = parent->children; child && child->sibling; ) { for (child = parent->children; child && child->sibling; ) {
child = child->sibling; child = child->sibling;
} }
dev = malloc(sizeof(*dev)); dev = malloc(sizeof(*dev));
if (dev == 0) { if (dev == 0) {
die("DEV: out of memory.\n"); die("DEV: out of memory.\n");
@ -47,14 +64,14 @@ device_t alloc_dev(struct bus *parent, struct device_path *path)
memset(dev, 0, sizeof(*dev)); memset(dev, 0, sizeof(*dev));
memcpy(&dev->path, path, sizeof(*path)); memcpy(&dev->path, path, sizeof(*path));
/* Append a new device to the global device chain. /* Append a new device to the global device list.
* The chain is used to find devices once everything is set up. * The list is used to find devices once everything is set up.
*/ */
*last_dev_p = dev; *last_dev_p = dev;
last_dev_p = &dev->next; last_dev_p = &dev->next;
/* Initialize the back pointers in the link fields */ /* Initialize the back pointers in the link fields */
for(link = 0; link < MAX_LINKS; link++) { for (link = 0; link < MAX_LINKS; link++) {
dev->link[link].dev = dev; dev->link[link].dev = dev;
dev->link[link].link = link; dev->link[link].link = link;
} }
@ -66,12 +83,15 @@ device_t alloc_dev(struct bus *parent, struct device_path *path)
} else { } else {
parent->children = dev; parent->children = dev;
} }
/* If we don't have any other information about a device enable it */ /* If we don't have any other information about a device enable it */
dev->enable = 1; dev->enable = 1;
return dev; return dev;
} }
/** round a number to an alignment. /**
* @brief round a number up to an alignment.
* @param val the starting value * @param val the starting value
* @param roundup Alignment as a power of two * @param roundup Alignment as a power of two
* @returns rounded up number * @returns rounded up number
@ -104,7 +124,7 @@ static void read_resources(struct bus *bus)
struct device *curdev; struct device *curdev;
/* Walk through all of the devices and find which resources they need. */ /* Walk through all of the devices and find which resources they need. */
for(curdev = bus->children; curdev; curdev = curdev->sibling) { for (curdev = bus->children; curdev; curdev = curdev->sibling) {
unsigned links; unsigned links;
int i; int i;
if (curdev->resources > 0) { if (curdev->resources > 0) {
@ -112,20 +132,22 @@ static void read_resources(struct bus *bus)
} }
if (!curdev->ops || !curdev->ops->read_resources) { if (!curdev->ops || !curdev->ops->read_resources) {
printk_err("%s missing read_resources\n", printk_err("%s missing read_resources\n",
dev_path(curdev)); dev_path(curdev));
continue; continue;
} }
if (!curdev->enable) { if (!curdev->enable) {
continue; continue;
} }
curdev->ops->read_resources(curdev); curdev->ops->read_resources(curdev);
/* Read in subtractive resources behind the current device */ /* Read in subtractive resources behind the current device */
links = 0; links = 0;
for(i = 0; i < curdev->resources; i++) { for (i = 0; i < curdev->resources; i++) {
struct resource *resource; struct resource *resource;
resource = &curdev->resource[i]; resource = &curdev->resource[i];
if ((resource->flags & IORESOURCE_SUBTRACTIVE) && if ((resource->flags & IORESOURCE_SUBTRACTIVE) &&
(!(links & (1 << resource->index)))) (!(links & (1 << resource->index))))
{ {
links |= (1 << resource->index); links |= (1 << resource->index);
read_resources(&curdev->link[resource->index]); read_resources(&curdev->link[resource->index]);
@ -142,8 +164,8 @@ struct pick_largest_state {
int seen_last; int seen_last;
}; };
static void pick_largest_resource( static void pick_largest_resource(struct pick_largest_state *state,
struct pick_largest_state *state, struct device *dev, struct resource *resource) struct device *dev, struct resource *resource)
{ {
struct resource *last; struct resource *last;
last = state->last; last = state->last;
@ -152,32 +174,33 @@ static void pick_largest_resource(
state->seen_last = 1; state->seen_last = 1;
return; return;
} }
if (last && ( if (last &&
(last->align < resource->align) || ((last->align < resource->align) ||
((last->align == resource->align) && ((last->align == resource->align) &&
(last->size < resource->size)) || (last->size < resource->size)) ||
((last->align == resource->align) && ((last->align == resource->align) &&
(last->size == resource->size) && (last->size == resource->size) &&
(!state->seen_last)))) { (!state->seen_last)))) {
return; return;
} }
if (!state->result || if (!state->result ||
(state->result->align < resource->align) || (state->result->align < resource->align) ||
((state->result->align == resource->align) && ((state->result->align == resource->align) &&
(state->result->size < resource->size))) { (state->result->size < resource->size))) {
state->result_dev = dev; state->result_dev = dev;
state->result = resource; state->result = resource;
} }
} }
static void find_largest_resource(struct pick_largest_state *state, static void find_largest_resource(struct pick_largest_state *state,
struct bus *bus, unsigned long type_mask, unsigned long type) struct bus *bus, unsigned long type_mask,
unsigned long type)
{ {
struct device *curdev; struct device *curdev;
for(curdev = bus->children; curdev; curdev = curdev->sibling) {
for (curdev = bus->children; curdev; curdev = curdev->sibling) {
int i; int i;
for(i = 0; i < curdev->resources; i++) { for (i = 0; i < curdev->resources; i++) {
struct resource *resource = &curdev->resource[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) { if ((resource->flags & type_mask) != type) {
@ -187,7 +210,8 @@ static void find_largest_resource(struct pick_largest_state *state,
if (resource->flags & IORESOURCE_SUBTRACTIVE) { if (resource->flags & IORESOURCE_SUBTRACTIVE) {
struct bus *subbus; struct bus *subbus;
subbus = &curdev->link[resource->index]; subbus = &curdev->link[resource->index];
find_largest_resource(state, subbus, type_mask, type); find_largest_resource(state, subbus,
type_mask, type);
continue; continue;
} }
/* See if this is the largest resource */ /* See if this is the largest resource */
@ -196,8 +220,10 @@ static void find_largest_resource(struct pick_largest_state *state,
} }
} }
static struct device *largest_resource(struct bus *bus, struct resource **result_res, static struct device *largest_resource(struct bus *bus,
unsigned long type_mask, unsigned long type) struct resource **result_res,
unsigned long type_mask,
unsigned long type)
{ {
struct pick_largest_state state; struct pick_largest_state state;
@ -254,12 +280,12 @@ void compute_allocate_resource(
min_align = 0; min_align = 0;
base = bridge->base; base = bridge->base;
printk_spew("%s compute_allocate_%s: base: %08lx size: %08lx align: %d gran: %d\n", printk_spew("%s compute_allocate_%s: base: %08lx size: %08lx "
dev_path(bus->dev), "align: %d gran: %d\n",
(bridge->flags & IORESOURCE_IO)? "io": dev_path(bus->dev),
(bridge->flags & IORESOURCE_PREFETCH)? "prefmem" : "mem", (bridge->flags & IORESOURCE_IO)? "io":
base, bridge->size, bridge->align, bridge->gran); (bridge->flags & IORESOURCE_PREFETCH)? "prefmem" : "mem",
base, bridge->size, bridge->align, bridge->gran);
/* We want different minimum alignments for different kinds of /* We want different minimum alignments for different kinds of
* resources. These minimums are not device type specific * resources. These minimums are not device type specific
@ -278,8 +304,9 @@ void compute_allocate_resource(
/* Remember I haven't found anything yet. */ /* Remember I haven't found anything yet. */
resource = 0; resource = 0;
/* Walk through all the devices on the current bus and compute the addresses */ /* Walk through all the devices on the current bus and compute the
while((dev = largest_resource(bus, &resource, type_mask, type))) { * addresses */
while ((dev = largest_resource(bus, &resource, type_mask, type))) {
unsigned long size; unsigned long size;
/* Do NOT I repeat do not ignore resources which have zero size. /* Do NOT I repeat do not ignore resources which have zero size.
* If they need to be ignored dev->read_resources should not even * If they need to be ignored dev->read_resources should not even
@ -357,6 +384,8 @@ void compute_allocate_resource(
static void allocate_vga_resource(void) static void allocate_vga_resource(void)
{ {
#warning "FIXME modify allocate_vga_resource so it is less pci centric!" #warning "FIXME modify allocate_vga_resource so it is less pci centric!"
#warning "This function knows to much about PCI stuff, it should be just a ietrator/visitor."
/* FIXME handle the VGA pallette snooping */ /* FIXME handle the VGA pallette snooping */
struct device *dev, *vga; struct device *dev, *vga;
struct bus *bus; struct bus *bus;
@ -422,7 +451,7 @@ void enable_resources(struct device *dev)
*/ */
if (!dev->ops || !dev->ops->enable_resources) { if (!dev->ops || !dev->ops->enable_resources) {
printk_err("%s missing enable_resources\n", printk_err("%s missing enable_resources\n",
dev_path(dev)); dev_path(dev));
return; return;
} }
if (!dev->enable) { if (!dev->enable) {
@ -431,58 +460,74 @@ void enable_resources(struct device *dev)
dev->ops->enable_resources(dev); dev->ops->enable_resources(dev);
} }
/** Enumerate the resources on the PCI by calling pci_init /**
* @brief Determine the existence of dynamic devices and construct dynamic
* device tree.
*
* Start for the root device 'dev_root', scan the buses in the system, build
* the dynamic device tree according to the result of the probe.
*
* This function have no idea how to scan and probe the buses and devices at
* all. It depends on the bus/device specific scan_bus() method to do it.
* The scan_bus() function also have to create the device structure and attach
* it to the device tree.
*/ */
void dev_enumerate(void) void dev_enumerate(void)
{ {
struct device *root; struct device *root;
unsigned subordinate; unsigned subordinate;
printk_info("Enumerating buses...");
printk_info("Enumerating buses...\n");
root = &dev_root; root = &dev_root;
subordinate = root->ops->scan_bus(root, 0); subordinate = root->ops->scan_bus(root, 0);
printk_info("done\n"); printk_info("done\n");
} }
/** Starting at the root, compute what resources are needed and allocate them. /**
* @brief Configure devices on the devices tree.
*
* Starting at the root, compute what resources are needed and allocate them.
* I/O starts at PCI_IO_START. Since the assignment is hierarchical we * I/O starts at PCI_IO_START. Since the assignment is hierarchical we
* set the values into the dev_root struct. * set the values into the dev_root struct.
*/ */
void dev_configure(void) void dev_configure(void)
{ {
struct device *root = &dev_root; struct device *root = &dev_root;
printk_info("Allocating resources..."); printk_info("Allocating resources...");
printk_debug("\n"); printk_debug("\n");
root->ops->read_resources(root); root->ops->read_resources(root);
/* Make certain the io devices are allocated somewhere /* Make certain the io devices are allocated somewhere safe. */
* safe.
*/
root->resource[0].base = DEVICE_IO_START; root->resource[0].base = DEVICE_IO_START;
root->resource[0].flags |= IORESOURCE_ASSIGNED; root->resource[0].flags |= IORESOURCE_ASSIGNED;
root->resource[0].flags &= ~IORESOURCE_STORED; root->resource[0].flags &= ~IORESOURCE_STORED;
/* Now reallocate the pci resources memory with the
* highest addresses I can manage. /* Now reallocate the pci resources memory with the highest
*/ * addresses I can manage.*/
root->resource[1].base = root->resource[1].base =
round_down(DEVICE_MEM_HIGH - root->resource[1].size, round_down(DEVICE_MEM_HIGH - root->resource[1].size,
1UL << root->resource[1].align); 1UL << root->resource[1].align);
root->resource[1].flags |= IORESOURCE_ASSIGNED; root->resource[1].flags |= IORESOURCE_ASSIGNED;
root->resource[1].flags &= ~IORESOURCE_STORED; root->resource[1].flags &= ~IORESOURCE_STORED;
/* Allocate the VGA I/O resource.. /* Allocate the VGA I/O resource.. */
*/
allocate_vga_resource(); allocate_vga_resource();
// now just set things into registers ... we hope ... /* now just set things into registers ... we hope ... */
root->ops->set_resources(root); root->ops->set_resources(root);
printk_info("done.\n"); printk_info("done.\n");
} }
/** Starting at the root, walk the tree and enable all devices/bridges. /**
* What really happens is computed COMMAND bits get set in register 4 * @brief Enable devices on the device tree.
*
* Starting at the root, walk the tree and enable all devices/bridges by
* calling the device's enable_resources() method.
*/ */
void dev_enable(void) void dev_enable(void)
{ {
@ -490,22 +535,28 @@ void dev_enable(void)
/* now enable everything. */ /* now enable everything. */
enable_resources(&dev_root); enable_resources(&dev_root);
printk_info("done.\n"); printk_info("done.\n");
} }
/** Starting at the root, walk the tree and call a driver to /**
* do device specific setup. * @brief Initialize all devices in the global device list.
*
* Starting at the first device on the global device link list,
* walk the list and call a driver to do device specific setup.
*/ */
void dev_initialize(void) void dev_initialize(void)
{ {
struct device *dev; struct device *dev;
printk_info("Initializing devices...\n"); printk_info("Initializing devices...\n");
for (dev = all_devices; dev; dev = dev->next) { for (dev = all_devices; dev; dev = dev->next) {
if (dev->enable && dev->ops && dev->ops->init) { if (dev->enable && dev->ops && dev->ops->init) {
printk_debug("%s init\n", dev_path(dev)); printk_debug("%s init\n", dev_path(dev));
dev->ops->init(dev); dev->ops->init(dev);
} }
} }
printk_info("Devices initialized\n"); printk_info("Devices initialized\n");
} }

View File

@ -6,15 +6,16 @@
/** /**
* See if a device structure already exists and if not allocate it * @brief See if a device structure already exists and if not allocate it
*
* @param bus The bus to find the device on * @param bus The bus to find the device on
* @param path The relative path from the bus to the appropriate device * @param path The relative path from the bus to the appropriate device
* @return pointer a device structure for the device on bus at path * @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) device_t alloc_find_dev(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)) {
return child; return child;
} }

View File

@ -151,7 +151,7 @@ static void pci_read_bases(struct device *dev, unsigned int howmany)
{ {
unsigned long index; unsigned long index;
for(index = PCI_BASE_ADDRESS_0; (index < PCI_BASE_ADDRESS_0 + (howmany << 2)); ) { for (index = PCI_BASE_ADDRESS_0; (index < PCI_BASE_ADDRESS_0 + (howmany << 2)); ) {
struct resource *resource; struct resource *resource;
resource = pci_get_resource(dev, index); resource = pci_get_resource(dev, index);
index += (resource->flags & IORESOURCE_PCI64)?8:4; index += (resource->flags & IORESOURCE_PCI64)?8:4;
@ -159,7 +159,6 @@ static void pci_read_bases(struct device *dev, unsigned int howmany)
compact_resources(dev); compact_resources(dev);
} }
static void pci_bridge_read_bases(struct device *dev) static void pci_bridge_read_bases(struct device *dev)
{ {
struct resource *resource; struct resource *resource;
@ -174,7 +173,7 @@ static void pci_bridge_read_bases(struct device *dev)
resource->limit = 0xffffUL; resource->limit = 0xffffUL;
resource->flags |= IORESOURCE_IO | IORESOURCE_PCI_BRIDGE; resource->flags |= IORESOURCE_IO | IORESOURCE_PCI_BRIDGE;
compute_allocate_resource(&dev->link[0], resource, compute_allocate_resource(&dev->link[0], resource,
IORESOURCE_IO, IORESOURCE_IO); IORESOURCE_IO, IORESOURCE_IO);
/* Initiliaze the prefetchable memory constraints on the current bus */ /* Initiliaze the prefetchable memory constraints on the current bus */
resource = get_resource(dev, PCI_PREF_MEMORY_BASE); resource = get_resource(dev, PCI_PREF_MEMORY_BASE);
@ -185,8 +184,8 @@ static void pci_bridge_read_bases(struct device *dev)
resource->flags = IORESOURCE_MEM | IORESOURCE_PREFETCH | IORESOURCE_PCI_BRIDGE; resource->flags = IORESOURCE_MEM | IORESOURCE_PREFETCH | IORESOURCE_PCI_BRIDGE;
resource->index = PCI_PREF_MEMORY_BASE; resource->index = PCI_PREF_MEMORY_BASE;
compute_allocate_resource(&dev->link[0], resource, compute_allocate_resource(&dev->link[0], resource,
IORESOURCE_MEM | IORESOURCE_PREFETCH, IORESOURCE_MEM | IORESOURCE_PREFETCH,
IORESOURCE_MEM | IORESOURCE_PREFETCH); IORESOURCE_MEM | IORESOURCE_PREFETCH);
/* Initialize the memory resources on the current bus */ /* Initialize the memory resources on the current bus */
resource = get_resource(dev, PCI_MEMORY_BASE); resource = get_resource(dev, PCI_MEMORY_BASE);
@ -196,17 +195,18 @@ static void pci_bridge_read_bases(struct device *dev)
resource->limit = 0xffffffffUL; resource->limit = 0xffffffffUL;
resource->flags = IORESOURCE_MEM | IORESOURCE_PCI_BRIDGE; resource->flags = IORESOURCE_MEM | IORESOURCE_PCI_BRIDGE;
compute_allocate_resource(&dev->link[0], resource, compute_allocate_resource(&dev->link[0], resource,
IORESOURCE_MEM | IORESOURCE_PREFETCH, IORESOURCE_MEM | IORESOURCE_PREFETCH,
IORESOURCE_MEM); IORESOURCE_MEM);
compact_resources(dev); compact_resources(dev);
} }
void pci_dev_read_resources(struct device *dev) void pci_dev_read_resources(struct device *dev)
{ {
uint32_t addr; uint32_t addr;
pci_read_bases(dev, 6); pci_read_bases(dev, 6);
addr = pci_read_config32(dev, PCI_ROM_ADDRESS); addr = pci_read_config32(dev, PCI_ROM_ADDRESS);
dev->rom_address = (addr == 0xffffffff)? 0 : addr; dev->rom_address = (addr == 0xffffffff)? 0 : addr;
} }
@ -214,14 +214,29 @@ void pci_dev_read_resources(struct device *dev)
void pci_bus_read_resources(struct device *dev) 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);
addr = pci_read_config32(dev, PCI_ROM_ADDRESS1); addr = pci_read_config32(dev, PCI_ROM_ADDRESS1);
dev->rom_address = (addr == 0xffffffff)? 0 : addr; dev->rom_address = (addr == 0xffffffff)? 0 : addr;
} }
/**
* @brief round a number up to an alignment.
* @param val the starting value
* @param roundup Alignment as a power of two
* @returns rounded up number
*/
static unsigned long round(unsigned long val, unsigned long roundup)
{
/* ROUNDUP MUST BE A POWER OF TWO. */
unsigned long inverse;
inverse = ~(roundup - 1);
val += (roundup - 1);
val &= inverse;
return val;
}
static void pci_set_resource(struct device *dev, struct resource *resource) static void pci_set_resource(struct device *dev, struct resource *resource)
{ {
@ -230,11 +245,10 @@ static void pci_set_resource(struct device *dev, struct resource *resource)
unsigned long gran; unsigned long gran;
/* Make certain the resource has actually been set */ /* Make certain the resource has actually been set */
if (!(resource->flags & IORESOURCE_ASSIGNED)) { if (!(resource->flags & IORESOURCE_ASSIGNED)) {
#if 1
printk_err("ERROR: %s %02x not allocated\n", printk_err("ERROR: %s %02x not allocated\n",
dev_path(dev), resource->index); dev_path(dev), resource->index);
#endif
return; return;
} }
@ -256,8 +270,10 @@ static void pci_set_resource(struct device *dev, struct resource *resource)
if (resource->flags & IORESOURCE_PCI_BRIDGE) { if (resource->flags & IORESOURCE_PCI_BRIDGE) {
dev->command |= PCI_COMMAND_MASTER; dev->command |= PCI_COMMAND_MASTER;
} }
/* Get the base address */ /* Get the base address */
base = resource->base; base = resource->base;
/* Get the resource granularity */ /* Get the resource granularity */
gran = 1UL << resource->gran; gran = 1UL << resource->gran;
@ -268,15 +284,13 @@ static void pci_set_resource(struct device *dev, struct resource *resource)
*/ */
/* Get the limit (rounded up) */ /* Get the limit (rounded up) */
limit = base + ((resource->size + gran - 1UL) & ~(gran - 1UL)) -1UL; limit = base + round(resource->size, gran) - 1UL;
/* Now store the resource */ /* Now store the resource */
resource->flags |= IORESOURCE_STORED; resource->flags |= IORESOURCE_STORED;
if (!(resource->flags & IORESOURCE_PCI_BRIDGE)) { if (!(resource->flags & IORESOURCE_PCI_BRIDGE)) {
/* /* some chipsets allow us to set/clear the IO bit.
* some chipsets allow us to set/clear the IO bit. * (e.g. VIA 82c686a.) So set it to be safe) */
* (e.g. VIA 82c686a.) So set it to be safe)
*/
limit = base + resource->size -1; limit = base + resource->size -1;
if (resource->flags & IORESOURCE_IO) { if (resource->flags & IORESOURCE_IO) {
base |= PCI_BASE_ADDRESS_SPACE_IO; base |= PCI_BASE_ADDRESS_SPACE_IO;
@ -286,58 +300,50 @@ static void pci_set_resource(struct device *dev, struct resource *resource)
/* FIXME handle real 64bit base addresses */ /* FIXME handle real 64bit base addresses */
pci_write_config32(dev, resource->index + 4, 0); pci_write_config32(dev, resource->index + 4, 0);
} }
} } else if (resource->index == PCI_IO_BASE) {
else if (resource->index == PCI_IO_BASE) {
/* set the IO ranges /* set the IO ranges
* WARNING: we don't really do 32-bit addressing for IO yet! * WARNING: we don't really do 32-bit addressing for IO yet!
*/ */
compute_allocate_resource(&dev->link[0], resource, compute_allocate_resource(&dev->link[0], resource,
IORESOURCE_IO, IORESOURCE_IO); IORESOURCE_IO, IORESOURCE_IO);
pci_write_config8(dev, PCI_IO_BASE, base >> 8); pci_write_config8(dev, PCI_IO_BASE, base >> 8);
pci_write_config8(dev, PCI_IO_LIMIT, limit >> 8); pci_write_config8(dev, PCI_IO_LIMIT, limit >> 8);
pci_write_config16(dev, PCI_IO_BASE_UPPER16, 0); pci_write_config16(dev, PCI_IO_BASE_UPPER16, 0);
pci_write_config16(dev, PCI_IO_LIMIT_UPPER16, 0); pci_write_config16(dev, PCI_IO_LIMIT_UPPER16, 0);
} } else if (resource->index == PCI_MEMORY_BASE) {
else if (resource->index == PCI_MEMORY_BASE) { /* set the memory range */
/* set the memory range
*/
compute_allocate_resource(&dev->link[0], resource, compute_allocate_resource(&dev->link[0], resource,
IORESOURCE_MEM | IORESOURCE_PREFETCH, IORESOURCE_MEM | IORESOURCE_PREFETCH,
IORESOURCE_MEM); IORESOURCE_MEM);
pci_write_config16(dev, PCI_MEMORY_BASE, base >> 16); pci_write_config16(dev, PCI_MEMORY_BASE, base >> 16);
pci_write_config16(dev, PCI_MEMORY_LIMIT, limit >> 16); pci_write_config16(dev, PCI_MEMORY_LIMIT, limit >> 16);
} } else if (resource->index == PCI_PREF_MEMORY_BASE) {
else if (resource->index == PCI_PREF_MEMORY_BASE) {
/* set the prefetchable memory range /* set the prefetchable memory range
* WARNING: we don't really do 64-bit addressing for prefetchable memory yet! * WARNING: we don't really do 64-bit addressing for
*/ * prefetchable memory yet! */
compute_allocate_resource(&dev->link[0], resource, compute_allocate_resource(&dev->link[0], resource,
IORESOURCE_MEM | IORESOURCE_PREFETCH, IORESOURCE_MEM | IORESOURCE_PREFETCH,
IORESOURCE_MEM | IORESOURCE_PREFETCH); IORESOURCE_MEM | IORESOURCE_PREFETCH);
pci_write_config16(dev, PCI_PREF_MEMORY_BASE, base >> 16); pci_write_config16(dev, PCI_PREF_MEMORY_BASE, base >> 16);
pci_write_config16(dev, PCI_PREF_MEMORY_LIMIT, limit >> 16); pci_write_config16(dev, PCI_PREF_MEMORY_LIMIT, limit >> 16);
pci_write_config32(dev, PCI_PREF_BASE_UPPER32, 0); pci_write_config32(dev, PCI_PREF_BASE_UPPER32, 0);
pci_write_config32(dev, PCI_PREF_LIMIT_UPPER32, 0); pci_write_config32(dev, PCI_PREF_LIMIT_UPPER32, 0);
} } else {
else {
/* Don't let me think I stored the resource */ /* Don't let me think I stored the resource */
resource->flags &= ~IORESOURCE_STORED; resource->flags &= ~IORESOURCE_STORED;
printk_err("ERROR: invalid resource->index %x\n", printk_err("ERROR: invalid resource->index %x\n",
resource->index); resource->index);
} }
buf[0] = '\0'; buf[0] = '\0';
if (resource->flags & IORESOURCE_PCI_BRIDGE) { if (resource->flags & IORESOURCE_PCI_BRIDGE) {
sprintf(buf, "bus %d ", dev->link[0].secondary); sprintf(buf, "bus %d ", dev->link[0].secondary);
} }
printk_debug("%s %02x <- [0x%08lx - 0x%08lx] %s%s\n",
printk_debug( dev_path(dev), resource->index, resource->base,
"%s %02x <- [0x%08lx - 0x%08lx] %s%s\n", limit, buf,
dev_path(dev), (resource->flags & IORESOURCE_IO)? "io":
resource->index, (resource->flags & IORESOURCE_PREFETCH)? "prefmem": "mem");
resource->base, limit,
buf,
(resource->flags & IORESOURCE_IO)? "io":
(resource->flags & IORESOURCE_PREFETCH)? "prefmem": "mem");
return; return;
} }
@ -348,11 +354,11 @@ void pci_dev_set_resources(struct device *dev)
uint8_t line; uint8_t line;
last = &dev->resource[dev->resources]; last = &dev->resource[dev->resources];
for (resource = &dev->resource[0]; resource < last; resource++) {
for(resource = &dev->resource[0]; resource < last; resource++) {
pci_set_resource(dev, resource); pci_set_resource(dev, resource);
} }
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) {
@ -401,43 +407,55 @@ void pci_bus_enable_resources(struct device *dev)
pci_dev_enable_resources(dev); pci_dev_enable_resources(dev);
} }
/** Default device operation for PCI devices */
struct device_operations default_pci_ops_dev = { struct device_operations default_pci_ops_dev = {
.read_resources = pci_dev_read_resources, .read_resources = pci_dev_read_resources,
.set_resources = pci_dev_set_resources, .set_resources = pci_dev_set_resources,
.enable_resources = pci_dev_enable_resources, .enable_resources = pci_dev_enable_resources,
.init = 0, .init = 0,
.scan_bus = 0, .scan_bus = 0,
}; };
/** Default device operations for PCI bridges */
struct device_operations default_pci_ops_bus = { struct device_operations default_pci_ops_bus = {
.read_resources = pci_bus_read_resources, .read_resources = pci_bus_read_resources,
.set_resources = pci_dev_set_resources, .set_resources = pci_dev_set_resources,
.enable_resources = pci_bus_enable_resources, .enable_resources = pci_bus_enable_resources,
.init = 0, .init = 0,
.scan_bus = pci_scan_bridge, .scan_bus = pci_scan_bridge,
}; };
/**
* @brief Set up PCI device operation
*
*
* @param dev
*
* @see pci_drivers
*/
static void set_pci_ops(struct device *dev) static void set_pci_ops(struct device *dev)
{ {
struct pci_driver *driver; struct pci_driver *driver;
if (dev->ops) { if (dev->ops) {
return; return;
} }
/* Look through the list of setup drivers and find one for /* Look through the list of setup drivers and find one for
* this pci device * this pci device */
*/ for (driver = &pci_drivers[0]; driver != &epci_drivers[0]; driver++) {
for(driver = &pci_drivers[0]; driver != &epci_drivers[0]; driver++) {
if ((driver->vendor == dev->vendor) && if ((driver->vendor == dev->vendor) &&
(driver->device == dev->device)) { (driver->device == dev->device)) {
dev->ops = driver->ops; dev->ops = driver->ops;
#if 1
printk_debug("%s [%04x/%04x] %sops\n", printk_debug("%s [%04x/%04x] %sops\n", dev_path(dev),
dev_path(dev), driver->vendor, driver->device,
driver->vendor, driver->device, (driver->ops->scan_bus?"bus ":""));
(driver->ops->scan_bus?"bus ":"")
);
#endif
return; return;
} }
} }
/* If I don't have a specific driver use the default operations */ /* If I don't have a specific driver use the default operations */
switch(dev->hdr_type & 0x7f) { /* header type */ switch(dev->hdr_type & 0x7f) { /* header type */
case PCI_HEADER_TYPE_NORMAL: /* standard header */ case PCI_HEADER_TYPE_NORMAL: /* standard header */
@ -454,27 +472,35 @@ static void set_pci_ops(struct device *dev)
bad: bad:
if (dev->enable) { if (dev->enable) {
printk_err("%s [%04x/%04x/%06x] has unknown header " printk_err("%s [%04x/%04x/%06x] has unknown header "
"type %02x, ignoring.\n", "type %02x, ignoring.\n",
dev_path(dev), dev_path(dev),
dev->vendor, dev->device, dev->vendor, dev->device,
dev->class >> 8, dev->hdr_type); dev->class >> 8, dev->hdr_type);
} }
} }
return; return;
} }
/** /**
* Given a bus and a devfn number, find the device structure * @brief Find a specific device structure on a list of device structures
* @param bus The bus structure *
* Given a linked list of PCI device structures and a devfn number, find the
* device structure correspond to the devfn.
*
* @param list the device structure list
* @param devfn a device/function number * @param devfn a device/function number
* @return pointer to the device structure *
* @return pointer to the device structure found
*/ */
static struct device *pci_scan_get_dev(struct device **list, unsigned int devfn) static struct device *pci_scan_get_dev(struct device **list,
unsigned int devfn)
{ {
struct device *dev = 0; struct device *dev = 0;
for(; *list; list = &(*list)->sibling) {
for (; *list; list = &(*list)->sibling) {
if ((*list)->path.type != DEVICE_PATH_PCI) { if ((*list)->path.type != DEVICE_PATH_PCI) {
printk_err("child %s not a pci device\n", dev_path(*list)); printk_err("child %s not a pci device\n",
dev_path(*list));
continue; continue;
} }
if ((*list)->path.u.pci.devfn == devfn) { if ((*list)->path.u.pci.devfn == devfn) {
@ -485,10 +511,13 @@ static struct device *pci_scan_get_dev(struct device **list, unsigned int devfn)
break; break;
} }
} }
/* FIXME: why are we doing this ? Isn't there some order between the
* structures before ? */
if (dev) { if (dev) {
device_t child; device_t child;
/* Find the last child of our parent */ /* Find the last child of our parent */
for(child = dev->bus->children; child && child->sibling; ) { for (child = dev->bus->children; child && child->sibling; ) {
child = child->sibling; child = child->sibling;
} }
/* Place the device on the list of children of it's parent. */ /* Place the device on the list of children of it's parent. */
@ -502,16 +531,24 @@ static struct device *pci_scan_get_dev(struct device **list, unsigned int devfn)
return dev; return dev;
} }
/** Scan the pci bus devices and bridges. /**
* @brief Scan a PCI bus
*
* Determine the existence of devices and bridges on a PCI bus. If there are
* bridges on the bus, recursively scan the buses behind the bridges.
*
* This function is the default scan_bus() method for the root device
* 'dev_root'.
*
* @param bus pointer to the bus structure * @param bus pointer to the bus structure
* @param min_devfn minimum devfn to look at in the scan usually 0x00 * @param min_devfn minimum devfn to look at in the scan usually 0x00
* @param max_devfn maximum devfn to look at in the scan usually 0xff * @param max_devfn maximum devfn to look at in the scan usually 0xff
* @param max current bus number * @param max current bus number
*
* @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 min_devfn, unsigned max_devfn, unsigned max_devfn, unsigned int max)
unsigned int max)
{ {
unsigned int devfn; unsigned int devfn;
device_t dev; device_t dev;
@ -524,42 +561,50 @@ unsigned int pci_scan_bus(struct bus *bus,
bus->children = 0; bus->children = 0;
post_code(0x24); post_code(0x24);
/* probe all devices on this bus with some optimization for non-existance and /* probe all devices on this bus with some optimization for
single funcion devices */ * non-existence and single funcion devices */
for (devfn = min_devfn; devfn <= max_devfn; devfn++) { for (devfn = min_devfn; devfn <= max_devfn; devfn++) {
uint32_t id, class; uint32_t id, class;
uint8_t hdr_type; uint8_t hdr_type;
/* First thing setup the device structure */ /* device structures for PCI devices associated with static
* devices are already created during the static device
* enumeration, find out if it is the case for this devfn */
dev = pci_scan_get_dev(&old_devices, devfn); dev = pci_scan_get_dev(&old_devices, devfn);
/* Detect if a device is present */
if (!dev) { if (!dev) {
/* it's not associated with a static device, detect if
* this device is present */
struct device dummy; struct device dummy;
dummy.bus = bus; dummy.bus = bus;
dummy.path.type = DEVICE_PATH_PCI; dummy.path.type = DEVICE_PATH_PCI;
dummy.path.u.pci.devfn = devfn; dummy.path.u.pci.devfn = devfn;
id = pci_read_config32(&dummy, PCI_VENDOR_ID); id = pci_read_config32(&dummy, PCI_VENDOR_ID);
/* some broken boards return 0 if a slot is empty: */ /* some broken boards return 0 if a slot is empty: */
if ( (id == 0xffffffff) || (id == 0x00000000) || if ((id == 0xffffffff) || (id == 0x00000000) ||
(id == 0x0000ffff) || (id == 0xffff0000)) (id == 0x0000ffff) || (id == 0xffff0000)) {
{ printk_spew("PCI: devfn 0x%x, bad id 0x%x\n",
printk_spew("PCI: devfn 0x%x, bad id 0x%x\n", devfn, id); devfn, id);
if (PCI_FUNC(devfn) == 0x00) { if (PCI_FUNC(devfn) == 0x00) {
/* if this is a function 0 device and it is not present, /* if this is a function 0 device and
skip to next device */ * it is not present, skip to next
* device */
devfn += 0x07; devfn += 0x07;
} }
/* multi function device, skip to next function */ /* this function in a multi function device is
* not present, skip to next function */
continue; continue;
} }
dev = alloc_dev(bus, &dummy.path); dev = alloc_dev(bus, &dummy.path);
} } else {
else { /* Run the magic enable/disable sequence for the
/* Run the magic enable sequence for the device */ * device */
if (dev->chip && dev->chip->control && dev->chip->control->enable_dev) { /* FIXME: What happen if this PCI device listed as
* static device but does not exist ? This calls
* some arbitray code without any justification */
if (dev->chip && dev->chip->control &&
dev->chip->control->enable_dev) {
int enable = dev->enable; int enable = dev->enable;
dev->enable = 1; dev->enable = 1;
dev->chip->control->enable_dev(dev); dev->chip->control->enable_dev(dev);
@ -580,14 +625,15 @@ unsigned int pci_scan_bus(struct bus *bus,
dev->class = class >> 8; dev->class = class >> 8;
/* Look at the vendor and device id, or at least the /* Look at the vendor and device id, or at least the
* header type and class and figure out which set of configuration * header type and class and figure out which set of
* methods to use. Unless we already have some pci ops. * configuration methods to use. Unless we already
* have some pci ops.
*/ */
set_pci_ops(dev); set_pci_ops(dev);
/* Error if we don't have some pci operations for it */ /* Error if we don't have some pci operations for it */
if (!dev->ops) { if (!dev->ops) {
printk_err("%s No device operations\n", printk_err("%s No device operations\n",
dev_path(dev)); dev_path(dev));
continue; continue;
} }
@ -600,24 +646,28 @@ unsigned int pci_scan_bus(struct bus *bus,
} }
printk_debug("%s [%04x/%04x] %s\n", printk_debug("%s [%04x/%04x] %s\n",
dev_path(dev), dev_path(dev),
dev->vendor, dev->device, dev->vendor, dev->device,
dev->enable?"enabled": "disabled"); dev->enable?"enabled": "disabled");
if (PCI_FUNC(devfn) == 0x00 && (hdr_type & 0x80) != 0x80) { if (PCI_FUNC(devfn) == 0x00 && (hdr_type & 0x80) != 0x80) {
/* if this is not a multi function device, don't waste time probe /* if this is not a multi function device, don't
another function. Skip to next device. */ * waste time probe another function.
* Skip to next device. */
devfn += 0x07; devfn += 0x07;
} }
} }
post_code(0x25); post_code(0x25);
for(child = bus->children; child; child = child->sibling) { /* if the child provides scan_bus(), for example a bridge, scan the
* bus behind that child */
for (child = bus->children; child; child = child->sibling) {
if (!child->ops->scan_bus) { if (!child->ops->scan_bus) {
continue; continue;
} }
max = child->ops->scan_bus(child, max); max = child->ops->scan_bus(child, max);
} }
/* /*
* We've scanned the bus and so we know all about what's on * We've scanned the bus and so we know all about what's on
* the other side of any bridges that may be on this bus plus * the other side of any bridges that may be on this bus plus
@ -630,8 +680,17 @@ unsigned int pci_scan_bus(struct bus *bus,
return max; return max;
} }
/** Scan the bus, first for bridges and next for devices. /**
* @param pci_bus pointer to the bus structure * @brief 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
*
* @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_bridge(struct device *dev, unsigned int max) unsigned int pci_scan_bridge(struct device *dev, unsigned int max)
@ -645,47 +704,44 @@ unsigned int pci_scan_bridge(struct device *dev, unsigned int max)
/* Set up the primary, secondary and subordinate bus numbers. We have /* Set up the primary, secondary and subordinate bus numbers. We have
* no idea how many buses are behind this bridge yet, so we set the * no idea how many buses are behind this bridge yet, so we set the
* subordinate bus number to 0xff for the moment * subordinate bus number to 0xff for the moment. */
*/
bus->secondary = ++max; bus->secondary = ++max;
bus->subordinate = 0xff; bus->subordinate = 0xff;
/* Clear all status bits and turn off memory, I/O and master enables. */ /* Clear all status bits and turn off memory, I/O and master enables. */
cr = pci_read_config16(dev, PCI_COMMAND); cr = pci_read_config16(dev, PCI_COMMAND);
pci_write_config16(dev, PCI_COMMAND, 0x0000); pci_write_config16(dev, PCI_COMMAND, 0x0000);
pci_write_config16(dev, PCI_STATUS, 0xffff); pci_write_config16(dev, PCI_STATUS, 0xffff);
/* /* Read the existing primary/secondary/subordinate bus
* Read the existing primary/secondary/subordinate bus * number configuration. */
* number configuration.
*/
buses = pci_read_config32(dev, PCI_PRIMARY_BUS); buses = pci_read_config32(dev, PCI_PRIMARY_BUS);
/* Configure the bus numbers for this bridge: the configuration /* Configure the bus numbers for this bridge: the configuration
* transactions will not be propagated by the bridge if it is not * transactions will not be propagated by the bridge if it is not
* correctly configured * correctly configured */
*/
buses &= 0xff000000; buses &= 0xff000000;
buses |= (((unsigned int) (dev->bus->secondary) << 0) | buses |= (((unsigned int) (dev->bus->secondary) << 0) |
((unsigned int) (bus->secondary) << 8) | ((unsigned int) (bus->secondary) << 8) |
((unsigned int) (bus->subordinate) << 16)); ((unsigned int) (bus->subordinate) << 16));
pci_write_config32(dev, PCI_PRIMARY_BUS, buses); pci_write_config32(dev, PCI_PRIMARY_BUS, buses);
/* Now we can scan all subordinate buses i.e. the bus hehind the bridge */ /* Now we can scan all subordinate buses i.e. the buses behind the
* bridge */
max = pci_scan_bus(bus, 0x00, 0xff, max); max = pci_scan_bus(bus, 0x00, 0xff, max);
/* We know the number of buses behind this bridge. Set the subordinate /* We know the number of buses behind this bridge. Set the subordinate
* bus number to its real value * bus number to its real value */
*/
bus->subordinate = max; bus->subordinate = max;
buses = (buses & 0xff00ffff) | buses = (buses & 0xff00ffff) |
((unsigned int) (bus->subordinate) << 16); ((unsigned int) (bus->subordinate) << 16);
pci_write_config32(dev, PCI_PRIMARY_BUS, buses); pci_write_config32(dev, PCI_PRIMARY_BUS, buses);
pci_write_config16(dev, PCI_COMMAND, cr); pci_write_config16(dev, PCI_COMMAND, cr);
printk_spew("%s returns max %d\n", __FUNCTION__, max); printk_spew("%s returns max %d\n", __FUNCTION__, max);
return max; return max;
} }
/* /*
Tell the EISA int controller this int must be level triggered Tell the EISA int controller this int must be level triggered
THIS IS A KLUDGE -- sorry, this needs to get cleaned up. THIS IS A KLUDGE -- sorry, this needs to get cleaned up.

View File

@ -21,9 +21,9 @@ void root_dev_read_resources(device_t root)
root->resource[res].flags = IORESOURCE_IO; root->resource[res].flags = IORESOURCE_IO;
root->resource[res].index = 0; root->resource[res].index = 0;
printk_spew("%s . link %p, resource %p\n", __FUNCTION__, printk_spew("%s . link %p, resource %p\n", __FUNCTION__,
&root->link[0], &root->resource[res]); &root->link[0], &root->resource[res]);
compute_allocate_resource(&root->link[0], &root->resource[res], compute_allocate_resource(&root->link[0], &root->resource[res],
IORESOURCE_IO, IORESOURCE_IO); IORESOURCE_IO, IORESOURCE_IO);
res++; res++;
/* Initialize the system wide memory resources constraints */ /* Initialize the system wide memory resources constraints */
@ -35,9 +35,9 @@ void root_dev_read_resources(device_t root)
root->resource[res].flags = IORESOURCE_MEM; root->resource[res].flags = IORESOURCE_MEM;
root->resource[res].index = 1; root->resource[res].index = 1;
printk_spew("%s . link %p, resource %p\n", __FUNCTION__, printk_spew("%s . link %p, resource %p\n", __FUNCTION__,
&root->link[0], &root->resource[res]); &root->link[0], &root->resource[res]);
compute_allocate_resource(&root->link[0], &root->resource[res], compute_allocate_resource(&root->link[0], &root->resource[res],
IORESOURCE_MEM, IORESOURCE_MEM); IORESOURCE_MEM, IORESOURCE_MEM);
res++; res++;
root->resources = res; root->resources = res;
@ -51,12 +51,12 @@ void root_dev_read_resources(device_t root)
*/ */
void root_dev_set_resources(device_t root) void root_dev_set_resources(device_t root)
{ {
struct bus *bus; struct bus *bus = &root->link[0];
bus = &root->link[0];
compute_allocate_resource(bus, compute_allocate_resource(bus, &root->resource[0],
&root->resource[0], IORESOURCE_IO, IORESOURCE_IO); IORESOURCE_IO, IORESOURCE_IO);
compute_allocate_resource(bus, compute_allocate_resource(bus, &root->resource[1],
&root->resource[1], IORESOURCE_MEM, IORESOURCE_MEM); IORESOURCE_MEM, IORESOURCE_MEM);
assign_resources(bus); assign_resources(bus);
} }
@ -71,18 +71,18 @@ unsigned int walk_static_devices(device_t bus, unsigned int max)
{ {
device_t child; device_t child;
unsigned link; unsigned link;
for(link = 0; link < bus->links; link++) {
for(child = bus->link[link].children; child; child = child->sibling) { for (link = 0; link < bus->links; link++) {
for (child = bus->link[link].children; child; child = child->sibling) {
if (child->ops && child->ops->enable) { if (child->ops && child->ops->enable) {
child->ops->enable(child); child->ops->enable(child);
} }
printk_debug("%s %s\n", printk_debug("%s %s\n", dev_path(child),
dev_path(child), child->enable?"enabled": "disabled");
child->enable?"enabled": "disabled");
} }
} }
for(link = 0; link < bus->links; link++) { for (link = 0; link < bus->links; link++) {
for(child = bus->link[link].children; child; child = child->sibling) { for (child = bus->link[link].children; child; child = child->sibling) {
if (!child->ops || !child->ops->scan_bus) if (!child->ops || !child->ops->scan_bus)
continue; continue;
printk_debug("%s scanning...\n", dev_path(child)); printk_debug("%s scanning...\n", dev_path(child));
@ -95,9 +95,9 @@ unsigned int walk_static_devices(device_t bus, unsigned int max)
void enable_childrens_resources(device_t dev) void enable_childrens_resources(device_t dev)
{ {
unsigned link; unsigned link;
for(link = 0; link < dev->links; link++) { for (link = 0; link < dev->links; link++) {
device_t child; device_t child;
for(child = dev->link[link].children; child; child = child->sibling) { for (child = dev->link[link].children; child; child = child->sibling) {
enable_resources(child); enable_resources(child);
} }
} }

View File

@ -46,6 +46,7 @@ struct device {
unsigned short device; unsigned short device;
unsigned int class; /* 3 bytes: (base,sub,prog-if) */ unsigned int class; /* 3 bytes: (base,sub,prog-if) */
unsigned int hdr_type; /* PCI header type */ unsigned int hdr_type; /* PCI header type */
/* @todo rename this to 'enabled' */
unsigned int enable : 1; /* set if we should enable the device */ unsigned int enable : 1; /* set if we should enable the device */
uint8_t command; uint8_t command;

View File

@ -28,7 +28,9 @@ struct pci_driver {
}; };
#define __pci_driver __attribute__ ((unused,__section__(".rodata.pci_driver"))) #define __pci_driver __attribute__ ((unused,__section__(".rodata.pci_driver")))
/** start of compile time generated pci driver array */
extern struct pci_driver pci_drivers[]; extern struct pci_driver pci_drivers[];
/** end of compile time generated pci driver array */
extern struct pci_driver epci_drivers[]; extern struct pci_driver epci_drivers[];

View File

@ -6,17 +6,19 @@ uses LB_CKS_RANGE_END
uses LB_CKS_LOC uses LB_CKS_LOC
uses MAINBOARD uses MAINBOARD
uses ARCH uses ARCH
# #
# #
### ###
### Set all of the defaults for an x86 architecture ### Set all of the defaults for an x86 architecture
### ###
# #
# #
### ###
### Build the objects we have code for in this directory. ### Build the objects we have code for in this directory.
### ###
##object mainboard.o
config chip.h config chip.h
register "fixup_scsi" = "1" register "fixup_scsi" = "1"
register "fixup_vga" = "1" register "fixup_vga" = "1"
@ -38,9 +40,10 @@ driver mainboard.o
object reset.o object reset.o
if HAVE_MP_TABLE object mptable.o end if HAVE_MP_TABLE object mptable.o end
if HAVE_PIRQ_TABLE object irq_tables.o end if HAVE_PIRQ_TABLE object irq_tables.o end
# #
arch i386 end arch i386 end
#cpu k8 end
# #
### ###
### Build our 16 bit and 32 bit linuxBIOS entry code ### Build our 16 bit and 32 bit linuxBIOS entry code
@ -50,6 +53,7 @@ mainboardinit cpu/i386/entry32.inc
mainboardinit cpu/i386/bist32.inc mainboardinit cpu/i386/bist32.inc
ldscript /cpu/i386/entry16.lds ldscript /cpu/i386/entry16.lds
ldscript /cpu/i386/entry32.lds ldscript /cpu/i386/entry32.lds
# #
### ###
### Build our reset vector (This is where linuxBIOS is entered) ### Build our reset vector (This is where linuxBIOS is entered)
@ -120,24 +124,30 @@ end
makerule ./failover.inc makerule ./failover.inc
depends "./romcc ./failover.E" depends "./romcc ./failover.E"
action "./romcc -O -o failover.inc --label-prefix=failover ./failover.E"end action "./romcc -O -o failover.inc --label-prefix=failover ./failover.E"
end
makerule ./auto.E makerule ./auto.E
depends "$(MAINBOARD)/auto.c option_table.h" depends "$(MAINBOARD)/auto.c option_table.h"
action "$(CPP) -I$(TOP)/src -I. $(ROMCCPPFLAGS) $(CPPFLAGS) $(MAINBOARD)/auto.c > ./auto.E" action "$(CPP) -I$(TOP)/src -I. $(ROMCCPPFLAGS) $(CPPFLAGS) $(MAINBOARD)/auto.c > ./auto.E"
end end
makerule ./auto.inc makerule ./auto.inc
depends "./romcc ./auto.E" depends "./romcc ./auto.E"
action "./romcc -O -mcpu=k8 -o auto.inc --label-prefix=auto ./auto.E" action "./romcc -O -mcpu=k8 -o auto.inc --label-prefix=auto ./auto.E"
# action "./romcc -mcpu=k8 -O ./auto.E > auto.inc" # action "./romcc -mcpu=k8 -O ./auto.E > auto.inc"
end end
mainboardinit cpu/k8/enable_mmx_sse.inc mainboardinit cpu/k8/enable_mmx_sse.inc
mainboardinit ./auto.inc mainboardinit ./auto.inc
mainboardinit cpu/k8/disable_mmx_sse.inc mainboardinit cpu/k8/disable_mmx_sse.inc
# #
### ###
### Include the secondary Configuration files ### Include the secondary Configuration files
### ###
dir /pc80
northbridge amd/amdk8 "mc0" northbridge amd/amdk8 "mc0"
pci 0:18.0 pci 0:18.0
pci 0:18.0 pci 0:18.0
@ -203,7 +213,7 @@ northbridge amd/amdk8 "mc1"
pci 0:19.2 pci 0:19.2
pci 0:19.3 pci 0:19.3
end end
dir /pc80 dir /pc80
#dir /bioscall #dir /bioscall

View File

@ -78,7 +78,8 @@ default HEAP_SIZE=0x4000
## ##
## Only use the option table in a normal image ## Only use the option table in a normal image
## ##
default USE_OPTION_TABLE = !USE_FALLBACK_IMAGE #default USE_OPTION_TABLE = !USE_FALLBACK_IMAGE
default USE_OPTION_TABLE = 0
## ##
## Compute the location and size of where this firmware image ## Compute the location and size of where this firmware image

View File

@ -1,8 +1,5 @@
#define ASSEMBLY 1 #define ASSEMBLY 1
//#define MAXIMUM_CONSOLE_LOGLEVEL 6
//#define DEFAULT_CONSOLE_LOGLEVEL 6
#include <stdint.h> #include <stdint.h>
#include <device/pci_def.h> #include <device/pci_def.h>
#include <cpu/p6/apic.h> #include <cpu/p6/apic.h>
@ -15,6 +12,7 @@
#include "ram/ramtest.c" #include "ram/ramtest.c"
#include "northbridge/via/vt8601/raminit.h" #include "northbridge/via/vt8601/raminit.h"
#include "cpu/p6/earlymtrr.c" #include "cpu/p6/earlymtrr.c"
/* /*
*/ */
void udelay(int usecs) void udelay(int usecs)

View File

@ -16,8 +16,8 @@ static int enumerate_ht_chain(void)
id = pci_read_config32(PCI_DEV(0,0,0), PCI_VENDOR_ID); id = pci_read_config32(PCI_DEV(0,0,0), PCI_VENDOR_ID);
/* If the chain is enumerated quit */ /* If the chain is enumerated quit */
if (((id & 0xffff) == 0x0000) || ((id & 0xffff) == 0xffff) || if (((id & 0xffff) == 0x0000) || ((id & 0xffff) == 0xffff) ||
(((id >> 16) & 0xffff) == 0xffff) || (((id >> 16) & 0xffff) == 0xffff) ||
(((id >> 16) & 0xffff) == 0x0000)) { (((id >> 16) & 0xffff) == 0x0000)) {
break; break;
} }
hdr_type = pci_read_config8(PCI_DEV(0,0,0), PCI_HEADER_TYPE); hdr_type = pci_read_config8(PCI_DEV(0,0,0), PCI_HEADER_TYPE);
@ -25,7 +25,7 @@ static int enumerate_ht_chain(void)
hdr_type &= 0x7f; hdr_type &= 0x7f;
if ((hdr_type == PCI_HEADER_TYPE_NORMAL) || if ((hdr_type == PCI_HEADER_TYPE_NORMAL) ||
(hdr_type == PCI_HEADER_TYPE_BRIDGE)) { (hdr_type == PCI_HEADER_TYPE_BRIDGE)) {
pos = pci_read_config8(PCI_DEV(0,0,0), PCI_CAPABILITY_LIST); pos = pci_read_config8(PCI_DEV(0,0,0), PCI_CAPABILITY_LIST);
} }
while(pos != 0) { while(pos != 0) {

View File

@ -42,7 +42,7 @@ struct mem_range *sizeram(void)
printk_debug("mmio_base: %dKB\n", mmio_basek); printk_debug("mmio_base: %dKB\n", mmio_basek);
#endif #endif
for(idx = i = 0; i < 8; i++) { for (idx = i = 0; i < 8; i++) {
uint32_t base, limit; uint32_t base, limit;
unsigned basek, limitk, sizek; unsigned basek, limitk, sizek;
base = pci_read_config32(dev, 0x40 + (i<<3)); base = pci_read_config32(dev, 0x40 + (i<<3));
@ -54,18 +54,18 @@ struct mem_range *sizeram(void)
limitk = ((limit + 0x00010000) & 0xffff0000) >> 2; limitk = ((limit + 0x00010000) & 0xffff0000) >> 2;
sizek = limitk - basek; sizek = limitk - basek;
if ((idx > 0) && if ((idx > 0) &&
((mem[idx -1].basek + mem[idx - 1].sizek) == basek)) { ((mem[idx - 1].basek + mem[idx - 1].sizek) == basek)) {
mem[idx -1].sizek += sizek; mem[idx -1].sizek += sizek;
} } else {
else {
mem[idx].basek = basek; mem[idx].basek = basek;
mem[idx].sizek = sizek; mem[idx].sizek = sizek;
idx++; idx++;
} }
/* see if we need a hole from 0xa0000 to 0xbffff */ /* see if we need a hole from 0xa0000 to 0xbffff */
if((mem[idx-1].basek < ((8*64)+(8*16))) && if ((mem[idx-1].basek < ((8*64)+(8*16))) /* 640 */ &&
(mem[idx-1].sizek > ((8*64)+(16*16)))) { (mem[idx-1].sizek > ((8*64)+(16*16))) /* 768 */ ) {
#warning "FIXME: this left 0xA0000 to 0xBFFFF undefined"
mem[idx].basek = (8*64)+(16*16); mem[idx].basek = (8*64)+(16*16);
mem[idx].sizek = mem[idx-1].sizek - ((8*64)+(16*16)); mem[idx].sizek = mem[idx-1].sizek - ((8*64)+(16*16));
mem[idx-1].sizek = ((8*64)+(8*16)) - mem[idx-1].basek; mem[idx-1].sizek = ((8*64)+(8*16)) - mem[idx-1].basek;
@ -74,7 +74,7 @@ struct mem_range *sizeram(void)
/* See if I need to split the region to accomodate pci memory space */ /* See if I need to split the region to accomodate pci memory space */
if ((mem[idx - 1].basek <= mmio_basek) && if ((mem[idx - 1].basek <= mmio_basek) &&
((mem[idx - 1].basek + mem[idx - 1].sizek) > mmio_basek)) { ((mem[idx - 1].basek + mem[idx - 1].sizek) > mmio_basek)) {
if (mem[idx - 1].basek < mmio_basek) { if (mem[idx - 1].basek < mmio_basek) {
unsigned pre_sizek; unsigned pre_sizek;
pre_sizek = mmio_basek - mem[idx - 1].basek; pre_sizek = mmio_basek - mem[idx - 1].basek;
@ -92,10 +92,10 @@ struct mem_range *sizeram(void)
} }
} }
} }
#if 0 #if 1
for(i = 0; i < idx; i++) { for (i = 0; i < idx; i++) {
printk_debug("mem[%d].basek = %08x mem[%d].sizek = %08x\n", printk_debug("mem[%d].basek = %08x mem[%d].sizek = %08x\n",
i, mem[i].basek, i, mem[i].sizek); i, mem[i].basek, i, mem[i].sizek);
} }
#endif #endif
while(idx < sizeof(mem)/sizeof(mem[0])) { while(idx < sizeof(mem)/sizeof(mem[0])) {
@ -514,6 +514,40 @@ static void mcf0_control_init(struct device *dev)
printk_debug("done.\n"); printk_debug("done.\n");
} }
static void amdk8_enable_resources(struct device *dev)
{
uint16_t ctrl;
unsigned link;
unsigned int vgalink = -1;
ctrl = pci_read_config16(dev, PCI_BRIDGE_CONTROL);
ctrl |= dev->link[0].bridge_ctrl;
printk_debug("%s bridge ctrl <- %04x\n", dev_path(dev), ctrl);
printk_err("%s bridge ctrl <- %04x\n", dev_path(dev), ctrl);
pci_write_config16(dev, PCI_BRIDGE_CONTROL, ctrl);
#if 0
/* let's see what link VGA is on */
for(link = 0; link < dev->links; link++) {
device_t child;
printk_err("Kid %d of k8: bridge ctrl says: 0x%x\n",
link, dev->link[link].bridge_ctrl);
if (dev->link[link].bridge_ctrl & PCI_BRIDGE_CTL_VGA)
vgalink = link;
}
if (vgalink != 1) {
/* now find the IOPAIR that goes to vgalink and set the vga enable in the base part (0x30) */
/* now allocate an MMIOPAIR and point it to the CPU0, LINK=vgalink */
/* now set IORR1 so it has a hole for the 0xa0000-0xcffff region */
}
#endif
pci_dev_enable_resources(dev);
//enable_childrens_resources(dev);
}
static struct device_operations northbridge_operations = { static struct device_operations northbridge_operations = {
.read_resources = amdk8_read_resources, .read_resources = amdk8_read_resources,
.set_resources = amdk8_set_resources, .set_resources = amdk8_set_resources,

View File

@ -5,10 +5,12 @@
#if (CONFIG_LB_MEM_TOPK & (CONFIG_LB_MEM_TOPK -1)) != 0 #if (CONFIG_LB_MEM_TOPK & (CONFIG_LB_MEM_TOPK -1)) != 0
# error "CONFIG_LB_MEM_TOPK must be a power of 2" # error "CONFIG_LB_MEM_TOPK must be a power of 2"
#endif #endif
static void setup_resource_map(const unsigned int *register_values, int max) static void setup_resource_map(const unsigned int *register_values, int max)
{ {
int i; int i;
print_debug("setting up resource map...."); print_debug("setting up resource map....");
#if 0 #if 0
print_debug("\r\n"); print_debug("\r\n");
#endif #endif

View File

@ -15,7 +15,7 @@ void amd8111_enable(device_t dev)
/* See if we are on the behind the amd8111 pci bridge */ /* See if we are on the behind the amd8111 pci bridge */
bus_dev = dev->bus->dev; bus_dev = dev->bus->dev;
if ((bus_dev->vendor == PCI_VENDOR_ID_AMD) && if ((bus_dev->vendor == PCI_VENDOR_ID_AMD) &&
(bus_dev->device == PCI_DEVICE_ID_AMD_8111_PCI)) { (bus_dev->device == PCI_DEVICE_ID_AMD_8111_PCI)) {
unsigned devfn; unsigned devfn;
devfn = bus_dev->path.u.pci.devfn + (1 << 3); devfn = bus_dev->path.u.pci.devfn + (1 << 3);
lpc_dev = dev_find_slot(bus_dev->bus->secondary, devfn); lpc_dev = dev_find_slot(bus_dev->bus->secondary, devfn);
@ -26,11 +26,12 @@ void amd8111_enable(device_t dev)
lpc_dev = dev_find_slot(dev->bus->secondary, devfn); lpc_dev = dev_find_slot(dev->bus->secondary, devfn);
index = dev->path.u.pci.devfn & 7; index = dev->path.u.pci.devfn & 7;
} }
if ((!lpc_dev) || (index >= 16)) { if ((!lpc_dev) || (index >= 16)) {
return; return;
} }
if ((lpc_dev->vendor != PCI_VENDOR_ID_AMD) || if ((lpc_dev->vendor != PCI_VENDOR_ID_AMD) ||
(lpc_dev->device != PCI_DEVICE_ID_AMD_8111_ISA)) { (lpc_dev->device != PCI_DEVICE_ID_AMD_8111_ISA)) {
uint32_t id; uint32_t id;
id = pci_read_config32(lpc_dev, PCI_VENDOR_ID); id = pci_read_config32(lpc_dev, PCI_VENDOR_ID);
if (id != (PCI_VENDOR_ID_AMD | (PCI_DEVICE_ID_AMD_8111_ISA << 16))) { if (id != (PCI_VENDOR_ID_AMD | (PCI_DEVICE_ID_AMD_8111_ISA << 16))) {
@ -48,6 +49,6 @@ void amd8111_enable(device_t dev)
} }
struct chip_control southbridge_amd_amd8111_control = { struct chip_control southbridge_amd_amd8111_control = {
.name = "AMD 8111", .name = "AMD 8111 Southbridge",
.enable_dev = amd8111_enable, .enable_dev = amd8111_enable,
}; };