root/arch/mips/mm/init.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. __bad_pagetable
  2. __bad_page
  3. __zero_page
  4. show_mem
  5. paging_init
  6. mem_init
  7. si_meminfo

   1 /*
   2  *  arch/mips/mm/init.c
   3  *
   4  *  Copyright (C) 1991, 1992, 1993, 1994  Linus Torvalds
   5  *  Ported to MIPS by Ralf Baechle
   6  */
   7 
   8 #include <linux/config.h>
   9 #include <linux/signal.h>
  10 #include <linux/sched.h>
  11 #include <linux/head.h>
  12 #include <linux/kernel.h>
  13 #include <linux/errno.h>
  14 #include <linux/string.h>
  15 #include <linux/types.h>
  16 #include <linux/ptrace.h>
  17 #include <linux/mman.h>
  18 #include <linux/mm.h>
  19 
  20 #include <asm/system.h>
  21 #include <asm/segment.h>
  22 #include <asm/mipsconfig.h>
  23 
  24 extern unsigned long pg0[1024];         /* page table for 0-4MB for everybody */
  25 
  26 extern void scsi_mem_init(unsigned long);
  27 extern void sound_mem_init(void);
  28 extern void die_if_kernel(char *,struct pt_regs *,long);
  29 extern void show_net_buffers(void);
  30 
  31 /*
  32  * BAD_PAGE is the page that is used for page faults when linux
  33  * is out-of-memory. Older versions of linux just did a
  34  * do_exit(), but using this instead means there is less risk
  35  * for a process dying in kernel mode, possibly leaving a inode
  36  * unused etc..
  37  *
  38  * BAD_PAGETABLE is the accompanying page-table: it is initialized
  39  * to point to BAD_PAGE entries.
  40  *
  41  * ZERO_PAGE is a special page that is used for zero-initialized
  42  * data and COW.
  43  */
  44 unsigned long __bad_pagetable(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  45 {
  46         extern char empty_bad_page_table[PAGE_SIZE];
  47         unsigned long dummy;
  48 
  49         __asm__ __volatile__(
  50                 ".set\tnoreorder\n\t"
  51                 "1:\tsw\t%2,(%0)\n\t"
  52                 "subu\t%1,%1,1\n\t"
  53                 "bne\t$0,%1,1b\n\t"
  54                 "addiu\t%0,%0,1\n\t"
  55                 ".set\treorder"
  56                 :"=r" (dummy),
  57                  "=r" (dummy)
  58                 :"r" (BAD_PAGE + PAGE_TABLE),
  59                  "0" ((long) empty_bad_page_table),
  60                  "1" (PTRS_PER_PAGE));
  61 
  62         return (unsigned long) empty_bad_page_table;
  63 }
  64 
  65 unsigned long __bad_page(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  66 {
  67         extern char empty_bad_page[PAGE_SIZE];
  68         unsigned long dummy;
  69 
  70         __asm__ __volatile__(
  71                 ".set\tnoreorder\n\t"
  72                 "1:\tsw\t$0,(%0)\n\t"
  73                 "subu\t%1,%1,1\n\t"
  74                 "bne\t$0,%1,1b\n\t"
  75                 "addiu\t%0,%0,1\n\t"
  76                 ".set\treorder"
  77                 :"=r" (dummy),
  78                  "=r" (dummy)
  79                 :"0" ((long) empty_bad_page),
  80                  "1" (PTRS_PER_PAGE));
  81 
  82         return (unsigned long) empty_bad_page;
  83 }
  84 
  85 unsigned long __zero_page(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  86 {
  87         extern char empty_zero_page[PAGE_SIZE];
  88         unsigned long dummy;
  89 
  90         __asm__ __volatile__(
  91                 ".set\tnoreorder\n\t"
  92                 "1:\tsw\t$0,(%0)\n\t"
  93                 "subu\t%1,%1,1\n\t"
  94                 "bne\t$0,%1,1b\n\t"
  95                 "addiu\t%0,%0,1\n\t"
  96                 ".set\treorder"
  97                 :"=r" (dummy),
  98                  "=r" (dummy)
  99                 :"0" ((long) empty_zero_page),
 100                  "1" (PTRS_PER_PAGE));
 101 
 102         return (unsigned long) empty_zero_page;
 103 }
 104 
 105 void show_mem(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 106 {
 107         int i,free = 0,total = 0,reserved = 0;
 108         int shared = 0;
 109 
 110         printk("Mem-info:\n");
 111         show_free_areas();
 112         printk("Free swap:       %6dkB\n",nr_swap_pages<<(PAGE_SHIFT-10));
 113         i = high_memory >> PAGE_SHIFT;
 114         while (i-- > 0) {
 115                 total++;
 116                 if (mem_map[i] & MAP_PAGE_RESERVED)
 117                         reserved++;
 118                 else if (!mem_map[i])
 119                         free++;
 120                 else
 121                         shared += mem_map[i]-1;
 122         }
 123         printk("%d pages of RAM\n",total);
 124         printk("%d free pages\n",free);
 125         printk("%d reserved pages\n",reserved);
 126         printk("%d pages shared\n",shared);
 127         show_buffers();
 128 #ifdef CONFIG_NET
 129         show_net_buffers();
 130 #endif
 131 }
 132 
 133 extern unsigned long free_area_init(unsigned long, unsigned long);
 134 
 135 /*
 136  * paging_init() sets up the page tables - note that the first 4MB are
 137  * already mapped by head.S.
 138  *
 139  * This routines also unmaps the page at virtual kernel address 0, so
 140  * that we can trap those pesky NULL-reference errors in the kernel.
 141  */
 142 unsigned long paging_init(unsigned long start_mem, unsigned long end_mem)
     /* [previous][next][first][last][top][bottom][index][help] */
 143 {
 144         unsigned long * pg_dir;
 145         unsigned long * pg_table;
 146         unsigned long tmp;
 147         unsigned long address;
 148 
 149         start_mem = PAGE_ALIGN(start_mem);
 150         address = 0;
 151         pg_dir = swapper_pg_dir;
 152         while (address < end_mem) {
 153                 tmp = *pg_dir;
 154                 tmp &= PAGE_MASK;
 155                 if (!tmp) {
 156                         tmp = start_mem;
 157                         start_mem += PAGE_SIZE;
 158                 }
 159                 /*
 160                  * also map it in at 0x00000000 for init
 161                  */
 162                 *pg_dir = tmp | PAGE_TABLE;
 163                 pg_dir++;
 164                 pg_table = (unsigned long *) (tmp & PAGE_MASK);
 165                 for (tmp = 0 ; tmp < PTRS_PER_PAGE ; tmp++,pg_table++) {
 166                         if (address < end_mem)
 167                                 *pg_table = address | PAGE_SHARED;
 168                         else
 169                                 *pg_table = 0;
 170                         address += PAGE_SIZE;
 171                 }
 172         }
 173 #if KERNELBASE == KSEG0
 174         cacheflush();
 175 #endif
 176         invalidate();
 177         return free_area_init(start_mem, end_mem);
 178 }
 179 
 180 void mem_init(unsigned long start_mem, unsigned long end_mem)
     /* [previous][next][first][last][top][bottom][index][help] */
 181 {
 182         int codepages = 0;
 183         int reservedpages = 0;
 184         int datapages = 0;
 185         unsigned long tmp;
 186         extern int etext;
 187 
 188         end_mem &= PAGE_MASK;
 189         high_memory = end_mem;
 190 
 191         /* mark usable pages in the mem_map[] */
 192         start_mem = PAGE_ALIGN(start_mem);
 193 
 194         while (start_mem < high_memory) {
 195                 mem_map[MAP_NR(start_mem)] = 0;
 196                 start_mem += PAGE_SIZE;
 197         }
 198 #ifdef CONFIG_SCSI
 199         scsi_mem_init(high_memory);
 200 #endif
 201 #ifdef CONFIG_SOUND
 202         sound_mem_init();
 203 #endif
 204         for (tmp = 0 ; tmp < high_memory ; tmp += PAGE_SIZE) {
 205                 if (mem_map[MAP_NR(tmp)]) {
 206                         /*
 207                          * We don't have any reserved pages on the
 208                          * MIPS systems supported until now
 209                          */
 210                         if (0)
 211                                 reservedpages++;
 212                         else if (tmp < ((unsigned long) &etext - KERNELBASE))
 213                                 codepages++;
 214                         else
 215                                 datapages++;
 216                         continue;
 217                 }
 218                 mem_map[MAP_NR(tmp)] = 1;
 219                 free_page(tmp);
 220         }
 221         tmp = nr_free_pages << PAGE_SHIFT;
 222         printk("Memory: %luk/%luk available (%dk kernel code, %dk reserved, %dk data)\n",
 223                 tmp >> 10,
 224                 high_memory >> 10,
 225                 codepages << (PAGE_SHIFT-10),
 226                 reservedpages << (PAGE_SHIFT-10),
 227                 datapages << (PAGE_SHIFT-10));
 228 
 229         invalidate();
 230         return;
 231 }
 232 
 233 void si_meminfo(struct sysinfo *val)
     /* [previous][next][first][last][top][bottom][index][help] */
 234 {
 235         int i;
 236 
 237         i = high_memory >> PAGE_SHIFT;
 238         val->totalram = 0;
 239         val->sharedram = 0;
 240         val->freeram = nr_free_pages << PAGE_SHIFT;
 241         val->bufferram = buffermem;
 242         while (i-- > 0)  {
 243                 if (mem_map[i] & MAP_PAGE_RESERVED)
 244                         continue;
 245                 val->totalram++;
 246                 if (!mem_map[i])
 247                         continue;
 248                 val->sharedram += mem_map[i]-1;
 249         }
 250         val->totalram <<= PAGE_SHIFT;
 251         val->sharedram <<= PAGE_SHIFT;
 252         return;
 253 }

/* [previous][next][first][last][top][bottom][index][help] */