gf100.c 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056
  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. int ret = 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. ret = nvkm_secboot_reset(sb, NVKM_SECBOOT_FALCON_FECS);
  1288. else
  1289. gf100_gr_init_fw(gr->fecs, &gr->fuc409c, &gr->fuc409d);
  1290. if (ret)
  1291. return ret;
  1292. if (nvkm_secboot_is_managed(sb, NVKM_SECBOOT_FALCON_GPCCS))
  1293. ret = nvkm_secboot_reset(sb, NVKM_SECBOOT_FALCON_GPCCS);
  1294. else
  1295. gf100_gr_init_fw(gr->gpccs, &gr->fuc41ac, &gr->fuc41ad);
  1296. if (ret)
  1297. return ret;
  1298. nvkm_mc_unk260(device, 1);
  1299. /* start both of them running */
  1300. nvkm_wr32(device, 0x409840, 0xffffffff);
  1301. nvkm_wr32(device, 0x41a10c, 0x00000000);
  1302. nvkm_wr32(device, 0x40910c, 0x00000000);
  1303. nvkm_falcon_start(gr->gpccs);
  1304. nvkm_falcon_start(gr->fecs);
  1305. if (nvkm_msec(device, 2000,
  1306. if (nvkm_rd32(device, 0x409800) & 0x00000001)
  1307. break;
  1308. ) < 0)
  1309. return -EBUSY;
  1310. nvkm_wr32(device, 0x409840, 0xffffffff);
  1311. nvkm_wr32(device, 0x409500, 0x7fffffff);
  1312. nvkm_wr32(device, 0x409504, 0x00000021);
  1313. nvkm_wr32(device, 0x409840, 0xffffffff);
  1314. nvkm_wr32(device, 0x409500, 0x00000000);
  1315. nvkm_wr32(device, 0x409504, 0x00000010);
  1316. if (nvkm_msec(device, 2000,
  1317. if ((gr->size = nvkm_rd32(device, 0x409800)))
  1318. break;
  1319. ) < 0)
  1320. return -EBUSY;
  1321. nvkm_wr32(device, 0x409840, 0xffffffff);
  1322. nvkm_wr32(device, 0x409500, 0x00000000);
  1323. nvkm_wr32(device, 0x409504, 0x00000016);
  1324. if (nvkm_msec(device, 2000,
  1325. if (nvkm_rd32(device, 0x409800))
  1326. break;
  1327. ) < 0)
  1328. return -EBUSY;
  1329. nvkm_wr32(device, 0x409840, 0xffffffff);
  1330. nvkm_wr32(device, 0x409500, 0x00000000);
  1331. nvkm_wr32(device, 0x409504, 0x00000025);
  1332. if (nvkm_msec(device, 2000,
  1333. if (nvkm_rd32(device, 0x409800))
  1334. break;
  1335. ) < 0)
  1336. return -EBUSY;
  1337. if (device->chipset >= 0xe0) {
  1338. nvkm_wr32(device, 0x409800, 0x00000000);
  1339. nvkm_wr32(device, 0x409500, 0x00000001);
  1340. nvkm_wr32(device, 0x409504, 0x00000030);
  1341. if (nvkm_msec(device, 2000,
  1342. if (nvkm_rd32(device, 0x409800))
  1343. break;
  1344. ) < 0)
  1345. return -EBUSY;
  1346. nvkm_wr32(device, 0x409810, 0xb00095c8);
  1347. nvkm_wr32(device, 0x409800, 0x00000000);
  1348. nvkm_wr32(device, 0x409500, 0x00000001);
  1349. nvkm_wr32(device, 0x409504, 0x00000031);
  1350. if (nvkm_msec(device, 2000,
  1351. if (nvkm_rd32(device, 0x409800))
  1352. break;
  1353. ) < 0)
  1354. return -EBUSY;
  1355. nvkm_wr32(device, 0x409810, 0x00080420);
  1356. nvkm_wr32(device, 0x409800, 0x00000000);
  1357. nvkm_wr32(device, 0x409500, 0x00000001);
  1358. nvkm_wr32(device, 0x409504, 0x00000032);
  1359. if (nvkm_msec(device, 2000,
  1360. if (nvkm_rd32(device, 0x409800))
  1361. break;
  1362. ) < 0)
  1363. return -EBUSY;
  1364. nvkm_wr32(device, 0x409614, 0x00000070);
  1365. nvkm_wr32(device, 0x409614, 0x00000770);
  1366. nvkm_wr32(device, 0x40802c, 0x00000001);
  1367. }
  1368. if (gr->data == NULL) {
  1369. int ret = gf100_grctx_generate(gr);
  1370. if (ret) {
  1371. nvkm_error(subdev, "failed to construct context\n");
  1372. return ret;
  1373. }
  1374. }
  1375. return 0;
  1376. }
  1377. static int
  1378. gf100_gr_init_ctxctl_int(struct gf100_gr *gr)
  1379. {
  1380. const struct gf100_grctx_func *grctx = gr->func->grctx;
  1381. struct nvkm_subdev *subdev = &gr->base.engine.subdev;
  1382. struct nvkm_device *device = subdev->device;
  1383. if (!gr->func->fecs.ucode) {
  1384. return -ENOSYS;
  1385. }
  1386. /* load HUB microcode */
  1387. nvkm_mc_unk260(device, 0);
  1388. nvkm_falcon_load_dmem(gr->fecs, gr->func->fecs.ucode->data.data, 0x0,
  1389. gr->func->fecs.ucode->data.size, 0);
  1390. nvkm_falcon_load_imem(gr->fecs, gr->func->fecs.ucode->code.data, 0x0,
  1391. gr->func->fecs.ucode->code.size, 0, 0, false);
  1392. /* load GPC microcode */
  1393. nvkm_falcon_load_dmem(gr->gpccs, gr->func->gpccs.ucode->data.data, 0x0,
  1394. gr->func->gpccs.ucode->data.size, 0);
  1395. nvkm_falcon_load_imem(gr->gpccs, gr->func->gpccs.ucode->code.data, 0x0,
  1396. gr->func->gpccs.ucode->code.size, 0, 0, false);
  1397. nvkm_mc_unk260(device, 1);
  1398. /* load register lists */
  1399. gf100_gr_init_csdata(gr, grctx->hub, 0x409000, 0x000, 0x000000);
  1400. gf100_gr_init_csdata(gr, grctx->gpc, 0x41a000, 0x000, 0x418000);
  1401. gf100_gr_init_csdata(gr, grctx->tpc, 0x41a000, 0x004, 0x419800);
  1402. gf100_gr_init_csdata(gr, grctx->ppc, 0x41a000, 0x008, 0x41be00);
  1403. /* start HUB ucode running, it'll init the GPCs */
  1404. nvkm_wr32(device, 0x40910c, 0x00000000);
  1405. nvkm_wr32(device, 0x409100, 0x00000002);
  1406. if (nvkm_msec(device, 2000,
  1407. if (nvkm_rd32(device, 0x409800) & 0x80000000)
  1408. break;
  1409. ) < 0) {
  1410. gf100_gr_ctxctl_debug(gr);
  1411. return -EBUSY;
  1412. }
  1413. gr->size = nvkm_rd32(device, 0x409804);
  1414. if (gr->data == NULL) {
  1415. int ret = gf100_grctx_generate(gr);
  1416. if (ret) {
  1417. nvkm_error(subdev, "failed to construct context\n");
  1418. return ret;
  1419. }
  1420. }
  1421. return 0;
  1422. }
  1423. int
  1424. gf100_gr_init_ctxctl(struct gf100_gr *gr)
  1425. {
  1426. int ret;
  1427. if (gr->firmware)
  1428. ret = gf100_gr_init_ctxctl_ext(gr);
  1429. else
  1430. ret = gf100_gr_init_ctxctl_int(gr);
  1431. return ret;
  1432. }
  1433. static int
  1434. gf100_gr_oneinit(struct nvkm_gr *base)
  1435. {
  1436. struct gf100_gr *gr = gf100_gr(base);
  1437. struct nvkm_device *device = gr->base.engine.subdev.device;
  1438. int i, j;
  1439. nvkm_pmu_pgob(device->pmu, false);
  1440. gr->rop_nr = gr->func->rops(gr);
  1441. gr->gpc_nr = nvkm_rd32(device, 0x409604) & 0x0000001f;
  1442. for (i = 0; i < gr->gpc_nr; i++) {
  1443. gr->tpc_nr[i] = nvkm_rd32(device, GPC_UNIT(i, 0x2608));
  1444. gr->tpc_total += gr->tpc_nr[i];
  1445. gr->ppc_nr[i] = gr->func->ppc_nr;
  1446. for (j = 0; j < gr->ppc_nr[i]; j++) {
  1447. u8 mask = nvkm_rd32(device, GPC_UNIT(i, 0x0c30 + (j * 4)));
  1448. if (mask)
  1449. gr->ppc_mask[i] |= (1 << j);
  1450. gr->ppc_tpc_nr[i][j] = hweight8(mask);
  1451. }
  1452. }
  1453. /*XXX: these need figuring out... though it might not even matter */
  1454. switch (device->chipset) {
  1455. case 0xc0:
  1456. if (gr->tpc_total == 11) { /* 465, 3/4/4/0, 4 */
  1457. gr->screen_tile_row_offset = 0x07;
  1458. } else
  1459. if (gr->tpc_total == 14) { /* 470, 3/3/4/4, 5 */
  1460. gr->screen_tile_row_offset = 0x05;
  1461. } else
  1462. if (gr->tpc_total == 15) { /* 480, 3/4/4/4, 6 */
  1463. gr->screen_tile_row_offset = 0x06;
  1464. }
  1465. break;
  1466. case 0xc3: /* 450, 4/0/0/0, 2 */
  1467. gr->screen_tile_row_offset = 0x03;
  1468. break;
  1469. case 0xc4: /* 460, 3/4/0/0, 4 */
  1470. gr->screen_tile_row_offset = 0x01;
  1471. break;
  1472. case 0xc1: /* 2/0/0/0, 1 */
  1473. gr->screen_tile_row_offset = 0x01;
  1474. break;
  1475. case 0xc8: /* 4/4/3/4, 5 */
  1476. gr->screen_tile_row_offset = 0x06;
  1477. break;
  1478. case 0xce: /* 4/4/0/0, 4 */
  1479. gr->screen_tile_row_offset = 0x03;
  1480. break;
  1481. case 0xcf: /* 4/0/0/0, 3 */
  1482. gr->screen_tile_row_offset = 0x03;
  1483. break;
  1484. case 0xd7:
  1485. case 0xd9: /* 1/0/0/0, 1 */
  1486. case 0xea: /* gk20a */
  1487. case 0x12b: /* gm20b */
  1488. gr->screen_tile_row_offset = 0x01;
  1489. break;
  1490. }
  1491. return 0;
  1492. }
  1493. static int
  1494. gf100_gr_init_(struct nvkm_gr *base)
  1495. {
  1496. struct gf100_gr *gr = gf100_gr(base);
  1497. struct nvkm_subdev *subdev = &base->engine.subdev;
  1498. u32 ret;
  1499. nvkm_pmu_pgob(gr->base.engine.subdev.device->pmu, false);
  1500. ret = nvkm_falcon_get(gr->fecs, subdev);
  1501. if (ret)
  1502. return ret;
  1503. ret = nvkm_falcon_get(gr->gpccs, subdev);
  1504. if (ret)
  1505. return ret;
  1506. return gr->func->init(gr);
  1507. }
  1508. static int
  1509. gf100_gr_fini_(struct nvkm_gr *base, bool suspend)
  1510. {
  1511. struct gf100_gr *gr = gf100_gr(base);
  1512. struct nvkm_subdev *subdev = &gr->base.engine.subdev;
  1513. nvkm_falcon_put(gr->gpccs, subdev);
  1514. nvkm_falcon_put(gr->fecs, subdev);
  1515. return 0;
  1516. }
  1517. void
  1518. gf100_gr_dtor_fw(struct gf100_gr_fuc *fuc)
  1519. {
  1520. kfree(fuc->data);
  1521. fuc->data = NULL;
  1522. }
  1523. static void
  1524. gf100_gr_dtor_init(struct gf100_gr_pack *pack)
  1525. {
  1526. vfree(pack);
  1527. }
  1528. void *
  1529. gf100_gr_dtor(struct nvkm_gr *base)
  1530. {
  1531. struct gf100_gr *gr = gf100_gr(base);
  1532. if (gr->func->dtor)
  1533. gr->func->dtor(gr);
  1534. kfree(gr->data);
  1535. nvkm_falcon_del(&gr->gpccs);
  1536. nvkm_falcon_del(&gr->fecs);
  1537. gf100_gr_dtor_fw(&gr->fuc409c);
  1538. gf100_gr_dtor_fw(&gr->fuc409d);
  1539. gf100_gr_dtor_fw(&gr->fuc41ac);
  1540. gf100_gr_dtor_fw(&gr->fuc41ad);
  1541. gf100_gr_dtor_init(gr->fuc_bundle);
  1542. gf100_gr_dtor_init(gr->fuc_method);
  1543. gf100_gr_dtor_init(gr->fuc_sw_ctx);
  1544. gf100_gr_dtor_init(gr->fuc_sw_nonctx);
  1545. return gr;
  1546. }
  1547. static const struct nvkm_gr_func
  1548. gf100_gr_ = {
  1549. .dtor = gf100_gr_dtor,
  1550. .oneinit = gf100_gr_oneinit,
  1551. .init = gf100_gr_init_,
  1552. .fini = gf100_gr_fini_,
  1553. .intr = gf100_gr_intr,
  1554. .units = gf100_gr_units,
  1555. .chan_new = gf100_gr_chan_new,
  1556. .object_get = gf100_gr_object_get,
  1557. .chsw_load = gf100_gr_chsw_load,
  1558. };
  1559. int
  1560. gf100_gr_ctor_fw_legacy(struct gf100_gr *gr, const char *fwname,
  1561. struct gf100_gr_fuc *fuc, int ret)
  1562. {
  1563. struct nvkm_subdev *subdev = &gr->base.engine.subdev;
  1564. struct nvkm_device *device = subdev->device;
  1565. const struct firmware *fw;
  1566. char f[32];
  1567. /* see if this firmware has a legacy path */
  1568. if (!strcmp(fwname, "fecs_inst"))
  1569. fwname = "fuc409c";
  1570. else if (!strcmp(fwname, "fecs_data"))
  1571. fwname = "fuc409d";
  1572. else if (!strcmp(fwname, "gpccs_inst"))
  1573. fwname = "fuc41ac";
  1574. else if (!strcmp(fwname, "gpccs_data"))
  1575. fwname = "fuc41ad";
  1576. else {
  1577. /* nope, let's just return the error we got */
  1578. nvkm_error(subdev, "failed to load %s\n", fwname);
  1579. return ret;
  1580. }
  1581. /* yes, try to load from the legacy path */
  1582. nvkm_debug(subdev, "%s: falling back to legacy path\n", fwname);
  1583. snprintf(f, sizeof(f), "nouveau/nv%02x_%s", device->chipset, fwname);
  1584. ret = request_firmware(&fw, f, device->dev);
  1585. if (ret) {
  1586. snprintf(f, sizeof(f), "nouveau/%s", fwname);
  1587. ret = request_firmware(&fw, f, device->dev);
  1588. if (ret) {
  1589. nvkm_error(subdev, "failed to load %s\n", fwname);
  1590. return ret;
  1591. }
  1592. }
  1593. fuc->size = fw->size;
  1594. fuc->data = kmemdup(fw->data, fuc->size, GFP_KERNEL);
  1595. release_firmware(fw);
  1596. return (fuc->data != NULL) ? 0 : -ENOMEM;
  1597. }
  1598. int
  1599. gf100_gr_ctor_fw(struct gf100_gr *gr, const char *fwname,
  1600. struct gf100_gr_fuc *fuc)
  1601. {
  1602. struct nvkm_subdev *subdev = &gr->base.engine.subdev;
  1603. struct nvkm_device *device = subdev->device;
  1604. const struct firmware *fw;
  1605. int ret;
  1606. ret = nvkm_firmware_get(device, fwname, &fw);
  1607. if (ret)
  1608. return gf100_gr_ctor_fw_legacy(gr, fwname, fuc, ret);
  1609. fuc->size = fw->size;
  1610. fuc->data = kmemdup(fw->data, fuc->size, GFP_KERNEL);
  1611. nvkm_firmware_put(fw);
  1612. return (fuc->data != NULL) ? 0 : -ENOMEM;
  1613. }
  1614. int
  1615. gf100_gr_ctor(const struct gf100_gr_func *func, struct nvkm_device *device,
  1616. int index, struct gf100_gr *gr)
  1617. {
  1618. struct nvkm_subdev *subdev = &gr->base.engine.subdev;
  1619. int ret;
  1620. gr->func = func;
  1621. gr->firmware = nvkm_boolopt(device->cfgopt, "NvGrUseFW",
  1622. func->fecs.ucode == NULL);
  1623. ret = nvkm_gr_ctor(&gf100_gr_, device, index,
  1624. gr->firmware || func->fecs.ucode != NULL,
  1625. &gr->base);
  1626. if (ret)
  1627. return ret;
  1628. ret = nvkm_falcon_v1_new(subdev, "FECS", 0x409000, &gr->fecs);
  1629. if (ret)
  1630. return ret;
  1631. return nvkm_falcon_v1_new(subdev, "GPCCS", 0x41a000, &gr->gpccs);
  1632. }
  1633. int
  1634. gf100_gr_new_(const struct gf100_gr_func *func, struct nvkm_device *device,
  1635. int index, struct nvkm_gr **pgr)
  1636. {
  1637. struct gf100_gr *gr;
  1638. int ret;
  1639. if (!(gr = kzalloc(sizeof(*gr), GFP_KERNEL)))
  1640. return -ENOMEM;
  1641. *pgr = &gr->base;
  1642. ret = gf100_gr_ctor(func, device, index, gr);
  1643. if (ret)
  1644. return ret;
  1645. if (gr->firmware) {
  1646. if (gf100_gr_ctor_fw(gr, "fecs_inst", &gr->fuc409c) ||
  1647. gf100_gr_ctor_fw(gr, "fecs_data", &gr->fuc409d) ||
  1648. gf100_gr_ctor_fw(gr, "gpccs_inst", &gr->fuc41ac) ||
  1649. gf100_gr_ctor_fw(gr, "gpccs_data", &gr->fuc41ad))
  1650. return -ENODEV;
  1651. }
  1652. return 0;
  1653. }
  1654. int
  1655. gf100_gr_init(struct gf100_gr *gr)
  1656. {
  1657. struct nvkm_device *device = gr->base.engine.subdev.device;
  1658. struct nvkm_fb *fb = device->fb;
  1659. const u32 magicgpc918 = DIV_ROUND_UP(0x00800000, gr->tpc_total);
  1660. u32 data[TPC_MAX / 8] = {};
  1661. u8 tpcnr[GPC_MAX];
  1662. int gpc, tpc, rop;
  1663. int i;
  1664. nvkm_wr32(device, GPC_BCAST(0x0880), 0x00000000);
  1665. nvkm_wr32(device, GPC_BCAST(0x08a4), 0x00000000);
  1666. nvkm_wr32(device, GPC_BCAST(0x0888), 0x00000000);
  1667. nvkm_wr32(device, GPC_BCAST(0x088c), 0x00000000);
  1668. nvkm_wr32(device, GPC_BCAST(0x0890), 0x00000000);
  1669. nvkm_wr32(device, GPC_BCAST(0x0894), 0x00000000);
  1670. nvkm_wr32(device, GPC_BCAST(0x08b4), nvkm_memory_addr(fb->mmu_wr) >> 8);
  1671. nvkm_wr32(device, GPC_BCAST(0x08b8), nvkm_memory_addr(fb->mmu_rd) >> 8);
  1672. gf100_gr_mmio(gr, gr->func->mmio);
  1673. nvkm_mask(device, TPC_UNIT(0, 0, 0x05c), 0x00000001, 0x00000001);
  1674. memcpy(tpcnr, gr->tpc_nr, sizeof(gr->tpc_nr));
  1675. for (i = 0, gpc = -1; i < gr->tpc_total; i++) {
  1676. do {
  1677. gpc = (gpc + 1) % gr->gpc_nr;
  1678. } while (!tpcnr[gpc]);
  1679. tpc = gr->tpc_nr[gpc] - tpcnr[gpc]--;
  1680. data[i / 8] |= tpc << ((i % 8) * 4);
  1681. }
  1682. nvkm_wr32(device, GPC_BCAST(0x0980), data[0]);
  1683. nvkm_wr32(device, GPC_BCAST(0x0984), data[1]);
  1684. nvkm_wr32(device, GPC_BCAST(0x0988), data[2]);
  1685. nvkm_wr32(device, GPC_BCAST(0x098c), data[3]);
  1686. for (gpc = 0; gpc < gr->gpc_nr; gpc++) {
  1687. nvkm_wr32(device, GPC_UNIT(gpc, 0x0914),
  1688. gr->screen_tile_row_offset << 8 | gr->tpc_nr[gpc]);
  1689. nvkm_wr32(device, GPC_UNIT(gpc, 0x0910), 0x00040000 |
  1690. gr->tpc_total);
  1691. nvkm_wr32(device, GPC_UNIT(gpc, 0x0918), magicgpc918);
  1692. }
  1693. if (device->chipset != 0xd7)
  1694. nvkm_wr32(device, GPC_BCAST(0x1bd4), magicgpc918);
  1695. else
  1696. nvkm_wr32(device, GPC_BCAST(0x3fd4), magicgpc918);
  1697. nvkm_wr32(device, GPC_BCAST(0x08ac), nvkm_rd32(device, 0x100800));
  1698. nvkm_wr32(device, 0x400500, 0x00010001);
  1699. nvkm_wr32(device, 0x400100, 0xffffffff);
  1700. nvkm_wr32(device, 0x40013c, 0xffffffff);
  1701. nvkm_wr32(device, 0x409c24, 0x000f0000);
  1702. nvkm_wr32(device, 0x404000, 0xc0000000);
  1703. nvkm_wr32(device, 0x404600, 0xc0000000);
  1704. nvkm_wr32(device, 0x408030, 0xc0000000);
  1705. nvkm_wr32(device, 0x40601c, 0xc0000000);
  1706. nvkm_wr32(device, 0x404490, 0xc0000000);
  1707. nvkm_wr32(device, 0x406018, 0xc0000000);
  1708. nvkm_wr32(device, 0x405840, 0xc0000000);
  1709. nvkm_wr32(device, 0x405844, 0x00ffffff);
  1710. nvkm_mask(device, 0x419cc0, 0x00000008, 0x00000008);
  1711. nvkm_mask(device, 0x419eb4, 0x00001000, 0x00001000);
  1712. for (gpc = 0; gpc < gr->gpc_nr; gpc++) {
  1713. nvkm_wr32(device, GPC_UNIT(gpc, 0x0420), 0xc0000000);
  1714. nvkm_wr32(device, GPC_UNIT(gpc, 0x0900), 0xc0000000);
  1715. nvkm_wr32(device, GPC_UNIT(gpc, 0x1028), 0xc0000000);
  1716. nvkm_wr32(device, GPC_UNIT(gpc, 0x0824), 0xc0000000);
  1717. for (tpc = 0; tpc < gr->tpc_nr[gpc]; tpc++) {
  1718. nvkm_wr32(device, TPC_UNIT(gpc, tpc, 0x508), 0xffffffff);
  1719. nvkm_wr32(device, TPC_UNIT(gpc, tpc, 0x50c), 0xffffffff);
  1720. nvkm_wr32(device, TPC_UNIT(gpc, tpc, 0x224), 0xc0000000);
  1721. nvkm_wr32(device, TPC_UNIT(gpc, tpc, 0x48c), 0xc0000000);
  1722. nvkm_wr32(device, TPC_UNIT(gpc, tpc, 0x084), 0xc0000000);
  1723. nvkm_wr32(device, TPC_UNIT(gpc, tpc, 0x644), 0x001ffffe);
  1724. nvkm_wr32(device, TPC_UNIT(gpc, tpc, 0x64c), 0x0000000f);
  1725. }
  1726. nvkm_wr32(device, GPC_UNIT(gpc, 0x2c90), 0xffffffff);
  1727. nvkm_wr32(device, GPC_UNIT(gpc, 0x2c94), 0xffffffff);
  1728. }
  1729. for (rop = 0; rop < gr->rop_nr; rop++) {
  1730. nvkm_wr32(device, ROP_UNIT(rop, 0x144), 0xc0000000);
  1731. nvkm_wr32(device, ROP_UNIT(rop, 0x070), 0xc0000000);
  1732. nvkm_wr32(device, ROP_UNIT(rop, 0x204), 0xffffffff);
  1733. nvkm_wr32(device, ROP_UNIT(rop, 0x208), 0xffffffff);
  1734. }
  1735. nvkm_wr32(device, 0x400108, 0xffffffff);
  1736. nvkm_wr32(device, 0x400138, 0xffffffff);
  1737. nvkm_wr32(device, 0x400118, 0xffffffff);
  1738. nvkm_wr32(device, 0x400130, 0xffffffff);
  1739. nvkm_wr32(device, 0x40011c, 0xffffffff);
  1740. nvkm_wr32(device, 0x400134, 0xffffffff);
  1741. nvkm_wr32(device, 0x400054, 0x34ce3464);
  1742. gf100_gr_zbc_init(gr);
  1743. return gf100_gr_init_ctxctl(gr);
  1744. }
  1745. #include "fuc/hubgf100.fuc3.h"
  1746. struct gf100_gr_ucode
  1747. gf100_gr_fecs_ucode = {
  1748. .code.data = gf100_grhub_code,
  1749. .code.size = sizeof(gf100_grhub_code),
  1750. .data.data = gf100_grhub_data,
  1751. .data.size = sizeof(gf100_grhub_data),
  1752. };
  1753. #include "fuc/gpcgf100.fuc3.h"
  1754. struct gf100_gr_ucode
  1755. gf100_gr_gpccs_ucode = {
  1756. .code.data = gf100_grgpc_code,
  1757. .code.size = sizeof(gf100_grgpc_code),
  1758. .data.data = gf100_grgpc_data,
  1759. .data.size = sizeof(gf100_grgpc_data),
  1760. };
  1761. static const struct gf100_gr_func
  1762. gf100_gr = {
  1763. .init = gf100_gr_init,
  1764. .mmio = gf100_gr_pack_mmio,
  1765. .fecs.ucode = &gf100_gr_fecs_ucode,
  1766. .gpccs.ucode = &gf100_gr_gpccs_ucode,
  1767. .rops = gf100_gr_rops,
  1768. .grctx = &gf100_grctx,
  1769. .sclass = {
  1770. { -1, -1, FERMI_TWOD_A },
  1771. { -1, -1, FERMI_MEMORY_TO_MEMORY_FORMAT_A },
  1772. { -1, -1, FERMI_A, &gf100_fermi },
  1773. { -1, -1, FERMI_COMPUTE_A },
  1774. {}
  1775. }
  1776. };
  1777. int
  1778. gf100_gr_new(struct nvkm_device *device, int index, struct nvkm_gr **pgr)
  1779. {
  1780. return gf100_gr_new_(&gf100_gr, device, index, pgr);
  1781. }