head	1.3;
access;
symbols
	netbsd-11-0-RC4:1.3
	netbsd-11-0-RC3:1.3
	netbsd-11-0-RC2:1.3
	netbsd-11-0-RC1:1.3
	perseant-exfatfs-base-20250801:1.3
	netbsd-11:1.3.0.98
	netbsd-11-base:1.3
	netbsd-10-1-RELEASE:1.3
	perseant-exfatfs-base-20240630:1.3
	perseant-exfatfs:1.3.0.96
	perseant-exfatfs-base:1.3
	netbsd-8-3-RELEASE:1.3
	netbsd-9-4-RELEASE:1.3
	netbsd-10-0-RELEASE:1.3
	netbsd-10-0-RC6:1.3
	netbsd-10-0-RC5:1.3
	netbsd-10-0-RC4:1.3
	netbsd-10-0-RC3:1.3
	netbsd-10-0-RC2:1.3
	thorpej-ifq:1.3.0.94
	thorpej-ifq-base:1.3
	thorpej-altq-separation:1.3.0.92
	thorpej-altq-separation-base:1.3
	netbsd-10-0-RC1:1.3
	netbsd-10:1.3.0.90
	netbsd-10-base:1.3
	bouyer-sunxi-drm:1.3.0.88
	bouyer-sunxi-drm-base:1.3
	netbsd-9-3-RELEASE:1.3
	thorpej-i2c-spi-conf2:1.3.0.86
	thorpej-i2c-spi-conf2-base:1.3
	thorpej-futex2:1.3.0.84
	thorpej-futex2-base:1.3
	thorpej-cfargs2:1.3.0.82
	thorpej-cfargs2-base:1.3
	cjep_sun2x-base1:1.3
	cjep_sun2x:1.3.0.80
	cjep_sun2x-base:1.3
	cjep_staticlib_x-base1:1.3
	netbsd-9-2-RELEASE:1.3
	cjep_staticlib_x:1.3.0.78
	cjep_staticlib_x-base:1.3
	thorpej-i2c-spi-conf:1.3.0.76
	thorpej-i2c-spi-conf-base:1.3
	thorpej-cfargs:1.3.0.74
	thorpej-cfargs-base:1.3
	thorpej-futex:1.3.0.72
	thorpej-futex-base:1.3
	netbsd-9-1-RELEASE:1.3
	bouyer-xenpvh-base2:1.3
	phil-wifi-20200421:1.3
	bouyer-xenpvh-base1:1.3
	phil-wifi-20200411:1.3
	bouyer-xenpvh:1.3.0.70
	bouyer-xenpvh-base:1.3
	is-mlppp:1.3.0.68
	is-mlppp-base:1.3
	phil-wifi-20200406:1.3
	netbsd-8-2-RELEASE:1.3
	ad-namecache-base3:1.3
	netbsd-9-0-RELEASE:1.3
	netbsd-9-0-RC2:1.3
	ad-namecache-base2:1.3
	ad-namecache-base1:1.3
	ad-namecache:1.3.0.66
	ad-namecache-base:1.3
	netbsd-9-0-RC1:1.3
	phil-wifi-20191119:1.3
	netbsd-9:1.3.0.64
	netbsd-9-base:1.3
	phil-wifi-20190609:1.3
	netbsd-8-1-RELEASE:1.3
	netbsd-8-1-RC1:1.3
	isaki-audio2:1.3.0.62
	isaki-audio2-base:1.3
	pgoyette-compat-merge-20190127:1.3
	pgoyette-compat-20190127:1.3
	pgoyette-compat-20190118:1.3
	pgoyette-compat-1226:1.3
	pgoyette-compat-1126:1.3
	pgoyette-compat-1020:1.3
	pgoyette-compat-0930:1.3
	pgoyette-compat-0906:1.3
	netbsd-7-2-RELEASE:1.3
	pgoyette-compat-0728:1.3
	netbsd-8-0-RELEASE:1.3
	phil-wifi:1.3.0.60
	phil-wifi-base:1.3
	pgoyette-compat-0625:1.3
	netbsd-8-0-RC2:1.3
	pgoyette-compat-0521:1.3
	pgoyette-compat-0502:1.3
	pgoyette-compat-0422:1.3
	netbsd-8-0-RC1:1.3
	pgoyette-compat-0415:1.3
	pgoyette-compat-0407:1.3
	pgoyette-compat-0330:1.3
	pgoyette-compat-0322:1.3
	pgoyette-compat-0315:1.3
	netbsd-7-1-2-RELEASE:1.3
	pgoyette-compat:1.3.0.58
	pgoyette-compat-base:1.3
	netbsd-7-1-1-RELEASE:1.3
	tls-maxphys-base-20171202:1.3
	matt-nb8-mediatek:1.3.0.56
	matt-nb8-mediatek-base:1.3
	nick-nhusb-base-20170825:1.3
	perseant-stdc-iso10646:1.3.0.54
	perseant-stdc-iso10646-base:1.3
	netbsd-8:1.3.0.52
	netbsd-8-base:1.3
	prg-localcount2-base3:1.3
	prg-localcount2-base2:1.3
	prg-localcount2-base1:1.3
	prg-localcount2:1.3.0.50
	prg-localcount2-base:1.3
	pgoyette-localcount-20170426:1.3
	bouyer-socketcan-base1:1.3
	jdolecek-ncq:1.3.0.48
	jdolecek-ncq-base:1.3
	pgoyette-localcount-20170320:1.3
	netbsd-7-1:1.3.0.46
	netbsd-7-1-RELEASE:1.3
	netbsd-7-1-RC2:1.3
	nick-nhusb-base-20170204:1.3
	netbsd-7-nhusb-base-20170116:1.3
	bouyer-socketcan:1.3.0.44
	bouyer-socketcan-base:1.3
	pgoyette-localcount-20170107:1.3
	netbsd-7-1-RC1:1.3
	nick-nhusb-base-20161204:1.3
	pgoyette-localcount-20161104:1.3
	netbsd-7-0-2-RELEASE:1.3
	nick-nhusb-base-20161004:1.3
	localcount-20160914:1.3
	netbsd-7-nhusb:1.3.0.42
	netbsd-7-nhusb-base:1.3
	pgoyette-localcount-20160806:1.3
	pgoyette-localcount-20160726:1.3
	pgoyette-localcount:1.3.0.40
	pgoyette-localcount-base:1.3
	nick-nhusb-base-20160907:1.3
	nick-nhusb-base-20160529:1.3
	netbsd-7-0-1-RELEASE:1.3
	nick-nhusb-base-20160422:1.3
	nick-nhusb-base-20160319:1.3
	nick-nhusb-base-20151226:1.3
	netbsd-7-0:1.3.0.38
	netbsd-7-0-RELEASE:1.3
	nick-nhusb-base-20150921:1.3
	netbsd-7-0-RC3:1.3
	netbsd-7-0-RC2:1.3
	netbsd-7-0-RC1:1.3
	nick-nhusb-base-20150606:1.3
	nick-nhusb-base-20150406:1.3
	nick-nhusb:1.3.0.36
	nick-nhusb-base:1.3
	netbsd-5-2-3-RELEASE:1.2
	netbsd-5-1-5-RELEASE:1.2
	netbsd-6-0-6-RELEASE:1.3
	netbsd-6-1-5-RELEASE:1.3
	netbsd-7:1.3.0.34
	netbsd-7-base:1.3
	yamt-pagecache-base9:1.3
	yamt-pagecache-tag8:1.3
	netbsd-6-1-4-RELEASE:1.3
	netbsd-6-0-5-RELEASE:1.3
	tls-earlyentropy:1.3.0.32
	tls-earlyentropy-base:1.3
	riastradh-xf86-video-intel-2-7-1-pre-2-21-15:1.3
	riastradh-drm2-base3:1.3
	netbsd-6-1-3-RELEASE:1.3
	netbsd-6-0-4-RELEASE:1.3
	netbsd-5-2-2-RELEASE:1.2
	netbsd-5-1-4-RELEASE:1.2
	netbsd-6-1-2-RELEASE:1.3
	netbsd-6-0-3-RELEASE:1.3
	netbsd-5-2-1-RELEASE:1.2
	netbsd-5-1-3-RELEASE:1.2
	rmind-smpnet-nbase:1.3
	netbsd-6-1-1-RELEASE:1.3
	riastradh-drm2-base2:1.3
	riastradh-drm2-base1:1.3
	riastradh-drm2:1.3.0.30
	riastradh-drm2-base:1.3
	rmind-smpnet:1.3.0.22
	rmind-smpnet-base:1.3
	netbsd-6-1:1.3.0.28
	netbsd-6-0-2-RELEASE:1.3
	netbsd-6-1-RELEASE:1.3
	khorben-n900:1.3.0.26
	netbsd-6-1-RC4:1.3
	netbsd-6-1-RC3:1.3
	agc-symver:1.3.0.24
	agc-symver-base:1.3
	netbsd-6-1-RC2:1.3
	netbsd-6-1-RC1:1.3
	yamt-pagecache-base8:1.3
	netbsd-5-2:1.2.0.28
	netbsd-6-0-1-RELEASE:1.3
	yamt-pagecache-base7:1.3
	netbsd-5-2-RELEASE:1.2
	netbsd-5-2-RC1:1.2
	matt-nb6-plus-nbase:1.3
	yamt-pagecache-base6:1.3
	netbsd-6-0:1.3.0.20
	netbsd-6-0-RELEASE:1.3
	netbsd-6-0-RC2:1.3
	tls-maxphys:1.3.0.18
	tls-maxphys-base:1.3
	matt-nb6-plus:1.3.0.16
	matt-nb6-plus-base:1.3
	netbsd-6-0-RC1:1.3
	jmcneill-usbmp-base10:1.3
	yamt-pagecache-base5:1.3
	jmcneill-usbmp-base9:1.3
	yamt-pagecache-base4:1.3
	jmcneill-usbmp-base8:1.3
	jmcneill-usbmp-base7:1.3
	jmcneill-usbmp-base6:1.3
	jmcneill-usbmp-base5:1.3
	jmcneill-usbmp-base4:1.3
	jmcneill-usbmp-base3:1.3
	jmcneill-usbmp-pre-base2:1.3
	jmcneill-usbmp-base2:1.3
	netbsd-6:1.3.0.14
	netbsd-6-base:1.3
	netbsd-5-1-2-RELEASE:1.2
	netbsd-5-1-1-RELEASE:1.2
	jmcneill-usbmp:1.3.0.12
	jmcneill-usbmp-base:1.3
	jmcneill-audiomp3:1.3.0.10
	jmcneill-audiomp3-base:1.3
	yamt-pagecache-base3:1.3
	yamt-pagecache-base2:1.3
	yamt-pagecache:1.3.0.8
	yamt-pagecache-base:1.3
	rmind-uvmplock-nbase:1.3
	cherry-xenmp:1.3.0.6
	cherry-xenmp-base:1.3
	jym-xensuspend-nbase:1.3
	uebayasi-xip-base7:1.3
	bouyer-quota2-nbase:1.3
	bouyer-quota2:1.3.0.4
	bouyer-quota2-base:1.3
	jruoho-x86intr:1.3.0.2
	jruoho-x86intr-base:1.3
	matt-mips64-premerge-20101231:1.3
	matt-nb5-mips64-premerge-20101231:1.2
	matt-nb5-pq3:1.2.0.26
	matt-nb5-pq3-base:1.2
	netbsd-5-1:1.2.0.24
	uebayasi-xip-base6:1.3
	uebayasi-xip-base5:1.3
	netbsd-5-1-RELEASE:1.2
	uebayasi-xip-base4:1.3
	uebayasi-xip-base3:1.3
	yamt-nfs-mp-base11:1.3
	netbsd-5-1-RC4:1.2
	matt-nb5-mips64-k15:1.2
	uebayasi-xip-base2:1.3
	yamt-nfs-mp-base10:1.3
	netbsd-5-1-RC3:1.2
	netbsd-5-1-RC2:1.2
	uebayasi-xip-base1:1.3
	netbsd-5-1-RC1:1.2
	rmind-uvmplock:1.2.0.22
	rmind-uvmplock-base:1.3
	yamt-nfs-mp-base9:1.2
	uebayasi-xip:1.2.0.20
	uebayasi-xip-base:1.2
	netbsd-5-0-2-RELEASE:1.2
	matt-nb5-mips64-premerge-20091211:1.2
	matt-premerge-20091211:1.2
	yamt-nfs-mp-base8:1.2
	matt-nb5-mips64-u2-k2-k4-k7-k8-k9:1.2
	matt-nb4-mips64-k7-u2a-k9b:1.2
	matt-nb5-mips64-u1-k1-k5:1.2
	yamt-nfs-mp-base7:1.2
	matt-nb5-mips64:1.2.0.18
	netbsd-5-0-1-RELEASE:1.2
	jymxensuspend-base:1.2
	yamt-nfs-mp-base6:1.2
	yamt-nfs-mp-base5:1.2
	yamt-nfs-mp-base4:1.2
	yamt-nfs-mp-base3:1.2
	nick-hppapmap-base4:1.2
	nick-hppapmap-base3:1.2
	netbsd-5-0:1.2.0.16
	netbsd-5-0-RELEASE:1.2
	netbsd-5-0-RC4:1.2
	netbsd-5-0-RC3:1.2
	nick-hppapmap-base2:1.2
	netbsd-5-0-RC2:1.2
	jym-xensuspend:1.2.0.14
	jym-xensuspend-base:1.3
	netbsd-5-0-RC1:1.2
	haad-dm-base2:1.2
	haad-nbase2:1.2
	ad-audiomp2:1.2.0.12
	ad-audiomp2-base:1.2
	netbsd-5:1.2.0.10
	netbsd-5-base:1.2
	nick-hppapmap:1.2.0.8
	nick-hppapmap-base:1.2
	matt-mips64-base2:1.2
	haad-dm-base1:1.2
	wrstuden-revivesa-base-4:1.2
	wrstuden-revivesa-base-3:1.2
	wrstuden-revivesa-base-2:1.2
	haad-dm:1.2.0.6
	haad-dm-base:1.2
	wrstuden-revivesa-base-1:1.2
	simonb-wapbl-nbase:1.2
	yamt-pf42-base4:1.2
	simonb-wapbl:1.2.0.4
	simonb-wapbl-base:1.2
	yamt-pf42-base3:1.2
	hpcarm-cleanup-nbase:1.2
	yamt-pf42-baseX:1.1
	yamt-pf42-base2:1.2
	yamt-nfs-mp-base2:1.2
	wrstuden-revivesa:1.2.0.2
	wrstuden-revivesa-base:1.2
	yamt-nfs-mp:1.1.0.12
	yamt-nfs-mp-base:1.1
	yamt-pf42:1.1.0.10
	yamt-pf42-base:1.1
	mjf-devfs2-base:1.2
	mjf-devfs2:1.1.0.8
	ad-socklock-base1:1.1
	yamt-lazymbuf-base15:1.1
	keiichi-mipv6-base:1.1
	yamt-lazymbuf-base14:1.1
	keiichi-mipv6:1.1.0.6
	matt-armv6:1.1.0.4
	matt-armv6-nbase:1.1
	keiichi-mipv6-nbase:1.1
	yamt-lazymbuf:1.1.0.2;
