svn commit: r216396 - in projects/stable_7_xen/sys: conf i386/conf i386/include i386/include/xen i386/xen xen/evtchn

Sean Bruno sbruno at FreeBSD.org
Sun Dec 12 20:48:08 UTC 2010


Author: sbruno
Date: Sun Dec 12 20:48:08 2010
New Revision: 216396
URL: http://svn.freebsd.org/changeset/base/216396

Log:
  Add non-compiling Xen DomU code here.  I love it when I get in over my head.

Added:
  projects/stable_7_xen/sys/i386/conf/XEN
  projects/stable_7_xen/sys/i386/include/xen/
  projects/stable_7_xen/sys/i386/include/xen/features.h
  projects/stable_7_xen/sys/i386/include/xen/hypercall.h
  projects/stable_7_xen/sys/i386/include/xen/synch_bitops.h
  projects/stable_7_xen/sys/i386/include/xen/xen-os.h
  projects/stable_7_xen/sys/i386/include/xen/xen_clock_util.h
  projects/stable_7_xen/sys/i386/include/xen/xenfunc.h
  projects/stable_7_xen/sys/i386/include/xen/xenpmap.h
  projects/stable_7_xen/sys/i386/include/xen/xenstored.h
  projects/stable_7_xen/sys/i386/include/xen/xenvar.h
  projects/stable_7_xen/sys/i386/xen/
  projects/stable_7_xen/sys/i386/xen/clock.c
  projects/stable_7_xen/sys/i386/xen/exception.s
  projects/stable_7_xen/sys/i386/xen/locore.s
  projects/stable_7_xen/sys/i386/xen/mp_machdep.c
  projects/stable_7_xen/sys/i386/xen/mptable.c
  projects/stable_7_xen/sys/i386/xen/pmap.c
  projects/stable_7_xen/sys/i386/xen/xen_clock_util.c
  projects/stable_7_xen/sys/i386/xen/xen_machdep.c
  projects/stable_7_xen/sys/i386/xen/xen_rtc.c
Modified:
  projects/stable_7_xen/sys/conf/options.i386
  projects/stable_7_xen/sys/i386/include/atomic.h
  projects/stable_7_xen/sys/i386/include/pcpu.h
  projects/stable_7_xen/sys/i386/include/pmap.h
  projects/stable_7_xen/sys/xen/evtchn/evtchn.c

Modified: projects/stable_7_xen/sys/conf/options.i386
==============================================================================
--- projects/stable_7_xen/sys/conf/options.i386	Sun Dec 12 16:56:16 2010	(r216395)
+++ projects/stable_7_xen/sys/conf/options.i386	Sun Dec 12 20:48:08 2010	(r216396)
@@ -149,3 +149,6 @@ STOP_NMI		opt_cpu.h
 
 # BPF just-in-time compiler
 BPF_JITTER		opt_bpf.h
+
+# Xen DomU Support
+XEN			opt_global.h

