linux-device-driver

How to include C backtrace in a kernel module code?

柔情痞子 提交于 2019-11-28 19:16:49
So I am trying to find out what kernel processes are calling some functions in a block driver. I thought including backtrace() in the C library would make it easy. But I am having trouble to load the backtrace. I copied this example function to show the backtrace: http://www.linuxjournal.com/files/linuxjournal.com/linuxjournal/articles/063/6391/6391l1.html All attempts to compile have error in one place or another that a file cannot be found or that the functions are not defined. Here is what comes closest. In the Makefile I put the compiler directives: -rdynamic -I/usr/include If I leave out

How would one prevent MMAP from caching values?

此生再无相见时 提交于 2019-11-28 19:15:42
问题 I've written a linux driver that ioremaps exports PCI BAR0 for a particular device to a sysfs binary attribute allowing userspace to directly control it. The problem rears when I attempt to MMAP on top of the attribute to directly access that bit of memory (from a userland program). Reads succeed just fine and return expected values, though when I write to that memory it appears to be cached somewhere between the kernel and memory and not delivered to the GMCH root complex (and therefore the

What is the Linux built-in driver load order?

徘徊边缘 提交于 2019-11-28 19:15:02
How can we customize the built-in driver load order (to make some built-in driver module load first, and the dependent module load later)? Built-in drivers wont be loaded , hence built-in. Their initialization functions are called and the drivers are activated when kernel sets up itself. These init functions are called in init/main.c::do_initcalls() . All init calls are classified in levels, which are defined in initcall_levels and include/linux/init.h These levels are actuall symbols defined in linker script ( arch/*/kernel/vmlinux.lds.* ). At kernel compile time, the linker collects all

Hard time in understanding MODULE_DEVICE_TABLE(usb, id_table) usage

[亡魂溺海] 提交于 2019-11-28 17:55:56
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? brokenfoot It is usually used to support hot-plugging, by loading/inserting the driver for a device if not already loaded. There is a similar question here: Detect the presence of

proc_create() example for kernel module

回眸只為那壹抹淺笑 提交于 2019-11-28 17:51:19
Can someone give me proc_create() example? Earlier they used create_proc_entry() in the kernel but now they are using proc_create() . Fred This example will create a proc entry which enables reading access. I think you can enable other kinds of access by changing the mode argument passed to the function. I haven't passed a parent directory because there is no need to. The structure file_operations is where you setup your reading and writing callbacks. struct proc_dir_entry *proc_file_entry; static const struct file_operations proc_file_fops = { .owner = THIS_MODULE, .open = open_callback,

Userspace vs kernel space driver

柔情痞子 提交于 2019-11-28 17:30:05
I am looking to write a PWM driver. I know that there are two ways we can control a hardware driver: User space driver. Kernel space driver If in general (do not consider a PWM driver case) we have to make a decision whether to go for user space or kernel space driver. Then what factors we have to take into consideration apart from these? User space driver can directly mmap() /dev/mem memory to their virtual address space and need no context switching. Userspace driver cannot have interrupt handlers implemented (They have to poll for interrupt). Userspace driver cannot perform DMA (As DMA

Who calls the probe() of driver

浪尽此生 提交于 2019-11-28 15:54:10
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. Mircea Long story short: the probe() function of the driver is called as a result of calling the register_driver for that specific bus. More precisely, it's called by the probe() of that bus_type structure. In your case: i2c

Linux kernel device driver to DMA from a device into user-space memory

本小妞迷上赌 提交于 2019-11-28 15:32:33
I want to get data from a DMA enabled, PCIe hardware device into user-space as quickly as possible. Q: How do I combine "direct I/O to user-space with/and/via a DMA transfer" Reading through LDD3, it seems that I need to perform a few different types of IO operations!? dma_alloc_coherent gives me the physical address that I can pass to the hardware device. But would need to have setup get_user_pages and perform a copy_to_user type call when the transfer completes. This seems a waste, asking the Device to DMA into kernel memory (acting as buffer) then transferring it again to user-space. LDD3

How does the linux kernel manage less than 1GB physical memory?

爷,独闯天下 提交于 2019-11-28 15:05:13
I'm learning the linux kernel internals and while reading "Understanding Linux Kernel", quite a few memory related questions struck me. One of them is, how the Linux kernel handles the memory mapping if the physical memory of say only 512 MB is installed on my system. As I read, kernel maps 0(or 16) MB-896MB physical RAM into 0xC0000000 linear address and can directly address it. So, in the above described case where I only have 512 MB: How can the kernel map 896 MB from only 512 MB ? In the scheme described, the kernel set things up so that every process's page tables mapped virtual addresses

Linux kernel device driver programming [closed]

眉间皱痕 提交于 2019-11-28 15:03:08
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. 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 other concepts such as signals, processes/threads and so on with this free resource. This is a must