Mark A. Greer | b2c5f61 | 2006-09-19 14:05:08 +1000 | [diff] [blame] | 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 | |
Scott Wood | ce3edb3 | 2007-03-12 14:41:38 -0600 | [diff] [blame] | 14 | #include <stddef.h> |
Mark A. Greer | b2c5f61 | 2006-09-19 14:05:08 +1000 | [diff] [blame] | 15 | #include "types.h" |
| 16 | |
| 17 | #define COMMAND_LINE_SIZE 512 |
| 18 | #define MAX_PATH_LEN 256 |
| 19 | #define MAX_PROP_LEN 256 /* What should this be? */ |
| 20 | |
| 21 | /* Platform specific operations */ |
| 22 | struct platform_ops { |
| 23 | void (*fixups)(void); |
| 24 | void (*image_hdr)(const void *); |
| 25 | void * (*malloc)(u32 size); |
Mark A. Greer | c888554 | 2006-10-16 13:49:27 -0700 | [diff] [blame] | 26 | void (*free)(void *ptr); |
| 27 | void * (*realloc)(void *ptr, unsigned long size); |
Mark A. Greer | b2c5f61 | 2006-09-19 14:05:08 +1000 | [diff] [blame] | 28 | void (*exit)(void); |
David Gibson | 79c8541 | 2007-03-05 14:24:52 +1100 | [diff] [blame] | 29 | void * (*vmlinux_alloc)(unsigned long size); |
Mark A. Greer | b2c5f61 | 2006-09-19 14:05:08 +1000 | [diff] [blame] | 30 | }; |
| 31 | extern struct platform_ops platform_ops; |
| 32 | |
| 33 | /* Device Tree operations */ |
| 34 | struct dt_ops { |
| 35 | void * (*finddevice)(const char *name); |
Mark A. Greer | c888554 | 2006-10-16 13:49:27 -0700 | [diff] [blame] | 36 | int (*getprop)(const void *phandle, const char *name, void *buf, |
Mark A. Greer | b2c5f61 | 2006-09-19 14:05:08 +1000 | [diff] [blame] | 37 | const int buflen); |
Mark A. Greer | c888554 | 2006-10-16 13:49:27 -0700 | [diff] [blame] | 38 | int (*setprop)(const void *phandle, const char *name, |
Mark A. Greer | b2c5f61 | 2006-09-19 14:05:08 +1000 | [diff] [blame] | 39 | const void *buf, const int buflen); |
David Gibson | 35af89e | 2006-11-21 11:37:37 +1100 | [diff] [blame] | 40 | unsigned long (*finalize)(void); |
Mark A. Greer | b2c5f61 | 2006-09-19 14:05:08 +1000 | [diff] [blame] | 41 | }; |
| 42 | extern struct dt_ops dt_ops; |
| 43 | |
| 44 | /* Console operations */ |
| 45 | struct console_ops { |
| 46 | int (*open)(void); |
| 47 | void (*write)(char *buf, int len); |
| 48 | void (*edit_cmdline)(char *buf, int len); |
| 49 | void (*close)(void); |
| 50 | void *data; |
| 51 | }; |
| 52 | extern struct console_ops console_ops; |
| 53 | |
| 54 | /* Serial console operations */ |
| 55 | struct serial_console_data { |
| 56 | int (*open)(void); |
| 57 | void (*putc)(unsigned char c); |
| 58 | unsigned char (*getc)(void); |
| 59 | u8 (*tstc)(void); |
| 60 | void (*close)(void); |
| 61 | }; |
| 62 | |
David Gibson | cd197ff | 2007-03-05 14:24:52 +1100 | [diff] [blame] | 63 | struct loader_info { |
| 64 | void *promptr; |
| 65 | unsigned long initrd_addr, initrd_size; |
| 66 | }; |
| 67 | extern struct loader_info loader_info; |
| 68 | |
| 69 | void start(void *sp); |
Mark A. Greer | c888554 | 2006-10-16 13:49:27 -0700 | [diff] [blame] | 70 | int ft_init(void *dt_blob, unsigned int max_size, unsigned int max_find_device); |
| 71 | int serial_console_init(void); |
| 72 | int ns16550_console_init(void *devp, struct serial_console_data *scdp); |
| 73 | void *simple_alloc_init(char *base, u32 heap_size, u32 granularity, |
| 74 | u32 max_allocs); |
| 75 | |
Mark A. Greer | b2c5f61 | 2006-09-19 14:05:08 +1000 | [diff] [blame] | 76 | |
| 77 | static inline void *finddevice(const char *name) |
| 78 | { |
| 79 | return (dt_ops.finddevice) ? dt_ops.finddevice(name) : NULL; |
| 80 | } |
| 81 | |
| 82 | static inline int getprop(void *devp, const char *name, void *buf, int buflen) |
| 83 | { |
| 84 | return (dt_ops.getprop) ? dt_ops.getprop(devp, name, buf, buflen) : -1; |
| 85 | } |
| 86 | |
| 87 | static inline int setprop(void *devp, const char *name, void *buf, int buflen) |
| 88 | { |
| 89 | return (dt_ops.setprop) ? dt_ops.setprop(devp, name, buf, buflen) : -1; |
| 90 | } |
| 91 | |
| 92 | static inline void *malloc(u32 size) |
| 93 | { |
| 94 | return (platform_ops.malloc) ? platform_ops.malloc(size) : NULL; |
| 95 | } |
| 96 | |
Mark A. Greer | c888554 | 2006-10-16 13:49:27 -0700 | [diff] [blame] | 97 | static inline void free(void *ptr) |
Mark A. Greer | b2c5f61 | 2006-09-19 14:05:08 +1000 | [diff] [blame] | 98 | { |
| 99 | if (platform_ops.free) |
Mark A. Greer | c888554 | 2006-10-16 13:49:27 -0700 | [diff] [blame] | 100 | platform_ops.free(ptr); |
Mark A. Greer | b2c5f61 | 2006-09-19 14:05:08 +1000 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | static inline void exit(void) |
| 104 | { |
| 105 | if (platform_ops.exit) |
| 106 | platform_ops.exit(); |
| 107 | for(;;); |
| 108 | } |
| 109 | |
David Gibson | cd197ff | 2007-03-05 14:24:52 +1100 | [diff] [blame] | 110 | #define BSS_STACK(size) \ |
| 111 | static char _bss_stack[size]; \ |
| 112 | void *_platform_stack_top = _bss_stack + sizeof(_bss_stack); |
| 113 | |
Mark A. Greer | b2c5f61 | 2006-09-19 14:05:08 +1000 | [diff] [blame] | 114 | #endif /* _PPC_BOOT_OPS_H_ */ |