2 * Copyright 2012 Red Hat Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
27 #include <nvif/class.h>
28 #include <nvif/event.h>
29 #include <nvif/unpack.h>
32 nv50_disp_mthd_list(struct nv50_disp *disp, int debug, u32 base, int c,
33 const struct nv50_disp_mthd_list *list, int inst)
35 struct nvkm_subdev *subdev = &disp->base.engine.subdev;
36 struct nvkm_device *device = subdev->device;
39 for (i = 0; list->data[i].mthd; i++) {
40 if (list->data[i].addr) {
41 u32 next = nvkm_rd32(device, list->data[i].addr + base + 0);
42 u32 prev = nvkm_rd32(device, list->data[i].addr + base + c);
43 u32 mthd = list->data[i].mthd + (list->mthd * inst);
44 const char *name = list->data[i].name;
48 snprintf(mods, sizeof(mods), "-> %08x", next);
50 snprintf(mods, sizeof(mods), "%13c", ' ');
52 nvkm_printk_(subdev, debug, info,
53 "\t%04x: %08x %s%s%s\n",
54 mthd, prev, mods, name ? " // " : "",
61 nv50_disp_mthd_chan(struct nv50_disp *disp, int debug, int head,
62 const struct nv50_disp_mthd_chan *chan)
64 struct nvkm_object *object = nv_object(disp);
65 const struct nv50_disp_impl *impl = (void *)object->oclass;
66 const struct nv50_disp_mthd_list *list;
67 struct nvkm_subdev *subdev = &disp->base.engine.subdev;
70 if (debug > nv_subdev(disp)->debug)
73 for (i = 0; (list = chan->data[i].mthd) != NULL; i++) {
74 u32 base = head * chan->addr;
75 for (j = 0; j < chan->data[i].nr; j++, base += list->addr) {
76 const char *cname = chan->name;
77 const char *sname = "";
78 char cname_[16], sname_[16];
81 snprintf(cname_, sizeof(cname_), "%s %d",
86 if (chan->data[i].nr > 1) {
87 snprintf(sname_, sizeof(sname_), " - %s %d",
88 chan->data[i].name, j);
92 nvkm_printk_(subdev, debug, info, "%s%s:\n", cname, sname);
93 nv50_disp_mthd_list(disp, debug, base, impl->mthd.prev,
100 nv50_disp_chan_uevent_fini(struct nvkm_event *event, int type, int index)
102 struct nv50_disp *disp = container_of(event, typeof(*disp), uevent);
103 struct nvkm_device *device = disp->base.engine.subdev.device;
104 nvkm_mask(device, 0x610028, 0x00000001 << index, 0x00000000 << index);
105 nvkm_wr32(device, 0x610020, 0x00000001 << index);
109 nv50_disp_chan_uevent_init(struct nvkm_event *event, int types, int index)
111 struct nv50_disp *disp = container_of(event, typeof(*disp), uevent);
112 struct nvkm_device *device = disp->base.engine.subdev.device;
113 nvkm_wr32(device, 0x610020, 0x00000001 << index);
114 nvkm_mask(device, 0x610028, 0x00000001 << index, 0x00000001 << index);
118 nv50_disp_chan_uevent_send(struct nv50_disp *disp, int chid)
120 struct nvif_notify_uevent_rep {
123 nvkm_event_send(&disp->uevent, 1, chid, &rep, sizeof(rep));
127 nv50_disp_chan_uevent_ctor(struct nvkm_object *object, void *data, u32 size,
128 struct nvkm_notify *notify)
130 struct nv50_disp_dmac *dmac = (void *)object;
132 struct nvif_notify_uevent_req none;
136 if (nvif_unvers(args->none)) {
137 notify->size = sizeof(struct nvif_notify_uevent_rep);
139 notify->index = dmac->base.chid;
146 const struct nvkm_event_func
147 nv50_disp_chan_uevent = {
148 .ctor = nv50_disp_chan_uevent_ctor,
149 .init = nv50_disp_chan_uevent_init,
150 .fini = nv50_disp_chan_uevent_fini,
154 nv50_disp_chan_ntfy(struct nvkm_object *object, u32 type,
155 struct nvkm_event **pevent)
157 struct nv50_disp *disp = (void *)object->engine;
159 case NV50_DISP_CORE_CHANNEL_DMA_V0_NTFY_UEVENT:
160 *pevent = &disp->uevent;
169 nv50_disp_chan_map(struct nvkm_object *object, u64 *addr, u32 *size)
171 struct nv50_disp_chan *chan = (void *)object;
172 *addr = nv_device_resource_start(nv_device(object), 0) +
173 0x640000 + (chan->chid * 0x1000);
179 nv50_disp_chan_rd32(struct nvkm_object *object, u64 addr)
181 struct nv50_disp_chan *chan = (void *)object;
182 struct nvkm_device *device = object->engine->subdev.device;
183 return nvkm_rd32(device, 0x640000 + (chan->chid * 0x1000) + addr);
187 nv50_disp_chan_wr32(struct nvkm_object *object, u64 addr, u32 data)
189 struct nv50_disp_chan *chan = (void *)object;
190 struct nvkm_device *device = object->engine->subdev.device;
191 nvkm_wr32(device, 0x640000 + (chan->chid * 0x1000) + addr, data);
195 nv50_disp_chan_destroy(struct nv50_disp_chan *chan)
197 struct nv50_disp_root *root = (void *)nv_object(chan)->parent;
198 root->chan &= ~(1 << chan->chid);
199 nvkm_namedb_destroy(&chan->base);
203 nv50_disp_chan_create_(struct nvkm_object *parent,
204 struct nvkm_object *engine,
205 struct nvkm_oclass *oclass, int head,
206 int length, void **pobject)
208 const struct nv50_disp_chan_impl *impl = (void *)oclass->ofuncs;
209 struct nv50_disp_root *root = (void *)parent;
210 struct nv50_disp_chan *chan;
211 int chid = impl->chid + head;
214 if (root->chan & (1 << chid))
216 root->chan |= (1 << chid);
218 ret = nvkm_namedb_create_(parent, engine, oclass, 0, NULL,
219 (1ULL << NVDEV_ENGINE_DMAOBJ),
226 nv_parent(chan)->object_attach = impl->attach;
227 nv_parent(chan)->object_detach = impl->detach;