Linux-libre 3.17.4-gnu
[librecmc/linux-libre.git] / drivers / gpu / drm / nouveau / core / engine / software / nv04.c
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/software.h>
29 #include <engine/fifo.h>
30
31 struct nv04_software_priv {
32         struct nouveau_software base;
33 };
34
35 struct nv04_software_chan {
36         struct nouveau_software_chan base;
37 };
38
39 /*******************************************************************************
40  * software object classes
41  ******************************************************************************/
42
43 static int
44 nv04_software_set_ref(struct nouveau_object *object, u32 mthd,
45                       void *data, u32 size)
46 {
47         struct nouveau_object *channel = (void *)nv_engctx(object->parent);
48         struct nouveau_fifo_chan *fifo = (void *)channel->parent;
49         atomic_set(&fifo->refcnt, *(u32*)data);
50         return 0;
51 }
52
53 static int
54 nv04_software_flip(struct nouveau_object *object, u32 mthd,
55                    void *args, u32 size)
56 {
57         struct nv04_software_chan *chan = (void *)nv_engctx(object->parent);
58         if (chan->base.flip)
59                 return chan->base.flip(chan->base.flip_data);
60         return -EINVAL;
61 }
62
63 static struct nouveau_omthds
64 nv04_software_omthds[] = {
65         { 0x0150, 0x0150, nv04_software_set_ref },
66         { 0x0500, 0x0500, nv04_software_flip },
67         {}
68 };
69
70 static struct nouveau_oclass
71 nv04_software_sclass[] = {
72         { 0x006e, &nouveau_object_ofuncs, nv04_software_omthds },
73         {}
74 };
75
76 /*******************************************************************************
77  * software context
78  ******************************************************************************/
79
80 static int
81 nv04_software_context_ctor(struct nouveau_object *parent,
82                       struct nouveau_object *engine,
83                       struct nouveau_oclass *oclass, void *data, u32 size,
84                       struct nouveau_object **pobject)
85 {
86         struct nv04_software_chan *chan;
87         int ret;
88
89         ret = nouveau_software_context_create(parent, engine, oclass, &chan);
90         *pobject = nv_object(chan);
91         if (ret)
92                 return ret;
93
94         return 0;
95 }
96
97 static struct nouveau_oclass
98 nv04_software_cclass = {
99         .handle = NV_ENGCTX(SW, 0x04),
100         .ofuncs = &(struct nouveau_ofuncs) {
101                 .ctor = nv04_software_context_ctor,
102                 .dtor = _nouveau_software_context_dtor,
103                 .init = _nouveau_software_context_init,
104                 .fini = _nouveau_software_context_fini,
105         },
106 };
107
108 /*******************************************************************************
109  * software engine/subdev functions
110  ******************************************************************************/
111
112 void
113 nv04_software_intr(struct nouveau_subdev *subdev)
114 {
115         nv_mask(subdev, 0x000100, 0x80000000, 0x00000000);
116 }
117
118 static int
119 nv04_software_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
120               struct nouveau_oclass *oclass, void *data, u32 size,
121               struct nouveau_object **pobject)
122 {
123         struct nv04_software_priv *priv;
124         int ret;
125
126         ret = nouveau_software_create(parent, engine, oclass, &priv);
127         *pobject = nv_object(priv);
128         if (ret)
129                 return ret;
130
131         nv_engine(priv)->cclass = &nv04_software_cclass;
132         nv_engine(priv)->sclass = nv04_software_sclass;
133         nv_subdev(priv)->intr = nv04_software_intr;
134         return 0;
135 }
136
137 struct nouveau_oclass *
138 nv04_software_oclass = &(struct nouveau_oclass) {
139         .handle = NV_ENGINE(SW, 0x04),
140         .ofuncs = &(struct nouveau_ofuncs) {
141                 .ctor = nv04_software_ctor,
142                 .dtor = _nouveau_software_dtor,
143                 .init = _nouveau_software_init,
144                 .fini = _nouveau_software_fini,
145         },
146 };