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

« back to all changes in this revision

Viewing changes to hw/xfree86/os-support/usl/usl_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
/* $XdotOrg: xserver/xorg/hw/xfree86/os-support/usl/usl_video.c,v 1.2 2005/11/08 06:33:30 jkj Exp $ */
 
2
/*
 
3
 * Copyrught 2005 Kean Johnston <jkj@sco.com>
 
4
 * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany
 
5
 * Copyright 1993 by David Wexelblat <dwex@goblin.org>
 
6
 *
 
7
 * Permission to use, copy, modify, distribute, and sell this software and its
 
8
 * documentation for any purpose is hereby granted without fee, provided that
 
9
 * the above copyright notice appear in all copies and that both that
 
10
 * copyright notice and this permission notice appear in supporting
 
11
 * documentation, and that the names of Thomas Roell, David Dawes 
 
12
 * and Kean Johnston not be used in advertising or publicity pertaining to
 
13
 * distribution of the software without specific, written prior permission.
 
14
 * Thomas Roell, David Dawes and Kean Johnston make no representations
 
15
 * about the suitability of this software for any purpose.  It is provided
 
16
 * "as is" without express or implied warranty.
 
17
 *
 
18
 * THOMAS ROELL, DAVID DAWES AND KEAN JOHNSTON DISCLAIM ALL WARRANTIES
 
19
 * WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
 
20
 * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL THOMAS ROELLm DAVID WEXELBLAT
 
21
 * OR KEAN JOHNSTON BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
 
22
 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
 
23
 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
 
24
 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
 
25
 * THIS SOFTWARE.
 
26
 *
 
27
 */
 
28
/* $XConsortium$ */
 
29
 
 
30
#include "X.h"
 
31
 
 
32
#define _NEED_SYSI86
 
33
#include "xf86.h"
 
34
#include "xf86Priv.h"
 
35
#include "xf86_OSlib.h"
 
36
#include "xf86OSpriv.h"
 
37
 
 
38
#ifndef MAP_FAILED
 
39
#define MAP_FAILED ((void *)-1)
 
40
#endif
 
41
 
 
42
static Bool
 
43
linearVidMem(void)
 
44
{
 
45
  return TRUE;
 
46
}
 
47
 
 
48
static pointer
 
49
mapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags)
 
50
{
 
51
  pointer base;
 
52
  int fd;
 
53
 
 
54
  fd = open(DEV_MEM, (flags & VIDMEM_READONLY) ? O_RDONLY : O_RDWR);
 
55
  if (fd < 0) {
 
56
    FatalError("xf86MapVidMem: failed to open %s (%s)\n",
 
57
      DEV_MEM, strerror(errno));
 
58
  }
 
59
  base = mmap((caddr_t)0, Size, (flags & VIDMEM_READONLY) ?
 
60
             PROT_READ : (PROT_READ | PROT_WRITE),
 
61
             MAP_SHARED, fd, (off_t)Base);
 
62
  close(fd);
 
63
 
 
64
  if (base == MAP_FAILED) {
 
65
    FatalError("%s: Could not mmap framebuffer [s=%x,a=%x] (%s)\n",
 
66
      "xf86MapVidMem", Size, Base, strerror(errno));
 
67
  }
 
68
  return(base);
 
69
}
 
70
 
 
71
/* ARGSUSED */
 
72
static void
 
73
unmapVidMem(int ScreenNum, pointer Base, unsigned long Size)
 
74
{
 
75
  munmap(Base, Size);
 
76
}
 
77
 
 
78
/*
 
79
 * For some SVR4 versions, a 32-bit read is done for the first location
 
80
 * in each page when the page is first mapped.  If this is done while
 
81
 * memory access is enabled for regions that have read side-effects,
 
82
 * this can cause unexpected results, including lockups on some hardware.
 
83
 * This function is called to make sure each page is mapped while it is
 
84
 * safe to do so.
 
85
 */
 
86
 
 
87
#define X_PAGE_SIZE 4096
 
88
 
 
89
static void
 
90
readSideEffects(int ScreenNum, pointer Base, unsigned long Size)
 
91
{
 
92
  unsigned long base, end, addr;
 
93
  CARD32 val;
 
94
 
 
95
  base = (unsigned long)Base;
 
96
  end = base + Size;
 
97
 
 
98
  for (addr = base; addr < end; addr += X_PAGE_SIZE)
 
99
    val = *(volatile CARD32 *)addr;
 
100
}
 
101
 
 
102
void
 
103
xf86OSInitVidMem(VidMemInfoPtr pVidMem)
 
104
{
 
105
  pVidMem->linearSupported = linearVidMem();
 
106
  pVidMem->mapMem = mapVidMem;
 
107
  pVidMem->unmapMem = unmapVidMem;
 
108
  pVidMem->readSideEffects = readSideEffects;
 
109
  pVidMem->initialised = TRUE;
 
110
}
 
111