channv50.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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. #include <core/client.h>
  27. #include <core/ramht.h>
  28. #include <engine/dma.h>
  29. #include <nvif/cl507d.h>
  30. #include <nvif/event.h>
  31. #include <nvif/unpack.h>
  32. static void
  33. nv50_disp_mthd_list(struct nv50_disp *disp, int debug, u32 base, int c,
  34. const struct nv50_disp_mthd_list *list, int inst)
  35. {
  36. struct nvkm_subdev *subdev = &disp->base.engine.subdev;
  37. struct nvkm_device *device = subdev->device;
  38. int i;
  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;
  45. char mods[16];
  46. if (prev != next)
  47. snprintf(mods, sizeof(mods), "-> %08x", next);
  48. else
  49. snprintf(mods, sizeof(mods), "%13c", ' ');
  50. nvkm_printk_(subdev, debug, info,
  51. "\t%04x: %08x %s%s%s\n",
  52. mthd, prev, mods, name ? " // " : "",
  53. name ? name : "");
  54. }
  55. }
  56. }
  57. void
  58. nv50_disp_chan_mthd(struct nv50_disp_chan *chan, int debug)
  59. {
  60. struct nv50_disp *disp = chan->root->disp;
  61. struct nvkm_subdev *subdev = &disp->base.engine.subdev;
  62. const struct nv50_disp_chan_mthd *mthd = chan->mthd;
  63. const struct nv50_disp_mthd_list *list;
  64. int i, j;
  65. if (debug > subdev->debug)
  66. return;
  67. for (i = 0; (list = mthd->data[i].mthd) != NULL; i++) {
  68. u32 base = chan->head * mthd->addr;
  69. for (j = 0; j < mthd->data[i].nr; j++, base += list->addr) {
  70. const char *cname = mthd->name;
  71. const char *sname = "";
  72. char cname_[16], sname_[16];
  73. if (mthd->addr) {
  74. snprintf(cname_, sizeof(cname_), "%s %d",
  75. mthd->name, chan->chid.user);
  76. cname = cname_;
  77. }
  78. if (mthd->data[i].nr > 1) {
  79. snprintf(sname_, sizeof(sname_), " - %s %d",
  80. mthd->data[i].name, j);
  81. sname = sname_;
  82. }
  83. nvkm_printk_(subdev, debug, info, "%s%s:\n", cname, sname);
  84. nv50_disp_mthd_list(disp, debug, base, mthd->prev,
  85. list, j);
  86. }
  87. }
  88. }
  89. static void
  90. nv50_disp_chan_uevent_fini(struct nvkm_event *event, int type, int index)
  91. {
  92. struct nv50_disp *disp = container_of(event, typeof(*disp), uevent);
  93. struct nvkm_device *device = disp->base.engine.subdev.device;
  94. nvkm_mask(device, 0x610028, 0x00000001 << index, 0x00000000 << index);
  95. nvkm_wr32(device, 0x610020, 0x00000001 << index);
  96. }
  97. static void
  98. nv50_disp_chan_uevent_init(struct nvkm_event *event, int types, int index)
  99. {
  100. struct nv50_disp *disp = container_of(event, typeof(*disp), uevent);
  101. struct nvkm_device *device = disp->base.engine.subdev.device;
  102. nvkm_wr32(device, 0x610020, 0x00000001 << index);
  103. nvkm_mask(device, 0x610028, 0x00000001 << index, 0x00000001 << index);
  104. }
  105. void
  106. nv50_disp_chan_uevent_send(struct nv50_disp *disp, int chid)
  107. {
  108. struct nvif_notify_uevent_rep {
  109. } rep;
  110. nvkm_event_send(&disp->uevent, 1, chid, &rep, sizeof(rep));
  111. }
  112. int
  113. nv50_disp_chan_uevent_ctor(struct nvkm_object *object, void *data, u32 size,
  114. struct nvkm_notify *notify)
  115. {
  116. struct nv50_disp_chan *chan = nv50_disp_chan(object);
  117. union {
  118. struct nvif_notify_uevent_req none;
  119. } *args = data;
  120. int ret = -ENOSYS;
  121. if (!(ret = nvif_unvers(ret, &data, &size, args->none))) {
  122. notify->size = sizeof(struct nvif_notify_uevent_rep);
  123. notify->types = 1;
  124. notify->index = chan->chid.user;
  125. return 0;
  126. }
  127. return ret;
  128. }
  129. const struct nvkm_event_func
  130. nv50_disp_chan_uevent = {
  131. .ctor = nv50_disp_chan_uevent_ctor,
  132. .init = nv50_disp_chan_uevent_init,
  133. .fini = nv50_disp_chan_uevent_fini,
  134. };
  135. static int
  136. nv50_disp_chan_rd32(struct nvkm_object *object, u64 addr, u32 *data)
  137. {
  138. struct nv50_disp_chan *chan = nv50_disp_chan(object);
  139. struct nv50_disp *disp = chan->root->disp;
  140. struct nvkm_device *device = disp->base.engine.subdev.device;
  141. *data = nvkm_rd32(device, 0x640000 + (chan->chid.user * 0x1000) + addr);
  142. return 0;
  143. }
  144. static int
  145. nv50_disp_chan_wr32(struct nvkm_object *object, u64 addr, u32 data)
  146. {
  147. struct nv50_disp_chan *chan = nv50_disp_chan(object);
  148. struct nv50_disp *disp = chan->root->disp;
  149. struct nvkm_device *device = disp->base.engine.subdev.device;
  150. nvkm_wr32(device, 0x640000 + (chan->chid.user * 0x1000) + addr, data);
  151. return 0;
  152. }
  153. static int
  154. nv50_disp_chan_ntfy(struct nvkm_object *object, u32 type,
  155. struct nvkm_event **pevent)
  156. {
  157. struct nv50_disp_chan *chan = nv50_disp_chan(object);
  158. struct nv50_disp *disp = chan->root->disp;
  159. switch (type) {
  160. case NV50_DISP_CORE_CHANNEL_DMA_V0_NTFY_UEVENT:
  161. *pevent = &disp->uevent;
  162. return 0;
  163. default:
  164. break;
  165. }
  166. return -EINVAL;
  167. }
  168. static int
  169. nv50_disp_chan_map(struct nvkm_object *object, u64 *addr, u32 *size)
  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;
  174. *addr = device->func->resource_addr(device, 0) +
  175. 0x640000 + (chan->chid.user * 0x1000);
  176. *size = 0x001000;
  177. return 0;
  178. }
  179. static int
  180. nv50_disp_chan_child_new(const struct nvkm_oclass *oclass,
  181. void *data, u32 size, struct nvkm_object **pobject)
  182. {
  183. struct nv50_disp_chan *chan = nv50_disp_chan(oclass->parent);
  184. return chan->func->child_new(chan, oclass, data, size, pobject);
  185. }
  186. static int
  187. nv50_disp_chan_child_get(struct nvkm_object *object, int index,
  188. struct nvkm_oclass *oclass)
  189. {
  190. struct nv50_disp_chan *chan = nv50_disp_chan(object);
  191. if (chan->func->child_get) {
  192. int ret = chan->func->child_get(chan, index, oclass);
  193. if (ret == 0)
  194. oclass->ctor = nv50_disp_chan_child_new;
  195. return ret;
  196. }
  197. return -EINVAL;
  198. }
  199. static int
  200. nv50_disp_chan_fini(struct nvkm_object *object, bool suspend)
  201. {
  202. struct nv50_disp_chan *chan = nv50_disp_chan(object);
  203. chan->func->fini(chan);
  204. return 0;
  205. }
  206. static int
  207. nv50_disp_chan_init(struct nvkm_object *object)
  208. {
  209. struct nv50_disp_chan *chan = nv50_disp_chan(object);
  210. return chan->func->init(chan);
  211. }
  212. static void *
  213. nv50_disp_chan_dtor(struct nvkm_object *object)
  214. {
  215. struct nv50_disp_chan *chan = nv50_disp_chan(object);
  216. struct nv50_disp *disp = chan->root->disp;
  217. if (chan->chid.user >= 0)
  218. disp->chan[chan->chid.user] = NULL;
  219. return chan->func->dtor ? chan->func->dtor(chan) : chan;
  220. }
  221. static const struct nvkm_object_func
  222. nv50_disp_chan = {
  223. .dtor = nv50_disp_chan_dtor,
  224. .init = nv50_disp_chan_init,
  225. .fini = nv50_disp_chan_fini,
  226. .rd32 = nv50_disp_chan_rd32,
  227. .wr32 = nv50_disp_chan_wr32,
  228. .ntfy = nv50_disp_chan_ntfy,
  229. .map = nv50_disp_chan_map,
  230. .sclass = nv50_disp_chan_child_get,
  231. };
  232. int
  233. nv50_disp_chan_ctor(const struct nv50_disp_chan_func *func,
  234. const struct nv50_disp_chan_mthd *mthd,
  235. struct nv50_disp_root *root, int ctrl, int user, int head,
  236. const struct nvkm_oclass *oclass,
  237. struct nv50_disp_chan *chan)
  238. {
  239. struct nv50_disp *disp = root->disp;
  240. nvkm_object_ctor(&nv50_disp_chan, oclass, &chan->object);
  241. chan->func = func;
  242. chan->mthd = mthd;
  243. chan->root = root;
  244. chan->chid.ctrl = ctrl;
  245. chan->chid.user = user;
  246. chan->head = head;
  247. if (disp->chan[chan->chid.user]) {
  248. chan->chid.user = -1;
  249. return -EBUSY;
  250. }
  251. disp->chan[chan->chid.user] = chan;
  252. return 0;
  253. }
  254. int
  255. nv50_disp_chan_new_(const struct nv50_disp_chan_func *func,
  256. const struct nv50_disp_chan_mthd *mthd,
  257. struct nv50_disp_root *root, int ctrl, int user, int head,
  258. const struct nvkm_oclass *oclass,
  259. struct nvkm_object **pobject)
  260. {
  261. struct nv50_disp_chan *chan;
  262. if (!(chan = kzalloc(sizeof(*chan), GFP_KERNEL)))
  263. return -ENOMEM;
  264. *pobject = &chan->object;
  265. return nv50_disp_chan_ctor(func, mthd, root, ctrl, user,
  266. head, oclass, chan);
  267. }