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 25 #include <core/os.h> 26 #include <core/engctx.h> 27 28 #include <engine/sw.h> 29 30 struct nv10_sw_priv { 31 struct nouveau_sw base; 32 }; 33 34 struct nv10_sw_chan { 35 struct nouveau_sw_chan base; 36 }; 37 38 /******************************************************************************* 39 * software object classes 40 ******************************************************************************/ 41 42 static int 43 nv10_sw_flip(struct nouveau_object *object, u32 mthd, 44 void *args, u32 size) 45 { 46 struct nv10_sw_chan *chan = (void *)nv_engctx(object->parent); 47 if (chan->base.flip) 48 return chan->base.flip(chan->base.flip_data); 49 return -EINVAL; 50 } 51 52 static struct nouveau_omthds 53 nv10_sw_omthds[] = { 54 { 0x0500, 0x0500, nv10_sw_flip }, 55 {} 56 }; 57 58 static struct nouveau_oclass 59 nv10_sw_sclass[] = { 60 { 0x016e, &nouveau_object_ofuncs, nv10_sw_omthds }, 61 {} 62 }; 63 64 /******************************************************************************* 65 * software context 66 ******************************************************************************/ 67 68 static int 69 nv10_sw_context_ctor(struct nouveau_object *parent, 70 struct nouveau_object *engine, 71 struct nouveau_oclass *oclass, void *data, u32 size, 72 struct nouveau_object **pobject) 73 { 74 struct nv10_sw_chan *chan; 75 int ret; 76 77 ret = nouveau_sw_context_create(parent, engine, oclass, &chan); 78 *pobject = nv_object(chan); 79 if (ret) 80 return ret; 81 82 return 0; 83 } 84 85 static struct nouveau_oclass 86 nv10_sw_cclass = { 87 .handle = NV_ENGCTX(SW, 0x04), 88 .ofuncs = &(struct nouveau_ofuncs) { 89 .ctor = nv10_sw_context_ctor, 90 .dtor = _nouveau_sw_context_dtor, 91 .init = _nouveau_sw_context_init, 92 .fini = _nouveau_sw_context_fini, 93 }, 94 }; 95 96 /******************************************************************************* 97 * software engine/subdev functions 98 ******************************************************************************/ 99 100 static int 101 nv10_sw_ctor(struct nouveau_object *parent, struct nouveau_object *engine, 102 struct nouveau_oclass *oclass, void *data, u32 size, 103 struct nouveau_object **pobject) 104 { 105 struct nv10_sw_priv *priv; 106 int ret; 107 108 ret = nouveau_sw_create(parent, engine, oclass, &priv); 109 *pobject = nv_object(priv); 110 if (ret) 111 return ret; 112 113 nv_engine(priv)->cclass = &nv10_sw_cclass; 114 nv_engine(priv)->sclass = nv10_sw_sclass; 115 nv_subdev(priv)->intr = nv04_sw_intr; 116 return 0; 117 } 118 119 struct nouveau_oclass * 120 nv10_sw_oclass = &(struct nouveau_oclass) { 121 .handle = NV_ENGINE(SW, 0x10), 122 .ofuncs = &(struct nouveau_ofuncs) { 123 .ctor = nv10_sw_ctor, 124 .dtor = _nouveau_sw_dtor, 125 .init = _nouveau_sw_init, 126 .fini = _nouveau_sw_fini, 127 }, 128 }; 129