The Driver Itself

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:

1. 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.
2. 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.
3. Provide an identification function that the server will call to list the chipsets that the driver is capable of supporting.
4. 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.
5. Provide a function to select dot-clocks available on the board.
6. Provide functions to save, restore, and initialize the driver- local data structure.
7. Provide a function to set the starting address for display in the video memory. This implements the virtual-screen for the server.
8. Perhaps provide a function for use during VT-switching.
9. 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:

1. 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

2. 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.
3. 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:

1. 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.
2. Bank selection. The SVGA chipset will have one or two registers that control read/write bank selection.
3. CRTC extensions. The standard VGA registers don't have enough bits to address large displays. So the SVGA chipsets have extension bits.
4. 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
5. 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.
6. 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.
7. 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.

### 6.1. Multiple Chipsets And Options

### 6.2. Data Structures

### 6.3. The Ident() function

### 6.4. The ClockSelect() function

### 6.5. The Probe() function

### 6.6. The EnterLeave() function

### 6.7. The Restore() function

### 6.8. The Save() function

### 6.9. The Init() function

### 6.10. The Adjust() function

### 6.11. The ValidMode() function

### 6.12. The SaveScreen() function

### 6.13. The GetMode() function

### 6.14. The FbInit() function

How to add an (S)VGA driver to XFree86 : The Driver Itself
Previous: The Bank-Switching Functions
Next: Multiple Chipsets And Options