Imported Upstream version 1.15.1
[deb_xorg-server.git] / hw / xfree86 / os-support / hurd / hurd_mmap.c
CommitLineData
a09e091a
JB
1/*
2 * Copyright 1997 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#ifdef HAVE_XORG_CONFIG_H
24#include <xorg-config.h>
25#endif
26
27#include<mach.h>
28#include<device/device.h>
29#include<mach/machine/mach_i386.h>
30#include <hurd.h>
31
32#include <X11/X.h>
33
34#include "xf86.h"
35#include "xf86Priv.h"
36#include "xf86_OSlib.h"
37
38#define BIOS_SIZE 0x20000
39
40int
41xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf,
42 int Len)
43{
44 mach_port_t device, mem_dev;
45 memory_object_t mem_obj;
46 vm_address_t addr = (vm_address_t) 0; /* serach starting address */
47 kern_return_t err;
48
49 err = get_privileged_ports(NULL, &device);
50 if (err) {
51 errno = err;
52 FatalError("xf86ReadBIOS() can't get_privileged_ports. (%s)\n",
53 strerror(errno));
54 }
55 err = device_open(device, D_READ | D_WRITE, "mem", &mem_dev);
56 mach_port_deallocate(mach_task_self(), device);
57 if (err) {
58 errno = err;
59 FatalError("xf86ReadBIOS() can't device_open. (%s)\n", strerror(errno));
60 }
61 err =
62 device_map(mem_dev, VM_PROT_READ | VM_PROT_WRITE, Base, BIOS_SIZE,
63 &mem_obj, 0);
64 if (err) {
65 errno = err;
66 FatalError("xf86ReadBIOS() can't device_map. (%s)\n", strerror(errno));
67 }
68 err = vm_map(mach_task_self(),
69 &addr,
70 BIOS_SIZE,
71 0,
72 TRUE,
73 mem_obj,
74 Base,
75 FALSE,
76 VM_PROT_READ | VM_PROT_WRITE,
77 VM_PROT_READ | VM_PROT_WRITE, VM_INHERIT_SHARE);
78 mach_port_deallocate(mach_task_self(), mem_obj);
79 if (err) {
80 errno = err;
81 FatalError("xf86ReadBIOS() can't vm_map. (%s)\n", strerror(errno));
82 }
83
84 memcpy(Buf, (void *) ((int) addr + Offset), Len);
85
86 err = vm_deallocate(mach_task_self(), addr, BIOS_SIZE);
87 if (err) {
88 errno = err;
89 FatalError("xf86ReadBIOS() can't vm_deallocate. (%s)\n",
90 strerror(errno));
91 }
92
93 return Len;
94}