root/arch/alpha/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. load_PCB
  6. paging_init
  7. mem_init
  8. si_meminfo

   1 /*
   2  *  linux/arch/alpha/mm/init.c
   3  *
   4  *  Copyright (C) 1995  Linus Torvalds
   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/pgtable.h>
  22 #include <asm/hwrpb.h>
  23 
  24 extern void scsi_mem_init(unsigned long);
  25 extern void die_if_kernel(char *,struct pt_regs *,long);
  26 extern void show_net_buffers(void);
  27 
  28 /*
  29  * BAD_PAGE is the page that is used for page faults when linux
  30  * is out-of-memory. Older versions of linux just did a
  31  * do_exit(), but using this instead means there is less risk
  32  * for a process dying in kernel mode, possibly leaving a inode
  33  * unused etc..
  34  *
  35  * BAD_PAGETABLE is the accompanying page-table: it is initialized
  36  * to point to BAD_PAGE entries.
  37  *
  38  * ZERO_PAGE is a special page that is used for zero-initialized
  39  * data and COW.
  40  */
  41 pmd_t * __bad_pagetable(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  42 {
  43         memset((void *) EMPTY_PGT, 0, PAGE_SIZE);
  44         return (pmd_t *) EMPTY_PGT;
  45 }
  46 
  47 pte_t __bad_page(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  48 {
  49         memset((void *) EMPTY_PGE, 0, PAGE_SIZE);
  50         return pte_mkdirty(mk_pte((unsigned long) EMPTY_PGE, PAGE_SHARED));
  51 }
  52 
  53 unsigned long __zero_page(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  54 {
  55         memset((void *) ZERO_PGE, 0, PAGE_SIZE);
  56         return (unsigned long) ZERO_PGE;
  57 }
  58 
  59 void show_mem(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  60 {
  61         int i,free = 0,total = 0,reserved = 0;
  62         int shared = 0;
  63 
  64         printk("\nMem-info:\n");
  65         show_free_areas();
  66         printk("Free swap:       %6dkB\n",nr_swap_pages<<(PAGE_SHIFT-10));
  67         i = MAP_NR(high_memory);
  68         while (i-- > 0) {
  69                 total++;
  70                 if (mem_map[i].reserved)
  71                         reserved++;
  72                 else if (!mem_map[i].count)
  73                         free++;
  74                 else
  75                         shared += mem_map[i].count-1;
  76         }
  77         printk("%d pages of RAM\n",total);
  78         printk("%d free pages\n",free);
  79         printk("%d reserved pages\n",reserved);
  80         printk("%d pages shared\n",shared);
  81         show_buffers();
  82 #ifdef CONFIG_NET
  83         show_net_buffers();
  84 #endif
  85 }
  86 
  87 extern unsigned long free_area_init(unsigned long, unsigned long);
  88 
  89 static void load_PCB(struct thread_struct * pcb)
     /* [previous][next][first][last][top][bottom][index][help] */
  90 {
  91         __asm__ __volatile__(
  92                 "stq $30,0(%0)\n\t"
  93                 "bis %0,%0,$16\n\t"
  94                 "call_pal %1"
  95                 : /* no outputs */
  96                 : "r" (pcb), "i" (PAL_swpctx)
  97                 : "$0", "$1", "$16", "$22", "$23", "$24", "$25");
  98 }
  99 
 100 /*
 101  * paging_init() sets up the page tables: in the alpha version this actually
 102  * unmaps the bootup page table (as we're now in KSEG, so we don't need it).
 103  */
 104 unsigned long paging_init(unsigned long start_mem, unsigned long end_mem)
     /* [previous][next][first][last][top][bottom][index][help] */
 105 {
 106         int i;
 107         unsigned long newptbr;
 108         struct memclust_struct * cluster;
 109         struct memdesc_struct * memdesc;
 110 
 111         /* initialize mem_map[] */
 112         start_mem = free_area_init(start_mem, end_mem);
 113 
 114         /* find free clusters, update mem_map[] accordingly */
 115         memdesc = (struct memdesc_struct *) (INIT_HWRPB->mddt_offset + (unsigned long) INIT_HWRPB);
 116         cluster = memdesc->cluster;
 117         for (i = memdesc->numclusters ; i > 0; i--, cluster++) {
 118                 unsigned long pfn, nr;
 119                 if (cluster->usage & 1)
 120                         continue;
 121                 pfn = cluster->start_pfn;
 122                 nr = cluster->numpages;
 123 
 124                 /* non-volatile memory. We might want to mark this for later */
 125                 if (cluster->usage & 2)
 126                         continue;
 127 
 128                 while (nr--)
 129                         mem_map[pfn++].reserved = 0;
 130         }
 131 
 132         /* unmap the console stuff: we don't need it, and we don't want it */
 133         /* Also set up the real kernel PCB while we're at it.. */
 134         memset((void *) ZERO_PGE, 0, PAGE_SIZE);
 135         memset(swapper_pg_dir, 0, PAGE_SIZE);
 136         newptbr = ((unsigned long) swapper_pg_dir - PAGE_OFFSET) >> PAGE_SHIFT;
 137         pgd_val(swapper_pg_dir[1023]) = (newptbr << 32) | pgprot_val(PAGE_KERNEL);
 138         init_task.tss.ptbr = newptbr;
 139         init_task.tss.flags = 1;
 140         init_task.kernel_stack_page = INIT_STACK;
 141         load_PCB(&init_task.tss);
 142 
 143         invalidate_all();
 144         return start_mem;
 145 }
 146 
 147 void mem_init(unsigned long start_mem, unsigned long end_mem)
     /* [previous][next][first][last][top][bottom][index][help] */
 148 {
 149         unsigned long tmp;
 150 
 151         end_mem &= PAGE_MASK;
 152         high_memory = end_mem;
 153         start_mem = PAGE_ALIGN(start_mem);
 154 
 155         /*
 156          * Mark the pages used by the kernel as reserved..
 157          */
 158         tmp = KERNEL_START;
 159         while (tmp < start_mem) {
 160                 mem_map[MAP_NR(tmp)].reserved = 1;
 161                 tmp += PAGE_SIZE;
 162         }
 163 
 164 
 165 #ifdef CONFIG_SCSI
 166         scsi_mem_init(high_memory);
 167 #endif
 168 
 169         for (tmp = PAGE_OFFSET ; tmp < high_memory ; tmp += PAGE_SIZE) {
 170                 if (mem_map[MAP_NR(tmp)].reserved)
 171                         continue;
 172                 mem_map[MAP_NR(tmp)].count = 1;
 173                 free_page(tmp);
 174         }
 175         tmp = nr_free_pages << PAGE_SHIFT;
 176         printk("Memory: %luk available\n", tmp >> 10);
 177         return;
 178 }
 179 
 180 void si_meminfo(struct sysinfo *val)
     /* [previous][next][first][last][top][bottom][index][help] */
 181 {
 182         int i;
 183 
 184         i = MAP_NR(high_memory);
 185         val->totalram = 0;
 186         val->sharedram = 0;
 187         val->freeram = nr_free_pages << PAGE_SHIFT;
 188         val->bufferram = buffermem;
 189         while (i-- > 0)  {
 190                 if (mem_map[i].reserved)
 191                         continue;
 192                 val->totalram++;
 193                 if (!mem_map[i].count)
 194                         continue;
 195                 val->sharedram += mem_map[i].count-1;
 196         }
 197         val->totalram <<= PAGE_SHIFT;
 198         val->sharedram <<= PAGE_SHIFT;
 199         return;
 200 }

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