Writing Device Drivers

Mapping the Device

To test the device, it must be mapped into memory. The PROM can then be used to verify proper operation of the device by using data-transfer commands to transfer bytes, words, and long words. If the device can be operated from the PROM, even in a limited way, the driver should also be able to operate the device.

To set up the device for initial testing, perform the following steps:

  1. Determine the SBus slot number the device is in. In this example, the cgsix device is located in slot 2.

  2. Determine the offset within the physical address space used by the device.

    The offset used is specific to the device. In the cgsix example, the video memory happens to start at an offset of 0x800000.

  3. Use the select-dev word to select the sbus device and the map-in word to map the device in.

    The select-dev word takes a string of the device path as its argument. The map-in word takes an offset, a slot number, and a size as arguments to map. Like the offset, the size of the byte transfer is specific to the device. In the cgsix example, the size is set to 0x100000 bytes.

    In the following code example, the sbus path is displayed as an argument to the select-dev word, and the offset, slot number, and size values for the frame buffer are displayed as arguments to the map-in word. Notice that there should be a space between the opening quote and / in the select-dev argument. The virtual address to use remains on top of the stack. The stack is shown using the .s word. It can be assigned a name with the constant operation.

    ok "/sbus@1f,0" select-dev
    ok 800000 2 100000 map-inok .sffe98000
    ok constant fb