1 /* 2 * Copyright 2023 Red Hat Inc. 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included in 12 * all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 * OTHER DEALINGS IN THE SOFTWARE. 21 */ 22 #include "priv.h" 23 24 #include <core/object.h> 25 #include <subdev/gsp.h> 26 #include <engine/fifo.h> 27 28 #include <nvrm/nvtypes.h> 29 #include <nvrm/535.113.01/common/sdk/nvidia/inc/nvos.h> 30 31 struct r535_nvjpg_obj { 32 struct nvkm_object object; 33 struct nvkm_gsp_object rm; 34 }; 35 36 static void * 37 r535_nvjpg_obj_dtor(struct nvkm_object *object) 38 { 39 struct r535_nvjpg_obj *obj = container_of(object, typeof(*obj), object); 40 41 nvkm_gsp_rm_free(&obj->rm); 42 return obj; 43 } 44 45 static const struct nvkm_object_func 46 r535_nvjpg_obj = { 47 .dtor = r535_nvjpg_obj_dtor, 48 }; 49 50 static int 51 r535_nvjpg_obj_ctor(const struct nvkm_oclass *oclass, void *argv, u32 argc, 52 struct nvkm_object **pobject) 53 { 54 struct nvkm_chan *chan = nvkm_uchan_chan(oclass->parent); 55 struct r535_nvjpg_obj *obj; 56 NV_NVJPG_ALLOCATION_PARAMETERS *args; 57 58 if (!(obj = kzalloc(sizeof(*obj), GFP_KERNEL))) 59 return -ENOMEM; 60 61 nvkm_object_ctor(&r535_nvjpg_obj, oclass, &obj->object); 62 *pobject = &obj->object; 63 64 args = nvkm_gsp_rm_alloc_get(&chan->rm.object, oclass->handle, oclass->base.oclass, 65 sizeof(*args), &obj->rm); 66 if (WARN_ON(IS_ERR(args))) 67 return PTR_ERR(args); 68 69 args->size = sizeof(*args); 70 args->engineInstance = oclass->engine->subdev.inst; 71 72 return nvkm_gsp_rm_alloc_wr(&obj->rm, args); 73 } 74 75 static void * 76 r535_nvjpg_dtor(struct nvkm_engine *engine) 77 { 78 kfree(engine->func); 79 return engine; 80 } 81 82 int 83 r535_nvjpg_new(const struct nvkm_engine_func *hw, struct nvkm_device *device, 84 enum nvkm_subdev_type type, int inst, struct nvkm_engine **pengine) 85 { 86 struct nvkm_engine_func *rm; 87 int nclass, ret; 88 89 for (nclass = 0; hw->sclass[nclass].oclass; nclass++); 90 91 if (!(rm = kzalloc(sizeof(*rm) + (nclass + 1) * sizeof(rm->sclass[0]), GFP_KERNEL))) 92 return -ENOMEM; 93 94 rm->dtor = r535_nvjpg_dtor; 95 for (int i = 0; i < nclass; i++) { 96 rm->sclass[i].minver = hw->sclass[i].minver; 97 rm->sclass[i].maxver = hw->sclass[i].maxver; 98 rm->sclass[i].oclass = hw->sclass[i].oclass; 99 rm->sclass[i].ctor = r535_nvjpg_obj_ctor; 100 } 101 102 ret = nvkm_engine_new_(rm, device, type, inst, true, pengine); 103 if (ret) 104 kfree(rm); 105 106 return ret; 107 } 108