linux-device-driver

How can I monitor the NIC status(up/down) in a C program without polling the kernel?

蓝咒 提交于 2019-11-27 11:30:14
Now I need to get the status of the NIC(up or down) in the real time. That means I have to catch the kernel interrupt when the NIC up or down in a blocked loop. The first stupid method from mine is that check on the /sys/class/net/eth0/operstate or use ioctl to get the ifflag every 100ms in a loop. But 100ms is too long for the app to reroute the traffic and also polling kernel every 100ms is not good idea. Once I notice the inotify function that can monitor the files in a block mode. But unfortunately, it can't monitor the /sys/class/net/eth0/operstate file since /sys is located in the RAM

Adding new driver code to linux source code

為{幸葍}努か 提交于 2019-11-27 11:15:41
I have developed a Linux device driver. As of now I am compiling it on Ubuntu 12.04 with cross-compiler for arm and then insmoding it in my arm Linux image. But I want to learn how I can add it in Linux source code and give and option to add/remove through configuration of arm Linux, so that I can compile it with Linux source code compilation? Any ideas? Deepak Singh To cross compile your own driver in the arm architecture you have to follow some steps as mentioned below. Create a directory like my_drvr inside drivers(which is in the Linux source code) for your driver and put your driver (my

Hard time in understanding MODULE_DEVICE_TABLE(usb, id_table) usage

你说的曾经没有我的故事 提交于 2019-11-27 10:54:54
问题 I have a hard time understanding the exact usage of MODULE_DEVICE_TABLE(usb, id_table) AFAIK this will generate the map files that will be used later by modprobe whenever a new device is inserted, it will match it against those map files and load the module if it matches. But my misunderstanding is "isn't the module loaded anyway?" I mean I already loaded it when I did insmod module-name . or am I missing something? 回答1: It is usually used to support hot-plugging, by loading/inserting the

Linux Device Driver Program, where the program starts?

强颜欢笑 提交于 2019-11-27 09:38:31
I've started to learn Linux driver programs, but I'm finding it a little difficult. I've been studying the i2c driver, and I got quite confused regarding the entry-point of the driver program. Does the driver program start at the MOUDULE_INIT() macro? And I'd also like to know how I can know the process of how the driver program runs. I got the book, Linux Device Driver, but I'm still quite confused. Could you help me? Thanks a lot. I'll take the i2c driver as an example. There are just so many functions in it, I just wanna know how I can get coordinating relation of the functions in the i2c

Who calls the probe() of driver

感情迁移 提交于 2019-11-27 09:25:33
问题 How does probe() call gets called? Who calls it? As per my understanding, __init() registers driver and then somehow probe() is called to register the device data and irq etc. How exactly it happens? I am working on touchscreen driver and its __init registers itself to i2c driver . Then probe expect i2c_clien t data which returns null. I want to track where it gets filled. 回答1: Long story short: the probe() function of the driver is called as a result of calling the register_driver for that

init function invocation of drivers compiled into kernel

元气小坏坏 提交于 2019-11-27 08:59:30
In Linux if device drivers are built as loadable kernel modules, then upon inserting the device driver kernel module, the kernel calls the init function of the device driver as pointed out by module_init() macro. How does this work for device drivers that are statically compiled into the kernel ? How is their init function called ? sawdust The init routine of a built-in driver can still use the module_init() macro to declare that entry point. Or the driver can use device_initcall() when the driver would never be compiled as a loadable module. Or to move its initialization very early in the

Linux kernel device driver programming [closed]

你。 提交于 2019-11-27 08:59:02
问题 I want to learn linux kernel device driver programming. So can anyone please post good tutorials pages or links here. I am new to linux kernel environment. I have searched for it but I don't know how to start and which one to read for easy understanding basics. Thanks in advance. 回答1: Depends on your current skills. If you're really new to Linux, perhaps you should start with user space system programming with Advanced Linux Programming. You'll get good knowledge of Unix system calls and

What does request_mem_region() actually do and when it is needed?

青春壹個敷衍的年華 提交于 2019-11-27 07:06:57
I'm studying on writing embedded linux driver, and decided to fire a few GPIOs to make sure I understand the book (LDD3, chap9.4.1) correctly. I am able to control the correct GPIO pins as intended (making it high and low, I probed with a multimeter); however, I tested 2 pieces of code, one with request_mem_region() , and one without. I'm expecting the one without will fail, but both is working just fine. Code with request_mem_region : if( request_mem_region( PIN3_CONF_PHYS, MAPPED_SIZE_GPIO_CONF,DEVICE_NAME ) == NULL ) { printk( KERN_ALERT "GPIO_140_141_conf_phys error:%s: unable to obtain I

Linux Stack Sizes

谁都会走 提交于 2019-11-27 06:53:20
I'm looking for a good description of stacks within the linux kernel, but I'm finding it surprisingly difficult to find anything useful. I know that stacks are limited to 4k for most systems, and 8k for others. I'm assuming that each kernel thread / bottom half has its own stack. I've also heard that if an interrupt goes off, it uses the current thread's stack, but I can't find any documentation on any of this. What I'm looking for is how the stacks are allocated, if there's any good debugging routines for them (I'm suspecting a stack overflow for a particular problem, and I'd like to know if

Driver code in kernel module doesn't execute?

核能气质少年 提交于 2019-11-27 06:16:14
问题 Why this kernel module doesn't do anything when i load it? #include <linux/init.h> #include <linux/module.h> #include <linux/platform_device.h> #define DEVICE_NAME "hello-1.00.a" #define DRIVER_NAME "hello" MODULE_LICENSE("Dual BSD/GPL"); static int hello_init(struct platform_device *pdev){ printk(KERN_ALERT "Hello, world\n"); return 0; } static int hello_exit(struct platform_device *pdev){ printk(KERN_ALERT "Goodbye, cruel world\n"); return 0; } static const struct of_device_id myled_of