1 diff --git a/config/hal.c b/config/hal.c
2 index ea574ca..e108f03 100644
7 * Copyright © 2007 Daniel Stone
8 * Copyright © 2007 Red Hat, Inc.
9 + * Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved.
11 * Permission is hereby granted, free of charge, to any person obtaining a
12 * copy of this software and associated documentation files (the "Software"),
14 #include "config-backends.h"
17 +#if ((defined(__sparc__) || defined(__sparc)) && defined(SUNSOFT))
18 +#include <sys/stat.h>
21 +#define MAX_DEVICES 4
23 +DeviceIntPtr added_devices[MAX_DEVICES];
24 +int num_added_devices = 0;
25 +Bool abort_on_fail_over = FALSE;
26 +static Bool do_abort = FALSE;
28 +extern int num_total_disp_dev;
29 +extern int num_session_disp_dev;
30 +extern char disp_dev_path[PATH_MAX];
31 +extern void GiveUp(int sig);
34 #define LIBHAL_PROP_KEY "input.x11_options."
35 #define LIBHAL_XKB_PROP_KEY "input.xkb."
37 @@ -124,6 +142,51 @@ get_prop_string_array(LibHalContext * hal_ctx, const char *udi,
41 +#if defined(SUNSOFT) && (defined(__sparc__) || defined(__sparc))
42 +Bool check_inactive_session(char const *path) {
43 + struct stat statbuf;
44 + char linkpath[PATH_MAX];
46 + char *usbpath = NULL;
48 + char disppath[PATH_MAX];
50 + if ((num_session_disp_dev == num_total_disp_dev) || !disp_dev_path[0])
53 + if (lstat(path, &statbuf) == 0 &&
54 + (statbuf.st_mode & S_IFMT) == S_IFLNK) {
55 + readstatus = readlink(path, linkpath, sizeof(linkpath));
57 + if (readstatus > 0 && readstatus < sizeof(linkpath)) {
58 + linkpath[readstatus] = 0;
60 + if (strncmp(usbpath, "../..", sizeof("../..") - 1) == 0)
61 + usbpath += sizeof("../..") - 1;
62 + if (strncmp(usbpath, "/devices", sizeof("/devices") - 1) == 0)
63 + usbpath += sizeof("/devices") - 1;
70 + if (ptr = strchr(usbpath + 1, '/'))
75 + strncpy(disppath, disp_dev_path, sizeof(disppath));
77 + if (ptr = strchr(disppath + 1, '/'))
82 + return (strcmp(usbpath, disppath));
87 device_added(LibHalContext * hal_ctx, const char *udi)
89 @@ -136,6 +199,11 @@ device_added(LibHalContext * hal_ctx, const char *udi)
90 struct xkb_options xkb_opts = { 0 };
93 +#if ((defined(__sparc__) || defined(__sparc)) && defined(SUNSOFT))
98 LibHalPropertySet *set = NULL;
99 LibHalPropertySetIterator set_iter;
100 char *psi_key = NULL, *tmp_val;
101 @@ -232,6 +300,28 @@ device_added(LibHalContext * hal_ctx, const char *udi)
102 input_options = input_option_new(input_options, "driver", driver);
103 input_options = input_option_new(input_options, "name", name);
105 +#if ((defined(__sparc__) || defined(__sparc)) && defined(SUNSOFT))
106 + if (!strcmp(name, "keyboard") || !strcmp(name, "mouse")) {
107 + if (check_inactive_session(path)) {
108 + if (abort_on_fail_over) {
109 + /* M5: Input devices were removed, new input device added is to
110 + activate another session, reset it.
113 + LogMessage(X_INFO, "config/hal: Server to abort\n");
115 + /* M5: No removal of input devices happened, new input device
116 + added is to activate another session, do nothing.
118 + LogMessage(X_INFO, "config/hal: Not adding input device %s\n", name);
122 + /* M5: new input device added is to activate current session. */
123 + abort_on_fail_over = FALSE;
127 if (asprintf(&config_info, "hal:%s", udi) == -1) {
129 LogMessage(X_ERROR, "config/hal: couldn't allocate name\n");
130 @@ -402,6 +492,26 @@ device_added(LibHalContext * hal_ctx, const char *udi)
134 +#if ((defined(__sparc__) || defined(__sparc)) && defined(SUNSOFT))
135 + if ((num_session_disp_dev < num_total_disp_dev) &&
136 + (!strcmp(name, "keyboard") || !strcmp(name, "mouse"))) {
139 + if (num_added_devices == MAX_DEVICES) {
140 + LogMessage(X_ERROR, "config/hal: Too manay devices to add\n");
144 + for (i = 0; i < MAX_DEVICES; i++) {
145 + if (added_devices[i] == 0) {
146 + added_devices[i] = dev;
147 + num_added_devices++;
156 libhal_free_property_set(set);
157 @@ -434,6 +544,12 @@ device_added(LibHalContext * hal_ctx, const char *udi)
159 dbus_error_free(&error);
161 +#if ((defined(__sparc__) || defined(__sparc)) && defined(SUNSOFT))
170 diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
171 index c56a2b9..a3a7645 100644
172 --- a/hw/xfree86/common/xf86Xinput.c
173 +++ b/hw/xfree86/common/xf86Xinput.c
175 * the sale, use or other dealings in this Software without prior written
176 * authorization from the copyright holder(s) and author(s).
179 + * Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved.
182 #ifdef HAVE_XORG_CONFIG_H
183 #include <xorg-config.h>
184 @@ -113,6 +116,15 @@ static int
185 static InputInfoPtr *new_input_devices;
186 static int new_input_devices_count;
188 +#if ((defined(__sparc__) || defined(__sparc)) && defined(sun))
189 +#define MAX_DEVICES 4
190 +extern int num_total_disp_dev;
191 +extern int num_session_disp_dev;
192 +extern DeviceIntPtr added_devices[MAX_DEVICES];
193 +extern int num_added_devices;
194 +extern Bool abort_on_fail_over;
198 * Eval config and modify DeviceVelocityRec accordingly
200 @@ -1469,6 +1481,25 @@ xf86DisableDevice(DeviceIntPtr dev, Bool panic)
201 SendDevicePresenceEvent(dev->id, DeviceUnrecoverable);
202 DeleteInputDeviceRequest(dev);
205 +#if ((defined(__sparc__) || defined(__sparc)) && defined(sun))
206 + if (num_session_disp_dev < num_total_disp_dev) {
209 + for (i = 0; i < MAX_DEVICES; i++) {
210 + if (added_devices[i] == dev) {
211 + added_devices[i] = 0;
212 + if (--num_added_devices == 0)
213 + /* M5: will abort server when another X session
216 + abort_on_fail_over = TRUE;
226 diff --git a/hw/xfree86/common/xf86pciBus.c b/hw/xfree86/common/xf86pciBus.c
227 index 8158c2b..f812a3b 100644
228 --- a/hw/xfree86/common/xf86pciBus.c
229 +++ b/hw/xfree86/common/xf86pciBus.c
232 * Copyright (c) 1997-2003 by The XFree86 Project, Inc.
233 + * Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved.
235 * Permission is hereby granted, free of charge, to any person obtaining a
236 * copy of this software and associated documentation files (the "Software"),
238 /* Bus-specific globals */
239 int pciSlotClaimed = 0;
241 +#if ((defined(__sparc__) || defined(__sparc)) && defined (sun))
242 +int num_total_disp_dev = 0;
243 +int num_session_disp_dev = 0;
244 +char disp_dev_path[PATH_MAX];
247 #define PCIINFOCLASSES(c) \
248 ( (((c) & 0x00ff0000) == (PCI_CLASS_PREHISTORIC << 16)) \
249 || (((c) & 0x00ff0000) == (PCI_CLASS_DISPLAY << 16)) \
250 @@ -115,6 +122,11 @@ xf86PciProbe(void)
251 primaryBus.id.pci = info;
255 +#if ((defined(__sparc__) || defined(__sparc)) && defined (sun))
256 + if (IS_VGA(info->device_class))
257 + num_total_disp_dev++;
262 @@ -483,6 +495,15 @@ xf86PciProbeDev(DriverPtr drvp)
263 const struct pci_id_match *const devices = drvp->supported_devices;
265 const unsigned numDevs = xf86MatchDevice(drvp->driverName, &devList);
266 +#if ((defined(__sparc__) || defined(__sparc)) && defined (sun))
267 + struct sol_device_private {
268 + struct pci_device base;
269 + const char * device_string;
271 +#define DEV_PATH(dev) (((struct sol_device_private *) dev)->device_string)
273 + num_session_disp_dev = numDevs;
276 for (i = 0; i < numDevs; i++) {
277 struct pci_device_iterator *iter;
278 @@ -560,6 +581,11 @@ xf86PciProbeDev(DriverPtr drvp)
279 if ((*drvp->PciProbe) (drvp, entry, pPci,
280 devices[j].match_data)) {
283 +#if ((defined(__sparc__) || defined(__sparc)) && defined (sun))
284 + strncpy(disp_dev_path, DEV_PATH(pPci), sizeof(disp_dev_path));
289 xf86UnclaimPciSlot(pPci, devList[i]);
290 @@ -568,6 +594,7 @@ xf86PciProbeDev(DriverPtr drvp)