an introduction to the linux drm subsystem · i embedded linux engineer and trainer at bootlin i...

32
Kernel Recipes 2017 An introduction to the Linux DRM subsystem Maxime Ripard [email protected] Copyright 2004-2018, Bootlin. Creative Commons BY-SA 3.0 license. Corrections, suggestions, contributions and translations are welcome! embedded Linux and kernel engineering - Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 1/1

Upload: others

Post on 07-Apr-2020

31 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: An introduction to the Linux DRM subsystem · I Embedded Linux engineer and trainer at Bootlin I Embedded Linux development: kernel and driver development, system integration, boot

Kernel Recipes 2017

An introduction to theLinux DRM subsystemMaxime [email protected]

© Copyright 2004-2018, Bootlin.

Creative Commons BY-SA 3.0 license.

Corrections, suggestions, contributions and translations are welcome!

embedded Linux and kernel engineering

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 1/1

Page 2: An introduction to the Linux DRM subsystem · I Embedded Linux engineer and trainer at Bootlin I Embedded Linux development: kernel and driver development, system integration, boot

Maxime Ripard

I Embedded Linux engineer and trainer at BootlinI Embedded Linux development: kernel and driver development, system integration,

boot time and power consumption optimization, consulting, etc.I Embedded Linux training, Linux driver development training and Android system

development training, with materials freely available under a Creative Commonslicense.

I http://bootlin.com

I ContributionsI Co-maintainer for the sunXi SoCs from AllwinnerI Contributor to a couple of other open-source projects, Buildroot, U-Boot, Barebox

I Living in Toulouse, south west of France

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 2/1

Page 3: An introduction to the Linux DRM subsystem · I Embedded Linux engineer and trainer at Bootlin I Embedded Linux development: kernel and driver development, system integration, boot

An introduction to the Linux DRM subsystem

Introduction

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 3/1

Page 4: An introduction to the Linux DRM subsystem · I Embedded Linux engineer and trainer at Bootlin I Embedded Linux development: kernel and driver development, system integration, boot

A long long time ago, in a galaxy (not so) far, far away

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 4/1

Page 5: An introduction to the Linux DRM subsystem · I Embedded Linux engineer and trainer at Bootlin I Embedded Linux development: kernel and driver development, system integration, boot

Framebuffers

I Display hardware was dead simple...

I .. and so was the API to drive it.

I Introducing... fbdev!I Allows for three things:

I Mode-SettingI Accessing the (only) bufferI Optional 2d acceleration: draw, copy, etc.I And access to the device registers...

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 5/1

Page 6: An introduction to the Linux DRM subsystem · I Embedded Linux engineer and trainer at Bootlin I Embedded Linux development: kernel and driver development, system integration, boot

That 90’s show

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 6/1

Page 7: An introduction to the Linux DRM subsystem · I Embedded Linux engineer and trainer at Bootlin I Embedded Linux development: kernel and driver development, system integration, boot

Back to the future

I Two different trendsI Embedded devices starting to show up, with their low power needs ⇒ Display

engines need to accelerate more thingsI Desktop displays getting more and more fancy in order to play Quake in 4k VR ⇒

Bigger and bigger GPUs

I Led to two different outcomes:I Interface to drive GPU devices through the kernel: DRMI Hacks piling on in order to fit embedded use-cases: omapdss, pxafb

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 7/1

Page 8: An introduction to the Linux DRM subsystem · I Embedded Linux engineer and trainer at Bootlin I Embedded Linux development: kernel and driver development, system integration, boot

Composition Evolved

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 8/1

Page 9: An introduction to the Linux DRM subsystem · I Embedded Linux engineer and trainer at Bootlin I Embedded Linux development: kernel and driver development, system integration, boot

The droid you’re looking at

Sean Paul and Zach Reizner - Google - XDC2016

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 9/1

Page 10: An introduction to the Linux DRM subsystem · I Embedded Linux engineer and trainer at Bootlin I Embedded Linux development: kernel and driver development, system integration, boot

Can I talk to the manager?

I DRM was initially introduced to deal with the GPU’s needI Initialize the card, load its firmware, etc.I Share the GPU command queue between multiple applicationsI Manage the memory (allocation, access)I But not modesetting!

I All the modesetting was in the userspace, especially in X

I Race between rendering and modesetting

I Only one graphical application that needed to remain there all the time

