Commit b794865d authored by Jian-Hong Pan's avatar Jian-Hong Pan
Browse files

xfree86: Detect the primary device by checking outputs

Before this patch, X server detects/sets the primary device by:
1. The "PrimaryGPU" option in extra X configuration
2. pci_device_is_boot_vga() for PCI devices
3. Set the first (0 index) device as the primary device, if it is not
   found yet.

However, the other display controllers like Amlogic's meson cannot be
detected as the primary device by pci_device_is_boot_vga(). Thus, it has
to set the extra X configuration for the "PrimaryGPU" option.
Otherwise, X server will set the first (0 index) device as the primary
device. But it may not be the correct one, because it has no output.
For example, Amlogic puts the GPU and display controller as different

(II) xfree86: Adding drm device (/dev/dri/card0)
(II) Platform probe for /sys/devices/platform/soc/d0000000.apb/d00c0000.gpu/drm/card0
(II) xfree86: Adding drm device (/dev/dri/card1)
(II) Platform probe for /sys/devices/platform/soc/d0100000.vpu/drm/card1

This patch adds a new way to set the primary device by detecting the
output of devices. It refers to the probe_hw() and related functions in
modesettings driver.

Buglink: xorg/xserver#1023

Signed-off-by: default avatarJian-Hong Pan <>
parent ddb86e94
Pipeline #180326 passed with stages
in 6 minutes and 4 seconds
......@@ -36,6 +36,7 @@
#include <pciaccess.h>
#include <fcntl.h>
#include <unistd.h>
#include <xf86drmMode.h>
#include "os.h"
#include "hotplug.h"
#include "systemd-logind.h"
......@@ -272,6 +273,37 @@ xf86PlatformMatchDriver(XF86MatchedDrivers *md)
static int
CheckOutput(struct xf86_platform_device *dev)
int connectors = 0;
drmModeResPtr res;
char *path;
int fd;
path = xf86_platform_device_odev_attributes(dev)->path;
if (!path)
return 0;
fd = open(path, O_RDWR | O_CLOEXEC, 0);
if (fd == -1) {
xf86DrvMsg(-1, X_ERROR, "open %s: %s\n", path, strerror(errno));
return 0;
res = drmModeGetResources(fd);
if (!res)
goto out;
connectors = res->count_connectors;
xf86DrvMsg(-1, X_DEBUG, "%s has %d connectors\n", path, connectors);
return connectors;
......@@ -347,6 +379,20 @@ xf86platformProbe(void)
/* Tnen check for the output of devices, if the primary is not set yet */
if (primaryBus.type != BUS_NONE)
return 0;
for (i = 0; i < xf86_num_platform_devices; i++) {
struct xf86_platform_device *dev = &xf86_platform_devices[i];
if (CheckOutput(dev) > 0) {
primaryBus.type = BUS_PLATFORM; = dev;
return 0;
return 0;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment