M7350v1_en_gpl

This commit is contained in:
T
2024-09-09 08:52:07 +00:00
commit f9cc65cfda
65988 changed files with 26357421 additions and 0 deletions

View File

@ -0,0 +1,49 @@
/*
* Copyright (c) 2009 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __APP_H
#define __APP_H
/* app support api */
void apps_init(void); /* one time setup */
/* app entry point */
struct app_descriptor;
typedef void (*app_init)(const struct app_descriptor *);
typedef void (*app_entry)(const struct app_descriptor *, void *args);
/* app startup flags */
#define APP_FLAG_DONT_START_ON_BOOT 0x1
/* each app needs to define one of these to define its startup conditions */
struct app_descriptor {
const char *name;
app_init init;
app_entry entry;
unsigned int flags;
};
#define APP_START(appname) struct app_descriptor _app_##appname __SECTION(".apps") = { .name = #appname,
#define APP_END };
#endif

View File

@ -0,0 +1,37 @@
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __ARCH_H
#define __ARCH_H
#if defined(__cplusplus)
extern "C" {
#endif
void arch_early_init(void);
void arch_init(void);
#if defined(__cplusplus)
}
#endif
#endif

View File

@ -0,0 +1,75 @@
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __ARCH_OPS_H
#define __ARCH_OPS_H
#ifndef ASSEMBLY
#include <sys/types.h>
#include <compiler.h>
#if defined(__cplusplus)
extern "C" {
#endif
void arch_enable_ints(void);
void arch_disable_ints(void);
int atomic_swap(volatile int *ptr, int val);
int atomic_add(volatile int *ptr, int val);
int atomic_and(volatile int *ptr, int val);
int atomic_or(volatile int *ptr, int val);
#endif // !ASSEMBLY
#define ICACHE 1
#define DCACHE 2
#define UCACHE (ICACHE|DCACHE)
#ifndef ASSEMBLY
void arch_disable_cache(uint flags);
void arch_enable_cache(uint flags);
void arch_clean_cache_range(addr_t start, size_t len);
void arch_clean_invalidate_cache_range(addr_t start, size_t len);
void arch_invalidate_cache_range(addr_t start, size_t len);
void arch_sync_cache_range(addr_t start, size_t len);
void arch_idle(void);
void arch_disable_mmu(void);
void arch_switch_stacks_and_call(addr_t call, addr_t stack) __NO_RETURN;
uint32_t arch_cycle_count(void);
#if defined(__cplusplus)
}
#endif
#endif // !ASSEMBLY
#if ARCH_ARM
#include <arch/arm/ops.h>
#endif
#endif

View File

@ -0,0 +1,34 @@
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __ARCH_THREAD_H
#define __ARCH_THREAD_H
// give the arch code a chance to declare the arch_thread struct
#include <arch/arch_thread.h>
struct thread;
void arch_thread_initialize(struct thread *);
void arch_context_switch(struct thread *oldthread, struct thread *newthread);
#endif

View File

@ -0,0 +1,30 @@
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __ASM_H
#define __ASM_H
//#define FUNCTION(x) .global x; .type x,@function; x:
#define FUNCTION(x) .global x; x:
#endif

View File

