2 * Copyright 1993 by David Wexelblat <dwex@goblin.org>
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of David Wexelblat not be used in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific, written prior permission. David Wexelblat makes no representations
11 * about the suitability of this software for any purpose. It is provided
12 * "as is" without express or implied warranty.
14 * DAVID WEXELBLAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL DAVID WEXELBLAT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 * PERFORMANCE OF THIS SOFTWARE.
24 #ifdef HAVE_XORG_CONFIG_H
25 #include <xorg-config.h>
32 #include "xf86_OSlib.h"
35 * Read BIOS via mmap()ing DEV_MEM
40 xf86ReadBIOS(unsigned long Base
, unsigned long Offset
, unsigned char *Buf
,
48 if ((fd
= open(DEV_MEM
, O_RDONLY
)) < 0) {
49 xf86Msg(X_WARNING
, "xf86ReadBIOS: Failed to open %s (%s)\n",
50 DEV_MEM
, strerror(errno
));
53 psize
= getpagesize();
54 Offset
+= Base
& (psize
- 1);
56 mlen
= (Offset
+ Len
+ psize
- 1) & ~(psize
- 1);
57 ptr
= (unsigned char *) mmap((caddr_t
) 0, mlen
, PROT_READ
,
58 MAP_SHARED
, fd
, (off_t
) Base
);
59 if (ptr
== MAP_FAILED
) {
60 xf86Msg(X_WARNING
, "xf86ReadBIOS: %s mmap failed (%s)\n",
61 DEV_MEM
, strerror(errno
));
65 DebugF("xf86ReadBIOS: BIOS at 0x%08x has signature 0x%04x\n",
66 Base
, ptr
[0] | (ptr
[1] << 8));
67 (void) memcpy(Buf
, (void *) (ptr
+ Offset
), Len
);
68 (void) munmap((caddr_t
) ptr
, mlen
);
76 * We trick "mmap" into mapping BUS memory for us via BUS_BASE,
77 * which is the KSEG address of the start of the DENSE memory
82 * NOTE: there prolly ought to be more validity checks and all
83 * re: boundaries and sizes and such...
88 extern unsigned long _bus_base(void);
90 #define BUS_BASE _bus_base()
94 extern u_int64_t
dense_base(void);
96 #define BUS_BASE dense_base()
101 xf86ReadBIOS(unsigned long Base
, unsigned long Offset
, unsigned char *Buf
,
109 if ((fd
= open(DEV_MEM
, O_RDONLY
)) < 0) {
110 xf86Msg(X_WARNING
, "xf86ReadBIOS: Failed to open %s (%s)\n",
111 DEV_MEM
, strerror(errno
));
115 psize
= getpagesize();
116 Offset
+= Base
& (psize
- 1);
117 Base
&= ~(psize
- 1);
118 mlen
= (Offset
+ Len
+ psize
- 1) & ~(psize
- 1);
119 base
= mmap((caddr_t
) 0, mlen
, PROT_READ
,
120 MAP_SHARED
, fd
, (off_t
) (Base
+ BUS_BASE
));
122 if (base
== MAP_FAILED
) {
123 xf86Msg(X_WARNING
, "xf86ReadBIOS: Failed to mmap %s (%s)\n",
124 DEV_MEM
, strerror(errno
));
128 xf86SlowBCopyFromBus((unsigned char *) (base
+ Offset
), Buf
, Len
);
130 munmap((caddr_t
) base
, mlen
);
135 #endif /* __alpha__ */