Ben Skeggs | 2a7909c | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 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 | #include "channv50.h" |
| 25 | #include "rootnv50.h" |
| 26 | |
Ben Skeggs | 0ce41e3 | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 27 | #include <core/client.h> |
| 28 | #include <core/ramht.h> |
| 29 | #include <engine/dma.h> |
| 30 | |
Ben Skeggs | 7568b10 | 2015-11-08 10:44:19 +1000 | [diff] [blame] | 31 | #include <nvif/cl507d.h> |
Ben Skeggs | 2a7909c | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 32 | #include <nvif/event.h> |
| 33 | #include <nvif/unpack.h> |
| 34 | |
| 35 | static void |
| 36 | nv50_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 | |
| 64 | void |
Ben Skeggs | 0ce41e3 | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 65 | nv50_disp_chan_mthd(struct nv50_disp_chan *chan, int debug) |
Ben Skeggs | 2a7909c | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 66 | { |
Ben Skeggs | 0ce41e3 | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 67 | struct nv50_disp *disp = chan->root->disp; |
Ben Skeggs | 2a7909c | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 68 | struct nvkm_subdev *subdev = &disp->base.engine.subdev; |
Ben Skeggs | 0ce41e3 | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 69 | const struct nv50_disp_chan_mthd *mthd = chan->mthd; |
| 70 | const struct nv50_disp_mthd_list *list; |
Ben Skeggs | 2a7909c | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 71 | int i, j; |
| 72 | |
Ben Skeggs | 0ce41e3 | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 73 | if (debug > subdev->debug) |
Ben Skeggs | 2a7909c | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 74 | return; |
| 75 | |
Ben Skeggs | 0ce41e3 | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 76 | for (i = 0; (list = mthd->data[i].mthd) != NULL; i++) { |
| 77 | u32 base = chan->head * mthd->addr; |
| 78 | for (j = 0; j < mthd->data[i].nr; j++, base += list->addr) { |
| 79 | const char *cname = mthd->name; |
Ben Skeggs | 2a7909c | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 80 | const char *sname = ""; |
| 81 | char cname_[16], sname_[16]; |
| 82 | |
Ben Skeggs | 0ce41e3 | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 83 | if (mthd->addr) { |
Ben Skeggs | 2a7909c | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 84 | snprintf(cname_, sizeof(cname_), "%s %d", |
Ben Skeggs | 5001756 | 2017-03-17 00:48:29 +0000 | [diff] [blame] | 85 | mthd->name, chan->chid.user); |
Ben Skeggs | 2a7909c | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 86 | cname = cname_; |
| 87 | } |
| 88 | |
Ben Skeggs | 0ce41e3 | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 89 | if (mthd->data[i].nr > 1) { |
Ben Skeggs | 2a7909c | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 90 | snprintf(sname_, sizeof(sname_), " - %s %d", |
Ben Skeggs | 0ce41e3 | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 91 | mthd->data[i].name, j); |
Ben Skeggs | 2a7909c | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 92 | sname = sname_; |
| 93 | } |
| 94 | |
| 95 | nvkm_printk_(subdev, debug, info, "%s%s:\n", cname, sname); |
Ben Skeggs | 0ce41e3 | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 96 | nv50_disp_mthd_list(disp, debug, base, mthd->prev, |
Ben Skeggs | 2a7909c | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 97 | list, j); |
| 98 | } |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | static void |
| 103 | nv50_disp_chan_uevent_fini(struct nvkm_event *event, int type, int index) |
| 104 | { |
| 105 | struct nv50_disp *disp = container_of(event, typeof(*disp), uevent); |
| 106 | struct nvkm_device *device = disp->base.engine.subdev.device; |
| 107 | nvkm_mask(device, 0x610028, 0x00000001 << index, 0x00000000 << index); |
| 108 | nvkm_wr32(device, 0x610020, 0x00000001 << index); |
| 109 | } |
| 110 | |
| 111 | static void |
| 112 | nv50_disp_chan_uevent_init(struct nvkm_event *event, int types, int index) |
| 113 | { |
| 114 | struct nv50_disp *disp = container_of(event, typeof(*disp), uevent); |
| 115 | struct nvkm_device *device = disp->base.engine.subdev.device; |
| 116 | nvkm_wr32(device, 0x610020, 0x00000001 << index); |
| 117 | nvkm_mask(device, 0x610028, 0x00000001 << index, 0x00000001 << index); |
| 118 | } |
| 119 | |
| 120 | void |
| 121 | nv50_disp_chan_uevent_send(struct nv50_disp *disp, int chid) |
| 122 | { |
| 123 | struct nvif_notify_uevent_rep { |
| 124 | } rep; |
| 125 | |
| 126 | nvkm_event_send(&disp->uevent, 1, chid, &rep, sizeof(rep)); |
| 127 | } |
| 128 | |
| 129 | int |
| 130 | nv50_disp_chan_uevent_ctor(struct nvkm_object *object, void *data, u32 size, |
| 131 | struct nvkm_notify *notify) |
| 132 | { |
Ben Skeggs | 0ce41e3 | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 133 | struct nv50_disp_chan *chan = nv50_disp_chan(object); |
Ben Skeggs | 2a7909c | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 134 | union { |
| 135 | struct nvif_notify_uevent_req none; |
| 136 | } *args = data; |
Ben Skeggs | f01c4e6 | 2015-11-09 09:21:27 +1000 | [diff] [blame] | 137 | int ret = -ENOSYS; |
Ben Skeggs | 2a7909c | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 138 | |
Ben Skeggs | f01c4e6 | 2015-11-09 09:21:27 +1000 | [diff] [blame] | 139 | if (!(ret = nvif_unvers(ret, &data, &size, args->none))) { |
Ben Skeggs | 2a7909c | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 140 | notify->size = sizeof(struct nvif_notify_uevent_rep); |
| 141 | notify->types = 1; |
Ben Skeggs | 5001756 | 2017-03-17 00:48:29 +0000 | [diff] [blame] | 142 | notify->index = chan->chid.user; |
Ben Skeggs | 2a7909c | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 143 | return 0; |
| 144 | } |
| 145 | |
| 146 | return ret; |
| 147 | } |
| 148 | |
| 149 | const struct nvkm_event_func |
| 150 | nv50_disp_chan_uevent = { |
| 151 | .ctor = nv50_disp_chan_uevent_ctor, |
| 152 | .init = nv50_disp_chan_uevent_init, |
| 153 | .fini = nv50_disp_chan_uevent_fini, |
| 154 | }; |
| 155 | |
| 156 | int |
Ben Skeggs | 0ce41e3 | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 157 | nv50_disp_chan_rd32(struct nvkm_object *object, u64 addr, u32 *data) |
| 158 | { |
| 159 | struct nv50_disp_chan *chan = nv50_disp_chan(object); |
| 160 | struct nv50_disp *disp = chan->root->disp; |
| 161 | struct nvkm_device *device = disp->base.engine.subdev.device; |
Ben Skeggs | 5001756 | 2017-03-17 00:48:29 +0000 | [diff] [blame] | 162 | *data = nvkm_rd32(device, 0x640000 + (chan->chid.user * 0x1000) + addr); |
Ben Skeggs | 0ce41e3 | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 163 | return 0; |
| 164 | } |
| 165 | |
| 166 | int |
| 167 | nv50_disp_chan_wr32(struct nvkm_object *object, u64 addr, u32 data) |
| 168 | { |
| 169 | struct nv50_disp_chan *chan = nv50_disp_chan(object); |
| 170 | struct nv50_disp *disp = chan->root->disp; |
| 171 | struct nvkm_device *device = disp->base.engine.subdev.device; |
Ben Skeggs | 5001756 | 2017-03-17 00:48:29 +0000 | [diff] [blame] | 172 | nvkm_wr32(device, 0x640000 + (chan->chid.user * 0x1000) + addr, data); |
Ben Skeggs | 0ce41e3 | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 173 | return 0; |
| 174 | } |
| 175 | |
| 176 | int |
Ben Skeggs | 2a7909c | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 177 | nv50_disp_chan_ntfy(struct nvkm_object *object, u32 type, |
| 178 | struct nvkm_event **pevent) |
| 179 | { |
Ben Skeggs | 0ce41e3 | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 180 | struct nv50_disp_chan *chan = nv50_disp_chan(object); |
| 181 | struct nv50_disp *disp = chan->root->disp; |
Ben Skeggs | 2a7909c | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 182 | switch (type) { |
| 183 | case NV50_DISP_CORE_CHANNEL_DMA_V0_NTFY_UEVENT: |
| 184 | *pevent = &disp->uevent; |
| 185 | return 0; |
| 186 | default: |
| 187 | break; |
| 188 | } |
| 189 | return -EINVAL; |
| 190 | } |
| 191 | |
| 192 | int |
| 193 | nv50_disp_chan_map(struct nvkm_object *object, u64 *addr, u32 *size) |
| 194 | { |
Ben Skeggs | 0ce41e3 | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 195 | struct nv50_disp_chan *chan = nv50_disp_chan(object); |
| 196 | struct nv50_disp *disp = chan->root->disp; |
| 197 | struct nvkm_device *device = disp->base.engine.subdev.device; |
Ben Skeggs | 7e8820f | 2015-08-20 14:54:23 +1000 | [diff] [blame] | 198 | *addr = device->func->resource_addr(device, 0) + |
Ben Skeggs | 5001756 | 2017-03-17 00:48:29 +0000 | [diff] [blame] | 199 | 0x640000 + (chan->chid.user * 0x1000); |
Ben Skeggs | 2a7909c | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 200 | *size = 0x001000; |
| 201 | return 0; |
| 202 | } |
| 203 | |
Ben Skeggs | 0ce41e3 | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 204 | static int |
| 205 | nv50_disp_chan_child_new(const struct nvkm_oclass *oclass, |
| 206 | void *data, u32 size, struct nvkm_object **pobject) |
Ben Skeggs | 2a7909c | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 207 | { |
Ben Skeggs | 0ce41e3 | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 208 | struct nv50_disp_chan *chan = nv50_disp_chan(oclass->parent); |
| 209 | return chan->func->child_new(chan, oclass, data, size, pobject); |
Ben Skeggs | 2a7909c | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 210 | } |
| 211 | |
Ben Skeggs | 0ce41e3 | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 212 | static int |
| 213 | nv50_disp_chan_child_get(struct nvkm_object *object, int index, |
| 214 | struct nvkm_oclass *oclass) |
Ben Skeggs | 2a7909c | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 215 | { |
Ben Skeggs | 0ce41e3 | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 216 | struct nv50_disp_chan *chan = nv50_disp_chan(object); |
| 217 | if (chan->func->child_get) { |
| 218 | int ret = chan->func->child_get(chan, index, oclass); |
| 219 | if (ret == 0) |
| 220 | oclass->ctor = nv50_disp_chan_child_new; |
| 221 | return ret; |
| 222 | } |
| 223 | return -EINVAL; |
Ben Skeggs | 2a7909c | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 224 | } |
| 225 | |
Ben Skeggs | 0ce41e3 | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 226 | static int |
| 227 | nv50_disp_chan_fini(struct nvkm_object *object, bool suspend) |
Ben Skeggs | 2a7909c | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 228 | { |
Ben Skeggs | 0ce41e3 | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 229 | struct nv50_disp_chan *chan = nv50_disp_chan(object); |
| 230 | chan->func->fini(chan); |
| 231 | return 0; |
| 232 | } |
| 233 | |
| 234 | static int |
| 235 | nv50_disp_chan_init(struct nvkm_object *object) |
| 236 | { |
| 237 | struct nv50_disp_chan *chan = nv50_disp_chan(object); |
| 238 | return chan->func->init(chan); |
| 239 | } |
| 240 | |
| 241 | static void * |
| 242 | nv50_disp_chan_dtor(struct nvkm_object *object) |
| 243 | { |
| 244 | struct nv50_disp_chan *chan = nv50_disp_chan(object); |
| 245 | struct nv50_disp *disp = chan->root->disp; |
Ben Skeggs | 5001756 | 2017-03-17 00:48:29 +0000 | [diff] [blame] | 246 | if (chan->chid.user >= 0) |
| 247 | disp->chan[chan->chid.user] = NULL; |
Ben Skeggs | 0ce41e3 | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 248 | return chan->func->dtor ? chan->func->dtor(chan) : chan; |
| 249 | } |
| 250 | |
| 251 | static const struct nvkm_object_func |
| 252 | nv50_disp_chan = { |
| 253 | .dtor = nv50_disp_chan_dtor, |
| 254 | .init = nv50_disp_chan_init, |
| 255 | .fini = nv50_disp_chan_fini, |
| 256 | .rd32 = nv50_disp_chan_rd32, |
| 257 | .wr32 = nv50_disp_chan_wr32, |
| 258 | .ntfy = nv50_disp_chan_ntfy, |
| 259 | .map = nv50_disp_chan_map, |
| 260 | .sclass = nv50_disp_chan_child_get, |
| 261 | }; |
| 262 | |
| 263 | int |
| 264 | nv50_disp_chan_ctor(const struct nv50_disp_chan_func *func, |
| 265 | const struct nv50_disp_chan_mthd *mthd, |
Ben Skeggs | 0042afe | 2017-03-17 00:48:30 +0000 | [diff] [blame] | 266 | struct nv50_disp_root *root, int ctrl, int user, int head, |
Ben Skeggs | 0ce41e3 | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 267 | const struct nvkm_oclass *oclass, |
| 268 | struct nv50_disp_chan *chan) |
| 269 | { |
| 270 | struct nv50_disp *disp = root->disp; |
| 271 | |
| 272 | nvkm_object_ctor(&nv50_disp_chan, oclass, &chan->object); |
| 273 | chan->func = func; |
| 274 | chan->mthd = mthd; |
| 275 | chan->root = root; |
Ben Skeggs | 0042afe | 2017-03-17 00:48:30 +0000 | [diff] [blame] | 276 | chan->chid.ctrl = ctrl; |
| 277 | chan->chid.user = user; |
Ben Skeggs | 0ce41e3 | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 278 | chan->head = head; |
| 279 | |
Ben Skeggs | 5001756 | 2017-03-17 00:48:29 +0000 | [diff] [blame] | 280 | if (disp->chan[chan->chid.user]) { |
| 281 | chan->chid.user = -1; |
Ben Skeggs | 0ce41e3 | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 282 | return -EBUSY; |
| 283 | } |
Ben Skeggs | 5001756 | 2017-03-17 00:48:29 +0000 | [diff] [blame] | 284 | disp->chan[chan->chid.user] = chan; |
Ben Skeggs | 0ce41e3 | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 285 | return 0; |
Ben Skeggs | 2a7909c | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | int |
Ben Skeggs | 0ce41e3 | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 289 | nv50_disp_chan_new_(const struct nv50_disp_chan_func *func, |
| 290 | const struct nv50_disp_chan_mthd *mthd, |
Ben Skeggs | 0042afe | 2017-03-17 00:48:30 +0000 | [diff] [blame] | 291 | struct nv50_disp_root *root, int ctrl, int user, int head, |
Ben Skeggs | 0ce41e3 | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 292 | const struct nvkm_oclass *oclass, |
| 293 | struct nvkm_object **pobject) |
Ben Skeggs | 2a7909c | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 294 | { |
Ben Skeggs | 2a7909c | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 295 | struct nv50_disp_chan *chan; |
Ben Skeggs | 2a7909c | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 296 | |
Ben Skeggs | 0ce41e3 | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 297 | if (!(chan = kzalloc(sizeof(*chan), GFP_KERNEL))) |
| 298 | return -ENOMEM; |
| 299 | *pobject = &chan->object; |
Ben Skeggs | 2a7909c | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 300 | |
Ben Skeggs | 0042afe | 2017-03-17 00:48:30 +0000 | [diff] [blame] | 301 | return nv50_disp_chan_ctor(func, mthd, root, ctrl, user, |
| 302 | head, oclass, chan); |
Ben Skeggs | 2a7909c | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 303 | } |