driver: add dev_name inline
[barebox-mini2440.git] / include / common.h
blob3df1f7fbfd11c3fd82082dfc20c7e6af53e33c4f
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 <asm/common.h>
36 #define pr_info(fmt, arg...) printf(fmt, ##arg)
37 #define pr_notice(fmt, arg...) printf(fmt, ##arg)
38 #define pr_err(fmt, arg...) printf(fmt, ##arg)
39 #define pr_warning(fmt, arg...) printf(fmt, ##arg)
40 #define pr_crit(fmt, arg...) printf(fmt, ##arg)
41 #define pr_alert(fmt, arg...) printf(fmt, ##arg)
42 #define pr_emerg(fmt, arg...) printf(fmt, ##arg)
44 #ifdef DEBUG
45 #define pr_debug(fmt, arg...) printf(fmt, ##arg)
46 #else
47 #define pr_debug(fmt, arg...) do {} while(0)
48 #endif
50 #define debug(fmt, arg...) pr_debug(fmt, ##arg)
52 #define BUG() do { \
53 printf("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __FUNCTION__); \
54 panic("BUG!"); \
55 } while (0)
56 #define BUG_ON(condition) do { if (unlikely((condition)!=0)) BUG(); } while(0)
58 typedef void (interrupt_handler_t)(void *);
60 #include <asm/u-boot.h> /* boot information for Linux kernel */
63 * Function Prototypes
65 void reginfo(void);
67 void hang (void) __attribute__ ((noreturn));
68 void panic(const char *fmt, ...);
70 /* */
71 long int initdram (int);
72 char *size_human_readable(ulong size);
74 /* common/main.c */
75 int run_command (const char *cmd, int flag);
76 int readline (const char *prompt, char *buf, int len);
78 /* common/memsize.c */
79 long get_ram_size (volatile long *, long);
81 /* $(CPU)/cpu.c */
82 void reset_cpu (ulong addr);
84 /* $(CPU)/interrupts.c */
85 //void timer_interrupt (struct pt_regs *);
86 //void external_interrupt (struct pt_regs *);
87 void irq_install_handler(int, interrupt_handler_t *, void *);
88 void irq_free_handler (int);
89 #ifdef CONFIG_USE_IRQ
90 void enable_interrupts (void);
91 int disable_interrupts (void);
92 #else
93 #define enable_interrupts() do {} while (0)
94 #define disable_interrupts() 0
95 #endif
97 /* lib_$(ARCH)/time.c */
98 void udelay (unsigned long);
99 void mdelay (unsigned long);
101 int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp);
103 /* lib_generic/vsprintf.c */
104 ulong simple_strtoul(const char *cp,char **endp,unsigned int base);
105 #ifdef CFG_64BIT_VSPRINTF
106 unsigned long long simple_strtoull(const char *cp,char **endp,unsigned int base);
107 #endif
108 long simple_strtol(const char *cp,char **endp,unsigned int base);
110 /* lib_generic/crc32.c */
111 ulong crc32 (ulong, const unsigned char *, uint);
112 ulong crc32_no_comp (ulong, const unsigned char *, uint);
114 /* common/console.c */
115 int ctrlc (void);
117 #define MEMAREA_SIZE_SPECIFIED 1
119 struct memarea_info {
120 struct device_d *device;
121 unsigned long start;
122 unsigned long end;
123 unsigned long size;
124 unsigned long flags;
127 int spec_str_to_info(const char *str, struct memarea_info *info);
128 int parse_area_spec(const char *str, ulong *start, ulong *size);
130 /* Just like simple_strtoul(), but this one honors a K/M/G suffix */
131 unsigned long strtoul_suffix(const char *str, char **endp, int base);
133 void start_uboot(void);
134 void shutdown_uboot(void);
136 int arch_execute(unsigned long address, int argc, char *argv[]);
138 int run_shell(void);
140 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
143 * container_of - cast a member of a structure out to the containing structure
144 * @ptr: the pointer to the member.
145 * @type: the type of the container struct this is embedded in.
146 * @member: the name of the member within the struct.
149 #define container_of(ptr, type, member) ({ \
150 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
151 (type *)( (char *)__mptr - offsetof(type,member) );})
153 #define USHORT_MAX ((u16)(~0U))
154 #define SHORT_MAX ((s16)(USHORT_MAX>>1))
155 #define SHORT_MIN (-SHORT_MAX - 1)
156 #define INT_MAX ((int)(~0U>>1))
157 #define INT_MIN (-INT_MAX - 1)
158 #define UINT_MAX (~0U)
159 #define LONG_MAX ((long)(~0UL>>1))
160 #define LONG_MIN (-LONG_MAX - 1)
161 #define ULONG_MAX (~0UL)
162 #define LLONG_MAX ((long long)(~0ULL>>1))
163 #define LLONG_MIN (-LLONG_MAX - 1)
164 #define ULLONG_MAX (~0ULL)
166 #endif /* __COMMON_H_ */