ieee1275.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. /* ieee1275.h - Access the Open Firmware client interface. */
  2. /*
  3. * GRUB -- GRand Unified Bootloader
  4. * Copyright (C) 2003,2004,2005,2007,2008,2009 Free Software Foundation, Inc.
  5. *
  6. * GRUB is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * GRUB is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef GRUB_IEEE1275_HEADER
  20. #define GRUB_IEEE1275_HEADER 1
  21. #include <grub/err.h>
  22. #include <grub/types.h>
  23. #include <grub/machine/ieee1275.h>
  24. #define GRUB_IEEE1275_CELL_FALSE ((grub_ieee1275_cell_t) 0)
  25. #define GRUB_IEEE1275_CELL_TRUE ((grub_ieee1275_cell_t) -1)
  26. struct grub_ieee1275_mem_region
  27. {
  28. unsigned int start;
  29. unsigned int size;
  30. };
  31. #define IEEE1275_MAX_PROP_LEN 8192
  32. #define IEEE1275_MAX_PATH_LEN 256
  33. #ifndef IEEE1275_CALL_ENTRY_FN
  34. #define IEEE1275_CALL_ENTRY_FN(args) (*grub_ieee1275_entry_fn) (args)
  35. #endif
  36. /* All backcalls to the firmware is done by calling an entry function
  37. which was passed to us from the bootloader. When doing the backcall,
  38. a structure is passed which specifies what the firmware should do.
  39. NAME is the requested service. NR_INS and NR_OUTS is the number of
  40. passed arguments and the expected number of return values, resp. */
  41. struct grub_ieee1275_common_hdr
  42. {
  43. grub_ieee1275_cell_t name;
  44. grub_ieee1275_cell_t nr_ins;
  45. grub_ieee1275_cell_t nr_outs;
  46. };
  47. #define INIT_IEEE1275_COMMON(p, xname, xins, xouts) \
  48. (p)->name = (grub_ieee1275_cell_t) xname; \
  49. (p)->nr_ins = (grub_ieee1275_cell_t) xins; \
  50. (p)->nr_outs = (grub_ieee1275_cell_t) xouts
  51. typedef grub_uint32_t grub_ieee1275_ihandle_t;
  52. typedef grub_uint32_t grub_ieee1275_phandle_t;
  53. #define GRUB_IEEE1275_IHANDLE_INVALID ((grub_ieee1275_ihandle_t) 0)
  54. #define GRUB_IEEE1275_PHANDLE_INVALID ((grub_ieee1275_phandle_t) -1)
  55. struct grub_ieee1275_devalias
  56. {
  57. char *name;
  58. char *path;
  59. char *type;
  60. char *parent_path;
  61. grub_ieee1275_phandle_t phandle;
  62. grub_ieee1275_phandle_t parent_dev;
  63. };
  64. extern void (*EXPORT_VAR(grub_ieee1275_net_config)) (const char *dev,
  65. char **device,
  66. char **path,
  67. char *bootargs);
  68. /* Maps a device alias to a pathname. */
  69. extern grub_ieee1275_phandle_t EXPORT_VAR(grub_ieee1275_chosen);
  70. extern grub_ieee1275_ihandle_t EXPORT_VAR(grub_ieee1275_mmu);
  71. #ifdef __i386__
  72. #define GRUB_IEEE1275_ENTRY_FN_ATTRIBUTE __attribute__ ((regparm(3)))
  73. #else
  74. #define GRUB_IEEE1275_ENTRY_FN_ATTRIBUTE
  75. #endif
  76. extern int (* EXPORT_VAR(grub_ieee1275_entry_fn)) (void *) GRUB_IEEE1275_ENTRY_FN_ATTRIBUTE;
  77. enum grub_ieee1275_flag
  78. {
  79. /* Old World Macintosh firmware fails seek when "dev:0" is opened. */
  80. GRUB_IEEE1275_FLAG_NO_PARTITION_0,
  81. /* Apple firmware runs in translated mode and requires use of the "map"
  82. method. Other firmware runs in untranslated mode and doesn't like "map"
  83. calls. */
  84. GRUB_IEEE1275_FLAG_REAL_MODE,
  85. /* CHRP specifies partitions are numbered from 1 (partition 0 refers to the
  86. whole disk). However, CodeGen firmware numbers partitions from 0. */
  87. GRUB_IEEE1275_FLAG_0_BASED_PARTITIONS,
  88. /* CodeGen firmware does not correctly implement "output-device output" */
  89. GRUB_IEEE1275_FLAG_BROKEN_OUTPUT,
  90. /* OLPC / XO firmware hangs when accessing USB devices. */
  91. GRUB_IEEE1275_FLAG_OFDISK_SDCARD_ONLY,
  92. /* OpenFirmware hangs on qemu if one requests any memory below 1.5 MiB. */
  93. GRUB_IEEE1275_FLAG_NO_PRE1_5M_CLAIM,
  94. /* OLPC / XO firmware has the cursor ON/OFF routines. */
  95. GRUB_IEEE1275_FLAG_HAS_CURSORONOFF,
  96. /* Some PowerMacs claim to use 2 address cells but in fact use only 1.
  97. Other PowerMacs claim to use only 1 and really do so. Always assume
  98. 1 address cell is used on PowerMacs.
  99. */
  100. GRUB_IEEE1275_FLAG_BROKEN_ADDRESS_CELLS,
  101. GRUB_IEEE1275_FLAG_NO_TREE_SCANNING_FOR_DISKS,
  102. GRUB_IEEE1275_FLAG_NO_OFNET_SUFFIX,
  103. GRUB_IEEE1275_FLAG_VIRT_TO_REAL_BROKEN,
  104. GRUB_IEEE1275_FLAG_BROKEN_REPEAT,
  105. GRUB_IEEE1275_FLAG_CURSORONOFF_ANSI_BROKEN,
  106. GRUB_IEEE1275_FLAG_RAW_DEVNAMES,
  107. #if defined(__powerpc__)
  108. /*
  109. * On PFW, the first time we boot a Linux partition, we may only get 256MB of
  110. * real memory area, even if the partition has more memory. Set this flag if
  111. * we think we're running under PFW. Then, if this flag is set, and the RMA is
  112. * only 256MB in size, try asking for more with CAS.
  113. */
  114. GRUB_IEEE1275_FLAG_CAN_TRY_CAS_FOR_MORE_MEMORY,
  115. #endif
  116. GRUB_IEEE1275_FLAG_POWER_VM,
  117. GRUB_IEEE1275_FLAG_POWER_KVM,
  118. };
  119. extern int EXPORT_FUNC(grub_ieee1275_test_flag) (enum grub_ieee1275_flag flag);
  120. extern void EXPORT_FUNC(grub_ieee1275_set_flag) (enum grub_ieee1275_flag flag);
  121. void EXPORT_FUNC(grub_ieee1275_init) (void);
  122. int EXPORT_FUNC(grub_ieee1275_finddevice) (const char *name,
  123. grub_ieee1275_phandle_t *phandlep);
  124. int EXPORT_FUNC(grub_ieee1275_get_property) (grub_ieee1275_phandle_t phandle,
  125. const char *property, void *buf,
  126. grub_size_t size,
  127. grub_ssize_t *actual);
  128. int EXPORT_FUNC(grub_ieee1275_get_integer_property) (grub_ieee1275_phandle_t phandle,
  129. const char *property, grub_uint32_t *buf,
  130. grub_size_t size,
  131. grub_ssize_t *actual);
  132. int EXPORT_FUNC(grub_ieee1275_next_property) (grub_ieee1275_phandle_t phandle,
  133. char *prev_prop, char *prop);
  134. int EXPORT_FUNC(grub_ieee1275_get_property_length)
  135. (grub_ieee1275_phandle_t phandle, const char *prop, grub_ssize_t *length);
  136. int EXPORT_FUNC(grub_ieee1275_instance_to_package)
  137. (grub_ieee1275_ihandle_t ihandle, grub_ieee1275_phandle_t *phandlep);
  138. int EXPORT_FUNC(grub_ieee1275_package_to_path) (grub_ieee1275_phandle_t phandle,
  139. char *path, grub_size_t len,
  140. grub_ssize_t *actual);
  141. int EXPORT_FUNC(grub_ieee1275_instance_to_path)
  142. (grub_ieee1275_ihandle_t ihandle, char *path, grub_size_t len,
  143. grub_ssize_t *actual);
  144. int EXPORT_FUNC(grub_ieee1275_write) (grub_ieee1275_ihandle_t ihandle,
  145. const void *buffer, grub_size_t len,
  146. grub_ssize_t *actualp);
  147. int EXPORT_FUNC(grub_ieee1275_read) (grub_ieee1275_ihandle_t ihandle,
  148. void *buffer, grub_size_t len,
  149. grub_ssize_t *actualp);
  150. int EXPORT_FUNC(grub_ieee1275_seek) (grub_ieee1275_ihandle_t ihandle,
  151. grub_disk_addr_t pos,
  152. grub_ssize_t *result);
  153. int EXPORT_FUNC(grub_ieee1275_peer) (grub_ieee1275_phandle_t node,
  154. grub_ieee1275_phandle_t *result);
  155. int EXPORT_FUNC(grub_ieee1275_child) (grub_ieee1275_phandle_t node,
  156. grub_ieee1275_phandle_t *result);
  157. int EXPORT_FUNC(grub_ieee1275_parent) (grub_ieee1275_phandle_t node,
  158. grub_ieee1275_phandle_t *result);
  159. int EXPORT_FUNC(grub_ieee1275_interpret) (const char *command,
  160. grub_ieee1275_cell_t *catch);
  161. int EXPORT_FUNC(grub_ieee1275_enter) (void);
  162. void EXPORT_FUNC(grub_ieee1275_exit) (void) __attribute__ ((noreturn));
  163. int EXPORT_FUNC(grub_ieee1275_open) (const char *node,
  164. grub_ieee1275_ihandle_t *result);
  165. int EXPORT_FUNC(grub_ieee1275_close) (grub_ieee1275_ihandle_t ihandle);
  166. int EXPORT_FUNC(grub_ieee1275_claim) (grub_addr_t addr, grub_size_t size,
  167. unsigned int align, grub_addr_t *result);
  168. int EXPORT_FUNC(grub_ieee1275_release) (grub_addr_t addr, grub_size_t size);
  169. int EXPORT_FUNC(grub_ieee1275_set_property) (grub_ieee1275_phandle_t phandle,
  170. const char *propname,
  171. const void *buf,
  172. grub_size_t size,
  173. grub_ssize_t *actual);
  174. int EXPORT_FUNC(grub_ieee1275_set_color) (grub_ieee1275_ihandle_t ihandle,
  175. int index, int r, int g, int b);
  176. int EXPORT_FUNC(grub_ieee1275_milliseconds) (grub_uint32_t *msecs);
  177. int EXPORT_FUNC(grub_ieee1275_set_address) (grub_ieee1275_ihandle_t ihandle,
  178. grub_uint32_t target,
  179. grub_uint32_t lun);
  180. int EXPORT_FUNC(grub_ieee1275_no_data_command) (grub_ieee1275_ihandle_t ihandle,
  181. const void *cmd_addr,
  182. grub_ssize_t *result);
  183. int EXPORT_FUNC(grub_ieee1275_decode_unit4) (grub_ieee1275_ihandle_t ihandle,
  184. void *addr, grub_size_t size,
  185. grub_uint32_t *phy_lo,
  186. grub_uint32_t *phy_hi,
  187. grub_uint32_t *lun_lo,
  188. grub_uint32_t *lun_hi);
  189. char *EXPORT_FUNC(grub_ieee1275_encode_uint4) (grub_ieee1275_ihandle_t ihandle,
  190. grub_uint32_t phy_lo,
  191. grub_uint32_t phy_hi,
  192. grub_uint32_t lun_lo,
  193. grub_uint32_t lun_hi,
  194. grub_size_t *size);
  195. int EXPORT_FUNC(grub_ieee1275_get_block_size) (grub_ieee1275_ihandle_t ihandle);
  196. grub_err_t EXPORT_FUNC(grub_claimmap) (grub_addr_t addr, grub_size_t size);
  197. int
  198. EXPORT_FUNC(grub_ieee1275_map) (grub_addr_t phys, grub_addr_t virt,
  199. grub_size_t size, grub_uint32_t mode);
  200. char *EXPORT_FUNC(grub_ieee1275_encode_devname) (const char *path);
  201. char *EXPORT_FUNC(grub_ieee1275_get_filename) (const char *path);
  202. int EXPORT_FUNC(grub_ieee1275_devices_iterate) (int (*hook)
  203. (struct grub_ieee1275_devalias *
  204. alias));
  205. char *EXPORT_FUNC(grub_ieee1275_get_aliasdevname) (const char *path);
  206. char *EXPORT_FUNC(grub_ieee1275_canonicalise_devname) (const char *path);
  207. char *EXPORT_FUNC(grub_ieee1275_get_device_type) (const char *path);
  208. char *EXPORT_FUNC(grub_ieee1275_get_devname) (const char *path);
  209. void EXPORT_FUNC(grub_ieee1275_devalias_init_iterator) (struct grub_ieee1275_devalias *alias);
  210. void EXPORT_FUNC(grub_ieee1275_devalias_free) (struct grub_ieee1275_devalias *alias);
  211. int EXPORT_FUNC(grub_ieee1275_devalias_next) (struct grub_ieee1275_devalias *alias);
  212. void EXPORT_FUNC(grub_ieee1275_children_peer) (struct grub_ieee1275_devalias *alias);
  213. void EXPORT_FUNC(grub_ieee1275_children_first) (const char *devpath,
  214. struct grub_ieee1275_devalias *alias);
  215. char *EXPORT_FUNC(grub_ieee1275_get_boot_dev) (void);
  216. #define FOR_IEEE1275_DEVALIASES(alias) for (grub_ieee1275_devalias_init_iterator (&(alias)); grub_ieee1275_devalias_next (&(alias));)
  217. #define FOR_IEEE1275_DEVCHILDREN(devpath, alias) for (grub_ieee1275_children_first ((devpath), &(alias)); \
  218. (alias).name; \
  219. grub_ieee1275_children_peer (&(alias)))
  220. #endif /* ! GRUB_IEEE1275_HEADER */