/*
 * Copyright (c) 2001-2005 Opsycon AB  (www.opsycon.se)
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. 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.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed by Opsycon AB, Sweden.
 * 4. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 _XIAOHU_H_
#define _XIAOHU_H_

#include <machine/endian.h>
#include <pmon/dev/pm8172.h>

/*
 *  Define top of PMON-land. PMON will not use memory above this
 *  address but leave it alone for applications.
 */
//#define PMON_TOP		0x08000000      /* 128MB */

/*
 *  Mapping
 */
#define	IO_OFFSET		0x00000000
#define	PHYS_TO_IOSPACE(x)	(PHYS_TO_UNCACHED(x) + IO_OFFSET)

/*
 *  Note! Both base addresses below are mapped into the same 64M space
 *  but only one is active at a time. Mapping both will cause conflicts.
 */
#define	FLASH_BASE		0x08000000	/* Flash in 68k space */
#define	FLASH_SIZE		0x04000000	/* Flash in 68k space */

#ifdef FLASH_NVRAM
#define	USERFLASH_BASE		(FLASH_BASE+0x20000)	/* Reserve first block for env */
#define	USERFLASH_SIZE		(FLASH_SIZE-0x20000)	/* Flash in 68k space */
#else
#define	USERFLASH_BASE		FLASH_BASE
#define	USERFLASH_SIZE		FLASH_SIZE	/* Flash in 68k space */
#endif
#define	BOOTFLASH_BASE		0x08000000	/* Boot flash in 68k space */
#define	BOOTFLASH_SIZE		0x00080000	/* Boot flash in 68k space */

/*
 *  PCI Bus allocation
 */
#define PCI_MEM_SPACE_BASE	0x0c000000
#define PCI_MEM_SPACE_SIZE	0x08000000	/* 128M */
#define PCI_IO_SPACE_BASE	0x14000000
#define PCI_IO_SPACE_SIZE	0x04000000

#define	ISA_IO_BASE		PCI_IO_BASE

/*
 *  NVRAM definitions.
 */
#ifdef ENV_FLASH
#define	NVRAM_START_ENV	0		/* Offset to start of NVRAM data */
#define NVRAM_SIZE_ENV	32768		/* Bytes available */
#else
#ifdef ENV_MASS
/*
 *  Definitions for environment on mass storage
 */
#define ENV_DEVICE	"/sd0"
#define ENV_DEV_OFFS	0x4			/* Start block number */
#define NVRAM_START_ENV	0			/* Offset to start of NVRAM data */
#define NVRAM_SIZE_ENV	4096			/* Bytes available (must be !power2) */
#define ENV_DEV_SIZE	(NVRAM_SIZE_ENV/512)	/* Number of blocks */
#else
#define	NVRAM_START_ENV	0		/* Offset to start of NVRAM data */
#define NVRAM_SIZE_ENV	(128+114)	/* Bytes available */
#endif
#endif

#ifdef VXWORKS
#define NVRAM_VXWORKS           (NVRAM_BASE + NVRAM_SIZE - 512)
#define NVRAM_VXWORKS_DEFAULT \
"rl(0,0)host:/usr/vw/config/netpc/vxWorks h=90.0.0.3 e=90.0.0.50 u=target"
#endif

/*
 *  Additional environment.
 */
#if defined(AUTOBOOT_DUAL)
#define BOOTIMAGE_A     "-x -w30 /dev/sd0@0x100 root=/dev/scsibd2"      /* image A */
#define BOOTIMAGE_B     "-x -w30 /dev/sd0@0x7cf00 root=/dev/scsibd4"    /* image B */
#define	TGT_DEFENV \
	{"bootstate", "A0", "A0 A1 A2 A3 B0 B1 B2 B3"}
#endif

/*
 *  Bootrom parameters used by "load -u".
 */
#define	BOOTROM_BASE	0xa8000000
#define	BOOTROM_SIZE	(1024 * 512)

/*
 *  Base UART in PM8172 (16C550 compatible).
 */
#define COM1_BASE_ADDR	PHYS_TO_IOSPACE(0x14011800 + 0x00)	/* Com 1 */

#define	NS16550HZ	(24000000/13)
#define nsreg(x)	unsigned char x;
#define NSREG(x)	(x)

#endif /* _XIAOHU_H_ */
