diff options
author | Adam Jackson <ajax@redhat.com> | 2012-06-26 13:12:45 -0400 |
---|---|---|
committer | Adam Jackson <ajax@redhat.com> | 2012-09-20 11:07:27 -0400 |
commit | 048674a6aeb61149a1b5f6b0bc3762ddf57f38ee (patch) | |
tree | f1c33335b06b59d75680daa9c3f0aa90bb7cc1f1 /hw/xfree86/os-support/linux/lnx_video.c | |
parent | f0bad69edd57facd6cffde8cb0863d1a735e2492 (diff) |
linux: Refactor xf86{En,Dis}ableIO
Pull platform methods into their own sections for legibility, and
rewrite the ifdefs to be more concise.
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Reviewed-by: Simon Farnsworth <simon.farnsworth@onelan.co.uk>
Signed-off-by: Adam Jackson <ajax@redhat.com>
Diffstat (limited to 'hw/xfree86/os-support/linux/lnx_video.c')
-rw-r--r-- | hw/xfree86/os-support/linux/lnx_video.c | 82 |
1 files changed, 48 insertions, 34 deletions
diff --git a/hw/xfree86/os-support/linux/lnx_video.c b/hw/xfree86/os-support/linux/lnx_video.c index 3526a21d4..895a79bbd 100644 --- a/hw/xfree86/os-support/linux/lnx_video.c +++ b/hw/xfree86/os-support/linux/lnx_video.c @@ -479,39 +479,36 @@ volatile unsigned char *ioBase = NULL; #define __NR_pciconfig_iobase 200 #endif -#endif - -Bool -xf86EnableIO(void) +static Bool +hwEnableIO(void) { -#if defined(__powerpc__) int fd; - unsigned int ioBase_phys; -#endif - - if (ExtendedEnabled) - return TRUE; - -#if defined(__powerpc__) - ioBase_phys = syscall(__NR_pciconfig_iobase, 2, 0, 0); + unsigned int ioBase_phys = syscall(__NR_pciconfig_iobase, 2, 0, 0); fd = open("/dev/mem", O_RDWR); if (ioBase == NULL) { ioBase = (volatile unsigned char *) mmap(0, 0x20000, PROT_READ | PROT_WRITE, MAP_SHARED, fd, ioBase_phys); -/* Should this be fatal or just a warning? */ -#if 0 - if (ioBase == MAP_FAILED) { - xf86Msg(X_WARNING, - "xf86EnableIOPorts: Failed to map iobase (%s)\n", - strerror(errno)); - return FALSE; - } -#endif } close(fd); -#elif !defined(__mc68000__) && !defined(__sparc__) && !defined(__mips__) && !defined(__sh__) && !defined(__hppa__) && !defined(__s390__) && !defined(__arm__) && !defined(__m32r__) && !defined(__nds32__) + + return ioBase != MAP_FAILED; +} + +static void +hwDisableIO(void) +{ + munmap(ioBase, 0x20000); + ioBase = NULL; +} + +#elif defined(__i386__) || defined(__x86_64__) || defined(__ia64__) || \ + defined(__alpha__) + +static Bool +hwEnableIO(void) +{ if (ioperm(0, 1024, 1) || iopl(3)) { if (errno == ENODEV) ErrorF("xf86EnableIOPorts: no I/O ports found\n"); @@ -526,27 +523,44 @@ xf86EnableIO(void) ioperm(0x40, 4, 0); /* trap access to the timer chip */ ioperm(0x60, 4, 0); /* trap access to the keyboard controller */ #endif -#endif - ExtendedEnabled = TRUE; return TRUE; } +static void +hwDisableIO(void) +{ + iopl(0); + ioperm(0, 1024, 0); +} + +#else /* non-IO architectures */ + +#define hwEnableIO() TRUE +#define hwDisableIO() do {} while (0) + +#endif + +Bool +xf86EnableIO(void) +{ + if (ExtendedEnabled) + return TRUE; + + ExtendedEnabled = hwEnableIO(); + + return ExtendedEnabled; +} + void xf86DisableIO(void) { if (!ExtendedEnabled) return; -#if defined(__powerpc__) - munmap(ioBase, 0x20000); - ioBase = NULL; -#elif !defined(__mc68000__) && !defined(__sparc__) && !defined(__mips__) && !defined(__sh__) && !defined(__hppa__) && !defined(__arm__) && !defined(__s390__) && !defined(__m32r__) && !defined(__nds32__) - iopl(0); - ioperm(0, 1024, 0); -#endif - ExtendedEnabled = FALSE; - return; + hwDisableIO(); + + ExtendedEnabled = FALSE; } #if defined (__alpha__) |