Repository navigation
Expand file tree
/
Copy pathnv2a_state.h
More file actions
250 lines (204 loc) · 6.8 KB
/
Copy pathnv2a_state.h
File metadata and controls
250 lines (204 loc) · 6.8 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
/*
* NV2A GPU State - Standalone adaptation of xemu's nv2a_int.h
*
* Based on xemu (Copyright (c) 2012 espes, 2015 Jannik Vogel,
* 2018-2025 Matt Borgerson) - LGPL v2+
*
* PGRAPHState holds register, subchannel, and image-blit state.
* Host render resources are managed by nv2a_pgraph_d3d11.c.
*/
#ifndef BURNOUT3_NV2A_STATE_H
#define BURNOUT3_NV2A_STATE_H
#include "qemu_shim.h"
#include "nv2a_regs.h"
/* Debug macros from xemu's debug.h */
#ifndef DEBUG_NV2A
# define DEBUG_NV2A 0
#endif
#if DEBUG_NV2A
# define NV2A_DPRINTF(format, ...) fprintf(stderr, "nv2a: " format, ## __VA_ARGS__)
#else
# define NV2A_DPRINTF(format, ...) do { } while (0)
#endif
#define NV2A_XPRINTF(x, ...) do { \
if (x) { fprintf(stderr, "nv2a: " __VA_ARGS__); } \
} while (0)
#define NV2A_UNCONFIRMED(...) do {} while (0)
#define NV2A_UNIMPLEMENTED(...) do {} while (0)
/* NV2A_DEVICE: cast to NV2AState* */
#define NV2A_DEVICE(obj) ((NV2AState*)(obj))
/* ============================================================
* FIFO Engine types
* ============================================================ */
enum FIFOEngine {
ENGINE_SOFTWARE = 0,
ENGINE_GRAPHICS = 1,
ENGINE_DVD = 2,
};
typedef struct DMAObject {
unsigned int dma_class;
unsigned int dma_target;
hwaddr address;
hwaddr limit;
} DMAObject;
/* ============================================================
* PGRAPH register and method state
* ============================================================ */
struct PGRAPHState {
uint32_t pending_interrupts;
uint32_t enabled_interrupts;
uint32_t regs[0x2000];
uint8_t subchannel_class[8];
uint32_t dma_semaphore;
uint32_t subchannel_object[8];
uint32_t subchannel_context[8][32];
uint32_t context_surfaces_2d_object;
uint32_t context_surfaces_2d_color_format;
uint32_t context_surfaces_2d_source_pitch;
uint32_t context_surfaces_2d_dest_pitch;
uint32_t context_surfaces_2d_source_offset;
uint32_t context_surfaces_2d_dest_offset;
uint32_t image_blit_point_in;
uint32_t image_blit_point_out;
uint32_t image_blit_size;
uint32_t context_surfaces_2d_dma_source;
uint32_t context_surfaces_2d_dma_dest;
uint32_t image_blit_context_surfaces;
uint32_t image_blit_operation;
};
/* ============================================================
* NV2AState - Main GPU state
* Adapted from xemu's nv2a_int.h
* ============================================================ */
typedef struct NV2AState {
/*< private >*/
PCIDevice parent_obj;
/*< public >*/
qemu_irq irq;
bool exiting;
VGACommonState vga;
GraphicHwOps hw_ops;
QEMUTimer *vblank_timer;
MemoryRegion *vram;
MemoryRegion vram_pci;
uint8_t *vram_ptr;
MemoryRegion ramin;
uint8_t *ramin_ptr;
MemoryRegion mmio;
MemoryRegion block_mmio[NV_NUM_BLOCKS];
struct {
uint32_t pending_interrupts;
uint32_t enabled_interrupts;
} pmc;
struct {
uint32_t pending_interrupts;
uint32_t enabled_interrupts;
uint32_t regs[0x2000];
QemuMutex lock;
QemuThread thread;
QemuCond fifo_cond;
QemuCond fifo_idle_cond;
bool fifo_kick;
bool halt;
} pfifo;
struct {
uint32_t regs[0x1000];
} pvideo;
struct {
uint32_t pending_interrupts;
uint32_t enabled_interrupts;
uint32_t numerator;
uint32_t denominator;
uint32_t alarm_time;
} ptimer;
struct {
uint32_t regs[0x1000];
} pfb;
struct PGRAPHState pgraph;
struct {
uint32_t pending_interrupts;
uint32_t enabled_interrupts;
hwaddr start;
uint32_t raster;
} pcrtc;
struct {
uint32_t core_clock_coeff;
uint64_t core_clock_freq;
uint32_t memory_clock_coeff;
uint32_t video_clock_coeff;
uint32_t general_control;
uint32_t fp_vdisplay_end;
uint32_t fp_vcrtc;
uint32_t fp_vsync_end;
uint32_t fp_vvalid_end;
uint32_t fp_hdisplay_end;
uint32_t fp_hcrtc;
uint32_t fp_hvalid_end;
} pramdac;
struct {
uint16_t write_mode_address;
uint8_t palette[256*3];
} puserdac;
} NV2AState;
/* ============================================================
* NV2ABlockInfo - block dispatch table entry
* ============================================================ */
typedef struct NV2ABlockInfo {
const char *name;
hwaddr offset;
uint64_t size;
MemoryRegionOps ops;
} NV2ABlockInfo;
extern const NV2ABlockInfo blocktable[NV_NUM_BLOCKS];
/* ============================================================
* Function prototypes
* ============================================================ */
void nv2a_update_irq(NV2AState *d);
/* Register block log helpers (no-op stubs since trace is disabled) */
static inline
void nv2a_reg_log_read(int block, hwaddr addr, unsigned int size, uint64_t val)
{
(void)block; (void)addr; (void)size; (void)val;
}
static inline
void nv2a_reg_log_write(int block, hwaddr addr, unsigned int size, uint64_t val)
{
(void)block; (void)addr; (void)size; (void)val;
}
/* Register block read/write prototypes */
#define DEFINE_PROTO(n) \
uint64_t n##_read(void *opaque, hwaddr addr, unsigned int size); \
void n##_write(void *opaque, hwaddr addr, uint64_t val, unsigned int size);
DEFINE_PROTO(pmc)
DEFINE_PROTO(pbus)
DEFINE_PROTO(pfifo)
DEFINE_PROTO(pvideo)
DEFINE_PROTO(ptimer)
DEFINE_PROTO(pfb)
DEFINE_PROTO(pgraph)
DEFINE_PROTO(pcrtc)
DEFINE_PROTO(pramdac)
#undef DEFINE_PROTO
/* Stub read/write for blocks we haven't implemented yet */
uint64_t nv2a_stub_read(void *opaque, hwaddr addr, unsigned int size);
void nv2a_stub_write(void *opaque, hwaddr addr, uint64_t val, unsigned int size);
/* DMA helpers */
DMAObject nv_dma_load(NV2AState *d, hwaddr dma_obj_address);
void *nv_dma_map(NV2AState *d, hwaddr dma_obj_address, hwaddr *len);
/* PGRAPH method dispatch (from push buffer commands) */
void pgraph_method(NV2AState *d, uint32_t subchannel,
uint32_t method, uint32_t param);
/* ============================================================
* Public API
* ============================================================ */
/* Initialize the NV2A GPU state (standalone, no QEMU PCI bus) */
NV2AState *nv2a_init_standalone(uint8_t *vram_ptr, uint32_t vram_size,
uint8_t *ramin_ptr, uint32_t ramin_size);
void nv2a_set_system_ram(uint8_t *system_ram_ptr);
/* Process an MMIO read/write from the VEH handler */
uint64_t nv2a_mmio_read(NV2AState *d, hwaddr addr, unsigned int size);
void nv2a_mmio_write(NV2AState *d, hwaddr addr, uint64_t val, unsigned int size);
/* Get the global NV2A state instance */
NV2AState *nv2a_get_state(void);
void nv2a_set_scanout_framebuffer(uint32_t framebuffer);
#endif /* BURNOUT3_NV2A_STATE_H */