Module: xenomai-gch
Branch: for-forge-fd-rework
Commit: f54a9bb4c98acd986e3a5011bd41bd0d1fc0ec55
URL:    
http://git.xenomai.org/?p=xenomai-gch.git;a=commit;h=f54a9bb4c98acd986e3a5011bd41bd0d1fc0ec55

Author: Gilles Chanteperdrix <gilles.chanteperd...@xenomai.org>
Date:   Sat May 17 21:15:58 2014 +0200

drivers/serial: adapt after RTDM API changes

---

 kernel/drivers/serial/16550A.c       |   87 +++++++++++++++-------------------
 kernel/drivers/serial/Kconfig        |    2 +-
 kernel/drivers/serial/mpc52xx_uart.c |   75 +++++++++++++----------------
 kernel/drivers/serial/rt_imx_uart.c  |   77 ++++++++++++++----------------
 4 files changed, 108 insertions(+), 133 deletions(-)

diff --git a/kernel/drivers/serial/16550A.c b/kernel/drivers/serial/16550A.c
index 8ee1c21..693f878 100644
--- a/kernel/drivers/serial/16550A.c
+++ b/kernel/drivers/serial/16550A.c
@@ -312,9 +312,7 @@ static int rt_16550_set_config(struct rt_16550_context *ctx,
        rtdm_lock_get_irqsave(&ctx->lock, lock_ctx);
 
        if (config->config_mask & RTSER_SET_BAUD) {
-               int dev_id = container_of(((void *)ctx),
-                                         struct rtdm_dev_context,
-                                         dev_private)->device->device_id;
+               int dev_id = rtdm_fd_device(rtdm_private_to_fd(ctx))->device_id;
                int baud_div;
 
                ctx->config.baud_rate = config->baud_rate;
@@ -439,16 +437,15 @@ void rt_16550_cleanup_ctx(struct rt_16550_context *ctx)
        rtdm_mutex_destroy(&ctx->out_lock);
 }
 
-int rt_16550_open(struct rtdm_dev_context *context,
-                 rtdm_user_info_t * user_info, int oflags)
+int rt_16550_open(struct rtdm_fd *fd, int oflags)
 {
        struct rt_16550_context *ctx;
-       int dev_id = context->device->device_id;
+       int dev_id = rtdm_fd_device(fd)->device_id;
        int err;
        uint64_t *dummy;
        rtdm_lockctx_t lock_ctx;
 
-       ctx = (struct rt_16550_context *)context->dev_private;
+       ctx = rtdm_fd_to_private(fd);
 
        /* IPC initialisation - cannot fail with used parameters */
        rtdm_lock_init(&ctx->lock);
@@ -480,8 +477,8 @@ int rt_16550_open(struct rtdm_dev_context *context,
        rt_16550_set_config(ctx, &default_config, &dummy);
 
        err = rtdm_irq_request(&ctx->irq_handle, irq[dev_id],
-                              rt_16550_interrupt, irqtype[dev_id],
-                              context->device->proc_name, ctx);
+                       rt_16550_interrupt, irqtype[dev_id],
+                       rtdm_fd_device(fd)->proc_name, ctx);
        if (err) {
                /* reset DTR and RTS */
                rt_16550_reg_out(rt_16550_io_mode_from_ctx(ctx), ctx->base_addr,
@@ -504,8 +501,7 @@ int rt_16550_open(struct rtdm_dev_context *context,
        return 0;
 }
 
-int rt_16550_close(struct rtdm_dev_context *context,
-                  rtdm_user_info_t * user_info)
+void rt_16550_close(struct rtdm_fd *fd)
 {
        struct rt_16550_context *ctx;
        unsigned long base;
@@ -513,7 +509,7 @@ int rt_16550_close(struct rtdm_dev_context *context,
        uint64_t *in_history;
        rtdm_lockctx_t lock_ctx;
 
-       ctx = (struct rt_16550_context *)context->dev_private;
+       ctx = rtdm_fd_to_private(fd);
        base = ctx->base_addr;
        mode = rt_16550_io_mode_from_ctx(ctx);
 
@@ -539,13 +535,9 @@ int rt_16550_close(struct rtdm_dev_context *context,
        rt_16550_cleanup_ctx(ctx);
 
        kfree(in_history);
-
-       return 0;
 }
 
-int rt_16550_ioctl(struct rtdm_dev_context *context,
-                  rtdm_user_info_t * user_info,
-                  unsigned int request, void *arg)
+int rt_16550_ioctl(struct rtdm_fd *fd, unsigned int request, void *arg)
 {
        rtdm_lockctx_t lock_ctx;
        struct rt_16550_context *ctx;
@@ -553,15 +545,15 @@ int rt_16550_ioctl(struct rtdm_dev_context *context,
        unsigned long base;
        int mode;
 
-       ctx = (struct rt_16550_context *)context->dev_private;
+       ctx = rtdm_fd_to_private(fd);
        base = ctx->base_addr;
        mode = rt_16550_io_mode_from_ctx(ctx);
 
        switch (request) {
        case RTSER_RTIOC_GET_CONFIG:
-               if (user_info)
+               if (rtdm_fd_is_user(fd))
                        err =
-                           rtdm_safe_copy_to_user(user_info, arg,
+                           rtdm_safe_copy_to_user(fd, arg,
                                                   &ctx->config,
                                                   sizeof(struct
                                                          rtser_config));
@@ -577,9 +569,9 @@ int rt_16550_ioctl(struct rtdm_dev_context *context,
 
                config = (struct rtser_config *)arg;
 
-               if (user_info) {
+               if (rtdm_fd_is_user(fd)) {
                        err =
-                           rtdm_safe_copy_from_user(user_info, &config_buf,
+                           rtdm_safe_copy_from_user(fd, &config_buf,
                                                     arg,
                                                     sizeof(struct
                                                            rtser_config));
@@ -591,8 +583,8 @@ int rt_16550_ioctl(struct rtdm_dev_context *context,
 
                if ((config->config_mask & RTSER_SET_BAUD) &&
                    (config->baud_rate >
-                    baud_base[context->device->device_id] ||
-                    config->baud_rate <= 0))
+                           baud_base[rtdm_fd_device(fd)->device_id] ||
+                           config->baud_rate <= 0))
                        /* invalid baudrate for this port */
                        return -EINVAL;
 
@@ -631,7 +623,7 @@ int rt_16550_ioctl(struct rtdm_dev_context *context,
 
                rtdm_lock_put_irqrestore(&ctx->lock, lock_ctx);
 
-               if (user_info) {
+               if (rtdm_fd_is_user(fd)) {
                        struct rtser_status status_buf;
 
                        status_buf.line_status =
@@ -640,7 +632,7 @@ int rt_16550_ioctl(struct rtdm_dev_context *context,
                            rt_16550_reg_in(mode, base, MSR);
 
                        err =
-                           rtdm_safe_copy_to_user(user_info, arg,
+                           rtdm_safe_copy_to_user(fd, arg,
                                                   &status_buf,
                                                   sizeof(struct
                                                          rtser_status));
@@ -654,9 +646,9 @@ int rt_16550_ioctl(struct rtdm_dev_context *context,
        }
 
        case RTSER_RTIOC_GET_CONTROL:
-               if (user_info)
+               if (rtdm_fd_is_user(fd))
                        err =
-                           rtdm_safe_copy_to_user(user_info, arg,
+                           rtdm_safe_copy_to_user(fd, arg,
                                                   &ctx->mcr_status,
                                                   sizeof(int));
                else
@@ -725,9 +717,9 @@ int rt_16550_ioctl(struct rtdm_dev_context *context,
 
                rtdm_lock_put_irqrestore(&ctx->lock, lock_ctx);
 
-               if (user_info)
+               if (rtdm_fd_is_user(fd))
                        err =
-                           rtdm_safe_copy_to_user(user_info, arg, &ev,
+                           rtdm_safe_copy_to_user(fd, arg, &ev,
                                                   sizeof(struct
                                                          rtser_event));
                        else
@@ -788,8 +780,7 @@ int rt_16550_ioctl(struct rtdm_dev_context *context,
        return err;
 }
 
-ssize_t rt_16550_read(struct rtdm_dev_context * context,
-                     rtdm_user_info_t * user_info, void *buf, size_t nbyte)
+ssize_t rt_16550_read(struct rtdm_fd *fd, void *buf, size_t nbyte)
 {
        struct rt_16550_context *ctx;
        rtdm_lockctx_t lock_ctx;
@@ -806,10 +797,10 @@ ssize_t rt_16550_read(struct rtdm_dev_context * context,
        if (nbyte == 0)
                return 0;
 
-       if (user_info && !rtdm_rw_user_ok(user_info, buf, nbyte))
+       if (rtdm_fd_is_user(fd) && !rtdm_rw_user_ok(fd, buf, nbyte))
                return -EFAULT;
 
-       ctx = (struct rt_16550_context *)context->dev_private;
+       ctx = rtdm_fd_to_private(fd);
 
        rtdm_toseq_init(&timeout_seq, ctx->config.rx_timeout);
 
@@ -857,9 +848,9 @@ ssize_t rt_16550_read(struct rtdm_dev_context * context,
                                   separately. */
                                subblock = IN_BUFFER_SIZE - in_pos;
 
-                               if (user_info) {
+                               if (rtdm_fd_is_user(fd)) {
                                        if (rtdm_copy_to_user
-                                           (user_info, out_pos,
+                                           (fd, out_pos,
                                             &ctx->in_buf[in_pos],
                                             subblock) != 0) {
                                                ret = -EFAULT;
@@ -876,8 +867,8 @@ ssize_t rt_16550_read(struct rtdm_dev_context * context,
                                in_pos = 0;
                        }
 
-                       if (user_info) {
-                               if (rtdm_copy_to_user(user_info, out_pos,
+                       if (rtdm_fd_is_user(fd)) {
+                               if (rtdm_copy_to_user(fd, out_pos,
                                                      &ctx->in_buf[in_pos],
                                                      subblock) != 0) {
                                        ret = -EFAULT;
@@ -952,9 +943,7 @@ break_unlocked:
        return ret;
 }
 
-ssize_t rt_16550_write(struct rtdm_dev_context * context,
-                      rtdm_user_info_t * user_info, const void *buf,
-                      size_t nbyte)
+ssize_t rt_16550_write(struct rtdm_fd *fd, const void *buf, size_t nbyte)
 {
        struct rt_16550_context *ctx;
        rtdm_lockctx_t lock_ctx;
@@ -970,10 +959,10 @@ ssize_t rt_16550_write(struct rtdm_dev_context * context,
        if (nbyte == 0)
                return 0;
 
-       if (user_info && !rtdm_read_user_ok(user_info, buf, nbyte))
+       if (rtdm_fd_is_user(fd) && !rtdm_read_user_ok(fd, buf, nbyte))
                return -EFAULT;
 
-       ctx = (struct rt_16550_context *)context->dev_private;
+       ctx = rtdm_fd_to_private(fd);
 
        rtdm_toseq_init(&timeout_seq, ctx->config.rx_timeout);
 
@@ -1000,9 +989,9 @@ ssize_t rt_16550_write(struct rtdm_dev_context * context,
                                   end separately. */
                                subblock = OUT_BUFFER_SIZE - out_pos;
 
-                               if (user_info) {
+                               if (rtdm_fd_is_user(fd)) {
                                        if (rtdm_copy_from_user
-                                           (user_info,
+                                           (fd,
                                             &ctx->out_buf[out_pos],
                                             in_pos, subblock) != 0) {
                                                ret = -EFAULT;
@@ -1019,9 +1008,9 @@ ssize_t rt_16550_write(struct rtdm_dev_context * context,
                                out_pos = 0;
                        }
 
-                       if (user_info) {
+                       if (rtdm_fd_is_user(fd)) {
                                if (rtdm_copy_from_user
-                                   (user_info, &ctx->out_buf[out_pos],
+                                   (fd, &ctx->out_buf[out_pos],
                                     in_pos, subblock) != 0) {
                                        ret = -EFAULT;
                                        break;
@@ -1085,10 +1074,10 @@ static const struct rtdm_device __initdata device_tmpl 
= {
        .context_size           = sizeof(struct rt_16550_context),
        .device_name            = "",
 
-       .open_nrt               = rt_16550_open,
+       .open                   = rt_16550_open,
 
        .ops = {
-               .close_nrt      = rt_16550_close,
+               .close          = rt_16550_close,
 
                .ioctl_rt       = rt_16550_ioctl,
                .ioctl_nrt      = rt_16550_ioctl,
diff --git a/kernel/drivers/serial/Kconfig b/kernel/drivers/serial/Kconfig
index e495911..e43fa74 100644
--- a/kernel/drivers/serial/Kconfig
+++ b/kernel/drivers/serial/Kconfig
@@ -69,7 +69,7 @@ config XENO_DRIVERS_MPC52XX_UART
        Real-time UART driver for the PSC on the MPC5200 processor.
 
 config XENO_DRIVERS_IMX_UART
-       depends on XENO_SKIN_RTDM && (ARCH_IMX || ARCH_MXC)
+       depends on ARCH_IMX || ARCH_MXC
        tristate "RT IMX UART driver"
        select RATIONAL
        help
diff --git a/kernel/drivers/serial/mpc52xx_uart.c 
b/kernel/drivers/serial/mpc52xx_uart.c
index 9d2bdfe..982d728 100644
--- a/kernel/drivers/serial/mpc52xx_uart.c
+++ b/kernel/drivers/serial/mpc52xx_uart.c
@@ -637,16 +637,15 @@ void rt_mpc52xx_uart_cleanup_ctx(struct 
rt_mpc52xx_uart_ctx *ctx)
        rtdm_mutex_destroy(&ctx->out_lock);
 }
 
-static int rt_mpc52xx_uart_open(struct rtdm_dev_context *context,
-                               rtdm_user_info_t *user_info, int oflags)
+static int rt_mpc52xx_uart_open(struct rtdm_fd *fd, int oflags)
 {
        struct rt_mpc52xx_uart_ctx *ctx;
        rtdm_lockctx_t lock_ctx;
        uint64_t *dummy;
        int err;
 
-       ctx = (struct rt_mpc52xx_uart_ctx *)context->dev_private;
-       ctx->port = (struct rt_mpc52xx_uart_port *)context->device->device_data;
+       ctx = rtdm_fd_to_private(fd);
+       ctx->port = (struct rt_mpc52xx_uart_port 
*)rtdm_fd_device(fd)->device_data;
 
        /* IPC initialisation - cannot fail with used parameters */
        rtdm_lock_init(&ctx->lock);
@@ -692,7 +691,7 @@ static int rt_mpc52xx_uart_open(struct rtdm_dev_context 
*context,
 
        err = rtdm_irq_request(&ctx->irq_handle, ctx->port->irq,
                               rt_mpc52xx_uart_interrupt, 0,
-                              context->device->proc_name, ctx);
+                              rtdm_fd_device(fd)->proc_name, ctx);
        if (err) {
                psc_set_mcr(ctx, 0);
                rt_mpc52xx_uart_cleanup_ctx(ctx);
@@ -703,14 +702,13 @@ static int rt_mpc52xx_uart_open(struct rtdm_dev_context 
*context,
        return 0;
 }
 
-static int rt_mpc52xx_uart_close(struct rtdm_dev_context *context,
-                                rtdm_user_info_t *user_info)
+static void rt_mpc52xx_uart_close(struct rtdm_fd *fd)
 {
        struct rt_mpc52xx_uart_ctx *ctx;
        uint64_t *in_history;
        rtdm_lockctx_t lock_ctx;
 
-       ctx = (struct rt_mpc52xx_uart_ctx *)context->dev_private;
+       ctx = rtdm_fd_to_private(fd);
 
        rtdm_lock_get_irqsave(&ctx->lock, lock_ctx);
 
@@ -729,24 +727,21 @@ static int rt_mpc52xx_uart_close(struct rtdm_dev_context 
*context,
        rt_mpc52xx_uart_cleanup_ctx(ctx);
 
        kfree(in_history);
-
-       return 0;
 }
 
-static int rt_mpc52xx_uart_ioctl(struct rtdm_dev_context *context,
-                                rtdm_user_info_t *user_info,
+static int rt_mpc52xx_uart_ioctl(struct rtdm_fd *fd,
                                 unsigned int request, void *arg)
 {
        rtdm_lockctx_t lock_ctx;
        struct rt_mpc52xx_uart_ctx *ctx;
        int err = 0;
 
-       ctx = (struct rt_mpc52xx_uart_ctx *)context->dev_private;
+       ctx = rtdm_fd_to_private(fd);
 
        switch (request) {
        case RTSER_RTIOC_GET_CONFIG:
-               if (user_info)
-                       err = rtdm_safe_copy_to_user(user_info, arg,
+               if (rtdm_is_user(fd))
+                       err = rtdm_safe_copy_to_user(fd, arg,
                                                     &ctx->config,
                                                     sizeof(struct
                                                            rtser_config));
@@ -761,8 +756,8 @@ static int rt_mpc52xx_uart_ioctl(struct rtdm_dev_context 
*context,
 
                config = (struct rtser_config *)arg;
 
-               if (user_info) {
-                       err = rtdm_safe_copy_from_user(user_info, &config_buf,
+               if (rtdm_is_user(fd)) {
+                       err = rtdm_safe_copy_from_user(fd, &config_buf,
                                                       arg,
                                                       sizeof(struct
                                                              rtser_config));
@@ -811,13 +806,13 @@ static int rt_mpc52xx_uart_ioctl(struct rtdm_dev_context 
*context,
 
                rtdm_lock_put_irqrestore(&ctx->lock, lock_ctx);
 
-               if (user_info) {
+               if (rtdm_is_user(fd)) {
                        struct rtser_status status_buf;
 
                        status_buf.line_status = status;
                        status_buf.modem_status = psc_get_msr(ctx);
 
-                       err = rtdm_safe_copy_to_user(user_info, arg,
+                       err = rtdm_safe_copy_to_user(fd, arg,
                                                     &status_buf,
                                                     sizeof(struct
                                                            rtser_status));
@@ -830,8 +825,8 @@ static int rt_mpc52xx_uart_ioctl(struct rtdm_dev_context 
*context,
        }
 
        case RTSER_RTIOC_GET_CONTROL:
-               if (user_info)
-                       err = rtdm_safe_copy_to_user(user_info, arg,
+               if (rtdm_is_user(fd))
+                       err = rtdm_safe_copy_to_user(fd, arg,
                                                     &ctx->mcr_status,
                                                     sizeof(int));
                else
@@ -894,9 +889,9 @@ static int rt_mpc52xx_uart_ioctl(struct rtdm_dev_context 
*context,
 
                rtdm_lock_put_irqrestore(&ctx->lock, lock_ctx);
 
-               if (user_info)
+               if (rtdm_is_user(fd))
                        err =
-                           rtdm_safe_copy_to_user(user_info, arg, &ev,
+                           rtdm_safe_copy_to_user(fd, arg, &ev,
                                                   sizeof(struct
                                                          rtser_event));
                        else
@@ -956,8 +951,7 @@ static int rt_mpc52xx_uart_ioctl(struct rtdm_dev_context 
*context,
        return err;
 }
 
-static ssize_t rt_mpc52xx_uart_read(struct rtdm_dev_context *context,
-                                   rtdm_user_info_t *user_info, void *buf,
+static ssize_t rt_mpc52xx_uart_read(struct rtdm_fd *fd, void *buf,
                                    size_t nbyte)
 {
        struct rt_mpc52xx_uart_ctx *ctx;
@@ -975,10 +969,10 @@ static ssize_t rt_mpc52xx_uart_read(struct 
rtdm_dev_context *context,
        if (nbyte == 0)
                return 0;
 
-       if (user_info && !rtdm_rw_user_ok(user_info, buf, nbyte))
+       if (rtdm_is_user(fd) && !rtdm_rw_user_ok(fd, buf, nbyte))
                return -EFAULT;
 
-       ctx = (struct rt_mpc52xx_uart_ctx *)context->dev_private;
+       ctx = rtdm_fd_to_private(fd);
 
        rtdm_toseq_init(&timeout_seq, ctx->config.rx_timeout);
 
@@ -1018,9 +1012,9 @@ static ssize_t rt_mpc52xx_uart_read(struct 
rtdm_dev_context *context,
                                   separately. */
                                subblock = IN_BUFFER_SIZE - in_pos;
 
-                               if (user_info) {
+                               if (rtdm_is_user(fd)) {
                                        if (rtdm_copy_to_user
-                                           (user_info, out_pos,
+                                           (fd, out_pos,
                                             &ctx->in_buf[in_pos],
                                             subblock) != 0) {
                                                ret = -EFAULT;
@@ -1037,8 +1031,8 @@ static ssize_t rt_mpc52xx_uart_read(struct 
rtdm_dev_context *context,
                                in_pos = 0;
                        }
 
-                       if (user_info) {
-                               if (rtdm_copy_to_user(user_info, out_pos,
+                       if (rtdm_is_user(fd)) {
+                               if (rtdm_copy_to_user(fd, out_pos,
                                                      &ctx->in_buf[in_pos],
                                                      subblock) != 0) {
                                        ret = -EFAULT;
@@ -1113,8 +1107,7 @@ break_unlocked:
        return ret;
 }
 
-static ssize_t rt_mpc52xx_uart_write(struct rtdm_dev_context *context,
-                                    rtdm_user_info_t  *user_info,
+static ssize_t rt_mpc52xx_uart_write(struct rtdm_fd *fd,
                                     const void *buf,
                                     size_t nbyte)
 {
@@ -1132,10 +1125,10 @@ static ssize_t rt_mpc52xx_uart_write(struct 
rtdm_dev_context *context,
        if (nbyte == 0)
                return 0;
 
-       if (user_info && !rtdm_read_user_ok(user_info, buf, nbyte))
+       if (rtdm_is_user(fd) && !rtdm_read_user_ok(fd, buf, nbyte))
                return -EFAULT;
 
-       ctx = (struct rt_mpc52xx_uart_ctx *)context->dev_private;
+       ctx = rtdm_fd_to_private(fd);
 
        rtdm_toseq_init(&timeout_seq, ctx->config.rx_timeout);
 
@@ -1162,9 +1155,9 @@ static ssize_t rt_mpc52xx_uart_write(struct 
rtdm_dev_context *context,
                                   end separately. */
                                subblock = OUT_BUFFER_SIZE - out_pos;
 
-                               if (user_info) {
+                               if (rtdm_is_user(fd)) {
                                        if (rtdm_copy_from_user
-                                           (user_info,
+                                           (fd,
                                             &ctx->out_buf[out_pos],
                                             in_pos, subblock) != 0) {
                                                ret = -EFAULT;
@@ -1181,9 +1174,9 @@ static ssize_t rt_mpc52xx_uart_write(struct 
rtdm_dev_context *context,
                                out_pos = 0;
                        }
 
-                       if (user_info) {
+                       if (rtdm_is_user(fd)) {
                                if (rtdm_copy_from_user
-                                   (user_info, &ctx->out_buf[out_pos],
+                                   (fd, &ctx->out_buf[out_pos],
                                     in_pos, subblock) != 0) {
                                        ret = -EFAULT;
                                        break;
@@ -1246,10 +1239,10 @@ static const struct rtdm_device device_tmpl = {
        .context_size           = sizeof(struct rt_mpc52xx_uart_ctx),
        .device_name            = "",
 
-       .open_nrt               = rt_mpc52xx_uart_open,
+       .open                   = rt_mpc52xx_uart_open,
 
        .ops = {
-               .close_nrt      = rt_mpc52xx_uart_close,
+               .close          = rt_mpc52xx_uart_close,
 
                .ioctl_rt       = rt_mpc52xx_uart_ioctl,
                .ioctl_nrt      = rt_mpc52xx_uart_ioctl,
diff --git a/kernel/drivers/serial/rt_imx_uart.c 
b/kernel/drivers/serial/rt_imx_uart.c
index d4e453a..2f9a8f1 100644
--- a/kernel/drivers/serial/rt_imx_uart.c
+++ b/kernel/drivers/serial/rt_imx_uart.c
@@ -738,8 +738,7 @@ static int rt_imx_uart_setup_ufcr(struct rt_imx_uart_port 
*port)
 /* half the RX buffer size */
 #define CTSTL 16
 
-static int rt_imx_uart_open(struct rtdm_dev_context *context,
-                           rtdm_user_info_t *user_info, int oflags)
+static int rt_imx_uart_open(struct rtdm_fd *fd, int oflags)
 {
        struct rt_imx_uart_ctx *ctx;
        struct rt_imx_uart_port *port;
@@ -748,8 +747,8 @@ static int rt_imx_uart_open(struct rtdm_dev_context 
*context,
        int retval;
        uint64_t *dummy;
 
-       ctx = (struct rt_imx_uart_ctx *)context->dev_private;
-       ctx->port = (struct rt_imx_uart_port *)context->device->device_data;
+       ctx = rtdm_fd_to_private(fd);
+       ctx->port = (struct rt_imx_uart_port *)rtdm_fd_device(fd)->device_data;
 
        port = ctx->port;
 
@@ -793,7 +792,7 @@ static int rt_imx_uart_open(struct rtdm_dev_context 
*context,
 
        retval = rtdm_irq_request(&ctx->irq_handle,
                                  port->irq, rt_imx_uart_int, 0,
-                                 context->device->proc_name, ctx);
+                                 rtdm_fd_device(fd)->proc_name, ctx);
        if (retval)
                return retval;
 
@@ -822,15 +821,14 @@ static int rt_imx_uart_open(struct rtdm_dev_context 
*context,
        return 0;
 }
 
-int rt_imx_uart_close(struct rtdm_dev_context *context,
-                     rtdm_user_info_t *user_info)
+void rt_imx_uart_close(struct rtdm_fd *fd)
 {
        struct rt_imx_uart_ctx *ctx;
        uint64_t *in_history;
        rtdm_lockctx_t lock_ctx;
        unsigned long temp;
 
-       ctx = (struct rt_imx_uart_ctx *)context->dev_private;
+       ctx = rtdm_fd_to_private(fd);
 
        rtdm_lock_get_irqsave(&ctx->lock, lock_ctx);
 
@@ -855,25 +853,22 @@ int rt_imx_uart_close(struct rtdm_dev_context *context,
 
        if (in_history)
                kfree(in_history);
-
-       return 0;
 }
 
-static int rt_imx_uart_ioctl(struct rtdm_dev_context *context,
-                            rtdm_user_info_t *user_info,
+static int rt_imx_uart_ioctl(struct rtdm_fd *fd,
                             unsigned int request, void *arg)
 {
        rtdm_lockctx_t lock_ctx;
        struct rt_imx_uart_ctx *ctx;
        int err = 0;
 
-       ctx = (struct rt_imx_uart_ctx *)context->dev_private;
+       ctx = rtdm_fd_to_private(fd);
 
        switch (request) {
        case RTSER_RTIOC_GET_CONFIG:
-               if (user_info)
+               if (rtdm_fd_is_user(fd))
                        err =
-                           rtdm_safe_copy_to_user(user_info, arg,
+                           rtdm_safe_copy_to_user(fd, arg,
                                                   &ctx->config,
                                                   sizeof(struct rtser_config));
                else
@@ -888,9 +883,9 @@ static int rt_imx_uart_ioctl(struct rtdm_dev_context 
*context,
 
                config = (struct rtser_config *)arg;
 
-               if (user_info) {
+               if (rtdm_fd_is_user(fd)) {
                        err =
-                           rtdm_safe_copy_from_user(user_info, &config_buf,
+                           rtdm_safe_copy_from_user(fd, &config_buf,
                                                     arg,
                                                     sizeof(struct
                                                            rtser_config));
@@ -942,14 +937,14 @@ static int rt_imx_uart_ioctl(struct rtdm_dev_context 
*context,
 
                rtdm_lock_put_irqrestore(&ctx->lock, lock_ctx);
 
-               if (user_info) {
+               if (rtdm_fd_is_user(fd)) {
                        struct rtser_status status_buf;
 
 
                        status_buf.line_status = status;
                        status_buf.modem_status = msr;
                        err =
-                           rtdm_safe_copy_to_user(user_info, arg,
+                           rtdm_safe_copy_to_user(fd, arg,
                                                   &status_buf,
                                                   sizeof(struct
                                                          rtser_status));
@@ -961,9 +956,9 @@ static int rt_imx_uart_ioctl(struct rtdm_dev_context 
*context,
        }
 
        case RTSER_RTIOC_GET_CONTROL:
-               if (user_info)
+               if (rtdm_fd_is_user(fd))
                        err =
-                           rtdm_safe_copy_to_user(user_info, arg,
+                           rtdm_safe_copy_to_user(fd, arg,
                                                   &ctx->mcr_status,
                                                   sizeof(int));
                else
@@ -1034,9 +1029,9 @@ static int rt_imx_uart_ioctl(struct rtdm_dev_context 
*context,
 
                rtdm_lock_put_irqrestore(&ctx->lock, lock_ctx);
 
-               if (user_info)
+               if (rtdm_fd_is_user(fd))
                        err =
-                           rtdm_safe_copy_to_user(user_info, arg, &ev,
+                           rtdm_safe_copy_to_user(fd, arg, &ev,
                                                   sizeof(struct
                                                          rtser_event));
                        else
@@ -1091,8 +1086,7 @@ wait_unlock_out:
        return err;
 }
 
-ssize_t rt_imx_uart_read(struct rtdm_dev_context *context,
-                        rtdm_user_info_t *user_info, void *buf, size_t nbyte)
+ssize_t rt_imx_uart_read(struct rtdm_fd *fd, void *buf, size_t nbyte)
 {
        struct rt_imx_uart_ctx *ctx;
        rtdm_lockctx_t lock_ctx;
@@ -1109,10 +1103,10 @@ ssize_t rt_imx_uart_read(struct rtdm_dev_context 
*context,
        if (nbyte == 0)
                return 0;
 
-       if (user_info && !rtdm_rw_user_ok(user_info, buf, nbyte))
+       if (rtdm_fd_is_user(fd) && !rtdm_rw_user_ok(fd, buf, nbyte))
                return -EFAULT;
 
-       ctx = (struct rt_imx_uart_ctx *)context->dev_private;
+       ctx = rtdm_fd_to_private(fd);
 
        rtdm_toseq_init(&timeout_seq, ctx->config.rx_timeout);
 
@@ -1152,9 +1146,9 @@ ssize_t rt_imx_uart_read(struct rtdm_dev_context *context,
                                   separately. */
                                subblock = IN_BUFFER_SIZE - in_pos;
 
-                               if (user_info) {
+                               if (rtdm_fd_is_user(fd)) {
                                        if (rtdm_copy_to_user
-                                           (user_info, out_pos,
+                                           (fd, out_pos,
                                             &ctx->in_buf[in_pos],
                                             subblock) != 0) {
                                                ret = -EFAULT;
@@ -1171,8 +1165,8 @@ ssize_t rt_imx_uart_read(struct rtdm_dev_context *context,
                                in_pos = 0;
                        }
 
-                       if (user_info) {
-                               if (rtdm_copy_to_user(user_info, out_pos,
+                       if (rtdm_fd_is_user(fd)) {
+                               if (rtdm_copy_to_user(fd, out_pos,
                                                      &ctx->in_buf[in_pos],
                                                      subblock) != 0) {
                                        ret = -EFAULT;
@@ -1248,9 +1242,8 @@ break_unlocked:
        return ret;
 }
 
-static ssize_t rt_imx_uart_write(struct rtdm_dev_context *context,
-                                rtdm_user_info_t *user_info, const void *buf,
-                                size_t nbyte)
+static ssize_t rt_imx_uart_write(struct rtdm_fd *fd, const void *buf,
+                               size_t nbyte)
 {
        struct rt_imx_uart_ctx *ctx;
        rtdm_lockctx_t lock_ctx;
@@ -1266,10 +1259,10 @@ static ssize_t rt_imx_uart_write(struct 
rtdm_dev_context *context,
        if (nbyte == 0)
                return 0;
 
-       if (user_info && !rtdm_read_user_ok(user_info, buf, nbyte))
+       if (rtdm_fd_is_user(fd) && !rtdm_read_user_ok(fd, buf, nbyte))
                return -EFAULT;
 
-       ctx = (struct rt_imx_uart_ctx *)context->dev_private;
+       ctx = rtdm_fd_to_private(fd);
 
        rtdm_toseq_init(&timeout_seq, ctx->config.rx_timeout);
 
@@ -1296,9 +1289,9 @@ static ssize_t rt_imx_uart_write(struct rtdm_dev_context 
*context,
                                   end separately. */
                                subblock = OUT_BUFFER_SIZE - out_pos;
 
-                               if (user_info) {
+                               if (rtdm_fd_is_user(fd)) {
                                        if (rtdm_copy_from_user
-                                           (user_info,
+                                           (fd,
                                             &ctx->out_buf[out_pos],
                                             in_pos, subblock) != 0) {
                                                ret = -EFAULT;
@@ -1315,9 +1308,9 @@ static ssize_t rt_imx_uart_write(struct rtdm_dev_context 
*context,
                                out_pos = 0;
                        }
 
-                       if (user_info) {
+                       if (rtdm_fd_is_user(fd)) {
                                if (rtdm_copy_from_user
-                                   (user_info, &ctx->out_buf[out_pos],
+                                   (fd, &ctx->out_buf[out_pos],
                                     in_pos, subblock) != 0) {
                                        ret = -EFAULT;
                                        break;
@@ -1377,10 +1370,10 @@ static const struct rtdm_device __initdata device_tmpl 
= {
        .context_size           = sizeof(struct rt_imx_uart_ctx),
        .device_name            = "",
 
-       .open_nrt               = rt_imx_uart_open,
+       .open                   = rt_imx_uart_open,
 
        .ops = {
-               .close_nrt      = rt_imx_uart_close,
+               .close          = rt_imx_uart_close,
                .ioctl_rt       = rt_imx_uart_ioctl,
                .ioctl_nrt      = rt_imx_uart_ioctl,
                .read_rt        = rt_imx_uart_read,


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git

Reply via email to