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 #include <linux/swap.h>
  19 
  20 #include <asm/system.h>
  21 #include <asm/segment.h>
  22 #include <asm/pgtable.h>
  23 #include <asm/hwrpb.h>
  24 #include <asm/dma.h>
  25 
  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 void show_mem(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  55 {
  56         int i,free = 0,total = 0,reserved = 0;
  57         int shared = 0;
  58 
  59         printk("\nMem-info:\n");
  60         show_free_areas();
  61         printk("Free swap:       %6dkB\n",nr_swap_pages<<(PAGE_SHIFT-10));
  62         i = MAP_NR(high_memory);
  63         while (i-- > 0) {
  64                 total++;
  65                 if (PageReserved(mem_map+i))
  66                         reserved++;
  67                 else if (!mem_map[i].count)
  68                         free++;
  69                 else
  70                         shared += mem_map[i].count-1;
  71         }
  72         printk("%d pages of RAM\n",total);
  73         printk("%d free pages\n",free);
  74         printk("%d reserved pages\n",reserved);
  75         printk("%d pages shared\n",shared);
  76         show_buffers();
  77 #ifdef CONFIG_NET
  78         show_net_buffers();
  79 #endif
  80 }
  81 
  82 extern unsigned long free_area_init(unsigned long, unsigned long);
  83 
  84 static void load_PCB(struct thread_struct * pcb)
     /* [previous][next][first][last][top][bottom][index][help] */
  85 {
  86         __asm__ __volatile__(
  87                 "stq $30,0(%0)\n\t"
  88                 "bis %0,%0,$16\n\t"
  89                 "call_pal %1"
  90                 : /* no outputs */
  91                 : "r" (pcb), "i" (PAL_swpctx)
  92                 : "$0", "$1", "$16", "$22", "$23", "$24", "$25");
  93 }
  94 
  95 /*
  96  * paging_init() sets up the page tables: in the alpha version this actually
  97  * unmaps the bootup page table (as we're now in KSEG, so we don't need it).
  98  */
  99 unsigned long paging_init(unsigned long start_mem, unsigned long end_mem)
     /* [previous][next][first][last][top][bottom][index][help] */
 100 {
 101         int i;
 102         unsigned long newptbr;
 103         struct memclust_struct * cluster;
 104         struct memdesc_struct * memdesc;
 105 
 106         /* initialize mem_map[] */
 107         start_mem = free_area_init(start_mem, end_mem);
 108 
 109         /* find free clusters, update mem_map[] accordingly */
 110         memdesc = (struct memdesc_struct *) (INIT_HWRPB->mddt_offset + (unsigned long) INIT_HWRPB);
 111         cluster = memdesc->cluster;
 112         for (i = memdesc->numclusters ; i > 0; i--, cluster++) {
 113                 unsigned long pfn, nr;
 114                 if (cluster->usage & 1)
 115                         continue;
 116                 pfn = cluster->start_pfn;
 117                 nr = cluster->numpages;
 118 
 119                 /* non-volatile memory. We might want to mark this for later */
 120                 if (cluster->usage & 2)
 121                         continue;
 122 
 123                 while (nr--)
 124                         clear_bit(PG_reserved, &mem_map[pfn++].flags);
 125         }
 126 
 127         /* unmap the console stuff: we don't need it, and we don't want it */
 128         /* Also set up the real kernel PCB while we're at it.. */
 129         memset((void *) ZERO_PAGE, 0, PAGE_SIZE);
 130         memset(swapper_pg_dir, 0, PAGE_SIZE);
 131         newptbr = ((unsigned long) swapper_pg_dir - PAGE_OFFSET) >> PAGE_SHIFT;
 132         pgd_val(swapper_pg_dir[1023]) = (newptbr << 32) | pgprot_val(PAGE_KERNEL);
 133         init_task.tss.ptbr = newptbr;
 134         init_task.tss.flags = 1;
 135         init_task.kernel_stack_page = INIT_STACK;
 136         load_PCB(&init_task.tss);
 137 
 138         flush_tlb_all();
 139         return start_mem;
 140 }
 141 
 142 void mem_init(unsigned long start_mem, unsigned long end_mem)
     /* [previous][next][first][last][top][bottom][index][help] */
 143 {
 144         unsigned long tmp;
 145 
 146         end_mem &= PAGE_MASK;
 147         high_memory = end_mem;
 148         start_mem = PAGE_ALIGN(start_mem);
 149 
 150         /*
 151          * Mark the pages used by the kernel as reserved..
 152          */
 153         tmp = KERNEL_START;
 154         while (tmp < start_mem) {
 155                 set_bit(PG_reserved, &mem_map[MAP_NR(tmp)].flags);
 156                 tmp += PAGE_SIZE;
 157         }
 158 
 159         for (tmp = PAGE_OFFSET ; tmp < high_memory ; tmp += PAGE_SIZE) {
 160                 if (tmp >= MAX_DMA_ADDRESS)
 161                         clear_bit(PG_DMA, &mem_map[MAP_NR(tmp)].flags);
 162                 if (PageReserved(mem_map+MAP_NR(tmp)))
 163                         continue;
 164                 mem_map[MAP_NR(tmp)].count = 1;
 165                 free_page(tmp);
 166         }
 167         tmp = nr_free_pages << PAGE_SHIFT;
 168         printk("Memory: %luk available\n", tmp >> 10);
 169         return;
 170 }
 171 
 172 void si_meminfo(struct sysinfo *val)
     /* [previous][next][first][last][top][bottom][index][help] */
 173 {
 174         int i;
 175 
 176         i = MAP_NR(high_memory);
 177         val->totalram = 0;
 178         val->sharedram = 0;
 179         val->freeram = nr_free_pages << PAGE_SHIFT;
 180         val->bufferram = buffermem;
 181         while (i-- > 0)  {
 182                 if (PageReserved(mem_map+i))
 183                         continue;
 184                 val->totalram++;
 185                 if (!mem_map[i].count)
 186                         continue;
 187                 val->sharedram += mem_map[i].count-1;
 188         }
 189         val->totalram <<= PAGE_SHIFT;
 190         val->sharedram <<= PAGE_SHIFT;
 191         return;
 192 }

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