ia64/xen-unstable

view xen/common/memory.c @ 1881:51f8d2380c82

bitkeeper revision 1.1108.2.23 (41009ec4IUCzAdT9TYmLiFFkyZUHiw)

memory.c:
Cleanup
author kaf24@scramble.cl.cam.ac.uk
date Fri Jul 23 05:14:44 2004 +0000 (2004-07-23)
parents 15cbfb844361
children 381b2b637b12
line source
1 /******************************************************************************
2 * memory.c
3 *
4 * Copyright (c) 2002-2004 K A Fraser
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
21 #include <xen/config.h>
22 #include <xen/init.h>
23 #include <xen/lib.h>
24 #include <xen/mm.h>
25 #include <xen/sched.h>
26 #include <xen/errno.h>
27 #include <xen/perfc.h>
28 #include <xen/irq.h>
29 #include <asm/page.h>
30 #include <asm/flushtlb.h>
31 #include <asm/io.h>
32 #include <asm/uaccess.h>
33 #include <asm/domain_page.h>
35 /* Frame table and its size in pages. */
36 struct pfn_info *frame_table;
37 unsigned long frame_table_size;
38 unsigned long max_page;
40 struct list_head free_list;
41 spinlock_t free_list_lock;
42 unsigned int free_pfns;
44 extern void init_percpu_info(void);
46 void __init init_frametable(void *frametable_vstart, unsigned long nr_pages)
47 {
48 unsigned long mfn;
50 init_percpu_info();
52 max_page = nr_pages;
53 frame_table_size = nr_pages * sizeof(struct pfn_info);
54 frame_table_size = (frame_table_size + PAGE_SIZE - 1) & PAGE_MASK;
55 frame_table = frametable_vstart;
57 if ( (__pa(frame_table) + frame_table_size) > (max_page << PAGE_SHIFT) )
58 panic("Not enough memory for frame table - reduce Xen heap size?\n");
60 memset(frame_table, 0, frame_table_size);
62 spin_lock_init(&free_list_lock);
63 INIT_LIST_HEAD(&free_list);
64 free_pfns = 0;
66 /* Initialise to a magic of 0x55555555 so easier to spot bugs later. */
67 memset(machine_to_phys_mapping, 0x55, 4<<20);
69 /* Pin the ownership of the MP table so that DOM0 can map it later. */
70 for ( mfn = virt_to_phys(&machine_to_phys_mapping[0<<20])>>PAGE_SHIFT;
71 mfn < virt_to_phys(&machine_to_phys_mapping[1<<20])>>PAGE_SHIFT;
72 mfn++ )
73 {
74 frame_table[mfn].count_and_flags = 1 | PGC_allocated;
75 frame_table[mfn].type_and_flags = 1 | PGT_gdt_page; /* non-RW type */
76 frame_table[mfn].u.domain = &idle0_task;
77 }
78 }
81 void add_to_domain_alloc_list(unsigned long ps, unsigned long pe)
82 {
83 unsigned long i;
84 unsigned long flags;
86 spin_lock_irqsave(&free_list_lock, flags);
87 for ( i = ps >> PAGE_SHIFT; i < (pe >> PAGE_SHIFT); i++ )
88 {
89 list_add_tail(&frame_table[i].list, &free_list);
90 free_pfns++;
91 }
92 spin_unlock_irqrestore(&free_list_lock, flags);
93 }