1 /* $NetBSD: nouveau_nvkm_engine_sw_nvsw.c,v 1.3 2021/12/18 23:45:37 riastradh Exp $ */ 2 3 /* 4 * Copyright 2015 Red Hat Inc. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the "Software"), 8 * to deal in the Software without restriction, including without limitation 9 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 * and/or sell copies of the Software, and to permit persons to whom the 11 * Software is furnished to do so, subject to the following conditions: 12 * 13 * The above copyright notice and this permission notice shall be included in 14 * all copies or substantial portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 * OTHER DEALINGS IN THE SOFTWARE. 23 * 24 * Authors: Ben Skeggs <bskeggs (at) redhat.com> 25 */ 26 #include <sys/cdefs.h> 27 __KERNEL_RCSID(0, "$NetBSD: nouveau_nvkm_engine_sw_nvsw.c,v 1.3 2021/12/18 23:45:37 riastradh Exp $"); 28 29 #include "nvsw.h" 30 #include "chan.h" 31 32 #include <nvif/if0004.h> 33 34 static int 35 nvkm_nvsw_mthd_(struct nvkm_object *object, u32 mthd, void *data, u32 size) 36 { 37 struct nvkm_nvsw *nvsw = nvkm_nvsw(object); 38 if (nvsw->func->mthd) 39 return nvsw->func->mthd(nvsw, mthd, data, size); 40 return -ENODEV; 41 } 42 43 static int 44 nvkm_nvsw_ntfy_(struct nvkm_object *object, u32 mthd, 45 struct nvkm_event **pevent) 46 { 47 struct nvkm_nvsw *nvsw = nvkm_nvsw(object); 48 switch (mthd) { 49 case NV04_NVSW_NTFY_UEVENT: 50 *pevent = &nvsw->chan->event; 51 return 0; 52 default: 53 break; 54 } 55 return -EINVAL; 56 } 57 58 static const struct nvkm_object_func 59 nvkm_nvsw_ = { 60 .mthd = nvkm_nvsw_mthd_, 61 .ntfy = nvkm_nvsw_ntfy_, 62 }; 63 64 int 65 nvkm_nvsw_new_(const struct nvkm_nvsw_func *func, struct nvkm_sw_chan *chan, 66 const struct nvkm_oclass *oclass, void *data, u32 size, 67 struct nvkm_object **pobject) 68 { 69 struct nvkm_nvsw *nvsw; 70 71 if (!(nvsw = kzalloc(sizeof(*nvsw), GFP_KERNEL))) 72 return -ENOMEM; 73 *pobject = &nvsw->object; 74 75 nvkm_object_ctor(&nvkm_nvsw_, oclass, &nvsw->object); 76 nvsw->func = func; 77 nvsw->chan = chan; 78 return 0; 79 } 80 81 static const struct nvkm_nvsw_func 82 nvkm_nvsw = { 83 }; 84 85 int 86 nvkm_nvsw_new(struct nvkm_sw_chan *chan, const struct nvkm_oclass *oclass, 87 void *data, u32 size, struct nvkm_object **pobject) 88 { 89 return nvkm_nvsw_new_(&nvkm_nvsw, chan, oclass, data, size, pobject); 90 } 91