locks; strict;
comment	@// @;


1.3
date	2010.04.06.16.20.28;	author nonaka;	state Exp;
branches;
next	1.2;

1.2
date	2008.04.28.20.23.20;	author martin;	state Exp;
branches
	1.2.20.1
	1.2.22.1;
next	1.1;

1.1
date	2008.03.08.02.26.03;	author rafal;	state Exp;
branches
	1.1.2.1
	1.1.4.1
	1.1.6.1
	1.1.8.1
	1.1.10.1
	1.1.12.1;
next	;

1.2.20.1
date	2010.04.30.14.39.24;	author uebayasi;	state Exp;
branches;
next	;

1.2.22.1
date	2010.05.30.05.16.50;	author rmind;	state Exp;
branches;
next	;

1.1.2.1
date	2008.03.08.02.26.03;	author yamt;	state dead;
branches;
next	1.1.2.2;

1.1.2.2
date	2008.03.17.09.14.18;	author yamt;	state Exp;
branches;
next	;

1.1.4.1
date	2008.03.08.02.26.03;	author matt;	state dead;
branches;
next	1.1.4.2;

1.1.4.2
date	2008.03.23.02.04.03;	author matt;	state Exp;
branches;
next	;

1.1.6.1
date	2008.03.08.02.26.03;	author keiichi;	state dead;
branches;
next	1.1.6.2;

