Programming PCI-Devices under Linux



Similar documents
PCI-to-PCI Bridge Architecture Specification. Revision 1.1

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.

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

21152 PCI-to-PCI Bridge

Intel 8255x 10/100 Mbps Ethernet Controller Family

The Bus (PCI and PCI-Express)

Computer Systems Structure Input/Output

Mbps PCI LAN Controller A Guide to Compatibility

H ARDWARE C ONSIDERATIONS

SCSI device drivers are provided for the following operating systems: Microsoft Windows NT Server 4.0 Novell NetWare 5.1

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

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

An Implementation Of Multiprocessor Linux

AcerAltos-1200_2CPU_PIII-866. Hardware Certification Report Vendor and Model Information

NOTICE. The information in this manual is subject to change without notice.

21154 PCI-to-PCI Bridge

What is a bus? A Bus is: Advantages of Buses. Disadvantage of Buses. Master versus Slave. The General Organization of a Bus

Xinying Wang, Cong Xu CS 423 Project

The anatomy of a PCI/PCI Express kernel driver

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

Intel N440BX Server System Event Log (SEL) Error Messages

I/O Products IC697VSC096

EUCIP IT Administrator - Module 1 PC Hardware Syllabus Version 3.0

INTRODUCTION INSTALLING THE SCSI CARD 2940UW PRO

PCM-3662 PC/104-plus Ethernet Module

Application Note. Introduction AN2471/D 3/2003. PC Master Software Communication Protocol Specification

C440GX+ System Event Log (SEL) Messages

Storage. The text highlighted in green in these slides contain external hyperlinks. 1 / 14

PCI-5565PIORC* Ultrahigh Speed Fiber-Optic Reflective Memory with Interrupts PRODUCT MANUAL REV. A

MICROPROCESSOR. Exclusive for IACE Students iacehyd.blogspot.in Ph: /422 Page 1

PCAN-ISA. CAN Interface for ISA. User Manual

Mother Board Component

1. Computer System Structure and Components

Knut Omang Ifi/Oracle 19 Oct, 2015

The Motherboard Chapter #5

Low Profile Ultra ATA-133 RAID PCI Host

PCI Local Bus Specification Revision 3.0. August 12, 2002

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

PCI BIOS SPECIFICATION. Revision 2.1

MPC603/MPC604 Evaluation System

Machine check handling on Linux

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

Appendix A. by Gordon Getty, Agilent Technologies

System Installation. 3-1 Socket 370 Celeron/Pentium-III Processor. Installing S370 CPU. Removing CPU. Configuring System Bus

2. THE PCI EXPRESS BUS

Datasheet CPV5375. CompactPCI Host Slot Processor Board. Intel Pentium III BGA2 processor

Chapter 11 I/O Management and Disk Scheduling

Intel Server Board S5000PALR Intel Server System SR1500ALR

Communicating with devices

Chapter 5 Cubix XP4 Blade Server

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

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

COMPUTERS ORGANIZATION 2ND YEAR COMPUTE SCIENCE MANAGEMENT ENGINEERING UNIT 5 INPUT/OUTPUT UNIT JOSÉ GARCÍA RODRÍGUEZ JOSÉ ANTONIO SERRA PÉREZ

OpenSPARC T1 Processor

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

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

Computer Organization & Architecture Lecture #19

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

Bandwidth Calculations for SA-1100 Processor LCD Displays

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

85MIV2 / 85MIV2-L -- Components Locations

Chapter 11: Input/Output Organisation. Lesson 06: Programmed IO

H ARDWARE C ONSIDERATIONS

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

General FAQ s E-Pos Systems.

OpenVox Communication Co. LTD. OpenVox-Best Cost Effective Asterisk Cards

Chapter 3 Operating-System Structures

Devices and Device Controllers

SATA II 4 Port PCI RAID Card RC217 User Manual

PCI ATA 133 RAID Controller Card. User Manual

Lesson Objectives. To provide a grand tour of the major operating systems components To provide coverage of basic computer system organization

Chapter 5 Busses, Ports and Connecting Peripherals

