tijin
tijin

Reputation: 757

How can i call a function that written in kernel module, from the user program?

sample driver created and loaded successfully, in that a user defined function is written, it does some actions. i need to write a user program that calls the user defined function in the driver module.

need help in following cases.

  1. How can i get access to the driver code from a user program ?.
  2. How can i call a function that written in kernel module, from the user program ?.

thanks.

Upvotes: 3

Views: 5821

Answers (4)

resultsway
resultsway

Reputation: 13300

for Qn.1: read/write/ioctl see file_operations for Qn.2: 1) system calls 2) driver - ioctl

Upvotes: 0

Kaz
Kaz

Reputation: 58558

VDSO:

http://en.wikipedia.org/wiki/VDSO

Kernel mode Linux:

http://www.yl.is.s.u-tokyo.ac.jp/~tosh/kml/

Upvotes: 1

Gnurou
Gnurou

Reputation: 8153

It depends on what your function does, but in general:

  • If you want to store and show properties in the form of values (e.g. current brightness of a backlight), the standard way of doing would be using sysfs: http://kernel.org/doc/Documentation/filesystems/sysfs.txt

  • If you want to write/read values from a device (real or virtual), export memory or IO regions of a device to user space, or more generally control a device (e.g. setting resolution of a camera and capturing frames), you would use a character or block devices with the read/write/mmap and ioctl functions: http://luv.asn.au/overheads/chrdev-talk.html

  • Finally if your function just controls something from the kernel, then sysfs or procfs should be the way to go. I am not sure why people are still using procfs nowadays, except for misc devices maybe.

So in general, you need to export your kernel functions to user space through files, by defining hooks that will be called when the file is opened, read, written (to copy data from/to user space), mmap'ed (to share memory areas without copying) or when an ioctl is invoked (to perform more general control).

Upvotes: 3

Adrian Panasiuk
Adrian Panasiuk

Reputation: 7343

You can make your driver to react on writes (or if necessary, ioctl) to a /dev/xxx file or a /proc/xxx file. Also, you can create a new syscall, but that's more of a toy as the module would only work on custom built kernels.

Edit: try http://www.faqs.org/docs/kernel/x571.html (on character device drivers.)

Upvotes: 7

Related Questions