售 价:¥
温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印
为你推荐
Title Page
Copyright
Linux Device Drivers Development
Credits
About the Author
About the Reviewer
www.PacktPub.com
Why subscribe?
Customer Feedback
Dedication
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
Introduction to Kernel Development
Environment setup
Getting the sources
Source organization
Kernel configuration
Build your kernel
Kernel habits
Coding style
Kernel structures allocation/initialization
Classes, objects, and OOP
Summary
Device Driver Basis
User space and kernel space
The concept of modules
Module dependencies
depmod utility
Module loading and unloading
Manual loading
modprobe and insmod
/etc/modules-load.d/<filename>.conf
Auto-loading
Module unload
Driver skeletons
Module entry and exit point
__init and __exit attributes
Module information
Licensing
Module author(s)
Module description
Errors and message printing
Error handling
Handling null pointer errors
Message printing – printk()
Module parameters
Building your first module
The module's makefile
In the kernel tree
Out of the tree
Building the module
Summary
Kernel Facilities and Helper Functions
Understanding container_of macro
Linked lists
Creating and initializing the list
Dynamic method
Static method
Creating a list node
Adding a list node
Deleting a node from the list
Linked list traversal
Kernel sleeping mechanism
Wait queue
Delay and timer management
Standard timers
Jiffies and HZ
Timers API
Timer setup initialization
Standard timer example
High resolution timers (HRTs)
HRT API
HRT setup initialization
Dynamic tick/tickless kernel
Delays and sleep in the kernel
Atomic context
Nonatomic context
Kernel locking mechanism
Mutex
Mutex API
Declare
Acquire and release
Spinlock
Spinlock versus mutexes
Work deferring mechanism
Softirqs and ksoftirqd
ksoftirqd
Tasklets
Declaring a tasklet
Enabling and disabling a tasklet
Tasklet scheduling
Work queues
Kernel-global workqueue – the shared queue
Dedicated work queue
Programming syntax
Predefined (shared) workqueue and standard workqueue functions
Kernel threads
Kernel interruption mechanism
Registering an interrupt handler
Interrupt handler and lock
Concept of bottom halves
The problem – interrupt handler design limitations
The solution – bottom halves
Tasklets as bottom halves
Workqueue as bottom halves
Softirqs as bottom half
Threaded IRQs
Threaded bottom half
Invoking user-space applications from the kernel
Summary
Character Device Drivers
The concept behind major and minor
Device number allocation and freeing
Introduction to device file operations
File representation in the kernel
Allocating and registering a character device
Writing file operations
Exchanging data between kernel space and user space
A single value copy
The open method
Per-device data
The release method
The write method
Steps to write
The read method
Steps to read
The llseek method
Steps to llseek
The poll method
Steps to poll
The ioctl method
Generating ioctl numbers (command)
Steps for ioctl
Filling the file_operations structure
Summary
Platform Device Drivers
Platform drivers
Platform devices
Resources and platform data
Device provisioning - the old and depreciated way
Resources
Platform data
Where to declare platform devices?
Device provisioning - the new and recommended way
Devices, drivers, and bus matching
How can platform devices and platform drivers match?
Kernel devices and drivers-matching function
OF style and ACPI match
ID table matching
Name matching - platform device name matching
Summary
The Concept of Device Tree
Device tree mechanism
Naming convention
Aliases, labels, and phandle
DT compiler
Representing and addressing devices
SPI and I2C addressing
Platform device addressing
Handling resources
Concept of named resources
Accessing registers
Handling interrupts
The interrupt handler
Interrupt controller code
Extract application-specific data
Text string
Cells and unsigned 32-bit integers
Boolean
Extract and parse sub-nodes
Platform drivers and DT
OF match style
Dealing with non-device tree platforms
Support multiple hardware with per device-specific data
Match style mixing
Platform resources and DT
Platform data versus DT
Summary
I2C Client Drivers
The driver architecture
The i2c_driver structure
The probe() function
Per-device data
The remove() function
Driver initialization and registration
Driver and device provisioning
Accessing the client
Plain I2C communication
System Management Bus (SMBus) compatible functions
Instantiating I2C devices in the board configuration file (old and depreciated way)
I2C and the device tree
Defining and registering the I2C driver
Remark
Instantiating I2C devices in the device tree - the new way
Putting it all together
Summary
SPI Device Drivers
The driver architecture
The device structure
spi_driver structure
The probe() function
Per-device data
The remove() function
Driver initialization and registration
Driver and devices provisioning
Instantiate SPI devices in board configuration file – old and depreciated way
SPI and device tree
Instantiate SPI devices in device tree - the new way
Define and register SPI driver
Accessing and talking to the client
Putting it all together
SPI user mode driver
With IOCTL
Summary
Regmap API – A Register Map Abstraction
Programming with the regmap API
regmap_config structure
regmap initialization
SPI initialization
I2C initialization
Device access functions
regmap_update_bits function
Special regmap_multi_reg_write function
Other device access functions
regmap and cache
Putting it all together
A regmap example
Summary
IIO Framework
IIO data structures
iio_dev structure
iio_info structure
IIO channels
Channel attribute naming conventions
Distinguishing channels
Putting it all together
Triggered buffer support
IIO trigger and sysfs (user space)
Sysfs trigger interface
add_trigger file
remove_trigger file
Tying a device with a trigger
The interrupt trigger interface
The hrtimer trigger interface
IIO buffers
IIO buffer sysfs interface
IIO buffer setup
Putting it all together
IIO data access
One-shot capture
Buffer data access
Capturing using the sysfs trigger
Capturing using the hrtimer trigger
IIO tools
Summary
Kernel Memory Management
System memory layout - kernel space and user space
Kernel addresses – concept of low and high memory
Low memory
High memory
User space addresses
Virtual Memory Area (VMA)
Address translation and MMU
Page look up and TLB
How does TLB work
Memory allocation mechanism
Page allocator
Page allocation API
Conversion functions
Slab allocator
The buddy algorithm
A journey into the slab allocator
kmalloc family allocation
vmalloc allocator
Process memory allocation under the hood
The copy-on-write (CoW) case
Work with I/O memory to talk with hardware
PIO devices access
MMIO devices access
__iomem cookie
Memory (re)mapping
kmap
Mapping kernel memory to user space
Using remap_pfn_range
Using io_remap_pfn_range
The mmap file operation
Implementing mmap in the kernel
Linux caching system
What is a cache?
CPU cache – memory caching
The Linux page cache – disk caching
Specialized caches (user space caching)
Why delay writing data to disk?
Write caching strategies
The flusher threads
Device-managed resources – Devres
Summary
DMA – Direct Memory Access
Setting up DMA mappings
Cache coherency and DMA
DMA mappings
Coherent mapping
Streaming DMA mapping
Single buffer mapping
Scatter/gather mapping
Concept of completion
DMA engine API
Allocate a DMA slave channel
Set slave and controller specific parameters
Get a descriptor for transaction
Submit the transaction
Issue pending DMA requests and wait for callback notification
Putting it all together – NXP SDMA (i.MX6)
DMA DT binding
Consumer binding
Summary
Linux Device Model
LDM data structures
The bus
Bus registration
Device driver
Device driver registration
Device
Device registration
Deep inside LDM
kobject structure
kobj_type
ksets
Attribute
Attributes group
Device model and sysfs
Sysfs files and attributes
Current interfaces
Device attributes
Bus attributes
Device drivers attributes
Class attributes
Allow sysfs attribute files to be pollable
Summary
Pin Control and GPIO Subsystem
Pin control subsystem
Pinctrl and the device tree
The GPIO subsystem
The integer-based GPIO interface: legacy
Claiming and configuring the GPIO
Accessing the GPIO – getting/setting the value
In atomic context
In a non-atomic context (that may sleep)
GPIOs mapped to IRQ
Putting it all together
The descriptor-based GPIO interface: the new and recommended way
GPIO descriptor mapping - the device tree
Allocating and using GPIO
Putting it all together
The GPIO interface and the device tree
The legacy integer-based interface and device tree
GPIO mapping to IRQ in the device tree
GPIO and sysfs
Exporting a GPIO from kernel code
Summary
GPIO Controller Drivers – gpio_chip
Driver architecture and data structures
Pin controller guideline
Sysfs interface for GPIO controller
GPIO controllers and DT
Summary
Advanced IRQ Management
Multiplexing interrupts and interrupt controllers
Advanced peripheral IRQs management
Interrupt request and propagation
Chaining IRQ
Chained interrupts
Nested interrupts
Case study – GPIO and IRQ chip
Legacy GPIO and IRQ chip
New gpiolib irqchip API
Interrupt controller and DT
Summary
Input Devices Drivers
Input device structures
Allocating and registering an input device
Polled input device sub-class
Generating and reporting an input event
User space interface
Putting it all together
Driver examples
Summary
RTC Drivers
RTC framework data structures
RTC API
Reading and setting time
Driver example
Playing with alarms
RTCs and user space
The sysfs interface
The hwclock utility
Summary
PWM Drivers
PWM controller driver
Driver example
PWM controller binding
PWM consumer interface
PWM clients binding
Using PWMs with the sysfs interface
Summary
Regulator Framework
PMIC/producer driver interface
Driver data structures
Description structure
Constraints structure
init data structure
Feeding init data into a board file
Feeding init data into the DT
Configuration structure
Device operation structure
Driver methods
Probe function
Remove function
Case study: Intersil ISL6271A voltage regulator
Driver example
Regulators consumer interface
Regulator device requesting
Controlling the regulator device
Regulator output enable and disable
Voltage control and status
Current limit control and status
Operating mode control and status
Regulator binding
Summary
Framebuffer Drivers
Driver data structures
Device methods
Driver methods
Detailed fb_ops
Checking information
Set controller's parameters
Screen blanking
Accelerated methods
Putting it all together
Framebuffer from user space
Summary
Network Interface Card Drivers
Driver data structures
The socket buffer structure
Socket buffer allocation
Network interface structure
The device methods
Opening and closing
Packet handling
Packet reception
Packet transmission
Driver example
Status and control
The interrupt handler
Ethtool support
Driver methods
The probe function
Module unloading
Summary
买过这本书的人还买过
读了这本书的人还在读
同类图书排行榜