linux-device-driver

Accessing a serial port from a linux kernel module

Deadly 提交于 2019-12-04 19:24:34
问题 Hello Linux Kernel Driver Gurus! I'm writing a v4l2 driver for a camera that uses a serial interface for configuration. I'd like the driver to configure the camera, as it keeps the client code consistent across camera models. The question is: what's the best way to access the camera's serial interface from the driver module? From what I hear, accessing files from a kernel driver is a big no-no, but it can be done. As such, I'm currently using the following code snippet, but it feels like a

What happens when a mov instruction causes a page fault with interrupts disabled on x86?

情到浓时终转凉″ 提交于 2019-12-04 16:33:01
问题 I recently encountered an issue in a custom Linux kernel (2.6.31.5, x86) driver where copy_to_user would periodically not copy any bytes to user space. It would return the count of bytes passed to it, indicating that it had not copied anything. After code inspection we found that the code was disabling interrupts while calling copy_to_user which violates it's contract. After correcting this, the issue stopped occurring. Because the issue happened so infrequently, I need to prove that

Device Tree and code size

限于喜欢 提交于 2019-12-04 16:01:32
问题 As per my understanding of device trees , one of main uses is to remove platform specific code from drivers to support multiple platforms. How does device tree handle multiple configuration for a single peripheral? For example if I want to use LCD Panel A in Platform A and LCD Panel B in Platform B, do I need to keep both LCD Panel A and Panel B related code in the final binary? If that is the case and there are multiple peripherals with more than one option, it seems there will be huge

What is a good interface for a Linux device driver for a co-processing peripheral

馋奶兔 提交于 2019-12-04 15:51:06
I've written some Linux device drivers but I am still at the level of newbie hack. I can get them working but that's all I can claim. So far, I've been able to work them into a model of write data using write() and read data using read(). I occasionally use ioctl for more fine-tuned control. Now I want to build a coprocessing block in FPGA logic and write a device driver for the ARM processor in that same FPGA to offload work from the ARM to the FPGA. I'm having a hard time working out how best to design this interface. If access to the coprocessor was exclusive, data could be written to the

Reading from a block device in kernel space

三世轮回 提交于 2019-12-04 15:36:22
I am writing a kernel module and need to perform reads from an existing block device. (/dev/something). Does anyone know of any other modules that do these that I can use as reference ? Any pointers would be welcome (Linux.2.6.30) If you really absolutely must then use the filp_open , filp_close , vfs_read and vfs_write functions. The description for for filp_open states "This is the helper to open a file from kernelspace if you really have to. But in generally you should not do this, so please move along, nothing to see here.." There is an excellent article "Driving Me Nuts - Things You Never

How to create a folder within a folder in sysfs

孤街醉人 提交于 2019-12-04 15:19:25
I am trying to create a sysfs for an implementation of mine in android and stuck at creating a folder of my own in CLASS . My requirement: /sys/class/example_class/my_sysfs_directory/file_one. Code: #include<linux/module.h> #include<linux/kernel.h> #include<linux/device.h> #include <linux/err.h> MODULE_LICENSE("GPL"); MODULE_AUTHOR("Manoj"); static ssize_t sysfs_demo_show(struct class *class, struct class_attribute *attr, char *buf) { pr_info("%s [%d]: \n", __func__, __LINE__); return sprintf(buf, "%s \n", __func__); } static ssize_t sysfs_demo_store(struct class *class, struct class_attribute

How Kernel stack is used in case of different processor mode in ARM architecture?

孤街浪徒 提交于 2019-12-04 15:13:37
As I understand every process have a user stack and kernel stack. Apart from that there is a stack for every mode in ARM achitecture. So I want to know How different stack and stack pointer works in ARM modes? Also when this kernel stack associated with the process will be used ? ... when this kernel stack associated with the process will be used ? When you make a system call. Like you want to get IP address of an interface, kernel just like any other application needs some stack to prepare what you want. So it has a corresponding stack when you switch to kernel side of a system call. How

BBB DT based approach

浪尽此生 提交于 2019-12-04 15:07:36
I have successfully implemented a GPIO based driver for my custom protocol using platform device model. I want to upgrade it using device tree approach. So for starters I have a beaglebone black, and I have cross compiled the kernel using the device tree config enabled and verified during uboot console messages showing Verifying Checksum ... OK Flattened Device Tree blob at 80f80000 Booting using the fdt blob at 0x80f80000 XIP Kernel Image ... OK OK Using Device Tree in place at 80f80000, end 80f899de I added my entry into the board common file node name my_gpio {compatible = "my_gpio" } Then

Linux transfer parameter for function in DECLARE_WORK

房东的猫 提交于 2019-12-04 14:05:47
问题 I try to programm a Event-Workqueue, but I meet some problems. I use a Linux 2.6.36 Kernel. And the DECLARE_WORK function changed from 3 parameters to 2. The question is, the old declaration was DECLARE_WORK (struct work_struct name, void (*func)(void *), void *data); And the new one is DECLARE_WORK (struct work_struct name, void (*func)(void *)); I think the void *data pointer was to give the func parameters. Is that right? And how can I do that with the new version of DECLARE_WORK? Thanks

Reading/Writing EFI variables on Linux in kernel mode

﹥>﹥吖頭↗ 提交于 2019-12-04 12:43:31
I am working on Linux UEFI .I want to access the efi variables through my driver code. Currently I'm looking linux/efi.h API like efi.get_variable(). but I'm not getting how to call those APIs with from my driver code. struct efi efi1; efi_init(); efi_char16_t *name = (efi_char16_t *)"Boot001"; efi_guid_t *vendor = (efi_guid_t *)"8be4df61-93ca-11d2-aa0d-00e098032b8c"; u32 *attr = (u32 *)0x7; unsigned long data_size = 1024; void *data = NULL; printk("\n Showing efi info \n"); stat = efi1.get_variable(name,vendor,attr,&data_size,data); with this code I'm getting NULL value for data. So can you