@ -0,0 +1,41 @@
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __ASSERT_H
#define __ASSERT_H
#include <compiler.h>
#include <debug.h>
#define ASSERT(x) \
do { if (unlikely(!(x))) { panic("ASSERT FAILED at (%s:%d): %s\n", __FILE__, __LINE__, #x); } } while (0)
#define assert(x) ASSERT(x)
#if DEBUGLEVEL > 1
#define DEBUG_ASSERT(x) \
do { if (unlikely(!(x))) { panic("DEBUG ASSERT FAILED at (%s:%d): %s\n", __FILE__, __LINE__, #x); } } while (0)
#else
#define DEBUG_ASSERT(x) \
do { } while(0)
#endif
#endif

View File

@ -0,0 +1,60 @@
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __BITS_H
#define __BITS_H
#include <arch/ops.h>
#define clz(x) __builtin_clz(x)
#define BIT(bit) (1 << (bit))
#define BIT_GET(x, bit) ((x) & (1 << (bit)))
#define BIT_SHIFT(x, bit) (((x) >> (bit)) & 1)
#define BITS(x, high, low) ((x) & (((1<<((high)+1))-1) & ~((1<<(low))-1)))
#define BITS_SHIFT(x, high, low) (((x) >> (low)) & ((1<<((high)-(low)+1))-1))
#define BIT_SET(x, bit) (((x) & (1 << (bit))) ? 1 : 0)
#define BITMAP_BITS_PER_WORD (sizeof(unsigned long) * 8)
#define BITMAP_NUM_WORDS(x) (((x) / BITMAP_BITS_PER_WORD) + 1)
#define BITMAP_WORD(x) ((x) / BITMAP_BITS_PER_WORD)
#define BITMAP_BIT_IN_WORD(x) ((x) & (BITMAP_BITS_PER_WORD - 1))
static inline int bitmap_set(unsigned long *bitmap, int bit)
{
unsigned long mask = 1 << BITMAP_BIT_IN_WORD(bit);
return atomic_or((int*)&bitmap[BITMAP_WORD(bit)], mask) & mask ? 1 : 0;
}
static inline int bitmap_clear(unsigned long *bitmap, int bit)
{
unsigned long mask = 1 << BITMAP_BIT_IN_WORD(bit);
return atomic_and((int*)&bitmap[BITMAP_WORD(bit)], ~mask) & mask ? 1:0;
}
static inline int bitmap_test(unsigned long *bitmap, int bit)
{
return BIT_SET(bitmap[BITMAP_WORD(bit)], BITMAP_BIT_IN_WORD(bit));
}
#endif

View File

@ -0,0 +1,48 @@
/* Copyright (c) 2013, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Fundation, Inc. nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __BOOT_STATS_H
#define __BOOT_STATS_H
/* The order of the entries in this enum does not correspond to bootup order.
* It is mandated by the expected order of the entries in imem when the values
* are read in the kernel.
*/
enum bs_entry {
BS_BL_START = 0,
BS_KERNEL_ENTRY,
BS_SPLASH_SCREEN_DISPLAY,
BS_KERNEL_LOAD_TIME,
BS_KERNEL_LOAD_START,
BS_KERNEL_LOAD_DONE,
BS_MAX,
};
void bs_set_timestamp(enum bs_entry bs_id);
#endif

View File

@ -0,0 +1,125 @@
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __COMPILER_H
#define __COMPILER_H
#ifndef __ASSEMBLY__
#if __GNUC__
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#define __UNUSED __attribute__((__unused__))
#define __PACKED __attribute__((packed))
#define __ALIGNED(x) __attribute__((aligned(x)))
#define __PRINTFLIKE(__fmt,__varargs) __attribute__((__format__ (__printf__, __fmt, __varargs)))
#define __SCANFLIKE(__fmt,__varargs) __attribute__((__format__ (__scanf__, __fmt, __varargs)))
#define __SECTION(x) __attribute((section(x)))
#define __PURE __attribute((pure))
#define __CONST __attribute((const))
#define __NO_RETURN __attribute__((noreturn))
#define __MALLOC __attribute__((malloc))
#define __WEAK __attribute__((weak))
#define __GNU_INLINE __attribute__((gnu_inline))
#define __GET_CALLER(x) __builtin_return_address(0)
#define __GET_FRAME(x) __builtin_frame_address(0)
#define INCBIN(symname, sizename, filename, section) \
__asm__ (".section " section "; .align 4; .globl "#symname); \
__asm__ (""#symname ":\n.incbin \"" filename "\""); \
__asm__ (".section " section "; .align 1;"); \
__asm__ (""#symname "_end:"); \
__asm__ (".section " section "; .align 4; .globl "#sizename); \
__asm__ (""#sizename ": .long "#symname "_end - "#symname " - 1"); \
extern unsigned char symname[]; \
extern unsigned int sizename
#define INCFILE(symname, sizename, filename) INCBIN(symname, sizename, filename, ".rodata")
/* look for gcc 3.0 and above */
#if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 0)
#define __ALWAYS_INLINE __attribute__((always_inline))
#else
#define __ALWAYS_INLINE
#endif
/* look for gcc 3.1 and above */
#if !defined(__DEPRECATED) // seems to be built in in some versions of the compiler
#if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
#define __DEPRECATED __attribute((deprecated))
#else
#define __DEPRECATED
#endif
#endif
/* look for gcc 3.3 and above */
#if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
/* the may_alias attribute was introduced in gcc 3.3; before that, there
* was no way to specify aliasiang rules on a type-by-type basis */
#define __MAY_ALIAS __attribute__((may_alias))
/* nonnull was added in gcc 3.3 as well */
#define __NONNULL(x) __attribute((nonnull x))
#else
#define __MAY_ALIAS
#define __NONNULL(x)
#endif
/* look for gcc 3.4 and above */
#if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
#define __WARN_UNUSED_RESULT __attribute((warn_unused_result))
#else
#define __WARN_UNUSED_RESULT
#endif
#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)
#define __EXTERNALLY_VISIBLE __attribute__((externally_visible))
#else
#define __EXTERNALLY_VISIBLE
#endif
#else
#define likely(x) (x)
#define unlikely(x) (x)
#define __UNUSED
#define __PACKED
#define __ALIGNED(x)
#define __PRINTFLIKE(__fmt,__varargs)
#define __SCANFLIKE(__fmt,__varargs)
#define __SECTION(x)
#define __PURE
#define __CONST
#define __NONNULL(x)
#define __DEPRECATED
#define __WARN_UNUSED_RESULT
#define __ALWAYS_INLINE
#define __MAY_ALIAS
#define __NO_RETURN
#endif
#endif
/* TODO: add type check */
#define countof(a) (sizeof(a) / sizeof((a)[0]))
#endif

View File

@ -0,0 +1,43 @@
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __CTYPE_H
#define __CTYPE_H
int isalnum(int c);
int isalpha(int c);
int isblank(int c);
int iscntrl(int c);
int isdigit(int c);
int isgraph(int c);
int islower(int c);
int isprint(int c);
int ispunct(int c);
int isspace(int c);
int isupper(int c);
int isxdigit(int c);
int tolower(int c);
int toupper(int c);
#endif

View File

@ -0,0 +1,95 @@
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __DEBUG_H
#define __DEBUG_H
#include <assert.h>
#include <stdarg.h>
#include <compiler.h>
#include <platform/debug.h>
#include <printf.h>
#if defined(__cplusplus)
extern "C" {
#endif
#if defined(DEBUG)
#define DEBUGLEVEL DEBUG
#else
#define DEBUGLEVEL 2
#endif
/* debug levels */
#define CRITICAL 0
#define ALWAYS 0
#define INFO 1
#define SPEW 2
/* output */
void _dputc(char c); // XXX for now, platform implements
int _dputs(const char *str);
int _dprintf(const char *fmt, ...) __PRINTFLIKE(1, 2);
int _dvprintf(const char *fmt, va_list ap);
#define dputc(level, str) do { if ((level) <= DEBUGLEVEL) { _dputc(str); } } while (0)
#define dputs(level, str) do { if ((level) <= DEBUGLEVEL) { _dputs(str); } } while (0)
#define dprintf(level, x...) do { if ((level) <= DEBUGLEVEL) { _dprintf(x); } } while (0)
#define dvprintf(level, x...) do { if ((level) <= DEBUGLEVEL) { _dvprintf(x); } } while (0)
/* input */
int dgetc(char *c, bool wait);
/* systemwide halts */
void halt(void);
void _panic(void *caller, const char *fmt, ...) __PRINTFLIKE(2, 3);
#define panic(x...) _panic(__GET_CALLER(), x)
#define PANIC_UNIMPLEMENTED panic("%s unimplemented\n", __PRETTY_FUNCTION__)
/* spin the cpu for a period of (short) time */
void spin(uint32_t usecs);
/* dump memory */
void hexdump(const void *ptr, size_t len);
void hexdump8(const void *ptr, size_t len);
/* trace routines */
#define TRACE_ENTRY printf("%s: entry\n", __PRETTY_FUNCTION__)
#define TRACE_EXIT printf("%s: exit\n", __PRETTY_FUNCTION__)
#define TRACE_ENTRY_OBJ printf("%s: entry obj %p\n", __PRETTY_FUNCTION__, this)
#define TRACE_EXIT_OBJ printf("%s: exit obj %p\n", __PRETTY_FUNCTION__, this)
#define TRACE printf("%s:%d\n", __PRETTY_FUNCTION__, __LINE__)
#define TRACEF(x...) do { printf("%s:%d: ", __PRETTY_FUNCTION__, __LINE__); printf(x); } while (0)
/* trace routines that work if LOCAL_TRACE is set */
#define LTRACE_ENTRY do { if (LOCAL_TRACE) { TRACE_ENTRY; } } while (0)
#define LTRACE_EXIT do { if (LOCAL_TRACE) { TRACE_EXIT; } } while (0)
#define LTRACE do { if (LOCAL_TRACE) { TRACE; } } while (0)
#define LTRACEF(x...) do { if (LOCAL_TRACE) { TRACEF(x); } } while (0)
#if defined(__cplusplus)
}
#endif
#endif

View File

@ -0,0 +1,48 @@
/*
* Copyright (c) 2008-2010 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __DEV_DISPLAY_H
#define __DEV_DISPLAY_H
#include <sys/types.h>
#include <lib/gfx.h>
int display_init(void *framebuffer);
int display_enable(bool enable);
void display_pre_freq_change(void);
void display_post_freq_change(void);
struct display_info {
void *framebuffer;
gfx_format format;
uint width;
uint height;
uint stride;
// Update function
void (*flush)(uint starty, uint endy);
};
void display_get_info(struct display_info *info);
#endif

View File

@ -0,0 +1,38 @@
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __DEV_ETHERNET_H
#define __DEV_ETHERNET_H
/* Queue an ethernet frame for send.
**
** CRC and minimum length padding are handled by the driver.
**
** Data is malloc()'d and ownership is transfered to the ethernet
** device which will free() it once the packet is transmitted.
**
*/
int ethernet_send(void *data, unsigned length);
status_t ethernet_init(void); /* initialize the ethernet device */
#endif

View File

@ -0,0 +1,54 @@
/*
* Copyright (c) 2008, Google Inc.
* All rights reserved.
*
* Copyright (c) 2009-2010, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef __DEV_FBCON_H
#define __DEV_FBCON_H
#define FB_FORMAT_RGB565 0
#define FB_FORMAT_RGB888 1
struct fbcon_config {
void *base;
unsigned width;
unsigned height;
unsigned stride;
unsigned bpp;
unsigned format;
void (*update_start)(void);
int (*update_done)(void);
};
void fbcon_setup(struct fbcon_config *cfg);
void fbcon_putc(char c);
void fbcon_clear(void);
struct fbcon_config* fbcon_display(void);
#endif /* __DEV_FBCON_H */

View File

@ -0,0 +1,83 @@
/*
* Copyright (c) 2008, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef __DEV_FLASH_H
#define __DEV_FLASH_H
#include <lib/ptable.h>
enum nand_ecc_width
{
NAND_WITH_4_BIT_ECC,
NAND_WITH_8_BIT_ECC,
};
struct flash_info {
unsigned id;
unsigned type;
unsigned vendor;
unsigned device;
unsigned page_size;
unsigned block_size;
unsigned spare_size;
unsigned num_blocks;
enum nand_ecc_width ecc_width;
unsigned num_pages_per_blk;
unsigned num_pages_per_blk_mask;
unsigned widebus;
unsigned density;
unsigned cw_size;
unsigned cws_per_page;
unsigned bad_blk_loc;
unsigned blksize;
unsigned dev_cfg;
};
void flash_init(void);
struct ptable *flash_get_ptable(void);
void flash_set_ptable(struct ptable *ptable);
struct flash_info *flash_get_info(void);
/* flash operations */
int flash_erase(struct ptentry *ptn);
int flash_read_ext(struct ptentry *ptn, unsigned extra_per_page,
unsigned offset, void *data, unsigned bytes);
int flash_write(struct ptentry *ptn, unsigned write_extra_bytes, const void *data,
unsigned bytes);
static inline int flash_read(struct ptentry *ptn, unsigned offset, void *data,
unsigned bytes)
{
return flash_read_ext(ptn, 0, offset, data, bytes);
}
unsigned flash_page_size(void);
int flash_ecc_bch_enabled(void);
#endif /* __DEV_FLASH_H */

View File

@ -0,0 +1,55 @@
/*
* Copyright (c) 2008, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef __DEV_GPIO_H
#define __DEV_GPIO_H
#ifndef GPIO_INPUT
#define GPIO_INPUT 0x0000
#endif
#ifndef GPIO_OUTPUT
#define GPIO_OUTPUT 0x0001
#endif
#define GPIO_LEVEL 0x0000
#define GPIO_EDGE 0x0010
#define GPIO_RISING 0x0020
#define GPIO_FALLING 0x0040
#define GPIO_HIGH 0x0020
#define GPIO_LOW 0x0040
#define GPIO_PULLUP 0x0100
#define GPIO_PULLDOWN 0x0200
int gpio_config(unsigned nr, unsigned flags);
void gpio_set(unsigned nr, unsigned on);
int gpio_get(unsigned nr);
#endif

View File

@ -0,0 +1,157 @@
/*
* Copyright (c) 2008, Google Inc.
* All rights reserved.
*
* Copyright (c) 2009-2012, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google, Inc. nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef __DEV_GPIO_KEYPAD_H
#define __DEV_GPIO_KEYPAD_H
#include <sys/types.h>
/* unset: drive active output low, set: drive active output high */
#define GPIOKPF_ACTIVE_HIGH (1U << 0)
#define GPIOKPF_DRIVE_INACTIVE (1U << 1)
struct gpio_keypad_info {
/* size must be ninputs * noutputs */
const uint16_t *keymap;
unsigned *input_gpios;
unsigned *output_gpios;
int ninputs;
int noutputs;
/* time to wait before reading inputs after driving each output */
time_t settle_time;
time_t poll_time;
unsigned flags;
};
void gpio_keypad_init(struct gpio_keypad_info *kpinfo);
// GPIO configurations
#define SSBI_REG_ADDR_GPIO_BASE 0x150
#define QT_PMIC_GPIO_KYPD_SNS 0x008
#define QT_PMIC_GPIO_KYPD_DRV 0x003
#define SSBI_OFFSET_ADDR_GPIO_KYPD_SNS 0x000
#define SSBI_OFFSET_ADDR_GPIO_KYPD_DRV 0x008
#define SSBI_REG_ADDR_GPIO(n) (SSBI_REG_ADDR_GPIO_BASE + n)
#define PM_GPIO_DIR_OUT 0x01
#define PM_GPIO_DIR_IN 0x02
#define PM_GPIO_DIR_BOTH (PM_GPIO_DIR_OUT | PM_GPIO_DIR_IN)
#define PM_GPIO_PULL_UP1 2
#define PM_GPIO_PULL_UP2 3
#define PM_GPIO_PULL_DN 4
#define PM_GPIO_PULL_NO 5
#define PM_GPIO_STRENGTH_NO 0
#define PM_GPIO_STRENGTH_HIGH 1
#define PM_GPIO_STRENGTH_MED 2
#define PM_GPIO_STRENGTH_LOW 3
#define PM_GPIO_FUNC_NORMAL 0
#define PM_GPIO_FUNC_PAIRED 1
#define PM_GPIO_FUNC_1 2
#define PM_GPIO_FUNC_2 3
#define PM8058_GPIO_BANK_MASK 0x70
#define PM8058_GPIO_BANK_SHIFT 4
#define PM8058_GPIO_WRITE 0x80
/* Bank 0 */
#define PM8058_GPIO_VIN_MASK 0x0E
#define PM8058_GPIO_VIN_SHIFT 1
#define PM8058_GPIO_MODE_ENABLE 0x01
/* Bank 1 */
#define PM8058_GPIO_MODE_MASK 0x0C
#define PM8058_GPIO_MODE_SHIFT 2
#define PM8058_GPIO_OUT_BUFFER 0x02
#define PM8058_GPIO_OUT_INVERT 0x01
#define PM8058_GPIO_MODE_OFF 3
#define PM8058_GPIO_MODE_OUTPUT 2
#define PM8058_GPIO_MODE_INPUT 0
#define PM8058_GPIO_MODE_BOTH 1
/* Bank 2 */
#define PM8058_GPIO_PULL_MASK 0x0E
#define PM8058_GPIO_PULL_SHIFT 1
/* Bank 3 */
#define PM8058_GPIO_OUT_STRENGTH_MASK 0x0C
#define PM8058_GPIO_OUT_STRENGTH_SHIFT 2
/* Bank 4 */
#define PM8058_GPIO_FUNC_MASK 0x0E
#define PM8058_GPIO_FUNC_SHIFT 1
struct pm8058_gpio {
int direction;
int pull;
int vin_sel; /* 0..7 */
int out_strength;
int function;
int inv_int_pol; /* invert interrupt polarity */
};
bool pm8058_gpio_get(unsigned int gpio);
typedef int (*read_func)(unsigned char *, unsigned short, unsigned short);
typedef int (*write_func)(unsigned char *, unsigned short, unsigned short);
typedef int (*gpio_get_func)(uint8_t, uint8_t *);
struct qwerty_keypad_info {
unsigned int *keymap;
unsigned int *gpiomap;
unsigned int mapsize;
unsigned char *old_keys;
unsigned char *rec_keys;
unsigned int rows;
unsigned int columns;
unsigned int num_of_reads;
read_func rd_func;
write_func wr_func;
gpio_get_func key_gpio_get;
/* time to wait before reading inputs after driving each output */
time_t settle_time;
time_t poll_time;
unsigned flags;
};
void ssbi_keypad_init (struct qwerty_keypad_info *);
#endif /* __DEV_GPIO_KEYPAD_H */

View File

@ -0,0 +1,39 @@
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __DEV_I2C_H
#define __DEV_I2C_H
void i2c_init(void);
void i2c_init_early(void);
/* send and receive blocks of data */
int i2c_transmit(int bus, uint8_t address, const void *buf, size_t count);
int i2c_receive(int bus, uint8_t address, void *buf, size_t count);
/* a few convenience routines based on the usual way of accessing 8 byte registers on i2c slave devices */
int i2c_write_reg(int bus, uint8_t address, uint8_t reg, uint8_t val);
int i2c_read_reg(int bus, uint8_t address, uint8_t reg, uint8_t *val);
#endif

View File

@ -0,0 +1,91 @@
/*
* Copyright (c) 2009, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google, Inc. nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef __DEV_KEYS_H
#define __DEV_KEYS_H
#include <sys/types.h>
/* these are just the ascii values for the chars */
#define KEY_0 0x30
#define KEY_1 0x31
#define KEY_2 0x32
#define KEY_3 0x33
#define KEY_4 0x34
#define KEY_5 0x35
#define KEY_6 0x36
#define KEY_7 0x37
#define KEY_8 0x38
#define KEY_9 0x39
#define KEY_A 0x61
#define KEY_ESC 0x100
#define KEY_F1 0x101
#define KEY_F2 0x102
#define KEY_F3 0x103
#define KEY_F4 0x104
#define KEY_F5 0x105
#define KEY_F6 0x106
#define KEY_F7 0x107
#define KEY_F8 0x108
#define KEY_F9 0x109
#define KEY_LEFT 0x110
#define KEY_RIGHT 0x111
#define KEY_UP 0x112
#define KEY_DOWN 0x113
#define KEY_CENTER 0x114
#define KEY_VOLUMEUP 0x115
#define KEY_VOLUMEDOWN 0x116
#define KEY_MUTE 0x117
#define KEY_SOUND 0x118
#define KEY_SOFT1 0x11a
#define KEY_SOFT2 0x11b
#define KEY_STAR 0x11c
#define KEY_SHARP 0x11d
#define KEY_MAIL 0x11e
#define KEY_SEND 0x120
#define KEY_CLEAR 0x121
#define KEY_HOME 0x122
#define KEY_BACK 0x123
#define KEY_MENU 0x124
#define MAX_KEYS 0x1ff
void keys_init(void);
void keys_post_event(uint16_t code, int16_t value);
int keys_get_state(uint16_t code);
#endif /* __DEV_KEYS_H */

View File

@ -0,0 +1,109 @@
/*
* Copyright (c) 2011, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef __DEV_LCDC_H
#define __DEV_LCDC_H
#include <platform/iomap.h>
#include <msm_panel.h>
#define DEFAULT_LCD_TIMING 0
#define MDP_DMA_P_CONFIG REG_MDP(0x90000)
#define MDP_DMA_P_OUT_XY REG_MDP(0x90010)
#define MDP_DMA_P_SIZE REG_MDP(0x90004)
#define MDP_DMA_P_BUF_ADDR REG_MDP(0x90008)
#define MDP_DMA_P_BUF_Y_STRIDE REG_MDP(0x9000C)
#define MDP_DMA_P_OP_MODE REG_MDP(0x90070)
#define MDP_LCDC_EN REG_MDP(LCDC_BASE + 0x00)
#define MDP_LCDC_HSYNC_CTL REG_MDP(LCDC_BASE + 0x04)
#define MDP_LCDC_VSYNC_PERIOD REG_MDP(LCDC_BASE + 0x08)
#define MDP_LCDC_VSYNC_PULSE_WIDTH REG_MDP(LCDC_BASE + 0x0C)
#define MDP_LCDC_DISPLAY_HCTL REG_MDP(LCDC_BASE + 0x10)
#define MDP_LCDC_DISPLAY_V_START REG_MDP(LCDC_BASE + 0x14)
#define MDP_LCDC_DISPLAY_V_END REG_MDP(LCDC_BASE + 0x18)
#define MDP_LCDC_ACTIVE_HCTL REG_MDP(LCDC_BASE + 0x1C)
#define MDP_LCDC_ACTIVE_V_START REG_MDP(LCDC_BASE + 0x20)
#define MDP_LCDC_ACTIVE_V_END REG_MDP(LCDC_BASE + 0x24)
#define MDP_LCDC_BORDER_CLR REG_MDP(LCDC_BASE + 0x28)
#define MDP_LCDC_UNDERFLOW_CTL REG_MDP(LCDC_BASE + 0x2C)
#define MDP_LCDC_HSYNC_SKEW REG_MDP(LCDC_BASE + 0x30)
#define MDP_LCDC_TEST_CTL REG_MDP(LCDC_BASE + 0x34)
#define MDP_LCDC_CTL_POLARITY REG_MDP(LCDC_BASE + 0x38)
#define MDP_LCDC_TEST_COL_VAR1 REG_MDP(LCDC_BASE + 0x3C)
#define MDP_LCDC_UNDERFLOW_HIDING_CTL REG_MDP(LCDC_BASE + 0x44)
#define MDP_LCDC_LOST_PIXEL_CNT_VALUE REG_MDP(LCDC_BASE + 0x48)
#define DMA_DSTC0G_8BITS (BIT(1)|BIT(0))
#define DMA_DSTC1B_8BITS (BIT(3)|BIT(2))
#define DMA_DSTC2R_8BITS (BIT(5)|BIT(4))
#define DMA_DSTC0G_6BITS (BIT(1))
#define DMA_DSTC1B_6BITS (BIT(3))
#define DMA_DSTC2R_6BITS (BIT(5))
#define DMA_DITHER_EN BIT(24)
#define DMA_OUT_SEL_LCDC BIT(20)
#define DMA_IBUF_FORMAT_RGB888 (0 << 25)
#define DMA_IBUF_FORMAT_RGB565 (1 << 25)
#define CLR_G 0x0
#define CLR_B 0x1
#define CLR_R 0x2
#define DMA_PACK_ALIGN_LSB 0
#define MDP_GET_PACK_PATTERN(a,x,y,z,bit) \
(((a)<<(bit*3))|((x)<<(bit*2))|((y)<<bit)|(z))
#define MDP_GET_PACK_PATTERN(a, x, y, z, bit) \
(((a)<<(bit*3))|((x)<<(bit*2))|((y)<<bit)|(z))
#define DMA_PACK_PATTERN_RGB \
(MDP_GET_PACK_PATTERN(0, CLR_R, CLR_G, CLR_B, 2)<<8)
#define MDP_RGB_888_FORMAT \
(BIT(17) | (1<<14) | (2<<9) | \
(0<<8) | (0<<6) | (3<<4) | \
(3<<2) | (3<<0))
#define MDP_RGB_565_FORMAT \
(BIT(17) | (1<<14) | (1<<9) | \
(0<<8) | (0<<6) | (1<<4) | \
(1<<2) | (2<<0))
/* used for setting custom timing parameters for different panels */
struct lcdc_timing_parameters
{
unsigned lcdc_fb_width;
unsigned lcdc_fb_height;
unsigned lcdc_hsync_pulse_width_dclk;
unsigned lcdc_hsync_back_porch_dclk;
unsigned lcdc_hsync_front_porch_dclk;
unsigned lcdc_hsync_skew_dclk;
unsigned lcdc_vsync_pulse_width_lines;
unsigned lcdc_vsync_back_porch_lines;
unsigned lcdc_vsync_front_porch_lines;
};
#endif /* __DEV_LCDC_H */

View File

@ -0,0 +1,179 @@
/*
* Copyright (c) 2009 Corey Tabaka
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __PCI_H
#define __PCI_H
#include <sys/types.h>
#include <compiler.h>
/*
* PCI access return codes
*/
#define _PCI_SUCCESSFUL 0x00
#define _PCI_FUNC_NOT_SUPPORTED 0x81
#define _PCI_BAD_VENDOR_ID 0x83
#define _PCI_DEVICE_NOT_FOUND 0x86
#define _PCI_BAD_REGISTER_NUMBER 0x87
#define _PCI_SET_FAILED 0x88
#define _PCI_BUFFER_TOO_SMALL 0x89
/*
* PCI configuration space offsets
*/
#define PCI_CONFIG_VENDOR_ID 0x00
#define PCI_CONFIG_DEVICE_ID 0x02
#define PCI_CONFIG_COMMAND 0x04
#define PCI_CONFIG_STATUS 0x06
#define PCI_CONFIG_REVISION_ID 0x08
#define PCI_CONFIG_CLASS_CODE 0x09
#define PCI_CONFIG_CACHE_LINE_SIZE 0x0c
#define PCI_CONFIG_LATENCY_TIMER 0x0d
#define PCI_CONFIG_HEADER_TYPE 0x0e
#define PCI_CONFIG_BIST 0x0f
#define PCI_CONFIG_BASE_ADDRESSES 0x10
#define PCI_CONFIG_CARDBUS_CIS_PTR 0x28
#define PCI_CONFIG_SUBSYS_VENDOR_ID 0x2c
#define PCI_CONFIG_SUBSYS_ID 0x2e
#define PCI_CONFIG_EXP_ROM_ADDRESS 0x30
#define PCI_CONFIG_CAPABILITIES 0x34
#define PCI_CONFIG_INTERRUPT_LINE 0x3c
#define PCI_CONFIG_INTERRUPT_PIN 0x3d
#define PCI_CONFIG_MIN_GRANT 0x3e
#define PCI_CONFIG_MAX_LATENCY 0x3f
/*
* PCI header type register bits
*/
#define PCI_HEADER_TYPE_MASK 0x7f
#define PCI_HEADER_TYPE_MULTI_FN 0x80
/*
* PCI header types
*/
#define PCI_HEADER_TYPE_STANDARD 0x00
#define PCI_HEADER_TYPE_PCI_BRIDGE 0x01
#define PCI_HEADER_TYPE_CARD_BUS 0x02
/*
* PCI command register bits
*/
#define PCI_COMMAND_IO_EN 0x0001
#define PCI_COMMAND_MEM_EN 0x0002
#define PCI_COMMAND_BUS_MASTER_EN 0x0004
#define PCI_COMMAND_SPECIAL_EN 0x0008
#define PCI_COMMAND_MEM_WR_INV_EN 0x0010
#define PCI_COMMAND_PAL_SNOOP_EN 0x0020
#define PCI_COMMAND_PERR_RESP_EN 0x0040
#define PCI_COMMAND_AD_STEP_EN 0x0080
#define PCI_COMMAND_SERR_EN 0x0100
#define PCI_COMMAND_FAST_B2B_EN 0x0200
/*
* PCI status register bits
*/
#define PCI_STATUS_NEW_CAPS 0x0010
#define PCI_STATUS_66_MHZ 0x0020
#define PCI_STATUS_FAST_B2B 0x0080
#define PCI_STATUS_MSTR_PERR 0x0100
#define PCI_STATUS_DEVSEL_MASK 0x0600
#define PCI_STATUS_TARG_ABORT_SIG 0x0800
#define PCI_STATUS_TARG_ABORT_RCV 0x1000
#define PCI_STATUS_MSTR_ABORT_RCV 0x2000
#define PCI_STATUS_SERR_SIG 0x4000
#define PCI_STATUS_PERR 0x8000
typedef struct {
uint16_t vendor_id;
uint16_t device_id;
uint16_t command;
uint16_t status;
uint8_t revision_id_0;
uint8_t program_interface;
uint8_t sub_class;
uint8_t base_class;
uint8_t cache_line_size;
uint8_t latency_timer;
uint8_t header_type;
uint8_t bist;
uint32_t base_addresses[6];
uint32_t cardbus_cis_ptr;
uint16_t subsystem_vendor_id;
uint16_t subsystem_id;
uint32_t expansion_rom_address;
uint8_t capabilities_ptr;
uint8_t reserved_0[3];
uint32_t reserved_1;
uint8_t interrupt_line;
uint8_t interrupt_pin;
uint8_t min_grant;
uint8_t max_latency;
} __PACKED pci_config_t;
/*
* PCI address structure
*/
typedef struct
{
uint8_t bus;
uint8_t dev_fn;
} pci_location_t;
typedef struct {
uint8_t id;
uint8_t next;
} __PACKED pci_capability_t;
typedef struct {
uint8_t bus;
uint8_t device;
uint8_t link_int_a;
uint16_t irq_int_a;
uint8_t link_int_b;
uint16_t irq_int_b;
uint8_t link_int_c;
uint16_t irq_int_c;
uint8_t link_int_d;
uint16_t irq_int_d;
uint8_t slot;
uint8_t reserved;
} __PACKED irq_routing_entry;
void pci_init(void);
int pci_get_last_bus(void);
int pci_find_pci_device(pci_location_t *state, uint16_t device_id, uint16_t vendor_id, uint16_t index);
int pci_find_pci_class_code(pci_location_t *state, uint32_t class_code, uint16_t index);
int pci_read_config_byte(const pci_location_t *state, uint32_t reg, uint8_t *value);
int pci_read_config_half(const pci_location_t *state, uint32_t reg, uint16_t *value);
int pci_read_config_word(const pci_location_t *state, uint32_t reg, uint32_t *value);
int pci_write_config_byte(const pci_location_t *state, uint32_t reg, uint8_t value);
int pci_write_config_half(const pci_location_t *state, uint32_t reg, uint16_t value);
int pci_write_config_word(const pci_location_t *state, uint32_t reg, uint32_t value);
int pci_get_irq_routing_options(irq_routing_entry *entries, uint16_t *count, uint16_t *pci_irqs);
int pci_set_irq_hw_int(const pci_location_t *state, uint8_t int_pin, uint8_t irq);
#endif

View File

@ -0,0 +1,38 @@
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __DEV_UART_H
#define __DEV_UART_H
#include <sys/types.h>
void uart_init(void);
void uart_init_early(void);
int uart_putc(int port, char c);
int uart_getc(int port, bool wait);
void uart_flush_tx(int port);
void uart_flush_rx(int port);
void uart_init_port(int port, uint baud);
#endif

View File

@ -0,0 +1,126 @@
/*
* Copyright (c) 2009, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef __DEV_UDC_H
#define __DEV_UDC_H
/* USB Device Controller Transfer Request */
struct udc_request {
void *buf;
unsigned length;
void (*complete)(struct udc_request *req, unsigned actual, int status);
void *context;
};
/* endpoints are opaque handles specific to the particular device controller */
struct udc_endpoint;
struct udc_request *udc_request_alloc(void);
void udc_request_free(struct udc_request *req);
int udc_request_queue(struct udc_endpoint *ept, struct udc_request *req);
int udc_request_cancel(struct udc_endpoint *ept, struct udc_request *req);
#define UDC_TYPE_BULK_IN 1
#define UDC_TYPE_BULK_OUT 2
struct udc_endpoint *udc_endpoint_alloc(unsigned type, unsigned maxpkt);
void udc_endpoint_free(struct udc_endpoint *ept);
#define UDC_EVENT_ONLINE 1
#define UDC_EVENT_OFFLINE 2
struct udc_gadget {
void (*notify)(struct udc_gadget *gadget, unsigned event);
void *context;
unsigned char ifc_class;
unsigned char ifc_subclass;
unsigned char ifc_protocol;
unsigned char ifc_endpoints;
const char *ifc_string;
unsigned flags;
struct udc_endpoint **ept;
};
struct udc_device {
unsigned short vendor_id;
unsigned short product_id;
unsigned short version_id;
const char *manufacturer;
const char *product;
const char *serialno;
};
int udc_init(struct udc_device *devinfo);
int udc_register_gadget(struct udc_gadget *gadget);
int udc_start(void);
int udc_stop(void);
/* these should probably go elsewhere */
#define GET_STATUS 0
#define CLEAR_FEATURE 1
#define SET_FEATURE 3
#define SET_ADDRESS 5
#define GET_DESCRIPTOR 6
#define SET_DESCRIPTOR 7
#define GET_CONFIGURATION 8
#define SET_CONFIGURATION 9
#define GET_INTERFACE 10
#define SET_INTERFACE 11
#define SYNCH_FRAME 12
#define TYPE_DEVICE 1
#define TYPE_CONFIGURATION 2
#define TYPE_STRING 3
#define TYPE_INTERFACE 4
#define TYPE_ENDPOINT 5
#define DEVICE_READ 0x80
#define DEVICE_WRITE 0x00
#define INTERFACE_READ 0x81
#define INTERFACE_WRITE 0x01
#define ENDPOINT_READ 0x82
#define ENDPOINT_WRITE 0x02
#define TEST_SE0_NAK 0x0300
#define TEST_PACKET 0x0400
#define PORTSC_PTC (0xF << 16)
#define PORTSC_PTC_SE0_NAK (0x03 << 16)
#define PORTSC_PTC_TST_PKT (0x4 << 16)
struct setup_packet {
unsigned char type;
unsigned char request;
unsigned short value;
unsigned short index;
unsigned short length;
} __attribute__ ((packed));
#endif

View File

@ -0,0 +1,65 @@
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __DEV_USB_H
#define __DEV_USB_H
#include <sys/types.h>
#include <compiler.h>
/* top level initialization for usb client, abstracts away the interfaces */
typedef struct {
void *desc;
size_t len;
} usb_descriptor __ALIGNED(2);
typedef struct {
usb_descriptor string;
uint8_t id;
} usb_string;
/* complete usb config struct, passed in to usb_setup() */
typedef struct {
struct usb_descriptor_speed {
usb_descriptor device;
usb_descriptor device_qual;
usb_descriptor config;
} lowspeed, highspeed;
usb_descriptor langid;
} usb_config;
void usb_init(void);
/* external code needs to set up the usb stack via the following calls */
void usb_setup(usb_config *config);
/* apped new interface descriptors to the existing config if desired */
int usb_append_interface_highspeed(const uint8_t *int_descr, size_t len);
int usb_append_interface_lowspeed(const uint8_t *int_descr, size_t len);
void usb_add_string(const char *string, uint8_t id);
void usb_start(void);
void usb_stop(void);
#endif

View File

@ -0,0 +1,98 @@
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __DEV_USBC_H
#define __DEV_USBC_H
#include <sys/types.h>
#include <debug.h>
#include <hw/usb.h>
void usbc_init(void);
typedef uint ep_t;
typedef enum {
IN = 0,
OUT
} ep_dir_t;
typedef enum {
CB_RESET,
CB_SUSPEND,
CB_RESUME,
CB_DISCONNECT,
CB_ONLINE,
CB_OFFLINE,
CB_SETUP_MSG,
/* endpoint transfer stuff */
CB_EP_RXCOMPLETE,
CB_EP_TXCOMPLETE,
CB_EP_TRANSFER_CANCELLED,
} usbc_callback_op_t;
typedef struct {
void *buf;
size_t buflen;
uint bufpos;
int result;
void *extra; // extra pointer to store whatever you want
} usbc_transfer;
enum {
USB_TRANSFER_RESULT_OK = 0,
USB_TRANSFER_RESULT_ERR = -1,
USB_TRANSFER_RESULT_CANCELLED = -2,
};
typedef int (*ep_callback)(ep_t endpoint, usbc_callback_op_t op, usbc_transfer *transfer);
void usbc_setup_endpoint(ep_t ep, ep_dir_t dir, bool active, ep_callback callback, uint width, uint blocksize);
int usbc_queue_rx(ep_t ep, usbc_transfer *transfer);
int usbc_queue_tx(ep_t ep, usbc_transfer *transfer);
/* setup arg is valid during CB_SETUP_MSG */
union usb_callback_args {
const struct usb_setup *setup;
};
typedef int (*usb_callback)(usbc_callback_op_t op, const union usb_callback_args *args);
int usbc_set_callback(usb_callback);
int usbc_set_active(bool active);
/* called back from within a callback to handle setup responses */
void usbc_ep0_ack(void);
void usbc_ep0_stall(void);
void usbc_ep0_send(const void *buf, size_t len, size_t maxlen);
void usbc_ep0_recv(void *buf, size_t len, ep_callback);
bool usbc_is_highspeed(void);
static inline void usbc_dump_transfer(const usbc_transfer *t)
{
printf("usb transfer %p: buf %p, buflen %zd, bufpos %u, result %d\n", t, t->buf, t->buflen, t->bufpos, t->result);
}
#endif

View File

@ -0,0 +1,99 @@
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __ENDIAN_H
#define __ENDIAN_H
#include <sys/types.h>
#ifndef LITTLE_ENDIAN
#define LITTLE_ENDIAN 1234
#endif
#ifndef BIG_ENDIAN
#define BIG_ENDIAN 4321
#endif
#if __POWERPC__
#include <ppc_intrinsics.h>
#endif
#if defined(ARCH_ARM)
#define BYTE_ORDER LITTLE_ENDIAN
#endif
#if defined(__i386__) || defined(_X86_)
#define BYTE_ORDER LITTLE_ENDIAN
#endif
#ifndef BYTE_ORDER
#error "need to get the BYTE_ORDER define from somewhere"
#endif
// define a macro that unconditionally swaps
#define SWAP_32(x) \
(((uint32_t)(x) << 24) | (((uint32_t)(x) & 0xff00) << 8) |(((uint32_t)(x) & 0x00ff0000) >> 8) | ((uint32_t)(x) >> 24))
#define SWAP_16(x) \
((((uint16_t)(x) & 0xff) << 8) | ((uint16_t)(x) >> 8))
// standard swap macros
#if BYTE_ORDER == BIG_ENDIAN
#define LE32(val) SWAP_32(val)
#define LE16(val) SWAP_16(val)
#define BE32(val) (val)
#define BE16(val) (val)
#else
#define LE32(val) (val)
#define LE16(val) (val)
#define BE32(val) SWAP_32(val)
#define BE16(val) SWAP_16(val)
#endif
#define LE32SWAP(var) (var) = LE32(var);
#define LE16SWAP(var) (var) = LE16(var);
#define BE32SWAP(var) (var) = BE32(var);
#define BE16SWAP(var) (var) = BE16(var);
/* classic network byte swap stuff */
#define ntohs(n) BE16(n)
#define htons(h) BE16(h)
#define ntohl(n) BE32(n)
#define htonl(h) BE32(h)
// some memory access macros
#if __POWERPC__
#define READ_MEM_WORD(ptr) __lwbrx((word *)(ptr), 0)
#define READ_MEM_HALFWORD(ptr) __lhbrx((halfword *)(ptr), 0)
#define READ_MEM_BYTE(ptr) (*(byte *)(ptr))
#define WRITE_MEM_WORD(ptr, data) __stwbrx(data, (word *)(ptr), 0)
#define WRITE_MEM_HALFWORD(ptr, data) __sthbrx(data, (halfword *)(ptr), 0)
#define WRITE_MEM_BYTE(ptr, data) (*(byte *)(ptr) = (data))
#else
#define READ_MEM_WORD(ptr) SWAPIT_32(*(word *)(ptr))
#define READ_MEM_HALFWORD(ptr) SWAPIT_16(*(halfword *)(ptr))
#define READ_MEM_BYTE(ptr) (*(byte *)(ptr))
#define WRITE_MEM_WORD(ptr, data) (*(word *)(ptr) = SWAPIT_32(data))
#define WRITE_MEM_HALFWORD(ptr, data) (*(halfword *)(ptr) = SWAPIT_16(data))
#define WRITE_MEM_BYTE(ptr, data) (*(byte *)(ptr) = (data))
#endif
#endif

View File

@ -0,0 +1,55 @@
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __ERR_H
#define __ERR_H
#include <sys/types.h> // for status_t
#define NO_ERROR 0
#define ERROR -1
#define ERR_NOT_FOUND -2
#define ERR_NOT_READY -3
#define ERR_NO_MSG -4
#define ERR_NO_MEMORY -5
#define ERR_ALREADY_STARTED -6
#define ERR_NOT_VALID -7
#define ERR_INVALID_ARGS -8
#define ERR_NOT_ENOUGH_BUFFER -9
#define ERR_NOT_SUSPENDED -10
#define ERR_OBJECT_DESTROYED -11
#define ERR_NOT_BLOCKED -12
#define ERR_TIMED_OUT -13
#define ERR_ALREADY_EXISTS -14
#define ERR_CHANNEL_CLOSED -15
#define ERR_OFFLINE -16
#define ERR_NOT_ALLOWED -17
#define ERR_BAD_PATH -18
#define ERR_ALREADY_MOUNTED -19
#define ERR_IO -20
#define ERR_NOT_DIR -21
#define ERR_NOT_FILE -22
#define ERR_RECURSE_TOO_DEEP -23
#define ERR_NOT_SUPPORTED -24
#define ERR_TOO_BIG -25
#endif

View File

@ -0,0 +1,33 @@
/*
* Copyright (c) 2011, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of The Linux Foundation nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef _ASM_GENERIC_ERRNO_H
#define _ASM_GENERIC_ERRNO_H
#endif

View File

@ -0,0 +1,75 @@
/*
* Copyright (c) 2006 Brian Swetland
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __HW_MII_H
#define __HW_MII_H
#define MII_REG_BCR 0x00
#define MII_REG_BSR 0x01
#define MII_REG_PHY_ID1 0x02
#define MII_REG_PHY_ID2 0x03
#define MII_REG_AUTO_ADV 0x04
#define MII_REG_AUTO_LINK 0x05
#define MII_REG_AUTO_EXPN 0x06
#define MII_REG_AUTO_NEXT 0x07
#define MII_REG_LINK_NEXT 0x08
#define MII_REG_RXER_CNT 0x15
#define MII_REG_ICSR 0x1b
#define MII_REG_100TX_PHY 0x1f
#define MII_BCR_RESET 0x8000
#define MII_BCR_LOOPBACK 0x4000
#define MII_BCR_100MBPS 0x2000
#define MII_BCR_AUTO_ENABLE 0x1000
#define MII_BCR_PWR_DOWN 0x0800
#define MII_BCR_ISOLATE 0x0400
#define MII_BCR_AUTO_RESTART 0x0200
#define MII_BCR_FULL_DUPLEX 0x0100
#define MII_BCR_COL_TEST 0x0080
#define MII_BCR_TX_DISABLE 0x0001
#define MII_BSR_T4 0x8000
#define MII_BSR_100TX_FULL 0x4000
#define MII_BSR_100TX_HALF 0x2000
#define MII_BSR_10T_FULL 0x1000
#define MII_BSR_10T_HALF 0x0800
#define MII_BSR_NO_PREAMBLE 0x0040
#define MII_BSR_AUTO_COMPLETE 0x0020
#define MII_BSR_REMOTE_FAULT 0x0010
#define MII_BSR_AUTO_ABLE 0x0008
#define MII_BSR_LINK_UP 0x0004
#define MII_BSR_JABBER 0x0002
#define MII_BSR_EXTEND 0x0001
#define MII_100TX_PHY_ISOLATE 0x0040
#define MII_100TX_MODE_MASK 0x001C
#define MII_100TX_MODE_AUTO 0x0000
#define MII_100TX_MODE_10T_H 0x0004
#define MII_100TX_MODE_100TX_H 0x0008
#define MII_100TX_MODE_10T_F 0x0014
#define MII_100TX_MODE_100TX_F 0x0018
#define MII_100TX_MODE_ISOLATE 0x001C
#define MII_100TX_SQE_TEST 0x0002
#define MII_100TX_NO_SCRAMBLE 0x0001
#endif

View File

@ -0,0 +1,106 @@
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __HW_USB_H
#define __HW_USB_H
#include <sys/types.h>
#include <compiler.h>
/* GLOBAL STATUS VALUES */
#define STD_COMMAND 0x00
#define SETUP_COMMAND_PHASE 0x40
#define FUNCTION_ERROR 0x7F /* Used when we are stalling the function EP0 */
#define HUB_ERROR 0xFF /* Used when we are stalling the HUB EP0 */
/* Request Types */
#define DIR_OUT (0 << 7)
#define DIR_IN (1 << 7)
#define DIR_MASK (1 << 7)
#define TYPE_STANDARD (0 << 5)
#define TYPE_CLASS (1 << 5)
#define TYPE_VENDOR (2 << 5)
#define TYPE_MASK (3 << 5)
#define RECIP_DEVICE (0 << 0)
#define RECIP_INTERFACE (1 << 0)
#define RECIP_ENDPOINT (2 << 0)
#define RECIP_OTHER (3 << 0)
#define RECIP_MASK (0x1f << 0)
/* 1.0 Request Values */
#define GET_STATUS 0x00
#define CLEAR_FEATURE 0x01
#define SET_FEATURE 0x03
#define SET_ADDRESS 0x05
#define GET_DESCRIPTOR 0x06
#define SET_DESCRIPTOR 0x07
#define GET_CONFIGURATION 0x08
#define SET_CONFIGURATION 0x09
#define GET_INTERFACE 0x0A
#define SET_INTERFACE 0x0B
#define SYNCH_FRAME 0x0C
/* Mass storage requests */
#define MASS_STORAGE_GET_MAX_LUN 0xfe
#define MASS_STORAGE_RESET 0xff
/* DFU requests */
#define DFU_DETACH 0x00
#define DFU_DNLOAD 0x01
#define DFU_UPLOAD 0x02
#define DFU_GETSTATUS 0x03
#define DFU_CLRSTATUS 0x04
#define DFU_GETSTATE 0x05
#define DFU_ABORT 0x06
/* HID Request Values */
#define GET_REPORT 0x01
#define GET_IDLE 0x02
#define GET_PROTOCOL 0x03
#define SET_REPORT 0x09
#define SET_IDLE 0x0A
#define SET_PROTOCOL 0x0B
/* Descriptor Types */
#define DEVICE 0x01
#define CONFIGURATION 0x02
#define STRING 0x03
#define INTERFACE 0x04
#define ENDPOINT 0x05
#define DEVICE_QUALIFIER 0x06
#define OTHER_SPEED_CONFIGURATION 0x07
#define INTERFACE_POWER 0x08
#define HID 0x21
#define HIDREPORT 0x22
#define HIDPHYSICAL 0x23
/* general USB defines */
struct usb_setup {
uint8_t request_type;
uint8_t request;
uint16_t value;
uint16_t index;
uint16_t length;
} __PACKED;
#endif

View File

@ -0,0 +1,29 @@
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __INTTYPES_H
#define __INTTYPES_H
#include <stdint.h>
#endif

View File

@ -0,0 +1,38 @@
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __KERNEL_DPC_H
#define __KERNEL_DPC_H
#include <list.h>
#include <sys/types.h>
void dpc_init(void);
typedef void (*dpc_callback)(void *arg);
#define DPC_FLAG_NORESCHED 0x1
status_t dpc_queue(dpc_callback, void *arg, uint flags);
#endif

View File

@ -0,0 +1,64 @@
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __KERNEL_EVENT_H
#define __KERNEL_EVENT_H
#include <kernel/thread.h>
#define EVENT_MAGIC 'evnt'
typedef struct event {
int magic;
bool signalled;
uint flags;
wait_queue_t wait;
} event_t;
#define EVENT_FLAG_AUTOUNSIGNAL 1
/* Rules for Events:
* - Events may be signaled from interrupt context *but* the reschedule
* parameter must be false in that case.
* - Events may not be waited upon from interrupt context.
* - Events without FLAG_AUTOUNSIGNAL:
* - Wake up any waiting threads when signaled.
* - Continue to do so (no threads will wait) until unsignaled.
* - Events with FLAG_AUTOUNSIGNAL:
* - If one or more threads are waiting when signaled, one thread will
* be woken up and return. The signaled state will not be set.
* - If no threads are waiting when signaled, the Event will remain
* in the signaled state until a thread attempts to wait (at which
* time it will unsignal atomicly and return immediately) or
* event_unsignal() is called.
*/
void event_init(event_t *, bool initial, uint flags);
void event_destroy(event_t *);
status_t event_wait(event_t *);
status_t event_wait_timeout(event_t *, time_t); /* wait on the event with a timeout */
status_t event_signal(event_t *, bool reschedule);
status_t event_unsignal(event_t *);
#define event_initialized(e) ((e)->magic == EVENT_MAGIC)
#endif

View File

@ -0,0 +1,49 @@
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __KERNEL_MUTEX_H
#define __KERNEL_MUTEX_H
#include <kernel/thread.h>
#define MUTEX_MAGIC 'mutx'
typedef struct mutex {
int magic;
int count;
thread_t *holder;
wait_queue_t wait;
} mutex_t;
/* Rules for Mutexes:
* - Mutexes are only safe to use from thread context.
* - Mutexes are non-recursive.
*/
void mutex_init(mutex_t *);
void mutex_destroy(mutex_t *);
status_t mutex_acquire(mutex_t *);
status_t mutex_acquire_timeout(mutex_t *, time_t); /* try to acquire the mutex with a timeout value */
status_t mutex_release(mutex_t *);
#endif

View File

@ -0,0 +1,231 @@
/*
* Copyright (c) 2008-2009 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __KERNEL_THREAD_H
#define __KERNEL_THREAD_H
#include <sys/types.h>
#include <list.h>
#include <compiler.h>
#include <arch/ops.h>
#include <arch/thread.h>
enum thread_state {
THREAD_SUSPENDED = 0,
THREAD_READY,
THREAD_RUNNING,
THREAD_BLOCKED,
THREAD_SLEEPING,
THREAD_DEATH,
};
typedef int (*thread_start_routine)(void *arg);
/* thread local storage */
enum thread_tls_list {
MAX_TLS_ENTRY
};
#define THREAD_MAGIC 'thrd'
typedef struct thread {
int magic;
struct list_node thread_list_node;
/* active bits */
struct list_node queue_node;
int priority;
enum thread_state state;
int saved_critical_section_count;
int remaining_quantum;
/* if blocked, a pointer to the wait queue */
struct wait_queue *blocking_wait_queue;
status_t wait_queue_block_ret;
/* architecture stuff */
struct arch_thread arch;
/* stack stuff */
void *stack;
size_t stack_size;
/* entry point */
thread_start_routine entry;
void *arg;
/* return code */
int retcode;
/* thread local storage */
uint32_t tls[MAX_TLS_ENTRY];
char name[32];
} thread_t;
/* thread priority */
#define NUM_PRIORITIES 32
#define LOWEST_PRIORITY 0
#define HIGHEST_PRIORITY (NUM_PRIORITIES - 1)
#define DPC_PRIORITY (NUM_PRIORITIES - 2)
#define IDLE_PRIORITY LOWEST_PRIORITY
#define LOW_PRIORITY (NUM_PRIORITIES / 4)
#define DEFAULT_PRIORITY (NUM_PRIORITIES / 2)
#define HIGH_PRIORITY ((NUM_PRIORITIES / 4) * 3)
/* stack size */
#define DEFAULT_STACK_SIZE 8192
/* functions */
void thread_init_early(void);
void thread_init(void);
void thread_become_idle(void) __NO_RETURN;
void thread_set_name(const char *name);
void thread_set_priority(int priority);
thread_t *thread_create(const char *name, thread_start_routine entry, void *arg, int priority, size_t stack_size);
status_t thread_resume(thread_t *);
void thread_exit(int retcode) __NO_RETURN;
void thread_sleep(time_t delay);
void dump_thread(thread_t *t);
void dump_all_threads(void);
/* scheduler routines */
void thread_yield(void); /* give up the cpu voluntarily */
void thread_preempt(void); /* get preempted (inserted into head of run queue) */
void thread_block(void); /* block on something and reschedule */
/* called on every timer tick for the scheduler to do quantum expiration */
enum handler_return thread_timer_tick(void);
/* the current thread */
extern thread_t *current_thread;
/* the idle thread */
extern thread_t *idle_thread;
/* critical sections */
extern int critical_section_count;
static inline __ALWAYS_INLINE void enter_critical_section(void)
{
critical_section_count++;
if (critical_section_count == 1)
arch_disable_ints();
}
static inline __ALWAYS_INLINE void exit_critical_section(void)
{
critical_section_count--;
if (critical_section_count == 0)
arch_enable_ints();
}
static inline __ALWAYS_INLINE bool in_critical_section(void)
{
return critical_section_count > 0;
}
/* only used by interrupt glue */
static inline void inc_critical_section(void) { critical_section_count++; }
static inline void dec_critical_section(void) { critical_section_count--; }
/* thread local storage */
static inline __ALWAYS_INLINE uint32_t tls_get(uint entry)
{
return current_thread->tls[entry];
}
static inline __ALWAYS_INLINE uint32_t tls_set(uint entry, uint32_t val)
{
uint32_t oldval = current_thread->tls[entry];
current_thread->tls[entry] = val;
return oldval;
}
/* wait queue stuff */
#define WAIT_QUEUE_MAGIC 'wait'
typedef struct wait_queue {
int magic;
struct list_node list;
int count;
} wait_queue_t;
/* wait queue primitive */
/* NOTE: must be inside critical section when using these */
void wait_queue_init(wait_queue_t *);
/*
* release all the threads on this wait queue with a return code of ERR_OBJECT_DESTROYED.
* the caller must assure that no other threads are operating on the wait queue during or
* after the call.
*/
void wait_queue_destroy(wait_queue_t *, bool reschedule);
/*
* block on a wait queue.
* return status is whatever the caller of wait_queue_wake_*() specifies.
* a timeout other than INFINITE_TIME will set abort after the specified time
* and return ERR_TIMED_OUT. a timeout of 0 will immediately return.
*/
status_t wait_queue_block(wait_queue_t *, time_t timeout);
/*
* release one or more threads from the wait queue.
* reschedule = should the system reschedule if any is released.
* wait_queue_error = what wait_queue_block() should return for the blocking thread.
*/
int wait_queue_wake_one(wait_queue_t *, bool reschedule, status_t wait_queue_error);
int wait_queue_wake_all(wait_queue_t *, bool reschedule, status_t wait_queue_error);
/*
* remove the thread from whatever wait queue it's in.
* return an error if the thread is not currently blocked (or is the current thread)
*/
status_t thread_unblock_from_wait_queue(thread_t *t, bool reschedule, status_t wait_queue_error);
/* thread level statistics */
#if DEBUGLEVEL > 1
#define THREAD_STATS 1
#else
#define THREAD_STATS 0
#endif
#if THREAD_STATS
struct thread_stats {
bigtime_t idle_time;
bigtime_t last_idle_timestamp;
int reschedules;
int context_switches;
int preempts;
int yields;
int interrupts; /* platform code increment this */
int timer_ints; /* timer code increment this */
int timers; /* timer code increment this */
};
extern struct thread_stats thread_stats;
#endif
#endif

View File

@ -0,0 +1,59 @@
/*
* Copyright (c) 2008-2009 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __KERNEL_TIMER_H
#define __KERNEL_TIMER_H
#include <list.h>
#include <sys/types.h>
void timer_init(void);
struct timer;
typedef enum handler_return (*timer_callback)(struct timer *, time_t now, void *arg);
#define TIMER_MAGIC 'timr'
typedef struct timer {
int magic;
struct list_node node;
time_t scheduled_time;
time_t periodic_time;
timer_callback callback;
void *arg;
} timer_t;
/* Rules for Timers:
* - Timer callbacks occur from interrupt context
* - Timers may be programmed or canceled from interrupt or thread context
* - Timers may be canceled or reprogrammed from within their callback
* - Timers currently are dispatched from a 10ms periodic tick
*/
void timer_initialize(timer_t *);
void timer_set_oneshot(timer_t *, time_t delay, timer_callback, void *arg);
void timer_set_periodic(timer_t *, time_t period, timer_callback, void *arg);
void timer_cancel(timer_t *);
#endif

View File

@ -0,0 +1,40 @@
/*
* Copyright (c) 2007 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __LIB_BCACHE_H
#define __LIB_BCACHE_H
#include <lib/bio.h>
typedef void * bcache_t;
bcache_t bcache_create(bdev_t *dev, size_t block_size, int block_count);
void bcache_destroy(bcache_t);
int bcache_read_block(bcache_t, void *, uint block);
// get and put a pointer directly to the block
int bcache_get_block(bcache_t, void **, uint block);
int bcache_put_block(bcache_t, uint block);
#endif

View File

@ -0,0 +1,81 @@
/*
* Copyright (c) 2009 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __LIB_BIO_H
#define __LIB_BIO_H
#include <sys/types.h>
#include <list.h>
typedef uint32_t bnum_t;
typedef struct bdev {
struct list_node node;
volatile int ref;
/* info about the block device */
char *name;
off_t size;
size_t block_size;
bnum_t block_count;
/* function pointers */
ssize_t (*read)(struct bdev *, void *buf, off_t offset, size_t len);
ssize_t (*read_block)(struct bdev *, void *buf, bnum_t block, uint count);
ssize_t (*write)(struct bdev *, const void *buf, off_t offset, size_t len);
ssize_t (*write_block)(struct bdev *, const void *buf, bnum_t block, uint count);
ssize_t (*erase)(struct bdev *, off_t offset, size_t len);
int (*ioctl)(struct bdev *, int request, void *argp);
void (*close)(struct bdev *);
} bdev_t;
/* user api */
bdev_t *bio_open(const char *name);
void bio_close(bdev_t *dev);
ssize_t bio_read(bdev_t *dev, void *buf, off_t offset, size_t len);
ssize_t bio_read_block(bdev_t *dev, void *buf, bnum_t block, uint count);
ssize_t bio_write(bdev_t *dev, const void *buf, off_t offset, size_t len);
ssize_t bio_write_block(bdev_t *dev, const void *buf, bnum_t block, uint count);
ssize_t bio_erase(bdev_t *dev, off_t offset, size_t len);
int bio_ioctl(bdev_t *dev, int request, void *argp);
/* intialize the block device layer */
void bio_init(void);
/* register a block device */
void bio_register_device(bdev_t *dev);
void bio_unregister_device(bdev_t *dev);
/* used during bdev construction */
void bio_initialize_bdev(bdev_t *dev, const char *name, size_t block_size, bnum_t block_count);
/* debug stuff */
void bio_dump_devices(void);
/* subdevice support */
status_t bio_publish_subdevice(const char *parent_dev, const char *subdev, bnum_t startblock, size_t len);
/* memory based block device */
int create_membdev(const char *name, void *ptr, size_t len);
#endif

View File

@ -0,0 +1,42 @@
/*
* Copyright (c) 2009 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __LIB_CBUF_H
#define __LIB_CBUF_H
#include <sys/types.h>
#include <kernel/event.h>
typedef struct cbuf {
uint head;
uint tail;
uint len_pow2;
char *buf;
event_t event;
} cbuf_t;
void cbuf_initialize(cbuf_t *cbuf, size_t len);
size_t cbuf_read(cbuf_t *cbuf, void *_buf, size_t buflen, bool block);
size_t cbuf_write(cbuf_t *cbuf, const void *_buf, size_t len, bool canreschedule);
#endif

View File

@ -0,0 +1,62 @@
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __LIB_CONSOLE_H
#define __LIB_CONSOLE_H
#include <sys/types.h>
#include <compiler.h>
/* command args */
typedef struct {
const char *str;
unsigned int u;
int i;
} cmd_args;
typedef int (*console_cmd)(int argc, const cmd_args *argv);
/* a block of commands to register */
typedef struct {
const char *cmd_str;
const char *help_str;
const console_cmd cmd_callback;
} cmd;
typedef struct _cmd_block {
struct _cmd_block *next;
size_t count;
const cmd *list;
} cmd_block;
/* register a static block of commands at init time */
#define STATIC_COMMAND_START static const cmd _cmd_list[] = {
#define STATIC_COMMAND_END(name) }; const cmd_block _cmd_block_##name __SECTION(".commands")= { NULL, sizeof(_cmd_list) / sizeof(_cmd_list[0]), _cmd_list }
/* external api */
int console_init(void);
void console_start(void);
void console_register_commands(cmd_block *block);
int console_run_command(const char *string);
#endif

View File

@ -0,0 +1,12 @@
#ifndef __LIB_FONT_H
#define __LIB_FONT_H
#include <lib/gfx.h>
#define FONT_X 6
#define FONT_Y 12
void font_draw_char(gfx_surface *surface, unsigned char c, int x, int y, uint32_t color);
#endif

View File

@ -0,0 +1,52 @@
/*
* Copyright (c) 2009 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __LIB_FS_H
#define __LIB_FS_H
void fs_init(void);
struct file_stat {
bool is_dir;
off_t size;
};
typedef void *filecookie;
typedef void *fscookie;
int fs_mount(const char *path, const char *device);
int fs_unmount(const char *path);
/* file api */
int fs_open_file(const char *path, filecookie *fcookie);
int fs_read_file(filecookie fcookie, void *buf, off_t offset, size_t len);
int fs_close_file(filecookie fcookie);
int fs_stat_file(filecookie fcookie, struct file_stat *);
/* convenience routines */
ssize_t fs_load_file(const char *path, void *ptr, size_t maxlen);
/* walk through a path string, removing duplicate path seperators, flattening . and .. references */
void fs_normalize_path(char *path);
#endif

View File

@ -0,0 +1,86 @@
#ifndef __LIB_GFX_H
#define __LIB_GFX_H
#include <sys/types.h>
// gfx library
// different graphics formats
typedef enum {
GFX_FORMAT_RGB_565,
GFX_FORMAT_ARGB_8888,
GFX_FORMAT_RGB_x888,
GFX_FORMAT_MAX
} gfx_format;
#define MAX_ALPHA 255
/**
* @brief Describe a graphics drawing surface
*
* The gfx_surface object represents a framebuffer that can be rendered
* to. Elements include a pointer to the actual pixel memory, its size, its
* layout, and pointers to basic drawing functions.
*
* @ingroup graphics
*/
typedef struct gfx_surface {
void *ptr;
bool free_on_destroy;
gfx_format format;
uint width;
uint height;
uint stride;
uint pixelsize;
size_t len;
uint alpha;
// function pointers
void (*copyrect)(struct gfx_surface *, uint x, uint y, uint width, uint height, uint x2, uint y2);
void (*fillrect)(struct gfx_surface *, uint x, uint y, uint width, uint height, uint color);
void (*putpixel)(struct gfx_surface *, uint x, uint y, uint color);
void (*flush)(uint starty, uint endy);
} gfx_surface;
// copy a rect from x,y with width x height to x2, y2
void gfx_copyrect(gfx_surface *surface, uint x, uint y, uint width, uint height, uint x2, uint y2);
// fill a rect within the surface with a color
void gfx_fillrect(gfx_surface *surface, uint x, uint y, uint width, uint height, uint color);
// draw a pixel at x, y in the surface
void gfx_putpixel(gfx_surface *surface, uint x, uint y, uint color);
// clear the entire surface with a color
static inline void gfx_clear(gfx_surface *surface, uint color)
{
surface->fillrect(surface, 0, 0, surface->width, surface->height, color);
if (surface->flush)
surface->flush(0, surface->height-1);
}
// blend between two surfaces
void gfx_surface_blend(struct gfx_surface *target, struct gfx_surface *source, uint destx, uint desty);
void gfx_flush(struct gfx_surface *surface);
void gfx_flush_rows(struct gfx_surface *surface, uint start, uint end);
// surface setup
gfx_surface *gfx_create_surface(void *ptr, uint width, uint height, uint stride, gfx_format format);
// utility routine to make a surface out of a display info
struct display_info;
gfx_surface *gfx_create_surface_from_display(struct display_info *);
// free the surface
// optionally frees the buffer if the free bit is set
void gfx_surface_destroy(struct gfx_surface *surface);
// utility routine to fill the display with a little moire pattern
void gfx_draw_pattern(void);
#endif

View File

@ -0,0 +1,10 @@
#ifndef __LIB_GFXCONSOLE_H
#define __LIB_GFXCONSOLE_H
#include <lib/gfx.h>
void gfxconsole_start_on_display(void);
void gfxconsole_start(gfx_surface *surface);
#endif

View File

@ -0,0 +1,36 @@
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __LIB_HEAP_H
#define __LIB_HEAP_H
#include <sys/types.h>
void *heap_alloc(size_t, unsigned int alignment);
void *heap_realloc(void *ptr, size_t size);
void heap_free(void *);
void heap_init(void);
#endif

View File

@ -0,0 +1,35 @@
/*
* Copyright (c) 2009 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __LIB_PARTITION_H
#define __LIB_PARTITION_H
#include <sys/types.h>
/* examine and try to publish partitions on a particular device at a particular offset */
int partition_publish(const char *device, off_t offset);
/* remove any published subdevices on this device */
int partition_unpublish(const char *device);
#endif

View File

@ -0,0 +1,71 @@
/*
* Copyright (c) 2008, Google Inc.
* All rights reserved.
*
* Copyright (c) 2009-2012, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef __LIB_PTABLE_H
#define __LIB_PTABLE_H
/* flash partitions are defined in terms of blocks
* (flash erase units)
*/
#define MAX_PTENTRY_NAME 16
#define MAX_PTABLE_PARTS 32
#define TYPE_MODEM_PARTITION 1
#define TYPE_APPS_PARTITION 0
#define PERM_NON_WRITEABLE 0
#define PERM_WRITEABLE 1
struct ptentry
{
char name[MAX_PTENTRY_NAME];
unsigned start;
unsigned length;
unsigned flags;
char type;
char perm;
};
struct ptable
{
struct ptentry parts[MAX_PTABLE_PARTS];
int count;
};
/* tools to populate and query the partition table */
void ptable_init(struct ptable *ptable);
void ptable_add(struct ptable *ptable, char *name, unsigned start,
unsigned length, unsigned flags, char type, char perm);
struct ptentry *ptable_find(struct ptable *ptable, const char *name);
struct ptentry *ptable_get(struct ptable *ptable, int n);
int ptable_get_index(struct ptable *ptable, const char *name);
int ptable_size(struct ptable *ptable);
void ptable_dump(struct ptable *ptable);
#endif /* __LIB_PTABLE_H */

View File

@ -0,0 +1,14 @@
#ifndef __LIB_TEXT_H
#define __LIB_TEXT_H
#include <lib/font.h>
/* super cheezy mechanism to stick lines of text up on top of whatever is being drawn */
/* XXX replace with something more generic later */
void text_draw(int x, int y, const char *string);
/* super dumb, someone has to call this to refresh everything */
void text_update(void);
#endif

View File

@ -0,0 +1,10 @@
#ifndef __LIB_TGA_H
#define __LIB_TGA_H
#include <lib/gfx.h>
#include <sys/types.h>
gfx_surface *tga_decode(const void *ptr, size_t len, gfx_format format);
#endif

View File

@ -0,0 +1,121 @@
/* This administrivia gets added to the beginning of limits.h
if the system has its own version of limits.h. */
/* We use _GCC_LIMITS_H_ because we want this not to match
any macros that the system's limits.h uses for its own purposes. */
#ifndef _GCC_LIMITS_H_ /* Terminated in limity.h. */
#define _GCC_LIMITS_H_
#ifndef _LIMITS_H___
#define _LIMITS_H___
/* Number of bits in a `char'. */
#undef CHAR_BIT
#define CHAR_BIT __CHAR_BIT__
/* Maximum length of a multibyte character. */
#ifndef MB_LEN_MAX
#define MB_LEN_MAX 1
#endif
/* Minimum and maximum values a `signed char' can hold. */
#undef SCHAR_MIN
#define SCHAR_MIN (-SCHAR_MAX - 1)
#undef SCHAR_MAX
#define SCHAR_MAX __SCHAR_MAX__
/* Maximum value an `unsigned char' can hold. (Minimum is 0). */
#undef UCHAR_MAX
#if __SCHAR_MAX__ == __INT_MAX__
# define UCHAR_MAX (SCHAR_MAX * 2U + 1U)
#else
# define UCHAR_MAX (SCHAR_MAX * 2 + 1)
#endif
/* Minimum and maximum values a `char' can hold. */
#ifdef __CHAR_UNSIGNED__
# undef CHAR_MIN
# if __SCHAR_MAX__ == __INT_MAX__
# define CHAR_MIN 0U
# else
# define CHAR_MIN 0
# endif
# undef CHAR_MAX
# define CHAR_MAX UCHAR_MAX
#else
# undef CHAR_MIN
# define CHAR_MIN SCHAR_MIN
# undef CHAR_MAX
# define CHAR_MAX SCHAR_MAX
#endif
/* Minimum and maximum values a `signed short int' can hold. */
#undef SHRT_MIN
#define SHRT_MIN (-SHRT_MAX - 1)
#undef SHRT_MAX
#define SHRT_MAX __SHRT_MAX__
/* Maximum value an `unsigned short int' can hold. (Minimum is 0). */
#undef USHRT_MAX
#if __SHRT_MAX__ == __INT_MAX__
# define USHRT_MAX (SHRT_MAX * 2U + 1U)
#else
# define USHRT_MAX (SHRT_MAX * 2 + 1)
#endif
/* Minimum and maximum values a `signed int' can hold. */
#undef INT_MIN
#define INT_MIN (-INT_MAX - 1)
#undef INT_MAX
#define INT_MAX __INT_MAX__
/* Maximum value an `unsigned int' can hold. (Minimum is 0). */
#undef UINT_MAX
#define UINT_MAX (INT_MAX * 2U + 1U)
/* Minimum and maximum values a `signed long int' can hold.
(Same as `int'). */
#undef LONG_MIN
#define LONG_MIN (-LONG_MAX - 1L)
#undef LONG_MAX
#define LONG_MAX __LONG_MAX__
/* Maximum value an `unsigned long int' can hold. (Minimum is 0). */
#undef ULONG_MAX
#define ULONG_MAX (LONG_MAX * 2UL + 1UL)
#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
/* Minimum and maximum values a `signed long long int' can hold. */
# undef LLONG_MIN
# define LLONG_MIN (-LLONG_MAX - 1LL)
# undef LLONG_MAX
# define LLONG_MAX __LONG_LONG_MAX__
/* Maximum value an `unsigned long long int' can hold. (Minimum is 0). */
# undef ULLONG_MAX
# define ULLONG_MAX (LLONG_MAX * 2ULL + 1ULL)
#endif
#if defined (__GNU_LIBRARY__) ? defined (__USE_GNU) : !defined (__STRICT_ANSI__)
/* Minimum and maximum values a `signed long long int' can hold. */
# undef LONG_LONG_MIN
# define LONG_LONG_MIN (-LONG_LONG_MAX - 1LL)
# undef LONG_LONG_MAX
# define LONG_LONG_MAX __LONG_LONG_MAX__
/* Maximum value an `unsigned long long int' can hold. (Minimum is 0). */
# undef ULONG_LONG_MAX
# define ULONG_LONG_MAX (LONG_LONG_MAX * 2ULL + 1ULL)
#endif
#endif /* _LIMITS_H___ */
/* This administrivia gets added to the end of limits.h
if the system has its own version of limits.h. */
#else /* not _GCC_LIMITS_H_ */
#ifdef _GCC_NEXT_LIMITS_H
#include_next <limits.h> /* recurse down to the real one */
#endif
#endif /* not _GCC_LIMITS_H_ */

View File

@ -0,0 +1,269 @@
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __LIST_H
#define __LIST_H
#include <sys/types.h>
#define containerof(ptr, type, member) \
((type *)((addr_t)(ptr) - offsetof(type, member)))
struct list_node {
struct list_node *prev;
struct list_node *next;
};
#define LIST_INITIAL_VALUE(list) { &(list), &(list) }
static inline void list_initialize(struct list_node *list)
{
list->prev = list->next = list;
}
static inline void list_clear_node(struct list_node *item)
{
item->prev = item->next = 0;
}
static inline bool list_in_list(struct list_node *item)
{
if (item->prev == 0 && item->next == 0)
return false;
else
return true;
}
static inline void list_add_head(struct list_node *list, struct list_node *item)
{
item->next = list->next;
item->prev = list;
list->next->prev = item;
list->next = item;
}
#define list_add_after(entry, new_entry) list_add_head(entry, new_entry)
static inline void list_add_tail(struct list_node *list, struct list_node *item)
{
item->prev = list->prev;
item->next = list;
list->prev->next = item;
list->prev = item;
}
#define list_add_before(entry, new_entry) list_add_tail(entry, new_entry)
static inline void list_delete(struct list_node *item)
{
item->next->prev = item->prev;
item->prev->next = item->next;
item->prev = item->next = 0;
}
static inline struct list_node* list_remove_head(struct list_node *list)
{
if(list->next != list) {
struct list_node *item = list->next;
list_delete(item);
return item;
} else {
return NULL;
}
}
#define list_remove_head_type(list, type, element) ({\
struct list_node *__nod = list_remove_head(list);\
type *__t;\
if(__nod)\
__t = containerof(__nod, type, element);\
else\
__t = (type *)0;\
__t;\
})
static inline struct list_node* list_remove_tail(struct list_node *list)
{
if(list->prev != list) {
struct list_node *item = list->prev;
list_delete(item);
return item;
} else {
return NULL;
}
}
#define list_remove_tail_type(list, type, element) ({\
struct list_node *__nod = list_remove_tail(list);\
type *__t;\
if(__nod)\
__t = containerof(__nod, type, element);\
else\
__t = (type *)0;\
__t;\
})
static inline struct list_node* list_peek_head(struct list_node *list)
{
if(list->next != list) {
return list->next;
} else {
return NULL;
}
}
#define list_peek_head_type(list, type, element) ({\
struct list_node *__nod = list_peek_head(list);\
type *__t;\
if(__nod)\
__t = containerof(__nod, type, element);\
else\
__t = (type *)0;\
__t;\
})
static inline struct list_node* list_peek_tail(struct list_node *list)
{
if(list->prev != list) {
return list->prev;
} else {
return NULL;
}
}
#define list_peek_tail_type(list, type, element) ({\
struct list_node *__nod = list_peek_tail(list);\
type *__t;\
if(__nod)\
__t = containerof(__nod, type, element);\
else\
__t = (type *)0;\
__t;\
})
static inline struct list_node* list_prev(struct list_node *list, struct list_node *item)
{
if(item->prev != list)
return item->prev;
else
return NULL;
}
#define list_prev_type(list, item, type, element) ({\
struct list_node *__nod = list_prev(list, item);\
type *__t;\
if(__nod)\
__t = containerof(__nod, type, element);\
else\
__t = (type *)0;\
__t;\
})
static inline struct list_node* list_prev_wrap(struct list_node *list, struct list_node *item)
{
if(item->prev != list)
return item->prev;
else if(item->prev->prev != list)
return item->prev->prev;
else
return NULL;
}
#define list_prev_wrap_type(list, item, type, element) ({\
struct list_node *__nod = list_prev_wrap(list, item);\
type *__t;\
if(__nod)\
__t = containerof(__nod, type, element);\
else\
__t = (type *)0;\
__t;\
})
static inline struct list_node* list_next(struct list_node *list, struct list_node *item)
{
if(item->next != list)
return item->next;
else
return NULL;
}
#define list_next_type(list, item, type, element) ({\
struct list_node *__nod = list_next(list, item);\
type *__t;\
if(__nod)\
__t = containerof(__nod, type, element);\
else\
__t = (type *)0;\
__t;\
})
static inline struct list_node* list_next_wrap(struct list_node *list, struct list_node *item)
{
if(item->next != list)
return item->next;
else if(item->next->next != list)
return item->next->next;
else
return NULL;
}
#define list_next_wrap_type(list, item, type, element) ({\
struct list_node *__nod = list_next_wrap(list, item);\
type *__t;\
if(__nod)\
__t = containerof(__nod, type, element);\
else\
__t = (type *)0;\
__t;\
})
// iterates over the list, node should be struct list_node*
#define list_for_every(list, node) \
for(node = (list)->next; node != (list); node = node->next)
// iterates over the list in a safe way for deletion of current node
// node and temp_node should be struct list_node*
#define list_for_every_safe(list, node, temp_node) \
for(node = (list)->next, temp_node = (node)->next;\
node != (list);\
node = temp_node, temp_node = (node)->next)
// iterates over the list, entry should be the container structure type *
#define list_for_every_entry(list, entry, type, member) \
for((entry) = containerof((list)->next, type, member);\
&(entry)->member != (list);\
(entry) = containerof((entry)->member.next, type, member))
// iterates over the list in a safe way for deletion of current node
// entry and temp_entry should be the container structure type *
#define list_for_every_entry_safe(list, entry, temp_entry, type, member) \
for(entry = containerof((list)->next, type, member),\
temp_entry = containerof((entry)->member.next, type, member);\
&(entry)->member != (list);\
entry = temp_entry, temp_entry = containerof((temp_entry)->member.next, type, member))
static inline bool list_is_empty(struct list_node *list)
{
return (list->next == list) ? true : false;
}
#endif

