2 * Copyright 1997, 1998 by UCHIYAMA Yasushi
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.
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.
24 #ifdef HAVE_XORG_CONFIG_H
25 #include <xorg-config.h>
29 #include <device/device.h>
30 #include <mach/machine/mach_i386.h>
35 #include "scrnintstr.h"
39 #include "xf86_OSlib.h"
40 #include "xf86OSpriv.h"
42 /**************************************************************************
43 * Video Memory Mapping section
44 ***************************************************************************/
46 mapVidMem(int ScreenNum
, unsigned long Base
, unsigned long Size
, int Flags
)
48 mach_port_t device
, mem_dev
;
49 memory_object_t mem_obj
;
51 vm_address_t addr
= (vm_address_t
) 0;
53 err
= get_privileged_ports(NULL
, &device
);
56 FatalError("xf86MapVidMem() can't get_privileged_ports. (%s)\n",
59 err
= device_open(device
, D_READ
| D_WRITE
, "mem", &mem_dev
);
60 mach_port_deallocate(mach_task_self(), device
);
63 FatalError("xf86MapVidMem() can't device_open. (%s)\n",
68 device_map(mem_dev
, VM_PROT_READ
| VM_PROT_WRITE
, Base
, Size
, &mem_obj
,
72 FatalError("xf86MapVidMem() can't device_map. (%s)\n", strerror(errno
));
74 err
= vm_map(mach_task_self(), &addr
, Size
, 0, /* mask */
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
);
82 FatalError("xf86MapVidMem() can't vm_map.(mem_obj) (%s)\n",
85 mach_port_deallocate(mach_task_self(), mem_dev
);
89 ("xf86MapVidMem() can't mach_port_deallocate.(mem_dev) (%s)\n",
92 return (pointer
) addr
;
96 unmapVidMem(int ScreenNum
, pointer Base
, unsigned long Size
)
98 kern_return_t err
= vm_deallocate(mach_task_self(), (int) Base
, Size
);
102 ErrorF("xf86UnMapVidMem: can't dealloc framebuffer space (%s)\n",
108 /**************************************************************************
109 * I/O Permissions section
110 ***************************************************************************/
113 * Due to conflicts with "compiler.h", don't rely on <sys/io.h> to declare
116 extern int ioperm(unsigned long __from
, unsigned long __num
, int __turn_on
);
121 if (ioperm(0, 0x10000, 1)) {
122 FatalError("xf86EnableIO: ioperm() failed (%s)\n", strerror(errno
));
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.)
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 */
142 ioperm(0, 0x10000, 0);
147 xf86OSInitVidMem(VidMemInfoPtr pVidMem
)
149 pVidMem
->linearSupported
= TRUE
;
150 pVidMem
->mapMem
= mapVidMem
;
151 pVidMem
->unmapMem
= unmapVidMem
;
152 pVidMem
->initialised
= TRUE
;