diff options
Diffstat (limited to 'xorg-server/hw/xfree86/os-support/shared')
-rw-r--r-- | xorg-server/hw/xfree86/os-support/shared/bios_mmap.c | 128 | ||||
-rw-r--r-- | xorg-server/hw/xfree86/os-support/shared/kmod_noop.c | 5 | ||||
-rw-r--r-- | xorg-server/hw/xfree86/os-support/shared/posix_tty.c | 847 | ||||
-rw-r--r-- | xorg-server/hw/xfree86/os-support/shared/sigio.c | 610 | ||||
-rw-r--r-- | xorg-server/hw/xfree86/os-support/shared/vidmem.c | 317 | ||||
-rw-r--r-- | xorg-server/hw/xfree86/os-support/shared/xf86Axp.c | 41 |
6 files changed, 959 insertions, 989 deletions
diff --git a/xorg-server/hw/xfree86/os-support/shared/bios_mmap.c b/xorg-server/hw/xfree86/os-support/shared/bios_mmap.c index b7b35d9db..e000dc9c8 100644 --- a/xorg-server/hw/xfree86/os-support/shared/bios_mmap.c +++ b/xorg-server/hw/xfree86/os-support/shared/bios_mmap.c @@ -38,41 +38,39 @@ #ifndef __alpha__ int xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf, - int Len) + int Len) { - int fd; - unsigned char *ptr; - int psize; - int mlen; - - if ((fd = open(DEV_MEM, O_RDONLY)) < 0) - { - xf86Msg(X_WARNING, "xf86ReadBIOS: Failed to open %s (%s)\n", - DEV_MEM, strerror(errno)); - return -1; - } - psize = getpagesize(); - Offset += Base & (psize - 1); - Base &= ~(psize - 1); - mlen = (Offset + Len + psize - 1) & ~(psize - 1); - ptr = (unsigned char *)mmap((caddr_t)0, mlen, PROT_READ, - MAP_SHARED, fd, (off_t)Base); - if (ptr == MAP_FAILED) - { - xf86Msg(X_WARNING, "xf86ReadBIOS: %s mmap failed (%s)\n", - DEV_MEM, strerror(errno)); - close(fd); - return -1; - } - DebugF("xf86ReadBIOS: BIOS at 0x%08x has signature 0x%04x\n", - Base, ptr[0] | (ptr[1] << 8)); - (void)memcpy(Buf, (void *)(ptr + Offset), Len); - (void)munmap((caddr_t)ptr, mlen); - (void)close(fd); - return Len; + int fd; + unsigned char *ptr; + int psize; + int mlen; + + if ((fd = open(DEV_MEM, O_RDONLY)) < 0) { + xf86Msg(X_WARNING, "xf86ReadBIOS: Failed to open %s (%s)\n", + DEV_MEM, strerror(errno)); + return -1; + } + psize = getpagesize(); + Offset += Base & (psize - 1); + Base &= ~(psize - 1); + mlen = (Offset + Len + psize - 1) & ~(psize - 1); + ptr = (unsigned char *) mmap((caddr_t) 0, mlen, PROT_READ, + MAP_SHARED, fd, (off_t) Base); + if (ptr == MAP_FAILED) { + xf86Msg(X_WARNING, "xf86ReadBIOS: %s mmap failed (%s)\n", + DEV_MEM, strerror(errno)); + close(fd); + return -1; + } + DebugF("xf86ReadBIOS: BIOS at 0x%08x has signature 0x%04x\n", + Base, ptr[0] | (ptr[1] << 8)); + (void) memcpy(Buf, (void *) (ptr + Offset), Len); + (void) munmap((caddr_t) ptr, mlen); + (void) close(fd); + return Len; } -#else /* __alpha__ */ +#else /* __alpha__ */ /* * We trick "mmap" into mapping BUS memory for us via BUS_BASE, @@ -88,50 +86,50 @@ xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf, #ifdef linux extern unsigned long _bus_base(void); + #define BUS_BASE _bus_base() #else extern u_int64_t dense_base(void); + #define BUS_BASE dense_base() #endif int xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf, - int Len) + int Len) { - caddr_t base; - int fd; - int psize; - int mlen; - - if ((fd = open(DEV_MEM, O_RDONLY)) < 0) - { - xf86Msg(X_WARNING, "xf86ReadBIOS: Failed to open %s (%s)\n", - DEV_MEM, strerror(errno)); - return -1; - } - - psize = getpagesize(); - Offset += Base & (psize - 1); - Base &= ~(psize - 1); - mlen = (Offset + Len + psize - 1) & ~(psize - 1); - base = mmap((caddr_t)0, mlen, PROT_READ, - MAP_SHARED, fd, (off_t)(Base + BUS_BASE)); - - if (base == MAP_FAILED) - { - xf86Msg(X_WARNING, "xf86ReadBIOS: Failed to mmap %s (%s)\n", - DEV_MEM, strerror(errno)); - return -1; - } - - xf86SlowBCopyFromBus((unsigned char *)(base+Offset), Buf, Len); - - munmap((caddr_t)base, mlen); - close(fd); - return Len; + caddr_t base; + int fd; + int psize; + int mlen; + + if ((fd = open(DEV_MEM, O_RDONLY)) < 0) { + xf86Msg(X_WARNING, "xf86ReadBIOS: Failed to open %s (%s)\n", + DEV_MEM, strerror(errno)); + return -1; + } + + psize = getpagesize(); + Offset += Base & (psize - 1); + Base &= ~(psize - 1); + mlen = (Offset + Len + psize - 1) & ~(psize - 1); + base = mmap((caddr_t) 0, mlen, PROT_READ, + MAP_SHARED, fd, (off_t) (Base + BUS_BASE)); + + if (base == MAP_FAILED) { + xf86Msg(X_WARNING, "xf86ReadBIOS: Failed to mmap %s (%s)\n", + DEV_MEM, strerror(errno)); + return -1; + } + + xf86SlowBCopyFromBus((unsigned char *) (base + Offset), Buf, Len); + + munmap((caddr_t) base, mlen); + close(fd); + return Len; } -#endif /* __alpha__ */ +#endif /* __alpha__ */ diff --git a/xorg-server/hw/xfree86/os-support/shared/kmod_noop.c b/xorg-server/hw/xfree86/os-support/shared/kmod_noop.c index e86d7472f..0437bc564 100644 --- a/xorg-server/hw/xfree86/os-support/shared/kmod_noop.c +++ b/xorg-server/hw/xfree86/os-support/shared/kmod_noop.c @@ -31,8 +31,9 @@ #include "xf86_OSproc.h" -int xf86LoadKernelModule(const char *pathname) +int +xf86LoadKernelModule(const char *pathname) { (void) pathname; - return 0; /* failure */ + return 0; /* failure */ } diff --git a/xorg-server/hw/xfree86/os-support/shared/posix_tty.c b/xorg-server/hw/xfree86/os-support/shared/posix_tty.c index cc12a31f2..ab3757a2a 100644 --- a/xorg-server/hw/xfree86/os-support/shared/posix_tty.c +++ b/xorg-server/hw/xfree86/os-support/shared/posix_tty.c @@ -61,458 +61,430 @@ #include "xf86Priv.h" #include "xf86_OSlib.h" -static int -GetBaud (int baudrate) +static int +GetBaud(int baudrate) { #ifdef B300 - if (baudrate == 300) - return B300; + if (baudrate == 300) + return B300; #endif #ifdef B1200 - if (baudrate == 1200) - return B1200; + if (baudrate == 1200) + return B1200; #endif #ifdef B2400 - if (baudrate == 2400) - return B2400; + if (baudrate == 2400) + return B2400; #endif #ifdef B4800 - if (baudrate == 4800) - return B4800; + if (baudrate == 4800) + return B4800; #endif #ifdef B9600 - if (baudrate == 9600) - return B9600; + if (baudrate == 9600) + return B9600; #endif #ifdef B19200 - if (baudrate == 19200) - return B19200; + if (baudrate == 19200) + return B19200; #endif #ifdef B38400 - if (baudrate == 38400) - return B38400; + if (baudrate == 38400) + return B38400; #endif #ifdef B57600 - if (baudrate == 57600) - return B57600; + if (baudrate == 57600) + return B57600; #endif #ifdef B115200 - if (baudrate == 115200) - return B115200; + if (baudrate == 115200) + return B115200; #endif #ifdef B230400 - if (baudrate == 230400) - return B230400; + if (baudrate == 230400) + return B230400; #endif #ifdef B460800 - if (baudrate == 460800) - return B460800; + if (baudrate == 460800) + return B460800; #endif - return 0; + return 0; } int -xf86OpenSerial (XF86OptionPtr options) +xf86OpenSerial(XF86OptionPtr options) { - struct termios t; - int fd, i; - char *dev; - - dev = xf86SetStrOption (options, "Device", NULL); - if (!dev) - { - xf86Msg (X_ERROR, "xf86OpenSerial: No Device specified.\n"); - return -1; - } - - SYSCALL (fd = open (dev, O_RDWR | O_NONBLOCK)); - if (fd == -1) - { - xf86Msg (X_ERROR, - "xf86OpenSerial: Cannot open device %s\n\t%s.\n", - dev, strerror (errno)); - free(dev); - return -1; - } - - if (!isatty (fd)) - { - /* Allow non-tty devices to be opened. */ - free(dev); - return fd; - } - - /* set up default port parameters */ - SYSCALL (tcgetattr (fd, &t)); - t.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR\ - |IGNCR|ICRNL|IXON); - t.c_oflag &= ~OPOST; - t.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN); - t.c_cflag &= ~(CSIZE|PARENB); - t.c_cflag |= CS8|CLOCAL; - - cfsetispeed (&t, B9600); - cfsetospeed (&t, B9600); - t.c_cc[VMIN] = 1; - t.c_cc[VTIME] = 0; - - SYSCALL (tcsetattr (fd, TCSANOW, &t)); - - if (xf86SetSerial (fd, options) == -1) - { - SYSCALL (close (fd)); - free(dev); - return -1; - } - - SYSCALL (i = fcntl (fd, F_GETFL, 0)); - if (i == -1) - { - SYSCALL (close (fd)); - free(dev); - return -1; - } - i &= ~O_NONBLOCK; - SYSCALL (i = fcntl (fd, F_SETFL, i)); - if (i == -1) - { - SYSCALL (close (fd)); - free(dev); - return -1; - } - free(dev); - return fd; + struct termios t; + int fd, i; + char *dev; + + dev = xf86SetStrOption(options, "Device", NULL); + if (!dev) { + xf86Msg(X_ERROR, "xf86OpenSerial: No Device specified.\n"); + return -1; + } + + SYSCALL(fd = open(dev, O_RDWR | O_NONBLOCK)); + if (fd == -1) { + xf86Msg(X_ERROR, + "xf86OpenSerial: Cannot open device %s\n\t%s.\n", + dev, strerror(errno)); + free(dev); + return -1; + } + + if (!isatty(fd)) { + /* Allow non-tty devices to be opened. */ + free(dev); + return fd; + } + + /* set up default port parameters */ + SYSCALL(tcgetattr(fd, &t)); + t.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR + | IGNCR | ICRNL | IXON); + t.c_oflag &= ~OPOST; + t.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN); + t.c_cflag &= ~(CSIZE | PARENB); + t.c_cflag |= CS8 | CLOCAL; + + cfsetispeed(&t, B9600); + cfsetospeed(&t, B9600); + t.c_cc[VMIN] = 1; + t.c_cc[VTIME] = 0; + + SYSCALL(tcsetattr(fd, TCSANOW, &t)); + + if (xf86SetSerial(fd, options) == -1) { + SYSCALL(close(fd)); + free(dev); + return -1; + } + + SYSCALL(i = fcntl(fd, F_GETFL, 0)); + if (i == -1) { + SYSCALL(close(fd)); + free(dev); + return -1; + } + i &= ~O_NONBLOCK; + SYSCALL(i = fcntl(fd, F_SETFL, i)); + if (i == -1) { + SYSCALL(close(fd)); + free(dev); + return -1; + } + free(dev); + return fd; } int -xf86SetSerial (int fd, XF86OptionPtr options) +xf86SetSerial(int fd, XF86OptionPtr options) { - struct termios t; - int val; - const char *s; - int baud, r; - - if (fd < 0) - return -1; - - /* Don't try to set parameters for non-tty devices. */ - if (!isatty(fd)) - return 0; - - SYSCALL (tcgetattr (fd, &t)); - - if ((val = xf86SetIntOption (options, "BaudRate", 0))) - { - if ((baud = GetBaud (val))) - { - cfsetispeed (&t, baud); - cfsetospeed (&t, baud); - } - else - { - xf86Msg (X_ERROR, - "Invalid Option BaudRate value: %d\n", val); - return -1; - } - } - - if ((val = xf86SetIntOption (options, "StopBits", 0))) - { - switch (val) - { - case 1: - t.c_cflag &= ~(CSTOPB); - break; - case 2: - t.c_cflag |= CSTOPB; - break; - default: - xf86Msg (X_ERROR, - "Invalid Option StopBits value: %d\n", val); - return -1; - break; - } - } - - if ((val = xf86SetIntOption (options, "DataBits", 0))) - { - switch (val) - { - case 5: - t.c_cflag &= ~(CSIZE); - t.c_cflag |= CS5; - break; - case 6: - t.c_cflag &= ~(CSIZE); - t.c_cflag |= CS6; - break; - case 7: - t.c_cflag &= ~(CSIZE); - t.c_cflag |= CS7; - break; - case 8: - t.c_cflag &= ~(CSIZE); - t.c_cflag |= CS8; - break; - default: - xf86Msg (X_ERROR, - "Invalid Option DataBits value: %d\n", val); - return -1; - break; - } - } - - if ((s = xf86SetStrOption (options, "Parity", NULL))) - { - if (xf86NameCmp (s, "Odd") == 0) - { - t.c_cflag |= PARENB | PARODD; - } - else if (xf86NameCmp (s, "Even") == 0) - { - t.c_cflag |= PARENB; - t.c_cflag &= ~(PARODD); - } - else if (xf86NameCmp (s, "None") == 0) - { - t.c_cflag &= ~(PARENB); - } - else - { - xf86Msg (X_ERROR, "Invalid Option Parity value: %s\n", - s); - return -1; - } - } - - if ((val = xf86SetIntOption (options, "Vmin", -1)) != -1) - { - t.c_cc[VMIN] = val; - } - if ((val = xf86SetIntOption (options, "Vtime", -1)) != -1) - { - t.c_cc[VTIME] = val; - } - - if ((s = xf86SetStrOption (options, "FlowControl", NULL))) - { - xf86MarkOptionUsedByName (options, "FlowControl"); - if (xf86NameCmp (s, "Xoff") == 0) - { - t.c_iflag |= IXOFF; - } - else if (xf86NameCmp (s, "Xon") == 0) - { - t.c_iflag |= IXON; - } - else if (xf86NameCmp (s, "XonXoff") == 0) - { - t.c_iflag |= IXON|IXOFF; - } - else if (xf86NameCmp (s, "None") == 0) - { - t.c_iflag &= ~(IXON | IXOFF); - } - else - { - xf86Msg (X_ERROR, - "Invalid Option FlowControl value: %s\n", s); - return -1; - } - } - - if ((xf86SetBoolOption (options, "ClearDTR", FALSE))) - { + struct termios t; + int val; + const char *s; + int baud, r; + + if (fd < 0) + return -1; + + /* Don't try to set parameters for non-tty devices. */ + if (!isatty(fd)) + return 0; + + SYSCALL(tcgetattr(fd, &t)); + + if ((val = xf86SetIntOption(options, "BaudRate", 0))) { + if ((baud = GetBaud(val))) { + cfsetispeed(&t, baud); + cfsetospeed(&t, baud); + } + else { + xf86Msg(X_ERROR, "Invalid Option BaudRate value: %d\n", val); + return -1; + } + } + + if ((val = xf86SetIntOption(options, "StopBits", 0))) { + switch (val) { + case 1: + t.c_cflag &= ~(CSTOPB); + break; + case 2: + t.c_cflag |= CSTOPB; + break; + default: + xf86Msg(X_ERROR, "Invalid Option StopBits value: %d\n", val); + return -1; + break; + } + } + + if ((val = xf86SetIntOption(options, "DataBits", 0))) { + switch (val) { + case 5: + t.c_cflag &= ~(CSIZE); + t.c_cflag |= CS5; + break; + case 6: + t.c_cflag &= ~(CSIZE); + t.c_cflag |= CS6; + break; + case 7: + t.c_cflag &= ~(CSIZE); + t.c_cflag |= CS7; + break; + case 8: + t.c_cflag &= ~(CSIZE); + t.c_cflag |= CS8; + break; + default: + xf86Msg(X_ERROR, "Invalid Option DataBits value: %d\n", val); + return -1; + break; + } + } + + if ((s = xf86SetStrOption(options, "Parity", NULL))) { + if (xf86NameCmp(s, "Odd") == 0) { + t.c_cflag |= PARENB | PARODD; + } + else if (xf86NameCmp(s, "Even") == 0) { + t.c_cflag |= PARENB; + t.c_cflag &= ~(PARODD); + } + else if (xf86NameCmp(s, "None") == 0) { + t.c_cflag &= ~(PARENB); + } + else { + xf86Msg(X_ERROR, "Invalid Option Parity value: %s\n", s); + return -1; + } + } + + if ((val = xf86SetIntOption(options, "Vmin", -1)) != -1) { + t.c_cc[VMIN] = val; + } + if ((val = xf86SetIntOption(options, "Vtime", -1)) != -1) { + t.c_cc[VTIME] = val; + } + + if ((s = xf86SetStrOption(options, "FlowControl", NULL))) { + xf86MarkOptionUsedByName(options, "FlowControl"); + if (xf86NameCmp(s, "Xoff") == 0) { + t.c_iflag |= IXOFF; + } + else if (xf86NameCmp(s, "Xon") == 0) { + t.c_iflag |= IXON; + } + else if (xf86NameCmp(s, "XonXoff") == 0) { + t.c_iflag |= IXON | IXOFF; + } + else if (xf86NameCmp(s, "None") == 0) { + t.c_iflag &= ~(IXON | IXOFF); + } + else { + xf86Msg(X_ERROR, "Invalid Option FlowControl value: %s\n", s); + return -1; + } + } + + if ((xf86SetBoolOption(options, "ClearDTR", FALSE))) { #ifdef CLEARDTR_SUPPORT -# if defined(TIOCMBIC) - val = TIOCM_DTR; - SYSCALL (ioctl(fd, TIOCMBIC, &val)); -# else - SYSCALL (ioctl(fd, TIOCCDTR, NULL)); -# endif +#if defined(TIOCMBIC) + val = TIOCM_DTR; + SYSCALL(ioctl(fd, TIOCMBIC, &val)); +#else + SYSCALL(ioctl(fd, TIOCCDTR, NULL)); +#endif #else - xf86Msg (X_WARNING, - "Option ClearDTR not supported on this OS\n"); - return -1; + xf86Msg(X_WARNING, "Option ClearDTR not supported on this OS\n"); + return -1; #endif - xf86MarkOptionUsedByName (options, "ClearDTR"); - } - - if ((xf86SetBoolOption (options, "ClearRTS", FALSE))) - { - xf86Msg (X_WARNING, - "Option ClearRTS not supported on this OS\n"); - return -1; - xf86MarkOptionUsedByName (options, "ClearRTS"); - } - - SYSCALL (r = tcsetattr (fd, TCSANOW, &t)); - return r; + xf86MarkOptionUsedByName(options, "ClearDTR"); + } + + if ((xf86SetBoolOption(options, "ClearRTS", FALSE))) { + xf86Msg(X_WARNING, "Option ClearRTS not supported on this OS\n"); + return -1; + xf86MarkOptionUsedByName(options, "ClearRTS"); + } + + SYSCALL(r = tcsetattr(fd, TCSANOW, &t)); + return r; } int -xf86SetSerialSpeed (int fd, int speed) +xf86SetSerialSpeed(int fd, int speed) { - struct termios t; - int baud, r; - - if (fd < 0) - return -1; - - /* Don't try to set parameters for non-tty devices. */ - if (!isatty(fd)) - return 0; - - SYSCALL (tcgetattr (fd, &t)); - - if ((baud = GetBaud (speed))) - { - cfsetispeed (&t, baud); - cfsetospeed (&t, baud); - } - else - { - xf86Msg (X_ERROR, - "Invalid Option BaudRate value: %d\n", speed); - return -1; - } - - SYSCALL (r = tcsetattr (fd, TCSANOW, &t)); - return r; + struct termios t; + int baud, r; + + if (fd < 0) + return -1; + + /* Don't try to set parameters for non-tty devices. */ + if (!isatty(fd)) + return 0; + + SYSCALL(tcgetattr(fd, &t)); + + if ((baud = GetBaud(speed))) { + cfsetispeed(&t, baud); + cfsetospeed(&t, baud); + } + else { + xf86Msg(X_ERROR, "Invalid Option BaudRate value: %d\n", speed); + return -1; + } + + SYSCALL(r = tcsetattr(fd, TCSANOW, &t)); + return r; } int -xf86ReadSerial (int fd, void *buf, int count) +xf86ReadSerial(int fd, void *buf, int count) { - int r; - int i; - - SYSCALL (r = read (fd, buf, count)); - DebugF("ReadingSerial: 0x%x", - (unsigned char)*(((unsigned char *)buf))); - for (i = 1; i < r; i++) - DebugF(", 0x%x",(unsigned char)*(((unsigned char *)buf) + i)); - DebugF("\n"); - return r; + int r; + int i; + + SYSCALL(r = read(fd, buf, count)); + DebugF("ReadingSerial: 0x%x", (unsigned char) *(((unsigned char *) buf))); + for (i = 1; i < r; i++) + DebugF(", 0x%x", (unsigned char) *(((unsigned char *) buf) + i)); + DebugF("\n"); + return r; } int -xf86WriteSerial (int fd, const void *buf, int count) +xf86WriteSerial(int fd, const void *buf, int count) { - int r; - int i; - - DebugF("WritingSerial: 0x%x",(unsigned char)*(((unsigned char *)buf))); - for (i = 1; i < count; i++) - DebugF(", 0x%x",(unsigned char)*(((unsigned char *)buf) + i)); - DebugF("\n"); - SYSCALL (r = write (fd, buf, count)); - return r; + int r; + int i; + + DebugF("WritingSerial: 0x%x", (unsigned char) *(((unsigned char *) buf))); + for (i = 1; i < count; i++) + DebugF(", 0x%x", (unsigned char) *(((unsigned char *) buf) + i)); + DebugF("\n"); + SYSCALL(r = write(fd, buf, count)); + return r; } int -xf86CloseSerial (int fd) +xf86CloseSerial(int fd) { - int r; + int r; - SYSCALL (r = close (fd)); - return r; + SYSCALL(r = close(fd)); + return r; } int -xf86WaitForInput (int fd, int timeout) +xf86WaitForInput(int fd, int timeout) { - fd_set readfds; - struct timeval to; - int r; - - FD_ZERO(&readfds); - - if (fd >= 0) { - FD_SET(fd, &readfds); - } - - to.tv_sec = timeout / 1000000; - to.tv_usec = timeout % 1000000; - - if (fd >= 0) { - SYSCALL (r = select (FD_SETSIZE, &readfds, NULL, NULL, &to)); - } - else { - SYSCALL (r = select (FD_SETSIZE, NULL, NULL, NULL, &to)); - } - xf86ErrorFVerb (9,"select returned %d\n", r); - return r; + fd_set readfds; + struct timeval to; + int r; + + FD_ZERO(&readfds); + + if (fd >= 0) { + FD_SET(fd, &readfds); + } + + to.tv_sec = timeout / 1000000; + to.tv_usec = timeout % 1000000; + + if (fd >= 0) { + SYSCALL(r = select(FD_SETSIZE, &readfds, NULL, NULL, &to)); + } + else { + SYSCALL(r = select(FD_SETSIZE, NULL, NULL, NULL, &to)); + } + xf86ErrorFVerb(9, "select returned %d\n", r); + return r; } int -xf86SerialSendBreak (int fd, int duration) +xf86SerialSendBreak(int fd, int duration) { - int r; + int r; + + SYSCALL(r = tcsendbreak(fd, duration)); + return r; - SYSCALL (r = tcsendbreak (fd, duration)); - return r; - } int xf86FlushInput(int fd) { - fd_set fds; - struct timeval timeout; - char c[4]; - - DebugF("FlushingSerial\n"); - if (tcflush(fd, TCIFLUSH) == 0) - return 0; - - timeout.tv_sec = 0; - timeout.tv_usec = 0; - FD_ZERO(&fds); - FD_SET(fd, &fds); - while (select(FD_SETSIZE, &fds, NULL, NULL, &timeout) > 0) { - if (read(fd, &c, sizeof(c)) < 1) - return 0; - FD_ZERO(&fds); - FD_SET(fd, &fds); - } - return 0; + fd_set fds; + struct timeval timeout; + char c[4]; + + DebugF("FlushingSerial\n"); + if (tcflush(fd, TCIFLUSH) == 0) + return 0; + + timeout.tv_sec = 0; + timeout.tv_usec = 0; + FD_ZERO(&fds); + FD_SET(fd, &fds); + while (select(FD_SETSIZE, &fds, NULL, NULL, &timeout) > 0) { + if (read(fd, &c, sizeof(c)) < 1) + return 0; + FD_ZERO(&fds); + FD_SET(fd, &fds); + } + return 0; } static struct states { - int xf; - int os; + int xf; + int os; } modemStates[] = { #ifdef TIOCM_LE - { XF86_M_LE, TIOCM_LE }, + { + XF86_M_LE, TIOCM_LE}, #endif #ifdef TIOCM_DTR - { XF86_M_DTR, TIOCM_DTR }, + { + XF86_M_DTR, TIOCM_DTR}, #endif #ifdef TIOCM_RTS - { XF86_M_RTS, TIOCM_RTS }, + { + XF86_M_RTS, TIOCM_RTS}, #endif #ifdef TIOCM_ST - { XF86_M_ST, TIOCM_ST }, + { + XF86_M_ST, TIOCM_ST}, #endif #ifdef TIOCM_SR - { XF86_M_SR, TIOCM_SR }, + { + XF86_M_SR, TIOCM_SR}, #endif #ifdef TIOCM_CTS - { XF86_M_CTS, TIOCM_CTS }, + { + XF86_M_CTS, TIOCM_CTS}, #endif #ifdef TIOCM_CAR - { XF86_M_CAR, TIOCM_CAR }, + { + XF86_M_CAR, TIOCM_CAR}, #elif defined(TIOCM_CD) - { XF86_M_CAR, TIOCM_CD }, + { + XF86_M_CAR, TIOCM_CD}, #endif #ifdef TIOCM_RNG - { XF86_M_RNG, TIOCM_RNG }, + { + XF86_M_RNG, TIOCM_RNG}, #elif defined(TIOCM_RI) - { XF86_M_CAR, TIOCM_RI }, + { + XF86_M_CAR, TIOCM_RI}, #endif #ifdef TIOCM_DSR - { XF86_M_DSR, TIOCM_DSR }, + { + XF86_M_DSR, TIOCM_DSR}, #endif }; @@ -521,35 +493,36 @@ static int numStates = sizeof(modemStates) / sizeof(modemStates[0]); static int xf2osState(int state) { - int i; - int ret = 0; + int i; + int ret = 0; - for (i = 0; i < numStates; i++) - if (state & modemStates[i].xf) - ret |= modemStates[i].os; - return ret; + for (i = 0; i < numStates; i++) + if (state & modemStates[i].xf) + ret |= modemStates[i].os; + return ret; } static int os2xfState(int state) { - int i; - int ret = 0; + int i; + int ret = 0; - for (i = 0; i < numStates; i++) - if (state & modemStates[i].os) - ret |= modemStates[i].xf; - return ret; + for (i = 0; i < numStates; i++) + if (state & modemStates[i].os) + ret |= modemStates[i].xf; + return ret; } static int getOsStateMask(void) { - int i; - int ret = 0; - for (i = 0; i < numStates; i++) - ret |= modemStates[i].os; - return ret; + int i; + int ret = 0; + + for (i = 0; i < numStates; i++) + ret |= modemStates[i].os; + return ret; } static int osStateMask = 0; @@ -557,99 +530,99 @@ static int osStateMask = 0; int xf86SetSerialModemState(int fd, int state) { - int ret; - int s; + int ret; + int s; - if (fd < 0) - return -1; + if (fd < 0) + return -1; - /* Don't try to set parameters for non-tty devices. */ - if (!isatty(fd)) - return 0; + /* Don't try to set parameters for non-tty devices. */ + if (!isatty(fd)) + return 0; #ifndef TIOCMGET - return -1; + return -1; #else - if (!osStateMask) - osStateMask = getOsStateMask(); - - state = xf2osState(state); - SYSCALL((ret = ioctl(fd, TIOCMGET, &s))); - if (ret < 0) - return -1; - s &= ~osStateMask; - s |= state; - SYSCALL((ret = ioctl(fd, TIOCMSET, &s))); - if (ret < 0) - return -1; - else - return 0; + if (!osStateMask) + osStateMask = getOsStateMask(); + + state = xf2osState(state); + SYSCALL((ret = ioctl(fd, TIOCMGET, &s))); + if (ret < 0) + return -1; + s &= ~osStateMask; + s |= state; + SYSCALL((ret = ioctl(fd, TIOCMSET, &s))); + if (ret < 0) + return -1; + else + return 0; #endif } int xf86GetSerialModemState(int fd) { - int ret; - int s; + int ret; + int s; - if (fd < 0) - return -1; + if (fd < 0) + return -1; - /* Don't try to set parameters for non-tty devices. */ - if (!isatty(fd)) - return 0; + /* Don't try to set parameters for non-tty devices. */ + if (!isatty(fd)) + return 0; #ifndef TIOCMGET - return -1; + return -1; #else - SYSCALL((ret = ioctl(fd, TIOCMGET, &s))); - if (ret < 0) - return -1; - return os2xfState(s); + SYSCALL((ret = ioctl(fd, TIOCMGET, &s))); + if (ret < 0) + return -1; + return os2xfState(s); #endif } int xf86SerialModemSetBits(int fd, int bits) { - int ret; - int s; + int ret; + int s; - if (fd < 0) - return -1; + if (fd < 0) + return -1; - /* Don't try to set parameters for non-tty devices. */ - if (!isatty(fd)) - return 0; + /* Don't try to set parameters for non-tty devices. */ + if (!isatty(fd)) + return 0; #ifndef TIOCMGET - return -1; + return -1; #else - s = xf2osState(bits); - SYSCALL((ret = ioctl(fd, TIOCMBIS, &s))); - return ret; + s = xf2osState(bits); + SYSCALL((ret = ioctl(fd, TIOCMBIS, &s))); + return ret; #endif } int xf86SerialModemClearBits(int fd, int bits) { - int ret; - int s; + int ret; + int s; - if (fd < 0) - return -1; + if (fd < 0) + return -1; - /* Don't try to set parameters for non-tty devices. */ - if (!isatty(fd)) - return 0; + /* Don't try to set parameters for non-tty devices. */ + if (!isatty(fd)) + return 0; #ifndef TIOCMGET - return -1; + return -1; #else - s = xf2osState(bits); - SYSCALL((ret = ioctl(fd, TIOCMBIC, &s))); - return ret; + s = xf2osState(bits); + SYSCALL((ret = ioctl(fd, TIOCMBIC, &s))); + return ret; #endif } diff --git a/xorg-server/hw/xfree86/os-support/shared/sigio.c b/xorg-server/hw/xfree86/os-support/shared/sigio.c index ef04c1140..12ae8a480 100644 --- a/xorg-server/hw/xfree86/os-support/shared/sigio.c +++ b/xorg-server/hw/xfree86/os-support/shared/sigio.c @@ -1,309 +1,301 @@ -/* sigio.c -- Support for SIGIO handler installation and removal
- * Created: Thu Jun 3 15:39:18 1999 by faith@precisioninsight.com
- *
- * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- * Authors: Rickard E. (Rik) Faith <faith@valinux.com>
- */
-/*
- * Copyright (c) 2002 by The XFree86 Project, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Except as contained in this notice, the name of the copyright holder(s)
- * and author(s) shall not be used in advertising or otherwise to promote
- * the sale, use or other dealings in this Software without prior written
- * authorization from the copyright holder(s) and author(s).
- */
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-# include <X11/X.h>
-# include "xf86.h"
-# include "xf86Priv.h"
-# include "xf86_OSlib.h"
-# include "inputstr.h"
-
-#ifdef HAVE_STROPTS_H
-# include <stropts.h>
-#endif
-
-#ifdef MAXDEVICES
-/* MAXDEVICES represents the maximimum number of input devices usable
- * at the same time plus one entry for DRM support.
- */
-# define MAX_FUNCS (MAXDEVICES + 1)
-#else
-# define MAX_FUNCS 16
-#endif
-
-typedef struct _xf86SigIOFunc {
- void (*f) (int, void *);
- int fd;
- void *closure;
-} Xf86SigIOFunc;
-
-static Xf86SigIOFunc xf86SigIOFuncs[MAX_FUNCS];
-static int xf86SigIOMax;
-static int xf86SigIOMaxFd;
-static fd_set xf86SigIOMask;
-
-/*
- * SIGIO gives no way of discovering which fd signalled, select
- * to discover
- */
-static void
-xf86SIGIO (int sig)
-{
- int i;
- fd_set ready;
- struct timeval to;
- int save_errno = errno; /* do not clobber the global errno */
- int r;
-
- ready = xf86SigIOMask;
- to.tv_sec = 0;
- to.tv_usec = 0;
- SYSCALL (r = select (xf86SigIOMaxFd, &ready, 0, 0, &to));
- for (i = 0; r > 0 && i < xf86SigIOMax; i++)
- if (xf86SigIOFuncs[i].f && FD_ISSET (xf86SigIOFuncs[i].fd, &ready))
- {
- (*xf86SigIOFuncs[i].f)(xf86SigIOFuncs[i].fd,
- xf86SigIOFuncs[i].closure);
- r--;
- }
- if (r > 0) {
- xf86Msg(X_ERROR, "SIGIO %d descriptors not handled\n", r);
- }
- /* restore global errno */
- errno = save_errno;
-}
-
-static int
-xf86IsPipe (int fd)
-{
- struct stat buf;
-
- if (fstat (fd, &buf) < 0)
- return 0;
- return S_ISFIFO(buf.st_mode);
-}
-
-int
-xf86InstallSIGIOHandler(int fd, void (*f)(int, void *), void *closure)
-{
- struct sigaction sa;
- struct sigaction osa;
- int i;
- int blocked;
- int installed = FALSE;
-
- if (!xf86Info.useSIGIO)
- return 0;
-
- for (i = 0; i < MAX_FUNCS; i++)
- {
- if (!xf86SigIOFuncs[i].f)
- {
- if (xf86IsPipe (fd))
- return 0;
- blocked = xf86BlockSIGIO();
-#ifdef O_ASYNC
- if (fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_ASYNC) == -1) {
- xf86Msg(X_WARNING, "fcntl(%d, O_ASYNC): %s\n",
- fd, strerror(errno));
- } else {
- if (fcntl(fd, F_SETOWN, getpid()) == -1) {
- xf86Msg(X_WARNING, "fcntl(%d, F_SETOWN): %s\n",
- fd, strerror(errno));
- } else {
- installed = TRUE;
- }
- }
-#endif
-#ifdef I_SETSIG /* System V Streams - used on Solaris for input devices */
- if (!installed && isastream(fd)) {
- if (ioctl(fd, I_SETSIG, S_INPUT | S_ERROR | S_HANGUP) == -1) {
- xf86Msg(X_WARNING, "fcntl(%d, I_SETSIG): %s\n",
- fd, strerror(errno));
- } else {
- installed = TRUE;
- }
- }
-#endif
- if (!installed) {
- xf86UnblockSIGIO(blocked);
- return 0;
- }
- sigemptyset(&sa.sa_mask);
- sigaddset(&sa.sa_mask, SIGIO);
- sa.sa_flags = 0;
- sa.sa_handler = xf86SIGIO;
- sigaction(SIGIO, &sa, &osa);
- xf86SigIOFuncs[i].fd = fd;
- xf86SigIOFuncs[i].closure = closure;
- xf86SigIOFuncs[i].f = f;
- if (i >= xf86SigIOMax)
- xf86SigIOMax = i+1;
- if (fd >= xf86SigIOMaxFd)
- xf86SigIOMaxFd = fd + 1;
- FD_SET (fd, &xf86SigIOMask);
- xf86UnblockSIGIO(blocked);
- return 1;
- }
- /* Allow overwriting of the closure and callback */
- else if (xf86SigIOFuncs[i].fd == fd)
- {
- xf86SigIOFuncs[i].closure = closure;
- xf86SigIOFuncs[i].f = f;
- return 1;
- }
- }
- return 0;
-}
-
-int
-xf86RemoveSIGIOHandler(int fd)
-{
- struct sigaction sa;
- struct sigaction osa;
- int i;
- int max;
- int maxfd;
- int ret;
-
- if (!xf86Info.useSIGIO)
- return 0;
-
- max = 0;
- maxfd = -1;
- ret = 0;
- for (i = 0; i < MAX_FUNCS; i++)
- {
- if (xf86SigIOFuncs[i].f)
- {
- if (xf86SigIOFuncs[i].fd == fd)
- {
- xf86SigIOFuncs[i].f = 0;
- xf86SigIOFuncs[i].fd = 0;
- xf86SigIOFuncs[i].closure = 0;
- FD_CLR (fd, &xf86SigIOMask);
- ret = 1;
- }
- else
- {
- max = i + 1;
- if (xf86SigIOFuncs[i].fd >= maxfd)
- maxfd = xf86SigIOFuncs[i].fd + 1;
- }
- }
- }
- if (ret)
- {
-#ifdef O_ASYNC
- fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) & ~O_ASYNC);
-#endif
-#ifdef I_SETSIG
- if (isastream(fd)) {
- if (ioctl(fd, I_SETSIG, 0) == -1) {
- xf86Msg(X_WARNING, "fcntl(%d, I_SETSIG, 0): %s\n",
- fd, strerror(errno));
- }
- }
-#endif
- xf86SigIOMax = max;
- xf86SigIOMaxFd = maxfd;
- if (!max)
- {
- sigemptyset(&sa.sa_mask);
- sigaddset(&sa.sa_mask, SIGIO);
- sa.sa_flags = 0;
- sa.sa_handler = SIG_IGN;
- sigaction(SIGIO, &sa, &osa);
- }
- }
- return ret;
-}
-
-int
-xf86BlockSIGIO (void)
-{
- sigset_t set, old;
- int ret;
-
- sigemptyset (&set);
- sigaddset (&set, SIGIO);
- sigprocmask (SIG_BLOCK, &set, &old);
- ret = sigismember (&old, SIGIO);
- return ret;
-}
-
-void
-xf86UnblockSIGIO (int wasset)
-{
- sigset_t set;
-
- if (!wasset)
- {
- sigemptyset (&set);
- sigaddset (&set, SIGIO);
- sigprocmask (SIG_UNBLOCK, &set, NULL);
- }
-}
-
-void
-xf86AssertBlockedSIGIO (char *where)
-{
- sigset_t set, old;
-
- sigemptyset (&set);
- sigprocmask (SIG_BLOCK, &set, &old);
- if (!sigismember (&old, SIGIO))
- xf86Msg (X_ERROR, "SIGIO not blocked at %s\n", where);
-}
-
-/* XXX This is a quick hack for the benefit of xf86SetSilkenMouse() */
-
-int
-xf86SIGIOSupported (void)
-{
- return 1;
-}
+/* sigio.c -- Support for SIGIO handler installation and removal + * Created: Thu Jun 3 15:39:18 1999 by faith@precisioninsight.com + * + * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: Rickard E. (Rik) Faith <faith@valinux.com> + */ +/* + * Copyright (c) 2002 by The XFree86 Project, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of the copyright holder(s) + * and author(s) shall not be used in advertising or otherwise to promote + * the sale, use or other dealings in this Software without prior written + * authorization from the copyright holder(s) and author(s). + */ + +#ifdef HAVE_XORG_CONFIG_H +#include <xorg-config.h> +#endif + +#include <X11/X.h> +#include "xf86.h" +#include "xf86Priv.h" +#include "xf86_OSlib.h" +#include "inputstr.h" + +#ifdef HAVE_STROPTS_H +#include <stropts.h> +#endif + +#ifdef MAXDEVICES +/* MAXDEVICES represents the maximimum number of input devices usable + * at the same time plus one entry for DRM support. + */ +#define MAX_FUNCS (MAXDEVICES + 1) +#else +#define MAX_FUNCS 16 +#endif + +typedef struct _xf86SigIOFunc { + void (*f) (int, void *); + int fd; + void *closure; +} Xf86SigIOFunc; + +static Xf86SigIOFunc xf86SigIOFuncs[MAX_FUNCS]; +static int xf86SigIOMax; +static int xf86SigIOMaxFd; +static fd_set xf86SigIOMask; + +/* + * SIGIO gives no way of discovering which fd signalled, select + * to discover + */ +static void +xf86SIGIO(int sig) +{ + int i; + fd_set ready; + struct timeval to; + int save_errno = errno; /* do not clobber the global errno */ + int r; + + ready = xf86SigIOMask; + to.tv_sec = 0; + to.tv_usec = 0; + SYSCALL(r = select(xf86SigIOMaxFd, &ready, 0, 0, &to)); + for (i = 0; r > 0 && i < xf86SigIOMax; i++) + if (xf86SigIOFuncs[i].f && FD_ISSET(xf86SigIOFuncs[i].fd, &ready)) { + (*xf86SigIOFuncs[i].f) (xf86SigIOFuncs[i].fd, + xf86SigIOFuncs[i].closure); + r--; + } + if (r > 0) { + xf86Msg(X_ERROR, "SIGIO %d descriptors not handled\n", r); + } + /* restore global errno */ + errno = save_errno; +} + +static int +xf86IsPipe(int fd) +{ + struct stat buf; + + if (fstat(fd, &buf) < 0) + return 0; + return S_ISFIFO(buf.st_mode); +} + +int +xf86InstallSIGIOHandler(int fd, void (*f) (int, void *), void *closure) +{ + struct sigaction sa; + struct sigaction osa; + int i; + int blocked; + int installed = FALSE; + + if (!xf86Info.useSIGIO) + return 0; + + for (i = 0; i < MAX_FUNCS; i++) { + if (!xf86SigIOFuncs[i].f) { + if (xf86IsPipe(fd)) + return 0; + blocked = xf86BlockSIGIO(); +#ifdef O_ASYNC + if (fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_ASYNC) == -1) { + xf86Msg(X_WARNING, "fcntl(%d, O_ASYNC): %s\n", + fd, strerror(errno)); + } + else { + if (fcntl(fd, F_SETOWN, getpid()) == -1) { + xf86Msg(X_WARNING, "fcntl(%d, F_SETOWN): %s\n", + fd, strerror(errno)); + } + else { + installed = TRUE; + } + } +#endif +#ifdef I_SETSIG /* System V Streams - used on Solaris for input devices */ + if (!installed && isastream(fd)) { + if (ioctl(fd, I_SETSIG, S_INPUT | S_ERROR | S_HANGUP) == -1) { + xf86Msg(X_WARNING, "fcntl(%d, I_SETSIG): %s\n", + fd, strerror(errno)); + } + else { + installed = TRUE; + } + } +#endif + if (!installed) { + xf86UnblockSIGIO(blocked); + return 0; + } + sigemptyset(&sa.sa_mask); + sigaddset(&sa.sa_mask, SIGIO); + sa.sa_flags = 0; + sa.sa_handler = xf86SIGIO; + sigaction(SIGIO, &sa, &osa); + xf86SigIOFuncs[i].fd = fd; + xf86SigIOFuncs[i].closure = closure; + xf86SigIOFuncs[i].f = f; + if (i >= xf86SigIOMax) + xf86SigIOMax = i + 1; + if (fd >= xf86SigIOMaxFd) + xf86SigIOMaxFd = fd + 1; + FD_SET(fd, &xf86SigIOMask); + xf86UnblockSIGIO(blocked); + return 1; + } + /* Allow overwriting of the closure and callback */ + else if (xf86SigIOFuncs[i].fd == fd) { + xf86SigIOFuncs[i].closure = closure; + xf86SigIOFuncs[i].f = f; + return 1; + } + } + return 0; +} + +int +xf86RemoveSIGIOHandler(int fd) +{ + struct sigaction sa; + struct sigaction osa; + int i; + int max; + int maxfd; + int ret; + + if (!xf86Info.useSIGIO) + return 0; + + max = 0; + maxfd = -1; + ret = 0; + for (i = 0; i < MAX_FUNCS; i++) { + if (xf86SigIOFuncs[i].f) { + if (xf86SigIOFuncs[i].fd == fd) { + xf86SigIOFuncs[i].f = 0; + xf86SigIOFuncs[i].fd = 0; + xf86SigIOFuncs[i].closure = 0; + FD_CLR(fd, &xf86SigIOMask); + ret = 1; + } + else { + max = i + 1; + if (xf86SigIOFuncs[i].fd >= maxfd) + maxfd = xf86SigIOFuncs[i].fd + 1; + } + } + } + if (ret) { +#ifdef O_ASYNC + fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) & ~O_ASYNC); +#endif +#ifdef I_SETSIG + if (isastream(fd)) { + if (ioctl(fd, I_SETSIG, 0) == -1) { + xf86Msg(X_WARNING, "fcntl(%d, I_SETSIG, 0): %s\n", + fd, strerror(errno)); + } + } +#endif + xf86SigIOMax = max; + xf86SigIOMaxFd = maxfd; + if (!max) { + sigemptyset(&sa.sa_mask); + sigaddset(&sa.sa_mask, SIGIO); + sa.sa_flags = 0; + sa.sa_handler = SIG_IGN; + sigaction(SIGIO, &sa, &osa); + } + } + return ret; +} + +int +xf86BlockSIGIO(void) +{ + sigset_t set, old; + int ret; + + sigemptyset(&set); + sigaddset(&set, SIGIO); + sigprocmask(SIG_BLOCK, &set, &old); + ret = sigismember(&old, SIGIO); + return ret; +} + +void +xf86UnblockSIGIO(int wasset) +{ + sigset_t set; + + if (!wasset) { + sigemptyset(&set); + sigaddset(&set, SIGIO); + sigprocmask(SIG_UNBLOCK, &set, NULL); + } +} + +void +xf86AssertBlockedSIGIO(char *where) +{ + sigset_t set, old; + + sigemptyset(&set); + sigprocmask(SIG_BLOCK, &set, &old); + if (!sigismember(&old, SIGIO)) + xf86Msg(X_ERROR, "SIGIO not blocked at %s\n", where); +} + +/* XXX This is a quick hack for the benefit of xf86SetSilkenMouse() */ + +int +xf86SIGIOSupported(void) +{ + return 1; +} diff --git a/xorg-server/hw/xfree86/os-support/shared/vidmem.c b/xorg-server/hw/xfree86/os-support/shared/vidmem.c index 54f6c6497..a7717d8f6 100644 --- a/xorg-server/hw/xfree86/os-support/shared/vidmem.c +++ b/xorg-server/hw/xfree86/os-support/shared/vidmem.c @@ -25,7 +25,6 @@ * authorization from the copyright holder(s) and author(s). */ - #ifdef HAVE_XORG_CONFIG_H #include <xorg-config.h> #endif @@ -51,240 +50,236 @@ */ typedef struct { - unsigned long size; - pointer virtBase; - pointer mtrrInfo; + unsigned long size; + pointer virtBase; + pointer mtrrInfo; } MappingRec, *MappingPtr; - + typedef struct { - int numMappings; - MappingPtr * mappings; - Bool mtrrEnabled; - MessageType mtrrFrom; - Bool mtrrOptChecked; - ScrnInfoPtr pScrn; + int numMappings; + MappingPtr *mappings; + Bool mtrrEnabled; + MessageType mtrrFrom; + Bool mtrrOptChecked; + ScrnInfoPtr pScrn; } VidMapRec, *VidMapPtr; static int vidMapIndex = -1; #define VIDMAPPTR(p) ((VidMapPtr)((p)->privates[vidMapIndex].ptr)) -static VidMemInfo vidMemInfo = {FALSE, }; -static VidMapRec vidMapRec = {0, NULL, TRUE, X_DEFAULT, FALSE, NULL}; +static VidMemInfo vidMemInfo = { FALSE, }; +static VidMapRec vidMapRec = { 0, NULL, TRUE, X_DEFAULT, FALSE, NULL }; static VidMapPtr getVidMapRec(int scrnIndex) { - VidMapPtr vp; - ScrnInfoPtr pScrn; + VidMapPtr vp; + ScrnInfoPtr pScrn; - if ((scrnIndex < 0) || - !(pScrn = xf86Screens[scrnIndex])) - return &vidMapRec; + if ((scrnIndex < 0) || !(pScrn = xf86Screens[scrnIndex])) + return &vidMapRec; - if (vidMapIndex < 0) - vidMapIndex = xf86AllocateScrnInfoPrivateIndex(); + if (vidMapIndex < 0) + vidMapIndex = xf86AllocateScrnInfoPrivateIndex(); - if (VIDMAPPTR(pScrn) != NULL) - return VIDMAPPTR(pScrn); + if (VIDMAPPTR(pScrn) != NULL) + return VIDMAPPTR(pScrn); - vp = pScrn->privates[vidMapIndex].ptr = xnfcalloc(sizeof(VidMapRec), 1); - vp->mtrrEnabled = TRUE; /* default to enabled */ - vp->mtrrFrom = X_DEFAULT; - vp->mtrrOptChecked = FALSE; - vp->pScrn = pScrn; - return vp; + vp = pScrn->privates[vidMapIndex].ptr = xnfcalloc(sizeof(VidMapRec), 1); + vp->mtrrEnabled = TRUE; /* default to enabled */ + vp->mtrrFrom = X_DEFAULT; + vp->mtrrOptChecked = FALSE; + vp->pScrn = pScrn; + return vp; } static MappingPtr newMapping(VidMapPtr vp) { - vp->mappings = xnfrealloc(vp->mappings, sizeof(MappingPtr) * - (vp->numMappings + 1)); - vp->mappings[vp->numMappings] = xnfcalloc(sizeof(MappingRec), 1); - return vp->mappings[vp->numMappings++]; + vp->mappings = xnfrealloc(vp->mappings, sizeof(MappingPtr) * + (vp->numMappings + 1)); + vp->mappings[vp->numMappings] = xnfcalloc(sizeof(MappingRec), 1); + return vp->mappings[vp->numMappings++]; } static MappingPtr findMapping(VidMapPtr vp, pointer vbase, unsigned long size) { - int i; - - for (i = 0; i < vp->numMappings; i++) { - if (vp->mappings[i]->virtBase == vbase && - vp->mappings[i]->size == size) - return vp->mappings[i]; - } - return NULL; + int i; + + for (i = 0; i < vp->numMappings; i++) { + if (vp->mappings[i]->virtBase == vbase && vp->mappings[i]->size == size) + return vp->mappings[i]; + } + return NULL; } static void removeMapping(VidMapPtr vp, MappingPtr mp) { - int i, found = 0; - - for (i = 0; i < vp->numMappings; i++) { - if (vp->mappings[i] == mp) { - found = 1; - free(vp->mappings[i]); - } else if (found) { - vp->mappings[i - 1] = vp->mappings[i]; - } - } - vp->numMappings--; - vp->mappings[vp->numMappings] = NULL; + int i, found = 0; + + for (i = 0; i < vp->numMappings; i++) { + if (vp->mappings[i] == mp) { + found = 1; + free(vp->mappings[i]); + } + else if (found) { + vp->mappings[i - 1] = vp->mappings[i]; + } + } + vp->numMappings--; + vp->mappings[vp->numMappings] = NULL; } enum { OPTION_MTRR }; -static const OptionInfoRec opts[] = -{ - { OPTION_MTRR, "mtrr", OPTV_BOOLEAN, {0}, FALSE }, - { -1, NULL, OPTV_NONE, {0}, FALSE } + +static const OptionInfoRec opts[] = { + {OPTION_MTRR, "mtrr", OPTV_BOOLEAN, {0}, FALSE}, + {-1, NULL, OPTV_NONE, {0}, FALSE} }; static void checkMtrrOption(VidMapPtr vp) { - if (!vp->mtrrOptChecked && vp->pScrn && vp->pScrn->options != NULL) { - OptionInfoPtr options; - - options = xnfalloc(sizeof(opts)); - (void)memcpy(options, opts, sizeof(opts)); - xf86ProcessOptions(vp->pScrn->scrnIndex, vp->pScrn->options, - options); - if (xf86GetOptValBool(options, OPTION_MTRR, &vp->mtrrEnabled)) - vp->mtrrFrom = X_CONFIG; - free(options); - vp->mtrrOptChecked = TRUE; - } + if (!vp->mtrrOptChecked && vp->pScrn && vp->pScrn->options != NULL) { + OptionInfoPtr options; + + options = xnfalloc(sizeof(opts)); + (void) memcpy(options, opts, sizeof(opts)); + xf86ProcessOptions(vp->pScrn->scrnIndex, vp->pScrn->options, options); + if (xf86GetOptValBool(options, OPTION_MTRR, &vp->mtrrEnabled)) + vp->mtrrFrom = X_CONFIG; + free(options); + vp->mtrrOptChecked = TRUE; + } } void -xf86MakeNewMapping(int ScreenNum, int Flags, unsigned long Base, unsigned long Size, pointer Vbase) +xf86MakeNewMapping(int ScreenNum, int Flags, unsigned long Base, + unsigned long Size, pointer Vbase) { - VidMapPtr vp; - MappingPtr mp; + VidMapPtr vp; + MappingPtr mp; - vp = getVidMapRec(ScreenNum); - mp = newMapping(vp); - mp->size = Size; - mp->virtBase = Vbase; + vp = getVidMapRec(ScreenNum); + mp = newMapping(vp); + mp->size = Size; + mp->virtBase = Vbase; } void xf86InitVidMem(void) { - if (!vidMemInfo.initialised) { - memset(&vidMemInfo, 0, sizeof(VidMemInfo)); - xf86OSInitVidMem(&vidMemInfo); - } + if (!vidMemInfo.initialised) { + memset(&vidMemInfo, 0, sizeof(VidMemInfo)); + xf86OSInitVidMem(&vidMemInfo); + } } pointer xf86MapVidMem(int ScreenNum, int Flags, unsigned long Base, unsigned long Size) { - pointer vbase = NULL; - VidMapPtr vp; - MappingPtr mp; - - if (((Flags & VIDMEM_FRAMEBUFFER) && - (Flags & (VIDMEM_MMIO | VIDMEM_MMIO_32BIT)))) - FatalError("Mapping memory with more than one type\n"); - - xf86InitVidMem(); - if (!vidMemInfo.initialised || !vidMemInfo.mapMem) - return NULL; - - vbase = vidMemInfo.mapMem(ScreenNum, Base, Size, Flags); - - if (!vbase || vbase == (pointer)-1) - return NULL; - - vp = getVidMapRec(ScreenNum); - mp = newMapping(vp); - mp->size = Size; - mp->virtBase = vbase; - - /* - * Check the "mtrr" option even when MTRR isn't supported to avoid - * warnings about unrecognised options. - */ - checkMtrrOption(vp); - - if (vp->mtrrEnabled && vidMemInfo.setWC) { - if (Flags & (VIDMEM_MMIO | VIDMEM_MMIO_32BIT)) - mp->mtrrInfo = - vidMemInfo.setWC(ScreenNum, Base, Size, FALSE, - vp->mtrrFrom); - else if (Flags & VIDMEM_FRAMEBUFFER) - mp->mtrrInfo = - vidMemInfo.setWC(ScreenNum, Base, Size, TRUE, - vp->mtrrFrom); - } - return vbase; + pointer vbase = NULL; + VidMapPtr vp; + MappingPtr mp; + + if (((Flags & VIDMEM_FRAMEBUFFER) && + (Flags & (VIDMEM_MMIO | VIDMEM_MMIO_32BIT)))) + FatalError("Mapping memory with more than one type\n"); + + xf86InitVidMem(); + if (!vidMemInfo.initialised || !vidMemInfo.mapMem) + return NULL; + + vbase = vidMemInfo.mapMem(ScreenNum, Base, Size, Flags); + + if (!vbase || vbase == (pointer) -1) + return NULL; + + vp = getVidMapRec(ScreenNum); + mp = newMapping(vp); + mp->size = Size; + mp->virtBase = vbase; + + /* + * Check the "mtrr" option even when MTRR isn't supported to avoid + * warnings about unrecognised options. + */ + checkMtrrOption(vp); + + if (vp->mtrrEnabled && vidMemInfo.setWC) { + if (Flags & (VIDMEM_MMIO | VIDMEM_MMIO_32BIT)) + mp->mtrrInfo = + vidMemInfo.setWC(ScreenNum, Base, Size, FALSE, vp->mtrrFrom); + else if (Flags & VIDMEM_FRAMEBUFFER) + mp->mtrrInfo = + vidMemInfo.setWC(ScreenNum, Base, Size, TRUE, vp->mtrrFrom); + } + return vbase; } void xf86UnMapVidMem(int ScreenNum, pointer Base, unsigned long Size) { - VidMapPtr vp; - MappingPtr mp; - - if (!vidMemInfo.initialised || !vidMemInfo.unmapMem) { - xf86DrvMsg(ScreenNum, X_WARNING, - "xf86UnMapVidMem() called before xf86MapVidMem()\n"); - return; - } - - vp = getVidMapRec(ScreenNum); - mp = findMapping(vp, Base, Size); - if (!mp) { - xf86DrvMsg(ScreenNum, X_WARNING, - "xf86UnMapVidMem: cannot find region for [%p,0x%lx]\n", - Base, Size); - return; - } - if (vp->mtrrEnabled && vidMemInfo.undoWC && mp) - vidMemInfo.undoWC(ScreenNum, mp->mtrrInfo); - - vidMemInfo.unmapMem(ScreenNum, Base, Size); - removeMapping(vp, mp); + VidMapPtr vp; + MappingPtr mp; + + if (!vidMemInfo.initialised || !vidMemInfo.unmapMem) { + xf86DrvMsg(ScreenNum, X_WARNING, + "xf86UnMapVidMem() called before xf86MapVidMem()\n"); + return; + } + + vp = getVidMapRec(ScreenNum); + mp = findMapping(vp, Base, Size); + if (!mp) { + xf86DrvMsg(ScreenNum, X_WARNING, + "xf86UnMapVidMem: cannot find region for [%p,0x%lx]\n", + Base, Size); + return; + } + if (vp->mtrrEnabled && vidMemInfo.undoWC && mp) + vidMemInfo.undoWC(ScreenNum, mp->mtrrInfo); + + vidMemInfo.unmapMem(ScreenNum, Base, Size); + removeMapping(vp, mp); } Bool xf86CheckMTRR(int ScreenNum) { - VidMapPtr vp = getVidMapRec(ScreenNum); - - /* - * Check the "mtrr" option even when MTRR isn't supported to avoid - * warnings about unrecognised options. - */ - checkMtrrOption(vp); - - if (vp->mtrrEnabled && vidMemInfo.setWC) - return TRUE; - - return FALSE; + VidMapPtr vp = getVidMapRec(ScreenNum); + + /* + * Check the "mtrr" option even when MTRR isn't supported to avoid + * warnings about unrecognised options. + */ + checkMtrrOption(vp); + + if (vp->mtrrEnabled && vidMemInfo.setWC) + return TRUE; + + return FALSE; } Bool xf86LinearVidMem(void) { - xf86InitVidMem(); - return vidMemInfo.linearSupported; + xf86InitVidMem(); + return vidMemInfo.linearSupported; } void xf86MapReadSideEffects(int ScreenNum, int Flags, pointer base, - unsigned long Size) + unsigned long Size) { - if (!(Flags & VIDMEM_READSIDEEFFECT)) - return; + if (!(Flags & VIDMEM_READSIDEEFFECT)) + return; - if (!vidMemInfo.initialised || !vidMemInfo.readSideEffects) - return; + if (!vidMemInfo.initialised || !vidMemInfo.readSideEffects) + return; - vidMemInfo.readSideEffects(ScreenNum, base, Size); + vidMemInfo.readSideEffects(ScreenNum, base, Size); } - diff --git a/xorg-server/hw/xfree86/os-support/shared/xf86Axp.c b/xorg-server/hw/xfree86/os-support/shared/xf86Axp.c index e6511dd43..5f2f3985e 100644 --- a/xorg-server/hw/xfree86/os-support/shared/xf86Axp.c +++ b/xorg-server/hw/xfree86/os-support/shared/xf86Axp.c @@ -31,19 +31,30 @@ #include "xf86Axp.h" -axpParams xf86AXPParams[] = { - {SYS_NONE, 0, 0, 0}, - {TSUNAMI, 0, 0, 0}, - {LCA, 1<<24,0xf8000000, 1UL << 32}, - {APECS, 1<<24,0xf8000000, 1UL << 32}, - {T2, 0,0xFC000000, 1UL << 31}, - {T2_GAMMA, 0,0xFC000000, 1UL << 31}, - {CIA, 0,0xE0000000, 1UL << 34}, - {MCPCIA, 0,0xf8000000, 1UL << 31}, - {JENSEN, 0, 0xE000000, 1UL << 32}, - {POLARIS, 0, 0, 0}, - {PYXIS, 0, 0, 0}, - {PYXIS_CIA, 0,0xE0000000, 1UL << 34}, - {IRONGATE, 0, 0, 0} +axpParams xf86AXPParams[] = { + {SYS_NONE, 0, 0, 0} + , + {TSUNAMI, 0, 0, 0} + , + {LCA, 1 << 24, 0xf8000000, 1UL << 32} + , + {APECS, 1 << 24, 0xf8000000, 1UL << 32} + , + {T2, 0, 0xFC000000, 1UL << 31} + , + {T2_GAMMA, 0, 0xFC000000, 1UL << 31} + , + {CIA, 0, 0xE0000000, 1UL << 34} + , + {MCPCIA, 0, 0xf8000000, 1UL << 31} + , + {JENSEN, 0, 0xE000000, 1UL << 32} + , + {POLARIS, 0, 0, 0} + , + {PYXIS, 0, 0, 0} + , + {PYXIS_CIA, 0, 0xE0000000, 1UL << 34} + , + {IRONGATE, 0, 0, 0} }; - |