1.1.6.2
date	2008.03.24.07.14.57;	author keiichi;	state Exp;
branches;
next	;

1.1.8.1
date	2008.03.08.02.26.03;	author mjf;	state dead;
branches;
next	1.1.8.2;

1.1.8.2
date	2008.04.03.12.42.16;	author mjf;	state Exp;
branches;
next	1.1.8.3;

1.1.8.3
date	2008.06.02.13.22.08;	author mjf;	state Exp;
branches;
next	;

1.1.10.1
date	2008.05.18.12.32.01;	author yamt;	state Exp;
branches;
next	;

1.1.12.1
date	2008.05.16.02.22.24;	author yamt;	state Exp;
branches;
next	1.1.12.2;

1.1.12.2
date	2010.08.11.22.52.04;	author yamt;	state Exp;
branches;
next	;


desc
@@


1.3
log
@Added support PXA270.
@
text
@/*	$NetBSD: arm_sa1100.cpp,v 1.2 2008/04/28 20:23:20 martin Exp $	*/

/*-
 * Copyright (c) 2001 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by UCHIYAMA Yasushi.
 *
 * 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.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
 */

#include <arm/arm_arch.h>
#include <console.h>
#include <memory.h>
#include <arm/arm_sa1100.h>

/*
 * Strong-ARM SA-1100 (e.g. HP-820 JORNADA)
 */

#define	PAGE_SIZE		0x1000
#define	DRAM_BANK_NUM		4		/* total 512MByte */
#define	DRAM_BANK_SIZE		0x08000000	/* 128Mbyte */

#define	DRAM_BANK0_START	0xc0000000
#define	DRAM_BANK0_SIZE		DRAM_BANK_SIZE
#define	DRAM_BANK1_START	0xc8000000
#define	DRAM_BANK1_SIZE		DRAM_BANK_SIZE
#define	DRAM_BANK2_START	0xd0000000
#define	DRAM_BANK2_SIZE		DRAM_BANK_SIZE
#define	DRAM_BANK3_START	0xd8000000
#define	DRAM_BANK3_SIZE		DRAM_BANK_SIZE
#define	ZERO_BANK_START		0xe0000000
#define	ZERO_BANK_SIZE		DRAM_BANK_SIZE

__BEGIN_DECLS

// 2nd bootloader
void boot_func_sa1100(kaddr_t, kaddr_t, kaddr_t, kaddr_t);
extern char boot_func_end_sa1100[];
#define	BOOT_FUNC_START		reinterpret_cast <vaddr_t>(boot_func_sa1100)
#define	BOOT_FUNC_END		reinterpret_cast <vaddr_t>(boot_func_end_sa1100)

/* jump to 2nd loader */
void FlatJump_sa1100(kaddr_t, kaddr_t, kaddr_t, kaddr_t);

__END_DECLS

SA1100Architecture::SA1100Architecture(Console *&cons, MemoryManager *&mem)
	: ARMArchitecture(cons, mem)
{
	DPRINTF((TEXT("SA-11x0 CPU.\n")));
}

SA1100Architecture::~SA1100Architecture(void)
{
}

BOOL
SA1100Architecture::init(void)
{
	if (!_mem->init()) {
		DPRINTF((TEXT("can't initialize memory manager.\n")));
		return FALSE;
	}
	// set D-RAM information
	_mem->loadBank(DRAM_BANK0_START, DRAM_BANK_SIZE);
	_mem->loadBank(DRAM_BANK1_START, DRAM_BANK_SIZE);
	_mem->loadBank(DRAM_BANK2_START, DRAM_BANK_SIZE);
	_mem->loadBank(DRAM_BANK3_START, DRAM_BANK_SIZE);

	// set D-cache information
	dcachesize = 8192;
	DPRINTF((TEXT("D-cache size = %d\n"), dcachesize));

	return TRUE;
}

