linux-device-driver

Using Linux virtual mouse driver

让人想犯罪 __ 提交于 2019-12-04 12:19:05
I am trying to implement a virtual mouse driver according to the Essential Linux device Drivers book. There is a user space application, which generates coordinates as well as a kernel module. See: Virtual mouse driver and userspace application code and also a step by step on how to use this driver. 1.) I compile the code of the user space application and driver. 2.) Next i checked dmesg output and have, input: Unspecified device as /class/input/input32 Virtual Mouse Driver Initialized 3.) The sysfs node was created properly during initialization (found in /sys/devices/platform/vms/coordinates

Is low latency mode safe to use with Linux serial ports?

拜拜、爱过 提交于 2019-12-04 10:50:01
Is it safe to use the low_latency tty mode with Linux serial ports? The tty_flip_buffer_push function is documented that it "must not be called from IRQ context if port->low_latency is set." Nevertheless, many low-level serial port drivers call it from an ISR whether or not the flag is set. For example, the mpc52xx driver calls flip buffer unconditionally after each read from its FIFO. A consequence of the low latency flip buffer in the ISR is that the line discipline driver is entered within the IRQ context. My goal is to get latency of one millisecond or less, reading from a high speed

Exactly when tasklet runs after it is schedule by ISR?

不打扰是莪最后的温柔 提交于 2019-12-04 10:41:18
I written my ISR and my tasklet ran immediately. BUT , I have seen people saying that tasklet runs only when it gets CPU attention. This is a very generic term CPU attention so i recite for those responders. I mean exactly which moment cpu attention goes to tasklet execution and what happen to the state of CPU ? Secondly, if suppose that i am keep on getting hard interrupt then when will tasklet get chance to run? Is it possible that tasklet may not get chance to run? How does kernel take care these things ? TL;DR: Tasklets are run by ksoftirq threads who are handled by Scheduler. Tasklet is

Memory usage of a kernel module

筅森魡賤 提交于 2019-12-04 09:17:33
问题 While trying to estimate the amount of memory consumed by a kernel module (usually device drivers),I tried using the size utility which gave the size of the static memory areas of the .ko ( .bss, .data, .text etc). So I was expecting the sum of these values to be exactly equal to the output given by the lsmod command immediately after inserting the module. No dynamic memory allocation(kmalloc or vmalloc) is performed in the init() function to ensure that it isn't causing the difference.So why

How to get current process's UID and EUID in Linux Kernel 4.2?

╄→尐↘猪︶ㄣ 提交于 2019-12-04 09:15:42
As LDD3 chapter 6 p175 show, we can get current process UID and EUID by current->uid and current->euid . But the definition of struct task_struct of Linux Kernel 4.2 don't contain fields named by uid or euid any more. So, I wonder if there are any other methods to get UID and EUID ? Thanks! .uid and .euid fields were moved to struct cred , which is now exposed as .cred field in struct task_struct . It was done in this commit: CRED: Separate task security context from task_struct . If you look at diff for include/linux/sched.h file, you can notice this change: - uid_t uid,euid,suid,fsuid; - gid

Call a userspace function from within a Linux kernel module

纵饮孤独 提交于 2019-12-04 07:38:52
I'm programming a simple Linux character device driver to output data to a piece of hardware via I/O ports. I have a function which performs floating point operations to calculate the correct output for the hardware; unfortunately this means I need to keep this function in userspace since the Linux kernel doesn't handle floating point operations very nicely. Here's a pseudo representation of the setup (note that this code doesn't do anything specific, it just shows the relative layout of my code): Userspace function : char calculate_output(char x){ double y = 2.5*x; double z = sqrt(y); char

Passing Bootargs via Chosen node in Device Tree not working for Beaglebone Black

♀尐吖头ヾ 提交于 2019-12-04 07:30:24
As per my understanding chosen node is used to send boot arguments to the kernel. The following is the chosen node of the existing device code (am335x-bone-common.dtsi). chosen { stdout-path = &uart0; }; So, I have modified chosen node to pass kernel arguments. chosen { bootargs = "console=ttyO0,115200 root=/dev/mmcblk0p2 rootfstype=ext3 rw rootwait"; stdout-path = &uart0; }; While bringing up the board I encountered KERNEL PANIC, Here is the log { https://pastebin.com/XHyrsmfG } FYI: These are the u-boot commands issued on serial console(minicom) inorder to port kernel and devicetree using

How GPIO is mapped in memory?

妖精的绣舞 提交于 2019-12-04 06:50:11
I am recently browsing GPIO driver for pi2, I found user space pi2 GPIO lib (like RPi.GPIO 0.5.11 of python) use /dev/mem for BCM2708 (begins at 0x20000000,and GPIO begins at 0x200000 relatively) to mmap a user space memory region in order to handler GPIO. But I found drivers/gpio in linux source tree is designed to be handled by /sys/class/gpio/* . I found nothing like I/O ports mapping like request_io_region and __io_remap . My question is How GPIO for BCM2708 mapped in memory ? Is there another driver? And can I handle GPIO just by R&W to /sys/class/gpio/* ? I found nothing like I/O ports

SCSI Read (10) and Write (10) with the SCSI Generic Interface

放肆的年华 提交于 2019-12-04 06:05:23
I try to issue a scsi read(10) and write(10) to a SSD. I use this example code as a reference/basic code. This is my scsi read: #define READ_REPLY_LEN 32 #define READ_CMDLEN 10 void scsi_read() { unsigned char Readbuffer[ SCSI_OFF + READ_REPLY_LEN ]; unsigned char cmdblk [ READ_CMDLEN ] = { 0x28, /* command */ 0, /* lun/reserved */ 0, /* lba */ 0, /* lba */ 0, /* lba */ 0, /* lba */ 0, /* reserved */ 0, /* transfer length */ READ_REPLY_LEN, /* transfer length */ 0 };/* reserved/flag/link */ memset(Readbuffer,0,sizeof(Readbuffer)); memcpy( cmd + SCSI_OFF, cmdblk, sizeof(cmdblk) ); /* * +-------

modinfo() equivalent INSIDE kernel?

百般思念 提交于 2019-12-04 06:04:03
问题 I have two modules A, B. A has a function f() that is globally acessible, i.e. the f() symbol is exported. B may want to call f() occasionally. But B should only call f() if module A is loaded. What is the best way for B to tell if A is loaded? Part b to this question is there is a way to check if f() is exported? I'm not sure which method is more effecient. 回答1: I assume you load module B first, then optionally module A. My strategy would be to have A register a set of functions with B when