ia64/xen-unstable

view xen/arch/powerpc/domain.c @ 13936:88ae0647d542

[XEN][POWERPC] remove redundant and confusing restart/halt messages

Signed-off-by: Jimi Xenidis <jimix@watson.ibm.com>
author Jimi Xenidis <jimix@watson.ibm.com>
date Sun Jan 21 07:47:35 2007 -0500 (2007-01-21)
parents a1e9bacfc57d
children 978ff6fad81f
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 IBM Corp. 2005, 2006, 2007
17 *
18 * Authors: Jimi Xenidis <jimix@watson.ibm.com>
19 */
21 #include <stdarg.h>
22 #include <xen/config.h>
23 #include <xen/lib.h>
24 #include <xen/sched.h>
25 #include <xen/mm.h>
26 #include <xen/serial.h>
27 #include <xen/domain.h>
28 #include <xen/console.h>
29 #include <xen/shutdown.h>
30 #include <xen/shadow.h>
31 #include <xen/mm.h>
32 #include <xen/softirq.h>
33 #include <asm/htab.h>
34 #include <asm/current.h>
35 #include <asm/hcalls.h>
36 #include "rtas.h"
37 #include "exceptions.h"
39 #define next_arg(fmt, args) ({ \
40 unsigned long __arg; \
41 switch ( *(fmt)++ ) \
42 { \
43 case 'i': __arg = (unsigned long)va_arg(args, unsigned int); break; \
44 case 'l': __arg = (unsigned long)va_arg(args, unsigned long); break; \
45 case 'p': __arg = (unsigned long)va_arg(args, void *); break; \
46 case 'h': __arg = (unsigned long)va_arg(args, void *); break; \
47 default: __arg = 0; BUG(); \
48 } \
49 __arg; \
50 })
52 unsigned long hypercall_create_continuation(unsigned int op,
53 const char *format, ...)
54 {
55 struct cpu_user_regs *regs = guest_cpu_user_regs();
56 const char *p = format;
57 va_list args;
58 int gprnum = 4;
59 int i;
61 va_start(args, format);
63 regs->pc -= 4; /* re-execute 'sc' */
65 for (i = 0; *p != '\0'; i++) {
66 regs->gprs[gprnum++] = next_arg(p, args);
67 }
69 va_end(args);
71 /* As luck would have it, we use the same register for hcall opcodes and
72 * for hcall return values. The return value from this function is placed
73 * in r3 on return, so modifying regs->gprs[3] would have no effect. */
74 return XEN_MARK(op);
75 }
77 int arch_domain_create(struct domain *d)
78 {
79 if (d->domain_id == IDLE_DOMAIN_ID) {
80 d->shared_info = (void *)alloc_xenheap_page();
81 clear_page(d->shared_info);
83 return 0;
84 }
86 d->arch.large_page_sizes = cpu_large_page_orders(
87 d->arch.large_page_order, ARRAY_SIZE(d->arch.large_page_order));
89 INIT_LIST_HEAD(&d->arch.extent_list);
91 d->arch.foreign_mfn_count = 1024;
92 d->arch.foreign_mfns = xmalloc_array(uint, d->arch.foreign_mfn_count);
93 BUG_ON(d->arch.foreign_mfns == NULL);
95 memset(d->arch.foreign_mfns, -1, d->arch.foreign_mfn_count * sizeof(uint));
97 return 0;
98 }
100 void arch_domain_destroy(struct domain *d)
101 {
102 shadow_teardown(d);
103 /* shared_info is part of the RMA so no need to release it */
104 }
106 static void machine_fail(const char *s)
107 {
108 printk("%s failed, manual powercycle required!\n"
109 " spinning....\n", s);
110 for (;;)
111 sleep();
112 }
113 void machine_halt(void)
114 {
115 console_start_sync();
116 printk("%s called\n", __func__);
117 rtas_halt();
119 machine_fail(__func__);
120 }
122 void machine_restart(char * __unused)
123 {
124 console_start_sync();
125 printk("%s called\n", __func__);
126 rtas_reboot();
127 machine_fail(__func__);
128 }
130 struct vcpu *alloc_vcpu_struct(void)
131 {
132 struct vcpu *v;
133 if ( (v = xmalloc(struct vcpu)) != NULL )
134 memset(v, 0, sizeof(*v));
135 return v;
136 }
138 void free_vcpu_struct(struct vcpu *v)
139 {
140 xfree(v);
141 }
143 int vcpu_initialise(struct vcpu *v)
144 {
145 return 0;
146 }
148 void vcpu_destroy(struct vcpu *v)
149 {
150 }
152 int arch_set_info_guest(struct vcpu *v, vcpu_guest_context_t *c)
153 {
154 struct domain *d = v->domain;
156 memcpy(&v->arch.ctxt, &c->user_regs, sizeof(c->user_regs));
158 printk("Domain[%d].%d: initializing\n", d->domain_id, v->vcpu_id);
160 if (d->arch.htab.order == 0)
161 panic("Page table never allocated for Domain: %d\n", d->domain_id);
162 if (d->arch.rma_order == 0)
163 panic("RMA never allocated for Domain: %d\n", d->domain_id);
165 d->shared_info->wc_sec = dom0->shared_info->wc_sec;
166 d->shared_info->wc_nsec = dom0->shared_info->wc_nsec;
167 d->shared_info->arch.boot_timebase = dom0->shared_info->arch.boot_timebase;
169 set_bit(_VCPUF_initialised, &v->vcpu_flags);
171 cpu_init_vcpu(v);
173 return 0;
174 }
176 void dump_pageframe_info(struct domain *d)
177 {
178 struct page_info *page;
180 printk("Memory pages belonging to domain %u:\n", d->domain_id);
182 if ( d->tot_pages >= 10 )
183 {
184 printk(" DomPage list too long to display\n");
185 }
186 else
187 {
188 list_for_each_entry ( page, &d->page_list, list )
189 {
190 printk(" DomPage %p: mfn=%p, caf=%016lx, taf=%" PRtype_info "\n",
191 _p(page_to_maddr(page)), _p(page_to_mfn(page)),
192 page->count_info, page->u.inuse.type_info);
193 }
194 }
196 list_for_each_entry ( page, &d->xenpage_list, list )
197 {
198 printk(" XenPage %p: mfn=%p, caf=%016lx, taf=%" PRtype_info "\n",
199 _p(page_to_maddr(page)), _p(page_to_mfn(page)),
200 page->count_info, page->u.inuse.type_info);
201 }
202 }
204 void context_switch(struct vcpu *prev, struct vcpu *next)
205 {
206 struct cpu_user_regs *stack_regs = guest_cpu_user_regs();
207 cpumask_t dirty_mask = next->vcpu_dirty_cpumask;
208 unsigned int cpu = smp_processor_id();
210 #if 0
211 printk("%s: dom %x to dom %x\n", __func__, prev->domain->domain_id,
212 next->domain->domain_id);
213 #endif
215 /* Allow at most one CPU at a time to be dirty. */
216 ASSERT(cpus_weight(dirty_mask) <= 1);
217 if (unlikely(!cpu_isset(cpu, dirty_mask) && !cpus_empty(dirty_mask)))
218 {
219 /* Other cpus call __sync_lazy_execstate from flush ipi handler. */
220 if (!cpus_empty(next->vcpu_dirty_cpumask))
221 flush_tlb_mask(next->vcpu_dirty_cpumask);
222 }
224 /* copy prev guest state off the stack into its vcpu */
225 memcpy(&prev->arch.ctxt, stack_regs, sizeof(struct cpu_user_regs));
227 set_current(next);
229 /* copy next guest state onto the stack */
230 memcpy(stack_regs, &next->arch.ctxt, sizeof(struct cpu_user_regs));
232 /* save old domain state */
233 save_sprs(prev);
234 save_float(prev);
235 save_segments(prev);
237 context_saved(prev);
239 /* load up new domain */
240 load_sprs(next);
241 load_float(next);
242 load_segments(next);
244 mtsdr1(next->domain->arch.htab.sdr1);
245 local_flush_tlb(); /* XXX maybe flush_tlb_mask? */
246 cpu_flush_icache();
248 if (is_idle_vcpu(next)) {
249 reset_stack_and_jump(idle_loop);
250 }
252 reset_stack_and_jump(full_resume);
253 /* not reached */
254 }
256 void continue_running(struct vcpu *same)
257 {
258 /* nothing to do */
259 return;
260 }
262 void sync_vcpu_execstate(struct vcpu *v)
263 {
264 /* do nothing */
265 return;
266 }
268 static void relinquish_memory(struct domain *d, struct list_head *list)
269 {
270 struct list_head *ent;
271 struct page_info *page;
273 /* Use a recursive lock, as we may enter 'free_domheap_page'. */
274 spin_lock_recursive(&d->page_alloc_lock);
276 ent = list->next;
277 while ( ent != list )
278 {
279 page = list_entry(ent, struct page_info, list);
281 /* Grab a reference to the page so it won't disappear from under us. */
282 if ( unlikely(!get_page(page, d)) )
283 {
284 /* Couldn't get a reference -- someone is freeing this page. */
285 ent = ent->next;
286 continue;
287 }
288 if ( test_and_clear_bit(_PGT_pinned, &page->u.inuse.type_info) )
289 put_page_and_type(page);
291 if ( test_and_clear_bit(_PGC_allocated, &page->count_info) )
292 put_page(page);
294 /* Follow the list chain and /then/ potentially free the page. */
295 ent = ent->next;
296 put_page(page);
297 }
298 spin_unlock_recursive(&d->page_alloc_lock);
299 }
301 void domain_relinquish_resources(struct domain *d)
302 {
303 relinquish_memory(d, &d->xenpage_list);
304 relinquish_memory(d, &d->page_list);
305 free_extents(d);
306 xfree(d->arch.foreign_mfns);
307 return;
308 }
310 void arch_dump_domain_info(struct domain *d)
311 {
312 }
314 void arch_dump_vcpu_info(struct vcpu *v)
315 {
316 }
318 static void safe_halt(void)
319 {
320 int cpu = smp_processor_id();
322 while (!softirq_pending(cpu))
323 sleep();
324 }
326 static void default_idle(void)
327 {
328 local_irq_disable();
329 if ( !softirq_pending(smp_processor_id()) )
330 safe_halt();
331 else
332 local_irq_enable();
333 }
335 void idle_loop(void)
336 {
337 for ( ; ; ) {
338 page_scrub_schedule_work();
339 default_idle();
340 do_softirq();
341 }
342 }