4. About drives and other storage media: Module 4a. Drives (4 pages) Module 4b. Hard disks (9 pages) Module 4c. Optic storage media (7.

Application Note 132. Introduction. Voice Video and Data Communications using a 2-Port Switch and Generic Bus Interface KSZ MQL/MVL

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

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

Serial ATA RAID PCI. User's Manual

PCI Express: Interconnect of the future

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

What is involved in input/output? How does the operating system manage I/O?

BIOS Update Release Notes

Trademarks. IBM, PC/AT, and PC/XT are trademarks of International Business Machines Corporation.

Microcontroller Based Low Cost Portable PC Mouse and Keyboard Tester

Installing, upgrading and troubleshooting your CLIO system under the Windows environment.

PC Boot Considerations for Devices >8GB

Freescale Semiconductor, I

Operating System Overview. Otto J. Anshus

M7VIK BIOS Setup BIOS Setup...1

A Comparison of VMware and {Virtual Server}

Dolphin In-Circuit programming Updating Firmware in the field

Chapter 8: Installing Linux The Complete Guide To Linux System Administration Modified by M. L. Malone, 11/05

UEFI on Dell BizClient Platforms

Module I-7410 Advanced Linux FS-11 Part1: Virtualization with KVM

Eight Ways to Increase GPIB System Performance

PC Notebook Diagnostic Card

I/O Device and Drivers

Transcription:

Programming PCI-Devices under Linux by Claus Schroeter (clausi@chemie.fu-berlin.de) Abstract This document is intended to be a short tutorial about PCI Programming under Linux. It describes the PCI basics and its implementation under Linux. Introduction to PCI PCI #0 PCI-Bus CPU PCI #1 PCI-Bridge Memory............. PCI #n Figure 1: The Architecture of the PCI Subsystem The Peripheral Component Interconnect - Bus (PCI) today is present in a wide variety of microcomputers ranging from Intel-based PC architectures to DEC-Alpha-based workstations. The main difference between the old fashioned ISA-Bus and PCI is the complete separation of the Bus-subsystem from the Memory Subsystem. The CPU communicates with the PCI subsystem using a special chipset known as PCI-Bridge. This is an intelligent controller, that handles all necessary tasks to transfer data from or to the CPU or the Memory Subsystem. On PCI the adresses and data are transferred as seperate chunks over the bus because all buslines can be used either as adress- or as data-lines. In special cases only one start address is transferred followed by a whole data block. To determine the address for each single data-word the PCI-Bridge and the PCI- Adapter increment internal counters, so the address is calculated while the data words are transmitted. This so called burst cycle speeds up the transfer significantly (up to 266Mbyte/sec for a 64bit data-transfer). Thanks to the intelligent handling of this tasks the programmer need not to take care about all this stuff. A schematic view of the PCI subsystem is depicted in Figure 1. The PCI design forces Hardware designers to use a standardized interface for PCI-Board access and control. Each bus device has its own 265byte space of Memory for configuration purposes that can be accessed through the CONFIG ADDRESS and the CON- FIG DATA registers. On system startup the BIOS uses the device configuration block to set the different board properties as IRQ line and base address for example. No jumpers need to be placed in the right places, so IRQ or address conflicts are no longer a problem with PCI. This feature is commonly known as Plug&Play functionality.

First Contact with the PCI subsystem To get an impression how linux sees the PCI bus in your computer try getting the PCI bus configuration from the kernel with cat /proc/pci. If everything works OK you will (hopefully) see: PCI devices found: Bus 0, device 12, function 0: SCSI storage controller: Adaptec AIC-7881U (rev 0). Medium devsel. Fast back-to-back capable. IRQ 11. Master Capable. Latency=32. Min Gnt=8.Max Lat=8. I/O at 0xd800. Non-prefetchable 32 bit memory at 0xf7fff000. Bus 0, device 11, function 0: VGA compatible controller: S3 Inc. Vision 968 (rev 0). Medium devsel. IRQ 10. Non-prefetchable 32 bit memory at 0xf2000000. Bus 0, device 10, function 0: Ethernet controller: 3Com 3C590 10bT (rev 0). Medium devsel. IRQ 12. Master Capable. Latency=248. Min Gnt=3.Max Lat=8. I/O at 0xe000. Bus 0, device 7, function 2: Unknown class: Intel Unknown device (rev 0). Vendor id=8086. Device id=7020. Medium devsel. Fast back-to-back capable. IRQ 9. Master Capable. Latency=32. I/O at 0xe400. Bus 0, device 7, function 1: IDE interface: Intel 82371SB Triton II PIIX (rev 0). Medium devsel. Fast back-to-back capable. Master Capable. Latency=32. I/O at 0xe800. Bus 0, device 7, function 0: ISA bridge: Intel 82371SB Triton II PIIX (rev 0). Medium devsel. Fast back-to-back capable. Master Capable. No bursts. Bus 0, device 0, function 0: Host bridge: Intel 82439HX Triton II (rev 1). Medium devsel. Master Capable. Latency=32. All devices that are known to Linux you will see at /proc/pci. Each device configuration block is assigned to a device and a function ID. To identify a certain device while driver writing you will at least have to know the vendor- and the device-id that is statically stored in the device configuration block (as discussed later on). Driver writers normally need to know only the base address of the device and the IRQ line that the device is using. As shown above all device id s or device class fields that cannot be resolved within the linux PCI-subsystem are printed as plain values, so driver writers have a simple chance to identify their card of choice without writing a special tool to do this task. The Device Configuration Block As mentioned above each PCI-device has its own assigned 256bytes PCIconfiguration memory block that is accessible through PCI-BIOS routines. The first 64bytes of this reserved space are used to identify and configure the basic properties for the PCI-Device. On system startup some of the parameters in the configuration block are replaced from the Plug&Play BIOS that configures the I/O or Memory base addresses and IRQ lines for the PCI-board to operate correctly with other cards in the PCI or ISA slots. The configuration blocks of the PCI subsystem can be accessed through the CONFIG ADDRESS

(0xcf8) and the CONFIG DATA (0xcfc) registers The Linux PCI-bios support is implemented on top of the Bios32 routines and defines some useful routines to handle the PCI configuration block and configure the PCI subsystem. Normally no changes in the configuration block are necessary because the BIOS sets up all parameters to operate correctly. Because Linux is intended to run on many hardware architectures it is recommended to use this functions instead of accessing the configuration registers directly. Before a PCI-board can be used, the driver has to determine the board specific parameters from the configuration block and set all desired options to operate the board correctly. Normally this task is done by a autodetect routine in the kernel driver that performs the following tasks: Linux-PCI Support Check if the PCI-Bios Support is enabled in the kernel and the BIOS is present with pcibios present() Get the configuration block for the desired device using pcibios find device() Get the desired parameters from the configuration block using pcibios read config byte(), pcibios read config word() or pcibios read config dword() to get 8,16 or 32bit parameter values. Set the desired parameters in the configuration block using pcibios write config byte(), pcibios write config word() or pcibios write config dword() The following example from the ne2000 clone driver shows how this task is performed in a real kernel network driver. #if defined(config_pci) if (pcibios_present()) { int pci_index; for (pci_index = 0; pci_index < 8; pci_index++) { unsigned char pci_bus, pci_device_fn; unsigned int pci_ioaddr; /* Currently only Realtek are making PCI ne2k clones. */ if (pcibios_find_device (PCI_VENDOR_ID_REALTEK, PCI_DEVICE_ID_REALTEK_8029, pci_index, &pci_bus, &pci_device_fn)!= 0) break; /* OK, now try to probe for std. ISA card */ pcibios_read_config_byte(pci_bus, pci_device_fn, PCI_INTERRUPT_LINE, &pci_irq_line); pcibios_read_config_dword(pci_bus, pci_device_fn, PCI_BASE_ADDRESS_0, &pci_ioaddr); /* Strip the I/O address out of the returned value */ pci_ioaddr &= PCI_BASE_ADDRESS_IO_MASK; /* Avoid already found cards from previous ne_probe() calls */ if (check_region(pci_ioaddr, NE_IO_EXTENT)) continue; printk("ne.c: PCI BIOS reports ne2000 clone at i/o %#x, irq %d.\n", pci_ioaddr, pci_irq_line); if (ne_probe1(dev, pci_ioaddr)!= 0) { /* Shouldn t happen. */ printk(kern_err "ne.c: Probe of PCI card at %#x failed.\n", pci_ioaddr); break; /* Hrmm, try to probe for ISA card... */ }

pci_irq_line = 0; return 0; } } #endif /* defined(config_pci) */ This card uses one IRQ and one base address in I/O space to communicate with the driver. The lower bits of the returned base address have different meanings depending if the address is an I/O address or a memory mapped area is returned. On an I/O address bit 0 is always 1 and bit 2 is always zero. On a memory mapped address type the lower 4 bits have the following meanings: Bit Description 0 always zero 1-2 adress type: 00=arbitrary 32 bit, 01=below 1M, 10=arbitrary 64-bit 3 prefetchable To keep things simple Linux defines two macros PCI BASE ADDRESS MEM MASK and PCI BASE ADDRESS IO MASK that can be used to strip the type bits from the returned address. The prefetch bit is set if the PCI-bridge is allowed to read the memory block in a prefetch buffer without problems, this is normally the case if the memory block is a memory area on the PCI-device, if the memory area maps hardware registers into memory the prefetch bit should not be set. There are a whole bunch of other setable and readable parameters in the configuration block, that can be accessed through the linux pcibios XXX() routines. Linux defines some useful Mnemonics to gain simple access to the configuration block parameter values that are defined in include/linux/pci.h. The Tables 1,2 and 3 will describe the Macros in detail. Reading and writing to a device Reading and writing to a PCI device is as easy as reading and writing to an ISA board or reading and writing to a memory area depending on the base address type of the device. If the device uses an I/O type base address, normal I/O can be performed using the usual inb()/outb(), inw()/outw() or the 32bit inl()/outl() routines. To get an impression how other linux drivers use this access modes please take a look through the network or scsi drivers. If the device uses a memory mapped area it is recommended to use the readb()/writeb(), readw()/writew() or the longword readl()/writel() routines to read or write to a single location (see include/asm/io.h). memcpy() can also be used to transfer a whole memory block as this is the case on framegrabber devices or whatever transfers large blocks of data. In this case the PCI-Bridge handles automatically which transfer mode is optimal for the bus system. For this purpose the PCI-bridge has internal prefetch queues (one for the Bus side, one for the CPU subsystem side) that are used to store transfer data before a send or receive is initiated. If the PREF (prefetchable) bit is set in the base address bit 3, the memory area is non prefetchable, in other words data and addressed are dumped directly to the bus-subsystem. This mode is intended for devices that maps special registers in a memory area so the CPU can read or write this registers without a PCI-Bridge related delay. Busmastering With busmaster transfer mode a controller can transfer its data to the memory without any CPU action by driving the appropriate bus-lines on a hardware basis. This is similar to the DMA transfer on a ISA bus with the only difference that the busmaster-controller sits on the PCIadapter card and not on the motherboard. If a device is busmaster capable the PCI COMMAND MASTER bit should have

