Section 4.6. The Device Tree


4.6. The Device Tree

From the standpoint of system initialization and booting, Open Firmware's core data structure is the device tree, which is referred to by all interfaces supported by Open Firmware.

The device tree is a representation of various hardware components in the system and their interconnections. It also contains pseudo-devices that have no corresponding physical devices.

The root node of the device tree is / (as in a Unix file system):

0 > dev /  ok 0 > ls ff88feb0: /cpus ff890118:   /PowerPC,G5@0 ff8905c8:     /l2-cache ff891550:   /PowerPC,G5@1 ff891a00:     /l2-cache ff891bf0: /chosen ff891d98: /memory@0,0 ff891fa8: /openprom ff892108:   /client-services ff8933f8: /rom@0,ff800000 ff8935b8:   /boot-rom@fff00000 ff8937a8:   /macos ff893840: /options ff8938d8: /packages ff893cc8:   /deblocker ff894618:   /disk-label ff895098:   /obp-tftp ff89fc68:   /telnet ... ff9a7610:   /temperatures ffa1bb70:     /drive-bay@4 ffa1f370:     /backside@6 ... ff9a77a8:   /audible-alarm ff9a7940:   /thermostats ffa1cfb8:     /overtemp*-signal@5800 ok 0 >


In the device tree, an individual node represents a bus, a physical device, or a pseudo-device. A node with childrenvisually indicated by indentations in the output of lsis often a bus. You can use the dev command to go to a certain node in the tree.

0 > dev /pseudo-hid ok       \ Go to node /pseudo-hid 0 > ls                        \ List children of current node ff943ff0: /keyboard ff944788: /mouse ff944d50: /eject-key 0 > dev mouse  ok             \ Go to a child 0 > pwd /pseudo-hid/mouse ok  \ Tell us where we are 0 > dev ..  ok                \ Go one level "up" 0 > pwd /pseudo-hid ok 0 > dev /cpus ok              \ Go to node /cpus 0 > ls ff890118: /PowerPC,G5@0 ff8905c8:   /l2-cache ff891550: /PowerPC,G5@1 ff891a00:   /l2-cache  ok


Since the complete pathname of a device could be rather long and inconvenient to use, commonly used devices have shorthand representations, or aliases. devalias shows the current list of aliases:

0 > devalias keyboard            /pseudo-hid/keyboard mouse               /pseudo-hid/mouse eject-key           /pseudo-hid/eject-key pci0                /pci@0,f0000000 ipc                 /ipc scca                /ht/pci@3/mac-io/escc/ch-a nvram               /nvram uni-n               /u3 u3                  /u3 dart                /u3/dart ... first-boot          /ht@0,f2000000/pci@7/k2-sata-root@c/k2-sata second-boot         /ht@0,f2000000/pci@5/ata-6@d/disk last-boot           /ht@0,f2000000/pci@6/ethernet screen              /pci@0,f0000000/ATY,WhelkParent@10/ATY,Whelk_A@0 ok


devalias followed by an alias shows the latter's expansion (note that the / separator is not used when specifying an alias):

0 > devalias hd /ht/pci@7/k2-sata-root/k2-sata@0/disk@0 ok 0 > devalias wireless /ht@0,f2000000/pci@4/pci80211@1 ok


The dir command can be used to list files on an HFS Plus or HFS volume. Its argument is a device path that represents a volume and a path within that volume. The device path can be an alias or a complete path.

0 > dir hd:\      Size/        GMT                      File/Dir      bytes   date     time   TYPE CRTR     Name      12292  6/18/ 5 15:23:14              .DS_Store     131072  5/25/ 5 10: 1:30              .hotfiles.btree   16777216  5/12/ 5  1:57:11  jrnl hfs+   .journal       4096  5/12/ 5  1:57:10  jrnl hfs+   .journal_info_block             6/18/ 5  1:32:14              .Spotlight-V100 ...             5/12/ 5  1:57:12              %00%00%00%00HFS+%20Private%20Data ok 0 > dir hd:\System\Library\CoreServices      Size/        GMT                      File/Dir      bytes   date     time   TYPE CRTR     Name        869  5/12/ 5  2:28:21  tbxj chrp   .disk_label         12  5/12/ 5  2:28:21              .disk_label.contentDetails             6/ 9/ 5  4: 8:44              AppleFileServer.app             3/28/ 5  4:53:13              Automator%20Launcher.app             3/28/ 5  4:42:25              BezelUI             3/28/ 5  4:51:51              Bluetooth%20Setup%20Assistant.app      14804  3/26/ 5 22:47: 0              bluetoothlauncher             3/28/ 5  4:51:51              BluetoothUIServer.app             3/21/ 5  3:12:59              BOMArchiveHelper.app     174276  5/19/ 5  3:46:35  tbxi chrp   BootX ...