View File

@ -0,0 +1,44 @@
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __MALLOC_H
#define __MALLOC_H
#include <sys/types.h>
#include <compiler.h>
#if defined(__cplusplus)
extern "C" {
#endif
void *malloc(size_t size) __MALLOC;
void *memalign(size_t boundary, size_t size) __MALLOC;
void *calloc(size_t count, size_t size) __MALLOC;
void free(void *ptr);
void *realloc(void *ptr, size_t size);
#if defined(__cplusplus)
}
#endif
#endif

View File

@ -0,0 +1,35 @@
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __NEW_H
#define __NEW_H
#include <sys/types.h>
void *operator new(size_t);
void *operator new(size_t, void *ptr);
void *operator new[](size_t);
void *operator new[](size_t, void *ptr);
void operator delete(void *p);
void operator delete[](void *p);
#endif

View File

@ -0,0 +1,55 @@
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __PLATFORM_H
#define __PLATFORM_H
#define PA(x) platform_get_virt_to_phys_mapping(x)
#define VA(x) platform_get_phys_to_virt_mapping(x)
time_t current_time(void);
bigtime_t current_time_hires(void);
/* super early platform initialization, before almost everything */
void platform_early_init(void);
/* later init, after the kernel has come up */
void platform_init(void);
/* called by the arch init code to get the platform to set up any mmu mappings it may need */
int platform_use_identity_mmu_mappings(void);
void platform_init_mmu_mappings(void);
addr_t platform_get_virt_to_phys_mapping(addr_t virt_addr);
addr_t platform_get_phys_to_virt_mapping(addr_t phys_addr);
void display_init(void);
void display_shutdown(void);
void display_image_on_screen(void);
unsigned board_machtype(void);
unsigned board_platform_id(void);
unsigned check_reboot_mode(void);
void platform_uninit_timer(void);
void reboot_device(unsigned);
int set_download_mode(void);
#endif

