1
/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bsd/arm_video.c,v 1.1tsi Exp $ */
3
* Copyright 1992 by Rich Murphey <Rich@Rice.edu>
4
* Copyright 1993 by David Wexelblat <dwex@goblin.org>
6
* Permission to use, copy, modify, distribute, and sell this software and its
7
* documentation for any purpose is hereby granted without fee, provided that
8
* the above copyright notice appear in all copies and that both that
9
* copyright notice and this permission notice appear in supporting
10
* documentation, and that the names of Rich Murphey and David Wexelblat
11
* not be used in advertising or publicity pertaining to distribution of
12
* the software without specific, written prior permission. Rich Murphey and
13
* David Wexelblat make no representations about the suitability of this
14
* software for any purpose. It is provided "as is" without express or
17
* RICH MURPHEY AND DAVID WEXELBLAT DISCLAIM ALL WARRANTIES WITH REGARD TO
18
* THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
19
* FITNESS, IN NO EVENT SHALL RICH MURPHEY OR DAVID WEXELBLAT BE LIABLE FOR
20
* ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
21
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
22
* CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
23
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
28
* The ARM32 code here carries the following copyright:
31
* Digital Equipment Corporation. All rights reserved.
32
* This software is furnished under license and may be used and copied only in
33
* accordance with the following terms and conditions. Subject to these
34
* conditions, you may download, copy, install, use, modify and distribute
35
* this software in source and/or binary form. No title or ownership is
38
* 1) Any source code used, modified or distributed must reproduce and retain
39
* this copyright notice and list of conditions as they appear in the
42
* 2) No right is granted to use any trade name, trademark, or logo of Digital
43
* Equipment Corporation. Neither the "Digital Equipment Corporation"
44
* name nor any trademark or logo of Digital Equipment Corporation may be
45
* used to endorse or promote products derived from this software without
46
* the prior written permission of Digital Equipment Corporation.
48
* 3) This software is provided "AS-IS" and any express or implied warranties,
49
* including but not limited to, any implied warranties of merchantability,
50
* fitness for a particular purpose, or non-infringement are disclaimed.
51
* In no event shall DIGITAL be liable for any damages whatsoever, and in
52
* particular, DIGITAL shall not be liable for special, indirect,
53
* consequential, or incidental damages or damages for lost profits, loss
54
* of revenue or loss of use, whether such damages arise in contract,
55
* negligence, tort, under statute, in equity, at law or otherwise, even
56
* if advised of the possibility of such damage.
60
/* $XConsortium: bsd_video.c /main/10 1996/10/25 11:37:57 kaleb $ */
62
#ifdef HAVE_XORG_CONFIG_H
63
#include <xorg-config.h>
69
#include "xf86_OSlib.h"
70
#include "xf86OSpriv.h"
73
#include "machine/devmap.h"
77
struct map_info memInfo;
78
pointer regionVirtBase;
83
static pointer xf86MapInfoMap();
84
static void xf86MapInfoUnmap();
85
static struct memAccess *checkMapInfo();
86
extern int vgaPhysLinearBase;
88
/* A memAccess structure is needed for each possible region */
89
struct memAccess vgaMemInfo = { CONSOLE_GET_MEM_INFO, NULL, NULL,
91
struct memAccess linearMemInfo = { CONSOLE_GET_LINEAR_INFO, NULL, NULL,
93
struct memAccess ioMemInfo = { CONSOLE_GET_IO_INFO, NULL, NULL,
95
#endif /* __arm32__ */
97
#if defined(__NetBSD__) && !defined(MAP_FILE)
98
#define MAP_FLAGS MAP_SHARED
100
#define MAP_FLAGS (MAP_FILE | MAP_SHARED)
104
#define MAP_FAILED ((caddr_t)-1)
109
#define BUS_BASE_BWX 0L
112
/***************************************************************************/
113
/* Video Memory Mapping section */
114
/***************************************************************************/
116
static Bool useDevMem = FALSE;
117
static int devMemFd = -1;
119
#define DEV_MEM "/dev/mem"
121
static pointer mapVidMem(int, unsigned long, unsigned long, int);
122
static void unmapVidMem(int, pointer, unsigned long);
125
* Check if /dev/mem can be mmap'd. If it can't print a warning when
129
checkDevMem(Bool warn)
131
static Bool devMemChecked = FALSE;
137
devMemChecked = TRUE;
139
if ((fd = open(DEV_MEM, O_RDWR)) >= 0)
141
/* Try to map a page at the VGA address */
142
base = mmap((caddr_t)0, 4096, PROT_READ | PROT_WRITE,
143
MAP_FLAGS, fd, (off_t)0xA0000 + BUS_BASE);
145
if (base != MAP_FAILED)
147
munmap((caddr_t)base, 4096);
152
/* This should not happen */
155
xf86Msg(X_WARNING, "checkDevMem: failed to mmap %s (%s)\n",
156
DEV_MEM, strerror(errno));
164
xf86Msg(X_WARNING, "checkDevMem: failed to open %s (%s)\n",
165
DEV_MEM, strerror(errno));
172
xf86OSInitVidMem(VidMemInfoPtr pVidMem)
176
pVidMem->linearSupported = useDevMem;
177
pVidMem->mapMem = armMapVidMem;
178
pVidMem->unmapVidMem = armUnmapVidMem;
180
pVidMem->initialised = TRUE;
184
mapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags)
194
FatalError("xf86MapVidMem: failed to open %s (%s)\n",
195
DEV_MEM, strerror(errno));
197
base = mmap((caddr_t)0, Size,
198
(flags & VIDMEM_READONLY) ?
199
PROT_READ : (PROT_READ | PROT_WRITE),
200
MAP_FLAGS, devMemFd, (off_t)Base + BUS_BASE_BWX);
201
if (base == MAP_FAILED)
203
FatalError("%s: could not mmap %s [s=%x,a=%x] (%s)\n",
204
"xf86MapVidMem", DEV_MEM, Size, Base,
210
/* else, mmap /dev/vga */
211
if ((unsigned long)Base < 0xA0000 || (unsigned long)Base >= 0xC0000)
213
FatalError("%s: Address 0x%x outside allowable range\n",
214
"xf86MapVidMem", Base);
217
(flags & VIDMEM_READONLY) ?
218
PROT_READ : (PROT_READ | PROT_WRITE),
219
MAP_FLAGS, xf86Info.screenFd,
220
(unsigned long)Base - 0xA0000);
221
if (base == MAP_FAILED)
223
FatalError("xf86MapVidMem: Could not mmap /dev/vga (%s)\n",
230
unmapVidMem(int ScreenNum, pointer Base, unsigned long Size)
232
munmap((caddr_t)Base, Size);
236
* Read BIOS via mmap()ing DEV_MEM
240
xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf,
248
if (devMemFd == -1) {
252
psize = xf86getpagesize();
253
Offset += Base & (psize - 1);
254
Base &= ~(psize - 1);
255
mlen = (Offset + Len + psize - 1) & ~(psize - 1);
256
ptr = (unsigned char *)mmap((caddr_t)0, mlen, PROT_READ,
257
MAP_SHARED, devMemFd, (off_t)Base+BUS_BASE);
261
"xf86ReadBIOS: %s mmap[s=%x,a=%x,o=%x] failed (%s)\n",
262
DEV_MEM, Len, Base, Offset, strerror(errno));
266
ErrorF("xf86ReadBIOS: BIOS at 0x%08x has signature 0x%04x\n",
267
Base, ptr[0] | (ptr[1] << 8));
269
(void)memcpy(Buf, (void *)(ptr + Offset), Len);
270
(void)munmap((caddr_t)ptr, mlen);
272
xf86MsgVerb(X_INFO, 3, "xf86ReadBIOS(%x, %x, Buf, %x)"
273
"-> %02x %02x %02x %02x...\n",
274
Base, Offset, Len, Buf[0], Buf[1], Buf[2], Buf[3]);
280
/* XXX This needs to be updated for the ND */
283
** Find out whether the console driver provides memory mapping information
284
** for the specified region and return the map_info pointer. Print a warning if required.
286
static struct memAccess *
287
checkMapInfo(Bool warn, int Region)
289
struct memAccess *memAccP;
294
memAccP = &vgaMemInfo;
298
memAccP = &linearMemInfo;
302
memAccP = &ioMemInfo;
310
if(!memAccP->Checked)
312
if(ioctl(xf86Info.screenFd, memAccP->ioctl, &(memAccP->memInfo)) == -1)
317
"checkMapInfo: failed to get map info for region %d\n\t(%s)\n",
318
Region, strerror(errno));
323
if(memAccP->memInfo.u.map_info_mmap.map_offset
327
memAccP->Checked = TRUE;
340
xf86MapInfoMap(struct memAccess *memInfoP, pointer Base, unsigned long Size)
342
struct map_info *mapInfoP = &(memInfoP->memInfo);
344
if (mapInfoP->u.map_info_mmap.map_size == MAP_INFO_UNKNOWN)
346
Size = (unsigned long)Base + Size;
350
Size = mapInfoP->u.map_info_mmap.map_size;
353
switch(mapInfoP->method)
356
/* Need to remap if size is unknown because we may not have
357
mapped the whole region initially */
358
if(memInfoP->regionVirtBase == NULL ||
359
mapInfoP->u.map_info_mmap.map_size == MAP_INFO_UNKNOWN)
361
if((memInfoP->regionVirtBase =
364
PROT_READ | PROT_WRITE,
367
(unsigned long)mapInfoP->u.map_info_mmap.map_offset))
370
FatalError("xf86MapInfoMap: Failed to map memory at 0x%x\n\t%s\n",
371
mapInfoP->u.map_info_mmap.map_offset, strerror(errno));
373
if(mapInfoP->u.map_info_mmap.internal_offset > 0)
374
memInfoP->regionVirtBase +=
375
mapInfoP->u.map_info_mmap.internal_offset;
380
FatalError("xf86MapInfoMap: Unsuported mapping method\n");
384
return (pointer)((int)memInfoP->regionVirtBase + (int)Base);
388
xf86MapInfoUnmap(struct memAccess *memInfoP, unsigned long Size)
390
struct map_info *mapInfoP = &(memInfoP->memInfo);
392
switch(mapInfoP->method)
395
if(memInfoP->regionVirtBase != NULL)
397
if(mapInfoP->u.map_info_mmap.map_size != MAP_INFO_UNKNOWN)
398
Size = mapInfoP->u.map_info_mmap.map_size;
399
munmap((caddr_t)memInfoP->regionVirtBase, Size);
400
memInfoP->regionVirtBase = NULL;
404
FatalError("xf86MapInfoMap: Unsuported mapping method\n");
410
armMapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags)
412
struct memAccess *memInfoP;
414
if((memInfoP = checkMapInfo(FALSE, Region)) != NULL)
417
** xf86 passes in a physical address offset from the start
418
** of physical memory, but xf86MapInfoMap expects an
419
** offset from the start of the specified region - it gets
420
** the physical address of the region from the display driver.
425
if (vgaPhysLinearBase)
427
Base -= vgaPhysLinearBase;
435
base = xf86MapInfoMap(memInfoP, Base, Size);
438
return mapVidMem(ScreenNum, Base, Size, flags);
442
armUnmapVidMem(int ScreenNum, pointer Base, unsigned long Size)
444
struct memAccess *memInfoP;
446
if((memInfoP = checkMapInfo(FALSE, Region)) != NULL)
448
xf86MapInfoUnmap(memInfoP, Base, Size);
450
unmapVidMem(ScreenNum, Base, Size);
454
static int IoFd = -1;
462
if ((IoFd = open("/dev/io", O_RDWR)) == -1)
464
xf86Msg(X_WARNING,"xf86EnableIO: "
465
"Failed to open /dev/io for extended I/O\n");
484
#if defined(USE_ARC_MMAP) || defined(__arm32__)
495
if ((fd = open("/dev/ttyC0", O_RDWR)) >= 0) {
496
/* Try to map a page at the pccons I/O space */
497
base = (pointer)mmap((caddr_t)0, 65536, PROT_READ | PROT_WRITE,
498
MAP_FLAGS, fd, (off_t)0x0000);
500
if (base != (pointer)-1) {
504
xf86Msg(X_WARNING,"EnableIO: failed to mmap %s (%s)\n",
505
"/dev/ttyC0", strerror(errno));
510
xf86Msg("EnableIO: failed to open %s (%s)\n",
511
"/dev/ttyC0", strerror(errno));
515
ExtendedEnabled = TRUE;
526
#endif /* USE_ARC_MMAP */
529
/***************************************************************************/
530
/* Interrupt Handling section */
531
/***************************************************************************/
534
xf86DisableInterrupts()
541
xf86EnableInterrupts()
551
* XXX This is here for reference. It needs to be handled differently for the
554
#if defined(USE_ARC_MMAP) || defined(__arm32__)
556
#ifdef USE_ARM32_MMAP
557
#define DEV_MEM_IOBASE 0x43000000
560
static Bool ScreenEnabled[MAXSCREENS];
561
static Bool ExtendedEnabled = FALSE;
562
static Bool InitDone = FALSE;
565
xf86EnableIOPorts(ScreenNum)
573
struct memAccess *memInfoP;
577
ScreenEnabled[ScreenNum] = TRUE;
583
if ((fd = open("/dev/ttyC0", O_RDWR)) >= 0) {
584
/* Try to map a page at the pccons I/O space */
585
base = (pointer)mmap((caddr_t)0, 65536, PROT_READ | PROT_WRITE,
586
MAP_FLAGS, fd, (off_t)0x0000);
588
if (base != (pointer)-1) {
593
"EnableIOPorts: failed to mmap %s (%s)\n",
594
"/dev/ttyC0", strerror(errno));
598
xf86Msg(X_ERROR, "EnableIOPorts: failed to open %s (%s)\n",
599
"/dev/ttyC0", strerror(errno));
604
IOPortBase = (unsigned int)-1;
606
if((memInfoP = checkMapInfo(TRUE, MMIO_REGION)) != NULL)
609
* xf86MapInfoMap maps an offset from the start of video IO
610
* space (e.g. 0x3B0), but IOPortBase is expected to map to
611
* physical address 0x000, so subtract the start of video I/O
612
* space from the result. This is safe for now becase we
613
* actually mmap the start of the page, then the start of video
614
* I/O space is added as an internal offset.
616
IOPortBase = (unsigned int)xf86MapInfoMap(memInfoP,
618
- memInfoP->memInfo.u.map_info_mmap.internal_offset;
619
ExtendedEnabled = TRUE;
622
#ifdef USE_ARM32_MMAP
625
if (devMemFd >= 0 && useDevMem)
627
base = (pointer)mmap((caddr_t)0, 0x400, PROT_READ | PROT_WRITE,
628
MAP_FLAGS, devMemFd, (off_t)DEV_MEM_IOBASE);
630
if (base != (pointer)-1)
631
IOPortBase = (unsigned int)base;
634
if (IOPortBase == (unsigned int)-1)
636
xf86Msg(X_WARNING,"xf86EnableIOPorts: failed to open mem device or map IO base. \n\
637
Make sure you have the Aperture Driver installed, or a kernel built with the INSECURE option\n");
641
/* We don't have the IOBASE, so we can't map the address */
642
xf86Msg(X_WARNING,"xf86EnableIOPorts: failed to open mem device or map IO base. \n\
643
Try building the server with USE_ARM32_MMAP defined\n");
648
ExtendedEnabled = TRUE;
654
xf86DisableIOPorts(ScreenNum)
659
struct memAccess *memInfoP;
662
ScreenEnabled[ScreenNum] = FALSE;
665
if((memInfoP = checkMapInfo(FALSE, MMIO_REGION)) != NULL)
667
xf86MapInfoUnmap(memInfoP, 0);
671
#ifdef USE_ARM32_MMAP
672
if (!ExtendedEnabled)
675
for (i = 0; i < MAXSCREENS; i++)
676
if (ScreenEnabled[i])
679
munmap((caddr_t)IOPortBase, 0x400);
680
IOPortBase = (unsigned int)-1;
681
ExtendedEnabled = FALSE;
687
#endif /* USE_ARC_MMAP || USE_ARM32_MMAP */