ops.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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)(u32 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. };
  67. extern struct loader_info loader_info;
  68. void start(void *sp);
  69. int ft_init(void *dt_blob, unsigned int max_size, unsigned int max_find_device);
  70. int serial_console_init(void);
  71. int ns16550_console_init(void *devp, struct serial_console_data *scdp);
  72. void *simple_alloc_init(char *base, u32 heap_size, u32 granularity,
  73. u32 max_allocs);
  74. extern void flush_cache(void *, unsigned long);
  75. static inline void *finddevice(const char *name)
  76. {
  77. return (dt_ops.finddevice) ? dt_ops.finddevice(name) : NULL;
  78. }
  79. static inline int getprop(void *devp, const char *name, void *buf, int buflen)
  80. {
  81. return (dt_ops.getprop) ? dt_ops.getprop(devp, name, buf, buflen) : -1;
  82. }
  83. static inline int setprop(void *devp, const char *name,
  84. const void *buf, int buflen)
  85. {
  86. return (dt_ops.setprop) ? dt_ops.setprop(devp, name, buf, buflen) : -1;
  87. }
  88. static inline int setprop_str(void *devp, const char *name, const char *buf)
  89. {
  90. if (dt_ops.setprop)
  91. return dt_ops.setprop(devp, name, buf, strlen(buf) + 1);
  92. return -1;
  93. }
  94. static inline void *get_parent(const char *devp)
  95. {
  96. return dt_ops.get_parent ? dt_ops.get_parent(devp) : NULL;
  97. }
  98. static inline void *create_node(const void *parent, const char *name)
  99. {
  100. return dt_ops.create_node ? dt_ops.create_node(parent, name) : NULL;
  101. }
  102. static inline void *find_node_by_prop_value(const void *prev,
  103. const char *propname,
  104. const char *propval, int proplen)
  105. {
  106. if (dt_ops.find_node_by_prop_value)
  107. return dt_ops.find_node_by_prop_value(prev, propname,
  108. propval, proplen);
  109. return NULL;
  110. }
  111. static inline void *find_node_by_prop_value_str(const void *prev,
  112. const char *propname,
  113. const char *propval)
  114. {
  115. return find_node_by_prop_value(prev, propname, propval,
  116. strlen(propval) + 1);
  117. }
  118. static inline void *find_node_by_devtype(const void *prev,
  119. const char *type)
  120. {
  121. return find_node_by_prop_value_str(prev, "device_type", type);
  122. }
  123. static inline void *malloc(u32 size)
  124. {
  125. return (platform_ops.malloc) ? platform_ops.malloc(size) : NULL;
  126. }
  127. static inline void free(void *ptr)
  128. {
  129. if (platform_ops.free)
  130. platform_ops.free(ptr);
  131. }
  132. static inline void exit(void)
  133. {
  134. if (platform_ops.exit)
  135. platform_ops.exit();
  136. for(;;);
  137. }
  138. #define BSS_STACK(size) \
  139. static char _bss_stack[size]; \
  140. void *_platform_stack_top = _bss_stack + sizeof(_bss_stack);
  141. #endif /* _PPC_BOOT_OPS_H_ */