The anatomy of a PCI/PCI Express kernel driver



Similar documents
Programming PCI-Devices under Linux

The Bus (PCI and PCI-Express)

2. THE PCI EXPRESS BUS

I/O. Input/Output. Types of devices. Interface. Computer hardware

Computer Systems Structure Input/Output

UMBC. ISA is the oldest of all these and today s computers still have a ISA bus interface. in form of an ISA slot (connection) on the main board.

Fastboot Techniques for x86 Architectures. Marcus Bortel Field Application Engineer QNX Software Systems

PCI Express Basic Info *This info also applies to Laptops

nanoetxexpress Specification Revision 1.0 Figure 1 nanoetxexpress board nanoetxexpress Specification Rev 1.

Chapter 02: Computer Organization. Lesson 04: Functional units and components in a computer organization Part 3 Bus Structures

Linux Driver Devices. Why, When, Which, How?

An Implementation Of Multiprocessor Linux

PCI Express: Interconnect of the future

PCI Express* Ethernet Networking

COS 318: Operating Systems. I/O Device and Drivers. Input and Output. Definitions and General Method. Revisit Hardware

SiS AMD Athlon TM 64FX/PCI-E Solution. Silicon Integrated Systems Corp. Integrated Product Division April. 2004

85MIV2 / 85MIV2-L -- Components Locations

PCI vs. PCI Express vs. AGP

How PCI Express Works (by Tracy V. Wilson)

Appendix A. by Gordon Getty, Agilent Technologies

Chapter 5 Busses, Ports and Connecting Peripherals

3 Address Spaces & Transaction Routing. The Previous Chapter. This Chapter. The Next Chapter

Autonomous NetFlow Probe

Digitale Signalverarbeitung mit FPGA (DSF) Soft Core Prozessor NIOS II Stand Mai Jens Onno Krah

Chapter Introduction. Storage and Other I/O Topics. p. 570( 頁 585) Fig I/O devices can be characterized by. I/O bus connections

PEX 8748, PCI Express Gen 3 Switch, 48 Lanes, 12 Ports

Intel Server Board S5000PALR Intel Server System SR1500ALR

AwardBIOS Setup Utility

Hardware Level IO Benchmarking of PCI Express*

Chapter 5 Cubix XP4 Blade Server

Communicating with devices

The Motherboard Chapter #5

An Introduction to PCI Express

INPUT/OUTPUT ORGANIZATION

Computer Organization & Architecture Lecture #19

A+ Guide to Managing and Maintaining Your PC, 7e. Chapter 1 Introducing Hardware

PCI Express Basics Ravi Budruk Senior Staff Engineer and Partner MindShare, Inc.

Knut Omang Ifi/Oracle 19 Oct, 2015

Introduction to PCI Express Positioning Information

Chapter 1 Lesson 3 Hardware Elements in the Embedded Systems Chapter-1L03: "Embedded Systems - ", Raj Kamal, Publs.: McGraw-Hill Education

3.4 Planning for PCI Express

Programming Interface. for. Bus Master IDE Controller. Revision 1.0

A Comparison of NVMe and AHCI

Intel X58 Express Chipset

7a. System-on-chip design and prototyping platforms

Serial Communications

Computer Performance. Topic 3. Contents. Prerequisite knowledge Before studying this topic you should be able to:

ADVANCED PROCESSOR ARCHITECTURES AND MEMORY ORGANISATION Lesson-17: Memory organisation, and types of memory

REAL TIME OPERATING SYSTEM PROGRAMMING-II: II: Windows CE, OSEK and Real time Linux. Lesson-12: Real Time Linux

Chapter 11 I/O Management and Disk Scheduling

Lecture 2: Computer Hardware and Ports.

Creating a PCI Express Interconnect AJAY V. BHATT, TECHNOLOGY AND RESEARCH LABS, INTEL CORPORATION

PCI-SIG SR-IOV Primer. An Introduction to SR-IOV Technology Intel LAN Access Division

Open Flow Controller and Switch Datasheet

Chapter 6. Inside the System Unit. What You Will Learn... Computers Are Your Future. What You Will Learn... Describing Hardware Performance

White Paper: M.2 SSDs: Aligned for Speed. Comparing SSD form factors, interfaces, and software support

Phoenix SecureCore TM Setup Utility

Below is a diagram explaining the data packet and the timing related to the mouse clock while receiving a byte from the PS-2 mouse:

