Message type for CDEV_{READ,WRITE,IOCTL}

Change-Id: Ia89c98410d3775fe3b6621576eadd186d60ec894
This commit is contained in:
Lionel Sambuc 2014-06-06 13:00:39 +02:00
parent ca7231fbef
commit b41d3ab74e
4 changed files with 42 additions and 36 deletions

View file

@ -1009,16 +1009,6 @@
#define CDEV_SEL1_REPLY (CDEV_RS_BASE + 1) /* immediate select reply */
#define CDEV_SEL2_REPLY (CDEV_RS_BASE + 2) /* select notification reply */
/* Field names for block device messages. */
#define CDEV_MINOR m10_i1 /* minor device number */
#define CDEV_GRANT m10_i2 /* grant ID of buffer */
#define CDEV_COUNT m10_i3 /* number of bytes to transfer */
#define CDEV_USER m10_i3 /* endpoint of user process */
#define CDEV_FLAGS m10_i4 /* transfer flags */
#define CDEV_ID m10_l1 /* opaque request ID */
#define CDEV_REQUEST m10_l2 /* I/O control request */
#define CDEV_POS m10_ull1 /* transfer position */
/* Bits in 'CDEV_ACCESS' field of block device open requests. */
# define CDEV_R_BIT 0x01 /* open with read access */
# define CDEV_W_BIT 0x02 /* open with write access */

View file

