gf100.c 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057
  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 "gf100.h"
  25. #include "ctxgf100.h"
  26. #include "fuc/os.h"
  27. #include <core/client.h>
  28. #include <core/option.h>
  29. #include <core/firmware.h>
  30. #include <subdev/secboot.h>
  31. #include <subdev/fb.h>
  32. #include <subdev/mc.h>
  33. #include <subdev/pmu.h>
  34. #include <subdev/timer.h>
  35. #include <engine/fifo.h>
  36. #include <nvif/class.h>
  37. #include <nvif/cl9097.h>
  38. #include <nvif/unpack.h>
  39. /*******************************************************************************
  40. * Zero Bandwidth Clear
  41. ******************************************************************************/
  42. static void
  43. gf100_gr_zbc_clear_color(struct gf100_gr *gr, int zbc)
  44. {
  45. struct nvkm_device *device = gr->base.engine.subdev.device;
  46. if (gr->zbc_color[zbc].format) {
  47. nvkm_wr32(device, 0x405804, gr->zbc_color[zbc].ds[0]);
  48. nvkm_wr32(device, 0x405808, gr->zbc_color[zbc].ds[1]);
  49. nvkm_wr32(device, 0x40580c, gr->zbc_color[zbc].ds[2]);
  50. nvkm_wr32(device, 0x405810, gr->zbc_color[zbc].ds[3]);
  51. }
  52. nvkm_wr32(device, 0x405814, gr->zbc_color[zbc].format);
  53. nvkm_wr32(device, 0x405820, zbc);
  54. nvkm_wr32(device, 0x405824, 0x00000004); /* TRIGGER | WRITE | COLOR */
  55. }
  56. static int
  57. gf100_gr_zbc_color_get(struct gf100_gr *gr, int format,
  58. const u32 ds[4], const u32 l2[4])
  59. {
  60. struct nvkm_ltc *ltc = gr->base.engine.subdev.device->ltc;
  61. int zbc = -ENOSPC, i;
  62. for (i = ltc->zbc_min; i <= ltc->zbc_max; i++) {
  63. if (gr->zbc_color[i].format) {
  64. if (gr->zbc_color[i].format != format)
  65. continue;
  66. if (memcmp(gr->zbc_color[i].ds, ds, sizeof(
  67. gr->zbc_color[i].ds)))
  68. continue;
  69. if (memcmp(gr->zbc_color[i].l2, l2, sizeof(
  70. gr->zbc_color[i].l2))) {
  71. WARN_ON(1);
  72. return -EINVAL;
  73. }
  74. return i;
  75. } else {
  76. zbc = (zbc < 0) ? i : zbc;
  77. }
  78. }
  79. if (zbc < 0)
  80. return zbc;
  81. memcpy(gr->zbc_color[zbc].ds, ds, sizeof(gr->zbc_color[zbc].ds));
  82. memcpy(gr->zbc_color[zbc].l2, l2, sizeof(gr->zbc_color[zbc].l2));
  83. gr->zbc_color[zbc].format = format;
  84. nvkm_ltc_zbc_color_get(ltc, zbc, l2);
  85. gf100_gr_zbc_clear_color(gr, zbc);
  86. return zbc;
  87. }
  88. static void
  89. gf100_gr_zbc_clear_depth(struct gf100_gr *gr, int zbc)
  90. {
  91. struct nvkm_device *device = gr->base.engine.subdev.device;
  92. if (gr->zbc_depth[zbc].format)
  93. nvkm_wr32(device, 0x405818, gr->zbc_depth[zbc].ds);
  94. nvkm_wr32(device, 0x40581c, gr->zbc_depth[zbc].format);
  95. nvkm_wr32(device, 0x405820, zbc);
  96. nvkm_wr32(device, 0x405824, 0x00000005); /* TRIGGER | WRITE | DEPTH */
  97. }
  98. static int
  99. gf100_gr_zbc_depth_get(struct gf100_gr *gr, int format,
  100. const u32 ds, const u32 l2)
  101. {
  102. struct nvkm_ltc *ltc = gr->base.engine.subdev.device->ltc;
  103. int zbc = -ENOSPC, i;
  104. for (i = ltc->zbc_min; i <= ltc->zbc_max; i++) {
  105. if (gr->zbc_depth[i].format) {
  106. if (gr->zbc_depth[i].format != format)
  107. continue;
  108. if (gr->zbc_depth[i].ds != ds)
  109. continue;
  110. if (gr->zbc_depth[i].l2 != l2) {
  111. WARN_ON(1);
  112. return -EINVAL;
  113. }
  114. return i;
  115. } else {
  116. zbc = (zbc < 0) ? i : zbc;
  117. }
  118. }
  119. if (zbc < 0)
  120. return zbc;
  121. gr->zbc_depth[zbc].format = format;
  122. gr->zbc_depth[zbc].ds = ds;
  123. gr->zbc_depth[zbc].l2 = l2;
  124. nvkm_ltc_zbc_depth_get(ltc, zbc, l2);
  125. gf100_gr_zbc_clear_depth(gr, zbc);
  126. return zbc;
  127. }
  128. /*******************************************************************************
  129. * Graphics object classes
  130. ******************************************************************************/
  131. #define gf100_gr_object(p) container_of((p), struct gf100_gr_object, object)
  132. struct gf100_gr_object {
  133. struct nvkm_object object;
  134. struct gf100_gr_chan *chan;
  135. };
  136. static int
  137. gf100_fermi_mthd_zbc_color(struct nvkm_object *object, void *data, u32 size)
  138. {
  139. struct gf100_gr *gr = gf100_gr(nvkm_gr(object->engine));
  140. union {
  141. struct fermi_a_zbc_color_v0 v0;
  142. } *args = data;
  143. int ret = -ENOSYS;
  144. if (!(ret = nvif_unpack(ret, &data, &size, args->v0, 0, 0, false))) {
  145. switch (args->v0.format) {
  146. case FERMI_A_ZBC_COLOR_V0_FMT_ZERO:
  147. case FERMI_A_ZBC_COLOR_V0_FMT_UNORM_ONE:
  148. case FERMI_A_ZBC_COLOR_V0_FMT_RF32_GF32_BF32_AF32:
  149. case FERMI_A_ZBC_COLOR_V0_FMT_R16_G16_B16_A16:
  150. case FERMI_A_ZBC_COLOR_V0_FMT_RN16_GN16_BN16_AN16:
  151. case FERMI_A_ZBC_COLOR_V0_FMT_RS16_GS16_BS16_AS16:
  152. case FERMI_A_ZBC_COLOR_V0_FMT_RU16_GU16_BU16_AU16:
  153. case FERMI_A_ZBC_COLOR_V0_FMT_RF16_GF16_BF16_AF16:
  154. case FERMI_A_ZBC_COLOR_V0_FMT_A8R8G8B8:
  155. case FERMI_A_ZBC_COLOR_V0_FMT_A8RL8GL8BL8:
  156. case FERMI_A_ZBC_COLOR_V0_FMT_A2B10G10R10:
  157. case FERMI_A_ZBC_COLOR_V0_FMT_AU2BU10GU10RU10:
  158. case FERMI_A_ZBC_COLOR_V0_FMT_A8B8G8R8:
  159. case FERMI_A_ZBC_COLOR_V0_FMT_A8BL8GL8RL8:
  160. case FERMI_A_ZBC_COLOR_V0_FMT_AN8BN8GN8RN8:
  161. case FERMI_A_ZBC_COLOR_V0_FMT_AS8BS8GS8RS8:
  162. case FERMI_A_ZBC_COLOR_V0_FMT_AU8BU8GU8RU8:
  163. case FERMI_A_ZBC_COLOR_V0_FMT_A2R10G10B10:
  164. case FERMI_A_ZBC_COLOR_V0_FMT_BF10GF11RF11:
  165. ret = gf100_gr_zbc_color_get(gr, args->v0.format,
  166. args->v0.ds,
  167. args->v0.l2);
  168. if (ret >= 0) {
  169. args->v0.index = ret;
  170. return 0;
  171. }
  172. break;
  173. default:
  174. return -EINVAL;
  175. }
  176. }
  177. return ret;
  178. }
  179. static int
  180. gf100_fermi_mthd_zbc_depth(struct nvkm_object *object, void *data, u32 size)
  181. {
  182. struct gf100_gr *gr = gf100_gr(nvkm_gr(object->engine));
  183. union {
  184. struct fermi_a_zbc_depth_v0 v0;
  185. } *args = data;
  186. int ret = -ENOSYS;
  187. if (!(ret = nvif_unpack(ret, &data, &size, args->v0, 0, 0, false))) {
  188. switch (args->v0.format) {
  189. case FERMI_A_ZBC_DEPTH_V0_FMT_FP32:
  190. ret = gf100_gr_zbc_depth_get(gr, args->v0.format,
  191. args->v0.ds,
  192. args->v0.l2);
  193. return (ret >= 0) ? 0 : -ENOSPC;
  194. default:
  195. return -EINVAL;
  196. }
  197. }
  198. return ret;
  199. }
  200. static int
  201. gf100_fermi_mthd(struct nvkm_object *object, u32 mthd, void *data, u32 size)
  202. {
  203. nvif_ioctl(object, "fermi mthd %08x\n", mthd);
  204. switch (mthd) {
  205. case FERMI_A_ZBC_COLOR:
  206. return gf100_fermi_mthd_zbc_color(object, data, size);
  207. case FERMI_A_ZBC_DEPTH:
  208. return gf100_fermi_mthd_zbc_depth(object, data, size);
  209. default:
  210. break;
  211. }
  212. return -EINVAL;
  213. }
  214. const struct nvkm_object_func
  215. gf100_fermi = {
  216. .mthd = gf100_fermi_mthd,
  217. };
  218. static void
  219. gf100_gr_mthd_set_shader_exceptions(struct nvkm_device *device, u32 data)
  220. {
  221. nvkm_wr32(device, 0x419e44, data ? 0xffffffff : 0x00000000);
  222. nvkm_wr32(device, 0x419e4c, data ? 0xffffffff : 0x00000000);
  223. }
  224. static bool
  225. gf100_gr_mthd_sw(struct nvkm_device *device, u16 class, u32 mthd, u32 data)
  226. {
  227. switch (class & 0x00ff) {
  228. case 0x97:
  229. case 0xc0:
  230. switch (mthd) {
  231. case 0x1528:
  232. gf100_gr_mthd_set_shader_exceptions(device, data);
  233. return true;
  234. default:
  235. break;
  236. }
  237. break;
  238. default:
  239. break;
  240. }
  241. return false;
  242. }
  243. static const struct nvkm_object_func
  244. gf100_gr_object_func = {
  245. };
  246. static int
  247. gf100_gr_object_new(const struct nvkm_oclass *oclass, void *data, u32 size,
  248. struct nvkm_object **pobject)
  249. {
  250. struct gf100_gr_chan *chan = gf100_gr_chan(oclass->parent);
  251. struct gf100_gr_object *object;
  252. if (!(object = kzalloc(sizeof(*object), GFP_KERNEL)))
  253. return -ENOMEM;
  254. *pobject = &object->object;
  255. nvkm_object_ctor(oclass->base.func ? oclass->base.func :
  256. &gf100_gr_object_func, oclass, &object->object);
  257. object->chan = chan;
  258. return 0;
  259. }
  260. static int
  261. gf100_gr_object_get(struct nvkm_gr *base, int index, struct nvkm_sclass *sclass)
  262. {
  263. struct gf100_gr *gr = gf100_gr(base);
  264. int c = 0;
  265. while (gr->func->sclass[c].oclass) {
  266. if (c++ == index) {
  267. *sclass = gr->func->sclass[index];
  268. sclass->ctor = gf100_gr_object_new;
  269. return index;
  270. }
  271. }
  272. return c;
  273. }
  274. /*******************************************************************************
  275. * PGRAPH context
  276. ******************************************************************************/
  277. static int
  278. gf100_gr_chan_bind(struct nvkm_object *object, struct nvkm_gpuobj *parent,
  279. int align, struct nvkm_gpuobj **pgpuobj)
  280. {
  281. struct gf100_gr_chan *chan = gf100_gr_chan(object);
  282. struct gf100_gr *gr = chan->gr;
  283. int ret, i;
  284. ret = nvkm_gpuobj_new(gr->base.engine.subdev.device, gr->size,
  285. align, false, parent, pgpuobj);
  286. if (ret)
  287. return ret;
  288. nvkm_kmap(*pgpuobj);
  289. for (i = 0; i < gr->size; i += 4)
  290. nvkm_wo32(*pgpuobj, i, gr->data[i / 4]);
  291. if (!gr->firmware) {
  292. nvkm_wo32(*pgpuobj, 0x00, chan->mmio_nr / 2);
  293. nvkm_wo32(*pgpuobj, 0x04, chan->mmio_vma.offset >> 8);
  294. } else {
  295. nvkm_wo32(*pgpuobj, 0xf4, 0);
  296. nvkm_wo32(*pgpuobj, 0xf8, 0);
  297. nvkm_wo32(*pgpuobj, 0x10, chan->mmio_nr / 2);
  298. nvkm_wo32(*pgpuobj, 0x14, lower_32_bits(chan->mmio_vma.offset));
  299. nvkm_wo32(*pgpuobj, 0x18, upper_32_bits(chan->mmio_vma.offset));
  300. nvkm_wo32(*pgpuobj, 0x1c, 1);
  301. nvkm_wo32(*pgpuobj, 0x20, 0);
  302. nvkm_wo32(*pgpuobj, 0x28, 0);
  303. nvkm_wo32(*pgpuobj, 0x2c, 0);
  304. }
  305. nvkm_done(*pgpuobj);
  306. return 0;
  307. }
  308. static void *
  309. gf100_gr_chan_dtor(struct nvkm_object *object)
  310. {
  311. struct gf100_gr_chan *chan = gf100_gr_chan(object);
  312. int i;
  313. for (i = 0; i < ARRAY_SIZE(chan->data); i++) {
  314. if (chan->data[i].vma.node) {
  315. nvkm_vm_unmap(&chan->data[i].vma);
  316. nvkm_vm_put(&chan->data[i].vma);
  317. }
  318. nvkm_memory_del(&chan->data[i].mem);
  319. }
  320. if (chan->mmio_vma.node) {
  321. nvkm_vm_unmap(&chan->mmio_vma);
  322. nvkm_vm_put(&chan->mmio_vma);
  323. }
  324. nvkm_memory_del(&chan->mmio);
  325. return chan;
  326. }
  327. static const struct nvkm_object_func
  328. gf100_gr_chan = {
  329. .dtor = gf100_gr_chan_dtor,
  330. .bind = gf100_gr_chan_bind,
  331. };
  332. static int
  333. gf100_gr_chan_new(struct nvkm_gr *base, struct nvkm_fifo_chan *fifoch,
  334. const struct nvkm_oclass *oclass,
  335. struct nvkm_object **pobject)
  336. {
  337. struct gf100_gr *gr = gf100_gr(base);
  338. struct gf100_gr_data *data = gr->mmio_data;
  339. struct gf100_gr_mmio *mmio = gr->mmio_list;
  340. struct gf100_gr_chan *chan;
  341. struct nvkm_device *device = gr->base.engine.subdev.device;
  342. int ret, i;
  343. if (!(chan = kzalloc(sizeof(*chan), GFP_KERNEL)))
  344. return -ENOMEM;
  345. nvkm_object_ctor(&gf100_gr_chan, oclass, &chan->object);
  346. chan->gr = gr;
  347. *pobject = &chan->object;
  348. /* allocate memory for a "mmio list" buffer that's used by the HUB
  349. * fuc to modify some per-context register settings on first load
  350. * of the context.
  351. */
  352. ret = nvkm_memory_new(device, NVKM_MEM_TARGET_INST, 0x1000, 0x100,
  353. false, &chan->mmio);
  354. if (ret)
  355. return ret;
  356. ret = nvkm_vm_get(fifoch->vm, 0x1000, 12, NV_MEM_ACCESS_RW |
  357. NV_MEM_ACCESS_SYS, &chan->mmio_vma);
  358. if (ret)
  359. return ret;
  360. nvkm_memory_map(chan->mmio, &chan->mmio_vma, 0);
  361. /* allocate buffers referenced by mmio list */
  362. for (i = 0; data->size && i < ARRAY_SIZE(gr->mmio_data); i++) {
  363. ret = nvkm_memory_new(device, NVKM_MEM_TARGET_INST,
  364. data->size, data->align, false,
  365. &chan->data[i].mem);
  366. if (ret)
  367. return ret;
  368. ret = nvkm_vm_get(fifoch->vm,
  369. nvkm_memory_size(chan->data[i].mem), 12,
  370. data->access, &chan->data[i].vma);
  371. if (ret)
  372. return ret;
  373. nvkm_memory_map(chan->data[i].mem, &chan->data[i].vma, 0);
  374. data++;
  375. }
  376. /* finally, fill in the mmio list and point the context at it */
  377. nvkm_kmap(chan->mmio);
  378. for (i = 0; mmio->addr && i < ARRAY_SIZE(gr->mmio_list); i++) {
  379. u32 addr = mmio->addr;
  380. u32 data = mmio->data;
  381. if (mmio->buffer >= 0) {
  382. u64 info = chan->data[mmio->buffer].vma.offset;
  383. data |= info >> mmio->shift;
  384. }
  385. nvkm_wo32(chan->mmio, chan->mmio_nr++ * 4, addr);
  386. nvkm_wo32(chan->mmio, chan->mmio_nr++ * 4, data);
  387. mmio++;
  388. }
  389. nvkm_done(chan->mmio);
  390. return 0;
  391. }
  392. /*******************************************************************************
  393. * PGRAPH register lists
  394. ******************************************************************************/
  395. const struct gf100_gr_init
  396. gf100_gr_init_main_0[] = {
  397. { 0x400080, 1, 0x04, 0x003083c2 },
  398. { 0x400088, 1, 0x04, 0x00006fe7 },
  399. { 0x40008c, 1, 0x04, 0x00000000 },
  400. { 0x400090, 1, 0x04, 0x00000030 },
  401. { 0x40013c, 1, 0x04, 0x013901f7 },
  402. { 0x400140, 1, 0x04, 0x00000100 },
  403. { 0x400144, 1, 0x04, 0x00000000 },
  404. { 0x400148, 1, 0x04, 0x00000110 },
  405. { 0x400138, 1, 0x04, 0x00000000 },
  406. { 0x400130, 2, 0x04, 0x00000000 },
  407. { 0x400124, 1, 0x04, 0x00000002 },
  408. {}
  409. };
  410. const struct gf100_gr_init
  411. gf100_gr_init_fe_0[] = {
  412. { 0x40415c, 1, 0x04, 0x00000000 },
  413. { 0x404170, 1, 0x04, 0x00000000 },
  414. {}
  415. };
  416. const struct gf100_gr_init
  417. gf100_gr_init_pri_0[] = {
  418. { 0x404488, 2, 0x04, 0x00000000 },
  419. {}
  420. };
  421. const struct gf100_gr_init
  422. gf100_gr_init_rstr2d_0[] = {
  423. { 0x407808, 1, 0x04, 0x00000000 },
  424. {}
  425. };
  426. const struct gf100_gr_init
  427. gf100_gr_init_pd_0[] = {
  428. { 0x406024, 1, 0x04, 0x00000000 },
  429. {}
  430. };
  431. const struct gf100_gr_init
  432. gf100_gr_init_ds_0[] = {
  433. { 0x405844, 1, 0x04, 0x00ffffff },
  434. { 0x405850, 1, 0x04, 0x00000000 },
  435. { 0x405908, 1, 0x04, 0x00000000 },
  436. {}
  437. };
  438. const struct gf100_gr_init
  439. gf100_gr_init_scc_0[] = {
  440. { 0x40803c, 1, 0x04, 0x00000000 },
  441. {}
  442. };
  443. const struct gf100_gr_init
  444. gf100_gr_init_prop_0[] = {
  445. { 0x4184a0, 1, 0x04, 0x00000000 },
  446. {}
  447. };
  448. const struct gf100_gr_init
  449. gf100_gr_init_gpc_unk_0[] = {
  450. { 0x418604, 1, 0x04, 0x00000000 },
  451. { 0x418680, 1, 0x04, 0x00000000 },
  452. { 0x418714, 1, 0x04, 0x80000000 },
  453. { 0x418384, 1, 0x04, 0x00000000 },
  454. {}
  455. };
  456. const struct gf100_gr_init
  457. gf100_gr_init_setup_0[] = {
  458. { 0x418814, 3, 0x04, 0x00000000 },
  459. {}
  460. };
  461. const struct gf100_gr_init
  462. gf100_gr_init_crstr_0[] = {
  463. { 0x418b04, 1, 0x04, 0x00000000 },
  464. {}
  465. };
  466. const struct gf100_gr_init
  467. gf100_gr_init_setup_1[] = {
  468. { 0x4188c8, 1, 0x04, 0x80000000 },
  469. { 0x4188cc, 1, 0x04, 0x00000000 },
  470. { 0x4188d0, 1, 0x04, 0x00010000 },
  471. { 0x4188d4, 1, 0x04, 0x00000001 },
  472. {}
  473. };
  474. const struct gf100_gr_init
  475. gf100_gr_init_zcull_0[] = {
  476. { 0x418910, 1, 0x04, 0x00010001 },
  477. { 0x418914, 1, 0x04, 0x00000301 },
  478. { 0x418918, 1, 0x04, 0x00800000 },
  479. { 0x418980, 1, 0x04, 0x77777770 },
  480. { 0x418984, 3, 0x04, 0x77777777 },
  481. {}
  482. };
  483. const struct gf100_gr_init
  484. gf100_gr_init_gpm_0[] = {
  485. { 0x418c04, 1, 0x04, 0x00000000 },
  486. { 0x418c88, 1, 0x04, 0x00000000 },
  487. {}
  488. };
  489. const struct gf100_gr_init
  490. gf100_gr_init_gpc_unk_1[] = {
  491. { 0x418d00, 1, 0x04, 0x00000000 },
  492. { 0x418f08, 1, 0x04, 0x00000000 },
  493. { 0x418e00, 1, 0x04, 0x00000050 },
  494. { 0x418e08, 1, 0x04, 0x00000000 },
  495. {}
  496. };
  497. const struct gf100_gr_init
  498. gf100_gr_init_gcc_0[] = {
  499. { 0x41900c, 1, 0x04, 0x00000000 },
  500. { 0x419018, 1, 0x04, 0x00000000 },
  501. {}
  502. };
  503. const struct gf100_gr_init
  504. gf100_gr_init_tpccs_0[] = {
  505. { 0x419d08, 2, 0x04, 0x00000000 },
  506. { 0x419d10, 1, 0x04, 0x00000014 },
  507. {}
  508. };
  509. const struct gf100_gr_init
  510. gf100_gr_init_tex_0[] = {
  511. { 0x419ab0, 1, 0x04, 0x00000000 },
  512. { 0x419ab8, 1, 0x04, 0x000000e7 },
  513. { 0x419abc, 2, 0x04, 0x00000000 },
  514. {}
  515. };
  516. const struct gf100_gr_init
  517. gf100_gr_init_pe_0[] = {
  518. { 0x41980c, 3, 0x04, 0x00000000 },
  519. { 0x419844, 1, 0x04, 0x00000000 },
  520. { 0x41984c, 1, 0x04, 0x00005bc5 },
  521. { 0x419850, 4, 0x04, 0x00000000 },
  522. {}
  523. };
  524. const struct gf100_gr_init
  525. gf100_gr_init_l1c_0[] = {
  526. { 0x419c98, 1, 0x04, 0x00000000 },
  527. { 0x419ca8, 1, 0x04, 0x80000000 },
  528. { 0x419cb4, 1, 0x04, 0x00000000 },
  529. { 0x419cb8, 1, 0x04, 0x00008bf4 },
  530. { 0x419cbc, 1, 0x04, 0x28137606 },
  531. { 0x419cc0, 2, 0x04, 0x00000000 },
  532. {}
  533. };
  534. const struct gf100_gr_init
  535. gf100_gr_init_wwdx_0[] = {
  536. { 0x419bd4, 1, 0x04, 0x00800000 },
  537. { 0x419bdc, 1, 0x04, 0x00000000 },
  538. {}
  539. };
  540. const struct gf100_gr_init
  541. gf100_gr_init_tpccs_1[] = {
  542. { 0x419d2c, 1, 0x04, 0x00000000 },
  543. {}
  544. };
  545. const struct gf100_gr_init
  546. gf100_gr_init_mpc_0[] = {
  547. { 0x419c0c, 1, 0x04, 0x00000000 },
  548. {}
  549. };
  550. static const struct gf100_gr_init
  551. gf100_gr_init_sm_0[] = {
  552. { 0x419e00, 1, 0x04, 0x00000000 },
  553. { 0x419ea0, 1, 0x04, 0x00000000 },
  554. { 0x419ea4, 1, 0x04, 0x00000100 },
  555. { 0x419ea8, 1, 0x04, 0x00001100 },
  556. { 0x419eac, 1, 0x04, 0x11100702 },
  557. { 0x419eb0, 1, 0x04, 0x00000003 },
  558. { 0x419eb4, 4, 0x04, 0x00000000 },
  559. { 0x419ec8, 1, 0x04, 0x06060618 },
  560. { 0x419ed0, 1, 0x04, 0x0eff0e38 },
  561. { 0x419ed4, 1, 0x04, 0x011104f1 },
  562. { 0x419edc, 1, 0x04, 0x00000000 },
  563. { 0x419f00, 1, 0x04, 0x00000000 },
  564. { 0x419f2c, 1, 0x04, 0x00000000 },
  565. {}
  566. };
  567. const struct gf100_gr_init
  568. gf100_gr_init_be_0[] = {
  569. { 0x40880c, 1, 0x04, 0x00000000 },
  570. { 0x408910, 9, 0x04, 0x00000000 },
  571. { 0x408950, 1, 0x04, 0x00000000 },
  572. { 0x408954, 1, 0x04, 0x0000ffff },
  573. { 0x408984, 1, 0x04, 0x00000000 },
  574. { 0x408988, 1, 0x04, 0x08040201 },
  575. { 0x40898c, 1, 0x04, 0x80402010 },
  576. {}
  577. };
  578. const struct gf100_gr_init
  579. gf100_gr_init_fe_1[] = {
  580. { 0x4040f0, 1, 0x04, 0x00000000 },
  581. {}
  582. };
  583. const struct gf100_gr_init
  584. gf100_gr_init_pe_1[] = {
  585. { 0x419880, 1, 0x04, 0x00000002 },
  586. {}
  587. };
  588. static const struct gf100_gr_pack
  589. gf100_gr_pack_mmio[] = {
  590. { gf100_gr_init_main_0 },
  591. { gf100_gr_init_fe_0 },
  592. { gf100_gr_init_pri_0 },
  593. { gf100_gr_init_rstr2d_0 },
  594. { gf100_gr_init_pd_0 },
  595. { gf100_gr_init_ds_0 },
  596. { gf100_gr_init_scc_0 },
  597. { gf100_gr_init_prop_0 },
  598. { gf100_gr_init_gpc_unk_0 },
  599. { gf100_gr_init_setup_0 },
  600. { gf100_gr_init_crstr_0 },
  601. { gf100_gr_init_setup_1 },
  602. { gf100_gr_init_zcull_0 },
  603. { gf100_gr_init_gpm_0 },
  604. { gf100_gr_init_gpc_unk_1 },
  605. { gf100_gr_init_gcc_0 },
  606. { gf100_gr_init_tpccs_0 },
  607. { gf100_gr_init_tex_0 },
  608. { gf100_gr_init_pe_0 },
  609. { gf100_gr_init_l1c_0 },
  610. { gf100_gr_init_wwdx_0 },
  611. { gf100_gr_init_tpccs_1 },
  612. { gf100_gr_init_mpc_0 },
  613. { gf100_gr_init_sm_0 },
  614. { gf100_gr_init_be_0 },
  615. { gf100_gr_init_fe_1 },
  616. { gf100_gr_init_pe_1 },
  617. {}
  618. };
  619. /*******************************************************************************
  620. * PGRAPH engine/subdev functions
  621. ******************************************************************************/
  622. static bool
  623. gf100_gr_chsw_load(struct nvkm_gr *base)
  624. {
  625. struct gf100_gr *gr = gf100_gr(base);
  626. if (!gr->firmware) {
  627. u32 trace = nvkm_rd32(gr->base.engine.subdev.device, 0x40981c);
  628. if (trace & 0x00000040)
  629. return true;
  630. } else {
  631. u32 mthd = nvkm_rd32(gr->base.engine.subdev.device, 0x409808);
  632. if (mthd & 0x00080000)
  633. return true;
  634. }
  635. return false;
  636. }
  637. int
  638. gf100_gr_rops(struct gf100_gr *gr)
  639. {
  640. struct nvkm_device *device = gr->base.engine.subdev.device;
  641. return (nvkm_rd32(device, 0x409604) & 0x001f0000) >> 16;
  642. }
  643. void
  644. gf100_gr_zbc_init(struct gf100_gr *gr)
  645. {
  646. const u32 zero[] = { 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  647. 0x00000000, 0x00000000, 0x00000000, 0x00000000 };
  648. const u32 one[] = { 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000,
  649. 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff };
  650. const u32 f32_0[] = { 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  651. 0x00000000, 0x00000000, 0x00000000, 0x00000000 };
  652. const u32 f32_1[] = { 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000,
  653. 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000 };
  654. struct nvkm_ltc *ltc = gr->base.engine.subdev.device->ltc;
  655. int index;
  656. if (!gr->zbc_color[0].format) {
  657. gf100_gr_zbc_color_get(gr, 1, & zero[0], &zero[4]);
  658. gf100_gr_zbc_color_get(gr, 2, & one[0], &one[4]);
  659. gf100_gr_zbc_color_get(gr, 4, &f32_0[0], &f32_0[4]);
  660. gf100_gr_zbc_color_get(gr, 4, &f32_1[0], &f32_1[4]);
  661. gf100_gr_zbc_depth_get(gr, 1, 0x00000000, 0x00000000);
  662. gf100_gr_zbc_depth_get(gr, 1, 0x3f800000, 0x3f800000);
  663. }
  664. for (index = ltc->zbc_min; index <= ltc->zbc_max; index++)
  665. gf100_gr_zbc_clear_color(gr, index);
  666. for (index = ltc->zbc_min; index <= ltc->zbc_max; index++)
  667. gf100_gr_zbc_clear_depth(gr, index);
  668. }
  669. /**
  670. * Wait until GR goes idle. GR is considered idle if it is disabled by the
  671. * MC (0x200) register, or GR is not busy and a context switch is not in
  672. * progress.
  673. */
  674. int
  675. gf100_gr_wait_idle(struct gf100_gr *gr)
  676. {
  677. struct nvkm_subdev *subdev = &gr->base.engine.subdev;
  678. struct nvkm_device *device = subdev->device;
  679. unsigned long end_jiffies = jiffies + msecs_to_jiffies(2000);
  680. bool gr_enabled, ctxsw_active, gr_busy;
  681. do {
  682. /*
  683. * required to make sure FIFO_ENGINE_STATUS (0x2640) is
  684. * up-to-date
  685. */
  686. nvkm_rd32(device, 0x400700);
  687. gr_enabled = nvkm_rd32(device, 0x200) & 0x1000;
  688. ctxsw_active = nvkm_rd32(device, 0x2640) & 0x8000;
  689. gr_busy = nvkm_rd32(device, 0x40060c) & 0x1;
  690. if (!gr_enabled || (!gr_busy && !ctxsw_active))
  691. return 0;
  692. } while (time_before(jiffies, end_jiffies));
  693. nvkm_error(subdev,
  694. "wait for idle timeout (en: %d, ctxsw: %d, busy: %d)\n",
  695. gr_enabled, ctxsw_active, gr_busy);
  696. return -EAGAIN;
  697. }
  698. void
  699. gf100_gr_mmio(struct gf100_gr *gr, const struct gf100_gr_pack *p)
  700. {
  701. struct nvkm_device *device = gr->base.engine.subdev.device;
  702. const struct gf100_gr_pack *pack;
  703. const struct gf100_gr_init *init;
  704. pack_for_each_init(init, pack, p) {
  705. u32 next = init->addr + init->count * init->pitch;
  706. u32 addr = init->addr;
  707. while (addr < next) {
  708. nvkm_wr32(device, addr, init->data);
  709. addr += init->pitch;
  710. }
  711. }
  712. }
  713. void
  714. gf100_gr_icmd(struct gf100_gr *gr, const struct gf100_gr_pack *p)
  715. {
  716. struct nvkm_device *device = gr->base.engine.subdev.device;
  717. const struct gf100_gr_pack *pack;
  718. const struct gf100_gr_init *init;
  719. u32 data = 0;
  720. nvkm_wr32(device, 0x400208, 0x80000000);
  721. pack_for_each_init(init, pack, p) {
  722. u32 next = init->addr + init->count * init->pitch;
  723. u32 addr = init->addr;
  724. if ((pack == p && init == p->init) || data != init->data) {
  725. nvkm_wr32(device, 0x400204, init->data);
  726. data = init->data;
  727. }
  728. while (addr < next) {
  729. nvkm_wr32(device, 0x400200, addr);
  730. /**
  731. * Wait for GR to go idle after submitting a
  732. * GO_IDLE bundle
  733. */
  734. if ((addr & 0xffff) == 0xe100)
  735. gf100_gr_wait_idle(gr);
  736. nvkm_msec(device, 2000,
  737. if (!(nvkm_rd32(device, 0x400700) & 0x00000004))
  738. break;
  739. );
  740. addr += init->pitch;
  741. }
  742. }
  743. nvkm_wr32(device, 0x400208, 0x00000000);
  744. }
  745. void
  746. gf100_gr_mthd(struct gf100_gr *gr, const struct gf100_gr_pack *p)
  747. {
  748. struct nvkm_device *device = gr->base.engine.subdev.device;
  749. const struct gf100_gr_pack *pack;
  750. const struct gf100_gr_init *init;
  751. u32 data = 0;
  752. pack_for_each_init(init, pack, p) {
  753. u32 ctrl = 0x80000000 | pack->type;
  754. u32 next = init->addr + init->count * init->pitch;
  755. u32 addr = init->addr;
  756. if ((pack == p && init == p->init) || data != init->data) {
  757. nvkm_wr32(device, 0x40448c, init->data);
  758. data = init->data;
  759. }
  760. while (addr < next) {
  761. nvkm_wr32(device, 0x404488, ctrl | (addr << 14));
  762. addr += init->pitch;
  763. }
  764. }
  765. }
  766. u64
  767. gf100_gr_units(struct nvkm_gr *base)
  768. {
  769. struct gf100_gr *gr = gf100_gr(base);
  770. u64 cfg;
  771. cfg = (u32)gr->gpc_nr;
  772. cfg |= (u32)gr->tpc_total << 8;
  773. cfg |= (u64)gr->rop_nr << 32;
  774. return cfg;
  775. }
  776. static const struct nvkm_bitfield gf100_dispatch_error[] = {
  777. { 0x00000001, "INJECTED_BUNDLE_ERROR" },
  778. { 0x00000002, "CLASS_SUBCH_MISMATCH" },
  779. { 0x00000004, "SUBCHSW_DURING_NOTIFY" },
  780. {}
  781. };
  782. static const struct nvkm_bitfield gf100_m2mf_error[] = {
  783. { 0x00000001, "PUSH_TOO_MUCH_DATA" },
  784. { 0x00000002, "PUSH_NOT_ENOUGH_DATA" },
  785. {}
  786. };
  787. static const struct nvkm_bitfield gf100_unk6_error[] = {
  788. { 0x00000001, "TEMP_TOO_SMALL" },
  789. {}
  790. };
  791. static const struct nvkm_bitfield gf100_ccache_error[] = {
  792. { 0x00000001, "INTR" },
  793. { 0x00000002, "LDCONST_OOB" },
  794. {}
  795. };
  796. static const struct nvkm_bitfield gf100_macro_error[] = {
  797. { 0x00000001, "TOO_FEW_PARAMS" },
  798. { 0x00000002, "TOO_MANY_PARAMS" },
  799. { 0x00000004, "ILLEGAL_OPCODE" },
  800. { 0x00000008, "DOUBLE_BRANCH" },
  801. { 0x00000010, "WATCHDOG" },
  802. {}
  803. };
  804. static const struct nvkm_bitfield gk104_sked_error[] = {
  805. { 0x00000040, "CTA_RESUME" },
  806. { 0x00000080, "CONSTANT_BUFFER_SIZE" },
  807. { 0x00000200, "LOCAL_MEMORY_SIZE_POS" },
  808. { 0x00000400, "LOCAL_MEMORY_SIZE_NEG" },
  809. { 0x00000800, "WARP_CSTACK_SIZE" },
  810. { 0x00001000, "TOTAL_TEMP_SIZE" },
  811. { 0x00002000, "REGISTER_COUNT" },
  812. { 0x00040000, "TOTAL_THREADS" },
  813. { 0x00100000, "PROGRAM_OFFSET" },
  814. { 0x00200000, "SHARED_MEMORY_SIZE" },
  815. { 0x00800000, "CTA_THREAD_DIMENSION_ZERO" },
  816. { 0x01000000, "MEMORY_WINDOW_OVERLAP" },
  817. { 0x02000000, "SHARED_CONFIG_TOO_SMALL" },
  818. { 0x04000000, "TOTAL_REGISTER_COUNT" },
  819. {}
  820. };
  821. static const struct nvkm_bitfield gf100_gpc_rop_error[] = {
  822. { 0x00000002, "RT_PITCH_OVERRUN" },
  823. { 0x00000010, "RT_WIDTH_OVERRUN" },
  824. { 0x00000020, "RT_HEIGHT_OVERRUN" },
  825. { 0x00000080, "ZETA_STORAGE_TYPE_MISMATCH" },
  826. { 0x00000100, "RT_STORAGE_TYPE_MISMATCH" },
  827. { 0x00000400, "RT_LINEAR_MISMATCH" },
  828. {}
  829. };
  830. static void
  831. gf100_gr_trap_gpc_rop(struct gf100_gr *gr, int gpc)
  832. {
  833. struct nvkm_subdev *subdev = &gr->base.engine.subdev;
  834. struct nvkm_device *device = subdev->device;
  835. char error[128];
  836. u32 trap[4];
  837. trap[0] = nvkm_rd32(device, GPC_UNIT(gpc, 0x0420)) & 0x3fffffff;
  838. trap[1] = nvkm_rd32(device, GPC_UNIT(gpc, 0x0434));
  839. trap[2] = nvkm_rd32(device, GPC_UNIT(gpc, 0x0438));
  840. trap[3] = nvkm_rd32(device, GPC_UNIT(gpc, 0x043c));
  841. nvkm_snprintbf(error, sizeof(error), gf100_gpc_rop_error, trap[0]);
  842. nvkm_error(subdev, "GPC%d/PROP trap: %08x [%s] x = %u, y = %u, "
  843. "format = %x, storage type = %x\n",
  844. gpc, trap[0], error, trap[1] & 0xffff, trap[1] >> 16,
  845. (trap[2] >> 8) & 0x3f, trap[3] & 0xff);
  846. nvkm_wr32(device, GPC_UNIT(gpc, 0x0420), 0xc0000000);
  847. }
  848. static const struct nvkm_enum gf100_mp_warp_error[] = {
  849. { 0x01, "STACK_ERROR" },
  850. { 0x02, "API_STACK_ERROR" },
  851. { 0x03, "RET_EMPTY_STACK_ERROR" },
  852. { 0x04, "PC_WRAP" },
  853. { 0x05, "MISALIGNED_PC" },
  854. { 0x06, "PC_OVERFLOW" },
  855. { 0x07, "MISALIGNED_IMMC_ADDR" },
  856. { 0x08, "MISALIGNED_REG" },
  857. { 0x09, "ILLEGAL_INSTR_ENCODING" },
  858. { 0x0a, "ILLEGAL_SPH_INSTR_COMBO" },
  859. { 0x0b, "ILLEGAL_INSTR_PARAM" },
  860. { 0x0c, "INVALID_CONST_ADDR" },
  861. { 0x0d, "OOR_REG" },
  862. { 0x0e, "OOR_ADDR" },
  863. { 0x0f, "MISALIGNED_ADDR" },
  864. { 0x10, "INVALID_ADDR_SPACE" },
  865. { 0x11, "ILLEGAL_INSTR_PARAM2" },
  866. { 0x12, "INVALID_CONST_ADDR_LDC" },
  867. { 0x13, "GEOMETRY_SM_ERROR" },
  868. { 0x14, "DIVERGENT" },
  869. { 0x15, "WARP_EXIT" },
  870. {}
  871. };
  872. static const struct nvkm_bitfield gf100_mp_global_error[] = {
  873. { 0x00000001, "SM_TO_SM_FAULT" },
  874. { 0x00000002, "L1_ERROR" },
  875. { 0x00000004, "MULTIPLE_WARP_ERRORS" },
  876. { 0x00000008, "PHYSICAL_STACK_OVERFLOW" },
  877. { 0x00000010, "BPT_INT" },
  878. { 0x00000020, "BPT_PAUSE" },
  879. { 0x00000040, "SINGLE_STEP_COMPLETE" },
  880. { 0x20000000, "ECC_SEC_ERROR" },
  881. { 0x40000000, "ECC_DED_ERROR" },
  882. { 0x80000000, "TIMEOUT" },
  883. {}
  884. };
  885. static void
  886. gf100_gr_trap_mp(struct gf100_gr *gr, int gpc, int tpc)
  887. {
  888. struct nvkm_subdev *subdev = &gr->base.engine.subdev;
  889. struct nvkm_device *device = subdev->device;
  890. u32 werr = nvkm_rd32(device, TPC_UNIT(gpc, tpc, 0x648));
  891. u32 gerr = nvkm_rd32(device, TPC_UNIT(gpc, tpc, 0x650));
  892. const struct nvkm_enum *warp;
  893. char glob[128];
  894. nvkm_snprintbf(glob, sizeof(glob), gf100_mp_global_error, gerr);
  895. warp = nvkm_enum_find(gf100_mp_warp_error, werr & 0xffff);
  896. nvkm_error(subdev, "GPC%i/TPC%i/MP trap: "
  897. "global %08x [%s] warp %04x [%s]\n",
  898. gpc, tpc, gerr, glob, werr, warp ? warp->name : "");
  899. nvkm_wr32(device, TPC_UNIT(gpc, tpc, 0x648), 0x00000000);
  900. nvkm_wr32(device, TPC_UNIT(gpc, tpc, 0x650), gerr);
  901. }
  902. static void
  903. gf100_gr_trap_tpc(struct gf100_gr *gr, int gpc, int tpc)
  904. {
  905. struct nvkm_subdev *subdev = &gr->base.engine.subdev;
  906. struct nvkm_device *device = subdev->device;
  907. u32 stat = nvkm_rd32(device, TPC_UNIT(gpc, tpc, 0x0508));
  908. if (stat & 0x00000001) {
  909. u32 trap = nvkm_rd32(device, TPC_UNIT(gpc, tpc, 0x0224));
  910. nvkm_error(subdev, "GPC%d/TPC%d/TEX: %08x\n", gpc, tpc, trap);
  911. nvkm_wr32(device, TPC_UNIT(gpc, tpc, 0x0224), 0xc0000000);
  912. stat &= ~0x00000001;
  913. }
  914. if (stat & 0x00000002) {
  915. gf100_gr_trap_mp(gr, gpc, tpc);
  916. stat &= ~0x00000002;
  917. }
  918. if (stat & 0x00000004) {
  919. u32 trap = nvkm_rd32(device, TPC_UNIT(gpc, tpc, 0x0084));
  920. nvkm_error(subdev, "GPC%d/TPC%d/POLY: %08x\n", gpc, tpc, trap);
  921. nvkm_wr32(device, TPC_UNIT(gpc, tpc, 0x0084), 0xc0000000);
  922. stat &= ~0x00000004;
  923. }
  924. if (stat & 0x00000008) {
  925. u32 trap = nvkm_rd32(device, TPC_UNIT(gpc, tpc, 0x048c));
  926. nvkm_error(subdev, "GPC%d/TPC%d/L1C: %08x\n", gpc, tpc, trap);
  927. nvkm_wr32(device, TPC_UNIT(gpc, tpc, 0x048c), 0xc0000000);
  928. stat &= ~0x00000008;
  929. }
  930. if (stat & 0x00000010) {
  931. u32 trap = nvkm_rd32(device, TPC_UNIT(gpc, tpc, 0x0430));
  932. nvkm_error(subdev, "GPC%d/TPC%d/MPC: %08x\n", gpc, tpc, trap);
  933. nvkm_wr32(device, TPC_UNIT(gpc, tpc, 0x0430), 0xc0000000);
  934. stat &= ~0x00000010;
  935. }
  936. if (stat) {
  937. nvkm_error(subdev, "GPC%d/TPC%d/%08x: unknown\n", gpc, tpc, stat);
  938. }
  939. }
  940. static void
  941. gf100_gr_trap_gpc(struct gf100_gr *gr, int gpc)
  942. {
  943. struct nvkm_subdev *subdev = &gr->base.engine.subdev;
  944. struct nvkm_device *device = subdev->device;
  945. u32 stat = nvkm_rd32(device, GPC_UNIT(gpc, 0x2c90));
  946. int tpc;
  947. if (stat & 0x00000001) {
  948. gf100_gr_trap_gpc_rop(gr, gpc);
  949. stat &= ~0x00000001;
  950. }
  951. if (stat & 0x00000002) {
  952. u32 trap = nvkm_rd32(device, GPC_UNIT(gpc, 0x0900));
  953. nvkm_error(subdev, "GPC%d/ZCULL: %08x\n", gpc, trap);
  954. nvkm_wr32(device, GPC_UNIT(gpc, 0x0900), 0xc0000000);
  955. stat &= ~0x00000002;
  956. }
  957. if (stat & 0x00000004) {
  958. u32 trap = nvkm_rd32(device, GPC_UNIT(gpc, 0x1028));
  959. nvkm_error(subdev, "GPC%d/CCACHE: %08x\n", gpc, trap);
  960. nvkm_wr32(device, GPC_UNIT(gpc, 0x1028), 0xc0000000);
  961. stat &= ~0x00000004;
  962. }
  963. if (stat & 0x00000008) {
  964. u32 trap = nvkm_rd32(device, GPC_UNIT(gpc, 0x0824));
  965. nvkm_error(subdev, "GPC%d/ESETUP: %08x\n", gpc, trap);
  966. nvkm_wr32(device, GPC_UNIT(gpc, 0x0824), 0xc0000000);
  967. stat &= ~0x00000009;
  968. }
  969. for (tpc = 0; tpc < gr->tpc_nr[gpc]; tpc++) {
  970. u32 mask = 0x00010000 << tpc;
  971. if (stat & mask) {
  972. gf100_gr_trap_tpc(gr, gpc, tpc);
  973. nvkm_wr32(device, GPC_UNIT(gpc, 0x2c90), mask);
  974. stat &= ~mask;
  975. }
  976. }
  977. if (stat) {
  978. nvkm_error(subdev, "GPC%d/%08x: unknown\n", gpc, stat);
  979. }
  980. }
  981. static void
  982. gf100_gr_trap_intr(struct gf100_gr *gr)
  983. {
  984. struct nvkm_subdev *subdev = &gr->base.engine.subdev;
  985. struct nvkm_device *device = subdev->device;
  986. char error[128];
  987. u32 trap = nvkm_rd32(device, 0x400108);
  988. int rop, gpc;
  989. if (trap & 0x00000001) {
  990. u32 stat = nvkm_rd32(device, 0x404000);
  991. nvkm_snprintbf(error, sizeof(error), gf100_dispatch_error,
  992. stat & 0x3fffffff);
  993. nvkm_error(subdev, "DISPATCH %08x [%s]\n", stat, error);
  994. nvkm_wr32(device, 0x404000, 0xc0000000);
  995. nvkm_wr32(device, 0x400108, 0x00000001);
  996. trap &= ~0x00000001;
  997. }
  998. if (trap & 0x00000002) {
  999. u32 stat = nvkm_rd32(device, 0x404600);
  1000. nvkm_snprintbf(error, sizeof(error), gf100_m2mf_error,
  1001. stat & 0x3fffffff);
  1002. nvkm_error(subdev, "M2MF %08x [%s]\n", stat, error);
  1003. nvkm_wr32(device, 0x404600, 0xc0000000);
  1004. nvkm_wr32(device, 0x400108, 0x00000002);
  1005. trap &= ~0x00000002;
  1006. }
  1007. if (trap & 0x00000008) {
  1008. u32 stat = nvkm_rd32(device, 0x408030);
  1009. nvkm_snprintbf(error, sizeof(error), gf100_ccache_error,
  1010. stat & 0x3fffffff);
  1011. nvkm_error(subdev, "CCACHE %08x [%s]\n", stat, error);
  1012. nvkm_wr32(device, 0x408030, 0xc0000000);
  1013. nvkm_wr32(device, 0x400108, 0x00000008);
  1014. trap &= ~0x00000008;
  1015. }
  1016. if (trap & 0x00000010) {
  1017. u32 stat = nvkm_rd32(device, 0x405840);
  1018. nvkm_error(subdev, "SHADER %08x, sph: 0x%06x, stage: 0x%02x\n",
  1019. stat, stat & 0xffffff, (stat >> 24) & 0x3f);
  1020. nvkm_wr32(device, 0x405840, 0xc0000000);
  1021. nvkm_wr32(device, 0x400108, 0x00000010);
  1022. trap &= ~0x00000010;
  1023. }
  1024. if (trap & 0x00000040) {
  1025. u32 stat = nvkm_rd32(device, 0x40601c);
  1026. nvkm_snprintbf(error, sizeof(error), gf100_unk6_error,
  1027. stat & 0x3fffffff);
  1028. nvkm_error(subdev, "UNK6 %08x [%s]\n", stat, error);
  1029. nvkm_wr32(device, 0x40601c, 0xc0000000);
  1030. nvkm_wr32(device, 0x400108, 0x00000040);
  1031. trap &= ~0x00000040;
  1032. }
  1033. if (trap & 0x00000080) {
  1034. u32 stat = nvkm_rd32(device, 0x404490);
  1035. u32 pc = nvkm_rd32(device, 0x404494);
  1036. u32 op = nvkm_rd32(device, 0x40449c);
  1037. nvkm_snprintbf(error, sizeof(error), gf100_macro_error,
  1038. stat & 0x1fffffff);
  1039. nvkm_error(subdev, "MACRO %08x [%s], pc: 0x%03x%s, op: 0x%08x\n",
  1040. stat, error, pc & 0x7ff,
  1041. (pc & 0x10000000) ? "" : " (invalid)",
  1042. op);
  1043. nvkm_wr32(device, 0x404490, 0xc0000000);
  1044. nvkm_wr32(device, 0x400108, 0x00000080);
  1045. trap &= ~0x00000080;
  1046. }
  1047. if (trap & 0x00000100) {
  1048. u32 stat = nvkm_rd32(device, 0x407020) & 0x3fffffff;
  1049. nvkm_snprintbf(error, sizeof(error), gk104_sked_error, stat);
  1050. nvkm_error(subdev, "SKED: %08x [%s]\n", stat, error);
  1051. if (stat)
  1052. nvkm_wr32(device, 0x407020, 0x40000000);
  1053. nvkm_wr32(device, 0x400108, 0x00000100);
  1054. trap &= ~0x00000100;
  1055. }
  1056. if (trap & 0x01000000) {
  1057. u32 stat = nvkm_rd32(device, 0x400118);
  1058. for (gpc = 0; stat && gpc < gr->gpc_nr; gpc++) {
  1059. u32 mask = 0x00000001 << gpc;
  1060. if (stat & mask) {
  1061. gf100_gr_trap_gpc(gr, gpc);
  1062. nvkm_wr32(device, 0x400118, mask);
  1063. stat &= ~mask;
  1064. }
  1065. }
  1066. nvkm_wr32(device, 0x400108, 0x01000000);
  1067. trap &= ~0x01000000;
  1068. }
  1069. if (trap & 0x02000000) {
  1070. for (rop = 0; rop < gr->rop_nr; rop++) {
  1071. u32 statz = nvkm_rd32(device, ROP_UNIT(rop, 0x070));
  1072. u32 statc = nvkm_rd32(device, ROP_UNIT(rop, 0x144));
  1073. nvkm_error(subdev, "ROP%d %08x %08x\n",
  1074. rop, statz, statc);
  1075. nvkm_wr32(device, ROP_UNIT(rop, 0x070), 0xc0000000);
  1076. nvkm_wr32(device, ROP_UNIT(rop, 0x144), 0xc0000000);
  1077. }
  1078. nvkm_wr32(device, 0x400108, 0x02000000);
  1079. trap &= ~0x02000000;
  1080. }
  1081. if (trap) {
  1082. nvkm_error(subdev, "TRAP UNHANDLED %08x\n", trap);
  1083. nvkm_wr32(device, 0x400108, trap);
  1084. }
  1085. }
  1086. static void
  1087. gf100_gr_ctxctl_debug_unit(struct gf100_gr *gr, u32 base)
  1088. {
  1089. struct nvkm_subdev *subdev = &gr->base.engine.subdev;
  1090. struct nvkm_device *device = subdev->device;
  1091. nvkm_error(subdev, "%06x - done %08x\n", base,
  1092. nvkm_rd32(device, base + 0x400));
  1093. nvkm_error(subdev, "%06x - stat %08x %08x %08x %08x\n", base,
  1094. nvkm_rd32(device, base + 0x800),
  1095. nvkm_rd32(device, base + 0x804),
  1096. nvkm_rd32(device, base + 0x808),
  1097. nvkm_rd32(device, base + 0x80c));
  1098. nvkm_error(subdev, "%06x - stat %08x %08x %08x %08x\n", base,
  1099. nvkm_rd32(device, base + 0x810),
  1100. nvkm_rd32(device, base + 0x814),
  1101. nvkm_rd32(device, base + 0x818),
  1102. nvkm_rd32(device, base + 0x81c));
  1103. }
  1104. void
  1105. gf100_gr_ctxctl_debug(struct gf100_gr *gr)
  1106. {
  1107. struct nvkm_device *device = gr->base.engine.subdev.device;
  1108. u32 gpcnr = nvkm_rd32(device, 0x409604) & 0xffff;
  1109. u32 gpc;
  1110. gf100_gr_ctxctl_debug_unit(gr, 0x409000);
  1111. for (gpc = 0; gpc < gpcnr; gpc++)
  1112. gf100_gr_ctxctl_debug_unit(gr, 0x502000 + (gpc * 0x8000));
  1113. }
  1114. static void
  1115. gf100_gr_ctxctl_isr(struct gf100_gr *gr)
  1116. {
  1117. struct nvkm_subdev *subdev = &gr->base.engine.subdev;
  1118. struct nvkm_device *device = subdev->device;
  1119. u32 stat = nvkm_rd32(device, 0x409c18);
  1120. if (!gr->firmware && (stat & 0x00000001)) {
  1121. u32 code = nvkm_rd32(device, 0x409814);
  1122. if (code == E_BAD_FWMTHD) {
  1123. u32 class = nvkm_rd32(device, 0x409808);
  1124. u32 addr = nvkm_rd32(device, 0x40980c);
  1125. u32 subc = (addr & 0x00070000) >> 16;
  1126. u32 mthd = (addr & 0x00003ffc);
  1127. u32 data = nvkm_rd32(device, 0x409810);
  1128. nvkm_error(subdev, "FECS MTHD subc %d class %04x "
  1129. "mthd %04x data %08x\n",
  1130. subc, class, mthd, data);
  1131. } else {
  1132. nvkm_error(subdev, "FECS ucode error %d\n", code);
  1133. }
  1134. nvkm_wr32(device, 0x409c20, 0x00000001);
  1135. stat &= ~0x00000001;
  1136. }
  1137. if (!gr->firmware && (stat & 0x00080000)) {
  1138. nvkm_error(subdev, "FECS watchdog timeout\n");
  1139. gf100_gr_ctxctl_debug(gr);
  1140. nvkm_wr32(device, 0x409c20, 0x00080000);
  1141. stat &= ~0x00080000;
  1142. }
  1143. if (stat) {
  1144. nvkm_error(subdev, "FECS %08x\n", stat);
  1145. gf100_gr_ctxctl_debug(gr);
  1146. nvkm_wr32(device, 0x409c20, stat);
  1147. }
  1148. }
  1149. static void
  1150. gf100_gr_intr(struct nvkm_gr *base)
  1151. {
  1152. struct gf100_gr *gr = gf100_gr(base);
  1153. struct nvkm_subdev *subdev = &gr->base.engine.subdev;
  1154. struct nvkm_device *device = subdev->device;
  1155. struct nvkm_fifo_chan *chan;
  1156. unsigned long flags;
  1157. u64 inst = nvkm_rd32(device, 0x409b00) & 0x0fffffff;
  1158. u32 stat = nvkm_rd32(device, 0x400100);
  1159. u32 addr = nvkm_rd32(device, 0x400704);
  1160. u32 mthd = (addr & 0x00003ffc);
  1161. u32 subc = (addr & 0x00070000) >> 16;
  1162. u32 data = nvkm_rd32(device, 0x400708);
  1163. u32 code = nvkm_rd32(device, 0x400110);
  1164. u32 class;
  1165. const char *name = "unknown";
  1166. int chid = -1;
  1167. chan = nvkm_fifo_chan_inst(device->fifo, (u64)inst << 12, &flags);
  1168. if (chan) {
  1169. name = chan->object.client->name;
  1170. chid = chan->chid;
  1171. }
  1172. if (device->card_type < NV_E0 || subc < 4)
  1173. class = nvkm_rd32(device, 0x404200 + (subc * 4));
  1174. else
  1175. class = 0x0000;
  1176. if (stat & 0x00000001) {
  1177. /*
  1178. * notifier interrupt, only needed for cyclestats
  1179. * can be safely ignored
  1180. */
  1181. nvkm_wr32(device, 0x400100, 0x00000001);
  1182. stat &= ~0x00000001;
  1183. }
  1184. if (stat & 0x00000010) {
  1185. if (!gf100_gr_mthd_sw(device, class, mthd, data)) {
  1186. nvkm_error(subdev, "ILLEGAL_MTHD ch %d [%010llx %s] "
  1187. "subc %d class %04x mthd %04x data %08x\n",
  1188. chid, inst << 12, name, subc,
  1189. class, mthd, data);
  1190. }
  1191. nvkm_wr32(device, 0x400100, 0x00000010);
  1192. stat &= ~0x00000010;
  1193. }
  1194. if (stat & 0x00000020) {
  1195. nvkm_error(subdev, "ILLEGAL_CLASS ch %d [%010llx %s] "
  1196. "subc %d class %04x mthd %04x data %08x\n",
  1197. chid, inst << 12, name, subc, class, mthd, data);
  1198. nvkm_wr32(device, 0x400100, 0x00000020);
  1199. stat &= ~0x00000020;
  1200. }
  1201. if (stat & 0x00100000) {
  1202. const struct nvkm_enum *en =
  1203. nvkm_enum_find(nv50_data_error_names, code);
  1204. nvkm_error(subdev, "DATA_ERROR %08x [%s] ch %d [%010llx %s] "
  1205. "subc %d class %04x mthd %04x data %08x\n",
  1206. code, en ? en->name : "", chid, inst << 12,
  1207. name, subc, class, mthd, data);
  1208. nvkm_wr32(device, 0x400100, 0x00100000);
  1209. stat &= ~0x00100000;
  1210. }
  1211. if (stat & 0x00200000) {
  1212. nvkm_error(subdev, "TRAP ch %d [%010llx %s]\n",
  1213. chid, inst << 12, name);
  1214. gf100_gr_trap_intr(gr);
  1215. nvkm_wr32(device, 0x400100, 0x00200000);
  1216. stat &= ~0x00200000;
  1217. }
  1218. if (stat & 0x00080000) {
  1219. gf100_gr_ctxctl_isr(gr);
  1220. nvkm_wr32(device, 0x400100, 0x00080000);
  1221. stat &= ~0x00080000;
  1222. }
  1223. if (stat) {
  1224. nvkm_error(subdev, "intr %08x\n", stat);
  1225. nvkm_wr32(device, 0x400100, stat);
  1226. }
  1227. nvkm_wr32(device, 0x400500, 0x00010001);
  1228. nvkm_fifo_chan_put(device->fifo, flags, &chan);
  1229. }
  1230. static void
  1231. gf100_gr_init_fw(struct nvkm_falcon *falcon,
  1232. struct gf100_gr_fuc *code, struct gf100_gr_fuc *data)
  1233. {
  1234. nvkm_falcon_load_dmem(falcon, data->data, 0x0, data->size, 0);
  1235. nvkm_falcon_load_imem(falcon, code->data, 0x0, code->size, 0, 0, false);
  1236. }
  1237. static void
  1238. gf100_gr_init_csdata(struct gf100_gr *gr,
  1239. const struct gf100_gr_pack *pack,
  1240. u32 falcon, u32 starstar, u32 base)
  1241. {
  1242. struct nvkm_device *device = gr->base.engine.subdev.device;
  1243. const struct gf100_gr_pack *iter;
  1244. const struct gf100_gr_init *init;
  1245. u32 addr = ~0, prev = ~0, xfer = 0;
  1246. u32 star, temp;
  1247. nvkm_wr32(device, falcon + 0x01c0, 0x02000000 + starstar);
  1248. star = nvkm_rd32(device, falcon + 0x01c4);
  1249. temp = nvkm_rd32(device, falcon + 0x01c4);
  1250. if (temp > star)
  1251. star = temp;
  1252. nvkm_wr32(device, falcon + 0x01c0, 0x01000000 + star);
  1253. pack_for_each_init(init, iter, pack) {
  1254. u32 head = init->addr - base;
  1255. u32 tail = head + init->count * init->pitch;
  1256. while (head < tail) {
  1257. if (head != prev + 4 || xfer >= 32) {
  1258. if (xfer) {
  1259. u32 data = ((--xfer << 26) | addr);
  1260. nvkm_wr32(device, falcon + 0x01c4, data);
  1261. star += 4;
  1262. }
  1263. addr = head;
  1264. xfer = 0;
  1265. }
  1266. prev = head;
  1267. xfer = xfer + 1;
  1268. head = head + init->pitch;
  1269. }
  1270. }
  1271. nvkm_wr32(device, falcon + 0x01c4, (--xfer << 26) | addr);
  1272. nvkm_wr32(device, falcon + 0x01c0, 0x01000004 + starstar);
  1273. nvkm_wr32(device, falcon + 0x01c4, star + 4);
  1274. }
  1275. /* Initialize context from an external (secure or not) firmware */
  1276. static int
  1277. gf100_gr_init_ctxctl_ext(struct gf100_gr *gr)
  1278. {
  1279. struct nvkm_subdev *subdev = &gr->base.engine.subdev;
  1280. struct nvkm_device *device = subdev->device;
  1281. struct nvkm_secboot *sb = device->secboot;
  1282. u32 secboot_mask = 0;
  1283. /* load fuc microcode */
  1284. nvkm_mc_unk260(device, 0);
  1285. /* securely-managed falcons must be reset using secure boot */
  1286. if (nvkm_secboot_is_managed(sb, NVKM_SECBOOT_FALCON_FECS))
  1287. secboot_mask |= BIT(NVKM_SECBOOT_FALCON_FECS);
  1288. else
  1289. gf100_gr_init_fw(gr->fecs, &gr->fuc409c, &gr->fuc409d);
  1290. if (nvkm_secboot_is_managed(sb, NVKM_SECBOOT_FALCON_GPCCS))
  1291. secboot_mask |= BIT(NVKM_SECBOOT_FALCON_GPCCS);
  1292. else
  1293. gf100_gr_init_fw(gr->gpccs, &gr->fuc41ac, &gr->fuc41ad);
  1294. if (secboot_mask != 0) {
  1295. int ret = nvkm_secboot_reset(sb, secboot_mask);
  1296. if (ret)
  1297. return ret;
  1298. }
  1299. nvkm_mc_unk260(device, 1);
  1300. /* start both of them running */
  1301. nvkm_wr32(device, 0x409840, 0xffffffff);
  1302. nvkm_wr32(device, 0x41a10c, 0x00000000);
  1303. nvkm_wr32(device, 0x40910c, 0x00000000);
  1304. nvkm_falcon_start(gr->gpccs);
  1305. nvkm_falcon_start(gr->fecs);
  1306. if (nvkm_msec(device, 2000,
  1307. if (nvkm_rd32(device, 0x409800) & 0x00000001)
  1308. break;
  1309. ) < 0)
  1310. return -EBUSY;
  1311. nvkm_wr32(device, 0x409840, 0xffffffff);
  1312. nvkm_wr32(device, 0x409500, 0x7fffffff);
  1313. nvkm_wr32(device, 0x409504, 0x00000021);
  1314. nvkm_wr32(device, 0x409840, 0xffffffff);
  1315. nvkm_wr32(device, 0x409500, 0x00000000);
  1316. nvkm_wr32(device, 0x409504, 0x00000010);
  1317. if (nvkm_msec(device, 2000,
  1318. if ((gr->size = nvkm_rd32(device, 0x409800)))
  1319. break;
  1320. ) < 0)
  1321. return -EBUSY;
  1322. nvkm_wr32(device, 0x409840, 0xffffffff);
  1323. nvkm_wr32(device, 0x409500, 0x00000000);
  1324. nvkm_wr32(device, 0x409504, 0x00000016);
  1325. if (nvkm_msec(device, 2000,
  1326. if (nvkm_rd32(device, 0x409800))
  1327. break;
  1328. ) < 0)
  1329. return -EBUSY;
  1330. nvkm_wr32(device, 0x409840, 0xffffffff);
  1331. nvkm_wr32(device, 0x409500, 0x00000000);
  1332. nvkm_wr32(device, 0x409504, 0x00000025);
  1333. if (nvkm_msec(device, 2000,
  1334. if (nvkm_rd32(device, 0x409800))
  1335. break;
  1336. ) < 0)
  1337. return -EBUSY;
  1338. if (device->chipset >= 0xe0) {
  1339. nvkm_wr32(device, 0x409800, 0x00000000);
  1340. nvkm_wr32(device, 0x409500, 0x00000001);
  1341. nvkm_wr32(device, 0x409504, 0x00000030);
  1342. if (nvkm_msec(device, 2000,
  1343. if (nvkm_rd32(device, 0x409800))
  1344. break;
  1345. ) < 0)
  1346. return -EBUSY;
  1347. nvkm_wr32(device, 0x409810, 0xb00095c8);
  1348. nvkm_wr32(device, 0x409800, 0x00000000);
  1349. nvkm_wr32(device, 0x409500, 0x00000001);
  1350. nvkm_wr32(device, 0x409504, 0x00000031);
  1351. if (nvkm_msec(device, 2000,
  1352. if (nvkm_rd32(device, 0x409800))
  1353. break;
  1354. ) < 0)
  1355. return -EBUSY;
  1356. nvkm_wr32(device, 0x409810, 0x00080420);
  1357. nvkm_wr32(device, 0x409800, 0x00000000);
  1358. nvkm_wr32(device, 0x409500, 0x00000001);
  1359. nvkm_wr32(device, 0x409504, 0x00000032);
  1360. if (nvkm_msec(device, 2000,
  1361. if (nvkm_rd32(device, 0x409800))
  1362. break;
  1363. ) < 0)
  1364. return -EBUSY;
  1365. nvkm_wr32(device, 0x409614, 0x00000070);
  1366. nvkm_wr32(device, 0x409614, 0x00000770);
  1367. nvkm_wr32(device, 0x40802c, 0x00000001);
  1368. }
  1369. if (gr->data == NULL) {
  1370. int ret = gf100_grctx_generate(gr);
  1371. if (ret) {
  1372. nvkm_error(subdev, "failed to construct context\n");
  1373. return ret;
  1374. }
  1375. }
  1376. return 0;
  1377. }
  1378. static int
  1379. gf100_gr_init_ctxctl_int(struct gf100_gr *gr)
  1380. {
  1381. const struct gf100_grctx_func *grctx = gr->func->grctx;
  1382. struct nvkm_subdev *subdev = &gr->base.engine.subdev;
  1383. struct nvkm_device *device = subdev->device;
  1384. if (!gr->func->fecs.ucode) {
  1385. return -ENOSYS;
  1386. }
  1387. /* load HUB microcode */
  1388. nvkm_mc_unk260(device, 0);
  1389. nvkm_falcon_load_dmem(gr->fecs, gr->func->fecs.ucode->data.data, 0x0,
  1390. gr->func->fecs.ucode->data.size, 0);
  1391. nvkm_falcon_load_imem(gr->fecs, gr->func->fecs.ucode->code.data, 0x0,
  1392. gr->func->fecs.ucode->code.size, 0, 0, false);
  1393. /* load GPC microcode */
  1394. nvkm_falcon_load_dmem(gr->gpccs, gr->func->gpccs.ucode->data.data, 0x0,
  1395. gr->func->gpccs.ucode->data.size, 0);
  1396. nvkm_falcon_load_imem(gr->gpccs, gr->func->gpccs.ucode->code.data, 0x0,
  1397. gr->func->gpccs.ucode->code.size, 0, 0, false);
  1398. nvkm_mc_unk260(device, 1);
  1399. /* load register lists */
  1400. gf100_gr_init_csdata(gr, grctx->hub, 0x409000, 0x000, 0x000000);
  1401. gf100_gr_init_csdata(gr, grctx->gpc, 0x41a000, 0x000, 0x418000);
  1402. gf100_gr_init_csdata(gr, grctx->tpc, 0x41a000, 0x004, 0x419800);
  1403. gf100_gr_init_csdata(gr, grctx->ppc, 0x41a000, 0x008, 0x41be00);
  1404. /* start HUB ucode running, it'll init the GPCs */
  1405. nvkm_wr32(device, 0x40910c, 0x00000000);
  1406. nvkm_wr32(device, 0x409100, 0x00000002);
  1407. if (nvkm_msec(device, 2000,
  1408. if (nvkm_rd32(device, 0x409800) & 0x80000000)
  1409. break;
  1410. ) < 0) {
  1411. gf100_gr_ctxctl_debug(gr);
  1412. return -EBUSY;
  1413. }
  1414. gr->size = nvkm_rd32(device, 0x409804);
  1415. if (gr->data == NULL) {
  1416. int ret = gf100_grctx_generate(gr);
  1417. if (ret) {
  1418. nvkm_error(subdev, "failed to construct context\n");
  1419. return ret;
  1420. }
  1421. }
  1422. return 0;
  1423. }
  1424. int
  1425. gf100_gr_init_ctxctl(struct gf100_gr *gr)
  1426. {
  1427. int ret;
  1428. if (gr->firmware)
  1429. ret = gf100_gr_init_ctxctl_ext(gr);
  1430. else
  1431. ret = gf100_gr_init_ctxctl_int(gr);
  1432. return ret;
  1433. }
  1434. static int
  1435. gf100_gr_oneinit(struct nvkm_gr *base)
  1436. {
  1437. struct gf100_gr *gr = gf100_gr(base);
  1438. struct nvkm_subdev *subdev = &gr->base.engine.subdev;
  1439. struct nvkm_device *device = subdev->device;
  1440. int i, j;
  1441. int ret;
  1442. ret = nvkm_falcon_v1_new(subdev, "FECS", 0x409000, &gr->fecs);
  1443. if (ret)
  1444. return ret;
  1445. ret = nvkm_falcon_v1_new(subdev, "GPCCS", 0x41a000, &gr->gpccs);
  1446. if (ret)
  1447. return ret;
  1448. nvkm_pmu_pgob(device->pmu, false);
  1449. gr->rop_nr = gr->func->rops(gr);
  1450. gr->gpc_nr = nvkm_rd32(device, 0x409604) & 0x0000001f;
  1451. for (i = 0; i < gr->gpc_nr; i++) {
  1452. gr->tpc_nr[i] = nvkm_rd32(device, GPC_UNIT(i, 0x2608));
  1453. gr->tpc_total += gr->tpc_nr[i];
  1454. gr->ppc_nr[i] = gr->func->ppc_nr;
  1455. for (j = 0; j < gr->ppc_nr[i]; j++) {
  1456. u8 mask = nvkm_rd32(device, GPC_UNIT(i, 0x0c30 + (j * 4)));
  1457. if (mask)
  1458. gr->ppc_mask[i] |= (1 << j);
  1459. gr->ppc_tpc_nr[i][j] = hweight8(mask);
  1460. }
  1461. }
  1462. /*XXX: these need figuring out... though it might not even matter */
  1463. switch (device->chipset) {
  1464. case 0xc0:
  1465. if (gr->tpc_total == 11) { /* 465, 3/4/4/0, 4 */
  1466. gr->screen_tile_row_offset = 0x07;
  1467. } else
  1468. if (gr->tpc_total == 14) { /* 470, 3/3/4/4, 5 */
  1469. gr->screen_tile_row_offset = 0x05;
  1470. } else
  1471. if (gr->tpc_total == 15) { /* 480, 3/4/4/4, 6 */
  1472. gr->screen_tile_row_offset = 0x06;
  1473. }
  1474. break;
  1475. case 0xc3: /* 450, 4/0/0/0, 2 */
  1476. gr->screen_tile_row_offset = 0x03;
  1477. break;
  1478. case 0xc4: /* 460, 3/4/0/0, 4 */
  1479. gr->screen_tile_row_offset = 0x01;
  1480. break;
  1481. case 0xc1: /* 2/0/0/0, 1 */
  1482. gr->screen_tile_row_offset = 0x01;
  1483. break;
  1484. case 0xc8: /* 4/4/3/4, 5 */
  1485. gr->screen_tile_row_offset = 0x06;
  1486. break;
  1487. case 0xce: /* 4/4/0/0, 4 */
  1488. gr->screen_tile_row_offset = 0x03;
  1489. break;
  1490. case 0xcf: /* 4/0/0/0, 3 */
  1491. gr->screen_tile_row_offset = 0x03;
  1492. break;
  1493. case 0xd7:
  1494. case 0xd9: /* 1/0/0/0, 1 */
  1495. case 0xea: /* gk20a */
  1496. case 0x12b: /* gm20b */
  1497. gr->screen_tile_row_offset = 0x01;
  1498. break;
  1499. }
  1500. return 0;
  1501. }
  1502. static int
  1503. gf100_gr_init_(struct nvkm_gr *base)
  1504. {
  1505. struct gf100_gr *gr = gf100_gr(base);
  1506. struct nvkm_subdev *subdev = &base->engine.subdev;
  1507. u32 ret;
  1508. nvkm_pmu_pgob(gr->base.engine.subdev.device->pmu, false);
  1509. ret = nvkm_falcon_get(gr->fecs, subdev);
  1510. if (ret)
  1511. return ret;
  1512. ret = nvkm_falcon_get(gr->gpccs, subdev);
  1513. if (ret)
  1514. return ret;
  1515. return gr->func->init(gr);
  1516. }
  1517. static int
  1518. gf100_gr_fini_(struct nvkm_gr *base, bool suspend)
  1519. {
  1520. struct gf100_gr *gr = gf100_gr(base);
  1521. struct nvkm_subdev *subdev = &gr->base.engine.subdev;
  1522. nvkm_falcon_put(gr->gpccs, subdev);
  1523. nvkm_falcon_put(gr->fecs, subdev);
  1524. return 0;
  1525. }
  1526. void
  1527. gf100_gr_dtor_fw(struct gf100_gr_fuc *fuc)
  1528. {
  1529. kfree(fuc->data);
  1530. fuc->data = NULL;
  1531. }
  1532. static void
  1533. gf100_gr_dtor_init(struct gf100_gr_pack *pack)
  1534. {
  1535. vfree(pack);
  1536. }
  1537. void *
  1538. gf100_gr_dtor(struct nvkm_gr *base)
  1539. {
  1540. struct gf100_gr *gr = gf100_gr(base);
  1541. if (gr->func->dtor)
  1542. gr->func->dtor(gr);
  1543. kfree(gr->data);
  1544. nvkm_falcon_del(&gr->gpccs);
  1545. nvkm_falcon_del(&gr->fecs);
  1546. gf100_gr_dtor_fw(&gr->fuc409c);
  1547. gf100_gr_dtor_fw(&gr->fuc409d);
  1548. gf100_gr_dtor_fw(&gr->fuc41ac);
  1549. gf100_gr_dtor_fw(&gr->fuc41ad);
  1550. gf100_gr_dtor_init(gr->fuc_bundle);
  1551. gf100_gr_dtor_init(gr->fuc_method);
  1552. gf100_gr_dtor_init(gr->fuc_sw_ctx);
  1553. gf100_gr_dtor_init(gr->fuc_sw_nonctx);
  1554. return gr;
  1555. }
  1556. static const struct nvkm_gr_func
  1557. gf100_gr_ = {
  1558. .dtor = gf100_gr_dtor,
  1559. .oneinit = gf100_gr_oneinit,
  1560. .init = gf100_gr_init_,
  1561. .fini = gf100_gr_fini_,
  1562. .intr = gf100_gr_intr,
  1563. .units = gf100_gr_units,
  1564. .chan_new = gf100_gr_chan_new,
  1565. .object_get = gf100_gr_object_get,
  1566. .chsw_load = gf100_gr_chsw_load,
  1567. };
  1568. int
  1569. gf100_gr_ctor_fw_legacy(struct gf100_gr *gr, const char *fwname,
  1570. struct gf100_gr_fuc *fuc, int ret)
  1571. {
  1572. struct nvkm_subdev *subdev = &gr->base.engine.subdev;
  1573. struct nvkm_device *device = subdev->device;
  1574. const struct firmware *fw;
  1575. char f[32];
  1576. /* see if this firmware has a legacy path */
  1577. if (!strcmp(fwname, "fecs_inst"))
  1578. fwname = "fuc409c";
  1579. else if (!strcmp(fwname, "fecs_data"))
  1580. fwname = "fuc409d";
  1581. else if (!strcmp(fwname, "gpccs_inst"))
  1582. fwname = "fuc41ac";
  1583. else if (!strcmp(fwname, "gpccs_data"))
  1584. fwname = "fuc41ad";
  1585. else {
  1586. /* nope, let's just return the error we got */
  1587. nvkm_error(subdev, "failed to load %s\n", fwname);
  1588. return ret;
  1589. }
  1590. /* yes, try to load from the legacy path */
  1591. nvkm_debug(subdev, "%s: falling back to legacy path\n", fwname);
  1592. snprintf(f, sizeof(f), "nouveau/nv%02x_%s", device->chipset, fwname);
  1593. ret = request_firmware(&fw, f, device->dev);
  1594. if (ret) {
  1595. snprintf(f, sizeof(f), "nouveau/%s", fwname);
  1596. ret = request_firmware(&fw, f, device->dev);
  1597. if (ret) {
  1598. nvkm_error(subdev, "failed to load %s\n", fwname);
  1599. return ret;
  1600. }
  1601. }
  1602. fuc->size = fw->size;
  1603. fuc->data = kmemdup(fw->data, fuc->size, GFP_KERNEL);
  1604. release_firmware(fw);
  1605. return (fuc->data != NULL) ? 0 : -ENOMEM;
  1606. }
  1607. int
  1608. gf100_gr_ctor_fw(struct gf100_gr *gr, const char *fwname,
  1609. struct gf100_gr_fuc *fuc)
  1610. {
  1611. struct nvkm_subdev *subdev = &gr->base.engine.subdev;
  1612. struct nvkm_device *device = subdev->device;
  1613. const struct firmware *fw;
  1614. int ret;
  1615. ret = nvkm_firmware_get(device, fwname, &fw);
  1616. if (ret)
  1617. return gf100_gr_ctor_fw_legacy(gr, fwname, fuc, ret);
  1618. fuc->size = fw->size;
  1619. fuc->data = kmemdup(fw->data, fuc->size, GFP_KERNEL);
  1620. nvkm_firmware_put(fw);
  1621. return (fuc->data != NULL) ? 0 : -ENOMEM;
  1622. }
  1623. int
  1624. gf100_gr_ctor(const struct gf100_gr_func *func, struct nvkm_device *device,
  1625. int index, struct gf100_gr *gr)
  1626. {
  1627. gr->func = func;
  1628. gr->firmware = nvkm_boolopt(device->cfgopt, "NvGrUseFW",
  1629. func->fecs.ucode == NULL);
  1630. return nvkm_gr_ctor(&gf100_gr_, device, index,
  1631. gr->firmware || func->fecs.ucode != NULL,
  1632. &gr->base);
  1633. }
  1634. int
  1635. gf100_gr_new_(const struct gf100_gr_func *func, struct nvkm_device *device,
  1636. int index, struct nvkm_gr **pgr)
  1637. {
  1638. struct gf100_gr *gr;
  1639. int ret;
  1640. if (!(gr = kzalloc(sizeof(*gr), GFP_KERNEL)))
  1641. return -ENOMEM;
  1642. *pgr = &gr->base;
  1643. ret = gf100_gr_ctor(func, device, index, gr);
  1644. if (ret)
  1645. return ret;
  1646. if (gr->firmware) {
  1647. if (gf100_gr_ctor_fw(gr, "fecs_inst", &gr->fuc409c) ||
  1648. gf100_gr_ctor_fw(gr, "fecs_data", &gr->fuc409d) ||
  1649. gf100_gr_ctor_fw(gr, "gpccs_inst", &gr->fuc41ac) ||
  1650. gf100_gr_ctor_fw(gr, "gpccs_data", &gr->fuc41ad))
  1651. return -ENODEV;
  1652. }
  1653. return 0;
  1654. }
  1655. int
  1656. gf100_gr_init(struct gf100_gr *gr)
  1657. {
  1658. struct nvkm_device *device = gr->base.engine.subdev.device;
  1659. struct nvkm_fb *fb = device->fb;
  1660. const u32 magicgpc918 = DIV_ROUND_UP(0x00800000, gr->tpc_total);
  1661. u32 data[TPC_MAX / 8] = {};
  1662. u8 tpcnr[GPC_MAX];
  1663. int gpc, tpc, rop;
  1664. int i;
  1665. nvkm_wr32(device, GPC_BCAST(0x0880), 0x00000000);
  1666. nvkm_wr32(device, GPC_BCAST(0x08a4), 0x00000000);
  1667. nvkm_wr32(device, GPC_BCAST(0x0888), 0x00000000);
  1668. nvkm_wr32(device, GPC_BCAST(0x088c), 0x00000000);
  1669. nvkm_wr32(device, GPC_BCAST(0x0890), 0x00000000);
  1670. nvkm_wr32(device, GPC_BCAST(0x0894), 0x00000000);
  1671. nvkm_wr32(device, GPC_BCAST(0x08b4), nvkm_memory_addr(fb->mmu_wr) >> 8);
  1672. nvkm_wr32(device, GPC_BCAST(0x08b8), nvkm_memory_addr(fb->mmu_rd) >> 8);
  1673. gf100_gr_mmio(gr, gr->func->mmio);
  1674. nvkm_mask(device, TPC_UNIT(0, 0, 0x05c), 0x00000001, 0x00000001);
  1675. memcpy(tpcnr, gr->tpc_nr, sizeof(gr->tpc_nr));
  1676. for (i = 0, gpc = -1; i < gr->tpc_total; i++) {
  1677. do {
  1678. gpc = (gpc + 1) % gr->gpc_nr;
  1679. } while (!tpcnr[gpc]);
  1680. tpc = gr->tpc_nr[gpc] - tpcnr[gpc]--;
  1681. data[i / 8] |= tpc << ((i % 8) * 4);
  1682. }
  1683. nvkm_wr32(device, GPC_BCAST(0x0980), data[0]);
  1684. nvkm_wr32(device, GPC_BCAST(0x0984), data[1]);
  1685. nvkm_wr32(device, GPC_BCAST(0x0988), data[2]);
  1686. nvkm_wr32(device, GPC_BCAST(0x098c), data[3]);
  1687. for (gpc = 0; gpc < gr->gpc_nr; gpc++) {
  1688. nvkm_wr32(device, GPC_UNIT(gpc, 0x0914),
  1689. gr->screen_tile_row_offset << 8 | gr->tpc_nr[gpc]);
  1690. nvkm_wr32(device, GPC_UNIT(gpc, 0x0910), 0x00040000 |
  1691. gr->tpc_total);
  1692. nvkm_wr32(device, GPC_UNIT(gpc, 0x0918), magicgpc918);
  1693. }
  1694. if (device->chipset != 0xd7)
  1695. nvkm_wr32(device, GPC_BCAST(0x1bd4), magicgpc918);
  1696. else
  1697. nvkm_wr32(device, GPC_BCAST(0x3fd4), magicgpc918);
  1698. nvkm_wr32(device, GPC_BCAST(0x08ac), nvkm_rd32(device, 0x100800));
  1699. nvkm_wr32(device, 0x400500, 0x00010001);
  1700. nvkm_wr32(device, 0x400100, 0xffffffff);
  1701. nvkm_wr32(device, 0x40013c, 0xffffffff);
  1702. nvkm_wr32(device, 0x409c24, 0x000f0000);
  1703. nvkm_wr32(device, 0x404000, 0xc0000000);
  1704. nvkm_wr32(device, 0x404600, 0xc0000000);
  1705. nvkm_wr32(device, 0x408030, 0xc0000000);
  1706. nvkm_wr32(device, 0x40601c, 0xc0000000);
  1707. nvkm_wr32(device, 0x404490, 0xc0000000);
  1708. nvkm_wr32(device, 0x406018, 0xc0000000);
  1709. nvkm_wr32(device, 0x405840, 0xc0000000);
  1710. nvkm_wr32(device, 0x405844, 0x00ffffff);
  1711. nvkm_mask(device, 0x419cc0, 0x00000008, 0x00000008);
  1712. nvkm_mask(device, 0x419eb4, 0x00001000, 0x00001000);
  1713. for (gpc = 0; gpc < gr->gpc_nr; gpc++) {
  1714. nvkm_wr32(device, GPC_UNIT(gpc, 0x0420), 0xc0000000);
  1715. nvkm_wr32(device, GPC_UNIT(gpc, 0x0900), 0xc0000000);
  1716. nvkm_wr32(device, GPC_UNIT(gpc, 0x1028), 0xc0000000);
  1717. nvkm_wr32(device, GPC_UNIT(gpc, 0x0824), 0xc0000000);
  1718. for (tpc = 0; tpc < gr->tpc_nr[gpc]; tpc++) {
  1719. nvkm_wr32(device, TPC_UNIT(gpc, tpc, 0x508), 0xffffffff);
  1720. nvkm_wr32(device, TPC_UNIT(gpc, tpc, 0x50c), 0xffffffff);
  1721. nvkm_wr32(device, TPC_UNIT(gpc, tpc, 0x224), 0xc0000000);
  1722. nvkm_wr32(device, TPC_UNIT(gpc, tpc, 0x48c), 0xc0000000);
  1723. nvkm_wr32(device, TPC_UNIT(gpc, tpc, 0x084), 0xc0000000);
  1724. nvkm_wr32(device, TPC_UNIT(gpc, tpc, 0x644), 0x001ffffe);
  1725. nvkm_wr32(device, TPC_UNIT(gpc, tpc, 0x64c), 0x0000000f);
  1726. }
  1727. nvkm_wr32(device, GPC_UNIT(gpc, 0x2c90), 0xffffffff);
  1728. nvkm_wr32(device, GPC_UNIT(gpc, 0x2c94), 0xffffffff);
  1729. }
  1730. for (rop = 0; rop < gr->rop_nr; rop++) {
  1731. nvkm_wr32(device, ROP_UNIT(rop, 0x144), 0xc0000000);
  1732. nvkm_wr32(device, ROP_UNIT(rop, 0x070), 0xc0000000);
  1733. nvkm_wr32(device, ROP_UNIT(rop, 0x204), 0xffffffff);
  1734. nvkm_wr32(device, ROP_UNIT(rop, 0x208), 0xffffffff);
  1735. }
  1736. nvkm_wr32(device, 0x400108, 0xffffffff);
  1737. nvkm_wr32(device, 0x400138, 0xffffffff);
  1738. nvkm_wr32(device, 0x400118, 0xffffffff);
  1739. nvkm_wr32(device, 0x400130, 0xffffffff);
  1740. nvkm_wr32(device, 0x40011c, 0xffffffff);
  1741. nvkm_wr32(device, 0x400134, 0xffffffff);
  1742. nvkm_wr32(device, 0x400054, 0x34ce3464);
  1743. gf100_gr_zbc_init(gr);
  1744. return gf100_gr_init_ctxctl(gr);
  1745. }
  1746. #include "fuc/hubgf100.fuc3.h"
  1747. struct gf100_gr_ucode
  1748. gf100_gr_fecs_ucode = {
  1749. .code.data = gf100_grhub_code,
  1750. .code.size = sizeof(gf100_grhub_code),
  1751. .data.data = gf100_grhub_data,
  1752. .data.size = sizeof(gf100_grhub_data),
  1753. };
  1754. #include "fuc/gpcgf100.fuc3.h"
  1755. struct gf100_gr_ucode
  1756. gf100_gr_gpccs_ucode = {
  1757. .code.data = gf100_grgpc_code,
  1758. .code.size = sizeof(gf100_grgpc_code),
  1759. .data.data = gf100_grgpc_data,
  1760. .data.size = sizeof(gf100_grgpc_data),
  1761. };
  1762. static const struct gf100_gr_func
  1763. gf100_gr = {
  1764. .init = gf100_gr_init,
  1765. .mmio = gf100_gr_pack_mmio,
  1766. .fecs.ucode = &gf100_gr_fecs_ucode,
  1767. .gpccs.ucode = &gf100_gr_gpccs_ucode,
  1768. .rops = gf100_gr_rops,
  1769. .grctx = &gf100_grctx,
  1770. .sclass = {
  1771. { -1, -1, FERMI_TWOD_A },
  1772. { -1, -1, FERMI_MEMORY_TO_MEMORY_FORMAT_A },
  1773. { -1, -1, FERMI_A, &gf100_fermi },
  1774. { -1, -1, FERMI_COMPUTE_A },
  1775. {}
  1776. }
  1777. };
  1778. int
  1779. gf100_gr_new(struct nvkm_device *device, int index, struct nvkm_gr **pgr)
  1780. {
  1781. return gf100_gr_new_(&gf100_gr, device, index, pgr);
  1782. }