Imported Upstream version 1.15.1
[deb_xorg-server.git] / hw / xfree86 / os-support / hurd / hurd_video.c
CommitLineData
a09e091a
JB
1/*
2 * Copyright 1997, 1998 by UCHIYAMA Yasushi
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 UCHIYAMA Yasushi not be used in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific, written prior permission. UCHIYAMA Yasushi 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 * UCHIYAMA YASUSHI DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL UCHIYAMA YASUSHI 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 <mach.h>
29#include <device/device.h>
30#include <mach/machine/mach_i386.h>
31#include <hurd.h>
32
33#include <X11/X.h>
34#include "input.h"
35#include "scrnintstr.h"
36
37#include "xf86.h"
38#include "xf86Priv.h"
39#include "xf86_OSlib.h"
40#include "xf86OSpriv.h"
41
42/**************************************************************************
43 * Video Memory Mapping section
44 ***************************************************************************/
45static pointer
46mapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int Flags)
47{
48 mach_port_t device, mem_dev;
49 memory_object_t mem_obj;
50 kern_return_t err;
51 vm_address_t addr = (vm_address_t) 0;
52
53 err = get_privileged_ports(NULL, &device);
54 if (err) {
55 errno = err;
56 FatalError("xf86MapVidMem() can't get_privileged_ports. (%s)\n",
57 strerror(errno));
58 }
59 err = device_open(device, D_READ | D_WRITE, "mem", &mem_dev);
60 mach_port_deallocate(mach_task_self(), device);
61 if (err) {
62 errno = err;
63 FatalError("xf86MapVidMem() can't device_open. (%s)\n",
64 strerror(errno));
65 }
66
67 err =
68 device_map(mem_dev, VM_PROT_READ | VM_PROT_WRITE, Base, Size, &mem_obj,
69 0);
70 if (err) {
71 errno = err;
72 FatalError("xf86MapVidMem() can't device_map. (%s)\n", strerror(errno));
73 }
74 err = vm_map(mach_task_self(), &addr, Size, 0, /* mask */
75 TRUE, /* anywhere */
76 mem_obj, (vm_offset_t) Base, FALSE, /* copy on write */
77 VM_PROT_READ | VM_PROT_WRITE,
78 VM_PROT_READ | VM_PROT_WRITE, VM_INHERIT_SHARE);
79 mach_port_deallocate(mach_task_self(), mem_obj);
80 if (err) {
81 errno = err;
82 FatalError("xf86MapVidMem() can't vm_map.(mem_obj) (%s)\n",
83 strerror(errno));
84 }
85 mach_port_deallocate(mach_task_self(), mem_dev);
86 if (err) {
87 errno = err;
88 FatalError
89 ("xf86MapVidMem() can't mach_port_deallocate.(mem_dev) (%s)\n",
90 strerror(errno));
91 }
92 return (pointer) addr;
93}
94
95static void
96unmapVidMem(int ScreenNum, pointer Base, unsigned long Size)
97{
98 kern_return_t err = vm_deallocate(mach_task_self(), (int) Base, Size);
99
100 if (err) {
101 errno = err;
102 ErrorF("xf86UnMapVidMem: can't dealloc framebuffer space (%s)\n",
103 strerror(errno));
104 }
105 return;
106}
107
108/**************************************************************************
109 * I/O Permissions section
110 ***************************************************************************/
111
112/*
113 * Due to conflicts with "compiler.h", don't rely on <sys/io.h> to declare
114 * this.
115 */
116extern int ioperm(unsigned long __from, unsigned long __num, int __turn_on);
117
118Bool
119xf86EnableIO()
120{
121 if (ioperm(0, 0x10000, 1)) {
122 FatalError("xf86EnableIO: ioperm() failed (%s)\n", strerror(errno));
123 return FALSE;
124 }
125#if 0
126 /*
127 * Trapping disabled for now, as some VBIOSes (mga-g450 notably) use these
128 * ports, and the int10 wrapper is not emulating them. (Note that it's
129 * effectively what happens in the Linux variant too, as iopl() is used
130 * there, making the ioperm() meaningless.)
131 *
132 * Reenable this when int10 gets fixed. */
133 ioperm(0x40, 4, 0); /* trap access to the timer chip */
134 ioperm(0x60, 4, 0); /* trap access to the keyboard controller */
135#endif
136 return TRUE;
137}
138
139void
140xf86DisableIO()
141{
142 ioperm(0, 0x10000, 0);
143 return;
144}
145
146void
147xf86OSInitVidMem(VidMemInfoPtr pVidMem)
148{
149 pVidMem->linearSupported = TRUE;
150 pVidMem->mapMem = mapVidMem;
151 pVidMem->unmapMem = unmapVidMem;
152 pVidMem->initialised = TRUE;
153}