1 /* Based on hw/xfree86/os-support/bsd/bsd_apm.c which bore no explicit
2 * copyright notice, so is covered by the following notice:
4 * Copyright (C) 1994-2003 The XFree86 Project, Inc. All Rights Reserved.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE XFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
21 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * Except as contained in this notice, the name of the XFree86 Project shall
25 * not be used in advertising or otherwise to promote the sale, use or other
26 * dealings in this Software without prior written authorization from the
30 /* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
32 * Permission is hereby granted, free of charge, to any person obtaining a
33 * copy of this software and associated documentation files (the "Software"),
34 * to deal in the Software without restriction, including without limitation
35 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
36 * and/or sell copies of the Software, and to permit persons to whom the
37 * Software is furnished to do so, subject to the following conditions:
39 * The above copyright notice and this permission notice (including the next
40 * paragraph) shall be included in all copies or substantial portions of the
43 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
44 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
45 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
46 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
47 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
48 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
49 * DEALINGS IN THE SOFTWARE.
52 #ifdef HAVE_XORG_CONFIG_H
53 #include <xorg-config.h>
61 #include "xf86_OSproc.h"
62 #include "xf86_OSlib.h"
64 #ifndef PLEASE_FIX_THIS
65 #define APM_STANDBY_REQ 0xa01
66 #define APM_SUSPEND_REQ 0xa02
67 #define APM_NORMAL_RESUME 0xa03
68 #define APM_CRIT_RESUME 0xa04
69 #define APM_BATTERY_LOW 0xa05
70 #define APM_POWER_CHANGE 0xa06
71 #define APM_UPDATE_TIME 0xa07
72 #define APM_CRIT_SUSPEND_REQ 0xa08
73 #define APM_USER_STANDBY_REQ 0xa09
74 #define APM_USER_SUSPEND_REQ 0xa0a
75 #define APM_SYS_STANDBY_RESUME 0xa0b
76 #define APM_IOC_NEXTEVENT 0xa0c
77 #define APM_IOC_RESUME 0xa0d
78 #define APM_IOC_SUSPEND 0xa0e
79 #define APM_IOC_STANDBY 0xa0f
82 typedef struct apm_event_info
{
87 This may be replaced with a better device name
90 #define APM_DEVICE "/dev/srn"
91 #define APM_DEVICE1 "/dev/apm"
93 static pointer APMihPtr
= NULL
;
94 static void sunCloseAPM(void);
99 } sunToXF86Array
[] = {
100 {APM_STANDBY_REQ
, XF86_APM_SYS_STANDBY
},
101 {APM_SUSPEND_REQ
, XF86_APM_SYS_SUSPEND
},
102 {APM_NORMAL_RESUME
, XF86_APM_NORMAL_RESUME
},
103 {APM_CRIT_RESUME
, XF86_APM_CRITICAL_RESUME
},
104 {APM_BATTERY_LOW
, XF86_APM_LOW_BATTERY
},
105 {APM_POWER_CHANGE
, XF86_APM_POWER_STATUS_CHANGE
},
106 {APM_UPDATE_TIME
, XF86_APM_UPDATE_TIME
},
107 {APM_CRIT_SUSPEND_REQ
, XF86_APM_CRITICAL_SUSPEND
},
108 {APM_USER_STANDBY_REQ
, XF86_APM_USER_STANDBY
},
109 {APM_USER_SUSPEND_REQ
, XF86_APM_USER_SUSPEND
},
110 {APM_SYS_STANDBY_RESUME
, XF86_APM_STANDBY_RESUME
},
111 #ifdef APM_CAPABILITY_CHANGE
112 {APM_CAPABILITY_CHANGE
, XF86_APM_CAPABILITY_CHANGED
},
116 #define numApmEvents (sizeof(sunToXF86Array) / sizeof(sunToXF86Array[0]))
123 for (i
= 0; i
< numApmEvents
; i
++) {
124 if (type
== sunToXF86Array
[i
].apmBsd
) {
125 return sunToXF86Array
[i
].xf86
;
128 return XF86_APM_UNKNOWN
;
132 * APM events can be requested direclty from /dev/apm
135 sunPMGetEventFromOS(int fd
, pmEvent
* events
, int num
)
137 struct apm_event_info sunEvent
;
140 for (i
= 0; i
< num
; i
++) {
142 if (ioctl(fd
, APM_IOC_NEXTEVENT
, &sunEvent
) < 0) {
143 if (errno
!= EAGAIN
) {
144 xf86Msg(X_WARNING
, "sunPMGetEventFromOS: APM_IOC_NEXTEVENT"
145 " %s\n", strerror(errno
));
149 events
[i
] = sunToXF86(sunEvent
.type
);
151 xf86Msg(X_WARNING
, "Got some events\n");
156 sunPMConfirmEventToOs(int fd
, pmEvent event
)
159 /* XXX: NOT CURRENTLY RETURNED FROM OS */
160 case XF86_APM_SYS_STANDBY
:
161 case XF86_APM_USER_STANDBY
:
162 if (ioctl(fd
, APM_IOC_STANDBY
, NULL
) == 0)
163 return PM_WAIT
; /* should we stop the Xserver in standby, too? */
166 case XF86_APM_SYS_SUSPEND
:
167 case XF86_APM_CRITICAL_SUSPEND
:
168 case XF86_APM_USER_SUSPEND
:
169 xf86Msg(X_WARNING
, "Got SUSPENDED\n");
170 if (ioctl(fd
, APM_IOC_SUSPEND
, NULL
) == 0)
173 xf86Msg(X_WARNING
, "sunPMConfirmEventToOs: APM_IOC_SUSPEND"
174 " %s\n", strerror(errno
));
177 case XF86_APM_STANDBY_RESUME
:
178 case XF86_APM_NORMAL_RESUME
:
179 case XF86_APM_CRITICAL_RESUME
:
180 case XF86_APM_STANDBY_FAILED
:
181 case XF86_APM_SUSPEND_FAILED
:
182 xf86Msg(X_WARNING
, "Got RESUME\n");
183 if (ioctl(fd
, APM_IOC_RESUME
, NULL
) == 0)
186 xf86Msg(X_WARNING
, "sunPMConfirmEventToOs: APM_IOC_RESUME"
187 " %s\n", strerror(errno
));
200 if (APMihPtr
|| !xf86Info
.pmFlag
) {
204 if ((fd
= open(APM_DEVICE
, O_RDWR
)) == -1) {
205 if ((fd
= open(APM_DEVICE1
, O_RDWR
)) == -1) {
209 xf86PMGetEventFromOs
= sunPMGetEventFromOS
;
210 xf86PMConfirmEventToOs
= sunPMConfirmEventToOs
;
211 APMihPtr
= xf86AddGeneralHandler(fd
, xf86HandlePMEvents
, NULL
);
221 fd
= xf86RemoveGeneralHandler(APMihPtr
);