linux-device-driver

Who calls “probe” function in driver code?

怎甘沉沦 提交于 2019-12-03 08:44:16
问题 I am trying to understand this driver code of mcspi for omap2 panda board. I don't understand who calls the probe function and what is the call chain in this driver code? How does the driver is informed when the device is connected? 回答1: The probe function from spi-omap2-mcspi.c is saved in the static struct platform_driver omap2_mcspi_driver , which is registered with module_platform_driver(omap2_mcspi_driver); (at the end of file). The module_platform_driver macro, defined in platform

Linux kernel: why do 'subclass' structs put base class info at end?

时间秒杀一切 提交于 2019-12-03 08:37:43
问题 I was reading the chapter in Beautiful Code on the Linux kernel and the author discusses how Linux kernel implements inheritance in the C language (amongst other topics). In a nutshell, a 'base' struct is defined and in order to inherit from it the 'subclass' struct places a copy of the base at the end of the subclass struct definition. The author then spends a couple pages explaining a clever and complicated macro to figure out how many bytes to back in order to convert from the base part of

Linux driver DMA transfer to a PCIe card with PC as master

馋奶兔 提交于 2019-12-03 07:07:36
I am working on a DMA routine to transfer data from PC to a FPGA on a PCIe card. I read DMA-API.txt and LDD3 ch. 15 for details. However, I could not figure out how to do a DMA transfer from PC to a consistent block of iomem on the PCIe card. The dad sample for PCI in LDD3 maps a buffer and then tells the card to do the DMA transfer, but I need the PC to do this. What I already found out: Request bus master pci_set_master(pdev); Set the DMA mask if (dma_set_mask(&(pdev->dev), DMA_BIT_MASK(32))) { dev_err(&pdev->dev,"No suitable DMA available.\n"); goto cleanup; } Request a DMA channel if

Detect the presence of a device when it's hot plugged in Linux

被刻印的时光 ゝ 提交于 2019-12-03 06:59:40
问题 I am running the SPI code on the panda board and I want to know which function in the code is responsible for detecting the device when it's hot plugged. Can somebody with the background of embedded systems, Linux device drivers and/or spi please answer my question? 回答1: This is the line in your code that does the magic: 1286 MODULE_DEVICE_TABLE(of, omap_mcspi_of_match); Process: 1. Driver for each device exposes its information using the API MODULE_DEVICE_TABLE . Each device has a unique

Explain list_for_each_entry and list_for_each_entry_safe

十年热恋 提交于 2019-12-03 05:52:59
问题 Can anyone explain the working of list_for_each_entry and ...entry_safe loop in linux. It is like list_for_each_entry(type *cursor, struct list_head *list, member) list_for_each_entry_safe(type *cursor, type *next, struct list_head *list,member) What are the role of all these parameters and how they are used to traverse the list. Thanks in ADVANCE 回答1: EDIT: sorry, it must be late, I've made a lot of typos. They are pure fun! :) The difference is that list_for_each_entry will break if you

Difference between Kernel Virtual Address and Kernel Logical Address?

冷暖自知 提交于 2019-12-03 05:09:36
问题 I am not able to exactly difference between kernel logical address and virtual address. In Linux device driver book it says that all logical address are kernel virtual address, and virtual address doesn't have any linear mapping. But logically wise when we say it is logical and when we say virtual and in which situation we use these two ? 回答1: The Linux kernel maps most of the virtual address space that belongs to the kernel to perform 1:1 mapping with an offset of the first part of physical

Finding original MAC address from Hardware itself

a 夏天 提交于 2019-12-03 04:20:33
Os:REDHAT LINUX Linux manage: 2.6.18.8-1 # Is this possible to read MAC address form NIC directly ? I have below code but it just read from above layer but not the card itself !!! I'm trying to figure out how to find the original MAC address of an ethernet NIC on my linux box. I understand how to find the current MAC address using ifconfig, but if the address has been changed, say by using 'ifconfig eth0 hw ether uu:vv:ww:yy:xx:zz' ,or I set "permanent" it using vi /etc/sysconfig/network-scripts/ifcfg-eth0 .this file...I can successfully UP it in REBOOT also. how do I find the original? There

How can I programmatically set permissions on my char device

拜拜、爱过 提交于 2019-12-03 04:16:42
I've recently inherited some code at work, this is old 2.4.X linux kernel drivers and I've been tasked with getting them working on a newer kernel 2.6 or greater. I'm running on OpenSUSE 12.1 with a 3.1.10 kernel. I've updated the original code from register_chrdev() to use class_create()/device_create() calls and I can see my devices show up in /dev correctly. My current issue is that the permissions for my device are being set to r/w for user only: crw------- 1 root root 244, 0 Aug 7 07:57 gcanain I know I can "chmod" the file via command line, and or I can set up udev permissions... but is

How do I intercept messages from a USB device on Linux?

戏子无情 提交于 2019-12-03 04:15:37
问题 I have a popular drawing tablet that I connect to my PC with USB. Once connected, the tablet detects hand movements and manipulates the pointer accordingly. Somewhere, the tablet is transmitting this data to my computer. My goal is to intercept these transmissions and manipulate the mouse after I process the data. The buzzwords I have found are: device drivers and HID , but I haven't been able to piece together much more than that. Assuming this is possible, I have a few questions: How is

“FATAL: Module not found error” using modprobe

南笙酒味 提交于 2019-12-03 04:15:28
问题 I have a problem with modprobe command... I compiled the hello world module and loaded it with insmod , it works fine and when I do lsmod , I can see it in the output list. But when I insert this module using modprobe I am getting a FATAL error: root@okapi:/home/ravi# modprobe ./hello.ko FATAL: Module ./hello.ko not found. root@okapi:/home/ravi# Here is the module code: #include <linux/init.h> #include <linux/module.h> MODULE_LICENSE("Dual BSD/GPL"); static int hello_init(void) { printk(KERN