Commit 5f7b25f7 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
devices:

(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 connecters of devices in platform dev driver, before use the
first platform device as a fallback. Get the amount of the device's
connectors by referring to the check_outputs() function in modesetting
driver.

Buglink: xorg/xserver#1023

Signed-off-by: default avatarJian-Hong Pan <jian-hong@endlessm.com>
parent 495bf63a
Pipeline #181593 passed with stages
in 3 minutes and 58 seconds
......@@ -746,16 +746,32 @@ void xf86platformVTProbe(void)
void xf86platformPrimary(void)
{
/* use the first platform device as a fallback */
if (primaryBus.type == BUS_NONE) {
xf86Msg(X_INFO, "no primary bus or device found\n");
struct xf86_platform_device *dev;
int i;
if (xf86_num_platform_devices > 0) {
primaryBus.id.plat = &xf86_platform_devices[0];
primaryBus.type = BUS_PLATFORM;
/* only deal when no primary device has been detected */
if (primaryBus.type != BUS_NONE)
return;
xf86Msg(X_NONE, "\tfalling back to %s\n", primaryBus.id.plat->attribs->syspath);
/* set it to the first platform device detected with output connector capabilities */
for (i = 0; i < xf86_num_platform_devices; i++) {
dev = &xf86_platform_devices[i];
if (xf86_platform_device_odev_attributes(dev)->num_connectors > 0) {
primaryBus.id.plat = dev;
primaryBus.type = BUS_PLATFORM;
return;
}
}
/* finally, use the first platform device as a fallback */
xf86Msg(X_INFO, "no primary bus or device found\n");
if (xf86_num_platform_devices > 0) {
primaryBus.id.plat = &xf86_platform_devices[0];
primaryBus.type = BUS_PLATFORM;
xf86Msg(X_NONE, "\tfalling back to %s\n", primaryBus.id.plat->attribs->syspath);
}
}
#endif
......@@ -5,6 +5,7 @@
#ifdef XSERVER_PLATFORM_BUS
#include <xf86drm.h>
#include <xf86drmMode.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
......@@ -20,6 +21,22 @@
#include "hotplug.h"
#include "systemd-logind.h"
static int
CountConnectors(int fd)
{
int connectors = 0;
drmModeResPtr res;
res = drmModeGetResources(fd);
if (!res)
return 0;
connectors = res->count_connectors;
drmModeFreeResources(res);
return connectors;
}
static Bool
get_drm_info(struct OdevAttributes *attribs, char *path, int delayed_index)
{
......@@ -66,6 +83,10 @@ get_drm_info(struct OdevAttributes *attribs, char *path, int delayed_index)
xf86_platform_odev_attributes(delayed_index)->driver = XNFstrdup(v->name);
drmFreeVersion(v);
xf86_platform_odev_attributes(delayed_index)->num_connectors = CountConnectors(fd);
xf86DrvMsg(-1, X_DEBUG, "%s has %d connectors\n",
path, xf86_platform_odev_attributes(delayed_index)->num_connectors);
out:
if (!server_fd)
close(fd);
......
......@@ -58,6 +58,9 @@ struct OdevAttributes {
/* kernel driver name */
char *driver;
/* Amount of display connectors */
int num_connectors;
};
/* Note starting with xserver 1.16 this function never fails */
......
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