View File

@ -0,0 +1,50 @@
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __PLATFORM_DEBUG_H
#define __PLATFORM_DEBUG_H
#include <sys/types.h>
#include <stdarg.h>
#include <compiler.h>
#if defined(__cplusplus)
extern "C" {
#endif
void debug_dump_regs(void);
void debug_dump_memory_bytes(void *mem, int len);
void debug_dump_memory_halfwords(void *mem, int len);
void debug_dump_memory_words(void *mem, int len);
void debug_set_trace_level(int trace_type, int level);
void platform_halt(void);
#if defined(__cplusplus)
}
#endif
#endif

View File

@ -0,0 +1,35 @@
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __PLATFORM_INTERRUPTS_H
#define __PLATFORM_INTERRUPTS_H
#include <sys/types.h>
status_t mask_interrupt(unsigned int vector);
status_t unmask_interrupt(unsigned int vector);
typedef enum handler_return (*int_handler)(void *arg);
void register_int_handler(unsigned int vector, int_handler handler, void *arg);
#endif

View File

@ -0,0 +1,37 @@
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __PLATFORM_TIMER_H
#define __PLATFORM_TIMER_H
typedef enum handler_return (*platform_timer_callback)(void *arg, time_t now);
status_t platform_set_periodic_timer(platform_timer_callback callback, void *arg, time_t interval);
void mdelay(unsigned msecs);
void udelay(unsigned usecs);
uint32_t platform_tick_rate(void);
#endif

