linux-device-driver

I2C device linux driver [closed]

你说的曾经没有我的故事 提交于 2019-11-29 07:04:07
How to make a character device for i2c device, with open, close, ioctl etc. functions? I was looking for information about it last two weeks and couldn't find anything working. I found some information in Essential Linux Device Drivers, but it was written for 2.6 kernel, and i use 3.4.79 (i'm trying to write this driver for cubieboard2 on cubian distr) so this book has many deprecated functions, i tried to write my driver like there, but it still don't work (give me kernel errors while i'm truing to cat character device). Can anyone explain me what to do with it, or at least give me a working

Does kernel have main function?

南笙酒味 提交于 2019-11-29 06:48:36
问题 I am learning Device Driver and Kernel programming.According to Jonathan Corbet book we do not have main() function in device drivers. #include <linux/init.h> #include <linux/module.h> static int my_init(void) { return 0; } static void my_exit(void) { return; } module_init(my_init); module_exit(my_exit); Here I have two questions : Why we do not need main() function in Device Drivers? Does Kernel have main() function? 回答1: Fundamentally, there is nothing special about a routine being named

Implementing poll in a Linux kernel module

余生长醉 提交于 2019-11-29 04:06:52
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, and then waits on a wait queue. When the DMA completes, the interrupt handler sets a flag and wakes up the wait queue. The important thing to note is that I can start the DMA at any time, even before the device has data to provide . The DMA engine will sit and wait until there is data to copy. This works well. I can implement a simple blocking read call

What is the difference between devm_kzalloc() and kzalloc() in linux driver programming

梦想的初衷 提交于 2019-11-29 02:55:13
问题 I have found devm_kzalloc() and kzalloc() in device driver programmong. But I don't know when/where to use these functions. Can anyone please specify the importance of these functions and their usage. 回答1: kzalloc() allocates kernel memory like kmalloc() , but it also zero-initializes the allocated memory. devm_kzalloc() is managed kzalloc() . The memory allocated with managed functions is associated with the device. When the device is detached from the system or the driver for the device is

how does open works for normal file and device drivers

社会主义新天地 提交于 2019-11-29 02:33:12
Currently, I am learning Linux device drivers. And got stuck over how opening a device file works ? What I got until now... Consider the a simple code that opens a normal file.. #incldue<stdio.h> int main() { FILE fp; char buffer[20]; fp = fopen(/home/yoggi/foo.txt, "r"); fread(buffer, 5, 1, fp); } In above program, The fopen(), c-library function, is a wrapper function to the system call open() , which intern calls sys_open() or file_open() in VFS layer function. As linux supports a number of file system, virtual file system then transfer the control to actual file system handler to the

How to communicate with a Linux kernel module from user space without littering /dev with new nodes?

杀马特。学长 韩版系。学妹 提交于 2019-11-29 01:36:18
问题 What are the ways to communicate with a kernel module from user space? By communication i mean sending information and commands between the kernel module and a user space process. I currently know of two way: open/close/read/write/ioctl on published device node. read/write on exported and hooked /proc file. More specifically, can someone advice the best way to communicate with a kernel module that does not actually drives any hardware and therefore should not be littering /dev with stub nodes

struct file in linux driver

China☆狼群 提交于 2019-11-29 01:31:21
问题 I am currently learning how to write Linux device drivers and I have trouble understanding " struct file ". I am using the book Linux Device Drivers 3rd edition to help me out. This is what I understood. a. struct file represents an open file thus, when open is called in the device driver module, the kernel will create a struct file that includes everything related to the device driver. b. If you want to pass around this instance of the device driver then one has to pass a pointer to the

usage of driver_data member of I2C device id table

核能气质少年 提交于 2019-11-29 00:38:49
I am trying to understand I2C client drivers. As per my understanding before registering I2C driver we have to define i2c_device_id table and device tree compatible table. I have following doubts. Could please help me to understand. 1) The definition of i2c_device_id structure contains two members ( name , driver_data ). The 1st member ( name ) is used to define the device name which will be used during driver binding, what is the use of the 2nd member ( driver_data ). 2) Driver binding will happen based on i2c_device_id table or device tree compatible string. Thanks in advance. 1) The

How remap_pfn_range remaps kernel memory to user space?

妖精的绣舞 提交于 2019-11-28 23:28:43
remap_pfn_range function (used in mmap call in driver) can be used to map kernel memory to user space. How is it done? Can anyone explain precise steps? Kernel Mode is a privileged mode (PM) while user space is non privileged (NPM). In PM CPU can access all memory while in NPM some memory is restricted - cannot be accessed by CPU. When remap_pfn_range is called, how is that range of memory which was restricted only to PM is now accessible to user space? Looking at remap_pfn_range code there is pgprot_t struct . This is protection mapping related struct. What is protection mapping? Is it the

Static functions in Linux device driver

混江龙づ霸主 提交于 2019-11-28 20:35:37
问题 Why is it that every function in most device drivers are static? As static functions are not visible outside of the file scope. Then, how do these driver function get called by user space applications? 回答1: Remember than in C everything is addresses. That means you can call a function if you have the address. The kernel has a macro named EXPORT_SYMBOL that does just that. It exports the address of a function so that driver functions can be called without having to place header declarations