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

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