1
/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/os2/os2_ioperm.c,v 3.6 1999/04/29 09:13:49 dawes Exp $ */
3
* Copyright 1993 by David Wexelblat <dwex@goblin.org>
4
* Modified 1996 by Sebastien Marineau <marineau@genie.uottawa.ca>
6
* Permission to use, copy, modify, distribute, and sell this software and its
7
* documentation for any purpose is hereby granted without fee, provided that
8
* the above copyright notice appear in all copies and that both that
9
* copyright notice and this permission notice appear in supporting
10
* documentation, and that the name of David Wexelblat not be used in
11
* advertising or publicity pertaining to distribution of the software without
12
* specific, written prior permission. David Wexelblat makes no representations
13
* about the suitability of this software for any purpose. It is provided
14
* "as is" without express or implied warranty.
16
* DAVID WEXELBLAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18
* EVENT SHALL DAVID WEXELBLAT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
20
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
21
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22
* PERFORMANCE OF THIS SOFTWARE.
25
/* $XConsortium: os2_ioperm.c /main/4 1996/04/18 16:50:01 kaleb $ */
32
#define INCL_DOSFILEMGR
35
#include "xf86_OSlib.h"
38
* To access I/O ports under OS/2, we use the xf86sup.sys driver.
39
* For the moment, we use a function which basically grants IO priviledge
40
* to the whole server. NOTE: Once the server is running, we should
41
* change this to use inline IO functions through the callgate returned by
47
char *ioDrvPath = "/dev/fastio$";
48
USHORT callgate[3]={0,0,0};
58
/* no need to call multiple times */
59
if (ioEnabled) return;
61
if (DosOpen((PSZ)ioDrvPath, (PHFILE)&hfd, (PULONG)&action,
62
(ULONG)0, FILE_SYSTEM, FILE_OPEN,
63
OPEN_SHARE_DENYNONE|OPEN_FLAGS_NOINHERIT|OPEN_ACCESS_READONLY,
65
xf86Msg(X_ERROR,"Error opening fastio$ driver...\n");
66
xf86Msg(X_ERROR,"Please install xf86sup.sys in config.sys!\n");
69
callgate[0] = callgate[1] = 0;
71
/* Get callgate from driver for fast io to ports and other stuff */
73
rc = DosDevIOCtl(hfd, (ULONG)0x76, (ULONG)0x64,
75
(ULONG*)&callgate[2], sizeof(USHORT), &dlen);
78
"EnableIOPorts failed, rc=%d, dlen=%d; emergency exit\n",
84
/* Calling callgate with function 13 sets IOPL for the program */
86
asm volatile ("movl $13,%%ebx;.byte 0xff,0x1d;.long _callgate"
89
: "eax","ebx","ecx","edx","cc");
102
/* no need to call multiple times */
103
if (!ioEnabled) return;
105
if (DosOpen((PSZ)ioDrvPath, (PHFILE)&hfd, (PULONG)&action,
106
(ULONG)0, FILE_SYSTEM, FILE_OPEN,
107
OPEN_SHARE_DENYNONE|OPEN_FLAGS_NOINHERIT|OPEN_ACCESS_READONLY,
109
xf86Msg(X_ERROR,"Error opening fastio$ driver...\n");
110
xf86Msg(X_ERROR,"Please install xf86sup.sys in config.sys!\n");
113
callgate[0] = callgate[1] = 0;
115
rc = DosDevIOCtl(hfd, (ULONG)0x76, (ULONG)0x64,
117
(ULONG*)&callgate[2], sizeof(USHORT), &dlen);
119
xf86Msg(X_ERROR,"DisableIOPorts failed, rc=%d, dlen=%d\n",
125
/* Function 14 of callgate brings program back to ring 3 */
127
asm volatile ("movl $14,%%ebx;.byte 0xff,0x1d;.long _callgate"
130
: "eax","ebx","ecx","edx","cc");