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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
|
# WPR (Write/Read Protect Region) Management
## Overview
WPR (Write Protect Region / Read Protect Region) provides memory isolation for vGPU by protecting guest memory regions from unauthorized access. The GSP firmware implements WPR through two handlers at **0x04F00B0C** and **0x04F00C78** (62 KB each).
## Key Addresses
| Handler | Address | Size | Role |
|---------|---------|------|------|
| WPR Handler 1 | 0x04F00B0C | 62 KB | Primary WPR management |
| WPR Handler 2 | 0x04F00C78 | 62 KB | Secondary/timeout handling |
| String Table | 60 locations | — | Completion/timeout strings |
## String References (60 Total)
### Completion Events
```
WPR_WRITE_COMPLETE 0x5E478F8
WPR_READ_COMPLETE 0x5E478E0
NV_WPR_WRITE_COMPLETE 0x5E478C8
NV_WPR_READ_COMPLETE 0x5E478B0
```
### Timeout Events
```
WPR_WRITE_TIMEOUT 0x5E47898
WPR_READ_TIMEOUT 0x5E47880
NV_WPR_WRITE_TIMEOUT 0x5E47868
NV_WPR_READ_TIMEOUT 0x5E47850
```
## WPR State Machine
### Handler 1: 0x04F00B0C (Primary)
```c
typedef enum {
WPR_STATE_IDLE = 0,
WPR_STATE_WRITE_PENDING = 1,
WPR_STATE_READ_PENDING = 2,
WPR_STATE_COMPLETE = 3,
WPR_STATE_TIMEOUT = 4,
WPR_STATE_ERROR = 0xFFFF
} wpr_state_t;
typedef struct {
uint64_t region_base; // Protected region base
uint64_t region_size; // Region size (page-aligned)
uint32_t vf_id; // Owning VF
uint32_t flags; // WPR_WRITE | WPR_READ | WPR_EXECUTE
wpr_state_t state;
uint64_t timeout_ns; // Operation timeout
void *completion_cb; // Callback on complete
void *timeout_cb; // Callback on timeout
} wpr_region_t;
```
### Operation Flow
#### Write Protect
```
1. VF requests WPR_WRITE on region [base, base+size)
2. Handler validates alignment (4KB) and permissions
3. Programs MMU/IOMMU write-protect bits
4. Starts timeout timer (configurable)
5. On GPU write attempt:
a. Trap to GSP via page fault
b. Check if VF owns region
c. If allowed: emulate write, return OK
d. If denied: trigger WPR_WRITE_COMPLETE/NV_WPR_WRITE_COMPLETE
6. On timeout: trigger WPR_WRITE_TIMEOUT/NV_WPR_WRITE_TIMEOUT
```
#### Read Protect
```
1. VF requests WPR_READ on region
2. Programs MMU/IOMMU read-protect bits
3. On GPU read attempt:
a. Trap to GSP
b. Return zero/poison data or emulate
c. Trigger WPR_READ_COMPLETE/NV_WPR_READ_COMPLETE
4. On timeout: trigger WPR_READ_TIMEOUT/NV_WPR_READ_TIMEOUT
```
## VBIOS Parsing (Handler 2: 0x04F00C78)
The WPR handlers parse VBIOS structures for legacy compatibility:
```c
int parse_vbios_for_wpr(void *vbios_ptr, size_t size) {
// Search for signatures:
// 0xAA55 - Standard VBIOS signature
// 0x57464F4E ("WFON") - WPR enable
// 0x5746564E ("WFVN") - WPR version
for (offset = 0; offset < size; offset += 0x1000) {
uint32_t sig = *(uint32_t*)(vbios_ptr + offset);
if (sig == 0xAA55) {
// Check for WPR structures
parse_wpr_tables(vbios_ptr + offset);
}
else if (sig == 0x57464F4E || sig == 0x5746564E) {
// WPR enabled in VBIOS
wpr_vbios_enabled = true;
wpr_vbios_offset = offset;
}
}
}
```
## Integration with GSP Subsystems
### Memory Allocator (0x429B450)
```c
// Allocate WPR metadata structures
wpr_region_t *wpr_alloc_region() {
return UNK_ram_058A1A9C(0x429B450, sizeof(wpr_region_t));
}
// Allocate bounce buffers for emulation
void *wpr_alloc_bounce(size_t size) {
return UNK_ram_058A1A9C(0x429B450, size);
}
```
### DMA/Copy Engine (0x0588F9C4, 0x05AEC86C)
```c
// Copy data for WPR emulation
int wpr_emulate_access(wpr_region_t *rgn, void *dst, void *src, size_t size) {
return UNK_ram_0588F9C4(dma_engine, src, dst, size);
}
```
### Logging (0x05AB7DA0)
```c
// Log WPR events
void wpr_log_event(const char *event_str, uint32_t vf_id, uint64_t addr) {
UNK_ram_05AB7DA0(1, &event_str); // Log string
UNK_ram_05AB7DA0(2, &vf_id); // Log VF ID
UNK_ram_05AB7DA0(3, &addr); // Log address
}
```
## vGPU-IO Integration
### Kernel WPR API
```c
struct gsp_wpr_ops {
int (*protect_write)(struct gsp_device *gsp,
uint32_t vf_id,
uint64_t base, uint64_t size);
int (*protect_read)(struct gsp_device *gsp,
uint32_t vf_id,
uint64_t base, uint64_t size);
int (*unprotect)(struct gsp_device *gsp,
uint32_t vf_id,
uint64_t base);
int (*set_timeout)(struct gsp_device *gsp,
uint32_t vf_id,
uint64_t timeout_ns);
int (*register_callback)(struct gsp_device *gsp,
uint32_t vf_id,
enum wpr_event_type type,
void (*cb)(struct wpr_event *));
};
static const struct gsp_wpr_ops gsp_wpr_ops = {
.protect_write = gsp_wpr_write_protect,
.protect_read = gsp_wpr_read_protect,
.unprotect = gsp_wpr_unprotect,
.set_timeout = gsp_wpr_set_timeout,
.register_callback = gsp_wpr_register_callback,
};
```
### VF WPR Lifecycle
```c
// VF initialization: register WPR regions
int gsp_vf_wpr_init(struct gsp_vf *vf) {
// Protect VF's page tables
gsp_wpr_ops.protect_write(vf->gsp, vf->id,
vf->pt_base, vf->pt_size);
// Protect VF's command buffers
gsp_wpr_ops.protect_write(vf->gsp, vf->id,
vf->cmd_base, vf->cmd_size);
// Set default timeout (10ms)
gsp_wpr_ops.set_timeout(vf->gsp, vf->id, 10000000);
// Register completion callbacks
gsp_wpr_ops.register_callback(vf->gsp, vf->id,
WPR_EVENT_WRITE_COMPLETE,
vf_wpr_write_complete_cb);
gsp_wpr_ops.register_callback(vf->gsp, vf->id,
WPR_EVENT_TIMEOUT,
vf_wpr_timeout_cb);
return 0;
}
// VF cleanup
void gsp_vf_wpr_fini(struct gsp_vf *vf) {
gsp_wpr_ops.unprotect(vf->gsp, vf->id, vf->pt_base);
gsp_wpr_ops.unprotect(vf->gsp, vf->id, vf->cmd_base);
// ... unregister callbacks
}
```
### Callback Handling
```c
static void vf_wpr_write_complete_cb(struct wpr_event *evt) {
struct gsp_vf *vf = evt->vf;
// Log the write attempt
dev_dbg(vf->dev, "WPR write complete: VF=%u addr=0x%llx\n",
vf->id, evt->address);
// If this was a page table update, invalidate TLB
if (evt->address >= vf->pt_base &&
evt->address < vf->pt_base + vf->pt_size) {
gsp_tlb_invalidate(vf->gsp, vf->id);
}
}
static void vf_wpr_timeout_cb(struct wpr_event *evt) {
struct gsp_vf *vf = evt->vf;
dev_warn(vf->dev, "WPR timeout: VF=%u type=%d addr=0x%llx\n",
vf->id, evt->type, evt->address);
// Escalate: reset VF or throttle
if (evt->type == WPR_EVENT_WRITE_TIMEOUT) {
gsp_vf_throttle(vf);
} else {
gsp_vf_reset(vf);
}
}
```
## Error Codes
| Code | Name | Description |
|------|------|-------------|
| 0x1E | ETIME | Operation timed out |
| 0x1F | EDEV | Device error |
| 0x25 | EOVERFLOW | Region too large |
| 0x37 | EINVAL | Invalid alignment |
| 0x51 | ENOMEM | Out of memory |
| 0x56 | EBUSY | Region busy |
| 0xFFFF | EPERM | Permission denied |
## Debugging
### Monitor These Addresses
```
0x04296048 : Global error flag
0x0429B750+0x111300 : Error status register
0x05E47850-0x05E478F8 : WPR string table
```
### GSP Log Patterns
```
WPR_WRITE_COMPLETE VF=<id> ADDR=<addr>
WPR_READ_COMPLETE VF=<id> ADDR=<addr>
WPR_WRITE_TIMEOUT VF=<id> ADDR=<addr>
WPR_READ_TIMEOUT VF=<id> ADDR=<addr>
NV_WPR_WRITE_COMPLETE VF=<id> ADDR=<addr>
NV_WPR_READ_COMPLETE VF=<id> ADDR=<addr>
NV_WPR_WRITE_TIMEOUT VF=<id> ADDR=<addr>
NV_WPR_READ_TIMEOUT VF=<id> ADDR=<addr>
```
### Trace Points
```c
// In kernel driver
trace_gsp_wpr_protect(vf_id, base, size, type);
trace_gsp_wpr_event(vf_id, event_type, address, status);
trace_gsp_wpr_timeout(vf_id, address, elapsed_ns);
```
---
## Reference
- Handler 1: `FUN_ram_04f00b0c_ram_04f00b0c.c` (62 KB)
- Handler 2: `FUN_ram_04f00c78_ram_04f00c78.c` (62 KB)
- RPC Types: Handled via primary/secondary dispatchers
|