of.h 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470
  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_alias_get_alias_list(const struct of_device_id *matches,
  342. const char *stem, unsigned long *bitmap,
  343. unsigned int nbits);
  344. extern int of_machine_is_compatible(const char *compat);
  345. extern int of_add_property(struct device_node *np, struct property *prop);
  346. extern int of_remove_property(struct device_node *np, struct property *prop);
  347. extern int of_update_property(struct device_node *np, struct property *newprop);
  348. /* For updating the device tree at runtime */
  349. #define OF_RECONFIG_ATTACH_NODE 0x0001
  350. #define OF_RECONFIG_DETACH_NODE 0x0002
  351. #define OF_RECONFIG_ADD_PROPERTY 0x0003
  352. #define OF_RECONFIG_REMOVE_PROPERTY 0x0004
  353. #define OF_RECONFIG_UPDATE_PROPERTY 0x0005
  354. extern int of_attach_node(struct device_node *);
  355. extern int of_detach_node(struct device_node *);
  356. #define of_match_ptr(_ptr) (_ptr)
  357. /**
  358. * of_property_read_u8_array - Find and read an array of u8 from a property.
  359. *
  360. * @np: device node from which the property value is to be read.
  361. * @propname: name of the property to be searched.
  362. * @out_values: pointer to return value, modified only if return value is 0.
  363. * @sz: number of array elements to read
  364. *
  365. * Search for a property in a device node and read 8-bit value(s) from
  366. * it. Returns 0 on success, -EINVAL if the property does not exist,
  367. * -ENODATA if property does not have a value, and -EOVERFLOW if the
  368. * property data isn't large enough.
  369. *
  370. * dts entry of array should be like:
  371. * property = /bits/ 8 <0x50 0x60 0x70>;
  372. *
  373. * The out_values is modified only if a valid u8 value can be decoded.
  374. */
  375. static inline int of_property_read_u8_array(const struct device_node *np,
  376. const char *propname,
  377. u8 *out_values, size_t sz)
  378. {
  379. int ret = of_property_read_variable_u8_array(np, propname, out_values,
  380. sz, 0);
  381. if (ret >= 0)
  382. return 0;
  383. else
  384. return ret;
  385. }
  386. /**
  387. * of_property_read_u16_array - Find and read an array of u16 from a property.
  388. *
  389. * @np: device node from which the property value is to be read.
  390. * @propname: name of the property to be searched.
  391. * @out_values: pointer to return value, modified only if return value is 0.
  392. * @sz: number of array elements to read
  393. *
  394. * Search for a property in a device node and read 16-bit value(s) from
  395. * it. Returns 0 on success, -EINVAL if the property does not exist,
  396. * -ENODATA if property does not have a value, and -EOVERFLOW if the
  397. * property data isn't large enough.
  398. *
  399. * dts entry of array should be like:
  400. * property = /bits/ 16 <0x5000 0x6000 0x7000>;
  401. *
  402. * The out_values is modified only if a valid u16 value can be decoded.
  403. */
  404. static inline int of_property_read_u16_array(const struct device_node *np,
  405. const char *propname,
  406. u16 *out_values, size_t sz)
  407. {
  408. int ret = of_property_read_variable_u16_array(np, propname, out_values,
  409. sz, 0);
  410. if (ret >= 0)
  411. return 0;
  412. else
  413. return ret;
  414. }
  415. /**
  416. * of_property_read_u32_array - Find and read an array of 32 bit integers
  417. * from a property.
  418. *
  419. * @np: device node from which the property value is to be read.
  420. * @propname: name of the property to be searched.
  421. * @out_values: pointer to return value, modified only if return value is 0.
  422. * @sz: number of array elements to read
  423. *
  424. * Search for a property in a device node and read 32-bit value(s) from
  425. * it. Returns 0 on success, -EINVAL if the property does not exist,
  426. * -ENODATA if property does not have a value, and -EOVERFLOW if the
  427. * property data isn't large enough.
  428. *
  429. * The out_values is modified only if a valid u32 value can be decoded.
  430. */
  431. static inline int of_property_read_u32_array(const struct device_node *np,
  432. const char *propname,
  433. u32 *out_values, size_t sz)
  434. {
  435. int ret = of_property_read_variable_u32_array(np, propname, out_values,
  436. sz, 0);
  437. if (ret >= 0)
  438. return 0;
  439. else
  440. return ret;
  441. }
  442. /**
  443. * of_property_read_u64_array - Find and read an array of 64 bit integers
  444. * from a property.
  445. *
  446. * @np: device node from which the property value is to be read.
  447. * @propname: name of the property to be searched.
  448. * @out_values: pointer to return value, modified only if return value is 0.
  449. * @sz: number of array elements to read
  450. *
  451. * Search for a property in a device node and read 64-bit value(s) from
  452. * it. Returns 0 on success, -EINVAL if the property does not exist,
  453. * -ENODATA if property does not have a value, and -EOVERFLOW if the
  454. * property data isn't large enough.
  455. *
  456. * The out_values is modified only if a valid u64 value can be decoded.
  457. */
  458. static inline int of_property_read_u64_array(const struct device_node *np,
  459. const char *propname,
  460. u64 *out_values, size_t sz)
  461. {
  462. int ret = of_property_read_variable_u64_array(np, propname, out_values,
  463. sz, 0);
  464. if (ret >= 0)
  465. return 0;
  466. else
  467. return ret;
  468. }
  469. /*
  470. * struct property *prop;
  471. * const __be32 *p;
  472. * u32 u;
  473. *
  474. * of_property_for_each_u32(np, "propname", prop, p, u)
  475. * printk("U32 value: %x\n", u);
  476. */
  477. const __be32 *of_prop_next_u32(struct property *prop, const __be32 *cur,
  478. u32 *pu);
  479. /*
  480. * struct property *prop;
  481. * const char *s;
  482. *
  483. * of_property_for_each_string(np, "propname", prop, s)
  484. * printk("String value: %s\n", s);
  485. */
  486. const char *of_prop_next_string(struct property *prop, const char *cur);
  487. bool of_console_check(struct device_node *dn, char *name, int index);
  488. extern int of_cpu_node_to_id(struct device_node *np);
  489. int of_map_rid(struct device_node *np, u32 rid,
  490. const char *map_name, const char *map_mask_name,
  491. struct device_node **target, u32 *id_out);
  492. #else /* CONFIG_OF */
  493. static inline void of_core_init(void)
  494. {
  495. }
  496. static inline bool is_of_node(const struct fwnode_handle *fwnode)
  497. {
  498. return false;
  499. }
  500. static inline struct device_node *to_of_node(const struct fwnode_handle *fwnode)
  501. {
  502. return NULL;
  503. }
  504. static inline bool of_node_name_eq(const struct device_node *np, const char *name)
  505. {
  506. return false;
  507. }
  508. static inline bool of_node_name_prefix(const struct device_node *np, const char *prefix)
  509. {
  510. return false;
  511. }
  512. static inline const char* of_node_full_name(const struct device_node *np)
  513. {
  514. return "<no-node>";
  515. }
  516. static inline struct device_node *of_find_node_by_name(struct device_node *from,
  517. const char *name)
  518. {
  519. return NULL;
  520. }
  521. static inline struct device_node *of_find_node_by_type(struct device_node *from,
  522. const char *type)
  523. {
  524. return NULL;
  525. }
  526. static inline struct device_node *of_find_matching_node_and_match(
  527. struct device_node *from,
  528. const struct of_device_id *matches,
  529. const struct of_device_id **match)
  530. {
  531. return NULL;
  532. }
  533. static inline struct device_node *of_find_node_by_path(const char *path)
  534. {
  535. return NULL;
  536. }
  537. static inline struct device_node *of_find_node_opts_by_path(const char *path,
  538. const char **opts)
  539. {
  540. return NULL;
  541. }
  542. static inline struct device_node *of_find_node_by_phandle(phandle handle)
  543. {
  544. return NULL;
  545. }
  546. static inline struct device_node *of_get_parent(const struct device_node *node)
  547. {
  548. return NULL;
  549. }
  550. static inline struct device_node *of_get_next_child(
  551. const struct device_node *node, struct device_node *prev)
  552. {
  553. return NULL;
  554. }
  555. static inline struct device_node *of_get_next_available_child(
  556. const struct device_node *node, struct device_node *prev)
  557. {
  558. return NULL;
  559. }
  560. static inline struct device_node *of_find_node_with_property(
  561. struct device_node *from, const char *prop_name)
  562. {
  563. return NULL;
  564. }
  565. #define of_fwnode_handle(node) NULL
  566. static inline bool of_have_populated_dt(void)
  567. {
  568. return false;
  569. }
  570. static inline struct device_node *of_get_compatible_child(const struct device_node *parent,
  571. const char *compatible)
  572. {
  573. return NULL;
  574. }
  575. static inline struct device_node *of_get_child_by_name(
  576. const struct device_node *node,
  577. const char *name)
  578. {
  579. return NULL;
  580. }
  581. static inline int of_device_is_compatible(const struct device_node *device,
  582. const char *name)
  583. {
  584. return 0;
  585. }
  586. static inline int of_device_compatible_match(struct device_node *device,
  587. const char *const *compat)
  588. {
  589. return 0;
  590. }
  591. static inline bool of_device_is_available(const struct device_node *device)
  592. {
  593. return false;
  594. }
  595. static inline bool of_device_is_big_endian(const struct device_node *device)
  596. {
  597. return false;
  598. }
  599. static inline struct property *of_find_property(const struct device_node *np,
  600. const char *name,
  601. int *lenp)
  602. {
  603. return NULL;
  604. }
  605. static inline struct device_node *of_find_compatible_node(
  606. struct device_node *from,
  607. const char *type,
  608. const char *compat)
  609. {
  610. return NULL;
  611. }
  612. static inline int of_property_count_elems_of_size(const struct device_node *np,
  613. const char *propname, int elem_size)
  614. {
  615. return -ENOSYS;
  616. }
  617. static inline int of_property_read_u8_array(const struct device_node *np,
  618. const char *propname, u8 *out_values, size_t sz)
  619. {
  620. return -ENOSYS;
  621. }
  622. static inline int of_property_read_u16_array(const struct device_node *np,
  623. const char *propname, u16 *out_values, size_t sz)
  624. {
  625. return -ENOSYS;
  626. }
  627. static inline int of_property_read_u32_array(const struct device_node *np,
  628. const char *propname,
  629. u32 *out_values, size_t sz)
  630. {
  631. return -ENOSYS;
  632. }
  633. static inline int of_property_read_u64_array(const struct device_node *np,
  634. const char *propname,
  635. u64 *out_values, size_t sz)
  636. {
  637. return -ENOSYS;
  638. }
  639. static inline int of_property_read_u32_index(const struct device_node *np,
  640. const char *propname, u32 index, u32 *out_value)
  641. {
  642. return -ENOSYS;
  643. }
  644. static inline int of_property_read_u64_index(const struct device_node *np,
  645. const char *propname, u32 index, u64 *out_value)
  646. {
  647. return -ENOSYS;
  648. }
  649. static inline const void *of_get_property(const struct device_node *node,
  650. const char *name,
  651. int *lenp)
  652. {
  653. return NULL;
  654. }
  655. static inline struct device_node *of_get_cpu_node(int cpu,
  656. unsigned int *thread)
  657. {
  658. return NULL;
  659. }
  660. static inline struct device_node *of_get_next_cpu_node(struct device_node *prev)
  661. {
  662. return NULL;
  663. }
  664. static inline int of_n_addr_cells(struct device_node *np)
  665. {
  666. return 0;
  667. }
  668. static inline int of_n_size_cells(struct device_node *np)
  669. {
  670. return 0;
  671. }
  672. static inline int of_property_read_variable_u8_array(const struct device_node *np,
  673. const char *propname, u8 *out_values,
  674. size_t sz_min, size_t sz_max)
  675. {
  676. return -ENOSYS;
  677. }
  678. static inline int of_property_read_variable_u16_array(const struct device_node *np,
  679. const char *propname, u16 *out_values,
  680. size_t sz_min, size_t sz_max)
  681. {
  682. return -ENOSYS;
  683. }
  684. static inline int of_property_read_variable_u32_array(const struct device_node *np,
  685. const char *propname,
  686. u32 *out_values,
  687. size_t sz_min,
  688. size_t sz_max)
  689. {
  690. return -ENOSYS;
  691. }
  692. static inline int of_property_read_u64(const struct device_node *np,
  693. const char *propname, u64 *out_value)
  694. {
  695. return -ENOSYS;
  696. }
  697. static inline int of_property_read_variable_u64_array(const struct device_node *np,
  698. const char *propname,
  699. u64 *out_values,
  700. size_t sz_min,
  701. size_t sz_max)
  702. {
  703. return -ENOSYS;
  704. }
  705. static inline int of_property_read_string(const struct device_node *np,
  706. const char *propname,
  707. const char **out_string)
  708. {
  709. return -ENOSYS;
  710. }
  711. static inline int of_property_match_string(const struct device_node *np,
  712. const char *propname,
  713. const char *string)
  714. {
  715. return -ENOSYS;
  716. }
  717. static inline int of_property_read_string_helper(const struct device_node *np,
  718. const char *propname,
  719. const char **out_strs, size_t sz, int index)
  720. {
  721. return -ENOSYS;
  722. }
  723. static inline struct device_node *of_parse_phandle(const struct device_node *np,
  724. const char *phandle_name,
  725. int index)
  726. {
  727. return NULL;
  728. }
  729. static inline int of_parse_phandle_with_args(const struct device_node *np,
  730. const char *list_name,
  731. const char *cells_name,
  732. int index,
  733. struct of_phandle_args *out_args)
  734. {
  735. return -ENOSYS;
  736. }
  737. static inline int of_parse_phandle_with_args_map(const struct device_node *np,
  738. const char *list_name,
  739. const char *stem_name,
  740. int index,
  741. struct of_phandle_args *out_args)
  742. {
  743. return -ENOSYS;
  744. }
  745. static inline int of_parse_phandle_with_fixed_args(const struct device_node *np,
  746. const char *list_name, int cells_count, int index,
  747. struct of_phandle_args *out_args)
  748. {
  749. return -ENOSYS;
  750. }
  751. static inline int of_count_phandle_with_args(struct device_node *np,
  752. const char *list_name,
  753. const char *cells_name)
  754. {
  755. return -ENOSYS;
  756. }
  757. static inline int of_phandle_iterator_init(struct of_phandle_iterator *it,
  758. const struct device_node *np,
  759. const char *list_name,
  760. const char *cells_name,
  761. int cell_count)
  762. {
  763. return -ENOSYS;
  764. }
  765. static inline int of_phandle_iterator_next(struct of_phandle_iterator *it)
  766. {
  767. return -ENOSYS;
  768. }
  769. static inline int of_phandle_iterator_args(struct of_phandle_iterator *it,
  770. uint32_t *args,
  771. int size)
  772. {
  773. return 0;
  774. }
  775. static inline int of_alias_get_id(struct device_node *np, const char *stem)
  776. {
  777. return -ENOSYS;
  778. }
  779. static inline int of_alias_get_highest_id(const char *stem)
  780. {
  781. return -ENOSYS;
  782. }
  783. static inline int of_alias_get_alias_list(const struct of_device_id *matches,
  784. const char *stem, unsigned long *bitmap,
  785. unsigned int nbits)
  786. {
  787. return -ENOSYS;
  788. }
  789. static inline int of_machine_is_compatible(const char *compat)
  790. {
  791. return 0;
  792. }
  793. static inline bool of_console_check(const struct device_node *dn, const char *name, int index)
  794. {
  795. return false;
  796. }
  797. static inline const __be32 *of_prop_next_u32(struct property *prop,
  798. const __be32 *cur, u32 *pu)
  799. {
  800. return NULL;
  801. }
  802. static inline const char *of_prop_next_string(struct property *prop,
  803. const char *cur)
  804. {
  805. return NULL;
  806. }
  807. static inline int of_node_check_flag(struct device_node *n, unsigned long flag)
  808. {
  809. return 0;
  810. }
  811. static inline int of_node_test_and_set_flag(struct device_node *n,
  812. unsigned long flag)
  813. {
  814. return 0;
  815. }
  816. static inline void of_node_set_flag(struct device_node *n, unsigned long flag)
  817. {
  818. }
  819. static inline void of_node_clear_flag(struct device_node *n, unsigned long flag)
  820. {
  821. }
  822. static inline int of_property_check_flag(struct property *p, unsigned long flag)
  823. {
  824. return 0;
  825. }
  826. static inline void of_property_set_flag(struct property *p, unsigned long flag)
  827. {
  828. }
  829. static inline void of_property_clear_flag(struct property *p, unsigned long flag)
  830. {
  831. }
  832. static inline int of_cpu_node_to_id(struct device_node *np)
  833. {
  834. return -ENODEV;
  835. }
  836. static inline int of_map_rid(struct device_node *np, u32 rid,
  837. const char *map_name, const char *map_mask_name,
  838. struct device_node **target, u32 *id_out)
  839. {
  840. return -EINVAL;
  841. }
  842. #define of_match_ptr(_ptr) NULL
  843. #define of_match_node(_matches, _node) NULL
  844. #endif /* CONFIG_OF */
  845. /* Default string compare functions, Allow arch asm/prom.h to override */
  846. #if !defined(of_compat_cmp)
  847. #define of_compat_cmp(s1, s2, l) strcasecmp((s1), (s2))
  848. #define of_prop_cmp(s1, s2) strcmp((s1), (s2))
  849. #define of_node_cmp(s1, s2) strcasecmp((s1), (s2))
  850. #endif
  851. #if defined(CONFIG_OF) && defined(CONFIG_NUMA)
  852. extern int of_node_to_nid(struct device_node *np);
  853. #else
  854. static inline int of_node_to_nid(struct device_node *device)
  855. {
  856. return NUMA_NO_NODE;
  857. }
  858. #endif
  859. #ifdef CONFIG_OF_NUMA
  860. extern int of_numa_init(void);
  861. #else
  862. static inline int of_numa_init(void)
  863. {
  864. return -ENOSYS;
  865. }
  866. #endif
  867. static inline struct device_node *of_find_matching_node(
  868. struct device_node *from,
  869. const struct of_device_id *matches)
  870. {
  871. return of_find_matching_node_and_match(from, matches, NULL);
  872. }
  873. static inline const char *of_node_get_device_type(const struct device_node *np)
  874. {
  875. return of_get_property(np, "device_type", NULL);
  876. }
  877. static inline bool of_node_is_type(const struct device_node *np, const char *type)
  878. {
  879. const char *match = of_node_get_device_type(np);
  880. return np && match && type && !strcmp(match, type);
  881. }
  882. /**
  883. * of_property_count_u8_elems - Count the number of u8 elements in a property
  884. *
  885. * @np: device node from which the property value is to be read.
  886. * @propname: name of the property to be searched.
  887. *
  888. * Search for a property in a device node and count the number of u8 elements
  889. * in it. Returns number of elements on sucess, -EINVAL if the property does
  890. * not exist or its length does not match a multiple of u8 and -ENODATA if the
  891. * property does not have a value.
  892. */
  893. static inline int of_property_count_u8_elems(const struct device_node *np,
  894. const char *propname)
  895. {
  896. return of_property_count_elems_of_size(np, propname, sizeof(u8));
  897. }
  898. /**
  899. * of_property_count_u16_elems - Count the number of u16 elements in a property
  900. *
  901. * @np: device node from which the property value is to be read.
  902. * @propname: name of the property to be searched.
  903. *
  904. * Search for a property in a device node and count the number of u16 elements
  905. * in it. Returns number of elements on sucess, -EINVAL if the property does
  906. * not exist or its length does not match a multiple of u16 and -ENODATA if the
  907. * property does not have a value.
  908. */
  909. static inline int of_property_count_u16_elems(const struct device_node *np,
  910. const char *propname)
  911. {
  912. return of_property_count_elems_of_size(np, propname, sizeof(u16));
  913. }
  914. /**
  915. * of_property_count_u32_elems - Count the number of u32 elements in a property
  916. *
  917. * @np: device node from which the property value is to be read.
  918. * @propname: name of the property to be searched.
  919. *
  920. * Search for a property in a device node and count the number of u32 elements
  921. * in it. Returns number of elements on sucess, -EINVAL if the property does
  922. * not exist or its length does not match a multiple of u32 and -ENODATA if the
  923. * property does not have a value.
  924. */
  925. static inline int of_property_count_u32_elems(const struct device_node *np,
  926. const char *propname)
  927. {
  928. return of_property_count_elems_of_size(np, propname, sizeof(u32));
  929. }
  930. /**
  931. * of_property_count_u64_elems - Count the number of u64 elements in a property
  932. *
  933. * @np: device node from which the property value is to be read.
  934. * @propname: name of the property to be searched.
  935. *
  936. * Search for a property in a device node and count the number of u64 elements
  937. * in it. Returns number of elements on sucess, -EINVAL if the property does
  938. * not exist or its length does not match a multiple of u64 and -ENODATA if the
  939. * property does not have a value.
  940. */
  941. static inline int of_property_count_u64_elems(const struct device_node *np,
  942. const char *propname)
  943. {
  944. return of_property_count_elems_of_size(np, propname, sizeof(u64));
  945. }
  946. /**
  947. * of_property_read_string_array() - Read an array of strings from a multiple
  948. * strings property.
  949. * @np: device node from which the property value is to be read.
  950. * @propname: name of the property to be searched.
  951. * @out_strs: output array of string pointers.
  952. * @sz: number of array elements to read.
  953. *
  954. * Search for a property in a device tree node and retrieve a list of
  955. * terminated string values (pointer to data, not a copy) in that property.
  956. *
  957. * If @out_strs is NULL, the number of strings in the property is returned.
  958. */
  959. static inline int of_property_read_string_array(const struct device_node *np,
  960. const char *propname, const char **out_strs,
  961. size_t sz)
  962. {
  963. return of_property_read_string_helper(np, propname, out_strs, sz, 0);
  964. }
  965. /**
  966. * of_property_count_strings() - Find and return the number of strings from a
  967. * multiple strings property.
  968. * @np: device node from which the property value is to be read.
  969. * @propname: name of the property to be searched.
  970. *
  971. * Search for a property in a device tree node and retrieve the number of null
  972. * terminated string contain in it. Returns the number of strings on
  973. * success, -EINVAL if the property does not exist, -ENODATA if property
  974. * does not have a value, and -EILSEQ if the string is not null-terminated
  975. * within the length of the property data.
  976. */
  977. static inline int of_property_count_strings(const struct device_node *np,
  978. const char *propname)
  979. {
  980. return of_property_read_string_helper(np, propname, NULL, 0, 0);
  981. }
  982. /**
  983. * of_property_read_string_index() - Find and read a string from a multiple
  984. * strings property.
  985. * @np: device node from which the property value is to be read.
  986. * @propname: name of the property to be searched.
  987. * @index: index of the string in the list of strings
  988. * @out_string: pointer to null terminated return string, modified only if
  989. * return value is 0.
  990. *
  991. * Search for a property in a device tree node and retrieve a null
  992. * terminated string value (pointer to data, not a copy) in the list of strings
  993. * contained in that property.
  994. * Returns 0 on success, -EINVAL if the property does not exist, -ENODATA if
  995. * property does not have a value, and -EILSEQ if the string is not
  996. * null-terminated within the length of the property data.
  997. *
  998. * The out_string pointer is modified only if a valid string can be decoded.
  999. */
  1000. static inline int of_property_read_string_index(const struct device_node *np,
  1001. const char *propname,
  1002. int index, const char **output)
  1003. {
  1004. int rc = of_property_read_string_helper(np, propname, output, 1, index);
  1005. return rc < 0 ? rc : 0;
  1006. }
  1007. /**
  1008. * of_property_read_bool - Findfrom a property
  1009. * @np: device node from which the property value is to be read.
  1010. * @propname: name of the property to be searched.
  1011. *
  1012. * Search for a property in a device node.
  1013. * Returns true if the property exists false otherwise.
  1014. */
  1015. static inline bool of_property_read_bool(const struct device_node *np,
  1016. const char *propname)
  1017. {
  1018. struct property *prop = of_find_property(np, propname, NULL);
  1019. return prop ? true : false;
  1020. }
  1021. static inline int of_property_read_u8(const struct device_node *np,
  1022. const char *propname,
  1023. u8 *out_value)
  1024. {
  1025. return of_property_read_u8_array(np, propname, out_value, 1);
  1026. }
  1027. static inline int of_property_read_u16(const struct device_node *np,
  1028. const char *propname,
  1029. u16 *out_value)
  1030. {
  1031. return of_property_read_u16_array(np, propname, out_value, 1);
  1032. }
  1033. static inline int of_property_read_u32(const struct device_node *np,
  1034. const char *propname,
  1035. u32 *out_value)
  1036. {
  1037. return of_property_read_u32_array(np, propname, out_value, 1);
  1038. }
  1039. static inline int of_property_read_s32(const struct device_node *np,
  1040. const char *propname,
  1041. s32 *out_value)
  1042. {
  1043. return of_property_read_u32(np, propname, (u32*) out_value);
  1044. }
  1045. #define of_for_each_phandle(it, err, np, ln, cn, cc) \
  1046. for (of_phandle_iterator_init((it), (np), (ln), (cn), (cc)), \
  1047. err = of_phandle_iterator_next(it); \
  1048. err == 0; \
  1049. err = of_phandle_iterator_next(it))
  1050. #define of_property_for_each_u32(np, propname, prop, p, u) \
  1051. for (prop = of_find_property(np, propname, NULL), \
  1052. p = of_prop_next_u32(prop, NULL, &u); \
  1053. p; \
  1054. p = of_prop_next_u32(prop, p, &u))
  1055. #define of_property_for_each_string(np, propname, prop, s) \
  1056. for (prop = of_find_property(np, propname, NULL), \
  1057. s = of_prop_next_string(prop, NULL); \
  1058. s; \
  1059. s = of_prop_next_string(prop, s))
  1060. #define for_each_node_by_name(dn, name) \
  1061. for (dn = of_find_node_by_name(NULL, name); dn; \
  1062. dn = of_find_node_by_name(dn, name))
  1063. #define for_each_node_by_type(dn, type) \
  1064. for (dn = of_find_node_by_type(NULL, type); dn; \
  1065. dn = of_find_node_by_type(dn, type))
  1066. #define for_each_compatible_node(dn, type, compatible) \
  1067. for (dn = of_find_compatible_node(NULL, type, compatible); dn; \
  1068. dn = of_find_compatible_node(dn, type, compatible))
  1069. #define for_each_matching_node(dn, matches) \
  1070. for (dn = of_find_matching_node(NULL, matches); dn; \
  1071. dn = of_find_matching_node(dn, matches))
  1072. #define for_each_matching_node_and_match(dn, matches, match) \
  1073. for (dn = of_find_matching_node_and_match(NULL, matches, match); \
  1074. dn; dn = of_find_matching_node_and_match(dn, matches, match))
  1075. #define for_each_child_of_node(parent, child) \
  1076. for (child = of_get_next_child(parent, NULL); child != NULL; \
  1077. child = of_get_next_child(parent, child))
  1078. #define for_each_available_child_of_node(parent, child) \
  1079. for (child = of_get_next_available_child(parent, NULL); child != NULL; \
  1080. child = of_get_next_available_child(parent, child))
  1081. #define for_each_of_cpu_node(cpu) \
  1082. for (cpu = of_get_next_cpu_node(NULL); cpu != NULL; \
  1083. cpu = of_get_next_cpu_node(cpu))
  1084. #define for_each_node_with_property(dn, prop_name) \
  1085. for (dn = of_find_node_with_property(NULL, prop_name); dn; \
  1086. dn = of_find_node_with_property(dn, prop_name))
  1087. static inline int of_get_child_count(const struct device_node *np)
  1088. {
  1089. struct device_node *child;
  1090. int num = 0;
  1091. for_each_child_of_node(np, child)
  1092. num++;
  1093. return num;
  1094. }
  1095. static inline int of_get_available_child_count(const struct device_node *np)
  1096. {
  1097. struct device_node *child;
  1098. int num = 0;
  1099. for_each_available_child_of_node(np, child)
  1100. num++;
  1101. return num;
  1102. }
  1103. #if defined(CONFIG_OF) && !defined(MODULE)
  1104. #define _OF_DECLARE(table, name, compat, fn, fn_type) \
  1105. static const struct of_device_id __of_table_##name \
  1106. __used __section(__##table##_of_table) \
  1107. = { .compatible = compat, \
  1108. .data = (fn == (fn_type)NULL) ? fn : fn }
  1109. #else
  1110. #define _OF_DECLARE(table, name, compat, fn, fn_type) \
  1111. static const struct of_device_id __of_table_##name \
  1112. __attribute__((unused)) \
  1113. = { .compatible = compat, \
  1114. .data = (fn == (fn_type)NULL) ? fn : fn }
  1115. #endif
  1116. typedef int (*of_init_fn_2)(struct device_node *, struct device_node *);
  1117. typedef int (*of_init_fn_1_ret)(struct device_node *);
  1118. typedef void (*of_init_fn_1)(struct device_node *);
  1119. #define OF_DECLARE_1(table, name, compat, fn) \
  1120. _OF_DECLARE(table, name, compat, fn, of_init_fn_1)
  1121. #define OF_DECLARE_1_RET(table, name, compat, fn) \
  1122. _OF_DECLARE(table, name, compat, fn, of_init_fn_1_ret)
  1123. #define OF_DECLARE_2(table, name, compat, fn) \
  1124. _OF_DECLARE(table, name, compat, fn, of_init_fn_2)
  1125. /**
  1126. * struct of_changeset_entry - Holds a changeset entry
  1127. *
  1128. * @node: list_head for the log list
  1129. * @action: notifier action
  1130. * @np: pointer to the device node affected
  1131. * @prop: pointer to the property affected
  1132. * @old_prop: hold a pointer to the original property
  1133. *
  1134. * Every modification of the device tree during a changeset
  1135. * is held in a list of of_changeset_entry structures.
  1136. * That way we can recover from a partial application, or we can
  1137. * revert the changeset
  1138. */
  1139. struct of_changeset_entry {
  1140. struct list_head node;
  1141. unsigned long action;
  1142. struct device_node *np;
  1143. struct property *prop;
  1144. struct property *old_prop;
  1145. };
  1146. /**
  1147. * struct of_changeset - changeset tracker structure
  1148. *
  1149. * @entries: list_head for the changeset entries
  1150. *
  1151. * changesets are a convenient way to apply bulk changes to the
  1152. * live tree. In case of an error, changes are rolled-back.
  1153. * changesets live on after initial application, and if not
  1154. * destroyed after use, they can be reverted in one single call.
  1155. */
  1156. struct of_changeset {
  1157. struct list_head entries;
  1158. };
  1159. enum of_reconfig_change {
  1160. OF_RECONFIG_NO_CHANGE = 0,
  1161. OF_RECONFIG_CHANGE_ADD,
  1162. OF_RECONFIG_CHANGE_REMOVE,
  1163. };
  1164. #ifdef CONFIG_OF_DYNAMIC
  1165. extern int of_reconfig_notifier_register(struct notifier_block *);
  1166. extern int of_reconfig_notifier_unregister(struct notifier_block *);
  1167. extern int of_reconfig_notify(unsigned long, struct of_reconfig_data *rd);
  1168. extern int of_reconfig_get_state_change(unsigned long action,
  1169. struct of_reconfig_data *arg);
  1170. extern void of_changeset_init(struct of_changeset *ocs);
  1171. extern void of_changeset_destroy(struct of_changeset *ocs);
  1172. extern int of_changeset_apply(struct of_changeset *ocs);
  1173. extern int of_changeset_revert(struct of_changeset *ocs);
  1174. extern int of_changeset_action(struct of_changeset *ocs,
  1175. unsigned long action, struct device_node *np,
  1176. struct property *prop);
  1177. static inline int of_changeset_attach_node(struct of_changeset *ocs,
  1178. struct device_node *np)
  1179. {
  1180. return of_changeset_action(ocs, OF_RECONFIG_ATTACH_NODE, np, NULL);
  1181. }
  1182. static inline int of_changeset_detach_node(struct of_changeset *ocs,
  1183. struct device_node *np)
  1184. {
  1185. return of_changeset_action(ocs, OF_RECONFIG_DETACH_NODE, np, NULL);
  1186. }
  1187. static inline int of_changeset_add_property(struct of_changeset *ocs,
  1188. struct device_node *np, struct property *prop)
  1189. {
  1190. return of_changeset_action(ocs, OF_RECONFIG_ADD_PROPERTY, np, prop);
  1191. }
  1192. static inline int of_changeset_remove_property(struct of_changeset *ocs,
  1193. struct device_node *np, struct property *prop)
  1194. {
  1195. return of_changeset_action(ocs, OF_RECONFIG_REMOVE_PROPERTY, np, prop);
  1196. }
  1197. static inline int of_changeset_update_property(struct of_changeset *ocs,
  1198. struct device_node *np, struct property *prop)
  1199. {
  1200. return of_changeset_action(ocs, OF_RECONFIG_UPDATE_PROPERTY, np, prop);
  1201. }
  1202. #else /* CONFIG_OF_DYNAMIC */
  1203. static inline int of_reconfig_notifier_register(struct notifier_block *nb)
  1204. {
  1205. return -EINVAL;
  1206. }
  1207. static inline int of_reconfig_notifier_unregister(struct notifier_block *nb)
  1208. {
  1209. return -EINVAL;
  1210. }
  1211. static inline int of_reconfig_notify(unsigned long action,
  1212. struct of_reconfig_data *arg)
  1213. {
  1214. return -EINVAL;
  1215. }
  1216. static inline int of_reconfig_get_state_change(unsigned long action,
  1217. struct of_reconfig_data *arg)
  1218. {
  1219. return -EINVAL;
  1220. }
  1221. #endif /* CONFIG_OF_DYNAMIC */
  1222. /**
  1223. * of_device_is_system_power_controller - Tells if system-power-controller is found for device_node
  1224. * @np: Pointer to the given device_node
  1225. *
  1226. * return true if present false otherwise
  1227. */
  1228. static inline bool of_device_is_system_power_controller(const struct device_node *np)
  1229. {
  1230. return of_property_read_bool(np, "system-power-controller");
  1231. }
  1232. /**
  1233. * Overlay support
  1234. */
  1235. enum of_overlay_notify_action {
  1236. OF_OVERLAY_PRE_APPLY = 0,
  1237. OF_OVERLAY_POST_APPLY,
  1238. OF_OVERLAY_PRE_REMOVE,
  1239. OF_OVERLAY_POST_REMOVE,
  1240. };
  1241. struct of_overlay_notify_data {
  1242. struct device_node *overlay;
  1243. struct device_node *target;
  1244. };
  1245. #ifdef CONFIG_OF_OVERLAY
  1246. int of_overlay_fdt_apply(const void *overlay_fdt, u32 overlay_fdt_size,
  1247. int *ovcs_id);
  1248. int of_overlay_remove(int *ovcs_id);
  1249. int of_overlay_remove_all(void);
  1250. int of_overlay_notifier_register(struct notifier_block *nb);
  1251. int of_overlay_notifier_unregister(struct notifier_block *nb);
  1252. #else
  1253. static inline int of_overlay_fdt_apply(void *overlay_fdt, int *ovcs_id)
  1254. {
  1255. return -ENOTSUPP;
  1256. }
  1257. static inline int of_overlay_remove(int *ovcs_id)
  1258. {
  1259. return -ENOTSUPP;
  1260. }
  1261. static inline int of_overlay_remove_all(void)
  1262. {
  1263. return -ENOTSUPP;
  1264. }
  1265. static inline int of_overlay_notifier_register(struct notifier_block *nb)
  1266. {
  1267. return 0;
  1268. }
  1269. static inline int of_overlay_notifier_unregister(struct notifier_block *nb)
  1270. {
  1271. return 0;
  1272. }
  1273. #endif
  1274. #endif /* _LINUX_OF_H */