Main Page | Directories | File List | Globals

memory.c File Reference

#include <agnix/agnix.h>
#include <agnix/init.h>
#include <asm/bios_parametrs.h>
#include <agnix/memory.h>
#include <asm/memtests.h>
#include <agnix/console.h>

Include dependency graph for memory.c:

Go to the source code of this file.

Defines

#define MOD_NAME   "BOOTM: "
#define mem_block_size(mem_block, i)   mem_block->entries[i].size
#define mem_block_start(mem_block, i)   mem_block->entries[i].start
#define mem_block_end(mem_block, i)   mem_block->entries[i].start + mem_block->entries[i].size
#define mem_block_type(mem_block, i)   mem_block->entries[i].type

Functions

int page_tables_init (struct main_memory_s *mem)
void __init modify_memory_entry (struct memory_block_s *mem_block, unsigned long long start, unsigned long long size, unsigned long type, int block_nr)
void __init add_memory_entry (struct memory_block_s *mem_block, struct e820_entry_s *entry)
unsigned long __init parse_biosmap (struct e820_entry_s *biosentry, char map_nr)
void print_memory_map (struct main_memory_s *memory, int broadcast)
void bootmem_free_ram (void)
int __init bootmem_init_bh (void)
int __init bootmem_init_dh (void)
int bootmem_free_init (void)
void bootmem_print_memory (void)

Variables

main_memory_s main_memory
memory_block_s main_block
bin_allocator_s bin_alloc
u32 swapper_pg_dir [1024]
char __init_begin
char __init_end


Define Documentation

#define mem_block_end mem_block,
 )     mem_block->entries[i].start + mem_block->entries[i].size
 

Definition at line 53 of file memory.c.

Referenced by parse_biosmap().

#define mem_block_size mem_block,
 )     mem_block->entries[i].size
 

Definition at line 47 of file memory.c.

Referenced by parse_biosmap().

#define mem_block_start mem_block,
 )     mem_block->entries[i].start
 

Definition at line 50 of file memory.c.

Referenced by parse_biosmap().

#define mem_block_type mem_block,
 )     mem_block->entries[i].type
 

Definition at line 56 of file memory.c.

Referenced by parse_biosmap().

#define MOD_NAME   "BOOTM: "
 

Definition at line 21 of file memory.c.


Function Documentation

void __init add_memory_entry struct memory_block_s *  mem_block,
struct e820_entry_s *  entry
 

Definition at line 39 of file memory.c.

References memcpy().

Referenced by parse_biosmap().

00040 {
00041     int block_nr = mem_block->mem_nr;
00042 
00043     memcpy(&mem_block->entries[block_nr], entry, sizeof(struct e820_entry_s));
00044     mem_block->mem_nr++;
00045 }

Here is the call graph for this function:

int bootmem_free_init void   ) 
 

Definition at line 208 of file memory.c.

References __init_begin, __init_end, init_start(), and printk().

Referenced by clean_kernel().

00209 {
00210     u32 init_start = (u32)&__init_begin;
00211     u32 init_end = (u32)&__init_end;
00212 
00213     printk("Freeing __init segment (%d kb)\n", (init_end - init_start) >> 10);
00214         
00215     return 0;
00216 }

Here is the call graph for this function:

void bootmem_free_ram void   ) 
 

Definition at line 162 of file memory.c.

References bin_alloc, bin_free_pages(), and main_block.

Referenced by bootmem_init_dh().

00163 {
00164     int i;
00165 
00166     for (i = 0; i < main_block.mem_nr; i++) {
00167     
00168         if (main_block.entries[i].size == 0)
00169             continue;
00170     
00171         if (main_block.entries[i].type == E820_RAM) {
00172             bin_free_pages(&bin_alloc, (unsigned long)(main_block.entries[i].start) >> PAGE_SHIFT, (unsigned long)(main_block.entries[i].size) >> PAGE_SHIFT);
00173         }
00174     }
00175 }

Here is the call graph for this function:

int __init bootmem_init_bh void   ) 
 

Definition at line 177 of file memory.c.

References main_block, main_memory, memset(), parse_biosmap(), and swapper_pg_dir.

Referenced by memalloc_init().

00178 {
00179     memset(&main_memory, 0, sizeof(main_memory));
00180     memset(&main_block, 0, sizeof(main_block));
00181     INIT_LIST_HEAD(&main_memory.list);
00182     INIT_LIST_HEAD(&main_block.list);
00183     list_add(&main_block.list, &main_memory.list);
00184 
00185     main_memory.mem_size = parse_biosmap(E820_MAP, E820_MAP_NR) >> 10;
00186     main_memory.pdbr     = (u32)swapper_pg_dir;
00187 
00188     return 0;
00189 }

