Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1 | /* |
| 2 | This software and ancillary information (herein called SOFTWARE ) |
| 3 | called LinuxBIOS is made available under the terms described |
| 4 | here. The SOFTWARE has been approved for release with associated |
| 5 | LA-CC Number 00-34 . Unless otherwise indicated, this SOFTWARE has |
| 6 | been authored by an employee or employees of the University of |
| 7 | California, operator of the Los Alamos National Laboratory under |
| 8 | Contract No. W-7405-ENG-36 with the U.S. Department of Energy. The |
| 9 | U.S. Government has rights to use, reproduce, and distribute this |
| 10 | SOFTWARE. The public may copy, distribute, prepare derivative works |
| 11 | and publicly display this SOFTWARE without charge, provided that this |
| 12 | Notice and any statement of authorship are reproduced on all copies. |
| 13 | Neither the Government nor the University makes any warranty, express |
| 14 | or implied, or assumes any liability or responsibility for the use of |
| 15 | this SOFTWARE. If SOFTWARE is modified to produce derivative works, |
| 16 | such modified SOFTWARE should be clearly marked, so as not to confuse |
| 17 | it with the version available from LANL. |
| 18 | */ |
| 19 | /* Copyright 2000, Ron Minnich, Advanced Computing Lab, LANL |
| 20 | * rminnich@lanl.gov |
| 21 | */ |
| 22 | |
| 23 | |
| 24 | /* |
| 25 | * C Bootstrap code for the LinuxBIOS |
| 26 | */ |
| 27 | |
| 28 | |
| 29 | #include <console/console.h> |
| 30 | #include <cpu/cpu.h> |
| 31 | #include <mem.h> |
| 32 | #include <version.h> |
| 33 | #include <smp/start_stop.h> |
| 34 | #include <boot/tables.h> |
| 35 | #include <part/sizeram.h> |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 36 | #include <device/device.h> |
| 37 | #include <device/pci.h> |
Greg Watson | 2910a2b | 2003-07-23 18:20:17 +0000 | [diff] [blame] | 38 | #include <device/chip.h> |
Eric Biederman | 9b4336c | 2003-07-19 04:28:22 +0000 | [diff] [blame] | 39 | #include <delay.h> |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 40 | #if 0 |
| 41 | #include <part/mainboard.h> |
| 42 | #endif |
| 43 | #if 0 |
| 44 | #include <part/hard_reset.h> |
| 45 | #endif |
| 46 | #include <smp/atomic.h> |
| 47 | #include <boot/elf.h> |
| 48 | |
| 49 | |
| 50 | #ifndef CONFIG_MAX_PHYSICAL_CPUS |
| 51 | #define CONFIG_MAX_PHYSICAL_CPUS CONFIG_MAX_CPUS |
| 52 | #endif |
| 53 | |
| 54 | /* The processor map. |
| 55 | * Now that SMP is in linuxbios, and Linux counts on us |
| 56 | * giving accurate information about processors, we need a map |
| 57 | * of what processors are out there. This could be a bit mask, |
| 58 | * but we will be optimistic and hope we someday run on |
| 59 | * REALLY BIG SMPs. Also we may need more than one bit of |
| 60 | * info per processor at some point. I hope we don't need |
| 61 | * anything more complex than an int. |
| 62 | */ |
Eric Biederman | 9bdb460 | 2003-09-01 23:17:58 +0000 | [diff] [blame^] | 63 | static unsigned long processor_map[CONFIG_MAX_CPUS]; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 64 | |
| 65 | static struct mem_range *get_ramsize(void) |
| 66 | { |
| 67 | struct mem_range *mem = 0; |
| 68 | if (!mem) { |
| 69 | mem = sizeram(); |
| 70 | } |
| 71 | if (!mem) { |
Eric Biederman | 2c018fb | 2003-07-21 20:13:45 +0000 | [diff] [blame] | 72 | printk_emerg("No memory size information!\n"); |
| 73 | for(;;) { |
| 74 | /* Ensure this loop is not optimized away */ |
| 75 | asm volatile("":/* outputs */:/*inputs */ :"memory"); |
| 76 | } |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 77 | } |
| 78 | return mem; |
| 79 | } |
| 80 | |
| 81 | |
Eric Biederman | 9b4336c | 2003-07-19 04:28:22 +0000 | [diff] [blame] | 82 | #if CONFIG_SMP == 1 |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 83 | /* Number of cpus that are currently running in linuxbios */ |
| 84 | static atomic_t active_cpus = ATOMIC_INIT(1); |
| 85 | |
| 86 | void secondary_cpu_init(void) |
| 87 | { |
| 88 | struct mem_range *mem; |
| 89 | unsigned long id; |
| 90 | int index; |
| 91 | |
| 92 | atomic_inc(&active_cpus); |
| 93 | printk_debug(__FUNCTION__ "\n"); |
| 94 | mem = get_ramsize(); |
| 95 | id = cpu_initialize(mem); |
| 96 | index = processor_index(id); |
| 97 | printk_debug(__FUNCTION__ " %d/%u\n", index, id); |
| 98 | processor_map[index] = CPU_ENABLED; |
| 99 | atomic_dec(&active_cpus); |
| 100 | stop_cpu(id); |
| 101 | } |
| 102 | |
| 103 | static void wait_for_other_cpus(void) |
| 104 | { |
| 105 | int old_active_count, active_count; |
| 106 | int i; |
| 107 | old_active_count = 1; |
| 108 | |
| 109 | active_count = atomic_read(&active_cpus); |
| 110 | while(active_count > 1) { |
| 111 | if (active_count != old_active_count) { |
| 112 | printk_info("Waiting for %d CPUS to stop\n", active_count); |
| 113 | old_active_count = active_count; |
| 114 | } |
| 115 | active_count = atomic_read(&active_cpus); |
| 116 | } |
Eric Biederman | 9bdb460 | 2003-09-01 23:17:58 +0000 | [diff] [blame^] | 117 | for(i = 0; i < CONFIG_MAX_CPUS; i++) { |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 118 | if (!(processor_map[i] & CPU_ENABLED)) { |
Eric Biederman | 9b4336c | 2003-07-19 04:28:22 +0000 | [diff] [blame] | 119 | printk_err("CPU %d did not initialize!\n", i); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 120 | processor_map[i] = 0; |
Eric Biederman | 9b4336c | 2003-07-19 04:28:22 +0000 | [diff] [blame] | 121 | #warning "FIXME do I need a mainboard_cpu_fixup function?" |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 122 | } |
| 123 | } |
| 124 | printk_debug("All AP CPUs stopped\n"); |
| 125 | } |
| 126 | |
Eric Biederman | 2c018fb | 2003-07-21 20:13:45 +0000 | [diff] [blame] | 127 | #else /* CONIFG_SMP */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 128 | #define wait_for_other_cpus() do {} while(0) |
Eric Biederman | 2c018fb | 2003-07-21 20:13:45 +0000 | [diff] [blame] | 129 | #endif /* CONFIG_SMP */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 130 | |
| 131 | void hardwaremain(int boot_complete) |
| 132 | { |
| 133 | /* Processor ID of the BOOT cpu (i.e. the one running this code) */ |
| 134 | unsigned long boot_cpu; |
| 135 | int boot_index; |
| 136 | |
| 137 | /* the order here is a bit tricky. We don't want to do much of |
| 138 | * anything that uses config registers until after PciAllocateResources |
| 139 | * since that function also figures out what kind of config strategy |
| 140 | * to use (type 1 or type 2). |
| 141 | * so we turn on cache, then worry about PCI setup, then do other |
| 142 | * things, so that the other work can use the PciRead* and PciWrite* |
| 143 | * functions. |
| 144 | */ |
| 145 | struct mem_range *mem, *tmem; |
| 146 | struct lb_memory *lb_mem; |
| 147 | unsigned long totalmem; |
| 148 | |
| 149 | post_code(0x80); |
Greg Watson | 2910a2b | 2003-07-23 18:20:17 +0000 | [diff] [blame] | 150 | |
| 151 | CONFIGURE(CONF_PASS_PRE_CONSOLE); |
| 152 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 153 | /* displayinit MUST PRECEDE ALL PRINTK! */ |
| 154 | console_init(); |
| 155 | |
| 156 | post_code(0x39); |
| 157 | printk_notice("LinuxBIOS-%s%s %s %s...\n", |
| 158 | linuxbios_version, linuxbios_extra_version, linuxbios_build, |
| 159 | (boot_complete)?"rebooting":"booting"); |
| 160 | |
| 161 | post_code(0x40); |
| 162 | |
| 163 | #if 0 |
| 164 | /* If we have already booted attempt a hard reboot */ |
| 165 | if (boot_complete) { |
| 166 | hard_reset(); |
| 167 | } |
| 168 | #endif |
Greg Watson | 5bed979 | 2003-07-23 21:38:02 +0000 | [diff] [blame] | 169 | init_timer(); /* needs to be moved into static configuration */ |
Greg Watson | 2910a2b | 2003-07-23 18:20:17 +0000 | [diff] [blame] | 170 | CONFIGURE(CONF_PASS_PRE_PCI); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 171 | |
Eric Biederman | 5268557 | 2003-05-19 19:16:21 +0000 | [diff] [blame] | 172 | /* pick how to scan the bus. This is first so we can get at memory size. */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 173 | printk_info("Finding PCI configuration type.\n"); |
| 174 | pci_set_method(); |
| 175 | post_code(0x5f); |
| 176 | #if 0 |
| 177 | enumerate_static_devices(); |
| 178 | #endif |
| 179 | dev_enumerate(); |
| 180 | post_code(0x66); |
Eric Biederman | 5268557 | 2003-05-19 19:16:21 +0000 | [diff] [blame] | 181 | /* Now do the real bus. |
| 182 | * We round the total ram up a lot for thing like the SISFB, which |
| 183 | * shares high memory with the CPU. |
| 184 | */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 185 | dev_configure(); |
| 186 | post_code(0x88); |
| 187 | |
| 188 | dev_enable(); |
Eric Biederman | 5268557 | 2003-05-19 19:16:21 +0000 | [diff] [blame] | 189 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 190 | dev_initialize(); |
| 191 | post_code(0x89); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 192 | |
Greg Watson | 5bed979 | 2003-07-23 21:38:02 +0000 | [diff] [blame] | 193 | CONFIGURE(CONF_PASS_POST_PCI); |
| 194 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 195 | mem = get_ramsize(); |
| 196 | post_code(0x70); |
| 197 | totalmem = 0; |
| 198 | for(tmem = mem; tmem->sizek; tmem++) { |
| 199 | totalmem += tmem->sizek; |
| 200 | } |
| 201 | printk_info("totalram: %ldM\n", |
| 202 | (totalmem + 512) >> 10); /* Round to the nearest meg */ |
| 203 | |
| 204 | /* Fully initialize the cpu before configuring the bus */ |
| 205 | boot_cpu = cpu_initialize(mem); |
| 206 | boot_index = processor_index(boot_cpu); |
| 207 | printk_spew("BOOT CPU is %d\n", boot_cpu); |
| 208 | processor_map[boot_index] = CPU_BOOTPROCESSOR|CPU_ENABLED; |
| 209 | |
| 210 | /* Now start the other cpus initializing |
| 211 | * The sooner they start the sooner they stop. |
| 212 | */ |
| 213 | post_code(0x75); |
| 214 | startup_other_cpus(processor_map); |
| 215 | post_code(0x77); |
| 216 | |
| 217 | /* make certain we are the only cpu running in linuxBIOS */ |
| 218 | wait_for_other_cpus(); |
| 219 | |
| 220 | /* Now that we have collected all of our information |
| 221 | * write our configuration tables. |
| 222 | */ |
| 223 | lb_mem = write_tables(mem, processor_map); |
| 224 | |
Greg Watson | 5bed979 | 2003-07-23 21:38:02 +0000 | [diff] [blame] | 225 | CONFIGURE(CONF_PASS_PRE_BOOT); |
Greg Watson | 2910a2b | 2003-07-23 18:20:17 +0000 | [diff] [blame] | 226 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 227 | elfboot(lb_mem); |
| 228 | } |
| 229 | |