I (Lack of) Abstraction!

I Introduction of the Kernel Mode-Setting (KMS) to move the modesetting backinto the kernel

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 10/1

Page 11: An introduction to the Linux DRM subsystem · I Embedded Linux engineer and trainer at Bootlin I Embedded Linux development: kernel and driver development, system integration, boot

Kill it with fire!

I Now, fbdev could be implemented on top of KMS...

I ... Or removed entirely

I Call for deprecation in 2012 (Hi Laurent!)

I Last fbdev driver merged in 2014

I First ARM DRM driver: exynos in 2011

I Followed: arm, armada, atmel-hclcdc, fsl-dcu, hisilicon, imx, mediatek, meson,msm, mxsfb, omapdrm, pl111, rcar-du, rockchip, shmobile, sti, stm, sun4i, tegra,tve200, etc...

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 11/1

Page 12: An introduction to the Linux DRM subsystem · I Embedded Linux engineer and trainer at Bootlin I Embedded Linux development: kernel and driver development, system integration, boot

Two nodes to go please

I Initially, DRM was created for devices that were both displaying and rendering(your traditionnal PC graphics card).

I On embedded devices, it’s never really been like thatI the GPU is discrete and comes from a third partyI the display engine is usually designed by the SoC vendor

I DRM and KMS APIs requiring the same level of privilege, with one master, andwere both exposed on the same device file

I Creation of render nodes

I Also useful for things like GPGPU, off-screen rendering, more flexible accesscontrol

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 12/1

Page 13: An introduction to the Linux DRM subsystem · I Embedded Linux engineer and trainer at Bootlin I Embedded Linux development: kernel and driver development, system integration, boot

An introduction to the Linux DRM subsystem

DRM/KMS

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 13/1

Page 14: An introduction to the Linux DRM subsystem · I Embedded Linux engineer and trainer at Bootlin I Embedded Linux development: kernel and driver development, system integration, boot

The pixels must flow

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 14/1

Page 15: An introduction to the Linux DRM subsystem · I Embedded Linux engineer and trainer at Bootlin I Embedded Linux development: kernel and driver development, system integration, boot

KMS components

I PlanesI Image sourceI Associated with one (or more!) framebuffersI Holds a resized / cropped version of that framebuffer

I CRTCsI Take the planes, and does the compositionI Contains the display mode and parameters

I EncodersI Take the raw data from the CRTC and convert it to a particular format

I ConnectorsI Outputs the encoded data to an external displayI Handles hotplug eventsI Reads EDIDs

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 15/1

Page 16: An introduction to the Linux DRM subsystem · I Embedded Linux engineer and trainer at Bootlin I Embedded Linux development: kernel and driver development, system integration, boot

Page flipping

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 16/1

Page 17: An introduction to the Linux DRM subsystem · I Embedded Linux engineer and trainer at Bootlin I Embedded Linux development: kernel and driver development, system integration, boot

KMS components

I PlanesI Image sourceI Associated with one (or more!) framebuffersI Holds a resized / cropped version of that framebuffer

I CRTCsI Take the planes, and does the compositionI Contains the display mode and parameters

I EncodersI Take the raw data from the CRTC and convert it to a particular format

I ConnectorsI Outputs the encoded data to an external displayI Handles hotplug eventsI Reads EDIDs

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 17/1

Page 18: An introduction to the Linux DRM subsystem · I Embedded Linux engineer and trainer at Bootlin I Embedded Linux development: kernel and driver development, system integration, boot

KMS components

I PlanesI Image sourceI Associated with one (or more!) framebuffersI Holds a resized / cropped version of that framebuffer

I CRTCsI Take the planes, and does the compositionI Contains the display mode and parameters

I EncodersI Take the raw data from the CRTC and convert it to a particular format

I ConnectorsI Outputs the encoded data to an external displayI Handles hotplug eventsI Reads EDIDs

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 17/1

Page 19: An introduction to the Linux DRM subsystem · I Embedded Linux engineer and trainer at Bootlin I Embedded Linux development: kernel and driver development, system integration, boot

KMS components

I PlanesI Image sourceI Associated with one (or more!) framebuffersI Holds a resized / cropped version of that framebuffer

I CRTCsI Take the planes, and does the compositionI Contains the display mode and parameters

I EncodersI Take the raw data from the CRTC and convert it to a particular format

