You are previewing FreeBSD Device Drivers.
O'Reilly logo
FreeBSD Device Drivers

Book Description

FreeBSD Device Drivers is the first and only book to teach readers how to develop device drivers for the FreeBSD operating system.

Table of Contents

  1. FreeBSD Device Drivers
  2. About the Technical Reviewer
  3. Foreword
  4. Acknowledgments
  5. Introduction
    1. Who Is This Book For?
    2. Prerequisites
    3. Contents at a Glance
    4. Welcome Aboard!
  6. 1. Building and Running Modules
    1. Types of Device Drivers
    2. Loadable Kernel Modules
      1. Module Event Handler
      2. DECLARE_MODULE Macro
        1. name
        2. data
        3. sub
        4. order
    3. Hello, world!
    4. Compiling and Loading
    5. Character Drivers
      1. d_foo Functions
      2. Character Device Switch Table
      3. make_dev and destroy_dev Functions
    6. Mostly Harmless
      1. echo_write Function
      2. echo_read Function
      3. echo_modevent Function
      4. DEV_MODULE Macro
      5. Don’t Panic
    7. Block Drivers Are Gone
    8. Conclusion
  7. 2. Allocating Memory
    1. Memory Management Routines
    2. malloc_type Structures
      1. MALLOC_DEFINE Macro
      2. MALLOC_DECLARE Macro
    3. Tying Everything Together
    4. Contiguous Physical Memory Management Routines
    5. A Straightforward Example
    6. Conclusion
  8. 3. Device Communication and Control
    1. ioctl
    2. Defining ioctl Commands
    3. Implementing ioctl
      1. echo_write Function
      2. echo_set_buffer_size Function
      3. echo_ioctl Function
      4. echo_modevent Function
      5. Don’t Panic
    4. Invoking ioctl
    5. sysctl
    6. Implementing sysctls, Part 1
    7. sysctl Context Management Routines
    8. Creating Dynamic sysctls
      1. SYSCTL_STATIC_CHILDREN Macro
      2. SYSCTL_CHILDREN Macro
    9. Implementing sysctls, Part 2
      1. sysctl_set_buffer_size Function
      2. Don’t Panic
    10. Conclusion
  9. 4. Thread Synchronization
    1. A Simple Synchronization Problem
    2. A More Complex Synchronization Problem
      1. race_new Function
      2. race_find Function
      3. race_destroy Function
      4. race_ioctl Function
      5. race_modevent Function
      6. The Root of the Problem
    3. Preventing Race Conditions
    4. Mutexes
      1. Spin Mutexes
      2. Sleep Mutexes
    5. Mutex Management Routines
    6. Implementing Mutexes
      1. race_modevent Function
      2. Don’t Panic
    7. Shared/Exclusive Locks
    8. Shared/Exclusive Lock Management Routines
    9. Implementing Shared/Exclusive Locks
    10. Reader/Writer Locks
    11. Reader/Writer Lock Management Routines
    12. Condition Variables
    13. Condition Variable Management Routines
    14. General Guidelines
      1. Avoid Recursing on Exclusive Locks
      2. Avoid Holding Exclusive Locks for Long Periods of Time
    15. Conclusion
  10. 5. Delaying Execution
    1. Voluntary Context Switching, or Sleeping
    2. Implementing Sleeps and Condition Variables
      1. sleep_modevent Function
      2. load Function
      3. sleep_thread Function
      4. sysctl_debug_sleep_test Function
      5. unload Function
      6. Don’t Panic
    3. Kernel Event Handlers
    4. Callouts
    5. Callouts and Race Conditions
    6. Taskqueues
      1. Global Taskqueues
      2. Taskqueue Management Routines
    7. Conclusion
  11. 6. Case Study: Virtual Null Modem
    1. Prerequisites
    2. Code Analysis
      1. nmdm_modevent Function
      2. nmdm_clone Function
      3. nmdm_alloc Function
      4. nmdm_outwakeup Function
      5. nmdm_task_tty Function
      6. nmdm_inwakeup Function
      7. nmdm_modem Function
      8. nmdm_param Function
      9. nmdm_timeout Function
      10. bits_per_char Function
      11. Don’t Panic
    3. Conclusion
  12. 7. Newbus and Resource Allocation
    1. Autoconfiguration and Newbus Drivers
      1. device_foo Functions
      2. Device Method Table
      3. DRIVER_MODULE Macro
        1. name
        2. busname
        3. driver
        4. devclass
        5. evh
        6. arg
    2. Tying Everything Together
      1. foo_pci_probe Function
      2. foo_pci_attach Function
      3. d_foo Functions
      4. foo_pci_detach Function
      5. Don’t Panic
    3. Hardware Resource Management
    4. Conclusion
  13. 8. Interrupt Handling
    1. Registering an Interrupt Handler
    2. Interrupt Handlers in FreeBSD
    3. Implementing an Interrupt Handler
      1. pint_identify Function
      2. pint_probe Function
      3. pint_attach Function
      4. pint_detach Function
      5. pint_open Function
      6. pint_close Function
      7. pint_write Function
      8. pint_read Function
      9. pint_intr Function
      10. Don’t Panic
    4. Generating Interrupts on the Parallel Port
    5. Conclusion
  14. 9. Case Study: Parallel Port Printer Driver
    1. Code Analysis
      1. lpt_identify Function
      2. lpt_probe Function
      3. lpt_detect Function
      4. lpt_port_test Function
      5. lpt_attach Function
      6. lpt_detach Function
      7. lpt_open Function
      8. lpt_read Function
      9. lpt_write Function
      10. lpt_intr Function
      11. lpt_timeout Function
      12. lpt_push_bytes Function
      13. lpt_close Function
      14. lpt_ioctl Function
      15. lpt_request_ppbus Function
      16. lpt_release_ppbus Function
    2. Conclusion
  15. 10. Managing and Using Resources
    1. I/O Ports and I/O Memory
      1. Reading from I/O Ports and I/O Memory
      2. Writing to I/O Ports and I/O Memory
      3. Stream Operations
    2. Memory Barriers
    3. Tying Everything Together
      1. led_identify Function
      2. led_probe Function
      3. led_attach Function
      4. led_detach Function
      5. led_open Function
      6. led_close Function
      7. led_read Function
      8. led_write Function
    4. Conclusion
  16. 11. Case Study: Intelligent Platform Management Interface Driver
    1. Code Analysis
      1. ipmi_pci_probe Function
      2. ipmi_pci_match Function
      3. ipmi_pci_attach Function
      4. ipmi2_pci_probe Function
      5. ipmi2_pci_attach Function
    2. Conclusion
  17. 12. Direct Memory Access
    1. Implementing DMA
      1. Initiating a DMA Data Transfer
      2. Dismantling DMA
    2. Creating DMA Tags
    3. Tearing Down DMA Tags
    4. DMA Map Management Routines, Part 1
    5. Loading (DMA) Buffers into DMA Maps
      1. bus_dma_segment Structures
      2. bus_dmamap_load Function
      3. bus_dmamap_load_mbuf Function
      4. bus_dmamap_load_mbuf_sg Function
      5. bus_dmamap_load_uio Function
      6. bus_dmamap_unload Function
    6. DMA Map Management Routines, Part 2
    7. A Straightforward Example
    8. Synchronizing DMA Buffers
    9. Conclusion
  18. 13. Storage Drivers
    1. disk Structures
      1. Descriptive Fields
      2. Storage Device Methods
      3. Mandatory Media Properties
      4. Optional Media Properties
      5. Driver Private Data
    2. disk Structure Management Routines
    3. Block I/O Structures
    4. Block I/O Queues
    5. Tying Everything Together
      1. at45d_attach Function
      2. at45d_delayed_attach Function
      3. at45d_get_info Function
      4. at45d_wait_for_device_ready Function
      5. at45d_get_status Function
      6. at45d_strategy Function
      7. at45d_task Function
    6. Block I/O Completion Routines
    7. Conclusion
  19. 14. Common Access Method
    1. How CAM Works
    2. A (Somewhat) Simple Example
      1. mfip_attach Function
      2. mfip_detach Function
      3. mfip_action Function
      4. mfip_poll Function
      5. mfip_start Function
      6. mfip_done Function
    3. SIM Registration Routines
      1. cam_simq_alloc Function
      2. cam_sim_alloc Function
      3. xpt_bus_register Function
    4. Action Routines
      1. XPT_PATH_INQ
      2. XPT_RESET_BUS
      3. XPT_GET_TRAN_SETTINGS
      4. XPT_SET_TRAN_SETTINGS
      5. XPT_SCSI_IO
      6. XPT_RESET_DEV
    5. Conclusion
  20. 15. USB Drivers
    1. About USB Devices
    2. More About USB Devices
    3. USB Configuration Structures
      1. Mandatory Fields
      2. Optional Fields
      3. USB Transfer Flags
    4. USB Transfers (in FreeBSD)
    5. USB Configuration Structure Management Routines
    6. USB Methods Structure
    7. Tying Everything Together
      1. ulpt_probe Function
      2. ulpt_attach Function
      3. ulpt_detach Function
      4. ulpt_open Function
      5. ulpt_reset Function
      6. unlpt_open Function
      7. ulpt_close Function
      8. ulpt_ioctl Function
      9. ulpt_watchdog Function
      10. ulpt_start_read Function
      11. ulpt_stop_read Function
      12. ulpt_start_write Function
      13. ulpt_stop_write Function
      14. ulpt_write_callback Function
      15. ulpt_read_callback Function
      16. ulpt_status_callback Function
    8. Conclusion
  21. 16. Network Drivers, Part 1: Data Structures
    1. Network Interface Structures
    2. Network Interface Structure Management Routines
      1. ether_ifattach Function
      2. ether_ifdetach Function
    3. Network Interface Media Structures
    4. Network Interface Media Structure Management Routines
    5. Hello, world!
    6. mbuf Structures
    7. Message Signaled Interrupts
    8. Implementing MSI
    9. MSI Management Routines
    10. Conclusion
  22. 17. Network Drivers, Part 2: Packet Reception and Transmission
    1. Packet Reception
      1. em_rxeof Function
      2. em_handle_rx Function
    2. Packet Transmission
      1. em_start_locked Function
      2. em_txeof Function
    3. Post Packet Transmission
    4. Conclusion
  23. References
  24. Index
  25. About the Author
  26. Colophon
  27. A. UPDATES