/* $XFree86: xc/programs/Xserver/hw/xfree86/SuperProbe/OS_Linux.c,v 3.10.2.2 1999/06/17 16:23:59 hohndel Exp $ */ /* * (c) Copyright 1993,1994 by Orest Zborowski * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * OREST ZBOROWSKI BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * * Except as contained in this notice, the name of Orest Zborowski shall not be * used in advertising or otherwise to promote the sale, use or other dealings * in this Software without prior written authorization from Orest Zborowski. * */ /* $XConsortium: OS_Linux.c /main/8 1996/10/19 17:47:14 kaleb $ */ #include "Probe.h" #include #include #include #include #include #ifdef __alpha__ /* * The Jensen lacks dense memory, thus we have to address the bus via * the sparse addressing scheme. * * Martin Ostermann (ost@comnets.rwth-aachen.de) - Apr.-Sep. 1996 */ #ifdef TEST_JENSEN_CODE /* define to test the Sparse addressing on a non-Jensen */ #define isJensen (1) #define SPARSE (5) #define WORD_CODING (0x08) #else #define isJensen (!_bus_base()) #define SPARSE (7) #define WORD_CODING (0x20) #endif #define BUS_BASE (isJensen ? _bus_base_sparse() : _bus_base()) #define JENSEN_SHIFT(x) (isJensen ? ((long)x< 0) { close(VT_fd); if (VT_cur >= 0) { if ((fd = open("/dev/console", O_WRONLY, 0)) >= 0) { ioctl(fd, VT_ACTIVATE, VT_cur); close(fd); } } } } /* * MapVGA -- * * Map the VGA memory window (0xA0000-0xAFFFF) as read/write memory for * the process for use in probing memory. */ Byte *MapVGA() { return( MapMem(0xA0000,0x10000) ); } Byte *MapMem(address, size) unsigned long address; unsigned long size; { int fd; Byte *base; #ifdef __alpha__ if(isJensen){ fprintf(stderr, "%s: MemProbe not supported on Jensen\n", MyName); return((Byte *)0); } #endif if ((fd = open("/dev/mem", O_RDWR)) < 0) { fprintf(stderr, "%s: Failed to open /dev/mem\n", MyName); return((Byte *)0); } base = (Byte *)mmap((caddr_t)0, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, (off_t)address + BUS_BASE); close(fd); if ((long)base == -1) { fprintf(stderr, "%s: Failed to mmap framebuffer\n", MyName); return((Byte *)0); } return(base); } /* * UnMapVGA -- * * Unmap the VGA memory window. */ void UnMapVGA(base) Byte *base; { UnMapMem(base,0x10000); return; } void UnMapMem(base,size) Byte *base; unsigned long size; { munmap((caddr_t)base, 0x10000); return; } #ifdef __alpha__ SlowBCopyFromBus(src, dst, count) unsigned char *src, *dst; int count; { unsigned long addr; long result; addr = (unsigned long) src; while( count ){ result = *(volatile int *) addr; result >>= ((addr>>SPARSE) & 3) * 8; *dst++ = (unsigned char) (0xffUL & result); addr += 1<>= ((long)Base & 3) * 8; tmp &= 0xffffUL; } else { tmp = *(Word *)mybase; } if (tmp != (Word)0xAA55) { fprintf(stderr, "%s: BIOS sanity check failed, addr=%lx\n", MyName, (long)Base); return(-1); } } if (isJensen) SlowBCopyFromBus(&mybase[JENSEN_SHIFT(myoffset)], Buffer, Len); else memcpy(Buffer, &mybase[myoffset], Len); munmap((caddr_t)((off_t)JENSEN_SHIFT(Base) | BUS_BASE), mysize); #else /* __alpha__ */ if ((off_t)((off_t)Base & 0x7FFF) != (off_t)0) { /* * Sanity check... */ (void)lseek(BIOS_fd, (off_t)((off_t)Base & 0xF8000), SEEK_SET); (void)read(BIOS_fd, &tmp, 2); if (tmp != (Word)0xAA55) { fprintf(stderr, "%s: BIOS sanity check failed, addr=%x\n", MyName, (int)Base); return(-1); } } if (lseek(BIOS_fd, (off_t)Base, SEEK_SET) < 0) { fprintf(stderr, "%s: BIOS seek failed\n", MyName); return(-1); } if (read(BIOS_fd, Buffer, Len) != Len) { fprintf(stderr, "%s: BIOS read failed\n", MyName); return(-1); } #endif /* __alpha__ */ return(Len); } /* * EnableIOPort -- * * Enable access to 'NumPorts' IO ports listed in array 'Ports'. For Linux, * we've disabled IO protections so this is a no-op. */ /*ARGSUSED*/ int EnableIOPorts(NumPorts, Ports) CONST int NumPorts; CONST Word *Ports; { return(0); } /* * DisableIOPort -- * * Disable access to 'NumPorts' IO ports listed in array 'Ports'. For Linux, * we've disabled IO protections so this is a no-op. */ /*ARGSUSED*/ int DisableIOPorts(NumPorts, Port) CONST int NumPorts; CONST Word *Port; { return(0); } /* * ShortSleep -- * * Sleep for the number of milliseconds specified in 'Delay'. */ void ShortSleep(Delay) int Delay; { usleep(Delay * 1000); }