Application Note 120 Communicating Through the 1-Wire Master

Network connectivity controllers

ACER INC. VERITON M200 QUICK SPEC

PCIeBPMC (PCI/PCI-X Bus Compatible) Bridge based PCIe and PMC Compatible Adapter Carrier Front View shown with 1 installed fans model # PCIeBPMC-FAN2

Lizy Kurian John Electrical and Computer Engineering Department, The University of Texas as Austin

Sockets vs. RDMA Interface over 10-Gigabit Networks: An In-depth Analysis of the Memory Traffic Bottleneck

BIOS Update Release Notes

PCI Express SATA / esata 6Gb/s RAID Card User Manual

How To Port A Program To Dynamic C (C) (C-Based) (Program) (For A Non Portable Program) (Un Portable) (Permanent) (Non Portable) C-Based (Programs) (Powerpoint)

2-Serial/1-Parallel Port PCI Adapter RC303 User Manual

PCI Local Bus Specification Revision 3.0. August 12, 2002

EUCIP IT Administrator - Module 1 PC Hardware Syllabus Version 3.0

Performance of Software Switching

Machine check handling on Linux

The proliferation of the raw processing

Von der Hardware zur Software in FPGAs mit Embedded Prozessoren. Alexander Hahn Senior Field Application Engineer Lattice Semiconductor

I/O Device and Drivers

Intel DPDK Boosts Server Appliance Performance White Paper

21152 PCI-to-PCI Bridge

User Manual. PCIe to PCIe Expansion MODELS EB3600-P

PCI Express Gen 2 Deep Dive on Power Architecture Based Products

Devices and Device Controllers

An Introduction To Simple Scheduling (Primarily targeted at Arduino Platform)

ALL-USB-RS422/485. User Manual. USB to Serial Converter RS422/485. ALLNET GmbH Computersysteme Alle Rechte vorbehalten

Intel Server System S7000FC4URE-HWR

PCI-to-PCI Bridge Architecture Specification. Revision 1.1

Have both hardware and software. Want to hide the details from the programmer (user).

EDUCATION. PCI Express, InfiniBand and Storage Ron Emerick, Sun Microsystems Paul Millard, Xyratex Corporation

PCI Express and Storage. Ron Emerick, Sun Microsystems

PCI Express Overview. And, by the way, they need to do it in less time.

ENGG*44200 Real Time System Design Lab3 Implement VoIP on ARM Outline

Products. CM-i586 Highlights. Página Web 1 de 5. file://c:\documents and Settings\Daniel\Os meus documentos\humanoid\material_o...

Switch Fabric Implementation Using Shared Memory

H ARDWARE C ONSIDERATIONS

Technology Note. PCI Express

Purpose Computer Hardware Configurations... 6 Single Computer Configuration... 6 Multiple Server Configurations Data Encryption...

PCI EXPRESS TECHNOLOGY. Jim Brewer, Dell Business and Technology Development Joe Sekel, Dell Server Architecture and Technology

Computer Setup (F10) Utility Guide HP Compaq dx2200 Microtower Business PC

A Brief Tutorial on Power Management in Computer Systems. David Chalupsky, Emily Qi, & Ilango Ganga Intel Corporation March 13, 2007

TLM-2.0 in Action: An Example-based Approach to Transaction-level Modeling and the New World of Model Interoperability

Mother Board Component

Transcription:

May 16th, 2011 / June 13th, 2011 This work is released under Creative Common s CC0 license version 1.0 or later. To the extent possible under law, the author has waived all copyright and related or neighboring rights to this work.

1 Introduction 2 3 4

Introduction

Overview Introduction Kernel programming is copying from people knowing better than you. Reading PCI/PCIe drivers is being told the solution without understanding the problem. We shall try to fill that gap Part I: Understanding the hardware: Buses, PCI, PCIe, interrupts Part II: Highlights of a PCI/PCIe driver Not covered: General kernel hacking practices (character devices, mutexes, spinlocks etc.)

It s all about wires and voltages The Memory bus The I/O bus The bus clock Bus locking / wait states The Bridge and Delayed Transaction Bursts Bus mastering, bus arbitration, DMA

PCI Introduction Very slow bus in today s terms (66 MHz) Memory space (32/64 bits), I/O space, configuration space Bus Mastering (DMA) and bursts Bridges Vendor ID, Device ID, class, subclass pci.ids, lspci and kernel support of a specific device

