blob: 0ff360d5b3b3078b1ca85d29696d02741473edd0 [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>
17
Grant Likelyd8678b52009-10-15 10:57:53 -060018/* Definitions used by the flattened device tree */
19#define OF_DT_HEADER 0xd00dfeed /* marker */
Grant Likelyd8678b52009-10-15 10:57:53 -060020
Grant Likelyd45d94f2009-10-15 10:57:55 -060021#ifndef __ASSEMBLY__
Grant Likelyd45d94f2009-10-15 10:57:55 -060022
Grant Likelycf32eb82010-04-13 16:12:25 -070023#if defined(CONFIG_OF_FLATTREE)
Stephen Neuendorffer9706a362010-11-18 15:54:59 -080024
Grant Likelya0817482011-01-08 21:42:42 -070025struct device_node;
26
Stephen Neuendorffer9706a362010-11-18 15:54:59 -080027/* For scanning an arbitrary device-tree at any time */
Rob Herringc972de12014-04-01 22:48:01 -050028extern char *of_fdt_get_string(const void *blob, u32 offset);
29extern void *of_fdt_get_property(const void *blob,
Stephen Neuendorffer9706a362010-11-18 15:54:59 -080030 unsigned long node,
31 const char *name,
Rob Herring9d0c4df2014-04-01 23:49:03 -050032 int *size);
Rob Herringc972de12014-04-01 22:48:01 -050033extern int of_fdt_is_compatible(const void *blob,
Stephen Neuendorffer9706a362010-11-18 15:54:59 -080034 unsigned long node,
35 const char *compat);
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);
Stephen Neuendorfferfe140422010-11-18 15:55:02 -080038extern void of_fdt_unflatten_tree(unsigned long *blob,
39 struct device_node **mynodes);
Stephen Neuendorffer9706a362010-11-18 15:54:59 -080040
Grant Likelye169cfb2009-11-23 14:53:09 -070041/* TBD: Temporary export of fdt globals - remove when code fully merged */
Grant Likelyf00abd92009-11-24 03:27:10 -070042extern int __initdata dt_root_addr_cells;
43extern int __initdata dt_root_size_cells;
Rob Herring1daa0c42014-03-31 15:25:04 -050044extern void *initial_boot_params;
Grant Likelye169cfb2009-11-23 14:53:09 -070045
Rob Herringccf33562014-04-03 13:38:32 -050046extern char __dtb_start[];
47extern char __dtb_end[];
48
Grant Likely8482f562009-10-15 10:58:04 -060049/* For scanning the flat device-tree at boot time */
Grant Likely31a6a872009-11-23 19:49:38 -070050extern int of_scan_flat_dt(int (*it)(unsigned long node, const char *uname,
51 int depth, void *data),
52 void *data);
Rob Herring9d0c4df2014-04-01 23:49:03 -050053extern const void *of_get_flat_dt_prop(unsigned long node, const char *name,
54 int *size);
Grant Likely31a6a872009-11-23 19:49:38 -070055extern int of_flat_dt_is_compatible(unsigned long node, const char *name);
Uwe Kleine-König7b482c82011-12-20 22:56:45 +010056extern int of_flat_dt_match(unsigned long node, const char *const *matches);
Grant Likely31a6a872009-11-23 19:49:38 -070057extern unsigned long of_get_flat_dt_root(void);
Rob Herringc0556d32014-04-22 12:55:10 -050058extern int of_get_flat_dt_size(void);
Grant Likely32c97682010-10-20 11:45:14 -060059
Grant Likely86e03222009-12-10 23:42:21 -070060extern int early_init_dt_scan_chosen(unsigned long node, const char *uname,
61 int depth, void *data);
Grant Likely51975db2010-02-01 21:34:14 -070062extern int early_init_dt_scan_memory(unsigned long node, const char *uname,
63 int depth, void *data);
Marek Szyprowskie8d9d1f2014-02-28 14:42:47 +010064extern void early_init_fdt_scan_reserved_mem(void);
Grant Likely51975db2010-02-01 21:34:14 -070065extern void early_init_dt_add_memory_arch(u64 base, u64 size);
Marek Szyprowskie8d9d1f2014-02-28 14:42:47 +010066extern int early_init_dt_reserve_memory_arch(phys_addr_t base, phys_addr_t size,
67 bool no_map);
Grant Likelyfe55c182011-08-04 10:27:32 +010068extern void * early_init_dt_alloc_memory_arch(u64 size, u64 align);
Rob Herring9d0c4df2014-04-01 23:49:03 -050069extern u64 dt_mem_next_cell(int s, const __be32 **cellp);
Grant Likely8482f562009-10-15 10:58:04 -060070
Grant Likelyf00abd92009-11-24 03:27:10 -070071/* Early flat tree scan hooks */
72extern int early_init_dt_scan_root(unsigned long node, const char *uname,
73 int depth, void *data);
74
Rob Herring0288ffcb2013-08-26 09:47:40 -050075extern bool early_init_dt_scan(void *params);
Laura Abbott4972a742014-07-15 10:03:34 -070076extern bool early_init_dt_verify(void *params);
77extern void early_init_dt_scan_nodes(void);
Rob Herring0288ffcb2013-08-26 09:47:40 -050078
Rob Herring6a903a22013-08-27 21:41:56 -050079extern const char *of_flat_dt_get_machine_name(void);
80extern const void *of_flat_dt_match_machine(const void *default_match,
81 const void * (*get_next_compat)(const char * const**));
82
Grant Likely82b29282009-10-15 10:58:07 -060083/* Other Prototypes */
Grant Likely82b29282009-10-15 10:58:07 -060084extern void unflatten_device_tree(void);
Rob Herringa8bf7522013-08-26 11:22:45 -050085extern void unflatten_and_copy_device_tree(void);
Grant Likely82b29282009-10-15 10:58:07 -060086extern void early_init_devtree(void *);
Kevin Haob27652d2013-12-24 15:12:08 +080087extern void early_get_first_memblock_info(void *, phys_addr_t *);
Rob Herringe06e8b22014-03-27 07:37:43 -050088extern u64 fdt_translate_address(const void *blob, int node_offset);
Laura Abbott704033c2014-07-15 10:03:35 -070089extern void of_fdt_limit_memory(int limit);
Grant Likely8bfe9b52010-04-13 16:12:26 -070090#else /* CONFIG_OF_FLATTREE */
Marek Szyprowskie8d9d1f2014-02-28 14:42:47 +010091static inline void early_init_fdt_scan_reserved_mem(void) {}
Rob Herring6a903a22013-08-27 21:41:56 -050092static inline const char *of_flat_dt_get_machine_name(void) { return NULL; }
Grant Likely8bfe9b52010-04-13 16:12:26 -070093static inline void unflatten_device_tree(void) {}
Rob Herringa8bf7522013-08-26 11:22:45 -050094static inline void unflatten_and_copy_device_tree(void) {}
Grant Likelycf32eb82010-04-13 16:12:25 -070095#endif /* CONFIG_OF_FLATTREE */
Grant Likely82b29282009-10-15 10:58:07 -060096
Grant Likelyd45d94f2009-10-15 10:57:55 -060097#endif /* __ASSEMBLY__ */
Grant Likelyd8678b52009-10-15 10:57:53 -060098#endif /* _LINUX_OF_FDT_H */