linux-device-driver

kernel stack and user space stack

邮差的信 提交于 2019-11-26 23:14:27
What's the difference between kernel stack and user stack? Why kernel stack is used? If a local variable is declared in an ISR, where it will be stored? Does each process has its own kernel stack? Then how the process coordinates between both these stacks? FrankH. What's the difference between kernel stack and user stack ? In short, nothing - apart from using a different location in memory (and hence a different value for the stackpointer register), and usually different memory access protections. I.e. when executing in user mode, kernel memory (part of which is the kernel stack) will not be

How do you read the mouse button state from /dev/input/mice?

旧时模样 提交于 2019-11-26 22:56:20
问题 How do you read the mouse button state from /dev/input/mice? I want to detect if the button is pressed down. 回答1: You can open the device and read from it. Events from /dev/input/mice are 3 bytes long and require some parsing. I think the prefered method now is to use /dev/input/event# instead. However, here is a small example using /dev/input/mice. #include <stdio.h> #include <unistd.h> #include <fcntl.h> int main(int argc, char** argv) { int fd, bytes; unsigned char data[3]; const char

What is the difference between module_init and subsys_initcall while initializing the driver?

房东的猫 提交于 2019-11-26 22:22:41
问题 What is the difference between module_init and subsys_initcall while initializing the driver? 回答1: The difference relates to timing, or more precisely, order of execution. That is, the procedure declared as subsys_initcall is guaranteed to be executed before the procedure declared as module_init . This ordering ensures that subsystem and platform drivers are initialized before device drivers try to utilize the former's functionality (e.g. a device driver registers as a subsystem device). The

IOCTL Linux device driver [closed]

孤者浪人 提交于 2019-11-26 18:43:47
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 4 months ago . Can anyone explain me, What is IOCTL ? What is it used for? How can I use it? Why can't I define new function that does the same work as IOCTL ? 回答1: An ioctl , which means "input-output control" is a kind of device-specific system call. There are only a few system calls in Linux

How do the files in '/dev' match Linux's model of a device? [closed]

时光怂恿深爱的人放手 提交于 2019-11-26 16:38:25
问题 Here is my understanding in opening to a file for reading/writing. In the application layer, I can invoke the fopen() function. The fwrite() function will invoke a system call open() . After the OS receives the open() call, it will pass the command to VFS(virtual file system). VFS looks up the file name, including any directories needed and does the necessary access checks. If this is in RAM cache then no disk access is needed. If not, the VFS sends a read request to the specific file system

Is it possible to set CFLAGS to a linux kernel module Makefile?

早过忘川 提交于 2019-11-26 16:27:27
问题 Eg: a common device module's Makefile obj-m:=jc.o default: $(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) modules clean: $(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) modules clean I consider if I can set CFLAGS to the file. When I change default section to $(MAKE) -O2 -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) modules But it didn't work. Any help? Thanks a lot. 回答1: -O2 would be an option to make (or $(MAKE) , as you're using it) in what you tried

Adding new driver code to linux source code

梦想的初衷 提交于 2019-11-26 15:29:17
问题 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? 回答1: To cross compile your own driver in the arm architecture you have to follow some steps as mentioned below. Create a directory like my

init function invocation of drivers compiled into kernel

旧街凉风 提交于 2019-11-26 14:25:29
问题 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 ? 回答1: 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

How to use netlink socket to communicate with a kernel module?

南笙酒味 提交于 2019-11-26 13:59:24
I am trying to write a linux kernel module that communicates with user process using netlink. I am using netlink because the user program I want to communicate to communicates only using sockets and I cant change that to add ioctl() or anything. Problem is that I cant figure out how to do that. I have googled but all examples I found are for old like this one and no longer valid for current kernel versions. I have also looked at this SO question but the sample here uses libnl for socket operations but I want to stick to standard socket functions (defined by sys/socket.h ). So can some one plz

Linux Stack Sizes

耗尽温柔 提交于 2019-11-26 12:57:40
问题 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