Added: projects/stable_7_xen/sys/i386/conf/XEN
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ projects/stable_7_xen/sys/i386/conf/XEN	Sun Dec 12 20:48:08 2010	(r216396)
@@ -0,0 +1,89 @@
+#
+# XEN -- Kernel configuration for i386 XEN DomU
+#
+# $FreeBSD: stable/8/sys/i386/conf/XEN 216008 2010-11-28 16:25:16Z cperciva $
+
+cpu		I686_CPU
+ident		XEN
+
+makeoptions	DEBUG=-g		# Build kernel with gdb(1) debug symbols
+makeoptions	MODULES_OVERRIDE=""
+
+options 	SCHED_ULE		# ULE scheduler
+options 	PREEMPTION		# Enable kernel thread preemption
+#options 	SCHED_4BSD		 
+
+options 	INET			# InterNETworking
+options 	INET6			# IPv6 communications protocols
+options 	SCTP			# Stream Control Transmission Protocol
+options 	FFS			# Berkeley Fast Filesystem
+options 	SOFTUPDATES		# Enable FFS soft updates support
+options 	UFS_ACL			# Support for access control lists
+options 	UFS_DIRHASH		# Improve performance on big directories
+options 	UFS_GJOURNAL		# Enable gjournal-based UFS journaling
+options 	NFSCLIENT		# Network Filesystem Client
+options 	NFSSERVER		# Network Filesystem Server
+options 	NFSLOCKD		# Network Lock Manager
+options 	NFS_ROOT		# NFS usable as /, requires NFSCLIENT
+options 	MSDOSFS			# MSDOS Filesystem
+options 	CD9660			# ISO 9660 Filesystem
+options 	PROCFS			# Process filesystem (requires PSEUDOFS)
+options 	PSEUDOFS		# Pseudo-filesystem framework
+options 	GEOM_PART_GPT		# GUID Partition Tables.
+options 	GEOM_LABEL		# Provides labelization
+options 	COMPAT_43TTY		# BSD 4.3 TTY compat (sgtty)
+options 	COMPAT_FREEBSD4		# Compatible with FreeBSD4
+options 	COMPAT_FREEBSD5		# Compatible with FreeBSD5
+options 	COMPAT_FREEBSD6		# Compatible with FreeBSD6
+options 	KTRACE			# ktrace(1) support
+options 	STACK			# stack(9) support
+options 	SYSVSHM			# SYSV-style shared memory
+options 	SYSVMSG			# SYSV-style message queues
+options 	SYSVSEM			# SYSV-style semaphores
+options 	_KPOSIX_PRIORITY_SCHEDULING # POSIX P1003_1B real-time extensions
+options 	KBD_INSTALL_CDEV	# install a CDEV entry in /dev
+options 	AUDIT			# Security event auditing
+
+# Debugging for use in -current
+options 	KDB			# Enable kernel debugger support.
+options 	DDB			# Support DDB.
+options 	GDB			# Support remote GDB.
+options 	INVARIANTS		# Enable calls of extra sanity checking
+options 	INVARIANT_SUPPORT	# Extra sanity checks of internal structures, required by INVARIANTS
+options 	WITNESS			# Enable checks to detect deadlocks and cycles
+options 	WITNESS_SKIPSPIN	# Don't run witness on spinlocks for speed
+
+options 	PAE
+nooption	NATIVE
+option		XEN
+nodevice	atpic
+nodevice	isa
+options 	MCLSHIFT=12
+
+# To make an SMP kernel, the next two lines are needed
+options 	SMP			# Symmetric MultiProcessor Kernel
+device		apic			# I/O APIC
+
+
+#device		atkbdc		# AT keyboard controller
+#device		atkbd		# AT keyboard
+device		psm		# PS/2 mouse
+device		pci
+
+#device		kbdmux		# keyboard multiplexer
+
+# Pseudo devices.
+device		loop		# Network loopback
+device		random		# Entropy device
+device		ether		# Ethernet support
+device		tun		# Packet tunnel.
+device		pty		# Pseudo-ttys (telnet etc)
+device		md		# Memory "disks"
+device		gif		# IPv6 and IPv4 tunneling
+device		faith		# IPv6-to-IPv4 relaying (translation)
+
+# The `bpf' device enables the Berkeley Packet Filter.
+# Be aware of the administrative consequences of enabling this!
+# Note that 'bpf' is required for DHCP.
+device		bpf		# Berkeley packet filter
+

Modified: projects/stable_7_xen/sys/i386/include/atomic.h
==============================================================================
--- projects/stable_7_xen/sys/i386/include/atomic.h	Sun Dec 12 16:56:16 2010	(r216395)
+++ projects/stable_7_xen/sys/i386/include/atomic.h	Sun Dec 12 20:48:08 2010	(r216396)
@@ -32,6 +32,10 @@
 #error this file needs sys/cdefs.h as a prerequisite
 #endif
 
+#define	mb()	__asm __volatile("lock; addl $0,(%%esp)" : : : "memory")
+#define	wmb()	__asm __volatile("lock; addl $0,(%%esp)" : : : "memory")
+#define	rmb()	__asm __volatile("lock; addl $0,(%%esp)" : : : "memory")
+
 /*
  * Various simple operations on memory, each of which is atomic in the
  * presence of interrupts and multiple processors.

Modified: projects/stable_7_xen/sys/i386/include/pcpu.h
==============================================================================
--- projects/stable_7_xen/sys/i386/include/pcpu.h	Sun Dec 12 16:56:16 2010	(r216395)
+++ projects/stable_7_xen/sys/i386/include/pcpu.h	Sun Dec 12 20:48:08 2010	(r216396)
@@ -43,6 +43,39 @@
  * to each CPU's data can be set up for things like "check curproc on all
  * other processors"
  */
+
+#ifdef XEN
+#ifndef NR_VIRQS
+#define NR_VIRQS        24
+#endif
+#ifndef NR_IPIS
+#define NR_IPIS         2
+#endif
+
+/* These are peridically updated in shared_info, and then copied here. */
+struct shadow_time_info {
+        uint64_t tsc_timestamp;     /* TSC at last update of time vals.  */
+        uint64_t system_timestamp;  /* Time, in nanosecs, since boot.    */
+        uint32_t tsc_to_nsec_mul;
+        uint32_t tsc_to_usec_mul;
+        int tsc_shift;
+        uint32_t version;
+};
+
+#define PCPU_XEN_FIELDS							\
+	;								\
+	u_int	pc_cr3;		/* track cr3 for R1/R3*/		\
+	vm_paddr_t *pc_pdir_shadow;					\
+	uint64_t pc_processed_system_time;				\
+	struct shadow_time_info pc_shadow_time;				\
+	int	pc_resched_irq;						\
+	int	pc_callfunc_irq;					\
+	int	pc_virq_to_irq[NR_VIRQS];				\
+	int	pc_ipi_to_irq[NR_IPIS]
+#else
+#define PCPU_XEN_FIELDS
+#endif
+
 #define	PCPU_MD_FIELDS							\
 	struct	pcpu *pc_prvspace;	/* Self-reference */		\
 	struct	pmap *pc_curpmap;					\
