jeffd has asked for the wisdom of the Perl Monks concerning the following question:

I would like to use perl ioctl to provide a simple peek/poke user interface to my device driver. Unfortunately, it doesn't work for some fundamental reason that I don't understand. I suspect its because the driver is using streams. Here is the basic flow of my program:

open($fd, "+<:unix", $dev_path) || die "Failed to open $dev_path : $!" +; @regs = ($addr, 0x10111213, 0xaaaa, 0xbbbb); $regs = pack('QQQ', @regs); $rc = ioctl($fd, $REG_R, $regs); ($offset, $data0, $data1, $data2) = unpack('QQQ', $regs);

I see the correct device opened and correct driver ioctl called but no data from $regs is passed in or out. I have dumped the iocblk structure at the driver and all I see in it is the value of $REG_R, the ioctl command type. The symptom is as if the third arg of the perl ioctl call is being ignored. My question is: Is there any special consideration I need to make because this a device driver using streams ? The perl code snip above works fine on a non-streams device driver.

Replies are listed 'Best First'.
Re: ioctl call of streams device driver ?
by dave_the_m (Monsignor) on Feb 11, 2017 at 08:04 UTC
    Some observations:

    You don't check the value of $rc.

    In your pack and unpack, you give 3 'Q' actions but pass or expect 4 args.

    Does strace (or whatever) show whether your perl process is making an ioctl system call with the correct fd, request and ptr args?

    Does the value of $REG_R correctly encode the details of the ioctl call - i.e. to indicate whether the arg is input or output and its size? See e.g. /usr/include/asm-generic/ioctl.h on linux systems.

    Dave.

Re: ioctl call of streams device driver ?
by jeffd (Initiate) on Feb 11, 2017 at 18:31 UTC

    Thank you all for your time. I see what the problem is now. The kernel syscall trace showed that the userland address was being passed from the perl script to the driver. The problem is that the ioctls do not support userland access, only kernel mode. I had assumed the new piece, the perl script, had to be at fault. I was wrong.

Re: ioctl call of streams device driver ?
by Anonymous Monk on Feb 11, 2017 at 01:26 UTC

    .oO( there are two peekpoke modules on cpan )