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

xfree86: Detect the primary device by checking outputs

Originally, 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 the correct one, because it has no output.

This patch adds a new way to set the primary device by detecting the
output device. It reuses the probe_hw() and related functions in
modesettings driver. So, it also moves them to output.c/.h as the new
source/header files to make the code more maintainable.

Buglink: xorg/xserver#1023

Signed-off-by: default avatarJian-Hong Pan <jian-hong@endlessm.com>
parent ddb86e94
Pipeline #179096 failed with stages
in 2 minutes and 23 seconds
......@@ -33,6 +33,8 @@ xf86DefModeSet.c: $(srcdir)/modeline2c.awk $(MODEDEFSOURCES)
$(AM_V_GEN)cat $(MODEDEFSOURCES) | LC_ALL=C $(AWK) -f $(srcdir)/modeline2c.awk > $@
$(AM_V_GEN)echo >> $@
MODESETOUTPUT = $(srcdir)/../drivers/modesetting/output.c
BUILT_SOURCES = xf86DefModeSet.c
AM_LDFLAGS = -r
......@@ -43,7 +45,7 @@ libcommon_la_SOURCES = xf86Configure.c xf86Bus.c xf86Config.c \
xf86VidMode.c xf86fbman.c xf86cmap.c \
xf86Helper.c xf86PM.c xf86Xinput.c xisb.c \
xf86Mode.c xorgHelper.c xf86Extensions.h \
xf86Extensions.c $(XF86VMODESOURCES) \
xf86Extensions.c $(XF86VMODESOURCES) $(MODESETOUTPUT) \
$(XVSOURCES) $(BUSSOURCES) $(RANDRSOURCES)
nodist_libcommon_la_SOURCES = xf86DefModeSet.c
libcommon_la_LIBADD = $(top_builddir)/config/libconfig.la
......@@ -53,7 +55,7 @@ AM_CPPFLAGS = $(XORG_INCS) -I$(srcdir)/../ddc -I$(srcdir)/../i2c \
-I$(srcdir)/../vbe -I$(srcdir)/../int10 \
-I$(srcdir)/../vgahw -I$(srcdir)/../dixmods/extmod \
-I$(srcdir)/../modes -I$(srcdir)/../ramdac -I$(srcdir)/../dri2 \
-I$(top_builddir)
-I$(srcdir)/../drivers/modesetting -I$(top_builddir)
sdk_HEADERS = compiler.h fourcc.h xf86.h xf86Module.h xf86Opt.h \
xf86PciInfo.h xf86Priv.h xf86Privstr.h \
......
......@@ -41,6 +41,7 @@
#include "systemd-logind.h"
#include "loaderProcs.h"
#include "output.h"
#include "xf86.h"
#include "xf86_OSproc.h"
#include "xf86Priv.h"
......@@ -347,6 +348,21 @@ 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];
path = xf86_platform_device_odev_attributes(dev)->path;
if (probe_hw(path, dev)) {
primaryBus.type = BUS_PLATFORM;
primaryBus.id.plat = dev;
return 0;
}
}
return 0;
}
......
......@@ -26,6 +26,7 @@
#include "hotplug.h"
#include "xf86MatchDrivers.h"
#include "xf86str.h"
struct xf86_platform_device {
struct OdevAttributes *attribs;
......
......@@ -31,6 +31,7 @@ AM_CFLAGS = $(DIX_CFLAGS) $(XORG_CFLAGS) $(LIBDRM_CFLAGS) $(UDEV_CFLAGS) $(CWARN
AM_CPPFLAGS = \
$(XORG_INCS) \
-I$(top_srcdir)/glamor \
-I$(srcdir)/../../common \
-I$(srcdir)/../../ddc \
-I$(srcdir)/../../dri2 \
-I$(srcdir)/../../i2c \
......@@ -52,6 +53,7 @@ modesetting_drv_la_SOURCES = \
drmmode_display.h \
dumb_bo.c \
dumb_bo.h \
output.c \
present.c \
vblank.c \
pageflip.c \
......
......@@ -34,10 +34,9 @@
#endif
#include <unistd.h>
#include <fcntl.h>
#include "xf86.h"
#include "xf86Priv.h"
#include "xf86_OSproc.h"
#include "xf86Priv.h"
#include "compiler.h"
#include "xf86Pci.h"
#include "mipointer.h"
......@@ -60,6 +59,7 @@
#include <pciaccess.h>
#endif
#include "driver.h"
#include "output.h"
static void AdjustFrame(ScrnInfoPtr pScrn, int x, int y);
static Bool CloseScreen(ScreenPtr pScreen);
......@@ -195,88 +195,6 @@ modesettingEntPtr ms_ent_priv(ScrnInfoPtr scrn)
return pPriv->ptr;
}
static int
get_passed_fd(void)
{
if (xf86DRMMasterFd >= 0) {
xf86DrvMsg(-1, X_INFO, "Using passed DRM master file descriptor %d\n", xf86DRMMasterFd);
return dup(xf86DRMMasterFd);
}
return -1;
}
static int
open_hw(const char *dev)
{
int fd;
if ((fd = get_passed_fd()) != -1)
return fd;
if (dev)
fd = open(dev, O_RDWR | O_CLOEXEC, 0);
else {
dev = getenv("KMSDEVICE");
if ((NULL == dev) || ((fd = open(dev, O_RDWR | O_CLOEXEC, 0)) == -1)) {
dev = "/dev/dri/card0";
fd = open(dev, O_RDWR | O_CLOEXEC, 0);
}
}
if (fd == -1)
xf86DrvMsg(-1, X_ERROR, "open %s: %s\n", dev, strerror(errno));
return fd;
}
static int
check_outputs(int fd, int *count)
{
drmModeResPtr res = drmModeGetResources(fd);
int ret;
if (!res)
return FALSE;
if (count)
*count = res->count_connectors;
ret = res->count_connectors > 0;
#if defined(GLAMOR_HAS_GBM_LINEAR)
if (ret == FALSE) {
uint64_t value = 0;
if (drmGetCap(fd, DRM_CAP_PRIME, &value) == 0 &&
(value & DRM_PRIME_CAP_EXPORT))
ret = TRUE;
}
#endif
drmModeFreeResources(res);
return ret;
}
static Bool
probe_hw(const char *dev, struct xf86_platform_device *platform_dev)
{
int fd;
#ifdef XF86_PDEV_SERVER_FD
if (platform_dev && (platform_dev->flags & XF86_PDEV_SERVER_FD)) {
fd = xf86_platform_device_odev_attributes(platform_dev)->fd;
if (fd == -1)
return FALSE;
return check_outputs(fd, NULL);
}
#endif
fd = open_hw(dev);
if (fd != -1) {
int ret = check_outputs(fd, NULL);
close(fd);
return ret;
}
return FALSE;
}
static char *
ms_DRICreatePCIBusID(const struct pci_device *dev)
{
......
/*
* Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
* Copyright 2011 Dave Airlie
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
* IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*
* Original Author: Alan Hourihane <alanh@tungstengraphics.com>
* Rewrite: Dave Airlie <airlied@redhat.com>
*
*/
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <xf86drm.h>
#include <xf86drmMode.h>
#include "xf86.h"
#include "xf86Priv.h"
#include "output.h"
int get_passed_fd(void)
{
if (xf86DRMMasterFd >= 0) {
xf86DrvMsg(-1, X_INFO, "Using passed DRM master file descriptor %d\n", xf86DRMMasterFd);
return dup(xf86DRMMasterFd);
}
return -1;
}
int open_hw(const char *dev)
{
int fd;
if ((fd = get_passed_fd()) != -1)
return fd;
if (dev)
fd = open(dev, O_RDWR | O_CLOEXEC, 0);
else {
dev = getenv("KMSDEVICE");
if ((NULL == dev) || ((fd = open(dev, O_RDWR | O_CLOEXEC, 0)) == -1)) {
dev = "/dev/dri/card0";
fd = open(dev, O_RDWR | O_CLOEXEC, 0);
}
}
if (fd == -1)
xf86DrvMsg(-1, X_ERROR, "open %s: %s\n", dev, strerror(errno));
return fd;
}
int check_outputs(int fd, int *count)
{
drmModeResPtr res = drmModeGetResources(fd);
int ret;
if (!res)
return FALSE;
if (count)
*count = res->count_connectors;
ret = res->count_connectors > 0;
#if defined(GLAMOR_HAS_GBM_LINEAR)
if (ret == FALSE) {
uint64_t value = 0;
if (drmGetCap(fd, DRM_CAP_PRIME, &value) == 0 &&
(value & DRM_PRIME_CAP_EXPORT))
ret = TRUE;
}
#endif
drmModeFreeResources(res);
return ret;
}
Bool probe_hw(const char *dev, struct xf86_platform_device *platform_dev)
{
int fd;
#ifdef XF86_PDEV_SERVER_FD
if (platform_dev && (platform_dev->flags & XF86_PDEV_SERVER_FD)) {
fd = xf86_platform_device_odev_attributes(platform_dev)->fd;
if (fd == -1)
return FALSE;
return check_outputs(fd, NULL);
}
#endif
fd = open_hw(dev);
if (fd != -1) {
int ret = check_outputs(fd, NULL);
close(fd);
return ret;
}
return FALSE;
}
/*
* Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
* Copyright 2011 Dave Airlie
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
* IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*
* Original Author: Alan Hourihane <alanh@tungstengraphics.com>
* Rewrite: Dave Airlie <airlied@redhat.com>
*
*/
#include "xf86platformBus.h"
int get_passed_fd(void);
int open_hw(const char *dev);
int check_outputs(int fd, int *count);
Bool probe_hw(const char *dev, struct xf86_platform_device *platform_dev);
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