rust-kernel
Rustbelt: a hobby x86_64 kernel written in Rust
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | //! A small reader for the **device tree** (a "DTB", flattened device tree).
//!
//! Arm boards have no PCI-style "ask the hardware what's there", so the
//! firmware (here QEMU) hands the kernel a description: a tree of nodes
//! like `pl011@9000000` with properties like `compatible = "arm,pl011"`
//! and `reg = <address size>`. The format is simple (devicetree.org spec,
//! chapter 5): a header, then a list of tokens (begin node, property, end
//! node), then a table of property names. Every number in it is big-endian.
//!
//! This reader only does what the bring-up needs: walk every node and hand
//! over its name, `compatible`, `reg`, `interrupts` and `device_type`. It
//! assumes `#address-cells = 2` and `#size-cells = 2` (64-bit addresses
//! and sizes), which is what QEMU's virt uses for every node we read.
const MAGIC: u32 = 0xd00d_feed;
const BEGIN_NODE: u32 = 1;
const END_NODE: u32 = 2;
const PROP: u32 = 3;
const NOP: u32 = 4;
const END: u32 = 9; // (the walk stops at anything it doesn't know, END included)
const MAX_DEPTH: usize = 16;
/// One node, as `for_each_node` hands it over.
|