blob: 7034d43e1d13baac9ed32ef81f136321bd48b60c [file] [log] [blame]
Kevin O'Connorf076a3e2008-02-25 22:25:15 -05001// Basic x86 asm functions and function defs.
2//
Kevin O'Connor244caf82010-09-15 21:48:16 -04003// Copyright (C) 2008-2010 Kevin O'Connor <kevin@koconnor.net>
Kevin O'Connorf076a3e2008-02-25 22:25:15 -05004//
Kevin O'Connorb1b7c2a2009-01-15 20:52:58 -05005// This file may be distributed under the terms of the GNU LGPLv3 license.
Kevin O'Connor786502d2008-02-27 10:41:41 -05006#ifndef __UTIL_H
7#define __UTIL_H
Kevin O'Connorf076a3e2008-02-25 22:25:15 -05008
Kevin O'Connor9521e262008-07-04 13:04:29 -04009#include "types.h" // u32
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050010
Kevin O'Connor786502d2008-02-27 10:41:41 -050011static inline void irq_disable(void)
12{
13 asm volatile("cli": : :"memory");
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050014}
15
Kevin O'Connor786502d2008-02-27 10:41:41 -050016static inline void irq_enable(void)
17{
18 asm volatile("sti": : :"memory");
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050019}
20
21static inline unsigned long irq_save(void)
22{
23 unsigned long flags;
Kevin O'Connor9c447c32010-05-23 10:24:22 -040024 asm volatile("pushfl ; popl %0" : "=g" (flags): :"memory");
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050025 irq_disable();
26 return flags;
27}
28
29static inline void irq_restore(unsigned long flags)
30{
31 asm volatile("pushl %0 ; popfl" : : "g" (flags) : "memory", "cc");
32}
33
Kevin O'Connor06ad44e2008-04-05 19:30:02 -040034static inline void cpu_relax(void)
35{
36 asm volatile("rep ; nop": : :"memory");
37}
38
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -050039static inline void nop(void)
40{
41 asm volatile("nop");
42}
43
Kevin O'Connor95b2f782008-03-05 19:52:06 -050044static inline void hlt(void)
45{
Kevin O'Connor9c447c32010-05-23 10:24:22 -040046 asm volatile("hlt": : :"memory");
Kevin O'Connor95b2f782008-03-05 19:52:06 -050047}
48
Kevin O'Connorda4a6482008-06-08 13:48:06 -040049static inline void wbinvd(void)
50{
Kevin O'Connor9c447c32010-05-23 10:24:22 -040051 asm volatile("wbinvd": : :"memory");
Kevin O'Connorda4a6482008-06-08 13:48:06 -040052}
53
Kevin O'Connore97ca7b2009-06-21 09:10:28 -040054#define CPUID_MSR (1 << 5)
55#define CPUID_APIC (1 << 9)
56#define CPUID_MTRR (1 << 12)
Kevin O'Connor84ad59a2008-07-04 05:47:26 -040057static inline void cpuid(u32 index, u32 *eax, u32 *ebx, u32 *ecx, u32 *edx)
58{
59 asm("cpuid"
60 : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
61 : "0" (index));
62}
63
Kevin O'Connore97ca7b2009-06-21 09:10:28 -040064static inline u64 rdmsr(u32 index)
65{
66 u64 ret;
67 asm ("rdmsr" : "=A"(ret) : "c"(index));
68 return ret;
69}
70
71static inline void wrmsr(u32 index, u64 val)
72{
73 asm volatile ("wrmsr" : : "c"(index), "A"(val));
74}
75
Kevin O'Connorbc2aecd2008-11-28 16:40:06 -050076static inline u64 rdtscll(void)
77{
78 u64 val;
79 asm volatile("rdtsc" : "=A" (val));
80 return val;
81}
82
Kevin O'Connor0bf92702009-08-01 11:45:37 -040083static inline u32 __ffs(u32 word)
84{
85 asm("bsf %1,%0"
86 : "=r" (word)
87 : "rm" (word));
88 return word;
89}
Kevin O'Connor86916ce2009-11-14 13:34:27 -050090static inline u32 __fls(u32 word)
91{
92 asm("bsr %1,%0"
93 : "=r" (word)
94 : "rm" (word));
95 return word;
96}
Kevin O'Connor0bf92702009-08-01 11:45:37 -040097
Kevin O'Connor68caaa72010-02-15 10:46:37 -050098static inline u16 __htons_constant(u16 val) {
99 return (val<<8) | (val>>8);
100}
101static inline u32 __htonl_constant(u32 val) {
102 return (val<<24) | ((val&0xff00)<<8) | ((val&0xff0000)>>8) | (val>>24);
103}
104static inline u32 __htonl(u32 val) {
105 asm("bswapl %0" : "+r"(val));
106 return val;
107}
108#define htonl(x) (__builtin_constant_p((u32)(x)) ? __htonl_constant(x) : __htonl(x))
109#define ntohl(x) htonl(x)
110#define htons(x) __htons_constant(x)
111#define ntohs(x) htons(x)
112
Isaku Yamahata2f54bb42010-07-20 16:37:16 +0900113static inline u16 cpu_to_le16(u16 x)
114{
115 return x;
116}
117
118static inline u32 cpu_to_le32(u32 x)
119{
120 return x;
121}
122
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500123static inline u32 getesp(void) {
Kevin O'Connor7cefbfa2009-12-10 21:35:49 -0500124 u32 esp;
125 asm("movl %%esp, %0" : "=rm"(esp));
126 return esp;
127}
128
Kevin O'Connor91031ed2009-10-12 09:49:27 -0400129static inline void writel(void *addr, u32 val) {
130 *(volatile u32 *)addr = val;
131}
132static inline void writew(void *addr, u16 val) {
133 *(volatile u16 *)addr = val;
134}
135static inline void writeb(void *addr, u8 val) {
136 *(volatile u8 *)addr = val;
137}
138static inline u32 readl(const void *addr) {
139 return *(volatile const u32 *)addr;
140}
141static inline u16 readw(const void *addr) {
142 return *(volatile const u16 *)addr;
143}
144static inline u8 readb(const void *addr) {
145 return *(volatile const u8 *)addr;
146}
147
Kevin O'Connor942d4952009-06-10 22:44:06 -0400148#define call16_simpint(nr, peax, pflags) do { \
Kevin O'Connor0b60a062009-06-15 23:03:05 -0400149 ASSERT16(); \
Kevin O'Connor942d4952009-06-10 22:44:06 -0400150 asm volatile( \
Kevin O'Connor4ed378a2010-03-13 22:29:55 -0500151 "pushl %%ebp\n" \
152 "sti\n" \
Kevin O'Connor942d4952009-06-10 22:44:06 -0400153 "stc\n" \
154 "int %2\n" \
155 "pushfl\n" \
156 "popl %1\n" \
157 "cli\n" \
Kevin O'Connor4ed378a2010-03-13 22:29:55 -0500158 "cld\n" \
159 "popl %%ebp" \
160 : "+a"(*peax), "=c"(*pflags) \
Kevin O'Connor942d4952009-06-10 22:44:06 -0400161 : "i"(nr) \
Kevin O'Connor4ed378a2010-03-13 22:29:55 -0500162 : "ebx", "edx", "esi", "edi", "cc", "memory"); \
Kevin O'Connor942d4952009-06-10 22:44:06 -0400163 } while (0)
164
Kevin O'Connorae6924d2010-07-25 14:46:21 -0400165// GDT bits
Kevin O'Connorad901592009-12-13 11:25:25 -0500166#define GDT_CODE (0x9bULL << 40) // Code segment - P,R,A bits also set
167#define GDT_DATA (0x93ULL << 40) // Data segment - W,A bits also set
168#define GDT_B (0x1ULL << 54) // Big flag
169#define GDT_G (0x1ULL << 55) // Granularity flag
Kevin O'Connorae6924d2010-07-25 14:46:21 -0400170// GDT bits for segment base
171#define GDT_BASE(v) ((((u64)(v) & 0xff000000) << 32) \
172 | (((u64)(v) & 0x00ffffff) << 16))
173// GDT bits for segment limit (0-1Meg)
174#define GDT_LIMIT(v) ((((u64)(v) & 0x000f0000) << 32) \
175 | (((u64)(v) & 0x0000ffff) << 0))
176// GDT bits for segment limit (0-4Gig in 4K chunks)
177#define GDT_GRANLIMIT(v) (GDT_G | GDT_LIMIT((v) >> 12))
Kevin O'Connorad901592009-12-13 11:25:25 -0500178
179struct descloc_s {
180 u16 length;
181 u32 addr;
182} PACKED;
183
Kevin O'Connora83ff552009-01-01 21:00:59 -0500184// util.c
Kevin O'Connor9521e262008-07-04 13:04:29 -0400185struct bregs;
186inline void call16(struct bregs *callregs);
Kevin O'Connor6e5b4a42008-12-06 13:03:52 -0500187inline void call16big(struct bregs *callregs);
Kevin O'Connor9521e262008-07-04 13:04:29 -0400188inline void __call16_int(struct bregs *callregs, u16 offset);
Kevin O'Connor3a47a312008-03-01 14:46:37 -0500189#define call16_int(nr, callregs) do { \
190 extern void irq_trampoline_ ##nr (); \
Kevin O'Connor117fc212008-04-13 18:17:02 -0400191 __call16_int((callregs), (u32)&irq_trampoline_ ##nr ); \
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500192 } while (0)
Kevin O'Connor7cefbfa2009-12-10 21:35:49 -0500193u8 checksum_far(u16 buf_seg, void *buf_far, u32 len);
194u8 checksum(void *buf, u32 len);
195size_t strlen(const char *s);
196int memcmp(const void *s1, const void *s2, size_t n);
197int strcmp(const char *s1, const char *s2);
198inline void memset_far(u16 d_seg, void *d_far, u8 c, size_t len);
199inline void memset16_far(u16 d_seg, void *d_far, u16 c, size_t len);
200void *memset(void *s, int c, size_t n);
Gerd Hoffmann0a806082010-11-29 09:42:11 +0100201void memset_fl(void *ptr, u8 val, size_t size);
Kevin O'Connor7cefbfa2009-12-10 21:35:49 -0500202inline void memcpy_far(u16 d_seg, void *d_far
203 , u16 s_seg, const void *s_far, size_t len);
Kevin O'Connor8f59aa32010-06-06 16:11:45 -0400204void memcpy_fl(void *d_fl, const void *s_fl, size_t len);
Kevin O'Connor7cefbfa2009-12-10 21:35:49 -0500205void *memcpy(void *d1, const void *s1, size_t len);
Kevin O'Connor52a300f2009-12-26 23:32:57 -0500206#if MODESEGMENT == 0
Kevin O'Connor7cefbfa2009-12-10 21:35:49 -0500207#define memcpy __builtin_memcpy
208#endif
209void iomemcpy(void *d, const void *s, u32 len);
210void *memmove(void *d, const void *s, size_t len);
211char *strtcpy(char *dest, const char *src, size_t len);
Kevin O'Connor2e109a62010-12-24 10:39:32 -0500212char *strchr(const char *s, int c);
Kevin O'Connor9e881a32011-01-08 12:06:54 -0500213void nullTrailingSpace(char *buf);
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500214int get_keystroke(int msec);
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500215
Kevin O'Connor7cefbfa2009-12-10 21:35:49 -0500216// stacks.c
Kevin O'Connoraf9629b2010-11-25 09:17:31 -0500217u32 call32(void *func, u32 eax, u32 errret);
Kevin O'Connorbca07362010-03-20 20:41:38 -0400218inline u32 stack_hop(u32 eax, u32 edx, void *func);
Kevin O'Connor7cefbfa2009-12-10 21:35:49 -0500219extern struct thread_info MainThread;
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500220struct thread_info *getCurThread(void);
221void yield(void);
Kevin O'Connor9c447c32010-05-23 10:24:22 -0400222void wait_irq(void);
Kevin O'Connor7cefbfa2009-12-10 21:35:49 -0500223void run_thread(void (*func)(void*), void *data);
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500224void wait_threads(void);
Kevin O'Connore9086652010-02-27 13:49:47 -0500225struct mutex_s { u32 isLocked; };
226void mutex_lock(struct mutex_s *mutex);
227void mutex_unlock(struct mutex_s *mutex);
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500228void start_preempt(void);
229void finish_preempt(void);
Kevin O'Connord7eb27e2010-03-20 18:17:19 -0400230int wait_preempt(void);
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500231void check_preempt(void);
Kevin O'Connor7cefbfa2009-12-10 21:35:49 -0500232
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500233// output.c
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500234void debug_serial_setup(void);
Kevin O'Connore07e18e2009-02-08 17:07:29 -0500235void panic(const char *fmt, ...)
Kevin O'Connordad41d92010-01-01 03:04:19 -0500236 __attribute__ ((format (printf, 1, 2))) __noreturn;
Kevin O'Connor567e4e32008-04-05 11:37:51 -0400237void printf(const char *fmt, ...)
238 __attribute__ ((format (printf, 1, 2)));
Kevin O'Connor2be312c2009-11-24 09:37:53 -0500239int snprintf(char *str, size_t size, const char *fmt, ...)
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400240 __attribute__ ((format (printf, 3, 4)));
Kevin O'Connorca2bc1c2010-12-29 21:41:19 -0500241char * znprintf(size_t size, const char *fmt, ...)
242 __attribute__ ((format (printf, 2, 3)));
Kevin O'Connorcfdc13f2010-02-14 13:07:54 -0500243void __dprintf(const char *fmt, ...)
244 __attribute__ ((format (printf, 1, 2)));
245void __debug_enter(struct bregs *regs, const char *fname);
246void __debug_isr(const char *fname);
247void __debug_stub(struct bregs *regs, int lineno, const char *fname);
248void __warn_invalid(struct bregs *regs, int lineno, const char *fname);
249void __warn_unimplemented(struct bregs *regs, int lineno, const char *fname);
Kevin O'Connor7fb8ba82010-02-26 08:45:00 -0500250void __warn_internalerror(int lineno, const char *fname);
Kevin O'Connorcfdc13f2010-02-14 13:07:54 -0500251void __warn_noalloc(int lineno, const char *fname);
252void __warn_timeout(int lineno, const char *fname);
253void __set_invalid(struct bregs *regs, int lineno, const char *fname);
254void __set_unimplemented(struct bregs *regs, int lineno, const char *fname);
255void __set_code_invalid(struct bregs *regs, u32 linecode, const char *fname);
256void __set_code_unimplemented(struct bregs *regs, u32 linecode
257 , const char *fname);
258void hexdump(const void *d, int len);
259
Kevin O'Connorac8df8c2008-05-24 23:46:33 -0400260#define dprintf(lvl, fmt, args...) do { \
261 if (CONFIG_DEBUG_LEVEL && (lvl) <= CONFIG_DEBUG_LEVEL) \
262 __dprintf((fmt) , ##args ); \
263 } while (0)
Kevin O'Connor15c1f222008-06-12 22:59:43 -0400264#define debug_enter(regs, lvl) do { \
265 if ((lvl) && (lvl) <= CONFIG_DEBUG_LEVEL) \
Kevin O'Connor05600342009-01-02 13:10:58 -0500266 __debug_enter((regs), __func__); \
Kevin O'Connor15c1f222008-06-12 22:59:43 -0400267 } while (0)
268#define debug_isr(lvl) do { \
269 if ((lvl) && (lvl) <= CONFIG_DEBUG_LEVEL) \
270 __debug_isr(__func__); \
271 } while (0)
Kevin O'Connor05600342009-01-02 13:10:58 -0500272#define debug_stub(regs) \
273 __debug_stub((regs), __LINE__, __func__)
Kevin O'Connorcfdc13f2010-02-14 13:07:54 -0500274#define warn_invalid(regs) \
275 __warn_invalid((regs), __LINE__, __func__)
276#define warn_unimplemented(regs) \
277 __warn_unimplemented((regs), __LINE__, __func__)
Kevin O'Connor7fb8ba82010-02-26 08:45:00 -0500278#define warn_internalerror() \
279 __warn_internalerror(__LINE__, __func__)
Kevin O'Connorcfdc13f2010-02-14 13:07:54 -0500280#define warn_noalloc() \
281 __warn_noalloc(__LINE__, __func__)
282#define warn_timeout() \
283 __warn_timeout(__LINE__, __func__)
284#define set_invalid(regs) \
285 __set_invalid((regs), __LINE__, __func__)
286#define set_code_invalid(regs, code) \
287 __set_code_invalid((regs), (code) | (__LINE__ << 8), __func__)
288#define set_unimplemented(regs) \
289 __set_unimplemented((regs), __LINE__, __func__)
290#define set_code_unimplemented(regs, code) \
291 __set_code_unimplemented((regs), (code) | (__LINE__ << 8), __func__)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500292
293// kbd.c
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500294void kbd_setup(void);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500295void handle_15c2(struct bregs *regs);
Kevin O'Connor114592f2009-09-28 21:32:08 -0400296void process_key(u8 key);
Kevin O'Connorbdce35f2008-02-26 21:33:14 -0500297
Kevin O'Connorf54c1502008-06-14 15:56:16 -0400298// mouse.c
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500299void mouse_setup(void);
Kevin O'Connor57877482009-12-09 21:00:41 -0500300void process_mouse(u8 data);
Kevin O'Connorf54c1502008-06-14 15:56:16 -0400301
302// system.c
Kevin O'Connore7916362008-12-28 22:03:17 -0500303extern u32 RamSize;
304extern u64 RamSizeOver4G;
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500305void mathcp_setup(void);
Kevin O'Connorf54c1502008-06-14 15:56:16 -0400306
Kevin O'Connor913cc2e2008-04-13 17:31:45 -0400307// serial.c
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500308void serial_setup(void);
309void lpt_setup(void);
Kevin O'Connor913cc2e2008-04-13 17:31:45 -0400310
Kevin O'Connorbdce35f2008-02-26 21:33:14 -0500311// clock.c
Kevin O'Connor991eaff2010-02-13 21:51:47 -0500312#define PIT_TICK_RATE 1193180 // Underlying HZ of PIT
313#define PIT_TICK_INTERVAL 65536 // Default interval for 18.2Hz timer
Kevin O'Connor144817b2010-05-23 10:46:49 -0400314static inline int check_tsc(u64 end) {
Kevin O'Connor89eb6242009-10-22 22:30:37 -0400315 return (s64)(rdtscll() - end) > 0;
316}
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500317void timer_setup(void);
Kevin O'Connorbc2aecd2008-11-28 16:40:06 -0500318void ndelay(u32 count);
319void udelay(u32 count);
320void mdelay(u32 count);
Kevin O'Connor10ad7992009-10-24 11:06:08 -0400321void nsleep(u32 count);
322void usleep(u32 count);
323void msleep(u32 count);
Kevin O'Connor4e6c9702008-12-13 10:45:50 -0500324u64 calc_future_tsc(u32 msecs);
Kevin O'Connor1c46a542009-10-17 23:53:32 -0400325u64 calc_future_tsc_usec(u32 usecs);
Kevin O'Connorb5cc2ca2010-05-23 11:38:53 -0400326u32 calc_future_timer_ticks(u32 count);
327u32 calc_future_timer(u32 msecs);
328int check_timer(u32 end);
Kevin O'Connorbdce35f2008-02-26 21:33:14 -0500329void handle_1583(struct bregs *regs);
Kevin O'Connor5be04902008-05-18 17:12:06 -0400330void handle_1586(struct bregs *regs);
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500331void useRTC(void);
332void releaseRTC(void);
Kevin O'Connorbdce35f2008-02-26 21:33:14 -0500333
Kevin O'Connor95b2f782008-03-05 19:52:06 -0500334// apm.c
Kevin O'Connor244caf82010-09-15 21:48:16 -0400335void apm_shutdown(void);
Kevin O'Connorc0031482010-01-01 13:03:17 -0500336void handle_1553(struct bregs *regs);
Kevin O'Connor95b2f782008-03-05 19:52:06 -0500337
Kevin O'Connora0dc2962008-03-16 14:29:32 -0400338// pcibios.c
339void handle_1ab1(struct bregs *regs);
Kevin O'Connor871e0a02009-12-30 12:14:53 -0500340void bios32_setup(void);
Kevin O'Connora0dc2962008-03-16 14:29:32 -0400341
Kevin O'Connorda4a6482008-06-08 13:48:06 -0400342// shadow.c
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500343void make_bios_writable(void);
344void make_bios_readonly(void);
Kevin O'Connor244caf82010-09-15 21:48:16 -0400345void qemu_prep_reset(void);
Kevin O'Connorda4a6482008-06-08 13:48:06 -0400346
Isaku Yamahata58a38e82010-10-28 15:54:35 +0900347// pci_region.c
348// region allocator. pci region allocates the requested region
349// sequentially with overflow check.
350struct pci_region {
351 // The region is [first, last].
352 u32 first;
353 u32 last;
354
355 // The next allocation starts from here.
356 // i.e. [start, cur_first) is allocated.
357 // Right after initialization cur_first == first.
358 u32 cur_first;
359};
360// initialize the pci_region of [first, last]
361// last must not be 0xffffffff
362void pci_region_init(struct pci_region *r, u32 first, u32 last);
363// allocate the region of size
364u32 pci_region_alloc(struct pci_region *r, u32 size);
365// make the next allocation aligned to align
366u32 pci_region_align(struct pci_region *r, u32 align);
367// revert the allocation to addr.
368void pci_region_revert(struct pci_region *r, u32 addr);
369// make the allocation fail.
370u32 pci_region_disable(struct pci_region *r);
371// returns the current allocation point.
372u32 pci_region_addr(const struct pci_region *r);
373// returns the region size.
374u32 pci_region_size(const struct pci_region *r);
375
Kevin O'Connor0525d292008-07-04 06:18:30 -0400376// pciinit.c
Kevin O'Connor0d6b8d52010-07-10 13:12:37 -0400377extern const u8 pci_irqs[4];
Kevin O'Connor40f5b5a2009-09-13 10:46:57 -0400378void pci_setup(void);
Kevin O'Connora4d35762008-03-08 15:43:03 -0500379
Kevin O'Connorf7ba6d72008-07-04 05:05:54 -0400380// smm.c
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500381void smm_init(void);
Kevin O'Connorf7ba6d72008-07-04 05:05:54 -0400382
Kevin O'Connore97ca7b2009-06-21 09:10:28 -0400383// smp.c
Kevin O'Connor603bfc32009-06-22 20:04:56 -0400384extern u32 CountCPUs;
Kevin O'Connor84705852009-10-08 22:13:15 -0400385extern u32 MaxCountCPUs;
Kevin O'Connore97ca7b2009-06-21 09:10:28 -0400386void wrmsr_smp(u32 index, u64 val);
387void smp_probe(void);
Kevin O'Connor84ad59a2008-07-04 05:47:26 -0400388
Kevin O'Connorc7812932008-06-08 23:08:12 -0400389// coreboot.c
Kevin O'Connor1edc89d2009-04-30 21:50:35 -0400390struct cbfs_file;
Kevin O'Connore2304262010-06-13 16:05:17 -0400391struct cbfs_file *cbfs_finddatafile(const char *fname);
Kevin O'Connor1f836252009-08-16 20:17:35 -0400392struct cbfs_file *cbfs_findprefix(const char *prefix, struct cbfs_file *last);
Kevin O'Connor00882592009-08-18 22:21:10 -0400393u32 cbfs_datasize(struct cbfs_file *file);
Kevin O'Connor1f836252009-08-16 20:17:35 -0400394const char *cbfs_filename(struct cbfs_file *file);
Kevin O'Connor00882592009-08-18 22:21:10 -0400395int cbfs_copyfile(struct cbfs_file *file, void *dst, u32 maxlen);
Kevin O'Connor1f836252009-08-16 20:17:35 -0400396void cbfs_run_payload(struct cbfs_file *file);
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500397void coreboot_copy_biostable(void);
Kevin O'Connor89a1efd2011-01-08 12:24:39 -0500398void cbfs_payload_setup(void);
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500399void coreboot_setup(void);
Kevin O'Connorc7812932008-06-08 23:08:12 -0400400
Ian Campbell1442c312011-06-01 11:00:28 +0100401// biostable.c
402void copy_pir(void *pos);
403void copy_mptable(void *pos);
404void copy_acpi_rsdp(void *pos);
Ian Campbell74c78782011-06-01 11:00:29 +0100405void copy_smbios(void *pos);
Ian Campbell1442c312011-06-01 11:00:28 +0100406
Kevin O'Connorcbffa8e2008-08-17 11:11:07 -0400407// vgahooks.c
Kevin O'Connor22e1b912009-07-19 18:52:46 -0400408extern int VGAbdf;
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500409void handle_155f(struct bregs *regs);
Kevin O'Connor22e1b912009-07-19 18:52:46 -0400410void vgahook_setup(const char *vendor, const char *part);
Kevin O'Connorcbffa8e2008-08-17 11:11:07 -0400411
Kevin O'Connor714325c2008-11-01 20:32:27 -0400412// optionroms.c
Kevin O'Connor0a924122009-02-08 19:43:47 -0500413void call_bcv(u16 seg, u16 ip);
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500414void optionrom_setup(void);
415void vga_setup(void);
416void s3_resume_vga_init(void);
Kevin O'Connore7739302009-07-26 19:16:09 -0400417extern u32 RomEnd;
Kevin O'Connor714325c2008-11-01 20:32:27 -0400418
Kevin O'Connorafbed1b2010-06-28 07:34:53 -0400419// bootsplash.c
420void enable_vga_console(void);
Kevin O'Connor9a01a9c2010-08-25 21:07:48 -0400421void enable_bootsplash(void);
Kevin O'Connorafbed1b2010-06-28 07:34:53 -0400422void disable_bootsplash(void);
423
Kevin O'Connor18e38b22008-12-10 20:40:13 -0500424// resume.c
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500425void init_dma(void);
Kevin O'Connor18e38b22008-12-10 20:40:13 -0500426
Kevin O'Connor0c3068d2008-12-21 17:51:36 -0500427// pnpbios.c
428#define PNP_SIGNATURE 0x506e5024 // $PnP
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500429u16 get_pnp_offset(void);
430void pnp_setup(void);
Kevin O'Connor0c3068d2008-12-21 17:51:36 -0500431
Kevin O'Connore54ee382009-07-26 19:33:13 -0400432// pmm.c
Kevin O'Connor415d4292009-08-30 19:19:31 -0400433extern struct zone_s ZoneLow, ZoneHigh, ZoneFSeg, ZoneTmpLow, ZoneTmpHigh;
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500434void malloc_setup(void);
435void malloc_finalize(void);
Kevin O'Connord948e2b2009-10-12 12:54:56 -0400436void *pmm_malloc(struct zone_s *zone, u32 handle, u32 size, u32 align);
437int pmm_free(void *data);
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500438void pmm_setup(void);
439void pmm_finalize(void);
Kevin O'Connord948e2b2009-10-12 12:54:56 -0400440#define PMM_DEFAULT_HANDLE 0xFFFFFFFF
Kevin O'Connor0bf92702009-08-01 11:45:37 -0400441// Minimum alignment of malloc'd memory
442#define MALLOC_MIN_ALIGN 16
Kevin O'Connor415d4292009-08-30 19:19:31 -0400443// Helper functions for memory allocation.
Kevin O'Connorf416fe92009-09-24 20:51:55 -0400444static inline void *malloc_low(u32 size) {
Kevin O'Connord948e2b2009-10-12 12:54:56 -0400445 return pmm_malloc(&ZoneLow, PMM_DEFAULT_HANDLE, size, MALLOC_MIN_ALIGN);
Kevin O'Connorf416fe92009-09-24 20:51:55 -0400446}
Kevin O'Connor415d4292009-08-30 19:19:31 -0400447static inline void *malloc_high(u32 size) {
Kevin O'Connord948e2b2009-10-12 12:54:56 -0400448 return pmm_malloc(&ZoneHigh, PMM_DEFAULT_HANDLE, size, MALLOC_MIN_ALIGN);
Kevin O'Connor415d4292009-08-30 19:19:31 -0400449}
450static inline void *malloc_fseg(u32 size) {
Kevin O'Connord948e2b2009-10-12 12:54:56 -0400451 return pmm_malloc(&ZoneFSeg, PMM_DEFAULT_HANDLE, size, MALLOC_MIN_ALIGN);
Kevin O'Connor415d4292009-08-30 19:19:31 -0400452}
Kevin O'Connora576c9c2010-07-26 22:43:18 -0400453static inline void *malloc_tmplow(u32 size) {
454 return pmm_malloc(&ZoneTmpLow, PMM_DEFAULT_HANDLE, size, MALLOC_MIN_ALIGN);
455}
Kevin O'Connor114592f2009-09-28 21:32:08 -0400456static inline void *malloc_tmphigh(u32 size) {
Kevin O'Connord948e2b2009-10-12 12:54:56 -0400457 return pmm_malloc(&ZoneTmpHigh, PMM_DEFAULT_HANDLE, size, MALLOC_MIN_ALIGN);
Kevin O'Connor114592f2009-09-28 21:32:08 -0400458}
Kevin O'Connor575ffc82010-02-21 23:20:10 -0500459static inline void *malloc_tmp(u32 size) {
460 void *ret = malloc_tmphigh(size);
461 if (ret)
462 return ret;
Kevin O'Connora576c9c2010-07-26 22:43:18 -0400463 return malloc_tmplow(size);
Kevin O'Connor575ffc82010-02-21 23:20:10 -0500464}
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400465static inline void *memalign_low(u32 align, u32 size) {
Kevin O'Connord948e2b2009-10-12 12:54:56 -0400466 return pmm_malloc(&ZoneLow, PMM_DEFAULT_HANDLE, size, align);
Kevin O'Connor415d4292009-08-30 19:19:31 -0400467}
468static inline void *memalign_high(u32 align, u32 size) {
Kevin O'Connord948e2b2009-10-12 12:54:56 -0400469 return pmm_malloc(&ZoneHigh, PMM_DEFAULT_HANDLE, size, align);
Kevin O'Connor415d4292009-08-30 19:19:31 -0400470}
Kevin O'Connor12fa24a2010-09-15 00:25:32 -0400471static inline void *memalign_tmplow(u32 align, u32 size) {
472 return pmm_malloc(&ZoneTmpLow, PMM_DEFAULT_HANDLE, size, align);
473}
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400474static inline void *memalign_tmphigh(u32 align, u32 size) {
Kevin O'Connord948e2b2009-10-12 12:54:56 -0400475 return pmm_malloc(&ZoneTmpHigh, PMM_DEFAULT_HANDLE, size, align);
476}
Kevin O'Connor12fa24a2010-09-15 00:25:32 -0400477static inline void *memalign_tmp(u32 align, u32 size) {
478 void *ret = memalign_tmphigh(align, size);
479 if (ret)
480 return ret;
481 return memalign_tmplow(align, size);
482}
Kevin O'Connord948e2b2009-10-12 12:54:56 -0400483static inline void free(void *data) {
484 pmm_free(data);
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400485}
Kevin O'Connore54ee382009-07-26 19:33:13 -0400486
Kevin O'Connor7061eb62009-01-04 21:48:22 -0500487// mtrr.c
488void mtrr_setup(void);
489
Kevin O'Connor18e38b22008-12-10 20:40:13 -0500490// romlayout.S
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500491void reset_vector(void) __noreturn;
Kevin O'Connor18e38b22008-12-10 20:40:13 -0500492
Kevin O'Connor30853762009-01-17 18:49:20 -0500493// misc.c
494extern u8 BiosChecksum;
495
Kevin O'Connorc95d2ce2009-07-29 20:41:39 -0400496// version (auto generated file out/version.c)
497extern const char VERSION[];
498
Kevin O'Connor786502d2008-02-27 10:41:41 -0500499#endif // util.h