ops.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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 COMMAND_LINE_SIZE 512
  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. };
  30. extern struct platform_ops platform_ops;
  31. /* Device Tree operations */
  32. struct dt_ops {
  33. void * (*finddevice)(const char *name);
  34. int (*getprop)(const void *phandle, const char *name, void *buf,
  35. const int buflen);
  36. int (*setprop)(const void *phandle, const char *name,
  37. const void *buf, const int buflen);
  38. void *(*get_parent)(const void *phandle);
  39. /* The node must not already exist. */
  40. void *(*create_node)(const void *parent, const char *name);
  41. void *(*find_node_by_prop_value)(const void *prev,
  42. const char *propname,
  43. const char *propval, int proplen);
  44. void *(*find_node_by_compatible)(const void *prev,
  45. const char *compat);
  46. unsigned long (*finalize)(void);
  47. char *(*get_path)(const void *phandle, char *buf, int len);
  48. };
  49. extern struct dt_ops dt_ops;
  50. /* Console operations */
  51. struct console_ops {
  52. int (*open)(void);
  53. void (*write)(const char *buf, int len);
  54. void (*edit_cmdline)(char *buf, int len);
  55. void (*close)(void);
  56. void *data;
  57. };
  58. extern struct console_ops console_ops;
  59. /* Serial console operations */
  60. struct serial_console_data {
  61. int (*open)(void);
  62. void (*putc)(unsigned char c);
  63. unsigned char (*getc)(void);
  64. u8 (*tstc)(void);
  65. void (*close)(void);
  66. };
  67. struct loader_info {
  68. void *promptr;
  69. unsigned long initrd_addr, initrd_size;
  70. char *cmdline;
  71. int cmdline_len;
  72. };
  73. extern struct loader_info loader_info;
  74. void start(void);
  75. void fdt_init(void *blob);
  76. int serial_console_init(void);
  77. int ns16550_console_init(void *devp, struct serial_console_data *scdp);
  78. int mpsc_console_init(void *devp, struct serial_console_data *scdp);
  79. int cpm_console_init(void *devp, struct serial_console_data *scdp);
  80. int mpc5200_psc_console_init(void *devp, struct serial_console_data *scdp);
  81. int uartlite_console_init(void *devp, struct serial_console_data *scdp);
  82. void *simple_alloc_init(char *base, unsigned long heap_size,
  83. unsigned long granularity, unsigned long max_allocs);
  84. extern void flush_cache(void *, unsigned long);
  85. int dt_xlate_reg(void *node, int res, unsigned long *addr, unsigned long *size);
  86. int dt_xlate_addr(void *node, u32 *buf, int buflen, unsigned long *xlated_addr);
  87. int dt_is_compatible(void *node, const char *compat);
  88. void dt_get_reg_format(void *node, u32 *naddr, u32 *nsize);
  89. int dt_get_virtual_reg(void *node, void **addr, int nres);
  90. static inline void *finddevice(const char *name)
  91. {
  92. return (dt_ops.finddevice) ? dt_ops.finddevice(name) : NULL;
  93. }
  94. static inline int getprop(void *devp, const char *name, void *buf, int buflen)
  95. {
  96. return (dt_ops.getprop) ? dt_ops.getprop(devp, name, buf, buflen) : -1;
  97. }
  98. static inline int setprop(void *devp, const char *name,
  99. const void *buf, int buflen)
  100. {
  101. return (dt_ops.setprop) ? dt_ops.setprop(devp, name, buf, buflen) : -1;
  102. }
  103. #define setprop_val(devp, name, val) \
  104. do { \
  105. typeof(val) x = (val); \
  106. setprop((devp), (name), &x, sizeof(x)); \
  107. } while (0)
  108. static inline int setprop_str(void *devp, const char *name, const char *buf)
  109. {
  110. if (dt_ops.setprop)
  111. return dt_ops.setprop(devp, name, buf, strlen(buf) + 1);
  112. return -1;
  113. }
  114. static inline void *get_parent(const char *devp)
  115. {
  116. return dt_ops.get_parent ? dt_ops.get_parent(devp) : NULL;
  117. }
  118. static inline void *create_node(const void *parent, const char *name)
  119. {
  120. return dt_ops.create_node ? dt_ops.create_node(parent, name) : NULL;
  121. }
  122. static inline void *find_node_by_prop_value(const void *prev,
  123. const char *propname,
  124. const char *propval, int proplen)
  125. {
  126. if (dt_ops.find_node_by_prop_value)
  127. return dt_ops.find_node_by_prop_value(prev, propname,
  128. propval, proplen);
  129. return NULL;
  130. }
  131. static inline void *find_node_by_prop_value_str(const void *prev,
  132. const char *propname,
  133. const char *propval)
  134. {
  135. return find_node_by_prop_value(prev, propname, propval,
  136. strlen(propval) + 1);
  137. }
  138. static inline void *find_node_by_devtype(const void *prev,
  139. const char *type)
  140. {
  141. return find_node_by_prop_value_str(prev, "device_type", type);
  142. }
  143. static inline void *find_node_by_alias(const char *alias)
  144. {
  145. void *devp = finddevice("/aliases");
  146. if (devp) {
  147. char path[MAX_PATH_LEN];
  148. if (getprop(devp, alias, path, MAX_PATH_LEN) > 0)
  149. return finddevice(path);
  150. }
  151. return NULL;
  152. }
  153. static inline void *find_node_by_compatible(const void *prev,
  154. const char *compat)
  155. {
  156. if (dt_ops.find_node_by_compatible)
  157. return dt_ops.find_node_by_compatible(prev, compat);
  158. return NULL;
  159. }
  160. void dt_fixup_memory(u64 start, u64 size);
  161. void dt_fixup_cpu_clocks(u32 cpufreq, u32 tbfreq, u32 busfreq);
  162. void dt_fixup_clock(const char *path, u32 freq);
  163. void dt_fixup_mac_address_by_alias(const char *alias, const u8 *addr);
  164. void dt_fixup_mac_address(u32 index, const u8 *addr);
  165. void __dt_fixup_mac_addresses(u32 startindex, ...);
  166. #define dt_fixup_mac_addresses(...) \
  167. __dt_fixup_mac_addresses(0, __VA_ARGS__, NULL)
  168. static inline void *find_node_by_linuxphandle(const u32 linuxphandle)
  169. {
  170. return find_node_by_prop_value(NULL, "linux,phandle",
  171. (char *)&linuxphandle, sizeof(u32));
  172. }
  173. static inline char *get_path(const void *phandle, char *buf, int len)
  174. {
  175. if (dt_ops.get_path)
  176. return dt_ops.get_path(phandle, buf, len);
  177. return NULL;
  178. }
  179. static inline void *malloc(unsigned long size)
  180. {
  181. return (platform_ops.malloc) ? platform_ops.malloc(size) : NULL;
  182. }
  183. static inline void free(void *ptr)
  184. {
  185. if (platform_ops.free)
  186. platform_ops.free(ptr);
  187. }
  188. static inline void exit(void)
  189. {
  190. if (platform_ops.exit)
  191. platform_ops.exit();
  192. for(;;);
  193. }
  194. #define fatal(args...) { printf(args); exit(); }
  195. #define BSS_STACK(size) \
  196. static char _bss_stack[size]; \
  197. void *_platform_stack_top = _bss_stack + sizeof(_bss_stack);
  198. extern unsigned long timebase_period_ns;
  199. void udelay(long delay);
  200. extern char _start[];
  201. extern char __bss_start[];
  202. extern char _end[];
  203. extern char _vmlinux_start[];
  204. extern char _vmlinux_end[];
  205. extern char _initrd_start[];
  206. extern char _initrd_end[];
  207. extern char _dtb_start[];
  208. extern char _dtb_end[];
  209. static inline __attribute__((const))
  210. int __ilog2_u32(u32 n)
  211. {
  212. int bit;
  213. asm ("cntlzw %0,%1" : "=r" (bit) : "r" (n));
  214. return 31 - bit;
  215. }
  216. #endif /* _PPC_BOOT_OPS_H_ */