linux-device-driver

max732x.c I2C IO Expander + GPIO Keys w/ Linux Device Tree not working

删除回忆录丶 提交于 2019-11-30 09:36:12
问题 I'm working with a Freescale MX6 and a 3.10.31 Freescale modified kernel. I have a Maxim MAX7325 used as an IO expander, which has pushbuttons attached to P0-P2. The interrupt line from the 7325 is attached to the GPIO_3 pad (which I believe is GPIO1_3...) I set up the 7325 and gpio-keys in the device tree like this: max7325_reset: max7325-reset { compatible = "gpio-reset"; reset-gpios = <&gpio5 16 GPIO_ACTIVE_LOW>; reset-delay-us = <1>; #reset-cells = <0>; }; gpio-keys { compatible = "gpio

copy_to_user vs memcpy

老子叫甜甜 提交于 2019-11-30 09:03:16
I have always been told(In books and tutorials) that while copying data from kernel space to user space, we should use copy_to_user() and using memcpy() would cause problems to the system. Recently by mistake i have used memcpy() and it worked perfectly fine with out any problems. Why is that we should use copy_to_user instead of memcpy() My test code(Kernel module) is something like this: static ssize_t test_read(struct file *file, char __user * buf, size_t len, loff_t * offset) { char ani[100]; if (!*offset) { memset(ani, 'A', 100); if (memcpy(buf, ani, 100)) return -EFAULT; *offset = 100;

How to establish adb connection over USB between two PCs [closed]

我是研究僧i 提交于 2019-11-30 08:55:41
问题 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 3 years ago . Summary (What we've done, what we've tried): Basically, the aim is to establish an adb protocol via usb between two linux computers by using adb source codes. Envinronment is Ubuntu 16.0.4. There's android-tools-adbd (adb daemon) package ready for use in the pool with its source

Implementing poll in a Linux kernel module

六眼飞鱼酱① 提交于 2019-11-30 07:30:21
问题 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

How to attach file operations to sysfs attribute in platform driver?

别说谁变了你拦得住时间么 提交于 2019-11-30 07:26:42
I wrote a platform driver for a peripheral we developed and would like to expose some configuration options to the sysfs. I have managed to create the appropriate files using attribute structs (see below) and sysfs_create_file in the probe function, but I can't figure out how to attach the show/store functions to the structs in a platform driver. Most resources I found online used a device_attribute struct or something similar to create their files, is that also appropriate here? Is there another way to do this for a platform driver? My attribute struct looks like this: struct attribute subkey

How to include C backtrace in a kernel module code?

我的梦境 提交于 2019-11-30 06:32:37
问题 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

proc_create() example for kernel module

谁都会走 提交于 2019-11-30 06:23:04
问题 Can someone give me proc_create() example? Earlier they used create_proc_entry() in the kernel but now they are using proc_create() . 回答1: 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;

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

杀马特。学长 韩版系。学妹 提交于 2019-11-30 06:12:01
问题 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

How linux drive many network cards with the same driver?

南楼画角 提交于 2019-11-30 04:48:11
问题 I am learning linux network driver recently, and I wonder that if I have many network cards in same type on my board, how does the kernel drive them? Does the kernel need to load the same driver many times? I think it's not possible, insmod won't do that, so how can I make all same kind cards work at same time? regards 回答1: The state of every card (I/O addresses, IRQs, ...) is stored into a driver-specific structure that is passed (directly or indirectly) to every entry point of the driver

How to filter and intercept Linux packets by using net_dev_add() API?

随声附和 提交于 2019-11-30 04:02:45
I'm writing ethernet network driver for linux. I want to receive packets, edit and resend them. I know how to edit the packet in packet_interceptor function, but how can I drop incoming packets in this function?? #include <linux/netdevice.h> #include <linux/skbuff.h> #include <linux/ip.h> #include <net/sock.h> struct packet_type my_proto; int packet_interceptor(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, struct net_device *orig_dev) { // I dont want certain packets go to upper in net_devices for further processing. // How can I drop sk_buff here?! return 0; } static