00001 /* 00002 * Copyright (C) 2001-2004 Jakub Jermar 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions 00007 * are met: 00008 * 00009 * - Redistributions of source code must retain the above copyright 00010 * notice, this list of conditions and the following disclaimer. 00011 * - Redistributions in binary form must reproduce the above copyright 00012 * notice, this list of conditions and the following disclaimer in the 00013 * documentation and/or other materials provided with the distribution. 00014 * - The name of the author may not be used to endorse or promote products 00015 * derived from this software without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 00018 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00019 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00020 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 00021 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 00022 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00023 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00024 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00025 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 00026 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00027 */ 00028 00038 #include <cpu.h> 00039 #include <arch.h> 00040 #include <arch/cpu.h> 00041 #include <mm/slab.h> 00042 #include <mm/page.h> 00043 #include <mm/frame.h> 00044 #include <arch/types.h> 00045 #include <config.h> 00046 #include <panic.h> 00047 #include <typedefs.h> 00048 #include <memstr.h> 00049 #include <adt/list.h> 00050 #include <print.h> 00051 00052 cpu_t *cpus; 00053 00059 void cpu_init(void) { 00060 int i, j; 00061 00062 #ifdef CONFIG_SMP 00063 if (config.cpu_active == 1) { 00064 #endif /* CONFIG_SMP */ 00065 cpus = (cpu_t *) malloc(sizeof(cpu_t) * config.cpu_count, 00066 FRAME_ATOMIC); 00067 if (!cpus) 00068 panic("malloc/cpus"); 00069 00070 /* initialize everything */ 00071 memsetb((__address) cpus, sizeof(cpu_t) * config.cpu_count, 0); 00072 00073 for (i=0; i < config.cpu_count; i++) { 00074 cpus[i].stack = (__u8 *) PA2KA(PFN2ADDR(frame_alloc(STACK_FRAMES, FRAME_KA | FRAME_PANIC))); 00075 00076 cpus[i].id = i; 00077 00078 spinlock_initialize(&cpus[i].lock, "cpu_t.lock"); 00079 00080 for (j = 0; j < RQ_COUNT; j++) { 00081 spinlock_initialize(&cpus[i].rq[j].lock, "rq_t.lock"); 00082 list_initialize(&cpus[i].rq[j].rq_head); 00083 } 00084 } 00085 00086 #ifdef CONFIG_SMP 00087 } 00088 #endif /* CONFIG_SMP */ 00089 00090 CPU = &cpus[config.cpu_active-1]; 00091 00092 CPU->active = 1; 00093 CPU->tlb_active = 1; 00094 00095 cpu_identify(); 00096 cpu_arch_init(); 00097 } 00098 00100 void cpu_list(void) 00101 { 00102 int i; 00103 00104 for (i = 0; i < config.cpu_count; i++) { 00105 if (cpus[i].active) 00106 cpu_print_report(&cpus[i]); 00107 else 00108 printf("cpu%d: not active\n", i); 00109 } 00110 } 00111