I2C: change BUSC_I2C_xxx to use own protocol

Previously it would use bits of the character driver protocol, which
will change heavily.  In the new situation, the BUSC_I2C_xxx requests
use a protocol more in line with the PCI protocol, with the reply code
in m_type.

Change-Id: I51597b3f191078c8178ce17372de123031f7a4c4
This commit is contained in:
David van Moolenbroek 2013-09-02 13:45:02 +02:00 committed by Lionel Sambuc
parent 4211c5d267
commit 660d34cd85
3 changed files with 21 additions and 18 deletions

View file

@ -34,7 +34,7 @@ static void update_reservation(endpoint_t endpt, char *key);
static void ds_event(void); static void ds_event(void);
static int validate_ioctl_exec(minix_i2c_ioctl_exec_t * ioctl_exec); static int validate_ioctl_exec(minix_i2c_ioctl_exec_t * ioctl_exec);
static int do_i2c_ioctl_exec(message * m); static int do_i2c_ioctl_exec(endpoint_t caller, cp_grant_id_t grant_nr);
static int env_parse_instance(void); static int env_parse_instance(void);
@ -253,16 +253,11 @@ validate_ioctl_exec(minix_i2c_ioctl_exec_t * ioctl_exec)
* Performs the action in minix_i2c_ioctl_exec_t. * Performs the action in minix_i2c_ioctl_exec_t.
*/ */
static int static int
do_i2c_ioctl_exec(message * m) do_i2c_ioctl_exec(endpoint_t caller, cp_grant_id_t grant_nr)
{ {
int r; int r;
endpoint_t caller;
cp_grant_id_t grant_nr;
minix_i2c_ioctl_exec_t ioctl_exec; minix_i2c_ioctl_exec_t ioctl_exec;
caller = (endpoint_t) m->m_source;
grant_nr = (cp_grant_id_t) m->IO_GRANT;
/* Copy the requested exection into the driver */ /* Copy the requested exection into the driver */
r = sys_safecopyfrom(caller, grant_nr, (vir_bytes) 0, r = sys_safecopyfrom(caller, grant_nr, (vir_bytes) 0,
(vir_bytes) & ioctl_exec, sizeof(ioctl_exec)); (vir_bytes) & ioctl_exec, sizeof(ioctl_exec));
@ -310,7 +305,7 @@ i2c_ioctl(message * m)
switch (m->COUNT) { switch (m->COUNT) {
case MINIX_I2C_IOCTL_EXEC: case MINIX_I2C_IOCTL_EXEC:
r = do_i2c_ioctl_exec(m); r = do_i2c_ioctl_exec(m->m_source, (cp_grant_id_t)m->IO_GRANT);
break; break;
default: default:
log_warn(&log, "Invalid ioctl() 0x%x\n", m->COUNT); log_warn(&log, "Invalid ioctl() 0x%x\n", m->COUNT);
@ -324,25 +319,24 @@ i2c_ioctl(message * m)
int int
i2c_other(message * m) i2c_other(message * m)
{ {
message m_reply;
int r; int r;
switch (m->m_type) { switch (m->m_type) {
case BUSC_I2C_RESERVE: case BUSC_I2C_RESERVE:
/* reserve a device on the bus for exclusive access */ /* reserve a device on the bus for exclusive access */
r = do_reserve((endpoint_t) m->m_source, m->DEVICE); r = do_reserve(m->m_source, m->BUSC_I2C_ADDR);
break; break;
case BUSC_I2C_EXEC: case BUSC_I2C_EXEC:
/* handle request from another driver */ /* handle request from another driver */
m->COUNT = MINIX_I2C_IOCTL_EXEC; r = do_i2c_ioctl_exec(m->m_source, m->BUSC_I2C_GRANT);
r = do_i2c_ioctl_exec(m);
break; break;
case NOTIFY_MESSAGE: case NOTIFY_MESSAGE:
/* handle notifications about drivers changing state */ /* handle notifications about drivers changing state */
if (m->m_source == DS_PROC_NR) { if (m->m_source == DS_PROC_NR) {
ds_event(); ds_event();
} }
r = OK; return EDONTREPLY;
break;
default: default:
log_warn(&log, "Invalid message type (0x%x)\n", m->m_type); log_warn(&log, "Invalid message type (0x%x)\n", m->m_type);
r = EINVAL; r = EINVAL;
@ -351,7 +345,14 @@ i2c_other(message * m)
log_trace(&log, "i2c_other() returning r=%d\n", r); log_trace(&log, "i2c_other() returning r=%d\n", r);
return r; /* We cannot use libchardriver to reply, as it will send DEV_REVIVE. */
memset(&m_reply, 0, sizeof(m_reply));
m_reply.m_type = r;
if ((r = send(m->m_source, &m_reply)) != OK)
log_warn(&log, "send() to %d failed: %d\n", m->m_source, r);
return EDONTREPLY;
} }
struct device * struct device *

View file

@ -182,7 +182,9 @@
*/ */
#define BUSC_I2C_RESERVE (BUSC_RQ_BASE + 64) /* reserve i2c device */ #define BUSC_I2C_RESERVE (BUSC_RQ_BASE + 64) /* reserve i2c device */
#define BUSC_I2C_ADDR m2_i1 /* slave address */
#define BUSC_I2C_EXEC (BUSC_RQ_BASE + 65) /* perform i2c action */ #define BUSC_I2C_EXEC (BUSC_RQ_BASE + 65) /* perform i2c action */
#define BUSC_I2C_GRANT m2_i1 /* grant for request */
/*===========================================================================* /*===========================================================================*
* Messages for CHARACTER device drivers * * Messages for CHARACTER device drivers *

View file

@ -161,14 +161,14 @@ i2cdriver_reserve_device(endpoint_t bus_endpoint, i2c_addr_t address)
message m; message m;
m.m_type = BUSC_I2C_RESERVE; m.m_type = BUSC_I2C_RESERVE;
m.DEVICE = address; m.BUSC_I2C_ADDR = address;
r = sendrec(bus_endpoint, &m); r = sendrec(bus_endpoint, &m);
if (r != OK) { if (r != OK) {
return EIO; return EIO;
} }
return m.REP_STATUS; /* return reply code OK, EBUSY, EINVAL, etc. */ return m.m_type; /* return reply code OK, EBUSY, EINVAL, etc. */
} }
int int
@ -184,7 +184,7 @@ i2cdriver_exec(endpoint_t bus_endpoint, minix_i2c_ioctl_exec_t * ioctl_exec)
memset(&m, '\0', sizeof(message)); memset(&m, '\0', sizeof(message));
m.m_type = BUSC_I2C_EXEC; m.m_type = BUSC_I2C_EXEC;
m.IO_GRANT = (char *) grant_nr; m.BUSC_I2C_GRANT = grant_nr;
r = sendrec(bus_endpoint, &m); r = sendrec(bus_endpoint, &m);
cpf_revoke(grant_nr); cpf_revoke(grant_nr);
@ -192,7 +192,7 @@ i2cdriver_exec(endpoint_t bus_endpoint, minix_i2c_ioctl_exec_t * ioctl_exec)
return EIO; return EIO;
} }
return m.REP_STATUS; return m.m_type;
} }
static int static int