0114-drm-vc4-Update-a-bunch-of-code-to-match-upstream-sub.patch 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893
  1. From dd5e9636e87ee08b38b28626fc862099e5a038cf Mon Sep 17 00:00:00 2001
  2. From: Eric Anholt <eric@anholt.net>
  3. Date: Fri, 4 Dec 2015 11:35:34 -0800
  4. Subject: [PATCH] drm/vc4: Update a bunch of code to match upstream submission.
  5. This gets almost everything matching, except for the MSAA support and
  6. using generic PM domains.
  7. Signed-off-by: Eric Anholt <eric@anholt.net>
  8. ---
  9. drivers/gpu/drm/drm_gem_cma_helper.c | 13 +-
  10. drivers/gpu/drm/vc4/vc4_bo.c | 322 +++++++++++++++++------------
  11. drivers/gpu/drm/vc4/vc4_crtc.c | 7 +-
  12. drivers/gpu/drm/vc4/vc4_drv.c | 6 +-
  13. drivers/gpu/drm/vc4/vc4_drv.h | 20 +-
  14. drivers/gpu/drm/vc4/vc4_gem.c | 24 ++-
  15. drivers/gpu/drm/vc4/vc4_irq.c | 5 +-
  16. drivers/gpu/drm/vc4/vc4_kms.c | 1 +
  17. drivers/gpu/drm/vc4/vc4_packet.h | 210 +++++++++----------
  18. drivers/gpu/drm/vc4/vc4_qpu_defines.h | 308 ++++++++++++++-------------
  19. drivers/gpu/drm/vc4/vc4_render_cl.c | 4 +-
  20. drivers/gpu/drm/vc4/vc4_v3d.c | 10 +-
  21. drivers/gpu/drm/vc4/vc4_validate.c | 130 ++++++------
  22. drivers/gpu/drm/vc4/vc4_validate_shaders.c | 66 +++---
  23. include/drm/drmP.h | 8 +-
  24. 15 files changed, 598 insertions(+), 536 deletions(-)
  25. --- a/drivers/gpu/drm/drm_gem_cma_helper.c
  26. +++ b/drivers/gpu/drm/drm_gem_cma_helper.c
  27. @@ -58,15 +58,14 @@ __drm_gem_cma_create(struct drm_device *
  28. struct drm_gem_cma_object *cma_obj;
  29. struct drm_gem_object *gem_obj;
  30. int ret;
  31. - size_t obj_size = (drm->driver->gem_obj_size ?
  32. - drm->driver->gem_obj_size :
  33. - sizeof(*cma_obj));
  34. - cma_obj = kzalloc(obj_size, GFP_KERNEL);
  35. - if (!cma_obj)
  36. + if (drm->driver->gem_create_object)
  37. + gem_obj = drm->driver->gem_create_object(drm, size);
  38. + else
  39. + gem_obj = kzalloc(sizeof(*cma_obj), GFP_KERNEL);
  40. + if (!gem_obj)
  41. return ERR_PTR(-ENOMEM);
  42. -
  43. - gem_obj = &cma_obj->base;
  44. + cma_obj = container_of(gem_obj, struct drm_gem_cma_object, base);
  45. ret = drm_gem_object_init(drm, gem_obj, size);
  46. if (ret)
  47. --- a/drivers/gpu/drm/vc4/vc4_bo.c
  48. +++ b/drivers/gpu/drm/vc4/vc4_bo.c
  49. @@ -12,6 +12,10 @@
  50. * access to system memory with no MMU in between. To support it, we
  51. * use the GEM CMA helper functions to allocate contiguous ranges of
  52. * physical memory for our BOs.
  53. + *
  54. + * Since the CMA allocator is very slow, we keep a cache of recently
  55. + * freed BOs around so that the kernel's allocation of objects for 3D
  56. + * rendering can return quickly.
  57. */
  58. #include "vc4_drv.h"
  59. @@ -34,6 +38,36 @@ static void vc4_bo_stats_dump(struct vc4
  60. vc4->bo_stats.size_cached / 1024);
  61. }
  62. +#ifdef CONFIG_DEBUG_FS
  63. +int vc4_bo_stats_debugfs(struct seq_file *m, void *unused)
  64. +{
  65. + struct drm_info_node *node = (struct drm_info_node *)m->private;
  66. + struct drm_device *dev = node->minor->dev;
  67. + struct vc4_dev *vc4 = to_vc4_dev(dev);
  68. + struct vc4_bo_stats stats;
  69. +
  70. + /* Take a snapshot of the current stats with the lock held. */
  71. + mutex_lock(&vc4->bo_lock);
  72. + stats = vc4->bo_stats;
  73. + mutex_unlock(&vc4->bo_lock);
  74. +
  75. + seq_printf(m, "num bos allocated: %d\n",
  76. + stats.num_allocated);
  77. + seq_printf(m, "size bos allocated: %dkb\n",
  78. + stats.size_allocated / 1024);
  79. + seq_printf(m, "num bos used: %d\n",
  80. + stats.num_allocated - stats.num_cached);
  81. + seq_printf(m, "size bos used: %dkb\n",
  82. + (stats.size_allocated - stats.size_cached) / 1024);
  83. + seq_printf(m, "num bos cached: %d\n",
  84. + stats.num_cached);
  85. + seq_printf(m, "size bos cached: %dkb\n",
  86. + stats.size_cached / 1024);
  87. +
  88. + return 0;
  89. +}
  90. +#endif
  91. +
  92. static uint32_t bo_page_index(size_t size)
  93. {
  94. return (size / PAGE_SIZE) - 1;
  95. @@ -81,8 +115,8 @@ static struct list_head *vc4_get_cache_l
  96. struct list_head *new_list;
  97. uint32_t i;
  98. - new_list = kmalloc(new_size * sizeof(struct list_head),
  99. - GFP_KERNEL);
  100. + new_list = kmalloc_array(new_size, sizeof(struct list_head),
  101. + GFP_KERNEL);
  102. if (!new_list)
  103. return NULL;
  104. @@ -90,7 +124,9 @@ static struct list_head *vc4_get_cache_l
  105. * head locations.
  106. */
  107. for (i = 0; i < vc4->bo_cache.size_list_size; i++) {
  108. - struct list_head *old_list = &vc4->bo_cache.size_list[i];
  109. + struct list_head *old_list =
  110. + &vc4->bo_cache.size_list[i];
  111. +
  112. if (list_empty(old_list))
  113. INIT_LIST_HEAD(&new_list[i]);
  114. else
  115. @@ -122,11 +158,60 @@ void vc4_bo_cache_purge(struct drm_devic
  116. mutex_unlock(&vc4->bo_lock);
  117. }
  118. -struct vc4_bo *vc4_bo_create(struct drm_device *dev, size_t unaligned_size)
  119. +static struct vc4_bo *vc4_bo_get_from_cache(struct drm_device *dev,
  120. + uint32_t size)
  121. {
  122. struct vc4_dev *vc4 = to_vc4_dev(dev);
  123. - uint32_t size = roundup(unaligned_size, PAGE_SIZE);
  124. uint32_t page_index = bo_page_index(size);
  125. + struct vc4_bo *bo = NULL;
  126. +
  127. + size = roundup(size, PAGE_SIZE);
  128. +
  129. + mutex_lock(&vc4->bo_lock);
  130. + if (page_index >= vc4->bo_cache.size_list_size)
  131. + goto out;
  132. +
  133. + if (list_empty(&vc4->bo_cache.size_list[page_index]))
  134. + goto out;
  135. +
  136. + bo = list_first_entry(&vc4->bo_cache.size_list[page_index],
  137. + struct vc4_bo, size_head);
  138. + vc4_bo_remove_from_cache(bo);
  139. + kref_init(&bo->base.base.refcount);
  140. +
  141. +out:
  142. + mutex_unlock(&vc4->bo_lock);
  143. + return bo;
  144. +}
  145. +
  146. +/**
  147. + * vc4_gem_create_object - Implementation of driver->gem_create_object.
  148. + *
  149. + * This lets the CMA helpers allocate object structs for us, and keep
  150. + * our BO stats correct.
  151. + */
  152. +struct drm_gem_object *vc4_create_object(struct drm_device *dev, size_t size)
  153. +{
  154. + struct vc4_dev *vc4 = to_vc4_dev(dev);
  155. + struct vc4_bo *bo;
  156. +
  157. + bo = kzalloc(sizeof(*bo), GFP_KERNEL);
  158. + if (!bo)
  159. + return ERR_PTR(-ENOMEM);
  160. +
  161. + mutex_lock(&vc4->bo_lock);
  162. + vc4->bo_stats.num_allocated++;
  163. + vc4->bo_stats.size_allocated += size;
  164. + mutex_unlock(&vc4->bo_lock);
  165. +
  166. + return &bo->base.base;
  167. +}
  168. +
  169. +struct vc4_bo *vc4_bo_create(struct drm_device *dev, size_t unaligned_size,
  170. + bool from_cache)
  171. +{
  172. + size_t size = roundup(unaligned_size, PAGE_SIZE);
  173. + struct vc4_dev *vc4 = to_vc4_dev(dev);
  174. struct drm_gem_cma_object *cma_obj;
  175. int pass;
  176. @@ -134,18 +219,12 @@ struct vc4_bo *vc4_bo_create(struct drm_
  177. return NULL;
  178. /* First, try to get a vc4_bo from the kernel BO cache. */
  179. - mutex_lock(&vc4->bo_lock);
  180. - if (page_index < vc4->bo_cache.size_list_size &&
  181. - !list_empty(&vc4->bo_cache.size_list[page_index])) {
  182. - struct vc4_bo *bo =
  183. - list_first_entry(&vc4->bo_cache.size_list[page_index],
  184. - struct vc4_bo, size_head);
  185. - vc4_bo_remove_from_cache(bo);
  186. - mutex_unlock(&vc4->bo_lock);
  187. - kref_init(&bo->base.base.refcount);
  188. - return bo;
  189. + if (from_cache) {
  190. + struct vc4_bo *bo = vc4_bo_get_from_cache(dev, size);
  191. +
  192. + if (bo)
  193. + return bo;
  194. }
  195. - mutex_unlock(&vc4->bo_lock);
  196. /* Otherwise, make a new BO. */
  197. for (pass = 0; ; pass++) {
  198. @@ -179,9 +258,6 @@ struct vc4_bo *vc4_bo_create(struct drm_
  199. }
  200. }
  201. - vc4->bo_stats.num_allocated++;
  202. - vc4->bo_stats.size_allocated += size;
  203. -
  204. return to_vc4_bo(&cma_obj->base);
  205. }
  206. @@ -199,7 +275,7 @@ int vc4_dumb_create(struct drm_file *fil
  207. if (args->size < args->pitch * args->height)
  208. args->size = args->pitch * args->height;
  209. - bo = vc4_bo_create(dev, args->size);
  210. + bo = vc4_bo_create(dev, args->size, false);
  211. if (!bo)
  212. return -ENOMEM;
  213. @@ -209,8 +285,8 @@ int vc4_dumb_create(struct drm_file *fil
  214. return ret;
  215. }
  216. -static void
  217. -vc4_bo_cache_free_old(struct drm_device *dev)
  218. +/* Must be called with bo_lock held. */
  219. +static void vc4_bo_cache_free_old(struct drm_device *dev)
  220. {
  221. struct vc4_dev *vc4 = to_vc4_dev(dev);
  222. unsigned long expire_time = jiffies - msecs_to_jiffies(1000);
  223. @@ -313,15 +389,77 @@ vc4_prime_export(struct drm_device *dev,
  224. return drm_gem_prime_export(dev, obj, flags);
  225. }
  226. -int
  227. -vc4_create_bo_ioctl(struct drm_device *dev, void *data,
  228. - struct drm_file *file_priv)
  229. +int vc4_mmap(struct file *filp, struct vm_area_struct *vma)
  230. +{
  231. + struct drm_gem_object *gem_obj;
  232. + struct vc4_bo *bo;
  233. + int ret;
  234. +
  235. + ret = drm_gem_mmap(filp, vma);
  236. + if (ret)
  237. + return ret;
  238. +
  239. + gem_obj = vma->vm_private_data;
  240. + bo = to_vc4_bo(gem_obj);
  241. +
  242. + if (bo->validated_shader && (vma->vm_flags & VM_WRITE)) {
  243. + DRM_ERROR("mmaping of shader BOs for writing not allowed.\n");
  244. + return -EINVAL;
  245. + }
  246. +
  247. + /*
  248. + * Clear the VM_PFNMAP flag that was set by drm_gem_mmap(), and set the
  249. + * vm_pgoff (used as a fake buffer offset by DRM) to 0 as we want to map
  250. + * the whole buffer.
  251. + */
  252. + vma->vm_flags &= ~VM_PFNMAP;
  253. + vma->vm_pgoff = 0;
  254. +
  255. + ret = dma_mmap_writecombine(bo->base.base.dev->dev, vma,
  256. + bo->base.vaddr, bo->base.paddr,
  257. + vma->vm_end - vma->vm_start);
  258. + if (ret)
  259. + drm_gem_vm_close(vma);
  260. +
  261. + return ret;
  262. +}
  263. +
  264. +int vc4_prime_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma)
  265. +{
  266. + struct vc4_bo *bo = to_vc4_bo(obj);
  267. +
  268. + if (bo->validated_shader && (vma->vm_flags & VM_WRITE)) {
  269. + DRM_ERROR("mmaping of shader BOs for writing not allowed.\n");
  270. + return -EINVAL;
  271. + }
  272. +
  273. + return drm_gem_cma_prime_mmap(obj, vma);
  274. +}
  275. +
  276. +void *vc4_prime_vmap(struct drm_gem_object *obj)
  277. +{
  278. + struct vc4_bo *bo = to_vc4_bo(obj);
  279. +
  280. + if (bo->validated_shader) {
  281. + DRM_ERROR("mmaping of shader BOs not allowed.\n");
  282. + return ERR_PTR(-EINVAL);
  283. + }
  284. +
  285. + return drm_gem_cma_prime_vmap(obj);
  286. +}
  287. +
  288. +int vc4_create_bo_ioctl(struct drm_device *dev, void *data,
  289. + struct drm_file *file_priv)
  290. {
  291. struct drm_vc4_create_bo *args = data;
  292. struct vc4_bo *bo = NULL;
  293. int ret;
  294. - bo = vc4_bo_create(dev, args->size);
  295. + /*
  296. + * We can't allocate from the BO cache, because the BOs don't
  297. + * get zeroed, and that might leak data between users.
  298. + */
  299. + bo = vc4_bo_create(dev, args->size, false);
  300. if (!bo)
  301. return -ENOMEM;
  302. @@ -331,6 +469,25 @@ vc4_create_bo_ioctl(struct drm_device *d
  303. return ret;
  304. }
  305. +int vc4_mmap_bo_ioctl(struct drm_device *dev, void *data,
  306. + struct drm_file *file_priv)
  307. +{
  308. + struct drm_vc4_mmap_bo *args = data;
  309. + struct drm_gem_object *gem_obj;
  310. +
  311. + gem_obj = drm_gem_object_lookup(dev, file_priv, args->handle);
  312. + if (!gem_obj) {
  313. + DRM_ERROR("Failed to look up GEM BO %d\n", args->handle);
  314. + return -EINVAL;
  315. + }
  316. +
  317. + /* The mmap offset was set up at BO allocation time. */
  318. + args->offset = drm_vma_node_offset_addr(&gem_obj->vma_node);
  319. +
  320. + drm_gem_object_unreference_unlocked(gem_obj);
  321. + return 0;
  322. +}
  323. +
  324. int
  325. vc4_create_shader_bo_ioctl(struct drm_device *dev, void *data,
  326. struct drm_file *file_priv)
  327. @@ -355,7 +512,7 @@ vc4_create_shader_bo_ioctl(struct drm_de
  328. return -EINVAL;
  329. }
  330. - bo = vc4_bo_create(dev, args->size);
  331. + bo = vc4_bo_create(dev, args->size, true);
  332. if (!bo)
  333. return -ENOMEM;
  334. @@ -364,6 +521,11 @@ vc4_create_shader_bo_ioctl(struct drm_de
  335. args->size);
  336. if (ret != 0)
  337. goto fail;
  338. + /* Clear the rest of the memory from allocating from the BO
  339. + * cache.
  340. + */
  341. + memset(bo->base.vaddr + args->size, 0,
  342. + bo->base.base.size - args->size);
  343. bo->validated_shader = vc4_validate_shader(&bo->base);
  344. if (!bo->validated_shader) {
  345. @@ -382,85 +544,6 @@ vc4_create_shader_bo_ioctl(struct drm_de
  346. return ret;
  347. }
  348. -int
  349. -vc4_mmap_bo_ioctl(struct drm_device *dev, void *data,
  350. - struct drm_file *file_priv)
  351. -{
  352. - struct drm_vc4_mmap_bo *args = data;
  353. - struct drm_gem_object *gem_obj;
  354. -
  355. - gem_obj = drm_gem_object_lookup(dev, file_priv, args->handle);
  356. - if (!gem_obj) {
  357. - DRM_ERROR("Failed to look up GEM BO %d\n", args->handle);
  358. - return -EINVAL;
  359. - }
  360. -
  361. - /* The mmap offset was set up at BO allocation time. */
  362. - args->offset = drm_vma_node_offset_addr(&gem_obj->vma_node);
  363. -
  364. - drm_gem_object_unreference(gem_obj);
  365. - return 0;
  366. -}
  367. -
  368. -int vc4_mmap(struct file *filp, struct vm_area_struct *vma)
  369. -{
  370. - struct drm_gem_object *gem_obj;
  371. - struct vc4_bo *bo;
  372. - int ret;
  373. -
  374. - ret = drm_gem_mmap(filp, vma);
  375. - if (ret)
  376. - return ret;
  377. -
  378. - gem_obj = vma->vm_private_data;
  379. - bo = to_vc4_bo(gem_obj);
  380. -
  381. - if (bo->validated_shader && (vma->vm_flags & VM_WRITE)) {
  382. - DRM_ERROR("mmaping of shader BOs for writing not allowed.\n");
  383. - return -EINVAL;
  384. - }
  385. -
  386. - /*
  387. - * Clear the VM_PFNMAP flag that was set by drm_gem_mmap(), and set the
  388. - * vm_pgoff (used as a fake buffer offset by DRM) to 0 as we want to map
  389. - * the whole buffer.
  390. - */
  391. - vma->vm_flags &= ~VM_PFNMAP;
  392. - vma->vm_pgoff = 0;
  393. -
  394. - ret = dma_mmap_writecombine(bo->base.base.dev->dev, vma,
  395. - bo->base.vaddr, bo->base.paddr,
  396. - vma->vm_end - vma->vm_start);
  397. - if (ret)
  398. - drm_gem_vm_close(vma);
  399. -
  400. - return ret;
  401. -}
  402. -
  403. -int vc4_prime_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma)
  404. -{
  405. - struct vc4_bo *bo = to_vc4_bo(obj);
  406. -
  407. - if (bo->validated_shader) {
  408. - DRM_ERROR("mmaping of shader BOs not allowed.\n");
  409. - return -EINVAL;
  410. - }
  411. -
  412. - return drm_gem_cma_prime_mmap(obj, vma);
  413. -}
  414. -
  415. -void *vc4_prime_vmap(struct drm_gem_object *obj)
  416. -{
  417. - struct vc4_bo *bo = to_vc4_bo(obj);
  418. -
  419. - if (bo->validated_shader) {
  420. - DRM_ERROR("mmaping of shader BOs not allowed.\n");
  421. - return ERR_PTR(-EINVAL);
  422. - }
  423. -
  424. - return drm_gem_cma_prime_vmap(obj);
  425. -}
  426. -
  427. void vc4_bo_cache_init(struct drm_device *dev)
  428. {
  429. struct vc4_dev *vc4 = to_vc4_dev(dev);
  430. @@ -472,7 +555,7 @@ void vc4_bo_cache_init(struct drm_device
  431. INIT_WORK(&vc4->bo_cache.time_work, vc4_bo_cache_time_work);
  432. setup_timer(&vc4->bo_cache.time_timer,
  433. vc4_bo_cache_time_timer,
  434. - (unsigned long) dev);
  435. + (unsigned long)dev);
  436. }
  437. void vc4_bo_cache_destroy(struct drm_device *dev)
  438. @@ -489,28 +572,3 @@ void vc4_bo_cache_destroy(struct drm_dev
  439. vc4_bo_stats_dump(vc4);
  440. }
  441. }
  442. -
  443. -#ifdef CONFIG_DEBUG_FS
  444. -int vc4_bo_stats_debugfs(struct seq_file *m, void *unused)
  445. -{
  446. - struct drm_info_node *node = (struct drm_info_node *) m->private;
  447. - struct drm_device *dev = node->minor->dev;
  448. - struct vc4_dev *vc4 = to_vc4_dev(dev);
  449. - struct vc4_bo_stats stats;
  450. -
  451. - mutex_lock(&vc4->bo_lock);
  452. - stats = vc4->bo_stats;
  453. - mutex_unlock(&vc4->bo_lock);
  454. -
  455. - seq_printf(m, "num bos allocated: %d\n", stats.num_allocated);
  456. - seq_printf(m, "size bos allocated: %dkb\n", stats.size_allocated / 1024);
  457. - seq_printf(m, "num bos used: %d\n", (stats.num_allocated -
  458. - stats.num_cached));
  459. - seq_printf(m, "size bos used: %dkb\n", (stats.size_allocated -
  460. - stats.size_cached) / 1024);
  461. - seq_printf(m, "num bos cached: %d\n", stats.num_cached);
  462. - seq_printf(m, "size bos cached: %dkb\n", stats.size_cached / 1024);
  463. -
  464. - return 0;
  465. -}
  466. -#endif
  467. --- a/drivers/gpu/drm/vc4/vc4_crtc.c
  468. +++ b/drivers/gpu/drm/vc4/vc4_crtc.c
  469. @@ -501,6 +501,7 @@ vc4_async_page_flip_complete(struct vc4_
  470. vc4_plane_async_set_fb(plane, flip_state->fb);
  471. if (flip_state->event) {
  472. unsigned long flags;
  473. +
  474. spin_lock_irqsave(&dev->event_lock, flags);
  475. drm_crtc_send_vblank_event(crtc, flip_state->event);
  476. spin_unlock_irqrestore(&dev->event_lock, flags);
  477. @@ -562,9 +563,9 @@ static int vc4_async_page_flip(struct dr
  478. }
  479. static int vc4_page_flip(struct drm_crtc *crtc,
  480. - struct drm_framebuffer *fb,
  481. - struct drm_pending_vblank_event *event,
  482. - uint32_t flags)
  483. + struct drm_framebuffer *fb,
  484. + struct drm_pending_vblank_event *event,
  485. + uint32_t flags)
  486. {
  487. if (flags & DRM_MODE_PAGE_FLIP_ASYNC)
  488. return vc4_async_page_flip(crtc, fb, event, flags);
  489. --- a/drivers/gpu/drm/vc4/vc4_drv.c
  490. +++ b/drivers/gpu/drm/vc4/vc4_drv.c
  491. @@ -81,7 +81,8 @@ static const struct drm_ioctl_desc vc4_d
  492. DRM_IOCTL_DEF_DRV(VC4_CREATE_BO, vc4_create_bo_ioctl, 0),
  493. DRM_IOCTL_DEF_DRV(VC4_MMAP_BO, vc4_mmap_bo_ioctl, 0),
  494. DRM_IOCTL_DEF_DRV(VC4_CREATE_SHADER_BO, vc4_create_shader_bo_ioctl, 0),
  495. - DRM_IOCTL_DEF_DRV(VC4_GET_HANG_STATE, vc4_get_hang_state_ioctl, DRM_ROOT_ONLY),
  496. + DRM_IOCTL_DEF_DRV(VC4_GET_HANG_STATE, vc4_get_hang_state_ioctl,
  497. + DRM_ROOT_ONLY),
  498. };
  499. static struct drm_driver vc4_drm_driver = {
  500. @@ -107,6 +108,7 @@ static struct drm_driver vc4_drm_driver
  501. .debugfs_cleanup = vc4_debugfs_cleanup,
  502. #endif
  503. + .gem_create_object = vc4_create_object,
  504. .gem_free_object = vc4_free_object,
  505. .gem_vm_ops = &drm_gem_cma_vm_ops,
  506. @@ -128,8 +130,6 @@ static struct drm_driver vc4_drm_driver
  507. .num_ioctls = ARRAY_SIZE(vc4_drm_ioctls),
  508. .fops = &vc4_drm_fops,
  509. - //.gem_obj_size = sizeof(struct vc4_bo),
  510. -
  511. .name = DRIVER_NAME,
  512. .desc = DRIVER_DESC,
  513. .date = DRIVER_DATE,
  514. --- a/drivers/gpu/drm/vc4/vc4_drv.h
  515. +++ b/drivers/gpu/drm/vc4/vc4_drv.h
  516. @@ -72,6 +72,9 @@ struct vc4_dev {
  517. * job_done_work.
  518. */
  519. struct list_head job_done_list;
  520. + /* Spinlock used to synchronize the job_list and seqno
  521. + * accesses between the IRQ handler and GEM ioctls.
  522. + */
  523. spinlock_t job_lock;
  524. wait_queue_head_t job_wait_queue;
  525. struct work_struct job_done_work;
  526. @@ -318,8 +321,7 @@ struct vc4_texture_sample_info {
  527. * and validate the shader state record's uniforms that define the texture
  528. * samples.
  529. */
  530. -struct vc4_validated_shader_info
  531. -{
  532. +struct vc4_validated_shader_info {
  533. uint32_t uniforms_size;
  534. uint32_t uniforms_src_size;
  535. uint32_t num_texture_samples;
  536. @@ -355,8 +357,10 @@ struct vc4_validated_shader_info
  537. #define wait_for(COND, MS) _wait_for(COND, MS, 1)
  538. /* vc4_bo.c */
  539. +struct drm_gem_object *vc4_create_object(struct drm_device *dev, size_t size);
  540. void vc4_free_object(struct drm_gem_object *gem_obj);
  541. -struct vc4_bo *vc4_bo_create(struct drm_device *dev, size_t size);
  542. +struct vc4_bo *vc4_bo_create(struct drm_device *dev, size_t size,
  543. + bool from_cache);
  544. int vc4_dumb_create(struct drm_file *file_priv,
  545. struct drm_device *dev,
  546. struct drm_mode_create_dumb *args);
  547. @@ -432,7 +436,8 @@ struct drm_plane *vc4_plane_init(struct
  548. enum drm_plane_type type);
  549. u32 vc4_plane_write_dlist(struct drm_plane *plane, u32 __iomem *dlist);
  550. u32 vc4_plane_dlist_size(struct drm_plane_state *state);
  551. -void vc4_plane_async_set_fb(struct drm_plane *plane, struct drm_framebuffer *fb);
  552. +void vc4_plane_async_set_fb(struct drm_plane *plane,
  553. + struct drm_framebuffer *fb);
  554. /* vc4_v3d.c */
  555. extern struct platform_driver vc4_v3d_driver;
  556. @@ -450,9 +455,6 @@ vc4_validate_bin_cl(struct drm_device *d
  557. int
  558. vc4_validate_shader_recs(struct drm_device *dev, struct vc4_exec_info *exec);
  559. -struct vc4_validated_shader_info *
  560. -vc4_validate_shader(struct drm_gem_cma_object *shader_obj);
  561. -
  562. bool vc4_use_bo(struct vc4_exec_info *exec,
  563. uint32_t hindex,
  564. enum vc4_bo_mode mode,
  565. @@ -464,3 +466,7 @@ bool vc4_check_tex_size(struct vc4_exec_
  566. struct drm_gem_cma_object *fbo,
  567. uint32_t offset, uint8_t tiling_format,
  568. uint32_t width, uint32_t height, uint8_t cpp);
  569. +
  570. +/* vc4_validate_shader.c */
  571. +struct vc4_validated_shader_info *
  572. +vc4_validate_shader(struct drm_gem_cma_object *shader_obj);
  573. --- a/drivers/gpu/drm/vc4/vc4_gem.c
  574. +++ b/drivers/gpu/drm/vc4/vc4_gem.c
  575. @@ -53,9 +53,8 @@ vc4_free_hang_state(struct drm_device *d
  576. unsigned int i;
  577. mutex_lock(&dev->struct_mutex);
  578. - for (i = 0; i < state->user_state.bo_count; i++) {
  579. + for (i = 0; i < state->user_state.bo_count; i++)
  580. drm_gem_object_unreference(state->bo[i]);
  581. - }
  582. mutex_unlock(&dev->struct_mutex);
  583. kfree(state);
  584. @@ -65,10 +64,10 @@ int
  585. vc4_get_hang_state_ioctl(struct drm_device *dev, void *data,
  586. struct drm_file *file_priv)
  587. {
  588. - struct drm_vc4_get_hang_state *get_state = data;
  589. + struct drm_vc4_get_hang_state *get_state = data;
  590. struct drm_vc4_get_hang_state_bo *bo_state;
  591. struct vc4_hang_state *kernel_state;
  592. - struct drm_vc4_get_hang_state *state;
  593. + struct drm_vc4_get_hang_state *state;
  594. struct vc4_dev *vc4 = to_vc4_dev(dev);
  595. unsigned long irqflags;
  596. u32 i;
  597. @@ -107,6 +106,7 @@ vc4_get_hang_state_ioctl(struct drm_devi
  598. for (i = 0; i < state->bo_count; i++) {
  599. struct vc4_bo *vc4_bo = to_vc4_bo(kernel_state->bo[i]);
  600. u32 handle;
  601. +
  602. ret = drm_gem_handle_create(file_priv, kernel_state->bo[i],
  603. &handle);
  604. @@ -124,7 +124,7 @@ vc4_get_hang_state_ioctl(struct drm_devi
  605. state->bo_count * sizeof(*bo_state));
  606. kfree(bo_state);
  607. - err_free:
  608. +err_free:
  609. vc4_free_hang_state(dev, kernel_state);
  610. @@ -578,7 +578,7 @@ vc4_get_bcl(struct drm_device *dev, stru
  611. goto fail;
  612. }
  613. - bo = vc4_bo_create(dev, exec_size);
  614. + bo = vc4_bo_create(dev, exec_size, true);
  615. if (!bo) {
  616. DRM_ERROR("Couldn't allocate BO for binning\n");
  617. ret = PTR_ERR(exec->exec_bo);
  618. @@ -668,6 +668,7 @@ vc4_job_handle_completed(struct vc4_dev
  619. static void vc4_seqno_cb_work(struct work_struct *work)
  620. {
  621. struct vc4_seqno_cb *cb = container_of(work, struct vc4_seqno_cb, work);
  622. +
  623. cb->func(cb);
  624. }
  625. @@ -717,6 +718,7 @@ vc4_wait_for_seqno_ioctl_helper(struct d
  626. if ((ret == -EINTR || ret == -ERESTARTSYS) && *timeout_ns != ~0ull) {
  627. uint64_t delta = jiffies_to_nsecs(jiffies - start);
  628. +
  629. if (*timeout_ns >= delta)
  630. *timeout_ns -= delta;
  631. }
  632. @@ -750,9 +752,10 @@ vc4_wait_bo_ioctl(struct drm_device *dev
  633. }
  634. bo = to_vc4_bo(gem_obj);
  635. - ret = vc4_wait_for_seqno_ioctl_helper(dev, bo->seqno, &args->timeout_ns);
  636. + ret = vc4_wait_for_seqno_ioctl_helper(dev, bo->seqno,
  637. + &args->timeout_ns);
  638. - drm_gem_object_unreference(gem_obj);
  639. + drm_gem_object_unreference_unlocked(gem_obj);
  640. return ret;
  641. }
  642. @@ -793,7 +796,8 @@ vc4_submit_cl_ioctl(struct drm_device *d
  643. if (ret)
  644. goto fail;
  645. } else {
  646. - exec->ct0ca = exec->ct0ea = 0;
  647. + exec->ct0ca = 0;
  648. + exec->ct0ea = 0;
  649. }
  650. ret = vc4_get_rcl(dev, exec);
  651. @@ -831,7 +835,7 @@ vc4_gem_init(struct drm_device *dev)
  652. INIT_WORK(&vc4->hangcheck.reset_work, vc4_reset_work);
  653. setup_timer(&vc4->hangcheck.timer,
  654. vc4_hangcheck_elapsed,
  655. - (unsigned long) dev);
  656. + (unsigned long)dev);
  657. INIT_WORK(&vc4->job_done_work, vc4_job_done_work);
  658. }
  659. --- a/drivers/gpu/drm/vc4/vc4_irq.c
  660. +++ b/drivers/gpu/drm/vc4/vc4_irq.c
  661. @@ -56,7 +56,7 @@ vc4_overflow_mem_work(struct work_struct
  662. struct drm_device *dev = vc4->dev;
  663. struct vc4_bo *bo;
  664. - bo = vc4_bo_create(dev, 256 * 1024);
  665. + bo = vc4_bo_create(dev, 256 * 1024, true);
  666. if (!bo) {
  667. DRM_ERROR("Couldn't allocate binner overflow mem\n");
  668. return;
  669. @@ -87,9 +87,8 @@ vc4_overflow_mem_work(struct work_struct
  670. spin_unlock_irqrestore(&vc4->job_lock, irqflags);
  671. }
  672. - if (vc4->overflow_mem) {
  673. + if (vc4->overflow_mem)
  674. drm_gem_object_unreference_unlocked(&vc4->overflow_mem->base.base);
  675. - }
  676. vc4->overflow_mem = bo;
  677. V3D_WRITE(V3D_BPOA, bo->base.paddr);
  678. --- a/drivers/gpu/drm/vc4/vc4_kms.c
  679. +++ b/drivers/gpu/drm/vc4/vc4_kms.c
  680. @@ -132,6 +132,7 @@ static int vc4_atomic_commit(struct drm_
  681. struct drm_gem_cma_object *cma_bo =
  682. drm_fb_cma_get_gem_obj(new_state->fb, 0);
  683. struct vc4_bo *bo = to_vc4_bo(&cma_bo->base);
  684. +
  685. wait_seqno = max(bo->seqno, wait_seqno);
  686. }
  687. }
  688. --- a/drivers/gpu/drm/vc4/vc4_packet.h
  689. +++ b/drivers/gpu/drm/vc4/vc4_packet.h
  690. @@ -27,60 +27,60 @@
  691. #include "vc4_regs.h" /* for VC4_MASK, VC4_GET_FIELD, VC4_SET_FIELD */
  692. enum vc4_packet {
  693. - VC4_PACKET_HALT = 0,
  694. - VC4_PACKET_NOP = 1,
  695. + VC4_PACKET_HALT = 0,
  696. + VC4_PACKET_NOP = 1,
  697. - VC4_PACKET_FLUSH = 4,
  698. - VC4_PACKET_FLUSH_ALL = 5,
  699. - VC4_PACKET_START_TILE_BINNING = 6,
  700. - VC4_PACKET_INCREMENT_SEMAPHORE = 7,
  701. - VC4_PACKET_WAIT_ON_SEMAPHORE = 8,
  702. -
  703. - VC4_PACKET_BRANCH = 16,
  704. - VC4_PACKET_BRANCH_TO_SUB_LIST = 17,
  705. -
  706. - VC4_PACKET_STORE_MS_TILE_BUFFER = 24,
  707. - VC4_PACKET_STORE_MS_TILE_BUFFER_AND_EOF = 25,
  708. - VC4_PACKET_STORE_FULL_RES_TILE_BUFFER = 26,
  709. - VC4_PACKET_LOAD_FULL_RES_TILE_BUFFER = 27,
  710. - VC4_PACKET_STORE_TILE_BUFFER_GENERAL = 28,
  711. - VC4_PACKET_LOAD_TILE_BUFFER_GENERAL = 29,
  712. -
  713. - VC4_PACKET_GL_INDEXED_PRIMITIVE = 32,
  714. - VC4_PACKET_GL_ARRAY_PRIMITIVE = 33,
  715. -
  716. - VC4_PACKET_COMPRESSED_PRIMITIVE = 48,
  717. - VC4_PACKET_CLIPPED_COMPRESSED_PRIMITIVE = 49,
  718. -
  719. - VC4_PACKET_PRIMITIVE_LIST_FORMAT = 56,
  720. -
  721. - VC4_PACKET_GL_SHADER_STATE = 64,
  722. - VC4_PACKET_NV_SHADER_STATE = 65,
  723. - VC4_PACKET_VG_SHADER_STATE = 66,
  724. -
  725. - VC4_PACKET_CONFIGURATION_BITS = 96,
  726. - VC4_PACKET_FLAT_SHADE_FLAGS = 97,
  727. - VC4_PACKET_POINT_SIZE = 98,
  728. - VC4_PACKET_LINE_WIDTH = 99,
  729. - VC4_PACKET_RHT_X_BOUNDARY = 100,
  730. - VC4_PACKET_DEPTH_OFFSET = 101,
  731. - VC4_PACKET_CLIP_WINDOW = 102,
  732. - VC4_PACKET_VIEWPORT_OFFSET = 103,
  733. - VC4_PACKET_Z_CLIPPING = 104,
  734. - VC4_PACKET_CLIPPER_XY_SCALING = 105,
  735. - VC4_PACKET_CLIPPER_Z_SCALING = 106,
  736. -
  737. - VC4_PACKET_TILE_BINNING_MODE_CONFIG = 112,
  738. - VC4_PACKET_TILE_RENDERING_MODE_CONFIG = 113,
  739. - VC4_PACKET_CLEAR_COLORS = 114,
  740. - VC4_PACKET_TILE_COORDINATES = 115,
  741. -
  742. - /* Not an actual hardware packet -- this is what we use to put
  743. - * references to GEM bos in the command stream, since we need the u32
  744. - * int the actual address packet in order to store the offset from the
  745. - * start of the BO.
  746. - */
  747. - VC4_PACKET_GEM_HANDLES = 254,
  748. + VC4_PACKET_FLUSH = 4,
  749. + VC4_PACKET_FLUSH_ALL = 5,
  750. + VC4_PACKET_START_TILE_BINNING = 6,
  751. + VC4_PACKET_INCREMENT_SEMAPHORE = 7,
  752. + VC4_PACKET_WAIT_ON_SEMAPHORE = 8,
  753. +
  754. + VC4_PACKET_BRANCH = 16,
  755. + VC4_PACKET_BRANCH_TO_SUB_LIST = 17,
  756. +
  757. + VC4_PACKET_STORE_MS_TILE_BUFFER = 24,
  758. + VC4_PACKET_STORE_MS_TILE_BUFFER_AND_EOF = 25,
  759. + VC4_PACKET_STORE_FULL_RES_TILE_BUFFER = 26,
  760. + VC4_PACKET_LOAD_FULL_RES_TILE_BUFFER = 27,
  761. + VC4_PACKET_STORE_TILE_BUFFER_GENERAL = 28,
  762. + VC4_PACKET_LOAD_TILE_BUFFER_GENERAL = 29,
  763. +
  764. + VC4_PACKET_GL_INDEXED_PRIMITIVE = 32,
  765. + VC4_PACKET_GL_ARRAY_PRIMITIVE = 33,
  766. +
  767. + VC4_PACKET_COMPRESSED_PRIMITIVE = 48,
  768. + VC4_PACKET_CLIPPED_COMPRESSED_PRIMITIVE = 49,
  769. +
  770. + VC4_PACKET_PRIMITIVE_LIST_FORMAT = 56,
  771. +
  772. + VC4_PACKET_GL_SHADER_STATE = 64,
  773. + VC4_PACKET_NV_SHADER_STATE = 65,
  774. + VC4_PACKET_VG_SHADER_STATE = 66,
  775. +
  776. + VC4_PACKET_CONFIGURATION_BITS = 96,
  777. + VC4_PACKET_FLAT_SHADE_FLAGS = 97,
  778. + VC4_PACKET_POINT_SIZE = 98,
  779. + VC4_PACKET_LINE_WIDTH = 99,
  780. + VC4_PACKET_RHT_X_BOUNDARY = 100,
  781. + VC4_PACKET_DEPTH_OFFSET = 101,
  782. + VC4_PACKET_CLIP_WINDOW = 102,
  783. + VC4_PACKET_VIEWPORT_OFFSET = 103,
  784. + VC4_PACKET_Z_CLIPPING = 104,
  785. + VC4_PACKET_CLIPPER_XY_SCALING = 105,
  786. + VC4_PACKET_CLIPPER_Z_SCALING = 106,
  787. +
  788. + VC4_PACKET_TILE_BINNING_MODE_CONFIG = 112,
  789. + VC4_PACKET_TILE_RENDERING_MODE_CONFIG = 113,
  790. + VC4_PACKET_CLEAR_COLORS = 114,
  791. + VC4_PACKET_TILE_COORDINATES = 115,
  792. +
  793. + /* Not an actual hardware packet -- this is what we use to put
  794. + * references to GEM bos in the command stream, since we need the u32
  795. + * int the actual address packet in order to store the offset from the
  796. + * start of the BO.
  797. + */
  798. + VC4_PACKET_GEM_HANDLES = 254,
  799. } __attribute__ ((__packed__));
  800. #define VC4_PACKET_HALT_SIZE 1
  801. @@ -148,10 +148,10 @@ enum vc4_packet {
  802. * VC4_PACKET_LOAD_TILE_BUFFER_GENERAL (low bits of the address)
  803. */
  804. -#define VC4_LOADSTORE_TILE_BUFFER_EOF (1 << 3)
  805. -#define VC4_LOADSTORE_TILE_BUFFER_DISABLE_FULL_VG_MASK (1 << 2)
  806. -#define VC4_LOADSTORE_TILE_BUFFER_DISABLE_FULL_ZS (1 << 1)
  807. -#define VC4_LOADSTORE_TILE_BUFFER_DISABLE_FULL_COLOR (1 << 0)
  808. +#define VC4_LOADSTORE_TILE_BUFFER_EOF BIT(3)
  809. +#define VC4_LOADSTORE_TILE_BUFFER_DISABLE_FULL_VG_MASK BIT(2)
  810. +#define VC4_LOADSTORE_TILE_BUFFER_DISABLE_FULL_ZS BIT(1)
  811. +#define VC4_LOADSTORE_TILE_BUFFER_DISABLE_FULL_COLOR BIT(0)
  812. /** @} */
  813. @@ -160,10 +160,10 @@ enum vc4_packet {
  814. * byte 0-1 of VC4_PACKET_STORE_TILE_BUFFER_GENERAL and
  815. * VC4_PACKET_LOAD_TILE_BUFFER_GENERAL
  816. */
  817. -#define VC4_STORE_TILE_BUFFER_DISABLE_VG_MASK_CLEAR (1 << 15)
  818. -#define VC4_STORE_TILE_BUFFER_DISABLE_ZS_CLEAR (1 << 14)
  819. -#define VC4_STORE_TILE_BUFFER_DISABLE_COLOR_CLEAR (1 << 13)
  820. -#define VC4_STORE_TILE_BUFFER_DISABLE_SWAP (1 << 12)
  821. +#define VC4_STORE_TILE_BUFFER_DISABLE_VG_MASK_CLEAR BIT(15)
  822. +#define VC4_STORE_TILE_BUFFER_DISABLE_ZS_CLEAR BIT(14)
  823. +#define VC4_STORE_TILE_BUFFER_DISABLE_COLOR_CLEAR BIT(13)
  824. +#define VC4_STORE_TILE_BUFFER_DISABLE_SWAP BIT(12)
  825. #define VC4_LOADSTORE_TILE_BUFFER_FORMAT_MASK VC4_MASK(9, 8)
  826. #define VC4_LOADSTORE_TILE_BUFFER_FORMAT_SHIFT 8
  827. @@ -201,28 +201,28 @@ enum vc4_packet {
  828. #define VC4_INDEX_BUFFER_U16 (1 << 4)
  829. /* This flag is only present in NV shader state. */
  830. -#define VC4_SHADER_FLAG_SHADED_CLIP_COORDS (1 << 3)
  831. -#define VC4_SHADER_FLAG_ENABLE_CLIPPING (1 << 2)
  832. -#define VC4_SHADER_FLAG_VS_POINT_SIZE (1 << 1)
  833. -#define VC4_SHADER_FLAG_FS_SINGLE_THREAD (1 << 0)
  834. +#define VC4_SHADER_FLAG_SHADED_CLIP_COORDS BIT(3)
  835. +#define VC4_SHADER_FLAG_ENABLE_CLIPPING BIT(2)
  836. +#define VC4_SHADER_FLAG_VS_POINT_SIZE BIT(1)
  837. +#define VC4_SHADER_FLAG_FS_SINGLE_THREAD BIT(0)
  838. /** @{ byte 2 of config bits. */
  839. -#define VC4_CONFIG_BITS_EARLY_Z_UPDATE (1 << 1)
  840. -#define VC4_CONFIG_BITS_EARLY_Z (1 << 0)
  841. +#define VC4_CONFIG_BITS_EARLY_Z_UPDATE BIT(1)
  842. +#define VC4_CONFIG_BITS_EARLY_Z BIT(0)
  843. /** @} */
  844. /** @{ byte 1 of config bits. */
  845. -#define VC4_CONFIG_BITS_Z_UPDATE (1 << 7)
  846. +#define VC4_CONFIG_BITS_Z_UPDATE BIT(7)
  847. /** same values in this 3-bit field as PIPE_FUNC_* */
  848. #define VC4_CONFIG_BITS_DEPTH_FUNC_SHIFT 4
  849. -#define VC4_CONFIG_BITS_COVERAGE_READ_LEAVE (1 << 3)
  850. +#define VC4_CONFIG_BITS_COVERAGE_READ_LEAVE BIT(3)
  851. #define VC4_CONFIG_BITS_COVERAGE_UPDATE_NONZERO (0 << 1)
  852. #define VC4_CONFIG_BITS_COVERAGE_UPDATE_ODD (1 << 1)
  853. #define VC4_CONFIG_BITS_COVERAGE_UPDATE_OR (2 << 1)
  854. #define VC4_CONFIG_BITS_COVERAGE_UPDATE_ZERO (3 << 1)
  855. -#define VC4_CONFIG_BITS_COVERAGE_PIPE_SELECT (1 << 0)
  856. +#define VC4_CONFIG_BITS_COVERAGE_PIPE_SELECT BIT(0)
  857. /** @} */
  858. /** @{ byte 0 of config bits. */
  859. @@ -230,15 +230,15 @@ enum vc4_packet {
  860. #define VC4_CONFIG_BITS_RASTERIZER_OVERSAMPLE_4X (1 << 6)
  861. #define VC4_CONFIG_BITS_RASTERIZER_OVERSAMPLE_16X (2 << 6)
  862. -#define VC4_CONFIG_BITS_AA_POINTS_AND_LINES (1 << 4)
  863. -#define VC4_CONFIG_BITS_ENABLE_DEPTH_OFFSET (1 << 3)
  864. -#define VC4_CONFIG_BITS_CW_PRIMITIVES (1 << 2)
  865. -#define VC4_CONFIG_BITS_ENABLE_PRIM_BACK (1 << 1)
  866. -#define VC4_CONFIG_BITS_ENABLE_PRIM_FRONT (1 << 0)
  867. +#define VC4_CONFIG_BITS_AA_POINTS_AND_LINES BIT(4)
  868. +#define VC4_CONFIG_BITS_ENABLE_DEPTH_OFFSET BIT(3)
  869. +#define VC4_CONFIG_BITS_CW_PRIMITIVES BIT(2)
  870. +#define VC4_CONFIG_BITS_ENABLE_PRIM_BACK BIT(1)
  871. +#define VC4_CONFIG_BITS_ENABLE_PRIM_FRONT BIT(0)
  872. /** @} */
  873. /** @{ bits in the last u8 of VC4_PACKET_TILE_BINNING_MODE_CONFIG */
  874. -#define VC4_BIN_CONFIG_DB_NON_MS (1 << 7)
  875. +#define VC4_BIN_CONFIG_DB_NON_MS BIT(7)
  876. #define VC4_BIN_CONFIG_ALLOC_BLOCK_SIZE_MASK VC4_MASK(6, 5)
  877. #define VC4_BIN_CONFIG_ALLOC_BLOCK_SIZE_SHIFT 5
  878. @@ -254,17 +254,17 @@ enum vc4_packet {
  879. #define VC4_BIN_CONFIG_ALLOC_INIT_BLOCK_SIZE_128 2
  880. #define VC4_BIN_CONFIG_ALLOC_INIT_BLOCK_SIZE_256 3
  881. -#define VC4_BIN_CONFIG_AUTO_INIT_TSDA (1 << 2)
  882. -#define VC4_BIN_CONFIG_TILE_BUFFER_64BIT (1 << 1)
  883. -#define VC4_BIN_CONFIG_MS_MODE_4X (1 << 0)
  884. +#define VC4_BIN_CONFIG_AUTO_INIT_TSDA BIT(2)
  885. +#define VC4_BIN_CONFIG_TILE_BUFFER_64BIT BIT(1)
  886. +#define VC4_BIN_CONFIG_MS_MODE_4X BIT(0)
  887. /** @} */
  888. /** @{ bits in the last u16 of VC4_PACKET_TILE_RENDERING_MODE_CONFIG */
  889. -#define VC4_RENDER_CONFIG_DB_NON_MS (1 << 12)
  890. -#define VC4_RENDER_CONFIG_EARLY_Z_COVERAGE_DISABLE (1 << 11)
  891. -#define VC4_RENDER_CONFIG_EARLY_Z_DIRECTION_G (1 << 10)
  892. -#define VC4_RENDER_CONFIG_COVERAGE_MODE (1 << 9)
  893. -#define VC4_RENDER_CONFIG_ENABLE_VG_MASK (1 << 8)
  894. +#define VC4_RENDER_CONFIG_DB_NON_MS BIT(12)
  895. +#define VC4_RENDER_CONFIG_EARLY_Z_COVERAGE_DISABLE BIT(11)
  896. +#define VC4_RENDER_CONFIG_EARLY_Z_DIRECTION_G BIT(10)
  897. +#define VC4_RENDER_CONFIG_COVERAGE_MODE BIT(9)
  898. +#define VC4_RENDER_CONFIG_ENABLE_VG_MASK BIT(8)
  899. /** The values of the field are VC4_TILING_FORMAT_* */
  900. #define VC4_RENDER_CONFIG_MEMORY_FORMAT_MASK VC4_MASK(7, 6)
  901. @@ -280,8 +280,8 @@ enum vc4_packet {
  902. #define VC4_RENDER_CONFIG_FORMAT_RGBA8888 1
  903. #define VC4_RENDER_CONFIG_FORMAT_BGR565 2
  904. -#define VC4_RENDER_CONFIG_TILE_BUFFER_64BIT (1 << 1)
  905. -#define VC4_RENDER_CONFIG_MS_MODE_4X (1 << 0)
  906. +#define VC4_RENDER_CONFIG_TILE_BUFFER_64BIT BIT(1)
  907. +#define VC4_RENDER_CONFIG_MS_MODE_4X BIT(0)
  908. #define VC4_PRIMITIVE_LIST_FORMAT_16_INDEX (1 << 4)
  909. #define VC4_PRIMITIVE_LIST_FORMAT_32_XY (3 << 4)
  910. @@ -291,24 +291,24 @@ enum vc4_packet {
  911. #define VC4_PRIMITIVE_LIST_FORMAT_TYPE_RHT (3 << 0)
  912. enum vc4_texture_data_type {
  913. - VC4_TEXTURE_TYPE_RGBA8888 = 0,
  914. - VC4_TEXTURE_TYPE_RGBX8888 = 1,
  915. - VC4_TEXTURE_TYPE_RGBA4444 = 2,
  916. - VC4_TEXTURE_TYPE_RGBA5551 = 3,
  917. - VC4_TEXTURE_TYPE_RGB565 = 4,
  918. - VC4_TEXTURE_TYPE_LUMINANCE = 5,
  919. - VC4_TEXTURE_TYPE_ALPHA = 6,
  920. - VC4_TEXTURE_TYPE_LUMALPHA = 7,
  921. - VC4_TEXTURE_TYPE_ETC1 = 8,
  922. - VC4_TEXTURE_TYPE_S16F = 9,
  923. - VC4_TEXTURE_TYPE_S8 = 10,
  924. - VC4_TEXTURE_TYPE_S16 = 11,
  925. - VC4_TEXTURE_TYPE_BW1 = 12,
  926. - VC4_TEXTURE_TYPE_A4 = 13,
  927. - VC4_TEXTURE_TYPE_A1 = 14,
  928. - VC4_TEXTURE_TYPE_RGBA64 = 15,
  929. - VC4_TEXTURE_TYPE_RGBA32R = 16,
  930. - VC4_TEXTURE_TYPE_YUV422R = 17,
  931. + VC4_TEXTURE_TYPE_RGBA8888 = 0,
  932. + VC4_TEXTURE_TYPE_RGBX8888 = 1,
  933. + VC4_TEXTURE_TYPE_RGBA4444 = 2,
  934. + VC4_TEXTURE_TYPE_RGBA5551 = 3,
  935. + VC4_TEXTURE_TYPE_RGB565 = 4,
  936. + VC4_TEXTURE_TYPE_LUMINANCE = 5,
  937. + VC4_TEXTURE_TYPE_ALPHA = 6,
  938. + VC4_TEXTURE_TYPE_LUMALPHA = 7,
  939. + VC4_TEXTURE_TYPE_ETC1 = 8,
  940. + VC4_TEXTURE_TYPE_S16F = 9,
  941. + VC4_TEXTURE_TYPE_S8 = 10,
  942. + VC4_TEXTURE_TYPE_S16 = 11,
  943. + VC4_TEXTURE_TYPE_BW1 = 12,
  944. + VC4_TEXTURE_TYPE_A4 = 13,
  945. + VC4_TEXTURE_TYPE_A1 = 14,
  946. + VC4_TEXTURE_TYPE_RGBA64 = 15,
  947. + VC4_TEXTURE_TYPE_RGBA32R = 16,
  948. + VC4_TEXTURE_TYPE_YUV422R = 17,
  949. };
  950. #define VC4_TEX_P0_OFFSET_MASK VC4_MASK(31, 12)
  951. --- a/drivers/gpu/drm/vc4/vc4_qpu_defines.h
  952. +++ b/drivers/gpu/drm/vc4/vc4_qpu_defines.h
  953. @@ -25,194 +25,190 @@
  954. #define VC4_QPU_DEFINES_H
  955. enum qpu_op_add {
  956. - QPU_A_NOP,
  957. - QPU_A_FADD,
  958. - QPU_A_FSUB,
  959. - QPU_A_FMIN,
  960. - QPU_A_FMAX,
  961. - QPU_A_FMINABS,
  962. - QPU_A_FMAXABS,
  963. - QPU_A_FTOI,
  964. - QPU_A_ITOF,
  965. - QPU_A_ADD = 12,
  966. - QPU_A_SUB,
  967. - QPU_A_SHR,
  968. - QPU_A_ASR,
  969. - QPU_A_ROR,
  970. - QPU_A_SHL,
  971. - QPU_A_MIN,
  972. - QPU_A_MAX,
  973. - QPU_A_AND,
  974. - QPU_A_OR,
  975. - QPU_A_XOR,
  976. - QPU_A_NOT,
  977. - QPU_A_CLZ,
  978. - QPU_A_V8ADDS = 30,
  979. - QPU_A_V8SUBS = 31,
  980. + QPU_A_NOP,
  981. + QPU_A_FADD,
  982. + QPU_A_FSUB,
  983. + QPU_A_FMIN,
  984. + QPU_A_FMAX,
  985. + QPU_A_FMINABS,
  986. + QPU_A_FMAXABS,
  987. + QPU_A_FTOI,
  988. + QPU_A_ITOF,
  989. + QPU_A_ADD = 12,
  990. + QPU_A_SUB,
  991. + QPU_A_SHR,
  992. + QPU_A_ASR,
  993. + QPU_A_ROR,
  994. + QPU_A_SHL,
  995. + QPU_A_MIN,
  996. + QPU_A_MAX,
  997. + QPU_A_AND,
  998. + QPU_A_OR,
  999. + QPU_A_XOR,
  1000. + QPU_A_NOT,
  1001. + QPU_A_CLZ,
  1002. + QPU_A_V8ADDS = 30,
  1003. + QPU_A_V8SUBS = 31,
  1004. };
  1005. enum qpu_op_mul {
  1006. - QPU_M_NOP,
  1007. - QPU_M_FMUL,
  1008. - QPU_M_MUL24,
  1009. - QPU_M_V8MULD,
  1010. - QPU_M_V8MIN,
  1011. - QPU_M_V8MAX,
  1012. - QPU_M_V8ADDS,
  1013. - QPU_M_V8SUBS,
  1014. + QPU_M_NOP,
  1015. + QPU_M_FMUL,
  1016. + QPU_M_MUL24,
  1017. + QPU_M_V8MULD,
  1018. + QPU_M_V8MIN,
  1019. + QPU_M_V8MAX,
  1020. + QPU_M_V8ADDS,
  1021. + QPU_M_V8SUBS,
  1022. };
  1023. enum qpu_raddr {
  1024. - QPU_R_FRAG_PAYLOAD_ZW = 15, /* W for A file, Z for B file */
  1025. - /* 0-31 are the plain regfile a or b fields */
  1026. - QPU_R_UNIF = 32,
  1027. - QPU_R_VARY = 35,
  1028. - QPU_R_ELEM_QPU = 38,
  1029. - QPU_R_NOP,
  1030. - QPU_R_XY_PIXEL_COORD = 41,
  1031. - QPU_R_MS_REV_FLAGS = 41,
  1032. - QPU_R_VPM = 48,
  1033. - QPU_R_VPM_LD_BUSY,
  1034. - QPU_R_VPM_LD_WAIT,
  1035. - QPU_R_MUTEX_ACQUIRE,
  1036. + QPU_R_FRAG_PAYLOAD_ZW = 15, /* W for A file, Z for B file */
  1037. + /* 0-31 are the plain regfile a or b fields */
  1038. + QPU_R_UNIF = 32,
  1039. + QPU_R_VARY = 35,
  1040. + QPU_R_ELEM_QPU = 38,
  1041. + QPU_R_NOP,
  1042. + QPU_R_XY_PIXEL_COORD = 41,
  1043. + QPU_R_MS_REV_FLAGS = 41,
  1044. + QPU_R_VPM = 48,
  1045. + QPU_R_VPM_LD_BUSY,
  1046. + QPU_R_VPM_LD_WAIT,
  1047. + QPU_R_MUTEX_ACQUIRE,
  1048. };
  1049. enum qpu_waddr {
  1050. - /* 0-31 are the plain regfile a or b fields */
  1051. - QPU_W_ACC0 = 32, /* aka r0 */
  1052. - QPU_W_ACC1,
  1053. - QPU_W_ACC2,
  1054. - QPU_W_ACC3,
  1055. - QPU_W_TMU_NOSWAP,
  1056. - QPU_W_ACC5,
  1057. - QPU_W_HOST_INT,
  1058. - QPU_W_NOP,
  1059. - QPU_W_UNIFORMS_ADDRESS,
  1060. - QPU_W_QUAD_XY, /* X for regfile a, Y for regfile b */
  1061. - QPU_W_MS_FLAGS = 42,
  1062. - QPU_W_REV_FLAG = 42,
  1063. - QPU_W_TLB_STENCIL_SETUP = 43,
  1064. - QPU_W_TLB_Z,
  1065. - QPU_W_TLB_COLOR_MS,
  1066. - QPU_W_TLB_COLOR_ALL,
  1067. - QPU_W_TLB_ALPHA_MASK,
  1068. - QPU_W_VPM,
  1069. - QPU_W_VPMVCD_SETUP, /* LD for regfile a, ST for regfile b */
  1070. - QPU_W_VPM_ADDR, /* LD for regfile a, ST for regfile b */
  1071. - QPU_W_MUTEX_RELEASE,
  1072. - QPU_W_SFU_RECIP,
  1073. - QPU_W_SFU_RECIPSQRT,
  1074. - QPU_W_SFU_EXP,
  1075. - QPU_W_SFU_LOG,
  1076. - QPU_W_TMU0_S,
  1077. - QPU_W_TMU0_T,
  1078. - QPU_W_TMU0_R,
  1079. - QPU_W_TMU0_B,
  1080. - QPU_W_TMU1_S,
  1081. - QPU_W_TMU1_T,
  1082. - QPU_W_TMU1_R,
  1083. - QPU_W_TMU1_B,
  1084. + /* 0-31 are the plain regfile a or b fields */
  1085. + QPU_W_ACC0 = 32, /* aka r0 */
  1086. + QPU_W_ACC1,
  1087. + QPU_W_ACC2,
  1088. + QPU_W_ACC3,
  1089. + QPU_W_TMU_NOSWAP,
  1090. + QPU_W_ACC5,
  1091. + QPU_W_HOST_INT,
  1092. + QPU_W_NOP,
  1093. + QPU_W_UNIFORMS_ADDRESS,
  1094. + QPU_W_QUAD_XY, /* X for regfile a, Y for regfile b */
  1095. + QPU_W_MS_FLAGS = 42,
  1096. + QPU_W_REV_FLAG = 42,
  1097. + QPU_W_TLB_STENCIL_SETUP = 43,
  1098. + QPU_W_TLB_Z,
  1099. + QPU_W_TLB_COLOR_MS,
  1100. + QPU_W_TLB_COLOR_ALL,
  1101. + QPU_W_TLB_ALPHA_MASK,
  1102. + QPU_W_VPM,
  1103. + QPU_W_VPMVCD_SETUP, /* LD for regfile a, ST for regfile b */
  1104. + QPU_W_VPM_ADDR, /* LD for regfile a, ST for regfile b */
  1105. + QPU_W_MUTEX_RELEASE,
  1106. + QPU_W_SFU_RECIP,
  1107. + QPU_W_SFU_RECIPSQRT,
  1108. + QPU_W_SFU_EXP,
  1109. + QPU_W_SFU_LOG,
  1110. + QPU_W_TMU0_S,
  1111. + QPU_W_TMU0_T,
  1112. + QPU_W_TMU0_R,
  1113. + QPU_W_TMU0_B,
  1114. + QPU_W_TMU1_S,
  1115. + QPU_W_TMU1_T,
  1116. + QPU_W_TMU1_R,
  1117. + QPU_W_TMU1_B,
  1118. };
  1119. enum qpu_sig_bits {
  1120. - QPU_SIG_SW_BREAKPOINT,
  1121. - QPU_SIG_NONE,
  1122. - QPU_SIG_THREAD_SWITCH,
  1123. - QPU_SIG_PROG_END,
  1124. - QPU_SIG_WAIT_FOR_SCOREBOARD,
  1125. - QPU_SIG_SCOREBOARD_UNLOCK,
  1126. - QPU_SIG_LAST_THREAD_SWITCH,
  1127. - QPU_SIG_COVERAGE_LOAD,
  1128. - QPU_SIG_COLOR_LOAD,
  1129. - QPU_SIG_COLOR_LOAD_END,
  1130. - QPU_SIG_LOAD_TMU0,
  1131. - QPU_SIG_LOAD_TMU1,
  1132. - QPU_SIG_ALPHA_MASK_LOAD,
  1133. - QPU_SIG_SMALL_IMM,
  1134. - QPU_SIG_LOAD_IMM,
  1135. - QPU_SIG_BRANCH
  1136. + QPU_SIG_SW_BREAKPOINT,
  1137. + QPU_SIG_NONE,
  1138. + QPU_SIG_THREAD_SWITCH,
  1139. + QPU_SIG_PROG_END,
  1140. + QPU_SIG_WAIT_FOR_SCOREBOARD,
  1141. + QPU_SIG_SCOREBOARD_UNLOCK,
  1142. + QPU_SIG_LAST_THREAD_SWITCH,
  1143. + QPU_SIG_COVERAGE_LOAD,
  1144. + QPU_SIG_COLOR_LOAD,
  1145. + QPU_SIG_COLOR_LOAD_END,
  1146. + QPU_SIG_LOAD_TMU0,
  1147. + QPU_SIG_LOAD_TMU1,
  1148. + QPU_SIG_ALPHA_MASK_LOAD,
  1149. + QPU_SIG_SMALL_IMM,
  1150. + QPU_SIG_LOAD_IMM,
  1151. + QPU_SIG_BRANCH
  1152. };
  1153. enum qpu_mux {
  1154. - /* hardware mux values */
  1155. - QPU_MUX_R0,
  1156. - QPU_MUX_R1,
  1157. - QPU_MUX_R2,
  1158. - QPU_MUX_R3,
  1159. - QPU_MUX_R4,
  1160. - QPU_MUX_R5,
  1161. - QPU_MUX_A,
  1162. - QPU_MUX_B,
  1163. + /* hardware mux values */
  1164. + QPU_MUX_R0,
  1165. + QPU_MUX_R1,
  1166. + QPU_MUX_R2,
  1167. + QPU_MUX_R3,
  1168. + QPU_MUX_R4,
  1169. + QPU_MUX_R5,
  1170. + QPU_MUX_A,
  1171. + QPU_MUX_B,
  1172. - /* non-hardware mux values */
  1173. - QPU_MUX_IMM,
  1174. + /* non-hardware mux values */
  1175. + QPU_MUX_IMM,
  1176. };
  1177. enum qpu_cond {
  1178. - QPU_COND_NEVER,
  1179. - QPU_COND_ALWAYS,
  1180. - QPU_COND_ZS,
  1181. - QPU_COND_ZC,
  1182. - QPU_COND_NS,
  1183. - QPU_COND_NC,
  1184. - QPU_COND_CS,
  1185. - QPU_COND_CC,
  1186. + QPU_COND_NEVER,
  1187. + QPU_COND_ALWAYS,
  1188. + QPU_COND_ZS,
  1189. + QPU_COND_ZC,
  1190. + QPU_COND_NS,
  1191. + QPU_COND_NC,
  1192. + QPU_COND_CS,
  1193. + QPU_COND_CC,
  1194. };
  1195. enum qpu_pack_mul {
  1196. - QPU_PACK_MUL_NOP,
  1197. - QPU_PACK_MUL_8888 = 3, /* replicated to each 8 bits of the 32-bit dst. */
  1198. - QPU_PACK_MUL_8A,
  1199. - QPU_PACK_MUL_8B,
  1200. - QPU_PACK_MUL_8C,
  1201. - QPU_PACK_MUL_8D,
  1202. + QPU_PACK_MUL_NOP,
  1203. + /* replicated to each 8 bits of the 32-bit dst. */
  1204. + QPU_PACK_MUL_8888 = 3,
  1205. + QPU_PACK_MUL_8A,
  1206. + QPU_PACK_MUL_8B,
  1207. + QPU_PACK_MUL_8C,
  1208. + QPU_PACK_MUL_8D,
  1209. };
  1210. enum qpu_pack_a {
  1211. - QPU_PACK_A_NOP,
  1212. - /* convert to 16 bit float if float input, or to int16. */
  1213. - QPU_PACK_A_16A,
  1214. - QPU_PACK_A_16B,
  1215. - /* replicated to each 8 bits of the 32-bit dst. */
  1216. - QPU_PACK_A_8888,
  1217. - /* Convert to 8-bit unsigned int. */
  1218. - QPU_PACK_A_8A,
  1219. - QPU_PACK_A_8B,
  1220. - QPU_PACK_A_8C,
  1221. - QPU_PACK_A_8D,
  1222. -
  1223. - /* Saturating variants of the previous instructions. */
  1224. - QPU_PACK_A_32_SAT, /* int-only */
  1225. - QPU_PACK_A_16A_SAT, /* int or float */
  1226. - QPU_PACK_A_16B_SAT,
  1227. - QPU_PACK_A_8888_SAT,
  1228. - QPU_PACK_A_8A_SAT,
  1229. - QPU_PACK_A_8B_SAT,
  1230. - QPU_PACK_A_8C_SAT,
  1231. - QPU_PACK_A_8D_SAT,
  1232. + QPU_PACK_A_NOP,
  1233. + /* convert to 16 bit float if float input, or to int16. */
  1234. + QPU_PACK_A_16A,
  1235. + QPU_PACK_A_16B,
  1236. + /* replicated to each 8 bits of the 32-bit dst. */
  1237. + QPU_PACK_A_8888,
  1238. + /* Convert to 8-bit unsigned int. */
  1239. + QPU_PACK_A_8A,
  1240. + QPU_PACK_A_8B,
  1241. + QPU_PACK_A_8C,
  1242. + QPU_PACK_A_8D,
  1243. +
  1244. + /* Saturating variants of the previous instructions. */
  1245. + QPU_PACK_A_32_SAT, /* int-only */
  1246. + QPU_PACK_A_16A_SAT, /* int or float */
  1247. + QPU_PACK_A_16B_SAT,
  1248. + QPU_PACK_A_8888_SAT,
  1249. + QPU_PACK_A_8A_SAT,
  1250. + QPU_PACK_A_8B_SAT,
  1251. + QPU_PACK_A_8C_SAT,
  1252. + QPU_PACK_A_8D_SAT,
  1253. };
  1254. enum qpu_unpack_r4 {
  1255. - QPU_UNPACK_R4_NOP,
  1256. - QPU_UNPACK_R4_F16A_TO_F32,
  1257. - QPU_UNPACK_R4_F16B_TO_F32,
  1258. - QPU_UNPACK_R4_8D_REP,
  1259. - QPU_UNPACK_R4_8A,
  1260. - QPU_UNPACK_R4_8B,
  1261. - QPU_UNPACK_R4_8C,
  1262. - QPU_UNPACK_R4_8D,
  1263. -};
  1264. -
  1265. -#define QPU_MASK(high, low) ((((uint64_t)1<<((high)-(low)+1))-1)<<(low))
  1266. -/* Using the GNU statement expression extension */
  1267. -#define QPU_SET_FIELD(value, field) \
  1268. - ({ \
  1269. - uint64_t fieldval = (uint64_t)(value) << field ## _SHIFT; \
  1270. - assert((fieldval & ~ field ## _MASK) == 0); \
  1271. - fieldval & field ## _MASK; \
  1272. - })
  1273. + QPU_UNPACK_R4_NOP,
  1274. + QPU_UNPACK_R4_F16A_TO_F32,
  1275. + QPU_UNPACK_R4_F16B_TO_F32,
  1276. + QPU_UNPACK_R4_8D_REP,
  1277. + QPU_UNPACK_R4_8A,
  1278. + QPU_UNPACK_R4_8B,
  1279. + QPU_UNPACK_R4_8C,
  1280. + QPU_UNPACK_R4_8D,
  1281. +};
  1282. +
  1283. +#define QPU_MASK(high, low) \
  1284. + ((((uint64_t)1 << ((high) - (low) + 1)) - 1) << (low))
  1285. -#define QPU_GET_FIELD(word, field) ((uint32_t)(((word) & field ## _MASK) >> field ## _SHIFT))
  1286. +#define QPU_GET_FIELD(word, field) \
  1287. + ((uint32_t)(((word) & field ## _MASK) >> field ## _SHIFT))
  1288. #define QPU_SIG_SHIFT 60
  1289. #define QPU_SIG_MASK QPU_MASK(63, 60)
  1290. --- a/drivers/gpu/drm/vc4/vc4_render_cl.c
  1291. +++ b/drivers/gpu/drm/vc4/vc4_render_cl.c
  1292. @@ -63,7 +63,6 @@ static inline void rcl_u32(struct vc4_rc
  1293. setup->next_offset += 4;
  1294. }
  1295. -
  1296. /*
  1297. * Emits a no-op STORE_TILE_BUFFER_GENERAL.
  1298. *
  1299. @@ -217,7 +216,7 @@ static int vc4_create_rcl_bo(struct drm_
  1300. }
  1301. size += xtiles * ytiles * loop_body_size;
  1302. - setup->rcl = &vc4_bo_create(dev, size)->base;
  1303. + setup->rcl = &vc4_bo_create(dev, size, true)->base;
  1304. if (!setup->rcl)
  1305. return -ENOMEM;
  1306. list_add_tail(&to_vc4_bo(&setup->rcl->base)->unref_head,
  1307. @@ -256,6 +255,7 @@ static int vc4_create_rcl_bo(struct drm_
  1308. for (x = min_x_tile; x <= max_x_tile; x++) {
  1309. bool first = (x == min_x_tile && y == min_y_tile);
  1310. bool last = (x == max_x_tile && y == max_y_tile);
  1311. +
  1312. emit_tile(exec, setup, x, y, first, last);
  1313. }
  1314. }
  1315. --- a/drivers/gpu/drm/vc4/vc4_v3d.c
  1316. +++ b/drivers/gpu/drm/vc4/vc4_v3d.c
  1317. @@ -125,7 +125,7 @@ int vc4_v3d_debugfs_regs(struct seq_file
  1318. int vc4_v3d_debugfs_ident(struct seq_file *m, void *unused)
  1319. {
  1320. - struct drm_info_node *node = (struct drm_info_node *) m->private;
  1321. + struct drm_info_node *node = (struct drm_info_node *)m->private;
  1322. struct drm_device *dev = node->minor->dev;
  1323. struct vc4_dev *vc4 = to_vc4_dev(dev);
  1324. uint32_t ident1 = V3D_READ(V3D_IDENT1);
  1325. @@ -133,11 +133,13 @@ int vc4_v3d_debugfs_ident(struct seq_fil
  1326. uint32_t tups = VC4_GET_FIELD(ident1, V3D_IDENT1_TUPS);
  1327. uint32_t qups = VC4_GET_FIELD(ident1, V3D_IDENT1_QUPS);
  1328. - seq_printf(m, "Revision: %d\n", VC4_GET_FIELD(ident1, V3D_IDENT1_REV));
  1329. + seq_printf(m, "Revision: %d\n",
  1330. + VC4_GET_FIELD(ident1, V3D_IDENT1_REV));
  1331. seq_printf(m, "Slices: %d\n", nslc);
  1332. seq_printf(m, "TMUs: %d\n", nslc * tups);
  1333. seq_printf(m, "QPUs: %d\n", nslc * qups);
  1334. - seq_printf(m, "Semaphores: %d\n", VC4_GET_FIELD(ident1, V3D_IDENT1_NSEM));
  1335. + seq_printf(m, "Semaphores: %d\n",
  1336. + VC4_GET_FIELD(ident1, V3D_IDENT1_NSEM));
  1337. return 0;
  1338. }
  1339. @@ -218,7 +220,7 @@ static int vc4_v3d_bind(struct device *d
  1340. }
  1341. static void vc4_v3d_unbind(struct device *dev, struct device *master,
  1342. - void *data)
  1343. + void *data)
  1344. {
  1345. struct drm_device *drm = dev_get_drvdata(master);
  1346. struct vc4_dev *vc4 = to_vc4_dev(drm);
  1347. --- a/drivers/gpu/drm/vc4/vc4_validate.c
  1348. +++ b/drivers/gpu/drm/vc4/vc4_validate.c
  1349. @@ -48,7 +48,6 @@
  1350. void *validated, \
  1351. void *untrusted
  1352. -
  1353. /** Return the width in pixels of a 64-byte microtile. */
  1354. static uint32_t
  1355. utile_width(int cpp)
  1356. @@ -192,7 +191,7 @@ vc4_check_tex_size(struct vc4_exec_info
  1357. if (size + offset < size ||
  1358. size + offset > fbo->base.size) {
  1359. - DRM_ERROR("Overflow in %dx%d (%dx%d) fbo size (%d + %d > %d)\n",
  1360. + DRM_ERROR("Overflow in %dx%d (%dx%d) fbo size (%d + %d > %zd)\n",
  1361. width, height,
  1362. aligned_width, aligned_height,
  1363. size, offset, fbo->base.size);
  1364. @@ -278,7 +277,7 @@ validate_indexed_prim_list(VALIDATE_ARGS
  1365. if (offset > ib->base.size ||
  1366. (ib->base.size - offset) / index_size < length) {
  1367. - DRM_ERROR("IB access overflow (%d + %d*%d > %d)\n",
  1368. + DRM_ERROR("IB access overflow (%d + %d*%d > %zd)\n",
  1369. offset, length, index_size, ib->base.size);
  1370. return -EINVAL;
  1371. }
  1372. @@ -377,6 +376,7 @@ static int
  1373. validate_tile_binning_config(VALIDATE_ARGS)
  1374. {
  1375. struct drm_device *dev = exec->exec_bo->base.dev;
  1376. + struct vc4_bo *tile_bo;
  1377. uint8_t flags;
  1378. uint32_t tile_state_size, tile_alloc_size;
  1379. uint32_t tile_count;
  1380. @@ -438,12 +438,12 @@ validate_tile_binning_config(VALIDATE_AR
  1381. */
  1382. tile_alloc_size += 1024 * 1024;
  1383. - exec->tile_bo = &vc4_bo_create(dev, exec->tile_alloc_offset +
  1384. - tile_alloc_size)->base;
  1385. + tile_bo = vc4_bo_create(dev, exec->tile_alloc_offset + tile_alloc_size,
  1386. + true);
  1387. + exec->tile_bo = &tile_bo->base;
  1388. if (!exec->tile_bo)
  1389. return -ENOMEM;
  1390. - list_add_tail(&to_vc4_bo(&exec->tile_bo->base)->unref_head,
  1391. - &exec->unref_list);
  1392. + list_add_tail(&tile_bo->unref_head, &exec->unref_list);
  1393. /* tile alloc address. */
  1394. *(uint32_t *)(validated + 0) = (exec->tile_bo->paddr +
  1395. @@ -463,8 +463,8 @@ validate_gem_handles(VALIDATE_ARGS)
  1396. return 0;
  1397. }
  1398. -#define VC4_DEFINE_PACKET(packet, name, func) \
  1399. - [packet] = { packet ## _SIZE, name, func }
  1400. +#define VC4_DEFINE_PACKET(packet, func) \
  1401. + [packet] = { packet ## _SIZE, #packet, func }
  1402. static const struct cmd_info {
  1403. uint16_t len;
  1404. @@ -472,42 +472,43 @@ static const struct cmd_info {
  1405. int (*func)(struct vc4_exec_info *exec, void *validated,
  1406. void *untrusted);
  1407. } cmd_info[] = {
  1408. - VC4_DEFINE_PACKET(VC4_PACKET_HALT, "halt", NULL),
  1409. - VC4_DEFINE_PACKET(VC4_PACKET_NOP, "nop", NULL),
  1410. - VC4_DEFINE_PACKET(VC4_PACKET_FLUSH, "flush", NULL),
  1411. - VC4_DEFINE_PACKET(VC4_PACKET_FLUSH_ALL, "flush all state", validate_flush_all),
  1412. - VC4_DEFINE_PACKET(VC4_PACKET_START_TILE_BINNING, "start tile binning", validate_start_tile_binning),
  1413. - VC4_DEFINE_PACKET(VC4_PACKET_INCREMENT_SEMAPHORE, "increment semaphore", validate_increment_semaphore),
  1414. -
  1415. - VC4_DEFINE_PACKET(VC4_PACKET_GL_INDEXED_PRIMITIVE, "Indexed Primitive List", validate_indexed_prim_list),
  1416. -
  1417. - VC4_DEFINE_PACKET(VC4_PACKET_GL_ARRAY_PRIMITIVE, "Vertex Array Primitives", validate_gl_array_primitive),
  1418. -
  1419. - /* This is only used by clipped primitives (packets 48 and 49), which
  1420. - * we don't support parsing yet.
  1421. - */
  1422. - VC4_DEFINE_PACKET(VC4_PACKET_PRIMITIVE_LIST_FORMAT, "primitive list format", NULL),
  1423. -
  1424. - VC4_DEFINE_PACKET(VC4_PACKET_GL_SHADER_STATE, "GL Shader State", validate_gl_shader_state),
  1425. - VC4_DEFINE_PACKET(VC4_PACKET_NV_SHADER_STATE, "NV Shader State", validate_nv_shader_state),
  1426. -
  1427. - VC4_DEFINE_PACKET(VC4_PACKET_CONFIGURATION_BITS, "configuration bits", NULL),
  1428. - VC4_DEFINE_PACKET(VC4_PACKET_FLAT_SHADE_FLAGS, "flat shade flags", NULL),
  1429. - VC4_DEFINE_PACKET(VC4_PACKET_POINT_SIZE, "point size", NULL),
  1430. - VC4_DEFINE_PACKET(VC4_PACKET_LINE_WIDTH, "line width", NULL),
  1431. - VC4_DEFINE_PACKET(VC4_PACKET_RHT_X_BOUNDARY, "RHT X boundary", NULL),
  1432. - VC4_DEFINE_PACKET(VC4_PACKET_DEPTH_OFFSET, "Depth Offset", NULL),
  1433. - VC4_DEFINE_PACKET(VC4_PACKET_CLIP_WINDOW, "Clip Window", NULL),
  1434. - VC4_DEFINE_PACKET(VC4_PACKET_VIEWPORT_OFFSET, "Viewport Offset", NULL),
  1435. - VC4_DEFINE_PACKET(VC4_PACKET_CLIPPER_XY_SCALING, "Clipper XY Scaling", NULL),
  1436. + VC4_DEFINE_PACKET(VC4_PACKET_HALT, NULL),
  1437. + VC4_DEFINE_PACKET(VC4_PACKET_NOP, NULL),
  1438. + VC4_DEFINE_PACKET(VC4_PACKET_FLUSH, NULL),
  1439. + VC4_DEFINE_PACKET(VC4_PACKET_FLUSH_ALL, validate_flush_all),
  1440. + VC4_DEFINE_PACKET(VC4_PACKET_START_TILE_BINNING,
  1441. + validate_start_tile_binning),
  1442. + VC4_DEFINE_PACKET(VC4_PACKET_INCREMENT_SEMAPHORE,
  1443. + validate_increment_semaphore),
  1444. +
  1445. + VC4_DEFINE_PACKET(VC4_PACKET_GL_INDEXED_PRIMITIVE,
  1446. + validate_indexed_prim_list),
  1447. + VC4_DEFINE_PACKET(VC4_PACKET_GL_ARRAY_PRIMITIVE,
  1448. + validate_gl_array_primitive),
  1449. +
  1450. + VC4_DEFINE_PACKET(VC4_PACKET_PRIMITIVE_LIST_FORMAT, NULL),
  1451. +
  1452. + VC4_DEFINE_PACKET(VC4_PACKET_GL_SHADER_STATE, validate_gl_shader_state),
  1453. + VC4_DEFINE_PACKET(VC4_PACKET_NV_SHADER_STATE, validate_nv_shader_state),
  1454. +
  1455. + VC4_DEFINE_PACKET(VC4_PACKET_CONFIGURATION_BITS, NULL),
  1456. + VC4_DEFINE_PACKET(VC4_PACKET_FLAT_SHADE_FLAGS, NULL),
  1457. + VC4_DEFINE_PACKET(VC4_PACKET_POINT_SIZE, NULL),
  1458. + VC4_DEFINE_PACKET(VC4_PACKET_LINE_WIDTH, NULL),
  1459. + VC4_DEFINE_PACKET(VC4_PACKET_RHT_X_BOUNDARY, NULL),
  1460. + VC4_DEFINE_PACKET(VC4_PACKET_DEPTH_OFFSET, NULL),
  1461. + VC4_DEFINE_PACKET(VC4_PACKET_CLIP_WINDOW, NULL),
  1462. + VC4_DEFINE_PACKET(VC4_PACKET_VIEWPORT_OFFSET, NULL),
  1463. + VC4_DEFINE_PACKET(VC4_PACKET_CLIPPER_XY_SCALING, NULL),
  1464. /* Note: The docs say this was also 105, but it was 106 in the
  1465. * initial userland code drop.
  1466. */
  1467. - VC4_DEFINE_PACKET(VC4_PACKET_CLIPPER_Z_SCALING, "Clipper Z Scale and Offset", NULL),
  1468. + VC4_DEFINE_PACKET(VC4_PACKET_CLIPPER_Z_SCALING, NULL),
  1469. - VC4_DEFINE_PACKET(VC4_PACKET_TILE_BINNING_MODE_CONFIG, "tile binning configuration", validate_tile_binning_config),
  1470. + VC4_DEFINE_PACKET(VC4_PACKET_TILE_BINNING_MODE_CONFIG,
  1471. + validate_tile_binning_config),
  1472. - VC4_DEFINE_PACKET(VC4_PACKET_GEM_HANDLES, "GEM handles", validate_gem_handles),
  1473. + VC4_DEFINE_PACKET(VC4_PACKET_GEM_HANDLES, validate_gem_handles),
  1474. };
  1475. int
  1476. @@ -526,7 +527,7 @@ vc4_validate_bin_cl(struct drm_device *d
  1477. u8 cmd = *(uint8_t *)src_pkt;
  1478. const struct cmd_info *info;
  1479. - if (cmd > ARRAY_SIZE(cmd_info)) {
  1480. + if (cmd >= ARRAY_SIZE(cmd_info)) {
  1481. DRM_ERROR("0x%08x: packet %d out of bounds\n",
  1482. src_offset, cmd);
  1483. return -EINVAL;
  1484. @@ -539,11 +540,6 @@ vc4_validate_bin_cl(struct drm_device *d
  1485. return -EINVAL;
  1486. }
  1487. -#if 0
  1488. - DRM_INFO("0x%08x: packet %d (%s) size %d processing...\n",
  1489. - src_offset, cmd, info->name, info->len);
  1490. -#endif
  1491. -
  1492. if (src_offset + info->len > len) {
  1493. DRM_ERROR("0x%08x: packet %d (%s) length 0x%08x "
  1494. "exceeds bounds (0x%08x)\n",
  1495. @@ -558,8 +554,7 @@ vc4_validate_bin_cl(struct drm_device *d
  1496. if (info->func && info->func(exec,
  1497. dst_pkt + 1,
  1498. src_pkt + 1)) {
  1499. - DRM_ERROR("0x%08x: packet %d (%s) failed to "
  1500. - "validate\n",
  1501. + DRM_ERROR("0x%08x: packet %d (%s) failed to validate\n",
  1502. src_offset, cmd, info->name);
  1503. return -EINVAL;
  1504. }
  1505. @@ -618,12 +613,14 @@ reloc_tex(struct vc4_exec_info *exec,
  1506. if (sample->is_direct) {
  1507. uint32_t remaining_size = tex->base.size - p0;
  1508. +
  1509. if (p0 > tex->base.size - 4) {
  1510. DRM_ERROR("UBO offset greater than UBO size\n");
  1511. goto fail;
  1512. }
  1513. if (p1 > remaining_size - 4) {
  1514. - DRM_ERROR("UBO clamp would allow reads outside of UBO\n");
  1515. + DRM_ERROR("UBO clamp would allow reads "
  1516. + "outside of UBO\n");
  1517. goto fail;
  1518. }
  1519. *validated_p0 = tex->paddr + p0;
  1520. @@ -786,7 +783,7 @@ validate_shader_rec(struct drm_device *d
  1521. struct drm_gem_cma_object *bo[ARRAY_SIZE(gl_relocs) + 8];
  1522. uint32_t nr_attributes = 0, nr_fixed_relocs, nr_relocs, packet_size;
  1523. int i;
  1524. - struct vc4_validated_shader_info *validated_shader;
  1525. + struct vc4_validated_shader_info *shader;
  1526. if (state->packet == VC4_PACKET_NV_SHADER_STATE) {
  1527. relocs = nv_relocs;
  1528. @@ -841,12 +838,12 @@ validate_shader_rec(struct drm_device *d
  1529. else
  1530. mode = VC4_MODE_RENDER;
  1531. - if (!vc4_use_bo(exec, src_handles[i], mode, &bo[i])) {
  1532. + if (!vc4_use_bo(exec, src_handles[i], mode, &bo[i]))
  1533. return false;
  1534. - }
  1535. }
  1536. for (i = 0; i < nr_fixed_relocs; i++) {
  1537. + struct vc4_bo *vc4_bo;
  1538. uint32_t o = relocs[i].offset;
  1539. uint32_t src_offset = *(uint32_t *)(pkt_u + o);
  1540. uint32_t *texture_handles_u;
  1541. @@ -858,34 +855,34 @@ validate_shader_rec(struct drm_device *d
  1542. switch (relocs[i].type) {
  1543. case RELOC_CODE:
  1544. if (src_offset != 0) {
  1545. - DRM_ERROR("Shaders must be at offset 0 of "
  1546. - "the BO.\n");
  1547. + DRM_ERROR("Shaders must be at offset 0 "
  1548. + "of the BO.\n");
  1549. goto fail;
  1550. }
  1551. - validated_shader = to_vc4_bo(&bo[i]->base)->validated_shader;
  1552. - if (!validated_shader)
  1553. + vc4_bo = to_vc4_bo(&bo[i]->base);
  1554. + shader = vc4_bo->validated_shader;
  1555. + if (!shader)
  1556. goto fail;
  1557. - if (validated_shader->uniforms_src_size >
  1558. - exec->uniforms_size) {
  1559. + if (shader->uniforms_src_size > exec->uniforms_size) {
  1560. DRM_ERROR("Uniforms src buffer overflow\n");
  1561. goto fail;
  1562. }
  1563. texture_handles_u = exec->uniforms_u;
  1564. uniform_data_u = (texture_handles_u +
  1565. - validated_shader->num_texture_samples);
  1566. + shader->num_texture_samples);
  1567. memcpy(exec->uniforms_v, uniform_data_u,
  1568. - validated_shader->uniforms_size);
  1569. + shader->uniforms_size);
  1570. for (tex = 0;
  1571. - tex < validated_shader->num_texture_samples;
  1572. + tex < shader->num_texture_samples;
  1573. tex++) {
  1574. if (!reloc_tex(exec,
  1575. uniform_data_u,
  1576. - &validated_shader->texture_samples[tex],
  1577. + &shader->texture_samples[tex],
  1578. texture_handles_u[tex])) {
  1579. goto fail;
  1580. }
  1581. @@ -893,9 +890,9 @@ validate_shader_rec(struct drm_device *d
  1582. *(uint32_t *)(pkt_v + o + 4) = exec->uniforms_p;
  1583. - exec->uniforms_u += validated_shader->uniforms_src_size;
  1584. - exec->uniforms_v += validated_shader->uniforms_size;
  1585. - exec->uniforms_p += validated_shader->uniforms_size;
  1586. + exec->uniforms_u += shader->uniforms_src_size;
  1587. + exec->uniforms_v += shader->uniforms_size;
  1588. + exec->uniforms_p += shader->uniforms_size;
  1589. break;
  1590. @@ -926,7 +923,8 @@ validate_shader_rec(struct drm_device *d
  1591. max_index = ((vbo->base.size - offset - attr_size) /
  1592. stride);
  1593. if (state->max_index > max_index) {
  1594. - DRM_ERROR("primitives use index %d out of supplied %d\n",
  1595. + DRM_ERROR("primitives use index %d out of "
  1596. + "supplied %d\n",
  1597. state->max_index, max_index);
  1598. return -EINVAL;
  1599. }
  1600. --- a/drivers/gpu/drm/vc4/vc4_validate_shaders.c
  1601. +++ b/drivers/gpu/drm/vc4/vc4_validate_shaders.c
  1602. @@ -24,24 +24,16 @@
  1603. /**
  1604. * DOC: Shader validator for VC4.
  1605. *
  1606. - * The VC4 has no IOMMU between it and system memory. So, a user with access
  1607. - * to execute shaders could escalate privilege by overwriting system memory
  1608. - * (using the VPM write address register in the general-purpose DMA mode) or
  1609. - * reading system memory it shouldn't (reading it as a texture, or uniform
  1610. - * data, or vertex data).
  1611. + * The VC4 has no IOMMU between it and system memory, so a user with
  1612. + * access to execute shaders could escalate privilege by overwriting
  1613. + * system memory (using the VPM write address register in the
  1614. + * general-purpose DMA mode) or reading system memory it shouldn't
  1615. + * (reading it as a texture, or uniform data, or vertex data).
  1616. *
  1617. - * This walks over a shader starting from some offset within a BO, ensuring
  1618. - * that its accesses are appropriately bounded, and recording how many texture
  1619. - * accesses are made and where so that we can do relocations for them in the
  1620. + * This walks over a shader BO, ensuring that its accesses are
  1621. + * appropriately bounded, and recording how many texture accesses are
  1622. + * made and where so that we can do relocations for them in the
  1623. * uniform stream.
  1624. - *
  1625. - * The kernel API has shaders stored in user-mapped BOs. The BOs will be
  1626. - * forcibly unmapped from the process before validation, and any cache of
  1627. - * validated state will be flushed if the mapping is faulted back in.
  1628. - *
  1629. - * Storing the shaders in BOs means that the validation process will be slow
  1630. - * due to uncached reads, but since shaders are long-lived and shader BOs are
  1631. - * never actually modified, this shouldn't be a problem.
  1632. */
  1633. #include "vc4_drv.h"
  1634. @@ -70,7 +62,6 @@ waddr_to_live_reg_index(uint32_t waddr,
  1635. else
  1636. return waddr;
  1637. } else if (waddr <= QPU_W_ACC3) {
  1638. -
  1639. return 64 + waddr - QPU_W_ACC0;
  1640. } else {
  1641. return ~0;
  1642. @@ -85,15 +76,14 @@ raddr_add_a_to_live_reg_index(uint64_t i
  1643. uint32_t raddr_a = QPU_GET_FIELD(inst, QPU_RADDR_A);
  1644. uint32_t raddr_b = QPU_GET_FIELD(inst, QPU_RADDR_B);
  1645. - if (add_a == QPU_MUX_A) {
  1646. + if (add_a == QPU_MUX_A)
  1647. return raddr_a;
  1648. - } else if (add_a == QPU_MUX_B && sig != QPU_SIG_SMALL_IMM) {
  1649. + else if (add_a == QPU_MUX_B && sig != QPU_SIG_SMALL_IMM)
  1650. return 32 + raddr_b;
  1651. - } else if (add_a <= QPU_MUX_R3) {
  1652. + else if (add_a <= QPU_MUX_R3)
  1653. return 64 + add_a;
  1654. - } else {
  1655. + else
  1656. return ~0;
  1657. - }
  1658. }
  1659. static bool
  1660. @@ -111,9 +101,9 @@ is_tmu_write(uint32_t waddr)
  1661. }
  1662. static bool
  1663. -record_validated_texture_sample(struct vc4_validated_shader_info *validated_shader,
  1664. - struct vc4_shader_validation_state *validation_state,
  1665. - int tmu)
  1666. +record_texture_sample(struct vc4_validated_shader_info *validated_shader,
  1667. + struct vc4_shader_validation_state *validation_state,
  1668. + int tmu)
  1669. {
  1670. uint32_t s = validated_shader->num_texture_samples;
  1671. int i;
  1672. @@ -226,8 +216,8 @@ check_tmu_write(uint64_t inst,
  1673. validated_shader->uniforms_size += 4;
  1674. if (submit) {
  1675. - if (!record_validated_texture_sample(validated_shader,
  1676. - validation_state, tmu)) {
  1677. + if (!record_texture_sample(validated_shader,
  1678. + validation_state, tmu)) {
  1679. return false;
  1680. }
  1681. @@ -238,10 +228,10 @@ check_tmu_write(uint64_t inst,
  1682. }
  1683. static bool
  1684. -check_register_write(uint64_t inst,
  1685. - struct vc4_validated_shader_info *validated_shader,
  1686. - struct vc4_shader_validation_state *validation_state,
  1687. - bool is_mul)
  1688. +check_reg_write(uint64_t inst,
  1689. + struct vc4_validated_shader_info *validated_shader,
  1690. + struct vc4_shader_validation_state *validation_state,
  1691. + bool is_mul)
  1692. {
  1693. uint32_t waddr = (is_mul ?
  1694. QPU_GET_FIELD(inst, QPU_WADDR_MUL) :
  1695. @@ -297,7 +287,7 @@ check_register_write(uint64_t inst,
  1696. return true;
  1697. case QPU_W_TLB_STENCIL_SETUP:
  1698. - return true;
  1699. + return true;
  1700. }
  1701. return true;
  1702. @@ -360,7 +350,7 @@ track_live_clamps(uint64_t inst,
  1703. }
  1704. validation_state->live_max_clamp_regs[lri_add] = true;
  1705. - } if (op_add == QPU_A_MIN) {
  1706. + } else if (op_add == QPU_A_MIN) {
  1707. /* Track live clamps of a value clamped to a minimum of 0 and
  1708. * a maximum of some uniform's offset.
  1709. */
  1710. @@ -392,8 +382,10 @@ check_instruction_writes(uint64_t inst,
  1711. return false;
  1712. }
  1713. - ok = (check_register_write(inst, validated_shader, validation_state, false) &&
  1714. - check_register_write(inst, validated_shader, validation_state, true));
  1715. + ok = (check_reg_write(inst, validated_shader, validation_state,
  1716. + false) &&
  1717. + check_reg_write(inst, validated_shader, validation_state,
  1718. + true));
  1719. track_live_clamps(inst, validated_shader, validation_state);
  1720. @@ -441,7 +433,7 @@ vc4_validate_shader(struct drm_gem_cma_o
  1721. shader = shader_obj->vaddr;
  1722. max_ip = shader_obj->base.size / sizeof(uint64_t);
  1723. - validated_shader = kcalloc(sizeof(*validated_shader), 1, GFP_KERNEL);
  1724. + validated_shader = kcalloc(1, sizeof(*validated_shader), GFP_KERNEL);
  1725. if (!validated_shader)
  1726. return NULL;
  1727. @@ -497,7 +489,7 @@ vc4_validate_shader(struct drm_gem_cma_o
  1728. if (ip == max_ip) {
  1729. DRM_ERROR("shader failed to terminate before "
  1730. - "shader BO end at %d\n",
  1731. + "shader BO end at %zd\n",
  1732. shader_obj->base.size);
  1733. goto fail;
  1734. }
  1735. --- a/include/drm/drmP.h
  1736. +++ b/include/drm/drmP.h
  1737. @@ -599,6 +599,13 @@ struct drm_driver {
  1738. int (*gem_open_object) (struct drm_gem_object *, struct drm_file *);
  1739. void (*gem_close_object) (struct drm_gem_object *, struct drm_file *);
  1740. + /**
  1741. + * Hook for allocating the GEM object struct, for use by core
  1742. + * helpers.
  1743. + */
  1744. + struct drm_gem_object *(*gem_create_object)(struct drm_device *dev,
  1745. + size_t size);
  1746. +
  1747. /* prime: */
  1748. /* export handle -> fd (see drm_gem_prime_handle_to_fd() helper) */
  1749. int (*prime_handle_to_fd)(struct drm_device *dev, struct drm_file *file_priv,
  1750. @@ -653,7 +660,6 @@ struct drm_driver {
  1751. u32 driver_features;
  1752. int dev_priv_size;
  1753. - size_t gem_obj_size;
  1754. const struct drm_ioctl_desc *ioctls;
  1755. int num_ioctls;
  1756. const struct file_operations *fops;