From: David van Moolenbroek Date: Mon, 2 Sep 2013 11:45:02 +0000 (+0200) Subject: I2C: change BUSC_I2C_xxx to use own protocol X-Git-Tag: v3.3.0~599 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/man.dnssec-checkds.html?a=commitdiff_plain;h=660d34cd85f595dcc14d3175d3c5e727f54fdb3f;p=minix.git 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 --- diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c index f82e60027..23a41a3a1 100644 --- a/drivers/i2c/i2c.c +++ b/drivers/i2c/i2c.c @@ -34,7 +34,7 @@ static void update_reservation(endpoint_t endpt, char *key); static void ds_event(void); 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); @@ -253,16 +253,11 @@ validate_ioctl_exec(minix_i2c_ioctl_exec_t * ioctl_exec) * Performs the action in minix_i2c_ioctl_exec_t. */ static int -do_i2c_ioctl_exec(message * m) +do_i2c_ioctl_exec(endpoint_t caller, cp_grant_id_t grant_nr) { int r; - endpoint_t caller; - cp_grant_id_t grant_nr; 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 */ r = sys_safecopyfrom(caller, grant_nr, (vir_bytes) 0, (vir_bytes) & ioctl_exec, sizeof(ioctl_exec)); @@ -310,7 +305,7 @@ i2c_ioctl(message * m) switch (m->COUNT) { 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; default: log_warn(&log, "Invalid ioctl() 0x%x\n", m->COUNT); @@ -324,25 +319,24 @@ i2c_ioctl(message * m) int i2c_other(message * m) { + message m_reply; int r; switch (m->m_type) { case BUSC_I2C_RESERVE: /* 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; case BUSC_I2C_EXEC: /* handle request from another driver */ - m->COUNT = MINIX_I2C_IOCTL_EXEC; - r = do_i2c_ioctl_exec(m); + r = do_i2c_ioctl_exec(m->m_source, m->BUSC_I2C_GRANT); break; case NOTIFY_MESSAGE: /* handle notifications about drivers changing state */ if (m->m_source == DS_PROC_NR) { ds_event(); } - r = OK; - break; + return EDONTREPLY; default: log_warn(&log, "Invalid message type (0x%x)\n", m->m_type); r = EINVAL; @@ -351,7 +345,14 @@ i2c_other(message * m) 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 * diff --git a/include/minix/com.h b/include/minix/com.h index b35e6228c..a2b805380 100644 --- a/include/minix/com.h +++ b/include/minix/com.h @@ -182,7 +182,9 @@ */ #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_GRANT m2_i1 /* grant for request */ /*===========================================================================* * Messages for CHARACTER device drivers * diff --git a/lib/libi2cdriver/i2cdriver.c b/lib/libi2cdriver/i2cdriver.c index 1a73ba7ed..1d16db095 100644 --- a/lib/libi2cdriver/i2cdriver.c +++ b/lib/libi2cdriver/i2cdriver.c @@ -161,14 +161,14 @@ i2cdriver_reserve_device(endpoint_t bus_endpoint, i2c_addr_t address) message m; m.m_type = BUSC_I2C_RESERVE; - m.DEVICE = address; + m.BUSC_I2C_ADDR = address; r = sendrec(bus_endpoint, &m); if (r != OK) { 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 @@ -184,7 +184,7 @@ i2cdriver_exec(endpoint_t bus_endpoint, minix_i2c_ioctl_exec_t * ioctl_exec) memset(&m, '\0', sizeof(message)); m.m_type = BUSC_I2C_EXEC; - m.IO_GRANT = (char *) grant_nr; + m.BUSC_I2C_GRANT = grant_nr; r = sendrec(bus_endpoint, &m); cpf_revoke(grant_nr); @@ -192,7 +192,7 @@ i2cdriver_exec(endpoint_t bus_endpoint, minix_i2c_ioctl_exec_t * ioctl_exec) return EIO; } - return m.REP_STATUS; + return m.m_type; } static int