. made libdriver understand *_S variants

. ioctl, transfer and 'other' functions get an extra parameter: 'safe', int
  is nonzero if function is called with *_S variant ('other' if ioctl)
This commit is contained in:
Ben Gras 2006-06-20 08:49:51 +00:00
parent 9be69be836
commit e929676268
3 changed files with 90 additions and 39 deletions

View file

@ -28,6 +28,8 @@
* | CANCEL | device | proc nr | r/w | | | * | CANCEL | device | proc nr | r/w | | |
* |------------+---------+---------+---------+---------+---------| * |------------+---------+---------+---------+---------+---------|
* | HARD_STOP | | | | | | * | HARD_STOP | | | | | |
* |------------+---------+---------+---------+---------+---------|
* | DEV_*_S | variants using safecopies of above |
* ---------------------------------------------------------------- * ----------------------------------------------------------------
* *
* The file contains one entry point: * The file contains one entry point:
@ -62,8 +64,8 @@ phys_bytes tmp_phys; /* phys address of DMA buffer */
#endif /* CHIP != INTEL */ #endif /* CHIP != INTEL */
FORWARD _PROTOTYPE( void init_buffer, (void) ); FORWARD _PROTOTYPE( void init_buffer, (void) );
FORWARD _PROTOTYPE( int do_rdwt, (struct driver *dr, message *mp) ); FORWARD _PROTOTYPE( int do_rdwt, (struct driver *dr, message *mp, int safe) );
FORWARD _PROTOTYPE( int do_vrdwt, (struct driver *dr, message *mp) ); FORWARD _PROTOTYPE( int do_vrdwt, (struct driver *dr, message *mp, int safe) );
int device_caller; int device_caller;
@ -96,13 +98,18 @@ struct driver *dp; /* Device dependent entry points. */
switch(mess.m_type) { switch(mess.m_type) {
case DEV_OPEN: r = (*dp->dr_open)(dp, &mess); break; case DEV_OPEN: r = (*dp->dr_open)(dp, &mess); break;
case DEV_CLOSE: r = (*dp->dr_close)(dp, &mess); break; case DEV_CLOSE: r = (*dp->dr_close)(dp, &mess); break;
case DEV_IOCTL: r = (*dp->dr_ioctl)(dp, &mess); break; case DEV_IOCTL: r = (*dp->dr_ioctl)(dp, &mess, 0); break;
case DEV_IOCTL_S: r = (*dp->dr_ioctl)(dp, &mess, 1); break;
case CANCEL: r = (*dp->dr_cancel)(dp, &mess);break; case CANCEL: r = (*dp->dr_cancel)(dp, &mess);break;
case DEV_SELECT: r = (*dp->dr_select)(dp, &mess);break; case DEV_SELECT: r = (*dp->dr_select)(dp, &mess);break;
case DEV_READ: case DEV_READ:
case DEV_WRITE: r = do_rdwt(dp, &mess); break; case DEV_WRITE: r = do_rdwt(dp, &mess, 0); break;
case DEV_READ_S:
case DEV_WRITE_S: r = do_rdwt(dp, &mess, 1); break;
case DEV_GATHER: case DEV_GATHER:
case DEV_SCATTER: r = do_vrdwt(dp, &mess); break; case DEV_SCATTER: r = do_vrdwt(dp, &mess, 0); break;
case DEV_GATHER_S:
case DEV_SCATTER_S: r = do_vrdwt(dp, &mess, 1); break;
case HARD_INT: /* leftover interrupt or expired timer. */ case HARD_INT: /* leftover interrupt or expired timer. */
if(dp->dr_hw_int) { if(dp->dr_hw_int) {
@ -118,7 +125,7 @@ struct driver *dp; /* Device dependent entry points. */
continue; continue;
default: default:
if(dp->dr_other) if(dp->dr_other)
r = (*dp->dr_other)(dp, &mess); r = (*dp->dr_other)(dp, &mess, 0);
else else
r = EINVAL; r = EINVAL;
break; break;
@ -166,9 +173,10 @@ PRIVATE void init_buffer()
/*===========================================================================* /*===========================================================================*
* do_rdwt * * do_rdwt *
*===========================================================================*/ *===========================================================================*/
PRIVATE int do_rdwt(dp, mp) PRIVATE int do_rdwt(dp, mp, safe)
struct driver *dp; /* device dependent entry points */ struct driver *dp; /* device dependent entry points */
message *mp; /* pointer to read or write message */ message *mp; /* pointer to read or write message */
int safe; /* use safecopies? */
{ {
/* Carry out a single read or write request. */ /* Carry out a single read or write request. */
iovec_t iovec1; iovec_t iovec1;
@ -178,20 +186,24 @@ message *mp; /* pointer to read or write message */
/* Disk address? Address and length of the user buffer? */ /* Disk address? Address and length of the user buffer? */
if (mp->COUNT < 0) return(EINVAL); if (mp->COUNT < 0) return(EINVAL);
/* Check the user buffer. */ /* Check the user buffer (not relevant for safe copies). */
if(!safe) {
sys_umap(mp->IO_ENDPT, D, (vir_bytes) mp->ADDRESS, mp->COUNT, &phys_addr); sys_umap(mp->IO_ENDPT, D, (vir_bytes) mp->ADDRESS, mp->COUNT, &phys_addr);
if (phys_addr == 0) return(EFAULT); if (phys_addr == 0) return(EFAULT);
}
/* Prepare for I/O. */ /* Prepare for I/O. */
if ((*dp->dr_prepare)(mp->DEVICE) == NIL_DEV) return(ENXIO); if ((*dp->dr_prepare)(mp->DEVICE) == NIL_DEV) return(ENXIO);
/* Create a one element scatter/gather vector for the buffer. */ /* Create a one element scatter/gather vector for the buffer. */
opcode = mp->m_type == DEV_READ ? DEV_GATHER : DEV_SCATTER; if(mp->m_type == DEV_READ || mp->m_type == DEV_READ_S) opcode = DEV_GATHER;
else opcode = DEV_SCATTER;
iovec1.iov_addr = (vir_bytes) mp->ADDRESS; iovec1.iov_addr = (vir_bytes) mp->ADDRESS;
iovec1.iov_size = mp->COUNT; iovec1.iov_size = mp->COUNT;
/* Transfer bytes from/to the device. */ /* Transfer bytes from/to the device. */
r = (*dp->dr_transfer)(mp->IO_ENDPT, opcode, mp->POSITION, &iovec1, 1); r = (*dp->dr_transfer)(mp->IO_ENDPT, opcode, mp->POSITION, &iovec1, 1, safe);
/* Return the number of bytes transferred or an error code. */ /* Return the number of bytes transferred or an error code. */
return(r == OK ? (mp->COUNT - iovec1.iov_size) : r); return(r == OK ? (mp->COUNT - iovec1.iov_size) : r);
@ -200,9 +212,10 @@ message *mp; /* pointer to read or write message */
/*==========================================================================* /*==========================================================================*
* do_vrdwt * * do_vrdwt *
*==========================================================================*/ *==========================================================================*/
PRIVATE int do_vrdwt(dp, mp) PRIVATE int do_vrdwt(dp, mp, safe)
struct driver *dp; /* device dependent entry points */ struct driver *dp; /* device dependent entry points */
message *mp; /* pointer to read or write message */ message *mp; /* pointer to read or write message */
int safe; /* use safecopies? */
{ {
/* Carry out an device read or write to/from a vector of user addresses. /* Carry out an device read or write to/from a vector of user addresses.
* The "user addresses" are assumed to be safe, i.e. FS transferring to/from * The "user addresses" are assumed to be safe, i.e. FS transferring to/from
@ -212,24 +225,28 @@ message *mp; /* pointer to read or write message */
iovec_t *iov; iovec_t *iov;
phys_bytes iovec_size; phys_bytes iovec_size;
unsigned nr_req; unsigned nr_req;
int r; int r, j, opcode;
nr_req = mp->COUNT; /* Length of I/O vector */ nr_req = mp->COUNT; /* Length of I/O vector */
#if 0
if (mp->m_source < 0) {
/* Called by a task, no need to copy vector. */
iov = (iovec_t *) mp->ADDRESS;
} else
#endif
{ {
/* Copy the vector from the caller to kernel space. */ /* Copy the vector from the caller to kernel space. */
if (nr_req > NR_IOREQS) nr_req = NR_IOREQS; if (nr_req > NR_IOREQS) nr_req = NR_IOREQS;
iovec_size = (phys_bytes) (nr_req * sizeof(iovec[0])); iovec_size = (phys_bytes) (nr_req * sizeof(iovec[0]));
if(safe) {
if (OK != sys_safecopyfrom(mp->m_source, (vir_bytes) mp->IO_GRANT,
0, (vir_bytes) iovec, iovec_size, D)) {
panic((*dp->dr_name)(),"bad (safe) I/O vector by", mp->m_source);
}
} else {
if (OK != sys_datacopy(mp->m_source, (vir_bytes) mp->ADDRESS, if (OK != sys_datacopy(mp->m_source, (vir_bytes) mp->ADDRESS,
SELF, (vir_bytes) iovec, iovec_size)) SELF, (vir_bytes) iovec, iovec_size)) {
panic((*dp->dr_name)(),"bad I/O vector by", mp->m_source); panic((*dp->dr_name)(),"bad I/O vector by", mp->m_source);
}
}
iov = iovec; iov = iovec;
} }
@ -237,14 +254,23 @@ message *mp; /* pointer to read or write message */
if ((*dp->dr_prepare)(mp->DEVICE) == NIL_DEV) return(ENXIO); if ((*dp->dr_prepare)(mp->DEVICE) == NIL_DEV) return(ENXIO);
/* Transfer bytes from/to the device. */ /* Transfer bytes from/to the device. */
r = (*dp->dr_transfer)(mp->IO_ENDPT, mp->m_type, mp->POSITION, iov, nr_req); opcode = mp->m_type;
if(opcode == DEV_GATHER_S) opcode = DEV_GATHER;
if(opcode == DEV_SCATTER_S) opcode = DEV_SCATTER;
r = (*dp->dr_transfer)(mp->IO_ENDPT, opcode, mp->POSITION, iov,
nr_req, safe);
/* Copy the I/O vector back to the caller. */ /* Copy the I/O vector back to the caller. */
#if 0 if(safe) {
if (mp->m_source >= 0) { if (OK != sys_safecopyto(mp->m_source, (vir_bytes) mp->IO_GRANT,
#endif 0, (vir_bytes) iovec, iovec_size, D)) {
panic((*dp->dr_name)(),"couldn't return I/O vector", mp->m_source);
}
} else {
sys_datacopy(SELF, (vir_bytes) iovec, sys_datacopy(SELF, (vir_bytes) iovec,
mp->m_source, (vir_bytes) mp->ADDRESS, iovec_size); mp->m_source, (vir_bytes) mp->ADDRESS, iovec_size);
}
return(r); return(r);
} }
@ -276,10 +302,21 @@ message *mp;
case DEV_OPEN: return(ENODEV); case DEV_OPEN: return(ENODEV);
case DEV_CLOSE: return(OK); case DEV_CLOSE: return(OK);
case DEV_IOCTL: return(ENOTTY); case DEV_IOCTL: return(ENOTTY);
default: return(EIO); default: printf("nop: ignoring code %d\n", mp->m_type); return(EIO);
} }
} }
/*============================================================================*
* nop_ioctl *
*============================================================================*/
PUBLIC int nop_ioctl(dp, mp, safe)
struct driver *dp;
message *mp;
int safe;
{
return(ENOTTY);
}
/*============================================================================* /*============================================================================*
* nop_signal * * nop_signal *
*============================================================================*/ *============================================================================*/
@ -338,9 +375,10 @@ PUBLIC int nop_select(struct driver *dr, message *m)
/*============================================================================* /*============================================================================*
* do_diocntl * * do_diocntl *
*============================================================================*/ *============================================================================*/
PUBLIC int do_diocntl(dp, mp) PUBLIC int do_diocntl(dp, mp, safe)
struct driver *dp; struct driver *dp;
message *mp; /* pointer to ioctl request */ message *mp; /* pointer to ioctl request */
int safe; /* addresses or grants? */
{ {
/* Carry out a partition setting/getting request. */ /* Carry out a partition setting/getting request. */
struct device *dv; struct device *dv;
@ -349,7 +387,7 @@ message *mp; /* pointer to ioctl request */
if (mp->REQUEST != DIOCSETP && mp->REQUEST != DIOCGETP) { if (mp->REQUEST != DIOCSETP && mp->REQUEST != DIOCGETP) {
if(dp->dr_other) { if(dp->dr_other) {
return dp->dr_other(dp, mp); return dp->dr_other(dp, mp, safe);
} else return(ENOTTY); } else return(ENOTTY);
} }
@ -358,8 +396,14 @@ message *mp; /* pointer to ioctl request */
if (mp->REQUEST == DIOCSETP) { if (mp->REQUEST == DIOCSETP) {
/* Copy just this one partition table entry. */ /* Copy just this one partition table entry. */
if (OK != (s=sys_datacopy(mp->IO_ENDPT, (vir_bytes) mp->ADDRESS, if(safe) {
SELF, (vir_bytes) &entry, sizeof(entry)))) s=sys_safecopyfrom(mp->IO_ENDPT, (vir_bytes) mp->IO_GRANT,
0, (vir_bytes) &entry, sizeof(entry), D);
} else{
s=sys_datacopy(mp->IO_ENDPT, (vir_bytes) mp->ADDRESS,
SELF, (vir_bytes) &entry, sizeof(entry));
}
if(s != OK)
return s; return s;
dv->dv_base = entry.base; dv->dv_base = entry.base;
dv->dv_size = entry.size; dv->dv_size = entry.size;
@ -368,8 +412,14 @@ message *mp; /* pointer to ioctl request */
entry.base = dv->dv_base; entry.base = dv->dv_base;
entry.size = dv->dv_size; entry.size = dv->dv_size;
(*dp->dr_geometry)(&entry); (*dp->dr_geometry)(&entry);
if (OK != (s=sys_datacopy(SELF, (vir_bytes) &entry, if(safe) {
mp->IO_ENDPT, (vir_bytes) mp->ADDRESS, sizeof(entry)))) s=sys_safecopyto(mp->IO_ENDPT, (vir_bytes) mp->IO_GRANT,
0, (vir_bytes) &entry, sizeof(entry), D);
} else {
s=sys_datacopy(SELF, (vir_bytes) &entry,
mp->IO_ENDPT, (vir_bytes) mp->ADDRESS, sizeof(entry));
}
if (OK != s)
return s; return s;
} }
return(OK); return(OK);

View file

@ -31,17 +31,17 @@ struct driver {
_PROTOTYPE( char *(*dr_name), (void) ); _PROTOTYPE( char *(*dr_name), (void) );
_PROTOTYPE( int (*dr_open), (struct driver *dp, message *m_ptr) ); _PROTOTYPE( int (*dr_open), (struct driver *dp, message *m_ptr) );
_PROTOTYPE( int (*dr_close), (struct driver *dp, message *m_ptr) ); _PROTOTYPE( int (*dr_close), (struct driver *dp, message *m_ptr) );
_PROTOTYPE( int (*dr_ioctl), (struct driver *dp, message *m_ptr) ); _PROTOTYPE( int (*dr_ioctl), (struct driver *dp, message *m_ptr, int safe) );
_PROTOTYPE( struct device *(*dr_prepare), (int device) ); _PROTOTYPE( struct device *(*dr_prepare), (int device) );
_PROTOTYPE( int (*dr_transfer), (int proc_nr, int opcode, off_t position, _PROTOTYPE( int (*dr_transfer), (int proc_nr, int opcode, off_t position,
iovec_t *iov, unsigned nr_req) ); iovec_t *iov, unsigned nr_req, int safe) );
_PROTOTYPE( void (*dr_cleanup), (void) ); _PROTOTYPE( void (*dr_cleanup), (void) );
_PROTOTYPE( void (*dr_geometry), (struct partition *entry) ); _PROTOTYPE( void (*dr_geometry), (struct partition *entry) );
_PROTOTYPE( void (*dr_signal), (struct driver *dp, message *m_ptr) ); _PROTOTYPE( void (*dr_signal), (struct driver *dp, message *m_ptr) );
_PROTOTYPE( void (*dr_alarm), (struct driver *dp, message *m_ptr) ); _PROTOTYPE( void (*dr_alarm), (struct driver *dp, message *m_ptr) );
_PROTOTYPE( int (*dr_cancel), (struct driver *dp, message *m_ptr) ); _PROTOTYPE( int (*dr_cancel), (struct driver *dp, message *m_ptr) );
_PROTOTYPE( int (*dr_select), (struct driver *dp, message *m_ptr) ); _PROTOTYPE( int (*dr_select), (struct driver *dp, message *m_ptr) );
_PROTOTYPE( int (*dr_other), (struct driver *dp, message *m_ptr) ); _PROTOTYPE( int (*dr_other), (struct driver *dp, message *m_ptr, int safe) );
_PROTOTYPE( int (*dr_hw_int), (struct driver *dp, message *m_ptr) ); _PROTOTYPE( int (*dr_hw_int), (struct driver *dp, message *m_ptr) );
}; };
@ -72,7 +72,8 @@ _PROTOTYPE( void nop_signal, (struct driver *dp, message *m_ptr) );
_PROTOTYPE( void nop_alarm, (struct driver *dp, message *m_ptr) ); _PROTOTYPE( void nop_alarm, (struct driver *dp, message *m_ptr) );
_PROTOTYPE( int nop_cancel, (struct driver *dp, message *m_ptr) ); _PROTOTYPE( int nop_cancel, (struct driver *dp, message *m_ptr) );
_PROTOTYPE( int nop_select, (struct driver *dp, message *m_ptr) ); _PROTOTYPE( int nop_select, (struct driver *dp, message *m_ptr) );
_PROTOTYPE( int do_diocntl, (struct driver *dp, message *m_ptr) ); _PROTOTYPE( int do_diocntl, (struct driver *dp, message *m_ptr, int safe) );
_PROTOTYPE( int nop_ioctl, (struct driver *dp, message *m_ptr, int safe) );
/* Parameters for the disk drive. */ /* Parameters for the disk drive. */
#define SECTOR_SIZE 512 /* physical sector size in bytes */ #define SECTOR_SIZE 512 /* physical sector size in bytes */

View file

@ -164,7 +164,7 @@ struct part_entry *table; /* four entries */
iovec1.iov_addr = (vir_bytes) partbuf; iovec1.iov_addr = (vir_bytes) partbuf;
iovec1.iov_size = CD_SECTOR_SIZE; iovec1.iov_size = CD_SECTOR_SIZE;
if ((*dp->dr_prepare)(device) != NIL_DEV) { if ((*dp->dr_prepare)(device) != NIL_DEV) {
(void) (*dp->dr_transfer)(SELF, DEV_GATHER, position, &iovec1, 1); (void) (*dp->dr_transfer)(SELF, DEV_GATHER, position, &iovec1, 1, 0);
} }
if (iovec1.iov_size != 0) { if (iovec1.iov_size != 0) {
return 0; return 0;