drm/nvc0/gr: add software methods to control some MP regs
[platform/adaptation/renesas_rcar/renesas_kernel.git] / drivers / gpu / drm / nouveau / core / engine / software / nvc0.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/class.h>
27 #include <core/engctx.h>
28 #include <core/event.h>
29
30 #include <subdev/bar.h>
31
32 #include <engine/software.h>
33 #include <engine/disp.h>
34
35 struct nvc0_software_priv {
36         struct nouveau_software base;
37 };
38
39 struct nvc0_software_chan {
40         struct nouveau_software_chan base;
41 };
42
43 /*******************************************************************************
44  * software object classes
45  ******************************************************************************/
46
47 static int
48 nvc0_software_mthd_vblsem_offset(struct nouveau_object *object, u32 mthd,
49                                  void *args, u32 size)
50 {
51         struct nvc0_software_chan *chan = (void *)nv_engctx(object->parent);
52         u64 data = *(u32 *)args;
53         if (mthd == 0x0400) {
54                 chan->base.vblank.offset &= 0x00ffffffffULL;
55                 chan->base.vblank.offset |= data << 32;
56         } else {
57                 chan->base.vblank.offset &= 0xff00000000ULL;
58                 chan->base.vblank.offset |= data;
59         }
60         return 0;
61 }
62
63 static int
64 nvc0_software_mthd_vblsem_value(struct nouveau_object *object, u32 mthd,
65                                 void *args, u32 size)
66 {
67         struct nvc0_software_chan *chan = (void *)nv_engctx(object->parent);
68         chan->base.vblank.value = *(u32 *)args;
69         return 0;
70 }
71
72 static int
73 nvc0_software_mthd_vblsem_release(struct nouveau_object *object, u32 mthd,
74                                   void *args, u32 size)
75 {
76         struct nvc0_software_chan *chan = (void *)nv_engctx(object->parent);
77         struct nouveau_disp *disp = nouveau_disp(object);
78         u32 crtc = *(u32 *)args;
79
80         if ((nv_device(object)->card_type < NV_E0 && crtc > 1) || crtc > 3)
81                 return -EINVAL;
82
83         nouveau_event_get(disp->vblank, crtc, &chan->base.vblank.event);
84         return 0;
85 }
86
87 static int
88 nvc0_software_mthd_flip(struct nouveau_object *object, u32 mthd,
89                         void *args, u32 size)
90 {
91         struct nvc0_software_chan *chan = (void *)nv_engctx(object->parent);
92         if (chan->base.flip)
93                 return chan->base.flip(chan->base.flip_data);
94         return -EINVAL;
95 }
96
97 static int
98 nvc0_software_mthd_mp_control(struct nouveau_object *object, u32 mthd,
99                               void *args, u32 size)
100 {
101         struct nvc0_software_chan *chan = (void *)nv_engctx(object->parent);
102         struct nvc0_software_priv *priv = (void *)nv_object(chan)->engine;
103         u32 data = *(u32 *)args;
104
105         switch (mthd) {
106         case 0x600:
107                 nv_wr32(priv, 0x419e00, data); /* MP.PM_UNK000 */
108                 break;
109         case 0x644:
110                 if (data & ~0x1ffffe)
111                         return -EINVAL;
112                 nv_wr32(priv, 0x419e44, data); /* MP.TRAP_WARP_ERROR_EN */
113                 break;
114         case 0x6ac:
115                 nv_wr32(priv, 0x419eac, data); /* MP.PM_UNK0AC */
116                 break;
117         default:
118                 return -EINVAL;
119         }
120         return 0;
121 }
122
123 static struct nouveau_omthds
124 nvc0_software_omthds[] = {
125         { 0x0400, 0x0400, nvc0_software_mthd_vblsem_offset },
126         { 0x0404, 0x0404, nvc0_software_mthd_vblsem_offset },
127         { 0x0408, 0x0408, nvc0_software_mthd_vblsem_value },
128         { 0x040c, 0x040c, nvc0_software_mthd_vblsem_release },
129         { 0x0500, 0x0500, nvc0_software_mthd_flip },
130         { 0x0600, 0x0600, nvc0_software_mthd_mp_control },
131         { 0x0644, 0x0644, nvc0_software_mthd_mp_control },
132         { 0x06ac, 0x06ac, nvc0_software_mthd_mp_control },
133         {}
134 };
135
136 static struct nouveau_oclass
137 nvc0_software_sclass[] = {
138         { 0x906e, &nouveau_object_ofuncs, nvc0_software_omthds },
139         {}
140 };
141
142 /*******************************************************************************
143  * software context
144  ******************************************************************************/
145
146 static int
147 nvc0_software_vblsem_release(struct nouveau_eventh *event, int head)
148 {
149         struct nouveau_software_chan *chan =
150                 container_of(event, struct nouveau_software_chan, vblank.event);
151         struct nvc0_software_priv *priv = (void *)nv_object(chan)->engine;
152         struct nouveau_bar *bar = nouveau_bar(priv);
153
154         nv_wr32(priv, 0x001718, 0x80000000 | chan->vblank.channel);
155         bar->flush(bar);
156         nv_wr32(priv, 0x06000c, upper_32_bits(chan->vblank.offset));
157         nv_wr32(priv, 0x060010, lower_32_bits(chan->vblank.offset));
158         nv_wr32(priv, 0x060014, chan->vblank.value);
159
160         return NVKM_EVENT_DROP;
161 }
162
163 static int
164 nvc0_software_context_ctor(struct nouveau_object *parent,
165                            struct nouveau_object *engine,
166                            struct nouveau_oclass *oclass, void *data, u32 size,
167                            struct nouveau_object **pobject)
168 {
169         struct nvc0_software_chan *chan;
170         int ret;
171
172         ret = nouveau_software_context_create(parent, engine, oclass, &chan);
173         *pobject = nv_object(chan);
174         if (ret)
175                 return ret;
176
177         chan->base.vblank.channel = nv_gpuobj(parent->parent)->addr >> 12;
178         chan->base.vblank.event.func = nvc0_software_vblsem_release;
179         return 0;
180 }
181
182 static struct nouveau_oclass
183 nvc0_software_cclass = {
184         .handle = NV_ENGCTX(SW, 0xc0),
185         .ofuncs = &(struct nouveau_ofuncs) {
186                 .ctor = nvc0_software_context_ctor,
187                 .dtor = _nouveau_software_context_dtor,
188                 .init = _nouveau_software_context_init,
189                 .fini = _nouveau_software_context_fini,
190         },
191 };
192
193 /*******************************************************************************
194  * software engine/subdev functions
195  ******************************************************************************/
196
197 static int
198 nvc0_software_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
199                    struct nouveau_oclass *oclass, void *data, u32 size,
200                    struct nouveau_object **pobject)
201 {
202         struct nvc0_software_priv *priv;
203         int ret;
204
205         ret = nouveau_software_create(parent, engine, oclass, &priv);
206         *pobject = nv_object(priv);
207         if (ret)
208                 return ret;
209
210         nv_engine(priv)->cclass = &nvc0_software_cclass;
211         nv_engine(priv)->sclass = nvc0_software_sclass;
212         nv_subdev(priv)->intr = nv04_software_intr;
213         return 0;
214 }
215
216 struct nouveau_oclass
217 nvc0_software_oclass = {
218         .handle = NV_ENGINE(SW, 0xc0),
219         .ofuncs = &(struct nouveau_ofuncs) {
220                 .ctor = nvc0_software_ctor,
221                 .dtor = _nouveau_software_dtor,
222                 .init = _nouveau_software_init,
223                 .fini = _nouveau_software_fini,
224         },
225 };