aboutsummaryrefslogtreecommitdiffstats
path: root/include/xen
diff options
context:
space:
mode:
Diffstat (limited to 'include/xen')
-rw-r--r--include/xen/events.h2
-rw-r--r--include/xen/interface/elfnote.h48
-rw-r--r--include/xen/interface/io/vscsiif.h229
-rw-r--r--include/xen/interface/xen.h272
-rw-r--r--include/xen/xenbus.h21
5 files changed, 537 insertions, 35 deletions
diff --git a/include/xen/events.h b/include/xen/events.h
index 8bee7a75e850..5321cd9636e6 100644
--- a/include/xen/events.h
+++ b/include/xen/events.h
@@ -28,6 +28,8 @@ int bind_ipi_to_irqhandler(enum ipi_vector ipi,
28 unsigned long irqflags, 28 unsigned long irqflags,
29 const char *devname, 29 const char *devname,
30 void *dev_id); 30 void *dev_id);
31int bind_interdomain_evtchn_to_irq(unsigned int remote_domain,
32 unsigned int remote_port);
31int bind_interdomain_evtchn_to_irqhandler(unsigned int remote_domain, 33int bind_interdomain_evtchn_to_irqhandler(unsigned int remote_domain,
32 unsigned int remote_port, 34 unsigned int remote_port,
33 irq_handler_t handler, 35 irq_handler_t handler,
diff --git a/include/xen/interface/elfnote.h b/include/xen/interface/elfnote.h
index 6f4eae328ca7..f90b03454659 100644
--- a/include/xen/interface/elfnote.h
+++ b/include/xen/interface/elfnote.h
@@ -3,6 +3,24 @@
3 * 3 *
4 * Definitions used for the Xen ELF notes. 4 * Definitions used for the Xen ELF notes.
5 * 5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
6 * Copyright (c) 2006, Ian Campbell, XenSource Ltd. 24 * Copyright (c) 2006, Ian Campbell, XenSource Ltd.
7 */ 25 */
8 26
@@ -18,12 +36,13 @@
18 * 36 *
19 * LEGACY indicated the fields in the legacy __xen_guest string which 37 * LEGACY indicated the fields in the legacy __xen_guest string which
20 * this a note type replaces. 38 * this a note type replaces.
39 *
40 * String values (for non-legacy) are NULL terminated ASCII, also known
41 * as ASCIZ type.
21 */ 42 */
22 43
23/* 44/*
24 * NAME=VALUE pair (string). 45 * NAME=VALUE pair (string).
25 *
26 * LEGACY: FEATURES and PAE
27 */ 46 */
28#define XEN_ELFNOTE_INFO 0 47#define XEN_ELFNOTE_INFO 0
29 48
@@ -137,10 +156,30 @@
137 156
138/* 157/*
139 * Whether or not the guest supports cooperative suspend cancellation. 158 * Whether or not the guest supports cooperative suspend cancellation.
159 * This is a numeric value.
160 *
161 * Default is 0
140 */ 162 */
141#define XEN_ELFNOTE_SUSPEND_CANCEL 14 163#define XEN_ELFNOTE_SUSPEND_CANCEL 14
142 164
143/* 165/*
166 * The (non-default) location the initial phys-to-machine map should be
167 * placed at by the hypervisor (Dom0) or the tools (DomU).
168 * The kernel must be prepared for this mapping to be established using
169 * large pages, despite such otherwise not being available to guests.
170 * The kernel must also be able to handle the page table pages used for
171 * this mapping not being accessible through the initial mapping.
172 * (Only x86-64 supports this at present.)
173 */
174#define XEN_ELFNOTE_INIT_P2M 15
175
176/*
177 * Whether or not the guest can deal with being passed an initrd not
178 * mapped through its initial page tables.
179 */
180#define XEN_ELFNOTE_MOD_START_PFN 16
181
182/*
144 * The features supported by this kernel (numeric). 183 * The features supported by this kernel (numeric).
145 * 184 *
146 * Other than XEN_ELFNOTE_FEATURES on pre-4.2 Xen, this note allows a 185 * Other than XEN_ELFNOTE_FEATURES on pre-4.2 Xen, this note allows a
@@ -153,6 +192,11 @@
153 */ 192 */
154#define XEN_ELFNOTE_SUPPORTED_FEATURES 17 193#define XEN_ELFNOTE_SUPPORTED_FEATURES 17
155 194
195/*
196 * The number of the highest elfnote defined.
197 */
198#define XEN_ELFNOTE_MAX XEN_ELFNOTE_SUPPORTED_FEATURES
199
156#endif /* __XEN_PUBLIC_ELFNOTE_H__ */ 200#endif /* __XEN_PUBLIC_ELFNOTE_H__ */
157 201
158/* 202/*
diff --git a/include/xen/interface/io/vscsiif.h b/include/xen/interface/io/vscsiif.h
new file mode 100644
index 000000000000..d07d7aca8d1c
--- /dev/null
+++ b/include/xen/interface/io/vscsiif.h
@@ -0,0 +1,229 @@
1/******************************************************************************
2 * vscsiif.h
3 *
4 * Based on the blkif.h code.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
24 * Copyright(c) FUJITSU Limited 2008.
25 */
26
27#ifndef __XEN__PUBLIC_IO_SCSI_H__
28#define __XEN__PUBLIC_IO_SCSI_H__
29
30#include "ring.h"
31#include "../grant_table.h"
32
33/*
34 * Feature and Parameter Negotiation
35 * =================================
36 * The two halves of a Xen pvSCSI driver utilize nodes within the XenStore to
37 * communicate capabilities and to negotiate operating parameters. This
38 * section enumerates these nodes which reside in the respective front and
39 * backend portions of the XenStore, following the XenBus convention.
40 *
41 * Any specified default value is in effect if the corresponding XenBus node
42 * is not present in the XenStore.
43 *
44 * XenStore nodes in sections marked "PRIVATE" are solely for use by the
45 * driver side whose XenBus tree contains them.
46 *
47 *****************************************************************************
48 * Backend XenBus Nodes
49 *****************************************************************************
50 *
51 *------------------ Backend Device Identification (PRIVATE) ------------------
52 *
53 * p-devname
54 * Values: string
55 *
56 * A free string used to identify the physical device (e.g. a disk name).
57 *
58 * p-dev
59 * Values: string
60 *
61 * A string specifying the backend device: either a 4-tuple "h:c:t:l"
62 * (host, controller, target, lun, all integers), or a WWN (e.g.
63 * "naa.60014054ac780582").
64 *
65 * v-dev
66 * Values: string
67 *
68 * A string specifying the frontend device in form of a 4-tuple "h:c:t:l"
69 * (host, controller, target, lun, all integers).
70 *
71 *--------------------------------- Features ---------------------------------
72 *
73 * feature-sg-grant
74 * Values: unsigned [VSCSIIF_SG_TABLESIZE...65535]
75 * Default Value: 0
76 *
77 * Specifies the maximum number of scatter/gather elements in grant pages
78 * supported. If not set, the backend supports up to VSCSIIF_SG_TABLESIZE
79 * SG elements specified directly in the request.
80 *
81 *****************************************************************************
82 * Frontend XenBus Nodes
83 *****************************************************************************
84 *
85 *----------------------- Request Transport Parameters -----------------------
86 *
87 * event-channel
88 * Values: unsigned
89 *
90 * The identifier of the Xen event channel used to signal activity
91 * in the ring buffer.
92 *
93 * ring-ref
94 * Values: unsigned
95 *
96 * The Xen grant reference granting permission for the backend to map
97 * the sole page in a single page sized ring buffer.
98 *
99 * protocol
100 * Values: string (XEN_IO_PROTO_ABI_*)
101 * Default Value: XEN_IO_PROTO_ABI_NATIVE
102 *
103 * The machine ABI rules governing the format of all ring request and
104 * response structures.
105 */
106
107/* Requests from the frontend to the backend */
108
109/*
110 * Request a SCSI operation specified via a CDB in vscsiif_request.cmnd.
111 * The target is specified via channel, id and lun.
112 *
113 * The operation to be performed is specified via a CDB in cmnd[], the length
114 * of the CDB is in cmd_len. sc_data_direction specifies the direction of data
115 * (to the device, from the device, or none at all).
116 *
117 * If data is to be transferred to or from the device the buffer(s) in the
118 * guest memory is/are specified via one or multiple scsiif_request_segment
119 * descriptors each specifying a memory page via a grant_ref_t, a offset into
120 * the page and the length of the area in that page. All scsiif_request_segment
121 * areas concatenated form the resulting data buffer used by the operation.
122 * If the number of scsiif_request_segment areas is not too large (less than
123 * or equal VSCSIIF_SG_TABLESIZE) the areas can be specified directly in the
124 * seg[] array and the number of valid scsiif_request_segment elements is to be
125 * set in nr_segments.
126 *
127 * If "feature-sg-grant" in the Xenstore is set it is possible to specify more
128 * than VSCSIIF_SG_TABLESIZE scsiif_request_segment elements via indirection.
129 * The maximum number of allowed scsiif_request_segment elements is the value
130 * of the "feature-sg-grant" entry from Xenstore. When using indirection the
131 * seg[] array doesn't contain specifications of the data buffers, but
132 * references to scsiif_request_segment arrays, which in turn reference the
133 * data buffers. While nr_segments holds the number of populated seg[] entries
134 * (plus the set VSCSIIF_SG_GRANT bit), the number of scsiif_request_segment
135 * elements referencing the target data buffers is calculated from the lengths
136 * of the seg[] elements (the sum of all valid seg[].length divided by the
137 * size of one scsiif_request_segment structure).
138 */
139#define VSCSIIF_ACT_SCSI_CDB 1
140
141/*
142 * Request abort of a running operation for the specified target given by
143 * channel, id, lun and the operation's rqid in ref_rqid.
144 */
145#define VSCSIIF_ACT_SCSI_ABORT 2
146
147/*
148 * Request a device reset of the specified target (channel and id).
149 */
150#define VSCSIIF_ACT_SCSI_RESET 3
151
152/*
153 * Preset scatter/gather elements for a following request. Deprecated.
154 * Keeping the define only to avoid usage of the value "4" for other actions.
155 */
156#define VSCSIIF_ACT_SCSI_SG_PRESET 4
157
158/*
159 * Maximum scatter/gather segments per request.
160 *
161 * Considering balance between allocating at least 16 "vscsiif_request"
162 * structures on one page (4096 bytes) and the number of scatter/gather
163 * elements needed, we decided to use 26 as a magic number.
164 *
165 * If "feature-sg-grant" is set, more scatter/gather elements can be specified
166 * by placing them in one or more (up to VSCSIIF_SG_TABLESIZE) granted pages.
167 * In this case the vscsiif_request seg elements don't contain references to
168 * the user data, but to the SG elements referencing the user data.
169 */
170#define VSCSIIF_SG_TABLESIZE 26
171
172/*
173 * based on Linux kernel 2.6.18, still valid
174 * Changing these values requires support of multiple protocols via the rings
175 * as "old clients" will blindly use these values and the resulting structure
176 * sizes.
177 */
178#define VSCSIIF_MAX_COMMAND_SIZE 16
179#define VSCSIIF_SENSE_BUFFERSIZE 96
180
181struct scsiif_request_segment {
182 grant_ref_t gref;
183 uint16_t offset;
184 uint16_t length;
185};
186
187#define VSCSIIF_SG_PER_PAGE (PAGE_SIZE / sizeof(struct scsiif_request_segment))
188
189/* Size of one request is 252 bytes */
190struct vscsiif_request {
191 uint16_t rqid; /* private guest value, echoed in resp */
192 uint8_t act; /* command between backend and frontend */
193 uint8_t cmd_len; /* valid CDB bytes */
194
195 uint8_t cmnd[VSCSIIF_MAX_COMMAND_SIZE]; /* the CDB */
196 uint16_t timeout_per_command; /* deprecated */
197 uint16_t channel, id, lun; /* (virtual) device specification */
198 uint16_t ref_rqid; /* command abort reference */
199 uint8_t sc_data_direction; /* for DMA_TO_DEVICE(1)
200 DMA_FROM_DEVICE(2)
201 DMA_NONE(3) requests */
202 uint8_t nr_segments; /* Number of pieces of scatter-gather */
203/*
204 * flag in nr_segments: SG elements via grant page
205 *
206 * If VSCSIIF_SG_GRANT is set, the low 7 bits of nr_segments specify the number
207 * of grant pages containing SG elements. Usable if "feature-sg-grant" set.
208 */
209#define VSCSIIF_SG_GRANT 0x80
210
211 struct scsiif_request_segment seg[VSCSIIF_SG_TABLESIZE];
212 uint32_t reserved[3];
213};
214
215/* Size of one response is 252 bytes */
216struct vscsiif_response {
217 uint16_t rqid; /* identifies request */
218 uint8_t padding;
219 uint8_t sense_len;
220 uint8_t sense_buffer[VSCSIIF_SENSE_BUFFERSIZE];
221 int32_t rslt;
222 uint32_t residual_len; /* request bufflen -
223 return the value from physical device */
224 uint32_t reserved[36];
225};
226
227DEFINE_RING_TYPES(vscsiif, struct vscsiif_request, struct vscsiif_response);
228
229#endif /*__XEN__PUBLIC_IO_SCSI_H__*/
diff --git a/include/xen/interface/xen.h b/include/xen/interface/xen.h
index de082130ba4b..f68719f405af 100644
--- a/include/xen/interface/xen.h
+++ b/include/xen/interface/xen.h
@@ -3,6 +3,24 @@
3 * 3 *
4 * Guest OS interface to Xen. 4 * Guest OS interface to Xen.
5 * 5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
6 * Copyright (c) 2004, K A Fraser 24 * Copyright (c) 2004, K A Fraser
7 */ 25 */
8 26
@@ -73,13 +91,23 @@
73 * VIRTUAL INTERRUPTS 91 * VIRTUAL INTERRUPTS
74 * 92 *
75 * Virtual interrupts that a guest OS may receive from Xen. 93 * Virtual interrupts that a guest OS may receive from Xen.
94 * In the side comments, 'V.' denotes a per-VCPU VIRQ while 'G.' denotes a
95 * global VIRQ. The former can be bound once per VCPU and cannot be re-bound.
96 * The latter can be allocated only once per guest: they must initially be
97 * allocated to VCPU0 but can subsequently be re-bound.
76 */ 98 */
77#define VIRQ_TIMER 0 /* Timebase update, and/or requested timeout. */ 99#define VIRQ_TIMER 0 /* V. Timebase update, and/or requested timeout. */
78#define VIRQ_DEBUG 1 /* Request guest to dump debug info. */ 100#define VIRQ_DEBUG 1 /* V. Request guest to dump debug info. */
79#define VIRQ_CONSOLE 2 /* (DOM0) Bytes received on emergency console. */ 101#define VIRQ_CONSOLE 2 /* G. (DOM0) Bytes received on emergency console. */
80#define VIRQ_DOM_EXC 3 /* (DOM0) Exceptional event for some domain. */ 102#define VIRQ_DOM_EXC 3 /* G. (DOM0) Exceptional event for some domain. */
81#define VIRQ_DEBUGGER 6 /* (DOM0) A domain has paused for debugging. */ 103#define VIRQ_TBUF 4 /* G. (DOM0) Trace buffer has records available. */
82#define VIRQ_PCPU_STATE 9 /* (DOM0) PCPU state changed */ 104#define VIRQ_DEBUGGER 6 /* G. (DOM0) A domain has paused for debugging. */
105#define VIRQ_XENOPROF 7 /* V. XenOprofile interrupt: new sample available */
106#define VIRQ_CON_RING 8 /* G. (DOM0) Bytes received on console */
107#define VIRQ_PCPU_STATE 9 /* G. (DOM0) PCPU state changed */
108#define VIRQ_MEM_EVENT 10 /* G. (DOM0) A memory event has occured */
109#define VIRQ_XC_RESERVED 11 /* G. Reserved for XenClient */
110#define VIRQ_ENOMEM 12 /* G. (DOM0) Low on heap memory */
83 111
84/* Architecture-specific VIRQ definitions. */ 112/* Architecture-specific VIRQ definitions. */
85#define VIRQ_ARCH_0 16 113#define VIRQ_ARCH_0 16
@@ -92,24 +120,68 @@
92#define VIRQ_ARCH_7 23 120#define VIRQ_ARCH_7 23
93 121
94#define NR_VIRQS 24 122#define NR_VIRQS 24
123
95/* 124/*
96 * MMU-UPDATE REQUESTS 125 * enum neg_errnoval HYPERVISOR_mmu_update(const struct mmu_update reqs[],
97 * 126 * unsigned count, unsigned *done_out,
98 * HYPERVISOR_mmu_update() accepts a list of (ptr, val) pairs. 127 * unsigned foreigndom)
99 * A foreigndom (FD) can be specified (or DOMID_SELF for none). 128 * @reqs is an array of mmu_update_t structures ((ptr, val) pairs).
100 * Where the FD has some effect, it is described below. 129 * @count is the length of the above array.
101 * ptr[1:0] specifies the appropriate MMU_* command. 130 * @pdone is an output parameter indicating number of completed operations
131 * @foreigndom[15:0]: FD, the expected owner of data pages referenced in this
132 * hypercall invocation. Can be DOMID_SELF.
133 * @foreigndom[31:16]: PFD, the expected owner of pagetable pages referenced
134 * in this hypercall invocation. The value of this field
135 * (x) encodes the PFD as follows:
136 * x == 0 => PFD == DOMID_SELF
137 * x != 0 => PFD == x - 1
102 * 138 *
139 * Sub-commands: ptr[1:0] specifies the appropriate MMU_* command.
140 * -------------
103 * ptr[1:0] == MMU_NORMAL_PT_UPDATE: 141 * ptr[1:0] == MMU_NORMAL_PT_UPDATE:
104 * Updates an entry in a page table. If updating an L1 table, and the new 142 * Updates an entry in a page table belonging to PFD. If updating an L1 table,
105 * table entry is valid/present, the mapped frame must belong to the FD, if 143 * and the new table entry is valid/present, the mapped frame must belong to
106 * an FD has been specified. If attempting to map an I/O page then the 144 * FD. If attempting to map an I/O page then the caller assumes the privilege
107 * caller assumes the privilege of the FD. 145 * of the FD.
108 * FD == DOMID_IO: Permit /only/ I/O mappings, at the priv level of the caller. 146 * FD == DOMID_IO: Permit /only/ I/O mappings, at the priv level of the caller.
109 * FD == DOMID_XEN: Map restricted areas of Xen's heap space. 147 * FD == DOMID_XEN: Map restricted areas of Xen's heap space.
110 * ptr[:2] -- Machine address of the page-table entry to modify. 148 * ptr[:2] -- Machine address of the page-table entry to modify.
111 * val -- Value to write. 149 * val -- Value to write.
112 * 150 *
151 * There also certain implicit requirements when using this hypercall. The
152 * pages that make up a pagetable must be mapped read-only in the guest.
153 * This prevents uncontrolled guest updates to the pagetable. Xen strictly
154 * enforces this, and will disallow any pagetable update which will end up
155 * mapping pagetable page RW, and will disallow using any writable page as a
156 * pagetable. In practice it means that when constructing a page table for a
157 * process, thread, etc, we MUST be very dilligient in following these rules:
158 * 1). Start with top-level page (PGD or in Xen language: L4). Fill out
159 * the entries.
160 * 2). Keep on going, filling out the upper (PUD or L3), and middle (PMD
161 * or L2).
162 * 3). Start filling out the PTE table (L1) with the PTE entries. Once
163 * done, make sure to set each of those entries to RO (so writeable bit
164 * is unset). Once that has been completed, set the PMD (L2) for this
165 * PTE table as RO.
166 * 4). When completed with all of the PMD (L2) entries, and all of them have
167 * been set to RO, make sure to set RO the PUD (L3). Do the same
168 * operation on PGD (L4) pagetable entries that have a PUD (L3) entry.
169 * 5). Now before you can use those pages (so setting the cr3), you MUST also
170 * pin them so that the hypervisor can verify the entries. This is done
171 * via the HYPERVISOR_mmuext_op(MMUEXT_PIN_L4_TABLE, guest physical frame
172 * number of the PGD (L4)). And this point the HYPERVISOR_mmuext_op(
173 * MMUEXT_NEW_BASEPTR, guest physical frame number of the PGD (L4)) can be
174 * issued.
175 * For 32-bit guests, the L4 is not used (as there is less pagetables), so
176 * instead use L3.
177 * At this point the pagetables can be modified using the MMU_NORMAL_PT_UPDATE
178 * hypercall. Also if so desired the OS can also try to write to the PTE
179 * and be trapped by the hypervisor (as the PTE entry is RO).
180 *
181 * To deallocate the pages, the operations are the reverse of the steps
182 * mentioned above. The argument is MMUEXT_UNPIN_TABLE for all levels and the
183 * pagetable MUST not be in use (meaning that the cr3 is not set to it).
184 *
113 * ptr[1:0] == MMU_MACHPHYS_UPDATE: 185 * ptr[1:0] == MMU_MACHPHYS_UPDATE:
114 * Updates an entry in the machine->pseudo-physical mapping table. 186 * Updates an entry in the machine->pseudo-physical mapping table.
115 * ptr[:2] -- Machine address within the frame whose mapping to modify. 187 * ptr[:2] -- Machine address within the frame whose mapping to modify.
@@ -119,6 +191,72 @@
119 * ptr[1:0] == MMU_PT_UPDATE_PRESERVE_AD: 191 * ptr[1:0] == MMU_PT_UPDATE_PRESERVE_AD:
120 * As MMU_NORMAL_PT_UPDATE above, but A/D bits currently in the PTE are ORed 192 * As MMU_NORMAL_PT_UPDATE above, but A/D bits currently in the PTE are ORed
121 * with those in @val. 193 * with those in @val.
194 *
195 * @val is usually the machine frame number along with some attributes.
196 * The attributes by default follow the architecture defined bits. Meaning that
197 * if this is a X86_64 machine and four page table layout is used, the layout
198 * of val is:
199 * - 63 if set means No execute (NX)
200 * - 46-13 the machine frame number
201 * - 12 available for guest
202 * - 11 available for guest
203 * - 10 available for guest
204 * - 9 available for guest
205 * - 8 global
206 * - 7 PAT (PSE is disabled, must use hypercall to make 4MB or 2MB pages)
207 * - 6 dirty
208 * - 5 accessed
209 * - 4 page cached disabled
210 * - 3 page write through
211 * - 2 userspace accessible
212 * - 1 writeable
213 * - 0 present
214 *
215 * The one bits that does not fit with the default layout is the PAGE_PSE
216 * also called PAGE_PAT). The MMUEXT_[UN]MARK_SUPER arguments to the
217 * HYPERVISOR_mmuext_op serve as mechanism to set a pagetable to be 4MB
218 * (or 2MB) instead of using the PAGE_PSE bit.
219 *
220 * The reason that the PAGE_PSE (bit 7) is not being utilized is due to Xen
221 * using it as the Page Attribute Table (PAT) bit - for details on it please
222 * refer to Intel SDM 10.12. The PAT allows to set the caching attributes of
223 * pages instead of using MTRRs.
224 *
225 * The PAT MSR is as follows (it is a 64-bit value, each entry is 8 bits):
226 * PAT4 PAT0
227 * +-----+-----+----+----+----+-----+----+----+
228 * | UC | UC- | WC | WB | UC | UC- | WC | WB | <= Linux
229 * +-----+-----+----+----+----+-----+----+----+
230 * | UC | UC- | WT | WB | UC | UC- | WT | WB | <= BIOS (default when machine boots)
231 * +-----+-----+----+----+----+-----+----+----+
232 * | rsv | rsv | WP | WC | UC | UC- | WT | WB | <= Xen
233 * +-----+-----+----+----+----+-----+----+----+
234 *
235 * The lookup of this index table translates to looking up
236 * Bit 7, Bit 4, and Bit 3 of val entry:
237 *
238 * PAT/PSE (bit 7) ... PCD (bit 4) .. PWT (bit 3).
239 *
240 * If all bits are off, then we are using PAT0. If bit 3 turned on,
241 * then we are using PAT1, if bit 3 and bit 4, then PAT2..
242 *
243 * As you can see, the Linux PAT1 translates to PAT4 under Xen. Which means
244 * that if a guest that follows Linux's PAT setup and would like to set Write
245 * Combined on pages it MUST use PAT4 entry. Meaning that Bit 7 (PAGE_PAT) is
246 * set. For example, under Linux it only uses PAT0, PAT1, and PAT2 for the
247 * caching as:
248 *
249 * WB = none (so PAT0)
250 * WC = PWT (bit 3 on)
251 * UC = PWT | PCD (bit 3 and 4 are on).
252 *
253 * To make it work with Xen, it needs to translate the WC bit as so:
254 *
255 * PWT (so bit 3 on) --> PAT (so bit 7 is on) and clear bit 3
256 *
257 * And to translate back it would:
258 *
259 * PAT (bit 7 on) --> PWT (bit 3 on) and clear bit 7.
122 */ 260 */
123#define MMU_NORMAL_PT_UPDATE 0 /* checked '*ptr = val'. ptr is MA. */ 261#define MMU_NORMAL_PT_UPDATE 0 /* checked '*ptr = val'. ptr is MA. */
124#define MMU_MACHPHYS_UPDATE 1 /* ptr = MA of frame to modify entry for */ 262#define MMU_MACHPHYS_UPDATE 1 /* ptr = MA of frame to modify entry for */
@@ -127,7 +265,12 @@
127/* 265/*
128 * MMU EXTENDED OPERATIONS 266 * MMU EXTENDED OPERATIONS
129 * 267 *
130 * HYPERVISOR_mmuext_op() accepts a list of mmuext_op structures. 268 * enum neg_errnoval HYPERVISOR_mmuext_op(mmuext_op_t uops[],
269 * unsigned int count,
270 * unsigned int *pdone,
271 * unsigned int foreigndom)
272 */
273/* HYPERVISOR_mmuext_op() accepts a list of mmuext_op structures.
131 * A foreigndom (FD) can be specified (or DOMID_SELF for none). 274 * A foreigndom (FD) can be specified (or DOMID_SELF for none).
132 * Where the FD has some effect, it is described below. 275 * Where the FD has some effect, it is described below.
133 * 276 *
@@ -164,9 +307,23 @@
164 * cmd: MMUEXT_FLUSH_CACHE 307 * cmd: MMUEXT_FLUSH_CACHE
165 * No additional arguments. Writes back and flushes cache contents. 308 * No additional arguments. Writes back and flushes cache contents.
166 * 309 *
310 * cmd: MMUEXT_FLUSH_CACHE_GLOBAL
311 * No additional arguments. Writes back and flushes cache contents
312 * on all CPUs in the system.
313 *
167 * cmd: MMUEXT_SET_LDT 314 * cmd: MMUEXT_SET_LDT
168 * linear_addr: Linear address of LDT base (NB. must be page-aligned). 315 * linear_addr: Linear address of LDT base (NB. must be page-aligned).
169 * nr_ents: Number of entries in LDT. 316 * nr_ents: Number of entries in LDT.
317 *
318 * cmd: MMUEXT_CLEAR_PAGE
319 * mfn: Machine frame number to be cleared.
320 *
321 * cmd: MMUEXT_COPY_PAGE
322 * mfn: Machine frame number of the destination page.
323 * src_mfn: Machine frame number of the source page.
324 *
325 * cmd: MMUEXT_[UN]MARK_SUPER
326 * mfn: Machine frame number of head of superpage to be [un]marked.
170 */ 327 */
171#define MMUEXT_PIN_L1_TABLE 0 328#define MMUEXT_PIN_L1_TABLE 0
172#define MMUEXT_PIN_L2_TABLE 1 329#define MMUEXT_PIN_L2_TABLE 1
@@ -183,12 +340,18 @@
183#define MMUEXT_FLUSH_CACHE 12 340#define MMUEXT_FLUSH_CACHE 12
184#define MMUEXT_SET_LDT 13 341#define MMUEXT_SET_LDT 13
185#define MMUEXT_NEW_USER_BASEPTR 15 342#define MMUEXT_NEW_USER_BASEPTR 15
343#define MMUEXT_CLEAR_PAGE 16
344#define MMUEXT_COPY_PAGE 17
345#define MMUEXT_FLUSH_CACHE_GLOBAL 18
346#define MMUEXT_MARK_SUPER 19
347#define MMUEXT_UNMARK_SUPER 20
186 348
187#ifndef __ASSEMBLY__ 349#ifndef __ASSEMBLY__
188struct mmuext_op { 350struct mmuext_op {
189 unsigned int cmd; 351 unsigned int cmd;
190 union { 352 union {
191 /* [UN]PIN_TABLE, NEW_BASEPTR, NEW_USER_BASEPTR */ 353 /* [UN]PIN_TABLE, NEW_BASEPTR, NEW_USER_BASEPTR
354 * CLEAR_PAGE, COPY_PAGE, [UN]MARK_SUPER */
192 xen_pfn_t mfn; 355 xen_pfn_t mfn;
193 /* INVLPG_LOCAL, INVLPG_ALL, SET_LDT */ 356 /* INVLPG_LOCAL, INVLPG_ALL, SET_LDT */
194 unsigned long linear_addr; 357 unsigned long linear_addr;
@@ -198,6 +361,8 @@ struct mmuext_op {
198 unsigned int nr_ents; 361 unsigned int nr_ents;
199 /* TLB_FLUSH_MULTI, INVLPG_MULTI */ 362 /* TLB_FLUSH_MULTI, INVLPG_MULTI */
200 void *vcpumask; 363 void *vcpumask;
364 /* COPY_PAGE */
365 xen_pfn_t src_mfn;
201 } arg2; 366 } arg2;
202}; 367};
203DEFINE_GUEST_HANDLE_STRUCT(mmuext_op); 368DEFINE_GUEST_HANDLE_STRUCT(mmuext_op);
@@ -225,10 +390,23 @@ DEFINE_GUEST_HANDLE_STRUCT(mmuext_op);
225 */ 390 */
226#define VMASST_CMD_enable 0 391#define VMASST_CMD_enable 0
227#define VMASST_CMD_disable 1 392#define VMASST_CMD_disable 1
393
394/* x86/32 guests: simulate full 4GB segment limits. */
228#define VMASST_TYPE_4gb_segments 0 395#define VMASST_TYPE_4gb_segments 0
396
397/* x86/32 guests: trap (vector 15) whenever above vmassist is used. */
229#define VMASST_TYPE_4gb_segments_notify 1 398#define VMASST_TYPE_4gb_segments_notify 1
399
400/*
401 * x86 guests: support writes to bottom-level PTEs.
402 * NB1. Page-directory entries cannot be written.
403 * NB2. Guest must continue to remove all writable mappings of PTEs.
404 */
230#define VMASST_TYPE_writable_pagetables 2 405#define VMASST_TYPE_writable_pagetables 2
406
407/* x86/PAE guests: support PDPTs above 4GB. */
231#define VMASST_TYPE_pae_extended_cr3 3 408#define VMASST_TYPE_pae_extended_cr3 3
409
232#define MAX_VMASST_TYPE 3 410#define MAX_VMASST_TYPE 3
233 411
234#ifndef __ASSEMBLY__ 412#ifndef __ASSEMBLY__
@@ -260,6 +438,15 @@ typedef uint16_t domid_t;
260 */ 438 */
261#define DOMID_XEN (0x7FF2U) 439#define DOMID_XEN (0x7FF2U)
262 440
441/* DOMID_COW is used as the owner of sharable pages */
442#define DOMID_COW (0x7FF3U)
443
444/* DOMID_INVALID is used to identify pages with unknown owner. */
445#define DOMID_INVALID (0x7FF4U)
446
447/* Idle domain. */
448#define DOMID_IDLE (0x7FFFU)
449
263/* 450/*
264 * Send an array of these to HYPERVISOR_mmu_update(). 451 * Send an array of these to HYPERVISOR_mmu_update().
265 * NB. The fields are natural pointer/address size for this architecture. 452 * NB. The fields are natural pointer/address size for this architecture.
@@ -272,7 +459,9 @@ DEFINE_GUEST_HANDLE_STRUCT(mmu_update);
272 459
273/* 460/*
274 * Send an array of these to HYPERVISOR_multicall(). 461 * Send an array of these to HYPERVISOR_multicall().
275 * NB. The fields are natural register size for this architecture. 462 * NB. The fields are logically the natural register size for this
463 * architecture. In cases where xen_ulong_t is larger than this then
464 * any unused bits in the upper portion must be zero.
276 */ 465 */
277struct multicall_entry { 466struct multicall_entry {
278 xen_ulong_t op; 467 xen_ulong_t op;
@@ -442,8 +631,48 @@ struct start_info {
442 unsigned long mod_start; /* VIRTUAL address of pre-loaded module. */ 631 unsigned long mod_start; /* VIRTUAL address of pre-loaded module. */
443 unsigned long mod_len; /* Size (bytes) of pre-loaded module. */ 632 unsigned long mod_len; /* Size (bytes) of pre-loaded module. */
444 int8_t cmd_line[MAX_GUEST_CMDLINE]; 633 int8_t cmd_line[MAX_GUEST_CMDLINE];
634 /* The pfn range here covers both page table and p->m table frames. */
635 unsigned long first_p2m_pfn;/* 1st pfn forming initial P->M table. */
636 unsigned long nr_p2m_frames;/* # of pfns forming initial P->M table. */
445}; 637};
446 638
639/* These flags are passed in the 'flags' field of start_info_t. */
640#define SIF_PRIVILEGED (1<<0) /* Is the domain privileged? */
641#define SIF_INITDOMAIN (1<<1) /* Is this the initial control domain? */
642#define SIF_MULTIBOOT_MOD (1<<2) /* Is mod_start a multiboot module? */
643#define SIF_MOD_START_PFN (1<<3) /* Is mod_start a PFN? */
644#define SIF_PM_MASK (0xFF<<8) /* reserve 1 byte for xen-pm options */
645
646/*
647 * A multiboot module is a package containing modules very similar to a
648 * multiboot module array. The only differences are:
649 * - the array of module descriptors is by convention simply at the beginning
650 * of the multiboot module,
651 * - addresses in the module descriptors are based on the beginning of the
652 * multiboot module,
653 * - the number of modules is determined by a termination descriptor that has
654 * mod_start == 0.
655 *
656 * This permits to both build it statically and reference it in a configuration
657 * file, and let the PV guest easily rebase the addresses to virtual addresses
658 * and at the same time count the number of modules.
659 */
660struct xen_multiboot_mod_list {
661 /* Address of first byte of the module */
662 uint32_t mod_start;
663 /* Address of last byte of the module (inclusive) */
664 uint32_t mod_end;
665 /* Address of zero-terminated command line */
666 uint32_t cmdline;
667 /* Unused, must be zero */
668 uint32_t pad;
669};
670/*
671 * The console structure in start_info.console.dom0
672 *
673 * This structure includes a variety of information required to
674 * have a working VGA/VESA console.
675 */
447struct dom0_vga_console_info { 676struct dom0_vga_console_info {
448 uint8_t video_type; 677 uint8_t video_type;
449#define XEN_VGATYPE_TEXT_MODE_3 0x03 678#define XEN_VGATYPE_TEXT_MODE_3 0x03
@@ -484,11 +713,6 @@ struct dom0_vga_console_info {
484 } u; 713 } u;
485}; 714};
486 715
487/* These flags are passed in the 'flags' field of start_info_t. */
488#define SIF_PRIVILEGED (1<<0) /* Is the domain privileged? */
489#define SIF_INITDOMAIN (1<<1) /* Is this the initial control domain? */
490#define SIF_PM_MASK (0xFF<<8) /* reserve 1 byte for xen-pm options */
491
492typedef uint64_t cpumap_t; 716typedef uint64_t cpumap_t;
493 717
494typedef uint8_t xen_domain_handle_t[16]; 718typedef uint8_t xen_domain_handle_t[16];
diff --git a/include/xen/xenbus.h b/include/xen/xenbus.h
index 0324c6d340c1..b78f21caf55a 100644
--- a/include/xen/xenbus.h
+++ b/include/xen/xenbus.h
@@ -86,6 +86,7 @@ struct xenbus_device_id
86 86
87/* A xenbus driver. */ 87/* A xenbus driver. */
88struct xenbus_driver { 88struct xenbus_driver {
89 const char *name; /* defaults to ids[0].devicetype */
89 const struct xenbus_device_id *ids; 90 const struct xenbus_device_id *ids;
90 int (*probe)(struct xenbus_device *dev, 91 int (*probe)(struct xenbus_device *dev,
91 const struct xenbus_device_id *id); 92 const struct xenbus_device_id *id);
@@ -100,20 +101,22 @@ struct xenbus_driver {
100 int (*is_ready)(struct xenbus_device *dev); 101 int (*is_ready)(struct xenbus_device *dev);
101}; 102};
102 103
103#define DEFINE_XENBUS_DRIVER(var, drvname, methods...) \
104struct xenbus_driver var ## _driver = { \
105 .driver.name = drvname + 0 ?: var ## _ids->devicetype, \
106 .driver.owner = THIS_MODULE, \
107 .ids = var ## _ids, ## methods \
108}
109
110static inline struct xenbus_driver *to_xenbus_driver(struct device_driver *drv) 104static inline struct xenbus_driver *to_xenbus_driver(struct device_driver *drv)
111{ 105{
112 return container_of(drv, struct xenbus_driver, driver); 106 return container_of(drv, struct xenbus_driver, driver);
113} 107}
114 108
115int __must_check xenbus_register_frontend(struct xenbus_driver *); 109int __must_check __xenbus_register_frontend(struct xenbus_driver *drv,
116int __must_check xenbus_register_backend(struct xenbus_driver *); 110 struct module *owner,
111 const char *mod_name);
112int __must_check __xenbus_register_backend(struct xenbus_driver *drv,
113 struct module *owner,
114 const char *mod_name);
115
116#define xenbus_register_frontend(drv) \
117 __xenbus_register_frontend(drv, THIS_MODULE, KBUILD_MODNAME);
118#define xenbus_register_backend(drv) \
119 __xenbus_register_backend(drv, THIS_MODULE, KBUILD_MODNAME);
117 120
118void xenbus_unregister_driver(struct xenbus_driver *drv); 121void xenbus_unregister_driver(struct xenbus_driver *drv);
119 122