All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai-help] driver: IOCTL command behavior
@ 2009-04-16 11:47 Marcel Soulot
  2009-04-16 12:59 ` Gilles Chanteperdrix
  0 siblings, 1 reply; 6+ messages in thread
From: Marcel Soulot @ 2009-04-16 11:47 UTC (permalink / raw)
  To: xenomai

[-- Attachment #1: Type: text/plain, Size: 572 bytes --]

Hi,

I wrote a driver and used IOCTL command. When I test my driver with a test
application with root access the IOCTL cmd work fine.
I notice when I declared my IOCTL command that I used the _IOR for all of
them. Even the IOCTL command is a read (on register) or write.
So I try to correct my mistake and wants to use _IOR for read command and
_IOW for write command.
For the write command, I got a error -25 (not a typewriter) so I don't
understand why.
I also try to change the _IOW to _IOWR but same mistake.

Someone can explain what is the problem, please ?
Marcel.

[-- Attachment #2: Type: text/html, Size: 614 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Xenomai-help] driver: IOCTL command behavior
  2009-04-16 11:47 [Xenomai-help] driver: IOCTL command behavior Marcel Soulot
@ 2009-04-16 12:59 ` Gilles Chanteperdrix
       [not found]   ` <37f89760904160654g43fde4f0l6cd228faa65d6baf@domain.hid>
  0 siblings, 1 reply; 6+ messages in thread
From: Gilles Chanteperdrix @ 2009-04-16 12:59 UTC (permalink / raw)
  To: Marcel Soulot; +Cc: xenomai

Marcel Soulot wrote:
> Hi,
> 
> I wrote a driver and used IOCTL command. When I test my driver with a test
> application with root access the IOCTL cmd work fine.
> I notice when I declared my IOCTL command that I used the _IOR for all of
> them. Even the IOCTL command is a read (on register) or write.
> So I try to correct my mistake and wants to use _IOR for read command and
> _IOW for write command.
> For the write command, I got a error -25 (not a typewriter) so I don't
> understand why.
> I also try to change the _IOW to _IOWR but same mistake.
> 
> Someone can explain what is the problem, please ?

A piece of code is worth a thousand words...

-- 
                                                 Gilles.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Xenomai-help] driver: IOCTL command behavior
       [not found]   ` <37f89760904160654g43fde4f0l6cd228faa65d6baf@domain.hid>
@ 2009-04-16 14:17     ` Gilles Chanteperdrix
  2009-04-16 14:55       ` Marcel Soulot
  0 siblings, 1 reply; 6+ messages in thread
From: Gilles Chanteperdrix @ 2009-04-16 14:17 UTC (permalink / raw)
  To: Marcel Soulot; +Cc: Xenomai help

Marcel Soulot wrote:
> Hi,
> sorry, i don't realise that my description is a bit fuzzy.
> 
> Here I define two IOCTL command:
> 
> #define RT_GPIO_RTIOC_GET_DIRECTION\
>     _IOR(RTIOC_TYPE_GPIO, 0x01, int)
> 
> #define RT_GPIO_RTIOC_SET_DIRECTION\
>     _IOR(RTIOC_TYPE_GPIO, 0x02, int)
> 
> the commands (both) works fine. For the command
> RT_GPIO_RTIOC_SET_DIRECTION,I try to switch _IOR() to _IOW() according
> the driver "xeno_16550A" (in the
> file /usr/xenomai/include/rtdm/rtserial.h)
> 
> #define RTSER_RTIOC_GET_CONFIG    \
>     _IOR(RTIOC_TYPE_SERIAL, 0x00, struct rtser_config)
> 
> #define RTSER_RTIOC_SET_CONFIG    \
>     _IOW(RTIOC_TYPE_SERIAL, 0x01, struct rtser_config)
> 
> But when I define :
> 
> #define RT_GPIO_RTIOC_SET_DIRECTION\
>     _IOW(RTIOC_TYPE_GPIO, 0x02, int)
> 
> or
> 
> #define RT_GPIO_RTIOC_SET_DIRECTION\
>     _IOWR(RTIOC_TYPE_GPIO, 0x02, int)
> 
> the call of "rt_dev_ioctl(my_fd,RT_GPIO_RTIOC_SET_DIRECTION,0xFF)" returns
> me the error  "-ENOTTY".
> Which means that the command RT_GPIO_RTIOC_SET_DIRECTION is not recognized
> and I drop in default error.
> 
> Hope my explanation is better,

