ops.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. /*
  2. * Global definition of all the bootwrapper operations.
  3. *
  4. * Author: Mark A. Greer <mgreer@mvista.com>
  5. *
  6. * 2006 (c) MontaVista Software, Inc. This file is licensed under
  7. * the terms of the GNU General Public License version 2. This program
  8. * is licensed "as is" without any warranty of any kind, whether express
  9. * or implied.
  10. */
  11. #ifndef _PPC_BOOT_OPS_H_
  12. #define _PPC_BOOT_OPS_H_
  13. #include <stddef.h>
  14. #include "types.h"
  15. #include "string.h"
  16. #define BOOT_COMMAND_LINE_SIZE 2048
  17. #define MAX_PATH_LEN 256
  18. #define MAX_PROP_LEN 256 /* What should this be? */
  19. typedef void (*kernel_entry_t)(unsigned long r3, unsigned long r4, void *r5);
  20. /* Platform specific operations */
  21. struct platform_ops {
  22. void (*fixups)(void);
  23. void (*image_hdr)(const void *);
  24. void * (*malloc)(unsigned long size);
  25. void (*free)(void *ptr);
  26. void * (*realloc)(void *ptr, unsigned long size);
  27. void (*exit)(void);
  28. void * (*vmlinux_alloc)(unsigned long size);
  29. void (*kentry)(unsigned long fdt_addr, void *vmlinux_addr);
  30. };
  31. extern struct platform_ops platform_ops;
  32. /* Device Tree operations */
  33. struct dt_ops {
  34. void * (*finddevice)(const char *name);
  35. int (*getprop)(const void *phandle, const char *name, void *buf,
  36. const int buflen);
  37. int (*setprop)(const void *phandle, const char *name,
  38. const void *buf, const int buflen);
  39. int (*del_node)(const void *phandle);
  40. void *(*get_parent)(const void *phandle);
  41. /* The node must not already exist. */
  42. void *(*create_node)(const void *parent, const char *name);
  43. void *(*find_node_by_prop_value)(const void *prev,
  44. const char *propname,
  45. const char *propval, int proplen);
  46. void *(*find_node_by_compatible)(const void *prev,
  47. const char *compat);
  48. unsigned long (*finalize)(void);
  49. char *(*get_path)(const void *phandle, char *buf, int len);
  50. };
  51. extern struct dt_ops dt_ops;
  52. /* Console operations */
  53. struct console_ops {
  54. int (*open)(void);
  55. void (*write)(const char *buf, int len);
  56. void (*edit_cmdline)(char *buf, int len, unsigned int getline_timeout);
  57. void (*close)(void);
  58. void *data;
  59. };
  60. extern struct console_ops console_ops;
  61. /* Serial console operations */
  62. struct serial_console_data {
  63. int (*open)(void);
  64. void (*putc)(unsigned char c);
  65. unsigned char (*getc)(void);
  66. u8 (*tstc)(void);
  67. void (*close)(void);
  68. };
  69. struct loader_info {
  70. void *promptr;
  71. unsigned long initrd_addr, initrd_size;
  72. char *cmdline;
  73. int cmdline_len;
  74. };
  75. extern struct loader_info loader_info;
  76. void start(void);
  77. void fdt_init(void *blob);
  78. int serial_console_init(void);
  79. int ns16550_console_init(void *devp, struct serial_console_data *scdp);
  80. int mpsc_console_init(void *devp, struct serial_console_data *scdp);
  81. int cpm_console_init(void *devp, struct serial_console_data *scdp);
  82. int mpc5200_psc_console_init(void *devp, struct serial_console_data *scdp);
  83. int uartlite_console_init(void *devp, struct serial_console_data *scdp);
  84. int opal_console_init(void *devp, struct serial_console_data *scdp);
  85. void *simple_alloc_init(char *base, unsigned long heap_size,
  86. unsigned long granularity, unsigned long max_allocs);
  87. extern void flush_cache(void *, unsigned long);
  88. int dt_xlate_reg(void *node, int res, unsigned long *addr, unsigned long *size);
  89. int dt_xlate_addr(void *node, u32 *buf, int buflen, unsigned long *xlated_addr);
  90. int dt_is_compatible(void *node, const char *compat);
  91. void dt_get_reg_format(void *node, u32 *naddr, u32 *nsize);
  92. int dt_get_virtual_reg(void *node, void **addr, int nres);
  93. static inline void *finddevice(const char *name)
  94. {
  95. return (dt_ops.finddevice) ? dt_ops.finddevice(name) : NULL;
  96. }
  97. static inline int getprop(void *devp, const char *name, void *buf, int buflen)
  98. {
  99. return (dt_ops.getprop) ? dt_ops.getprop(devp, name, buf, buflen) : -1;
  100. }
  101. static inline int setprop(void *devp, const char *name,
  102. const void *buf, int buflen)
  103. {
  104. return (dt_ops.setprop) ? dt_ops.setprop(devp, name, buf, buflen) : -1;
  105. }
  106. #define setprop_val(devp, name, val) \
  107. do { \
  108. typeof(val) x = (val); \
  109. setprop((devp), (name), &x, sizeof(x)); \
  110. } while (0)
  111. static inline int setprop_str(void *devp, const char *name, const char *buf)
  112. {
  113. if (dt_ops.setprop)
  114. return dt_ops.setprop(devp, name, buf, strlen(buf) + 1);
  115. return -1;
  116. }
  117. static inline int del_node(const void *devp)
  118. {
  119. return dt_ops.del_node ? dt_ops.del_node(devp) : -1;
  120. }
  121. static inline void *get_parent(const char *devp)
  122. {
  123. return dt_ops.get_parent ? dt_ops.get_parent(devp) : NULL;
  124. }
  125. static inline void *create_node(const void *parent, const char *name)
  126. {
  127. return dt_ops.create_node ? dt_ops.create_node(parent, name) : NULL;
  128. }
  129. static inline void *find_node_by_prop_value(const void *prev,
  130. const char *propname,
  131. const char *propval, int proplen)
  132. {
  133. if (dt_ops.find_node_by_prop_value)
  134. return dt_ops.find_node_by_prop_value(prev, propname,
  135. propval, proplen);
  136. return NULL;
  137. }
  138. static inline void *find_node_by_prop_value_str(const void *prev,
  139. const char *propname,
  140. const char *propval)
  141. {
  142. return find_node_by_prop_value(prev, propname, propval,
  143. strlen(propval) + 1);
  144. }
  145. static inline void *find_node_by_devtype(const void *prev,
  146. const char *type)
  147. {
  148. return find_node_by_prop_value_str(prev, "device_type", type);
  149. }
  150. static inline void *find_node_by_alias(const char *alias)
  151. {
  152. void *devp = finddevice("/aliases");
  153. if (devp) {
  154. char path[MAX_PATH_LEN];
  155. if (getprop(devp, alias, path, MAX_PATH_LEN) > 0)
  156. return finddevice(path);
  157. }
  158. return NULL;
  159. }
  160. static inline void *find_node_by_compatible(const void *prev,
  161. const char *compat)
  162. {
  163. if (dt_ops.find_node_by_compatible)
  164. return dt_ops.find_node_by_compatible(prev, compat);
  165. return NULL;
  166. }
  167. void dt_fixup_memory(u64 start, u64 size);
  168. void dt_fixup_cpu_clocks(u32 cpufreq, u32 tbfreq, u32 busfreq);
  169. void dt_fixup_clock(const char *path, u32 freq);
  170. void dt_fixup_mac_address_by_alias(const char *alias, const u8 *addr);
  171. void dt_fixup_mac_address(u32 index, const u8 *addr);
  172. void __dt_fixup_mac_addresses(u32 startindex, ...);
  173. #define dt_fixup_mac_addresses(...) \
  174. __dt_fixup_mac_addresses(0, __VA_ARGS__, NULL)
  175. static inline void *find_node_by_linuxphandle(const u32 linuxphandle)
  176. {
  177. return find_node_by_prop_value(NULL, "linux,phandle",
  178. (char *)&linuxphandle, sizeof(u32));
  179. }
  180. static inline char *get_path(const void *phandle, char *buf, int len)
  181. {
  182. if (dt_ops.get_path)
  183. return dt_ops.get_path(phandle, buf, len);
  184. return NULL;
  185. }
  186. static inline void *malloc(unsigned long size)
  187. {
  188. return (platform_ops.malloc) ? platform_ops.malloc(size) : NULL;
  189. }
  190. static inline void free(void *ptr)
  191. {
  192. if (platform_ops.free)
  193. platform_ops.free(ptr);
  194. }
  195. static inline void exit(void)
  196. {
  197. if (platform_ops.exit)
  198. platform_ops.exit();
  199. for(;;);
  200. }
  201. #define fatal(args...) { printf(args); exit(); }
  202. #define BSS_STACK(size) \
  203. static char _bss_stack[size]; \
  204. void *_platform_stack_top = _bss_stack + sizeof(_bss_stack);
  205. extern unsigned long timebase_period_ns;
  206. void udelay(long delay);
  207. extern char _start[];
  208. extern char __bss_start[];
  209. extern char _end[];
  210. extern char _vmlinux_start[];
  211. extern char _vmlinux_end[];
  212. extern char _initrd_start[];
  213. extern char _initrd_end[];
  214. extern char _dtb_start[];
  215. extern char _dtb_end[];
  216. static inline __attribute__((const))
  217. int __ilog2_u32(u32 n)
  218. {
  219. int bit;
  220. asm ("cntlzw %0,%1" : "=r" (bit) : "r" (n));
  221. return 31 - bit;
  222. }
  223. long partial_decompress(void *inbuf, unsigned long input_size, void *outbuf,
  224. unsigned long output_size, unsigned long skip);
  225. #endif /* _PPC_BOOT_OPS_H_ */