The Linux PCI Interface An introduction to the PCI configuration space registers.

Slides:



Advertisements
Similar presentations
Linux device-driver issues
Advertisements

CT213 – Computing system Organization
Device Drivers. Linux Device Drivers Linux supports three types of hardware device: character, block and network –character devices: R/W without buffering.
Part IV: Memory Management
Using VMX within Linux We explore the feasibility of executing ROM-BIOS code within the Linux x86_64 kernel.
Linux ‘Demand-Paging’
I/O Multiplexing The role of the ‘poll()’ method in Linux device-driver operations.
Avishai Wool lecture Introduction to Systems Programming Lecture 8 Input-Output.
CS 686: Programming SuperVGA Graphics Devices Introduction: An exercise in working with graphics file formats.
The ‘thread’ abstraction A look at the distinction between the idea of a ‘process’ and the concept of a ‘thread’
CMPT 300: Operating Systems I Dr. Mohamed Hefeeda
The RealTek interface Introduction to the RTL-8139 network controller registers.
SiS 315 Graphics Engine Introduction to some capabilities of graphics accelerator hardware.
The ‘ioctl’ driver-function On implementing ‘show’ and ‘hide’ for the SiS 315 hardware cursor.
Access to video memory We create a Linux device-driver that gives applications access to our graphics frame-buffer.
CS 333 Introduction to Operating Systems Class 18 - File System Performance Jonathan Walpole Computer Science Portland State University.
Embedded Real-time Systems The Linux kernel. The Operating System Kernel Resident in memory, privileged mode System calls offer general purpose services.
Linux Memory Issues Introduction. Some Architecture History 8080 (late-1970s) 16-bit address (64-KB) 8086 (early-1980s) 20-bit address (1-MB) (mid-’80s)
The kernel’s task list Introduction to process descriptors and their related data-structures for Linux kernel version
Scientific Visualization Using imagery to aid humans in understanding a complicated phenomenon.
A device-driver for Video Memory Introduction to basic principles of the PC’s graphics display.
Introduction to the Intel x86’s support for “virtual” memory
What’s needed to transmit? A look at the minimum steps required for programming our anchor nic’s to send packets.
Notes for Lab 10 On implementing ‘show’ and ‘hide’ for the SiS 315 hardware cursor.
I/O Tanenbaum, ch. 5 p. 329 – 427 Silberschatz, ch. 13 p
Memory Mapped Files Using the Linux mechanism for direct access to device data.
Input/Output. Input/Output Problems Wide variety of peripherals —Delivering different amounts of data —At different speeds —In different formats All slower.
Computer Organization
System Calls 1.
Computer Maintenance Unit Subtitle: Basic Input/Output System (BIOS) Excerpted from 1 Copyright © Texas Education Agency, All.
Chapter 10: Input / Output Devices Dr Mohamed Menacer Taibah University
Buses Warning: some of the terminology is used inconsistently within the field.
Computer Architecture and Organization Introduction.
Contact Information Office: 225 Neville Hall Office Hours: Monday and Wednesday 12:00-1:00 and by appointment.
8.4 paging Paging is a memory-management scheme that permits the physical address space of a process to be non-contiguous. The basic method for implementation.
S2008Final_part1.ppt CS11 Introduction to Programming Final Exam Part 1 S A computer is a mechanical or electrical device which stores, retrieves,
1 Linux Operating System 許 富 皓. 2 Memory Addressing.
Operating System What is an Operating System? A program that acts as an intermediary between a user of a computer and the computer hardware. An operating.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
Digression on r/w ‘/proc’ files An application of kernel module programming to Super VGA graphics device control.
Implementing ‘noecho’ Programming details regarding the Linux implementation for ‘struct termios’ objects.
Input/Output Problems Wide variety of peripherals —Delivering different amounts of data —At different speeds —In different formats All slower than CPU.
OSes: 2. Structs 1 Operating Systems v Objective –to give a (selective) overview of computer system architectures Certificate Program in Software Development.
Input Output Techniques Programmed Interrupt driven Direct Memory Access (DMA)
Computer Maintenance I
1 CSC103: Introduction to Computer and Programming Lecture No 27.
1 Device Controller I/O units typically consist of A mechanical component: the device itself An electronic component: the device controller or adapter.
ECE 456 Computer Architecture Lecture #9 – Input/Output Instructor: Dr. Honggang Wang Fall 2013.
Memory Management Chapter 5 Advanced Operating System.
File System Department of Computer Science Southern Illinois University Edwardsville Spring, 2016 Dr. Hiroshi Fujinoki CS 314.
1 Chapter 2: Operating-System Structures Services Interface provided to users & programmers –System calls (programmer access) –User level access to system.
CIT 140: Introduction to ITSlide #1 CSC 140: Introduction to IT Operating Systems.
CSCE451/851 Introduction to Operating Systems
Input/Output (I/O) Important OS function – control I/O
SLC/VER1.0/OS CONCEPTS/OCT'99
Jonathan Walpole Computer Science Portland State University
Linux Details: Device Drivers
The PCI bus (Peripheral Component Interconnect ) is the most commonly used peripheral bus on desktops and bigger computers. higher-level bus architectures.
Plug-and-Play.
Paging and Segmentation
Operation System Program 4
Optimizing Malloc and Free
Chapter 9: Virtual-Memory Management
Overview Continuation from Monday (File system implementation)
Linux Details: Device Drivers
COMP755 Advanced Operating Systems
Chapter 13: I/O Systems “The two main jobs of a computer are I/O and [CPU] processing. In many cases, the main job is I/O, and the [CPU] processing is.
Presentation transcript:

