diff options
Diffstat (limited to 'xorg-server/hw/xfree86/os-support/bsd')
-rw-r--r-- | xorg-server/hw/xfree86/os-support/bsd/alpha_video.c | 606 | ||||
-rw-r--r-- | xorg-server/hw/xfree86/os-support/bsd/arm_video.c | 741 | ||||
-rw-r--r-- | xorg-server/hw/xfree86/os-support/bsd/bsd_apm.c | 96 | ||||
-rw-r--r-- | xorg-server/hw/xfree86/os-support/bsd/bsd_axp.c | 65 | ||||
-rw-r--r-- | xorg-server/hw/xfree86/os-support/bsd/bsd_bell.c | 48 | ||||
-rw-r--r-- | xorg-server/hw/xfree86/os-support/bsd/bsd_init.c | 778 | ||||
-rw-r--r-- | xorg-server/hw/xfree86/os-support/bsd/bsd_kmod.c | 7 | ||||
-rw-r--r-- | xorg-server/hw/xfree86/os-support/bsd/bsd_kqueue_apm.c | 134 | ||||
-rw-r--r-- | xorg-server/hw/xfree86/os-support/bsd/i386_video.c | 1113 | ||||
-rw-r--r-- | xorg-server/hw/xfree86/os-support/bsd/memrange.h | 57 | ||||
-rw-r--r-- | xorg-server/hw/xfree86/os-support/bsd/ppc_video.c | 105 | ||||
-rw-r--r-- | xorg-server/hw/xfree86/os-support/bsd/sparc64_video.c | 40 |
12 files changed, 1841 insertions, 1949 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; } |