View File

@ -0,0 +1,60 @@
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __POW2_H
#define __POW2_H
#include <sys/types.h>
#include <compiler.h>
/* routines for dealing with power of 2 values for efficiency */
static inline __ALWAYS_INLINE bool ispow2(uint val)
{
return ((val - 1) & val) == 0;
}
static inline __ALWAYS_INLINE uint log2(uint val)
{
if (!ispow2(val))
return 0; // undefined
return __builtin_ctz(val);
}
static inline __ALWAYS_INLINE uint valpow2(uint valp2)
{
return 1 << valp2;
}
static inline __ALWAYS_INLINE uint divpow2(uint val, uint divp2)
{
return val >> divp2;
}
static inline __ALWAYS_INLINE uint modpow2(uint val, uint modp2)
{
return val & ((1UL << modp2) - 1);
}
#endif

View File

@ -0,0 +1,44 @@
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __LIB_PRINTF_H
#define __LIB_PRINTF_H
#include <stdarg.h>
#include <compiler.h>
#include <debug.h>
#if defined(__cplusplus)
extern "C" {
#endif
int printf(const char *fmt, ...);
int sprintf(char *str, const char *fmt, ...) __PRINTFLIKE(2, 3);
int snprintf(char *str, size_t len, const char *fmt, ...) __PRINTFLIKE(3, 4);
int vsprintf(char *str, const char *fmt, va_list ap);
int vsnprintf(char *str, size_t len, const char *fmt, va_list ap);
#if defined(__cplusplus)
}
#endif
#endif