void
SA1100Architecture::testFramebuffer(void)
{
	// get frame buffer address from LCD controller register.
	paddr_t fbaddr_p = _mem->readPhysical4(0xb0100010); // 0xc0002e00
	// map frame buffer
	vaddr_t fbaddr_v = _mem->mapPhysicalPage(fbaddr_p, 0x50000,
	    PAGE_READWRITE);

	// test frame buffer
	int j, k;
	DI();
	for (j = 0; j < 480; j++)
		for (k = 0; k < 640; k++)
			VOLATILE_REF8(fbaddr_v + 0x200 + j * 640 + k)
			    = j * k & 0xff;
	for (j = 120; j < 360; j++)
		for (k = 120; k < 520; k++)
			VOLATILE_REF8(fbaddr_v + 0x200 + j * 640 + k) = 0x3;
	EI();
	_mem->unmapPhysicalPage(fbaddr_v);
}

void
SA1100Architecture::testUART(void)
{
#define	TBY			VOLATILE_REF(uart + 0x20)
#define	UTDR			VOLATILE_REF(uart + 0x14)
#define	TBY_BUSY		while (TBY & 0x1)
#define	UTDR_PUTCHAR(c)		(UTDR =(c))
#define	_(c)								\
__BEGIN_MACRO								\
	TBY_BUSY;							\
	UTDR_PUTCHAR(c);						\
__END_MACRO
	vaddr_t uart =
	    _mem->mapPhysicalPage(0x80050000, 0x100, PAGE_READWRITE);
	_('H');_('e');_('l');_('l');_('o');_(' ');
	_('W');_('o');_('r');_('l');_('d');_('\r');_('\n');
	_mem->unmapPhysicalPage(uart);
}

void
SA1100Architecture::dumpPeripheralRegs(void)
{
}

BOOL
SA1100Architecture::setupLoader(void)
{
	vaddr_t v;
	vsize_t sz = BOOT_FUNC_END - BOOT_FUNC_START;

	// check 2nd bootloader size.
	if (sz > _mem->getPageSize()) {
		DPRINTF((TEXT("2nd bootloader size(%dbyte) is larger than page size(%d).\n"),
		    sz, _mem->getPageSize()));
		return FALSE;
	}

	// get physical mapped page and copy loader to there.
	// don't writeback D-cache here. make sure to writeback before jump.
	if (!_mem->getPage(v , _loader_addr)) {
		DPRINTF((TEXT("can't get page for 2nd loader.\n")));
		return FALSE;
	}
	DPRINTF((TEXT("2nd bootloader vaddr=0x%08x paddr=0x%08x\n"),
	    (unsigned)v,(unsigned)_loader_addr));

	memcpy(reinterpret_cast <LPVOID>(v),
	    reinterpret_cast <LPVOID>(BOOT_FUNC_START), sz);
	DPRINTF((TEXT("2nd bootloader copy done.\n")));

	return TRUE;
}

void
SA1100Architecture::jump(paddr_t info, paddr_t pvec)
{
	kaddr_t sp;
	vaddr_t v;
	paddr_t p;

	// stack for bootloader
	_mem->getPage(v, p);
	sp = ptokv(p) + _mem->getPageSize();
	DPRINTF((TEXT("sp for bootloader = %08x + %08x = %08x\n"),
	    ptokv(p), _mem->getPageSize(), sp));

	// writeback whole D-cache
	WritebackDCache();

	SetKMode(1);
	FlatJump_sa1100(info, pvec, sp, _loader_addr);
	// NOTREACHED
}
@


1.2
log
@Remove clause 3 and 4 from TNF licenses
@
text
@d1 1
a1 1
/*	$NetBSD: arm_sa1100.cpp,v 1.1 2008/03/08 02:26:03 rafal Exp $	*/
d59 4
a62 4
void boot_func(kaddr_t, kaddr_t, kaddr_t, kaddr_t);
extern char boot_func_end[];
#define	BOOT_FUNC_START		reinterpret_cast <vaddr_t>(boot_func)
#define	BOOT_FUNC_END		reinterpret_cast <vaddr_t>(boot_func_end)
d65 1
a65 1
void FlatJump(kaddr_t, kaddr_t, kaddr_t, kaddr_t);
d92 4
d141 5
d192 1
a192 1
	FlatJump(info, pvec, sp, _loader_addr);
@


1.2.22.1
log
@sync with head
@
text
@d1 1
a1 1
/*	$NetBSD: arm_sa1100.cpp,v 1.2 2008/04/28 20:23:20 martin Exp $	*/
d59 4
a62 4
void boot_func_sa1100(kaddr_t, kaddr_t, kaddr_t, kaddr_t);
extern char boot_func_end_sa1100[];
#define	BOOT_FUNC_START		reinterpret_cast <vaddr_t>(boot_func_sa1100)
#define	BOOT_FUNC_END		reinterpret_cast <vaddr_t>(boot_func_end_sa1100)
d65 1
a65 1
void FlatJump_sa1100(kaddr_t, kaddr_t, kaddr_t, kaddr_t);
a91 4
	// set D-cache information
	dcachesize = 8192;
	DPRINTF((TEXT("D-cache size = %d\n"), dcachesize));

a136 5
void
SA1100Architecture::dumpPeripheralRegs(void)
{
}

d183 1
a183 1
	FlatJump_sa1100(info, pvec, sp, _loader_addr);
@


1.2.20.1
log
@Sync with HEAD.
@
text
@d1 1
a1 1
/*	$NetBSD$	*/
d59 4
a62 4
void boot_func_sa1100(kaddr_t, kaddr_t, kaddr_t, kaddr_t);
extern char boot_func_end_sa1100[];
#define	BOOT_FUNC_START		reinterpret_cast <vaddr_t>(boot_func_sa1100)
#define	BOOT_FUNC_END		reinterpret_cast <vaddr_t>(boot_func_end_sa1100)
d65 1
a65 1
void FlatJump_sa1100(kaddr_t, kaddr_t, kaddr_t, kaddr_t);
a91 4
	// set D-cache information
	dcachesize = 8192;
	DPRINTF((TEXT("D-cache size = %d\n"), dcachesize));

a136 5
void
SA1100Architecture::dumpPeripheralRegs(void)
{
}

d183 1
a183 1
	FlatJump_sa1100(info, pvec, sp, _loader_addr);
@


1.1
log
@Support for XScale-based (PXA-2x0) iPaqs -- original refactoring / code from
Robert Swindells, with addition of serial console,  other assorted cleanup
and much headbanging by me.  Tested only on a iPaq 3970 so far.

NB: So far this uses the SA-11xx-targetted assembly code (including cache
handling, etc).  Fortunately, none of that's required since hpcboot allocs
cache-inhibited pages from WinCE to copy the 2nd-stage loader and kernel
into.  I've split the code into SA-11xx and PXA-2x0 bits in my tree, but
that needs help/review from someone with ARM/XScale clue.
@
text
@d1 1
a1 1
/*	$NetBSD: $	*/
a17 7
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *        This product includes software developed by the NetBSD
 *        Foundation, Inc. and its contributors.
 * 4. Neither the name of The NetBSD Foundation nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
