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 26 /******************************************************************************* 27 * software object classes 28 ******************************************************************************/ 29 30 static int 31 nv10_sw_flip(struct nvkm_object *object, u32 mthd, void *args, u32 size) 32 { 33 struct nvkm_sw_chan *chan = (void *)nv_engctx(object->parent); 34 if (chan->flip) 35 return chan->flip(chan->flip_data); 36 return -EINVAL; 37 } 38 39 static struct nvkm_omthds 40 nv10_sw_omthds[] = { 41 { 0x0500, 0x0500, nv10_sw_flip }, 42 {} 43 }; 44 45 static struct nvkm_oclass 46 nv10_sw_sclass[] = { 47 { 0x016e, &nvkm_object_ofuncs, nv10_sw_omthds }, 48 {} 49 }; 50 51 /******************************************************************************* 52 * software context 53 ******************************************************************************/ 54 55 static int 56 nv10_sw_context_ctor(struct nvkm_object *parent, struct nvkm_object *engine, 57 struct nvkm_oclass *oclass, void *data, u32 size, 58 struct nvkm_object **pobject) 59 { 60 struct nvkm_sw_chan *chan; 61 int ret; 62 63 ret = nvkm_sw_context_create(parent, engine, oclass, &chan); 64 *pobject = nv_object(chan); 65 if (ret) 66 return ret; 67 68 return 0; 69 } 70 71 static struct nvkm_oclass 72 nv10_sw_cclass = { 73 .handle = NV_ENGCTX(SW, 0x04), 74 .ofuncs = &(struct nvkm_ofuncs) { 75 .ctor = nv10_sw_context_ctor, 76 .dtor = _nvkm_sw_context_dtor, 77 .init = _nvkm_sw_context_init, 78 .fini = _nvkm_sw_context_fini, 79 }, 80 }; 81 82 /******************************************************************************* 83 * software engine/subdev functions 84 ******************************************************************************/ 85 86 static int 87 nv10_sw_ctor(struct nvkm_object *parent, struct nvkm_object *engine, 88 struct nvkm_oclass *oclass, void *data, u32 size, 89 struct nvkm_object **pobject) 90 { 91 struct nvkm_sw *sw; 92 int ret; 93 94 ret = nvkm_sw_create(parent, engine, oclass, &sw); 95 *pobject = nv_object(sw); 96 if (ret) 97 return ret; 98 99 nv_engine(sw)->cclass = &nv10_sw_cclass; 100 nv_engine(sw)->sclass = nv10_sw_sclass; 101 nv_subdev(sw)->intr = nv04_sw_intr; 102 return 0; 103 } 104 105 struct nvkm_oclass * 106 nv10_sw_oclass = &(struct nvkm_oclass) { 107 .handle = NV_ENGINE(SW, 0x10), 108 .ofuncs = &(struct nvkm_ofuncs) { 109 .ctor = nv10_sw_ctor, 110 .dtor = _nvkm_sw_dtor, 111 .init = _nvkm_sw_init, 112 .fini = _nvkm_sw_fini, 113 }, 114 }; 115