Each node in the device tree may have properties, methods, and data.

4.6.1. Properties

A node's properties are externally visible data structures that describe the node and possibly its associated devices, which may further have their own specific properties. Open Firmware's client programs, as well as its own procedures, may inspect and modify properties. Access to properties is also available from the Open Firmware user interface. The .properties word shows the names and values of the current node's properties.

0 > dev enet  ok 0 > .properties vendor-id                         0000106b device-id               0000004c revision-id             00000000 class-code              00020000 interrupts              00000029 00000001 min-grant               00000040 ... name                    ethernet device_type             network network-type            ethernet ... local-mac-address       ... gbit-phy  ok 0 > dev /cpus/PowerPC,G5@0  ok 0 > .properties name                    PowerPC,G5 device_type             cpu reg                     00000000 cpu-version             003c0300 cpu#                    00000000 soft-reset              00000071 state                   running clock-frequency         9502f900 bus-frequency           4a817c80 config-bus-frequency    4a817c80 timebase-frequency      01fca055 reservation-granule-size00000080 tlb-sets                00000100 tlb-size                00001000 d-cache-size            00008000 i-cache-size            00010000 d-cache-sets            00000080 i-cache-sets            00000200 i-cache-block-size      00000080 d-cache-block-size      00000080 graphics performance-monitor altivec data-streams dcbz                    00000080 general-purpose 64-bit 32-64-bridge ...


The dump-properties word can be used to show properties of all nodes in the device tree.

0 > dump-properties / PROPERTIES: model                   PowerMac7,3 compatible              PowerMac7,3                         MacRISC4                         Power Macintosh ... /cpus/PowerPC,G5@0/l2-cache PROPERTIES: name                    l2-cache device_type             cache i-cache-size            00080000 ... /sep/thermostats/overtemp*-signal@5800 PROPERTIES: name                    overtemp*-signal ...


Properties are represented as collections of names and their corresponding values. Property names are human-readable text strings, and property values are variable-lengthpossibly zero-lengthbyte arrays representing encoded information. Standard property names found in a package include the following:

  • namethe name of the package

  • regthe package's "registers"

  • device_typethe characteristics the package's device is expected to have, such as block, byte, display, memory, network, pci, and serial

A package's registers can represent very different information depending on the nature of the package. For example, the registers of the memory package contain the physical memory addresses installed in the system. Details of installed memory can be examined through the .properties command.

The machine in Figure 42 has two PC2700 DDR SDRAM memory modules installed. The two pairs of numbers shown against reg specify the starting address and size of the module. The first RAM module starts at address 0x00000000 and has a size 0x10000000 (256MB). The second module starts at 0x10000000 (256MB) and has a size 256MB. The total RAM is therefore 512MB.

Figure 42. Physical memory properties in the device tree of a PowerBook G4

0 > dev /memory .properties ok name                       memory device_type                memory reg                        00000000  10000000                            10000000  10000000 slot-names                 00000003                            SODIMM0/J25LOWER                            SODIMM1/J25UPPER ... dimm-types                 DDR SDRAM                            DDR SDRAM dimm-speeds                PC2700U-25330                            PC2700U-25330 ...

It is possible to delete certain properties and specify your own. In the case of memory, this would be useful if you need to reduce the installed RAM size seen by Mac OS X without physically removing a RAM module. This way, you could simulate an arbitrary memory size that is less than the total memory installed. The following command sequence disables the second of the two memory modules installed in the machine from Figure 42. The change is not permanent in that it is not written to NVRAMonce the system is rebooted, the "disabled" module will be detected and used as before.

0 > dev /memory 0 > " reg" delete-property  ok 0 > 0 encode-int 10000000 encode-int encode+ " reg" property  ok


It must be noted that the reg properties may change from machine to machine, or more likely, with architectural changes. For example, the format of memory properties changed with the Power Mac G5. Figure 43 shows the memory properties on a quad-processor Power Mac G5 with six of its eight RAM slots filled, each with a 512MB DDR2 module.

Figure 43. Physical memory properties in the device tree of a Power Mac G5

