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