2005-04-21 16:53:53 +02:00
|
|
|
/* This file contains device independent device driver interface.
|
2005-07-26 14:50:25 +02:00
|
|
|
*
|
2005-04-21 16:53:53 +02:00
|
|
|
* Changes:
|
2005-08-02 17:30:36 +02:00
|
|
|
* Jul 25, 2005 added SYS_SIG type for signals (Jorrit N. Herder)
|
2005-04-21 16:53:53 +02:00
|
|
|
* Sep 15, 2004 added SYN_ALARM type for timeouts (Jorrit N. Herder)
|
|
|
|
* Jul 23, 2004 removed kernel dependencies (Jorrit N. Herder)
|
2005-07-26 14:50:25 +02:00
|
|
|
* Apr 02, 1992 constructed from AT wini and floppy driver (Kees J. Bot)
|
2005-04-21 16:53:53 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* The drivers support the following operations (using message format m2):
|
|
|
|
*
|
2006-03-03 11:21:45 +01:00
|
|
|
* m_type DEVICE IO_ENDPT COUNT POSITION ADRRESS
|
2005-04-21 16:53:53 +02:00
|
|
|
* ----------------------------------------------------------------
|
|
|
|
* | DEV_OPEN | device | proc nr | | | |
|
|
|
|
* |------------+---------+---------+---------+---------+---------|
|
|
|
|
* | DEV_CLOSE | device | proc nr | | | |
|
|
|
|
* |------------+---------+---------+---------+---------+---------|
|
|
|
|
* | DEV_READ | device | proc nr | bytes | offset | buf ptr |
|
|
|
|
* |------------+---------+---------+---------+---------+---------|
|
|
|
|
* | DEV_WRITE | device | proc nr | bytes | offset | buf ptr |
|
|
|
|
* |------------+---------+---------+---------+---------+---------|
|
|
|
|
* | DEV_GATHER | device | proc nr | iov len | offset | iov ptr |
|
|
|
|
* |------------+---------+---------+---------+---------+---------|
|
|
|
|
* | DEV_SCATTER| device | proc nr | iov len | offset | iov ptr |
|
|
|
|
* |------------+---------+---------+---------+---------+---------|
|
|
|
|
* | DEV_IOCTL | device | proc nr |func code| | buf ptr |
|
|
|
|
* |------------+---------+---------+---------+---------+---------|
|
2005-07-08 19:23:44 +02:00
|
|
|
* | CANCEL | device | proc nr | r/w | | |
|
|
|
|
* |------------+---------+---------+---------+---------+---------|
|
2005-04-21 16:53:53 +02:00
|
|
|
* | HARD_STOP | | | | | |
|
2006-06-20 10:49:51 +02:00
|
|
|
* |------------+---------+---------+---------+---------+---------|
|
|
|
|
* | DEV_*_S | variants using safecopies of above |
|
2005-04-21 16:53:53 +02:00
|
|
|
* ----------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* The file contains one entry point:
|
|
|
|
*
|
|
|
|
* driver_task: called by the device dependent task entry
|
|
|
|
*/
|
|
|
|
|
2007-02-07 17:22:19 +01:00
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
#include "../drivers.h"
|
|
|
|
#include <sys/ioc_disk.h>
|
2007-01-12 14:33:12 +01:00
|
|
|
#include <minix/mq.h>
|
2005-04-21 16:53:53 +02:00
|
|
|
#include "driver.h"
|
|
|
|
|
|
|
|
/* Claim space for variables. */
|
2008-11-19 13:26:10 +01:00
|
|
|
#if 0
|
|
|
|
PRIVATE u8_t buffer[(unsigned) 2 * DMA_BUF_SIZE];
|
|
|
|
#endif
|
2005-04-21 16:53:53 +02:00
|
|
|
u8_t *tmp_buf; /* the DMA buffer eventually */
|
|
|
|
phys_bytes tmp_phys; /* phys address of DMA buffer */
|
|
|
|
|
2006-06-20 10:49:51 +02:00
|
|
|
FORWARD _PROTOTYPE( int do_rdwt, (struct driver *dr, message *mp, int safe) );
|
|
|
|
FORWARD _PROTOTYPE( int do_vrdwt, (struct driver *dr, message *mp, int safe) );
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2005-07-08 19:23:44 +02:00
|
|
|
int device_caller;
|
2007-01-12 14:33:12 +01:00
|
|
|
PRIVATE mq_t *queue_head = NULL;
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* driver_task *
|
|
|
|
*===========================================================================*/
|
|
|
|
PUBLIC void driver_task(dp)
|
|
|
|
struct driver *dp; /* Device dependent entry points. */
|
|
|
|
{
|
|
|
|
/* Main program of any device driver task. */
|
|
|
|
|
2005-07-08 19:23:44 +02:00
|
|
|
int r, proc_nr;
|
2005-04-21 16:53:53 +02:00
|
|
|
message mess;
|
|
|
|
|
2008-12-11 15:42:23 +01:00
|
|
|
system_hz = sys_hz();
|
|
|
|
|
2007-01-12 14:33:12 +01:00
|
|
|
/* Init MQ library. */
|
|
|
|
mq_init();
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
/* Here is the main loop of the disk task. It waits for a message, carries
|
|
|
|
* it out, and sends a reply.
|
|
|
|
*/
|
|
|
|
while (TRUE) {
|
2007-01-12 14:33:12 +01:00
|
|
|
/* Any queued messages? Oldest are at the head. */
|
|
|
|
if(queue_head) {
|
|
|
|
mq_t *mq;
|
|
|
|
mq = queue_head;
|
|
|
|
memcpy(&mess, &mq->mq_mess, sizeof(mess));
|
|
|
|
queue_head = queue_head->mq_next;
|
|
|
|
mq_free(mq);
|
|
|
|
} else {
|
|
|
|
int s;
|
|
|
|
/* Wait for a request to read or write a disk block. */
|
|
|
|
if ((s=receive(ANY, &mess)) != OK)
|
|
|
|
panic((*dp->dr_name)(),"receive() failed", s);
|
|
|
|
}
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2005-07-08 19:23:44 +02:00
|
|
|
device_caller = mess.m_source;
|
2006-03-03 11:21:45 +01:00
|
|
|
proc_nr = mess.IO_ENDPT;
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* Now carry out the work. */
|
|
|
|
switch(mess.m_type) {
|
2005-10-20 22:26:02 +02:00
|
|
|
case DEV_OPEN: r = (*dp->dr_open)(dp, &mess); break;
|
2005-04-21 16:53:53 +02:00
|
|
|
case DEV_CLOSE: r = (*dp->dr_close)(dp, &mess); break;
|
2007-02-07 17:22:19 +01:00
|
|
|
#ifdef DEV_IOCTL
|
2006-06-20 10:49:51 +02:00
|
|
|
case DEV_IOCTL: r = (*dp->dr_ioctl)(dp, &mess, 0); break;
|
2007-02-07 17:22:19 +01:00
|
|
|
#endif
|
2006-06-20 10:49:51 +02:00
|
|
|
case DEV_IOCTL_S: r = (*dp->dr_ioctl)(dp, &mess, 1); break;
|
2005-07-08 19:23:44 +02:00
|
|
|
case CANCEL: r = (*dp->dr_cancel)(dp, &mess);break;
|
|
|
|
case DEV_SELECT: r = (*dp->dr_select)(dp, &mess);break;
|
2007-02-07 17:22:19 +01:00
|
|
|
#ifdef DEV_READ
|
2005-05-13 10:57:08 +02:00
|
|
|
case DEV_READ:
|
2006-06-20 10:49:51 +02:00
|
|
|
case DEV_WRITE: r = do_rdwt(dp, &mess, 0); break;
|
2007-02-07 17:22:19 +01:00
|
|
|
#endif
|
2006-06-20 10:49:51 +02:00
|
|
|
case DEV_READ_S:
|
|
|
|
case DEV_WRITE_S: r = do_rdwt(dp, &mess, 1); break;
|
2007-02-07 17:22:19 +01:00
|
|
|
#ifdef DEV_GATHER
|
2005-05-13 10:57:08 +02:00
|
|
|
case DEV_GATHER:
|
2006-06-20 10:49:51 +02:00
|
|
|
case DEV_SCATTER: r = do_vrdwt(dp, &mess, 0); break;
|
2007-02-07 17:22:19 +01:00
|
|
|
#endif
|
2006-06-20 10:49:51 +02:00
|
|
|
case DEV_GATHER_S:
|
|
|
|
case DEV_SCATTER_S: r = do_vrdwt(dp, &mess, 1); break;
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
case HARD_INT: /* leftover interrupt or expired timer. */
|
2005-08-25 10:19:11 +02:00
|
|
|
if(dp->dr_hw_int) {
|
|
|
|
(*dp->dr_hw_int)(dp, &mess);
|
|
|
|
}
|
2005-04-21 16:53:53 +02:00
|
|
|
continue;
|
2006-03-10 17:20:24 +01:00
|
|
|
case PROC_EVENT:
|
2005-08-02 17:30:36 +02:00
|
|
|
case SYS_SIG: (*dp->dr_signal)(dp, &mess);
|
2005-04-21 16:53:53 +02:00
|
|
|
continue; /* don't reply */
|
2005-07-26 14:50:25 +02:00
|
|
|
case SYN_ALARM: (*dp->dr_alarm)(dp, &mess);
|
2005-04-21 16:53:53 +02:00
|
|
|
continue; /* don't reply */
|
2005-10-12 16:31:39 +02:00
|
|
|
case DEV_PING: notify(mess.m_source);
|
|
|
|
continue;
|
2005-07-08 19:23:44 +02:00
|
|
|
default:
|
|
|
|
if(dp->dr_other)
|
2006-06-20 10:49:51 +02:00
|
|
|
r = (*dp->dr_other)(dp, &mess, 0);
|
2005-07-08 19:23:44 +02:00
|
|
|
else
|
|
|
|
r = EINVAL;
|
|
|
|
break;
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Clean up leftover state. */
|
|
|
|
(*dp->dr_cleanup)();
|
|
|
|
|
|
|
|
/* Finally, prepare and send the reply message. */
|
2005-07-21 20:29:52 +02:00
|
|
|
if (r != EDONTREPLY) {
|
|
|
|
mess.m_type = TASK_REPLY;
|
2006-03-03 11:21:45 +01:00
|
|
|
mess.REP_ENDPT = proc_nr;
|
2005-07-21 20:29:52 +02:00
|
|
|
/* Status is # of bytes transferred or error code. */
|
|
|
|
mess.REP_STATUS = r;
|
2008-02-22 16:52:13 +01:00
|
|
|
r= sendnb(device_caller, &mess);
|
|
|
|
if (r != OK)
|
|
|
|
{
|
|
|
|
printf("driver_task: unable to sendnb to %d: %d\n",
|
|
|
|
device_caller, r);
|
|
|
|
}
|
2005-07-21 20:29:52 +02:00
|
|
|
}
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-10-20 22:26:02 +02:00
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* init_buffer *
|
|
|
|
*===========================================================================*/
|
2008-11-19 13:26:10 +01:00
|
|
|
PUBLIC void init_buffer(void)
|
2005-04-21 16:53:53 +02:00
|
|
|
{
|
|
|
|
/* Select a buffer that can safely be used for DMA transfers. It may also
|
|
|
|
* be used to read partition tables and such. Its absolute address is
|
|
|
|
* 'tmp_phys', the normal address is 'tmp_buf'.
|
|
|
|
*/
|
|
|
|
|
|
|
|
unsigned left;
|
|
|
|
|
2008-11-19 13:26:10 +01:00
|
|
|
if(!(tmp_buf = alloc_contig(2*DMA_BUF_SIZE, AC_ALIGN4K, &tmp_phys)))
|
|
|
|
panic(__FILE__, "can't allocate tmp_buf", DMA_BUF_SIZE);
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* do_rdwt *
|
|
|
|
*===========================================================================*/
|
2006-06-20 10:49:51 +02:00
|
|
|
PRIVATE int do_rdwt(dp, mp, safe)
|
2005-04-21 16:53:53 +02:00
|
|
|
struct driver *dp; /* device dependent entry points */
|
|
|
|
message *mp; /* pointer to read or write message */
|
2006-06-20 10:49:51 +02:00
|
|
|
int safe; /* use safecopies? */
|
2005-04-21 16:53:53 +02:00
|
|
|
{
|
|
|
|
/* Carry out a single read or write request. */
|
|
|
|
iovec_t iovec1;
|
|
|
|
int r, opcode;
|
|
|
|
phys_bytes phys_addr;
|
2006-11-27 15:21:43 +01:00
|
|
|
u64_t position;
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* Disk address? Address and length of the user buffer? */
|
|
|
|
if (mp->COUNT < 0) return(EINVAL);
|
|
|
|
|
2006-06-20 10:49:51 +02:00
|
|
|
/* Check the user buffer (not relevant for safe copies). */
|
|
|
|
if(!safe) {
|
2008-11-19 13:26:10 +01:00
|
|
|
printf("libdriver_asyn: do_rdwt: no support for non-safe command.\n");
|
|
|
|
return EINVAL;
|
2006-06-20 10:49:51 +02:00
|
|
|
}
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* Prepare for I/O. */
|
|
|
|
if ((*dp->dr_prepare)(mp->DEVICE) == NIL_DEV) return(ENXIO);
|
|
|
|
|
|
|
|
/* Create a one element scatter/gather vector for the buffer. */
|
2007-02-07 17:22:19 +01:00
|
|
|
if(
|
|
|
|
#ifdef DEV_READ
|
|
|
|
mp->m_type == DEV_READ ||
|
|
|
|
#endif
|
|
|
|
mp->m_type == DEV_READ_S) opcode = DEV_GATHER_S;
|
|
|
|
else opcode = DEV_SCATTER_S;
|
2006-06-20 10:49:51 +02:00
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
iovec1.iov_addr = (vir_bytes) mp->ADDRESS;
|
|
|
|
iovec1.iov_size = mp->COUNT;
|
|
|
|
|
|
|
|
/* Transfer bytes from/to the device. */
|
2006-11-27 15:21:43 +01:00
|
|
|
position= make64(mp->POSITION, mp->HIGHPOS);
|
|
|
|
r = (*dp->dr_transfer)(mp->IO_ENDPT, opcode, position, &iovec1, 1, safe);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* Return the number of bytes transferred or an error code. */
|
|
|
|
return(r == OK ? (mp->COUNT - iovec1.iov_size) : r);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*==========================================================================*
|
|
|
|
* do_vrdwt *
|
|
|
|
*==========================================================================*/
|
2006-06-20 10:49:51 +02:00
|
|
|
PRIVATE int do_vrdwt(dp, mp, safe)
|
2005-04-21 16:53:53 +02:00
|
|
|
struct driver *dp; /* device dependent entry points */
|
|
|
|
message *mp; /* pointer to read or write message */
|
2006-06-20 10:49:51 +02:00
|
|
|
int safe; /* use safecopies? */
|
2005-04-21 16:53:53 +02:00
|
|
|
{
|
|
|
|
/* 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
|
|
|
|
* its own buffers, so they are not checked.
|
|
|
|
*/
|
|
|
|
static iovec_t iovec[NR_IOREQS];
|
|
|
|
iovec_t *iov;
|
|
|
|
phys_bytes iovec_size;
|
|
|
|
unsigned nr_req;
|
2006-06-20 10:49:51 +02:00
|
|
|
int r, j, opcode;
|
2006-11-27 15:21:43 +01:00
|
|
|
u64_t position;
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
nr_req = mp->COUNT; /* Length of I/O vector */
|
|
|
|
|
2006-03-03 11:21:45 +01:00
|
|
|
{
|
2005-04-21 16:53:53 +02:00
|
|
|
/* Copy the vector from the caller to kernel space. */
|
|
|
|
if (nr_req > NR_IOREQS) nr_req = NR_IOREQS;
|
|
|
|
iovec_size = (phys_bytes) (nr_req * sizeof(iovec[0]));
|
|
|
|
|
2006-06-20 10:49:51 +02:00
|
|
|
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,
|
|
|
|
SELF, (vir_bytes) iovec, iovec_size)) {
|
|
|
|
panic((*dp->dr_name)(),"bad I/O vector by", mp->m_source);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
iov = iovec;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Prepare for I/O. */
|
|
|
|
if ((*dp->dr_prepare)(mp->DEVICE) == NIL_DEV) return(ENXIO);
|
|
|
|
|
|
|
|
/* Transfer bytes from/to the device. */
|
2006-06-20 10:49:51 +02:00
|
|
|
opcode = mp->m_type;
|
2006-11-27 15:21:43 +01:00
|
|
|
position= make64(mp->POSITION, mp->HIGHPOS);
|
|
|
|
r = (*dp->dr_transfer)(mp->IO_ENDPT, opcode, position, iov,
|
2006-06-20 10:49:51 +02:00
|
|
|
nr_req, safe);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* Copy the I/O vector back to the caller. */
|
2006-06-20 10:49:51 +02:00
|
|
|
if(safe) {
|
|
|
|
if (OK != sys_safecopyto(mp->m_source, (vir_bytes) mp->IO_GRANT,
|
|
|
|
0, (vir_bytes) iovec, iovec_size, D)) {
|
|
|
|
panic((*dp->dr_name)(),"couldn't return I/O vector", mp->m_source);
|
|
|
|
}
|
|
|
|
} else {
|
2005-04-21 16:53:53 +02:00
|
|
|
sys_datacopy(SELF, (vir_bytes) iovec,
|
|
|
|
mp->m_source, (vir_bytes) mp->ADDRESS, iovec_size);
|
2006-06-20 10:49:51 +02:00
|
|
|
}
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
return(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* no_name *
|
|
|
|
*===========================================================================*/
|
|
|
|
PUBLIC char *no_name()
|
|
|
|
{
|
|
|
|
/* Use this default name if there is no specific name for the device. This was
|
|
|
|
* originally done by fetching the name from the task table for this process:
|
|
|
|
* "return(tasktab[proc_number(proc_ptr) + NR_TASKS].name);", but currently a
|
|
|
|
* real "noname" is returned. Perhaps, some system information service can be
|
|
|
|
* queried for a name at a later time.
|
|
|
|
*/
|
|
|
|
static char name[] = "noname";
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*============================================================================*
|
|
|
|
* do_nop *
|
|
|
|
*============================================================================*/
|
|
|
|
PUBLIC int do_nop(dp, mp)
|
|
|
|
struct driver *dp;
|
|
|
|
message *mp;
|
|
|
|
{
|
|
|
|
/* Nothing there, or nothing to do. */
|
|
|
|
|
|
|
|
switch (mp->m_type) {
|
|
|
|
case DEV_OPEN: return(ENODEV);
|
|
|
|
case DEV_CLOSE: return(OK);
|
2007-02-07 17:22:19 +01:00
|
|
|
case DEV_IOCTL_S:
|
|
|
|
#ifdef DEV_IOCTL
|
2005-04-21 16:53:53 +02:00
|
|
|
case DEV_IOCTL: return(ENOTTY);
|
2007-02-07 17:22:19 +01:00
|
|
|
#endif
|
2006-06-20 10:49:51 +02:00
|
|
|
default: printf("nop: ignoring code %d\n", mp->m_type); return(EIO);
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-20 10:49:51 +02:00
|
|
|
/*============================================================================*
|
|
|
|
* nop_ioctl *
|
|
|
|
*============================================================================*/
|
|
|
|
PUBLIC int nop_ioctl(dp, mp, safe)
|
|
|
|
struct driver *dp;
|
|
|
|
message *mp;
|
|
|
|
int safe;
|
|
|
|
{
|
|
|
|
return(ENOTTY);
|
|
|
|
}
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
/*============================================================================*
|
2005-07-26 14:50:25 +02:00
|
|
|
* nop_signal *
|
2005-04-21 16:53:53 +02:00
|
|
|
*============================================================================*/
|
2005-07-26 14:50:25 +02:00
|
|
|
PUBLIC void nop_signal(dp, mp)
|
2005-04-21 16:53:53 +02:00
|
|
|
struct driver *dp;
|
2005-07-26 14:50:25 +02:00
|
|
|
message *mp;
|
2005-04-21 16:53:53 +02:00
|
|
|
{
|
2005-07-26 14:50:25 +02:00
|
|
|
/* Default action for signal is to ignore. */
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*============================================================================*
|
|
|
|
* nop_alarm *
|
|
|
|
*============================================================================*/
|
2005-07-26 14:50:25 +02:00
|
|
|
PUBLIC void nop_alarm(dp, mp)
|
2005-04-21 16:53:53 +02:00
|
|
|
struct driver *dp;
|
2005-07-26 14:50:25 +02:00
|
|
|
message *mp;
|
2005-04-21 16:53:53 +02:00
|
|
|
{
|
|
|
|
/* Ignore the leftover alarm. */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* nop_prepare *
|
|
|
|
*===========================================================================*/
|
|
|
|
PUBLIC struct device *nop_prepare(device)
|
|
|
|
{
|
|
|
|
/* Nothing to prepare for. */
|
|
|
|
return(NIL_DEV);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* nop_cleanup *
|
|
|
|
*===========================================================================*/
|
|
|
|
PUBLIC void nop_cleanup()
|
|
|
|
{
|
|
|
|
/* Nothing to clean up. */
|
|
|
|
}
|
|
|
|
|
2005-07-08 19:23:44 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* nop_cancel *
|
|
|
|
*===========================================================================*/
|
|
|
|
PUBLIC int nop_cancel(struct driver *dr, message *m)
|
|
|
|
{
|
|
|
|
/* Nothing to do for cancel. */
|
2005-08-25 14:50:11 +02:00
|
|
|
return(OK);
|
2005-07-08 19:23:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* nop_select *
|
|
|
|
*===========================================================================*/
|
|
|
|
PUBLIC int nop_select(struct driver *dr, message *m)
|
|
|
|
{
|
|
|
|
/* Nothing to do for select. */
|
2005-08-25 14:50:11 +02:00
|
|
|
return(OK);
|
2005-07-08 19:23:44 +02:00
|
|
|
}
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
/*============================================================================*
|
|
|
|
* do_diocntl *
|
|
|
|
*============================================================================*/
|
2006-06-20 10:49:51 +02:00
|
|
|
PUBLIC int do_diocntl(dp, mp, safe)
|
2005-04-21 16:53:53 +02:00
|
|
|
struct driver *dp;
|
|
|
|
message *mp; /* pointer to ioctl request */
|
2006-06-20 10:49:51 +02:00
|
|
|
int safe; /* addresses or grants? */
|
2005-04-21 16:53:53 +02:00
|
|
|
{
|
|
|
|
/* Carry out a partition setting/getting request. */
|
|
|
|
struct device *dv;
|
|
|
|
struct partition entry;
|
|
|
|
int s;
|
|
|
|
|
2005-07-13 16:58:21 +02:00
|
|
|
if (mp->REQUEST != DIOCSETP && mp->REQUEST != DIOCGETP) {
|
|
|
|
if(dp->dr_other) {
|
2006-06-20 10:49:51 +02:00
|
|
|
return dp->dr_other(dp, mp, safe);
|
2005-07-13 16:58:21 +02:00
|
|
|
} else return(ENOTTY);
|
|
|
|
}
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/* Decode the message parameters. */
|
|
|
|
if ((dv = (*dp->dr_prepare)(mp->DEVICE)) == NIL_DEV) return(ENXIO);
|
|
|
|
|
|
|
|
if (mp->REQUEST == DIOCSETP) {
|
|
|
|
/* Copy just this one partition table entry. */
|
2006-06-20 10:49:51 +02:00
|
|
|
if(safe) {
|
|
|
|
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)
|
2005-04-21 16:53:53 +02:00
|
|
|
return s;
|
|
|
|
dv->dv_base = entry.base;
|
|
|
|
dv->dv_size = entry.size;
|
|
|
|
} else {
|
|
|
|
/* Return a partition table entry and the geometry of the drive. */
|
|
|
|
entry.base = dv->dv_base;
|
|
|
|
entry.size = dv->dv_size;
|
|
|
|
(*dp->dr_geometry)(&entry);
|
2006-06-20 10:49:51 +02:00
|
|
|
if(safe) {
|
|
|
|
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)
|
2005-04-21 16:53:53 +02:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
return(OK);
|
|
|
|
}
|
2007-01-12 14:33:12 +01:00
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* mq_queue *
|
|
|
|
*===========================================================================*/
|
|
|
|
PUBLIC int mq_queue(message *m)
|
|
|
|
{
|
|
|
|
mq_t *mq, *mi;
|
|
|
|
|
|
|
|
if(!(mq = mq_get()))
|
|
|
|
panic("libdriver","mq_queue: mq_get failed", NO_NUM);
|
|
|
|
memcpy(&mq->mq_mess, m, sizeof(mq->mq_mess));
|
|
|
|
mq->mq_next = NULL;
|
|
|
|
if(!queue_head) {
|
|
|
|
queue_head = mq;
|
|
|
|
} else {
|
|
|
|
for(mi = queue_head; mi->mq_next; mi = mi->mq_next)
|
|
|
|
;
|
|
|
|
mi->mq_next = mq;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|