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

« back to all changes in this revision

Viewing changes to hw/xfree86/os-support/bsd/arm_video.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/bsd/arm_video.c,v 1.1tsi Exp $ */
 
2
/*
 
3
 * Copyright 1992 by Rich Murphey <Rich@Rice.edu>
 
4
 * Copyright 1993 by David Wexelblat <dwex@goblin.org>
 
5
 *
 
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 
 
15
 * implied warranty.
 
16
 *
 
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.
 
24
 *
 
25
 */
 
26
 
 
27
/*
 
28
 * The ARM32 code here carries the following copyright:
 
29
 *
 
30
 * Copyright 1997
 
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
 
36
 * transferred hereby.
 
37
 *
 
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
 
40
 *    source file.
 
41
 *
 
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.
 
47
 *
 
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. 
 
57
 *
 
58
 */
 
59
 
 
60
/* $XConsortium: bsd_video.c /main/10 1996/10/25 11:37:57 kaleb $ */
 
61
 
 
62
#ifdef HAVE_XORG_CONFIG_H
 
63
#include <xorg-config.h>
 
64
#endif
 
65
 
 
66
#include <X11/X.h>
 
67
#include "xf86.h"
 
68
#include "xf86Priv.h"
 
69
#include "xf86_OSlib.h"
 
70
#include "xf86OSpriv.h"
 
71
 
 
72
#ifdef __arm32__
 
73
#include "machine/devmap.h"
 
74
struct memAccess
 
75
{
 
76
    int ioctl;
 
77
    struct map_info memInfo;
 
78
    pointer regionVirtBase;
 
79
    Bool Checked;
 
80
    Bool OK;
 
81
};
 
82
 
 
83
static pointer xf86MapInfoMap();
 
84
static void xf86MapInfoUnmap();
 
85
static struct memAccess *checkMapInfo();
 
86
extern int vgaPhysLinearBase;
 
87
 
 
88
/* A memAccess structure is needed for each possible region */ 
 
89
struct memAccess vgaMemInfo = { CONSOLE_GET_MEM_INFO, NULL, NULL, 
 
90
                                    FALSE, FALSE };
 
91
struct memAccess linearMemInfo = { CONSOLE_GET_LINEAR_INFO, NULL, NULL, 
 
92
                                       FALSE, FALSE };
 
93
struct memAccess ioMemInfo = { CONSOLE_GET_IO_INFO, NULL, NULL,
 
94
                                   FALSE, FALSE };
 
95
#endif /* __arm32__ */
 
96
 
 
97
#if defined(__NetBSD__) && !defined(MAP_FILE)
 
98
#define MAP_FLAGS MAP_SHARED
 
99
#else
 
100
#define MAP_FLAGS (MAP_FILE | MAP_SHARED)
 
101
#endif
 
102
 
 
103
#ifndef MAP_FAILED
 
104
#define MAP_FAILED ((caddr_t)-1)
 
105
#endif
 
106
 
 
107
 
 
108
#define BUS_BASE        0L
 
109
#define BUS_BASE_BWX    0L
 
110
 
 
111
 
 
112
/***************************************************************************/
 
113
/* Video Memory Mapping section                                            */
 
114
/***************************************************************************/
 
115
 
 
116
static Bool useDevMem = FALSE;
 
117
static int  devMemFd = -1;
 
118
 
 
119
#define DEV_MEM "/dev/mem"
 
120
 
 
121
static pointer mapVidMem(int, unsigned long, unsigned long, int);
 
122
static void unmapVidMem(int, pointer, unsigned long);
 
123
 
 
124
/*
 
125
 * Check if /dev/mem can be mmap'd.  If it can't print a warning when
 
126
 * "warn" is TRUE.
 
127
 */
 
128
static void
 
129
checkDevMem(Bool warn)
 
130
{
 
131
        static Bool devMemChecked = FALSE;
 
132
        int fd;
 
133
        pointer base;
 
134
 
 
135
        if (devMemChecked)
 
136
            return;
 
137
        devMemChecked = TRUE;
 
138
 
 
139
        if ((fd = open(DEV_MEM, O_RDWR)) >= 0)
 
140
        {
 
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);
 
144
        
 
145
            if (base != MAP_FAILED)
 
146
            {
 
147
                munmap((caddr_t)base, 4096);
 
148
                devMemFd = fd;
 
149
                useDevMem = TRUE;
 
150
                return;
 
151
            } else {
 
152
                /* This should not happen */
 
153
                if (warn)
 
154
                {
 
155
                    xf86Msg(X_WARNING, "checkDevMem: failed to mmap %s (%s)\n",
 
156
                            DEV_MEM, strerror(errno));
 
157
                }
 
158
                useDevMem = FALSE;
 
159
                return;
 
160
            }
 
161
        }
 