No, please send us enough code for us to reproduce the issue.

Please do not drop the mailing list from the discussion.

-- 
                                                 Gilles.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Xenomai-help] driver: IOCTL command behavior
  2009-04-16 14:17     ` Gilles Chanteperdrix
@ 2009-04-16 14:55       ` Marcel Soulot
  2009-04-16 15:15         ` Jan Kiszka
  0 siblings, 1 reply; 6+ messages in thread
From: Marcel Soulot @ 2009-04-16 14:55 UTC (permalink / raw)
  To: Gilles Chanteperdrix; +Cc: Xenomai help

[-- Attachment #1: Type: text/plain, Size: 2588 bytes --]

Hi,
here is the my ioctl function and the header file below.


/*****************************************************************************************/
int rt_gpio_ioctl(struct rtdm_dev_context *context,
                  rtdm_user_info_t *user_info,
                  unsigned int request, void *arg)
{
    struct rt_gpio_context *ctx_gpio;
    int err = 0;
    unsigned long base;
    int mode;

    ctx_gpio = (struct rt_gpio_context *)context->dev_private;
    base = ctx_gpio->base_addr;
    mode = rt_gpio_io_mode_from_ctx_gpio(ctx_gpio);

    printk(KERN_INFO "IOCTL : request %x\n", request);
    switch (request)
    {
    case RT_GPIO_RTIOC_GET_DIRECTION:
        {
            /*
            ** 1 = input and 0 = output, by default all are inputs.
            */
            int gpio_dir;

            gpio_dir = rt_gpio_reg_in(mode, base, OFF_MPIOSEL);
            printk(KERN_INFO "GET_DIRECTION %x\n", gpio_dir);

            if (user_info)
            {
                err = rtdm_safe_copy_to_user(user_info, arg,
                                             &gpio_dir, sizeof(int));
            }
            else
            {
                *(int *)arg = gpio_dir;
            }

            break;
        }

    case RT_GPIO_RTIOC_SET_DIRECTION:
        {
            /*
            ** 1 = input and 0 = output, by default all are inputs.
            */
            unsigned int gpio_dir = (unsigned int)arg;

            rt_gpio_reg_out(mode, base, OFF_MPIOSEL, gpio_dir);
            printk(KERN_INFO "SET_DIRECTION %x\n", gpio_dir);

            break;
        }

    default:
        err = -ENOTTY;
    }

    return err;
}


/**************************************************************************************************/
header file
/**************************************************************************************************/

#ifndef _RTGPIO_H
#define _RTGPIO_H

#include <rtdm/rtdm.h>

#define RT_GPIO_PROFILE_VER        2

#define RTIOC_TYPE_GPIO                 RTDM_CLASS_GPIO
#define RTDM_SUBCLASS_GPIO              0

#define RT_GPIO_RTIOC_GET_DIRECTION\
    _IOR(RTIOC_TYPE_GPIO, 0x00, int)

#define RT_GPIO_RTIOC_SET_DIRECTION\
    _IOR(RTIOC_TYPE_GPIO, 0x01, int)

#endif /* _RTGPIO_H */

/**************************************************************************************************/

So for the "RT_GPIO_RTIOC_SET_DIRECTION"  when I switch "_IOR(RTIOC_TYPE_GPIO,
0x01, int)" to "_IOW(RTIOC_TYPE_GPIO, 0x01, int)" or "_IOWR(RTIOC_TYPE_GPIO,
0x01, int)", the switch pass in "default".

Someone as an explanation ?
Thanks,
Marcel.

[-- Attachment #2: Type: text/html, Size: 3191 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Xenomai-help] driver: IOCTL command behavior
  2009-04-16 14:55       ` Marcel Soulot
@ 2009-04-16 15:15         ` Jan Kiszka
  2009-04-16 15:47           ` Marcel Soulot
  0 siblings, 1 reply; 6+ messages in thread
From: Jan Kiszka @ 2009-04-16 15:15 UTC (permalink / raw)
  To: Marcel Soulot; +Cc: Xenomai help

