PATH 
ADC Home > Documentation > Hardware > Device Managers and Drivers > PCI Card Services > Designing PCI Cards and Drivers for Power Macintosh Computers


  

Sample FCode Drivers

Listing 5-2 shows an example of minimal FCode support for a PCI SCSI card. The FCode in the example provides identifying information in its device node and creates a property that contains the run-time driver to be loaded into the Macintosh system heap by the Expansion Bus Manager.

Listing 5-2 Minimal PCI SCSI card FCode support

/ push arguments on the stack for pci-header:
/ *** THESE MUST MATCH THE CONFIG REGISTERS FOR YOUR ***
/ *** FCODE TO BE RECOGNIZED BY OPEN FIRMWARE ***
/ vendor #, device #, class-code = SCSI bus controller

/                       vendorID        deviceID            classCode
    tokenizer[ hex      1000           0003               010000 ]tokenizer

/ generate proper PCI image header
    pci-header

/ generate proper FCode header (within PCI image)
    fcode-version2
    hex

/ encode name property
/ refer to IEEE 1275-1994, page 162
/ refer to PCI bus binding to IEEE 1275-1994 Revision 2.0,
/ Section 2.5 FCode Evaluation Semantics, page 9, line 36
    "AAPL,scsi" encode-string " name" property

/ encode compatibility property
/ refer to IEEE 1275-1995, page 127
/ refer to Open Firmware Recommended Pratice, Generic Names, version 1.4,
/ Section 3 Generic Names, page 5, Guidline 2
    "APPL,SYN53C875J" encode-string " compatibility" property

/ encode device_type property
/ refer to IEEE Std 1275-1994 : page 208
" scsi-2" encode-string " device_type" property

/ encode reg property
/ refer to IEEE Std 1275-1994 : page 174
/ refer to Writting FCode Programs For PCI : page 84

/ generate a "reg" property which lists our configuration space at the start
/ of the assigned space. with 0 size (as required by the PCI Binding
/ Supplement)

/ PCI Configuration Space entry of the reg property
my-address my-space encode-phys configuration space
0 encode-int        encode+     0 encode-int        encode+     \ size ( 0 )

/ Base Address Zero entry of the reg property
my-address my-space 01000010 or encode-phys         encode+     \ I/O space
0 encode-int        encode+     100 encode-int      encode+     \ size ( 256 )

/ Base Address One entry of the reg property
my-address my-space 02000014 or encode-phys         encode+     \ memory space
0 encode-int        encode+     100 encode-int      encode+     \ size ( 256 )

/ Base Address Two entry of the reg property
my-address my-space 02000018 or encode-phys         encode+     \ memory space
0 encode-int        encode+     1000 encode-int     encode+     \ size ( 4K )

/ PCI Expansion ROM entry of the reg property
my-address my-space 02000030 or encode-phys         encode+     \ expansion rom
0 encode-int        encode+     10000 encode-int    encode+     \ size ( 64K )

" reg" property

/ "power-consumption" property which lists standby and full-on power
/ consumtion for various power rails in microwatts goes here; if you
/ don't create this property, Open Firmware creates one by filling in the
/ "unspecified" rail entries from the PRSNT pins (if you don't know the
/ power consumption values, you can fill the "unspecified" entries with
/ zeros)

0 encode-int 0 encode-int encode+                               / "unspecified"
d# 7500000 encode-int d# 7500000 encode-int encode+ encode+     / +5V
0 encode-int 0 encode-int encode+ encode+                       / +3V
d# 8100000 encode-int d# 8100000 encode-int encode+ encode+     / I/Opower
/ remaining entries are 0 and can be omitted
0 encode-int 0 encode-int encode+ encode+                       / reserved

"power-consumption" property

/ the following properties will automatically be generated for this card by
/ Open Firmware from the PCI Configuration Space Header.
/ Ref : PCI Bus Binding to : IEEE Std 1275-1994 Revision 2.0, Section 2.5,
/ FCode Evaluation Semantics : page 8 : lines 14 - 57.

/ "has-fcode"
/ "vendor-id"
/ "device-id"
/ "revision-id"
/ "class-code"
/ "interrupts"
/ "min-grant" - unless header is type 01h
/ "max-latency" - unless header is type 01h
/ "devsel-speed"
/ "fast-back-to-back"
/ "subsystem-id"
/ "cache-line-size"
/ "66MHz-capable"
/ "udf-supported"
/ "assigned-addresses"

/ there is enough information for the runtime driver to be able to locate the card,
/ however a complete FCode implementation would also provide boot-time I/O services

/ include an image of the runtime driver, and have it assigned as the value of a
/ property that the Mac OS will read at startup

code-end            / end FCode header
pci-end             / end PCI header

Listing 5-3 Minimal network FCode driver support

/ Network drivers should support the
/ TFTP Booting Extension Recommened Pratice
/ [promiscous], [speed= n], [duplex= mode], [bootp], [siaddr], [filename],
/ [ciaddr], [giaddr], [bootp-retries], [tftp-retries]
/ See the PCI DDK 3.0 for a complete Network driver example
" ethernet" device-name
" network" device-type
" ethernet" encode-string " network-type" property
" network" encode-string " removable" property
" net" encode-string " category" property

Listing 5-4 Minimal display FCode driver support

/ See the PCI DDK 3.0 for a complete display driver example
" display" device-type                      / defines the device type as display


: my-open ( -- )
    ... initialize device                   / your device initialization
    ... monitor sense                       / monitor sense code
    ;
: my-close ( -- )
    ...             / close code goes here
    ;


[`] my-open is-install
    / You could put fcode in this area that puts up boot time options or a logo
    / in a terminal emulator.
    / here is a prototype example
    : open ( -- true )
        ...
        my-open
        ;
    : write ( adr len -- actual )
        ...
        ;
    : draw-logo ( l# a w h -- )
        ...
        ;
    : restore
    ;
['] my-close is-remove
    : close ( -- )
        my-close
        ;
/ If you want to draw with color, you should support the
/ Open Firmware 8-bit graphics extensions recommended pratice. See also,
/ "Terminal Emulation in Graphics Drivers" on page 5-cxxvi.
/ The basic requirements are:
        / draw-rectangle ( adr x y w h -- )
        / fill-rectangle ( index x y w h -- )
        / read-rectangle ( adr x y w h -- )
        / color! ( r g b index -- )
        / color@ ( index -- r g b )
        / set-colors ( adr index #indices -- )
        / get-colors ( adr index #indices -- )

© 1999 Apple Computer, Inc. – (Last Updated 26 March 99)