Here is the call graph for this function:

int __init bootmem_init_dh void   ) 
 

Definition at line 191 of file memory.c.

References bin_reserve_system_pages(), bootmem_free_ram(), do_memtests(), main_memory, page_tables_init(), and print_memory_map().

Referenced by memalloc_init().

00192 {
00193     bootmem_free_ram();
00194     bin_reserve_system_pages();
00195     print_memory_map(&main_memory, 1);
00196 
00197     page_tables_init(&main_memory);
00198 
00199 #if CONFIG_MEMTESTS
00200     if (do_memtests() < 0) {
00201         return -1;
00202     }
00203 #endif
00204 
00205     return 0;
00206 }

Here is the call graph for this function:

void bootmem_print_memory void   ) 
 

Definition at line 218 of file memory.c.

References main_memory, and print_memory_map().

Referenced by agnix_console_print_memory().

00219 {
00220     print_memory_map(&main_memory, 0);
00221 }

Here is the call graph for this function:

void __init modify_memory_entry struct memory_block_s *  mem_block,
unsigned long long  start,
unsigned long long  size,
unsigned long  type,
int  block_nr
 

Definition at line 31 of file memory.c.

00033 {
00034     mem_block->entries[block_nr].start = start;
00035     mem_block->entries[block_nr].size  = size;
00036     mem_block->entries[block_nr].type  = type;
00037 }

int page_tables_init struct main_memory_s *  mem  ) 
 

Definition at line 53 of file pgmap.c.

References MOD_NAME, printk(), and pte_ptr().

Referenced by bootmem_init_dh().

00054 {
00055     struct pde_s *pde;
00056     struct pte_s *pte;
00057     u32    page_start;
00058     u32    page_end;
00059     u32    page_len;
00060     u32    page_count;
00061     int    i, j;
00062 
00063 #if DEBUG_MEM    
00064     printk(MOD_NAME "Initializing page tables\n");
00065 #endif
00066 
00067     page_count = 0;
00068     page_start = 0;
00069     page_end   = (mem->mem_size) >> 2; // KB >> 2 == pages 
00070     page_len = page_end - page_start;
00071 
00072     pde = (struct pde_s *)mem->pdbr;
00073     pde += pde_offset(PAGE_OFFSET);
00074 
00075 #if DEBUG_MEM
00076     printk(MOD_NAME "page count = %d\n", page_len);
00077 #endif
00078 
00079     __cli();
00080 
00081 //    write_cr4(read_cr4() | 0x10);
00082 
00083     for (i = pde_offset(PAGE_OFFSET); i < PDE_PER_PD; i++) {
00084 
00085 //      pde->pte_addr = (page_count << PAGE_SHIFT);     
00086 //      set_pde(pde, make_pde_phys(pde->pte_addr, PDE_FLAG_P | PDE_FLAG_RW | PDE_FLAG_PS));
00087 //      pde++;
00088 //      page_count += 1024;
00089 //    
00090         pte = pte_ptr(pde);
00091         for (j = 0; j < PTE_PER_PT; j++) {
00092 
00093             set_pte(pte, make_pte_phys(page_count << PAGE_SHIFT, (PTE_FLAG_P | PTE_FLAG_RW | PTE_FLAG_A | PTE_FLAG_D)));                
00094 
00095             if (++page_count >= page_len)
00096                 break;
00097 
00098             pte++;
00099         }
00100         
00101         if (page_count >= page_len)
00102             break;
00103         
00104         pde++;
00105     }
00106 
00107 
00108 #if DEBUG_MEM
00109     printk(MOD_NAME "Loading cr3 (phys_addr=%x) ... ", virt_to_phys(mem->pdbr));
00110 #endif
00111 
00112     load_cr3(mem->pdbr);
00113     
00114 #if DEBUG_MEM
00115     printk("ok\n");
00116 #endif
00117 
00118     return 0;
00119 }

Here is the call graph for this function:

unsigned long __init parse_biosmap struct e820_entry_s *  biosentry,
char  map_nr
 

Definition at line 59 of file memory.c.

References add_memory_entry(), main_block, mem_block_end, mem_block_size, mem_block_start, mem_block_type, and memcpy().

Referenced by bootmem_init_bh().

