prom.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. #ifndef _POWERPC_PROM_H
  2. #define _POWERPC_PROM_H
  3. #ifdef __KERNEL__
  4. /*
  5. * Definitions for talking to the Open Firmware PROM on
  6. * Power Macintosh computers.
  7. *
  8. * Copyright (C) 1996-2005 Paul Mackerras.
  9. *
  10. * Updates for PPC64 by Peter Bergner & David Engebretsen, IBM Corp.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License
  14. * as published by the Free Software Foundation; either version
  15. * 2 of the License, or (at your option) any later version.
  16. */
  17. #include <linux/config.h>
  18. #include <linux/types.h>
  19. #include <linux/proc_fs.h>
  20. #include <asm/atomic.h>
  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 interrupt_info {
  61. int line;
  62. int sense; /* +ve/-ve logic, edge or level, etc. */
  63. };
  64. struct property {
  65. char *name;
  66. int length;
  67. unsigned char *value;
  68. struct property *next;
  69. };
  70. struct device_node {
  71. char *name;
  72. char *type;
  73. phandle node;
  74. phandle linux_phandle;
  75. int n_intrs;
  76. struct interrupt_info *intrs;
  77. char *full_name;
  78. struct property *properties;
  79. struct property *deadprops; /* removed properties */
  80. struct device_node *parent;
  81. struct device_node *child;
  82. struct device_node *sibling;
  83. struct device_node *next; /* next device of same type */
  84. struct device_node *allnext; /* next in list of all nodes */
  85. struct proc_dir_entry *pde; /* this node's proc directory */
  86. struct kref kref;
  87. unsigned long _flags;
  88. void *data;
  89. };
  90. extern struct device_node *of_chosen;
  91. /* flag descriptions */
  92. #define OF_DYNAMIC 1 /* node and properties were allocated via kmalloc */
  93. #define OF_IS_DYNAMIC(x) test_bit(OF_DYNAMIC, &x->_flags)
  94. #define OF_MARK_DYNAMIC(x) set_bit(OF_DYNAMIC, &x->_flags)
  95. #define HAVE_ARCH_DEVTREE_FIXUPS
  96. static inline void set_node_proc_entry(struct device_node *dn, struct proc_dir_entry *de)
  97. {
  98. dn->pde = de;
  99. }
  100. /* OBSOLETE: Old style node lookup */
  101. extern struct device_node *find_devices(const char *name);
  102. extern struct device_node *find_type_devices(const char *type);
  103. extern struct device_node *find_path_device(const char *path);
  104. extern struct device_node *find_compatible_devices(const char *type,
  105. const char *compat);
  106. extern struct device_node *find_all_nodes(void);
  107. /* New style node lookup */
  108. extern struct device_node *of_find_node_by_name(struct device_node *from,
  109. const char *name);
  110. extern struct device_node *of_find_node_by_type(struct device_node *from,
  111. const char *type);
  112. extern struct device_node *of_find_compatible_node(struct device_node *from,
  113. const char *type, const char *compat);
  114. extern struct device_node *of_find_node_by_path(const char *path);
  115. extern struct device_node *of_find_node_by_phandle(phandle handle);
  116. extern struct device_node *of_find_all_nodes(struct device_node *prev);
  117. extern struct device_node *of_get_parent(const struct device_node *node);
  118. extern struct device_node *of_get_next_child(const struct device_node *node,
  119. struct device_node *prev);
  120. extern struct property *of_find_property(struct device_node *np,
  121. const char *name,
  122. int *lenp);
  123. extern struct device_node *of_node_get(struct device_node *node);
  124. extern void of_node_put(struct device_node *node);
  125. /* For scanning the flat device-tree at boot time */
  126. int __init of_scan_flat_dt(int (*it)(unsigned long node,
  127. const char *uname, int depth,
  128. void *data),
  129. void *data);
  130. void* __init of_get_flat_dt_prop(unsigned long node, const char *name,
  131. unsigned long *size);
  132. /* For updating the device tree at runtime */
  133. extern void of_attach_node(struct device_node *);
  134. extern void of_detach_node(const struct device_node *);
  135. /* Other Prototypes */
  136. extern void finish_device_tree(void);
  137. extern void unflatten_device_tree(void);
  138. extern void early_init_devtree(void *);
  139. extern int device_is_compatible(struct device_node *device, const char *);
  140. extern int machine_is_compatible(const char *compat);
  141. extern unsigned char *get_property(struct device_node *node, const char *name,
  142. int *lenp);
  143. extern void print_properties(struct device_node *node);
  144. extern int prom_n_addr_cells(struct device_node* np);
  145. extern int prom_n_size_cells(struct device_node* np);
  146. extern int prom_n_intr_cells(struct device_node* np);
  147. extern void prom_get_irq_senses(unsigned char *senses, int off, int max);
  148. extern int prom_add_property(struct device_node* np, struct property* prop);
  149. extern int prom_remove_property(struct device_node *np, struct property *prop);
  150. extern int prom_update_property(struct device_node *np,
  151. struct property *newprop,
  152. struct property *oldprop);
  153. #ifdef CONFIG_PPC32
  154. /*
  155. * PCI <-> OF matching functions
  156. * (XXX should these be here?)
  157. */
  158. struct pci_bus;
  159. struct pci_dev;
  160. extern int pci_device_from_OF_node(struct device_node *node,
  161. u8* bus, u8* devfn);
  162. extern struct device_node* pci_busdev_to_OF_node(struct pci_bus *, int);
  163. extern struct device_node* pci_device_to_OF_node(struct pci_dev *);
  164. extern void pci_create_OF_bus_map(void);
  165. #endif
  166. extern struct resource *request_OF_resource(struct device_node* node,
  167. int index, const char* name_postfix);
  168. extern int release_OF_resource(struct device_node* node, int index);
  169. /*
  170. * OF address retreival & translation
  171. */
  172. /* Translate an OF address block into a CPU physical address
  173. */
  174. #define OF_BAD_ADDR ((u64)-1)
  175. extern u64 of_translate_address(struct device_node *np, u32 *addr);
  176. /* Extract an address from a device, returns the region size and
  177. * the address space flags too. The PCI version uses a BAR number
  178. * instead of an absolute index
  179. */
  180. extern u32 *of_get_address(struct device_node *dev, int index,
  181. u64 *size, unsigned int *flags);
  182. extern u32 *of_get_pci_address(struct device_node *dev, int bar_no,
  183. u64 *size, unsigned int *flags);
  184. /* Get an address as a resource. Note that if your address is
  185. * a PIO address, the conversion will fail if the physical address
  186. * can't be internally converted to an IO token with
  187. * pci_address_to_pio(), that is because it's either called to early
  188. * or it can't be matched to any host bridge IO space
  189. */
  190. extern int of_address_to_resource(struct device_node *dev, int index,
  191. struct resource *r);
  192. extern int of_pci_address_to_resource(struct device_node *dev, int bar,
  193. struct resource *r);
  194. #endif /* __KERNEL__ */
  195. #endif /* _POWERPC_PROM_H */