1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 1999-2018 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: MIT
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  * DEALINGS IN THE SOFTWARE.
22  */
23 
24 #ifndef _NV_HYPERVISOR_H_
25 #define _NV_HYPERVISOR_H_
26 
27 #include <nv-kernel-interface-api.h>
28 
29 // Enums for supported hypervisor types.
30 // New hypervisor type should be added before OS_HYPERVISOR_UNKNOWN
31 typedef enum _HYPERVISOR_TYPE
32 {
33     OS_HYPERVISOR_XEN = 0,
34     OS_HYPERVISOR_VMWARE,
35     OS_HYPERVISOR_HYPERV,
36     OS_HYPERVISOR_KVM,
37     OS_HYPERVISOR_UNKNOWN
38 } HYPERVISOR_TYPE;
39 
40 #define CMD_VGPU_VFIO_WAKE_WAIT_QUEUE         0
41 #define CMD_VGPU_VFIO_INJECT_INTERRUPT        1
42 #define CMD_VGPU_VFIO_REGISTER_MDEV           2
43 #define CMD_VGPU_VFIO_PRESENT                 3
44 
45 #define MAX_VF_COUNT_PER_GPU 64
46 
47 typedef enum _VGPU_TYPE_INFO
48 {
49     VGPU_TYPE_NAME = 0,
50     VGPU_TYPE_DESCRIPTION,
51     VGPU_TYPE_INSTANCES,
52 } VGPU_TYPE_INFO;
53 
54 typedef struct
55 {
56     void  *vgpuVfioRef;
57     void  *waitQueue;
58     void  *nv;
59     NvU32 *vgpuTypeIds;
60     NvU32  numVgpuTypes;
61     NvU32  domain;
62     NvU8   bus;
63     NvU8   slot;
64     NvU8   function;
65     NvBool is_virtfn;
66 } vgpu_vfio_info;
67 
68 typedef struct
69 {
70     NvU32       domain;
71     NvU8        bus;
72     NvU8        slot;
73     NvU8        function;
74     NvBool      isNvidiaAttached;
75     NvBool      isMdevAttached;
76 } vgpu_vf_pci_info;
77 
78 typedef enum VGPU_CMD_PROCESS_VF_INFO_E
79 {
80     NV_VGPU_SAVE_VF_INFO         = 0,
81     NV_VGPU_REMOVE_VF_PCI_INFO   = 1,
82     NV_VGPU_REMOVE_VF_MDEV_INFO  = 2,
83     NV_VGPU_GET_VF_INFO          = 3
84 } VGPU_CMD_PROCESS_VF_INFO;
85 
86 typedef enum VGPU_DEVICE_STATE_E
87 {
88     NV_VGPU_DEV_UNUSED = 0,
89     NV_VGPU_DEV_OPENED = 1,
90     NV_VGPU_DEV_IN_USE = 2
91 } VGPU_DEVICE_STATE;
92 
93 /*
94  * Function prototypes
95  */
96 
97 HYPERVISOR_TYPE NV_API_CALL nv_get_hypervisor_type(void);
98 
99 #endif // _NV_HYPERVISOR_H_
100