Digression on r/w ‘/proc’ files An application of kernel module

advertisement
Digression on r/w ‘/proc’ files
An application of kernel module
programming to Super VGA
graphics device control
Super VGA
•
•
•
•
•
Modern graphics cards have lots of vram
Our class machines show only part of it
Screen resolution is 1280 x 1024 ‘pixels’
Each ‘pixel’ is 32-bits of video memory
Total vram for one full screen:
1280 x 1024 x 4 bytes = 5 megabytes
• Our class machines have 32 megabytes
SVGA ‘Start Address’ parameter
•
•
•
•
•
•
Our machines use the SiS 315 svga chip
Its ‘Start Address’ governs what we see
It’s a 24-bit value, held in 3 byte-registers
Registers accessible through i/o ports
Kernel code can reprogram these registers
Module-inferface gives application-access
How Start Address works
Start_address = 0
visible
Start_address = 2048
visible
VRAM
VRAM
The CRT Controller
•
•
•
•
•
•
•
•
Display monitor uses Cathode Ray Tube
It’s operated by SVGA’s CRT Controller
Old design: It has lots of 8-bit registers
Two i/o port-addresses are ‘multiplrexed’
ADDRESS_PORT: 0x03D4
DATA_PORT:
0x03D5
CRTC register 13: start_address[ 7..0 ]
CRTC register 12: start_address[ 15..8 ]
SVGA incompatibility
•
•
•
•
•
•
•
Many features of SVGA are now standard
But vendors add their own ‘extras’
These are NOT programmed identically!
You usually need manufacturer’s manual
But not always easy to get (proprietary)
(We found SiS information in a web email)
Software for SiS chip ‘extras’ non-portable
SVGA Memory Sequencer
•
•
•
•
•
•
•
Sequencer also has lots of 8-bit registers
They’re also accessed via two i/o ports
ADDRESS_PORT: 0x03C4
DATA_PORT:
0x03C5
Seq register 13: start_address[ 23..16 ]
SiS chip uses Seq register 5 as a ‘lock’
Write 0x86 to ‘unlock’ sequencer registers
pci_find_device()
• Driver must ‘detect’ the SiS SVGA device
• SiS chip’s VENDOR_ID is 0x1039
• SiS chip’s DEVICE_ID is 0x6325
• #include <linux/pci.h>
struct pci_dev *devp = NULL;
devp = pci_find_device( VENDOR, DEVICE, devp );
Class Demo
•
•
•
•
•
•
•
Module name is ‘sischip.c’
Creates a pseudo-file: ‘proc/sischip’
It’s a binary file (don’t use ‘cat’ command)
File is both readable and writable
Lets application get or set ‘start_address’
Our demo-program is ‘vgascroll.cpp’
It lets us see 16 megabytes of video ram
Today’s Class Exercise
• Use your knowledge of ‘ioremap()’
• Draw an image in the offscreen vram
• Run ‘vgascroll’ to see what you’ve drawn
Download