prom.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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 /* 4: version, 4: total size */
  23. #define OF_DT_BEGIN_NODE 0x1 /* Start node: full name */
  24. #define OF_DT_END_NODE 0x2 /* End node */
  25. #define OF_DT_PROP 0x3 /* Property: name off, size, content */
  26. #define OF_DT_END 0x9
  27. #define OF_DT_VERSION 1
  28. /*
  29. * This is what gets passed to the kernel by prom_init or kexec
  30. *
  31. * The dt struct contains the device tree structure, full pathes and
  32. * property contents. The dt strings contain a separate block with just
  33. * the strings for the property names, and is fully page aligned and
  34. * self contained in a page, so that it can be kept around by the kernel,
  35. * each property name appears only once in this page (cheap compression)
  36. *
  37. * the mem_rsvmap contains a map of reserved ranges of physical memory,
  38. * passing it here instead of in the device-tree itself greatly simplifies
  39. * the job of everybody. It's just a list of u64 pairs (base/size) that
  40. * ends when size is 0
  41. */
  42. struct boot_param_header
  43. {
  44. u32 magic; /* magic word OF_DT_HEADER */
  45. u32 totalsize; /* total size of DT block */
  46. u32 off_dt_struct; /* offset to structure */
  47. u32 off_dt_strings; /* offset to strings */
  48. u32 off_mem_rsvmap; /* offset to memory reserve map */
  49. u32 version; /* format version */
  50. u32 last_comp_version; /* last compatible version */
  51. /* version 2 fields below */
  52. u32 boot_cpuid_phys; /* Which physical CPU id we're booting on */
  53. };
  54. typedef u32 phandle;
  55. typedef u32 ihandle;
  56. struct address_range {
  57. unsigned long space;
  58. unsigned long address;
  59. unsigned long size;
  60. };
  61. struct interrupt_info {
  62. int line;
  63. int sense; /* +ve/-ve logic, edge or level, etc. */
  64. };
  65. struct pci_address {
  66. u32 a_hi;
  67. u32 a_mid;
  68. u32 a_lo;
  69. };
  70. struct isa_address {
  71. u32 a_hi;
  72. u32 a_lo;
  73. };
  74. struct isa_range {
  75. struct isa_address isa_addr;
  76. struct pci_address pci_addr;
  77. unsigned int size;
  78. };
  79. struct reg_property {
  80. unsigned long address;
  81. unsigned long size;
  82. };
  83. struct reg_property32 {
  84. unsigned int address;
  85. unsigned int size;
  86. };
  87. struct reg_property64 {
  88. unsigned long address;
  89. unsigned long size;
  90. };
  91. struct property {
  92. char *name;
  93. int length;
  94. unsigned char *value;
  95. struct property *next;
  96. };
  97. /* NOTE: the device_node contains PCI specific info for pci devices.
  98. * This perhaps could be hung off the device_node with another struct,
  99. * but for now it is directly in the node. The phb ptr is a good
  100. * indication of a real PCI node. Other nodes leave these fields zeroed.
  101. */
  102. struct pci_controller;
  103. struct iommu_table;
  104. struct device_node {
  105. char *name;
  106. char *type;
  107. phandle node;
  108. phandle linux_phandle;
  109. int n_addrs;
  110. struct address_range *addrs;
  111. int n_intrs;
  112. struct interrupt_info *intrs;
  113. char *full_name;
  114. /* PCI stuff probably doesn't belong here */
  115. int busno; /* for pci devices */
  116. int bussubno; /* for pci devices */
  117. int devfn; /* for pci devices */
  118. int eeh_mode; /* See eeh.h for possible EEH_MODEs */
  119. int eeh_config_addr;
  120. int pci_ext_config_space; /* for pci devices */
  121. struct pci_controller *phb; /* for pci devices */
  122. struct iommu_table *iommu_table; /* for phb's or bridges */
  123. struct property *properties;
  124. struct device_node *parent;
  125. struct device_node *child;
  126. struct device_node *sibling;
  127. struct device_node *next; /* next device of same type */
  128. struct device_node *allnext; /* next in list of all nodes */
  129. struct proc_dir_entry *pde; /* this node's proc directory */
  130. struct kref kref;
  131. unsigned long _flags;
  132. };
  133. extern struct device_node *of_chosen;
  134. /* flag descriptions */
  135. #define OF_DYNAMIC 1 /* node and properties were allocated via kmalloc */
  136. #define OF_IS_DYNAMIC(x) test_bit(OF_DYNAMIC, &x->_flags)
  137. #define OF_MARK_DYNAMIC(x) set_bit(OF_DYNAMIC, &x->_flags)
  138. /*
  139. * Until 32-bit ppc can add proc_dir_entries to its device_node
  140. * definition, we cannot refer to pde, name_link, and addr_link
  141. * in arch-independent code.
  142. */
  143. #define HAVE_ARCH_DEVTREE_FIXUPS
  144. static inline void set_node_proc_entry(struct device_node *dn, struct proc_dir_entry *de)
  145. {
  146. dn->pde = de;
  147. }
  148. /* OBSOLETE: Old stlye node lookup */
  149. extern struct device_node *find_devices(const char *name);
  150. extern struct device_node *find_type_devices(const char *type);
  151. extern struct device_node *find_path_device(const char *path);
  152. extern struct device_node *find_compatible_devices(const char *type,
  153. const char *compat);
  154. extern struct device_node *find_all_nodes(void);
  155. /* New style node lookup */
  156. extern struct device_node *of_find_node_by_name(struct device_node *from,
  157. const char *name);
  158. extern struct device_node *of_find_node_by_type(struct device_node *from,
  159. const char *type);
  160. extern struct device_node *of_find_compatible_node(struct device_node *from,
  161. const char *type, const char *compat);
  162. extern struct device_node *of_find_node_by_path(const char *path);
  163. extern struct device_node *of_find_node_by_phandle(phandle handle);
  164. extern struct device_node *of_find_all_nodes(struct device_node *prev);
  165. extern struct device_node *of_get_parent(const struct device_node *node);
  166. extern struct device_node *of_get_next_child(const struct device_node *node,
  167. struct device_node *prev);
  168. extern struct device_node *of_node_get(struct device_node *node);
  169. extern void of_node_put(struct device_node *node);
  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 void prom_add_property(struct device_node* np, struct property* prop);
  187. #endif /* _PPC64_PROM_H */