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