1 /* 2 * Copyright 2012 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 * Authors: Ben Skeggs 23 */ 24 #include <engine/sw.h> 25 #include <engine/fifo.h> 26 27 #include <nvif/ioctl.h> 28 29 /******************************************************************************* 30 * software object classes 31 ******************************************************************************/ 32 33 static int 34 nv04_sw_set_ref(struct nvkm_object *object, u32 mthd, void *data, u32 size) 35 { 36 struct nvkm_object *channel = (void *)nv_engctx(object->parent); 37 struct nvkm_fifo_chan *fifo = (void *)channel->parent; 38 atomic_set(&fifo->refcnt, *(u32*)data); 39 return 0; 40 } 41 42 static int 43 nv04_sw_flip(struct nvkm_object *object, u32 mthd, void *args, u32 size) 44 { 45 struct nvkm_sw_chan *chan = (void *)nv_engctx(object->parent); 46 if (chan->flip) 47 return chan->flip(chan->flip_data); 48 return -EINVAL; 49 } 50 51 static struct nvkm_omthds 52 nv04_sw_omthds[] = { 53 { 0x0150, 0x0150, nv04_sw_set_ref }, 54 { 0x0500, 0x0500, nv04_sw_flip }, 55 {} 56 }; 57 58 static struct nvkm_oclass 59 nv04_sw_sclass[] = { 60 { NVIF_IOCTL_NEW_V0_SW_NV04, &nvkm_object_ofuncs, nv04_sw_omthds }, 61 {} 62 }; 63 64 /******************************************************************************* 65 * software context 66 ******************************************************************************/ 67 68 static int 69 nv04_sw_context_ctor(struct nvkm_object *parent, struct nvkm_object *engine, 70 struct nvkm_oclass *oclass, void *data, u32 size, 71 struct nvkm_object **pobject) 72 { 73 struct nvkm_sw_chan *chan; 74 int ret; 75 76 ret = nvkm_sw_context_create(parent, engine, oclass, &chan); 77 *pobject = nv_object(chan); 78 if (ret) 79 return ret; 80 81 return 0; 82 } 83 84 static struct nvkm_oclass 85 nv04_sw_cclass = { 86 .handle = NV_ENGCTX(SW, 0x04), 87 .ofuncs = &(struct nvkm_ofuncs) { 88 .ctor = nv04_sw_context_ctor, 89 .dtor = _nvkm_sw_context_dtor, 90 .init = _nvkm_sw_context_init, 91 .fini = _nvkm_sw_context_fini, 92 }, 93 }; 94 95 /******************************************************************************* 96 * software engine/subdev functions 97 ******************************************************************************/ 98 99 void 100 nv04_sw_intr(struct nvkm_subdev *subdev) 101 { 102 nvkm_mask(subdev->device, 0x000100, 0x80000000, 0x00000000); 103 } 104 105 static int 106 nv04_sw_ctor(struct nvkm_object *parent, struct nvkm_object *engine, 107 struct nvkm_oclass *oclass, void *data, u32 size, 108 struct nvkm_object **pobject) 109 { 110 struct nvkm_sw *sw; 111 int ret; 112 113 ret = nvkm_sw_create(parent, engine, oclass, &sw); 114 *pobject = nv_object(sw); 115 if (ret) 116 return ret; 117 118 nv_engine(sw)->cclass = &nv04_sw_cclass; 119 nv_engine(sw)->sclass = nv04_sw_sclass; 120 nv_subdev(sw)->intr = nv04_sw_intr; 121 return 0; 122 } 123 124 struct nvkm_oclass * 125 nv04_sw_oclass = &(struct nvkm_oclass) { 126 .handle = NV_ENGINE(SW, 0x04), 127 .ofuncs = &(struct nvkm_ofuncs) { 128 .ctor = nv04_sw_ctor, 129 .dtor = _nvkm_sw_dtor, 130 .init = _nvkm_sw_init, 131 .fini = _nvkm_sw_fini, 132 }, 133 }; 134