of.h 41 KB

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