do_vdevio.c

Go to the documentation of this file.
00001 /* The kernel call implemented in this file:
00002  *   m_type:    SYS_VDEVIO
00003  *
00004  * The parameters for this kernel call are:
00005  *    m2_i3:    DIO_REQUEST     (request input or output)       
00006  *    m2_i1:    DIO_TYPE        (flag indicating byte, word, or long)
00007  *    m2_p1:    DIO_VEC_ADDR    (pointer to port/ value pairs)  
00008  *    m2_i2:    DIO_VEC_SIZE    (number of ports to read or write) 
00009  */
00010 
00011 #include "../system.h"
00012 #include <minix/devio.h>
00013 #include <minix/endpoint.h>
00014 
00015 #if USE_VDEVIO
00016 
00017 /* Buffer for SYS_VDEVIO to copy (port,value)-pairs from/ to user. */
00018 PRIVATE char vdevio_buf[VDEVIO_BUF_SIZE];      
00019 PRIVATE pvb_pair_t *pvb = (pvb_pair_t *) vdevio_buf;           
00020 PRIVATE pvw_pair_t *pvw = (pvw_pair_t *) vdevio_buf;      
00021 PRIVATE pvl_pair_t *pvl = (pvl_pair_t *) vdevio_buf;     
00022 
00023 /*===========================================================================*
00024  *                              do_vdevio                                    *
00025  *===========================================================================*/
00026 PUBLIC int do_vdevio(m_ptr)
00027 register message *m_ptr;        /* pointer to request message */
00028 {
00029 /* Perform a series of device I/O on behalf of a non-kernel process. The 
00030  * I/O addresses and I/O values are fetched from and returned to some buffer
00031  * in user space. The actual I/O is wrapped by lock() and unlock() to prevent
00032  * that I/O batch from being interrrupted.
00033  * This is the counterpart of do_devio, which performs a single device I/O. 
00034  */ 
00035   int vec_size;               /* size of vector */
00036   int io_in;                  /* true if input */
00037   size_t bytes;               /* # bytes to be copied */
00038   vir_bytes caller_vir;       /* virtual address at caller */
00039   phys_bytes caller_phys;     /* physical address at caller */
00040   int i;
00041     
00042   /* Get the request, size of the request vector, and check the values. */
00043   if (m_ptr->DIO_REQUEST == DIO_INPUT) io_in = TRUE;
00044   else if (m_ptr->DIO_REQUEST == DIO_OUTPUT) io_in = FALSE;
00045   else return(EINVAL);
00046   if ((vec_size = m_ptr->DIO_VEC_SIZE) <= 0) return(EINVAL);
00047   switch (m_ptr->DIO_TYPE) {
00048       case DIO_BYTE: bytes = vec_size * sizeof(pvb_pair_t); break;
00049       case DIO_WORD: bytes = vec_size * sizeof(pvw_pair_t); break;
00050       case DIO_LONG: bytes = vec_size * sizeof(pvl_pair_t); break;
00051       default:  return(EINVAL);   /* check type once and for all */
00052   }
00053   if (bytes > sizeof(vdevio_buf))  return(E2BIG);
00054 
00055   /* Calculate physical addresses and copy (port,value)-pairs from user. */
00056   caller_vir = (vir_bytes) m_ptr->DIO_VEC_ADDR;
00057   caller_phys = umap_local(proc_addr(who_p), D, caller_vir, bytes);
00058   if (0 == caller_phys) return(EFAULT);
00059   phys_copy(caller_phys, vir2phys(vdevio_buf), (phys_bytes) bytes);
00060 
00061   /* Perform actual device I/O for byte, word, and long values. Note that 
00062    * the entire switch is wrapped in lock() and unlock() to prevent the I/O
00063    * batch from being interrupted. 
00064    */  
00065   lock(13, "do_vdevio");
00066   switch (m_ptr->DIO_TYPE) {
00067   case DIO_BYTE:                                         /* byte values */
00068       if (io_in) for (i=0; i<vec_size; i++)  pvb[i].value = inb(pvb[i].port); 
00069       else       for (i=0; i<vec_size; i++)  outb(pvb[i].port, pvb[i].value); 
00070       break; 
00071   case DIO_WORD:                                          /* word values */
00072       if (io_in) for (i=0; i<vec_size; i++)  pvw[i].value = inw(pvw[i].port);  
00073       else       for (i=0; i<vec_size; i++)  outw(pvw[i].port, pvw[i].value); 
00074       break; 
00075   default:                                                /* long values */
00076       if (io_in) for (i=0; i<vec_size; i++) pvl[i].value = inl(pvl[i].port);  
00077       else       for (i=0; i<vec_size; i++) outl(pvb[i].port, pvl[i].value); 
00078   }
00079   unlock(13);
00080     
00081   /* Almost done, copy back results for input requests. */
00082   if (io_in) phys_copy(vir2phys(vdevio_buf), caller_phys, (phys_bytes) bytes);
00083   return(OK);
00084 }
00085 
00086 #endif /* USE_VDEVIO */
00087 

Generated on Fri Apr 14 22:57:24 2006 for minix by  doxygen 1.4.6