Query regarding read/write operation using IOCTLS in KMDF Driver

Hi,

I am a beginner to Windows Device Driver Development and trying to complete a read operation (from hardware registers) using IOCTL from a user application.

I am able to call EvtIODeviceControl of KMDF Driver from User application.

Following call is being used:-

if (!DeviceIoControl(DriverHandle,
(DWORD) IOCTL_READ_REG, // Read IOCTL
&reglist, // Ptr to Input Buffer
sizeof(struct hx170_reglist_t), // Length of InBuffer
&reglist1, // Ptr to Output Buffer
sizeof(struct hx170_reglist_t), // Length of OutBuffer
&index, // BytesReturned
0) ) // Ptr to Overlapped structure

Problem is :

  1. How can we access the input buffer pointer (&reglist) passed in DeviceIOControl of user application in kernel side driver? (Input buffer pointer contains offset information to read from hardware registers). In linux, we have copy_to_user and copy_from_user to copy data from kernel to user and user to kernel side. How it is possible in Windows?

  2. Can WdfRequestRetrieveOutputBuffer/WdfRequestRetrieveInputBuffer be used for same in EvtDeviceIOControl of Driver?

  3. How can we return the read value back to the user application?

Thanks and Regards
Jayant Shekhar

Part of the answer depends on how you defined your IOCTL code. Show the
CTL_CODE definition.

What’s with the DWORD cast? It seems silly, and getting into the habit of
gratuitous casting will eventually do you in.

I don’t want to take the time to explain every detail to you; but without
seeing the CTL_CODE definition, I’d have to guess, and I see no point to
that.

Hint: in providing code samples, no non-framework names shall be used
unless their corresponding definitions are provided.

The short answer is that the functions you refer to do not exist in
Windows because drivers do not need them, ever. Either the I/O Manager
handles it, or you are using direct mode, in which case you either program
the DMA controller with the physical address or you get a kernel-mapped
address and just write o the memory it describes.

DeviceIoControl is tricky, and as I said, I can’t give a simple answer to
a question so ill-specified.
joe

Hi,

I am a beginner to Windows Device Driver Development and trying to
complete a read operation (from hardware registers) using IOCTL from a
user application.

I am able to call EvtIODeviceControl of KMDF Driver from User application.

Following call is being used:-

if (!DeviceIoControl(DriverHandle,
(DWORD) IOCTL_READ_REG, // Read IOCTL
&reglist, // Ptr to Input Buffer
sizeof(struct hx170_reglist_t), //
Length of InBuffer
&reglist1, // Ptr to Output Buffer
sizeof(struct hx170_reglist_t), //
Length of OutBuffer
&index, // BytesReturned
0) ) // Ptr to Overlapped structure

Problem is :

  1. How can we access the input buffer pointer (&reglist) passed in
    DeviceIOControl of user application in kernel side driver? (Input buffer
    pointer contains offset information to read from hardware registers). In
    linux, we have copy_to_user and copy_from_user to copy data from kernel to
    user and user to kernel side. How it is possible in Windows?

  2. Can WdfRequestRetrieveOutputBuffer/WdfRequestRetrieveInputBuffer be
    used for same in EvtDeviceIOControl of Driver?

  3. How can we return the read value back to the user application?

Thanks and Regards
Jayant Shekhar


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

xxxxx@gmail.com wrote:

I am a beginner to Windows Device Driver Development and trying to complete a read operation (from hardware registers) using IOCTL from a user application.

I am able to call EvtIODeviceControl of KMDF Driver from User application.

  1. How can we access the input buffer pointer (&reglist) passed in DeviceIOControl of user application in kernel side driver? (Input buffer pointer contains offset information to read from hardware registers). In linux, we have copy_to_user and copy_from_user to copy data from kernel to user and user to kernel side. How it is possible in Windows?

  2. Can WdfRequestRetrieveOutputBuffer/WdfRequestRetrieveInputBuffer be used for same in EvtDeviceIOControl of Driver?

Have you read the documentation of those two functions? That’s exactly
what they are used for.

  1. How can we return the read value back to the user application?

What else would you do with an output buffer? Just remember to set the
“information” value to the number of bytes you set when you complete the
request.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.