@@ -55,6 +88,7 @@
 	u_int	pc_apic_id;						\
 	int	pc_private_tss;		/* Flag indicating private tss*/\
 	u_int	pc_cmci_mask		/* MCx banks for CMCI */	\
+	PCPU_XEN_FIELDS
 
 
 #ifdef _KERNEL

Modified: projects/stable_7_xen/sys/i386/include/pmap.h
==============================================================================
--- projects/stable_7_xen/sys/i386/include/pmap.h	Sun Dec 12 16:56:16 2010	(r216395)
+++ projects/stable_7_xen/sys/i386/include/pmap.h	Sun Dec 12 20:48:08 2010	(r216396)
@@ -189,9 +189,7 @@ extern pd_entry_t PTDpde[];
 extern pdpt_entry_t *IdlePDPT;
 #endif
 extern pd_entry_t *IdlePTD;	/* physical address of "Idle" state directory */
-#endif
 
-#ifdef _KERNEL
 /*
  * Translate a virtual address to the kernel virtual address of its page table
  * entry (PTE).  This can be used recursively.  If the address of a PTE as
@@ -210,6 +208,72 @@ extern pd_entry_t *IdlePTD;	/* physical 
  */
 #define	vtophys(va)	pmap_kextract((vm_offset_t)(va))
 
+#ifdef XEN
+#include <sys/param.h>
+#include <machine/xen/xen-os.h>
+#include <machine/xen/xenvar.h>
+#include <machine/xen/xenpmap.h>
+
+extern pt_entry_t pg_nx;
+
+#define PG_KERNEL  (PG_V | PG_A | PG_RW | PG_M)
+
+#define MACH_TO_VM_PAGE(ma) PHYS_TO_VM_PAGE(xpmap_mtop((ma)))
+#define VM_PAGE_TO_MACH(m) xpmap_ptom(VM_PAGE_TO_PHYS((m)))
+
+static __inline vm_paddr_t
+pmap_kextract_ma(vm_offset_t va)
+{
+        vm_paddr_t ma;
+        if ((ma = PTD[va >> PDRSHIFT]) & PG_PS) {
+                ma = (ma & ~(NBPDR - 1)) | (va & (NBPDR - 1));
+        } else {
+                ma = (*vtopte(va) & PG_FRAME) | (va & PAGE_MASK);
+        }
+        return ma;
+}
+
+static __inline vm_paddr_t
+pmap_kextract(vm_offset_t va)
+{
+        return xpmap_mtop(pmap_kextract_ma(va));
+}
+#define vtomach(va)     pmap_kextract_ma(((vm_offset_t) (va)))
+
+vm_paddr_t pmap_extract_ma(struct pmap *pmap, vm_offset_t va);
+
+void    pmap_kenter_ma(vm_offset_t va, vm_paddr_t pa);
+void    pmap_map_readonly(struct pmap *pmap, vm_offset_t va, int len);
+void    pmap_map_readwrite(struct pmap *pmap, vm_offset_t va, int len);
+
+static __inline pt_entry_t
+pte_load_store(pt_entry_t *ptep, pt_entry_t v)
+{
+	pt_entry_t r;
+
+	v = xpmap_ptom(v);
+	r = *ptep;
+	PT_SET_VA(ptep, v, TRUE);
+	return (r);
+}
+
+static __inline pt_entry_t
+pte_load_store_ma(pt_entry_t *ptep, pt_entry_t v)
+{
+	pt_entry_t r;
+
+	r = *ptep;
+	PT_SET_VA_MA(ptep, v, TRUE);
+	return (r);
+}
+
+#define	pte_load_clear(ptep)	pte_load_store((ptep), (pt_entry_t)0ULL)
+
+#define	pte_store(ptep, pte)	pte_load_store((ptep), (pt_entry_t)pte)
+#define	pte_store_ma(ptep, pte)	pte_load_store_ma((ptep), (pt_entry_t)pte)
+#define	pde_store_ma(ptep, pte)	pte_load_store_ma((ptep), (pt_entry_t)pte)
+
+#elif !defined(XEN)
 
 /*
  * KPTmap is a linear mapping of the kernel page table.  It differs from the
@@ -251,7 +315,10 @@ pmap_kextract(vm_offset_t va)
 	return (pa);
 }
 
-#ifdef PAE
+#define PT_UPDATES_FLUSH()
+#endif
+
+#if defined(PAE) && !defined(XEN)
 
 #define	pde_cmpset(pdep, old, new) \
 				atomic_cmpset_64((pdep), (old), (new))
@@ -310,7 +377,7 @@ atomic_cmpset_64(volatile uint64_t *dst,
 
 extern pt_entry_t pg_nx;
 
-#else /* PAE */
+#elif !defined(PAE) && !defined (XEN)
 
 #define	pde_cmpset(pdep, old, new) \
 				atomic_cmpset_int((pdep), (old), (new))

