blob: f5a8db1bb8b7271c0407460b835e328807771af1 [file] [log] [blame]
Ben Skeggs2a7909c2015-08-20 14:54:19 +10001/*
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 "channv50.h"
25#include "rootnv50.h"
26
Ben Skeggs0ce41e32015-08-20 14:54:19 +100027#include <core/client.h>
28#include <core/ramht.h>
29#include <engine/dma.h>
30
Ben Skeggs7568b102015-11-08 10:44:19 +100031#include <nvif/cl507d.h>
Ben Skeggs2a7909c2015-08-20 14:54:19 +100032#include <nvif/event.h>
33#include <nvif/unpack.h>
34
35static void
36nv50_disp_mthd_list(struct nv50_disp *disp, int debug, u32 base, int c,
37 const struct nv50_disp_mthd_list *list, int inst)
38{
39 struct nvkm_subdev *subdev = &disp->base.engine.subdev;
40 struct nvkm_device *device = subdev->device;
41 int i;
42
43 for (i = 0; list->data[i].mthd; i++) {
44 if (list->data[i].addr) {
45 u32 next = nvkm_rd32(device, list->data[i].addr + base + 0);
46 u32 prev = nvkm_rd32(device, list->data[i].addr + base + c);
47 u32 mthd = list->data[i].mthd + (list->mthd * inst);
48 const char *name = list->data[i].name;
49 char mods[16];
50
51 if (prev != next)
52 snprintf(mods, sizeof(mods), "-> %08x", next);
53 else
54 snprintf(mods, sizeof(mods), "%13c", ' ');
55
56 nvkm_printk_(subdev, debug, info,
57 "\t%04x: %08x %s%s%s\n",
58 mthd, prev, mods, name ? " // " : "",
59 name ? name : "");
60 }
61 }
62}
63
64void
Ben Skeggs0ce41e32015-08-20 14:54:19 +100065nv50_disp_chan_mthd(struct nv50_disp_chan *chan, int debug)
Ben Skeggs2a7909c2015-08-20 14:54:19 +100066{
Ben Skeggs0ce41e32015-08-20 14:54:19 +100067 struct nv50_disp *disp = chan->root->disp;
Ben Skeggs2a7909c2015-08-20 14:54:19 +100068 struct nvkm_subdev *subdev = &disp->base.engine.subdev;
Ben Skeggs0ce41e32015-08-20 14:54:19 +100069 const struct nv50_disp_chan_mthd *mthd = chan->mthd;
70 const struct nv50_disp_mthd_list *list;
Ben Skeggs2a7909c2015-08-20 14:54:19 +100071 int i, j;
72
Ben Skeggs0ce41e32015-08-20 14:54:19 +100073 if (debug > subdev->debug)
Ben Skeggs2a7909c2015-08-20 14:54:19 +100074 return;
Ben Skeggs25b357f2020-01-28 14:39:26 +100075 if (!mthd)
76 return;
Ben Skeggs2a7909c2015-08-20 14:54:19 +100077
Ben Skeggs0ce41e32015-08-20 14:54:19 +100078 for (i = 0; (list = mthd->data[i].mthd) != NULL; i++) {
79 u32 base = chan->head * mthd->addr;
80 for (j = 0; j < mthd->data[i].nr; j++, base += list->addr) {
81 const char *cname = mthd->name;
Ben Skeggs2a7909c2015-08-20 14:54:19 +100082 const char *sname = "";
83 char cname_[16], sname_[16];
84
Ben Skeggs0ce41e32015-08-20 14:54:19 +100085 if (mthd->addr) {
Ben Skeggs2a7909c2015-08-20 14:54:19 +100086 snprintf(cname_, sizeof(cname_), "%s %d",
Ben Skeggs50017562017-03-17 00:48:29 +000087 mthd->name, chan->chid.user);
Ben Skeggs2a7909c2015-08-20 14:54:19 +100088 cname = cname_;
89 }
90
Ben Skeggs0ce41e32015-08-20 14:54:19 +100091 if (mthd->data[i].nr > 1) {
Ben Skeggs2a7909c2015-08-20 14:54:19 +100092 snprintf(sname_, sizeof(sname_), " - %s %d",
Ben Skeggs0ce41e32015-08-20 14:54:19 +100093 mthd->data[i].name, j);
Ben Skeggs2a7909c2015-08-20 14:54:19 +100094 sname = sname_;
95 }
96
97 nvkm_printk_(subdev, debug, info, "%s%s:\n", cname, sname);
Ben Skeggs0ce41e32015-08-20 14:54:19 +100098 nv50_disp_mthd_list(disp, debug, base, mthd->prev,
Ben Skeggs2a7909c2015-08-20 14:54:19 +100099 list, j);
100 }
101 }
102}
103
104static void
105nv50_disp_chan_uevent_fini(struct nvkm_event *event, int type, int index)
106{
107 struct nv50_disp *disp = container_of(event, typeof(*disp), uevent);
108 struct nvkm_device *device = disp->base.engine.subdev.device;
109 nvkm_mask(device, 0x610028, 0x00000001 << index, 0x00000000 << index);
110 nvkm_wr32(device, 0x610020, 0x00000001 << index);
111}
112
113static void
114nv50_disp_chan_uevent_init(struct nvkm_event *event, int types, int index)
115{
116 struct nv50_disp *disp = container_of(event, typeof(*disp), uevent);
117 struct nvkm_device *device = disp->base.engine.subdev.device;
118 nvkm_wr32(device, 0x610020, 0x00000001 << index);
119 nvkm_mask(device, 0x610028, 0x00000001 << index, 0x00000001 << index);
120}
121
122void
123nv50_disp_chan_uevent_send(struct nv50_disp *disp, int chid)
124{
125 struct nvif_notify_uevent_rep {
126 } rep;
127
128 nvkm_event_send(&disp->uevent, 1, chid, &rep, sizeof(rep));
129}
130
131int
132nv50_disp_chan_uevent_ctor(struct nvkm_object *object, void *data, u32 size,
133 struct nvkm_notify *notify)
134{
Ben Skeggs0ce41e32015-08-20 14:54:19 +1000135 struct nv50_disp_chan *chan = nv50_disp_chan(object);
Ben Skeggs2a7909c2015-08-20 14:54:19 +1000136 union {
137 struct nvif_notify_uevent_req none;
138 } *args = data;
Ben Skeggsf01c4e62015-11-09 09:21:27 +1000139 int ret = -ENOSYS;
Ben Skeggs2a7909c2015-08-20 14:54:19 +1000140
Ben Skeggsf01c4e62015-11-09 09:21:27 +1000141 if (!(ret = nvif_unvers(ret, &data, &size, args->none))) {
Ben Skeggs2a7909c2015-08-20 14:54:19 +1000142 notify->size = sizeof(struct nvif_notify_uevent_rep);
143 notify->types = 1;
Ben Skeggs50017562017-03-17 00:48:29 +0000144 notify->index = chan->chid.user;
Ben Skeggs2a7909c2015-08-20 14:54:19 +1000145 return 0;
146 }
147
148 return ret;
149}
150
151const struct nvkm_event_func
152nv50_disp_chan_uevent = {
153 .ctor = nv50_disp_chan_uevent_ctor,
154 .init = nv50_disp_chan_uevent_init,
155 .fini = nv50_disp_chan_uevent_fini,
156};
157
158int
Ben Skeggs0ce41e32015-08-20 14:54:19 +1000159nv50_disp_chan_rd32(struct nvkm_object *object, u64 addr, u32 *data)
160{
161 struct nv50_disp_chan *chan = nv50_disp_chan(object);
162 struct nv50_disp *disp = chan->root->disp;
163 struct nvkm_device *device = disp->base.engine.subdev.device;
Ben Skeggs50017562017-03-17 00:48:29 +0000164 *data = nvkm_rd32(device, 0x640000 + (chan->chid.user * 0x1000) + addr);
Ben Skeggs0ce41e32015-08-20 14:54:19 +1000165 return 0;
166}
167
168int
169nv50_disp_chan_wr32(struct nvkm_object *object, u64 addr, u32 data)
170{
171 struct nv50_disp_chan *chan = nv50_disp_chan(object);
172 struct nv50_disp *disp = chan->root->disp;
173 struct nvkm_device *device = disp->base.engine.subdev.device;
Ben Skeggs50017562017-03-17 00:48:29 +0000174 nvkm_wr32(device, 0x640000 + (chan->chid.user * 0x1000) + addr, data);
Ben Skeggs0ce41e32015-08-20 14:54:19 +1000175 return 0;
176}
177
178int
Ben Skeggs2a7909c2015-08-20 14:54:19 +1000179nv50_disp_chan_ntfy(struct nvkm_object *object, u32 type,
180 struct nvkm_event **pevent)
181{
Ben Skeggs0ce41e32015-08-20 14:54:19 +1000182 struct nv50_disp_chan *chan = nv50_disp_chan(object);
183 struct nv50_disp *disp = chan->root->disp;
Ben Skeggs2a7909c2015-08-20 14:54:19 +1000184 switch (type) {
185 case NV50_DISP_CORE_CHANNEL_DMA_V0_NTFY_UEVENT:
186 *pevent = &disp->uevent;
187 return 0;
188 default:
189 break;
190 }
191 return -EINVAL;
192}
193
194int
195nv50_disp_chan_map(struct nvkm_object *object, u64 *addr, u32 *size)
196{
Ben Skeggs0ce41e32015-08-20 14:54:19 +1000197 struct nv50_disp_chan *chan = nv50_disp_chan(object);
198 struct nv50_disp *disp = chan->root->disp;
199 struct nvkm_device *device = disp->base.engine.subdev.device;
Ben Skeggs7e8820f2015-08-20 14:54:23 +1000200 *addr = device->func->resource_addr(device, 0) +
Ben Skeggs50017562017-03-17 00:48:29 +0000201 0x640000 + (chan->chid.user * 0x1000);
Ben Skeggs2a7909c2015-08-20 14:54:19 +1000202 *size = 0x001000;
203 return 0;
204}
205
Ben Skeggs0ce41e32015-08-20 14:54:19 +1000206static int
207nv50_disp_chan_child_new(const struct nvkm_oclass *oclass,
208 void *data, u32 size, struct nvkm_object **pobject)
Ben Skeggs2a7909c2015-08-20 14:54:19 +1000209{
Ben Skeggs0ce41e32015-08-20 14:54:19 +1000210 struct nv50_disp_chan *chan = nv50_disp_chan(oclass->parent);
211 return chan->func->child_new(chan, oclass, data, size, pobject);
Ben Skeggs2a7909c2015-08-20 14:54:19 +1000212}
213
Ben Skeggs0ce41e32015-08-20 14:54:19 +1000214static int
215nv50_disp_chan_child_get(struct nvkm_object *object, int index,
216 struct nvkm_oclass *oclass)
Ben Skeggs2a7909c2015-08-20 14:54:19 +1000217{
Ben Skeggs0ce41e32015-08-20 14:54:19 +1000218 struct nv50_disp_chan *chan = nv50_disp_chan(object);
219 if (chan->func->child_get) {
220 int ret = chan->func->child_get(chan, index, oclass);
221 if (ret == 0)
222 oclass->ctor = nv50_disp_chan_child_new;
223 return ret;
224 }
225 return -EINVAL;
Ben Skeggs2a7909c2015-08-20 14:54:19 +1000226}
227
Ben Skeggs0ce41e32015-08-20 14:54:19 +1000228static int
229nv50_disp_chan_fini(struct nvkm_object *object, bool suspend)
Ben Skeggs2a7909c2015-08-20 14:54:19 +1000230{
Ben Skeggs0ce41e32015-08-20 14:54:19 +1000231 struct nv50_disp_chan *chan = nv50_disp_chan(object);
232 chan->func->fini(chan);
233 return 0;
234}
235
236static int
237nv50_disp_chan_init(struct nvkm_object *object)
238{
239 struct nv50_disp_chan *chan = nv50_disp_chan(object);
240 return chan->func->init(chan);
241}
242
243static void *
244nv50_disp_chan_dtor(struct nvkm_object *object)
245{
246 struct nv50_disp_chan *chan = nv50_disp_chan(object);
247 struct nv50_disp *disp = chan->root->disp;
Ben Skeggs50017562017-03-17 00:48:29 +0000248 if (chan->chid.user >= 0)
249 disp->chan[chan->chid.user] = NULL;
Ben Skeggs0ce41e32015-08-20 14:54:19 +1000250 return chan->func->dtor ? chan->func->dtor(chan) : chan;
251}
252
253static const struct nvkm_object_func
254nv50_disp_chan = {
255 .dtor = nv50_disp_chan_dtor,
256 .init = nv50_disp_chan_init,
257 .fini = nv50_disp_chan_fini,
258 .rd32 = nv50_disp_chan_rd32,
259 .wr32 = nv50_disp_chan_wr32,
260 .ntfy = nv50_disp_chan_ntfy,
261 .map = nv50_disp_chan_map,
262 .sclass = nv50_disp_chan_child_get,
263};
264
265int
266nv50_disp_chan_ctor(const struct nv50_disp_chan_func *func,
267 const struct nv50_disp_chan_mthd *mthd,
Ben Skeggs0042afe2017-03-17 00:48:30 +0000268 struct nv50_disp_root *root, int ctrl, int user, int head,
Ben Skeggs0ce41e32015-08-20 14:54:19 +1000269 const struct nvkm_oclass *oclass,
270 struct nv50_disp_chan *chan)
271{
272 struct nv50_disp *disp = root->disp;
273
274 nvkm_object_ctor(&nv50_disp_chan, oclass, &chan->object);
275 chan->func = func;
276 chan->mthd = mthd;
277 chan->root = root;
Ben Skeggs0042afe2017-03-17 00:48:30 +0000278 chan->chid.ctrl = ctrl;
279 chan->chid.user = user;
Ben Skeggs0ce41e32015-08-20 14:54:19 +1000280 chan->head = head;
281
Ben Skeggs50017562017-03-17 00:48:29 +0000282 if (disp->chan[chan->chid.user]) {
283 chan->chid.user = -1;
Ben Skeggs0ce41e32015-08-20 14:54:19 +1000284 return -EBUSY;
285 }
Ben Skeggs50017562017-03-17 00:48:29 +0000286 disp->chan[chan->chid.user] = chan;
Ben Skeggs0ce41e32015-08-20 14:54:19 +1000287 return 0;
Ben Skeggs2a7909c2015-08-20 14:54:19 +1000288}
289
290int
Ben Skeggs0ce41e32015-08-20 14:54:19 +1000291nv50_disp_chan_new_(const struct nv50_disp_chan_func *func,
292 const struct nv50_disp_chan_mthd *mthd,
Ben Skeggs0042afe2017-03-17 00:48:30 +0000293 struct nv50_disp_root *root, int ctrl, int user, int head,
Ben Skeggs0ce41e32015-08-20 14:54:19 +1000294 const struct nvkm_oclass *oclass,
295 struct nvkm_object **pobject)
Ben Skeggs2a7909c2015-08-20 14:54:19 +1000296{
Ben Skeggs2a7909c2015-08-20 14:54:19 +1000297 struct nv50_disp_chan *chan;
Ben Skeggs2a7909c2015-08-20 14:54:19 +1000298
Ben Skeggs0ce41e32015-08-20 14:54:19 +1000299 if (!(chan = kzalloc(sizeof(*chan), GFP_KERNEL)))
300 return -ENOMEM;
301 *pobject = &chan->object;
Ben Skeggs2a7909c2015-08-20 14:54:19 +1000302
Ben Skeggs0042afe2017-03-17 00:48:30 +0000303 return nv50_disp_chan_ctor(func, mthd, root, ctrl, user,
304 head, oclass, chan);
Ben Skeggs2a7909c2015-08-20 14:54:19 +1000305}