00060 {
00061     struct e820_entry_s *bios_entry  = biosentry;
00062     struct e820_entry_s bios_entry_tmp;
00063     struct memory_block_s *mem_block = &main_block;
00064     unsigned long max_ram_addr  = 0;
00065     int           max_entry;
00066     unsigned long max_addr;
00067     unsigned long prev_max_addr = -1;
00068     int           i;
00069     int           map_count = (int)map_nr;
00070 
00071     do {
00072         max_entry = -1;
00073         max_addr  = -1;
00074         for (i = 0; i < map_nr; i++) {
00075             if (((prev_max_addr == -1) || (bios_entry[i].start > prev_max_addr)) && (bios_entry[i].start < max_addr)) {
00076                 max_entry = i;
00077                 max_addr = bios_entry[i].start;
00078             }   
00079         }
00080         if (max_entry == -1) break;
00081     
00082         prev_max_addr = max_addr;
00083         
00084         memcpy(&bios_entry_tmp, &bios_entry[max_entry], sizeof(bios_entry_tmp));
00085 
00086         for (i = 0; i < mem_block->mem_nr; i++) {
00087             if (bios_entry_tmp.start < mem_block_end(mem_block, i)) {
00088                 if (bios_entry_tmp.type > mem_block_type(mem_block, i)) {
00089                     mem_block_size(mem_block, i) = mem_block_start(mem_block, i) - 
00090                                                bios_entry_tmp.start;
00091                 } else {
00092                     bios_entry_tmp.start = mem_block_end(mem_block, i);
00093                 }
00094             }
00095         }
00096 
00097         add_memory_entry(mem_block, &bios_entry_tmp);
00098         if (bios_entry_tmp.type == E820_RAM) { 
00099             if (max_ram_addr < bios_entry_tmp.start + bios_entry_tmp.size)
00100                 max_ram_addr = bios_entry_tmp.start + bios_entry_tmp.size;
00101         }
00102                 
00103         map_count--;
00104     } while(map_count);
00105 
00106     return max_ram_addr;
00107 }

Here is the call graph for this function:

void print_memory_map struct main_memory_s *  memory,
int  broadcast
 

Definition at line 109 of file memory.c.

References main_block, MOD_NAME, printf(), and printk().

Referenced by bootmem_init_dh(), and bootmem_print_memory().

00110 {
00111     int i;
00112     char *e820_name;
00113     
00114     if (broadcast) {
00115         printk("\n");
00116         printk(MOD_NAME "Memory size = %dKB\n", (unsigned long)(memory->mem_size));
00117         printk(MOD_NAME "Memory map (BIOS):\n");
00118     } else {
00119         printf("\n");
00120         printf(MOD_NAME "Memory size = %dKB\n", (unsigned long)(memory->mem_size));
00121         printf(MOD_NAME "Memory map (BIOS):\n");
00122     }
00123     
00124     for (i = 0; i < main_block.mem_nr; i++) {
00125     
00126         if (main_block.entries[i].size == 0)
00127             continue;
00128     
00129         switch (main_block.entries[i].type) {
00130         
00131             case E820_RAM:
00132                 e820_name = "(RAM)     ";
00133                 break;
00134             case E820_RESERVED:
00135                 e820_name = "(RESERVED)";
00136                 break;
00137             case E820_ACPI:
00138                 e820_name = "(ACPI)    ";
00139                 break;
00140             case E820_NVS:
00141                 e820_name = "(NVS)     ";
00142                 break;
00143             default:
00144                 e820_name = "(UNKNOWN) ";
00145         }
00146         
00147         if (broadcast) {
00148             printk("\t%s %08x-%08x\n", e820_name, (unsigned long)main_block.entries[i].start, 
00149                    (unsigned long)(main_block.entries[i].start + main_block.entries[i].size));
00150         } else {
00151             printf("\t%s %08x-%08x\n", e820_name, (unsigned long)main_block.entries[i].start, 
00152                    (unsigned long)(main_block.entries[i].start + main_block.entries[i].size));
00153         }
00154     }
00155 
00156     if (broadcast)
00157         printk("\n");    
00158     else
00159         printf("\n");    
00160 }

Here is the call graph for this function:


Variable Documentation

char __init_begin
 

Referenced by bootmem_free_init().

char __init_end
 

Referenced by bootmem_free_init().

struct bin_allocator_s bin_alloc
 

Definition at line 27 of file bin_alloc.c.

Referenced by bin_alloc_init(), bin_get_free_pages(), bin_put_all_free_pages(), bin_put_free_pages(), bin_reserve_system_pages(), and bootmem_free_ram().

struct memory_block_s main_block
 

Definition at line 24 of file memory.c.

Referenced by bootmem_free_ram(), bootmem_init_bh(), parse_biosmap(), and print_memory_map().

struct main_memory_s main_memory
 

Definition at line 23 of file memory.c.

Referenced by bootmem_init_bh(), bootmem_init_dh(), bootmem_print_memory(), do_memtests(), memalloc_init(), remap_kpage_tables(), task_fork(), and task_kernel_create().

u32 swapper_pg_dir[1024]
 

Referenced by bootmem_init_bh().

Dokumentacje wygenerowano programem Doxygen 1.4.2 dla projektu Agnix