I ConnectorsI Outputs the encoded data to an external displayI Handles hotplug eventsI Reads EDIDs

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 17/1

Page 20: An introduction to the Linux DRM subsystem · I Embedded Linux engineer and trainer at Bootlin I Embedded Linux development: kernel and driver development, system integration, boot

Allwinner display pipeline

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 18/1

Page 21: An introduction to the Linux DRM subsystem · I Embedded Linux engineer and trainer at Bootlin I Embedded Linux development: kernel and driver development, system integration, boot

DRM vs SoC pipeline

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 19/1

Page 22: An introduction to the Linux DRM subsystem · I Embedded Linux engineer and trainer at Bootlin I Embedded Linux development: kernel and driver development, system integration, boot

DRM Stack: KMS

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 20/1

Page 23: An introduction to the Linux DRM subsystem · I Embedded Linux engineer and trainer at Bootlin I Embedded Linux development: kernel and driver development, system integration, boot

DRM Stack: GEM

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 21/1

Page 24: An introduction to the Linux DRM subsystem · I Embedded Linux engineer and trainer at Bootlin I Embedded Linux development: kernel and driver development, system integration, boot

DRM Stack: CMA

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 22/1

Page 25: An introduction to the Linux DRM subsystem · I Embedded Linux engineer and trainer at Bootlin I Embedded Linux development: kernel and driver development, system integration, boot

DRM Stack: PRIME

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 23/1

Page 26: An introduction to the Linux DRM subsystem · I Embedded Linux engineer and trainer at Bootlin I Embedded Linux development: kernel and driver development, system integration, boot

DRM Stack: GPUs

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 24/1

Page 27: An introduction to the Linux DRM subsystem · I Embedded Linux engineer and trainer at Bootlin I Embedded Linux development: kernel and driver development, system integration, boot

An introduction to the Linux DRM subsystem

Vendor solutions...

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 25/1

Page 28: An introduction to the Linux DRM subsystem · I Embedded Linux engineer and trainer at Bootlin I Embedded Linux development: kernel and driver development, system integration, boot

Solutions

I The GPU found in most Allwinner SoCs is the Mali-400 from ARM (with avariable number of cores)

I There are two options to support that GPU:I Lima

I Reversed engineered proof-of-conceptI Triggered the reverse engineering effort of the GPUs (freedreno, etnaviv, etc.)I Development (close to?) stopped three years ago, and then resumed a couple of

monthes ago

I ARM-Provided supportI FeaturefulI Two parts: GPL kernel driver and proprietary OpenGL ES implementation

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 26/1

Page 29: An introduction to the Linux DRM subsystem · I Embedded Linux engineer and trainer at Bootlin I Embedded Linux development: kernel and driver development, system integration, boot

DRM Stack: GPU

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 27/1

Page 30: An introduction to the Linux DRM subsystem · I Embedded Linux engineer and trainer at Bootlin I Embedded Linux development: kernel and driver development, system integration, boot

Development

I Everything is provided by ARM on their website (if you’re lucky)

I On the userspace side, you just need to put the library they provided on yoursystem

I On the driver side, you need to create a platform glue that will deal with:I Memory mappingI InterruptsI ClocksI Reset linesI Power DomainsI Basically everything needed for the GPU to operate properly on your SoC

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 28/1

Page 31: An introduction to the Linux DRM subsystem · I Embedded Linux engineer and trainer at Bootlin I Embedded Linux development: kernel and driver development, system integration, boot

X11 integration

I We need a DDX (Device Dependent X) driver

I xf86-video-modesetting is working on top of KMS and GBM (MESA-defineduser-space API to allocate buffers)

I ARM developped xf86-video-armsoc for SoC using a 3rd party GPU (Mali,PowerVR, Vivante, etc.)

I Relies on KMS for the display configuration, driver-specific ioctl for bufferallocations and vendor-provided OpenGL ES implementation

I Just have to write a small glue to use your driver allocator, and give some hints toX about what your hardware support (hw cursor, vblank, etc.)

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 29/1

Page 32: An introduction to the Linux DRM subsystem · I Embedded Linux engineer and trainer at Bootlin I Embedded Linux development: kernel and driver development, system integration, boot

Questions? Suggestions? Comments?

Maxime [email protected]

Slides under CC-BY-SA 3.0http://bootlin.com/pub/conferences/2017/kr/ripard-drm

- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 30/1