7

I have an embedded process that renders to a screen directly using DRM & KMS APIs. It's running on a minimal Yocto distribution (no desktop or Wayland). I would like to render to a second screen that is attached to the same GPU from another process. The first process opens '/dev/dri/card0' and becomes the de-facto DRM master and it can do drmModeSetCrtc & drmModePageFlip on the primary screen to display the framebuffer. However, if I call drmDropMaster it can't do the page flip anymore. Therefore the second process cannot become the DRM master and render to the other display using the same technique.

There's plenty of examples on how to render to one screen using the Direct Rendering Manager (DRM) and Kernel Mode Setting (KMS), but I found none that can render to a second screen from another process.

I would like to not have a master if possible once the display mode is set, but the page flip is also a restricted API. If this cannot be achieved, maybe an example on how to grant the second process permission using drmAuthMagic?

Fritz
  • 141
  • 8
  • How is this related to OpenGL? I mean, if you use Mesa, then some glX context functions will help you attaching each Display to a context. – Ripi2 Dec 11 '18 at 00:31
  • @Ripi2: GLX assumes X11, which is not running here. And for most pure KMS+GBM environments, OpenGL is the de-facto standard graphics API being used. So while not entirely OpenGL related, it's close enough, that readers of the opengl tag might know the answer. – datenwolf Dec 11 '18 at 10:02
  • @Fritz: Ever looked into DRM leases? https://www.x.org/wiki/Events/XDC2017/packard_drm_lease.pdf – https://keithp.com/blogs/DRM-lease/ - https://keithp.com/blogs/DRM-lease-2/ – https://keithp.com/blogs/DRM-lease-3/ – https://keithp.com/blogs/DRM-lease-4/ – datenwolf Dec 11 '18 at 10:03
  • @Ripi2: There is no tags for DRM or KMS. OpenGL is what I ultimately want to use once I get passed the kernel security. I was hoping there might be a kernel patch that bypassed it completely. – Fritz Dec 11 '18 at 14:00
  • @datenwolf: Thanks for the interesting read. I didn't think of it, but VR is very closely related to my application in the sense that latency is a main concern and it needs to drive external displays. I realize that my question is very specific and there might not be an easy solution. – Fritz Dec 11 '18 at 14:10

1 Answers1

7

It isn't possible to do a page flip without being the DRM master. The IOCTL is protected in drm_ioctl.c:

DRM_IOCTL_DEF(DRM_IOCTL_MODE_PAGE_FLIP, drm_mode_page_flip_ioctl, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED)
DRM_IOCTL_DEF(DRM_IOCTL_SET_MASTER, drm_setmaster_ioctl, DRM_ROOT_ONLY),
DRM_IOCTL_DEF(DRM_IOCTL_DROP_MASTER, drm_dropmaster_ioctl, DRM_ROOT_ONLY),

So I decided to put the flip into a critical section where the application calls drmSetMaster, schedules the flip, and calls drmDropMaster. It's heavy handed and both processes need to be root, but it works well enough for an embedded platform. The process has to authorize itself however using drmGetMagic and drmAuthMagic in order for it to be able to render while it isn't the master and to grab mastership again. I do this when it first becomes master and does the mode set.

genpfault
  • 51,148
  • 11
  • 85
  • 139
Fritz
  • 141
  • 8
  • I think you can run that without being a root. At least on my Linux, the card0/card1 files allow access to members of `video` security group, and `renderD128` file allows permissions to `render` security group. Add yourself to these groups, and it should work without root. – Soonts Sep 01 '21 at 12:13