--- /dev/null
+The headers in this directory have been imported from the Xen Project with few\r
+modification that are described in this README.\r
+\r
+The modifications that needed to be done are:\r
+- Use of ZeroMem() or SetMem() instead of memset().\r
+- If a struct is using a 64bit field, then a #pragma(4) might be needed\r
+ for IA32, like in io/blkif.h.\r
+- Replace the types with the ones used in UEFI.\r
+\r
+\r
+* Command to run to change types:\r
+find OvmfPkg/Include/IndustryStandard/Xen -type f -name '*.h' -exec sed --regexp-extended --file=fix_type_in_xen_includes.sed --in-place {} \;\r
+\r
+$ cat fix_type_in_xen_includes.sed\r
+# Avoid changing the 'long' that is not a type.\r
+/as long as/b\r
+\r
+s/([^a-zA-Z0-9_]|^)uint8_t([^a-zA-Z0-9_]|$)/\1UINT8\2/g\r
+s/([^a-zA-Z0-9_]|^)uint16_t([^a-zA-Z0-9_]|$)/\1UINT16\2/g\r
+s/([^a-zA-Z0-9_]|^)uint32_t([^a-zA-Z0-9_]|$)/\1UINT32\2/g\r
+s/([^a-zA-Z0-9_]|^)uint64_t([^a-zA-Z0-9_]|$)/\1UINT64\2/g\r
+\r
+s/([^a-zA-Z0-9_]|^)int8_t([^a-zA-Z0-9_]|$)/\1INT8\2/g\r
+s/([^a-zA-Z0-9_]|^)int16_t([^a-zA-Z0-9_]|$)/\1INT16\2/g\r
+s/([^a-zA-Z0-9_]|^)int32_t([^a-zA-Z0-9_]|$)/\1INT32\2/g\r
+s/([^a-zA-Z0-9_]|^)int64_t([^a-zA-Z0-9_]|$)/\1INT64\2/g\r
+\r
+s/([^a-zA-Z0-9_]|^)void([^a-zA-Z0-9_]|$)/\1VOID\2/g\r
+s/([^a-zA-Z0-9_]|^)unsigned int([^a-zA-Z0-9_]|$)/\1UINT32\2/g\r
+s/([^a-zA-Z0-9_]|^)int([^a-zA-Z0-9_]|$)/\1INT32\2/g\r
+s/([^a-zA-Z0-9_]|^)unsigned char([^a-zA-Z0-9_]|$)/\1UINT8\2/g\r
+s/([^a-zA-Z0-9_]|^)char([^a-zA-Z0-9_]|$)/\1CHAR8\2/g\r
+s/([^a-zA-Z0-9_]|^)unsigned long([^a-zA-Z0-9_]|$)/\1UINTN\2/g\r
+s/([^a-zA-Z0-9_]|^)long([^a-zA-Z0-9_]|$)/\1INTN\2/g\r
--- /dev/null
+/******************************************************************************\r
+ * xen-x86_32.h\r
+ * \r
+ * Guest OS interface to x86 32-bit Xen.\r
+ * \r
+ * Permission is hereby granted, free of charge, to any person obtaining a copy\r
+ * of this software and associated documentation files (the "Software"), to\r
+ * deal in the Software without restriction, including without limitation the\r
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\r
+ * sell copies of the Software, and to permit persons to whom the Software is\r
+ * furnished to do so, subject to the following conditions:\r
+ *\r
+ * The above copyright notice and this permission notice shall be included in\r
+ * all copies or substantial portions of the Software.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\r
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\r
+ * DEALINGS IN THE SOFTWARE.\r
+ *\r
+ * Copyright (c) 2004-2007, K A Fraser\r
+ */\r
+\r
+#ifndef __XEN_PUBLIC_ARCH_X86_XEN_X86_32_H__\r
+#define __XEN_PUBLIC_ARCH_X86_XEN_X86_32_H__\r
+\r
+/*\r
+ * Hypercall interface:\r
+ * Input: %ebx, %ecx, %edx, %esi, %edi, %ebp (arguments 1-6)\r
+ * Output: %eax\r
+ * Access is via hypercall page (set up by guest loader or via a Xen MSR):\r
+ * call hypercall_page + hypercall-number * 32\r
+ * Clobbered: Argument registers (e.g., 2-arg hypercall clobbers %ebx,%ecx)\r
+ */\r
+\r
+#ifndef __ASSEMBLY__\r
+\r
+struct arch_vcpu_info {\r
+ UINTN cr2;\r
+ UINTN pad[5]; /* sizeof(vcpu_info_t) == 64 */\r
+};\r
+typedef struct arch_vcpu_info arch_vcpu_info_t;\r
+\r
+#endif /* !__ASSEMBLY__ */\r
+\r
+#endif /* __XEN_PUBLIC_ARCH_X86_XEN_X86_32_H__ */\r
+\r
+/*\r
+ * Local variables:\r
+ * mode: C\r
+ * c-file-style: "BSD"\r
+ * c-basic-offset: 4\r
+ * tab-width: 4\r
+ * indent-tabs-mode: nil\r
+ * End:\r
+ */\r
--- /dev/null
+/******************************************************************************\r
+ * xen-x86_64.h\r
+ * \r
+ * Guest OS interface to x86 64-bit Xen.\r
+ * \r
+ * Permission is hereby granted, free of charge, to any person obtaining a copy\r
+ * of this software and associated documentation files (the "Software"), to\r
+ * deal in the Software without restriction, including without limitation the\r
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\r
+ * sell copies of the Software, and to permit persons to whom the Software is\r
+ * furnished to do so, subject to the following conditions:\r
+ *\r
+ * The above copyright notice and this permission notice shall be included in\r
+ * all copies or substantial portions of the Software.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\r
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\r
+ * DEALINGS IN THE SOFTWARE.\r
+ *\r
+ * Copyright (c) 2004-2006, K A Fraser\r
+ */\r
+\r
+#ifndef __XEN_PUBLIC_ARCH_X86_XEN_X86_64_H__\r
+#define __XEN_PUBLIC_ARCH_X86_XEN_X86_64_H__\r
+\r
+/*\r
+ * Hypercall interface:\r
+ * Input: %rdi, %rsi, %rdx, %r10, %r8, %r9 (arguments 1-6)\r
+ * Output: %rax\r
+ * Access is via hypercall page (set up by guest loader or via a Xen MSR):\r
+ * call hypercall_page + hypercall-number * 32\r
+ * Clobbered: argument registers (e.g., 2-arg hypercall clobbers %rdi,%rsi)\r
+ */\r
+\r
+#ifndef __ASSEMBLY__\r
+\r
+struct arch_vcpu_info {\r
+ UINTN cr2;\r
+ UINTN pad; /* sizeof(vcpu_info_t) == 64 */\r
+};\r
+typedef struct arch_vcpu_info arch_vcpu_info_t;\r
+\r
+#endif /* !__ASSEMBLY__ */\r
+\r
+#endif /* __XEN_PUBLIC_ARCH_X86_XEN_X86_64_H__ */\r
+\r
+/*\r
+ * Local variables:\r
+ * mode: C\r
+ * c-file-style: "BSD"\r
+ * c-basic-offset: 4\r
+ * tab-width: 4\r
+ * indent-tabs-mode: nil\r
+ * End:\r
+ */\r
--- /dev/null
+/******************************************************************************\r
+ * arch-x86/xen.h\r
+ * \r
+ * Guest OS interface to x86 Xen.\r
+ * \r
+ * Permission is hereby granted, free of charge, to any person obtaining a copy\r
+ * of this software and associated documentation files (the "Software"), to\r
+ * deal in the Software without restriction, including without limitation the\r
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\r
+ * sell copies of the Software, and to permit persons to whom the Software is\r
+ * furnished to do so, subject to the following conditions:\r
+ *\r
+ * The above copyright notice and this permission notice shall be included in\r
+ * all copies or substantial portions of the Software.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\r
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\r
+ * DEALINGS IN THE SOFTWARE.\r
+ *\r
+ * Copyright (c) 2004-2006, K A Fraser\r
+ */\r
+\r
+#include "../xen.h"\r
+\r
+#ifndef __XEN_PUBLIC_ARCH_X86_XEN_H__\r
+#define __XEN_PUBLIC_ARCH_X86_XEN_H__\r
+\r
+/* Structural guest handles introduced in 0x00030201. */\r
+#if __XEN_INTERFACE_VERSION__ >= 0x00030201\r
+#define ___DEFINE_XEN_GUEST_HANDLE(name, type) \\r
+ typedef struct { type *p; } __guest_handle_ ## name\r
+#else\r
+#define ___DEFINE_XEN_GUEST_HANDLE(name, type) \\r
+ typedef type * __guest_handle_ ## name\r
+#endif\r
+\r
+/*\r
+ * XEN_GUEST_HANDLE represents a guest pointer, when passed as a field\r
+ * in a struct in memory.\r
+ * XEN_GUEST_HANDLE_PARAM represent a guest pointer, when passed as an\r
+ * hypercall argument.\r
+ * XEN_GUEST_HANDLE_PARAM and XEN_GUEST_HANDLE are the same on X86 but\r
+ * they might not be on other architectures.\r
+ */\r
+#define __DEFINE_XEN_GUEST_HANDLE(name, type) \\r
+ ___DEFINE_XEN_GUEST_HANDLE(name, type); \\r
+ ___DEFINE_XEN_GUEST_HANDLE(const_##name, const type)\r
+#define DEFINE_XEN_GUEST_HANDLE(name) __DEFINE_XEN_GUEST_HANDLE(name, name)\r
+#define __XEN_GUEST_HANDLE(name) __guest_handle_ ## name\r
+#define XEN_GUEST_HANDLE(name) __XEN_GUEST_HANDLE(name)\r
+#define XEN_GUEST_HANDLE_PARAM(name) XEN_GUEST_HANDLE(name)\r
+#define set_xen_guest_handle_raw(hnd, val) do { (hnd).p = val; } while (0)\r
+#ifdef __XEN_TOOLS__\r
+#define get_xen_guest_handle(val, hnd) do { val = (hnd).p; } while (0)\r
+#endif\r
+#define set_xen_guest_handle(hnd, val) set_xen_guest_handle_raw(hnd, val)\r
+\r
+#if defined(__i386__)\r
+#include "xen-x86_32.h"\r
+#elif defined(__x86_64__)\r
+#include "xen-x86_64.h"\r
+#endif\r
+\r
+#ifndef __ASSEMBLY__\r
+typedef UINTN xen_pfn_t;\r
+#define PRI_xen_pfn "lx"\r
+#endif\r
+\r
+#define XEN_HAVE_PV_UPCALL_MASK 1\r
+\r
+/* Maximum number of virtual CPUs in legacy multi-processor guests. */\r
+#define XEN_LEGACY_MAX_VCPUS 32\r
+\r
+#ifndef __ASSEMBLY__\r
+\r
+typedef UINTN xen_ulong_t;\r
+#define PRI_xen_ulong "lx"\r
+\r
+typedef UINT64 tsc_timestamp_t; /* RDTSC timestamp */\r
+\r
+#ifdef __i386__\r
+#pragma pack(4)\r
+#endif\r
+struct arch_shared_info {\r
+ UINTN max_pfn; /* max pfn that appears in table */\r
+ /* Frame containing list of mfns containing list of mfns containing p2m. */\r
+ xen_pfn_t pfn_to_mfn_frame_list_list;\r
+ UINTN nmi_reason;\r
+ UINT64 pad[32];\r
+};\r
+typedef struct arch_shared_info arch_shared_info_t;\r
+#ifdef __i386__\r
+#pragma pack()\r
+#endif\r
+\r
+#endif /* !__ASSEMBLY__ */\r
+\r
+#endif /* __XEN_PUBLIC_ARCH_X86_XEN_H__ */\r
+\r
+/*\r
+ * Local variables:\r
+ * mode: C\r
+ * c-file-style: "BSD"\r
+ * c-basic-offset: 4\r
+ * tab-width: 4\r
+ * indent-tabs-mode: nil\r
+ * End:\r
+ */\r
--- /dev/null
+/******************************************************************************\r
+ * grant_table.h\r
+ *\r
+ * Interface for granting foreign access to page frames, and receiving\r
+ * page-ownership transfers.\r
+ *\r
+ * Permission is hereby granted, free of charge, to any person obtaining a copy\r
+ * of this software and associated documentation files (the "Software"), to\r
+ * deal in the Software without restriction, including without limitation the\r
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\r
+ * sell copies of the Software, and to permit persons to whom the Software is\r
+ * furnished to do so, subject to the following conditions:\r
+ *\r
+ * The above copyright notice and this permission notice shall be included in\r
+ * all copies or substantial portions of the Software.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\r
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\r
+ * DEALINGS IN THE SOFTWARE.\r
+ *\r
+ * Copyright (c) 2004, K A Fraser\r
+ */\r
+\r
+#ifndef __XEN_PUBLIC_GRANT_TABLE_H__\r
+#define __XEN_PUBLIC_GRANT_TABLE_H__\r
+\r
+#include "xen.h"\r
+\r
+/*\r
+ * `incontents 150 gnttab Grant Tables\r
+ *\r
+ * Xen's grant tables provide a generic mechanism to memory sharing\r
+ * between domains. This shared memory interface underpins the split\r
+ * device drivers for block and network IO.\r
+ *\r
+ * Each domain has its own grant table. This is a data structure that\r
+ * is shared with Xen; it allows the domain to tell Xen what kind of\r
+ * permissions other domains have on its pages. Entries in the grant\r
+ * table are identified by grant references. A grant reference is an\r
+ * integer, which indexes into the grant table. It acts as a\r
+ * capability which the grantee can use to perform operations on the\r
+ * granter’s memory.\r
+ *\r
+ * This capability-based system allows shared-memory communications\r
+ * between unprivileged domains. A grant reference also encapsulates\r
+ * the details of a shared page, removing the need for a domain to\r
+ * know the real machine address of a page it is sharing. This makes\r
+ * it possible to share memory correctly with domains running in\r
+ * fully virtualised memory.\r
+ */\r
+\r
+/***********************************\r
+ * GRANT TABLE REPRESENTATION\r
+ */\r
+\r
+/* Some rough guidelines on accessing and updating grant-table entries\r
+ * in a concurrency-safe manner. For more information, Linux contains a\r
+ * reference implementation for guest OSes (drivers/xen/grant_table.c, see\r
+ * http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=drivers/xen/grant-table.c;hb=HEAD\r
+ *\r
+ * NB. WMB is a no-op on current-generation x86 processors. However, a\r
+ * compiler barrier will still be required.\r
+ *\r
+ * Introducing a valid entry into the grant table:\r
+ * 1. Write ent->domid.\r
+ * 2. Write ent->frame:\r
+ * GTF_permit_access: Frame to which access is permitted.\r
+ * GTF_accept_transfer: Pseudo-phys frame slot being filled by new\r
+ * frame, or zero if none.\r
+ * 3. Write memory barrier (WMB).\r
+ * 4. Write ent->flags, inc. valid type.\r
+ *\r
+ * Invalidating an unused GTF_permit_access entry:\r
+ * 1. flags = ent->flags.\r
+ * 2. Observe that !(flags & (GTF_reading|GTF_writing)).\r
+ * 3. Check result of SMP-safe CMPXCHG(&ent->flags, flags, 0).\r
+ * NB. No need for WMB as reuse of entry is control-dependent on success of\r
+ * step 3, and all architectures guarantee ordering of ctrl-dep writes.\r
+ *\r
+ * Invalidating an in-use GTF_permit_access entry:\r
+ * This cannot be done directly. Request assistance from the domain controller\r
+ * which can set a timeout on the use of a grant entry and take necessary\r
+ * action. (NB. This is not yet implemented!).\r
+ *\r
+ * Invalidating an unused GTF_accept_transfer entry:\r
+ * 1. flags = ent->flags.\r
+ * 2. Observe that !(flags & GTF_transfer_committed). [*]\r
+ * 3. Check result of SMP-safe CMPXCHG(&ent->flags, flags, 0).\r
+ * NB. No need for WMB as reuse of entry is control-dependent on success of\r
+ * step 3, and all architectures guarantee ordering of ctrl-dep writes.\r
+ * [*] If GTF_transfer_committed is set then the grant entry is 'committed'.\r
+ * The guest must /not/ modify the grant entry until the address of the\r
+ * transferred frame is written. It is safe for the guest to spin waiting\r
+ * for this to occur (detect by observing GTF_transfer_completed in\r
+ * ent->flags).\r
+ *\r
+ * Invalidating a committed GTF_accept_transfer entry:\r
+ * 1. Wait for (ent->flags & GTF_transfer_completed).\r
+ *\r
+ * Changing a GTF_permit_access from writable to read-only:\r
+ * Use SMP-safe CMPXCHG to set GTF_readonly, while checking !GTF_writing.\r
+ *\r
+ * Changing a GTF_permit_access from read-only to writable:\r
+ * Use SMP-safe bit-setting instruction.\r
+ */\r
+\r
+/*\r
+ * Reference to a grant entry in a specified domain's grant table.\r
+ */\r
+typedef UINT32 grant_ref_t;\r
+\r
+/*\r
+ * A grant table comprises a packed array of grant entries in one or more\r
+ * page frames shared between Xen and a guest.\r
+ * [XEN]: This field is written by Xen and read by the sharing guest.\r
+ * [GST]: This field is written by the guest and read by Xen.\r
+ */\r
+\r
+/*\r
+ * Version 1 of the grant table entry structure is maintained purely\r
+ * for backwards compatibility. New guests should use version 2.\r
+ */\r
+#if __XEN_INTERFACE_VERSION__ < 0x0003020a\r
+#define grant_entry_v1 grant_entry\r
+#define grant_entry_v1_t grant_entry_t\r
+#endif\r
+struct grant_entry_v1 {\r
+ /* GTF_xxx: various type and flag information. [XEN,GST] */\r
+ UINT16 flags;\r
+ /* The domain being granted foreign privileges. [GST] */\r
+ domid_t domid;\r
+ /*\r
+ * GTF_permit_access: Frame that @domid is allowed to map and access. [GST]\r
+ * GTF_accept_transfer: Frame whose ownership transferred by @domid. [XEN]\r
+ */\r
+ UINT32 frame;\r
+};\r
+typedef struct grant_entry_v1 grant_entry_v1_t;\r
+\r
+/* The first few grant table entries will be preserved across grant table\r
+ * version changes and may be pre-populated at domain creation by tools.\r
+ */\r
+#define GNTTAB_NR_RESERVED_ENTRIES 8\r
+#define GNTTAB_RESERVED_CONSOLE 0\r
+#define GNTTAB_RESERVED_XENSTORE 1\r
+\r
+/*\r
+ * Type of grant entry.\r
+ * GTF_invalid: This grant entry grants no privileges.\r
+ * GTF_permit_access: Allow @domid to map/access @frame.\r
+ * GTF_accept_transfer: Allow @domid to transfer ownership of one page frame\r
+ * to this guest. Xen writes the page number to @frame.\r
+ * GTF_transitive: Allow @domid to transitively access a subrange of\r
+ * @trans_grant in @trans_domid. No mappings are allowed.\r
+ */\r
+#define GTF_invalid (0U<<0)\r
+#define GTF_permit_access (1U<<0)\r
+#define GTF_accept_transfer (2U<<0)\r
+#define GTF_transitive (3U<<0)\r
+#define GTF_type_mask (3U<<0)\r
+\r
+/*\r
+ * Subflags for GTF_permit_access.\r
+ * GTF_readonly: Restrict @domid to read-only mappings and accesses. [GST]\r
+ * GTF_reading: Grant entry is currently mapped for reading by @domid. [XEN]\r
+ * GTF_writing: Grant entry is currently mapped for writing by @domid. [XEN]\r
+ * GTF_PAT, GTF_PWT, GTF_PCD: (x86) cache attribute flags for the grant [GST]\r
+ * GTF_sub_page: Grant access to only a subrange of the page. @domid\r
+ * will only be allowed to copy from the grant, and not\r
+ * map it. [GST]\r
+ */\r
+#define _GTF_readonly (2)\r
+#define GTF_readonly (1U<<_GTF_readonly)\r
+#define _GTF_reading (3)\r
+#define GTF_reading (1U<<_GTF_reading)\r
+#define _GTF_writing (4)\r
+#define GTF_writing (1U<<_GTF_writing)\r
+#define _GTF_PWT (5)\r
+#define GTF_PWT (1U<<_GTF_PWT)\r
+#define _GTF_PCD (6)\r
+#define GTF_PCD (1U<<_GTF_PCD)\r
+#define _GTF_PAT (7)\r
+#define GTF_PAT (1U<<_GTF_PAT)\r
+#define _GTF_sub_page (8)\r
+#define GTF_sub_page (1U<<_GTF_sub_page)\r
+\r
+/*\r
+ * Subflags for GTF_accept_transfer:\r
+ * GTF_transfer_committed: Xen sets this flag to indicate that it is committed\r
+ * to transferring ownership of a page frame. When a guest sees this flag\r
+ * it must /not/ modify the grant entry until GTF_transfer_completed is\r
+ * set by Xen.\r
+ * GTF_transfer_completed: It is safe for the guest to spin-wait on this flag\r
+ * after reading GTF_transfer_committed. Xen will always write the frame\r
+ * address, followed by ORing this flag, in a timely manner.\r
+ */\r
+#define _GTF_transfer_committed (2)\r
+#define GTF_transfer_committed (1U<<_GTF_transfer_committed)\r
+#define _GTF_transfer_completed (3)\r
+#define GTF_transfer_completed (1U<<_GTF_transfer_completed)\r
+\r
+/*\r
+ * Version 2 grant table entries. These fulfil the same role as\r
+ * version 1 entries, but can represent more complicated operations.\r
+ * Any given domain will have either a version 1 or a version 2 table,\r
+ * and every entry in the table will be the same version.\r
+ *\r
+ * The interface by which domains use grant references does not depend\r
+ * on the grant table version in use by the other domain.\r
+ */\r
+#if __XEN_INTERFACE_VERSION__ >= 0x0003020a\r
+/*\r
+ * Version 1 and version 2 grant entries share a common prefix. The\r
+ * fields of the prefix are documented as part of struct\r
+ * grant_entry_v1.\r
+ */\r
+struct grant_entry_header {\r
+ UINT16 flags;\r
+ domid_t domid;\r
+};\r
+typedef struct grant_entry_header grant_entry_header_t;\r
+\r
+/*\r
+ * Version 2 of the grant entry structure.\r
+ */\r
+union grant_entry_v2 {\r
+ grant_entry_header_t hdr;\r
+\r
+ /*\r
+ * This member is used for V1-style full page grants, where either:\r
+ *\r
+ * -- hdr.type is GTF_accept_transfer, or\r
+ * -- hdr.type is GTF_permit_access and GTF_sub_page is not set.\r
+ *\r
+ * In that case, the frame field has the same semantics as the\r
+ * field of the same name in the V1 entry structure.\r
+ */\r
+ struct {\r
+ grant_entry_header_t hdr;\r
+ UINT32 pad0;\r
+ UINT64 frame;\r
+ } full_page;\r
+\r
+ /*\r
+ * If the grant type is GTF_grant_access and GTF_sub_page is set,\r
+ * @domid is allowed to access bytes [@page_off,@page_off+@length)\r
+ * in frame @frame.\r
+ */\r
+ struct {\r
+ grant_entry_header_t hdr;\r
+ UINT16 page_off;\r
+ UINT16 length;\r
+ UINT64 frame;\r
+ } sub_page;\r
+\r
+ /*\r
+ * If the grant is GTF_transitive, @domid is allowed to use the\r
+ * grant @gref in domain @trans_domid, as if it was the local\r
+ * domain. Obviously, the transitive access must be compatible\r
+ * with the original grant.\r
+ *\r
+ * The current version of Xen does not allow transitive grants\r
+ * to be mapped.\r
+ */\r
+ struct {\r
+ grant_entry_header_t hdr;\r
+ domid_t trans_domid;\r
+ UINT16 pad0;\r
+ grant_ref_t gref;\r
+ } transitive;\r
+\r
+ UINT32 __spacer[4]; /* Pad to a power of two */\r
+};\r
+typedef union grant_entry_v2 grant_entry_v2_t;\r
+\r
+typedef UINT16 grant_status_t;\r
+\r
+#endif /* __XEN_INTERFACE_VERSION__ */\r
+\r
+/***********************************\r
+ * GRANT TABLE QUERIES AND USES\r
+ */\r
+\r
+/* ` enum neg_errnoval\r
+ * ` HYPERVISOR_grant_table_op(enum grant_table_op cmd,\r
+ * ` VOID *args,\r
+ * ` UINT32 count)\r
+ * `\r
+ *\r
+ * @args points to an array of a per-command data structure. The array\r
+ * has @count members\r
+ */\r
+\r
+/* ` enum grant_table_op { // GNTTABOP_* => struct gnttab_* */\r
+#define GNTTABOP_map_grant_ref 0\r
+#define GNTTABOP_unmap_grant_ref 1\r
+/* ` } */\r
+\r
+/*\r
+ * Handle to track a mapping created via a grant reference.\r
+ */\r
+typedef UINT32 grant_handle_t;\r
+\r
+/*\r
+ * GNTTABOP_map_grant_ref: Map the grant entry (<dom>,<ref>) for access\r
+ * by devices and/or host CPUs. If successful, <handle> is a tracking number\r
+ * that must be presented later to destroy the mapping(s). On error, <handle>\r
+ * is a negative status code.\r
+ * NOTES:\r
+ * 1. If GNTMAP_device_map is specified then <dev_bus_addr> is the address\r
+ * via which I/O devices may access the granted frame.\r
+ * 2. If GNTMAP_host_map is specified then a mapping will be added at\r
+ * either a host virtual address in the current address space, or at\r
+ * a PTE at the specified machine address. The type of mapping to\r
+ * perform is selected through the GNTMAP_contains_pte flag, and the\r
+ * address is specified in <host_addr>.\r
+ * 3. Mappings should only be destroyed via GNTTABOP_unmap_grant_ref. If a\r
+ * host mapping is destroyed by other means then it is *NOT* guaranteed\r
+ * to be accounted to the correct grant reference!\r
+ */\r
+struct gnttab_map_grant_ref {\r
+ /* IN parameters. */\r
+ UINT64 host_addr;\r
+ UINT32 flags; /* GNTMAP_* */\r
+ grant_ref_t ref;\r
+ domid_t dom;\r
+ /* OUT parameters. */\r
+ INT16 status; /* => enum grant_status */\r
+ grant_handle_t handle;\r
+ UINT64 dev_bus_addr;\r
+};\r
+typedef struct gnttab_map_grant_ref gnttab_map_grant_ref_t;\r
+DEFINE_XEN_GUEST_HANDLE(gnttab_map_grant_ref_t);\r
+\r
+/*\r
+ * GNTTABOP_unmap_grant_ref: Destroy one or more grant-reference mappings\r
+ * tracked by <handle>. If <host_addr> or <dev_bus_addr> is zero, that\r
+ * field is ignored. If non-zero, they must refer to a device/host mapping\r
+ * that is tracked by <handle>\r
+ * NOTES:\r
+ * 1. The call may fail in an undefined manner if either mapping is not\r
+ * tracked by <handle>.\r
+ * 3. After executing a batch of unmaps, it is guaranteed that no stale\r
+ * mappings will remain in the device or host TLBs.\r
+ */\r
+struct gnttab_unmap_grant_ref {\r
+ /* IN parameters. */\r
+ UINT64 host_addr;\r
+ UINT64 dev_bus_addr;\r
+ grant_handle_t handle;\r
+ /* OUT parameters. */\r
+ INT16 status; /* => enum grant_status */\r
+};\r
+typedef struct gnttab_unmap_grant_ref gnttab_unmap_grant_ref_t;\r
+DEFINE_XEN_GUEST_HANDLE(gnttab_unmap_grant_ref_t);\r
+\r
+/*\r
+ * Bitfield values for gnttab_map_grant_ref.flags.\r
+ */\r
+ /* Map the grant entry for access by I/O devices. */\r
+#define _GNTMAP_device_map (0)\r
+#define GNTMAP_device_map (1<<_GNTMAP_device_map)\r
+ /* Map the grant entry for access by host CPUs. */\r
+#define _GNTMAP_host_map (1)\r
+#define GNTMAP_host_map (1<<_GNTMAP_host_map)\r
+ /* Accesses to the granted frame will be restricted to read-only access. */\r
+#define _GNTMAP_readonly (2)\r
+#define GNTMAP_readonly (1<<_GNTMAP_readonly)\r
+ /*\r
+ * GNTMAP_host_map subflag:\r
+ * 0 => The host mapping is usable only by the guest OS.\r
+ * 1 => The host mapping is usable by guest OS + current application.\r
+ */\r
+#define _GNTMAP_application_map (3)\r
+#define GNTMAP_application_map (1<<_GNTMAP_application_map)\r
+\r
+ /*\r
+ * GNTMAP_contains_pte subflag:\r
+ * 0 => This map request contains a host virtual address.\r
+ * 1 => This map request contains the machine addess of the PTE to update.\r
+ */\r
+#define _GNTMAP_contains_pte (4)\r
+#define GNTMAP_contains_pte (1<<_GNTMAP_contains_pte)\r
+\r
+#define _GNTMAP_can_fail (5)\r
+#define GNTMAP_can_fail (1<<_GNTMAP_can_fail)\r
+\r
+/*\r
+ * Bits to be placed in guest kernel available PTE bits (architecture\r
+ * dependent; only supported when XENFEAT_gnttab_map_avail_bits is set).\r
+ */\r
+#define _GNTMAP_guest_avail0 (16)\r
+#define GNTMAP_guest_avail_mask ((UINT32)~0 << _GNTMAP_guest_avail0)\r
+\r
+/*\r
+ * Values for error status returns. All errors are -ve.\r
+ */\r
+/* ` enum grant_status { */\r
+#define GNTST_okay (0) /* Normal return. */\r
+#define GNTST_general_error (-1) /* General undefined error. */\r
+#define GNTST_bad_domain (-2) /* Unrecognsed domain id. */\r
+#define GNTST_bad_gntref (-3) /* Unrecognised or inappropriate gntref. */\r
+#define GNTST_bad_handle (-4) /* Unrecognised or inappropriate handle. */\r
+#define GNTST_bad_virt_addr (-5) /* Inappropriate virtual address to map. */\r
+#define GNTST_bad_dev_addr (-6) /* Inappropriate device address to unmap.*/\r
+#define GNTST_no_device_space (-7) /* Out of space in I/O MMU. */\r
+#define GNTST_permission_denied (-8) /* Not enough privilege for operation. */\r
+#define GNTST_bad_page (-9) /* Specified page was invalid for op. */\r
+#define GNTST_bad_copy_arg (-10) /* copy arguments cross page boundary. */\r
+#define GNTST_address_too_big (-11) /* transfer page address too large. */\r
+#define GNTST_eagain (-12) /* Operation not done; try again. */\r
+/* ` } */\r
+\r
+#define GNTTABOP_error_msgs { \\r
+ "okay", \\r
+ "undefined error", \\r
+ "unrecognised domain id", \\r
+ "invalid grant reference", \\r
+ "invalid mapping handle", \\r
+ "invalid virtual address", \\r
+ "invalid device address", \\r
+ "no spare translation slot in the I/O MMU", \\r
+ "permission denied", \\r
+ "bad page", \\r
+ "copy arguments cross page boundary", \\r
+ "page address size too large", \\r
+ "operation not done; try again" \\r
+}\r
+\r
+#endif /* __XEN_PUBLIC_GRANT_TABLE_H__ */\r
+\r
+/*\r
+ * Local variables:\r
+ * mode: C\r
+ * c-file-style: "BSD"\r
+ * c-basic-offset: 4\r
+ * tab-width: 4\r
+ * indent-tabs-mode: nil\r
+ * End:\r
+ */\r
--- /dev/null
+/*\r
+ * Permission is hereby granted, free of charge, to any person obtaining a copy\r
+ * of this software and associated documentation files (the "Software"), to\r
+ * deal in the Software without restriction, including without limitation the\r
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\r
+ * sell copies of the Software, and to permit persons to whom the Software is\r
+ * furnished to do so, subject to the following conditions:\r
+ *\r
+ * The above copyright notice and this permission notice shall be included in\r
+ * all copies or substantial portions of the Software.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\r
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\r
+ * DEALINGS IN THE SOFTWARE.\r
+ */\r
+\r
+#ifndef __XEN_PUBLIC_HVM_HVM_OP_H__\r
+#define __XEN_PUBLIC_HVM_HVM_OP_H__\r
+\r
+#include "../xen.h"\r
+\r
+/* Get/set subcommands: extra argument == pointer to xen_hvm_param struct. */\r
+#define HVMOP_set_param 0\r
+#define HVMOP_get_param 1\r
+struct xen_hvm_param {\r
+ domid_t domid; /* IN */\r
+ UINT32 index; /* IN */\r
+ UINT64 value; /* IN/OUT */\r
+};\r
+typedef struct xen_hvm_param xen_hvm_param_t;\r
+DEFINE_XEN_GUEST_HANDLE(xen_hvm_param_t);\r
+\r
+#endif /* __XEN_PUBLIC_HVM_HVM_OP_H__ */\r
--- /dev/null
+/*\r
+ * Permission is hereby granted, free of charge, to any person obtaining a copy\r
+ * of this software and associated documentation files (the "Software"), to\r
+ * deal in the Software without restriction, including without limitation the\r
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\r
+ * sell copies of the Software, and to permit persons to whom the Software is\r
+ * furnished to do so, subject to the following conditions:\r
+ *\r
+ * The above copyright notice and this permission notice shall be included in\r
+ * all copies or substantial portions of the Software.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\r
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\r
+ * DEALINGS IN THE SOFTWARE.\r
+ */\r
+\r
+#ifndef __XEN_PUBLIC_HVM_PARAMS_H__\r
+#define __XEN_PUBLIC_HVM_PARAMS_H__\r
+\r
+#include "hvm_op.h"\r
+\r
+/*\r
+ * Parameter space for HVMOP_{set,get}_param.\r
+ */\r
+\r
+/*\r
+ * How should CPU0 event-channel notifications be delivered?\r
+ * val[63:56] == 0: val[55:0] is a delivery GSI (Global System Interrupt).\r
+ * val[63:56] == 1: val[55:0] is a delivery PCI INTx line, as follows:\r
+ * Domain = val[47:32], Bus = val[31:16],\r
+ * DevFn = val[15: 8], IntX = val[ 1: 0]\r
+ * val[63:56] == 2: val[7:0] is a vector number, check for\r
+ * XENFEAT_hvm_callback_vector to know if this delivery\r
+ * method is available.\r
+ * If val == 0 then CPU0 event-channel notifications are not delivered.\r
+ */\r
+#define HVM_PARAM_CALLBACK_IRQ 0\r
+\r
+/*\r
+ * These are not used by Xen. They are here for convenience of HVM-guest\r
+ * xenbus implementations.\r
+ */\r
+#define HVM_PARAM_STORE_PFN 1\r
+#define HVM_PARAM_STORE_EVTCHN 2\r
+\r
+#define HVM_PARAM_PAE_ENABLED 4\r
+\r
+#define HVM_PARAM_IOREQ_PFN 5\r
+\r
+#define HVM_PARAM_BUFIOREQ_PFN 6\r
+#define HVM_PARAM_BUFIOREQ_EVTCHN 26\r
+\r
+#if defined(__i386__) || defined(__x86_64__)\r
+\r
+/* Expose Viridian interfaces to this HVM guest? */\r
+#define HVM_PARAM_VIRIDIAN 9\r
+\r
+#endif\r
+\r
+/*\r
+ * Set mode for virtual timers (currently x86 only):\r
+ * delay_for_missed_ticks (default):\r
+ * Do not advance a vcpu's time beyond the correct delivery time for\r
+ * interrupts that have been missed due to preemption. Deliver missed\r
+ * interrupts when the vcpu is rescheduled and advance the vcpu's virtual\r
+ * time stepwise for each one.\r
+ * no_delay_for_missed_ticks:\r
+ * As above, missed interrupts are delivered, but guest time always tracks\r
+ * wallclock (i.e., real) time while doing so.\r
+ * no_missed_ticks_pending:\r
+ * No missed interrupts are held pending. Instead, to ensure ticks are\r
+ * delivered at some non-zero rate, if we detect missed ticks then the\r
+ * internal tick alarm is not disabled if the VCPU is preempted during the\r
+ * next tick period.\r
+ * one_missed_tick_pending:\r
+ * Missed interrupts are collapsed together and delivered as one 'late tick'.\r
+ * Guest time always tracks wallclock (i.e., real) time.\r
+ */\r
+#define HVM_PARAM_TIMER_MODE 10\r
+#define HVMPTM_delay_for_missed_ticks 0\r
+#define HVMPTM_no_delay_for_missed_ticks 1\r
+#define HVMPTM_no_missed_ticks_pending 2\r
+#define HVMPTM_one_missed_tick_pending 3\r
+\r
+/* Boolean: Enable virtual HPET (high-precision event timer)? (x86-only) */\r
+#define HVM_PARAM_HPET_ENABLED 11\r
+\r
+/* Identity-map page directory used by Intel EPT when CR0.PG=0. */\r
+#define HVM_PARAM_IDENT_PT 12\r
+\r
+/* Device Model domain, defaults to 0. */\r
+#define HVM_PARAM_DM_DOMAIN 13\r
+\r
+/* ACPI S state: currently support S0 and S3 on x86. */\r
+#define HVM_PARAM_ACPI_S_STATE 14\r
+\r
+/* TSS used on Intel when CR0.PE=0. */\r
+#define HVM_PARAM_VM86_TSS 15\r
+\r
+/* Boolean: Enable aligning all periodic vpts to reduce interrupts */\r
+#define HVM_PARAM_VPT_ALIGN 16\r
+\r
+/* Console debug shared memory ring and event channel */\r
+#define HVM_PARAM_CONSOLE_PFN 17\r
+#define HVM_PARAM_CONSOLE_EVTCHN 18\r
+\r
+/*\r
+ * Select location of ACPI PM1a and TMR control blocks. Currently two locations\r
+ * are supported, specified by version 0 or 1 in this parameter:\r
+ * - 0: default, use the old addresses\r
+ * PM1A_EVT == 0x1f40; PM1A_CNT == 0x1f44; PM_TMR == 0x1f48\r
+ * - 1: use the new default qemu addresses\r
+ * PM1A_EVT == 0xb000; PM1A_CNT == 0xb004; PM_TMR == 0xb008\r
+ * You can find these address definitions in <hvm/ioreq.h>\r
+ */\r
+#define HVM_PARAM_ACPI_IOPORTS_LOCATION 19\r
+\r
+/* Enable blocking memory events, async or sync (pause vcpu until response) \r
+ * onchangeonly indicates messages only on a change of value */\r
+#define HVM_PARAM_MEMORY_EVENT_CR0 20\r
+#define HVM_PARAM_MEMORY_EVENT_CR3 21\r
+#define HVM_PARAM_MEMORY_EVENT_CR4 22\r
+#define HVM_PARAM_MEMORY_EVENT_INT3 23\r
+#define HVM_PARAM_MEMORY_EVENT_SINGLE_STEP 25\r
+#define HVM_PARAM_MEMORY_EVENT_MSR 30\r
+\r
+#define HVMPME_MODE_MASK (3 << 0)\r
+#define HVMPME_mode_disabled 0\r
+#define HVMPME_mode_async 1\r
+#define HVMPME_mode_sync 2\r
+#define HVMPME_onchangeonly (1 << 2)\r
+\r
+/* Boolean: Enable nestedhvm (hvm only) */\r
+#define HVM_PARAM_NESTEDHVM 24\r
+\r
+/* Params for the mem event rings */\r
+#define HVM_PARAM_PAGING_RING_PFN 27\r
+#define HVM_PARAM_ACCESS_RING_PFN 28\r
+#define HVM_PARAM_SHARING_RING_PFN 29\r
+\r
+/* SHUTDOWN_* action in case of a triple fault */\r
+#define HVM_PARAM_TRIPLE_FAULT_REASON 31\r
+\r
+#define HVM_NR_PARAMS 32\r
+\r
+#endif /* __XEN_PUBLIC_HVM_PARAMS_H__ */\r
--- /dev/null
+/******************************************************************************\r
+ * protocols.h\r
+ * \r
+ * Permission is hereby granted, free of charge, to any person obtaining a copy\r
+ * of this software and associated documentation files (the "Software"), to\r
+ * deal in the Software without restriction, including without limitation the\r
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\r
+ * sell copies of the Software, and to permit persons to whom the Software is\r
+ * furnished to do so, subject to the following conditions:\r
+ *\r
+ * The above copyright notice and this permission notice shall be included in\r
+ * all copies or substantial portions of the Software.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\r
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\r
+ * DEALINGS IN THE SOFTWARE.\r
+ */\r
+\r
+#ifndef __XEN_PROTOCOLS_H__\r
+#define __XEN_PROTOCOLS_H__\r
+\r
+#define XEN_IO_PROTO_ABI_X86_32 "x86_32-abi"\r
+#define XEN_IO_PROTO_ABI_X86_64 "x86_64-abi"\r
+#define XEN_IO_PROTO_ABI_ARM "arm-abi"\r
+\r
+#if defined(__i386__)\r
+# define XEN_IO_PROTO_ABI_NATIVE XEN_IO_PROTO_ABI_X86_32\r
+#elif defined(__x86_64__)\r
+# define XEN_IO_PROTO_ABI_NATIVE XEN_IO_PROTO_ABI_X86_64\r
+#elif defined(__arm__) || defined(__aarch64__)\r
+# define XEN_IO_PROTO_ABI_NATIVE XEN_IO_PROTO_ABI_ARM\r
+#else\r
+# error arch fixup needed here\r
+#endif\r
+\r
+#endif\r
--- /dev/null
+/******************************************************************************\r
+ * ring.h\r
+ * \r
+ * Shared producer-consumer ring macros.\r
+ *\r
+ * Permission is hereby granted, free of charge, to any person obtaining a copy\r
+ * of this software and associated documentation files (the "Software"), to\r
+ * deal in the Software without restriction, including without limitation the\r
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\r
+ * sell copies of the Software, and to permit persons to whom the Software is\r
+ * furnished to do so, subject to the following conditions:\r
+ *\r
+ * The above copyright notice and this permission notice shall be included in\r
+ * all copies or substantial portions of the Software.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\r
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\r
+ * DEALINGS IN THE SOFTWARE.\r
+ *\r
+ * Tim Deegan and Andrew Warfield November 2004.\r
+ */\r
+\r
+#ifndef __XEN_PUBLIC_IO_RING_H__\r
+#define __XEN_PUBLIC_IO_RING_H__\r
+\r
+#include "../xen-compat.h"\r
+\r
+#if __XEN_INTERFACE_VERSION__ < 0x00030208\r
+#define xen_mb() mb()\r
+#define xen_rmb() rmb()\r
+#define xen_wmb() wmb()\r
+#endif\r
+\r
+typedef UINT32 RING_IDX;\r
+\r
+/* Round a 32-bit unsigned constant down to the nearest power of two. */\r
+#define __RD2(_x) (((_x) & 0x00000002) ? 0x2 : ((_x) & 0x1))\r
+#define __RD4(_x) (((_x) & 0x0000000c) ? __RD2((_x)>>2)<<2 : __RD2(_x))\r
+#define __RD8(_x) (((_x) & 0x000000f0) ? __RD4((_x)>>4)<<4 : __RD4(_x))\r
+#define __RD16(_x) (((_x) & 0x0000ff00) ? __RD8((_x)>>8)<<8 : __RD8(_x))\r
+#define __RD32(_x) (((_x) & 0xffff0000) ? __RD16((_x)>>16)<<16 : __RD16(_x))\r
+\r
+/*\r
+ * Calculate size of a shared ring, given the total available space for the\r
+ * ring and indexes (_sz), and the name tag of the request/response structure.\r
+ * A ring contains as many entries as will fit, rounded down to the nearest \r
+ * power of two (so we can mask with (size-1) to loop around).\r
+ */\r
+#define __CONST_RING_SIZE(_s, _sz) \\r
+ (__RD32(((_sz) - offsetof(struct _s##_sring, ring)) / \\r
+ sizeof(((struct _s##_sring *)0)->ring[0])))\r
+/*\r
+ * The same for passing in an actual pointer instead of a name tag.\r
+ */\r
+#define __RING_SIZE(_s, _sz) \\r
+ (__RD32(((_sz) - (INTN)(_s)->ring + (INTN)(_s)) / sizeof((_s)->ring[0])))\r
+\r
+/*\r
+ * Macros to make the correct C datatypes for a new kind of ring.\r
+ * \r
+ * To make a new ring datatype, you need to have two message structures,\r
+ * let's say request_t, and response_t already defined.\r
+ *\r
+ * In a header where you want the ring datatype declared, you then do:\r
+ *\r
+ * DEFINE_RING_TYPES(mytag, request_t, response_t);\r
+ *\r
+ * These expand out to give you a set of types, as you can see below.\r
+ * The most important of these are:\r
+ * \r
+ * mytag_sring_t - The shared ring.\r
+ * mytag_front_ring_t - The 'front' half of the ring.\r
+ * mytag_back_ring_t - The 'back' half of the ring.\r
+ *\r
+ * To initialize a ring in your code you need to know the location and size\r
+ * of the shared memory area (PAGE_SIZE, for instance). To initialise\r
+ * the front half:\r
+ *\r
+ * mytag_front_ring_t front_ring;\r
+ * SHARED_RING_INIT((mytag_sring_t *)shared_page);\r
+ * FRONT_RING_INIT(&front_ring, (mytag_sring_t *)shared_page, PAGE_SIZE);\r
+ *\r
+ * Initializing the back follows similarly (note that only the front\r
+ * initializes the shared ring):\r
+ *\r
+ * mytag_back_ring_t back_ring;\r
+ * BACK_RING_INIT(&back_ring, (mytag_sring_t *)shared_page, PAGE_SIZE);\r
+ */\r
+\r
+#define DEFINE_RING_TYPES(__name, __req_t, __rsp_t) \\r
+ \\r
+/* Shared ring entry */ \\r
+union __name##_sring_entry { \\r
+ __req_t req; \\r
+ __rsp_t rsp; \\r
+}; \\r
+ \\r
+/* Shared ring page */ \\r
+struct __name##_sring { \\r
+ RING_IDX req_prod, req_event; \\r
+ RING_IDX rsp_prod, rsp_event; \\r
+ union { \\r
+ struct { \\r
+ UINT8 smartpoll_active; \\r
+ } netif; \\r
+ struct { \\r
+ UINT8 msg; \\r
+ } tapif_user; \\r
+ UINT8 pvt_pad[4]; \\r
+ } private; \\r
+ UINT8 __pad[44]; \\r
+ union __name##_sring_entry ring[1]; /* variable-length */ \\r
+}; \\r
+ \\r
+/* "Front" end's private variables */ \\r
+struct __name##_front_ring { \\r
+ RING_IDX req_prod_pvt; \\r
+ RING_IDX rsp_cons; \\r
+ UINT32 nr_ents; \\r
+ struct __name##_sring *sring; \\r
+}; \\r
+ \\r
+/* "Back" end's private variables */ \\r
+struct __name##_back_ring { \\r
+ RING_IDX rsp_prod_pvt; \\r
+ RING_IDX req_cons; \\r
+ UINT32 nr_ents; \\r
+ struct __name##_sring *sring; \\r
+}; \\r
+ \\r
+/* Syntactic sugar */ \\r
+typedef struct __name##_sring __name##_sring_t; \\r
+typedef struct __name##_front_ring __name##_front_ring_t; \\r
+typedef struct __name##_back_ring __name##_back_ring_t\r
+\r
+/*\r
+ * Macros for manipulating rings.\r
+ * \r
+ * FRONT_RING_whatever works on the "front end" of a ring: here \r
+ * requests are pushed on to the ring and responses taken off it.\r
+ * \r
+ * BACK_RING_whatever works on the "back end" of a ring: here \r
+ * requests are taken off the ring and responses put on.\r
+ * \r
+ * N.B. these macros do NO INTERLOCKS OR FLOW CONTROL. \r
+ * This is OK in 1-for-1 request-response situations where the \r
+ * requestor (front end) never has more than RING_SIZE()-1\r
+ * outstanding requests.\r
+ */\r
+\r
+/* Initialising empty rings */\r
+#define SHARED_RING_INIT(_s) do { \\r
+ (_s)->req_prod = (_s)->rsp_prod = 0; \\r
+ (_s)->req_event = (_s)->rsp_event = 1; \\r
+ (VOID)ZeroMem((_s)->private.pvt_pad, sizeof((_s)->private.pvt_pad)); \\r
+ (VOID)ZeroMem((_s)->__pad, sizeof((_s)->__pad)); \\r
+} while(0)\r
+\r
+#define FRONT_RING_INIT(_r, _s, __size) do { \\r
+ (_r)->req_prod_pvt = 0; \\r
+ (_r)->rsp_cons = 0; \\r
+ (_r)->nr_ents = __RING_SIZE(_s, __size); \\r
+ (_r)->sring = (_s); \\r
+} while (0)\r
+\r
+#define BACK_RING_INIT(_r, _s, __size) do { \\r
+ (_r)->rsp_prod_pvt = 0; \\r
+ (_r)->req_cons = 0; \\r
+ (_r)->nr_ents = __RING_SIZE(_s, __size); \\r
+ (_r)->sring = (_s); \\r
+} while (0)\r
+\r
+/* How big is this ring? */\r
+#define RING_SIZE(_r) \\r
+ ((_r)->nr_ents)\r
+\r
+/* Number of free requests (for use on front side only). */\r
+#define RING_FREE_REQUESTS(_r) \\r
+ (RING_SIZE(_r) - ((_r)->req_prod_pvt - (_r)->rsp_cons))\r
+\r
+/* Test if there is an empty slot available on the front ring.\r
+ * (This is only meaningful from the front. )\r
+ */\r
+#define RING_FULL(_r) \\r
+ (RING_FREE_REQUESTS(_r) == 0)\r
+\r
+/* Test if there are outstanding messages to be processed on a ring. */\r
+#define RING_HAS_UNCONSUMED_RESPONSES(_r) \\r
+ ((_r)->sring->rsp_prod - (_r)->rsp_cons)\r
+\r
+#ifdef __GNUC__\r
+#define RING_HAS_UNCONSUMED_REQUESTS(_r) ({ \\r
+ UINT32 req = (_r)->sring->req_prod - (_r)->req_cons; \\r
+ UINT32 rsp = RING_SIZE(_r) - \\r
+ ((_r)->req_cons - (_r)->rsp_prod_pvt); \\r
+ req < rsp ? req : rsp; \\r
+})\r
+#else\r
+/* Same as above, but without the nice GCC ({ ... }) syntax. */\r
+#define RING_HAS_UNCONSUMED_REQUESTS(_r) \\r
+ ((((_r)->sring->req_prod - (_r)->req_cons) < \\r
+ (RING_SIZE(_r) - ((_r)->req_cons - (_r)->rsp_prod_pvt))) ? \\r
+ ((_r)->sring->req_prod - (_r)->req_cons) : \\r
+ (RING_SIZE(_r) - ((_r)->req_cons - (_r)->rsp_prod_pvt)))\r
+#endif\r
+\r
+/* Direct access to individual ring elements, by index. */\r
+#define RING_GET_REQUEST(_r, _idx) \\r
+ (&((_r)->sring->ring[((_idx) & (RING_SIZE(_r) - 1))].req))\r
+\r
+#define RING_GET_RESPONSE(_r, _idx) \\r
+ (&((_r)->sring->ring[((_idx) & (RING_SIZE(_r) - 1))].rsp))\r
+\r
+/* Loop termination condition: Would the specified index overflow the ring? */\r
+#define RING_REQUEST_CONS_OVERFLOW(_r, _cons) \\r
+ (((_cons) - (_r)->rsp_prod_pvt) >= RING_SIZE(_r))\r
+\r
+/* Ill-behaved frontend determination: Can there be this many requests? */\r
+#define RING_REQUEST_PROD_OVERFLOW(_r, _prod) \\r
+ (((_prod) - (_r)->rsp_prod_pvt) > RING_SIZE(_r))\r
+\r
+#define RING_PUSH_REQUESTS(_r) do { \\r
+ xen_wmb(); /* back sees requests /before/ updated producer index */ \\r
+ (_r)->sring->req_prod = (_r)->req_prod_pvt; \\r
+} while (0)\r
+\r
+#define RING_PUSH_RESPONSES(_r) do { \\r
+ xen_wmb(); /* front sees resps /before/ updated producer index */ \\r
+ (_r)->sring->rsp_prod = (_r)->rsp_prod_pvt; \\r
+} while (0)\r
+\r
+/*\r
+ * Notification hold-off (req_event and rsp_event):\r
+ * \r
+ * When queueing requests or responses on a shared ring, it may not always be\r
+ * necessary to notify the remote end. For example, if requests are in flight\r
+ * in a backend, the front may be able to queue further requests without\r
+ * notifying the back (if the back checks for new requests when it queues\r
+ * responses).\r
+ * \r
+ * When enqueuing requests or responses:\r
+ * \r
+ * Use RING_PUSH_{REQUESTS,RESPONSES}_AND_CHECK_NOTIFY(). The second argument\r
+ * is a boolean return value. True indicates that the receiver requires an\r
+ * asynchronous notification.\r
+ * \r
+ * After dequeuing requests or responses (before sleeping the connection):\r
+ * \r
+ * Use RING_FINAL_CHECK_FOR_REQUESTS() or RING_FINAL_CHECK_FOR_RESPONSES().\r
+ * The second argument is a boolean return value. True indicates that there\r
+ * are pending messages on the ring (i.e., the connection should not be put\r
+ * to sleep).\r
+ * \r
+ * These macros will set the req_event/rsp_event field to trigger a\r
+ * notification on the very next message that is enqueued. If you want to\r
+ * create batches of work (i.e., only receive a notification after several\r
+ * messages have been enqueued) then you will need to create a customised\r
+ * version of the FINAL_CHECK macro in your own code, which sets the event\r
+ * field appropriately.\r
+ */\r
+\r
+#define RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(_r, _notify) do { \\r
+ RING_IDX __old = (_r)->sring->req_prod; \\r
+ RING_IDX __new = (_r)->req_prod_pvt; \\r
+ xen_wmb(); /* back sees requests /before/ updated producer index */ \\r
+ (_r)->sring->req_prod = __new; \\r
+ xen_mb(); /* back sees new requests /before/ we check req_event */ \\r
+ (_notify) = ((RING_IDX)(__new - (_r)->sring->req_event) < \\r
+ (RING_IDX)(__new - __old)); \\r
+} while (0)\r
+\r
+#define RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(_r, _notify) do { \\r
+ RING_IDX __old = (_r)->sring->rsp_prod; \\r
+ RING_IDX __new = (_r)->rsp_prod_pvt; \\r
+ xen_wmb(); /* front sees resps /before/ updated producer index */ \\r
+ (_r)->sring->rsp_prod = __new; \\r
+ xen_mb(); /* front sees new resps /before/ we check rsp_event */ \\r
+ (_notify) = ((RING_IDX)(__new - (_r)->sring->rsp_event) < \\r
+ (RING_IDX)(__new - __old)); \\r
+} while (0)\r
+\r
+#define RING_FINAL_CHECK_FOR_REQUESTS(_r, _work_to_do) do { \\r
+ (_work_to_do) = RING_HAS_UNCONSUMED_REQUESTS(_r); \\r
+ if (_work_to_do) break; \\r
+ (_r)->sring->req_event = (_r)->req_cons + 1; \\r
+ xen_mb(); \\r
+ (_work_to_do) = RING_HAS_UNCONSUMED_REQUESTS(_r); \\r
+} while (0)\r
+\r
+#define RING_FINAL_CHECK_FOR_RESPONSES(_r, _work_to_do) do { \\r
+ (_work_to_do) = RING_HAS_UNCONSUMED_RESPONSES(_r); \\r
+ if (_work_to_do) break; \\r
+ (_r)->sring->rsp_event = (_r)->rsp_cons + 1; \\r
+ xen_mb(); \\r
+ (_work_to_do) = RING_HAS_UNCONSUMED_RESPONSES(_r); \\r
+} while (0)\r
+\r
+#endif /* __XEN_PUBLIC_IO_RING_H__ */\r
+\r
+/*\r
+ * Local variables:\r
+ * mode: C\r
+ * c-file-style: "BSD"\r
+ * c-basic-offset: 4\r
+ * tab-width: 4\r
+ * indent-tabs-mode: nil\r
+ * End:\r
+ */\r
--- /dev/null
+/*****************************************************************************\r
+ * xenbus.h\r
+ *\r
+ * Xenbus protocol details.\r
+ *\r
+ * Permission is hereby granted, free of charge, to any person obtaining a copy\r
+ * of this software and associated documentation files (the "Software"), to\r
+ * deal in the Software without restriction, including without limitation the\r
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\r
+ * sell copies of the Software, and to permit persons to whom the Software is\r
+ * furnished to do so, subject to the following conditions:\r
+ *\r
+ * The above copyright notice and this permission notice shall be included in\r
+ * all copies or substantial portions of the Software.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\r
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\r
+ * DEALINGS IN THE SOFTWARE.\r
+ *\r
+ * Copyright (C) 2005 XenSource Ltd.\r
+ */\r
+\r
+#ifndef _XEN_PUBLIC_IO_XENBUS_H\r
+#define _XEN_PUBLIC_IO_XENBUS_H\r
+\r
+/*\r
+ * The state of either end of the Xenbus, i.e. the current communication\r
+ * status of initialisation across the bus. States here imply nothing about\r
+ * the state of the connection between the driver and the kernel's device\r
+ * layers.\r
+ */\r
+enum xenbus_state {\r
+ XenbusStateUnknown = 0,\r
+\r
+ XenbusStateInitialising = 1,\r
+\r
+ /*\r
+ * InitWait: Finished early initialisation but waiting for information\r
+ * from the peer or hotplug scripts.\r
+ */\r
+ XenbusStateInitWait = 2,\r
+\r
+ /*\r
+ * Initialised: Waiting for a connection from the peer.\r
+ */\r
+ XenbusStateInitialised = 3,\r
+\r
+ XenbusStateConnected = 4,\r
+\r
+ /*\r
+ * Closing: The device is being closed due to an error or an unplug event.\r
+ */\r
+ XenbusStateClosing = 5,\r
+\r
+ XenbusStateClosed = 6,\r
+\r
+ /*\r
+ * Reconfiguring: The device is being reconfigured.\r
+ */\r
+ XenbusStateReconfiguring = 7,\r
+\r
+ XenbusStateReconfigured = 8\r
+};\r
+typedef enum xenbus_state XenbusState;\r
+\r
+#endif /* _XEN_PUBLIC_IO_XENBUS_H */\r
+\r
+/*\r
+ * Local variables:\r
+ * mode: C\r
+ * c-file-style: "BSD"\r
+ * c-basic-offset: 4\r
+ * tab-width: 4\r
+ * indent-tabs-mode: nil\r
+ * End:\r
+ */\r
--- /dev/null
+/******************************************************************************\r
+ * memory.h\r
+ * \r
+ * Memory reservation and information.\r
+ * \r
+ * Permission is hereby granted, free of charge, to any person obtaining a copy\r
+ * of this software and associated documentation files (the "Software"), to\r
+ * deal in the Software without restriction, including without limitation the\r
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\r
+ * sell copies of the Software, and to permit persons to whom the Software is\r
+ * furnished to do so, subject to the following conditions:\r
+ *\r
+ * The above copyright notice and this permission notice shall be included in\r
+ * all copies or substantial portions of the Software.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\r
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\r
+ * DEALINGS IN THE SOFTWARE.\r
+ *\r
+ * Copyright (c) 2005, Keir Fraser <keir@xensource.com>\r
+ */\r
+\r
+#ifndef __XEN_PUBLIC_MEMORY_H__\r
+#define __XEN_PUBLIC_MEMORY_H__\r
+\r
+#include "xen.h"\r
+\r
+/* Source mapping space. */\r
+/* ` enum phys_map_space { */\r
+#define XENMAPSPACE_shared_info 0 /* shared info page */\r
+#define XENMAPSPACE_grant_table 1 /* grant table page */\r
+#define XENMAPSPACE_gmfn 2 /* GMFN */\r
+#define XENMAPSPACE_gmfn_range 3 /* GMFN range, XENMEM_add_to_physmap only. */\r
+#define XENMAPSPACE_gmfn_foreign 4 /* GMFN from another dom,\r
+ * XENMEM_add_to_physmap_batch only. */\r
+/* ` } */\r
+\r
+/*\r
+ * Sets the GPFN at which a particular page appears in the specified guest's\r
+ * pseudophysical address space.\r
+ * arg == addr of xen_add_to_physmap_t.\r
+ */\r
+#define XENMEM_add_to_physmap 7\r
+struct xen_add_to_physmap {\r
+ /* Which domain to change the mapping for. */\r
+ domid_t domid;\r
+\r
+ /* Number of pages to go through for gmfn_range */\r
+ UINT16 size;\r
+\r
+ UINT32 space; /* => enum phys_map_space */\r
+\r
+#define XENMAPIDX_grant_table_status 0x80000000\r
+\r
+ /* Index into space being mapped. */\r
+ xen_ulong_t idx;\r
+\r
+ /* GPFN in domid where the source mapping page should appear. */\r
+ xen_pfn_t gpfn;\r
+};\r
+typedef struct xen_add_to_physmap xen_add_to_physmap_t;\r
+DEFINE_XEN_GUEST_HANDLE(xen_add_to_physmap_t);\r
+\r
+/*\r
+ * Unmaps the page appearing at a particular GPFN from the specified guest's\r
+ * pseudophysical address space.\r
+ * arg == addr of xen_remove_from_physmap_t.\r
+ */\r
+#define XENMEM_remove_from_physmap 15\r
+struct xen_remove_from_physmap {\r
+ /* Which domain to change the mapping for. */\r
+ domid_t domid;\r
+\r
+ /* GPFN of the current mapping of the page. */\r
+ xen_pfn_t gpfn;\r
+};\r
+typedef struct xen_remove_from_physmap xen_remove_from_physmap_t;\r
+DEFINE_XEN_GUEST_HANDLE(xen_remove_from_physmap_t);\r
+\r
+#endif /* __XEN_PUBLIC_MEMORY_H__ */\r
+\r
+/*\r
+ * Local variables:\r
+ * mode: C\r
+ * c-file-style: "BSD"\r
+ * c-basic-offset: 4\r
+ * tab-width: 4\r
+ * indent-tabs-mode: nil\r
+ * End:\r
+ */\r
--- /dev/null
+/******************************************************************************\r
+ * xen-compat.h\r
+ * \r
+ * Guest OS interface to Xen. Compatibility layer.\r
+ * \r
+ * Permission is hereby granted, free of charge, to any person obtaining a copy\r
+ * of this software and associated documentation files (the "Software"), to\r
+ * deal in the Software without restriction, including without limitation the\r
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\r
+ * sell copies of the Software, and to permit persons to whom the Software is\r
+ * furnished to do so, subject to the following conditions:\r
+ *\r
+ * The above copyright notice and this permission notice shall be included in\r
+ * all copies or substantial portions of the Software.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\r
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\r
+ * DEALINGS IN THE SOFTWARE.\r
+ *\r
+ * Copyright (c) 2006, Christian Limpach\r
+ */\r
+\r
+#ifndef __XEN_PUBLIC_XEN_COMPAT_H__\r
+#define __XEN_PUBLIC_XEN_COMPAT_H__\r
+\r
+#define __XEN_LATEST_INTERFACE_VERSION__ 0x00040400\r
+\r
+#if defined(__XEN__) || defined(__XEN_TOOLS__)\r
+/* Xen is built with matching headers and implements the latest interface. */\r
+#define __XEN_INTERFACE_VERSION__ __XEN_LATEST_INTERFACE_VERSION__\r
+#elif !defined(__XEN_INTERFACE_VERSION__)\r
+/* Guests which do not specify a version get the legacy interface. */\r
+#define __XEN_INTERFACE_VERSION__ 0x00000000\r
+#endif\r
+\r
+#if __XEN_INTERFACE_VERSION__ > __XEN_LATEST_INTERFACE_VERSION__\r
+#error "These header files do not support the requested interface version."\r
+#endif\r
+\r
+#endif /* __XEN_PUBLIC_XEN_COMPAT_H__ */\r
--- /dev/null
+/******************************************************************************\r
+ * xen.h\r
+ * \r
+ * Guest OS interface to Xen.\r
+ * \r
+ * Permission is hereby granted, free of charge, to any person obtaining a copy\r
+ * of this software and associated documentation files (the "Software"), to\r
+ * deal in the Software without restriction, including without limitation the\r
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\r
+ * sell copies of the Software, and to permit persons to whom the Software is\r
+ * furnished to do so, subject to the following conditions:\r
+ *\r
+ * The above copyright notice and this permission notice shall be included in\r
+ * all copies or substantial portions of the Software.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\r
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\r
+ * DEALINGS IN THE SOFTWARE.\r
+ *\r
+ * Copyright (c) 2004, K A Fraser\r
+ */\r
+\r
+#ifndef __XEN_PUBLIC_XEN_H__\r
+#define __XEN_PUBLIC_XEN_H__\r
+\r
+#include "xen-compat.h"\r
+\r
+#if defined(__i386__) || defined(__x86_64__)\r
+#include "arch-x86/xen.h"\r
+#elif defined(__arm__) || defined (__aarch64__)\r
+#include "arch-arm.h"\r
+#else\r
+#error "Unsupported architecture"\r
+#endif\r
+\r
+#ifndef __ASSEMBLY__\r
+/* Guest handles for primitive C types. */\r
+DEFINE_XEN_GUEST_HANDLE(CHAR8);\r
+__DEFINE_XEN_GUEST_HANDLE(uchar, UINT8);\r
+DEFINE_XEN_GUEST_HANDLE(INT32);\r
+__DEFINE_XEN_GUEST_HANDLE(uint, UINT32);\r
+#if __XEN_INTERFACE_VERSION__ < 0x00040300\r
+DEFINE_XEN_GUEST_HANDLE(INTN);\r
+__DEFINE_XEN_GUEST_HANDLE(ulong, UINTN);\r
+#endif\r
+DEFINE_XEN_GUEST_HANDLE(VOID);\r
+\r
+DEFINE_XEN_GUEST_HANDLE(UINT64);\r
+DEFINE_XEN_GUEST_HANDLE(xen_pfn_t);\r
+DEFINE_XEN_GUEST_HANDLE(xen_ulong_t);\r
+#endif\r
+\r
+/*\r
+ * HYPERCALLS\r
+ */\r
+\r
+/* `incontents 100 hcalls List of hypercalls\r
+ * ` enum hypercall_num { // __HYPERVISOR_* => HYPERVISOR_*()\r
+ */\r
+\r
+#define __HYPERVISOR_set_trap_table 0\r
+#define __HYPERVISOR_mmu_update 1\r
+#define __HYPERVISOR_set_gdt 2\r
+#define __HYPERVISOR_stack_switch 3\r
+#define __HYPERVISOR_set_callbacks 4\r
+#define __HYPERVISOR_fpu_taskswitch 5\r
+#define __HYPERVISOR_sched_op_compat 6 /* compat since 0x00030101 */\r
+#define __HYPERVISOR_platform_op 7\r
+#define __HYPERVISOR_set_debugreg 8\r
+#define __HYPERVISOR_get_debugreg 9\r
+#define __HYPERVISOR_update_descriptor 10\r
+#define __HYPERVISOR_memory_op 12\r
+#define __HYPERVISOR_multicall 13\r
+#define __HYPERVISOR_update_va_mapping 14\r
+#define __HYPERVISOR_set_timer_op 15\r
+#define __HYPERVISOR_event_channel_op_compat 16 /* compat since 0x00030202 */\r
+#define __HYPERVISOR_xen_version 17\r
+#define __HYPERVISOR_console_io 18\r
+#define __HYPERVISOR_physdev_op_compat 19 /* compat since 0x00030202 */\r
+#define __HYPERVISOR_grant_table_op 20\r
+#define __HYPERVISOR_vm_assist 21\r
+#define __HYPERVISOR_update_va_mapping_otherdomain 22\r
+#define __HYPERVISOR_iret 23 /* x86 only */\r
+#define __HYPERVISOR_vcpu_op 24\r
+#define __HYPERVISOR_set_segment_base 25 /* x86/64 only */\r
+#define __HYPERVISOR_mmuext_op 26\r
+#define __HYPERVISOR_xsm_op 27\r
+#define __HYPERVISOR_nmi_op 28\r
+#define __HYPERVISOR_sched_op 29\r
+#define __HYPERVISOR_callback_op 30\r
+#define __HYPERVISOR_xenoprof_op 31\r
+#define __HYPERVISOR_event_channel_op 32\r
+#define __HYPERVISOR_physdev_op 33\r
+#define __HYPERVISOR_hvm_op 34\r
+#define __HYPERVISOR_sysctl 35\r
+#define __HYPERVISOR_domctl 36\r
+#define __HYPERVISOR_kexec_op 37\r
+#define __HYPERVISOR_tmem_op 38\r
+#define __HYPERVISOR_xc_reserved_op 39 /* reserved for XenClient */\r
+\r
+/* Architecture-specific hypercall definitions. */\r
+#define __HYPERVISOR_arch_0 48\r
+#define __HYPERVISOR_arch_1 49\r
+#define __HYPERVISOR_arch_2 50\r
+#define __HYPERVISOR_arch_3 51\r
+#define __HYPERVISOR_arch_4 52\r
+#define __HYPERVISOR_arch_5 53\r
+#define __HYPERVISOR_arch_6 54\r
+#define __HYPERVISOR_arch_7 55\r
+\r
+/* ` } */\r
+\r
+/*\r
+ * HYPERCALL COMPATIBILITY.\r
+ */\r
+\r
+/* New sched_op hypercall introduced in 0x00030101. */\r
+#if __XEN_INTERFACE_VERSION__ < 0x00030101\r
+#undef __HYPERVISOR_sched_op\r
+#define __HYPERVISOR_sched_op __HYPERVISOR_sched_op_compat\r
+#endif\r
+\r
+/* New event-channel and physdev hypercalls introduced in 0x00030202. */\r
+#if __XEN_INTERFACE_VERSION__ < 0x00030202\r
+#undef __HYPERVISOR_event_channel_op\r
+#define __HYPERVISOR_event_channel_op __HYPERVISOR_event_channel_op_compat\r
+#undef __HYPERVISOR_physdev_op\r
+#define __HYPERVISOR_physdev_op __HYPERVISOR_physdev_op_compat\r
+#endif\r
+\r
+/* New platform_op hypercall introduced in 0x00030204. */\r
+#if __XEN_INTERFACE_VERSION__ < 0x00030204\r
+#define __HYPERVISOR_dom0_op __HYPERVISOR_platform_op\r
+#endif\r
+\r
+#ifndef __ASSEMBLY__\r
+\r
+typedef UINT16 domid_t;\r
+\r
+/* Domain ids >= DOMID_FIRST_RESERVED cannot be used for ordinary domains. */\r
+#define DOMID_FIRST_RESERVED (0x7FF0U)\r
+\r
+/* DOMID_SELF is used in certain contexts to refer to oneself. */\r
+#define DOMID_SELF (0x7FF0U)\r
+\r
+/*\r
+ * DOMID_IO is used to restrict page-table updates to mapping I/O memory.\r
+ * Although no Foreign Domain need be specified to map I/O pages, DOMID_IO\r
+ * is useful to ensure that no mappings to the OS's own heap are accidentally\r
+ * installed. (e.g., in Linux this could cause havoc as reference counts\r
+ * aren't adjusted on the I/O-mapping code path).\r
+ * This only makes sense in MMUEXT_SET_FOREIGNDOM, but in that context can\r
+ * be specified by any calling domain.\r
+ */\r
+#define DOMID_IO (0x7FF1U)\r
+\r
+/*\r
+ * DOMID_XEN is used to allow privileged domains to map restricted parts of\r
+ * Xen's heap space (e.g., the machine_to_phys table).\r
+ * This only makes sense in MMUEXT_SET_FOREIGNDOM, and is only permitted if\r
+ * the caller is privileged.\r
+ */\r
+#define DOMID_XEN (0x7FF2U)\r
+\r
+/*\r
+ * DOMID_COW is used as the owner of sharable pages */\r
+#define DOMID_COW (0x7FF3U)\r
+\r
+/* DOMID_INVALID is used to identify pages with unknown owner. */\r
+#define DOMID_INVALID (0x7FF4U)\r
+\r
+/* Idle domain. */\r
+#define DOMID_IDLE (0x7FFFU)\r
+\r
+#if __XEN_INTERFACE_VERSION__ < 0x00040400\r
+/*\r
+ * Event channel endpoints per domain (when using the 2-level ABI):\r
+ * 1024 if a INTN is 32 bits; 4096 if a INTN is 64 bits.\r
+ */\r
+#define NR_EVENT_CHANNELS EVTCHN_2L_NR_CHANNELS\r
+#endif\r
+\r
+struct vcpu_time_info {\r
+ /*\r
+ * Updates to the following values are preceded and followed by an\r
+ * increment of 'version'. The guest can therefore detect updates by\r
+ * looking for changes to 'version'. If the least-significant bit of\r
+ * the version number is set then an update is in progress and the guest\r
+ * must wait to read a consistent set of values.\r
+ * The correct way to interact with the version number is similar to\r
+ * Linux's seqlock: see the implementations of read_seqbegin/read_seqretry.\r
+ */\r
+ UINT32 version;\r
+ UINT32 pad0;\r
+ UINT64 tsc_timestamp; /* TSC at last update of time vals. */\r
+ UINT64 system_time; /* Time, in nanosecs, since boot. */\r
+ /*\r
+ * Current system time:\r
+ * system_time +\r
+ * ((((tsc - tsc_timestamp) << tsc_shift) * tsc_to_system_mul) >> 32)\r
+ * CPU frequency (Hz):\r
+ * ((10^9 << 32) / tsc_to_system_mul) >> tsc_shift\r
+ */\r
+ UINT32 tsc_to_system_mul;\r
+ INT8 tsc_shift;\r
+ INT8 pad1[3];\r
+}; /* 32 bytes */\r
+typedef struct vcpu_time_info vcpu_time_info_t;\r
+\r
+struct vcpu_info {\r
+ /*\r
+ * 'evtchn_upcall_pending' is written non-zero by Xen to indicate\r
+ * a pending notification for a particular VCPU. It is then cleared \r
+ * by the guest OS /before/ checking for pending work, thus avoiding\r
+ * a set-and-check race. Note that the mask is only accessed by Xen\r
+ * on the CPU that is currently hosting the VCPU. This means that the\r
+ * pending and mask flags can be updated by the guest without special\r
+ * synchronisation (i.e., no need for the x86 LOCK prefix).\r
+ * This may seem suboptimal because if the pending flag is set by\r
+ * a different CPU then an IPI may be scheduled even when the mask\r
+ * is set. However, note:\r
+ * 1. The task of 'interrupt holdoff' is covered by the per-event-\r
+ * channel mask bits. A 'noisy' event that is continually being\r
+ * triggered can be masked at source at this very precise\r
+ * granularity.\r
+ * 2. The main purpose of the per-VCPU mask is therefore to restrict\r
+ * reentrant execution: whether for concurrency control, or to\r
+ * prevent unbounded stack usage. Whatever the purpose, we expect\r
+ * that the mask will be asserted only for short periods at a time,\r
+ * and so the likelihood of a 'spurious' IPI is suitably small.\r
+ * The mask is read before making an event upcall to the guest: a\r
+ * non-zero mask therefore guarantees that the VCPU will not receive\r
+ * an upcall activation. The mask is cleared when the VCPU requests\r
+ * to block: this avoids wakeup-waiting races.\r
+ */\r
+ UINT8 evtchn_upcall_pending;\r
+#ifdef XEN_HAVE_PV_UPCALL_MASK\r
+ UINT8 evtchn_upcall_mask;\r
+#else /* XEN_HAVE_PV_UPCALL_MASK */\r
+ UINT8 pad0;\r
+#endif /* XEN_HAVE_PV_UPCALL_MASK */\r
+ xen_ulong_t evtchn_pending_sel;\r
+ struct arch_vcpu_info arch;\r
+ struct vcpu_time_info time;\r
+}; /* 64 bytes (x86) */\r
+#ifndef __XEN__\r
+typedef struct vcpu_info vcpu_info_t;\r
+#endif\r
+\r
+/*\r
+ * `incontents 200 startofday_shared Start-of-day shared data structure\r
+ * Xen/kernel shared data -- pointer provided in start_info.\r
+ *\r
+ * This structure is defined to be both smaller than a page, and the\r
+ * only data on the shared page, but may vary in actual size even within\r
+ * compatible Xen versions; guests should not rely on the size\r
+ * of this structure remaining constant.\r
+ */\r
+struct shared_info {\r
+ struct vcpu_info vcpu_info[XEN_LEGACY_MAX_VCPUS];\r
+\r
+ /*\r
+ * A domain can create "event channels" on which it can send and receive\r
+ * asynchronous event notifications. There are three classes of event that\r
+ * are delivered by this mechanism:\r
+ * 1. Bi-directional inter- and intra-domain connections. Domains must\r
+ * arrange out-of-band to set up a connection (usually by allocating\r
+ * an unbound 'listener' port and avertising that via a storage service\r
+ * such as xenstore).\r
+ * 2. Physical interrupts. A domain with suitable hardware-access\r
+ * privileges can bind an event-channel port to a physical interrupt\r
+ * source.\r
+ * 3. Virtual interrupts ('events'). A domain can bind an event-channel\r
+ * port to a virtual interrupt source, such as the virtual-timer\r
+ * device or the emergency console.\r
+ * \r
+ * Event channels are addressed by a "port index". Each channel is\r
+ * associated with two bits of information:\r
+ * 1. PENDING -- notifies the domain that there is a pending notification\r
+ * to be processed. This bit is cleared by the guest.\r
+ * 2. MASK -- if this bit is clear then a 0->1 transition of PENDING\r
+ * will cause an asynchronous upcall to be scheduled. This bit is only\r
+ * updated by the guest. It is read-only within Xen. If a channel\r
+ * becomes pending while the channel is masked then the 'edge' is lost\r
+ * (i.e., when the channel is unmasked, the guest must manually handle\r
+ * pending notifications as no upcall will be scheduled by Xen).\r
+ * \r
+ * To expedite scanning of pending notifications, any 0->1 pending\r
+ * transition on an unmasked channel causes a corresponding bit in a\r
+ * per-vcpu selector word to be set. Each bit in the selector covers a\r
+ * 'C INTN' in the PENDING bitfield array.\r
+ */\r
+ xen_ulong_t evtchn_pending[sizeof(xen_ulong_t) * 8];\r
+ xen_ulong_t evtchn_mask[sizeof(xen_ulong_t) * 8];\r
+\r
+ /*\r
+ * Wallclock time: updated only by control software. Guests should base\r
+ * their gettimeofday() syscall on this wallclock-base value.\r
+ */\r
+ UINT32 wc_version; /* Version counter: see vcpu_time_info_t. */\r
+ UINT32 wc_sec; /* Secs 00:00:00 UTC, Jan 1, 1970. */\r
+ UINT32 wc_nsec; /* Nsecs 00:00:00 UTC, Jan 1, 1970. */\r
+\r
+ struct arch_shared_info arch;\r
+\r
+};\r
+#ifndef __XEN__\r
+typedef struct shared_info shared_info_t;\r
+#endif\r
+\r
+/* Turn a plain number into a C UINTN constant. */\r
+#define __mk_unsigned_long(x) x ## UL\r
+#define mk_unsigned_long(x) __mk_unsigned_long(x)\r
+\r
+__DEFINE_XEN_GUEST_HANDLE(uint8, UINT8);\r
+__DEFINE_XEN_GUEST_HANDLE(uint16, UINT16);\r
+__DEFINE_XEN_GUEST_HANDLE(uint32, UINT32);\r
+__DEFINE_XEN_GUEST_HANDLE(uint64, UINT64);\r
+\r
+#else /* __ASSEMBLY__ */\r
+\r
+/* In assembly code we cannot use C numeric constant suffixes. */\r
+#define mk_unsigned_long(x) x\r
+\r
+#endif /* !__ASSEMBLY__ */\r
+\r
+#endif /* __XEN_PUBLIC_XEN_H__ */\r
+\r
+/*\r
+ * Local variables:\r
+ * mode: C\r
+ * c-file-style: "BSD"\r
+ * c-basic-offset: 4\r
+ * tab-width: 4\r
+ * indent-tabs-mode: nil\r
+ * End:\r
+ */\r