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

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