0 > dev /memory  ok 0 > .properties name                    memory device_type             memory reg                     00000000 00000000  20000000                         00000000 20000000  20000000                         00000000 40000000  20000000                         00000000 60000000  20000000                         00000001 00000000  20000000                         00000001 20000000  20000000                         00000000 00000000  00000000                         00000000 00000000  00000000 slot-names              000000ff                         DIMM0/J6700                         DIMM1/J6800                         DIMM2/J6900                         DIMM3/J7000                         DIMM4/J7100                         DIMM5/J7200                         DIMM6/J7300                         DIMM7/J7400 available               00003000 1f5ed000 ram-map                 ... bank-names              000000ff                         64 bit Bank0/J6700/J6800/front                         64 bit Bank1/J6700/J6800/back                         64 bit Bank2/J6900/J7000/front                         64 bit Bank3/J6900/J7000/back                         64 bit Bank4/J7100/J7200/front                         64 bit Bank5/J7100/J7200/back                         64 bit Bank6/J7300/J7400/front                         64 bit Bank7/J7300/J7400/back ... dimm-types              DDR2 SDRAM                         DDR2 SDRAM                         DDR2 SDRAM                         DDR2 SDRAM                         DDR2 SDRAM                         DDR2 SDRAM dimm-speeds             PC2-4200U-444                         PC2-4200U-444                         PC2-4200U-444                         PC2-4200U-444                         PC2-4200U-444                         PC2-4200U-444 ...

A less adventurous and more appropriate way to limit visible RAM is to use the kernel's maxmem boot argument. You can use the nvram command-line program from within Mac OS X to get and set Open Firmware NVRAM variables. For example, the following command executed at a shell prompt in Mac OS X would limit available memory size to 128MB:

$ sudo nvram boot-args="maxmem=128"


A package that defines a physical address space usually contains the #address-cells and #size-cells standard properties. The value of #address-cells defines the number of cells required to encode a physical address within the address space defined by the package. The #size-cells property defines the number of cells required to represent the length of a physical address range. For example, the value of #address-cells for the root node of the device tree is 2 on the G5 and 1 on the G4.


4.6.2. Methods

A node's methods are simply software procedures supported by the device it represents. The words Forth word shows the current node's methods:

0 > dev enet  ok 0 > words power-down      ((open))        max-transfer    block-size      #blocks dma-free        dma-alloc       load            write           flush read            close           (open)          open            enet-quiesce ... show-enet-debug?                enet-base       my_space  ok


As we noted earlier, a word's definition may be viewed using see:

0 > see flush : flush     " enet: Flush" 1 .enet-debug restart-rxdma ; ok


The dump-device-tree word walks the entire device tree, showing each node's methods and properties.

4.6.3. Data

A node may also have private data used by its methods. Such data could be either instance-specific or static. Static data, which is seen by all instances, persists across instances.

There is a related abstraction called a package that we referred to earlier. Usually, a package is synonymous with a device. A distinction is made for pseudo-devices, which have no corresponding physical device. Pseudo-devices are said to have software-only packages. Here is a simple way to look at this.

  • The device tree has device nodes, some of which represent software-only devices.

  • A package is the combination of a device node's properties, methods, and data.

  • Multiple packages may implement the same interface. For example, two distinct network device driver packagessay, for two different network cardsmay each implement the same network device interface.

There is a special category of packages: the support packages. These do not correspond to any specific devices but implement general-purpose utility methods. They live under the /packages node in the device tree.

0 > dev /packages 0 > ls ff893cc8: /deblocker ff894618: /disk-label ff895098: /obp-tftp ff89fc68: /telnet ff8a0520: /mac-parts ff8a1e48: /mac-files ff8a4fc0: /hfs-plus-files ff8aa268: /fat-files ff8ad008: /iso-9660-files ff8ade20: /bootinfo-loader ff8afa88: /xcoff-loader ff8b0560: /macho-loader ff8b33d0: /pe-loader ff8b3dd8: /elf-loader ff8b5d20: /usb-hid-class ff8b8870: /usb-ms-class ff8bb540: /usb-audio-class ff929048: /ata-disk ff92b610: /atapi-disk ff92daf0: /sbp2-disk ff931508: /bootpath-search ff9380f8: /terminal-emulator ok 0 >


We came across the telnet support package earlier when we used it to connect to Open Firmware from another computer. obp-tftp implements a TFTP client for use in network booting. atapi-disk lets you communicate with an ATAPI device using the ATAPI protocol.

ATAPI

ATAPI stands for ATA Packet Interface, where ATA, in turn, stands for AT Attachment. AT (advanced technology) refers to the IBM PC/AT of 1984. ATA is a device interface for mass-storage devices. It is colloquially referred to as IDE (integrated device electronics) or EIDE (extended IDE). ATAPI can be viewed as an ATA extension used by a variety of non-hard-disk storage devices.





Mac OS X Internals. A Systems Approach
Mac OS X Internals: A Systems Approach
ISBN: 0321278542
EAN: 2147483647
Year: 2006
Pages: 161
Authors: Amit Singh

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net