diff -Naur xorg-x11-6.8.2/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_acpi.c xorg-x11-6.8.x.99/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_acpi.c --- xorg-x11-6.8.2/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_acpi.c 1970-01-01 03:00:00 +0300 +++ xorg-x11-6.8.x.99/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_acpi.c 2005-08-22 16:05:18 +0400 @@ -0,0 +1,168 @@ +#include "X.h" +#include "os.h" +#include "xf86.h" +#include "xf86Priv.h" +#define XF86_OS_PRIVS +#include "xf86_OSproc.h" +#include +#include +#include +#include +#include +#include +#include + +#define ACPI_SOCKET "/var/run/acpid.socket" +#define ACPI_EVENTS "/proc/acpi/event" + +#define ACPI_VIDEO_NOTIFY_SWITCH 0x80 +#define ACPI_VIDEO_NOTIFY_PROBE 0x81 +#define ACPI_VIDEO_NOTIFY_CYCLE 0x82 +#define ACPI_VIDEO_NOTIFY_NEXT_OUTPUT 0x83 +#define ACPI_VIDEO_NOTIFY_PREV_OUTPUT 0x84 + +#define ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS 0x82 +#define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS 0x83 +#define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS 0x84 +#define ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS 0x85 +#define ACPI_VIDEO_NOTIFY_DISPLAY_OFF 0x86 + +#define ACPI_VIDEO_HEAD_INVALID (~0u - 1) +#define ACPI_VIDEO_HEAD_END (~0u) + +static void lnxCloseACPI(void); +static pointer ACPIihPtr = NULL; +PMClose lnxACPIOpen(void); + +#define LINE_LENGTH 80 + +static int +lnxACPIGetEventFromOs(int fd, pmEvent *events, int num) +{ + char ev[LINE_LENGTH]; + int n; + + memset(ev, 0, LINE_LENGTH); + + n = read( fd, ev, LINE_LENGTH ); + + /* Check that we have a video event */ + if (strstr(ev, "video") == ev) { + char *video = NULL; + char *GFX = NULL; + char *notify = NULL; + char *data = NULL; /* doesn't appear to be used in the kernel */ + unsigned long int notify_l, data_l; + + video = strtok(ev, "video"); + + GFX = strtok(NULL, " "); +#if 0 + ErrorF("GFX: %s\n",GFX); +#endif + + notify = strtok(NULL, " "); + notify_l = strtoul(notify, NULL, 16); +#if 0 + ErrorF("notify: 0x%lx\n",notify_l); +#endif + + data = strtok(NULL, " "); + data_l = strtoul(data, NULL, 16); +#if 0 + ErrorF("data: 0x%lx\n",data_l); +#endif + + /* We currently don't differentiate between any event */ + switch (notify_l) { + case ACPI_VIDEO_NOTIFY_SWITCH: + break; + case ACPI_VIDEO_NOTIFY_PROBE: + break; + case ACPI_VIDEO_NOTIFY_CYCLE: + break; + case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: + break; + case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: + break; + default: + break; + } + + /* Deal with all ACPI events as a capability change */ + events[0] = XF86_APM_CAPABILITY_CHANGED; + + return 1; + } + + return 0; +} + +static pmWait +lnxACPIConfirmEventToOs(int fd, pmEvent event) +{ + /* No ability to send back to the kernel in ACPI */ + switch (event) { + default: + return PM_NONE; + } +} + +PMClose +lnxACPIOpen(void) +{ + int fd; + struct sockaddr_un addr; + int r = -1; + +#ifdef DEBUG + ErrorF("ACPI: OSPMOpen called\n"); +#endif + if (ACPIihPtr || !xf86Info.pmFlag) + return NULL; + +#ifdef DEBUG + ErrorF("ACPI: Opening device\n"); +#endif + if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) > -1) { + memset(&addr, 0, sizeof(addr)); + addr.sun_family = AF_UNIX; + strcpy(addr.sun_path, ACPI_SOCKET); + if ((r = connect(fd, (struct sockaddr*)&addr, sizeof(addr))) == -1) { + shutdown(fd, 2); + fd = -1; + } + } + + /* acpid's socket isn't available, so try going direct */ + if (fd == -1) { + if ((fd = open(ACPI_EVENTS, O_RDONLY)) < 0) { + xf86MsgVerb(X_WARNING,3,"Open ACPI failed (%s) (%s)\n", ACPI_EVENTS, + strerror(errno)); + return NULL; + } + } + + xf86PMGetEventFromOs = lnxACPIGetEventFromOs; + xf86PMConfirmEventToOs = lnxACPIConfirmEventToOs; + ACPIihPtr = xf86AddInputHandler(fd,xf86HandlePMEvents,NULL); + xf86MsgVerb(X_INFO,3,"Open ACPI successful (%s)\n", (r != -1) ? ACPI_SOCKET : ACPI_EVENTS); + + return lnxCloseACPI; +} + +static void +lnxCloseACPI(void) +{ + int fd; + +#ifdef DEBUG + ErrorF("ACPI: Closing device\n"); +#endif + if (ACPIihPtr) { + fd = xf86RemoveInputHandler(ACPIihPtr); + shutdown(fd, 2); + ACPIihPtr = NULL; + } +} + diff -Naur xorg-x11-6.8.2/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_apm.c xorg-x11-6.8.x.99/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_apm.c --- xorg-x11-6.8.2/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_apm.c 2004-04-23 23:54:08 +0400 +++ xorg-x11-6.8.x.99/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_apm.c 2005-08-22 21:30:17 +0400 @@ -25,6 +29,8 @@ # define APM_SUSPEND_FAILED 0xf001 #endif +static PMClose lnxAPMOpen(void); +extern PMClose lnxACPIOpen(void); static void lnxCloseAPM(void); static pointer APMihPtr = NULL; @@ -98,6 +104,11 @@ case XF86_APM_CRITICAL_SUSPEND: case XF86_APM_USER_SUSPEND: if (ioctl( fd, APM_IOC_SUSPEND, NULL )) { + /* I believe this is wrong (EE) + EBUSY is sent when a device refuses to be suspended. + In this case we still need to undo everything we have + done to suspend ourselves or we will stay in suspended + state forever. */ if (errno == EBUSY) return PM_CONTINUE; else @@ -118,6 +129,21 @@ PMClose xf86OSPMOpen(void) { + PMClose ret = NULL; + + /* Favour ACPI over APM */ + + ret = lnxACPIOpen(); + + if (!ret) + ret = lnxAPMOpen(); + + return ret; +} + +static PMClose +lnxAPMOpen(void) +{ int fd, pfd; #ifdef DEBUG @@ -144,8 +170,7 @@ xf86MsgVerb(X_INFO,3,"Open APM successful\n"); return lnxCloseAPM; } - xf86MsgVerb(X_WARNING,3,"Open APM failed (%s) (%s)\n", APM_DEVICE, - strerror(errno)); + xf86MsgVerb(X_INFO,3,"No APM support in BIOS or kernel\n"); return NULL; } --- xorg-x11-6.8.2/xc/programs/Xserver/hw/xfree86/os-support/linux/Imakefile.orig 2005-08-24 12:45:31 +0400 +++ xorg-x11-6.8.2/xc/programs/Xserver/hw/xfree86/os-support/linux/Imakefile 2005-08-24 12:44:22 +0400 @@ -48,12 +48,12 @@ #endif SRCS = lnx_init.c lnx_video.c lnx_io.c libc_wrapper.c bios_mmap.c \ - VTsw_usl.c std_kbdEv.c posix_tty.c $(MOUSESRC) \ + VTsw_usl.c std_kbdEv.c posix_tty.c lnx_acpi.c $(MOUSESRC) \ lnx_pci.c vidmem.c lnx_apm.c $(JOYSTICK_SRC) $(DRI_SRC) $(RES_SRCS) \ $(PLATFORM_SRC) lnx_kmod.c lnx_agp.c $(KBDSRC) /*wcHelper.c*/ OBJS = lnx_init.o lnx_video.o lnx_io.o libc_wrapper.o bios_mmap.o \ - VTsw_usl.o std_kbdEv.o posix_tty.o $(MOUSEOBJ) \ + VTsw_usl.o std_kbdEv.o posix_tty.o lnx_acpi.o $(MOUSEOBJ) \ lnx_pci.o vidmem.o lnx_apm.o $(JOYSTICK_OBJ) $(DRI_OBJ) $(RES_OBJS) \ $(PLATFORM_OBJ) lnx_kmod.o lnx_agp.o $(KBDOBJ) /*wcHelper.o*/