blob: a1a10f4e867e1443adb1701ec2324f5a56fd77d9 [file] [log] [blame]
Kevin O'Connorfa9c66a2013-09-14 19:10:40 -04001// Misc function and variable declarations.
Kevin O'Connor786502d2008-02-27 10:41:41 -05002#ifndef __UTIL_H
3#define __UTIL_H
Kevin O'Connorf076a3e2008-02-25 22:25:15 -05004
Kevin O'Connor9521e262008-07-04 13:04:29 -04005#include "types.h" // u32
Kevin O'Connorf076a3e2008-02-25 22:25:15 -05006
Kevin O'Connorf076a3e2008-02-25 22:25:15 -05007// output.c
Ian Campbell54f3b252012-06-28 11:08:32 +01008extern u16 DebugOutputPort;
Kevin O'Connord83c87b2013-01-21 01:14:12 -05009void debug_serial_preinit(void);
Kevin O'Connore07e18e2009-02-08 17:07:29 -050010void panic(const char *fmt, ...)
Kevin O'Connordad41d92010-01-01 03:04:19 -050011 __attribute__ ((format (printf, 1, 2))) __noreturn;
Kevin O'Connor567e4e32008-04-05 11:37:51 -040012void printf(const char *fmt, ...)
13 __attribute__ ((format (printf, 1, 2)));
Kevin O'Connor2be312c2009-11-24 09:37:53 -050014int snprintf(char *str, size_t size, const char *fmt, ...)
Kevin O'Connor9ed6b622009-10-07 21:41:08 -040015 __attribute__ ((format (printf, 3, 4)));
Kevin O'Connorca2bc1c2010-12-29 21:41:19 -050016char * znprintf(size_t size, const char *fmt, ...)
17 __attribute__ ((format (printf, 2, 3)));
Kevin O'Connorcfdc13f2010-02-14 13:07:54 -050018void __dprintf(const char *fmt, ...)
19 __attribute__ ((format (printf, 1, 2)));
Kevin O'Connor3df600b2013-09-14 19:28:55 -040020struct bregs;
Kevin O'Connorcfdc13f2010-02-14 13:07:54 -050021void __debug_enter(struct bregs *regs, const char *fname);
Kevin O'Connor1297e5d2012-06-02 20:30:58 -040022void __debug_isr(const char *fname);
Kevin O'Connorcfdc13f2010-02-14 13:07:54 -050023void __debug_stub(struct bregs *regs, int lineno, const char *fname);
24void __warn_invalid(struct bregs *regs, int lineno, const char *fname);
25void __warn_unimplemented(struct bregs *regs, int lineno, const char *fname);
Kevin O'Connor7fb8ba82010-02-26 08:45:00 -050026void __warn_internalerror(int lineno, const char *fname);
Kevin O'Connorcfdc13f2010-02-14 13:07:54 -050027void __warn_noalloc(int lineno, const char *fname);
28void __warn_timeout(int lineno, const char *fname);
29void __set_invalid(struct bregs *regs, int lineno, const char *fname);
30void __set_unimplemented(struct bregs *regs, int lineno, const char *fname);
31void __set_code_invalid(struct bregs *regs, u32 linecode, const char *fname);
32void __set_code_unimplemented(struct bregs *regs, u32 linecode
33 , const char *fname);
34void hexdump(const void *d, int len);
35
Kevin O'Connorac8df8c2008-05-24 23:46:33 -040036#define dprintf(lvl, fmt, args...) do { \
37 if (CONFIG_DEBUG_LEVEL && (lvl) <= CONFIG_DEBUG_LEVEL) \
38 __dprintf((fmt) , ##args ); \
39 } while (0)
Kevin O'Connor15c1f222008-06-12 22:59:43 -040040#define debug_enter(regs, lvl) do { \
41 if ((lvl) && (lvl) <= CONFIG_DEBUG_LEVEL) \
Kevin O'Connor05600342009-01-02 13:10:58 -050042 __debug_enter((regs), __func__); \
Kevin O'Connor15c1f222008-06-12 22:59:43 -040043 } while (0)
Kevin O'Connor1297e5d2012-06-02 20:30:58 -040044#define debug_isr(lvl) do { \
45 if ((lvl) && (lvl) <= CONFIG_DEBUG_LEVEL) \
46 __debug_isr(__func__); \
47 } while (0)
Kevin O'Connor05600342009-01-02 13:10:58 -050048#define debug_stub(regs) \
49 __debug_stub((regs), __LINE__, __func__)
Kevin O'Connorcfdc13f2010-02-14 13:07:54 -050050#define warn_invalid(regs) \
51 __warn_invalid((regs), __LINE__, __func__)
52#define warn_unimplemented(regs) \
53 __warn_unimplemented((regs), __LINE__, __func__)
Kevin O'Connor7fb8ba82010-02-26 08:45:00 -050054#define warn_internalerror() \
55 __warn_internalerror(__LINE__, __func__)
Kevin O'Connorcfdc13f2010-02-14 13:07:54 -050056#define warn_noalloc() \
57 __warn_noalloc(__LINE__, __func__)
58#define warn_timeout() \
59 __warn_timeout(__LINE__, __func__)
60#define set_invalid(regs) \
61 __set_invalid((regs), __LINE__, __func__)
62#define set_code_invalid(regs, code) \
63 __set_code_invalid((regs), (code) | (__LINE__ << 8), __func__)
64#define set_unimplemented(regs) \
65 __set_unimplemented((regs), __LINE__, __func__)
66#define set_code_unimplemented(regs, code) \
67 __set_code_unimplemented((regs), (code) | (__LINE__ << 8), __func__)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050068
69// kbd.c
Kevin O'Connord83c87b2013-01-21 01:14:12 -050070void kbd_init(void);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050071void handle_15c2(struct bregs *regs);
Kevin O'Connor114592f2009-09-28 21:32:08 -040072void process_key(u8 key);
Kevin O'Connorbdce35f2008-02-26 21:33:14 -050073
Kevin O'Connorf54c1502008-06-14 15:56:16 -040074// mouse.c
Kevin O'Connord83c87b2013-01-21 01:14:12 -050075void mouse_init(void);
Kevin O'Connor57877482009-12-09 21:00:41 -050076void process_mouse(u8 data);
Kevin O'Connorf54c1502008-06-14 15:56:16 -040077
Kevin O'Connor913cc2e2008-04-13 17:31:45 -040078// serial.c
Kevin O'Connor1ca05b02010-01-03 17:43:37 -050079void serial_setup(void);
80void lpt_setup(void);
Kevin O'Connor913cc2e2008-04-13 17:31:45 -040081
Kevin O'Connorbdce35f2008-02-26 21:33:14 -050082// clock.c
Kevin O'Connorc6e8c072013-07-20 10:51:58 -040083void clock_setup(void);
84void handle_1583(struct bregs *regs);
85void handle_1586(struct bregs *regs);
86void useRTC(void);
87void releaseRTC(void);
88
Kevin O'Connor5d369d82013-09-02 20:48:46 -040089// hw/timer.c
Kevin O'Connor1ca05b02010-01-03 17:43:37 -050090void timer_setup(void);
Kevin O'Connor018bdd72013-07-20 18:22:57 -040091void pmtimer_setup(u16 ioport);
92u32 timer_calc(u32 msecs);
93u32 timer_calc_usec(u32 usecs);
94int timer_check(u32 end);
Kevin O'Connorbc2aecd2008-11-28 16:40:06 -050095void ndelay(u32 count);
96void udelay(u32 count);
97void mdelay(u32 count);
Kevin O'Connor10ad7992009-10-24 11:06:08 -040098void nsleep(u32 count);
99void usleep(u32 count);
100void msleep(u32 count);
Kevin O'Connor018bdd72013-07-20 18:22:57 -0400101u32 ticks_to_ms(u32 ticks);
102u32 ticks_from_ms(u32 ms);
Kevin O'Connor95ee3822013-07-20 18:07:50 -0400103u32 irqtimer_calc_ticks(u32 count);
104u32 irqtimer_calc(u32 msecs);
105int irqtimer_check(u32 end);
Kevin O'Connorbdce35f2008-02-26 21:33:14 -0500106
Kevin O'Connor95b2f782008-03-05 19:52:06 -0500107// apm.c
Kevin O'Connor244caf82010-09-15 21:48:16 -0400108void apm_shutdown(void);
Kevin O'Connorc0031482010-01-01 13:03:17 -0500109void handle_1553(struct bregs *regs);
Kevin O'Connor95b2f782008-03-05 19:52:06 -0500110
Kevin O'Connora0dc2962008-03-16 14:29:32 -0400111// pcibios.c
112void handle_1ab1(struct bregs *regs);
Kevin O'Connord83c87b2013-01-21 01:14:12 -0500113void bios32_init(void);
Kevin O'Connora0dc2962008-03-16 14:29:32 -0400114
Kevin O'Connorccee6e82013-09-02 21:25:21 -0400115// fw/shadow.c
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500116void make_bios_writable(void);
117void make_bios_readonly(void);
Kevin O'Connor244caf82010-09-15 21:48:16 -0400118void qemu_prep_reset(void);
Kevin O'Connorda4a6482008-06-08 13:48:06 -0400119
Kevin O'Connorccee6e82013-09-02 21:25:21 -0400120// fw/pciinit.c
Kevin O'Connor0d6b8d52010-07-10 13:12:37 -0400121extern const u8 pci_irqs[4];
Kevin O'Connor40f5b5a2009-09-13 10:46:57 -0400122void pci_setup(void);
Kevin O'Connora4d35762008-03-08 15:43:03 -0500123
Kevin O'Connorccee6e82013-09-02 21:25:21 -0400124// fw/smm.c
Kevin O'Connorcdbac7f2013-03-08 19:33:39 -0500125void smm_device_setup(void);
Kevin O'Connord83c87b2013-01-21 01:14:12 -0500126void smm_setup(void);
Kevin O'Connorf7ba6d72008-07-04 05:05:54 -0400127
Kevin O'Connorccee6e82013-09-02 21:25:21 -0400128// fw/smp.c
Kevin O'Connor603bfc32009-06-22 20:04:56 -0400129extern u32 CountCPUs;
Kevin O'Connor84705852009-10-08 22:13:15 -0400130extern u32 MaxCountCPUs;
Kevin O'Connore97ca7b2009-06-21 09:10:28 -0400131void wrmsr_smp(u32 index, u64 val);
Kevin O'Connord83c87b2013-01-21 01:14:12 -0500132void smp_setup(void);
Eduardo Habkost008c1fc2012-07-25 15:45:30 -0300133int apic_id_is_present(u8 apic_id);
Kevin O'Connor84ad59a2008-07-04 05:47:26 -0400134
Kevin O'Connorccee6e82013-09-02 21:25:21 -0400135// fw/coreboot.c
Kevin O'Connorc1de91b2011-07-02 13:50:21 -0400136extern const char *CBvendor, *CBpart;
Kevin O'Connor1edc89d2009-04-30 21:50:35 -0400137struct cbfs_file;
Gerd Hoffmannebf03f72013-06-24 11:24:57 +0200138void debug_cbmem(char c);
Kevin O'Connor1f836252009-08-16 20:17:35 -0400139void cbfs_run_payload(struct cbfs_file *file);
Kevin O'Connora2a86e22013-02-13 19:35:12 -0500140void coreboot_platform_setup(void);
Kevin O'Connor89a1efd2011-01-08 12:24:39 -0500141void cbfs_payload_setup(void);
Kevin O'Connord83c87b2013-01-21 01:14:12 -0500142void coreboot_preinit(void);
143void coreboot_cbfs_init(void);
Kevin O'Connorc7812932008-06-08 23:08:12 -0400144
Kevin O'Connorccee6e82013-09-02 21:25:21 -0400145// fw/biostable.c
David Woodhouse38b24db2013-01-25 19:33:58 -0600146void copy_smbios(void *pos);
Kevin O'Connor4d053eb2012-06-09 13:08:02 -0400147void copy_table(void *pos);
Ian Campbell1442c312011-06-01 11:00:28 +0100148
Kevin O'Connorcbffa8e2008-08-17 11:11:07 -0400149// vgahooks.c
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500150void handle_155f(struct bregs *regs);
Kevin O'Connorc1de91b2011-07-02 13:50:21 -0400151struct pci_device;
152void vgahook_setup(struct pci_device *pci);
Kevin O'Connorcbffa8e2008-08-17 11:11:07 -0400153
Kevin O'Connor714325c2008-11-01 20:32:27 -0400154// optionroms.c
Kevin O'Connor0a924122009-02-08 19:43:47 -0500155void call_bcv(u16 seg, u16 ip);
Alex Williamson7adfd712013-03-20 10:58:47 -0600156int is_pci_vga(struct pci_device *pci);
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500157void optionrom_setup(void);
Kevin O'Connord83c87b2013-01-21 01:14:12 -0500158void vgarom_setup(void);
159void s3_resume_vga(void);
Kevin O'Connor422263d2011-07-05 20:56:07 -0400160extern int ScreenAndDebug;
Kevin O'Connor714325c2008-11-01 20:32:27 -0400161
Kevin O'Connorafbed1b2010-06-28 07:34:53 -0400162// bootsplash.c
163void enable_vga_console(void);
Kevin O'Connor9a01a9c2010-08-25 21:07:48 -0400164void enable_bootsplash(void);
Kevin O'Connorafbed1b2010-06-28 07:34:53 -0400165void disable_bootsplash(void);
166
Kevin O'Connor18e38b22008-12-10 20:40:13 -0500167// resume.c
Kevin O'Connor87b533b2011-07-10 22:35:07 -0400168extern int HaveRunPost;
Kevin O'Connor9e4d41c2013-01-21 12:14:29 -0500169void dma_setup(void);
Kevin O'Connor18e38b22008-12-10 20:40:13 -0500170
Kevin O'Connor0c3068d2008-12-21 17:51:36 -0500171// pnpbios.c
172#define PNP_SIGNATURE 0x506e5024 // $PnP
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500173u16 get_pnp_offset(void);
Kevin O'Connord83c87b2013-01-21 01:14:12 -0500174void pnp_init(void);
Kevin O'Connor0c3068d2008-12-21 17:51:36 -0500175
Kevin O'Connore54ee382009-07-26 19:33:13 -0400176// pmm.c
Kevin O'Connor415d4292009-08-30 19:19:31 -0400177extern struct zone_s ZoneLow, ZoneHigh, ZoneFSeg, ZoneTmpLow, ZoneTmpHigh;
Kevin O'Connor3733f6f2013-02-17 12:44:23 -0500178u32 rom_get_max(void);
Kevin O'Connor5e019082012-05-20 21:11:43 -0400179u32 rom_get_last(void);
180struct rom_header *rom_reserve(u32 size);
181int rom_confirm(u32 size);
David Woodhouse118469a2013-01-25 19:46:25 -0600182void csm_malloc_preinit(u32 low_pmm, u32 low_pmm_size, u32 hi_pmm,
183 u32 hi_pmm_size);
Kevin O'Connord83c87b2013-01-21 01:14:12 -0500184void malloc_preinit(void);
Kevin O'Connorf85e4bc2013-02-19 01:33:45 -0500185extern u32 LegacyRamSize;
Kevin O'Connor6afc6f82013-02-19 01:02:50 -0500186void malloc_init(void);
Kevin O'Connord83c87b2013-01-21 01:14:12 -0500187void malloc_prepboot(void);
Kevin O'Connord948e2b2009-10-12 12:54:56 -0400188void *pmm_malloc(struct zone_s *zone, u32 handle, u32 size, u32 align);
189int pmm_free(void *data);
Kevin O'Connord83c87b2013-01-21 01:14:12 -0500190void pmm_init(void);
191void pmm_prepboot(void);
Kevin O'Connord948e2b2009-10-12 12:54:56 -0400192#define PMM_DEFAULT_HANDLE 0xFFFFFFFF
Kevin O'Connor0bf92702009-08-01 11:45:37 -0400193// Minimum alignment of malloc'd memory
194#define MALLOC_MIN_ALIGN 16
Kevin O'Connor415d4292009-08-30 19:19:31 -0400195// Helper functions for memory allocation.
Kevin O'Connorf416fe92009-09-24 20:51:55 -0400196static inline void *malloc_low(u32 size) {
Kevin O'Connord948e2b2009-10-12 12:54:56 -0400197 return pmm_malloc(&ZoneLow, PMM_DEFAULT_HANDLE, size, MALLOC_MIN_ALIGN);
Kevin O'Connorf416fe92009-09-24 20:51:55 -0400198}
Kevin O'Connor415d4292009-08-30 19:19:31 -0400199static inline void *malloc_high(u32 size) {
Kevin O'Connord948e2b2009-10-12 12:54:56 -0400200 return pmm_malloc(&ZoneHigh, PMM_DEFAULT_HANDLE, size, MALLOC_MIN_ALIGN);
Kevin O'Connor415d4292009-08-30 19:19:31 -0400201}
202static inline void *malloc_fseg(u32 size) {
Kevin O'Connord948e2b2009-10-12 12:54:56 -0400203 return pmm_malloc(&ZoneFSeg, PMM_DEFAULT_HANDLE, size, MALLOC_MIN_ALIGN);
Kevin O'Connor415d4292009-08-30 19:19:31 -0400204}
Kevin O'Connora576c9c2010-07-26 22:43:18 -0400205static inline void *malloc_tmplow(u32 size) {
206 return pmm_malloc(&ZoneTmpLow, PMM_DEFAULT_HANDLE, size, MALLOC_MIN_ALIGN);
207}
Kevin O'Connor114592f2009-09-28 21:32:08 -0400208static inline void *malloc_tmphigh(u32 size) {
Kevin O'Connord948e2b2009-10-12 12:54:56 -0400209 return pmm_malloc(&ZoneTmpHigh, PMM_DEFAULT_HANDLE, size, MALLOC_MIN_ALIGN);
Kevin O'Connor114592f2009-09-28 21:32:08 -0400210}
Kevin O'Connor575ffc82010-02-21 23:20:10 -0500211static inline void *malloc_tmp(u32 size) {
212 void *ret = malloc_tmphigh(size);
213 if (ret)
214 return ret;
Kevin O'Connora576c9c2010-07-26 22:43:18 -0400215 return malloc_tmplow(size);
Kevin O'Connor575ffc82010-02-21 23:20:10 -0500216}
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400217static inline void *memalign_low(u32 align, u32 size) {
Kevin O'Connord948e2b2009-10-12 12:54:56 -0400218 return pmm_malloc(&ZoneLow, PMM_DEFAULT_HANDLE, size, align);
Kevin O'Connor415d4292009-08-30 19:19:31 -0400219}
220static inline void *memalign_high(u32 align, u32 size) {
Kevin O'Connord948e2b2009-10-12 12:54:56 -0400221 return pmm_malloc(&ZoneHigh, PMM_DEFAULT_HANDLE, size, align);
Kevin O'Connor415d4292009-08-30 19:19:31 -0400222}
Kevin O'Connor12fa24a2010-09-15 00:25:32 -0400223static inline void *memalign_tmplow(u32 align, u32 size) {
224 return pmm_malloc(&ZoneTmpLow, PMM_DEFAULT_HANDLE, size, align);
225}
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400226static inline void *memalign_tmphigh(u32 align, u32 size) {
Kevin O'Connord948e2b2009-10-12 12:54:56 -0400227 return pmm_malloc(&ZoneTmpHigh, PMM_DEFAULT_HANDLE, size, align);
228}
Kevin O'Connor12fa24a2010-09-15 00:25:32 -0400229static inline void *memalign_tmp(u32 align, u32 size) {
230 void *ret = memalign_tmphigh(align, size);
231 if (ret)
232 return ret;
233 return memalign_tmplow(align, size);
234}
Kevin O'Connord948e2b2009-10-12 12:54:56 -0400235static inline void free(void *data) {
236 pmm_free(data);
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400237}
Kevin O'Connore54ee382009-07-26 19:33:13 -0400238
Kevin O'Connorccee6e82013-09-02 21:25:21 -0400239// fw/mtrr.c
Kevin O'Connor7061eb62009-01-04 21:48:22 -0500240void mtrr_setup(void);
241
Kevin O'Connor18e38b22008-12-10 20:40:13 -0500242// romlayout.S
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500243void reset_vector(void) __noreturn;
Kevin O'Connor18e38b22008-12-10 20:40:13 -0500244
Kevin O'Connor30853762009-01-17 18:49:20 -0500245// misc.c
Kevin O'Connor3a735ba2013-02-10 00:35:01 -0500246void mathcp_setup(void);
Kevin O'Connor30853762009-01-17 18:49:20 -0500247extern u8 BiosChecksum;
248
Kevin O'Connorc95d2ce2009-07-29 20:41:39 -0400249// version (auto generated file out/version.c)
250extern const char VERSION[];
251
Kevin O'Connor786502d2008-02-27 10:41:41 -0500252#endif // util.h