diff options
Diffstat (limited to 'xorg-server/hw/xfree86/os-support')
38 files changed, 6122 insertions, 6228 deletions
diff --git a/xorg-server/hw/xfree86/os-support/bsd/alpha_video.c b/xorg-server/hw/xfree86/os-support/bsd/alpha_video.c index 882fb3b46..91f9fc826 100644 --- a/xorg-server/hw/xfree86/os-support/bsd/alpha_video.c +++ b/xorg-server/hw/xfree86/os-support/bsd/alpha_video.c @@ -65,21 +65,21 @@ memory_base(void) static unsigned long base = 0; if (base == 0) { - size_t len = sizeof(base); - int error; + size_t len = sizeof(base); + int error; + #ifdef __OpenBSD__ - int mib[3]; + int mib[3]; - mib[0] = CTL_MACHDEP; - mib[1] = CPU_CHIPSET; - mib[2] = CPU_CHIPSET_MEM; + mib[0] = CTL_MACHDEP; + mib[1] = CPU_CHIPSET; + mib[2] = CPU_CHIPSET_MEM; - if ((error = sysctl(mib, 3, &base, &len, NULL, 0)) < 0) + if ((error = sysctl(mib, 3, &base, &len, NULL, 0)) < 0) #else - if ((error = sysctlbyname("hw.chipset.memory", &base, &len, - 0, 0)) < 0) + if ((error = sysctlbyname("hw.chipset.memory", &base, &len, 0, 0)) < 0) #endif - FatalError("xf86MapVidMem: can't find memory\n"); + FatalError("xf86MapVidMem: can't find memory\n"); } return base; @@ -91,6 +91,7 @@ has_bwx(void) static int bwx = 0; size_t len = sizeof(bwx); int error; + #ifdef __OpenBSD__ int mib[3]; @@ -99,76 +100,74 @@ has_bwx(void) mib[2] = CPU_CHIPSET_BWX; if ((error = sysctl(mib, 3, &bwx, &len, NULL, 0)) < 0) - return FALSE; + return FALSE; else - return bwx; + return bwx; #else if ((error = sysctlbyname("hw.chipset.bwx", &bwx, &len, 0, 0)) < 0) - return FALSE; + return FALSE; else - return bwx; + return bwx; #endif } -#else /* __NetBSD__ */ +#else /* __NetBSD__ */ static unsigned long hae_thresh = (1UL << 24); -static unsigned long hae_mask = 0xf8000000UL; /* XXX - should use xf86AXP.c */ +static unsigned long hae_mask = 0xf8000000UL; /* XXX - should use xf86AXP.c */ static struct alpha_bus_window *abw; static int abw_count = -1; static void init_abw(void) { - if (abw_count < 0) { - abw_count = alpha_bus_getwindows(ALPHA_BUS_TYPE_PCI_MEM, &abw); - if (abw_count <= 0) - FatalError("init_abw: alpha_bus_getwindows failed\n"); - } + if (abw_count < 0) { + abw_count = alpha_bus_getwindows(ALPHA_BUS_TYPE_PCI_MEM, &abw); + if (abw_count <= 0) + FatalError("init_abw: alpha_bus_getwindows failed\n"); + } } static int has_bwx(void) { - if (abw_count < 0) - init_abw(); + if (abw_count < 0) + init_abw(); - xf86Msg(X_INFO, "has_bwx = %d\n", - abw[0].abw_abst.abst_flags & ABST_BWX ? 1 : 0); /* XXXX */ - return abw[0].abw_abst.abst_flags & ABST_BWX; + xf86Msg(X_INFO, "has_bwx = %d\n", abw[0].abw_abst.abst_flags & ABST_BWX ? 1 : 0); /* XXXX */ + return abw[0].abw_abst.abst_flags & ABST_BWX; } static unsigned long dense_base(void) { - if (abw_count < 0) - init_abw(); + if (abw_count < 0) + init_abw(); - /* XXX check abst_flags for ABST_DENSE just to be safe? */ - xf86Msg(X_INFO, "dense base = %#lx\n", - abw[0].abw_abst.abst_sys_start); /* XXXX */ - return abw[0].abw_abst.abst_sys_start; + /* XXX check abst_flags for ABST_DENSE just to be safe? */ + xf86Msg(X_INFO, "dense base = %#lx\n", abw[0].abw_abst.abst_sys_start); /* XXXX */ + return abw[0].abw_abst.abst_sys_start; } static unsigned long memory_base(void) { - if (abw_count < 0) - init_abw(); - - if (abw_count > 1) { - xf86Msg(X_INFO, "memory base = %#lx\n", - abw[1].abw_abst.abst_sys_start); /* XXXX */ - return abw[1].abw_abst.abst_sys_start; - } else if (abw_count == 1) { - /* assume memory_base == dense_base */ - xf86Msg(X_INFO, "memory base = %#lx\n", - abw[0].abw_abst.abst_sys_start); /* XXXX */ - return abw[0].abw_abst.abst_sys_start; - } else { - xf86Msg(X_INFO, "no memory base\n"); /* XXXX */ - return 0; - } + if (abw_count < 0) + init_abw(); + + if (abw_count > 1) { + xf86Msg(X_INFO, "memory base = %#lx\n", abw[1].abw_abst.abst_sys_start); /* XXXX */ + return abw[1].abw_abst.abst_sys_start; + } + else if (abw_count == 1) { + /* assume memory_base == dense_base */ + xf86Msg(X_INFO, "memory base = %#lx\n", abw[0].abw_abst.abst_sys_start); /* XXXX */ + return abw[0].abw_abst.abst_sys_start; + } + else { + xf86Msg(X_INFO, "no memory base\n"); /* XXXX */ + return 0; + } } -#endif /* __NetBSD__ */ +#endif /* __NetBSD__ */ #define BUS_BASE dense_base() #define BUS_BASE_BWX memory_base() @@ -184,7 +183,7 @@ memory_base(void) #endif static Bool useDevMem = FALSE; -static int devMemFd = -1; +static int devMemFd = -1; #ifdef HAS_APERTURE_DRV #define DEV_APERTURE "/dev/xf86" @@ -202,148 +201,144 @@ static void unmapVidMemSparse(int, pointer, unsigned long); static void checkDevMem(Bool warn) { - static Bool devMemChecked = FALSE; - int fd; - pointer base; + static Bool devMemChecked = FALSE; + int fd; + pointer base; - if (devMemChecked) - return; - devMemChecked = TRUE; + if (devMemChecked) + return; + devMemChecked = TRUE; #ifdef HAS_APERTURE_DRV - /* Try the aperture driver first */ - if ((fd = open(DEV_APERTURE, O_RDWR)) >= 0) { - /* Try to map a page at the VGA address */ - base = mmap((caddr_t)0, 4096, PROT_READ | PROT_WRITE, - MAP_FLAGS, fd, (off_t)0xA0000 + BUS_BASE); - - if (base != MAP_FAILED) { - munmap((caddr_t)base, 4096); - devMemFd = fd; - useDevMem = TRUE; - xf86Msg(X_INFO, "checkDevMem: using aperture driver %s\n", - DEV_APERTURE); - return; - } else { - if (warn) { - xf86Msg(X_WARNING, "checkDevMem: failed to mmap %s (%s)\n", - DEV_APERTURE, strerror(errno)); - } - } - } + /* Try the aperture driver first */ + if ((fd = open(DEV_APERTURE, O_RDWR)) >= 0) { + /* Try to map a page at the VGA address */ + base = mmap((caddr_t) 0, 4096, PROT_READ | PROT_WRITE, + MAP_FLAGS, fd, (off_t) 0xA0000 + BUS_BASE); + + if (base != MAP_FAILED) { + munmap((caddr_t) base, 4096); + devMemFd = fd; + useDevMem = TRUE; + xf86Msg(X_INFO, "checkDevMem: using aperture driver %s\n", + DEV_APERTURE); + return; + } + else { + if (warn) { + xf86Msg(X_WARNING, "checkDevMem: failed to mmap %s (%s)\n", + DEV_APERTURE, strerror(errno)); + } + } + } #endif - if ((fd = open(DEV_MEM, O_RDWR)) >= 0) { - /* Try to map a page at the VGA address */ - base = mmap((caddr_t)0, 4096, PROT_READ | PROT_WRITE, - MAP_FLAGS, fd, (off_t)0xA0000 + BUS_BASE); - - if (base != MAP_FAILED) { - munmap((caddr_t)base, 4096); - devMemFd = fd; - useDevMem = TRUE; - return; - } else { - if (warn) { - xf86Msg(X_WARNING, "checkDevMem: failed to mmap %s (%s)\n", - DEV_MEM, strerror(errno)); - } - } - } - if (warn) { + if ((fd = open(DEV_MEM, O_RDWR)) >= 0) { + /* Try to map a page at the VGA address */ + base = mmap((caddr_t) 0, 4096, PROT_READ | PROT_WRITE, + MAP_FLAGS, fd, (off_t) 0xA0000 + BUS_BASE); + + if (base != MAP_FAILED) { + munmap((caddr_t) base, 4096); + devMemFd = fd; + useDevMem = TRUE; + return; + } + else { + if (warn) { + xf86Msg(X_WARNING, "checkDevMem: failed to mmap %s (%s)\n", + DEV_MEM, strerror(errno)); + } + } + } + if (warn) { #ifndef HAS_APERTURE_DRV - xf86Msg(X_WARNING, "checkDevMem: failed to open/mmap %s (%s)\n", - DEV_MEM, strerror(errno)); + xf86Msg(X_WARNING, "checkDevMem: failed to open/mmap %s (%s)\n", + DEV_MEM, strerror(errno)); #else #ifndef __OpenBSD__ - xf86Msg(X_WARNING, "checkDevMem: failed to open %s and %s\n" - "\t(%s)\n", DEV_APERTURE, DEV_MEM, strerror(errno)); -#else /* __OpenBSD__ */ - xf86Msg(X_WARNING, "checkDevMem: failed to open %s and %s\n" - "\t(%s)\n%s", DEV_APERTURE, DEV_MEM, strerror(errno), - SYSCTL_MSG); -#endif /* __OpenBSD__ */ + xf86Msg(X_WARNING, "checkDevMem: failed to open %s and %s\n" + "\t(%s)\n", DEV_APERTURE, DEV_MEM, strerror(errno)); +#else /* __OpenBSD__ */ + xf86Msg(X_WARNING, "checkDevMem: failed to open %s and %s\n" + "\t(%s)\n%s", DEV_APERTURE, DEV_MEM, strerror(errno), + SYSCTL_MSG); +#endif /* __OpenBSD__ */ #endif - xf86ErrorF("\tlinear framebuffer access unavailable\n"); - } - useDevMem = FALSE; - return; + xf86ErrorF("\tlinear framebuffer access unavailable\n"); + } + useDevMem = FALSE; + return; } void xf86OSInitVidMem(VidMemInfoPtr pVidMem) { - checkDevMem(TRUE); - pVidMem->linearSupported = useDevMem; - - if (has_bwx()) { - xf86Msg(X_PROBED,"Machine type has 8/16 bit access\n"); - pVidMem->mapMem = mapVidMem; - pVidMem->unmapMem = unmapVidMem; - } else { - xf86Msg(X_PROBED,"Machine needs sparse mapping\n"); - pVidMem->mapMem = mapVidMemSparse; - pVidMem->unmapMem = unmapVidMemSparse; + checkDevMem(TRUE); + pVidMem->linearSupported = useDevMem; + + if (has_bwx()) { + xf86Msg(X_PROBED, "Machine type has 8/16 bit access\n"); + pVidMem->mapMem = mapVidMem; + pVidMem->unmapMem = unmapVidMem; + } + else { + xf86Msg(X_PROBED, "Machine needs sparse mapping\n"); + pVidMem->mapMem = mapVidMemSparse; + pVidMem->unmapMem = unmapVidMemSparse; #ifndef __NetBSD__ - if (axpSystem == -1) - axpSystem = bsdGetAXP(); - hae_thresh = xf86AXPParams[axpSystem].hae_thresh; - hae_mask = xf86AXPParams[axpSystem].hae_mask; -#endif /* __NetBSD__ */ - } - pVidMem->initialised = TRUE; + if (axpSystem == -1) + axpSystem = bsdGetAXP(); + hae_thresh = xf86AXPParams[axpSystem].hae_thresh; + hae_mask = xf86AXPParams[axpSystem].hae_mask; +#endif /* __NetBSD__ */ + } + pVidMem->initialised = TRUE; } static pointer mapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags) { - pointer base; - - checkDevMem(FALSE); - Base = Base & ((1L<<32) - 1); - - if (useDevMem) - { - if (devMemFd < 0) - { - FatalError("xf86MapVidMem: failed to open %s (%s)\n", - DEV_MEM, strerror(errno)); - } - base = mmap((caddr_t)0, Size, - (flags & VIDMEM_READONLY) ? - PROT_READ : (PROT_READ | PROT_WRITE), - MAP_FLAGS, devMemFd, (off_t)Base + BUS_BASE_BWX); - if (base == MAP_FAILED) - { - FatalError("%s: could not mmap %s [s=%lx,a=%lx] (%s)\n", - "xf86MapVidMem", DEV_MEM, Size, Base, - strerror(errno)); - } - return base; - } - - /* else, mmap /dev/vga */ - if ((unsigned long)Base < 0xA0000 || (unsigned long)Base >= 0xC0000) - { - FatalError("%s: Address 0x%lx outside allowable range\n", - "xf86MapVidMem", Base); - } - base = mmap(0, Size, - (flags & VIDMEM_READONLY) ? - PROT_READ : (PROT_READ | PROT_WRITE), - MAP_FLAGS, xf86Info.consoleFd, - (unsigned long)Base + BUS_BASE); - if (base == MAP_FAILED) - { - FatalError("xf86MapVidMem: Could not mmap /dev/vga (%s)\n", - strerror(errno)); - } - return base; + pointer base; + + checkDevMem(FALSE); + Base = Base & ((1L << 32) - 1); + + if (useDevMem) { + if (devMemFd < 0) { + FatalError("xf86MapVidMem: failed to open %s (%s)\n", + DEV_MEM, strerror(errno)); + } + base = mmap((caddr_t) 0, Size, + (flags & VIDMEM_READONLY) ? + PROT_READ : (PROT_READ | PROT_WRITE), + MAP_FLAGS, devMemFd, (off_t) Base + BUS_BASE_BWX); + if (base == MAP_FAILED) { + FatalError("%s: could not mmap %s [s=%lx,a=%lx] (%s)\n", + "xf86MapVidMem", DEV_MEM, Size, Base, strerror(errno)); + } + return base; + } + + /* else, mmap /dev/vga */ + if ((unsigned long) Base < 0xA0000 || (unsigned long) Base >= 0xC0000) { + FatalError("%s: Address 0x%lx outside allowable range\n", + "xf86MapVidMem", Base); + } + base = mmap(0, Size, + (flags & VIDMEM_READONLY) ? + PROT_READ : (PROT_READ | PROT_WRITE), + MAP_FLAGS, xf86Info.consoleFd, (unsigned long) Base + BUS_BASE); + if (base == MAP_FAILED) { + FatalError("xf86MapVidMem: Could not mmap /dev/vga (%s)\n", + strerror(errno)); + } + return base; } static void unmapVidMem(int ScreenNum, pointer Base, unsigned long Size) { - munmap((caddr_t)Base, Size); + munmap((caddr_t) Base, Size); } /* @@ -352,45 +347,44 @@ unmapVidMem(int ScreenNum, pointer Base, unsigned long Size) int xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf, - int Len) + int Len) { - unsigned char *ptr; - int psize; - int mlen; - - checkDevMem(TRUE); - if (devMemFd == -1) { - 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, devMemFd, (off_t)Base+BUS_BASE); - if ((long)ptr == -1) - { - xf86Msg(X_WARNING, - "xf86ReadBIOS: %s mmap[s=%x,a=%lx,o=%lx] failed (%s)\n", - DEV_MEM, Len, Base, Offset, strerror(errno)); - return -1; - } + unsigned char *ptr; + int psize; + int mlen; + + checkDevMem(TRUE); + if (devMemFd == -1) { + 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, devMemFd, (off_t) Base + BUS_BASE); + if ((long) ptr == -1) { + xf86Msg(X_WARNING, + "xf86ReadBIOS: %s mmap[s=%x,a=%lx,o=%lx] failed (%s)\n", + DEV_MEM, Len, Base, Offset, strerror(errno)); + return -1; + } #ifdef DEBUG - xf86MsgVerb(X_INFO, 3, "xf86ReadBIOS: BIOS at 0x%08x has signature 0x%04x\n", - Base, ptr[0] | (ptr[1] << 8)); + xf86MsgVerb(X_INFO, 3, + "xf86ReadBIOS: BIOS at 0x%08x has signature 0x%04x\n", Base, + ptr[0] | (ptr[1] << 8)); #endif - (void)memcpy(Buf, (void *)(ptr + Offset), Len); - (void)munmap((caddr_t)ptr, mlen); + (void) memcpy(Buf, (void *) (ptr + Offset), Len); + (void) munmap((caddr_t) ptr, mlen); #ifdef DEBUG - xf86MsgVerb(X_INFO, 3, "xf86ReadBIOS(%x, %x, Buf, %x)" - "-> %02x %02x %02x %02x...\n", - Base, Offset, Len, Buf[0], Buf[1], Buf[2], Buf[3]); + xf86MsgVerb(X_INFO, 3, "xf86ReadBIOS(%x, %x, Buf, %x)" + "-> %02x %02x %02x %02x...\n", + Base, Offset, Len, Buf[0], Buf[1], Buf[2], Buf[3]); #endif - return Len; + return Len; } - #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) extern int ioperm(unsigned long from, unsigned long num, int on); @@ -399,34 +393,34 @@ Bool xf86EnableIO() { if (!ioperm(0, 65536, TRUE)) - return TRUE; + return TRUE; return FALSE; } void xf86DisableIO() { - return; + return; } -#endif /* __FreeBSD_kernel__ || __OpenBSD__ */ +#endif /* __FreeBSD_kernel__ || __OpenBSD__ */ #ifdef USE_ALPHA_PIO Bool xf86EnableIO() { - alpha_pci_io_enable(1); - return TRUE; + alpha_pci_io_enable(1); + return TRUE; } void xf86DisableIO() { - alpha_pci_io_enable(0); + alpha_pci_io_enable(0); } -#endif /* USE_ALPHA_PIO */ +#endif /* USE_ALPHA_PIO */ #define vuip volatile unsigned int * @@ -437,39 +431,39 @@ extern int readDense8(pointer Base, register unsigned long Offset); extern int readDense16(pointer Base, register unsigned long Offset); extern int readDense32(pointer Base, register unsigned long Offset); extern void -writeDenseNB8(int Value, pointer Base, register unsigned long Offset); + writeDenseNB8(int Value, pointer Base, register unsigned long Offset); extern void -writeDenseNB16(int Value, pointer Base, register unsigned long Offset); + writeDenseNB16(int Value, pointer Base, register unsigned long Offset); extern void -writeDenseNB32(int Value, pointer Base, register unsigned long Offset); + writeDenseNB32(int Value, pointer Base, register unsigned long Offset); extern void -writeDense8(int Value, pointer Base, register unsigned long Offset); + writeDense8(int Value, pointer Base, register unsigned long Offset); extern void -writeDense16(int Value, pointer Base, register unsigned long Offset); + writeDense16(int Value, pointer Base, register unsigned long Offset); extern void -writeDense32(int Value, pointer Base, register unsigned long Offset); + writeDense32(int Value, pointer Base, register unsigned long Offset); static int readSparse8(pointer Base, register unsigned long Offset); static int readSparse16(pointer Base, register unsigned long Offset); static int readSparse32(pointer Base, register unsigned long Offset); static void -writeSparseNB8(int Value, pointer Base, register unsigned long Offset); + writeSparseNB8(int Value, pointer Base, register unsigned long Offset); static void -writeSparseNB16(int Value, pointer Base, register unsigned long Offset); + writeSparseNB16(int Value, pointer Base, register unsigned long Offset); static void -writeSparseNB32(int Value, pointer Base, register unsigned long Offset); + writeSparseNB32(int Value, pointer Base, register unsigned long Offset); static void -writeSparse8(int Value, pointer Base, register unsigned long Offset); + writeSparse8(int Value, pointer Base, register unsigned long Offset); static void -writeSparse16(int Value, pointer Base, register unsigned long Offset); + writeSparse16(int Value, pointer Base, register unsigned long Offset); static void -writeSparse32(int Value, pointer Base, register unsigned long Offset); + writeSparse32(int Value, pointer Base, register unsigned long Offset); #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) extern int sysarch(int, void *); struct parms { - u_int64_t hae; + u_int64_t hae; }; static void @@ -478,50 +472,49 @@ sethae(u_int64_t hae) #ifndef ALPHA_SETHAE #define ALPHA_SETHAE 0 #endif - static struct parms p; + static struct parms p; - if (p.hae != hae) { - p.hae = hae; - sysarch(ALPHA_SETHAE, (char *)&p); - } + if (p.hae != hae) { + p.hae = hae; + sysarch(ALPHA_SETHAE, (char *) &p); + } } #endif static pointer -mapVidMemSparse(int ScreenNum, unsigned long Base, unsigned long Size, int flags) +mapVidMemSparse(int ScreenNum, unsigned long Base, unsigned long Size, + int flags) { static Bool was_here = FALSE; if (!was_here) { - was_here = TRUE; - - checkDevMem(FALSE); - - xf86WriteMmio8 = writeSparse8; - xf86WriteMmio16 = writeSparse16; - xf86WriteMmio32 = writeSparse32; - xf86WriteMmioNB8 = writeSparseNB8; - xf86WriteMmioNB16 = writeSparseNB16; - xf86WriteMmioNB32 = writeSparseNB32; - xf86ReadMmio8 = readSparse8; - xf86ReadMmio16 = readSparse16; - xf86ReadMmio32 = readSparse32; - - memBase = mmap((caddr_t)0, 0x100000000, - PROT_READ | PROT_WRITE, - MAP_SHARED, devMemFd, - (off_t) BUS_BASE); - memSBase = mmap((caddr_t)0, 0x100000000, - PROT_READ | PROT_WRITE, - MAP_SHARED, devMemFd, - (off_t) BUS_BASE_BWX); - - if (memSBase == MAP_FAILED || memBase == MAP_FAILED) { - FatalError("xf86MapVidMem: Could not mmap framebuffer (%s)\n", - strerror(errno)); - } + was_here = TRUE; + + checkDevMem(FALSE); + + xf86WriteMmio8 = writeSparse8; + xf86WriteMmio16 = writeSparse16; + xf86WriteMmio32 = writeSparse32; + xf86WriteMmioNB8 = writeSparseNB8; + xf86WriteMmioNB16 = writeSparseNB16; + xf86WriteMmioNB32 = writeSparseNB32; + xf86ReadMmio8 = readSparse8; + xf86ReadMmio16 = readSparse16; + xf86ReadMmio32 = readSparse32; + + memBase = mmap((caddr_t) 0, 0x100000000, + PROT_READ | PROT_WRITE, + MAP_SHARED, devMemFd, (off_t) BUS_BASE); + memSBase = mmap((caddr_t) 0, 0x100000000, + PROT_READ | PROT_WRITE, + MAP_SHARED, devMemFd, (off_t) BUS_BASE_BWX); + + if (memSBase == MAP_FAILED || memBase == MAP_FAILED) { + FatalError("xf86MapVidMem: Could not mmap framebuffer (%s)\n", + strerror(errno)); + } } - return (pointer)((unsigned long)memBase + Base); + return (pointer) ((unsigned long) memBase + Base); } static void @@ -534,17 +527,18 @@ readSparse8(pointer Base, register unsigned long Offset) { register unsigned long result, shift; register unsigned long msb; + mem_barrier(); - Offset += (unsigned long)Base - (unsigned long)memBase; + Offset += (unsigned long) Base - (unsigned long) memBase; shift = (Offset & 0x3) << 3; - if (Offset >= (hae_thresh)) { + if (Offset >= (hae_thresh)) { msb = Offset & hae_mask; Offset -= msb; #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) - sethae(msb); + sethae(msb); #endif - } - result = *(vuip) ((unsigned long)memSBase + (Offset << 5)); + } + result = *(vuip) ((unsigned long) memSBase + (Offset << 5)); result >>= shift; return 0xffUL & result; } @@ -556,16 +550,17 @@ readSparse16(pointer Base, register unsigned long Offset) register unsigned long msb; mem_barrier(); - Offset += (unsigned long)Base - (unsigned long)memBase; + Offset += (unsigned long) Base - (unsigned long) memBase; shift = (Offset & 0x2) << 3; if (Offset >= (hae_thresh)) { msb = Offset & hae_mask; Offset -= msb; #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) - sethae(msb); + sethae(msb); #endif } - result = *(vuip)((unsigned long)memSBase+(Offset<<5)+(1<<(5-2))); + result = + *(vuip) ((unsigned long) memSBase + (Offset << 5) + (1 << (5 - 2))); result >>= shift; return 0xffffUL & result; } @@ -574,7 +569,7 @@ static int readSparse32(pointer Base, register unsigned long Offset) { mem_barrier(); - return *(vuip)((unsigned long)Base+(Offset)); + return *(vuip) ((unsigned long) Base + (Offset)); } static void @@ -584,15 +579,15 @@ writeSparse8(int Value, pointer Base, register unsigned long Offset) register unsigned int b = Value & 0xffU; write_mem_barrier(); - Offset += (unsigned long)Base - (unsigned long)memBase; + Offset += (unsigned long) Base - (unsigned long) memBase; if (Offset >= (hae_thresh)) { - msb = Offset & hae_mask; - Offset -= msb; + msb = Offset & hae_mask; + Offset -= msb; #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) - sethae(msb); + sethae(msb); #endif } - *(vuip) ((unsigned long)memSBase + (Offset << 5)) = b * 0x01010101; + *(vuip) ((unsigned long) memSBase + (Offset << 5)) = b * 0x01010101; } static void @@ -602,16 +597,16 @@ writeSparse16(int Value, pointer Base, register unsigned long Offset) register unsigned int w = Value & 0xffffU; write_mem_barrier(); - Offset += (unsigned long)Base - (unsigned long)memBase; + Offset += (unsigned long) Base - (unsigned long) memBase; if (Offset >= (hae_thresh)) { - msb = Offset & hae_mask; - Offset -= msb; + msb = Offset & hae_mask; + Offset -= msb; #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) - sethae(msb); + sethae(msb); #endif } - *(vuip)((unsigned long)memSBase+(Offset<<5)+(1<<(5-2))) = - w * 0x00010001; + *(vuip) ((unsigned long) memSBase + (Offset << 5) + (1 << (5 - 2))) = + w * 0x00010001; } @@ -619,7 +614,7 @@ static void writeSparse32(int Value, pointer Base, register unsigned long Offset) { write_mem_barrier(); - *(vuip)((unsigned long)Base + (Offset)) = Value; + *(vuip) ((unsigned long) Base + (Offset)) = Value; return; } @@ -629,15 +624,15 @@ writeSparseNB8(int Value, pointer Base, register unsigned long Offset) register unsigned long msb; register unsigned int b = Value & 0xffU; - Offset += (unsigned long)Base - (unsigned long)memBase; + Offset += (unsigned long) Base - (unsigned long) memBase; if (Offset >= (hae_thresh)) { - msb = Offset & hae_mask; - Offset -= msb; + msb = Offset & hae_mask; + Offset -= msb; #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) - sethae(msb); + sethae(msb); #endif } - *(vuip) ((unsigned long)memSBase + (Offset << 5)) = b * 0x01010101; + *(vuip) ((unsigned long) memSBase + (Offset << 5)) = b * 0x01010101; } static void @@ -646,41 +641,40 @@ writeSparseNB16(int Value, pointer Base, register unsigned long Offset) register unsigned long msb; register unsigned int w = Value & 0xffffU; - Offset += (unsigned long)Base - (unsigned long)memBase; + Offset += (unsigned long) Base - (unsigned long) memBase; if (Offset >= (hae_thresh)) { - msb = Offset & hae_mask ; - Offset -= msb; + msb = Offset & hae_mask; + Offset -= msb; #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) - sethae(msb); + sethae(msb); #endif } - *(vuip)((unsigned long)memSBase+(Offset<<5)+(1<<(5-2))) = - w * 0x00010001; + *(vuip) ((unsigned long) memSBase + (Offset << 5) + (1 << (5 - 2))) = + w * 0x00010001; } static void writeSparseNB32(int Value, pointer Base, register unsigned long Offset) { - *(vuip)((unsigned long)Base + (Offset)) = Value; + *(vuip) ((unsigned long) Base + (Offset)) = Value; return; } -void (*xf86WriteMmio8)(int Value, pointer Base, unsigned long Offset) - = writeDense8; -void (*xf86WriteMmio16)(int Value, pointer Base, unsigned long Offset) - = writeDense16; -void (*xf86WriteMmio32)(int Value, pointer Base, unsigned long Offset) - = writeDense32; -void (*xf86WriteMmioNB8)(int Value, pointer Base, unsigned long Offset) - = writeDenseNB8; -void (*xf86WriteMmioNB16)(int Value, pointer Base, unsigned long Offset) - = writeDenseNB16; -void (*xf86WriteMmioNB32)(int Value, pointer Base, unsigned long Offset) - = writeDenseNB32; -int (*xf86ReadMmio8)(pointer Base, unsigned long Offset) - = readDense8; -int (*xf86ReadMmio16)(pointer Base, unsigned long Offset) - = readDense16; -int (*xf86ReadMmio32)(pointer Base, unsigned long Offset) - = readDense32; - +void (*xf86WriteMmio8) (int Value, pointer Base, unsigned long Offset) + = writeDense8; +void (*xf86WriteMmio16) (int Value, pointer Base, unsigned long Offset) + = writeDense16; +void (*xf86WriteMmio32) (int Value, pointer Base, unsigned long Offset) + = writeDense32; +void (*xf86WriteMmioNB8) (int Value, pointer Base, unsigned long Offset) + = writeDenseNB8; +void (*xf86WriteMmioNB16) (int Value, pointer Base, unsigned long Offset) + = writeDenseNB16; +void (*xf86WriteMmioNB32) (int Value, pointer Base, unsigned long Offset) + = writeDenseNB32; +int (*xf86ReadMmio8) (pointer Base, unsigned long Offset) + = readDense8; +int (*xf86ReadMmio16) (pointer Base, unsigned long Offset) + = readDense16; +int (*xf86ReadMmio32) (pointer Base, unsigned long Offset) + = readDense32; diff --git a/xorg-server/hw/xfree86/os-support/bsd/arm_video.c b/xorg-server/hw/xfree86/os-support/bsd/arm_video.c index 1de6c87d6..71064af03 100644 --- a/xorg-server/hw/xfree86/os-support/bsd/arm_video.c +++ b/xorg-server/hw/xfree86/os-support/bsd/arm_video.c @@ -68,8 +68,7 @@ #ifdef __arm32__ #include "machine/devmap.h" -struct memAccess -{ +struct memAccess { int ioctl; struct map_info memInfo; pointer regionVirtBase; @@ -82,14 +81,19 @@ static void xf86MapInfoUnmap(); static struct memAccess *checkMapInfo(); extern int vgaPhysLinearBase; -/* A memAccess structure is needed for each possible region */ -struct memAccess vgaMemInfo = { CONSOLE_GET_MEM_INFO, NULL, NULL, - FALSE, FALSE }; -struct memAccess linearMemInfo = { CONSOLE_GET_LINEAR_INFO, NULL, NULL, - FALSE, FALSE }; +/* A memAccess structure is needed for each possible region */ +struct memAccess vgaMemInfo = { CONSOLE_GET_MEM_INFO, NULL, NULL, + FALSE, FALSE +}; + +struct memAccess linearMemInfo = { CONSOLE_GET_LINEAR_INFO, NULL, NULL, + FALSE, FALSE +}; + struct memAccess ioMemInfo = { CONSOLE_GET_IO_INFO, NULL, NULL, - FALSE, FALSE }; -#endif /* __arm32__ */ + FALSE, FALSE +}; +#endif /* __arm32__ */ #if defined(__NetBSD__) && !defined(MAP_FILE) #define MAP_FLAGS MAP_SHARED @@ -100,13 +104,12 @@ struct memAccess ioMemInfo = { CONSOLE_GET_IO_INFO, NULL, NULL, #define BUS_BASE 0L #define BUS_BASE_BWX 0L - /***************************************************************************/ /* Video Memory Mapping section */ /***************************************************************************/ static Bool useDevMem = FALSE; -static int devMemFd = -1; +static int devMemFd = -1; static pointer mapVidMem(int, unsigned long, unsigned long, int); static void unmapVidMem(int, pointer, unsigned long); @@ -118,108 +121,98 @@ static void unmapVidMem(int, pointer, unsigned long); static void checkDevMem(Bool warn) { - static Bool devMemChecked = FALSE; - int fd; - pointer base; - - if (devMemChecked) - return; - devMemChecked = TRUE; - - if ((fd = open(DEV_MEM, O_RDWR)) >= 0) - { - /* Try to map a page at the VGA address */ - base = mmap((caddr_t)0, 4096, PROT_READ | PROT_WRITE, - MAP_FLAGS, fd, (off_t)0xA0000 + BUS_BASE); - - if (base != MAP_FAILED) - { - munmap((caddr_t)base, 4096); - devMemFd = fd; - useDevMem = TRUE; - return; - } else { - /* This should not happen */ - if (warn) - { - xf86Msg(X_WARNING, "checkDevMem: failed to mmap %s (%s)\n", - DEV_MEM, strerror(errno)); - } - useDevMem = FALSE; - return; - } - } - if (warn) - { - xf86Msg(X_WARNING, "checkDevMem: failed to open %s (%s)\n", - DEV_MEM, strerror(errno)); - } - useDevMem = FALSE; - return; + static Bool devMemChecked = FALSE; + int fd; + pointer base; + + if (devMemChecked) + return; + devMemChecked = TRUE; + + if ((fd = open(DEV_MEM, O_RDWR)) >= 0) { + /* Try to map a page at the VGA address */ + base = mmap((caddr_t) 0, 4096, PROT_READ | PROT_WRITE, + MAP_FLAGS, fd, (off_t) 0xA0000 + BUS_BASE); + + if (base != MAP_FAILED) { + munmap((caddr_t) base, 4096); + devMemFd = fd; + useDevMem = TRUE; + return; + } + else { + /* This should not happen */ + if (warn) { + xf86Msg(X_WARNING, "checkDevMem: failed to mmap %s (%s)\n", + DEV_MEM, strerror(errno)); + } + useDevMem = FALSE; + return; + } + } + if (warn) { + xf86Msg(X_WARNING, "checkDevMem: failed to open %s (%s)\n", + DEV_MEM, strerror(errno)); + } + useDevMem = FALSE; + return; } void xf86OSInitVidMem(VidMemInfoPtr pVidMem) { - checkDevMem(TRUE); - pVidMem->linearSupported = useDevMem; - pVidMem->mapMem = armMapVidMem; - pVidMem->unmapVidMem = armUnmapVidMem; + checkDevMem(TRUE); + pVidMem->linearSupported = useDevMem; + pVidMem->mapMem = armMapVidMem; + pVidMem->unmapVidMem = armUnmapVidMem; - pVidMem->initialised = TRUE; + pVidMem->initialised = TRUE; } static pointer mapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags) { - pointer base; - - checkDevMem(FALSE); - - if (useDevMem) - { - if (devMemFd < 0) - { - FatalError("xf86MapVidMem: failed to open %s (%s)\n", - DEV_MEM, strerror(errno)); - } - base = mmap((caddr_t)0, Size, - (flags & VIDMEM_READONLY) ? - PROT_READ : (PROT_READ | PROT_WRITE), - MAP_FLAGS, devMemFd, (off_t)Base + BUS_BASE_BWX); - if (base == MAP_FAILED) - { - FatalError("%s: could not mmap %s [s=%x,a=%x] (%s)\n", - "xf86MapVidMem", DEV_MEM, Size, Base, - strerror(errno)); - } - return base; - } - - /* else, mmap /dev/vga */ - if ((unsigned long)Base < 0xA0000 || (unsigned long)Base >= 0xC0000) - { - FatalError("%s: Address 0x%x outside allowable range\n", - "xf86MapVidMem", Base); - } - base = mmap(0, Size, - (flags & VIDMEM_READONLY) ? - PROT_READ : (PROT_READ | PROT_WRITE), - MAP_FLAGS, xf86Info.consoleFd, - (unsigned long)Base - 0xA0000); - if (base == MAP_FAILED) - { - FatalError("xf86MapVidMem: Could not mmap /dev/vga (%s)\n", - strerror(errno)); - } - return base; + pointer base; + + checkDevMem(FALSE); + + if (useDevMem) { + if (devMemFd < 0) { + FatalError("xf86MapVidMem: failed to open %s (%s)\n", + DEV_MEM, strerror(errno)); + } + base = mmap((caddr_t) 0, Size, + (flags & VIDMEM_READONLY) ? + PROT_READ : (PROT_READ | PROT_WRITE), + MAP_FLAGS, devMemFd, (off_t) Base + BUS_BASE_BWX); + if (base == MAP_FAILED) { + FatalError("%s: could not mmap %s [s=%x,a=%x] (%s)\n", + "xf86MapVidMem", DEV_MEM, Size, Base, strerror(errno)); + } + return base; + } + + /* else, mmap /dev/vga */ + if ((unsigned long) Base < 0xA0000 || (unsigned long) Base >= 0xC0000) { + FatalError("%s: Address 0x%x outside allowable range\n", + "xf86MapVidMem", Base); + } + base = mmap(0, Size, + (flags & VIDMEM_READONLY) ? + PROT_READ : (PROT_READ | PROT_WRITE), + MAP_FLAGS, xf86Info.consoleFd, (unsigned long) Base - 0xA0000); + if (base == MAP_FAILED) { + FatalError("xf86MapVidMem: Could not mmap /dev/vga (%s)\n", + strerror(errno)); + } + return base; } static void unmapVidMem(int ScreenNum, pointer Base, unsigned long Size) { - munmap((caddr_t)Base, Size); + munmap((caddr_t) Base, Size); } /* @@ -228,45 +221,43 @@ unmapVidMem(int ScreenNum, pointer Base, unsigned long Size) int xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf, - int Len) + int Len) { - unsigned char *ptr; - int psize; - int mlen; - - checkDevMem(TRUE); - if (devMemFd == -1) { - 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, devMemFd, (off_t)Base+BUS_BASE); - if ((long)ptr == -1) - { - xf86Msg(X_WARNING, - "xf86ReadBIOS: %s mmap[s=%x,a=%x,o=%x] failed (%s)\n", - DEV_MEM, Len, Base, Offset, strerror(errno)); - return -1; - } + unsigned char *ptr; + int psize; + int mlen; + + checkDevMem(TRUE); + if (devMemFd == -1) { + 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, devMemFd, (off_t) Base + BUS_BASE); + if ((long) ptr == -1) { + xf86Msg(X_WARNING, + "xf86ReadBIOS: %s mmap[s=%x,a=%x,o=%x] failed (%s)\n", + DEV_MEM, Len, Base, Offset, strerror(errno)); + return -1; + } #ifdef DEBUG - ErrorF("xf86ReadBIOS: BIOS at 0x%08x has signature 0x%04x\n", - Base, ptr[0] | (ptr[1] << 8)); + ErrorF("xf86ReadBIOS: BIOS at 0x%08x has signature 0x%04x\n", + Base, ptr[0] | (ptr[1] << 8)); #endif - (void)memcpy(Buf, (void *)(ptr + Offset), Len); - (void)munmap((caddr_t)ptr, mlen); + (void) memcpy(Buf, (void *) (ptr + Offset), Len); + (void) munmap((caddr_t) ptr, mlen); #ifdef DEBUG - xf86MsgVerb(X_INFO, 3, "xf86ReadBIOS(%x, %x, Buf, %x)" - "-> %02x %02x %02x %02x...\n", - Base, Offset, Len, Buf[0], Buf[1], Buf[2], Buf[3]); + xf86MsgVerb(X_INFO, 3, "xf86ReadBIOS(%x, %x, Buf, %x)" + "-> %02x %02x %02x %02x...\n", + Base, Offset, Len, Buf[0], Buf[1], Buf[2], Buf[3]); #endif - return Len; + return Len; } - /* XXX This needs to be updated for the ND */ /* @@ -277,52 +268,45 @@ static struct memAccess * checkMapInfo(Bool warn, int Region) { struct memAccess *memAccP; - - switch (Region) - { - case VGA_REGION: - memAccP = &vgaMemInfo; - break; - - case LINEAR_REGION: - memAccP = &linearMemInfo; - break; - - case MMIO_REGION: - memAccP = &ioMemInfo; - break; - - default: - return NULL; - break; + + switch (Region) { + case VGA_REGION: + memAccP = &vgaMemInfo; + break; + + case LINEAR_REGION: + memAccP = &linearMemInfo; + break; + + case MMIO_REGION: + memAccP = &ioMemInfo; + break; + + default: + return NULL; + break; } - - if(!memAccP->Checked) - { - if(ioctl(xf86Info.consoleFd, memAccP->ioctl, &(memAccP->memInfo)) == -1) - { - if(warn) - { - xf86Msg(X_WARNING, - "checkMapInfo: failed to get map info for region %d\n\t(%s)\n", - Region, strerror(errno)); - } - } - else - { - if(memAccP->memInfo.u.map_info_mmap.map_offset - != MAP_INFO_UNKNOWN) - memAccP->OK = TRUE; - } - memAccP->Checked = TRUE; + + if (!memAccP->Checked) { + if (ioctl(xf86Info.consoleFd, memAccP->ioctl, &(memAccP->memInfo)) == + -1) { + if (warn) { + xf86Msg(X_WARNING, + "checkMapInfo: failed to get map info for region %d\n\t(%s)\n", + Region, strerror(errno)); + } + } + else { + if (memAccP->memInfo.u.map_info_mmap.map_offset != MAP_INFO_UNKNOWN) + memAccP->OK = TRUE; + } + memAccP->Checked = TRUE; } - if (memAccP->OK) - { - return memAccP; + if (memAccP->OK) { + return memAccP; } - else - { - return NULL; + else { + return NULL; } } @@ -331,113 +315,103 @@ xf86MapInfoMap(struct memAccess *memInfoP, pointer Base, unsigned long Size) { struct map_info *mapInfoP = &(memInfoP->memInfo); - if (mapInfoP->u.map_info_mmap.map_size == MAP_INFO_UNKNOWN) - { - Size = (unsigned long)Base + Size; + if (mapInfoP->u.map_info_mmap.map_size == MAP_INFO_UNKNOWN) { + Size = (unsigned long) Base + Size; } - else - { - Size = mapInfoP->u.map_info_mmap.map_size; + else { + Size = mapInfoP->u.map_info_mmap.map_size; } - - switch(mapInfoP->method) - { - case MAP_MMAP: - /* Need to remap if size is unknown because we may not have - mapped the whole region initially */ - if(memInfoP->regionVirtBase == NULL || - mapInfoP->u.map_info_mmap.map_size == MAP_INFO_UNKNOWN) - { - if((memInfoP->regionVirtBase = - mmap((caddr_t)0, - Size, - PROT_READ | PROT_WRITE, - MAP_SHARED, - xf86Info.consoleFd, - (unsigned long)mapInfoP->u.map_info_mmap.map_offset)) - == (pointer)-1) - { - FatalError("xf86MapInfoMap: Failed to map memory at 0x%x\n\t%s\n", - mapInfoP->u.map_info_mmap.map_offset, strerror(errno)); - } - if(mapInfoP->u.map_info_mmap.internal_offset > 0) - memInfoP->regionVirtBase += - mapInfoP->u.map_info_mmap.internal_offset; - } - break; - - default: - FatalError("xf86MapInfoMap: Unsuported mapping method\n"); - break; + + switch (mapInfoP->method) { + case MAP_MMAP: + /* Need to remap if size is unknown because we may not have + mapped the whole region initially */ + if (memInfoP->regionVirtBase == NULL || + mapInfoP->u.map_info_mmap.map_size == MAP_INFO_UNKNOWN) { + if ((memInfoP->regionVirtBase = + mmap((caddr_t) 0, + Size, + PROT_READ | PROT_WRITE, + MAP_SHARED, + xf86Info.consoleFd, + (unsigned long) mapInfoP->u.map_info_mmap.map_offset)) + == (pointer) -1) { + FatalError + ("xf86MapInfoMap: Failed to map memory at 0x%x\n\t%s\n", + mapInfoP->u.map_info_mmap.map_offset, strerror(errno)); + } + if (mapInfoP->u.map_info_mmap.internal_offset > 0) + memInfoP->regionVirtBase += + mapInfoP->u.map_info_mmap.internal_offset; + } + break; + + default: + FatalError("xf86MapInfoMap: Unsuported mapping method\n"); + break; } - - return (pointer)((int)memInfoP->regionVirtBase + (int)Base); + + return (pointer) ((int) memInfoP->regionVirtBase + (int) Base); } static void xf86MapInfoUnmap(struct memAccess *memInfoP, unsigned long Size) { struct map_info *mapInfoP = &(memInfoP->memInfo); - - switch(mapInfoP->method) - { - case MAP_MMAP: - if(memInfoP->regionVirtBase != NULL) - { - if(mapInfoP->u.map_info_mmap.map_size != MAP_INFO_UNKNOWN) - Size = mapInfoP->u.map_info_mmap.map_size; - munmap((caddr_t)memInfoP->regionVirtBase, Size); - memInfoP->regionVirtBase = NULL; - } - break; - default: - FatalError("xf86MapInfoMap: Unsuported mapping method\n"); - break; + + switch (mapInfoP->method) { + case MAP_MMAP: + if (memInfoP->regionVirtBase != NULL) { + if (mapInfoP->u.map_info_mmap.map_size != MAP_INFO_UNKNOWN) + Size = mapInfoP->u.map_info_mmap.map_size; + munmap((caddr_t) memInfoP->regionVirtBase, Size); + memInfoP->regionVirtBase = NULL; + } + break; + default: + FatalError("xf86MapInfoMap: Unsuported mapping method\n"); + break; } } static pointer armMapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags) { - struct memAccess *memInfoP; - - if((memInfoP = checkMapInfo(FALSE, Region)) != NULL) - { - /* - ** xf86 passes in a physical address offset from the start - ** of physical memory, but xf86MapInfoMap expects an - ** offset from the start of the specified region - it gets - ** the physical address of the region from the display driver. - */ - switch(Region) - { - case LINEAR_REGION: - if (vgaPhysLinearBase) - { - Base -= vgaPhysLinearBase; - } - break; - case VGA_REGION: - Base -= 0xA0000; - break; - } - - base = xf86MapInfoMap(memInfoP, Base, Size); - return base; - } - return mapVidMem(ScreenNum, Base, Size, flags); + struct memAccess *memInfoP; + + if ((memInfoP = checkMapInfo(FALSE, Region)) != NULL) { + /* + ** xf86 passes in a physical address offset from the start + ** of physical memory, but xf86MapInfoMap expects an + ** offset from the start of the specified region - it gets + ** the physical address of the region from the display driver. + */ + switch (Region) { + case LINEAR_REGION: + if (vgaPhysLinearBase) { + Base -= vgaPhysLinearBase; + } + break; + case VGA_REGION: + Base -= 0xA0000; + break; + } + + base = xf86MapInfoMap(memInfoP, Base, Size); + return base; + } + return mapVidMem(ScreenNum, Base, Size, flags); } static void armUnmapVidMem(int ScreenNum, pointer Base, unsigned long Size) { - struct memAccess *memInfoP; - - if((memInfoP = checkMapInfo(FALSE, Region)) != NULL) - { - xf86MapInfoUnmap(memInfoP, Base, Size); - } - unmapVidMem(ScreenNum, Base, Size); + struct memAccess *memInfoP; + + if ((memInfoP = checkMapInfo(FALSE, Region)) != NULL) { + xf86MapInfoUnmap(memInfoP, Base, Size); + } + unmapVidMem(ScreenNum, Base, Size); } #ifdef USE_DEV_IO @@ -446,27 +420,26 @@ static int IoFd = -1; Bool xf86EnableIO() { - if (IoFd >= 0) - return TRUE; - - if ((IoFd = open("/dev/io", O_RDWR)) == -1) - { - xf86Msg(X_WARNING,"xf86EnableIO: " - "Failed to open /dev/io for extended I/O\n"); - return FALSE; - } - return TRUE; + if (IoFd >= 0) + return TRUE; + + if ((IoFd = open("/dev/io", O_RDWR)) == -1) { + xf86Msg(X_WARNING, "xf86EnableIO: " + "Failed to open /dev/io for extended I/O\n"); + return FALSE; + } + return TRUE; } void xf86DisableIO() { - if (IoFd < 0) - return; + if (IoFd < 0) + return; - close(IoFd); - IoFd = -1; - return; + close(IoFd); + IoFd = -1; + return; } #endif @@ -476,44 +449,44 @@ xf86DisableIO() Bool xf86EnableIO() { - int fd; - pointer base; - - if (ExtendedEnabled) - return TRUE; - - if ((fd = open("/dev/ttyC0", O_RDWR)) >= 0) { - /* Try to map a page at the pccons I/O space */ - base = (pointer)mmap((caddr_t)0, 65536, PROT_READ | PROT_WRITE, - MAP_FLAGS, fd, (off_t)0x0000); - - if (base != (pointer)-1) { - IOPortBase = base; - } - else { - xf86Msg(X_WARNING,"EnableIO: failed to mmap %s (%s)\n", - "/dev/ttyC0", strerror(errno)); - return FALSE; - } - } - else { - xf86Msg("EnableIO: failed to open %s (%s)\n", - "/dev/ttyC0", strerror(errno)); - return FALSE; - } - - ExtendedEnabled = TRUE; - - return TRUE; + int fd; + pointer base; + + if (ExtendedEnabled) + return TRUE; + + if ((fd = open("/dev/ttyC0", O_RDWR)) >= 0) { + /* Try to map a page at the pccons I/O space */ + base = (pointer) mmap((caddr_t) 0, 65536, PROT_READ | PROT_WRITE, + MAP_FLAGS, fd, (off_t) 0x0000); + + if (base != (pointer) -1) { + IOPortBase = base; + } + else { + xf86Msg(X_WARNING, "EnableIO: failed to mmap %s (%s)\n", + "/dev/ttyC0", strerror(errno)); + return FALSE; + } + } + else { + xf86Msg("EnableIO: failed to open %s (%s)\n", + "/dev/ttyC0", strerror(errno)); + return FALSE; + } + + ExtendedEnabled = TRUE; + + return TRUE; } void xf86DisableIO() { - return; + return; } -#endif /* USE_ARC_MMAP */ +#endif /* USE_ARC_MMAP */ #if 0 /* @@ -534,126 +507,122 @@ Bool xf86EnableIOPorts(ScreenNum) int ScreenNum; { - int i; - int fd; - pointer base; + int i; + int fd; + pointer base; #ifdef __arm32__ - struct memAccess *memInfoP; - int *Size; + struct memAccess *memInfoP; + int *Size; #endif - ScreenEnabled[ScreenNum] = TRUE; + ScreenEnabled[ScreenNum] = TRUE; - if (ExtendedEnabled) - return TRUE; + if (ExtendedEnabled) + return TRUE; #ifdef USE_ARC_MMAP - if ((fd = open("/dev/ttyC0", O_RDWR)) >= 0) { - /* Try to map a page at the pccons I/O space */ - base = (pointer)mmap((caddr_t)0, 65536, PROT_READ | PROT_WRITE, - MAP_FLAGS, fd, (off_t)0x0000); - - if (base != (pointer)-1) { - IOPortBase = base; - } - else { - xf86Msg(X_ERROR, - "EnableIOPorts: failed to mmap %s (%s)\n", - "/dev/ttyC0", strerror(errno)); - } - } - else { - xf86Msg(X_ERROR, "EnableIOPorts: failed to open %s (%s)\n", - "/dev/ttyC0", strerror(errno)); - } + if ((fd = open("/dev/ttyC0", O_RDWR)) >= 0) { + /* Try to map a page at the pccons I/O space */ + base = (pointer) mmap((caddr_t) 0, 65536, PROT_READ | PROT_WRITE, + MAP_FLAGS, fd, (off_t) 0x0000); + + if (base != (pointer) -1) { + IOPortBase = base; + } + else { + xf86Msg(X_ERROR, + "EnableIOPorts: failed to mmap %s (%s)\n", + "/dev/ttyC0", strerror(errno)); + } + } + else { + xf86Msg(X_ERROR, "EnableIOPorts: failed to open %s (%s)\n", + "/dev/ttyC0", strerror(errno)); + } #endif #ifdef __arm32__ - IOPortBase = (unsigned int)-1; - - if((memInfoP = checkMapInfo(TRUE, MMIO_REGION)) != NULL) - { - /* - * xf86MapInfoMap maps an offset from the start of video IO - * space (e.g. 0x3B0), but IOPortBase is expected to map to - * physical address 0x000, so subtract the start of video I/O - * space from the result. This is safe for now becase we - * actually mmap the start of the page, then the start of video - * I/O space is added as an internal offset. - */ - IOPortBase = (unsigned int)xf86MapInfoMap(memInfoP, - (caddr_t)0x0, 0L) - - memInfoP->memInfo.u.map_info_mmap.internal_offset; - ExtendedEnabled = TRUE; - return TRUE; - } + IOPortBase = (unsigned int) -1; + + if ((memInfoP = checkMapInfo(TRUE, MMIO_REGION)) != NULL) { + /* + * xf86MapInfoMap maps an offset from the start of video IO + * space (e.g. 0x3B0), but IOPortBase is expected to map to + * physical address 0x000, so subtract the start of video I/O + * space from the result. This is safe for now becase we + * actually mmap the start of the page, then the start of video + * I/O space is added as an internal offset. + */ + IOPortBase = (unsigned int) xf86MapInfoMap(memInfoP, (caddr_t) 0x0, 0L) + - memInfoP->memInfo.u.map_info_mmap.internal_offset; + ExtendedEnabled = TRUE; + return TRUE; + } #ifdef USE_ARM32_MMAP - checkDevMem(TRUE); + checkDevMem(TRUE); - if (devMemFd >= 0 && useDevMem) - { - base = (pointer)mmap((caddr_t)0, 0x400, PROT_READ | PROT_WRITE, - MAP_FLAGS, devMemFd, (off_t)DEV_MEM_IOBASE); + if (devMemFd >= 0 && useDevMem) { + base = (pointer) mmap((caddr_t) 0, 0x400, PROT_READ | PROT_WRITE, + MAP_FLAGS, devMemFd, (off_t) DEV_MEM_IOBASE); - if (base != (pointer)-1) - IOPortBase = (unsigned int)base; - } + if (base != (pointer) -1) + IOPortBase = (unsigned int) base; + } - if (IOPortBase == (unsigned int)-1) - { - xf86Msg(X_WARNING,"xf86EnableIOPorts: failed to open mem device or map IO base. \n\ + if (IOPortBase == (unsigned int) -1) { + xf86Msg(X_WARNING, + "xf86EnableIOPorts: failed to open mem device or map IO base. \n\ Make sure you have the Aperture Driver installed, or a kernel built with the INSECURE option\n"); - return FALSE; - } + return FALSE; + } #else - /* We don't have the IOBASE, so we can't map the address */ - xf86Msg(X_WARNING,"xf86EnableIOPorts: failed to open mem device or map IO base. \n\ + /* We don't have the IOBASE, so we can't map the address */ + xf86Msg(X_WARNING, + "xf86EnableIOPorts: failed to open mem device or map IO base. \n\ Try building the server with USE_ARM32_MMAP defined\n"); - return FALSE; + return FALSE; #endif #endif - - ExtendedEnabled = TRUE; - return TRUE; + ExtendedEnabled = TRUE; + + return TRUE; } void xf86DisableIOPorts(ScreenNum) int ScreenNum; { - int i; + int i; + #ifdef __arm32__ - struct memAccess *memInfoP; + struct memAccess *memInfoP; #endif - ScreenEnabled[ScreenNum] = FALSE; + ScreenEnabled[ScreenNum] = FALSE; #ifdef __arm32__ - if((memInfoP = checkMapInfo(FALSE, MMIO_REGION)) != NULL) - { - xf86MapInfoUnmap(memInfoP, 0); - } + if ((memInfoP = checkMapInfo(FALSE, MMIO_REGION)) != NULL) { + xf86MapInfoUnmap(memInfoP, 0); + } #endif #ifdef USE_ARM32_MMAP - if (!ExtendedEnabled) - return; + if (!ExtendedEnabled) + return; - for (i = 0; i < MAXSCREENS; i++) - if (ScreenEnabled[i]) - return; + for (i = 0; i < MAXSCREENS; i++) + if (ScreenEnabled[i]) + return; - munmap((caddr_t)IOPortBase, 0x400); - IOPortBase = (unsigned int)-1; - ExtendedEnabled = FALSE; + munmap((caddr_t) IOPortBase, 0x400); + IOPortBase = (unsigned int) -1; + ExtendedEnabled = FALSE; #endif - return; + return; } -#endif /* USE_ARC_MMAP || USE_ARM32_MMAP */ +#endif /* USE_ARC_MMAP || USE_ARM32_MMAP */ #endif - - diff --git a/xorg-server/hw/xfree86/os-support/bsd/bsd_apm.c b/xorg-server/hw/xfree86/os-support/bsd/bsd_apm.c index 73c88dca3..a8a4164e0 100644 --- a/xorg-server/hw/xfree86/os-support/bsd/bsd_apm.c +++ b/xorg-server/hw/xfree86/os-support/bsd/bsd_apm.c @@ -20,20 +20,22 @@ static void bsdCloseAPM(void); static struct { u_int apmBsd; pmEvent xf86; -} bsdToXF86Array [] = { - { APM_STANDBY_REQ, XF86_APM_SYS_STANDBY }, - { APM_SUSPEND_REQ, XF86_APM_SYS_SUSPEND }, - { APM_NORMAL_RESUME, XF86_APM_NORMAL_RESUME }, - { APM_CRIT_RESUME, XF86_APM_CRITICAL_RESUME }, - { APM_BATTERY_LOW, XF86_APM_LOW_BATTERY }, - { APM_POWER_CHANGE, XF86_APM_POWER_STATUS_CHANGE }, - { APM_UPDATE_TIME, XF86_APM_UPDATE_TIME }, - { APM_CRIT_SUSPEND_REQ, XF86_APM_CRITICAL_SUSPEND }, - { APM_USER_STANDBY_REQ, XF86_APM_USER_STANDBY }, - { APM_USER_SUSPEND_REQ, XF86_APM_USER_SUSPEND }, - { APM_SYS_STANDBY_RESUME, XF86_APM_STANDBY_RESUME }, +} bsdToXF86Array[] = { + { + APM_STANDBY_REQ, XF86_APM_SYS_STANDBY}, { + APM_SUSPEND_REQ, XF86_APM_SYS_SUSPEND}, { + APM_NORMAL_RESUME, XF86_APM_NORMAL_RESUME}, { + APM_CRIT_RESUME, XF86_APM_CRITICAL_RESUME}, { + APM_BATTERY_LOW, XF86_APM_LOW_BATTERY}, { + APM_POWER_CHANGE, XF86_APM_POWER_STATUS_CHANGE}, { + APM_UPDATE_TIME, XF86_APM_UPDATE_TIME}, { + APM_CRIT_SUSPEND_REQ, XF86_APM_CRITICAL_SUSPEND}, { + APM_USER_STANDBY_REQ, XF86_APM_USER_STANDBY}, { + APM_USER_SUSPEND_REQ, XF86_APM_USER_SUSPEND}, { + APM_SYS_STANDBY_RESUME, XF86_APM_STANDBY_RESUME}, #ifdef APM_CAPABILITY_CHANGE - { APM_CAPABILITY_CHANGE, XF86_APM_CAPABILITY_CHANGED }, + { + APM_CAPABILITY_CHANGE, XF86_APM_CAPABILITY_CHANGED}, #endif }; @@ -45,9 +47,9 @@ bsdToXF86(int type) int i; for (i = 0; i < numApmEvents; i++) { - if (type == bsdToXF86Array[i].apmBsd) { - return bsdToXF86Array[i].xf86; - } + if (type == bsdToXF86Array[i].apmBsd) { + return bsdToXF86Array[i].xf86; + } } return XF86_APM_UNKNOWN; } @@ -55,22 +57,22 @@ bsdToXF86(int type) /* * APM events can be requested direclty from /dev/apm */ -static int -bsdPMGetEventFromOS(int fd, pmEvent *events, int num) +static int +bsdPMGetEventFromOS(int fd, pmEvent * events, int num) { struct apm_event_info bsdEvent; int i; for (i = 0; i < num; i++) { - - if (ioctl(fd, APM_IOC_NEXTEVENT, &bsdEvent) < 0) { - if (errno != EAGAIN) { - xf86Msg(X_WARNING, "bsdPMGetEventFromOS: APM_IOC_NEXTEVENT" - " %s\n", strerror(errno)); - } - break; - } - events[i] = bsdToXF86(bsdEvent.type); + + if (ioctl(fd, APM_IOC_NEXTEVENT, &bsdEvent) < 0) { + if (errno != EAGAIN) { + xf86Msg(X_WARNING, "bsdPMGetEventFromOS: APM_IOC_NEXTEVENT" + " %s\n", strerror(errno)); + } + break; + } + events[i] = bsdToXF86(bsdEvent.type); } return i; } @@ -84,27 +86,27 @@ static pmWait bsdPMConfirmEventToOs(int fd, pmEvent event) { switch (event) { - case XF86_APM_SYS_STANDBY: - case XF86_APM_USER_STANDBY: - if (ioctl( fd, APM_IOC_STANDBY, NULL ) == 0) - return PM_WAIT; /* should we stop the Xserver in standby, too? */ + case XF86_APM_SYS_STANDBY: + case XF86_APM_USER_STANDBY: + if (ioctl(fd, APM_IOC_STANDBY, NULL) == 0) + return PM_WAIT; /* should we stop the Xserver in standby, too? */ else return PM_NONE; - case XF86_APM_SYS_SUSPEND: - case XF86_APM_CRITICAL_SUSPEND: - case XF86_APM_USER_SUSPEND: - if (ioctl( fd, APM_IOC_SUSPEND, NULL ) == 0) + case XF86_APM_SYS_SUSPEND: + case XF86_APM_CRITICAL_SUSPEND: + case XF86_APM_USER_SUSPEND: + if (ioctl(fd, APM_IOC_SUSPEND, NULL) == 0) return PM_WAIT; else return PM_NONE; - case XF86_APM_STANDBY_RESUME: - case XF86_APM_NORMAL_RESUME: - case XF86_APM_CRITICAL_RESUME: - case XF86_APM_STANDBY_FAILED: - case XF86_APM_SUSPEND_FAILED: + case XF86_APM_STANDBY_RESUME: + case XF86_APM_NORMAL_RESUME: + case XF86_APM_CRITICAL_RESUME: + case XF86_APM_STANDBY_FAILED: + case XF86_APM_SUSPEND_FAILED: return PM_CONTINUE; - default: - return PM_NONE; + default: + return PM_NONE; } } @@ -114,11 +116,11 @@ xf86OSPMOpen(void) int fd; if (APMihPtr || !xf86Info.pmFlag) { - return NULL; + return NULL; } if ((fd = open(APM_DEVICE, O_RDWR)) == -1) { - return NULL; + return NULL; } xf86PMGetEventFromOs = bsdPMGetEventFromOS; xf86PMConfirmEventToOs = bsdPMConfirmEventToOs; @@ -132,8 +134,8 @@ bsdCloseAPM(void) int fd; if (APMihPtr) { - fd = xf86RemoveGeneralHandler(APMihPtr); - close(fd); - APMihPtr = NULL; + fd = xf86RemoveGeneralHandler(APMihPtr); + close(fd); + APMihPtr = NULL; } } diff --git a/xorg-server/hw/xfree86/os-support/bsd/bsd_axp.c b/xorg-server/hw/xfree86/os-support/bsd/bsd_axp.c index 77c87ce1d..e7a36f8bf 100644 --- a/xorg-server/hw/xfree86/os-support/bsd/bsd_axp.c +++ b/xorg-server/hw/xfree86/os-support/bsd/bsd_axp.c @@ -24,49 +24,48 @@ axpDevice bsdGetAXP(void); */ typedef struct { - char *name; - int type; -} _AXP; + char *name; + int type; +} _AXP; static _AXP axpList[] = { - {"apecs",APECS}, - {"pyxis",PYXIS}, - {"cia",CIA}, - {"irongate",IRONGATE}, - {"lca",LCA}, - {"t2",T2}, - {"tsunami",TSUNAMI}, - {NULL,SYS_NONE} + {"apecs", APECS}, + {"pyxis", PYXIS}, + {"cia", CIA}, + {"irongate", IRONGATE}, + {"lca", LCA}, + {"t2", T2}, + {"tsunami", TSUNAMI}, + {NULL, SYS_NONE} }; axpDevice bsdGetAXP(void) { - int i; - char sysname[64]; - size_t len = sizeof(sysname); - + int i; + char sysname[64]; + size_t len = sizeof(sysname); + #ifdef __OpenBSD__ - int mib[3]; - int error; + int mib[3]; + int error; - mib[0] = CTL_MACHDEP; - mib[1] = CPU_CHIPSET; - mib[2] = CPU_CHIPSET_TYPE; + mib[0] = CTL_MACHDEP; + mib[1] = CPU_CHIPSET; + mib[2] = CPU_CHIPSET_TYPE; - if ((error = sysctl(mib, 3, &sysname, &len, NULL, 0)) < 0) -#else - if ((sysctlbyname("hw.chipset.type", &sysname, &len, - 0, 0)) < 0) + if ((error = sysctl(mib, 3, &sysname, &len, NULL, 0)) < 0) +#else + if ((sysctlbyname("hw.chipset.type", &sysname, &len, 0, 0)) < 0) #endif - FatalError("bsdGetAXP: can't find machine type\n"); + FatalError("bsdGetAXP: can't find machine type\n"); #ifdef DEBUG - xf86Msg(X_INFO,"AXP is a: %s\n",sysname); + xf86Msg(X_INFO, "AXP is a: %s\n", sysname); #endif - for (i=0;;i++) { - if (axpList[i].name == NULL) - return SYS_NONE; - if (!strcmp(sysname, axpList[i].name)) - return axpList[i].type; - } -} + for (i = 0;; i++) { + if (axpList[i].name == NULL) + return SYS_NONE; + if (!strcmp(sysname, axpList[i].name)) + return axpList[i].type; + } +} diff --git a/xorg-server/hw/xfree86/os-support/bsd/bsd_bell.c b/xorg-server/hw/xfree86/os-support/bsd/bsd_bell.c index fb457db71..f6643ee62 100644 --- a/xorg-server/hw/xfree86/os-support/bsd/bsd_bell.c +++ b/xorg-server/hw/xfree86/os-support/bsd/bsd_bell.c @@ -41,42 +41,40 @@ void xf86OSRingBell(int loudness, int pitch, int duration) { #ifdef WSCONS_SUPPORT - struct wskbd_bell_data wsb; + struct wskbd_bell_data wsb; #endif - if (loudness && pitch) - { + if (loudness && pitch) { #ifdef PCCONS_SUPPORT - int data[2]; + int data[2]; #endif - switch (xf86Info.consType) { + switch (xf86Info.consType) { #ifdef PCCONS_SUPPORT - case PCCONS: - data[0] = pitch; - data[1] = (duration * loudness) / 50; - ioctl(xf86Info.consoleFd, CONSOLE_X_BELL, data); - break; + case PCCONS: + data[0] = pitch; + data[1] = (duration * loudness) / 50; + ioctl(xf86Info.consoleFd, CONSOLE_X_BELL, data); + break; #endif #if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT) - case SYSCONS: - case PCVT: - ioctl(xf86Info.consoleFd, KDMKTONE, - ((1193190 / pitch) & 0xffff) | - (((unsigned long)duration*loudness/50)<<16)); - break; + case SYSCONS: + case PCVT: + ioctl(xf86Info.consoleFd, KDMKTONE, + ((1193190 / pitch) & 0xffff) | + (((unsigned long) duration * loudness / 50) << 16)); + break; #endif #if defined (WSCONS_SUPPORT) - case WSCONS: - wsb.which = WSKBD_BELL_DOALL; - wsb.pitch = pitch; - wsb.period = duration; - wsb.volume = loudness; - ioctl(xf86Info.consoleFd, WSKBDIO_COMPLEXBELL, - &wsb); - break; + case WSCONS: + wsb.which = WSKBD_BELL_DOALL; + wsb.pitch = pitch; + wsb.period = duration; + wsb.volume = loudness; + ioctl(xf86Info.consoleFd, WSKBDIO_COMPLEXBELL, &wsb); + break; #endif - } } + } } diff --git a/xorg-server/hw/xfree86/os-support/bsd/bsd_init.c b/xorg-server/hw/xfree86/os-support/bsd/bsd_init.c index 7079d62b4..c9f823321 100644 --- a/xorg-server/hw/xfree86/os-support/bsd/bsd_init.c +++ b/xorg-server/hw/xfree86/os-support/bsd/bsd_init.c @@ -67,9 +67,9 @@ static int initialVT = -1; #ifdef PCVT_SUPPORT /* Hellmuth Michaelis' pcvt driver */ #ifndef __OpenBSD__ -# define PCVT_CONSOLE_DEV "/dev/ttyv0" +#define PCVT_CONSOLE_DEV "/dev/ttyv0" #else -# define PCVT_CONSOLE_DEV "/dev/ttyC0" +#define PCVT_CONSOLE_DEV "/dev/ttyC0" #endif #define PCVT_CONSOLE_MODE O_RDWR|O_NDELAY #endif @@ -88,20 +88,19 @@ static int initialVT = -1; static char *supported_drivers[] = { #ifdef PCCONS_SUPPORT - "pccons (with X support)", + "pccons (with X support)", #endif #ifdef SYSCONS_SUPPORT - "syscons", + "syscons", #endif #ifdef PCVT_SUPPORT - "pcvt", + "pcvt", #endif #ifdef WSCONS_SUPPORT - "wscons", + "wscons", #endif }; - /* * Functions to probe for the existance of a supported console driver. * Any function returns either a valid file descriptor (driver probed @@ -110,19 +109,19 @@ static char *supported_drivers[] = { * an X server. */ -typedef int (*xf86ConsOpen_t)(void); +typedef int (*xf86ConsOpen_t) (void); #ifdef PCCONS_SUPPORT static int xf86OpenPccons(void); -#endif /* PCCONS_SUPPORT */ +#endif /* PCCONS_SUPPORT */ #ifdef SYSCONS_SUPPORT static int xf86OpenSyscons(void); -#endif /* SYSCONS_SUPPORT */ +#endif /* SYSCONS_SUPPORT */ #ifdef PCVT_SUPPORT static int xf86OpenPcvt(void); -#endif /* PCVT_SUPPORT */ +#endif /* PCVT_SUPPORT */ #ifdef WSCONS_SUPPORT static int xf86OpenWScons(void); @@ -147,191 +146,174 @@ static xf86ConsOpen_t xf86ConsTab[] = { #ifdef WSCONS_SUPPORT xf86OpenWScons, #endif - (xf86ConsOpen_t)NULL + (xf86ConsOpen_t) NULL }; - void xf86OpenConsole() { int i, fd = -1; xf86ConsOpen_t *driver; + #if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT) int result; + #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) struct utsname uts; #endif vtmode_t vtmode; #endif - - if (serverGeneration == 1) - { - /* check if we are run with euid==0 */ - if (geteuid() != 0) - { - FatalError("xf86OpenConsole: Server must be suid root"); - } - - if (!KeepTty) - { - /* - * detaching the controlling tty solves problems of kbd character - * loss. This is not interesting for CO driver, because it is - * exclusive. - */ - setpgrp(0, getpid()); - if ((i = open("/dev/tty",O_RDWR)) >= 0) - { - ioctl(i,TIOCNOTTY,(char *)0); - close(i); - } - } - - /* detect which driver we are running on */ - for (driver = xf86ConsTab; *driver; driver++) - { - if ((fd = (*driver)()) >= 0) - break; - } - - /* Check that a supported console driver was found */ - if (fd < 0) - { - char cons_drivers[80] = {0, }; - for (i = 0; i < sizeof(supported_drivers) / sizeof(char *); i++) - { - if (i) - { - strcat(cons_drivers, ", "); - } - strcat(cons_drivers, supported_drivers[i]); - } - FatalError( - "%s: No console driver found\n\tSupported drivers: %s\n\t%s", - "xf86OpenConsole", cons_drivers, CHECK_DRIVER_MSG); - } - xf86Info.consoleFd = fd; - - switch (xf86Info.consType) - { + + if (serverGeneration == 1) { + /* check if we are run with euid==0 */ + if (geteuid() != 0) { + FatalError("xf86OpenConsole: Server must be suid root"); + } + + if (!KeepTty) { + /* + * detaching the controlling tty solves problems of kbd character + * loss. This is not interesting for CO driver, because it is + * exclusive. + */ + setpgrp(0, getpid()); + if ((i = open("/dev/tty", O_RDWR)) >= 0) { + ioctl(i, TIOCNOTTY, (char *) 0); + close(i); + } + } + + /* detect which driver we are running on */ + for (driver = xf86ConsTab; *driver; driver++) { + if ((fd = (*driver) ()) >= 0) + break; + } + + /* Check that a supported console driver was found */ + if (fd < 0) { + char cons_drivers[80] = { 0, }; + for (i = 0; i < sizeof(supported_drivers) / sizeof(char *); i++) { + if (i) { + strcat(cons_drivers, ", "); + } + strcat(cons_drivers, supported_drivers[i]); + } + FatalError + ("%s: No console driver found\n\tSupported drivers: %s\n\t%s", + "xf86OpenConsole", cons_drivers, CHECK_DRIVER_MSG); + } + xf86Info.consoleFd = fd; + + switch (xf86Info.consType) { #ifdef PCCONS_SUPPORT - case PCCONS: - if (ioctl (xf86Info.consoleFd, CONSOLE_X_MODE_ON, 0) < 0) - { - FatalError("%s: CONSOLE_X_MODE_ON failed (%s)\n%s", - "xf86OpenConsole", strerror(errno), - CHECK_DRIVER_MSG); - } - /* - * Hack to prevent keyboard hanging when syslogd closes - * /dev/console - */ - if ((devConsoleFd = open("/dev/console", O_WRONLY,0)) < 0) - { - xf86Msg(X_WARNING, - "xf86OpenConsole: couldn't open /dev/console (%s)\n", - strerror(errno)); - } - break; + case PCCONS: + if (ioctl(xf86Info.consoleFd, CONSOLE_X_MODE_ON, 0) < 0) { + FatalError("%s: CONSOLE_X_MODE_ON failed (%s)\n%s", + "xf86OpenConsole", strerror(errno), + CHECK_DRIVER_MSG); + } + /* + * Hack to prevent keyboard hanging when syslogd closes + * /dev/console + */ + if ((devConsoleFd = open("/dev/console", O_WRONLY, 0)) < 0) { + xf86Msg(X_WARNING, + "xf86OpenConsole: couldn't open /dev/console (%s)\n", + strerror(errno)); + } + break; #endif #if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT) - case SYSCONS: - /* as of FreeBSD 2.2.8, syscons driver does not need the #1 vt - * switching anymore. Here we check for FreeBSD 3.1 and up. - * Add cases for other *BSD that behave the same. - */ + case SYSCONS: + /* as of FreeBSD 2.2.8, syscons driver does not need the #1 vt + * switching anymore. Here we check for FreeBSD 3.1 and up. + * Add cases for other *BSD that behave the same. + */ #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) - uname (&uts); - i = atof(uts.release) * 100; - if (i >= 310) goto acquire_vt; + uname(&uts); + i = atof(uts.release) * 100; + if (i >= 310) + goto acquire_vt; #endif - /* otherwise fall through */ - case PCVT: + /* otherwise fall through */ + case PCVT: #if !(defined(__NetBSD__) && (__NetBSD_Version__ >= 200000000)) - /* - * First activate the #1 VT. This is a hack to allow a server - * to be started while another one is active. There should be - * a better way. - */ - if (initialVT != 1) { - - if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, 1) != 0) - { - xf86Msg(X_WARNING, - "xf86OpenConsole: VT_ACTIVATE failed\n"); - } - sleep(1); - } -#endif -acquire_vt: - if (!xf86Info.ShareVTs) { - /* - * now get the VT - */ - SYSCALL(result = - ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno)); - if (result != 0) - { - xf86Msg(X_WARNING, "xf86OpenConsole: VT_ACTIVATE failed\n"); - } - SYSCALL(result = - ioctl(xf86Info.consoleFd, VT_WAITACTIVE, xf86Info.vtno)); - if (result != 0) - { - xf86Msg(X_WARNING, "xf86OpenConsole: VT_WAITACTIVE failed\n"); - } - - signal(SIGUSR1, xf86VTRequest); - - vtmode.mode = VT_PROCESS; - vtmode.relsig = SIGUSR1; - vtmode.acqsig = SIGUSR1; - vtmode.frsig = SIGUSR1; - if (ioctl(xf86Info.consoleFd, VT_SETMODE, &vtmode) < 0) - { - FatalError("xf86OpenConsole: VT_SETMODE VT_PROCESS failed"); - } + /* + * First activate the #1 VT. This is a hack to allow a server + * to be started while another one is active. There should be + * a better way. + */ + if (initialVT != 1) { + + if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, 1) != 0) { + xf86Msg(X_WARNING, "xf86OpenConsole: VT_ACTIVATE failed\n"); + } + sleep(1); + } +#endif + acquire_vt: + if (!xf86Info.ShareVTs) { + /* + * now get the VT + */ + SYSCALL(result = + ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno)); + if (result != 0) { + xf86Msg(X_WARNING, "xf86OpenConsole: VT_ACTIVATE failed\n"); + } + SYSCALL(result = + ioctl(xf86Info.consoleFd, VT_WAITACTIVE, + xf86Info.vtno)); + if (result != 0) { + xf86Msg(X_WARNING, + "xf86OpenConsole: VT_WAITACTIVE failed\n"); + } + + signal(SIGUSR1, xf86VTRequest); + + vtmode.mode = VT_PROCESS; + vtmode.relsig = SIGUSR1; + vtmode.acqsig = SIGUSR1; + vtmode.frsig = SIGUSR1; + if (ioctl(xf86Info.consoleFd, VT_SETMODE, &vtmode) < 0) { + FatalError("xf86OpenConsole: VT_SETMODE VT_PROCESS failed"); + } #if !defined(__OpenBSD__) && !defined(USE_DEV_IO) && !defined(USE_I386_IOPL) - if (ioctl(xf86Info.consoleFd, KDENABIO, 0) < 0) - { - FatalError("xf86OpenConsole: KDENABIO failed (%s)", - strerror(errno)); - } -#endif - if (ioctl(xf86Info.consoleFd, KDSETMODE, KD_GRAPHICS) < 0) - { - FatalError("xf86OpenConsole: KDSETMODE KD_GRAPHICS failed"); - } - } else { /* xf86Info.ShareVTs */ - close(xf86Info.consoleFd); - } - break; -#endif /* SYSCONS_SUPPORT || PCVT_SUPPORT */ + if (ioctl(xf86Info.consoleFd, KDENABIO, 0) < 0) { + FatalError("xf86OpenConsole: KDENABIO failed (%s)", + strerror(errno)); + } +#endif + if (ioctl(xf86Info.consoleFd, KDSETMODE, KD_GRAPHICS) < 0) { + FatalError("xf86OpenConsole: KDSETMODE KD_GRAPHICS failed"); + } + } + else { /* xf86Info.ShareVTs */ + close(xf86Info.consoleFd); + } + break; +#endif /* SYSCONS_SUPPORT || PCVT_SUPPORT */ #ifdef WSCONS_SUPPORT - case WSCONS: - /* Nothing to do */ - break; + case WSCONS: + /* Nothing to do */ + break; #endif } } - else - { - /* serverGeneration != 1 */ + else { + /* serverGeneration != 1 */ #if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT) - if (!xf86Info.ShareVTs && - (xf86Info.consType == SYSCONS || xf86Info.consType == PCVT)) - { - if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno) != 0) - { - xf86Msg(X_WARNING, "xf86OpenConsole: VT_ACTIVATE failed\n"); - } + if (!xf86Info.ShareVTs && + (xf86Info.consType == SYSCONS || xf86Info.consType == PCVT)) { + if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno) != 0) { + xf86Msg(X_WARNING, "xf86OpenConsole: VT_ACTIVATE failed\n"); + } } -#endif /* SYSCONS_SUPPORT || PCVT_SUPPORT */ +#endif /* SYSCONS_SUPPORT || PCVT_SUPPORT */ } return; } - #ifdef PCCONS_SUPPORT static int @@ -340,26 +322,22 @@ xf86OpenPccons() int fd = -1; if ((fd = open(PCCONS_CONSOLE_DEV1, PCCONS_CONSOLE_MODE, 0)) - >= 0 || - (fd = open(PCCONS_CONSOLE_DEV2, PCCONS_CONSOLE_MODE, 0)) - >= 0) - { - if (ioctl(fd, CONSOLE_X_MODE_OFF, 0) < 0) - { - FatalError( - "%s: CONSOLE_X_MODE_OFF failed (%s)\n%s\n%s", - "xf86OpenPccons", - strerror(errno), - "Was expecting pccons driver with X support", - CHECK_DRIVER_MSG); - } - xf86Info.consType = PCCONS; - xf86Msg(X_PROBED, "Using pccons driver with X support\n"); + >= 0 || (fd = open(PCCONS_CONSOLE_DEV2, PCCONS_CONSOLE_MODE, 0)) + >= 0) { + if (ioctl(fd, CONSOLE_X_MODE_OFF, 0) < 0) { + FatalError("%s: CONSOLE_X_MODE_OFF failed (%s)\n%s\n%s", + "xf86OpenPccons", + strerror(errno), + "Was expecting pccons driver with X support", + CHECK_DRIVER_MSG); + } + xf86Info.consType = PCCONS; + xf86Msg(X_PROBED, "Using pccons driver with X support\n"); } return fd; } -#endif /* PCCONS_SUPPORT */ +#endif /* PCCONS_SUPPORT */ #ifdef SYSCONS_SUPPORT @@ -374,113 +352,98 @@ xf86OpenSyscons() /* Check for syscons */ if ((fd = open(SYSCONS_CONSOLE_DEV1, SYSCONS_CONSOLE_MODE, 0)) >= 0 - || (fd = open(SYSCONS_CONSOLE_DEV2, SYSCONS_CONSOLE_MODE, 0)) >= 0) - { - if (ioctl(fd, VT_GETMODE, &vtmode) >= 0) - { - /* Get syscons version */ - if (ioctl(fd, CONS_GETVERS, &syscons_version) < 0) - { - syscons_version = 0; - } + || (fd = open(SYSCONS_CONSOLE_DEV2, SYSCONS_CONSOLE_MODE, 0)) >= 0) { + if (ioctl(fd, VT_GETMODE, &vtmode) >= 0) { + /* Get syscons version */ + if (ioctl(fd, CONS_GETVERS, &syscons_version) < 0) { + syscons_version = 0; + } - xf86Info.vtno = VTnum; - from = X_CMDLINE; + xf86Info.vtno = VTnum; + from = X_CMDLINE; #ifdef VT_GETACTIVE - if (ioctl(fd, VT_GETACTIVE, &initialVT) < 0) - initialVT = -1; + if (ioctl(fd, VT_GETACTIVE, &initialVT) < 0) + initialVT = -1; #endif if (xf86Info.ShareVTs) - xf86Info.vtno = initialVT; + xf86Info.vtno = initialVT; - if (xf86Info.vtno == -1) - { - /* - * For old syscons versions (<0x100), VT_OPENQRY returns - * the current VT rather than the next free VT. In this - * case, the server gets started on the current VT instead - * of the next free VT. - */ + if (xf86Info.vtno == -1) { + /* + * For old syscons versions (<0x100), VT_OPENQRY returns + * the current VT rather than the next free VT. In this + * case, the server gets started on the current VT instead + * of the next free VT. + */ #if 0 - /* check for the fixed VT_OPENQRY */ - if (syscons_version >= 0x100) - { -#endif - if (ioctl(fd, VT_OPENQRY, &xf86Info.vtno) < 0) - { - /* No free VTs */ - xf86Info.vtno = -1; - } + /* check for the fixed VT_OPENQRY */ + if (syscons_version >= 0x100) { +#endif + if (ioctl(fd, VT_OPENQRY, &xf86Info.vtno) < 0) { + /* No free VTs */ + xf86Info.vtno = -1; + } #if 0 - } -#endif - - if (xf86Info.vtno == -1) - { - /* - * All VTs are in use. If initialVT was found, use it. - */ - if (initialVT != -1) - { - xf86Info.vtno = initialVT; - } - else - { - if (syscons_version >= 0x100) - { - FatalError("%s: Cannot find a free VT", - "xf86OpenSyscons"); - } - /* Should no longer reach here */ - FatalError("%s: %s %s\n\t%s %s", - "xf86OpenSyscons", - "syscons versions prior to 1.0 require", - "either the", - "server's stdin be a VT", - "or the use of the vtxx server option"); - } - } - from = X_PROBED; - } - - close(fd); - snprintf(vtname, sizeof(vtname), "/dev/ttyv%01x", xf86Info.vtno - 1); - if ((fd = open(vtname, SYSCONS_CONSOLE_MODE, 0)) < 0) - { - FatalError("xf86OpenSyscons: Cannot open %s (%s)", - vtname, strerror(errno)); - } - if (ioctl(fd, VT_GETMODE, &vtmode) < 0) - { - FatalError("xf86OpenSyscons: VT_GETMODE failed"); - } - xf86Info.consType = SYSCONS; - xf86Msg(X_PROBED, "Using syscons driver with X support"); - if (syscons_version >= 0x100) - { - xf86ErrorF(" (version %ld.%ld)\n", syscons_version >> 8, - syscons_version & 0xFF); - } - else - { - xf86ErrorF(" (version 0.x)\n"); - } - xf86Msg(from, "using VT number %d\n\n", xf86Info.vtno); - } - else - { - /* VT_GETMODE failed, probably not syscons */ - close(fd); - fd = -1; - } + } +#endif + + if (xf86Info.vtno == -1) { + /* + * All VTs are in use. If initialVT was found, use it. + */ + if (initialVT != -1) { + xf86Info.vtno = initialVT; + } + else { + if (syscons_version >= 0x100) { + FatalError("%s: Cannot find a free VT", + "xf86OpenSyscons"); + } + /* Should no longer reach here */ + FatalError("%s: %s %s\n\t%s %s", + "xf86OpenSyscons", + "syscons versions prior to 1.0 require", + "either the", + "server's stdin be a VT", + "or the use of the vtxx server option"); + } + } + from = X_PROBED; + } + + close(fd); + snprintf(vtname, sizeof(vtname), "/dev/ttyv%01x", + xf86Info.vtno - 1); + if ((fd = open(vtname, SYSCONS_CONSOLE_MODE, 0)) < 0) { + FatalError("xf86OpenSyscons: Cannot open %s (%s)", + vtname, strerror(errno)); + } + if (ioctl(fd, VT_GETMODE, &vtmode) < 0) { + FatalError("xf86OpenSyscons: VT_GETMODE failed"); + } + xf86Info.consType = SYSCONS; + xf86Msg(X_PROBED, "Using syscons driver with X support"); + if (syscons_version >= 0x100) { + xf86ErrorF(" (version %ld.%ld)\n", syscons_version >> 8, + syscons_version & 0xFF); + } + else { + xf86ErrorF(" (version 0.x)\n"); + } + xf86Msg(from, "using VT number %d\n\n", xf86Info.vtno); + } + else { + /* VT_GETMODE failed, probably not syscons */ + close(fd); + fd = -1; + } } return fd; } -#endif /* SYSCONS_SUPPORT */ - +#endif /* SYSCONS_SUPPORT */ #ifdef PCVT_SUPPORT @@ -501,93 +464,82 @@ xf86OpenPcvt() fd = open(PCVT_CONSOLE_DEV, PCVT_CONSOLE_MODE, 0); #ifdef WSCONS_PCVT_COMPAT_CONSOLE_DEV - if (fd < 0) - { - fd = open(WSCONS_PCVT_COMPAT_CONSOLE_DEV, PCVT_CONSOLE_MODE, 0); - vtprefix = "/dev/ttyE"; + if (fd < 0) { + fd = open(WSCONS_PCVT_COMPAT_CONSOLE_DEV, PCVT_CONSOLE_MODE, 0); + vtprefix = "/dev/ttyE"; } #endif - if (fd >= 0) - { - if (ioctl(fd, VGAPCVTID, &pcvt_version) >= 0) - { - if(ioctl(fd, VT_GETMODE, &vtmode) < 0) - { - FatalError("%s: VT_GETMODE failed\n%s%s\n%s", - "xf86OpenPcvt", - "Found pcvt driver but X11 seems to be", - " not supported.", CHECK_DRIVER_MSG); - } - - xf86Info.vtno = VTnum; - - if (ioctl(fd, VT_GETACTIVE, &initialVT) < 0) - initialVT = -1; - - if (xf86Info.vtno == -1) - { - if (ioctl(fd, VT_OPENQRY, &xf86Info.vtno) < 0) - { - /* No free VTs */ - xf86Info.vtno = -1; - } - - if (xf86Info.vtno == -1) - { - /* - * All VTs are in use. If initialVT was found, use it. - */ - if (initialVT != -1) - { - xf86Info.vtno = initialVT; - } - else - { - FatalError("%s: Cannot find a free VT", - "xf86OpenPcvt"); - } - } - } - - close(fd); - snprintf(vtname, sizeof(vtname), "%s%01x", vtprefix, xf86Info.vtno - 1); - if ((fd = open(vtname, PCVT_CONSOLE_MODE, 0)) < 0) - { - ErrorF("xf86OpenPcvt: Cannot open %s (%s)", - vtname, strerror(errno)); - xf86Info.vtno = initialVT; - snprintf(vtname, sizeof(vtname), "%s%01x", vtprefix, xf86Info.vtno - 1); - if ((fd = open(vtname, PCVT_CONSOLE_MODE, 0)) < 0) { - FatalError("xf86OpenPcvt: Cannot open %s (%s)", - vtname, strerror(errno)); - } - } - if (ioctl(fd, VT_GETMODE, &vtmode) < 0) - { - FatalError("xf86OpenPcvt: VT_GETMODE failed"); - } - xf86Info.consType = PCVT; + if (fd >= 0) { + if (ioctl(fd, VGAPCVTID, &pcvt_version) >= 0) { + if (ioctl(fd, VT_GETMODE, &vtmode) < 0) { + FatalError("%s: VT_GETMODE failed\n%s%s\n%s", + "xf86OpenPcvt", + "Found pcvt driver but X11 seems to be", + " not supported.", CHECK_DRIVER_MSG); + } + + xf86Info.vtno = VTnum; + + if (ioctl(fd, VT_GETACTIVE, &initialVT) < 0) + initialVT = -1; + + if (xf86Info.vtno == -1) { + if (ioctl(fd, VT_OPENQRY, &xf86Info.vtno) < 0) { + /* No free VTs */ + xf86Info.vtno = -1; + } + + if (xf86Info.vtno == -1) { + /* + * All VTs are in use. If initialVT was found, use it. + */ + if (initialVT != -1) { + xf86Info.vtno = initialVT; + } + else { + FatalError("%s: Cannot find a free VT", "xf86OpenPcvt"); + } + } + } + + close(fd); + snprintf(vtname, sizeof(vtname), "%s%01x", vtprefix, + xf86Info.vtno - 1); + if ((fd = open(vtname, PCVT_CONSOLE_MODE, 0)) < 0) { + ErrorF("xf86OpenPcvt: Cannot open %s (%s)", + vtname, strerror(errno)); + xf86Info.vtno = initialVT; + snprintf(vtname, sizeof(vtname), "%s%01x", vtprefix, + xf86Info.vtno - 1); + if ((fd = open(vtname, PCVT_CONSOLE_MODE, 0)) < 0) { + FatalError("xf86OpenPcvt: Cannot open %s (%s)", + vtname, strerror(errno)); + } + } + if (ioctl(fd, VT_GETMODE, &vtmode) < 0) { + FatalError("xf86OpenPcvt: VT_GETMODE failed"); + } + xf86Info.consType = PCVT; #ifdef WSCONS_SUPPORT - xf86Msg(X_PROBED, - "Using wscons driver on %s in pcvt compatibility mode " - "(version %d.%d)\n", vtname, - pcvt_version.rmajor, pcvt_version.rminor); + xf86Msg(X_PROBED, + "Using wscons driver on %s in pcvt compatibility mode " + "(version %d.%d)\n", vtname, + pcvt_version.rmajor, pcvt_version.rminor); #else - xf86Msg(X_PROBED, "Using pcvt driver (version %d.%d)\n", - pcvt_version.rmajor, pcvt_version.rminor); -#endif - } - else - { - /* Not pcvt */ - close(fd); - fd = -1; - } + xf86Msg(X_PROBED, "Using pcvt driver (version %d.%d)\n", + pcvt_version.rmajor, pcvt_version.rminor); +#endif + } + else { + /* Not pcvt */ + close(fd); + fd = -1; + } } return fd; } -#endif /* PCVT_SUPPORT */ +#endif /* PCVT_SUPPORT */ #ifdef WSCONS_SUPPORT @@ -602,77 +554,75 @@ xf86OpenWScons() /* XXX Is this ok? */ for (i = 0; i < 8; i++) { #if defined(__NetBSD__) - snprintf(ttyname, sizeof(ttyname), "/dev/ttyE%d", i); + snprintf(ttyname, sizeof(ttyname), "/dev/ttyE%d", i); #elif defined(__OpenBSD__) - snprintf(ttyname, sizeof(ttyname), "/dev/ttyC%x", i); + snprintf(ttyname, sizeof(ttyname), "/dev/ttyC%x", i); #endif - if ((fd = open(ttyname, 2)) != -1) - break; + if ((fd = open(ttyname, 2)) != -1) + break; } if (fd != -1) { - if (ioctl(fd, WSDISPLAYIO_SMODE, &mode) < 0) { - FatalError("%s: WSDISPLAYIO_MODE_MAPPED failed (%s)\n%s", - "xf86OpenConsole", strerror(errno), - CHECK_DRIVER_MSG); - } - xf86Info.consType = WSCONS; - xf86Msg(X_PROBED, "Using wscons driver\n"); + if (ioctl(fd, WSDISPLAYIO_SMODE, &mode) < 0) { + FatalError("%s: WSDISPLAYIO_MODE_MAPPED failed (%s)\n%s", + "xf86OpenConsole", strerror(errno), CHECK_DRIVER_MSG); + } + xf86Info.consType = WSCONS; + xf86Msg(X_PROBED, "Using wscons driver\n"); } return fd; } -#endif /* WSCONS_SUPPORT */ +#endif /* WSCONS_SUPPORT */ void xf86CloseConsole() { #if defined(SYSCONS_SUPPORT) || defined(PCVT_SUPPORT) - struct vt_mode VT; + struct vt_mode VT; #endif - if (xf86Info.ShareVTs) return; + if (xf86Info.ShareVTs) + return; - switch (xf86Info.consType) - { + switch (xf86Info.consType) { #ifdef PCCONS_SUPPORT case PCCONS: - ioctl (xf86Info.consoleFd, CONSOLE_X_MODE_OFF, 0); - break; -#endif /* PCCONS_SUPPORT */ + ioctl(xf86Info.consoleFd, CONSOLE_X_MODE_OFF, 0); + break; +#endif /* PCCONS_SUPPORT */ #if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT) case SYSCONS: case PCVT: ioctl(xf86Info.consoleFd, KDSETMODE, KD_TEXT); /* Back to text mode */ - if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) != -1) - { - VT.mode = VT_AUTO; - ioctl(xf86Info.consoleFd, VT_SETMODE, &VT); /* dflt vt handling */ + if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) != -1) { + VT.mode = VT_AUTO; + ioctl(xf86Info.consoleFd, VT_SETMODE, &VT); /* dflt vt handling */ } #if !defined(__OpenBSD__) && !defined(USE_DEV_IO) && !defined(USE_I386_IOPL) - if (ioctl(xf86Info.consoleFd, KDDISABIO, 0) < 0) - { + if (ioctl(xf86Info.consoleFd, KDDISABIO, 0) < 0) { xf86FatalError("xf86CloseConsole: KDDISABIO failed (%s)", - strerror(errno)); + strerror(errno)); } #endif - if (initialVT != -1) - ioctl(xf86Info.consoleFd, VT_ACTIVATE, initialVT); + if (initialVT != -1) + ioctl(xf86Info.consoleFd, VT_ACTIVATE, initialVT); break; -#endif /* SYSCONS_SUPPORT || PCVT_SUPPORT */ +#endif /* SYSCONS_SUPPORT || PCVT_SUPPORT */ #ifdef WSCONS_SUPPORT case WSCONS: - { - int mode = WSDISPLAYIO_MODE_EMUL; - ioctl(xf86Info.consoleFd, WSDISPLAYIO_SMODE, &mode); - break; - } + { + int mode = WSDISPLAYIO_MODE_EMUL; + + ioctl(xf86Info.consoleFd, WSDISPLAYIO_SMODE, &mode); + break; + } #endif } close(xf86Info.consoleFd); #ifdef PCCONS_SUPPORT if (devConsoleFd >= 0) - close(devConsoleFd); + close(devConsoleFd); #endif return; } @@ -680,38 +630,34 @@ xf86CloseConsole() int xf86ProcessArgument(int argc, char *argv[], int i) { - /* - * Keep server from detaching from controlling tty. This is useful - * when debugging (so the server can receive keyboard signals. - */ - if (!strcmp(argv[i], "-keeptty")) - { - KeepTty = TRUE; - return 1; - } + /* + * Keep server from detaching from controlling tty. This is useful + * when debugging (so the server can receive keyboard signals. + */ + if (!strcmp(argv[i], "-keeptty")) { + KeepTty = TRUE; + return 1; + } #if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT) - if ((argv[i][0] == 'v') && (argv[i][1] == 't')) - { - if (sscanf(argv[i], "vt%2d", &VTnum) == 0 || - VTnum < 1 || VTnum > 12) - { - UseMsg(); - VTnum = -1; - return 0; - } - return 1; - } -#endif /* SYSCONS_SUPPORT || PCVT_SUPPORT */ - return 0; + if ((argv[i][0] == 'v') && (argv[i][1] == 't')) { + if (sscanf(argv[i], "vt%2d", &VTnum) == 0 || VTnum < 1 || VTnum > 12) { + UseMsg(); + VTnum = -1; + return 0; + } + return 1; + } +#endif /* SYSCONS_SUPPORT || PCVT_SUPPORT */ + return 0; } void xf86UseMsg() { #if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT) - ErrorF("vtXX use the specified VT number (1-12)\n"); -#endif /* SYSCONS_SUPPORT || PCVT_SUPPORT */ - ErrorF("-keeptty "); - ErrorF("don't detach controlling tty (for debugging only)\n"); - return; + ErrorF("vtXX use the specified VT number (1-12)\n"); +#endif /* SYSCONS_SUPPORT || PCVT_SUPPORT */ + ErrorF("-keeptty "); + ErrorF("don't detach controlling tty (for debugging only)\n"); + return; } diff --git a/xorg-server/hw/xfree86/os-support/bsd/bsd_kmod.c b/xorg-server/hw/xfree86/os-support/bsd/bsd_kmod.c index 34e434188..150bb0db4 100644 --- a/xorg-server/hw/xfree86/os-support/bsd/bsd_kmod.c +++ b/xorg-server/hw/xfree86/os-support/bsd/bsd_kmod.c @@ -19,10 +19,11 @@ * Return: * 0 for failure, 1 for success */ -int xf86LoadKernelModule(const char *modName) +int +xf86LoadKernelModule(const char *modName) { if (kldload(modName) != -1) - return 1; + return 1; else - return 0; + return 0; } diff --git a/xorg-server/hw/xfree86/os-support/bsd/bsd_kqueue_apm.c b/xorg-server/hw/xfree86/os-support/bsd/bsd_kqueue_apm.c index 053619e1d..10251f38e 100644 --- a/xorg-server/hw/xfree86/os-support/bsd/bsd_kqueue_apm.c +++ b/xorg-server/hw/xfree86/os-support/bsd/bsd_kqueue_apm.c @@ -53,20 +53,22 @@ static void bsdCloseAPM(void); static struct { u_int apmBsd; pmEvent xf86; -} bsdToXF86Array [] = { - { APM_STANDBY_REQ, XF86_APM_SYS_STANDBY }, - { APM_SUSPEND_REQ, XF86_APM_SYS_SUSPEND }, - { APM_NORMAL_RESUME, XF86_APM_NORMAL_RESUME }, - { APM_CRIT_RESUME, XF86_APM_CRITICAL_RESUME }, - { APM_BATTERY_LOW, XF86_APM_LOW_BATTERY }, - { APM_POWER_CHANGE, XF86_APM_POWER_STATUS_CHANGE }, - { APM_UPDATE_TIME, XF86_APM_UPDATE_TIME }, - { APM_CRIT_SUSPEND_REQ, XF86_APM_CRITICAL_SUSPEND }, - { APM_USER_STANDBY_REQ, XF86_APM_USER_STANDBY }, - { APM_USER_SUSPEND_REQ, XF86_APM_USER_SUSPEND }, - { APM_SYS_STANDBY_RESUME, XF86_APM_STANDBY_RESUME }, +} bsdToXF86Array[] = { + { + APM_STANDBY_REQ, XF86_APM_SYS_STANDBY}, { + APM_SUSPEND_REQ, XF86_APM_SYS_SUSPEND}, { + APM_NORMAL_RESUME, XF86_APM_NORMAL_RESUME}, { + APM_CRIT_RESUME, XF86_APM_CRITICAL_RESUME}, { + APM_BATTERY_LOW, XF86_APM_LOW_BATTERY}, { + APM_POWER_CHANGE, XF86_APM_POWER_STATUS_CHANGE}, { + APM_UPDATE_TIME, XF86_APM_UPDATE_TIME}, { + APM_CRIT_SUSPEND_REQ, XF86_APM_CRITICAL_SUSPEND}, { + APM_USER_STANDBY_REQ, XF86_APM_USER_STANDBY}, { + APM_USER_SUSPEND_REQ, XF86_APM_USER_SUSPEND}, { + APM_SYS_STANDBY_RESUME, XF86_APM_STANDBY_RESUME}, #ifdef APM_CAPABILITY_CHANGE - { APM_CAPABILITY_CHANGE, XF86_APM_CAPABILITY_CHANGED }, + { + APM_CAPABILITY_CHANGE, XF86_APM_CAPABILITY_CHANGED}, #endif }; @@ -78,9 +80,9 @@ bsdToXF86(int type) int i; for (i = 0; i < numApmEvents; i++) { - if (type == bsdToXF86Array[i].apmBsd) { - return bsdToXF86Array[i].xf86; - } + if (type == bsdToXF86Array[i].apmBsd) { + return bsdToXF86Array[i].xf86; + } } return XF86_APM_UNKNOWN; } @@ -88,24 +90,25 @@ bsdToXF86(int type) /* * APM events can be requested direclty from /dev/apm */ -static int -bsdPMGetEventFromOS(int kq, pmEvent *events, int num) +static int +bsdPMGetEventFromOS(int kq, pmEvent * events, int num) { struct kevent ev; int i, result; struct timespec ts = { 0, 0 }; - + for (i = 0; i < num; i++) { - result = kevent(kq, NULL, 0, &ev, 1, &ts); - if (result == 0 || APM_EVENT_TYPE(ev.data) == APM_NOEVENT) { - /* no event */ - break; - } else if (result < 0) { - xf86Msg(X_WARNING, "bsdPMGetEventFromOS: kevent returns" - " %s\n", strerror(errno)); - break; - } - events[i] = bsdToXF86(APM_EVENT_TYPE(ev.data)); + result = kevent(kq, NULL, 0, &ev, 1, &ts); + if (result == 0 || APM_EVENT_TYPE(ev.data) == APM_NOEVENT) { + /* no event */ + break; + } + else if (result < 0) { + xf86Msg(X_WARNING, "bsdPMGetEventFromOS: kevent returns" + " %s\n", strerror(errno)); + break; + } + events[i] = bsdToXF86(APM_EVENT_TYPE(ev.data)); } return i; } @@ -120,36 +123,36 @@ static pmWait bsdPMConfirmEventToOs(int dummyfd, pmEvent event) { if (ctlFd < 0) { - if ((ctlFd = open(_PATH_APM_CTLDEV, O_RDWR)) < 0) { - return PM_NONE; - } + if ((ctlFd = open(_PATH_APM_CTLDEV, O_RDWR)) < 0) { + return PM_NONE; + } } /* apmctl open succeedeed */ switch (event) { - case XF86_APM_SYS_STANDBY: - case XF86_APM_USER_STANDBY: - if (ioctl( ctlFd, APM_IOC_STANDBY, NULL ) == 0) - return PM_WAIT; /* should we stop the Xserver in standby, too? */ + case XF86_APM_SYS_STANDBY: + case XF86_APM_USER_STANDBY: + if (ioctl(ctlFd, APM_IOC_STANDBY, NULL) == 0) + return PM_WAIT; /* should we stop the Xserver in standby, too? */ else return PM_NONE; - case XF86_APM_SYS_SUSPEND: - case XF86_APM_CRITICAL_SUSPEND: - case XF86_APM_USER_SUSPEND: - if (ioctl( ctlFd, APM_IOC_SUSPEND, NULL ) == 0) + case XF86_APM_SYS_SUSPEND: + case XF86_APM_CRITICAL_SUSPEND: + case XF86_APM_USER_SUSPEND: + if (ioctl(ctlFd, APM_IOC_SUSPEND, NULL) == 0) return PM_WAIT; else return PM_NONE; - break; - case XF86_APM_STANDBY_RESUME: - case XF86_APM_NORMAL_RESUME: - case XF86_APM_CRITICAL_RESUME: - case XF86_APM_STANDBY_FAILED: - case XF86_APM_SUSPEND_FAILED: + break; + case XF86_APM_STANDBY_RESUME: + case XF86_APM_NORMAL_RESUME: + case XF86_APM_CRITICAL_RESUME: + case XF86_APM_STANDBY_FAILED: + case XF86_APM_SUSPEND_FAILED: return PM_CONTINUE; - break; - default: - return PM_NONE; + break; + default: + return PM_NONE; } } @@ -160,20 +163,19 @@ xf86OSPMOpen(void) struct kevent ev; if (APMihPtr || !xf86Info.pmFlag) { - return NULL; + return NULL; } if ((devFd = open(_PATH_APM_DEV, O_RDONLY)) == -1) { - return NULL; + return NULL; } if ((kq = kqueue()) <= 0) { - close(devFd); - return NULL; + close(devFd); + return NULL; } - EV_SET(&ev, devFd, EVFILT_READ, EV_ADD | EV_ENABLE | EV_CLEAR, - 0, 0, NULL); + EV_SET(&ev, devFd, EVFILT_READ, EV_ADD | EV_ENABLE | EV_CLEAR, 0, 0, NULL); if (kevent(kq, &ev, 1, NULL, 0, NULL) < 0) { - close(devFd); - return NULL; + close(devFd); + return NULL; } xf86PMGetEventFromOs = bsdPMGetEventFromOS; @@ -188,14 +190,14 @@ bsdCloseAPM(void) int kq; if (APMihPtr) { - kq = xf86RemoveGeneralHandler(APMihPtr); - close(devFd); - devFd = -1; - close(kq); - if (ctlFd >= 0) { - close(ctlFd); - ctlFd = -1; - } - APMihPtr = NULL; + kq = xf86RemoveGeneralHandler(APMihPtr); + close(devFd); + devFd = -1; + close(kq); + if (ctlFd >= 0) { + close(ctlFd); + ctlFd = -1; + } + APMihPtr = NULL; } } diff --git a/xorg-server/hw/xfree86/os-support/bsd/i386_video.c b/xorg-server/hw/xfree86/os-support/bsd/i386_video.c index 35e00fce7..569a4ec51 100644 --- a/xorg-server/hw/xfree86/os-support/bsd/i386_video.c +++ b/xorg-server/hw/xfree86/os-support/bsd/i386_video.c @@ -79,7 +79,7 @@ /***************************************************************************/ static Bool useDevMem = FALSE; -static int devMemFd = -1; +static int devMemFd = -1; #ifdef HAS_APERTURE_DRV #define DEV_APERTURE "/dev/xf86" @@ -95,7 +95,7 @@ static Bool cleanMTRR(void); #endif #if defined(HAS_MTRR_BUILTIN) && defined(__NetBSD__) static pointer NetBSDsetWC(int, unsigned long, unsigned long, Bool, - MessageType); + MessageType); static void NetBSDundoWC(int, pointer); #endif @@ -106,85 +106,80 @@ static void NetBSDundoWC(int, pointer); static void checkDevMem(Bool warn) { - static Bool devMemChecked = FALSE; - int fd; - pointer base; - - if (devMemChecked) - return; - devMemChecked = TRUE; - - if ((fd = open(DEV_MEM, O_RDWR)) >= 0) - { - /* Try to map a page at the VGA address */ - base = mmap((caddr_t)0, 4096, PROT_READ | PROT_WRITE, - MAP_FLAGS, fd, (off_t)0xA0000); - - if (base != MAP_FAILED) - { - munmap((caddr_t)base, 4096); - devMemFd = fd; - useDevMem = TRUE; - return; - } else { - /* This should not happen */ - if (warn) - { - xf86Msg(X_WARNING, "checkDevMem: failed to mmap %s (%s)\n", - DEV_MEM, strerror(errno)); - } - useDevMem = FALSE; - return; - } - } + static Bool devMemChecked = FALSE; + int fd; + pointer base; + + if (devMemChecked) + return; + devMemChecked = TRUE; + + if ((fd = open(DEV_MEM, O_RDWR)) >= 0) { + /* Try to map a page at the VGA address */ + base = mmap((caddr_t) 0, 4096, PROT_READ | PROT_WRITE, + MAP_FLAGS, fd, (off_t) 0xA0000); + + if (base != MAP_FAILED) { + munmap((caddr_t) base, 4096); + devMemFd = fd; + useDevMem = TRUE; + return; + } + else { + /* This should not happen */ + if (warn) { + xf86Msg(X_WARNING, "checkDevMem: failed to mmap %s (%s)\n", + DEV_MEM, strerror(errno)); + } + useDevMem = FALSE; + return; + } + } #ifndef HAS_APERTURE_DRV - if (warn) - { - xf86Msg(X_WARNING, "checkDevMem: failed to open %s (%s)\n", - DEV_MEM, strerror(errno)); - } - useDevMem = FALSE; - return; + if (warn) { + xf86Msg(X_WARNING, "checkDevMem: failed to open %s (%s)\n", + DEV_MEM, strerror(errno)); + } + useDevMem = FALSE; + return; #else - /* Failed to open /dev/mem, try the aperture driver */ - if ((fd = open(DEV_APERTURE, O_RDWR)) >= 0) - { - /* Try to map a page at the VGA address */ - base = mmap((caddr_t)0, 4096, PROT_READ | PROT_WRITE, - MAP_FLAGS, fd, (off_t)0xA0000); - - if (base != MAP_FAILED) - { - munmap((caddr_t)base, 4096); - devMemFd = fd; - useDevMem = TRUE; - xf86Msg(X_INFO, "checkDevMem: using aperture driver %s\n", - DEV_APERTURE); - return; - } else { - - if (warn) - { - xf86Msg(X_WARNING, "checkDevMem: failed to mmap %s (%s)\n", - DEV_APERTURE, strerror(errno)); - } - } - } else { - if (warn) - { + /* Failed to open /dev/mem, try the aperture driver */ + if ((fd = open(DEV_APERTURE, O_RDWR)) >= 0) { + /* Try to map a page at the VGA address */ + base = mmap((caddr_t) 0, 4096, PROT_READ | PROT_WRITE, + MAP_FLAGS, fd, (off_t) 0xA0000); + + if (base != MAP_FAILED) { + munmap((caddr_t) base, 4096); + devMemFd = fd; + useDevMem = TRUE; + xf86Msg(X_INFO, "checkDevMem: using aperture driver %s\n", + DEV_APERTURE); + return; + } + else { + + if (warn) { + xf86Msg(X_WARNING, "checkDevMem: failed to mmap %s (%s)\n", + DEV_APERTURE, strerror(errno)); + } + } + } + else { + if (warn) { #ifndef __OpenBSD__ - xf86Msg(X_WARNING, "checkDevMem: failed to open %s and %s\n" - "\t(%s)\n", DEV_MEM, DEV_APERTURE, strerror(errno)); -#else /* __OpenBSD__ */ - xf86Msg(X_WARNING, "checkDevMem: failed to open %s and %s\n" - "\t(%s)\n%s", DEV_MEM, DEV_APERTURE, strerror(errno), - SYSCTL_MSG); -#endif /* __OpenBSD__ */ - } - } - - useDevMem = FALSE; - return; + xf86Msg(X_WARNING, "checkDevMem: failed to open %s and %s\n" + "\t(%s)\n", DEV_MEM, DEV_APERTURE, strerror(errno)); +#else /* __OpenBSD__ */ + xf86Msg(X_WARNING, "checkDevMem: failed to open %s and %s\n" + "\t(%s)\n%s", DEV_MEM, DEV_APERTURE, strerror(errno), + SYSCTL_MSG); +#endif /* __OpenBSD__ */ + } + } + + useDevMem = FALSE; + return; #endif } @@ -192,80 +187,72 @@ checkDevMem(Bool warn) void xf86OSInitVidMem(VidMemInfoPtr pVidMem) { - checkDevMem(TRUE); - pVidMem->linearSupported = useDevMem; - pVidMem->mapMem = mapVidMem; - pVidMem->unmapMem = unmapVidMem; + checkDevMem(TRUE); + pVidMem->linearSupported = useDevMem; + pVidMem->mapMem = mapVidMem; + pVidMem->unmapMem = unmapVidMem; - if (useDevMem) - pci_system_init_dev_mem(devMemFd); + if (useDevMem) + pci_system_init_dev_mem(devMemFd); #ifdef HAS_MTRR_SUPPORT - if (useDevMem) { - if (cleanMTRR()) { - pVidMem->setWC = setWC; - pVidMem->undoWC = undoWC; - } - } + if (useDevMem) { + if (cleanMTRR()) { + pVidMem->setWC = setWC; + pVidMem->undoWC = undoWC; + } + } #endif #if defined(HAS_MTRR_BUILTIN) && defined(__NetBSD__) - pVidMem->setWC = NetBSDsetWC; - pVidMem->undoWC = NetBSDundoWC; + pVidMem->setWC = NetBSDsetWC; + pVidMem->undoWC = NetBSDundoWC; #endif - pVidMem->initialised = TRUE; + pVidMem->initialised = TRUE; } static pointer mapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags) { - pointer base; - - checkDevMem(FALSE); - - if (useDevMem) - { - if (devMemFd < 0) - { - FatalError("xf86MapVidMem: failed to open %s (%s)", - DEV_MEM, strerror(errno)); - } - base = mmap((caddr_t)0, Size, - (flags & VIDMEM_READONLY) ? - PROT_READ : (PROT_READ | PROT_WRITE), - MAP_FLAGS, devMemFd, (off_t)Base); - if (base == MAP_FAILED) - { - FatalError("%s: could not mmap %s [s=%lx,a=%lx] (%s)", - "xf86MapVidMem", DEV_MEM, Size, Base, - strerror(errno)); - } - return base; - } - - /* else, mmap /dev/vga */ - if ((unsigned long)Base < 0xA0000 || (unsigned long)Base >= 0xC0000) - { - FatalError("%s: Address 0x%lx outside allowable range", - "xf86MapVidMem", Base); - } - base = mmap(0, Size, - (flags & VIDMEM_READONLY) ? - PROT_READ : (PROT_READ | PROT_WRITE), - MAP_FLAGS, xf86Info.consoleFd, - (unsigned long)Base - 0xA0000 - ); - if (base == MAP_FAILED) - { - FatalError("xf86MapVidMem: Could not mmap /dev/vga (%s)", - strerror(errno)); - } - return base; + pointer base; + + checkDevMem(FALSE); + + if (useDevMem) { + if (devMemFd < 0) { + FatalError("xf86MapVidMem: failed to open %s (%s)", + DEV_MEM, strerror(errno)); + } + base = mmap((caddr_t) 0, Size, + (flags & VIDMEM_READONLY) ? + PROT_READ : (PROT_READ | PROT_WRITE), + MAP_FLAGS, devMemFd, (off_t) Base); + if (base == MAP_FAILED) { + FatalError("%s: could not mmap %s [s=%lx,a=%lx] (%s)", + "xf86MapVidMem", DEV_MEM, Size, Base, strerror(errno)); + } + return base; + } + + /* else, mmap /dev/vga */ + if ((unsigned long) Base < 0xA0000 || (unsigned long) Base >= 0xC0000) { + FatalError("%s: Address 0x%lx outside allowable range", + "xf86MapVidMem", Base); + } + base = mmap(0, Size, + (flags & VIDMEM_READONLY) ? + PROT_READ : (PROT_READ | PROT_WRITE), + MAP_FLAGS, xf86Info.consoleFd, (unsigned long) Base - 0xA0000); + if (base == MAP_FAILED) { + FatalError("xf86MapVidMem: Could not mmap /dev/vga (%s)", + strerror(errno)); + } + return base; } static void unmapVidMem(int ScreenNum, pointer Base, unsigned long Size) { - munmap((caddr_t)Base, Size); + munmap((caddr_t) Base, Size); } /* @@ -274,47 +261,46 @@ unmapVidMem(int ScreenNum, pointer Base, unsigned long Size) int xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf, - int Len) + int Len) { - unsigned char *ptr; - int psize; - int mlen; - - checkDevMem(TRUE); - if (devMemFd == -1) { - 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, devMemFd, (off_t)Base); - if ((long)ptr == -1) - { - xf86Msg(X_WARNING, - "xf86ReadBIOS: %s mmap[s=%x,a=%lx,o=%lx] failed (%s)\n", - DEV_MEM, Len, Base, Offset, strerror(errno)); + unsigned char *ptr; + int psize; + int mlen; + + checkDevMem(TRUE); + if (devMemFd == -1) { + 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, devMemFd, (off_t) Base); + if ((long) ptr == -1) { + xf86Msg(X_WARNING, + "xf86ReadBIOS: %s mmap[s=%x,a=%lx,o=%lx] failed (%s)\n", + DEV_MEM, Len, Base, Offset, strerror(errno)); #ifdef __OpenBSD__ - if (Base < 0xa0000) { - xf86Msg(X_WARNING, SYSCTL_MSG2); - } + if (Base < 0xa0000) { + xf86Msg(X_WARNING, SYSCTL_MSG2); + } #endif - return -1; - } + return -1; + } #ifdef DEBUG - ErrorF("xf86ReadBIOS: BIOS at 0x%08x has signature 0x%04x\n", - Base, ptr[0] | (ptr[1] << 8)); + ErrorF("xf86ReadBIOS: BIOS at 0x%08x has signature 0x%04x\n", + Base, ptr[0] | (ptr[1] << 8)); #endif - (void)memcpy(Buf, (void *)(ptr + Offset), Len); - (void)munmap((caddr_t)ptr, mlen); + (void) memcpy(Buf, (void *) (ptr + Offset), Len); + (void) munmap((caddr_t) ptr, mlen); #ifdef DEBUG - xf86MsgVerb(X_INFO, 3, "xf86ReadBIOS(%x, %x, Buf, %x)" - "-> %02x %02x %02x %02x...\n", - Base, Offset, Len, Buf[0], Buf[1], Buf[2], Buf[3]); + xf86MsgVerb(X_INFO, 3, "xf86ReadBIOS(%x, %x, Buf, %x)" + "-> %02x %02x %02x %02x...\n", + Base, Offset, Len, Buf[0], Buf[1], Buf[2], Buf[3]); #endif - return Len; + return Len; } #ifdef USE_I386_IOPL @@ -327,38 +313,37 @@ static Bool ExtendedEnabled = FALSE; Bool xf86EnableIO() { - if (ExtendedEnabled) - return TRUE; + if (ExtendedEnabled) + return TRUE; - if (i386_iopl(TRUE) < 0) - { + if (i386_iopl(TRUE) < 0) { #ifndef __OpenBSD__ - xf86Msg(X_WARNING,"%s: Failed to set IOPL for extended I/O", - "xf86EnableIO"); + xf86Msg(X_WARNING, "%s: Failed to set IOPL for extended I/O", + "xf86EnableIO"); #else - xf86Msg(X_WARNING,"%s: Failed to set IOPL for extended I/O\n%s", - "xf86EnableIO", SYSCTL_MSG); + xf86Msg(X_WARNING, "%s: Failed to set IOPL for extended I/O\n%s", + "xf86EnableIO", SYSCTL_MSG); #endif - return FALSE; - } - ExtendedEnabled = TRUE; + return FALSE; + } + ExtendedEnabled = TRUE; - return TRUE; + return TRUE; } - + void xf86DisableIO() { - if (!ExtendedEnabled) - return; + if (!ExtendedEnabled) + return; - i386_iopl(FALSE); - ExtendedEnabled = FALSE; + i386_iopl(FALSE); + ExtendedEnabled = FALSE; - return; + return; } -#endif /* USE_I386_IOPL */ +#endif /* USE_I386_IOPL */ #ifdef USE_AMD64_IOPL /***************************************************************************/ @@ -370,41 +355,40 @@ static Bool ExtendedEnabled = FALSE; Bool xf86EnableIO() { - if (ExtendedEnabled) - return TRUE; + if (ExtendedEnabled) + return TRUE; - if (amd64_iopl(TRUE) < 0) - { + if (amd64_iopl(TRUE) < 0) { #ifndef __OpenBSD__ - xf86Msg(X_WARNING,"%s: Failed to set IOPL for extended I/O", - "xf86EnableIO"); + xf86Msg(X_WARNING, "%s: Failed to set IOPL for extended I/O", + "xf86EnableIO"); #else - xf86Msg(X_WARNING,"%s: Failed to set IOPL for extended I/O\n%s", - "xf86EnableIO", SYSCTL_MSG); + xf86Msg(X_WARNING, "%s: Failed to set IOPL for extended I/O\n%s", + "xf86EnableIO", SYSCTL_MSG); #endif - return FALSE; - } - ExtendedEnabled = TRUE; + return FALSE; + } + ExtendedEnabled = TRUE; - return TRUE; + return TRUE; } - + void xf86DisableIO() { - if (!ExtendedEnabled) - return; - - if (amd64_iopl(FALSE) == 0) { - ExtendedEnabled = FALSE; - } - /* Otherwise, the X server has revoqued its root uid, - and thus cannot give up IO privileges any more */ - - return; + if (!ExtendedEnabled) + return; + + if (amd64_iopl(FALSE) == 0) { + ExtendedEnabled = FALSE; + } + /* Otherwise, the X server has revoqued its root uid, + and thus cannot give up IO privileges any more */ + + return; } -#endif /* USE_AMD64_IOPL */ +#endif /* USE_AMD64_IOPL */ #ifdef USE_DEV_IO static int IoFd = -1; @@ -412,27 +396,26 @@ static int IoFd = -1; Bool xf86EnableIO() { - if (IoFd >= 0) - return TRUE; - - if ((IoFd = open("/dev/io", O_RDWR)) == -1) - { - xf86Msg(X_WARNING,"xf86EnableIO: " - "Failed to open /dev/io for extended I/O"); - return FALSE; - } - return TRUE; + if (IoFd >= 0) + return TRUE; + + if ((IoFd = open("/dev/io", O_RDWR)) == -1) { + xf86Msg(X_WARNING, "xf86EnableIO: " + "Failed to open /dev/io for extended I/O"); + return FALSE; + } + return TRUE; } void xf86DisableIO() { - if (IoFd < 0) - return; + if (IoFd < 0) + return; - close(IoFd); - IoFd = -1; - return; + close(IoFd); + IoFd = -1; + return; } #endif @@ -443,50 +426,46 @@ xf86DisableIO() /***************************************************************************/ void xf86SetTVOut(int mode) -{ - switch (xf86Info.consType) - { +{ + switch (xf86Info.consType) { #ifdef PCCONS_SUPPORT - case PCCONS:{ - - if (ioctl (xf86Info.consoleFd, CONSOLE_X_TV_ON, &mode) < 0) - { - xf86Msg(X_WARNING, - "xf86SetTVOut: Could not set console to TV output, %s\n", - strerror(errno)); - } - } - break; -#endif /* PCCONS_SUPPORT */ - - default: - FatalError("Xf86SetTVOut: Unsupported console"); - break; + case PCCONS:{ + + if (ioctl(xf86Info.consoleFd, CONSOLE_X_TV_ON, &mode) < 0) { + xf86Msg(X_WARNING, + "xf86SetTVOut: Could not set console to TV output, %s\n", + strerror(errno)); + } + } + break; +#endif /* PCCONS_SUPPORT */ + + default: + FatalError("Xf86SetTVOut: Unsupported console"); + break; } return; } void xf86SetRGBOut() -{ - switch (xf86Info.consType) - { +{ + switch (xf86Info.consType) { #ifdef PCCONS_SUPPORT - case PCCONS:{ - - if (ioctl (xf86Info.consoleFd, CONSOLE_X_TV_OFF, 0) < 0) - { - xf86Msg(X_WARNING, - "xf86SetTVOut: Could not set console to RGB output, %s\n", - strerror(errno)); - } - } - break; -#endif /* PCCONS_SUPPORT */ - - default: - FatalError("Xf86SetTVOut: Unsupported console"); - break; + case PCCONS:{ + + if (ioctl(xf86Info.consoleFd, CONSOLE_X_TV_OFF, 0) < 0) { + xf86Msg(X_WARNING, + "xf86SetTVOut: Could not set console to RGB output, %s\n", + strerror(errno)); + } + } + break; +#endif /* PCCONS_SUPPORT */ + + default: + FatalError("Xf86SetTVOut: Unsupported console"); + break; } return; } @@ -507,25 +486,25 @@ xf86SetRGBOut() static struct mem_range_desc * getAllRanges(int *nmr) { - struct mem_range_desc *mrd; - struct mem_range_op mro; - - /* - * Find how many ranges there are. If this fails, then the kernel - * probably doesn't have MTRR support. - */ - mro.mo_arg[0] = 0; - if (ioctl(devMemFd, MEMRANGE_GET, &mro)) - return NULL; - *nmr = mro.mo_arg[0]; - mrd = xnfalloc(*nmr * sizeof(struct mem_range_desc)); - mro.mo_arg[0] = *nmr; - mro.mo_desc = mrd; - if (ioctl(devMemFd, MEMRANGE_GET, &mro)) { - free(mrd); - return NULL; - } - return mrd; + struct mem_range_desc *mrd; + struct mem_range_op mro; + + /* + * Find how many ranges there are. If this fails, then the kernel + * probably doesn't have MTRR support. + */ + mro.mo_arg[0] = 0; + if (ioctl(devMemFd, MEMRANGE_GET, &mro)) + return NULL; + *nmr = mro.mo_arg[0]; + mrd = xnfalloc(*nmr * sizeof(struct mem_range_desc)); + mro.mo_arg[0] = *nmr; + mro.mo_desc = mrd; + if (ioctl(devMemFd, MEMRANGE_GET, &mro)) { + free(mrd); + return NULL; + } + return mrd; } /* @@ -537,109 +516,111 @@ getAllRanges(int *nmr) static Bool cleanMTRR() { - struct mem_range_desc *mrd; - struct mem_range_op mro; - int nmr, i; + struct mem_range_desc *mrd; + struct mem_range_op mro; + int nmr, i; - /* This shouldn't happen */ - if (devMemFd < 0) - return FALSE; + /* This shouldn't happen */ + if (devMemFd < 0) + return FALSE; - if (!(mrd = getAllRanges(&nmr))) - return FALSE; + if (!(mrd = getAllRanges(&nmr))) + return FALSE; - for (i = 0; i < nmr; i++) { - if (strcmp(mrd[i].mr_owner, X_MTRR_ID) == 0 && - (mrd[i].mr_flags & MDF_ACTIVE)) { + for (i = 0; i < nmr; i++) { + if (strcmp(mrd[i].mr_owner, X_MTRR_ID) == 0 && + (mrd[i].mr_flags & MDF_ACTIVE)) { #ifdef DEBUG - ErrorF("Clean for (0x%lx,0x%lx)\n", - (unsigned long)mrd[i].mr_base, - (unsigned long)mrd[i].mr_len); + ErrorF("Clean for (0x%lx,0x%lx)\n", + (unsigned long) mrd[i].mr_base, + (unsigned long) mrd[i].mr_len); #endif - if (mrd[i].mr_flags & MDF_FIXACTIVE) { - mro.mo_arg[0] = MEMRANGE_SET_UPDATE; - mrd[i].mr_flags = MDF_UNCACHEABLE; - } else { - mro.mo_arg[0] = MEMRANGE_SET_REMOVE; - } - mro.mo_desc = mrd + i; - ioctl(devMemFd, MEMRANGE_SET, &mro); - } - } + if (mrd[i].mr_flags & MDF_FIXACTIVE) { + mro.mo_arg[0] = MEMRANGE_SET_UPDATE; + mrd[i].mr_flags = MDF_UNCACHEABLE; + } + else { + mro.mo_arg[0] = MEMRANGE_SET_REMOVE; + } + mro.mo_desc = mrd + i; + ioctl(devMemFd, MEMRANGE_SET, &mro); + } + } #ifdef DEBUG - sleep(10); + sleep(10); #endif - free(mrd); - return TRUE; + free(mrd); + return TRUE; } typedef struct x_RangeRec { - struct mem_range_desc mrd; - Bool wasWC; - struct x_RangeRec * next; + struct mem_range_desc mrd; + Bool wasWC; + struct x_RangeRec *next; } RangeRec, *RangePtr; static void freeRangeList(RangePtr range) { - RangePtr rp; + RangePtr rp; - while (range) { - rp = range; - range = rp->next; - free(rp); - } + while (range) { + rp = range; + range = rp->next; + free(rp); + } } static RangePtr dupRangeList(RangePtr list) { - RangePtr new = NULL, rp, p; - - rp = list; - while (rp) { - p = xnfalloc(sizeof(RangeRec)); - *p = *rp; - p->next = new; - new = p; - rp = rp->next; - } - return new; + RangePtr new = NULL, rp, p; + + rp = list; + while (rp) { + p = xnfalloc(sizeof(RangeRec)); + *p = *rp; + p->next = new; + new = p; + rp = rp->next; + } + return new; } static RangePtr sortRangeList(RangePtr list) { - RangePtr rp1, rp2, copy, sorted = NULL, minp, prev, minprev; - unsigned long minBase; - - /* Sort by base address */ - rp1 = copy = dupRangeList(list); - while (rp1) { - minBase = rp1->mrd.mr_base; - minp = rp1; - minprev = NULL; - prev = rp1; - rp2 = rp1->next; - while (rp2) { - if (rp2->mrd.mr_base < minBase) { - minBase = rp2->mrd.mr_base; - minp = rp2; - minprev = prev; - } - prev = rp2; - rp2 = rp2->next; - } - if (minprev) { - minprev->next = minp->next; - rp1 = copy; - } else { - rp1 = minp->next; - } - minp->next = sorted; - sorted = minp; - } - return sorted; + RangePtr rp1, rp2, copy, sorted = NULL, minp, prev, minprev; + unsigned long minBase; + + /* Sort by base address */ + rp1 = copy = dupRangeList(list); + while (rp1) { + minBase = rp1->mrd.mr_base; + minp = rp1; + minprev = NULL; + prev = rp1; + rp2 = rp1->next; + while (rp2) { + if (rp2->mrd.mr_base < minBase) { + minBase = rp2->mrd.mr_base; + minp = rp2; + minprev = prev; + } + prev = rp2; + rp2 = rp2->next; + } + if (minprev) { + minprev->next = minp->next; + rp1 = copy; + } + else { + rp1 = minp->next; + } + minp->next = sorted; + sorted = minp; + } + return sorted; } /* @@ -647,32 +628,33 @@ sortRangeList(RangePtr list) */ static void -findRanges(unsigned long base, unsigned long size, RangePtr *ucp, RangePtr *wcp) +findRanges(unsigned long base, unsigned long size, RangePtr * ucp, + RangePtr * wcp) { - struct mem_range_desc *mrd; - int nmr, i; - RangePtr rp, *p; - - if (!(mrd = getAllRanges(&nmr))) - return; - - for (i = 0; i < nmr; i++) { - if ((mrd[i].mr_flags & MDF_ACTIVE) && - mrd[i].mr_base < base + size && - mrd[i].mr_base + mrd[i].mr_len > base) { - if (mrd[i].mr_flags & MDF_WRITECOMBINE) - p = wcp; - else if (mrd[i].mr_flags & MDF_UNCACHEABLE) - p = ucp; - else - continue; - rp = xnfalloc(sizeof(RangeRec)); - rp->mrd = mrd[i]; - rp->next = *p; - *p = rp; - } - } - free(mrd); + struct mem_range_desc *mrd; + int nmr, i; + RangePtr rp, *p; + + if (!(mrd = getAllRanges(&nmr))) + return; + + for (i = 0; i < nmr; i++) { + if ((mrd[i].mr_flags & MDF_ACTIVE) && + mrd[i].mr_base < base + size && + mrd[i].mr_base + mrd[i].mr_len > base) { + if (mrd[i].mr_flags & MDF_WRITECOMBINE) + p = wcp; + else if (mrd[i].mr_flags & MDF_UNCACHEABLE) + p = ucp; + else + continue; + rp = xnfalloc(sizeof(RangeRec)); + rp->mrd = mrd[i]; + rp->next = *p; + *p = rp; + } + } + free(mrd); } /* @@ -683,219 +665,222 @@ findRanges(unsigned long base, unsigned long size, RangePtr *ucp, RangePtr *wcp) static Bool fullCoverage(unsigned long base, unsigned long size, RangePtr overlap) { - RangePtr rp1, sorted = NULL; - unsigned long end; - - sorted = sortRangeList(overlap); - /* Look for gaps */ - rp1 = sorted; - end = base + size; - while (rp1) { - if (rp1->mrd.mr_base > base) { - freeRangeList(sorted); - return FALSE; - } else { - base = rp1->mrd.mr_base + rp1->mrd.mr_len; - } - if (base >= end) { - freeRangeList(sorted); - return TRUE; - } - rp1 = rp1->next; - } - freeRangeList(sorted); - return FALSE; + RangePtr rp1, sorted = NULL; + unsigned long end; + + sorted = sortRangeList(overlap); + /* Look for gaps */ + rp1 = sorted; + end = base + size; + while (rp1) { + if (rp1->mrd.mr_base > base) { + freeRangeList(sorted); + return FALSE; + } + else { + base = rp1->mrd.mr_base + rp1->mrd.mr_len; + } + if (base >= end) { + freeRangeList(sorted); + return TRUE; + } + rp1 = rp1->next; + } + freeRangeList(sorted); + return FALSE; } static pointer addWC(int screenNum, unsigned long base, unsigned long size, MessageType from) { - RangePtr uc = NULL, wc = NULL, retlist = NULL; - struct mem_range_desc mrd; - struct mem_range_op mro; - - findRanges(base, size, &uc, &wc); - - /* See of the full range is already WC */ - if (!uc && fullCoverage(base, size, wc)) { - xf86DrvMsg(screenNum, from, - "Write-combining range (0x%lx,0x%lx) was already set\n", - base, size); - return NULL; - } - - /* Otherwise, try to add the new range */ - mrd.mr_base = base; - mrd.mr_len = size; - strcpy(mrd.mr_owner, X_MTRR_ID); - mrd.mr_flags = MDF_WRITECOMBINE; - mro.mo_desc = &mrd; - mro.mo_arg[0] = MEMRANGE_SET_UPDATE; - if (ioctl(devMemFd, MEMRANGE_SET, &mro)) { - xf86DrvMsg(screenNum, X_WARNING, - "Failed to set write-combining range " - "(0x%lx,0x%lx)\n", base, size); - return NULL; - } else { - xf86DrvMsg(screenNum, from, - "Write-combining range (0x%lx,0x%lx)\n", base, size); - retlist = xnfalloc(sizeof(RangeRec)); - retlist->mrd = mrd; - retlist->wasWC = FALSE; - retlist->next = NULL; - return retlist; - } + RangePtr uc = NULL, wc = NULL, retlist = NULL; + struct mem_range_desc mrd; + struct mem_range_op mro; + + findRanges(base, size, &uc, &wc); + + /* See of the full range is already WC */ + if (!uc && fullCoverage(base, size, wc)) { + xf86DrvMsg(screenNum, from, + "Write-combining range (0x%lx,0x%lx) was already set\n", + base, size); + return NULL; + } + + /* Otherwise, try to add the new range */ + mrd.mr_base = base; + mrd.mr_len = size; + strcpy(mrd.mr_owner, X_MTRR_ID); + mrd.mr_flags = MDF_WRITECOMBINE; + mro.mo_desc = &mrd; + mro.mo_arg[0] = MEMRANGE_SET_UPDATE; + if (ioctl(devMemFd, MEMRANGE_SET, &mro)) { + xf86DrvMsg(screenNum, X_WARNING, + "Failed to set write-combining range " + "(0x%lx,0x%lx)\n", base, size); + return NULL; + } + else { + xf86DrvMsg(screenNum, from, + "Write-combining range (0x%lx,0x%lx)\n", base, size); + retlist = xnfalloc(sizeof(RangeRec)); + retlist->mrd = mrd; + retlist->wasWC = FALSE; + retlist->next = NULL; + return retlist; + } } static pointer delWC(int screenNum, unsigned long base, unsigned long size, MessageType from) { - RangePtr uc = NULL, wc = NULL, retlist = NULL; - struct mem_range_desc mrd; - struct mem_range_op mro; - - findRanges(base, size, &uc, &wc); - - /* - * See of the full range is already not WC, or if there is full - * coverage from UC ranges. - */ - if (!wc || fullCoverage(base, size, uc)) { - xf86DrvMsg(screenNum, from, - "Write-combining range (0x%lx,0x%lx) was already clear\n", - base, size); - return NULL; - } - - /* Otherwise, try to add the new range */ - mrd.mr_base = base; - mrd.mr_len = size; - strcpy(mrd.mr_owner, X_MTRR_ID); - mrd.mr_flags = MDF_UNCACHEABLE; - mro.mo_desc = &mrd; - mro.mo_arg[0] = MEMRANGE_SET_UPDATE; - if (ioctl(devMemFd, MEMRANGE_SET, &mro)) { - xf86DrvMsg(screenNum, X_WARNING, - "Failed to remove write-combining range " - "(0x%lx,0x%lx)\n", base, size); - /* XXX Should then remove all of the overlapping WC ranges */ - return NULL; - } else { - xf86DrvMsg(screenNum, from, - "Removed Write-combining range (0x%lx,0x%lx)\n", - base, size); - retlist = xnfalloc(sizeof(RangeRec)); - retlist->mrd = mrd; - retlist->wasWC = TRUE; - retlist->next = NULL; - return retlist; - } + RangePtr uc = NULL, wc = NULL, retlist = NULL; + struct mem_range_desc mrd; + struct mem_range_op mro; + + findRanges(base, size, &uc, &wc); + + /* + * See of the full range is already not WC, or if there is full + * coverage from UC ranges. + */ + if (!wc || fullCoverage(base, size, uc)) { + xf86DrvMsg(screenNum, from, + "Write-combining range (0x%lx,0x%lx) was already clear\n", + base, size); + return NULL; + } + + /* Otherwise, try to add the new range */ + mrd.mr_base = base; + mrd.mr_len = size; + strcpy(mrd.mr_owner, X_MTRR_ID); + mrd.mr_flags = MDF_UNCACHEABLE; + mro.mo_desc = &mrd; + mro.mo_arg[0] = MEMRANGE_SET_UPDATE; + if (ioctl(devMemFd, MEMRANGE_SET, &mro)) { + xf86DrvMsg(screenNum, X_WARNING, + "Failed to remove write-combining range " + "(0x%lx,0x%lx)\n", base, size); + /* XXX Should then remove all of the overlapping WC ranges */ + return NULL; + } + else { + xf86DrvMsg(screenNum, from, + "Removed Write-combining range (0x%lx,0x%lx)\n", base, size); + retlist = xnfalloc(sizeof(RangeRec)); + retlist->mrd = mrd; + retlist->wasWC = TRUE; + retlist->next = NULL; + return retlist; + } } static pointer setWC(int screenNum, unsigned long base, unsigned long size, Bool enable, - MessageType from) + MessageType from) { - if (enable) - return addWC(screenNum, base, size, from); - else - return delWC(screenNum, base, size, from); + if (enable) + return addWC(screenNum, base, size, from); + else + return delWC(screenNum, base, size, from); } static void undoWC(int screenNum, pointer list) { - RangePtr rp; - struct mem_range_op mro; - Bool failed; + RangePtr rp; + struct mem_range_op mro; + Bool failed; - rp = list; - while (rp) { + rp = list; + while (rp) { #ifdef DEBUG - ErrorF("Undo for (0x%lx,0x%lx), %d\n", - (unsigned long)rp->mrd.mr_base, - (unsigned long)rp->mrd.mr_len, rp->wasWC); + ErrorF("Undo for (0x%lx,0x%lx), %d\n", + (unsigned long) rp->mrd.mr_base, + (unsigned long) rp->mrd.mr_len, rp->wasWC); #endif - failed = FALSE; - if (rp->wasWC) { - mro.mo_arg[0] = MEMRANGE_SET_UPDATE; - rp->mrd.mr_flags = MDF_WRITECOMBINE; - strcpy(rp->mrd.mr_owner, "unknown"); - } else { - mro.mo_arg[0] = MEMRANGE_SET_REMOVE; - } - mro.mo_desc = &rp->mrd; - - if (ioctl(devMemFd, MEMRANGE_SET, &mro)) { - if (!rp->wasWC) { - mro.mo_arg[0] = MEMRANGE_SET_UPDATE; - rp->mrd.mr_flags = MDF_UNCACHEABLE; - strcpy(rp->mrd.mr_owner, "unknown"); - if (ioctl(devMemFd, MEMRANGE_SET, &mro)) - failed = TRUE; - } else - failed = TRUE; - } - if (failed) { - xf86DrvMsg(screenNum, X_WARNING, - "Failed to restore MTRR range (0x%lx,0x%lx)\n", - (unsigned long)rp->mrd.mr_base, - (unsigned long)rp->mrd.mr_len); - } - rp = rp->next; - } + failed = FALSE; + if (rp->wasWC) { + mro.mo_arg[0] = MEMRANGE_SET_UPDATE; + rp->mrd.mr_flags = MDF_WRITECOMBINE; + strcpy(rp->mrd.mr_owner, "unknown"); + } + else { + mro.mo_arg[0] = MEMRANGE_SET_REMOVE; + } + mro.mo_desc = &rp->mrd; + + if (ioctl(devMemFd, MEMRANGE_SET, &mro)) { + if (!rp->wasWC) { + mro.mo_arg[0] = MEMRANGE_SET_UPDATE; + rp->mrd.mr_flags = MDF_UNCACHEABLE; + strcpy(rp->mrd.mr_owner, "unknown"); + if (ioctl(devMemFd, MEMRANGE_SET, &mro)) + failed = TRUE; + } + else + failed = TRUE; + } + if (failed) { + xf86DrvMsg(screenNum, X_WARNING, + "Failed to restore MTRR range (0x%lx,0x%lx)\n", + (unsigned long) rp->mrd.mr_base, + (unsigned long) rp->mrd.mr_len); + } + rp = rp->next; + } } -#endif /* HAS_MTRR_SUPPORT */ - +#endif /* HAS_MTRR_SUPPORT */ #if defined(HAS_MTRR_BUILTIN) && defined(__NetBSD__) static pointer NetBSDsetWC(int screenNum, unsigned long base, unsigned long size, Bool enable, - MessageType from) + MessageType from) { - struct mtrr *mtrrp; - int n; - - xf86DrvMsg(screenNum, X_WARNING, - "%s MTRR %lx - %lx\n", enable ? "set" : "remove", - base, (base + size)); - - mtrrp = xnfalloc(sizeof (struct mtrr)); - mtrrp->base = base; - mtrrp->len = size; - mtrrp->type = MTRR_TYPE_WC; - - /* - * MTRR_PRIVATE will make this MTRR get reset automatically - * if this process exits, so we have no need for an explicit - * cleanup operation when starting a new server. - */ - - if (enable) - mtrrp->flags = MTRR_VALID | MTRR_PRIVATE; - else - mtrrp->flags = 0; - n = 1; - - if (i386_set_mtrr(mtrrp, &n) < 0) { - free(mtrrp); - return NULL; - } - return mtrrp; + struct mtrr *mtrrp; + int n; + + xf86DrvMsg(screenNum, X_WARNING, + "%s MTRR %lx - %lx\n", enable ? "set" : "remove", + base, (base + size)); + + mtrrp = xnfalloc(sizeof(struct mtrr)); + mtrrp->base = base; + mtrrp->len = size; + mtrrp->type = MTRR_TYPE_WC; + + /* + * MTRR_PRIVATE will make this MTRR get reset automatically + * if this process exits, so we have no need for an explicit + * cleanup operation when starting a new server. + */ + + if (enable) + mtrrp->flags = MTRR_VALID | MTRR_PRIVATE; + else + mtrrp->flags = 0; + n = 1; + + if (i386_set_mtrr(mtrrp, &n) < 0) { + free(mtrrp); + return NULL; + } + return mtrrp; } static void NetBSDundoWC(int screenNum, pointer list) { - struct mtrr *mtrrp = (struct mtrr *)list; - int n; - - if (mtrrp == NULL) - return; - n = 1; - mtrrp->flags &= ~MTRR_VALID; - i386_set_mtrr(mtrrp, &n); - free(mtrrp); + struct mtrr *mtrrp = (struct mtrr *) list; + int n; + + if (mtrrp == NULL) + return; + n = 1; + mtrrp->flags &= ~MTRR_VALID; + i386_set_mtrr(mtrrp, &n); + free(mtrrp); } #endif diff --git a/xorg-server/hw/xfree86/os-support/bsd/memrange.h b/xorg-server/hw/xfree86/os-support/bsd/memrange.h index 03c479144..bacd4aa0d 100644 --- a/xorg-server/hw/xfree86/os-support/bsd/memrange.h +++ b/xorg-server/hw/xfree86/os-support/bsd/memrange.h @@ -10,36 +10,37 @@ #define _MEMRANGE_H /* Memory range attributes */ -#define MDF_UNCACHEABLE (1<<0) /* region not cached */ -#define MDF_WRITECOMBINE (1<<1) /* region supports "write combine" - * action */ -#define MDF_WRITETHROUGH (1<<2) /* write-through cached */ -#define MDF_WRITEBACK (1<<3) /* write-back cached */ -#define MDF_WRITEPROTECT (1<<4) /* read-only region */ +#define MDF_UNCACHEABLE (1<<0) /* region not cached */ +#define MDF_WRITECOMBINE (1<<1) /* region supports "write combine" + * action */ +#define MDF_WRITETHROUGH (1<<2) /* write-through cached */ +#define MDF_WRITEBACK (1<<3) /* write-back cached */ +#define MDF_WRITEPROTECT (1<<4) /* read-only region */ #define MDF_ATTRMASK (0x00ffffff) -#define MDF_FIXBASE (1<<24) /* fixed base */ -#define MDF_FIXLEN (1<<25) /* fixed length */ -#define MDF_FIRMWARE (1<<26) /* set by firmware (XXX not useful?) */ -#define MDF_ACTIVE (1<<27) /* currently active */ -#define MDF_BOGUS (1<<28) /* we don't like it */ -#define MDF_FIXACTIVE (1<<29) /* can't be turned off */ -#define MDF_BUSY (1<<30) /* range is in use */ +#define MDF_FIXBASE (1<<24) /* fixed base */ +#define MDF_FIXLEN (1<<25) /* fixed length */ +#define MDF_FIRMWARE (1<<26) /* set by firmware (XXX not useful?) */ +#define MDF_ACTIVE (1<<27) /* currently active */ +#define MDF_BOGUS (1<<28) /* we don't like it */ +#define MDF_FIXACTIVE (1<<29) /* can't be turned off */ +#define MDF_BUSY (1<<30) /* range is in use */ struct mem_range_desc { - u_int64_t mr_base; - u_int64_t mr_len; - int mr_flags; - char mr_owner[8]; + u_int64_t mr_base; + u_int64_t mr_len; + int mr_flags; + char mr_owner[8]; }; struct mem_range_op { - struct mem_range_desc *mo_desc; - int mo_arg[2]; + struct mem_range_desc *mo_desc; + int mo_arg[2]; #define MEMRANGE_SET_UPDATE 0 #define MEMRANGE_SET_REMOVE 1 - /* XXX want a flag that says "set and undo when I exit" */ + /* XXX want a flag that says "set and undo when I exit" */ }; + #define MEMRANGE_GET _IOWR('m', 50, struct mem_range_op) #define MEMRANGE_SET _IOW('m', 51, struct mem_range_op) @@ -47,16 +48,18 @@ struct mem_range_op { struct mem_range_softc; struct mem_range_ops { - void (*init) __P((struct mem_range_softc * sc)); - int (*set) __P((struct mem_range_softc * sc, struct mem_range_desc * mrd, int *arg)); - void (*initAP) __P((struct mem_range_softc * sc)); + void (*init) __P((struct mem_range_softc * sc)); + int (*set) + __P((struct mem_range_softc * sc, struct mem_range_desc * mrd, + int *arg)); + void (*initAP) __P((struct mem_range_softc * sc)); }; struct mem_range_softc { - struct mem_range_ops *mr_op; - int mr_cap; - int mr_ndesc; - struct mem_range_desc *mr_desc; + struct mem_range_ops *mr_op; + int mr_cap; + int mr_ndesc; + struct mem_range_desc *mr_desc; }; extern struct mem_range_softc mem_range_softc; diff --git a/xorg-server/hw/xfree86/os-support/bsd/ppc_video.c b/xorg-server/hw/xfree86/os-support/bsd/ppc_video.c index e5d832eed..417adbf4b 100644 --- a/xorg-server/hw/xfree86/os-support/bsd/ppc_video.c +++ b/xorg-server/hw/xfree86/os-support/bsd/ppc_video.c @@ -53,94 +53,89 @@ void xf86DisableIO(void); void xf86OSInitVidMem(VidMemInfoPtr pVidMem) { - pVidMem->linearSupported = TRUE; - pVidMem->mapMem = ppcMapVidMem; - pVidMem->unmapMem = ppcUnmapVidMem; - pVidMem->initialised = TRUE; - xf86EnableIO(); + pVidMem->linearSupported = TRUE; + pVidMem->mapMem = ppcMapVidMem; + pVidMem->unmapMem = ppcUnmapVidMem; + pVidMem->initialised = TRUE; + xf86EnableIO(); } - volatile unsigned char *ioBase = MAP_FAILED; static pointer ppcMapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags) { - int fd = xf86Info.consoleFd; - pointer base; + int fd = xf86Info.consoleFd; + pointer base; + #ifdef DEBUG - xf86MsgVerb(X_INFO, 3, "mapVidMem %lx, %lx, fd = %d", - Base, Size, fd); + xf86MsgVerb(X_INFO, 3, "mapVidMem %lx, %lx, fd = %d", Base, Size, fd); #endif - base = mmap(0, Size, - (flags & VIDMEM_READONLY) ? - PROT_READ : (PROT_READ | PROT_WRITE), - MAP_SHARED, fd, Base); - if (base == MAP_FAILED) - FatalError("%s: could not mmap screen [s=%x,a=%x] (%s)", - "xf86MapVidMem", Size, Base, strerror(errno)); + base = mmap(0, Size, + (flags & VIDMEM_READONLY) ? + PROT_READ : (PROT_READ | PROT_WRITE), MAP_SHARED, fd, Base); + if (base == MAP_FAILED) + FatalError("%s: could not mmap screen [s=%x,a=%x] (%s)", + "xf86MapVidMem", Size, Base, strerror(errno)); - return base; + return base; } static void ppcUnmapVidMem(int ScreenNum, pointer Base, unsigned long Size) { - munmap(Base, Size); + munmap(Base, Size); } int xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf, - int Len) + int Len) { - int rv; - static int kmem = -1; + int rv; + static int kmem = -1; - if (kmem == -1) { - kmem = open(DEV_MEM, 2); - if (kmem == -1) { - FatalError("xf86ReadBIOS: open %s", DEV_MEM); - } - } + if (kmem == -1) { + kmem = open(DEV_MEM, 2); + if (kmem == -1) { + FatalError("xf86ReadBIOS: open %s", DEV_MEM); + } + } #ifdef DEBUG - xf86MsgVerb(X_INFO, 3, "xf86ReadBIOS() %lx %lx, %x\n", - Base, Offset, Len); + xf86MsgVerb(X_INFO, 3, "xf86ReadBIOS() %lx %lx, %x\n", Base, Offset, Len); #endif + lseek(kmem, Base + Offset, 0); + rv = read(kmem, Buf, Len); - lseek(kmem, Base + Offset, 0); - rv = read(kmem, Buf, Len); - - return rv; + return rv; } -Bool xf86EnableIO() +Bool +xf86EnableIO() { - int fd = xf86Info.consoleFd; - - xf86MsgVerb(X_WARNING, 3, "xf86EnableIO %d\n", fd); - if (ioBase == MAP_FAILED) - { - ioBase=mmap(NULL, 0x10000, PROT_READ|PROT_WRITE, MAP_SHARED, fd, - 0xf2000000); - xf86MsgVerb(X_INFO, 3, "xf86EnableIO: %08x\n", ioBase); - if (ioBase == MAP_FAILED) { - xf86MsgVerb(X_WARNING, 3, "Can't map IO space!\n"); - return FALSE; - } + int fd = xf86Info.consoleFd; + + xf86MsgVerb(X_WARNING, 3, "xf86EnableIO %d\n", fd); + if (ioBase == MAP_FAILED) { + ioBase = mmap(NULL, 0x10000, PROT_READ | PROT_WRITE, MAP_SHARED, fd, + 0xf2000000); + xf86MsgVerb(X_INFO, 3, "xf86EnableIO: %08x\n", ioBase); + if (ioBase == MAP_FAILED) { + xf86MsgVerb(X_WARNING, 3, "Can't map IO space!\n"); + return FALSE; } - return TRUE; + } + return TRUE; } -void xf86DisableIO() +void +xf86DisableIO() { - if (ioBase != MAP_FAILED) - { - munmap(__UNVOLATILE(ioBase), 0x10000); - ioBase = MAP_FAILED; - } + if (ioBase != MAP_FAILED) { + munmap(__UNVOLATILE(ioBase), 0x10000); + ioBase = MAP_FAILED; + } } - diff --git a/xorg-server/hw/xfree86/os-support/bsd/sparc64_video.c b/xorg-server/hw/xfree86/os-support/bsd/sparc64_video.c index 960c850a8..21c166105 100644 --- a/xorg-server/hw/xfree86/os-support/bsd/sparc64_video.c +++ b/xorg-server/hw/xfree86/os-support/bsd/sparc64_video.c @@ -44,44 +44,42 @@ static void sparc64UnmapVidMem(int, pointer, unsigned long); void xf86OSInitVidMem(VidMemInfoPtr pVidMem) { - pVidMem->linearSupported = TRUE; - pVidMem->mapMem = sparc64MapVidMem; - pVidMem->unmapMem = sparc64UnmapVidMem; - pVidMem->initialised = TRUE; + pVidMem->linearSupported = TRUE; + pVidMem->mapMem = sparc64MapVidMem; + pVidMem->unmapMem = sparc64UnmapVidMem; + pVidMem->initialised = TRUE; } static pointer -sparc64MapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, - int flags) +sparc64MapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, + int flags) { - int fd = xf86Info.consoleFd; - pointer base; + int fd = xf86Info.consoleFd; + pointer base; #ifdef DEBUG - xf86MsgVerb(X_INFO, 3, "mapVidMem %lx, %lx, fd = %d", - Base, Size, fd); + xf86MsgVerb(X_INFO, 3, "mapVidMem %lx, %lx, fd = %d", Base, Size, fd); #endif - base = mmap(0, Size, - (flags & VIDMEM_READONLY) ? - PROT_READ : (PROT_READ | PROT_WRITE), - MAP_SHARED, fd, Base); - if (base == MAP_FAILED) - FatalError("%s: could not mmap screen [s=%x,a=%x] (%s)", - "xf86MapVidMem", Size, Base, strerror(errno)); - return base; + base = mmap(0, Size, + (flags & VIDMEM_READONLY) ? + PROT_READ : (PROT_READ | PROT_WRITE), MAP_SHARED, fd, Base); + if (base == MAP_FAILED) + FatalError("%s: could not mmap screen [s=%x,a=%x] (%s)", + "xf86MapVidMem", Size, Base, strerror(errno)); + return base; } static void sparc64UnmapVidMem(int ScreenNum, pointer Base, unsigned long Size) { - munmap(Base, Size); + munmap(Base, Size); } int xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf, - int Len) + int Len) { - return 0; + return 0; } diff --git a/xorg-server/hw/xfree86/os-support/bus/Sbus.c b/xorg-server/hw/xfree86/os-support/bus/Sbus.c index c02d2cd55..b75308aa1 100644 --- a/xorg-server/hw/xfree86/os-support/bus/Sbus.c +++ b/xorg-server/hw/xfree86/os-support/bus/Sbus.c @@ -47,6 +47,7 @@ static int promFd = -1; static int promCurrentNode; static int promOpenCount = 0; static int promP1275 = -1; + #define MAX_PROP 128 #define MAX_VAL (4096-128-4) static struct openpromio *promOpio; @@ -54,21 +55,23 @@ static struct openpromio *promOpio; sbusDevicePtr *xf86SbusInfo = NULL; struct sbus_devtable sbusDeviceTable[] = { - { SBUS_DEVICE_BW2, FBTYPE_SUN2BW, "bwtwo", "sunbw2", "Sun Monochrome (bwtwo)" }, - { SBUS_DEVICE_CG2, FBTYPE_SUN2COLOR, "cgtwo", NULL, "Sun Color2 (cgtwo)" }, - { SBUS_DEVICE_CG3, FBTYPE_SUN3COLOR, "cgthree", "suncg3", "Sun Color3 (cgthree)" }, - { SBUS_DEVICE_CG4, FBTYPE_SUN4COLOR, "cgfour", NULL, "Sun Color4 (cgfour)" }, - { SBUS_DEVICE_CG6, FBTYPE_SUNFAST_COLOR, "cgsix", "suncg6", "Sun GX" }, - { SBUS_DEVICE_CG8, FBTYPE_MEMCOLOR, "cgeight", NULL, "Sun CG8/RasterOps" }, - { SBUS_DEVICE_CG12, FBTYPE_SUNGP3, "cgtwelve", NULL, "Sun GS (cgtwelve)" }, - { SBUS_DEVICE_CG14, FBTYPE_MDICOLOR, "cgfourteen", "suncg14", "Sun SX" }, - { SBUS_DEVICE_GT, FBTYPE_SUNGT, "gt", NULL, "Sun Graphics Tower" }, - { SBUS_DEVICE_MGX, -1, "mgx", NULL, "Quantum 3D MGXplus" }, - { SBUS_DEVICE_LEO, FBTYPE_SUNLEO, "leo", "sunleo", "Sun ZX or Turbo ZX" }, - { SBUS_DEVICE_TCX, FBTYPE_TCXCOLOR, "tcx", "suntcx", "Sun TCX" }, - { SBUS_DEVICE_FFB, FBTYPE_CREATOR, "ffb", "sunffb", "Sun FFB" }, - { SBUS_DEVICE_FFB, FBTYPE_CREATOR, "afb", "sunffb", "Sun Elite3D" }, - { 0, 0, NULL } + {SBUS_DEVICE_BW2, FBTYPE_SUN2BW, "bwtwo", "sunbw2", + "Sun Monochrome (bwtwo)"}, + {SBUS_DEVICE_CG2, FBTYPE_SUN2COLOR, "cgtwo", NULL, "Sun Color2 (cgtwo)"}, + {SBUS_DEVICE_CG3, FBTYPE_SUN3COLOR, "cgthree", "suncg3", + "Sun Color3 (cgthree)"}, + {SBUS_DEVICE_CG4, FBTYPE_SUN4COLOR, "cgfour", NULL, "Sun Color4 (cgfour)"}, + {SBUS_DEVICE_CG6, FBTYPE_SUNFAST_COLOR, "cgsix", "suncg6", "Sun GX"}, + {SBUS_DEVICE_CG8, FBTYPE_MEMCOLOR, "cgeight", NULL, "Sun CG8/RasterOps"}, + {SBUS_DEVICE_CG12, FBTYPE_SUNGP3, "cgtwelve", NULL, "Sun GS (cgtwelve)"}, + {SBUS_DEVICE_CG14, FBTYPE_MDICOLOR, "cgfourteen", "suncg14", "Sun SX"}, + {SBUS_DEVICE_GT, FBTYPE_SUNGT, "gt", NULL, "Sun Graphics Tower"}, + {SBUS_DEVICE_MGX, -1, "mgx", NULL, "Quantum 3D MGXplus"}, + {SBUS_DEVICE_LEO, FBTYPE_SUNLEO, "leo", "sunleo", "Sun ZX or Turbo ZX"}, + {SBUS_DEVICE_TCX, FBTYPE_TCXCOLOR, "tcx", "suntcx", "Sun TCX"}, + {SBUS_DEVICE_FFB, FBTYPE_CREATOR, "ffb", "sunffb", "Sun FFB"}, + {SBUS_DEVICE_FFB, FBTYPE_CREATOR, "afb", "sunffb", "Sun Elite3D"}, + {0, 0, NULL} }; int @@ -76,12 +79,13 @@ promGetSibling(int node) { promOpio->oprom_size = sizeof(int); - if (node == -1) return 0; - *(int *)promOpio->oprom_array = node; + if (node == -1) + return 0; + *(int *) promOpio->oprom_array = node; if (ioctl(promFd, OPROMNEXT, promOpio) < 0) - return 0; - promCurrentNode = *(int *)promOpio->oprom_array; - return *(int *)promOpio->oprom_array; + return 0; + promCurrentNode = *(int *) promOpio->oprom_array; + return *(int *) promOpio->oprom_array; } int @@ -89,12 +93,13 @@ promGetChild(int node) { promOpio->oprom_size = sizeof(int); - if (!node || node == -1) return 0; - *(int *)promOpio->oprom_array = node; + if (!node || node == -1) + return 0; + *(int *) promOpio->oprom_array = node; if (ioctl(promFd, OPROMCHILD, promOpio) < 0) - return 0; - promCurrentNode = *(int *)promOpio->oprom_array; - return *(int *)promOpio->oprom_array; + return 0; + promCurrentNode = *(int *) promOpio->oprom_array; + return *(int *) promOpio->oprom_array; } char * @@ -104,8 +109,9 @@ promGetProperty(const char *prop, int *lenp) strcpy(promOpio->oprom_array, prop); if (ioctl(promFd, OPROMGETPROP, promOpio) < 0) - return 0; - if (lenp) *lenp = promOpio->oprom_size; + return 0; + if (lenp) + *lenp = promOpio->oprom_size; return promOpio->oprom_array; } @@ -114,15 +120,15 @@ promGetBool(const char *prop) { promOpio->oprom_size = 0; - *(int *)promOpio->oprom_array = 0; + *(int *) promOpio->oprom_array = 0; for (;;) { - promOpio->oprom_size = MAX_PROP; - if (ioctl(promFd, OPROMNXTPROP, promOpio) < 0) - return 0; - if (!promOpio->oprom_size) - return 0; - if (!strcmp(promOpio->oprom_array, prop)) - return 1; + promOpio->oprom_size = MAX_PROP; + if (ioctl(promFd, OPROMNXTPROP, promOpio) < 0) + return 0; + if (!promOpio->oprom_size) + return 0; + if (!strcmp(promOpio->oprom_array, prop)) + return 1; } } @@ -138,13 +144,13 @@ promSetNode(sbusPromNodePtr pnode) int node; if (!pnode->node || pnode->node == -1) - return -1; + return -1; if (pnode->cookie[0] & PROM_NODE_SIBLING) - node = promGetSibling(pnode->cookie[1]); + node = promGetSibling(pnode->cookie[1]); else - node = promGetChild(pnode->cookie[1]); + node = promGetChild(pnode->cookie[1]); if (pnode->node != node) - return -1; + return -1; return 0; } @@ -156,23 +162,24 @@ promIsP1275(void) char buffer[1024]; if (promP1275 != -1) - return; + return; promP1275 = 0; - f = fopen("/proc/cpuinfo","r"); - if (!f) return; + f = fopen("/proc/cpuinfo", "r"); + if (!f) + return; while (fgets(buffer, 1024, f) != NULL) - if (!strncmp (buffer, "type", 4) && strstr (buffer, "sun4u")) { - promP1275 = 1; - break; - } + if (!strncmp(buffer, "type", 4) && strstr(buffer, "sun4u")) { + promP1275 = 1; + break; + } fclose(f); #elif defined(sun) struct utsname buffer; if ((uname(&buffer) >= 0) && !strcmp(buffer.machine, "sun4u")) - promP1275 = TRUE; + promP1275 = TRUE; else - promP1275 = FALSE; + promP1275 = FALSE; #elif defined(__FreeBSD__) promP1275 = TRUE; #else @@ -184,12 +191,12 @@ void sparcPromClose(void) { if (promOpenCount > 1) { - promOpenCount--; - return; + promOpenCount--; + return; } if (promFd != -1) { - close(promFd); - promFd = -1; + close(promFd); + promFd = -1; } free(promOpio); promOpio = NULL; @@ -200,21 +207,21 @@ int sparcPromInit(void) { if (promOpenCount) { - promOpenCount++; - return 0; + promOpenCount++; + return 0; } promFd = open("/dev/openprom", O_RDONLY, 0); if (promFd == -1) - return -1; - promOpio = (struct openpromio *)malloc(4096); + return -1; + promOpio = (struct openpromio *) malloc(4096); if (!promOpio) { - sparcPromClose(); - return -1; + sparcPromClose(); + return -1; } promRootNode = promGetSibling(0); if (!promRootNode) { - sparcPromClose(); - return -1; + sparcPromClose(); + return -1; } promIsP1275(); promOpenCount++; @@ -226,7 +233,7 @@ char * sparcPromGetProperty(sbusPromNodePtr pnode, const char *prop, int *lenp) { if (promSetNode(pnode)) - return NULL; + return NULL; return promGetProperty(prop, lenp); } @@ -234,7 +241,7 @@ int sparcPromGetBool(sbusPromNodePtr pnode, const char *prop) { if (promSetNode(pnode)) - return 0; + return 0; return promGetBool(prop); } @@ -247,35 +254,37 @@ promWalkGetDriverName(int node, int oldnode) int devId, i; prop = promGetProperty("device_type", &len); - if (prop && (len > 0)) do { - if (!strcmp(prop, "display")) { - prop = promGetProperty("name", &len); - if (!prop || len <= 0) - break; - while ((*prop >= 'A' && *prop <= 'Z') || *prop == ',') - prop++; - for (i = 0; sbusDeviceTable[i].devId; i++) - if (!strcmp(prop, sbusDeviceTable[i].promName)) - break; - devId = sbusDeviceTable[i].devId; - if (!devId) - break; - if (sbusDeviceTable[i].driverName) - return sbusDeviceTable[i].driverName; - } - } while (0); + if (prop && (len > 0)) + do { + if (!strcmp(prop, "display")) { + prop = promGetProperty("name", &len); + if (!prop || len <= 0) + break; + while ((*prop >= 'A' && *prop <= 'Z') || *prop == ',') + prop++; + for (i = 0; sbusDeviceTable[i].devId; i++) + if (!strcmp(prop, sbusDeviceTable[i].promName)) + break; + devId = sbusDeviceTable[i].devId; + if (!devId) + break; + if (sbusDeviceTable[i].driverName) + return sbusDeviceTable[i].driverName; + } + } while (0); nextnode = promGetChild(node); if (nextnode) { - char *name; - name = promWalkGetDriverName(nextnode, node); - if (name) - return name; + char *name; + + name = promWalkGetDriverName(nextnode, node); + if (name) + return name; } nextnode = promGetSibling(node); if (nextnode) - return promWalkGetDriverName(nextnode, node); + return promWalkGetDriverName(nextnode, node); return NULL; } @@ -285,7 +294,7 @@ sparcDriverName(void) char *name; if (sparcPromInit() < 0) - return NULL; + return NULL; promGetSibling(0); name = promWalkGetDriverName(promRootNode, 0); sparcPromClose(); @@ -293,7 +302,8 @@ sparcDriverName(void) } static void -promWalkAssignNodes(int node, int oldnode, int flags, sbusDevicePtr *devicePtrs) +promWalkAssignNodes(int node, int oldnode, int flags, + sbusDevicePtr * devicePtrs) { int nextnode; int len, sbus = flags & PROM_NODE_SBUS; @@ -302,67 +312,72 @@ promWalkAssignNodes(int node, int oldnode, int flags, sbusDevicePtr *devicePtrs) sbusPromNode pNode, pNode2; prop = promGetProperty("device_type", &len); - if (prop && (len > 0)) do { - if (!strcmp(prop, "display")) { - prop = promGetProperty("name", &len); - if (!prop || len <= 0) - break; - while ((*prop >= 'A' && *prop <= 'Z') || *prop == ',') - prop++; - for (i = 0; sbusDeviceTable[i].devId; i++) - if (!strcmp(prop, sbusDeviceTable[i].promName)) - break; - devId = sbusDeviceTable[i].devId; - if (!devId) - break; - if (!sbus) { - if (devId == SBUS_DEVICE_FFB) { - /* - * All /SUNW,ffb outside of SBUS tree come before all - * /SUNW,afb outside of SBUS tree in Linux. - */ - if (!strcmp(prop, "afb")) - flags |= PROM_NODE_PREF; - } else if (devId != SBUS_DEVICE_CG14) - break; - } - for (i = 0; i < 32; i++) { - if (!devicePtrs[i] || devicePtrs[i]->devId != devId) - continue; - if (devicePtrs[i]->node.node) { - if ((devicePtrs[i]->node.cookie[0] & ~PROM_NODE_SIBLING) <= - (flags & ~PROM_NODE_SIBLING)) - continue; - for (j = i + 1, pNode = devicePtrs[i]->node; j < 32; j++) { - if (!devicePtrs[j] || devicePtrs[j]->devId != devId) - continue; - pNode2 = devicePtrs[j]->node; - devicePtrs[j]->node = pNode; - pNode = pNode2; - } - } - devicePtrs[i]->node.node = node; - devicePtrs[i]->node.cookie[0] = flags; - devicePtrs[i]->node.cookie[1] = oldnode; - break; - } - break; - } - } while (0); + if (prop && (len > 0)) + do { + if (!strcmp(prop, "display")) { + prop = promGetProperty("name", &len); + if (!prop || len <= 0) + break; + while ((*prop >= 'A' && *prop <= 'Z') || *prop == ',') + prop++; + for (i = 0; sbusDeviceTable[i].devId; i++) + if (!strcmp(prop, sbusDeviceTable[i].promName)) + break; + devId = sbusDeviceTable[i].devId; + if (!devId) + break; + if (!sbus) { + if (devId == SBUS_DEVICE_FFB) { + /* + * All /SUNW,ffb outside of SBUS tree come before all + * /SUNW,afb outside of SBUS tree in Linux. + */ + if (!strcmp(prop, "afb")) + flags |= PROM_NODE_PREF; + } + else if (devId != SBUS_DEVICE_CG14) + break; + } + for (i = 0; i < 32; i++) { + if (!devicePtrs[i] || devicePtrs[i]->devId != devId) + continue; + if (devicePtrs[i]->node.node) { + if ((devicePtrs[i]->node. + cookie[0] & ~PROM_NODE_SIBLING) <= + (flags & ~PROM_NODE_SIBLING)) + continue; + for (j = i + 1, pNode = devicePtrs[i]->node; j < 32; + j++) { + if (!devicePtrs[j] || devicePtrs[j]->devId != devId) + continue; + pNode2 = devicePtrs[j]->node; + devicePtrs[j]->node = pNode; + pNode = pNode2; + } + } + devicePtrs[i]->node.node = node; + devicePtrs[i]->node.cookie[0] = flags; + devicePtrs[i]->node.cookie[1] = oldnode; + break; + } + break; + } + } while (0); prop = promGetProperty("name", &len); if (prop && len > 0) { - if (!strcmp(prop, "sbus") || !strcmp(prop, "sbi")) - sbus = PROM_NODE_SBUS; + if (!strcmp(prop, "sbus") || !strcmp(prop, "sbi")) + sbus = PROM_NODE_SBUS; } nextnode = promGetChild(node); if (nextnode) - promWalkAssignNodes(nextnode, node, sbus, devicePtrs); + promWalkAssignNodes(nextnode, node, sbus, devicePtrs); nextnode = promGetSibling(node); if (nextnode) - promWalkAssignNodes(nextnode, node, PROM_NODE_SIBLING | sbus, devicePtrs); + promWalkAssignNodes(nextnode, node, PROM_NODE_SIBLING | sbus, + devicePtrs); } void @@ -375,63 +390,66 @@ sparcPromAssignNodes(void) memset(devicePtrs, 0, sizeof(devicePtrs)); for (psdpp = xf86SbusInfo, n = 0; (psdp = *psdpp); psdpp++, n++) { - if (psdp->fbNum != n) - holes = 1; - devicePtrs[psdp->fbNum] = psdp; + if (psdp->fbNum != n) + holes = 1; + devicePtrs[psdp->fbNum] = psdp; } if (holes && (f = fopen("/proc/fb", "r")) != NULL) { - /* We could not open one of fb devices, check /proc/fb to see what - * were the types of the cards missed. */ - char buffer[64]; - int fbNum, devId; - static struct { - int devId; - char *prefix; - } procFbPrefixes[] = { - { SBUS_DEVICE_BW2, "BWtwo" }, - { SBUS_DEVICE_CG14, "CGfourteen" }, - { SBUS_DEVICE_CG6, "CGsix" }, - { SBUS_DEVICE_CG3, "CGthree" }, - { SBUS_DEVICE_FFB, "Creator" }, - { SBUS_DEVICE_FFB, "Elite 3D" }, - { SBUS_DEVICE_LEO, "Leo" }, - { SBUS_DEVICE_TCX, "TCX" }, - { 0, NULL }, - }; - - while (fscanf(f, "%d %63s\n", &fbNum, buffer) == 2) { - for (i = 0; procFbPrefixes[i].devId; i++) - if (! strncmp(procFbPrefixes[i].prefix, buffer, - strlen(procFbPrefixes[i].prefix))) - break; - devId = procFbPrefixes[i].devId; - if (! devId) continue; - if (devicePtrs[fbNum]) { - if (devicePtrs[fbNum]->devId != devId) - xf86ErrorF("Inconsistent /proc/fb with FBIOGATTR\n"); - } else if (!devicePtrs[fbNum]) { - devicePtrs[fbNum] = psdp = xnfcalloc(sizeof (sbusDevice), 1); - psdp->devId = devId; - psdp->fbNum = fbNum; - psdp->fd = -2; - } - } - fclose(f); + /* We could not open one of fb devices, check /proc/fb to see what + * were the types of the cards missed. */ + char buffer[64]; + int fbNum, devId; + static struct { + int devId; + char *prefix; + } procFbPrefixes[] = { + { + SBUS_DEVICE_BW2, "BWtwo"}, { + SBUS_DEVICE_CG14, "CGfourteen"}, { + SBUS_DEVICE_CG6, "CGsix"}, { + SBUS_DEVICE_CG3, "CGthree"}, { + SBUS_DEVICE_FFB, "Creator"}, { + SBUS_DEVICE_FFB, "Elite 3D"}, { + SBUS_DEVICE_LEO, "Leo"}, { + SBUS_DEVICE_TCX, "TCX"}, { + 0, NULL},}; + + while (fscanf(f, "%d %63s\n", &fbNum, buffer) == 2) { + for (i = 0; procFbPrefixes[i].devId; i++) + if (!strncmp(procFbPrefixes[i].prefix, buffer, + strlen(procFbPrefixes[i].prefix))) + break; + devId = procFbPrefixes[i].devId; + if (!devId) + continue; + if (devicePtrs[fbNum]) { + if (devicePtrs[fbNum]->devId != devId) + xf86ErrorF("Inconsistent /proc/fb with FBIOGATTR\n"); + } + else if (!devicePtrs[fbNum]) { + devicePtrs[fbNum] = psdp = xnfcalloc(sizeof(sbusDevice), 1); + psdp->devId = devId; + psdp->fbNum = fbNum; + psdp->fd = -2; + } + } + fclose(f); } promGetSibling(0); promWalkAssignNodes(promRootNode, 0, PROM_NODE_PREF, devicePtrs); for (i = 0, j = 0; i < 32; i++) - if (devicePtrs[i] && devicePtrs[i]->fbNum == -1) - j++; + if (devicePtrs[i] && devicePtrs[i]->fbNum == -1) + j++; xf86SbusInfo = xnfrealloc(xf86SbusInfo, sizeof(psdp) * (n + j + 1)); for (i = 0, psdpp = xf86SbusInfo; i < 32; i++) - if (devicePtrs[i]) { - if (devicePtrs[i]->fbNum == -1) { - memmove(psdpp + 1, psdpp, sizeof(psdpp) * (n + 1)); - *psdpp = devicePtrs[i]; - } else - n--; - } + if (devicePtrs[i]) { + if (devicePtrs[i]->fbNum == -1) { + memmove(psdpp + 1, psdpp, sizeof(psdpp) * (n + 1)); + *psdpp = devicePtrs[i]; + } + else + n--; + } } static char * @@ -444,37 +462,43 @@ promGetReg(int type) regstr[0] = 0; prop = promGetProperty("reg", &len); if (prop && len >= 4) { - unsigned int *reg = (unsigned int *)prop; - if (!promP1275 || (type == PROM_NODE_SBUS) || (type == PROM_NODE_EBUS)) - snprintf (regstr, sizeof(regstr), "@%x,%x", reg[0], reg[1]); - else if (type == PROM_NODE_PCI) { - if ((reg[0] >> 8) & 7) - snprintf (regstr, sizeof(regstr), "@%x,%x", (reg[0] >> 11) & 0x1f, (reg[0] >> 8) & 7); - else - snprintf (regstr, sizeof(regstr), "@%x", (reg[0] >> 11) & 0x1f); - } else if (len == 4) - snprintf (regstr, sizeof(regstr), "@%x", reg[0]); - else { - unsigned int regs[2]; - - /* Things get more complicated on UPA. If upa-portid exists, - then address is @upa-portid,second-int-in-reg, otherwise - it is @first-int-in-reg/16,second-int-in-reg (well, probably - upa-portid always exists, but just to be safe). */ - memcpy (regs, reg, sizeof(regs)); - prop = promGetProperty("upa-portid", &len); - if (prop && len == 4) { - reg = (unsigned int *)prop; - snprintf (regstr, sizeof(regstr), "@%x,%x", reg[0], regs[1]); - } else - snprintf (regstr, sizeof(regstr), "@%x,%x", regs[0] >> 4, regs[1]); - } + unsigned int *reg = (unsigned int *) prop; + + if (!promP1275 || (type == PROM_NODE_SBUS) || (type == PROM_NODE_EBUS)) + snprintf(regstr, sizeof(regstr), "@%x,%x", reg[0], reg[1]); + else if (type == PROM_NODE_PCI) { + if ((reg[0] >> 8) & 7) + snprintf(regstr, sizeof(regstr), "@%x,%x", + (reg[0] >> 11) & 0x1f, (reg[0] >> 8) & 7); + else + snprintf(regstr, sizeof(regstr), "@%x", (reg[0] >> 11) & 0x1f); + } + else if (len == 4) + snprintf(regstr, sizeof(regstr), "@%x", reg[0]); + else { + unsigned int regs[2]; + + /* Things get more complicated on UPA. If upa-portid exists, + then address is @upa-portid,second-int-in-reg, otherwise + it is @first-int-in-reg/16,second-int-in-reg (well, probably + upa-portid always exists, but just to be safe). */ + memcpy(regs, reg, sizeof(regs)); + prop = promGetProperty("upa-portid", &len); + if (prop && len == 4) { + reg = (unsigned int *) prop; + snprintf(regstr, sizeof(regstr), "@%x,%x", reg[0], regs[1]); + } + else + snprintf(regstr, sizeof(regstr), "@%x,%x", regs[0] >> 4, + regs[1]); + } } return regstr; } static int -promWalkNode2Pathname(char *path, int parent, int node, int searchNode, int type) +promWalkNode2Pathname(char *path, int parent, int node, int searchNode, + int type) { int nextnode; int len, ntype = type; @@ -483,27 +507,28 @@ promWalkNode2Pathname(char *path, int parent, int node, int searchNode, int type prop = promGetProperty("name", &len); *path = '/'; if (!prop || len <= 0) - return 0; + return 0; if ((!strcmp(prop, "sbus") || !strcmp(prop, "sbi")) && !type) - ntype = PROM_NODE_SBUS; + ntype = PROM_NODE_SBUS; else if (!strcmp(prop, "ebus") && type == PROM_NODE_PCI) - ntype = PROM_NODE_EBUS; + ntype = PROM_NODE_EBUS; else if (!strcmp(prop, "pci") && !type) - ntype = PROM_NODE_PCI; - strcpy (path + 1, prop); + ntype = PROM_NODE_PCI; + strcpy(path + 1, prop); p = promGetReg(type); if (*p) - strcat (path, p); + strcat(path, p); if (node == searchNode) - return 1; + return 1; nextnode = promGetChild(node); if (nextnode && - promWalkNode2Pathname(strchr(path, 0), node, nextnode, searchNode, ntype)) - return 1; + promWalkNode2Pathname(strchr(path, 0), node, nextnode, searchNode, + ntype)) + return 1; nextnode = promGetSibling(node); if (nextnode && - promWalkNode2Pathname(path, parent, nextnode, searchNode, type)) - return 1; + promWalkNode2Pathname(path, parent, nextnode, searchNode, type)) + return 1; return 0; } @@ -512,11 +537,14 @@ sparcPromNode2Pathname(sbusPromNodePtr pnode) { char *ret; - if (!pnode->node) return NULL; + if (!pnode->node) + return NULL; ret = malloc(4096); - if (!ret) return NULL; - if (promWalkNode2Pathname(ret, promRootNode, promGetChild(promRootNode), pnode->node, 0)) - return ret; + if (!ret) + return NULL; + if (promWalkNode2Pathname + (ret, promRootNode, promGetChild(promRootNode), pnode->node, 0)) + return ret; free(ret); return NULL; } @@ -528,51 +556,52 @@ promWalkPathname2Node(char *name, char *regstr, int parent, int type) char *prop, *p; for (;;) { - prop = promGetProperty("name", &len); - if (!prop || len <= 0) - return 0; - if ((!strcmp(prop, "sbus") || !strcmp(prop, "sbi")) && !type) - type = PROM_NODE_SBUS; - else if (!strcmp(prop, "ebus") && type == PROM_NODE_PCI) - type = PROM_NODE_EBUS; - else if (!strcmp(prop, "pci") && !type) - type = PROM_NODE_PCI; - for (node = promGetChild(parent); node; node = promGetSibling(node)) { - prop = promGetProperty("name", &len); - if (!prop || len <= 0) - continue; - if (*name && strcmp(name, prop)) - continue; - if (*regstr) { - p = promGetReg(type); - if (! *p || strcmp(p + 1, regstr)) - continue; - } - break; - } - if (!node) { - for (node = promGetChild(parent); node; node = promGetSibling(node)) { - ret = promWalkPathname2Node(name, regstr, node, type); - if (ret) return ret; - } - return 0; - } - name = strchr(regstr, 0) + 1; - if (! *name) - return node; - p = strchr(name, '/'); - if (p) - *p = 0; - else - p = strchr(name, 0); - regstr = strchr(name, '@'); - if (regstr) - *regstr++ = 0; - else - regstr = p; - if (name == regstr) - return 0; - parent = node; + prop = promGetProperty("name", &len); + if (!prop || len <= 0) + return 0; + if ((!strcmp(prop, "sbus") || !strcmp(prop, "sbi")) && !type) + type = PROM_NODE_SBUS; + else if (!strcmp(prop, "ebus") && type == PROM_NODE_PCI) + type = PROM_NODE_EBUS; + else if (!strcmp(prop, "pci") && !type) + type = PROM_NODE_PCI; + for (node = promGetChild(parent); node; node = promGetSibling(node)) { + prop = promGetProperty("name", &len); + if (!prop || len <= 0) + continue; + if (*name && strcmp(name, prop)) + continue; + if (*regstr) { + p = promGetReg(type); + if (!*p || strcmp(p + 1, regstr)) + continue; + } + break; + } + if (!node) { + for (node = promGetChild(parent); node; node = promGetSibling(node)) { + ret = promWalkPathname2Node(name, regstr, node, type); + if (ret) + return ret; + } + return 0; + } + name = strchr(regstr, 0) + 1; + if (!*name) + return node; + p = strchr(name, '/'); + if (p) + *p = 0; + else + p = strchr(name, 0); + regstr = strchr(name, '@'); + if (regstr) + *regstr++ = 0; + else + regstr = p; + if (name == regstr) + return 0; + parent = node; } } @@ -584,23 +613,24 @@ sparcPromPathname2Node(const char *pathName) i = strlen(pathName); name = malloc(i + 2); - if (! name) return 0; - strcpy (name, pathName); - name [i + 1] = 0; + if (!name) + return 0; + strcpy(name, pathName); + name[i + 1] = 0; if (name[0] != '/') - return 0; + return 0; p = strchr(name + 1, '/'); if (p) - *p = 0; + *p = 0; else - p = strchr(name, 0); + p = strchr(name, 0); regstr = strchr(name, '@'); if (regstr) - *regstr++ = 0; + *regstr++ = 0; else - regstr = p; + regstr = p; if (name + 1 == regstr) - return 0; + return 0; promGetSibling(0); i = promWalkPathname2Node(name + 1, regstr, promRootNode, 0); free(name); @@ -616,32 +646,33 @@ xf86MapSbusMem(sbusDevicePtr psdp, unsigned long offset, unsigned long size) unsigned long len = ((offset + size + pagemask) & ~pagemask) - off; if (psdp->fd == -1) { - psdp->fd = open(psdp->device, O_RDWR); - if (psdp->fd == -1) - return NULL; - } else if (psdp->fd < 0) - return NULL; - - ret = (pointer) mmap (NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE, - psdp->fd, off); + psdp->fd = open(psdp->device, O_RDWR); + if (psdp->fd == -1) + return NULL; + } + else if (psdp->fd < 0) + return NULL; + + ret = (pointer) mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE, + psdp->fd, off); if (ret == (pointer) -1) { - ret = (pointer) mmap (NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, - psdp->fd, off); + ret = (pointer) mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, + psdp->fd, off); } if (ret == (pointer) -1) - return NULL; + return NULL; - return (char *)ret + (offset - off); + return (char *) ret + (offset - off); } void xf86UnmapSbusMem(sbusDevicePtr psdp, pointer addr, unsigned long size) { unsigned long mask = getpagesize() - 1; - unsigned long base = (unsigned long)addr & ~mask; - unsigned long len = (((unsigned long)addr + size + mask) & ~mask) - base; + unsigned long base = (unsigned long) addr & ~mask; + unsigned long len = (((unsigned long) addr + size + mask) & ~mask) - base; - munmap ((pointer)base, len); + munmap((pointer) base, len); } /* Tell OS that we are driving the HW cursor ourselves. */ @@ -657,8 +688,8 @@ xf86SbusHideOsHwCursor(sbusDevicePtr psdp) fbcursor.cmap.red = zeros; fbcursor.cmap.green = zeros; fbcursor.cmap.blue = zeros; - fbcursor.image = (char *)zeros; - fbcursor.mask = (char *)zeros; + fbcursor.image = (char *) zeros; + fbcursor.mask = (char *) zeros; fbcursor.size.x = 32; fbcursor.size.y = 1; fbcursor.set = FB_CUR_SETALL; diff --git a/xorg-server/hw/xfree86/os-support/bus/nobus.c b/xorg-server/hw/xfree86/os-support/bus/nobus.c index ad23f5288..dca58fee2 100644 --- a/xorg-server/hw/xfree86/os-support/bus/nobus.c +++ b/xorg-server/hw/xfree86/os-support/bus/nobus.c @@ -1 +1,5 @@ -static void __noop_to_appease_ar__() { return; } +static void +__noop_to_appease_ar__() +{ + return; +} diff --git a/xorg-server/hw/xfree86/os-support/bus/xf86Pci.h b/xorg-server/hw/xfree86/os-support/bus/xf86Pci.h index 74ead201e..f69e55b39 100644 --- a/xorg-server/hw/xfree86/os-support/bus/xf86Pci.h +++ b/xorg-server/hw/xfree86/os-support/bus/xf86Pci.h @@ -95,7 +95,6 @@ * authorization from the copyright holder(s) and author(s). */ - /* * This file contains just the public interface to the PCI code. * Drivers should use this file rather than Pci.h. @@ -234,8 +233,8 @@ */ /* Primitive Types */ -typedef unsigned long ADDRESS; /* Memory/PCI address */ -typedef unsigned long IOADDRESS _X_DEPRECATED; /* Must be large enough for a pointer */ +typedef unsigned long ADDRESS; /* Memory/PCI address */ +typedef unsigned long IOADDRESS _X_DEPRECATED; /* Must be large enough for a pointer */ typedef CARD32 PCITAG _X_DEPRECATED; typedef enum { @@ -249,12 +248,12 @@ typedef enum { PCI_IO_SPARSE_MASK } PciAddrType; - /* Public PCI access functions */ extern _X_EXPORT Bool xf86scanpci(void); /* Domain access functions. Some of these probably shouldn't be public */ extern _X_EXPORT struct pci_io_handle *xf86MapLegacyIO(struct pci_device *dev); -extern _X_EXPORT void xf86UnmapLegacyIO(struct pci_device *, struct pci_io_handle *); +extern _X_EXPORT void xf86UnmapLegacyIO(struct pci_device *, + struct pci_io_handle *); -#endif /* _XF86PCI_H */ +#endif /* _XF86PCI_H */ diff --git a/xorg-server/hw/xfree86/os-support/hurd/hurd_init.c b/xorg-server/hw/xfree86/os-support/hurd/hurd_init.c index 94e261553..185b2b951 100644 --- a/xorg-server/hw/xfree86/os-support/hurd/hurd_init.c +++ b/xorg-server/hw/xfree86/os-support/hurd/hurd_init.c @@ -44,39 +44,38 @@ #include <mach.h> int -xf86ProcessArgument( int argc,char **argv, int i ) +xf86ProcessArgument(int argc, char **argv, int i) { return 0; } + void xf86UseMsg() { return; } - void xf86OpenConsole() { - if( serverGeneration == 1 ) - { - kern_return_t err; - mach_port_t device; - int fd; - err = get_privileged_ports( NULL, &device ); - if( err ) - { - errno = err; - FatalError( "xf86KbdInit can't get_privileged_ports. (%s)\n" , strerror(errno) ); - } - mach_port_deallocate (mach_task_self (), device); - - if( ( fd = open( "/dev/kbd" , O_RDONLY|O_NONBLOCK ) ) < 0 ) - { - fprintf( stderr , "Cannot open keyboard (%s)\n",strerror(errno) ); - exit(1); - } - xf86Info.consoleFd = fd; + if (serverGeneration == 1) { + kern_return_t err; + mach_port_t device; + int fd; + + err = get_privileged_ports(NULL, &device); + if (err) { + errno = err; + FatalError("xf86KbdInit can't get_privileged_ports. (%s)\n", + strerror(errno)); + } + mach_port_deallocate(mach_task_self(), device); + + if ((fd = open("/dev/kbd", O_RDONLY | O_NONBLOCK)) < 0) { + fprintf(stderr, "Cannot open keyboard (%s)\n", strerror(errno)); + exit(1); + } + xf86Info.consoleFd = fd; } return; } @@ -84,6 +83,6 @@ xf86OpenConsole() void xf86CloseConsole() { - close( xf86Info.consoleFd ); + close(xf86Info.consoleFd); return; } diff --git a/xorg-server/hw/xfree86/os-support/hurd/hurd_mmap.c b/xorg-server/hw/xfree86/os-support/hurd/hurd_mmap.c index 9d9b84a28..6ac9efdfe 100644 --- a/xorg-server/hw/xfree86/os-support/hurd/hurd_mmap.c +++ b/xorg-server/hw/xfree86/os-support/hurd/hurd_mmap.c @@ -1,95 +1,93 @@ -/*
- * Copyright 1997 by UCHIYAMA Yasushi
- *
- * Permission to use, copy, modify, distribute, and sell this software and its
- * documentation for any purpose is hereby granted without fee, provided that
- * the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of UCHIYAMA Yasushi not be used in
- * advertising or publicity pertaining to distribution of the software without
- * specific, written prior permission. UCHIYAMA Yasushi makes no representations
- * about the suitability of this software for any purpose. It is provided
- * "as is" without express or implied warranty.
- *
- * UCHIYAMA YASUSHI DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- * EVENT SHALL UCHIYAMA YASUSHI BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- * PERFORMANCE OF THIS SOFTWARE.
- *
- */
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include<mach.h>
-#include<device/device.h>
-#include<mach/machine/mach_i386.h>
-
-#include <X11/X.h>
-
-#include "xf86.h"
-#include "xf86Priv.h"
-#include "xf86_OSlib.h"
-
-#define BIOS_SIZE 0x20000
-
-int
-xf86ReadBIOS(unsigned long Base,unsigned long Offset,unsigned char *Buf,int Len)
-{
- mach_port_t device,mem_dev;
- memory_object_t mem_obj;
- vm_address_t addr = (vm_address_t)0; /* serach starting address */
- kern_return_t err;
-
-
- err = get_privileged_ports (NULL, &device);
- if( err )
- {
- errno = err;
- FatalError("xf86ReadBIOS() can't get_privileged_ports. (%s)\n",strerror(errno));
- }
- err = device_open(device,D_READ|D_WRITE,"mem",&mem_dev);
- mach_port_deallocate (mach_task_self (), device);
- if( err )
- {
- errno = err;
- FatalError("xf86ReadBIOS() can't device_open. (%s)\n",strerror(errno));
- }
- err = device_map(mem_dev,VM_PROT_READ|VM_PROT_WRITE, Base , BIOS_SIZE ,&mem_obj,0);
- if( err )
- {
- errno = err;
- FatalError("xf86ReadBIOS() can't device_map. (%s)\n",strerror(errno));
- }
- err = vm_map(mach_task_self(),
- &addr,
- BIOS_SIZE,
- 0,
- TRUE,
- mem_obj,
- Base,
- FALSE,
- VM_PROT_READ|VM_PROT_WRITE,
- VM_PROT_READ|VM_PROT_WRITE,
- VM_INHERIT_SHARE);
- mach_port_deallocate(mach_task_self(),mem_obj);
- if( err )
- {
- errno = err;
- FatalError("xf86ReadBIOS() can't vm_map. (%s)\n",strerror(errno));
- }
-
- memcpy(Buf,(void*)((int)addr + Offset), Len);
-
- err = vm_deallocate(mach_task_self(), addr, BIOS_SIZE);
- if( err )
- {
- errno = err;
- FatalError("xf86ReadBIOS() can't vm_deallocate. (%s)\n",strerror(errno));
- }
-
- return Len;
-}
+/* + * Copyright 1997 by UCHIYAMA Yasushi + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of UCHIYAMA Yasushi not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. UCHIYAMA Yasushi makes no representations + * about the suitability of this software for any purpose. It is provided + * "as is" without express or implied warranty. + * + * UCHIYAMA YASUSHI DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL UCHIYAMA YASUSHI BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + * + */ +#ifdef HAVE_XORG_CONFIG_H +#include <xorg-config.h> +#endif + +#include<mach.h> +#include<device/device.h> +#include<mach/machine/mach_i386.h> + +#include <X11/X.h> + +#include "xf86.h" +#include "xf86Priv.h" +#include "xf86_OSlib.h" + +#define BIOS_SIZE 0x20000 + +int +xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf, + int Len) +{ + mach_port_t device, mem_dev; + memory_object_t mem_obj; + vm_address_t addr = (vm_address_t) 0; /* serach starting address */ + kern_return_t err; + + err = get_privileged_ports(NULL, &device); + if (err) { + errno = err; + FatalError("xf86ReadBIOS() can't get_privileged_ports. (%s)\n", + strerror(errno)); + } + err = device_open(device, D_READ | D_WRITE, "mem", &mem_dev); + mach_port_deallocate(mach_task_self(), device); + if (err) { + errno = err; + FatalError("xf86ReadBIOS() can't device_open. (%s)\n", strerror(errno)); + } + err = + device_map(mem_dev, VM_PROT_READ | VM_PROT_WRITE, Base, BIOS_SIZE, + &mem_obj, 0); + if (err) { + errno = err; + FatalError("xf86ReadBIOS() can't device_map. (%s)\n", strerror(errno)); + } + err = vm_map(mach_task_self(), + &addr, + BIOS_SIZE, + 0, + TRUE, + mem_obj, + Base, + FALSE, + VM_PROT_READ | VM_PROT_WRITE, + VM_PROT_READ | VM_PROT_WRITE, VM_INHERIT_SHARE); + mach_port_deallocate(mach_task_self(), mem_obj); + if (err) { + errno = err; + FatalError("xf86ReadBIOS() can't vm_map. (%s)\n", strerror(errno)); + } + + memcpy(Buf, (void *) ((int) addr + Offset), Len); + + err = vm_deallocate(mach_task_self(), addr, BIOS_SIZE); + if (err) { + errno = err; + FatalError("xf86ReadBIOS() can't vm_deallocate. (%s)\n", + strerror(errno)); + } + + return Len; +} diff --git a/xorg-server/hw/xfree86/os-support/hurd/hurd_video.c b/xorg-server/hw/xfree86/os-support/hurd/hurd_video.c index a0a3b2758..72474ba10 100644 --- a/xorg-server/hw/xfree86/os-support/hurd/hurd_video.c +++ b/xorg-server/hw/xfree86/os-support/hurd/hurd_video.c @@ -1,155 +1,152 @@ -/*
- * Copyright 1997, 1998 by UCHIYAMA Yasushi
- *
- * Permission to use, copy, modify, distribute, and sell this software and its
- * documentation for any purpose is hereby granted without fee, provided that
- * the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of UCHIYAMA Yasushi not be used in
- * advertising or publicity pertaining to distribution of the software without
- * specific, written prior permission. UCHIYAMA Yasushi makes no representations
- * about the suitability of this software for any purpose. It is provided
- * "as is" without express or implied warranty.
- *
- * UCHIYAMA YASUSHI DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- * EVENT SHALL UCHIYAMA YASUSHI BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- * PERFORMANCE OF THIS SOFTWARE.
- *
- */
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include <mach.h>
-#include <device/device.h>
-#include <mach/machine/mach_i386.h>
-
-#include <X11/X.h>
-#include "input.h"
-#include "scrnintstr.h"
-
-#include "xf86.h"
-#include "xf86Priv.h"
-#include "xf86_OSlib.h"
-#include "xf86OSpriv.h"
-
-/**************************************************************************
- * Video Memory Mapping section
- ***************************************************************************/
-static pointer
-mapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int Flags)
-{
- mach_port_t device,mem_dev;
- memory_object_t mem_obj;
- kern_return_t err;
- vm_address_t addr=(vm_address_t)0;
-
- err = get_privileged_ports (NULL, &device);
- if( err )
- {
- errno = err;
- FatalError("xf86MapVidMem() can't get_privileged_ports. (%s)\n",strerror(errno));
- }
- err = device_open(device,D_READ|D_WRITE,"mem",&mem_dev);
- mach_port_deallocate (mach_task_self(), device);
- if( err )
- {
- errno = err;
- FatalError("xf86MapVidMem() can't device_open. (%s)\n",strerror(errno));
- }
-
- err = device_map(mem_dev,VM_PROT_READ|VM_PROT_WRITE, Base , Size ,&mem_obj,0);
- if( err )
- {
- errno = err;
- FatalError("xf86MapVidMem() can't device_map. (%s)\n",strerror(errno));
- }
- err = vm_map(mach_task_self(),
- &addr,
- Size,
- 0, /* mask */
- TRUE, /* anywhere */
- mem_obj,
- (vm_offset_t)Base,
- FALSE, /* copy on write */
- VM_PROT_READ|VM_PROT_WRITE,
- VM_PROT_READ|VM_PROT_WRITE,
- VM_INHERIT_SHARE);
- mach_port_deallocate(mach_task_self(),mem_obj);
- if( err )
- {
- errno = err;
- FatalError("xf86MapVidMem() can't vm_map.(mem_obj) (%s)\n",strerror(errno));
- }
- mach_port_deallocate(mach_task_self(),mem_dev);
- if( err )
- {
- errno = err;
- FatalError("xf86MapVidMem() can't mach_port_deallocate.(mem_dev) (%s)\n",strerror(errno));
- }
- return (pointer)addr;
-}
-
-static void
-unmapVidMem(int ScreenNum,pointer Base,unsigned long Size)
-{
- kern_return_t err = vm_deallocate(mach_task_self(), (int)Base, Size);
- if( err )
- {
- errno = err;
- ErrorF("xf86UnMapVidMem: can't dealloc framebuffer space (%s)\n",strerror(errno));
- }
- return;
-}
-
-/**************************************************************************
- * I/O Permissions section
- ***************************************************************************/
-
-/*
- * Due to conflicts with "compiler.h", don't rely on <sys/io.h> to declare
- * this.
- */
-extern int ioperm(unsigned long __from, unsigned long __num, int __turn_on);
-
-Bool
-xf86EnableIO()
-{
- if (ioperm(0, 0x10000, 1)) {
- FatalError("xf86EnableIO: ioperm() failed (%s)\n", strerror(errno));
- return FALSE;
- }
-#if 0
- /*
- * Trapping disabled for now, as some VBIOSes (mga-g450 notably) use these
- * ports, and the int10 wrapper is not emulating them. (Note that it's
- * effectively what happens in the Linux variant too, as iopl() is used
- * there, making the ioperm() meaningless.)
- *
- * Reenable this when int10 gets fixed. */
- ioperm(0x40,4,0); /* trap access to the timer chip */
- ioperm(0x60,4,0); /* trap access to the keyboard controller */
-#endif
- return TRUE;
-}
-
-void
-xf86DisableIO()
-{
- ioperm(0,0x10000,0);
- return;
-}
-
-void
-xf86OSInitVidMem(VidMemInfoPtr pVidMem)
-{
- pVidMem->linearSupported = TRUE;
- pVidMem->mapMem = mapVidMem;
- pVidMem->unmapMem = unmapVidMem;
- pVidMem->initialised = TRUE;
-}
+/* + * Copyright 1997, 1998 by UCHIYAMA Yasushi + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of UCHIYAMA Yasushi not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. UCHIYAMA Yasushi makes no representations + * about the suitability of this software for any purpose. It is provided + * "as is" without express or implied warranty. + * + * UCHIYAMA YASUSHI DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL UCHIYAMA YASUSHI BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + * + */ + +#ifdef HAVE_XORG_CONFIG_H +#include <xorg-config.h> +#endif + +#include <mach.h> +#include <device/device.h> +#include <mach/machine/mach_i386.h> + +#include <X11/X.h> +#include "input.h" +#include "scrnintstr.h" + +#include "xf86.h" +#include "xf86Priv.h" +#include "xf86_OSlib.h" +#include "xf86OSpriv.h" + +/************************************************************************** + * Video Memory Mapping section + ***************************************************************************/ +static pointer +mapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int Flags) +{ + mach_port_t device, mem_dev; + memory_object_t mem_obj; + kern_return_t err; + vm_address_t addr = (vm_address_t) 0; + + err = get_privileged_ports(NULL, &device); + if (err) { + errno = err; + FatalError("xf86MapVidMem() can't get_privileged_ports. (%s)\n", + strerror(errno)); + } + err = device_open(device, D_READ | D_WRITE, "mem", &mem_dev); + mach_port_deallocate(mach_task_self(), device); + if (err) { + errno = err; + FatalError("xf86MapVidMem() can't device_open. (%s)\n", + strerror(errno)); + } + + err = + device_map(mem_dev, VM_PROT_READ | VM_PROT_WRITE, Base, Size, &mem_obj, + 0); + if (err) { + errno = err; + FatalError("xf86MapVidMem() can't device_map. (%s)\n", strerror(errno)); + } + err = vm_map(mach_task_self(), &addr, Size, 0, /* mask */ + TRUE, /* anywhere */ + mem_obj, (vm_offset_t) Base, FALSE, /* copy on write */ + VM_PROT_READ | VM_PROT_WRITE, + VM_PROT_READ | VM_PROT_WRITE, VM_INHERIT_SHARE); + mach_port_deallocate(mach_task_self(), mem_obj); + if (err) { + errno = err; + FatalError("xf86MapVidMem() can't vm_map.(mem_obj) (%s)\n", + strerror(errno)); + } + mach_port_deallocate(mach_task_self(), mem_dev); + if (err) { + errno = err; + FatalError + ("xf86MapVidMem() can't mach_port_deallocate.(mem_dev) (%s)\n", + strerror(errno)); + } + return (pointer) addr; +} + +static void +unmapVidMem(int ScreenNum, pointer Base, unsigned long Size) +{ + kern_return_t err = vm_deallocate(mach_task_self(), (int) Base, Size); + + if (err) { + errno = err; + ErrorF("xf86UnMapVidMem: can't dealloc framebuffer space (%s)\n", + strerror(errno)); + } + return; +} + +/************************************************************************** + * I/O Permissions section + ***************************************************************************/ + +/* + * Due to conflicts with "compiler.h", don't rely on <sys/io.h> to declare + * this. + */ +extern int ioperm(unsigned long __from, unsigned long __num, int __turn_on); + +Bool +xf86EnableIO() +{ + if (ioperm(0, 0x10000, 1)) { + FatalError("xf86EnableIO: ioperm() failed (%s)\n", strerror(errno)); + return FALSE; + } +#if 0 + /* + * Trapping disabled for now, as some VBIOSes (mga-g450 notably) use these + * ports, and the int10 wrapper is not emulating them. (Note that it's + * effectively what happens in the Linux variant too, as iopl() is used + * there, making the ioperm() meaningless.) + * + * Reenable this when int10 gets fixed. */ + ioperm(0x40, 4, 0); /* trap access to the timer chip */ + ioperm(0x60, 4, 0); /* trap access to the keyboard controller */ +#endif + return TRUE; +} + +void +xf86DisableIO() +{ + ioperm(0, 0x10000, 0); + return; +} + +void +xf86OSInitVidMem(VidMemInfoPtr pVidMem) +{ + pVidMem->linearSupported = TRUE; + pVidMem->mapMem = mapVidMem; + pVidMem->unmapMem = unmapVidMem; + pVidMem->initialised = TRUE; +} diff --git a/xorg-server/hw/xfree86/os-support/linux/int10/linux.c b/xorg-server/hw/xfree86/os-support/linux/int10/linux.c index 564447ff6..fa58a72b6 100644 --- a/xorg-server/hw/xfree86/os-support/linux/int10/linux.c +++ b/xorg-server/hw/xfree86/os-support/linux/int10/linux.c @@ -50,10 +50,10 @@ int10MemRec linuxMem = { typedef struct { int lowMem; int highMem; - char* base; - char* base_high; + char *base; + char *base_high; int screen; - char* alloc; + char *alloc; } linuxInt10Priv; #if defined DoSubModules @@ -69,7 +69,7 @@ static Int10LinuxSubModuleState loadedSubModule = INT10_NOT_LOADED; static Int10LinuxSubModuleState int10LinuxLoadSubModule(ScrnInfoPtr pScrn); -#endif /* DoSubModules */ +#endif /* DoSubModules */ xf86Int10InfoPtr xf86ExtendedInitInt10(int entityIndex, int Flags) @@ -77,152 +77,155 @@ xf86ExtendedInitInt10(int entityIndex, int Flags) xf86Int10InfoPtr pInt = NULL; int screen; int fd; - static void* vidMem = NULL; - static void* sysMem = NULL; - void* vMem = NULL; + static void *vidMem = NULL; + static void *sysMem = NULL; + void *vMem = NULL; void *options = NULL; int low_mem; int high_mem = -1; char *base = SHMERRORPTR; char *base_high = SHMERRORPTR; - int pagesize; + int pagesize; memType cs; legacyVGARec vga; Bool videoBiosMapped = FALSE; - + if (int10Generation != serverGeneration) { - counter = 0; - int10Generation = serverGeneration; + counter = 0; + int10Generation = serverGeneration; } screen = (xf86FindScreenForEntity(entityIndex))->scrnIndex; - options = xf86HandleInt10Options(xf86Screens[screen],entityIndex); + options = xf86HandleInt10Options(xf86Screens[screen], entityIndex); if (int10skip(options)) { - free(options); - return NULL; + free(options); + return NULL; } #if defined DoSubModules - if (loadedSubModule == INT10_NOT_LOADED) - loadedSubModule = int10LinuxLoadSubModule(xf86Screens[screen]); + if (loadedSubModule == INT10_NOT_LOADED) + loadedSubModule = int10LinuxLoadSubModule(xf86Screens[screen]); if (loadedSubModule == INT10_LOAD_FAILED) - return NULL; + return NULL; #endif if ((!vidMem) || (!sysMem)) { - if ((fd = open(DEV_MEM, O_RDWR, 0)) >= 0) { - if (!sysMem) { - DebugF("Mapping sys bios area\n"); - if ((sysMem = mmap((void *)(SYS_BIOS), BIOS_SIZE, - PROT_READ | PROT_EXEC, - MAP_SHARED | MAP_FIXED, fd, SYS_BIOS)) - == MAP_FAILED) { - xf86DrvMsg(screen, X_ERROR, "Cannot map SYS BIOS\n"); - close(fd); - goto error0; - } - } - if (!vidMem) { - DebugF("Mapping VRAM area\n"); - if ((vidMem = mmap((void *)(V_RAM), VRAM_SIZE, - PROT_READ | PROT_WRITE | PROT_EXEC, - MAP_SHARED | MAP_FIXED, fd, V_RAM)) - == MAP_FAILED) { - xf86DrvMsg(screen, X_ERROR, "Cannot map V_RAM\n"); - close(fd); - goto error0; - } - } - close(fd); - } else { - xf86DrvMsg(screen, X_ERROR, "Cannot open %s\n", DEV_MEM); - goto error0; - } + if ((fd = open(DEV_MEM, O_RDWR, 0)) >= 0) { + if (!sysMem) { + DebugF("Mapping sys bios area\n"); + if ((sysMem = mmap((void *) (SYS_BIOS), BIOS_SIZE, + PROT_READ | PROT_EXEC, + MAP_SHARED | MAP_FIXED, fd, SYS_BIOS)) + == MAP_FAILED) { + xf86DrvMsg(screen, X_ERROR, "Cannot map SYS BIOS\n"); + close(fd); + goto error0; + } + } + if (!vidMem) { + DebugF("Mapping VRAM area\n"); + if ((vidMem = mmap((void *) (V_RAM), VRAM_SIZE, + PROT_READ | PROT_WRITE | PROT_EXEC, + MAP_SHARED | MAP_FIXED, fd, V_RAM)) + == MAP_FAILED) { + xf86DrvMsg(screen, X_ERROR, "Cannot map V_RAM\n"); + close(fd); + goto error0; + } + } + close(fd); + } + else { + xf86DrvMsg(screen, X_ERROR, "Cannot open %s\n", DEV_MEM); + goto error0; + } } - pInt = (xf86Int10InfoPtr)xnfcalloc(1, sizeof(xf86Int10InfoRec)); + pInt = (xf86Int10InfoPtr) xnfcalloc(1, sizeof(xf86Int10InfoRec)); pInt->scrnIndex = screen; pInt->entityIndex = entityIndex; pInt->dev = xf86GetPciInfoForEntity(entityIndex); if (!xf86Int10ExecSetup(pInt)) - goto error0; + goto error0; pInt->mem = &linuxMem; pagesize = getpagesize(); - pInt->private = (pointer)xnfcalloc(1, sizeof(linuxInt10Priv)); - ((linuxInt10Priv*)pInt->private)->screen = screen; - ((linuxInt10Priv*)pInt->private)->alloc = - (pointer)xnfcalloc(1, ALLOC_ENTRIES(pagesize)); + pInt->private = (pointer) xnfcalloc(1, sizeof(linuxInt10Priv)); + ((linuxInt10Priv *) pInt->private)->screen = screen; + ((linuxInt10Priv *) pInt->private)->alloc = + (pointer) xnfcalloc(1, ALLOC_ENTRIES(pagesize)); if (!xf86IsEntityPrimary(entityIndex)) { - DebugF("Mapping high memory area\n"); - if ((high_mem = shmget(counter++, HIGH_MEM_SIZE, - IPC_CREAT | SHM_R | SHM_W)) == -1) { - if (errno == ENOSYS) - xf86DrvMsg(screen, X_ERROR, "shmget error\n Please reconfigure" - " your kernel to include System V IPC support\n"); - else - xf86DrvMsg(screen, X_ERROR, - "shmget(highmem) error: %s\n",strerror(errno)); - goto error1; - } - } else { - DebugF("Mapping Video BIOS\n"); - videoBiosMapped = TRUE; - if ((fd = open(DEV_MEM, O_RDWR, 0)) >= 0) { - if ((vMem = mmap((void *)(V_BIOS), SYS_BIOS - V_BIOS, - PROT_READ | PROT_WRITE | PROT_EXEC, - MAP_SHARED | MAP_FIXED, fd, V_BIOS)) - == MAP_FAILED) { - xf86DrvMsg(screen, X_ERROR, "Cannot map V_BIOS\n"); - close(fd); - goto error1; - } - close (fd); - } else - goto error1; + DebugF("Mapping high memory area\n"); + if ((high_mem = shmget(counter++, HIGH_MEM_SIZE, + IPC_CREAT | SHM_R | SHM_W)) == -1) { + if (errno == ENOSYS) + xf86DrvMsg(screen, X_ERROR, "shmget error\n Please reconfigure" + " your kernel to include System V IPC support\n"); + else + xf86DrvMsg(screen, X_ERROR, + "shmget(highmem) error: %s\n", strerror(errno)); + goto error1; + } + } + else { + DebugF("Mapping Video BIOS\n"); + videoBiosMapped = TRUE; + if ((fd = open(DEV_MEM, O_RDWR, 0)) >= 0) { + if ((vMem = mmap((void *) (V_BIOS), SYS_BIOS - V_BIOS, + PROT_READ | PROT_WRITE | PROT_EXEC, + MAP_SHARED | MAP_FIXED, fd, V_BIOS)) + == MAP_FAILED) { + xf86DrvMsg(screen, X_ERROR, "Cannot map V_BIOS\n"); + close(fd); + goto error1; + } + close(fd); + } + else + goto error1; } - ((linuxInt10Priv*)pInt->private)->highMem = high_mem; - + ((linuxInt10Priv *) pInt->private)->highMem = high_mem; + DebugF("Mapping 640kB area\n"); - if ((low_mem = shmget(counter++, V_RAM, - IPC_CREAT | SHM_R | SHM_W)) == -1) { - xf86DrvMsg(screen, X_ERROR, - "shmget(lowmem) error: %s\n",strerror(errno)); - goto error2; + if ((low_mem = shmget(counter++, V_RAM, IPC_CREAT | SHM_R | SHM_W)) == -1) { + xf86DrvMsg(screen, X_ERROR, + "shmget(lowmem) error: %s\n", strerror(errno)); + goto error2; } - ((linuxInt10Priv*)pInt->private)->lowMem = low_mem; + ((linuxInt10Priv *) pInt->private)->lowMem = low_mem; base = shmat(low_mem, 0, 0); if (base == SHMERRORPTR) { - xf86DrvMsg(screen, X_ERROR, - "shmat(low_mem) error: %s\n",strerror(errno)); - goto error3; + xf86DrvMsg(screen, X_ERROR, + "shmat(low_mem) error: %s\n", strerror(errno)); + goto error3; } - ((linuxInt10Priv *)pInt->private)->base = base; + ((linuxInt10Priv *) pInt->private)->base = base; if (high_mem > -1) { - base_high = shmat(high_mem, 0, 0); - if (base_high == SHMERRORPTR) { - xf86DrvMsg(screen, X_ERROR, - "shmat(high_mem) error: %s\n",strerror(errno)); - goto error3; - } - ((linuxInt10Priv*)pInt->private)->base_high = base_high; - } else - ((linuxInt10Priv*)pInt->private)->base_high = NULL; + base_high = shmat(high_mem, 0, 0); + if (base_high == SHMERRORPTR) { + xf86DrvMsg(screen, X_ERROR, + "shmat(high_mem) error: %s\n", strerror(errno)); + goto error3; + } + ((linuxInt10Priv *) pInt->private)->base_high = base_high; + } + else + ((linuxInt10Priv *) pInt->private)->base_high = NULL; if (!MapCurrentInt10(pInt)) - goto error3; - + goto error3; + Int10Current = pInt; DebugF("Mapping int area\n"); - if (xf86ReadBIOS(0, 0, (unsigned char *)0, LOW_PAGE_SIZE) < 0) { - xf86DrvMsg(screen, X_ERROR, "Cannot read int vect\n"); - goto error3; + if (xf86ReadBIOS(0, 0, (unsigned char *) 0, LOW_PAGE_SIZE) < 0) { + xf86DrvMsg(screen, X_ERROR, "Cannot read int vect\n"); + goto error3; } DebugF("done\n"); /* @@ -231,57 +234,58 @@ xf86ExtendedInitInt10(int entityIndex, int Flags) * 64K bytes at a time. */ if (!videoBiosMapped) { - memset((pointer)V_BIOS, 0, SYS_BIOS - V_BIOS); - DebugF("Reading BIOS\n"); - for (cs = V_BIOS; cs < SYS_BIOS; cs += V_BIOS_SIZE) - if (xf86ReadBIOS(cs, 0, (pointer)cs, V_BIOS_SIZE) < V_BIOS_SIZE) - xf86DrvMsg(screen, X_WARNING, - "Unable to retrieve all of segment 0x%06lX.\n", - (long)cs); - DebugF("done\n"); + memset((pointer) V_BIOS, 0, SYS_BIOS - V_BIOS); + DebugF("Reading BIOS\n"); + for (cs = V_BIOS; cs < SYS_BIOS; cs += V_BIOS_SIZE) + if (xf86ReadBIOS(cs, 0, (pointer) cs, V_BIOS_SIZE) < V_BIOS_SIZE) + xf86DrvMsg(screen, X_WARNING, + "Unable to retrieve all of segment 0x%06lX.\n", + (long) cs); + DebugF("done\n"); } if (xf86IsEntityPrimary(entityIndex) && !(initPrimary(options))) { - if (!xf86int10GetBiosSegment(pInt, NULL)) - goto error3; - - set_return_trap(pInt); -#ifdef _PC - pInt->Flags = Flags & (SET_BIOS_SCRATCH | RESTORE_BIOS_SCRATCH); - if (! (pInt->Flags & SET_BIOS_SCRATCH)) - pInt->Flags &= ~RESTORE_BIOS_SCRATCH; - xf86Int10SaveRestoreBIOSVars(pInt, TRUE); + if (!xf86int10GetBiosSegment(pInt, NULL)) + goto error3; + + set_return_trap(pInt); +#ifdef _PC + pInt->Flags = Flags & (SET_BIOS_SCRATCH | RESTORE_BIOS_SCRATCH); + if (!(pInt->Flags & SET_BIOS_SCRATCH)) + pInt->Flags &= ~RESTORE_BIOS_SCRATCH; + xf86Int10SaveRestoreBIOSVars(pInt, TRUE); #endif - } else { - const BusType location_type = xf86int10GetBiosLocationType(pInt); - - switch (location_type) { - case BUS_PCI: { - int err; - struct pci_device *rom_device = - xf86GetPciInfoForEntity(pInt->entityIndex); - - pci_device_enable(rom_device); - err = pci_device_read_rom(rom_device, (unsigned char *)(V_BIOS)); - if (err) { - xf86DrvMsg(screen,X_ERROR,"Cannot read V_BIOS (%s)\n", - strerror(err)); - goto error3; - } - - pInt->BIOSseg = V_BIOS >> 4; - break; - } - default: - goto error3; - } - - pInt->num = 0xe6; - reset_int_vect(pInt); - set_return_trap(pInt); - LockLegacyVGA(pInt, &vga); - xf86ExecX86int10(pInt); - UnlockLegacyVGA(pInt, &vga); + } + else { + const BusType location_type = xf86int10GetBiosLocationType(pInt); + + switch (location_type) { + case BUS_PCI:{ + int err; + struct pci_device *rom_device = + xf86GetPciInfoForEntity(pInt->entityIndex); + + pci_device_enable(rom_device); + err = pci_device_read_rom(rom_device, (unsigned char *) (V_BIOS)); + if (err) { + xf86DrvMsg(screen, X_ERROR, "Cannot read V_BIOS (%s)\n", + strerror(err)); + goto error3; + } + + pInt->BIOSseg = V_BIOS >> 4; + break; + } + default: + goto error3; + } + + pInt->num = 0xe6; + reset_int_vect(pInt); + set_return_trap(pInt); + LockLegacyVGA(pInt, &vga); + xf86ExecX86int10(pInt); + UnlockLegacyVGA(pInt, &vga); } #ifdef DEBUG dprint(0xc0000, 0x20); @@ -290,24 +294,24 @@ xf86ExtendedInitInt10(int entityIndex, int Flags) free(options); return pInt; -error3: + error3: if (base_high) - shmdt(base_high); + shmdt(base_high); shmdt(base); shmdt(0); if (base_high) - shmdt((char*)HIGH_MEM); + shmdt((char *) HIGH_MEM); shmctl(low_mem, IPC_RMID, NULL); Int10Current = NULL; -error2: + error2: if (high_mem > -1) - shmctl(high_mem, IPC_RMID,NULL); -error1: + shmctl(high_mem, IPC_RMID, NULL); + error1: if (vMem) - munmap(vMem, SYS_BIOS - V_BIOS); - free(((linuxInt10Priv*)pInt->private)->alloc); + munmap(vMem, SYS_BIOS - V_BIOS); + free(((linuxInt10Priv *) pInt->private)->alloc); free(pInt->private); -error0: + error0: free(options); free(pInt); return NULL; @@ -318,57 +322,60 @@ MapCurrentInt10(xf86Int10InfoPtr pInt) { pointer addr; int fd = -1; - + if (Int10Current) { - shmdt(0); - if (((linuxInt10Priv*)Int10Current->private)->highMem >= 0) - shmdt((char*)HIGH_MEM); - else - munmap((pointer)V_BIOS, (SYS_BIOS - V_BIOS)); + shmdt(0); + if (((linuxInt10Priv *) Int10Current->private)->highMem >= 0) + shmdt((char *) HIGH_MEM); + else + munmap((pointer) V_BIOS, (SYS_BIOS - V_BIOS)); } - addr = shmat(((linuxInt10Priv*)pInt->private)->lowMem, (char*)1, SHM_RND); + addr = + shmat(((linuxInt10Priv *) pInt->private)->lowMem, (char *) 1, SHM_RND); if (addr == SHMERRORPTR) { - xf86DrvMsg(pInt->scrnIndex, X_ERROR, "Cannot shmat() low memory\n"); - xf86DrvMsg(pInt->scrnIndex, X_ERROR, - "shmat(low_mem) error: %s\n",strerror(errno)); - return FALSE; + xf86DrvMsg(pInt->scrnIndex, X_ERROR, "Cannot shmat() low memory\n"); + xf86DrvMsg(pInt->scrnIndex, X_ERROR, + "shmat(low_mem) error: %s\n", strerror(errno)); + return FALSE; } - if (mprotect((void*)0, V_RAM, PROT_READ|PROT_WRITE|PROT_EXEC) != 0) + if (mprotect((void *) 0, V_RAM, PROT_READ | PROT_WRITE | PROT_EXEC) != 0) xf86DrvMsg(pInt->scrnIndex, X_ERROR, - "Cannot set EXEC bit on low memory: %s\n", strerror(errno)); - - if (((linuxInt10Priv*)pInt->private)->highMem >= 0) { - addr = shmat(((linuxInt10Priv*)pInt->private)->highMem, - (char*)HIGH_MEM, 0); - if (addr == SHMERRORPTR) { - xf86DrvMsg(pInt->scrnIndex, X_ERROR, - "Cannot shmat() high memory\n"); - xf86DrvMsg(pInt->scrnIndex, X_ERROR, - "shmget error: %s\n",strerror(errno)); - return FALSE; - } - if (mprotect((void*)HIGH_MEM, HIGH_MEM_SIZE, - PROT_READ|PROT_WRITE|PROT_EXEC) != 0) - xf86DrvMsg(pInt->scrnIndex, X_ERROR, - "Cannot set EXEC bit on high memory: %s\n", - strerror(errno)); - } else { - if ((fd = open(DEV_MEM, O_RDWR, 0)) >= 0) { - if (mmap((void *)(V_BIOS), SYS_BIOS - V_BIOS, - PROT_READ | PROT_WRITE | PROT_EXEC, - MAP_SHARED | MAP_FIXED, fd, V_BIOS) - == MAP_FAILED) { - xf86DrvMsg(pInt->scrnIndex, X_ERROR, "Cannot map V_BIOS\n"); - close (fd); - return FALSE; - } - } else { - xf86DrvMsg(pInt->scrnIndex, X_ERROR, "Cannot open %s\n",DEV_MEM); - return FALSE; - } - close (fd); + "Cannot set EXEC bit on low memory: %s\n", strerror(errno)); + + if (((linuxInt10Priv *) pInt->private)->highMem >= 0) { + addr = shmat(((linuxInt10Priv *) pInt->private)->highMem, + (char *) HIGH_MEM, 0); + if (addr == SHMERRORPTR) { + xf86DrvMsg(pInt->scrnIndex, X_ERROR, + "Cannot shmat() high memory\n"); + xf86DrvMsg(pInt->scrnIndex, X_ERROR, + "shmget error: %s\n", strerror(errno)); + return FALSE; + } + if (mprotect((void *) HIGH_MEM, HIGH_MEM_SIZE, + PROT_READ | PROT_WRITE | PROT_EXEC) != 0) + xf86DrvMsg(pInt->scrnIndex, X_ERROR, + "Cannot set EXEC bit on high memory: %s\n", + strerror(errno)); } - + else { + if ((fd = open(DEV_MEM, O_RDWR, 0)) >= 0) { + if (mmap((void *) (V_BIOS), SYS_BIOS - V_BIOS, + PROT_READ | PROT_WRITE | PROT_EXEC, + MAP_SHARED | MAP_FIXED, fd, V_BIOS) + == MAP_FAILED) { + xf86DrvMsg(pInt->scrnIndex, X_ERROR, "Cannot map V_BIOS\n"); + close(fd); + return FALSE; + } + } + else { + xf86DrvMsg(pInt->scrnIndex, X_ERROR, "Cannot open %s\n", DEV_MEM); + return FALSE; + } + close(fd); + } + return TRUE; } @@ -376,27 +383,27 @@ void xf86FreeInt10(xf86Int10InfoPtr pInt) { if (!pInt) - return; + return; #ifdef _PC - xf86Int10SaveRestoreBIOSVars(pInt, FALSE); + xf86Int10SaveRestoreBIOSVars(pInt, FALSE); #endif if (Int10Current == pInt) { - shmdt(0); - if (((linuxInt10Priv*)pInt->private)->highMem >= 0) - shmdt((char*)HIGH_MEM); - else - munmap((pointer)V_BIOS, (SYS_BIOS - V_BIOS)); - Int10Current = NULL; + shmdt(0); + if (((linuxInt10Priv *) pInt->private)->highMem >= 0) + shmdt((char *) HIGH_MEM); + else + munmap((pointer) V_BIOS, (SYS_BIOS - V_BIOS)); + Int10Current = NULL; } - - if (((linuxInt10Priv*)pInt->private)->base_high) - shmdt(((linuxInt10Priv*)pInt->private)->base_high); - shmdt(((linuxInt10Priv*)pInt->private)->base); - shmctl(((linuxInt10Priv*)pInt->private)->lowMem, IPC_RMID, NULL); - if (((linuxInt10Priv*)pInt->private)->highMem >= 0) - shmctl(((linuxInt10Priv*)pInt->private)->highMem, IPC_RMID, NULL); - free(((linuxInt10Priv*)pInt->private)->alloc); + + if (((linuxInt10Priv *) pInt->private)->base_high) + shmdt(((linuxInt10Priv *) pInt->private)->base_high); + shmdt(((linuxInt10Priv *) pInt->private)->base); + shmctl(((linuxInt10Priv *) pInt->private)->lowMem, IPC_RMID, NULL); + if (((linuxInt10Priv *) pInt->private)->highMem >= 0) + shmctl(((linuxInt10Priv *) pInt->private)->highMem, IPC_RMID, NULL); + free(((linuxInt10Priv *) pInt->private)->alloc); free(pInt->private); free(pInt); } @@ -409,91 +416,93 @@ xf86Int10AllocPages(xf86Int10InfoPtr pInt, int num, int *off) int i, j; for (i = 0; i < (num_pages - num); i++) { - if (((linuxInt10Priv*)pInt->private)->alloc[i] == 0) { - for (j = i; j < (num + i); j++) - if ((((linuxInt10Priv*)pInt->private)->alloc[j] != 0)) - break; - if (j == (num + i)) - break; - else - i = i + num; - } + if (((linuxInt10Priv *) pInt->private)->alloc[i] == 0) { + for (j = i; j < (num + i); j++) + if ((((linuxInt10Priv *) pInt->private)->alloc[j] != 0)) + break; + if (j == (num + i)) + break; + else + i = i + num; + } } if (i == (num_pages - num)) - return NULL; + return NULL; for (j = i; j < (i + num); j++) - ((linuxInt10Priv*)pInt->private)->alloc[j] = 1; + ((linuxInt10Priv *) pInt->private)->alloc[j] = 1; *off = (i + 1) * pagesize; - return ((linuxInt10Priv*)pInt->private)->base + ((i + 1) * pagesize); + return ((linuxInt10Priv *) pInt->private)->base + ((i + 1) * pagesize); } void xf86Int10FreePages(xf86Int10InfoPtr pInt, void *pbase, int num) { int pagesize = getpagesize(); - int first = (((unsigned long)pbase - - (unsigned long)((linuxInt10Priv*)pInt->private)->base) - / pagesize) - 1; + int first = (((unsigned long) pbase + - (unsigned long) ((linuxInt10Priv *) pInt->private)->base) + / pagesize) - 1; int i; for (i = first; i < (first + num); i++) - ((linuxInt10Priv*)pInt->private)->alloc[i] = 0; + ((linuxInt10Priv *) pInt->private)->alloc[i] = 0; } static CARD8 read_b(xf86Int10InfoPtr pInt, int addr) { - return *((CARD8 *)(memType)addr); + return *((CARD8 *) (memType) addr); } static CARD16 read_w(xf86Int10InfoPtr pInt, int addr) { - return *((CARD16 *)(memType)addr); + return *((CARD16 *) (memType) addr); } static CARD32 read_l(xf86Int10InfoPtr pInt, int addr) { - return *((CARD32 *)(memType)addr); + return *((CARD32 *) (memType) addr); } static void write_b(xf86Int10InfoPtr pInt, int addr, CARD8 val) { - *((CARD8 *)(memType)addr) = val; + *((CARD8 *) (memType) addr) = val; } static void write_w(xf86Int10InfoPtr pInt, int addr, CARD16 val) { - *((CARD16 *)(memType)addr) = val; + *((CARD16 *) (memType) addr) = val; } static -void write_l(xf86Int10InfoPtr pInt, int addr, CARD32 val) + void +write_l(xf86Int10InfoPtr pInt, int addr, CARD32 val) { - *((CARD32 *)(memType) addr) = val; + *((CARD32 *) (memType) addr) = val; } pointer xf86int10Addr(xf86Int10InfoPtr pInt, CARD32 addr) { if (addr < V_RAM) - return ((linuxInt10Priv*)pInt->private)->base + addr; + return ((linuxInt10Priv *) pInt->private)->base + addr; else if (addr < V_BIOS) - return (pointer)(memType)addr; + return (pointer) (memType) addr; else if (addr < SYS_BIOS) { - if (((linuxInt10Priv*)pInt->private)->base_high) - return (pointer)(((linuxInt10Priv*)pInt->private)->base_high - - V_BIOS + addr); - else - return (pointer) (memType)addr; - } else - return (pointer) (memType)addr; + if (((linuxInt10Priv *) pInt->private)->base_high) + return (pointer) (((linuxInt10Priv *) pInt->private)->base_high + - V_BIOS + addr); + else + return (pointer) (memType) addr; + } + else + return (pointer) (memType) addr; } #if defined DoSubModules @@ -507,20 +516,17 @@ vm86_tst(void) /* When compiling with -fPIC, we can't use asm constraint "b" because %ebx is already taken by gcc. */ __asm__ __volatile__("pushl %%ebx\n\t" - "movl %2,%%ebx\n\t" - "movl %1,%%eax\n\t" - "int $0x80\n\t" - "popl %%ebx" - :"=a" (__res) - :"n" ((int)113), "r" (NULL)); + "movl %2,%%ebx\n\t" + "movl %1,%%eax\n\t" + "int $0x80\n\t" "popl %%ebx":"=a"(__res) + :"n"((int) 113), "r"(NULL)); #else - __asm__ __volatile__("int $0x80\n\t" - :"=a" (__res):"a" ((int)113), - "b" ((struct vm86_struct *)NULL)); + __asm__ __volatile__("int $0x80\n\t":"=a"(__res):"a"((int) 113), + "b"((struct vm86_struct *) NULL)); #endif - if (__res < 0 && __res == -ENOSYS) - return FALSE; + if (__res < 0 && __res == -ENOSYS) + return FALSE; return TRUE; } @@ -529,13 +535,13 @@ static Int10LinuxSubModuleState int10LinuxLoadSubModule(ScrnInfoPtr pScrn) { if (vm86_tst()) { - if (xf86LoadSubModule(pScrn,"vm86")) - return INT10_LOADED_VM86; - } - if (xf86LoadSubModule(pScrn,"x86emu")) - return INT10_LOADED_X86EMU; + if (xf86LoadSubModule(pScrn, "vm86")) + return INT10_LOADED_VM86; + } + if (xf86LoadSubModule(pScrn, "x86emu")) + return INT10_LOADED_X86EMU; return INT10_LOAD_FAILED; } -#endif /* DoSubModules */ +#endif /* DoSubModules */ diff --git a/xorg-server/hw/xfree86/os-support/linux/int10/vm86/linux_vm86.c b/xorg-server/hw/xfree86/os-support/linux/int10/vm86/linux_vm86.c index 34afd9502..8502b21b7 100644 --- a/xorg-server/hw/xfree86/os-support/linux/int10/vm86/linux_vm86.c +++ b/xorg-server/hw/xfree86/os-support/linux/int10/vm86/linux_vm86.c @@ -25,7 +25,7 @@ xf86Int10ExecSetup(xf86Int10InfoPtr pInt) { #define VM86S ((struct vm86_struct *)pInt->cpuRegs) - pInt->cpuRegs = &vm86_s; + pInt->cpuRegs = &vm86_s; VM86S->flags = 0; VM86S->screen_bitmap = 0; VM86S->cpu_type = CPU_586; @@ -58,137 +58,172 @@ vm86_GP_fault(xf86Int10InfoPtr pInt) /* eat up prefixes */ done = 0; do { - switch (MEM_RB(pInt, (int)csp++)) { - case 0x66: /* operand prefix */ prefix66=1; break; - case 0x67: /* address prefix */ prefix67=1; break; - case 0x2e: /* CS */ pref_seg=X86_CS; break; - case 0x3e: /* DS */ pref_seg=X86_DS; break; - case 0x26: /* ES */ pref_seg=X86_ES; break; - case 0x36: /* SS */ pref_seg=X86_SS; break; - case 0x65: /* GS */ pref_seg=X86_GS; break; - case 0x64: /* FS */ pref_seg=X86_FS; break; - case 0xf0: /* lock */ break; - case 0xf2: /* repnz */ - case 0xf3: /* rep */ is_rep=1; break; - default: done=1; - } + switch (MEM_RB(pInt, (int) csp++)) { + case 0x66: /* operand prefix */ + prefix66 = 1; + break; + case 0x67: /* address prefix */ + prefix67 = 1; + break; + case 0x2e: /* CS */ + pref_seg = X86_CS; + break; + case 0x3e: /* DS */ + pref_seg = X86_DS; + break; + case 0x26: /* ES */ + pref_seg = X86_ES; + break; + case 0x36: /* SS */ + pref_seg = X86_SS; + break; + case 0x65: /* GS */ + pref_seg = X86_GS; + break; + case 0x64: /* FS */ + pref_seg = X86_FS; + break; + case 0xf0: /* lock */ + break; + case 0xf2: /* repnz */ + case 0xf3: /* rep */ + is_rep = 1; + break; + default: + done = 1; + } } while (!done); - csp--; /* oops one too many */ + csp--; /* oops one too many */ org_eip = X86_EIP; X86_IP += (csp - lina); - switch (MEM_RB(pInt, (int)csp)) { - case 0x6c: /* insb */ - /* NOTE: ES can't be overwritten; prefixes 66,67 should use esi,edi,ecx - * but is anyone using extended regs in real mode? */ - /* WARNING: no test for DI wrapping! */ - X86_EDI += port_rep_inb(pInt, X86_DX, SEG_EADR((CARD32), X86_ES, DI), - X86_FLAGS & DF, is_rep ? LWECX : 1); - if (is_rep) LWECX_ZERO; - X86_IP++; - break; - - case 0x6d: /* (rep) insw / insd */ - /* NOTE: ES can't be overwritten */ - /* WARNING: no test for _DI wrapping! */ - if (prefix66) { - X86_DI += port_rep_inl(pInt, X86_DX, SEG_ADR((CARD32), X86_ES, DI), - X86_EFLAGS & DF, is_rep ? LWECX : 1); - } - else { - X86_DI += port_rep_inw(pInt, X86_DX, SEG_ADR((CARD32), X86_ES, DI), - X86_FLAGS & DF, is_rep ? LWECX : 1); - } - if (is_rep) LWECX_ZERO; - X86_IP++; - break; - - case 0x6e: /* (rep) outsb */ - if (pref_seg < 0) pref_seg = X86_DS; - /* WARNING: no test for _SI wrapping! */ - X86_SI += port_rep_outb(pInt, X86_DX, (CARD32)LIN_PREF_SI, - X86_FLAGS & DF, is_rep ? LWECX : 1); - if (is_rep) LWECX_ZERO; - X86_IP++; - break; - - case 0x6f: /* (rep) outsw / outsd */ - if (pref_seg < 0) pref_seg = X86_DS; - /* WARNING: no test for _SI wrapping! */ - if (prefix66) { - X86_SI += port_rep_outl(pInt, X86_DX, (CARD32)LIN_PREF_SI, - X86_EFLAGS & DF, is_rep ? LWECX : 1); - } - else { - X86_SI += port_rep_outw(pInt, X86_DX, (CARD32)LIN_PREF_SI, - X86_FLAGS & DF, is_rep ? LWECX : 1); - } - if (is_rep) LWECX_ZERO; - X86_IP++; - break; - - case 0xe5: /* inw xx, inl xx */ - if (prefix66) X86_EAX = x_inl(csp[1]); - else X86_AX = x_inw(csp[1]); - X86_IP += 2; - break; - - case 0xe4: /* inb xx */ - X86_AL = x_inb(csp[1]); - X86_IP += 2; - break; - - case 0xed: /* inw dx, inl dx */ - if (prefix66) X86_EAX = x_inl(X86_DX); - else X86_AX = x_inw(X86_DX); - X86_IP += 1; - break; - - case 0xec: /* inb dx */ - X86_AL = x_inb(X86_DX); - X86_IP += 1; - break; - - case 0xe7: /* outw xx */ - if (prefix66) x_outl(csp[1], X86_EAX); - else x_outw(csp[1], X86_AX); - X86_IP += 2; - break; - - case 0xe6: /* outb xx */ - x_outb(csp[1], X86_AL); - X86_IP += 2; - break; - - case 0xef: /* outw dx */ - if (prefix66) x_outl(X86_DX, X86_EAX); - else x_outw(X86_DX, X86_AX); - X86_IP += 1; - break; - - case 0xee: /* outb dx */ - x_outb(X86_DX, X86_AL); - X86_IP += 1; - break; + switch (MEM_RB(pInt, (int) csp)) { + case 0x6c: /* insb */ + /* NOTE: ES can't be overwritten; prefixes 66,67 should use esi,edi,ecx + * but is anyone using extended regs in real mode? */ + /* WARNING: no test for DI wrapping! */ + X86_EDI += port_rep_inb(pInt, X86_DX, SEG_EADR((CARD32), X86_ES, DI), + X86_FLAGS & DF, is_rep ? LWECX : 1); + if (is_rep) + LWECX_ZERO; + X86_IP++; + break; + + case 0x6d: /* (rep) insw / insd */ + /* NOTE: ES can't be overwritten */ + /* WARNING: no test for _DI wrapping! */ + if (prefix66) { + X86_DI += port_rep_inl(pInt, X86_DX, SEG_ADR((CARD32), X86_ES, DI), + X86_EFLAGS & DF, is_rep ? LWECX : 1); + } + else { + X86_DI += port_rep_inw(pInt, X86_DX, SEG_ADR((CARD32), X86_ES, DI), + X86_FLAGS & DF, is_rep ? LWECX : 1); + } + if (is_rep) + LWECX_ZERO; + X86_IP++; + break; + + case 0x6e: /* (rep) outsb */ + if (pref_seg < 0) + pref_seg = X86_DS; + /* WARNING: no test for _SI wrapping! */ + X86_SI += port_rep_outb(pInt, X86_DX, (CARD32) LIN_PREF_SI, + X86_FLAGS & DF, is_rep ? LWECX : 1); + if (is_rep) + LWECX_ZERO; + X86_IP++; + break; + + case 0x6f: /* (rep) outsw / outsd */ + if (pref_seg < 0) + pref_seg = X86_DS; + /* WARNING: no test for _SI wrapping! */ + if (prefix66) { + X86_SI += port_rep_outl(pInt, X86_DX, (CARD32) LIN_PREF_SI, + X86_EFLAGS & DF, is_rep ? LWECX : 1); + } + else { + X86_SI += port_rep_outw(pInt, X86_DX, (CARD32) LIN_PREF_SI, + X86_FLAGS & DF, is_rep ? LWECX : 1); + } + if (is_rep) + LWECX_ZERO; + X86_IP++; + break; + + case 0xe5: /* inw xx, inl xx */ + if (prefix66) + X86_EAX = x_inl(csp[1]); + else + X86_AX = x_inw(csp[1]); + X86_IP += 2; + break; + + case 0xe4: /* inb xx */ + X86_AL = x_inb(csp[1]); + X86_IP += 2; + break; + + case 0xed: /* inw dx, inl dx */ + if (prefix66) + X86_EAX = x_inl(X86_DX); + else + X86_AX = x_inw(X86_DX); + X86_IP += 1; + break; + + case 0xec: /* inb dx */ + X86_AL = x_inb(X86_DX); + X86_IP += 1; + break; + + case 0xe7: /* outw xx */ + if (prefix66) + x_outl(csp[1], X86_EAX); + else + x_outw(csp[1], X86_AX); + X86_IP += 2; + break; + + case 0xe6: /* outb xx */ + x_outb(csp[1], X86_AL); + X86_IP += 2; + break; + + case 0xef: /* outw dx */ + if (prefix66) + x_outl(X86_DX, X86_EAX); + else + x_outw(X86_DX, X86_AX); + X86_IP += 1; + break; + + case 0xee: /* outb dx */ + x_outb(X86_DX, X86_AL); + X86_IP += 1; + break; case 0xf4: - DebugF("hlt at %p\n", lina); - return FALSE; + DebugF("hlt at %p\n", lina); + return FALSE; case 0x0f: - xf86DrvMsg(pInt->scrnIndex, X_ERROR, - "CPU 0x0f Trap at CS:EIP=0x%4.4x:0x%8.8lx\n", X86_CS, X86_EIP); - goto op0ferr; + xf86DrvMsg(pInt->scrnIndex, X_ERROR, + "CPU 0x0f Trap at CS:EIP=0x%4.4x:0x%8.8lx\n", X86_CS, + X86_EIP); + goto op0ferr; default: - xf86DrvMsg(pInt->scrnIndex, X_ERROR, "unknown reason for exception\n"); - - op0ferr: - dump_registers(pInt); - stack_trace(pInt); - dump_code(pInt); - xf86DrvMsg(pInt->scrnIndex, X_ERROR, "cannot continue\n"); - return FALSE; + xf86DrvMsg(pInt->scrnIndex, X_ERROR, "unknown reason for exception\n"); + + op0ferr: + dump_registers(pInt); + stack_trace(pInt); + dump_code(pInt); + xf86DrvMsg(pInt->scrnIndex, X_ERROR, "cannot continue\n"); + return FALSE; } /* end of switch() */ return TRUE; } @@ -203,51 +238,52 @@ do_vm86(xf86Int10InfoPtr pInt) xf86InterceptSignals(NULL); if (signo >= 0) { - xf86DrvMsg(pInt->scrnIndex, X_ERROR, - "vm86() syscall generated signal %d.\n", signo); - dump_registers(pInt); - dump_code(pInt); - stack_trace(pInt); - return 0; + xf86DrvMsg(pInt->scrnIndex, X_ERROR, + "vm86() syscall generated signal %d.\n", signo); + dump_registers(pInt); + dump_code(pInt); + stack_trace(pInt); + return 0; } switch (VM86_TYPE(retval)) { case VM86_UNKNOWN: - if (!vm86_GP_fault(pInt)) return 0; - break; + if (!vm86_GP_fault(pInt)) + return 0; + break; case VM86_STI: - xf86DrvMsg(pInt->scrnIndex, X_ERROR, "vm86_sti :-((\n"); - dump_registers(pInt); - dump_code(pInt); - stack_trace(pInt); - return 0; + xf86DrvMsg(pInt->scrnIndex, X_ERROR, "vm86_sti :-((\n"); + dump_registers(pInt); + dump_code(pInt); + stack_trace(pInt); + return 0; case VM86_INTx: - pInt->num = VM86_ARG(retval); - if (!int_handler(pInt)) { - xf86DrvMsg(pInt->scrnIndex, X_ERROR, - "Unknown vm86_int: 0x%X\n\n", VM86_ARG(retval)); - dump_registers(pInt); - dump_code(pInt); - stack_trace(pInt); - return 0; - } - /* I'm not sure yet what to do if we can handle ints */ - break; + pInt->num = VM86_ARG(retval); + if (!int_handler(pInt)) { + xf86DrvMsg(pInt->scrnIndex, X_ERROR, + "Unknown vm86_int: 0x%X\n\n", VM86_ARG(retval)); + dump_registers(pInt); + dump_code(pInt); + stack_trace(pInt); + return 0; + } + /* I'm not sure yet what to do if we can handle ints */ + break; case VM86_SIGNAL: - return 1; - /* - * we used to warn here and bail out - but now the sigio stuff - * always fires signals at us. So we just ignore them for now. - */ - xf86DrvMsg(pInt->scrnIndex, X_WARNING, "received signal\n"); - return 0; + return 1; + /* + * we used to warn here and bail out - but now the sigio stuff + * always fires signals at us. So we just ignore them for now. + */ + xf86DrvMsg(pInt->scrnIndex, X_WARNING, "received signal\n"); + return 0; default: - xf86DrvMsg(pInt->scrnIndex, X_ERROR, "unknown type(0x%x)=0x%x\n", - VM86_ARG(retval), VM86_TYPE(retval)); - dump_registers(pInt); - dump_code(pInt); - stack_trace(pInt); - return 0; + xf86DrvMsg(pInt->scrnIndex, X_ERROR, "unknown type(0x%x)=0x%x\n", + VM86_ARG(retval), VM86_TYPE(retval)); + dump_registers(pInt); + dump_code(pInt); + stack_trace(pInt); + return 0; } return 1; @@ -259,7 +295,8 @@ xf86ExecX86int10(xf86Int10InfoPtr pInt) int sig = setup_int(pInt); if (int_handler(pInt)) - while(do_vm86(pInt)) {}; + while (do_vm86(pInt)) { + }; finish_int(pInt, sig); } @@ -273,28 +310,25 @@ vm86_rep(struct vm86_struct *ptr) /* When compiling with -fPIC, we can't use asm constraint "b" because %ebx is already taken by gcc. */ __asm__ __volatile__("pushl %%ebx\n\t" - "push %%gs\n\t" - "movl %2,%%ebx\n\t" - "movl %1,%%eax\n\t" - "int $0x80\n\t" - "pop %%gs\n\t" - "popl %%ebx" - :"=a" (__res) - :"n" ((int)113), "r" ((struct vm86_struct *)ptr)); + "push %%gs\n\t" + "movl %2,%%ebx\n\t" + "movl %1,%%eax\n\t" + "int $0x80\n\t" "pop %%gs\n\t" "popl %%ebx":"=a"(__res) + :"n"((int) 113), "r"((struct vm86_struct *) ptr)); #else __asm__ __volatile__("push %%gs\n\t" - "int $0x80\n\t" - "pop %%gs" - :"=a" (__res):"a" ((int)113), - "b" ((struct vm86_struct *)ptr)); + "int $0x80\n\t" + "pop %%gs":"=a"(__res):"a"((int) 113), + "b"((struct vm86_struct *) ptr)); #endif - if (__res < 0) { - errno = -__res; - __res = -1; - } - else errno = 0; - return __res; + if (__res < 0) { + errno = -__res; + __res = -1; + } + else + errno = 0; + return __res; } #endif diff --git a/xorg-server/hw/xfree86/os-support/linux/lnx_agp.c b/xorg-server/hw/xfree86/os-support/linux/lnx_agp.c index dcc878060..e1fa3f8a7 100644 --- a/xorg-server/hw/xfree86/os-support/linux/lnx_agp.c +++ b/xorg-server/hw/xfree86/os-support/linux/lnx_agp.c @@ -1,374 +1,371 @@ -/*
- * Abstraction of the AGP GART interface.
- *
- * This version is for Linux and Free/Open/NetBSD.
- *
- * Copyright © 2000 VA Linux Systems, Inc.
- * Copyright © 2001 The XFree86 Project, Inc.
- */
-
-
-#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 "xf86OSpriv.h"
-
-#if defined(linux)
-#include <asm/ioctl.h>
-#include <linux/agpgart.h>
-#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
-#include <sys/ioctl.h>
-#include <sys/agpio.h>
-#endif
-
-#ifndef AGP_DEVICE
-#define AGP_DEVICE "/dev/agpgart"
-#endif
-/* AGP page size is independent of the host page size. */
-#ifndef AGP_PAGE_SIZE
-#define AGP_PAGE_SIZE 4096
-#endif
-#define AGPGART_MAJOR_VERSION 0
-#define AGPGART_MINOR_VERSION 99
-
-static int gartFd = -1;
-static int acquiredScreen = -1;
-static Bool initDone = FALSE;
-/*
- * Close /dev/agpgart. This frees all associated memory allocated during
- * this server generation.
- */
-Bool
-xf86GARTCloseScreen(int screenNum)
-{
- if(gartFd != -1) {
- close(gartFd);
- acquiredScreen = -1;
- gartFd = -1;
- initDone = FALSE;
- }
- return TRUE;
-}
-
-/*
- * Open /dev/agpgart. Keep it open until xf86GARTCloseScreen is called.
- */
-static Bool
-GARTInit(int screenNum)
-{
- struct _agp_info agpinf;
-
- if (initDone)
- return gartFd != -1;
-
- initDone = TRUE;
-
- if (gartFd == -1)
- gartFd = open(AGP_DEVICE, O_RDWR, 0);
- else
- return FALSE;
-
- if (gartFd == -1) {
- xf86DrvMsg(screenNum, X_ERROR,
- "GARTInit: Unable to open " AGP_DEVICE " (%s)\n",
- strerror(errno));
- return FALSE;
- }
-
- xf86AcquireGART(-1);
- /* Check the kernel driver version. */
- if (ioctl(gartFd, AGPIOC_INFO, &agpinf) != 0) {
- xf86DrvMsg(screenNum, X_ERROR,
- "GARTInit: AGPIOC_INFO failed (%s)\n", strerror(errno));
- close(gartFd);
- gartFd = -1;
- return FALSE;
- }
- xf86ReleaseGART(-1);
-
-#if defined(linux)
- /* Per Dave Jones, every effort will be made to keep the
- * agpgart interface backwards compatible, so allow all
- * future versions.
- */
- if (
-#if (AGPGART_MAJOR_VERSION > 0) /* quiet compiler */
- agpinf.version.major < AGPGART_MAJOR_VERSION ||
-#endif
- (agpinf.version.major == AGPGART_MAJOR_VERSION &&
- agpinf.version.minor < AGPGART_MINOR_VERSION)) {
- xf86DrvMsg(screenNum, X_ERROR,
- "GARTInit: Kernel agpgart driver version is not current"
- " (%d.%d vs %d.%d)\n",
- agpinf.version.major, agpinf.version.minor,
- AGPGART_MAJOR_VERSION, AGPGART_MINOR_VERSION);
- close(gartFd);
- gartFd = -1;
- return FALSE;
- }
-#endif
-
- return TRUE;
-}
-
-Bool
-xf86AgpGARTSupported(void)
-{
- return GARTInit(-1);
-}
-
-AgpInfoPtr
-xf86GetAGPInfo(int screenNum)
-{
- struct _agp_info agpinf;
- AgpInfoPtr info;
-
- if (!GARTInit(screenNum))
- return NULL;
-
-
- if ((info = calloc(sizeof(AgpInfo), 1)) == NULL) {
- xf86DrvMsg(screenNum, X_ERROR,
- "xf86GetAGPInfo: Failed to allocate AgpInfo\n");
- return NULL;
- }
-
- memset((char*)&agpinf, 0, sizeof(agpinf));
-
- if (ioctl(gartFd, AGPIOC_INFO, &agpinf) != 0) {
- xf86DrvMsg(screenNum, X_ERROR,
- "xf86GetAGPInfo: AGPIOC_INFO failed (%s)\n",
- strerror(errno));
- return NULL;
- }
-
- info->bridgeId = agpinf.bridge_id;
- info->agpMode = agpinf.agp_mode;
- info->base = agpinf.aper_base;
- info->size = agpinf.aper_size;
- info->totalPages = agpinf.pg_total;
- info->systemPages = agpinf.pg_system;
- info->usedPages = agpinf.pg_used;
-
- xf86DrvMsg(screenNum, X_INFO, "Kernel reported %zu total, %zu used\n", agpinf.pg_total, agpinf.pg_used);
-
- return info;
-}
-
-/*
- * XXX If multiple screens can acquire the GART, should we have a reference
- * count instead of using acquiredScreen?
- */
-
-Bool
-xf86AcquireGART(int screenNum)
-{
- if (screenNum != -1 && !GARTInit(screenNum))
- return FALSE;
-
- if (screenNum == -1 || acquiredScreen != screenNum) {
- if (ioctl(gartFd, AGPIOC_ACQUIRE, 0) != 0) {
- xf86DrvMsg(screenNum, X_WARNING,
- "xf86AcquireGART: AGPIOC_ACQUIRE failed (%s)\n",
- strerror(errno));
- return FALSE;
- }
- acquiredScreen = screenNum;
- }
- return TRUE;
-}
-
-Bool
-xf86ReleaseGART(int screenNum)
-{
- if (screenNum != -1 && !GARTInit(screenNum))
- return FALSE;
-
- if (acquiredScreen == screenNum) {
- /*
- * The FreeBSD agp driver removes allocations on release.
- * The Linux driver doesn't. xf86ReleaseGART() is expected
- * to give up access to the GART, but not to remove any
- * allocations.
- */
-#if !defined(linux)
- if (screenNum == -1)
-#endif
- {
- if (ioctl(gartFd, AGPIOC_RELEASE, 0) != 0) {
- xf86DrvMsg(screenNum, X_WARNING,
- "xf86ReleaseGART: AGPIOC_RELEASE failed (%s)\n",
- strerror(errno));
- return FALSE;
- }
- acquiredScreen = -1;
- }
- return TRUE;
- }
- return FALSE;
-}
-
-int
-xf86AllocateGARTMemory(int screenNum, unsigned long size, int type,
- unsigned long *physical)
-{
- struct _agp_allocate alloc;
- int pages;
-
- /*
- * Allocates "size" bytes of GART memory (rounds up to the next
- * page multiple) or type "type". A handle (key) for the allocated
- * memory is returned. On error, the return value is -1.
- */
-
- if (!GARTInit(screenNum) || acquiredScreen != screenNum)
- return -1;
-
- pages = (size / AGP_PAGE_SIZE);
- if (size % AGP_PAGE_SIZE != 0)
- pages++;
-
- /* XXX check for pages == 0? */
-
- alloc.pg_count = pages;
- alloc.type = type;
-
- if (ioctl(gartFd, AGPIOC_ALLOCATE, &alloc) != 0) {
- xf86DrvMsg(screenNum, X_WARNING, "xf86AllocateGARTMemory: "
- "allocation of %d pages failed\n\t(%s)\n", pages,
- strerror(errno));
- return -1;
- }
-
- if (physical)
- *physical = alloc.physical;
-
- return alloc.key;
-}
-
-Bool
-xf86DeallocateGARTMemory(int screenNum, int key)
-{
- if (!GARTInit(screenNum) || acquiredScreen != screenNum)
- return FALSE;
-
- if (acquiredScreen != screenNum) {
- xf86DrvMsg(screenNum, X_ERROR,
- "xf86UnbindGARTMemory: AGP not acquired by this screen\n");
- return FALSE;
- }
-
-#ifdef __linux__
- if (ioctl(gartFd, AGPIOC_DEALLOCATE, (int *)(uintptr_t)key) != 0) {
-#else
- if (ioctl(gartFd, AGPIOC_DEALLOCATE, &key) != 0) {
-#endif
- xf86DrvMsg(screenNum, X_WARNING,"xf86DeAllocateGARTMemory: "
- "deallocation gart memory with key %d failed\n\t(%s)\n",
- key, strerror(errno));
- return FALSE;
- }
-
- return TRUE;
-}
-
-/* Bind GART memory with "key" at "offset" */
-Bool
-xf86BindGARTMemory(int screenNum, int key, unsigned long offset)
-{
- struct _agp_bind bind;
- int pageOffset;
-
- if (!GARTInit(screenNum) || acquiredScreen != screenNum)
- return FALSE;
-
- if (acquiredScreen != screenNum) {
- xf86DrvMsg(screenNum, X_ERROR,
- "xf86BindGARTMemory: AGP not acquired by this screen\n");
- return FALSE;
- }
-
- if (offset % AGP_PAGE_SIZE != 0) {
- xf86DrvMsg(screenNum, X_WARNING, "xf86BindGARTMemory: "
- "offset (0x%lx) is not page-aligned (%d)\n",
- offset, AGP_PAGE_SIZE);
- return FALSE;
- }
- pageOffset = offset / AGP_PAGE_SIZE;
-
- xf86DrvMsgVerb(screenNum, X_INFO, 3,
- "xf86BindGARTMemory: bind key %d at 0x%08lx "
- "(pgoffset %d)\n", key, offset, pageOffset);
-
- bind.pg_start = pageOffset;
- bind.key = key;
-
- if (ioctl(gartFd, AGPIOC_BIND, &bind) != 0) {
- xf86DrvMsg(screenNum, X_WARNING, "xf86BindGARTMemory: "
- "binding of gart memory with key %d\n"
- "\tat offset 0x%lx failed (%s)\n",
- key, offset, strerror(errno));
- return FALSE;
- }
-
- return TRUE;
-}
-
-
-/* Unbind GART memory with "key" */
-Bool
-xf86UnbindGARTMemory(int screenNum, int key)
-{
- struct _agp_unbind unbind;
-
- if (!GARTInit(screenNum) || acquiredScreen != screenNum)
- return FALSE;
-
- if (acquiredScreen != screenNum) {
- xf86DrvMsg(screenNum, X_ERROR,
- "xf86UnbindGARTMemory: AGP not acquired by this screen\n");
- return FALSE;
- }
-
- unbind.priority = 0;
- unbind.key = key;
-
- if (ioctl(gartFd, AGPIOC_UNBIND, &unbind) != 0) {
- xf86DrvMsg(screenNum, X_WARNING, "xf86UnbindGARTMemory: "
- "unbinding of gart memory with key %d "
- "failed (%s)\n", key, strerror(errno));
- return FALSE;
- }
-
- xf86DrvMsgVerb(screenNum, X_INFO, 3,
- "xf86UnbindGARTMemory: unbind key %d\n", key);
-
- return TRUE;
-}
-
-
-/* XXX Interface may change. */
-Bool
-xf86EnableAGP(int screenNum, CARD32 mode)
-{
- agp_setup setup;
-
- if (!GARTInit(screenNum) || acquiredScreen != screenNum)
- return FALSE;
-
- setup.agp_mode = mode;
- if (ioctl(gartFd, AGPIOC_SETUP, &setup) != 0) {
- xf86DrvMsg(screenNum, X_WARNING, "xf86EnableAGP: "
- "AGPIOC_SETUP with mode %ld failed (%s)\n",
- (unsigned long)mode, strerror(errno));
- return FALSE;
- }
-
- return TRUE;
-}
-
+/* + * Abstraction of the AGP GART interface. + * + * This version is for Linux and Free/Open/NetBSD. + * + * Copyright © 2000 VA Linux Systems, Inc. + * Copyright © 2001 The XFree86 Project, Inc. + */ + +#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 "xf86OSpriv.h" + +#if defined(linux) +#include <asm/ioctl.h> +#include <linux/agpgart.h> +#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) +#include <sys/ioctl.h> +#include <sys/agpio.h> +#endif + +#ifndef AGP_DEVICE +#define AGP_DEVICE "/dev/agpgart" +#endif +/* AGP page size is independent of the host page size. */ +#ifndef AGP_PAGE_SIZE +#define AGP_PAGE_SIZE 4096 +#endif +#define AGPGART_MAJOR_VERSION 0 +#define AGPGART_MINOR_VERSION 99 + +static int gartFd = -1; +static int acquiredScreen = -1; +static Bool initDone = FALSE; + +/* + * Close /dev/agpgart. This frees all associated memory allocated during + * this server generation. + */ +Bool +xf86GARTCloseScreen(int screenNum) +{ + if (gartFd != -1) { + close(gartFd); + acquiredScreen = -1; + gartFd = -1; + initDone = FALSE; + } + return TRUE; +} + +/* + * Open /dev/agpgart. Keep it open until xf86GARTCloseScreen is called. + */ +static Bool +GARTInit(int screenNum) +{ + struct _agp_info agpinf; + + if (initDone) + return gartFd != -1; + + initDone = TRUE; + + if (gartFd == -1) + gartFd = open(AGP_DEVICE, O_RDWR, 0); + else + return FALSE; + + if (gartFd == -1) { + xf86DrvMsg(screenNum, X_ERROR, + "GARTInit: Unable to open " AGP_DEVICE " (%s)\n", + strerror(errno)); + return FALSE; + } + + xf86AcquireGART(-1); + /* Check the kernel driver version. */ + if (ioctl(gartFd, AGPIOC_INFO, &agpinf) != 0) { + xf86DrvMsg(screenNum, X_ERROR, + "GARTInit: AGPIOC_INFO failed (%s)\n", strerror(errno)); + close(gartFd); + gartFd = -1; + return FALSE; + } + xf86ReleaseGART(-1); + +#if defined(linux) + /* Per Dave Jones, every effort will be made to keep the + * agpgart interface backwards compatible, so allow all + * future versions. + */ + if ( +#if (AGPGART_MAJOR_VERSION > 0) /* quiet compiler */ + agpinf.version.major < AGPGART_MAJOR_VERSION || +#endif + (agpinf.version.major == AGPGART_MAJOR_VERSION && + agpinf.version.minor < AGPGART_MINOR_VERSION)) { + xf86DrvMsg(screenNum, X_ERROR, + "GARTInit: Kernel agpgart driver version is not current" + " (%d.%d vs %d.%d)\n", + agpinf.version.major, agpinf.version.minor, + AGPGART_MAJOR_VERSION, AGPGART_MINOR_VERSION); + close(gartFd); + gartFd = -1; + return FALSE; + } +#endif + + return TRUE; +} + +Bool +xf86AgpGARTSupported(void) +{ + return GARTInit(-1); +} + +AgpInfoPtr +xf86GetAGPInfo(int screenNum) +{ + struct _agp_info agpinf; + AgpInfoPtr info; + + if (!GARTInit(screenNum)) + return NULL; + + if ((info = calloc(sizeof(AgpInfo), 1)) == NULL) { + xf86DrvMsg(screenNum, X_ERROR, + "xf86GetAGPInfo: Failed to allocate AgpInfo\n"); + return NULL; + } + + memset((char *) &agpinf, 0, sizeof(agpinf)); + + if (ioctl(gartFd, AGPIOC_INFO, &agpinf) != 0) { + xf86DrvMsg(screenNum, X_ERROR, + "xf86GetAGPInfo: AGPIOC_INFO failed (%s)\n", + strerror(errno)); + return NULL; + } + + info->bridgeId = agpinf.bridge_id; + info->agpMode = agpinf.agp_mode; + info->base = agpinf.aper_base; + info->size = agpinf.aper_size; + info->totalPages = agpinf.pg_total; + info->systemPages = agpinf.pg_system; + info->usedPages = agpinf.pg_used; + + xf86DrvMsg(screenNum, X_INFO, "Kernel reported %zu total, %zu used\n", + agpinf.pg_total, agpinf.pg_used); + + return info; +} + +/* + * XXX If multiple screens can acquire the GART, should we have a reference + * count instead of using acquiredScreen? + */ + +Bool +xf86AcquireGART(int screenNum) +{ + if (screenNum != -1 && !GARTInit(screenNum)) + return FALSE; + + if (screenNum == -1 || acquiredScreen != screenNum) { + if (ioctl(gartFd, AGPIOC_ACQUIRE, 0) != 0) { + xf86DrvMsg(screenNum, X_WARNING, + "xf86AcquireGART: AGPIOC_ACQUIRE failed (%s)\n", + strerror(errno)); + return FALSE; + } + acquiredScreen = screenNum; + } + return TRUE; +} + +Bool +xf86ReleaseGART(int screenNum) +{ + if (screenNum != -1 && !GARTInit(screenNum)) + return FALSE; + + if (acquiredScreen == screenNum) { + /* + * The FreeBSD agp driver removes allocations on release. + * The Linux driver doesn't. xf86ReleaseGART() is expected + * to give up access to the GART, but not to remove any + * allocations. + */ +#if !defined(linux) + if (screenNum == -1) +#endif + { + if (ioctl(gartFd, AGPIOC_RELEASE, 0) != 0) { + xf86DrvMsg(screenNum, X_WARNING, + "xf86ReleaseGART: AGPIOC_RELEASE failed (%s)\n", + strerror(errno)); + return FALSE; + } + acquiredScreen = -1; + } + return TRUE; + } + return FALSE; +} + +int +xf86AllocateGARTMemory(int screenNum, unsigned long size, int type, + unsigned long *physical) +{ + struct _agp_allocate alloc; + int pages; + + /* + * Allocates "size" bytes of GART memory (rounds up to the next + * page multiple) or type "type". A handle (key) for the allocated + * memory is returned. On error, the return value is -1. + */ + + if (!GARTInit(screenNum) || acquiredScreen != screenNum) + return -1; + + pages = (size / AGP_PAGE_SIZE); + if (size % AGP_PAGE_SIZE != 0) + pages++; + + /* XXX check for pages == 0? */ + + alloc.pg_count = pages; + alloc.type = type; + + if (ioctl(gartFd, AGPIOC_ALLOCATE, &alloc) != 0) { + xf86DrvMsg(screenNum, X_WARNING, "xf86AllocateGARTMemory: " + "allocation of %d pages failed\n\t(%s)\n", pages, + strerror(errno)); + return -1; + } + + if (physical) + *physical = alloc.physical; + + return alloc.key; +} + +Bool +xf86DeallocateGARTMemory(int screenNum, int key) +{ + if (!GARTInit(screenNum) || acquiredScreen != screenNum) + return FALSE; + + if (acquiredScreen != screenNum) { + xf86DrvMsg(screenNum, X_ERROR, + "xf86UnbindGARTMemory: AGP not acquired by this screen\n"); + return FALSE; + } + +#ifdef __linux__ + if (ioctl(gartFd, AGPIOC_DEALLOCATE, (int *) (uintptr_t) key) != 0) { +#else + if (ioctl(gartFd, AGPIOC_DEALLOCATE, &key) != 0) { +#endif + xf86DrvMsg(screenNum, X_WARNING, "xf86DeAllocateGARTMemory: " + "deallocation gart memory with key %d failed\n\t(%s)\n", + key, strerror(errno)); + return FALSE; + } + + return TRUE; +} + +/* Bind GART memory with "key" at "offset" */ +Bool +xf86BindGARTMemory(int screenNum, int key, unsigned long offset) +{ + struct _agp_bind bind; + int pageOffset; + + if (!GARTInit(screenNum) || acquiredScreen != screenNum) + return FALSE; + + if (acquiredScreen != screenNum) { + xf86DrvMsg(screenNum, X_ERROR, + "xf86BindGARTMemory: AGP not acquired by this screen\n"); + return FALSE; + } + + if (offset % AGP_PAGE_SIZE != 0) { + xf86DrvMsg(screenNum, X_WARNING, "xf86BindGARTMemory: " + "offset (0x%lx) is not page-aligned (%d)\n", + offset, AGP_PAGE_SIZE); + return FALSE; + } + pageOffset = offset / AGP_PAGE_SIZE; + + xf86DrvMsgVerb(screenNum, X_INFO, 3, + "xf86BindGARTMemory: bind key %d at 0x%08lx " + "(pgoffset %d)\n", key, offset, pageOffset); + + bind.pg_start = pageOffset; + bind.key = key; + + if (ioctl(gartFd, AGPIOC_BIND, &bind) != 0) { + xf86DrvMsg(screenNum, X_WARNING, "xf86BindGARTMemory: " + "binding of gart memory with key %d\n" + "\tat offset 0x%lx failed (%s)\n", + key, offset, strerror(errno)); + return FALSE; + } + + return TRUE; +} + +/* Unbind GART memory with "key" */ +Bool +xf86UnbindGARTMemory(int screenNum, int key) +{ + struct _agp_unbind unbind; + + if (!GARTInit(screenNum) || acquiredScreen != screenNum) + return FALSE; + + if (acquiredScreen != screenNum) { + xf86DrvMsg(screenNum, X_ERROR, + "xf86UnbindGARTMemory: AGP not acquired by this screen\n"); + return FALSE; + } + + unbind.priority = 0; + unbind.key = key; + + if (ioctl(gartFd, AGPIOC_UNBIND, &unbind) != 0) { + xf86DrvMsg(screenNum, X_WARNING, "xf86UnbindGARTMemory: " + "unbinding of gart memory with key %d " + "failed (%s)\n", key, strerror(errno)); + return FALSE; + } + + xf86DrvMsgVerb(screenNum, X_INFO, 3, + "xf86UnbindGARTMemory: unbind key %d\n", key); + + return TRUE; +} + +/* XXX Interface may change. */ +Bool +xf86EnableAGP(int screenNum, CARD32 mode) +{ + agp_setup setup; + + if (!GARTInit(screenNum) || acquiredScreen != screenNum) + return FALSE; + + setup.agp_mode = mode; + if (ioctl(gartFd, AGPIOC_SETUP, &setup) != 0) { + xf86DrvMsg(screenNum, X_WARNING, "xf86EnableAGP: " + "AGPIOC_SETUP with mode %ld failed (%s)\n", + (unsigned long) mode, strerror(errno)); + return FALSE; + } + + return TRUE; +} diff --git a/xorg-server/hw/xfree86/os-support/linux/lnx_apm.c b/xorg-server/hw/xfree86/os-support/linux/lnx_apm.c index 54c698965..a37331e52 100644 --- a/xorg-server/hw/xfree86/os-support/linux/lnx_apm.c +++ b/xorg-server/hw/xfree86/os-support/linux/lnx_apm.c @@ -23,15 +23,15 @@ extern PMClose lnxACPIOpen(void); #include <sys/stat.h> #include <fcntl.h> #include <errno.h> - + #define APM_PROC "/proc/apm" #define APM_DEVICE "/dev/apm_bios" #ifndef APM_STANDBY_FAILED -# define APM_STANDBY_FAILED 0xf000 +#define APM_STANDBY_FAILED 0xf000 #endif #ifndef APM_SUSPEND_FAILED -# define APM_SUSPEND_FAILED 0xf001 +#define APM_SUSPEND_FAILED 0xf001 #endif static PMClose lnxAPMOpen(void); @@ -42,23 +42,26 @@ static struct { apm_event_t apmLinux; pmEvent xf86; } LinuxToXF86[] = { - { APM_SYS_STANDBY, XF86_APM_SYS_STANDBY }, - { APM_SYS_SUSPEND, XF86_APM_SYS_SUSPEND }, - { APM_NORMAL_RESUME, XF86_APM_NORMAL_RESUME }, - { APM_CRITICAL_RESUME, XF86_APM_CRITICAL_RESUME }, - { APM_LOW_BATTERY, XF86_APM_LOW_BATTERY }, - { APM_POWER_STATUS_CHANGE, XF86_APM_POWER_STATUS_CHANGE }, - { APM_UPDATE_TIME, XF86_APM_UPDATE_TIME }, - { APM_CRITICAL_SUSPEND, XF86_APM_CRITICAL_SUSPEND }, - { APM_USER_STANDBY, XF86_APM_USER_STANDBY }, - { APM_USER_SUSPEND, XF86_APM_USER_SUSPEND }, - { APM_STANDBY_RESUME, XF86_APM_STANDBY_RESUME }, + { + APM_SYS_STANDBY, XF86_APM_SYS_STANDBY}, { + APM_SYS_SUSPEND, XF86_APM_SYS_SUSPEND}, { + APM_NORMAL_RESUME, XF86_APM_NORMAL_RESUME}, { + APM_CRITICAL_RESUME, XF86_APM_CRITICAL_RESUME}, { + APM_LOW_BATTERY, XF86_APM_LOW_BATTERY}, { + APM_POWER_STATUS_CHANGE, XF86_APM_POWER_STATUS_CHANGE}, { + APM_UPDATE_TIME, XF86_APM_UPDATE_TIME}, { + APM_CRITICAL_SUSPEND, XF86_APM_CRITICAL_SUSPEND}, { + APM_USER_STANDBY, XF86_APM_USER_STANDBY}, { + APM_USER_SUSPEND, XF86_APM_USER_SUSPEND}, { + APM_STANDBY_RESUME, XF86_APM_STANDBY_RESUME}, #if defined(APM_CAPABILITY_CHANGED) - { APM_CAPABILITY_CHANGED, XF86_CAPABILITY_CHANGED }, + { + APM_CAPABILITY_CHANGED, XF86_CAPABILITY_CHANGED}, #endif #if 0 - { APM_STANDBY_FAILED, XF86_APM_STANDBY_FAILED }, - { APM_SUSPEND_FAILED, XF86_APM_SUSPEND_FAILED } + { + APM_STANDBY_FAILED, XF86_APM_STANDBY_FAILED}, { + APM_SUSPEND_FAILED, XF86_APM_SUSPEND_FAILED} #endif }; @@ -73,24 +76,24 @@ static struct { * event is reasonable. */ static int -lnxPMGetEventFromOs(int fd, pmEvent *events, int num) +lnxPMGetEventFromOs(int fd, pmEvent * events, int num) { - int i,j,n; + int i, j, n; apm_event_t linuxEvents[8]; - if ((n = read( fd, linuxEvents, num * sizeof(apm_event_t) )) == -1) - return 0; + if ((n = read(fd, linuxEvents, num * sizeof(apm_event_t))) == -1) + return 0; n /= sizeof(apm_event_t); if (n > num) - n = num; + n = num; for (i = 0; i < n; i++) { - for (j = 0; j < numApmEvents; j++) - if (LinuxToXF86[j].apmLinux == linuxEvents[i]) { - events[i] = LinuxToXF86[j].xf86; - break; - } - if (j == numApmEvents) - events[i] = XF86_APM_UNKNOWN; + for (j = 0; j < numApmEvents; j++) + if (LinuxToXF86[j].apmLinux == linuxEvents[i]) { + events[i] = LinuxToXF86[j].xf86; + break; + } + if (j == numApmEvents) + events[i] = XF86_APM_UNKNOWN; } return n; } @@ -101,55 +104,55 @@ lnxPMConfirmEventToOs(int fd, pmEvent event) switch (event) { case XF86_APM_SYS_STANDBY: case XF86_APM_USER_STANDBY: - if (ioctl( fd, APM_IOC_STANDBY, NULL )) - return PM_FAILED; - return PM_CONTINUE; + if (ioctl(fd, APM_IOC_STANDBY, NULL)) + return PM_FAILED; + return PM_CONTINUE; case XF86_APM_SYS_SUSPEND: 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 - return PM_FAILED; - } - return PM_CONTINUE; + 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 + return PM_FAILED; + } + return PM_CONTINUE; case XF86_APM_STANDBY_RESUME: case XF86_APM_NORMAL_RESUME: case XF86_APM_CRITICAL_RESUME: case XF86_APM_STANDBY_FAILED: case XF86_APM_SUSPEND_FAILED: - return PM_CONTINUE; + return PM_CONTINUE; default: - return PM_NONE; + return PM_NONE; } } -#endif // HAVE_APM +#endif // HAVE_APM PMClose xf86OSPMOpen(void) { - PMClose ret = NULL; + PMClose ret = NULL; #ifdef HAVE_ACPI - /* Favour ACPI over APM, but only when enabled */ + /* Favour ACPI over APM, but only when enabled */ - if (!xf86acpiDisableFlag) - ret = lnxACPIOpen(); + if (!xf86acpiDisableFlag) + ret = lnxACPIOpen(); - if (!ret) + if (!ret) #endif #ifdef HAVE_APM - ret = lnxAPMOpen(); + ret = lnxAPMOpen(); #endif - return ret; + return ret; } #ifdef HAVE_APM @@ -157,27 +160,27 @@ xf86OSPMOpen(void) static PMClose lnxAPMOpen(void) { - int fd, pfd; + int fd, pfd; DebugF("APM: OSPMOpen called\n"); if (APMihPtr || !xf86Info.pmFlag) - return NULL; - + return NULL; + DebugF("APM: Opening device\n"); - if ((fd = open( APM_DEVICE, O_RDWR )) > -1) { - if (access( APM_PROC, R_OK ) || - ((pfd = open( APM_PROC, O_RDONLY)) == -1)) { - xf86MsgVerb(X_WARNING,3,"Cannot open APM (%s) (%s)\n", - APM_PROC, strerror(errno)); - close(fd); - return NULL; - } else - close(pfd); - xf86PMGetEventFromOs = lnxPMGetEventFromOs; - xf86PMConfirmEventToOs = lnxPMConfirmEventToOs; - APMihPtr = xf86AddGeneralHandler(fd, xf86HandlePMEvents, NULL); - xf86MsgVerb(X_INFO,3,"Open APM successful\n"); - return lnxCloseAPM; + if ((fd = open(APM_DEVICE, O_RDWR)) > -1) { + if (access(APM_PROC, R_OK) || ((pfd = open(APM_PROC, O_RDONLY)) == -1)) { + xf86MsgVerb(X_WARNING, 3, "Cannot open APM (%s) (%s)\n", + APM_PROC, strerror(errno)); + close(fd); + return NULL; + } + else + close(pfd); + xf86PMGetEventFromOs = lnxPMGetEventFromOs; + xf86PMConfirmEventToOs = lnxPMConfirmEventToOs; + APMihPtr = xf86AddGeneralHandler(fd, xf86HandlePMEvents, NULL); + xf86MsgVerb(X_INFO, 3, "Open APM successful\n"); + return lnxCloseAPM; } return NULL; } @@ -189,10 +192,10 @@ lnxCloseAPM(void) DebugF("APM: Closing device\n"); if (APMihPtr) { - fd = xf86RemoveGeneralHandler(APMihPtr); - close(fd); - APMihPtr = NULL; + fd = xf86RemoveGeneralHandler(APMihPtr); + close(fd); + APMihPtr = NULL; } } -#endif // HAVE_APM +#endif // HAVE_APM diff --git a/xorg-server/hw/xfree86/os-support/linux/lnx_axp.c b/xorg-server/hw/xfree86/os-support/linux/lnx_axp.c index 10fd9e865..d65a3a487 100644 --- a/xorg-server/hw/xfree86/os-support/linux/lnx_axp.c +++ b/xorg-server/hw/xfree86/os-support/linux/lnx_axp.c @@ -9,93 +9,95 @@ axpDevice lnxGetAXP(void); -typedef struct - { char* sysName; - char* sysVari; - char* cpu; - axpDevice sys; } -AXP; +typedef struct { + char *sysName; + char *sysVari; + char *cpu; + axpDevice sys; +} AXP; static AXP axpList[] = { - { "Tsunami", NULL, NULL, TSUNAMI }, - { "Eiger", NULL, NULL, TSUNAMI }, - {"Noname", NULL, NULL, LCA }, - { "AlphaBook1", NULL, NULL, LCA }, - {"EB66", NULL, NULL, LCA}, - {"EB64+",NULL,NULL, APECS}, - {"Noritake",NULL,"EV5",CIA}, - {"Noritake",NULL,"EV56",CIA}, - {"Noritake",NULL,NULL,APECS}, - {"XL",NULL,NULL,APECS}, - {"Avanti",NULL,NULL,APECS}, - {"Mikasa",NULL,"EV5",CIA}, - {"Mikasa",NULL,"EV56",CIA}, - {"Mikasa",NULL,NULL,APECS}, - {"EB164","EB164",NULL,CIA}, - {"EB164","PC164", NULL,CIA}, - {"EB164","LX164",NULL, PYXIS}, - {"EB164","SX164",NULL, PYXIS}, - {"EB164","RX164",NULL, POLARIS}, - {"Alcor",NULL,NULL,CIA}, - {"Takara",NULL,NULL,CIA}, - {"Sable",NULL, "EV5",T2_GAMMA}, - {"Sable",NULL,"EV56",T2_GAMMA}, - {"Sable",NULL,NULL,T2}, - {"Rawhide",NULL,NULL,MCPCIA}, - {"Jensen",NULL,NULL,JENSEN}, - {"Miata",NULL,NULL,PYXIS_CIA}, - {"Ruffian",NULL,NULL,PYXIS_CIA}, - {"Nautilus",NULL,NULL,IRONGATE}, - {NULL,NULL,NULL,SYS_NONE} + {"Tsunami", NULL, NULL, TSUNAMI}, + {"Eiger", NULL, NULL, TSUNAMI}, + {"Noname", NULL, NULL, LCA}, + {"AlphaBook1", NULL, NULL, LCA}, + {"EB66", NULL, NULL, LCA}, + {"EB64+", NULL, NULL, APECS}, + {"Noritake", NULL, "EV5", CIA}, + {"Noritake", NULL, "EV56", CIA}, + {"Noritake", NULL, NULL, APECS}, + {"XL", NULL, NULL, APECS}, + {"Avanti", NULL, NULL, APECS}, + {"Mikasa", NULL, "EV5", CIA}, + {"Mikasa", NULL, "EV56", CIA}, + {"Mikasa", NULL, NULL, APECS}, + {"EB164", "EB164", NULL, CIA}, + {"EB164", "PC164", NULL, CIA}, + {"EB164", "LX164", NULL, PYXIS}, + {"EB164", "SX164", NULL, PYXIS}, + {"EB164", "RX164", NULL, POLARIS}, + {"Alcor", NULL, NULL, CIA}, + {"Takara", NULL, NULL, CIA}, + {"Sable", NULL, "EV5", T2_GAMMA}, + {"Sable", NULL, "EV56", T2_GAMMA}, + {"Sable", NULL, NULL, T2}, + {"Rawhide", NULL, NULL, MCPCIA}, + {"Jensen", NULL, NULL, JENSEN}, + {"Miata", NULL, NULL, PYXIS_CIA}, + {"Ruffian", NULL, NULL, PYXIS_CIA}, + {"Nautilus", NULL, NULL, IRONGATE}, + {NULL, NULL, NULL, SYS_NONE} }; - axpDevice lnxGetAXP(void) { - FILE *file; - int count = 0; - char res[256]; - char cpu[255]; - char systype[255]; - char sysvari[255]; - if (!(file = fopen("/proc/cpuinfo","r"))) - return SYS_NONE; - do { - if (!fgets(res,0xff,file)) return SYS_NONE; - switch (count) { - case 1: - sscanf(res, "cpu model : %s",cpu); - DebugF("CPU %s\n",cpu); - break; - case 5: - sscanf(res, "system type : %s",systype); - DebugF("system type : %s\n",systype); - break; - case 6: - sscanf(res, "system variation : %s",sysvari); - DebugF("system variation: %s\n",sysvari); - break; - } - count++; - } while (count < 8); - - fclose(file); - - count = 0; - - do { - if (!axpList[count].sysName || !strcmp(axpList[count].sysName,systype)) { - if (axpList[count].sysVari && strcmp(axpList[count].sysVari,sysvari)) { - count++; - continue; - }; - if (axpList[count].cpu && strcmp(axpList[count].cpu,cpu)) { - count++; - continue; - } - return axpList[count].sys; - } - count++; - } while (1); + FILE *file; + int count = 0; + char res[256]; + char cpu[255]; + char systype[255]; + char sysvari[255]; + + if (!(file = fopen("/proc/cpuinfo", "r"))) + return SYS_NONE; + do { + if (!fgets(res, 0xff, file)) + return SYS_NONE; + switch (count) { + case 1: + sscanf(res, "cpu model : %s", cpu); + DebugF("CPU %s\n", cpu); + break; + case 5: + sscanf(res, "system type : %s", systype); + DebugF("system type : %s\n", systype); + break; + case 6: + sscanf(res, "system variation : %s", sysvari); + DebugF("system variation: %s\n", sysvari); + break; + } + count++; + } while (count < 8); + + fclose(file); + + count = 0; + + do { + if (!axpList[count].sysName || !strcmp(axpList[count].sysName, systype)) { + if (axpList[count].sysVari && + strcmp(axpList[count].sysVari, sysvari)) { + count++; + continue; + }; + if (axpList[count].cpu && strcmp(axpList[count].cpu, cpu)) { + count++; + continue; + } + return axpList[count].sys; + } + count++; + } while (1); } diff --git a/xorg-server/hw/xfree86/os-support/linux/lnx_init.c b/xorg-server/hw/xfree86/os-support/linux/lnx_init.c index 2176985f9..68c296b0f 100644 --- a/xorg-server/hw/xfree86/os-support/linux/lnx_init.c +++ b/xorg-server/hw/xfree86/os-support/linux/lnx_init.c @@ -43,7 +43,7 @@ static int activeVT = -1; static char vtname[11]; static struct termios tty_attr; /* tty state to restore */ -static int tty_mode; /* kbd mode to restore */ +static int tty_mode; /* kbd mode to restore */ static void drain_console(int fd, void *closure) @@ -61,11 +61,11 @@ switch_to(int vt, const char *from) SYSCALL(ret = ioctl(xf86Info.consoleFd, VT_ACTIVATE, vt)); if (ret < 0) - FatalError("%s: VT_ACTIVATE failed: %s\n", from, strerror(errno)); + FatalError("%s: VT_ACTIVATE failed: %s\n", from, strerror(errno)); SYSCALL(ret = ioctl(xf86Info.consoleFd, VT_WAITACTIVE, vt)); if (ret < 0) - FatalError("%s: VT_WAITACTIVE failed: %s\n", from, strerror(errno)); + FatalError("%s: VT_WAITACTIVE failed: %s\n", from, strerror(errno)); } void @@ -80,171 +80,169 @@ xf86OpenConsole(void) if (serverGeneration == 1) { - /* when KeepTty check if we're run with euid==0 */ - if (KeepTty && geteuid() != 0) - FatalError("xf86OpenConsole:" - " Server must be suid root for option \"KeepTTY\"\n"); - - /* - * setup the virtual terminal manager - */ - if (xf86Info.vtno != -1) { - from = X_CMDLINE; - } else { - - i=0; - while (tty0[i] != NULL) { - if ((fd = open(tty0[i],O_WRONLY,0)) >= 0) - break; - i++; - } - - if (fd < 0) - FatalError( - "xf86OpenConsole: Cannot open /dev/tty0 (%s)\n", - strerror(errno)); - - if (xf86Info.ShareVTs) - { - SYSCALL(ret = ioctl(fd, VT_GETSTATE, &vts)); - if (ret < 0) - FatalError("xf86OpenConsole: Cannot find the current" - " VT (%s)\n", strerror(errno)); + /* when KeepTty check if we're run with euid==0 */ + if (KeepTty && geteuid() != 0) + FatalError("xf86OpenConsole:" + " Server must be suid root for option \"KeepTTY\"\n"); + + /* + * setup the virtual terminal manager + */ + if (xf86Info.vtno != -1) { + from = X_CMDLINE; + } + else { + + i = 0; + while (tty0[i] != NULL) { + if ((fd = open(tty0[i], O_WRONLY, 0)) >= 0) + break; + i++; + } + + if (fd < 0) + FatalError("xf86OpenConsole: Cannot open /dev/tty0 (%s)\n", + strerror(errno)); + + if (xf86Info.ShareVTs) { + SYSCALL(ret = ioctl(fd, VT_GETSTATE, &vts)); + if (ret < 0) + FatalError("xf86OpenConsole: Cannot find the current" + " VT (%s)\n", strerror(errno)); xf86Info.vtno = vts.v_active; - } else { - SYSCALL(ret = ioctl(fd, VT_OPENQRY, &xf86Info.vtno)); - if (ret < 0) - FatalError("xf86OpenConsole: Cannot find a free VT: " - "%s\n", strerror(errno)); - if (xf86Info.vtno == -1) - FatalError("xf86OpenConsole: Cannot find a free VT\n"); - } - close(fd); - } - - xf86Msg(from, "using VT number %d\n\n", xf86Info.vtno); - - if (!KeepTty) { - pid_t ppid = getppid(); - pid_t ppgid; - ppgid = getpgid(ppid); - - /* - * change to parent process group that pgid != pid so - * that setsid() doesn't fail and we become process - * group leader - */ - if (setpgid(0,ppgid) < 0) - xf86Msg(X_WARNING, "xf86OpenConsole: setpgid failed: %s\n", - strerror(errno)); - - /* become process group leader */ - if ((setsid() < 0)) - xf86Msg(X_WARNING, "xf86OpenConsole: setsid failed: %s\n", - strerror(errno)); - } - - i=0; + } + else { + SYSCALL(ret = ioctl(fd, VT_OPENQRY, &xf86Info.vtno)); + if (ret < 0) + FatalError("xf86OpenConsole: Cannot find a free VT: " + "%s\n", strerror(errno)); + if (xf86Info.vtno == -1) + FatalError("xf86OpenConsole: Cannot find a free VT\n"); + } + close(fd); + } + + xf86Msg(from, "using VT number %d\n\n", xf86Info.vtno); + + if (!KeepTty) { + pid_t ppid = getppid(); + pid_t ppgid; + + ppgid = getpgid(ppid); + + /* + * change to parent process group that pgid != pid so + * that setsid() doesn't fail and we become process + * group leader + */ + if (setpgid(0, ppgid) < 0) + xf86Msg(X_WARNING, "xf86OpenConsole: setpgid failed: %s\n", + strerror(errno)); + + /* become process group leader */ + if ((setsid() < 0)) + xf86Msg(X_WARNING, "xf86OpenConsole: setsid failed: %s\n", + strerror(errno)); + } + + i = 0; while (vcs[i] != NULL) { - snprintf(vtname, sizeof(vtname), vcs[i], xf86Info.vtno); /* /dev/tty1-64 */ - if ((xf86Info.consoleFd = open(vtname, O_RDWR|O_NDELAY, 0)) >= 0) - break; + snprintf(vtname, sizeof(vtname), vcs[i], xf86Info.vtno); /* /dev/tty1-64 */ + if ((xf86Info.consoleFd = open(vtname, O_RDWR | O_NDELAY, 0)) >= 0) + break; i++; } - if (xf86Info.consoleFd < 0) - FatalError("xf86OpenConsole: Cannot open virtual console" - " %d (%s)\n", xf86Info.vtno, strerror(errno)); - - /* - * Linux doesn't switch to an active vt after the last close of a vt, - * so we do this ourselves by remembering which is active now. - */ - SYSCALL(ret = ioctl(xf86Info.consoleFd, VT_GETSTATE, &vts)); - if (ret < 0) - xf86Msg(X_WARNING,"xf86OpenConsole: VT_GETSTATE failed: %s\n", - strerror(errno)); - else - activeVT = vts.v_active; + if (xf86Info.consoleFd < 0) + FatalError("xf86OpenConsole: Cannot open virtual console" + " %d (%s)\n", xf86Info.vtno, strerror(errno)); + + /* + * Linux doesn't switch to an active vt after the last close of a vt, + * so we do this ourselves by remembering which is active now. + */ + SYSCALL(ret = ioctl(xf86Info.consoleFd, VT_GETSTATE, &vts)); + if (ret < 0) + xf86Msg(X_WARNING, "xf86OpenConsole: VT_GETSTATE failed: %s\n", + strerror(errno)); + else + activeVT = vts.v_active; #if 0 - if (!KeepTty) { - /* - * Detach from the controlling tty to avoid char loss - */ - if ((i = open("/dev/tty",O_RDWR)) >= 0) { - SYSCALL(ioctl(i, TIOCNOTTY, 0)); - close(i); - } - } + if (!KeepTty) { + /* + * Detach from the controlling tty to avoid char loss + */ + if ((i = open("/dev/tty", O_RDWR)) >= 0) { + SYSCALL(ioctl(i, TIOCNOTTY, 0)); + close(i); + } + } #endif - if (!xf86Info.ShareVTs) - { + if (!xf86Info.ShareVTs) { struct termios nTty; - /* - * now get the VT. This _must_ succeed, or else fail completely. - */ + /* + * now get the VT. This _must_ succeed, or else fail completely. + */ switch_to(xf86Info.vtno, "xf86OpenConsole"); - SYSCALL(ret = ioctl(xf86Info.consoleFd, VT_GETMODE, &VT)); - if (ret < 0) - FatalError("xf86OpenConsole: VT_GETMODE failed %s\n", - strerror(errno)); + SYSCALL(ret = ioctl(xf86Info.consoleFd, VT_GETMODE, &VT)); + if (ret < 0) + FatalError("xf86OpenConsole: VT_GETMODE failed %s\n", + strerror(errno)); - signal(SIGUSR1, xf86VTRequest); + signal(SIGUSR1, xf86VTRequest); - VT.mode = VT_PROCESS; - VT.relsig = SIGUSR1; - VT.acqsig = SIGUSR1; + VT.mode = VT_PROCESS; + VT.relsig = SIGUSR1; + VT.acqsig = SIGUSR1; - SYSCALL(ret = ioctl(xf86Info.consoleFd, VT_SETMODE, &VT)); - if (ret < 0) - FatalError("xf86OpenConsole: VT_SETMODE VT_PROCESS failed: %s\n", - strerror(errno)); + SYSCALL(ret = ioctl(xf86Info.consoleFd, VT_SETMODE, &VT)); + if (ret < 0) + FatalError + ("xf86OpenConsole: VT_SETMODE VT_PROCESS failed: %s\n", + strerror(errno)); - SYSCALL(ret = ioctl(xf86Info.consoleFd, KDSETMODE, KD_GRAPHICS)); - if (ret < 0) - FatalError("xf86OpenConsole: KDSETMODE KD_GRAPHICS failed %s\n", - strerror(errno)); + SYSCALL(ret = ioctl(xf86Info.consoleFd, KDSETMODE, KD_GRAPHICS)); + if (ret < 0) + FatalError("xf86OpenConsole: KDSETMODE KD_GRAPHICS failed %s\n", + strerror(errno)); tcgetattr(xf86Info.consoleFd, &tty_attr); - SYSCALL(ioctl(xf86Info.consoleFd, KDGKBMODE, &tty_mode)); + SYSCALL(ioctl(xf86Info.consoleFd, KDGKBMODE, &tty_mode)); #ifdef K_OFF - /* disable kernel special keys and buffering */ - SYSCALL(ret = ioctl(xf86Info.consoleFd, KDSKBMODE, K_OFF)); - if (ret < 0) + /* disable kernel special keys and buffering */ + SYSCALL(ret = ioctl(xf86Info.consoleFd, KDSKBMODE, K_OFF)); + if (ret < 0) #endif - { - SYSCALL(ret = ioctl(xf86Info.consoleFd, KDSKBMODE, K_RAW)); - if (ret < 0) - FatalError("xf86OpenConsole: KDSKBMODE K_RAW failed %s\n", - strerror(errno)); + { + SYSCALL(ret = ioctl(xf86Info.consoleFd, KDSKBMODE, K_RAW)); + if (ret < 0) + FatalError("xf86OpenConsole: KDSKBMODE K_RAW failed %s\n", + strerror(errno)); - /* need to keep the buffer clean, else the kernel gets angry */ - xf86SetConsoleHandler(drain_console, NULL); - } + /* need to keep the buffer clean, else the kernel gets angry */ + xf86SetConsoleHandler(drain_console, NULL); + } nTty = tty_attr; nTty.c_iflag = (IGNPAR | IGNBRK) & (~PARMRK) & (~ISTRIP); nTty.c_oflag = 0; nTty.c_cflag = CREAD | CS8; nTty.c_lflag = 0; - nTty.c_cc[VTIME]=0; - nTty.c_cc[VMIN]=1; + nTty.c_cc[VTIME] = 0; + nTty.c_cc[VMIN] = 1; cfsetispeed(&nTty, 9600); cfsetospeed(&nTty, 9600); tcsetattr(xf86Info.consoleFd, TCSANOW, &nTty); - - /* we really should have a InitOSInputDevices() function instead - * of Init?$#*&Device(). So I just place it here */ } - } else { /* serverGeneration != 1 */ - if (!xf86Info.ShareVTs && xf86Info.autoVTSwitch) - { - /* now get the VT */ + } + else { /* serverGeneration != 1 */ + if (!xf86Info.ShareVTs && xf86Info.autoVTSwitch) { + /* now get the VT */ switch_to(xf86Info.vtno, "xf86OpenConsole"); } } @@ -253,7 +251,7 @@ xf86OpenConsole(void) void xf86CloseConsole(void) { - struct vt_mode VT; + struct vt_mode VT; int ret; if (xf86Info.ShareVTs) { @@ -270,68 +268,64 @@ xf86CloseConsole(void) /* Back to text mode ... */ SYSCALL(ret = ioctl(xf86Info.consoleFd, KDSETMODE, KD_TEXT)); if (ret < 0) - xf86Msg(X_WARNING, "xf86CloseConsole: KDSETMODE failed: %s\n", - strerror(errno)); + xf86Msg(X_WARNING, "xf86CloseConsole: KDSETMODE failed: %s\n", + strerror(errno)); SYSCALL(ioctl(xf86Info.consoleFd, KDSKBMODE, tty_mode)); tcsetattr(xf86Info.consoleFd, TCSANOW, &tty_attr); SYSCALL(ret = ioctl(xf86Info.consoleFd, VT_GETMODE, &VT)); if (ret < 0) - xf86Msg(X_WARNING, "xf86CloseConsole: VT_GETMODE failed: %s\n", - strerror(errno)); + xf86Msg(X_WARNING, "xf86CloseConsole: VT_GETMODE failed: %s\n", + strerror(errno)); else { - /* set dflt vt handling */ - VT.mode = VT_AUTO; - SYSCALL(ret = ioctl(xf86Info.consoleFd, VT_SETMODE, &VT)); - if (ret < 0) - xf86Msg(X_WARNING, "xf86CloseConsole: VT_SETMODE failed: %s\n", - strerror(errno)); + /* set dflt vt handling */ + VT.mode = VT_AUTO; + SYSCALL(ret = ioctl(xf86Info.consoleFd, VT_SETMODE, &VT)); + if (ret < 0) + xf86Msg(X_WARNING, "xf86CloseConsole: VT_SETMODE failed: %s\n", + strerror(errno)); } - if (xf86Info.autoVTSwitch) - { + if (xf86Info.autoVTSwitch) { /* * Perform a switch back to the active VT when we were started */ if (activeVT >= 0) { switch_to(activeVT, "xf86CloseConsole"); - activeVT = -1; + activeVT = -1; } } - close(xf86Info.consoleFd); /* make the vt-manager happy */ + close(xf86Info.consoleFd); /* make the vt-manager happy */ } int xf86ProcessArgument(int argc, char *argv[], int i) { - /* - * Keep server from detaching from controlling tty. This is useful - * when debugging (so the server can receive keyboard signals. - */ - if (!strcmp(argv[i], "-keeptty")) - { - KeepTty = TRUE; - return 1; - } - - if ((argv[i][0] == 'v') && (argv[i][1] == 't')) - { - if (sscanf(argv[i], "vt%2d", &xf86Info.vtno) == 0) - { - UseMsg(); - xf86Info.vtno = -1; - return 0; - } - return 1; - } - return 0; + /* + * Keep server from detaching from controlling tty. This is useful + * when debugging (so the server can receive keyboard signals. + */ + if (!strcmp(argv[i], "-keeptty")) { + KeepTty = TRUE; + return 1; + } + + if ((argv[i][0] == 'v') && (argv[i][1] == 't')) { + if (sscanf(argv[i], "vt%2d", &xf86Info.vtno) == 0) { + UseMsg(); + xf86Info.vtno = -1; + return 0; + } + return 1; + } + return 0; } void xf86UseMsg(void) { - ErrorF("vtXX use the specified VT number\n"); - ErrorF("-keeptty "); - ErrorF("don't detach controlling tty (for debugging only)\n"); + ErrorF("vtXX use the specified VT number\n"); + ErrorF("-keeptty "); + ErrorF("don't detach controlling tty (for debugging only)\n"); } diff --git a/xorg-server/hw/xfree86/os-support/linux/lnx_video.c b/xorg-server/hw/xfree86/os-support/linux/lnx_video.c index 0d91f7a52..3526a21d4 100644 --- a/xorg-server/hw/xfree86/os-support/linux/lnx_video.c +++ b/xorg-server/hw/xfree86/os-support/linux/lnx_video.c @@ -70,10 +70,10 @@ extern int iopl(int __level); #endif #ifdef __alpha__ -# define BUS_BASE bus_base -#else +#define BUS_BASE bus_base +#else #define BUS_BASE (0) -#endif /* __alpha__ */ +#endif /* __alpha__ */ /***************************************************************************/ /* Video Memory Mapping section */ @@ -81,10 +81,11 @@ extern int iopl(int __level); static pointer mapVidMem(int, unsigned long, unsigned long, int); static void unmapVidMem(int, pointer, unsigned long); -#if defined (__alpha__) + +#if defined (__alpha__) extern void sethae(unsigned long hae); -extern unsigned long _bus_base __P ((void)) __attribute__ ((const)); -extern unsigned long _bus_base_sparse __P ((void)) __attribute__ ((const)); +extern unsigned long _bus_base __P((void)) __attribute__ ((const)); +extern unsigned long _bus_base_sparse __P((void)) __attribute__ ((const)); static pointer mapVidMemSparse(int, unsigned long, unsigned long, int); extern axpDevice lnxGetAXP(void); @@ -105,9 +106,9 @@ static void undoWC(int, pointer); /* The file desc for /proc/mtrr. Once opened, left opened, and the mtrr driver will clean up when we exit. */ -#define MTRR_FD_UNOPENED (-1) /* We have yet to open /proc/mtrr */ -#define MTRR_FD_PROBLEM (-2) /* We tried to open /proc/mtrr, but had - a problem. */ +#define MTRR_FD_UNOPENED (-1) /* We have yet to open /proc/mtrr */ +#define MTRR_FD_PROBLEM (-2) /* We tried to open /proc/mtrr, but had + a problem. */ static int mtrr_fd = MTRR_FD_UNOPENED; /* Open /proc/mtrr. FALSE on failure. Will always fail on Linux 2.0, @@ -116,29 +117,29 @@ static int mtrr_fd = MTRR_FD_UNOPENED; static Bool mtrr_open(int verbosity) { - /* Only report absence of /proc/mtrr once. */ - static Bool warned = FALSE; - - if (mtrr_fd == MTRR_FD_UNOPENED) { - mtrr_fd = open("/proc/mtrr", O_WRONLY); - - if (mtrr_fd < 0) - mtrr_fd = MTRR_FD_PROBLEM; - } - - if (mtrr_fd == MTRR_FD_PROBLEM) { - /* To make sure we only ever warn once, need to check - verbosity outside xf86MsgVerb */ - if (!warned && verbosity <= xf86GetVerbosity()) { - xf86MsgVerb(X_WARNING, verbosity, - "System lacks support for changing MTRRs\n"); - warned = TRUE; - } - - return FALSE; - } - else - return TRUE; + /* Only report absence of /proc/mtrr once. */ + static Bool warned = FALSE; + + if (mtrr_fd == MTRR_FD_UNOPENED) { + mtrr_fd = open("/proc/mtrr", O_WRONLY); + + if (mtrr_fd < 0) + mtrr_fd = MTRR_FD_PROBLEM; + } + + if (mtrr_fd == MTRR_FD_PROBLEM) { + /* To make sure we only ever warn once, need to check + verbosity outside xf86MsgVerb */ + if (!warned && verbosity <= xf86GetVerbosity()) { + xf86MsgVerb(X_WARNING, verbosity, + "System lacks support for changing MTRRs\n"); + warned = TRUE; + } + + return FALSE; + } + else + return TRUE; } /* @@ -147,260 +148,257 @@ mtrr_open(int verbosity) */ struct mtrr_wc_region { - struct mtrr_sentry sentry; - Bool added; /* added WC or removed it */ - struct mtrr_wc_region * next; + struct mtrr_sentry sentry; + Bool added; /* added WC or removed it */ + struct mtrr_wc_region *next; }; - static struct mtrr_wc_region * mtrr_cull_wc_region(int screenNum, unsigned long base, unsigned long size, - MessageType from) + MessageType from) { - /* Some BIOS writers thought that setting wc over the mmio - region of a graphics devices was a good idea. Try to fix - it. */ - - struct mtrr_gentry gent; - struct mtrr_wc_region *wcreturn = NULL, *wcr; - int count, ret=0; - - /* Linux 2.0 users should not get a warning without -verbose */ - if (!mtrr_open(2)) - return NULL; - - for (gent.regnum = 0; - ioctl(mtrr_fd, MTRRIOC_GET_ENTRY, &gent) >= 0; - gent.regnum++) { - if (gent.type != MTRR_TYPE_WRCOMB - || gent.base + gent.size <= base - || base + size <= gent.base) - continue; - - /* Found an overlapping region. Delete it. */ - - wcr = malloc(sizeof(*wcr)); - if (!wcr) - return NULL; - wcr->sentry.base = gent.base; - wcr->sentry.size = gent.size; - wcr->sentry.type = MTRR_TYPE_WRCOMB; - wcr->added = FALSE; - - count = 3; - while (count-- && - (ret = ioctl(mtrr_fd, MTRRIOC_KILL_ENTRY, &(wcr->sentry))) < 0); - - if (ret >= 0) { - xf86DrvMsg(screenNum, from, - "Removed MMIO write-combining range " - "(0x%lx,0x%lx)\n", - (unsigned long) gent.base, (unsigned long) gent.size); - wcr->next = wcreturn; - wcreturn = wcr; - gent.regnum--; - } else { - free(wcr); - xf86DrvMsgVerb(screenNum, X_WARNING, 0, - "Failed to remove MMIO " - "write-combining range (0x%lx,0x%lx)\n", - gent.base, (unsigned long) gent.size); - } - } - return wcreturn; -} + /* Some BIOS writers thought that setting wc over the mmio + region of a graphics devices was a good idea. Try to fix + it. */ + struct mtrr_gentry gent; + struct mtrr_wc_region *wcreturn = NULL, *wcr; + int count, ret = 0; + + /* Linux 2.0 users should not get a warning without -verbose */ + if (!mtrr_open(2)) + return NULL; + + for (gent.regnum = 0; + ioctl(mtrr_fd, MTRRIOC_GET_ENTRY, &gent) >= 0; gent.regnum++) { + if (gent.type != MTRR_TYPE_WRCOMB + || gent.base + gent.size <= base || base + size <= gent.base) + continue; + + /* Found an overlapping region. Delete it. */ + + wcr = malloc(sizeof(*wcr)); + if (!wcr) + return NULL; + wcr->sentry.base = gent.base; + wcr->sentry.size = gent.size; + wcr->sentry.type = MTRR_TYPE_WRCOMB; + wcr->added = FALSE; + + count = 3; + while (count-- && + (ret = ioctl(mtrr_fd, MTRRIOC_KILL_ENTRY, &(wcr->sentry))) < 0); + + if (ret >= 0) { + xf86DrvMsg(screenNum, from, + "Removed MMIO write-combining range " + "(0x%lx,0x%lx)\n", + (unsigned long) gent.base, (unsigned long) gent.size); + wcr->next = wcreturn; + wcreturn = wcr; + gent.regnum--; + } + else { + free(wcr); + xf86DrvMsgVerb(screenNum, X_WARNING, 0, + "Failed to remove MMIO " + "write-combining range (0x%lx,0x%lx)\n", + gent.base, (unsigned long) gent.size); + } + } + return wcreturn; +} static struct mtrr_wc_region * mtrr_remove_offending(int screenNum, unsigned long base, unsigned long size, - MessageType from) + MessageType from) { struct mtrr_gentry gent; struct mtrr_wc_region *wcreturn = NULL, **wcr; if (!mtrr_open(2)) - return NULL; + return NULL; wcr = &wcreturn; - for (gent.regnum = 0; - ioctl(mtrr_fd, MTRRIOC_GET_ENTRY, &gent) >= 0; gent.regnum++ ) { - if (gent.type == MTRR_TYPE_WRCOMB - && ((gent.base >= base && gent.base + gent.size < base + size) || - (gent.base > base && gent.base + gent.size <= base + size))) { - *wcr = mtrr_cull_wc_region(screenNum, gent.base, gent.size, from); - if (*wcr) gent.regnum--; - while(*wcr) { - wcr = &((*wcr)->next); - } - } + for (gent.regnum = 0; + ioctl(mtrr_fd, MTRRIOC_GET_ENTRY, &gent) >= 0; gent.regnum++) { + if (gent.type == MTRR_TYPE_WRCOMB + && ((gent.base >= base && gent.base + gent.size < base + size) || + (gent.base > base && gent.base + gent.size <= base + size))) { + *wcr = mtrr_cull_wc_region(screenNum, gent.base, gent.size, from); + if (*wcr) + gent.regnum--; + while (*wcr) { + wcr = &((*wcr)->next); + } + } } return wcreturn; } - static struct mtrr_wc_region * mtrr_add_wc_region(int screenNum, unsigned long base, unsigned long size, - MessageType from) + MessageType from) { - struct mtrr_wc_region **wcr, *wcreturn, *curwcr; + struct mtrr_wc_region **wcr, *wcreturn, *curwcr; - /* - * There can be only one.... - */ + /* + * There can be only one.... + */ - wcreturn = mtrr_remove_offending(screenNum, base, size, from); - wcr = &wcreturn; - while (*wcr) { - wcr = &((*wcr)->next); - } + wcreturn = mtrr_remove_offending(screenNum, base, size, from); + wcr = &wcreturn; + while (*wcr) { + wcr = &((*wcr)->next); + } - /* Linux 2.0 should not warn, unless the user explicitly asks for - WC. */ + /* Linux 2.0 should not warn, unless the user explicitly asks for + WC. */ - if (!mtrr_open(from == X_CONFIG ? 0 : 2)) - return wcreturn; + if (!mtrr_open(from == X_CONFIG ? 0 : 2)) + return wcreturn; - *wcr = curwcr = malloc(sizeof(**wcr)); - if (!curwcr) - return wcreturn; + *wcr = curwcr = malloc(sizeof(**wcr)); + if (!curwcr) + return wcreturn; - curwcr->sentry.base = base; - curwcr->sentry.size = size; - curwcr->sentry.type = MTRR_TYPE_WRCOMB; - curwcr->added = TRUE; - curwcr->next = NULL; + curwcr->sentry.base = base; + curwcr->sentry.size = size; + curwcr->sentry.type = MTRR_TYPE_WRCOMB; + curwcr->added = TRUE; + curwcr->next = NULL; #if SPLIT_WC_REGIONS - /* - * Splits up the write-combining region if it is not aligned on a - * size boundary. - */ - - { - unsigned long lbase, d_size = 1; - unsigned long n_size = size; - unsigned long n_base = base; - - for (lbase = n_base, d_size = 1; !(lbase & 1); - lbase = lbase >> 1, d_size <<= 1); - while (d_size > n_size) - d_size = d_size >> 1; - DebugF("WC_BASE: 0x%lx WC_END: 0x%lx\n",base,base+d_size-1); - n_base += d_size; - n_size -= d_size; - if (n_size) { - xf86DrvMsgVerb(screenNum,X_INFO,3,"Splitting WC range: " - "base: 0x%lx, size: 0x%lx\n",base,size); - curwcr->next = mtrr_add_wc_region(screenNum, n_base, n_size,from); - } - curwcr->sentry.size = d_size; - } - - /*****************************************************************/ -#endif /* SPLIT_WC_REGIONS */ - - if (ioctl(mtrr_fd, MTRRIOC_ADD_ENTRY, &curwcr->sentry) >= 0) { - /* Avoid printing on every VT switch */ - if (xf86ServerIsInitialising()) { - xf86DrvMsg(screenNum, from, - "Write-combining range (0x%lx,0x%lx)\n", - base, size); - } - return wcreturn; - } - else { - *wcr = curwcr->next; - free(curwcr); - - /* Don't complain about the VGA region: MTRR fixed - regions aren't currently supported, but might be in - the future. */ - if ((unsigned long)base >= 0x100000) { - xf86DrvMsgVerb(screenNum, X_WARNING, 0, - "Failed to set up write-combining range " - "(0x%lx,0x%lx)\n", base, size); - } - return wcreturn; - } + /* + * Splits up the write-combining region if it is not aligned on a + * size boundary. + */ + + { + unsigned long lbase, d_size = 1; + unsigned long n_size = size; + unsigned long n_base = base; + + for (lbase = n_base, d_size = 1; !(lbase & 1); + lbase = lbase >> 1, d_size <<= 1); + while (d_size > n_size) + d_size = d_size >> 1; + DebugF("WC_BASE: 0x%lx WC_END: 0x%lx\n", base, base + d_size - 1); + n_base += d_size; + n_size -= d_size; + if (n_size) { + xf86DrvMsgVerb(screenNum, X_INFO, 3, "Splitting WC range: " + "base: 0x%lx, size: 0x%lx\n", base, size); + curwcr->next = mtrr_add_wc_region(screenNum, n_base, n_size, from); + } + curwcr->sentry.size = d_size; + } + + /*****************************************************************/ +#endif /* SPLIT_WC_REGIONS */ + + if (ioctl(mtrr_fd, MTRRIOC_ADD_ENTRY, &curwcr->sentry) >= 0) { + /* Avoid printing on every VT switch */ + if (xf86ServerIsInitialising()) { + xf86DrvMsg(screenNum, from, + "Write-combining range (0x%lx,0x%lx)\n", base, size); + } + return wcreturn; + } + else { + *wcr = curwcr->next; + free(curwcr); + + /* Don't complain about the VGA region: MTRR fixed + regions aren't currently supported, but might be in + the future. */ + if ((unsigned long) base >= 0x100000) { + xf86DrvMsgVerb(screenNum, X_WARNING, 0, + "Failed to set up write-combining range " + "(0x%lx,0x%lx)\n", base, size); + } + return wcreturn; + } } static void mtrr_undo_wc_region(int screenNum, struct mtrr_wc_region *wcr) { - struct mtrr_wc_region *p, *prev; - - if (mtrr_fd >= 0) { - p = wcr; - while (p) { - if (p->added) - ioctl(mtrr_fd, MTRRIOC_DEL_ENTRY, &p->sentry); - prev = p; - p = p->next; - free(prev); - } - } + struct mtrr_wc_region *p, *prev; + + if (mtrr_fd >= 0) { + p = wcr; + while (p) { + if (p->added) + ioctl(mtrr_fd, MTRRIOC_DEL_ENTRY, &p->sentry); + prev = p; + p = p->next; + free(prev); + } + } } static pointer setWC(int screenNum, unsigned long base, unsigned long size, Bool enable, MessageType from) { - if (enable) - return mtrr_add_wc_region(screenNum, base, size, from); - else - return mtrr_cull_wc_region(screenNum, base, size, from); + if (enable) + return mtrr_add_wc_region(screenNum, base, size, from); + else + return mtrr_cull_wc_region(screenNum, base, size, from); } static void undoWC(int screenNum, pointer regioninfo) { - mtrr_undo_wc_region(screenNum, regioninfo); + mtrr_undo_wc_region(screenNum, regioninfo); } -#endif /* HAS_MTRR_SUPPORT */ +#endif /* HAS_MTRR_SUPPORT */ void xf86OSInitVidMem(VidMemInfoPtr pVidMem) { - pVidMem->linearSupported = TRUE; + pVidMem->linearSupported = TRUE; #ifdef __alpha__ - if (axpSystem == -1) { - axpSystem = lnxGetAXP(); - if ((needSparse = (_bus_base_sparse() > 0))) { - hae_thresh = xf86AXPParams[axpSystem].hae_thresh; - hae_mask = xf86AXPParams[axpSystem].hae_mask; - } - bus_base = _bus_base(); - } - if (needSparse) { - xf86Msg(X_INFO,"Machine needs sparse mapping\n"); - pVidMem->mapMem = mapVidMemSparse; - pVidMem->unmapMem = unmapVidMemSparse; - } else { - xf86Msg(X_INFO,"Machine type has 8/16 bit access\n"); - pVidMem->mapMem = mapVidMem; - pVidMem->unmapMem = unmapVidMem; - } + if (axpSystem == -1) { + axpSystem = lnxGetAXP(); + if ((needSparse = (_bus_base_sparse() > 0))) { + hae_thresh = xf86AXPParams[axpSystem].hae_thresh; + hae_mask = xf86AXPParams[axpSystem].hae_mask; + } + bus_base = _bus_base(); + } + if (needSparse) { + xf86Msg(X_INFO, "Machine needs sparse mapping\n"); + pVidMem->mapMem = mapVidMemSparse; + pVidMem->unmapMem = unmapVidMemSparse; + } + else { + xf86Msg(X_INFO, "Machine type has 8/16 bit access\n"); + pVidMem->mapMem = mapVidMem; + pVidMem->unmapMem = unmapVidMem; + } #else - pVidMem->mapMem = mapVidMem; - pVidMem->unmapMem = unmapVidMem; -#endif /* __alpha__ */ - + pVidMem->mapMem = mapVidMem; + pVidMem->unmapMem = unmapVidMem; +#endif /* __alpha__ */ #ifdef HAS_MTRR_SUPPORT - pVidMem->setWC = setWC; - pVidMem->undoWC = undoWC; + pVidMem->setWC = setWC; + pVidMem->undoWC = undoWC; #endif - pVidMem->initialised = TRUE; + pVidMem->initialised = TRUE; } #ifdef __sparc__ /* Basically, you simply cannot do this on Sparc. You have to do something portable * like use /dev/fb* or mmap() on /proc/bus/pci/X/Y nodes. -DaveM */ -static pointer mapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags) +static pointer +mapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags) { - return NULL; + return NULL; } #else static pointer @@ -408,14 +406,14 @@ mapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags) { pointer base; int fd; - int mapflags = MAP_SHARED; + int mapflags = MAP_SHARED; int prot; memType realBase, alignOff; realBase = Base & ~(getpagesize() - 1); alignOff = Base - realBase; DebugF("base: %lx, realBase: %lx, alignOff: %lx \n", - Base,realBase,alignOff); + Base, realBase, alignOff); #if defined(__ia64__) || defined(__arm__) || defined(__s390__) #ifndef MAP_WRITECOMBINED @@ -424,55 +422,52 @@ mapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags) #ifndef MAP_NONCACHED #define MAP_NONCACHED 0x00020000 #endif - if(flags & VIDMEM_FRAMEBUFFER) - mapflags |= MAP_WRITECOMBINED; + if (flags & VIDMEM_FRAMEBUFFER) + mapflags |= MAP_WRITECOMBINED; else - mapflags |= MAP_NONCACHED; + mapflags |= MAP_NONCACHED; #endif #if 0 /* this will disappear when people upgrade their kernels */ fd = open(DEV_MEM, - ((flags & VIDMEM_READONLY) ? O_RDONLY : O_RDWR) | O_SYNC); + ((flags & VIDMEM_READONLY) ? O_RDONLY : O_RDWR) | O_SYNC); #else fd = open(DEV_MEM, (flags & VIDMEM_READONLY) ? O_RDONLY : O_RDWR); #endif - if (fd < 0) - { - FatalError("xf86MapVidMem: failed to open " DEV_MEM " (%s)\n", - strerror(errno)); + if (fd < 0) { + FatalError("xf86MapVidMem: failed to open " DEV_MEM " (%s)\n", + strerror(errno)); } if (flags & VIDMEM_READONLY) - prot = PROT_READ; + prot = PROT_READ; else - prot = PROT_READ | PROT_WRITE; + prot = PROT_READ | PROT_WRITE; /* This requires linux-0.99.pl10 or above */ - base = mmap((caddr_t)0, Size + alignOff, prot, mapflags, fd, - (off_t)realBase + BUS_BASE); + base = mmap((caddr_t) 0, Size + alignOff, prot, mapflags, fd, + (off_t) realBase + BUS_BASE); close(fd); if (base == MAP_FAILED) { FatalError("xf86MapVidMem: Could not mmap framebuffer" - " (0x%08lx,0x%lx) (%s)\n", Base, Size, - strerror(errno)); + " (0x%08lx,0x%lx) (%s)\n", Base, Size, strerror(errno)); } - DebugF("base: %lx aligned base: %lx\n",base, (char *)base + alignOff); - return (char *)base + alignOff; + DebugF("base: %lx aligned base: %lx\n", base, (char *) base + alignOff); + return (char *) base + alignOff; } -#endif /* !(__sparc__) */ - +#endif /* !(__sparc__) */ + static void unmapVidMem(int ScreenNum, pointer Base, unsigned long Size) { - uintptr_t alignOff = (uintptr_t)Base - - ((uintptr_t)Base & ~(getpagesize() - 1)); + uintptr_t alignOff = (uintptr_t) Base + - ((uintptr_t) Base & ~(getpagesize() - 1)); - DebugF("alignment offset: %lx\n", (unsigned long)alignOff); - munmap((void *)((uintptr_t)Base - alignOff), (Size + alignOff)); + DebugF("alignment offset: %lx\n", (unsigned long) alignOff); + munmap((void *) ((uintptr_t) Base - alignOff), (Size + alignOff)); } - /***************************************************************************/ /* I/O Permissions section */ /***************************************************************************/ @@ -490,68 +485,68 @@ Bool xf86EnableIO(void) { #if defined(__powerpc__) - int fd; - unsigned int ioBase_phys; + int fd; + unsigned int ioBase_phys; #endif - if (ExtendedEnabled) - return TRUE; + if (ExtendedEnabled) + return TRUE; #if defined(__powerpc__) - ioBase_phys = syscall(__NR_pciconfig_iobase, 2, 0, 0); + ioBase_phys = syscall(__NR_pciconfig_iobase, 2, 0, 0); - fd = open("/dev/mem", O_RDWR); - if (ioBase == NULL) { - ioBase = (volatile unsigned char *)mmap(0, 0x20000, - PROT_READ | PROT_WRITE, MAP_SHARED, fd, - ioBase_phys); + fd = open("/dev/mem", O_RDWR); + if (ioBase == NULL) { + ioBase = (volatile unsigned char *) mmap(0, 0x20000, + PROT_READ | PROT_WRITE, + MAP_SHARED, fd, ioBase_phys); /* Should this be fatal or just a warning? */ #if 0 - if (ioBase == MAP_FAILED) { - xf86Msg(X_WARNING, - "xf86EnableIOPorts: Failed to map iobase (%s)\n", - strerror(errno)); - return FALSE; - } + if (ioBase == MAP_FAILED) { + xf86Msg(X_WARNING, + "xf86EnableIOPorts: Failed to map iobase (%s)\n", + strerror(errno)); + return FALSE; + } #endif - } - close(fd); + } + close(fd); #elif !defined(__mc68000__) && !defined(__sparc__) && !defined(__mips__) && !defined(__sh__) && !defined(__hppa__) && !defined(__s390__) && !defined(__arm__) && !defined(__m32r__) && !defined(__nds32__) - if (ioperm(0, 1024, 1) || iopl(3)) { - if (errno == ENODEV) - ErrorF("xf86EnableIOPorts: no I/O ports found\n"); - else - FatalError("xf86EnableIOPorts: failed to set IOPL" - " for I/O (%s)\n", strerror(errno)); - return FALSE; - } -# if !defined(__alpha__) - /* XXX: this is actually not trapping anything because of iopl(3) - * above */ - ioperm(0x40,4,0); /* trap access to the timer chip */ - ioperm(0x60,4,0); /* trap access to the keyboard controller */ -# endif + if (ioperm(0, 1024, 1) || iopl(3)) { + if (errno == ENODEV) + ErrorF("xf86EnableIOPorts: no I/O ports found\n"); + else + FatalError("xf86EnableIOPorts: failed to set IOPL" + " for I/O (%s)\n", strerror(errno)); + return FALSE; + } +#if !defined(__alpha__) + /* XXX: this is actually not trapping anything because of iopl(3) + * above */ + ioperm(0x40, 4, 0); /* trap access to the timer chip */ + ioperm(0x60, 4, 0); /* trap access to the keyboard controller */ +#endif #endif - ExtendedEnabled = TRUE; + ExtendedEnabled = TRUE; - return TRUE; + return TRUE; } void xf86DisableIO(void) { - if (!ExtendedEnabled) - return; + if (!ExtendedEnabled) + return; #if defined(__powerpc__) - munmap(ioBase, 0x20000); - ioBase = NULL; + munmap(ioBase, 0x20000); + ioBase = NULL; #elif !defined(__mc68000__) && !defined(__sparc__) && !defined(__mips__) && !defined(__sh__) && !defined(__hppa__) && !defined(__arm__) && !defined(__s390__) && !defined(__m32r__) && !defined(__nds32__) - iopl(0); - ioperm(0, 1024, 0); + iopl(0); + ioperm(0, 1024, 0); #endif - ExtendedEnabled = FALSE; + ExtendedEnabled = FALSE; - return; + return; } #if defined (__alpha__) @@ -562,33 +557,33 @@ extern int readDense8(pointer Base, register unsigned long Offset); extern int readDense16(pointer Base, register unsigned long Offset); extern int readDense32(pointer Base, register unsigned long Offset); extern void -writeDenseNB8(int Value, pointer Base, register unsigned long Offset); + writeDenseNB8(int Value, pointer Base, register unsigned long Offset); extern void -writeDenseNB16(int Value, pointer Base, register unsigned long Offset); + writeDenseNB16(int Value, pointer Base, register unsigned long Offset); extern void -writeDenseNB32(int Value, pointer Base, register unsigned long Offset); + writeDenseNB32(int Value, pointer Base, register unsigned long Offset); extern void -writeDense8(int Value, pointer Base, register unsigned long Offset); + writeDense8(int Value, pointer Base, register unsigned long Offset); extern void -writeDense16(int Value, pointer Base, register unsigned long Offset); + writeDense16(int Value, pointer Base, register unsigned long Offset); extern void -writeDense32(int Value, pointer Base, register unsigned long Offset); + writeDense32(int Value, pointer Base, register unsigned long Offset); static int readSparse8(pointer Base, register unsigned long Offset); static int readSparse16(pointer Base, register unsigned long Offset); static int readSparse32(pointer Base, register unsigned long Offset); static void -writeSparseNB8(int Value, pointer Base, register unsigned long Offset); + writeSparseNB8(int Value, pointer Base, register unsigned long Offset); static void -writeSparseNB16(int Value, pointer Base, register unsigned long Offset); + writeSparseNB16(int Value, pointer Base, register unsigned long Offset); static void -writeSparseNB32(int Value, pointer Base, register unsigned long Offset); + writeSparseNB32(int Value, pointer Base, register unsigned long Offset); static void -writeSparse8(int Value, pointer Base, register unsigned long Offset); + writeSparse8(int Value, pointer Base, register unsigned long Offset); static void -writeSparse16(int Value, pointer Base, register unsigned long Offset); + writeSparse16(int Value, pointer Base, register unsigned long Offset); static void -writeSparse32(int Value, pointer Base, register unsigned long Offset); + writeSparse32(int Value, pointer Base, register unsigned long Offset); #define DENSE_BASE 0x2ff00000000UL #define SPARSE_BASE 0x30000000000UL @@ -596,7 +591,8 @@ writeSparse32(int Value, pointer Base, register unsigned long Offset); static unsigned long msb_set = 0; static pointer -mapVidMemSparse(int ScreenNum, unsigned long Base, unsigned long Size, int flags) +mapVidMemSparse(int ScreenNum, unsigned long Base, unsigned long Size, + int flags) { int fd, prot; unsigned long ret, rets = 0; @@ -604,43 +600,42 @@ mapVidMemSparse(int ScreenNum, unsigned long Base, unsigned long Size, int flags static Bool was_here = FALSE; if (!was_here) { - was_here = TRUE; - - xf86WriteMmio8 = writeSparse8; - xf86WriteMmio16 = writeSparse16; - xf86WriteMmio32 = writeSparse32; - xf86WriteMmioNB8 = writeSparseNB8; - xf86WriteMmioNB16 = writeSparseNB16; - xf86WriteMmioNB32 = writeSparseNB32; - xf86ReadMmio8 = readSparse8; - xf86ReadMmio16 = readSparse16; - xf86ReadMmio32 = readSparse32; + was_here = TRUE; + + xf86WriteMmio8 = writeSparse8; + xf86WriteMmio16 = writeSparse16; + xf86WriteMmio32 = writeSparse32; + xf86WriteMmioNB8 = writeSparseNB8; + xf86WriteMmioNB16 = writeSparseNB16; + xf86WriteMmioNB32 = writeSparseNB32; + xf86ReadMmio8 = readSparse8; + xf86ReadMmio16 = readSparse16; + xf86ReadMmio32 = readSparse32; } - + fd = open(DEV_MEM, (flags & VIDMEM_READONLY) ? O_RDONLY : O_RDWR); if (fd < 0) { FatalError("xf86MapVidMem: failed to open " DEV_MEM " (%s)\n", - strerror(errno)); + strerror(errno)); } #if 0 - xf86Msg(X_INFO,"mapVidMemSparse: try Base 0x%lx size 0x%lx flags 0x%x\n", - Base, Size, flags); + xf86Msg(X_INFO, "mapVidMemSparse: try Base 0x%lx size 0x%lx flags 0x%x\n", + Base, Size, flags); #endif if (flags & VIDMEM_READONLY) - prot = PROT_READ; + prot = PROT_READ; else - prot = PROT_READ | PROT_WRITE; + prot = PROT_READ | PROT_WRITE; /* This requirers linux-0.99.pl10 or above */ /* * Always do DENSE mmap, since read32/write32 currently require it. */ - ret = (unsigned long)mmap((caddr_t)(DENSE_BASE + Base), Size, - prot, MAP_SHARED, fd, - (off_t) (bus_base + Base)); + ret = (unsigned long) mmap((caddr_t) (DENSE_BASE + Base), Size, + prot, MAP_SHARED, fd, (off_t) (bus_base + Base)); /* * Do SPARSE mmap only when MMIO and not MMIO_32BIT, or FRAMEBUFFER @@ -650,40 +645,36 @@ mapVidMemSparse(int ScreenNum, unsigned long Base, unsigned long Size, int flags * bytes worth of pagetable (32 pages). */ if (((flags & VIDMEM_MMIO) && !(flags & VIDMEM_MMIO_32BIT)) || - ((flags & VIDMEM_FRAMEBUFFER) && (flags & VIDMEM_SPARSE))) - { - rets = (unsigned long)mmap((caddr_t)(SPARSE_BASE + (Base << 5)), - Size << 5, prot, MAP_SHARED, fd, - (off_t) _bus_base_sparse() + (Base << 5)); + ((flags & VIDMEM_FRAMEBUFFER) && (flags & VIDMEM_SPARSE))) { + rets = (unsigned long) mmap((caddr_t) (SPARSE_BASE + (Base << 5)), + Size << 5, prot, MAP_SHARED, fd, + (off_t) _bus_base_sparse() + (Base << 5)); } close(fd); - - if (ret == (unsigned long)MAP_FAILED) { + + if (ret == (unsigned long) MAP_FAILED) { FatalError("xf86MapVidMemSparse: Could not (dense) mmap fb (%s)\n", - strerror(errno)); + strerror(errno)); } if (((flags & VIDMEM_MMIO) && !(flags & VIDMEM_MMIO_32BIT)) || - ((flags & VIDMEM_FRAMEBUFFER) && (flags & VIDMEM_SPARSE))) - { - if (rets == (unsigned long)MAP_FAILED || - rets != (SPARSE_BASE + (Base << 5))) - { - FatalError("mapVidMemSparse: Could not (sparse) mmap fb (%s)\n", - strerror(errno)); - } + ((flags & VIDMEM_FRAMEBUFFER) && (flags & VIDMEM_SPARSE))) { + if (rets == (unsigned long) MAP_FAILED || + rets != (SPARSE_BASE + (Base << 5))) { + FatalError("mapVidMemSparse: Could not (sparse) mmap fb (%s)\n", + strerror(errno)); + } } #if 1 if (rets) - xf86Msg(X_INFO,"mapVidMemSparse: mapped Base 0x%lx size 0x%lx" - " to DENSE at 0x%lx and SPARSE at 0x%lx\n", - Base, Size, ret, rets); + xf86Msg(X_INFO, "mapVidMemSparse: mapped Base 0x%lx size 0x%lx" + " to DENSE at 0x%lx and SPARSE at 0x%lx\n", + Base, Size, ret, rets); else - xf86Msg(X_INFO,"mapVidMemSparse: mapped Base 0x%lx size 0x%lx" - " to DENSE only at 0x%lx\n", - Base, Size, ret); + xf86Msg(X_INFO, "mapVidMemSparse: mapped Base 0x%lx size 0x%lx" + " to DENSE only at 0x%lx\n", Base, Size, ret); #endif return (pointer) ret; @@ -692,16 +683,17 @@ mapVidMemSparse(int ScreenNum, unsigned long Base, unsigned long Size, int flags static void unmapVidMemSparse(int ScreenNum, pointer Base, unsigned long Size) { - unsigned long Offset = (unsigned long)Base - DENSE_BASE; + unsigned long Offset = (unsigned long) Base - DENSE_BASE; + #if 1 - xf86Msg(X_INFO,"unmapVidMemSparse: unmapping Base 0x%lx Size 0x%lx\n", - Base, Size); + xf86Msg(X_INFO, "unmapVidMemSparse: unmapping Base 0x%lx Size 0x%lx\n", + Base, Size); #endif /* Unmap DENSE always. */ - munmap((caddr_t)Base, Size); + munmap((caddr_t) Base, Size); /* Unmap SPARSE always, and ignore error in case we did not map it. */ - munmap((caddr_t)(SPARSE_BASE + (Offset << 5)), Size << 5); + munmap((caddr_t) (SPARSE_BASE + (Offset << 5)), Size << 5); } static int @@ -711,15 +703,15 @@ readSparse8(pointer Base, register unsigned long Offset) register unsigned long msb; mem_barrier(); - Offset += (unsigned long)Base - DENSE_BASE; + Offset += (unsigned long) Base - DENSE_BASE; shift = (Offset & 0x3) << 3; if (Offset >= (hae_thresh)) { msb = Offset & hae_mask; Offset -= msb; - if (msb_set != msb) { - sethae(msb); - msb_set = msb; - } + if (msb_set != msb) { + sethae(msb); + msb_set = msb; + } } mem_barrier(); @@ -735,19 +727,19 @@ readSparse16(pointer Base, register unsigned long Offset) register unsigned long msb; mem_barrier(); - Offset += (unsigned long)Base - DENSE_BASE; + Offset += (unsigned long) Base - DENSE_BASE; shift = (Offset & 0x2) << 3; if (Offset >= hae_thresh) { msb = Offset & hae_mask; Offset -= msb; - if (msb_set != msb) { - sethae(msb); - msb_set = msb; - } + if (msb_set != msb) { + sethae(msb); + msb_set = msb; + } } mem_barrier(); - result = *(vuip)(SPARSE_BASE + (Offset<<5) + (1<<(5-2))); + result = *(vuip) (SPARSE_BASE + (Offset << 5) + (1 << (5 - 2))); result >>= shift; return 0xffffUL & result; } @@ -757,7 +749,7 @@ readSparse32(pointer Base, register unsigned long Offset) { /* NOTE: this is really using DENSE. */ mem_barrier(); - return *(vuip)((unsigned long)Base+(Offset)); + return *(vuip) ((unsigned long) Base + (Offset)); } static void @@ -767,14 +759,14 @@ writeSparse8(int Value, pointer Base, register unsigned long Offset) register unsigned int b = Value & 0xffU; write_mem_barrier(); - Offset += (unsigned long)Base - DENSE_BASE; + Offset += (unsigned long) Base - DENSE_BASE; if (Offset >= hae_thresh) { msb = Offset & hae_mask; - Offset -= msb; - if (msb_set != msb) { - sethae(msb); - msb_set = msb; - } + Offset -= msb; + if (msb_set != msb) { + sethae(msb); + msb_set = msb; + } } write_mem_barrier(); @@ -788,18 +780,18 @@ writeSparse16(int Value, pointer Base, register unsigned long Offset) register unsigned int w = Value & 0xffffU; write_mem_barrier(); - Offset += (unsigned long)Base - DENSE_BASE; + Offset += (unsigned long) Base - DENSE_BASE; if (Offset >= hae_thresh) { msb = Offset & hae_mask; - Offset -= msb; - if (msb_set != msb) { - sethae(msb); - msb_set = msb; - } + Offset -= msb; + if (msb_set != msb) { + sethae(msb); + msb_set = msb; + } } write_mem_barrier(); - *(vuip)(SPARSE_BASE + (Offset<<5) + (1<<(5-2))) = w * 0x00010001; + *(vuip) (SPARSE_BASE + (Offset << 5) + (1 << (5 - 2))) = w * 0x00010001; } static void @@ -807,7 +799,7 @@ writeSparse32(int Value, pointer Base, register unsigned long Offset) { /* NOTE: this is really using DENSE. */ write_mem_barrier(); - *(vuip)((unsigned long)Base + (Offset)) = Value; + *(vuip) ((unsigned long) Base + (Offset)) = Value; return; } @@ -817,14 +809,14 @@ writeSparseNB8(int Value, pointer Base, register unsigned long Offset) register unsigned long msb; register unsigned int b = Value & 0xffU; - Offset += (unsigned long)Base - DENSE_BASE; + Offset += (unsigned long) Base - DENSE_BASE; if (Offset >= hae_thresh) { msb = Offset & hae_mask; - Offset -= msb; - if (msb_set != msb) { - sethae(msb); - msb_set = msb; - } + Offset -= msb; + if (msb_set != msb) { + sethae(msb); + msb_set = msb; + } } *(vuip) (SPARSE_BASE + (Offset << 5)) = b * 0x01010101; } @@ -835,43 +827,43 @@ writeSparseNB16(int Value, pointer Base, register unsigned long Offset) register unsigned long msb; register unsigned int w = Value & 0xffffU; - Offset += (unsigned long)Base - DENSE_BASE; + Offset += (unsigned long) Base - DENSE_BASE; if (Offset >= hae_thresh) { msb = Offset & hae_mask; - Offset -= msb; - if (msb_set != msb) { - sethae(msb); - msb_set = msb; - } + Offset -= msb; + if (msb_set != msb) { + sethae(msb); + msb_set = msb; + } } - *(vuip)(SPARSE_BASE+(Offset<<5)+(1<<(5-2))) = w * 0x00010001; + *(vuip) (SPARSE_BASE + (Offset << 5) + (1 << (5 - 2))) = w * 0x00010001; } static void writeSparseNB32(int Value, pointer Base, register unsigned long Offset) { /* NOTE: this is really using DENSE. */ - *(vuip)((unsigned long)Base + (Offset)) = Value; + *(vuip) ((unsigned long) Base + (Offset)) = Value; return; } -void (*xf86WriteMmio8)(int Value, pointer Base, unsigned long Offset) - = writeDense8; -void (*xf86WriteMmio16)(int Value, pointer Base, unsigned long Offset) - = writeDense16; -void (*xf86WriteMmio32)(int Value, pointer Base, unsigned long Offset) - = writeDense32; -void (*xf86WriteMmioNB8)(int Value, pointer Base, unsigned long Offset) - = writeDenseNB8; -void (*xf86WriteMmioNB16)(int Value, pointer Base, unsigned long Offset) - = writeDenseNB16; -void (*xf86WriteMmioNB32)(int Value, pointer Base, unsigned long Offset) - = writeDenseNB32; -int (*xf86ReadMmio8)(pointer Base, unsigned long Offset) - = readDense8; -int (*xf86ReadMmio16)(pointer Base, unsigned long Offset) - = readDense16; -int (*xf86ReadMmio32)(pointer Base, unsigned long Offset) - = readDense32; - -#endif /* __alpha__ */ +void (*xf86WriteMmio8) (int Value, pointer Base, unsigned long Offset) + = writeDense8; +void (*xf86WriteMmio16) (int Value, pointer Base, unsigned long Offset) + = writeDense16; +void (*xf86WriteMmio32) (int Value, pointer Base, unsigned long Offset) + = writeDense32; +void (*xf86WriteMmioNB8) (int Value, pointer Base, unsigned long Offset) + = writeDenseNB8; +void (*xf86WriteMmioNB16) (int Value, pointer Base, unsigned long Offset) + = writeDenseNB16; +void (*xf86WriteMmioNB32) (int Value, pointer Base, unsigned long Offset) + = writeDenseNB32; +int (*xf86ReadMmio8) (pointer Base, unsigned long Offset) + = readDense8; +int (*xf86ReadMmio16) (pointer Base, unsigned long Offset) + = readDense16; +int (*xf86ReadMmio32) (pointer Base, unsigned long Offset) + = readDense32; + +#endif /* __alpha__ */ diff --git a/xorg-server/hw/xfree86/os-support/misc/SlowBcopy.c b/xorg-server/hw/xfree86/os-support/misc/SlowBcopy.c index 0021b5544..254748ff6 100644 --- a/xorg-server/hw/xfree86/os-support/misc/SlowBcopy.c +++ b/xorg-server/hw/xfree86/os-support/misc/SlowBcopy.c @@ -1,7 +1,7 @@ /******************************************************************************* for Alpha Linux *******************************************************************************/ - + /* * Create a dependency that should be immune from the effect of register * renaming as is commonly seen in superscalar processors. This should @@ -10,7 +10,7 @@ * * Slowbcopy(char *src, char *dst, int count) * - */ + */ #ifdef HAVE_XORG_CONFIG_H #include <xorg-config.h> @@ -27,16 +27,16 @@ static int really_slow_bcopy; void xf86SetReallySlowBcopy(void) { - really_slow_bcopy = 1; + really_slow_bcopy = 1; } #if defined(__i386__) || defined(__amd64__) -static void xf86_really_slow_bcopy(unsigned char *src, unsigned char *dst, int len) +static void +xf86_really_slow_bcopy(unsigned char *src, unsigned char *dst, int len) { - while(len--) - { - *dst++ = *src++; - outb(0x80, 0x00); + while (len--) { + *dst++ = *src++; + outb(0x80, 0x00); } } #endif @@ -47,12 +47,12 @@ xf86SlowBcopy(unsigned char *src, unsigned char *dst, int len) { #if defined(__i386__) || defined(__amd64__) if (really_slow_bcopy) { - xf86_really_slow_bcopy(src, dst, len); - return; + xf86_really_slow_bcopy(src, dst, len); + return; } #endif - while(len--) - *dst++ = *src++; + while (len--) + *dst++ = *src++; } #ifdef __alpha__ @@ -76,42 +76,41 @@ unsigned long _bus_base(void); void xf86SlowBCopyFromBus(unsigned char *src, unsigned char *dst, int count) { - if (useSparse()) - { - unsigned long addr; - long result; - - addr = (unsigned long) src; - while (count) { - result = *(volatile int *) addr; - result >>= ((addr>>SPARSE) & 3) * 8; - *dst++ = (unsigned char) (0xffUL & result); - addr += 1<<SPARSE; - count--; - outb(0x80, 0x00); - } - } - else - xf86SlowBcopy(src, dst, count); + if (useSparse()) { + unsigned long addr; + long result; + + addr = (unsigned long) src; + while (count) { + result = *(volatile int *) addr; + result >>= ((addr >> SPARSE) & 3) * 8; + *dst++ = (unsigned char) (0xffUL & result); + addr += 1 << SPARSE; + count--; + outb(0x80, 0x00); + } + } + else + xf86SlowBcopy(src, dst, count); } void xf86SlowBCopyToBus(unsigned char *src, unsigned char *dst, int count) { - if (useSparse()) - { - unsigned long addr; - - addr = (unsigned long) dst; - while (count) { - *(volatile unsigned int *) addr = (unsigned short)(*src) * 0x01010101; - src++; - addr += 1<<SPARSE; - count--; - outb(0x80, 0x00); - } - } - else - xf86SlowBcopy(src, dst, count); + if (useSparse()) { + unsigned long addr; + + addr = (unsigned long) dst; + while (count) { + *(volatile unsigned int *) addr = + (unsigned short) (*src) * 0x01010101; + src++; + addr += 1 << SPARSE; + count--; + outb(0x80, 0x00); + } + } + else + xf86SlowBcopy(src, dst, count); } #endif 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} }; - diff --git a/xorg-server/hw/xfree86/os-support/solaris/sun_VTsw.c b/xorg-server/hw/xfree86/os-support/solaris/sun_VTsw.c index d145ac77b..573358b43 100644 --- a/xorg-server/hw/xfree86/os-support/solaris/sun_VTsw.c +++ b/xorg-server/hw/xfree86/os-support/solaris/sun_VTsw.c @@ -1,137 +1,134 @@ -/*
- * Copyright (c) 2009, Oracle and/or its affiliates. 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
- * THE AUTHORS OR COPYRIGHT HOLDERS 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.
- */
-
-#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 <door.h>
-#include <sys/vtdaemon.h>
-
-/*
- * Handle the VT-switching interface for Solaris/OpenSolaris
- */
-
-static int xf86VTPruneDoor = 0;
-
-void
-xf86VTRelease(int sig)
-{
- if (xf86Info.vtPendingNum == -1)
- {
- xf86VTPruneDoor = 1;
- xf86Info.vtRequestsPending = TRUE;
- return;
- }
-
- ioctl(xf86Info.consoleFd, VT_RELDISP, 1);
- xf86Info.vtPendingNum = -1;
-
- return;
-}
-
-void
-xf86VTAcquire(int sig)
-{
- xf86Info.vtRequestsPending = TRUE;
- return;
-}
-
-Bool
-xf86VTSwitchPending(void)
-{
- return xf86Info.vtRequestsPending ? TRUE : FALSE;
-}
-
-Bool
-xf86VTSwitchAway(void)
-{
- int door_fd;
- vt_cmd_arg_t vt_door_arg;
- door_arg_t door_arg;
-
- xf86Info.vtRequestsPending = FALSE;
-
- if (xf86VTPruneDoor) {
- xf86VTPruneDoor = 0;
- ioctl(xf86Info.consoleFd, VT_RELDISP, 1);
- return TRUE;
- }
-
- vt_door_arg.vt_ev = VT_EV_HOTKEYS;
- vt_door_arg.vt_num = xf86Info.vtPendingNum;
- door_arg.data_ptr = (char *)&vt_door_arg;
- door_arg.data_size = sizeof (vt_cmd_arg_t);
- door_arg.rbuf = NULL;
- door_arg.rsize = 0;
- door_arg.desc_ptr = NULL;
- door_arg.desc_num = 0;
-
- if ((door_fd = open(VT_DAEMON_DOOR_FILE, O_RDONLY)) < 0)
- return FALSE;
-
- if (door_call(door_fd, &door_arg) != 0) {
- close(door_fd);
- return FALSE;
- }
-
- close(door_fd);
- return TRUE;
-}
-
-Bool
-xf86VTSwitchTo(void)
-{
- xf86Info.vtRequestsPending = FALSE;
- if (ioctl(xf86Info.consoleFd, VT_RELDISP, VT_ACKACQ) < 0)
- {
- return FALSE;
- }
- else
- {
- return TRUE;
- }
-}
-
-Bool
-xf86VTActivate(int vtno)
-{
- struct vt_stat state;
-
- if (ioctl(xf86Info.consoleFd, VT_GETSTATE, &state) < 0)
- return FALSE;
-
- if ((state.v_state & (1 << vtno)) == 0)
- return FALSE;
-
- xf86Info.vtRequestsPending = TRUE;
- xf86Info.vtPendingNum = vtno;
-
- return TRUE;
-}
+/* + * Copyright (c) 2009, Oracle and/or its affiliates. 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 + * THE AUTHORS OR COPYRIGHT HOLDERS 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. + */ + +#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 <door.h> +#include <sys/vtdaemon.h> + +/* + * Handle the VT-switching interface for Solaris/OpenSolaris + */ + +static int xf86VTPruneDoor = 0; + +void +xf86VTRelease(int sig) +{ + if (xf86Info.vtPendingNum == -1) { + xf86VTPruneDoor = 1; + xf86Info.vtRequestsPending = TRUE; + return; + } + + ioctl(xf86Info.consoleFd, VT_RELDISP, 1); + xf86Info.vtPendingNum = -1; + + return; +} + +void +xf86VTAcquire(int sig) +{ + xf86Info.vtRequestsPending = TRUE; + return; +} + +Bool +xf86VTSwitchPending(void) +{ + return xf86Info.vtRequestsPending ? TRUE : FALSE; +} + +Bool +xf86VTSwitchAway(void) +{ + int door_fd; + vt_cmd_arg_t vt_door_arg; + door_arg_t door_arg; + + xf86Info.vtRequestsPending = FALSE; + + if (xf86VTPruneDoor) { + xf86VTPruneDoor = 0; + ioctl(xf86Info.consoleFd, VT_RELDISP, 1); + return TRUE; + } + + vt_door_arg.vt_ev = VT_EV_HOTKEYS; + vt_door_arg.vt_num = xf86Info.vtPendingNum; + door_arg.data_ptr = (char *) &vt_door_arg; + door_arg.data_size = sizeof(vt_cmd_arg_t); + door_arg.rbuf = NULL; + door_arg.rsize = 0; + door_arg.desc_ptr = NULL; + door_arg.desc_num = 0; + + if ((door_fd = open(VT_DAEMON_DOOR_FILE, O_RDONLY)) < 0) + return FALSE; + + if (door_call(door_fd, &door_arg) != 0) { + close(door_fd); + return FALSE; + } + + close(door_fd); + return TRUE; +} + +Bool +xf86VTSwitchTo(void) +{ + xf86Info.vtRequestsPending = FALSE; + if (ioctl(xf86Info.consoleFd, VT_RELDISP, VT_ACKACQ) < 0) { + return FALSE; + } + else { + return TRUE; + } +} + +Bool +xf86VTActivate(int vtno) +{ + struct vt_stat state; + + if (ioctl(xf86Info.consoleFd, VT_GETSTATE, &state) < 0) + return FALSE; + + if ((state.v_state & (1 << vtno)) == 0) + return FALSE; + + xf86Info.vtRequestsPending = TRUE; + xf86Info.vtPendingNum = vtno; + + return TRUE; +} diff --git a/xorg-server/hw/xfree86/os-support/solaris/sun_apm.c b/xorg-server/hw/xfree86/os-support/solaris/sun_apm.c index 7a5128ffb..4ff64649a 100644 --- a/xorg-server/hw/xfree86/os-support/solaris/sun_apm.c +++ b/xorg-server/hw/xfree86/os-support/solaris/sun_apm.c @@ -1,226 +1,227 @@ -/* Based on hw/xfree86/os-support/bsd/bsd_apm.c which bore no explicit
- * copyright notice, so is covered by the following notice:
- *
- * Copyright (C) 1994-2003 The XFree86 Project, Inc. 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 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 XFREE86 PROJECT 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 XFree86 Project 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
- * XFree86 Project.
- */
-
-/* Copyright (c) 2005, Oracle and/or its affiliates. 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
- * THE AUTHORS OR COPYRIGHT HOLDERS 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.
- */
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include <X11/X.h>
-#include "os.h"
-#include "xf86.h"
-#include "xf86Priv.h"
-#define XF86_OS_PRIVS
-#include "xf86_OSproc.h"
-#include "xf86_OSlib.h"
-
-#ifndef PLEASE_FIX_THIS
-#define APM_STANDBY_REQ 0xa01
-#define APM_SUSPEND_REQ 0xa02
-#define APM_NORMAL_RESUME 0xa03
-#define APM_CRIT_RESUME 0xa04
-#define APM_BATTERY_LOW 0xa05
-#define APM_POWER_CHANGE 0xa06
-#define APM_UPDATE_TIME 0xa07
-#define APM_CRIT_SUSPEND_REQ 0xa08
-#define APM_USER_STANDBY_REQ 0xa09
-#define APM_USER_SUSPEND_REQ 0xa0a
-#define APM_SYS_STANDBY_RESUME 0xa0b
-#define APM_IOC_NEXTEVENT 0xa0c
-#define APM_IOC_RESUME 0xa0d
-#define APM_IOC_SUSPEND 0xa0e
-#define APM_IOC_STANDBY 0xa0f
-#endif
-
-typedef struct apm_event_info
-{
- int type;
-} apm_event_info;
-
-/*
- This may be replaced with a better device name
- very soon...
-*/
-#define APM_DEVICE "/dev/srn"
-#define APM_DEVICE1 "/dev/apm"
-
-static pointer APMihPtr = NULL;
-static void sunCloseAPM(void);
-
-static struct {
- u_int apmBsd;
- pmEvent xf86;
-} sunToXF86Array [] = {
- { APM_STANDBY_REQ, XF86_APM_SYS_STANDBY },
- { APM_SUSPEND_REQ, XF86_APM_SYS_SUSPEND },
- { APM_NORMAL_RESUME, XF86_APM_NORMAL_RESUME },
- { APM_CRIT_RESUME, XF86_APM_CRITICAL_RESUME },
- { APM_BATTERY_LOW, XF86_APM_LOW_BATTERY },
- { APM_POWER_CHANGE, XF86_APM_POWER_STATUS_CHANGE },
- { APM_UPDATE_TIME, XF86_APM_UPDATE_TIME },
- { APM_CRIT_SUSPEND_REQ, XF86_APM_CRITICAL_SUSPEND },
- { APM_USER_STANDBY_REQ, XF86_APM_USER_STANDBY },
- { APM_USER_SUSPEND_REQ, XF86_APM_USER_SUSPEND },
- { APM_SYS_STANDBY_RESUME, XF86_APM_STANDBY_RESUME },
-#ifdef APM_CAPABILITY_CHANGE
- { APM_CAPABILITY_CHANGE, XF86_APM_CAPABILITY_CHANGED },
-#endif
-};
-
-#define numApmEvents (sizeof(sunToXF86Array) / sizeof(sunToXF86Array[0]))
-
-static pmEvent
-sunToXF86(int type)
-{
- int i;
-
- for (i = 0; i < numApmEvents; i++) {
- if (type == sunToXF86Array[i].apmBsd) {
- return sunToXF86Array[i].xf86;
- }
- }
- return XF86_APM_UNKNOWN;
-}
-
-/*
- * APM events can be requested direclty from /dev/apm
- */
-static int
-sunPMGetEventFromOS(int fd, pmEvent *events, int num)
-{
- struct apm_event_info sunEvent;
- int i;
-
- for (i = 0; i < num; i++) {
-
- if (ioctl(fd, APM_IOC_NEXTEVENT, &sunEvent) < 0) {
- if (errno != EAGAIN) {
- xf86Msg(X_WARNING, "sunPMGetEventFromOS: APM_IOC_NEXTEVENT"
- " %s\n", strerror(errno));
- }
- break;
- }
- events[i] = sunToXF86(sunEvent.type);
- }
- xf86Msg(X_WARNING, "Got some events\n");
- return i;
-}
-
-static pmWait
-sunPMConfirmEventToOs(int fd, pmEvent event)
-{
- switch (event) {
-/* XXX: NOT CURRENTLY RETURNED FROM OS */
- case XF86_APM_SYS_STANDBY:
- case XF86_APM_USER_STANDBY:
- if (ioctl( fd, APM_IOC_STANDBY, NULL ) == 0)
- return PM_WAIT; /* should we stop the Xserver in standby, too? */
- else
- return PM_NONE;
- case XF86_APM_SYS_SUSPEND:
- case XF86_APM_CRITICAL_SUSPEND:
- case XF86_APM_USER_SUSPEND:
- xf86Msg(X_WARNING, "Got SUSPENDED\n");
- if (ioctl( fd, APM_IOC_SUSPEND, NULL ) == 0)
- return PM_CONTINUE;
- else {
- xf86Msg(X_WARNING, "sunPMConfirmEventToOs: APM_IOC_SUSPEND"
- " %s\n", strerror(errno));
- return PM_FAILED;
- }
- case XF86_APM_STANDBY_RESUME:
- case XF86_APM_NORMAL_RESUME:
- case XF86_APM_CRITICAL_RESUME:
- case XF86_APM_STANDBY_FAILED:
- case XF86_APM_SUSPEND_FAILED:
- xf86Msg(X_WARNING, "Got RESUME\n");
- if (ioctl( fd, APM_IOC_RESUME, NULL ) == 0)
- return PM_CONTINUE;
- else {
- xf86Msg(X_WARNING, "sunPMConfirmEventToOs: APM_IOC_RESUME"
- " %s\n", strerror(errno));
- return PM_FAILED;
- }
- default:
- return PM_NONE;
- }
-}
-
-PMClose
-xf86OSPMOpen(void)
-{
- int fd;
-
- if (APMihPtr || !xf86Info.pmFlag) {
- return NULL;
- }
-
- if ((fd = open(APM_DEVICE, O_RDWR)) == -1) {
- if ((fd = open(APM_DEVICE1, O_RDWR)) == -1) {
- return NULL;
- }
- }
- xf86PMGetEventFromOs = sunPMGetEventFromOS;
- xf86PMConfirmEventToOs = sunPMConfirmEventToOs;
- APMihPtr = xf86AddGeneralHandler(fd, xf86HandlePMEvents, NULL);
- return sunCloseAPM;
-}
-
-static void
-sunCloseAPM(void)
-{
- int fd;
-
- if (APMihPtr) {
- fd = xf86RemoveGeneralHandler(APMihPtr);
- close(fd);
- APMihPtr = NULL;
- }
-}
+/* Based on hw/xfree86/os-support/bsd/bsd_apm.c which bore no explicit + * copyright notice, so is covered by the following notice: + * + * Copyright (C) 1994-2003 The XFree86 Project, Inc. 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 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 XFREE86 PROJECT 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 XFree86 Project 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 + * XFree86 Project. + */ + +/* Copyright (c) 2005, Oracle and/or its affiliates. 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 + * THE AUTHORS OR COPYRIGHT HOLDERS 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. + */ + +#ifdef HAVE_XORG_CONFIG_H +#include <xorg-config.h> +#endif + +#include <X11/X.h> +#include "os.h" +#include "xf86.h" +#include "xf86Priv.h" +#define XF86_OS_PRIVS +#include "xf86_OSproc.h" +#include "xf86_OSlib.h" + +#ifndef PLEASE_FIX_THIS +#define APM_STANDBY_REQ 0xa01 +#define APM_SUSPEND_REQ 0xa02 +#define APM_NORMAL_RESUME 0xa03 +#define APM_CRIT_RESUME 0xa04 +#define APM_BATTERY_LOW 0xa05 +#define APM_POWER_CHANGE 0xa06 +#define APM_UPDATE_TIME 0xa07 +#define APM_CRIT_SUSPEND_REQ 0xa08 +#define APM_USER_STANDBY_REQ 0xa09 +#define APM_USER_SUSPEND_REQ 0xa0a +#define APM_SYS_STANDBY_RESUME 0xa0b +#define APM_IOC_NEXTEVENT 0xa0c +#define APM_IOC_RESUME 0xa0d +#define APM_IOC_SUSPEND 0xa0e +#define APM_IOC_STANDBY 0xa0f +#endif + +typedef struct apm_event_info { + int type; +} apm_event_info; + +/* + This may be replaced with a better device name + very soon... +*/ +#define APM_DEVICE "/dev/srn" +#define APM_DEVICE1 "/dev/apm" + +static pointer APMihPtr = NULL; +static void sunCloseAPM(void); + +static struct { + u_int apmBsd; + pmEvent xf86; +} sunToXF86Array[] = { + { + APM_STANDBY_REQ, XF86_APM_SYS_STANDBY}, { + APM_SUSPEND_REQ, XF86_APM_SYS_SUSPEND}, { + APM_NORMAL_RESUME, XF86_APM_NORMAL_RESUME}, { + APM_CRIT_RESUME, XF86_APM_CRITICAL_RESUME}, { + APM_BATTERY_LOW, XF86_APM_LOW_BATTERY}, { + APM_POWER_CHANGE, XF86_APM_POWER_STATUS_CHANGE}, { + APM_UPDATE_TIME, XF86_APM_UPDATE_TIME}, { + APM_CRIT_SUSPEND_REQ, XF86_APM_CRITICAL_SUSPEND}, { + APM_USER_STANDBY_REQ, XF86_APM_USER_STANDBY}, { + APM_USER_SUSPEND_REQ, XF86_APM_USER_SUSPEND}, { + APM_SYS_STANDBY_RESUME, XF86_APM_STANDBY_RESUME}, +#ifdef APM_CAPABILITY_CHANGE + { + APM_CAPABILITY_CHANGE, XF86_APM_CAPABILITY_CHANGED}, +#endif +}; + +#define numApmEvents (sizeof(sunToXF86Array) / sizeof(sunToXF86Array[0])) + +static pmEvent +sunToXF86(int type) +{ + int i; + + for (i = 0; i < numApmEvents; i++) { + if (type == sunToXF86Array[i].apmBsd) { + return sunToXF86Array[i].xf86; + } + } + return XF86_APM_UNKNOWN; +} + +/* + * APM events can be requested direclty from /dev/apm + */ +static int +sunPMGetEventFromOS(int fd, pmEvent * events, int num) +{ + struct apm_event_info sunEvent; + int i; + + for (i = 0; i < num; i++) { + + if (ioctl(fd, APM_IOC_NEXTEVENT, &sunEvent) < 0) { + if (errno != EAGAIN) { + xf86Msg(X_WARNING, "sunPMGetEventFromOS: APM_IOC_NEXTEVENT" + " %s\n", strerror(errno)); + } + break; + } + events[i] = sunToXF86(sunEvent.type); + } + xf86Msg(X_WARNING, "Got some events\n"); + return i; +} + +static pmWait +sunPMConfirmEventToOs(int fd, pmEvent event) +{ + switch (event) { +/* XXX: NOT CURRENTLY RETURNED FROM OS */ + case XF86_APM_SYS_STANDBY: + case XF86_APM_USER_STANDBY: + if (ioctl(fd, APM_IOC_STANDBY, NULL) == 0) + return PM_WAIT; /* should we stop the Xserver in standby, too? */ + else + return PM_NONE; + case XF86_APM_SYS_SUSPEND: + case XF86_APM_CRITICAL_SUSPEND: + case XF86_APM_USER_SUSPEND: + xf86Msg(X_WARNING, "Got SUSPENDED\n"); + if (ioctl(fd, APM_IOC_SUSPEND, NULL) == 0) + return PM_CONTINUE; + else { + xf86Msg(X_WARNING, "sunPMConfirmEventToOs: APM_IOC_SUSPEND" + " %s\n", strerror(errno)); + return PM_FAILED; + } + case XF86_APM_STANDBY_RESUME: + case XF86_APM_NORMAL_RESUME: + case XF86_APM_CRITICAL_RESUME: + case XF86_APM_STANDBY_FAILED: + case XF86_APM_SUSPEND_FAILED: + xf86Msg(X_WARNING, "Got RESUME\n"); + if (ioctl(fd, APM_IOC_RESUME, NULL) == 0) + return PM_CONTINUE; + else { + xf86Msg(X_WARNING, "sunPMConfirmEventToOs: APM_IOC_RESUME" + " %s\n", strerror(errno)); + return PM_FAILED; + } + default: + return PM_NONE; + } +} + +PMClose +xf86OSPMOpen(void) +{ + int fd; + + if (APMihPtr || !xf86Info.pmFlag) { + return NULL; + } + + if ((fd = open(APM_DEVICE, O_RDWR)) == -1) { + if ((fd = open(APM_DEVICE1, O_RDWR)) == -1) { + return NULL; + } + } + xf86PMGetEventFromOs = sunPMGetEventFromOS; + xf86PMConfirmEventToOs = sunPMConfirmEventToOs; + APMihPtr = xf86AddGeneralHandler(fd, xf86HandlePMEvents, NULL); + return sunCloseAPM; +} + +static void +sunCloseAPM(void) +{ + int fd; + + if (APMihPtr) { + fd = xf86RemoveGeneralHandler(APMihPtr); + close(fd); + APMihPtr = NULL; + } +} diff --git a/xorg-server/hw/xfree86/os-support/solaris/sun_bell.c b/xorg-server/hw/xfree86/os-support/solaris/sun_bell.c index 8cd4de25b..beb13d2e9 100644 --- a/xorg-server/hw/xfree86/os-support/solaris/sun_bell.c +++ b/xorg-server/hw/xfree86/os-support/solaris/sun_bell.c @@ -1,180 +1,183 @@ -/* Copyright (c) 2004-2005, Oracle and/or its affiliates. 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
- * THE AUTHORS OR COPYRIGHT HOLDERS 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.
- */
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include <sys/audio.h>
-#include <sys/uio.h>
-#include <limits.h>
-#include <math.h>
-#include <poll.h>
-
-#include "xf86.h"
-#include "xf86Priv.h"
-#include "xf86_OSlib.h"
-
-#define BELL_RATE 48000 /* Samples per second */
-#define BELL_HZ 50 /* Fraction of a second i.e. 1/x */
-#define BELL_MS (1000/BELL_HZ) /* MS */
-#define BELL_SAMPLES (BELL_RATE / BELL_HZ)
-#define BELL_MIN 3 /* Min # of repeats */
-
-#define AUDIO_DEVICE "/dev/audio"
-
-void
-xf86OSRingBell(int loudness, int pitch, int duration)
-{
- static short samples[BELL_SAMPLES];
- static short silence[BELL_SAMPLES]; /* "The Sound of Silence" */
- static int lastFreq;
- int cnt;
- int i;
- int written;
- int repeats;
- int freq;
- audio_info_t audioInfo;
- struct iovec iov[IOV_MAX];
- int iovcnt;
- double ampl, cyclen, phase;
- int audioFD;
-
- if ((loudness <= 0) || (pitch <= 0) || (duration <= 0)) {
- return;
- }
-
- lastFreq = 0;
- memset(silence, 0, sizeof(silence));
-
- audioFD = open(AUDIO_DEVICE, O_WRONLY | O_NONBLOCK);
- if (audioFD == -1) {
- xf86Msg(X_ERROR, "Bell: cannot open audio device \"%s\": %s\n",
- AUDIO_DEVICE, strerror(errno));
- return;
- }
-
- freq = pitch;
- freq = min(freq, (BELL_RATE / 2) - 1);
- freq = max(freq, 2 * BELL_HZ);
-
- /*
- * Ensure full waves per buffer
- */
- freq -= freq % BELL_HZ;
-
- if (freq != lastFreq) {
- lastFreq = freq;
- ampl = 16384.0;
-
- cyclen = (double) freq / (double) BELL_RATE;
- phase = 0.0;
-
- for (i = 0; i < BELL_SAMPLES; i++) {
- samples[i] = (short) (ampl * sin(2.0 * M_PI * phase));
- phase += cyclen;
- if (phase >= 1.0)
- phase -= 1.0;
- }
- }
-
- repeats = (duration + (BELL_MS / 2)) / BELL_MS;
- repeats = max(repeats, BELL_MIN);
-
- loudness = max(0, loudness);
- loudness = min(loudness, 100);
-
-#ifdef DEBUG
- ErrorF("BELL : freq %d volume %d duration %d repeats %d\n",
- freq, loudness, duration, repeats);
-#endif
-
- AUDIO_INITINFO(&audioInfo);
- audioInfo.play.encoding = AUDIO_ENCODING_LINEAR;
- audioInfo.play.sample_rate = BELL_RATE;
- audioInfo.play.channels = 2;
- audioInfo.play.precision = 16;
- audioInfo.play.gain = min(AUDIO_MAX_GAIN, AUDIO_MAX_GAIN * loudness / 100);
-
- if (ioctl(audioFD, AUDIO_SETINFO, &audioInfo) < 0){
- xf86Msg(X_ERROR,
- "Bell: AUDIO_SETINFO failed on audio device \"%s\": %s\n",
- AUDIO_DEVICE, strerror(errno));
- close(audioFD);
- return;
- }
-
- iovcnt = 0;
-
- for (cnt = 0; cnt <= repeats; cnt++) {
- if (cnt == repeats) {
- /* Insert a bit of silence so that multiple beeps are distinct and
- * not compressed into a single tone.
- */
- iov[iovcnt].iov_base = (char *) silence;
- iov[iovcnt++].iov_len = sizeof(silence);
- } else {
- iov[iovcnt].iov_base = (char *) samples;
- iov[iovcnt++].iov_len = sizeof(samples);
- }
- if ((iovcnt >= IOV_MAX) || (cnt == repeats)) {
- written = writev(audioFD, iov, iovcnt);
-
- if ((written < ((int)(sizeof(samples) * iovcnt)))) {
- /* audio buffer was full! */
-
- int naptime;
-
- if (written == -1) {
- if (errno != EAGAIN) {
- xf86Msg(X_ERROR,
- "Bell: writev failed on audio device \"%s\": %s\n",
- AUDIO_DEVICE, strerror(errno));
- close(audioFD);
- return;
- }
- i = iovcnt;
- } else {
- i = ((sizeof(samples) * iovcnt) - written)
- / sizeof(samples);
- }
- cnt -= i;
-
- /* sleep a little to allow audio buffer to drain */
- naptime = BELL_MS * i;
- poll(NULL, 0, naptime);
-
- i = ((sizeof(samples) * iovcnt) - written) % sizeof(samples);
- iovcnt = 0;
- if ((written != -1) && (i > 0)) {
- iov[iovcnt].iov_base = ((char *) samples) + i;
- iov[iovcnt++].iov_len = sizeof(samples) - i;
- }
- } else {
- iovcnt = 0;
- }
- }
- }
-
- close(audioFD);
- return;
-}
+/* Copyright (c) 2004-2005, Oracle and/or its affiliates. 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 + * THE AUTHORS OR COPYRIGHT HOLDERS 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. + */ + +#ifdef HAVE_XORG_CONFIG_H +#include <xorg-config.h> +#endif + +#include <sys/audio.h> +#include <sys/uio.h> +#include <limits.h> +#include <math.h> +#include <poll.h> + +#include "xf86.h" +#include "xf86Priv.h" +#include "xf86_OSlib.h" + +#define BELL_RATE 48000 /* Samples per second */ +#define BELL_HZ 50 /* Fraction of a second i.e. 1/x */ +#define BELL_MS (1000/BELL_HZ) /* MS */ +#define BELL_SAMPLES (BELL_RATE / BELL_HZ) +#define BELL_MIN 3 /* Min # of repeats */ + +#define AUDIO_DEVICE "/dev/audio" + +void +xf86OSRingBell(int loudness, int pitch, int duration) +{ + static short samples[BELL_SAMPLES]; + static short silence[BELL_SAMPLES]; /* "The Sound of Silence" */ + static int lastFreq; + int cnt; + int i; + int written; + int repeats; + int freq; + audio_info_t audioInfo; + struct iovec iov[IOV_MAX]; + int iovcnt; + double ampl, cyclen, phase; + int audioFD; + + if ((loudness <= 0) || (pitch <= 0) || (duration <= 0)) { + return; + } + + lastFreq = 0; + memset(silence, 0, sizeof(silence)); + + audioFD = open(AUDIO_DEVICE, O_WRONLY | O_NONBLOCK); + if (audioFD == -1) { + xf86Msg(X_ERROR, "Bell: cannot open audio device \"%s\": %s\n", + AUDIO_DEVICE, strerror(errno)); + return; + } + + freq = pitch; + freq = min(freq, (BELL_RATE / 2) - 1); + freq = max(freq, 2 * BELL_HZ); + + /* + * Ensure full waves per buffer + */ + freq -= freq % BELL_HZ; + + if (freq != lastFreq) { + lastFreq = freq; + ampl = 16384.0; + + cyclen = (double) freq / (double) BELL_RATE; + phase = 0.0; + + for (i = 0; i < BELL_SAMPLES; i++) { + samples[i] = (short) (ampl * sin(2.0 * M_PI * phase)); + phase += cyclen; + if (phase >= 1.0) + phase -= 1.0; + } + } + + repeats = (duration + (BELL_MS / 2)) / BELL_MS; + repeats = max(repeats, BELL_MIN); + + loudness = max(0, loudness); + loudness = min(loudness, 100); + +#ifdef DEBUG + ErrorF("BELL : freq %d volume %d duration %d repeats %d\n", + freq, loudness, duration, repeats); +#endif + + AUDIO_INITINFO(&audioInfo); + audioInfo.play.encoding = AUDIO_ENCODING_LINEAR; + audioInfo.play.sample_rate = BELL_RATE; + audioInfo.play.channels = 2; + audioInfo.play.precision = 16; + audioInfo.play.gain = min(AUDIO_MAX_GAIN, AUDIO_MAX_GAIN * loudness / 100); + + if (ioctl(audioFD, AUDIO_SETINFO, &audioInfo) < 0) { + xf86Msg(X_ERROR, + "Bell: AUDIO_SETINFO failed on audio device \"%s\": %s\n", + AUDIO_DEVICE, strerror(errno)); + close(audioFD); + return; + } + + iovcnt = 0; + + for (cnt = 0; cnt <= repeats; cnt++) { + if (cnt == repeats) { + /* Insert a bit of silence so that multiple beeps are distinct and + * not compressed into a single tone. + */ + iov[iovcnt].iov_base = (char *) silence; + iov[iovcnt++].iov_len = sizeof(silence); + } + else { + iov[iovcnt].iov_base = (char *) samples; + iov[iovcnt++].iov_len = sizeof(samples); + } + if ((iovcnt >= IOV_MAX) || (cnt == repeats)) { + written = writev(audioFD, iov, iovcnt); + + if ((written < ((int) (sizeof(samples) * iovcnt)))) { + /* audio buffer was full! */ + + int naptime; + + if (written == -1) { + if (errno != EAGAIN) { + xf86Msg(X_ERROR, + "Bell: writev failed on audio device \"%s\": %s\n", + AUDIO_DEVICE, strerror(errno)); + close(audioFD); + return; + } + i = iovcnt; + } + else { + i = ((sizeof(samples) * iovcnt) - written) + / sizeof(samples); + } + cnt -= i; + + /* sleep a little to allow audio buffer to drain */ + naptime = BELL_MS * i; + poll(NULL, 0, naptime); + + i = ((sizeof(samples) * iovcnt) - written) % sizeof(samples); + iovcnt = 0; + if ((written != -1) && (i > 0)) { + iov[iovcnt].iov_base = ((char *) samples) + i; + iov[iovcnt++].iov_len = sizeof(samples) - i; + } + } + else { + iovcnt = 0; + } + } + } + + close(audioFD); + return; +} diff --git a/xorg-server/hw/xfree86/os-support/solaris/sun_init.c b/xorg-server/hw/xfree86/os-support/solaris/sun_init.c index 800fc1c3d..4b75a98ac 100644 --- a/xorg-server/hw/xfree86/os-support/solaris/sun_init.c +++ b/xorg-server/hw/xfree86/os-support/solaris/sun_init.c @@ -30,7 +30,7 @@ #include "xf86Priv.h" #include "xf86_OSlib.h" #ifdef HAVE_SYS_KD_H -# include <sys/kd.h> +#include <sys/kd.h> #endif /* @@ -48,6 +48,7 @@ static Bool KeepTty = FALSE; static Bool Protect0 = FALSE; static Bool UseConsole = FALSE; + #ifdef HAS_USL_VTS static int VTnum = -1; static int xf86StartVT = -1; @@ -71,18 +72,19 @@ switch_to(int vt, const char *from) SYSCALL(ret = ioctl(xf86Info.consoleFd, VT_ACTIVATE, vt)); if (ret != 0) xf86Msg(X_WARNING, "%s: VT_ACTIVATE failed: %s\n", - from, strerror(errno)); + from, strerror(errno)); SYSCALL(ret = ioctl(xf86Info.consoleFd, VT_WAITACTIVE, vt)); if (ret != 0) xf86Msg(X_WARNING, "%s: VT_WAITACTIVE failed: %s\n", - from, strerror(errno)); + from, strerror(errno)); } void xf86OpenConsole(void) { int i; + #ifdef HAS_USL_VTS int fd; struct vt_mode VT; @@ -90,209 +92,192 @@ xf86OpenConsole(void) MessageType from = X_PROBED; #endif - if (serverGeneration == 1) - { - /* Check if we're run with euid==0 */ - if (geteuid() != 0) - FatalError("xf86OpenConsole: Server must be suid root\n"); - - /* Protect page 0 to help find NULL dereferencing */ - /* mprotect() doesn't seem to work */ - if (Protect0) - { - int fd = -1; - - if ((fd = open("/dev/zero", O_RDONLY, 0)) < 0) - { - xf86Msg(X_WARNING, - "xf86OpenConsole: cannot open /dev/zero (%s)\n", - strerror(errno)); - } - else - { - if (mmap(0, 0x1000, PROT_NONE, - MAP_FIXED | MAP_SHARED, fd, 0) == MAP_FAILED) - xf86Msg(X_WARNING, - "xf86OpenConsole: failed to protect page 0 (%s)\n", - strerror(errno)); - - close(fd); - } - } + if (serverGeneration == 1) { + /* Check if we're run with euid==0 */ + if (geteuid() != 0) + FatalError("xf86OpenConsole: Server must be suid root\n"); + + /* Protect page 0 to help find NULL dereferencing */ + /* mprotect() doesn't seem to work */ + if (Protect0) { + int fd = -1; + + if ((fd = open("/dev/zero", O_RDONLY, 0)) < 0) { + xf86Msg(X_WARNING, + "xf86OpenConsole: cannot open /dev/zero (%s)\n", + strerror(errno)); + } + else { + if (mmap(0, 0x1000, PROT_NONE, + MAP_FIXED | MAP_SHARED, fd, 0) == MAP_FAILED) + xf86Msg(X_WARNING, + "xf86OpenConsole: failed to protect page 0 (%s)\n", + strerror(errno)); + + close(fd); + } + } #ifdef HAS_USL_VTS - /* - * Setup the virtual terminal manager - */ - if ((fd = open("/dev/vt/0",O_RDWR,0)) == -1) - { - xf86ErrorF("xf86OpenConsole: Cannot open /dev/vt/0 (%s)\n", - strerror(errno)); - vtEnabled = 0; - } - else - { - if (ioctl(fd, VT_ENABLED, &vtEnabled) < 0) - { - xf86ErrorF("xf86OpenConsole: VT_ENABLED failed (%s)\n", - strerror(errno)); - vtEnabled = 0; - } - } -#endif /* HAS_USL_VTS */ - - if (UseConsole) - { - strlcpy(consoleDev, SOL_CONSOLE_DEV, sizeof(consoleDev)); + /* + * Setup the virtual terminal manager + */ + if ((fd = open("/dev/vt/0", O_RDWR, 0)) == -1) { + xf86ErrorF("xf86OpenConsole: Cannot open /dev/vt/0 (%s)\n", + strerror(errno)); + vtEnabled = 0; + } + else { + if (ioctl(fd, VT_ENABLED, &vtEnabled) < 0) { + xf86ErrorF("xf86OpenConsole: VT_ENABLED failed (%s)\n", + strerror(errno)); + vtEnabled = 0; + } + } +#endif /* HAS_USL_VTS */ + + if (UseConsole) { + strlcpy(consoleDev, SOL_CONSOLE_DEV, sizeof(consoleDev)); #ifdef HAS_USL_VTS - xf86Info.vtno = CONSOLE_VTNO; - - if (vtEnabled == 0) - { - xf86StartVT = 0; - } - else - { - if (ioctl(fd, VT_GETSTATE, &vtinfo) < 0) - FatalError("xf86OpenConsole: Cannot determine current VT\n"); - xf86StartVT = vtinfo.v_active; - } -#endif /* HAS_USL_VTS */ - goto OPENCONSOLE; - } + xf86Info.vtno = CONSOLE_VTNO; + + if (vtEnabled == 0) { + xf86StartVT = 0; + } + else { + if (ioctl(fd, VT_GETSTATE, &vtinfo) < 0) + FatalError + ("xf86OpenConsole: Cannot determine current VT\n"); + xf86StartVT = vtinfo.v_active; + } +#endif /* HAS_USL_VTS */ + goto OPENCONSOLE; + } #ifdef HAS_USL_VTS - if (vtEnabled == 0) - { - /* VT not enabled - kernel too old or Sparc platforms - without visual_io support */ - xf86Msg(from, "VT infrastructure is not available\n"); - - xf86StartVT = 0; - xf86Info.vtno = 0; - strlcpy(consoleDev, xf86SolarisFbDev, sizeof(consoleDev)); - goto OPENCONSOLE; - } - - if (ioctl(fd, VT_GETSTATE, &vtinfo) < 0) - FatalError("xf86OpenConsole: Cannot determine current VT\n"); - - xf86StartVT = vtinfo.v_active; - - if (VTnum != -1) - { - xf86Info.vtno = VTnum; - from = X_CMDLINE; - } - else if (xf86Info.ShareVTs) - { - xf86Info.vtno = vtinfo.v_active; - from = X_CMDLINE; - } - else - { - if ((ioctl(fd, VT_OPENQRY, &xf86Info.vtno) < 0) || - (xf86Info.vtno == -1)) - { - FatalError("xf86OpenConsole: Cannot find a free VT\n"); - } - } - - xf86Msg(from, "using VT number %d\n\n", xf86Info.vtno); - snprintf(consoleDev, PATH_MAX, "/dev/vt/%d", xf86Info.vtno); - - if (fd != -1) - { - close(fd); - } - -#endif /* HAS_USL_VTS */ - -OPENCONSOLE: - if (!KeepTty) - setpgrp(); - - if (((xf86Info.consoleFd = open(consoleDev, O_RDWR | O_NDELAY, 0)) < 0)) - FatalError("xf86OpenConsole: Cannot open %s (%s)\n", - consoleDev, strerror(errno)); - - /* Change ownership of the vt or console */ - chown(consoleDev, getuid(), getgid()); + if (vtEnabled == 0) { + /* VT not enabled - kernel too old or Sparc platforms + without visual_io support */ + xf86Msg(from, "VT infrastructure is not available\n"); + + xf86StartVT = 0; + xf86Info.vtno = 0; + strlcpy(consoleDev, xf86SolarisFbDev, sizeof(consoleDev)); + goto OPENCONSOLE; + } + + if (ioctl(fd, VT_GETSTATE, &vtinfo) < 0) + FatalError("xf86OpenConsole: Cannot determine current VT\n"); + + xf86StartVT = vtinfo.v_active; + + if (VTnum != -1) { + xf86Info.vtno = VTnum; + from = X_CMDLINE; + } + else if (xf86Info.ShareVTs) { + xf86Info.vtno = vtinfo.v_active; + from = X_CMDLINE; + } + else { + if ((ioctl(fd, VT_OPENQRY, &xf86Info.vtno) < 0) || + (xf86Info.vtno == -1)) { + FatalError("xf86OpenConsole: Cannot find a free VT\n"); + } + } + + xf86Msg(from, "using VT number %d\n\n", xf86Info.vtno); + snprintf(consoleDev, PATH_MAX, "/dev/vt/%d", xf86Info.vtno); + + if (fd != -1) { + close(fd); + } + +#endif /* HAS_USL_VTS */ + + OPENCONSOLE: + if (!KeepTty) + setpgrp(); + + if (((xf86Info.consoleFd = open(consoleDev, O_RDWR | O_NDELAY, 0)) < 0)) + FatalError("xf86OpenConsole: Cannot open %s (%s)\n", + consoleDev, strerror(errno)); + + /* Change ownership of the vt or console */ + chown(consoleDev, getuid(), getgid()); #ifdef HAS_USL_VTS - if (xf86Info.ShareVTs) - return; - - if (vtEnabled) - { - /* - * Now get the VT - */ - switch_to(xf86Info.vtno, "xf86OpenConsole"); - -#ifdef VT_SET_CONSUSER /* added in snv_139 */ - if (strcmp(display, "0") == 0) - if (ioctl(xf86Info.consoleFd, VT_SET_CONSUSER) != 0) - xf86Msg(X_WARNING, - "xf86OpenConsole: VT_SET_CONSUSER failed\n"); + if (xf86Info.ShareVTs) + return; + + if (vtEnabled) { + /* + * Now get the VT + */ + switch_to(xf86Info.vtno, "xf86OpenConsole"); + +#ifdef VT_SET_CONSUSER /* added in snv_139 */ + if (strcmp(display, "0") == 0) + if (ioctl(xf86Info.consoleFd, VT_SET_CONSUSER) != 0) + xf86Msg(X_WARNING, + "xf86OpenConsole: VT_SET_CONSUSER failed\n"); #endif - if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) < 0) - FatalError("xf86OpenConsole: VT_GETMODE failed\n"); + if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) < 0) + FatalError("xf86OpenConsole: VT_GETMODE failed\n"); - OsSignal(SIGUSR1, xf86VTAcquire); - OsSignal(SIGUSR2, xf86VTRelease); + OsSignal(SIGUSR1, xf86VTAcquire); + OsSignal(SIGUSR2, xf86VTRelease); - VT.mode = VT_PROCESS; - VT.acqsig = SIGUSR1; - VT.relsig = SIGUSR2; + VT.mode = VT_PROCESS; + VT.acqsig = SIGUSR1; + VT.relsig = SIGUSR2; - if (ioctl(xf86Info.consoleFd, VT_SETMODE, &VT) < 0) - FatalError("xf86OpenConsole: VT_SETMODE VT_PROCESS failed\n"); + if (ioctl(xf86Info.consoleFd, VT_SETMODE, &VT) < 0) + FatalError("xf86OpenConsole: VT_SETMODE VT_PROCESS failed\n"); - if (ioctl(xf86Info.consoleFd, VT_SETDISPINFO, atoi(display)) < 0) - xf86Msg(X_WARNING, "xf86OpenConsole: VT_SETDISPINFO failed\n"); - } + if (ioctl(xf86Info.consoleFd, VT_SETDISPINFO, atoi(display)) < 0) + xf86Msg(X_WARNING, "xf86OpenConsole: VT_SETDISPINFO failed\n"); + } #endif #ifdef KDSETMODE - SYSCALL(i = ioctl(xf86Info.consoleFd, KDSETMODE, KD_GRAPHICS)); - if (i < 0) { - xf86Msg(X_WARNING, - "xf86OpenConsole: KDSETMODE KD_GRAPHICS failed on %s (%s)\n", - consoleDev, strerror(errno)); - } + SYSCALL(i = ioctl(xf86Info.consoleFd, KDSETMODE, KD_GRAPHICS)); + if (i < 0) { + xf86Msg(X_WARNING, + "xf86OpenConsole: KDSETMODE KD_GRAPHICS failed on %s (%s)\n", + consoleDev, strerror(errno)); + } #endif } - else /* serverGeneration != 1 */ - { + else { /* serverGeneration != 1 */ + #ifdef HAS_USL_VTS - if (vtEnabled && !xf86Info.ShareVTs) - { - /* - * Now re-get the VT - */ - if (xf86Info.autoVTSwitch) - switch_to(xf86Info.vtno, "xf86OpenConsole"); - -#ifdef VT_SET_CONSUSER /* added in snv_139 */ - if (strcmp(display, "0") == 0) - if (ioctl(xf86Info.consoleFd, VT_SET_CONSUSER) != 0) - xf86Msg(X_WARNING, - "xf86OpenConsole: VT_SET_CONSUSER failed\n"); + if (vtEnabled && !xf86Info.ShareVTs) { + /* + * Now re-get the VT + */ + if (xf86Info.autoVTSwitch) + switch_to(xf86Info.vtno, "xf86OpenConsole"); + +#ifdef VT_SET_CONSUSER /* added in snv_139 */ + if (strcmp(display, "0") == 0) + if (ioctl(xf86Info.consoleFd, VT_SET_CONSUSER) != 0) + xf86Msg(X_WARNING, + "xf86OpenConsole: VT_SET_CONSUSER failed\n"); #endif - /* - * If the server doesn't have the VT when the reset occurs, - * this is to make sure we don't continue until the activate - * signal is received. - */ - if (!xf86Screens[0]->vtSema) - sleep(5); - } -#endif /* HAS_USL_VTS */ + /* + * If the server doesn't have the VT when the reset occurs, + * this is to make sure we don't continue until the activate + * signal is received. + */ + if (!xf86Screens[0]->vtSema) + sleep(5); + } +#endif /* HAS_USL_VTS */ } } @@ -307,44 +292,47 @@ xf86CloseConsole(void) #if !defined(__i386__) && !defined(__i386) && !defined(__x86) if (!xf86DoConfigure) { - int fd; - - /* - * Wipe out framebuffer just like the non-SI Xsun server does. This - * could be improved by saving framebuffer contents in - * xf86OpenConsole() above and restoring them here. Also, it's unclear - * at this point whether this should be done for all framebuffers in - * the system, rather than only the console. - */ - if ((fd = open(xf86SolarisFbDev, O_RDWR, 0)) < 0) { - xf86Msg(X_WARNING, - "xf86CloseConsole(): unable to open framebuffer (%s)\n", - strerror(errno)); - } else { - struct fbgattr fbattr; - - if ((ioctl(fd, FBIOGATTR, &fbattr) < 0) && - (ioctl(fd, FBIOGTYPE, &fbattr.fbtype) < 0)) { - xf86Msg(X_WARNING, - "xf86CloseConsole(): unable to retrieve framebuffer" - " attributes (%s)\n", strerror(errno)); - } else { - pointer fbdata; - - fbdata = mmap(NULL, fbattr.fbtype.fb_size, - PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); - if (fbdata == MAP_FAILED) { - xf86Msg(X_WARNING, - "xf86CloseConsole(): unable to mmap framebuffer" - " (%s)\n", strerror(errno)); - } else { - memset(fbdata, 0, fbattr.fbtype.fb_size); - munmap(fbdata, fbattr.fbtype.fb_size); - } - } - - close(fd); - } + int fd; + + /* + * Wipe out framebuffer just like the non-SI Xsun server does. This + * could be improved by saving framebuffer contents in + * xf86OpenConsole() above and restoring them here. Also, it's unclear + * at this point whether this should be done for all framebuffers in + * the system, rather than only the console. + */ + if ((fd = open(xf86SolarisFbDev, O_RDWR, 0)) < 0) { + xf86Msg(X_WARNING, + "xf86CloseConsole(): unable to open framebuffer (%s)\n", + strerror(errno)); + } + else { + struct fbgattr fbattr; + + if ((ioctl(fd, FBIOGATTR, &fbattr) < 0) && + (ioctl(fd, FBIOGTYPE, &fbattr.fbtype) < 0)) { + xf86Msg(X_WARNING, + "xf86CloseConsole(): unable to retrieve framebuffer" + " attributes (%s)\n", strerror(errno)); + } + else { + pointer fbdata; + + fbdata = mmap(NULL, fbattr.fbtype.fb_size, + PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + if (fbdata == MAP_FAILED) { + xf86Msg(X_WARNING, + "xf86CloseConsole(): unable to mmap framebuffer" + " (%s)\n", strerror(errno)); + } + else { + memset(fbdata, 0, fbattr.fbtype.fb_size); + munmap(fbdata, fbattr.fbtype.fb_size); + } + } + + close(fd); + } } #endif @@ -355,19 +343,17 @@ xf86CloseConsole(void) #endif #ifdef HAS_USL_VTS - if (vtEnabled) - { - if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) != -1) - { - VT.mode = VT_AUTO; /* Set default vt handling */ - ioctl(xf86Info.consoleFd, VT_SETMODE, &VT); - } - - /* Activate the VT that X was started on */ - if (xf86Info.autoVTSwitch) - switch_to(xf86StartVT, "xf86CloseConsole"); + if (vtEnabled) { + if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) != -1) { + VT.mode = VT_AUTO; /* Set default vt handling */ + ioctl(xf86Info.consoleFd, VT_SETMODE, &VT); + } + + /* Activate the VT that X was started on */ + if (xf86Info.autoVTSwitch) + switch_to(xf86StartVT, "xf86CloseConsole"); } -#endif /* HAS_USL_VTS */ +#endif /* HAS_USL_VTS */ close(xf86Info.consoleFd); } @@ -379,58 +365,54 @@ xf86ProcessArgument(int argc, char **argv, int i) * Keep server from detaching from controlling tty. This is useful when * debugging, so the server can receive keyboard signals. */ - if (!strcmp(argv[i], "-keeptty")) - { - KeepTty = TRUE; - return 1; + if (!strcmp(argv[i], "-keeptty")) { + KeepTty = TRUE; + return 1; } /* * Undocumented flag to protect page 0 from read/write to help catch NULL * pointer dereferences. This is purely a debugging flag. */ - if (!strcmp(argv[i], "-protect0")) - { - Protect0 = TRUE; - return 1; + if (!strcmp(argv[i], "-protect0")) { + Protect0 = TRUE; + return 1; } /* * Use /dev/console as the console device. */ - if (!strcmp(argv[i], "-C")) - { - UseConsole = TRUE; - return 1; + if (!strcmp(argv[i], "-C")) { + UseConsole = TRUE; + return 1; } #ifdef HAS_USL_VTS - if ((argv[i][0] == 'v') && (argv[i][1] == 't')) - { - if (sscanf(argv[i], "vt%d", &VTnum) == 0) - { - UseMsg(); - VTnum = -1; - return 0; - } + if ((argv[i][0] == 'v') && (argv[i][1] == 't')) { + if (sscanf(argv[i], "vt%d", &VTnum) == 0) { + UseMsg(); + VTnum = -1; + return 0; + } - return 1; + return 1; } -#endif /* HAS_USL_VTS */ +#endif /* HAS_USL_VTS */ if ((i + 1) < argc) { - if (!strcmp(argv[i], "-dev")) { - strlcpy(xf86SolarisFbDev, argv[i+1], sizeof(xf86SolarisFbDev)); - return 2; - } + if (!strcmp(argv[i], "-dev")) { + strlcpy(xf86SolarisFbDev, argv[i + 1], sizeof(xf86SolarisFbDev)); + return 2; + } } return 0; } -void xf86UseMsg(void) +void +xf86UseMsg(void) { #ifdef HAS_USL_VTS ErrorF("vtX Use the specified VT number\n"); diff --git a/xorg-server/hw/xfree86/os-support/solaris/sun_vid.c b/xorg-server/hw/xfree86/os-support/solaris/sun_vid.c index b7b7c0ed7..67ef17689 100644 --- a/xorg-server/hw/xfree86/os-support/solaris/sun_vid.c +++ b/xorg-server/hw/xfree86/os-support/solaris/sun_vid.c @@ -1,258 +1,247 @@ -/*
- * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany
- * Copyright 1993 by David Wexelblat <dwex@goblin.org>
- * Copyright 1999 by David Holland <davidh@iquest.net>
- *
- * Permission to use, copy, modify, distribute, and sell this software and its
- * documentation for any purpose is hereby granted without fee, provided that
- * the above copyright notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting documentation, and
- * that the names of the copyright holders not be used in advertising or
- * publicity pertaining to distribution of the software without specific,
- * written prior permission. The copyright holders make no representations
- * about the suitability of this software for any purpose. It is provided "as
- * is" without express or implied warranty.
- *
- * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT
- * SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
- * OF THIS SOFTWARE.
- *
- */
-/* Copyright (c) 2008, Oracle and/or its affiliates. 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
- * THE AUTHORS OR COPYRIGHT HOLDERS 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.
- */
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include <sys/types.h> /* get __x86 definition if not set by compiler */
-
-#if defined(__i386__) || defined(__i386) || defined(__x86)
-# define _NEED_SYSI86
-#endif
-#include "xf86.h"
-#include "xf86Priv.h"
-#include "xf86_OSlib.h"
-#include "xf86OSpriv.h"
-#include <sys/mman.h>
-
-/***************************************************************************/
-/* Video Memory Mapping section */
-/***************************************************************************/
-
-static char *apertureDevName = NULL;
-static int apertureDevFD_ro = -1;
-static int apertureDevFD_rw = -1;
-
-static Bool
-solOpenAperture(void)
-{
- if (apertureDevName == NULL)
- {
- apertureDevName = "/dev/xsvc";
- if ((apertureDevFD_rw = open(apertureDevName, O_RDWR)) < 0)
- {
- xf86MsgVerb(X_WARNING, 0,
- "solOpenAperture: failed to open %s (%s)\n",
- apertureDevName, strerror(errno));
- apertureDevName = "/dev/fbs/aperture";
- apertureDevFD_rw = open(apertureDevName, O_RDWR);
- }
- apertureDevFD_ro = open(apertureDevName, O_RDONLY);
-
- if ((apertureDevFD_rw < 0) || (apertureDevFD_ro < 0))
- {
- xf86MsgVerb(X_WARNING, 0,
- "solOpenAperture: failed to open %s (%s)\n",
- apertureDevName, strerror(errno));
- xf86MsgVerb(X_WARNING, 0,
- "solOpenAperture: either /dev/fbs/aperture"
- " or /dev/xsvc required\n");
-
- apertureDevName = NULL;
-
- if (apertureDevFD_rw >= 0)
- {
- close(apertureDevFD_rw);
- }
- apertureDevFD_rw = -1;
-
- if (apertureDevFD_ro >= 0)
- {
- close(apertureDevFD_ro);
- }
- apertureDevFD_ro = -1;
-
- return FALSE;
- }
- }
- return TRUE;
-}
-
-static pointer
-solMapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int Flags)
-{
- pointer base;
- int fd;
- int prot;
-
- if (Flags & VIDMEM_READONLY)
- {
- fd = apertureDevFD_ro;
- prot = PROT_READ;
- }
- else
- {
- fd = apertureDevFD_rw;
- prot = PROT_READ | PROT_WRITE;
- }
-
- if (fd < 0)
- {
- xf86DrvMsg(ScreenNum, X_ERROR,
- "solMapVidMem: failed to open %s (%s)\n",
- apertureDevName, strerror(errno));
- return NULL;
- }
-
- base = mmap(NULL, Size, prot, MAP_SHARED, fd, (off_t)Base);
-
- if (base == MAP_FAILED) {
- xf86DrvMsg(ScreenNum, X_ERROR,
- "solMapVidMem: failed to mmap %s (0x%08lx,0x%lx) (%s)\n",
- apertureDevName, Base, Size, strerror(errno));
- return NULL;
- }
-
- return base;
-}
-
-/* ARGSUSED */
-static void
-solUnMapVidMem(int ScreenNum, pointer Base, unsigned long Size)
-{
- if (munmap(Base, Size) != 0) {
- xf86DrvMsgVerb(ScreenNum, X_WARNING, 0,
- "solUnMapVidMem: failed to unmap %s"
- " (0x%p,0x%lx) (%s)\n",
- apertureDevName, Base, Size,
- strerror(errno));
- }
-}
-
-_X_HIDDEN void
-xf86OSInitVidMem(VidMemInfoPtr pVidMem)
-{
- pVidMem->linearSupported = solOpenAperture();
- if (pVidMem->linearSupported) {
- pVidMem->mapMem = solMapVidMem;
- pVidMem->unmapMem = solUnMapVidMem;
- } else {
- xf86MsgVerb(X_WARNING, 0,
- "xf86OSInitVidMem: linear memory access disabled\n");
- }
- pVidMem->initialised = TRUE;
-}
-
-/*
- * Read BIOS via mmap()ing physical memory.
- */
-int
-xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf,
- int Len)
-{
- unsigned char *ptr;
- int psize;
- int mlen;
-
- psize = getpagesize();
- Offset += Base & (psize - 1);
- Base &= ~(psize - 1);
- mlen = (Offset + Len + psize - 1) & ~(psize - 1);
-
- if (solOpenAperture() == FALSE)
- {
- xf86Msg(X_WARNING,
- "xf86ReadBIOS: Failed to open aperture to read BIOS\n");
- return -1;
- }
-
- ptr = (unsigned char *)mmap(NULL, mlen, PROT_READ,
- MAP_SHARED, apertureDevFD_ro, (off_t)Base);
- if (ptr == MAP_FAILED)
- {
- xf86Msg(X_WARNING, "xf86ReadBIOS: %s mmap failed [0x%08lx, 0x%04x]\n",
- apertureDevName, Base, mlen);
- return -1;
- }
-
- (void)memcpy(Buf, (void *)(ptr + Offset), Len);
- if (munmap((caddr_t)ptr, mlen) != 0) {
- xf86MsgVerb(X_WARNING, 0,
- "xf86ReadBIOS: failed to unmap %s (0x%p,0x%x) (%s)\n",
- apertureDevName, ptr, mlen, strerror(errno));
- }
-
- return Len;
-}
-
-
-/***************************************************************************/
-/* I/O Permissions section */
-/***************************************************************************/
-
-#if defined(__i386__) || defined(__i386) || defined(__x86)
-static Bool ExtendedEnabled = FALSE;
-#endif
-
-Bool
-xf86EnableIO(void)
-{
-#if defined(__i386__) || defined(__i386) || defined(__x86)
- if (ExtendedEnabled)
- return TRUE;
-
- if (sysi86(SI86V86, V86SC_IOPL, PS_IOPL) < 0) {
- xf86Msg(X_WARNING, "xf86EnableIOPorts: Failed to set IOPL for I/O\n");
- return FALSE;
- }
- ExtendedEnabled = TRUE;
-#endif /* i386 */
- return TRUE;
-}
-
-void
-xf86DisableIO(void)
-{
-#if defined(__i386__) || defined(__i386) || defined(__x86)
- if(!ExtendedEnabled)
- return;
-
- sysi86(SI86V86, V86SC_IOPL, 0);
-
- ExtendedEnabled = FALSE;
-#endif /* i386 */
-}
+/* + * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany + * Copyright 1993 by David Wexelblat <dwex@goblin.org> + * Copyright 1999 by David Holland <davidh@iquest.net> + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting documentation, and + * that the names of the copyright holders not be used in advertising or + * publicity pertaining to distribution of the software without specific, + * written prior permission. The copyright holders make no representations + * about the suitability of this software for any purpose. It is provided "as + * is" without express or implied warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT + * SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + * + */ +/* Copyright (c) 2008, Oracle and/or its affiliates. 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 + * THE AUTHORS OR COPYRIGHT HOLDERS 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. + */ + +#ifdef HAVE_XORG_CONFIG_H +#include <xorg-config.h> +#endif + +#include <sys/types.h> /* get __x86 definition if not set by compiler */ + +#if defined(__i386__) || defined(__i386) || defined(__x86) +#define _NEED_SYSI86 +#endif +#include "xf86.h" +#include "xf86Priv.h" +#include "xf86_OSlib.h" +#include "xf86OSpriv.h" +#include <sys/mman.h> + +/***************************************************************************/ +/* Video Memory Mapping section */ +/***************************************************************************/ + +static char *apertureDevName = NULL; +static int apertureDevFD_ro = -1; +static int apertureDevFD_rw = -1; + +static Bool +solOpenAperture(void) +{ + if (apertureDevName == NULL) { + apertureDevName = "/dev/xsvc"; + if ((apertureDevFD_rw = open(apertureDevName, O_RDWR)) < 0) { + xf86MsgVerb(X_WARNING, 0, + "solOpenAperture: failed to open %s (%s)\n", + apertureDevName, strerror(errno)); + apertureDevName = "/dev/fbs/aperture"; + apertureDevFD_rw = open(apertureDevName, O_RDWR); + } + apertureDevFD_ro = open(apertureDevName, O_RDONLY); + + if ((apertureDevFD_rw < 0) || (apertureDevFD_ro < 0)) { + xf86MsgVerb(X_WARNING, 0, + "solOpenAperture: failed to open %s (%s)\n", + apertureDevName, strerror(errno)); + xf86MsgVerb(X_WARNING, 0, + "solOpenAperture: either /dev/fbs/aperture" + " or /dev/xsvc required\n"); + + apertureDevName = NULL; + + if (apertureDevFD_rw >= 0) { + close(apertureDevFD_rw); + } + apertureDevFD_rw = -1; + + if (apertureDevFD_ro >= 0) { + close(apertureDevFD_ro); + } + apertureDevFD_ro = -1; + + return FALSE; + } + } + return TRUE; +} + +static pointer +solMapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int Flags) +{ + pointer base; + int fd; + int prot; + + if (Flags & VIDMEM_READONLY) { + fd = apertureDevFD_ro; + prot = PROT_READ; + } + else { + fd = apertureDevFD_rw; + prot = PROT_READ | PROT_WRITE; + } + + if (fd < 0) { + xf86DrvMsg(ScreenNum, X_ERROR, + "solMapVidMem: failed to open %s (%s)\n", + apertureDevName, strerror(errno)); + return NULL; + } + + base = mmap(NULL, Size, prot, MAP_SHARED, fd, (off_t) Base); + + if (base == MAP_FAILED) { + xf86DrvMsg(ScreenNum, X_ERROR, + "solMapVidMem: failed to mmap %s (0x%08lx,0x%lx) (%s)\n", + apertureDevName, Base, Size, strerror(errno)); + return NULL; + } + + return base; +} + +/* ARGSUSED */ +static void +solUnMapVidMem(int ScreenNum, pointer Base, unsigned long Size) +{ + if (munmap(Base, Size) != 0) { + xf86DrvMsgVerb(ScreenNum, X_WARNING, 0, + "solUnMapVidMem: failed to unmap %s" + " (0x%p,0x%lx) (%s)\n", + apertureDevName, Base, Size, strerror(errno)); + } +} + +_X_HIDDEN void +xf86OSInitVidMem(VidMemInfoPtr pVidMem) +{ + pVidMem->linearSupported = solOpenAperture(); + if (pVidMem->linearSupported) { + pVidMem->mapMem = solMapVidMem; + pVidMem->unmapMem = solUnMapVidMem; + } + else { + xf86MsgVerb(X_WARNING, 0, + "xf86OSInitVidMem: linear memory access disabled\n"); + } + pVidMem->initialised = TRUE; +} + +/* + * Read BIOS via mmap()ing physical memory. + */ +int +xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf, + int Len) +{ + unsigned char *ptr; + int psize; + int mlen; + + psize = getpagesize(); + Offset += Base & (psize - 1); + Base &= ~(psize - 1); + mlen = (Offset + Len + psize - 1) & ~(psize - 1); + + if (solOpenAperture() == FALSE) { + xf86Msg(X_WARNING, + "xf86ReadBIOS: Failed to open aperture to read BIOS\n"); + return -1; + } + + ptr = (unsigned char *) mmap(NULL, mlen, PROT_READ, + MAP_SHARED, apertureDevFD_ro, (off_t) Base); + if (ptr == MAP_FAILED) { + xf86Msg(X_WARNING, "xf86ReadBIOS: %s mmap failed [0x%08lx, 0x%04x]\n", + apertureDevName, Base, mlen); + return -1; + } + + (void) memcpy(Buf, (void *) (ptr + Offset), Len); + if (munmap((caddr_t) ptr, mlen) != 0) { + xf86MsgVerb(X_WARNING, 0, + "xf86ReadBIOS: failed to unmap %s (0x%p,0x%x) (%s)\n", + apertureDevName, ptr, mlen, strerror(errno)); + } + + return Len; +} + +/***************************************************************************/ +/* I/O Permissions section */ +/***************************************************************************/ + +#if defined(__i386__) || defined(__i386) || defined(__x86) +static Bool ExtendedEnabled = FALSE; +#endif + +Bool +xf86EnableIO(void) +{ +#if defined(__i386__) || defined(__i386) || defined(__x86) + if (ExtendedEnabled) + return TRUE; + + if (sysi86(SI86V86, V86SC_IOPL, PS_IOPL) < 0) { + xf86Msg(X_WARNING, "xf86EnableIOPorts: Failed to set IOPL for I/O\n"); + return FALSE; + } + ExtendedEnabled = TRUE; +#endif /* i386 */ + return TRUE; +} + +void +xf86DisableIO(void) +{ +#if defined(__i386__) || defined(__i386) || defined(__x86) + if (!ExtendedEnabled) + return; + + sysi86(SI86V86, V86SC_IOPL, 0); + + ExtendedEnabled = FALSE; +#endif /* i386 */ +} diff --git a/xorg-server/hw/xfree86/os-support/xf86_OSproc.h b/xorg-server/hw/xfree86/os-support/xf86_OSproc.h index 78ea6e660..e171146dd 100644 --- a/xorg-server/hw/xfree86/os-support/xf86_OSproc.h +++ b/xorg-server/hw/xfree86/os-support/xf86_OSproc.h @@ -64,7 +64,6 @@ * */ - #ifndef _XF86_OSPROC_H #define _XF86_OSPROC_H @@ -72,7 +71,7 @@ * The actual prototypes have been pulled into this seperate file so * that they can can be used without pulling in all of the OS specific * stuff like sys/stat.h, etc. This casues problem for loadable modules. - */ + */ /* * Flags for xf86MapVidMem(). Multiple flags can be or'd together. The @@ -80,31 +79,31 @@ * enable write combining for memory marked only for framebuffer use. */ -#define VIDMEM_FRAMEBUFFER 0x01 /* memory for framebuffer use */ -#define VIDMEM_MMIO 0x02 /* memory for I/O use */ -#define VIDMEM_MMIO_32BIT 0x04 /* memory accesses >= 32bit */ -#define VIDMEM_READSIDEEFFECT 0x08 /* reads can have side-effects */ -#define VIDMEM_SPARSE 0x10 /* sparse mapping required - * assumed when VIDMEM_MMIO is - * set. May be used with - * VIDMEM_FRAMEBUFFER) */ -#define VIDMEM_READONLY 0x20 /* read-only mapping - * used when reading BIOS images - * through xf86MapVidMem() */ +#define VIDMEM_FRAMEBUFFER 0x01 /* memory for framebuffer use */ +#define VIDMEM_MMIO 0x02 /* memory for I/O use */ +#define VIDMEM_MMIO_32BIT 0x04 /* memory accesses >= 32bit */ +#define VIDMEM_READSIDEEFFECT 0x08 /* reads can have side-effects */ +#define VIDMEM_SPARSE 0x10 /* sparse mapping required + * assumed when VIDMEM_MMIO is + * set. May be used with + * VIDMEM_FRAMEBUFFER) */ +#define VIDMEM_READONLY 0x20 /* read-only mapping + * used when reading BIOS images + * through xf86MapVidMem() */ /* * OS-independent modem state flags for xf86SetSerialModemState() and * xf86GetSerialModemState(). */ -#define XF86_M_LE 0x001 /* line enable */ -#define XF86_M_DTR 0x002 /* data terminal ready */ -#define XF86_M_RTS 0x004 /* request to send */ -#define XF86_M_ST 0x008 /* secondary transmit */ -#define XF86_M_SR 0x010 /* secondary receive */ -#define XF86_M_CTS 0x020 /* clear to send */ -#define XF86_M_CAR 0x040 /* carrier detect */ -#define XF86_M_RNG 0x080 /* ring */ -#define XF86_M_DSR 0x100 /* data set ready */ +#define XF86_M_LE 0x001 /* line enable */ +#define XF86_M_DTR 0x002 /* data terminal ready */ +#define XF86_M_RTS 0x004 /* request to send */ +#define XF86_M_ST 0x008 /* secondary transmit */ +#define XF86_M_SR 0x010 /* secondary receive */ +#define XF86_M_CTS 0x020 /* clear to send */ +#define XF86_M_CAR 0x040 /* carrier detect */ +#define XF86_M_RNG 0x080 /* ring */ +#define XF86_M_DSR 0x100 /* data set ready */ #ifndef NO_OSLIB_PROTOTYPES /* @@ -133,12 +132,17 @@ _XFUNCPROTOBEGIN /* public functions */ extern _X_EXPORT Bool xf86LinearVidMem(void); extern _X_EXPORT _X_DEPRECATED Bool xf86CheckMTRR(int); -extern _X_EXPORT _X_DEPRECATED pointer xf86MapVidMem(int, int, unsigned long, unsigned long); -extern _X_EXPORT _X_DEPRECATED void xf86UnMapVidMem(int, pointer, unsigned long); -extern _X_EXPORT _X_DEPRECATED void xf86MapReadSideEffects(int, int, pointer, unsigned long); -extern _X_EXPORT int xf86ReadBIOS(unsigned long, unsigned long, unsigned char *, int); +extern _X_EXPORT _X_DEPRECATED pointer xf86MapVidMem(int, int, unsigned long, + unsigned long); +extern _X_EXPORT _X_DEPRECATED void xf86UnMapVidMem(int, pointer, + unsigned long); +extern _X_EXPORT _X_DEPRECATED void xf86MapReadSideEffects(int, int, pointer, + unsigned long); +extern _X_EXPORT int xf86ReadBIOS(unsigned long, unsigned long, unsigned char *, + int); extern _X_EXPORT Bool xf86EnableIO(void); extern _X_EXPORT void xf86DisableIO(void); + #ifdef __NetBSD__ extern _X_EXPORT void xf86SetTVOut(int); extern _X_EXPORT void xf86SetRGBOut(void); @@ -164,23 +168,24 @@ extern _X_EXPORT int xf86LoadKernelModule(const char *pathname); /* AGP GART interface */ typedef struct _AgpInfo { - CARD32 bridgeId; - CARD32 agpMode; - unsigned long base; - unsigned long size; - unsigned long totalPages; - unsigned long systemPages; - unsigned long usedPages; + CARD32 bridgeId; + CARD32 agpMode; + unsigned long base; + unsigned long size; + unsigned long totalPages; + unsigned long systemPages; + unsigned long usedPages; } AgpInfo, *AgpInfoPtr; extern _X_EXPORT Bool xf86AgpGARTSupported(void); extern _X_EXPORT AgpInfoPtr xf86GetAGPInfo(int screenNum); extern _X_EXPORT Bool xf86AcquireGART(int screenNum); extern _X_EXPORT Bool xf86ReleaseGART(int screenNum); -extern _X_EXPORT int xf86AllocateGARTMemory(int screenNum, unsigned long size, int type, - unsigned long *physical); +extern _X_EXPORT int xf86AllocateGARTMemory(int screenNum, unsigned long size, + int type, unsigned long *physical); extern _X_EXPORT Bool xf86DeallocateGARTMemory(int screenNum, int key); -extern _X_EXPORT Bool xf86BindGARTMemory(int screenNum, int key, unsigned long offset); +extern _X_EXPORT Bool xf86BindGARTMemory(int screenNum, int key, + unsigned long offset); extern _X_EXPORT Bool xf86UnbindGARTMemory(int screenNum, int key); extern _X_EXPORT Bool xf86EnableAGP(int screenNum, CARD32 mode); extern _X_EXPORT Bool xf86GARTCloseScreen(int screenNum); @@ -189,15 +194,16 @@ extern _X_EXPORT Bool xf86GARTCloseScreen(int screenNum); module. These routines are small, and the code if very POSIX-signal (or OS-signal) specific, so it seemed better to provide more complex wrappers than to wrap each individual function called. */ -extern _X_EXPORT int xf86InstallSIGIOHandler(int fd, void (*f)(int, void *), void *); +extern _X_EXPORT int xf86InstallSIGIOHandler(int fd, void (*f) (int, void *), + void *); extern _X_EXPORT int xf86RemoveSIGIOHandler(int fd); -extern _X_EXPORT int xf86BlockSIGIO (void); -extern _X_EXPORT void xf86UnblockSIGIO (int); -extern _X_EXPORT void xf86AssertBlockedSIGIO (char *); -extern _X_EXPORT Bool xf86SIGIOSupported (void); +extern _X_EXPORT int xf86BlockSIGIO(void); +extern _X_EXPORT void xf86UnblockSIGIO(int); +extern _X_EXPORT void xf86AssertBlockedSIGIO(char *); +extern _X_EXPORT Bool xf86SIGIOSupported(void); #ifdef XF86_OS_PRIVS -typedef void (*PMClose)(void); +typedef void (*PMClose) (void); extern _X_EXPORT void xf86OpenConsole(void); extern _X_EXPORT void xf86CloseConsole(void); extern _X_HIDDEN Bool xf86VTActivate(int vtno); @@ -209,13 +215,12 @@ extern _X_EXPORT int xf86ProcessArgument(int, char **, int); extern _X_EXPORT void xf86UseMsg(void); extern _X_EXPORT PMClose xf86OSPMOpen(void); -extern _X_EXPORT _X_DEPRECATED void xf86MakeNewMapping(int, int, unsigned long, unsigned long, pointer); +extern _X_EXPORT _X_DEPRECATED void xf86MakeNewMapping(int, int, unsigned long, + unsigned long, pointer); extern _X_EXPORT void xf86InitVidMem(void); -#endif /* XF86_OS_PRIVS */ - +#endif /* XF86_OS_PRIVS */ _XFUNCPROTOEND -#endif /* NO_OSLIB_PROTOTYPES */ - -#endif /* _XF86_OSPROC_H */ +#endif /* NO_OSLIB_PROTOTYPES */ +#endif /* _XF86_OSPROC_H */ |