1 /* The kernel call implemented in this file:
4 * The parameters for this kernel call are:
5 * m_lsys_krn_sys_devio.request (request input or output)
6 * m_lsys_krn_sys_devio.port (port to read/ write)
7 * m_lsys_krn_sys_devio.value (value to write/ return value read)
10 #include "kernel/system.h"
11 #include <minix/devio.h>
12 #include <minix/endpoint.h>
16 /*===========================================================================*
18 *===========================================================================*/
19 int do_devio(struct proc
* caller
, message
* m_ptr
)
23 struct io_range
*iorp
;
24 int i
, size
, nr_io_range
;
27 io_type
= m_ptr
->m_lsys_krn_sys_devio
.request
& _DIO_TYPEMASK
;
28 io_dir
= m_ptr
->m_lsys_krn_sys_devio
.request
& _DIO_DIRMASK
;
32 case _DIO_BYTE
: size
= 1; break;
33 case _DIO_WORD
: size
= 2; break;
34 case _DIO_LONG
: size
= 4; break;
35 default: size
= 4; break; /* Be conservative */
41 printf("no priv structure!\n");
44 if (privp
->s_flags
& CHECK_IO_PORT
)
46 port
= m_ptr
->m_lsys_krn_sys_devio
.port
;
47 nr_io_range
= privp
->s_nr_io_range
;
48 for (i
= 0, iorp
= privp
->s_io_tab
; i
<nr_io_range
; i
++, iorp
++)
50 if (port
>= iorp
->ior_base
&& port
+size
-1 <= iorp
->ior_limit
)
55 printf("do_devio: port 0x%x (size %d) not allowed\n",
56 m_ptr
->m_lsys_krn_sys_devio
.port
, size
);
62 if (m_ptr
->m_lsys_krn_sys_devio
.port
& (size
-1))
64 printf("do_devio: unaligned port 0x%x (size %d)\n",
65 m_ptr
->m_lsys_krn_sys_devio
.port
, size
);
69 /* Process a single I/O request for byte, word, and long values. */
70 if (io_dir
== _DIO_INPUT
) {
72 /* maybe "it" should not be called ports */
74 m_ptr
->m_krn_lsys_sys_devio
.value
=
75 inb(m_ptr
->m_lsys_krn_sys_devio
.port
);
78 m_ptr
->m_krn_lsys_sys_devio
.value
=
79 inw(m_ptr
->m_lsys_krn_sys_devio
.port
);
82 m_ptr
->m_krn_lsys_sys_devio
.value
=
83 inl(m_ptr
->m_lsys_krn_sys_devio
.port
);
85 default: return(EINVAL
);
90 outb(m_ptr
->m_lsys_krn_sys_devio
.port
,
91 m_ptr
->m_lsys_krn_sys_devio
.value
);
94 outw(m_ptr
->m_lsys_krn_sys_devio
.port
,
95 m_ptr
->m_lsys_krn_sys_devio
.value
);
98 outl(m_ptr
->m_lsys_krn_sys_devio
.port
,
99 m_ptr
->m_lsys_krn_sys_devio
.value
);
101 default: return(EINVAL
);
107 #endif /* USE_DEVIO */