ia64/xen-unstable

view xen/arch/powerpc/shadow.c @ 12034:b07487d91f93

[XEN] Logging parameters for powerpc code.
Signed-off-by: Steven Rostedt <srostedt@redhat.com>
author kaf24@localhost.localdomain
date Fri Oct 27 18:56:44 2006 +0100 (2006-10-27)
parents 4fdf5151b187
children 36679b74e24a
line source
1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15 *
16 * Copyright (C) IBM Corp. 2006
17 *
18 * Authors: Jimi Xenidis <jimix@watson.ibm.com>
19 */
21 #include <xen/config.h>
22 #include <xen/types.h>
23 #include <xen/shadow.h>
25 static ulong htab_calc_sdr1(ulong htab_addr, ulong log_htab_size)
26 {
27 ulong sdr1_htabsize;
29 ASSERT((htab_addr & ((1UL << log_htab_size) - 1)) == 0);
30 ASSERT(log_htab_size <= SDR1_HTABSIZE_MAX);
31 ASSERT(log_htab_size >= HTAB_MIN_LOG_SIZE);
33 sdr1_htabsize = log_htab_size - LOG_PTEG_SIZE - SDR1_HTABSIZE_BASEBITS;
35 return (htab_addr | (sdr1_htabsize & SDR1_HTABSIZE_MASK));
36 }
38 static ulong htab_alloc(struct domain *d, uint order)
39 {
40 ulong htab_raddr;
41 uint log_htab_bytes = order + PAGE_SHIFT;
42 uint htab_bytes = 1UL << log_htab_bytes;
44 /* we use xenheap pages to keep domheap pages usefull for domains */
46 if (order < 6)
47 order = 6; /* architectural minimum is 2^18 */
48 if (order > 34)
49 order = 34; /* architectural minimum is 2^46 */
51 htab_raddr = (ulong)alloc_xenheap_pages(order);
52 if (htab_raddr > 0) {
53 ASSERT((htab_raddr & (htab_bytes - 1)) == 0);
55 d->arch.htab.order = order;
56 d->arch.htab.log_num_ptes = log_htab_bytes - LOG_PTE_SIZE;
57 d->arch.htab.sdr1 = htab_calc_sdr1(htab_raddr, log_htab_bytes);
58 d->arch.htab.map = (union pte *)htab_raddr;
59 }
60 return htab_raddr;
61 }
63 static void htab_free(struct domain *d)
64 {
65 ulong htab_raddr = GET_HTAB(d);
67 free_xenheap_pages((void *)htab_raddr, d->arch.htab.order);
68 }
71 unsigned int shadow_teardown(struct domain *d)
72 {
73 htab_free(d);
74 return 0;
75 }
77 unsigned int shadow_set_allocation(struct domain *d,
78 unsigned int megabytes,
79 int *preempted)
80 {
81 uint pages;
82 uint p;
83 uint order;
84 ulong addr;
87 if (d->arch.htab.order)
88 return -EBUSY;
90 if (megabytes == 0) {
91 /* old management tools */
92 megabytes = 1; /* 1/64th of 64M */
93 printk("%s: WARNING!!: Update your managment tools\n"
94 " using %d MiB htab\n",
95 __func__, megabytes);
96 }
97 pages = megabytes << (20 - PAGE_SHIFT);
98 order = fls(pages) - 1; /* log2 truncated */
99 if (pages & ((1 << order) - 1))
100 ++order; /* round up */
102 addr = htab_alloc(d, order);
104 printk("%s: ibm,fpt-size should be: 0x%x\n", __func__,
105 d->arch.htab.log_num_ptes + LOG_PTE_SIZE);
107 if (addr == 0)
108 return -ENOMEM;
110 /* XXX make this a continuation */
111 for (p = 0; p < (1 << order); p++)
112 clear_page((void *)(addr + (p << PAGE_SHIFT)));
114 return 0;
115 }
117 int shadow_domctl(struct domain *d,
118 xen_domctl_shadow_op_t *sc,
119 XEN_GUEST_HANDLE(xen_domctl_t) u_domctl)
120 {
121 if ( unlikely(d == current->domain) )
122 {
123 DPRINTK(XENLOG_G_INFO "Don't try to do a shadow op on yourself!\n");
124 return -EINVAL;
125 }
127 switch ( sc->op )
128 {
129 case XEN_DOMCTL_SHADOW_OP_OFF:
130 DPRINTK(XENLOG_G_INFO "Shadow is mandatory!\n");
131 return -EINVAL;
133 case XEN_DOMCTL_SHADOW_OP_GET_ALLOCATION:
134 sc->mb = shadow_get_allocation(d);
135 return 0;
137 case XEN_DOMCTL_SHADOW_OP_SET_ALLOCATION: {
138 int rc;
139 int preempted = 0;
141 rc = shadow_set_allocation(d, sc->mb, &preempted);
143 if (preempted)
144 /* Not finished. Set up to re-run the call. */
145 rc = hypercall_create_continuation(
146 __HYPERVISOR_domctl, "h", u_domctl);
147 else
148 /* Finished. Return the new allocation */
149 sc->mb = shadow_get_allocation(d);
150 return rc;
151 }
153 default:
154 printk("Bad shadow op %u\n", sc->op);
155 BUG();
156 return -EINVAL;
157 }
158 }