linux-device-driver

Does i2c driver need to be implemented just like any other character device driver?

微笑、不失礼 提交于 2019-12-03 21:54:25
I'm a noob to Linux device drivers so please bear with me. I'm trying to implement a i2c driver (client). It's at the point where I can insmod , .probe gets called (because of device-tree entries) and in the .probe I can read/write to the device. Great. However I need to be able to initiate read/writes from userspace to the driver. In order to do this, should an i2c driver be shaped like any other char device driver? Meaning having a file_operations struct so userspace can open , close , read , write , and ioctls ? I'm asking because in all the i2c client examples I've seen, nobody has

What do I need to build to directly access the Ethernet frame bits in the kernel level?

狂风中的少年 提交于 2019-12-03 20:54:37
I would like to retrieve the Ethernet Frame bits for all the Ethernet frames on the wire no matter if they are destined (MAC level) for my machine or not. The logic for that has to be at the kernel level. So in order to achieve this do I need to build a separate kernel module or Ethernet driver or Ethernet network interface Note: I have just started learning Linux kernel module development for my project. I'm sorry if it is not the appropriate place to post this question. rodolk For receiving frames destined to all hosts you must set your network interface in promiscuous mode. For getting

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

做~自己de王妃 提交于 2019-12-03 20:22:39
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 have few question with respect to above implentation. Will 2 i2c operation in "handler fn" takes

How to prevent “error: 'symbol' undeclared here” despite EXPORT_SYMBOL in a Linux kernel module?

心已入冬 提交于 2019-12-03 20:10:28
问题 I'm embedding some driver into a Linux kernel when I get this error (I'm adding the device in the board file and registering it): error: 'kxtf9_get_slave_descr' undeclared here (not in a function) I located the function above in a driver file struct ext_slave_descr *kxtf9_get_slave_descr(void) { return &kxtf9_descr; } EXPORT_SYMBOL(kxtf9_get_slave_descr); Shouldn't it made "visible" by EXPORT_SYMBOL? The C file containing the code above has no header file (I didn't write it, I just found it

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

拈花ヽ惹草 提交于 2019-12-03 20:08:26
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 appear, but that approach does not work because of races with other devices, both real and uinput, that are

What register state is saved on a context switch in Linux?

与世无争的帅哥 提交于 2019-12-03 17:18:31
Where in Linux would you look to find out what registers are saved on a context switch? I'm wondering, for example, if it is safe to use FP or vector registers in kernel-mode driver code (mostly interested in x86-64 and ARM, but I'm hoping for an architecture-independent answer). Since no one seems to have answered this, let me venture. Take a look at the _math_restore_cpu and __unlazy_fpu methods. You can find them here: http://www.cs.fsu.edu/~baker/devices/lxr/http/ident?i=math_state_restore http://www.cs.fsu.edu/~baker/devices/lxr/http/ident?i=__unlazy_fpu The x86 like processors have

Clarification about the behaviour of request_threaded_irq

牧云@^-^@ 提交于 2019-12-03 16:37:48
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 had we gone ahead with a "traditional", top half/bottom half approach, we would have needed either spin

create device mapper target

∥☆過路亽.° 提交于 2019-12-03 15:51:48
I am trying to implement device mapper target by referring to the already existing ones dm-linear, dm-snapshot, dm-cache etc. In my implementation, I need to perform a read/modify/write operation on a certain sector range. Since the device mapper directly talks to the block layer, I am not sure what data structures/functions to use to read the sectors in the memory, modify the buffer and write it back to another sector range. At the application level, we have syscalls and below we have vfs_read/vfs_write. Is there anything similar for device mapper layer? I have been stuck here for very long.

Changing the Interrupt descriptor Table

久未见 提交于 2019-12-03 15:06:36
I am using Linux 2.6.26 kernel version and I am trying to change the interrupt descriptor table using a kernel module. I am only trying to change the page fault table entry here. So I make a copy of the original IDT and make changes to the page fault table entry only. The objective of the ISR is to print out information of the page fault before calling the original Page fault handler. But the kernel just crashes once I load it with insmod i.e it specifically crashed with the "loadIDTR" function. With further debugging, I found out that by not changing any entry if I load the IDTR it works fine

What happens to preempted interrupt handler?

最后都变了- 提交于 2019-12-03 15:05:45
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 executing it will disable all the interrupt in the current processor) , so what will happen for the interrupts