blob: 1c6660d2d7f5d5f5453af65ebe727f9e3f74ad61 [file] [log] [blame]
David Gibsonc125a182006-02-01 03:05:22 -08001 Booting the Linux/ppc kernel without Open Firmware
2 --------------------------------------------------
3
David Gibsonc125a182006-02-01 03:05:22 -08004(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
Vitaly Wool28f9ec32006-11-20 16:32:39 +03008(c) 2006 MontaVista Software, Inc.
9 Flash chip node definition
David Gibsonc125a182006-02-01 03:05:22 -080010
Stuart Yoder5e1e9ba2007-06-06 04:29:14 +100011Table of Contents
12=================
13
14 I - Introduction
15 1) Entry point for arch/powerpc
16 2) Board support
17
18 II - The DT block format
19 1) Header
20 2) Device tree generalities
21 3) Device tree "structure" block
22 4) Device tree "strings" block
23
24 III - Required content of the device tree
25 1) Note about cells and address representation
26 2) Note about "compatible" properties
27 3) Note about "name" properties
28 4) Note about node and property names and character set
29 5) Required nodes and properties
30 a) The root node
31 b) The /cpus node
32 c) The /cpus/* nodes
33 d) the /memory node(s)
34 e) The /chosen node
35 f) the /soc<SOCname> node
36
37 IV - "dtc", the device tree compiler
38
39 V - Recommendations for a bootloader
40
41 VI - System-on-a-chip devices and nodes
42 1) Defining child nodes of an SOC
43 2) Representing devices without a current OF specification
Trent Piephoec5d7652008-11-10 13:09:21 -080044 a) PHY nodes
45 b) Interrupt controllers
Stefan Roeseefcc2da2009-04-16 15:11:54 -060046 c) 4xx/Axon EMAC ethernet nodes
47 d) Xilinx IP cores
48 e) USB EHCI controllers
49 f) MDIO on GPIOs
50 g) SPI busses
Stuart Yoder5e1e9ba2007-06-06 04:29:14 +100051
Anton Vorontsovb9e0ba82010-08-11 20:56:03 +040052 VII - Specifying interrupt information for devices
Stuart Yoder5e1e9ba2007-06-06 04:29:14 +100053 1) interrupts property
54 2) interrupt-parent property
55 3) OpenPIC Interrupt Controllers
56 4) ISA Interrupt Controllers
57
Anton Vorontsovb9e0ba82010-08-11 20:56:03 +040058 VIII - Specifying device power management information (sleep property)
Scott Wood2dff4172008-07-11 17:31:15 -050059
Stuart Yoder5e1e9ba2007-06-06 04:29:14 +100060 Appendix A - Sample SOC node for MPC8540
61
62
63Revision Information
64====================
65
David Gibsonc125a182006-02-01 03:05:22 -080066 May 18, 2005: Rev 0.1 - Initial draft, no chapter III yet.
67
68 May 19, 2005: Rev 0.2 - Add chapter III and bits & pieces here or
69 clarifies the fact that a lot of things are
70 optional, the kernel only requires a very
71 small device tree, though it is encouraged
72 to provide an as complete one as possible.
73
74 May 24, 2005: Rev 0.3 - Precise that DT block has to be in RAM
75 - Misc fixes
76 - Define version 3 and new format version 16
77 for the DT block (version 16 needs kernel
78 patches, will be fwd separately).
79 String block now has a size, and full path
80 is replaced by unit name for more
81 compactness.
82 linux,phandle is made optional, only nodes
83 that are referenced by other nodes need it.
84 "name" property is now automatically
85 deduced from the unit name
86
87 June 1, 2005: Rev 0.4 - Correct confusion between OF_DT_END and
88 OF_DT_END_NODE in structure definition.
89 - Change version 16 format to always align
90 property data to 4 bytes. Since tokens are
91 already aligned, that means no specific
Matt LaPlante5d3f0832006-11-30 05:21:10 +010092 required alignment between property size
David Gibsonc125a182006-02-01 03:05:22 -080093 and property data. The old style variable
94 alignment would make it impossible to do
95 "simple" insertion of properties using
Domen Puncer5dd60162007-03-02 21:44:45 +110096 memmove (thanks Milton for
David Gibsonc125a182006-02-01 03:05:22 -080097 noticing). Updated kernel patch as well
Matt LaPlante5d3f0832006-11-30 05:21:10 +010098 - Correct a few more alignment constraints
David Gibsonc125a182006-02-01 03:05:22 -080099 - Add a chapter about the device-tree
100 compiler and the textural representation of
101 the tree that can be "compiled" by dtc.
102
David Gibsonc125a182006-02-01 03:05:22 -0800103 November 21, 2005: Rev 0.5
104 - Additions/generalizations for 32-bit
105 - Changed to reflect the new arch/powerpc
106 structure
107 - Added chapter VI
108
109
110 ToDo:
111 - Add some definitions of interrupt tree (simple/complex)
Domen Puncer5dd60162007-03-02 21:44:45 +1100112 - Add some definitions for PCI host bridges
David Gibsonc125a182006-02-01 03:05:22 -0800113 - Add some common address format examples
114 - Add definitions for standard properties and "compatible"
115 names for cells that are not already defined by the existing
116 OF spec.
117 - Compare FSL SOC use of PCI to standard and make sure no new
118 node definition required.
119 - Add more information about node definitions for SOC devices
120 that currently have no standard, like the FSL CPM.
121
122
123I - Introduction
124================
125
126During the recent development of the Linux/ppc64 kernel, and more
127specifically, the addition of new platform types outside of the old
128IBM pSeries/iSeries pair, it was decided to enforce some strict rules
129regarding the kernel entry and bootloader <-> kernel interfaces, in
130order to avoid the degeneration that had become the ppc32 kernel entry
131point and the way a new platform should be added to the kernel. The
132legacy iSeries platform breaks those rules as it predates this scheme,
133but no new board support will be accepted in the main tree that
134doesn't follows them properly. In addition, since the advent of the
135arch/powerpc merged architecture for ppc32 and ppc64, new 32-bit
136platforms and 32-bit platforms which move into arch/powerpc will be
137required to use these rules as well.
138
139The main requirement that will be defined in more detail below is
140the presence of a device-tree whose format is defined after Open
141Firmware specification. However, in order to make life easier
142to embedded board vendors, the kernel doesn't require the device-tree
143to represent every device in the system and only requires some nodes
144and properties to be present. This will be described in detail in
145section III, but, for example, the kernel does not require you to
146create a node for every PCI device in the system. It is a requirement
147to have a node for PCI host bridges in order to provide interrupt
148routing informations and memory/IO ranges, among others. It is also
149recommended to define nodes for on chip devices and other busses that
150don't specifically fit in an existing OF specification. This creates a
151great flexibility in the way the kernel can then probe those and match
152drivers to device, without having to hard code all sorts of tables. It
153also makes it more flexible for board vendors to do minor hardware
154upgrades without significantly impacting the kernel code or cluttering
155it with special cases.
156
157
1581) Entry point for arch/powerpc
159-------------------------------
160
161 There is one and one single entry point to the kernel, at the start
162 of the kernel image. That entry point supports two calling
163 conventions:
164
165 a) Boot from Open Firmware. If your firmware is compatible
166 with Open Firmware (IEEE 1275) or provides an OF compatible
167 client interface API (support for "interpret" callback of
168 forth words isn't required), you can enter the kernel with:
169
170 r5 : OF callback pointer as defined by IEEE 1275
Domen Puncer5dd60162007-03-02 21:44:45 +1100171 bindings to powerpc. Only the 32-bit client interface
David Gibsonc125a182006-02-01 03:05:22 -0800172 is currently supported
173
174 r3, r4 : address & length of an initrd if any or 0
175
176 The MMU is either on or off; the kernel will run the
177 trampoline located in arch/powerpc/kernel/prom_init.c to
178 extract the device-tree and other information from open
179 firmware and build a flattened device-tree as described
180 in b). prom_init() will then re-enter the kernel using
181 the second method. This trampoline code runs in the
182 context of the firmware, which is supposed to handle all
183 exceptions during that time.
184
185 b) Direct entry with a flattened device-tree block. This entry
186 point is called by a) after the OF trampoline and can also be
187 called directly by a bootloader that does not support the Open
188 Firmware client interface. It is also used by "kexec" to
189 implement "hot" booting of a new kernel from a previous
190 running one. This method is what I will describe in more
191 details in this document, as method a) is simply standard Open
192 Firmware, and thus should be implemented according to the
193 various standard documents defining it and its binding to the
194 PowerPC platform. The entry point definition then becomes:
195
196 r3 : physical pointer to the device-tree block
197 (defined in chapter II) in RAM
198
199 r4 : physical pointer to the kernel itself. This is
200 used by the assembly code to properly disable the MMU
201 in case you are entering the kernel with MMU enabled
202 and a non-1:1 mapping.
203
Matt LaPlante2fe0ae72006-10-03 22:50:39 +0200204 r5 : NULL (as to differentiate with method a)
David Gibsonc125a182006-02-01 03:05:22 -0800205
206 Note about SMP entry: Either your firmware puts your other
207 CPUs in some sleep loop or spin loop in ROM where you can get
208 them out via a soft reset or some other means, in which case
209 you don't need to care, or you'll have to enter the kernel
210 with all CPUs. The way to do that with method b) will be
211 described in a later revision of this document.
212
213
2142) Board support
215----------------
216
21764-bit kernels:
218
219 Board supports (platforms) are not exclusive config options. An
220 arbitrary set of board supports can be built in a single kernel
221 image. The kernel will "know" what set of functions to use for a
222 given platform based on the content of the device-tree. Thus, you
223 should:
224
225 a) add your platform support as a _boolean_ option in
226 arch/powerpc/Kconfig, following the example of PPC_PSERIES,
227 PPC_PMAC and PPC_MAPLE. The later is probably a good
228 example of a board support to start from.
229
230 b) create your main platform file as
231 "arch/powerpc/platforms/myplatform/myboard_setup.c" and add it
232 to the Makefile under the condition of your CONFIG_
233 option. This file will define a structure of type "ppc_md"
234 containing the various callbacks that the generic code will
235 use to get to your platform specific code
236
237 c) Add a reference to your "ppc_md" structure in the
238 "machines" table in arch/powerpc/kernel/setup_64.c if you are
239 a 64-bit platform.
240
241 d) request and get assigned a platform number (see PLATFORM_*
Stephen Rothwellb8b572e2008-08-01 15:20:30 +1000242 constants in arch/powerpc/include/asm/processor.h
David Gibsonc125a182006-02-01 03:05:22 -0800243
24432-bit embedded kernels:
245
246 Currently, board support is essentially an exclusive config option.
247 The kernel is configured for a single platform. Part of the reason
248 for this is to keep kernels on embedded systems small and efficient;
249 part of this is due to the fact the code is already that way. In the
250 future, a kernel may support multiple platforms, but only if the
Domen Puncer5dd60162007-03-02 21:44:45 +1100251 platforms feature the same core architecture. A single kernel build
David Gibsonc125a182006-02-01 03:05:22 -0800252 cannot support both configurations with Book E and configurations
253 with classic Powerpc architectures.
254
255 32-bit embedded platforms that are moved into arch/powerpc using a
256 flattened device tree should adopt the merged tree practice of
257 setting ppc_md up dynamically, even though the kernel is currently
258 built with support for only a single platform at a time. This allows
259 unification of the setup code, and will make it easier to go to a
260 multiple-platform-support model in the future.
261
262NOTE: I believe the above will be true once Ben's done with the merge
263of the boot sequences.... someone speak up if this is wrong!
264
265 To add a 32-bit embedded platform support, follow the instructions
266 for 64-bit platforms above, with the exception that the Kconfig
267 option should be set up such that the kernel builds exclusively for
268 the platform selected. The processor type for the platform should
269 enable another config option to select the specific board
270 supported.
271
Domen Puncer5dd60162007-03-02 21:44:45 +1100272NOTE: If Ben doesn't merge the setup files, may need to change this to
David Gibsonc125a182006-02-01 03:05:22 -0800273point to setup_32.c
274
275
276 I will describe later the boot process and various callbacks that
277 your platform should implement.
278
279
280II - The DT block format
281========================
282
283
284This chapter defines the actual format of the flattened device-tree
285passed to the kernel. The actual content of it and kernel requirements
286are described later. You can find example of code manipulating that
287format in various places, including arch/powerpc/kernel/prom_init.c
288which will generate a flattened device-tree from the Open Firmware
289representation, or the fs2dt utility which is part of the kexec tools
290which will generate one from a filesystem representation. It is
291expected that a bootloader like uboot provides a bit more support,
292that will be discussed later as well.
293
294Note: The block has to be in main memory. It has to be accessible in
295both real mode and virtual mode with no mapping other than main
296memory. If you are writing a simple flash bootloader, it should copy
297the block to RAM before passing it to the kernel.
298
299
3001) Header
301---------
302
303 The kernel is entered with r3 pointing to an area of memory that is
Stephen Rothwellb8b572e2008-08-01 15:20:30 +1000304 roughly described in arch/powerpc/include/asm/prom.h by the structure
David Gibsonc125a182006-02-01 03:05:22 -0800305 boot_param_header:
306
307struct boot_param_header {
308 u32 magic; /* magic word OF_DT_HEADER */
309 u32 totalsize; /* total size of DT block */
310 u32 off_dt_struct; /* offset to structure */
311 u32 off_dt_strings; /* offset to strings */
312 u32 off_mem_rsvmap; /* offset to memory reserve map
Domen Puncer5dd60162007-03-02 21:44:45 +1100313 */
David Gibsonc125a182006-02-01 03:05:22 -0800314 u32 version; /* format version */
315 u32 last_comp_version; /* last compatible version */
316
317 /* version 2 fields below */
318 u32 boot_cpuid_phys; /* Which physical CPU id we're
319 booting on */
320 /* version 3 fields below */
321 u32 size_dt_strings; /* size of the strings block */
David Gibson0e0293c2007-03-14 11:50:40 +1100322
323 /* version 17 fields below */
324 u32 size_dt_struct; /* size of the DT structure block */
David Gibsonc125a182006-02-01 03:05:22 -0800325};
326
327 Along with the constants:
328
329/* Definitions used by the flattened device tree */
330#define OF_DT_HEADER 0xd00dfeed /* 4: version,
331 4: total size */
332#define OF_DT_BEGIN_NODE 0x1 /* Start node: full name
Domen Puncer5dd60162007-03-02 21:44:45 +1100333 */
David Gibsonc125a182006-02-01 03:05:22 -0800334#define OF_DT_END_NODE 0x2 /* End node */
335#define OF_DT_PROP 0x3 /* Property: name off,
336 size, content */
337#define OF_DT_END 0x9
338
339 All values in this header are in big endian format, the various
340 fields in this header are defined more precisely below. All
341 "offset" values are in bytes from the start of the header; that is
342 from the value of r3.
343
344 - magic
345
346 This is a magic value that "marks" the beginning of the
347 device-tree block header. It contains the value 0xd00dfeed and is
348 defined by the constant OF_DT_HEADER
349
350 - totalsize
351
352 This is the total size of the DT block including the header. The
353 "DT" block should enclose all data structures defined in this
354 chapter (who are pointed to by offsets in this header). That is,
355 the device-tree structure, strings, and the memory reserve map.
356
357 - off_dt_struct
358
359 This is an offset from the beginning of the header to the start
360 of the "structure" part the device tree. (see 2) device tree)
361
362 - off_dt_strings
363
364 This is an offset from the beginning of the header to the start
365 of the "strings" part of the device-tree
366
367 - off_mem_rsvmap
368
369 This is an offset from the beginning of the header to the start
Domen Puncer5dd60162007-03-02 21:44:45 +1100370 of the reserved memory map. This map is a list of pairs of 64-
David Gibsonc125a182006-02-01 03:05:22 -0800371 bit integers. Each pair is a physical address and a size. The
David Gibsonc125a182006-02-01 03:05:22 -0800372 list is terminated by an entry of size 0. This map provides the
373 kernel with a list of physical memory areas that are "reserved"
374 and thus not to be used for memory allocations, especially during
375 early initialization. The kernel needs to allocate memory during
376 boot for things like un-flattening the device-tree, allocating an
377 MMU hash table, etc... Those allocations must be done in such a
378 way to avoid overriding critical things like, on Open Firmware
379 capable machines, the RTAS instance, or on some pSeries, the TCE
380 tables used for the iommu. Typically, the reserve map should
381 contain _at least_ this DT block itself (header,total_size). If
382 you are passing an initrd to the kernel, you should reserve it as
383 well. You do not need to reserve the kernel image itself. The map
Domen Puncer5dd60162007-03-02 21:44:45 +1100384 should be 64-bit aligned.
David Gibsonc125a182006-02-01 03:05:22 -0800385
386 - version
387
388 This is the version of this structure. Version 1 stops
389 here. Version 2 adds an additional field boot_cpuid_phys.
390 Version 3 adds the size of the strings block, allowing the kernel
391 to reallocate it easily at boot and free up the unused flattened
392 structure after expansion. Version 16 introduces a new more
393 "compact" format for the tree itself that is however not backward
David Gibson0e0293c2007-03-14 11:50:40 +1100394 compatible. Version 17 adds an additional field, size_dt_struct,
395 allowing it to be reallocated or moved more easily (this is
396 particularly useful for bootloaders which need to make
397 adjustments to a device tree based on probed information). You
398 should always generate a structure of the highest version defined
399 at the time of your implementation. Currently that is version 17,
400 unless you explicitly aim at being backward compatible.
David Gibsonc125a182006-02-01 03:05:22 -0800401
402 - last_comp_version
403
404 Last compatible version. This indicates down to what version of
405 the DT block you are backward compatible. For example, version 2
406 is backward compatible with version 1 (that is, a kernel build
407 for version 1 will be able to boot with a version 2 format). You
408 should put a 1 in this field if you generate a device tree of
David Gibson0e0293c2007-03-14 11:50:40 +1100409 version 1 to 3, or 16 if you generate a tree of version 16 or 17
David Gibsonc125a182006-02-01 03:05:22 -0800410 using the new unit name format.
411
412 - boot_cpuid_phys
413
414 This field only exist on version 2 headers. It indicate which
415 physical CPU ID is calling the kernel entry point. This is used,
416 among others, by kexec. If you are on an SMP system, this value
417 should match the content of the "reg" property of the CPU node in
418 the device-tree corresponding to the CPU calling the kernel entry
419 point (see further chapters for more informations on the required
420 device-tree contents)
421
David Gibson0e0293c2007-03-14 11:50:40 +1100422 - size_dt_strings
423
424 This field only exists on version 3 and later headers. It
425 gives the size of the "strings" section of the device tree (which
426 starts at the offset given by off_dt_strings).
427
428 - size_dt_struct
429
430 This field only exists on version 17 and later headers. It gives
431 the size of the "structure" section of the device tree (which
432 starts at the offset given by off_dt_struct).
David Gibsonc125a182006-02-01 03:05:22 -0800433
434 So the typical layout of a DT block (though the various parts don't
435 need to be in that order) looks like this (addresses go from top to
436 bottom):
437
438
439 ------------------------------
440 r3 -> | struct boot_param_header |
441 ------------------------------
442 | (alignment gap) (*) |
443 ------------------------------
444 | memory reserve map |
445 ------------------------------
446 | (alignment gap) |
447 ------------------------------
448 | |
449 | device-tree structure |
450 | |
451 ------------------------------
452 | (alignment gap) |
453 ------------------------------
454 | |
455 | device-tree strings |
456 | |
457 -----> ------------------------------
458 |
459 |
460 --- (r3 + totalsize)
461
462 (*) The alignment gaps are not necessarily present; their presence
463 and size are dependent on the various alignment requirements of
464 the individual data blocks.
465
466
4672) Device tree generalities
468---------------------------
469
470This device-tree itself is separated in two different blocks, a
471structure block and a strings block. Both need to be aligned to a 4
472byte boundary.
473
474First, let's quickly describe the device-tree concept before detailing
475the storage format. This chapter does _not_ describe the detail of the
476required types of nodes & properties for the kernel, this is done
477later in chapter III.
478
479The device-tree layout is strongly inherited from the definition of
480the Open Firmware IEEE 1275 device-tree. It's basically a tree of
481nodes, each node having two or more named properties. A property can
482have a value or not.
483
484It is a tree, so each node has one and only one parent except for the
485root node who has no parent.
486
487A node has 2 names. The actual node name is generally contained in a
488property of type "name" in the node property list whose value is a
489zero terminated string and is mandatory for version 1 to 3 of the
David Gibson0e0293c2007-03-14 11:50:40 +1100490format definition (as it is in Open Firmware). Version 16 makes it
David Gibsonc125a182006-02-01 03:05:22 -0800491optional as it can generate it from the unit name defined below.
492
Matt LaPlante2fe0ae72006-10-03 22:50:39 +0200493There is also a "unit name" that is used to differentiate nodes with
David Gibsonc125a182006-02-01 03:05:22 -0800494the same name at the same level, it is usually made of the node
Matt LaPlante2fe0ae72006-10-03 22:50:39 +0200495names, the "@" sign, and a "unit address", which definition is
David Gibsonc125a182006-02-01 03:05:22 -0800496specific to the bus type the node sits on.
497
498The unit name doesn't exist as a property per-se but is included in
499the device-tree structure. It is typically used to represent "path" in
500the device-tree. More details about the actual format of these will be
501below.
502
503The kernel powerpc generic code does not make any formal use of the
504unit address (though some board support code may do) so the only real
505requirement here for the unit address is to ensure uniqueness of
506the node unit name at a given level of the tree. Nodes with no notion
507of address and no possible sibling of the same name (like /memory or
508/cpus) may omit the unit address in the context of this specification,
509or use the "@0" default unit address. The unit name is used to define
510a node "full path", which is the concatenation of all parent node
511unit names separated with "/".
512
513The root node doesn't have a defined name, and isn't required to have
514a name property either if you are using version 3 or earlier of the
515format. It also has no unit address (no @ symbol followed by a unit
516address). The root node unit name is thus an empty string. The full
517path to the root node is "/".
518
519Every node which actually represents an actual device (that is, a node
520which isn't only a virtual "container" for more nodes, like "/cpus"
521is) is also required to have a "device_type" property indicating the
522type of node .
523
524Finally, every node that can be referenced from a property in another
525node is required to have a "linux,phandle" property. Real open
526firmware implementations provide a unique "phandle" value for every
527node that the "prom_init()" trampoline code turns into
528"linux,phandle" properties. However, this is made optional if the
529flattened device tree is used directly. An example of a node
530referencing another node via "phandle" is when laying out the
531interrupt tree which will be described in a further version of this
532document.
533
Domen Puncer5dd60162007-03-02 21:44:45 +1100534This "linux, phandle" property is a 32-bit value that uniquely
David Gibsonc125a182006-02-01 03:05:22 -0800535identifies a node. You are free to use whatever values or system of
536values, internal pointers, or whatever to generate these, the only
537requirement is that every node for which you provide that property has
538a unique value for it.
539
540Here is an example of a simple device-tree. In this example, an "o"
541designates a node followed by the node unit name. Properties are
542presented with their name followed by their content. "content"
543represents an ASCII string (zero terminated) value, while <content>
Domen Puncer5dd60162007-03-02 21:44:45 +1100544represents a 32-bit hexadecimal value. The various nodes in this
David Gibsonc125a182006-02-01 03:05:22 -0800545example will be discussed in a later chapter. At this point, it is
546only meant to give you a idea of what a device-tree looks like. I have
547purposefully kept the "name" and "linux,phandle" properties which
548aren't necessary in order to give you a better idea of what the tree
549looks like in practice.
550
551 / o device-tree
552 |- name = "device-tree"
553 |- model = "MyBoardName"
554 |- compatible = "MyBoardFamilyName"
555 |- #address-cells = <2>
556 |- #size-cells = <2>
557 |- linux,phandle = <0>
558 |
559 o cpus
560 | | - name = "cpus"
561 | | - linux,phandle = <1>
562 | | - #address-cells = <1>
563 | | - #size-cells = <0>
564 | |
565 | o PowerPC,970@0
566 | |- name = "PowerPC,970"
567 | |- device_type = "cpu"
568 | |- reg = <0>
569 | |- clock-frequency = <5f5e1000>
Timur Tabi32aed2a2007-02-14 15:29:07 -0600570 | |- 64-bit
David Gibsonc125a182006-02-01 03:05:22 -0800571 | |- linux,phandle = <2>
572 |
573 o memory@0
574 | |- name = "memory"
575 | |- device_type = "memory"
576 | |- reg = <00000000 00000000 00000000 20000000>
577 | |- linux,phandle = <3>
578 |
579 o chosen
580 |- name = "chosen"
581 |- bootargs = "root=/dev/sda2"
David Gibsonc125a182006-02-01 03:05:22 -0800582 |- linux,phandle = <4>
583
584This tree is almost a minimal tree. It pretty much contains the
585minimal set of required nodes and properties to boot a linux kernel;
586that is, some basic model informations at the root, the CPUs, and the
587physical memory layout. It also includes misc information passed
588through /chosen, like in this example, the platform type (mandatory)
589and the kernel command line arguments (optional).
590
Timur Tabi32aed2a2007-02-14 15:29:07 -0600591The /cpus/PowerPC,970@0/64-bit property is an example of a
David Gibsonc125a182006-02-01 03:05:22 -0800592property without a value. All other properties have a value. The
593significance of the #address-cells and #size-cells properties will be
594explained in chapter IV which defines precisely the required nodes and
595properties and their content.
596
597
5983) Device tree "structure" block
599
600The structure of the device tree is a linearized tree structure. The
601"OF_DT_BEGIN_NODE" token starts a new node, and the "OF_DT_END_NODE"
602ends that node definition. Child nodes are simply defined before
603"OF_DT_END_NODE" (that is nodes within the node). A 'token' is a 32
604bit value. The tree has to be "finished" with a OF_DT_END token
605
606Here's the basic structure of a single node:
607
608 * token OF_DT_BEGIN_NODE (that is 0x00000001)
609 * for version 1 to 3, this is the node full path as a zero
610 terminated string, starting with "/". For version 16 and later,
611 this is the node unit name only (or an empty string for the
612 root node)
613 * [align gap to next 4 bytes boundary]
614 * for each property:
615 * token OF_DT_PROP (that is 0x00000003)
Domen Puncer5dd60162007-03-02 21:44:45 +1100616 * 32-bit value of property value size in bytes (or 0 if no
617 value)
618 * 32-bit value of offset in string block of property name
David Gibsonc125a182006-02-01 03:05:22 -0800619 * property value data if any
620 * [align gap to next 4 bytes boundary]
621 * [child nodes if any]
622 * token OF_DT_END_NODE (that is 0x00000002)
623
Domen Puncer5dd60162007-03-02 21:44:45 +1100624So the node content can be summarized as a start token, a full path,
Matt LaPlante53cb4722006-10-03 22:55:17 +0200625a list of properties, a list of child nodes, and an end token. Every
David Gibsonc125a182006-02-01 03:05:22 -0800626child node is a full node structure itself as defined above.
627
David Gibsoneff2ebd2007-06-28 15:56:26 +1000628NOTE: The above definition requires that all property definitions for
629a particular node MUST precede any subnode definitions for that node.
630Although the structure would not be ambiguous if properties and
631subnodes were intermingled, the kernel parser requires that the
632properties come first (up until at least 2.6.22). Any tools
633manipulating a flattened tree must take care to preserve this
634constraint.
635
Matt LaPlante53cb4722006-10-03 22:55:17 +02006364) Device tree "strings" block
David Gibsonc125a182006-02-01 03:05:22 -0800637
638In order to save space, property names, which are generally redundant,
639are stored separately in the "strings" block. This block is simply the
640whole bunch of zero terminated strings for all property names
641concatenated together. The device-tree property definitions in the
642structure block will contain offset values from the beginning of the
643strings block.
644
645
646III - Required content of the device tree
647=========================================
648
649WARNING: All "linux,*" properties defined in this document apply only
650to a flattened device-tree. If your platform uses a real
651implementation of Open Firmware or an implementation compatible with
652the Open Firmware client interface, those properties will be created
653by the trampoline code in the kernel's prom_init() file. For example,
654that's where you'll have to add code to detect your board model and
Matt LaPlantea2ffd272006-10-03 22:49:15 +0200655set the platform number. However, when using the flattened device-tree
David Gibsonc125a182006-02-01 03:05:22 -0800656entry point, there is no prom_init() pass, and thus you have to
657provide those properties yourself.
658
659
6601) Note about cells and address representation
661----------------------------------------------
662
663The general rule is documented in the various Open Firmware
Domen Puncer5dd60162007-03-02 21:44:45 +1100664documentations. If you choose to describe a bus with the device-tree
David Gibsonc125a182006-02-01 03:05:22 -0800665and there exist an OF bus binding, then you should follow the
666specification. However, the kernel does not require every single
667device or bus to be described by the device tree.
668
669In general, the format of an address for a device is defined by the
670parent bus type, based on the #address-cells and #size-cells
Mark A. Greer5b14e5f2008-01-04 02:40:47 +1100671properties. Note that the parent's parent definitions of #address-cells
Matt LaPlanted9195882008-07-25 19:45:33 -0700672and #size-cells are not inherited so every node with children must specify
Mark A. Greer5b14e5f2008-01-04 02:40:47 +1100673them. The kernel requires the root node to have those properties defining
674addresses format for devices directly mapped on the processor bus.
David Gibsonc125a182006-02-01 03:05:22 -0800675
676Those 2 properties define 'cells' for representing an address and a
Domen Puncer5dd60162007-03-02 21:44:45 +1100677size. A "cell" is a 32-bit number. For example, if both contain 2
David Gibsonc125a182006-02-01 03:05:22 -0800678like the example tree given above, then an address and a size are both
Domen Puncer5dd60162007-03-02 21:44:45 +1100679composed of 2 cells, and each is a 64-bit number (cells are
David Gibsonc125a182006-02-01 03:05:22 -0800680concatenated and expected to be in big endian format). Another example
681is the way Apple firmware defines them, with 2 cells for an address
682and one cell for a size. Most 32-bit implementations should define
683#address-cells and #size-cells to 1, which represents a 32-bit value.
684Some 32-bit processors allow for physical addresses greater than 32
685bits; these processors should define #address-cells as 2.
686
687"reg" properties are always a tuple of the type "address size" where
688the number of cells of address and size is specified by the bus
689#address-cells and #size-cells. When a bus supports various address
690spaces and other flags relative to a given address allocation (like
691prefetchable, etc...) those flags are usually added to the top level
692bits of the physical address. For example, a PCI physical address is
693made of 3 cells, the bottom two containing the actual address itself
694while the top cell contains address space indication, flags, and pci
695bus & device numbers.
696
697For busses that support dynamic allocation, it's the accepted practice
698to then not provide the address in "reg" (keep it 0) though while
699providing a flag indicating the address is dynamically allocated, and
700then, to provide a separate "assigned-addresses" property that
701contains the fully allocated addresses. See the PCI OF bindings for
702details.
703
704In general, a simple bus with no address space bits and no dynamic
705allocation is preferred if it reflects your hardware, as the existing
706kernel address parsing functions will work out of the box. If you
707define a bus type with a more complex address format, including things
708like address space bits, you'll have to add a bus translator to the
709prom_parse.c file of the recent kernels for your bus type.
710
Stephen Neuendorffere1fd1862007-12-04 12:08:57 +1100711The "reg" property only defines addresses and sizes (if #size-cells is
712non-0) within a given bus. In order to translate addresses upward
Domen Puncer5dd60162007-03-02 21:44:45 +1100713(that is into parent bus addresses, and possibly into CPU physical
David Gibsonc125a182006-02-01 03:05:22 -0800714addresses), all busses must contain a "ranges" property. If the
715"ranges" property is missing at a given level, it's assumed that
Stephen Neuendorffere1fd1862007-12-04 12:08:57 +1100716translation isn't possible, i.e., the registers are not visible on the
717parent bus. The format of the "ranges" property for a bus is a list
718of:
David Gibsonc125a182006-02-01 03:05:22 -0800719
720 bus address, parent bus address, size
721
722"bus address" is in the format of the bus this bus node is defining,
723that is, for a PCI bridge, it would be a PCI address. Thus, (bus
724address, size) defines a range of addresses for child devices. "parent
725bus address" is in the format of the parent bus of this bus. For
726example, for a PCI host controller, that would be a CPU address. For a
727PCI<->ISA bridge, that would be a PCI address. It defines the base
728address in the parent bus where the beginning of that range is mapped.
729
Domen Puncer5dd60162007-03-02 21:44:45 +1100730For a new 64-bit powerpc board, I recommend either the 2/2 format or
David Gibsonc125a182006-02-01 03:05:22 -0800731Apple's 2/1 format which is slightly more compact since sizes usually
Domen Puncer5dd60162007-03-02 21:44:45 +1100732fit in a single 32-bit word. New 32-bit powerpc boards should use a
David Gibsonc125a182006-02-01 03:05:22 -08007331/1 format, unless the processor supports physical addresses greater
734than 32-bits, in which case a 2/1 format is recommended.
735
Stephen Neuendorffere1fd1862007-12-04 12:08:57 +1100736Alternatively, the "ranges" property may be empty, indicating that the
737registers are visible on the parent bus using an identity mapping
738translation. In other words, the parent bus address space is the same
739as the child bus address space.
David Gibsonc125a182006-02-01 03:05:22 -0800740
7412) Note about "compatible" properties
742-------------------------------------
743
744These properties are optional, but recommended in devices and the root
745node. The format of a "compatible" property is a list of concatenated
746zero terminated strings. They allow a device to express its
747compatibility with a family of similar devices, in some cases,
748allowing a single driver to match against several devices regardless
749of their actual names.
750
7513) Note about "name" properties
752-------------------------------
753
754While earlier users of Open Firmware like OldWorld macintoshes tended
755to use the actual device name for the "name" property, it's nowadays
756considered a good practice to use a name that is closer to the device
757class (often equal to device_type). For example, nowadays, ethernet
758controllers are named "ethernet", an additional "model" property
759defining precisely the chip type/model, and "compatible" property
760defining the family in case a single driver can driver more than one
761of these chips. However, the kernel doesn't generally put any
762restriction on the "name" property; it is simply considered good
763practice to follow the standard and its evolutions as closely as
764possible.
765
766Note also that the new format version 16 makes the "name" property
767optional. If it's absent for a node, then the node's unit name is then
768used to reconstruct the name. That is, the part of the unit name
769before the "@" sign is used (or the entire unit name if no "@" sign
770is present).
771
7724) Note about node and property names and character set
773-------------------------------------------------------
774
Matt LaPlantea2ffd272006-10-03 22:49:15 +0200775While open firmware provides more flexible usage of 8859-1, this
David Gibsonc125a182006-02-01 03:05:22 -0800776specification enforces more strict rules. Nodes and properties should
777be comprised only of ASCII characters 'a' to 'z', '0' to
778'9', ',', '.', '_', '+', '#', '?', and '-'. Node names additionally
779allow uppercase characters 'A' to 'Z' (property names should be
780lowercase. The fact that vendors like Apple don't respect this rule is
781irrelevant here). Additionally, node and property names should always
782begin with a character in the range 'a' to 'z' (or 'A' to 'Z' for node
783names).
784
785The maximum number of characters for both nodes and property names
786is 31. In the case of node names, this is only the leftmost part of
787a unit name (the pure "name" property), it doesn't include the unit
788address which can extend beyond that limit.
789
790
7915) Required nodes and properties
792--------------------------------
793 These are all that are currently required. However, it is strongly
794 recommended that you expose PCI host bridges as documented in the
795 PCI binding to open firmware, and your interrupt tree as documented
796 in OF interrupt tree specification.
797
798 a) The root node
799
800 The root node requires some properties to be present:
801
802 - model : this is your board name/model
803 - #address-cells : address representation for "root" devices
804 - #size-cells: the size representation for "root" devices
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100805 - device_type : This property shouldn't be necessary. However, if
806 you decide to create a device_type for your root node, make sure it
807 is _not_ "chrp" unless your platform is a pSeries or PAPR compliant
808 one for 64-bit, or a CHRP-type machine for 32-bit as this will
809 matched by the kernel this way.
David Gibsonc125a182006-02-01 03:05:22 -0800810
811 Additionally, some recommended properties are:
812
813 - compatible : the board "family" generally finds its way here,
814 for example, if you have 2 board models with a similar layout,
815 that typically get driven by the same platform code in the
816 kernel, you would use a different "model" property but put a
817 value in "compatible". The kernel doesn't directly use that
Stuart Yoder143a42d2007-02-16 11:30:29 -0600818 value but it is generally useful.
David Gibsonc125a182006-02-01 03:05:22 -0800819
820 The root node is also generally where you add additional properties
821 specific to your board like the serial number if any, that sort of
Matt LaPlante6c28f2c2006-10-03 22:46:31 +0200822 thing. It is recommended that if you add any "custom" property whose
David Gibsonc125a182006-02-01 03:05:22 -0800823 name may clash with standard defined ones, you prefix them with your
824 vendor name and a comma.
825
826 b) The /cpus node
827
828 This node is the parent of all individual CPU nodes. It doesn't
829 have any specific requirements, though it's generally good practice
830 to have at least:
831
832 #address-cells = <00000001>
833 #size-cells = <00000000>
834
835 This defines that the "address" for a CPU is a single cell, and has
836 no meaningful size. This is not necessary but the kernel will assume
837 that format when reading the "reg" properties of a CPU node, see
838 below
839
840 c) The /cpus/* nodes
841
842 So under /cpus, you are supposed to create a node for every CPU on
843 the machine. There is no specific restriction on the name of the
844 CPU, though It's common practice to call it PowerPC,<name>. For
845 example, Apple uses PowerPC,G5 while IBM uses PowerPC,970FX.
846
847 Required properties:
848
849 - device_type : has to be "cpu"
Domen Puncer5dd60162007-03-02 21:44:45 +1100850 - reg : This is the physical CPU number, it's a single 32-bit cell
David Gibsonc125a182006-02-01 03:05:22 -0800851 and is also used as-is as the unit number for constructing the
852 unit name in the full path. For example, with 2 CPUs, you would
853 have the full path:
854 /cpus/PowerPC,970FX@0
855 /cpus/PowerPC,970FX@1
856 (unit addresses do not require leading zeroes)
Benjamin Herrenschmidt20474ab2007-10-28 08:49:28 +1100857 - d-cache-block-size : one cell, L1 data cache block size in bytes (*)
858 - i-cache-block-size : one cell, L1 instruction cache block size in
David Gibsonc125a182006-02-01 03:05:22 -0800859 bytes
860 - d-cache-size : one cell, size of L1 data cache in bytes
861 - i-cache-size : one cell, size of L1 instruction cache in bytes
David Gibsonc125a182006-02-01 03:05:22 -0800862
Benjamin Herrenschmidt20474ab2007-10-28 08:49:28 +1100863(*) The cache "block" size is the size on which the cache management
864instructions operate. Historically, this document used the cache
865"line" size here which is incorrect. The kernel will prefer the cache
866block size and will fallback to cache line size for backward
867compatibility.
868
David Gibsonc125a182006-02-01 03:05:22 -0800869 Recommended properties:
870
871 - timebase-frequency : a cell indicating the frequency of the
872 timebase in Hz. This is not directly used by the generic code,
873 but you are welcome to copy/paste the pSeries code for setting
874 the kernel timebase/decrementer calibration based on this
875 value.
876 - clock-frequency : a cell indicating the CPU core clock frequency
Domen Puncer5dd60162007-03-02 21:44:45 +1100877 in Hz. A new property will be defined for 64-bit values, but if
David Gibsonc125a182006-02-01 03:05:22 -0800878 your frequency is < 4Ghz, one cell is enough. Here as well as
879 for the above, the common code doesn't use that property, but
880 you are welcome to re-use the pSeries or Maple one. A future
881 kernel version might provide a common function for this.
Benjamin Herrenschmidt20474ab2007-10-28 08:49:28 +1100882 - d-cache-line-size : one cell, L1 data cache line size in bytes
883 if different from the block size
884 - i-cache-line-size : one cell, L1 instruction cache line size in
885 bytes if different from the block size
David Gibsonc125a182006-02-01 03:05:22 -0800886
887 You are welcome to add any property you find relevant to your board,
888 like some information about the mechanism used to soft-reset the
889 CPUs. For example, Apple puts the GPIO number for CPU soft reset
890 lines in there as a "soft-reset" property since they start secondary
891 CPUs by soft-resetting them.
892
893
894 d) the /memory node(s)
895
896 To define the physical memory layout of your board, you should
897 create one or more memory node(s). You can either create a single
898 node with all memory ranges in its reg property, or you can create
899 several nodes, as you wish. The unit address (@ part) used for the
900 full path is the address of the first range of memory defined by a
901 given node. If you use a single memory node, this will typically be
902 @0.
903
904 Required properties:
905
906 - device_type : has to be "memory"
907 - reg : This property contains all the physical memory ranges of
908 your board. It's a list of addresses/sizes concatenated
909 together, with the number of cells of each defined by the
910 #address-cells and #size-cells of the root node. For example,
Matt LaPlante6c28f2c2006-10-03 22:46:31 +0200911 with both of these properties being 2 like in the example given
David Gibsonc125a182006-02-01 03:05:22 -0800912 earlier, a 970 based machine with 6Gb of RAM could typically
913 have a "reg" property here that looks like:
914
915 00000000 00000000 00000000 80000000
916 00000001 00000000 00000001 00000000
917
918 That is a range starting at 0 of 0x80000000 bytes and a range
919 starting at 0x100000000 and of 0x100000000 bytes. You can see
920 that there is no memory covering the IO hole between 2Gb and
921 4Gb. Some vendors prefer splitting those ranges into smaller
922 segments, but the kernel doesn't care.
923
924 e) The /chosen node
925
926 This node is a bit "special". Normally, that's where open firmware
927 puts some variable environment information, like the arguments, or
Stuart Yoderd1bff9e2007-02-19 11:25:05 -0600928 the default input/output devices.
David Gibsonc125a182006-02-01 03:05:22 -0800929
930 This specification makes a few of these mandatory, but also defines
931 some linux-specific properties that would be normally constructed by
932 the prom_init() trampoline when booting with an OF client interface,
933 but that you have to provide yourself when using the flattened format.
934
David Gibsonc125a182006-02-01 03:05:22 -0800935 Recommended properties:
936
937 - bootargs : This zero-terminated string is passed as the kernel
938 command line
939 - linux,stdout-path : This is the full path to your standard
940 console device if any. Typically, if you have serial devices on
941 your board, you may want to put the full path to the one set as
942 the default console in the firmware here, for the kernel to pick
Matt LaPlante5d3f0832006-11-30 05:21:10 +0100943 it up as its own default console. If you look at the function
David Gibsonc125a182006-02-01 03:05:22 -0800944 set_preferred_console() in arch/ppc64/kernel/setup.c, you'll see
945 that the kernel tries to find out the default console and has
946 knowledge of various types like 8250 serial ports. You may want
947 to extend this function to add your own.
David Gibsonc125a182006-02-01 03:05:22 -0800948
949 Note that u-boot creates and fills in the chosen node for platforms
950 that use it.
951
Stuart Yoderd1bff9e2007-02-19 11:25:05 -0600952 (Note: a practice that is now obsolete was to include a property
953 under /chosen called interrupt-controller which had a phandle value
954 that pointed to the main interrupt controller)
955
David Gibsonc125a182006-02-01 03:05:22 -0800956 f) the /soc<SOCname> node
957
958 This node is used to represent a system-on-a-chip (SOC) and must be
959 present if the processor is a SOC. The top-level soc node contains
960 information that is global to all devices on the SOC. The node name
961 should contain a unit address for the SOC, which is the base address
962 of the memory-mapped register set for the SOC. The name of an soc
963 node should start with "soc", and the remainder of the name should
964 represent the part number for the soc. For example, the MPC8540's
965 soc node would be called "soc8540".
966
967 Required properties:
968
969 - device_type : Should be "soc"
970 - ranges : Should be defined as specified in 1) to describe the
971 translation of SOC addresses for memory mapped SOC registers.
Becky Bruce7d4b95a2006-02-06 14:26:31 -0600972 - bus-frequency: Contains the bus frequency for the SOC node.
973 Typically, the value of this field is filled in by the boot
Stefan Roeseefcc2da2009-04-16 15:11:54 -0600974 loader.
Becky Bruce7d4b95a2006-02-06 14:26:31 -0600975
David Gibsonc125a182006-02-01 03:05:22 -0800976
977 Recommended properties:
978
979 - reg : This property defines the address and size of the
980 memory-mapped registers that are used for the SOC node itself.
981 It does not include the child device registers - these will be
982 defined inside each child node. The address specified in the
983 "reg" property should match the unit address of the SOC node.
984 - #address-cells : Address representation for "soc" devices. The
985 format of this field may vary depending on whether or not the
986 device registers are memory mapped. For memory mapped
987 registers, this field represents the number of cells needed to
988 represent the address of the registers. For SOCs that do not
989 use MMIO, a special address format should be defined that
990 contains enough cells to represent the required information.
991 See 1) above for more details on defining #address-cells.
992 - #size-cells : Size representation for "soc" devices
993 - #interrupt-cells : Defines the width of cells used to represent
994 interrupts. Typically this value is <2>, which includes a
995 32-bit number that represents the interrupt number, and a
996 32-bit number that represents the interrupt sense and level.
997 This field is only needed if the SOC contains an interrupt
998 controller.
999
1000 The SOC node may contain child nodes for each SOC device that the
1001 platform uses. Nodes should not be created for devices which exist
1002 on the SOC but are not used by a particular platform. See chapter VI
Domen Puncer5dd60162007-03-02 21:44:45 +11001003 for more information on how to specify devices that are part of a SOC.
David Gibsonc125a182006-02-01 03:05:22 -08001004
1005 Example SOC node for the MPC8540:
1006
1007 soc8540@e0000000 {
1008 #address-cells = <1>;
1009 #size-cells = <1>;
1010 #interrupt-cells = <2>;
1011 device_type = "soc";
1012 ranges = <00000000 e0000000 00100000>
1013 reg = <e0000000 00003000>;
Becky Bruce7d4b95a2006-02-06 14:26:31 -06001014 bus-frequency = <0>;
David Gibsonc125a182006-02-01 03:05:22 -08001015 }
1016
1017
1018
1019IV - "dtc", the device tree compiler
1020====================================
1021
1022
1023dtc source code can be found at
Justin P. Mattock0ea6e612010-07-23 20:51:24 -07001024<http://git.jdl.com/gitweb/?p=dtc.git>
David Gibsonc125a182006-02-01 03:05:22 -08001025
1026WARNING: This version is still in early development stage; the
1027resulting device-tree "blobs" have not yet been validated with the
1028kernel. The current generated bloc lacks a useful reserve map (it will
1029be fixed to generate an empty one, it's up to the bootloader to fill
1030it up) among others. The error handling needs work, bugs are lurking,
1031etc...
1032
1033dtc basically takes a device-tree in a given format and outputs a
1034device-tree in another format. The currently supported formats are:
1035
1036 Input formats:
1037 -------------
1038
1039 - "dtb": "blob" format, that is a flattened device-tree block
1040 with
1041 header all in a binary blob.
1042 - "dts": "source" format. This is a text file containing a
1043 "source" for a device-tree. The format is defined later in this
1044 chapter.
1045 - "fs" format. This is a representation equivalent to the
1046 output of /proc/device-tree, that is nodes are directories and
1047 properties are files
1048
1049 Output formats:
1050 ---------------
1051
1052 - "dtb": "blob" format
1053 - "dts": "source" format
1054 - "asm": assembly language file. This is a file that can be
1055 sourced by gas to generate a device-tree "blob". That file can
1056 then simply be added to your Makefile. Additionally, the
Matt LaPlante6c28f2c2006-10-03 22:46:31 +02001057 assembly file exports some symbols that can be used.
David Gibsonc125a182006-02-01 03:05:22 -08001058
1059
1060The syntax of the dtc tool is
1061
1062 dtc [-I <input-format>] [-O <output-format>]
1063 [-o output-filename] [-V output_version] input_filename
1064
1065
Domen Puncer5dd60162007-03-02 21:44:45 +11001066The "output_version" defines what version of the "blob" format will be
David Gibsonc125a182006-02-01 03:05:22 -08001067generated. Supported versions are 1,2,3 and 16. The default is
1068currently version 3 but that may change in the future to version 16.
1069
1070Additionally, dtc performs various sanity checks on the tree, like the
Matt LaPlante6c28f2c2006-10-03 22:46:31 +02001071uniqueness of linux, phandle properties, validity of strings, etc...
David Gibsonc125a182006-02-01 03:05:22 -08001072
1073The format of the .dts "source" file is "C" like, supports C and C++
Matt LaPlante6c28f2c2006-10-03 22:46:31 +02001074style comments.
David Gibsonc125a182006-02-01 03:05:22 -08001075
1076/ {
1077}
1078
1079The above is the "device-tree" definition. It's the only statement
1080supported currently at the toplevel.
1081
1082/ {
1083 property1 = "string_value"; /* define a property containing a 0
1084 * terminated string
1085 */
1086
1087 property2 = <1234abcd>; /* define a property containing a
Domen Puncer5dd60162007-03-02 21:44:45 +11001088 * numerical 32-bit value (hexadecimal)
David Gibsonc125a182006-02-01 03:05:22 -08001089 */
1090
1091 property3 = <12345678 12345678 deadbeef>;
1092 /* define a property containing 3
Domen Puncer5dd60162007-03-02 21:44:45 +11001093 * numerical 32-bit values (cells) in
David Gibsonc125a182006-02-01 03:05:22 -08001094 * hexadecimal
1095 */
1096 property4 = [0a 0b 0c 0d de ea ad be ef];
1097 /* define a property whose content is
1098 * an arbitrary array of bytes
1099 */
1100
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04001101 childnode@address { /* define a child node named "childnode"
David Gibsonc125a182006-02-01 03:05:22 -08001102 * whose unit name is "childnode at
1103 * address"
1104 */
1105
1106 childprop = "hello\n"; /* define a property "childprop" of
1107 * childnode (in this case, a string)
1108 */
1109 };
1110};
1111
1112Nodes can contain other nodes etc... thus defining the hierarchical
1113structure of the tree.
1114
1115Strings support common escape sequences from C: "\n", "\t", "\r",
1116"\(octal value)", "\x(hex value)".
1117
1118It is also suggested that you pipe your source file through cpp (gcc
1119preprocessor) so you can use #include's, #define for constants, etc...
1120
1121Finally, various options are planned but not yet implemented, like
1122automatic generation of phandles, labels (exported to the asm file so
1123you can point to a property content and change it easily from whatever
1124you link the device-tree with), label or path instead of numeric value
1125in some cells to "point" to a node (replaced by a phandle at compile
1126time), export of reserve map address to the asm file, ability to
1127specify reserve map content at compile time, etc...
1128
1129We may provide a .h include file with common definitions of that
1130proves useful for some properties (like building PCI properties or
1131interrupt maps) though it may be better to add a notion of struct
1132definitions to the compiler...
1133
1134
1135V - Recommendations for a bootloader
1136====================================
1137
1138
1139Here are some various ideas/recommendations that have been proposed
1140while all this has been defined and implemented.
1141
1142 - The bootloader may want to be able to use the device-tree itself
1143 and may want to manipulate it (to add/edit some properties,
1144 like physical memory size or kernel arguments). At this point, 2
1145 choices can be made. Either the bootloader works directly on the
1146 flattened format, or the bootloader has its own internal tree
1147 representation with pointers (similar to the kernel one) and
1148 re-flattens the tree when booting the kernel. The former is a bit
1149 more difficult to edit/modify, the later requires probably a bit
1150 more code to handle the tree structure. Note that the structure
1151 format has been designed so it's relatively easy to "insert"
1152 properties or nodes or delete them by just memmoving things
1153 around. It contains no internal offsets or pointers for this
1154 purpose.
1155
Matt LaPlanted6bc8ac2006-10-03 22:54:15 +02001156 - An example of code for iterating nodes & retrieving properties
David Gibsonc125a182006-02-01 03:05:22 -08001157 directly from the flattened tree format can be found in the kernel
1158 file arch/ppc64/kernel/prom.c, look at scan_flat_dt() function,
Matt LaPlanted6bc8ac2006-10-03 22:54:15 +02001159 its usage in early_init_devtree(), and the corresponding various
David Gibsonc125a182006-02-01 03:05:22 -08001160 early_init_dt_scan_*() callbacks. That code can be re-used in a
1161 GPL bootloader, and as the author of that code, I would be happy
Domen Puncer5dd60162007-03-02 21:44:45 +11001162 to discuss possible free licensing to any vendor who wishes to
David Gibsonc125a182006-02-01 03:05:22 -08001163 integrate all or part of this code into a non-GPL bootloader.
1164
1165
1166
1167VI - System-on-a-chip devices and nodes
1168=======================================
1169
1170Many companies are now starting to develop system-on-a-chip
Domen Puncer5dd60162007-03-02 21:44:45 +11001171processors, where the processor core (CPU) and many peripheral devices
David Gibsonc125a182006-02-01 03:05:22 -08001172exist on a single piece of silicon. For these SOCs, an SOC node
1173should be used that defines child nodes for the devices that make
1174up the SOC. While platforms are not required to use this model in
1175order to boot the kernel, it is highly encouraged that all SOC
1176implementations define as complete a flat-device-tree as possible to
1177describe the devices on the SOC. This will allow for the
1178genericization of much of the kernel code.
1179
1180
11811) Defining child nodes of an SOC
1182---------------------------------
1183
1184Each device that is part of an SOC may have its own node entry inside
1185the SOC node. For each device that is included in the SOC, the unit
1186address property represents the address offset for this device's
1187memory-mapped registers in the parent's address space. The parent's
1188address space is defined by the "ranges" property in the top-level soc
1189node. The "reg" property for each node that exists directly under the
1190SOC node should contain the address mapping from the child address space
1191to the parent SOC address space and the size of the device's
1192memory-mapped register file.
1193
1194For many devices that may exist inside an SOC, there are predefined
1195specifications for the format of the device tree node. All SOC child
1196nodes should follow these specifications, except where noted in this
1197document.
1198
1199See appendix A for an example partial SOC node definition for the
1200MPC8540.
1201
1202
Stuart Yoder27565902007-03-02 13:42:33 -060012032) Representing devices without a current OF specification
David Gibsonc125a182006-02-01 03:05:22 -08001204----------------------------------------------------------
1205
1206Currently, there are many devices on SOCs that do not have a standard
1207representation pre-defined as part of the open firmware
1208specifications, mainly because the boards that contain these SOCs are
1209not currently booted using open firmware. This section contains
1210descriptions for the SOC devices for which new nodes have been
1211defined; this list will expand as more and more SOC-containing
1212platforms are moved over to use the flattened-device-tree model.
1213
Kumar Galab053dc52009-06-19 08:31:05 -05001214VII - Specifying interrupt information for devices
Stuart Yoder27565902007-03-02 13:42:33 -06001215===================================================
1216
1217The device tree represents the busses and devices of a hardware
1218system in a form similar to the physical bus topology of the
1219hardware.
1220
1221In addition, a logical 'interrupt tree' exists which represents the
1222hierarchy and routing of interrupts in the hardware.
1223
1224The interrupt tree model is fully described in the
1225document "Open Firmware Recommended Practice: Interrupt
1226Mapping Version 0.9". The document is available at:
1227<http://playground.sun.com/1275/practice>.
1228
12291) interrupts property
1230----------------------
1231
1232Devices that generate interrupts to a single interrupt controller
1233should use the conventional OF representation described in the
1234OF interrupt mapping documentation.
1235
1236Each device which generates interrupts must have an 'interrupt'
1237property. The interrupt property value is an arbitrary number of
1238of 'interrupt specifier' values which describe the interrupt or
1239interrupts for the device.
1240
1241The encoding of an interrupt specifier is determined by the
1242interrupt domain in which the device is located in the
1243interrupt tree. The root of an interrupt domain specifies in
1244its #interrupt-cells property the number of 32-bit cells
1245required to encode an interrupt specifier. See the OF interrupt
1246mapping documentation for a detailed description of domains.
1247
1248For example, the binding for the OpenPIC interrupt controller
1249specifies an #interrupt-cells value of 2 to encode the interrupt
1250number and level/sense information. All interrupt children in an
1251OpenPIC interrupt domain use 2 cells per interrupt in their interrupts
1252property.
1253
1254The PCI bus binding specifies a #interrupt-cell value of 1 to encode
1255which interrupt pin (INTA,INTB,INTC,INTD) is used.
1256
12572) interrupt-parent property
1258----------------------------
1259
1260The interrupt-parent property is specified to define an explicit
1261link between a device node and its interrupt parent in
1262the interrupt tree. The value of interrupt-parent is the
1263phandle of the parent node.
1264
Francis Galieguea33f3222010-04-23 00:08:02 +02001265If the interrupt-parent property is not defined for a node, its
Stuart Yoder27565902007-03-02 13:42:33 -06001266interrupt parent is assumed to be an ancestor in the node's
1267_device tree_ hierarchy.
1268
12693) OpenPIC Interrupt Controllers
1270--------------------------------
1271
1272OpenPIC interrupt controllers require 2 cells to encode
1273interrupt information. The first cell defines the interrupt
1274number. The second cell defines the sense and level
1275information.
1276
1277Sense and level information should be encoded as follows:
1278
1279 0 = low to high edge sensitive type enabled
1280 1 = active low level sensitive type enabled
1281 2 = active high level sensitive type enabled
1282 3 = high to low edge sensitive type enabled
1283
12844) ISA Interrupt Controllers
1285----------------------------
1286
1287ISA PIC interrupt controllers require 2 cells to encode
1288interrupt information. The first cell defines the interrupt
1289number. The second cell defines the sense and level
1290information.
1291
1292ISA PIC interrupt controllers should adhere to the ISA PIC
1293encodings listed below:
1294
1295 0 = active low level sensitive type enabled
1296 1 = active high level sensitive type enabled
1297 2 = high to low edge sensitive type enabled
1298 3 = low to high edge sensitive type enabled
1299
Kumar Galab053dc52009-06-19 08:31:05 -05001300VIII - Specifying Device Power Management Information (sleep property)
Scott Wood2dff4172008-07-11 17:31:15 -05001301===================================================================
1302
1303Devices on SOCs often have mechanisms for placing devices into low-power
1304states that are decoupled from the devices' own register blocks. Sometimes,
1305this information is more complicated than a cell-index property can
1306reasonably describe. Thus, each device controlled in such a manner
1307may contain a "sleep" property which describes these connections.
1308
1309The sleep property consists of one or more sleep resources, each of
1310which consists of a phandle to a sleep controller, followed by a
1311controller-specific sleep specifier of zero or more cells.
1312
1313The semantics of what type of low power modes are possible are defined
1314by the sleep controller. Some examples of the types of low power modes
1315that may be supported are:
1316
1317 - Dynamic: The device may be disabled or enabled at any time.
1318 - System Suspend: The device may request to be disabled or remain
1319 awake during system suspend, but will not be disabled until then.
1320 - Permanent: The device is disabled permanently (until the next hard
1321 reset).
1322
1323Some devices may share a clock domain with each other, such that they should
1324only be suspended when none of the devices are in use. Where reasonable,
1325such nodes should be placed on a virtual bus, where the bus has the sleep
1326property. If the clock domain is shared among devices that cannot be
1327reasonably grouped in this manner, then create a virtual sleep controller
1328(similar to an interrupt nexus, except that defining a standardized
1329sleep-map should wait until its necessity is demonstrated).
1330
David Gibsonc125a182006-02-01 03:05:22 -08001331Appendix A - Sample SOC node for MPC8540
1332========================================
1333
Scott Wood7e720632008-06-25 12:07:39 -05001334 soc@e0000000 {
David Gibsonc125a182006-02-01 03:05:22 -08001335 #address-cells = <1>;
1336 #size-cells = <1>;
Scott Wood7e720632008-06-25 12:07:39 -05001337 compatible = "fsl,mpc8540-ccsr", "simple-bus";
David Gibsonc125a182006-02-01 03:05:22 -08001338 device_type = "soc";
Scott Wood7e720632008-06-25 12:07:39 -05001339 ranges = <0x00000000 0xe0000000 0x00100000>
Becky Bruce7d4b95a2006-02-06 14:26:31 -06001340 bus-frequency = <0>;
Scott Wood7e720632008-06-25 12:07:39 -05001341 interrupt-parent = <&pic>;
David Gibsonc125a182006-02-01 03:05:22 -08001342
David Gibsonc125a182006-02-01 03:05:22 -08001343 ethernet@24000 {
Scott Wood2dff4172008-07-11 17:31:15 -05001344 #address-cells = <1>;
1345 #size-cells = <1>;
David Gibsonc125a182006-02-01 03:05:22 -08001346 device_type = "network";
1347 model = "TSEC";
Scott Wood2dff4172008-07-11 17:31:15 -05001348 compatible = "gianfar", "simple-bus";
Scott Wood7e720632008-06-25 12:07:39 -05001349 reg = <0x24000 0x1000>;
1350 local-mac-address = [ 00 E0 0C 00 73 00 ];
1351 interrupts = <29 2 30 2 34 2>;
1352 phy-handle = <&phy0>;
Scott Wood2dff4172008-07-11 17:31:15 -05001353 sleep = <&pmc 00000080>;
1354 ranges;
1355
1356 mdio@24520 {
Scott Wood7e720632008-06-25 12:07:39 -05001357 reg = <0x24520 0x20>;
Scott Wood2dff4172008-07-11 17:31:15 -05001358 compatible = "fsl,gianfar-mdio";
1359
Scott Wood7e720632008-06-25 12:07:39 -05001360 phy0: ethernet-phy@0 {
1361 interrupts = <5 1>;
Scott Wood2dff4172008-07-11 17:31:15 -05001362 reg = <0>;
1363 device_type = "ethernet-phy";
1364 };
1365
Scott Wood7e720632008-06-25 12:07:39 -05001366 phy1: ethernet-phy@1 {
1367 interrupts = <5 1>;
Scott Wood2dff4172008-07-11 17:31:15 -05001368 reg = <1>;
1369 device_type = "ethernet-phy";
1370 };
1371
Scott Wood7e720632008-06-25 12:07:39 -05001372 phy3: ethernet-phy@3 {
1373 interrupts = <7 1>;
Scott Wood2dff4172008-07-11 17:31:15 -05001374 reg = <3>;
1375 device_type = "ethernet-phy";
1376 };
1377 };
David Gibsonc125a182006-02-01 03:05:22 -08001378 };
1379
1380 ethernet@25000 {
David Gibsonc125a182006-02-01 03:05:22 -08001381 device_type = "network";
1382 model = "TSEC";
1383 compatible = "gianfar";
Scott Wood7e720632008-06-25 12:07:39 -05001384 reg = <0x25000 0x1000>;
1385 local-mac-address = [ 00 E0 0C 00 73 01 ];
1386 interrupts = <13 2 14 2 18 2>;
1387 phy-handle = <&phy1>;
Scott Wood2dff4172008-07-11 17:31:15 -05001388 sleep = <&pmc 00000040>;
David Gibsonc125a182006-02-01 03:05:22 -08001389 };
1390
1391 ethernet@26000 {
David Gibsonc125a182006-02-01 03:05:22 -08001392 device_type = "network";
1393 model = "FEC";
1394 compatible = "gianfar";
Scott Wood7e720632008-06-25 12:07:39 -05001395 reg = <0x26000 0x1000>;
1396 local-mac-address = [ 00 E0 0C 00 73 02 ];
1397 interrupts = <41 2>;
1398 phy-handle = <&phy3>;
Scott Wood2dff4172008-07-11 17:31:15 -05001399 sleep = <&pmc 00000020>;
David Gibsonc125a182006-02-01 03:05:22 -08001400 };
1401
1402 serial@4500 {
Scott Wood2dff4172008-07-11 17:31:15 -05001403 #address-cells = <1>;
1404 #size-cells = <1>;
1405 compatible = "fsl,mpc8540-duart", "simple-bus";
1406 sleep = <&pmc 00000002>;
1407 ranges;
1408
1409 serial@4500 {
1410 device_type = "serial";
1411 compatible = "ns16550";
Scott Wood7e720632008-06-25 12:07:39 -05001412 reg = <0x4500 0x100>;
Scott Wood2dff4172008-07-11 17:31:15 -05001413 clock-frequency = <0>;
Scott Wood7e720632008-06-25 12:07:39 -05001414 interrupts = <42 2>;
Scott Wood2dff4172008-07-11 17:31:15 -05001415 };
1416
1417 serial@4600 {
1418 device_type = "serial";
1419 compatible = "ns16550";
Scott Wood7e720632008-06-25 12:07:39 -05001420 reg = <0x4600 0x100>;
Scott Wood2dff4172008-07-11 17:31:15 -05001421 clock-frequency = <0>;
Scott Wood7e720632008-06-25 12:07:39 -05001422 interrupts = <42 2>;
Scott Wood2dff4172008-07-11 17:31:15 -05001423 };
David Gibsonc125a182006-02-01 03:05:22 -08001424 };
1425
Scott Wood7e720632008-06-25 12:07:39 -05001426 pic: pic@40000 {
David Gibsonc125a182006-02-01 03:05:22 -08001427 interrupt-controller;
1428 #address-cells = <0>;
Scott Wood7e720632008-06-25 12:07:39 -05001429 #interrupt-cells = <2>;
1430 reg = <0x40000 0x40000>;
David Gibsonc125a182006-02-01 03:05:22 -08001431 compatible = "chrp,open-pic";
1432 device_type = "open-pic";
David Gibsonc125a182006-02-01 03:05:22 -08001433 };
1434
1435 i2c@3000 {
Scott Wood7e720632008-06-25 12:07:39 -05001436 interrupts = <43 2>;
1437 reg = <0x3000 0x100>;
David Gibsonc125a182006-02-01 03:05:22 -08001438 compatible = "fsl-i2c";
1439 dfsrr;
Scott Wood2dff4172008-07-11 17:31:15 -05001440 sleep = <&pmc 00000004>;
David Gibsonc125a182006-02-01 03:05:22 -08001441 };
1442
Scott Wood2dff4172008-07-11 17:31:15 -05001443 pmc: power@e0070 {
1444 compatible = "fsl,mpc8540-pmc", "fsl,mpc8548-pmc";
Scott Wood7e720632008-06-25 12:07:39 -05001445 reg = <0xe0070 0x20>;
Scott Wood2dff4172008-07-11 17:31:15 -05001446 };
David Gibsonc125a182006-02-01 03:05:22 -08001447 };