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