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/cleanup.h> 17 #include <linux/errno.h> 18 #include <linux/kobject.h> 19 #include <linux/mod_devicetable.h> 20 #include <linux/property.h> 21 #include <linux/list.h> 22 23 #include <asm/byteorder.h> 24 25 typedef u32 phandle; 26 typedef u32 ihandle; 27 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 44 #if defined(CONFIG_SPARC) 45 struct of_irq_controller; 46 #endif 47 48 struct device_node { 49 const char *name; 50 phandle phandle; 51 const char *full_name; 52 struct fwnode_handle fwnode; 53 54 struct property *properties; 55 struct property *deadprops; /* removed properties */ 56 struct device_node *parent; 57 struct device_node *child; 58 struct device_node *sibling; 59 #if defined(CONFIG_OF_KOBJ) 60 struct kobject kobj; 61 #endif 62 unsigned long _flags; 63 void *data; 64 #if defined(CONFIG_SPARC) 65 unsigned int unique_id; 66 struct of_irq_controller *irq_trans; 67 #endif 68 }; 69 70 #define MAX_PHANDLE_ARGS 16 71 struct of_phandle_args { 72 struct device_node *np; 73 int args_count; 74 uint32_t args[MAX_PHANDLE_ARGS]; 75 }; 76 77 struct of_phandle_iterator { 78 /* Common iterator information */ 79 const char *cells_name; 80 int cell_count; 81 const struct device_node *parent; 82 83 /* List size information */ 84 const __be32 *list_end; 85 const __be32 *phandle_end; 86 87 /* Current position state */ 88 const __be32 *cur; 89 uint32_t cur_count; 90 phandle phandle; 91 struct device_node *node; 92 }; 93 94 struct of_reconfig_data { 95 struct device_node *dn; 96 struct property *prop; 97 struct property *old_prop; 98 }; 99 100 extern const struct kobj_type of_node_ktype; 101 extern const struct fwnode_operations of_fwnode_ops; 102 103 /** 104 * of_node_init - initialize a devicetree node 105 * @node: Pointer to device node that has been created by kzalloc() 106 * 107 * On return the device_node refcount is set to one. Use of_node_put() 108 * on @node when done to free the memory allocated for it. If the node 109 * is NOT a dynamic node the memory will not be freed. The decision of 110 * whether to free the memory will be done by node->release(), which is 111 * of_node_release(). 112 */ 113 static inline void of_node_init(struct device_node *node) 114 { 115 #if defined(CONFIG_OF_KOBJ) 116 kobject_init(&node->kobj, &of_node_ktype); 117 #endif 118 fwnode_init(&node->fwnode, &of_fwnode_ops); 119 } 120 121 #if defined(CONFIG_OF_KOBJ) 122 #define of_node_kobj(n) (&(n)->kobj) 123 #else 124 #define of_node_kobj(n) NULL 125 #endif 126 127 #ifdef CONFIG_OF_DYNAMIC 128 extern struct device_node *of_node_get(struct device_node *node); 129 extern void of_node_put(struct device_node *node); 130 #else /* CONFIG_OF_DYNAMIC */ 131 /* Dummy ref counting routines - to be implemented later */ 132 static inline struct device_node *of_node_get(struct device_node *node) 133 { 134 return node; 135 } 136 static inline void of_node_put(struct device_node *node) { } 137 #endif /* !CONFIG_OF_DYNAMIC */ 138 DEFINE_FREE(device_node, struct device_node *, if (_T) of_node_put(_T)) 139 140 /* Pointer for first entry in chain of all nodes. */ 141 extern struct device_node *of_root; 142 extern struct device_node *of_chosen; 143 extern struct device_node *of_aliases; 144 extern struct device_node *of_stdout; 145 146 /* 147 * struct device_node flag descriptions 148 * (need to be visible even when !CONFIG_OF) 149 */ 150 #define OF_DYNAMIC 1 /* (and properties) allocated via kmalloc */ 151 #define OF_DETACHED 2 /* detached from the device tree */ 152 #define OF_POPULATED 3 /* device already created */ 153 #define OF_POPULATED_BUS 4 /* platform bus created for children */ 154 #define OF_OVERLAY 5 /* allocated for an overlay */ 155 #define OF_OVERLAY_FREE_CSET 6 /* in overlay cset being freed */ 156 157 #define OF_BAD_ADDR ((u64)-1) 158 159 #ifdef CONFIG_OF 160 void of_core_init(void); 161 162 static inline bool is_of_node(const struct fwnode_handle *fwnode) 163 { 164 return !IS_ERR_OR_NULL(fwnode) && fwnode->ops == &of_fwnode_ops; 165 } 166 167 #define to_of_node(__fwnode) \ 168 ({ \ 169 typeof(__fwnode) __to_of_node_fwnode = (__fwnode); \ 170 \ 171 is_of_node(__to_of_node_fwnode) ? \ 172 container_of(__to_of_node_fwnode, \ 173 struct device_node, fwnode) : \ 174 NULL; \ 175 }) 176 177 #define of_fwnode_handle(node) \ 178 ({ \ 179 typeof(node) __of_fwnode_handle_node = (node); \ 180 \ 181 __of_fwnode_handle_node ? \ 182 &__of_fwnode_handle_node->fwnode : NULL; \ 183 }) 184 185 static inline bool of_node_is_root(const struct device_node *node) 186 { 187 return node && (node->parent == NULL); 188 } 189 190 static inline int of_node_check_flag(const struct device_node *n, unsigned long flag) 191 { 192 return test_bit(flag, &n->_flags); 193 } 194 195 static inline int of_node_test_and_set_flag(struct device_node *n, 196 unsigned long flag) 197 { 198 return test_and_set_bit(flag, &n->_flags); 199 } 200 201 static inline void of_node_set_flag(struct device_node *n, unsigned long flag) 202 { 203 set_bit(flag, &n->_flags); 204 } 205 206 static inline void of_node_clear_flag(struct device_node *n, unsigned long flag) 207 { 208 clear_bit(flag, &n->_flags); 209 } 210 211 #if defined(CONFIG_OF_DYNAMIC) || defined(CONFIG_SPARC) 212 static inline int of_property_check_flag(const struct property *p, unsigned long flag) 213 { 214 return test_bit(flag, &p->_flags); 215 } 216 217 static inline void of_property_set_flag(struct property *p, unsigned long flag) 218 { 219 set_bit(flag, &p->_flags); 220 } 221 222 static inline void of_property_clear_flag(struct property *p, unsigned long flag) 223 { 224 clear_bit(flag, &p->_flags); 225 } 226 #endif 227 228 extern struct device_node *__of_find_all_nodes(struct device_node *prev); 229 extern struct device_node *of_find_all_nodes(struct device_node *prev); 230 231 /* 232 * OF address retrieval & translation 233 */ 234 235 /* Helper to read a big number; size is in cells (not bytes) */ 236 static inline u64 of_read_number(const __be32 *cell, int size) 237 { 238 u64 r = 0; 239 for (; size--; cell++) 240 r = (r << 32) | be32_to_cpu(*cell); 241 return r; 242 } 243 244 /* Like of_read_number, but we want an unsigned long result */ 245 static inline unsigned long of_read_ulong(const __be32 *cell, int size) 246 { 247 /* toss away upper bits if unsigned long is smaller than u64 */ 248 return of_read_number(cell, size); 249 } 250 251 #if defined(CONFIG_SPARC) 252 #include <asm/prom.h> 253 #endif 254 255 #define OF_IS_DYNAMIC(x) test_bit(OF_DYNAMIC, &x->_flags) 256 #define OF_MARK_DYNAMIC(x) set_bit(OF_DYNAMIC, &x->_flags) 257 258 extern bool of_node_name_eq(const struct device_node *np, const char *name); 259 extern bool of_node_name_prefix(const struct device_node *np, const char *prefix); 260 261 static inline const char *of_node_full_name(const struct device_node *np) 262 { 263 return np ? np->full_name : "<no-node>"; 264 } 265 266 #define for_each_of_allnodes_from(from, dn) \ 267 for (dn = __of_find_all_nodes(from); dn; dn = __of_find_all_nodes(dn)) 268 #define for_each_of_allnodes(dn) for_each_of_allnodes_from(NULL, dn) 269 extern struct device_node *of_find_node_by_name(struct device_node *from, 270 const char *name); 271 extern struct device_node *of_find_node_by_type(struct device_node *from, 272 const char *type); 273 extern struct device_node *of_find_compatible_node(struct device_node *from, 274 const char *type, const char *compat); 275 extern struct device_node *of_find_matching_node_and_match( 276 struct device_node *from, 277 const struct of_device_id *matches, 278 const struct of_device_id **match); 279 280 extern struct device_node *of_find_node_opts_by_path(const char *path, 281 const char **opts); 282 static inline struct device_node *of_find_node_by_path(const char *path) 283 { 284 return of_find_node_opts_by_path(path, NULL); 285 } 286 287 extern struct device_node *of_find_node_by_phandle(phandle handle); 288 extern struct device_node *of_get_parent(const struct device_node *node); 289 extern struct device_node *of_get_next_parent(struct device_node *node); 290 extern struct device_node *of_get_next_child(const struct device_node *node, 291 struct device_node *prev); 292 extern struct device_node *of_get_next_available_child( 293 const struct device_node *node, struct device_node *prev); 294 295 extern struct device_node *of_get_compatible_child(const struct device_node *parent, 296 const char *compatible); 297 extern struct device_node *of_get_child_by_name(const struct device_node *node, 298 const char *name); 299 300 /* cache lookup */ 301 extern struct device_node *of_find_next_cache_node(const struct device_node *); 302 extern int of_find_last_cache_level(unsigned int cpu); 303 extern struct device_node *of_find_node_with_property( 304 struct device_node *from, const char *prop_name); 305 306 extern struct property *of_find_property(const struct device_node *np, 307 const char *name, 308 int *lenp); 309 extern int of_property_count_elems_of_size(const struct device_node *np, 310 const char *propname, int elem_size); 311 extern int of_property_read_u32_index(const struct device_node *np, 312 const char *propname, 313 u32 index, u32 *out_value); 314 extern int of_property_read_u64_index(const struct device_node *np, 315 const char *propname, 316 u32 index, u64 *out_value); 317 extern int of_property_read_variable_u8_array(const struct device_node *np, 318 const char *propname, u8 *out_values, 319 size_t sz_min, size_t sz_max); 320 extern int of_property_read_variable_u16_array(const struct device_node *np, 321 const char *propname, u16 *out_values, 322 size_t sz_min, size_t sz_max); 323 extern int of_property_read_variable_u32_array(const struct device_node *np, 324 const char *propname, 325 u32 *out_values, 326 size_t sz_min, 327 size_t sz_max); 328 extern int of_property_read_u64(const struct device_node *np, 329 const char *propname, u64 *out_value); 330 extern int of_property_read_variable_u64_array(const struct device_node *np, 331 const char *propname, 332 u64 *out_values, 333 size_t sz_min, 334 size_t sz_max); 335 336 extern int of_property_read_string(const struct device_node *np, 337 const char *propname, 338 const char **out_string); 339 extern int of_property_match_string(const struct device_node *np, 340 const char *propname, 341 const char *string); 342 extern int of_property_read_string_helper(const struct device_node *np, 343 const char *propname, 344 const char **out_strs, size_t sz, int index); 345 extern int of_device_is_compatible(const struct device_node *device, 346 const char *); 347 extern int of_device_compatible_match(const struct device_node *device, 348 const char *const *compat); 349 extern bool of_device_is_available(const struct device_node *device); 350 extern bool of_device_is_big_endian(const struct device_node *device); 351 extern const void *of_get_property(const struct device_node *node, 352 const char *name, 353 int *lenp); 354 extern struct device_node *of_get_cpu_node(int cpu, unsigned int *thread); 355 extern struct device_node *of_cpu_device_node_get(int cpu); 356 extern int of_cpu_node_to_id(struct device_node *np); 357 extern struct device_node *of_get_next_cpu_node(struct device_node *prev); 358 extern struct device_node *of_get_cpu_state_node(struct device_node *cpu_node, 359 int index); 360 extern u64 of_get_cpu_hwid(struct device_node *cpun, unsigned int thread); 361 362 extern int of_n_addr_cells(struct device_node *np); 363 extern int of_n_size_cells(struct device_node *np); 364 extern const struct of_device_id *of_match_node( 365 const struct of_device_id *matches, const struct device_node *node); 366 extern const void *of_device_get_match_data(const struct device *dev); 367 extern int of_alias_from_compatible(const struct device_node *node, char *alias, 368 int len); 369 extern void of_print_phandle_args(const char *msg, const struct of_phandle_args *args); 370 extern int __of_parse_phandle_with_args(const struct device_node *np, 371 const char *list_name, const char *cells_name, int cell_count, 372 int index, struct of_phandle_args *out_args); 373 extern int of_parse_phandle_with_args_map(const struct device_node *np, 374 const char *list_name, const char *stem_name, int index, 375 struct of_phandle_args *out_args); 376 extern int of_count_phandle_with_args(const struct device_node *np, 377 const char *list_name, const char *cells_name); 378 379 /* module functions */ 380 extern ssize_t of_modalias(const struct device_node *np, char *str, ssize_t len); 381 extern int of_request_module(const struct device_node *np); 382 383 /* phandle iterator functions */ 384 extern int of_phandle_iterator_init(struct of_phandle_iterator *it, 385 const struct device_node *np, 386 const char *list_name, 387 const char *cells_name, 388 int cell_count); 389 390 extern int of_phandle_iterator_next(struct of_phandle_iterator *it); 391 extern int of_phandle_iterator_args(struct of_phandle_iterator *it, 392 uint32_t *args, 393 int size); 394 395 extern void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align)); 396 extern int of_alias_get_id(struct device_node *np, const char *stem); 397 extern int of_alias_get_highest_id(const char *stem); 398 399 extern int of_machine_is_compatible(const char *compat); 400 401 extern int of_add_property(struct device_node *np, struct property *prop); 402 extern int of_remove_property(struct device_node *np, struct property *prop); 403 extern int of_update_property(struct device_node *np, struct property *newprop); 404 405 /* For updating the device tree at runtime */ 406 #define OF_RECONFIG_ATTACH_NODE 0x0001 407 #define OF_RECONFIG_DETACH_NODE 0x0002 408 #define OF_RECONFIG_ADD_PROPERTY 0x0003 409 #define OF_RECONFIG_REMOVE_PROPERTY 0x0004 410 #define OF_RECONFIG_UPDATE_PROPERTY 0x0005 411 412 extern int of_attach_node(struct device_node *); 413 extern int of_detach_node(struct device_node *); 414 415 #define of_match_ptr(_ptr) (_ptr) 416 417 /* 418 * struct property *prop; 419 * const __be32 *p; 420 * u32 u; 421 * 422 * of_property_for_each_u32(np, "propname", prop, p, u) 423 * printk("U32 value: %x\n", u); 424 */ 425 const __be32 *of_prop_next_u32(struct property *prop, const __be32 *cur, 426 u32 *pu); 427 /* 428 * struct property *prop; 429 * const char *s; 430 * 431 * of_property_for_each_string(np, "propname", prop, s) 432 * printk("String value: %s\n", s); 433 */ 434 const char *of_prop_next_string(struct property *prop, const char *cur); 435 436 bool of_console_check(struct device_node *dn, char *name, int index); 437 438 int of_map_id(struct device_node *np, u32 id, 439 const char *map_name, const char *map_mask_name, 440 struct device_node **target, u32 *id_out); 441 442 phys_addr_t of_dma_get_max_cpu_address(struct device_node *np); 443 444 struct kimage; 445 void *of_kexec_alloc_and_setup_fdt(const struct kimage *image, 446 unsigned long initrd_load_addr, 447 unsigned long initrd_len, 448 const char *cmdline, size_t extra_fdt_size); 449 #else /* CONFIG_OF */ 450 451 static inline void of_core_init(void) 452 { 453 } 454 455 static inline bool is_of_node(const struct fwnode_handle *fwnode) 456 { 457 return false; 458 } 459 460 static inline struct device_node *to_of_node(const struct fwnode_handle *fwnode) 461 { 462 return NULL; 463 } 464 465 static inline bool of_node_name_eq(const struct device_node *np, const char *name) 466 { 467 return false; 468 } 469 470 static inline bool of_node_name_prefix(const struct device_node *np, const char *prefix) 471 { 472 return false; 473 } 474 475 static inline const char* of_node_full_name(const struct device_node *np) 476 { 477 return "<no-node>"; 478 } 479 480 static inline struct device_node *of_find_node_by_name(struct device_node *from, 481 const char *name) 482 { 483 return NULL; 484 } 485 486 static inline struct device_node *of_find_node_by_type(struct device_node *from, 487 const char *type) 488 { 489 return NULL; 490 } 491 492 static inline struct device_node *of_find_matching_node_and_match( 493 struct device_node *from, 494 const struct of_device_id *matches, 495 const struct of_device_id **match) 496 { 497 return NULL; 498 } 499 500 static inline struct device_node *of_find_node_by_path(const char *path) 501 { 502 return NULL; 503 } 504 505 static inline struct device_node *of_find_node_opts_by_path(const char *path, 506 const char **opts) 507 { 508 return NULL; 509 } 510 511 static inline struct device_node *of_find_node_by_phandle(phandle handle) 512 { 513 return NULL; 514 } 515 516 static inline struct device_node *of_get_parent(const struct device_node *node) 517 { 518 return NULL; 519 } 520 521 static inline struct device_node *of_get_next_parent(struct device_node *node) 522 { 523 return NULL; 524 } 525 526 static inline struct device_node *of_get_next_child( 527 const struct device_node *node, struct device_node *prev) 528 { 529 return NULL; 530 } 531 532 static inline struct device_node *of_get_next_available_child( 533 const struct device_node *node, struct device_node *prev) 534 { 535 return NULL; 536 } 537 538 static inline struct device_node *of_find_node_with_property( 539 struct device_node *from, const char *prop_name) 540 { 541 return NULL; 542 } 543 544 #define of_fwnode_handle(node) NULL 545 546 static inline struct device_node *of_get_compatible_child(const struct device_node *parent, 547 const char *compatible) 548 { 549 return NULL; 550 } 551 552 static inline struct device_node *of_get_child_by_name( 553 const struct device_node *node, 554 const char *name) 555 { 556 return NULL; 557 } 558 559 static inline int of_device_is_compatible(const struct device_node *device, 560 const char *name) 561 { 562 return 0; 563 } 564 565 static inline int of_device_compatible_match(const struct device_node *device, 566 const char *const *compat) 567 { 568 return 0; 569 } 570 571 static inline bool of_device_is_available(const struct device_node *device) 572 { 573 return false; 574 } 575 576 static inline bool of_device_is_big_endian(const struct device_node *device) 577 { 578 return false; 579 } 580 581 static inline struct property *of_find_property(const struct device_node *np, 582 const char *name, 583 int *lenp) 584 { 585 return NULL; 586 } 587 588 static inline struct device_node *of_find_compatible_node( 589 struct device_node *from, 590 const char *type, 591 const char *compat) 592 { 593 return NULL; 594 } 595 596 static inline int of_property_count_elems_of_size(const struct device_node *np, 597 const char *propname, int elem_size) 598 { 599 return -ENOSYS; 600 } 601 602 static inline int of_property_read_u32_index(const struct device_node *np, 603 const char *propname, u32 index, u32 *out_value) 604 { 605 return -ENOSYS; 606 } 607 608 static inline int of_property_read_u64_index(const struct device_node *np, 609 const char *propname, u32 index, u64 *out_value) 610 { 611 return -ENOSYS; 612 } 613 614 static inline const void *of_get_property(const struct device_node *node, 615 const char *name, 616 int *lenp) 617 { 618 return NULL; 619 } 620 621 static inline struct device_node *of_get_cpu_node(int cpu, 622 unsigned int *thread) 623 { 624 return NULL; 625 } 626 627 static inline struct device_node *of_cpu_device_node_get(int cpu) 628 { 629 return NULL; 630 } 631 632 static inline int of_cpu_node_to_id(struct device_node *np) 633 { 634 return -ENODEV; 635 } 636 637 static inline struct device_node *of_get_next_cpu_node(struct device_node *prev) 638 { 639 return NULL; 640 } 641 642 static inline struct device_node *of_get_cpu_state_node(struct device_node *cpu_node, 643 int index) 644 { 645 return NULL; 646 } 647 648 static inline int of_n_addr_cells(struct device_node *np) 649 { 650 return 0; 651 652 } 653 static inline int of_n_size_cells(struct device_node *np) 654 { 655 return 0; 656 } 657 658 static inline int of_property_read_variable_u8_array(const struct device_node *np, 659 const char *propname, u8 *out_values, 660 size_t sz_min, size_t sz_max) 661 { 662 return -ENOSYS; 663 } 664 665 static inline int of_property_read_variable_u16_array(const struct device_node *np, 666 const char *propname, u16 *out_values, 667 size_t sz_min, size_t sz_max) 668 { 669 return -ENOSYS; 670 } 671 672 static inline int of_property_read_variable_u32_array(const struct device_node *np, 673 const char *propname, 674 u32 *out_values, 675 size_t sz_min, 676 size_t sz_max) 677 { 678 return -ENOSYS; 679 } 680 681 static inline int of_property_read_u64(const struct device_node *np, 682 const char *propname, u64 *out_value) 683 { 684 return -ENOSYS; 685 } 686 687 static inline int of_property_read_variable_u64_array(const struct device_node *np, 688 const char *propname, 689 u64 *out_values, 690 size_t sz_min, 691 size_t sz_max) 692 { 693 return -ENOSYS; 694 } 695 696 static inline int of_property_read_string(const struct device_node *np, 697 const char *propname, 698 const char **out_string) 699 { 700 return -ENOSYS; 701 } 702 703 static inline int of_property_match_string(const struct device_node *np, 704 const char *propname, 705 const char *string) 706 { 707 return -ENOSYS; 708 } 709 710 static inline int of_property_read_string_helper(const struct device_node *np, 711 const char *propname, 712 const char **out_strs, size_t sz, int index) 713 { 714 return -ENOSYS; 715 } 716 717 static inline int __of_parse_phandle_with_args(const struct device_node *np, 718 const char *list_name, 719 const char *cells_name, 720 int cell_count, 721 int index, 722 struct of_phandle_args *out_args) 723 { 724 return -ENOSYS; 725 } 726 727 static inline int of_parse_phandle_with_args_map(const struct device_node *np, 728 const char *list_name, 729 const char *stem_name, 730 int index, 731 struct of_phandle_args *out_args) 732 { 733 return -ENOSYS; 734 } 735 736 static inline int of_count_phandle_with_args(const struct device_node *np, 737 const char *list_name, 738 const char *cells_name) 739 { 740 return -ENOSYS; 741 } 742 743 static inline ssize_t of_modalias(const struct device_node *np, char *str, 744 ssize_t len) 745 { 746 return -ENODEV; 747 } 748 749 static inline int of_request_module(const struct device_node *np) 750 { 751 return -ENODEV; 752 } 753 754 static inline int of_phandle_iterator_init(struct of_phandle_iterator *it, 755 const struct device_node *np, 756 const char *list_name, 757 const char *cells_name, 758 int cell_count) 759 { 760 return -ENOSYS; 761 } 762 763 static inline int of_phandle_iterator_next(struct of_phandle_iterator *it) 764 { 765 return -ENOSYS; 766 } 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 775 static inline int of_alias_get_id(struct device_node *np, const char *stem) 776 { 777 return -ENOSYS; 778 } 779 780 static inline int of_alias_get_highest_id(const char *stem) 781 { 782 return -ENOSYS; 783 } 784 785 static inline int of_machine_is_compatible(const char *compat) 786 { 787 return 0; 788 } 789 790 static inline int of_add_property(struct device_node *np, struct property *prop) 791 { 792 return 0; 793 } 794 795 static inline int of_remove_property(struct device_node *np, struct property *prop) 796 { 797 return 0; 798 } 799 800 static inline bool of_console_check(const struct device_node *dn, const char *name, int index) 801 { 802 return false; 803 } 804 805 static inline const __be32 *of_prop_next_u32(struct property *prop, 806 const __be32 *cur, u32 *pu) 807 { 808 return NULL; 809 } 810 811 static inline const char *of_prop_next_string(struct property *prop, 812 const char *cur) 813 { 814 return NULL; 815 } 816 817 static inline int of_node_check_flag(struct device_node *n, unsigned long flag) 818 { 819 return 0; 820 } 821 822 static inline int of_node_test_and_set_flag(struct device_node *n, 823 unsigned long flag) 824 { 825 return 0; 826 } 827 828 static inline void of_node_set_flag(struct device_node *n, unsigned long flag) 829 { 830 } 831 832 static inline void of_node_clear_flag(struct device_node *n, unsigned long flag) 833 { 834 } 835 836 static inline int of_property_check_flag(const struct property *p, 837 unsigned long flag) 838 { 839 return 0; 840 } 841 842 static inline void of_property_set_flag(struct property *p, unsigned long flag) 843 { 844 } 845 846 static inline void of_property_clear_flag(struct property *p, unsigned long flag) 847 { 848 } 849 850 static inline int of_map_id(struct device_node *np, u32 id, 851 const char *map_name, const char *map_mask_name, 852 struct device_node **target, u32 *id_out) 853 { 854 return -EINVAL; 855 } 856 857 static inline phys_addr_t of_dma_get_max_cpu_address(struct device_node *np) 858 { 859 return PHYS_ADDR_MAX; 860 } 861 862 static inline const void *of_device_get_match_data(const struct device *dev) 863 { 864 return NULL; 865 } 866 867 #define of_match_ptr(_ptr) NULL 868 #define of_match_node(_matches, _node) NULL 869 #endif /* CONFIG_OF */ 870 871 /* Default string compare functions, Allow arch asm/prom.h to override */ 872 #if !defined(of_compat_cmp) 873 #define of_compat_cmp(s1, s2, l) strcasecmp((s1), (s2)) 874 #define of_prop_cmp(s1, s2) strcmp((s1), (s2)) 875 #define of_node_cmp(s1, s2) strcasecmp((s1), (s2)) 876 #endif 877 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 884 #define for_each_property_of_node(dn, pp) \ 885 for (pp = dn->properties; pp != NULL; pp = pp->next) 886 887 #if defined(CONFIG_OF) && defined(CONFIG_NUMA) 888 extern int of_node_to_nid(struct device_node *np); 889 #else 890 static inline int of_node_to_nid(struct device_node *device) 891 { 892 return NUMA_NO_NODE; 893 } 894 #endif 895 896 #ifdef CONFIG_OF_NUMA 897 extern int of_numa_init(void); 898 #else 899 static inline int of_numa_init(void) 900 { 901 return -ENOSYS; 902 } 903 #endif 904 905 static inline struct device_node *of_find_matching_node( 906 struct device_node *from, 907 const struct of_device_id *matches) 908 { 909 return of_find_matching_node_and_match(from, matches, NULL); 910 } 911 912 static inline const char *of_node_get_device_type(const struct device_node *np) 913 { 914 return of_get_property(np, "device_type", NULL); 915 } 916 917 static inline bool of_node_is_type(const struct device_node *np, const char *type) 918 { 919 const char *match = of_node_get_device_type(np); 920 921 return np && match && type && !strcmp(match, type); 922 } 923 924 /** 925 * of_parse_phandle - Resolve a phandle property to a device_node pointer 926 * @np: Pointer to device node holding phandle property 927 * @phandle_name: Name of property holding a phandle value 928 * @index: For properties holding a table of phandles, this is the index into 929 * the table 930 * 931 * Return: The device_node pointer with refcount incremented. Use 932 * of_node_put() on it when done. 933 */ 934 static inline struct device_node *of_parse_phandle(const struct device_node *np, 935 const char *phandle_name, 936 int index) 937 { 938 struct of_phandle_args args; 939 940 if (__of_parse_phandle_with_args(np, phandle_name, NULL, 0, 941 index, &args)) 942 return NULL; 943 944 return args.np; 945 } 946 947 /** 948 * of_parse_phandle_with_args() - Find a node pointed by phandle in a list 949 * @np: pointer to a device tree node containing a list 950 * @list_name: property name that contains a list 951 * @cells_name: property name that specifies phandles' arguments count 952 * @index: index of a phandle to parse out 953 * @out_args: optional pointer to output arguments structure (will be filled) 954 * 955 * This function is useful to parse lists of phandles and their arguments. 956 * Returns 0 on success and fills out_args, on error returns appropriate 957 * errno value. 958 * 959 * Caller is responsible to call of_node_put() on the returned out_args->np 960 * pointer. 961 * 962 * Example:: 963 * 964 * phandle1: node1 { 965 * #list-cells = <2>; 966 * }; 967 * 968 * phandle2: node2 { 969 * #list-cells = <1>; 970 * }; 971 * 972 * node3 { 973 * list = <&phandle1 1 2 &phandle2 3>; 974 * }; 975 * 976 * To get a device_node of the ``node2`` node you may call this: 977 * of_parse_phandle_with_args(node3, "list", "#list-cells", 1, &args); 978 */ 979 static inline int of_parse_phandle_with_args(const struct device_node *np, 980 const char *list_name, 981 const char *cells_name, 982 int index, 983 struct of_phandle_args *out_args) 984 { 985 int cell_count = -1; 986 987 /* If cells_name is NULL we assume a cell count of 0 */ 988 if (!cells_name) 989 cell_count = 0; 990 991 return __of_parse_phandle_with_args(np, list_name, cells_name, 992 cell_count, index, out_args); 993 } 994 995 /** 996 * of_parse_phandle_with_fixed_args() - Find a node pointed by phandle in a list 997 * @np: pointer to a device tree node containing a list 998 * @list_name: property name that contains a list 999 * @cell_count: number of argument cells following the phandle 1000 * @index: index of a phandle to parse out 1001 * @out_args: optional pointer to output arguments structure (will be filled) 1002 * 1003 * This function is useful to parse lists of phandles and their arguments. 1004 * Returns 0 on success and fills out_args, on error returns appropriate 1005 * errno value. 1006 * 1007 * Caller is responsible to call of_node_put() on the returned out_args->np 1008 * pointer. 1009 * 1010 * Example:: 1011 * 1012 * phandle1: node1 { 1013 * }; 1014 * 1015 * phandle2: node2 { 1016 * }; 1017 * 1018 * node3 { 1019 * list = <&phandle1 0 2 &phandle2 2 3>; 1020 * }; 1021 * 1022 * To get a device_node of the ``node2`` node you may call this: 1023 * of_parse_phandle_with_fixed_args(node3, "list", 2, 1, &args); 1024 */ 1025 static inline int of_parse_phandle_with_fixed_args(const struct device_node *np, 1026 const char *list_name, 1027 int cell_count, 1028 int index, 1029 struct of_phandle_args *out_args) 1030 { 1031 return __of_parse_phandle_with_args(np, list_name, NULL, cell_count, 1032 index, out_args); 1033 } 1034 1035 /** 1036 * of_parse_phandle_with_optional_args() - Find a node pointed by phandle in a list 1037 * @np: pointer to a device tree node containing a list 1038 * @list_name: property name that contains a list 1039 * @cells_name: property name that specifies phandles' arguments count 1040 * @index: index of a phandle to parse out 1041 * @out_args: optional pointer to output arguments structure (will be filled) 1042 * 1043 * Same as of_parse_phandle_with_args() except that if the cells_name property 1044 * is not found, cell_count of 0 is assumed. 1045 * 1046 * This is used to useful, if you have a phandle which didn't have arguments 1047 * before and thus doesn't have a '#*-cells' property but is now migrated to 1048 * having arguments while retaining backwards compatibility. 1049 */ 1050 static inline int of_parse_phandle_with_optional_args(const struct device_node *np, 1051 const char *list_name, 1052 const char *cells_name, 1053 int index, 1054 struct of_phandle_args *out_args) 1055 { 1056 return __of_parse_phandle_with_args(np, list_name, cells_name, 1057 0, index, out_args); 1058 } 1059 1060 /** 1061 * of_property_count_u8_elems - Count the number of u8 elements in a property 1062 * 1063 * @np: device node from which the property value is to be read. 1064 * @propname: name of the property to be searched. 1065 * 1066 * Search for a property in a device node and count the number of u8 elements 1067 * in it. 1068 * 1069 * Return: The number of elements on sucess, -EINVAL if the property does 1070 * not exist or its length does not match a multiple of u8 and -ENODATA if the 1071 * property does not have a value. 1072 */ 1073 static inline int of_property_count_u8_elems(const struct device_node *np, 1074 const char *propname) 1075 { 1076 return of_property_count_elems_of_size(np, propname, sizeof(u8)); 1077 } 1078 1079 /** 1080 * of_property_count_u16_elems - Count the number of u16 elements in a property 1081 * 1082 * @np: device node from which the property value is to be read. 1083 * @propname: name of the property to be searched. 1084 * 1085 * Search for a property in a device node and count the number of u16 elements 1086 * in it. 1087 * 1088 * Return: The number of elements on sucess, -EINVAL if the property does 1089 * not exist or its length does not match a multiple of u16 and -ENODATA if the 1090 * property does not have a value. 1091 */ 1092 static inline int of_property_count_u16_elems(const struct device_node *np, 1093 const char *propname) 1094 { 1095 return of_property_count_elems_of_size(np, propname, sizeof(u16)); 1096 } 1097 1098 /** 1099 * of_property_count_u32_elems - Count the number of u32 elements in a property 1100 * 1101 * @np: device node from which the property value is to be read. 1102 * @propname: name of the property to be searched. 1103 * 1104 * Search for a property in a device node and count the number of u32 elements 1105 * in it. 1106 * 1107 * Return: The number of elements on sucess, -EINVAL if the property does 1108 * not exist or its length does not match a multiple of u32 and -ENODATA if the 1109 * property does not have a value. 1110 */ 1111 static inline int of_property_count_u32_elems(const struct device_node *np, 1112 const char *propname) 1113 { 1114 return of_property_count_elems_of_size(np, propname, sizeof(u32)); 1115 } 1116 1117 /** 1118 * of_property_count_u64_elems - Count the number of u64 elements in a property 1119 * 1120 * @np: device node from which the property value is to be read. 1121 * @propname: name of the property to be searched. 1122 * 1123 * Search for a property in a device node and count the number of u64 elements 1124 * in it. 1125 * 1126 * Return: The number of elements on sucess, -EINVAL if the property does 1127 * not exist or its length does not match a multiple of u64 and -ENODATA if the 1128 * property does not have a value. 1129 */ 1130 static inline int of_property_count_u64_elems(const struct device_node *np, 1131 const char *propname) 1132 { 1133 return of_property_count_elems_of_size(np, propname, sizeof(u64)); 1134 } 1135 1136 /** 1137 * of_property_read_string_array() - Read an array of strings from a multiple 1138 * strings property. 1139 * @np: device node from which the property value is to be read. 1140 * @propname: name of the property to be searched. 1141 * @out_strs: output array of string pointers. 1142 * @sz: number of array elements to read. 1143 * 1144 * Search for a property in a device tree node and retrieve a list of 1145 * terminated string values (pointer to data, not a copy) in that property. 1146 * 1147 * Return: If @out_strs is NULL, the number of strings in the property is returned. 1148 */ 1149 static inline int of_property_read_string_array(const struct device_node *np, 1150 const char *propname, const char **out_strs, 1151 size_t sz) 1152 { 1153 return of_property_read_string_helper(np, propname, out_strs, sz, 0); 1154 } 1155 1156 /** 1157 * of_property_count_strings() - Find and return the number of strings from a 1158 * multiple strings property. 1159 * @np: device node from which the property value is to be read. 1160 * @propname: name of the property to be searched. 1161 * 1162 * Search for a property in a device tree node and retrieve the number of null 1163 * terminated string contain in it. 1164 * 1165 * Return: The number of strings on success, -EINVAL if the property does not 1166 * exist, -ENODATA if property does not have a value, and -EILSEQ if the string 1167 * is not null-terminated within the length of the property data. 1168 */ 1169 static inline int of_property_count_strings(const struct device_node *np, 1170 const char *propname) 1171 { 1172 return of_property_read_string_helper(np, propname, NULL, 0, 0); 1173 } 1174 1175 /** 1176 * of_property_read_string_index() - Find and read a string from a multiple 1177 * strings property. 1178 * @np: device node from which the property value is to be read. 1179 * @propname: name of the property to be searched. 1180 * @index: index of the string in the list of strings 1181 * @output: pointer to null terminated return string, modified only if 1182 * return value is 0. 1183 * 1184 * Search for a property in a device tree node and retrieve a null 1185 * terminated string value (pointer to data, not a copy) in the list of strings 1186 * contained in that property. 1187 * 1188 * Return: 0 on success, -EINVAL if the property does not exist, -ENODATA if 1189 * property does not have a value, and -EILSEQ if the string is not 1190 * null-terminated within the length of the property data. 1191 * 1192 * The out_string pointer is modified only if a valid string can be decoded. 1193 */ 1194 static inline int of_property_read_string_index(const struct device_node *np, 1195 const char *propname, 1196 int index, const char **output) 1197 { 1198 int rc = of_property_read_string_helper(np, propname, output, 1, index); 1199 return rc < 0 ? rc : 0; 1200 } 1201 1202 /** 1203 * of_property_read_bool - Find a property 1204 * @np: device node from which the property value is to be read. 1205 * @propname: name of the property to be searched. 1206 * 1207 * Search for a boolean property in a device node. Usage on non-boolean 1208 * property types is deprecated. 1209 * 1210 * Return: true if the property exists false otherwise. 1211 */ 1212 static inline bool of_property_read_bool(const struct device_node *np, 1213 const char *propname) 1214 { 1215 struct property *prop = of_find_property(np, propname, NULL); 1216 1217 return prop ? true : false; 1218 } 1219 1220 /** 1221 * of_property_present - Test if a property is present in a node 1222 * @np: device node to search for the property. 1223 * @propname: name of the property to be searched. 1224 * 1225 * Test for a property present in a device node. 1226 * 1227 * Return: true if the property exists false otherwise. 1228 */ 1229 static inline bool of_property_present(const struct device_node *np, const char *propname) 1230 { 1231 return of_property_read_bool(np, propname); 1232 } 1233 1234 /** 1235 * of_property_read_u8_array - Find and read an array of u8 from a property. 1236 * 1237 * @np: device node from which the property value is to be read. 1238 * @propname: name of the property to be searched. 1239 * @out_values: pointer to return value, modified only if return value is 0. 1240 * @sz: number of array elements to read 1241 * 1242 * Search for a property in a device node and read 8-bit value(s) from 1243 * it. 1244 * 1245 * dts entry of array should be like: 1246 * ``property = /bits/ 8 <0x50 0x60 0x70>;`` 1247 * 1248 * Return: 0 on success, -EINVAL if the property does not exist, 1249 * -ENODATA if property does not have a value, and -EOVERFLOW if the 1250 * property data isn't large enough. 1251 * 1252 * The out_values is modified only if a valid u8 value can be decoded. 1253 */ 1254 static inline int of_property_read_u8_array(const struct device_node *np, 1255 const char *propname, 1256 u8 *out_values, size_t sz) 1257 { 1258 int ret = of_property_read_variable_u8_array(np, propname, out_values, 1259 sz, 0); 1260 if (ret >= 0) 1261 return 0; 1262 else 1263 return ret; 1264 } 1265 1266 /** 1267 * of_property_read_u16_array - Find and read an array of u16 from a property. 1268 * 1269 * @np: device node from which the property value is to be read. 1270 * @propname: name of the property to be searched. 1271 * @out_values: pointer to return value, modified only if return value is 0. 1272 * @sz: number of array elements to read 1273 * 1274 * Search for a property in a device node and read 16-bit value(s) from 1275 * it. 1276 * 1277 * dts entry of array should be like: 1278 * ``property = /bits/ 16 <0x5000 0x6000 0x7000>;`` 1279 * 1280 * Return: 0 on success, -EINVAL if the property does not exist, 1281 * -ENODATA if property does not have a value, and -EOVERFLOW if the 1282 * property data isn't large enough. 1283 * 1284 * The out_values is modified only if a valid u16 value can be decoded. 1285 */ 1286 static inline int of_property_read_u16_array(const struct device_node *np, 1287 const char *propname, 1288 u16 *out_values, size_t sz) 1289 { 1290 int ret = of_property_read_variable_u16_array(np, propname, out_values, 1291 sz, 0); 1292 if (ret >= 0) 1293 return 0; 1294 else 1295 return ret; 1296 } 1297 1298 /** 1299 * of_property_read_u32_array - Find and read an array of 32 bit integers 1300 * from a property. 1301 * 1302 * @np: device node from which the property value is to be read. 1303 * @propname: name of the property to be searched. 1304 * @out_values: pointer to return value, modified only if return value is 0. 1305 * @sz: number of array elements to read 1306 * 1307 * Search for a property in a device node and read 32-bit value(s) from 1308 * it. 1309 * 1310 * Return: 0 on success, -EINVAL if the property does not exist, 1311 * -ENODATA if property does not have a value, and -EOVERFLOW if the 1312 * property data isn't large enough. 1313 * 1314 * The out_values is modified only if a valid u32 value can be decoded. 1315 */ 1316 static inline int of_property_read_u32_array(const struct device_node *np, 1317 const char *propname, 1318 u32 *out_values, size_t sz) 1319 { 1320 int ret = of_property_read_variable_u32_array(np, propname, out_values, 1321 sz, 0); 1322 if (ret >= 0) 1323 return 0; 1324 else 1325 return ret; 1326 } 1327 1328 /** 1329 * of_property_read_u64_array - Find and read an array of 64 bit integers 1330 * from a property. 1331 * 1332 * @np: device node from which the property value is to be read. 1333 * @propname: name of the property to be searched. 1334 * @out_values: pointer to return value, modified only if return value is 0. 1335 * @sz: number of array elements to read 1336 * 1337 * Search for a property in a device node and read 64-bit value(s) from 1338 * it. 1339 * 1340 * Return: 0 on success, -EINVAL if the property does not exist, 1341 * -ENODATA if property does not have a value, and -EOVERFLOW if the 1342 * property data isn't large enough. 1343 * 1344 * The out_values is modified only if a valid u64 value can be decoded. 1345 */ 1346 static inline int of_property_read_u64_array(const struct device_node *np, 1347 const char *propname, 1348 u64 *out_values, size_t sz) 1349 { 1350 int ret = of_property_read_variable_u64_array(np, propname, out_values, 1351 sz, 0); 1352 if (ret >= 0) 1353 return 0; 1354 else 1355 return ret; 1356 } 1357 1358 static inline int of_property_read_u8(const struct device_node *np, 1359 const char *propname, 1360 u8 *out_value) 1361 { 1362 return of_property_read_u8_array(np, propname, out_value, 1); 1363 } 1364 1365 static inline int of_property_read_u16(const struct device_node *np, 1366 const char *propname, 1367 u16 *out_value) 1368 { 1369 return of_property_read_u16_array(np, propname, out_value, 1); 1370 } 1371 1372 static inline int of_property_read_u32(const struct device_node *np, 1373 const char *propname, 1374 u32 *out_value) 1375 { 1376 return of_property_read_u32_array(np, propname, out_value, 1); 1377 } 1378 1379 static inline int of_property_read_s32(const struct device_node *np, 1380 const char *propname, 1381 s32 *out_value) 1382 { 1383 return of_property_read_u32(np, propname, (u32*) out_value); 1384 } 1385 1386 #define of_for_each_phandle(it, err, np, ln, cn, cc) \ 1387 for (of_phandle_iterator_init((it), (np), (ln), (cn), (cc)), \ 1388 err = of_phandle_iterator_next(it); \ 1389 err == 0; \ 1390 err = of_phandle_iterator_next(it)) 1391 1392 #define of_property_for_each_u32(np, propname, prop, p, u) \ 1393 for (prop = of_find_property(np, propname, NULL), \ 1394 p = of_prop_next_u32(prop, NULL, &u); \ 1395 p; \ 1396 p = of_prop_next_u32(prop, p, &u)) 1397 1398 #define of_property_for_each_string(np, propname, prop, s) \ 1399 for (prop = of_find_property(np, propname, NULL), \ 1400 s = of_prop_next_string(prop, NULL); \ 1401 s; \ 1402 s = of_prop_next_string(prop, s)) 1403 1404 #define for_each_node_by_name(dn, name) \ 1405 for (dn = of_find_node_by_name(NULL, name); dn; \ 1406 dn = of_find_node_by_name(dn, name)) 1407 #define for_each_node_by_type(dn, type) \ 1408 for (dn = of_find_node_by_type(NULL, type); dn; \ 1409 dn = of_find_node_by_type(dn, type)) 1410 #define for_each_compatible_node(dn, type, compatible) \ 1411 for (dn = of_find_compatible_node(NULL, type, compatible); dn; \ 1412 dn = of_find_compatible_node(dn, type, compatible)) 1413 #define for_each_matching_node(dn, matches) \ 1414 for (dn = of_find_matching_node(NULL, matches); dn; \ 1415 dn = of_find_matching_node(dn, matches)) 1416 #define for_each_matching_node_and_match(dn, matches, match) \ 1417 for (dn = of_find_matching_node_and_match(NULL, matches, match); \ 1418 dn; dn = of_find_matching_node_and_match(dn, matches, match)) 1419 1420 #define for_each_child_of_node(parent, child) \ 1421 for (child = of_get_next_child(parent, NULL); child != NULL; \ 1422 child = of_get_next_child(parent, child)) 1423 #define for_each_available_child_of_node(parent, child) \ 1424 for (child = of_get_next_available_child(parent, NULL); child != NULL; \ 1425 child = of_get_next_available_child(parent, child)) 1426 1427 #define for_each_of_cpu_node(cpu) \ 1428 for (cpu = of_get_next_cpu_node(NULL); cpu != NULL; \ 1429 cpu = of_get_next_cpu_node(cpu)) 1430 1431 #define for_each_node_with_property(dn, prop_name) \ 1432 for (dn = of_find_node_with_property(NULL, prop_name); dn; \ 1433 dn = of_find_node_with_property(dn, prop_name)) 1434 1435 static inline int of_get_child_count(const struct device_node *np) 1436 { 1437 struct device_node *child; 1438 int num = 0; 1439 1440 for_each_child_of_node(np, child) 1441 num++; 1442 1443 return num; 1444 } 1445 1446 static inline int of_get_available_child_count(const struct device_node *np) 1447 { 1448 struct device_node *child; 1449 int num = 0; 1450 1451 for_each_available_child_of_node(np, child) 1452 num++; 1453 1454 return num; 1455 } 1456 1457 #define _OF_DECLARE_STUB(table, name, compat, fn, fn_type) \ 1458 static const struct of_device_id __of_table_##name \ 1459 __attribute__((unused)) \ 1460 = { .compatible = compat, \ 1461 .data = (fn == (fn_type)NULL) ? fn : fn } 1462 1463 #if defined(CONFIG_OF) && !defined(MODULE) 1464 #define _OF_DECLARE(table, name, compat, fn, fn_type) \ 1465 static const struct of_device_id __of_table_##name \ 1466 __used __section("__" #table "_of_table") \ 1467 __aligned(__alignof__(struct of_device_id)) \ 1468 = { .compatible = compat, \ 1469 .data = (fn == (fn_type)NULL) ? fn : fn } 1470 #else 1471 #define _OF_DECLARE(table, name, compat, fn, fn_type) \ 1472 _OF_DECLARE_STUB(table, name, compat, fn, fn_type) 1473 #endif 1474 1475 typedef int (*of_init_fn_2)(struct device_node *, struct device_node *); 1476 typedef int (*of_init_fn_1_ret)(struct device_node *); 1477 typedef void (*of_init_fn_1)(struct device_node *); 1478 1479 #define OF_DECLARE_1(table, name, compat, fn) \ 1480 _OF_DECLARE(table, name, compat, fn, of_init_fn_1) 1481 #define OF_DECLARE_1_RET(table, name, compat, fn) \ 1482 _OF_DECLARE(table, name, compat, fn, of_init_fn_1_ret) 1483 #define OF_DECLARE_2(table, name, compat, fn) \ 1484 _OF_DECLARE(table, name, compat, fn, of_init_fn_2) 1485 1486 /** 1487 * struct of_changeset_entry - Holds a changeset entry 1488 * 1489 * @node: list_head for the log list 1490 * @action: notifier action 1491 * @np: pointer to the device node affected 1492 * @prop: pointer to the property affected 1493 * @old_prop: hold a pointer to the original property 1494 * 1495 * Every modification of the device tree during a changeset 1496 * is held in a list of of_changeset_entry structures. 1497 * That way we can recover from a partial application, or we can 1498 * revert the changeset 1499 */ 1500 struct of_changeset_entry { 1501 struct list_head node; 1502 unsigned long action; 1503 struct device_node *np; 1504 struct property *prop; 1505 struct property *old_prop; 1506 }; 1507 1508 /** 1509 * struct of_changeset - changeset tracker structure 1510 * 1511 * @entries: list_head for the changeset entries 1512 * 1513 * changesets are a convenient way to apply bulk changes to the 1514 * live tree. In case of an error, changes are rolled-back. 1515 * changesets live on after initial application, and if not 1516 * destroyed after use, they can be reverted in one single call. 1517 */ 1518 struct of_changeset { 1519 struct list_head entries; 1520 }; 1521 1522 enum of_reconfig_change { 1523 OF_RECONFIG_NO_CHANGE = 0, 1524 OF_RECONFIG_CHANGE_ADD, 1525 OF_RECONFIG_CHANGE_REMOVE, 1526 }; 1527 1528 struct notifier_block; 1529 1530 #ifdef CONFIG_OF_DYNAMIC 1531 extern int of_reconfig_notifier_register(struct notifier_block *); 1532 extern int of_reconfig_notifier_unregister(struct notifier_block *); 1533 extern int of_reconfig_notify(unsigned long, struct of_reconfig_data *rd); 1534 extern int of_reconfig_get_state_change(unsigned long action, 1535 struct of_reconfig_data *arg); 1536 1537 extern void of_changeset_init(struct of_changeset *ocs); 1538 extern void of_changeset_destroy(struct of_changeset *ocs); 1539 extern int of_changeset_apply(struct of_changeset *ocs); 1540 extern int of_changeset_revert(struct of_changeset *ocs); 1541 extern int of_changeset_action(struct of_changeset *ocs, 1542 unsigned long action, struct device_node *np, 1543 struct property *prop); 1544 1545 static inline int of_changeset_attach_node(struct of_changeset *ocs, 1546 struct device_node *np) 1547 { 1548 return of_changeset_action(ocs, OF_RECONFIG_ATTACH_NODE, np, NULL); 1549 } 1550 1551 static inline int of_changeset_detach_node(struct of_changeset *ocs, 1552 struct device_node *np) 1553 { 1554 return of_changeset_action(ocs, OF_RECONFIG_DETACH_NODE, np, NULL); 1555 } 1556 1557 static inline int of_changeset_add_property(struct of_changeset *ocs, 1558 struct device_node *np, struct property *prop) 1559 { 1560 return of_changeset_action(ocs, OF_RECONFIG_ADD_PROPERTY, np, prop); 1561 } 1562 1563 static inline int of_changeset_remove_property(struct of_changeset *ocs, 1564 struct device_node *np, struct property *prop) 1565 { 1566 return of_changeset_action(ocs, OF_RECONFIG_REMOVE_PROPERTY, np, prop); 1567 } 1568 1569 static inline int of_changeset_update_property(struct of_changeset *ocs, 1570 struct device_node *np, struct property *prop) 1571 { 1572 return of_changeset_action(ocs, OF_RECONFIG_UPDATE_PROPERTY, np, prop); 1573 } 1574 1575 struct device_node *of_changeset_create_node(struct of_changeset *ocs, 1576 struct device_node *parent, 1577 const char *full_name); 1578 int of_changeset_add_prop_string(struct of_changeset *ocs, 1579 struct device_node *np, 1580 const char *prop_name, const char *str); 1581 int of_changeset_add_prop_string_array(struct of_changeset *ocs, 1582 struct device_node *np, 1583 const char *prop_name, 1584 const char **str_array, size_t sz); 1585 int of_changeset_add_prop_u32_array(struct of_changeset *ocs, 1586 struct device_node *np, 1587 const char *prop_name, 1588 const u32 *array, size_t sz); 1589 static inline int of_changeset_add_prop_u32(struct of_changeset *ocs, 1590 struct device_node *np, 1591 const char *prop_name, 1592 const u32 val) 1593 { 1594 return of_changeset_add_prop_u32_array(ocs, np, prop_name, &val, 1); 1595 } 1596 1597 #else /* CONFIG_OF_DYNAMIC */ 1598 static inline int of_reconfig_notifier_register(struct notifier_block *nb) 1599 { 1600 return -EINVAL; 1601 } 1602 static inline int of_reconfig_notifier_unregister(struct notifier_block *nb) 1603 { 1604 return -EINVAL; 1605 } 1606 static inline int of_reconfig_notify(unsigned long action, 1607 struct of_reconfig_data *arg) 1608 { 1609 return -EINVAL; 1610 } 1611 static inline int of_reconfig_get_state_change(unsigned long action, 1612 struct of_reconfig_data *arg) 1613 { 1614 return -EINVAL; 1615 } 1616 #endif /* CONFIG_OF_DYNAMIC */ 1617 1618 /** 1619 * of_device_is_system_power_controller - Tells if system-power-controller is found for device_node 1620 * @np: Pointer to the given device_node 1621 * 1622 * Return: true if present false otherwise 1623 */ 1624 static inline bool of_device_is_system_power_controller(const struct device_node *np) 1625 { 1626 return of_property_read_bool(np, "system-power-controller"); 1627 } 1628 1629 /** 1630 * of_have_populated_dt() - Has DT been populated by bootloader 1631 * 1632 * Return: True if a DTB has been populated by the bootloader and it isn't the 1633 * empty builtin one. False otherwise. 1634 */ 1635 static inline bool of_have_populated_dt(void) 1636 { 1637 #ifdef CONFIG_OF 1638 return of_property_present(of_root, "compatible"); 1639 #else 1640 return false; 1641 #endif 1642 } 1643 1644 /* 1645 * Overlay support 1646 */ 1647 1648 enum of_overlay_notify_action { 1649 OF_OVERLAY_INIT = 0, /* kzalloc() of ovcs sets this value */ 1650 OF_OVERLAY_PRE_APPLY, 1651 OF_OVERLAY_POST_APPLY, 1652 OF_OVERLAY_PRE_REMOVE, 1653 OF_OVERLAY_POST_REMOVE, 1654 }; 1655 1656 static inline const char *of_overlay_action_name(enum of_overlay_notify_action action) 1657 { 1658 static const char *const of_overlay_action_name[] = { 1659 "init", 1660 "pre-apply", 1661 "post-apply", 1662 "pre-remove", 1663 "post-remove", 1664 }; 1665 1666 return of_overlay_action_name[action]; 1667 } 1668 1669 struct of_overlay_notify_data { 1670 struct device_node *overlay; 1671 struct device_node *target; 1672 }; 1673 1674 #ifdef CONFIG_OF_OVERLAY 1675 1676 int of_overlay_fdt_apply(const void *overlay_fdt, u32 overlay_fdt_size, 1677 int *ovcs_id, struct device_node *target_base); 1678 int of_overlay_remove(int *ovcs_id); 1679 int of_overlay_remove_all(void); 1680 1681 int of_overlay_notifier_register(struct notifier_block *nb); 1682 int of_overlay_notifier_unregister(struct notifier_block *nb); 1683 1684 #else 1685 1686 static inline int of_overlay_fdt_apply(const void *overlay_fdt, u32 overlay_fdt_size, 1687 int *ovcs_id, struct device_node *target_base) 1688 { 1689 return -ENOTSUPP; 1690 } 1691 1692 static inline int of_overlay_remove(int *ovcs_id) 1693 { 1694 return -ENOTSUPP; 1695 } 1696 1697 static inline int of_overlay_remove_all(void) 1698 { 1699 return -ENOTSUPP; 1700 } 1701 1702 static inline int of_overlay_notifier_register(struct notifier_block *nb) 1703 { 1704 return 0; 1705 } 1706 1707 static inline int of_overlay_notifier_unregister(struct notifier_block *nb) 1708 { 1709 return 0; 1710 } 1711 1712 #endif 1713 1714 #endif /* _LINUX_OF_H */ 1715