PCI: Enumeration Bus number, Device number, Function The Configuration Header Automatic allocation of dedicated addresses segments ( BAR addresses ) by OS (BIOS on PCs)... and interrupts Tons of extensions PCIe mimics PCI, so we ll get to it later... Try lspci -tv and setpci

lspci output Introduction $ lspci 00:00.0 Host bridge: Intel Corporation Clarksfield/Lynnfield DMI (rev 11) 00:03.0 PCI bridge: Intel Corporation Clarksfield/Lynnfield PCI Express Root Port 1 (rev 11) 00:08.0 System peripheral: Intel Corporation Clarksfield/Lynnfield System Management Registe rs (rev 11) 00:08.1 System peripheral: Intel Corporation Clarksfield/Lynnfield Semaphore and Scratchpad Registers (rev 11) 00:08.2 System peripheral: Intel Corporation Clarksfield/Lynnfield System Control and Status Registers (rev 11) 00:08.3 System peripheral: Intel Corporation Clarksfield/Lynnfield Miscellaneous Registers ( rev 11) 00:10.0 System peripheral: Intel Corporation QPI Link (rev 11) 00:10.1 System peripheral: Intel Corporation QPI Routing and Protocol Registers (rev 11) 00:1a.0 USB Controller: Intel Corporation Ibex Peak USB Universal Host Controller (rev 05) 00:1a.1 USB Controller: Intel Corporation Ibex Peak USB Universal Host Controller (rev 05) 00:1a.2 USB Controller: Intel Corporation Ibex Peak USB Universal Host Controller (rev 05) 00:1a.7 USB Controller: Intel Corporation Ibex Peak USB2 Enhanced Host Controller (rev 05) 00:1b.0 Audio device: Intel Corporation Ibex Peak High Definition Audio (rev 05) 00:1c.0 PCI bridge: Intel Corporation Ibex Peak PCI Express Root Port 1 (rev 05) 00:1c.1 PCI bridge: Intel Corporation Ibex Peak PCI Express Root Port 2 (rev 05) 00:1c.3 PCI bridge: Intel Corporation Ibex Peak PCI Express Root Port 4 (rev 05)

lspci output (more) 00:1d.0 USB Controller: Intel Corporation Ibex Peak USB Universal Host Controller (rev 05) 00:1d.1 USB Controller: Intel Corporation Ibex Peak USB Universal Host Controller (rev 05) 00:1d.2 USB Controller: Intel Corporation Ibex Peak USB Universal Host Controller (rev 05) 00:1d.3 USB Controller: Intel Corporation Ibex Peak USB Universal Host Controller (rev 05) 00:1d.7 USB Controller: Intel Corporation Ibex Peak USB2 Enhanced Host Controller (rev 05) 00:1e.0 PCI bridge: Intel Corporation 82801 PCI Bridge (rev a5) 00:1f.0 ISA bridge: Intel Corporation Ibex Peak LPC Interface Controller (rev 05) 00:1f.2 SATA controller: Intel Corporation Ibex Peak 6 port SATA AHCI Controller (rev 05) 00:1f.3 SMBus: Intel Corporation Ibex Peak SMBus Controller (rev 05) 01:00.0 VGA compatible controller: ATI Technologies Inc RV710 [Radeon HD 4350] 01:00.1 Audio device: ATI Technologies Inc R700 Audio Device [Radeon HD 4000 Series] 02:00.0 SATA controller: JMicron Technologies, Inc. 20360/20363 Serial ATA Controller (rev 0 2) 02:00.1 IDE interface: JMicron Technologies, Inc. 20360/20363 Serial ATA Controller (rev 02) 03:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8111/8168B PCI Express Gigab it Ethernet controller (rev 03) 04:00.0 SATA controller: JMicron Technologies, Inc. 20360/20363 Serial ATA Controller (rev 0 3) 04:00.1 IDE interface: JMicron Technologies, Inc. 20360/20363 Serial ATA Controller (rev 03) 05:04.0 Modem: ALi Corporation SmartLink SmartPCI563 56K Modem 05:05.0 Ethernet controller: 3Com Corporation 3CSOHO100B-TX 910-A01 [tulip] (rev 31)

