arm_video.c (6120B)
1 /* 2 * Copyright 1992 by Rich Murphey <Rich@Rice.edu> 3 * Copyright 1993 by David Wexelblat <dwex@goblin.org> 4 * 5 * Permission to use, copy, modify, distribute, and sell this software and its 6 * documentation for any purpose is hereby granted without fee, provided that 7 * the above copyright notice appear in all copies and that both that 8 * copyright notice and this permission notice appear in supporting 9 * documentation, and that the names of Rich Murphey and David Wexelblat 10 * not be used in advertising or publicity pertaining to distribution of 11 * the software without specific, written prior permission. Rich Murphey and 12 * David Wexelblat make no representations about the suitability of this 13 * software for any purpose. It is provided "as is" without express or 14 * implied warranty. 15 * 16 * RICH MURPHEY AND DAVID WEXELBLAT DISCLAIM ALL WARRANTIES WITH REGARD TO 17 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 * FITNESS, IN NO EVENT SHALL RICH MURPHEY OR DAVID WEXELBLAT BE LIABLE FOR 19 * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER 20 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF 21 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 22 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 23 * 24 */ 25 26 /* 27 * The ARM32 code here carries the following copyright: 28 * 29 * Copyright 1997 30 * Digital Equipment Corporation. All rights reserved. 31 * This software is furnished under license and may be used and copied only in 32 * accordance with the following terms and conditions. Subject to these 33 * conditions, you may download, copy, install, use, modify and distribute 34 * this software in source and/or binary form. No title or ownership is 35 * transferred hereby. 36 * 37 * 1) Any source code used, modified or distributed must reproduce and retain 38 * this copyright notice and list of conditions as they appear in the 39 * source file. 40 * 41 * 2) No right is granted to use any trade name, trademark, or logo of Digital 42 * Equipment Corporation. Neither the "Digital Equipment Corporation" 43 * name nor any trademark or logo of Digital Equipment Corporation may be 44 * used to endorse or promote products derived from this software without 45 * the prior written permission of Digital Equipment Corporation. 46 * 47 * 3) This software is provided "AS-IS" and any express or implied warranties, 48 * including but not limited to, any implied warranties of merchantability, 49 * fitness for a particular purpose, or non-infringement are disclaimed. 50 * In no event shall DIGITAL be liable for any damages whatsoever, and in 51 * particular, DIGITAL shall not be liable for special, indirect, 52 * consequential, or incidental damages or damages for lost profits, loss 53 * of revenue or loss of use, whether such damages arise in contract, 54 * negligence, tort, under statute, in equity, at law or otherwise, even 55 * if advised of the possibility of such damage. 56 * 57 */ 58 59 #ifdef HAVE_XORG_CONFIG_H 60 #include <xorg-config.h> 61 #endif 62 63 #include <X11/X.h> 64 #include "xf86.h" 65 #include "xf86Priv.h" 66 #include "xf86_OSlib.h" 67 #include "xf86OSpriv.h" 68 #include "compiler.h" 69 70 #if defined(__NetBSD__) && !defined(MAP_FILE) 71 #define MAP_FLAGS MAP_SHARED 72 #else 73 #define MAP_FLAGS (MAP_FILE | MAP_SHARED) 74 #endif 75 76 #define BUS_BASE 0L 77 #define BUS_BASE_BWX 0L 78 79 /***************************************************************************/ 80 /* Video Memory Mapping section */ 81 /***************************************************************************/ 82 83 static int devMemFd = -1; 84 85 /* 86 * Check if /dev/mem can be mmap'd. If it can't print a warning when 87 * "warn" is TRUE. 88 */ 89 static void 90 checkDevMem(Bool warn) 91 { 92 static Bool devMemChecked = FALSE; 93 int fd; 94 void *base; 95 96 if (devMemChecked) 97 return; 98 devMemChecked = TRUE; 99 100 if ((fd = open(DEV_MEM, O_RDWR)) >= 0) { 101 /* Try to map a page at the VGA address */ 102 base = mmap((caddr_t) 0, 4096, PROT_READ | PROT_WRITE, 103 MAP_FLAGS, fd, (off_t) 0xA0000 + BUS_BASE); 104 105 if (base != MAP_FAILED) { 106 munmap((caddr_t) base, 4096); 107 devMemFd = fd; 108 return; 109 } 110 else { 111 /* This should not happen */ 112 if (warn) { 113 xf86Msg(X_WARNING, "checkDevMem: failed to mmap %s (%s)\n", 114 DEV_MEM, strerror(errno)); 115 } 116 return; 117 } 118 } 119 if (warn) { 120 xf86Msg(X_WARNING, "checkDevMem: failed to open %s (%s)\n", 121 DEV_MEM, strerror(errno)); 122 } 123 return; 124 } 125 126 void 127 xf86OSInitVidMem(VidMemInfoPtr pVidMem) 128 { 129 checkDevMem(TRUE); 130 131 pVidMem->initialised = TRUE; 132 } 133 134 #ifdef USE_DEV_IO 135 static int IoFd = -1; 136 137 Bool 138 xf86EnableIO() 139 { 140 if (IoFd >= 0) 141 return TRUE; 142 143 if ((IoFd = open("/dev/io", O_RDWR)) == -1) { 144 xf86Msg(X_WARNING, "xf86EnableIO: " 145 "Failed to open /dev/io for extended I/O\n"); 146 return FALSE; 147 } 148 return TRUE; 149 } 150 151 void 152 xf86DisableIO() 153 { 154 if (IoFd < 0) 155 return; 156 157 close(IoFd); 158 IoFd = -1; 159 return; 160 } 161 162 #endif 163 164 #if defined(USE_ARC_MMAP) || defined(__arm32__) 165 166 unsigned int IOPortBase; 167 168 Bool 169 xf86EnableIO() 170 { 171 int fd; 172 void *base; 173 174 if (ExtendedEnabled) 175 return TRUE; 176 177 if ((fd = open("/dev/ttyC0", O_RDWR)) >= 0) { 178 /* Try to map a page at the pccons I/O space */ 179 base = (void *) mmap((caddr_t) 0, 65536, PROT_READ | PROT_WRITE, 180 MAP_FLAGS, fd, (off_t) 0x0000); 181 182 if (base != (void *) -1) { 183 IOPortBase = base; 184 } 185 else { 186 xf86Msg(X_WARNING, "EnableIO: failed to mmap %s (%s)\n", 187 "/dev/ttyC0", strerror(errno)); 188 return FALSE; 189 } 190 } 191 else { 192 xf86Msg("EnableIO: failed to open %s (%s)\n", 193 "/dev/ttyC0", strerror(errno)); 194 return FALSE; 195 } 196 197 ExtendedEnabled = TRUE; 198 199 return TRUE; 200 } 201 202 void 203 xf86DisableIO() 204 { 205 return; 206 } 207 208 #endif /* USE_ARC_MMAP */