162
        if (warn)
 
163
        { 
 
164
            xf86Msg(X_WARNING, "checkDevMem: failed to open %s (%s)\n",
 
165
                    DEV_MEM, strerror(errno));
 
166
        } 
 
167
        useDevMem = FALSE;
 
168
        return;
 
169
}
 
170
 
 
171
void
 
172
xf86OSInitVidMem(VidMemInfoPtr pVidMem)
 
173
{
 
174
 
 
175
        checkDevMem(TRUE);
 
176
        pVidMem->linearSupported = useDevMem;
 
177
        pVidMem->mapMem = armMapVidMem;
 
178
        pVidMem->unmapVidMem = armUnmapVidMem;
 
179
 
 
180
        pVidMem->initialised = TRUE;
 
181
}
 
182
 
 
183
static pointer
 
184
mapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags)
 
185
{
 
186
        pointer base;
 
187
 
 
188
        checkDevMem(FALSE);
 
189
 
 
190
        if (useDevMem)
 
191
        {
 
192
            if (devMemFd < 0) 
 
193
            {
 
194
                FatalError("xf86MapVidMem: failed to open %s (%s)\n",
 
195
                           DEV_MEM, strerror(errno));
 
196
            }
 
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)
 
202
            {
 
203
                FatalError("%s: could not mmap %s [s=%x,a=%x] (%s)\n",
 
204
                           "xf86MapVidMem", DEV_MEM, Size, Base, 
 
205
                           strerror(errno));
 
206
            }
 
207
            return(base);
 
208
        }
 
209
                
 
210
        /* else, mmap /dev/vga */
 
211
        if ((unsigned long)Base < 0xA0000 || (unsigned long)Base >= 0xC0000)
 
212
        {
 
213
                FatalError("%s: Address 0x%x outside allowable range\n",
 
214
                           "xf86MapVidMem", Base);
 
215
        }
 
216
        base = mmap(0, Size,
 
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)
 
222
        {
 
223
            FatalError("xf86MapVidMem: Could not mmap /dev/vga (%s)\n",
 
224
                       strerror(errno));
 
225
        }
 
226
        return(base);
 
227
}
 
228
 
 
229
static void
 
230
unmapVidMem(int ScreenNum, pointer Base, unsigned long Size)
 
231
{
 
232
        munmap((caddr_t)Base, Size);
 
233
}
 
234
 
 
235
/*
 
236
 * Read BIOS via mmap()ing DEV_MEM
 
237
 */
 
238
 
 
239
int
 
240
xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf,
 
241
             int Len)
 
242
{
 
243
        unsigned char *ptr;
 
244
        int psize;
 
245
        int mlen;
 
246
 
 
247
        checkDevMem(TRUE);
 
248
        if (devMemFd == -1) {
 
249
            return(-1);
 
250
        }
 
251
 
 
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);
 
258
        if ((long)ptr == -1)
 
259
        {
 
260
                xf86Msg(X_WARNING, 
 
261
                        "xf86ReadBIOS: %s mmap[s=%x,a=%x,o=%x] failed (%s)\n",
 
262
                        DEV_MEM, Len, Base, Offset, strerror(errno));
 
263
                return(-1);
 
264
        }
 
265
#ifdef DEBUG
 
266
        ErrorF("xf86ReadBIOS: BIOS at 0x%08x has signature 0x%04x\n",
 
267
                Base, ptr[0] | (ptr[1] << 8));
 
268
#endif
 
269
        (void)memcpy(Buf, (void *)(ptr + Offset), Len);
 
270
        (void)munmap((caddr_t)ptr, mlen);
 
271
#ifdef DEBUG
 
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]);
 
275
#endif
 
276
        return(Len);
 
277
}
 
278
 
 
279
 
 
280
/* XXX This needs to be updated for the ND */
 
281
 
 
282
/*
 
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.
 
285
*/
 
286
static struct memAccess *
 
