blob: acf820e88952977cdcb2d34cebd8d0ea759f2117 [file] [log] [blame]
Rob Herringaf6074f2017-12-27 12:55:14 -06001/* SPDX-License-Identifier: GPL-2.0 */
Grant Likelyd8678b52009-10-15 10:57:53 -06002/*
3 * Definitions for working with the Flattened Device Tree data format
4 *
5 * Copyright 2009 Benjamin Herrenschmidt, IBM Corp
6 * benh@kernel.crashing.org
Grant Likelyd8678b52009-10-15 10:57:53 -06007 */
8
9#ifndef _LINUX_OF_FDT_H
10#define _LINUX_OF_FDT_H
11
Grant Likely8482f562009-10-15 10:58:04 -060012#include <linux/types.h>
13#include <linux/init.h>
Leif Lindholmd5031872016-09-27 23:54:12 +030014#include <linux/errno.h>
Grant Likely8482f562009-10-15 10:58:04 -060015
Grant Likelyd8678b52009-10-15 10:57:53 -060016/* Definitions used by the flattened device tree */
17#define OF_DT_HEADER 0xd00dfeed /* marker */
Grant Likelyd8678b52009-10-15 10:57:53 -060018
Grant Likelyd45d94f2009-10-15 10:57:55 -060019#ifndef __ASSEMBLY__
Grant Likelyd45d94f2009-10-15 10:57:55 -060020
Grant Likelycf32eb82010-04-13 16:12:25 -070021#if defined(CONFIG_OF_FLATTREE)
Stephen Neuendorffer9706a362010-11-18 15:54:59 -080022
Grant Likelya0817482011-01-08 21:42:42 -070023struct device_node;
24
Stephen Neuendorffer9706a362010-11-18 15:54:59 -080025/* For scanning an arbitrary device-tree at any time */
Gavin Shan83262412016-05-03 23:22:51 +100026extern void *of_fdt_unflatten_tree(const unsigned long *blob,
27 struct device_node *dad,
28 struct device_node **mynodes);
Stephen Neuendorffer9706a362010-11-18 15:54:59 -080029
Grant Likelye169cfb2009-11-23 14:53:09 -070030/* TBD: Temporary export of fdt globals - remove when code fully merged */
Grant Likelyf00abd92009-11-24 03:27:10 -070031extern int __initdata dt_root_addr_cells;
32extern int __initdata dt_root_size_cells;
Rob Herring1daa0c42014-03-31 15:25:04 -050033extern void *initial_boot_params;
Grant Likelye169cfb2009-11-23 14:53:09 -070034
Rob Herringccf33562014-04-03 13:38:32 -050035extern char __dtb_start[];
36extern char __dtb_end[];
37
Geert Uytterhoevenf347c362018-01-04 10:08:36 +010038/* Other Prototypes */
39extern u64 of_flat_dt_translate_address(unsigned long node);
40extern void of_fdt_limit_memory(int limit);
41#endif /* CONFIG_OF_FLATTREE */
42
43#ifdef CONFIG_OF_EARLY_FLATTREE
Grant Likely8482f562009-10-15 10:58:04 -060044/* For scanning the flat device-tree at boot time */
Grant Likely31a6a872009-11-23 19:49:38 -070045extern int of_scan_flat_dt(int (*it)(unsigned long node, const char *uname,
46 int depth, void *data),
47 void *data);
Nicholas Pigginea47dd12017-04-19 05:12:18 +100048extern int of_scan_flat_dt_subnodes(unsigned long node,
49 int (*it)(unsigned long node,
50 const char *uname,
51 void *data),
52 void *data);
Shannon Zhao9c609862016-04-07 20:03:33 +080053extern int of_get_flat_dt_subnode_by_name(unsigned long node,
54 const char *uname);
Rob Herring9d0c4df2014-04-01 23:49:03 -050055extern const void *of_get_flat_dt_prop(unsigned long node, const char *name,
56 int *size);
Grant Likely31a6a872009-11-23 19:49:38 -070057extern int of_flat_dt_is_compatible(unsigned long node, const char *name);
58extern unsigned long of_get_flat_dt_root(void);
Nicholas Pigginea47dd12017-04-19 05:12:18 +100059extern uint32_t of_get_flat_dt_phandle(unsigned long node);
Grant Likely32c97682010-10-20 11:45:14 -060060
Grant Likely86e03222009-12-10 23:42:21 -070061extern int early_init_dt_scan_chosen(unsigned long node, const char *uname,
62 int depth, void *data);
Grant Likely51975db2010-02-01 21:34:14 -070063extern int early_init_dt_scan_memory(unsigned long node, const char *uname,
64 int depth, void *data);
Leif Lindholmd5031872016-09-27 23:54:12 +030065extern int early_init_dt_scan_chosen_stdout(void);
Marek Szyprowskie8d9d1f2014-02-28 14:42:47 +010066extern void early_init_fdt_scan_reserved_mem(void);
Ard Biesheuvel24bbd922015-06-01 13:40:31 +020067extern void early_init_fdt_reserve_self(void);
Yi Wang89f579c2018-11-22 10:04:09 +080068extern void __init early_init_dt_scan_chosen_arch(unsigned long node);
Grant Likely51975db2010-02-01 21:34:14 -070069extern void early_init_dt_add_memory_arch(u64 base, u64 size);
Reza Arbab41a9ada2016-12-12 16:43:02 -080070extern int early_init_dt_mark_hotplug_memory_arch(u64 base, u64 size);
Marek Szyprowskie8d9d1f2014-02-28 14:42:47 +010071extern int early_init_dt_reserve_memory_arch(phys_addr_t base, phys_addr_t size,
72 bool no_map);
Rob Herring9d0c4df2014-04-01 23:49:03 -050073extern u64 dt_mem_next_cell(int s, const __be32 **cellp);
Grant Likely8482f562009-10-15 10:58:04 -060074
Grant Likelyf00abd92009-11-24 03:27:10 -070075/* Early flat tree scan hooks */
76extern int early_init_dt_scan_root(unsigned long node, const char *uname,
77 int depth, void *data);
78
Rob Herring0288ffcb2013-08-26 09:47:40 -050079extern bool early_init_dt_scan(void *params);
Laura Abbott4972a742014-07-15 10:03:34 -070080extern bool early_init_dt_verify(void *params);
81extern void early_init_dt_scan_nodes(void);
Rob Herring0288ffcb2013-08-26 09:47:40 -050082
Rob Herring6a903a22013-08-27 21:41:56 -050083extern const char *of_flat_dt_get_machine_name(void);
84extern const void *of_flat_dt_match_machine(const void *default_match,
85 const void * (*get_next_compat)(const char * const**));
86
Grant Likely82b29282009-10-15 10:58:07 -060087/* Other Prototypes */
Grant Likely82b29282009-10-15 10:58:07 -060088extern void unflatten_device_tree(void);
Rob Herringa8bf7522013-08-26 11:22:45 -050089extern void unflatten_and_copy_device_tree(void);
Grant Likely82b29282009-10-15 10:58:07 -060090extern void early_init_devtree(void *);
Kevin Haob27652d2013-12-24 15:12:08 +080091extern void early_get_first_memblock_info(void *, phys_addr_t *);
Geert Uytterhoevenf347c362018-01-04 10:08:36 +010092#else /* CONFIG_OF_EARLY_FLATTREE */
Leif Lindholmd5031872016-09-27 23:54:12 +030093static inline int early_init_dt_scan_chosen_stdout(void) { return -ENODEV; }
Marek Szyprowskie8d9d1f2014-02-28 14:42:47 +010094static inline void early_init_fdt_scan_reserved_mem(void) {}
Ard Biesheuvel24bbd922015-06-01 13:40:31 +020095static inline void early_init_fdt_reserve_self(void) {}
Rob Herring6a903a22013-08-27 21:41:56 -050096static inline const char *of_flat_dt_get_machine_name(void) { return NULL; }
Grant Likely8bfe9b52010-04-13 16:12:26 -070097static inline void unflatten_device_tree(void) {}
Rob Herringa8bf7522013-08-26 11:22:45 -050098static inline void unflatten_and_copy_device_tree(void) {}
Geert Uytterhoevenf347c362018-01-04 10:08:36 +010099#endif /* CONFIG_OF_EARLY_FLATTREE */
Grant Likely82b29282009-10-15 10:58:07 -0600100
Grant Likelyd45d94f2009-10-15 10:57:55 -0600101#endif /* __ASSEMBLY__ */
Grant Likelyd8678b52009-10-15 10:57:53 -0600102#endif /* _LINUX_OF_FDT_H */