1
/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/shared/bios_mmap.c,v 1.8 2000/11/19 16:38:06 tsi Exp $ */
3
* Copyright 1993 by David Wexelblat <dwex@goblin.org>
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 name of David Wexelblat not be used in
10
* advertising or publicity pertaining to distribution of the software without
11
* specific, written prior permission. David Wexelblat makes no representations
12
* about the suitability of this software for any purpose. It is provided
13
* "as is" without express or implied warranty.
15
* DAVID WEXELBLAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
17
* EVENT SHALL DAVID WEXELBLAT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
19
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
20
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
21
* PERFORMANCE OF THIS SOFTWARE.
24
/* $XConsortium: bios_V4mmap.c /main/4 1996/02/21 17:54:27 kaleb $ */
26
#ifdef HAVE_XORG_CONFIG_H
27
#include <xorg-config.h>
34
#include "xf86_OSlib.h"
37
#define MAP_FAILED ((void *)-1)
41
* Read BIOS via mmap()ing DEV_MEM
46
xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf,
54
if ((fd = open(DEV_MEM, O_RDONLY)) < 0)
56
xf86Msg(X_WARNING, "xf86ReadBIOS: Failed to open %s (%s)\n",
57
DEV_MEM, strerror(errno));
60
psize = xf86getpagesize();
61
Offset += Base & (psize - 1);
63
mlen = (Offset + Len + psize - 1) & ~(psize - 1);
64
ptr = (unsigned char *)mmap((caddr_t)0, mlen, PROT_READ,
65
MAP_SHARED, fd, (off_t)Base);
66
if (ptr == MAP_FAILED)
68
xf86Msg(X_WARNING, "xf86ReadBIOS: %s mmap failed (%s)\n",
69
DEV_MEM, strerror(errno));
74
ErrorF("xf86ReadBIOS: BIOS at 0x%08x has signature 0x%04x\n",
75
Base, ptr[0] | (ptr[1] << 8));
77
(void)memcpy(Buf, (void *)(ptr + Offset), Len);
78
(void)munmap((caddr_t)ptr, mlen);
86
* We trick "mmap" into mapping BUS memory for us via BUS_BASE,
87
* which is the KSEG address of the start of the DENSE memory
92
* NOTE: there prolly ought to be more validity checks and all
93
* re: boundaries and sizes and such...
97
* The Jensen lacks dense memory, thus we have to address the bus via
98
* the sparse addressing scheme.
100
* Martin Ostermann (ost@comnets.rwth-aachen.de) - Apr.-Sep. 1996
105
#ifdef TEST_JENSEN_CODE /* define to test the Sparse addressing on a non-Jensen */
109
#define isJensen (!_bus_base())
113
extern unsigned long _bus_base(void);
114
extern unsigned long _bus_base_sparse(void);
115
#define BUS_BASE (isJensen ? _bus_base_sparse() : _bus_base())
116
#define JENSEN_SHIFT(x) (isJensen ? ((long)x<<SPARSE) : (long)x)
120
extern u_int64_t dense_base(void);
121
#define BUS_BASE dense_base()
122
#define JENSEN_SHIFT(x) ((long) x)
127
xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf,
135
if ((fd = open(DEV_MEM, O_RDONLY)) < 0)
137
xf86Msg(X_WARNING, "xf86ReadBIOS: Failed to open %s (%s)\n",
138
DEV_MEM, strerror(errno));
142
psize = xf86getpagesize();
143
Offset += Base & (psize - 1);
144
Base &= ~(psize - 1);
145
mlen = (Offset + Len + psize - 1) & ~(psize - 1);
146
base = mmap((caddr_t)0, JENSEN_SHIFT(mlen), PROT_READ,
147
MAP_SHARED, fd, (off_t)(JENSEN_SHIFT(Base) + BUS_BASE));
149
if (base == MAP_FAILED)
151
xf86Msg(X_WARNING, "xf86ReadBIOS: Failed to mmap %s (%s)\n",
152
DEV_MEM, strerror(errno));
156
xf86SlowBCopyFromBus((unsigned char *)(base+JENSEN_SHIFT(Offset)),
159
munmap((caddr_t)JENSEN_SHIFT(base), JENSEN_SHIFT(mlen));
164
#endif /* __alpha__ */