xref: /OK3568_Linux_fs/external/xserver/hw/xfree86/os-support/bsd/arm_video.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
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 
69 #if defined(__NetBSD__) && !defined(MAP_FILE)
70 #define MAP_FLAGS MAP_SHARED
71 #else
72 #define MAP_FLAGS (MAP_FILE | MAP_SHARED)
73 #endif
74 
75 #define BUS_BASE	0L
76 #define BUS_BASE_BWX	0L
77 
78 /***************************************************************************/
79 /* Video Memory Mapping section                                            */
80 /***************************************************************************/
81 
82 static int devMemFd = -1;
83 
84 /*
85  * Check if /dev/mem can be mmap'd.  If it can't print a warning when
86  * "warn" is TRUE.
87  */
88 static void
checkDevMem(Bool warn)89 checkDevMem(Bool warn)
90 {
91     static Bool devMemChecked = FALSE;
92     int fd;
93     void *base;
94 
95     if (devMemChecked)
96         return;
97     devMemChecked = TRUE;
98 
99     if ((fd = open(DEV_MEM, O_RDWR)) >= 0) {
100         /* Try to map a page at the VGA address */
101         base = mmap((caddr_t) 0, 4096, PROT_READ | PROT_WRITE,
102                     MAP_FLAGS, fd, (off_t) 0xA0000 + BUS_BASE);
103 
104         if (base != MAP_FAILED) {
105             munmap((caddr_t) base, 4096);
106             devMemFd = fd;
107             return;
108         }
109         else {
110             /* This should not happen */
111             if (warn) {
112                 xf86Msg(X_WARNING, "checkDevMem: failed to mmap %s (%s)\n",
113                         DEV_MEM, strerror(errno));
114             }
115             return;
116         }
117     }
118     if (warn) {
119         xf86Msg(X_WARNING, "checkDevMem: failed to open %s (%s)\n",
120                 DEV_MEM, strerror(errno));
121     }
122     return;
123 }
124 
125 void
xf86OSInitVidMem(VidMemInfoPtr pVidMem)126 xf86OSInitVidMem(VidMemInfoPtr pVidMem)
127 {
128     checkDevMem(TRUE);
129 
130     pVidMem->initialised = TRUE;
131 }
132 
133 #ifdef USE_DEV_IO
134 static int IoFd = -1;
135 
136 Bool
xf86EnableIO()137 xf86EnableIO()
138 {
139     if (IoFd >= 0)
140         return TRUE;
141 
142     if ((IoFd = open("/dev/io", O_RDWR)) == -1) {
143         xf86Msg(X_WARNING, "xf86EnableIO: "
144                 "Failed to open /dev/io for extended I/O\n");
145         return FALSE;
146     }
147     return TRUE;
148 }
149 
150 void
xf86DisableIO()151 xf86DisableIO()
152 {
153     if (IoFd < 0)
154         return;
155 
156     close(IoFd);
157     IoFd = -1;
158     return;
159 }
160 
161 #endif
162 
163 #if defined(USE_ARC_MMAP) || defined(__arm32__)
164 
165 Bool
xf86EnableIO()166 xf86EnableIO()
167 {
168     int fd;
169     void *base;
170 
171     if (ExtendedEnabled)
172         return TRUE;
173 
174     if ((fd = open("/dev/ttyC0", O_RDWR)) >= 0) {
175         /* Try to map a page at the pccons I/O space */
176         base = (void *) mmap((caddr_t) 0, 65536, PROT_READ | PROT_WRITE,
177                              MAP_FLAGS, fd, (off_t) 0x0000);
178 
179         if (base != (void *) -1) {
180             IOPortBase = base;
181         }
182         else {
183             xf86Msg(X_WARNING, "EnableIO: failed to mmap %s (%s)\n",
184                     "/dev/ttyC0", strerror(errno));
185             return FALSE;
186         }
187     }
188     else {
189         xf86Msg("EnableIO: failed to open %s (%s)\n",
190                 "/dev/ttyC0", strerror(errno));
191         return FALSE;
192     }
193 
194     ExtendedEnabled = TRUE;
195 
196     return TRUE;
197 }
198 
199 void
xf86DisableIO()200 xf86DisableIO()
201 {
202     return;
203 }
204 
205 #endif                          /* USE_ARC_MMAP */
206