ops.h 5.5 KB

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