@ -1592,6 +1592,20 @@ typedef struct {
} mess_vfs_lchardriver_openclose;
_ASSERT_MSG_SIZE(mess_vfs_lchardriver_openclose);
typedef struct {
off_t pos;
cp_grant_id_t grant;
size_t count;
int request;
int flags;
endpoint_t id;
endpoint_t user;
devminor_t minor;
uint8_t padding[20];
} mess_vfs_lchardriver_readwrite;
_ASSERT_MSG_SIZE(mess_vfs_lchardriver_readwrite);
typedef struct {
devminor_t minor;
int ops;
@ -1889,6 +1903,7 @@ typedef struct {
mess_vfs_lchardriver_cancel m_vfs_lchardriver_cancel;
mess_vfs_lchardriver_openclose m_vfs_lchardriver_openclose;
mess_vfs_lchardriver_readwrite m_vfs_lchardriver_readwrite;
mess_vfs_lchardriver_select m_vfs_lchardriver_select;
mess_vfs_utimens m_vfs_utimens;

View file

@ -205,13 +205,13 @@ static void chardriver_reply(message *mess, int ipc_status, int r)
case CDEV_READ:
case CDEV_WRITE:
case CDEV_IOCTL:
/* FIXME: we should be able to check CDEV_FLAGS against
/* FIXME: we should be able to check FLAGS against
* CDEV_NONBLOCK here, but in practice, several drivers do not
* send a reply through this path (eg TTY) or simply do not
* implement nonblocking calls properly (eg audio, LWIP).
*/
#if 0
if (mess->CDEV_FLAGS & CDEV_NONBLOCK)
if (mess->m_vfs_lchardriver_readwrite.flags & CDEV_NONBLOCK)
panic("chardriver: cannot suspend nonblocking I/O");
#endif
/*fall-through*/
@ -248,7 +248,8 @@ static void chardriver_reply(message *mess, int ipc_status, int r)
case CDEV_IOCTL:
reply_mess.m_type = CDEV_REPLY;
reply_mess.m_lchardriver_vfs_reply.status = r;
reply_mess.m_lchardriver_vfs_reply.id = mess->CDEV_ID;
reply_mess.m_lchardriver_vfs_reply.id =
mess->m_vfs_lchardriver_readwrite.id;
break;
case CDEV_CANCEL: /* For cancel, this is a reply to the original request! */
@ -328,7 +329,7 @@ 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;
off_t position;
endpoint_t endpt;
cp_grant_id_t grant;
size_t size;
@ -336,13 +337,13 @@ static int do_transfer(struct chardriver *cdp, message *m_ptr, int do_write)
cdev_id_t id;
ssize_t r;
minor = m_ptr->CDEV_MINOR;
position = m_ptr->CDEV_POS;
minor = m_ptr->m_vfs_lchardriver_readwrite.minor;
position = m_ptr->m_vfs_lchardriver_readwrite.pos;
endpt = m_ptr->m_source;
grant = (cp_grant_id_t) m_ptr->CDEV_GRANT;
size = m_ptr->CDEV_COUNT;
flags = m_ptr->CDEV_FLAGS;
id = m_ptr->CDEV_ID;
grant = m_ptr->m_vfs_lchardriver_readwrite.grant;
size = m_ptr->m_vfs_lchardriver_readwrite.count;
flags = m_ptr->m_vfs_lchardriver_readwrite.flags;
id = m_ptr->m_vfs_lchardriver_readwrite.id;
/* Call the read/write hook, if the appropriate one is in place. */
if (!do_write && cdp->cdr_read != NULL)
@ -373,13 +374,13 @@ static int do_ioctl(struct chardriver *cdp, message *m_ptr)
return ENOTTY;
/* Call the ioctl hook. */
minor = m_ptr->CDEV_MINOR;
request = m_ptr->CDEV_REQUEST;
minor = m_ptr->m_vfs_lchardriver_readwrite.minor;
request = m_ptr->m_vfs_lchardriver_readwrite.request;
endpt = m_ptr->m_source;
grant = m_ptr->CDEV_GRANT;
flags = m_ptr->CDEV_FLAGS;
user_endpt = m_ptr->CDEV_USER;
id = m_ptr->CDEV_ID;
grant = m_ptr->m_vfs_lchardriver_readwrite.grant;
flags = m_ptr->m_vfs_lchardriver_readwrite.flags;
user_endpt = m_ptr->m_vfs_lchardriver_readwrite.user;
id = m_ptr->m_vfs_lchardriver_readwrite.id;
return cdp->cdr_ioctl(minor, request, endpt, grant, flags, user_endpt, id);
}
@ -589,7 +590,7 @@ int chardriver_get_minor(message *m, devminor_t *minor)
case CDEV_READ:
case CDEV_WRITE:
case CDEV_IOCTL:
*minor = m->CDEV_MINOR;
*minor = m->m_vfs_lchardriver_readwrite.minor;
return OK;
default:
return EINVAL;

View file

@ -281,19 +281,19 @@ int cdev_io(
/* Set up the rest of the message that will be sent to the driver. */
memset(&dev_mess, 0, sizeof(dev_mess));
dev_mess.m_type = op;
dev_mess.CDEV_MINOR = minor_dev;
dev_mess.m_vfs_lchardriver_readwrite.minor = minor_dev;
if (op == CDEV_IOCTL) {
dev_mess.CDEV_REQUEST = bytes;
dev_mess.CDEV_USER = proc_e;
dev_mess.m_vfs_lchardriver_readwrite.request = bytes;
dev_mess.m_vfs_lchardriver_readwrite.user = proc_e;
} else {
dev_mess.CDEV_POS = pos;
dev_mess.CDEV_COUNT = (size_t) bytes;
dev_mess.m_vfs_lchardriver_readwrite.pos = pos;
dev_mess.m_vfs_lchardriver_readwrite.count = bytes;
}
dev_mess.CDEV_ID = proc_e;
dev_mess.CDEV_GRANT = gid;
dev_mess.CDEV_FLAGS = 0;
dev_mess.m_vfs_lchardriver_readwrite.id = proc_e;
dev_mess.m_vfs_lchardriver_readwrite.grant = gid;
dev_mess.m_vfs_lchardriver_readwrite.flags = 0;
if (flags & O_NONBLOCK)
dev_mess.CDEV_FLAGS |= CDEV_NONBLOCK;
dev_mess.m_vfs_lchardriver_readwrite.flags |= CDEV_NONBLOCK;
/* Send the request to the driver. */
if ((r = asynsend3(dp->dmap_driver, &dev_mess, AMF_NOREPLY)) != OK)