create-multi-session-built-in-config.patch revision 1386
1386N/Adiff --git a/hw/xfree86/common/xf86AutoConfig.c b/hw/xfree86/common/xf86AutoConfig.c
1386N/Aindex cc8976f..7a43694 100644
1386N/A--- a/hw/xfree86/common/xf86AutoConfig.c
1386N/A+++ b/hw/xfree86/common/xf86AutoConfig.c
1386N/A@@ -1,8 +1,8 @@
1386N/A /*
1386N/A * Copyright 2003 by David H. Dawes.
1386N/A * Copyright 2003 by X-Oz Technologies.
1386N/A+ * Copyright (c) 2013 Oracle and/or its affiliates.
1386N/A * All rights reserved.
1386N/A- * Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved.
1386N/A *
1386N/A * Permission is hereby granted, free of charge, to any person obtaining a
1386N/A * copy of this software and associated documentation files (the "Software"),
1386N/A@@ -49,6 +49,9 @@
1386N/A #ifdef sun
1386N/A #include <sys/visual_io.h>
1386N/A #include <ctype.h>
1386N/A+#if (defined(__sparc__) || defined(__sparc))
1386N/A+static Bool MultiSessionConfig (void);
1386N/A+#endif
1386N/A #endif
1386N/A
1386N/A /* Sections for the default built-in configuration. */
1386N/A@@ -169,6 +172,10 @@ xf86AutoConfig(void)
1386N/A char buf[1024];
1386N/A ConfigStatus ret;
1386N/A
1386N/A+#if ((defined(__sparc__) || defined(__sparc)) && defined (sun))
1386N/A+ if (!MultiSessionConfig()) {
1386N/A+#endif
1386N/A+
1386N/A listPossibleVideoDrivers(deviceList, 20);
1386N/A
1386N/A for (p = deviceList; *p; p++) {
1386N/A@@ -196,6 +203,9 @@ xf86AutoConfig(void)
1386N/A for (p = deviceList; *p; p++) {
1386N/A free(*p);
1386N/A }
1386N/A+#if ((defined(__sparc__) || defined(__sparc)) && defined (sun))
1386N/A+ }
1386N/A+#endif
1386N/A
1386N/A xf86MsgVerb(X_DEFAULT, 0,
1386N/A "Using default built-in configuration (%d lines)\n",
1386N/A@@ -442,3 +452,173 @@ autoConfigDevice(GDevPtr preconf_device)
1386N/A
1386N/A return ptr;
1386N/A }
1386N/A+
1386N/A+#if ((defined(__sparc__) || defined(__sparc)) && defined (sun))
1386N/A+#include <libdevinfo.h>
1386N/A+#include <xorg/xf86Pci.h>
1386N/A+#include "pciaccess.h"
1386N/A+#include <sys/utsname.h>
1386N/A+
1386N/A+#define MAX_DEV 16
1386N/A+
1386N/A+#define IS_VGA(c) \
1386N/A+ (((c) & 0x00ffff00) \
1386N/A+ == ((PCI_CLASS_DISPLAY << 16) | (PCI_SUBCLASS_DISPLAY_VGA << 8)))
1386N/A+
1386N/A+#define BUILTIN_MULTI_SERVERFLAGS_OPT1 \
1386N/A+ "\tOption\t\"DefaultServerLayout\"\t\"Xsession0\"\n"
1386N/A+
1386N/A+#define BUILTIN_MULTI_SECTION_POST \
1386N/A+ "EndSection\n\n"
1386N/A+
1386N/A+#define BUILTIN_MULTI_SERVERFLAGS_OPT2 \
1386N/A+ "\tOption\t\"AutoAddDevices\"\t\"true\"\n"
1386N/A+
1386N/A+#define BUILTIN_MULTI_SERVERFLAGS_SECTION \
1386N/A+ "Section \"ServerFlags\"\n" \
1386N/A+ BUILTIN_MULTI_SERVERFLAGS_OPT1 \
1386N/A+ BUILTIN_MULTI_SERVERFLAGS_OPT2 \
1386N/A+ BUILTIN_MULTI_SECTION_POST
1386N/A+
1386N/A+#define BUILTIN_MULTI_LAYOUT_SECTION_PRE \
1386N/A+ "Section \"ServerLayout\"\n" \
1386N/A+ "\tIdentifier\t\"Xsession%d\"\n"
1386N/A+
1386N/A+#define BUILTIN_MULTI_LAYOUT_SECTION_LINE \
1386N/A+ "\tScreen\t\t\"Screen%d\"\n"
1386N/A+
1386N/A+#define BUILTIN_MULTI_SCREEN_SECTION_PRE \
1386N/A+ "Section \"Screen\"\n" \
1386N/A+ "\tIdentifier\t\"Screen%d\"\n"
1386N/A+
1386N/A+#define BUILTIN_MULTI_SCREEN_SECTION_LINE \
1386N/A+ "\tDevice\t\t\"Card%d\"\n"
1386N/A+
1386N/A+#define BUILTIN_MULTI_DEVICE_SECTION_PRE \
1386N/A+ "Section \"Device\"\n" \
1386N/A+ "\tIdentifier\t\"Card%d\"\n"
1386N/A+
1386N/A+#define BUILTIN_MULTI_DEVICE_SECTION_LINE \
1386N/A+ "\tBusID\t\t\"%s\"\n\tDriver\t\t\"%s\"\n"
1386N/A+
1386N/A+static Bool
1386N/A+MultiSessionConfig (void)
1386N/A+{
1386N/A+ di_node_t node;
1386N/A+ struct pci_device_iterator * iter;
1386N/A+ struct pci_device * dev;
1386N/A+ typedef struct {
1386N/A+ char busid[64];
1386N/A+ char dev_path[PATH_MAX];
1386N/A+ } disp_dev_type;
1386N/A+ disp_dev_type disp_dev[MAX_DEV];
1386N/A+ int num = 0;
1386N/A+ char buf[1024];
1386N/A+ int i;
1386N/A+ struct utsname sys;
1386N/A+ struct sol_device_private {
1386N/A+ struct pci_device base;
1386N/A+ const char * device_string;
1386N/A+ };
1386N/A+#define DEV_PATH(dev) (((struct sol_device_private *) dev)->device_string)
1386N/A+
1386N/A+ if (uname(&sys) < 0) {
1386N/A+ xf86Msg(X_ERROR, "Error in uname call\n");
1386N/A+ return FALSE;
1386N/A+ }
1386N/A+
1386N/A+ if (strcmp(sys.machine, "sun4v"))
1386N/A+ return FALSE;
1386N/A+
1386N/A+ iter = pci_slot_match_iterator_create( NULL );
1386N/A+
1386N/A+ while ( (dev = pci_device_next( iter )) != NULL ) {
1386N/A+ if (IS_VGA(dev->device_class)) {
1386N/A+ if (num > MAX_DEV) {
1386N/A+ xf86Msg(X_ERROR, "Too many display devices: %d\n", num);
1386N/A+ return FALSE;
1386N/A+ }
1386N/A+
1386N/A+ memset(&disp_dev[num], 0, sizeof (disp_dev_type));
1386N/A+
1386N/A+ snprintf(disp_dev[num].busid, sizeof(disp_dev[num].busid),
1386N/A+ "PCI:%d@%d:%d:%d", dev->bus, dev->domain,
1386N/A+ dev->dev, dev->func);
1386N/A+
1386N/A+ strcpy(disp_dev[num].dev_path, "/devices");
1386N/A+ strncat(disp_dev[num].dev_path, DEV_PATH(dev),
1386N/A+ sizeof(disp_dev_type) - strlen("/devices"));
1386N/A+
1386N/A+ num++;
1386N/A+ }
1386N/A+ }
1386N/A+
1386N/A+ pci_iterator_destroy(iter);
1386N/A+
1386N/A+ /* Do not do multi-session configuration if dev number is 0 or 1 */
1386N/A+ if (num <= 1)
1386N/A+ return FALSE;
1386N/A+
1386N/A+ snprintf(buf, sizeof(buf), BUILTIN_MULTI_SERVERFLAGS_SECTION);
1386N/A+ AppendToConfig(buf);
1386N/A+
1386N/A+ for (i = 0; i < num; i++) {
1386N/A+ char drv[32];
1386N/A+
1386N/A+ snprintf(buf, sizeof(buf), BUILTIN_MULTI_LAYOUT_SECTION_PRE, i);
1386N/A+ AppendToConfig(buf);
1386N/A+ snprintf(buf, sizeof(buf), BUILTIN_MULTI_LAYOUT_SECTION_LINE, i);
1386N/A+ AppendToConfig(buf);
1386N/A+ snprintf(buf, sizeof(buf), BUILTIN_MULTI_SECTION_POST);
1386N/A+ AppendToConfig(buf);
1386N/A+
1386N/A+ snprintf(buf, sizeof(buf), BUILTIN_MULTI_SCREEN_SECTION_PRE, i);
1386N/A+ AppendToConfig(buf);
1386N/A+ snprintf(buf, sizeof(buf), BUILTIN_MULTI_SCREEN_SECTION_LINE, i);
1386N/A+ AppendToConfig(buf);
1386N/A+ snprintf(buf, sizeof(buf), BUILTIN_MULTI_SECTION_POST);
1386N/A+ AppendToConfig(buf);
1386N/A+
1386N/A+ snprintf(buf, sizeof(buf), BUILTIN_MULTI_DEVICE_SECTION_PRE, i);
1386N/A+ AppendToConfig(buf);
1386N/A+
1386N/A+ drv[0] = 0;
1386N/A+ if (disp_dev[i].dev_path) {
1386N/A+ int iret;
1386N/A+ int fd;
1386N/A+
1386N/A+ fd = open(disp_dev[i].dev_path, O_RDONLY);
1386N/A+ if (fd >= 0) {
1386N/A+ struct vis_identifier visid;
1386N/A+ const char *cp;
1386N/A+
1386N/A+ SYSCALL(iret = ioctl(fd, VIS_GETIDENTIFIER, &visid));
1386N/A+ close (fd);
1386N/A+
1386N/A+ if (iret >= 0) {
1386N/A+ if (strcmp(visid.name, "SUNWtext") != 0) {
1386N/A+ for (cp = visid.name; (*cp != '\0') && isupper((uchar_t)*cp); cp++);
1386N/A+ /* find end of all uppercase vendor section */
1386N/A+ if ((cp != visid.name) && (*cp != '\0'))
1386N/A+ strncpy (drv, cp, sizeof(drv));
1386N/A+ }
1386N/A+ }
1386N/A+ }
1386N/A+ }
1386N/A+
1386N/A+ if (drv[0] == 0) {
1386N/A+ xf86Msg(X_ERROR, "Can't find driver for session %d\n", i);
1386N/A+ FreeConfig();
1386N/A+ return FALSE;
1386N/A+ }
1386N/A+
1386N/A+ snprintf(buf, sizeof(buf), BUILTIN_MULTI_DEVICE_SECTION_LINE,
1386N/A+ disp_dev[i].busid, drv);
1386N/A+ AppendToConfig(buf);
1386N/A+ snprintf(buf, sizeof(buf), BUILTIN_MULTI_SECTION_POST);
1386N/A+ AppendToConfig(buf);
1386N/A+ }
1386N/A+
1386N/A+ return TRUE;
1386N/A+}
1386N/A+#endif