Mastering Linux Device Driver Development
eBook - ePub

Mastering Linux Device Driver Development

Write custom device drivers to support computer peripherals in Linux operating systems

John Madieu

  1. 646 pagine
  2. English
  3. ePUB (disponibile sull'app)
  4. Disponibile su iOS e Android
eBook - ePub

Mastering Linux Device Driver Development

Write custom device drivers to support computer peripherals in Linux operating systems

John Madieu

Dettagli del libro
Anteprima del libro
Indice dei contenuti
Citazioni

Informazioni sul libro

Master the art of developing customized device drivers for your embedded Linux systemsKey Features• Stay up to date with the Linux PCI, ASoC, and V4L2 subsystems and write device drivers for them• Get to grips with the Linux kernel power management infrastructure• Adopt a practical approach to customizing your Linux environment using best practicesBook DescriptionLinux is one of the fastest-growing operating systems around the world, and in the last few years, the Linux kernel has evolved significantly to support a wide variety of embedded devices with its improved subsystems and a range of new features. With this book, you'll find out how you can enhance your skills to write custom device drivers for your Linux operating system.Mastering Linux Device Driver Development provides complete coverage of kernel topics, including video and audio frameworks, that usually go unaddressed. You'll work with some of the most complex and impactful Linux kernel frameworks, such as PCI, ALSA for SoC, and Video4Linux2, and discover expert tips and best practices along the way. In addition to this, you'll understand how to make the most of frameworks such as NVMEM and Watchdog. Once you've got to grips with Linux kernel helpers, you'll advance to working with special device types such as Multi-Function Devices (MFD) followed by video and audio device drivers.By the end of this book, you'll be able to write feature-rich device drivers and integrate them with some of the most complex Linux kernel frameworks, including V4L2 and ALSA for SoC.What you will learn• Explore and adopt Linux kernel helpers for locking, work deferral, and interrupt management• Understand the Regmap subsystem to manage memory accesses and work with the IRQ subsystem• Get to grips with the PCI subsystem and write reliable drivers for PCI devices• Write full multimedia device drivers using ALSA SoC and the V4L2 framework• Build power-aware device drivers using the kernel power management framework• Find out how to get the most out of miscellaneous kernel subsystems such as NVMEM and WatchdogWho this book is forThis book is for embedded developers, Linux system engineers, and system programmers who want to explore Linux kernel frameworks and subsystems. C programming skills and a basic understanding of driver development are necessary to get started with this book.

Domande frequenti

Come faccio ad annullare l'abbonamento?
È semplicissimo: basta accedere alla sezione Account nelle Impostazioni e cliccare su "Annulla abbonamento". Dopo la cancellazione, l'abbonamento rimarrà attivo per il periodo rimanente già pagato. Per maggiori informazioni, clicca qui
È possibile scaricare libri? Se sì, come?
Al momento è possibile scaricare tramite l'app tutti i nostri libri ePub mobile-friendly. Anche la maggior parte dei nostri PDF è scaricabile e stiamo lavorando per rendere disponibile quanto prima il download di tutti gli altri file. Per maggiori informazioni, clicca qui
Che differenza c'è tra i piani?
Entrambi i piani ti danno accesso illimitato alla libreria e a tutte le funzionalità di Perlego. Le uniche differenze sono il prezzo e il periodo di abbonamento: con il piano annuale risparmierai circa il 30% rispetto a 12 rate con quello mensile.
Cos'è Perlego?
Perlego è un servizio di abbonamento a testi accademici, che ti permette di accedere a un'intera libreria online a un prezzo inferiore rispetto a quello che pagheresti per acquistare un singolo libro al mese. Con oltre 1 milione di testi suddivisi in più di 1.000 categorie, troverai sicuramente ciò che fa per te! Per maggiori informazioni, clicca qui.
Perlego supporta la sintesi vocale?
Cerca l'icona Sintesi vocale nel prossimo libro che leggerai per verificare se è possibile riprodurre l'audio. Questo strumento permette di leggere il testo a voce alta, evidenziandolo man mano che la lettura procede. Puoi aumentare o diminuire la velocità della sintesi vocale, oppure sospendere la riproduzione. Per maggiori informazioni, clicca qui.
Mastering Linux Device Driver Development è disponibile online in formato PDF/ePub?
Sì, puoi accedere a Mastering Linux Device Driver Development di John Madieu in formato PDF e/o ePub, così come ad altri libri molto apprezzati nelle sezioni relative a Computer Science e System Administration. Scopri oltre 1 milione di libri disponibili nel nostro catalogo.

Informazioni

Anno
2021
ISBN
9781789342208
Edizione
1

Section 1:Kernel Core Frameworks for Embedded Device Driver Development

This section deals with the Linux kernel core, introducing the abstraction layers and facilities that the Linux kernel offers, in order to reduce the development efforts. Moreover, in this section we will learn about the Linux clock framework, thanks to which most peripherals on the system are driven.
This section contains the following chapters:
  • Chapter 1, Linux Kernel Concepts for Embedded Developers
  • Chapter 2, Leveraging the Regmap API and Simplifying the Code
  • Chapter 3, Delving into the MFD Subsystem and the Syscon API
  • Chapter 4, Storming the Common Clock Framework

Chapter 1: Linux Kernel Concepts for Embedded Developers

As a standalone software, the Linux kernel implements a set of functions that help not to reinvent the wheel and ease device driver developments. The importance of these helpers is that it’s not a requirement to use these for code to be accepted upstream. This is the kernel core that drivers rely on. We’ll cover the most popular of these core functionalities in this book, though other ones also exist. We will begin by looking at the kernel locking API before discussing how to protect shared objects and avoid race conditions. Then, we will look at various work deferring mechanisms available, where you will learn what part of the code to defer in which execution context. Finally, you will learn how interrupts work and how to design interrupt handlers from within the Linux kernel.
This chapter will cover the following topics:
  • The kernel locking API and shared objects
  • Work deferring mechanisms
  • Linux kernel interrupt management
Let’s get started!

Technical requirements

To understand and follow this chapter’s content, you will need the following:
  • Advanced computer architecture knowledge and C programming skills
  • Linux kernel 4.19 sources, available at https://github.com/torvalds/linux

The kernel locking API and shared objects

A resource is said to be shared when it can be accessed by several contenders, regardless of their exclusively. When they are exclusive, access must be synchronized so that only the allowed contender(s) may own the resource. Such resources might be memory locations or peripheral devices, while the contenders might be processors, processes, or threads. Operating systems perform mutual exclusion by atomically (that is, by means of an operation that can be interrupted) modifying a variable that holds the current state of the resource, making this visible to all contenders that might access the variable at the same time. This atomicity guarantees that the modification will either be successful, or not successful at all. Nowadays, modern operating systems rely on the hardware (which should allow atomic operations) used for implementing synchronization, though a simple system may ensure atomicity by disabling interrupts (and avoiding scheduling) around the critical code section.
In this section, we’ll describe the following two synchronization mechanisms:
  • Locks: Used for mutual exclusion. When one contender holds the lock, no other contender can hold it (others are excluded). The most well-known locking primitives in the kernel are spinlocks and mutexes.
  • Conditional variables: Mostly used to sense or wait for a state change. These are implemented differently in the kernel, as we will see later, mainly in the Waiting, sensing, and blocking in the Linux kernel section.
When it comes to locking, it is up to the hardware to allow such synchronizations by means of atomic operations. The kernel then uses these to implement locking facilities. Synchronization primitives are data structures that are used for coordinating access to shared resources. Because only one contender can hold the lock (and thus access the shared resource), it might perform an arbitrary operation on the resource associated with the lock that would appear to be atomic to others.
Apart from dealing with the exclusive ownership of a given shared resource, there are situations where it is better to wait for the state of the resource to change; for example, waiting for a list to contain at least one object (its state then passes from empty to not empty) or for a task to complete (a DMA transaction, for example). The Linux kernel does not implement conditional variables. From our user space, we could think of using a conditional variable for both situations, but to achieve the same or even better, the kernel provides the following mechanisms:
  • Wait queue: Mainly used to wait for a state change. It’s designed to work in concert with locks.
  • Completion queue: Used to wait for a given computation to complete.
Both mechanisms are supported by the Linux kernel and are exposed to drivers thanks to a reduced set of APIs (which significantly ease their use when used by a developer). We will discuss these in the upcoming sections.

Spinlocks

A spinlock is a hardware-based locking primitive. It depends on the capabilities of the hardware at hand to provide atomic operations (such as test_and_set, which, in a non-atomic implementation, would result in read, modify, and write operations). Spinlocks are essentially used in an atomic context where sleeping is not allowed or simply not needed (in interrupts, for example, or when you want to disable preemption), but also as an inter-CPU locking primitive.
It is the simplest locking primitive and also the base one. It works as follows:
Figure 1.1 – Spinlock contention flow
Figure 1.1 – Spinlock con...

Indice dei contenuti

  1. Mastering Linux Device Driver Development
  2. Why subscribe?
  3. Preface
  4. Section 1:Kernel Core Frameworks for Embedded Device Driver Development
  5. Chapter 1: Linux Kernel Concepts for Embedded Developers
  6. Chapter 2: Leveraging the Regmap API and Simplifying the Code
  7. Chapter 3: Delving into the MFD Subsystem and Syscon API
  8. Chapter 4: Storming the Common Clock Framework
  9. Section 2: Multimedia and Power Saving in Embedded Linux Systems
  10. Chapter 5: ALSA SoC Framework – Leveraging Codec and Platform Class Drivers
  11. Chapter 6: ALSA SoC Framework – Delving into the Machine Class Drivers
  12. Chapter 7: Demystifying V4L2 and Video Capture Device Drivers
  13. Chapter 8: Integrating with V4L2 Async and Media Controller Frameworks
  14. Chapter 9:Leveraging the V4L2 API from the User Space
  15. Chapter 10: Linux Kernel Power Management
  16. Section 3: Staying Up to Date with Other Linux Kernel Subsystems
  17. Chapter 11: Writing PCI Device Drivers
  18. Chapter 12: Leveraging the NVMEM Framework
  19. Chapter 13: Watchdog Device Drivers
  20. Chapter 14: Linux Kernel Debugging Tips and Best Practices
  21. Other Books You May Enjoy
Stili delle citazioni per Mastering Linux Device Driver Development

APA 6 Citation

Madieu, J. (2021). Mastering Linux Device Driver Development (1st ed.). Packt Publishing. Retrieved from https://www.perlego.com/book/2094756/mastering-linux-device-driver-development-write-custom-device-drivers-to-support-computer-peripherals-in-linux-operating-systems-pdf (Original work published 2021)

Chicago Citation

Madieu, John. (2021) 2021. Mastering Linux Device Driver Development. 1st ed. Packt Publishing. https://www.perlego.com/book/2094756/mastering-linux-device-driver-development-write-custom-device-drivers-to-support-computer-peripherals-in-linux-operating-systems-pdf.

Harvard Citation

Madieu, J. (2021) Mastering Linux Device Driver Development. 1st edn. Packt Publishing. Available at: https://www.perlego.com/book/2094756/mastering-linux-device-driver-development-write-custom-device-drivers-to-support-computer-peripherals-in-linux-operating-systems-pdf (Accessed: 15 October 2022).

MLA 7 Citation

Madieu, John. Mastering Linux Device Driver Development. 1st ed. Packt Publishing, 2021. Web. 15 Oct. 2022.