lspci: A tree view $ lspci -tv -[0000:00]-+-00.0 Intel Corporation Clarksfield/Lynnfield DMI +-03.0-[01]--+-00.0 ATI Technologies Inc RV710 [Radeon HD 4350] \-00.1 ATI Technologies Inc R700 Audio Device [Radeon HD 4000 Series] +-08.0 Intel Corporation Clarksfield/Lynnfield System Management Registers +-08.1 Intel Corporation Clarksfield/Lynnfield Semaphore and Scratchpad Registers +-08.2 Intel Corporation Clarksfield/Lynnfield System Control and Status Registers +-08.3 Intel Corporation Clarksfield/Lynnfield Miscellaneous Registers +-10.0 Intel Corporation QPI Link +-10.1 Intel Corporation QPI Routing and Protocol Registers +-1a.0 Intel Corporation Ibex Peak USB Universal Host Controller +-1a.1 Intel Corporation Ibex Peak USB Universal Host Controller +-1a.2 Intel Corporation Ibex Peak USB Universal Host Controller +-1a.7 Intel Corporation Ibex Peak USB2 Enhanced Host Controller +-1b.0 Intel Corporation Ibex Peak High Definition Audio +-1c.0-[02]--+-00.0 JMicron Technologies, Inc. 20360/20363 Serial ATA Controller \-00.1 JMicron Technologies, Inc. 20360/20363 Serial ATA Controller +-1c.1-[03]----00.0 Realtek Semiconductor Co., Ltd. RTL8111/8168B PCI Express Gigabit Ethernet +-1c.3-[04]--+-00.0 JMicron Technologies, Inc. 20360/20363 Serial ATA Controller \-00.1 JMicron Technologies, Inc. 20360/20363 Serial ATA Controller +-1d.0 Intel Corporation Ibex Peak USB Universal Host Controller +-1d.1 Intel Corporation Ibex Peak USB Universal Host Controller +-1d.2 Intel Corporation Ibex Peak USB Universal Host Controller +-1d.3 Intel Corporation Ibex Peak USB Universal Host Controller +-1d.7 Intel Corporation Ibex Peak USB2 Enhanced Host Controller +-1e.0-[05]--+-04.0 ALi Corporation SmartLink SmartPCI563 56K Modem \-05.0 3Com Corporation 3CSOHO100B-TX 910-A01 [tulip] +-1f.0 Intel Corporation Ibex Peak LPC Interface Controller +-1f.2 Intel Corporation Ibex Peak 6 port SATA AHCI Controller \-1f.3 Intel Corporation Ibex Peak SMBus Controller

lspci: Details Introduction The ATI card is Vendor/Product ID 1002:954f # lspci -v (...) 01:00.0 VGA compatible controller: ATI Technologies Inc RV710 [Radeon HD 4350] (prog-if 00 [VGA controller Subsystem: Giga-byte Technology Device 21ac Flags: bus master, fast devsel, latency 0, IRQ 50 Memory at e0000000 (64-bit, prefetchable) [size=256m] Memory at fbce0000 (64-bit, non-prefetchable) [size=64k] I/O ports at ae00 [size=256] [virtual] Expansion ROM at fbc00000 [disabled] [size=128k] Capabilities: [50] Power Management version 3 Capabilities: [58] Express Legacy Endpoint, MSI 00 Capabilities: [a0] MSI: Enable+ Count=1/1 Maskable- 64bit+ Capabilities: [100] Vendor Specific Information: ID=0001 Rev=1 Len=010 <?> Kernel driver in use: radeon Kernel modules: radeon # lspci -x (...) 01:00.0 VGA compatible controller: ATI Technologies Inc RV710 [Radeon HD 4350] 00: 02 10 4f 95 07 04 10 00 00 00 00 03 10 00 80 00 10: 0c 00 00 e0 00 00 00 00 04 00 ce fb 00 00 00 00 20: 01 ae 00 00 00 00 00 00 00 00 00 00 58 14 ac 21 30: 00 00 00 00 50 00 00 00 00 00 00 00 0b 01 00 00

I/O Mapped I/O It makes sense, doesn t it? But it s deprecated on new designs (parallel port at 0x0378, anyone?) Widely used (on chipsets?), but to be removed from future PCIe spec. Delayed Transaction not allowed on I/O writes. (but is on Memory writes) PCI and PCIe alike. 16 bits addressing on x86. Depends on architecture. PCI allows 32 bits. Check out /proc/ioports for your own computer s mapping.

Memory mapped I/O The processor thinks it s memory, so does the compiler. So they optimize. Read prefetching (side effects?) Write reordering (Reset and kick-off writes?) Cache coherency and flushing Read memory-barriers.txt in the kernel source s Documentation. volatile-considered-harmful.txt and circular-buffers.txt are recommended as well. IOMMU Check out /proc/iomem for your own computer s mapping.

