164dbbd40SGerald Van Baren /* 264dbbd40SGerald Van Baren * (C) Copyright 2007 364dbbd40SGerald Van Baren * Gerald Van Baren, Custom IDEAS, vanbaren@cideas.com 464dbbd40SGerald Van Baren * 51a459660SWolfgang Denk * SPDX-License-Identifier: GPL-2.0+ 664dbbd40SGerald Van Baren */ 764dbbd40SGerald Van Baren 864dbbd40SGerald Van Baren #ifndef __FDT_SUPPORT_H 964dbbd40SGerald Van Baren #define __FDT_SUPPORT_H 1064dbbd40SGerald Van Baren 1164dbbd40SGerald Van Baren #ifdef CONFIG_OF_LIBFDT 1264dbbd40SGerald Van Baren 1358864ddcSGerald Van Baren #include <libfdt.h> 1464dbbd40SGerald Van Baren 1594fb182cSAlexander Graf u32 fdt_getprop_u32_default_node(const void *fdt, int off, int cell, 1694fb182cSAlexander Graf const char *prop, const u32 dflt); 1707e12784SGabe Black u32 fdt_getprop_u32_default(const void *fdt, const char *path, 1807e12784SGabe Black const char *prop, const u32 dflt); 19bc6ed0f9SMasahiro Yamada int fdt_chosen(void *fdt); 20dbe963aeSMasahiro Yamada int fdt_initrd(void *fdt, ulong initrd_start, ulong initrd_end); 21e93becf8SKumar Gala void do_fixup_by_path(void *fdt, const char *path, const char *prop, 22e93becf8SKumar Gala const void *val, int len, int create); 23e93becf8SKumar Gala void do_fixup_by_path_u32(void *fdt, const char *path, const char *prop, 24e93becf8SKumar Gala u32 val, int create); 258ddb10eaSChunhe Lan 268ddb10eaSChunhe Lan static inline void do_fixup_by_path_string(void *fdt, const char *path, 278ddb10eaSChunhe Lan const char *prop, const char *status) 288ddb10eaSChunhe Lan { 298ddb10eaSChunhe Lan do_fixup_by_path(fdt, path, prop, status, strlen(status) + 1, 1); 308ddb10eaSChunhe Lan } 318ddb10eaSChunhe Lan 329eb77ceaSKumar Gala void do_fixup_by_prop(void *fdt, 339eb77ceaSKumar Gala const char *pname, const void *pval, int plen, 349eb77ceaSKumar Gala const char *prop, const void *val, int len, 359eb77ceaSKumar Gala int create); 369eb77ceaSKumar Gala void do_fixup_by_prop_u32(void *fdt, 379eb77ceaSKumar Gala const char *pname, const void *pval, int plen, 389eb77ceaSKumar Gala const char *prop, u32 val, int create); 399eb77ceaSKumar Gala void do_fixup_by_compat(void *fdt, const char *compat, 409eb77ceaSKumar Gala const char *prop, const void *val, int len, int create); 419eb77ceaSKumar Gala void do_fixup_by_compat_u32(void *fdt, const char *compat, 429eb77ceaSKumar Gala const char *prop, u32 val, int create); 433c927281SKumar Gala int fdt_fixup_memory(void *blob, u64 start, u64 size); 44a6bd9e83SJohn Rigby int fdt_fixup_memory_banks(void *blob, u64 start[], u64 size[], int banks); 45ba37aa03SKumar Gala void fdt_fixup_ethernet(void *fdt); 4622fb2246SMatthias Fuchs int fdt_find_and_setprop(void *fdt, const char *node, const char *prop, 4722fb2246SMatthias Fuchs const void *val, int len, int create); 48b8ec2385STimur Tabi void fdt_fixup_qe_firmware(void *fdt); 4964dbbd40SGerald Van Baren 5079f49120Sramneek mehresh #if defined(CONFIG_HAS_FSL_DR_USB) || defined(CONFIG_HAS_FSL_MPH_USB) 5118e69a35SAnton Vorontsov void fdt_fixup_dr_usb(void *blob, bd_t *bd); 5218e69a35SAnton Vorontsov #else 5318e69a35SAnton Vorontsov static inline void fdt_fixup_dr_usb(void *blob, bd_t *bd) {} 5479f49120Sramneek mehresh #endif /* defined(CONFIG_HAS_FSL_DR_USB) || defined(CONFIG_HAS_FSL_MPH_USB) */ 5518e69a35SAnton Vorontsov 56929a2138SKim Phillips #if defined(CONFIG_SYS_FSL_SEC_COMPAT) 576b70ffb9SKim Phillips void fdt_fixup_crypto_node(void *blob, int sec_rev); 586b70ffb9SKim Phillips #else 596b70ffb9SKim Phillips static inline void fdt_fixup_crypto_node(void *blob, int sec_rev) {} 606b70ffb9SKim Phillips #endif 616b70ffb9SKim Phillips 628ab451c4SKumar Gala #ifdef CONFIG_PCI 638ab451c4SKumar Gala #include <pci.h> 648ab451c4SKumar Gala int fdt_pci_dma_ranges(void *blob, int phb_off, struct pci_controller *hose); 658ab451c4SKumar Gala #endif 668ab451c4SKumar Gala 67a9e8e291SSimon Glass int fdt_find_or_add_subnode(void *fdt, int parentoffset, const char *name); 68a9e8e291SSimon Glass 69e895a4b0SSimon Glass /** 70e895a4b0SSimon Glass * Add board-specific data to the FDT before booting the OS. 71e895a4b0SSimon Glass * 72e895a4b0SSimon Glass * Use CONFIG_SYS_FDT_PAD to ensure there is sufficient space. 736f4dbc21SSimon Glass * This function is called if CONFIG_OF_BOARD_SETUP is defined 74e895a4b0SSimon Glass * 75e895a4b0SSimon Glass * @param blob FDT blob to update 76e895a4b0SSimon Glass * @param bd_t Pointer to board data 77e895a4b0SSimon Glass * @return 0 if ok, or -FDT_ERR_... on error 78e895a4b0SSimon Glass */ 79e895a4b0SSimon Glass int ft_board_setup(void *blob, bd_t *bd); 80e895a4b0SSimon Glass 8100c200f1SVitaly Andrianov /* 8200c200f1SVitaly Andrianov * The keystone2 SOC requires all 32 bit aliased addresses to be converted 8300c200f1SVitaly Andrianov * to their 36 physical format. This has to happen after all fdt nodes 8400c200f1SVitaly Andrianov * are added or modified by the image_setup_libfdt(). The ft_board_setup_ex() 8500c200f1SVitaly Andrianov * called at the end of the image_setup_libfdt() is to do that convertion. 8600c200f1SVitaly Andrianov */ 8700c200f1SVitaly Andrianov void ft_board_setup_ex(void *blob, bd_t *bd); 88e125a2ffSGerald Van Baren void ft_cpu_setup(void *blob, bd_t *bd); 89e125a2ffSGerald Van Baren void ft_pci_setup(void *blob, bd_t *bd); 90e125a2ffSGerald Van Baren 91*c654b517SSimon Glass /** 92*c654b517SSimon Glass * Add system-specific data to the FDT before booting the OS. 93*c654b517SSimon Glass * 94*c654b517SSimon Glass * Use CONFIG_SYS_FDT_PAD to ensure there is sufficient space. 95*c654b517SSimon Glass * This function is called if CONFIG_OF_SYSTEM_SETUP is defined 96*c654b517SSimon Glass * 97*c654b517SSimon Glass * @param blob FDT blob to update 98*c654b517SSimon Glass * @param bd_t Pointer to board data 99*c654b517SSimon Glass * @return 0 if ok, or -FDT_ERR_... on error 100*c654b517SSimon Glass */ 101*c654b517SSimon Glass int ft_system_setup(void *blob, bd_t *bd); 102*c654b517SSimon Glass 10354f9c866SKumar Gala void set_working_fdt_addr(void *addr); 1045bf58cccSSimon Glass int fdt_shrink_to_minimum(void *blob); 105b3606f14STimur Tabi int fdt_increase_size(void *fdt, int add_len); 10654f9c866SKumar Gala 1078a805df1SStefan Roese int fdt_fixup_nor_flash_size(void *blob); 10830d45c0dSStefan Roese 1093c950e2eSAnatolij Gustschin void fdt_fixup_mtdparts(void *fdt, void *node_info, int node_info_size); 11049b97d9cSKumar Gala void fdt_del_node_and_alias(void *blob, const char *alias); 1118aa5ec6eSKim Phillips u64 fdt_translate_address(void *blob, int node_offset, const __be32 *in_addr); 11275e73afdSKumar Gala int fdt_node_offset_by_compat_reg(void *blob, const char *compat, 11375e73afdSKumar Gala phys_addr_t compat_off); 114b4b847e9SKumar Gala int fdt_alloc_phandle(void *blob); 115f117c0f0SKumar Gala int fdt_set_phandle(void *fdt, int nodeoffset, uint32_t phandle); 1163c927cccSTimur Tabi unsigned int fdt_create_phandle(void *fdt, int nodeoffset); 117beca5a5fSAnatolij Gustschin int fdt_add_edid(void *blob, const char *compat, unsigned char *buf); 1183c950e2eSAnatolij Gustschin 119bb682001STimur Tabi int fdt_verify_alias_address(void *fdt, int anode, const char *alias, 120bb682001STimur Tabi u64 addr); 121bb682001STimur Tabi u64 fdt_get_base_address(void *fdt, int node); 122c48e6868SAlexander Graf int fdt_read_range(void *fdt, int node, int n, uint64_t *child_addr, 123c48e6868SAlexander Graf uint64_t *addr, uint64_t *len); 124bb682001STimur Tabi 1252a523f52SShengzhou Liu enum fdt_status { 1262a523f52SShengzhou Liu FDT_STATUS_OKAY, 1272a523f52SShengzhou Liu FDT_STATUS_DISABLED, 1282a523f52SShengzhou Liu FDT_STATUS_FAIL, 1292a523f52SShengzhou Liu FDT_STATUS_FAIL_ERROR_CODE, 1302a523f52SShengzhou Liu }; 1312a523f52SShengzhou Liu int fdt_set_node_status(void *fdt, int nodeoffset, 1322a523f52SShengzhou Liu enum fdt_status status, unsigned int error_code); 1332a523f52SShengzhou Liu static inline int fdt_status_okay(void *fdt, int nodeoffset) 1342a523f52SShengzhou Liu { 1352a523f52SShengzhou Liu return fdt_set_node_status(fdt, nodeoffset, FDT_STATUS_OKAY, 0); 1362a523f52SShengzhou Liu } 1372a523f52SShengzhou Liu static inline int fdt_status_disabled(void *fdt, int nodeoffset) 1382a523f52SShengzhou Liu { 1392a523f52SShengzhou Liu return fdt_set_node_status(fdt, nodeoffset, FDT_STATUS_DISABLED, 0); 1402a523f52SShengzhou Liu } 141b940ca64SJ. German Rivera static inline int fdt_status_fail(void *fdt, int nodeoffset) 142b940ca64SJ. German Rivera { 143b940ca64SJ. German Rivera return fdt_set_node_status(fdt, nodeoffset, FDT_STATUS_FAIL, 0); 144b940ca64SJ. German Rivera } 1452a523f52SShengzhou Liu 1462a523f52SShengzhou Liu int fdt_set_status_by_alias(void *fdt, const char *alias, 1472a523f52SShengzhou Liu enum fdt_status status, unsigned int error_code); 1482a523f52SShengzhou Liu static inline int fdt_status_okay_by_alias(void *fdt, const char *alias) 1492a523f52SShengzhou Liu { 1502a523f52SShengzhou Liu return fdt_set_status_by_alias(fdt, alias, FDT_STATUS_OKAY, 0); 1512a523f52SShengzhou Liu } 1522a523f52SShengzhou Liu static inline int fdt_status_disabled_by_alias(void *fdt, const char *alias) 1532a523f52SShengzhou Liu { 1542a523f52SShengzhou Liu return fdt_set_status_by_alias(fdt, alias, FDT_STATUS_DISABLED, 0); 1552a523f52SShengzhou Liu } 156b940ca64SJ. German Rivera static inline int fdt_status_fail_by_alias(void *fdt, const char *alias) 157b940ca64SJ. German Rivera { 158b940ca64SJ. German Rivera return fdt_set_status_by_alias(fdt, alias, FDT_STATUS_FAIL, 0); 159b940ca64SJ. German Rivera } 1602a523f52SShengzhou Liu 16108df4a21SArnab Basu /* Helper to read a big number; size is in cells (not bytes) */ 16208df4a21SArnab Basu static inline u64 of_read_number(const fdt32_t *cell, int size) 16308df4a21SArnab Basu { 16408df4a21SArnab Basu u64 r = 0; 16508df4a21SArnab Basu while (size--) 16608df4a21SArnab Basu r = (r << 32) | fdt32_to_cpu(*(cell++)); 16708df4a21SArnab Basu return r; 16808df4a21SArnab Basu } 16908df4a21SArnab Basu 170f43b4356SArnab Basu void of_bus_default_count_cells(void *blob, int parentoffset, 171f43b4356SArnab Basu int *addrc, int *sizec); 172d50b07dfSJeroen Hofstee int ft_verify_fdt(void *fdt); 173d50b07dfSJeroen Hofstee int arch_fixup_memory_node(void *blob); 174f43b4356SArnab Basu 17564dbbd40SGerald Van Baren #endif /* ifdef CONFIG_OF_LIBFDT */ 17629a23f9dSHeiko Schocher 17729a23f9dSHeiko Schocher #ifdef USE_HOSTCC 17829a23f9dSHeiko Schocher int fdtdec_get_int(const void *blob, int node, const char *prop_name, 17929a23f9dSHeiko Schocher int default_val); 18029a23f9dSHeiko Schocher #endif 18164dbbd40SGerald Van Baren #endif /* ifndef __FDT_SUPPORT_H */ 182