prom.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. * Definitions for talking to the Open Firmware PROM on
  3. * Power Macintosh computers.
  4. *
  5. * Copyright (C) 1996 Paul Mackerras.
  6. */
  7. #ifdef __KERNEL__
  8. #ifndef _PPC_PROM_H
  9. #define _PPC_PROM_H
  10. #include <linux/config.h>
  11. #include <linux/types.h>
  12. typedef u32 phandle;
  13. typedef u32 ihandle;
  14. struct address_range {
  15. unsigned int space;
  16. unsigned int address;
  17. unsigned int size;
  18. };
  19. struct interrupt_info {
  20. int line;
  21. int sense; /* +ve/-ve logic, edge or level, etc. */
  22. };
  23. struct reg_property {
  24. unsigned int address;
  25. unsigned int size;
  26. };
  27. struct property {
  28. char *name;
  29. int length;
  30. unsigned char *value;
  31. struct property *next;
  32. };
  33. /*
  34. * Note: don't change this structure for now or you'll break BootX !
  35. */
  36. struct device_node {
  37. char *name;
  38. char *type;
  39. phandle node;
  40. int n_addrs;
  41. struct address_range *addrs;
  42. int n_intrs;
  43. struct interrupt_info *intrs;
  44. char *full_name;
  45. struct property *properties;
  46. struct device_node *parent;
  47. struct device_node *child;
  48. struct device_node *sibling;
  49. struct device_node *next; /* next device of same type */
  50. struct device_node *allnext; /* next in list of all nodes */
  51. };
  52. struct prom_args;
  53. typedef void (*prom_entry)(struct prom_args *);
  54. /* OBSOLETE: Old style node lookup */
  55. extern struct device_node *find_devices(const char *name);
  56. extern struct device_node *find_type_devices(const char *type);
  57. extern struct device_node *find_path_device(const char *path);
  58. extern struct device_node *find_compatible_devices(const char *type,
  59. const char *compat);
  60. extern struct device_node *find_all_nodes(void);
  61. /* New style node lookup */
  62. extern struct device_node *of_find_node_by_name(struct device_node *from,
  63. const char *name);
  64. extern struct device_node *of_find_node_by_type(struct device_node *from,
  65. const char *type);
  66. extern struct device_node *of_find_compatible_node(struct device_node *from,
  67. const char *type, const char *compat);
  68. extern struct device_node *of_find_node_by_path(const char *path);
  69. extern struct device_node *of_find_all_nodes(struct device_node *prev);
  70. extern struct device_node *of_get_parent(const struct device_node *node);
  71. extern struct device_node *of_get_next_child(const struct device_node *node,
  72. struct device_node *prev);
  73. extern struct device_node *of_node_get(struct device_node *node);
  74. extern void of_node_put(struct device_node *node);
  75. /* Other Prototypes */
  76. extern void abort(void);
  77. extern unsigned long prom_init(int, int, prom_entry);
  78. extern void prom_print(const char *msg);
  79. extern void relocate_nodes(void);
  80. extern void finish_device_tree(void);
  81. extern int device_is_compatible(struct device_node *device, const char *);
  82. extern int machine_is_compatible(const char *compat);
  83. extern unsigned char *get_property(struct device_node *node, const char *name,
  84. int *lenp);
  85. extern int prom_add_property(struct device_node* np, struct property* prop);
  86. extern void prom_get_irq_senses(unsigned char *, int, int);
  87. extern int prom_n_addr_cells(struct device_node* np);
  88. extern int prom_n_size_cells(struct device_node* np);
  89. extern struct resource*
  90. request_OF_resource(struct device_node* node, int index, const char* name_postfix);
  91. extern int release_OF_resource(struct device_node* node, int index);
  92. extern void print_properties(struct device_node *node);
  93. extern int call_rtas(const char *service, int nargs, int nret,
  94. unsigned long *outputs, ...);
  95. /*
  96. * PCI <-> OF matching functions
  97. */
  98. struct pci_bus;
  99. struct pci_dev;
  100. extern int pci_device_from_OF_node(struct device_node *node,
  101. u8* bus, u8* devfn);
  102. extern struct device_node* pci_busdev_to_OF_node(struct pci_bus *, int);
  103. extern struct device_node* pci_device_to_OF_node(struct pci_dev *);
  104. extern void pci_create_OF_bus_map(void);
  105. /*
  106. * When we call back to the Open Firmware client interface, we usually
  107. * have to do that before the kernel is relocated to its final location
  108. * (this is because we can't use OF after we have overwritten the
  109. * exception vectors with our exception handlers). These macros assist
  110. * in performing the address calculations that we need to do to access
  111. * data when the kernel is running at an address that is different from
  112. * the address that the kernel is linked at. The reloc_offset() function
  113. * returns the difference between these two addresses and the macros
  114. * simplify the process of adding or subtracting this offset to/from
  115. * pointer values. See arch/ppc/kernel/prom.c for how these are used.
  116. */
  117. extern unsigned long reloc_offset(void);
  118. extern unsigned long add_reloc_offset(unsigned long);
  119. extern unsigned long sub_reloc_offset(unsigned long);
  120. #define PTRRELOC(x) ((typeof(x))add_reloc_offset((unsigned long)(x)))
  121. #define PTRUNRELOC(x) ((typeof(x))sub_reloc_offset((unsigned long)(x)))
  122. /*
  123. * OF address retreival & translation
  124. */
  125. /* Translate an OF address block into a CPU physical address
  126. */
  127. #define OF_BAD_ADDR ((u64)-1)
  128. extern u64 of_translate_address(struct device_node *np, u32 *addr);
  129. /* Extract an address from a device, returns the region size and
  130. * the address space flags too. The PCI version uses a BAR number
  131. * instead of an absolute index
  132. */
  133. extern u32 *of_get_address(struct device_node *dev, int index,
  134. u64 *size, unsigned int *flags);
  135. extern u32 *of_get_pci_address(struct device_node *dev, int bar_no,
  136. u64 *size, unsigned int *flags);
  137. /* Get an address as a resource. Note that if your address is
  138. * a PIO address, the conversion will fail if the physical address
  139. * can't be internally converted to an IO token with
  140. * pci_address_to_pio(), that is because it's either called to early
  141. * or it can't be matched to any host bridge IO space
  142. */
  143. extern int of_address_to_resource(struct device_node *dev, int index,
  144. struct resource *r);
  145. extern int of_pci_address_to_resource(struct device_node *dev, int bar,
  146. struct resource *r);
  147. #ifndef CONFIG_PPC_OF
  148. /*
  149. * Fallback definitions for builds where we don't have prom.c included.
  150. */
  151. #define machine_is_compatible(x) 0
  152. #define of_find_compatible_node(f, t, c) NULL
  153. #define get_property(p, n, l) NULL
  154. #endif
  155. #endif /* _PPC_PROM_H */
  156. #endif /* __KERNEL__ */