First import
[xorg_rtime.git] / xorg-server-1.4 / hw / xfree86 / os-support / shared / bios_devmem.c
blob7288239be69b98e1f1483486ebaf324f219a2018
1 /*
2 * Copyright 1993 by David Wexelblat <dwex@goblin.org>
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 David Wexelblat not be used in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific, written prior permission. David Wexelblat 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 * DAVID WEXELBLAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL DAVID WEXELBLAT 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>
26 #endif
28 #include <X11/X.h>
29 #include "xf86.h"
30 #include "xf86Priv.h"
31 #include "xf86_OSlib.h"
32 #include <string.h>
35 * Read BIOS via /dev/mem.
38 #ifndef DEV_MEM
39 # define DEV_MEM "/dev/mem"
40 #endif
42 _X_EXPORT int
43 xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf,
44 int Len)
46 int fd;
48 #ifdef __ia64__
49 if ((fd = open(DEV_MEM, O_RDONLY | O_SYNC)) < 0)
50 #else
51 if ((fd = open(DEV_MEM, O_RDONLY)) < 0)
52 #endif
54 xf86Msg(X_WARNING, "xf86ReadBIOS: Failed to open %s (%s)\n",
55 DEV_MEM, strerror(errno));
56 return(-1);
59 if (lseek(fd, (Base+Offset), SEEK_SET) < 0)
61 xf86Msg(X_WARNING, "xf86ReadBIOS: %s seek failed (%s)\n",
62 DEV_MEM, strerror(errno));
63 close(fd);
64 return(-1);
66 if (read(fd, Buf, Len) != Len)
68 xf86Msg(X_WARNING, "xf86ReadBIOS: %s read failed (%s)\n",
69 DEV_MEM, strerror(errno));
70 close(fd);
71 return(-1);
73 close(fd);
74 return(Len);