View File

@ -0,0 +1,29 @@
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __RAND_H
#define __RAND_H
int rand(void);
#endif

View File

@ -0,0 +1,47 @@
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __REG_H
#define __REG_H
#include <sys/types.h>
/* low level macros for accessing memory mapped hardware registers */
#define REG64(addr) ((volatile uint64_t *)(addr))
#define REG32(addr) ((volatile uint32_t *)(addr))
#define REG16(addr) ((volatile uint16_t *)(addr))
#define REG8(addr) ((volatile uint8_t *)(addr))
#define RMWREG64(addr, startbit, width, val) *REG64(addr) = (*REG64(addr) & ~(((1<<(width)) - 1) << (startbit))) | ((val) << (startbit))
#define RMWREG32(addr, startbit, width, val) *REG32(addr) = (*REG32(addr) & ~(((1<<(width)) - 1) << (startbit))) | ((val) << (startbit))
#define RMWREG16(addr, startbit, width, val) *REG16(addr) = (*REG16(addr) & ~(((1<<(width)) - 1) << (startbit))) | ((val) << (startbit))
#define RMWREG8(addr, startbit, width, val) *REG8(addr) = (*REG8(addr) & ~(((1<<(width)) - 1) << (startbit))) | ((val) << (startbit))
#define writel(v, a) (*REG32(a) = (v))
#define readl(a) (*REG32(a))
#define writeb(v, a) (*REG8(a) = (v))
#define readb(a) (*REG8(a))
#define writehw(v, a) (*REG16(a) = (v))
#define readhw(a) (*REG16(a))
#endif

