144184828SRob Herring.. SPDX-License-Identifier: GPL-2.0 244184828SRob Herring 344184828SRob HerringDeviceTree Booting 444184828SRob Herring------------------ 544184828SRob Herring 644184828SRob HerringDuring the development of the Linux/ppc64 kernel, and more specifically, the 744184828SRob Herringaddition of new platform types outside of the old IBM pSeries/iSeries pair, it 844184828SRob Herringwas decided to enforce some strict rules regarding the kernel entry and 944184828SRob Herringbootloader <-> kernel interfaces, in order to avoid the degeneration that had 1044184828SRob Herringbecome the ppc32 kernel entry point and the way a new platform should be added 1144184828SRob Herringto the kernel. The legacy iSeries platform breaks those rules as it predates 1244184828SRob Herringthis scheme, but no new board support will be accepted in the main tree that 1344184828SRob Herringdoesn't follow them properly. In addition, since the advent of the arch/powerpc 1444184828SRob Herringmerged architecture for ppc32 and ppc64, new 32-bit platforms and 32-bit 1544184828SRob Herringplatforms which move into arch/powerpc will be required to use these rules as 1644184828SRob Herringwell. 1744184828SRob Herring 1844184828SRob HerringThe main requirement that will be defined in more detail below is the presence 1944184828SRob Herringof a device-tree whose format is defined after Open Firmware specification. 2044184828SRob HerringHowever, in order to make life easier to embedded board vendors, the kernel 2144184828SRob Herringdoesn't require the device-tree to represent every device in the system and only 2244184828SRob Herringrequires some nodes and properties to be present. For example, the kernel does 2344184828SRob Herringnot require you to create a node for every PCI device in the system. It is a 2444184828SRob Herringrequirement to have a node for PCI host bridges in order to provide interrupt 2544184828SRob Herringrouting information and memory/IO ranges, among others. It is also recommended 2644184828SRob Herringto define nodes for on chip devices and other buses that don't specifically fit 2744184828SRob Herringin an existing OF specification. This creates a great flexibility in the way the 2844184828SRob Herringkernel can then probe those and match drivers to device, without having to hard 2944184828SRob Herringcode all sorts of tables. It also makes it more flexible for board vendors to do 3044184828SRob Herringminor hardware upgrades without significantly impacting the kernel code or 3144184828SRob Herringcluttering it with special cases. 3244184828SRob Herring 3344184828SRob Herring 3444184828SRob HerringEntry point 3544184828SRob Herring~~~~~~~~~~~ 3644184828SRob Herring 3744184828SRob HerringThere is one single entry point to the kernel, at the start 3844184828SRob Herringof the kernel image. That entry point supports two calling 3944184828SRob Herringconventions: 4044184828SRob Herring 4144184828SRob Herring a) Boot from Open Firmware. If your firmware is compatible 4244184828SRob Herring with Open Firmware (IEEE 1275) or provides an OF compatible 4344184828SRob Herring client interface API (support for "interpret" callback of 4444184828SRob Herring forth words isn't required), you can enter the kernel with: 4544184828SRob Herring 4644184828SRob Herring r5 : OF callback pointer as defined by IEEE 1275 4744184828SRob Herring bindings to powerpc. Only the 32-bit client interface 4844184828SRob Herring is currently supported 4944184828SRob Herring 5044184828SRob Herring r3, r4 : address & length of an initrd if any or 0 5144184828SRob Herring 5244184828SRob Herring The MMU is either on or off; the kernel will run the 5344184828SRob Herring trampoline located in arch/powerpc/kernel/prom_init.c to 5444184828SRob Herring extract the device-tree and other information from open 5544184828SRob Herring firmware and build a flattened device-tree as described 5644184828SRob Herring in b). prom_init() will then re-enter the kernel using 5744184828SRob Herring the second method. This trampoline code runs in the 5844184828SRob Herring context of the firmware, which is supposed to handle all 5944184828SRob Herring exceptions during that time. 6044184828SRob Herring 6144184828SRob Herring b) Direct entry with a flattened device-tree block. This entry 6244184828SRob Herring point is called by a) after the OF trampoline and can also be 6344184828SRob Herring called directly by a bootloader that does not support the Open 6444184828SRob Herring Firmware client interface. It is also used by "kexec" to 6544184828SRob Herring implement "hot" booting of a new kernel from a previous 6644184828SRob Herring running one. This method is what I will describe in more 6744184828SRob Herring details in this document, as method a) is simply standard Open 6844184828SRob Herring Firmware, and thus should be implemented according to the 6944184828SRob Herring various standard documents defining it and its binding to the 7044184828SRob Herring PowerPC platform. The entry point definition then becomes: 7144184828SRob Herring 7244184828SRob Herring r3 : physical pointer to the device-tree block 7344184828SRob Herring (defined in chapter II) in RAM 7444184828SRob Herring 7544184828SRob Herring r4 : physical pointer to the kernel itself. This is 7644184828SRob Herring used by the assembly code to properly disable the MMU 7744184828SRob Herring in case you are entering the kernel with MMU enabled 7844184828SRob Herring and a non-1:1 mapping. 7944184828SRob Herring 8044184828SRob Herring r5 : NULL (as to differentiate with method a) 8144184828SRob Herring 8244184828SRob HerringNote about SMP entry: Either your firmware puts your other 8344184828SRob HerringCPUs in some sleep loop or spin loop in ROM where you can get 8444184828SRob Herringthem out via a soft reset or some other means, in which case 8544184828SRob Herringyou don't need to care, or you'll have to enter the kernel 8644184828SRob Herringwith all CPUs. The way to do that with method b) will be 8744184828SRob Herringdescribed in a later revision of this document. 8844184828SRob Herring 8944184828SRob HerringBoard supports (platforms) are not exclusive config options. An 9044184828SRob Herringarbitrary set of board supports can be built in a single kernel 9144184828SRob Herringimage. The kernel will "know" what set of functions to use for a 9244184828SRob Herringgiven platform based on the content of the device-tree. Thus, you 9344184828SRob Herringshould: 9444184828SRob Herring 9544184828SRob Herring a) add your platform support as a _boolean_ option in 9644184828SRob Herring arch/powerpc/Kconfig, following the example of PPC_PSERIES, 97*f8b42777SHe Ying PPC_PMAC and PPC_MAPLE. The latter is probably a good 9844184828SRob Herring example of a board support to start from. 9944184828SRob Herring 10044184828SRob Herring b) create your main platform file as 10144184828SRob Herring "arch/powerpc/platforms/myplatform/myboard_setup.c" and add it 10244184828SRob Herring to the Makefile under the condition of your ``CONFIG_`` 10344184828SRob Herring option. This file will define a structure of type "ppc_md" 10444184828SRob Herring containing the various callbacks that the generic code will 10544184828SRob Herring use to get to your platform specific code 10644184828SRob Herring 10744184828SRob HerringA kernel image may support multiple platforms, but only if the 10844184828SRob Herringplatforms feature the same core architecture. A single kernel build 10944184828SRob Herringcannot support both configurations with Book E and configurations 11044184828SRob Herringwith classic Powerpc architectures. 111