Added: projects/stable_7_xen/sys/i386/include/xen/features.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ projects/stable_7_xen/sys/i386/include/xen/features.h	Sun Dec 12 20:48:08 2010	(r216396)
@@ -0,0 +1,22 @@
+/******************************************************************************
+ * features.h
+ *
+ * Query the features reported by Xen.
+ *
+ * Copyright (c) 2006, Ian Campbell
+ *
+ * $FreeBSD: stable/8/sys/i386/include/xen/features.h 181638 2008-08-12 19:41:11Z kmacy $
+ */
+
+#ifndef __ASM_XEN_FEATURES_H__
+#define __ASM_XEN_FEATURES_H__
+
+#include <xen/interface/version.h>
+
+extern void setup_xen_features(void);
+
+extern uint8_t xen_features[XENFEAT_NR_SUBMAPS * 32];
+
+#define xen_feature(flag)	(xen_features[flag])
+
+#endif /* __ASM_XEN_FEATURES_H__ */

Added: projects/stable_7_xen/sys/i386/include/xen/hypercall.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ projects/stable_7_xen/sys/i386/include/xen/hypercall.h	Sun Dec 12 20:48:08 2010	(r216396)
@@ -0,0 +1,405 @@
+/******************************************************************************
+ * hypercall.h
+ * 
+ * Linux-specific hypervisor handling.
+ * 
+ * Copyright (c) 2002-2004, K A Fraser
+ * 
+ * This file may be distributed separately from the Linux kernel, or
+ * incorporated into other software packages, subject to the following license:
+ * 
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this source file (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy, modify,
+ * merge, publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#ifndef __HYPERCALL_H__
+#define __HYPERCALL_H__
+
+#include <sys/systm.h>
+#include <xen/interface/xen.h>
+#include <xen/interface/sched.h>
+
+#define __STR(x) #x
+#define STR(x) __STR(x)
+#define	ENOXENSYS	38
+#define CONFIG_XEN_COMPAT	0x030002
+
+
+#if defined(XEN)
+#define HYPERCALL_STR(name)                                     \
+        "call hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"
+#else
+#define HYPERCALL_STR(name)                                     \
+        "mov hypercall_stubs,%%eax; "                           \
+        "add $("STR(__HYPERVISOR_##name)" * 32),%%eax; "        \
+        "call *%%eax"
+#endif
+
+#define _hypercall0(type, name)                 \
+({                                              \
+        long __res;                             \
+        __asm__ volatile (                          \
+                HYPERCALL_STR(name)             \
+                : "=a" (__res)                  \
+                :                               \
+                : "memory" );                   \
+        (type)__res;                            \
+})
+
+#define _hypercall1(type, name, a1)                             \
+({                                                              \
+        long __res, __ign1;                                     \
+        __asm__ volatile (                                          \
+                HYPERCALL_STR(name)                             \
+                : "=a" (__res), "=b" (__ign1)                   \
+                : "1" ((long)(a1))                              \
+                : "memory" );                                   \
+        (type)__res;                                            \
+})
+
+#define _hypercall2(type, name, a1, a2)                         \
+({                                                              \
+        long __res, __ign1, __ign2;                             \
+        __asm__ volatile (                                          \
+                HYPERCALL_STR(name)                             \
+                : "=a" (__res), "=b" (__ign1), "=c" (__ign2)    \
+                : "1" ((long)(a1)), "2" ((long)(a2))            \
+                : "memory" );                                   \
+        (type)__res;                                            \
+})
+
+#define _hypercall3(type, name, a1, a2, a3)                     \
+({                                                              \
+        long __res, __ign1, __ign2, __ign3;                     \
+        __asm__ volatile (                                          \
+                HYPERCALL_STR(name)                             \
+                : "=a" (__res), "=b" (__ign1), "=c" (__ign2),   \
+                "=d" (__ign3)                                   \
+                : "1" ((long)(a1)), "2" ((long)(a2)),           \
+                "3" ((long)(a3))                                \
+                : "memory" );                                   \
+        (type)__res;                                            \
+})
+
+#define _hypercall4(type, name, a1, a2, a3, a4)                 \
+({                                                              \
+        long __res, __ign1, __ign2, __ign3, __ign4;             \
+        __asm__ volatile (                                          \
+                HYPERCALL_STR(name)                             \
+                : "=a" (__res), "=b" (__ign1), "=c" (__ign2),   \
+                "=d" (__ign3), "=S" (__ign4)                    \
+                : "1" ((long)(a1)), "2" ((long)(a2)),           \
+                "3" ((long)(a3)), "4" ((long)(a4))              \
+                : "memory" );                                   \
+        (type)__res;                                            \
+})
+
+#define _hypercall5(type, name, a1, a2, a3, a4, a5)             \
+({                                                              \
+        long __res, __ign1, __ign2, __ign3, __ign4, __ign5;     \
+        __asm__ volatile (                                          \
+                HYPERCALL_STR(name)                             \
+                : "=a" (__res), "=b" (__ign1), "=c" (__ign2),   \
+                "=d" (__ign3), "=S" (__ign4), "=D" (__ign5)     \
+                : "1" ((long)(a1)), "2" ((long)(a2)),           \
+                "3" ((long)(a3)), "4" ((long)(a4)),             \
+                "5" ((long)(a5))                                \
+                : "memory" );                                   \
+        (type)__res;                                            \
+})								
+
+static inline int
+HYPERVISOR_set_trap_table(
+	trap_info_t *table)
+{
+	return _hypercall1(int, set_trap_table, table);
+}
+
+static inline int
+HYPERVISOR_mmu_update(
+	mmu_update_t *req, int count, int *success_count, domid_t domid)
+{
+	return _hypercall4(int, mmu_update, req, count, success_count, domid);
+}
+
+static inline int
+HYPERVISOR_mmuext_op(
+	mmuext_op_t *op, int count, int *success_count, domid_t domid)
+{
+	return _hypercall4(int, mmuext_op, op, count, success_count, domid);
+}
+
+static inline int
+HYPERVISOR_set_gdt(
+	unsigned long *frame_list, int entries)
+{
+	return _hypercall2(int, set_gdt, frame_list, entries);
+}
+
+static inline int
+HYPERVISOR_stack_switch(
+	unsigned long ss, unsigned long esp)
+{
+	return _hypercall2(int, stack_switch, ss, esp);
+}
+
+static inline int
+HYPERVISOR_set_callbacks(
+	unsigned long event_selector, unsigned long event_address,
+	unsigned long failsafe_selector, unsigned long failsafe_address)
+{
+	return _hypercall4(int, set_callbacks,
+			   event_selector, event_address,
+			   failsafe_selector, failsafe_address);
+}
+
+static inline int
+HYPERVISOR_fpu_taskswitch(
+	int set)
+{
+	return _hypercall1(int, fpu_taskswitch, set);
+}
+
+static inline int 
+HYPERVISOR_sched_op_compat(
+	int cmd, unsigned long arg)
+{
+	return _hypercall2(int, sched_op_compat, cmd, arg);
+}
+
+static inline int
+HYPERVISOR_sched_op(
+	int cmd, void *arg)
+{
+	return _hypercall2(int, sched_op, cmd, arg);
+}
+
+static inline long
+HYPERVISOR_set_timer_op(
+	uint64_t timeout)
+{
+	unsigned long timeout_hi = (unsigned long)(timeout>>32);
+	unsigned long timeout_lo = (unsigned long)timeout;
+	return _hypercall2(long, set_timer_op, timeout_lo, timeout_hi);
+}
+#if 0
+static inline int
+HYPERVISOR_platform_op(
+        struct xen_platform_op *platform_op)
+{
+        platform_op->interface_version = XENPF_INTERFACE_VERSION;
+        return _hypercall1(int, platform_op, platform_op);
+}
+#endif
+static inline int
+HYPERVISOR_set_debugreg(
+	int reg, unsigned long value)
+{
+	return _hypercall2(int, set_debugreg, reg, value);
+}
+
+static inline unsigned long
+HYPERVISOR_get_debugreg(
+	int reg)
+{
+	return _hypercall1(unsigned long, get_debugreg, reg);
+}
+
+static inline int
+HYPERVISOR_update_descriptor(
+	uint64_t ma, uint64_t desc)
+{
+	return _hypercall4(int, update_descriptor, ma, ma>>32, desc, desc>>32);
+}
+
+static inline int
+HYPERVISOR_memory_op(
+	unsigned int cmd, void *arg)
+{
+	return _hypercall2(int, memory_op, cmd, arg);
+}
+
+static inline int
+HYPERVISOR_multicall(
+	void *call_list, int nr_calls)
+{
+	return _hypercall2(int, multicall, call_list, nr_calls);
+}
+
+static inline int
+HYPERVISOR_update_va_mapping(
+	unsigned long va, uint64_t new_val, unsigned long flags)
+{
+	uint32_t hi, lo;
+
+	lo = (uint32_t)(new_val & 0xffffffff);
+	hi = (uint32_t)(new_val >> 32);
+	
+	return _hypercall4(int, update_va_mapping, va,
+			   lo, hi, flags);
+}
+
+static inline int
+HYPERVISOR_event_channel_op(
+	int cmd, void *arg)
+{
+	int rc = _hypercall2(int, event_channel_op, cmd, arg);
+
+#if CONFIG_XEN_COMPAT <= 0x030002
+	if (__predict_false(rc == -ENOXENSYS)) {
+		struct evtchn_op op;
+		op.cmd = cmd;
+		memcpy(&op.u, arg, sizeof(op.u));
+		rc = _hypercall1(int, event_channel_op_compat, &op);
+		memcpy(arg, &op.u, sizeof(op.u));
+	}
+#endif
+	return (rc);
+}
+
+static inline int
+HYPERVISOR_xen_version(
+	int cmd, void *arg)
+{
+	return _hypercall2(int, xen_version, cmd, arg);
+}
+
+static inline int
+HYPERVISOR_console_io(
+	int cmd, int count, char *str)
+{
+	return _hypercall3(int, console_io, cmd, count, str);
+}
+
+static inline int
+HYPERVISOR_physdev_op(
+	int cmd, void *arg)
+{
+	int rc = _hypercall2(int, physdev_op, cmd, arg);
+#if CONFIG_XEN_COMPAT <= 0x030002
+	if (__predict_false(rc == -ENOXENSYS)) {
+		struct physdev_op op;
+		op.cmd = cmd;
+		memcpy(&op.u, arg, sizeof(op.u));
+		rc = _hypercall1(int, physdev_op_compat, &op);
+		memcpy(arg, &op.u, sizeof(op.u));
+	}
+#endif
+	return (rc);
+}
+
+static inline int
+HYPERVISOR_grant_table_op(
+	unsigned int cmd, void *uop, unsigned int count)
+{
+	return _hypercall3(int, grant_table_op, cmd, uop, count);
+}
+
+static inline int
+HYPERVISOR_update_va_mapping_otherdomain(
+	unsigned long va, uint64_t new_val, unsigned long flags, domid_t domid)
+{
+	uint32_t hi, lo;
+	
+	lo = (uint32_t)(new_val & 0xffffffff);
+	hi = (uint32_t)(new_val >> 32);
+	
+	return _hypercall5(int, update_va_mapping_otherdomain, va,
+			   lo, hi, flags, domid);
+}
+
+static inline int
+HYPERVISOR_vm_assist(
+	unsigned int cmd, unsigned int type)
+{
+	return _hypercall2(int, vm_assist, cmd, type);
+}
+
+static inline int
+HYPERVISOR_vcpu_op(
+	int cmd, int vcpuid, void *extra_args)
+{
+	return _hypercall3(int, vcpu_op, cmd, vcpuid, extra_args);
+}
+
+static inline int
+HYPERVISOR_suspend(
+	unsigned long srec)
+{
+	struct sched_shutdown sched_shutdown = {
+		.reason = SHUTDOWN_suspend
+	};
+	int rc = _hypercall3(int, sched_op, SCHEDOP_shutdown,
+			   &sched_shutdown, srec);
+#if CONFIG_XEN_COMPAT <= 0x030002
+	if (rc == -ENOXENSYS)
+		rc = _hypercall3(int, sched_op_compat, SCHEDOP_shutdown,
+				 SHUTDOWN_suspend, srec);
+#endif	
+	return (rc);
+}
+
+#if CONFIG_XEN_COMPAT <= 0x030002
+static inline int
+HYPERVISOR_nmi_op(
+        unsigned long op, void *arg)
+{
+        return _hypercall2(int, nmi_op, op, arg);
+}
+#endif
+
+static inline int
+HYPERVISOR_callback_op(
+        int cmd, void *arg)
+{
+        return _hypercall2(int, callback_op, cmd, arg);
+}
+
+#ifndef CONFIG_XEN
+static inline unsigned long
+HYPERVISOR_hvm_op(
+    int op, void *arg)
+{
+    return _hypercall2(unsigned long, hvm_op, op, arg);
+}
+#endif
+
+static inline int
+HYPERVISOR_xenoprof_op(
+        int op, void *arg)
+{
+        return _hypercall2(int, xenoprof_op, op, arg);
+}
+
+static inline int
+HYPERVISOR_kexec_op(
+        unsigned long op, void *args)
+{
+        return _hypercall2(int, kexec_op, op, args);
+}
+#endif /* __HYPERCALL_H__ */
+
+/*
+ * Local variables:
+ *  c-file-style: "linux"
+ *  indent-tabs-mode: t
+ *  c-indent-level: 8
+ *  c-basic-offset: 8
+ *  tab-width: 8
+ * End:
+ */

