1 /* The kernel call implemented in this file:
4 * The parameters for this kernel call are:
5 * m2_i3: DIO_REQUEST (request input or output)
6 * m2_l1: DIO_PORT (port to read/ write)
7 * m2_l2: DIO_VALUE (value to write/ return value read)
10 #include "kernel/system.h"
11 #include <minix/devio.h>
12 #include <minix/endpoint.h>
13 #include <minix/portio.h>
17 /*===========================================================================*
19 *===========================================================================*/
20 int do_devio(struct proc
* caller
, message
* m_ptr
)
24 struct io_range
*iorp
;
25 int i
, size
, nr_io_range
;
28 io_type
= m_ptr
->DIO_REQUEST
& _DIO_TYPEMASK
;
29 io_dir
= m_ptr
->DIO_REQUEST
& _DIO_DIRMASK
;
33 case _DIO_BYTE
: size
= 1; break;
34 case _DIO_WORD
: size
= 2; break;
35 case _DIO_LONG
: size
= 4; break;
36 default: size
= 4; break; /* Be conservative */
42 printf("no priv structure!\n");
45 if (privp
->s_flags
& CHECK_IO_PORT
)
47 port
= m_ptr
->DIO_PORT
;
48 nr_io_range
= privp
->s_nr_io_range
;
49 for (i
= 0, iorp
= privp
->s_io_tab
; i
<nr_io_range
; i
++, iorp
++)
51 if (port
>= iorp
->ior_base
&& port
+size
-1 <= iorp
->ior_limit
)
56 printf("do_devio: port 0x%x (size %d) not allowed\n",
57 m_ptr
->DIO_PORT
, size
);
63 if (m_ptr
->DIO_PORT
& (size
-1))
65 printf("do_devio: unaligned port 0x%x (size %d)\n",
66 m_ptr
->DIO_PORT
, size
);
70 /* Process a single I/O request for byte, word, and long values. */
71 if (io_dir
== _DIO_INPUT
) {
73 /* maybe "it" should not be called ports */
74 case _DIO_BYTE
: m_ptr
->DIO_VALUE
= inb(m_ptr
->DIO_PORT
); break;
75 case _DIO_WORD
: m_ptr
->DIO_VALUE
= inw(m_ptr
->DIO_PORT
); break;
76 case _DIO_LONG
: m_ptr
->DIO_VALUE
= inl(m_ptr
->DIO_PORT
); break;
77 default: return(EINVAL
);
81 case _DIO_BYTE
: outb(m_ptr
->DIO_PORT
, m_ptr
->DIO_VALUE
); break;
82 case _DIO_WORD
: outw(m_ptr
->DIO_PORT
, m_ptr
->DIO_VALUE
); break;
83 case _DIO_LONG
: outl(m_ptr
->DIO_PORT
, m_ptr
->DIO_VALUE
); break;
84 default: return(EINVAL
);
90 #endif /* USE_DEVIO */