1 #ifndef __NVKM_GSP_H__ 2 #define __NVKM_GSP_H__ 3 #define nvkm_gsp(p) container_of((p), struct nvkm_gsp, subdev) 4 #include <core/subdev.h> 5 #include <core/falcon.h> 6 #include <core/firmware.h> 7 8 #include <linux/debugfs.h> 9 10 #define GSP_PAGE_SHIFT 12 11 #define GSP_PAGE_SIZE BIT(GSP_PAGE_SHIFT) 12 13 struct nvkm_gsp_mem { 14 struct device *dev; 15 size_t size; 16 void *data; 17 dma_addr_t addr; 18 }; 19 20 int nvkm_gsp_mem_ctor(struct nvkm_gsp *, size_t size, struct nvkm_gsp_mem *); 21 void nvkm_gsp_mem_dtor(struct nvkm_gsp_mem *); 22 23 struct nvkm_gsp_radix3 { 24 struct nvkm_gsp_mem lvl0; 25 struct nvkm_gsp_mem lvl1; 26 struct sg_table lvl2; 27 }; 28 29 int nvkm_gsp_sg(struct nvkm_device *, u64 size, struct sg_table *); 30 void nvkm_gsp_sg_free(struct nvkm_device *, struct sg_table *); 31 32 typedef int (*nvkm_gsp_msg_ntfy_func)(void *priv, u32 fn, void *repv, u32 repc); 33 34 struct nvkm_gsp_event; 35 typedef void (*nvkm_gsp_event_func)(struct nvkm_gsp_event *, void *repv, u32 repc); 36 37 /** 38 * DOC: GSP message handling policy 39 * 40 * When sending a GSP RPC command, there can be multiple cases of handling 41 * the GSP RPC messages, which are the reply of GSP RPC commands, according 42 * to the requirement of the callers and the nature of the GSP RPC commands. 43 * 44 * NVKM_GSP_RPC_REPLY_NOWAIT - If specified, immediately return to the 45 * caller after the GSP RPC command is issued. 46 * 47 * NVKM_GSP_RPC_REPLY_NOSEQ - If specified, exactly like NOWAIT 48 * but don't emit RPC sequence number. 49 * 50 * NVKM_GSP_RPC_REPLY_RECV - If specified, wait and receive the entire GSP 51 * RPC message after the GSP RPC command is issued. 52 * 53 * NVKM_GSP_RPC_REPLY_POLL - If specified, wait for the specific reply and 54 * discard the reply before returning to the caller. 55 * 56 */ 57 enum nvkm_gsp_rpc_reply_policy { 58 NVKM_GSP_RPC_REPLY_NOWAIT = 0, 59 NVKM_GSP_RPC_REPLY_NOSEQ, 60 NVKM_GSP_RPC_REPLY_RECV, 61 NVKM_GSP_RPC_REPLY_POLL, 62 }; 63 64 struct nvkm_gsp { 65 const struct nvkm_gsp_func *func; 66 struct nvkm_subdev subdev; 67 68 struct nvkm_falcon falcon; 69 70 struct { 71 struct { 72 const struct firmware *load; 73 const struct firmware *unload; 74 } booter; 75 76 const struct firmware *fmc; 77 78 const struct firmware *bl; 79 const struct firmware *rm; 80 81 struct { 82 struct nvkm_falcon_fw sb; 83 } falcon; 84 } fws; 85 86 struct nvkm_firmware fw; 87 struct nvkm_gsp_mem sig; 88 struct nvkm_gsp_radix3 radix3; 89 90 struct { 91 struct { 92 struct { 93 u64 addr; 94 u64 size; 95 } vga_workspace; 96 u64 addr; 97 u64 size; 98 } bios; 99 struct { 100 struct { 101 u64 addr; 102 u64 size; 103 } frts, boot, elf, heap; 104 u64 addr; 105 u64 size; 106 } wpr2; 107 struct { 108 u64 addr; 109 u64 size; 110 } heap; 111 u64 addr; 112 u64 size; 113 114 struct { 115 u64 addr; 116 u64 size; 117 } region[16]; 118 int region_nr; 119 u32 rsvd_size; 120 } fb; 121 122 struct { 123 struct nvkm_falcon_fw load; 124 struct nvkm_falcon_fw unload; 125 } booter; 126 127 struct { 128 struct nvkm_gsp_mem fw; 129 u8 *hash; 130 u8 *pkey; 131 u8 *sig; 132 133 struct nvkm_gsp_mem args; 134 } fmc; 135 136 struct { 137 struct nvkm_gsp_mem fw; 138 u32 code_offset; 139 u32 data_offset; 140 u32 manifest_offset; 141 u32 app_version; 142 } boot; 143 144 struct nvkm_gsp_mem libos; 145 struct nvkm_gsp_mem loginit; 146 struct nvkm_gsp_mem logintr; 147 struct nvkm_gsp_mem logrm; 148 struct nvkm_gsp_mem rmargs; 149 150 struct nvkm_gsp_mem wpr_meta; 151 152 struct { 153 struct sg_table sgt; 154 struct nvkm_gsp_radix3 radix3; 155 struct nvkm_gsp_mem meta; 156 struct sg_table fbsr; 157 } sr; 158 159 struct { 160 bool use_raw_mode_comptagline_alloc; 161 } memsys; 162 163 struct { 164 struct nvkm_gsp_mem mem; 165 166 struct { 167 int nr; 168 u32 size; 169 u64 *ptr; 170 } ptes; 171 172 struct { 173 u32 size; 174 void *ptr; 175 } cmdq, msgq; 176 } shm; 177 178 struct nvkm_gsp_cmdq { 179 struct mutex mutex; 180 u32 cnt; 181 u32 seq; 182 u32 *wptr; 183 u32 *rptr; 184 } cmdq; 185 186 struct nvkm_gsp_msgq { 187 struct mutex mutex; 188 u32 cnt; 189 u32 *wptr; 190 u32 *rptr; 191 struct nvkm_gsp_msgq_ntfy { 192 u32 fn; 193 nvkm_gsp_msg_ntfy_func func; 194 void *priv; 195 } ntfy[16]; 196 int ntfy_nr; 197 struct work_struct work; 198 } msgq; 199 200 bool running; 201 202 /* Internal GSP-RM control handles. */ 203 struct { 204 struct nvkm_gsp_client { 205 struct nvkm_gsp_object { 206 struct nvkm_gsp_client *client; 207 struct nvkm_gsp_object *parent; 208 u32 handle; 209 } object; 210 211 struct nvkm_gsp *gsp; 212 213 struct list_head events; 214 } client; 215 216 struct nvkm_gsp_device { 217 struct nvkm_gsp_object object; 218 struct nvkm_gsp_object subdevice; 219 } device; 220 } internal; 221 222 struct { 223 enum nvkm_subdev_type type; 224 int inst; 225 u32 stall; 226 u32 nonstall; 227 } intr[32]; 228 int intr_nr; 229 230 struct { 231 u64 rm_bar1_pdb; 232 u64 rm_bar2_pdb; 233 } bar; 234 235 struct { 236 u8 gpcs; 237 u8 tpcs; 238 } gr; 239 240 struct nvkm_rm *rm; 241 242 struct { 243 struct mutex mutex; 244 struct idr idr; 245 } client_id; 246 247 /* A linked list of registry items. The registry RPC will be built from it. */ 248 struct list_head registry_list; 249 250 /* The size of the registry RPC */ 251 size_t registry_rpc_size; 252 253 u32 rpc_seq; 254 255 #ifdef CONFIG_DEBUG_FS 256 /* 257 * Logging buffers in debugfs. The wrapper objects need to remain 258 * in memory until the dentry is deleted. 259 */ 260 struct { 261 struct dentry *parent; 262 struct dentry *init; 263 struct dentry *rm; 264 struct dentry *intr; 265 struct dentry *pmu; 266 } debugfs; 267 struct debugfs_blob_wrapper blob_init; 268 struct debugfs_blob_wrapper blob_intr; 269 struct debugfs_blob_wrapper blob_rm; 270 struct debugfs_blob_wrapper blob_pmu; 271 #endif 272 }; 273 274 static inline bool 275 nvkm_gsp_rm(struct nvkm_gsp *gsp) 276 { 277 return gsp && (gsp->fws.rm || gsp->fw.img); 278 } 279 280 #include <rm/rm.h> 281 282 static inline void * 283 nvkm_gsp_rpc_get(struct nvkm_gsp *gsp, u32 fn, u32 argc) 284 { 285 return gsp->rm->api->rpc->get(gsp, fn, argc); 286 } 287 288 static inline void * 289 nvkm_gsp_rpc_push(struct nvkm_gsp *gsp, void *argv, 290 enum nvkm_gsp_rpc_reply_policy policy, u32 repc) 291 { 292 return gsp->rm->api->rpc->push(gsp, argv, policy, repc); 293 } 294 295 static inline void * 296 nvkm_gsp_rpc_rd(struct nvkm_gsp *gsp, u32 fn, u32 argc) 297 { 298 void *argv = nvkm_gsp_rpc_get(gsp, fn, argc); 299 300 if (IS_ERR_OR_NULL(argv)) 301 return argv; 302 303 return nvkm_gsp_rpc_push(gsp, argv, NVKM_GSP_RPC_REPLY_RECV, argc); 304 } 305 306 static inline int 307 nvkm_gsp_rpc_wr(struct nvkm_gsp *gsp, void *argv, 308 enum nvkm_gsp_rpc_reply_policy policy) 309 { 310 void *repv = nvkm_gsp_rpc_push(gsp, argv, policy, 0); 311 312 if (IS_ERR(repv)) 313 return PTR_ERR(repv); 314 315 return 0; 316 } 317 318 static inline void 319 nvkm_gsp_rpc_done(struct nvkm_gsp *gsp, void *repv) 320 { 321 gsp->rm->api->rpc->done(gsp, repv); 322 } 323 324 static inline void * 325 nvkm_gsp_rm_ctrl_get(struct nvkm_gsp_object *object, u32 cmd, u32 argc) 326 { 327 return object->client->gsp->rm->api->ctrl->get(object, cmd, argc); 328 } 329 330 static inline int 331 nvkm_gsp_rm_ctrl_push(struct nvkm_gsp_object *object, void *argv, u32 repc) 332 { 333 return object->client->gsp->rm->api->ctrl->push(object, argv, repc); 334 } 335 336 static inline void * 337 nvkm_gsp_rm_ctrl_rd(struct nvkm_gsp_object *object, u32 cmd, u32 repc) 338 { 339 void *argv = nvkm_gsp_rm_ctrl_get(object, cmd, repc); 340 int ret; 341 342 if (IS_ERR(argv)) 343 return argv; 344 345 ret = nvkm_gsp_rm_ctrl_push(object, &argv, repc); 346 if (ret) 347 return ERR_PTR(ret); 348 return argv; 349 } 350 351 static inline int 352 nvkm_gsp_rm_ctrl_wr(struct nvkm_gsp_object *object, void *argv) 353 { 354 int ret = nvkm_gsp_rm_ctrl_push(object, &argv, 0); 355 356 if (ret) 357 return ret; 358 return 0; 359 } 360 361 static inline void 362 nvkm_gsp_rm_ctrl_done(struct nvkm_gsp_object *object, void *repv) 363 { 364 object->client->gsp->rm->api->ctrl->done(object, repv); 365 } 366 367 static inline void * 368 nvkm_gsp_rm_alloc_get(struct nvkm_gsp_object *parent, u32 handle, u32 oclass, u32 argc, 369 struct nvkm_gsp_object *object) 370 { 371 struct nvkm_gsp_client *client = parent->client; 372 struct nvkm_gsp *gsp = client->gsp; 373 void *argv; 374 375 object->client = parent->client; 376 object->parent = parent; 377 object->handle = handle; 378 379 argv = gsp->rm->api->alloc->get(object, oclass, argc); 380 if (IS_ERR_OR_NULL(argv)) { 381 object->client = NULL; 382 return argv; 383 } 384 385 return argv; 386 } 387 388 static inline void * 389 nvkm_gsp_rm_alloc_push(struct nvkm_gsp_object *object, void *argv) 390 { 391 void *repv = object->client->gsp->rm->api->alloc->push(object, argv); 392 393 if (IS_ERR(repv)) 394 object->client = NULL; 395 396 return repv; 397 } 398 399 static inline int 400 nvkm_gsp_rm_alloc_wr(struct nvkm_gsp_object *object, void *argv) 401 { 402 void *repv = nvkm_gsp_rm_alloc_push(object, argv); 403 404 if (IS_ERR(repv)) 405 return PTR_ERR(repv); 406 407 return 0; 408 } 409 410 static inline void 411 nvkm_gsp_rm_alloc_done(struct nvkm_gsp_object *object, void *repv) 412 { 413 object->client->gsp->rm->api->alloc->done(object, repv); 414 } 415 416 static inline int 417 nvkm_gsp_rm_alloc(struct nvkm_gsp_object *parent, u32 handle, u32 oclass, u32 argc, 418 struct nvkm_gsp_object *object) 419 { 420 void *argv = nvkm_gsp_rm_alloc_get(parent, handle, oclass, argc, object); 421 422 if (IS_ERR_OR_NULL(argv)) 423 return argv ? PTR_ERR(argv) : -EIO; 424 425 return nvkm_gsp_rm_alloc_wr(object, argv); 426 } 427 428 static inline int 429 nvkm_gsp_rm_free(struct nvkm_gsp_object *object) 430 { 431 if (object->client) { 432 int ret = object->client->gsp->rm->api->alloc->free(object); 433 object->client = NULL; 434 return ret; 435 } 436 437 return 0; 438 } 439 440 int nvkm_gsp_client_ctor(struct nvkm_gsp *, struct nvkm_gsp_client *); 441 void nvkm_gsp_client_dtor(struct nvkm_gsp_client *); 442 443 static inline int 444 nvkm_gsp_device_ctor(struct nvkm_gsp_client *client, struct nvkm_gsp_device *device) 445 { 446 return client->gsp->rm->api->device->ctor(client, device); 447 } 448 449 static inline void 450 nvkm_gsp_device_dtor(struct nvkm_gsp_device *device) 451 { 452 if (device->object.client) 453 device->object.client->gsp->rm->api->device->dtor(device); 454 } 455 456 static inline int 457 nvkm_gsp_client_device_ctor(struct nvkm_gsp *gsp, 458 struct nvkm_gsp_client *client, struct nvkm_gsp_device *device) 459 { 460 int ret = nvkm_gsp_client_ctor(gsp, client); 461 462 if (ret == 0) { 463 ret = nvkm_gsp_device_ctor(client, device); 464 if (ret) 465 nvkm_gsp_client_dtor(client); 466 } 467 468 return ret; 469 } 470 471 struct nvkm_gsp_event { 472 struct nvkm_gsp_device *device; 473 u32 id; 474 nvkm_gsp_event_func func; 475 476 struct nvkm_gsp_object object; 477 478 struct list_head head; 479 }; 480 481 static inline int 482 nvkm_gsp_device_event_ctor(struct nvkm_gsp_device *device, u32 handle, u32 id, 483 nvkm_gsp_event_func func, struct nvkm_gsp_event *event) 484 { 485 struct nvkm_rm *rm = device->object.client->gsp->rm; 486 487 return rm->api->device->event.ctor(device, handle, id, func, event); 488 } 489 490 static inline void 491 nvkm_gsp_event_dtor(struct nvkm_gsp_event *event) 492 { 493 struct nvkm_gsp_device *device = event->device; 494 495 if (device) 496 device->object.client->gsp->rm->api->device->event.dtor(event); 497 } 498 499 int nvkm_gsp_intr_stall(struct nvkm_gsp *, enum nvkm_subdev_type, int); 500 int nvkm_gsp_intr_nonstall(struct nvkm_gsp *, enum nvkm_subdev_type, int); 501 502 int nvkm_gsp_gcx_ready(struct nvkm_gsp *gsp); 503 504 int gv100_gsp_new(struct nvkm_device *, enum nvkm_subdev_type, int, struct nvkm_gsp **); 505 int tu102_gsp_new(struct nvkm_device *, enum nvkm_subdev_type, int, struct nvkm_gsp **); 506 int tu116_gsp_new(struct nvkm_device *, enum nvkm_subdev_type, int, struct nvkm_gsp **); 507 int ga100_gsp_new(struct nvkm_device *, enum nvkm_subdev_type, int, struct nvkm_gsp **); 508 int ga102_gsp_new(struct nvkm_device *, enum nvkm_subdev_type, int, struct nvkm_gsp **); 509 int gh100_gsp_new(struct nvkm_device *, enum nvkm_subdev_type, int, struct nvkm_gsp **); 510 int ad102_gsp_new(struct nvkm_device *, enum nvkm_subdev_type, int, struct nvkm_gsp **); 511 int gb100_gsp_new(struct nvkm_device *, enum nvkm_subdev_type, int, struct nvkm_gsp **); 512 int gb202_gsp_new(struct nvkm_device *, enum nvkm_subdev_type, int, struct nvkm_gsp **); 513 #endif 514