prom.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. #ifndef _PPC64_PROM_H
  2. #define _PPC64_PROM_H
  3. /*
  4. * Definitions for talking to the Open Firmware PROM on
  5. * Power Macintosh computers.
  6. *
  7. * Copyright (C) 1996 Paul Mackerras.
  8. *
  9. * Updates for PPC64 by Peter Bergner & David Engebretsen, IBM Corp.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License
  13. * as published by the Free Software Foundation; either version
  14. * 2 of the License, or (at your option) any later version.
  15. */
  16. #include <linux/proc_fs.h>
  17. #include <asm/atomic.h>
  18. #define PTRRELOC(x) ((typeof(x))((unsigned long)(x) - offset))
  19. #define PTRUNRELOC(x) ((typeof(x))((unsigned long)(x) + offset))
  20. #define RELOC(x) (*PTRRELOC(&(x)))
  21. /* Definitions used by the flattened device tree */
  22. #define OF_DT_HEADER 0xd00dfeed /* marker */
  23. #define OF_DT_BEGIN_NODE 0x1 /* Start of node, full name */
  24. #define OF_DT_END_NODE 0x2 /* End node */
  25. #define OF_DT_PROP 0x3 /* Property: name off, size,
  26. * content */
  27. #define OF_DT_NOP 0x4 /* nop */
  28. #define OF_DT_END 0x9
  29. #define OF_DT_VERSION 0x10
  30. /*
  31. * This is what gets passed to the kernel by prom_init or kexec
  32. *
  33. * The dt struct contains the device tree structure, full pathes and
  34. * property contents. The dt strings contain a separate block with just
  35. * the strings for the property names, and is fully page aligned and
  36. * self contained in a page, so that it can be kept around by the kernel,
  37. * each property name appears only once in this page (cheap compression)
  38. *
  39. * the mem_rsvmap contains a map of reserved ranges of physical memory,
  40. * passing it here instead of in the device-tree itself greatly simplifies
  41. * the job of everybody. It's just a list of u64 pairs (base/size) that
  42. * ends when size is 0
  43. */
  44. struct boot_param_header
  45. {
  46. u32 magic; /* magic word OF_DT_HEADER */
  47. u32 totalsize; /* total size of DT block */
  48. u32 off_dt_struct; /* offset to structure */
  49. u32 off_dt_strings; /* offset to strings */
  50. u32 off_mem_rsvmap; /* offset to memory reserve map */
  51. u32 version; /* format version */
  52. u32 last_comp_version; /* last compatible version */
  53. /* version 2 fields below */
  54. u32 boot_cpuid_phys; /* Physical CPU id we're booting on */
  55. /* version 3 fields below */
  56. u32 dt_strings_size; /* size of the DT strings block */
  57. };
  58. typedef u32 phandle;
  59. typedef u32 ihandle;
  60. struct address_range {
  61. unsigned long space;
  62. unsigned long address;
  63. unsigned long size;
  64. };
  65. struct interrupt_info {
  66. int line;
  67. int sense; /* +ve/-ve logic, edge or level, etc. */
  68. };
  69. struct pci_address {
  70. u32 a_hi;
  71. u32 a_mid;
  72. u32 a_lo;
  73. };
  74. struct isa_address {
  75. u32 a_hi;
  76. u32 a_lo;
  77. };
  78. struct isa_range {
  79. struct isa_address isa_addr;
  80. struct pci_address pci_addr;
  81. unsigned int size;
  82. };
  83. struct reg_property {
  84. unsigned long address;
  85. unsigned long size;
  86. };
  87. struct reg_property32 {
  88. unsigned int address;
  89. unsigned int size;
  90. };
  91. struct reg_property64 {
  92. unsigned long address;
  93. unsigned long size;
  94. };
  95. struct property {
  96. char *name;
  97. int length;
  98. unsigned char *value;
  99. struct property *next;
  100. };
  101. struct device_node {
  102. char *name;
  103. char *type;
  104. phandle node;
  105. phandle linux_phandle;
  106. int n_addrs;
  107. struct address_range *addrs;
  108. int n_intrs;
  109. struct interrupt_info *intrs;
  110. char *full_name;
  111. struct property *properties;
  112. struct device_node *parent;
  113. struct device_node *child;
  114. struct device_node *sibling;
  115. struct device_node *next; /* next device of same type */
  116. struct device_node *allnext; /* next in list of all nodes */
  117. struct proc_dir_entry *pde; /* this node's proc directory */
  118. struct kref kref;
  119. unsigned long _flags;
  120. void *data;
  121. };
  122. extern struct device_node *of_chosen;
  123. /* flag descriptions */
  124. #define OF_DYNAMIC 1 /* node and properties were allocated via kmalloc */
  125. #define OF_IS_DYNAMIC(x) test_bit(OF_DYNAMIC, &x->_flags)
  126. #define OF_MARK_DYNAMIC(x) set_bit(OF_DYNAMIC, &x->_flags)
  127. /*
  128. * Until 32-bit ppc can add proc_dir_entries to its device_node
  129. * definition, we cannot refer to pde, name_link, and addr_link
  130. * in arch-independent code.
  131. */
  132. #define HAVE_ARCH_DEVTREE_FIXUPS
  133. static inline void set_node_proc_entry(struct device_node *dn, struct proc_dir_entry *de)
  134. {
  135. dn->pde = de;
  136. }
  137. /* OBSOLETE: Old stlye node lookup */
  138. extern struct device_node *find_devices(const char *name);
  139. extern struct device_node *find_type_devices(const char *type);
  140. extern struct device_node *find_path_device(const char *path);
  141. extern struct device_node *find_compatible_devices(const char *type,
  142. const char *compat);
  143. extern struct device_node *find_all_nodes(void);
  144. /* New style node lookup */
  145. extern struct device_node *of_find_node_by_name(struct device_node *from,
  146. const char *name);
  147. extern struct device_node *of_find_node_by_type(struct device_node *from,
  148. const char *type);
  149. extern struct device_node *of_find_compatible_node(struct device_node *from,
  150. const char *type, const char *compat);
  151. extern struct device_node *of_find_node_by_path(const char *path);
  152. extern struct device_node *of_find_node_by_phandle(phandle handle);
  153. extern struct device_node *of_find_all_nodes(struct device_node *prev);
  154. extern struct device_node *of_get_parent(const struct device_node *node);
  155. extern struct device_node *of_get_next_child(const struct device_node *node,
  156. struct device_node *prev);
  157. extern struct device_node *of_node_get(struct device_node *node);
  158. extern void of_node_put(struct device_node *node);
  159. /* For updating the device tree at runtime */
  160. extern void of_attach_node(struct device_node *);
  161. extern void of_detach_node(const struct device_node *);
  162. /* Other Prototypes */
  163. extern unsigned long prom_init(unsigned long, unsigned long, unsigned long,
  164. unsigned long, unsigned long);
  165. extern void finish_device_tree(void);
  166. extern int device_is_compatible(struct device_node *device, const char *);
  167. extern int machine_is_compatible(const char *compat);
  168. extern unsigned char *get_property(struct device_node *node, const char *name,
  169. int *lenp);
  170. extern void print_properties(struct device_node *node);
  171. extern int prom_n_addr_cells(struct device_node* np);
  172. extern int prom_n_size_cells(struct device_node* np);
  173. extern int prom_n_intr_cells(struct device_node* np);
  174. extern void prom_get_irq_senses(unsigned char *senses, int off, int max);
  175. extern void prom_add_property(struct device_node* np, struct property* prop);
  176. #endif /* _PPC64_PROM_H */