etnaviv_gpu.c 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769
  1. /*
  2. * Copyright (C) 2015 Etnaviv Project
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License version 2 as published by
  6. * the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * You should have received a copy of the GNU General Public License along with
  14. * this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include <linux/component.h>
  17. #include <linux/fence.h>
  18. #include <linux/moduleparam.h>
  19. #include <linux/of_device.h>
  20. #include "etnaviv_dump.h"
  21. #include "etnaviv_gpu.h"
  22. #include "etnaviv_gem.h"
  23. #include "etnaviv_mmu.h"
  24. #include "etnaviv_iommu.h"
  25. #include "etnaviv_iommu_v2.h"
  26. #include "common.xml.h"
  27. #include "state.xml.h"
  28. #include "state_hi.xml.h"
  29. #include "cmdstream.xml.h"
  30. static const struct platform_device_id gpu_ids[] = {
  31. { .name = "etnaviv-gpu,2d" },
  32. { },
  33. };
  34. static bool etnaviv_dump_core = true;
  35. module_param_named(dump_core, etnaviv_dump_core, bool, 0600);
  36. /*
  37. * Driver functions:
  38. */
  39. int etnaviv_gpu_get_param(struct etnaviv_gpu *gpu, u32 param, u64 *value)
  40. {
  41. switch (param) {
  42. case ETNAVIV_PARAM_GPU_MODEL:
  43. *value = gpu->identity.model;
  44. break;
  45. case ETNAVIV_PARAM_GPU_REVISION:
  46. *value = gpu->identity.revision;
  47. break;
  48. case ETNAVIV_PARAM_GPU_FEATURES_0:
  49. *value = gpu->identity.features;
  50. break;
  51. case ETNAVIV_PARAM_GPU_FEATURES_1:
  52. *value = gpu->identity.minor_features0;
  53. break;
  54. case ETNAVIV_PARAM_GPU_FEATURES_2:
  55. *value = gpu->identity.minor_features1;
  56. break;
  57. case ETNAVIV_PARAM_GPU_FEATURES_3:
  58. *value = gpu->identity.minor_features2;
  59. break;
  60. case ETNAVIV_PARAM_GPU_FEATURES_4:
  61. *value = gpu->identity.minor_features3;
  62. break;
  63. case ETNAVIV_PARAM_GPU_FEATURES_5:
  64. *value = gpu->identity.minor_features4;
  65. break;
  66. case ETNAVIV_PARAM_GPU_FEATURES_6:
  67. *value = gpu->identity.minor_features5;
  68. break;
  69. case ETNAVIV_PARAM_GPU_STREAM_COUNT:
  70. *value = gpu->identity.stream_count;
  71. break;
  72. case ETNAVIV_PARAM_GPU_REGISTER_MAX:
  73. *value = gpu->identity.register_max;
  74. break;
  75. case ETNAVIV_PARAM_GPU_THREAD_COUNT:
  76. *value = gpu->identity.thread_count;
  77. break;
  78. case ETNAVIV_PARAM_GPU_VERTEX_CACHE_SIZE:
  79. *value = gpu->identity.vertex_cache_size;
  80. break;
  81. case ETNAVIV_PARAM_GPU_SHADER_CORE_COUNT:
  82. *value = gpu->identity.shader_core_count;
  83. break;
  84. case ETNAVIV_PARAM_GPU_PIXEL_PIPES:
  85. *value = gpu->identity.pixel_pipes;
  86. break;
  87. case ETNAVIV_PARAM_GPU_VERTEX_OUTPUT_BUFFER_SIZE:
  88. *value = gpu->identity.vertex_output_buffer_size;
  89. break;
  90. case ETNAVIV_PARAM_GPU_BUFFER_SIZE:
  91. *value = gpu->identity.buffer_size;
  92. break;
  93. case ETNAVIV_PARAM_GPU_INSTRUCTION_COUNT:
  94. *value = gpu->identity.instruction_count;
  95. break;
  96. case ETNAVIV_PARAM_GPU_NUM_CONSTANTS:
  97. *value = gpu->identity.num_constants;
  98. break;
  99. case ETNAVIV_PARAM_GPU_NUM_VARYINGS:
  100. *value = gpu->identity.varyings_count;
  101. break;
  102. default:
  103. DBG("%s: invalid param: %u", dev_name(gpu->dev), param);
  104. return -EINVAL;
  105. }
  106. return 0;
  107. }
  108. #define etnaviv_is_model_rev(gpu, mod, rev) \
  109. ((gpu)->identity.model == chipModel_##mod && \
  110. (gpu)->identity.revision == rev)
  111. #define etnaviv_field(val, field) \
  112. (((val) & field##__MASK) >> field##__SHIFT)
  113. static void etnaviv_hw_specs(struct etnaviv_gpu *gpu)
  114. {
  115. if (gpu->identity.minor_features0 &
  116. chipMinorFeatures0_MORE_MINOR_FEATURES) {
  117. u32 specs[4];
  118. unsigned int streams;
  119. specs[0] = gpu_read(gpu, VIVS_HI_CHIP_SPECS);
  120. specs[1] = gpu_read(gpu, VIVS_HI_CHIP_SPECS_2);
  121. specs[2] = gpu_read(gpu, VIVS_HI_CHIP_SPECS_3);
  122. specs[3] = gpu_read(gpu, VIVS_HI_CHIP_SPECS_4);
  123. gpu->identity.stream_count = etnaviv_field(specs[0],
  124. VIVS_HI_CHIP_SPECS_STREAM_COUNT);
  125. gpu->identity.register_max = etnaviv_field(specs[0],
  126. VIVS_HI_CHIP_SPECS_REGISTER_MAX);
  127. gpu->identity.thread_count = etnaviv_field(specs[0],
  128. VIVS_HI_CHIP_SPECS_THREAD_COUNT);
  129. gpu->identity.vertex_cache_size = etnaviv_field(specs[0],
  130. VIVS_HI_CHIP_SPECS_VERTEX_CACHE_SIZE);
  131. gpu->identity.shader_core_count = etnaviv_field(specs[0],
  132. VIVS_HI_CHIP_SPECS_SHADER_CORE_COUNT);
  133. gpu->identity.pixel_pipes = etnaviv_field(specs[0],
  134. VIVS_HI_CHIP_SPECS_PIXEL_PIPES);
  135. gpu->identity.vertex_output_buffer_size =
  136. etnaviv_field(specs[0],
  137. VIVS_HI_CHIP_SPECS_VERTEX_OUTPUT_BUFFER_SIZE);
  138. gpu->identity.buffer_size = etnaviv_field(specs[1],
  139. VIVS_HI_CHIP_SPECS_2_BUFFER_SIZE);
  140. gpu->identity.instruction_count = etnaviv_field(specs[1],
  141. VIVS_HI_CHIP_SPECS_2_INSTRUCTION_COUNT);
  142. gpu->identity.num_constants = etnaviv_field(specs[1],
  143. VIVS_HI_CHIP_SPECS_2_NUM_CONSTANTS);
  144. gpu->identity.varyings_count = etnaviv_field(specs[2],
  145. VIVS_HI_CHIP_SPECS_3_VARYINGS_COUNT);
  146. /* This overrides the value from older register if non-zero */
  147. streams = etnaviv_field(specs[3],
  148. VIVS_HI_CHIP_SPECS_4_STREAM_COUNT);
  149. if (streams)
  150. gpu->identity.stream_count = streams;
  151. }
  152. /* Fill in the stream count if not specified */
  153. if (gpu->identity.stream_count == 0) {
  154. if (gpu->identity.model >= 0x1000)
  155. gpu->identity.stream_count = 4;
  156. else
  157. gpu->identity.stream_count = 1;
  158. }
  159. /* Convert the register max value */
  160. if (gpu->identity.register_max)
  161. gpu->identity.register_max = 1 << gpu->identity.register_max;
  162. else if (gpu->identity.model == chipModel_GC400)
  163. gpu->identity.register_max = 32;
  164. else
  165. gpu->identity.register_max = 64;
  166. /* Convert thread count */
  167. if (gpu->identity.thread_count)
  168. gpu->identity.thread_count = 1 << gpu->identity.thread_count;
  169. else if (gpu->identity.model == chipModel_GC400)
  170. gpu->identity.thread_count = 64;
  171. else if (gpu->identity.model == chipModel_GC500 ||
  172. gpu->identity.model == chipModel_GC530)
  173. gpu->identity.thread_count = 128;
  174. else
  175. gpu->identity.thread_count = 256;
  176. if (gpu->identity.vertex_cache_size == 0)
  177. gpu->identity.vertex_cache_size = 8;
  178. if (gpu->identity.shader_core_count == 0) {
  179. if (gpu->identity.model >= 0x1000)
  180. gpu->identity.shader_core_count = 2;
  181. else
  182. gpu->identity.shader_core_count = 1;
  183. }
  184. if (gpu->identity.pixel_pipes == 0)
  185. gpu->identity.pixel_pipes = 1;
  186. /* Convert virtex buffer size */
  187. if (gpu->identity.vertex_output_buffer_size) {
  188. gpu->identity.vertex_output_buffer_size =
  189. 1 << gpu->identity.vertex_output_buffer_size;
  190. } else if (gpu->identity.model == chipModel_GC400) {
  191. if (gpu->identity.revision < 0x4000)
  192. gpu->identity.vertex_output_buffer_size = 512;
  193. else if (gpu->identity.revision < 0x4200)
  194. gpu->identity.vertex_output_buffer_size = 256;
  195. else
  196. gpu->identity.vertex_output_buffer_size = 128;
  197. } else {
  198. gpu->identity.vertex_output_buffer_size = 512;
  199. }
  200. switch (gpu->identity.instruction_count) {
  201. case 0:
  202. if (etnaviv_is_model_rev(gpu, GC2000, 0x5108) ||
  203. gpu->identity.model == chipModel_GC880)
  204. gpu->identity.instruction_count = 512;
  205. else
  206. gpu->identity.instruction_count = 256;
  207. break;
  208. case 1:
  209. gpu->identity.instruction_count = 1024;
  210. break;
  211. case 2:
  212. gpu->identity.instruction_count = 2048;
  213. break;
  214. default:
  215. gpu->identity.instruction_count = 256;
  216. break;
  217. }
  218. if (gpu->identity.num_constants == 0)
  219. gpu->identity.num_constants = 168;
  220. if (gpu->identity.varyings_count == 0) {
  221. if (gpu->identity.minor_features1 & chipMinorFeatures1_HALTI0)
  222. gpu->identity.varyings_count = 12;
  223. else
  224. gpu->identity.varyings_count = 8;
  225. }
  226. /*
  227. * For some cores, two varyings are consumed for position, so the
  228. * maximum varying count needs to be reduced by one.
  229. */
  230. if (etnaviv_is_model_rev(gpu, GC5000, 0x5434) ||
  231. etnaviv_is_model_rev(gpu, GC4000, 0x5222) ||
  232. etnaviv_is_model_rev(gpu, GC4000, 0x5245) ||
  233. etnaviv_is_model_rev(gpu, GC4000, 0x5208) ||
  234. etnaviv_is_model_rev(gpu, GC3000, 0x5435) ||
  235. etnaviv_is_model_rev(gpu, GC2200, 0x5244) ||
  236. etnaviv_is_model_rev(gpu, GC2100, 0x5108) ||
  237. etnaviv_is_model_rev(gpu, GC2000, 0x5108) ||
  238. etnaviv_is_model_rev(gpu, GC1500, 0x5246) ||
  239. etnaviv_is_model_rev(gpu, GC880, 0x5107) ||
  240. etnaviv_is_model_rev(gpu, GC880, 0x5106))
  241. gpu->identity.varyings_count -= 1;
  242. }
  243. static void etnaviv_hw_identify(struct etnaviv_gpu *gpu)
  244. {
  245. u32 chipIdentity;
  246. chipIdentity = gpu_read(gpu, VIVS_HI_CHIP_IDENTITY);
  247. /* Special case for older graphic cores. */
  248. if (etnaviv_field(chipIdentity, VIVS_HI_CHIP_IDENTITY_FAMILY) == 0x01) {
  249. gpu->identity.model = chipModel_GC500;
  250. gpu->identity.revision = etnaviv_field(chipIdentity,
  251. VIVS_HI_CHIP_IDENTITY_REVISION);
  252. } else {
  253. gpu->identity.model = gpu_read(gpu, VIVS_HI_CHIP_MODEL);
  254. gpu->identity.revision = gpu_read(gpu, VIVS_HI_CHIP_REV);
  255. /*
  256. * !!!! HACK ALERT !!!!
  257. * Because people change device IDs without letting software
  258. * know about it - here is the hack to make it all look the
  259. * same. Only for GC400 family.
  260. */
  261. if ((gpu->identity.model & 0xff00) == 0x0400 &&
  262. gpu->identity.model != chipModel_GC420) {
  263. gpu->identity.model = gpu->identity.model & 0x0400;
  264. }
  265. /* Another special case */
  266. if (etnaviv_is_model_rev(gpu, GC300, 0x2201)) {
  267. u32 chipDate = gpu_read(gpu, VIVS_HI_CHIP_DATE);
  268. u32 chipTime = gpu_read(gpu, VIVS_HI_CHIP_TIME);
  269. if (chipDate == 0x20080814 && chipTime == 0x12051100) {
  270. /*
  271. * This IP has an ECO; put the correct
  272. * revision in it.
  273. */
  274. gpu->identity.revision = 0x1051;
  275. }
  276. }
  277. }
  278. dev_info(gpu->dev, "model: GC%x, revision: %x\n",
  279. gpu->identity.model, gpu->identity.revision);
  280. gpu->identity.features = gpu_read(gpu, VIVS_HI_CHIP_FEATURE);
  281. /* Disable fast clear on GC700. */
  282. if (gpu->identity.model == chipModel_GC700)
  283. gpu->identity.features &= ~chipFeatures_FAST_CLEAR;
  284. if ((gpu->identity.model == chipModel_GC500 &&
  285. gpu->identity.revision < 2) ||
  286. (gpu->identity.model == chipModel_GC300 &&
  287. gpu->identity.revision < 0x2000)) {
  288. /*
  289. * GC500 rev 1.x and GC300 rev < 2.0 doesn't have these
  290. * registers.
  291. */
  292. gpu->identity.minor_features0 = 0;
  293. gpu->identity.minor_features1 = 0;
  294. gpu->identity.minor_features2 = 0;
  295. gpu->identity.minor_features3 = 0;
  296. gpu->identity.minor_features4 = 0;
  297. gpu->identity.minor_features5 = 0;
  298. } else
  299. gpu->identity.minor_features0 =
  300. gpu_read(gpu, VIVS_HI_CHIP_MINOR_FEATURE_0);
  301. if (gpu->identity.minor_features0 &
  302. chipMinorFeatures0_MORE_MINOR_FEATURES) {
  303. gpu->identity.minor_features1 =
  304. gpu_read(gpu, VIVS_HI_CHIP_MINOR_FEATURE_1);
  305. gpu->identity.minor_features2 =
  306. gpu_read(gpu, VIVS_HI_CHIP_MINOR_FEATURE_2);
  307. gpu->identity.minor_features3 =
  308. gpu_read(gpu, VIVS_HI_CHIP_MINOR_FEATURE_3);
  309. gpu->identity.minor_features4 =
  310. gpu_read(gpu, VIVS_HI_CHIP_MINOR_FEATURE_4);
  311. gpu->identity.minor_features5 =
  312. gpu_read(gpu, VIVS_HI_CHIP_MINOR_FEATURE_5);
  313. }
  314. /* GC600 idle register reports zero bits where modules aren't present */
  315. if (gpu->identity.model == chipModel_GC600) {
  316. gpu->idle_mask = VIVS_HI_IDLE_STATE_TX |
  317. VIVS_HI_IDLE_STATE_RA |
  318. VIVS_HI_IDLE_STATE_SE |
  319. VIVS_HI_IDLE_STATE_PA |
  320. VIVS_HI_IDLE_STATE_SH |
  321. VIVS_HI_IDLE_STATE_PE |
  322. VIVS_HI_IDLE_STATE_DE |
  323. VIVS_HI_IDLE_STATE_FE;
  324. } else {
  325. gpu->idle_mask = ~VIVS_HI_IDLE_STATE_AXI_LP;
  326. }
  327. etnaviv_hw_specs(gpu);
  328. }
  329. static void etnaviv_gpu_load_clock(struct etnaviv_gpu *gpu, u32 clock)
  330. {
  331. gpu_write(gpu, VIVS_HI_CLOCK_CONTROL, clock |
  332. VIVS_HI_CLOCK_CONTROL_FSCALE_CMD_LOAD);
  333. gpu_write(gpu, VIVS_HI_CLOCK_CONTROL, clock);
  334. }
  335. static int etnaviv_hw_reset(struct etnaviv_gpu *gpu)
  336. {
  337. u32 control, idle;
  338. unsigned long timeout;
  339. bool failed = true;
  340. /* TODO
  341. *
  342. * - clock gating
  343. * - puls eater
  344. * - what about VG?
  345. */
  346. /* We hope that the GPU resets in under one second */
  347. timeout = jiffies + msecs_to_jiffies(1000);
  348. while (time_is_after_jiffies(timeout)) {
  349. control = VIVS_HI_CLOCK_CONTROL_DISABLE_DEBUG_REGISTERS |
  350. VIVS_HI_CLOCK_CONTROL_FSCALE_VAL(0x40);
  351. /* enable clock */
  352. etnaviv_gpu_load_clock(gpu, control);
  353. /* Wait for stable clock. Vivante's code waited for 1ms */
  354. usleep_range(1000, 10000);
  355. /* isolate the GPU. */
  356. control |= VIVS_HI_CLOCK_CONTROL_ISOLATE_GPU;
  357. gpu_write(gpu, VIVS_HI_CLOCK_CONTROL, control);
  358. /* set soft reset. */
  359. control |= VIVS_HI_CLOCK_CONTROL_SOFT_RESET;
  360. gpu_write(gpu, VIVS_HI_CLOCK_CONTROL, control);
  361. /* wait for reset. */
  362. msleep(1);
  363. /* reset soft reset bit. */
  364. control &= ~VIVS_HI_CLOCK_CONTROL_SOFT_RESET;
  365. gpu_write(gpu, VIVS_HI_CLOCK_CONTROL, control);
  366. /* reset GPU isolation. */
  367. control &= ~VIVS_HI_CLOCK_CONTROL_ISOLATE_GPU;
  368. gpu_write(gpu, VIVS_HI_CLOCK_CONTROL, control);
  369. /* read idle register. */
  370. idle = gpu_read(gpu, VIVS_HI_IDLE_STATE);
  371. /* try reseting again if FE it not idle */
  372. if ((idle & VIVS_HI_IDLE_STATE_FE) == 0) {
  373. dev_dbg(gpu->dev, "FE is not idle\n");
  374. continue;
  375. }
  376. /* read reset register. */
  377. control = gpu_read(gpu, VIVS_HI_CLOCK_CONTROL);
  378. /* is the GPU idle? */
  379. if (((control & VIVS_HI_CLOCK_CONTROL_IDLE_3D) == 0) ||
  380. ((control & VIVS_HI_CLOCK_CONTROL_IDLE_2D) == 0)) {
  381. dev_dbg(gpu->dev, "GPU is not idle\n");
  382. continue;
  383. }
  384. failed = false;
  385. break;
  386. }
  387. if (failed) {
  388. idle = gpu_read(gpu, VIVS_HI_IDLE_STATE);
  389. control = gpu_read(gpu, VIVS_HI_CLOCK_CONTROL);
  390. dev_err(gpu->dev, "GPU failed to reset: FE %sidle, 3D %sidle, 2D %sidle\n",
  391. idle & VIVS_HI_IDLE_STATE_FE ? "" : "not ",
  392. control & VIVS_HI_CLOCK_CONTROL_IDLE_3D ? "" : "not ",
  393. control & VIVS_HI_CLOCK_CONTROL_IDLE_2D ? "" : "not ");
  394. return -EBUSY;
  395. }
  396. /* We rely on the GPU running, so program the clock */
  397. control = VIVS_HI_CLOCK_CONTROL_DISABLE_DEBUG_REGISTERS |
  398. VIVS_HI_CLOCK_CONTROL_FSCALE_VAL(0x40);
  399. /* enable clock */
  400. etnaviv_gpu_load_clock(gpu, control);
  401. return 0;
  402. }
  403. static void etnaviv_gpu_enable_mlcg(struct etnaviv_gpu *gpu)
  404. {
  405. u32 pmc, ppc;
  406. /* enable clock gating */
  407. ppc = gpu_read(gpu, VIVS_PM_POWER_CONTROLS);
  408. ppc |= VIVS_PM_POWER_CONTROLS_ENABLE_MODULE_CLOCK_GATING;
  409. /* Disable stall module clock gating for 4.3.0.1 and 4.3.0.2 revs */
  410. if (gpu->identity.revision == 0x4301 ||
  411. gpu->identity.revision == 0x4302)
  412. ppc |= VIVS_PM_POWER_CONTROLS_DISABLE_STALL_MODULE_CLOCK_GATING;
  413. gpu_write(gpu, VIVS_PM_POWER_CONTROLS, ppc);
  414. pmc = gpu_read(gpu, VIVS_PM_MODULE_CONTROLS);
  415. /* Disable PA clock gating for GC400+ except for GC420 */
  416. if (gpu->identity.model >= chipModel_GC400 &&
  417. gpu->identity.model != chipModel_GC420)
  418. pmc |= VIVS_PM_MODULE_CONTROLS_DISABLE_MODULE_CLOCK_GATING_PA;
  419. /*
  420. * Disable PE clock gating on revs < 5.0.0.0 when HZ is
  421. * present without a bug fix.
  422. */
  423. if (gpu->identity.revision < 0x5000 &&
  424. gpu->identity.minor_features0 & chipMinorFeatures0_HZ &&
  425. !(gpu->identity.minor_features1 &
  426. chipMinorFeatures1_DISABLE_PE_GATING))
  427. pmc |= VIVS_PM_MODULE_CONTROLS_DISABLE_MODULE_CLOCK_GATING_PE;
  428. if (gpu->identity.revision < 0x5422)
  429. pmc |= BIT(15); /* Unknown bit */
  430. pmc |= VIVS_PM_MODULE_CONTROLS_DISABLE_MODULE_CLOCK_GATING_RA_HZ;
  431. pmc |= VIVS_PM_MODULE_CONTROLS_DISABLE_MODULE_CLOCK_GATING_RA_EZ;
  432. gpu_write(gpu, VIVS_PM_MODULE_CONTROLS, pmc);
  433. }
  434. static void etnaviv_gpu_hw_init(struct etnaviv_gpu *gpu)
  435. {
  436. u16 prefetch;
  437. if ((etnaviv_is_model_rev(gpu, GC320, 0x5007) ||
  438. etnaviv_is_model_rev(gpu, GC320, 0x5220)) &&
  439. gpu_read(gpu, VIVS_HI_CHIP_TIME) != 0x2062400) {
  440. u32 mc_memory_debug;
  441. mc_memory_debug = gpu_read(gpu, VIVS_MC_DEBUG_MEMORY) & ~0xff;
  442. if (gpu->identity.revision == 0x5007)
  443. mc_memory_debug |= 0x0c;
  444. else
  445. mc_memory_debug |= 0x08;
  446. gpu_write(gpu, VIVS_MC_DEBUG_MEMORY, mc_memory_debug);
  447. }
  448. /* enable module-level clock gating */
  449. etnaviv_gpu_enable_mlcg(gpu);
  450. /*
  451. * Update GPU AXI cache atttribute to "cacheable, no allocate".
  452. * This is necessary to prevent the iMX6 SoC locking up.
  453. */
  454. gpu_write(gpu, VIVS_HI_AXI_CONFIG,
  455. VIVS_HI_AXI_CONFIG_AWCACHE(2) |
  456. VIVS_HI_AXI_CONFIG_ARCACHE(2));
  457. /* GC2000 rev 5108 needs a special bus config */
  458. if (etnaviv_is_model_rev(gpu, GC2000, 0x5108)) {
  459. u32 bus_config = gpu_read(gpu, VIVS_MC_BUS_CONFIG);
  460. bus_config &= ~(VIVS_MC_BUS_CONFIG_FE_BUS_CONFIG__MASK |
  461. VIVS_MC_BUS_CONFIG_TX_BUS_CONFIG__MASK);
  462. bus_config |= VIVS_MC_BUS_CONFIG_FE_BUS_CONFIG(1) |
  463. VIVS_MC_BUS_CONFIG_TX_BUS_CONFIG(0);
  464. gpu_write(gpu, VIVS_MC_BUS_CONFIG, bus_config);
  465. }
  466. /* set base addresses */
  467. gpu_write(gpu, VIVS_MC_MEMORY_BASE_ADDR_RA, gpu->memory_base);
  468. gpu_write(gpu, VIVS_MC_MEMORY_BASE_ADDR_FE, gpu->memory_base);
  469. gpu_write(gpu, VIVS_MC_MEMORY_BASE_ADDR_TX, gpu->memory_base);
  470. gpu_write(gpu, VIVS_MC_MEMORY_BASE_ADDR_PEZ, gpu->memory_base);
  471. gpu_write(gpu, VIVS_MC_MEMORY_BASE_ADDR_PE, gpu->memory_base);
  472. /* setup the MMU page table pointers */
  473. etnaviv_iommu_domain_restore(gpu, gpu->mmu->domain);
  474. /* Start command processor */
  475. prefetch = etnaviv_buffer_init(gpu);
  476. gpu_write(gpu, VIVS_HI_INTR_ENBL, ~0U);
  477. gpu_write(gpu, VIVS_FE_COMMAND_ADDRESS,
  478. gpu->buffer->paddr - gpu->memory_base);
  479. gpu_write(gpu, VIVS_FE_COMMAND_CONTROL,
  480. VIVS_FE_COMMAND_CONTROL_ENABLE |
  481. VIVS_FE_COMMAND_CONTROL_PREFETCH(prefetch));
  482. }
  483. int etnaviv_gpu_init(struct etnaviv_gpu *gpu)
  484. {
  485. int ret, i;
  486. struct iommu_domain *iommu;
  487. enum etnaviv_iommu_version version;
  488. bool mmuv2;
  489. ret = pm_runtime_get_sync(gpu->dev);
  490. if (ret < 0) {
  491. dev_err(gpu->dev, "Failed to enable GPU power domain\n");
  492. return ret;
  493. }
  494. etnaviv_hw_identify(gpu);
  495. if (gpu->identity.model == 0) {
  496. dev_err(gpu->dev, "Unknown GPU model\n");
  497. ret = -ENXIO;
  498. goto fail;
  499. }
  500. /* Exclude VG cores with FE2.0 */
  501. if (gpu->identity.features & chipFeatures_PIPE_VG &&
  502. gpu->identity.features & chipFeatures_FE20) {
  503. dev_info(gpu->dev, "Ignoring GPU with VG and FE2.0\n");
  504. ret = -ENXIO;
  505. goto fail;
  506. }
  507. /*
  508. * Set the GPU linear window to be at the end of the DMA window, where
  509. * the CMA area is likely to reside. This ensures that we are able to
  510. * map the command buffers while having the linear window overlap as
  511. * much RAM as possible, so we can optimize mappings for other buffers.
  512. *
  513. * For 3D cores only do this if MC2.0 is present, as with MC1.0 it leads
  514. * to different views of the memory on the individual engines.
  515. */
  516. if (!(gpu->identity.features & chipFeatures_PIPE_3D) ||
  517. (gpu->identity.minor_features0 & chipMinorFeatures0_MC20)) {
  518. u32 dma_mask = (u32)dma_get_required_mask(gpu->dev);
  519. if (dma_mask < PHYS_OFFSET + SZ_2G)
  520. gpu->memory_base = PHYS_OFFSET;
  521. else
  522. gpu->memory_base = dma_mask - SZ_2G + 1;
  523. }
  524. ret = etnaviv_hw_reset(gpu);
  525. if (ret) {
  526. dev_err(gpu->dev, "GPU reset failed\n");
  527. goto fail;
  528. }
  529. /* Setup IOMMU.. eventually we will (I think) do this once per context
  530. * and have separate page tables per context. For now, to keep things
  531. * simple and to get something working, just use a single address space:
  532. */
  533. mmuv2 = gpu->identity.minor_features1 & chipMinorFeatures1_MMU_VERSION;
  534. dev_dbg(gpu->dev, "mmuv2: %d\n", mmuv2);
  535. if (!mmuv2) {
  536. iommu = etnaviv_iommu_domain_alloc(gpu);
  537. version = ETNAVIV_IOMMU_V1;
  538. } else {
  539. iommu = etnaviv_iommu_v2_domain_alloc(gpu);
  540. version = ETNAVIV_IOMMU_V2;
  541. }
  542. if (!iommu) {
  543. dev_err(gpu->dev, "Failed to allocate GPU IOMMU domain\n");
  544. ret = -ENOMEM;
  545. goto fail;
  546. }
  547. gpu->mmu = etnaviv_iommu_new(gpu, iommu, version);
  548. if (!gpu->mmu) {
  549. dev_err(gpu->dev, "Failed to instantiate GPU IOMMU\n");
  550. iommu_domain_free(iommu);
  551. ret = -ENOMEM;
  552. goto fail;
  553. }
  554. /* Create buffer: */
  555. gpu->buffer = etnaviv_gpu_cmdbuf_new(gpu, PAGE_SIZE, 0);
  556. if (!gpu->buffer) {
  557. ret = -ENOMEM;
  558. dev_err(gpu->dev, "could not create command buffer\n");
  559. goto destroy_iommu;
  560. }
  561. if (gpu->buffer->paddr - gpu->memory_base > 0x80000000) {
  562. ret = -EINVAL;
  563. dev_err(gpu->dev,
  564. "command buffer outside valid memory window\n");
  565. goto free_buffer;
  566. }
  567. /* Setup event management */
  568. spin_lock_init(&gpu->event_spinlock);
  569. init_completion(&gpu->event_free);
  570. for (i = 0; i < ARRAY_SIZE(gpu->event); i++) {
  571. gpu->event[i].used = false;
  572. complete(&gpu->event_free);
  573. }
  574. /* Now program the hardware */
  575. mutex_lock(&gpu->lock);
  576. etnaviv_gpu_hw_init(gpu);
  577. gpu->exec_state = -1;
  578. mutex_unlock(&gpu->lock);
  579. pm_runtime_mark_last_busy(gpu->dev);
  580. pm_runtime_put_autosuspend(gpu->dev);
  581. return 0;
  582. free_buffer:
  583. etnaviv_gpu_cmdbuf_free(gpu->buffer);
  584. gpu->buffer = NULL;
  585. destroy_iommu:
  586. etnaviv_iommu_destroy(gpu->mmu);
  587. gpu->mmu = NULL;
  588. fail:
  589. pm_runtime_mark_last_busy(gpu->dev);
  590. pm_runtime_put_autosuspend(gpu->dev);
  591. return ret;
  592. }
  593. #ifdef CONFIG_DEBUG_FS
  594. struct dma_debug {
  595. u32 address[2];
  596. u32 state[2];
  597. };
  598. static void verify_dma(struct etnaviv_gpu *gpu, struct dma_debug *debug)
  599. {
  600. u32 i;
  601. debug->address[0] = gpu_read(gpu, VIVS_FE_DMA_ADDRESS);
  602. debug->state[0] = gpu_read(gpu, VIVS_FE_DMA_DEBUG_STATE);
  603. for (i = 0; i < 500; i++) {
  604. debug->address[1] = gpu_read(gpu, VIVS_FE_DMA_ADDRESS);
  605. debug->state[1] = gpu_read(gpu, VIVS_FE_DMA_DEBUG_STATE);
  606. if (debug->address[0] != debug->address[1])
  607. break;
  608. if (debug->state[0] != debug->state[1])
  609. break;
  610. }
  611. }
  612. int etnaviv_gpu_debugfs(struct etnaviv_gpu *gpu, struct seq_file *m)
  613. {
  614. struct dma_debug debug;
  615. u32 dma_lo, dma_hi, axi, idle;
  616. int ret;
  617. seq_printf(m, "%s Status:\n", dev_name(gpu->dev));
  618. ret = pm_runtime_get_sync(gpu->dev);
  619. if (ret < 0)
  620. return ret;
  621. dma_lo = gpu_read(gpu, VIVS_FE_DMA_LOW);
  622. dma_hi = gpu_read(gpu, VIVS_FE_DMA_HIGH);
  623. axi = gpu_read(gpu, VIVS_HI_AXI_STATUS);
  624. idle = gpu_read(gpu, VIVS_HI_IDLE_STATE);
  625. verify_dma(gpu, &debug);
  626. seq_puts(m, "\tfeatures\n");
  627. seq_printf(m, "\t minor_features0: 0x%08x\n",
  628. gpu->identity.minor_features0);
  629. seq_printf(m, "\t minor_features1: 0x%08x\n",
  630. gpu->identity.minor_features1);
  631. seq_printf(m, "\t minor_features2: 0x%08x\n",
  632. gpu->identity.minor_features2);
  633. seq_printf(m, "\t minor_features3: 0x%08x\n",
  634. gpu->identity.minor_features3);
  635. seq_printf(m, "\t minor_features4: 0x%08x\n",
  636. gpu->identity.minor_features4);
  637. seq_printf(m, "\t minor_features5: 0x%08x\n",
  638. gpu->identity.minor_features5);
  639. seq_puts(m, "\tspecs\n");
  640. seq_printf(m, "\t stream_count: %d\n",
  641. gpu->identity.stream_count);
  642. seq_printf(m, "\t register_max: %d\n",
  643. gpu->identity.register_max);
  644. seq_printf(m, "\t thread_count: %d\n",
  645. gpu->identity.thread_count);
  646. seq_printf(m, "\t vertex_cache_size: %d\n",
  647. gpu->identity.vertex_cache_size);
  648. seq_printf(m, "\t shader_core_count: %d\n",
  649. gpu->identity.shader_core_count);
  650. seq_printf(m, "\t pixel_pipes: %d\n",
  651. gpu->identity.pixel_pipes);
  652. seq_printf(m, "\t vertex_output_buffer_size: %d\n",
  653. gpu->identity.vertex_output_buffer_size);
  654. seq_printf(m, "\t buffer_size: %d\n",
  655. gpu->identity.buffer_size);
  656. seq_printf(m, "\t instruction_count: %d\n",
  657. gpu->identity.instruction_count);
  658. seq_printf(m, "\t num_constants: %d\n",
  659. gpu->identity.num_constants);
  660. seq_printf(m, "\t varyings_count: %d\n",
  661. gpu->identity.varyings_count);
  662. seq_printf(m, "\taxi: 0x%08x\n", axi);
  663. seq_printf(m, "\tidle: 0x%08x\n", idle);
  664. idle |= ~gpu->idle_mask & ~VIVS_HI_IDLE_STATE_AXI_LP;
  665. if ((idle & VIVS_HI_IDLE_STATE_FE) == 0)
  666. seq_puts(m, "\t FE is not idle\n");
  667. if ((idle & VIVS_HI_IDLE_STATE_DE) == 0)
  668. seq_puts(m, "\t DE is not idle\n");
  669. if ((idle & VIVS_HI_IDLE_STATE_PE) == 0)
  670. seq_puts(m, "\t PE is not idle\n");
  671. if ((idle & VIVS_HI_IDLE_STATE_SH) == 0)
  672. seq_puts(m, "\t SH is not idle\n");
  673. if ((idle & VIVS_HI_IDLE_STATE_PA) == 0)
  674. seq_puts(m, "\t PA is not idle\n");
  675. if ((idle & VIVS_HI_IDLE_STATE_SE) == 0)
  676. seq_puts(m, "\t SE is not idle\n");
  677. if ((idle & VIVS_HI_IDLE_STATE_RA) == 0)
  678. seq_puts(m, "\t RA is not idle\n");
  679. if ((idle & VIVS_HI_IDLE_STATE_TX) == 0)
  680. seq_puts(m, "\t TX is not idle\n");
  681. if ((idle & VIVS_HI_IDLE_STATE_VG) == 0)
  682. seq_puts(m, "\t VG is not idle\n");
  683. if ((idle & VIVS_HI_IDLE_STATE_IM) == 0)
  684. seq_puts(m, "\t IM is not idle\n");
  685. if ((idle & VIVS_HI_IDLE_STATE_FP) == 0)
  686. seq_puts(m, "\t FP is not idle\n");
  687. if ((idle & VIVS_HI_IDLE_STATE_TS) == 0)
  688. seq_puts(m, "\t TS is not idle\n");
  689. if (idle & VIVS_HI_IDLE_STATE_AXI_LP)
  690. seq_puts(m, "\t AXI low power mode\n");
  691. if (gpu->identity.features & chipFeatures_DEBUG_MODE) {
  692. u32 read0 = gpu_read(gpu, VIVS_MC_DEBUG_READ0);
  693. u32 read1 = gpu_read(gpu, VIVS_MC_DEBUG_READ1);
  694. u32 write = gpu_read(gpu, VIVS_MC_DEBUG_WRITE);
  695. seq_puts(m, "\tMC\n");
  696. seq_printf(m, "\t read0: 0x%08x\n", read0);
  697. seq_printf(m, "\t read1: 0x%08x\n", read1);
  698. seq_printf(m, "\t write: 0x%08x\n", write);
  699. }
  700. seq_puts(m, "\tDMA ");
  701. if (debug.address[0] == debug.address[1] &&
  702. debug.state[0] == debug.state[1]) {
  703. seq_puts(m, "seems to be stuck\n");
  704. } else if (debug.address[0] == debug.address[1]) {
  705. seq_puts(m, "address is constant\n");
  706. } else {
  707. seq_puts(m, "is running\n");
  708. }
  709. seq_printf(m, "\t address 0: 0x%08x\n", debug.address[0]);
  710. seq_printf(m, "\t address 1: 0x%08x\n", debug.address[1]);
  711. seq_printf(m, "\t state 0: 0x%08x\n", debug.state[0]);
  712. seq_printf(m, "\t state 1: 0x%08x\n", debug.state[1]);
  713. seq_printf(m, "\t last fetch 64 bit word: 0x%08x 0x%08x\n",
  714. dma_lo, dma_hi);
  715. ret = 0;
  716. pm_runtime_mark_last_busy(gpu->dev);
  717. pm_runtime_put_autosuspend(gpu->dev);
  718. return ret;
  719. }
  720. #endif
  721. /*
  722. * Power Management:
  723. */
  724. static int enable_clk(struct etnaviv_gpu *gpu)
  725. {
  726. if (gpu->clk_core)
  727. clk_prepare_enable(gpu->clk_core);
  728. if (gpu->clk_shader)
  729. clk_prepare_enable(gpu->clk_shader);
  730. return 0;
  731. }
  732. static int disable_clk(struct etnaviv_gpu *gpu)
  733. {
  734. if (gpu->clk_core)
  735. clk_disable_unprepare(gpu->clk_core);
  736. if (gpu->clk_shader)
  737. clk_disable_unprepare(gpu->clk_shader);
  738. return 0;
  739. }
  740. static int enable_axi(struct etnaviv_gpu *gpu)
  741. {
  742. if (gpu->clk_bus)
  743. clk_prepare_enable(gpu->clk_bus);
  744. return 0;
  745. }
  746. static int disable_axi(struct etnaviv_gpu *gpu)
  747. {
  748. if (gpu->clk_bus)
  749. clk_disable_unprepare(gpu->clk_bus);
  750. return 0;
  751. }
  752. /*
  753. * Hangcheck detection for locked gpu:
  754. */
  755. static void recover_worker(struct work_struct *work)
  756. {
  757. struct etnaviv_gpu *gpu = container_of(work, struct etnaviv_gpu,
  758. recover_work);
  759. unsigned long flags;
  760. unsigned int i;
  761. dev_err(gpu->dev, "hangcheck recover!\n");
  762. if (pm_runtime_get_sync(gpu->dev) < 0)
  763. return;
  764. mutex_lock(&gpu->lock);
  765. /* Only catch the first event, or when manually re-armed */
  766. if (etnaviv_dump_core) {
  767. etnaviv_core_dump(gpu);
  768. etnaviv_dump_core = false;
  769. }
  770. etnaviv_hw_reset(gpu);
  771. /* complete all events, the GPU won't do it after the reset */
  772. spin_lock_irqsave(&gpu->event_spinlock, flags);
  773. for (i = 0; i < ARRAY_SIZE(gpu->event); i++) {
  774. if (!gpu->event[i].used)
  775. continue;
  776. fence_signal(gpu->event[i].fence);
  777. gpu->event[i].fence = NULL;
  778. gpu->event[i].used = false;
  779. complete(&gpu->event_free);
  780. }
  781. spin_unlock_irqrestore(&gpu->event_spinlock, flags);
  782. gpu->completed_fence = gpu->active_fence;
  783. etnaviv_gpu_hw_init(gpu);
  784. gpu->switch_context = true;
  785. gpu->exec_state = -1;
  786. mutex_unlock(&gpu->lock);
  787. pm_runtime_mark_last_busy(gpu->dev);
  788. pm_runtime_put_autosuspend(gpu->dev);
  789. /* Retire the buffer objects in a work */
  790. etnaviv_queue_work(gpu->drm, &gpu->retire_work);
  791. }
  792. static void hangcheck_timer_reset(struct etnaviv_gpu *gpu)
  793. {
  794. DBG("%s", dev_name(gpu->dev));
  795. mod_timer(&gpu->hangcheck_timer,
  796. round_jiffies_up(jiffies + DRM_ETNAVIV_HANGCHECK_JIFFIES));
  797. }
  798. static void hangcheck_handler(unsigned long data)
  799. {
  800. struct etnaviv_gpu *gpu = (struct etnaviv_gpu *)data;
  801. u32 fence = gpu->completed_fence;
  802. bool progress = false;
  803. if (fence != gpu->hangcheck_fence) {
  804. gpu->hangcheck_fence = fence;
  805. progress = true;
  806. }
  807. if (!progress) {
  808. u32 dma_addr = gpu_read(gpu, VIVS_FE_DMA_ADDRESS);
  809. int change = dma_addr - gpu->hangcheck_dma_addr;
  810. if (change < 0 || change > 16) {
  811. gpu->hangcheck_dma_addr = dma_addr;
  812. progress = true;
  813. }
  814. }
  815. if (!progress && fence_after(gpu->active_fence, fence)) {
  816. dev_err(gpu->dev, "hangcheck detected gpu lockup!\n");
  817. dev_err(gpu->dev, " completed fence: %u\n", fence);
  818. dev_err(gpu->dev, " active fence: %u\n",
  819. gpu->active_fence);
  820. etnaviv_queue_work(gpu->drm, &gpu->recover_work);
  821. }
  822. /* if still more pending work, reset the hangcheck timer: */
  823. if (fence_after(gpu->active_fence, gpu->hangcheck_fence))
  824. hangcheck_timer_reset(gpu);
  825. }
  826. static void hangcheck_disable(struct etnaviv_gpu *gpu)
  827. {
  828. del_timer_sync(&gpu->hangcheck_timer);
  829. cancel_work_sync(&gpu->recover_work);
  830. }
  831. /* fence object management */
  832. struct etnaviv_fence {
  833. struct etnaviv_gpu *gpu;
  834. struct fence base;
  835. };
  836. static inline struct etnaviv_fence *to_etnaviv_fence(struct fence *fence)
  837. {
  838. return container_of(fence, struct etnaviv_fence, base);
  839. }
  840. static const char *etnaviv_fence_get_driver_name(struct fence *fence)
  841. {
  842. return "etnaviv";
  843. }
  844. static const char *etnaviv_fence_get_timeline_name(struct fence *fence)
  845. {
  846. struct etnaviv_fence *f = to_etnaviv_fence(fence);
  847. return dev_name(f->gpu->dev);
  848. }
  849. static bool etnaviv_fence_enable_signaling(struct fence *fence)
  850. {
  851. return true;
  852. }
  853. static bool etnaviv_fence_signaled(struct fence *fence)
  854. {
  855. struct etnaviv_fence *f = to_etnaviv_fence(fence);
  856. return fence_completed(f->gpu, f->base.seqno);
  857. }
  858. static void etnaviv_fence_release(struct fence *fence)
  859. {
  860. struct etnaviv_fence *f = to_etnaviv_fence(fence);
  861. kfree_rcu(f, base.rcu);
  862. }
  863. static const struct fence_ops etnaviv_fence_ops = {
  864. .get_driver_name = etnaviv_fence_get_driver_name,
  865. .get_timeline_name = etnaviv_fence_get_timeline_name,
  866. .enable_signaling = etnaviv_fence_enable_signaling,
  867. .signaled = etnaviv_fence_signaled,
  868. .wait = fence_default_wait,
  869. .release = etnaviv_fence_release,
  870. };
  871. static struct fence *etnaviv_gpu_fence_alloc(struct etnaviv_gpu *gpu)
  872. {
  873. struct etnaviv_fence *f;
  874. f = kzalloc(sizeof(*f), GFP_KERNEL);
  875. if (!f)
  876. return NULL;
  877. f->gpu = gpu;
  878. fence_init(&f->base, &etnaviv_fence_ops, &gpu->fence_spinlock,
  879. gpu->fence_context, ++gpu->next_fence);
  880. return &f->base;
  881. }
  882. int etnaviv_gpu_fence_sync_obj(struct etnaviv_gem_object *etnaviv_obj,
  883. unsigned int context, bool exclusive)
  884. {
  885. struct reservation_object *robj = etnaviv_obj->resv;
  886. struct reservation_object_list *fobj;
  887. struct fence *fence;
  888. int i, ret;
  889. if (!exclusive) {
  890. ret = reservation_object_reserve_shared(robj);
  891. if (ret)
  892. return ret;
  893. }
  894. /*
  895. * If we have any shared fences, then the exclusive fence
  896. * should be ignored as it will already have been signalled.
  897. */
  898. fobj = reservation_object_get_list(robj);
  899. if (!fobj || fobj->shared_count == 0) {
  900. /* Wait on any existing exclusive fence which isn't our own */
  901. fence = reservation_object_get_excl(robj);
  902. if (fence && fence->context != context) {
  903. ret = fence_wait(fence, true);
  904. if (ret)
  905. return ret;
  906. }
  907. }
  908. if (!exclusive || !fobj)
  909. return 0;
  910. for (i = 0; i < fobj->shared_count; i++) {
  911. fence = rcu_dereference_protected(fobj->shared[i],
  912. reservation_object_held(robj));
  913. if (fence->context != context) {
  914. ret = fence_wait(fence, true);
  915. if (ret)
  916. return ret;
  917. }
  918. }
  919. return 0;
  920. }
  921. /*
  922. * event management:
  923. */
  924. static unsigned int event_alloc(struct etnaviv_gpu *gpu)
  925. {
  926. unsigned long ret, flags;
  927. unsigned int i, event = ~0U;
  928. ret = wait_for_completion_timeout(&gpu->event_free,
  929. msecs_to_jiffies(10 * 10000));
  930. if (!ret)
  931. dev_err(gpu->dev, "wait_for_completion_timeout failed");
  932. spin_lock_irqsave(&gpu->event_spinlock, flags);
  933. /* find first free event */
  934. for (i = 0; i < ARRAY_SIZE(gpu->event); i++) {
  935. if (gpu->event[i].used == false) {
  936. gpu->event[i].used = true;
  937. event = i;
  938. break;
  939. }
  940. }
  941. spin_unlock_irqrestore(&gpu->event_spinlock, flags);
  942. return event;
  943. }
  944. static void event_free(struct etnaviv_gpu *gpu, unsigned int event)
  945. {
  946. unsigned long flags;
  947. spin_lock_irqsave(&gpu->event_spinlock, flags);
  948. if (gpu->event[event].used == false) {
  949. dev_warn(gpu->dev, "event %u is already marked as free",
  950. event);
  951. spin_unlock_irqrestore(&gpu->event_spinlock, flags);
  952. } else {
  953. gpu->event[event].used = false;
  954. spin_unlock_irqrestore(&gpu->event_spinlock, flags);
  955. complete(&gpu->event_free);
  956. }
  957. }
  958. /*
  959. * Cmdstream submission/retirement:
  960. */
  961. struct etnaviv_cmdbuf *etnaviv_gpu_cmdbuf_new(struct etnaviv_gpu *gpu, u32 size,
  962. size_t nr_bos)
  963. {
  964. struct etnaviv_cmdbuf *cmdbuf;
  965. size_t sz = size_vstruct(nr_bos, sizeof(cmdbuf->bo_map[0]),
  966. sizeof(*cmdbuf));
  967. cmdbuf = kzalloc(sz, GFP_KERNEL);
  968. if (!cmdbuf)
  969. return NULL;
  970. cmdbuf->vaddr = dma_alloc_wc(gpu->dev, size, &cmdbuf->paddr,
  971. GFP_KERNEL);
  972. if (!cmdbuf->vaddr) {
  973. kfree(cmdbuf);
  974. return NULL;
  975. }
  976. cmdbuf->gpu = gpu;
  977. cmdbuf->size = size;
  978. return cmdbuf;
  979. }
  980. void etnaviv_gpu_cmdbuf_free(struct etnaviv_cmdbuf *cmdbuf)
  981. {
  982. dma_free_wc(cmdbuf->gpu->dev, cmdbuf->size, cmdbuf->vaddr,
  983. cmdbuf->paddr);
  984. kfree(cmdbuf);
  985. }
  986. static void retire_worker(struct work_struct *work)
  987. {
  988. struct etnaviv_gpu *gpu = container_of(work, struct etnaviv_gpu,
  989. retire_work);
  990. u32 fence = gpu->completed_fence;
  991. struct etnaviv_cmdbuf *cmdbuf, *tmp;
  992. unsigned int i;
  993. mutex_lock(&gpu->lock);
  994. list_for_each_entry_safe(cmdbuf, tmp, &gpu->active_cmd_list, node) {
  995. if (!fence_is_signaled(cmdbuf->fence))
  996. break;
  997. list_del(&cmdbuf->node);
  998. fence_put(cmdbuf->fence);
  999. for (i = 0; i < cmdbuf->nr_bos; i++) {
  1000. struct etnaviv_vram_mapping *mapping = cmdbuf->bo_map[i];
  1001. struct etnaviv_gem_object *etnaviv_obj = mapping->object;
  1002. atomic_dec(&etnaviv_obj->gpu_active);
  1003. /* drop the refcount taken in etnaviv_gpu_submit */
  1004. etnaviv_gem_mapping_unreference(mapping);
  1005. }
  1006. etnaviv_gpu_cmdbuf_free(cmdbuf);
  1007. /*
  1008. * We need to balance the runtime PM count caused by
  1009. * each submission. Upon submission, we increment
  1010. * the runtime PM counter, and allocate one event.
  1011. * So here, we put the runtime PM count for each
  1012. * completed event.
  1013. */
  1014. pm_runtime_put_autosuspend(gpu->dev);
  1015. }
  1016. gpu->retired_fence = fence;
  1017. mutex_unlock(&gpu->lock);
  1018. wake_up_all(&gpu->fence_event);
  1019. }
  1020. int etnaviv_gpu_wait_fence_interruptible(struct etnaviv_gpu *gpu,
  1021. u32 fence, struct timespec *timeout)
  1022. {
  1023. int ret;
  1024. if (fence_after(fence, gpu->next_fence)) {
  1025. DRM_ERROR("waiting on invalid fence: %u (of %u)\n",
  1026. fence, gpu->next_fence);
  1027. return -EINVAL;
  1028. }
  1029. if (!timeout) {
  1030. /* No timeout was requested: just test for completion */
  1031. ret = fence_completed(gpu, fence) ? 0 : -EBUSY;
  1032. } else {
  1033. unsigned long remaining = etnaviv_timeout_to_jiffies(timeout);
  1034. ret = wait_event_interruptible_timeout(gpu->fence_event,
  1035. fence_completed(gpu, fence),
  1036. remaining);
  1037. if (ret == 0) {
  1038. DBG("timeout waiting for fence: %u (retired: %u completed: %u)",
  1039. fence, gpu->retired_fence,
  1040. gpu->completed_fence);
  1041. ret = -ETIMEDOUT;
  1042. } else if (ret != -ERESTARTSYS) {
  1043. ret = 0;
  1044. }
  1045. }
  1046. return ret;
  1047. }
  1048. /*
  1049. * Wait for an object to become inactive. This, on it's own, is not race
  1050. * free: the object is moved by the retire worker off the active list, and
  1051. * then the iova is put. Moreover, the object could be re-submitted just
  1052. * after we notice that it's become inactive.
  1053. *
  1054. * Although the retirement happens under the gpu lock, we don't want to hold
  1055. * that lock in this function while waiting.
  1056. */
  1057. int etnaviv_gpu_wait_obj_inactive(struct etnaviv_gpu *gpu,
  1058. struct etnaviv_gem_object *etnaviv_obj, struct timespec *timeout)
  1059. {
  1060. unsigned long remaining;
  1061. long ret;
  1062. if (!timeout)
  1063. return !is_active(etnaviv_obj) ? 0 : -EBUSY;
  1064. remaining = etnaviv_timeout_to_jiffies(timeout);
  1065. ret = wait_event_interruptible_timeout(gpu->fence_event,
  1066. !is_active(etnaviv_obj),
  1067. remaining);
  1068. if (ret > 0) {
  1069. struct etnaviv_drm_private *priv = gpu->drm->dev_private;
  1070. /* Synchronise with the retire worker */
  1071. flush_workqueue(priv->wq);
  1072. return 0;
  1073. } else if (ret == -ERESTARTSYS) {
  1074. return -ERESTARTSYS;
  1075. } else {
  1076. return -ETIMEDOUT;
  1077. }
  1078. }
  1079. int etnaviv_gpu_pm_get_sync(struct etnaviv_gpu *gpu)
  1080. {
  1081. return pm_runtime_get_sync(gpu->dev);
  1082. }
  1083. void etnaviv_gpu_pm_put(struct etnaviv_gpu *gpu)
  1084. {
  1085. pm_runtime_mark_last_busy(gpu->dev);
  1086. pm_runtime_put_autosuspend(gpu->dev);
  1087. }
  1088. /* add bo's to gpu's ring, and kick gpu: */
  1089. int etnaviv_gpu_submit(struct etnaviv_gpu *gpu,
  1090. struct etnaviv_gem_submit *submit, struct etnaviv_cmdbuf *cmdbuf)
  1091. {
  1092. struct fence *fence;
  1093. unsigned int event, i;
  1094. int ret;
  1095. ret = etnaviv_gpu_pm_get_sync(gpu);
  1096. if (ret < 0)
  1097. return ret;
  1098. /*
  1099. * TODO
  1100. *
  1101. * - flush
  1102. * - data endian
  1103. * - prefetch
  1104. *
  1105. */
  1106. event = event_alloc(gpu);
  1107. if (unlikely(event == ~0U)) {
  1108. DRM_ERROR("no free event\n");
  1109. ret = -EBUSY;
  1110. goto out_pm_put;
  1111. }
  1112. fence = etnaviv_gpu_fence_alloc(gpu);
  1113. if (!fence) {
  1114. event_free(gpu, event);
  1115. ret = -ENOMEM;
  1116. goto out_pm_put;
  1117. }
  1118. mutex_lock(&gpu->lock);
  1119. gpu->event[event].fence = fence;
  1120. submit->fence = fence->seqno;
  1121. gpu->active_fence = submit->fence;
  1122. if (gpu->lastctx != cmdbuf->ctx) {
  1123. gpu->mmu->need_flush = true;
  1124. gpu->switch_context = true;
  1125. gpu->lastctx = cmdbuf->ctx;
  1126. }
  1127. etnaviv_buffer_queue(gpu, event, cmdbuf);
  1128. cmdbuf->fence = fence;
  1129. list_add_tail(&cmdbuf->node, &gpu->active_cmd_list);
  1130. /* We're committed to adding this command buffer, hold a PM reference */
  1131. pm_runtime_get_noresume(gpu->dev);
  1132. for (i = 0; i < submit->nr_bos; i++) {
  1133. struct etnaviv_gem_object *etnaviv_obj = submit->bos[i].obj;
  1134. /* Each cmdbuf takes a refcount on the mapping */
  1135. etnaviv_gem_mapping_reference(submit->bos[i].mapping);
  1136. cmdbuf->bo_map[i] = submit->bos[i].mapping;
  1137. atomic_inc(&etnaviv_obj->gpu_active);
  1138. if (submit->bos[i].flags & ETNA_SUBMIT_BO_WRITE)
  1139. reservation_object_add_excl_fence(etnaviv_obj->resv,
  1140. fence);
  1141. else
  1142. reservation_object_add_shared_fence(etnaviv_obj->resv,
  1143. fence);
  1144. }
  1145. cmdbuf->nr_bos = submit->nr_bos;
  1146. hangcheck_timer_reset(gpu);
  1147. ret = 0;
  1148. mutex_unlock(&gpu->lock);
  1149. out_pm_put:
  1150. etnaviv_gpu_pm_put(gpu);
  1151. return ret;
  1152. }
  1153. /*
  1154. * Init/Cleanup:
  1155. */
  1156. static irqreturn_t irq_handler(int irq, void *data)
  1157. {
  1158. struct etnaviv_gpu *gpu = data;
  1159. irqreturn_t ret = IRQ_NONE;
  1160. u32 intr = gpu_read(gpu, VIVS_HI_INTR_ACKNOWLEDGE);
  1161. if (intr != 0) {
  1162. int event;
  1163. pm_runtime_mark_last_busy(gpu->dev);
  1164. dev_dbg(gpu->dev, "intr 0x%08x\n", intr);
  1165. if (intr & VIVS_HI_INTR_ACKNOWLEDGE_AXI_BUS_ERROR) {
  1166. dev_err(gpu->dev, "AXI bus error\n");
  1167. intr &= ~VIVS_HI_INTR_ACKNOWLEDGE_AXI_BUS_ERROR;
  1168. }
  1169. while ((event = ffs(intr)) != 0) {
  1170. struct fence *fence;
  1171. event -= 1;
  1172. intr &= ~(1 << event);
  1173. dev_dbg(gpu->dev, "event %u\n", event);
  1174. fence = gpu->event[event].fence;
  1175. gpu->event[event].fence = NULL;
  1176. fence_signal(fence);
  1177. /*
  1178. * Events can be processed out of order. Eg,
  1179. * - allocate and queue event 0
  1180. * - allocate event 1
  1181. * - event 0 completes, we process it
  1182. * - allocate and queue event 0
  1183. * - event 1 and event 0 complete
  1184. * we can end up processing event 0 first, then 1.
  1185. */
  1186. if (fence_after(fence->seqno, gpu->completed_fence))
  1187. gpu->completed_fence = fence->seqno;
  1188. event_free(gpu, event);
  1189. }
  1190. /* Retire the buffer objects in a work */
  1191. etnaviv_queue_work(gpu->drm, &gpu->retire_work);
  1192. ret = IRQ_HANDLED;
  1193. }
  1194. return ret;
  1195. }
  1196. static int etnaviv_gpu_clk_enable(struct etnaviv_gpu *gpu)
  1197. {
  1198. int ret;
  1199. ret = enable_clk(gpu);
  1200. if (ret)
  1201. return ret;
  1202. ret = enable_axi(gpu);
  1203. if (ret) {
  1204. disable_clk(gpu);
  1205. return ret;
  1206. }
  1207. return 0;
  1208. }
  1209. static int etnaviv_gpu_clk_disable(struct etnaviv_gpu *gpu)
  1210. {
  1211. int ret;
  1212. ret = disable_axi(gpu);
  1213. if (ret)
  1214. return ret;
  1215. ret = disable_clk(gpu);
  1216. if (ret)
  1217. return ret;
  1218. return 0;
  1219. }
  1220. static int etnaviv_gpu_hw_suspend(struct etnaviv_gpu *gpu)
  1221. {
  1222. if (gpu->buffer) {
  1223. unsigned long timeout;
  1224. /* Replace the last WAIT with END */
  1225. etnaviv_buffer_end(gpu);
  1226. /*
  1227. * We know that only the FE is busy here, this should
  1228. * happen quickly (as the WAIT is only 200 cycles). If
  1229. * we fail, just warn and continue.
  1230. */
  1231. timeout = jiffies + msecs_to_jiffies(100);
  1232. do {
  1233. u32 idle = gpu_read(gpu, VIVS_HI_IDLE_STATE);
  1234. if ((idle & gpu->idle_mask) == gpu->idle_mask)
  1235. break;
  1236. if (time_is_before_jiffies(timeout)) {
  1237. dev_warn(gpu->dev,
  1238. "timed out waiting for idle: idle=0x%x\n",
  1239. idle);
  1240. break;
  1241. }
  1242. udelay(5);
  1243. } while (1);
  1244. }
  1245. return etnaviv_gpu_clk_disable(gpu);
  1246. }
  1247. #ifdef CONFIG_PM
  1248. static int etnaviv_gpu_hw_resume(struct etnaviv_gpu *gpu)
  1249. {
  1250. u32 clock;
  1251. int ret;
  1252. ret = mutex_lock_killable(&gpu->lock);
  1253. if (ret)
  1254. return ret;
  1255. clock = VIVS_HI_CLOCK_CONTROL_DISABLE_DEBUG_REGISTERS |
  1256. VIVS_HI_CLOCK_CONTROL_FSCALE_VAL(0x40);
  1257. etnaviv_gpu_load_clock(gpu, clock);
  1258. etnaviv_gpu_hw_init(gpu);
  1259. gpu->switch_context = true;
  1260. gpu->exec_state = -1;
  1261. mutex_unlock(&gpu->lock);
  1262. return 0;
  1263. }
  1264. #endif
  1265. static int etnaviv_gpu_bind(struct device *dev, struct device *master,
  1266. void *data)
  1267. {
  1268. struct drm_device *drm = data;
  1269. struct etnaviv_drm_private *priv = drm->dev_private;
  1270. struct etnaviv_gpu *gpu = dev_get_drvdata(dev);
  1271. int ret;
  1272. #ifdef CONFIG_PM
  1273. ret = pm_runtime_get_sync(gpu->dev);
  1274. #else
  1275. ret = etnaviv_gpu_clk_enable(gpu);
  1276. #endif
  1277. if (ret < 0)
  1278. return ret;
  1279. gpu->drm = drm;
  1280. gpu->fence_context = fence_context_alloc(1);
  1281. spin_lock_init(&gpu->fence_spinlock);
  1282. INIT_LIST_HEAD(&gpu->active_cmd_list);
  1283. INIT_WORK(&gpu->retire_work, retire_worker);
  1284. INIT_WORK(&gpu->recover_work, recover_worker);
  1285. init_waitqueue_head(&gpu->fence_event);
  1286. setup_deferrable_timer(&gpu->hangcheck_timer, hangcheck_handler,
  1287. (unsigned long)gpu);
  1288. priv->gpu[priv->num_gpus++] = gpu;
  1289. pm_runtime_mark_last_busy(gpu->dev);
  1290. pm_runtime_put_autosuspend(gpu->dev);
  1291. return 0;
  1292. }
  1293. static void etnaviv_gpu_unbind(struct device *dev, struct device *master,
  1294. void *data)
  1295. {
  1296. struct etnaviv_gpu *gpu = dev_get_drvdata(dev);
  1297. DBG("%s", dev_name(gpu->dev));
  1298. hangcheck_disable(gpu);
  1299. #ifdef CONFIG_PM
  1300. pm_runtime_get_sync(gpu->dev);
  1301. pm_runtime_put_sync_suspend(gpu->dev);
  1302. #else
  1303. etnaviv_gpu_hw_suspend(gpu);
  1304. #endif
  1305. if (gpu->buffer) {
  1306. etnaviv_gpu_cmdbuf_free(gpu->buffer);
  1307. gpu->buffer = NULL;
  1308. }
  1309. if (gpu->mmu) {
  1310. etnaviv_iommu_destroy(gpu->mmu);
  1311. gpu->mmu = NULL;
  1312. }
  1313. gpu->drm = NULL;
  1314. }
  1315. static const struct component_ops gpu_ops = {
  1316. .bind = etnaviv_gpu_bind,
  1317. .unbind = etnaviv_gpu_unbind,
  1318. };
  1319. static const struct of_device_id etnaviv_gpu_match[] = {
  1320. {
  1321. .compatible = "vivante,gc"
  1322. },
  1323. { /* sentinel */ }
  1324. };
  1325. static int etnaviv_gpu_platform_probe(struct platform_device *pdev)
  1326. {
  1327. struct device *dev = &pdev->dev;
  1328. struct etnaviv_gpu *gpu;
  1329. int err = 0;
  1330. gpu = devm_kzalloc(dev, sizeof(*gpu), GFP_KERNEL);
  1331. if (!gpu)
  1332. return -ENOMEM;
  1333. gpu->dev = &pdev->dev;
  1334. mutex_init(&gpu->lock);
  1335. /* Map registers: */
  1336. gpu->mmio = etnaviv_ioremap(pdev, NULL, dev_name(gpu->dev));
  1337. if (IS_ERR(gpu->mmio))
  1338. return PTR_ERR(gpu->mmio);
  1339. /* Get Interrupt: */
  1340. gpu->irq = platform_get_irq(pdev, 0);
  1341. if (gpu->irq < 0) {
  1342. err = gpu->irq;
  1343. dev_err(dev, "failed to get irq: %d\n", err);
  1344. goto fail;
  1345. }
  1346. err = devm_request_irq(&pdev->dev, gpu->irq, irq_handler, 0,
  1347. dev_name(gpu->dev), gpu);
  1348. if (err) {
  1349. dev_err(dev, "failed to request IRQ%u: %d\n", gpu->irq, err);
  1350. goto fail;
  1351. }
  1352. /* Get Clocks: */
  1353. gpu->clk_bus = devm_clk_get(&pdev->dev, "bus");
  1354. DBG("clk_bus: %p", gpu->clk_bus);
  1355. if (IS_ERR(gpu->clk_bus))
  1356. gpu->clk_bus = NULL;
  1357. gpu->clk_core = devm_clk_get(&pdev->dev, "core");
  1358. DBG("clk_core: %p", gpu->clk_core);
  1359. if (IS_ERR(gpu->clk_core))
  1360. gpu->clk_core = NULL;
  1361. gpu->clk_shader = devm_clk_get(&pdev->dev, "shader");
  1362. DBG("clk_shader: %p", gpu->clk_shader);
  1363. if (IS_ERR(gpu->clk_shader))
  1364. gpu->clk_shader = NULL;
  1365. /* TODO: figure out max mapped size */
  1366. dev_set_drvdata(dev, gpu);
  1367. /*
  1368. * We treat the device as initially suspended. The runtime PM
  1369. * autosuspend delay is rather arbitary: no measurements have
  1370. * yet been performed to determine an appropriate value.
  1371. */
  1372. pm_runtime_use_autosuspend(gpu->dev);
  1373. pm_runtime_set_autosuspend_delay(gpu->dev, 200);
  1374. pm_runtime_enable(gpu->dev);
  1375. err = component_add(&pdev->dev, &gpu_ops);
  1376. if (err < 0) {
  1377. dev_err(&pdev->dev, "failed to register component: %d\n", err);
  1378. goto fail;
  1379. }
  1380. return 0;
  1381. fail:
  1382. return err;
  1383. }
  1384. static int etnaviv_gpu_platform_remove(struct platform_device *pdev)
  1385. {
  1386. component_del(&pdev->dev, &gpu_ops);
  1387. pm_runtime_disable(&pdev->dev);
  1388. return 0;
  1389. }
  1390. #ifdef CONFIG_PM
  1391. static int etnaviv_gpu_rpm_suspend(struct device *dev)
  1392. {
  1393. struct etnaviv_gpu *gpu = dev_get_drvdata(dev);
  1394. u32 idle, mask;
  1395. /* If we have outstanding fences, we're not idle */
  1396. if (gpu->completed_fence != gpu->active_fence)
  1397. return -EBUSY;
  1398. /* Check whether the hardware (except FE) is idle */
  1399. mask = gpu->idle_mask & ~VIVS_HI_IDLE_STATE_FE;
  1400. idle = gpu_read(gpu, VIVS_HI_IDLE_STATE) & mask;
  1401. if (idle != mask)
  1402. return -EBUSY;
  1403. return etnaviv_gpu_hw_suspend(gpu);
  1404. }
  1405. static int etnaviv_gpu_rpm_resume(struct device *dev)
  1406. {
  1407. struct etnaviv_gpu *gpu = dev_get_drvdata(dev);
  1408. int ret;
  1409. ret = etnaviv_gpu_clk_enable(gpu);
  1410. if (ret)
  1411. return ret;
  1412. /* Re-initialise the basic hardware state */
  1413. if (gpu->drm && gpu->buffer) {
  1414. ret = etnaviv_gpu_hw_resume(gpu);
  1415. if (ret) {
  1416. etnaviv_gpu_clk_disable(gpu);
  1417. return ret;
  1418. }
  1419. }
  1420. return 0;
  1421. }
  1422. #endif
  1423. static const struct dev_pm_ops etnaviv_gpu_pm_ops = {
  1424. SET_RUNTIME_PM_OPS(etnaviv_gpu_rpm_suspend, etnaviv_gpu_rpm_resume,
  1425. NULL)
  1426. };
  1427. struct platform_driver etnaviv_gpu_driver = {
  1428. .driver = {
  1429. .name = "etnaviv-gpu",
  1430. .owner = THIS_MODULE,
  1431. .pm = &etnaviv_gpu_pm_ops,
  1432. .of_match_table = etnaviv_gpu_match,
  1433. },
  1434. .probe = etnaviv_gpu_platform_probe,
  1435. .remove = etnaviv_gpu_platform_remove,
  1436. .id_table = gpu_ids,
  1437. };