@


1.1.10.1
log
@sync with head.
@
text
@d1 1
a1 1
/*	$NetBSD: arm_sa1100.cpp,v 1.1 2008/03/08 02:26:03 rafal Exp $	*/
d18 7
@


1.1.12.1
log
@sync with head.
@
text
@d1 1
a1 1
/*	$NetBSD: arm_sa1100.cpp,v 1.1 2008/03/08 02:26:03 rafal Exp $	*/
d18 7
@


1.1.12.2
log
@sync with head.
@
text
@d1 1
a1 1
/*	$NetBSD: arm_sa1100.cpp,v 1.1.12.1 2008/05/16 02:22:24 yamt Exp $	*/
d59 4
a62 4
void boot_func_sa1100(kaddr_t, kaddr_t, kaddr_t, kaddr_t);
extern char boot_func_end_sa1100[];
#define	BOOT_FUNC_START		reinterpret_cast <vaddr_t>(boot_func_sa1100)
#define	BOOT_FUNC_END		reinterpret_cast <vaddr_t>(boot_func_end_sa1100)
d65 1
a65 1
void FlatJump_sa1100(kaddr_t, kaddr_t, kaddr_t, kaddr_t);
a91 4
	// set D-cache information
	dcachesize = 8192;
	DPRINTF((TEXT("D-cache size = %d\n"), dcachesize));

a136 5
void
SA1100Architecture::dumpPeripheralRegs(void)
{
}

d183 1
a183 1
	FlatJump_sa1100(info, pvec, sp, _loader_addr);
@


1.1.8.1
log
@file arm_sa1100.cpp was added on branch mjf-devfs2 on 2008-04-03 12:42:16 +0000
@
text
@d1 192
@


1.1.8.2
log
@Sync with HEAD.
@
text
@a0 192
/*	$NetBSD$	*/

/*-
 * Copyright (c) 2001 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by UCHIYAMA Yasushi.
 *
 * 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 the NetBSD
 *        Foundation, Inc. and its contributors.
 * 4. Neither the name of The NetBSD 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
 */

#include <arm/arm_arch.h>
#include <console.h>
#include <memory.h>
#include <arm/arm_sa1100.h>

/*
 * Strong-ARM SA-1100 (e.g. HP-820 JORNADA)
 */

#define	PAGE_SIZE		0x1000
#define	DRAM_BANK_NUM		4		/* total 512MByte */
#define	DRAM_BANK_SIZE		0x08000000	/* 128Mbyte */

#define	DRAM_BANK0_START	0xc0000000
#define	DRAM_BANK0_SIZE		DRAM_BANK_SIZE
#define	DRAM_BANK1_START	0xc8000000
#define	DRAM_BANK1_SIZE		DRAM_BANK_SIZE
#define	DRAM_BANK2_START	0xd0000000
#define	DRAM_BANK2_SIZE		DRAM_BANK_SIZE
#define	DRAM_BANK3_START	0xd8000000
#define	DRAM_BANK3_SIZE		DRAM_BANK_SIZE
#define	ZERO_BANK_START		0xe0000000
#define	ZERO_BANK_SIZE		DRAM_BANK_SIZE

__BEGIN_DECLS

// 2nd bootloader
void boot_func(kaddr_t, kaddr_t, kaddr_t, kaddr_t);
extern char boot_func_end[];
#define	BOOT_FUNC_START		reinterpret_cast <vaddr_t>(boot_func)
#define	BOOT_FUNC_END		reinterpret_cast <vaddr_t>(boot_func_end)

/* jump to 2nd loader */
void FlatJump(kaddr_t, kaddr_t, kaddr_t, kaddr_t);

__END_DECLS

SA1100Architecture::SA1100Architecture(Console *&cons, MemoryManager *&mem)
	: ARMArchitecture(cons, mem)
{
	DPRINTF((TEXT("SA-11x0 CPU.\n")));
}

SA1100Architecture::~SA1100Architecture(void)
{
}

BOOL
SA1100Architecture::init(void)
{
	if (!_mem->init()) {
		DPRINTF((TEXT("can't initialize memory manager.\n")));
		return FALSE;
	}
	// set D-RAM information
	_mem->loadBank(DRAM_BANK0_START, DRAM_BANK_SIZE);
	_mem->loadBank(DRAM_BANK1_START, DRAM_BANK_SIZE);
	_mem->loadBank(DRAM_BANK2_START, DRAM_BANK_SIZE);
	_mem->loadBank(DRAM_BANK3_START, DRAM_BANK_SIZE);

	return TRUE;
}

void
SA1100Architecture::testFramebuffer(void)
{
	// get frame buffer address from LCD controller register.
	paddr_t fbaddr_p = _mem->readPhysical4(0xb0100010); // 0xc0002e00
	// map frame buffer
	vaddr_t fbaddr_v = _mem->mapPhysicalPage(fbaddr_p, 0x50000,
	    PAGE_READWRITE);

	// test frame buffer
	int j, k;
	DI();
	for (j = 0; j < 480; j++)
		for (k = 0; k < 640; k++)
			VOLATILE_REF8(fbaddr_v + 0x200 + j * 640 + k)
			    = j * k & 0xff;
	for (j = 120; j < 360; j++)
		for (k = 120; k < 520; k++)
			VOLATILE_REF8(fbaddr_v + 0x200 + j * 640 + k) = 0x3;
	EI();
	_mem->unmapPhysicalPage(fbaddr_v);
}

void
SA1100Architecture::testUART(void)
{
#define	TBY			VOLATILE_REF(uart + 0x20)
#define	UTDR			VOLATILE_REF(uart + 0x14)
#define	TBY_BUSY		while (TBY & 0x1)
#define	UTDR_PUTCHAR(c)		(UTDR =(c))
#define	_(c)								\
__BEGIN_MACRO								\
	TBY_BUSY;							\
	UTDR_PUTCHAR(c);						\
__END_MACRO
	vaddr_t uart =
	    _mem->mapPhysicalPage(0x80050000, 0x100, PAGE_READWRITE);
	_('H');_('e');_('l');_('l');_('o');_(' ');
	_('W');_('o');_('r');_('l');_('d');_('\r');_('\n');
	_mem->unmapPhysicalPage(uart);
}

