usb-serial: acquire references when a new tty is installed
[linux-2.6/mini2440.git] / arch / x86 / boot / boot.h
blob98239d2658f27b3ed3494ea1b0ad3d6cd0a01624
1 /* -*- linux-c -*- ------------------------------------------------------- *
3 * Copyright (C) 1991, 1992 Linus Torvalds
4 * Copyright 2007 rPath, Inc. - All Rights Reserved
5 * Copyright 2009 Intel Corporation; author H. Peter Anvin
7 * This file is part of the Linux kernel, and is made available under
8 * the terms of the GNU General Public License version 2.
10 * ----------------------------------------------------------------------- */
13 * Header file for the real-mode kernel code
16 #ifndef BOOT_BOOT_H
17 #define BOOT_BOOT_H
19 #define STACK_SIZE 512 /* Minimum number of bytes for stack */
21 #ifndef __ASSEMBLY__
23 #include <stdarg.h>
24 #include <linux/types.h>
25 #include <linux/edd.h>
26 #include <asm/boot.h>
27 #include <asm/setup.h>
28 #include "bitops.h"
29 #include <asm/cpufeature.h>
30 #include <asm/processor-flags.h>
32 /* Useful macros */
33 #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
35 #define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
37 extern struct setup_header hdr;
38 extern struct boot_params boot_params;
40 /* Basic port I/O */
41 static inline void outb(u8 v, u16 port)
43 asm volatile("outb %0,%1" : : "a" (v), "dN" (port));
45 static inline u8 inb(u16 port)
47 u8 v;
48 asm volatile("inb %1,%0" : "=a" (v) : "dN" (port));
49 return v;
52 static inline void outw(u16 v, u16 port)
54 asm volatile("outw %0,%1" : : "a" (v), "dN" (port));
56 static inline u16 inw(u16 port)
58 u16 v;
59 asm volatile("inw %1,%0" : "=a" (v) : "dN" (port));
60 return v;
63 static inline void outl(u32 v, u16 port)
65 asm volatile("outl %0,%1" : : "a" (v), "dN" (port));
67 static inline u32 inl(u32 port)
69 u32 v;
70 asm volatile("inl %1,%0" : "=a" (v) : "dN" (port));
71 return v;
74 static inline void io_delay(void)
76 const u16 DELAY_PORT = 0x80;
77 asm volatile("outb %%al,%0" : : "dN" (DELAY_PORT));
80 /* These functions are used to reference data in other segments. */
82 static inline u16 ds(void)
84 u16 seg;
85 asm("movw %%ds,%0" : "=rm" (seg));
86 return seg;
89 static inline void set_fs(u16 seg)
91 asm volatile("movw %0,%%fs" : : "rm" (seg));
93 static inline u16 fs(void)
95 u16 seg;
96 asm volatile("movw %%fs,%0" : "=rm" (seg));
97 return seg;
100 static inline void set_gs(u16 seg)
102 asm volatile("movw %0,%%gs" : : "rm" (seg));
104 static inline u16 gs(void)
106 u16 seg;
107 asm volatile("movw %%gs,%0" : "=rm" (seg));
108 return seg;
111 typedef unsigned int addr_t;
113 static inline u8 rdfs8(addr_t addr)
115 u8 v;
116 asm volatile("movb %%fs:%1,%0" : "=q" (v) : "m" (*(u8 *)addr));
117 return v;
119 static inline u16 rdfs16(addr_t addr)
121 u16 v;
122 asm volatile("movw %%fs:%1,%0" : "=r" (v) : "m" (*(u16 *)addr));
123 return v;
125 static inline u32 rdfs32(addr_t addr)
127 u32 v;
128 asm volatile("movl %%fs:%1,%0" : "=r" (v) : "m" (*(u32 *)addr));
129 return v;
132 static inline void wrfs8(u8 v, addr_t addr)
134 asm volatile("movb %1,%%fs:%0" : "+m" (*(u8 *)addr) : "qi" (v));
136 static inline void wrfs16(u16 v, addr_t addr)
138 asm volatile("movw %1,%%fs:%0" : "+m" (*(u16 *)addr) : "ri" (v));
140 static inline void wrfs32(u32 v, addr_t addr)
142 asm volatile("movl %1,%%fs:%0" : "+m" (*(u32 *)addr) : "ri" (v));
145 static inline u8 rdgs8(addr_t addr)
147 u8 v;
148 asm volatile("movb %%gs:%1,%0" : "=q" (v) : "m" (*(u8 *)addr));
149 return v;
151 static inline u16 rdgs16(addr_t addr)
153 u16 v;
154 asm volatile("movw %%gs:%1,%0" : "=r" (v) : "m" (*(u16 *)addr));
155 return v;
157 static inline u32 rdgs32(addr_t addr)
159 u32 v;
160 asm volatile("movl %%gs:%1,%0" : "=r" (v) : "m" (*(u32 *)addr));
161 return v;
164 static inline void wrgs8(u8 v, addr_t addr)
166 asm volatile("movb %1,%%gs:%0" : "+m" (*(u8 *)addr) : "qi" (v));
168 static inline void wrgs16(u16 v, addr_t addr)
170 asm volatile("movw %1,%%gs:%0" : "+m" (*(u16 *)addr) : "ri" (v));
172 static inline void wrgs32(u32 v, addr_t addr)
174 asm volatile("movl %1,%%gs:%0" : "+m" (*(u32 *)addr) : "ri" (v));
177 /* Note: these only return true/false, not a signed return value! */
178 static inline int memcmp(const void *s1, const void *s2, size_t len)
180 u8 diff;
181 asm("repe; cmpsb; setnz %0"
182 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
183 return diff;
186 static inline int memcmp_fs(const void *s1, addr_t s2, size_t len)
188 u8 diff;
189 asm volatile("fs; repe; cmpsb; setnz %0"
190 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
191 return diff;
193 static inline int memcmp_gs(const void *s1, addr_t s2, size_t len)
195 u8 diff;
196 asm volatile("gs; repe; cmpsb; setnz %0"
197 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
198 return diff;
201 static inline int isdigit(int ch)
203 return (ch >= '0') && (ch <= '9');
206 /* Heap -- available for dynamic lists. */
207 extern char _end[];
208 extern char *HEAP;
209 extern char *heap_end;
210 #define RESET_HEAP() ((void *)( HEAP = _end ))
211 static inline char *__get_heap(size_t s, size_t a, size_t n)
213 char *tmp;
215 HEAP = (char *)(((size_t)HEAP+(a-1)) & ~(a-1));
216 tmp = HEAP;
217 HEAP += s*n;
218 return tmp;
220 #define GET_HEAP(type, n) \
221 ((type *)__get_heap(sizeof(type),__alignof__(type),(n)))
223 static inline bool heap_free(size_t n)
225 return (int)(heap_end-HEAP) >= (int)n;
228 /* copy.S */
230 void copy_to_fs(addr_t dst, void *src, size_t len);
231 void *copy_from_fs(void *dst, addr_t src, size_t len);
232 void copy_to_gs(addr_t dst, void *src, size_t len);
233 void *copy_from_gs(void *dst, addr_t src, size_t len);
234 void *memcpy(void *dst, void *src, size_t len);
235 void *memset(void *dst, int c, size_t len);
237 #define memcpy(d,s,l) __builtin_memcpy(d,s,l)
238 #define memset(d,c,l) __builtin_memset(d,c,l)
240 /* a20.c */
241 int enable_a20(void);
243 /* apm.c */
244 int query_apm_bios(void);
246 /* bioscall.c */
247 struct biosregs {
248 union {
249 struct {
250 u32 edi;
251 u32 esi;
252 u32 ebp;
253 u32 _esp;
254 u32 ebx;
255 u32 edx;
256 u32 ecx;
257 u32 eax;
258 u32 _fsgs;
259 u32 _dses;
260 u32 eflags;
262 struct {
263 u16 di, hdi;
264 u16 si, hsi;
265 u16 bp, hbp;
266 u16 _sp, _hsp;
267 u16 bx, hbx;
268 u16 dx, hdx;
269 u16 cx, hcx;
270 u16 ax, hax;
271 u16 gs, fs;
272 u16 es, ds;
273 u16 flags, hflags;
275 struct {
276 u8 dil, dih, edi2, edi3;
277 u8 sil, sih, esi2, esi3;
278 u8 bpl, bph, ebp2, ebp3;
279 u8 _spl, _sph, _esp2, _esp3;
280 u8 bl, bh, ebx2, ebx3;
281 u8 dl, dh, edx2, edx3;
282 u8 cl, ch, ecx2, ecx3;
283 u8 al, ah, eax2, eax3;
287 void intcall(u8 int_no, const struct biosregs *ireg, struct biosregs *oreg);
289 /* cmdline.c */
290 int cmdline_find_option(const char *option, char *buffer, int bufsize);
291 int cmdline_find_option_bool(const char *option);
293 /* cpu.c, cpucheck.c */
294 struct cpu_features {
295 int level; /* Family, or 64 for x86-64 */
296 int model;
297 u32 flags[NCAPINTS];
299 extern struct cpu_features cpu;
300 int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr);
301 int validate_cpu(void);
303 /* edd.c */
304 void query_edd(void);
306 /* header.S */
307 void __attribute__((noreturn)) die(void);
309 /* mca.c */
310 int query_mca(void);
312 /* memory.c */
313 int detect_memory(void);
315 /* pm.c */
316 void __attribute__((noreturn)) go_to_protected_mode(void);
318 /* pmjump.S */
319 void __attribute__((noreturn))
320 protected_mode_jump(u32 entrypoint, u32 bootparams);
322 /* printf.c */
323 int sprintf(char *buf, const char *fmt, ...);
324 int vsprintf(char *buf, const char *fmt, va_list args);
325 int printf(const char *fmt, ...);
327 /* regs.c */
328 void initregs(struct biosregs *regs);
330 /* string.c */
331 int strcmp(const char *str1, const char *str2);
332 size_t strnlen(const char *s, size_t maxlen);
333 unsigned int atou(const char *s);
335 /* tty.c */
336 void puts(const char *);
337 void putchar(int);
338 int getchar(void);
339 void kbd_flush(void);
340 int getchar_timeout(void);
342 /* video.c */
343 void set_video(void);
345 /* video-mode.c */
346 int set_mode(u16 mode);
347 int mode_defined(u16 mode);
348 void probe_cards(int unsafe);
350 /* video-vesa.c */
351 void vesa_store_edid(void);
353 #endif /* __ASSEMBLY__ */
355 #endif /* BOOT_BOOT_H */