summaryrefslogtreecommitdiffstats
path: root/kernel/include/nv-vgpu-vfio-interface.h
blob: 25537223816e2e97d903d6c7398d2ec12289ec21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* SPDX-FileCopyrightText: Copyright (c) 2016-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
 * SPDX-License-Identifier: MIT
 */

#ifndef _NV_VGPU_VFIO_INTERFACE_H_
#define _NV_VGPU_VFIO_INTERFACE_H_

#include <linux/pci.h>
#include <linux/device.h>
#include <linux/mdev.h>
#include <linux/vfio.h>

/* Use standard kernel types */
typedef int NV_STATUS;
typedef unsigned char NvU8;
typedef unsigned int NvU32;
typedef unsigned short NvU16;
typedef unsigned long long NvU64;
typedef int NvS32;
typedef unsigned char NvBool;

#define NV_OK 0
#define NV_ERR_NOT_SUPPORTED -1
#define NV_ERR_GENERIC -2
#define NV_ERR_INVALID_ARGUMENT -3
#define NV_ERR_NO_MEMORY -4

typedef enum {
    VGPU_DEVICE_STATE_UNINITIALIZED = 0,
    VGPU_DEVICE_STATE_INITIALIZING,
    VGPU_DEVICE_STATE_READY,
    VGPU_DEVICE_STATE_RUNNING,
    VGPU_DEVICE_STATE_SUSPENDED,
    VGPU_DEVICE_STATE_ERROR,
    VGPU_DEVICE_STATE_MIGRATING,
} VGPU_DEVICE_STATE;

typedef NV_STATUS (*vgpu_vfio_probe_t)(struct pci_dev *, NvU32, NvU32 *);
typedef void (*vgpu_vfio_remove_t)(struct pci_dev *);
typedef NV_STATUS (*vgpu_vfio_inject_interrupt_t)(void *);

typedef struct
{
    vgpu_vfio_probe_t probe;
    vgpu_vfio_remove_t  remove;
    vgpu_vfio_inject_interrupt_t inject_interrupt;
} vgpu_vfio_ops_t;

typedef NV_STATUS (*vgpu_vfio_vgpu_create_t) (struct pci_dev *dev, const NvU8 *uuid,
                                              NvU32 vgpu_type_id, NvU16 *vgpu_id,
                                              NvU32 *gpu_pci_id, NvU32 gpu_pci_bdf);
typedef NV_STATUS (*vgpu_vfio_vgpu_destroy_t) (const NvU8 *uuid, NvU16 vgpu_id);
typedef NV_STATUS (*vgpu_vfio_start_t) (const NvU8 *uuid, void *wait_queue, NvS32 *return_status,
                                        NvU8 *vm_name, NvU32 qemu_pid);
typedef NV_STATUS (*vgpu_vfio_bar_info_t) (struct pci_dev *dev, const NvU8 *, NvU64 *,
                                           NvU32 bar_index, void *);
typedef NV_STATUS (*vgpu_vfio_get_description) (struct pci_dev *, NvU32, char *);
typedef NV_STATUS (*vgpu_vfio_get_name) (struct pci_dev *, NvU32, char *);
typedef NV_STATUS (*vgpu_vfio_get_instance) (struct pci_dev *, NvU32, char *);
typedef NV_STATUS (*vgpu_vfio_sparse_mmap_t) (struct pci_dev *, const NvU8 *, NvU64 **, NvU64 **, NvU32 *);
typedef void (*vgpu_vfio_update_request_t) (const NvU8 *, NvU64 *, NvU64 *, VGPU_DEVICE_STATE, const char *);

typedef struct
{
    const char *version_string;
    vgpu_vfio_vgpu_create_t vgpu_create;
    vgpu_vfio_vgpu_destroy_t vgpu_delete;
    vgpu_vfio_bar_info_t vgpu_bar_info;
    vgpu_vfio_start_t vgpu_start;
    vgpu_vfio_get_description get_description;
    vgpu_vfio_get_instance get_instances;
    vgpu_vfio_get_name get_name;
    vgpu_vfio_sparse_mmap_t get_sparse_mmap;
    vgpu_vfio_update_request_t update_request;
} rm_vgpu_vfio_ops_t;

extern NV_STATUS nvidia_vgpu_vfio_set_ops(vgpu_vfio_ops_t *vgpu_vfio_ops);
extern NV_STATUS nvidia_vgpu_vfio_get_ops(rm_vgpu_vfio_ops_t *ops);

extern NV_STATUS nvidia_vgpu_vfio_probe(struct pci_dev *);
extern void nvidia_vgpu_vfio_remove(struct pci_dev *, NvBool);

#endif /* _NV_VGPU_VFIO_INTERFACE_H_ */