Split block/character protocols and libdriver
This patch separates the character and block driver communication
protocols. The old character protocol remains the same, but a new
block protocol is introduced. The libdriver library is replaced by
two new libraries: libchardriver and libblockdriver. Their exposed
API, and drivers that use them, have been updated accordingly.
Together, libbdev and libblockdriver now completely abstract away
the message format used by the block protocol. As the memory driver
is both a character and a block device driver, it now implements its
own message loop.
The most important semantic change made to the block protocol is that
it is no longer possible to return both partial results and an error
for a single transfer. This simplifies the interaction between the
caller and the driver, as the I/O vector no longer needs to be copied
back. Also, drivers are now no longer supposed to decide based on the
layout of the I/O vector when a transfer should be cut short. Put
simply, transfers are now supposed to either succeed completely, or
result in an error.
After this patch, the state of the various pieces is as follows:
- block protocol: stable
- libbdev API: stable for synchronous communication
- libblockdriver API: needs slight revision (the drvlib/partition API
in particular; the threading API will also change shortly)
- character protocol: needs cleanup
- libchardriver API: needs cleanup accordingly
- driver restarts: largely unsupported until endpoint changes are
reintroduced
As a side effect, this patch eliminates several bugs, hacks, and gcc
-Wall and -W warnings all over the place. It probably introduces a
few new ones, too.
Update warning: this patch changes the protocol between MFS and disk
drivers, so in order to use old/new images, the MFS from the ramdisk
must be used to mount all file systems.
2011-11-22 13:27:53 +01:00
|
|
|
/* This file contains the device independent character driver interface.
|
2005-04-21 16:53:53 +02:00
|
|
|
*
|
|
|
|
* The drivers support the following operations (using message format m2):
|
|
|
|
*
|
Server/driver protocols: no longer allow third-party copies.
Before safecopies, the IO_ENDPT and DL_ENDPT message fields were needed
to know which actual process to copy data from/to, as that process may
not always be the caller. Now that we have full safecopy support, these
fields have become useless for that purpose: the owner of the grant is
*always* the caller. Allowing the caller to supply another endpoint is
in fact dangerous, because the callee may then end up using a grant
from a third party. One could call this a variant of the confused
deputy problem.
From now on, safecopy calls should always use the caller's endpoint as
grant owner. This fully obsoletes the DL_ENDPT field in the
inet/ethernet protocol. IO_ENDPT has other uses besides identifying the
grant owner though. This patch renames IO_ENDPT to USER_ENDPT, not only
because that is a more fitting name (it should never be used for I/O
after all), but also in order to intentionally break any old system
source code outside the base system. If this patch breaks your code,
fixing it is fairly simple:
- DL_ENDPT should be replaced with m_source;
- IO_ENDPT should be replaced with m_source when used for safecopies;
- IO_ENDPT should be replaced with USER_ENDPT for any other use, e.g.
when setting REP_ENDPT, matching requests in CANCEL calls, getting
DEV_SELECT flags, and retrieving of the real user process's endpoint
in DEV_OPEN.
The changes in this patch are binary backward compatible.
2011-04-11 19:35:05 +02:00
|
|
|
* m_type DEVICE USER_ENDPT COUNT POSITION HIGHPOS IO_GRANT
|
2009-12-02 10:57:48 +01:00
|
|
|
* ----------------------------------------------------------------------------
|
2011-11-02 17:31:38 +01:00
|
|
|
* | DEV_OPEN | device | proc nr | mode | | | |
|
2009-12-02 10:57:48 +01:00
|
|
|
* |---------------+--------+---------+---------+--------+--------+-----------|
|
|
|
|
* | DEV_CLOSE | device | proc nr | | | | |
|
|
|
|
* |---------------+--------+---------+---------+--------+--------+-----------|
|
|
|
|
* | DEV_READ_S | device | proc nr | bytes | off lo | off hi i buf grant |
|
|
|
|
* |---------------+--------+---------+---------+--------+--------+-----------|
|
|
|
|
* | DEV_WRITE_S | device | proc nr | bytes | off lo | off hi | buf grant |
|
|
|
|
* |---------------+--------+---------+---------+--------+--------+-----------|
|
|
|
|
* | DEV_GATHER_S | device | proc nr | iov len | off lo | off hi | iov grant |
|
|
|
|
* |---------------+--------+---------+---------+--------+--------+-----------|
|
|
|
|
* | DEV_SCATTER_S | device | proc nr | iov len | off lo | off hi | iov grant |
|
|
|
|
* |---------------+--------+---------+---------+--------+--------+-----------|
|
|
|
|
* | DEV_IOCTL_S | device | proc nr | request | | | buf grant |
|
|
|
|
* |---------------+--------+---------+---------+--------+--------+-----------|
|
2011-11-02 17:31:38 +01:00
|
|
|
* | CANCEL | device | proc nr | r/w | | | grant |
|
|
|
|
* |---------------+--------+---------+---------+--------+--------+-----------|
|
|
|
|
* | DEV_SELECT | device | ops | | | | |
|
2009-12-02 10:57:48 +01:00
|
|
|
* ----------------------------------------------------------------------------
|
2005-04-21 16:53:53 +02:00
|
|
|
*
|
2011-11-02 17:31:38 +01:00
|
|
|
* Changes:
|
2013-09-03 01:49:38 +02:00
|
|
|
* Sep 01, 2013 complete rewrite of the API (D.C. van Moolenboek)
|
|
|
|
* Aug 20, 2013 retire synchronous protocol (D.C. van Moolenbroek)
|
Split block/character protocols and libdriver
This patch separates the character and block driver communication
protocols. The old character protocol remains the same, but a new
block protocol is introduced. The libdriver library is replaced by
two new libraries: libchardriver and libblockdriver. Their exposed
API, and drivers that use them, have been updated accordingly.
Together, libbdev and libblockdriver now completely abstract away
the message format used by the block protocol. As the memory driver
is both a character and a block device driver, it now implements its
own message loop.
The most important semantic change made to the block protocol is that
it is no longer possible to return both partial results and an error
for a single transfer. This simplifies the interaction between the
caller and the driver, as the I/O vector no longer needs to be copied
back. Also, drivers are now no longer supposed to decide based on the
layout of the I/O vector when a transfer should be cut short. Put
simply, transfers are now supposed to either succeed completely, or
result in an error.
After this patch, the state of the various pieces is as follows:
- block protocol: stable
- libbdev API: stable for synchronous communication
- libblockdriver API: needs slight revision (the drvlib/partition API
in particular; the threading API will also change shortly)
- character protocol: needs cleanup
- libchardriver API: needs cleanup accordingly
- driver restarts: largely unsupported until endpoint changes are
reintroduced
As a side effect, this patch eliminates several bugs, hacks, and gcc
-Wall and -W warnings all over the place. It probably introduces a
few new ones, too.
Update warning: this patch changes the protocol between MFS and disk
drivers, so in order to use old/new images, the MFS from the ramdisk
must be used to mount all file systems.
2011-11-22 13:27:53 +01:00
|
|
|
* Oct 16, 2011 split character and block protocol (D.C. van Moolenbroek)
|
|
|
|
* Aug 27, 2011 move common functions into driver.c (A. Welzel)
|
2011-11-02 17:31:38 +01:00
|
|
|
* Jul 25, 2005 added SYS_SIG type for signals (Jorrit N. Herder)
|
|
|
|
* Sep 15, 2004 added SYN_ALARM type for timeouts (Jorrit N. Herder)
|
|
|
|
* Jul 23, 2004 removed kernel dependencies (Jorrit N. Herder)
|
|
|
|
* Apr 02, 1992 constructed from AT wini and floppy driver (Kees J. Bot)
|
2005-04-21 16:53:53 +02:00
|
|
|
*/
|
|
|
|
|
2010-03-22 22:25:22 +01:00
|
|
|
#include <minix/drivers.h>
|
Split block/character protocols and libdriver
This patch separates the character and block driver communication
protocols. The old character protocol remains the same, but a new
block protocol is introduced. The libdriver library is replaced by
two new libraries: libchardriver and libblockdriver. Their exposed
API, and drivers that use them, have been updated accordingly.
Together, libbdev and libblockdriver now completely abstract away
the message format used by the block protocol. As the memory driver
is both a character and a block device driver, it now implements its
own message loop.
The most important semantic change made to the block protocol is that
it is no longer possible to return both partial results and an error
for a single transfer. This simplifies the interaction between the
caller and the driver, as the I/O vector no longer needs to be copied
back. Also, drivers are now no longer supposed to decide based on the
layout of the I/O vector when a transfer should be cut short. Put
simply, transfers are now supposed to either succeed completely, or
result in an error.
After this patch, the state of the various pieces is as follows:
- block protocol: stable
- libbdev API: stable for synchronous communication
- libblockdriver API: needs slight revision (the drvlib/partition API
in particular; the threading API will also change shortly)
- character protocol: needs cleanup
- libchardriver API: needs cleanup accordingly
- driver restarts: largely unsupported until endpoint changes are
reintroduced
As a side effect, this patch eliminates several bugs, hacks, and gcc
-Wall and -W warnings all over the place. It probably introduces a
few new ones, too.
Update warning: this patch changes the protocol between MFS and disk
drivers, so in order to use old/new images, the MFS from the ramdisk
must be used to mount all file systems.
2011-11-22 13:27:53 +01:00
|
|
|
#include <minix/chardriver.h>
|
2010-04-08 15:41:35 +02:00
|
|
|
#include <minix/ds.h>
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2012-03-25 20:25:53 +02:00
|
|
|
static int running;
|
2011-11-02 17:31:38 +01:00
|
|
|
|
|
|
|
/* Management data for opened devices. */
|
2013-09-03 01:49:38 +02:00
|
|
|
static devminor_t open_devs[MAX_NR_OPEN_DEVICES];
|
2012-03-25 20:25:53 +02:00
|
|
|
static int next_open_devs_slot = 0;
|
2010-04-08 15:41:35 +02:00
|
|
|
|
|
|
|
/*===========================================================================*
|
2011-11-02 17:31:38 +01:00
|
|
|
* clear_open_devs *
|
2010-04-08 15:41:35 +02:00
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
static void clear_open_devs(void)
|
2010-04-08 15:41:35 +02:00
|
|
|
{
|
2011-11-02 17:31:38 +01:00
|
|
|
/* Reset the set of previously opened minor devices. */
|
2010-04-08 15:41:35 +02:00
|
|
|
next_open_devs_slot = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
2011-11-02 17:31:38 +01:00
|
|
|
* is_open_dev *
|
2010-04-08 15:41:35 +02:00
|
|
|
*===========================================================================*/
|
2013-09-03 01:49:38 +02:00
|
|
|
static int is_open_dev(devminor_t minor)
|
2010-04-08 15:41:35 +02:00
|
|
|
{
|
2011-11-02 17:31:38 +01:00
|
|
|
/* Check whether the given minor device has previously been opened. */
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < next_open_devs_slot; i++)
|
2013-09-03 01:49:38 +02:00
|
|
|
if (open_devs[i] == minor)
|
2011-11-02 17:31:38 +01:00
|
|
|
return TRUE;
|
2010-04-08 15:41:35 +02:00
|
|
|
|
2011-11-02 17:31:38 +01:00
|
|
|
return FALSE;
|
2010-04-08 15:41:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
2011-11-02 17:31:38 +01:00
|
|
|
* set_open_dev *
|
2010-04-08 15:41:35 +02:00
|
|
|
*===========================================================================*/
|
2013-09-03 01:49:38 +02:00
|
|
|
static void set_open_dev(devminor_t minor)
|
2010-04-08 15:41:35 +02:00
|
|
|
{
|
2011-11-02 17:31:38 +01:00
|
|
|
/* Mark the given minor device as having been opened. */
|
|
|
|
|
|
|
|
if (next_open_devs_slot >= MAX_NR_OPEN_DEVICES)
|
|
|
|
panic("out of slots for open devices");
|
|
|
|
|
2013-09-03 01:49:38 +02:00
|
|
|
open_devs[next_open_devs_slot] = minor;
|
2010-04-08 15:41:35 +02:00
|
|
|
next_open_devs_slot++;
|
|
|
|
}
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2009-12-02 10:57:48 +01:00
|
|
|
/*===========================================================================*
|
Split block/character protocols and libdriver
This patch separates the character and block driver communication
protocols. The old character protocol remains the same, but a new
block protocol is introduced. The libdriver library is replaced by
two new libraries: libchardriver and libblockdriver. Their exposed
API, and drivers that use them, have been updated accordingly.
Together, libbdev and libblockdriver now completely abstract away
the message format used by the block protocol. As the memory driver
is both a character and a block device driver, it now implements its
own message loop.
The most important semantic change made to the block protocol is that
it is no longer possible to return both partial results and an error
for a single transfer. This simplifies the interaction between the
caller and the driver, as the I/O vector no longer needs to be copied
back. Also, drivers are now no longer supposed to decide based on the
layout of the I/O vector when a transfer should be cut short. Put
simply, transfers are now supposed to either succeed completely, or
result in an error.
After this patch, the state of the various pieces is as follows:
- block protocol: stable
- libbdev API: stable for synchronous communication
- libblockdriver API: needs slight revision (the drvlib/partition API
in particular; the threading API will also change shortly)
- character protocol: needs cleanup
- libchardriver API: needs cleanup accordingly
- driver restarts: largely unsupported until endpoint changes are
reintroduced
As a side effect, this patch eliminates several bugs, hacks, and gcc
-Wall and -W warnings all over the place. It probably introduces a
few new ones, too.
Update warning: this patch changes the protocol between MFS and disk
drivers, so in order to use old/new images, the MFS from the ramdisk
must be used to mount all file systems.
2011-11-22 13:27:53 +01:00
|
|
|
* chardriver_announce *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
void chardriver_announce(void)
|
Split block/character protocols and libdriver
This patch separates the character and block driver communication
protocols. The old character protocol remains the same, but a new
block protocol is introduced. The libdriver library is replaced by
two new libraries: libchardriver and libblockdriver. Their exposed
API, and drivers that use them, have been updated accordingly.
Together, libbdev and libblockdriver now completely abstract away
the message format used by the block protocol. As the memory driver
is both a character and a block device driver, it now implements its
own message loop.
The most important semantic change made to the block protocol is that
it is no longer possible to return both partial results and an error
for a single transfer. This simplifies the interaction between the
caller and the driver, as the I/O vector no longer needs to be copied
back. Also, drivers are now no longer supposed to decide based on the
layout of the I/O vector when a transfer should be cut short. Put
simply, transfers are now supposed to either succeed completely, or
result in an error.
After this patch, the state of the various pieces is as follows:
- block protocol: stable
- libbdev API: stable for synchronous communication
- libblockdriver API: needs slight revision (the drvlib/partition API
in particular; the threading API will also change shortly)
- character protocol: needs cleanup
- libchardriver API: needs cleanup accordingly
- driver restarts: largely unsupported until endpoint changes are
reintroduced
As a side effect, this patch eliminates several bugs, hacks, and gcc
-Wall and -W warnings all over the place. It probably introduces a
few new ones, too.
Update warning: this patch changes the protocol between MFS and disk
drivers, so in order to use old/new images, the MFS from the ramdisk
must be used to mount all file systems.
2011-11-22 13:27:53 +01:00
|
|
|
{
|
|
|
|
/* Announce we are up after a fresh start or restart. */
|
|
|
|
int r;
|
|
|
|
char key[DS_MAX_KEYLEN];
|
|
|
|
char label[DS_MAX_KEYLEN];
|
|
|
|
char *driver_prefix = "drv.chr.";
|
|
|
|
|
|
|
|
/* Callers are allowed to use sendrec to communicate with drivers.
|
|
|
|
* For this reason, there may blocked callers when a driver restarts.
|
|
|
|
* Ask the kernel to unblock them (if any).
|
|
|
|
*/
|
|
|
|
#if USE_STATECTL
|
|
|
|
if ((r = sys_statectl(SYS_STATE_CLEAR_IPC_REFS)) != OK)
|
|
|
|
panic("chardriver_init: sys_statectl failed: %d", r);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Publish a driver up event. */
|
|
|
|
if ((r = ds_retrieve_label_name(label, getprocnr())) != OK)
|
|
|
|
panic("chardriver_init: unable to get own label: %d", r);
|
|
|
|
|
|
|
|
snprintf(key, DS_MAX_KEYLEN, "%s%s", driver_prefix, label);
|
|
|
|
if ((r = ds_publish_u32(key, DS_DRIVER_UP, DSF_OVERWRITE)) != OK)
|
|
|
|
panic("chardriver_init: unable to publish driver up event: %d", r);
|
|
|
|
|
|
|
|
/* Expect a DEV_OPEN for any device before serving regular driver requests. */
|
|
|
|
clear_open_devs();
|
|
|
|
}
|
|
|
|
|
2013-09-03 01:49:38 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* chardriver_reply_task *
|
|
|
|
*===========================================================================*/
|
|
|
|
void chardriver_reply_task(endpoint_t endpt, cdev_id_t id, int r)
|
|
|
|
{
|
|
|
|
/* Reply to a (read, write, ioctl) task request that was suspended earlier.
|
|
|
|
* Not-so-well-written drivers may use this function to send a reply to a
|
|
|
|
* request that is being processed right now, and then return EDONTREPLY later.
|
|
|
|
*/
|
|
|
|
message m_reply;
|
|
|
|
|
|
|
|
if (r == EDONTREPLY || r == SUSPEND)
|
|
|
|
panic("chardriver: bad task reply: %d", r);
|
|
|
|
|
|
|
|
memset(&m_reply, 0, sizeof(m_reply));
|
|
|
|
|
|
|
|
m_reply.m_type = DEV_REVIVE;
|
|
|
|
m_reply.REP_STATUS = r;
|
|
|
|
m_reply.REP_ENDPT = endpt; /* XXX FIXME: hack */
|
|
|
|
m_reply.REP_IO_GRANT = (cp_grant_id_t) id;
|
|
|
|
|
|
|
|
if ((r = asynsend3(endpt, &m_reply, AMF_NOREPLY)) != OK)
|
|
|
|
printf("chardriver_reply_task: send to %d failed: %d\n", endpt, r);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* chardriver_reply_select *
|
|
|
|
*===========================================================================*/
|
|
|
|
void chardriver_reply_select(endpoint_t endpt, devminor_t minor, int r)
|
|
|
|
{
|
|
|
|
/* Reply to a select request with a status update. This must not be used to
|
|
|
|
* reply to a select request that is being processed right now.
|
|
|
|
*/
|
|
|
|
message m_reply;
|
|
|
|
|
|
|
|
/* Replying with an error is allowed (if unusual). */
|
|
|
|
if (r == EDONTREPLY || r == SUSPEND)
|
|
|
|
panic("chardriver: bad select reply: %d", r);
|
|
|
|
|
|
|
|
memset(&m_reply, 0, sizeof(m_reply));
|
|
|
|
|
|
|
|
m_reply.m_type = DEV_SEL_REPL2;
|
|
|
|
m_reply.DEV_MINOR = minor;
|
|
|
|
m_reply.DEV_SEL_OPS = r;
|
|
|
|
|
|
|
|
if ((r = asynsend3(endpt, &m_reply, AMF_NOREPLY)) != OK)
|
|
|
|
printf("chardriver_reply_select: send to %d failed: %d\n", endpt, r);
|
|
|
|
}
|
|
|
|
|
Split block/character protocols and libdriver
This patch separates the character and block driver communication
protocols. The old character protocol remains the same, but a new
block protocol is introduced. The libdriver library is replaced by
two new libraries: libchardriver and libblockdriver. Their exposed
API, and drivers that use them, have been updated accordingly.
Together, libbdev and libblockdriver now completely abstract away
the message format used by the block protocol. As the memory driver
is both a character and a block device driver, it now implements its
own message loop.
The most important semantic change made to the block protocol is that
it is no longer possible to return both partial results and an error
for a single transfer. This simplifies the interaction between the
caller and the driver, as the I/O vector no longer needs to be copied
back. Also, drivers are now no longer supposed to decide based on the
layout of the I/O vector when a transfer should be cut short. Put
simply, transfers are now supposed to either succeed completely, or
result in an error.
After this patch, the state of the various pieces is as follows:
- block protocol: stable
- libbdev API: stable for synchronous communication
- libblockdriver API: needs slight revision (the drvlib/partition API
in particular; the threading API will also change shortly)
- character protocol: needs cleanup
- libchardriver API: needs cleanup accordingly
- driver restarts: largely unsupported until endpoint changes are
reintroduced
As a side effect, this patch eliminates several bugs, hacks, and gcc
-Wall and -W warnings all over the place. It probably introduces a
few new ones, too.
Update warning: this patch changes the protocol between MFS and disk
drivers, so in order to use old/new images, the MFS from the ramdisk
must be used to mount all file systems.
2011-11-22 13:27:53 +01:00
|
|
|
/*===========================================================================*
|
2013-08-30 11:14:03 +02:00
|
|
|
* send_reply *
|
2009-12-02 10:57:48 +01:00
|
|
|
*===========================================================================*/
|
2013-09-03 01:49:38 +02:00
|
|
|
static void send_reply(endpoint_t endpt, message *m_ptr, int ipc_status)
|
|
|
|
{
|
|
|
|
/* Send a reply message to a request. */
|
|
|
|
int r;
|
|
|
|
|
|
|
|
/* If we would block sending the message, send it asynchronously. */
|
|
|
|
if (IPC_STATUS_CALL(ipc_status) == SENDREC)
|
|
|
|
r = sendnb(endpt, m_ptr);
|
|
|
|
else
|
|
|
|
r = asynsend3(endpt, m_ptr, AMF_NOREPLY);
|
|
|
|
|
|
|
|
if (r != OK)
|
|
|
|
printf("chardriver: unable to send reply to %d: %d\n", endpt, r);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* chardriver_reply *
|
|
|
|
*===========================================================================*/
|
|
|
|
static void chardriver_reply(message *mess, int ipc_status, int r)
|
2009-12-02 10:57:48 +01:00
|
|
|
{
|
2013-08-30 11:14:03 +02:00
|
|
|
/* Prepare and send a reply message. */
|
2009-12-02 10:57:48 +01:00
|
|
|
message reply_mess;
|
|
|
|
|
2013-09-03 01:49:38 +02:00
|
|
|
/* If the EDONTREPLY pseudo-reply is given, we do not reply. This is however
|
|
|
|
* allowed only for blocking task calls. Perform a sanity check.
|
|
|
|
*/
|
|
|
|
if (r == EDONTREPLY) {
|
|
|
|
switch (mess->m_type) {
|
|
|
|
case DEV_READ_S:
|
|
|
|
case DEV_WRITE_S:
|
|
|
|
case DEV_IOCTL_S:
|
|
|
|
#if 0 /* XXX doesn't match lwip's model, disabled for now */
|
|
|
|
if (mess->FLAGS & FLG_OP_NONBLOCK)
|
|
|
|
panic("chardriver: cannot suspend nonblocking I/O");
|
|
|
|
#endif
|
|
|
|
/*fall-through*/
|
|
|
|
case CANCEL:
|
|
|
|
return; /* alright */
|
|
|
|
default:
|
|
|
|
panic("chardriver: cannot suspend request %d", mess->m_type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (r == SUSPEND)
|
|
|
|
panic("chardriver: SUSPEND should not be used anymore");
|
2013-08-30 11:14:03 +02:00
|
|
|
|
|
|
|
/* Do not reply with ERESTART. The only possible caller, VFS, will find out
|
|
|
|
* through other means when we have restarted, and is not (fully) ready to
|
|
|
|
* deal with ERESTART errors.
|
2011-11-02 17:31:38 +01:00
|
|
|
*/
|
|
|
|
if (r == ERESTART)
|
|
|
|
return;
|
|
|
|
|
2012-07-27 17:02:12 +02:00
|
|
|
memset(&reply_mess, 0, sizeof(reply_mess));
|
|
|
|
|
2009-12-02 10:57:48 +01:00
|
|
|
switch (mess->m_type) {
|
|
|
|
case DEV_OPEN:
|
2012-02-09 11:32:08 +01:00
|
|
|
reply_mess.m_type = DEV_OPEN_REPL;
|
2011-11-02 17:31:38 +01:00
|
|
|
reply_mess.REP_ENDPT = mess->USER_ENDPT;
|
2009-12-02 10:57:48 +01:00
|
|
|
reply_mess.REP_STATUS = r;
|
|
|
|
break;
|
|
|
|
|
2013-09-03 01:49:38 +02:00
|
|
|
case DEV_REOPEN:
|
|
|
|
reply_mess.m_type = DEV_REOPEN_REPL;
|
|
|
|
reply_mess.REP_ENDPT = mess->USER_ENDPT;
|
|
|
|
reply_mess.REP_STATUS = r;
|
|
|
|
break;
|
|
|
|
|
2009-12-02 10:57:48 +01:00
|
|
|
case DEV_CLOSE:
|
|
|
|
reply_mess.m_type = DEV_CLOSE_REPL;
|
2011-11-02 17:31:38 +01:00
|
|
|
reply_mess.REP_ENDPT = mess->USER_ENDPT;
|
2009-12-02 10:57:48 +01:00
|
|
|
reply_mess.REP_STATUS = r;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DEV_READ_S:
|
|
|
|
case DEV_WRITE_S:
|
2010-10-08 11:33:18 +02:00
|
|
|
case DEV_IOCTL_S:
|
2013-09-03 01:49:38 +02:00
|
|
|
case CANCEL: /* For CANCEL, this is a reply to the original request! */
|
2009-12-02 10:57:48 +01:00
|
|
|
reply_mess.m_type = DEV_REVIVE;
|
2011-11-02 17:31:38 +01:00
|
|
|
reply_mess.REP_ENDPT = mess->USER_ENDPT;
|
2009-12-02 10:57:48 +01:00
|
|
|
reply_mess.REP_IO_GRANT = (cp_grant_id_t) mess->IO_GRANT;
|
|
|
|
reply_mess.REP_STATUS = r;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DEV_SELECT:
|
|
|
|
reply_mess.m_type = DEV_SEL_REPL1;
|
|
|
|
reply_mess.DEV_MINOR = mess->DEVICE;
|
|
|
|
reply_mess.DEV_SEL_OPS = r;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2013-09-03 01:49:38 +02:00
|
|
|
panic("chardriver: unknown request %d", mess->m_type);
|
2009-12-02 10:57:48 +01:00
|
|
|
}
|
|
|
|
|
2013-09-03 01:49:38 +02:00
|
|
|
send_reply(mess->m_source, &reply_mess, ipc_status);
|
|
|
|
}
|
2011-11-02 17:31:38 +01:00
|
|
|
|
2013-09-03 01:49:38 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* do_open *
|
|
|
|
*===========================================================================*/
|
|
|
|
static int do_open(struct chardriver *cdp, message *m_ptr, int is_reopen)
|
|
|
|
{
|
|
|
|
/* Open a minor device. */
|
|
|
|
endpoint_t user_endpt;
|
|
|
|
devminor_t minor;
|
|
|
|
int r, access;
|
|
|
|
|
|
|
|
/* Default action if no open hook is in place. */
|
|
|
|
if (cdp->cdr_open == NULL)
|
|
|
|
return OK;
|
|
|
|
|
|
|
|
/* Call the open hook. */
|
|
|
|
minor = m_ptr->DEVICE;
|
|
|
|
access = m_ptr->COUNT;
|
|
|
|
user_endpt = is_reopen ? NONE : m_ptr->USER_ENDPT; /* XXX FIXME */
|
|
|
|
|
|
|
|
r = cdp->cdr_open(minor, access, user_endpt);
|
|
|
|
|
|
|
|
/* If the device has been cloned, mark the new minor as open too. */
|
|
|
|
if (r >= 0 && !is_open_dev(r)) /* XXX FIXME */
|
|
|
|
set_open_dev(r);
|
|
|
|
|
|
|
|
return r;
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
2013-09-03 01:49:38 +02:00
|
|
|
* do_close *
|
2005-04-21 16:53:53 +02:00
|
|
|
*===========================================================================*/
|
2013-09-03 01:49:38 +02:00
|
|
|
static int do_close(struct chardriver *cdp, message *m_ptr)
|
2005-04-21 16:53:53 +02:00
|
|
|
{
|
2013-09-03 01:49:38 +02:00
|
|
|
/* Close a minor device. */
|
|
|
|
devminor_t minor;
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2013-09-03 01:49:38 +02:00
|
|
|
/* Default action if no close hook is in place. */
|
|
|
|
if (cdp->cdr_close == NULL)
|
|
|
|
return OK;
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2013-09-03 01:49:38 +02:00
|
|
|
/* Call the close hook. */
|
|
|
|
minor = m_ptr->DEVICE;
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2013-09-03 01:49:38 +02:00
|
|
|
return cdp->cdr_close(minor);
|
|
|
|
}
|
2006-06-20 10:49:51 +02:00
|
|
|
|
2013-09-03 01:49:38 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* do_trasnfer *
|
|
|
|
*===========================================================================*/
|
|
|
|
static int do_transfer(struct chardriver *cdp, message *m_ptr, int do_write)
|
|
|
|
{
|
|
|
|
/* Carry out a read or write task request. */
|
|
|
|
devminor_t minor;
|
|
|
|
u64_t position;
|
|
|
|
endpoint_t endpt;
|
|
|
|
cp_grant_id_t grant;
|
|
|
|
size_t size;
|
|
|
|
int flags;
|
|
|
|
cdev_id_t id;
|
|
|
|
ssize_t r;
|
|
|
|
|
|
|
|
minor = m_ptr->DEVICE;
|
|
|
|
position = make64(m_ptr->POSITION, m_ptr->HIGHPOS);
|
|
|
|
endpt = m_ptr->m_source;
|
|
|
|
grant = (cp_grant_id_t) m_ptr->IO_GRANT;
|
|
|
|
size = m_ptr->COUNT;
|
|
|
|
flags = m_ptr->FLAGS;
|
|
|
|
id = (cdev_id_t) m_ptr->IO_GRANT;
|
|
|
|
|
|
|
|
/* Call the read/write hook, if the appropriate one is in place. */
|
|
|
|
if (!do_write && cdp->cdr_read != NULL)
|
|
|
|
r = cdp->cdr_read(minor, position, endpt, grant, size, flags, id);
|
|
|
|
else if (do_write && cdp->cdr_write != NULL)
|
|
|
|
r = cdp->cdr_write(minor, position, endpt, grant, size, flags, id);
|
|
|
|
else
|
|
|
|
r = EIO; /* Default action if no read/write hook is in place. */
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2013-09-03 01:49:38 +02:00
|
|
|
return r;
|
|
|
|
}
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2013-09-03 01:49:38 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* do_ioctl *
|
|
|
|
*===========================================================================*/
|
|
|
|
static int do_ioctl(struct chardriver *cdp, message *m_ptr)
|
|
|
|
{
|
|
|
|
/* Carry out an I/O control task request. */
|
|
|
|
devminor_t minor;
|
|
|
|
unsigned long request;
|
|
|
|
cp_grant_id_t grant;
|
|
|
|
endpoint_t endpt, user_endpt;
|
|
|
|
int flags;
|
|
|
|
cdev_id_t id;
|
|
|
|
|
|
|
|
/* Default action if no ioctl hook is in place. */
|
|
|
|
if (cdp->cdr_ioctl == NULL)
|
|
|
|
return ENOTTY;
|
|
|
|
|
|
|
|
/* Call the ioctl hook. */
|
|
|
|
minor = m_ptr->DEVICE;
|
|
|
|
request = m_ptr->REQUEST;
|
|
|
|
endpt = m_ptr->m_source;
|
|
|
|
grant = (cp_grant_id_t) m_ptr->IO_GRANT;
|
|
|
|
flags = m_ptr->FLAGS;
|
|
|
|
user_endpt = (endpoint_t) m_ptr->POSITION;
|
|
|
|
id = (cdev_id_t) m_ptr->IO_GRANT;
|
|
|
|
|
|
|
|
return cdp->cdr_ioctl(minor, request, endpt, grant, flags, user_endpt, id);
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
2011-11-02 17:31:38 +01:00
|
|
|
/*===========================================================================*
|
2013-09-03 01:49:38 +02:00
|
|
|
* do_cancel *
|
2011-11-02 17:31:38 +01:00
|
|
|
*===========================================================================*/
|
2013-09-03 01:49:38 +02:00
|
|
|
static int do_cancel(struct chardriver *cdp, message *m_ptr)
|
2005-04-21 16:53:53 +02:00
|
|
|
{
|
2013-09-03 01:49:38 +02:00
|
|
|
/* Cancel a suspended (read, write, ioctl) task request. The original request
|
|
|
|
* may already have finished, in which case no reply should be sent.
|
2005-04-21 16:53:53 +02:00
|
|
|
*/
|
2013-09-03 01:49:38 +02:00
|
|
|
devminor_t minor;
|
|
|
|
endpoint_t endpt;
|
|
|
|
cdev_id_t id;
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2013-09-03 01:49:38 +02:00
|
|
|
/* Default action if no cancel hook is in place: let the request finish. */
|
|
|
|
if (cdp->cdr_cancel == NULL)
|
|
|
|
return EDONTREPLY;
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2013-09-03 01:49:38 +02:00
|
|
|
/* Call the cancel hook. */
|
|
|
|
minor = m_ptr->DEVICE;
|
|
|
|
endpt = m_ptr->m_source;
|
|
|
|
id = (cdev_id_t) m_ptr->IO_GRANT;
|
2009-12-02 10:57:48 +01:00
|
|
|
|
2013-09-03 01:49:38 +02:00
|
|
|
return cdp->cdr_cancel(minor, endpt, id);
|
|
|
|
}
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2013-09-03 01:49:38 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* do_select *
|
|
|
|
*===========================================================================*/
|
|
|
|
static int do_select(struct chardriver *cdp, message *m_ptr)
|
|
|
|
{
|
|
|
|
/* Perform a select query on a minor device. */
|
|
|
|
devminor_t minor;
|
|
|
|
unsigned int ops;
|
|
|
|
endpoint_t endpt;
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2013-09-03 01:49:38 +02:00
|
|
|
/* Default action if no select hook is in place. */
|
|
|
|
if (cdp->cdr_select == NULL)
|
|
|
|
return EBADF;
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2013-09-03 01:49:38 +02:00
|
|
|
/* Call the select hook. */
|
|
|
|
minor = m_ptr->DEV_MINOR;
|
|
|
|
ops = m_ptr->DEV_SEL_OPS;
|
|
|
|
endpt = m_ptr->m_source;
|
2006-06-20 10:49:51 +02:00
|
|
|
|
2013-09-03 01:49:38 +02:00
|
|
|
return cdp->cdr_select(minor, ops, endpt);
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
2011-11-02 17:31:38 +01:00
|
|
|
/*===========================================================================*
|
2013-09-03 01:49:38 +02:00
|
|
|
* do_block_open *
|
2011-11-02 17:31:38 +01:00
|
|
|
*===========================================================================*/
|
2013-09-03 01:49:38 +02:00
|
|
|
static void do_block_open(message *m_ptr, int ipc_status)
|
2011-11-02 17:31:38 +01:00
|
|
|
{
|
2013-09-03 01:49:38 +02:00
|
|
|
/* Reply to a block driver open request stating there is no such device. */
|
|
|
|
message m_reply;
|
2011-11-02 17:31:38 +01:00
|
|
|
|
2013-09-03 01:49:38 +02:00
|
|
|
memset(&m_reply, 0, sizeof(m_reply));
|
2011-11-02 17:31:38 +01:00
|
|
|
|
2013-09-03 01:49:38 +02:00
|
|
|
m_reply.m_type = BDEV_REPLY;
|
|
|
|
m_reply.BDEV_STATUS = ENXIO;
|
|
|
|
m_reply.BDEV_ID = m_ptr->BDEV_ID;
|
|
|
|
|
|
|
|
send_reply(m_ptr->m_source, &m_reply, ipc_status);
|
2011-11-02 17:31:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
2013-09-03 01:49:38 +02:00
|
|
|
* chardriver_process *
|
2011-11-02 17:31:38 +01:00
|
|
|
*===========================================================================*/
|
2013-09-03 01:49:38 +02:00
|
|
|
void chardriver_process(struct chardriver *cdp, message *m_ptr, int ipc_status)
|
2011-11-02 17:31:38 +01:00
|
|
|
{
|
2013-09-03 01:49:38 +02:00
|
|
|
/* Call the appropiate driver function, based on the type of request. Send a
|
|
|
|
* reply to the caller if necessary.
|
2011-11-02 17:31:38 +01:00
|
|
|
*/
|
2013-09-03 01:49:38 +02:00
|
|
|
int r, reply;
|
|
|
|
|
|
|
|
/* Check for notifications first. We never reply to notifications. */
|
|
|
|
if (is_ipc_notify(ipc_status)) {
|
|
|
|
switch (_ENDPOINT_P(m_ptr->m_source)) {
|
|
|
|
case HARDWARE:
|
|
|
|
if (cdp->cdr_intr)
|
|
|
|
cdp->cdr_intr(m_ptr->NOTIFY_ARG);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CLOCK:
|
|
|
|
if (cdp->cdr_alarm)
|
|
|
|
cdp->cdr_alarm(m_ptr->NOTIFY_TIMESTAMP);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (cdp->cdr_other)
|
|
|
|
cdp->cdr_other(m_ptr, ipc_status);
|
|
|
|
}
|
|
|
|
|
|
|
|
return; /* do not send a reply */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reply to block driver open requests with an error code. Otherwise, if
|
|
|
|
* someone creates a block device node for a character driver, opening that
|
|
|
|
* device node will cause the corresponding VFS thread to block forever.
|
|
|
|
*/
|
|
|
|
if (m_ptr->m_type == BDEV_OPEN) {
|
|
|
|
do_block_open(m_ptr, ipc_status);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2011-11-02 17:31:38 +01:00
|
|
|
|
|
|
|
/* We might get spurious requests if the driver has been restarted. Deny any
|
2013-09-03 01:49:38 +02:00
|
|
|
* requests on devices that have not previously been opened.
|
2011-11-02 17:31:38 +01:00
|
|
|
*/
|
2013-08-30 11:14:03 +02:00
|
|
|
if (IS_DEV_RQ(m_ptr->m_type) && !is_open_dev(m_ptr->DEVICE)) {
|
2013-09-03 01:49:38 +02:00
|
|
|
/* Ignore spurious requests for unopened devices. */
|
|
|
|
if (m_ptr->m_type != DEV_OPEN && m_ptr->m_type != DEV_REOPEN)
|
|
|
|
return; /* do not send a reply */
|
2011-11-02 17:31:38 +01:00
|
|
|
|
|
|
|
/* Mark the device as opened otherwise. */
|
|
|
|
set_open_dev(m_ptr->DEVICE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Call the appropriate function(s) for this request. */
|
|
|
|
switch (m_ptr->m_type) {
|
2013-09-03 01:49:38 +02:00
|
|
|
case DEV_OPEN: r = do_open(cdp, m_ptr, FALSE); break;
|
|
|
|
case DEV_REOPEN: r = do_open(cdp, m_ptr, TRUE); break;
|
|
|
|
case DEV_CLOSE: r = do_close(cdp, m_ptr); break;
|
|
|
|
case DEV_READ_S: r = do_transfer(cdp, m_ptr, FALSE); break;
|
|
|
|
case DEV_WRITE_S: r = do_transfer(cdp, m_ptr, TRUE); break;
|
|
|
|
case DEV_IOCTL_S: r = do_ioctl(cdp, m_ptr); break;
|
|
|
|
case CANCEL: r = do_cancel(cdp, m_ptr); break;
|
|
|
|
case DEV_SELECT: r = do_select(cdp, m_ptr); break;
|
2011-11-02 17:31:38 +01:00
|
|
|
default:
|
Split block/character protocols and libdriver
This patch separates the character and block driver communication
protocols. The old character protocol remains the same, but a new
block protocol is introduced. The libdriver library is replaced by
two new libraries: libchardriver and libblockdriver. Their exposed
API, and drivers that use them, have been updated accordingly.
Together, libbdev and libblockdriver now completely abstract away
the message format used by the block protocol. As the memory driver
is both a character and a block device driver, it now implements its
own message loop.
The most important semantic change made to the block protocol is that
it is no longer possible to return both partial results and an error
for a single transfer. This simplifies the interaction between the
caller and the driver, as the I/O vector no longer needs to be copied
back. Also, drivers are now no longer supposed to decide based on the
layout of the I/O vector when a transfer should be cut short. Put
simply, transfers are now supposed to either succeed completely, or
result in an error.
After this patch, the state of the various pieces is as follows:
- block protocol: stable
- libbdev API: stable for synchronous communication
- libblockdriver API: needs slight revision (the drvlib/partition API
in particular; the threading API will also change shortly)
- character protocol: needs cleanup
- libchardriver API: needs cleanup accordingly
- driver restarts: largely unsupported until endpoint changes are
reintroduced
As a side effect, this patch eliminates several bugs, hacks, and gcc
-Wall and -W warnings all over the place. It probably introduces a
few new ones, too.
Update warning: this patch changes the protocol between MFS and disk
drivers, so in order to use old/new images, the MFS from the ramdisk
must be used to mount all file systems.
2011-11-22 13:27:53 +01:00
|
|
|
if (cdp->cdr_other)
|
2013-09-03 01:49:38 +02:00
|
|
|
cdp->cdr_other(m_ptr, ipc_status);
|
|
|
|
return; /* do not send a reply */
|
2011-11-02 17:31:38 +01:00
|
|
|
}
|
|
|
|
|
2013-09-03 01:49:38 +02:00
|
|
|
chardriver_reply(m_ptr, ipc_status, r);
|
2011-11-02 17:31:38 +01:00
|
|
|
}
|
|
|
|
|
2005-04-21 16:53:53 +02:00
|
|
|
/*===========================================================================*
|
2013-09-03 01:49:38 +02:00
|
|
|
* chardriver_terminate *
|
2005-04-21 16:53:53 +02:00
|
|
|
*===========================================================================*/
|
2013-09-03 01:49:38 +02:00
|
|
|
void chardriver_terminate(void)
|
2005-04-21 16:53:53 +02:00
|
|
|
{
|
2013-09-03 01:49:38 +02:00
|
|
|
/* Break out of the main loop after finishing the current request. */
|
Split block/character protocols and libdriver
This patch separates the character and block driver communication
protocols. The old character protocol remains the same, but a new
block protocol is introduced. The libdriver library is replaced by
two new libraries: libchardriver and libblockdriver. Their exposed
API, and drivers that use them, have been updated accordingly.
Together, libbdev and libblockdriver now completely abstract away
the message format used by the block protocol. As the memory driver
is both a character and a block device driver, it now implements its
own message loop.
The most important semantic change made to the block protocol is that
it is no longer possible to return both partial results and an error
for a single transfer. This simplifies the interaction between the
caller and the driver, as the I/O vector no longer needs to be copied
back. Also, drivers are now no longer supposed to decide based on the
layout of the I/O vector when a transfer should be cut short. Put
simply, transfers are now supposed to either succeed completely, or
result in an error.
After this patch, the state of the various pieces is as follows:
- block protocol: stable
- libbdev API: stable for synchronous communication
- libblockdriver API: needs slight revision (the drvlib/partition API
in particular; the threading API will also change shortly)
- character protocol: needs cleanup
- libchardriver API: needs cleanup accordingly
- driver restarts: largely unsupported until endpoint changes are
reintroduced
As a side effect, this patch eliminates several bugs, hacks, and gcc
-Wall and -W warnings all over the place. It probably introduces a
few new ones, too.
Update warning: this patch changes the protocol between MFS and disk
drivers, so in order to use old/new images, the MFS from the ramdisk
must be used to mount all file systems.
2011-11-22 13:27:53 +01:00
|
|
|
|
2013-09-03 01:49:38 +02:00
|
|
|
running = FALSE;
|
Split block/character protocols and libdriver
This patch separates the character and block driver communication
protocols. The old character protocol remains the same, but a new
block protocol is introduced. The libdriver library is replaced by
two new libraries: libchardriver and libblockdriver. Their exposed
API, and drivers that use them, have been updated accordingly.
Together, libbdev and libblockdriver now completely abstract away
the message format used by the block protocol. As the memory driver
is both a character and a block device driver, it now implements its
own message loop.
The most important semantic change made to the block protocol is that
it is no longer possible to return both partial results and an error
for a single transfer. This simplifies the interaction between the
caller and the driver, as the I/O vector no longer needs to be copied
back. Also, drivers are now no longer supposed to decide based on the
layout of the I/O vector when a transfer should be cut short. Put
simply, transfers are now supposed to either succeed completely, or
result in an error.
After this patch, the state of the various pieces is as follows:
- block protocol: stable
- libbdev API: stable for synchronous communication
- libblockdriver API: needs slight revision (the drvlib/partition API
in particular; the threading API will also change shortly)
- character protocol: needs cleanup
- libchardriver API: needs cleanup accordingly
- driver restarts: largely unsupported until endpoint changes are
reintroduced
As a side effect, this patch eliminates several bugs, hacks, and gcc
-Wall and -W warnings all over the place. It probably introduces a
few new ones, too.
Update warning: this patch changes the protocol between MFS and disk
drivers, so in order to use old/new images, the MFS from the ramdisk
must be used to mount all file systems.
2011-11-22 13:27:53 +01:00
|
|
|
|
2013-09-03 01:49:38 +02:00
|
|
|
sef_cancel();
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
|
2011-11-02 17:31:38 +01:00
|
|
|
/*===========================================================================*
|
Split block/character protocols and libdriver
This patch separates the character and block driver communication
protocols. The old character protocol remains the same, but a new
block protocol is introduced. The libdriver library is replaced by
two new libraries: libchardriver and libblockdriver. Their exposed
API, and drivers that use them, have been updated accordingly.
Together, libbdev and libblockdriver now completely abstract away
the message format used by the block protocol. As the memory driver
is both a character and a block device driver, it now implements its
own message loop.
The most important semantic change made to the block protocol is that
it is no longer possible to return both partial results and an error
for a single transfer. This simplifies the interaction between the
caller and the driver, as the I/O vector no longer needs to be copied
back. Also, drivers are now no longer supposed to decide based on the
layout of the I/O vector when a transfer should be cut short. Put
simply, transfers are now supposed to either succeed completely, or
result in an error.
After this patch, the state of the various pieces is as follows:
- block protocol: stable
- libbdev API: stable for synchronous communication
- libblockdriver API: needs slight revision (the drvlib/partition API
in particular; the threading API will also change shortly)
- character protocol: needs cleanup
- libchardriver API: needs cleanup accordingly
- driver restarts: largely unsupported until endpoint changes are
reintroduced
As a side effect, this patch eliminates several bugs, hacks, and gcc
-Wall and -W warnings all over the place. It probably introduces a
few new ones, too.
Update warning: this patch changes the protocol between MFS and disk
drivers, so in order to use old/new images, the MFS from the ramdisk
must be used to mount all file systems.
2011-11-22 13:27:53 +01:00
|
|
|
* chardriver_task *
|
2011-11-02 17:31:38 +01:00
|
|
|
*===========================================================================*/
|
2013-08-30 11:14:03 +02:00
|
|
|
void chardriver_task(struct chardriver *cdp)
|
2005-04-21 16:53:53 +02:00
|
|
|
{
|
Split block/character protocols and libdriver
This patch separates the character and block driver communication
protocols. The old character protocol remains the same, but a new
block protocol is introduced. The libdriver library is replaced by
two new libraries: libchardriver and libblockdriver. Their exposed
API, and drivers that use them, have been updated accordingly.
Together, libbdev and libblockdriver now completely abstract away
the message format used by the block protocol. As the memory driver
is both a character and a block device driver, it now implements its
own message loop.
The most important semantic change made to the block protocol is that
it is no longer possible to return both partial results and an error
for a single transfer. This simplifies the interaction between the
caller and the driver, as the I/O vector no longer needs to be copied
back. Also, drivers are now no longer supposed to decide based on the
layout of the I/O vector when a transfer should be cut short. Put
simply, transfers are now supposed to either succeed completely, or
result in an error.
After this patch, the state of the various pieces is as follows:
- block protocol: stable
- libbdev API: stable for synchronous communication
- libblockdriver API: needs slight revision (the drvlib/partition API
in particular; the threading API will also change shortly)
- character protocol: needs cleanup
- libchardriver API: needs cleanup accordingly
- driver restarts: largely unsupported until endpoint changes are
reintroduced
As a side effect, this patch eliminates several bugs, hacks, and gcc
-Wall and -W warnings all over the place. It probably introduces a
few new ones, too.
Update warning: this patch changes the protocol between MFS and disk
drivers, so in order to use old/new images, the MFS from the ramdisk
must be used to mount all file systems.
2011-11-22 13:27:53 +01:00
|
|
|
/* Main program of any device driver task. */
|
|
|
|
int r, ipc_status;
|
|
|
|
message mess;
|
|
|
|
|
|
|
|
running = TRUE;
|
|
|
|
|
|
|
|
/* Here is the main loop of the disk task. It waits for a message, carries
|
|
|
|
* it out, and sends a reply.
|
|
|
|
*/
|
|
|
|
while (running) {
|
2013-09-03 01:49:38 +02:00
|
|
|
if ((r = sef_receive_status(ANY, &mess, &ipc_status)) != OK) {
|
|
|
|
if (r == EINTR && !running)
|
|
|
|
break;
|
|
|
|
|
Split block/character protocols and libdriver
This patch separates the character and block driver communication
protocols. The old character protocol remains the same, but a new
block protocol is introduced. The libdriver library is replaced by
two new libraries: libchardriver and libblockdriver. Their exposed
API, and drivers that use them, have been updated accordingly.
Together, libbdev and libblockdriver now completely abstract away
the message format used by the block protocol. As the memory driver
is both a character and a block device driver, it now implements its
own message loop.
The most important semantic change made to the block protocol is that
it is no longer possible to return both partial results and an error
for a single transfer. This simplifies the interaction between the
caller and the driver, as the I/O vector no longer needs to be copied
back. Also, drivers are now no longer supposed to decide based on the
layout of the I/O vector when a transfer should be cut short. Put
simply, transfers are now supposed to either succeed completely, or
result in an error.
After this patch, the state of the various pieces is as follows:
- block protocol: stable
- libbdev API: stable for synchronous communication
- libblockdriver API: needs slight revision (the drvlib/partition API
in particular; the threading API will also change shortly)
- character protocol: needs cleanup
- libchardriver API: needs cleanup accordingly
- driver restarts: largely unsupported until endpoint changes are
reintroduced
As a side effect, this patch eliminates several bugs, hacks, and gcc
-Wall and -W warnings all over the place. It probably introduces a
few new ones, too.
Update warning: this patch changes the protocol between MFS and disk
drivers, so in order to use old/new images, the MFS from the ramdisk
must be used to mount all file systems.
2011-11-22 13:27:53 +01:00
|
|
|
panic("driver_receive failed: %d", r);
|
2013-09-03 01:49:38 +02:00
|
|
|
}
|
Split block/character protocols and libdriver
This patch separates the character and block driver communication
protocols. The old character protocol remains the same, but a new
block protocol is introduced. The libdriver library is replaced by
two new libraries: libchardriver and libblockdriver. Their exposed
API, and drivers that use them, have been updated accordingly.
Together, libbdev and libblockdriver now completely abstract away
the message format used by the block protocol. As the memory driver
is both a character and a block device driver, it now implements its
own message loop.
The most important semantic change made to the block protocol is that
it is no longer possible to return both partial results and an error
for a single transfer. This simplifies the interaction between the
caller and the driver, as the I/O vector no longer needs to be copied
back. Also, drivers are now no longer supposed to decide based on the
layout of the I/O vector when a transfer should be cut short. Put
simply, transfers are now supposed to either succeed completely, or
result in an error.
After this patch, the state of the various pieces is as follows:
- block protocol: stable
- libbdev API: stable for synchronous communication
- libblockdriver API: needs slight revision (the drvlib/partition API
in particular; the threading API will also change shortly)
- character protocol: needs cleanup
- libchardriver API: needs cleanup accordingly
- driver restarts: largely unsupported until endpoint changes are
reintroduced
As a side effect, this patch eliminates several bugs, hacks, and gcc
-Wall and -W warnings all over the place. It probably introduces a
few new ones, too.
Update warning: this patch changes the protocol between MFS and disk
drivers, so in order to use old/new images, the MFS from the ramdisk
must be used to mount all file systems.
2011-11-22 13:27:53 +01:00
|
|
|
|
2013-08-30 11:14:03 +02:00
|
|
|
chardriver_process(cdp, &mess, ipc_status);
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
|
|
|
}
|