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

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