1/* $NetBSD: physdev.h,v 1.7 2016/07/07 06:55:40 msaitoh Exp $ */
2/*
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
4 * of this software and associated documentation files (the "Software"), to
5 * deal in the Software without restriction, including without limitation the
6 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 * sell copies of the Software, and to permit persons to whom the Software is
8 * furnished to do so, subject to the following conditions:
9 *
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
19 * DEALINGS IN THE SOFTWARE.
20 */
21
22#ifndef __XEN_PUBLIC_PHYSDEV_H__
23#define __XEN_PUBLIC_PHYSDEV_H__
24
25#include "xen.h"
26
27/*
28 * Prototype for this hypercall is:
29 * int physdev_op(int cmd, void *args)
30 * @cmd == PHYSDEVOP_??? (physdev operation).
31 * @args == Operation-specific extra arguments (NULL if none).
32 */
33
34/*
35 * Notify end-of-interrupt (EOI) for the specified IRQ.
36 * @arg == pointer to physdev_eoi structure.
37 */
38#define PHYSDEVOP_eoi 12
39struct physdev_eoi {
40 /* IN */
41 uint32_t irq;
42};
43typedef struct physdev_eoi physdev_eoi_t;
44DEFINE_XEN_GUEST_HANDLE(physdev_eoi_t);
45
46/*
47 * Register a shared page for the hypervisor to indicate whether the guest
48 * must issue PHYSDEVOP_eoi. The semantics of PHYSDEVOP_eoi change slightly
49 * once the guest used this function in that the associated event channel
50 * will automatically get unmasked. The page registered is used as a bit
51 * array indexed by Xen's PIRQ value.
52 */
53#define PHYSDEVOP_pirq_eoi_gmfn 17
54struct physdev_pirq_eoi_gmfn {
55 /* IN */
56 xen_pfn_t gmfn;
57};
58typedef struct physdev_pirq_eoi_gmfn physdev_pirq_eoi_gmfn_t;
59DEFINE_XEN_GUEST_HANDLE(physdev_pirq_eoi_gmfn_t);
60
61/*
62 * Query the status of an IRQ line.
63 * @arg == pointer to physdev_irq_status_query structure.
64 */
65#define PHYSDEVOP_irq_status_query 5
66struct physdev_irq_status_query {
67 /* IN */
68 uint32_t irq;
69 /* OUT */
70 uint32_t flags; /* XENIRQSTAT_* */
71};
72typedef struct physdev_irq_status_query physdev_irq_status_query_t;
73DEFINE_XEN_GUEST_HANDLE(physdev_irq_status_query_t);
74
75/* Need to call PHYSDEVOP_eoi when the IRQ has been serviced? */
76#define _XENIRQSTAT_needs_eoi (0)
77#define XENIRQSTAT_needs_eoi (1U<<_XENIRQSTAT_needs_eoi)
78
79/* IRQ shared by multiple guests? */
80#define _XENIRQSTAT_shared (1)
81#define XENIRQSTAT_shared (1U<<_XENIRQSTAT_shared)
82
83/*
84 * Set the current VCPU's I/O privilege level.
85 * @arg == pointer to physdev_set_iopl structure.
86 */
87#define PHYSDEVOP_set_iopl 6
88struct physdev_set_iopl {
89 /* IN */
90 uint32_t iopl;
91};
92typedef struct physdev_set_iopl physdev_set_iopl_t;
93DEFINE_XEN_GUEST_HANDLE(physdev_set_iopl_t);
94
95/*
96 * Set the current VCPU's I/O-port permissions bitmap.
97 * @arg == pointer to physdev_set_iobitmap structure.
98 */
99#define PHYSDEVOP_set_iobitmap 7
100struct physdev_set_iobitmap {
101 /* IN */
102#if __XEN_INTERFACE_VERSION__ >= 0x00030205
103 XEN_GUEST_HANDLE(uint8) bitmap;
104#else
105 uint8_t *bitmap;
106#endif
107 uint32_t nr_ports;
108};
109typedef struct physdev_set_iobitmap physdev_set_iobitmap_t;
110DEFINE_XEN_GUEST_HANDLE(physdev_set_iobitmap_t);
111
112/*
113 * Read or write an IO-APIC register.
114 * @arg == pointer to physdev_apic structure.
115 */
116#define PHYSDEVOP_apic_read 8
117#define PHYSDEVOP_apic_write 9
118struct physdev_apic {
119 /* IN */
120 unsigned long apic_physbase;
121 uint32_t reg;
122 /* IN or OUT */
123 uint32_t value;
124};
125typedef struct physdev_apic physdev_apic_t;
126DEFINE_XEN_GUEST_HANDLE(physdev_apic_t);
127
128/*
129 * Allocate or free a physical upcall vector for the specified IRQ line.
130 * @arg == pointer to physdev_irq structure.
131 */
132#define PHYSDEVOP_alloc_irq_vector 10
133#define PHYSDEVOP_free_irq_vector 11
134struct physdev_irq {
135 /* IN */
136 uint32_t irq;
137 /* IN or OUT */
138 uint32_t vector;
139};
140typedef struct physdev_irq physdev_irq_t;
141DEFINE_XEN_GUEST_HANDLE(physdev_irq_t);
142
143#define MAP_PIRQ_TYPE_MSI 0x0
144#define MAP_PIRQ_TYPE_GSI 0x1
145#define MAP_PIRQ_TYPE_UNKNOWN 0x2
146
147#define PHYSDEVOP_map_pirq 13
148struct physdev_map_pirq {
149 domid_t domid;
150 /* IN */
151 int type;
152 /* IN */
153 int index;
154 /* IN or OUT */
155 int pirq;
156 /* IN */
157 int bus;
158 /* IN */
159 int devfn;
160 /* IN */
161 int entry_nr;
162 /* IN */
163 uint64_t table_base;
164};
165typedef struct physdev_map_pirq physdev_map_pirq_t;
166DEFINE_XEN_GUEST_HANDLE(physdev_map_pirq_t);
167
168#define PHYSDEVOP_unmap_pirq 14
169struct physdev_unmap_pirq {
170 domid_t domid;
171 /* IN */
172 int pirq;
173};
174
175typedef struct physdev_unmap_pirq physdev_unmap_pirq_t;
176DEFINE_XEN_GUEST_HANDLE(physdev_unmap_pirq_t);
177
178#define PHYSDEVOP_manage_pci_add 15
179#define PHYSDEVOP_manage_pci_remove 16
180struct physdev_manage_pci {
181 /* IN */
182 uint8_t bus;
183 uint8_t devfn;
184};
185
186typedef struct physdev_manage_pci physdev_manage_pci_t;
187DEFINE_XEN_GUEST_HANDLE(physdev_manage_pci_t);
188
189#define PHYSDEVOP_restore_msi 19
190struct physdev_restore_msi {
191 /* IN */
192 uint8_t bus;
193 uint8_t devfn;
194};
195typedef struct physdev_restore_msi physdev_restore_msi_t;
196DEFINE_XEN_GUEST_HANDLE(physdev_restore_msi_t);
197
198#define PHYSDEVOP_manage_pci_add_ext 20
199struct physdev_manage_pci_ext {
200 /* IN */
201 uint8_t bus;
202 uint8_t devfn;
203 unsigned is_extfn;
204 unsigned is_virtfn;
205 struct {
206 uint8_t bus;
207 uint8_t devfn;
208 } physfn;
209};
210
211typedef struct physdev_manage_pci_ext physdev_manage_pci_ext_t;
212DEFINE_XEN_GUEST_HANDLE(physdev_manage_pci_ext_t);
213
214/*
215 * Argument to physdev_op_compat() hypercall. Superceded by new physdev_op()
216 * hypercall since 0x00030202.
217 */
218struct physdev_op {
219 uint32_t cmd;
220 union {
221 struct physdev_irq_status_query irq_status_query;
222 struct physdev_set_iopl set_iopl;
223 struct physdev_set_iobitmap set_iobitmap;
224 struct physdev_apic apic_op;
225 struct physdev_irq irq_op;
226 } u;
227};
228typedef struct physdev_op physdev_op_t;
229DEFINE_XEN_GUEST_HANDLE(physdev_op_t);
230
231#define PHYSDEVOP_setup_gsi 21
232struct physdev_setup_gsi {
233 int gsi;
234 /* IN */
235 uint8_t triggering;
236 /* IN */
237 uint8_t polarity;
238 /* IN */
239};
240
241typedef struct physdev_setup_gsi physdev_setup_gsi_t;
242DEFINE_XEN_GUEST_HANDLE(physdev_setup_gsi_t);
243
244/* leave PHYSDEVOP 22 free */
245
246/* type is MAP_PIRQ_TYPE_GSI or MAP_PIRQ_TYPE_MSI
247 * the hypercall returns a free pirq */
248#define PHYSDEVOP_get_free_pirq 23
249struct physdev_get_free_pirq {
250 /* IN */
251 int type;
252 /* OUT */
253 uint32_t pirq;
254};
255
256typedef struct physdev_get_free_pirq physdev_get_free_pirq_t;
257DEFINE_XEN_GUEST_HANDLE(physdev_get_free_pirq_t);
258
259/*
260 * Notify that some PIRQ-bound event channels have been unmasked.
261 * ** This command is obsolete since interface version 0x00030202 and is **
262 * ** unsupported by newer versions of Xen. **
263 */
264#define PHYSDEVOP_IRQ_UNMASK_NOTIFY 4
265
266/*
267 * These all-capitals physdev operation names are superceded by the new names
268 * (defined above) since interface version 0x00030202.
269 */
270#define PHYSDEVOP_IRQ_STATUS_QUERY PHYSDEVOP_irq_status_query
271#define PHYSDEVOP_SET_IOPL PHYSDEVOP_set_iopl
272#define PHYSDEVOP_SET_IOBITMAP PHYSDEVOP_set_iobitmap
273#define PHYSDEVOP_APIC_READ PHYSDEVOP_apic_read
274#define PHYSDEVOP_APIC_WRITE PHYSDEVOP_apic_write
275#define PHYSDEVOP_ASSIGN_VECTOR PHYSDEVOP_alloc_irq_vector
276#define PHYSDEVOP_FREE_VECTOR PHYSDEVOP_free_irq_vector
277#define PHYSDEVOP_IRQ_NEEDS_UNMASK_NOTIFY XENIRQSTAT_needs_eoi
278#define PHYSDEVOP_IRQ_SHARED XENIRQSTAT_shared
279
280#endif /* __XEN_PUBLIC_PHYSDEV_H__ */
281
282/*
283 * Local variables:
284 * mode: C
285 * c-set-style: "BSD"
286 * c-basic-offset: 4
287 * tab-width: 4
288 * indent-tabs-mode: nil
289 * End:
290 */
291