diff options
author | Greg Kroah-Hartman <gregkh@suse.de> | 2011-02-24 14:36:31 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2011-02-24 14:36:31 -0500 |
commit | f227e08b71b9c273eaa29a57370a3a5b833aa382 (patch) | |
tree | 9f1483776a2bde3bb1a6bd744e69acf19f6f3428 /Documentation/devicetree/booting-without-of.txt | |
parent | fec38d1752c01ad72789bac9f1a128f7e933735d (diff) | |
parent | f5412be599602124d2bdd49947b231dd77c0bf99 (diff) |
Merge 2.6.38-rc6 into tty-next
This was to resolve a merge issue with drivers/char/Makefile and
drivers/tty/serial/68328serial.c
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'Documentation/devicetree/booting-without-of.txt')
-rw-r--r-- | Documentation/devicetree/booting-without-of.txt | 1390 |
1 files changed, 1390 insertions, 0 deletions
diff --git a/Documentation/devicetree/booting-without-of.txt b/Documentation/devicetree/booting-without-of.txt new file mode 100644 index 000000000000..28b1c9d3d351 --- /dev/null +++ b/Documentation/devicetree/booting-without-of.txt | |||
@@ -0,0 +1,1390 @@ | |||
1 | Booting the Linux/ppc kernel without Open Firmware | ||
2 | -------------------------------------------------- | ||
3 | |||
4 | (c) 2005 Benjamin Herrenschmidt <benh at kernel.crashing.org>, | ||
5 | IBM Corp. | ||
6 | (c) 2005 Becky Bruce <becky.bruce at freescale.com>, | ||
7 | Freescale Semiconductor, FSL SOC and 32-bit additions | ||
8 | (c) 2006 MontaVista Software, Inc. | ||
9 | Flash chip node definition | ||
10 | |||
11 | Table of Contents | ||
12 | ================= | ||
13 | |||
14 | I - Introduction | ||
15 | 1) Entry point for arch/powerpc | ||
16 | |||
17 | II - The DT block format | ||
18 | 1) Header | ||
19 | 2) Device tree generalities | ||
20 | 3) Device tree "structure" block | ||
21 | 4) Device tree "strings" block | ||
22 | |||
23 | III - Required content of the device tree | ||
24 | 1) Note about cells and address representation | ||
25 | 2) Note about "compatible" properties | ||
26 | 3) Note about "name" properties | ||
27 | 4) Note about node and property names and character set | ||
28 | 5) Required nodes and properties | ||
29 | a) The root node | ||
30 | b) The /cpus node | ||
31 | c) The /cpus/* nodes | ||
32 | d) the /memory node(s) | ||
33 | e) The /chosen node | ||
34 | f) the /soc<SOCname> node | ||
35 | |||
36 | IV - "dtc", the device tree compiler | ||
37 | |||
38 | V - Recommendations for a bootloader | ||
39 | |||
40 | VI - System-on-a-chip devices and nodes | ||
41 | 1) Defining child nodes of an SOC | ||
42 | 2) Representing devices without a current OF specification | ||
43 | |||
44 | VII - Specifying interrupt information for devices | ||
45 | 1) interrupts property | ||
46 | 2) interrupt-parent property | ||
47 | 3) OpenPIC Interrupt Controllers | ||
48 | 4) ISA Interrupt Controllers | ||
49 | |||
50 | VIII - Specifying device power management information (sleep property) | ||
51 | |||
52 | Appendix A - Sample SOC node for MPC8540 | ||
53 | |||
54 | |||
55 | Revision Information | ||
56 | ==================== | ||
57 | |||
58 | May 18, 2005: Rev 0.1 - Initial draft, no chapter III yet. | ||
59 | |||
60 | May 19, 2005: Rev 0.2 - Add chapter III and bits & pieces here or | ||
61 | clarifies the fact that a lot of things are | ||
62 | optional, the kernel only requires a very | ||
63 | small device tree, though it is encouraged | ||
64 | to provide an as complete one as possible. | ||
65 | |||
66 | May 24, 2005: Rev 0.3 - Precise that DT block has to be in RAM | ||
67 | - Misc fixes | ||
68 | - Define version 3 and new format version 16 | ||
69 | for the DT block (version 16 needs kernel | ||
70 | patches, will be fwd separately). | ||
71 | String block now has a size, and full path | ||
72 | is replaced by unit name for more | ||
73 | compactness. | ||
74 | linux,phandle is made optional, only nodes | ||
75 | that are referenced by other nodes need it. | ||
76 | "name" property is now automatically | ||
77 | deduced from the unit name | ||
78 | |||
79 | June 1, 2005: Rev 0.4 - Correct confusion between OF_DT_END and | ||
80 | OF_DT_END_NODE in structure definition. | ||
81 | - Change version 16 format to always align | ||
82 | property data to 4 bytes. Since tokens are | ||
83 | already aligned, that means no specific | ||
84 | required alignment between property size | ||
85 | and property data. The old style variable | ||
86 | alignment would make it impossible to do | ||
87 | "simple" insertion of properties using | ||
88 | memmove (thanks Milton for | ||
89 | noticing). Updated kernel patch as well | ||
90 | - Correct a few more alignment constraints | ||
91 | - Add a chapter about the device-tree | ||
92 | compiler and the textural representation of | ||
93 | the tree that can be "compiled" by dtc. | ||
94 | |||
95 | November 21, 2005: Rev 0.5 | ||
96 | - Additions/generalizations for 32-bit | ||
97 | - Changed to reflect the new arch/powerpc | ||
98 | structure | ||
99 | - Added chapter VI | ||
100 | |||
101 | |||
102 | ToDo: | ||
103 | - Add some definitions of interrupt tree (simple/complex) | ||
104 | - Add some definitions for PCI host bridges | ||
105 | - Add some common address format examples | ||
106 | - Add definitions for standard properties and "compatible" | ||
107 | names for cells that are not already defined by the existing | ||
108 | OF spec. | ||
109 | - Compare FSL SOC use of PCI to standard and make sure no new | ||
110 | node definition required. | ||
111 | - Add more information about node definitions for SOC devices | ||
112 | that currently have no standard, like the FSL CPM. | ||
113 | |||
114 | |||
115 | I - Introduction | ||
116 | ================ | ||
117 | |||
118 | During the development of the Linux/ppc64 kernel, and more | ||
119 | specifically, the addition of new platform types outside of the old | ||
120 | IBM pSeries/iSeries pair, it was decided to enforce some strict rules | ||
121 | regarding the kernel entry and bootloader <-> kernel interfaces, in | ||
122 | order to avoid the degeneration that had become the ppc32 kernel entry | ||
123 | point and the way a new platform should be added to the kernel. The | ||
124 | legacy iSeries platform breaks those rules as it predates this scheme, | ||
125 | but no new board support will be accepted in the main tree that | ||
126 | doesn't follow them properly. In addition, since the advent of the | ||
127 | arch/powerpc merged architecture for ppc32 and ppc64, new 32-bit | ||
128 | platforms and 32-bit platforms which move into arch/powerpc will be | ||
129 | required to use these rules as well. | ||
130 | |||
131 | The main requirement that will be defined in more detail below is | ||
132 | the presence of a device-tree whose format is defined after Open | ||
133 | Firmware specification. However, in order to make life easier | ||
134 | to embedded board vendors, the kernel doesn't require the device-tree | ||
135 | to represent every device in the system and only requires some nodes | ||
136 | and properties to be present. This will be described in detail in | ||
137 | section III, but, for example, the kernel does not require you to | ||
138 | create a node for every PCI device in the system. It is a requirement | ||
139 | to have a node for PCI host bridges in order to provide interrupt | ||
140 | routing informations and memory/IO ranges, among others. It is also | ||
141 | recommended to define nodes for on chip devices and other buses that | ||
142 | don't specifically fit in an existing OF specification. This creates a | ||
143 | great flexibility in the way the kernel can then probe those and match | ||
144 | drivers to device, without having to hard code all sorts of tables. It | ||
145 | also makes it more flexible for board vendors to do minor hardware | ||
146 | upgrades without significantly impacting the kernel code or cluttering | ||
147 | it with special cases. | ||
148 | |||
149 | |||
150 | 1) Entry point for arch/powerpc | ||
151 | ------------------------------- | ||
152 | |||
153 | There is one single entry point to the kernel, at the start | ||
154 | of the kernel image. That entry point supports two calling | ||
155 | conventions: | ||
156 | |||
157 | a) Boot from Open Firmware. If your firmware is compatible | ||
158 | with Open Firmware (IEEE 1275) or provides an OF compatible | ||
159 | client interface API (support for "interpret" callback of | ||
160 | forth words isn't required), you can enter the kernel with: | ||
161 | |||
162 | r5 : OF callback pointer as defined by IEEE 1275 | ||
163 | bindings to powerpc. Only the 32-bit client interface | ||
164 | is currently supported | ||
165 | |||
166 | r3, r4 : address & length of an initrd if any or 0 | ||
167 | |||
168 | The MMU is either on or off; the kernel will run the | ||
169 | trampoline located in arch/powerpc/kernel/prom_init.c to | ||
170 | extract the device-tree and other information from open | ||
171 | firmware and build a flattened device-tree as described | ||
172 | in b). prom_init() will then re-enter the kernel using | ||
173 | the second method. This trampoline code runs in the | ||
174 | context of the firmware, which is supposed to handle all | ||
175 | exceptions during that time. | ||
176 | |||
177 | b) Direct entry with a flattened device-tree block. This entry | ||
178 | point is called by a) after the OF trampoline and can also be | ||
179 | called directly by a bootloader that does not support the Open | ||
180 | Firmware client interface. It is also used by "kexec" to | ||
181 | implement "hot" booting of a new kernel from a previous | ||
182 | running one. This method is what I will describe in more | ||
183 | details in this document, as method a) is simply standard Open | ||
184 | Firmware, and thus should be implemented according to the | ||
185 | various standard documents defining it and its binding to the | ||
186 | PowerPC platform. The entry point definition then becomes: | ||
187 | |||
188 | r3 : physical pointer to the device-tree block | ||
189 | (defined in chapter II) in RAM | ||
190 | |||
191 | r4 : physical pointer to the kernel itself. This is | ||
192 | used by the assembly code to properly disable the MMU | ||
193 | in case you are entering the kernel with MMU enabled | ||
194 | and a non-1:1 mapping. | ||
195 | |||
196 | r5 : NULL (as to differentiate with method a) | ||
197 | |||
198 | Note about SMP entry: Either your firmware puts your other | ||
199 | CPUs in some sleep loop or spin loop in ROM where you can get | ||
200 | them out via a soft reset or some other means, in which case | ||
201 | you don't need to care, or you'll have to enter the kernel | ||
202 | with all CPUs. The way to do that with method b) will be | ||
203 | described in a later revision of this document. | ||
204 | |||
205 | Board supports (platforms) are not exclusive config options. An | ||
206 | arbitrary set of board supports can be built in a single kernel | ||
207 | image. The kernel will "know" what set of functions to use for a | ||
208 | given platform based on the content of the device-tree. Thus, you | ||
209 | should: | ||
210 | |||
211 | a) add your platform support as a _boolean_ option in | ||
212 | arch/powerpc/Kconfig, following the example of PPC_PSERIES, | ||
213 | PPC_PMAC and PPC_MAPLE. The later is probably a good | ||
214 | example of a board support to start from. | ||
215 | |||
216 | b) create your main platform file as | ||
217 | "arch/powerpc/platforms/myplatform/myboard_setup.c" and add it | ||
218 | to the Makefile under the condition of your CONFIG_ | ||
219 | option. This file will define a structure of type "ppc_md" | ||
220 | containing the various callbacks that the generic code will | ||
221 | use to get to your platform specific code | ||
222 | |||
223 | A kernel image may support multiple platforms, but only if the | ||
224 | platforms feature the same core architecture. A single kernel build | ||
225 | cannot support both configurations with Book E and configurations | ||
226 | with classic Powerpc architectures. | ||
227 | |||
228 | |||
229 | II - The DT block format | ||
230 | ======================== | ||
231 | |||
232 | |||
233 | This chapter defines the actual format of the flattened device-tree | ||
234 | passed to the kernel. The actual content of it and kernel requirements | ||
235 | are described later. You can find example of code manipulating that | ||
236 | format in various places, including arch/powerpc/kernel/prom_init.c | ||
237 | which will generate a flattened device-tree from the Open Firmware | ||
238 | representation, or the fs2dt utility which is part of the kexec tools | ||
239 | which will generate one from a filesystem representation. It is | ||
240 | expected that a bootloader like uboot provides a bit more support, | ||
241 | that will be discussed later as well. | ||
242 | |||
243 | Note: The block has to be in main memory. It has to be accessible in | ||
244 | both real mode and virtual mode with no mapping other than main | ||
245 | memory. If you are writing a simple flash bootloader, it should copy | ||
246 | the block to RAM before passing it to the kernel. | ||
247 | |||
248 | |||
249 | 1) Header | ||
250 | --------- | ||
251 | |||
252 | The kernel is passed the physical address pointing to an area of memory | ||
253 | that is roughly described in include/linux/of_fdt.h by the structure | ||
254 | boot_param_header: | ||
255 | |||
256 | struct boot_param_header { | ||
257 | u32 magic; /* magic word OF_DT_HEADER */ | ||
258 | u32 totalsize; /* total size of DT block */ | ||
259 | u32 off_dt_struct; /* offset to structure */ | ||
260 | u32 off_dt_strings; /* offset to strings */ | ||
261 | u32 off_mem_rsvmap; /* offset to memory reserve map | ||
262 | */ | ||
263 | u32 version; /* format version */ | ||
264 | u32 last_comp_version; /* last compatible version */ | ||
265 | |||
266 | /* version 2 fields below */ | ||
267 | u32 boot_cpuid_phys; /* Which physical CPU id we're | ||
268 | booting on */ | ||
269 | /* version 3 fields below */ | ||
270 | u32 size_dt_strings; /* size of the strings block */ | ||
271 | |||
272 | /* version 17 fields below */ | ||
273 | u32 size_dt_struct; /* size of the DT structure block */ | ||
274 | }; | ||
275 | |||
276 | Along with the constants: | ||
277 | |||
278 | /* Definitions used by the flattened device tree */ | ||
279 | #define OF_DT_HEADER 0xd00dfeed /* 4: version, | ||
280 | 4: total size */ | ||
281 | #define OF_DT_BEGIN_NODE 0x1 /* Start node: full name | ||
282 | */ | ||
283 | #define OF_DT_END_NODE 0x2 /* End node */ | ||
284 | #define OF_DT_PROP 0x3 /* Property: name off, | ||
285 | size, content */ | ||
286 | #define OF_DT_END 0x9 | ||
287 | |||
288 | All values in this header are in big endian format, the various | ||
289 | fields in this header are defined more precisely below. All | ||
290 | "offset" values are in bytes from the start of the header; that is | ||
291 | from the physical base address of the device tree block. | ||
292 | |||
293 | - magic | ||
294 | |||
295 | This is a magic value that "marks" the beginning of the | ||
296 | device-tree block header. It contains the value 0xd00dfeed and is | ||
297 | defined by the constant OF_DT_HEADER | ||
298 | |||
299 | - totalsize | ||
300 | |||
301 | This is the total size of the DT block including the header. The | ||
302 | "DT" block should enclose all data structures defined in this | ||
303 | chapter (who are pointed to by offsets in this header). That is, | ||
304 | the device-tree structure, strings, and the memory reserve map. | ||
305 | |||
306 | - off_dt_struct | ||
307 | |||
308 | This is an offset from the beginning of the header to the start | ||
309 | of the "structure" part the device tree. (see 2) device tree) | ||
310 | |||
311 | - off_dt_strings | ||
312 | |||
313 | This is an offset from the beginning of the header to the start | ||
314 | of the "strings" part of the device-tree | ||
315 | |||
316 | - off_mem_rsvmap | ||
317 | |||
318 | This is an offset from the beginning of the header to the start | ||
319 | of the reserved memory map. This map is a list of pairs of 64- | ||
320 | bit integers. Each pair is a physical address and a size. The | ||
321 | list is terminated by an entry of size 0. This map provides the | ||
322 | kernel with a list of physical memory areas that are "reserved" | ||
323 | and thus not to be used for memory allocations, especially during | ||
324 | early initialization. The kernel needs to allocate memory during | ||
325 | boot for things like un-flattening the device-tree, allocating an | ||
326 | MMU hash table, etc... Those allocations must be done in such a | ||
327 | way to avoid overriding critical things like, on Open Firmware | ||
328 | capable machines, the RTAS instance, or on some pSeries, the TCE | ||
329 | tables used for the iommu. Typically, the reserve map should | ||
330 | contain _at least_ this DT block itself (header,total_size). If | ||
331 | you are passing an initrd to the kernel, you should reserve it as | ||
332 | well. You do not need to reserve the kernel image itself. The map | ||
333 | should be 64-bit aligned. | ||
334 | |||
335 | - version | ||
336 | |||
337 | This is the version of this structure. Version 1 stops | ||
338 | here. Version 2 adds an additional field boot_cpuid_phys. | ||
339 | Version 3 adds the size of the strings block, allowing the kernel | ||
340 | to reallocate it easily at boot and free up the unused flattened | ||
341 | structure after expansion. Version 16 introduces a new more | ||
342 | "compact" format for the tree itself that is however not backward | ||
343 | compatible. Version 17 adds an additional field, size_dt_struct, | ||
344 | allowing it to be reallocated or moved more easily (this is | ||
345 | particularly useful for bootloaders which need to make | ||
346 | adjustments to a device tree based on probed information). You | ||
347 | should always generate a structure of the highest version defined | ||
348 | at the time of your implementation. Currently that is version 17, | ||
349 | unless you explicitly aim at being backward compatible. | ||
350 | |||
351 | - last_comp_version | ||
352 | |||
353 | Last compatible version. This indicates down to what version of | ||
354 | the DT block you are backward compatible. For example, version 2 | ||
355 | is backward compatible with version 1 (that is, a kernel build | ||
356 | for version 1 will be able to boot with a version 2 format). You | ||
357 | should put a 1 in this field if you generate a device tree of | ||
358 | version 1 to 3, or 16 if you generate a tree of version 16 or 17 | ||
359 | using the new unit name format. | ||
360 | |||
361 | - boot_cpuid_phys | ||
362 | |||
363 | This field only exist on version 2 headers. It indicate which | ||
364 | physical CPU ID is calling the kernel entry point. This is used, | ||
365 | among others, by kexec. If you are on an SMP system, this value | ||
366 | should match the content of the "reg" property of the CPU node in | ||
367 | the device-tree corresponding to the CPU calling the kernel entry | ||
368 | point (see further chapters for more informations on the required | ||
369 | device-tree contents) | ||
370 | |||
371 | - size_dt_strings | ||
372 | |||
373 | This field only exists on version 3 and later headers. It | ||
374 | gives the size of the "strings" section of the device tree (which | ||
375 | starts at the offset given by off_dt_strings). | ||
376 | |||
377 | - size_dt_struct | ||
378 | |||
379 | This field only exists on version 17 and later headers. It gives | ||
380 | the size of the "structure" section of the device tree (which | ||
381 | starts at the offset given by off_dt_struct). | ||
382 | |||
383 | So the typical layout of a DT block (though the various parts don't | ||
384 | need to be in that order) looks like this (addresses go from top to | ||
385 | bottom): | ||
386 | |||
387 | |||
388 | ------------------------------ | ||
389 | base -> | struct boot_param_header | | ||
390 | ------------------------------ | ||
391 | | (alignment gap) (*) | | ||
392 | ------------------------------ | ||
393 | | memory reserve map | | ||
394 | ------------------------------ | ||
395 | | (alignment gap) | | ||
396 | ------------------------------ | ||
397 | | | | ||
398 | | device-tree structure | | ||
399 | | | | ||
400 | ------------------------------ | ||
401 | | (alignment gap) | | ||
402 | ------------------------------ | ||
403 | | | | ||
404 | | device-tree strings | | ||
405 | | | | ||
406 | -----> ------------------------------ | ||
407 | | | ||
408 | | | ||
409 | --- (base + totalsize) | ||
410 | |||
411 | (*) The alignment gaps are not necessarily present; their presence | ||
412 | and size are dependent on the various alignment requirements of | ||
413 | the individual data blocks. | ||
414 | |||
415 | |||
416 | 2) Device tree generalities | ||
417 | --------------------------- | ||
418 | |||
419 | This device-tree itself is separated in two different blocks, a | ||
420 | structure block and a strings block. Both need to be aligned to a 4 | ||
421 | byte boundary. | ||
422 | |||
423 | First, let's quickly describe the device-tree concept before detailing | ||
424 | the storage format. This chapter does _not_ describe the detail of the | ||
425 | required types of nodes & properties for the kernel, this is done | ||
426 | later in chapter III. | ||
427 | |||
428 | The device-tree layout is strongly inherited from the definition of | ||
429 | the Open Firmware IEEE 1275 device-tree. It's basically a tree of | ||
430 | nodes, each node having two or more named properties. A property can | ||
431 | have a value or not. | ||
432 | |||
433 | It is a tree, so each node has one and only one parent except for the | ||
434 | root node who has no parent. | ||
435 | |||
436 | A node has 2 names. The actual node name is generally contained in a | ||
437 | property of type "name" in the node property list whose value is a | ||
438 | zero terminated string and is mandatory for version 1 to 3 of the | ||
439 | format definition (as it is in Open Firmware). Version 16 makes it | ||
440 | optional as it can generate it from the unit name defined below. | ||
441 | |||
442 | There is also a "unit name" that is used to differentiate nodes with | ||
443 | the same name at the same level, it is usually made of the node | ||
444 | names, the "@" sign, and a "unit address", which definition is | ||
445 | specific to the bus type the node sits on. | ||
446 | |||
447 | The unit name doesn't exist as a property per-se but is included in | ||
448 | the device-tree structure. It is typically used to represent "path" in | ||
449 | the device-tree. More details about the actual format of these will be | ||
450 | below. | ||
451 | |||
452 | The kernel generic code does not make any formal use of the | ||
453 | unit address (though some board support code may do) so the only real | ||
454 | requirement here for the unit address is to ensure uniqueness of | ||
455 | the node unit name at a given level of the tree. Nodes with no notion | ||
456 | of address and no possible sibling of the same name (like /memory or | ||
457 | /cpus) may omit the unit address in the context of this specification, | ||
458 | or use the "@0" default unit address. The unit name is used to define | ||
459 | a node "full path", which is the concatenation of all parent node | ||
460 | unit names separated with "/". | ||
461 | |||
462 | The root node doesn't have a defined name, and isn't required to have | ||
463 | a name property either if you are using version 3 or earlier of the | ||
464 | format. It also has no unit address (no @ symbol followed by a unit | ||
465 | address). The root node unit name is thus an empty string. The full | ||
466 | path to the root node is "/". | ||
467 | |||
468 | Every node which actually represents an actual device (that is, a node | ||
469 | which isn't only a virtual "container" for more nodes, like "/cpus" | ||
470 | is) is also required to have a "compatible" property indicating the | ||
471 | specific hardware and an optional list of devices it is fully | ||
472 | backwards compatible with. | ||
473 | |||
474 | Finally, every node that can be referenced from a property in another | ||
475 | node is required to have either a "phandle" or a "linux,phandle" | ||
476 | property. Real Open Firmware implementations provide a unique | ||
477 | "phandle" value for every node that the "prom_init()" trampoline code | ||
478 | turns into "linux,phandle" properties. However, this is made optional | ||
479 | if the flattened device tree is used directly. An example of a node | ||
480 | referencing another node via "phandle" is when laying out the | ||
481 | interrupt tree which will be described in a further version of this | ||
482 | document. | ||
483 | |||
484 | The "phandle" property is a 32-bit value that uniquely | ||
485 | identifies a node. You are free to use whatever values or system of | ||
486 | values, internal pointers, or whatever to generate these, the only | ||
487 | requirement is that every node for which you provide that property has | ||
488 | a unique value for it. | ||
489 | |||
490 | Here is an example of a simple device-tree. In this example, an "o" | ||
491 | designates a node followed by the node unit name. Properties are | ||
492 | presented with their name followed by their content. "content" | ||
493 | represents an ASCII string (zero terminated) value, while <content> | ||
494 | represents a 32-bit hexadecimal value. The various nodes in this | ||
495 | example will be discussed in a later chapter. At this point, it is | ||
496 | only meant to give you a idea of what a device-tree looks like. I have | ||
497 | purposefully kept the "name" and "linux,phandle" properties which | ||
498 | aren't necessary in order to give you a better idea of what the tree | ||
499 | looks like in practice. | ||
500 | |||
501 | / o device-tree | ||
502 | |- name = "device-tree" | ||
503 | |- model = "MyBoardName" | ||
504 | |- compatible = "MyBoardFamilyName" | ||
505 | |- #address-cells = <2> | ||
506 | |- #size-cells = <2> | ||
507 | |- linux,phandle = <0> | ||
508 | | | ||
509 | o cpus | ||
510 | | | - name = "cpus" | ||
511 | | | - linux,phandle = <1> | ||
512 | | | - #address-cells = <1> | ||
513 | | | - #size-cells = <0> | ||
514 | | | | ||
515 | | o PowerPC,970@0 | ||
516 | | |- name = "PowerPC,970" | ||
517 | | |- device_type = "cpu" | ||
518 | | |- reg = <0> | ||
519 | | |- clock-frequency = <5f5e1000> | ||
520 | | |- 64-bit | ||
521 | | |- linux,phandle = <2> | ||
522 | | | ||
523 | o memory@0 | ||
524 | | |- name = "memory" | ||
525 | | |- device_type = "memory" | ||
526 | | |- reg = <00000000 00000000 00000000 20000000> | ||
527 | | |- linux,phandle = <3> | ||
528 | | | ||
529 | o chosen | ||
530 | |- name = "chosen" | ||
531 | |- bootargs = "root=/dev/sda2" | ||
532 | |- linux,phandle = <4> | ||
533 | |||
534 | This tree is almost a minimal tree. It pretty much contains the | ||
535 | minimal set of required nodes and properties to boot a linux kernel; | ||
536 | that is, some basic model informations at the root, the CPUs, and the | ||
537 | physical memory layout. It also includes misc information passed | ||
538 | through /chosen, like in this example, the platform type (mandatory) | ||
539 | and the kernel command line arguments (optional). | ||
540 | |||
541 | The /cpus/PowerPC,970@0/64-bit property is an example of a | ||
542 | property without a value. All other properties have a value. The | ||
543 | significance of the #address-cells and #size-cells properties will be | ||
544 | explained in chapter IV which defines precisely the required nodes and | ||
545 | properties and their content. | ||
546 | |||
547 | |||
548 | 3) Device tree "structure" block | ||
549 | |||
550 | The structure of the device tree is a linearized tree structure. The | ||
551 | "OF_DT_BEGIN_NODE" token starts a new node, and the "OF_DT_END_NODE" | ||
552 | ends that node definition. Child nodes are simply defined before | ||
553 | "OF_DT_END_NODE" (that is nodes within the node). A 'token' is a 32 | ||
554 | bit value. The tree has to be "finished" with a OF_DT_END token | ||
555 | |||
556 | Here's the basic structure of a single node: | ||
557 | |||
558 | * token OF_DT_BEGIN_NODE (that is 0x00000001) | ||
559 | * for version 1 to 3, this is the node full path as a zero | ||
560 | terminated string, starting with "/". For version 16 and later, | ||
561 | this is the node unit name only (or an empty string for the | ||
562 | root node) | ||
563 | * [align gap to next 4 bytes boundary] | ||
564 | * for each property: | ||
565 | * token OF_DT_PROP (that is 0x00000003) | ||
566 | * 32-bit value of property value size in bytes (or 0 if no | ||
567 | value) | ||
568 | * 32-bit value of offset in string block of property name | ||
569 | * property value data if any | ||
570 | * [align gap to next 4 bytes boundary] | ||
571 | * [child nodes if any] | ||
572 | * token OF_DT_END_NODE (that is 0x00000002) | ||
573 | |||
574 | So the node content can be summarized as a start token, a full path, | ||
575 | a list of properties, a list of child nodes, and an end token. Every | ||
576 | child node is a full node structure itself as defined above. | ||
577 | |||
578 | NOTE: The above definition requires that all property definitions for | ||
579 | a particular node MUST precede any subnode definitions for that node. | ||
580 | Although the structure would not be ambiguous if properties and | ||
581 | subnodes were intermingled, the kernel parser requires that the | ||
582 | properties come first (up until at least 2.6.22). Any tools | ||
583 | manipulating a flattened tree must take care to preserve this | ||
584 | constraint. | ||
585 | |||
586 | 4) Device tree "strings" block | ||
587 | |||
588 | In order to save space, property names, which are generally redundant, | ||
589 | are stored separately in the "strings" block. This block is simply the | ||
590 | whole bunch of zero terminated strings for all property names | ||
591 | concatenated together. The device-tree property definitions in the | ||
592 | structure block will contain offset values from the beginning of the | ||
593 | strings block. | ||
594 | |||
595 | |||
596 | III - Required content of the device tree | ||
597 | ========================================= | ||
598 | |||
599 | WARNING: All "linux,*" properties defined in this document apply only | ||
600 | to a flattened device-tree. If your platform uses a real | ||
601 | implementation of Open Firmware or an implementation compatible with | ||
602 | the Open Firmware client interface, those properties will be created | ||
603 | by the trampoline code in the kernel's prom_init() file. For example, | ||
604 | that's where you'll have to add code to detect your board model and | ||
605 | set the platform number. However, when using the flattened device-tree | ||
606 | entry point, there is no prom_init() pass, and thus you have to | ||
607 | provide those properties yourself. | ||
608 | |||
609 | |||
610 | 1) Note about cells and address representation | ||
611 | ---------------------------------------------- | ||
612 | |||
613 | The general rule is documented in the various Open Firmware | ||
614 | documentations. If you choose to describe a bus with the device-tree | ||
615 | and there exist an OF bus binding, then you should follow the | ||
616 | specification. However, the kernel does not require every single | ||
617 | device or bus to be described by the device tree. | ||
618 | |||
619 | In general, the format of an address for a device is defined by the | ||
620 | parent bus type, based on the #address-cells and #size-cells | ||
621 | properties. Note that the parent's parent definitions of #address-cells | ||
622 | and #size-cells are not inherited so every node with children must specify | ||
623 | them. The kernel requires the root node to have those properties defining | ||
624 | addresses format for devices directly mapped on the processor bus. | ||
625 | |||
626 | Those 2 properties define 'cells' for representing an address and a | ||
627 | size. A "cell" is a 32-bit number. For example, if both contain 2 | ||
628 | like the example tree given above, then an address and a size are both | ||
629 | composed of 2 cells, and each is a 64-bit number (cells are | ||
630 | concatenated and expected to be in big endian format). Another example | ||
631 | is the way Apple firmware defines them, with 2 cells for an address | ||
632 | and one cell for a size. Most 32-bit implementations should define | ||
633 | #address-cells and #size-cells to 1, which represents a 32-bit value. | ||
634 | Some 32-bit processors allow for physical addresses greater than 32 | ||
635 | bits; these processors should define #address-cells as 2. | ||
636 | |||
637 | "reg" properties are always a tuple of the type "address size" where | ||
638 | the number of cells of address and size is specified by the bus | ||
639 | #address-cells and #size-cells. When a bus supports various address | ||
640 | spaces and other flags relative to a given address allocation (like | ||
641 | prefetchable, etc...) those flags are usually added to the top level | ||
642 | bits of the physical address. For example, a PCI physical address is | ||
643 | made of 3 cells, the bottom two containing the actual address itself | ||
644 | while the top cell contains address space indication, flags, and pci | ||
645 | bus & device numbers. | ||
646 | |||
647 | For buses that support dynamic allocation, it's the accepted practice | ||
648 | to then not provide the address in "reg" (keep it 0) though while | ||
649 | providing a flag indicating the address is dynamically allocated, and | ||
650 | then, to provide a separate "assigned-addresses" property that | ||
651 | contains the fully allocated addresses. See the PCI OF bindings for | ||
652 | details. | ||
653 | |||
654 | In general, a simple bus with no address space bits and no dynamic | ||
655 | allocation is preferred if it reflects your hardware, as the existing | ||
656 | kernel address parsing functions will work out of the box. If you | ||
657 | define a bus type with a more complex address format, including things | ||
658 | like address space bits, you'll have to add a bus translator to the | ||
659 | prom_parse.c file of the recent kernels for your bus type. | ||
660 | |||
661 | The "reg" property only defines addresses and sizes (if #size-cells is | ||
662 | non-0) within a given bus. In order to translate addresses upward | ||
663 | (that is into parent bus addresses, and possibly into CPU physical | ||
664 | addresses), all buses must contain a "ranges" property. If the | ||
665 | "ranges" property is missing at a given level, it's assumed that | ||
666 | translation isn't possible, i.e., the registers are not visible on the | ||
667 | parent bus. The format of the "ranges" property for a bus is a list | ||
668 | of: | ||
669 | |||
670 | bus address, parent bus address, size | ||
671 | |||
672 | "bus address" is in the format of the bus this bus node is defining, | ||
673 | that is, for a PCI bridge, it would be a PCI address. Thus, (bus | ||
674 | address, size) defines a range of addresses for child devices. "parent | ||
675 | bus address" is in the format of the parent bus of this bus. For | ||
676 | example, for a PCI host controller, that would be a CPU address. For a | ||
677 | PCI<->ISA bridge, that would be a PCI address. It defines the base | ||
678 | address in the parent bus where the beginning of that range is mapped. | ||
679 | |||
680 | For new 64-bit board support, I recommend either the 2/2 format or | ||
681 | Apple's 2/1 format which is slightly more compact since sizes usually | ||
682 | fit in a single 32-bit word. New 32-bit board support should use a | ||
683 | 1/1 format, unless the processor supports physical addresses greater | ||
684 | than 32-bits, in which case a 2/1 format is recommended. | ||
685 | |||
686 | Alternatively, the "ranges" property may be empty, indicating that the | ||
687 | registers are visible on the parent bus using an identity mapping | ||
688 | translation. In other words, the parent bus address space is the same | ||
689 | as the child bus address space. | ||
690 | |||
691 | 2) Note about "compatible" properties | ||
692 | ------------------------------------- | ||
693 | |||
694 | These properties are optional, but recommended in devices and the root | ||
695 | node. The format of a "compatible" property is a list of concatenated | ||
696 | zero terminated strings. They allow a device to express its | ||
697 | compatibility with a family of similar devices, in some cases, | ||
698 | allowing a single driver to match against several devices regardless | ||
699 | of their actual names. | ||
700 | |||
701 | 3) Note about "name" properties | ||
702 | ------------------------------- | ||
703 | |||
704 | While earlier users of Open Firmware like OldWorld macintoshes tended | ||
705 | to use the actual device name for the "name" property, it's nowadays | ||
706 | considered a good practice to use a name that is closer to the device | ||
707 | class (often equal to device_type). For example, nowadays, Ethernet | ||
708 | controllers are named "ethernet", an additional "model" property | ||
709 | defining precisely the chip type/model, and "compatible" property | ||
710 | defining the family in case a single driver can driver more than one | ||
711 | of these chips. However, the kernel doesn't generally put any | ||
712 | restriction on the "name" property; it is simply considered good | ||
713 | practice to follow the standard and its evolutions as closely as | ||
714 | possible. | ||
715 | |||
716 | Note also that the new format version 16 makes the "name" property | ||
717 | optional. If it's absent for a node, then the node's unit name is then | ||
718 | used to reconstruct the name. That is, the part of the unit name | ||
719 | before the "@" sign is used (or the entire unit name if no "@" sign | ||
720 | is present). | ||
721 | |||
722 | 4) Note about node and property names and character set | ||
723 | ------------------------------------------------------- | ||
724 | |||
725 | While Open Firmware provides more flexible usage of 8859-1, this | ||
726 | specification enforces more strict rules. Nodes and properties should | ||
727 | be comprised only of ASCII characters 'a' to 'z', '0' to | ||
728 | '9', ',', '.', '_', '+', '#', '?', and '-'. Node names additionally | ||
729 | allow uppercase characters 'A' to 'Z' (property names should be | ||
730 | lowercase. The fact that vendors like Apple don't respect this rule is | ||
731 | irrelevant here). Additionally, node and property names should always | ||
732 | begin with a character in the range 'a' to 'z' (or 'A' to 'Z' for node | ||
733 | names). | ||
734 | |||
735 | The maximum number of characters for both nodes and property names | ||
736 | is 31. In the case of node names, this is only the leftmost part of | ||
737 | a unit name (the pure "name" property), it doesn't include the unit | ||
738 | address which can extend beyond that limit. | ||
739 | |||
740 | |||
741 | 5) Required nodes and properties | ||
742 | -------------------------------- | ||
743 | These are all that are currently required. However, it is strongly | ||
744 | recommended that you expose PCI host bridges as documented in the | ||
745 | PCI binding to Open Firmware, and your interrupt tree as documented | ||
746 | in OF interrupt tree specification. | ||
747 | |||
748 | a) The root node | ||
749 | |||
750 | The root node requires some properties to be present: | ||
751 | |||
752 | - model : this is your board name/model | ||
753 | - #address-cells : address representation for "root" devices | ||
754 | - #size-cells: the size representation for "root" devices | ||
755 | - compatible : the board "family" generally finds its way here, | ||
756 | for example, if you have 2 board models with a similar layout, | ||
757 | that typically get driven by the same platform code in the | ||
758 | kernel, you would specify the exact board model in the | ||
759 | compatible property followed by an entry that represents the SoC | ||
760 | model. | ||
761 | |||
762 | The root node is also generally where you add additional properties | ||
763 | specific to your board like the serial number if any, that sort of | ||
764 | thing. It is recommended that if you add any "custom" property whose | ||
765 | name may clash with standard defined ones, you prefix them with your | ||
766 | vendor name and a comma. | ||
767 | |||
768 | b) The /cpus node | ||
769 | |||
770 | This node is the parent of all individual CPU nodes. It doesn't | ||
771 | have any specific requirements, though it's generally good practice | ||
772 | to have at least: | ||
773 | |||
774 | #address-cells = <00000001> | ||
775 | #size-cells = <00000000> | ||
776 | |||
777 | This defines that the "address" for a CPU is a single cell, and has | ||
778 | no meaningful size. This is not necessary but the kernel will assume | ||
779 | that format when reading the "reg" properties of a CPU node, see | ||
780 | below | ||
781 | |||
782 | c) The /cpus/* nodes | ||
783 | |||
784 | So under /cpus, you are supposed to create a node for every CPU on | ||
785 | the machine. There is no specific restriction on the name of the | ||
786 | CPU, though it's common to call it <architecture>,<core>. For | ||
787 | example, Apple uses PowerPC,G5 while IBM uses PowerPC,970FX. | ||
788 | However, the Generic Names convention suggests that it would be | ||
789 | better to simply use 'cpu' for each cpu node and use the compatible | ||
790 | property to identify the specific cpu core. | ||
791 | |||
792 | Required properties: | ||
793 | |||
794 | - device_type : has to be "cpu" | ||
795 | - reg : This is the physical CPU number, it's a single 32-bit cell | ||
796 | and is also used as-is as the unit number for constructing the | ||
797 | unit name in the full path. For example, with 2 CPUs, you would | ||
798 | have the full path: | ||
799 | /cpus/PowerPC,970FX@0 | ||
800 | /cpus/PowerPC,970FX@1 | ||
801 | (unit addresses do not require leading zeroes) | ||
802 | - d-cache-block-size : one cell, L1 data cache block size in bytes (*) | ||
803 | - i-cache-block-size : one cell, L1 instruction cache block size in | ||
804 | bytes | ||
805 | - d-cache-size : one cell, size of L1 data cache in bytes | ||
806 | - i-cache-size : one cell, size of L1 instruction cache in bytes | ||
807 | |||
808 | (*) The cache "block" size is the size on which the cache management | ||
809 | instructions operate. Historically, this document used the cache | ||
810 | "line" size here which is incorrect. The kernel will prefer the cache | ||
811 | block size and will fallback to cache line size for backward | ||
812 | compatibility. | ||
813 | |||
814 | Recommended properties: | ||
815 | |||
816 | - timebase-frequency : a cell indicating the frequency of the | ||
817 | timebase in Hz. This is not directly used by the generic code, | ||
818 | but you are welcome to copy/paste the pSeries code for setting | ||
819 | the kernel timebase/decrementer calibration based on this | ||
820 | value. | ||
821 | - clock-frequency : a cell indicating the CPU core clock frequency | ||
822 | in Hz. A new property will be defined for 64-bit values, but if | ||
823 | your frequency is < 4Ghz, one cell is enough. Here as well as | ||
824 | for the above, the common code doesn't use that property, but | ||
825 | you are welcome to re-use the pSeries or Maple one. A future | ||
826 | kernel version might provide a common function for this. | ||
827 | - d-cache-line-size : one cell, L1 data cache line size in bytes | ||
828 | if different from the block size | ||
829 | - i-cache-line-size : one cell, L1 instruction cache line size in | ||
830 | bytes if different from the block size | ||
831 | |||
832 | You are welcome to add any property you find relevant to your board, | ||
833 | like some information about the mechanism used to soft-reset the | ||
834 | CPUs. For example, Apple puts the GPIO number for CPU soft reset | ||
835 | lines in there as a "soft-reset" property since they start secondary | ||
836 | CPUs by soft-resetting them. | ||
837 | |||
838 | |||
839 | d) the /memory node(s) | ||
840 | |||
841 | To define the physical memory layout of your board, you should | ||
842 | create one or more memory node(s). You can either create a single | ||
843 | node with all memory ranges in its reg property, or you can create | ||
844 | several nodes, as you wish. The unit address (@ part) used for the | ||
845 | full path is the address of the first range of memory defined by a | ||
846 | given node. If you use a single memory node, this will typically be | ||
847 | @0. | ||
848 | |||
849 | Required properties: | ||
850 | |||
851 | - device_type : has to be "memory" | ||
852 | - reg : This property contains all the physical memory ranges of | ||
853 | your board. It's a list of addresses/sizes concatenated | ||
854 | together, with the number of cells of each defined by the | ||
855 | #address-cells and #size-cells of the root node. For example, | ||
856 | with both of these properties being 2 like in the example given | ||
857 | earlier, a 970 based machine with 6Gb of RAM could typically | ||
858 | have a "reg" property here that looks like: | ||
859 | |||
860 | 00000000 00000000 00000000 80000000 | ||
861 | 00000001 00000000 00000001 00000000 | ||
862 | |||
863 | That is a range starting at 0 of 0x80000000 bytes and a range | ||
864 | starting at 0x100000000 and of 0x100000000 bytes. You can see | ||
865 | that there is no memory covering the IO hole between 2Gb and | ||
866 | 4Gb. Some vendors prefer splitting those ranges into smaller | ||
867 | segments, but the kernel doesn't care. | ||
868 | |||
869 | e) The /chosen node | ||
870 | |||
871 | This node is a bit "special". Normally, that's where Open Firmware | ||
872 | puts some variable environment information, like the arguments, or | ||
873 | the default input/output devices. | ||
874 | |||
875 | This specification makes a few of these mandatory, but also defines | ||
876 | some linux-specific properties that would be normally constructed by | ||
877 | the prom_init() trampoline when booting with an OF client interface, | ||
878 | but that you have to provide yourself when using the flattened format. | ||
879 | |||
880 | Recommended properties: | ||
881 | |||
882 | - bootargs : This zero-terminated string is passed as the kernel | ||
883 | command line | ||
884 | - linux,stdout-path : This is the full path to your standard | ||
885 | console device if any. Typically, if you have serial devices on | ||
886 | your board, you may want to put the full path to the one set as | ||
887 | the default console in the firmware here, for the kernel to pick | ||
888 | it up as its own default console. | ||
889 | |||
890 | Note that u-boot creates and fills in the chosen node for platforms | ||
891 | that use it. | ||
892 | |||
893 | (Note: a practice that is now obsolete was to include a property | ||
894 | under /chosen called interrupt-controller which had a phandle value | ||
895 | that pointed to the main interrupt controller) | ||
896 | |||
897 | f) the /soc<SOCname> node | ||
898 | |||
899 | This node is used to represent a system-on-a-chip (SoC) and must be | ||
900 | present if the processor is a SoC. The top-level soc node contains | ||
901 | information that is global to all devices on the SoC. The node name | ||
902 | should contain a unit address for the SoC, which is the base address | ||
903 | of the memory-mapped register set for the SoC. The name of an SoC | ||
904 | node should start with "soc", and the remainder of the name should | ||
905 | represent the part number for the soc. For example, the MPC8540's | ||
906 | soc node would be called "soc8540". | ||
907 | |||
908 | Required properties: | ||
909 | |||
910 | - ranges : Should be defined as specified in 1) to describe the | ||
911 | translation of SoC addresses for memory mapped SoC registers. | ||
912 | - bus-frequency: Contains the bus frequency for the SoC node. | ||
913 | Typically, the value of this field is filled in by the boot | ||
914 | loader. | ||
915 | - compatible : Exact model of the SoC | ||
916 | |||
917 | |||
918 | Recommended properties: | ||
919 | |||
920 | - reg : This property defines the address and size of the | ||
921 | memory-mapped registers that are used for the SOC node itself. | ||
922 | It does not include the child device registers - these will be | ||
923 | defined inside each child node. The address specified in the | ||
924 | "reg" property should match the unit address of the SOC node. | ||
925 | - #address-cells : Address representation for "soc" devices. The | ||
926 | format of this field may vary depending on whether or not the | ||
927 | device registers are memory mapped. For memory mapped | ||
928 | registers, this field represents the number of cells needed to | ||
929 | represent the address of the registers. For SOCs that do not | ||
930 | use MMIO, a special address format should be defined that | ||
931 | contains enough cells to represent the required information. | ||
932 | See 1) above for more details on defining #address-cells. | ||
933 | - #size-cells : Size representation for "soc" devices | ||
934 | - #interrupt-cells : Defines the width of cells used to represent | ||
935 | interrupts. Typically this value is <2>, which includes a | ||
936 | 32-bit number that represents the interrupt number, and a | ||
937 | 32-bit number that represents the interrupt sense and level. | ||
938 | This field is only needed if the SOC contains an interrupt | ||
939 | controller. | ||
940 | |||
941 | The SOC node may contain child nodes for each SOC device that the | ||
942 | platform uses. Nodes should not be created for devices which exist | ||
943 | on the SOC but are not used by a particular platform. See chapter VI | ||
944 | for more information on how to specify devices that are part of a SOC. | ||
945 | |||
946 | Example SOC node for the MPC8540: | ||
947 | |||
948 | soc8540@e0000000 { | ||
949 | #address-cells = <1>; | ||
950 | #size-cells = <1>; | ||
951 | #interrupt-cells = <2>; | ||
952 | device_type = "soc"; | ||
953 | ranges = <00000000 e0000000 00100000> | ||
954 | reg = <e0000000 00003000>; | ||
955 | bus-frequency = <0>; | ||
956 | } | ||
957 | |||
958 | |||
959 | |||
960 | IV - "dtc", the device tree compiler | ||
961 | ==================================== | ||
962 | |||
963 | |||
964 | dtc source code can be found at | ||
965 | <http://git.jdl.com/gitweb/?p=dtc.git> | ||
966 | |||
967 | WARNING: This version is still in early development stage; the | ||
968 | resulting device-tree "blobs" have not yet been validated with the | ||
969 | kernel. The current generated block lacks a useful reserve map (it will | ||
970 | be fixed to generate an empty one, it's up to the bootloader to fill | ||
971 | it up) among others. The error handling needs work, bugs are lurking, | ||
972 | etc... | ||
973 | |||
974 | dtc basically takes a device-tree in a given format and outputs a | ||
975 | device-tree in another format. The currently supported formats are: | ||
976 | |||
977 | Input formats: | ||
978 | ------------- | ||
979 | |||
980 | - "dtb": "blob" format, that is a flattened device-tree block | ||
981 | with | ||
982 | header all in a binary blob. | ||
983 | - "dts": "source" format. This is a text file containing a | ||
984 | "source" for a device-tree. The format is defined later in this | ||
985 | chapter. | ||
986 | - "fs" format. This is a representation equivalent to the | ||
987 | output of /proc/device-tree, that is nodes are directories and | ||
988 | properties are files | ||
989 | |||
990 | Output formats: | ||
991 | --------------- | ||
992 | |||
993 | - "dtb": "blob" format | ||
994 | - "dts": "source" format | ||
995 | - "asm": assembly language file. This is a file that can be | ||
996 | sourced by gas to generate a device-tree "blob". That file can | ||
997 | then simply be added to your Makefile. Additionally, the | ||
998 | assembly file exports some symbols that can be used. | ||
999 | |||
1000 | |||
1001 | The syntax of the dtc tool is | ||
1002 | |||
1003 | dtc [-I <input-format>] [-O <output-format>] | ||
1004 | [-o output-filename] [-V output_version] input_filename | ||
1005 | |||
1006 | |||
1007 | The "output_version" defines what version of the "blob" format will be | ||
1008 | generated. Supported versions are 1,2,3 and 16. The default is | ||
1009 | currently version 3 but that may change in the future to version 16. | ||
1010 | |||
1011 | Additionally, dtc performs various sanity checks on the tree, like the | ||
1012 | uniqueness of linux, phandle properties, validity of strings, etc... | ||
1013 | |||
1014 | The format of the .dts "source" file is "C" like, supports C and C++ | ||
1015 | style comments. | ||
1016 | |||
1017 | / { | ||
1018 | } | ||
1019 | |||
1020 | The above is the "device-tree" definition. It's the only statement | ||
1021 | supported currently at the toplevel. | ||
1022 | |||
1023 | / { | ||
1024 | property1 = "string_value"; /* define a property containing a 0 | ||
1025 | * terminated string | ||
1026 | */ | ||
1027 | |||
1028 | property2 = <1234abcd>; /* define a property containing a | ||
1029 | * numerical 32-bit value (hexadecimal) | ||
1030 | */ | ||
1031 | |||
1032 | property3 = <12345678 12345678 deadbeef>; | ||
1033 | /* define a property containing 3 | ||
1034 | * numerical 32-bit values (cells) in | ||
1035 | * hexadecimal | ||
1036 | */ | ||
1037 | property4 = [0a 0b 0c 0d de ea ad be ef]; | ||
1038 | /* define a property whose content is | ||
1039 | * an arbitrary array of bytes | ||
1040 | */ | ||
1041 | |||
1042 | childnode@address { /* define a child node named "childnode" | ||
1043 | * whose unit name is "childnode at | ||
1044 | * address" | ||
1045 | */ | ||
1046 | |||
1047 | childprop = "hello\n"; /* define a property "childprop" of | ||
1048 | * childnode (in this case, a string) | ||
1049 | */ | ||
1050 | }; | ||
1051 | }; | ||
1052 | |||
1053 | Nodes can contain other nodes etc... thus defining the hierarchical | ||
1054 | structure of the tree. | ||
1055 | |||
1056 | Strings support common escape sequences from C: "\n", "\t", "\r", | ||
1057 | "\(octal value)", "\x(hex value)". | ||
1058 | |||
1059 | It is also suggested that you pipe your source file through cpp (gcc | ||
1060 | preprocessor) so you can use #include's, #define for constants, etc... | ||
1061 | |||
1062 | Finally, various options are planned but not yet implemented, like | ||
1063 | automatic generation of phandles, labels (exported to the asm file so | ||
1064 | you can point to a property content and change it easily from whatever | ||
1065 | you link the device-tree with), label or path instead of numeric value | ||
1066 | in some cells to "point" to a node (replaced by a phandle at compile | ||
1067 | time), export of reserve map address to the asm file, ability to | ||
1068 | specify reserve map content at compile time, etc... | ||
1069 | |||
1070 | We may provide a .h include file with common definitions of that | ||
1071 | proves useful for some properties (like building PCI properties or | ||
1072 | interrupt maps) though it may be better to add a notion of struct | ||
1073 | definitions to the compiler... | ||
1074 | |||
1075 | |||
1076 | V - Recommendations for a bootloader | ||
1077 | ==================================== | ||
1078 | |||
1079 | |||
1080 | Here are some various ideas/recommendations that have been proposed | ||
1081 | while all this has been defined and implemented. | ||
1082 | |||
1083 | - The bootloader may want to be able to use the device-tree itself | ||
1084 | and may want to manipulate it (to add/edit some properties, | ||
1085 | like physical memory size or kernel arguments). At this point, 2 | ||
1086 | choices can be made. Either the bootloader works directly on the | ||
1087 | flattened format, or the bootloader has its own internal tree | ||
1088 | representation with pointers (similar to the kernel one) and | ||
1089 | re-flattens the tree when booting the kernel. The former is a bit | ||
1090 | more difficult to edit/modify, the later requires probably a bit | ||
1091 | more code to handle the tree structure. Note that the structure | ||
1092 | format has been designed so it's relatively easy to "insert" | ||
1093 | properties or nodes or delete them by just memmoving things | ||
1094 | around. It contains no internal offsets or pointers for this | ||
1095 | purpose. | ||
1096 | |||
1097 | - An example of code for iterating nodes & retrieving properties | ||
1098 | directly from the flattened tree format can be found in the kernel | ||
1099 | file drivers/of/fdt.c. Look at the of_scan_flat_dt() function, | ||
1100 | its usage in early_init_devtree(), and the corresponding various | ||
1101 | early_init_dt_scan_*() callbacks. That code can be re-used in a | ||
1102 | GPL bootloader, and as the author of that code, I would be happy | ||
1103 | to discuss possible free licensing to any vendor who wishes to | ||
1104 | integrate all or part of this code into a non-GPL bootloader. | ||
1105 | (reference needed; who is 'I' here? ---gcl Jan 31, 2011) | ||
1106 | |||
1107 | |||
1108 | |||
1109 | VI - System-on-a-chip devices and nodes | ||
1110 | ======================================= | ||
1111 | |||
1112 | Many companies are now starting to develop system-on-a-chip | ||
1113 | processors, where the processor core (CPU) and many peripheral devices | ||
1114 | exist on a single piece of silicon. For these SOCs, an SOC node | ||
1115 | should be used that defines child nodes for the devices that make | ||
1116 | up the SOC. While platforms are not required to use this model in | ||
1117 | order to boot the kernel, it is highly encouraged that all SOC | ||
1118 | implementations define as complete a flat-device-tree as possible to | ||
1119 | describe the devices on the SOC. This will allow for the | ||
1120 | genericization of much of the kernel code. | ||
1121 | |||
1122 | |||
1123 | 1) Defining child nodes of an SOC | ||
1124 | --------------------------------- | ||
1125 | |||
1126 | Each device that is part of an SOC may have its own node entry inside | ||
1127 | the SOC node. For each device that is included in the SOC, the unit | ||
1128 | address property represents the address offset for this device's | ||
1129 | memory-mapped registers in the parent's address space. The parent's | ||
1130 | address space is defined by the "ranges" property in the top-level soc | ||
1131 | node. The "reg" property for each node that exists directly under the | ||
1132 | SOC node should contain the address mapping from the child address space | ||
1133 | to the parent SOC address space and the size of the device's | ||
1134 | memory-mapped register file. | ||
1135 | |||
1136 | For many devices that may exist inside an SOC, there are predefined | ||
1137 | specifications for the format of the device tree node. All SOC child | ||
1138 | nodes should follow these specifications, except where noted in this | ||
1139 | document. | ||
1140 | |||
1141 | See appendix A for an example partial SOC node definition for the | ||
1142 | MPC8540. | ||
1143 | |||
1144 | |||
1145 | 2) Representing devices without a current OF specification | ||
1146 | ---------------------------------------------------------- | ||
1147 | |||
1148 | Currently, there are many devices on SoCs that do not have a standard | ||
1149 | representation defined as part of the Open Firmware specifications, | ||
1150 | mainly because the boards that contain these SoCs are not currently | ||
1151 | booted using Open Firmware. Binding documentation for new devices | ||
1152 | should be added to the Documentation/devicetree/bindings directory. | ||
1153 | That directory will expand as device tree support is added to more and | ||
1154 | more SoCs. | ||
1155 | |||
1156 | |||
1157 | VII - Specifying interrupt information for devices | ||
1158 | =================================================== | ||
1159 | |||
1160 | The device tree represents the buses and devices of a hardware | ||
1161 | system in a form similar to the physical bus topology of the | ||
1162 | hardware. | ||
1163 | |||
1164 | In addition, a logical 'interrupt tree' exists which represents the | ||
1165 | hierarchy and routing of interrupts in the hardware. | ||
1166 | |||
1167 | The interrupt tree model is fully described in the | ||
1168 | document "Open Firmware Recommended Practice: Interrupt | ||
1169 | Mapping Version 0.9". The document is available at: | ||
1170 | <http://playground.sun.com/1275/practice>. | ||
1171 | |||
1172 | 1) interrupts property | ||
1173 | ---------------------- | ||
1174 | |||
1175 | Devices that generate interrupts to a single interrupt controller | ||
1176 | should use the conventional OF representation described in the | ||
1177 | OF interrupt mapping documentation. | ||
1178 | |||
1179 | Each device which generates interrupts must have an 'interrupt' | ||
1180 | property. The interrupt property value is an arbitrary number of | ||
1181 | of 'interrupt specifier' values which describe the interrupt or | ||
1182 | interrupts for the device. | ||
1183 | |||
1184 | The encoding of an interrupt specifier is determined by the | ||
1185 | interrupt domain in which the device is located in the | ||
1186 | interrupt tree. The root of an interrupt domain specifies in | ||
1187 | its #interrupt-cells property the number of 32-bit cells | ||
1188 | required to encode an interrupt specifier. See the OF interrupt | ||
1189 | mapping documentation for a detailed description of domains. | ||
1190 | |||
1191 | For example, the binding for the OpenPIC interrupt controller | ||
1192 | specifies an #interrupt-cells value of 2 to encode the interrupt | ||
1193 | number and level/sense information. All interrupt children in an | ||
1194 | OpenPIC interrupt domain use 2 cells per interrupt in their interrupts | ||
1195 | property. | ||
1196 | |||
1197 | The PCI bus binding specifies a #interrupt-cell value of 1 to encode | ||
1198 | which interrupt pin (INTA,INTB,INTC,INTD) is used. | ||
1199 | |||
1200 | 2) interrupt-parent property | ||
1201 | ---------------------------- | ||
1202 | |||
1203 | The interrupt-parent property is specified to define an explicit | ||
1204 | link between a device node and its interrupt parent in | ||
1205 | the interrupt tree. The value of interrupt-parent is the | ||
1206 | phandle of the parent node. | ||
1207 | |||
1208 | If the interrupt-parent property is not defined for a node, its | ||
1209 | interrupt parent is assumed to be an ancestor in the node's | ||
1210 | _device tree_ hierarchy. | ||
1211 | |||
1212 | 3) OpenPIC Interrupt Controllers | ||
1213 | -------------------------------- | ||
1214 | |||
1215 | OpenPIC interrupt controllers require 2 cells to encode | ||
1216 | interrupt information. The first cell defines the interrupt | ||
1217 | number. The second cell defines the sense and level | ||
1218 | information. | ||
1219 | |||
1220 | Sense and level information should be encoded as follows: | ||
1221 | |||
1222 | 0 = low to high edge sensitive type enabled | ||
1223 | 1 = active low level sensitive type enabled | ||
1224 | 2 = active high level sensitive type enabled | ||
1225 | 3 = high to low edge sensitive type enabled | ||
1226 | |||
1227 | 4) ISA Interrupt Controllers | ||
1228 | ---------------------------- | ||
1229 | |||
1230 | ISA PIC interrupt controllers require 2 cells to encode | ||
1231 | interrupt information. The first cell defines the interrupt | ||
1232 | number. The second cell defines the sense and level | ||
1233 | information. | ||
1234 | |||
1235 | ISA PIC interrupt controllers should adhere to the ISA PIC | ||
1236 | encodings listed below: | ||
1237 | |||
1238 | 0 = active low level sensitive type enabled | ||
1239 | 1 = active high level sensitive type enabled | ||
1240 | 2 = high to low edge sensitive type enabled | ||
1241 | 3 = low to high edge sensitive type enabled | ||
1242 | |||
1243 | VIII - Specifying Device Power Management Information (sleep property) | ||
1244 | =================================================================== | ||
1245 | |||
1246 | Devices on SOCs often have mechanisms for placing devices into low-power | ||
1247 | states that are decoupled from the devices' own register blocks. Sometimes, | ||
1248 | this information is more complicated than a cell-index property can | ||
1249 | reasonably describe. Thus, each device controlled in such a manner | ||
1250 | may contain a "sleep" property which describes these connections. | ||
1251 | |||
1252 | The sleep property consists of one or more sleep resources, each of | ||
1253 | which consists of a phandle to a sleep controller, followed by a | ||
1254 | controller-specific sleep specifier of zero or more cells. | ||
1255 | |||
1256 | The semantics of what type of low power modes are possible are defined | ||
1257 | by the sleep controller. Some examples of the types of low power modes | ||
1258 | that may be supported are: | ||
1259 | |||
1260 | - Dynamic: The device may be disabled or enabled at any time. | ||
1261 | - System Suspend: The device may request to be disabled or remain | ||
1262 | awake during system suspend, but will not be disabled until then. | ||
1263 | - Permanent: The device is disabled permanently (until the next hard | ||
1264 | reset). | ||
1265 | |||
1266 | Some devices may share a clock domain with each other, such that they should | ||
1267 | only be suspended when none of the devices are in use. Where reasonable, | ||
1268 | such nodes should be placed on a virtual bus, where the bus has the sleep | ||
1269 | property. If the clock domain is shared among devices that cannot be | ||
1270 | reasonably grouped in this manner, then create a virtual sleep controller | ||
1271 | (similar to an interrupt nexus, except that defining a standardized | ||
1272 | sleep-map should wait until its necessity is demonstrated). | ||
1273 | |||
1274 | Appendix A - Sample SOC node for MPC8540 | ||
1275 | ======================================== | ||
1276 | |||
1277 | soc@e0000000 { | ||
1278 | #address-cells = <1>; | ||
1279 | #size-cells = <1>; | ||
1280 | compatible = "fsl,mpc8540-ccsr", "simple-bus"; | ||
1281 | device_type = "soc"; | ||
1282 | ranges = <0x00000000 0xe0000000 0x00100000> | ||
1283 | bus-frequency = <0>; | ||
1284 | interrupt-parent = <&pic>; | ||
1285 | |||
1286 | ethernet@24000 { | ||
1287 | #address-cells = <1>; | ||
1288 | #size-cells = <1>; | ||
1289 | device_type = "network"; | ||
1290 | model = "TSEC"; | ||
1291 | compatible = "gianfar", "simple-bus"; | ||
1292 | reg = <0x24000 0x1000>; | ||
1293 | local-mac-address = [ 00 E0 0C 00 73 00 ]; | ||
1294 | interrupts = <29 2 30 2 34 2>; | ||
1295 | phy-handle = <&phy0>; | ||
1296 | sleep = <&pmc 00000080>; | ||
1297 | ranges; | ||
1298 | |||
1299 | mdio@24520 { | ||
1300 | reg = <0x24520 0x20>; | ||
1301 | compatible = "fsl,gianfar-mdio"; | ||
1302 | |||
1303 | phy0: ethernet-phy@0 { | ||
1304 | interrupts = <5 1>; | ||
1305 | reg = <0>; | ||
1306 | device_type = "ethernet-phy"; | ||
1307 | }; | ||
1308 | |||
1309 | phy1: ethernet-phy@1 { | ||
1310 | interrupts = <5 1>; | ||
1311 | reg = <1>; | ||
1312 | device_type = "ethernet-phy"; | ||
1313 | }; | ||
1314 | |||
1315 | phy3: ethernet-phy@3 { | ||
1316 | interrupts = <7 1>; | ||
1317 | reg = <3>; | ||
1318 | device_type = "ethernet-phy"; | ||
1319 | }; | ||
1320 | }; | ||
1321 | }; | ||
1322 | |||
1323 | ethernet@25000 { | ||
1324 | device_type = "network"; | ||
1325 | model = "TSEC"; | ||
1326 | compatible = "gianfar"; | ||
1327 | reg = <0x25000 0x1000>; | ||
1328 | local-mac-address = [ 00 E0 0C 00 73 01 ]; | ||
1329 | interrupts = <13 2 14 2 18 2>; | ||
1330 | phy-handle = <&phy1>; | ||
1331 | sleep = <&pmc 00000040>; | ||
1332 | }; | ||
1333 | |||
1334 | ethernet@26000 { | ||
1335 | device_type = "network"; | ||
1336 | model = "FEC"; | ||
1337 | compatible = "gianfar"; | ||
1338 | reg = <0x26000 0x1000>; | ||
1339 | local-mac-address = [ 00 E0 0C 00 73 02 ]; | ||
1340 | interrupts = <41 2>; | ||
1341 | phy-handle = <&phy3>; | ||
1342 | sleep = <&pmc 00000020>; | ||
1343 | }; | ||
1344 | |||
1345 | serial@4500 { | ||
1346 | #address-cells = <1>; | ||
1347 | #size-cells = <1>; | ||
1348 | compatible = "fsl,mpc8540-duart", "simple-bus"; | ||
1349 | sleep = <&pmc 00000002>; | ||
1350 | ranges; | ||
1351 | |||
1352 | serial@4500 { | ||
1353 | device_type = "serial"; | ||
1354 | compatible = "ns16550"; | ||
1355 | reg = <0x4500 0x100>; | ||
1356 | clock-frequency = <0>; | ||
1357 | interrupts = <42 2>; | ||
1358 | }; | ||
1359 | |||
1360 | serial@4600 { | ||
1361 | device_type = "serial"; | ||
1362 | compatible = "ns16550"; | ||
1363 | reg = <0x4600 0x100>; | ||
1364 | clock-frequency = <0>; | ||
1365 | interrupts = <42 2>; | ||
1366 | }; | ||
1367 | }; | ||
1368 | |||
1369 | pic: pic@40000 { | ||
1370 | interrupt-controller; | ||
1371 | #address-cells = <0>; | ||
1372 | #interrupt-cells = <2>; | ||
1373 | reg = <0x40000 0x40000>; | ||
1374 | compatible = "chrp,open-pic"; | ||
1375 | device_type = "open-pic"; | ||
1376 | }; | ||
1377 | |||
1378 | i2c@3000 { | ||
1379 | interrupts = <43 2>; | ||
1380 | reg = <0x3000 0x100>; | ||
1381 | compatible = "fsl-i2c"; | ||
1382 | dfsrr; | ||
1383 | sleep = <&pmc 00000004>; | ||
1384 | }; | ||
1385 | |||
1386 | pmc: power@e0070 { | ||
1387 | compatible = "fsl,mpc8540-pmc", "fsl,mpc8548-pmc"; | ||
1388 | reg = <0xe0070 0x20>; | ||
1389 | }; | ||
1390 | }; | ||