2011-02-17 18:11:09 +01:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
#include "namespace.h"
|
|
|
|
#include <lib.h>
|
2013-12-06 12:04:52 +01:00
|
|
|
#include <stdarg.h>
|
2011-02-17 18:11:09 +01:00
|
|
|
|
|
|
|
#include <sys/ioctl.h>
|
2013-07-15 16:29:09 +02:00
|
|
|
#include <minix/i2c.h>
|
2013-12-12 17:34:44 +01:00
|
|
|
#include <string.h>
|
|
|
|
#include <sys/ioccom.h>
|
|
|
|
#include <stdarg.h>
|
2011-02-17 18:11:09 +01:00
|
|
|
|
2013-07-15 16:29:09 +02:00
|
|
|
static void rewrite_i2c_netbsd_to_minix(minix_i2c_ioctl_exec_t *out,
|
|
|
|
i2c_ioctl_exec_t *in);
|
|
|
|
static void rewrite_i2c_minix_to_netbsd(i2c_ioctl_exec_t *out,
|
|
|
|
minix_i2c_ioctl_exec_t *in);
|
|
|
|
|
|
|
|
static void rewrite_i2c_netbsd_to_minix(minix_i2c_ioctl_exec_t *out,
|
|
|
|
i2c_ioctl_exec_t *in)
|
|
|
|
{
|
|
|
|
memset(out, '\0', sizeof(minix_i2c_ioctl_exec_t));
|
|
|
|
|
|
|
|
out->iie_op = in->iie_op;
|
|
|
|
out->iie_addr = in->iie_addr;
|
|
|
|
out->iie_cmdlen = I2C_EXEC_MAX_CMDLEN < in->iie_cmdlen ?
|
|
|
|
I2C_EXEC_MAX_CMDLEN : in->iie_cmdlen;
|
|
|
|
out->iie_buflen = I2C_EXEC_MAX_BUFLEN < in->iie_buflen ?
|
|
|
|
I2C_EXEC_MAX_BUFLEN : in->iie_buflen;
|
|
|
|
|
|
|
|
if (in->iie_cmdlen > 0 && in->iie_cmd != NULL) {
|
|
|
|
memcpy(out->iie_cmd, in->iie_cmd, in->iie_cmdlen);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (in->iie_buflen > 0 && in->iie_buf != NULL) {
|
|
|
|
memcpy(out->iie_buf, in->iie_buf, in->iie_buflen);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rewrite_i2c_minix_to_netbsd(i2c_ioctl_exec_t *out,
|
|
|
|
minix_i2c_ioctl_exec_t *in)
|
|
|
|
{
|
|
|
|
/* the only field that changes is iie_buf, everything else is the same */
|
|
|
|
if (in->iie_buflen > 0 && in->iie_buf != NULL) {
|
|
|
|
memcpy(out->iie_buf, in->iie_buf, in->iie_buflen);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-12 17:34:44 +01:00
|
|
|
int ioctl(int fd, unsigned long request, ...)
|
2011-02-17 18:11:09 +01:00
|
|
|
{
|
2013-07-15 16:29:09 +02:00
|
|
|
int r, request_save;
|
2011-02-17 18:11:09 +01:00
|
|
|
message m;
|
2013-07-15 16:29:09 +02:00
|
|
|
void *addr;
|
2013-12-12 17:34:44 +01:00
|
|
|
void *data;
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, request);
|
|
|
|
data = va_arg(ap, void *);
|
2013-07-15 16:29:09 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* To support compatibility with interfaces on other systems, certain
|
|
|
|
* requests are re-written to flat structures (i.e. without pointers).
|
|
|
|
*/
|
|
|
|
minix_i2c_ioctl_exec_t i2c;
|
|
|
|
|
|
|
|
request_save = request;
|
|
|
|
|
|
|
|
switch (request) {
|
|
|
|
case I2C_IOCTL_EXEC:
|
|
|
|
rewrite_i2c_netbsd_to_minix(&i2c, data);
|
|
|
|
addr = (void *) &i2c;
|
|
|
|
request = MINIX_I2C_IOCTL_EXEC;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* Keep original as-is */
|
|
|
|
addr = (void *) data;
|
|
|
|
break;
|
|
|
|
}
|
2011-02-17 18:11:09 +01:00
|
|
|
|
2013-11-04 22:48:08 +01:00
|
|
|
memset(&m, 0, sizeof(m));
|
2014-05-12 12:46:59 +02:00
|
|
|
m.m_lc_vfs_ioctl.fd = fd;
|
|
|
|
m.m_lc_vfs_ioctl.req = request;
|
|
|
|
m.m_lc_vfs_ioctl.arg = addr;
|
2013-07-15 16:29:09 +02:00
|
|
|
|
2013-11-04 22:48:08 +01:00
|
|
|
r = _syscall(VFS_PROC_NR, VFS_IOCTL, &m);
|
2013-07-15 16:29:09 +02:00
|
|
|
|
|
|
|
/* Translate back to original form */
|
|
|
|
switch (request_save) {
|
|
|
|
case I2C_IOCTL_EXEC:
|
|
|
|
rewrite_i2c_minix_to_netbsd(data, &i2c);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* Nothing to do */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-12-12 17:34:44 +01:00
|
|
|
va_end(ap);
|
|
|
|
|
2013-07-15 16:29:09 +02:00
|
|
|
return r;
|
2011-02-17 18:11:09 +01:00
|
|
|
}
|