been set in the PCI COMMAND register. If a busmaster transfer has been aborted by the busmaster device, the PCI STATUS REC MASTER ABORT bit in the Linux-PCI Support PCI STATUS register is set, on the receiving end an abort can be notified by looking on the PCI STATUS REC TARGET ABORT bit. Macro Width Description PCI VENDOR ID 16bit Unique Vendor ID (see pci.h) This ID is defined by the PCI consortium PCI DEVICE ID 16bit Unique Device ID (see pci.h) this is defined by the vendor unique for each device PCI COMMAND 16bit This field is used for device specific configuration commands (see table 2) PCI STATUS 16bit This is used for board specific status results (see table 3) PCI CLASS REVISION 32bit The high 24bits are used to determine the device s class type the low 8bit for revision code PCI CLASS DEVICE The device s class code (see pci.h) PCI BIST 8bit If PCI BIST CAPABLE is set the device can perform a Build-in self test that can be started by writing PCI BIST START to this field. The result mask is PCI BIST CODE MASK PCI HEADER TYPE 8bit Specifies the Layout type for the following 48 bytes in PCI configuration (currently only 0x0) PCI LATENCY TIMER 8bit This is the maximal time a PCI cycle may consume (time=latency+8cycles) PCI CACHE LINE SIZE 8bit Specifies the Cache-Line Size in units of 32bytes, PCI BASE ADDRESS [0-5] 32bit This are up to 6 memory locations the device can map its memory area(s) to. The lower 4 bits are used to specify the type and the access mode of the memory area. PCI ROM ADDRESS 32bit bit 11-31 is the start address of the device s ROM area. (write bit 1 to enable ROM) PCI MIN GNT 8bit minimal latency time (vendor specific) PCI MIN LAT 8bit maximal latency time (vendor specific) PCI INTERRUPT PIN 8bit This entry denotes the IRQ pin that should be used 1=INTA 2=INTB 0=disabled PCI INTERRUPT LINE 8bit This entry specifies the interrupt line on which the device IRQ is mapped (usually IRQ 0-15) Table 1: The Linux PCI-Configuration macros

Macro PCI COMMAND IO PCI COMMAND MEMORY PCI COMMAND MASTER PCI COMMAND SPECIAL PCI COMMAND INVALIDATE PCI COMMAND VGA PALETTE PCI COMMAND PARITY PCI COMMAND WAIT PCI COMMAND SERR PCI COMMAND FAST BACK Description Enable I/O area Enable Memory area Enable Busmastering Enable response to special cycles Use memory write and invalidate Enable video palette access Enable parity checking Enable address/data stepping Enable SERR Enable back-to-back writes Table 2: The Linux PCI-Command Bit-Settings Macro PCI STATUS 66MHZ PCI STATUS UDF PCI STATUS FAST BACK PCI STATUS PARITY PCI STATUS DEVSEL [MASK FAST MEDIUM SLOW] PCI STATUS SIG TARGET ABORT PCI STATUS REC TARGET ABORT PCI STATUS REC MASTER ABORT PCI STATUS SIG SYSTEM ERROR PCI STATUS DETECTED PARITY Description Support 66 Mhz PCI 2.1 bus Support User Definable Features Accept fast-back to back Detected parity error DEVSEL timing Set on target abort Master ack of Set on master abort Set when we drive SERR Set on parity error Table 3: The Linux PCI-Status Bit-Settings