kernel: kill proc with bogus ipc address
[minix.git] / kernel / system / do_devio.c
blob722e6c100bd33664c579554fba8a421d8135bdcc
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 "kernel/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 int do_devio(struct proc * caller, message * m_ptr)
22 struct priv *privp;
23 port_t port;
24 struct io_range *iorp;
25 int i, size, nr_io_range;
26 int io_type, io_dir;
28 io_type = m_ptr->DIO_REQUEST & _DIO_TYPEMASK;
29 io_dir = m_ptr->DIO_REQUEST & _DIO_DIRMASK;
31 switch (io_type)
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 */
39 privp= priv(caller);
40 if (!privp)
42 printf("no priv structure!\n");
43 goto doit;
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)
52 break;
54 if (i >= nr_io_range)
56 printf("do_devio: port 0x%x (size %d) not allowed\n",
57 m_ptr->DIO_PORT, size);
58 return EPERM;
62 doit:
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);
67 return EPERM;
70 /* Process a single I/O request for byte, word, and long values. */
71 if (io_dir == _DIO_INPUT) {
72 switch (io_type) {
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);
79 } else {
80 switch (io_type) {
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);
87 return(OK);
90 #endif /* USE_DEVIO */