3 - Kernel Driver
The part of the graphics driver that exists in the kernel space serves one purpose, to give the accelerant access to the video card. During video driver startup, the kernel driver 'transfers' as much resources as possible to the accelerant in order to allow the accelerant direct access to the video card, without taxing the kernel any further. Resources and information that can not be transferred are instead accessed through the API of the kernel driver component in simple functions.
This split method accomplishes two major things that can not normally be achieved by normal drivers: optimal speed, and stability. Optimal speed is reached because there are barely any (slow) context switches between user and kernel space. Stability is achieved because if the accelerant happens to die, it does not bring the system down since it resides in user space.
The kernel driver has two interfaces
- the interface to the OS ("system hooks") in kernel space that is responsible for the driver
initialization and publicizing of the driver name to the system
- the interface to the accelerant ("user hooks") in user space for actual use of the driver
The following picture of the startup method of BeOS (in relation to video drivers) shows among other things how the kernel driver is loaded. First the kernel drivers are initialized via the "system hooks". For drivers that succeed (ie: there is supported hardware found) the "user hooks" can then be used.
After the kernel driver is loaded all known accelerant's are tried via the user interface of the first found working kernel driver. This process is continued until an accelerant reports a
B_OK status, meaning that it can work with the loaded kernel driver. After this the rest of the loading process continues as usual, ending when BeUserScript script is run in
/boot/home/config/boot/. At this point, the user is usually moving the mouse and attempting to use the system.
For the rest of this chapter, we will discuss the system and user interfaces of the kernel driver. Information on the accelerant is found in chapter 4 - Accelerant.
3.1 - Interface To The OS
A kernel driver is loaded during the startup of the OS, is started by the OS, and is published to the user space, which can access it via the accelerant using "user hooks".
To do this the kernel driver needs a few standard routines:
Kernel drivers are found in two locations in BeOS:
/boot/beos/system/add-ons/kernel/drivers/bin/(standard with the system supplied drivers)
/boot/home/config/add-ons/kernel/drivers/bin/(for user add-on drivers)
System kernel drivers are linked to by a symlink, located in
/boot/beos/system/add-ons/kernel/drivers/dev/graphics/, and user add-on drivers are linked to by a symlink, located in
If a problem appears with a particular add-on during boot, a configuration screen can be accessed by pressing the spacebar at the very beginning of the iconic boot screen. Choose "Safe Mode Options" -> "Disable User Addons", and continue booting. The system will then not attempt to load any add-ons, and allow you to manually remove the offending driver in
/boot/home/config/add-ons/kernel/drivers/bin. If no working kernel driver is found, BeOS will boot into a black and white failsafe video mode, allowing you to manually check what is wrong.
3.1.1 - init_hardware()
If all the installation demands are met, the system will attempt to initialize the kernel driver during startup by calling
init_hardware(). This routine will check if the required bus system (e.g.: ISA and/or PCI) is available, and naturally, if a supported device is present.
3.1.2 - init_driver()
On success of
init_driver() will be called. With this some needed variables are initialized, like the name of the present device, and the required bus will be opened for use.
3.1.3 - publish_devices()
The system will now call the names of the supported hardware via
publish_devices(). The names will be published as symbolic links in the file system, in the
/dev/ directory. Where this symbolic link points to depends on the corresponding driver location, which was explained in section 3.1 above.
The driver is supposed to generate and publish a "unique" name for the card it is bound to. Usually the driver uses the manufacturer ID, card ID, bus number, slot number, and in some cases a function number, to generate it's "unique" name. Also of relevance is the physical slot the video card is seated in. Therefore creating unique names for two exact cards is not an issue, since they are seated in two different card slots.
The driver will be loaded only once into kernel space, and will support a predefined maximum number of different cards. That number is programmed into the driver itself, when it was created by the driver author.
- A single unified driver has been created to deal with multiple graphics cards by the same vendor, strictly PCI. The driver author has decided to limit the number of cards of this type to thirty (30) instances at one time, for whatever reason. If the computer has 3 PCI cards of this make/model, there will be three entries in
- A single unified driver has been created to deal with multiple graphics cards by the same vendor, regardless of bus type. The driver author decides using 30 is still a good limit, and uses that. The computer happens to have one AGP video card, and 4 PCI video cards in it. (Lucky computer user. ;) What will show up in the
/dev/path will be five entries for this driver.
Every "filename" in the
/dev/ hierarchy ressembles a supported device that can be used by the system, using the unique name assigned to it by the driver. If however
init_hardware() was unsuccessful then no names will be published in the
/dev/ hierarchy at all.
When a second accelerant tries to control the same video card, the kernel driver will keep a "times opened" counter, and report that the driver and video card were already initialized.
3.1.4 - uninit_driver()
When a kernel driver is no longer required, and the accelerant has performed the final close routine for the driver, the operating system will call
uninit_driver(). This routine releases all used resources and closes any open busses used by the driver.
3.1.5 - find_device()
find_device() routine returns all routine names associated with the "unique name", and makes it ready to be used by "driver hooks". These "driver hooks" are the interface to the user, used to access the driver in the kernel.
3.2 - Interface To The User
Once the kernel driver is initialized by the operating system, it can be accessed by using the following hook routines:
With this a driver can be opened and closed, can be written and read, and controlled dierctly. The hooks are based on a concept similar to file access: a driver can open or close the driver-filename in the
Applications of a kernel driver as a part of a video driver.
For a video driver only the following routines truly work:
The remaining routines are simply not used, according to the BeOS Documentation.
For the video driver the accelerant portion is considered the "user", unlike other driver types where an application can use the remaining hook routines directly, such as
write_hook(). An example of a driver that can use all hook functions would be a mass storage driver.
control_hook() routine determines when an accelerant trying to access the kernel driver if it is allowed to do so. Input/Output commands can be given for ISA or PCI operations too.
The kernel driver must recognize the supported card, map it into system memory, assign ISA and PCI "configuration space", assess what Input/Output commands are available, and be prepared to deal with the accelerant's use of "user_hooks". One more thing to be aware of, is that IRQ's can be accessed in kernel space too, more of which will be explained later.
Resources such as PCI Input/Output addresses are mapped into system memory, and in some cases, the entire video memory can be allocated in system memory, further speeding up video operations. By allocating these resources into system memory, they become available to the accelerant, without having to go through the (slow) kernel driver repeatedly. Any registers that the video card has may optionally be placed into memory, depending on if the programmer chooses to do so, the video card make/model, and if it is a PCI or AGP video card. More of these concerns are covered later.
3.2.1 - open_hook()
open_hook() routine makes a "shared info"
struct that can be accessed by all accelerants, and contains the card's ID, the manufacturer, card specifications (DAC speed for each color depth, memory and core speed), and display settings available by it.
If possible a semaphore is created that later can be used to synchronize with the vertical r