prom.h 6.6 KB

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