BOOL
SA1100Architecture::setupLoader(void)
{
	vaddr_t v;
	vsize_t sz = BOOT_FUNC_END - BOOT_FUNC_START;

	// check 2nd bootloader size.
	if (sz > _mem->getPageSize()) {
		DPRINTF((TEXT("2nd bootloader size(%dbyte) is larger than page size(%d).\n"),
		    sz, _mem->getPageSize()));
		return FALSE;
	}

	// get physical mapped page and copy loader to there.
	// don't writeback D-cache here. make sure to writeback before jump.
	if (!_mem->getPage(v , _loader_addr)) {
		DPRINTF((TEXT("can't get page for 2nd loader.\n")));
		return FALSE;
	}
	DPRINTF((TEXT("2nd bootloader vaddr=0x%08x paddr=0x%08x\n"),
	    (unsigned)v,(unsigned)_loader_addr));

	memcpy(reinterpret_cast <LPVOID>(v),
	    reinterpret_cast <LPVOID>(BOOT_FUNC_START), sz);
	DPRINTF((TEXT("2nd bootloader copy done.\n")));

	return TRUE;
}

void
SA1100Architecture::jump(paddr_t info, paddr_t pvec)
{
	kaddr_t sp;
	vaddr_t v;
	paddr_t p;

	// stack for bootloader
	_mem->getPage(v, p);
	sp = ptokv(p) + _mem->getPageSize();
	DPRINTF((TEXT("sp for bootloader = %08x + %08x = %08x\n"),
	    ptokv(p), _mem->getPageSize(), sp));

	// writeback whole D-cache
	WritebackDCache();

	SetKMode(1);
	FlatJump(info, pvec, sp, _loader_addr);
	// NOTREACHED
}
@


1.1.8.3
log
@Sync with HEAD.
@
text
@d18 7
@


1.1.6.1
log
@file arm_sa1100.cpp was added on branch keiichi-mipv6 on 2008-03-24 07:14:57 +0000
@
text
@d1 192
@


1.1.6.2
log
@sync with head.
@
text
@a0 192
/*	$NetBSD: arm_sa1100.cpp,v 1.1 2008/03/08 02:26:03 rafal Exp $	*/

/*-
 * Copyright (c) 2001 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by UCHIYAMA Yasushi.
 *
 * 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 the NetBSD
 *        Foundation, Inc. and its contributors.
 * 4. Neither the name of The NetBSD 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
 */

#include <arm/arm_arch.h>
#include <console.h>
#include <memory.h>
#include <arm/arm_sa1100.h>

/*
 * Strong-ARM SA-1100 (e.g. HP-820 JORNADA)
 */

#define	PAGE_SIZE		0x1000
#define	DRAM_BANK_NUM		4		/* total 512MByte */
#define	DRAM_BANK_SIZE		0x08000000	/* 128Mbyte */

#define	DRAM_BANK0_START	0xc0000000
#define	DRAM_BANK0_SIZE		DRAM_BANK_SIZE
#define	DRAM_BANK1_START	0xc8000000
#define	DRAM_BANK1_SIZE		DRAM_BANK_SIZE
#define	DRAM_BANK2_START	0xd0000000
#define	DRAM_BANK2_SIZE		DRAM_BANK_SIZE
#define	DRAM_BANK3_START	0xd8000000
#define	DRAM_BANK3_SIZE		DRAM_BANK_SIZE
#define	ZERO_BANK_START		0xe0000000
#define	ZERO_BANK_SIZE		DRAM_BANK_SIZE

__BEGIN_DECLS

// 2nd bootloader
void boot_func(kaddr_t, kaddr_t, kaddr_t, kaddr_t);
extern char boot_func_end[];
#define	BOOT_FUNC_START		reinterpret_cast <vaddr_t>(boot_func)
#define	BOOT_FUNC_END		reinterpret_cast <vaddr_t>(boot_func_end)

/* jump to 2nd loader */
void FlatJump(kaddr_t, kaddr_t, kaddr_t, kaddr_t);

__END_DECLS

SA1100Architecture::SA1100Architecture(Console *&cons, MemoryManager *&mem)
	: ARMArchitecture(cons, mem)
{
	DPRINTF((TEXT("SA-11x0 CPU.\n")));
}

SA1100Architecture::~SA1100Architecture(void)
{
}

BOOL
SA1100Architecture::init(void)
{
	if (!_mem->init()) {
		DPRINTF((TEXT("can't initialize memory manager.\n")));
		return FALSE;
	}
	// set D-RAM information
	_mem->loadBank(DRAM_BANK0_START, DRAM_BANK_SIZE);
	_mem->loadBank(DRAM_BANK1_START, DRAM_BANK_SIZE);
	_mem->loadBank(DRAM_BANK2_START, DRAM_BANK_SIZE);
	_mem->loadBank(DRAM_BANK3_START, DRAM_BANK_SIZE);

	return TRUE;
}

void
SA1100Architecture::testFramebuffer(void)
{
	// get frame buffer address from LCD controller register.
	paddr_t fbaddr_p = _mem->readPhysical4(0xb0100010); // 0xc0002e00
	// map frame buffer
	vaddr_t fbaddr_v = _mem->mapPhysicalPage(fbaddr_p, 0x50000,
	    PAGE_READWRITE);

	// test frame buffer
	int j, k;
	DI();
	for (j = 0; j < 480; j++)
		for (k = 0; k < 640; k++)
			VOLATILE_REF8(fbaddr_v + 0x200 + j * 640 + k)
			    = j * k & 0xff;
	for (j = 120; j < 360; j++)
		for (k = 120; k < 520; k++)
			VOLATILE_REF8(fbaddr_v + 0x200 + j * 640 + k) = 0x3;
	EI();
	_mem->unmapPhysicalPage(fbaddr_v);
}

void
SA1100Architecture::testUART(void)
{
#define	TBY			VOLATILE_REF(uart + 0x20)
#define	UTDR			VOLATILE_REF(uart + 0x14)
#define	TBY_BUSY		while (TBY & 0x1)
#define	UTDR_PUTCHAR(c)		(UTDR =(c))
#define	_(c)								\
__BEGIN_MACRO								\
	TBY_BUSY;							\
	UTDR_PUTCHAR(c);						\
__END_MACRO
	vaddr_t uart =
	    _mem->mapPhysicalPage(0x80050000, 0x100, PAGE_READWRITE);
	_('H');_('e');_('l');_('l');_('o');_(' ');
	_('W');_('o');_('r');_('l');_('d');_('\r');_('\n');
	_mem->unmapPhysicalPage(uart);
}

BOOL
SA1100Architecture::setupLoader(void)
{
	vaddr_t v;
	vsize_t sz = BOOT_FUNC_END - BOOT_FUNC_START;

	// check 2nd bootloader size.
	if (sz > _mem->getPageSize()) {
		DPRINTF((TEXT("2nd bootloader size(%dbyte) is larger than page size(%d).\n"),
		    sz, _mem->getPageSize()));
		return FALSE;
	}

	// get physical mapped page and copy loader to there.
	// don't writeback D-cache here. make sure to writeback before jump.
	if (!_mem->getPage(v , _loader_addr)) {
		DPRINTF((TEXT("can't get page for 2nd loader.\n")));
		return FALSE;
	}
	DPRINTF((TEXT("2nd bootloader vaddr=0x%08x paddr=0x%08x\n"),
	    (unsigned)v,(unsigned)_loader_addr));

	memcpy(reinterpret_cast <LPVOID>(v),
	    reinterpret_cast <LPVOID>(BOOT_FUNC_START), sz);
	DPRINTF((TEXT("2nd bootloader copy done.\n")));

	return TRUE;
}

