prom.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. /* NOTE: the device_node contains PCI specific info for pci devices.
  102. * This perhaps could be hung off the device_node with another struct,
  103. * but for now it is directly in the node. The phb ptr is a good
  104. * indication of a real PCI node. Other nodes leave these fields zeroed.
  105. */
  106. struct pci_controller;
  107. struct iommu_table;
  108. struct device_node {
  109. char *name;
  110. char *type;
  111. phandle node;
  112. phandle linux_phandle;
  113. int n_addrs;
  114. struct address_range *addrs;
  115. int n_intrs;
  116. struct interrupt_info *intrs;
  117. char *full_name;
  118. /* PCI stuff probably doesn't belong here */
  119. int busno; /* for pci devices */
  120. int bussubno; /* for pci devices */
  121. int devfn; /* for pci devices */
  122. int eeh_mode; /* See eeh.h for possible EEH_MODEs */
  123. int eeh_config_addr;
  124. int pci_ext_config_space; /* for pci devices */
  125. struct pci_controller *phb; /* for pci devices */
  126. struct iommu_table *iommu_table; /* for phb's or bridges */
  127. struct property *properties;
  128. struct device_node *parent;
  129. struct device_node *child;
  130. struct device_node *sibling;
  131. struct device_node *next; /* next device of same type */
  132. struct device_node *allnext; /* next in list of all nodes */
  133. struct proc_dir_entry *pde; /* this node's proc directory */
  134. struct kref kref;
  135. unsigned long _flags;
  136. };
  137. extern struct device_node *of_chosen;
  138. /* flag descriptions */
  139. #define OF_DYNAMIC 1 /* node and properties were allocated via kmalloc */
  140. #define OF_IS_DYNAMIC(x) test_bit(OF_DYNAMIC, &x->_flags)
  141. #define OF_MARK_DYNAMIC(x) set_bit(OF_DYNAMIC, &x->_flags)
  142. /*
  143. * Until 32-bit ppc can add proc_dir_entries to its device_node
  144. * definition, we cannot refer to pde, name_link, and addr_link
  145. * in arch-independent code.
  146. */
  147. #define HAVE_ARCH_DEVTREE_FIXUPS
  148. static inline void set_node_proc_entry(struct device_node *dn, struct proc_dir_entry *de)
  149. {
  150. dn->pde = de;
  151. }
  152. /* OBSOLETE: Old stlye node lookup */
  153. extern struct device_node *find_devices(const char *name);
  154. extern struct device_node *find_type_devices(const char *type);
  155. extern struct device_node *find_path_device(const char *path);
  156. extern struct device_node *find_compatible_devices(const char *type,
  157. const char *compat);
  158. extern struct device_node *find_all_nodes(void);
  159. /* New style node lookup */
  160. extern struct device_node *of_find_node_by_name(struct device_node *from,
  161. const char *name);
  162. extern struct device_node *of_find_node_by_type(struct device_node *from,
  163. const char *type);
  164. extern struct device_node *of_find_compatible_node(struct device_node *from,
  165. const char *type, const char *compat);
  166. extern struct device_node *of_find_node_by_path(const char *path);
  167. extern struct device_node *of_find_node_by_phandle(phandle handle);
  168. extern struct device_node *of_find_all_nodes(struct device_node *prev);
  169. extern struct device_node *of_get_parent(const struct device_node *node);
  170. extern struct device_node *of_get_next_child(const struct device_node *node,
  171. struct device_node *prev);
  172. extern struct device_node *of_node_get(struct device_node *node);
  173. extern void of_node_put(struct device_node *node);
  174. /* For updating the device tree at runtime */
  175. extern void of_attach_node(struct device_node *);
  176. extern void of_detach_node(const struct device_node *);
  177. /* Other Prototypes */
  178. extern unsigned long prom_init(unsigned long, unsigned long, unsigned long,
  179. unsigned long, unsigned long);
  180. extern void finish_device_tree(void);
  181. extern int device_is_compatible(struct device_node *device, const char *);
  182. extern int machine_is_compatible(const char *compat);
  183. extern unsigned char *get_property(struct device_node *node, const char *name,
  184. int *lenp);
  185. extern void print_properties(struct device_node *node);
  186. extern int prom_n_addr_cells(struct device_node* np);
  187. extern int prom_n_size_cells(struct device_node* np);
  188. extern int prom_n_intr_cells(struct device_node* np);
  189. extern void prom_get_irq_senses(unsigned char *senses, int off, int max);
  190. extern void prom_add_property(struct device_node* np, struct property* prop);
  191. #endif /* _PPC64_PROM_H */