2003-04-22 21:02:15 +02:00
|
|
|
/*
|
|
|
|
This software and ancillary information (herein called SOFTWARE )
|
|
|
|
called LinuxBIOS is made available under the terms described
|
|
|
|
here. The SOFTWARE has been approved for release with associated
|
|
|
|
LA-CC Number 00-34 . Unless otherwise indicated, this SOFTWARE has
|
|
|
|
been authored by an employee or employees of the University of
|
|
|
|
California, operator of the Los Alamos National Laboratory under
|
|
|
|
Contract No. W-7405-ENG-36 with the U.S. Department of Energy. The
|
|
|
|
U.S. Government has rights to use, reproduce, and distribute this
|
|
|
|
SOFTWARE. The public may copy, distribute, prepare derivative works
|
|
|
|
and publicly display this SOFTWARE without charge, provided that this
|
|
|
|
Notice and any statement of authorship are reproduced on all copies.
|
|
|
|
Neither the Government nor the University makes any warranty, express
|
|
|
|
or implied, or assumes any liability or responsibility for the use of
|
|
|
|
this SOFTWARE. If SOFTWARE is modified to produce derivative works,
|
|
|
|
such modified SOFTWARE should be clearly marked, so as not to confuse
|
|
|
|
it with the version available from LANL.
|
|
|
|
*/
|
|
|
|
/* Copyright 2000, Ron Minnich, Advanced Computing Lab, LANL
|
|
|
|
* rminnich@lanl.gov
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* C Bootstrap code for the LinuxBIOS
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <console/console.h>
|
|
|
|
#include <cpu/cpu.h>
|
|
|
|
#include <mem.h>
|
|
|
|
#include <version.h>
|
|
|
|
#include <smp/start_stop.h>
|
|
|
|
#include <boot/tables.h>
|
|
|
|
#include <part/sizeram.h>
|
2003-04-24 08:25:08 +02:00
|
|
|
#include <device/device.h>
|
|
|
|
#include <device/pci.h>
|
2003-07-23 20:20:17 +02:00
|
|
|
#include <device/chip.h>
|
2003-07-19 06:28:22 +02:00
|
|
|
#include <delay.h>
|
2003-04-22 21:02:15 +02:00
|
|
|
#include <part/hard_reset.h>
|
|
|
|
#include <smp/atomic.h>
|
|
|
|
#include <boot/elf.h>
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef CONFIG_MAX_PHYSICAL_CPUS
|
|
|
|
#define CONFIG_MAX_PHYSICAL_CPUS CONFIG_MAX_CPUS
|
|
|
|
#endif
|
|
|
|
|
2004-03-26 03:32:45 +01:00
|
|
|
#if CONFIG_FS_STREAM == 1
|
|
|
|
extern int filo(struct lb_memory *);
|
|
|
|
#endif
|
|
|
|
|
2003-04-22 21:02:15 +02:00
|
|
|
/* The processor map.
|
|
|
|
* Now that SMP is in linuxbios, and Linux counts on us
|
|
|
|
* giving accurate information about processors, we need a map
|
|
|
|
* of what processors are out there. This could be a bit mask,
|
|
|
|
* but we will be optimistic and hope we someday run on
|
|
|
|
* REALLY BIG SMPs. Also we may need more than one bit of
|
|
|
|
* info per processor at some point. I hope we don't need
|
|
|
|
* anything more complex than an int.
|
|
|
|
*/
|
2003-09-02 01:17:58 +02:00
|
|
|
static unsigned long processor_map[CONFIG_MAX_CPUS];
|
2003-04-22 21:02:15 +02:00
|
|
|
|
|
|
|
static struct mem_range *get_ramsize(void)
|
|
|
|
{
|
|
|
|
struct mem_range *mem = 0;
|
|
|
|
if (!mem) {
|
|
|
|
mem = sizeram();
|
|
|
|
}
|
|
|
|
if (!mem) {
|
2003-07-21 22:13:45 +02:00
|
|
|
printk_emerg("No memory size information!\n");
|
|
|
|
for(;;) {
|
|
|
|
/* Ensure this loop is not optimized away */
|
|
|
|
asm volatile("":/* outputs */:/*inputs */ :"memory");
|
|
|
|
}
|
2003-04-22 21:02:15 +02:00
|
|
|
}
|
|
|
|
return mem;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-19 06:28:22 +02:00
|
|
|
#if CONFIG_SMP == 1
|
2003-04-22 21:02:15 +02:00
|
|
|
/* Number of cpus that are currently running in linuxbios */
|
|
|
|
static atomic_t active_cpus = ATOMIC_INIT(1);
|
|
|
|
|
2004-03-23 22:28:05 +01:00
|
|
|
/**
|
|
|
|
* @brief Initialize secondary processors.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @todo move this into a method of per cpu data structure.
|
|
|
|
*/
|
2003-04-22 21:02:15 +02:00
|
|
|
void secondary_cpu_init(void)
|
|
|
|
{
|
|
|
|
struct mem_range *mem;
|
|
|
|
unsigned long id;
|
|
|
|
int index;
|
|
|
|
|
|
|
|
atomic_inc(&active_cpus);
|
2004-03-23 22:28:05 +01:00
|
|
|
|
2003-09-26 16:36:27 +02:00
|
|
|
printk_debug("%s\n", __FUNCTION__);
|
2003-04-22 21:02:15 +02:00
|
|
|
mem = get_ramsize();
|
|
|
|
id = cpu_initialize(mem);
|
|
|
|
index = processor_index(id);
|
2003-09-26 16:36:27 +02:00
|
|
|
printk_debug("%s %d/%u\n", __FUNCTION__ , index, id);
|
2003-04-22 21:02:15 +02:00
|
|
|
processor_map[index] = CPU_ENABLED;
|
2004-03-23 22:28:05 +01:00
|
|
|
|
2003-04-22 21:02:15 +02:00
|
|
|
atomic_dec(&active_cpus);
|
|
|
|
stop_cpu(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wait_for_other_cpus(void)
|
|
|
|
{
|
|
|
|
int old_active_count, active_count;
|
|
|
|
int i;
|
|
|
|
old_active_count = 1;
|
|
|
|
|
|
|
|
active_count = atomic_read(&active_cpus);
|
2004-03-23 22:28:05 +01:00
|
|
|
while (active_count > 1) {
|
2003-04-22 21:02:15 +02:00
|
|
|
if (active_count != old_active_count) {
|
2004-03-23 22:28:05 +01:00
|
|
|
printk_info("Waiting for %d CPUS to stop\n",
|
|
|
|
active_count);
|
2003-04-22 21:02:15 +02:00
|
|
|
old_active_count = active_count;
|
|
|
|
}
|
|
|
|
active_count = atomic_read(&active_cpus);
|
|
|
|
}
|
2004-03-23 22:28:05 +01:00
|
|
|
|
|
|
|
for (i = 0; i < CONFIG_MAX_CPUS; i++) {
|
2003-04-22 21:02:15 +02:00
|
|
|
if (!(processor_map[i] & CPU_ENABLED)) {
|
2003-07-19 06:28:22 +02:00
|
|
|
printk_err("CPU %d did not initialize!\n", i);
|
2003-04-22 21:02:15 +02:00
|
|
|
processor_map[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
2004-03-23 22:28:05 +01:00
|
|
|
|
2003-04-22 21:02:15 +02:00
|
|
|
printk_debug("All AP CPUs stopped\n");
|
|
|
|
}
|
|
|
|
|
2003-07-21 22:13:45 +02:00
|
|
|
#else /* CONIFG_SMP */
|
2003-04-22 21:02:15 +02:00
|
|
|
#define wait_for_other_cpus() do {} while(0)
|
2003-07-21 22:13:45 +02:00
|
|
|
#endif /* CONFIG_SMP */
|
2003-04-22 21:02:15 +02:00
|
|
|
|
2004-03-23 22:28:05 +01:00
|
|
|
/**
|
|
|
|
* @brief Main program of LinuxBIOS
|
|
|
|
*
|
|
|
|
* @param boot_complete
|
|
|
|
*/
|
2003-04-22 21:02:15 +02:00
|
|
|
void hardwaremain(int boot_complete)
|
|
|
|
{
|
|
|
|
/* Processor ID of the BOOT cpu (i.e. the one running this code) */
|
|
|
|
unsigned long boot_cpu;
|
|
|
|
int boot_index;
|
|
|
|
struct mem_range *mem, *tmem;
|
|
|
|
struct lb_memory *lb_mem;
|
|
|
|
unsigned long totalmem;
|
|
|
|
|
|
|
|
post_code(0x80);
|
2004-05-13 22:39:07 +02:00
|
|
|
|
2003-07-23 20:20:17 +02:00
|
|
|
CONFIGURE(CONF_PASS_PRE_CONSOLE);
|
|
|
|
|
2003-04-22 21:02:15 +02:00
|
|
|
/* displayinit MUST PRECEDE ALL PRINTK! */
|
|
|
|
console_init();
|
|
|
|
|
|
|
|
post_code(0x39);
|
|
|
|
printk_notice("LinuxBIOS-%s%s %s %s...\n",
|
2004-03-23 22:28:05 +01:00
|
|
|
linuxbios_version, linuxbios_extra_version,
|
|
|
|
linuxbios_build, (boot_complete)?"rebooting":"booting");
|
2003-04-22 21:02:15 +02:00
|
|
|
|
|
|
|
post_code(0x40);
|
|
|
|
|
|
|
|
/* If we have already booted attempt a hard reboot */
|
|
|
|
if (boot_complete) {
|
|
|
|
hard_reset();
|
|
|
|
}
|
2004-03-23 22:28:05 +01:00
|
|
|
|
2003-07-23 20:20:17 +02:00
|
|
|
CONFIGURE(CONF_PASS_PRE_PCI);
|
2003-04-22 21:02:15 +02:00
|
|
|
|
2004-03-23 22:28:05 +01:00
|
|
|
/* determine how software can generate PCI configuration transactions
|
|
|
|
* in this system */
|
2003-04-22 21:02:15 +02:00
|
|
|
printk_info("Finding PCI configuration type.\n");
|
|
|
|
pci_set_method();
|
|
|
|
post_code(0x5f);
|
2004-03-23 22:28:05 +01:00
|
|
|
|
|
|
|
/* convert static device structures into dynamic device structures
|
|
|
|
* before probing dynamic devices. */
|
2003-04-22 21:02:15 +02:00
|
|
|
enumerate_static_devices();
|
2004-03-23 22:28:05 +01:00
|
|
|
|
|
|
|
/* probe the existence of dynamic devices and construct the dynamic
|
|
|
|
* device tree. */
|
2003-04-22 21:02:15 +02:00
|
|
|
dev_enumerate();
|
|
|
|
post_code(0x66);
|
2004-03-23 22:28:05 +01:00
|
|
|
|
|
|
|
/* probe and assign the resources required by the dynamic devices */
|
2003-04-22 21:02:15 +02:00
|
|
|
dev_configure();
|
|
|
|
post_code(0x88);
|
|
|
|
|
2004-03-23 22:28:05 +01:00
|
|
|
/* enable the resources probed and assigned in dev_configure() */
|
2003-04-22 21:02:15 +02:00
|
|
|
dev_enable();
|
2003-05-19 21:16:21 +02:00
|
|
|
|
2004-03-23 22:28:05 +01:00
|
|
|
/* do the device specific init in additional to simple resources
|
|
|
|
* allocation performed in dev_enable() */
|
2003-04-22 21:02:15 +02:00
|
|
|
dev_initialize();
|
|
|
|
post_code(0x89);
|
|
|
|
|
2003-07-23 23:38:02 +02:00
|
|
|
CONFIGURE(CONF_PASS_POST_PCI);
|
|
|
|
|
2004-03-23 22:28:05 +01:00
|
|
|
/* this is done last because some devices may 'steal' memory from
|
|
|
|
* the system during device initialization. */
|
2003-04-22 21:02:15 +02:00
|
|
|
mem = get_ramsize();
|
|
|
|
post_code(0x70);
|
2004-03-23 22:28:05 +01:00
|
|
|
for (totalmem = 0, tmem = mem; tmem->sizek; tmem++) {
|
2003-04-22 21:02:15 +02:00
|
|
|
totalmem += tmem->sizek;
|
|
|
|
}
|
2004-03-23 22:28:05 +01:00
|
|
|
/* Round to the nearest mega */
|
|
|
|
printk_info("totalram: %ldM\n", (totalmem + 512) >> 10);
|
2003-04-22 21:02:15 +02:00
|
|
|
|
2004-03-23 22:28:05 +01:00
|
|
|
/* fully initialize the boot processor */
|
2003-04-22 21:02:15 +02:00
|
|
|
boot_cpu = cpu_initialize(mem);
|
|
|
|
boot_index = processor_index(boot_cpu);
|
|
|
|
printk_spew("BOOT CPU is %d\n", boot_cpu);
|
|
|
|
processor_map[boot_index] = CPU_BOOTPROCESSOR|CPU_ENABLED;
|
|
|
|
|
2004-03-23 22:28:05 +01:00
|
|
|
/* start up other processors, it works like a pthread_create() or
|
|
|
|
* fork(), instead of running the initialization code for all devices
|
|
|
|
* as the boot processor, they start from secondary_cpu_init(), doing
|
|
|
|
* cpu initialization only. */
|
2003-04-22 21:02:15 +02:00
|
|
|
post_code(0x75);
|
|
|
|
startup_other_cpus(processor_map);
|
|
|
|
|
2004-03-23 22:28:05 +01:00
|
|
|
/* 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 */
|
2003-04-22 21:02:15 +02:00
|
|
|
wait_for_other_cpus();
|
|
|
|
|
2004-03-23 22:28:05 +01:00
|
|
|
/* Now that we have collected all of our information, write our
|
|
|
|
* configuration tables. */
|
2003-04-22 21:02:15 +02:00
|
|
|
lb_mem = write_tables(mem, processor_map);
|
|
|
|
|
2003-07-23 23:38:02 +02:00
|
|
|
CONFIGURE(CONF_PASS_PRE_BOOT);
|
2003-07-23 20:20:17 +02:00
|
|
|
|
2004-03-17 18:10:32 +01:00
|
|
|
#if CONFIG_FS_STREAM == 1
|
|
|
|
filo(lb_mem);
|
|
|
|
#else
|
2003-04-22 21:02:15 +02:00
|
|
|
elfboot(lb_mem);
|
2004-03-17 18:10:32 +01:00
|
|
|
#endif
|
2003-04-22 21:02:15 +02:00
|
|
|
}
|
|
|
|
|