View File

@ -0,0 +1,60 @@
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __STDINT_H
#define __STDINT_H
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long long uint64_t;
typedef signed char int8_t;
typedef short int16_t;
typedef int int32_t;
typedef long long int64_t;
typedef int8_t int_least8_t;
typedef int16_t int_least16_t;
typedef int32_t int_least32_t;
typedef int64_t int_least64_t;
typedef uint8_t uint_least8_t;
typedef uint16_t uint_least16_t;
typedef uint32_t uint_least32_t;
typedef uint64_t uint_least64_t;
typedef int8_t int_fast8_t;
typedef int16_t int_fast16_t;
typedef int32_t int_fast32_t;
typedef int64_t int_fast64_t;
typedef uint8_t uint_fast8_t;
typedef uint16_t uint_fast16_t;
typedef uint32_t uint_fast32_t;
typedef uint64_t uint_fast64_t;
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long long intmax_t;
typedef unsigned long long uintmax_t;
#endif

View File

@ -0,0 +1,12 @@
#ifndef __STDIO_H
#define __STDIO_H
#include <debug.h>
#include <printf.h>
void putc(char c);
int puts(const char *str);
int getc(char *c); // XXX not really getc
#endif

View File

@ -0,0 +1,61 @@
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* Copyright (c) 2013, The Linux Foundation. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __STDLIB_H
#define __STDLIB_H
#include <sys/types.h>
#include <stddef.h>
#include <malloc.h>
#include <printf.h>
#include <endian.h>
#include <arch/defines.h>
unsigned gcd(unsigned m, unsigned n);
unsigned lcm(unsigned m, unsigned n);
int atoi(const char *num);
unsigned int atoui(const char *num);
long atol(const char *num);
unsigned long atoul(const char *num);
int itoa(int num, unsigned char* str, int len, int base);
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#define ROUNDUP(a, b) (((a) + ((b)-1)) & ~((b)-1))
#define ROUNDDOWN(a, b) ((a) & ~((b)-1))
/* allocate a buffer on the stack aligned and padded to the cpu's cache line size */
#define STACKBUF_DMA_ALIGN(var, size) \
uint8_t __##var[(size) + CACHE_LINE]; uint8_t *var = (uint8_t *)(ROUNDUP((addr_t)__##var, CACHE_LINE))
/* Macro to allocate buffer in both local & global space, the STACKBUF_DMA_ALIGN cannot
* be used for global space.
* If we use STACKBUF_DMA_ALIGN 'C' compiler throws the error "Initializer element
* is not constant", since global variable need to be initialized with a constant value.
*/
#define BUF_DMA_ALIGN(var, size) \
static uint8_t var[ROUNDUP(size, CACHE_LINE)] __attribute__((aligned(CACHE_LINE)));
#endif

