2003-02-07 09:41:57 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 by Alan Korr
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2003-02-07 09:41:57 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __SYSTEM_H__
|
|
|
|
#define __SYSTEM_H__
|
|
|
|
|
2004-10-06 13:49:48 +00:00
|
|
|
#include "cpu.h"
|
2005-03-01 14:35:10 +00:00
|
|
|
#include "stdbool.h"
|
2007-03-10 12:41:52 +00:00
|
|
|
#include "kernel.h"
|
2003-02-07 09:41:57 +00:00
|
|
|
|
2004-02-25 13:00:36 +00:00
|
|
|
extern void system_reboot (void);
|
2009-01-08 10:15:32 +00:00
|
|
|
/* Called from any UIE handler and panicf - wait for a key and return
|
|
|
|
* to reboot system. */
|
|
|
|
extern void system_exception_wait(void);
|
2004-02-25 13:00:36 +00:00
|
|
|
extern void system_init(void);
|
|
|
|
|
2005-03-01 14:35:10 +00:00
|
|
|
extern long cpu_frequency;
|
|
|
|
|
2006-08-05 20:19:10 +00:00
|
|
|
struct flash_header {
|
|
|
|
unsigned long magic;
|
|
|
|
unsigned long length;
|
|
|
|
char version[32];
|
|
|
|
};
|
|
|
|
|
2007-01-12 18:34:00 +00:00
|
|
|
bool detect_flashed_romimage(void);
|
|
|
|
bool detect_flashed_ramimage(void);
|
|
|
|
bool detect_original_firmware(void);
|
2006-08-05 20:19:10 +00:00
|
|
|
|
2007-01-22 10:41:25 +00:00
|
|
|
#if defined(HAVE_ADJUSTABLE_CPU_FREQ) \
|
2007-03-26 16:55:17 +00:00
|
|
|
&& defined(ROCKBOX_HAS_LOGF) && (NUM_CORES == 1)
|
2007-01-22 10:41:25 +00:00
|
|
|
#define CPU_BOOST_LOGGING
|
|
|
|
#endif
|
|
|
|
|
2005-03-01 14:35:10 +00:00
|
|
|
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
2007-10-16 01:25:17 +00:00
|
|
|
#if NUM_CORES > 1
|
|
|
|
extern struct spinlock boostctrl_spin;
|
|
|
|
#endif
|
|
|
|
void cpu_boost_init(void);
|
2005-03-01 14:35:10 +00:00
|
|
|
#define FREQ cpu_frequency
|
2005-03-03 16:29:02 +00:00
|
|
|
void set_cpu_frequency(long frequency);
|
2007-01-22 10:41:25 +00:00
|
|
|
#ifdef CPU_BOOST_LOGGING
|
|
|
|
char * cpu_boost_log_getlog_first(void);
|
|
|
|
char * cpu_boost_log_getlog_next(void);
|
|
|
|
int cpu_boost_log_getcount(void);
|
|
|
|
void cpu_boost_(bool on_off, char* location, int line);
|
|
|
|
#else
|
2005-03-03 16:29:02 +00:00
|
|
|
void cpu_boost(bool on_off);
|
2007-01-22 10:41:25 +00:00
|
|
|
#endif
|
2005-07-05 07:58:19 +00:00
|
|
|
void cpu_idle_mode(bool on_off);
|
2006-10-05 10:07:03 +00:00
|
|
|
int get_cpu_boost_counter(void);
|
2005-03-01 14:35:10 +00:00
|
|
|
#else
|
2003-02-07 09:41:57 +00:00
|
|
|
#define FREQ CPU_FREQ
|
2005-09-12 10:34:27 +00:00
|
|
|
#define set_cpu_frequency(frequency)
|
2007-01-22 10:58:40 +00:00
|
|
|
#define cpu_boost(on_off)
|
2006-10-05 10:07:03 +00:00
|
|
|
#define cpu_boost_id(on_off, id)
|
2005-07-05 07:58:19 +00:00
|
|
|
#define cpu_idle_mode(on_off)
|
2006-10-05 10:07:03 +00:00
|
|
|
#define get_cpu_boost_counter()
|
|
|
|
#define get_cpu_boost_tracker()
|
2005-03-01 14:35:10 +00:00
|
|
|
#endif
|
2005-03-03 16:29:02 +00:00
|
|
|
|
2007-01-22 10:41:25 +00:00
|
|
|
#ifdef CPU_BOOST_LOGGING
|
|
|
|
#define cpu_boost(on_off) cpu_boost_(on_off,__FILE__, __LINE__)
|
|
|
|
#endif
|
|
|
|
|
2003-02-07 09:41:57 +00:00
|
|
|
#define BAUDRATE 9600
|
|
|
|
|
|
|
|
#ifndef NULL
|
|
|
|
#define NULL ((void*)0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef MIN
|
|
|
|
#define MIN(a, b) (((a)<(b))?(a):(b))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef MAX
|
|
|
|
#define MAX(a, b) (((a)>(b))?(a):(b))
|
|
|
|
#endif
|
|
|
|
|
2006-11-06 18:07:30 +00:00
|
|
|
/* return number of elements in array a */
|
|
|
|
#define ARRAYLEN(a) (sizeof(a)/sizeof((a)[0]))
|
|
|
|
|
|
|
|
/* return p incremented by specified number of bytes */
|
|
|
|
#define SKIPBYTES(p, count) ((typeof (p))((char *)(p) + (count)))
|
|
|
|
|
|
|
|
#define P2_M1(p2) ((1 << (p2))-1)
|
|
|
|
|
|
|
|
/* align up or down to nearest 2^p2 */
|
|
|
|
#define ALIGN_DOWN_P2(n, p2) ((n) & ~P2_M1(p2))
|
|
|
|
#define ALIGN_UP_P2(n, p2) ALIGN_DOWN_P2((n) + P2_M1(p2),p2)
|
|
|
|
|
|
|
|
/* align up or down to nearest integer multiple of a */
|
|
|
|
#define ALIGN_DOWN(n, a) ((n)/(a)*(a))
|
|
|
|
#define ALIGN_UP(n, a) ALIGN_DOWN((n)+((a)-1),a)
|
|
|
|
|
2009-01-13 13:48:26 +00:00
|
|
|
/* align start and end of buffer to nearest integer multiple of a */
|
|
|
|
#define ALIGN_BUFFER(ptr,len,align) \
|
|
|
|
{\
|
|
|
|
uintptr_t tmp_ptr1 = (uintptr_t)ptr; \
|
|
|
|
uintptr_t tmp_ptr2 = tmp_ptr1 + len;\
|
|
|
|
tmp_ptr1 = ALIGN_UP(tmp_ptr1,align); \
|
|
|
|
tmp_ptr2 = ALIGN_DOWN(tmp_ptr2,align); \
|
|
|
|
len = tmp_ptr2 - tmp_ptr1; \
|
|
|
|
ptr = (typeof(ptr))tmp_ptr1; \
|
|
|
|
}
|
|
|
|
|
2009-09-01 14:53:37 +00:00
|
|
|
#ifndef __PCTOOL__
|
|
|
|
|
2009-01-24 10:16:22 +00:00
|
|
|
/* newer? SDL includes endian.h, So we ignore it */
|
|
|
|
#ifdef SIMULATOR
|
|
|
|
#undef letoh16
|
|
|
|
#undef letoh32
|
|
|
|
#undef htole16
|
|
|
|
#undef htole32
|
|
|
|
#undef betoh16
|
|
|
|
#undef betoh32
|
|
|
|
#undef htobe16
|
|
|
|
#undef htobe32
|
|
|
|
#endif
|
|
|
|
|
2006-11-06 18:07:30 +00:00
|
|
|
/* live endianness conversion */
|
2005-05-07 22:41:17 +00:00
|
|
|
#ifdef ROCKBOX_LITTLE_ENDIAN
|
2005-10-06 19:27:43 +00:00
|
|
|
#define letoh16(x) (x)
|
|
|
|
#define letoh32(x) (x)
|
|
|
|
#define htole16(x) (x)
|
|
|
|
#define htole32(x) (x)
|
|
|
|
#define betoh16(x) swap16(x)
|
|
|
|
#define betoh32(x) swap32(x)
|
|
|
|
#define htobe16(x) swap16(x)
|
|
|
|
#define htobe32(x) swap32(x)
|
2006-11-06 18:07:30 +00:00
|
|
|
#define swap_odd_even_be32(x) (x)
|
|
|
|
#define swap_odd_even_le32(x) swap_odd_even32(x)
|
2006-08-21 17:35:35 +00:00
|
|
|
#else
|
2005-10-06 19:27:43 +00:00
|
|
|
#define letoh16(x) swap16(x)
|
|
|
|
#define letoh32(x) swap32(x)
|
|
|
|
#define htole16(x) swap16(x)
|
|
|
|
#define htole32(x) swap32(x)
|
|
|
|
#define betoh16(x) (x)
|
|
|
|
#define betoh32(x) (x)
|
|
|
|
#define htobe16(x) (x)
|
|
|
|
#define htobe32(x) (x)
|
2006-11-06 18:07:30 +00:00
|
|
|
#define swap_odd_even_be32(x) swap_odd_even32(x)
|
|
|
|
#define swap_odd_even_le32(x) (x)
|
|
|
|
#endif
|
|
|
|
|
2009-09-01 14:53:37 +00:00
|
|
|
#endif
|
|
|
|
|
2006-11-06 18:07:30 +00:00
|
|
|
/* static endianness conversion */
|
|
|
|
#define SWAP_16(x) ((typeof(x))(unsigned short)(((unsigned short)(x) >> 8) | \
|
|
|
|
((unsigned short)(x) << 8)))
|
|
|
|
|
|
|
|
#define SWAP_32(x) ((typeof(x))(unsigned long)( ((unsigned long)(x) >> 24) | \
|
|
|
|
(((unsigned long)(x) & 0xff0000ul) >> 8) | \
|
|
|
|
(((unsigned long)(x) & 0xff00ul) << 8) | \
|
|
|
|
((unsigned long)(x) << 24)))
|
|
|
|
|
|
|
|
#ifdef ROCKBOX_LITTLE_ENDIAN
|
|
|
|
#define LE_TO_H16(x) (x)
|
|
|
|
#define LE_TO_H32(x) (x)
|
|
|
|
#define H_TO_LE16(x) (x)
|
|
|
|
#define H_TO_LE32(x) (x)
|
|
|
|
#define BE_TO_H16(x) SWAP_16(x)
|
|
|
|
#define BE_TO_H32(x) SWAP_32(x)
|
|
|
|
#define H_TO_BE16(x) SWAP_16(x)
|
|
|
|
#define H_TO_BE32(x) SWAP_32(x)
|
|
|
|
#else
|
|
|
|
#define LE_TO_H16(x) SWAP_16(x)
|
|
|
|
#define LE_TO_H32(x) SWAP_32(x)
|
|
|
|
#define H_TO_LE16(x) SWAP_16(x)
|
|
|
|
#define H_TO_LE32(x) SWAP_32(x)
|
|
|
|
#define BE_TO_H16(x) (x)
|
|
|
|
#define BE_TO_H32(x) (x)
|
|
|
|
#define H_TO_BE16(x) (x)
|
|
|
|
#define H_TO_BE32(x) (x)
|
2003-02-07 09:41:57 +00:00
|
|
|
#endif
|
|
|
|
|
2008-03-25 02:34:12 +00:00
|
|
|
/* Get the byte offset of a type's member */
|
|
|
|
#define OFFSETOF(type, membername) ((off_t)&((type *)0)->membername)
|
|
|
|
|
|
|
|
/* Get the type pointer from one of its members */
|
|
|
|
#define TYPE_FROM_MEMBER(type, memberptr, membername) \
|
|
|
|
((type *)((intptr_t)(memberptr) - OFFSETOF(type, membername)))
|
|
|
|
|
2008-11-20 20:20:43 +00:00
|
|
|
/* Use to give gcc hints on which branch is most likely taken */
|
|
|
|
#if defined(__GNUC__) && __GNUC__ >= 3
|
2008-11-22 16:56:20 +00:00
|
|
|
#define LIKELY(x) __builtin_expect(!!(x), 1)
|
|
|
|
#define UNLIKELY(x) __builtin_expect(!!(x), 0)
|
2008-11-20 20:20:43 +00:00
|
|
|
#else
|
2008-11-22 16:56:20 +00:00
|
|
|
#define LIKELY(x) (x)
|
|
|
|
#define UNLIKELY(x) (x)
|
2008-11-20 20:20:43 +00:00
|
|
|
#endif
|
|
|
|
|
2008-03-25 02:34:12 +00:00
|
|
|
/* returns index of first set bit + 1 or 0 if no bits are set */
|
|
|
|
int find_first_set_bit(uint32_t val);
|
|
|
|
|
|
|
|
static inline __attribute__((always_inline))
|
|
|
|
uint32_t isolate_first_bit(uint32_t val)
|
|
|
|
{ return val & -val; }
|
|
|
|
|
2004-07-24 11:39:17 +00:00
|
|
|
/* gcc 3.4 changed the format of the constraints */
|
2005-04-22 19:34:01 +00:00
|
|
|
#if (__GNUC__ >= 3) && (__GNUC_MINOR__ > 3) || (__GNUC__ >= 4)
|
2004-07-24 11:39:17 +00:00
|
|
|
#define I_CONSTRAINT "I08"
|
|
|
|
#else
|
|
|
|
#define I_CONSTRAINT "I"
|
|
|
|
#endif
|
|
|
|
|
2005-02-02 21:45:56 +00:00
|
|
|
/* Utilize the user break controller to catch invalid memory accesses. */
|
|
|
|
int system_memory_guard(int newmode);
|
|
|
|
|
|
|
|
enum {
|
|
|
|
MEMGUARD_KEEP = -1, /* don't change the mode; for reading */
|
|
|
|
MEMGUARD_NONE = 0, /* catch nothing */
|
|
|
|
MEMGUARD_FLASH_WRITES, /* catch writes to area 02 (flash ROM) */
|
|
|
|
MEMGUARD_ZERO_AREA, /* catch all accesses to areas 00 and 01 */
|
|
|
|
MAXMEMGUARD
|
|
|
|
};
|
|
|
|
|
2006-10-30 14:17:14 +00:00
|
|
|
#ifndef SIMULATOR
|
|
|
|
#include "system-target.h"
|
2006-11-06 18:07:30 +00:00
|
|
|
#else /* SIMULATOR */
|
2005-02-09 14:23:35 +00:00
|
|
|
|
2007-03-29 05:30:25 +00:00
|
|
|
static inline uint16_t swap16(uint16_t value)
|
2005-10-06 19:27:43 +00:00
|
|
|
/*
|
|
|
|
result[15..8] = value[ 7..0];
|
|
|
|
result[ 7..0] = value[15..8];
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
return (value >> 8) | (value << 8);
|
|
|
|
}
|
|
|
|
|
2007-03-29 05:30:25 +00:00
|
|
|
static inline uint32_t swap32(uint32_t value)
|
2005-10-06 19:27:43 +00:00
|
|
|
/*
|
|
|
|
result[31..24] = value[ 7.. 0];
|
|
|
|
result[23..16] = value[15.. 8];
|
|
|
|
result[15.. 8] = value[23..16];
|
|
|
|
result[ 7.. 0] = value[31..24];
|
|
|
|
*/
|
|
|
|
{
|
2007-03-29 05:30:25 +00:00
|
|
|
uint32_t hi = swap16(value >> 16);
|
|
|
|
uint32_t lo = swap16(value & 0xffff);
|
2006-03-17 02:45:06 +00:00
|
|
|
return (lo << 16) | hi;
|
2005-10-06 19:27:43 +00:00
|
|
|
}
|
|
|
|
|
2007-03-29 05:30:25 +00:00
|
|
|
static inline uint32_t swap_odd_even32(uint32_t value)
|
2006-11-06 18:07:30 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
result[31..24],[15.. 8] = value[23..16],[ 7.. 0]
|
|
|
|
result[23..16],[ 7.. 0] = value[31..24],[15.. 8]
|
|
|
|
*/
|
2007-03-29 05:30:25 +00:00
|
|
|
uint32_t t = value & 0xff00ff00;
|
2006-11-06 18:07:30 +00:00
|
|
|
return (t >> 8) | ((t ^ value) << 8);
|
|
|
|
}
|
|
|
|
|
2007-04-13 20:55:48 +00:00
|
|
|
#endif /* !SIMULATOR */
|
|
|
|
|
2009-06-06 00:11:41 +00:00
|
|
|
#ifndef BIT_N
|
2009-06-06 00:58:57 +00:00
|
|
|
#define BIT_N(n) (1U << (n))
|
2009-06-06 00:00:58 +00:00
|
|
|
#endif
|
|
|
|
|
2007-05-12 05:20:04 +00:00
|
|
|
/* Declare this as HIGHEST_IRQ_LEVEL if they don't differ */
|
|
|
|
#ifndef DISABLE_INTERRUPTS
|
|
|
|
#define DISABLE_INTERRUPTS HIGHEST_IRQ_LEVEL
|
|
|
|
#endif
|
|
|
|
|
2007-04-13 20:55:48 +00:00
|
|
|
/* Just define these as empty if not declared */
|
2009-02-11 12:55:51 +00:00
|
|
|
#ifdef HAVE_CPUCACHE_INVALIDATE
|
|
|
|
void cpucache_invalidate(void);
|
|
|
|
#else
|
|
|
|
static inline void cpucache_invalidate(void)
|
|
|
|
{
|
|
|
|
}
|
2007-04-13 20:55:48 +00:00
|
|
|
#endif
|
2005-02-09 14:23:35 +00:00
|
|
|
|
2009-02-11 12:55:51 +00:00
|
|
|
#ifdef HAVE_CPUCACHE_FLUSH
|
|
|
|
void cpucache_flush(void);
|
|
|
|
#else
|
|
|
|
static inline void cpucache_flush(void)
|
|
|
|
{
|
|
|
|
}
|
2007-04-13 20:55:48 +00:00
|
|
|
#endif
|
2003-02-07 09:41:57 +00:00
|
|
|
|
2007-11-08 05:17:20 +00:00
|
|
|
#ifdef PROC_NEEDS_CACHEALIGN
|
|
|
|
/* Cache alignment attributes and sizes are enabled */
|
|
|
|
|
|
|
|
/* 2^CACHEALIGN_BITS = the byte size */
|
|
|
|
#define CACHEALIGN_SIZE (1u << CACHEALIGN_BITS)
|
|
|
|
|
|
|
|
#define CACHEALIGN_ATTR __attribute__((aligned(CACHEALIGN_SIZE)))
|
|
|
|
/* Aligns x up to a CACHEALIGN_SIZE boundary */
|
|
|
|
#define CACHEALIGN_UP(x) \
|
|
|
|
((typeof (x))ALIGN_UP_P2((uintptr_t)(x), CACHEALIGN_BITS))
|
|
|
|
/* Aligns x down to a CACHEALIGN_SIZE boundary */
|
|
|
|
#define CACHEALIGN_DOWN(x) \
|
|
|
|
((typeof (x))ALIGN_DOWN_P2((uintptr_t)(x), CACHEALIGN_BITS))
|
|
|
|
/* Aligns at least to the greater of size x or CACHEALIGN_SIZE */
|
2007-12-29 19:46:35 +00:00
|
|
|
#define CACHEALIGN_AT_LEAST_ATTR(x) \
|
|
|
|
__attribute__((aligned(CACHEALIGN_UP(x))))
|
2007-11-08 05:17:20 +00:00
|
|
|
/* Aligns a buffer pointer and size to proper boundaries */
|
|
|
|
#define CACHEALIGN_BUFFER(start, size) \
|
2009-01-13 13:48:26 +00:00
|
|
|
ALIGN_BUFFER((start), (size), CACHEALIGN_SIZE)
|
2007-11-08 05:17:20 +00:00
|
|
|
|
|
|
|
#else /* ndef PROC_NEEDS_CACHEALIGN */
|
|
|
|
|
|
|
|
/* Cache alignment attributes and sizes are not enabled */
|
|
|
|
#define CACHEALIGN_ATTR
|
2007-12-29 19:46:35 +00:00
|
|
|
#define CACHEALIGN_AT_LEAST_ATTR(x) \
|
|
|
|
__attribute__((aligned(x)))
|
2007-11-08 05:17:20 +00:00
|
|
|
#define CACHEALIGN_UP(x) (x)
|
|
|
|
#define CACHEALIGN_DOWN(x) (x)
|
|
|
|
/* Make no adjustments */
|
2009-01-13 13:48:26 +00:00
|
|
|
#define CACHEALIGN_BUFFER(start, size)
|
2007-11-08 05:17:20 +00:00
|
|
|
|
|
|
|
#endif /* PROC_NEEDS_CACHEALIGN */
|
|
|
|
|
2007-12-29 19:46:35 +00:00
|
|
|
/* Double-cast to avoid 'dereferencing type-punned pointer will
|
|
|
|
* break strict aliasing rules' B.S. */
|
|
|
|
#define PUN_PTR(type, p) ((type)(intptr_t)(p))
|
|
|
|
|
2006-11-06 18:07:30 +00:00
|
|
|
#endif /* __SYSTEM_H__ */
|