Marcel Soulot wrote:
> Hi,
> here is the my ioctl function and the header file below.
> 
> 
> /*****************************************************************************************/
> int rt_gpio_ioctl(struct rtdm_dev_context *context,
>                   rtdm_user_info_t *user_info,
>                   unsigned int request, void *arg)
> {
>     struct rt_gpio_context *ctx_gpio;
>     int err = 0;
>     unsigned long base;
>     int mode;
> 
>     ctx_gpio = (struct rt_gpio_context *)context->dev_private;
>     base = ctx_gpio->base_addr;
>     mode = rt_gpio_io_mode_from_ctx_gpio(ctx_gpio);
> 
>     printk(KERN_INFO "IOCTL : request %x\n", request);
>     switch (request)
>     {
>     case RT_GPIO_RTIOC_GET_DIRECTION:
>         {
>             /*
>             ** 1 = input and 0 = output, by default all are inputs.
>             */
>             int gpio_dir;
> 
>             gpio_dir = rt_gpio_reg_in(mode, base, OFF_MPIOSEL);
>             printk(KERN_INFO "GET_DIRECTION %x\n", gpio_dir);
> 
>             if (user_info)
>             {
>                 err = rtdm_safe_copy_to_user(user_info, arg,
>                                              &gpio_dir, sizeof(int));
>             }
>             else
>             {
>                 *(int *)arg = gpio_dir;
>             }
> 
>             break;
>         }
> 
>     case RT_GPIO_RTIOC_SET_DIRECTION:
>         {
>             /*
>             ** 1 = input and 0 = output, by default all are inputs.
>             */
>             unsigned int gpio_dir = (unsigned int)arg;
> 
>             rt_gpio_reg_out(mode, base, OFF_MPIOSEL, gpio_dir);
>             printk(KERN_INFO "SET_DIRECTION %x\n", gpio_dir);
> 
>             break;
>         }
> 
>     default:
>         err = -ENOTTY;
>     }
> 
>     return err;
> }
> 
> 
> /**************************************************************************************************/
> header file
> /**************************************************************************************************/
> 
> #ifndef _RTGPIO_H
> #define _RTGPIO_H
> 
> #include <rtdm/rtdm.h>
> 
> #define RT_GPIO_PROFILE_VER        2
> 
> #define RTIOC_TYPE_GPIO                 RTDM_CLASS_GPIO
> #define RTDM_SUBCLASS_GPIO              0
> 
> #define RT_GPIO_RTIOC_GET_DIRECTION\
>     _IOR(RTIOC_TYPE_GPIO, 0x00, int)
> 
> #define RT_GPIO_RTIOC_SET_DIRECTION\
>     _IOR(RTIOC_TYPE_GPIO, 0x01, int)
> 
> #endif /* _RTGPIO_H */
> 
> /**************************************************************************************************/
> 
> So for the "RT_GPIO_RTIOC_SET_DIRECTION"  when I switch "_IOR(RTIOC_TYPE_GPIO,
> 0x01, int)" to "_IOW(RTIOC_TYPE_GPIO, 0x01, int)" or "_IOWR(RTIOC_TYPE_GPIO,
> 0x01, int)", the switch pass in "default".
> 
> Someone as an explanation ?

Did you cleanly rebuild both kernel and user space after fiddling with
_IO*? The numerical value of RT_GPIO_RTIOC_SET_DIRECTION changes each time.

BTW, _IO* are conventions between driver and user, nothing is checked or
enforced elsewhere.

Jan

-- 
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Xenomai-help] driver: IOCTL command behavior
  2009-04-16 15:15         ` Jan Kiszka
@ 2009-04-16 15:47           ` Marcel Soulot
  0 siblings, 0 replies; 6+ messages in thread
From: Marcel Soulot @ 2009-04-16 15:47 UTC (permalink / raw)
  To: Jan Kiszka; +Cc: Xenomai help

[-- Attachment #1: Type: text/plain, Size: 74 bytes --]

Thanks for the tips. I forgot to recompile the user application.

Marcel.

[-- Attachment #2: Type: text/html, Size: 88 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2009-04-16 15:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-04-16 11:47 [Xenomai-help] driver: IOCTL command behavior Marcel Soulot
2009-04-16 12:59 ` Gilles Chanteperdrix
     [not found]   ` <37f89760904160654g43fde4f0l6cd228faa65d6baf@domain.hid>
2009-04-16 14:17     ` Gilles Chanteperdrix
2009-04-16 14:55       ` Marcel Soulot
2009-04-16 15:15         ` Jan Kiszka
2009-04-16 15:47           ` Marcel Soulot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.