source: trunk/minix/kernel/system/do_vdevio.c@ 9

Last change on this file since 9 was 9, checked in by Mattia Monga, 13 years ago

Minix 3.1.2a

File size: 3.6 KB
Line 
1/* The kernel call implemented in this file:
2 * m_type: SYS_VDEVIO
3 *
4 * The parameters for this kernel call are:
5 * m2_i3: DIO_REQUEST (request input or output)
6 * m2_i1: DIO_TYPE (flag indicating byte, word, or long)
7 * m2_p1: DIO_VEC_ADDR (pointer to port/ value pairs)
8 * m2_i2: DIO_VEC_SIZE (number of ports to read or write)
9 */
10
11#include "../system.h"
12#include <minix/devio.h>
13#include <minix/endpoint.h>
14
15#if USE_VDEVIO
16
17/* Buffer for SYS_VDEVIO to copy (port,value)-pairs from/ to user. */
18PRIVATE char vdevio_buf[VDEVIO_BUF_SIZE];
19PRIVATE pvb_pair_t *pvb = (pvb_pair_t *) vdevio_buf;
20PRIVATE pvw_pair_t *pvw = (pvw_pair_t *) vdevio_buf;
21PRIVATE pvl_pair_t *pvl = (pvl_pair_t *) vdevio_buf;
22
23/*===========================================================================*
24 * do_vdevio *
25 *===========================================================================*/
26PUBLIC int do_vdevio(m_ptr)
27register message *m_ptr; /* pointer to request message */
28{
29/* Perform a series of device I/O on behalf of a non-kernel process. The
30 * I/O addresses and I/O values are fetched from and returned to some buffer
31 * in user space. The actual I/O is wrapped by lock() and unlock() to prevent
32 * that I/O batch from being interrrupted.
33 * This is the counterpart of do_devio, which performs a single device I/O.
34 */
35 int vec_size; /* size of vector */
36 int io_in; /* true if input */
37 size_t bytes; /* # bytes to be copied */
38 vir_bytes caller_vir; /* virtual address at caller */
39 phys_bytes caller_phys; /* physical address at caller */
40 int i;
41
42 /* Get the request, size of the request vector, and check the values. */
43 if (m_ptr->DIO_REQUEST == DIO_INPUT) io_in = TRUE;
44 else if (m_ptr->DIO_REQUEST == DIO_OUTPUT) io_in = FALSE;
45 else return(EINVAL);
46 if ((vec_size = m_ptr->DIO_VEC_SIZE) <= 0) return(EINVAL);
47 switch (m_ptr->DIO_TYPE) {
48 case DIO_BYTE: bytes = vec_size * sizeof(pvb_pair_t); break;
49 case DIO_WORD: bytes = vec_size * sizeof(pvw_pair_t); break;
50 case DIO_LONG: bytes = vec_size * sizeof(pvl_pair_t); break;
51 default: return(EINVAL); /* check type once and for all */
52 }
53 if (bytes > sizeof(vdevio_buf)) return(E2BIG);
54
55 /* Calculate physical addresses and copy (port,value)-pairs from user. */
56 caller_vir = (vir_bytes) m_ptr->DIO_VEC_ADDR;
57 caller_phys = umap_local(proc_addr(who_p), D, caller_vir, bytes);
58 if (0 == caller_phys) return(EFAULT);
59 phys_copy(caller_phys, vir2phys(vdevio_buf), (phys_bytes) bytes);
60
61 /* Perform actual device I/O for byte, word, and long values. Note that
62 * the entire switch is wrapped in lock() and unlock() to prevent the I/O
63 * batch from being interrupted.
64 */
65 lock(13, "do_vdevio");
66 switch (m_ptr->DIO_TYPE) {
67 case DIO_BYTE: /* byte values */
68 if (io_in) for (i=0; i<vec_size; i++) pvb[i].value = inb(pvb[i].port);
69 else for (i=0; i<vec_size; i++) outb(pvb[i].port, pvb[i].value);
70 break;
71 case DIO_WORD: /* word values */
72 if (io_in) for (i=0; i<vec_size; i++) pvw[i].value = inw(pvw[i].port);
73 else for (i=0; i<vec_size; i++) outw(pvw[i].port, pvw[i].value);
74 break;
75 default: /* long values */
76 if (io_in) for (i=0; i<vec_size; i++) pvl[i].value = inl(pvl[i].port);
77 else for (i=0; i<vec_size; i++) outl(pvb[i].port, pvl[i].value);
78 }
79 unlock(13);
80
81 /* Almost done, copy back results for input requests. */
82 if (io_in) phys_copy(vir2phys(vdevio_buf), caller_phys, (phys_bytes) bytes);
83 return(OK);
84}
85
86#endif /* USE_VDEVIO */
87
Note: See TracBrowser for help on using the repository browser.