blob: 013c5418aeecfdbdfb5804c6f69547b2aa57c463 [file] [log] [blame]
Grant Likelyd8678b52009-10-15 10:57:53 -06001/*
2 * Definitions for working with the Flattened Device Tree data format
3 *
4 * Copyright 2009 Benjamin Herrenschmidt, IBM Corp
5 * benh@kernel.crashing.org
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * version 2 as published by the Free Software Foundation.
10 */
11
12#ifndef _LINUX_OF_FDT_H
13#define _LINUX_OF_FDT_H
14
Grant Likely8482f562009-10-15 10:58:04 -060015#include <linux/types.h>
16#include <linux/init.h>
Leif Lindholmd5031872016-09-27 23:54:12 +030017#include <linux/errno.h>
Grant Likely8482f562009-10-15 10:58:04 -060018
Grant Likelyd8678b52009-10-15 10:57:53 -060019/* Definitions used by the flattened device tree */
20#define OF_DT_HEADER 0xd00dfeed /* marker */
Grant Likelyd8678b52009-10-15 10:57:53 -060021
Grant Likelyd45d94f2009-10-15 10:57:55 -060022#ifndef __ASSEMBLY__
Grant Likelyd45d94f2009-10-15 10:57:55 -060023
Grant Likelycf32eb82010-04-13 16:12:25 -070024#if defined(CONFIG_OF_FLATTREE)
Stephen Neuendorffer9706a362010-11-18 15:54:59 -080025
Grant Likelya0817482011-01-08 21:42:42 -070026struct device_node;
27
Stephen Neuendorffer9706a362010-11-18 15:54:59 -080028/* For scanning an arbitrary device-tree at any time */
Rob Herringc972de12014-04-01 22:48:01 -050029extern char *of_fdt_get_string(const void *blob, u32 offset);
30extern void *of_fdt_get_property(const void *blob,
Stephen Neuendorffer9706a362010-11-18 15:54:59 -080031 unsigned long node,
32 const char *name,
Rob Herring9d0c4df2014-04-01 23:49:03 -050033 int *size);
Kevin Cernekeecc783782015-04-09 13:05:15 -070034extern bool of_fdt_is_big_endian(const void *blob,
35 unsigned long node);
Rob Herringc972de12014-04-01 22:48:01 -050036extern int of_fdt_match(const void *blob, unsigned long node,
Uwe Kleine-König7b482c82011-12-20 22:56:45 +010037 const char *const *compat);
Gavin Shan83262412016-05-03 23:22:51 +100038extern void *of_fdt_unflatten_tree(const unsigned long *blob,
39 struct device_node *dad,
40 struct device_node **mynodes);
Stephen Neuendorffer9706a362010-11-18 15:54:59 -080041
Grant Likelye169cfb2009-11-23 14:53:09 -070042/* TBD: Temporary export of fdt globals - remove when code fully merged */
Grant Likelyf00abd92009-11-24 03:27:10 -070043extern int __initdata dt_root_addr_cells;
44extern int __initdata dt_root_size_cells;
Rob Herring1daa0c42014-03-31 15:25:04 -050045extern void *initial_boot_params;
Grant Likelye169cfb2009-11-23 14:53:09 -070046
Rob Herringccf33562014-04-03 13:38:32 -050047extern char __dtb_start[];
48extern char __dtb_end[];
49
Grant Likely8482f562009-10-15 10:58:04 -060050/* For scanning the flat device-tree at boot time */
Grant Likely31a6a872009-11-23 19:49:38 -070051extern int of_scan_flat_dt(int (*it)(unsigned long node, const char *uname,
52 int depth, void *data),
53 void *data);
Nicholas Pigginea47dd12017-04-19 05:12:18 +100054extern int of_scan_flat_dt_subnodes(unsigned long node,
55 int (*it)(unsigned long node,
56 const char *uname,
57 void *data),
58 void *data);
Shannon Zhao9c609862016-04-07 20:03:33 +080059extern int of_get_flat_dt_subnode_by_name(unsigned long node,
60 const char *uname);
Rob Herring9d0c4df2014-04-01 23:49:03 -050061extern const void *of_get_flat_dt_prop(unsigned long node, const char *name,
62 int *size);
Grant Likely31a6a872009-11-23 19:49:38 -070063extern int of_flat_dt_is_compatible(unsigned long node, const char *name);
Uwe Kleine-König7b482c82011-12-20 22:56:45 +010064extern int of_flat_dt_match(unsigned long node, const char *const *matches);
Grant Likely31a6a872009-11-23 19:49:38 -070065extern unsigned long of_get_flat_dt_root(void);
Rob Herringc0556d32014-04-22 12:55:10 -050066extern int of_get_flat_dt_size(void);
Nicholas Pigginea47dd12017-04-19 05:12:18 +100067extern uint32_t of_get_flat_dt_phandle(unsigned long node);
Grant Likely32c97682010-10-20 11:45:14 -060068
Grant Likely86e03222009-12-10 23:42:21 -070069extern int early_init_dt_scan_chosen(unsigned long node, const char *uname,
70 int depth, void *data);
Grant Likely51975db2010-02-01 21:34:14 -070071extern int early_init_dt_scan_memory(unsigned long node, const char *uname,
72 int depth, void *data);
Leif Lindholmd5031872016-09-27 23:54:12 +030073extern int early_init_dt_scan_chosen_stdout(void);
Marek Szyprowskie8d9d1f2014-02-28 14:42:47 +010074extern void early_init_fdt_scan_reserved_mem(void);
Ard Biesheuvel24bbd922015-06-01 13:40:31 +020075extern void early_init_fdt_reserve_self(void);
Grant Likely51975db2010-02-01 21:34:14 -070076extern void early_init_dt_add_memory_arch(u64 base, u64 size);
Reza Arbab41a9ada2016-12-12 16:43:02 -080077extern int early_init_dt_mark_hotplug_memory_arch(u64 base, u64 size);
Marek Szyprowskie8d9d1f2014-02-28 14:42:47 +010078extern int early_init_dt_reserve_memory_arch(phys_addr_t base, phys_addr_t size,
79 bool no_map);
Grant Likelyfe55c182011-08-04 10:27:32 +010080extern void * early_init_dt_alloc_memory_arch(u64 size, u64 align);
Rob Herring9d0c4df2014-04-01 23:49:03 -050081extern u64 dt_mem_next_cell(int s, const __be32 **cellp);
Grant Likely8482f562009-10-15 10:58:04 -060082
Grant Likelyf00abd92009-11-24 03:27:10 -070083/* Early flat tree scan hooks */
84extern int early_init_dt_scan_root(unsigned long node, const char *uname,
85 int depth, void *data);
86
Rob Herring0288ffcb2013-08-26 09:47:40 -050087extern bool early_init_dt_scan(void *params);
Laura Abbott4972a742014-07-15 10:03:34 -070088extern bool early_init_dt_verify(void *params);
89extern void early_init_dt_scan_nodes(void);
Rob Herring0288ffcb2013-08-26 09:47:40 -050090
Rob Herring6a903a22013-08-27 21:41:56 -050091extern const char *of_flat_dt_get_machine_name(void);
92extern const void *of_flat_dt_match_machine(const void *default_match,
93 const void * (*get_next_compat)(const char * const**));
94
Grant Likely82b29282009-10-15 10:58:07 -060095/* Other Prototypes */
Grant Likely82b29282009-10-15 10:58:07 -060096extern void unflatten_device_tree(void);
Rob Herringa8bf7522013-08-26 11:22:45 -050097extern void unflatten_and_copy_device_tree(void);
Grant Likely82b29282009-10-15 10:58:07 -060098extern void early_init_devtree(void *);
Kevin Haob27652d2013-12-24 15:12:08 +080099extern void early_get_first_memblock_info(void *, phys_addr_t *);
Peter Hurleyc90fe9c2016-01-16 15:23:44 -0800100extern u64 of_flat_dt_translate_address(unsigned long node);
Laura Abbott704033c2014-07-15 10:03:35 -0700101extern void of_fdt_limit_memory(int limit);
Grant Likely8bfe9b52010-04-13 16:12:26 -0700102#else /* CONFIG_OF_FLATTREE */
Leif Lindholmd5031872016-09-27 23:54:12 +0300103static inline int early_init_dt_scan_chosen_stdout(void) { return -ENODEV; }
Marek Szyprowskie8d9d1f2014-02-28 14:42:47 +0100104static inline void early_init_fdt_scan_reserved_mem(void) {}
Ard Biesheuvel24bbd922015-06-01 13:40:31 +0200105static inline void early_init_fdt_reserve_self(void) {}
Rob Herring6a903a22013-08-27 21:41:56 -0500106static inline const char *of_flat_dt_get_machine_name(void) { return NULL; }
Grant Likely8bfe9b52010-04-13 16:12:26 -0700107static inline void unflatten_device_tree(void) {}
Rob Herringa8bf7522013-08-26 11:22:45 -0500108static inline void unflatten_and_copy_device_tree(void) {}
Grant Likelycf32eb82010-04-13 16:12:25 -0700109#endif /* CONFIG_OF_FLATTREE */
Grant Likely82b29282009-10-15 10:58:07 -0600110
Grant Likelyd45d94f2009-10-15 10:57:55 -0600111#endif /* __ASSEMBLY__ */
Grant Likelyd8678b52009-10-15 10:57:53 -0600112#endif /* _LINUX_OF_FDT_H */