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

how to use 'cat' in following simple device read program

static ssize_t device_read (struct file* filp, char *bufStoreData, size_t bufCount, loff_t* curOffset) { printk(KERN_INFO"reading from the device"); ret = copy_to_user(bufStoreData,virtual_device.data,bufCount); return ret; } does…
mrigendra
  • 1,472
  • 3
  • 19
  • 33
2
votes
2 answers

Why software interrupts can sleep while it is not allowed in hardware interrupts?

Why we can sleep in software interrupt case while it is not allowed in case of hardware interrupt? e.g. System calls can sleep while ISR cannot sleep.
2
votes
0 answers

.ndo_start_xmit in Usbnet.c driver

In usbnet.c driver, there is function pointer called .ndo_start_xmit which gets called whenever there is a packet to be transmitted from the upper layers. Can it be called twice for the same packet and in what cases ?? If the USB endpoint buffers…
2
votes
1 answer

How to implement poll in linux driver that notices FD closed

I'm implementing a misc device driver for linux. This driver implements file_operations::poll and I want to make it so that poll(2) would return POLLHUP if the descriptor is closed. Supposed driver client code(userland code) follows. void…
bbpencil
  • 41
  • 1
  • 3
2
votes
1 answer

How to use a FIFO in a Linux char device driver so that two process that uses the driver can communicate

I have a char device driver that for a virtual device. I want a FIFO in the device driver so that 2 process using the device driver can transfer characters between them. I tried kfifo but I am new to this and find it difficult to use. Can any body…
goldenptr
  • 321
  • 1
  • 4
  • 14
2
votes
0 answers

How are intermodule dependencies resolved when...?

How are intermodule dependencies resolved when both modules are built outside of the kernel tree and modversioning is enabled? Modversioning is used to ensure that binary loadable modules are compatible with the kernels they are loaded upon. It is…
Peter L.
  • 1,041
  • 2
  • 22
  • 26
2
votes
1 answer

Push all packets received at network interface card into TCP/IP stack

Is it possible to push all packets received at NIC to the TCP/IP stack even if their ethernet address doesn't match my ethernet address? In other words I want to process all incoming packets at my NIC. Can anyone mention a possible scenario for…
MSH
  • 429
  • 3
  • 7
  • 20
2
votes
1 answer

Avoid creating debug info in LKM with kbuild

I'm building Linux kernel module (LKM) from a big C files (>50 000 LOC). It's some generated RAID calculation code. When I try to build it from kbuild gcc eats all of the memory and crashes, while invoking gcc manually works fine. After inspecting…
Alexander Dzyoba
  • 4,009
  • 1
  • 24
  • 29
2
votes
2 answers

Read() function doesnt read the entire data on serial communication

Here is my code void Reading_TtyS0() { int ret; char mypipe_ttyS0[80] = {0}; fcntl(fd, F_SETFL, 0); ret = read(fd, ttyS0_mypipe , 80 ); printf(ret = %d\n", ret); if (ret > 0) { perror("Message Log,…
2
votes
1 answer

Would somebody explain how to use pci_enable_device() in linux

I am starting to learn to write PCI driver and the first exercise i took was to find if a given device exists on the bus. After searching some books and internet, i was able to write down the below program which does work but i am not clear on few…
pkumarn
  • 1,383
  • 4
  • 22
  • 29
2
votes
0 answers

Not able to light up keyboard LED using outb() call

I am trying to light up the keyboard LED in Linux with the following program (found this on internet) but nothing seems to happen. Am I missing anything? /* sample.c: very simple example of port I/O * * This code does nothing useful, just a port…
pkumarn
  • 1,383
  • 4
  • 22
  • 29
2
votes
3 answers

dma_map_single(): minimum requirements to struct device

I have been trying to make the following trivial example code work in my module (kernel versions 2.6.32, 2.6.35): int rc; struct device dev; dev_set_name(&dev, "mydev"); if ((rc = device_register(&dev)) != 0) goto fail; …
amicus99
  • 81
  • 1
  • 6
2
votes
1 answer

Why prototype of ioctl call is using unsigned long as third argument?

Below is the prototype of an ioctl call long ioctl(struct file *f, unsigned int cmd, unsigned long arg); Why third argument of an ioctl is unsigned long by default? Some times we pass a pointer to it. But it is using unsigned long.
Chinna
  • 3,930
  • 4
  • 25
  • 55
2
votes
1 answer

how to know on which CPU interrupt handler is handled in linux

On multiple processor system, it is quite possible that interrupts can be handled on multiple processors. Is there a way to check where (means on which CPUS) does my interrupt handler is executed on linux kernel ?
Rakesh Babu
  • 143
  • 1
  • 1
  • 8
2
votes
2 answers

How multiple interrupt handler share address 0x00000018

I am reading about how Interrupts are handled in ARM and came to know whenever any Hardware interrupts comes instruction at an address 0x00000018 is executed which is generally a jump to respected interrupt handler but there could be many interrupt…
Amit Singh Tomar
  • 8,380
  • 27
  • 120
  • 199