nv04.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  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 "nv04.h"
  25. #include "channv04.h"
  26. #include "regsnv04.h"
  27. #include <core/client.h>
  28. #include <core/ramht.h>
  29. #include <subdev/instmem.h>
  30. #include <subdev/timer.h>
  31. #include <engine/sw.h>
  32. static const struct nv04_fifo_ramfc
  33. nv04_fifo_ramfc[] = {
  34. { 32, 0, 0x00, 0, NV04_PFIFO_CACHE1_DMA_PUT },
  35. { 32, 0, 0x04, 0, NV04_PFIFO_CACHE1_DMA_GET },
  36. { 16, 0, 0x08, 0, NV04_PFIFO_CACHE1_DMA_INSTANCE },
  37. { 16, 16, 0x08, 0, NV04_PFIFO_CACHE1_DMA_DCOUNT },
  38. { 32, 0, 0x0c, 0, NV04_PFIFO_CACHE1_DMA_STATE },
  39. { 32, 0, 0x10, 0, NV04_PFIFO_CACHE1_DMA_FETCH },
  40. { 32, 0, 0x14, 0, NV04_PFIFO_CACHE1_ENGINE },
  41. { 32, 0, 0x18, 0, NV04_PFIFO_CACHE1_PULL1 },
  42. {}
  43. };
  44. void
  45. nv04_fifo_pause(struct nvkm_fifo *base, unsigned long *pflags)
  46. __acquires(fifo->base.lock)
  47. {
  48. struct nv04_fifo *fifo = nv04_fifo(base);
  49. struct nvkm_device *device = fifo->base.engine.subdev.device;
  50. unsigned long flags;
  51. spin_lock_irqsave(&fifo->base.lock, flags);
  52. *pflags = flags;
  53. nvkm_wr32(device, NV03_PFIFO_CACHES, 0x00000000);
  54. nvkm_mask(device, NV04_PFIFO_CACHE1_PULL0, 0x00000001, 0x00000000);
  55. /* in some cases the puller may be left in an inconsistent state
  56. * if you try to stop it while it's busy translating handles.
  57. * sometimes you get a CACHE_ERROR, sometimes it just fails
  58. * silently; sending incorrect instance offsets to PGRAPH after
  59. * it's started up again.
  60. *
  61. * to avoid this, we invalidate the most recently calculated
  62. * instance.
  63. */
  64. nvkm_msec(device, 2000,
  65. u32 tmp = nvkm_rd32(device, NV04_PFIFO_CACHE1_PULL0);
  66. if (!(tmp & NV04_PFIFO_CACHE1_PULL0_HASH_BUSY))
  67. break;
  68. );
  69. if (nvkm_rd32(device, NV04_PFIFO_CACHE1_PULL0) &
  70. NV04_PFIFO_CACHE1_PULL0_HASH_FAILED)
  71. nvkm_wr32(device, NV03_PFIFO_INTR_0, NV_PFIFO_INTR_CACHE_ERROR);
  72. nvkm_wr32(device, NV04_PFIFO_CACHE1_HASH, 0x00000000);
  73. }
  74. void
  75. nv04_fifo_start(struct nvkm_fifo *base, unsigned long *pflags)
  76. __releases(fifo->base.lock)
  77. {
  78. struct nv04_fifo *fifo = nv04_fifo(base);
  79. struct nvkm_device *device = fifo->base.engine.subdev.device;
  80. unsigned long flags = *pflags;
  81. nvkm_mask(device, NV04_PFIFO_CACHE1_PULL0, 0x00000001, 0x00000001);
  82. nvkm_wr32(device, NV03_PFIFO_CACHES, 0x00000001);
  83. spin_unlock_irqrestore(&fifo->base.lock, flags);
  84. }
  85. static const char *
  86. nv_dma_state_err(u32 state)
  87. {
  88. static const char * const desc[] = {
  89. "NONE", "CALL_SUBR_ACTIVE", "INVALID_MTHD", "RET_SUBR_INACTIVE",
  90. "INVALID_CMD", "IB_EMPTY"/* NV50+ */, "MEM_FAULT", "UNK"
  91. };
  92. return desc[(state >> 29) & 0x7];
  93. }
  94. static bool
  95. nv04_fifo_swmthd(struct nvkm_device *device, u32 chid, u32 addr, u32 data)
  96. {
  97. struct nvkm_sw *sw = device->sw;
  98. const int subc = (addr & 0x0000e000) >> 13;
  99. const int mthd = (addr & 0x00001ffc);
  100. const u32 mask = 0x0000000f << (subc * 4);
  101. u32 engine = nvkm_rd32(device, 0x003280);
  102. bool handled = false;
  103. switch (mthd) {
  104. case 0x0000 ... 0x0000: /* subchannel's engine -> software */
  105. nvkm_wr32(device, 0x003280, (engine &= ~mask));
  106. case 0x0180 ... 0x01fc: /* handle -> instance */
  107. data = nvkm_rd32(device, 0x003258) & 0x0000ffff;
  108. case 0x0100 ... 0x017c:
  109. case 0x0200 ... 0x1ffc: /* pass method down to sw */
  110. if (!(engine & mask) && sw)
  111. handled = nvkm_sw_mthd(sw, chid, subc, mthd, data);
  112. break;
  113. default:
  114. break;
  115. }
  116. return handled;
  117. }
  118. static void
  119. nv04_fifo_cache_error(struct nv04_fifo *fifo, u32 chid, u32 get)
  120. {
  121. struct nvkm_subdev *subdev = &fifo->base.engine.subdev;
  122. struct nvkm_device *device = subdev->device;
  123. struct nvkm_fifo_chan *chan;
  124. unsigned long flags;
  125. u32 pull0 = nvkm_rd32(device, 0x003250);
  126. u32 mthd, data;
  127. int ptr;
  128. /* NV_PFIFO_CACHE1_GET actually goes to 0xffc before wrapping on my
  129. * G80 chips, but CACHE1 isn't big enough for this much data.. Tests
  130. * show that it wraps around to the start at GET=0x800.. No clue as to
  131. * why..
  132. */
  133. ptr = (get & 0x7ff) >> 2;
  134. if (device->card_type < NV_40) {
  135. mthd = nvkm_rd32(device, NV04_PFIFO_CACHE1_METHOD(ptr));
  136. data = nvkm_rd32(device, NV04_PFIFO_CACHE1_DATA(ptr));
  137. } else {
  138. mthd = nvkm_rd32(device, NV40_PFIFO_CACHE1_METHOD(ptr));
  139. data = nvkm_rd32(device, NV40_PFIFO_CACHE1_DATA(ptr));
  140. }
  141. if (!(pull0 & 0x00000100) ||
  142. !nv04_fifo_swmthd(device, chid, mthd, data)) {
  143. chan = nvkm_fifo_chan_chid(&fifo->base, chid, &flags);
  144. nvkm_error(subdev, "CACHE_ERROR - "
  145. "ch %d [%s] subc %d mthd %04x data %08x\n",
  146. chid, chan ? chan->object.client->name : "unknown",
  147. (mthd >> 13) & 7, mthd & 0x1ffc, data);
  148. nvkm_fifo_chan_put(&fifo->base, flags, &chan);
  149. }
  150. nvkm_wr32(device, NV04_PFIFO_CACHE1_DMA_PUSH, 0);
  151. nvkm_wr32(device, NV03_PFIFO_INTR_0, NV_PFIFO_INTR_CACHE_ERROR);
  152. nvkm_wr32(device, NV03_PFIFO_CACHE1_PUSH0,
  153. nvkm_rd32(device, NV03_PFIFO_CACHE1_PUSH0) & ~1);
  154. nvkm_wr32(device, NV03_PFIFO_CACHE1_GET, get + 4);
  155. nvkm_wr32(device, NV03_PFIFO_CACHE1_PUSH0,
  156. nvkm_rd32(device, NV03_PFIFO_CACHE1_PUSH0) | 1);
  157. nvkm_wr32(device, NV04_PFIFO_CACHE1_HASH, 0);
  158. nvkm_wr32(device, NV04_PFIFO_CACHE1_DMA_PUSH,
  159. nvkm_rd32(device, NV04_PFIFO_CACHE1_DMA_PUSH) | 1);
  160. nvkm_wr32(device, NV04_PFIFO_CACHE1_PULL0, 1);
  161. }
  162. static void
  163. nv04_fifo_dma_pusher(struct nv04_fifo *fifo, u32 chid)
  164. {
  165. struct nvkm_subdev *subdev = &fifo->base.engine.subdev;
  166. struct nvkm_device *device = subdev->device;
  167. u32 dma_get = nvkm_rd32(device, 0x003244);
  168. u32 dma_put = nvkm_rd32(device, 0x003240);
  169. u32 push = nvkm_rd32(device, 0x003220);
  170. u32 state = nvkm_rd32(device, 0x003228);
  171. struct nvkm_fifo_chan *chan;
  172. unsigned long flags;
  173. const char *name;
  174. chan = nvkm_fifo_chan_chid(&fifo->base, chid, &flags);
  175. name = chan ? chan->object.client->name : "unknown";
  176. if (device->card_type == NV_50) {
  177. u32 ho_get = nvkm_rd32(device, 0x003328);
  178. u32 ho_put = nvkm_rd32(device, 0x003320);
  179. u32 ib_get = nvkm_rd32(device, 0x003334);
  180. u32 ib_put = nvkm_rd32(device, 0x003330);
  181. nvkm_error(subdev, "DMA_PUSHER - "
  182. "ch %d [%s] get %02x%08x put %02x%08x ib_get %08x "
  183. "ib_put %08x state %08x (err: %s) push %08x\n",
  184. chid, name, ho_get, dma_get, ho_put, dma_put,
  185. ib_get, ib_put, state, nv_dma_state_err(state),
  186. push);
  187. /* METHOD_COUNT, in DMA_STATE on earlier chipsets */
  188. nvkm_wr32(device, 0x003364, 0x00000000);
  189. if (dma_get != dma_put || ho_get != ho_put) {
  190. nvkm_wr32(device, 0x003244, dma_put);
  191. nvkm_wr32(device, 0x003328, ho_put);
  192. } else
  193. if (ib_get != ib_put)
  194. nvkm_wr32(device, 0x003334, ib_put);
  195. } else {
  196. nvkm_error(subdev, "DMA_PUSHER - ch %d [%s] get %08x put %08x "
  197. "state %08x (err: %s) push %08x\n",
  198. chid, name, dma_get, dma_put, state,
  199. nv_dma_state_err(state), push);
  200. if (dma_get != dma_put)
  201. nvkm_wr32(device, 0x003244, dma_put);
  202. }
  203. nvkm_fifo_chan_put(&fifo->base, flags, &chan);
  204. nvkm_wr32(device, 0x003228, 0x00000000);
  205. nvkm_wr32(device, 0x003220, 0x00000001);
  206. nvkm_wr32(device, 0x002100, NV_PFIFO_INTR_DMA_PUSHER);
  207. }
  208. void
  209. nv04_fifo_intr(struct nvkm_fifo *base)
  210. {
  211. struct nv04_fifo *fifo = nv04_fifo(base);
  212. struct nvkm_subdev *subdev = &fifo->base.engine.subdev;
  213. struct nvkm_device *device = subdev->device;
  214. u32 mask = nvkm_rd32(device, NV03_PFIFO_INTR_EN_0);
  215. u32 stat = nvkm_rd32(device, NV03_PFIFO_INTR_0) & mask;
  216. u32 reassign, chid, get, sem;
  217. reassign = nvkm_rd32(device, NV03_PFIFO_CACHES) & 1;
  218. nvkm_wr32(device, NV03_PFIFO_CACHES, 0);
  219. chid = nvkm_rd32(device, NV03_PFIFO_CACHE1_PUSH1) & (fifo->base.nr - 1);
  220. get = nvkm_rd32(device, NV03_PFIFO_CACHE1_GET);
  221. if (stat & NV_PFIFO_INTR_CACHE_ERROR) {
  222. nv04_fifo_cache_error(fifo, chid, get);
  223. stat &= ~NV_PFIFO_INTR_CACHE_ERROR;
  224. }
  225. if (stat & NV_PFIFO_INTR_DMA_PUSHER) {
  226. nv04_fifo_dma_pusher(fifo, chid);
  227. stat &= ~NV_PFIFO_INTR_DMA_PUSHER;
  228. }
  229. if (stat & NV_PFIFO_INTR_SEMAPHORE) {
  230. stat &= ~NV_PFIFO_INTR_SEMAPHORE;
  231. nvkm_wr32(device, NV03_PFIFO_INTR_0, NV_PFIFO_INTR_SEMAPHORE);
  232. sem = nvkm_rd32(device, NV10_PFIFO_CACHE1_SEMAPHORE);
  233. nvkm_wr32(device, NV10_PFIFO_CACHE1_SEMAPHORE, sem | 0x1);
  234. nvkm_wr32(device, NV03_PFIFO_CACHE1_GET, get + 4);
  235. nvkm_wr32(device, NV04_PFIFO_CACHE1_PULL0, 1);
  236. }
  237. if (device->card_type == NV_50) {
  238. if (stat & 0x00000010) {
  239. stat &= ~0x00000010;
  240. nvkm_wr32(device, 0x002100, 0x00000010);
  241. }
  242. if (stat & 0x40000000) {
  243. nvkm_wr32(device, 0x002100, 0x40000000);
  244. nvkm_fifo_uevent(&fifo->base);
  245. stat &= ~0x40000000;
  246. }
  247. }
  248. if (stat) {
  249. nvkm_warn(subdev, "intr %08x\n", stat);
  250. nvkm_mask(device, NV03_PFIFO_INTR_EN_0, stat, 0x00000000);
  251. nvkm_wr32(device, NV03_PFIFO_INTR_0, stat);
  252. }
  253. nvkm_wr32(device, NV03_PFIFO_CACHES, reassign);
  254. }
  255. void
  256. nv04_fifo_init(struct nvkm_fifo *base)
  257. {
  258. struct nv04_fifo *fifo = nv04_fifo(base);
  259. struct nvkm_device *device = fifo->base.engine.subdev.device;
  260. struct nvkm_instmem *imem = device->imem;
  261. struct nvkm_ramht *ramht = imem->ramht;
  262. struct nvkm_memory *ramro = imem->ramro;
  263. struct nvkm_memory *ramfc = imem->ramfc;
  264. nvkm_wr32(device, NV04_PFIFO_DELAY_0, 0x000000ff);
  265. nvkm_wr32(device, NV04_PFIFO_DMA_TIMESLICE, 0x0101ffff);
  266. nvkm_wr32(device, NV03_PFIFO_RAMHT, (0x03 << 24) /* search 128 */ |
  267. ((ramht->bits - 9) << 16) |
  268. (ramht->gpuobj->addr >> 8));
  269. nvkm_wr32(device, NV03_PFIFO_RAMRO, nvkm_memory_addr(ramro) >> 8);
  270. nvkm_wr32(device, NV03_PFIFO_RAMFC, nvkm_memory_addr(ramfc) >> 8);
  271. nvkm_wr32(device, NV03_PFIFO_CACHE1_PUSH1, fifo->base.nr - 1);
  272. nvkm_wr32(device, NV03_PFIFO_INTR_0, 0xffffffff);
  273. nvkm_wr32(device, NV03_PFIFO_INTR_EN_0, 0xffffffff);
  274. nvkm_wr32(device, NV03_PFIFO_CACHE1_PUSH0, 1);
  275. nvkm_wr32(device, NV04_PFIFO_CACHE1_PULL0, 1);
  276. nvkm_wr32(device, NV03_PFIFO_CACHES, 1);
  277. }
  278. int
  279. nv04_fifo_new_(const struct nvkm_fifo_func *func, struct nvkm_device *device,
  280. int index, int nr, const struct nv04_fifo_ramfc *ramfc,
  281. struct nvkm_fifo **pfifo)
  282. {
  283. struct nv04_fifo *fifo;
  284. int ret;
  285. if (!(fifo = kzalloc(sizeof(*fifo), GFP_KERNEL)))
  286. return -ENOMEM;
  287. fifo->ramfc = ramfc;
  288. *pfifo = &fifo->base;
  289. ret = nvkm_fifo_ctor(func, device, index, nr, &fifo->base);
  290. if (ret)
  291. return ret;
  292. set_bit(nr - 1, fifo->base.mask); /* inactive channel */
  293. return 0;
  294. }
  295. static const struct nvkm_fifo_func
  296. nv04_fifo = {
  297. .init = nv04_fifo_init,
  298. .intr = nv04_fifo_intr,
  299. .pause = nv04_fifo_pause,
  300. .start = nv04_fifo_start,
  301. .chan = {
  302. &nv04_fifo_dma_oclass,
  303. NULL
  304. },
  305. };
  306. int
  307. nv04_fifo_new(struct nvkm_device *device, int index, struct nvkm_fifo **pfifo)
  308. {
  309. return nv04_fifo_new_(&nv04_fifo, device, index, 16,
  310. nv04_fifo_ramfc, pfifo);
  311. }