void
SA1100Architecture::jump(paddr_t info, paddr_t pvec)
{
	kaddr_t sp;
	vaddr_t v;
	paddr_t p;

	// stack for bootloader
	_mem->getPage(v, p);
	sp = ptokv(p) + _mem->getPageSize();
	DPRINTF((TEXT("sp for bootloader = %08x + %08x = %08x\n"),
	    ptokv(p), _mem->getPageSize(), sp));

	// writeback whole D-cache
	WritebackDCache();

	SetKMode(1);
	FlatJump(info, pvec, sp, _loader_addr);
	// NOTREACHED
}
@


1.1.4.1
log
@file arm_sa1100.cpp was added on branch matt-armv6 on 2008-03-23 02:04:03 +0000
@
text
@d1 192
@


1.1.4.2
log
@sync with HEAD
@
text
@a0 192
/*	$NetBSD: arm_sa1100.cpp,v 1.1 2008/03/08 02:26:03 rafal Exp $	*/

/*-
 * Copyright (c) 2001 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by UCHIYAMA Yasushi.
 *
 * 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 the NetBSD
 *        Foundation, Inc. and its contributors.
 * 4. Neither the name of The NetBSD 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
 */

#include <arm/arm_arch.h>
#include <console.h>
#include <memory.h>
#include <arm/arm_sa1100.h>

/*
 * Strong-ARM SA-1100 (e.g. HP-820 JORNADA)
 */

#define	PAGE_SIZE		0x1000
#define	DRAM_BANK_NUM		4		/* total 512MByte */
#define	DRAM_BANK_SIZE		0x08000000	/* 128Mbyte */

#define	DRAM_BANK0_START	0xc0000000
#define	DRAM_BANK0_SIZE		DRAM_BANK_SIZE
#define	DRAM_BANK1_START	0xc8000000
#define	DRAM_BANK1_SIZE		DRAM_BANK_SIZE
#define	DRAM_BANK2_START	0xd0000000
#define	DRAM_BANK2_SIZE		DRAM_BANK_SIZE
#define	DRAM_BANK3_START	0xd8000000
#define	DRAM_BANK3_SIZE		DRAM_BANK_SIZE
#define	ZERO_BANK_START		0xe0000000
#define	ZERO_BANK_SIZE		DRAM_BANK_SIZE

__BEGIN_DECLS

// 2nd bootloader
void boot_func(kaddr_t, kaddr_t, kaddr_t, kaddr_t);
extern char boot_func_end[];
#define	BOOT_FUNC_START		reinterpret_cast <vaddr_t>(boot_func)
#define	BOOT_FUNC_END		reinterpret_cast <vaddr_t>(boot_func_end)

/* jump to 2nd loader */
void FlatJump(kaddr_t, kaddr_t, kaddr_t, kaddr_t);

__END_DECLS

SA1100Architecture::SA1100Architecture(Console *&cons, MemoryManager *&mem)
	: ARMArchitecture(cons, mem)
{
	DPRINTF((TEXT("SA-11x0 CPU.\n")));
}

SA1100Architecture::~SA1100Architecture(void)
{
}

BOOL
SA1100Architecture::init(void)
{
	if (!_mem->init()) {
		DPRINTF((TEXT("can't initialize memory manager.\n")));
		return FALSE;
	}
	// set D-RAM information
	_mem->loadBank(DRAM_BANK0_START, DRAM_BANK_SIZE);
	_mem->loadBank(DRAM_BANK1_START, DRAM_BANK_SIZE);
	_mem->loadBank(DRAM_BANK2_START, DRAM_BANK_SIZE);
	_mem->loadBank(DRAM_BANK3_START, DRAM_BANK_SIZE);

	return TRUE;
}

void
SA1100Architecture::testFramebuffer(void)
{
	// get frame buffer address from LCD controller register.
	paddr_t fbaddr_p = _mem->readPhysical4(0xb0100010); // 0xc0002e00
	// map frame buffer
	vaddr_t fbaddr_v = _mem->mapPhysicalPage(fbaddr_p, 0x50000,
	    PAGE_READWRITE);

	// test frame buffer
	int j, k;
	DI();
	for (j = 0; j < 480; j++)
		for (k = 0; k < 640; k++)
			VOLATILE_REF8(fbaddr_v + 0x200 + j * 640 + k)
			    = j * k & 0xff;
	for (j = 120; j < 360; j++)
		for (k = 120; k < 520; k++)
			VOLATILE_REF8(fbaddr_v + 0x200 + j * 640 + k) = 0x3;
	EI();
	_mem->unmapPhysicalPage(fbaddr_v);
}

void
SA1100Architecture::testUART(void)
{
#define	TBY			VOLATILE_REF(uart + 0x20)
#define	UTDR			VOLATILE_REF(uart + 0x14)
#define	TBY_BUSY		while (TBY & 0x1)
#define	UTDR_PUTCHAR(c)		(UTDR =(c))
#define	_(c)								\
__BEGIN_MACRO								\
	TBY_BUSY;							\
	UTDR_PUTCHAR(c);						\
__END_MACRO
	vaddr_t uart =
	    _mem->mapPhysicalPage(0x80050000, 0x100, PAGE_READWRITE);
	_('H');_('e');_('l');_('l');_('o');_(' ');
	_('W');_('o');_('r');_('l');_('d');_('\r');_('\n');
	_mem->unmapPhysicalPage(uart);
}

BOOL
SA1100Architecture::setupLoader(void)
{
	vaddr_t v;
	vsize_t sz = BOOT_FUNC_END - BOOT_FUNC_START;

	// check 2nd bootloader size.
	if (sz > _mem->getPageSize()) {
		DPRINTF((TEXT("2nd bootloader size(%dbyte) is larger than page size(%d).\n"),
		    sz, _mem->getPageSize()));
		return FALSE;
	}

	// get physical mapped page and copy loader to there.
	// don't writeback D-cache here. make sure to writeback before jump.
	if (!_mem->getPage(v , _loader_addr)) {
		DPRINTF((TEXT("can't get page for 2nd loader.\n")));
		return FALSE;
	}
	DPRINTF((TEXT("2nd bootloader vaddr=0x%08x paddr=0x%08x\n"),
	    (unsigned)v,(unsigned)_loader_addr));

	memcpy(reinterpret_cast <LPVOID>(v),
	    reinterpret_cast <LPVOID>(BOOT_FUNC_START), sz);
	DPRINTF((TEXT("2nd bootloader copy done.\n")));

	return TRUE;
}

