Re: exposing kernel driver to user space app

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Ilya,

ilya wrote:
hello,

my name is ilya, i am a kernel newbie, and  i just
joined the list in hopes of getting some insight on
linux device driver development.

i am writing a kernel-mode driver for a pci card and
i need a mechanism to control the device via user-space
application. at first i had an additional character driver
initialized along with my driver and using fread/fwrite
i would transfer info back and forth. then i found out
about sysfs, so now i am using files in sysfs to
send "commands" to the driver and receive data back.

i have a feeling, however, that i am abusing this method.
what is the appropriate way of setting this up?

IIRC, sysfs documentation in the kernel sources does not seem to state what is permitted and what not when it comes to the sysfs usage. All it does is line up few rules and limitations - I guess if you could live with that, then that is the way to do it, too ;)

is there
a way for the module to notify an application of some
event happening?

By using select/poll from the userspace one needs to implement similar procedure in their (character) device driver as well - namely poll(). This would (if properly implemented) relieve you of the need to manually check for an event to happen. See LDD3 (http://lwn.net/Kernel/LDD3/) for sample device driver that utilizes the poll() syscall.

because right now i do this by
constantly reading from one of the files in sysfs until
the value it holds changes. i also know that reading
files from kernel-mode is not a good thing, but i want
to implement something of a config file that can be
modified from user-space but would be read in by
the module. what is the best way of doing this?

I would go with one of these options:
a) use write() or ioctl() syscall to pass the parameters from the userspace to the kernel driver,
b) use sysfs to supply the parameters to the kernel

Both ways deal with predefined structure being constructed, filled with the parameter values and fed to the driver by the means of either using syscalls or sysfs interface.
Maybe someone else has some other way of doing it...

Regards,
Hinko

--
ČETRTA POT, d.o.o., Kranj
Planina 3
4000 Kranj
Slovenia, Europe
Tel. +386 (0) 4 280 66 03
E-mail: hinko.kocevar@xxxxxxxxxxxx
Http: www.cetrtapot.si


--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux