frame.c

Go to the documentation of this file.
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 
00036 #include <mm/frame.h>
00037 #include <arch/mm/frame.h>
00038 #include <mm/as.h>
00039 #include <config.h>
00040 #include <arch/boot/boot.h>
00041 #include <arch/boot/memmap.h>
00042 #include <panic.h>
00043 #include <debug.h>
00044 #include <align.h>
00045 #include <macros.h>
00046 
00047 #include <print.h>
00048 #include <console/cmd.h>
00049 #include <console/kconsole.h>
00050 
00051 size_t hardcoded_unmapped_ktext_size = 0;
00052 size_t hardcoded_unmapped_kdata_size = 0;
00053 
00054 __address last_frame = 0;
00055 
00056 static void init_e820_memory(pfn_t minconf)
00057 {
00058         int i;
00059         pfn_t start, conf;
00060         size_t size;
00061 
00062         for (i = 0; i < e820counter; i++) {
00063                 if (e820table[i].type == MEMMAP_MEMORY_AVAILABLE) {
00064                         start = ADDR2PFN(ALIGN_UP(e820table[i].base_address,
00065                                                   FRAME_SIZE));
00066                         size = SIZE2FRAMES(ALIGN_DOWN(e820table[i].size,
00067                                                    FRAME_SIZE));
00068                         if (minconf < start || minconf >= start+size)
00069                                 conf = start;
00070                         else
00071                                 conf = minconf;
00072                         zone_create(start, size, conf, 0);
00073                         if (last_frame < ALIGN_UP(e820table[i].base_address + e820table[i].size, FRAME_SIZE))
00074                                 last_frame = ALIGN_UP(e820table[i].base_address + e820table[i].size, FRAME_SIZE);
00075                 }                       
00076         }
00077 }
00078 
00079 static int cmd_e820mem(cmd_arg_t *argv);
00080 static cmd_info_t e820_info = {
00081         .name = "e820list",
00082         .description = "List e820 memory.",
00083         .func = cmd_e820mem,
00084         .argc = 0
00085 };
00086 
00087 static char *e820names[] = { "invalid", "available", "reserved",
00088                              "acpi", "nvs", "unusable" };
00089 
00090 
00091 static int cmd_e820mem(cmd_arg_t *argv)
00092 {
00093         int i;
00094         char *name;
00095 
00096         for (i = 0; i < e820counter; i++) {
00097                 if (e820table[i].type <= MEMMAP_MEMORY_UNUSABLE)
00098                         name = e820names[e820table[i].type];
00099                 else
00100                         name = "invalid";
00101                 printf("%.*p %#.16llXB %s\n", 
00102                         sizeof(__native) * 2,
00103                        (__native) e820table[i].base_address, 
00104                        (__u64) e820table[i].size,
00105                        name);
00106         }                       
00107         return 0;
00108 }
00109 
00110 
00111 void frame_arch_init(void)
00112 {
00113         static pfn_t minconf;
00114 
00115         if (config.cpu_active == 1) {
00116                 cmd_initialize(&e820_info);
00117                 cmd_register(&e820_info);
00118 
00119 
00120                 minconf = 1;
00121 #ifdef CONFIG_SMP
00122                 minconf = max(minconf,
00123                               ADDR2PFN(AP_BOOT_OFFSET+hardcoded_unmapped_ktext_size + hardcoded_unmapped_kdata_size));
00124 #endif
00125 #ifdef CONFIG_SIMICS_FIX
00126                 minconf = max(minconf, ADDR2PFN(0x10000));
00127 #endif
00128                 init_e820_memory(minconf);
00129 
00130                 /* Reserve frame 0 (BIOS data) */
00131                 frame_mark_unavailable(0, 1);
00132                 
00133 #ifdef CONFIG_SMP
00134                 /* Reserve AP real mode bootstrap memory */
00135                 frame_mark_unavailable(AP_BOOT_OFFSET >> FRAME_WIDTH, 
00136                                        (hardcoded_unmapped_ktext_size + hardcoded_unmapped_kdata_size) >> FRAME_WIDTH);
00137                 
00138 #ifdef CONFIG_SIMICS_FIX
00139                 /* Don't know why, but this addresses help */
00140                 frame_mark_unavailable(0xd000 >> FRAME_WIDTH,3);
00141 #endif
00142 #endif
00143         }
00144 }
00145 

Generated on Sun Jun 18 16:38:51 2006 for HelenOS Kernel (ia32) by  doxygen 1.4.6