void
SA1100Architecture::jump(paddr_t info, paddr_t pvec)
{
	kaddr_t sp;
	vaddr_t v;
	paddr_t p;

	// stack for bootloader
	_mem->getPage(v, p);
	sp = ptokv(p) + _mem->getPageSize();
	DPRINTF((TEXT("sp for bootloader = %08x + %08x = %08x\n"),
	    ptokv(p), _mem->getPageSize(), sp));

	// writeback whole D-cache
	WritebackDCache();

	SetKMode(1);
	FlatJump(info, pvec, sp, _loader_addr);
	// NOTREACHED
}
@


1.1.2.1
log
@file arm_sa1100.cpp was added on branch yamt-lazymbuf on 2008-03-17 09:14:18 +0000
@
text
@d1 192
@


1.1.2.2
log
@sync with head.
@
text
@a0 192
/*	$NetBSD$	*/

/*-
 * Copyright (c) 2001 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by UCHIYAMA Yasushi.
 *
 * 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 the NetBSD
 *        Foundation, Inc. and its contributors.
 * 4. Neither the name of The NetBSD 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
 */

#include <arm/arm_arch.h>
#include <console.h>
#include <memory.h>
#include <arm/arm_sa1100.h>

/*
 * Strong-ARM SA-1100 (e.g. HP-820 JORNADA)
 */

#define	PAGE_SIZE		0x1000
#define	DRAM_BANK_NUM		4		/* total 512MByte */
#define	DRAM_BANK_SIZE		0x08000000	/* 128Mbyte */

#define	DRAM_BANK0_START	0xc0000000
#define	DRAM_BANK0_SIZE		DRAM_BANK_SIZE
#define	DRAM_BANK1_START	0xc8000000
#define	DRAM_BANK1_SIZE		DRAM_BANK_SIZE
#define	DRAM_BANK2_START	0xd0000000
#define	DRAM_BANK2_SIZE		DRAM_BANK_SIZE
#define	DRAM_BANK3_START	0xd8000000
#define	DRAM_BANK3_SIZE		DRAM_BANK_SIZE
#define	ZERO_BANK_START		0xe0000000
#define	ZERO_BANK_SIZE		DRAM_BANK_SIZE

__BEGIN_DECLS

// 2nd bootloader
void boot_func(kaddr_t, kaddr_t, kaddr_t, kaddr_t);
extern char boot_func_end[];
#define	BOOT_FUNC_START		reinterpret_cast <vaddr_t>(boot_func)
#define	BOOT_FUNC_END		reinterpret_cast <vaddr_t>(boot_func_end)

/* jump to 2nd loader */
void FlatJump(kaddr_t, kaddr_t, kaddr_t, kaddr_t);

__END_DECLS

SA1100Architecture::SA1100Architecture(Console *&cons, MemoryManager *&mem)
	: ARMArchitecture(cons, mem)
{
	DPRINTF((TEXT("SA-11x0 CPU.\n")));
}

SA1100Architecture::~SA1100Architecture(void)
{
}

BOOL
SA1100Architecture::init(void)
{
	if (!_mem->init()) {
		DPRINTF((TEXT("can't initialize memory manager.\n")));
		return FALSE;
	}
	// set D-RAM information
	_mem->loadBank(DRAM_BANK0_START, DRAM_BANK_SIZE);
	_mem->loadBank(DRAM_BANK1_START, DRAM_BANK_SIZE);
	_mem->loadBank(DRAM_BANK2_START, DRAM_BANK_SIZE);
	_mem->loadBank(DRAM_BANK3_START, DRAM_BANK_SIZE);

	return TRUE;
}

void
SA1100Architecture::testFramebuffer(void)
{
	// get frame buffer address from LCD controller register.
	paddr_t fbaddr_p = _mem->readPhysical4(0xb0100010); // 0xc0002e00
	// map frame buffer
	vaddr_t fbaddr_v = _mem->mapPhysicalPage(fbaddr_p, 0x50000,
	    PAGE_READWRITE);

	// test frame buffer
	int j, k;
	DI();
	for (j = 0; j < 480; j++)
		for (k = 0; k < 640; k++)
			VOLATILE_REF8(fbaddr_v + 0x200 + j * 640 + k)
			    = j * k & 0xff;
	for (j = 120; j < 360; j++)
		for (k = 120; k < 520; k++)
			VOLATILE_REF8(fbaddr_v + 0x200 + j * 640 + k) = 0x3;
	EI();
	_mem->unmapPhysicalPage(fbaddr_v);
}

void
SA1100Architecture::testUART(void)
{
#define	TBY			VOLATILE_REF(uart + 0x20)
#define	UTDR			VOLATILE_REF(uart + 0x14)
#define	TBY_BUSY		while (TBY & 0x1)
#define	UTDR_PUTCHAR(c)		(UTDR =(c))
#define	_(c)								\
__BEGIN_MACRO								\
	TBY_BUSY;							\
	UTDR_PUTCHAR(c);						\
__END_MACRO
	vaddr_t uart =
	    _mem->mapPhysicalPage(0x80050000, 0x100, PAGE_READWRITE);
	_('H');_('e');_('l');_('l');_('o');_(' ');
	_('W');_('o');_('r');_('l');_('d');_('\r');_('\n');
	_mem->unmapPhysicalPage(uart);
}

BOOL
SA1100Architecture::setupLoader(void)
{
	vaddr_t v;
	vsize_t sz = BOOT_FUNC_END - BOOT_FUNC_START;

	// check 2nd bootloader size.
	if (sz > _mem->getPageSize()) {
		DPRINTF((TEXT("2nd bootloader size(%dbyte) is larger than page size(%d).\n"),
		    sz, _mem->getPageSize()));
		return FALSE;
	}

	// get physical mapped page and copy loader to there.
	// don't writeback D-cache here. make sure to writeback before jump.
	if (!_mem->getPage(v , _loader_addr)) {
		DPRINTF((TEXT("can't get page for 2nd loader.\n")));
		return FALSE;
	}
	DPRINTF((TEXT("2nd bootloader vaddr=0x%08x paddr=0x%08x\n"),
	    (unsigned)v,(unsigned)_loader_addr));

	memcpy(reinterpret_cast <LPVOID>(v),
	    reinterpret_cast <LPVOID>(BOOT_FUNC_START), sz);
	DPRINTF((TEXT("2nd bootloader copy done.\n")));

	return TRUE;
}

void
SA1100Architecture::jump(paddr_t info, paddr_t pvec)
{
	kaddr_t sp;
	vaddr_t v;
	paddr_t p;

	// stack for bootloader
	_mem->getPage(v, p);
	sp = ptokv(p) + _mem->getPageSize();
	DPRINTF((TEXT("sp for bootloader = %08x + %08x = %08x\n"),
	    ptokv(p), _mem->getPageSize(), sp));

	// writeback whole D-cache
	WritebackDCache();

	SetKMode(1);
	FlatJump(info, pvec, sp, _loader_addr);
	// NOTREACHED
}
@


