of.h 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. #ifndef _LINUX_OF_H
  3. #define _LINUX_OF_H
  4. /*
  5. * Definitions for talking to the Open Firmware PROM on
  6. * Power Macintosh and other computers.
  7. *
  8. * Copyright (C) 1996-2005 Paul Mackerras.
  9. *
  10. * Updates for PPC64 by Peter Bergner & David Engebretsen, IBM Corp.
  11. * Updates for SPARC64 by David S. Miller
  12. * Derived from PowerPC and Sparc prom.h files by Stephen Rothwell, IBM Corp.
  13. */
  14. #include <linux/types.h>
  15. #include <linux/bitops.h>
  16. #include <linux/errno.h>
  17. #include <linux/kobject.h>
  18. #include <linux/mod_devicetable.h>
  19. #include <linux/spinlock.h>
  20. #include <linux/topology.h>
  21. #include <linux/notifier.h>
  22. #include <linux/property.h>
  23. #include <linux/list.h>
  24. #include <asm/byteorder.h>
  25. #include <asm/errno.h>
  26. typedef u32 phandle;
  27. typedef u32 ihandle;
  28. struct property {
  29. char *name;
  30. int length;
  31. void *value;
  32. struct property *next;
  33. #if defined(CONFIG_OF_DYNAMIC) || defined(CONFIG_SPARC)
  34. unsigned long _flags;
  35. #endif
  36. #if defined(CONFIG_OF_PROMTREE)
  37. unsigned int unique_id;
  38. #endif
  39. #if defined(CONFIG_OF_KOBJ)
  40. struct bin_attribute attr;
  41. #endif
  42. };
  43. #if defined(CONFIG_SPARC)
  44. struct of_irq_controller;
  45. #endif
  46. struct device_node {
  47. const char *name;
  48. const char *type;
  49. phandle phandle;
  50. const char *full_name;
  51. struct fwnode_handle fwnode;
  52. struct property *properties;
  53. struct property *deadprops; /* removed properties */
  54. struct device_node *parent;
  55. struct device_node *child;
  56. struct device_node *sibling;
  57. #if defined(CONFIG_OF_KOBJ)
  58. struct kobject kobj;
  59. #endif
  60. unsigned long _flags;
  61. void *data;
  62. #if defined(CONFIG_SPARC)
  63. const char *path_component_name;
  64. unsigned int unique_id;
  65. struct of_irq_controller *irq_trans;
  66. #endif
  67. };
  68. #define MAX_PHANDLE_ARGS 16
  69. struct of_phandle_args {
  70. struct device_node *np;
  71. int args_count;
  72. uint32_t args[MAX_PHANDLE_ARGS];
  73. };
  74. struct of_phandle_iterator {
  75. /* Common iterator information */
  76. const char *cells_name;
  77. int cell_count;
  78. const struct device_node *parent;
  79. /* List size information */
  80. const __be32 *list_end;
  81. const __be32 *phandle_end;
  82. /* Current position state */
  83. const __be32 *cur;
  84. uint32_t cur_count;
  85. phandle phandle;
  86. struct device_node *node;
  87. };
  88. struct of_reconfig_data {
  89. struct device_node *dn;
  90. struct property *prop;
  91. struct property *old_prop;
  92. };
  93. /* initialize a node */
  94. extern struct kobj_type of_node_ktype;
  95. extern const struct fwnode_operations of_fwnode_ops;
  96. static inline void of_node_init(struct device_node *node)
  97. {
  98. #if defined(CONFIG_OF_KOBJ)
  99. kobject_init(&node->kobj, &of_node_ktype);
  100. #endif
  101. node->fwnode.ops = &of_fwnode_ops;
  102. }
  103. #if defined(CONFIG_OF_KOBJ)
  104. #define of_node_kobj(n) (&(n)->kobj)
  105. #else
  106. #define of_node_kobj(n) NULL
  107. #endif
  108. #ifdef CONFIG_OF_DYNAMIC
  109. extern struct device_node *of_node_get(struct device_node *node);
  110. extern void of_node_put(struct device_node *node);
  111. #else /* CONFIG_OF_DYNAMIC */
  112. /* Dummy ref counting routines - to be implemented later */
  113. static inline struct device_node *of_node_get(struct device_node *node)
  114. {
  115. return node;
  116. }
  117. static inline void of_node_put(struct device_node *node) { }
  118. #endif /* !CONFIG_OF_DYNAMIC */
  119. /* Pointer for first entry in chain of all nodes. */
  120. extern struct device_node *of_root;
  121. extern struct device_node *of_chosen;
  122. extern struct device_node *of_aliases;
  123. extern struct device_node *of_stdout;
  124. extern raw_spinlock_t devtree_lock;
  125. /* flag descriptions (need to be visible even when !CONFIG_OF) */
  126. #define OF_DYNAMIC 1 /* node and properties were allocated via kmalloc */
  127. #define OF_DETACHED 2 /* node has been detached from the device tree */
  128. #define OF_POPULATED 3 /* device already created for the node */
  129. #define OF_POPULATED_BUS 4 /* of_platform_populate recursed to children of this node */
  130. #define OF_BAD_ADDR ((u64)-1)
  131. #ifdef CONFIG_OF
  132. void of_core_init(void);
  133. static inline bool is_of_node(const struct fwnode_handle *fwnode)
  134. {
  135. return !IS_ERR_OR_NULL(fwnode) && fwnode->ops == &of_fwnode_ops;
  136. }
  137. #define to_of_node(__fwnode) \
  138. ({ \
  139. typeof(__fwnode) __to_of_node_fwnode = (__fwnode); \
  140. \
  141. is_of_node(__to_of_node_fwnode) ? \
  142. container_of(__to_of_node_fwnode, \
  143. struct device_node, fwnode) : \
  144. NULL; \
  145. })
  146. #define of_fwnode_handle(node) \
  147. ({ \
  148. typeof(node) __of_fwnode_handle_node = (node); \
  149. \
  150. __of_fwnode_handle_node ? \
  151. &__of_fwnode_handle_node->fwnode : NULL; \
  152. })
  153. static inline bool of_have_populated_dt(void)
  154. {
  155. return of_root != NULL;
  156. }
  157. static inline bool of_node_is_root(const struct device_node *node)
  158. {
  159. return node && (node->parent == NULL);
  160. }
  161. static inline int of_node_check_flag(struct device_node *n, unsigned long flag)
  162. {
  163. return test_bit(flag, &n->_flags);
  164. }
  165. static inline int of_node_test_and_set_flag(struct device_node *n,
  166. unsigned long flag)
  167. {
  168. return test_and_set_bit(flag, &n->_flags);
  169. }
  170. static inline void of_node_set_flag(struct device_node *n, unsigned long flag)
  171. {
  172. set_bit(flag, &n->_flags);
  173. }
  174. static inline void of_node_clear_flag(struct device_node *n, unsigned long flag)
  175. {
  176. clear_bit(flag, &n->_flags);
  177. }
  178. #if defined(CONFIG_OF_DYNAMIC) || defined(CONFIG_SPARC)
  179. static inline int of_property_check_flag(struct property *p, unsigned long flag)
  180. {
  181. return test_bit(flag, &p->_flags);
  182. }
  183. static inline void of_property_set_flag(struct property *p, unsigned long flag)
  184. {
  185. set_bit(flag, &p->_flags);
  186. }
  187. static inline void of_property_clear_flag(struct property *p, unsigned long flag)
  188. {
  189. clear_bit(flag, &p->_flags);
  190. }
  191. #endif
  192. extern struct device_node *__of_find_all_nodes(struct device_node *prev);
  193. extern struct device_node *of_find_all_nodes(struct device_node *prev);
  194. /*
  195. * OF address retrieval & translation
  196. */
  197. /* Helper to read a big number; size is in cells (not bytes) */
  198. static inline u64 of_read_number(const __be32 *cell, int size)
  199. {
  200. u64 r = 0;
  201. while (size--)
  202. r = (r << 32) | be32_to_cpu(*(cell++));
  203. return r;
  204. }
  205. /* Like of_read_number, but we want an unsigned long result */
  206. static inline unsigned long of_read_ulong(const __be32 *cell, int size)
  207. {
  208. /* toss away upper bits if unsigned long is smaller than u64 */
  209. return of_read_number(cell, size);
  210. }
  211. #if defined(CONFIG_SPARC)
  212. #include <asm/prom.h>
  213. #endif
  214. #define OF_IS_DYNAMIC(x) test_bit(OF_DYNAMIC, &x->_flags)
  215. #define OF_MARK_DYNAMIC(x) set_bit(OF_DYNAMIC, &x->_flags)
  216. extern bool of_node_name_eq(const struct device_node *np, const char *name);
  217. extern bool of_node_name_prefix(const struct device_node *np, const char *prefix);
  218. static inline const char *of_node_full_name(const struct device_node *np)
  219. {
  220. return np ? np->full_name : "<no-node>";
  221. }
  222. #define for_each_of_allnodes_from(from, dn) \
  223. for (dn = __of_find_all_nodes(from); dn; dn = __of_find_all_nodes(dn))
  224. #define for_each_of_allnodes(dn) for_each_of_allnodes_from(NULL, dn)
  225. extern struct device_node *of_find_node_by_name(struct device_node *from,
  226. const char *name);
  227. extern struct device_node *of_find_node_by_type(struct device_node *from,
  228. const char *type);
  229. extern struct device_node *of_find_compatible_node(struct device_node *from,
  230. const char *type, const char *compat);
  231. extern struct device_node *of_find_matching_node_and_match(
  232. struct device_node *from,
  233. const struct of_device_id *matches,
  234. const struct of_device_id **match);
  235. extern struct device_node *of_find_node_opts_by_path(const char *path,
  236. const char **opts);
  237. static inline struct device_node *of_find_node_by_path(const char *path)
  238. {
  239. return of_find_node_opts_by_path(path, NULL);
  240. }
  241. extern struct device_node *of_find_node_by_phandle(phandle handle);
  242. extern struct device_node *of_get_parent(const struct device_node *node);
  243. extern struct device_node *of_get_next_parent(struct device_node *node);
  244. extern struct device_node *of_get_next_child(const struct device_node *node,
  245. struct device_node *prev);
  246. extern struct device_node *of_get_next_available_child(
  247. const struct device_node *node, struct device_node *prev);
  248. extern struct device_node *of_get_compatible_child(const struct device_node *parent,
  249. const char *compatible);
  250. extern struct device_node *of_get_child_by_name(const struct device_node *node,
  251. const char *name);
  252. /* cache lookup */
  253. extern struct device_node *of_find_next_cache_node(const struct device_node *);
  254. extern int of_find_last_cache_level(unsigned int cpu);
  255. extern struct device_node *of_find_node_with_property(
  256. struct device_node *from, const char *prop_name);
  257. extern struct property *of_find_property(const struct device_node *np,
  258. const char *name,
  259. int *lenp);
  260. extern int of_property_count_elems_of_size(const struct device_node *np,
  261. const char *propname, int elem_size);
  262. extern int of_property_read_u32_index(const struct device_node *np,
  263. const char *propname,
  264. u32 index, u32 *out_value);
  265. extern int of_property_read_u64_index(const struct device_node *np,
  266. const char *propname,
  267. u32 index, u64 *out_value);
  268. extern int of_property_read_variable_u8_array(const struct device_node *np,
  269. const char *propname, u8 *out_values,
  270. size_t sz_min, size_t sz_max);
  271. extern int of_property_read_variable_u16_array(const struct device_node *np,
  272. const char *propname, u16 *out_values,
  273. size_t sz_min, size_t sz_max);
  274. extern int of_property_read_variable_u32_array(const struct device_node *np,
  275. const char *propname,
  276. u32 *out_values,
  277. size_t sz_min,
  278. size_t sz_max);
  279. extern int of_property_read_u64(const struct device_node *np,
  280. const char *propname, u64 *out_value);
  281. extern int of_property_read_variable_u64_array(const struct device_node *np,
  282. const char *propname,
  283. u64 *out_values,
  284. size_t sz_min,
  285. size_t sz_max);
  286. extern int of_property_read_string(const struct device_node *np,
  287. const char *propname,
  288. const char **out_string);
  289. extern int of_property_match_string(const struct device_node *np,
  290. const char *propname,
  291. const char *string);
  292. extern int of_property_read_string_helper(const struct device_node *np,
  293. const char *propname,
  294. const char **out_strs, size_t sz, int index);
  295. extern int of_device_is_compatible(const struct device_node *device,
  296. const char *);
  297. extern int of_device_compatible_match(struct device_node *device,
  298. const char *const *compat);
  299. extern bool of_device_is_available(const struct device_node *device);
  300. extern bool of_device_is_big_endian(const struct device_node *device);
  301. extern const void *of_get_property(const struct device_node *node,
  302. const char *name,
  303. int *lenp);
  304. extern struct device_node *of_get_cpu_node(int cpu, unsigned int *thread);
  305. extern struct device_node *of_get_next_cpu_node(struct device_node *prev);
  306. #define for_each_property_of_node(dn, pp) \
  307. for (pp = dn->properties; pp != NULL; pp = pp->next)
  308. extern int of_n_addr_cells(struct device_node *np);
  309. extern int of_n_size_cells(struct device_node *np);
  310. extern const struct of_device_id *of_match_node(
  311. const struct of_device_id *matches, const struct device_node *node);
  312. extern int of_modalias_node(struct device_node *node, char *modalias, int len);
  313. extern void of_print_phandle_args(const char *msg, const struct of_phandle_args *args);
  314. extern struct device_node *of_parse_phandle(const struct device_node *np,
  315. const char *phandle_name,
  316. int index);
  317. extern int of_parse_phandle_with_args(const struct device_node *np,
  318. const char *list_name, const char *cells_name, int index,
  319. struct of_phandle_args *out_args);
  320. extern int of_parse_phandle_with_args_map(const struct device_node *np,
  321. const char *list_name, const char *stem_name, int index,
  322. struct of_phandle_args *out_args);
  323. extern int of_parse_phandle_with_fixed_args(const struct device_node *np,
  324. const char *list_name, int cells_count, int index,
  325. struct of_phandle_args *out_args);
  326. extern int of_count_phandle_with_args(const struct device_node *np,
  327. const char *list_name, const char *cells_name);
  328. /* phandle iterator functions */
  329. extern int of_phandle_iterator_init(struct of_phandle_iterator *it,
  330. const struct device_node *np,
  331. const char *list_name,
  332. const char *cells_name,
  333. int cell_count);
  334. extern int of_phandle_iterator_next(struct of_phandle_iterator *it);
  335. extern int of_phandle_iterator_args(struct of_phandle_iterator *it,
  336. uint32_t *args,
  337. int size);
  338. extern void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align));
  339. extern int of_alias_get_id(struct device_node *np, const char *stem);
  340. extern int of_alias_get_highest_id(const char *stem);
  341. extern int of_machine_is_compatible(const char *compat);
  342. extern int of_add_property(struct device_node *np, struct property *prop);
  343. extern int of_remove_property(struct device_node *np, struct property *prop);
  344. extern int of_update_property(struct device_node *np, struct property *newprop);
  345. /* For updating the device tree at runtime */
  346. #define OF_RECONFIG_ATTACH_NODE 0x0001
  347. #define OF_RECONFIG_DETACH_NODE 0x0002
  348. #define OF_RECONFIG_ADD_PROPERTY 0x0003
  349. #define OF_RECONFIG_REMOVE_PROPERTY 0x0004
  350. #define OF_RECONFIG_UPDATE_PROPERTY 0x0005
  351. extern int of_attach_node(struct device_node *);
  352. extern int of_detach_node(struct device_node *);
  353. #define of_match_ptr(_ptr) (_ptr)
  354. /**
  355. * of_property_read_u8_array - Find and read an array of u8 from a property.
  356. *
  357. * @np: device node from which the property value is to be read.
  358. * @propname: name of the property to be searched.
  359. * @out_values: pointer to return value, modified only if return value is 0.
  360. * @sz: number of array elements to read
  361. *
  362. * Search for a property in a device node and read 8-bit value(s) from
  363. * it. Returns 0 on success, -EINVAL if the property does not exist,
  364. * -ENODATA if property does not have a value, and -EOVERFLOW if the
  365. * property data isn't large enough.
  366. *
  367. * dts entry of array should be like:
  368. * property = /bits/ 8 <0x50 0x60 0x70>;
  369. *
  370. * The out_values is modified only if a valid u8 value can be decoded.
  371. */
  372. static inline int of_property_read_u8_array(const struct device_node *np,
  373. const char *propname,
  374. u8 *out_values, size_t sz)
  375. {
  376. int ret = of_property_read_variable_u8_array(np, propname, out_values,
  377. sz, 0);
  378. if (ret >= 0)
  379. return 0;
  380. else
  381. return ret;
  382. }
  383. /**
  384. * of_property_read_u16_array - Find and read an array of u16 from a property.
  385. *
  386. * @np: device node from which the property value is to be read.
  387. * @propname: name of the property to be searched.
  388. * @out_values: pointer to return value, modified only if return value is 0.
  389. * @sz: number of array elements to read
  390. *
  391. * Search for a property in a device node and read 16-bit value(s) from
  392. * it. Returns 0 on success, -EINVAL if the property does not exist,
  393. * -ENODATA if property does not have a value, and -EOVERFLOW if the
  394. * property data isn't large enough.
  395. *
  396. * dts entry of array should be like:
  397. * property = /bits/ 16 <0x5000 0x6000 0x7000>;
  398. *
  399. * The out_values is modified only if a valid u16 value can be decoded.
  400. */
  401. static inline int of_property_read_u16_array(const struct device_node *np,
  402. const char *propname,
  403. u16 *out_values, size_t sz)
  404. {
  405. int ret = of_property_read_variable_u16_array(np, propname, out_values,
  406. sz, 0);
  407. if (ret >= 0)
  408. return 0;
  409. else
  410. return ret;
  411. }
  412. /**
  413. * of_property_read_u32_array - Find and read an array of 32 bit integers
  414. * from a property.
  415. *
  416. * @np: device node from which the property value is to be read.
  417. * @propname: name of the property to be searched.
  418. * @out_values: pointer to return value, modified only if return value is 0.
  419. * @sz: number of array elements to read
  420. *
  421. * Search for a property in a device node and read 32-bit value(s) from
  422. * it. Returns 0 on success, -EINVAL if the property does not exist,
  423. * -ENODATA if property does not have a value, and -EOVERFLOW if the
  424. * property data isn't large enough.
  425. *
  426. * The out_values is modified only if a valid u32 value can be decoded.
  427. */
  428. static inline int of_property_read_u32_array(const struct device_node *np,
  429. const char *propname,
  430. u32 *out_values, size_t sz)
  431. {
  432. int ret = of_property_read_variable_u32_array(np, propname, out_values,
  433. sz, 0);
  434. if (ret >= 0)
  435. return 0;
  436. else
  437. return ret;
  438. }
  439. /**
  440. * of_property_read_u64_array - Find and read an array of 64 bit integers
  441. * from a property.
  442. *
  443. * @np: device node from which the property value is to be read.
  444. * @propname: name of the property to be searched.
  445. * @out_values: pointer to return value, modified only if return value is 0.
  446. * @sz: number of array elements to read
  447. *
  448. * Search for a property in a device node and read 64-bit value(s) from
  449. * it. Returns 0 on success, -EINVAL if the property does not exist,
  450. * -ENODATA if property does not have a value, and -EOVERFLOW if the
  451. * property data isn't large enough.
  452. *
  453. * The out_values is modified only if a valid u64 value can be decoded.
  454. */
  455. static inline int of_property_read_u64_array(const struct device_node *np,
  456. const char *propname,
  457. u64 *out_values, size_t sz)
  458. {
  459. int ret = of_property_read_variable_u64_array(np, propname, out_values,
  460. sz, 0);
  461. if (ret >= 0)
  462. return 0;
  463. else
  464. return ret;
  465. }
  466. /*
  467. * struct property *prop;
  468. * const __be32 *p;
  469. * u32 u;
  470. *
  471. * of_property_for_each_u32(np, "propname", prop, p, u)
  472. * printk("U32 value: %x\n", u);
  473. */
  474. const __be32 *of_prop_next_u32(struct property *prop, const __be32 *cur,
  475. u32 *pu);
  476. /*
  477. * struct property *prop;
  478. * const char *s;
  479. *
  480. * of_property_for_each_string(np, "propname", prop, s)
  481. * printk("String value: %s\n", s);
  482. */
  483. const char *of_prop_next_string(struct property *prop, const char *cur);
  484. bool of_console_check(struct device_node *dn, char *name, int index);
  485. extern int of_cpu_node_to_id(struct device_node *np);
  486. #else /* CONFIG_OF */
  487. static inline void of_core_init(void)
  488. {
  489. }
  490. static inline bool is_of_node(const struct fwnode_handle *fwnode)
  491. {
  492. return false;
  493. }
  494. static inline struct device_node *to_of_node(const struct fwnode_handle *fwnode)
  495. {
  496. return NULL;
  497. }
  498. static inline bool of_node_name_eq(const struct device_node *np, const char *name)
  499. {
  500. return false;
  501. }
  502. static inline bool of_node_name_prefix(const struct device_node *np, const char *prefix)
  503. {
  504. return false;
  505. }
  506. static inline const char* of_node_full_name(const struct device_node *np)
  507. {
  508. return "<no-node>";
  509. }
  510. static inline struct device_node *of_find_node_by_name(struct device_node *from,
  511. const char *name)
  512. {
  513. return NULL;
  514. }
  515. static inline struct device_node *of_find_node_by_type(struct device_node *from,
  516. const char *type)
  517. {
  518. return NULL;
  519. }
  520. static inline struct device_node *of_find_matching_node_and_match(
  521. struct device_node *from,
  522. const struct of_device_id *matches,
  523. const struct of_device_id **match)
  524. {
  525. return NULL;
  526. }
  527. static inline struct device_node *of_find_node_by_path(const char *path)
  528. {
  529. return NULL;
  530. }
  531. static inline struct device_node *of_find_node_opts_by_path(const char *path,
  532. const char **opts)
  533. {
  534. return NULL;
  535. }
  536. static inline struct device_node *of_find_node_by_phandle(phandle handle)
  537. {
  538. return NULL;
  539. }
  540. static inline struct device_node *of_get_parent(const struct device_node *node)
  541. {
  542. return NULL;
  543. }
  544. static inline struct device_node *of_get_next_child(
  545. const struct device_node *node, struct device_node *prev)
  546. {
  547. return NULL;
  548. }
  549. static inline struct device_node *of_get_next_available_child(
  550. const struct device_node *node, struct device_node *prev)
  551. {
  552. return NULL;
  553. }
  554. static inline struct device_node *of_find_node_with_property(
  555. struct device_node *from, const char *prop_name)
  556. {
  557. return NULL;
  558. }
  559. #define of_fwnode_handle(node) NULL
  560. static inline bool of_have_populated_dt(void)
  561. {
  562. return false;
  563. }
  564. static inline struct device_node *of_get_compatible_child(const struct device_node *parent,
  565. const char *compatible)
  566. {
  567. return NULL;
  568. }
  569. static inline struct device_node *of_get_child_by_name(
  570. const struct device_node *node,
  571. const char *name)
  572. {
  573. return NULL;
  574. }
  575. static inline int of_device_is_compatible(const struct device_node *device,
  576. const char *name)
  577. {
  578. return 0;
  579. }
  580. static inline int of_device_compatible_match(struct device_node *device,
  581. const char *const *compat)
  582. {
  583. return 0;
  584. }
  585. static inline bool of_device_is_available(const struct device_node *device)
  586. {
  587. return false;
  588. }
  589. static inline bool of_device_is_big_endian(const struct device_node *device)
  590. {
  591. return false;
  592. }
  593. static inline struct property *of_find_property(const struct device_node *np,
  594. const char *name,
  595. int *lenp)
  596. {
  597. return NULL;
  598. }
  599. static inline struct device_node *of_find_compatible_node(
  600. struct device_node *from,
  601. const char *type,
  602. const char *compat)
  603. {
  604. return NULL;
  605. }
  606. static inline int of_property_count_elems_of_size(const struct device_node *np,
  607. const char *propname, int elem_size)
  608. {
  609. return -ENOSYS;
  610. }
  611. static inline int of_property_read_u8_array(const struct device_node *np,
  612. const char *propname, u8 *out_values, size_t sz)
  613. {
  614. return -ENOSYS;
  615. }
  616. static inline int of_property_read_u16_array(const struct device_node *np,
  617. const char *propname, u16 *out_values, size_t sz)
  618. {
  619. return -ENOSYS;
  620. }
  621. static inline int of_property_read_u32_array(const struct device_node *np,
  622. const char *propname,
  623. u32 *out_values, size_t sz)
  624. {
  625. return -ENOSYS;
  626. }
  627. static inline int of_property_read_u64_array(const struct device_node *np,
  628. const char *propname,
  629. u64 *out_values, size_t sz)
  630. {
  631. return -ENOSYS;
  632. }
  633. static inline int of_property_read_u32_index(const struct device_node *np,
  634. const char *propname, u32 index, u32 *out_value)
  635. {
  636. return -ENOSYS;
  637. }
  638. static inline int of_property_read_u64_index(const struct device_node *np,
  639. const char *propname, u32 index, u64 *out_value)
  640. {
  641. return -ENOSYS;
  642. }
  643. static inline const void *of_get_property(const struct device_node *node,
  644. const char *name,
  645. int *lenp)
  646. {
  647. return NULL;
  648. }
  649. static inline struct device_node *of_get_cpu_node(int cpu,
  650. unsigned int *thread)
  651. {
  652. return NULL;
  653. }
  654. static inline struct device_node *of_get_next_cpu_node(struct device_node *prev)
  655. {
  656. return NULL;
  657. }
  658. static inline int of_n_addr_cells(struct device_node *np)
  659. {
  660. return 0;
  661. }
  662. static inline int of_n_size_cells(struct device_node *np)
  663. {
  664. return 0;
  665. }
  666. static inline int of_property_read_variable_u8_array(const struct device_node *np,
  667. const char *propname, u8 *out_values,
  668. size_t sz_min, size_t sz_max)
  669. {
  670. return -ENOSYS;
  671. }
  672. static inline int of_property_read_variable_u16_array(const struct device_node *np,
  673. const char *propname, u16 *out_values,
  674. size_t sz_min, size_t sz_max)
  675. {
  676. return -ENOSYS;
  677. }
  678. static inline int of_property_read_variable_u32_array(const struct device_node *np,
  679. const char *propname,
  680. u32 *out_values,
  681. size_t sz_min,
  682. size_t sz_max)
  683. {
  684. return -ENOSYS;
  685. }
  686. static inline int of_property_read_u64(const struct device_node *np,
  687. const char *propname, u64 *out_value)
  688. {
  689. return -ENOSYS;
  690. }
  691. static inline int of_property_read_variable_u64_array(const struct device_node *np,
  692. const char *propname,
  693. u64 *out_values,
  694. size_t sz_min,
  695. size_t sz_max)
  696. {
  697. return -ENOSYS;
  698. }
  699. static inline int of_property_read_string(const struct device_node *np,
  700. const char *propname,
  701. const char **out_string)
  702. {
  703. return -ENOSYS;
  704. }
  705. static inline int of_property_match_string(const struct device_node *np,
  706. const char *propname,
  707. const char *string)
  708. {
  709. return -ENOSYS;
  710. }
  711. static inline int of_property_read_string_helper(const struct device_node *np,
  712. const char *propname,
  713. const char **out_strs, size_t sz, int index)
  714. {
  715. return -ENOSYS;
  716. }
  717. static inline struct device_node *of_parse_phandle(const struct device_node *np,
  718. const char *phandle_name,
  719. int index)
  720. {
  721. return NULL;
  722. }
  723. static inline int of_parse_phandle_with_args(const struct device_node *np,
  724. const char *list_name,
  725. const char *cells_name,
  726. int index,
  727. struct of_phandle_args *out_args)
  728. {
  729. return -ENOSYS;
  730. }
  731. static inline int of_parse_phandle_with_args_map(const struct device_node *np,
  732. const char *list_name,
  733. const char *stem_name,
  734. int index,
  735. struct of_phandle_args *out_args)
  736. {
  737. return -ENOSYS;
  738. }
  739. static inline int of_parse_phandle_with_fixed_args(const struct device_node *np,
  740. const char *list_name, int cells_count, int index,
  741. struct of_phandle_args *out_args)
  742. {
  743. return -ENOSYS;
  744. }
  745. static inline int of_count_phandle_with_args(struct device_node *np,
  746. const char *list_name,
  747. const char *cells_name)
  748. {
  749. return -ENOSYS;
  750. }
  751. static inline int of_phandle_iterator_init(struct of_phandle_iterator *it,
  752. const struct device_node *np,
  753. const char *list_name,
  754. const char *cells_name,
  755. int cell_count)
  756. {
  757. return -ENOSYS;
  758. }
  759. static inline int of_phandle_iterator_next(struct of_phandle_iterator *it)
  760. {
  761. return -ENOSYS;
  762. }
  763. static inline int of_phandle_iterator_args(struct of_phandle_iterator *it,
  764. uint32_t *args,
  765. int size)
  766. {
  767. return 0;
  768. }
  769. static inline int of_alias_get_id(struct device_node *np, const char *stem)
  770. {
  771. return -ENOSYS;
  772. }
  773. static inline int of_alias_get_highest_id(const char *stem)
  774. {
  775. return -ENOSYS;
  776. }
  777. static inline int of_machine_is_compatible(const char *compat)
  778. {
  779. return 0;
  780. }
  781. static inline bool of_console_check(const struct device_node *dn, const char *name, int index)
  782. {
  783. return false;
  784. }
  785. static inline const __be32 *of_prop_next_u32(struct property *prop,
  786. const __be32 *cur, u32 *pu)
  787. {
  788. return NULL;
  789. }
  790. static inline const char *of_prop_next_string(struct property *prop,
  791. const char *cur)
  792. {
  793. return NULL;
  794. }
  795. static inline int of_node_check_flag(struct device_node *n, unsigned long flag)
  796. {
  797. return 0;
  798. }
  799. static inline int of_node_test_and_set_flag(struct device_node *n,
  800. unsigned long flag)
  801. {
  802. return 0;
  803. }
  804. static inline void of_node_set_flag(struct device_node *n, unsigned long flag)
  805. {
  806. }
  807. static inline void of_node_clear_flag(struct device_node *n, unsigned long flag)
  808. {
  809. }
  810. static inline int of_property_check_flag(struct property *p, unsigned long flag)
  811. {
  812. return 0;
  813. }
  814. static inline void of_property_set_flag(struct property *p, unsigned long flag)
  815. {
  816. }
  817. static inline void of_property_clear_flag(struct property *p, unsigned long flag)
  818. {
  819. }
  820. static inline int of_cpu_node_to_id(struct device_node *np)
  821. {
  822. return -ENODEV;
  823. }
  824. #define of_match_ptr(_ptr) NULL
  825. #define of_match_node(_matches, _node) NULL
  826. #endif /* CONFIG_OF */
  827. /* Default string compare functions, Allow arch asm/prom.h to override */
  828. #if !defined(of_compat_cmp)
  829. #define of_compat_cmp(s1, s2, l) strcasecmp((s1), (s2))
  830. #define of_prop_cmp(s1, s2) strcmp((s1), (s2))
  831. #define of_node_cmp(s1, s2) strcasecmp((s1), (s2))
  832. #endif
  833. #if defined(CONFIG_OF) && defined(CONFIG_NUMA)
  834. extern int of_node_to_nid(struct device_node *np);
  835. #else
  836. static inline int of_node_to_nid(struct device_node *device)
  837. {
  838. return NUMA_NO_NODE;
  839. }
  840. #endif
  841. #ifdef CONFIG_OF_NUMA
  842. extern int of_numa_init(void);
  843. #else
  844. static inline int of_numa_init(void)
  845. {
  846. return -ENOSYS;
  847. }
  848. #endif
  849. static inline struct device_node *of_find_matching_node(
  850. struct device_node *from,
  851. const struct of_device_id *matches)
  852. {
  853. return of_find_matching_node_and_match(from, matches, NULL);
  854. }
  855. static inline const char *of_node_get_device_type(const struct device_node *np)
  856. {
  857. return of_get_property(np, "device_type", NULL);
  858. }
  859. static inline bool of_node_is_type(const struct device_node *np, const char *type)
  860. {
  861. const char *match = of_node_get_device_type(np);
  862. return np && match && type && !strcmp(match, type);
  863. }
  864. /**
  865. * of_property_count_u8_elems - Count the number of u8 elements in a property
  866. *
  867. * @np: device node from which the property value is to be read.
  868. * @propname: name of the property to be searched.
  869. *
  870. * Search for a property in a device node and count the number of u8 elements
  871. * in it. Returns number of elements on sucess, -EINVAL if the property does
  872. * not exist or its length does not match a multiple of u8 and -ENODATA if the
  873. * property does not have a value.
  874. */
  875. static inline int of_property_count_u8_elems(const struct device_node *np,
  876. const char *propname)
  877. {
  878. return of_property_count_elems_of_size(np, propname, sizeof(u8));
  879. }
  880. /**
  881. * of_property_count_u16_elems - Count the number of u16 elements in a property
  882. *
  883. * @np: device node from which the property value is to be read.
  884. * @propname: name of the property to be searched.
  885. *
  886. * Search for a property in a device node and count the number of u16 elements
  887. * in it. Returns number of elements on sucess, -EINVAL if the property does
  888. * not exist or its length does not match a multiple of u16 and -ENODATA if the
  889. * property does not have a value.
  890. */
  891. static inline int of_property_count_u16_elems(const struct device_node *np,
  892. const char *propname)
  893. {
  894. return of_property_count_elems_of_size(np, propname, sizeof(u16));
  895. }
  896. /**
  897. * of_property_count_u32_elems - Count the number of u32 elements in a property
  898. *
  899. * @np: device node from which the property value is to be read.
  900. * @propname: name of the property to be searched.
  901. *
  902. * Search for a property in a device node and count the number of u32 elements
  903. * in it. Returns number of elements on sucess, -EINVAL if the property does
  904. * not exist or its length does not match a multiple of u32 and -ENODATA if the
  905. * property does not have a value.
  906. */
  907. static inline int of_property_count_u32_elems(const struct device_node *np,
  908. const char *propname)
  909. {
  910. return of_property_count_elems_of_size(np, propname, sizeof(u32));
  911. }
  912. /**
  913. * of_property_count_u64_elems - Count the number of u64 elements in a property
  914. *
  915. * @np: device node from which the property value is to be read.
  916. * @propname: name of the property to be searched.
  917. *
  918. * Search for a property in a device node and count the number of u64 elements
  919. * in it. Returns number of elements on sucess, -EINVAL if the property does
  920. * not exist or its length does not match a multiple of u64 and -ENODATA if the
  921. * property does not have a value.
  922. */
  923. static inline int of_property_count_u64_elems(const struct device_node *np,
  924. const char *propname)
  925. {
  926. return of_property_count_elems_of_size(np, propname, sizeof(u64));
  927. }
  928. /**
  929. * of_property_read_string_array() - Read an array of strings from a multiple
  930. * strings property.
  931. * @np: device node from which the property value is to be read.
  932. * @propname: name of the property to be searched.
  933. * @out_strs: output array of string pointers.
  934. * @sz: number of array elements to read.
  935. *
  936. * Search for a property in a device tree node and retrieve a list of
  937. * terminated string values (pointer to data, not a copy) in that property.
  938. *
  939. * If @out_strs is NULL, the number of strings in the property is returned.
  940. */
  941. static inline int of_property_read_string_array(const struct device_node *np,
  942. const char *propname, const char **out_strs,
  943. size_t sz)
  944. {
  945. return of_property_read_string_helper(np, propname, out_strs, sz, 0);
  946. }
  947. /**
  948. * of_property_count_strings() - Find and return the number of strings from a
  949. * multiple strings property.
  950. * @np: device node from which the property value is to be read.
  951. * @propname: name of the property to be searched.
  952. *
  953. * Search for a property in a device tree node and retrieve the number of null
  954. * terminated string contain in it. Returns the number of strings on
  955. * success, -EINVAL if the property does not exist, -ENODATA if property
  956. * does not have a value, and -EILSEQ if the string is not null-terminated
  957. * within the length of the property data.
  958. */
  959. static inline int of_property_count_strings(const struct device_node *np,
  960. const char *propname)
  961. {
  962. return of_property_read_string_helper(np, propname, NULL, 0, 0);
  963. }
  964. /**
  965. * of_property_read_string_index() - Find and read a string from a multiple
  966. * strings property.
  967. * @np: device node from which the property value is to be read.
  968. * @propname: name of the property to be searched.
  969. * @index: index of the string in the list of strings
  970. * @out_string: pointer to null terminated return string, modified only if
  971. * return value is 0.
  972. *
  973. * Search for a property in a device tree node and retrieve a null
  974. * terminated string value (pointer to data, not a copy) in the list of strings
  975. * contained in that property.
  976. * Returns 0 on success, -EINVAL if the property does not exist, -ENODATA if
  977. * property does not have a value, and -EILSEQ if the string is not
  978. * null-terminated within the length of the property data.
  979. *
  980. * The out_string pointer is modified only if a valid string can be decoded.
  981. */
  982. static inline int of_property_read_string_index(const struct device_node *np,
  983. const char *propname,
  984. int index, const char **output)
  985. {
  986. int rc = of_property_read_string_helper(np, propname, output, 1, index);
  987. return rc < 0 ? rc : 0;
  988. }
  989. /**
  990. * of_property_read_bool - Findfrom a property
  991. * @np: device node from which the property value is to be read.
  992. * @propname: name of the property to be searched.
  993. *
  994. * Search for a property in a device node.
  995. * Returns true if the property exists false otherwise.
  996. */
  997. static inline bool of_property_read_bool(const struct device_node *np,
  998. const char *propname)
  999. {
  1000. struct property *prop = of_find_property(np, propname, NULL);
  1001. return prop ? true : false;
  1002. }
  1003. static inline int of_property_read_u8(const struct device_node *np,
  1004. const char *propname,
  1005. u8 *out_value)
  1006. {
  1007. return of_property_read_u8_array(np, propname, out_value, 1);
  1008. }
  1009. static inline int of_property_read_u16(const struct device_node *np,
  1010. const char *propname,
  1011. u16 *out_value)
  1012. {
  1013. return of_property_read_u16_array(np, propname, out_value, 1);
  1014. }
  1015. static inline int of_property_read_u32(const struct device_node *np,
  1016. const char *propname,
  1017. u32 *out_value)
  1018. {
  1019. return of_property_read_u32_array(np, propname, out_value, 1);
  1020. }
  1021. static inline int of_property_read_s32(const struct device_node *np,
  1022. const char *propname,
  1023. s32 *out_value)
  1024. {
  1025. return of_property_read_u32(np, propname, (u32*) out_value);
  1026. }
  1027. #define of_for_each_phandle(it, err, np, ln, cn, cc) \
  1028. for (of_phandle_iterator_init((it), (np), (ln), (cn), (cc)), \
  1029. err = of_phandle_iterator_next(it); \
  1030. err == 0; \
  1031. err = of_phandle_iterator_next(it))
  1032. #define of_property_for_each_u32(np, propname, prop, p, u) \
  1033. for (prop = of_find_property(np, propname, NULL), \
  1034. p = of_prop_next_u32(prop, NULL, &u); \
  1035. p; \
  1036. p = of_prop_next_u32(prop, p, &u))
  1037. #define of_property_for_each_string(np, propname, prop, s) \
  1038. for (prop = of_find_property(np, propname, NULL), \
  1039. s = of_prop_next_string(prop, NULL); \
  1040. s; \
  1041. s = of_prop_next_string(prop, s))
  1042. #define for_each_node_by_name(dn, name) \
  1043. for (dn = of_find_node_by_name(NULL, name); dn; \
  1044. dn = of_find_node_by_name(dn, name))
  1045. #define for_each_node_by_type(dn, type) \
  1046. for (dn = of_find_node_by_type(NULL, type); dn; \
  1047. dn = of_find_node_by_type(dn, type))
  1048. #define for_each_compatible_node(dn, type, compatible) \
  1049. for (dn = of_find_compatible_node(NULL, type, compatible); dn; \
  1050. dn = of_find_compatible_node(dn, type, compatible))
  1051. #define for_each_matching_node(dn, matches) \
  1052. for (dn = of_find_matching_node(NULL, matches); dn; \
  1053. dn = of_find_matching_node(dn, matches))
  1054. #define for_each_matching_node_and_match(dn, matches, match) \
  1055. for (dn = of_find_matching_node_and_match(NULL, matches, match); \
  1056. dn; dn = of_find_matching_node_and_match(dn, matches, match))
  1057. #define for_each_child_of_node(parent, child) \
  1058. for (child = of_get_next_child(parent, NULL); child != NULL; \
  1059. child = of_get_next_child(parent, child))
  1060. #define for_each_available_child_of_node(parent, child) \
  1061. for (child = of_get_next_available_child(parent, NULL); child != NULL; \
  1062. child = of_get_next_available_child(parent, child))
  1063. #define for_each_of_cpu_node(cpu) \
  1064. for (cpu = of_get_next_cpu_node(NULL); cpu != NULL; \
  1065. cpu = of_get_next_cpu_node(cpu))
  1066. #define for_each_node_with_property(dn, prop_name) \
  1067. for (dn = of_find_node_with_property(NULL, prop_name); dn; \
  1068. dn = of_find_node_with_property(dn, prop_name))
  1069. static inline int of_get_child_count(const struct device_node *np)
  1070. {
  1071. struct device_node *child;
  1072. int num = 0;
  1073. for_each_child_of_node(np, child)
  1074. num++;
  1075. return num;
  1076. }
  1077. static inline int of_get_available_child_count(const struct device_node *np)
  1078. {
  1079. struct device_node *child;
  1080. int num = 0;
  1081. for_each_available_child_of_node(np, child)
  1082. num++;
  1083. return num;
  1084. }
  1085. #if defined(CONFIG_OF) && !defined(MODULE)
  1086. #define _OF_DECLARE(table, name, compat, fn, fn_type) \
  1087. static const struct of_device_id __of_table_##name \
  1088. __used __section(__##table##_of_table) \
  1089. = { .compatible = compat, \
  1090. .data = (fn == (fn_type)NULL) ? fn : fn }
  1091. #else
  1092. #define _OF_DECLARE(table, name, compat, fn, fn_type) \
  1093. static const struct of_device_id __of_table_##name \
  1094. __attribute__((unused)) \
  1095. = { .compatible = compat, \
  1096. .data = (fn == (fn_type)NULL) ? fn : fn }
  1097. #endif
  1098. typedef int (*of_init_fn_2)(struct device_node *, struct device_node *);
  1099. typedef int (*of_init_fn_1_ret)(struct device_node *);
  1100. typedef void (*of_init_fn_1)(struct device_node *);
  1101. #define OF_DECLARE_1(table, name, compat, fn) \
  1102. _OF_DECLARE(table, name, compat, fn, of_init_fn_1)
  1103. #define OF_DECLARE_1_RET(table, name, compat, fn) \
  1104. _OF_DECLARE(table, name, compat, fn, of_init_fn_1_ret)
  1105. #define OF_DECLARE_2(table, name, compat, fn) \
  1106. _OF_DECLARE(table, name, compat, fn, of_init_fn_2)
  1107. /**
  1108. * struct of_changeset_entry - Holds a changeset entry
  1109. *
  1110. * @node: list_head for the log list
  1111. * @action: notifier action
  1112. * @np: pointer to the device node affected
  1113. * @prop: pointer to the property affected
  1114. * @old_prop: hold a pointer to the original property
  1115. *
  1116. * Every modification of the device tree during a changeset
  1117. * is held in a list of of_changeset_entry structures.
  1118. * That way we can recover from a partial application, or we can
  1119. * revert the changeset
  1120. */
  1121. struct of_changeset_entry {
  1122. struct list_head node;
  1123. unsigned long action;
  1124. struct device_node *np;
  1125. struct property *prop;
  1126. struct property *old_prop;
  1127. };
  1128. /**
  1129. * struct of_changeset - changeset tracker structure
  1130. *
  1131. * @entries: list_head for the changeset entries
  1132. *
  1133. * changesets are a convenient way to apply bulk changes to the
  1134. * live tree. In case of an error, changes are rolled-back.
  1135. * changesets live on after initial application, and if not
  1136. * destroyed after use, they can be reverted in one single call.
  1137. */
  1138. struct of_changeset {
  1139. struct list_head entries;
  1140. };
  1141. enum of_reconfig_change {
  1142. OF_RECONFIG_NO_CHANGE = 0,
  1143. OF_RECONFIG_CHANGE_ADD,
  1144. OF_RECONFIG_CHANGE_REMOVE,
  1145. };
  1146. #ifdef CONFIG_OF_DYNAMIC
  1147. extern int of_reconfig_notifier_register(struct notifier_block *);
  1148. extern int of_reconfig_notifier_unregister(struct notifier_block *);
  1149. extern int of_reconfig_notify(unsigned long, struct of_reconfig_data *rd);
  1150. extern int of_reconfig_get_state_change(unsigned long action,
  1151. struct of_reconfig_data *arg);
  1152. extern void of_changeset_init(struct of_changeset *ocs);
  1153. extern void of_changeset_destroy(struct of_changeset *ocs);
  1154. extern int of_changeset_apply(struct of_changeset *ocs);
  1155. extern int of_changeset_revert(struct of_changeset *ocs);
  1156. extern int of_changeset_action(struct of_changeset *ocs,
  1157. unsigned long action, struct device_node *np,
  1158. struct property *prop);
  1159. static inline int of_changeset_attach_node(struct of_changeset *ocs,
  1160. struct device_node *np)
  1161. {
  1162. return of_changeset_action(ocs, OF_RECONFIG_ATTACH_NODE, np, NULL);
  1163. }
  1164. static inline int of_changeset_detach_node(struct of_changeset *ocs,
  1165. struct device_node *np)
  1166. {
  1167. return of_changeset_action(ocs, OF_RECONFIG_DETACH_NODE, np, NULL);
  1168. }
  1169. static inline int of_changeset_add_property(struct of_changeset *ocs,
  1170. struct device_node *np, struct property *prop)
  1171. {
  1172. return of_changeset_action(ocs, OF_RECONFIG_ADD_PROPERTY, np, prop);
  1173. }
  1174. static inline int of_changeset_remove_property(struct of_changeset *ocs,
  1175. struct device_node *np, struct property *prop)
  1176. {
  1177. return of_changeset_action(ocs, OF_RECONFIG_REMOVE_PROPERTY, np, prop);
  1178. }
  1179. static inline int of_changeset_update_property(struct of_changeset *ocs,
  1180. struct device_node *np, struct property *prop)
  1181. {
  1182. return of_changeset_action(ocs, OF_RECONFIG_UPDATE_PROPERTY, np, prop);
  1183. }
  1184. #else /* CONFIG_OF_DYNAMIC */
  1185. static inline int of_reconfig_notifier_register(struct notifier_block *nb)
  1186. {
  1187. return -EINVAL;
  1188. }
  1189. static inline int of_reconfig_notifier_unregister(struct notifier_block *nb)
  1190. {
  1191. return -EINVAL;
  1192. }
  1193. static inline int of_reconfig_notify(unsigned long action,
  1194. struct of_reconfig_data *arg)
  1195. {
  1196. return -EINVAL;
  1197. }
  1198. static inline int of_reconfig_get_state_change(unsigned long action,
  1199. struct of_reconfig_data *arg)
  1200. {
  1201. return -EINVAL;
  1202. }
  1203. #endif /* CONFIG_OF_DYNAMIC */
  1204. /**
  1205. * of_device_is_system_power_controller - Tells if system-power-controller is found for device_node
  1206. * @np: Pointer to the given device_node
  1207. *
  1208. * return true if present false otherwise
  1209. */
  1210. static inline bool of_device_is_system_power_controller(const struct device_node *np)
  1211. {
  1212. return of_property_read_bool(np, "system-power-controller");
  1213. }
  1214. /**
  1215. * Overlay support
  1216. */
  1217. enum of_overlay_notify_action {
  1218. OF_OVERLAY_PRE_APPLY = 0,
  1219. OF_OVERLAY_POST_APPLY,
  1220. OF_OVERLAY_PRE_REMOVE,
  1221. OF_OVERLAY_POST_REMOVE,
  1222. };
  1223. struct of_overlay_notify_data {
  1224. struct device_node *overlay;
  1225. struct device_node *target;
  1226. };
  1227. #ifdef CONFIG_OF_OVERLAY
  1228. int of_overlay_fdt_apply(const void *overlay_fdt, u32 overlay_fdt_size,
  1229. int *ovcs_id);
  1230. int of_overlay_remove(int *ovcs_id);
  1231. int of_overlay_remove_all(void);
  1232. int of_overlay_notifier_register(struct notifier_block *nb);
  1233. int of_overlay_notifier_unregister(struct notifier_block *nb);
  1234. #else
  1235. static inline int of_overlay_fdt_apply(void *overlay_fdt, int *ovcs_id)
  1236. {
  1237. return -ENOTSUPP;
  1238. }
  1239. static inline int of_overlay_remove(int *ovcs_id)
  1240. {
  1241. return -ENOTSUPP;
  1242. }
  1243. static inline int of_overlay_remove_all(void)
  1244. {
  1245. return -ENOTSUPP;
  1246. }
  1247. static inline int of_overlay_notifier_register(struct notifier_block *nb)
  1248. {
  1249. return 0;
  1250. }
  1251. static inline int of_overlay_notifier_unregister(struct notifier_block *nb)
  1252. {
  1253. return 0;
  1254. }
  1255. #endif
  1256. #endif /* _LINUX_OF_H */