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

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