Added: projects/stable_7_xen/sys/i386/include/xen/synch_bitops.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ projects/stable_7_xen/sys/i386/include/xen/synch_bitops.h	Sun Dec 12 20:48:08 2010	(r216396)
@@ -0,0 +1,139 @@
+#ifndef __XEN_SYNCH_BITOPS_H__
+#define __XEN_SYNCH_BITOPS_H__
+
+/*
+ * Copyright 1992, Linus Torvalds.
+ * Heavily modified to provide guaranteed strong synchronisation
+ * when communicating with Xen or other guest OSes running on other CPUs.
+ */
+
+
+#define ADDR (*(volatile long *) addr)
+
+static __inline__ void synch_set_bit(int nr, volatile void * addr)
+{
+    __asm__ __volatile__ ( 
+        "lock btsl %1,%0"
+        : "=m" (ADDR) : "Ir" (nr) : "memory" );
+}
+
+static __inline__ void synch_clear_bit(int nr, volatile void * addr)
+{
+    __asm__ __volatile__ (
+        "lock btrl %1,%0"
+        : "=m" (ADDR) : "Ir" (nr) : "memory" );
+}
+
+static __inline__ void synch_change_bit(int nr, volatile void * addr)
+{
+    __asm__ __volatile__ (
+        "lock btcl %1,%0"
+        : "=m" (ADDR) : "Ir" (nr) : "memory" );
+}
+
+static __inline__ int synch_test_and_set_bit(int nr, volatile void * addr)
+{
+    int oldbit;
+    __asm__ __volatile__ (
+        "lock btsl %2,%1\n\tsbbl %0,%0"
+        : "=r" (oldbit), "=m" (ADDR) : "Ir" (nr) : "memory");
+    return oldbit;
+}
+
+static __inline__ int synch_test_and_clear_bit(int nr, volatile void * addr)
+{
+    int oldbit;
+    __asm__ __volatile__ (
+        "lock btrl %2,%1\n\tsbbl %0,%0"
+        : "=r" (oldbit), "=m" (ADDR) : "Ir" (nr) : "memory");
+    return oldbit;
+}
+
+static __inline__ int synch_test_and_change_bit(int nr, volatile void * addr)
+{
+    int oldbit;
+
+    __asm__ __volatile__ (
+        "lock btcl %2,%1\n\tsbbl %0,%0"
+        : "=r" (oldbit), "=m" (ADDR) : "Ir" (nr) : "memory");
+    return oldbit;
+}
+
+struct __synch_xchg_dummy { unsigned long a[100]; };
+#define __synch_xg(x) ((volatile struct __synch_xchg_dummy *)(x))
+
+#define synch_cmpxchg(ptr, old, new) \
+((__typeof__(*(ptr)))__synch_cmpxchg((ptr),\
+                                     (unsigned long)(old), \
+                                     (unsigned long)(new), \
+                                     sizeof(*(ptr))))
+
+static inline unsigned long __synch_cmpxchg(volatile void *ptr,
+					    unsigned long old,
+					    unsigned long new, int size)
+{
+	unsigned long prev;
+	switch (size) {
+	case 1:
+		__asm__ __volatile__("lock; cmpxchgb %b1,%2"
+				     : "=a"(prev)
+				     : "q"(new), "m"(*__synch_xg(ptr)),
+				       "0"(old)
+				     : "memory");
+		return prev;
+	case 2:
+		__asm__ __volatile__("lock; cmpxchgw %w1,%2"
+				     : "=a"(prev)
+				     : "q"(new), "m"(*__synch_xg(ptr)),
+				       "0"(old)
+				     : "memory");
+		return prev;
+#ifdef CONFIG_X86_64
+	case 4:
+		__asm__ __volatile__("lock; cmpxchgl %k1,%2"
+				     : "=a"(prev)
+				     : "q"(new), "m"(*__synch_xg(ptr)),
+				       "0"(old)
+				     : "memory");
+		return prev;
+	case 8:
+		__asm__ __volatile__("lock; cmpxchgq %1,%2"
+				     : "=a"(prev)
+				     : "q"(new), "m"(*__synch_xg(ptr)),
+				       "0"(old)
+				     : "memory");
+		return prev;
+#else
+	case 4:
+		__asm__ __volatile__("lock; cmpxchgl %1,%2"
+				     : "=a"(prev)
+				     : "q"(new), "m"(*__synch_xg(ptr)),
+				       "0"(old)
+				     : "memory");
+		return prev;
+#endif
+	}
+	return old;
+}
+
+static __inline__ int synch_const_test_bit(int nr, const volatile void * addr)
+{
+    return ((1UL << (nr & 31)) & 
+            (((const volatile unsigned int *) addr)[nr >> 5])) != 0;
+}
+
+static __inline__ int synch_var_test_bit(int nr, volatile void * addr)
+{
+    int oldbit;
+    __asm__ __volatile__ (
+        "btl %2,%1\n\tsbbl %0,%0"
+        : "=r" (oldbit) : "m" (ADDR), "Ir" (nr) );
+    return oldbit;
+}
+
+#define synch_test_bit(nr,addr) \
+(__builtin_constant_p(nr) ? \
+ synch_const_test_bit((nr),(addr)) : \
+ synch_var_test_bit((nr),(addr)))
+
+#endif /* __XEN_SYNCH_BITOPS_H__ */

