ops.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Global definition of all the bootwrapper operations.
  4. *
  5. * Author: Mark A. Greer <[email protected]>
  6. *
  7. * 2006 (c) MontaVista Software, Inc.
  8. */
  9. #ifndef _PPC_BOOT_OPS_H_
  10. #define _PPC_BOOT_OPS_H_
  11. #include <stddef.h>
  12. #include "types.h"
  13. #include "string.h"
  14. #define BOOT_COMMAND_LINE_SIZE 2048
  15. #define MAX_PATH_LEN 256
  16. #define MAX_PROP_LEN 256 /* What should this be? */
  17. typedef void (*kernel_entry_t)(unsigned long r3, unsigned long r4, void *r5);
  18. /* Platform specific operations */
  19. struct platform_ops {
  20. void (*fixups)(void);
  21. void (*image_hdr)(const void *);
  22. void * (*malloc)(unsigned long size);
  23. void (*free)(void *ptr);
  24. void * (*realloc)(void *ptr, unsigned long size);
  25. void (*exit)(void);
  26. void * (*vmlinux_alloc)(unsigned long size);
  27. void (*kentry)(unsigned long fdt_addr, void *vmlinux_addr);
  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. int (*del_node)(const void *phandle);
  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, unsigned int getline_timeout);
  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 cpm_console_init(void *devp, struct serial_console_data *scdp);
  79. int mpc5200_psc_console_init(void *devp, struct serial_console_data *scdp);
  80. int opal_console_init(void *devp, struct serial_console_data *scdp);
  81. void *simple_alloc_init(char *base, unsigned long heap_size,
  82. unsigned long granularity, unsigned long max_allocs);
  83. extern void flush_cache(void *, unsigned long);
  84. int dt_xlate_reg(void *node, int res, unsigned long *addr, unsigned long *size);
  85. int dt_xlate_addr(void *node, u32 *buf, int buflen, unsigned long *xlated_addr);
  86. int dt_is_compatible(void *node, const char *compat);
  87. void dt_get_reg_format(void *node, u32 *naddr, u32 *nsize);
  88. int dt_get_virtual_reg(void *node, void **addr, int nres);
  89. static inline void *finddevice(const char *name)
  90. {
  91. return (dt_ops.finddevice) ? dt_ops.finddevice(name) : NULL;
  92. }
  93. static inline int getprop(void *devp, const char *name, void *buf, int buflen)
  94. {
  95. return (dt_ops.getprop) ? dt_ops.getprop(devp, name, buf, buflen) : -1;
  96. }
  97. static inline int setprop(void *devp, const char *name,
  98. const void *buf, int buflen)
  99. {
  100. return (dt_ops.setprop) ? dt_ops.setprop(devp, name, buf, buflen) : -1;
  101. }
  102. #define setprop_val(devp, name, val) \
  103. do { \
  104. typeof(val) x = (val); \
  105. setprop((devp), (name), &x, sizeof(x)); \
  106. } while (0)
  107. static inline int setprop_str(void *devp, const char *name, const char *buf)
  108. {
  109. if (dt_ops.setprop)
  110. return dt_ops.setprop(devp, name, buf, strlen(buf) + 1);
  111. return -1;
  112. }
  113. static inline int del_node(const void *devp)
  114. {
  115. return dt_ops.del_node ? dt_ops.del_node(devp) : -1;
  116. }
  117. static inline void *get_parent(const char *devp)
  118. {
  119. return dt_ops.get_parent ? dt_ops.get_parent(devp) : NULL;
  120. }
  121. static inline void *create_node(const void *parent, const char *name)
  122. {
  123. return dt_ops.create_node ? dt_ops.create_node(parent, name) : NULL;
  124. }
  125. static inline void *find_node_by_prop_value(const void *prev,
  126. const char *propname,
  127. const char *propval, int proplen)
  128. {
  129. if (dt_ops.find_node_by_prop_value)
  130. return dt_ops.find_node_by_prop_value(prev, propname,
  131. propval, proplen);
  132. return NULL;
  133. }
  134. static inline void *find_node_by_prop_value_str(const void *prev,
  135. const char *propname,
  136. const char *propval)
  137. {
  138. return find_node_by_prop_value(prev, propname, propval,
  139. strlen(propval) + 1);
  140. }
  141. static inline void *find_node_by_devtype(const void *prev,
  142. const char *type)
  143. {
  144. return find_node_by_prop_value_str(prev, "device_type", type);
  145. }
  146. static inline void *find_node_by_alias(const char *alias)
  147. {
  148. void *devp = finddevice("/aliases");
  149. if (devp) {
  150. char path[MAX_PATH_LEN];
  151. if (getprop(devp, alias, path, MAX_PATH_LEN) > 0)
  152. return finddevice(path);
  153. }
  154. return NULL;
  155. }
  156. static inline void *find_node_by_compatible(const void *prev,
  157. const char *compat)
  158. {
  159. if (dt_ops.find_node_by_compatible)
  160. return dt_ops.find_node_by_compatible(prev, compat);
  161. return NULL;
  162. }
  163. void dt_fixup_memory(u64 start, u64 size);
  164. void dt_fixup_cpu_clocks(u32 cpufreq, u32 tbfreq, u32 busfreq);
  165. void dt_fixup_clock(const char *path, u32 freq);
  166. void dt_fixup_mac_address_by_alias(const char *alias, const u8 *addr);
  167. void dt_fixup_mac_address(u32 index, const u8 *addr);
  168. void __dt_fixup_mac_addresses(u32 startindex, ...);
  169. #define dt_fixup_mac_addresses(...) \
  170. __dt_fixup_mac_addresses(0, __VA_ARGS__, NULL)
  171. static inline char *get_path(const void *phandle, char *buf, int len)
  172. {
  173. if (dt_ops.get_path)
  174. return dt_ops.get_path(phandle, buf, len);
  175. return NULL;
  176. }
  177. static inline void *malloc(unsigned long size)
  178. {
  179. return (platform_ops.malloc) ? platform_ops.malloc(size) : NULL;
  180. }
  181. static inline void free(void *ptr)
  182. {
  183. if (platform_ops.free)
  184. platform_ops.free(ptr);
  185. }
  186. static inline void exit(void)
  187. {
  188. if (platform_ops.exit)
  189. platform_ops.exit();
  190. for(;;);
  191. }
  192. #define fatal(args...) { printf(args); exit(); }
  193. #define BSS_STACK(size) \
  194. static char _bss_stack[size]; \
  195. void *_platform_stack_top = _bss_stack + sizeof(_bss_stack);
  196. extern unsigned long timebase_period_ns;
  197. void udelay(long delay);
  198. extern char _start[];
  199. extern char __bss_start[];
  200. extern char _end[];
  201. extern char _vmlinux_start[];
  202. extern char _vmlinux_end[];
  203. extern char _initrd_start[];
  204. extern char _initrd_end[];
  205. extern char _dtb_start[];
  206. extern char _dtb_end[];
  207. extern char _esm_blob_start[];
  208. extern char _esm_blob_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. long partial_decompress(void *inbuf, unsigned long input_size, void *outbuf,
  217. unsigned long output_size, unsigned long skip);
  218. #endif /* _PPC_BOOT_OPS_H_ */