ops.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. void *simple_alloc_init(char *base, unsigned long heap_size,
  75. unsigned long granularity, unsigned long max_allocs);
  76. extern void flush_cache(void *, unsigned long);
  77. int dt_xlate_reg(void *node, int res, unsigned long *addr, unsigned long *size);
  78. int dt_xlate_addr(void *node, u32 *buf, int buflen, unsigned long *xlated_addr);
  79. static inline void *finddevice(const char *name)
  80. {
  81. return (dt_ops.finddevice) ? dt_ops.finddevice(name) : NULL;
  82. }
  83. static inline int getprop(void *devp, const char *name, void *buf, int buflen)
  84. {
  85. return (dt_ops.getprop) ? dt_ops.getprop(devp, name, buf, buflen) : -1;
  86. }
  87. static inline int setprop(void *devp, const char *name,
  88. const void *buf, int buflen)
  89. {
  90. return (dt_ops.setprop) ? dt_ops.setprop(devp, name, buf, buflen) : -1;
  91. }
  92. #define setprop_val(devp, name, val) \
  93. do { \
  94. typeof(val) x = (val); \
  95. setprop((devp), (name), &x, sizeof(x)); \
  96. } while (0)
  97. static inline int setprop_str(void *devp, const char *name, const char *buf)
  98. {
  99. if (dt_ops.setprop)
  100. return dt_ops.setprop(devp, name, buf, strlen(buf) + 1);
  101. return -1;
  102. }
  103. static inline void *get_parent(const char *devp)
  104. {
  105. return dt_ops.get_parent ? dt_ops.get_parent(devp) : NULL;
  106. }
  107. static inline void *create_node(const void *parent, const char *name)
  108. {
  109. return dt_ops.create_node ? dt_ops.create_node(parent, name) : NULL;
  110. }
  111. static inline void *find_node_by_prop_value(const void *prev,
  112. const char *propname,
  113. const char *propval, int proplen)
  114. {
  115. if (dt_ops.find_node_by_prop_value)
  116. return dt_ops.find_node_by_prop_value(prev, propname,
  117. propval, proplen);
  118. return NULL;
  119. }
  120. static inline void *find_node_by_prop_value_str(const void *prev,
  121. const char *propname,
  122. const char *propval)
  123. {
  124. return find_node_by_prop_value(prev, propname, propval,
  125. strlen(propval) + 1);
  126. }
  127. static inline void *find_node_by_devtype(const void *prev,
  128. const char *type)
  129. {
  130. return find_node_by_prop_value_str(prev, "device_type", type);
  131. }
  132. void dt_fixup_memory(u64 start, u64 size);
  133. void dt_fixup_cpu_clocks(u32 cpufreq, u32 tbfreq, u32 busfreq);
  134. void dt_fixup_clock(const char *path, u32 freq);
  135. void __dt_fixup_mac_addresses(u32 startindex, ...);
  136. #define dt_fixup_mac_addresses(...) \
  137. __dt_fixup_mac_addresses(0, __VA_ARGS__, NULL)
  138. static inline void *find_node_by_linuxphandle(const u32 linuxphandle)
  139. {
  140. return find_node_by_prop_value(NULL, "linux,phandle",
  141. (char *)&linuxphandle, sizeof(u32));
  142. }
  143. static inline void *malloc(unsigned long size)
  144. {
  145. return (platform_ops.malloc) ? platform_ops.malloc(size) : NULL;
  146. }
  147. static inline void free(void *ptr)
  148. {
  149. if (platform_ops.free)
  150. platform_ops.free(ptr);
  151. }
  152. static inline void exit(void)
  153. {
  154. if (platform_ops.exit)
  155. platform_ops.exit();
  156. for(;;);
  157. }
  158. #define fatal(args...) { printf(args); exit(); }
  159. #define BSS_STACK(size) \
  160. static char _bss_stack[size]; \
  161. void *_platform_stack_top = _bss_stack + sizeof(_bss_stack);
  162. #endif /* _PPC_BOOT_OPS_H_ */