The ‘ioctl’ driver-function On implementing ‘show’ and ‘hide’ for the SiS 315 hardware cursor.

Slides:



Advertisements
Similar presentations
Linux device-driver issues
Advertisements

Device Drivers. Linux Device Drivers Linux supports three types of hardware device: character, block and network –character devices: R/W without buffering.
Sogang University Advanced Operating Systems (Linux Device Drivers) Advanced Operating Systems (Linux Device Drivers) Sang Gue Oh, Ph.D.
Using our device-drivers How can an application display the data in a device special file?
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.
Dr A Sahu Dept of Comp Sc & Engg. IIT Guwahati 1.
CS 686: Programming SuperVGA Graphics Devices Introduction: An exercise in working with graphics file formats.
Creating a device-file node An introduction to some privileged Linux system-calls (needed for an upcoming programming exercise)
I/o multiplexing On adding a ‘poll()’ method to our character-mode device-driver for an 82573L network controller.
Sleeping and waking An introduction to character-mode device-driver modules for Linux.
The Linux PCI Interface An introduction to the PCI configuration space registers.
UNIX’s “grand illusion” How Linux makes a hardware device appear to be a ‘file’
IA32 Paging Scheme Introduction to the Pentium’s support for “virtual” memory.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 13: I/O Systems I/O Hardware Application I/O Interface Kernel I/O Subsystem.
The RealTek interface Introduction to the RTL-8139 network controller registers.
A look at memory issues Data-transfers must occur between system memory and the network interface controller.
Timeout for some demos An instructive look at how the Linux Operating System sets up system data-structures.
SiS 315 Graphics Engine Introduction to some capabilities of graphics accelerator hardware.
Standard C Libraries Application Programmming Interface to System-Calls.
RTL-8139 experimentation Setting up an environment for studying the Network Controller.
Access to video memory We create a Linux device-driver that gives applications access to our graphics frame-buffer.
Graphics acceleration An example of line-drawing by the ATI Radeon’s 2D graphics engine.
04/16/2010CSCI 315 Operating Systems Design1 I/O Systems Notice: The slides for this lecture have been largely based on those accompanying an earlier edition.
I/O Systems CS 3100 I/O Hardware1. I/O Hardware Incredible variety of I/O devices Common concepts ◦Port ◦Bus (daisy chain or shared direct access) ◦Controller.
Managing physical memory
Rapid prototyping of LKMs Configuring our Linux systems for the quick creation and use of loadable kernel modules.
The ‘ioctl’ driver-function On implementing a way to query and modify our UART’s baudrate via the ‘device-file’ abstraction.
Adjusting out device-driver Here we complete the job of modifying our ‘nicf.c’ Linux driver to support ‘raw’ packet-transfers.
CS 686: Programming SuperVGA Graphics Devices Introduction: An exercise in working with graphics file formats.
Looking at kernel objects How a character-mode Linux device driver can be useful in viewing a ‘net_device’ structure.
A device-driver for Video Memory Introduction to basic principles of the PC’s graphics display.
The ‘mmap()’ method Adding the ‘mmap()’ capability to our ‘vram.c’ device-driver.
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
Linux Device Drivers Inroduction. What’s a ‘device-driver’? A special kind of computer program Intended to control a peripheral device Needs to execute.
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.
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
An Introduction to Device Drivers Sarah Diesburg COP 5641 / CIS 4930.
Loadable Kernel Modules Dzintars Lepešs The University of Latvia.
Memory Mapped Files Using the Linux mechanism for direct access to device data.
CHAPTER 13: I/O SYSTEMS Overview Overview I/O Hardware I/O Hardware I/O API I/O API I/O Subsystem I/O Subsystem Transforming I/O Requests to Hardware Operations.
UART and UART Driver B. Ramamurthy.
ECE291 Computer Engineering II Lecture 9 Josh Potts University of Illinois at Urbana- Champaign.
Chapter 13: I/O Systems Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Jan 2, 2005 Chapter 13: I/O Systems I/O Hardware.
I/O Systems I/O Hardware Application I/O Interface
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.
‘Identify Device’ A mandatory command that allows device-drivers to query any standard IDE/ATA hard disk for its parameters.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 13: I/O Systems I/O Hardware Application I/O Interface Kernel I/O Subsystem.
Digression on r/w ‘/proc’ files An application of kernel module programming to Super VGA graphics device control.
An Introduction to Device Drivers Ted Baker  Andy Wang COP 5641 / CIS 4930.
Interfacing Device Drivers with the Kernel
CSC414 “Introduction to UNIX/ Linux” Lecture 2. Schedule 1. Introduction to Unix/ Linux 2. Kernel Structure and Device Drivers. 3. System and Storage.
Lab 12 Department of Computer Science and Information Engineering National Taiwan University Lab12 – Driver 2014/12/16 1 /21.
Silberschatz, Galvin, and Gagne  Applied Operating System Concepts Module 12: I/O Systems I/O hardwared Application I/O Interface Kernel I/O.
Low Overhead Real-Time Computing General Purpose OS’s can be highly unpredictable Linux response times seen in the 100’s of milliseconds Work around this.
 Backlight 에서 나온 백색광이 액정 셀을 통과하면 서 투과율이 조절되고 red, green, blue 의 color filter 를 투과해 나오는 빛의 혼합을 통해 색이 구 성됨  Color filter 는 셀사이의 빛을 차단하는 black matrix,
