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 "../system.h"
11 #include <minix/devio.h>
12 #include <minix/endpoint.h>
13 #include <minix/portio.h>
17 /*===========================================================================*
19 *===========================================================================*/
20 PUBLIC
int do_devio(m_ptr
)
21 register message
*m_ptr
; /* pointer to request message */
26 struct io_range
*iorp
;
27 int i
, size
, nr_io_range
;
30 io_type
= m_ptr
->DIO_REQUEST
& _DIO_TYPEMASK
;
31 io_dir
= m_ptr
->DIO_REQUEST
& _DIO_DIRMASK
;
37 kprintf("no priv structure!\n");
40 if (privp
->s_flags
& CHECK_IO_PORT
)
44 case _DIO_BYTE
: size
= 1; break;
45 case _DIO_WORD
: size
= 2; break;
46 case _DIO_LONG
: size
= 4; break;
47 default: size
= 4; break; /* Be conservative */
49 port
= m_ptr
->DIO_PORT
;
50 nr_io_range
= privp
->s_nr_io_range
;
51 for (i
= 0, iorp
= privp
->s_io_tab
; i
<nr_io_range
; i
++, iorp
++)
53 if (port
>= iorp
->ior_base
&& port
+size
-1 <= iorp
->ior_limit
)
59 "do_devio: I/O port check failed for proc %d, port 0x%x\n",
60 m_ptr
->m_source
, port
);
67 /* Process a single I/O request for byte, word, and long values. */
68 if (io_dir
== _DIO_INPUT
) {
70 /* maybe "it" should not be called ports */
71 case _DIO_BYTE
: m_ptr
->DIO_VALUE
= inb(m_ptr
->DIO_PORT
); break;
72 case _DIO_WORD
: m_ptr
->DIO_VALUE
= inw(m_ptr
->DIO_PORT
); break;
73 case _DIO_LONG
: m_ptr
->DIO_VALUE
= inl(m_ptr
->DIO_PORT
); break;
74 default: return(EINVAL
);
78 case _DIO_BYTE
: outb(m_ptr
->DIO_PORT
, m_ptr
->DIO_VALUE
); break;
79 case _DIO_WORD
: outw(m_ptr
->DIO_PORT
, m_ptr
->DIO_VALUE
); break;
80 case _DIO_LONG
: outl(m_ptr
->DIO_PORT
, m_ptr
->DIO_VALUE
); break;
81 default: return(EINVAL
);
87 #endif /* USE_DEVIO */