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