万本电子书0元读

万本电子书0元读

顶部广告

Linux Device Drivers Development电子书

售       价:¥

20人正在读 | 0人评论 9.8

作       者:John Madieu

出  版  社:Packt Publishing

出版时间:2017-10-20

字       数:69.3万

所属分类: 进口书 > 外文原版书 > 电脑/网络

温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印

为你推荐

  • 读书简介
  • 目录
  • 累计评论(0条)
  • 读书简介
  • 目录
  • 累计评论(0条)
Learn to develop customized device drivers for your embedded Linux system About This Book ? Learn to develop customized Linux device drivers ? Learn the core concepts of device drivers such as memory management, kernel caching, advanced IRQ management, and so on. ? Practical experience on the embedded side of Linux Who This Book Is For This book will help anyone who wants to get started with developing their own Linux device drivers for embedded systems. Embedded Linux users will benefit highly from this book. This book covers all about device driver development, from char drivers to network device drivers to memory management. What You Will Learn ? Use kernel facilities to develop powerful drivers ? Develop drivers for widely used I2C and SPI devices and use the regmap API ? Write and support devicetree from within your drivers ? Program advanced drivers for network and frame buffer devices ? Delve into the Linux irqdomain API and write interrupt controller drivers ? Enhance your skills with regulator and PWM frameworks ? Develop measurement system drivers with IIO framework ? Get the best from memory management and the DMA subsystem ? Access and manage GPIO subsystems and develop GPIO controller drivers In Detail Linux kernel is a complex, portable, modular and widely used piece of software, running on around 80% of servers and embedded systems in more than half of devices throughout the World. Device drivers play a critical role in how well a Linux system performs. As Linux has turned out to be one of the most popular operating systems used, the interest in developing proprietary device drivers is also increasing steadily. This book will initially help you understand the basics of drivers as well as prepare for the long journey through the Linux Kernel. This book then covers drivers development based on various Linux subsystems such as memory management, PWM, RTC, IIO, IRQ management, and so on. The book also offers a practical approach on direct memory access and network device drivers. By the end of this book, you will be comfortable with the concept of device driver development and will be in a position to write any device driver from scratch using the latest kernel version (v4.13 at the time of writing this book). Style and approach A set of engaging examples to develop Linux device drivers
目录展开

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

累计评论(0条) 0个书友正在讨论这本书 发表评论

发表评论

发表评论,分享你的想法吧!

买过这本书的人还买过

读了这本书的人还在读

回顶部