Commit | Line | Data |
---|---|---|
a09e091a JB |
1 | /* |
2 | * Copyright 1993 by David Wexelblat <dwex@goblin.org> | |
3 | * | |
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. | |
13 | * | |
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. | |
21 | * | |
22 | */ | |
23 | ||
24 | #ifdef HAVE_XORG_CONFIG_H | |
25 | #include <xorg-config.h> | |
26 | #endif | |
27 | ||
28 | #include <X11/X.h> | |
29 | ||
30 | #include "xf86.h" | |
31 | #include "xf86Priv.h" | |
32 | #include "xf86_OSlib.h" | |
33 | ||
34 | /* | |
35 | * Read BIOS via mmap()ing DEV_MEM | |
36 | */ | |
37 | ||
38 | #ifndef __alpha__ | |
39 | int | |
40 | xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf, | |
41 | int Len) | |
42 | { | |
43 | int fd; | |
44 | unsigned char *ptr; | |
45 | int psize; | |
46 | int mlen; | |
47 | ||
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)); | |
51 | return -1; | |
52 | } | |
53 | psize = getpagesize(); | |
54 | Offset += Base & (psize - 1); | |
55 | 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)); | |
62 | close(fd); | |
63 | return -1; | |
64 | } | |
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); | |
69 | (void) close(fd); | |
70 | return Len; | |
71 | } | |
72 | ||
73 | #else /* __alpha__ */ | |
74 | ||
75 | /* | |
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 | |
78 | * area. | |
79 | */ | |
80 | ||
81 | /* | |
82 | * NOTE: there prolly ought to be more validity checks and all | |
83 | * re: boundaries and sizes and such... | |
84 | */ | |
85 | ||
86 | #ifdef linux | |
87 | ||
88 | extern unsigned long _bus_base(void); | |
89 | ||
90 | #define BUS_BASE _bus_base() | |
91 | ||
92 | #else | |
93 | ||
94 | extern u_int64_t dense_base(void); | |
95 | ||
96 | #define BUS_BASE dense_base() | |
97 | ||
98 | #endif | |
99 | ||
100 | int | |
101 | xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf, | |
102 | int Len) | |
103 | { | |
104 | caddr_t base; | |
105 | int fd; | |
106 | int psize; | |
107 | int mlen; | |
108 | ||
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)); | |
112 | return -1; | |
113 | } | |
114 | ||
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)); | |
121 | ||
122 | if (base == MAP_FAILED) { | |
123 | xf86Msg(X_WARNING, "xf86ReadBIOS: Failed to mmap %s (%s)\n", | |
124 | DEV_MEM, strerror(errno)); | |
125 | return -1; | |
126 | } | |
127 | ||
128 | xf86SlowBCopyFromBus((unsigned char *) (base + Offset), Buf, Len); | |
129 | ||
130 | munmap((caddr_t) base, mlen); | |
131 | close(fd); | |
132 | return Len; | |
133 | } | |
134 | ||
135 | #endif /* __alpha__ */ |