libpayload: The initial chunk of code writen by AMD
[coreboot.git] / payloads / libpayload / include / libpayload.h
1 /*
2  * This file is part of the libpayload project.
3  *
4  * Copyright (C) 2008 Advanced Micro Devices, Inc.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. The name of the author may not be used to endorse or promote products
15  *    derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29
30 #ifndef LIBPAYLOAD_H_
31 #define LIBPAYLOAD_H_
32
33 #include <autoconf.h>
34 #include <stddef.h>
35 #include <arch/types.h>
36 #include <arch/io.h>
37 #include <stdarg.h>
38
39 #define MIN(a,b) ((a) < (b) ? (a) : (b))
40 #define MAX(a,b) ((a) > (b) ? (a) : (b))
41 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
42
43 /* serial.c */
44 void serial_putchar(unsigned char c);
45
46 /* console.c */
47 int putchar(int c);
48 extern int last_putchar;
49
50 #define havechar havekey
51
52 /* ctype.c */
53 int isspace(int c);
54 int isdigit(int c);
55 int tolower(int c);
56
57 /* malloc.c */
58 void *malloc(size_t size);
59 void free(void *ptr);
60 void *calloc(size_t nmemb, size_t size);
61 void *realloc(void *ptr, size_t size);
62
63 /* memory.c */
64 int memcmp(const char *s1, const char *s2, size_t len);
65 void *memcpy(void *dst, const void *src, size_t n);
66 void *memset(void *s, int c, size_t n);
67 void *memmove(void *dst, const void *src, size_t n);
68
69 /* printf.c */
70 int sprintf(char *str, const char *fmt, ...);
71 int vsnprintf(char *str, size_t size, const char *fmt, va_list ap);
72 int vsprintf(char *str, const char *fmt, va_list ap);
73 int printf(const char *fmt, ...);
74 int vprintf(const char *fmt, va_list ap);
75
76 /* string.c */
77 size_t strnlen(const char *src, size_t max);
78 size_t strlen(const char *src);
79 int strcmp(const char *s1, const char *s2);
80 char *strdup(const char *s);
81 char *strchr(const char *s, int c);
82 char *strncpy(char *to, const char *from, int count);
83 char * strcpy (char *dest, const char *src);
84 char * strstr (const char *s1, const char *s2);
85
86 /* ipchchecksum.c */
87 unsigned short ipchksum(const unsigned short *ptr, unsigned long nbytes);
88
89 /* util.S */
90 #define abort() halt()
91 void halt(void) __attribute__ ((noreturn));
92
93 /* Timer functions - defined by each arcitecture */
94
95 void ndelay(unsigned int);
96 void mdelay(unsigned int);
97 void delay(unsigned int);
98
99 #endif