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