of.h 43 KB

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