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
13
votes
2 answers

Implementing poll in a Linux kernel module

I have a simple character device driver that allows you to read from a custom hardware device. It uses a DMA to copy data from the device's memory into kernel space (and then up to the user). The read call is very simple. It starts a DMA write,…
zmb
  • 7,605
  • 4
  • 40
  • 55
13
votes
3 answers

how to find Linux module path

in the linux, lsmod lists a lot of modules. but how can we find where those module loaded from. for some modules,linux command "modprobe -l" shows a path but some are not. edited i also tried "find" and "locate". both of them lists all kind of…
cppython
  • 1,209
  • 3
  • 20
  • 30
13
votes
1 answer

What is MODULE_ALIAS in Linux device driver code?

Explanation for MODULE_ALIAS in the code says /* work with hotplug and coldplug */ MODULE_ALIAS("platform:omap2_mcspi"); But, what exactly is MODULE_ALIAS? Is there a significance for : (colon) in the argument?
Sagar Jain
  • 7,475
  • 12
  • 47
  • 83
13
votes
1 answer

What is the significance of /queue/rotational in Linux?

I was searching to identify the way to detect whether a disk is SSD or HDD? I found that there is a way to detect it. This is by reading the value of cat /sys/block/sda/queue/rotational? If it is 1 then it is HDD otherwise it is SSD. I was…
dexterous
  • 6,422
  • 12
  • 51
  • 99
13
votes
4 answers

What is the significance of THIS_MODULE in Linux kernel module drivers?

In Linux device driver development, the file_operations structure uses struct module *owner. What is the use of this structure when we always initialize it with THIS_MODULE? When can this field be set to NULL?
Anup Warnulkar
  • 773
  • 1
  • 8
  • 25
13
votes
1 answer

What is the difference between tasklet and workqueue

I am a Linux device driver newbie, and want to know the exact differences between tasklet and workqueue. I have the following doubts: Which kernel stack do interrupts, tasklet and workqueue use when running in interrupt/process context? At what…
manav m-n
  • 11,136
  • 23
  • 74
  • 97
13
votes
4 answers

Is there a way to ask the Linux Kernel to re-run its PCI initialization code?

I'm looking for either a kernel mode call that I can make from a driver, a userland utility, or a system call that will ask the Kernel to look at the PCI bus and either completely re-run its initialization, or initialize a specific device. …
mlustig
  • 131
  • 1
  • 3
13
votes
1 answer

Format specifier for printk loff_t types?

I am working on a Linux character device driver for a school assignment and am not sure how to print the *ppos passed into my read function which is of type loff_t. I know I must use printk rather than the standard library printf from within the…
Anthony Jack
  • 5,333
  • 7
  • 28
  • 47
12
votes
3 answers

How do I determine if a connected USB device is a USB flash drive?

how do you determine what kind of media has been attached to the system? I have Ubuntu, and when I inserted an SD-card, it notices that it is in fact an SD card. Same counts for USB sticks. But how can I determine on low level when a new device is…
Boy
  • 7,010
  • 4
  • 54
  • 68
12
votes
7 answers

Linux: direct access to the hard-disk in C

How can I obtain a raw access to the HD and know if that location is used or is a free space? Just a piece of example, I can obtain a direct access simply with an open and a read on a disk device, the goal is knowing whether the, for example, 10.000…
Lopoc
  • 1,308
  • 5
  • 16
  • 26
12
votes
2 answers

How can I pause for 100+ milliseconds in a linux driver module?

I'm writing a kernel driver for a device that produces regular amounts of data for reading periodically. The user space program is ideally suited to making this a blocking driver. What methods are available for pausing anywhere from 4 to 100ms in a…
Jamie
  • 7,075
  • 12
  • 56
  • 86
12
votes
5 answers

Reason to pass data using struct inode and struct file in Linux device driver programming

I'm studying Chapter 3.5 of Linux Device Drivers, 3rd edition. This section introduces a method to retrieve a custom structure we defined ourselves from struct inode *inode in the open function: int scull_open(struct inode *inode, struct file…
I'm a frog dragon
  • 7,865
  • 7
  • 46
  • 49
12
votes
1 answer

What is the difference between DMA and IOMMU?

What is DMA and IOMMU ? How DMA and IOMMU used ? What if architecture does not support IOMMU ? How to use DMA without IOMMU ?
12
votes
3 answers

copy_to_user undefined in linux kernel version 4.12.8

In my project I am using char driver to communicate between user space and kernel space. I use the function copy_to_user(void user *to, const void *from, unsigned long n) to copy data from kernel space to user space buffer. We can find this function…
12
votes
1 answer

Direct Control of HCI Device (Bypass Bluetooth Drivers) on Linux

I need to control an HCI device directly without the Linux drivers/kernel interfering. For example, when creating an LE connection to a peripheral, the driver is independently sending an "LE Connection Update" command which I would like to avoid. I…
Dan Shemesh
  • 464
  • 3
  • 13