replace library time handling functions
[minix3.git] / kernel / system / do_devio.c
blob810b5a9d01461f027613a33aebb792d4e4585e41
1 /* The kernel call implemented in this file:
2 * m_type: SYS_DEVIO
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)
8 */
10 #include "../system.h"
11 #include <minix/devio.h>
12 #include <minix/endpoint.h>
13 #include <minix/portio.h>
15 #if USE_DEVIO
17 /*===========================================================================*
18 * do_devio *
19 *===========================================================================*/
20 PUBLIC int do_devio(m_ptr)
21 register message *m_ptr; /* pointer to request message */
23 struct proc *rp;
24 struct priv *privp;
25 port_t port;
26 struct io_range *iorp;
27 int i, size, nr_io_range;
28 int io_type, io_dir;
30 io_type = m_ptr->DIO_REQUEST & _DIO_TYPEMASK;
31 io_dir = m_ptr->DIO_REQUEST & _DIO_DIRMASK;
33 rp= proc_addr(who_p);
34 privp= priv(rp);
35 if (!privp)
37 kprintf("no priv structure!\n");
38 goto doit;
40 if (privp->s_flags & CHECK_IO_PORT)
42 switch (io_type)
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)
54 break;
56 if (i >= nr_io_range)
58 kprintf(
59 "do_devio: I/O port check failed for proc %d, port 0x%x\n",
60 m_ptr->m_source, port);
61 return EPERM;
65 doit:
67 /* Process a single I/O request for byte, word, and long values. */
68 if (io_dir == _DIO_INPUT) {
69 switch (io_type) {
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);
76 } else {
77 switch (io_type) {
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);
84 return(OK);
87 #endif /* USE_DEVIO */