Questions tagged [linux-device-driver]

Device drivers take on a special role in the Linux kernel. They are distinct programmatically abstracted “black boxes” that make a particular piece of hardware respond to a well-defined internal programming interface; they hide completely the details of how the device works.

User activities are performed by means of a set of standardized calls that are independent of the specific driver. Mapping those calls to device-specific operations that act on real hardware is the role of the device driver. This programming interface is such that drivers can be built separately from the rest of the kernel and “plugged in” at runtime when needed. This modularity makes Linux device drivers easy to write, to the point that there are now thousands of them available.

There are a number of reasons to be interested in the writing of Linux device drivers.

  • The rate at which new hardware becomes available (and obsolete!) alone guarantees that driver writers will be busy for the foreseeable future.

  • Individuals may need to know about drivers in order to gain access to a particular device that is of interest to them.

  • Hardware vendors, by making a Linux device driver available for their products, can add the large and growing Linux user-base to their potential markets.

The open-source nature of the Linux system means that if the driver writer wishes, the source to a driver can be quickly disseminated to millions of users.

Source -

  1. Linux Device Drivers 3rd edition

  2. Linux module programming guide

4991 questions
11
votes
3 answers

Memory usage of a kernel module

While trying to estimate the amount of memory consumed by a kernel module (usually device drivers),I tried using the size utility which gave the size of the static memory areas of the .ko ( .bss, .data, .text etc). So I was expecting the sum of…
AIB
  • 5,894
  • 8
  • 30
  • 36
11
votes
4 answers

insmod: ERROR: could not insert module HelloWorld.ko: Operation not permitted

I am trying to learn linux and kernel development. I am able to build the module but am unable to load it. HelloWorld.c /* * hello-1.c - The simplest kernel module. */ #include /* Needed by all modules */ #include…
kpk
  • 142
  • 1
  • 2
  • 11
11
votes
1 answer

Why does /proc/iomem only show zeros instead addresses in 64bit linux?

As I understand it, /proc/iomem should list all addresses, but on my 64bit Linux (both on Debian 9 and Fedora 27 it shows only zeros: cat /proc/iomem 00000000-00000000 : reserved 00000000-00000000 : System RAM 00000000-00000000 :…
11
votes
1 answer

Purpose and usage of GPIO-Hog declaration

Questions What is the purpose and use-case of the gpio-hog declaration? Can a 'hogged' gpio pin be interfaced with from Userspace? If a 'hogged' gpio pin cannot be interfaced with from Userspace, then is there any mechanism to configure GPIO pins…
Liam Kelly
  • 3,524
  • 1
  • 17
  • 41
11
votes
2 answers

What are coding conventions for using floating-point in Linux device drivers?

This is related to this question. I'm not an expert on Linux device drivers or kernel modules, but I've been reading "Linux Device Drivers" [O'Reilly] by Rubini & Corbet and a number of online sources, but I haven't been able to find anything on…
Die in Sente
  • 9,546
  • 3
  • 35
  • 41
11
votes
3 answers

Makefile for Linux kernel module?

I was just reading The Linux Kernel Module Programming Guide and and got stuck on character device drivers example. Makefiles for previous examples were provided, but not for this one, so I'm trying to make one: obj-m += chardev.o all: make -C…
matcheek
  • 4,887
  • 9
  • 42
  • 73
11
votes
2 answers

how to compile a kernel module

I'm trying to compile a simple hello world module following this guide and I'm confused about what the Makefile is actually doing. obj-m += hello-1.o all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules clean: make -C…
Jordan Camp
  • 842
  • 4
  • 9
  • 20
11
votes
2 answers

device-tree mismatch: .probe never called

I'm having trouble understanding how device-tree works, or specifically why this driver won't init. This is in the rockchip vendor kernel for android, version 3.10 drivers/watchdog/rk29_wdt.c (reduced for readability) static const struct…
aep
  • 776
  • 5
  • 26
11
votes
2 answers

What are linux irq domains, why are they needed?

What are irq domains, i read kernel documentation (https://www.kernel.org/doc/Documentation/IRQ-domain.txt) they say: The number of interrupt controllers registered as unique irqchips show a rising tendency: for example subdrivers of different…
11
votes
3 answers

IS_ERR() macro in Linux

While getting to know how to write device drivers I came across IS_ERR() macro. But I couldn't find how is it working. I have include the code below: majorNumber = register_chrdev(0, DEVICE_NAME, &fops); if (majorNumber<0) { printk(KERN_ALERT…
S.I.J
  • 979
  • 1
  • 10
  • 22
11
votes
1 answer

Character Driver with Circular buffer

I am learning device driver programming and I have created a simple character driver where I am passing data from a user space app and storing it in a kernel space circular buffer, then reading this circular buffer again from another user space…
Ankit Pandya
  • 111
  • 1
  • 3
11
votes
2 answers

Why driver programming prefer kzalloc over kmalloc

AM I correct to observe that in case of any memory allocation done within device driver routines, kzalloc is preferred over kmalloc ? I have seen kernel patches replacing kmalloc+memset with kzalloc. But my doubt is why one needs to set memory…
Jaydeep Sen
  • 111
  • 1
  • 1
  • 5
11
votes
1 answer

create /dev/fakeDevice supporting read, write and ioctl

I have a piece of software running on an embedded device (x86, recent linux). To ease development, use automated tests, etc., I want to run it on my host system. The code compiles just fine with some tweaks to the build-system. The next step would…
Peter Schneider
  • 1,683
  • 12
  • 31
11
votes
1 answer

Device tree driven kernel for raspberry pi

I'd like to boot the raspberry pi with a device-tree-driven linux kernel, is there anything special to do to do that? Can anyone point what are required to set up a device-tree-based kernel boot up for the raspberry pi. I may need to have raspberry…
Amit Singh Tomar
  • 8,380
  • 27
  • 120
  • 199
11
votes
1 answer

Is it possible to call device layer code from driver code in Linux Kernel

I am going through Linux Networking device driver code and wanted to know is it possible call device layer code from driver code. --- a/drivers/net/ethernet/realtek/8139too.c +++ b/drivers/net/ethernet/realtek/8139too.c @@ -1706,10 +1706,20 @@…
Amit Singh Tomar
  • 8,380
  • 27
  • 120
  • 199