of.h 41 KB

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