287
checkMapInfo(Bool warn, int Region)
 
288
{
 
289
    struct memAccess *memAccP;
 
290
        
 
291
    switch (Region)
 
292
    {
 
293
        case VGA_REGION:
 
294
            memAccP = &vgaMemInfo;
 
295
            break;
 
296
                    
 
297
        case LINEAR_REGION:
 
298
            memAccP = &linearMemInfo;
 
299
            break;
 
300
            
 
301
        case MMIO_REGION:
 
302
            memAccP = &ioMemInfo;
 
303
            break;
 
304
        
 
305
        default:
 
306
            return NULL;
 
307
            break;
 
308
    }
 
309
    
 
310
    if(!memAccP->Checked)
 
311
    {   
 
312
        if(ioctl(xf86Info.screenFd, memAccP->ioctl, &(memAccP->memInfo)) == -1)
 
313
        {
 
314
            if(warn)
 
315
            {
 
316
                xf86Msg(X_WARNING,
 
317
                 "checkMapInfo: failed to get map info for region %d\n\t(%s)\n",
 
318
                       Region, strerror(errno));
 
319
            }
 
320
        }
 
321
        else
 
322
        {
 
323
            if(memAccP->memInfo.u.map_info_mmap.map_offset 
 
324
               != MAP_INFO_UNKNOWN)
 
325
                memAccP->OK = TRUE;
 
326
        }
 
327
        memAccP->Checked = TRUE;
 
328
    }
 
329
    if (memAccP->OK)
 
330
    {
 
331
        return memAccP;
 
332
    }
 
333
    else
 
334
    {
 
335
        return NULL;
 
336
    }
 
337
}
 
338
 
 
339
static pointer
 
340
xf86MapInfoMap(struct memAccess *memInfoP, pointer Base, unsigned long Size)
 
341
{
 
342
    struct map_info *mapInfoP = &(memInfoP->memInfo);
 
343
 
 
344
    if (mapInfoP->u.map_info_mmap.map_size == MAP_INFO_UNKNOWN)
 
345
    {   
 
346
        Size = (unsigned long)Base + Size;
 
347
    }
 
348
    else
 
349
    {
 
350
        Size = mapInfoP->u.map_info_mmap.map_size;
 
351
    }
 
352
    
 
353
    switch(mapInfoP->method)
 
354
    {
 
355
        case MAP_MMAP:
 
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)
 
360
            {
 
361
                if((memInfoP->regionVirtBase = 
 
362
                    mmap((caddr_t)0,
 
363
                         Size,
 
364
                         PROT_READ | PROT_WRITE,
 
365
                         MAP_SHARED,
 
366
                         xf86Info.screenFd,
 
367
                         (unsigned long)mapInfoP->u.map_info_mmap.map_offset))
 
368
                   == (pointer)-1)
 
369
                {
 
370
                    FatalError("xf86MapInfoMap: Failed to map memory at 0x%x\n\t%s\n", 
 
371
                               mapInfoP->u.map_info_mmap.map_offset, strerror(errno));
 
372
                }
 
373
                if(mapInfoP->u.map_info_mmap.internal_offset > 0)
 
374
                    memInfoP->regionVirtBase += 
 
375
                        mapInfoP->u.map_info_mmap.internal_offset;
 
376
            }
 
377
            break;
 
378
            
 
379
        default:
 
380
            FatalError("xf86MapInfoMap: Unsuported mapping method\n");
 
381
            break;
 
382
    }
 
383
            
 
384
    return (pointer)((int)memInfoP->regionVirtBase + (int)Base);
 
385
}
 
386
 
 
387
static void
 
388
xf86MapInfoUnmap(struct memAccess *memInfoP, unsigned long Size)
 
389
{
 
390
    struct map_info *mapInfoP = &(memInfoP->memInfo);
 
391
    
 
392
    switch(mapInfoP->method)
 
393
    {
 
394
        case MAP_MMAP:
 
395
            if(memInfoP->regionVirtBase != NULL)
 
396
            {
 
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;
 
401
            }
 
402
            break;
 
403
         default:
 
404
            FatalError("xf86MapInfoMap: Unsuported mapping method\n");
 
405
            break;
 
406
    }
 
407
}
 
408
 
 
409
static pointer
 
410
armMapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags)
 
