blob: 12bce63d7854bff887cba4bc08553b25f17f98f5 (
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
84
|
/*
* GSP Emulation Engine for Host-Side GSP Emulation
* Replaces guest-side GSP communication with host kernel emulation
*/
#ifndef _GSP_EMULATION_H_
#define _GSP_EMULATION_H_
#include <linux/types.h>
#include <linux/device.h>
#include <linux/mutex.h>
#include <linux/spinlock.h>
#include <linux/workqueue.h>
#include <linux/list.h>
#include <linux/kthread.h>
#include <linux/eventfd.h>
#include "nvidia-vgpu-vfio.h"
#include "gsp_rpc_client.h"
#include "bar_emulation.h"
#include "irq.h"
#include "memory.h"
/* ============================================================
* GSP Emulation Constants
* ============================================================ */
#define GSP_EMU_DOORBELL_OFFSET 0x110C00
#define GSP_EMU_SHARED_MEM_OFFSET 0x1000
#define GSP_EMU_SHARED_MEM_SIZE 4096
#define GSP_EMU_MSIX_TABLE_OFFSET 0x2000
#define GSP_EMU_MSIX_PBA_OFFSET 0x3000
#define GSP_EMU_POLL_BUSY_US 100
#define GSP_EMU_POLL_SLEEP_MIN_US 50
#define GSP_EMU_POLL_SLEEP_MAX_US 100
/* ============================================================
* GSP Emulation Context
* ============================================================ */
struct gsp_emu_context {
struct nv_vgpu_device *vgpu;
struct task_struct *thread;
struct completion thread_stopped;
void __iomem *bar0_vaddr;
void __iomem *doorbell_reg;
void __iomem *shared_mem;
struct gsp_client *rpc_client;
spinlock_t lock;
bool running;
bool initialized;
bool stopping;
/* Shared memory for RPC communication (4KB at BAR0+0x1000) */
void *shared_mem_virt;
dma_addr_t shared_mem_dma;
size_t shared_mem_size;
/* Statistics */
u64 processed_rpcs;
u64 failed_rpcs;
u64 total_latency_ns;
/* MSI-X injection */
struct eventfd_ctx *msix_trigger[NV_VGPU_MAX_IRQS];
};
/* ============================================================
* Public API
* ============================================================ */
int gsp_emu_init(struct nv_vgpu_device *vgpu);
void gsp_emu_cleanup(struct nv_vgpu_device *vgpu);
int gsp_emu_process_rpc(struct gsp_emu_context *ctx);
void gsp_emu_inject_completion_interrupt(struct gsp_emu_context *ctx, u32 seq_id);
/* ============================================================
* Debug/Statistics
* ============================================================ */
void gsp_emu_get_stats(struct gsp_emu_context *ctx,
u64 *processed, u64 *failed, u64 *total_latency_ns);
#endif /* _GSP_EMULATION_H_ */
|