OPERATING SYSTEMS (OS) By the end of this lesson you will be able to explain: 1. What an OS is 2. The relationship between the OS & application programs.
Module 12: I/O Systems I/O hardware Application I/O Interface
Linux Details: Device Drivers
CSNB COMPUTER SYSTEM CHAPTER 1 INTRODUCTION CSNB153 computer system.
Chapter 12: File System Implementation
UART and UART Driver B. Ramamurthy.
An Introduction to Device Drivers
CSCI 315 Operating Systems Design
UART and UART Driver B. Ramamurthy.
CS 140 Lecture Notes: Virtual Machines
Linux Details: Device Drivers
Computer System Laboratory
Presentation transcript:

The ‘ioctl’ driver-function On implementing ‘show’ and ‘hide’ for the SiS 315 hardware cursor

‘struct file_operations’ For a Linux device-driver’s ‘init_module()’ function, there are two main actions: –Initializing the driver’s global data-structures (this includes verifying the device’s presence) –Registering the driver’s service-functions with the kernel (i.e., the ‘file_operations’ structure) The driver’s ‘cleanup_module()’ function has the duty to ‘unregister’ those services

Driver services For character-mode device-drivers (such as our ‘dram.c’, ‘mbr.c’, and ‘vramm.c’), we have implemented some (or all) of the following service-functions (i.e., ‘methods’) – read() – llseek() – write() – mmap()

The ‘file’ paradigm The UNIX approach to device-control is to create objects that represent i/o-devices, but which behave like ‘files’ do, insofar as the application programmer is concerned So ‘read()’, ‘llseek()’, ‘write()’ and ‘mmap() use the same function-call syntax – and in most respects the same semantics – for both ‘files’ and ‘devices’

An imperfect paradigm But often there are a few ways in which the file-object paradigm doesn’t quite fit with important features of an i/o device In these cases, device-drivers can provide a ‘workaround’ that allows applications to perform device-actions that deviate from customary ‘read/write/seek’ file-like actions This ‘workaround’ mechanism is ‘ioctl()’

The graphics display Our PC’s graphics display device offers an easy example of desirable behavior that is outside the traditional ‘file’ paradigm In order to display graphical images that are full-screen renderings of artistic work, we want to avoid seeing a mouse-cursor (it’s an ugly and disruptive and distraction) How can a program ‘turn off’ that cursor?

The GPU ‘resources’ The SiS 315 graphics processing units in our workstations are each equipped with 32-megabytes of video display memory (designated as PCI resource 0) These graphics adapters also implement a set of memory-mapped registers known as the 2D graphics engine (and designated as PCI resource 1)

‘pci_resource_start()’ Device-drivers can use this Linux kernel function to discover the physical address where resource 0, or resource 1, resides struct pci_dev*devp = NULL: devp = pci_find_device( VEN, DEV, devp ); vram = pci_resource_start( devp, 0 ); mmio = pci_resource_start( devp, 1 );

SiS 315 information Programming manual for the SiS 315 GPU is not usually made available to the public But some information can be derived from reading Linux device-driver source-code Examples are: –The ‘/usr/src/linux/drivers/video/sis’ directory –Also download the ‘svgalib ’ package

Graphics Cursor cursor-image source-offset x8500 cursor visibility control bit: 0=hide, 1=show cursor-image horizontal coordinate 0x850C 0x8510 cursor starting command bit: 0=no, 1=yes cursor-image vertical coordinate

Algorithm to hide cursor Map physical page containing the registers to a virtual address (with ‘ioremap()’) Read current values of these registers Clear bit #30 (to make cursor invisible) Set bit #31 (to initiate a new command) Write these adjusted register values Undo the mapping (with ‘iounmap()’)

Algorithm to show cursor Map physical page containing the registers to a virtual address (with ‘ioremap()’) Read current values of these registers Set bit #30 (to make cursor visible) Set bit #31 (to initiate a new command) Write these adjusted register values Undo the mapping (with ‘iounmap()’)

The ‘ioctl.c’ module These techniques are demonstrated in this device-driver module’s ‘ioctl()’ function Two IOCTL commands are implemented –#define CURSOR_HIDE0 –#define CURSOR_SHOW1 Applications can open the device-file, then use an ioctl-command; for example: int fd = open( “/dev/vram”, O_RDWR ); ioctl( fd, CURSOR_HIDE);

In-class exercise #1 Try adding new IOCTL commands to the ‘ioctl.c’ driver which lets applications find or move the cursor’s screen-position; #define CURSOR_FIND2 #define CURSOR_MOVE3 struct { long x, y; } location; ioctl( fd, CURSOR_FIND, &location ); location.x += 40; location.y += 40; ioctl( fd, CURSOR_MOVE, &location );

In-class exercise #2 We are not told what function is served by two of the SiS engine’s i/o locations: –0x8500 (longword) cursor-image source-offset –0x8504 (longword) –0x8508 (longword) –0x850C (longword) cursor-image horiz-coord –0x8510 (longword) cursor-image vertl-coord So can you ‘discover’ their purpose?