411
{
 
412
        struct memAccess *memInfoP;
 
413
        
 
414
        if((memInfoP = checkMapInfo(FALSE, Region)) != NULL)
 
415
        {
 
416
            /*
 
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.
 
421
             */
 
422
            switch(Region)
 
423
            {
 
424
                case LINEAR_REGION:
 
425
                    if (vgaPhysLinearBase)
 
426
                    {
 
427
                        Base -= vgaPhysLinearBase;
 
428
                    }
 
429
                    break;
 
430
                case VGA_REGION:
 
431
                    Base -= 0xA0000;
 
432
                    break;
 
433
            }
 
434
            
 
435
            base = xf86MapInfoMap(memInfoP, Base, Size);
 
436
            return (base);
 
437
        }
 
438
        return mapVidMem(ScreenNum, Base, Size, flags);
 
439
}
 
440
 
 
441
static void
 
442
armUnmapVidMem(int ScreenNum, pointer Base, unsigned long Size)
 
443
{
 
444
        struct memAccess *memInfoP;
 
445
        
 
446
        if((memInfoP = checkMapInfo(FALSE, Region)) != NULL)
 
447
        {
 
448
            xf86MapInfoUnmap(memInfoP, Base, Size);
 
449
        }
 
450
        unmapVidMem(ScreenNum, Base, Size);
 
451
}
 
452
 
 
453
#ifdef USE_DEV_IO
 
454
static int IoFd = -1;
 
455
 
 
456
Bool
 
457
xf86EnableIO()
 
458
{
 
459
        if (IoFd >= 0)
 
460
                return TRUE;
 
461
 
 
462
        if ((IoFd = open("/dev/io", O_RDWR)) == -1)
 
463
        {
 
464
                xf86Msg(X_WARNING,"xf86EnableIO: "
 
465
                                "Failed to open /dev/io for extended I/O\n");
 
466
                return FALSE;
 
467
        }
 
468
        return TRUE;
 
469
}
 
470
 
 
471
void
 
472
xf86DisableIO()
 
473
{
 
474
        if (IoFd < 0)
 
475
                return;
 
476
 
 
477
        close(IoFd);
 
478
        IoFd = -1;
 
479
        return;
 
480
}
 
481
 
 
482
#endif
 
483
 
 
484
#if defined(USE_ARC_MMAP) || defined(__arm32__)
 
485
 
 
486
Bool
 
487
xf86EnableIO()
 
488
{
 
489
        int fd;
 
490
        pointer base;
 
491
 
 
492
        if (ExtendedEnabled)
 
493
                return TRUE;
 
494
 
 
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);
 
499
 
 
500
                if (base != (pointer)-1) {
 
501
                        IOPortBase = base;
 
502
                }
 
503
                else {
 
504
                        xf86Msg(X_WARNING,"EnableIO: failed to mmap %s (%s)\n",
 
505
                                "/dev/ttyC0", strerror(errno));
 
506
                        return FALSE;
 
507
                }
 
508
        }
 
509
        else {
 
510
                xf86Msg("EnableIO: failed to open %s (%s)\n",
 
511
                        "/dev/ttyC0", strerror(errno));
 
512
                return FALSE;
 
513
        }
 
514
        
 
515
        ExtendedEnabled = TRUE;
 
516
 
 
517
        return TRUE;
 
518
}
 
519
 
 
520
void
 
521
xf86DisableIO()
 
522
{
 
523
        return;
 
524
}
 
525
 
 
526
#endif /* USE_ARC_MMAP */
 
527
 
 
528
 
 
529
/***************************************************************************/
 
530
/* Interrupt Handling section                                              */
 
531
/***************************************************************************/
 
532
 
 
533
Bool
 
534
xf86DisableInterrupts()
 
535
{
 
536
 
 
537
        return(TRUE);
 
538
}
 
539
 
 
540
void
 
541
xf86EnableInterrupts()
 
542
{
 
543
 
 
544
        return;
 
545
}
 
546
 
 
547
 
 
548
 
 
549
#if 0
 
550
/*
 
551
 * XXX This is here for reference.  It needs to be handled differently for the
 
552
 * ND.
 
553
 */
 
554
#if defined(USE_ARC_MMAP) || defined(__arm32__)
 
555
 
 
556
#ifdef USE_ARM32_MMAP
 
557
#define DEV_MEM_IOBASE  0x43000000
 
558
#endif
 