The Interrupt Introduction A processor will make a jump to a known address more or less immediately Physical interrupt lines are limited PCI has INTA, INTB, INTC, INTD. Interrupt sharing: Everyone answers the phone Edge triggered can t be shared, and double interrupts are missed Level triggered can MSI: Message Signalled Interrupt. The savior. Check out /proc/interrupts to get the nudges.

PCI express Introduction PCI Express is not PCI-X! It s not a bus, it s a packet network of 32 bit elements Hotpluggable, energy saving (for laptops...) Each device has its own dedicated wires Bus switches as routers Transaction Layer Packets (TLPs) instead of bus transactions Posted and non-posted bus requests Data flow control, error detection and retransmit Design to look, feel and smell like PCI Full backward compatibility and interoperability with legacy PCI (including INTx)

PCI express (cont.) Lanes: 1x, 2x, 4x, 8x, 16x Speeds: PCIe 1.0: 2.5 Gb/s raw bits, 2.0 Gb/s data bits, parallel to 62.5 MHz 32-bit bus...... in both directions! Doubled in PCIe 2.0, and sky is the limit Multiple lanes work in sync to transmit 32-bit words faster. The specification is wisely designed... and horribly written

How a (sane) PCI/PCIe device works The BAR address space (mapped in memory or I/O space) is used for control registers The driver allocates buffers in RAM The addresses of these buffers are written in control registers The device reads and writes from the buffer via DMA All this it timed and orchestrated via control registers... and interrupts Video cards may take a different strategy.

This device is mine! static const struct pci_device_id foo_ids[] = { {.class = 0x000000,.class_mask = 0x000000,.vendor = 0xdead,.device = 0xbeef,.subvendor = PCI_ANY_ID,.subdevice = PCI_ANY_ID,.driver_data = 0 /* Arbitrary data, hence zero */ }, { /* End: all zeroes */ } };

Declarations Introduction Somewhere at the end of the module... MODULE_DEVICE_TABLE(pci, foo_ids); static struct pci_driver foo_driver = {.name = "foo",.id_table = foo_ids,.probe = foo_probe,.remove = devexit_p(foo_remove), };

Finishing up the bureaucratics Still at the end of the module... static int init foo_init(void) { return pci_register_driver(&foo_driver); } static void exit foo_exit(void) { pci_unregister_driver(&foo_driver); } module_init(foo_init); module_exit(foo_exit);

What we have, what we ll do We ve told the kernel which device(s) we want to handle Kernel will invoke our probe function when meeting one such... in process context So for the sake of example, all code from here on belongs to the probe function In reality, the real action happens in the character / block / network device s code The operations are shown in a possible real-life order

The probe method static int devinit foo_probe(struct pci_dev *pdev, const struct pci_device_id *ent) { struct foo_privdata *privdata; int rc = 0; int i; privdata = kzalloc(sizeof(*privdata), GFP_KERNEL); if (!privdata) { printk(kern_err "foo: Failed to allocate memory.\n"); return -ENOMEM; } pci_set_drvdata(pdev, privdata);

Enabling the device rc = pci_enable_device(pdev); if (rc) { printk(kern_err "foo: pci_enable_device() failed.\n"); goto no_enable; }

A small sanity check Checking that BAR 0 is defined and memory mapped: if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) { printk(kern_err "foo: Incorrect BAR configuration.\n"); rc = -ENODEV; goto bad_bar; }

Taking ownership of a memory region rc = pci_request_regions(pdev, "foo"); if (rc) { printk(kern_err "foo: pci_request_regions() failed.\n"); goto failed_request_regions; } After this, foo will show up in /proc/iomem

Obtaining our impression of the BAR address Assuming that our device s configuration header requests 128 bytes on BAR 0: privdata->registers = pci_iomap(pdev, 0, 128); if (!privdata->registers) { printk(kern_err "foo: Failed to map BAR 0.\n"); goto failed_iomap0; } iowrite32(1, &privdata->registers[0x10]); mmiowb(); /* Some holy water never hurts */ registers is pointer to u32.

Reading a bit... for (i=0; i<16; i++) printk(kern_info "foo: Register 0x%x = 0x%x \n", i, ioread32(&privdata->registers[i])); Also common in the kernel: inp, outp, writel, readl, writew, readw, writeb, readb, ioread8, ioread16, iowrite8, iowrite16

