1411N/Adiff --git a/config/hal.c b/config/hal.c
1411N/Aindex 9de9dfc..f069dff 100644
1411N/A--- a/config/hal.c
1411N/A+++ b/config/hal.c
1411N/A@@ -1,6 +1,7 @@
1411N/A /*
1411N/A * Copyright © 2007 Daniel Stone
1411N/A * Copyright © 2007 Red Hat, Inc.
1411N/A+ * Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved.
1411N/A *
1411N/A * Permission is hereby granted, free of charge, to any person obtaining a
1411N/A * copy of this software and associated documentation files (the "Software"),
1411N/A@@ -39,6 +40,23 @@
1411N/A #include "config-backends.h"
1411N/A #include "os.h"
1411N/A
1411N/A+#if ((defined(__sparc__) || defined(__sparc)) && defined(SUNSOFT))
1411N/A+#include <sys/stat.h>
1411N/A+#include <unistd.h>
1411N/A+
1411N/A+#define MAX_DEVICES 4
1411N/A+
1411N/A+DeviceIntPtr added_devices[MAX_DEVICES];
1411N/A+int num_added_devices = 0;
1411N/A+Bool abort_on_fail_over = FALSE;
1411N/A+static Bool do_abort = FALSE;
1411N/A+
1411N/A+extern int num_total_disp_dev;
1411N/A+extern int num_session_disp_dev;
1411N/A+extern char disp_dev_path[PATH_MAX];
1411N/A+extern void GiveUp(int sig);
1411N/A+#endif
1411N/A+
1411N/A #define LIBHAL_PROP_KEY "input.x11_options."
1411N/A #define LIBHAL_XKB_PROP_KEY "input.xkb."
1411N/A
1411N/A@@ -124,6 +142,51 @@ get_prop_string_array(LibHalContext * hal_ctx, const char *udi,
1411N/A }
1411N/A
1411N/A #ifdef SUNSOFT
1411N/A+#if (defined(__sparc__) || defined(__sparc))
1411N/A+Bool check_inactive_session(char const *path) {
1411N/A+ struct stat statbuf;
1411N/A+ char linkpath[PATH_MAX];
1411N/A+ ssize_t readstatus;
1411N/A+ char *usbpath = NULL;
1411N/A+ char *ptr;
1411N/A+ char disppath[PATH_MAX];
1411N/A+
1411N/A+ if ((num_session_disp_dev == num_total_disp_dev) || !disp_dev_path[0])
1411N/A+ return FALSE;
1411N/A+
1411N/A+ if (lstat(path, &statbuf) == 0 &&
1411N/A+ (statbuf.st_mode & S_IFMT) == S_IFLNK) {
1411N/A+ readstatus = readlink(path, linkpath, sizeof(linkpath));
1411N/A+
1411N/A+ if (readstatus > 0 && readstatus < sizeof(linkpath)) {
1411N/A+ linkpath[readstatus] = 0;
1411N/A+ usbpath = linkpath;
1411N/A+ if (strncmp(usbpath, "../..", sizeof("../..") - 1) == 0)
1411N/A+ usbpath += sizeof("../..") - 1;
1411N/A+ if (strncmp(usbpath, "/devices", sizeof("/devices") - 1) == 0)
1411N/A+ usbpath += sizeof("/devices") - 1;
1411N/A+ }
1411N/A+ }
1411N/A+
1411N/A+ if (!usbpath)
1411N/A+ return FALSE;
1411N/A+
1411N/A+ if (ptr = strchr(usbpath + 1, '/'))
1411N/A+ *ptr = 0;
1411N/A+ else
1411N/A+ return FALSE;
1411N/A+
1411N/A+ strncpy(disppath, disp_dev_path, sizeof(disppath));
1411N/A+
1411N/A+ if (ptr = strchr(disppath + 1, '/'))
1411N/A+ *ptr = 0;
1411N/A+ else
1411N/A+ return FALSE;
1411N/A+
1411N/A+ return (strcmp(usbpath, disppath));
1411N/A+}
1411N/A+#endif
1411N/A+
1411N/A static void
1411N/A add_extra_device(char *driver)
1411N/A {
1411N/A@@ -178,6 +241,11 @@ device_added(LibHalContext * hal_ctx, const char *udi)
1411N/A struct xkb_options xkb_opts = { 0 };
1411N/A int rc;
1411N/A
1411N/A+#if ((defined(__sparc__) || defined(__sparc)) && defined(SUNSOFT))
1411N/A+ if (do_abort)
1411N/A+ return;
1411N/A+#endif
1411N/A+
1411N/A LibHalPropertySet *set = NULL;
1411N/A LibHalPropertySetIterator set_iter;
1411N/A char *psi_key = NULL, *tmp_val;
1411N/A@@ -264,6 +332,28 @@ device_added(LibHalContext * hal_ctx, const char *udi)
1411N/A input_options = input_option_new(input_options, "driver", driver);
1411N/A input_options = input_option_new(input_options, "name", name);
1411N/A
1411N/A+#if ((defined(__sparc__) || defined(__sparc)) && defined(SUNSOFT))
1411N/A+ if (!strcmp(name, "keyboard") || !strcmp(name, "mouse")) {
1411N/A+ if (check_inactive_session(path)) {
1411N/A+ if (abort_on_fail_over) {
1411N/A+ /* M5: Input devices were removed, new input device added is to
1411N/A+ activate another session, reset it.
1411N/A+ */
1411N/A+ do_abort = TRUE;
1411N/A+ LogMessage(X_INFO, "config/hal: Server to abort\n");
1411N/A+ } else
1411N/A+ /* M5: No removal of input devices happened, new input device
1411N/A+ added is to activate another session, do nothing.
1411N/A+ */
1411N/A+ LogMessage(X_INFO, "config/hal: Not adding input device %s\n", name);
1411N/A+
1411N/A+ goto unwind;
1411N/A+ } else
1411N/A+ /* M5: new input device added is to activate current session. */
1411N/A+ abort_on_fail_over = FALSE;
1411N/A+ }
1411N/A+#endif
1411N/A+
1411N/A if (asprintf(&config_info, "hal:%s", udi) == -1) {
1411N/A config_info = NULL;
1411N/A LogMessage(X_ERROR, "config/hal: couldn't allocate name\n");
1411N/A@@ -428,7 +518,7 @@ device_added(LibHalContext * hal_ctx, const char *udi)
1411N/A #ifdef SUNSOFT
1411N/A InputOption *md = input_option_find(input_options, "mdriver");
1411N/A if (md) {
1411N/A- char *mdriver = input_option_get_value(md);
1411N/A+ char *mdriver = (char *) input_option_get_value(md);
1411N/A add_extra_device (mdriver);
1411N/A }
1411N/A #endif
1411N/A@@ -442,6 +532,26 @@ device_added(LibHalContext * hal_ctx, const char *udi)
1411N/A goto unwind;
1411N/A }
1411N/A
1411N/A+#if ((defined(__sparc__) || defined(__sparc)) && defined(SUNSOFT))
1411N/A+ if ((num_session_disp_dev < num_total_disp_dev) &&
1411N/A+ (!strcmp(name, "keyboard") || !strcmp(name, "mouse"))) {
1411N/A+ int i;
1411N/A+
1411N/A+ if (num_added_devices == MAX_DEVICES) {
1411N/A+ LogMessage(X_ERROR, "config/hal: Too manay devices to add\n");
1411N/A+ goto unwind;
1411N/A+ }
1411N/A+
1411N/A+ for (i = 0; i < MAX_DEVICES; i++) {
1411N/A+ if (added_devices[i] == 0) {
1411N/A+ added_devices[i] = dev;
1411N/A+ num_added_devices++;
1411N/A+ break;
1411N/A+ }
1411N/A+ }
1411N/A+ }
1411N/A+#endif
1411N/A+
1411N/A unwind:
1411N/A if (set)
1411N/A libhal_free_property_set(set);
1411N/A@@ -474,6 +584,12 @@ device_added(LibHalContext * hal_ctx, const char *udi)
1411N/A
1411N/A dbus_error_free(&error);
1411N/A
1411N/A+#if ((defined(__sparc__) || defined(__sparc)) && defined(SUNSOFT))
1411N/A+ if (do_abort) {
1411N/A+ config_fini();
1411N/A+ GiveUp(0);
1411N/A+ }
1411N/A+#endif
1411N/A return;
1411N/A }
1411N/A
1411N/Adiff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
1411N/Aindex bee407b..248c603 100644
1411N/A--- a/hw/xfree86/common/xf86Xinput.c
1411N/A+++ b/hw/xfree86/common/xf86Xinput.c
1411N/A@@ -45,6 +45,9 @@
1411N/A * the sale, use or other dealings in this Software without prior written
1411N/A * authorization from the copyright holder(s) and author(s).
1411N/A */
1411N/A+/*
1411N/A+ * Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved.
1411N/A+ */
1411N/A
1411N/A #ifdef HAVE_XORG_CONFIG_H
1411N/A #include <xorg-config.h>
1411N/A@@ -103,6 +106,15 @@
1411N/A static int
1411N/A xf86InputDevicePostInit(DeviceIntPtr dev);
1411N/A
1411N/A+#if ((defined(__sparc__) || defined(__sparc)) && defined(sun))
1411N/A+#define MAX_DEVICES 4
1411N/A+extern int num_total_disp_dev;
1411N/A+extern int num_session_disp_dev;
1411N/A+extern DeviceIntPtr added_devices[MAX_DEVICES];
1411N/A+extern int num_added_devices;
1411N/A+extern Bool abort_on_fail_over;
1411N/A+#endif
1411N/A+
1411N/A /**
1411N/A * Eval config and modify DeviceVelocityRec accordingly
1411N/A */
1411N/A@@ -1432,6 +1444,25 @@ xf86DisableDevice(DeviceIntPtr dev, Bool panic)
1411N/A SendDevicePresenceEvent(dev->id, DeviceUnrecoverable);
1411N/A DeleteInputDeviceRequest(dev);
1411N/A }
1411N/A+
1411N/A+#if ((defined(__sparc__) || defined(__sparc)) && defined(sun))
1411N/A+ if (num_session_disp_dev < num_total_disp_dev) {
1411N/A+ int i;
1411N/A+
1411N/A+ for (i = 0; i < MAX_DEVICES; i++) {
1411N/A+ if (added_devices[i] == dev) {
1411N/A+ added_devices[i] = 0;
1411N/A+ if (--num_added_devices == 0)
1411N/A+ /* M5: will abort server when another X session
1411N/A+ is activated.
1411N/A+ */
1411N/A+ abort_on_fail_over = TRUE;
1411N/A+
1411N/A+ break;
1411N/A+ }
1411N/A+ }
1411N/A+ }
1411N/A+#endif
1411N/A }
1411N/A
1411N/A /**
1411N/Adiff --git a/hw/xfree86/common/xf86pciBus.c b/hw/xfree86/common/xf86pciBus.c
1411N/Aindex 258988a..2ec07d9 100644
1411N/A--- a/hw/xfree86/common/xf86pciBus.c
1411N/A+++ b/hw/xfree86/common/xf86pciBus.c
1411N/A@@ -1,5 +1,6 @@
1411N/A /*
1411N/A * Copyright (c) 1997-2003 by The XFree86 Project, Inc.
1411N/A+ * Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved.
1411N/A *
1411N/A * Permission is hereby granted, free of charge, to any person obtaining a
1411N/A * copy of this software and associated documentation files (the "Software"),
1411N/A@@ -54,6 +55,12 @@
1411N/A /* Bus-specific globals */
1411N/A int pciSlotClaimed = 0;
1411N/A
1411N/A+#if ((defined(__sparc__) || defined(__sparc)) && defined (sun))
1411N/A+int num_total_disp_dev = 0;
1411N/A+int num_session_disp_dev = 0;
1411N/A+char disp_dev_path[PATH_MAX];
1411N/A+#endif
1411N/A+
1411N/A #define PCIINFOCLASSES(c) \
1411N/A ( (((c) & 0x00ff0000) == (PCI_CLASS_PREHISTORIC << 16)) \
1411N/A || (((c) & 0x00ff0000) == (PCI_CLASS_DISPLAY << 16)) \
1411N/A@@ -115,6 +122,11 @@ xf86PciProbe(void)
1411N/A primaryBus.id.pci = info;
1411N/A }
1411N/A info->user_data = 0;
1411N/A+
1411N/A+#if ((defined(__sparc__) || defined(__sparc)) && defined (sun))
1411N/A+ if (IS_VGA(info->device_class))
1411N/A+ num_total_disp_dev++;
1411N/A+#endif
1411N/A }
1411N/A }
1411N/A free(iter);
1411N/A@@ -483,6 +495,15 @@ xf86PciProbeDev(DriverPtr drvp)
1411N/A const struct pci_id_match *const devices = drvp->supported_devices;
1411N/A GDevPtr *devList;
1411N/A const unsigned numDevs = xf86MatchDevice(drvp->driverName, &devList);
1411N/A+#if ((defined(__sparc__) || defined(__sparc)) && defined (sun))
1411N/A+ struct sol_device_private {
1411N/A+ struct pci_device base;
1411N/A+ const char * device_string;
1411N/A+ };
1411N/A+#define DEV_PATH(dev) (((struct sol_device_private *) dev)->device_string)
1411N/A+
1411N/A+ num_session_disp_dev = numDevs;
1411N/A+#endif
1411N/A
1411N/A for (i = 0; i < numDevs; i++) {
1411N/A struct pci_device_iterator *iter;
1411N/A@@ -560,6 +581,11 @@ xf86PciProbeDev(DriverPtr drvp)
1411N/A if ((*drvp->PciProbe) (drvp, entry, pPci,
1411N/A devices[j].match_data)) {
1411N/A foundScreen = TRUE;
1411N/A+
1411N/A+#if ((defined(__sparc__) || defined(__sparc)) && defined (sun))
1411N/A+ strncpy(disp_dev_path, DEV_PATH(pPci), sizeof(disp_dev_path));
1411N/A+#endif
1411N/A+
1411N/A }
1411N/A else
1411N/A xf86UnclaimPciSlot(pPci, devList[i]);
1411N/A@@ -568,6 +594,7 @@ xf86PciProbeDev(DriverPtr drvp)
1411N/A break;
1411N/A }
1411N/A }
1411N/A+
1411N/A }
1411N/A free(devList);
1411N/A