559
 
 
560
static Bool ScreenEnabled[MAXSCREENS];
 
561
static Bool ExtendedEnabled = FALSE;
 
562
static Bool InitDone = FALSE;
 
563
 
 
564
Bool
 
565
xf86EnableIOPorts(ScreenNum)
 
566
int ScreenNum;
 
567
{
 
568
        int i;
 
569
        int fd;
 
570
        pointer base;
 
571
 
 
572
#ifdef __arm32__
 
573
        struct memAccess *memInfoP;
 
574
        int *Size;
 
575
#endif
 
576
 
 
577
        ScreenEnabled[ScreenNum] = TRUE;
 
578
 
 
579
        if (ExtendedEnabled)
 
580
                return TRUE;
 
581
 
 
582
#ifdef USE_ARC_MMAP
 
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);
 
587
 
 
588
                if (base != (pointer)-1) {
 
589
                        IOPortBase = base;
 
590
                }
 
591
                else {
 
592
                        xf86Msg(X_ERROR,
 
593
                                "EnableIOPorts: failed to mmap %s (%s)\n",
 
594
                                "/dev/ttyC0", strerror(errno));
 
595
                }
 
596
        }
 
597
        else {
 
598
                xf86Msg(X_ERROR, "EnableIOPorts: failed to open %s (%s)\n",
 
599
                        "/dev/ttyC0", strerror(errno));
 
600
        }
 
601
#endif
 
602
 
 
603
#ifdef __arm32__
 
604
        IOPortBase = (unsigned int)-1;
 
605
 
 
606
        if((memInfoP = checkMapInfo(TRUE, MMIO_REGION)) != NULL)
 
607
        {
 
608
            /* 
 
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.
 
615
             */
 
616
            IOPortBase = (unsigned int)xf86MapInfoMap(memInfoP,
 
617
                                                      (caddr_t)0x0, 0L) 
 
618
                - memInfoP->memInfo.u.map_info_mmap.internal_offset;
 
619
            ExtendedEnabled = TRUE;
 
620
            return TRUE;
 
621
        }
 
622
#ifdef USE_ARM32_MMAP
 
623
        checkDevMem(TRUE);
 
624
 
 
625
        if (devMemFd >= 0 && useDevMem)
 
626
        {
 
627
            base = (pointer)mmap((caddr_t)0, 0x400, PROT_READ | PROT_WRITE,
 
628
                                 MAP_FLAGS, devMemFd, (off_t)DEV_MEM_IOBASE);
 
629
 
 
630
            if (base != (pointer)-1)
 
631
                IOPortBase = (unsigned int)base;
 
632
        }
 
633
 
 
634
        if (IOPortBase == (unsigned int)-1)
 
635
        {       
 
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");
 
638
            return FALSE;
 
639
        }
 
640
#else
 
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");
 
644
        return FALSE;
 
645
#endif
 
646
#endif
 
647
        
 
648
        ExtendedEnabled = TRUE;
 
649
 
 
650
        return TRUE;
 
651
}
 
652
 
 
653
void
 
654
xf86DisableIOPorts(ScreenNum)
 
655
int ScreenNum;
 
656
{
 
657
        int i;
 
658
#ifdef __arm32__
 
659
        struct memAccess *memInfoP;
 
660
#endif
 
661
 
 
662
        ScreenEnabled[ScreenNum] = FALSE;
 
663
 
 
664
#ifdef __arm32__
 
665
        if((memInfoP = checkMapInfo(FALSE, MMIO_REGION)) != NULL)
 
666
        {
 
667
            xf86MapInfoUnmap(memInfoP, 0);
 
668
        }
 
669
#endif
 
670
 
 
671
#ifdef USE_ARM32_MMAP
 
672
        if (!ExtendedEnabled)
 
673
        return;
 
674
 
 
675
        for (i = 0; i < MAXSCREENS; i++)
 
676
                if (ScreenEnabled[i])
 
677
                        return;
 
678
 
 
679
        munmap((caddr_t)IOPortBase, 0x400);
 
680
        IOPortBase = (unsigned int)-1;
 
681
        ExtendedEnabled = FALSE;
 
682
#endif
 
683
 
 
684
        return;
 
685
}
 
686
 
 
687
#endif /* USE_ARC_MMAP || USE_ARM32_MMAP */
 
688
#endif
 
689
 
 
690