0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef _PPC_BOOT_OPS_H_
0012 #define _PPC_BOOT_OPS_H_
0013
0014 #include <stddef.h>
0015 #include "types.h"
0016 #include "string.h"
0017
0018 #define BOOT_COMMAND_LINE_SIZE 2048
0019 #define MAX_PATH_LEN 256
0020 #define MAX_PROP_LEN 256
0021
0022 typedef void (*kernel_entry_t)(unsigned long r3, unsigned long r4, void *r5);
0023
0024
0025 struct platform_ops {
0026 void (*fixups)(void);
0027 void (*image_hdr)(const void *);
0028 void * (*malloc)(unsigned long size);
0029 void (*free)(void *ptr);
0030 void * (*realloc)(void *ptr, unsigned long size);
0031 void (*exit)(void);
0032 void * (*vmlinux_alloc)(unsigned long size);
0033 void (*kentry)(unsigned long fdt_addr, void *vmlinux_addr);
0034 };
0035 extern struct platform_ops platform_ops;
0036
0037
0038 struct dt_ops {
0039 void * (*finddevice)(const char *name);
0040 int (*getprop)(const void *phandle, const char *name, void *buf,
0041 const int buflen);
0042 int (*setprop)(const void *phandle, const char *name,
0043 const void *buf, const int buflen);
0044 int (*del_node)(const void *phandle);
0045 void *(*get_parent)(const void *phandle);
0046
0047 void *(*create_node)(const void *parent, const char *name);
0048 void *(*find_node_by_prop_value)(const void *prev,
0049 const char *propname,
0050 const char *propval, int proplen);
0051 void *(*find_node_by_compatible)(const void *prev,
0052 const char *compat);
0053 unsigned long (*finalize)(void);
0054 char *(*get_path)(const void *phandle, char *buf, int len);
0055 };
0056 extern struct dt_ops dt_ops;
0057
0058
0059 struct console_ops {
0060 int (*open)(void);
0061 void (*write)(const char *buf, int len);
0062 void (*edit_cmdline)(char *buf, int len, unsigned int getline_timeout);
0063 void (*close)(void);
0064 void *data;
0065 };
0066 extern struct console_ops console_ops;
0067
0068
0069 struct serial_console_data {
0070 int (*open)(void);
0071 void (*putc)(unsigned char c);
0072 unsigned char (*getc)(void);
0073 u8 (*tstc)(void);
0074 void (*close)(void);
0075 };
0076
0077 struct loader_info {
0078 void *promptr;
0079 unsigned long initrd_addr, initrd_size;
0080 char *cmdline;
0081 int cmdline_len;
0082 };
0083 extern struct loader_info loader_info;
0084
0085 void start(void);
0086 void fdt_init(void *blob);
0087 int serial_console_init(void);
0088 int ns16550_console_init(void *devp, struct serial_console_data *scdp);
0089 int cpm_console_init(void *devp, struct serial_console_data *scdp);
0090 int mpc5200_psc_console_init(void *devp, struct serial_console_data *scdp);
0091 int opal_console_init(void *devp, struct serial_console_data *scdp);
0092 void *simple_alloc_init(char *base, unsigned long heap_size,
0093 unsigned long granularity, unsigned long max_allocs);
0094 extern void flush_cache(void *, unsigned long);
0095 int dt_xlate_reg(void *node, int res, unsigned long *addr, unsigned long *size);
0096 int dt_xlate_addr(void *node, u32 *buf, int buflen, unsigned long *xlated_addr);
0097 int dt_is_compatible(void *node, const char *compat);
0098 void dt_get_reg_format(void *node, u32 *naddr, u32 *nsize);
0099 int dt_get_virtual_reg(void *node, void **addr, int nres);
0100
0101 static inline void *finddevice(const char *name)
0102 {
0103 return (dt_ops.finddevice) ? dt_ops.finddevice(name) : NULL;
0104 }
0105
0106 static inline int getprop(void *devp, const char *name, void *buf, int buflen)
0107 {
0108 return (dt_ops.getprop) ? dt_ops.getprop(devp, name, buf, buflen) : -1;
0109 }
0110
0111 static inline int setprop(void *devp, const char *name,
0112 const void *buf, int buflen)
0113 {
0114 return (dt_ops.setprop) ? dt_ops.setprop(devp, name, buf, buflen) : -1;
0115 }
0116 #define setprop_val(devp, name, val) \
0117 do { \
0118 typeof(val) x = (val); \
0119 setprop((devp), (name), &x, sizeof(x)); \
0120 } while (0)
0121
0122 static inline int setprop_str(void *devp, const char *name, const char *buf)
0123 {
0124 if (dt_ops.setprop)
0125 return dt_ops.setprop(devp, name, buf, strlen(buf) + 1);
0126
0127 return -1;
0128 }
0129
0130 static inline int del_node(const void *devp)
0131 {
0132 return dt_ops.del_node ? dt_ops.del_node(devp) : -1;
0133 }
0134
0135 static inline void *get_parent(const char *devp)
0136 {
0137 return dt_ops.get_parent ? dt_ops.get_parent(devp) : NULL;
0138 }
0139
0140 static inline void *create_node(const void *parent, const char *name)
0141 {
0142 return dt_ops.create_node ? dt_ops.create_node(parent, name) : NULL;
0143 }
0144
0145
0146 static inline void *find_node_by_prop_value(const void *prev,
0147 const char *propname,
0148 const char *propval, int proplen)
0149 {
0150 if (dt_ops.find_node_by_prop_value)
0151 return dt_ops.find_node_by_prop_value(prev, propname,
0152 propval, proplen);
0153
0154 return NULL;
0155 }
0156
0157 static inline void *find_node_by_prop_value_str(const void *prev,
0158 const char *propname,
0159 const char *propval)
0160 {
0161 return find_node_by_prop_value(prev, propname, propval,
0162 strlen(propval) + 1);
0163 }
0164
0165 static inline void *find_node_by_devtype(const void *prev,
0166 const char *type)
0167 {
0168 return find_node_by_prop_value_str(prev, "device_type", type);
0169 }
0170
0171 static inline void *find_node_by_alias(const char *alias)
0172 {
0173 void *devp = finddevice("/aliases");
0174
0175 if (devp) {
0176 char path[MAX_PATH_LEN];
0177 if (getprop(devp, alias, path, MAX_PATH_LEN) > 0)
0178 return finddevice(path);
0179 }
0180
0181 return NULL;
0182 }
0183
0184 static inline void *find_node_by_compatible(const void *prev,
0185 const char *compat)
0186 {
0187 if (dt_ops.find_node_by_compatible)
0188 return dt_ops.find_node_by_compatible(prev, compat);
0189
0190 return NULL;
0191 }
0192
0193 void dt_fixup_memory(u64 start, u64 size);
0194 void dt_fixup_cpu_clocks(u32 cpufreq, u32 tbfreq, u32 busfreq);
0195 void dt_fixup_clock(const char *path, u32 freq);
0196 void dt_fixup_mac_address_by_alias(const char *alias, const u8 *addr);
0197 void dt_fixup_mac_address(u32 index, const u8 *addr);
0198 void __dt_fixup_mac_addresses(u32 startindex, ...);
0199 #define dt_fixup_mac_addresses(...) \
0200 __dt_fixup_mac_addresses(0, __VA_ARGS__, NULL)
0201
0202
0203 static inline char *get_path(const void *phandle, char *buf, int len)
0204 {
0205 if (dt_ops.get_path)
0206 return dt_ops.get_path(phandle, buf, len);
0207
0208 return NULL;
0209 }
0210
0211 static inline void *malloc(unsigned long size)
0212 {
0213 return (platform_ops.malloc) ? platform_ops.malloc(size) : NULL;
0214 }
0215
0216 static inline void free(void *ptr)
0217 {
0218 if (platform_ops.free)
0219 platform_ops.free(ptr);
0220 }
0221
0222 static inline void exit(void)
0223 {
0224 if (platform_ops.exit)
0225 platform_ops.exit();
0226 for(;;);
0227 }
0228 #define fatal(args...) { printf(args); exit(); }
0229
0230
0231 #define BSS_STACK(size) \
0232 static char _bss_stack[size]; \
0233 void *_platform_stack_top = _bss_stack + sizeof(_bss_stack);
0234
0235 extern unsigned long timebase_period_ns;
0236 void udelay(long delay);
0237
0238 extern char _start[];
0239 extern char __bss_start[];
0240 extern char _end[];
0241 extern char _vmlinux_start[];
0242 extern char _vmlinux_end[];
0243 extern char _initrd_start[];
0244 extern char _initrd_end[];
0245 extern char _dtb_start[];
0246 extern char _dtb_end[];
0247 extern char _esm_blob_start[];
0248 extern char _esm_blob_end[];
0249
0250 static inline __attribute__((const))
0251 int __ilog2_u32(u32 n)
0252 {
0253 int bit;
0254 asm ("cntlzw %0,%1" : "=r" (bit) : "r" (n));
0255 return 31 - bit;
0256 }
0257
0258 long partial_decompress(void *inbuf, unsigned long input_size, void *outbuf,
0259 unsigned long output_size, unsigned long skip);
0260
0261 #endif