Merge tag 'pci-v5.17-fixes-1' of git://git.kernel.org/pub/scm/linux/kernel/git/helgaa...
[platform/kernel/linux-rpi.git] / include / asm-generic / hyperv-tlfs.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2
3 /*
4  * This file contains definitions from Hyper-V Hypervisor Top-Level Functional
5  * Specification (TLFS):
6  * https://docs.microsoft.com/en-us/virtualization/hyper-v-on-windows/reference/tlfs
7  */
8
9 #ifndef _ASM_GENERIC_HYPERV_TLFS_H
10 #define _ASM_GENERIC_HYPERV_TLFS_H
11
12 #include <linux/types.h>
13 #include <linux/bits.h>
14 #include <linux/time64.h>
15
16 /*
17  * While not explicitly listed in the TLFS, Hyper-V always runs with a page size
18  * of 4096. These definitions are used when communicating with Hyper-V using
19  * guest physical pages and guest physical page addresses, since the guest page
20  * size may not be 4096 on all architectures.
21  */
22 #define HV_HYP_PAGE_SHIFT      12
23 #define HV_HYP_PAGE_SIZE       BIT(HV_HYP_PAGE_SHIFT)
24 #define HV_HYP_PAGE_MASK       (~(HV_HYP_PAGE_SIZE - 1))
25
26 /*
27  * Hyper-V provides two categories of flags relevant to guest VMs.  The
28  * "Features" category indicates specific functionality that is available
29  * to guests on this particular instance of Hyper-V. The "Features"
30  * are presented in four groups, each of which is 32 bits. The group A
31  * and B definitions are common across architectures and are listed here.
32  * However, not all flags are relevant on all architectures.
33  *
34  * Groups C and D vary across architectures and are listed in the
35  * architecture specific portion of hyperv-tlfs.h. Some of these flags exist
36  * on multiple architectures, but the bit positions are different so they
37  * cannot appear in the generic portion of hyperv-tlfs.h.
38  *
39  * The "Enlightenments" category provides recommendations on whether to use
40  * specific enlightenments that are available. The Enlighenments are a single
41  * group of 32 bits, but they vary across architectures and are listed in
42  * the architecture specific portion of hyperv-tlfs.h.
43  */
44
45 /*
46  * Group A Features.
47  */
48
49 /* VP Runtime register available */
50 #define HV_MSR_VP_RUNTIME_AVAILABLE             BIT(0)
51 /* Partition Reference Counter available*/
52 #define HV_MSR_TIME_REF_COUNT_AVAILABLE         BIT(1)
53 /* Basic SynIC register available */
54 #define HV_MSR_SYNIC_AVAILABLE                  BIT(2)
55 /* Synthetic Timer registers available */
56 #define HV_MSR_SYNTIMER_AVAILABLE               BIT(3)
57 /* Virtual APIC assist and VP assist page registers available */
58 #define HV_MSR_APIC_ACCESS_AVAILABLE            BIT(4)
59 /* Hypercall and Guest OS ID registers available*/
60 #define HV_MSR_HYPERCALL_AVAILABLE              BIT(5)
61 /* Access virtual processor index register available*/
62 #define HV_MSR_VP_INDEX_AVAILABLE               BIT(6)
63 /* Virtual system reset register available*/
64 #define HV_MSR_RESET_AVAILABLE                  BIT(7)
65 /* Access statistics page registers available */
66 #define HV_MSR_STAT_PAGES_AVAILABLE             BIT(8)
67 /* Partition reference TSC register is available */
68 #define HV_MSR_REFERENCE_TSC_AVAILABLE          BIT(9)
69 /* Partition Guest IDLE register is available */
70 #define HV_MSR_GUEST_IDLE_AVAILABLE             BIT(10)
71 /* Partition local APIC and TSC frequency registers available */
72 #define HV_ACCESS_FREQUENCY_MSRS                BIT(11)
73 /* AccessReenlightenmentControls privilege */
74 #define HV_ACCESS_REENLIGHTENMENT               BIT(13)
75 /* AccessTscInvariantControls privilege */
76 #define HV_ACCESS_TSC_INVARIANT                 BIT(15)
77
78 /*
79  * Group B features.
80  */
81 #define HV_CREATE_PARTITIONS                    BIT(0)
82 #define HV_ACCESS_PARTITION_ID                  BIT(1)
83 #define HV_ACCESS_MEMORY_POOL                   BIT(2)
84 #define HV_ADJUST_MESSAGE_BUFFERS               BIT(3)
85 #define HV_POST_MESSAGES                        BIT(4)
86 #define HV_SIGNAL_EVENTS                        BIT(5)
87 #define HV_CREATE_PORT                          BIT(6)
88 #define HV_CONNECT_PORT                         BIT(7)
89 #define HV_ACCESS_STATS                         BIT(8)
90 #define HV_DEBUGGING                            BIT(11)
91 #define HV_CPU_MANAGEMENT                       BIT(12)
92 #define HV_ENABLE_EXTENDED_HYPERCALLS           BIT(20)
93 #define HV_ISOLATION                            BIT(22)
94
95 /*
96  * TSC page layout.
97  */
98 struct ms_hyperv_tsc_page {
99         volatile u32 tsc_sequence;
100         u32 reserved1;
101         volatile u64 tsc_scale;
102         volatile s64 tsc_offset;
103 } __packed;
104
105 /*
106  * The guest OS needs to register the guest ID with the hypervisor.
107  * The guest ID is a 64 bit entity and the structure of this ID is
108  * specified in the Hyper-V specification:
109  *
110  * msdn.microsoft.com/en-us/library/windows/hardware/ff542653%28v=vs.85%29.aspx
111  *
112  * While the current guideline does not specify how Linux guest ID(s)
113  * need to be generated, our plan is to publish the guidelines for
114  * Linux and other guest operating systems that currently are hosted
115  * on Hyper-V. The implementation here conforms to this yet
116  * unpublished guidelines.
117  *
118  *
119  * Bit(s)
120  * 63 - Indicates if the OS is Open Source or not; 1 is Open Source
121  * 62:56 - Os Type; Linux is 0x100
122  * 55:48 - Distro specific identification
123  * 47:16 - Linux kernel version number
124  * 15:0  - Distro specific identification
125  *
126  *
127  */
128
129 #define HV_LINUX_VENDOR_ID              0x8100
130
131 /*
132  * Crash notification flags.
133  */
134 #define HV_CRASH_CTL_CRASH_NOTIFY_MSG           BIT_ULL(62)
135 #define HV_CRASH_CTL_CRASH_NOTIFY               BIT_ULL(63)
136
137 /* Declare the various hypercall operations. */
138 #define HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE      0x0002
139 #define HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST       0x0003
140 #define HVCALL_NOTIFY_LONG_SPIN_WAIT            0x0008
141 #define HVCALL_SEND_IPI                         0x000b
142 #define HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE_EX   0x0013
143 #define HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST_EX    0x0014
144 #define HVCALL_SEND_IPI_EX                      0x0015
145 #define HVCALL_GET_PARTITION_ID                 0x0046
146 #define HVCALL_DEPOSIT_MEMORY                   0x0048
147 #define HVCALL_CREATE_VP                        0x004e
148 #define HVCALL_GET_VP_REGISTERS                 0x0050
149 #define HVCALL_SET_VP_REGISTERS                 0x0051
150 #define HVCALL_POST_MESSAGE                     0x005c
151 #define HVCALL_SIGNAL_EVENT                     0x005d
152 #define HVCALL_POST_DEBUG_DATA                  0x0069
153 #define HVCALL_RETRIEVE_DEBUG_DATA              0x006a
154 #define HVCALL_RESET_DEBUG_SESSION              0x006b
155 #define HVCALL_ADD_LOGICAL_PROCESSOR            0x0076
156 #define HVCALL_MAP_DEVICE_INTERRUPT             0x007c
157 #define HVCALL_UNMAP_DEVICE_INTERRUPT           0x007d
158 #define HVCALL_RETARGET_INTERRUPT               0x007e
159 #define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_SPACE 0x00af
160 #define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_LIST 0x00b0
161 #define HVCALL_MODIFY_SPARSE_GPA_PAGE_HOST_VISIBILITY 0x00db
162
163 /* Extended hypercalls */
164 #define HV_EXT_CALL_QUERY_CAPABILITIES          0x8001
165 #define HV_EXT_CALL_MEMORY_HEAT_HINT            0x8003
166
167 #define HV_FLUSH_ALL_PROCESSORS                 BIT(0)
168 #define HV_FLUSH_ALL_VIRTUAL_ADDRESS_SPACES     BIT(1)
169 #define HV_FLUSH_NON_GLOBAL_MAPPINGS_ONLY       BIT(2)
170 #define HV_FLUSH_USE_EXTENDED_RANGE_FORMAT      BIT(3)
171
172 /* Extended capability bits */
173 #define HV_EXT_CAPABILITY_MEMORY_COLD_DISCARD_HINT BIT(8)
174
175 enum HV_GENERIC_SET_FORMAT {
176         HV_GENERIC_SET_SPARSE_4K,
177         HV_GENERIC_SET_ALL,
178 };
179
180 #define HV_PARTITION_ID_SELF            ((u64)-1)
181 #define HV_VP_INDEX_SELF                ((u32)-2)
182
183 #define HV_HYPERCALL_RESULT_MASK        GENMASK_ULL(15, 0)
184 #define HV_HYPERCALL_FAST_BIT           BIT(16)
185 #define HV_HYPERCALL_VARHEAD_OFFSET     17
186 #define HV_HYPERCALL_REP_COMP_OFFSET    32
187 #define HV_HYPERCALL_REP_COMP_1         BIT_ULL(32)
188 #define HV_HYPERCALL_REP_COMP_MASK      GENMASK_ULL(43, 32)
189 #define HV_HYPERCALL_REP_START_OFFSET   48
190 #define HV_HYPERCALL_REP_START_MASK     GENMASK_ULL(59, 48)
191
192 /* hypercall status code */
193 #define HV_STATUS_SUCCESS                       0
194 #define HV_STATUS_INVALID_HYPERCALL_CODE        2
195 #define HV_STATUS_INVALID_HYPERCALL_INPUT       3
196 #define HV_STATUS_INVALID_ALIGNMENT             4
197 #define HV_STATUS_INVALID_PARAMETER             5
198 #define HV_STATUS_ACCESS_DENIED                 6
199 #define HV_STATUS_OPERATION_DENIED              8
200 #define HV_STATUS_INSUFFICIENT_MEMORY           11
201 #define HV_STATUS_INVALID_PORT_ID               17
202 #define HV_STATUS_INVALID_CONNECTION_ID         18
203 #define HV_STATUS_INSUFFICIENT_BUFFERS          19
204
205 /*
206  * The Hyper-V TimeRefCount register and the TSC
207  * page provide a guest VM clock with 100ns tick rate
208  */
209 #define HV_CLOCK_HZ (NSEC_PER_SEC/100)
210
211 /* Define the number of synthetic interrupt sources. */
212 #define HV_SYNIC_SINT_COUNT             (16)
213 /* Define the expected SynIC version. */
214 #define HV_SYNIC_VERSION_1              (0x1)
215 /* Valid SynIC vectors are 16-255. */
216 #define HV_SYNIC_FIRST_VALID_VECTOR     (16)
217
218 #define HV_SYNIC_CONTROL_ENABLE         (1ULL << 0)
219 #define HV_SYNIC_SIMP_ENABLE            (1ULL << 0)
220 #define HV_SYNIC_SIEFP_ENABLE           (1ULL << 0)
221 #define HV_SYNIC_SINT_MASKED            (1ULL << 16)
222 #define HV_SYNIC_SINT_AUTO_EOI          (1ULL << 17)
223 #define HV_SYNIC_SINT_VECTOR_MASK       (0xFF)
224
225 #define HV_SYNIC_STIMER_COUNT           (4)
226
227 /* Define synthetic interrupt controller message constants. */
228 #define HV_MESSAGE_SIZE                 (256)
229 #define HV_MESSAGE_PAYLOAD_BYTE_COUNT   (240)
230 #define HV_MESSAGE_PAYLOAD_QWORD_COUNT  (30)
231
232 /*
233  * Define hypervisor message types. Some of the message types
234  * are x86/x64 specific, but there's no good way to separate
235  * them out into the arch-specific version of hyperv-tlfs.h
236  * because C doesn't provide a way to extend enum types.
237  * Keeping them all in the arch neutral hyperv-tlfs.h seems
238  * the least messy compromise.
239  */
240 enum hv_message_type {
241         HVMSG_NONE                      = 0x00000000,
242
243         /* Memory access messages. */
244         HVMSG_UNMAPPED_GPA              = 0x80000000,
245         HVMSG_GPA_INTERCEPT             = 0x80000001,
246
247         /* Timer notification messages. */
248         HVMSG_TIMER_EXPIRED             = 0x80000010,
249
250         /* Error messages. */
251         HVMSG_INVALID_VP_REGISTER_VALUE = 0x80000020,
252         HVMSG_UNRECOVERABLE_EXCEPTION   = 0x80000021,
253         HVMSG_UNSUPPORTED_FEATURE       = 0x80000022,
254
255         /* Trace buffer complete messages. */
256         HVMSG_EVENTLOG_BUFFERCOMPLETE   = 0x80000040,
257
258         /* Platform-specific processor intercept messages. */
259         HVMSG_X64_IOPORT_INTERCEPT      = 0x80010000,
260         HVMSG_X64_MSR_INTERCEPT         = 0x80010001,
261         HVMSG_X64_CPUID_INTERCEPT       = 0x80010002,
262         HVMSG_X64_EXCEPTION_INTERCEPT   = 0x80010003,
263         HVMSG_X64_APIC_EOI              = 0x80010004,
264         HVMSG_X64_LEGACY_FP_ERROR       = 0x80010005
265 };
266
267 /* Define synthetic interrupt controller message flags. */
268 union hv_message_flags {
269         __u8 asu8;
270         struct {
271                 __u8 msg_pending:1;
272                 __u8 reserved:7;
273         } __packed;
274 };
275
276 /* Define port identifier type. */
277 union hv_port_id {
278         __u32 asu32;
279         struct {
280                 __u32 id:24;
281                 __u32 reserved:8;
282         } __packed u;
283 };
284
285 /* Define synthetic interrupt controller message header. */
286 struct hv_message_header {
287         __u32 message_type;
288         __u8 payload_size;
289         union hv_message_flags message_flags;
290         __u8 reserved[2];
291         union {
292                 __u64 sender;
293                 union hv_port_id port;
294         };
295 } __packed;
296
297 /* Define synthetic interrupt controller message format. */
298 struct hv_message {
299         struct hv_message_header header;
300         union {
301                 __u64 payload[HV_MESSAGE_PAYLOAD_QWORD_COUNT];
302         } u;
303 } __packed;
304
305 /* Define the synthetic interrupt message page layout. */
306 struct hv_message_page {
307         struct hv_message sint_message[HV_SYNIC_SINT_COUNT];
308 } __packed;
309
310 /* Define timer message payload structure. */
311 struct hv_timer_message_payload {
312         __u32 timer_index;
313         __u32 reserved;
314         __u64 expiration_time;  /* When the timer expired */
315         __u64 delivery_time;    /* When the message was delivered */
316 } __packed;
317
318
319 /* Define synthetic interrupt controller flag constants. */
320 #define HV_EVENT_FLAGS_COUNT            (256 * 8)
321 #define HV_EVENT_FLAGS_LONG_COUNT       (256 / sizeof(unsigned long))
322
323 /*
324  * Synthetic timer configuration.
325  */
326 union hv_stimer_config {
327         u64 as_uint64;
328         struct {
329                 u64 enable:1;
330                 u64 periodic:1;
331                 u64 lazy:1;
332                 u64 auto_enable:1;
333                 u64 apic_vector:8;
334                 u64 direct_mode:1;
335                 u64 reserved_z0:3;
336                 u64 sintx:4;
337                 u64 reserved_z1:44;
338         } __packed;
339 };
340
341
342 /* Define the synthetic interrupt controller event flags format. */
343 union hv_synic_event_flags {
344         unsigned long flags[HV_EVENT_FLAGS_LONG_COUNT];
345 };
346
347 /* Define SynIC control register. */
348 union hv_synic_scontrol {
349         u64 as_uint64;
350         struct {
351                 u64 enable:1;
352                 u64 reserved:63;
353         } __packed;
354 };
355
356 /* Define synthetic interrupt source. */
357 union hv_synic_sint {
358         u64 as_uint64;
359         struct {
360                 u64 vector:8;
361                 u64 reserved1:8;
362                 u64 masked:1;
363                 u64 auto_eoi:1;
364                 u64 polling:1;
365                 u64 reserved2:45;
366         } __packed;
367 };
368
369 /* Define the format of the SIMP register */
370 union hv_synic_simp {
371         u64 as_uint64;
372         struct {
373                 u64 simp_enabled:1;
374                 u64 preserved:11;
375                 u64 base_simp_gpa:52;
376         } __packed;
377 };
378
379 /* Define the format of the SIEFP register */
380 union hv_synic_siefp {
381         u64 as_uint64;
382         struct {
383                 u64 siefp_enabled:1;
384                 u64 preserved:11;
385                 u64 base_siefp_gpa:52;
386         } __packed;
387 };
388
389 struct hv_vpset {
390         u64 format;
391         u64 valid_bank_mask;
392         u64 bank_contents[];
393 } __packed;
394
395 /* HvCallSendSyntheticClusterIpi hypercall */
396 struct hv_send_ipi {
397         u32 vector;
398         u32 reserved;
399         u64 cpu_mask;
400 } __packed;
401
402 /* HvCallSendSyntheticClusterIpiEx hypercall */
403 struct hv_send_ipi_ex {
404         u32 vector;
405         u32 reserved;
406         struct hv_vpset vp_set;
407 } __packed;
408
409 /* HvFlushGuestPhysicalAddressSpace hypercalls */
410 struct hv_guest_mapping_flush {
411         u64 address_space;
412         u64 flags;
413 } __packed;
414
415 /*
416  *  HV_MAX_FLUSH_PAGES = "additional_pages" + 1. It's limited
417  *  by the bitwidth of "additional_pages" in union hv_gpa_page_range.
418  */
419 #define HV_MAX_FLUSH_PAGES (2048)
420 #define HV_GPA_PAGE_RANGE_PAGE_SIZE_2MB         0
421 #define HV_GPA_PAGE_RANGE_PAGE_SIZE_1GB         1
422
423 /* HvFlushGuestPhysicalAddressList, HvExtCallMemoryHeatHint hypercall */
424 union hv_gpa_page_range {
425         u64 address_space;
426         struct {
427                 u64 additional_pages:11;
428                 u64 largepage:1;
429                 u64 basepfn:52;
430         } page;
431         struct {
432                 u64 reserved:12;
433                 u64 page_size:1;
434                 u64 reserved1:8;
435                 u64 base_large_pfn:43;
436         };
437 };
438
439 /*
440  * All input flush parameters should be in single page. The max flush
441  * count is equal with how many entries of union hv_gpa_page_range can
442  * be populated into the input parameter page.
443  */
444 #define HV_MAX_FLUSH_REP_COUNT ((HV_HYP_PAGE_SIZE - 2 * sizeof(u64)) /  \
445                                 sizeof(union hv_gpa_page_range))
446
447 struct hv_guest_mapping_flush_list {
448         u64 address_space;
449         u64 flags;
450         union hv_gpa_page_range gpa_list[HV_MAX_FLUSH_REP_COUNT];
451 };
452
453 /* HvFlushVirtualAddressSpace, HvFlushVirtualAddressList hypercalls */
454 struct hv_tlb_flush {
455         u64 address_space;
456         u64 flags;
457         u64 processor_mask;
458         u64 gva_list[];
459 } __packed;
460
461 /* HvFlushVirtualAddressSpaceEx, HvFlushVirtualAddressListEx hypercalls */
462 struct hv_tlb_flush_ex {
463         u64 address_space;
464         u64 flags;
465         struct hv_vpset hv_vp_set;
466         u64 gva_list[];
467 } __packed;
468
469 /* HvGetPartitionId hypercall (output only) */
470 struct hv_get_partition_id {
471         u64 partition_id;
472 } __packed;
473
474 /* HvDepositMemory hypercall */
475 struct hv_deposit_memory {
476         u64 partition_id;
477         u64 gpa_page_list[];
478 } __packed;
479
480 struct hv_proximity_domain_flags {
481         u32 proximity_preferred : 1;
482         u32 reserved : 30;
483         u32 proximity_info_valid : 1;
484 } __packed;
485
486 /* Not a union in windows but useful for zeroing */
487 union hv_proximity_domain_info {
488         struct {
489                 u32 domain_id;
490                 struct hv_proximity_domain_flags flags;
491         };
492         u64 as_uint64;
493 } __packed;
494
495 struct hv_lp_startup_status {
496         u64 hv_status;
497         u64 substatus1;
498         u64 substatus2;
499         u64 substatus3;
500         u64 substatus4;
501         u64 substatus5;
502         u64 substatus6;
503 } __packed;
504
505 /* HvAddLogicalProcessor hypercall */
506 struct hv_add_logical_processor_in {
507         u32 lp_index;
508         u32 apic_id;
509         union hv_proximity_domain_info proximity_domain_info;
510         u64 flags;
511 } __packed;
512
513 struct hv_add_logical_processor_out {
514         struct hv_lp_startup_status startup_status;
515 } __packed;
516
517 enum HV_SUBNODE_TYPE
518 {
519     HvSubnodeAny = 0,
520     HvSubnodeSocket = 1,
521     HvSubnodeAmdNode = 2,
522     HvSubnodeL3 = 3,
523     HvSubnodeCount = 4,
524     HvSubnodeInvalid = -1
525 };
526
527 /* HvCreateVp hypercall */
528 struct hv_create_vp {
529         u64 partition_id;
530         u32 vp_index;
531         u8 padding[3];
532         u8 subnode_type;
533         u64 subnode_id;
534         union hv_proximity_domain_info proximity_domain_info;
535         u64 flags;
536 } __packed;
537
538 enum hv_interrupt_source {
539         HV_INTERRUPT_SOURCE_MSI = 1, /* MSI and MSI-X */
540         HV_INTERRUPT_SOURCE_IOAPIC,
541 };
542
543 union hv_ioapic_rte {
544         u64 as_uint64;
545
546         struct {
547                 u32 vector:8;
548                 u32 delivery_mode:3;
549                 u32 destination_mode:1;
550                 u32 delivery_status:1;
551                 u32 interrupt_polarity:1;
552                 u32 remote_irr:1;
553                 u32 trigger_mode:1;
554                 u32 interrupt_mask:1;
555                 u32 reserved1:15;
556
557                 u32 reserved2:24;
558                 u32 destination_id:8;
559         };
560
561         struct {
562                 u32 low_uint32;
563                 u32 high_uint32;
564         };
565 } __packed;
566
567 struct hv_interrupt_entry {
568         u32 source;
569         u32 reserved1;
570         union {
571                 union hv_msi_entry msi_entry;
572                 union hv_ioapic_rte ioapic_rte;
573         };
574 } __packed;
575
576 /*
577  * flags for hv_device_interrupt_target.flags
578  */
579 #define HV_DEVICE_INTERRUPT_TARGET_MULTICAST            1
580 #define HV_DEVICE_INTERRUPT_TARGET_PROCESSOR_SET        2
581
582 struct hv_device_interrupt_target {
583         u32 vector;
584         u32 flags;
585         union {
586                 u64 vp_mask;
587                 struct hv_vpset vp_set;
588         };
589 } __packed;
590
591 struct hv_retarget_device_interrupt {
592         u64 partition_id;               /* use "self" */
593         u64 device_id;
594         struct hv_interrupt_entry int_entry;
595         u64 reserved2;
596         struct hv_device_interrupt_target int_target;
597 } __packed __aligned(8);
598
599
600 /* HvGetVpRegisters hypercall input with variable size reg name list*/
601 struct hv_get_vp_registers_input {
602         struct {
603                 u64 partitionid;
604                 u32 vpindex;
605                 u8  inputvtl;
606                 u8  padding[3];
607         } header;
608         struct input {
609                 u32 name0;
610                 u32 name1;
611         } element[];
612 } __packed;
613
614
615 /* HvGetVpRegisters returns an array of these output elements */
616 struct hv_get_vp_registers_output {
617         union {
618                 struct {
619                         u32 a;
620                         u32 b;
621                         u32 c;
622                         u32 d;
623                 } as32 __packed;
624                 struct {
625                         u64 low;
626                         u64 high;
627                 } as64 __packed;
628         };
629 };
630
631 /* HvSetVpRegisters hypercall with variable size reg name/value list*/
632 struct hv_set_vp_registers_input {
633         struct {
634                 u64 partitionid;
635                 u32 vpindex;
636                 u8  inputvtl;
637                 u8  padding[3];
638         } header;
639         struct {
640                 u32 name;
641                 u32 padding1;
642                 u64 padding2;
643                 u64 valuelow;
644                 u64 valuehigh;
645         } element[];
646 } __packed;
647
648 enum hv_device_type {
649         HV_DEVICE_TYPE_LOGICAL = 0,
650         HV_DEVICE_TYPE_PCI = 1,
651         HV_DEVICE_TYPE_IOAPIC = 2,
652         HV_DEVICE_TYPE_ACPI = 3,
653 };
654
655 typedef u16 hv_pci_rid;
656 typedef u16 hv_pci_segment;
657 typedef u64 hv_logical_device_id;
658 union hv_pci_bdf {
659         u16 as_uint16;
660
661         struct {
662                 u8 function:3;
663                 u8 device:5;
664                 u8 bus;
665         };
666 } __packed;
667
668 union hv_pci_bus_range {
669         u16 as_uint16;
670
671         struct {
672                 u8 subordinate_bus;
673                 u8 secondary_bus;
674         };
675 } __packed;
676
677 union hv_device_id {
678         u64 as_uint64;
679
680         struct {
681                 u64 reserved0:62;
682                 u64 device_type:2;
683         };
684
685         /* HV_DEVICE_TYPE_LOGICAL */
686         struct {
687                 u64 id:62;
688                 u64 device_type:2;
689         } logical;
690
691         /* HV_DEVICE_TYPE_PCI */
692         struct {
693                 union {
694                         hv_pci_rid rid;
695                         union hv_pci_bdf bdf;
696                 };
697
698                 hv_pci_segment segment;
699                 union hv_pci_bus_range shadow_bus_range;
700
701                 u16 phantom_function_bits:2;
702                 u16 source_shadow:1;
703
704                 u16 rsvdz0:11;
705                 u16 device_type:2;
706         } pci;
707
708         /* HV_DEVICE_TYPE_IOAPIC */
709         struct {
710                 u8 ioapic_id;
711                 u8 rsvdz0;
712                 u16 rsvdz1;
713                 u16 rsvdz2;
714
715                 u16 rsvdz3:14;
716                 u16 device_type:2;
717         } ioapic;
718
719         /* HV_DEVICE_TYPE_ACPI */
720         struct {
721                 u32 input_mapping_base;
722                 u32 input_mapping_count:30;
723                 u32 device_type:2;
724         } acpi;
725 } __packed;
726
727 enum hv_interrupt_trigger_mode {
728         HV_INTERRUPT_TRIGGER_MODE_EDGE = 0,
729         HV_INTERRUPT_TRIGGER_MODE_LEVEL = 1,
730 };
731
732 struct hv_device_interrupt_descriptor {
733         u32 interrupt_type;
734         u32 trigger_mode;
735         u32 vector_count;
736         u32 reserved;
737         struct hv_device_interrupt_target target;
738 } __packed;
739
740 struct hv_input_map_device_interrupt {
741         u64 partition_id;
742         u64 device_id;
743         u64 flags;
744         struct hv_interrupt_entry logical_interrupt_entry;
745         struct hv_device_interrupt_descriptor interrupt_descriptor;
746 } __packed;
747
748 struct hv_output_map_device_interrupt {
749         struct hv_interrupt_entry interrupt_entry;
750 } __packed;
751
752 struct hv_input_unmap_device_interrupt {
753         u64 partition_id;
754         u64 device_id;
755         struct hv_interrupt_entry interrupt_entry;
756 } __packed;
757
758 #define HV_SOURCE_SHADOW_NONE               0x0
759 #define HV_SOURCE_SHADOW_BRIDGE_BUS_RANGE   0x1
760
761 /*
762  * The whole argument should fit in a page to be able to pass to the hypervisor
763  * in one hypercall.
764  */
765 #define HV_MEMORY_HINT_MAX_GPA_PAGE_RANGES  \
766         ((HV_HYP_PAGE_SIZE - sizeof(struct hv_memory_hint)) / \
767                 sizeof(union hv_gpa_page_range))
768
769 /* HvExtCallMemoryHeatHint hypercall */
770 #define HV_EXT_MEMORY_HEAT_HINT_TYPE_COLD_DISCARD       2
771 struct hv_memory_hint {
772         u64 type:2;
773         u64 reserved:62;
774         union hv_gpa_page_range ranges[];
775 } __packed;
776
777 #endif