linux-device-driver

How do I determine the files corresponding to a uinput device?

送分小仙女□ 提交于 2019-12-05 02:43:48
问题 In linux when a uinput device is created, one or more event files corresponding to that device get created in the file system. (For example, if I create a uinput mouse, then the file /dev/input/mouseN is created.) But how do I determine which files got created for a given uinput device? The uinput kernel module does not appear to provide any ioctl for getting that information. One possible approach is to poll the file system immediately after creating the uinput device to see what files

How an I2c read as well as write operation in “handler function” of request_threaded_irq affects the driver as a whole.?

时光怂恿深爱的人放手 提交于 2019-12-05 02:38:31
问题 I have a driver code with handler function and thread function of request_threaded_irq similar to this: irq-handler fn() { /*disable device interrupt*/ i2c read from register; set disable bit to client-device-interrupt i2c write back; return IRQ_WAKe_THREAD; } irq-thread fn() { i2c read from register; .... .... /*enable device interrupt*/ i2c read from register; set enable bit to client-device-interrupt i2c write back; /*Rest of the operation*/ .......... .......... return IRQ_HANDLED; } I

Why do we need to call poll_wait in poll?

我只是一个虾纸丫 提交于 2019-12-05 02:33:03
In LDD3, i saw such codes static unsigned int scull_p_poll(struct file *filp, poll_table *wait) { struct scull_pipe *dev = filp->private_data; unsigned int mask = 0; /* * The buffer is circular; it is considered full * if "wp" is right behind "rp" and empty if the * two are equal. */ down(&dev->sem); poll_wait(filp, &dev->inq, wait); poll_wait(filp, &dev->outq, wait); if (dev->rp != dev->wp) mask |= POLLIN | POLLRDNORM; /* readable */ if (spacefree(dev)) mask |= POLLOUT | POLLWRNORM; /* writable */ up(&dev->sem); return mask; } But it says poll_wait won't wait and will return immediately. Then

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

a 夏天 提交于 2019-12-05 02:14:33
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 this specific issue yet. When is a kernel or driver module allowed to use floating-point registers? If so, who is responsible for saving and restoring their contents? (Assume x86-64 architecture) If I understand correctly, whenever a KM is running, it is using a hardware context (or hardware thread or register set -- whatever you want to call it) that

Clarification about the behaviour of request_threaded_irq

☆樱花仙子☆ 提交于 2019-12-05 01:07:09
问题 I have scoured the web, but haven't found a convincing answer to a couple of related questions I have, with regard to the "request_threaded_irq" feature. Question1: Firstly, I was reading this article, regarding threaded IRQ's: http://lwn.net/Articles/302043/ and there is this one line that isn't clear to me: "Converting an interrupt to threaded makes only sense when the handler code takes advantage of it by integrating tasklet/softirq functionality and simplifying the locking." I understand

why is u8 u16 u32 u64 used instead of unsigned int in kernel programming

佐手、 提交于 2019-12-04 23:18:54
I see u8 u16 u32 u64 data types being used in kernel code. And I am wondering why is there need to use u8 or u16 or u32 or u64 and not unsigned int ? Often when working close to the hardware or when trying to control the size/format of a data structure you need to have precise control of the size of your integers. As for u8 vs uint8_t , this is simply because Linux predated <stdint.h> being available in C, which is technically a C99-ism, but in my experience is available on most modern compilers even in their ANSI-C / C89 modes. Adding my 10 cents to this answer : u64 means an 'unsigned 64

What happens to preempted interrupt handler?

走远了吗. 提交于 2019-12-04 23:10:05
问题 I could not find a proper answer for the following questions even in some well written kernel books: They are saying that an ISR can't sleep because its not possible to reschedule an ISR as it is not connected with any process , so what happens when a higher priority interrupt preempt the executing one? the interrupted ISR will not rescheduled(execute) again ? if yes how & who will do that work? many time we will disable interrupt (eg: 1.In critical region 2. When a fast interrupt is

How to measure ISR execution time?

人走茶凉 提交于 2019-12-04 21:51:52
I am on linux kernel 2.6.32. I am facing an issue in which one of the two ISR (serial and ethernet) are taking more time (hundreds of microseconds) on several occasion/under some scenarios which I don't know. I would like to get the time difference every time the ISR executes. What would be the best way (least expensive in terms of overhead involved). I don't see ARM architecture has some TSC register (read_tsc api) which would give me direct access to time as it offers on some other architecture. So Idea is 1) The moment ISR is invoked measure time 2) the moment ISR is complete measure the

Using stdlib.h within a device driver

本小妞迷上赌 提交于 2019-12-04 19:38:36
I am trying to write a device driver and I need to use system() function in the driver. To use system() we need to include <stdlib.h> , which dosnt seem to work from a driver. It says no such file or directory found. Is there an alternative to stdlib.h for device drivers? Or an alternative to system() ? stdlib.h is a user space header. User space is that set of memory locations in which user processes (i.e., everything other than the kernel) run. A process is an executing instance of a program. One of the roles of the kernel is to manage individual user processes within this space and to

Polling a loop device through a kernel module

谁说我不能喝 提交于 2019-12-04 19:31:58
I was trying to read a loopback device that I have created through a kernel module in periods of 200ms, but it is crashing the kernel, when I try to insert it. I think there is problem with my read module, but it works fine without timer. I am new to kernel programming,please help. Thank you in advance:D #include <linux/kernel.h> #include <linux/module.h> #include <linux/timer.h> #include<linux/fs.h> #include <linux/init.h> #include <asm/segment.h> #include <asm/uaccess.h> #include <linux/buffer_head.h> static struct timer_list my_timer; static void read_file(char *filename) { struct file *fd;