1 /* $NetBSD: nouveau_nvkm_engine_sw_nv04.c,v 1.3 2021/12/18 23:45:37 riastradh Exp $ */ 2 3 /* 4 * Copyright 2012 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 25 */ 26 #include <sys/cdefs.h> 27 __KERNEL_RCSID(0, "$NetBSD: nouveau_nvkm_engine_sw_nv04.c,v 1.3 2021/12/18 23:45:37 riastradh Exp $"); 28 29 #define nv04_sw_chan(p) container_of((p), struct nv04_sw_chan, base) 30 #include "priv.h" 31 #include "chan.h" 32 #include "nvsw.h" 33 34 #include <nvif/class.h> 35 #include <nvif/if0004.h> 36 #include <nvif/ioctl.h> 37 #include <nvif/unpack.h> 38 39 struct nv04_sw_chan { 40 struct nvkm_sw_chan base; 41 atomic_t ref; 42 }; 43 44 /******************************************************************************* 45 * software object classes 46 ******************************************************************************/ 47 48 static int 49 nv04_nvsw_mthd_get_ref(struct nvkm_nvsw *nvsw, void *data, u32 size) 50 { 51 struct nv04_sw_chan *chan = nv04_sw_chan(nvsw->chan); 52 union { 53 struct nv04_nvsw_get_ref_v0 v0; 54 } *args = data; 55 int ret = -ENOSYS; 56 57 if (!(ret = nvif_unpack(ret, &data, &size, args->v0, 0, 0, false))) { 58 args->v0.ref = atomic_read(&chan->ref); 59 } 60 61 return ret; 62 } 63 64 static int 65 nv04_nvsw_mthd(struct nvkm_nvsw *nvsw, u32 mthd, void *data, u32 size) 66 { 67 switch (mthd) { 68 case NV04_NVSW_GET_REF: 69 return nv04_nvsw_mthd_get_ref(nvsw, data, size); 70 default: 71 break; 72 } 73 return -EINVAL; 74 } 75 76 static const struct nvkm_nvsw_func 77 nv04_nvsw = { 78 .mthd = nv04_nvsw_mthd, 79 }; 80 81 static int 82 nv04_nvsw_new(struct nvkm_sw_chan *chan, const struct nvkm_oclass *oclass, 83 void *data, u32 size, struct nvkm_object **pobject) 84 { 85 return nvkm_nvsw_new_(&nv04_nvsw, chan, oclass, data, size, pobject); 86 } 87 88 /******************************************************************************* 89 * software context 90 ******************************************************************************/ 91 92 static bool 93 nv04_sw_chan_mthd(struct nvkm_sw_chan *base, int subc, u32 mthd, u32 data) 94 { 95 struct nv04_sw_chan *chan = nv04_sw_chan(base); 96 97 switch (mthd) { 98 case 0x0150: 99 atomic_set(&chan->ref, data); 100 return true; 101 default: 102 break; 103 } 104 105 return false; 106 } 107 108 static const struct nvkm_sw_chan_func 109 nv04_sw_chan = { 110 .mthd = nv04_sw_chan_mthd, 111 }; 112 113 static int 114 nv04_sw_chan_new(struct nvkm_sw *sw, struct nvkm_fifo_chan *fifo, 115 const struct nvkm_oclass *oclass, struct nvkm_object **pobject) 116 { 117 struct nv04_sw_chan *chan; 118 119 if (!(chan = kzalloc(sizeof(*chan), GFP_KERNEL))) 120 return -ENOMEM; 121 atomic_set(&chan->ref, 0); 122 *pobject = &chan->base.object; 123 124 return nvkm_sw_chan_ctor(&nv04_sw_chan, sw, fifo, oclass, &chan->base); 125 } 126 127 /******************************************************************************* 128 * software engine/subdev functions 129 ******************************************************************************/ 130 131 static const struct nvkm_sw_func 132 nv04_sw = { 133 .chan_new = nv04_sw_chan_new, 134 .sclass = { 135 { nv04_nvsw_new, { -1, -1, NVIF_CLASS_SW_NV04 } }, 136 {} 137 } 138 }; 139 140 int 141 nv04_sw_new(struct nvkm_device *device, int index, struct nvkm_sw **psw) 142 { 143 return nvkm_sw_new_(&nv04_sw, device, index, psw); 144 } 145