The Linux PCI Interface An introduction to the PCI configuration space registers

Some background on PCI ISA: Industry Standard Architecture (1981) PCI: Peripheral Component Interconnect An Intel-backed industry initiative (1992-9) Main goals: –Improve data-xfers to/from peripheral devices –Eliminate (or reduce) platform dependencies –Simplify adding/removing peripheral devices –Lower total consumption of electrical power

Features for driver-writers Support for “auto-detection” of devices Device configuration is “programmable” Introduces “PCI Configuration Space” A nonvolatile data-structure of device info A standard “header” layout: 64 longwords Linux provides some interface functions: #include

pci_dev_struct Linux extracts info from PCI Config. Space Stores the info in linked-lists of structures Examples: –Name of the device’s manufacturer –Name and release version of the product –Hardware resources provided by the product –System resources allocated to the product (Linux provides “search-and-extract” routines)

The ‘lspci’ command Linux scans PCI Configuration Space It builds a list of ‘pci_dev_struct’ objects It exports partial info using a ‘/proc’ file You can view this info using a command: $ /sbin/lspci Or you can directly view the /proc/pci file: $ cat /proc/pci

An illustrative example: vram.c Let’s write another character device-driver It will allow read/write access to video ram Very analogous to our prior ‘ram.c’ driver Some differences: –Device’s memory resides on PCI the bus –Can safely allow writing as well as reading –Hardware uses memory in nonstandard ways –We really need vendor’s programmer manual

init_module() Driver’s first job is ‘device detection’ PCI devices are identified by numbers Device classes also have ID-numbers VGA device-class:0x –’03’ means a ‘display device’ –’00’ means ‘VGA compatible’ –’00’ means ‘revision-number’

pci_find_class(); Define the manifest constant: #define VGA_CLASS 0x Declare a null-pointer: struct pci_dev_struct *devp = NULL; Call ‘pci_find_class()’ function: devp = pci_find_class( VGA_CLASS, devp ); Check for ‘device-not-found’: if ( devp == NULL ) return –ENODEV;

Locate the VGA ‘frame buffer’ In PCI Configuration Space: – offset 0x10: base_address0 – offset 0x14: base_address1 – offset 0x18: base_address2 –... etc.... (complete layout on page 475 in textbook) A convenient Linux extraction-function: fb_base = pci_resource_start( devp, 0 );

How big is the frame buffer? Size of video memory varies with product Driver needs to determine memory-size PCI: a standard way to determine size (But product might provide support for larger vram than is currently installed) Two-step size-detection method: –First determine maximum supported size –Then check for ‘redundant’ addressing

Maximum memory-size Some bits in ‘base_address0’ are ‘wired’ But other bit-values are ‘programmable’ Bits 0..3 have some special meanings So we will need to examing bits Find least significant ‘programmable’ bit It tells the ‘maximum’ supported memory

Programming algorithm Get configuration longword at offset 0x10 Save it (so that we can restore it later) Write a new value: all bits set to 1’s Read back the longword just written The ‘hard-wired’ bits will still be 0’s We will scan for first bit that’s ‘1’ Be sure to restore the original longword

Loop to find the ‘lowest 1’ Implementing the PCI size-test: pci_write_config_dword( devp, 0x10, ~0 ); pci_read_config_dword( devp, 0x10, &val); inti; for (i = 4; i < 32; i++) if ( val & ( 1 << i ) ) break; fb_maxsize = ( 1 << i );

Checking for memory ‘wrap’ Do vram bytes have multiple addresses? We use a ‘quick-and-dirty’ check write to one address, read from another If what we read didn’t change: no ‘wrap’! Some assumptions we make: –Memory-size will be a power of 2 –If two bytes differ, all between them do, too (Should we question these assumptions?)

Device-memory: read and write The CPU understands ‘virtual’ addresses They must be ‘mapped’ to bus addresses The kernel must setup page-table entries Linux kernel provides functions: vaddr = ioremap( physaddr, memsize ); iounmap( vaddr ); Alternative: can use ‘ioremap_nocache()’

For copying: ram to/from vram Linux provides special ‘memcpy’ functions: –memcpy_fromio( ram, vram, nbytes ); –memcpy_toio( vram, ram, nbytes );

Our ‘vram.c’ driver We imitate the code in our ‘ram.c’ driver We use ‘temporary’ mappings (one page) Our ‘read()’ and ‘write()’ are very similar One notable difference: ‘read()’ is supposed to return 0 in case the file’s pointer is at the ‘end-of-file’ (This defect should be corrected in ‘ram.c’)

Warning about Red Hat 9.0 Red Hat 9.0 is now available in stores It advertises kernel version But it’s not identical to in our class Our demo modules do not always work Changes were made to kernel structures (e.g., task_struct) Changes were made to exported symbols (e.g., sys_call_table)

Need a ‘work-around’ Our ‘vram.c’ doesn’t create its device-node Requires users to create a node manually We ‘hard-coded’ the device major number So decisions differ from our ‘past practice’

Exercises Get ‘vram.c’ from our class website Compile and install the ‘vram.c’ driver Create the device special file: ‘/dev/vram’ Change file-attributes (to allow writing) Try copying video frame-buffer to a file Use ‘dump.cpp’ to view that binary file Try using ‘fileview.cpp’ to view video ram