How to add an (S)VGA driver to XFree86
: The Driver Itself
Previous: The Bank-Switching Functions
Next: Multiple Chipsets And Options
6. The Driver Itself
Now it's time to get down to the real work - writing the major driver
functions in the files sdc_driver.c. First, an overview of what the
responsibilities of the driver are:
- Provide a chipset-descriptor data structure to the server. This
data structure contains pointers to the driver functions and
some data-structure initialization as well.
- Provide a driver-local data structure to hold the contents of
the chipset registers. This data structure will contain a
generic part and a driver-specific part. It is used to save the
initial chipset state, and is initialized by the driver to put
the chipset into different modes.
- Provide an identification function that the server will call to
list the chipsets that the driver is capable of supporting.
- Provide a probe function that will identify this chipset as
different from all others, and return a positive response if
the chipset this driver supports is installed, and a negative
response otherwise.
- Provide a function to select dot-clocks available on the board.
- Provide functions to save, restore, and initialize the driver-
local data structure.
- Provide a function to set the starting address for display in
the video memory. This implements the virtual-screen for the
server.
- Perhaps provide a function for use during VT-switching.
- Perhaps provide a function to check if each mode is suitable for
the chipset being used.
Before stepping through the driver file in detail, here are some important
issues:
- If your driver supports both the color and monochrome servers,
you should take care of both cases in the same file. Most things
are the same - you can differentiate between the two with the
MONOVGA
#define
. If the 16 color server is supported,
code specific to it can be enabled with the XF86VGA16
#define
. In most cases it is sufficient to put
the following near the top of the stub_driver.c file:
#ifdef XF86VGA16
#define MONOVGA
#endif
- The color server uses the SVGA's 8-bit packed-pixel mode. The
monochrome and vga16 servers uses the VGA's 16-color mode
(4 bit-planes). Only one plane is enabled for the monochrome
server.
- It is possible for you to define your monochrome driver so that
no bank-switching is done. This is not particularly desirable,
as it yields only 64k of viewing area.
Keeping these things in mind, you need to find the registers from your
SVGA chipset that control the desired features. In particular, registers
that control:
- Clock select bits. The two low-order bits are part of the
standard Miscellaneous Output Register; most SVGA chipsets
will include 1 or 2 more bits, allowing the use of 8 or 16
discrete clocks.
- Bank selection. The SVGA chipset will have one or two registers
that control read/write bank selection.
- CRTC extensions. The standard VGA registers don't have enough
bits to address large displays. So the SVGA chipsets have
extension bits.
- Interlaced mode. Standard VGA does not support interlaced
displays. So the SVGA chipset will have a bit somewhere to
control interlaced mode. Some chipsets require additional
registers to be set up to control interlaced mode
- Starting address. The standard VGA only has 16 bits in which
to specify the starting address for the display. This restricts
the screen size usable by the virtual screen feature. The SVGA
chipset will usually provide one or more extension bits.
- Lock registers. Many SVGA chipset prevent modification of
extended registers unless the registers are first ``unlocked''.
You will need to disable protection of any registers you will
need for other purposes.
- Any other facilities. Some chipset may, for example, require
that certain bits be set before you can access extended VGA
memory (beyond the IBM-standard 256k). Or other facilities;
read through all of the extended register descriptions and see
if anything important leaps out at you.
If you are fortunate, the chipset vendor will include in the databook some
tables of register settings for various BIOS modes. You can learn a lot
about what manipulations you must do by looking at the various BIOS modes.
How to add an (S)VGA driver to XFree86
: The Driver Itself
Previous: The Bank-Switching Functions
Next: Multiple Chipsets And Options