View File

@ -0,0 +1,81 @@
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __LIB_STRING_H
#define __LIB_STRING_H
#include <sys/types.h>
#include <compiler.h>
#ifdef __cplusplus
extern "C" {
#endif
void *memchr (void const *, int, size_t) __PURE;
int memcmp (void const *, const void *, size_t) __PURE;
void *memcpy (void *, void const *, size_t);
void *memmove(void *, void const *, size_t);
void *memset (void *, int, size_t);
char *strcat(char *, char const *);
char *strchr(char const *, int) __PURE;
int strcmp(char const *, char const *) __PURE;
char *strcpy(char *, char const *);
char const *strerror(int) __CONST;
size_t strlen(char const *) __PURE;
char *strncat(char *, char const *, size_t);
int strncmp(char const *, char const *, size_t) __PURE;
char *strncpy(char *, char const *, size_t);
char *strpbrk(char const *, char const *) __PURE;
char *strrchr(char const *, int) __PURE;
size_t strspn(char const *, char const *) __PURE;
size_t strcspn(const char *s, const char *) __PURE;
char *strstr(char const *, char const *) __PURE;
char *strtok(char *, char const *);
int strcoll(const char *s1, const char *s2) __PURE;
size_t strxfrm(char *dest, const char *src, size_t n) __PURE;
char *strdup(const char *str) __MALLOC;
void strrev(unsigned char *str) __PURE;
#ifdef __cplusplus
} /* extern "C" */
#endif
#ifdef __cplusplus
extern "C"
{
#endif
/* non standard */
void *bcopy(void const *, void *, size_t);
void bzero(void *, size_t);
size_t strlcat(char *, char const *, size_t);
size_t strlcpy(char *, char const *, size_t);
int strncasecmp(char const *, char const *, size_t) __PURE;
int strnicmp(char const *, char const *, size_t) __PURE;
size_t strnlen(char const *s, size_t count) __PURE;
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,75 @@
/*
* Copyright (c) 2008-2009 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __SYS_TYPES_H
#define __SYS_TYPES_H
#ifndef __cplusplus
#define false 0
#define true 1
typedef int bool;
#endif
#include <stddef.h>
#include <limits.h>
#include <stdint.h>
typedef unsigned char uchar;
typedef unsigned short ushort;
typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned char u_char;
typedef unsigned short u_short;
typedef unsigned int u_int;
typedef unsigned long u_long;
#ifndef _SIZE_T_DEFINED_
typedef unsigned long size_t;
#endif
typedef long ssize_t;
typedef long long off_t;
typedef int status_t;
typedef uintptr_t addr_t;
typedef uintptr_t vaddr_t;
typedef uintptr_t paddr_t;
typedef int kobj_id;
typedef unsigned long time_t;
typedef unsigned long long bigtime_t;
#define INFINITE_TIME ULONG_MAX
#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
#define TIME_GTE(a, b) ((long)((a) - (b)) >= 0)
#define TIME_LTE(a, b) ((long)((a) - (b)) <= 0)
#define TIME_GT(a, b) ((long)((a) - (b)) > 0)
#define TIME_LT(a, b) ((long)((a) - (b)) < 0)
enum handler_return {
INT_NO_RESCHEDULE = 0,
INT_RESCHEDULE,
};
#endif

View File

@ -0,0 +1,52 @@
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* Copyright (c) 2013, The Linux Foundation. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __TARGET_H
#define __TARGET_H
/* super early platform initialization, before almost everything */
void target_early_init(void);
/* later init, after the kernel has come up */
void target_init(void);
/* get memory address for fastboot image loading */
void *target_get_scratch_address(void);
/* get the max allowed flash size */
unsigned target_get_max_flash_size(void);
/* if target is using eMMC bootup */
int target_is_emmc_boot(void);
unsigned* target_atag_mem(unsigned* ptr);
void target_battery_charging_enable(unsigned enable, unsigned disconnect);
unsigned target_pause_for_battery_charge(void);
unsigned target_baseband(void);
void target_serialno(unsigned char *buf);
void target_fastboot_init(void);
struct mmc_device *target_mmc_device();
#endif