Added: projects/stable_7_xen/sys/i386/include/xen/xen-os.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ projects/stable_7_xen/sys/i386/include/xen/xen-os.h	Sun Dec 12 20:48:08 2010	(r216396)
@@ -0,0 +1,353 @@
+/******************************************************************************
+ * os.h
+ * 
+ * random collection of macros and definition
+ */
+
+#ifndef _XEN_OS_H_
+#define _XEN_OS_H_
+#include <machine/param.h>
+
+#ifdef PAE
+#define CONFIG_X86_PAE
+#endif
+
+#if defined(XEN) && !defined(__XEN_INTERFACE_VERSION__) 
+/* 
+ * Can update to a more recent version when we implement 
+ * the hypercall page 
+ */ 
+#define  __XEN_INTERFACE_VERSION__ 0x00030204 
+#endif 
+
+#include <xen/interface/xen.h>
+
+/* Force a proper event-channel callback from Xen. */
+void force_evtchn_callback(void);
+
+#define likely(x)  __builtin_expect((x),1)
+#define unlikely(x)  __builtin_expect((x),0)
+
+#ifndef vtophys
+#include <vm/vm.h>
+#include <vm/vm_param.h>
+#include <vm/pmap.h>
+#endif
+
+extern int gdtset;
+#ifdef SMP
+#include <sys/time.h> /* XXX for pcpu.h */
+#include <sys/pcpu.h> /* XXX for PCPU_GET */
+static inline int 
+smp_processor_id(void)  
+{
+    if (likely(gdtset))
+	return PCPU_GET(cpuid);
+    return 0;
+}
+
+#else
+#define smp_processor_id() 0
+#endif
+
+#ifndef NULL
+#define NULL (void *)0
+#endif
+
+#ifndef PANIC_IF
+#define PANIC_IF(exp) if (unlikely(exp)) {printk("panic - %s: %s:%d\n",#exp, __FILE__, __LINE__); panic("%s: %s:%d", #exp, __FILE__, __LINE__);} 
+#endif
+
+extern shared_info_t *HYPERVISOR_shared_info;
+
+/* Somewhere in the middle of the GCC 2.96 development cycle, we implemented
+   a mechanism by which the user can annotate likely branch directions and
+   expect the blocks to be reordered appropriately.  Define __builtin_expect
+   to nothing for earlier compilers.  */
+
+/* REP NOP (PAUSE) is a good thing to insert into busy-wait loops. */
+static inline void rep_nop(void)
+{
+    __asm__ __volatile__ ( "rep;nop" : : : "memory" );
+}
+#define cpu_relax() rep_nop()
+
+
+#if __GNUC__ == 2 && __GNUC_MINOR__ < 96
+#define __builtin_expect(x, expected_value) (x)
+#endif
+
+#define per_cpu(var, cpu)           (pcpu_find((cpu))->pc_ ## var)
+
+/* crude memory allocator for memory allocation early in 
+ *  boot
+ */
+void *bootmem_alloc(unsigned int size);
+void bootmem_free(void *ptr, unsigned int size);
+
+
+/* Everything below this point is not included by assembler (.S) files. */
+#ifndef __ASSEMBLY__
+#include <sys/types.h>
+
+void printk(const char *fmt, ...);
+
+/* some function prototypes */
+void trap_init(void);
+
+/*
+ * STI/CLI equivalents. These basically set and clear the virtual
+ * event_enable flag in teh shared_info structure. Note that when
+ * the enable bit is set, there may be pending events to be handled.
+ * We may therefore call into do_hypervisor_callback() directly.
+ */
+
+
+#define __cli()                                                         \
+do {                                                                    \
+        vcpu_info_t *_vcpu;                                             \
+        _vcpu = &HYPERVISOR_shared_info->vcpu_info[smp_processor_id()]; \
+        _vcpu->evtchn_upcall_mask = 1;                                  \
+        barrier();                                                      \
+} while (0)
+
+#define __sti()                                                         \
+do {                                                                    \
+        vcpu_info_t *_vcpu;                                             \
+        barrier();                                                      \
+        _vcpu = &HYPERVISOR_shared_info->vcpu_info[smp_processor_id()]; \
+        _vcpu->evtchn_upcall_mask = 0;                                  \
+        barrier(); /* unmask then check (avoid races) */                \
+        if ( unlikely(_vcpu->evtchn_upcall_pending) )                   \
+                force_evtchn_callback();                                \
+} while (0)
+
+#define __restore_flags(x)                                              \
+do {                                                                    \
+        vcpu_info_t *_vcpu;                                             \
+        barrier();                                                      \
+        _vcpu = &HYPERVISOR_shared_info->vcpu_info[smp_processor_id()]; \
+        if ((_vcpu->evtchn_upcall_mask = (x)) == 0) {                   \
+                barrier(); /* unmask then check (avoid races) */        \
+                if ( unlikely(_vcpu->evtchn_upcall_pending) )           \
+                        force_evtchn_callback();                        \
+        } 								\
+} while (0)
+
+/*
+ * Add critical_{enter, exit}?
+ *
+ */
+#define __save_and_cli(x)                                               \
+do {                                                                    \
+        vcpu_info_t *_vcpu;                                             \
+        _vcpu = &HYPERVISOR_shared_info->vcpu_info[smp_processor_id()]; \
+        (x) = _vcpu->evtchn_upcall_mask;                                \
+        _vcpu->evtchn_upcall_mask = 1;                                  \
+        barrier();                                                      \
+} while (0)
+
+
+#define cli() __cli()
+#define sti() __sti()

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***


More information about the svn-src-projects mailing list