~ubuntu-branches/ubuntu/intrepid/xserver-xgl/intrepid

« back to all changes in this revision

Viewing changes to hw/xfree86/os-support/shared/bios_mmap.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthew Garrett
  • Date: 2006-02-13 14:21:43 UTC
  • Revision ID: james.westby@ubuntu.com-20060213142143-mad6z9xzem7hzxz9
Tags: upstream-7.0.0
ImportĀ upstreamĀ versionĀ 7.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/shared/bios_mmap.c,v 1.8 2000/11/19 16:38:06 tsi Exp $ */
 
2
/*
 
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 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.
 
14
 *
 
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.
 
22
 *
 
23
 */
 
24
/* $XConsortium: bios_V4mmap.c /main/4 1996/02/21 17:54:27 kaleb $ */
 
25
 
 
26
#ifdef HAVE_XORG_CONFIG_H
 
27
#include <xorg-config.h>
 
28
#endif
 
29
 
 
30
#include <X11/X.h>
 
31
 
 
32
#include "xf86.h"
 
33
#include "xf86Priv.h"
 
34
#include "xf86_OSlib.h"
 
35
 
 
36
#ifndef MAP_FAILED
 
37
#define MAP_FAILED ((void *)-1)
 
38
#endif
 
39
 
 
40
/*
 
41
 * Read BIOS via mmap()ing DEV_MEM
 
42
 */
 
43
 
 
44
#ifndef __alpha__
 
45
int
 
46
xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf,
 
47
             int Len)
 
48
{
 
49
        int fd;
 
50
        unsigned char *ptr;
 
51
        int psize;
 
52
        int mlen;
 
53
 
 
54
        if ((fd = open(DEV_MEM, O_RDONLY)) < 0)
 
55
        {
 
56
                xf86Msg(X_WARNING, "xf86ReadBIOS: Failed to open %s (%s)\n",
 
57
                        DEV_MEM, strerror(errno));
 
58
                return(-1);
 
59
        }
 
60
        psize = xf86getpagesize();
 
61
        Offset += Base & (psize - 1);
 
62
        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)
 
67
        {
 
68
                xf86Msg(X_WARNING, "xf86ReadBIOS: %s mmap failed (%s)\n",
 
69
                        DEV_MEM, strerror(errno));
 
70
                close(fd);
 
71
                return(-1);
 
72
        }
 
73
#ifdef DEBUG
 
74
        ErrorF("xf86ReadBIOS: BIOS at 0x%08x has signature 0x%04x\n",
 
75
                Base, ptr[0] | (ptr[1] << 8));
 
76
#endif
 
77
        (void)memcpy(Buf, (void *)(ptr + Offset), Len);
 
78
        (void)munmap((caddr_t)ptr, mlen);
 
79
        (void)close(fd);
 
80
        return(Len);
 
81
}
 
82
 
 
83
#else /* __alpha__ */
 
84
 
 
85
  /*
 
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
 
88
   *  area.
 
89
   */
 
90
 
 
91
  /*
 
92
   * NOTE: there prolly ought to be more validity checks and all
 
93
   *  re: boundaries and sizes and such...
 
94
   */
 
95
 
 
96
/*
 
97
 * The Jensen lacks dense memory, thus we have to address the bus via
 
98
 * the sparse addressing scheme.
 
99
 *
 
100
 * Martin Ostermann (ost@comnets.rwth-aachen.de) - Apr.-Sep. 1996
 
101
 */
 
102
 
 
103
#ifdef linux
 
104
 
 
105
#ifdef TEST_JENSEN_CODE /* define to test the Sparse addressing on a non-Jensen */
 
106
#define SPARSE (5)
 
107
#define isJensen (1)
 
108
#else
 
109
#define isJensen (!_bus_base())
 
110
#define SPARSE (7)
 
111
#endif
 
112
 
 
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)
 
117
 
 
118
#else
 
119
 
 
120
extern u_int64_t dense_base(void);
 
121
#define BUS_BASE dense_base()
 
122
#define JENSEN_SHIFT(x) ((long) x)
 
123
 
 
124
#endif
 
125
 
 
126
int
 
127
xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf,
 
128
             int Len)
 
129
{
 
130
        caddr_t base;
 
131
        int fd;
 
132
        int psize;
 
133
        int mlen;
 
134
 
 
135
        if ((fd = open(DEV_MEM, O_RDONLY)) < 0)
 
136
        {
 
137
                xf86Msg(X_WARNING, "xf86ReadBIOS: Failed to open %s (%s)\n",
 
138
                        DEV_MEM, strerror(errno));
 
139
                return(-1);
 
140
        }
 
141
 
 
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));
 
148
 
 
149
        if (base == MAP_FAILED)
 
150
        {
 
151
                xf86Msg(X_WARNING, "xf86ReadBIOS: Failed to mmap %s (%s)\n",
 
152
                        DEV_MEM, strerror(errno));
 
153
                return(-1);
 
154
        }
 
155
 
 
156
        xf86SlowBCopyFromBus((unsigned char *)(base+JENSEN_SHIFT(Offset)), 
 
157
                                                                    Buf, Len);
 
158
 
 
159
        munmap((caddr_t)JENSEN_SHIFT(base), JENSEN_SHIFT(mlen));
 
160
        close(fd);
 
161
        return(Len);
 
162
}
 
163
 
 
164
#endif /* __alpha__ */