todo.rst 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. .. _todo:
  2. =========
  3. TODO list
  4. =========
  5. This section contains a list of smaller janitorial tasks in the kernel DRM
  6. graphics subsystem useful as newbie projects. Or for slow rainy days.
  7. Subsystem-wide refactorings
  8. ===========================
  9. De-midlayer drivers
  10. -------------------
  11. With the recent ``drm_bus`` cleanup patches for 3.17 it is no longer required
  12. to have a ``drm_bus`` structure set up. Drivers can directly set up the
  13. ``drm_device`` structure instead of relying on bus methods in ``drm_usb.c``
  14. and ``drm_pci.c``. The goal is to get rid of the driver's ``->load`` /
  15. ``->unload`` callbacks and open-code the load/unload sequence properly, using
  16. the new two-stage ``drm_device`` setup/teardown.
  17. Once all existing drivers are converted we can also remove those bus support
  18. files for USB and platform devices.
  19. All you need is a GPU for a non-converted driver (currently almost all of
  20. them, but also all the virtual ones used by KVM, so everyone qualifies).
  21. Contact: Daniel Vetter, Thierry Reding, respective driver maintainers
  22. Switch from reference/unreference to get/put
  23. --------------------------------------------
  24. For some reason DRM core uses ``reference``/``unreference`` suffixes for
  25. refcounting functions, but kernel uses ``get``/``put`` (e.g.
  26. ``kref_get``/``put()``). It would be good to switch over for consistency, and
  27. it's shorter. Needs to be done in 3 steps for each pair of functions:
  28. * Create new ``get``/``put`` functions, define the old names as compatibility
  29. wrappers
  30. * Switch over each file/driver using a cocci-generated spatch.
  31. * Once all users of the old names are gone, remove them.
  32. This way drivers/patches in the progress of getting merged won't break.
  33. Contact: Daniel Vetter
  34. Convert existing KMS drivers to atomic modesetting
  35. --------------------------------------------------
  36. 3.19 has the atomic modeset interfaces and helpers, so drivers can now be
  37. converted over. Modern compositors like Wayland or Surfaceflinger on Android
  38. really want an atomic modeset interface, so this is all about the bright
  39. future.
  40. There is a conversion guide for atomic and all you need is a GPU for a
  41. non-converted driver (again virtual HW drivers for KVM are still all
  42. suitable).
  43. As part of this drivers also need to convert to universal plane (which means
  44. exposing primary & cursor as proper plane objects). But that's much easier to
  45. do by directly using the new atomic helper driver callbacks.
  46. Contact: Daniel Vetter, respective driver maintainers
  47. Clean up the clipped coordination confusion around planes
  48. ---------------------------------------------------------
  49. We have a helper to get this right with drm_plane_helper_check_update(), but
  50. it's not consistently used. This should be fixed, preferrably in the atomic
  51. helpers (and drivers then moved over to clipped coordinates). Probably the
  52. helper should also be moved from drm_plane_helper.c to the atomic helpers, to
  53. avoid confusion - the other helpers in that file are all deprecated legacy
  54. helpers.
  55. Contact: Ville Syrjälä, Daniel Vetter, driver maintainers
  56. Convert early atomic drivers to async commit helpers
  57. ----------------------------------------------------
  58. For the first year the atomic modeset helpers didn't support asynchronous /
  59. nonblocking commits, and every driver had to hand-roll them. This is fixed
  60. now, but there's still a pile of existing drivers that easily could be
  61. converted over to the new infrastructure.
  62. One issue with the helpers is that they require that drivers handle completion
  63. events for atomic commits correctly. But fixing these bugs is good anyway.
  64. Contact: Daniel Vetter, respective driver maintainers
  65. Better manual-upload support for atomic
  66. ---------------------------------------
  67. This would be especially useful for tinydrm:
  68. - Add a struct drm_rect dirty_clip to drm_crtc_state. When duplicating the
  69. crtc state, clear that to the max values, x/y = 0 and w/h = MAX_INT, in
  70. __drm_atomic_helper_crtc_duplicate_state().
  71. - Move tinydrm_merge_clips into drm_framebuffer.c, dropping the tinydrm\_
  72. prefix ofc and using drm_fb\_. drm_framebuffer.c makes sense since this
  73. is a function useful to implement the fb->dirty function.
  74. - Create a new drm_fb_dirty function which does essentially what e.g.
  75. mipi_dbi_fb_dirty does. You can use e.g. drm_atomic_helper_update_plane as the
  76. template. But instead of doing a simple full-screen plane update, this new
  77. helper also sets crtc_state->dirty_clip to the right coordinates. And of
  78. course it needs to check whether the fb is actually active (and maybe where),
  79. so there's some book-keeping involved. There's also some good fun involved in
  80. scaling things appropriately. For that case we might simply give up and
  81. declare the entire area covered by the plane as dirty.
  82. Contact: Noralf Trønnes, Daniel Vetter
  83. Fallout from atomic KMS
  84. -----------------------
  85. ``drm_atomic_helper.c`` provides a batch of functions which implement legacy
  86. IOCTLs on top of the new atomic driver interface. Which is really nice for
  87. gradual conversion of drivers, but unfortunately the semantic mismatches are
  88. a bit too severe. So there's some follow-up work to adjust the function
  89. interfaces to fix these issues:
  90. * atomic needs the lock acquire context. At the moment that's passed around
  91. implicitly with some horrible hacks, and it's also allocate with
  92. ``GFP_NOFAIL`` behind the scenes. All legacy paths need to start allocating
  93. the acquire context explicitly on stack and then also pass it down into
  94. drivers explicitly so that the legacy-on-atomic functions can use them.
  95. Except for some driver code this is done.
  96. * A bunch of the vtable hooks are now in the wrong place: DRM has a split
  97. between core vfunc tables (named ``drm_foo_funcs``), which are used to
  98. implement the userspace ABI. And then there's the optional hooks for the
  99. helper libraries (name ``drm_foo_helper_funcs``), which are purely for
  100. internal use. Some of these hooks should be move from ``_funcs`` to
  101. ``_helper_funcs`` since they are not part of the core ABI. There's a
  102. ``FIXME`` comment in the kerneldoc for each such case in ``drm_crtc.h``.
  103. * There's a new helper ``drm_atomic_helper_best_encoder()`` which could be
  104. used by all atomic drivers which don't select the encoder for a given
  105. connector at runtime. That's almost all of them, and would allow us to get
  106. rid of a lot of ``best_encoder`` boilerplate in drivers.
  107. This was almost done, but new drivers added a few more cases again.
  108. Contact: Daniel Vetter
  109. Get rid of dev->struct_mutex from GEM drivers
  110. ---------------------------------------------
  111. ``dev->struct_mutex`` is the Big DRM Lock from legacy days and infested
  112. everything. Nowadays in modern drivers the only bit where it's mandatory is
  113. serializing GEM buffer object destruction. Which unfortunately means drivers
  114. have to keep track of that lock and either call ``unreference`` or
  115. ``unreference_locked`` depending upon context.
  116. Core GEM doesn't have a need for ``struct_mutex`` any more since kernel 4.8,
  117. and there's a ``gem_free_object_unlocked`` callback for any drivers which are
  118. entirely ``struct_mutex`` free.
  119. For drivers that need ``struct_mutex`` it should be replaced with a driver-
  120. private lock. The tricky part is the BO free functions, since those can't
  121. reliably take that lock any more. Instead state needs to be protected with
  122. suitable subordinate locks or some cleanup work pushed to a worker thread. For
  123. performance-critical drivers it might also be better to go with a more
  124. fine-grained per-buffer object and per-context lockings scheme. Currently the
  125. following drivers still use ``struct_mutex``: ``msm``, ``omapdrm`` and
  126. ``udl``.
  127. Contact: Daniel Vetter, respective driver maintainers
  128. Convert instances of dev_info/dev_err/dev_warn to their DRM_DEV_* equivalent
  129. ----------------------------------------------------------------------------
  130. For drivers which could have multiple instances, it is necessary to
  131. differentiate between which is which in the logs. Since DRM_INFO/WARN/ERROR
  132. don't do this, drivers used dev_info/warn/err to make this differentiation. We
  133. now have DRM_DEV_* variants of the drm print macros, so we can start to convert
  134. those drivers back to using drm-formwatted specific log messages.
  135. Before you start this conversion please contact the relevant maintainers to make
  136. sure your work will be merged - not everyone agrees that the DRM dmesg macros
  137. are better.
  138. Contact: Sean Paul, Maintainer of the driver you plan to convert
  139. Convert drivers to use simple modeset suspend/resume
  140. ----------------------------------------------------
  141. Most drivers (except i915 and nouveau) that use
  142. drm_atomic_helper_suspend/resume() can probably be converted to use
  143. drm_mode_config_helper_suspend/resume().
  144. Contact: Maintainer of the driver you plan to convert
  145. Convert drivers to use drm_fb_helper_fbdev_setup/teardown()
  146. -----------------------------------------------------------
  147. Most drivers can use drm_fb_helper_fbdev_setup() except maybe:
  148. - amdgpu which has special logic to decide whether to call
  149. drm_helper_disable_unused_functions()
  150. - armada which isn't atomic and doesn't call
  151. drm_helper_disable_unused_functions()
  152. - i915 which calls drm_fb_helper_initial_config() in a worker
  153. Drivers that use drm_framebuffer_remove() to clean up the fbdev framebuffer can
  154. probably use drm_fb_helper_fbdev_teardown().
  155. Contact: Maintainer of the driver you plan to convert
  156. Clean up mmap forwarding
  157. ------------------------
  158. A lot of drivers forward gem mmap calls to dma-buf mmap for imported buffers.
  159. And also a lot of them forward dma-buf mmap to the gem mmap implementations.
  160. Would be great to refactor this all into a set of small common helpers.
  161. Contact: Daniel Vetter
  162. Put a reservation_object into drm_gem_object
  163. --------------------------------------------
  164. This would remove the need for the ->gem_prime_res_obj callback. It would also
  165. allow us to implement generic helpers for waiting for a bo, allowing for quite a
  166. bit of refactoring in the various wait ioctl implementations.
  167. Contact: Daniel Vetter
  168. idr_init_base()
  169. ---------------
  170. DRM core&drivers uses a lot of idr (integer lookup directories) for mapping
  171. userspace IDs to internal objects, and in most places ID=0 means NULL and hence
  172. is never used. Switching to idr_init_base() for these would make the idr more
  173. efficient.
  174. Contact: Daniel Vetter
  175. Core refactorings
  176. =================
  177. Clean up the DRM header mess
  178. ----------------------------
  179. Currently the DRM subsystem has only one global header, ``drmP.h``. This is
  180. used both for functions exported to helper libraries and drivers and functions
  181. only used internally in the ``drm.ko`` module. The goal would be to move all
  182. header declarations not needed outside of ``drm.ko`` into
  183. ``drivers/gpu/drm/drm_*_internal.h`` header files. ``EXPORT_SYMBOL`` also
  184. needs to be dropped for these functions.
  185. This would nicely tie in with the below task to create kerneldoc after the API
  186. is cleaned up. Or with the "hide legacy cruft better" task.
  187. Note that this is well in progress, but ``drmP.h`` is still huge. The updated
  188. plan is to switch to per-file driver API headers, which will also structure
  189. the kerneldoc better. This should also allow more fine-grained ``#include``
  190. directives.
  191. In the end no .c file should need to include ``drmP.h`` anymore.
  192. Contact: Daniel Vetter
  193. Add missing kerneldoc for exported functions
  194. --------------------------------------------
  195. The DRM reference documentation is still lacking kerneldoc in a few areas. The
  196. task would be to clean up interfaces like moving functions around between
  197. files to better group them and improving the interfaces like dropping return
  198. values for functions that never fail. Then write kerneldoc for all exported
  199. functions and an overview section and integrate it all into the drm book.
  200. See https://dri.freedesktop.org/docs/drm/ for what's there already.
  201. Contact: Daniel Vetter
  202. Hide legacy cruft better
  203. ------------------------
  204. Way back DRM supported only drivers which shadow-attached to PCI devices with
  205. userspace or fbdev drivers setting up outputs. Modern DRM drivers take charge
  206. of the entire device, you can spot them with the DRIVER_MODESET flag.
  207. Unfortunately there's still large piles of legacy code around which needs to
  208. be hidden so that driver writers don't accidentally end up using it. And to
  209. prevent security issues in those legacy IOCTLs from being exploited on modern
  210. drivers. This has multiple possible subtasks:
  211. * Extract support code for legacy features into a ``drm-legacy.ko`` kernel
  212. module and compile it only when one of the legacy drivers is enabled.
  213. This is mostly done, the only thing left is to split up ``drm_irq.c`` into
  214. legacy cruft and the parts needed by modern KMS drivers.
  215. Contact: Daniel Vetter
  216. Make panic handling work
  217. ------------------------
  218. This is a really varied tasks with lots of little bits and pieces:
  219. * The panic path can't be tested currently, leading to constant breaking. The
  220. main issue here is that panics can be triggered from hardirq contexts and
  221. hence all panic related callback can run in hardirq context. It would be
  222. awesome if we could test at least the fbdev helper code and driver code by
  223. e.g. trigger calls through drm debugfs files. hardirq context could be
  224. achieved by using an IPI to the local processor.
  225. * There's a massive confusion of different panic handlers. DRM fbdev emulation
  226. helpers have one, but on top of that the fbcon code itself also has one. We
  227. need to make sure that they stop fighting over each another.
  228. * ``drm_can_sleep()`` is a mess. It hides real bugs in normal operations and
  229. isn't a full solution for panic paths. We need to make sure that it only
  230. returns true if there's a panic going on for real, and fix up all the
  231. fallout.
  232. * The panic handler must never sleep, which also means it can't ever
  233. ``mutex_lock()``. Also it can't grab any other lock unconditionally, not
  234. even spinlocks (because NMI and hardirq can panic too). We need to either
  235. make sure to not call such paths, or trylock everything. Really tricky.
  236. * For the above locking troubles reasons it's pretty much impossible to
  237. attempt a synchronous modeset from panic handlers. The only thing we could
  238. try to achive is an atomic ``set_base`` of the primary plane, and hope that
  239. it shows up. Everything else probably needs to be delayed to some worker or
  240. something else which happens later on. Otherwise it just kills the box
  241. harder, prevent the panic from going out on e.g. netconsole.
  242. * There's also proposal for a simplied DRM console instead of the full-blown
  243. fbcon and DRM fbdev emulation. Any kind of panic handling tricks should
  244. obviously work for both console, in case we ever get kmslog merged.
  245. Contact: Daniel Vetter
  246. Clean up the debugfs support
  247. ----------------------------
  248. There's a bunch of issues with it:
  249. - The drm_info_list ->show() function doesn't even bother to cast to the drm
  250. structure for you. This is lazy.
  251. - We probably want to have some support for debugfs files on crtc/connectors and
  252. maybe other kms objects directly in core. There's even drm_print support in
  253. the funcs for these objects to dump kms state, so it's all there. And then the
  254. ->show() functions should obviously give you a pointer to the right object.
  255. - The drm_info_list stuff is centered on drm_minor instead of drm_device. For
  256. anything we want to print drm_device (or maybe drm_file) is the right thing.
  257. - The drm_driver->debugfs_init hooks we have is just an artifact of the old
  258. midlayered load sequence. DRM debugfs should work more like sysfs, where you
  259. can create properties/files for an object anytime you want, and the core
  260. takes care of publishing/unpuplishing all the files at register/unregister
  261. time. Drivers shouldn't need to worry about these technicalities, and fixing
  262. this (together with the drm_minor->drm_device move) would allow us to remove
  263. debugfs_init.
  264. Contact: Daniel Vetter
  265. KMS cleanups
  266. ------------
  267. Some of these date from the very introduction of KMS in 2008 ...
  268. - drm_mode_config.crtc_idr is misnamed, since it contains all KMS object. Should
  269. be renamed to drm_mode_config.object_idr.
  270. - drm_display_mode doesn't need to be derived from drm_mode_object. That's
  271. leftovers from older (never merged into upstream) KMS designs where modes
  272. where set using their ID, including support to add/remove modes.
  273. Better Testing
  274. ==============
  275. Enable trinity for DRM
  276. ----------------------
  277. And fix up the fallout. Should be really interesting ...
  278. Make KMS tests in i-g-t generic
  279. -------------------------------
  280. The i915 driver team maintains an extensive testsuite for the i915 DRM driver,
  281. including tons of testcases for corner-cases in the modesetting API. It would
  282. be awesome if those tests (at least the ones not relying on Intel-specific GEM
  283. features) could be made to run on any KMS driver.
  284. Basic work to run i-g-t tests on non-i915 is done, what's now missing is mass-
  285. converting things over. For modeset tests we also first need a bit of
  286. infrastructure to use dumb buffers for untiled buffers, to be able to run all
  287. the non-i915 specific modeset tests.
  288. Contact: Daniel Vetter
  289. Create a virtual KMS driver for testing (vkms)
  290. ----------------------------------------------
  291. With all the latest helpers it should be fairly simple to create a virtual KMS
  292. driver useful for testing, or for running X or similar on headless machines
  293. (to be able to still use the GPU). This would be similar to vgem, but aimed at
  294. the modeset side.
  295. Once the basics are there there's tons of possibilities to extend it.
  296. Contact: Daniel Vetter
  297. Driver Specific
  298. ===============
  299. tinydrm
  300. -------
  301. Tinydrm is the helper driver for really simple fb drivers. The goal is to make
  302. those drivers as simple as possible, so lots of room for refactoring:
  303. - backlight helpers, probably best to put them into a new drm_backlight.c.
  304. This is because drivers/video is de-facto unmaintained. We could also
  305. move drivers/video/backlight to drivers/gpu/backlight and take it all
  306. over within drm-misc, but that's more work. Backlight helpers require a fair
  307. bit of reworking and refactoring. A simple example is the enabling of a backlight.
  308. Tinydrm has helpers for this. It would be good if other drivers can also use the
  309. helper. However, there are various cases we need to consider i.e different
  310. drivers seem to have different ways of enabling/disabling a backlight.
  311. We also need to consider the backlight drivers (like gpio_backlight). The situation
  312. is further complicated by the fact that the backlight is tied to fbdev
  313. via fb_notifier_callback() which has complicated logic. For further details, refer
  314. to the following discussion thread:
  315. https://groups.google.com/forum/#!topic/outreachy-kernel/8rBe30lwtdA
  316. - spi helpers, probably best put into spi core/helper code. Thierry said
  317. the spi maintainer is fast&reactive, so shouldn't be a big issue.
  318. - extract the mipi-dbi helper (well, the non-tinydrm specific parts at
  319. least) into a separate helper, like we have for mipi-dsi already. Or follow
  320. one of the ideas for having a shared dsi/dbi helper, abstracting away the
  321. transport details more.
  322. - tinydrm_gem_cma_prime_import_sg_table should probably go into the cma
  323. helpers, as a _vmapped variant (since not every driver needs the vmap).
  324. And tinydrm_gem_cma_free_object could the be merged into
  325. drm_gem_cma_free_object().
  326. - tinydrm_fb_create we could move into drm_simple_pipe, only need to add
  327. the fb_create hook to drm_simple_pipe_funcs, which would again simplify a
  328. bunch of things (since it gives you a one-stop vfunc for simple drivers).
  329. - Quick aside: The unregister devm stuff is kinda getting the lifetimes of
  330. a drm_device wrong. Doesn't matter, since everyone else gets it wrong
  331. too :-)
  332. - also rework the drm_framebuffer_funcs->dirty hook wire-up, see above.
  333. Contact: Noralf Trønnes, Daniel Vetter
  334. AMD DC Display Driver
  335. ---------------------
  336. AMD DC is the display driver for AMD devices starting with Vega. There has been
  337. a bunch of progress cleaning it up but there's still plenty of work to be done.
  338. See drivers/gpu/drm/amd/display/TODO for tasks.
  339. Contact: Harry Wentland, Alex Deucher
  340. i915
  341. ----
  342. - Our early/late pm callbacks could be removed in favour of using
  343. device_link_add to model the dependency between i915 and snd_had. See
  344. https://dri.freedesktop.org/docs/drm/driver-api/device_link.html
  345. Outside DRM
  346. ===========