nv20.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. #include "nv20.h"
  2. #include "regs.h"
  3. #include <core/client.h>
  4. #include <core/gpuobj.h>
  5. #include <engine/fifo.h>
  6. #include <engine/fifo/chan.h>
  7. #include <subdev/fb.h>
  8. #include <subdev/timer.h>
  9. /*******************************************************************************
  10. * PGRAPH context
  11. ******************************************************************************/
  12. int
  13. nv20_gr_chan_init(struct nvkm_object *object)
  14. {
  15. struct nv20_gr_chan *chan = nv20_gr_chan(object);
  16. struct nv20_gr *gr = chan->gr;
  17. u32 inst = nvkm_memory_addr(chan->inst);
  18. nvkm_kmap(gr->ctxtab);
  19. nvkm_wo32(gr->ctxtab, chan->chid * 4, inst >> 4);
  20. nvkm_done(gr->ctxtab);
  21. return 0;
  22. }
  23. int
  24. nv20_gr_chan_fini(struct nvkm_object *object, bool suspend)
  25. {
  26. struct nv20_gr_chan *chan = nv20_gr_chan(object);
  27. struct nv20_gr *gr = chan->gr;
  28. struct nvkm_device *device = gr->base.engine.subdev.device;
  29. u32 inst = nvkm_memory_addr(chan->inst);
  30. int chid = -1;
  31. nvkm_mask(device, 0x400720, 0x00000001, 0x00000000);
  32. if (nvkm_rd32(device, 0x400144) & 0x00010000)
  33. chid = (nvkm_rd32(device, 0x400148) & 0x1f000000) >> 24;
  34. if (chan->chid == chid) {
  35. nvkm_wr32(device, 0x400784, inst >> 4);
  36. nvkm_wr32(device, 0x400788, 0x00000002);
  37. nvkm_msec(device, 2000,
  38. if (!nvkm_rd32(device, 0x400700))
  39. break;
  40. );
  41. nvkm_wr32(device, 0x400144, 0x10000000);
  42. nvkm_mask(device, 0x400148, 0xff000000, 0x1f000000);
  43. }
  44. nvkm_mask(device, 0x400720, 0x00000001, 0x00000001);
  45. nvkm_kmap(gr->ctxtab);
  46. nvkm_wo32(gr->ctxtab, chan->chid * 4, 0x00000000);
  47. nvkm_done(gr->ctxtab);
  48. return 0;
  49. }
  50. void *
  51. nv20_gr_chan_dtor(struct nvkm_object *object)
  52. {
  53. struct nv20_gr_chan *chan = nv20_gr_chan(object);
  54. nvkm_memory_del(&chan->inst);
  55. return chan;
  56. }
  57. static const struct nvkm_object_func
  58. nv20_gr_chan = {
  59. .dtor = nv20_gr_chan_dtor,
  60. .init = nv20_gr_chan_init,
  61. .fini = nv20_gr_chan_fini,
  62. };
  63. static int
  64. nv20_gr_chan_new(struct nvkm_gr *base, struct nvkm_fifo_chan *fifoch,
  65. const struct nvkm_oclass *oclass, struct nvkm_object **pobject)
  66. {
  67. struct nv20_gr *gr = nv20_gr(base);
  68. struct nv20_gr_chan *chan;
  69. int ret, i;
  70. if (!(chan = kzalloc(sizeof(*chan), GFP_KERNEL)))
  71. return -ENOMEM;
  72. nvkm_object_ctor(&nv20_gr_chan, oclass, &chan->object);
  73. chan->gr = gr;
  74. chan->chid = fifoch->chid;
  75. *pobject = &chan->object;
  76. ret = nvkm_memory_new(gr->base.engine.subdev.device,
  77. NVKM_MEM_TARGET_INST, 0x37f0, 16, true,
  78. &chan->inst);
  79. if (ret)
  80. return ret;
  81. nvkm_kmap(chan->inst);
  82. nvkm_wo32(chan->inst, 0x0000, 0x00000001 | (chan->chid << 24));
  83. nvkm_wo32(chan->inst, 0x033c, 0xffff0000);
  84. nvkm_wo32(chan->inst, 0x03a0, 0x0fff0000);
  85. nvkm_wo32(chan->inst, 0x03a4, 0x0fff0000);
  86. nvkm_wo32(chan->inst, 0x047c, 0x00000101);
  87. nvkm_wo32(chan->inst, 0x0490, 0x00000111);
  88. nvkm_wo32(chan->inst, 0x04a8, 0x44400000);
  89. for (i = 0x04d4; i <= 0x04e0; i += 4)
  90. nvkm_wo32(chan->inst, i, 0x00030303);
  91. for (i = 0x04f4; i <= 0x0500; i += 4)
  92. nvkm_wo32(chan->inst, i, 0x00080000);
  93. for (i = 0x050c; i <= 0x0518; i += 4)
  94. nvkm_wo32(chan->inst, i, 0x01012000);
  95. for (i = 0x051c; i <= 0x0528; i += 4)
  96. nvkm_wo32(chan->inst, i, 0x000105b8);
  97. for (i = 0x052c; i <= 0x0538; i += 4)
  98. nvkm_wo32(chan->inst, i, 0x00080008);
  99. for (i = 0x055c; i <= 0x0598; i += 4)
  100. nvkm_wo32(chan->inst, i, 0x07ff0000);
  101. nvkm_wo32(chan->inst, 0x05a4, 0x4b7fffff);
  102. nvkm_wo32(chan->inst, 0x05fc, 0x00000001);
  103. nvkm_wo32(chan->inst, 0x0604, 0x00004000);
  104. nvkm_wo32(chan->inst, 0x0610, 0x00000001);
  105. nvkm_wo32(chan->inst, 0x0618, 0x00040000);
  106. nvkm_wo32(chan->inst, 0x061c, 0x00010000);
  107. for (i = 0x1c1c; i <= 0x248c; i += 16) {
  108. nvkm_wo32(chan->inst, (i + 0), 0x10700ff9);
  109. nvkm_wo32(chan->inst, (i + 4), 0x0436086c);
  110. nvkm_wo32(chan->inst, (i + 8), 0x000c001b);
  111. }
  112. nvkm_wo32(chan->inst, 0x281c, 0x3f800000);
  113. nvkm_wo32(chan->inst, 0x2830, 0x3f800000);
  114. nvkm_wo32(chan->inst, 0x285c, 0x40000000);
  115. nvkm_wo32(chan->inst, 0x2860, 0x3f800000);
  116. nvkm_wo32(chan->inst, 0x2864, 0x3f000000);
  117. nvkm_wo32(chan->inst, 0x286c, 0x40000000);
  118. nvkm_wo32(chan->inst, 0x2870, 0x3f800000);
  119. nvkm_wo32(chan->inst, 0x2878, 0xbf800000);
  120. nvkm_wo32(chan->inst, 0x2880, 0xbf800000);
  121. nvkm_wo32(chan->inst, 0x34a4, 0x000fe000);
  122. nvkm_wo32(chan->inst, 0x3530, 0x000003f8);
  123. nvkm_wo32(chan->inst, 0x3540, 0x002fe000);
  124. for (i = 0x355c; i <= 0x3578; i += 4)
  125. nvkm_wo32(chan->inst, i, 0x001c527c);
  126. nvkm_done(chan->inst);
  127. return 0;
  128. }
  129. /*******************************************************************************
  130. * PGRAPH engine/subdev functions
  131. ******************************************************************************/
  132. void
  133. nv20_gr_tile(struct nvkm_gr *base, int i, struct nvkm_fb_tile *tile)
  134. {
  135. struct nv20_gr *gr = nv20_gr(base);
  136. struct nvkm_device *device = gr->base.engine.subdev.device;
  137. struct nvkm_fifo *fifo = device->fifo;
  138. unsigned long flags;
  139. nvkm_fifo_pause(fifo, &flags);
  140. nv04_gr_idle(&gr->base);
  141. nvkm_wr32(device, NV20_PGRAPH_TLIMIT(i), tile->limit);
  142. nvkm_wr32(device, NV20_PGRAPH_TSIZE(i), tile->pitch);
  143. nvkm_wr32(device, NV20_PGRAPH_TILE(i), tile->addr);
  144. nvkm_wr32(device, NV10_PGRAPH_RDI_INDEX, 0x00EA0030 + 4 * i);
  145. nvkm_wr32(device, NV10_PGRAPH_RDI_DATA, tile->limit);
  146. nvkm_wr32(device, NV10_PGRAPH_RDI_INDEX, 0x00EA0050 + 4 * i);
  147. nvkm_wr32(device, NV10_PGRAPH_RDI_DATA, tile->pitch);
  148. nvkm_wr32(device, NV10_PGRAPH_RDI_INDEX, 0x00EA0010 + 4 * i);
  149. nvkm_wr32(device, NV10_PGRAPH_RDI_DATA, tile->addr);
  150. if (device->chipset != 0x34) {
  151. nvkm_wr32(device, NV20_PGRAPH_ZCOMP(i), tile->zcomp);
  152. nvkm_wr32(device, NV10_PGRAPH_RDI_INDEX, 0x00ea0090 + 4 * i);
  153. nvkm_wr32(device, NV10_PGRAPH_RDI_DATA, tile->zcomp);
  154. }
  155. nvkm_fifo_start(fifo, &flags);
  156. }
  157. void
  158. nv20_gr_intr(struct nvkm_gr *base)
  159. {
  160. struct nv20_gr *gr = nv20_gr(base);
  161. struct nvkm_subdev *subdev = &gr->base.engine.subdev;
  162. struct nvkm_device *device = subdev->device;
  163. struct nvkm_fifo_chan *chan;
  164. u32 stat = nvkm_rd32(device, NV03_PGRAPH_INTR);
  165. u32 nsource = nvkm_rd32(device, NV03_PGRAPH_NSOURCE);
  166. u32 nstatus = nvkm_rd32(device, NV03_PGRAPH_NSTATUS);
  167. u32 addr = nvkm_rd32(device, NV04_PGRAPH_TRAPPED_ADDR);
  168. u32 chid = (addr & 0x01f00000) >> 20;
  169. u32 subc = (addr & 0x00070000) >> 16;
  170. u32 mthd = (addr & 0x00001ffc);
  171. u32 data = nvkm_rd32(device, NV04_PGRAPH_TRAPPED_DATA);
  172. u32 class = nvkm_rd32(device, 0x400160 + subc * 4) & 0xfff;
  173. u32 show = stat;
  174. char msg[128], src[128], sta[128];
  175. unsigned long flags;
  176. chan = nvkm_fifo_chan_chid(device->fifo, chid, &flags);
  177. nvkm_wr32(device, NV03_PGRAPH_INTR, stat);
  178. nvkm_wr32(device, NV04_PGRAPH_FIFO, 0x00000001);
  179. if (show) {
  180. nvkm_snprintbf(msg, sizeof(msg), nv10_gr_intr_name, show);
  181. nvkm_snprintbf(src, sizeof(src), nv04_gr_nsource, nsource);
  182. nvkm_snprintbf(sta, sizeof(sta), nv10_gr_nstatus, nstatus);
  183. nvkm_error(subdev, "intr %08x [%s] nsource %08x [%s] "
  184. "nstatus %08x [%s] ch %d [%s] subc %d "
  185. "class %04x mthd %04x data %08x\n",
  186. show, msg, nsource, src, nstatus, sta, chid,
  187. chan ? chan->object.client->name : "unknown",
  188. subc, class, mthd, data);
  189. }
  190. nvkm_fifo_chan_put(device->fifo, flags, &chan);
  191. }
  192. int
  193. nv20_gr_oneinit(struct nvkm_gr *base)
  194. {
  195. struct nv20_gr *gr = nv20_gr(base);
  196. return nvkm_memory_new(gr->base.engine.subdev.device,
  197. NVKM_MEM_TARGET_INST, 32 * 4, 16,
  198. true, &gr->ctxtab);
  199. }
  200. int
  201. nv20_gr_init(struct nvkm_gr *base)
  202. {
  203. struct nv20_gr *gr = nv20_gr(base);
  204. struct nvkm_device *device = gr->base.engine.subdev.device;
  205. u32 tmp, vramsz;
  206. int i;
  207. nvkm_wr32(device, NV20_PGRAPH_CHANNEL_CTX_TABLE,
  208. nvkm_memory_addr(gr->ctxtab) >> 4);
  209. if (device->chipset == 0x20) {
  210. nvkm_wr32(device, NV10_PGRAPH_RDI_INDEX, 0x003d0000);
  211. for (i = 0; i < 15; i++)
  212. nvkm_wr32(device, NV10_PGRAPH_RDI_DATA, 0x00000000);
  213. nvkm_msec(device, 2000,
  214. if (!nvkm_rd32(device, 0x400700))
  215. break;
  216. );
  217. } else {
  218. nvkm_wr32(device, NV10_PGRAPH_RDI_INDEX, 0x02c80000);
  219. for (i = 0; i < 32; i++)
  220. nvkm_wr32(device, NV10_PGRAPH_RDI_DATA, 0x00000000);
  221. nvkm_msec(device, 2000,
  222. if (!nvkm_rd32(device, 0x400700))
  223. break;
  224. );
  225. }
  226. nvkm_wr32(device, NV03_PGRAPH_INTR , 0xFFFFFFFF);
  227. nvkm_wr32(device, NV03_PGRAPH_INTR_EN, 0xFFFFFFFF);
  228. nvkm_wr32(device, NV04_PGRAPH_DEBUG_0, 0xFFFFFFFF);
  229. nvkm_wr32(device, NV04_PGRAPH_DEBUG_0, 0x00000000);
  230. nvkm_wr32(device, NV04_PGRAPH_DEBUG_1, 0x00118700);
  231. nvkm_wr32(device, NV04_PGRAPH_DEBUG_3, 0xF3CE0475); /* 0x4 = auto ctx switch */
  232. nvkm_wr32(device, NV10_PGRAPH_DEBUG_4, 0x00000000);
  233. nvkm_wr32(device, 0x40009C , 0x00000040);
  234. if (device->chipset >= 0x25) {
  235. nvkm_wr32(device, 0x400890, 0x00a8cfff);
  236. nvkm_wr32(device, 0x400610, 0x304B1FB6);
  237. nvkm_wr32(device, 0x400B80, 0x1cbd3883);
  238. nvkm_wr32(device, 0x400B84, 0x44000000);
  239. nvkm_wr32(device, 0x400098, 0x40000080);
  240. nvkm_wr32(device, 0x400B88, 0x000000ff);
  241. } else {
  242. nvkm_wr32(device, 0x400880, 0x0008c7df);
  243. nvkm_wr32(device, 0x400094, 0x00000005);
  244. nvkm_wr32(device, 0x400B80, 0x45eae20e);
  245. nvkm_wr32(device, 0x400B84, 0x24000000);
  246. nvkm_wr32(device, 0x400098, 0x00000040);
  247. nvkm_wr32(device, NV10_PGRAPH_RDI_INDEX, 0x00E00038);
  248. nvkm_wr32(device, NV10_PGRAPH_RDI_DATA , 0x00000030);
  249. nvkm_wr32(device, NV10_PGRAPH_RDI_INDEX, 0x00E10038);
  250. nvkm_wr32(device, NV10_PGRAPH_RDI_DATA , 0x00000030);
  251. }
  252. nvkm_wr32(device, 0x4009a0, nvkm_rd32(device, 0x100324));
  253. nvkm_wr32(device, NV10_PGRAPH_RDI_INDEX, 0x00EA000C);
  254. nvkm_wr32(device, NV10_PGRAPH_RDI_DATA, nvkm_rd32(device, 0x100324));
  255. nvkm_wr32(device, NV10_PGRAPH_CTX_CONTROL, 0x10000100);
  256. nvkm_wr32(device, NV10_PGRAPH_STATE , 0xFFFFFFFF);
  257. tmp = nvkm_rd32(device, NV10_PGRAPH_SURFACE) & 0x0007ff00;
  258. nvkm_wr32(device, NV10_PGRAPH_SURFACE, tmp);
  259. tmp = nvkm_rd32(device, NV10_PGRAPH_SURFACE) | 0x00020100;
  260. nvkm_wr32(device, NV10_PGRAPH_SURFACE, tmp);
  261. /* begin RAM config */
  262. vramsz = device->func->resource_size(device, 1) - 1;
  263. nvkm_wr32(device, 0x4009A4, nvkm_rd32(device, 0x100200));
  264. nvkm_wr32(device, 0x4009A8, nvkm_rd32(device, 0x100204));
  265. nvkm_wr32(device, NV10_PGRAPH_RDI_INDEX, 0x00EA0000);
  266. nvkm_wr32(device, NV10_PGRAPH_RDI_DATA , nvkm_rd32(device, 0x100200));
  267. nvkm_wr32(device, NV10_PGRAPH_RDI_INDEX, 0x00EA0004);
  268. nvkm_wr32(device, NV10_PGRAPH_RDI_DATA , nvkm_rd32(device, 0x100204));
  269. nvkm_wr32(device, 0x400820, 0);
  270. nvkm_wr32(device, 0x400824, 0);
  271. nvkm_wr32(device, 0x400864, vramsz - 1);
  272. nvkm_wr32(device, 0x400868, vramsz - 1);
  273. /* interesting.. the below overwrites some of the tile setup above.. */
  274. nvkm_wr32(device, 0x400B20, 0x00000000);
  275. nvkm_wr32(device, 0x400B04, 0xFFFFFFFF);
  276. nvkm_wr32(device, NV03_PGRAPH_ABS_UCLIP_XMIN, 0);
  277. nvkm_wr32(device, NV03_PGRAPH_ABS_UCLIP_YMIN, 0);
  278. nvkm_wr32(device, NV03_PGRAPH_ABS_UCLIP_XMAX, 0x7fff);
  279. nvkm_wr32(device, NV03_PGRAPH_ABS_UCLIP_YMAX, 0x7fff);
  280. return 0;
  281. }
  282. void *
  283. nv20_gr_dtor(struct nvkm_gr *base)
  284. {
  285. struct nv20_gr *gr = nv20_gr(base);
  286. nvkm_memory_del(&gr->ctxtab);
  287. return gr;
  288. }
  289. int
  290. nv20_gr_new_(const struct nvkm_gr_func *func, struct nvkm_device *device,
  291. int index, struct nvkm_gr **pgr)
  292. {
  293. struct nv20_gr *gr;
  294. if (!(gr = kzalloc(sizeof(*gr), GFP_KERNEL)))
  295. return -ENOMEM;
  296. *pgr = &gr->base;
  297. return nvkm_gr_ctor(func, device, index, true, &gr->base);
  298. }
  299. static const struct nvkm_gr_func
  300. nv20_gr = {
  301. .dtor = nv20_gr_dtor,
  302. .oneinit = nv20_gr_oneinit,
  303. .init = nv20_gr_init,
  304. .intr = nv20_gr_intr,
  305. .tile = nv20_gr_tile,
  306. .chan_new = nv20_gr_chan_new,
  307. .sclass = {
  308. { -1, -1, 0x0012, &nv04_gr_object }, /* beta1 */
  309. { -1, -1, 0x0019, &nv04_gr_object }, /* clip */
  310. { -1, -1, 0x0030, &nv04_gr_object }, /* null */
  311. { -1, -1, 0x0039, &nv04_gr_object }, /* m2mf */
  312. { -1, -1, 0x0043, &nv04_gr_object }, /* rop */
  313. { -1, -1, 0x0044, &nv04_gr_object }, /* patt */
  314. { -1, -1, 0x004a, &nv04_gr_object }, /* gdi */
  315. { -1, -1, 0x0062, &nv04_gr_object }, /* surf2d */
  316. { -1, -1, 0x0072, &nv04_gr_object }, /* beta4 */
  317. { -1, -1, 0x0089, &nv04_gr_object }, /* sifm */
  318. { -1, -1, 0x008a, &nv04_gr_object }, /* ifc */
  319. { -1, -1, 0x0096, &nv04_gr_object }, /* celcius */
  320. { -1, -1, 0x0097, &nv04_gr_object }, /* kelvin */
  321. { -1, -1, 0x009e, &nv04_gr_object }, /* swzsurf */
  322. { -1, -1, 0x009f, &nv04_gr_object }, /* imageblit */
  323. {}
  324. }
  325. };
  326. int
  327. nv20_gr_new(struct nvkm_device *device, int index, struct nvkm_gr **pgr)
  328. {
  329. return nv20_gr_new_(&nv20_gr, device, index, pgr);
  330. }