Video/Graphics of Modern Desktop Board & its Linux programming
Dr A Sahu
Dept of Comp Sc & Engg.
IIT Guwahati
1
Outline
2
Intel 945 Express Chipset
3
4 Serial ATA Ports
Integrated Matrix Storage Technology
6 PCI Slots
BIOS
Support
Intel HD Audio
8 high Speed USB Ports
6 PCI Express*
x1 slot
Intel Pro 100/1000 LAN
Intel Active
Mngement Tech.
82801 GR
ICH7 (io cont. hub sys7)
South Bridge
Intel
Pentium D Processor
DDR2
DDR2
Support for Media Ext Card
Intel GMA 950 Graphics
PCI Express*
x16 Graphics
82945
GMCH/MCH
North Bridge
82945 : GMCH/MCH
4
82801: ICH7
5
Introduction
6
Intel
Pentium D Processor
DDR2
DDR2
Support for Media Ext Card
Intel GMA 950 Graphics
PCI Express*
x16 Graphics
82945
GMCH/MCH
North Bridge
Migration from Char to Graphics/Video
7
RED ARROW
Circle
Multiplexed 1024x768 pixel display
8
1024x768 Pixel LCD
0 1 2 3 4 ….. …1023
0
1
2
767
R
Row Ctr
Col
Ctr
CLK > 1024x768x50Hz
B
G
8x3=24 Bits
Frame Buffer
Refresh screen 50 time a Sec
Frame Buffer (24 Bit Pixel)
9
Pixels in Frame Buffer
Pixels on
the Screen
24 Bit Per Pixels
Graphical representation of 24 bit color
Graphics Cards
10
Graphics System
11
3D application
3D API: OpenGL
DirectX/3D
3D API Commands
CPU-GPU Boundary
GPU Command
& Data Stream
GPU
Command
Primitive
Assembly
Rastereisation
Interpolation
Raster
Operation
Frame Buffer
Programmable
Fragment
Processors
Programmable
Vertex
Processor
Vertex Index
Stream
Assembled polygon, line
& points
Pixel
Location
Stream
Pixel
Updates
Transformed
Fragments
Rastorized Pretransformed
Fragments
transformed
Vertices
Pretransformed
Vertices
Graphics System
12
Memory
System
Texture
Memory
Frame
Buffer
Vertex
Processing
Pixel
Processing
Vertices
(x,y,z)
Pixel
R, G,B
Vertex
Shadder
Pixel
Shadder
Access to video memory
13
14
The role of a device-driver
user
application
standard
“runtime”
libraries
call
ret
user space
kernel space
Operating System
kernel
syscall
sysret
device-driver
module
call
ret
hardware device
out
in
i/o memory
RAM
A device-driver is a software module
that controls a hardware device
in response to OS kernel requests
relayed, often, from an application
Raster Display Technology
15
The graphics screen is a two-dimensional array of picture elements (‘pixels’)
Each pixel’s color is an individually programmable mix of red, green, and blue
These pixels are redrawn sequentially, left-to-right, by rows from top to bottom
Special “dual-ported” memory
16
VRAM
RAM
CPU
CRT
16-MB of VRAM
2048-MB of RAM
How much VRAM is needed?
17
How ‘truecolor’ works
18
R
B
G
alpha
red
green
blue
0
8
16
24
pixel
longword
The intensity of each color-component within a pixel is an 8-bit value
0.5, 0, 1, 0
0, 0.5, 0
Alpha represent pre-multiplied valued
x86 uses “little-endian” order
19
B
G
R
A
B
G
R
A
B
G
R
VRAM
0 1 2 3
Video Screen
4 5 6 7
8 9 10
…
“truecolor” graphics-modes use 4-bytes per picture-element
Some operating system issues
20
Our ‘vram.c’ module
$ cat /proc/vram
21
What is PCI?
22
23
PCI Configuration Space
PCI Configuration Space Body
(48 doublewords – variable format)
64
doublewords
PCI Configuration Space Header
(16 doublewords – fixed format)
A non-volatile parameter-storage area for each PCI device-function
24
Example: Header Type 0
Status
Register
Command
Register
Device
ID
Vendor
ID
BIST
Cache
Line
Size
Class Code
Class/SubClass/ProgIF
Revision
ID
Base Address 0
Subsystem
Device ID
Subsystem
Vendor ID
CardBus CIS Pointer
reserved
capabilities
pointer
Expansion ROM Base Address
Minimum
Grant
Interrupt
Pin
reserved
Latency
Timer
Header
Type
Base Address 1
Base Address 2
Base Address 3
Base Address 4
Base Address 5
Interrupt
Line
Maximum
Latency
31 0
31 0
16 doublewords
Dwords
1 - 0
3 - 2
5 - 4
7 - 6
9 - 8
11 - 10
13 - 12
15 - 14
Examples of VENDOR-IDs
25
Examples of DEVICE-IDs
See this Linux header-file for lots more examples:
</usr/src/linux/include/linux/pci_ids.h>
26
Defined PCI Class Codes
27
Example of Sub-Class Codes
28
29
Example of Sub-Class Codes
Example of Sub-Class codes
30
Hardware details may differ
31
The ‘frame-buffer’
32
The ‘base address’ fields
33
ATI Radeon uses Base Address 0
34
#include <linux/pci.h>
struct pci_dev *devp; // for a variable that will point to
//a kernel-structure
// get a pointer to the PCI device’s Linux data-structure
devp = pci_get_device( VENDOR_ID, DEVICE_ID, NULL );
if ( !devp ) return –ENODEV; // device is not present
// get starting address and length for memory-resource 0
vram_base = pci_resource_start( devp, 0 );
vram_size = pci_resource_len( devp, 0 );
Reading from ‘vram’
$ fileview /dev/vram
35
I/O ‘memcpy()’ functions
memcpy_fromio( buf, vaddr, len );
memcpy_toio( vaddr, buf, len );
36
‘mmap()’
37
The user-role
int mmap( (void*)baseaddress,
int memorysize,
int accessattributes,
int flags,
int filehandle,
int offset );
38
The driver-role
int mmap( struct file *file,
struct vm_area_struct *vma );
39
Our driver’s code
40
int mmap( struct file *file, struct vm_area_struct *vma )
{
// extract the paramers we will need from the ‘vm_area_struct’
unsigned long region_length = vma->vm_end – vma->vm_start;
unsigned long region_origin = vma->vm_pgoff * PAGE_SIZE;
unsigned long physical_addr = fb_base + region_origin;
unsigned long user_virtaddr = vma->vm_start;
// sanity check: mapped region cannot extend past end of vram
if ( region_origin + region_length > fb_size ) return –EINVAL;
// tell the kernel not to try ‘swapping out’ this region to the disk
vma->vm_flags |= VM_RESERVED;
// tell the kernel to exclude this region from any core dumps
vma->vm_flags |= VM_IO;
Driver’s code continued
41
// invoke a helper-function that will set up the page-table entries
if ( remap_pfn_range( vma, user_virtaddr, physical_addr >> 12,
region_length, vma->vm_page_prot ) ) return –EAGAIN;
return 0; // SUCCESS
}
Demo: ‘rotation.cpp’
42
Thanks
43