etnaviv_gpu.c 44 KB

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