booting-without-of.txt 60 KB

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