ops.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. unsigned long (*finalize)(void);
  45. };
  46. extern struct dt_ops dt_ops;
  47. /* Console operations */
  48. struct console_ops {
  49. int (*open)(void);
  50. void (*write)(const char *buf, int len);
  51. void (*edit_cmdline)(char *buf, int len);
  52. void (*close)(void);
  53. void *data;
  54. };
  55. extern struct console_ops console_ops;
  56. /* Serial console operations */
  57. struct serial_console_data {
  58. int (*open)(void);
  59. void (*putc)(unsigned char c);
  60. unsigned char (*getc)(void);
  61. u8 (*tstc)(void);
  62. void (*close)(void);
  63. };
  64. struct loader_info {
  65. void *promptr;
  66. unsigned long initrd_addr, initrd_size;
  67. char *cmdline;
  68. int cmdline_len;
  69. };
  70. extern struct loader_info loader_info;
  71. void start(void);
  72. int ft_init(void *dt_blob, unsigned int max_size, unsigned int max_find_device);
  73. int serial_console_init(void);
  74. int ns16550_console_init(void *devp, struct serial_console_data *scdp);
  75. int mpsc_console_init(void *devp, struct serial_console_data *scdp);
  76. void *simple_alloc_init(char *base, unsigned long heap_size,
  77. unsigned long granularity, unsigned long max_allocs);
  78. extern void flush_cache(void *, unsigned long);
  79. int dt_xlate_reg(void *node, int res, unsigned long *addr, unsigned long *size);
  80. int dt_xlate_addr(void *node, u32 *buf, int buflen, unsigned long *xlated_addr);
  81. static inline void *finddevice(const char *name)
  82. {
  83. return (dt_ops.finddevice) ? dt_ops.finddevice(name) : NULL;
  84. }
  85. static inline int getprop(void *devp, const char *name, void *buf, int buflen)
  86. {
  87. return (dt_ops.getprop) ? dt_ops.getprop(devp, name, buf, buflen) : -1;
  88. }
  89. static inline int setprop(void *devp, const char *name,
  90. const void *buf, int buflen)
  91. {
  92. return (dt_ops.setprop) ? dt_ops.setprop(devp, name, buf, buflen) : -1;
  93. }
  94. #define setprop_val(devp, name, val) \
  95. do { \
  96. typeof(val) x = (val); \
  97. setprop((devp), (name), &x, sizeof(x)); \
  98. } while (0)
  99. static inline int setprop_str(void *devp, const char *name, const char *buf)
  100. {
  101. if (dt_ops.setprop)
  102. return dt_ops.setprop(devp, name, buf, strlen(buf) + 1);
  103. return -1;
  104. }
  105. static inline void *get_parent(const char *devp)
  106. {
  107. return dt_ops.get_parent ? dt_ops.get_parent(devp) : NULL;
  108. }
  109. static inline void *create_node(const void *parent, const char *name)
  110. {
  111. return dt_ops.create_node ? dt_ops.create_node(parent, name) : NULL;
  112. }
  113. static inline void *find_node_by_prop_value(const void *prev,
  114. const char *propname,
  115. const char *propval, int proplen)
  116. {
  117. if (dt_ops.find_node_by_prop_value)
  118. return dt_ops.find_node_by_prop_value(prev, propname,
  119. propval, proplen);
  120. return NULL;
  121. }
  122. static inline void *find_node_by_prop_value_str(const void *prev,
  123. const char *propname,
  124. const char *propval)
  125. {
  126. return find_node_by_prop_value(prev, propname, propval,
  127. strlen(propval) + 1);
  128. }
  129. static inline void *find_node_by_devtype(const void *prev,
  130. const char *type)
  131. {
  132. return find_node_by_prop_value_str(prev, "device_type", type);
  133. }
  134. void dt_fixup_memory(u64 start, u64 size);
  135. void dt_fixup_cpu_clocks(u32 cpufreq, u32 tbfreq, u32 busfreq);
  136. void dt_fixup_clock(const char *path, u32 freq);
  137. void __dt_fixup_mac_addresses(u32 startindex, ...);
  138. #define dt_fixup_mac_addresses(...) \
  139. __dt_fixup_mac_addresses(0, __VA_ARGS__, NULL)
  140. static inline void *find_node_by_linuxphandle(const u32 linuxphandle)
  141. {
  142. return find_node_by_prop_value(NULL, "linux,phandle",
  143. (char *)&linuxphandle, sizeof(u32));
  144. }
  145. static inline void *malloc(unsigned long size)
  146. {
  147. return (platform_ops.malloc) ? platform_ops.malloc(size) : NULL;
  148. }
  149. static inline void free(void *ptr)
  150. {
  151. if (platform_ops.free)
  152. platform_ops.free(ptr);
  153. }
  154. static inline void exit(void)
  155. {
  156. if (platform_ops.exit)
  157. platform_ops.exit();
  158. for(;;);
  159. }
  160. #define fatal(args...) { printf(args); exit(); }
  161. #define BSS_STACK(size) \
  162. static char _bss_stack[size]; \
  163. void *_platform_stack_top = _bss_stack + sizeof(_bss_stack);
  164. #endif /* _PPC_BOOT_OPS_H_ */