root/arch/sparc/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  *  linux/arch/sparc/mm/init.c
   3  *
   4  *  Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
   5  */
   6 
   7 #include <linux/config.h>
   8 #include <linux/signal.h>
   9 #include <linux/sched.h>
  10 #include <linux/head.h>
  11 #include <linux/kernel.h>
  12 #include <linux/errno.h>
  13 #include <linux/string.h>
  14 #include <linux/types.h>
  15 #include <linux/ptrace.h>
  16 #include <linux/mman.h>
  17 #include <linux/mm.h>
  18 
  19 #include <asm/system.h>
  20 #include <asm/segment.h>
  21 #include <asm/vac-ops.h>
  22 #include <asm/page.h>
  23 #include <asm/pgtable.h>
  24 #include <asm/vaddrs.h>
  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 struct sparc_phys_banks sp_banks[SPARC_PHYS_BANKS];
  32 
  33 /* The following number keeps track of which page table is to
  34  * next be allocated in a page.  This is necessary since there
  35  * are 16 page tables per page on the space.
  36  */
  37 unsigned long ptr_in_current_pgd;
  38 
  39 /* This keeps track of which physical segments are in use right now. */
  40 unsigned int phys_seg_map[PSEG_ENTRIES];
  41 unsigned int phys_seg_life[PSEG_ENTRIES];
  42 
  43 /* Context allocation. */
  44 struct task_struct *ctx_tasks[MAX_CTXS];
  45 int ctx_tasks_last_frd;
  46 
  47 extern int invalid_segment, num_segmaps, num_contexts;
  48 
  49 /*
  50  * BAD_PAGE is the page that is used for page faults when linux
  51  * is out-of-memory. Older versions of linux just did a
  52  * do_exit(), but using this instead means there is less risk
  53  * for a process dying in kernel mode, possibly leaving a inode
  54  * unused etc..
  55  *
  56  * BAD_PAGETABLE is the accompanying page-table: it is initialized
  57  * to point to BAD_PAGE entries.
  58  *
  59  * ZERO_PAGE is a special page that is used for zero-initialized
  60  * data and COW.
  61  */
  62 pte_t *__bad_pagetable(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  63 {
  64         memset((void *) EMPTY_PGT, 0, PAGE_SIZE);
  65         return (pte_t *) EMPTY_PGT;
  66 }
  67 
  68 pte_t __bad_page(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  69 {
  70         memset((void *) EMPTY_PGE, 0, PAGE_SIZE);
  71         return pte_mkdirty(mk_pte((unsigned long) EMPTY_PGE, PAGE_SHARED));
  72 }
  73 
  74 unsigned long __zero_page(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  75 {
  76         memset((void *) ZERO_PGE, 0, PAGE_SIZE);
  77         return (unsigned long) ZERO_PGE;
  78 }
  79 
  80 void show_mem(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  81 {
  82         int i,free = 0,total = 0,reserved = 0;
  83         int shared = 0;
  84 
  85         printk("Mem-info:\n");
  86         show_free_areas();
  87         printk("Free swap:       %6dkB\n",nr_swap_pages<<(PAGE_SHIFT-10));
  88         i = high_memory >> PAGE_SHIFT;
  89         while (i-- > 0) {
  90                 total++;
  91                 if (mem_map[i] & MAP_PAGE_RESERVED)
  92                         reserved++;
  93                 else if (!mem_map[i])
  94                         free++;
  95                 else
  96                         shared += mem_map[i]-1;
  97         }
  98         printk("%d pages of RAM\n",total);
  99         printk("%d free pages\n",free);
 100         printk("%d reserved pages\n",reserved);
 101         printk("%d pages shared\n",shared);
 102         show_buffers();
 103 #ifdef CONFIG_NET
 104         show_net_buffers();
 105 #endif
 106 }
 107 
 108 extern unsigned long free_area_init(unsigned long, unsigned long);
 109 extern pgprot_t protection_map[16];
 110 
 111 /*
 112  * paging_init() sets up the page tables: We call the MMU specific
 113  * init routine based upon the Sun model type on the Sparc.
 114  *
 115  */
 116 extern unsigned long sun4c_paging_init(unsigned long, unsigned long);
 117 extern unsigned long srmmu_paging_init(unsigned long, unsigned long);
 118 extern unsigned long probe_devices(unsigned long);
 119 
 120 unsigned long paging_init(unsigned long start_mem, unsigned long end_mem)
     /* [previous][next][first][last][top][bottom][index][help] */
 121 {
 122         int i;
 123 
 124         switch(sparc_cpu_model) {
 125         case sun4c:
 126                 start_mem = sun4c_paging_init(start_mem, end_mem);
 127                 break;
 128         case sun4m:
 129         case sun4d:
 130         case sun4e:
 131                 start_mem = srmmu_paging_init(start_mem, end_mem);
 132                 break;
 133         default:
 134                 printk("paging_init: Cannot init paging on this Sparc\n");
 135                 printk("paging_init: sparc_cpu_model = %d\n", sparc_cpu_model);
 136                 printk("paging_init: Halting...\n");
 137                 halt();
 138         };
 139 
 140         /* Initialize context map. */
 141         for(i=0; i<MAX_CTXS; i++) ctx_tasks[i] = NULL;
 142 
 143         /* Initialize the protection map */
 144         protection_map[0] = __P000;
 145         protection_map[1] = __P001;
 146         protection_map[2] = __P010;
 147         protection_map[3] = __P011;
 148         protection_map[4] = __P100;
 149         protection_map[5] = __P101;
 150         protection_map[6] = __P110;
 151         protection_map[7] = __P111;
 152         protection_map[8] = __S000;
 153         protection_map[9] = __S001;
 154         protection_map[10] = __S010;
 155         protection_map[11] = __S011;
 156         protection_map[12] = __S100;
 157         protection_map[13] = __S101;
 158         protection_map[14] = __S110;
 159         protection_map[15] = __S111;
 160 
 161         start_mem = probe_devices(start_mem);
 162 
 163         return start_mem;
 164 }
 165 
 166 extern unsigned long sun4c_test_wp(unsigned long);
 167 extern void srmmu_test_wp(void);
 168 
 169 void mem_init(unsigned long start_mem, unsigned long end_mem)
     /* [previous][next][first][last][top][bottom][index][help] */
 170 {
 171         int codepages = 0;
 172         int reservedpages = 0;
 173         int datapages = 0;
 174         unsigned long tmp2, addr;
 175         extern char etext;
 176 
 177         end_mem &= PAGE_MASK;
 178         high_memory = end_mem;
 179 
 180         start_mem = PAGE_ALIGN(start_mem);
 181 
 182         addr = PAGE_OFFSET;
 183         while(addr < start_mem) {
 184                 mem_map[MAP_NR(addr)] = MAP_PAGE_RESERVED;
 185                 addr += PAGE_SIZE;
 186         }
 187 
 188         for(addr = start_mem; addr < end_mem; addr += PAGE_SIZE)
 189                         mem_map[MAP_NR(addr)] = 0;
 190 
 191 #ifdef CONFIG_SCSI
 192         scsi_mem_init(high_memory);
 193 #endif
 194 
 195         for (addr = PAGE_OFFSET; addr < end_mem; addr += PAGE_SIZE) {
 196                 if(mem_map[MAP_NR(addr)]) {
 197                         if (addr < (unsigned long) &etext)
 198                                 codepages++;
 199                         else if(addr < start_mem)
 200                                 datapages++;
 201                         else
 202                                 reservedpages++;
 203                         continue;
 204                 }
 205                 mem_map[MAP_NR(addr)] = 1;
 206                 free_page(addr);
 207         }
 208 
 209         tmp2 = nr_free_pages << PAGE_SHIFT;
 210 
 211         printk("Memory: %luk/%luk available (%dk kernel code, %dk reserved, %dk data)\n",
 212                tmp2 >> 10,
 213                (high_memory - PAGE_OFFSET) >> 10,
 214                codepages << (PAGE_SHIFT-10),
 215                reservedpages << (PAGE_SHIFT-10),
 216                datapages << (PAGE_SHIFT-10));
 217 
 218 /* Heh, test write protection just like the i386, this is bogus but it is
 219  * fun to do ;)
 220  */
 221         switch(sparc_cpu_model) {
 222         case sun4c:
 223                 start_mem = sun4c_test_wp(start_mem);
 224                 break;
 225         case sun4m:
 226         case sun4d:
 227         case sun4e:
 228                 srmmu_test_wp();
 229                 break;
 230         default:
 231                 printk("mem_init: Could not test WP bit on this machine.\n");
 232                 printk("mem_init: sparc_cpu_model = %d\n", sparc_cpu_model);
 233                 printk("mem_init: Halting...\n");
 234                 halt();
 235         };
 236 
 237 #ifdef DEBUG_MEMINIT
 238         printk("Breaker breaker...Roger roger.... Over and out...\n");
 239 #endif
 240         invalidate();
 241 
 242         return;
 243 }
 244 
 245 void si_meminfo(struct sysinfo *val)
     /* [previous][next][first][last][top][bottom][index][help] */
 246 {
 247         int i;
 248 
 249         i = high_memory >> PAGE_SHIFT;
 250         val->totalram = 0;
 251         val->sharedram = 0;
 252         val->freeram = nr_free_pages << PAGE_SHIFT;
 253         val->bufferram = buffermem;
 254         while (i-- > 0)  {
 255                 if (mem_map[i] & MAP_PAGE_RESERVED)
 256                         continue;
 257                 val->totalram++;
 258                 if (!mem_map[i])
 259                         continue;
 260                 val->sharedram += mem_map[i]-1;
 261         }
 262         val->totalram <<= PAGE_SHIFT;
 263         val->sharedram <<= PAGE_SHIFT;
 264         return;
 265 }

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