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 páginas
  2. English
  3. ePUB (apto para móviles)
  4. Disponible en iOS y Android
eBook - ePub

Mastering Linux Device Driver Development

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

John Madieu

Detalles del libro
Vista previa del libro
Índice
Citas

Información del 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.

Preguntas frecuentes

¿Cómo cancelo mi suscripción?
Simplemente, dirígete a la sección ajustes de la cuenta y haz clic en «Cancelar suscripción». Así de sencillo. Después de cancelar tu suscripción, esta permanecerá activa el tiempo restante que hayas pagado. Obtén más información aquí.
¿Cómo descargo los libros?
Por el momento, todos nuestros libros ePub adaptables a dispositivos móviles se pueden descargar a través de la aplicación. La mayor parte de nuestros PDF también se puede descargar y ya estamos trabajando para que el resto también sea descargable. Obtén más información aquí.
¿En qué se diferencian los planes de precios?
Ambos planes te permiten acceder por completo a la biblioteca y a todas las funciones de Perlego. Las únicas diferencias son el precio y el período de suscripción: con el plan anual ahorrarás en torno a un 30 % en comparación con 12 meses de un plan mensual.
¿Qué es Perlego?
Somos un servicio de suscripción de libros de texto en línea que te permite acceder a toda una biblioteca en línea por menos de lo que cuesta un libro al mes. Con más de un millón de libros sobre más de 1000 categorías, ¡tenemos todo lo que necesitas! Obtén más información aquí.
¿Perlego ofrece la función de texto a voz?
Busca el símbolo de lectura en voz alta en tu próximo libro para ver si puedes escucharlo. La herramienta de lectura en voz alta lee el texto en voz alta por ti, resaltando el texto a medida que se lee. Puedes pausarla, acelerarla y ralentizarla. Obtén más información aquí.
¿Es Mastering Linux Device Driver Development un PDF/ePUB en línea?
Sí, puedes acceder a Mastering Linux Device Driver Development de John Madieu en formato PDF o ePUB, así como a otros libros populares de Computer Science y System Administration. Tenemos más de un millón de libros disponibles en nuestro catálogo para que explores.

Información

Año
2021
ISBN
9781789342208
Edición
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...

Índice

  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
Estilos de citas para 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.