Add basic support for mini2440 board to barebox.
[barebox-mini2440.git] / include / common.h
blob64f49db387c8cc36cf946b61b6b963b6afd18d71
1 /*
2 * (C) Copyright 2000-2004
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
6 * project.
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
24 #ifndef __COMMON_H_
25 #define __COMMON_H_ 1
27 #include <stdio.h>
28 #include <module.h>
29 #include <config.h>
30 #include <linux/bitops.h>
31 #include <linux/types.h>
32 #include <linux/string.h>
33 #include <linux/kernel.h>
34 #include <linux/stddef.h>
35 #include <asm/common.h>
37 #define pr_info(fmt, arg...) printf(fmt, ##arg)
38 #define pr_notice(fmt, arg...) printf(fmt, ##arg)
39 #define pr_err(fmt, arg...) printf(fmt, ##arg)
40 #define pr_warning(fmt, arg...) printf(fmt, ##arg)
41 #define pr_crit(fmt, arg...) printf(fmt, ##arg)
42 #define pr_alert(fmt, arg...) printf(fmt, ##arg)
43 #define pr_emerg(fmt, arg...) printf(fmt, ##arg)
45 #ifdef DEBUG
46 #define pr_debug(fmt, arg...) printf(fmt, ##arg)
47 #else
48 #define pr_debug(fmt, arg...) do {} while(0)
49 #endif
51 #define debug(fmt, arg...) pr_debug(fmt, ##arg)
53 #define BUG() do { \
54 printf("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __FUNCTION__); \
55 panic("BUG!"); \
56 } while (0)
57 #define BUG_ON(condition) do { if (unlikely((condition)!=0)) BUG(); } while(0)
60 #define __WARN() do { \
61 printf("WARNING: at %s:%d/%s()!\n", __FILE__, __LINE__, __FUNCTION__); \
62 } while (0)
64 #ifndef WARN_ON
65 #define WARN_ON(condition) ({ \
66 int __ret_warn_on = !!(condition); \
67 if (unlikely(__ret_warn_on)) \
68 __WARN(); \
69 unlikely(__ret_warn_on); \
71 #endif
73 #ifndef WARN
74 #define WARN(condition, format...) ({ \
75 int __ret_warn_on = !!(condition); \
76 if (unlikely(__ret_warn_on)) \
77 __WARN(); \
78 puts("WARNING: "); \
79 printf(format); \
80 unlikely(__ret_warn_on); \
82 #endif
84 typedef void (interrupt_handler_t)(void *);
86 #include <asm/barebox.h> /* boot information for Linux kernel */
89 * Function Prototypes
91 void reginfo(void);
93 void __noreturn hang (void);
94 void __noreturn panic(const char *fmt, ...);
96 /* */
97 long int initdram (int);
98 char *size_human_readable(ulong size);
100 /* common/main.c */
101 int run_command (const char *cmd, int flag);
102 int readline (const char *prompt, char *buf, int len);
104 /* common/memsize.c */
105 long get_ram_size (volatile long *, long);
107 /* $(CPU)/cpu.c */
108 void __noreturn reset_cpu(unsigned long addr);
110 /* $(CPU)/interrupts.c */
111 //void timer_interrupt (struct pt_regs *);
112 //void external_interrupt (struct pt_regs *);
113 void irq_install_handler(int, interrupt_handler_t *, void *);
114 void irq_free_handler (int);
115 #ifdef CONFIG_USE_IRQ
116 void enable_interrupts (void);
117 int disable_interrupts (void);
118 #else
119 #define enable_interrupts() do {} while (0)
120 #define disable_interrupts() 0
121 #endif
123 /* lib_$(ARCH)/time.c */
124 void udelay (unsigned long);
125 void mdelay (unsigned long);
127 int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp);
129 /* lib_generic/vsprintf.c */
130 ulong simple_strtoul(const char *cp,char **endp,unsigned int base);
131 #ifdef CFG_64BIT_VSPRINTF
132 unsigned long long simple_strtoull(const char *cp,char **endp,unsigned int base);
133 #endif
134 long simple_strtol(const char *cp,char **endp,unsigned int base);
136 /* lib_generic/crc32.c */
137 uint32_t crc32(uint32_t, const void*, unsigned int);
138 uint32_t crc32_no_comp(uint32_t, const void*, unsigned int);
140 /* common/console.c */
141 int ctrlc (void);
143 #define MEMAREA_SIZE_SPECIFIED 1
145 struct memarea_info {
146 struct device_d *device;
147 unsigned long start;
148 unsigned long end;
149 unsigned long size;
150 unsigned long flags;
153 int spec_str_to_info(const char *str, struct memarea_info *info);
154 int parse_area_spec(const char *str, ulong *start, ulong *size);
156 /* Just like simple_strtoul(), but this one honors a K/M/G suffix */
157 unsigned long strtoul_suffix(const char *str, char **endp, int base);
159 void start_barebox(void);
160 void shutdown_barebox(void);
162 void arch_shutdown(void);
164 int run_shell(void);
166 /* Force a compilation error if condition is true */
167 #define BUILD_BUG_ON(condition) ((void)BUILD_BUG_ON_ZERO(condition))
169 /* Force a compilation error if condition is constant and true */
170 #define MAYBE_BUILD_BUG_ON(cond) ((void)sizeof(char[1 - 2 * !!(cond)]))
172 /* Force a compilation error if a constant expression is not a power of 2 */
173 #define BUILD_BUG_ON_NOT_POWER_OF_2(n) \
174 BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0))
177 * Force a compilation error if condition is true, but also produce a
178 * result (of value 0 and type size_t), so the expression can be used
179 * e.g. in a structure initializer (or where-ever else comma
180 * expressions aren't permitted).
182 #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
183 #define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); }))
185 #define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1)
186 #define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask))
187 #define PTR_ALIGN(p, a) ((typeof(p))ALIGN((unsigned long)(p), (a)))
188 #define IS_ALIGNED(x, a) (((x) & ((typeof(x))(a) - 1)) == 0)
190 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
191 #define ARRAY_AND_SIZE(x) (x), ARRAY_SIZE(x)
194 * container_of - cast a member of a structure out to the containing structure
195 * @ptr: the pointer to the member.
196 * @type: the type of the container struct this is embedded in.
197 * @member: the name of the member within the struct.
200 #define container_of(ptr, type, member) ({ \
201 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
202 (type *)( (char *)__mptr - offsetof(type,member) );})
204 #define USHORT_MAX ((u16)(~0U))
205 #define SHORT_MAX ((s16)(USHORT_MAX>>1))
206 #define SHORT_MIN (-SHORT_MAX - 1)
207 #define INT_MAX ((int)(~0U>>1))
208 #define INT_MIN (-INT_MAX - 1)
209 #define UINT_MAX (~0U)
210 #define LONG_MAX ((long)(~0UL>>1))
211 #define LONG_MIN (-LONG_MAX - 1)
212 #define ULONG_MAX (~0UL)
213 #define LLONG_MAX ((long long)(~0ULL>>1))
214 #define LLONG_MIN (-LLONG_MAX - 1)
215 #define ULLONG_MAX (~0ULL)
217 #define PAGE_SIZE 4096
219 #endif /* __COMMON_H_ */