Enabling mastership and MSI pci_set_master(pdev); /* Set up a single MSI interrupt */ if (pci_enable_msi(pdev)) { printk(kern_err "foo: Failed to enable MSI.\n"); rc = -ENODEV; goto failed_enable_msi; }

32 or 64 bit? Introduction if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) privdata->dma_using_dac = 1; else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) privdata->dma_using_dac = 0; else { printk(kern_err "foo: Failed to set DMA mask.\n"); rc = -ENODEV; goto failed_dmamask; }

Allocating aligned memory int memorder = 2; privdata->mem = (u32 *) get_free_pages(gfp_kernel GFP_DMA GFP_ZERO, memorder); if (!privdata->mem) { printk(kern_err "foo: Failed to allocate memory.\n"); rc = -ENOMEM; goto failed_dmamem; } printk(kern_info "foo: Got %ld bytes at 0x%x\n", PAGE_SIZE * (1 << memorder), (u32) privdata->mem);

DMA mapping Introduction dma_mem = pci_map_single(pdev, privdata->mem, PAGE_SIZE * (1 << memorder), PCI_DMA_FROMDEVICE); if (pci_dma_mapping_error(pdev, dma_mem)) { printk(kern_err "foo: Failed to map memory).\n"); rc = -ENOMEM; goto failed_dmamap; } dma mem is a dma addr t, which may be a u64 or a u32, depending on the CONFIG X86 64 or CONFIG HIGHMEM64G kernel compilation flags.

Preparing for DMA Tell the device what the DMA address is, and if 64 bits should be used... iowrite32( (u32) (dma_mem & 0xffffffff), &privdata->registers[0x0c]); iowrite32( ( (u32) ( ( dma_mem >> 32) & 0xffffffff) ), &privdata->registers[0x0d]); iowrite32( privdata->dma_using_dac, &privdata->registers[0x08]); mmiowb(); /* Hope the holy water works */ Warning: Is the PCI device aware of the host s endianess?

Setting up the interrupt handler init_waitqueue_head(&privdata->waitq); rc = request_irq(pdev->irq, foo_msi, 0, "foo", privdata); if (rc) { printk(kern_err "foo: Failed to register MSI.\n"); rc = -ENODEV; goto failed_register_msi; } waitq is of type wait queue head t

A short diversion: The MSI handler static irqreturn_t foo_msi(int irq, void *data) { struct foo_privdata *privdata = data; privdata->flag = 1; wake_up_interruptible(&privdata->waitq); } return IRQ_HANDLED; Important: On a non-msi handler, checking that our device really asserted the interrupt is mandatory.

A simple DMA cycle privdata->flag = 0; iowrite32( (u32) 1, &privdata->registers[0x09]); /* GO! */ wait_event_interruptible(privdata->waitq, (privdata->flag!= 0)); if (privdata->flag == 0) { printk(kern_err "foo: Interrupted!.\n"); rc = -ENODEV; goto failed_wait_irq; } This is correct if we assume no other process waits on the queue, and may clear the flag. It works for the probe() method and if we have a mutex held. Otherwise, the return value is the correct indicator.

A simple DMA cycle (cont.) pci_dma_sync_single_for_cpu(pdev, privdata->dma_mem, PAGE_SIZE * (1 << memorder), PCI_DMA_FROMDEVICE); for (i=0; i<16; i++) printk(kern_info "foo: Read at index %d: %x\n", i, privdata->mem[i]); pci_dma_sync_single_for_device(pdev, privdata->dma_mem, PAGE_SIZE * (1 << memorder), PCI_DMA_FROMDEVICE);

DMA flavors Introduction Consistent DMA Streaming DMA mapped and unmapped every use Streaming DMA mapped once (as shown here) Scatter-gather See DMA-API-HOWTO.txt in the kernel docs

Letting go Introduction (trivial memory releases excluded) pci_unmap_single(pdev, privdata->dma_mem, PAGE_SIZE * (1 << memorder), PCI_DMA_FROMDEVICE); free_pages ((unsigned long) privdata->mem, memorder); free_irq(pdev->irq, privdata); pci_disable_msi(pdev); pci_clear_master(pdev); /* Nobody seems to do this */ pci_iounmap(pdev, privdata->registers); pci_release_regions(pdev); pci_disable_device(pdev);

Thank you! Introduction Questions?