ia64/xen-unstable

changeset 7563:bcccadcc56e5

Merged.
author emellor@leeni.uk.xensource.com
date Sun Oct 30 14:00:35 2005 +0100 (2005-10-30)
parents dc36edf1102f b5903c9aeda5
children 47ba7a4bed45
files tools/examples/Makefile tools/python/xen/xm/create.py
line diff
     1.1 --- a/extras/mini-os/include/events.h	Sun Oct 30 13:52:38 2005 +0100
     1.2 +++ b/extras/mini-os/include/events.h	Sun Oct 30 14:00:35 2005 +0100
     1.3 @@ -47,7 +47,7 @@ static inline int notify_via_evtchn(int 
     1.4  {
     1.5      evtchn_op_t op;
     1.6      op.cmd = EVTCHNOP_send;
     1.7 -    op.u.send.local_port = port;
     1.8 +    op.u.send.port = port;
     1.9      return HYPERVISOR_event_channel_op(&op);
    1.10  }
    1.11  
     2.1 --- a/extras/mini-os/include/hypervisor.h	Sun Oct 30 13:52:38 2005 +0100
     2.2 +++ b/extras/mini-os/include/hypervisor.h	Sun Oct 30 14:00:35 2005 +0100
     2.3 @@ -14,6 +14,7 @@
     2.4  
     2.5  #include <types.h>
     2.6  #include <xen/xen.h>
     2.7 +#include <xen/dom0_ops.h>
     2.8  
     2.9  /*
    2.10   * a placeholder for the start of day information passed up from the hypervisor
    2.11 @@ -37,548 +38,281 @@ void clear_evtchn(u32 port);
    2.12   * Assembler stubs for hyper-calls.
    2.13   */
    2.14  #if defined(__i386__)
    2.15 +/* Taken from Linux */
    2.16 +
    2.17 +#ifndef __HYPERCALL_H__
    2.18 +#define __HYPERCALL_H__
    2.19 +
    2.20 +#include <xen/sched.h>
    2.21 +
    2.22 +#define _hypercall0(type, name)			\
    2.23 +({						\
    2.24 +	long __res;				\
    2.25 +	asm volatile (				\
    2.26 +		TRAP_INSTR			\
    2.27 +		: "=a" (__res)			\
    2.28 +		: "0" (__HYPERVISOR_##name)	\
    2.29 +		: "memory" );			\
    2.30 +	(type)__res;				\
    2.31 +})
    2.32 +
    2.33 +#define _hypercall1(type, name, a1)				\
    2.34 +({								\
    2.35 +	long __res, __ign1;					\
    2.36 +	asm volatile (						\
    2.37 +		TRAP_INSTR					\
    2.38 +		: "=a" (__res), "=b" (__ign1)			\
    2.39 +		: "0" (__HYPERVISOR_##name), "1" ((long)(a1))	\
    2.40 +		: "memory" );					\
    2.41 +	(type)__res;						\
    2.42 +})
    2.43 +
    2.44 +#define _hypercall2(type, name, a1, a2)				\
    2.45 +({								\
    2.46 +	long __res, __ign1, __ign2;				\
    2.47 +	asm volatile (						\
    2.48 +		TRAP_INSTR					\
    2.49 +		: "=a" (__res), "=b" (__ign1), "=c" (__ign2)	\
    2.50 +		: "0" (__HYPERVISOR_##name), "1" ((long)(a1)),	\
    2.51 +		"2" ((long)(a2))				\
    2.52 +		: "memory" );					\
    2.53 +	(type)__res;						\
    2.54 +})
    2.55 +
    2.56 +#define _hypercall3(type, name, a1, a2, a3)			\
    2.57 +({								\
    2.58 +	long __res, __ign1, __ign2, __ign3;			\
    2.59 +	asm volatile (						\
    2.60 +		TRAP_INSTR					\
    2.61 +		: "=a" (__res), "=b" (__ign1), "=c" (__ign2), 	\
    2.62 +		"=d" (__ign3)					\
    2.63 +		: "0" (__HYPERVISOR_##name), "1" ((long)(a1)),	\
    2.64 +		"2" ((long)(a2)), "3" ((long)(a3))		\
    2.65 +		: "memory" );					\
    2.66 +	(type)__res;						\
    2.67 +})
    2.68 +
    2.69 +#define _hypercall4(type, name, a1, a2, a3, a4)			\
    2.70 +({								\
    2.71 +	long __res, __ign1, __ign2, __ign3, __ign4;		\
    2.72 +	asm volatile (						\
    2.73 +		TRAP_INSTR					\
    2.74 +		: "=a" (__res), "=b" (__ign1), "=c" (__ign2),	\
    2.75 +		"=d" (__ign3), "=S" (__ign4)			\
    2.76 +		: "0" (__HYPERVISOR_##name), "1" ((long)(a1)),	\
    2.77 +		"2" ((long)(a2)), "3" ((long)(a3)),		\
    2.78 +		"4" ((long)(a4))				\
    2.79 +		: "memory" );					\
    2.80 +	(type)__res;						\
    2.81 +})
    2.82 +
    2.83 +#define _hypercall5(type, name, a1, a2, a3, a4, a5)		\
    2.84 +({								\
    2.85 +	long __res, __ign1, __ign2, __ign3, __ign4, __ign5;	\
    2.86 +	asm volatile (						\
    2.87 +		TRAP_INSTR					\
    2.88 +		: "=a" (__res), "=b" (__ign1), "=c" (__ign2),	\
    2.89 +		"=d" (__ign3), "=S" (__ign4), "=D" (__ign5)	\
    2.90 +		: "0" (__HYPERVISOR_##name), "1" ((long)(a1)),	\
    2.91 +		"2" ((long)(a2)), "3" ((long)(a3)),		\
    2.92 +		"4" ((long)(a4)), "5" ((long)(a5))		\
    2.93 +		: "memory" );					\
    2.94 +	(type)__res;						\
    2.95 +})
    2.96 +
    2.97  static inline int
    2.98  HYPERVISOR_set_trap_table(
    2.99 -    trap_info_t *table)
   2.100 +	trap_info_t *table)
   2.101  {
   2.102 -    int ret;
   2.103 -    unsigned long ignore;
   2.104 -
   2.105 -    __asm__ __volatile__ (
   2.106 -        TRAP_INSTR
   2.107 -        : "=a" (ret), "=b" (ignore)
   2.108 -	: "0" (__HYPERVISOR_set_trap_table), "1" (table)
   2.109 -	: "memory" );
   2.110 -
   2.111 -    return ret;
   2.112 +	return _hypercall1(int, set_trap_table, table);
   2.113  }
   2.114  
   2.115  static inline int
   2.116  HYPERVISOR_mmu_update(
   2.117 -    mmu_update_t *req, int count, int *success_count, domid_t domid)
   2.118 +	mmu_update_t *req, int count, int *success_count, domid_t domid)
   2.119  {
   2.120 -    int ret;
   2.121 -    unsigned long ign1, ign2, ign3, ign4;
   2.122 -
   2.123 -    __asm__ __volatile__ (
   2.124 -        TRAP_INSTR
   2.125 -        : "=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3), "=S" (ign4)
   2.126 -	: "0" (__HYPERVISOR_mmu_update), "1" (req), "2" (count),
   2.127 -        "3" (success_count), "4" (domid)
   2.128 -	: "memory" );
   2.129 -
   2.130 -    return ret;
   2.131 +	return _hypercall4(int, mmu_update, req, count, success_count, domid);
   2.132  }
   2.133  
   2.134  static inline int
   2.135  HYPERVISOR_mmuext_op(
   2.136 -    struct mmuext_op *op, int count, int *success_count, domid_t domid)
   2.137 +	struct mmuext_op *op, int count, int *success_count, domid_t domid)
   2.138  {
   2.139 -    int ret;
   2.140 -    unsigned long ign1, ign2, ign3, ign4;
   2.141 -
   2.142 -    __asm__ __volatile__ (
   2.143 -        TRAP_INSTR
   2.144 -        : "=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3), "=S" (ign4)
   2.145 -	: "0" (__HYPERVISOR_mmuext_op), "1" (op), "2" (count),
   2.146 -        "3" (success_count), "4" (domid)
   2.147 -	: "memory" );
   2.148 -
   2.149 -    return ret;
   2.150 +	return _hypercall4(int, mmuext_op, op, count, success_count, domid);
   2.151  }
   2.152  
   2.153  static inline int
   2.154  HYPERVISOR_set_gdt(
   2.155 -    unsigned long *frame_list, int entries)
   2.156 +	unsigned long *frame_list, int entries)
   2.157  {
   2.158 -    int ret;
   2.159 -    unsigned long ign1, ign2;
   2.160 -
   2.161 -    __asm__ __volatile__ (
   2.162 -        TRAP_INSTR
   2.163 -        : "=a" (ret), "=b" (ign1), "=c" (ign2)
   2.164 -	: "0" (__HYPERVISOR_set_gdt), "1" (frame_list), "2" (entries)
   2.165 -	: "memory" );
   2.166 -
   2.167 -
   2.168 -    return ret;
   2.169 +	return _hypercall2(int, set_gdt, frame_list, entries);
   2.170  }
   2.171  
   2.172  static inline int
   2.173  HYPERVISOR_stack_switch(
   2.174 -    unsigned long ss, unsigned long esp)
   2.175 +	unsigned long ss, unsigned long esp)
   2.176  {
   2.177 -    int ret;
   2.178 -    unsigned long ign1, ign2;
   2.179 -
   2.180 -    __asm__ __volatile__ (
   2.181 -        TRAP_INSTR
   2.182 -        : "=a" (ret), "=b" (ign1), "=c" (ign2)
   2.183 -	: "0" (__HYPERVISOR_stack_switch), "1" (ss), "2" (esp)
   2.184 -	: "memory" );
   2.185 -
   2.186 -    return ret;
   2.187 +	return _hypercall2(int, stack_switch, ss, esp);
   2.188  }
   2.189  
   2.190  static inline int
   2.191  HYPERVISOR_set_callbacks(
   2.192 -    unsigned long event_selector, unsigned long event_address,
   2.193 -    unsigned long failsafe_selector, unsigned long failsafe_address)
   2.194 +	unsigned long event_selector, unsigned long event_address,
   2.195 +	unsigned long failsafe_selector, unsigned long failsafe_address)
   2.196  {
   2.197 -    int ret;
   2.198 -    unsigned long ign1, ign2, ign3, ign4;
   2.199 -
   2.200 -    __asm__ __volatile__ (
   2.201 -        TRAP_INSTR
   2.202 -        : "=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3), "=S" (ign4)
   2.203 -	: "0" (__HYPERVISOR_set_callbacks), "1" (event_selector),
   2.204 -	  "2" (event_address), "3" (failsafe_selector), "4" (failsafe_address)
   2.205 -	: "memory" );
   2.206 -
   2.207 -    return ret;
   2.208 +	return _hypercall4(int, set_callbacks,
   2.209 +			   event_selector, event_address,
   2.210 +			   failsafe_selector, failsafe_address);
   2.211  }
   2.212  
   2.213  static inline int
   2.214  HYPERVISOR_fpu_taskswitch(
   2.215 -    int set)
   2.216 -{
   2.217 -    int ret;
   2.218 -    unsigned long ign;
   2.219 -
   2.220 -    __asm__ __volatile__ (
   2.221 -        TRAP_INSTR
   2.222 -        : "=a" (ret), "=b" (ign)
   2.223 -        : "0" (__HYPERVISOR_fpu_taskswitch), "1" (set)
   2.224 -        : "memory" );
   2.225 -
   2.226 -    return ret;
   2.227 -}
   2.228 -
   2.229 -static inline int
   2.230 -HYPERVISOR_yield(
   2.231 -    void)
   2.232 +	int set)
   2.233  {
   2.234 -    int ret;
   2.235 -    unsigned long ign;
   2.236 -
   2.237 -    __asm__ __volatile__ (
   2.238 -        TRAP_INSTR
   2.239 -        : "=a" (ret), "=b" (ign)
   2.240 -	: "0" (__HYPERVISOR_sched_op), "1" (SCHEDOP_yield)
   2.241 -	: "memory", "ecx" );
   2.242 -
   2.243 -    return ret;
   2.244 -}
   2.245 -
   2.246 -static inline int
   2.247 -HYPERVISOR_block(
   2.248 -    void)
   2.249 -{
   2.250 -    int ret;
   2.251 -    unsigned long ign1;
   2.252 -    __asm__ __volatile__ (
   2.253 -        TRAP_INSTR
   2.254 -        : "=a" (ret), "=b" (ign1)
   2.255 -	: "0" (__HYPERVISOR_sched_op), "1" (SCHEDOP_block)
   2.256 -	: "memory", "ecx" );
   2.257 -
   2.258 -    return ret;
   2.259 +	return _hypercall1(int, fpu_taskswitch, set);
   2.260  }
   2.261  
   2.262  static inline int
   2.263 -HYPERVISOR_shutdown(
   2.264 -    void)
   2.265 -{
   2.266 -    int ret;
   2.267 -    unsigned long ign1;
   2.268 -    __asm__ __volatile__ (
   2.269 -        TRAP_INSTR
   2.270 -        : "=a" (ret), "=b" (ign1)
   2.271 -	: "0" (__HYPERVISOR_sched_op),
   2.272 -	  "1" (SCHEDOP_shutdown | (SHUTDOWN_poweroff << SCHEDOP_reasonshift))
   2.273 -        : "memory", "ecx" );
   2.274 -
   2.275 -    return ret;
   2.276 -}
   2.277 -
   2.278 -static inline int
   2.279 -HYPERVISOR_reboot(
   2.280 -    void)
   2.281 +HYPERVISOR_sched_op(
   2.282 +	int cmd, unsigned long arg)
   2.283  {
   2.284 -    int ret;
   2.285 -    unsigned long ign1;
   2.286 -    __asm__ __volatile__ (
   2.287 -        TRAP_INSTR
   2.288 -        : "=a" (ret), "=b" (ign1)
   2.289 -	: "0" (__HYPERVISOR_sched_op),
   2.290 -	  "1" (SCHEDOP_shutdown | (SHUTDOWN_reboot << SCHEDOP_reasonshift))
   2.291 -        : "memory", "ecx" );
   2.292 -
   2.293 -    return ret;
   2.294 -}
   2.295 -
   2.296 -static inline int
   2.297 -HYPERVISOR_suspend(
   2.298 -    unsigned long srec)
   2.299 -{
   2.300 -    int ret;
   2.301 -    unsigned long ign1, ign2;
   2.302 -
   2.303 -    /* NB. On suspend, control software expects a suspend record in %esi. */
   2.304 -    __asm__ __volatile__ (
   2.305 -        TRAP_INSTR
   2.306 -        : "=a" (ret), "=b" (ign1), "=S" (ign2)
   2.307 -	: "0" (__HYPERVISOR_sched_op),
   2.308 -        "b" (SCHEDOP_shutdown | (SHUTDOWN_suspend << SCHEDOP_reasonshift)), 
   2.309 -        "S" (srec) : "memory", "ecx");
   2.310 -
   2.311 -    return ret;
   2.312 -}
   2.313 -
   2.314 -static inline int
   2.315 -HYPERVISOR_crash(
   2.316 -    void)
   2.317 -{
   2.318 -    int ret;
   2.319 -    unsigned long ign1;
   2.320 -    __asm__ __volatile__ (
   2.321 -        TRAP_INSTR
   2.322 -        : "=a" (ret), "=b" (ign1)
   2.323 -	: "0" (__HYPERVISOR_sched_op),
   2.324 -	  "1" (SCHEDOP_shutdown | (SHUTDOWN_crash << SCHEDOP_reasonshift))
   2.325 -        : "memory", "ecx" );
   2.326 -
   2.327 -    return ret;
   2.328 +	return _hypercall2(int, sched_op, cmd, arg);
   2.329  }
   2.330  
   2.331  static inline long
   2.332  HYPERVISOR_set_timer_op(
   2.333 -    u64 timeout)
   2.334 +	u64 timeout)
   2.335  {
   2.336 -    int ret;
   2.337 -    unsigned long timeout_hi = (unsigned long)(timeout>>32);
   2.338 -    unsigned long timeout_lo = (unsigned long)timeout;
   2.339 -    unsigned long ign1, ign2;
   2.340 -
   2.341 -    __asm__ __volatile__ (
   2.342 -        TRAP_INSTR
   2.343 -        : "=a" (ret), "=b" (ign1), "=c" (ign2)
   2.344 -	: "0" (__HYPERVISOR_set_timer_op), "b" (timeout_lo), "c" (timeout_hi)
   2.345 -	: "memory");
   2.346 -
   2.347 -    return ret;
   2.348 +	unsigned long timeout_hi = (unsigned long)(timeout>>32);
   2.349 +	unsigned long timeout_lo = (unsigned long)timeout;
   2.350 +	return _hypercall2(long, set_timer_op, timeout_lo, timeout_hi);
   2.351  }
   2.352  
   2.353 -#if 0
   2.354  static inline int
   2.355  HYPERVISOR_dom0_op(
   2.356 -    dom0_op_t *dom0_op)
   2.357 +	dom0_op_t *dom0_op)
   2.358  {
   2.359 -    int ret;
   2.360 -    unsigned long ign1;
   2.361 -
   2.362 -    dom0_op->interface_version = DOM0_INTERFACE_VERSION;
   2.363 -    __asm__ __volatile__ (
   2.364 -        TRAP_INSTR
   2.365 -        : "=a" (ret), "=b" (ign1)
   2.366 -	: "0" (__HYPERVISOR_dom0_op), "1" (dom0_op)
   2.367 -	: "memory");
   2.368 -
   2.369 -    return ret;
   2.370 +	dom0_op->interface_version = DOM0_INTERFACE_VERSION;
   2.371 +	return _hypercall1(int, dom0_op, dom0_op);
   2.372  }
   2.373 -#endif
   2.374  
   2.375  static inline int
   2.376  HYPERVISOR_set_debugreg(
   2.377 -    int reg, unsigned long value)
   2.378 +	int reg, unsigned long value)
   2.379  {
   2.380 -    int ret;
   2.381 -    unsigned long ign1, ign2;
   2.382 -    __asm__ __volatile__ (
   2.383 -        TRAP_INSTR
   2.384 -        : "=a" (ret), "=b" (ign1), "=c" (ign2)
   2.385 -	: "0" (__HYPERVISOR_set_debugreg), "1" (reg), "2" (value)
   2.386 -	: "memory" );
   2.387 -
   2.388 -    return ret;
   2.389 +	return _hypercall2(int, set_debugreg, reg, value);
   2.390  }
   2.391  
   2.392  static inline unsigned long
   2.393  HYPERVISOR_get_debugreg(
   2.394 -    int reg)
   2.395 +	int reg)
   2.396  {
   2.397 -    unsigned long ret;
   2.398 -    unsigned long ign;
   2.399 -    __asm__ __volatile__ (
   2.400 -        TRAP_INSTR
   2.401 -        : "=a" (ret), "=b" (ign)
   2.402 -	: "0" (__HYPERVISOR_get_debugreg), "1" (reg)
   2.403 -	: "memory" );
   2.404 -
   2.405 -    return ret;
   2.406 +	return _hypercall1(unsigned long, get_debugreg, reg);
   2.407  }
   2.408  
   2.409  static inline int
   2.410  HYPERVISOR_update_descriptor(
   2.411 -    u64 ma, u64 desc)
   2.412 +	u64 ma, u64 desc)
   2.413  {
   2.414 -    int ret;
   2.415 -    unsigned long ign1, ign2, ign3, ign4;
   2.416 -
   2.417 -    __asm__ __volatile__ (
   2.418 -        TRAP_INSTR
   2.419 -        : "=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3), "=S" (ign4)
   2.420 -	: "0" (__HYPERVISOR_update_descriptor),
   2.421 -	  "1" ((unsigned long)ma), "2" ((unsigned long)(ma>>32)),
   2.422 -	  "3" ((unsigned long)desc), "4" ((unsigned long)(desc>>32))
   2.423 -	: "memory" );
   2.424 -
   2.425 -    return ret;
   2.426 +	return _hypercall4(int, update_descriptor, ma, ma>>32, desc, desc>>32);
   2.427  }
   2.428  
   2.429  static inline int
   2.430 -HYPERVISOR_dom_mem_op(
   2.431 -    unsigned int op, unsigned long *extent_list,
   2.432 -    unsigned long nr_extents, unsigned int extent_order)
   2.433 +HYPERVISOR_memory_op(
   2.434 +	unsigned int cmd, void *arg)
   2.435  {
   2.436 -    int ret;
   2.437 -    unsigned long ign1, ign2, ign3, ign4, ign5;
   2.438 -
   2.439 -    __asm__ __volatile__ (
   2.440 -        TRAP_INSTR
   2.441 -        : "=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3), "=S" (ign4),
   2.442 -	  "=D" (ign5)
   2.443 -	: "0" (__HYPERVISOR_dom_mem_op), "1" (op), "2" (extent_list),
   2.444 -	  "3" (nr_extents), "4" (extent_order), "5" (DOMID_SELF)
   2.445 -        : "memory" );
   2.446 -
   2.447 -    return ret;
   2.448 +	return _hypercall2(int, memory_op, cmd, arg);
   2.449  }
   2.450  
   2.451  static inline int
   2.452  HYPERVISOR_multicall(
   2.453 -    void *call_list, int nr_calls)
   2.454 +	void *call_list, int nr_calls)
   2.455  {
   2.456 -    int ret;
   2.457 -    unsigned long ign1, ign2;
   2.458 -
   2.459 -    __asm__ __volatile__ (
   2.460 -        TRAP_INSTR
   2.461 -        : "=a" (ret), "=b" (ign1), "=c" (ign2)
   2.462 -	: "0" (__HYPERVISOR_multicall), "1" (call_list), "2" (nr_calls)
   2.463 -	: "memory" );
   2.464 -
   2.465 -    return ret;
   2.466 +	return _hypercall2(int, multicall, call_list, nr_calls);
   2.467  }
   2.468  
   2.469  static inline int
   2.470  HYPERVISOR_update_va_mapping(
   2.471 -    unsigned long va, pte_t new_val, unsigned long flags)
   2.472 +	unsigned long va, pte_t new_val, unsigned long flags)
   2.473  {
   2.474 -    int ret;
   2.475 -    unsigned long ign1, ign2, ign3, ign4;
   2.476 -
   2.477 -    __asm__ __volatile__ (
   2.478 -        TRAP_INSTR
   2.479 -        : "=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3), "=S" (ign4)
   2.480 -	: "0" (__HYPERVISOR_update_va_mapping), 
   2.481 -          "1" (va), "2" ((new_val).pte_low),
   2.482 +	unsigned long pte_hi = 0;
   2.483  #ifdef CONFIG_X86_PAE
   2.484 -	  "3" ((new_val).pte_high),
   2.485 -#else
   2.486 -	  "3" (0),
   2.487 +	pte_hi = new_val.pte_high;
   2.488  #endif
   2.489 -	  "4" (flags)
   2.490 -	: "memory" );
   2.491 -
   2.492 -    return ret;
   2.493 +	return _hypercall4(int, update_va_mapping, va,
   2.494 +			   new_val.pte_low, pte_hi, flags);
   2.495  }
   2.496  
   2.497  static inline int
   2.498  HYPERVISOR_event_channel_op(
   2.499 -    void *op)
   2.500 +	void *op)
   2.501  {
   2.502 -    int ret;
   2.503 -    unsigned long ignore;
   2.504 -    __asm__ __volatile__ (
   2.505 -        TRAP_INSTR
   2.506 -        : "=a" (ret), "=b" (ignore)
   2.507 -	: "0" (__HYPERVISOR_event_channel_op), "1" (op)
   2.508 -	: "memory" );
   2.509 -
   2.510 -    return ret;
   2.511 +	return _hypercall1(int, event_channel_op, op);
   2.512  }
   2.513  
   2.514  static inline int
   2.515  HYPERVISOR_xen_version(
   2.516 -    int cmd, void *arg)
   2.517 +	int cmd, void *arg)
   2.518  {
   2.519 -    int ret;
   2.520 -    unsigned long ignore, ign2;
   2.521 -
   2.522 -    __asm__ __volatile__ (
   2.523 -        TRAP_INSTR
   2.524 -        : "=a" (ret), "=b" (ignore), "=c" (ign2)
   2.525 -	: "0" (__HYPERVISOR_xen_version), "1" (cmd), "2" (arg)
   2.526 -	: "memory" );
   2.527 -
   2.528 -    return ret;
   2.529 +	return _hypercall2(int, xen_version, cmd, arg);
   2.530  }
   2.531  
   2.532  static inline int
   2.533  HYPERVISOR_console_io(
   2.534 -    int cmd, int count, char *str)
   2.535 +	int cmd, int count, char *str)
   2.536  {
   2.537 -    int ret;
   2.538 -    unsigned long ign1, ign2, ign3;
   2.539 -    __asm__ __volatile__ (
   2.540 -        TRAP_INSTR
   2.541 -        : "=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3)
   2.542 -	: "0" (__HYPERVISOR_console_io), "1" (cmd), "2" (count), "3" (str)
   2.543 -	: "memory" );
   2.544 -
   2.545 -    return ret;
   2.546 +	return _hypercall3(int, console_io, cmd, count, str);
   2.547  }
   2.548  
   2.549  static inline int
   2.550  HYPERVISOR_physdev_op(
   2.551 -    void *physdev_op)
   2.552 +	void *physdev_op)
   2.553  {
   2.554 -    int ret;
   2.555 -    unsigned long ign;
   2.556 -
   2.557 -    __asm__ __volatile__ (
   2.558 -        TRAP_INSTR
   2.559 -        : "=a" (ret), "=b" (ign)
   2.560 -	: "0" (__HYPERVISOR_physdev_op), "1" (physdev_op)
   2.561 -	: "memory" );
   2.562 -
   2.563 -    return ret;
   2.564 +	return _hypercall1(int, physdev_op, physdev_op);
   2.565  }
   2.566  
   2.567  static inline int
   2.568  HYPERVISOR_grant_table_op(
   2.569 -    unsigned int cmd, void *uop, unsigned int count)
   2.570 +	unsigned int cmd, void *uop, unsigned int count)
   2.571  {
   2.572 -    int ret;
   2.573 -    unsigned long ign1, ign2, ign3;
   2.574 -
   2.575 -    __asm__ __volatile__ (
   2.576 -        TRAP_INSTR
   2.577 -        : "=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3)
   2.578 -	: "0" (__HYPERVISOR_grant_table_op), "1" (cmd), "2" (uop), "3" (count)
   2.579 -	: "memory" );
   2.580 -
   2.581 -    return ret;
   2.582 +	return _hypercall3(int, grant_table_op, cmd, uop, count);
   2.583  }
   2.584  
   2.585  static inline int
   2.586  HYPERVISOR_update_va_mapping_otherdomain(
   2.587 -    unsigned long va, pte_t new_val, unsigned long flags, domid_t domid)
   2.588 +	unsigned long va, pte_t new_val, unsigned long flags, domid_t domid)
   2.589  {
   2.590 -    int ret;
   2.591 -    unsigned long ign1, ign2, ign3, ign4, ign5;
   2.592 -
   2.593 -    __asm__ __volatile__ (
   2.594 -        TRAP_INSTR
   2.595 -        : "=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3),
   2.596 -	  "=S" (ign4), "=D" (ign5)
   2.597 -	: "0" (__HYPERVISOR_update_va_mapping_otherdomain),
   2.598 -          "1" (va), "2" ((new_val).pte_low),
   2.599 +	unsigned long pte_hi = 0;
   2.600  #ifdef CONFIG_X86_PAE
   2.601 -	  "3" ((new_val).pte_high),
   2.602 -#else
   2.603 -	  "3" (0),
   2.604 +	pte_hi = new_val.pte_high;
   2.605  #endif
   2.606 -	  "4" (flags), "5" (domid) :
   2.607 -        "memory" );
   2.608 -    
   2.609 -    return ret;
   2.610 +	return _hypercall5(int, update_va_mapping_otherdomain, va,
   2.611 +			   new_val.pte_low, pte_hi, flags, domid);
   2.612  }
   2.613  
   2.614  static inline int
   2.615  HYPERVISOR_vm_assist(
   2.616 -    unsigned int cmd, unsigned int type)
   2.617 +	unsigned int cmd, unsigned int type)
   2.618  {
   2.619 -    int ret;
   2.620 -    unsigned long ign1, ign2;
   2.621 -
   2.622 -    __asm__ __volatile__ (
   2.623 -        TRAP_INSTR
   2.624 -        : "=a" (ret), "=b" (ign1), "=c" (ign2)
   2.625 -	: "0" (__HYPERVISOR_vm_assist), "1" (cmd), "2" (type)
   2.626 -	: "memory" );
   2.627 -
   2.628 -    return ret;
   2.629 -}
   2.630 -
   2.631 -static inline int
   2.632 -HYPERVISOR_boot_vcpu(
   2.633 -    unsigned long vcpu, vcpu_guest_context_t *ctxt)
   2.634 -{
   2.635 -    int ret;
   2.636 -    unsigned long ign1, ign2;
   2.637 -
   2.638 -    __asm__ __volatile__ (
   2.639 -        TRAP_INSTR
   2.640 -        : "=a" (ret), "=b" (ign1), "=c" (ign2)
   2.641 -	: "0" (__HYPERVISOR_boot_vcpu), "1" (vcpu), "2" (ctxt)
   2.642 -	: "memory");
   2.643 -
   2.644 -    return ret;
   2.645 +	return _hypercall2(int, vm_assist, cmd, type);
   2.646  }
   2.647  
   2.648  static inline int
   2.649 -HYPERVISOR_vcpu_down(
   2.650 -    int vcpu)
   2.651 +HYPERVISOR_vcpu_op(
   2.652 +	int cmd, int vcpuid, void *extra_args)
   2.653  {
   2.654 -    int ret;
   2.655 -    unsigned long ign1;
   2.656 -    /* Yes, I really do want to clobber edx here: when we resume a
   2.657 -       vcpu after unpickling a multi-processor domain, it returns
   2.658 -       here, but clobbers all of the call clobbered registers. */
   2.659 -    __asm__ __volatile__ (
   2.660 -        TRAP_INSTR
   2.661 -        : "=a" (ret), "=b" (ign1)
   2.662 -	: "0" (__HYPERVISOR_sched_op),
   2.663 -	  "1" (SCHEDOP_vcpu_down | (vcpu << SCHEDOP_vcpushift))
   2.664 -        : "memory", "ecx", "edx" );
   2.665 -
   2.666 -    return ret;
   2.667 +	return _hypercall3(int, vcpu_op, cmd, vcpuid, extra_args);
   2.668  }
   2.669  
   2.670  static inline int
   2.671 -HYPERVISOR_vcpu_up(
   2.672 -    int vcpu)
   2.673 +HYPERVISOR_suspend(
   2.674 +	unsigned long srec)
   2.675  {
   2.676 -    int ret;
   2.677 -    unsigned long ign1;
   2.678 -    __asm__ __volatile__ (
   2.679 -        TRAP_INSTR
   2.680 -        : "=a" (ret), "=b" (ign1)
   2.681 -	: "0" (__HYPERVISOR_sched_op),
   2.682 -	  "1" (SCHEDOP_vcpu_up | (vcpu << SCHEDOP_vcpushift))
   2.683 -        : "memory", "ecx" );
   2.684 -
   2.685 -    return ret;
   2.686 +	return _hypercall3(int, sched_op, SCHEDOP_shutdown,
   2.687 +			   SHUTDOWN_suspend, srec);
   2.688  }
   2.689  
   2.690 -static inline int
   2.691 -HYPERVISOR_vcpu_pickle(
   2.692 -    int vcpu, vcpu_guest_context_t *ctxt)
   2.693 -{
   2.694 -    int ret;
   2.695 -    unsigned long ign1, ign2;
   2.696 -    __asm__ __volatile__ (
   2.697 -        TRAP_INSTR
   2.698 -        : "=a" (ret), "=b" (ign1), "=c" (ign2)
   2.699 -	: "0" (__HYPERVISOR_sched_op),
   2.700 -	  "1" (SCHEDOP_vcpu_pickle | (vcpu << SCHEDOP_vcpushift)),
   2.701 -	  "2" (ctxt)
   2.702 -        : "memory" );
   2.703 -
   2.704 -    return ret;
   2.705 -}
   2.706 +#endif /* __HYPERCALL_H__ */
   2.707  #elif defined(__x86_64__)
   2.708  
   2.709  #define __syscall_clobber "r11","rcx","memory"
   2.710 @@ -792,106 +526,4 @@ HYPERVISOR_set_timer_op(
   2.711  }
   2.712  #endif
   2.713  
   2.714 -
   2.715 -static __inline__ int HYPERVISOR_dom0_op(void *dom0_op)
   2.716 -{
   2.717 -    int ret;
   2.718 -    __asm__ __volatile__ (
   2.719 -        TRAP_INSTR
   2.720 -        : "=a" (ret) : "0" (__HYPERVISOR_dom0_op),
   2.721 -        _a1 (dom0_op) : "memory" );
   2.722 -
   2.723 -    return ret;
   2.724 -}
   2.725 -
   2.726 -static __inline__ int HYPERVISOR_set_debugreg(int reg, unsigned long value)
   2.727 -{
   2.728 -    int ret;
   2.729 -    __asm__ __volatile__ (
   2.730 -        TRAP_INSTR
   2.731 -        : "=a" (ret) : "0" (__HYPERVISOR_set_debugreg),
   2.732 -        _a1 (reg), _a2 (value) : "memory" );
   2.733 -
   2.734 -    return ret;
   2.735 -}
   2.736 -
   2.737 -static __inline__ unsigned long HYPERVISOR_get_debugreg(int reg)
   2.738 -{
   2.739 -    unsigned long ret;
   2.740 -    __asm__ __volatile__ (
   2.741 -        TRAP_INSTR
   2.742 -        : "=a" (ret) : "0" (__HYPERVISOR_get_debugreg),
   2.743 -        _a1 (reg) : "memory" );
   2.744 -
   2.745 -    return ret;
   2.746 -}
   2.747 -
   2.748 -static __inline__ int HYPERVISOR_update_descriptor(
   2.749 -    unsigned long pa, unsigned long word1, unsigned long word2)
   2.750 -{
   2.751 -    int ret;
   2.752 -    __asm__ __volatile__ (
   2.753 -        TRAP_INSTR
   2.754 -        : "=a" (ret) : "0" (__HYPERVISOR_update_descriptor), 
   2.755 -        _a1 (pa), _a2 (word1), _a3 (word2) : "memory" );
   2.756 -
   2.757 -    return ret;
   2.758 -}
   2.759 -
   2.760 -static __inline__ int HYPERVISOR_dom_mem_op(void *dom_mem_op)
   2.761 -{
   2.762 -    int ret;
   2.763 -    __asm__ __volatile__ (
   2.764 -        TRAP_INSTR
   2.765 -        : "=a" (ret) : "0" (__HYPERVISOR_memory_op),
   2.766 -        _a1 (dom_mem_op) : "memory" );
   2.767 -
   2.768 -    return ret;
   2.769 -}
   2.770 -
   2.771 -static __inline__ int HYPERVISOR_multicall(void *call_list, int nr_calls)
   2.772 -{
   2.773 -    int ret;
   2.774 -    __asm__ __volatile__ (
   2.775 -        TRAP_INSTR
   2.776 -        : "=a" (ret) : "0" (__HYPERVISOR_multicall),
   2.777 -        _a1 (call_list), _a2 (nr_calls) : "memory" );
   2.778 -
   2.779 -    return ret;
   2.780 -}
   2.781 -
   2.782 -static __inline__ int HYPERVISOR_update_va_mapping(
   2.783 -    unsigned long page_nr, unsigned long new_val, unsigned long flags)
   2.784 -{
   2.785 -    int ret;
   2.786 -    __asm__ __volatile__ (
   2.787 -        TRAP_INSTR
   2.788 -        : "=a" (ret) : "0" (__HYPERVISOR_update_va_mapping), 
   2.789 -        _a1 (page_nr), _a2 (new_val), _a3 (flags) : "memory" );
   2.790 -
   2.791 -    return ret;
   2.792 -}
   2.793 -
   2.794 -static __inline__ int HYPERVISOR_xen_version(int cmd)
   2.795 -{
   2.796 -    int ret;
   2.797 -    __asm__ __volatile__ (
   2.798 -        TRAP_INSTR
   2.799 -        : "=a" (ret) : "0" (__HYPERVISOR_xen_version), 
   2.800 -        _a1 (cmd) : "memory" );
   2.801 -
   2.802 -    return ret;
   2.803 -}
   2.804 -
   2.805 -static __inline__ int HYPERVISOR_console_io(int cmd, int count, char *str)
   2.806 -{
   2.807 -    int ret;
   2.808 -    __asm__ __volatile__ (
   2.809 -        TRAP_INSTR
   2.810 -        : "=a" (ret) : "0" (__HYPERVISOR_console_io),
   2.811 -        _a1 (cmd), _a2 (count), _a3 (str) : "memory" );
   2.812 -
   2.813 -    return ret;
   2.814 -}
   2.815 -
   2.816  #endif /* __HYPERVISOR_H__ */
     3.1 --- a/extras/mini-os/include/os.h	Sun Oct 30 13:52:38 2005 +0100
     3.2 +++ b/extras/mini-os/include/os.h	Sun Oct 30 14:00:35 2005 +0100
     3.3 @@ -24,7 +24,7 @@
     3.4  #include <xen/xen.h>
     3.5  
     3.6  
     3.7 -#define force_evtchn_callback() ((void)HYPERVISOR_xen_version(0))
     3.8 +#define force_evtchn_callback() ((void)HYPERVISOR_xen_version(0, 0))
     3.9  
    3.10  #define __KERNEL_CS  FLAT_KERNEL_CS
    3.11  #define __KERNEL_DS  FLAT_KERNEL_DS
    3.12 @@ -55,6 +55,8 @@
    3.13  /* Everything below this point is not included by assembler (.S) files. */
    3.14  #ifndef __ASSEMBLY__
    3.15  
    3.16 +extern shared_info_t *HYPERVISOR_shared_info;
    3.17 +
    3.18  void trap_init(void);
    3.19  
    3.20  /* 
     4.1 --- a/extras/mini-os/include/types.h	Sun Oct 30 13:52:38 2005 +0100
     4.2 +++ b/extras/mini-os/include/types.h	Sun Oct 30 14:00:35 2005 +0100
     4.3 @@ -54,7 +54,14 @@ typedef unsigned long       uintptr_t;
     4.4  typedef struct { unsigned long pte; } pte_t;
     4.5  #endif
     4.6  
     4.7 -
     4.8 +typedef  u8 uint8_t;
     4.9 +typedef  s8 int8_t;
    4.10 +typedef u16 uint16_t;
    4.11 +typedef s16 int16_t;
    4.12 +typedef u32 uint32_t;
    4.13 +typedef s32 int32_t;
    4.14 +typedef u64 uint64_t;
    4.15 +typedef s64 int64_t;
    4.16  
    4.17  
    4.18  #define INT_MAX         ((int)(~0U>>1))
     5.1 --- a/extras/mini-os/kernel.c	Sun Oct 30 13:52:38 2005 +0100
     5.2 +++ b/extras/mini-os/kernel.c	Sun Oct 30 14:00:35 2005 +0100
     5.3 @@ -61,7 +61,7 @@ void failsafe_callback(void);
     5.4  
     5.5  extern char shared_info[PAGE_SIZE];
     5.6  
     5.7 -#define __pte(x) ((pte_t) { (0) } )
     5.8 +#define __pte(x) ((pte_t) { (x) } )
     5.9  
    5.10  static shared_info_t *map_shared_info(unsigned long pa)
    5.11  {
    5.12 @@ -150,5 +150,5 @@ void start_kernel(start_info_t *si)
    5.13  void do_exit(void)
    5.14  {
    5.15      printk("do_exit called!\n");
    5.16 -    for ( ;; ) HYPERVISOR_shutdown();
    5.17 +    for ( ;; ) HYPERVISOR_sched_op(SCHEDOP_shutdown, SHUTDOWN_crash);
    5.18  }
     6.1 --- a/extras/mini-os/time.c	Sun Oct 30 13:52:38 2005 +0100
     6.2 +++ b/extras/mini-os/time.c	Sun Oct 30 14:00:35 2005 +0100
     6.3 @@ -208,7 +208,7 @@ void block_domain(u32 millisecs)
     6.4      struct timeval tv;
     6.5      gettimeofday(&tv);
     6.6      HYPERVISOR_set_timer_op(monotonic_clock() + 1000000LL * (s64) millisecs);
     6.7 -    HYPERVISOR_block();
     6.8 +    HYPERVISOR_sched_op(SCHEDOP_block, 0);
     6.9  }
    6.10  
    6.11  
     7.1 --- a/extras/mini-os/xenbus/xenbus_xs.c	Sun Oct 30 13:52:38 2005 +0100
     7.2 +++ b/extras/mini-os/xenbus/xenbus_xs.c	Sun Oct 30 14:00:35 2005 +0100
     7.3 @@ -39,7 +39,7 @@
     7.4  #include <wait.h>
     7.5  #include <sched.h>
     7.6  #include <semaphore.h>
     7.7 -#include "xenstored.h"
     7.8 +#include <xen/io/xs_wire.h>
     7.9  #include "xenbus_comms.h"
    7.10  
    7.11  #define streq(a, b) (strcmp((a), (b)) == 0)
    7.12 @@ -408,7 +408,12 @@ static char *xs_read_watch(char **token)
    7.13  
    7.14  static int xs_acknowledge_watch(const char *token)
    7.15  {
    7.16 +#if 0
    7.17  	return xs_error(xs_single(XS_WATCH_ACK, token, NULL));
    7.18 +#else
    7.19 +	/* XS_WATCH_ACK is no longer available */
    7.20 +	return 0;
    7.21 +#endif
    7.22  }
    7.23  
    7.24  static int xs_unwatch(const char *path, const char *token)
     8.1 --- a/linux-2.6-xen-sparse/arch/ia64/xen/drivers/evtchn_ia64.c	Sun Oct 30 13:52:38 2005 +0100
     8.2 +++ b/linux-2.6-xen-sparse/arch/ia64/xen/drivers/evtchn_ia64.c	Sun Oct 30 14:00:35 2005 +0100
     8.3 @@ -29,7 +29,7 @@ unsigned int bind_virq_to_evtchn(int vir
     8.4      return op.u.bind_virq.port;
     8.5  }
     8.6  
     8.7 -int bind_virq_to_irq(int virq)
     8.8 +int bind_virq_to_irq(int virq, int cpu)
     8.9  {
    8.10  	printk("bind_virq_to_irq called... FIXME??\n");
    8.11  	while(1);
    8.12 @@ -66,7 +66,11 @@ int bind_evtchn_to_irqhandler(unsigned i
    8.13      evtchns[evtchn].handler = handler;
    8.14      evtchns[evtchn].dev_id = dev_id;
    8.15      unmask_evtchn(evtchn);
    8.16 -    return 0;
    8.17 +    //return 0;
    8.18 +    /* On ia64, there's only one irq vector allocated for all event channels,
    8.19 +     * so let's just return evtchn as handle for later communication
    8.20 +     */
    8.21 +    return evtchn;
    8.22  }
    8.23  
    8.24  void unbind_evtchn_from_irqhandler(unsigned int evtchn, void *dev_id)
     9.1 --- a/linux-2.6-xen-sparse/arch/ia64/xen/xenentry.S	Sun Oct 30 13:52:38 2005 +0100
     9.2 +++ b/linux-2.6-xen-sparse/arch/ia64/xen/xenentry.S	Sun Oct 30 14:00:35 2005 +0100
     9.3 @@ -46,8 +46,6 @@ GLOBAL_ENTRY(ia64_switch_to)
     9.4  	.prologue
     9.5  	alloc r16=ar.pfs,1,0,0,0
     9.6  #endif
     9.7 -	.prologue
     9.8 -	alloc r16=ar.pfs,1,0,0,0
     9.9  	DO_SAVE_SWITCH_STACK
    9.10  	.body
    9.11  
    10.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/kernel/entry.S	Sun Oct 30 13:52:38 2005 +0100
    10.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/entry.S	Sun Oct 30 14:00:35 2005 +0100
    10.3 @@ -653,7 +653,7 @@ ENTRY(simd_coprocessor_error)
    10.4  ENTRY(device_not_available)
    10.5  	pushl $-1			# mark this as an int
    10.6  	SAVE_ALL
    10.7 -	preempt_stop
    10.8 +	#preempt_stop /* This is already an interrupt gate on Xen. */
    10.9  	call math_state_restore
   10.10  	jmp ret_from_exception
   10.11  
    11.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/kernel/process.c	Sun Oct 30 13:52:38 2005 +0100
    11.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/process.c	Sun Oct 30 14:00:35 2005 +0100
    11.3 @@ -483,6 +483,9 @@ struct task_struct fastcall * __switch_t
    11.4  		mcl->args[0] = 1;
    11.5  		mcl++;
    11.6  	}
    11.7 +#if 0 /* lazy fpu sanity check */
    11.8 +	else BUG_ON(!(read_cr0() & 8));
    11.9 +#endif
   11.10  
   11.11  	/*
   11.12  	 * Reload esp0, LDT and the page table pointer:
    12.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/kernel/traps.c	Sun Oct 30 13:52:38 2005 +0100
    12.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/traps.c	Sun Oct 30 14:00:35 2005 +0100
    12.3 @@ -648,6 +648,12 @@ fastcall void do_int3(struct pt_regs *re
    12.4  }
    12.5  #endif
    12.6  
    12.7 +static inline void conditional_sti(struct pt_regs *regs)
    12.8 +{
    12.9 +	if ((uint8_t)(regs->xcs >> 16) == 0)
   12.10 +		local_irq_enable();
   12.11 +}
   12.12 +
   12.13  /*
   12.14   * Our handling of the processor debug registers is non-trivial.
   12.15   * We do not clear them on entry and exit from the kernel. Therefore
   12.16 @@ -680,11 +686,9 @@ fastcall void do_debug(struct pt_regs * 
   12.17  	if (notify_die(DIE_DEBUG, "debug", regs, condition, error_code,
   12.18  					SIGTRAP) == NOTIFY_STOP)
   12.19  		return;
   12.20 -#if 0
   12.21 +
   12.22  	/* It's safe to allow irq's after DR6 has been saved */
   12.23 -	if (regs->eflags & X86_EFLAGS_IF)
   12.24 -		local_irq_enable();
   12.25 -#endif
   12.26 +	conditional_sti(regs);
   12.27  
   12.28  	/* Mask out spurious debug traps due to lazy DR7 setting */
   12.29  	if (condition & (DR_TRAP0|DR_TRAP1|DR_TRAP2|DR_TRAP3)) {
   12.30 @@ -967,15 +971,18 @@ void __init trap_init_f00f_bug(void)
   12.31  #endif
   12.32  
   12.33  
   12.34 -/* NB. All these are "trap gates" (i.e. events_mask isn't cleared). */
   12.35 +/*
   12.36 + * NB. All these are "trap gates" (i.e. events_mask isn't cleared) except
   12.37 + * for those that specify <dpl>|4 in the second field.
   12.38 + */
   12.39  static trap_info_t trap_table[] = {
   12.40  	{  0, 0, __KERNEL_CS, (unsigned long)divide_error		},
   12.41 -	{  1, 0, __KERNEL_CS, (unsigned long)debug			},
   12.42 -	{  3, 3, __KERNEL_CS, (unsigned long)int3			},
   12.43 +	{  1, 0|4, __KERNEL_CS, (unsigned long)debug			},
   12.44 +	{  3, 3|4, __KERNEL_CS, (unsigned long)int3			},
   12.45  	{  4, 3, __KERNEL_CS, (unsigned long)overflow			},
   12.46  	{  5, 3, __KERNEL_CS, (unsigned long)bounds			},
   12.47  	{  6, 0, __KERNEL_CS, (unsigned long)invalid_op			},
   12.48 -	{  7, 0, __KERNEL_CS, (unsigned long)device_not_available	},
   12.49 +	{  7, 0|4, __KERNEL_CS, (unsigned long)device_not_available	},
   12.50  	{  9, 0, __KERNEL_CS, (unsigned long)coprocessor_segment_overrun },
   12.51  	{ 10, 0, __KERNEL_CS, (unsigned long)invalid_TSS		},
   12.52  	{ 11, 0, __KERNEL_CS, (unsigned long)segment_not_present	},
    13.1 --- a/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/setup.c	Sun Oct 30 13:52:38 2005 +0100
    13.2 +++ b/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/setup.c	Sun Oct 30 14:00:35 2005 +0100
    13.3 @@ -733,6 +733,7 @@ void __init setup_arch(char **cmdline_p)
    13.4  #ifdef CONFIG_XEN
    13.5  	{
    13.6  		int i, j, k, fpp;
    13.7 +		unsigned long va;
    13.8  
    13.9  		/* Make sure we have a large enough P->M table. */
   13.10  		phys_to_machine_mapping = alloc_bootmem(
   13.11 @@ -746,9 +747,21 @@ void __init setup_arch(char **cmdline_p)
   13.12  			__pa(xen_start_info->mfn_list), 
   13.13  			PFN_PHYS(PFN_UP(xen_start_info->nr_pages *
   13.14  					sizeof(unsigned long))));
   13.15 -		make_pages_readonly((void *)xen_start_info->mfn_list,
   13.16 -				    PFN_UP(xen_start_info->nr_pages *
   13.17 -					   sizeof(unsigned long)));
   13.18 +
   13.19 +		/* 'Initial mapping' of old p2m table must be destroyed. */
   13.20 +		for (va = xen_start_info->mfn_list;
   13.21 +		     va < (xen_start_info->mfn_list +
   13.22 +			   (xen_start_info->nr_pages*sizeof(unsigned long)));
   13.23 +		     va += PAGE_SIZE) {
   13.24 +			HYPERVISOR_update_va_mapping(va, __pte_ma(0), 0);
   13.25 +		}
   13.26 +
   13.27 +		/* 'Initial mapping' of initrd must be destroyed. */
   13.28 +		for (va = xen_start_info->mod_start;
   13.29 +		     va < (xen_start_info->mod_start+xen_start_info->mod_len);
   13.30 +		     va += PAGE_SIZE) {
   13.31 +			HYPERVISOR_update_va_mapping(va, __pte_ma(0), 0);
   13.32 +		}
   13.33  
   13.34  		/* 
   13.35  		 * Initialise the list of the frames that specify the list of 
    14.1 --- a/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/xen_entry.S	Sun Oct 30 13:52:38 2005 +0100
    14.2 +++ b/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/xen_entry.S	Sun Oct 30 14:00:35 2005 +0100
    14.3 @@ -5,7 +5,7 @@
    14.4  #define evtchn_upcall_pending		0
    14.5  #define evtchn_upcall_mask		1
    14.6  
    14.7 -#define sizeof_vcpu_shift		3
    14.8 +#define sizeof_vcpu_shift		4
    14.9  
   14.10  #ifdef CONFIG_SMP
   14.11  //#define preempt_disable(reg)	incl threadinfo_preempt_count(reg)
    15.1 --- a/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c	Sun Oct 30 13:52:38 2005 +0100
    15.2 +++ b/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c	Sun Oct 30 14:00:35 2005 +0100
    15.3 @@ -191,12 +191,13 @@ static int increase_reservation(unsigned
    15.4  	rc = HYPERVISOR_memory_op(
    15.5  		XENMEM_increase_reservation, &reservation);
    15.6  	if (rc < nr_pages) {
    15.7 +		int ret;
    15.8  		/* We hit the Xen hard limit: reprobe. */
    15.9  		reservation.extent_start = mfn_list;
   15.10  		reservation.nr_extents   = rc;
   15.11 -		BUG_ON(HYPERVISOR_memory_op(
   15.12 -			XENMEM_decrease_reservation,
   15.13 -			&reservation) != rc);
   15.14 +		ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation,
   15.15 +				&reservation);
   15.16 +		BUG_ON(ret != rc);
   15.17  		hard_limit = current_pages + rc - driver_pages;
   15.18  		goto out;
   15.19  	}
   15.20 @@ -213,11 +214,14 @@ static int increase_reservation(unsigned
   15.21  		xen_machphys_update(mfn_list[i], pfn);
   15.22              
   15.23  		/* Link back into the page tables if not highmem. */
   15.24 -		if (pfn < max_low_pfn)
   15.25 -			BUG_ON(HYPERVISOR_update_va_mapping(
   15.26 +		if (pfn < max_low_pfn) {
   15.27 +			int ret;
   15.28 +			ret = HYPERVISOR_update_va_mapping(
   15.29  				(unsigned long)__va(pfn << PAGE_SHIFT),
   15.30  				pfn_pte_ma(mfn_list[i], PAGE_KERNEL),
   15.31 -				0));
   15.32 +				0);
   15.33 +			BUG_ON(ret);
   15.34 +		}
   15.35  
   15.36  		/* Relinquish the page back to the allocator. */
   15.37  		ClearPageReserved(page);
   15.38 @@ -242,6 +246,7 @@ static int decrease_reservation(unsigned
   15.39  	struct page   *page;
   15.40  	void          *v;
   15.41  	int            need_sleep = 0;
   15.42 +	int ret;
   15.43  	struct xen_memory_reservation reservation = {
   15.44  		.address_bits = 0,
   15.45  		.extent_order = 0,
   15.46 @@ -268,8 +273,9 @@ static int decrease_reservation(unsigned
   15.47  		if (!PageHighMem(page)) {
   15.48  			v = phys_to_virt(pfn << PAGE_SHIFT);
   15.49  			scrub_pages(v, 1);
   15.50 -			BUG_ON(HYPERVISOR_update_va_mapping(
   15.51 -				(unsigned long)v, __pte_ma(0), 0));
   15.52 +			ret = HYPERVISOR_update_va_mapping(
   15.53 +				(unsigned long)v, __pte_ma(0), 0);
   15.54 +			BUG_ON(ret);
   15.55  		}
   15.56  #ifdef CONFIG_XEN_SCRUB_PAGES
   15.57  		else {
   15.58 @@ -295,8 +301,8 @@ static int decrease_reservation(unsigned
   15.59  
   15.60  	reservation.extent_start = mfn_list;
   15.61  	reservation.nr_extents   = nr_pages;
   15.62 -	BUG_ON(HYPERVISOR_memory_op(
   15.63 -		XENMEM_decrease_reservation, &reservation) != nr_pages);
   15.64 +	ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation, &reservation);
   15.65 +	BUG_ON(ret != nr_pages);
   15.66  
   15.67  	current_pages -= nr_pages;
   15.68  	totalram_pages = current_pages;
   15.69 @@ -501,6 +507,7 @@ static int dealloc_pte_fn(
   15.70  	pte_t *pte, struct page *pte_page, unsigned long addr, void *data)
   15.71  {
   15.72  	unsigned long mfn = pte_mfn(*pte);
   15.73 +	int ret;
   15.74  	struct xen_memory_reservation reservation = {
   15.75  		.extent_start = &mfn,
   15.76  		.nr_extents   = 1,
   15.77 @@ -510,8 +517,8 @@ static int dealloc_pte_fn(
   15.78  	set_pte_at(&init_mm, addr, pte, __pte_ma(0));
   15.79  	phys_to_machine_mapping[__pa(addr) >> PAGE_SHIFT] =
   15.80  		INVALID_P2M_ENTRY;
   15.81 -	BUG_ON(HYPERVISOR_memory_op(
   15.82 -		XENMEM_decrease_reservation, &reservation) != 1);
   15.83 +	ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation, &reservation);
   15.84 +	BUG_ON(ret != 1);
   15.85  	return 0;
   15.86  }
   15.87  
   15.88 @@ -519,6 +526,7 @@ struct page *balloon_alloc_empty_page_ra
   15.89  {
   15.90  	unsigned long vstart, flags;
   15.91  	unsigned int  order = get_order(nr_pages * PAGE_SIZE);
   15.92 +	int ret;
   15.93  
   15.94  	vstart = __get_free_pages(GFP_KERNEL, order);
   15.95  	if (vstart == 0)
   15.96 @@ -527,8 +535,9 @@ struct page *balloon_alloc_empty_page_ra
   15.97  	scrub_pages(vstart, 1 << order);
   15.98  
   15.99  	balloon_lock(flags);
  15.100 -	BUG_ON(generic_page_range(
  15.101 -		&init_mm, vstart, PAGE_SIZE << order, dealloc_pte_fn, NULL));
  15.102 +	ret = generic_page_range(
  15.103 +		&init_mm, vstart, PAGE_SIZE << order, dealloc_pte_fn, NULL);
  15.104 +	BUG_ON(ret);
  15.105  	current_pages -= 1UL << order;
  15.106  	balloon_unlock(flags);
  15.107  
    16.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c	Sun Oct 30 13:52:38 2005 +0100
    16.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c	Sun Oct 30 14:00:35 2005 +0100
    16.3 @@ -108,6 +108,7 @@ static void fast_flush_area(int idx, int
    16.4  	struct gnttab_unmap_grant_ref unmap[BLKIF_MAX_SEGMENTS_PER_REQUEST];
    16.5  	unsigned int i, invcount = 0;
    16.6  	u16 handle;
    16.7 +	int ret;
    16.8  
    16.9  	for (i = 0; i < nr_pages; i++) {
   16.10  		handle = pending_handle(idx, i);
   16.11 @@ -120,8 +121,9 @@ static void fast_flush_area(int idx, int
   16.12  		invcount++;
   16.13  	}
   16.14  
   16.15 -	BUG_ON(HYPERVISOR_grant_table_op(
   16.16 -		GNTTABOP_unmap_grant_ref, unmap, invcount));
   16.17 +	ret = HYPERVISOR_grant_table_op(
   16.18 +		GNTTABOP_unmap_grant_ref, unmap, invcount);
   16.19 +	BUG_ON(ret);
   16.20  }
   16.21  
   16.22  
   16.23 @@ -338,6 +340,7 @@ static void dispatch_rw_block_io(blkif_t
   16.24  	struct bio *bio = NULL, *biolist[BLKIF_MAX_SEGMENTS_PER_REQUEST];
   16.25  	int nbio = 0;
   16.26  	request_queue_t *q;
   16.27 +	int ret;
   16.28  
   16.29  	/* Check that number of segments is sane. */
   16.30  	nseg = req->nr_segments;
   16.31 @@ -367,8 +370,8 @@ static void dispatch_rw_block_io(blkif_t
   16.32  			map[i].flags |= GNTMAP_readonly;
   16.33  	}
   16.34  
   16.35 -	BUG_ON(HYPERVISOR_grant_table_op(
   16.36 -		GNTTABOP_map_grant_ref, map, nseg));
   16.37 +	ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, map, nseg);
   16.38 +	BUG_ON(ret);
   16.39  
   16.40  	for (i = 0; i < nseg; i++) {
   16.41  		if (unlikely(map[i].handle < 0)) {
   16.42 @@ -493,6 +496,7 @@ static int __init blkif_init(void)
   16.43  {
   16.44  	int i;
   16.45  	struct page *page;
   16.46 +	int ret;
   16.47  
   16.48  	blkif_interface_init();
   16.49  
   16.50 @@ -509,7 +513,8 @@ static int __init blkif_init(void)
   16.51  	spin_lock_init(&blkio_schedule_list_lock);
   16.52  	INIT_LIST_HEAD(&blkio_schedule_list);
   16.53  
   16.54 -	BUG_ON(kernel_thread(blkio_schedule, 0, CLONE_FS | CLONE_FILES) < 0);
   16.55 +	ret = kernel_thread(blkio_schedule, 0, CLONE_FS | CLONE_FILES);
   16.56 +	BUG_ON(ret < 0);
   16.57  
   16.58  	blkif_xenbus_init();
   16.59  
    17.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/interface.c	Sun Oct 30 13:52:38 2005 +0100
    17.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/interface.c	Sun Oct 30 14:00:35 2005 +0100
    17.3 @@ -31,6 +31,7 @@ blkif_t *alloc_blkif(domid_t domid)
    17.4  static int map_frontend_page(blkif_t *blkif, unsigned long shared_page)
    17.5  {
    17.6  	struct gnttab_map_grant_ref op;
    17.7 +	int ret;
    17.8  
    17.9  	op.host_addr = (unsigned long)blkif->blk_ring_area->addr;
   17.10  	op.flags     = GNTMAP_host_map;
   17.11 @@ -38,8 +39,9 @@ static int map_frontend_page(blkif_t *bl
   17.12  	op.dom       = blkif->domid;
   17.13  
   17.14  	lock_vm_area(blkif->blk_ring_area);
   17.15 -	BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1));
   17.16 +	ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1);
   17.17  	unlock_vm_area(blkif->blk_ring_area);
   17.18 +	BUG_ON(ret);
   17.19  
   17.20  	if (op.handle < 0) {
   17.21  		DPRINTK(" Grant table operation failure !\n");
   17.22 @@ -55,14 +57,16 @@ static int map_frontend_page(blkif_t *bl
   17.23  static void unmap_frontend_page(blkif_t *blkif)
   17.24  {
   17.25  	struct gnttab_unmap_grant_ref op;
   17.26 +	int ret;
   17.27  
   17.28  	op.host_addr    = (unsigned long)blkif->blk_ring_area->addr;
   17.29  	op.handle       = blkif->shmem_handle;
   17.30  	op.dev_bus_addr = 0;
   17.31  
   17.32  	lock_vm_area(blkif->blk_ring_area);
   17.33 -	BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1));
   17.34 +	ret = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1);
   17.35  	unlock_vm_area(blkif->blk_ring_area);
   17.36 +	BUG_ON(ret);
   17.37  }
   17.38  
   17.39  int blkif_map(blkif_t *blkif, unsigned long shared_page, unsigned int evtchn)
    18.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c	Sun Oct 30 13:52:38 2005 +0100
    18.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c	Sun Oct 30 14:00:35 2005 +0100
    18.3 @@ -305,6 +305,7 @@ static irqreturn_t blkif_int(int irq, vo
    18.4  
    18.5  	for (i = info->ring.rsp_cons; i != rp; i++) {
    18.6  		unsigned long id;
    18.7 +		int ret;
    18.8  
    18.9  		bret = RING_GET_RESPONSE(&info->ring, i);
   18.10  		id   = bret->id;
   18.11 @@ -321,9 +322,10 @@ static irqreturn_t blkif_int(int irq, vo
   18.12  				DPRINTK("Bad return from blkdev data "
   18.13  					"request: %x\n", bret->status);
   18.14  
   18.15 -			BUG_ON(end_that_request_first(
   18.16 +			ret = end_that_request_first(
   18.17  				req, (bret->status == BLKIF_RSP_OKAY),
   18.18 -				req->hard_nr_sectors));
   18.19 +				req->hard_nr_sectors);
   18.20 +			BUG_ON(ret);
   18.21  			end_that_request_last(req);
   18.22  			break;
   18.23  		default:
    19.1 --- a/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c	Sun Oct 30 13:52:38 2005 +0100
    19.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c	Sun Oct 30 14:00:35 2005 +0100
    19.3 @@ -413,6 +413,7 @@ static void fast_flush_area(int idx, int
    19.4  	unsigned int i, op = 0;
    19.5  	struct grant_handle_pair *handle;
    19.6  	unsigned long ptep;
    19.7 +	int ret;
    19.8  
    19.9  	for ( i = 0; i < nr_pages; i++)
   19.10  	{
   19.11 @@ -440,8 +441,8 @@ static void fast_flush_area(int idx, int
   19.12  		BLKTAP_INVALIDATE_HANDLE(handle);
   19.13  	}
   19.14  
   19.15 -	BUG_ON(HYPERVISOR_grant_table_op(
   19.16 -		GNTTABOP_unmap_grant_ref, unmap, op));
   19.17 +	ret = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, unmap, op);
   19.18 +	BUG_ON(ret);
   19.19  
   19.20  	if (blktap_vma != NULL)
   19.21  		zap_page_range(blktap_vma, 
   19.22 @@ -673,6 +674,7 @@ static void dispatch_rw_block_io(blkif_t
   19.23  	struct gnttab_map_grant_ref map[BLKIF_MAX_SEGMENTS_PER_REQUEST*2];
   19.24  	int op, ret;
   19.25  	unsigned int nseg;
   19.26 +	int retval;
   19.27  
   19.28  	/* Check that number of segments is sane. */
   19.29  	nseg = req->nr_segments;
   19.30 @@ -740,8 +742,8 @@ static void dispatch_rw_block_io(blkif_t
   19.31  		op++;
   19.32  	}
   19.33  
   19.34 -	BUG_ON(HYPERVISOR_grant_table_op(
   19.35 -		GNTTABOP_map_grant_ref, map, op));
   19.36 +	retval = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, map, op);
   19.37 +	BUG_ON(retval);
   19.38  
   19.39  	op = 0;
   19.40  	for (i = 0; i < (req->nr_segments*2); i += 2) {
   19.41 @@ -877,7 +879,8 @@ static int __init blkif_init(void)
   19.42  	spin_lock_init(&blkio_schedule_list_lock);
   19.43  	INIT_LIST_HEAD(&blkio_schedule_list);
   19.44  
   19.45 -	BUG_ON(kernel_thread(blkio_schedule, 0, CLONE_FS | CLONE_FILES) < 0);
   19.46 +	i = kernel_thread(blkio_schedule, 0, CLONE_FS | CLONE_FILES);
   19.47 +	BUG_ON(i<0);
   19.48  
   19.49  	blkif_xenbus_init();
   19.50  
    20.1 --- a/linux-2.6-xen-sparse/drivers/xen/blktap/interface.c	Sun Oct 30 13:52:38 2005 +0100
    20.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blktap/interface.c	Sun Oct 30 14:00:35 2005 +0100
    20.3 @@ -31,6 +31,7 @@ blkif_t *alloc_blkif(domid_t domid)
    20.4  static int map_frontend_page(blkif_t *blkif, unsigned long shared_page)
    20.5  {
    20.6  	struct gnttab_map_grant_ref op;
    20.7 +	int ret;
    20.8  
    20.9  	op.host_addr = (unsigned long)blkif->blk_ring_area->addr;
   20.10  	op.flags     = GNTMAP_host_map;
   20.11 @@ -38,8 +39,9 @@ static int map_frontend_page(blkif_t *bl
   20.12  	op.dom       = blkif->domid;
   20.13  
   20.14  	lock_vm_area(blkif->blk_ring_area);
   20.15 -	BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1));
   20.16 +	ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1);
   20.17  	unlock_vm_area(blkif->blk_ring_area);
   20.18 +	BUG_ON(ret);
   20.19  
   20.20  	if (op.handle < 0) {
   20.21  		DPRINTK(" Grant table operation failure !\n");
   20.22 @@ -55,14 +57,16 @@ static int map_frontend_page(blkif_t *bl
   20.23  static void unmap_frontend_page(blkif_t *blkif)
   20.24  {
   20.25  	struct gnttab_unmap_grant_ref op;
   20.26 +	int ret;
   20.27  
   20.28  	op.host_addr    = (unsigned long)blkif->blk_ring_area->addr;
   20.29  	op.handle       = blkif->shmem_handle;
   20.30  	op.dev_bus_addr = 0;
   20.31  
   20.32  	lock_vm_area(blkif->blk_ring_area);
   20.33 -	BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1));
   20.34 +	ret = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1);
   20.35  	unlock_vm_area(blkif->blk_ring_area);
   20.36 +	BUG_ON(ret);
   20.37  }
   20.38  
   20.39  int blkif_map(blkif_t *blkif, unsigned long shared_page, unsigned int evtchn)
    21.1 --- a/linux-2.6-xen-sparse/drivers/xen/evtchn/evtchn.c	Sun Oct 30 13:52:38 2005 +0100
    21.2 +++ b/linux-2.6-xen-sparse/drivers/xen/evtchn/evtchn.c	Sun Oct 30 14:00:35 2005 +0100
    21.3 @@ -282,6 +282,7 @@ static int evtchn_ioctl(struct inode *in
    21.4  
    21.5  	case IOCTL_EVTCHN_UNBIND: {
    21.6  		struct ioctl_evtchn_unbind unbind;
    21.7 +		int ret;
    21.8  
    21.9  		rc = -EFAULT;
   21.10  		if (copy_from_user(&unbind, (void *)arg, sizeof(unbind)))
   21.11 @@ -306,7 +307,8 @@ static int evtchn_ioctl(struct inode *in
   21.12  
   21.13  		op.cmd = EVTCHNOP_close;
   21.14  		op.u.close.port = unbind.port;
   21.15 -		BUG_ON(HYPERVISOR_event_channel_op(&op));
   21.16 +		ret = HYPERVISOR_event_channel_op(&op);
   21.17 +		BUG_ON(ret);
   21.18  
   21.19  		rc = 0;
   21.20  		break;
   21.21 @@ -399,6 +401,7 @@ static int evtchn_release(struct inode *
   21.22  
   21.23  	for (i = 0; i < NR_EVENT_CHANNELS; i++)
   21.24  	{
   21.25 +		int ret;
   21.26  		if (port_user[i] != u)
   21.27  			continue;
   21.28  
   21.29 @@ -407,7 +410,8 @@ static int evtchn_release(struct inode *
   21.30  
   21.31  		op.cmd = EVTCHNOP_close;
   21.32  		op.u.close.port = i;
   21.33 -		BUG_ON(HYPERVISOR_event_channel_op(&op));
   21.34 +		ret = HYPERVISOR_event_channel_op(&op);
   21.35 +		BUG_ON(ret);
   21.36  	}
   21.37  
   21.38  	spin_unlock_irq(&port_user_lock);
    22.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/interface.c	Sun Oct 30 13:52:38 2005 +0100
    22.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/interface.c	Sun Oct 30 14:00:35 2005 +0100
    22.3 @@ -115,6 +115,7 @@ static int map_frontend_pages(
    22.4  	netif_t *netif, grant_ref_t tx_ring_ref, grant_ref_t rx_ring_ref)
    22.5  {
    22.6  	struct gnttab_map_grant_ref op;
    22.7 +	int ret;
    22.8  
    22.9  	op.host_addr = (unsigned long)netif->comms_area->addr;
   22.10  	op.flags     = GNTMAP_host_map;
   22.11 @@ -122,8 +123,9 @@ static int map_frontend_pages(
   22.12  	op.dom       = netif->domid;
   22.13      
   22.14  	lock_vm_area(netif->comms_area);
   22.15 -	BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1));
   22.16 +	ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1);
   22.17  	unlock_vm_area(netif->comms_area);
   22.18 +	BUG_ON(ret);
   22.19  
   22.20  	if (op.handle < 0) { 
   22.21  		DPRINTK(" Gnttab failure mapping tx_ring_ref!\n");
   22.22 @@ -139,8 +141,9 @@ static int map_frontend_pages(
   22.23  	op.dom       = netif->domid;
   22.24  
   22.25  	lock_vm_area(netif->comms_area);
   22.26 -	BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1));
   22.27 +	ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1);
   22.28  	unlock_vm_area(netif->comms_area);
   22.29 +	BUG_ON(ret);
   22.30  
   22.31  	if (op.handle < 0) { 
   22.32  		DPRINTK(" Gnttab failure mapping rx_ring_ref!\n");
   22.33 @@ -156,22 +159,25 @@ static int map_frontend_pages(
   22.34  static void unmap_frontend_pages(netif_t *netif)
   22.35  {
   22.36  	struct gnttab_unmap_grant_ref op;
   22.37 +	int ret;
   22.38  
   22.39  	op.host_addr    = (unsigned long)netif->comms_area->addr;
   22.40  	op.handle       = netif->tx_shmem_handle;
   22.41  	op.dev_bus_addr = 0;
   22.42  
   22.43  	lock_vm_area(netif->comms_area);
   22.44 -	BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1));
   22.45 +	ret = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1);
   22.46  	unlock_vm_area(netif->comms_area);
   22.47 +	BUG_ON(ret);
   22.48  
   22.49  	op.host_addr    = (unsigned long)netif->comms_area->addr + PAGE_SIZE;
   22.50  	op.handle       = netif->rx_shmem_handle;
   22.51  	op.dev_bus_addr = 0;
   22.52  
   22.53  	lock_vm_area(netif->comms_area);
   22.54 -	BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1));
   22.55 +	ret = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1);
   22.56  	unlock_vm_area(netif->comms_area);
   22.57 +	BUG_ON(ret);
   22.58  }
   22.59  
   22.60  int netif_map(netif_t *netif, unsigned long tx_ring_ref,
    23.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/netback.c	Sun Oct 30 13:52:38 2005 +0100
    23.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/netback.c	Sun Oct 30 14:00:35 2005 +0100
    23.3 @@ -112,9 +112,12 @@ static void free_mfn(unsigned long mfn)
    23.4  	spin_lock_irqsave(&mfn_lock, flags);
    23.5  	if ( alloc_index != MAX_MFN_ALLOC )
    23.6  		mfn_list[alloc_index++] = mfn;
    23.7 -	else
    23.8 -		BUG_ON(HYPERVISOR_memory_op(XENMEM_decrease_reservation,
    23.9 -					    &reservation) != 1);
   23.10 +	else {
   23.11 +		int ret;
   23.12 +		ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation,
   23.13 +					    &reservation);
   23.14 +		BUG_ON(ret != 1);
   23.15 +	}
   23.16  	spin_unlock_irqrestore(&mfn_lock, flags);
   23.17  }
   23.18  #endif
   23.19 @@ -159,13 +162,15 @@ int netif_be_start_xmit(struct sk_buff *
   23.20  	 */
   23.21  	if (skb_shared(skb) || skb_cloned(skb) || !is_xen_skb(skb)) {
   23.22  		int hlen = skb->data - skb->head;
   23.23 +		int ret;
   23.24  		struct sk_buff *nskb = dev_alloc_skb(hlen + skb->len);
   23.25  		if ( unlikely(nskb == NULL) )
   23.26  			goto drop;
   23.27  		skb_reserve(nskb, hlen);
   23.28  		__skb_put(nskb, skb->len);
   23.29 -		BUG_ON(skb_copy_bits(skb, -hlen, nskb->data - hlen,
   23.30 -				     skb->len + hlen));
   23.31 +		ret = skb_copy_bits(skb, -hlen, nskb->data - hlen,
   23.32 +				     skb->len + hlen);
   23.33 +		BUG_ON(ret);
   23.34  		nskb->dev = skb->dev;
   23.35  		nskb->proto_csum_valid = skb->proto_csum_valid;
   23.36  		dev_kfree_skb(skb);
   23.37 @@ -218,6 +223,7 @@ static void net_rx_action(unsigned long 
   23.38  	struct sk_buff *skb;
   23.39  	u16 notify_list[NETIF_RX_RING_SIZE];
   23.40  	int notify_nr = 0;
   23.41 +	int ret;
   23.42  
   23.43  	skb_queue_head_init(&rxq);
   23.44  
   23.45 @@ -279,7 +285,8 @@ static void net_rx_action(unsigned long 
   23.46  	mcl++;
   23.47  
   23.48  	mcl[-2].args[MULTI_UVMFLAGS_INDEX] = UVMF_TLB_FLUSH|UVMF_ALL;
   23.49 -	BUG_ON(HYPERVISOR_multicall(rx_mcl, mcl - rx_mcl) != 0);
   23.50 +	ret = HYPERVISOR_multicall(rx_mcl, mcl - rx_mcl);
   23.51 +	BUG_ON(ret != 0);
   23.52  
   23.53  	mcl = rx_mcl;
   23.54  	if( HYPERVISOR_grant_table_op(GNTTABOP_transfer, grant_rx_op, 
   23.55 @@ -421,6 +428,7 @@ inline static void net_tx_action_dealloc
   23.56  	u16 pending_idx;
   23.57  	PEND_RING_IDX dc, dp;
   23.58  	netif_t *netif;
   23.59 +	int ret;
   23.60  
   23.61  	dc = dealloc_cons;
   23.62  	dp = dealloc_prod;
   23.63 @@ -436,8 +444,9 @@ inline static void net_tx_action_dealloc
   23.64  		gop->handle       = grant_tx_ref[pending_idx];
   23.65  		gop++;
   23.66  	}
   23.67 -	BUG_ON(HYPERVISOR_grant_table_op(
   23.68 -		GNTTABOP_unmap_grant_ref, tx_unmap_ops, gop - tx_unmap_ops));
   23.69 +	ret = HYPERVISOR_grant_table_op(
   23.70 +		GNTTABOP_unmap_grant_ref, tx_unmap_ops, gop - tx_unmap_ops);
   23.71 +	BUG_ON(ret);
   23.72  
   23.73  	while (dealloc_cons != dp) {
   23.74  		pending_idx = dealloc_ring[MASK_PEND_IDX(dealloc_cons++)];
   23.75 @@ -477,6 +486,7 @@ static void net_tx_action(unsigned long 
   23.76  	NETIF_RING_IDX i;
   23.77  	gnttab_map_grant_ref_t *mop;
   23.78  	unsigned int data_len;
   23.79 +	int ret;
   23.80  
   23.81  	if (dealloc_cons != dealloc_prod)
   23.82  		net_tx_action_dealloc();
   23.83 @@ -599,8 +609,9 @@ static void net_tx_action(unsigned long 
   23.84  	if (mop == tx_map_ops)
   23.85  		return;
   23.86  
   23.87 -	BUG_ON(HYPERVISOR_grant_table_op(
   23.88 -		GNTTABOP_map_grant_ref, tx_map_ops, mop - tx_map_ops));
   23.89 +	ret = HYPERVISOR_grant_table_op(
   23.90 +		GNTTABOP_map_grant_ref, tx_map_ops, mop - tx_map_ops);
   23.91 +	BUG_ON(ret);
   23.92  
   23.93  	mop = tx_map_ops;
   23.94  	while ((skb = __skb_dequeue(&tx_queue)) != NULL) {
    24.1 --- a/linux-2.6-xen-sparse/drivers/xen/privcmd/privcmd.c	Sun Oct 30 13:52:38 2005 +0100
    24.2 +++ b/linux-2.6-xen-sparse/drivers/xen/privcmd/privcmd.c	Sun Oct 30 14:00:35 2005 +0100
    24.3 @@ -25,8 +25,8 @@
    24.4  #include <asm/pgtable.h>
    24.5  #include <asm/uaccess.h>
    24.6  #include <asm/tlb.h>
    24.7 +#include <asm/hypervisor.h>
    24.8  #include <asm-xen/linux-public/privcmd.h>
    24.9 -#include <asm/hypervisor.h>
   24.10  #include <asm-xen/xen-public/xen.h>
   24.11  #include <asm-xen/xen-public/dom0_ops.h>
   24.12  #include <asm-xen/xen_proc.h>
    25.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c	Sun Oct 30 13:52:38 2005 +0100
    25.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c	Sun Oct 30 14:00:35 2005 +0100
    25.3 @@ -78,6 +78,7 @@ tpmif_find(domid_t domid, long int insta
    25.4  static int
    25.5  map_frontend_page(tpmif_t *tpmif, unsigned long shared_page)
    25.6  {
    25.7 +	int ret;
    25.8  	struct gnttab_map_grant_ref op = {
    25.9  		.host_addr = (unsigned long)tpmif->tx_area->addr,
   25.10  		.flags = GNTMAP_host_map,
   25.11 @@ -86,8 +87,9 @@ map_frontend_page(tpmif_t *tpmif, unsign
   25.12  	};
   25.13  
   25.14  	lock_vm_area(tpmif->tx_area);
   25.15 -	BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1));
   25.16 +	ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1);
   25.17  	unlock_vm_area(tpmif->tx_area);
   25.18 +	BUG_ON(ret);
   25.19  
   25.20  	if (op.handle < 0) {
   25.21  		DPRINTK(" Grant table operation failure !\n");
   25.22 @@ -104,14 +106,16 @@ static void
   25.23  unmap_frontend_page(tpmif_t *tpmif)
   25.24  {
   25.25  	struct gnttab_unmap_grant_ref op;
   25.26 +	int ret;
   25.27  
   25.28  	op.host_addr    = (unsigned long)tpmif->tx_area->addr;
   25.29  	op.handle       = tpmif->shmem_handle;
   25.30  	op.dev_bus_addr = 0;
   25.31  
   25.32  	lock_vm_area(tpmif->tx_area);
   25.33 -	BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1));
   25.34 +	ret = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1);
   25.35  	unlock_vm_area(tpmif->tx_area);
   25.36 +	BUG_ON(ret);
   25.37  }
   25.38  
   25.39  int
    26.1 --- a/linux-2.6-xen-sparse/drivers/xen/util.c	Sun Oct 30 13:52:38 2005 +0100
    26.2 +++ b/linux-2.6-xen-sparse/drivers/xen/util.c	Sun Oct 30 14:00:35 2005 +0100
    26.3 @@ -34,7 +34,9 @@ struct vm_struct *alloc_vm_area(unsigned
    26.4  
    26.5  void free_vm_area(struct vm_struct *area)
    26.6  {
    26.7 -	BUG_ON(remove_vm_area(area->addr) != area);
    26.8 +	struct vm_struct *ret;
    26.9 +	ret = remove_vm_area(area->addr);
   26.10 +	BUG_ON(ret != area);
   26.11  	kfree(area);
   26.12  }
   26.13  
    27.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c	Sun Oct 30 13:52:38 2005 +0100
    27.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c	Sun Oct 30 14:00:35 2005 +0100
    27.3 @@ -714,11 +714,7 @@ static int xsd_port_read(char *page, cha
    27.4  
    27.5  static int __init xenbus_probe_init(void)
    27.6  {
    27.7 -	int err = 0;
    27.8 -	/* 
    27.9 -	** Domain0 doesn't have a store_evtchn or store_mfn yet. 
   27.10 -	*/
   27.11 -	int dom0 = (xen_start_info->store_evtchn == 0);
   27.12 +	int err = 0, dom0;
   27.13  
   27.14  	printk("xenbus_probe_init\n");
   27.15  
   27.16 @@ -733,10 +729,16 @@ static int __init xenbus_probe_init(void
   27.17  	device_register(&xenbus_frontend.dev);
   27.18  	device_register(&xenbus_backend.dev);
   27.19  
   27.20 +	/*
   27.21 +	** Domain0 doesn't have a store_evtchn or store_mfn yet.
   27.22 +	*/
   27.23 +	dom0 = (xen_start_info->store_evtchn == 0);
   27.24 +
   27.25  	if (dom0) {
   27.26  
   27.27  		unsigned long page;
   27.28  		evtchn_op_t op = { 0 };
   27.29 +		int ret;
   27.30  
   27.31  
   27.32  		/* Allocate page. */
   27.33 @@ -757,7 +759,8 @@ static int __init xenbus_probe_init(void
   27.34  		op.u.alloc_unbound.dom        = DOMID_SELF;
   27.35  		op.u.alloc_unbound.remote_dom = 0; 
   27.36  
   27.37 -		BUG_ON(HYPERVISOR_event_channel_op(&op)); 
   27.38 +		ret = HYPERVISOR_event_channel_op(&op);
   27.39 +		BUG_ON(ret); 
   27.40  		xen_start_info->store_evtchn = op.u.alloc_unbound.port;
   27.41  
   27.42  		/* And finally publish the above info in /proc/xen */
    28.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c	Sun Oct 30 13:52:38 2005 +0100
    28.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c	Sun Oct 30 14:00:35 2005 +0100
    28.3 @@ -28,6 +28,7 @@
    28.4   * IN THE SOFTWARE.
    28.5   */
    28.6  
    28.7 +#include <linux/unistd.h>
    28.8  #include <linux/errno.h>
    28.9  #include <linux/types.h>
   28.10  #include <linux/uio.h>
    29.1 --- a/tools/examples/Makefile	Sun Oct 30 13:52:38 2005 +0100
    29.2 +++ b/tools/examples/Makefile	Sun Oct 30 14:00:35 2005 +0100
    29.3 @@ -17,6 +17,7 @@ XEN_CONFIGS = xend-config.sxp
    29.4  XEN_CONFIGS += xmexample1 
    29.5  XEN_CONFIGS += xmexample2
    29.6  XEN_CONFIGS += xmexample.vmx
    29.7 +XEN_CONFIGS += xmexample.vti
    29.8  
    29.9  # Xen script dir and scripts to go there.
   29.10  XEN_SCRIPT_DIR = /etc/xen/scripts
    30.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    30.2 +++ b/tools/examples/xmexample.vti	Sun Oct 30 14:00:35 2005 +0100
    30.3 @@ -0,0 +1,100 @@
    30.4 +#  -*- mode: python; -*-
    30.5 +#============================================================================
    30.6 +# Python configuration setup for 'xm create'.
    30.7 +# This script sets the parameters used when a domain is created using 'xm create'.
    30.8 +# You use a separate script for each domain you want to create, or 
    30.9 +# you can set the parameters for the domain on the xm command line.
   30.10 +#============================================================================
   30.11 +
   30.12 +import os, re
   30.13 +arch = os.uname()[4]
   30.14 +arch_libdir = 'lib'
   30.15 +
   30.16 +#----------------------------------------------------------------------------
   30.17 +# Kernel image file.
   30.18 +kernel = "/boot/Flash.fd"
   30.19 +
   30.20 +# The domain build function. VMX domain uses 'vmx'.
   30.21 +builder='vmx'
   30.22 +
   30.23 +# Initial memory allocation (in megabytes) for the new domain.
   30.24 +memory = 256
   30.25 +
   30.26 +# A name for your domain. All domains must have different names.
   30.27 +name = "ExampleVMXDomain"
   30.28 +
   30.29 +# Which CPU to start domain on? 
   30.30 +#cpu = -1   # leave to Xen to pick
   30.31 +
   30.32 +# Optionally define mac and/or bridge for the network interfaces.
   30.33 +# Random MACs are assigned if not given.
   30.34 +#vif = [ 'mac=aa:00:00:00:00:11, bridge=xen-br0' ]
   30.35 +
   30.36 +#----------------------------------------------------------------------------
   30.37 +# Define the disk devices you want the domain to have access to, and
   30.38 +# what you want them accessible as.
   30.39 +# Each disk entry is of the form phy:UNAME,DEV,MODE
   30.40 +# where UNAME is the device, DEV is the device name the domain will see,
   30.41 +# and MODE is r for read-only, w for read-write.
   30.42 +
   30.43 +#disk = [ 'phy:hda1,hda1,r' ]
   30.44 +disk = [ 'file:/var/images/xenia64.img,ioemu:hda,w' ]
   30.45 +
   30.46 +#----------------------------------------------------------------------------
   30.47 +# Set according to whether you want the domain restarted when it exits.
   30.48 +# The default is 'onreboot', which restarts the domain when it shuts down
   30.49 +# with exit code reboot.
   30.50 +# Other values are 'always', and 'never'.
   30.51 +
   30.52 +#restart = 'onreboot'
   30.53 +
   30.54 +#============================================================================
   30.55 +
   30.56 +# New stuff
   30.57 +device_model = '/usr/' + arch_libdir + '/xen/bin/qemu-dm.debug'
   30.58 +
   30.59 +# Advanced users only. Don't touch if you don't know what you're doing
   30.60 +memmap = '/usr/lib/xen/boot/mem-map.sxp'
   30.61 +
   30.62 +#-----------------------------------------------------------------------------
   30.63 +# Disk image for 
   30.64 +#cdrom=
   30.65 +
   30.66 +#-----------------------------------------------------------------------------
   30.67 +# boot on floppy (a), hard disk (c) or CD-ROM (d) 
   30.68 +#boot=[a|c|d]
   30.69 +#-----------------------------------------------------------------------------
   30.70 +#  write to temporary files instead of disk image files
   30.71 +#snapshot=1
   30.72 +
   30.73 +#----------------------------------------------------------------------------
   30.74 +# enable SDL library for graphics, default = 0
   30.75 +sdl=1
   30.76 +
   30.77 +stdvga=1
   30.78 +#----------------------------------------------------------------------------
   30.79 +# enable VNC library for graphics, default = 1
   30.80 +vnc=0
   30.81 +
   30.82 +#----------------------------------------------------------------------------
   30.83 +# enable spawning vncviewer(only valid when vnc=1), default = 1
   30.84 +vncviewer=0
   30.85 +
   30.86 +#----------------------------------------------------------------------------
   30.87 +# no graphics, use serial port
   30.88 +#nographic=0
   30.89 +
   30.90 +
   30.91 +#-----------------------------------------------------------------------------
   30.92 +#   enable audio support
   30.93 +#enable-audio=1
   30.94 +
   30.95 +
   30.96 +#-----------------------------------------------------------------------------
   30.97 +#    set the real time clock to local time [default=0 i.e. set to utc]
   30.98 +#localtime=1
   30.99 +
  30.100 +
  30.101 +#-----------------------------------------------------------------------------
  30.102 +#    start in full screen
  30.103 +#full-screen=1   diff -r 42cab8724273 tools/libxc/xc_ia64_stubs.c
    31.1 --- a/tools/ioemu/hw/ide.c	Sun Oct 30 13:52:38 2005 +0100
    31.2 +++ b/tools/ioemu/hw/ide.c	Sun Oct 30 14:00:35 2005 +0100
    31.3 @@ -22,6 +22,7 @@
    31.4   * THE SOFTWARE.
    31.5   */
    31.6  #include "vl.h"
    31.7 +#include <pthread.h>
    31.8  
    31.9  /* debug IDE devices */
   31.10  //#define DEBUG_IDE
   31.11 @@ -360,6 +361,48 @@ typedef struct PCIIDEState {
   31.12      BMDMAState bmdma[2];
   31.13  } PCIIDEState;
   31.14  
   31.15 +#define DMA_MULTI_THREAD
   31.16 +
   31.17 +#ifdef DMA_MULTI_THREAD
   31.18 +
   31.19 +static int file_pipes[2];
   31.20 +
   31.21 +static void ide_dma_loop(BMDMAState *bm);
   31.22 +static void dma_thread_loop(BMDMAState *bm);
   31.23 +
   31.24 +static void *dma_thread_func(void* opaque)
   31.25 +{
   31.26 +    BMDMAState* req;
   31.27 +
   31.28 +    while (read(file_pipes[0], &req, sizeof(req))) {
   31.29 +        dma_thread_loop(req);
   31.30 +    }
   31.31 +
   31.32 +    return NULL;
   31.33 +}
   31.34 +
   31.35 +static void dma_create_thread()
   31.36 +{
   31.37 +    pthread_t tid;
   31.38 +    int rt;
   31.39 +
   31.40 +    if (pipe(file_pipes) != 0){
   31.41 +        fprintf(stderr, "create pipe failed\n");
   31.42 +        exit(1);
   31.43 +    }
   31.44 +
   31.45 +    if ( (rt = pthread_create(&tid, NULL, dma_thread_func, NULL)) ) {
   31.46 +        fprintf(stderr, "Oops, dma thread creation failed, errno=%d\n", rt);
   31.47 +        exit(1);
   31.48 +    }
   31.49 +
   31.50 +    if ( (rt = pthread_detach(tid)) ) {
   31.51 +        fprintf(stderr, "Oops, dma thread detachment failed, errno=%d\n", rt);
   31.52 +        exit(1);
   31.53 +    }
   31.54 +}
   31.55 +#endif //DMA_MULTI_THREAD
   31.56 +
   31.57  static void ide_dma_start(IDEState *s, IDEDMAFunc *dma_cb);
   31.58  
   31.59  static void padstr(char *str, const char *src, int len)
   31.60 @@ -1978,8 +2021,16 @@ static void ide_map(PCIDevice *pci_dev, 
   31.61  
   31.62  /* XXX: full callback usage to prepare non blocking I/Os support -
   31.63     error handling */
   31.64 +#ifdef DMA_MULTI_THREAD
   31.65  static void ide_dma_loop(BMDMAState *bm)
   31.66  {
   31.67 +    write(file_pipes[1], &bm, sizeof(bm));
   31.68 +}
   31.69 +static void dma_thread_loop(BMDMAState *bm)
   31.70 +#else 
   31.71 +static void ide_dma_loop(BMDMAState *bm)
   31.72 +#endif //DMA_MULTI_THREAD
   31.73 +{
   31.74      struct {
   31.75          uint32_t addr;
   31.76          uint32_t size;
   31.77 @@ -2166,6 +2217,9 @@ void pci_ide_init(PCIBus *bus, BlockDriv
   31.78          d->ide_if[i].pci_dev = (PCIDevice *)d;
   31.79      ide_init2(&d->ide_if[0], 16, hd_table[0], hd_table[1]);
   31.80      ide_init2(&d->ide_if[2], 16, hd_table[2], hd_table[3]);
   31.81 +#ifdef DMA_MULTI_THREAD    
   31.82 +    dma_create_thread();
   31.83 +#endif //DMA_MULTI_THREAD    
   31.84  }
   31.85  
   31.86  /* hd_table must contain 4 block drivers */
   31.87 @@ -2196,6 +2250,9 @@ void pci_piix3_ide_init(PCIBus *bus, Blo
   31.88      ide_init2(&d->ide_if[2], 15, hd_table[2], hd_table[3]);
   31.89      ide_init_ioport(&d->ide_if[0], 0x1f0, 0x3f6);
   31.90      ide_init_ioport(&d->ide_if[2], 0x170, 0x376);
   31.91 +#ifdef DMA_MULTI_THREAD    
   31.92 +    dma_create_thread();
   31.93 +#endif //DMA_MULTI_THREAD    
   31.94  }
   31.95  
   31.96  /***********************************************************/
    32.1 --- a/tools/libxc/xc_elf.h	Sun Oct 30 13:52:38 2005 +0100
    32.2 +++ b/tools/libxc/xc_elf.h	Sun Oct 30 14:00:35 2005 +0100
    32.3 @@ -24,26 +24,26 @@
    32.4   * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    32.5   */
    32.6  
    32.7 -typedef u_int8_t	Elf_Byte;
    32.8 +typedef uint8_t		Elf_Byte;
    32.9  
   32.10 -typedef u_int32_t	Elf32_Addr;	/* Unsigned program address */
   32.11 -typedef u_int32_t	Elf32_Off;	/* Unsigned file offset */
   32.12 +typedef uint32_t	Elf32_Addr;	/* Unsigned program address */
   32.13 +typedef uint32_t	Elf32_Off;	/* Unsigned file offset */
   32.14  typedef int32_t		Elf32_Sword;	/* Signed large integer */
   32.15 -typedef u_int32_t	Elf32_Word;	/* Unsigned large integer */
   32.16 -typedef u_int16_t	Elf32_Half;	/* Unsigned medium integer */
   32.17 +typedef uint32_t	Elf32_Word;	/* Unsigned large integer */
   32.18 +typedef uint16_t	Elf32_Half;	/* Unsigned medium integer */
   32.19  
   32.20 -typedef u_int64_t	Elf64_Addr;
   32.21 -typedef u_int64_t	Elf64_Off;
   32.22 +typedef uint64_t	Elf64_Addr;
   32.23 +typedef uint64_t	Elf64_Off;
   32.24  typedef int32_t		Elf64_Shalf;
   32.25  
   32.26  typedef int32_t		Elf64_Sword;
   32.27 -typedef u_int32_t	Elf64_Word;
   32.28 +typedef uint32_t	Elf64_Word;
   32.29  
   32.30  typedef int64_t		Elf64_Sxword;
   32.31 -typedef u_int64_t	Elf64_Xword;
   32.32 +typedef uint64_t	Elf64_Xword;
   32.33  
   32.34 -typedef u_int32_t	Elf64_Half;
   32.35 -typedef u_int16_t	Elf64_Quarter;
   32.36 +typedef uint32_t	Elf64_Half;
   32.37 +typedef uint16_t	Elf64_Quarter;
   32.38  
   32.39  /*
   32.40   * e_ident[] identification indexes 
    33.1 --- a/tools/libxc/xc_ia64_stubs.c	Sun Oct 30 13:52:38 2005 +0100
    33.2 +++ b/tools/libxc/xc_ia64_stubs.c	Sun Oct 30 14:00:35 2005 +0100
    33.3 @@ -1,5 +1,11 @@
    33.4  #include "xg_private.h"
    33.5  #include "xenguest.h"
    33.6 +#include "xc_private.h"
    33.7 +#include "xc_elf.h"
    33.8 +#include <stdlib.h>
    33.9 +#include <zlib.h>
   33.10 +#include "xen/arch-ia64.h"
   33.11 +#include <xen/io/ioreq.h>
   33.12  
   33.13  int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters, 
   33.14                    uint32_t max_factor, uint32_t flags)
   33.15 @@ -16,22 +22,6 @@ int xc_linux_restore(int xc_handle, int 
   33.16      return -1;
   33.17  }
   33.18  
   33.19 -int xc_vmx_build(int xc_handle,
   33.20 -                   uint32_t domid,
   33.21 -                   int memsize,
   33.22 -                   const char *image_name,
   33.23 -                   struct mem_map *mem_mapp,
   33.24 -                   const char *ramdisk_name,
   33.25 -                   const char *cmdline,
   33.26 -                   unsigned int control_evtchn,
   33.27 -                   unsigned int vcpus,
   33.28 -                   unsigned int store_evtchn,
   33.29 -                   unsigned long *store_mfn)
   33.30 -{
   33.31 -    PERROR("xc_vmx_build not implemented\n");
   33.32 -    return -1;
   33.33 -}
   33.34 -
   33.35  int
   33.36  xc_plan9_build(int xc_handle,
   33.37                 uint32_t domid,
   33.38 @@ -43,6 +33,653 @@ xc_plan9_build(int xc_handle,
   33.39      return -1;
   33.40  }
   33.41  
   33.42 +int xc_ia64_get_pfn_list(int xc_handle,
   33.43 +                         uint32_t domid, 
   33.44 +                         unsigned long *pfn_buf, 
   33.45 +                         unsigned int start_page,
   33.46 +                         unsigned int nr_pages)
   33.47 +{
   33.48 +    dom0_op_t op;
   33.49 +    int ret;
   33.50 +    unsigned long max_pfns = ((unsigned long)start_page << 32) | nr_pages;
   33.51 +
   33.52 +    op.cmd = DOM0_GETMEMLIST;
   33.53 +    op.u.getmemlist.domain   = (domid_t)domid;
   33.54 +    op.u.getmemlist.max_pfns = max_pfns;
   33.55 +    op.u.getmemlist.buffer   = pfn_buf;
   33.56 +
   33.57 +    if ( (max_pfns != -1UL)
   33.58 +		&& mlock(pfn_buf, nr_pages * sizeof(unsigned long)) != 0 )
   33.59 +    {
   33.60 +        PERROR("Could not lock pfn list buffer");
   33.61 +        return -1;
   33.62 +    }    
   33.63 +
   33.64 +    ret = do_dom0_op(xc_handle, &op);
   33.65 +
   33.66 +    if (max_pfns != -1UL)
   33.67 +    	(void)munlock(pfn_buf, nr_pages * sizeof(unsigned long));
   33.68 +
   33.69 +    return (ret < 0) ? -1 : op.u.getmemlist.num_pfns;
   33.70 +}
   33.71 +
   33.72 +long xc_get_max_pages(int xc_handle, uint32_t domid)
   33.73 +{
   33.74 +    dom0_op_t op;
   33.75 +    op.cmd = DOM0_GETDOMAININFO;
   33.76 +    op.u.getdomaininfo.domain = (domid_t)domid;
   33.77 +    return (do_dom0_op(xc_handle, &op) < 0) ? 
   33.78 +        -1 : op.u.getdomaininfo.max_pages;
   33.79 +}
   33.80 +
   33.81 +int xc_ia64_copy_to_domain_pages(int xc_handle, uint32_t domid,
   33.82 +        void* src_page, unsigned long dst_pfn, int nr_pages)
   33.83 +{
   33.84 +    // N.B. gva should be page aligned
   33.85 +    
   33.86 +    unsigned long *page_array=NULL;
   33.87 +    int i;
   33.88 +
   33.89 +    if ( (page_array = malloc(nr_pages * sizeof(unsigned long))) == NULL ){
   33.90 +        PERROR("Could not allocate memory");
   33.91 +        goto error_out;
   33.92 +    }
   33.93 +    if ( xc_ia64_get_pfn_list(xc_handle, domid, page_array,
   33.94 +                dst_pfn>>PAGE_SHIFT, nr_pages) != nr_pages ){
   33.95 +        PERROR("Could not get the page frame list");
   33.96 +        goto error_out;
   33.97 +    }
   33.98 +
   33.99 +    for ( i=0; i< nr_pages; i++ ){
  33.100 +	if (xc_copy_to_domain_page(xc_handle, domid, page_array[i],
  33.101 +			src_page + (i << PAGE_SHIFT)))
  33.102 +	    goto error_out;
  33.103 +    }
  33.104 +    free(page_array);
  33.105 +    return 0;
  33.106 +    
  33.107 +error_out:
  33.108 +    if (page_array)
  33.109 +        free(page_array);
  33.110 +    return -1;
  33.111 +}
  33.112 +
  33.113 +
  33.114 +#define HOB_SIGNATURE 0x3436474953424f48 // "HOBSIG64"
  33.115 +#define GFW_HOB_START    ((4UL<<30)-(14UL<<20))    //4G -14M
  33.116 +#define GFW_HOB_SIZE     (1UL<<20)              //1M
  33.117 +#define MEM_G   (1UL << 30) 
  33.118 +#define MEM_M   (1UL << 20) 
  33.119 +
  33.120 +typedef struct {
  33.121 +    unsigned long signature;
  33.122 +    unsigned int  type;
  33.123 +    unsigned int  length;
  33.124 +} HOB_GENERIC_HEADER;
  33.125 +
  33.126 +/*
  33.127 + * INFO HOB is the first data data in one HOB list
  33.128 + * it contains the control information of the HOB list
  33.129 + */
  33.130 +typedef struct { 
  33.131 +    HOB_GENERIC_HEADER  header;
  33.132 +    unsigned long       length;    // current length of hob
  33.133 +    unsigned long       cur_pos;   // current poisiton of hob
  33.134 +    unsigned long       buf_size;  // size of hob buffer
  33.135 +}HOB_INFO;
  33.136 +
  33.137 +typedef struct{
  33.138 +    unsigned long start;
  33.139 +    unsigned long size;
  33.140 +}hob_mem_t;
  33.141 +
  33.142 +typedef enum {
  33.143 +    HOB_TYPE_INFO=0,
  33.144 +    HOB_TYPE_TERMINAL,
  33.145 +    HOB_TYPE_MEM,
  33.146 +    HOB_TYPE_PAL_BUS_GET_FEATURES_DATA,
  33.147 +    HOB_TYPE_PAL_CACHE_SUMMARY,
  33.148 +    HOB_TYPE_PAL_MEM_ATTRIB,
  33.149 +    HOB_TYPE_PAL_CACHE_INFO,
  33.150 +    HOB_TYPE_PAL_CACHE_PROT_INFO,
  33.151 +    HOB_TYPE_PAL_DEBUG_INFO,
  33.152 +    HOB_TYPE_PAL_FIXED_ADDR,
  33.153 +    HOB_TYPE_PAL_FREQ_BASE,
  33.154 +    HOB_TYPE_PAL_FREQ_RATIOS,
  33.155 +    HOB_TYPE_PAL_HALT_INFO,
  33.156 +    HOB_TYPE_PAL_PERF_MON_INFO,
  33.157 +    HOB_TYPE_PAL_PROC_GET_FEATURES,
  33.158 +    HOB_TYPE_PAL_PTCE_INFO,
  33.159 +    HOB_TYPE_PAL_REGISTER_INFO,
  33.160 +    HOB_TYPE_PAL_RSE_INFO,
  33.161 +    HOB_TYPE_PAL_TEST_INFO,
  33.162 +    HOB_TYPE_PAL_VM_SUMMARY,
  33.163 +    HOB_TYPE_PAL_VM_INFO,
  33.164 +    HOB_TYPE_PAL_VM_PAGE_SIZE,
  33.165 +    HOB_TYPE_MAX
  33.166 +}hob_type_t;
  33.167 +
  33.168 +static int hob_init( void  *buffer ,unsigned long buf_size);
  33.169 +static int add_pal_hob(void* hob_buf);
  33.170 +static int add_mem_hob(void* hob_buf, unsigned long dom_mem_size);
  33.171 +static int build_hob (void* hob_buf, unsigned long hob_buf_size,
  33.172 +                  unsigned long dom_mem_size);
  33.173 +static int load_hob(int xc_handle,uint32_t dom, void *hob_buf);
  33.174 +
  33.175 +int xc_ia64_build_hob(int xc_handle, uint32_t dom, unsigned long memsize){
  33.176 +
  33.177 +    char   hob_buf[GFW_HOB_SIZE];
  33.178 +
  33.179 +    if ( build_hob( hob_buf, GFW_HOB_SIZE, memsize<<20) < 0){
  33.180 +        PERROR("Could not build hob");
  33.181 +        return -1;
  33.182 +    }
  33.183 +
  33.184 +    if ( load_hob( xc_handle, dom, hob_buf) <0){
  33.185 +        PERROR("Could not load hob");
  33.186 +       return -1;
  33.187 +    }
  33.188 +
  33.189 +    return 0;
  33.190 +
  33.191 +}
  33.192 +static int
  33.193 +hob_init( void  *buffer ,unsigned long buf_size)
  33.194 +{
  33.195 +    HOB_INFO *phit;
  33.196 +    HOB_GENERIC_HEADER     *terminal;
  33.197 +
  33.198 +    if (sizeof(HOB_INFO) + sizeof(HOB_GENERIC_HEADER) > buf_size){
  33.199 +        // buffer too small
  33.200 +        return -1;
  33.201 +    }
  33.202 +    
  33.203 +    phit = (HOB_INFO*)buffer;
  33.204 +    phit->header.signature = HOB_SIGNATURE;
  33.205 +    phit->header.type = HOB_TYPE_INFO;
  33.206 +    phit->header.length = sizeof(HOB_INFO);
  33.207 +    phit->length = sizeof(HOB_INFO) + sizeof(HOB_GENERIC_HEADER);
  33.208 +    phit->cur_pos = 0;
  33.209 +    phit->buf_size = buf_size;
  33.210 +    
  33.211 +    terminal = (HOB_GENERIC_HEADER*) (buffer + sizeof(HOB_INFO));
  33.212 +    terminal->signature= HOB_SIGNATURE;
  33.213 +    terminal->type = HOB_TYPE_TERMINAL;
  33.214 +    terminal->length = sizeof(HOB_GENERIC_HEADER);
  33.215 +
  33.216 +    return 0;
  33.217 +}
  33.218 +
  33.219 +/*
  33.220 + *  Add a new HOB to the HOB List.
  33.221 + *       
  33.222 + *  hob_start  -  start address of hob buffer
  33.223 + *  type       -  type of the hob to be added
  33.224 + *  data       -  data of the hob to be added
  33.225 + *  data_size  -  size of the data
  33.226 + */
  33.227 +static int
  33.228 +hob_add(
  33.229 +     void*  hob_start,
  33.230 +     int    type,
  33.231 +     void*  data,
  33.232 +     int    data_size
  33.233 +)
  33.234 +{
  33.235 +    HOB_INFO *phit;
  33.236 +    HOB_GENERIC_HEADER     *newhob,*tail;   
  33.237 +    
  33.238 +    phit = (HOB_INFO*)hob_start;
  33.239 +
  33.240 +    if (phit->length + data_size > phit->buf_size){
  33.241 +        // no space for new hob
  33.242 +        return -1;
  33.243 +    }
  33.244 +
  33.245 +    //append new HOB 
  33.246 +    newhob = (HOB_GENERIC_HEADER*)
  33.247 +        (hob_start + phit->length - sizeof(HOB_GENERIC_HEADER));
  33.248 +    newhob->signature = HOB_SIGNATURE;
  33.249 +    newhob->type = type;
  33.250 +    newhob->length = data_size + sizeof(HOB_GENERIC_HEADER);
  33.251 +    memcpy((void*)newhob + sizeof(HOB_GENERIC_HEADER), data, data_size);
  33.252 +
  33.253 +    // append terminal HOB  
  33.254 +    tail = (HOB_GENERIC_HEADER*) ( hob_start + phit->length + data_size);
  33.255 +    tail->signature = HOB_SIGNATURE;
  33.256 +    tail->type = HOB_TYPE_TERMINAL;
  33.257 +    tail->length = sizeof(HOB_GENERIC_HEADER);
  33.258 +
  33.259 +    // adjust HOB list length
  33.260 +    phit->length += sizeof(HOB_GENERIC_HEADER)+ data_size;
  33.261 +
  33.262 +    return 0;
  33.263 +
  33.264 +}
  33.265 +
  33.266 +int get_hob_size(void* hob_buf){
  33.267 +    
  33.268 +    HOB_INFO *phit = (HOB_INFO*)hob_buf;
  33.269 +    
  33.270 +    if (phit->header.signature != HOB_SIGNATURE){
  33.271 +        PERROR("xc_get_hob_size:Incorrect signature");
  33.272 +        return -1;
  33.273 +    }
  33.274 +    return phit->length;
  33.275 +}
  33.276 +
  33.277 +int build_hob (void* hob_buf, unsigned long hob_buf_size,
  33.278 +                  unsigned long dom_mem_size)
  33.279 +{   
  33.280 +    //Init HOB List 
  33.281 +    if (hob_init (hob_buf, hob_buf_size)<0){
  33.282 +        PERROR("buffer too small");
  33.283 +        goto err_out;
  33.284 +    }
  33.285 +    
  33.286 +    if ( add_mem_hob( hob_buf,dom_mem_size) < 0){
  33.287 +        PERROR("Add memory hob failed, buffer too small");
  33.288 +        goto err_out;
  33.289 +    }
  33.290 +    
  33.291 +    if ( add_pal_hob( hob_buf ) < 0 ){
  33.292 +        PERROR("Add PAL hob failed, buffer too small");
  33.293 +        goto err_out;
  33.294 +    }
  33.295 +    
  33.296 +    return 0;
  33.297 +
  33.298 +err_out:
  33.299 +    return -1;  
  33.300 +}
  33.301 +
  33.302 +static int 
  33.303 +load_hob(int xc_handle, uint32_t dom, void *hob_buf)
  33.304 +{
  33.305 +    // hob_buf should be page aligned
  33.306 +    int hob_size;
  33.307 +    int nr_pages;
  33.308 +
  33.309 +    if ((hob_size = get_hob_size(hob_buf)) < 0){
  33.310 +        PERROR("Invalid hob data");
  33.311 +        return -1;
  33.312 +    }
  33.313 +
  33.314 +    if (hob_size > GFW_HOB_SIZE){
  33.315 +        PERROR("No enough memory for hob data");
  33.316 +        return -1;
  33.317 +    }
  33.318 +
  33.319 +    nr_pages = (hob_size + PAGE_SIZE -1) >> PAGE_SHIFT;
  33.320 +    
  33.321 +    return xc_ia64_copy_to_domain_pages(xc_handle, dom,
  33.322 +            hob_buf, GFW_HOB_START, nr_pages );
  33.323 +}
  33.324 +
  33.325 +#define MIN(x, y) ((x) < (y)) ? (x) : (y)
  33.326 +static int 
  33.327 +add_mem_hob(void* hob_buf, unsigned long dom_mem_size){
  33.328 +    hob_mem_t memhob;
  33.329 +
  33.330 +    // less than 3G
  33.331 +    memhob.start = 0;
  33.332 +    memhob.size = MIN(dom_mem_size, 0xC0000000);
  33.333 +    
  33.334 +    if (hob_add(hob_buf, HOB_TYPE_MEM, &memhob, sizeof(memhob)) < 0){
  33.335 +	return -1;
  33.336 +    }
  33.337 +
  33.338 +    if (dom_mem_size > 0xC0000000) {
  33.339 +        // 4G ~ 4G+remain
  33.340 +        memhob.start = 0x100000000; //4G
  33.341 +        memhob.size = dom_mem_size - 0xC0000000;
  33.342 +        if (hob_add(hob_buf, HOB_TYPE_MEM, &memhob, sizeof(memhob)) < 0)
  33.343 +            return -1;
  33.344 +    }
  33.345 +    return 0;
  33.346 +}
  33.347 +
  33.348 +unsigned char config_pal_bus_get_features_data[24] = {
  33.349 +    0, 0, 0, 32, 0, 0, 240, 189, 0, 0, 0, 0, 0, 0,
  33.350 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  33.351 +};
  33.352 +unsigned char config_pal_cache_summary[16] = {
  33.353 +    3, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0};
  33.354 +unsigned char config_pal_mem_attrib[8] =    {
  33.355 +    241, 0, 0, 0, 0, 0, 0, 0
  33.356 +};
  33.357 +unsigned char config_pal_cache_info[152] = {
  33.358 +    3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  33.359 +    6, 4, 6, 7, 255, 1, 0, 1, 0, 64, 0, 0, 12, 12, 
  33.360 +    49, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 6, 7, 0, 1,
  33.361 +    0, 1, 0, 64, 0, 0, 12, 12, 49, 0, 0, 0, 0, 0, 0, 
  33.362 +    0, 0, 0, 6, 8, 7, 7, 255, 7, 0, 11, 0, 0, 16, 0, 
  33.363 +    12, 17, 49, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 8, 7, 
  33.364 +    7, 7, 5, 9, 11, 0, 0, 4, 0, 12, 15, 49, 0, 254, 255,
  33.365 +    255, 255, 255, 255, 255, 255, 2, 8, 7, 7, 7, 5, 9, 
  33.366 +    11, 0, 0, 4, 0, 12, 15, 49, 0, 0, 0, 0, 0, 0, 0, 0, 
  33.367 +    0, 3, 12, 7, 7, 7, 14, 1, 3, 0, 0, 192, 0, 12, 20, 49, 0
  33.368 +};
  33.369 +unsigned char config_pal_cache_prot_info[200] = {
  33.370 +    3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  33.371 +    45, 0, 16, 8, 0, 76, 12, 64, 0, 0, 0, 0, 0, 0, 0,
  33.372 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  33.373 +    8, 0, 16, 4, 0, 76, 44, 68, 0, 0, 0, 0, 0, 0, 0, 0, 
  33.374 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 
  33.375 +    0, 16, 8, 0, 81, 44, 72, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  33.376 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 0,
  33.377 +    112, 12, 0, 79, 124, 76, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  33.378 +    0, 0, 0, 0, 0, 0, 254, 255, 255, 255, 255, 255, 255, 255, 
  33.379 +    32, 0, 112, 12, 0, 79, 124, 76, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  33.380 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 160, 
  33.381 +    12, 0, 84, 124, 76, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  33.382 +    0, 0, 0
  33.383 +};
  33.384 +unsigned char config_pal_debug_info[16] = {
  33.385 +    2, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0
  33.386 +};
  33.387 +unsigned char config_pal_fixed_addr[8] = {
  33.388 +    0, 0, 0, 0, 0, 0, 0, 0
  33.389 +};
  33.390 +unsigned char config_pal_freq_base[8] = {
  33.391 +    109, 219, 182, 13, 0, 0, 0, 0
  33.392 +};
  33.393 +unsigned char config_pal_freq_ratios[24] = {
  33.394 +    11, 1, 0, 0, 77, 7, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 4, 
  33.395 +    0, 0, 0, 7, 0, 0, 0
  33.396 +};
  33.397 +unsigned char config_pal_halt_info[64] = {
  33.398 +    0, 0, 0, 0, 0, 0, 0, 48, 0, 0, 0, 0, 0, 0, 0, 0, 
  33.399 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  33.400 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  33.401 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  33.402 +};
  33.403 +unsigned char config_pal_perf_mon_info[136] = {
  33.404 +    12, 47, 18, 8, 0, 0, 0, 0, 241, 255, 0, 0, 255, 7, 0, 0, 
  33.405 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  33.406 +    0, 0, 0, 0, 0, 0, 0, 0, 241, 255, 0, 0, 223, 0, 255, 255, 
  33.407 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  33.408 +    0, 0, 0, 0, 0, 0, 0, 0, 240, 255, 0, 0, 0, 0, 0, 0, 
  33.409 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  33.410 +    0, 0, 0, 0, 0, 0, 0, 0, 240, 255, 0, 0, 0, 0, 0, 0, 
  33.411 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  33.412 +    0, 0, 0, 0, 0, 0, 0, 0
  33.413 +};
  33.414 +unsigned char config_pal_proc_get_features[104] = {
  33.415 +    3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  33.416 +    0, 0, 0, 0, 64, 6, 64, 49, 0, 0, 0, 0, 64, 6, 0, 0, 
  33.417 +    0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 
  33.418 +    231, 0, 0, 0, 0, 0, 0, 0, 228, 0, 0, 0, 0, 0, 0, 0, 
  33.419 +    0, 0, 0, 0, 0, 0, 0, 0, 17, 0, 0, 0, 0, 0, 0, 0, 
  33.420 +    63, 0, 0, 0, 0, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0,
  33.421 +    0, 0, 0, 0, 0, 0, 0, 0
  33.422 +};
  33.423 +unsigned char config_pal_ptce_info[24] = {
  33.424 +    0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 
  33.425 +    0, 0, 0, 0, 0, 0, 0, 0
  33.426 +};
  33.427 +unsigned char config_pal_register_info[64] = {
  33.428 +    255, 0, 47, 127, 17, 17, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0,
  33.429 +    255, 208, 128, 238, 238, 0, 0, 248, 255, 255, 255, 255, 255, 0, 0, 7, 3,
  33.430 +    251, 3, 0, 0, 0, 0, 255, 7, 3, 0, 0, 0, 0, 0, 248, 252, 4,
  33.431 +    252, 255, 255, 255, 255, 2, 248, 252, 255, 255, 255, 255, 255
  33.432 +};
  33.433 +unsigned char config_pal_rse_info[16] = {
  33.434 +    96, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  33.435 +};
  33.436 +unsigned char config_pal_test_info[48] = {
  33.437 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  33.438 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  33.439 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  33.440 +};
  33.441 +unsigned char config_pal_vm_summary[16] = {
  33.442 +    101, 18, 15, 2, 7, 7, 4, 2, 59, 18, 0, 0, 0, 0, 0, 0
  33.443 +};
  33.444 +unsigned char config_pal_vm_info[104] = {
  33.445 +    2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
  33.446 +    32, 32, 0, 0, 0, 0, 0, 0, 112, 85, 21, 0, 0, 0, 0, 0, 0,
  33.447 +    0, 0, 0, 0, 0, 0, 1, 32, 32, 0, 0, 0, 0, 0, 0, 112, 85,
  33.448 +    21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 128, 128, 0,
  33.449 +    4, 0, 0, 0, 0, 112, 85, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  33.450 +    0, 0, 0, 1, 128, 128, 0, 4, 0, 0, 0, 0, 112, 85, 0, 0, 0, 0, 0
  33.451 +};
  33.452 +unsigned char config_pal_vm_page_size[16] = {
  33.453 +    0, 112, 85, 21, 0, 0, 0, 0, 0, 112, 85, 21, 0, 0, 0, 0
  33.454 +};
  33.455 +
  33.456 +typedef struct{
  33.457 +    hob_type_t type;
  33.458 +    void* data;
  33.459 +    unsigned long size;     
  33.460 +}hob_batch_t;
  33.461 +
  33.462 +hob_batch_t hob_batch[]={
  33.463 +    {  HOB_TYPE_PAL_BUS_GET_FEATURES_DATA,
  33.464 +        &config_pal_bus_get_features_data,
  33.465 +        sizeof(config_pal_bus_get_features_data)
  33.466 +    },
  33.467 +    {  HOB_TYPE_PAL_CACHE_SUMMARY,
  33.468 +        &config_pal_cache_summary,
  33.469 +        sizeof(config_pal_cache_summary)
  33.470 +    },
  33.471 +    {  HOB_TYPE_PAL_MEM_ATTRIB,
  33.472 +        &config_pal_mem_attrib,
  33.473 +        sizeof(config_pal_mem_attrib)
  33.474 +    },
  33.475 +    {  HOB_TYPE_PAL_CACHE_INFO,
  33.476 +        &config_pal_cache_info,
  33.477 +        sizeof(config_pal_cache_info)
  33.478 +    },
  33.479 +    {  HOB_TYPE_PAL_CACHE_PROT_INFO,
  33.480 +        &config_pal_cache_prot_info,
  33.481 +        sizeof(config_pal_cache_prot_info)
  33.482 +    },
  33.483 +    {  HOB_TYPE_PAL_DEBUG_INFO,
  33.484 +        &config_pal_debug_info,
  33.485 +        sizeof(config_pal_debug_info)
  33.486 +    },
  33.487 +    {  HOB_TYPE_PAL_FIXED_ADDR,
  33.488 +        &config_pal_fixed_addr,
  33.489 +        sizeof(config_pal_fixed_addr)
  33.490 +    },
  33.491 +    {  HOB_TYPE_PAL_FREQ_BASE,
  33.492 +        &config_pal_freq_base,
  33.493 +        sizeof(config_pal_freq_base)
  33.494 +    },
  33.495 +    {  HOB_TYPE_PAL_FREQ_RATIOS,
  33.496 +        &config_pal_freq_ratios,
  33.497 +        sizeof(config_pal_freq_ratios)
  33.498 +    },
  33.499 +    {  HOB_TYPE_PAL_HALT_INFO,
  33.500 +        &config_pal_halt_info,
  33.501 +        sizeof(config_pal_halt_info)
  33.502 +    },
  33.503 +    {  HOB_TYPE_PAL_PERF_MON_INFO,
  33.504 +        &config_pal_perf_mon_info,
  33.505 +        sizeof(config_pal_perf_mon_info)
  33.506 +    },
  33.507 +    {  HOB_TYPE_PAL_PROC_GET_FEATURES,
  33.508 +        &config_pal_proc_get_features,
  33.509 +        sizeof(config_pal_proc_get_features)
  33.510 +    },
  33.511 +    {  HOB_TYPE_PAL_PTCE_INFO,
  33.512 +        &config_pal_ptce_info,
  33.513 +        sizeof(config_pal_ptce_info)
  33.514 +    },
  33.515 +    {  HOB_TYPE_PAL_REGISTER_INFO,
  33.516 +        &config_pal_register_info,
  33.517 +        sizeof(config_pal_register_info)
  33.518 +    },
  33.519 +    {  HOB_TYPE_PAL_RSE_INFO,
  33.520 +        &config_pal_rse_info,
  33.521 +        sizeof(config_pal_rse_info)
  33.522 +    },
  33.523 +    {  HOB_TYPE_PAL_TEST_INFO,
  33.524 +        &config_pal_test_info,
  33.525 +        sizeof(config_pal_test_info)
  33.526 +    },
  33.527 +    {  HOB_TYPE_PAL_VM_SUMMARY,
  33.528 +        &config_pal_vm_summary,
  33.529 +        sizeof(config_pal_vm_summary)
  33.530 +    },
  33.531 +    {  HOB_TYPE_PAL_VM_INFO,
  33.532 +        &config_pal_vm_info,
  33.533 +        sizeof(config_pal_vm_info)
  33.534 +    },
  33.535 +    {  HOB_TYPE_PAL_VM_PAGE_SIZE,
  33.536 +        &config_pal_vm_page_size,
  33.537 +        sizeof(config_pal_vm_page_size)
  33.538 +    },      
  33.539 +};
  33.540 +
  33.541 +static int add_pal_hob(void* hob_buf){
  33.542 +    int i;
  33.543 +    for (i=0; i<sizeof(hob_batch)/sizeof(hob_batch_t); i++){
  33.544 +        if (hob_add(hob_buf, hob_batch[i].type, 
  33.545 +                    hob_batch[i].data,
  33.546 +                    hob_batch[i].size)<0)
  33.547 +            return -1;
  33.548 +    }
  33.549 +    return 0;
  33.550 +}
  33.551 +
  33.552 +static int setup_guest(  int xc_handle,
  33.553 +                         uint32_t dom, unsigned long memsize,
  33.554 +                         char *image, unsigned long image_size,
  33.555 +                         unsigned int control_evtchn,
  33.556 +                         unsigned int store_evtchn,
  33.557 +                         unsigned long *store_mfn)
  33.558 +{
  33.559 +    unsigned long page_array[2];
  33.560 +    shared_iopage_t *sp;
  33.561 +    // FIXME: initialize pfn list for a temp hack
  33.562 +    if (xc_ia64_get_pfn_list(xc_handle, dom, NULL, -1, -1) == -1) {
  33.563 +	PERROR("Could not allocate continuous memory");
  33.564 +	goto error_out;
  33.565 +    }
  33.566 +    
  33.567 +    if ((image_size > 12 * MEM_M) || (image_size & (PAGE_SIZE - 1))) {
  33.568 +        PERROR("Guest firmware size is incorrect [%ld]?", image_size);
  33.569 +        return -1;
  33.570 +    }
  33.571 +
  33.572 +    /* Load guest firmware */
  33.573 +    if( xc_ia64_copy_to_domain_pages( xc_handle, dom, 
  33.574 +            image, 4*MEM_G-image_size, image_size>>PAGE_SHIFT)) {
  33.575 +        PERROR("Could not load guest firmware into domain");
  33.576 +        goto error_out;
  33.577 +    }
  33.578 +
  33.579 +    /* Hand-off state passed to guest firmware */
  33.580 +    if (xc_ia64_build_hob(xc_handle, dom, memsize) < 0){
  33.581 +        PERROR("Could not build hob\n");
  33.582 +       goto error_out;
  33.583 +    }
  33.584 +
  33.585 +    /* Retrieve special pages like io, xenstore, etc. */
  33.586 +    if ( xc_ia64_get_pfn_list(xc_handle, dom, page_array, IO_PAGE_START>>PAGE_SHIFT, 2) != 2 )
  33.587 +    {
  33.588 +        PERROR("Could not get the page frame list");
  33.589 +        goto error_out;
  33.590 +    }
  33.591 +
  33.592 +    *store_mfn = page_array[1];
  33.593 +    if ((sp = (shared_iopage_t *) xc_map_foreign_range(
  33.594 +		xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE,
  33.595 +		page_array[0])) == 0)
  33.596 +	goto error_out;
  33.597 +    memset(sp, 0, PAGE_SIZE);
  33.598 +    sp->sp_global.eport = control_evtchn;
  33.599 +    munmap(sp, PAGE_SIZE);
  33.600 +
  33.601 +    return 0;
  33.602 +
  33.603 + error_out:
  33.604 +    return -1;
  33.605 +}
  33.606 +
  33.607 +int xc_vmx_build(int xc_handle,
  33.608 +                 uint32_t domid,
  33.609 +                 int memsize,
  33.610 +                 const char *image_name,
  33.611 +                 unsigned int control_evtchn,
  33.612 +                 unsigned int vcpus,
  33.613 +                 unsigned int store_evtchn,
  33.614 +                 unsigned long *store_mfn)
  33.615 +{
  33.616 +    dom0_op_t launch_op, op;
  33.617 +    int rc ;
  33.618 +    vcpu_guest_context_t st_ctxt, *ctxt = &st_ctxt;
  33.619 +    char         *image = NULL;
  33.620 +    unsigned long image_size;
  33.621 +    unsigned long nr_pages;
  33.622 +
  33.623 +    if ( (nr_pages = xc_get_max_pages(xc_handle, domid)) < 0 )
  33.624 +    {
  33.625 +        PERROR("Could not find total pages for domain");
  33.626 +        goto error_out;
  33.627 +    }
  33.628 +
  33.629 +    if ( (image = xc_read_kernel_image(image_name, &image_size)) == NULL ){
  33.630 +        PERROR("Could not read guest firmware image %s",image_name);
  33.631 +        goto error_out;
  33.632 +    }
  33.633 +
  33.634 +    image_size = (image_size + PAGE_SIZE - 1) & PAGE_MASK;
  33.635 +
  33.636 +    if ( mlock(&st_ctxt, sizeof(st_ctxt) ) ){   
  33.637 +        PERROR("Unable to mlock ctxt");
  33.638 +        return 1;
  33.639 +    }
  33.640 +
  33.641 +    op.cmd = DOM0_GETDOMAININFO;
  33.642 +    op.u.getdomaininfo.domain = (domid_t)domid;
  33.643 +    if ( (do_dom0_op(xc_handle, &op) < 0) || 
  33.644 +         ((uint16_t)op.u.getdomaininfo.domain != domid) ) {
  33.645 +        PERROR("Could not get info on domain");
  33.646 +        goto error_out;
  33.647 +    }
  33.648 +
  33.649 +    if ( xc_domain_get_vcpu_context(xc_handle, domid, 0, ctxt) ){
  33.650 +        PERROR("Could not get vcpu context");
  33.651 +        goto error_out;
  33.652 +    }
  33.653 +
  33.654 +    if ( !(op.u.getdomaininfo.flags & DOMFLAGS_PAUSED) ) {
  33.655 +        ERROR("Domain is already constructed");
  33.656 +        goto error_out;
  33.657 +    }
  33.658 +
  33.659 +    if ( setup_guest(xc_handle, domid, (unsigned long)memsize, image, image_size, 
  33.660 +                       control_evtchn, store_evtchn, store_mfn ) < 0 ){
  33.661 +        ERROR("Error constructing guest OS");
  33.662 +        goto error_out;
  33.663 +    }
  33.664 +
  33.665 +    if ( image != NULL )
  33.666 +        free(image);
  33.667 +
  33.668 +    ctxt->flags = VGCF_VMX_GUEST;
  33.669 +    ctxt->regs.cr_iip = 0x80000000ffffffb0UL;
  33.670 +    ctxt->vcpu.privregs = 0;
  33.671 +
  33.672 +    memset( &launch_op, 0, sizeof(launch_op) );
  33.673 +
  33.674 +    launch_op.u.setdomaininfo.domain = (domid_t)domid;
  33.675 +    launch_op.u.setdomaininfo.vcpu   = 0;
  33.676 +    launch_op.u.setdomaininfo.ctxt   = ctxt;
  33.677 +
  33.678 +    launch_op.cmd = DOM0_SETDOMAININFO;
  33.679 +    rc = do_dom0_op(xc_handle, &launch_op);
  33.680 +    return rc;
  33.681 +
  33.682 + error_out:
  33.683 +    if ( image != NULL )
  33.684 +        free(image);
  33.685 +
  33.686 +    return -1;
  33.687 +}
  33.688 +
  33.689  /*
  33.690   * Local variables:
  33.691   * mode: C
    34.1 --- a/tools/libxc/xc_linux_build.c	Sun Oct 30 13:52:38 2005 +0100
    34.2 +++ b/tools/libxc/xc_linux_build.c	Sun Oct 30 14:00:35 2005 +0100
    34.3 @@ -350,6 +350,8 @@ static int setup_guest(int xc_handle,
    34.4      start_info = xc_map_foreign_range(
    34.5          xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE, page_array[0]);
    34.6      memset(start_info, 0, sizeof(*start_info));
    34.7 +    rc = xc_version(xc_handle, XENVER_version, NULL);
    34.8 +    sprintf(start_info->magic, "Xen-%i.%i", rc >> 16, rc & (0xFFFF));
    34.9      start_info->flags        = flags;
   34.10      start_info->store_mfn    = nr_pages - 2;
   34.11      start_info->store_evtchn = store_evtchn;
   34.12 @@ -624,6 +626,8 @@ static int setup_guest(int xc_handle,
   34.13          xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE,
   34.14          page_array[(vstartinfo_start-dsi.v_start)>>PAGE_SHIFT]);
   34.15      memset(start_info, 0, sizeof(*start_info));
   34.16 +    rc = xc_version(xc_handle, XENVER_version, NULL);
   34.17 +    sprintf(start_info->magic, "Xen-%i.%i", rc >> 16, rc & (0xFFFF));
   34.18      start_info->nr_pages     = nr_pages;
   34.19      start_info->shared_info  = shared_info_frame << PAGE_SHIFT;
   34.20      start_info->flags        = flags;
    35.1 --- a/tools/libxc/xc_private.c	Sun Oct 30 13:52:38 2005 +0100
    35.2 +++ b/tools/libxc/xc_private.c	Sun Oct 30 14:00:35 2005 +0100
    35.3 @@ -313,46 +313,6 @@ int xc_get_pfn_list(int xc_handle,
    35.4      return (ret < 0) ? -1 : op.u.getmemlist.num_pfns;
    35.5  }
    35.6  
    35.7 -#ifdef __ia64__
    35.8 -int xc_ia64_get_pfn_list(int xc_handle,
    35.9 -                         uint32_t domid, 
   35.10 -                         unsigned long *pfn_buf, 
   35.11 -                         unsigned int start_page,
   35.12 -                         unsigned int nr_pages)
   35.13 -{
   35.14 -    dom0_op_t op;
   35.15 -    int ret;
   35.16 -
   35.17 -    op.cmd = DOM0_GETMEMLIST;
   35.18 -    op.u.getmemlist.domain   = (domid_t)domid;
   35.19 -    op.u.getmemlist.max_pfns = ((unsigned long)start_page << 32) | nr_pages;
   35.20 -    op.u.getmemlist.buffer   = pfn_buf;
   35.21 -
   35.22 -    if ( mlock(pfn_buf, nr_pages * sizeof(unsigned long)) != 0 )
   35.23 -    {
   35.24 -        PERROR("Could not lock pfn list buffer");
   35.25 -        return -1;
   35.26 -    }    
   35.27 -
   35.28 -    /* XXX Hack to put pages in TLB, hypervisor should be able to handle this */
   35.29 -    memset(pfn_buf, 0, nr_pages * sizeof(unsigned long));
   35.30 -    ret = do_dom0_op(xc_handle, &op);
   35.31 -
   35.32 -    (void)munlock(pfn_buf, nr_pages * sizeof(unsigned long));
   35.33 -
   35.34 -    return (ret < 0) ? -1 : op.u.getmemlist.num_pfns;
   35.35 -}
   35.36 -
   35.37 -long xc_get_max_pages(int xc_handle, uint32_t domid)
   35.38 -{
   35.39 -    dom0_op_t op;
   35.40 -    op.cmd = DOM0_GETDOMAININFO;
   35.41 -    op.u.getdomaininfo.domain = (domid_t)domid;
   35.42 -    return (do_dom0_op(xc_handle, &op) < 0) ? 
   35.43 -        -1 : op.u.getdomaininfo.max_pages;
   35.44 -}
   35.45 -#endif
   35.46 -
   35.47  long xc_get_tot_pages(int xc_handle, uint32_t domid)
   35.48  {
   35.49      dom0_op_t op;
    36.1 --- a/tools/libxc/xc_vmx_build.c	Sun Oct 30 13:52:38 2005 +0100
    36.2 +++ b/tools/libxc/xc_vmx_build.c	Sun Oct 30 14:00:35 2005 +0100
    36.3 @@ -279,6 +279,7 @@ static int setup_guest(int xc_handle,
    36.4                         vcpu_guest_context_t *ctxt,
    36.5                         unsigned long shared_info_frame,
    36.6                         unsigned int control_evtchn,
    36.7 +                       unsigned int lapic,
    36.8                         unsigned int vcpus,
    36.9                         unsigned int store_evtchn,
   36.10                         unsigned long *store_mfn)
   36.11 @@ -554,7 +555,7 @@ static int setup_guest(int xc_handle,
   36.12      ctxt->user_regs.eax = 0;
   36.13      ctxt->user_regs.esp = 0;
   36.14      ctxt->user_regs.ebx = 0; /* startup_32 expects this to be 0 to signal boot cpu */
   36.15 -    ctxt->user_regs.ecx = 0;
   36.16 +    ctxt->user_regs.ecx = lapic;
   36.17      ctxt->user_regs.esi = 0;
   36.18      ctxt->user_regs.edi = 0;
   36.19      ctxt->user_regs.ebp = 0;
   36.20 @@ -597,6 +598,7 @@ int xc_vmx_build(int xc_handle,
   36.21                   int memsize,
   36.22                   const char *image_name,
   36.23                   unsigned int control_evtchn,
   36.24 +                 unsigned int lapic,
   36.25                   unsigned int vcpus,
   36.26                   unsigned int store_evtchn,
   36.27                   unsigned long *store_mfn)
   36.28 @@ -651,9 +653,9 @@ int xc_vmx_build(int xc_handle,
   36.29          goto error_out;
   36.30      }
   36.31  
   36.32 -    if ( setup_guest(xc_handle, domid, memsize, image, image_size,
   36.33 -                     nr_pages, ctxt, op.u.getdomaininfo.shared_info_frame,
   36.34 -                     control_evtchn, vcpus, store_evtchn, store_mfn) < 0)
   36.35 +    if ( setup_guest(xc_handle, domid, memsize, image, image_size, nr_pages,
   36.36 +                     ctxt, op.u.getdomaininfo.shared_info_frame, control_evtchn,
   36.37 +                     lapic, vcpus, store_evtchn, store_mfn) < 0)
   36.38      {
   36.39          ERROR("Error constructing guest OS");
   36.40          goto error_out;
    37.1 --- a/tools/libxc/xenctrl.h	Sun Oct 30 13:52:38 2005 +0100
    37.2 +++ b/tools/libxc/xenctrl.h	Sun Oct 30 14:00:35 2005 +0100
    37.3 @@ -414,6 +414,12 @@ int xc_ia64_get_pfn_list(int xc_handle, 
    37.4                           unsigned long *pfn_buf, 
    37.5                           unsigned int start_page, unsigned int nr_pages);
    37.6  
    37.7 +int xc_copy_to_domain_page(int xc_handle, uint32_t domid,
    37.8 +			   unsigned long dst_pfn, void *src_page);
    37.9 +
   37.10 +int xc_ia64_copy_to_domain_pages(int xc_handle, uint32_t domid,
   37.11 +        void* src_page, unsigned long dst_pfn, int nr_pages);
   37.12 +
   37.13  long xc_get_max_pages(int xc_handle, uint32_t domid);
   37.14  
   37.15  int xc_mmuext_op(int xc_handle, struct mmuext_op *op, unsigned int nr_ops,
    38.1 --- a/tools/libxc/xenguest.h	Sun Oct 30 13:52:38 2005 +0100
    38.2 +++ b/tools/libxc/xenguest.h	Sun Oct 30 14:00:35 2005 +0100
    38.3 @@ -56,6 +56,7 @@ int xc_vmx_build(int xc_handle,
    38.4                   int memsize,
    38.5                   const char *image_name,
    38.6                   unsigned int control_evtchn,
    38.7 +                 unsigned int lapic,
    38.8                   unsigned int vcpus,
    38.9                   unsigned int store_evtchn,
   38.10                   unsigned long *store_mfn);
    39.1 --- a/tools/misc/cpuperf/cpuperf.c	Sun Oct 30 13:52:38 2005 +0100
    39.2 +++ b/tools/misc/cpuperf/cpuperf.c	Sun Oct 30 14:00:35 2005 +0100
    39.3 @@ -16,7 +16,6 @@
    39.4  
    39.5  #include <sys/types.h>
    39.6  #include <sched.h>
    39.7 -#include <error.h>
    39.8  #include <stdio.h>
    39.9  #include <unistd.h>
   39.10  #include <stdlib.h>
    40.1 --- a/tools/misc/miniterm/miniterm.c	Sun Oct 30 13:52:38 2005 +0100
    40.2 +++ b/tools/misc/miniterm/miniterm.c	Sun Oct 30 14:00:35 2005 +0100
    40.3 @@ -29,7 +29,7 @@
    40.4  #include <stdlib.h>
    40.5  #include <unistd.h>
    40.6  #include <fcntl.h>
    40.7 -#include <sys/signal.h>
    40.8 +#include <signal.h>
    40.9  #include <sys/types.h>
   40.10  #include <sys/wait.h>
   40.11  
    41.1 --- a/tools/python/xen/lowlevel/xc/xc.c	Sun Oct 30 13:52:38 2005 +0100
    41.2 +++ b/tools/python/xen/lowlevel/xc/xc.c	Sun Oct 30 14:00:35 2005 +0100
    41.3 @@ -438,19 +438,20 @@ static PyObject *pyxc_vmx_build(PyObject
    41.4      char *image;
    41.5      int control_evtchn, store_evtchn;
    41.6      int vcpus = 1;
    41.7 +    int lapic = 0;
    41.8      int memsize;
    41.9      unsigned long store_mfn = 0;
   41.10  
   41.11      static char *kwd_list[] = { "dom", "control_evtchn", "store_evtchn",
   41.12 -                                "memsize", "image", "vcpus", NULL };
   41.13 +                                "memsize", "image", "lapic", "vcpus", NULL };
   41.14  
   41.15 -    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiiisi", kwd_list,
   41.16 +    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiiisii", kwd_list,
   41.17                                        &dom, &control_evtchn, &store_evtchn,
   41.18 -                                      &memsize, &image, &vcpus) )
   41.19 +                                      &memsize, &image, &lapic, &vcpus) )
   41.20          return NULL;
   41.21  
   41.22      if ( xc_vmx_build(xc->xc_handle, dom, memsize, image, control_evtchn,
   41.23 -                      vcpus, store_evtchn, &store_mfn) != 0 )
   41.24 +                      lapic, vcpus, store_evtchn, &store_mfn) != 0 )
   41.25          return PyErr_SetFromErrno(xc_error);
   41.26  
   41.27      return Py_BuildValue("{s:i}", "store_mfn", store_mfn);
    42.1 --- a/tools/python/xen/web/tcp.py	Sun Oct 30 13:52:38 2005 +0100
    42.2 +++ b/tools/python/xen/web/tcp.py	Sun Oct 30 14:00:35 2005 +0100
    42.3 @@ -99,7 +99,7 @@ def listenTCP(port, factory, interface='
    42.4      return l
    42.5  
    42.6  def SetCloExec(SocketListener):
    42.7 -    SocketListener.SetCloExec()
    42.8 +    SocketListener.setCloExec()
    42.9  
   42.10  def connectTCP(host, port, factory, timeout=None, bindAddress=None):
   42.11      c = TCPConnector(host, port, factory, timeout=timeout, bindAddress=bindAddress)
    43.1 --- a/tools/python/xen/xend/image.py	Sun Oct 30 13:52:38 2005 +0100
    43.2 +++ b/tools/python/xen/xend/image.py	Sun Oct 30 14:00:35 2005 +0100
    43.3 @@ -203,6 +203,10 @@ class VmxImageHandler(ImageHandler):
    43.4  
    43.5          self.dmargs += self.configVNC(imageConfig)
    43.6  
    43.7 +        self.lapic = 0
    43.8 +        lapic = sxp.child_value(imageConfig, 'lapic')
    43.9 +        if not lapic is None:
   43.10 +            self.lapic = int(lapic)
   43.11  
   43.12      def buildDomain(self):
   43.13          # Create an event channel
   43.14 @@ -217,6 +221,7 @@ class VmxImageHandler(ImageHandler):
   43.15          log.debug("control_evtchn = %d", self.device_channel)
   43.16          log.debug("store_evtchn   = %d", store_evtchn)
   43.17          log.debug("memsize        = %d", self.vm.getMemoryTarget() / 1024)
   43.18 +        log.debug("lapic          = %d", self.lapic)
   43.19          log.debug("vcpus          = %d", self.vm.getVCpuCount())
   43.20  
   43.21          return xc.vmx_build(dom            = self.vm.getDomid(),
   43.22 @@ -224,6 +229,7 @@ class VmxImageHandler(ImageHandler):
   43.23                              control_evtchn = self.device_channel,
   43.24                              store_evtchn   = store_evtchn,
   43.25                              memsize        = self.vm.getMemoryTarget() / 1024,
   43.26 +                            lapic          = self.lapic,
   43.27                              vcpus          = self.vm.getVCpuCount())
   43.28  
   43.29  
   43.30 @@ -342,12 +348,15 @@ class VmxImageHandler(ImageHandler):
   43.31  
   43.32      def getDomainMemory(self, mem):
   43.33          """@see ImageHandler.getDomainMemory"""
   43.34 +	page_kb = 4
   43.35 +	if os.uname()[4] == 'ia64':
   43.36 +	    page_kb = 16
   43.37          # for ioreq_t and xenstore
   43.38          static_pages = 2
   43.39 -        return mem + self.getPageTableSize(mem / 1024) + 4 * static_pages
   43.40 +        return mem + (self.getPageTableSize(mem / 1024) + static_pages) * page_kb
   43.41              
   43.42      def getPageTableSize(self, mem_mb):
   43.43 -        """Return the size of memory needed for 1:1 page tables for physical
   43.44 +        """Return the pages of memory needed for 1:1 page tables for physical
   43.45             mode.
   43.46  
   43.47          @param mem_mb: size in MB
   43.48 @@ -355,13 +364,13 @@ class VmxImageHandler(ImageHandler):
   43.49          """
   43.50          # 1 page for the PGD + 1 pte page for 4MB of memory (rounded)
   43.51          if os.uname()[4] == 'x86_64':
   43.52 -            return (5 + ((mem_mb + 1) >> 1)) * 4
   43.53 +            return 5 + ((mem_mb + 1) >> 1)
   43.54          elif os.uname()[4] == 'ia64':
   43.55 -            # XEN/IA64 has p2m table allocated on demand, so only return
   43.56 -            # guest firmware size here.
   43.57 -            return 16 * 1024
   43.58 +            # 1:1 pgtable is allocated on demand ia64, so just return rom size
   43.59 +	    # for guest firmware
   43.60 +            return 1024
   43.61          else:
   43.62 -            return (1 + ((mem_mb + 3) >> 2)) * 4
   43.63 +            return 1 + ((mem_mb + 3) >> 2)
   43.64  
   43.65  
   43.66  """Table of image handler classes for virtual machine images.  Indexed by
    44.1 --- a/tools/python/xen/xend/server/event.py	Sun Oct 30 13:52:38 2005 +0100
    44.2 +++ b/tools/python/xen/xend/server/event.py	Sun Oct 30 14:00:35 2005 +0100
    44.3 @@ -192,4 +192,5 @@ def listenEvent(daemon):
    44.4      if xroot.get_xend_http_server():
    44.5          port = xroot.get_xend_event_port()
    44.6          interface = xroot.get_xend_address()
    44.7 -        tcp.listenTCP(port, factory, interface=interface)
    44.8 +        l = tcp.listenTCP(port, factory, interface=interface)
    44.9 +        l.setCloExec()
    45.1 --- a/tools/python/xen/xm/create.py	Sun Oct 30 13:52:38 2005 +0100
    45.2 +++ b/tools/python/xen/xm/create.py	Sun Oct 30 14:00:35 2005 +0100
    45.3 @@ -157,6 +157,10 @@ gopts.var('cpu', val='CPU',
    45.4            fn=set_int, default=None,
    45.5            use="CPU to run the domain on.")
    45.6  
    45.7 +gopts.var('lapic', val='LAPIC',
    45.8 +          fn=set_int, default=0,
    45.9 +          use="Disable or enable local APIC of VMX domain.")
   45.10 +
   45.11  gopts.var('vcpus', val='VCPUS',
   45.12            fn=set_int, default=1,
   45.13            use="# of Virtual CPUS in domain.")
   45.14 @@ -315,10 +319,6 @@ gopts.var('nfs_root', val="PATH",
   45.15            fn=set_value, default=None,
   45.16            use="Set the path of the root NFS directory.")
   45.17  
   45.18 -gopts.var('memmap', val='FILE',
   45.19 -          fn=set_value, default='',
   45.20 -          use="Path to memap SXP file.")
   45.21 -
   45.22  gopts.var('device_model', val='FILE',
   45.23            fn=set_value, default='',
   45.24            use="Path to device model program.")
   45.25 @@ -556,9 +556,9 @@ def configure_vfr(config, vals):
   45.26  def configure_vmx(config_image, vals):
   45.27      """Create the config for VMX devices.
   45.28      """
   45.29 -    args = [ 'memmap', 'device_model', 'vcpus', 'cdrom',
   45.30 -             'boot', 'fda', 'fdb', 'localtime', 'serial', 'macaddr', 'stdvga', 
   45.31 -             'isa', 'nographic', 'vnc', 'vncviewer', 'sdl', 'display', 'ne2000']
   45.32 +    args = [ 'device_model', 'vcpus', 'cdrom', 'boot', 'fda', 'fdb',
   45.33 +             'localtime', 'serial', 'macaddr', 'stdvga', 'isa', 'nographic',
   45.34 +             'vnc', 'vncviewer', 'sdl', 'display', 'ne2000', 'lapic']
   45.35      for a in args:
   45.36          if (vals.__dict__[a]):
   45.37              config_image.append([a, vals.__dict__[a]])
    46.1 --- a/tools/python/xen/xm/main.py	Sun Oct 30 13:52:38 2005 +0100
    46.2 +++ b/tools/python/xen/xm/main.py	Sun Oct 30 14:00:35 2005 +0100
    46.3 @@ -61,6 +61,8 @@ xm common subcommands:
    46.4      top                     monitor system and domains in real-time
    46.5      unpause <DomId>         unpause a paused domain
    46.6  
    46.7 +<DomName> can be substituted for <DomId> in xm subcommands.
    46.8 +
    46.9  For a complete list of subcommands run 'xm help --long'
   46.10  For more help on xm see the xm(1) man page
   46.11  For more help on xm create, see the xmdomain.cfg(5) man page"""
   46.12 @@ -119,6 +121,8 @@ xm full list of subcommands:
   46.13      vnet-create <config>       create a vnet from a config file
   46.14      vnet-delete <vnetid>       delete a vnet
   46.15  
   46.16 +<DomName> can be substituted for <DomId> in xm subcommands.
   46.17 +
   46.18  For a short list of subcommands run 'xm help'
   46.19  For more help on xm see the xm(1) man page
   46.20  For more help on xm create, see the xmdomain.cfg(5) man page"""
    47.1 --- a/tools/security/getlabel.sh	Sun Oct 30 13:52:38 2005 +0100
    47.2 +++ b/tools/security/getlabel.sh	Sun Oct 30 14:00:35 2005 +0100
    47.3 @@ -36,18 +36,21 @@ source labelfuncs.sh
    47.4  
    47.5  usage ()
    47.6  {
    47.7 -	echo "Usage: $0 -sid <ssidref> [<policy name>] or"
    47.8 -	echo "       $0 -dom <domid>   [<policy name>]  "
    47.9 -	echo ""
   47.10 -	echo "policy name : the name of the policy, i.e. 'chwall'"
   47.11 -	echo "              If the policy name is omitted, the grub.conf"
   47.12 -	echo "              entry of the running system is tried to be read"
   47.13 -	echo "              and the policy name determined from there."
   47.14 -	echo "ssidref     : an ssidref in hex or decimal format, i.e., '0x00010002'"
   47.15 -	echo "              or '65538'"
   47.16 -	echo "domid       : id of the domain, i.e., '1'; Use numbers from the 2nd"
   47.17 -	echo "              column shown when invoking 'xm list'"
   47.18 -	echo ""
   47.19 +echo "Use this tool to display the label of a domain or the label that is
   47.20 +corresponding to an ssidref given the name of the running policy.
   47.21 +
   47.22 +Usage: $0 -sid <ssidref> [<policy name>] or
   47.23 +       $0 -dom <domid>   [<policy name>]
   47.24 +
   47.25 +policy name : the name of the policy, i.e. 'chwall'
   47.26 +              If the policy name is omitted, the grub.conf
   47.27 +              entry of the running system is tried to be read
   47.28 +              and the policy name determined from there.
   47.29 +ssidref     : an ssidref in hex or decimal format, i.e., '0x00010002'
   47.30 +              or '65538'
   47.31 +domid       : id of the domain, i.e., '1'; Use numbers from the 2nd
   47.32 +              column shown when invoking 'xm list'
   47.33 +"
   47.34  }
   47.35  
   47.36  
    48.1 --- a/tools/security/setlabel.sh	Sun Oct 30 13:52:38 2005 +0100
    48.2 +++ b/tools/security/setlabel.sh	Sun Oct 30 14:00:35 2005 +0100
    48.3 @@ -39,21 +39,27 @@ source labelfuncs.sh
    48.4  
    48.5  usage ()
    48.6  {
    48.7 -	echo "Usage: $0 [Option] <vmfile> <label> [<policy name>]"
    48.8 -	echo "    or $0 -l [<policy name>]"
    48.9 -	echo ""
   48.10 -	echo "Valid options are:"
   48.11 -	echo "-r          : to relabel a file without being prompted"
   48.12 -	echo ""
   48.13 -	echo "vmfile      : XEN vm configuration file"
   48.14 -	echo "label       : the label to map to an ssidref"
   48.15 -	echo "policy name : the name of the policy, i.e. 'chwall'"
   48.16 -	echo "              If the policy name is omitted, it is attempted"
   48.17 -	echo "              to find the current policy's name in grub.conf."
   48.18 -	echo ""
   48.19 -	echo "-l [<policy name>] is used to show valid labels in the map file of"
   48.20 -	echo "                   the given or current policy."
   48.21 -	echo ""
   48.22 +echo "Use this tool to put the ssidref corresponding to a label of a policy into
   48.23 +the VM configuration file, or use it to display all labels of a policy.
   48.24 +
   48.25 +Usage: $0 [Option] <vmfile> <label> [<policy name>]
   48.26 +    or $0 -l [<policy name>]
   48.27 +
   48.28 +Valid options are:
   48.29 +-r          : to relabel a file without being prompted
   48.30 +
   48.31 +vmfile      : XEN vm configuration file; give complete path
   48.32 +label       : the label to map to an ssidref
   48.33 +policy name : the name of the policy, i.e. 'chwall'
   48.34 +              If the policy name is omitted, it is attempted
   48.35 +              to find the current policy's name in grub.conf.
   48.36 +
   48.37 +-l [<policy name>] is used to show valid labels in the map file of
   48.38 +                   the given or current policy. If the policy name
   48.39 +                   is omitted, it will be tried to determine the
   48.40 +                   current policy from grub.conf (/boot/grub/grub.conf)
   48.41 +
   48.42 +"
   48.43  }
   48.44  
   48.45  
   48.46 @@ -83,7 +89,7 @@ if [ "$mode" == "show" ]; then
   48.47  			exit -1;
   48.48  		fi
   48.49  	else
   48.50 -		policy=$3;
   48.51 +		policy=$1;
   48.52  	fi
   48.53  
   48.54  
   48.55 @@ -92,7 +98,7 @@ if [ "$mode" == "show" ]; then
   48.56  	if [ "$res" != "0" ]; then
   48.57  		showLabels $mapfile
   48.58  	else
   48.59 -		echo "Could not find map file for policy '$1'."
   48.60 +		echo "Could not find map file for policy '$policy'."
   48.61  	fi
   48.62  elif [ "$mode" == "usage" ]; then
   48.63  	usage
    49.1 --- a/tools/security/updategrub.sh	Sun Oct 30 13:52:38 2005 +0100
    49.2 +++ b/tools/security/updategrub.sh	Sun Oct 30 14:00:35 2005 +0100
    49.3 @@ -26,11 +26,16 @@ fi
    49.4  # Show usage of this program
    49.5  usage ()
    49.6  {
    49.7 -	echo "Usage: $0 <policy name> <root of xen repository>"
    49.8 -	echo ""
    49.9 -	echo "<policy name>             : The name of the policy, i.e. xen_null"
   49.10 -	echo "<root of xen repository>  : The root of the XEN repositrory."
   49.11 -	echo ""
   49.12 +echo "Use this tool to add the binary policy to the Xen grub entry and
   49.13 +have Xen automatically enforce the policy when starting.
   49.14 +
   49.15 +Usage: $0 <policy name> <root of xen repository>
   49.16 +
   49.17 +<policy name>             : The name of the policy, i.e. xen_null
   49.18 +<root of xen repository>  : The root of the XEN repository. Give
   49.19 +                            complete path.
   49.20 +
   49.21 +"
   49.22  }
   49.23  
   49.24  # This function sets the global variable 'linux'
   49.25 @@ -43,11 +48,24 @@ getLinuxVersion ()
   49.26  	for f in $path/linux-*-xen0 ; do
   49.27  		versionfile=$f/include/linux/version.h
   49.28  		if [ -r $versionfile ]; then
   49.29 -			lnx=`cat $versionfile | \
   49.30 -			     grep UTS_RELEASE | \
   49.31 -			     awk '{             \
   49.32 -			       len=length($3);  \
   49.33 -			       print substr($3,2,len-2) }'`
   49.34 +			lnx=`cat $versionfile |                \
   49.35 +			     grep UTS_RELEASE |                \
   49.36 +			     awk '{                            \
   49.37 +			       len=length($3);                 \
   49.38 +			       version=substr($3,2,len-2);     \
   49.39 +			       split(version,numbers,".");     \
   49.40 +			       if (numbers[4]=="") {           \
   49.41 +			         printf("%s.%s.%s",            \
   49.42 +			                 numbers[1],           \
   49.43 +			                 numbers[2],           \
   49.44 +			                 numbers[3]);          \
   49.45 +			       } else {                        \
   49.46 +			         printf("%s.%s.%s[.0-9]*-xen0",\
   49.47 +			                numbers[1],            \
   49.48 +			                numbers[2],            \
   49.49 +			                numbers[3]);           \
   49.50 +			       }                               \
   49.51 +			     }'`
   49.52  		fi
   49.53  		if [ "$lnx" != "" ]; then
   49.54  			linux="[./0-9a-zA-z]*$lnx"
   49.55 @@ -143,10 +161,19 @@ updateGrub ()
   49.56  		echo "Could not create temporary file! Aborting."
   49.57  		exit -1
   49.58  	fi
   49.59 -	mv -f $tmpfile $grubconf
   49.60 +	diff $tmpfile $grubconf > /dev/null
   49.61 +	RES=$?
   49.62 +	if [ "$RES" == "0" ]; then
   49.63 +		echo "No changes were made to $grubconf."
   49.64 +	else
   49.65 +		echo "Successfully updated $grubconf."
   49.66 +		mv -f $tmpfile $grubconf
   49.67 +	fi
   49.68  }
   49.69  
   49.70  if [ "$1" == "" -o "$2" == "" ]; then
   49.71 +	echo "Error: Not enough command line parameters."
   49.72 +	echo ""
   49.73  	usage
   49.74  	exit -1
   49.75  fi
    50.1 --- a/tools/xenstore/Makefile	Sun Oct 30 13:52:38 2005 +0100
    50.2 +++ b/tools/xenstore/Makefile	Sun Oct 30 14:00:35 2005 +0100
    50.3 @@ -77,7 +77,7 @@ libxenstore.so: xs.opic xs_lib.opic
    50.4  clean: testsuite-clean
    50.5  	rm -f *.o *.opic *.so
    50.6  	rm -f xenstored xs_random xs_stress xs_crashme
    50.7 -	rm -f xs_test xenstored_test
    50.8 +	rm -f xs_test xenstored_test xs_tdb_dump
    50.9  	$(RM) $(PROG_DEP)
   50.10  
   50.11  print-dir:
    51.1 --- a/xen/acm/acm_simple_type_enforcement_hooks.c	Sun Oct 30 13:52:38 2005 +0100
    51.2 +++ b/xen/acm/acm_simple_type_enforcement_hooks.c	Sun Oct 30 14:00:35 2005 +0100
    51.3 @@ -392,8 +392,11 @@ check_cache(struct domain *dom, domid_t 
    51.4      int i;
    51.5  
    51.6      printkd("checking cache: %x --> %x.\n", dom->domain_id, rdom);
    51.7 +
    51.8 +    if (dom->ssid == NULL)
    51.9 +        return 0;
   51.10      ste_ssid = GET_SSIDP(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, 
   51.11 -                         (struct acm_ssid_domain *)(dom)->ssid);
   51.12 +                         (struct acm_ssid_domain *)(dom->ssid));
   51.13  
   51.14      for(i=0; i< ACM_TE_CACHE_SIZE; i++) {
   51.15          if ((ste_ssid->ste_cache[i].valid == VALID) &&
   51.16 @@ -412,6 +415,8 @@ cache_result(struct domain *subj, struct
   51.17      struct ste_ssid *ste_ssid;
   51.18      int i;
   51.19      printkd("caching from doms: %x --> %x.\n", subj->domain_id, obj->domain_id);
   51.20 +    if (subj->ssid == NULL)
   51.21 +        return;
   51.22      ste_ssid = GET_SSIDP(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, 
   51.23                           (struct acm_ssid_domain *)(subj)->ssid);
   51.24      for(i=0; i< ACM_TE_CACHE_SIZE; i++)
   51.25 @@ -431,26 +436,34 @@ clean_id_from_cache(domid_t id)
   51.26      struct ste_ssid *ste_ssid;
   51.27      int i;
   51.28      struct domain **pd;
   51.29 +    struct acm_ssid_domain *ssid;
   51.30  
   51.31      printkd("deleting cache for dom %x.\n", id);
   51.32 -
   51.33      read_lock(&domlist_lock); /* look through caches of all domains */
   51.34      pd = &domain_list;
   51.35      for ( pd = &domain_list; *pd != NULL; pd = &(*pd)->next_in_list ) {
   51.36 -        ste_ssid = GET_SSIDP(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, 
   51.37 -                             (struct acm_ssid_domain *)(*pd)->ssid);
   51.38 +        ssid = (struct acm_ssid_domain *)((*pd)->ssid);
   51.39 +
   51.40 +        if (ssid == NULL)
   51.41 +            continue; /* hanging domain structure, no ssid any more ... */
   51.42 +        ste_ssid = GET_SSIDP(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, ssid);
   51.43 +        if (!ste_ssid) {
   51.44 +            printk("%s: deleting ID from cache ERROR (no ste_ssid)!\n",
   51.45 +                   __func__);
   51.46 +            goto out;
   51.47 +        }
   51.48          for (i=0; i<ACM_TE_CACHE_SIZE; i++)
   51.49              if ((ste_ssid->ste_cache[i].valid == VALID) &&
   51.50 -                (ste_ssid->ste_cache[i].id = id))
   51.51 +                (ste_ssid->ste_cache[i].id == id))
   51.52                  ste_ssid->ste_cache[i].valid = FREE;
   51.53      }
   51.54 + out:
   51.55      read_unlock(&domlist_lock);
   51.56  }
   51.57  
   51.58  /***************************
   51.59   * Authorization functions
   51.60   **************************/
   51.61 -
   51.62  static int 
   51.63  ste_pre_domain_create(void *subject_ssid, ssidref_t ssidref)
   51.64  {      
   51.65 @@ -484,44 +497,13 @@ ste_post_domain_destroy(void *subject_ss
   51.66  
   51.67  /* -------- EVENTCHANNEL OPERATIONS -----------*/
   51.68  static int
   51.69 -ste_pre_eventchannel_unbound(domid_t id) {
   51.70 -    struct domain *subj, *obj;
   51.71 -    int ret;
   51.72 -    traceprintk("%s: dom%x-->dom%x.\n", 
   51.73 -                __func__, current->domain->domain_id, id);
   51.74 -
   51.75 -    if (check_cache(current->domain, id)) {
   51.76 -        atomic_inc(&ste_bin_pol.ec_cachehit_count);
   51.77 -        return ACM_ACCESS_PERMITTED;
   51.78 -    }
   51.79 -    atomic_inc(&ste_bin_pol.ec_eval_count);
   51.80 -    subj = current->domain;
   51.81 -    obj = find_domain_by_id(id);
   51.82 -
   51.83 -    if (share_common_type(subj, obj)) {
   51.84 -        cache_result(subj, obj);
   51.85 -        ret = ACM_ACCESS_PERMITTED;
   51.86 -    } else {
   51.87 -        atomic_inc(&ste_bin_pol.ec_denied_count); 
   51.88 -        ret = ACM_ACCESS_DENIED; 
   51.89 -    }
   51.90 -    if (obj != NULL)
   51.91 -        put_domain(obj);
   51.92 -    return ret;
   51.93 -}
   51.94 -
   51.95 -static int
   51.96 -ste_pre_eventchannel_interdomain(domid_t id1, domid_t id2)
   51.97 -{
   51.98 +ste_pre_eventchannel_unbound(domid_t id1, domid_t id2) {
   51.99      struct domain *subj, *obj;
  51.100      int ret;
  51.101      traceprintk("%s: dom%x-->dom%x.\n", __func__,
  51.102                  (id1 == DOMID_SELF) ? current->domain->domain_id : id1,
  51.103                  (id2 == DOMID_SELF) ? current->domain->domain_id : id2);
  51.104  
  51.105 -    /* following is a bit longer but ensures that we
  51.106 -     * "put" only domains that we where "find"-ing 
  51.107 -     */
  51.108      if (id1 == DOMID_SELF) id1 = current->domain->domain_id;
  51.109      if (id2 == DOMID_SELF) id2 = current->domain->domain_id;
  51.110  
  51.111 @@ -531,7 +513,7 @@ ste_pre_eventchannel_interdomain(domid_t
  51.112          ret = ACM_ACCESS_DENIED;
  51.113          goto out;
  51.114      }
  51.115 -    /* cache check late, but evtchn is not on performance critical path */
  51.116 +    /* cache check late */
  51.117      if (check_cache(subj, obj->domain_id)) {
  51.118          atomic_inc(&ste_bin_pol.ec_cachehit_count);
  51.119          ret = ACM_ACCESS_PERMITTED;
  51.120 @@ -546,7 +528,7 @@ ste_pre_eventchannel_interdomain(domid_t
  51.121          atomic_inc(&ste_bin_pol.ec_denied_count); 
  51.122          ret = ACM_ACCESS_DENIED; 
  51.123      }
  51.124 - out:
  51.125 +  out:
  51.126      if (obj != NULL)
  51.127          put_domain(obj);
  51.128      if (subj != NULL)
  51.129 @@ -554,6 +536,50 @@ ste_pre_eventchannel_interdomain(domid_t
  51.130      return ret;
  51.131  }
  51.132  
  51.133 +static int
  51.134 +ste_pre_eventchannel_interdomain(domid_t id)
  51.135 +{
  51.136 +    struct domain *subj=NULL, *obj=NULL;
  51.137 +    int ret;
  51.138 +
  51.139 +    traceprintk("%s: dom%x-->dom%x.\n", __func__,
  51.140 +                current->domain->domain_id,
  51.141 +                (id == DOMID_SELF) ? current->domain->domain_id : id);
  51.142 +
  51.143 +    /* following is a bit longer but ensures that we
  51.144 +     * "put" only domains that we where "find"-ing 
  51.145 +     */
  51.146 +    if (id == DOMID_SELF) id = current->domain->domain_id;
  51.147 +
  51.148 +    subj = current->domain;
  51.149 +    obj  = find_domain_by_id(id);
  51.150 +    if (obj == NULL) {
  51.151 +        ret = ACM_ACCESS_DENIED;
  51.152 +        goto out;
  51.153 +    }
  51.154 +
  51.155 +    /* cache check late, but evtchn is not on performance critical path */
  51.156 +    if (check_cache(subj, obj->domain_id)) {
  51.157 +        atomic_inc(&ste_bin_pol.ec_cachehit_count);
  51.158 +        ret = ACM_ACCESS_PERMITTED;
  51.159 +        goto out;
  51.160 +    }
  51.161 +
  51.162 +    atomic_inc(&ste_bin_pol.ec_eval_count);
  51.163 +
  51.164 +    if (share_common_type(subj, obj)) {
  51.165 +        cache_result(subj, obj);
  51.166 +        ret = ACM_ACCESS_PERMITTED;
  51.167 +    } else {
  51.168 +        atomic_inc(&ste_bin_pol.ec_denied_count); 
  51.169 +        ret = ACM_ACCESS_DENIED; 
  51.170 +    }
  51.171 + out:
  51.172 +    if (obj != NULL)
  51.173 +        put_domain(obj);
  51.174 +    return ret;
  51.175 +}
  51.176 +
  51.177  /* -------- SHARED MEMORY OPERATIONS -----------*/
  51.178  
  51.179  static int
    52.1 --- a/xen/arch/ia64/asm-offsets.c	Sun Oct 30 13:52:38 2005 +0100
    52.2 +++ b/xen/arch/ia64/asm-offsets.c	Sun Oct 30 14:00:35 2005 +0100
    52.3 @@ -59,6 +59,8 @@ void foo(void)
    52.4  	DEFINE(XSI_BANKNUM_OFS, offsetof(mapped_regs_t, banknum));
    52.5  	DEFINE(XSI_BANK0_OFS, offsetof(mapped_regs_t, bank0_regs[0]));
    52.6  	DEFINE(XSI_BANK1_OFS, offsetof(mapped_regs_t, bank1_regs[0]));
    52.7 +	DEFINE(XSI_B0NATS_OFS, offsetof(mapped_regs_t, vbnat));
    52.8 +	DEFINE(XSI_B1NATS_OFS, offsetof(mapped_regs_t, vnat));
    52.9  	DEFINE(XSI_RR0_OFS, offsetof(mapped_regs_t, rrs[0]));
   52.10  	DEFINE(XSI_METAPHYS_OFS, offsetof(mapped_regs_t, metaphysical_mode));
   52.11  	DEFINE(XSI_PRECOVER_IFS_OFS, offsetof(mapped_regs_t, precover_ifs));
   52.12 @@ -79,13 +81,17 @@ void foo(void)
   52.13  	//DEFINE(IA64_TASK_SIGHAND_OFFSET,offsetof (struct task_struct, sighand));
   52.14  	//DEFINE(IA64_TASK_SIGNAL_OFFSET,offsetof (struct task_struct, signal));
   52.15  	//DEFINE(IA64_TASK_TGID_OFFSET, offsetof (struct task_struct, tgid));
   52.16 +	DEFINE(IA64_PGD, offsetof(struct domain, arch.mm));
   52.17  	DEFINE(IA64_TASK_THREAD_KSP_OFFSET, offsetof (struct vcpu, arch._thread.ksp));
   52.18  	DEFINE(IA64_TASK_THREAD_ON_USTACK_OFFSET, offsetof (struct vcpu, arch._thread.on_ustack));
   52.19  
   52.20 +	DEFINE(IA64_VCPU_DOMAIN_OFFSET, offsetof (struct vcpu, domain));
   52.21  	DEFINE(IA64_VCPU_META_RR0_OFFSET, offsetof (struct vcpu, arch.metaphysical_rr0));
   52.22  	DEFINE(IA64_VCPU_META_SAVED_RR0_OFFSET, offsetof (struct vcpu, arch.metaphysical_saved_rr0));
   52.23  	DEFINE(IA64_VCPU_BREAKIMM_OFFSET, offsetof (struct vcpu, arch.breakimm));
   52.24  	DEFINE(IA64_VCPU_IVA_OFFSET, offsetof (struct vcpu, arch.iva));
   52.25 +	DEFINE(IA64_VCPU_DTLB_PTE_OFFSET, offsetof (struct vcpu, arch.dtlb_pte));
   52.26 +	DEFINE(IA64_VCPU_ITLB_PTE_OFFSET, offsetof (struct vcpu, arch.itlb_pte));
   52.27  	DEFINE(IA64_VCPU_IRR0_OFFSET, offsetof (struct vcpu, arch.irr[0]));
   52.28  	DEFINE(IA64_VCPU_IRR3_OFFSET, offsetof (struct vcpu, arch.irr[3]));
   52.29  	DEFINE(IA64_VCPU_INSVC3_OFFSET, offsetof (struct vcpu, arch.insvc[3]));
    53.1 --- a/xen/arch/ia64/linux-xen/entry.S	Sun Oct 30 13:52:38 2005 +0100
    53.2 +++ b/xen/arch/ia64/linux-xen/entry.S	Sun Oct 30 14:00:35 2005 +0100
    53.3 @@ -900,10 +900,17 @@ GLOBAL_ENTRY(ia64_leave_kernel)
    53.4      adds r7 = PT(EML_UNAT)+16,r12
    53.5  	;;
    53.6      ld8 r7 = [r7]
    53.7 +	;;
    53.8 +#if 0
    53.9 +leave_kernel_self:
   53.10 +    cmp.ne p8,p0 = r0, r7
   53.11 +(p8) br.sptk.few leave_kernel_self
   53.12 +	;; 
   53.13 +#endif
   53.14  (p6)	br.call.sptk.many b0=deliver_pending_interrupt
   53.15      ;;
   53.16  	mov ar.pfs=loc0
   53.17 -    mov ar.unat=r7  /* load eml_unat  */
   53.18 +	mov ar.unat=r7  /* load eml_unat  */
   53.19  	mov r31=r0
   53.20  
   53.21  
    54.1 --- a/xen/arch/ia64/linux-xen/head.S	Sun Oct 30 13:52:38 2005 +0100
    54.2 +++ b/xen/arch/ia64/linux-xen/head.S	Sun Oct 30 14:00:35 2005 +0100
    54.3 @@ -324,6 +324,9 @@ 1:	// now we are in virtual mode
    54.4  	mov r16=-1
    54.5  (isBP)	br.cond.dpnt .load_current // BP stack is on region 5 --- no need to map it
    54.6  
    54.7 +#ifndef XEN
    54.8 +	// XEN:	stack is allocated in xenheap, which is currently always
    54.9 +	//  mapped.
   54.10  	// load mapping for stack (virtaddr in r2, physaddr in r3)
   54.11  	rsm psr.ic
   54.12  	movl r17=PAGE_KERNEL
   54.13 @@ -353,7 +356,8 @@ 1:	// now we are in virtual mode
   54.14  	ssm psr.ic
   54.15  	srlz.d
   54.16    	;;
   54.17 -
   54.18 +#endif
   54.19 +	
   54.20  .load_current:
   54.21  	// load the "current" pointer (r13) and ar.k6 with the current task
   54.22  #if defined(XEN) && defined(VALIDATE_VT)
    55.1 --- a/xen/arch/ia64/linux-xen/irq_ia64.c	Sun Oct 30 13:52:38 2005 +0100
    55.2 +++ b/xen/arch/ia64/linux-xen/irq_ia64.c	Sun Oct 30 14:00:35 2005 +0100
    55.3 @@ -281,5 +281,8 @@ ia64_send_ipi (int cpu, int vector, int 
    55.4  	ipi_data = (delivery_mode << 8) | (vector & 0xff);
    55.5  	ipi_addr = ipi_base_addr + ((phys_cpu_id << 4) | ((redirect & 1) << 3));
    55.6  
    55.7 +#ifdef XEN
    55.8 +	printf ("send_ipi to %d (%x)\n", cpu, phys_cpu_id);
    55.9 +#endif
   55.10  	writeq(ipi_data, ipi_addr);
   55.11  }
    56.1 --- a/xen/arch/ia64/linux-xen/mm_contig.c	Sun Oct 30 13:52:38 2005 +0100
    56.2 +++ b/xen/arch/ia64/linux-xen/mm_contig.c	Sun Oct 30 14:00:35 2005 +0100
    56.3 @@ -193,8 +193,8 @@ per_cpu_init (void)
    56.4  	 */
    56.5  	if (smp_processor_id() == 0) {
    56.6  #ifdef XEN
    56.7 -		cpu_data = alloc_xenheap_pages(PERCPU_PAGE_SHIFT -
    56.8 -			PAGE_SHIFT + get_order(NR_CPUS));
    56.9 +		cpu_data = alloc_xenheap_pages(get_order(NR_CPUS
   56.10 +							 * PERCPU_PAGE_SIZE));
   56.11  #else
   56.12  		cpu_data = __alloc_bootmem(PERCPU_PAGE_SIZE * NR_CPUS,
   56.13  					   PERCPU_PAGE_SIZE, __pa(MAX_DMA_ADDRESS));
    57.1 --- a/xen/arch/ia64/linux-xen/setup.c	Sun Oct 30 13:52:38 2005 +0100
    57.2 +++ b/xen/arch/ia64/linux-xen/setup.c	Sun Oct 30 14:00:35 2005 +0100
    57.3 @@ -366,6 +366,7 @@ check_for_logical_procs (void)
    57.4  }
    57.5  #endif
    57.6  
    57.7 +void __init
    57.8  #ifdef XEN
    57.9  early_setup_arch (char **cmdline_p)
   57.10  #else
   57.11 @@ -377,14 +378,12 @@ setup_arch (char **cmdline_p)
   57.12  	ia64_patch_vtop((u64) __start___vtop_patchlist, (u64) __end___vtop_patchlist);
   57.13  
   57.14  	*cmdline_p = __va(ia64_boot_param->command_line);
   57.15 -#ifdef XEN
   57.16 -	efi_init();
   57.17 -#else
   57.18 +#ifndef XEN
   57.19  	strlcpy(saved_command_line, *cmdline_p, COMMAND_LINE_SIZE);
   57.20 +#endif
   57.21  
   57.22  	efi_init();
   57.23  	io_port_init();
   57.24 -#endif
   57.25  
   57.26  #ifdef CONFIG_IA64_GENERIC
   57.27  	{
   57.28 @@ -414,11 +413,17 @@ setup_arch (char **cmdline_p)
   57.29  #ifdef XEN
   57.30  	early_cmdline_parse(cmdline_p);
   57.31  	cmdline_parse(*cmdline_p);
   57.32 -#undef CONFIG_ACPI_BOOT
   57.33  #endif
   57.34  	if (early_console_setup(*cmdline_p) == 0)
   57.35  		mark_bsp_online();
   57.36  
   57.37 +#ifdef XEN
   57.38 +}
   57.39 +
   57.40 +void __init
   57.41 +late_setup_arch (char **cmdline_p)
   57.42 +{
   57.43 +#endif
   57.44  #ifdef CONFIG_ACPI_BOOT
   57.45  	/* Initialize the ACPI boot-time table parser */
   57.46  	acpi_table_init();
   57.47 @@ -433,20 +438,16 @@ setup_arch (char **cmdline_p)
   57.48  
   57.49  #ifndef XEN
   57.50  	find_memory();
   57.51 -#else
   57.52 -	io_port_init();
   57.53 -}
   57.54 +#endif
   57.55  
   57.56 -void __init
   57.57 -late_setup_arch (char **cmdline_p)
   57.58 -{
   57.59 -#undef CONFIG_ACPI_BOOT
   57.60 -	acpi_table_init();
   57.61 -#endif
   57.62  	/* process SAL system table: */
   57.63  	ia64_sal_init(efi.sal_systab);
   57.64  
   57.65  #ifdef CONFIG_SMP
   57.66 +#ifdef XEN
   57.67 +	init_smp_config ();
   57.68 +#endif
   57.69 +
   57.70  	cpu_physical_id(0) = hard_smp_processor_id();
   57.71  
   57.72  	cpu_set(0, cpu_sibling_map[0]);
   57.73 @@ -768,6 +769,11 @@ cpu_init (void)
   57.74  
   57.75  	cpu_data = per_cpu_init();
   57.76  
   57.77 +#ifdef XEN
   57.78 +	printf ("cpu_init: current=%p, current->domain->arch.mm=%p\n",
   57.79 +		current, current->domain->arch.mm);
   57.80 +#endif
   57.81 +
   57.82  	/*
   57.83  	 * We set ar.k3 so that assembly code in MCA handler can compute
   57.84  	 * physical addresses of per cpu variables with a simple:
   57.85 @@ -887,6 +893,16 @@ cpu_init (void)
   57.86  #ifndef XEN
   57.87  	pm_idle = default_idle;
   57.88  #endif
   57.89 +
   57.90 +#ifdef XEN
   57.91 +    /* surrender usage of kernel registers to domain, use percpu area instead */
   57.92 +    __get_cpu_var(cpu_kr)._kr[IA64_KR_IO_BASE] = ia64_get_kr(IA64_KR_IO_BASE);
   57.93 +    __get_cpu_var(cpu_kr)._kr[IA64_KR_PER_CPU_DATA] = ia64_get_kr(IA64_KR_PER_CPU_DATA);
   57.94 +    __get_cpu_var(cpu_kr)._kr[IA64_KR_CURRENT_STACK] = ia64_get_kr(IA64_KR_CURRENT_STACK);
   57.95 +    __get_cpu_var(cpu_kr)._kr[IA64_KR_FPU_OWNER] = ia64_get_kr(IA64_KR_FPU_OWNER);
   57.96 +    __get_cpu_var(cpu_kr)._kr[IA64_KR_CURRENT] = ia64_get_kr(IA64_KR_CURRENT);
   57.97 +    __get_cpu_var(cpu_kr)._kr[IA64_KR_PT_BASE] = ia64_get_kr(IA64_KR_PT_BASE);
   57.98 +#endif
   57.99  }
  57.100  
  57.101  void
    58.1 --- a/xen/arch/ia64/linux-xen/smp.c	Sun Oct 30 13:52:38 2005 +0100
    58.2 +++ b/xen/arch/ia64/linux-xen/smp.c	Sun Oct 30 14:00:35 2005 +0100
    58.3 @@ -63,9 +63,18 @@ void flush_tlb_mask(cpumask_t mask)
    58.4  //Huh? This seems to be used on ia64 even if !CONFIG_SMP
    58.5  void smp_send_event_check_mask(cpumask_t mask)
    58.6  {
    58.7 -	printf("smp_send_event_check_mask called\n");
    58.8 -	//dummy();
    58.9 -	//send_IPI_mask(cpu_mask, EVENT_CHECK_VECTOR);
   58.10 +    int cpu;
   58.11 +
   58.12 +    /*  Not for me.  */
   58.13 +    cpu_clear(smp_processor_id(), mask);
   58.14 +    if (cpus_empty(mask))
   58.15 +        return;
   58.16 +
   58.17 +    printf("smp_send_event_check_mask called\n");
   58.18 +
   58.19 +    for (cpu = 0; cpu < NR_CPUS; ++cpu)
   58.20 +        if (cpu_isset(cpu, mask))
   58.21 +	    platform_send_ipi(cpu, IA64_IPI_RESCHEDULE, IA64_IPI_DM_INT, 0);
   58.22  }
   58.23  
   58.24  
   58.25 @@ -249,6 +258,7 @@ send_IPI_self (int op)
   58.26  	send_IPI_single(smp_processor_id(), op);
   58.27  }
   58.28  
   58.29 +#ifndef XEN
   58.30  /*
   58.31   * Called with preeemption disabled.
   58.32   */
   58.33 @@ -257,6 +267,7 @@ smp_send_reschedule (int cpu)
   58.34  {
   58.35  	platform_send_ipi(cpu, IA64_IPI_RESCHEDULE, IA64_IPI_DM_INT, 0);
   58.36  }
   58.37 +#endif
   58.38  
   58.39  void
   58.40  smp_flush_tlb_all (void)
   58.41 @@ -395,15 +406,14 @@ smp_call_function (void (*func) (void *i
   58.42  	if (wait)
   58.43  		atomic_set(&data.finished, 0);
   58.44  
   58.45 -	printk("smp_call_function: about to spin_lock \n");
   58.46  	spin_lock(&call_lock);
   58.47 -	printk("smp_call_function: done with spin_lock \n");
   58.48 +#if 0 //def XEN
   58.49 +	printk("smp_call_function: %d lock\n", smp_processor_id ());
   58.50 +#endif
   58.51  
   58.52  	call_data = &data;
   58.53  	mb();	/* ensure store to call_data precedes setting of IPI_CALL_FUNC */
   58.54 -	printk("smp_call_function: about to send_IPI \n");
   58.55  	send_IPI_allbutself(IPI_CALL_FUNC);
   58.56 -	printk("smp_call_function: done with send_IPI \n");
   58.57  
   58.58  	/* Wait for response */
   58.59  	while (atomic_read(&data.started) != cpus)
   58.60 @@ -414,9 +424,10 @@ smp_call_function (void (*func) (void *i
   58.61  			cpu_relax();
   58.62  	call_data = NULL;
   58.63  
   58.64 -	printk("smp_call_function: about to spin_unlock \n");
   58.65  	spin_unlock(&call_lock);
   58.66 +#if 0 //def XEN
   58.67  	printk("smp_call_function: DONE WITH spin_unlock, returning \n");
   58.68 +#endif
   58.69  	return 0;
   58.70  }
   58.71  EXPORT_SYMBOL(smp_call_function);
    59.1 --- a/xen/arch/ia64/linux-xen/smpboot.c	Sun Oct 30 13:52:38 2005 +0100
    59.2 +++ b/xen/arch/ia64/linux-xen/smpboot.c	Sun Oct 30 14:00:35 2005 +0100
    59.3 @@ -477,6 +477,22 @@ do_boot_cpu (int sapicid, int cpu)
    59.4  
    59.5  do_rest:
    59.6  	task_for_booting_cpu = c_idle.idle;
    59.7 +#else
    59.8 +	struct domain *idle;
    59.9 +	struct vcpu *v;
   59.10 +	void *stack;
   59.11 +
   59.12 +	if ( (idle = do_createdomain(IDLE_DOMAIN_ID, cpu)) == NULL )
   59.13 +		panic("failed 'createdomain' for CPU %d", cpu);
   59.14 +	set_bit(_DOMF_idle_domain, &idle->domain_flags);
   59.15 +	v = idle->vcpu[0];
   59.16 +
   59.17 +	printf ("do_boot_cpu: cpu=%d, domain=%p, vcpu=%p\n", cpu, idle, v);
   59.18 +
   59.19 +	task_for_booting_cpu = v;
   59.20 +
   59.21 +	/* Set cpu number.  */
   59.22 +	get_thread_info(v)->cpu = cpu;
   59.23  #endif
   59.24  
   59.25  	Dprintk("Sending wakeup vector %lu to AP 0x%x/0x%x.\n", ap_wakeup_vector, cpu, sapicid);
    60.1 --- a/xen/arch/ia64/vmx/mm.c	Sun Oct 30 13:52:38 2005 +0100
    60.2 +++ b/xen/arch/ia64/vmx/mm.c	Sun Oct 30 14:00:35 2005 +0100
    60.3 @@ -87,7 +87,7 @@
    60.4   */
    60.5  
    60.6  #include <xen/config.h>
    60.7 -#include <public/xen.h>
    60.8 +//#include <public/xen.h>
    60.9  #include <xen/init.h>
   60.10  #include <xen/lib.h>
   60.11  #include <xen/mm.h>
    61.1 --- a/xen/arch/ia64/vmx/vmx_entry.S	Sun Oct 30 13:52:38 2005 +0100
    61.2 +++ b/xen/arch/ia64/vmx/vmx_entry.S	Sun Oct 30 14:00:35 2005 +0100
    61.3 @@ -720,11 +720,11 @@ 1:
    61.4  
    61.5     // re-pin mappings for guest_vhpt
    61.6  
    61.7 -   mov r24=IA64_TR_VHPT
    61.8 +   mov r24=IA64_TR_PERVP_VHPT
    61.9     movl r25=PAGE_KERNEL
   61.10     ;;
   61.11     or loc5 = r25,loc5          // construct PA | page properties
   61.12 -   mov r23 = VCPU_TLB_SHIFT<<2
   61.13 +   mov r23 = IA64_GRANULE_SHIFT <<2
   61.14     ;;
   61.15     ptr.d   in3,r23
   61.16     ;;
    62.1 --- a/xen/arch/ia64/vmx/vmx_hypercall.c	Sun Oct 30 13:52:38 2005 +0100
    62.2 +++ b/xen/arch/ia64/vmx/vmx_hypercall.c	Sun Oct 30 14:00:35 2005 +0100
    62.3 @@ -22,7 +22,7 @@
    62.4  #include <xen/config.h>
    62.5  #include <xen/errno.h>
    62.6  #include <asm/vmx_vcpu.h>
    62.7 -#include <public/xen.h>
    62.8 +//#include <public/xen.h>
    62.9  #include <public/event_channel.h>
   62.10  #include <asm/vmmu.h>
   62.11  #include <asm/tlb.h>
    63.1 --- a/xen/arch/ia64/vmx/vmx_init.c	Sun Oct 30 13:52:38 2005 +0100
    63.2 +++ b/xen/arch/ia64/vmx/vmx_init.c	Sun Oct 30 14:00:35 2005 +0100
    63.3 @@ -47,6 +47,7 @@
    63.4  #include <asm/processor.h>
    63.5  #include <asm/vmx.h>
    63.6  #include <xen/mm.h>
    63.7 +#include <public/arch-ia64.h>
    63.8  
    63.9  /* Global flag to identify whether Intel vmx feature is on */
   63.10  u32 vmx_enabled = 0;
   63.11 @@ -136,39 +137,6 @@ vmx_init_env(void)
   63.12  #endif 
   63.13  }
   63.14  
   63.15 -void vmx_setup_platform(struct vcpu *v, struct vcpu_guest_context *c)
   63.16 -{
   63.17 -	struct domain *d = v->domain;
   63.18 -	shared_iopage_t *sp;
   63.19 -
   63.20 -	ASSERT(d != dom0); /* only for non-privileged vti domain */
   63.21 -	d->arch.vmx_platform.shared_page_va = __va(c->share_io_pg);
   63.22 -	sp = get_sp(d);
   63.23 -	memset((char *)sp,0,PAGE_SIZE);
   63.24 -	/* FIXME: temp due to old CP */
   63.25 -	sp->sp_global.eport = 2;
   63.26 -#ifdef V_IOSAPIC_READY
   63.27 -	sp->vcpu_number = 1;
   63.28 -#endif
   63.29 -	/* TEMP */
   63.30 -	d->arch.vmx_platform.pib_base = 0xfee00000UL;
   63.31 -
   63.32 -	/* One more step to enable interrupt assist */
   63.33 -	set_bit(ARCH_VMX_INTR_ASSIST, &v->arch.arch_vmx.flags);
   63.34 -	/* Only open one port for I/O and interrupt emulation */
   63.35 -	if (v == d->vcpu[0]) {
   63.36 -	    memset(&d->shared_info->evtchn_mask[0], 0xff,
   63.37 -		sizeof(d->shared_info->evtchn_mask));
   63.38 -	    clear_bit(iopacket_port(d), &d->shared_info->evtchn_mask[0]);
   63.39 -	}
   63.40 -
   63.41 -	/* FIXME: only support PMT table continuously by far */
   63.42 -//	d->arch.pmt = __va(c->pt_base);
   63.43 -
   63.44 -
   63.45 -	vmx_final_setup_domain(d);
   63.46 -}
   63.47 -
   63.48  typedef union {
   63.49  	u64 value;
   63.50  	struct {
   63.51 @@ -376,40 +344,6 @@ vmx_final_setup_domain(struct domain *d)
   63.52  	/* Other vmx specific initialization work */
   63.53  }
   63.54  
   63.55 -/*
   63.56 - * Following stuff should really move to domain builder. However currently
   63.57 - * XEN/IA64 doesn't export physical -> machine page table to domain builder,
   63.58 - * instead only the copy. Also there's no hypercall to notify hypervisor
   63.59 - * IO ranges by far. Let's enhance it later.
   63.60 - */
   63.61 -
   63.62 -#define MEM_G   (1UL << 30)	
   63.63 -#define MEM_M   (1UL << 20)	
   63.64 -
   63.65 -#define MMIO_START       (3 * MEM_G)
   63.66 -#define MMIO_SIZE        (512 * MEM_M)
   63.67 -
   63.68 -#define VGA_IO_START     0xA0000UL
   63.69 -#define VGA_IO_SIZE      0x20000
   63.70 -
   63.71 -#define LEGACY_IO_START  (MMIO_START + MMIO_SIZE)
   63.72 -#define LEGACY_IO_SIZE   (64*MEM_M)  
   63.73 -
   63.74 -#define IO_PAGE_START (LEGACY_IO_START + LEGACY_IO_SIZE)
   63.75 -#define IO_PAGE_SIZE  PAGE_SIZE
   63.76 -
   63.77 -#define STORE_PAGE_START (IO_PAGE_START + IO_PAGE_SIZE)
   63.78 -#define STORE_PAGE_SIZE	 PAGE_SIZE
   63.79 -
   63.80 -#define IO_SAPIC_START   0xfec00000UL
   63.81 -#define IO_SAPIC_SIZE    0x100000
   63.82 -
   63.83 -#define PIB_START 0xfee00000UL
   63.84 -#define PIB_SIZE 0x100000 
   63.85 -
   63.86 -#define GFW_START        (4*MEM_G -16*MEM_M)
   63.87 -#define GFW_SIZE         (16*MEM_M)
   63.88 -
   63.89  typedef struct io_range {
   63.90  	unsigned long start;
   63.91  	unsigned long size;
   63.92 @@ -424,18 +358,26 @@ io_range_t io_ranges[] = {
   63.93  	{PIB_START, PIB_SIZE, GPFN_PIB},
   63.94  };
   63.95  
   63.96 -#define VMX_SYS_PAGES	(2 + GFW_SIZE >> PAGE_SHIFT)
   63.97 +#define VMX_SYS_PAGES	(2 + (GFW_SIZE >> PAGE_SHIFT))
   63.98  #define VMX_CONFIG_PAGES(d) ((d)->max_pages - VMX_SYS_PAGES)
   63.99  
  63.100  int vmx_alloc_contig_pages(struct domain *d)
  63.101  {
  63.102 -	unsigned int order, i, j;
  63.103 -	unsigned long start, end, pgnr, conf_nr;
  63.104 +	unsigned int order;
  63.105 +	unsigned long i, j, start, end, pgnr, conf_nr;
  63.106  	struct pfn_info *page;
  63.107  	struct vcpu *v = d->vcpu[0];
  63.108  
  63.109  	ASSERT(!test_bit(ARCH_VMX_CONTIG_MEM, &v->arch.arch_vmx.flags));
  63.110  
  63.111 +	/* Mark I/O ranges */
  63.112 +	for (i = 0; i < (sizeof(io_ranges) / sizeof(io_range_t)); i++) {
  63.113 +	    for (j = io_ranges[i].start;
  63.114 +		 j < io_ranges[i].start + io_ranges[i].size;
  63.115 +		 j += PAGE_SIZE)
  63.116 +		map_domain_page(d, j, io_ranges[i].type);
  63.117 +	}
  63.118 +
  63.119  	conf_nr = VMX_CONFIG_PAGES(d);
  63.120  	order = get_order_from_pages(conf_nr);
  63.121  	if (unlikely((page = alloc_domheap_pages(d, order, 0)) == NULL)) {
  63.122 @@ -462,32 +404,64 @@ int vmx_alloc_contig_pages(struct domain
  63.123  
  63.124  	d->arch.max_pfn = end >> PAGE_SHIFT;
  63.125  
  63.126 -	order = get_order_from_pages(VMX_SYS_PAGES);
  63.127 +	order = get_order_from_pages(GFW_SIZE >> PAGE_SHIFT);
  63.128  	if (unlikely((page = alloc_domheap_pages(d, order, 0)) == NULL)) {
  63.129  	    printk("Could not allocate order=%d pages for vmx contig alloc\n",
  63.130  			order);
  63.131  	    return -1;
  63.132  	}
  63.133  
  63.134 +	/* Map guest firmware */
  63.135 +	pgnr = page_to_pfn(page);
  63.136 +	for (i = GFW_START; i < GFW_START + GFW_SIZE; i += PAGE_SIZE, pgnr++)
  63.137 +	    map_domain_page(d, i, pgnr << PAGE_SHIFT);
  63.138 +
  63.139 +	if (unlikely((page = alloc_domheap_pages(d, 1, 0)) == NULL)) {
  63.140 +	    printk("Could not allocate order=1 pages for vmx contig alloc\n");
  63.141 +	    return -1;
  63.142 +	}
  63.143 +
  63.144  	/* Map for shared I/O page and xenstore */
  63.145  	pgnr = page_to_pfn(page);
  63.146  	map_domain_page(d, IO_PAGE_START, pgnr << PAGE_SHIFT);
  63.147  	pgnr++;
  63.148  	map_domain_page(d, STORE_PAGE_START, pgnr << PAGE_SHIFT);
  63.149 -	pgnr++;
  63.150 -
  63.151 -	/* Map guest firmware */
  63.152 -	for (i = GFW_START; i < GFW_START + GFW_SIZE; i += PAGE_SIZE, pgnr++)
  63.153 -	    map_domain_page(d, i, pgnr << PAGE_SHIFT);
  63.154 -
  63.155 -	/* Mark I/O ranges */
  63.156 -	for (i = 0; i < (sizeof(io_ranges) / sizeof(io_range_t)); i++) {
  63.157 -	    for (j = io_ranges[i].start;
  63.158 -		 j < io_ranges[i].start + io_ranges[i].size;
  63.159 -		 j += PAGE_SIZE)
  63.160 -		map_domain_page(d, j, io_ranges[i].type);
  63.161 -	}
  63.162  
  63.163  	set_bit(ARCH_VMX_CONTIG_MEM, &v->arch.arch_vmx.flags);
  63.164  	return 0;
  63.165  }
  63.166 +
  63.167 +void vmx_setup_platform(struct vcpu *v, struct vcpu_guest_context *c)
  63.168 +{
  63.169 +	struct domain *d = v->domain;
  63.170 +	shared_iopage_t *sp;
  63.171 +
  63.172 +	ASSERT(d != dom0); /* only for non-privileged vti domain */
  63.173 +	d->arch.vmx_platform.shared_page_va =
  63.174 +		__va(__gpa_to_mpa(d, IO_PAGE_START));
  63.175 +	sp = get_sp(d);
  63.176 +	//memset((char *)sp,0,PAGE_SIZE);
  63.177 +	//sp->sp_global.eport = 2;
  63.178 +#ifdef V_IOSAPIC_READY
  63.179 +	sp->vcpu_number = 1;
  63.180 +#endif
  63.181 +	/* TEMP */
  63.182 +	d->arch.vmx_platform.pib_base = 0xfee00000UL;
  63.183 +
  63.184 +	/* One more step to enable interrupt assist */
  63.185 +	set_bit(ARCH_VMX_INTR_ASSIST, &v->arch.arch_vmx.flags);
  63.186 +	/* Only open one port for I/O and interrupt emulation */
  63.187 +	if (v == d->vcpu[0]) {
  63.188 +	    memset(&d->shared_info->evtchn_mask[0], 0xff,
  63.189 +		sizeof(d->shared_info->evtchn_mask));
  63.190 +	    clear_bit(iopacket_port(d), &d->shared_info->evtchn_mask[0]);
  63.191 +	}
  63.192 +
  63.193 +	/* FIXME: only support PMT table continuously by far */
  63.194 +//	d->arch.pmt = __va(c->pt_base);
  63.195 +
  63.196 +
  63.197 +	vmx_final_setup_domain(d);
  63.198 +}
  63.199 +
  63.200 +
    64.1 --- a/xen/arch/ia64/vmx/vmx_irq_ia64.c	Sun Oct 30 13:52:38 2005 +0100
    64.2 +++ b/xen/arch/ia64/vmx/vmx_irq_ia64.c	Sun Oct 30 14:00:35 2005 +0100
    64.3 @@ -101,7 +101,10 @@ vmx_ia64_handle_irq (ia64_vector vector,
    64.4  
    64.5  		if (vector != IA64_TIMER_VECTOR) {
    64.6  			/* FIXME: Leave IRQ re-route later */
    64.7 -			vmx_vcpu_pend_interrupt(dom0->vcpu[0],vector);
    64.8 +			if (!VMX_DOMAIN(dom0->vcpu[0]))
    64.9 +				vcpu_pend_interrupt(dom0->vcpu[0],vector);
   64.10 +			else
   64.11 +				vmx_vcpu_pend_interrupt(dom0->vcpu[0],vector);
   64.12  			wake_dom0 = 1;
   64.13  		}
   64.14  		else {	// FIXME: Handle Timer only now
    65.1 --- a/xen/arch/ia64/vmx/vmx_phy_mode.c	Sun Oct 30 13:52:38 2005 +0100
    65.2 +++ b/xen/arch/ia64/vmx/vmx_phy_mode.c	Sun Oct 30 14:00:35 2005 +0100
    65.3 @@ -157,13 +157,6 @@ physical_itlb_miss_domn(VCPU *vcpu, u64 
    65.4  #endif
    65.5  
    65.6  void
    65.7 -physical_itlb_miss(VCPU *vcpu, u64 vadr)
    65.8 -{
    65.9 -        physical_itlb_miss_dom0(vcpu, vadr);
   65.10 -}
   65.11 -
   65.12 -
   65.13 -void
   65.14  physical_itlb_miss_dom0(VCPU *vcpu, u64 vadr)
   65.15  {
   65.16      u64 psr;
   65.17 @@ -187,6 +180,13 @@ physical_itlb_miss_dom0(VCPU *vcpu, u64 
   65.18  
   65.19  
   65.20  void
   65.21 +physical_itlb_miss(VCPU *vcpu, u64 vadr)
   65.22 +{
   65.23 +        physical_itlb_miss_dom0(vcpu, vadr);
   65.24 +}
   65.25 +
   65.26 +
   65.27 +void
   65.28  physical_dtlb_miss(VCPU *vcpu, u64 vadr)
   65.29  {
   65.30      u64 psr;
    66.1 --- a/xen/arch/ia64/vmx/vmx_process.c	Sun Oct 30 13:52:38 2005 +0100
    66.2 +++ b/xen/arch/ia64/vmx/vmx_process.c	Sun Oct 30 14:00:35 2005 +0100
    66.3 @@ -56,6 +56,38 @@ extern struct ia64_sal_retval pal_emulat
    66.4  extern struct ia64_sal_retval sal_emulator(UINT64,UINT64,UINT64,UINT64,UINT64,UINT64,UINT64,UINT64);
    66.5  extern void rnat_consumption (VCPU *vcpu);
    66.6  #define DOMN_PAL_REQUEST    0x110000
    66.7 +
    66.8 +static UINT64 vec2off[68] = {0x0,0x400,0x800,0xc00,0x1000, 0x1400,0x1800,
    66.9 +    0x1c00,0x2000,0x2400,0x2800,0x2c00,0x3000,0x3400,0x3800,0x3c00,0x4000,
   66.10 +    0x4400,0x4800,0x4c00,0x5000,0x5100,0x5200,0x5300,0x5400,0x5500,0x5600,
   66.11 +    0x5700,0x5800,0x5900,0x5a00,0x5b00,0x5c00,0x5d00,0x5e00,0x5f00,0x6000,
   66.12 +    0x6100,0x6200,0x6300,0x6400,0x6500,0x6600,0x6700,0x6800,0x6900,0x6a00,
   66.13 +    0x6b00,0x6c00,0x6d00,0x6e00,0x6f00,0x7000,0x7100,0x7200,0x7300,0x7400,
   66.14 +    0x7500,0x7600,0x7700,0x7800,0x7900,0x7a00,0x7b00,0x7c00,0x7d00,0x7e00,
   66.15 +    0x7f00,
   66.16 +};
   66.17 +
   66.18 +
   66.19 +
   66.20 +void vmx_reflect_interruption(UINT64 ifa,UINT64 isr,UINT64 iim,
   66.21 +     UINT64 vector,REGS *regs)
   66.22 +{
   66.23 +    VCPU *vcpu = current;
   66.24 +    UINT64 viha,vpsr = vmx_vcpu_get_psr(vcpu);
   66.25 +    if(!(vpsr&IA64_PSR_IC)&&(vector!=5)){
   66.26 +        panic("Guest nested fault!");
   66.27 +    }
   66.28 +    VCPU(vcpu,isr)=isr;
   66.29 +    VCPU(vcpu,iipa) = regs->cr_iip;
   66.30 +    vector=vec2off[vector];
   66.31 +    if (vector == IA64_BREAK_VECTOR || vector == IA64_SPECULATION_VECTOR)
   66.32 +        VCPU(vcpu,iim) = iim;
   66.33 +    else {
   66.34 +        set_ifa_itir_iha(vcpu,ifa,1,1,1);
   66.35 +    }
   66.36 +    inject_guest_interruption(vcpu, vector);
   66.37 +}
   66.38 +
   66.39  IA64FAULT
   66.40  vmx_ia64_handle_break (unsigned long ifa, struct pt_regs *regs, unsigned long isr, unsigned long iim)
   66.41  {
   66.42 @@ -157,37 +189,6 @@ vmx_ia64_handle_break (unsigned long ifa
   66.43  		vmx_reflect_interruption(ifa,isr,iim,11,regs);
   66.44  }
   66.45  
   66.46 -static UINT64 vec2off[68] = {0x0,0x400,0x800,0xc00,0x1000, 0x1400,0x1800,
   66.47 -    0x1c00,0x2000,0x2400,0x2800,0x2c00,0x3000,0x3400,0x3800,0x3c00,0x4000,
   66.48 -    0x4400,0x4800,0x4c00,0x5000,0x5100,0x5200,0x5300,0x5400,0x5500,0x5600,
   66.49 -    0x5700,0x5800,0x5900,0x5a00,0x5b00,0x5c00,0x5d00,0x5e00,0x5f00,0x6000,
   66.50 -    0x6100,0x6200,0x6300,0x6400,0x6500,0x6600,0x6700,0x6800,0x6900,0x6a00,
   66.51 -    0x6b00,0x6c00,0x6d00,0x6e00,0x6f00,0x7000,0x7100,0x7200,0x7300,0x7400,
   66.52 -    0x7500,0x7600,0x7700,0x7800,0x7900,0x7a00,0x7b00,0x7c00,0x7d00,0x7e00,
   66.53 -    0x7f00,
   66.54 -};
   66.55 -
   66.56 -
   66.57 -
   66.58 -void vmx_reflect_interruption(UINT64 ifa,UINT64 isr,UINT64 iim,
   66.59 -     UINT64 vector,REGS *regs)
   66.60 -{
   66.61 -    VCPU *vcpu = current;
   66.62 -    UINT64 viha,vpsr = vmx_vcpu_get_psr(vcpu);
   66.63 -    if(!(vpsr&IA64_PSR_IC)&&(vector!=5)){
   66.64 -        panic("Guest nested fault!");
   66.65 -    }
   66.66 -    VCPU(vcpu,isr)=isr;
   66.67 -    VCPU(vcpu,iipa) = regs->cr_iip;
   66.68 -    vector=vec2off[vector];
   66.69 -    if (vector == IA64_BREAK_VECTOR || vector == IA64_SPECULATION_VECTOR)
   66.70 -        VCPU(vcpu,iim) = iim;
   66.71 -    else {
   66.72 -        set_ifa_itir_iha(vcpu,ifa,1,1,1);
   66.73 -    }
   66.74 -    inject_guest_interruption(vcpu, vector);
   66.75 -}
   66.76 -
   66.77  
   66.78  void save_banked_regs_to_vpd(VCPU *v, REGS *regs)
   66.79  {
   66.80 @@ -271,10 +272,10 @@ void vmx_hpw_miss(u64 vadr , u64 vec, RE
   66.81  {
   66.82      IA64_PSR vpsr;
   66.83      CACHE_LINE_TYPE type;
   66.84 -    u64 vhpt_adr;
   66.85 +    u64 vhpt_adr, gppa;
   66.86      ISR misr;
   66.87      ia64_rr vrr;
   66.88 -    REGS *regs;
   66.89 +//    REGS *regs;
   66.90      thash_cb_t *vtlb, *vhpt;
   66.91      thash_data_t *data, me;
   66.92      VCPU *v = current;
   66.93 @@ -314,9 +315,9 @@ void vmx_hpw_miss(u64 vadr , u64 vec, RE
   66.94  //    prepare_if_physical_mode(v);
   66.95  
   66.96      if(data=vtlb_lookup_ex(vtlb, vrr.rid, vadr,type)){
   66.97 -        if(v->domain!=dom0&&type==DSIDE_TLB && __gpfn_is_io(v->domain,data->ppn>>(PAGE_SHIFT-12))){
   66.98 -            vadr=(vadr&((1UL<<data->ps)-1))+(data->ppn>>(data->ps-12)<<data->ps);
   66.99 -            emulate_io_inst(v, vadr, data->ma);
  66.100 +	gppa = (vadr&((1UL<<data->ps)-1))+(data->ppn>>(data->ps-12)<<data->ps);
  66.101 +        if(v->domain!=dom0&&type==DSIDE_TLB && __gpfn_is_io(v->domain,gppa>>PAGE_SHIFT)){
  66.102 +            emulate_io_inst(v, gppa, data->ma);
  66.103              return IA64_FAULT;
  66.104          }
  66.105  
    67.1 --- a/xen/arch/ia64/vmx/vmx_support.c	Sun Oct 30 13:52:38 2005 +0100
    67.2 +++ b/xen/arch/ia64/vmx/vmx_support.c	Sun Oct 30 14:00:35 2005 +0100
    67.3 @@ -158,7 +158,7 @@ void vmx_intr_assist(struct vcpu *v)
    67.4  #ifdef V_IOSAPIC_READY
    67.5      vlapic_update_ext_irq(v);
    67.6  #else
    67.7 -    panic("IOSAPIC model is missed in qemu\n");
    67.8 +    //panic("IOSAPIC model is missed in qemu\n");
    67.9  #endif
   67.10      return;
   67.11  }
    68.1 --- a/xen/arch/ia64/vmx/vtlb.c	Sun Oct 30 13:52:38 2005 +0100
    68.2 +++ b/xen/arch/ia64/vmx/vtlb.c	Sun Oct 30 14:00:35 2005 +0100
    68.3 @@ -387,6 +387,15 @@ void vtlb_insert(thash_cb_t *hcb, thash_
    68.4         thash_insert(hcb->ts->vhpt, entry, va);
    68.5          return;
    68.6      }
    68.7 +
    68.8 +#if 1
    68.9 +    vrr=vmx_vcpu_rr(current, va);
   68.10 +    if (vrr.ps != entry->ps) {
   68.11 +	printk("not preferred ps with va: 0x%lx\n", va);
   68.12 +	return;
   68.13 +    }
   68.14 +#endif 
   68.15 +
   68.16      flag = 1;
   68.17      gppn = (POFFSET(va,entry->ps)|PAGEALIGN((entry->ppn<<12),entry->ps))>>PAGE_SHIFT;
   68.18      ppns = PAGEALIGN((entry->ppn<<12),entry->ps);
    69.1 --- a/xen/arch/ia64/xen/acpi.c	Sun Oct 30 13:52:38 2005 +0100
    69.2 +++ b/xen/arch/ia64/xen/acpi.c	Sun Oct 30 14:00:35 2005 +0100
    69.3 @@ -121,6 +121,7 @@ acpi_get_sysname (void)
    69.4  #ifdef CONFIG_ACPI_BOOT
    69.5  
    69.6  #define ACPI_MAX_PLATFORM_INTERRUPTS	256
    69.7 +#define NR_IOSAPICS 4
    69.8  
    69.9  #if 0
   69.10  /* Array to record platform interrupt vectors for generic interrupt routing. */
   69.11 @@ -162,7 +163,6 @@ static int			available_cpus __initdata;
   69.12  struct acpi_table_madt *	acpi_madt __initdata;
   69.13  static u8			has_8259;
   69.14  
   69.15 -#if 0
   69.16  static int __init
   69.17  acpi_parse_lapic_addr_ovr (
   69.18  	acpi_table_entry_header *header, const unsigned long end)
   69.19 @@ -247,12 +247,13 @@ acpi_parse_iosapic (acpi_table_entry_hea
   69.20  
   69.21  	acpi_table_print_madt_entry(header);
   69.22  
   69.23 +#if 0
   69.24  	iosapic_init(iosapic->address, iosapic->global_irq_base);
   69.25 +#endif
   69.26  
   69.27  	return 0;
   69.28  }
   69.29  
   69.30 -
   69.31  static int __init
   69.32  acpi_parse_plat_int_src (
   69.33  	acpi_table_entry_header *header, const unsigned long end)
   69.34 @@ -267,6 +268,7 @@ acpi_parse_plat_int_src (
   69.35  
   69.36  	acpi_table_print_madt_entry(header);
   69.37  
   69.38 +#if 0
   69.39  	/*
   69.40  	 * Get vector assignment for this interrupt, set attributes,
   69.41  	 * and program the IOSAPIC routing table.
   69.42 @@ -280,6 +282,7 @@ acpi_parse_plat_int_src (
   69.43  						(plintsrc->flags.trigger == 1) ? IOSAPIC_EDGE : IOSAPIC_LEVEL);
   69.44  
   69.45  	platform_intr_list[plintsrc->type] = vector;
   69.46 +#endif
   69.47  	return 0;
   69.48  }
   69.49  
   69.50 @@ -297,13 +300,14 @@ acpi_parse_int_src_ovr (
   69.51  
   69.52  	acpi_table_print_madt_entry(header);
   69.53  
   69.54 +#if 0
   69.55  	iosapic_override_isa_irq(p->bus_irq, p->global_irq,
   69.56  				 (p->flags.polarity == 1) ? IOSAPIC_POL_HIGH : IOSAPIC_POL_LOW,
   69.57  				 (p->flags.trigger == 1) ? IOSAPIC_EDGE : IOSAPIC_LEVEL);
   69.58 +#endif
   69.59  	return 0;
   69.60  }
   69.61  
   69.62 -
   69.63  static int __init
   69.64  acpi_parse_nmi_src (acpi_table_entry_header *header, const unsigned long end)
   69.65  {
   69.66 @@ -331,8 +335,10 @@ void __init acpi_madt_oem_check(char *oe
   69.67  		 */
   69.68  		sal_platform_features |= IA64_SAL_PLATFORM_FEATURE_ITC_DRIFT;
   69.69  
   69.70 +#if 0
   69.71  		/*Start cyclone clock*/
   69.72  		cyclone_setup(0);
   69.73 +#endif
   69.74  	}
   69.75  }
   69.76  
   69.77 @@ -350,7 +356,9 @@ acpi_parse_madt (unsigned long phys_addr
   69.78  #else
   69.79  	has_8259 = acpi_madt->flags.pcat_compat;
   69.80  #endif
   69.81 +#if 0
   69.82  	iosapic_system_init(has_8259);
   69.83 +#endif
   69.84  
   69.85  	/* Get base address of IPI Message Block */
   69.86  
   69.87 @@ -364,7 +372,6 @@ acpi_parse_madt (unsigned long phys_addr
   69.88  
   69.89  	return 0;
   69.90  }
   69.91 -#endif
   69.92  
   69.93  #ifdef CONFIG_ACPI_NUMA
   69.94  
   69.95 @@ -529,6 +536,7 @@ acpi_register_gsi (u32 gsi, int polarity
   69.96  	return acpi_register_irq(gsi, polarity, trigger);
   69.97  }
   69.98  EXPORT_SYMBOL(acpi_register_gsi);
   69.99 +#endif
  69.100  static int __init
  69.101  acpi_parse_fadt (unsigned long phys_addr, unsigned long size)
  69.102  {
  69.103 @@ -550,10 +558,11 @@ acpi_parse_fadt (unsigned long phys_addr
  69.104  	if (fadt->iapc_boot_arch & BAF_LEGACY_DEVICES)
  69.105  		acpi_legacy_devices = 1;
  69.106  
  69.107 +#if 0
  69.108  	acpi_register_gsi(fadt->sci_int, ACPI_ACTIVE_LOW, ACPI_LEVEL_SENSITIVE);
  69.109 +#endif
  69.110  	return 0;
  69.111  }
  69.112 -#endif
  69.113  
  69.114  unsigned long __init
  69.115  acpi_find_rsdp (void)
  69.116 @@ -567,7 +576,6 @@ acpi_find_rsdp (void)
  69.117  	return rsdp_phys;
  69.118  }
  69.119  
  69.120 -#if 0
  69.121  int __init
  69.122  acpi_boot_init (void)
  69.123  {
  69.124 @@ -646,6 +654,7 @@ acpi_boot_init (void)
  69.125  	printk(KERN_INFO "%d CPUs available, %d CPUs total\n", available_cpus, total_cpus);
  69.126  	return 0;
  69.127  }
  69.128 +#if 0
  69.129  int
  69.130  acpi_gsi_to_irq (u32 gsi, unsigned int *irq)
  69.131  {
    70.1 --- a/xen/arch/ia64/xen/dom0_ops.c	Sun Oct 30 13:52:38 2005 +0100
    70.2 +++ b/xen/arch/ia64/xen/dom0_ops.c	Sun Oct 30 14:00:35 2005 +0100
    70.3 @@ -177,13 +177,8 @@ long arch_do_dom0_op(dom0_op_t *op, dom0
    70.4  
    70.5              for ( i = start_page; i < (start_page + nr_pages); i++ )
    70.6              {
    70.7 -                page = map_new_domain_page(d, i << PAGE_SHIFT);
    70.8 -                if ( page == NULL )
    70.9 -                {
   70.10 -                    ret = -ENOMEM;
   70.11 -                    break;
   70.12 -                }
   70.13 -                pfn = page_to_pfn(page);
   70.14 +		pfn = __gpfn_to_mfn_foreign(d, i);
   70.15 +
   70.16                  if ( put_user(pfn, buffer) )
   70.17                  {
   70.18                      ret = -EFAULT;
    71.1 --- a/xen/arch/ia64/xen/dom_fw.c	Sun Oct 30 13:52:38 2005 +0100
    71.2 +++ b/xen/arch/ia64/xen/dom_fw.c	Sun Oct 30 14:00:35 2005 +0100
    71.3 @@ -301,7 +301,7 @@ xen_pal_emulator(unsigned long index, un
    71.4  	// pal code must be mapped by a TR when pal is called, however
    71.5  	// calls are rare enough that we will map it lazily rather than
    71.6  	// at every context switch
    71.7 -	efi_map_pal_code();
    71.8 +	//efi_map_pal_code();
    71.9  	switch (index) {
   71.10  	    case PAL_MEM_ATTRIB:
   71.11  		status = ia64_pal_mem_attrib(&r9);
    72.1 --- a/xen/arch/ia64/xen/domain.c	Sun Oct 30 13:52:38 2005 +0100
    72.2 +++ b/xen/arch/ia64/xen/domain.c	Sun Oct 30 14:00:35 2005 +0100
    72.3 @@ -23,11 +23,13 @@
    72.4  #include <asm/io.h>
    72.5  #include <asm/processor.h>
    72.6  #include <asm/desc.h>
    72.7 +#include <asm/hw_irq.h>
    72.8  //#include <asm/mpspec.h>
    72.9  #include <xen/irq.h>
   72.10  #include <xen/event.h>
   72.11  //#include <xen/shadow.h>
   72.12  #include <xen/console.h>
   72.13 +#include <xen/compile.h>
   72.14  
   72.15  #include <xen/elf.h>
   72.16  //#include <asm/page.h>
   72.17 @@ -58,6 +60,7 @@ unsigned long *domU_staging_area;
   72.18  
   72.19  // initialized by arch/ia64/setup.c:find_initrd()
   72.20  unsigned long initrd_start = 0, initrd_end = 0;
   72.21 +extern unsigned long running_on_sim;
   72.22  
   72.23  #define IS_XEN_ADDRESS(d,a) ((a >= d->xen_vastart) && (a <= d->xen_vaend))
   72.24  
   72.25 @@ -75,35 +78,21 @@ void free_perdomain_pt(struct domain *d)
   72.26  	//free_page((unsigned long)d->mm.perdomain_pt);
   72.27  }
   72.28  
   72.29 -int hlt_counter;
   72.30 -
   72.31 -void disable_hlt(void)
   72.32 +static void default_idle(void)
   72.33  {
   72.34 -	hlt_counter++;
   72.35 -}
   72.36 -
   72.37 -void enable_hlt(void)
   72.38 -{
   72.39 -	hlt_counter--;
   72.40 +	int cpu = smp_processor_id();
   72.41 +	local_irq_disable();
   72.42 +	if ( !softirq_pending(cpu))
   72.43 +	        safe_halt();
   72.44 +	local_irq_enable();
   72.45  }
   72.46  
   72.47 -static void default_idle(void)
   72.48 -{
   72.49 -	if ( hlt_counter == 0 )
   72.50 -	{
   72.51 -	local_irq_disable();
   72.52 -	    if ( !softirq_pending(smp_processor_id()) )
   72.53 -	        safe_halt();
   72.54 -	    //else
   72.55 -		local_irq_enable();
   72.56 -	}
   72.57 -}
   72.58 -
   72.59 -void continue_cpu_idle_loop(void)
   72.60 +static void continue_cpu_idle_loop(void)
   72.61  {
   72.62  	int cpu = smp_processor_id();
   72.63  	for ( ; ; )
   72.64  	{
   72.65 +	printf ("idle%dD\n", cpu);
   72.66  #ifdef IA64
   72.67  //        __IRQ_STAT(cpu, idle_timestamp) = jiffies
   72.68  #else
   72.69 @@ -111,23 +100,32 @@ void continue_cpu_idle_loop(void)
   72.70  #endif
   72.71  	    while ( !softirq_pending(cpu) )
   72.72  	        default_idle();
   72.73 +	    add_preempt_count(SOFTIRQ_OFFSET);
   72.74  	    raise_softirq(SCHEDULE_SOFTIRQ);
   72.75  	    do_softirq();
   72.76 +	    sub_preempt_count(SOFTIRQ_OFFSET);
   72.77  	}
   72.78  }
   72.79  
   72.80  void startup_cpu_idle_loop(void)
   72.81  {
   72.82 +	int cpu = smp_processor_id ();
   72.83  	/* Just some sanity to ensure that the scheduler is set up okay. */
   72.84  	ASSERT(current->domain == IDLE_DOMAIN_ID);
   72.85 +	printf ("idle%dA\n", cpu);
   72.86  	raise_softirq(SCHEDULE_SOFTIRQ);
   72.87 +#if 0   /* All this work is done within continue_cpu_idle_loop  */
   72.88 +	printf ("idle%dB\n", cpu);
   72.89 +	asm volatile ("mov ar.k2=r0");
   72.90  	do_softirq();
   72.91 +	printf ("idle%dC\n", cpu);
   72.92  
   72.93  	/*
   72.94  	 * Declares CPU setup done to the boot processor.
   72.95  	 * Therefore memory barrier to ensure state is visible.
   72.96  	 */
   72.97  	smp_mb();
   72.98 +#endif
   72.99  #if 0
  72.100  //do we have to ensure the idle task has a shared page so that, for example,
  72.101  //region registers can be loaded from it.  Apparently not...
  72.102 @@ -204,6 +202,15 @@ void arch_do_createdomain(struct vcpu *v
  72.103     		while (1);
  72.104  	}
  72.105  	memset(d->shared_info, 0, PAGE_SIZE);
  72.106 +	if (v == d->vcpu[0])
  72.107 +	    memset(&d->shared_info->evtchn_mask[0], 0xff,
  72.108 +		sizeof(d->shared_info->evtchn_mask));
  72.109 +#if 0
  72.110 +	d->vcpu[0].arch.privregs = 
  72.111 +			alloc_xenheap_pages(get_order(sizeof(mapped_regs_t)));
  72.112 +	printf("arch_vcpu_info=%p\n", d->vcpu[0].arch.privregs);
  72.113 +	memset(d->vcpu.arch.privregs, 0, PAGE_SIZE);
  72.114 +#endif
  72.115  	v->vcpu_info = &(d->shared_info->vcpu_data[0]);
  72.116  
  72.117  	d->max_pages = (128UL*1024*1024)/PAGE_SIZE; // 128MB default // FIXME
  72.118 @@ -233,17 +240,21 @@ void arch_do_createdomain(struct vcpu *v
  72.119  	v->arch.breakimm = d->arch.breakimm;
  72.120  
  72.121  	d->arch.sys_pgnr = 0;
  72.122 -	d->arch.mm = xmalloc(struct mm_struct);
  72.123 -	if (unlikely(!d->arch.mm)) {
  72.124 -		printk("Can't allocate mm_struct for domain %d\n",d->domain_id);
  72.125 -		return -ENOMEM;
  72.126 -	}
  72.127 -	memset(d->arch.mm, 0, sizeof(*d->arch.mm));
  72.128 -	d->arch.mm->pgd = pgd_alloc(d->arch.mm);
  72.129 -	if (unlikely(!d->arch.mm->pgd)) {
  72.130 -		printk("Can't allocate pgd for domain %d\n",d->domain_id);
  72.131 -		return -ENOMEM;
  72.132 -	}
  72.133 +	if (d->domain_id != IDLE_DOMAIN_ID) {
  72.134 +		d->arch.mm = xmalloc(struct mm_struct);
  72.135 +		if (unlikely(!d->arch.mm)) {
  72.136 +			printk("Can't allocate mm_struct for domain %d\n",d->domain_id);
  72.137 +			return -ENOMEM;
  72.138 +		}
  72.139 +		memset(d->arch.mm, 0, sizeof(*d->arch.mm));
  72.140 +		d->arch.mm->pgd = pgd_alloc(d->arch.mm);
  72.141 +		if (unlikely(!d->arch.mm->pgd)) {
  72.142 +			printk("Can't allocate pgd for domain %d\n",d->domain_id);
  72.143 +			return -ENOMEM;
  72.144 +		}
  72.145 +	} else
  72.146 + 		d->arch.mm = NULL;
  72.147 + 	printf ("arch_do_create_domain: domain=%p\n", d);
  72.148  }
  72.149  
  72.150  void arch_getdomaininfo_ctxt(struct vcpu *v, struct vcpu_guest_context *c)
  72.151 @@ -268,6 +279,14 @@ int arch_set_info_guest(struct vcpu *v, 
  72.152  	if ( test_bit(_VCPUF_initialised, &v->vcpu_flags) )
  72.153              return 0;
  72.154  
  72.155 +	/* Sync d/i cache conservatively */
  72.156 +	if (!running_on_sim) {
  72.157 +	    ret = ia64_pal_cache_flush(4, 0, &progress, NULL);
  72.158 +	    if (ret != PAL_STATUS_SUCCESS)
  72.159 +	        panic("PAL CACHE FLUSH failed for domain.\n");
  72.160 +	    printk("Sync i/d cache for dom0 image SUCC\n");
  72.161 +	}
  72.162 +
  72.163  	if (c->flags & VGCF_VMX_GUEST) {
  72.164  	    if (!vmx_enabled) {
  72.165  		printk("No VMX hardware feature for vmx domain.\n");
  72.166 @@ -527,7 +546,8 @@ tryagain:
  72.167  				if (pte_present(*pte)) {
  72.168  //printk("lookup_domain_page: found mapping for %lx, pte=%lx\n",mpaddr,pte_val(*pte));
  72.169  					return *(unsigned long *)pte;
  72.170 -				}
  72.171 +				} else if (VMX_DOMAIN(d->vcpu[0]))
  72.172 +					return GPFN_INV_MASK;
  72.173  			}
  72.174  		}
  72.175  	}
  72.176 @@ -779,7 +799,6 @@ void physdev_init_dom0(struct domain *d)
  72.177  	set_bit(_DOMF_physdev_access, &d->domain_flags);
  72.178  }
  72.179  
  72.180 -extern unsigned long running_on_sim;
  72.181  unsigned int vmx_dom0 = 0;
  72.182  int construct_dom0(struct domain *d, 
  72.183  	               unsigned long image_start, unsigned long image_len, 
  72.184 @@ -930,6 +949,7 @@ int construct_dom0(struct domain *d,
  72.185  	si = (start_info_t *)alloc_xenheap_page();
  72.186  	memset(si, 0, PAGE_SIZE);
  72.187  	d->shared_info->arch.start_info_pfn = __pa(si) >> PAGE_SHIFT;
  72.188 +	sprintf(si->magic, "Xen-%i.%i", XEN_VERSION, XEN_SUBVERSION);
  72.189  
  72.190  #if 0
  72.191  	si->nr_pages     = d->tot_pages;
    73.1 --- a/xen/arch/ia64/xen/hyperprivop.S	Sun Oct 30 13:52:38 2005 +0100
    73.2 +++ b/xen/arch/ia64/xen/hyperprivop.S	Sun Oct 30 14:00:35 2005 +0100
    73.3 @@ -14,6 +14,10 @@
    73.4  #include <asm/system.h>
    73.5  #include <public/arch-ia64.h>
    73.6  
    73.7 +#define	_PAGE_PPN_MASK	0x0003fffffffff000 //asm/pgtable.h doesn't do assembly
    73.8 +#define PAGE_PHYS	0x0010000000000761 //__pgprot(__DIRTY_BITS|_PAGE_PL_2|_PAGE_AR_RWX)
    73.9 +#define _PAGE_PL_2	(2<<7)
   73.10 +
   73.11  #if 1	 // change to 0 to turn off all fast paths
   73.12  #define FAST_HYPERPRIVOPS
   73.13  #define FAST_HYPERPRIVOP_CNT
   73.14 @@ -24,6 +28,7 @@
   73.15  #define FAST_RFI
   73.16  #define FAST_SSM_I
   73.17  #define FAST_PTC_GA
   73.18 +#undef FAST_ITC	// working but default off for now
   73.19  #undef RFI_TO_INTERRUPT // not working yet
   73.20  #endif
   73.21  
   73.22 @@ -802,8 +807,11 @@ just_do_rfi:
   73.23  	// OK, now all set to go except for switch to virtual bank1
   73.24  	mov r22=1;; st4 [r20]=r22;
   73.25  	mov r30=r2; mov r29=r3;;
   73.26 +    adds r16=XSI_B1NATS_OFS-XSI_PSR_IC_OFS,r18
   73.27  	adds r2=XSI_BANK1_OFS-XSI_PSR_IC_OFS,r18;
   73.28  	adds r3=(XSI_BANK1_OFS+8)-XSI_PSR_IC_OFS,r18;;
   73.29 +    ld8 r16=[r16];;
   73.30 +    mov ar.unat=r16;;
   73.31  	bsw.1;;
   73.32  	// FIXME?: ar.unat is not really handled correctly,
   73.33  	// but may not matter if the OS is NaT-clean
   73.34 @@ -1663,10 +1671,159 @@ 2:
   73.35  	;;
   73.36  END(hyper_ptc_ga)
   73.37  
   73.38 +//  Registers at entry
   73.39 +//	r17 = break immediate (XEN_HYPER_ITC_D or I)
   73.40 +//	r18 == XSI_PSR_IC_OFS
   73.41 +//	r31 == pr
   73.42 +GLOBAL_ENTRY(hyper_itc)
   73.43 +ENTRY(hyper_itc_i)
   73.44 +	// fall through, hyper_itc_d handles both i and d
   73.45  ENTRY(hyper_itc_d)
   73.46 +#ifndef FAST_ITC
   73.47  	br.spnt.many dispatch_break_fault ;;
   73.48 +#endif
   73.49 +	adds r23=XSI_ITIR_OFS-XSI_PSR_IC_OFS,r18 ;;
   73.50 +	ld8 r23=[r23];;
   73.51 +	extr.u r24=r23,2,6;;		// r24==logps
   73.52 +	cmp.gt p7,p0=PAGE_SHIFT,r24
   73.53 +(p7)	br.spnt.many dispatch_break_fault ;;
   73.54 +	// translate_domain_pte(r8=pteval,PSCB(ifa)=address,r24=itir)
   73.55 +	mov r19=1;;
   73.56 +	shl r20=r19,r24;;
   73.57 +	adds r20=-1,r20;;	// r20 == mask
   73.58 +	movl r19=_PAGE_PPN_MASK;;
   73.59 +	and r22=r8,r19;;	// r22 == pteval & _PAGE_PPN_MASK
   73.60 +	andcm r19=r22,r20;;
   73.61 +	adds r21=XSI_IFA_OFS-XSI_PSR_IC_OFS,r18 ;;
   73.62 +	ld8 r21=[r21];;
   73.63 +	and r20=r21,r20;;
   73.64 +	or r19=r19,r20;;	// r19 == mpaddr
   73.65 +	movl r27=THIS_CPU(cpu_kr)+IA64_KR_CURRENT_OFFSET;;
   73.66 +	ld8 r27=[r27];;
   73.67 +	adds r27=IA64_VCPU_DOMAIN_OFFSET,r27;;
   73.68 +	ld8 r27=[r27];;
   73.69 +// FIXME: is the global var dom0 always pinned? assume so for now
   73.70 +	movl r28=dom0;;
   73.71 +	ld8 r28=[r28];;
   73.72 +// FIXME: for now, only handle dom0 (see lookup_domain_mpa below)
   73.73 +	cmp.ne p7,p0=r27,r28
   73.74 +(p7)	br.spnt.many dispatch_break_fault ;;
   73.75 +	// if region 6, go slow way
   73.76 +#ifdef FAST_HYPERPRIVOP_CNT
   73.77 +	cmp.eq p6,p7=XEN_HYPER_ITC_D,r17;;
   73.78 +(p6)	movl r20=fast_hyperpriv_cnt+(8*XEN_HYPER_ITC_D);;
   73.79 +(p7)	movl r20=fast_hyperpriv_cnt+(8*XEN_HYPER_ITC_I);;
   73.80 +	ld8 r21=[r20];;
   73.81 +	adds r21=1,r21;;
   73.82 +	st8 [r20]=r21;;
   73.83 +#endif
   73.84 +// FIXME: for now, just do domain0 and skip mpaddr range checks
   73.85 +	dep r20=r0,r19,0,PAGE_SHIFT
   73.86 +	movl r21=PAGE_PHYS ;;
   73.87 +	or r20=r20,r21 ;;	// r20==return value from lookup_domain_mpa
   73.88 +	// r8=pteval,r20=pteval2
   73.89 +	movl r19=_PAGE_PPN_MASK
   73.90 +	movl r21=_PAGE_PL_2;;
   73.91 +	andcm r25=r8,r19;;	// r25==pteval & ~_PAGE_PPN_MASK
   73.92 +	and r22=r20,r19;;
   73.93 +	or r22=r22,r21;;
   73.94 +	or r22=r22,r25;;	// r22==return value from translate_domain_pte
   73.95 +	// done with translate_domain_pte
   73.96 +	// now do vcpu_itc_no_srlz(vcpu,IorD,ifa,r22=pte,r8=mppte,r24=logps)
   73.97 +// FIXME: for now, just domain0 and skip range check
   73.98 +	// psr.ic already cleared
   73.99 +	// NOTE: r24 still contains ps (from above)
  73.100 +	shladd r24=r24,2,r0;;
  73.101 +	mov cr.itir=r24;;
  73.102 +	adds r23=XSI_IFA_OFS-XSI_PSR_IC_OFS,r18 ;;
  73.103 +	ld8 r23=[r23];;
  73.104 +	mov cr.ifa=r23;;
  73.105 +	cmp.eq p6,p7=XEN_HYPER_ITC_D,r17;;
  73.106 +(p6)	itc.d r22;;
  73.107 +(p7)	itc.i r22;;
  73.108 +	dv_serialize_data
  73.109 +	// FIXME: how do I make assembler warnings go away here?
  73.110 +	// vhpt_insert(r23=vaddr,r22=pte,r24=logps<<2)
  73.111 +	thash r28=r23
  73.112 +	or r26=1,r22;;
  73.113 +	ttag r21=r23
  73.114 +	adds r25=8,r28
  73.115 +	mov r19=r28;;
  73.116 +	st8 [r25]=r24
  73.117 +	adds r20=16,r28;;
  73.118 +	st8 [r19]=r26
  73.119 +	st8 [r20]=r21;;
  73.120 +	// vcpu_set_tr_entry(trp,r22=pte|1,r24=itir,r23=ifa)
  73.121 +	// TR_ENTRY = {page_flags,itir,addr,rid}
  73.122 +	cmp.eq p6,p7=XEN_HYPER_ITC_D,r17
  73.123 +	movl r27=THIS_CPU(cpu_kr)+IA64_KR_CURRENT_OFFSET;;
  73.124 +	ld8 r27=[r27];;
  73.125 +	adds r28=IA64_VCPU_STARTING_RID_OFFSET,r27
  73.126 +(p6)	adds r27=IA64_VCPU_DTLB_OFFSET,r27
  73.127 +(p7)	adds r27=IA64_VCPU_ITLB_OFFSET,r27;;
  73.128 +	st8 [r27]=r22,8;;	// page_flags: already has pl >= 2 and p==1
  73.129 +	st8 [r27]=r24,8;;	// itir
  73.130 +	mov r19=-4096;;
  73.131 +	and r23=r23,r19;;
  73.132 +	st8 [r27]=r23,8;;	// ifa & ~0xfff
  73.133 +// ?? is virtualize_rid(v,get_rr(ifa))==vcpu_get_rr(ifa)?? YES!!
  73.134 +	adds r29 = XSI_RR0_OFS-XSI_PSR_IC_OFS,r18
  73.135 +	extr.u r25=r23,61,3;;
  73.136 +	shladd r29=r25,3,r29;;
  73.137 +	ld8 r29=[r29];;
  73.138 +	movl r20=0xffffff00;;
  73.139 +	and r29=r29,r20;;
  73.140 +	st8 [r27]=r29,-8;;		// rid
  73.141 +	//if ps > 12
  73.142 +	cmp.eq p7,p0=12<<2,r24
  73.143 +(p7)	br.cond.sptk.many 1f;;
  73.144 +	// if (ps > 12) {
  73.145 +	// trp->ppn &= ~((1UL<<(ps-12))-1); trp->vadr &= ~((1UL<<ps)-1); }
  73.146 +	extr.u r29=r24,2,6
  73.147 +	mov r28=1;;
  73.148 +	shl r26=r28,r29;;
  73.149 +	adds r29=-12,r29;;
  73.150 +	shl r25=r28,r29;;
  73.151 +	mov r29=-1
  73.152 +	adds r26=-1,r26
  73.153 +	adds r25=-1,r25;;
  73.154 +	andcm r26=r29,r26	// ~((1UL<<ps)-1)
  73.155 +	andcm r25=r29,r25;;	// ~((1UL<<(ps-12))-1)
  73.156 +	ld8 r29=[r27];;
  73.157 +	and r29=r29,r26;;
  73.158 +	st8 [r27]=r29,-16;;
  73.159 +	ld8 r29=[r27];;
  73.160 +	extr.u r28=r29,12,38;;
  73.161 +	movl r26=0xfffc000000000fff;;
  73.162 +	and r29=r29,r26
  73.163 +	and r28=r28,r25;;
  73.164 +	shl r28=r28,12;;
  73.165 +	or r29=r29,r28;;
  73.166 +	st8 [r27]=r29;;
  73.167 +1:	// done with vcpu_set_tr_entry
  73.168 +	//PSCBX(vcpu,i/dtlb_pte) = mp_pte
  73.169 +	movl r27=THIS_CPU(cpu_kr)+IA64_KR_CURRENT_OFFSET;;
  73.170 +	ld8 r27=[r27];;
  73.171 +	cmp.eq p6,p7=XEN_HYPER_ITC_D,r17;;
  73.172 +(p6)	adds r27=IA64_VCPU_DTLB_PTE_OFFSET,r27
  73.173 +(p7)	adds r27=IA64_VCPU_ITLB_PTE_OFFSET,r27;;
  73.174 +	st8 [r27]=r8;;
  73.175 +	// done with vcpu_itc_no_srlz
  73.176 +
  73.177 +	// done, increment to point to next instruction
  73.178 +	mov r29=cr.ipsr
  73.179 +	mov r30=cr.iip;;
  73.180 +	extr.u r26=r29,41,2 ;;
  73.181 +	cmp.eq p6,p7=2,r26 ;;
  73.182 +(p6)	mov r26=0
  73.183 +(p6)	adds r30=16,r30
  73.184 +(p7)	adds r26=1,r26
  73.185 +	;;
  73.186 +	dep r29=r26,r29,41,2
  73.187 +	;;
  73.188 +	mov cr.ipsr=r29
  73.189 +	mov cr.iip=r30
  73.190 +	mov pr=r31,-1 ;;
  73.191 +	rfi
  73.192 +	;;
  73.193  END(hyper_itc_d)
  73.194 -
  73.195 -ENTRY(hyper_itc_i)
  73.196 -	br.spnt.many dispatch_break_fault ;;
  73.197 -END(hyper_itc_i)
    74.1 --- a/xen/arch/ia64/xen/ivt.S	Sun Oct 30 13:52:38 2005 +0100
    74.2 +++ b/xen/arch/ia64/xen/ivt.S	Sun Oct 30 14:00:35 2005 +0100
    74.3 @@ -484,6 +484,7 @@ END(alt_dtlb_miss)
    74.4  /////////////////////////////////////////////////////////////////////////////////////////
    74.5  // 0x1400 Entry 5 (size 64 bundles) Data nested TLB (6,45)
    74.6  ENTRY(nested_dtlb_miss)
    74.7 +	DBG_FAULT(5)
    74.8  	/*
    74.9  	 * In the absence of kernel bugs, we get here when the virtually mapped linear
   74.10  	 * page table is accessed non-speculatively (e.g., in the Dirty-bit, Instruction
   74.11 @@ -552,10 +553,10 @@ END(nested_dtlb_miss)
   74.12  /////////////////////////////////////////////////////////////////////////////////////////
   74.13  // 0x1800 Entry 6 (size 64 bundles) Instruction Key Miss (24)
   74.14  ENTRY(ikey_miss)
   74.15 +	DBG_FAULT(6)
   74.16  #ifdef XEN
   74.17  	REFLECT(6)
   74.18  #endif
   74.19 -	DBG_FAULT(6)
   74.20  	FAULT(6)
   74.21  END(ikey_miss)
   74.22  
   74.23 @@ -597,10 +598,10 @@ END(page_fault)
   74.24  /////////////////////////////////////////////////////////////////////////////////////////
   74.25  // 0x1c00 Entry 7 (size 64 bundles) Data Key Miss (12,51)
   74.26  ENTRY(dkey_miss)
   74.27 +	DBG_FAULT(7)
   74.28  #ifdef XEN
   74.29  	REFLECT(7)
   74.30  #endif
   74.31 -	DBG_FAULT(7)
   74.32  	FAULT(7)
   74.33  END(dkey_miss)
   74.34  
   74.35 @@ -608,10 +609,10 @@ END(dkey_miss)
   74.36  /////////////////////////////////////////////////////////////////////////////////////////
   74.37  // 0x2000 Entry 8 (size 64 bundles) Dirty-bit (54)
   74.38  ENTRY(dirty_bit)
   74.39 +	DBG_FAULT(8)
   74.40  #ifdef XEN
   74.41  	REFLECT(8)
   74.42  #endif
   74.43 -	DBG_FAULT(8)
   74.44  	/*
   74.45  	 * What we do here is to simply turn on the dirty bit in the PTE.  We need to
   74.46  	 * update both the page-table and the TLB entry.  To efficiently access the PTE,
   74.47 @@ -673,6 +674,7 @@ END(dirty_bit)
   74.48  /////////////////////////////////////////////////////////////////////////////////////////
   74.49  // 0x2400 Entry 9 (size 64 bundles) Instruction Access-bit (27)
   74.50  ENTRY(iaccess_bit)
   74.51 +	DBG_FAULT(9)
   74.52  #ifdef XEN
   74.53  	mov r31=pr;
   74.54  	mov r16=cr.isr
   74.55 @@ -681,7 +683,6 @@ ENTRY(iaccess_bit)
   74.56  	movl r20=0x2400
   74.57  	br.sptk.many fast_access_reflect;;
   74.58  #endif
   74.59 -	DBG_FAULT(9)
   74.60  	// Like Entry 8, except for instruction access
   74.61  	mov r16=cr.ifa				// get the address that caused the fault
   74.62  	movl r30=1f				// load continuation point in case of nested fault
   74.63 @@ -746,6 +747,7 @@ END(iaccess_bit)
   74.64  /////////////////////////////////////////////////////////////////////////////////////////
   74.65  // 0x2800 Entry 10 (size 64 bundles) Data Access-bit (15,55)
   74.66  ENTRY(daccess_bit)
   74.67 +	DBG_FAULT(10)
   74.68  #ifdef XEN
   74.69  	mov r31=pr;
   74.70  	mov r16=cr.isr
   74.71 @@ -754,7 +756,6 @@ ENTRY(daccess_bit)
   74.72  	movl r20=0x2800
   74.73  	br.sptk.many fast_access_reflect;;
   74.74  #endif
   74.75 -	DBG_FAULT(10)
   74.76  	// Like Entry 8, except for data access
   74.77  	mov r16=cr.ifa				// get the address that caused the fault
   74.78  	movl r30=1f				// load continuation point in case of nested fault
   74.79 @@ -971,8 +972,10 @@ slow_interrupt:
   74.80  	mov out0=cr.ivr		// pass cr.ivr as first arg
   74.81  #endif
   74.82  	add out1=16,sp		// pass pointer to pt_regs as second arg
   74.83 +#ifndef XEN
   74.84  	;;
   74.85  	srlz.d			// make sure we see the effect of cr.ivr
   74.86 +#endif
   74.87  	movl r14=ia64_leave_kernel
   74.88  	;;
   74.89  	mov rp=r14
   74.90 @@ -1363,10 +1366,10 @@ END(dispatch_to_fault_handler)
   74.91  /////////////////////////////////////////////////////////////////////////////////////////
   74.92  // 0x5000 Entry 20 (size 16 bundles) Page Not Present (10,22,49)
   74.93  ENTRY(page_not_present)
   74.94 +	DBG_FAULT(20)
   74.95  #ifdef XEN
   74.96  	REFLECT(20)
   74.97  #endif
   74.98 -	DBG_FAULT(20)
   74.99  	mov r16=cr.ifa
  74.100  	rsm psr.dt
  74.101  	/*
  74.102 @@ -1386,10 +1389,10 @@ END(page_not_present)
  74.103  /////////////////////////////////////////////////////////////////////////////////////////
  74.104  // 0x5100 Entry 21 (size 16 bundles) Key Permission (13,25,52)
  74.105  ENTRY(key_permission)
  74.106 +	DBG_FAULT(21)
  74.107  #ifdef XEN
  74.108  	REFLECT(21)
  74.109  #endif
  74.110 -	DBG_FAULT(21)
  74.111  	mov r16=cr.ifa
  74.112  	rsm psr.dt
  74.113  	mov r31=pr
  74.114 @@ -1402,10 +1405,10 @@ END(key_permission)
  74.115  /////////////////////////////////////////////////////////////////////////////////////////
  74.116  // 0x5200 Entry 22 (size 16 bundles) Instruction Access Rights (26)
  74.117  ENTRY(iaccess_rights)
  74.118 +	DBG_FAULT(22)
  74.119  #ifdef XEN
  74.120  	REFLECT(22)
  74.121  #endif
  74.122 -	DBG_FAULT(22)
  74.123  	mov r16=cr.ifa
  74.124  	rsm psr.dt
  74.125  	mov r31=pr
  74.126 @@ -1418,6 +1421,7 @@ END(iaccess_rights)
  74.127  /////////////////////////////////////////////////////////////////////////////////////////
  74.128  // 0x5300 Entry 23 (size 16 bundles) Data Access Rights (14,53)
  74.129  ENTRY(daccess_rights)
  74.130 +	DBG_FAULT(23)
  74.131  #ifdef XEN
  74.132  	mov r31=pr;
  74.133  	mov r16=cr.isr
  74.134 @@ -1426,7 +1430,6 @@ ENTRY(daccess_rights)
  74.135  	movl r20=0x5300
  74.136  	br.sptk.many fast_access_reflect;;
  74.137  #endif
  74.138 -	DBG_FAULT(23)
  74.139  	mov r16=cr.ifa
  74.140  	rsm psr.dt
  74.141  	mov r31=pr
  74.142 @@ -1459,10 +1462,31 @@ END(general_exception)
  74.143  /////////////////////////////////////////////////////////////////////////////////////////
  74.144  // 0x5500 Entry 25 (size 16 bundles) Disabled FP-Register (35)
  74.145  ENTRY(disabled_fp_reg)
  74.146 +	DBG_FAULT(25)
  74.147  #ifdef XEN
  74.148 +#if 0
  74.149 +	mov r20=pr
  74.150 +	movl r16=0x2000000000000000
  74.151 +	movl r17=0x2000000000176b60
  74.152 +	mov r18=cr.iip
  74.153 +	mov r19=rr[r16]
  74.154 +	movl r22=0xe95d0439
  74.155 +	;;
  74.156 +	mov pr=r0,-1
  74.157 +	;;
  74.158 +	cmp.eq p6,p7=r22,r19
  74.159 +	;;
  74.160 +	(p6) cmp.eq p8,p9=r17,r18
  74.161 +	(p8) br.sptk.few floating_panic
  74.162 +	;;
  74.163 +	mov pr=r20,-1
  74.164 +	;;
  74.165 +#endif
  74.166  	REFLECT(25)
  74.167 +//floating_panic:
  74.168 +//	br.sptk.many floating_panic
  74.169 +	;;
  74.170  #endif
  74.171 -	DBG_FAULT(25)
  74.172  	rsm psr.dfh		// ensure we can access fph
  74.173  	;;
  74.174  	srlz.d
  74.175 @@ -1475,10 +1499,10 @@ END(disabled_fp_reg)
  74.176  /////////////////////////////////////////////////////////////////////////////////////////
  74.177  // 0x5600 Entry 26 (size 16 bundles) Nat Consumption (11,23,37,50)
  74.178  ENTRY(nat_consumption)
  74.179 +	DBG_FAULT(26)
  74.180  #ifdef XEN
  74.181  	REFLECT(26)
  74.182  #endif
  74.183 -	DBG_FAULT(26)
  74.184  	FAULT(26)
  74.185  END(nat_consumption)
  74.186  
  74.187 @@ -1486,11 +1510,11 @@ END(nat_consumption)
  74.188  /////////////////////////////////////////////////////////////////////////////////////////
  74.189  // 0x5700 Entry 27 (size 16 bundles) Speculation (40)
  74.190  ENTRY(speculation_vector)
  74.191 +	DBG_FAULT(27)
  74.192  #ifdef XEN
  74.193  	// this probably need not reflect...
  74.194  	REFLECT(27)
  74.195  #endif
  74.196 -	DBG_FAULT(27)
  74.197  	/*
  74.198  	 * A [f]chk.[as] instruction needs to take the branch to the recovery code but
  74.199  	 * this part of the architecture is not implemented in hardware on some CPUs, such
  74.200 @@ -1533,10 +1557,10 @@ END(speculation_vector)
  74.201  /////////////////////////////////////////////////////////////////////////////////////////
  74.202  // 0x5900 Entry 29 (size 16 bundles) Debug (16,28,56)
  74.203  ENTRY(debug_vector)
  74.204 +	DBG_FAULT(29)
  74.205  #ifdef XEN
  74.206  	REFLECT(29)
  74.207  #endif
  74.208 -	DBG_FAULT(29)
  74.209  	FAULT(29)
  74.210  END(debug_vector)
  74.211  
  74.212 @@ -1544,10 +1568,10 @@ END(debug_vector)
  74.213  /////////////////////////////////////////////////////////////////////////////////////////
  74.214  // 0x5a00 Entry 30 (size 16 bundles) Unaligned Reference (57)
  74.215  ENTRY(unaligned_access)
  74.216 +	DBG_FAULT(30)
  74.217  #ifdef XEN
  74.218  	REFLECT(30)
  74.219  #endif
  74.220 -	DBG_FAULT(30)
  74.221  	mov r16=cr.ipsr
  74.222  	mov r31=pr		// prepare to save predicates
  74.223  	;;
  74.224 @@ -1558,10 +1582,10 @@ END(unaligned_access)
  74.225  /////////////////////////////////////////////////////////////////////////////////////////
  74.226  // 0x5b00 Entry 31 (size 16 bundles) Unsupported Data Reference (57)
  74.227  ENTRY(unsupported_data_reference)
  74.228 +	DBG_FAULT(31)
  74.229  #ifdef XEN
  74.230  	REFLECT(31)
  74.231  #endif
  74.232 -	DBG_FAULT(31)
  74.233  	FAULT(31)
  74.234  END(unsupported_data_reference)
  74.235  
  74.236 @@ -1569,10 +1593,10 @@ END(unsupported_data_reference)
  74.237  /////////////////////////////////////////////////////////////////////////////////////////
  74.238  // 0x5c00 Entry 32 (size 16 bundles) Floating-Point Fault (64)
  74.239  ENTRY(floating_point_fault)
  74.240 +	DBG_FAULT(32)
  74.241  #ifdef XEN
  74.242  	REFLECT(32)
  74.243  #endif
  74.244 -	DBG_FAULT(32)
  74.245  	FAULT(32)
  74.246  END(floating_point_fault)
  74.247  
  74.248 @@ -1580,10 +1604,10 @@ END(floating_point_fault)
  74.249  /////////////////////////////////////////////////////////////////////////////////////////
  74.250  // 0x5d00 Entry 33 (size 16 bundles) Floating Point Trap (66)
  74.251  ENTRY(floating_point_trap)
  74.252 +	DBG_FAULT(33)
  74.253  #ifdef XEN
  74.254  	REFLECT(33)
  74.255  #endif
  74.256 -	DBG_FAULT(33)
  74.257  	FAULT(33)
  74.258  END(floating_point_trap)
  74.259  
  74.260 @@ -1591,10 +1615,10 @@ END(floating_point_trap)
  74.261  /////////////////////////////////////////////////////////////////////////////////////////
  74.262  // 0x5e00 Entry 34 (size 16 bundles) Lower Privilege Transfer Trap (66)
  74.263  ENTRY(lower_privilege_trap)
  74.264 +	DBG_FAULT(34)
  74.265  #ifdef XEN
  74.266  	REFLECT(34)
  74.267  #endif
  74.268 -	DBG_FAULT(34)
  74.269  	FAULT(34)
  74.270  END(lower_privilege_trap)
  74.271  
  74.272 @@ -1602,10 +1626,10 @@ END(lower_privilege_trap)
  74.273  /////////////////////////////////////////////////////////////////////////////////////////
  74.274  // 0x5f00 Entry 35 (size 16 bundles) Taken Branch Trap (68)
  74.275  ENTRY(taken_branch_trap)
  74.276 +	DBG_FAULT(35)
  74.277  #ifdef XEN
  74.278  	REFLECT(35)
  74.279  #endif
  74.280 -	DBG_FAULT(35)
  74.281  	FAULT(35)
  74.282  END(taken_branch_trap)
  74.283  
  74.284 @@ -1613,10 +1637,10 @@ END(taken_branch_trap)
  74.285  /////////////////////////////////////////////////////////////////////////////////////////
  74.286  // 0x6000 Entry 36 (size 16 bundles) Single Step Trap (69)
  74.287  ENTRY(single_step_trap)
  74.288 +	DBG_FAULT(36)
  74.289  #ifdef XEN
  74.290  	REFLECT(36)
  74.291  #endif
  74.292 -	DBG_FAULT(36)
  74.293  	FAULT(36)
  74.294  END(single_step_trap)
  74.295  
  74.296 @@ -1672,10 +1696,10 @@ END(single_step_trap)
  74.297  /////////////////////////////////////////////////////////////////////////////////////////
  74.298  // 0x6900 Entry 45 (size 16 bundles) IA-32 Exeception (17,18,29,41,42,43,44,58,60,61,62,72,73,75,76,77)
  74.299  ENTRY(ia32_exception)
  74.300 +	DBG_FAULT(45)
  74.301  #ifdef XEN
  74.302  	REFLECT(45)
  74.303  #endif
  74.304 -	DBG_FAULT(45)
  74.305  	FAULT(45)
  74.306  END(ia32_exception)
  74.307  
  74.308 @@ -1683,10 +1707,10 @@ END(ia32_exception)
  74.309  /////////////////////////////////////////////////////////////////////////////////////////
  74.310  // 0x6a00 Entry 46 (size 16 bundles) IA-32 Intercept  (30,31,59,70,71)
  74.311  ENTRY(ia32_intercept)
  74.312 +	DBG_FAULT(46)
  74.313  #ifdef XEN
  74.314  	REFLECT(46)
  74.315  #endif
  74.316 -	DBG_FAULT(46)
  74.317  #ifdef	CONFIG_IA32_SUPPORT
  74.318  	mov r31=pr
  74.319  	mov r16=cr.isr
  74.320 @@ -1716,10 +1740,10 @@ END(ia32_intercept)
  74.321  /////////////////////////////////////////////////////////////////////////////////////////
  74.322  // 0x6b00 Entry 47 (size 16 bundles) IA-32 Interrupt  (74)
  74.323  ENTRY(ia32_interrupt)
  74.324 +	DBG_FAULT(47)
  74.325  #ifdef XEN
  74.326  	REFLECT(47)
  74.327  #endif
  74.328 -	DBG_FAULT(47)
  74.329  #ifdef CONFIG_IA32_SUPPORT
  74.330  	mov r31=pr
  74.331  	br.sptk.many dispatch_to_ia32_handler
    75.1 --- a/xen/arch/ia64/xen/process.c	Sun Oct 30 13:52:38 2005 +0100
    75.2 +++ b/xen/arch/ia64/xen/process.c	Sun Oct 30 14:00:35 2005 +0100
    75.3 @@ -62,11 +62,23 @@ long do_iopl(domid_t domain, unsigned in
    75.4  	return 0;
    75.5  }
    75.6  
    75.7 +#include <xen/sched-if.h>
    75.8 +
    75.9 +extern struct schedule_data schedule_data[NR_CPUS];
   75.10 +
   75.11  void schedule_tail(struct vcpu *next)
   75.12  {
   75.13  	unsigned long rr7;
   75.14  	//printk("current=%lx,shared_info=%lx\n",current,current->vcpu_info);
   75.15  	//printk("next=%lx,shared_info=%lx\n",next,next->vcpu_info);
   75.16 +
   75.17 +    // TG: Real HACK FIXME.
   75.18 +    // This is currently necessary because when a new domain is started, 
   75.19 +    // the context_switch function of xen/common/schedule.c(__enter_scheduler)
   75.20 +    // never returns.  Therefore, the lock must be released.
   75.21 +    // schedule_tail is only called when a domain is started.
   75.22 +    spin_unlock_irq(&schedule_data[current->processor].schedule_lock);
   75.23 +
   75.24  	/* rr7 will be postponed to last point when resuming back to guest */
   75.25      if(VMX_DOMAIN(current)){
   75.26      	vmx_load_all_rr(current);
   75.27 @@ -733,6 +745,8 @@ ia64_handle_reflection (unsigned long if
   75.28  	    case 26:
   75.29  printf("*** NaT fault... attempting to handle as privop\n");
   75.30  printf("isr=%p, ifa=%p,iip=%p,ipsr=%p\n",isr,ifa,regs->cr_iip,psr);
   75.31 +		regs->eml_unat = 0;
   75.32 +		return;
   75.33  		vector = priv_emulate(v,regs,isr);
   75.34  		if (vector == IA64_NO_FAULT) {
   75.35  printf("*** Handled privop masquerading as NaT fault\n");
    76.1 --- a/xen/arch/ia64/xen/regionreg.c	Sun Oct 30 13:52:38 2005 +0100
    76.2 +++ b/xen/arch/ia64/xen/regionreg.c	Sun Oct 30 14:00:35 2005 +0100
    76.3 @@ -15,7 +15,8 @@
    76.4  #include <asm/regionreg.h>
    76.5  #include <asm/vhpt.h>
    76.6  #include <asm/vcpu.h>
    76.7 -extern void ia64_new_rr7(unsigned long rid,void *shared_info, void *shared_arch_info);
    76.8 +extern void ia64_new_rr7(unsigned long rid,void *shared_info, void *shared_arch_info, unsigned long p_vhpt, unsigned long v_pal);
    76.9 +extern void *pal_vaddr;
   76.10  
   76.11  
   76.12  #define	IA64_MIN_IMPL_RID_BITS	(IA64_MIN_IMPL_RID_MSB+1)
   76.13 @@ -66,9 +67,12 @@ unsigned long allocate_metaphysical_rr(v
   76.14  {
   76.15  	ia64_rr rrv;
   76.16  
   76.17 +	rrv.rrval = 0;	// Or else may see reserved bit fault
   76.18  	rrv.rid = allocate_reserved_rid();
   76.19  	rrv.ps = PAGE_SHIFT;
   76.20  	rrv.ve = 0;
   76.21 +	/* Mangle metaphysical rid */
   76.22 +	rrv.rrval = vmMangleRID(rrv.rrval);
   76.23  	return rrv.rrval;
   76.24  }
   76.25  
   76.26 @@ -213,6 +217,7 @@ int set_one_rr(unsigned long rr, unsigne
   76.27  	unsigned long rreg = REGION_NUMBER(rr);
   76.28  	ia64_rr rrv, newrrv, memrrv;
   76.29  	unsigned long newrid;
   76.30 +	extern unsigned long vhpt_paddr;
   76.31  
   76.32  	if (val == -1) return 1;
   76.33  
   76.34 @@ -250,9 +255,10 @@ int set_one_rr(unsigned long rr, unsigne
   76.35  	newrrv.rid = newrid;
   76.36  	newrrv.ve = 1;  // VHPT now enabled for region 7!!
   76.37  	newrrv.ps = PAGE_SHIFT;
   76.38 -	if (rreg == 0) v->arch.metaphysical_saved_rr0 = newrrv.rrval;
   76.39 +	if (rreg == 0) v->arch.metaphysical_saved_rr0 =
   76.40 +		vmMangleRID(newrrv.rrval);
   76.41  	if (rreg == 7) ia64_new_rr7(vmMangleRID(newrrv.rrval),v->vcpu_info,
   76.42 -				v->arch.privregs);
   76.43 +				v->arch.privregs, vhpt_paddr, pal_vaddr);
   76.44  	else set_rr(rr,newrrv.rrval);
   76.45  #endif
   76.46  	return 1;
   76.47 @@ -265,7 +271,8 @@ int set_metaphysical_rr0(void)
   76.48  	ia64_rr rrv;
   76.49  	
   76.50  //	rrv.ve = 1; 	FIXME: TURN ME BACK ON WHEN VHPT IS WORKING
   76.51 -	set_rr(0,v->arch.metaphysical_rr0);
   76.52 +	ia64_set_rr(0,v->arch.metaphysical_rr0);
   76.53 +	ia64_srlz_d();
   76.54  }
   76.55  
   76.56  // validates/changes region registers 0-6 in the currently executing domain
   76.57 @@ -290,7 +297,7 @@ void init_all_rr(struct vcpu *v)
   76.58  	ia64_rr rrv;
   76.59  
   76.60  	rrv.rrval = 0;
   76.61 -	rrv.rrval = v->domain->arch.metaphysical_rr0;
   76.62 +	//rrv.rrval = v->domain->arch.metaphysical_rr0;
   76.63  	rrv.ps = PAGE_SHIFT;
   76.64  	rrv.ve = 1;
   76.65  if (!v->vcpu_info) { printf("Stopping in init_all_rr\n"); dummy(); }
   76.66 @@ -343,12 +350,16 @@ unsigned long load_region_regs(struct vc
   76.67  	if (VCPU(v,metaphysical_mode)) {
   76.68  		ia64_rr rrv;
   76.69  
   76.70 +#if 0
   76.71  		rrv.rrval = 0;
   76.72  		rrv.rid = v->domain->arch.metaphysical_rr0;
   76.73  		rrv.ps = PAGE_SHIFT;
   76.74  		rrv.ve = 1;
   76.75  		rr0 = rrv.rrval;
   76.76  		set_rr_no_srlz(0x0000000000000000L, rr0);
   76.77 +#endif
   76.78 +		rr0 = v->domain->arch.metaphysical_rr0;
   76.79 +		ia64_set_rr(0x0000000000000000L, rr0);
   76.80  		ia64_srlz_d();
   76.81  	}
   76.82  	else {
    77.1 --- a/xen/arch/ia64/xen/vcpu.c	Sun Oct 30 13:52:38 2005 +0100
    77.2 +++ b/xen/arch/ia64/xen/vcpu.c	Sun Oct 30 14:00:35 2005 +0100
    77.3 @@ -66,8 +66,16 @@ unsigned long phys_translate_count = 0;
    77.4  unsigned long vcpu_verbose = 0;
    77.5  #define verbose(a...) do {if (vcpu_verbose) printf(a);} while(0)
    77.6  
    77.7 -extern TR_ENTRY *match_tr(VCPU *vcpu, unsigned long ifa);
    77.8 -extern TR_ENTRY *match_dtlb(VCPU *vcpu, unsigned long ifa);
    77.9 +//#define vcpu_quick_region_check(_tr_regions,_ifa)	1
   77.10 +#define vcpu_quick_region_check(_tr_regions,_ifa)			\
   77.11 +	(_tr_regions & (1 << ((unsigned long)_ifa >> 61)))
   77.12 +#define vcpu_quick_region_set(_tr_regions,_ifa)				\
   77.13 +	do {_tr_regions |= (1 << ((unsigned long)_ifa >> 61)); } while (0)
   77.14 +
   77.15 +// FIXME: also need to check && (!trp->key || vcpu_pkr_match(trp->key))
   77.16 +#define vcpu_match_tr_entry(_trp,_ifa,_rid)				\
   77.17 +	((_trp->p && (_trp->rid==_rid) && (_ifa >= _trp->vadr) &&	\
   77.18 +	(_ifa < (_trp->vadr + (1L<< _trp->ps)) - 1)))
   77.19  
   77.20  /**************************************************************************
   77.21   VCPU general register access routines
   77.22 @@ -620,7 +628,7 @@ void vcpu_pend_interrupt(VCPU *vcpu, UIN
   77.23  		return;
   77.24  	}
   77.25      if ( VMX_DOMAIN(vcpu) ) {
   77.26 - 	    set_bit(vector,VCPU(vcpu,irr));
   77.27 +	    set_bit(vector,VCPU(vcpu,irr));
   77.28      } else
   77.29      {
   77.30  	/* if (!test_bit(vector,PSCB(vcpu,delivery_mask))) return; */
   77.31 @@ -630,16 +638,6 @@ void vcpu_pend_interrupt(VCPU *vcpu, UIN
   77.32  	set_bit(vector,PSCBX(vcpu,irr));
   77.33  	PSCB(vcpu,pending_interruption) = 1;
   77.34      }
   77.35 -
   77.36 -#if 0
   77.37 -    /* Keir: I think you should unblock when an interrupt is pending. */
   77.38 -    {
   77.39 -        int running = test_bit(_VCPUF_running, &vcpu->vcpu_flags);
   77.40 -        vcpu_unblock(vcpu);
   77.41 -        if ( running )
   77.42 -            smp_send_event_check_cpu(vcpu->processor);
   77.43 -    }
   77.44 -#endif
   77.45  }
   77.46  
   77.47  void early_tick(VCPU *vcpu)
   77.48 @@ -710,14 +708,6 @@ UINT64 vcpu_check_pending_interrupts(VCP
   77.49  	}
   77.50  
   77.51  //printf("returned to caller\n");
   77.52 -#if 0
   77.53 -if (vector == (PSCB(vcpu,itv) & 0xff)) {
   77.54 -	UINT64 now = ia64_get_itc();
   77.55 -	UINT64 itm = PSCBX(vcpu,domain_itm);
   77.56 -	if (now < itm) early_tick(vcpu);
   77.57 -
   77.58 -}
   77.59 -#endif
   77.60  	return vector;
   77.61  }
   77.62  
   77.63 @@ -775,6 +765,7 @@ IA64FAULT vcpu_get_ivr(VCPU *vcpu, UINT6
   77.64  	}
   77.65  #ifdef HEARTBEAT_FREQ
   77.66  	if (domid >= N_DOMS) domid = N_DOMS-1;
   77.67 +#if 0
   77.68  	if (vector == (PSCB(vcpu,itv) & 0xff)) {
   77.69  	    if (!(++count[domid] & ((HEARTBEAT_FREQ*1024)-1))) {
   77.70  		printf("Dom%d heartbeat... ticks=%lx,nonticks=%lx\n",
   77.71 @@ -783,6 +774,7 @@ IA64FAULT vcpu_get_ivr(VCPU *vcpu, UINT6
   77.72  		//dump_runq();
   77.73  	    }
   77.74  	}
   77.75 +#endif
   77.76  	else nonclockcount[domid]++;
   77.77  #endif
   77.78  	// now have an unmasked, pending, deliverable vector!
   77.79 @@ -1068,23 +1060,6 @@ void vcpu_set_next_timer(VCPU *vcpu)
   77.80  	/* gloss over the wraparound problem for now... we know it exists
   77.81  	 * but it doesn't matter right now */
   77.82  
   77.83 -#if 0
   77.84 -	/* ensure at least next SP tick is in the future */
   77.85 -	if (!interval) PSCBX(vcpu,xen_itm) = now +
   77.86 -#if 0
   77.87 -		(running_on_sim() ? SIM_DEFAULT_CLOCK_RATE :
   77.88 -					DEFAULT_CLOCK_RATE);
   77.89 -#else
   77.90 -	3000000;
   77.91 -//printf("vcpu_set_next_timer: HACK!\n");
   77.92 -#endif
   77.93 -#if 0
   77.94 -	if (PSCBX(vcpu,xen_itm) < now)
   77.95 -		while (PSCBX(vcpu,xen_itm) < now + (interval>>1))
   77.96 -			PSCBX(vcpu,xen_itm) += interval;
   77.97 -#endif
   77.98 -#endif
   77.99 -
  77.100  	if (is_idle_task(vcpu->domain)) {
  77.101  //		printf("****** vcpu_set_next_timer called during idle!!\n");
  77.102  		vcpu_safe_set_itm(s);
  77.103 @@ -1175,14 +1150,6 @@ void vcpu_pend_timer(VCPU *vcpu)
  77.104  		// don't deliver another
  77.105  		return;
  77.106  	}
  77.107 -#if 0
  77.108 -	// attempt to flag "timer tick before its due" source
  77.109 -	{
  77.110 -	UINT64 itm = PSCBX(vcpu,domain_itm);
  77.111 -	UINT64 now = ia64_get_itc();
  77.112 -	if (now < itm) printf("******* vcpu_pend_timer: pending before due!\n");
  77.113 -	}
  77.114 -#endif
  77.115  	vcpu_pend_interrupt(vcpu, itv);
  77.116  }
  77.117  
  77.118 @@ -1197,33 +1164,6 @@ UINT64 vcpu_timer_pending_early(VCPU *vc
  77.119  	return (vcpu_deliverable_timer(vcpu) && (now < itm));
  77.120  }
  77.121  
  77.122 -//FIXME: This is a hack because everything dies if a timer tick is lost
  77.123 -void vcpu_poke_timer(VCPU *vcpu)
  77.124 -{
  77.125 -	UINT64 itv = PSCB(vcpu,itv) & 0xff;
  77.126 -	UINT64 now = ia64_get_itc();
  77.127 -	UINT64 itm = PSCBX(vcpu,domain_itm);
  77.128 -	UINT64 irr;
  77.129 -
  77.130 -	if (vcpu_timer_disabled(vcpu)) return;
  77.131 -	if (!itm) return;
  77.132 -	if (itv != 0xefL) {
  77.133 -		printf("vcpu_poke_timer: unimplemented itv=%lx!\n",itv);
  77.134 -		while(1);
  77.135 -	}
  77.136 -	// using 0xef instead of itv so can get real irr
  77.137 -	if (now > itm && !test_bit(0xefL, PSCBX(vcpu,insvc))) {
  77.138 -		if (!test_bit(0xefL,PSCBX(vcpu,irr))) {
  77.139 -			irr = ia64_getreg(_IA64_REG_CR_IRR3);
  77.140 -			if (irr & (1L<<(0xef-0xc0))) return;
  77.141 -if (now-itm>0x800000)
  77.142 -printf("*** poking timer: now=%lx,vitm=%lx,xitm=%lx,itm=%lx\n",now,itm,local_cpu_data->itm_next,ia64_get_itm());
  77.143 -			vcpu_pend_timer(vcpu);
  77.144 -		}
  77.145 -	}
  77.146 -}
  77.147 -
  77.148 -
  77.149  /**************************************************************************
  77.150  Privileged operation emulation routines
  77.151  **************************************************************************/
  77.152 @@ -1316,13 +1256,6 @@ IA64FAULT vcpu_thash(VCPU *vcpu, UINT64 
  77.153  	UINT64 VHPT_addr = VHPT_addr1 | ((VHPT_addr2a | VHPT_addr2b) << 15) |
  77.154  			VHPT_addr3;
  77.155  
  77.156 -#if 0
  77.157 -	if (VHPT_addr1 == 0xe000000000000000L) {
  77.158 -	    printf("vcpu_thash: thash unsupported with rr7 @%lx\n",
  77.159 -		PSCB(vcpu,iip));
  77.160 -	    return (IA64_ILLOP_FAULT);
  77.161 -	}
  77.162 -#endif
  77.163  //verbose("vcpu_thash: vadr=%p, VHPT_addr=%p\n",vadr,VHPT_addr);
  77.164  	*pval = VHPT_addr;
  77.165  	return (IA64_NO_FAULT);
  77.166 @@ -1341,9 +1274,9 @@ unsigned long vhpt_translate_count = 0;
  77.167  
  77.168  IA64FAULT vcpu_translate(VCPU *vcpu, UINT64 address, BOOLEAN is_data, UINT64 *pteval, UINT64 *itir, UINT64 *iha)
  77.169  {
  77.170 -	unsigned long pta, pta_mask, pte, ps;
  77.171 +	unsigned long pta, pte, rid, rr;
  77.172 +	int i;
  77.173  	TR_ENTRY *trp;
  77.174 -	ia64_rr rr;
  77.175  
  77.176  	if (!(address >> 61)) {
  77.177  		if (!PSCB(vcpu,metaphysical_mode)) {
  77.178 @@ -1361,67 +1294,80 @@ IA64FAULT vcpu_translate(VCPU *vcpu, UIN
  77.179  		return IA64_NO_FAULT;
  77.180  	}
  77.181  
  77.182 -	/* check translation registers */
  77.183 -	if ((trp = match_tr(vcpu,address))) {
  77.184 -			tr_translate_count++;
  77.185 -		*pteval = trp->page_flags;
  77.186 -		*itir = trp->itir;
  77.187 -		return IA64_NO_FAULT;
  77.188 +	rr = PSCB(vcpu,rrs)[address>>61];
  77.189 +	rid = rr & RR_RID_MASK;
  77.190 +	if (is_data) {
  77.191 +		if (vcpu_quick_region_check(vcpu->arch.dtr_regions,address)) {
  77.192 +			for (trp = vcpu->arch.dtrs, i = NDTRS; i; i--, trp++) {
  77.193 +				if (vcpu_match_tr_entry(trp,address,rid)) {
  77.194 +					*pteval = trp->page_flags;
  77.195 +					*itir = trp->itir;
  77.196 +					tr_translate_count++;
  77.197 +					return IA64_NO_FAULT;
  77.198 +				}
  77.199 +			}
  77.200 +		}
  77.201 +	}
  77.202 +	// FIXME?: check itr's for data accesses too, else bad things happen?
  77.203 +	/* else */ {
  77.204 +		if (vcpu_quick_region_check(vcpu->arch.itr_regions,address)) {
  77.205 +			for (trp = vcpu->arch.itrs, i = NITRS; i; i--, trp++) {
  77.206 +				if (vcpu_match_tr_entry(trp,address,rid)) {
  77.207 +					*pteval = trp->page_flags;
  77.208 +					*itir = trp->itir;
  77.209 +					tr_translate_count++;
  77.210 +					return IA64_NO_FAULT;
  77.211 +				}
  77.212 +			}
  77.213 +		}
  77.214  	}
  77.215  
  77.216  	/* check 1-entry TLB */
  77.217 -	if ((trp = match_dtlb(vcpu,address))) {
  77.218 -		dtlb_translate_count++;
  77.219 +	// FIXME?: check dtlb for inst accesses too, else bad things happen?
  77.220 +	trp = &vcpu->arch.dtlb;
  77.221 +	if (/* is_data && */ vcpu_match_tr_entry(trp,address,rid)) {
  77.222  		if (vcpu->domain==dom0 && !in_tpa) *pteval = trp->page_flags;
  77.223  		else *pteval = vcpu->arch.dtlb_pte;
  77.224 -//		printf("DTLB MATCH... NEW, DOM%s, %s\n", vcpu->domain==dom0?
  77.225 -//			"0":"U", in_tpa?"vcpu_tpa":"ia64_do_page_fault");
  77.226  		*itir = trp->itir;
  77.227 +		dtlb_translate_count++;
  77.228  		return IA64_NO_FAULT;
  77.229  	}
  77.230  
  77.231  	/* check guest VHPT */
  77.232  	pta = PSCB(vcpu,pta);
  77.233 -	rr.rrval = PSCB(vcpu,rrs)[address>>61];
  77.234 -	if (!rr.ve || !(pta & IA64_PTA_VE)) {
  77.235 -// FIXME? does iha get set for alt faults? does xenlinux depend on it?
  77.236 -		vcpu_thash(vcpu, address, iha);
  77.237 -// FIXME?: does itir get set for alt faults?
  77.238 -		*itir = vcpu_get_itir_on_fault(vcpu,address);
  77.239 -		return (is_data ? IA64_ALT_DATA_TLB_VECTOR :
  77.240 -				IA64_ALT_INST_TLB_VECTOR);
  77.241 -	}
  77.242  	if (pta & IA64_PTA_VF) { /* long format VHPT - not implemented */
  77.243 -		// thash won't work right?
  77.244  		panic_domain(vcpu_regs(vcpu),"can't do long format VHPT\n");
  77.245  		//return (is_data ? IA64_DATA_TLB_VECTOR:IA64_INST_TLB_VECTOR);
  77.246  	}
  77.247  
  77.248 +	*itir = rr & (RR_RID_MASK | RR_PS_MASK);
  77.249 +	// note: architecturally, iha is optionally set for alt faults but
  77.250 +	// xenlinux depends on it so should document it as part of PV interface
  77.251 +	vcpu_thash(vcpu, address, iha);
  77.252 +	if (!(rr & RR_VE_MASK) || !(pta & IA64_PTA_VE))
  77.253 +		return (is_data ? IA64_ALT_DATA_TLB_VECTOR : IA64_ALT_INST_TLB_VECTOR);
  77.254 +
  77.255  	/* avoid recursively walking (short format) VHPT */
  77.256 -	pta_mask = (itir_mask(pta) << 3) >> 3;
  77.257 -	if (((address ^ pta) & pta_mask) == 0)
  77.258 +	if (((address ^ pta) & ((itir_mask(pta) << 3) >> 3)) == 0)
  77.259  		return (is_data ? IA64_DATA_TLB_VECTOR : IA64_INST_TLB_VECTOR);
  77.260  
  77.261 -	vcpu_thash(vcpu, address, iha);
  77.262 -	if (__copy_from_user(&pte, (void *)(*iha), sizeof(pte)) != 0) {
  77.263 -// FIXME?: does itir get set for vhpt faults?
  77.264 -		*itir = vcpu_get_itir_on_fault(vcpu,*iha);
  77.265 +	if (__copy_from_user(&pte, (void *)(*iha), sizeof(pte)) != 0)
  77.266 +		// virtual VHPT walker "missed" in TLB
  77.267  		return IA64_VHPT_FAULT;
  77.268 -	}
  77.269  
  77.270  	/*
  77.271 -	 * Optimisation: this VHPT walker aborts on not-present pages
  77.272 -	 * instead of inserting a not-present translation, this allows
  77.273 -	 * vectoring directly to the miss handler.
  77.274 -	 */
  77.275 -	if (pte & _PAGE_P) {
  77.276 -		*pteval = pte;
  77.277 -		*itir = vcpu_get_itir_on_fault(vcpu,address);
  77.278 -		vhpt_translate_count++;
  77.279 -		return IA64_NO_FAULT;
  77.280 -	}
  77.281 -	*itir = vcpu_get_itir_on_fault(vcpu,address);
  77.282 -	return (is_data ? IA64_DATA_TLB_VECTOR : IA64_INST_TLB_VECTOR);
  77.283 +	* Optimisation: this VHPT walker aborts on not-present pages
  77.284 +	* instead of inserting a not-present translation, this allows
  77.285 +	* vectoring directly to the miss handler.
  77.286 +	*/
  77.287 +	if (!(pte & _PAGE_P))
  77.288 +		return (is_data ? IA64_DATA_TLB_VECTOR : IA64_INST_TLB_VECTOR);
  77.289 +
  77.290 +	/* found mapping in guest VHPT! */
  77.291 +	*itir = rr & RR_PS_MASK;
  77.292 +	*pteval = pte;
  77.293 +	vhpt_translate_count++;
  77.294 +	return IA64_NO_FAULT;
  77.295  }
  77.296  
  77.297  IA64FAULT vcpu_tpa(VCPU *vcpu, UINT64 vadr, UINT64 *padr)
  77.298 @@ -1736,33 +1682,6 @@ static void vcpu_set_tr_entry(TR_ENTRY *
  77.299  	}
  77.300  }
  77.301  
  77.302 -TR_ENTRY *vcpu_match_tr_entry(VCPU *vcpu, TR_ENTRY *trp, UINT64 ifa, int count)
  77.303 -{
  77.304 -	unsigned long rid = (get_rr(ifa) & RR_RID_MASK);
  77.305 -	int i;
  77.306 -
  77.307 -	for (i = 0; i < count; i++, trp++) {
  77.308 -		if (!trp->p) continue;
  77.309 -		if (physicalize_rid(vcpu,trp->rid) != rid) continue;
  77.310 -		if (ifa < trp->vadr) continue;
  77.311 -		if (ifa >= (trp->vadr + (1L << trp->ps)) - 1) continue;
  77.312 -		//if (trp->key && !match_pkr(vcpu,trp->key)) continue;
  77.313 -		return trp;
  77.314 -	}
  77.315 -	return 0;
  77.316 -}
  77.317 -
  77.318 -TR_ENTRY *match_tr(VCPU *vcpu, unsigned long ifa)
  77.319 -{
  77.320 -	TR_ENTRY *trp;
  77.321 -
  77.322 -	trp = vcpu_match_tr_entry(vcpu,vcpu->arch.dtrs,ifa,NDTRS);
  77.323 -	if (trp) return trp;
  77.324 -	trp = vcpu_match_tr_entry(vcpu,vcpu->arch.itrs,ifa,NITRS);
  77.325 -	if (trp) return trp;
  77.326 -	return 0;
  77.327 -}
  77.328 -
  77.329  IA64FAULT vcpu_itr_d(VCPU *vcpu, UINT64 slot, UINT64 pte,
  77.330  		UINT64 itir, UINT64 ifa)
  77.331  {
  77.332 @@ -1772,6 +1691,7 @@ IA64FAULT vcpu_itr_d(VCPU *vcpu, UINT64 
  77.333  	trp = &PSCBX(vcpu,dtrs[slot]);
  77.334  //printf("***** itr.d: setting slot %d: ifa=%p\n",slot,ifa);
  77.335  	vcpu_set_tr_entry(trp,pte,itir,ifa);
  77.336 +	vcpu_quick_region_set(PSCBX(vcpu,dtr_regions),ifa);
  77.337  	return IA64_NO_FAULT;
  77.338  }
  77.339  
  77.340 @@ -1784,6 +1704,7 @@ IA64FAULT vcpu_itr_i(VCPU *vcpu, UINT64 
  77.341  	trp = &PSCBX(vcpu,itrs[slot]);
  77.342  //printf("***** itr.i: setting slot %d: ifa=%p\n",slot,ifa);
  77.343  	vcpu_set_tr_entry(trp,pte,itir,ifa);
  77.344 +	vcpu_quick_region_set(PSCBX(vcpu,itr_regions),ifa);
  77.345  	return IA64_NO_FAULT;
  77.346  }
  77.347  
  77.348 @@ -1835,17 +1756,6 @@ void vcpu_itc_no_srlz(VCPU *vcpu, UINT64
  77.349  	}
  77.350  }
  77.351  
  77.352 -// NOTE: returns a physical pte, NOT a "metaphysical" pte, so do not check
  77.353 -// the physical address contained for correctness
  77.354 -TR_ENTRY *match_dtlb(VCPU *vcpu, unsigned long ifa)
  77.355 -{
  77.356 -	TR_ENTRY *trp;
  77.357 -
  77.358 -	if (trp = vcpu_match_tr_entry(vcpu,&vcpu->arch.dtlb,ifa,1))
  77.359 -		return (&vcpu->arch.dtlb);
  77.360 -	return 0UL;
  77.361 -}
  77.362 -
  77.363  IA64FAULT vcpu_itc_d(VCPU *vcpu, UINT64 pte, UINT64 itir, UINT64 ifa)
  77.364  {
  77.365  	unsigned long pteval, logps = (itir >> 2) & 0x3f;
  77.366 @@ -1952,12 +1862,14 @@ IA64FAULT vcpu_ptc_ga(VCPU *vcpu,UINT64 
  77.367  IA64FAULT vcpu_ptr_d(VCPU *vcpu,UINT64 vadr,UINT64 addr_range)
  77.368  {
  77.369  	printf("vcpu_ptr_d: Purging TLB is unsupported\n");
  77.370 +	// don't forget to recompute dtr_regions
  77.371  	return (IA64_ILLOP_FAULT);
  77.372  }
  77.373  
  77.374  IA64FAULT vcpu_ptr_i(VCPU *vcpu,UINT64 vadr,UINT64 addr_range)
  77.375  {
  77.376  	printf("vcpu_ptr_i: Purging TLB is unsupported\n");
  77.377 +	// don't forget to recompute itr_regions
  77.378  	return (IA64_ILLOP_FAULT);
  77.379  }
  77.380  
    78.1 --- a/xen/arch/ia64/xen/xenasm.S	Sun Oct 30 13:52:38 2005 +0100
    78.2 +++ b/xen/arch/ia64/xen/xenasm.S	Sun Oct 30 14:00:35 2005 +0100
    78.3 @@ -48,11 +48,11 @@ END(platform_is_hp_ski)
    78.4  // FIXME? Note that this turns off the DB bit (debug)
    78.5  #define PSR_BITS_TO_SET	IA64_PSR_BN
    78.6  
    78.7 -//extern void ia64_new_rr7(unsigned long rid,void *shared_info, void *shared_arch_info);
    78.8 +//extern void ia64_new_rr7(unsigned long rid,void *shared_info, void *shared_arch_info, unsigned long p_vhpt, unsigned long v_pal);
    78.9  GLOBAL_ENTRY(ia64_new_rr7)
   78.10  	// not sure this unwind statement is correct...
   78.11  	.prologue ASM_UNW_PRLG_RP|ASM_UNW_PRLG_PFS, ASM_UNW_PRLG_GRSAVE(1)
   78.12 -	alloc loc1 = ar.pfs, 3, 8, 0, 0
   78.13 +	alloc loc1 = ar.pfs, 5, 9, 0, 0
   78.14  1:	{
   78.15  	  mov r28  = in0		// copy procedure index
   78.16  	  mov r8   = ip			// save ip to compute branch
   78.17 @@ -63,10 +63,12 @@ 1:	{
   78.18  	;;
   78.19  	tpa loc2=loc2			// grab this BEFORE changing rr7
   78.20  	;;
   78.21 +	dep loc8=0,in4,60,4
   78.22 +	;;
   78.23  #if VHPT_ENABLED
   78.24 -	movl loc6=VHPT_ADDR
   78.25 +	mov loc6=in3
   78.26  	;;
   78.27 -	tpa loc6=loc6			// grab this BEFORE changing rr7
   78.28 +	//tpa loc6=loc6			// grab this BEFORE changing rr7
   78.29  	;;
   78.30  #endif
   78.31  	mov loc5=in1
   78.32 @@ -231,6 +233,21 @@ 1:
   78.33  	itr.d dtr[r25]=r23		// wire in new mapping...
   78.34  	;;
   78.35  
   78.36 +	//Purge/insert PAL TR
   78.37 +	mov r24=IA64_TR_PALCODE
   78.38 +	movl r25=PAGE_KERNEL
   78.39 +	;;
   78.40 +	or loc8=r25,loc8
   78.41 +	mov r23=IA64_GRANULE_SHIFT<<2
   78.42 +	;;
   78.43 +	ptr.i	in4,r23
   78.44 +	;;
   78.45 +	mov cr.itir=r23
   78.46 +	mov cr.ifa=in4
   78.47 +	;;
   78.48 +	itr.i itr[r24]=loc8
   78.49 +	;;
   78.50 +
   78.51  	// done, switch back to virtual and return
   78.52  	mov r16=loc3			// r16= original psr
   78.53  	br.call.sptk.many rp=ia64_switch_mode_virt // return to virtual mode
    79.1 --- a/xen/arch/ia64/xen/xenirq.c	Sun Oct 30 13:52:38 2005 +0100
    79.2 +++ b/xen/arch/ia64/xen/xenirq.c	Sun Oct 30 14:00:35 2005 +0100
    79.3 @@ -35,7 +35,7 @@ xen_debug_irq(ia64_vector vector, struct
    79.4  int
    79.5  xen_do_IRQ(ia64_vector vector)
    79.6  {
    79.7 -	if (vector != 0xef) {
    79.8 +	if (vector != IA64_TIMER_VECTOR && vector != IA64_IPI_VECTOR) {
    79.9  		extern void vcpu_pend_interrupt(void *, int);
   79.10  #if 0
   79.11  		if (firsttime[vector]) {
   79.12 @@ -57,22 +57,18 @@ xen_do_IRQ(ia64_vector vector)
   79.13  	return(0);
   79.14  }
   79.15  
   79.16 -/* From linux/kernel/softirq.c */
   79.17 -#ifdef __ARCH_IRQ_EXIT_IRQS_DISABLED
   79.18 -# define invoke_softirq()	__do_softirq()
   79.19 -#else
   79.20 -# define invoke_softirq()	do_softirq()
   79.21 -#endif
   79.22 -
   79.23  /*
   79.24   * Exit an interrupt context. Process softirqs if needed and possible:
   79.25   */
   79.26  void irq_exit(void)
   79.27  {
   79.28  	//account_system_vtime(current);
   79.29 -	//sub_preempt_count(IRQ_EXIT_OFFSET);
   79.30 -	if (!in_interrupt() && local_softirq_pending())
   79.31 -		invoke_softirq();
   79.32 +	sub_preempt_count(IRQ_EXIT_OFFSET);
   79.33 +	if (!in_interrupt() && local_softirq_pending()) {
   79.34 +		add_preempt_count(SOFTIRQ_OFFSET);
   79.35 +		do_softirq();
   79.36 +		sub_preempt_count(SOFTIRQ_OFFSET);
   79.37 +	}
   79.38  	//preempt_enable_no_resched();
   79.39  }
   79.40  /* end from linux/kernel/softirq.c */
    80.1 --- a/xen/arch/ia64/xen/xenmisc.c	Sun Oct 30 13:52:38 2005 +0100
    80.2 +++ b/xen/arch/ia64/xen/xenmisc.c	Sun Oct 30 14:00:35 2005 +0100
    80.3 @@ -17,6 +17,7 @@
    80.4  #include <asm/io.h>
    80.5  #include <xen/softirq.h>
    80.6  #include <public/sched.h>
    80.7 +#include <asm/vhpt.h>
    80.8  
    80.9  efi_memory_desc_t ia64_efi_io_md;
   80.10  EXPORT_SYMBOL(ia64_efi_io_md);
   80.11 @@ -280,6 +281,8 @@ void cs01foo(void) {}
   80.12  
   80.13  unsigned long context_switch_count = 0;
   80.14  
   80.15 +#include <asm/vcpu.h>
   80.16 +
   80.17  void context_switch(struct vcpu *prev, struct vcpu *next)
   80.18  {
   80.19  //printk("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n");
   80.20 @@ -287,7 +290,8 @@ void context_switch(struct vcpu *prev, s
   80.21  //prev->domain->domain_id,(long)prev&0xffffff,next->domain->domain_id,(long)next&0xffffff);
   80.22  //if (prev->domain->domain_id == 1 && next->domain->domain_id == 0) cs10foo();
   80.23  //if (prev->domain->domain_id == 0 && next->domain->domain_id == 1) cs01foo();
   80.24 -//printk("@@sw %d->%d\n",prev->domain->domain_id,next->domain->domain_id);
   80.25 +printk("@@sw%d/%x %d->%d\n",smp_processor_id(), hard_smp_processor_id (),
   80.26 +       prev->domain->domain_id,next->domain->domain_id);
   80.27      if(VMX_DOMAIN(prev)){
   80.28      	vtm_domain_out(prev);
   80.29      }
   80.30 @@ -307,9 +311,13 @@ if (!cnt[id]--) { printk("%x",id); cnt[i
   80.31  if (!i--) { printk("+",id); i = 1000000; }
   80.32  }
   80.33  
   80.34 -	if (VMX_DOMAIN(current)){
   80.35 +    if (VMX_DOMAIN(current)){
   80.36  		vmx_load_all_rr(current);
   80.37      }else{
   80.38 +	extern char ia64_ivt;
   80.39 +	ia64_set_iva(&ia64_ivt);
   80.40 +	ia64_set_pta(VHPT_ADDR | (1 << 8) | (VHPT_SIZE_LOG2 << 2) |
   80.41 +		VHPT_ENABLED);
   80.42      	if (!is_idle_task(current->domain)) {
   80.43  	    	load_region_regs(current);
   80.44  		    if (vcpu_timer_expired(current)) vcpu_pend_timer(current);
    81.1 --- a/xen/arch/ia64/xen/xensetup.c	Sun Oct 30 13:52:38 2005 +0100
    81.2 +++ b/xen/arch/ia64/xen/xensetup.c	Sun Oct 30 14:00:35 2005 +0100
    81.3 @@ -253,11 +253,11 @@ void start_kernel(void)
    81.4  printk("About to call scheduler_init()\n");
    81.5      scheduler_init();
    81.6      local_irq_disable();
    81.7 +    init_IRQ ();
    81.8  printk("About to call init_xen_time()\n");
    81.9      init_xen_time(); /* initialise the time */
   81.10  printk("About to call ac_timer_init()\n");
   81.11      ac_timer_init();
   81.12 -// init_xen_time(); ???
   81.13  
   81.14  #ifdef CONFIG_SMP
   81.15      if ( opt_nosmp )
   81.16 @@ -276,6 +276,9 @@ printk("About to call ac_timer_init()\n"
   81.17  
   81.18      //BUG_ON(!local_irq_is_enabled());
   81.19  
   81.20 +    /*  Enable IRQ to receive IPI (needed for ITC sync).  */
   81.21 +    local_irq_enable();
   81.22 +
   81.23  printk("num_online_cpus=%d, max_cpus=%d\n",num_online_cpus(),max_cpus);
   81.24      for_each_present_cpu ( i )
   81.25      {
   81.26 @@ -287,24 +290,16 @@ printk("About to call __cpu_up(%d)\n",i)
   81.27  	}
   81.28      }
   81.29  
   81.30 +    local_irq_disable();
   81.31 +
   81.32      printk("Brought up %ld CPUs\n", (long)num_online_cpus());
   81.33      smp_cpus_done(max_cpus);
   81.34  #endif
   81.35  
   81.36 -
   81.37 -	// FIXME: Should the following be swapped and moved later?
   81.38 -    schedulers_start();
   81.39      do_initcalls();
   81.40  printk("About to call sort_main_extable()\n");
   81.41      sort_main_extable();
   81.42  
   81.43 -    /* surrender usage of kernel registers to domain, use percpu area instead */
   81.44 -    __get_cpu_var(cpu_kr)._kr[IA64_KR_IO_BASE] = ia64_get_kr(IA64_KR_IO_BASE);
   81.45 -    __get_cpu_var(cpu_kr)._kr[IA64_KR_PER_CPU_DATA] = ia64_get_kr(IA64_KR_PER_CPU_DATA);
   81.46 -    __get_cpu_var(cpu_kr)._kr[IA64_KR_CURRENT_STACK] = ia64_get_kr(IA64_KR_CURRENT_STACK);
   81.47 -    __get_cpu_var(cpu_kr)._kr[IA64_KR_FPU_OWNER] = ia64_get_kr(IA64_KR_FPU_OWNER);
   81.48 -    __get_cpu_var(cpu_kr)._kr[IA64_KR_CURRENT] = ia64_get_kr(IA64_KR_CURRENT);
   81.49 -    __get_cpu_var(cpu_kr)._kr[IA64_KR_PT_BASE] = ia64_get_kr(IA64_KR_PT_BASE);
   81.50  
   81.51      /* Create initial domain 0. */
   81.52  printk("About to call do_createdomain()\n");
   81.53 @@ -342,6 +337,11 @@ printk("About to call construct_dom0()\n
   81.54                          0,
   81.55  			0) != 0)
   81.56          panic("Could not set up DOM0 guest OS\n");
   81.57 +
   81.58 +    /* PIN domain0 on CPU 0.  */
   81.59 +    dom0->vcpu[0]->cpumap=1;
   81.60 +    set_bit(_VCPUF_cpu_pinned, &dom0->vcpu[0]->vcpu_flags);
   81.61 +
   81.62  #ifdef CLONE_DOMAIN0
   81.63      {
   81.64      int i;
   81.65 @@ -379,9 +379,16 @@ printk("About to call init_trace_bufs()\
   81.66  	domain_unpause_by_systemcontroller(clones[i]);
   81.67      }
   81.68  #endif
   81.69 +    domain0_ready = 1;
   81.70 +
   81.71 +    local_irq_enable();
   81.72 +
   81.73 +    printf("About to call schedulers_start dom0=%p, idle0_dom=%p\n",
   81.74 +	   dom0, &idle0_domain);
   81.75 +    schedulers_start();
   81.76 +
   81.77      domain_unpause_by_systemcontroller(dom0);
   81.78 -    domain0_ready = 1;
   81.79 -    local_irq_enable();
   81.80 +
   81.81  printk("About to call startup_cpu_idle_loop()\n");
   81.82      startup_cpu_idle_loop();
   81.83  }
    82.1 --- a/xen/arch/ia64/xen/xentime.c	Sun Oct 30 13:52:38 2005 +0100
    82.2 +++ b/xen/arch/ia64/xen/xentime.c	Sun Oct 30 14:00:35 2005 +0100
    82.3 @@ -38,6 +38,20 @@ static s_time_t        stime_irq = 0x0; 
    82.4  unsigned long itc_scale, ns_scale;
    82.5  unsigned long itc_at_irq;
    82.6  
    82.7 +/* We don't expect an absolute cycle value here, since then no way
    82.8 + * to prevent overflow for large norminator. Normally this conversion
    82.9 + * is used for relative offset.
   82.10 + */
   82.11 +u64 cycle_to_ns(u64 cycle)
   82.12 +{
   82.13 +    return (cycle * itc_scale) >> 32;
   82.14 +}
   82.15 +
   82.16 +u64 ns_to_cycle(u64 ns)
   82.17 +{
   82.18 +    return (ns * ns_scale) >> 32;
   82.19 +}
   82.20 +
   82.21  static inline u64 get_time_delta(void)
   82.22  {
   82.23      s64      delta_itc;
   82.24 @@ -52,19 +66,6 @@ static inline u64 get_time_delta(void)
   82.25      return cycle_to_ns(delta_itc);
   82.26  }
   82.27  
   82.28 -/* We don't expect an absolute cycle value here, since then no way
   82.29 - * to prevent overflow for large norminator. Normally this conversion
   82.30 - * is used for relative offset.
   82.31 - */
   82.32 -u64 cycle_to_ns(u64 cycle)
   82.33 -{
   82.34 -    return (cycle * itc_scale) >> 32;
   82.35 -}
   82.36 -
   82.37 -u64 ns_to_cycle(u64 ns)
   82.38 -{
   82.39 -    return (ns * ns_scale) >> 32;
   82.40 -}
   82.41  
   82.42  s_time_t get_s_time(void)
   82.43  {
   82.44 @@ -99,17 +100,19 @@ xen_timer_interrupt (int irq, void *dev_
   82.45  {
   82.46  	unsigned long new_itm, old_itc;
   82.47  
   82.48 +#if 0
   82.49  #define HEARTBEAT_FREQ 16	// period in seconds
   82.50  #ifdef HEARTBEAT_FREQ
   82.51  	static long count = 0;
   82.52  	if (!(++count & ((HEARTBEAT_FREQ*1024)-1))) {
   82.53 -		printf("Heartbeat... iip=%p,psr.i=%d,pend=%d\n",
   82.54 -			regs->cr_iip,
   82.55 +		printf("Heartbeat... iip=%p\n", /*",psr.i=%d,pend=%d\n", */
   82.56 +			regs->cr_iip /*,
   82.57  			VCPU(current,interrupt_delivery_enabled),
   82.58 -			VCPU(current,pending_interruption));
   82.59 +			VCPU(current,pending_interruption) */);
   82.60  		count = 0;
   82.61  	}
   82.62  #endif
   82.63 +#endif
   82.64  	if (current->domain == dom0) {
   82.65  		// FIXME: there's gotta be a better way of doing this...
   82.66  		// We have to ensure that domain0 is launched before we
   82.67 @@ -117,12 +120,14 @@ xen_timer_interrupt (int irq, void *dev_
   82.68  		//domain0_ready = 1; // moved to xensetup.c
   82.69  		VCPU(current,pending_interruption) = 1;
   82.70  	}
   82.71 -	if (domain0_ready && vcpu_timer_expired(dom0->vcpu[0])) {
   82.72 -		vcpu_pend_timer(dom0->vcpu[0]);
   82.73 -		//vcpu_set_next_timer(dom0->vcpu[0]);
   82.74 -		vcpu_wake(dom0->vcpu[0]);
   82.75 +	if (domain0_ready && current->domain != dom0) {
   82.76 +		if(vcpu_timer_expired(dom0->vcpu[0])) {
   82.77 +			vcpu_pend_timer(dom0->vcpu[0]);
   82.78 +			//vcpu_set_next_timer(dom0->vcpu[0]);
   82.79 +			vcpu_wake(dom0->vcpu[0]);
   82.80 +		}
   82.81  	}
   82.82 -	if (!is_idle_task(current->domain) && current->domain != dom0) {
   82.83 +	if (!is_idle_task(current->domain))  {
   82.84  		if (vcpu_timer_expired(current)) {
   82.85  			vcpu_pend_timer(current);
   82.86  			// ensure another timer interrupt happens even if domain doesn't
   82.87 @@ -132,9 +137,12 @@ xen_timer_interrupt (int irq, void *dev_
   82.88  	}
   82.89  	new_itm = local_cpu_data->itm_next;
   82.90  
   82.91 -	if (!time_after(ia64_get_itc(), new_itm))
   82.92 +	if (!VMX_DOMAIN(current) && !time_after(ia64_get_itc(), new_itm))
   82.93  		return;
   82.94  
   82.95 +	if (VMX_DOMAIN(current))
   82.96 +		vcpu_wake(current);
   82.97 +
   82.98  	while (1) {
   82.99  		new_itm += local_cpu_data->itm_delta;
  82.100  
  82.101 @@ -233,7 +241,7 @@ int reprogram_ac_timer(s_time_t timeout)
  82.102  	s_time_t expire;
  82.103  	unsigned long seq, cur_itc, itm_next;
  82.104  
  82.105 -	if (!domain0_ready) return 1;
  82.106 +	if (!domain0_ready || timeout == 0) return 1;
  82.107  
  82.108  	do {
  82.109  		seq = read_seqbegin(&xtime_lock);
    83.1 --- a/xen/arch/x86/apic.c	Sun Oct 30 13:52:38 2005 +0100
    83.2 +++ b/xen/arch/x86/apic.c	Sun Oct 30 14:00:35 2005 +0100
    83.3 @@ -815,6 +815,10 @@ int __init calibrate_APIC_clock(void)
    83.4      return result;
    83.5  }
    83.6  
    83.7 +unsigned int get_apic_bus_scale(void)
    83.8 +{
    83.9 +    return bus_scale;
   83.10 +}
   83.11  
   83.12  static unsigned int calibration_result;
   83.13  
    84.1 --- a/xen/arch/x86/dm/i8259.c	Sun Oct 30 13:52:38 2005 +0100
    84.2 +++ b/xen/arch/x86/dm/i8259.c	Sun Oct 30 14:00:35 2005 +0100
    84.3 @@ -32,8 +32,8 @@
    84.4  #include <public/io/ioreq.h>
    84.5  #include <asm/vmx.h>
    84.6  #include <public/io/vmx_vpic.h>
    84.7 -#include <public/io/vmx_vlapic.h>
    84.8  #include <asm/current.h>
    84.9 +#include <asm/vmx_vlapic.h>
   84.10  
   84.11  /* set irq level. If an edge is detected, then the IRR is set to 1 */
   84.12  static inline void pic_set_irq1(PicState *s, int irq, int level)
   84.13 @@ -135,7 +135,6 @@ void do_pic_irqs (struct vmx_virpic *s, 
   84.14  {
   84.15      s->pics[1].irr |= (uint8_t)(irqs >> 8);
   84.16      s->pics[0].irr |= (uint8_t) irqs;
   84.17 -    /* TODO for alt_irq_func */
   84.18      pic_update_irq(s);
   84.19  }
   84.20  
   84.21 @@ -505,14 +504,22 @@ int cpu_get_pic_interrupt(struct vcpu *v
   84.22  {
   84.23      int intno;
   84.24      struct vmx_virpic *s = &v->domain->arch.vmx_platform.vmx_pic;
   84.25 -    
   84.26 +    struct vmx_platform *plat = &v->domain->arch.vmx_platform;
   84.27 +
   84.28 +    if ( !vlapic_accept_pic_intr(v) )
   84.29 +        return -1;
   84.30 +
   84.31 +    if ( !plat->interrupt_request )
   84.32 +        return -1;
   84.33 +
   84.34      /* read the irq from the PIC */
   84.35      intno = pic_read_irq(s);
   84.36      *type = VLAPIC_DELIV_MODE_EXT;
   84.37 +    plat->interrupt_request = 0;
   84.38      return intno;
   84.39  }
   84.40  
   84.41 -int is_pit_irq(struct vcpu *v, int irq)
   84.42 +int is_pit_irq(struct vcpu *v, int irq, int type)
   84.43  {
   84.44      int  pit_vec = v->domain->arch.vmx_platform.vmx_pic.pics[0].irq_base;
   84.45  
    85.1 --- a/xen/arch/x86/domain_build.c	Sun Oct 30 13:52:38 2005 +0100
    85.2 +++ b/xen/arch/x86/domain_build.c	Sun Oct 30 14:00:35 2005 +0100
    85.3 @@ -15,6 +15,7 @@
    85.4  #include <xen/elf.h>
    85.5  #include <xen/kernel.h>
    85.6  #include <xen/domain.h>
    85.7 +#include <xen/compile.h>
    85.8  #include <asm/regs.h>
    85.9  #include <asm/system.h>
   85.10  #include <asm/io.h>
   85.11 @@ -582,26 +583,23 @@ int construct_dom0(struct domain *d,
   85.12              _initrd_start, (_initrd_start+initrd_len+PAGE_SIZE-1) & PAGE_MASK);
   85.13      }
   85.14  
   85.15 -    d->next_io_page = max_page;
   85.16 -
   85.17      /* Set up start info area. */
   85.18      si = (start_info_t *)vstartinfo_start;
   85.19      memset(si, 0, PAGE_SIZE);
   85.20      si->nr_pages = nr_pages;
   85.21  
   85.22 +    si->shared_info = virt_to_phys(d->shared_info);
   85.23      if ( opt_dom0_translate )
   85.24      {
   85.25 -        si->shared_info  = d->next_io_page << PAGE_SHIFT;
   85.26 -        set_pfn_from_mfn(virt_to_phys(d->shared_info) >> PAGE_SHIFT, d->next_io_page);
   85.27 -        d->next_io_page++;
   85.28 +        si->shared_info  = max_page << PAGE_SHIFT;
   85.29 +        set_pfn_from_mfn(virt_to_phys(d->shared_info) >> PAGE_SHIFT, max_page);
   85.30      }
   85.31 -    else
   85.32 -        si->shared_info  = virt_to_phys(d->shared_info);
   85.33  
   85.34      si->flags        = SIF_PRIVILEGED | SIF_INITDOMAIN;
   85.35      si->pt_base      = vpt_start;
   85.36      si->nr_pt_frames = nr_pt_pages;
   85.37      si->mfn_list     = vphysmap_start;
   85.38 +    sprintf(si->magic, "Xen-%i.%i", XEN_VERSION, XEN_SUBVERSION);
   85.39  
   85.40      /* Write the phys->machine and machine->phys table entries. */
   85.41      for ( pfn = 0; pfn < d->tot_pages; pfn++ )
    86.1 --- a/xen/arch/x86/mm.c	Sun Oct 30 13:52:38 2005 +0100
    86.2 +++ b/xen/arch/x86/mm.c	Sun Oct 30 14:00:35 2005 +0100
    86.3 @@ -1164,6 +1164,7 @@ static int mod_l3_entry(l3_pgentry_t *pl
    86.4  {
    86.5      l3_pgentry_t ol3e;
    86.6      unsigned long vaddr;
    86.7 +    int okay;
    86.8  
    86.9      if ( unlikely(!is_guest_l3_slot(pgentry_ptr_to_slot(pl3e))) )
   86.10      {
   86.11 @@ -1218,7 +1219,9 @@ static int mod_l3_entry(l3_pgentry_t *pl
   86.12          return 0;
   86.13      }
   86.14  
   86.15 -    BUG_ON(!create_pae_xen_mappings(pl3e));
   86.16 +    okay = create_pae_xen_mappings(pl3e);
   86.17 +    BUG_ON(!okay);
   86.18 +
   86.19      put_page_from_l3e(ol3e, pfn);
   86.20      return 1;
   86.21  }
    87.1 --- a/xen/arch/x86/time.c	Sun Oct 30 13:52:38 2005 +0100
    87.2 +++ b/xen/arch/x86/time.c	Sun Oct 30 14:00:35 2005 +0100
    87.3 @@ -323,7 +323,7 @@ static u64 read_pit_count(void)
    87.4      return pit_counter64 + (u16)(pit_stamp - pit_read_counter());
    87.5  }
    87.6  
    87.7 -static int init_pit(void)
    87.8 +static void init_pit(void)
    87.9  {
   87.10      read_platform_count = read_pit_count;
   87.11  
   87.12 @@ -333,8 +333,6 @@ static int init_pit(void)
   87.13  
   87.14      printk("Platform timer is %s PIT\n", freq_string(CLOCK_TICK_RATE));
   87.15      using_pit = 1;
   87.16 -
   87.17 -    return 1;
   87.18  }
   87.19  
   87.20  /************************************************************
   87.21 @@ -563,7 +561,7 @@ static void platform_time_calibration(vo
   87.22  static void init_platform_timer(void)
   87.23  {
   87.24      if ( !init_cyclone() && !init_hpet() )
   87.25 -        BUG_ON(!init_pit());
   87.26 +        init_pit();
   87.27  }
   87.28  
   87.29  
    88.1 --- a/xen/arch/x86/traps.c	Sun Oct 30 13:52:38 2005 +0100
    88.2 +++ b/xen/arch/x86/traps.c	Sun Oct 30 14:00:35 2005 +0100
    88.3 @@ -1147,6 +1147,9 @@ asmlinkage void do_nmi(struct cpu_user_r
    88.4  
    88.5  asmlinkage int math_state_restore(struct cpu_user_regs *regs)
    88.6  {
    88.7 +    struct trap_bounce *tb;
    88.8 +    trap_info_t *ti;
    88.9 +
   88.10      /* Prevent recursion. */
   88.11      clts();
   88.12  
   88.13 @@ -1154,10 +1157,15 @@ asmlinkage int math_state_restore(struct
   88.14  
   88.15      if ( current->arch.guest_context.ctrlreg[0] & X86_CR0_TS )
   88.16      {
   88.17 -        struct trap_bounce *tb = &current->arch.trap_bounce;
   88.18 +        tb = &current->arch.trap_bounce;
   88.19 +        ti = &current->arch.guest_context.trap_ctxt[TRAP_no_device];
   88.20 +
   88.21          tb->flags = TBF_EXCEPTION;
   88.22 -        tb->cs    = current->arch.guest_context.trap_ctxt[7].cs;
   88.23 -        tb->eip   = current->arch.guest_context.trap_ctxt[7].address;
   88.24 +        tb->cs    = ti->cs;
   88.25 +        tb->eip   = ti->address;
   88.26 +        if ( TI_GET_IF(ti) )
   88.27 +            tb->flags |= TBF_INTERRUPT;
   88.28 +
   88.29          current->arch.guest_context.ctrlreg[0] &= ~X86_CR0_TS;
   88.30      }
   88.31  
   88.32 @@ -1169,6 +1177,7 @@ asmlinkage int do_debug(struct cpu_user_
   88.33      unsigned long condition;
   88.34      struct vcpu *v = current;
   88.35      struct trap_bounce *tb = &v->arch.trap_bounce;
   88.36 +    trap_info_t *ti;
   88.37  
   88.38      __asm__ __volatile__("mov %%db6,%0" : "=r" (condition));
   88.39  
   88.40 @@ -1198,9 +1207,12 @@ asmlinkage int do_debug(struct cpu_user_
   88.41      /* Save debug status register where guest OS can peek at it */
   88.42      v->arch.guest_context.debugreg[6] = condition;
   88.43  
   88.44 +    ti = &v->arch.guest_context.trap_ctxt[TRAP_debug];
   88.45      tb->flags = TBF_EXCEPTION;
   88.46 -    tb->cs    = v->arch.guest_context.trap_ctxt[TRAP_debug].cs;
   88.47 -    tb->eip   = v->arch.guest_context.trap_ctxt[TRAP_debug].address;
   88.48 +    tb->cs    = ti->cs;
   88.49 +    tb->eip   = ti->address;
   88.50 +    if ( TI_GET_IF(ti) )
   88.51 +        tb->flags |= TBF_INTERRUPT;
   88.52  
   88.53   out:
   88.54      return EXCRET_not_a_fault;
    89.1 --- a/xen/arch/x86/vmx.c	Sun Oct 30 13:52:38 2005 +0100
    89.2 +++ b/xen/arch/x86/vmx.c	Sun Oct 30 14:00:35 2005 +0100
    89.3 @@ -65,6 +65,11 @@ void vmx_final_setup_guest(struct vcpu *
    89.4  
    89.5      if ( v == v->domain->vcpu[0] )
    89.6      {
    89.7 +        v->domain->arch.vmx_platform.lapic_enable =
    89.8 +            v->arch.guest_context.user_regs.ecx;
    89.9 +        v->arch.guest_context.user_regs.ecx = 0;
   89.10 +        VMX_DBG_LOG(DBG_LEVEL_VLAPIC, "lapic enable is %d.\n",
   89.11 +                    v->domain->arch.vmx_platform.lapic_enable);
   89.12          /*
   89.13           * Required to do this once per domain
   89.14           * XXX todo: add a seperate function to do these.
   89.15 @@ -96,6 +101,10 @@ void vmx_relinquish_resources(struct vcp
   89.16      destroy_vmcs(&v->arch.arch_vmx);
   89.17      free_monitor_pagetable(v);
   89.18      rem_ac_timer(&v->domain->arch.vmx_platform.vmx_pit.pit_timer);
   89.19 +    if ( vmx_apic_support(v->domain) ) {
   89.20 +        rem_ac_timer( &(VLAPIC(v)->vlapic_timer) );
   89.21 +        xfree( VLAPIC(v) );
   89.22 +    }
   89.23  }
   89.24  
   89.25  #ifdef __x86_64__
   89.26 @@ -442,7 +451,9 @@ static int vmx_do_page_fault(unsigned lo
   89.27  
   89.28      /* Use 1:1 page table to identify MMIO address space */
   89.29      if ( mmio_space(gpa) ){
   89.30 -        if (gpa >= 0xFEE00000) { /* workaround for local APIC */
   89.31 +        struct vcpu *v = current;
   89.32 +        /* No support for APIC */
   89.33 +        if (!vmx_apic_support(v->domain) && gpa >= 0xFEC00000) { 
   89.34              u32 inst_len;
   89.35              __vmread(VM_EXIT_INSTRUCTION_LEN, &(inst_len));
   89.36              __update_guest_eip(inst_len);
   89.37 @@ -487,6 +498,7 @@ static void vmx_vmexit_do_cpuid(unsigned
   89.38  {
   89.39      unsigned int eax, ebx, ecx, edx;
   89.40      unsigned long eip;
   89.41 +    struct vcpu *v = current;
   89.42  
   89.43      __vmread(GUEST_RIP, &eip);
   89.44  
   89.45 @@ -500,6 +512,9 @@ static void vmx_vmexit_do_cpuid(unsigned
   89.46      cpuid(input, &eax, &ebx, &ecx, &edx);
   89.47  
   89.48      if (input == 1) {
   89.49 +        if ( vmx_apic_support(v->domain) &&
   89.50 +                !vlapic_global_enabled((VLAPIC(v))) )
   89.51 +            clear_bit(X86_FEATURE_APIC, &edx);
   89.52  #ifdef __i386__
   89.53          clear_bit(X86_FEATURE_PSE, &edx);
   89.54          clear_bit(X86_FEATURE_PAE, &edx);
   89.55 @@ -1441,6 +1456,7 @@ static int vmx_cr_access(unsigned long e
   89.56  static inline void vmx_do_msr_read(struct cpu_user_regs *regs)
   89.57  {
   89.58      u64 msr_content = 0;
   89.59 +    struct vcpu *v = current;
   89.60  
   89.61      VMX_DBG_LOG(DBG_LEVEL_1, "vmx_do_msr_read: ecx=%lx, eax=%lx, edx=%lx",
   89.62                  (unsigned long)regs->ecx, (unsigned long)regs->eax,
   89.63 @@ -1455,6 +1471,9 @@ static inline void vmx_do_msr_read(struc
   89.64      case MSR_IA32_SYSENTER_EIP:
   89.65          __vmread(GUEST_SYSENTER_EIP, &msr_content);
   89.66          break;
   89.67 +    case MSR_IA32_APICBASE:
   89.68 +        msr_content = VLAPIC(v) ? VLAPIC(v)->apic_base_msr : 0;
   89.69 +        break;
   89.70      default:
   89.71          if(long_mode_do_msr_read(regs))
   89.72              return;
   89.73 @@ -1474,6 +1493,7 @@ static inline void vmx_do_msr_read(struc
   89.74  static inline void vmx_do_msr_write(struct cpu_user_regs *regs)
   89.75  {
   89.76      u64 msr_content;
   89.77 +    struct vcpu *v = current;
   89.78  
   89.79      VMX_DBG_LOG(DBG_LEVEL_1, "vmx_do_msr_write: ecx=%lx, eax=%lx, edx=%lx",
   89.80                  (unsigned long)regs->ecx, (unsigned long)regs->eax,
   89.81 @@ -1491,6 +1511,9 @@ static inline void vmx_do_msr_write(stru
   89.82      case MSR_IA32_SYSENTER_EIP:
   89.83          __vmwrite(GUEST_SYSENTER_EIP, msr_content);
   89.84          break;
   89.85 +    case MSR_IA32_APICBASE:
   89.86 +        vlapic_msr_set(VLAPIC(v), msr_content);
   89.87 +        break;
   89.88      default:
   89.89          long_mode_do_msr_write(regs);
   89.90          break;
    90.1 --- a/xen/arch/x86/vmx_intercept.c	Sun Oct 30 13:52:38 2005 +0100
    90.2 +++ b/xen/arch/x86/vmx_intercept.c	Sun Oct 30 14:00:35 2005 +0100
    90.3 @@ -23,6 +23,7 @@
    90.4  #include <asm/vmx_platform.h>
    90.5  #include <asm/vmx_virpit.h>
    90.6  #include <asm/vmx_intercept.h>
    90.7 +#include <asm/vmx_vlapic.h>
    90.8  #include <public/io/ioreq.h>
    90.9  #include <xen/lib.h>
   90.10  #include <xen/sched.h>
   90.11 @@ -32,6 +33,123 @@
   90.12  
   90.13  #ifdef CONFIG_VMX
   90.14  
   90.15 +struct vmx_mmio_handler vmx_mmio_handers[VMX_MMIO_HANDLER_NR] =
   90.16 +{
   90.17 +    {
   90.18 +        .check_handler = vlapic_range,
   90.19 +        .read_handler  = vlapic_read,
   90.20 +        .write_handler = vlapic_write
   90.21 +    }
   90.22 +};
   90.23 +
   90.24 +static inline void vmx_mmio_access(struct vcpu *v,
   90.25 +                                   ioreq_t *p,
   90.26 +                                   vmx_mmio_read_t read_handler,
   90.27 +                                   vmx_mmio_write_t write_handler)
   90.28 +{
   90.29 +    ioreq_t *req;
   90.30 +    vcpu_iodata_t *vio = get_vio(v->domain, v->vcpu_id);
   90.31 +    unsigned int tmp1, tmp2;
   90.32 +    unsigned long data;
   90.33 +
   90.34 +    if (vio == NULL) {
   90.35 +        printk("vlapic_access: bad shared page\n");
   90.36 +        domain_crash_synchronous();
   90.37 +    }
   90.38 +
   90.39 +    req = &vio->vp_ioreq;
   90.40 +
   90.41 +    switch (req->type) {
   90.42 +    case IOREQ_TYPE_COPY:
   90.43 +    {
   90.44 +        int sign = (req->df) ? -1 : 1, i;
   90.45 +
   90.46 +        if (!req->pdata_valid) {
   90.47 +            if (req->dir == IOREQ_READ){
   90.48 +                req->u.data = read_handler(v, req->addr, req->size);
   90.49 +            } else {                 /* req->dir != IOREQ_READ */
   90.50 +                write_handler(v, req->addr, req->size, req->u.data);
   90.51 +            }
   90.52 +        } else {                     /* !req->pdata_valid */
   90.53 +            if (req->dir == IOREQ_READ) {
   90.54 +                for (i = 0; i < req->count; i++) {
   90.55 +                    data = read_handler(v,
   90.56 +                      req->addr + (sign * i * req->size),
   90.57 +                      req->size);
   90.58 +                    vmx_copy(&data,
   90.59 +                      (unsigned long)p->u.pdata + (sign * i * req->size),
   90.60 +                      p->size,
   90.61 +                      VMX_COPY_OUT);
   90.62 +                }
   90.63 +            } else {                  /* !req->dir == IOREQ_READ */
   90.64 +                for (i = 0; i < req->count; i++) {
   90.65 +                    vmx_copy(&data,
   90.66 +                      (unsigned long)p->u.pdata + (sign * i * req->size),
   90.67 +                      p->size,
   90.68 +                      VMX_COPY_IN);
   90.69 +                    write_handler(v,
   90.70 +                      req->addr + (sign * i * req->size),
   90.71 +                      req->size, data);
   90.72 +                }
   90.73 +            }
   90.74 +        }
   90.75 +        break;
   90.76 +    }
   90.77 +
   90.78 +    case IOREQ_TYPE_AND:
   90.79 +        tmp1 = read_handler(v, req->addr, req->size);
   90.80 +        if (req->dir == IOREQ_WRITE) {
   90.81 +            tmp2 = tmp1 & (unsigned long) req->u.data;
   90.82 +            write_handler(v, req->addr, req->size, tmp2);
   90.83 +        }
   90.84 +        req->u.data = tmp1;
   90.85 +        break;
   90.86 +
   90.87 +    case IOREQ_TYPE_OR:
   90.88 +        tmp1 = read_handler(v, req->addr, req->size);
   90.89 +        if (req->dir == IOREQ_WRITE) {
   90.90 +            tmp2 = tmp1 | (unsigned long) req->u.data;
   90.91 +            write_handler(v, req->addr, req->size, tmp2);
   90.92 +        }
   90.93 +        req->u.data = tmp1;
   90.94 +        break;
   90.95 +
   90.96 +    case IOREQ_TYPE_XOR:
   90.97 +        tmp1 = read_handler(v, req->addr, req->size);
   90.98 +        if (req->dir == IOREQ_WRITE) {
   90.99 +            tmp2 = tmp1 ^ (unsigned long) req->u.data;
  90.100 +            write_handler(v, req->addr, req->size, tmp2);
  90.101 +        }
  90.102 +        req->u.data = tmp1;
  90.103 +        break;
  90.104 +
  90.105 +    default:
  90.106 +        printk("error ioreq type for local APIC %x\n", req->type);
  90.107 +        domain_crash_synchronous();
  90.108 +        break;
  90.109 +    }
  90.110 +}
  90.111 +
  90.112 +int vmx_mmio_intercept(ioreq_t *p)
  90.113 +{
  90.114 +    struct vcpu *v = current;
  90.115 +    int i;
  90.116 +    struct vmx_mmio_handler *handler = vmx_mmio_handers;
  90.117 +
  90.118 +    /* XXX currently only APIC use intercept */
  90.119 +    if ( !vmx_apic_support(v->domain) )
  90.120 +        return 0;
  90.121 +
  90.122 +    for ( i = 0; i < VMX_MMIO_HANDLER_NR; i++ ) {
  90.123 +        if ( handler[i].check_handler(v, p->addr) ) {
  90.124 +            vmx_mmio_access(v, p,
  90.125 +              handler[i].read_handler, handler[i].write_handler);
  90.126 +            return 1;
  90.127 +        }
  90.128 +    }
  90.129 +    return 0;
  90.130 +}
  90.131 +
  90.132  /*
  90.133   * Check if the request is handled inside xen
  90.134   * return value: 0 --not handled; 1 --handled
    91.1 --- a/xen/arch/x86/vmx_io.c	Sun Oct 30 13:52:38 2005 +0100
    91.2 +++ b/xen/arch/x86/vmx_io.c	Sun Oct 30 14:00:35 2005 +0100
    91.3 @@ -36,9 +36,9 @@
    91.4  #include <asm/apic.h>
    91.5  #include <asm/shadow.h>
    91.6  
    91.7 +#include <asm/vmx_vlapic.h>
    91.8  #include <public/io/ioreq.h>
    91.9  #include <public/io/vmx_vpic.h>
   91.10 -#include <public/io/vmx_vlapic.h>
   91.11  
   91.12  #ifdef CONFIG_VMX
   91.13  #if defined (__i386__)
   91.14 @@ -732,48 +732,6 @@ void vmx_wait_io()
   91.15      } while(1);
   91.16  }
   91.17  
   91.18 -#if defined(__i386__) || defined(__x86_64__)
   91.19 -static inline int __fls(u32 word)
   91.20 -{
   91.21 -    int bit;
   91.22 -
   91.23 -    __asm__("bsrl %1,%0"
   91.24 -            :"=r" (bit)
   91.25 -            :"rm" (word));
   91.26 -    return word ? bit : -1;
   91.27 -}
   91.28 -#else
   91.29 -#define __fls(x)  generic_fls(x)
   91.30 -static __inline__ int generic_fls(u32 x)
   91.31 -{
   91.32 -    int r = 31;
   91.33 -
   91.34 -    if (!x)
   91.35 -        return -1;
   91.36 -    if (!(x & 0xffff0000u)) {
   91.37 -        x <<= 16;
   91.38 -        r -= 16;
   91.39 -    }
   91.40 -    if (!(x & 0xff000000u)) {
   91.41 -        x <<= 8;
   91.42 -        r -= 8;
   91.43 -    }
   91.44 -    if (!(x & 0xf0000000u)) {
   91.45 -        x <<= 4;
   91.46 -        r -= 4;
   91.47 -    }
   91.48 -    if (!(x & 0xc0000000u)) {
   91.49 -        x <<= 2;
   91.50 -        r -= 2;
   91.51 -    }
   91.52 -    if (!(x & 0x80000000u)) {
   91.53 -        x <<= 1;
   91.54 -        r -= 1;
   91.55 -    }
   91.56 -    return r;
   91.57 -}
   91.58 -#endif
   91.59 -
   91.60  /* Simple minded Local APIC priority implementation. Fix later */
   91.61  static __inline__ int find_highest_irq(u32 *pintr)
   91.62  {
   91.63 @@ -801,31 +759,31 @@ interrupt_post_injection(struct vcpu * v
   91.64      struct vmx_virpit *vpit = &(v->domain->arch.vmx_platform.vmx_pit);
   91.65      u64    drift;
   91.66  
   91.67 +    if ( is_pit_irq(v, vector, type) ) {
   91.68 +        if ( !vpit->first_injected ) {
   91.69 +            vpit->first_injected = 1;
   91.70 +            vpit->pending_intr_nr = 0;
   91.71 +        } else {
   91.72 +            vpit->pending_intr_nr--;
   91.73 +        }
   91.74 +        vpit->inject_point = NOW();
   91.75 +        drift = vpit->period_cycles * vpit->pending_intr_nr;
   91.76 +        drift = v->arch.arch_vmx.tsc_offset - drift;
   91.77 +        __vmwrite(TSC_OFFSET, drift);
   91.78 +
   91.79 +#if defined (__i386__)
   91.80 +        __vmwrite(TSC_OFFSET_HIGH, (drift >> 32));
   91.81 +#endif
   91.82 +
   91.83 +    }
   91.84 +
   91.85      switch(type)
   91.86      {
   91.87      case VLAPIC_DELIV_MODE_EXT:
   91.88 -        if ( is_pit_irq(v, vector) ) {
   91.89 -            if ( !vpit->first_injected ) {
   91.90 -                vpit->first_injected = 1;
   91.91 -                vpit->pending_intr_nr = 0;
   91.92 -            }
   91.93 -            else {
   91.94 -                vpit->pending_intr_nr--;
   91.95 -            }
   91.96 -            vpit->inject_point = NOW();
   91.97 -            drift = vpit->period_cycles * vpit->pending_intr_nr;
   91.98 -            drift = v->arch.arch_vmx.tsc_offset - drift;
   91.99 -            __vmwrite(TSC_OFFSET, drift);
  91.100 -
  91.101 -#if defined (__i386__)
  91.102 -            __vmwrite(TSC_OFFSET_HIGH, (drift >> 32));
  91.103 -#endif
  91.104 - 
  91.105 -        }
  91.106          break;
  91.107  
  91.108      default:
  91.109 -        printk("Not support interrupt type\n");
  91.110 +        vlapic_post_injection(v, vector, type);
  91.111          break;
  91.112      }
  91.113  }
  91.114 @@ -885,6 +843,24 @@ void vmx_pic_assist(struct vcpu *v)
  91.115  
  91.116  }
  91.117  
  91.118 +int cpu_get_interrupt(struct vcpu *v, int *type)
  91.119 +{
  91.120 +    int intno;
  91.121 +    struct vmx_virpic *s = &v->domain->arch.vmx_platform.vmx_pic;
  91.122 +
  91.123 +    if ( (intno = cpu_get_apic_interrupt(v, type)) != -1 ) {
  91.124 +        /* set irq request if a PIC irq is still pending */
  91.125 +        /* XXX: improve that */
  91.126 +        pic_update_irq(s);
  91.127 +        return intno;
  91.128 +    }
  91.129 +    /* read the irq from the PIC */
  91.130 +    if ( (intno = cpu_get_pic_interrupt(v, type)) != -1 )
  91.131 +        return intno;
  91.132 +
  91.133 +    return -1;
  91.134 +}
  91.135 +
  91.136  asmlinkage void vmx_intr_assist(void)
  91.137  {
  91.138      int intr_type = 0;
  91.139 @@ -902,11 +878,6 @@ asmlinkage void vmx_intr_assist(void)
  91.140          pic_set_irq(pic, 0, 1);
  91.141      }
  91.142  
  91.143 -    if ( !plat->interrupt_request ) {
  91.144 -        disable_irq_window(cpu_exec_control);
  91.145 -        return;
  91.146 -    }
  91.147 -
  91.148      __vmread(VM_ENTRY_INTR_INFO_FIELD, &intr_fields);
  91.149  
  91.150      if (intr_fields & INTR_INFO_VALID_MASK) {
  91.151 @@ -928,16 +899,21 @@ asmlinkage void vmx_intr_assist(void)
  91.152          enable_irq_window(cpu_exec_control);
  91.153          return;
  91.154      }
  91.155 -    plat->interrupt_request = 0;
  91.156 -    highest_vector = cpu_get_pic_interrupt(v, &intr_type); 
  91.157 +
  91.158 +    highest_vector = cpu_get_interrupt(v, &intr_type); 
  91.159 +
  91.160 +    if (highest_vector == -1) {
  91.161 +        disable_irq_window(cpu_exec_control);
  91.162 +        return;
  91.163 +    }
  91.164  
  91.165      switch (intr_type) {
  91.166      case VLAPIC_DELIV_MODE_EXT:
  91.167 +    case VLAPIC_DELIV_MODE_FIXED:
  91.168 +    case VLAPIC_DELIV_MODE_LPRI:
  91.169          vmx_inject_extint(v, highest_vector, VMX_INVALID_ERROR_CODE);
  91.170          TRACE_3D(TRC_VMX_INT, v->domain->domain_id, highest_vector, 0);
  91.171          break;
  91.172 -    case VLAPIC_DELIV_MODE_FIXED:
  91.173 -    case VLAPIC_DELIV_MODE_LPRI:
  91.174      case VLAPIC_DELIV_MODE_SMI:
  91.175      case VLAPIC_DELIV_MODE_NMI:
  91.176      case VLAPIC_DELIV_MODE_INIT:
    92.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    92.2 +++ b/xen/arch/x86/vmx_vlapic.c	Sun Oct 30 14:00:35 2005 +0100
    92.3 @@ -0,0 +1,997 @@
    92.4 +/*
    92.5 + * vmx_vlapic.c: virtualize LAPIC for VMX vcpus.
    92.6 + * Copyright (c) 2004, Intel Corporation.
    92.7 + *
    92.8 + * This program is free software; you can redistribute it and/or modify it
    92.9 + * under the terms and conditions of the GNU General Public License,
   92.10 + * version 2, as published by the Free Software Foundation.
   92.11 + *
   92.12 + * This program is distributed in the hope it will be useful, but WITHOUT
   92.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   92.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
   92.15 + * more details.
   92.16 + *
   92.17 + * You should have received a copy of the GNU General Public License along with
   92.18 + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
   92.19 + * Place - Suite 330, Boston, MA 02111-1307 USA.
   92.20 + *
   92.21 + */
   92.22 +
   92.23 +#include <xen/config.h>
   92.24 +#include <xen/types.h>
   92.25 +#include <xen/mm.h>
   92.26 +#include <xen/xmalloc.h>
   92.27 +#include <asm/shadow.h>
   92.28 +#include <asm/page.h>
   92.29 +#include <xen/event.h>
   92.30 +#include <xen/trace.h>
   92.31 +#include <asm/vmx.h>
   92.32 +#include <asm/vmx_platform.h>
   92.33 +#include <asm/vmx_vlapic.h>
   92.34 +
   92.35 +#include <xen/lib.h>
   92.36 +#include <xen/sched.h>
   92.37 +#include <asm/current.h>
   92.38 +#include <public/io/ioreq.h>
   92.39 +
   92.40 +#ifdef CONFIG_VMX
   92.41 +
   92.42 +/* XXX remove this definition after GFW enabled */
   92.43 +#define VLAPIC_NO_BIOS
   92.44 +
   92.45 +extern unsigned int get_apic_bus_scale(void);
   92.46 +
   92.47 +static unsigned int vlapic_lvt_mask[VLAPIC_LVT_NUM] =
   92.48 +{
   92.49 +    0x310ff, 0x117ff, 0x117ff, 0x1f7ff, 0x1f7ff, 0x117ff
   92.50 +};
   92.51 +
   92.52 +int vlapic_find_highest_irr(struct vlapic *vlapic)
   92.53 +{
   92.54 +    int result;
   92.55 +
   92.56 +    result = find_highest_bit((uint32_t *)&vlapic->irr[0], INTR_LEN_32);
   92.57 +
   92.58 +    if (result != -1 && result < 16) {
   92.59 +        printk("VLAPIC: irr on reserved bits %d\n ", result);
   92.60 +        domain_crash_synchronous();
   92.61 +    }
   92.62 +
   92.63 +    return result;
   92.64 +}
   92.65 +
   92.66 +inline int vmx_apic_support(struct domain *d)
   92.67 +{
   92.68 +    return d->arch.vmx_platform.lapic_enable;
   92.69 +}
   92.70 +
   92.71 +int vlapic_find_highest_isr(struct vlapic *vlapic)
   92.72 +{
   92.73 +    int result;
   92.74 +
   92.75 +    result = find_highest_bit((uint32_t *)&vlapic->isr[0], INTR_LEN_32);
   92.76 +
   92.77 +    if (result != -1 && result < 16) {
   92.78 +        int i = 0;
   92.79 +        printk("VLAPIC: isr on reserved bits %d, isr is\n ", result);
   92.80 +        for (i = 0; i < INTR_LEN_32; i += 2)
   92.81 +            printk("%d: 0x%08x%08x\n", i, vlapic->isr[i], vlapic->isr[i+1]);
   92.82 +        return -1;
   92.83 +    }
   92.84 +
   92.85 +    return result;
   92.86 +}
   92.87 +
   92.88 +uint32_t vlapic_update_ppr(struct vlapic *vlapic)
   92.89 +{
   92.90 +    uint32_t tpr, isrv, ppr;
   92.91 +    int isr;
   92.92 +
   92.93 +    tpr = (vlapic->task_priority >> 4) & 0xf;      /* we want 7:4 */
   92.94 +
   92.95 +    isr = vlapic_find_highest_isr(vlapic);
   92.96 +    if (isr != -1)
   92.97 +        isrv = (isr >> 4) & 0xf;   /* ditto */
   92.98 +    else
   92.99 +        isrv = 0;
  92.100 +
  92.101 +    if (tpr >= isrv)
  92.102 +        ppr = vlapic->task_priority & 0xff;
  92.103 +    else
  92.104 +        ppr = isrv << 4;  /* low 4 bits of PPR have to be cleared */
  92.105 +
  92.106 +    vlapic->processor_priority = ppr;
  92.107 +
  92.108 +    VMX_DBG_LOG(DBG_LEVEL_VLAPIC_INTERRUPT,
  92.109 +                "vlapic_update_ppr: vlapic %p ppr %x isr %x isrv %x",
  92.110 +                vlapic, ppr, isr, isrv);
  92.111 +
  92.112 +    return ppr;
  92.113 +}
  92.114 +
  92.115 +/* This only for fixed delivery mode */
  92.116 +int vlapic_match_dest(struct vlapic *target, struct vlapic *source,
  92.117 +                      int short_hand, int dest, int dest_mode,
  92.118 +                      int delivery_mode)
  92.119 +{
  92.120 +    int result = 0;
  92.121 +
  92.122 +    VMX_DBG_LOG(DBG_LEVEL_VLAPIC, "vlapic_match_dest: "
  92.123 +                "target %p source %p dest %x dest_mode %x short_hand %x "
  92.124 +                "delivery_mode %x",
  92.125 +                target, source, dest, dest_mode, short_hand, delivery_mode);
  92.126 +
  92.127 +    switch (short_hand) {
  92.128 +    case VLAPIC_NO_SHORTHAND:
  92.129 +        if (!dest_mode) {   /* Physical */
  92.130 +            result = (target->id == dest);
  92.131 +        } else {            /* Logical */
  92.132 +            if (((target->dest_format >> 28) & 0xf) == 0xf) {   /* Flat mode */
  92.133 +                result = (target->logical_dest >> 24) & dest;
  92.134 +            } else {
  92.135 +                if ((delivery_mode == VLAPIC_DELIV_MODE_LPRI) &&
  92.136 +                   (dest == 0xff)) {
  92.137 +                    /* What shall we do now? */
  92.138 +                    printk("Broadcast IPI with lowest priority "
  92.139 +                           "delivery mode\n");
  92.140 +                    domain_crash_synchronous();
  92.141 +                }
  92.142 +                result = (target->logical_dest == (dest & 0xf)) ?
  92.143 +                  ((target->logical_dest >> 4) & (dest >> 4)) : 0;
  92.144 +            }
  92.145 +        }
  92.146 +        break;
  92.147 +
  92.148 +    case VLAPIC_SHORTHAND_SELF:
  92.149 +        if (target == source)
  92.150 +            result = 1;
  92.151 +        break;
  92.152 +
  92.153 +    case VLAPIC_SHORTHAND_INCLUDE_SELF:
  92.154 +        result = 1;
  92.155 +        break;
  92.156 +
  92.157 +    case VLAPIC_SHORTHAND_EXCLUDE_SELF:
  92.158 +        if (target != source)
  92.159 +            result = 1;
  92.160 +        break;
  92.161 +
  92.162 +    default:
  92.163 +        break;
  92.164 +    }
  92.165 +
  92.166 +    return result;
  92.167 +}
  92.168 +
  92.169 +/*
  92.170 + * Add a pending IRQ into lapic.
  92.171 + * Return 1 if successfully added and 0 if discarded.
  92.172 + */
  92.173 +int vlapic_accept_irq(struct vlapic *vlapic, int delivery_mode,
  92.174 +                      int vector, int level, int trig_mode)
  92.175 +{
  92.176 +    int	result = 1;
  92.177 +
  92.178 +    switch (delivery_mode) {
  92.179 +    case VLAPIC_DELIV_MODE_FIXED:
  92.180 +    case VLAPIC_DELIV_MODE_LPRI:
  92.181 +        /* FIXME add logic for vcpu on reset */
  92.182 +        if (!vlapic->vcpu || !vlapic_enabled(vlapic))
  92.183 +            return 0;
  92.184 +
  92.185 +        if (test_and_set_bit(vector, &vlapic->irr[0])) {
  92.186 +            printk("<vlapic_accept_irq>"
  92.187 +                    "level trig mode repeatedly for vector %d\n", vector);
  92.188 +            result = 0;
  92.189 +        } else {
  92.190 +            if (level) {
  92.191 +                printk("<vlapic_accept_irq> level trig mode for vector %d\n", vector);
  92.192 +                set_bit(vector, &vlapic->tmr[0]);
  92.193 +            }
  92.194 +        }
  92.195 +        evtchn_set_pending(vlapic->vcpu, iopacket_port(vlapic->domain));
  92.196 +        break;
  92.197 +
  92.198 +    case VLAPIC_DELIV_MODE_RESERVED:
  92.199 +        printk("Ignore deliver mode 3 in vlapic_accept_irq\n");
  92.200 +        break;
  92.201 +
  92.202 +    case VLAPIC_DELIV_MODE_SMI:
  92.203 +    case VLAPIC_DELIV_MODE_NMI:
  92.204 +        /* Fixme */
  92.205 +        printk("TODO: for guest SMI/NMI\n");
  92.206 +        break;
  92.207 +
  92.208 +    case VLAPIC_DELIV_MODE_INIT:
  92.209 +        if (!level && trig_mode == 1) {        //Deassert
  92.210 +            printk("This vmx_vlapic is for P4, no work for De-assert init\n");
  92.211 +        } else {
  92.212 +            /* FIXME How to check the situation after vcpu reset? */
  92.213 +            vlapic->init_sipi_sipi_state = VLAPIC_INIT_SIPI_SIPI_STATE_WAIT_SIPI;
  92.214 +            if (vlapic->vcpu) {
  92.215 +                vcpu_pause(vlapic->vcpu);
  92.216 +            }
  92.217 +        }
  92.218 +        break;
  92.219 +
  92.220 +    case VLAPIC_DELIV_MODE_STARTUP:
  92.221 +        if (vlapic->init_sipi_sipi_state != VLAPIC_INIT_SIPI_SIPI_STATE_WAIT_SIPI)
  92.222 +            break;
  92.223 +        vlapic->init_sipi_sipi_state = VLAPIC_INIT_SIPI_SIPI_STATE_NORM;
  92.224 +        if (!vlapic->vcpu) {
  92.225 +            /* XXX Call vmx_bringup_ap here */
  92.226 +             result = 0;
  92.227 +        }else{
  92.228 +            //vmx_vcpu_reset(vlapic->vcpu);
  92.229 +        }
  92.230 +        break;
  92.231 +
  92.232 +    default:
  92.233 +        printk("TODO: not support interrup type %x\n", delivery_mode);
  92.234 +        domain_crash_synchronous();
  92.235 +        break;
  92.236 +    }
  92.237 +
  92.238 +    return result;
  92.239 +}
  92.240 +/*
  92.241 +    This function is used by both ioapic and local APIC
  92.242 +    The bitmap is for vcpu_id
  92.243 + */
  92.244 +struct vlapic* apic_round_robin(struct domain *d,
  92.245 +                                uint8_t dest_mode,
  92.246 +                                uint8_t vector,
  92.247 +                                uint32_t bitmap)
  92.248 +{
  92.249 +    int next, old;
  92.250 +    struct vlapic* target = NULL;
  92.251 +
  92.252 +    if (dest_mode == 0) { //Physical mode
  92.253 +        printk("<apic_round_robin> lowest priority for physical mode\n");
  92.254 +        return NULL;
  92.255 +    }
  92.256 +
  92.257 +    if (!bitmap) {
  92.258 +        printk("<apic_round_robin> no bit on bitmap\n");
  92.259 +        return NULL;
  92.260 +    }
  92.261 +
  92.262 +    spin_lock(&d->arch.vmx_platform.round_robin_lock);
  92.263 +
  92.264 +    old = next = d->arch.vmx_platform.round_info[vector];
  92.265 +
  92.266 +    next++;
  92.267 +    if (next == MAX_VIRT_CPUS || !d->vcpu[next])
  92.268 +        next = 0;
  92.269 +
  92.270 +    do {
  92.271 +        /* the vcpu array is arranged according to vcpu_id */
  92.272 +        if (test_bit(next, &bitmap)) {
  92.273 +            target = d->vcpu[next]->arch.arch_vmx.vlapic;
  92.274 +            if (!vlapic_enabled(target)) {
  92.275 +                printk("warning: targe round robin local apic disabled\n");
  92.276 +                /* XXX should we domain crash?? Or should we return NULL */
  92.277 +            }
  92.278 +            break;
  92.279 +        }
  92.280 +
  92.281 +        next ++;
  92.282 +        if (next == MAX_VIRT_CPUS || !d->vcpu[next])
  92.283 +            next = 0;
  92.284 +    }while(next != old);
  92.285 +
  92.286 +    d->arch.vmx_platform.round_info[vector] = next;
  92.287 +    spin_unlock(&d->arch.vmx_platform.round_robin_lock);
  92.288 +    return target;
  92.289 +}
  92.290 +
  92.291 +void
  92.292 +vlapic_EOI_set(struct vlapic *vlapic)
  92.293 +{
  92.294 +    int vector = vlapic_find_highest_isr(vlapic);
  92.295 +
  92.296 +    /* Not every write EOI will has correpsoning ISR,
  92.297 +       one example is when Kernel check timer on setup_IO_APIC */
  92.298 +    if (vector == -1) {
  92.299 +        return ;
  92.300 +    }
  92.301 +
  92.302 +    vlapic_clear_isr(vlapic, vector);
  92.303 +    vlapic_update_ppr(vlapic);
  92.304 +}
  92.305 +
  92.306 +int vlapic_check_vector(struct vlapic *vlapic,
  92.307 +                        unsigned char dm, int vector)
  92.308 +{
  92.309 +    if ((dm == VLAPIC_DELIV_MODE_FIXED) && (vector < 16)) {
  92.310 +        vlapic->err_status |= 0x40;
  92.311 +        vlapic_accept_irq(vlapic, VLAPIC_DELIV_MODE_FIXED,
  92.312 +          vlapic_lvt_vector(vlapic, VLAPIC_LVT_ERROR), 0, 0);
  92.313 +        printk("<vlapic_check_vector>: check fail\n");
  92.314 +        return 0;
  92.315 +    }
  92.316 +    return 1;
  92.317 +}
  92.318 +
  92.319 +
  92.320 +void vlapic_ipi(struct vlapic *vlapic)
  92.321 +{
  92.322 +    unsigned int dest = (vlapic->icr_high >> 24) & 0xff;
  92.323 +    unsigned int short_hand = (vlapic->icr_low >> 18) & 3;
  92.324 +    unsigned int trig_mode = (vlapic->icr_low >> 15) & 1;
  92.325 +    unsigned int level = (vlapic->icr_low >> 14) & 1;
  92.326 +    unsigned int dest_mode = (vlapic->icr_low >> 11) & 1;
  92.327 +    unsigned int delivery_mode = (vlapic->icr_low >> 8) & 7;
  92.328 +    unsigned int vector = (vlapic->icr_low & 0xff);
  92.329 +
  92.330 +    struct vlapic *target;
  92.331 +    struct vcpu *v = NULL;
  92.332 +    int result = 0;
  92.333 +    uint32_t lpr_map;
  92.334 +
  92.335 +    VMX_DBG_LOG(DBG_LEVEL_VLAPIC, "vlapic_ipi: "
  92.336 +                "icr_high %x icr_low %x "
  92.337 +                "short_hand %x dest %x trig_mode %x level %x "
  92.338 +                "dest_mode %x delivery_mode %x vector %x",
  92.339 +                vlapic->icr_high, vlapic->icr_low,
  92.340 +                short_hand, dest, trig_mode, level, dest_mode,
  92.341 +                delivery_mode, vector);
  92.342 +
  92.343 +    for_each_vcpu ( vlapic->domain, v ) {
  92.344 +        target = VLAPIC(v);
  92.345 +        if (vlapic_match_dest(target, vlapic, short_hand,
  92.346 +                              dest, dest_mode, delivery_mode)) {
  92.347 +            if (delivery_mode == VLAPIC_DELIV_MODE_LPRI) {
  92.348 +                set_bit(v->vcpu_id, &lpr_map);
  92.349 +            }else
  92.350 +                result = vlapic_accept_irq(target, delivery_mode,
  92.351 +                  vector, level, trig_mode);
  92.352 +        }
  92.353 +    }
  92.354 +
  92.355 +    if (delivery_mode == VLAPIC_DELIV_MODE_LPRI) {
  92.356 +        extern struct vlapic*
  92.357 +          apic_round_robin(struct domain *d,
  92.358 +            uint8_t dest_mode, uint8_t vector, uint32_t bitmap);
  92.359 +
  92.360 +        v = vlapic->vcpu;
  92.361 +        target = apic_round_robin(v->domain, dest_mode, vector, lpr_map);
  92.362 +
  92.363 +        if (target)
  92.364 +            vlapic_accept_irq(target, delivery_mode,
  92.365 +              vector, level, trig_mode);
  92.366 +    }
  92.367 +}
  92.368 +
  92.369 +void vlapic_begin_timer(struct vlapic *vlapic)
  92.370 +{
  92.371 +    s_time_t cur = NOW(), offset;
  92.372 +
  92.373 +    offset = vlapic->timer_current *
  92.374 +      (262144 / get_apic_bus_scale()) * vlapic->timer_divide_counter;
  92.375 +    vlapic->vlapic_timer.expires = cur + offset;
  92.376 +
  92.377 +    set_ac_timer(&(vlapic->vlapic_timer), vlapic->vlapic_timer.expires );
  92.378 +
  92.379 +    VMX_DBG_LOG(DBG_LEVEL_VLAPIC, "vlapic_begin_timer: "
  92.380 +                "bus_scale %x now %08x%08x expire %08x%08x "
  92.381 +                "offset %08x%08x current %x",
  92.382 +                get_apic_bus_scale(), (uint32_t)(cur >> 32), (uint32_t)cur,
  92.383 +                (uint32_t)(vlapic->vlapic_timer.expires >> 32),
  92.384 +                (uint32_t) vlapic->vlapic_timer.expires,
  92.385 +                (uint32_t)(offset >> 32), (uint32_t)offset,
  92.386 +                vlapic->timer_current);
  92.387 +}
  92.388 +
  92.389 +void vlapic_read_aligned(struct vlapic *vlapic, unsigned int offset,
  92.390 +                         unsigned int len, unsigned int *result)
  92.391 +{
  92.392 +    if (len != 4) {
  92.393 +        VMX_DBG_LOG(DBG_LEVEL_VLAPIC,
  92.394 +                    "local apic read with len=%d (should be 4)", len);
  92.395 +    }
  92.396 +
  92.397 +    *result = 0;
  92.398 +
  92.399 +    switch (offset) {
  92.400 +    case APIC_ID:
  92.401 +        *result = (vlapic->id) << 24;
  92.402 +        break;
  92.403 +
  92.404 +    case APIC_LVR:
  92.405 +        *result = vlapic->version;
  92.406 +        break;
  92.407 +
  92.408 +    case APIC_TASKPRI:
  92.409 +        *result = vlapic->task_priority;
  92.410 +        break;
  92.411 +
  92.412 +    case APIC_ARBPRI:
  92.413 +        printk("Access local APIC ARBPRI register which is for P6\n");
  92.414 +        break;
  92.415 +
  92.416 +    case APIC_PROCPRI:
  92.417 +        *result = vlapic->processor_priority;
  92.418 +        break;
  92.419 +
  92.420 +    case APIC_EOI:      /* EOI is write only */
  92.421 +        break;
  92.422 +
  92.423 +    case APIC_LDR:
  92.424 +        *result = vlapic->logical_dest;
  92.425 +        break;
  92.426 +
  92.427 +    case APIC_DFR:
  92.428 +        *result = vlapic->dest_format;
  92.429 +        break;
  92.430 +
  92.431 +    case APIC_SPIV:
  92.432 +        *result = vlapic->spurious_vec;
  92.433 +        break;
  92.434 +
  92.435 +    case APIC_ISR:
  92.436 +    case 0x110:
  92.437 +    case 0x120:
  92.438 +    case 0x130:
  92.439 +    case 0x140:
  92.440 +    case 0x150:
  92.441 +    case 0x160:
  92.442 +    case 0x170:
  92.443 +        *result = vlapic->isr[(offset - APIC_ISR) >> 4];
  92.444 +        break;
  92.445 +
  92.446 +    case APIC_TMR:
  92.447 +    case 0x190:
  92.448 +    case 0x1a0:
  92.449 +    case 0x1b0:
  92.450 +    case 0x1c0:
  92.451 +    case 0x1d0:
  92.452 +    case 0x1e0:
  92.453 +    case 0x1f0:
  92.454 +        *result = vlapic->tmr[(offset - APIC_TMR) >> 4];
  92.455 +        break;
  92.456 +
  92.457 +    case APIC_IRR:
  92.458 +    case 0x210:
  92.459 +    case 0x220:
  92.460 +    case 0x230:
  92.461 +    case 0x240:
  92.462 +    case 0x250:
  92.463 +    case 0x260:
  92.464 +    case 0x270:
  92.465 +        *result = vlapic->irr[(offset - APIC_IRR) >> 4];
  92.466 +        break;
  92.467 +
  92.468 +    case APIC_ESR:
  92.469 +        if (vlapic->err_write_count)
  92.470 +            *result = vlapic->err_status;
  92.471 +        break;
  92.472 +
  92.473 +    case APIC_ICR:
  92.474 +        *result = vlapic->icr_low;
  92.475 +        break;
  92.476 +
  92.477 +    case APIC_ICR2:
  92.478 +        *result = vlapic->icr_high;
  92.479 +        break;
  92.480 +
  92.481 +    case APIC_LVTT:     /* LVT Timer Reg */
  92.482 +    case APIC_LVTTHMR:     /* LVT Thermal Monitor */
  92.483 +    case APIC_LVTPC:     /* LVT Performance Counter */
  92.484 +    case APIC_LVT0:     /* LVT LINT0 Reg */
  92.485 +    case APIC_LVT1:     /* LVT Lint1 Reg */
  92.486 +    case APIC_LVTERR:     /* LVT Error Reg */
  92.487 +        *result = vlapic->lvt[(offset - APIC_LVTT) >> 4];
  92.488 +        break;
  92.489 +
  92.490 +    case APIC_TMICT:
  92.491 +        *result = vlapic->timer_initial;
  92.492 +        break;
  92.493 +
  92.494 +    case APIC_TMCCT:         //Timer CCR
  92.495 +        {
  92.496 +            uint32_t counter;
  92.497 +            s_time_t passed, cur = NOW();
  92.498 +
  92.499 +            if (cur <= vlapic->timer_current_update) {
  92.500 +                passed = ~0x0LL - vlapic->timer_current_update + cur;
  92.501 +                VMX_DBG_LOG(DBG_LEVEL_VLAPIC,"time elapsed");
  92.502 +            }else
  92.503 +                passed = cur - vlapic->timer_current_update;
  92.504 +
  92.505 +            counter = (passed * get_apic_bus_scale()) / (262144* vlapic->timer_divide_counter);
  92.506 +            if (vlapic->timer_current > counter)
  92.507 +                *result = vlapic->timer_current - counter;
  92.508 +            else {
  92.509 +                if (!vlapic_lvt_timer_period(vlapic))
  92.510 +                    *result = 0;
  92.511 +                //FIXME should we add interrupt here?
  92.512 +                else
  92.513 +                    //*result = counter % vlapic->timer_initial;
  92.514 +                    *result = vlapic->timer_initial - (counter - vlapic->timer_current);
  92.515 +            }
  92.516 +            vlapic->timer_current = *result;
  92.517 +            vlapic->timer_current_update = NOW();
  92.518 +
  92.519 +            VMX_DBG_LOG(DBG_LEVEL_VLAPIC_TIMER,
  92.520 +                        "initial %x timer current %x "
  92.521 +                        "update %08x%08x cur %08x%08x offset %d",
  92.522 +                        vlapic->timer_initial, vlapic->timer_current,
  92.523 +                        (uint32_t)(vlapic->timer_current_update >> 32),
  92.524 +                        (uint32_t)vlapic->timer_current_update ,
  92.525 +                        (uint32_t)(cur >> 32), (uint32_t)cur, counter);
  92.526 +        }
  92.527 +        break;
  92.528 +
  92.529 +    case APIC_TDCR:
  92.530 +        *result = vlapic->timer_divconf;
  92.531 +        break;
  92.532 +
  92.533 +    default:
  92.534 +        printk("Read local APIC address %x not implemented\n",offset);
  92.535 +        *result = 0;
  92.536 +        break;
  92.537 +    }
  92.538 +}
  92.539 +
  92.540 +unsigned long vlapic_read(struct vcpu *v, unsigned long address,
  92.541 +            unsigned long len)
  92.542 +{
  92.543 +    unsigned int alignment;
  92.544 +    unsigned int tmp;
  92.545 +    unsigned long result;
  92.546 +    struct vlapic *vlapic = VLAPIC(v);
  92.547 +    unsigned int offset = address - vlapic->base_address;
  92.548 +
  92.549 +    if ( len != 4) {
  92.550 +        /* some bugs on kernel cause read this with byte*/
  92.551 +        printk("Local APIC read with len = %lx, should be 4 instead\n", len);
  92.552 +    }
  92.553 +
  92.554 +    alignment = offset & 0x3;
  92.555 +
  92.556 +    vlapic_read_aligned(vlapic, offset & ~0x3, 4, &tmp);
  92.557 +    switch (len) {
  92.558 +    case 1:
  92.559 +        result = *((unsigned char *)&tmp + alignment);
  92.560 +        break;
  92.561 +
  92.562 +    case 2:
  92.563 +        result = *(unsigned short *)((unsigned char *)&tmp + alignment);
  92.564 +        break;
  92.565 +
  92.566 +    case 4:
  92.567 +        result = *(unsigned int *)((unsigned char *)&tmp + alignment);
  92.568 +        break;
  92.569 +
  92.570 +    default:
  92.571 +        printk("Local APIC read with len = %lx, should be 4 instead\n", len);
  92.572 +        domain_crash_synchronous();
  92.573 +        break;
  92.574 +    }
  92.575 +
  92.576 +    VMX_DBG_LOG(DBG_LEVEL_VLAPIC,
  92.577 +                "vlapic_read offset %x with length %lx and the result is %lx",
  92.578 +                offset, len, result);
  92.579 +    return result;
  92.580 +}
  92.581 +
  92.582 +unsigned long vlapic_write(struct vcpu *v, unsigned long address,
  92.583 +                  unsigned long len, unsigned long val)
  92.584 +{
  92.585 +    struct vlapic *vlapic = VLAPIC(v);
  92.586 +    unsigned int offset = address - vlapic->base_address;
  92.587 +
  92.588 +    if (offset != 0xb0)
  92.589 +        VMX_DBG_LOG(DBG_LEVEL_VLAPIC,
  92.590 +          "vlapic_write offset %x with length %lx source %lx",
  92.591 +          offset, len, val);
  92.592 +
  92.593 +    /*
  92.594 +     * According to IA 32 Manual, all resgiters should be accessed with
  92.595 +     * 32 bits alignment.
  92.596 +     */
  92.597 +    if (len != 4) {
  92.598 +        unsigned int tmp;
  92.599 +        unsigned char alignment;
  92.600 +
  92.601 +        /* Some kernel do will access with byte/word alignment*/
  92.602 +        printk("Notice: Local APIC write with len = %lx\n",len);
  92.603 +        alignment = offset & 0x3;
  92.604 +        tmp = vlapic_read(v, offset & (~0x3), 4);
  92.605 +        switch (len) {
  92.606 +        case 1:
  92.607 +            /* XXX the saddr is a tmp variable from caller, so should be ok
  92.608 +               But we should still change the following ref to val to 
  92.609 +               local variable later */
  92.610 +            val  = (tmp & ~(0xff << alignment)) |
  92.611 +                        ((val & 0xff) << alignment);
  92.612 +            break;
  92.613 +
  92.614 +        case 2:
  92.615 +            if (alignment != 0x0 && alignment != 0x2) {
  92.616 +                printk("alignment error for vlapic with len == 2\n");
  92.617 +                    domain_crash_synchronous();
  92.618 +            }
  92.619 +
  92.620 +            val = (tmp & ~(0xffff << alignment)) |
  92.621 +                        ((val & 0xffff)  << alignment);
  92.622 +            break;
  92.623 +
  92.624 +        case 3:
  92.625 +            /* will it happen? */
  92.626 +            printk("vlapic_write with len = 3 !!!\n");
  92.627 +            domain_crash_synchronous();
  92.628 +            break;
  92.629 +
  92.630 +        default:
  92.631 +            printk("Local APIC write with len = %lx, should be 4 instead\n", len);
  92.632 +            domain_crash_synchronous();
  92.633 +            break;
  92.634 +        }
  92.635 +    }
  92.636 +
  92.637 +    offset &= 0xff0;
  92.638 +
  92.639 +    switch (offset) {
  92.640 +    case APIC_ID:   /* Local APIC ID */
  92.641 +        vlapic->id = ((val) >> 24) & VAPIC_ID_MASK;
  92.642 +        break;
  92.643 +
  92.644 +    case APIC_TASKPRI:
  92.645 +        vlapic->task_priority = val & 0xff;
  92.646 +        vlapic_update_ppr(vlapic);
  92.647 +        break;
  92.648 +
  92.649 +    case APIC_EOI:
  92.650 +        vlapic_EOI_set(vlapic);
  92.651 +        break;
  92.652 +
  92.653 +    case APIC_LDR:
  92.654 +        vlapic->logical_dest = val & VAPIC_LDR_MASK;
  92.655 +        break;
  92.656 +
  92.657 +    case APIC_DFR:
  92.658 +        vlapic->dest_format = val ;
  92.659 +        break;
  92.660 +
  92.661 +    case APIC_SPIV:
  92.662 +        vlapic->spurious_vec = val & 0x1ff;
  92.663 +        if (!(vlapic->spurious_vec & 0x100)) {
  92.664 +            int i = 0;
  92.665 +            for (i=0; i < VLAPIC_LVT_NUM; i++) 
  92.666 +                vlapic->lvt[i] |= 0x10000;
  92.667 +            vlapic->status |= VLAPIC_SOFTWARE_DISABLE_MASK;
  92.668 +        }
  92.669 +        else
  92.670 +            vlapic->status &= ~VLAPIC_SOFTWARE_DISABLE_MASK;
  92.671 +        break;
  92.672 +
  92.673 +    case APIC_ESR:
  92.674 +        vlapic->err_write_count = !vlapic->err_write_count;
  92.675 +        if (!vlapic->err_write_count)
  92.676 +            vlapic->err_status = 0;
  92.677 +        break;
  92.678 +
  92.679 +    case APIC_ICR:
  92.680 +        /* No delay here, so we always clear the pending bit*/
  92.681 +        vlapic->icr_low = val & ~(1 << 12);
  92.682 +        vlapic_ipi(vlapic);
  92.683 +        break;
  92.684 +
  92.685 +    case APIC_ICR2:
  92.686 +        vlapic->icr_high = val & 0xff000000;
  92.687 +        break;
  92.688 +
  92.689 +    case APIC_LVTT: // LVT Timer Reg
  92.690 +    case APIC_LVTTHMR: // LVT Thermal Monitor
  92.691 +    case APIC_LVTPC: // LVT Performance Counter
  92.692 +    case APIC_LVT0: // LVT LINT0 Reg
  92.693 +    case APIC_LVT1: // LVT Lint1 Reg
  92.694 +    case APIC_LVTERR: // LVT Error Reg
  92.695 +        {
  92.696 +            int vt = (offset - APIC_LVTT) >> 4;
  92.697 +
  92.698 +            vlapic->lvt[vt] = val & vlapic_lvt_mask[vt];
  92.699 +            if (vlapic->status & VLAPIC_SOFTWARE_DISABLE_MASK)
  92.700 +                vlapic->lvt[vt] |= VLAPIC_LVT_BIT_MASK;
  92.701 +
  92.702 +            /* On hardware, when write vector less than 0x20 will error */
  92.703 +            vlapic_check_vector(vlapic, vlapic_lvt_dm(vlapic->lvt[vt]),
  92.704 +              vlapic_lvt_vector(vlapic, vt));
  92.705 +
  92.706 +            if (!vlapic->vcpu_id && (offset == APIC_LVT0)) {
  92.707 +                if ((vlapic->lvt[VLAPIC_LVT_LINT0] & VLAPIC_LVT_BIT_DELIMOD)
  92.708 +                            == 0x700) {
  92.709 +                    if (!(vlapic->lvt[VLAPIC_LVT_LINT0] & VLAPIC_LVT_BIT_MASK)) {
  92.710 +                        set_bit(_VLAPIC_BSP_ACCEPT_PIC, &vlapic->status);
  92.711 +                    }else
  92.712 +                        clear_bit(_VLAPIC_BSP_ACCEPT_PIC, &vlapic->status);
  92.713 +                }
  92.714 +                else
  92.715 +                    clear_bit(_VLAPIC_BSP_ACCEPT_PIC, &vlapic->status);
  92.716 +            }
  92.717 +
  92.718 +        }
  92.719 +        break;
  92.720 +
  92.721 +    case APIC_TMICT:
  92.722 +        if (vlapic_timer_active(vlapic))
  92.723 +            rem_ac_timer(&(vlapic->vlapic_timer));
  92.724 +
  92.725 +        vlapic->timer_initial = val;
  92.726 +        vlapic->timer_current = val;
  92.727 +        vlapic->timer_current_update = NOW();
  92.728 +
  92.729 +        VMX_DBG_LOG(DBG_LEVEL_VLAPIC,
  92.730 +          "timer_init %x timer_current %x timer_current_update %08x%08x",
  92.731 +          vlapic->timer_initial, vlapic->timer_current, (uint32_t)(vlapic->timer_current_update>>32), (uint32_t)vlapic->timer_current_update);
  92.732 +        vlapic_begin_timer(vlapic);
  92.733 +        break;
  92.734 +
  92.735 +    case APIC_TDCR:
  92.736 +        {
  92.737 +            //FIXME clean this code
  92.738 +            unsigned char tmp1,tmp2;
  92.739 +            tmp1 = (val & 0xf);
  92.740 +            tmp2 = ((tmp1 & 0x3 )|((tmp1 & 0x8) >>1)) + 1;
  92.741 +            vlapic->timer_divide_counter = 0x1<<tmp2;
  92.742 +
  92.743 +            VMX_DBG_LOG(DBG_LEVEL_VLAPIC_TIMER,
  92.744 +                        "timer divider is 0x%x",
  92.745 +                        vlapic->timer_divide_counter);
  92.746 +        }
  92.747 +        break;
  92.748 +
  92.749 +    default:
  92.750 +        printk("Local APIC Write to read-only register\n");
  92.751 +        break;
  92.752 +    }
  92.753 +    return 1;
  92.754 +}
  92.755 +
  92.756 +int vlapic_range(struct vcpu *v, unsigned long addr)
  92.757 +{
  92.758 +    struct vlapic *vlapic = VLAPIC(v);
  92.759 +
  92.760 +    if (vlapic_global_enabled(vlapic) &&
  92.761 +        (addr >= vlapic->base_address) &&
  92.762 +        (addr <= (vlapic->base_address + VLOCAL_APIC_MEM_LENGTH)))
  92.763 +        return 1;
  92.764 +
  92.765 +    return 0;
  92.766 +}
  92.767 +
  92.768 +void vlapic_msr_set(struct vlapic *vlapic, uint64_t value)
  92.769 +{
  92.770 +    /* When apic disabled */
  92.771 +    if (!vlapic)
  92.772 +        return;
  92.773 +
  92.774 +    if (vlapic->vcpu_id)
  92.775 +        value &= ~MSR_IA32_APICBASE_BSP;
  92.776 +
  92.777 +    vlapic->apic_base_msr = value;
  92.778 +    vlapic->base_address = vlapic_get_base_address(vlapic);
  92.779 +
  92.780 +    if (!(value & 0x800))
  92.781 +        set_bit(_VLAPIC_GLOB_DISABLE, &vlapic->status );
  92.782 +
  92.783 +    VMX_DBG_LOG(DBG_LEVEL_VLAPIC,
  92.784 +                "apic base msr = 0x%08x%08x,\nbase address = 0x%lx",
  92.785 +                (uint32_t)(vlapic->apic_base_msr >> 32),
  92.786 +                (uint32_t)vlapic->apic_base_msr,
  92.787 +                vlapic->base_address);
  92.788 +}
  92.789 +
  92.790 +static inline int vlapic_get_init_id(struct vcpu *v)
  92.791 +{
  92.792 +    return v->vcpu_id;
  92.793 +}
  92.794 +
  92.795 +void vlapic_timer_fn(void *data)
  92.796 +{
  92.797 +    struct vlapic *vlapic;
  92.798 +
  92.799 +    vlapic = data;
  92.800 +    if (!vlapic_enabled(vlapic)) return;
  92.801 +
  92.802 +    vlapic->timer_current_update = NOW();
  92.803 +
  92.804 +    if (vlapic_lvt_timer_enabled(vlapic)) {
  92.805 +        if (!vlapic_irr_status(vlapic,
  92.806 +              vlapic_lvt_vector(vlapic, VLAPIC_LVT_TIMER))) {
  92.807 +            test_and_set_bit(vlapic_lvt_vector(vlapic, VLAPIC_LVT_TIMER),
  92.808 +              &vlapic->irr[0]);
  92.809 +        }
  92.810 +        else
  92.811 +            vlapic->intr_pending_count[vlapic_lvt_vector(vlapic, VLAPIC_LVT_TIMER)]++;
  92.812 +    }
  92.813 +
  92.814 +    vlapic->timer_current_update = NOW();
  92.815 +    if (vlapic_lvt_timer_period(vlapic)) {
  92.816 +        s_time_t offset;
  92.817 +
  92.818 +        vlapic->timer_current = vlapic->timer_initial;
  92.819 +        offset = vlapic->timer_current * (262144/get_apic_bus_scale()) * vlapic->timer_divide_counter;
  92.820 +        vlapic->vlapic_timer.expires = NOW() + offset;
  92.821 +        set_ac_timer(&(vlapic->vlapic_timer), vlapic->vlapic_timer.expires);
  92.822 +    }else {
  92.823 +        vlapic->timer_current = 0;
  92.824 +    }
  92.825 +
  92.826 +    VMX_DBG_LOG(DBG_LEVEL_VLAPIC_TIMER,
  92.827 +      "vlapic_timer_fn: now: %08x%08x expire %08x%08x init %x current %x",
  92.828 +      (uint32_t)(NOW() >> 32),(uint32_t)NOW(),
  92.829 +      (uint32_t)(vlapic->vlapic_timer.expires >> 32),
  92.830 +      (uint32_t)vlapic->vlapic_timer.expires,
  92.831 +      vlapic->timer_initial,vlapic->timer_current);
  92.832 +}
  92.833 +
  92.834 +#if 0
  92.835 +static int
  92.836 +vlapic_check_direct_intr(struct vcpu *v, int * mode)
  92.837 +{
  92.838 +    struct vlapic *vlapic = VLAPIC(v);
  92.839 +    int type;
  92.840 +
  92.841 +    type = __fls(vlapic->direct_intr.deliver_mode);
  92.842 +    if (type == -1)
  92.843 +        return -1;
  92.844 +
  92.845 +    *mode = type;
  92.846 +    return 0;
  92.847 +}
  92.848 +#endif
  92.849 +
  92.850 +int
  92.851 +vlapic_accept_pic_intr(struct vcpu *v)
  92.852 +{
  92.853 +    struct vlapic *vlapic = VLAPIC(v);
  92.854 +
  92.855 +    return vlapic ? test_bit(_VLAPIC_BSP_ACCEPT_PIC, &vlapic->status) : 1;
  92.856 +}
  92.857 +
  92.858 +int cpu_get_apic_interrupt(struct vcpu* v, int *mode)
  92.859 +{
  92.860 +    struct vlapic *vlapic = VLAPIC(v);
  92.861 +
  92.862 +    if (vlapic && vlapic_enabled(vlapic)) {
  92.863 +        int highest_irr = vlapic_find_highest_irr(vlapic);
  92.864 +
  92.865 +        if (highest_irr != -1 && highest_irr >= vlapic->processor_priority) {
  92.866 +            if (highest_irr < 0x10) {
  92.867 +                vlapic->err_status |= 0x20;
  92.868 +                /* XXX What will happen if this vector illegal stil */
  92.869 +                VMX_DBG_LOG(DBG_LEVEL_VLAPIC,
  92.870 +                  "vmx_intr_assist: illegal vector number %x err_status %x",
  92.871 +                  highest_irr,  vlapic_lvt_vector(vlapic, VLAPIC_LVT_ERROR));
  92.872 +
  92.873 +                set_bit(vlapic_lvt_vector(vlapic, VLAPIC_LVT_ERROR), &vlapic->irr[0]);
  92.874 +                highest_irr = vlapic_lvt_vector(vlapic, VLAPIC_LVT_ERROR);
  92.875 +            }
  92.876 +
  92.877 +            *mode = VLAPIC_DELIV_MODE_FIXED;
  92.878 +            return highest_irr;
  92.879 +        }
  92.880 +    }
  92.881 +    return -1;
  92.882 +}
  92.883 +
  92.884 +void vlapic_post_injection(struct vcpu *v, int vector, int deliver_mode) {
  92.885 +    struct vlapic  *vlapic = VLAPIC(v);
  92.886 +
  92.887 +    if (!vlapic)
  92.888 +        return;
  92.889 +
  92.890 +    switch (deliver_mode) {
  92.891 +    case VLAPIC_DELIV_MODE_FIXED:
  92.892 +    case VLAPIC_DELIV_MODE_LPRI:
  92.893 +        vlapic_set_isr(vlapic, vector);
  92.894 +        vlapic_clear_irr(vlapic, vector);
  92.895 +        vlapic_update_ppr(vlapic);
  92.896 +
  92.897 +        if (vector == vlapic_lvt_vector(vlapic, VLAPIC_LVT_TIMER)) {
  92.898 +            vlapic->intr_pending_count[vector]--;
  92.899 +            if (vlapic->intr_pending_count[vector] > 0)
  92.900 +                test_and_set_bit(vlapic_lvt_vector(vlapic, VLAPIC_LVT_TIMER),
  92.901 +                  &vlapic->irr[0]);
  92.902 +        }
  92.903 +
  92.904 +        break;
  92.905 +        /*XXX deal with these later */
  92.906 +
  92.907 +    case VLAPIC_DELIV_MODE_RESERVED:
  92.908 +        printk("Ignore deliver mode 3 in vlapic_post_injection\n");
  92.909 +        break;
  92.910 +
  92.911 +    case VLAPIC_DELIV_MODE_SMI:
  92.912 +    case VLAPIC_DELIV_MODE_NMI:
  92.913 +    case VLAPIC_DELIV_MODE_INIT:
  92.914 +    case VLAPIC_DELIV_MODE_STARTUP:
  92.915 +        vlapic->direct_intr.deliver_mode &= ~(1 << deliver_mode);
  92.916 +        break;
  92.917 +
  92.918 +    default:
  92.919 +        printk("<vlapic_post_injection> error deliver mode\n");
  92.920 +        break;
  92.921 +    }
  92.922 +}
  92.923 +
  92.924 +static int vlapic_reset(struct vlapic *vlapic)
  92.925 +{
  92.926 +    struct vcpu *v = vlapic->vcpu;
  92.927 +    int apic_id = v->vcpu_id, i;
  92.928 +
  92.929 +    if (!v || !vlapic)
  92.930 +        return 0;
  92.931 +
  92.932 +    memset(vlapic, 0,sizeof(struct vlapic));
  92.933 +
  92.934 +    v->arch.arch_vmx.vlapic = vlapic;
  92.935 +
  92.936 +    vlapic->domain = v->domain;
  92.937 +
  92.938 +    vlapic->id = apic_id;
  92.939 +
  92.940 +    vlapic->version = VLAPIC_VERSION;
  92.941 +
  92.942 +    vlapic->apic_base_msr = VLAPIC_BASE_MSR_INIT_VALUE;
  92.943 +
  92.944 +    if (apic_id == 0)
  92.945 +        vlapic->apic_base_msr |= MSR_IA32_APICBASE_BSP;
  92.946 +    vlapic->base_address = vlapic_get_base_address(vlapic);
  92.947 +
  92.948 +    for (i = 0; i < VLAPIC_LVT_NUM; i++)
  92.949 +        vlapic->lvt[i] = VLAPIC_LVT_BIT_MASK;
  92.950 +
  92.951 +    vlapic->dest_format = 0xffffffffU;
  92.952 +
  92.953 +    vlapic->spurious_vec = 0xff;
  92.954 +
  92.955 +
  92.956 +    init_ac_timer(&vlapic->vlapic_timer,
  92.957 +      vlapic_timer_fn, vlapic, v->processor);
  92.958 +
  92.959 +#ifdef VLAPIC_NO_BIOS
  92.960 +    /*
  92.961 +     * XXX According to mp sepcific, BIOS will enable LVT0/1,
  92.962 +     * remove it after BIOS enabled
  92.963 +     */
  92.964 +    if (!v->vcpu_id) {
  92.965 +        vlapic->lvt[VLAPIC_LVT_LINT0] = 0x700;
  92.966 +        vlapic->lvt[VLAPIC_LVT_LINT1] = 0x500;
  92.967 +        set_bit(_VLAPIC_BSP_ACCEPT_PIC, &vlapic->status);
  92.968 +    }
  92.969 +#endif
  92.970 +
  92.971 +    VMX_DBG_LOG(DBG_LEVEL_VLAPIC, "vlapic_reset: "
  92.972 +      "vcpu=%p id=%d vlapic_apic_base_msr=%08x%08x "
  92.973 +      "vlapic_base_address=%0lx",
  92.974 +      v, vlapic->id, (uint32_t)(vlapic->apic_base_msr >> 32),
  92.975 +      (uint32_t)vlapic->apic_base_msr, vlapic->base_address);
  92.976 +
  92.977 +    return 1;
  92.978 +}
  92.979 +
  92.980 +int vlapic_init(struct vcpu *v)
  92.981 +{
  92.982 +    struct vlapic *vlapic = NULL;
  92.983 +
  92.984 +    VMX_DBG_LOG(DBG_LEVEL_VLAPIC, "vlapic_init %d", v->vcpu_id);
  92.985 +
  92.986 +    vlapic = xmalloc_bytes(sizeof(struct vlapic));
  92.987 +
  92.988 +    if (!vlapic) {
  92.989 +        printk("malloc vlapic error for vcpu %x\n", v->vcpu_id);
  92.990 +        return -ENOMEM;
  92.991 +    }
  92.992 +
  92.993 +    vlapic->vcpu = v;
  92.994 +
  92.995 +    vlapic_reset(vlapic);
  92.996 +
  92.997 +    return 0;
  92.998 +}
  92.999 +
 92.1000 +#endif  /* CONFIG_VMX */
    93.1 --- a/xen/arch/x86/vmx_vmcs.c	Sun Oct 30 13:52:38 2005 +0100
    93.2 +++ b/xen/arch/x86/vmx_vmcs.c	Sun Oct 30 14:00:35 2005 +0100
    93.3 @@ -252,6 +252,10 @@ static void vmx_setup_platform(struct do
    93.4      pic_init(&platform->vmx_pic,  pic_irq_request, 
    93.5               &platform->interrupt_request);
    93.6      register_pic_io_hook();
    93.7 +
    93.8 +    if ( vmx_apic_support(d) ) {
    93.9 +        spin_lock_init(&d->arch.vmx_platform.round_robin_lock);
   93.10 +    }
   93.11  }
   93.12  
   93.13  static void vmx_set_host_env(struct vcpu *v)
   93.14 @@ -313,6 +317,9 @@ static void vmx_do_launch(struct vcpu *v
   93.15  
   93.16      vmx_stts();
   93.17  
   93.18 +    if(vmx_apic_support(v->domain))
   93.19 +        vlapic_init(v);
   93.20 +
   93.21      vmx_set_host_env(v);
   93.22  
   93.23      error |= __vmwrite(GUEST_LDTR_SELECTOR, 0);
    94.1 --- a/xen/common/acm_ops.c	Sun Oct 30 13:52:38 2005 +0100
    94.2 +++ b/xen/common/acm_ops.c	Sun Oct 30 14:00:35 2005 +0100
    94.3 @@ -133,7 +133,10 @@ long do_acm_op(struct acm_op * u_acm_op)
    94.4              struct domain *subj = find_domain_by_id(op->u.getssid.id.domainid);
    94.5              if (!subj)
    94.6                  return -ESRCH; /* domain not found */
    94.7 -
    94.8 +            if (subj->ssid == NULL) {
    94.9 +                put_domain(subj);
   94.10 +                return -ESRCH;
   94.11 +            }
   94.12              ssidref = ((struct acm_ssid_domain *)(subj->ssid))->ssidref;
   94.13              put_domain(subj);
   94.14          } else
   94.15 @@ -167,6 +170,10 @@ long do_acm_op(struct acm_op * u_acm_op)
   94.16                  ret = -ESRCH; /* domain not found */
   94.17                  goto out;
   94.18              }
   94.19 +            if (subj->ssid == NULL) {
   94.20 +                put_domain(subj);
   94.21 +                ret = -ESRCH;
   94.22 +            }
   94.23              ssidref1 = ((struct acm_ssid_domain *)(subj->ssid))->ssidref;
   94.24              put_domain(subj);
   94.25          } else {
   94.26 @@ -182,6 +189,10 @@ long do_acm_op(struct acm_op * u_acm_op)
   94.27                  ret = -ESRCH; /* domain not found */
   94.28                  goto out;
   94.29              }
   94.30 +            if (subj->ssid == NULL) {
   94.31 +                put_domain(subj);
   94.32 +                return -ESRCH;
   94.33 +            }
   94.34              ssidref2 = ((struct acm_ssid_domain *)(subj->ssid))->ssidref;
   94.35              put_domain(subj);
   94.36          } else {
    95.1 --- a/xen/common/schedule.c	Sun Oct 30 13:52:38 2005 +0100
    95.2 +++ b/xen/common/schedule.c	Sun Oct 30 14:00:35 2005 +0100
    95.3 @@ -514,7 +514,7 @@ static void dom_timer_fn(void *data)
    95.4  /* Initialise the data structures. */
    95.5  void __init scheduler_init(void)
    95.6  {
    95.7 -    int i;
    95.8 +    int i, rc;
    95.9  
   95.10      open_softirq(SCHEDULE_SOFTIRQ, __enter_scheduler);
   95.11  
   95.12 @@ -540,7 +540,9 @@ void __init scheduler_init(void)
   95.13  
   95.14      printk("Using scheduler: %s (%s)\n", ops.name, ops.opt_name);
   95.15  
   95.16 -    BUG_ON(SCHED_OP(alloc_task, idle_task[0]) < 0);
   95.17 +    rc = SCHED_OP(alloc_task, idle_task[0]);
   95.18 +    BUG_ON(rc < 0);
   95.19 +
   95.20      sched_add_domain(idle_task[0]);
   95.21  }
   95.22  
    96.1 --- a/xen/include/acm/acm_hooks.h	Sun Oct 30 13:52:38 2005 +0100
    96.2 +++ b/xen/include/acm/acm_hooks.h	Sun Oct 30 14:00:35 2005 +0100
    96.3 @@ -100,10 +100,10 @@ struct acm_operations {
    96.4      void (*fail_domain_create)         (void *subject_ssid, ssidref_t ssidref);
    96.5      void (*post_domain_destroy)        (void *object_ssid, domid_t id);
    96.6      /* event channel control hooks  (can be NULL) */
    96.7 -    int  (*pre_eventchannel_unbound)      (domid_t id);
    96.8 -    void (*fail_eventchannel_unbound)     (domid_t id);
    96.9 -    int  (*pre_eventchannel_interdomain)  (domid_t id1, domid_t id2);
   96.10 -    int  (*fail_eventchannel_interdomain) (domid_t id1, domid_t id2);
   96.11 +    int  (*pre_eventchannel_unbound)      (domid_t id1, domid_t id2);
   96.12 +    void (*fail_eventchannel_unbound)     (domid_t id1, domid_t id2);
   96.13 +    int  (*pre_eventchannel_interdomain)  (domid_t id);
   96.14 +    void (*fail_eventchannel_interdomain) (domid_t id);
   96.15      /* grant table control hooks (can be NULL)  */
   96.16      int  (*pre_grant_map_ref)          (domid_t id);
   96.17      void (*fail_grant_map_ref)         (domid_t id);
   96.18 @@ -193,31 +193,31 @@ static inline void acm_post_domain_destr
   96.19      return;
   96.20  }
   96.21  
   96.22 -static inline int acm_pre_eventchannel_unbound(domid_t id)
   96.23 +static inline int acm_pre_eventchannel_unbound(domid_t id1, domid_t id2)
   96.24  {
   96.25      if ((acm_primary_ops->pre_eventchannel_unbound != NULL) && 
   96.26 -        acm_primary_ops->pre_eventchannel_unbound(id))
   96.27 +        acm_primary_ops->pre_eventchannel_unbound(id1, id2))
   96.28          return ACM_ACCESS_DENIED;
   96.29      else if ((acm_secondary_ops->pre_eventchannel_unbound != NULL) && 
   96.30 -             acm_secondary_ops->pre_eventchannel_unbound(id)) {
   96.31 +             acm_secondary_ops->pre_eventchannel_unbound(id1, id2)) {
   96.32          /* roll-back primary */
   96.33          if (acm_primary_ops->fail_eventchannel_unbound != NULL)
   96.34 -            acm_primary_ops->fail_eventchannel_unbound(id);
   96.35 +            acm_primary_ops->fail_eventchannel_unbound(id1, id2);
   96.36          return ACM_ACCESS_DENIED;
   96.37      } else
   96.38          return ACM_ACCESS_PERMITTED;
   96.39  }
   96.40  
   96.41 -static inline int acm_pre_eventchannel_interdomain(domid_t id1, domid_t id2)
   96.42 +static inline int acm_pre_eventchannel_interdomain(domid_t id)
   96.43  {
   96.44      if ((acm_primary_ops->pre_eventchannel_interdomain != NULL) &&
   96.45 -        acm_primary_ops->pre_eventchannel_interdomain(id1, id2))
   96.46 +        acm_primary_ops->pre_eventchannel_interdomain(id))
   96.47          return ACM_ACCESS_DENIED;
   96.48      else if ((acm_secondary_ops->pre_eventchannel_interdomain != NULL) &&
   96.49 -             acm_secondary_ops->pre_eventchannel_interdomain(id1, id2)) {
   96.50 +             acm_secondary_ops->pre_eventchannel_interdomain(id)) {
   96.51          /* roll-back primary */
   96.52          if (acm_primary_ops->fail_eventchannel_interdomain != NULL)
   96.53 -            acm_primary_ops->fail_eventchannel_interdomain(id1, id2);
   96.54 +            acm_primary_ops->fail_eventchannel_interdomain(id);
   96.55          return ACM_ACCESS_DENIED;
   96.56      } else
   96.57          return ACM_ACCESS_PERMITTED;
   96.58 @@ -234,10 +234,22 @@ static inline int acm_pre_dom0_op(dom0_o
   96.59              current->domain->ssid, op->u.createdomain.ssidref);
   96.60          break;
   96.61      case DOM0_DESTROYDOMAIN:
   96.62 +        if (*ssid != NULL) {
   96.63 +            printkd("%s: Warning. Overlapping destruction.\n", 
   96.64 +                    __func__);
   96.65 +            return -EACCES;
   96.66 +        }
   96.67          d = find_domain_by_id(op->u.destroydomain.domain);
   96.68          if (d != NULL) {
   96.69              *ssid = d->ssid; /* save for post destroy when d is gone */
   96.70 -            /* no policy-specific hook */
   96.71 +            if (*ssid == NULL) {
   96.72 +                printk("%s: Warning. Destroying domain without ssid pointer.\n", 
   96.73 +                       __func__);
   96.74 +                put_domain(d);
   96.75 +                return -EACCES;
   96.76 +            }
   96.77 +            d->ssid = NULL; /* make sure it's not used any more */
   96.78 +             /* no policy-specific hook */
   96.79              put_domain(d);
   96.80              ret = 0;
   96.81          }
   96.82 @@ -248,7 +260,7 @@ static inline int acm_pre_dom0_op(dom0_o
   96.83      return ret;
   96.84  }
   96.85  
   96.86 -static inline void acm_post_dom0_op(dom0_op_t *op, void *ssid) 
   96.87 +static inline void acm_post_dom0_op(dom0_op_t *op, void **ssid)
   96.88  {
   96.89      switch(op->cmd) {
   96.90      case DOM0_CREATEDOMAIN:
   96.91 @@ -261,7 +273,8 @@ static inline void acm_post_dom0_op(dom0
   96.92      case DOM0_DESTROYDOMAIN:
   96.93          acm_post_domain_destroy(ssid, op->u.destroydomain.domain);
   96.94          /* free security ssid for the destroyed domain (also if null policy */
   96.95 -        acm_free_domain_ssid((struct acm_ssid_domain *)ssid);
   96.96 +        acm_free_domain_ssid((struct acm_ssid_domain *)(*ssid));
   96.97 +        *ssid = NULL;
   96.98          break;
   96.99      }
  96.100  }
  96.101 @@ -282,12 +295,13 @@ static inline int acm_pre_event_channel(
  96.102  
  96.103      switch(op->cmd) {
  96.104      case EVTCHNOP_alloc_unbound:
  96.105 -        ret = acm_pre_eventchannel_unbound(op->u.alloc_unbound.dom);
  96.106 +        ret = acm_pre_eventchannel_unbound(
  96.107 +                  op->u.alloc_unbound.dom,
  96.108 +                  op->u.alloc_unbound.remote_dom);
  96.109          break;
  96.110      case EVTCHNOP_bind_interdomain:
  96.111          ret = acm_pre_eventchannel_interdomain(
  96.112 -            current->domain->domain_id,
  96.113 -            op->u.bind_interdomain.remote_dom);
  96.114 +                  op->u.bind_interdomain.remote_dom);
  96.115          break;
  96.116      default:
  96.117          ret = 0; /* ok */
    97.1 --- a/xen/include/asm-ia64/config.h	Sun Oct 30 13:52:38 2005 +0100
    97.2 +++ b/xen/include/asm-ia64/config.h	Sun Oct 30 14:00:35 2005 +0100
    97.3 @@ -28,8 +28,8 @@
    97.4  
    97.5  #ifdef CONFIG_XEN_SMP
    97.6  #define CONFIG_SMP 1
    97.7 -#define NR_CPUS 2
    97.8 -#define CONFIG_NR_CPUS 2
    97.9 +#define NR_CPUS 8
   97.10 +#define CONFIG_NR_CPUS 8
   97.11  #else
   97.12  #undef CONFIG_SMP
   97.13  #define NR_CPUS 1
   97.14 @@ -102,7 +102,7 @@ extern char _end[]; /* standard ELF symb
   97.15  #endif
   97.16  
   97.17  // xen/include/asm/config.h
   97.18 -#define HZ 100
   97.19 +//#define HZ 1000
   97.20  // FIXME SMP: leave SMP for a later time
   97.21  #define barrier() __asm__ __volatile__("": : :"memory")
   97.22  
   97.23 @@ -123,8 +123,7 @@ extern char _end[]; /* standard ELF symb
   97.24  #ifdef CONFIG_SMP
   97.25  #warning "Lots of things to fix to enable CONFIG_SMP!"
   97.26  #endif
   97.27 -// FIXME SMP
   97.28 -#define	get_cpu()	0
   97.29 +#define	get_cpu()	smp_processor_id()
   97.30  #define put_cpu()	do {} while(0)
   97.31  
   97.32  // needed for common/dom0_ops.c until hyperthreading is supported
   97.33 @@ -140,6 +139,7 @@ struct page;
   97.34  // function calls; see decl in xen/include/xen/sched.h
   97.35  #undef free_task_struct
   97.36  #undef alloc_task_struct
   97.37 +#define get_thread_info(v) alloc_thread_info(v)
   97.38  
   97.39  // initial task has a different name in Xen
   97.40  //#define	idle0_task	init_task
   97.41 @@ -299,7 +299,11 @@ extern int ht_per_core;
   97.42  #endif /* __XEN_IA64_CONFIG_H__ */
   97.43  
   97.44  // needed for include/xen/smp.h
   97.45 +#ifdef CONFIG_SMP
   97.46 +#define __smp_processor_id()	current_thread_info()->cpu
   97.47 +#else
   97.48  #define __smp_processor_id()	0
   97.49 +#endif
   97.50  
   97.51  
   97.52  // FOLLOWING ADDED FOR XEN POST-NGIO and/or LINUX 2.6.7
    98.1 --- a/xen/include/asm-ia64/domain.h	Sun Oct 30 13:52:38 2005 +0100
    98.2 +++ b/xen/include/asm-ia64/domain.h	Sun Oct 30 14:00:35 2005 +0100
    98.3 @@ -49,6 +49,8 @@ struct arch_vcpu {
    98.4  	TR_ENTRY dtrs[NDTRS];
    98.5  	TR_ENTRY itlb;
    98.6  	TR_ENTRY dtlb;
    98.7 +	unsigned int itr_regions;
    98.8 +	unsigned int dtr_regions;
    98.9  	unsigned long itlb_pte;
   98.10  	unsigned long dtlb_pte;
   98.11  	unsigned long irr[4];
    99.1 --- a/xen/include/asm-ia64/event.h	Sun Oct 30 13:52:38 2005 +0100
    99.2 +++ b/xen/include/asm-ia64/event.h	Sun Oct 30 14:00:35 2005 +0100
    99.3 @@ -14,6 +14,21 @@
    99.4  
    99.5  static inline void evtchn_notify(struct vcpu *v)
    99.6  {
    99.7 +    /*
    99.8 +     * NB1. 'vcpu_flags' and 'processor' must be checked /after/ update of
    99.9 +     * pending flag. These values may fluctuate (after all, we hold no
   99.10 +     * locks) but the key insight is that each change will cause
   99.11 +     * evtchn_upcall_pending to be polled.
   99.12 +     * 
   99.13 +     * NB2. We save VCPUF_running across the unblock to avoid a needless
   99.14 +     * IPI for domains that we IPI'd to unblock.
   99.15 +     */
   99.16 +    int running = test_bit(_VCPUF_running, &v->vcpu_flags);
   99.17 +    vcpu_unblock(v);
   99.18 +    if ( running )
   99.19 +        smp_send_event_check_cpu(v->processor);
   99.20 +
   99.21 +    if(!VMX_DOMAIN(v))
   99.22  	vcpu_pend_interrupt(v, v->vcpu_info->arch.evtchn_vector);
   99.23  }
   99.24  
   100.1 --- a/xen/include/asm-ia64/linux-xen/asm/spinlock.h	Sun Oct 30 13:52:38 2005 +0100
   100.2 +++ b/xen/include/asm-ia64/linux-xen/asm/spinlock.h	Sun Oct 30 14:00:35 2005 +0100
   100.3 @@ -17,11 +17,16 @@
   100.4  #include <asm/intrinsics.h>
   100.5  #include <asm/system.h>
   100.6  
   100.7 +#define DEBUG_SPINLOCK
   100.8 +
   100.9  typedef struct {
  100.10  	volatile unsigned int lock;
  100.11  #ifdef CONFIG_PREEMPT
  100.12  	unsigned int break_lock;
  100.13  #endif
  100.14 +#ifdef DEBUG_SPINLOCK
  100.15 +	void *locker;
  100.16 +#endif
  100.17  #ifdef XEN
  100.18  	unsigned char recurse_cpu;
  100.19  	unsigned char recurse_cnt;
  100.20 @@ -96,6 +101,10 @@ static inline void
  100.21  		      : "=r"(ptr) : "r"(ptr), "r" (flags) : IA64_SPINLOCK_CLOBBERS);
  100.22  # endif /* CONFIG_MCKINLEY */
  100.23  #endif
  100.24 +
  100.25 +#ifdef DEBUG_SPINLOCK
  100.26 +	asm volatile ("mov %0=ip" : "=r" (lock->locker));
  100.27 +#endif
  100.28  }
  100.29  #define _raw_spin_lock(lock) _raw_spin_lock_flags(lock, 0)
  100.30  #else /* !ASM_SUPPORTED */
   101.1 --- a/xen/include/asm-ia64/linux-xen/linux/hardirq.h	Sun Oct 30 13:52:38 2005 +0100
   101.2 +++ b/xen/include/asm-ia64/linux-xen/linux/hardirq.h	Sun Oct 30 14:00:35 2005 +0100
   101.3 @@ -67,11 +67,7 @@
   101.4   */
   101.5  #define in_irq()		(hardirq_count())
   101.6  #define in_softirq()		(softirq_count())
   101.7 -#ifdef XEN
   101.8 -#define in_interrupt()		0 		// FIXME SMP LATER
   101.9 -#else
  101.10  #define in_interrupt()		(irq_count())
  101.11 -#endif
  101.12  
  101.13  #if defined(CONFIG_PREEMPT) && !defined(CONFIG_PREEMPT_BKL)
  101.14  # define in_atomic()	((preempt_count() & ~PREEMPT_ACTIVE) != kernel_locked())
   102.1 --- a/xen/include/asm-ia64/linux-xen/linux/interrupt.h	Sun Oct 30 13:52:38 2005 +0100
   102.2 +++ b/xen/include/asm-ia64/linux-xen/linux/interrupt.h	Sun Oct 30 14:00:35 2005 +0100
   102.3 @@ -88,6 +88,7 @@ static inline void __deprecated save_and
   102.4  #define save_and_cli(x)	save_and_cli(&x)
   102.5  #endif /* CONFIG_SMP */
   102.6  
   102.7 +#ifndef XEN
   102.8  /* SoftIRQ primitives.  */
   102.9  #define local_bh_disable() \
  102.10  		do { add_preempt_count(SOFTIRQ_OFFSET); barrier(); } while (0)
  102.11 @@ -95,6 +96,7 @@ static inline void __deprecated save_and
  102.12  		do { barrier(); sub_preempt_count(SOFTIRQ_OFFSET); } while (0)
  102.13  
  102.14  extern void local_bh_enable(void);
  102.15 +#endif
  102.16  
  102.17  /* PLEASE, avoid to allocate new softirqs, if you need not _really_ high
  102.18     frequency threaded job scheduling. For almost all the purposes
   103.1 --- a/xen/include/asm-ia64/mm.h	Sun Oct 30 13:52:38 2005 +0100
   103.2 +++ b/xen/include/asm-ia64/mm.h	Sun Oct 30 14:00:35 2005 +0100
   103.3 @@ -405,6 +405,7 @@ extern unsigned long totalram_pages;
   103.4  extern int nr_swap_pages;
   103.5  
   103.6  extern unsigned long *mpt_table;
   103.7 +extern unsigned long lookup_domain_mpa(struct domain *d, unsigned long mpaddr);
   103.8  #undef machine_to_phys_mapping
   103.9  #define machine_to_phys_mapping	mpt_table
  103.10  
  103.11 @@ -433,10 +434,10 @@ extern unsigned long *mpt_table;
  103.12  
  103.13  #define __gpfn_is_mem(_d, gpfn)				\
  103.14  	(__gpfn_valid(_d, gpfn) ?			\
  103.15 -	(lookup_domain_mpa((_d), ((gpfn)<<PAGE_SHIFT) & GPFN_IO_MASK) == GPFN_MEM) : 0)
  103.16 +	((lookup_domain_mpa((_d), ((gpfn)<<PAGE_SHIFT)) & GPFN_IO_MASK) == GPFN_MEM) : 0)
  103.17  
  103.18  
  103.19 -//#define __gpa_to_mpa(_d, gpa)   \
  103.20 -//    ((__gpfn_to_mfn((_d),(gpa)>>PAGE_SHIFT)<<PAGE_SHIFT)|((gpa)&~PAGE_MASK))
  103.21 +#define __gpa_to_mpa(_d, gpa)   \
  103.22 +    ((__gpfn_to_mfn((_d),(gpa)>>PAGE_SHIFT)<<PAGE_SHIFT)|((gpa)&~PAGE_MASK))
  103.23  
  103.24  #endif /* __ASM_IA64_MM_H__ */
   104.1 --- a/xen/include/asm-ia64/vhpt.h	Sun Oct 30 13:52:38 2005 +0100
   104.2 +++ b/xen/include/asm-ia64/vhpt.h	Sun Oct 30 14:00:35 2005 +0100
   104.3 @@ -5,27 +5,16 @@
   104.4  #define VHPT_ENABLED_REGION_0_TO_6 1
   104.5  #define VHPT_ENABLED_REGION_7 0
   104.6  
   104.7 +/* Size of the VHPT.  */
   104.8 +#define	VHPT_SIZE_LOG2			24
   104.9  
  104.10 -#if 0
  104.11 +/* Number of entries in the VHPT.  The size of an entry is 4*8B == 32B */
  104.12 +#define	VHPT_NUM_ENTRIES		(1 << (VHPT_SIZE_LOG2 - 5))
  104.13 +
  104.14 +#define VHPT_CACHE_MASK			(VHPT_NUM_ENTRIES - 1)
  104.15  #define	VHPT_CACHE_ENTRY_SIZE		64
  104.16 -#define	VHPT_CACHE_MASK			2097151
  104.17 -#define	VHPT_CACHE_NUM_ENTRIES		32768
  104.18 -#define	VHPT_NUM_ENTRIES		2097152
  104.19 -#define	VHPT_CACHE_ENTRY_SIZE_LOG2	6
  104.20 -#define	VHPT_SIZE_LOG2			26	//????
  104.21 -#define	VHPT_PAGE_SHIFT			26	//????
  104.22 -#else
  104.23 -//#define	VHPT_CACHE_NUM_ENTRIES		2048
  104.24 -//#define	VHPT_NUM_ENTRIES		131072
  104.25 -//#define	VHPT_CACHE_MASK			131071
  104.26 -//#define	VHPT_SIZE_LOG2			22	//????
  104.27 -#define	VHPT_CACHE_ENTRY_SIZE		64
  104.28 -#define	VHPT_CACHE_NUM_ENTRIES		8192
  104.29 -#define	VHPT_NUM_ENTRIES		524288
  104.30 -#define	VHPT_CACHE_MASK			524287
  104.31 -#define	VHPT_SIZE_LOG2			24	//????
  104.32 -#define	VHPT_PAGE_SHIFT			24	//????
  104.33 -#endif
  104.34 +
  104.35 +#define	VHPT_PAGE_SHIFT			VHPT_SIZE_LOG2
  104.36  
  104.37  // FIXME: These should be automatically generated
  104.38  
  104.39 @@ -52,7 +41,7 @@
  104.40  // VHPT collison chain entry (part of the "V-Cache")
  104.41  // DO NOT CHANGE THE SIZE OF THIS STRUCTURE (see vhpt.S banked regs calculations)
  104.42  //
  104.43 -typedef struct vcache_entry {
  104.44 +struct vcache_entry {
  104.45      union {
  104.46          struct {
  104.47              unsigned long tag  : 63; // 0-62
  104.48 @@ -123,12 +112,21 @@ struct vhpt_lf_entry {
  104.49  
  104.50  #define INVALID_TI_TAG 0x8000000000000000L
  104.51  
  104.52 +extern void vhpt_init (void);
  104.53 +extern void zero_vhpt_stats(void);
  104.54 +extern int dump_vhpt_stats(char *buf);
  104.55 +extern void vhpt_flush_address(unsigned long vadr, unsigned long addr_range);
  104.56 +extern void vhpt_multiple_insert(unsigned long vaddr, unsigned long pte,
  104.57 +				 unsigned long logps);
  104.58 +extern void vhpt_insert (unsigned long vadr, unsigned long ptr,
  104.59 +			 unsigned logps);
  104.60 +extern void vhpt_flush(void);
  104.61  #endif /* !__ASSEMBLY */
  104.62  
  104.63  #if !VHPT_ENABLED
  104.64  #define VHPT_CCHAIN_LOOKUP(Name, i_or_d)
  104.65  #else
  104.66 -#ifdef CONFIG_SMP
  104.67 +#if 0 /* One VHPT per cpu! def CONFIG_SMP */
  104.68  #warning "FIXME SMP: VHPT_CCHAIN_LOOKUP needs a semaphore on the VHPT!"
  104.69  #endif
  104.70  
   105.1 --- a/xen/include/asm-ia64/vmx.h	Sun Oct 30 13:52:38 2005 +0100
   105.2 +++ b/xen/include/asm-ia64/vmx.h	Sun Oct 30 14:00:35 2005 +0100
   105.3 @@ -25,6 +25,7 @@
   105.4  #define RR7_SWITCH_SHIFT	12	/* 4k enough */
   105.5  #include <public/io/ioreq.h>
   105.6  
   105.7 +
   105.8  extern void identify_vmx_feature(void);
   105.9  extern unsigned int vmx_enabled;
  105.10  extern void vmx_init_env(void);
   106.1 --- a/xen/include/asm-ia64/xenkregs.h	Sun Oct 30 13:52:38 2005 +0100
   106.2 +++ b/xen/include/asm-ia64/xenkregs.h	Sun Oct 30 14:00:35 2005 +0100
   106.3 @@ -6,7 +6,8 @@
   106.4   */
   106.5  #define IA64_TR_SHARED_INFO	3	/* dtr3: page shared with domain */
   106.6  #define	IA64_TR_VHPT		4	/* dtr4: vhpt */
   106.7 -#define IA64_TR_ARCH_INFO      5
   106.8 +#define IA64_TR_ARCH_INFO	5
   106.9 +#define IA64_TR_PERVP_VHPT	6
  106.10  
  106.11  /* Processor status register bits: */
  106.12  #define IA64_PSR_VM_BIT		46
   107.1 --- a/xen/include/asm-x86/vmx_intercept.h	Sun Oct 30 13:52:38 2005 +0100
   107.2 +++ b/xen/include/asm-x86/vmx_intercept.h	Sun Oct 30 14:00:35 2005 +0100
   107.3 @@ -14,6 +14,16 @@
   107.4  #define VMX_MMIO                    1
   107.5  
   107.6  typedef int (*intercept_action_t)(ioreq_t *);
   107.7 +typedef unsigned long (*vmx_mmio_read_t)(struct vcpu *v,
   107.8 +                                         unsigned long addr,
   107.9 +                                         unsigned long length);
  107.10 +
  107.11 +typedef unsigned long (*vmx_mmio_write_t)(struct vcpu *v,
  107.12 +                                         unsigned long addr,
  107.13 +                                         unsigned long length,
  107.14 +                                         unsigned long val);
  107.15 +
  107.16 +typedef int (*vmx_mmio_check_t)(struct vcpu *v, unsigned long addr);
  107.17  
  107.18  struct io_handler {
  107.19      int                 type;
  107.20 @@ -27,6 +37,16 @@ struct vmx_io_handler {
  107.21      struct  io_handler hdl_list[MAX_IO_HANDLER];
  107.22  };
  107.23  
  107.24 +struct vmx_mmio_handler {
  107.25 +    vmx_mmio_check_t check_handler;
  107.26 +    vmx_mmio_read_t read_handler;
  107.27 +    vmx_mmio_write_t write_handler;
  107.28 +};
  107.29 +
  107.30 +#define VMX_MMIO_HANDLER_NR 1
  107.31 +
  107.32 +extern struct vmx_mmio_handler vmx_mmio_handers[VMX_MMIO_HANDLER_NR];
  107.33 +
  107.34  /* global io interception point in HV */
  107.35  extern int vmx_io_intercept(ioreq_t *p, int type);
  107.36  extern int register_io_handler(unsigned long addr, unsigned long size,
  107.37 @@ -37,10 +57,7 @@ static inline int vmx_portio_intercept(i
  107.38      return vmx_io_intercept(p, VMX_PORTIO);
  107.39  }
  107.40  
  107.41 -static inline int vmx_mmio_intercept(ioreq_t *p)
  107.42 -{
  107.43 -    return vmx_io_intercept(p, VMX_MMIO);
  107.44 -}
  107.45 +int vmx_mmio_intercept(ioreq_t *p);
  107.46  
  107.47  static inline int register_portio_handler(unsigned long addr,
  107.48                                            unsigned long size,
  107.49 @@ -49,11 +66,4 @@ static inline int register_portio_handle
  107.50      return register_io_handler(addr, size, action, VMX_PORTIO);
  107.51  }
  107.52  
  107.53 -static inline int register_mmio_handler(unsigned long addr,
  107.54 -                                        unsigned long size,
  107.55 -                                        intercept_action_t action)
  107.56 -{
  107.57 -    return register_io_handler(addr, size, action, VMX_MMIO);
  107.58 -}
  107.59 -
  107.60  #endif /* _VMX_INTERCEPT_H */
   108.1 --- a/xen/include/asm-x86/vmx_platform.h	Sun Oct 30 13:52:38 2005 +0100
   108.2 +++ b/xen/include/asm-x86/vmx_platform.h	Sun Oct 30 14:00:35 2005 +0100
   108.3 @@ -80,10 +80,13 @@ struct instruction {
   108.4  struct vmx_platform {
   108.5      unsigned long          shared_page_va;
   108.6      unsigned int           nr_vcpu;
   108.7 +    unsigned int           lapic_enable;
   108.8  
   108.9      struct vmx_virpit      vmx_pit;
  108.10      struct vmx_io_handler  vmx_io_handler;
  108.11      struct vmx_virpic      vmx_pic;
  108.12 +    unsigned char          round_info[256];
  108.13 +    spinlock_t             round_robin_lock;
  108.14      int                    interrupt_request;
  108.15  };
  108.16  
   109.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   109.2 +++ b/xen/include/asm-x86/vmx_vlapic.h	Sun Oct 30 14:00:35 2005 +0100
   109.3 @@ -0,0 +1,245 @@
   109.4 +/*
   109.5 + * vmx_vlapic.h: virtualize LAPIC definitions.
   109.6 + * Copyright (c) 2004, Intel Corporation.
   109.7 + *
   109.8 + * This program is free software; you can redistribute it and/or modify it
   109.9 + * under the terms and conditions of the GNU General Public License,
  109.10 + * version 2, as published by the Free Software Foundation.
  109.11 + *
  109.12 + * This program is distributed in the hope it will be useful, but WITHOUT
  109.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  109.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  109.15 + * more details.
  109.16 + *
  109.17 + * You should have received a copy of the GNU General Public License along with
  109.18 + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  109.19 + * Place - Suite 330, Boston, MA 02111-1307 USA.
  109.20 + *
  109.21 + */
  109.22 +
  109.23 +#ifndef VMX_VLAPIC_H
  109.24 +#define VMX_VLAPIC_H
  109.25 +
  109.26 +#include <asm/msr.h>
  109.27 +#include <public/io/ioreq.h>
  109.28 +
  109.29 +#if defined(__i386__) || defined(__x86_64__)
  109.30 +static inline int __fls(uint32_t word)
  109.31 +{
  109.32 +    int bit;
  109.33 +
  109.34 +    __asm__("bsrl %1,%0"
  109.35 +      :"=r" (bit)
  109.36 +      :"rm" (word));
  109.37 +    return word ? bit : -1;
  109.38 +}
  109.39 +#else
  109.40 +#define __fls(x)    generic_fls(x)
  109.41 +static __inline__ int generic_fls(uint32_t x)
  109.42 +{
  109.43 +    int r = 31;
  109.44 +
  109.45 +    if (!x)
  109.46 +        return -1;
  109.47 +    if (!(x & 0xffff0000u)) {
  109.48 +        x <<= 16;
  109.49 +        r -= 16;
  109.50 +    }
  109.51 +    if (!(x & 0xff000000u)) {
  109.52 +        x <<= 8;
  109.53 +        r -= 8;
  109.54 +    }
  109.55 +    if (!(x & 0xf0000000u)) {
  109.56 +        x <<= 4;
  109.57 +        r -= 4;
  109.58 +    }
  109.59 +    if (!(x & 0xc0000000u)) {
  109.60 +        x <<= 2;
  109.61 +        r -= 2;
  109.62 +    }
  109.63 +    if (!(x & 0x80000000u)) {
  109.64 +        x <<= 1;
  109.65 +        r -= 1;
  109.66 +    }
  109.67 +    return r;
  109.68 +}
  109.69 +#endif
  109.70 +
  109.71 +static __inline__ int find_highest_bit(uint32_t *data, int length)
  109.72 +{
  109.73 +    while(length && !data[--length]);
  109.74 +    return __fls(data[length]) +  32 * length;
  109.75 +}
  109.76 +
  109.77 +#define VLAPIC(v)                       (v->arch.arch_vmx.vlapic)
  109.78 +
  109.79 +#define VAPIC_ID_MASK                   0xff
  109.80 +#define VAPIC_LDR_MASK                  (VAPIC_ID_MASK << 24)
  109.81 +#define VLAPIC_VERSION                  0x00050014
  109.82 +
  109.83 +#define VLAPIC_BASE_MSR_MASK            0x00000000fffff900ULL
  109.84 +#define VLAPIC_BASE_MSR_INIT_BASE_ADDR  0xfee00000U
  109.85 +#define VLAPIC_BASE_MSR_BASE_ADDR_MASK  0xfffff000U
  109.86 +#define VLAPIC_BASE_MSR_INIT_VALUE      (VLAPIC_BASE_MSR_INIT_BASE_ADDR | \
  109.87 +                                         MSR_IA32_APICBASE_ENABLE)
  109.88 +#define VLOCAL_APIC_MEM_LENGTH          (1 << 12)
  109.89 +
  109.90 +#define VLAPIC_LVT_TIMER                0
  109.91 +#define VLAPIC_LVT_THERMAL              1
  109.92 +#define VLAPIC_LVT_PERFORM              2
  109.93 +#define VLAPIC_LVT_LINT0                3
  109.94 +#define VLAPIC_LVT_LINT1                4
  109.95 +#define VLAPIC_LVT_ERROR                5
  109.96 +#define VLAPIC_LVT_NUM                  6
  109.97 +
  109.98 +#define VLAPIC_LVT_BIT_MASK             (1 << 16)
  109.99 +#define VLAPIC_LVT_BIT_VECTOR           0xff
 109.100 +#define VLAPIC_LVT_BIT_DELIMOD          (0x7 << 8)
 109.101 +#define VLAPIC_LVT_BIT_DELISTATUS       (1 << 12)
 109.102 +#define VLAPIC_LVT_BIT_POLARITY         (1 << 13)
 109.103 +#define VLAPIC_LVT_BIT_IRR              (1 << 14)
 109.104 +#define VLAPIC_LVT_BIT_TRIG             (1 << 15)
 109.105 +#define VLAPIC_LVT_TIMERMODE            (1 << 17)
 109.106 +
 109.107 +#define VLAPIC_DELIV_MODE_FIXED          0x0
 109.108 +#define VLAPIC_DELIV_MODE_LPRI           0x1
 109.109 +#define VLAPIC_DELIV_MODE_SMI            0x2
 109.110 +#define VLAPIC_DELIV_MODE_RESERVED       0x3
 109.111 +#define VLAPIC_DELIV_MODE_NMI            0x4
 109.112 +#define VLAPIC_DELIV_MODE_INIT           0x5
 109.113 +#define VLAPIC_DELIV_MODE_STARTUP        0x6
 109.114 +#define VLAPIC_DELIV_MODE_EXT            0x7
 109.115 +
 109.116 +
 109.117 +
 109.118 +#define VLAPIC_NO_SHORTHAND             0x0
 109.119 +#define VLAPIC_SHORTHAND_SELF           0x1
 109.120 +#define VLAPIC_SHORTHAND_INCLUDE_SELF   0x2
 109.121 +#define VLAPIC_SHORTHAND_EXCLUDE_SELF   0x3
 109.122 +
 109.123 +#define vlapic_lvt_timer_enabled(vlapic)    \
 109.124 +  (!(vlapic->lvt[VLAPIC_LVT_TIMER] & VLAPIC_LVT_BIT_MASK))
 109.125 +
 109.126 +#define vlapic_lvt_vector(vlapic, type)   \
 109.127 +  (vlapic->lvt[type] & VLAPIC_LVT_BIT_VECTOR)
 109.128 +
 109.129 +#define vlapic_lvt_dm(value)        ((value >> 8) && 7)
 109.130 +#define vlapic_lvt_timer_period(vlapic) \
 109.131 +  (vlapic->lvt[VLAPIC_LVT_TIMER] & VLAPIC_LVT_TIMERMODE)
 109.132 +
 109.133 +#define vlapic_isr_status(vlapic,vector)    \
 109.134 +  test_bit(vector, &vlapic->isr[0])
 109.135 +
 109.136 +#define vlapic_irr_status(vlapic,vector)    \
 109.137 +  test_bit(vector, &vlapic->irr[0])
 109.138 +
 109.139 +#define vlapic_set_isr(vlapic,vector) \
 109.140 +  test_and_set_bit(vector, &vlapic->isr[0])
 109.141 +
 109.142 +#define vlapic_set_irr(vlapic,vector)      \
 109.143 +  test_and_set_bit(vector, &vlapic->irr[0])
 109.144 +
 109.145 +#define vlapic_clear_irr(vlapic,vector)      \
 109.146 +  clear_bit(vector, &vlapic->irr[0])
 109.147 +#define vlapic_clear_isr(vlapic,vector)     \
 109.148 +  clear_bit(vector, &vlapic->isr[0])
 109.149 +
 109.150 +#define vlapic_enabled(vlapic)               \
 109.151 +  (!(vlapic->status &                           \
 109.152 +     (VLAPIC_GLOB_DISABLE_MASK | VLAPIC_SOFTWARE_DISABLE_MASK)))
 109.153 +
 109.154 +#define vlapic_global_enabled(vlapic)               \
 109.155 +  !(test_bit(_VLAPIC_GLOB_DISABLE, &(vlapic)->status))
 109.156 +
 109.157 +typedef struct direct_intr_info {
 109.158 +    int deliver_mode;
 109.159 +    int source[6];
 109.160 +} direct_intr_info_t;
 109.161 +
 109.162 +#define VLAPIC_INIT_SIPI_SIPI_STATE_NORM          0
 109.163 +#define VLAPIC_INIT_SIPI_SIPI_STATE_WAIT_SIPI     1
 109.164 +
 109.165 +struct vlapic
 109.166 +{
 109.167 +    //FIXME check what would be 64 bit on EM64T
 109.168 +    uint32_t           version;
 109.169 +#define _VLAPIC_GLOB_DISABLE            0x0
 109.170 +#define VLAPIC_GLOB_DISABLE_MASK        0x1
 109.171 +#define VLAPIC_SOFTWARE_DISABLE_MASK    0x2
 109.172 +#define _VLAPIC_BSP_ACCEPT_PIC          0x3
 109.173 +    uint32_t           status;
 109.174 +    uint32_t           id;
 109.175 +    uint32_t           vcpu_id;
 109.176 +    unsigned long      base_address;
 109.177 +    uint32_t           isr[8];
 109.178 +    uint32_t           irr[INTR_LEN_32];
 109.179 +    uint32_t           tmr[INTR_LEN_32];
 109.180 +    uint32_t           task_priority;
 109.181 +    uint32_t           processor_priority;
 109.182 +    uint32_t           logical_dest;
 109.183 +    uint32_t           dest_format;
 109.184 +    uint32_t           spurious_vec;
 109.185 +    uint32_t           lvt[6];
 109.186 +    uint32_t           timer_initial;
 109.187 +    uint32_t           timer_current;
 109.188 +    uint32_t           timer_divconf;
 109.189 +    uint32_t           timer_divide_counter;
 109.190 +    struct ac_timer    vlapic_timer;
 109.191 +    int                intr_pending_count[MAX_VECTOR];
 109.192 +    s_time_t           timer_current_update;
 109.193 +    uint32_t           icr_high;
 109.194 +    uint32_t           icr_low;
 109.195 +    direct_intr_info_t direct_intr;
 109.196 +    uint32_t           err_status;
 109.197 +    unsigned long      init_ticks;
 109.198 +    uint32_t           err_write_count;
 109.199 +    uint64_t           apic_base_msr;
 109.200 +    uint32_t           init_sipi_sipi_state;
 109.201 +    struct vcpu        *vcpu;
 109.202 +    struct domain      *domain;
 109.203 +};
 109.204 +
 109.205 +static inline int  vlapic_timer_active(struct vlapic *vlapic)
 109.206 +{
 109.207 +    return  active_ac_timer(&(vlapic->vlapic_timer));
 109.208 +}
 109.209 +
 109.210 +int vlapic_find_highest_irr(struct vlapic *vlapic);
 109.211 +
 109.212 +int vlapic_find_highest_isr(struct vlapic *vlapic);
 109.213 +
 109.214 +static uint32_t inline vlapic_get_base_address(struct vlapic *vlapic)
 109.215 +{
 109.216 +    return (vlapic->apic_base_msr & VLAPIC_BASE_MSR_BASE_ADDR_MASK);
 109.217 +}
 109.218 +
 109.219 +void vlapic_post_injection(struct vcpu* v, int vector, int deliver_mode);
 109.220 +
 109.221 +int cpu_get_apic_interrupt(struct vcpu* v, int *mode);
 109.222 +
 109.223 +extern uint32_t vlapic_update_ppr(struct vlapic *vlapic);
 109.224 +
 109.225 +int vlapic_update(struct vcpu *v);
 109.226 +
 109.227 +extern int vlapic_init(struct vcpu *vc);
 109.228 +
 109.229 +extern void vlapic_msr_set(struct vlapic *vlapic, uint64_t value);
 109.230 +
 109.231 +int vlapic_range(struct vcpu *v, unsigned long addr);
 109.232 +
 109.233 +unsigned long vlapic_write(struct vcpu *v, unsigned long address,
 109.234 +                           unsigned long len, unsigned long val);
 109.235 +
 109.236 +unsigned long vlapic_read(struct vcpu *v, unsigned long address,
 109.237 +                          unsigned long len);
 109.238 +
 109.239 +int vlapic_accept_pic_intr(struct vcpu *v);
 109.240 +
 109.241 +struct vlapic* apic_round_robin(struct domain *d,
 109.242 +                                uint8_t dest_mode,
 109.243 +                                uint8_t vector,
 109.244 +                                uint32_t bitmap);
 109.245 +
 109.246 +int vmx_apic_support(struct domain *d);
 109.247 +
 109.248 +#endif /* VMX_VLAPIC_H */
   110.1 --- a/xen/include/asm-x86/vmx_vmcs.h	Sun Oct 30 13:52:38 2005 +0100
   110.2 +++ b/xen/include/asm-x86/vmx_vmcs.h	Sun Oct 30 14:00:35 2005 +0100
   110.3 @@ -22,6 +22,7 @@
   110.4  #include <asm/config.h>
   110.5  #include <asm/vmx_cpu.h>
   110.6  #include <asm/vmx_platform.h>
   110.7 +#include <asm/vmx_vlapic.h>
   110.8  #include <public/vmx_assist.h>
   110.9  
  110.10  extern int start_vmx(void);
  110.11 @@ -96,6 +97,7 @@ struct arch_vmx_struct {
  110.12      struct msr_state        msr_content;
  110.13      struct mmio_op          mmio_op;  /* MMIO */
  110.14      void                    *io_bitmap_a, *io_bitmap_b;
  110.15 +    struct vlapic           *vlapic;
  110.16      u64                     tsc_offset;
  110.17  };
  110.18  
  110.19 @@ -272,18 +274,21 @@ enum vmcs_field {
  110.20  
  110.21  #define VMX_DEBUG 1
  110.22  #if VMX_DEBUG
  110.23 -#define DBG_LEVEL_0     (1 << 0)
  110.24 -#define DBG_LEVEL_1     (1 << 1)
  110.25 -#define DBG_LEVEL_2     (1 << 2)
  110.26 -#define DBG_LEVEL_3     (1 << 3)
  110.27 -#define DBG_LEVEL_IO    (1 << 4)
  110.28 -#define DBG_LEVEL_VMMU  (1 << 5)
  110.29 +#define DBG_LEVEL_0                 (1 << 0)
  110.30 +#define DBG_LEVEL_1                 (1 << 1)
  110.31 +#define DBG_LEVEL_2                 (1 << 2)
  110.32 +#define DBG_LEVEL_3                 (1 << 3)
  110.33 +#define DBG_LEVEL_IO                (1 << 4)
  110.34 +#define DBG_LEVEL_VMMU              (1 << 5)
  110.35 +#define DBG_LEVEL_VLAPIC            (1 << 6)
  110.36 +#define DBG_LEVEL_VLAPIC_TIMER      (1 << 7)
  110.37 +#define DBG_LEVEL_VLAPIC_INTERRUPT  (1 << 7)
  110.38  
  110.39  extern unsigned int opt_vmx_debug_level;
  110.40  #define VMX_DBG_LOG(level, _f, _a...)           \
  110.41      if ((level) & opt_vmx_debug_level)          \
  110.42          printk("[VMX:%d.%d] " _f "\n",          \
  110.43 -                current->domain->domain_id, current->vcpu_id, ## _a)
  110.44 +               current->domain->domain_id, current->vcpu_id, ## _a)
  110.45  #else
  110.46  #define VMX_DBG_LOG(level, _f, _a...)
  110.47  #endif
   111.1 --- a/xen/include/public/arch-ia64.h	Sun Oct 30 13:52:38 2005 +0100
   111.2 +++ b/xen/include/public/arch-ia64.h	Sun Oct 30 14:00:35 2005 +0100
   111.3 @@ -38,6 +38,33 @@ typedef struct {
   111.4  
   111.5  #define INVALID_MFN       (~0UL)
   111.6  
   111.7 +#define MEM_G   (1UL << 30)	
   111.8 +#define MEM_M   (1UL << 20)	
   111.9 +
  111.10 +#define MMIO_START       (3 * MEM_G)
  111.11 +#define MMIO_SIZE        (512 * MEM_M)
  111.12 +
  111.13 +#define VGA_IO_START     0xA0000UL
  111.14 +#define VGA_IO_SIZE      0x20000
  111.15 +
  111.16 +#define LEGACY_IO_START  (MMIO_START + MMIO_SIZE)
  111.17 +#define LEGACY_IO_SIZE   (64*MEM_M)  
  111.18 +
  111.19 +#define IO_PAGE_START (LEGACY_IO_START + LEGACY_IO_SIZE)
  111.20 +#define IO_PAGE_SIZE  PAGE_SIZE
  111.21 +
  111.22 +#define STORE_PAGE_START (IO_PAGE_START + IO_PAGE_SIZE)
  111.23 +#define STORE_PAGE_SIZE	 PAGE_SIZE
  111.24 +
  111.25 +#define IO_SAPIC_START   0xfec00000UL
  111.26 +#define IO_SAPIC_SIZE    0x100000
  111.27 +
  111.28 +#define PIB_START 0xfee00000UL
  111.29 +#define PIB_SIZE 0x100000 
  111.30 +
  111.31 +#define GFW_START        (4*MEM_G -16*MEM_M)
  111.32 +#define GFW_SIZE         (16*MEM_M)
  111.33 +
  111.34  /*
  111.35   * NB. This may become a 64-bit count with no shift. If this happens then the 
  111.36   * structure size will still be 8 bytes, so no other alignments will change.
   112.1 --- a/xen/include/public/io/ioreq.h	Sun Oct 30 13:52:38 2005 +0100
   112.2 +++ b/xen/include/public/io/ioreq.h	Sun Oct 30 14:00:35 2005 +0100
   112.3 @@ -29,11 +29,11 @@
   112.4  #define STATE_IORESP_READY      3
   112.5  #define STATE_IORESP_HOOK       4
   112.6  
   112.7 -#define IOREQ_TYPE_PIO  0 /* pio */
   112.8 -#define IOREQ_TYPE_COPY  1 /* mmio ops */
   112.9 -#define IOREQ_TYPE_AND  2
  112.10 -#define IOREQ_TYPE_OR  3
  112.11 -#define IOREQ_TYPE_XOR  4
  112.12 +#define IOREQ_TYPE_PIO          0 /* pio */
  112.13 +#define IOREQ_TYPE_COPY         1 /* mmio ops */
  112.14 +#define IOREQ_TYPE_AND          2
  112.15 +#define IOREQ_TYPE_OR           3
  112.16 +#define IOREQ_TYPE_XOR          4
  112.17  
  112.18  /*
  112.19   * VMExit dispatcher should cooperate with instruction decoder to
  112.20 @@ -55,9 +55,10 @@ typedef struct {
  112.21      uint8_t type;    /* I/O type                     */
  112.22  } ioreq_t;
  112.23  
  112.24 -#define MAX_VECTOR    256
  112.25 +#define MAX_VECTOR      256
  112.26  #define BITS_PER_BYTE   8
  112.27  #define INTR_LEN        (MAX_VECTOR/(BITS_PER_BYTE * sizeof(uint64_t)))
  112.28 +#define INTR_LEN_32     (MAX_VECTOR/(BITS_PER_BYTE * sizeof(uint32_t)))
  112.29  
  112.30  typedef struct {
  112.31      uint16_t  pic_elcr;
   113.1 --- a/xen/include/public/io/vmx_vpic.h	Sun Oct 30 13:52:38 2005 +0100
   113.2 +++ b/xen/include/public/io/vmx_vpic.h	Sun Oct 30 14:00:35 2005 +0100
   113.3 @@ -76,7 +76,7 @@ void pic_update_irq(struct vmx_virpic *s
   113.4  uint32_t pic_intack_read(struct vmx_virpic *s);
   113.5  void register_pic_io_hook (void);
   113.6  int cpu_get_pic_interrupt(struct vcpu *v, int *type);
   113.7 -int is_pit_irq(struct vcpu *v, int irq);
   113.8 +int is_pit_irq(struct vcpu *v, int irq, int type);
   113.9  void do_pic_irqs (struct vmx_virpic *s, uint16_t irqs);
  113.10  void do_pic_irqs_clear (struct vmx_virpic *s, uint16_t irqs);
  113.11  
   114.1 --- a/xen/include/public/xen.h	Sun Oct 30 13:52:38 2005 +0100
   114.2 +++ b/xen/include/public/xen.h	Sun Oct 30 14:00:35 2005 +0100
   114.3 @@ -410,6 +410,7 @@ typedef struct shared_info {
   114.4  #define MAX_GUEST_CMDLINE 1024
   114.5  typedef struct start_info {
   114.6      /* THE FOLLOWING ARE FILLED IN BOTH ON INITIAL BOOT AND ON RESUME.    */
   114.7 +    char magic[32];             /* "Xen-<version>.<subversion>". */
   114.8      unsigned long nr_pages;     /* Total pages allocated to this domain.  */
   114.9      unsigned long shared_info;  /* MACHINE address of shared info struct. */
  114.10      uint32_t flags;             /* SIF_xxx flags.                         */
   115.1 --- a/xen/include/xen/sched.h	Sun Oct 30 13:52:38 2005 +0100
   115.2 +++ b/xen/include/xen/sched.h	Sun Oct 30 14:00:35 2005 +0100
   115.3 @@ -101,7 +101,6 @@ struct domain
   115.4      struct list_head xenpage_list;    /* linked list, of size xenheap_pages */
   115.5      unsigned int     tot_pages;       /* number of pages currently possesed */
   115.6      unsigned int     max_pages;       /* maximum value for tot_pages        */
   115.7 -    unsigned int     next_io_page;    /* next io pfn to give to domain      */
   115.8      unsigned int     xenheap_pages;   /* # pages allocated from Xen heap    */
   115.9  
  115.10      /* Scheduling. */