Fri Jan 20 15:00:27 2012 UTC ()
Kernel load address can be changed now.


(nonaka)
diff -r1.3 -r1.4 src/sys/arch/zaurus/conf/Makefile.zaurus.inc
diff -r1.3 -r1.4 src/sys/arch/zaurus/conf/std.zaurus
diff -r1.1 -r0 src/sys/arch/zaurus/conf/ldscript
diff -r0 -r1.3 src/sys/arch/zaurus/conf/ldscript.zaurus
diff -r1.4 -r1.5 src/sys/arch/zaurus/zaurus/kloader_machdep.c
diff -r1.27 -r1.28 src/sys/arch/zaurus/zaurus/machdep.c

cvs diff -r1.3 -r1.4 src/sys/arch/zaurus/conf/Makefile.zaurus.inc (switch to unified diff)

--- src/sys/arch/zaurus/conf/Makefile.zaurus.inc 2011/05/05 09:07:59 1.3
+++ src/sys/arch/zaurus/conf/Makefile.zaurus.inc 2012/01/20 15:00:27 1.4
@@ -1,22 +1,32 @@ @@ -1,22 +1,32 @@
1# $NetBSD: Makefile.zaurus.inc,v 1.3 2011/05/05 09:07:59 nonaka Exp $ 1# $NetBSD: Makefile.zaurus.inc,v 1.4 2012/01/20 15:00:27 nonaka Exp $
2 2
3MACHINE_ARCH= arm 3MACHINE_ARCH= arm
4CPPFLAGS+= -D${MACHINE} 4CPPFLAGS+= -D${MACHINE}
5 5
6SYSTEM_FIRST_OBJ= zaurus_start.o 6SYSTEM_FIRST_OBJ= zaurus_start.o
7SYSTEM_FIRST_SFILE= ${THISARM}/zaurus/zaurus_start.S 7SYSTEM_FIRST_SFILE= ${THISARM}/zaurus/zaurus_start.S
8 8
9LINKFLAGS= -T ${THISARM}/conf/ldscript 
10 
11EXTRA_CLEAN+= netbsd.map assym.d 
12 
13SYSTEM_LD_TAIL_EXTRA+=; \ 9SYSTEM_LD_TAIL_EXTRA+=; \
14 echo "Checking kernel size..."; \ 10 echo "Checking kernel size..."; \
15 size=`wc -c "$@" | ${TOOL_AWK} '{ print $$1 }'`; \ 11 size=`wc -c "$@" | ${TOOL_AWK} '{ print $$1 }'`; \
16 maxsize=5242880; \ 12 maxsize=5242880; \
17 if [ $$size -gt $$maxsize ]; \ 13 if [ $$size -gt $$maxsize ]; \
18 then \ 14 then \
19 echo "Fatal: kernel size must be less than 5MB."; \ 15 echo "Fatal: kernel size must be less than 5MB."; \
20 echo "Fatal: kernel size: $$size, max kernel size: $$maxsize"; \ 16 echo "Fatal: kernel size: $$size, max kernel size: $$maxsize"; \
21 false; \ 17 false; \
22 fi 18 fi
 19
 20KERNEL_BASE_VIRT= $(LOADADDRESS)
 21
 22LINKFLAGS= -T ldscript
 23
 24EXTRA_CLEAN+= netbsd.map assym.d ldscript tmp
 25
 26netbsd: ldscript # XXX
 27
 28# generate ldscript from common template
 29ldscript: ${THISARM}/conf/ldscript.zaurus ${THISARM}/conf/Makefile.zaurus.inc Makefile
 30 ${TOOL_SED} -e 's/@KERNEL_BASE_PHYS@/${KERNEL_BASE_PHYS}/' \
 31 -e 's/@KERNEL_BASE_VIRT@/${KERNEL_BASE_VIRT}/' \
 32 ${THISARM}/conf/ldscript.zaurus > tmp && mv tmp $@

cvs diff -r1.3 -r1.4 src/sys/arch/zaurus/conf/std.zaurus (switch to unified diff)

--- src/sys/arch/zaurus/conf/std.zaurus 2008/01/27 12:37:12 1.3
+++ src/sys/arch/zaurus/conf/std.zaurus 2012/01/20 15:00:27 1.4
@@ -1,21 +1,22 @@ @@ -1,21 +1,22 @@
1# $NetBSD: std.zaurus,v 1.3 2008/01/27 12:37:12 chris Exp $ 1# $NetBSD: std.zaurus,v 1.4 2012/01/20 15:00:27 nonaka Exp $
2# 2#
3# standard NetBSD/zaurus options 3# standard NetBSD/zaurus options
4 4
5machine zaurus arm 5machine zaurus arm
6include "conf/std" # MI standard options 6include "conf/std" # MI standard options
7include "arch/arm/conf/std.arm" # arch standard options 7include "arch/arm/conf/std.arm" # arch standard options
8 8
9options EXEC_AOUT 9options EXEC_AOUT
10options EXEC_ELF32 10options EXEC_ELF32
11options EXEC_SCRIPT 11options EXEC_SCRIPT
12 12
13# To support easy transit to ../arch/arm/arm32 13# To support easy transit to ../arch/arm/arm32
14options ARM32 14options ARM32
15 15
16#options ARM32_NEW_VM_LAYOUT # Not yet ready for prime-time 16makeoptions KERNEL_BASE_PHYS="0xa0200000"
 17makeoptions LOADADDRESS="0xc0200000"
17 18
18options ARM_INTR_IMPL="<arch/arm/xscale/pxa2x0_intr.h>" 19options ARM_INTR_IMPL="<arch/arm/xscale/pxa2x0_intr.h>"
19 20
20# OS Timer 21# OS Timer
21saost* at pxaip? addr 0x40a00000 size 0x20 22saost* at pxaip? addr 0x40a00000 size 0x20

File Deleted: src/sys/arch/zaurus/conf/Attic/ldscript

File Added: src/sys/arch/zaurus/conf/ldscript.zaurus
/*	$NetBSD: ldscript.zaurus,v 1.3 2012/01/20 15:00:27 nonaka Exp $	*/

OUTPUT_ARCH(arm)
ENTRY(KERNEL_BASE_phys)
SECTIONS
{
  KERNEL_BASE_phys = @KERNEL_BASE_PHYS@;
  KERNEL_BASE_virt = @KERNEL_BASE_VIRT@;

  /* Kernel start: */
  .start (KERNEL_BASE_phys) :
  {
    *(.start)
  } =0

  /* Read-only sections, merged into text segment: */
  .text (KERNEL_BASE_virt + SIZEOF(.start)) :
  AT (LOADADDR(.start) + SIZEOF(.start))
  {
    *(.text)
    *(.text.*)
    *(.stub)
    *(.glue_7t) *(.glue_7)
    *(.rodata) *(.rodata.*)
  } =0
  PROVIDE (__etext = .);
  PROVIDE (_etext = .);
  PROVIDE (etext = .);
  /* Adjust the address for the data segment to start on the next page
     boundary.  */
  . = ALIGN(0x8000);
  .data    :
  AT (LOADADDR(.text) + (ADDR(.data) - ADDR(.text)))
  {
    __data_start = . ;
    *(.data)
    *(.data.*)
  }
  .sdata     : 
  AT (LOADADDR(.data) + (ADDR(.sdata) - ADDR(.data)))
  {
    *(.sdata) 
    *(.sdata.*)
  }
  _edata = .;
  PROVIDE (edata = .);
  __bss_start = .;
  __bss_start__ = .;
  .sbss      :
  {
    PROVIDE (__sbss_start = .);
    PROVIDE (___sbss_start = .);
    *(.dynsbss)
    *(.sbss)
    *(.sbss.*)
    *(.scommon)
    PROVIDE (__sbss_end = .);
    PROVIDE (___sbss_end = .);
  }
  .bss       :
  {
   *(.dynbss)
   *(.bss)
   *(.bss.*)
   *(COMMON)
   /* Align here to ensure that the .bss section occupies space up to
      _end.  Align after .bss to ensure correct alignment even if the
      .bss section disappears because there are no input sections.  */
   . = ALIGN(32 / 8);
  }
  . = ALIGN(32 / 8);
  _end = .;
  _bss_end__ = . ; __bss_end__ = . ; __end__ = . ;
  PROVIDE (end = .);
  .note.netbsd.ident :
  {
    KEEP(*(.note.netbsd.ident));
  }
}

cvs diff -r1.4 -r1.5 src/sys/arch/zaurus/zaurus/kloader_machdep.c (switch to unified diff)

--- src/sys/arch/zaurus/zaurus/kloader_machdep.c 2011/11/20 04:07:50 1.4
+++ src/sys/arch/zaurus/zaurus/kloader_machdep.c 2012/01/20 15:00:27 1.5
@@ -1,150 +1,150 @@ @@ -1,150 +1,150 @@
1/* $NetBSD: kloader_machdep.c,v 1.4 2011/11/20 04:07:50 nonaka Exp $ */ 1/* $NetBSD: kloader_machdep.c,v 1.5 2012/01/20 15:00:27 nonaka Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2009 NONAKA Kimihiro <nonaka@netbsd.org> 4 * Copyright (c) 2009-2012 NONAKA Kimihiro <nonaka@netbsd.org>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 16 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE. 26 * SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30__KERNEL_RCSID(0, "$NetBSD: kloader_machdep.c,v 1.4 2011/11/20 04:07:50 nonaka Exp $"); 30__KERNEL_RCSID(0, "$NetBSD: kloader_machdep.c,v 1.5 2012/01/20 15:00:27 nonaka Exp $");
31 31
32#include "debug_kloader.h" 32#include "debug_kloader.h"
33 33
34#include <sys/param.h> 34#include <sys/param.h>
35#include <sys/systm.h> 35#include <sys/systm.h>
36#include <sys/device.h> 36#include <sys/device.h>
37#include <sys/disklabel.h> 37#include <sys/disklabel.h>
38 38
39#include <machine/kloader.h> 39#include <machine/kloader.h>
40#include <machine/pmap.h> 40#include <machine/pmap.h>
41 41
42#include <arm/cpufunc.h> 42#include <arm/cpufunc.h>
43#include <arm/xscale/pxa2x0reg.h> 43#include <arm/xscale/pxa2x0reg.h>
44 44
45#include <zaurus/zaurus/zaurus_var.h> 45#include <zaurus/zaurus/zaurus_var.h>
46 46
47#ifndef KERNEL_BASE 47#define KERNEL_TEXT_BASE ((vaddr_t)&KERNEL_BASE_virt)
48#define KERNEL_BASE 0xc0000000 
49#endif 
50 48
51kloader_jumpfunc_t kloader_zaurus_jump __attribute__((__noreturn__)); 49kloader_jumpfunc_t kloader_zaurus_jump __attribute__((__noreturn__));
52kloader_bootfunc_t kloader_zaurus_boot __attribute__((__noreturn__)); 50kloader_bootfunc_t kloader_zaurus_boot __attribute__((__noreturn__));
53void kloader_zaurus_reset(void); 51void kloader_zaurus_reset(void);
54 52
55struct kloader_ops kloader_zaurus_ops = { 53struct kloader_ops kloader_zaurus_ops = {
56 .jump = kloader_zaurus_jump, 54 .jump = kloader_zaurus_jump,
57 .boot = kloader_zaurus_boot, 55 .boot = kloader_zaurus_boot,
58 .reset = kloader_zaurus_reset, 56 .reset = kloader_zaurus_reset,
59}; 57};
60 58
61void 59void
62kloader_reboot_setup(const char *filename) 60kloader_reboot_setup(const char *filename)
63{ 61{
64 62
65 __kloader_reboot_setup(&kloader_zaurus_ops, filename); 63 __kloader_reboot_setup(&kloader_zaurus_ops, filename);
66} 64}
67 65
68void 66void
69kloader_zaurus_reset(void) 67kloader_zaurus_reset(void)
70{ 68{
71 69
72 zaurus_restart(); 70 zaurus_restart();
73 /*NOTREACHED*/ 71 /*NOTREACHED*/
74} 72}
75 73
76void 74void
77kloader_zaurus_jump(kloader_bootfunc_t func, vaddr_t sp, 75kloader_zaurus_jump(kloader_bootfunc_t func, vaddr_t sp,
78 struct kloader_bootinfo *kbi, struct kloader_page_tag *tag) 76 struct kloader_bootinfo *kbi, struct kloader_page_tag *tag)
79{ 77{
80 extern int kloader_howto; 78 extern int kloader_howto;
81 void (*bootinfop)(void *, void *) = (void *)(0xc0200000 - PAGE_SIZE); 79 extern char KERNEL_BASE_virt[];
82 uint32_t *bootmagicp = (uint32_t *)(0xc0200000 - BOOTARGS_BUFSIZ); 80 void (*bootinfop)(void *, void *);
 81 uint32_t *bootmagicp;
83 vaddr_t top, ptr; 82 vaddr_t top, ptr;
84 struct bootinfo *bootinfo; 83 struct bootinfo *bootinfo;
85 struct btinfo_howto *bi_howto; 84 struct btinfo_howto *bi_howto;
86 struct btinfo_rootdevice *bi_rootdv; 85 struct btinfo_rootdevice *bi_rootdv;
87 86
88 disable_interrupts(I32_bit|F32_bit);  87 disable_interrupts(I32_bit|F32_bit);
89 88
90 /* copy 2nd boot-loader to va=pa page */ 89 /* copy 2nd boot-loader to va=pa page */
 90 bootinfop = (void *)(KERNEL_TEXT_BASE - PAGE_SIZE);
91 memmove(bootinfop, func, PAGE_SIZE); 91 memmove(bootinfop, func, PAGE_SIZE);
92 92
93 /* 93 /*
94 * make bootinfo 94 * make bootinfo
95 */ 95 */
 96 bootmagicp = (uint32_t *)(KERNEL_TEXT_BASE - BOOTARGS_BUFSIZ);
96 memset(bootmagicp, 0, BOOTARGS_BUFSIZ); 97 memset(bootmagicp, 0, BOOTARGS_BUFSIZ);
97 bootinfo = (struct bootinfo *)(bootmagicp + 1); 98 bootinfo = (struct bootinfo *)(bootmagicp + 1);
98 bootinfo->nentries = 0; 99 bootinfo->nentries = 0;
99 top = ptr = (vaddr_t)bootinfo->info; 100 top = ptr = (vaddr_t)bootinfo->info;
100 101
101 /* pass to howto for new kernel */ 102 /* pass to howto for new kernel */
102 bi_howto = (struct btinfo_howto *)ptr; 103 bi_howto = (struct btinfo_howto *)ptr;
103 bi_howto->common.len = sizeof(struct btinfo_howto); 104 bi_howto->common.len = sizeof(struct btinfo_howto);
104 bi_howto->common.type = BTINFO_HOWTO; 105 bi_howto->common.type = BTINFO_HOWTO;
105 bi_howto->howto = kloader_howto; 106 bi_howto->howto = kloader_howto;
106 bootinfo->nentries++; 107 bootinfo->nentries++;
107 ptr += bi_howto->common.len; 108 ptr += bi_howto->common.len;
108 109
109 /* set previous root device for new boot device */ 110 /* set previous root device for new boot device */
110 if (root_device != NULL  111 if (root_device != NULL
111 && device_class(root_device) == DV_DISK 112 && device_class(root_device) == DV_DISK
112 && !device_is_a(root_device, "dk")) { 113 && !device_is_a(root_device, "dk")) {
113 bi_rootdv = (struct btinfo_rootdevice *)ptr; 114 bi_rootdv = (struct btinfo_rootdevice *)ptr;
114 bi_rootdv->common.len = sizeof(struct btinfo_rootdevice); 115 bi_rootdv->common.len = sizeof(struct btinfo_rootdevice);
115 bi_rootdv->common.type = BTINFO_ROOTDEVICE; 116 bi_rootdv->common.type = BTINFO_ROOTDEVICE;
116 snprintf(bi_rootdv->devname, sizeof(bi_rootdv->devname), "%s%c", 117 snprintf(bi_rootdv->devname, sizeof(bi_rootdv->devname), "%s%c",
117 device_xname(root_device), (int)DISKPART(rootdev) + 'a'); 118 device_xname(root_device), (int)DISKPART(rootdev) + 'a');
118 bootinfo->nentries++; 119 bootinfo->nentries++;
119 ptr += bi_rootdv->common.len; 120 ptr += bi_rootdv->common.len;
120 } 121 }
121 122
122 if (bootinfo->nentries > 0) 123 *bootmagicp = BOOTARGS_MAGIC;
123 *bootmagicp = BOOTARGS_MAGIC; 
124 cpu_idcache_wbinv_all(); 124 cpu_idcache_wbinv_all();
125 125
126 /* jump to 2nd boot-loader */ 126 /* jump to 2nd boot-loader */
127 (*bootinfop)(kbi, tag); 127 (*bootinfop)(kbi, tag);
128 128
129 /*NOTREACHED*/ 129 /*NOTREACHED*/
130 for (;;) 130 for (;;)
131 continue; 131 continue;
132} 132}
133 133
134/* 134/*
135 * Physcal address to virtual address 135 * Physcal address to virtual address
136 */ 136 */
137vaddr_t 137vaddr_t
138kloader_phystov(paddr_t pa) 138kloader_phystov(paddr_t pa)
139{ 139{
140 vaddr_t va; 140 vaddr_t va;
141 int error; 141 int error;
142 142
143 va = KERNEL_BASE + pa - 0xa0000000UL; 143 va = KERNEL_BASE + pa - PXA2X0_SDRAM0_START;
144 error = pmap_enter(pmap_kernel(), va, pa, VM_PROT_ALL, 0); 144 error = pmap_enter(pmap_kernel(), va, pa, VM_PROT_ALL, 0);
145 if (error) { 145 if (error) {
146 printf("%s: map failed: pa=0x%lx, va=0x%lx, error=%d\n", 146 printf("%s: map failed: pa=0x%lx, va=0x%lx, error=%d\n",
147 __func__, pa, va, error); 147 __func__, pa, va, error);
148 } 148 }
149 return va; 149 return va;
150} 150}

cvs diff -r1.27 -r1.28 src/sys/arch/zaurus/zaurus/machdep.c (switch to unified diff)

--- src/sys/arch/zaurus/zaurus/machdep.c 2011/11/12 04:39:19 1.27
+++ src/sys/arch/zaurus/zaurus/machdep.c 2012/01/20 15:00:27 1.28
@@ -1,1342 +1,1343 @@ @@ -1,1342 +1,1343 @@
1/* $NetBSD: machdep.c,v 1.27 2011/11/12 04:39:19 nonaka Exp $ */ 1/* $NetBSD: machdep.c,v 1.28 2012/01/20 15:00:27 nonaka Exp $ */
2/* $OpenBSD: zaurus_machdep.c,v 1.25 2006/06/20 18:24:04 todd Exp $ */ 2/* $OpenBSD: zaurus_machdep.c,v 1.25 2006/06/20 18:24:04 todd Exp $ */
3 3
4/* 4/*
5 * Copyright (c) 2002, 2003 Genetec Corporation. All rights reserved. 5 * Copyright (c) 2002, 2003 Genetec Corporation. All rights reserved.
6 * Written by Hiroyuki Bessho for Genetec Corporation. 6 * Written by Hiroyuki Bessho for Genetec Corporation.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution. 15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of Genetec Corporation may not be used to endorse or  16 * 3. The name of Genetec Corporation may not be used to endorse or
17 * promote products derived from this software without specific prior 17 * promote products derived from this software without specific prior
18 * written permission. 18 * written permission.
19 * 19 *
20 * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND 20 * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GENETEC CORPORATION 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GENETEC CORPORATION
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE. 30 * POSSIBILITY OF SUCH DAMAGE.
31 * 31 *
32 * Machine dependent functions for kernel setup for  32 * Machine dependent functions for kernel setup for
33 * Intel DBPXA250 evaluation board (a.k.a. Lubbock). 33 * Intel DBPXA250 evaluation board (a.k.a. Lubbock).
34 * Based on iq80310_machhdep.c 34 * Based on iq80310_machhdep.c
35 */ 35 */
36 36
37/* 37/*
38 * Copyright (c) 2001 Wasabi Systems, Inc. 38 * Copyright (c) 2001 Wasabi Systems, Inc.
39 * All rights reserved. 39 * All rights reserved.
40 * 40 *
41 * Written by Jason R. Thorpe for Wasabi Systems, Inc. 41 * Written by Jason R. Thorpe for Wasabi Systems, Inc.
42 * 42 *
43 * Redistribution and use in source and binary forms, with or without 43 * Redistribution and use in source and binary forms, with or without
44 * modification, are permitted provided that the following conditions 44 * modification, are permitted provided that the following conditions
45 * are met: 45 * are met:
46 * 1. Redistributions of source code must retain the above copyright 46 * 1. Redistributions of source code must retain the above copyright
47 * notice, this list of conditions and the following disclaimer. 47 * notice, this list of conditions and the following disclaimer.
48 * 2. Redistributions in binary form must reproduce the above copyright 48 * 2. Redistributions in binary form must reproduce the above copyright
49 * notice, this list of conditions and the following disclaimer in the 49 * notice, this list of conditions and the following disclaimer in the
50 * documentation and/or other materials provided with the distribution. 50 * documentation and/or other materials provided with the distribution.
51 * 3. All advertising materials mentioning features or use of this software 51 * 3. All advertising materials mentioning features or use of this software
52 * must display the following acknowledgement: 52 * must display the following acknowledgement:
53 * This product includes software developed for the NetBSD Project by 53 * This product includes software developed for the NetBSD Project by
54 * Wasabi Systems, Inc. 54 * Wasabi Systems, Inc.
55 * 4. The name of Wasabi Systems, Inc. may not be used to endorse 55 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
56 * or promote products derived from this software without specific prior 56 * or promote products derived from this software without specific prior
57 * written permission. 57 * written permission.
58 * 58 *
59 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 59 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
60 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 60 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
61 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 61 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
62 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 62 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
63 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 63 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
64 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 64 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
65 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 65 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
66 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 66 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
67 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 67 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
68 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 68 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
69 * POSSIBILITY OF SUCH DAMAGE. 69 * POSSIBILITY OF SUCH DAMAGE.
70 */ 70 */
71 71
72/* 72/*
73 * Copyright (c) 1997,1998 Mark Brinicombe. 73 * Copyright (c) 1997,1998 Mark Brinicombe.
74 * Copyright (c) 1997,1998 Causality Limited. 74 * Copyright (c) 1997,1998 Causality Limited.
75 * All rights reserved. 75 * All rights reserved.
76 * 76 *
77 * Redistribution and use in source and binary forms, with or without 77 * Redistribution and use in source and binary forms, with or without
78 * modification, are permitted provided that the following conditions 78 * modification, are permitted provided that the following conditions
79 * are met: 79 * are met:
80 * 1. Redistributions of source code must retain the above copyright 80 * 1. Redistributions of source code must retain the above copyright
81 * notice, this list of conditions and the following disclaimer. 81 * notice, this list of conditions and the following disclaimer.
82 * 2. Redistributions in binary form must reproduce the above copyright 82 * 2. Redistributions in binary form must reproduce the above copyright
83 * notice, this list of conditions and the following disclaimer in the 83 * notice, this list of conditions and the following disclaimer in the
84 * documentation and/or other materials provided with the distribution. 84 * documentation and/or other materials provided with the distribution.
85 * 3. All advertising materials mentioning features or use of this software 85 * 3. All advertising materials mentioning features or use of this software
86 * must display the following acknowledgement: 86 * must display the following acknowledgement:
87 * This product includes software developed by Mark Brinicombe 87 * This product includes software developed by Mark Brinicombe
88 * for the NetBSD Project. 88 * for the NetBSD Project.
89 * 4. The name of the company nor the name of the author may be used to 89 * 4. The name of the company nor the name of the author may be used to
90 * endorse or promote products derived from this software without specific 90 * endorse or promote products derived from this software without specific
91 * prior written permission. 91 * prior written permission.
92 * 92 *
93 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 93 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
94 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 94 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
95 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 95 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
96 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 96 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
97 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 97 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
98 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 98 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
99 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 99 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
101 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 101 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
102 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 102 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
103 * SUCH DAMAGE. 103 * SUCH DAMAGE.
104 * 104 *
105 * Machine dependent functions for kernel setup for Intel IQ80310 evaluation 105 * Machine dependent functions for kernel setup for Intel IQ80310 evaluation
106 * boards using RedBoot firmware. 106 * boards using RedBoot firmware.
107 */ 107 */
108 108
109#include <sys/cdefs.h> 109#include <sys/cdefs.h>
110__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.27 2011/11/12 04:39:19 nonaka Exp $"); 110__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.28 2012/01/20 15:00:27 nonaka Exp $");
111 111
112#include "opt_ddb.h" 112#include "opt_ddb.h"
113#include "opt_kgdb.h" 113#include "opt_kgdb.h"
114#include "opt_modular.h" 114#include "opt_modular.h"
115#include "opt_pmap_debug.h" 115#include "opt_pmap_debug.h"
116#include "opt_md.h" 116#include "opt_md.h"
117#include "opt_com.h" 117#include "opt_com.h"
118#include "ksyms.h" 118#include "ksyms.h"
119 119
120#include "opt_kloader.h" 120#include "opt_kloader.h"
121#ifndef KLOADER_KERNEL_PATH 121#ifndef KLOADER_KERNEL_PATH
122#define KLOADER_KERNEL_PATH "/netbsd" 122#define KLOADER_KERNEL_PATH "/netbsd"
123#endif 123#endif
124 124
125#include <sys/param.h> 125#include <sys/param.h>
126#include <sys/device.h> 126#include <sys/device.h>
127#include <sys/systm.h> 127#include <sys/systm.h>
128#include <sys/kernel.h> 128#include <sys/kernel.h>
129#include <sys/exec.h> 129#include <sys/exec.h>
130#include <sys/proc.h> 130#include <sys/proc.h>
131#include <sys/msgbuf.h> 131#include <sys/msgbuf.h>
132#include <sys/reboot.h> 132#include <sys/reboot.h>
133#include <sys/termios.h> 133#include <sys/termios.h>
134#include <sys/boot_flag.h> 134#include <sys/boot_flag.h>
135 135
136#include <uvm/uvm_extern.h> 136#include <uvm/uvm_extern.h>
137 137
138#include <dev/cons.h> 138#include <dev/cons.h>
139#include <sys/conf.h> 139#include <sys/conf.h>
140#include <sys/queue.h> 140#include <sys/queue.h>
141#include <sys/bus.h> 141#include <sys/bus.h>
142 142
143#include <machine/db_machdep.h> 143#include <machine/db_machdep.h>
144#include <ddb/db_sym.h> 144#include <ddb/db_sym.h>
145#include <ddb/db_extern.h> 145#include <ddb/db_extern.h>
146#ifdef KGDB 146#ifdef KGDB
147#include <sys/kgdb.h> 147#include <sys/kgdb.h>
148#endif 148#endif
149 149
150#include <machine/bootconfig.h> 150#include <machine/bootconfig.h>
151#include <machine/bootinfo.h> 151#include <machine/bootinfo.h>
152#include <machine/cpu.h> 152#include <machine/cpu.h>
153#include <machine/frame.h> 153#include <machine/frame.h>
154#ifdef KLOADER 154#ifdef KLOADER
155#include <machine/kloader.h> 155#include <machine/kloader.h>
156#endif 156#endif
157 157
158#include <arm/undefined.h> 158#include <arm/undefined.h>
159#include <arm/arm32/machdep.h> 159#include <arm/arm32/machdep.h>
160 160
161#include <arm/xscale/pxa2x0cpu.h> 161#include <arm/xscale/pxa2x0cpu.h>
162#include <arm/xscale/pxa2x0reg.h> 162#include <arm/xscale/pxa2x0reg.h>
163#include <arm/xscale/pxa2x0var.h> 163#include <arm/xscale/pxa2x0var.h>
164#include <arm/xscale/pxa2x0_gpio.h> 164#include <arm/xscale/pxa2x0_gpio.h>
165 165
166#include <arch/zaurus/zaurus/zaurus_reg.h> 166#include <arch/zaurus/zaurus/zaurus_reg.h>
167#include <arch/zaurus/zaurus/zaurus_var.h> 167#include <arch/zaurus/zaurus/zaurus_var.h>
168 168
169#include <zaurus/dev/scoopreg.h> 169#include <zaurus/dev/scoopreg.h>
170#include <zaurus/dev/zlcdvar.h> 170#include <zaurus/dev/zlcdvar.h>
171 171
172#include <dev/ic/comreg.h> 172#include <dev/ic/comreg.h>
173 173
174#if 0 /* XXX */ 174#if 0 /* XXX */
175#include "apm.h" 175#include "apm.h"
176#endif /* XXX */ 176#endif /* XXX */
177#if NAPM > 0 177#if NAPM > 0
178#include <zaurus/dev/zapmvar.h> 178#include <zaurus/dev/zapmvar.h>
179#endif 179#endif
180 180
181/* Kernel text starts 2MB in from the bottom of the kernel address space. */ 181/* Kernel text starts 2MB in from the bottom of the kernel address space. */
182#define KERNEL_TEXT_OFFSET 0x00200000 182#define KERNEL_TEXT_BASE ((vaddr_t)&KERNEL_BASE_virt)
183#define KERNEL_TEXT_BASE (KERNEL_BASE + KERNEL_TEXT_OFFSET) 
184#ifndef KERNEL_VM_BASE 183#ifndef KERNEL_VM_BASE
185#define KERNEL_VM_BASE (KERNEL_BASE + 0x01000000) 184#define KERNEL_VM_BASE (KERNEL_BASE + 0x01000000)
186#endif 185#endif
187 186
188/* 187/*
189 * The range 0xc4000000 - 0xcfffffff is available for kernel VM space 188 * The range 0xc4000000 - 0xcfffffff is available for kernel VM space
190 * Core-logic registers and I/O mappings occupy 0xfd000000 - 0xffffffff 189 * Core-logic registers and I/O mappings occupy 0xfd000000 - 0xffffffff
191 */ 190 */
192#define KERNEL_VM_SIZE 0x0c000000 191#define KERNEL_VM_SIZE 0x0c000000
193 192
194/* 193/*
195 * Address to call from cpu_reset() to reset the machine. 194 * Address to call from cpu_reset() to reset the machine.
196 * This is machine architecture dependent as it varies depending 195 * This is machine architecture dependent as it varies depending
197 * on where the ROM appears when you turn the MMU off. 196 * on where the ROM appears when you turn the MMU off.
198 */ 197 */
199u_int cpu_reset_address = 0; 198u_int cpu_reset_address = 0;
200 199
201/* Define various stack sizes in pages */ 200/* Define various stack sizes in pages */
202#define IRQ_STACK_SIZE 1 201#define IRQ_STACK_SIZE 1
203#define ABT_STACK_SIZE 1 202#define ABT_STACK_SIZE 1
204#define UND_STACK_SIZE 1 203#define UND_STACK_SIZE 1
205 204
206int zaurusmod; /* Zaurus model */ 205int zaurusmod; /* Zaurus model */
207 206
208BootConfig bootconfig; /* Boot config storage */ 207BootConfig bootconfig; /* Boot config storage */
209char *boot_file = NULL; 208char *boot_file = NULL;
210char *boot_args = NULL; 209char *boot_args = NULL;
211 210
212paddr_t physical_start; 211paddr_t physical_start;
213paddr_t physical_freestart; 212paddr_t physical_freestart;
214paddr_t physical_freeend; 213paddr_t physical_freeend;
215paddr_t physical_end; 214paddr_t physical_end;
216u_int free_pages; 215u_int free_pages;
217 216
218#ifndef PMAP_STATIC_L1S 217#ifndef PMAP_STATIC_L1S
219int max_processes = 64; /* Default number */ 218int max_processes = 64; /* Default number */
220#endif /* !PMAP_STATIC_L1S */ 219#endif /* !PMAP_STATIC_L1S */
221 220
222/* Physical and virtual addresses for some global pages */ 221/* Physical and virtual addresses for some global pages */
223pv_addr_t irqstack; 222pv_addr_t irqstack;
224pv_addr_t undstack; 223pv_addr_t undstack;
225pv_addr_t abtstack; 224pv_addr_t abtstack;
226extern pv_addr_t kernelstack; 225extern pv_addr_t kernelstack;
227pv_addr_t minidataclean; 226pv_addr_t minidataclean;
228 227
229paddr_t msgbufphys; 228paddr_t msgbufphys;
230 229
231extern u_int data_abort_handler_address; 230extern u_int data_abort_handler_address;
232extern u_int prefetch_abort_handler_address; 231extern u_int prefetch_abort_handler_address;
233extern u_int undefined_handler_address; 232extern u_int undefined_handler_address;
234 233
235#ifdef PMAP_DEBUG 234#ifdef PMAP_DEBUG
236extern int pmap_debug_level; 235extern int pmap_debug_level;
237#endif 236#endif
238 237
239#define KERNEL_PT_SYS 0 /* Page table for mapping proc0 zero page */ 238#define KERNEL_PT_SYS 0 /* Page table for mapping proc0 zero page */
240#define KERNEL_PT_KERNEL 1 /* Page table for mapping kernel */ 239#define KERNEL_PT_KERNEL 1 /* Page table for mapping kernel */
241#define KERNEL_PT_KERNEL_NUM ((KERNEL_VM_BASE - KERNEL_BASE) >> 22) 240#define KERNEL_PT_KERNEL_NUM ((KERNEL_VM_BASE - KERNEL_BASE) >> 22)
242#define KERNEL_PT_VMDATA (KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM) 241#define KERNEL_PT_VMDATA (KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM)
243 /* Page tables for mapping kernel VM */ 242 /* Page tables for mapping kernel VM */
244#define KERNEL_PT_VMDATA_NUM 4 /* start with 16MB of KVM */ 243#define KERNEL_PT_VMDATA_NUM 4 /* start with 16MB of KVM */
245#define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM) 244#define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
246 245
247pv_addr_t kernel_pt_table[NUM_KERNEL_PTS]; 246pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
248 247
249const char *console = 248const char *console =
250#ifdef FFUARTCONSOLE 249#ifdef FFUARTCONSOLE
251 "ffuart"; 250 "ffuart";
252#else 251#else
253 "glass"; 252 "glass";
254#endif 253#endif
255int glass_console = 0; 254int glass_console = 0;
256 255
257#ifdef KLOADER 256#ifdef KLOADER
258pv_addr_t bootinfo_pt; 257pv_addr_t bootinfo_pt;
259pv_addr_t bootinfo_pg; 258pv_addr_t bootinfo_pg;
260struct kloader_bootinfo kbootinfo; 259struct kloader_bootinfo kbootinfo;
261int kloader_howto = 0; 260int kloader_howto = 0;
262#else 261#else
263struct bootinfo _bootinfo; 262struct bootinfo _bootinfo;
264#endif 263#endif
265struct bootinfo *bootinfo; 264struct bootinfo *bootinfo;
266struct btinfo_howto *bi_howto; 265struct btinfo_howto *bi_howto;
267 266
268#define KERNEL_BASE_PHYS (PXA2X0_SDRAM0_START + KERNEL_TEXT_OFFSET) 267#define KERNEL_BASE_PHYS ((paddr_t)&KERNEL_BASE_phys)
269#define BOOTINFO_PAGE (KERNEL_BASE_PHYS - PAGE_SIZE) 268#define BOOTINFO_PAGE (KERNEL_BASE_PHYS - PAGE_SIZE)
270 269
271/* Prototypes */ 270/* Prototypes */
272void consinit(void); 271void consinit(void);
273void dumpsys(void); 272void dumpsys(void);
274#ifdef KGDB 273#ifdef KGDB
275void kgdb_port_init(void); 274void kgdb_port_init(void);
276#endif 275#endif
277#ifdef KLOADER 276#ifdef KLOADER
278static int parseboot(char *arg, char **filename, int *howto); 277static int parseboot(char *arg, char **filename, int *howto);
279static char *gettrailer(char *arg); 278static char *gettrailer(char *arg);
280static int parseopts(const char *opts, int *howto); 279static int parseopts(const char *opts, int *howto);
281#endif 280#endif
282 281
283#if defined(CPU_XSCALE_PXA250) 282#if defined(CPU_XSCALE_PXA250)
284static struct pxa2x0_gpioconf pxa25x_boarddep_gpioconf[] = { 283static struct pxa2x0_gpioconf pxa25x_boarddep_gpioconf[] = {
285 { 34, GPIO_ALT_FN_1_IN }, /* FFRXD */ 284 { 34, GPIO_ALT_FN_1_IN }, /* FFRXD */
286 { 35, GPIO_ALT_FN_1_IN }, /* FFCTS */ 285 { 35, GPIO_ALT_FN_1_IN }, /* FFCTS */
287 { 39, GPIO_ALT_FN_2_OUT }, /* FFTXD */ 286 { 39, GPIO_ALT_FN_2_OUT }, /* FFTXD */
288 { 40, GPIO_ALT_FN_2_OUT }, /* FFDTR */ 287 { 40, GPIO_ALT_FN_2_OUT }, /* FFDTR */
289 { 41, GPIO_ALT_FN_2_OUT }, /* FFRTS */ 288 { 41, GPIO_ALT_FN_2_OUT }, /* FFRTS */
290 289
291 { 44, GPIO_ALT_FN_1_IN }, /* BTCST */ 290 { 44, GPIO_ALT_FN_1_IN }, /* BTCST */
292 { 45, GPIO_ALT_FN_2_OUT }, /* BTRST */ 291 { 45, GPIO_ALT_FN_2_OUT }, /* BTRST */
293 292
294 { -1 } 293 { -1 }
295}; 294};
296static struct pxa2x0_gpioconf *pxa25x_zaurus_gpioconf[] = { 295static struct pxa2x0_gpioconf *pxa25x_zaurus_gpioconf[] = {
297 pxa25x_com_btuart_gpioconf, 296 pxa25x_com_btuart_gpioconf,
298 pxa25x_com_ffuart_gpioconf, 297 pxa25x_com_ffuart_gpioconf,
299 pxa25x_com_stuart_gpioconf, 298 pxa25x_com_stuart_gpioconf,
300 pxa25x_boarddep_gpioconf, 299 pxa25x_boarddep_gpioconf,
301 NULL 300 NULL
302}; 301};
303#else 302#else
304static struct pxa2x0_gpioconf *pxa25x_zaurus_gpioconf[] = { 303static struct pxa2x0_gpioconf *pxa25x_zaurus_gpioconf[] = {
305 NULL 304 NULL
306}; 305};
307#endif 306#endif
308#if defined(CPU_XSCALE_PXA270) 307#if defined(CPU_XSCALE_PXA270)
309static struct pxa2x0_gpioconf pxa27x_boarddep_gpioconf[] = { 308static struct pxa2x0_gpioconf pxa27x_boarddep_gpioconf[] = {
310 { 34, GPIO_ALT_FN_1_IN }, /* FFRXD */ 309 { 34, GPIO_ALT_FN_1_IN }, /* FFRXD */
311 { 35, GPIO_ALT_FN_1_IN }, /* FFCTS */ 310 { 35, GPIO_ALT_FN_1_IN }, /* FFCTS */
312 { 39, GPIO_ALT_FN_2_OUT }, /* FFTXD */ 311 { 39, GPIO_ALT_FN_2_OUT }, /* FFTXD */
313 { 40, GPIO_ALT_FN_2_OUT }, /* FFDTR */ 312 { 40, GPIO_ALT_FN_2_OUT }, /* FFDTR */
314 { 41, GPIO_ALT_FN_2_OUT }, /* FFRTS */ 313 { 41, GPIO_ALT_FN_2_OUT }, /* FFRTS */
315 314
316 { 44, GPIO_ALT_FN_1_IN }, /* BTCST */ 315 { 44, GPIO_ALT_FN_1_IN }, /* BTCST */
317 { 45, GPIO_ALT_FN_2_OUT }, /* BTRST */ 316 { 45, GPIO_ALT_FN_2_OUT }, /* BTRST */
318 317
319 { 104, GPIO_ALT_FN_1_OUT }, /* pSKTSEL */ 318 { 104, GPIO_ALT_FN_1_OUT }, /* pSKTSEL */
320 319
321 { -1 } 320 { -1 }
322}; 321};
323static struct pxa2x0_gpioconf *pxa27x_zaurus_gpioconf[] = { 322static struct pxa2x0_gpioconf *pxa27x_zaurus_gpioconf[] = {
324 pxa27x_com_btuart_gpioconf, 323 pxa27x_com_btuart_gpioconf,
325 pxa27x_com_ffuart_gpioconf, 324 pxa27x_com_ffuart_gpioconf,
326 pxa27x_com_stuart_gpioconf, 325 pxa27x_com_stuart_gpioconf,
327 pxa27x_i2c_gpioconf, 326 pxa27x_i2c_gpioconf,
328 pxa27x_i2s_gpioconf, 327 pxa27x_i2s_gpioconf,
329 pxa27x_pxamci_gpioconf, 328 pxa27x_pxamci_gpioconf,
330 pxa27x_boarddep_gpioconf, 329 pxa27x_boarddep_gpioconf,
331 NULL 330 NULL
332}; 331};
333#else 332#else
334static struct pxa2x0_gpioconf *pxa27x_zaurus_gpioconf[] = { 333static struct pxa2x0_gpioconf *pxa27x_zaurus_gpioconf[] = {
335 NULL 334 NULL
336}; 335};
337#endif 336#endif
338 337
339/* 338/*
340 * void cpu_reboot(int howto, char *bootstr) 339 * void cpu_reboot(int howto, char *bootstr)
341 * 340 *
342 * Reboots the system 341 * Reboots the system
343 * 342 *
344 * Deal with any syncing, unmounting, dumping and shutdown hooks, 343 * Deal with any syncing, unmounting, dumping and shutdown hooks,
345 * then reset the CPU. 344 * then reset the CPU.
346 */ 345 */
347void 346void
348cpu_reboot(int howto, char *bootstr) 347cpu_reboot(int howto, char *bootstr)
349{ 348{
350 /* 349 /*
351 * If we are still cold then hit the air brakes 350 * If we are still cold then hit the air brakes
352 * and crash to earth fast 351 * and crash to earth fast
353 */ 352 */
354 if (cold) { 353 if (cold) {
355 howto |= RB_HALT; 354 howto |= RB_HALT;
356 goto haltsys; 355 goto haltsys;
357 } 356 }
358 357
359 boothowto = howto; 358 boothowto = howto;
360 359
361#ifdef KLOADER 360#ifdef KLOADER
362 if ((howto & RB_HALT) == 0 && panicstr == NULL) { 361 if ((howto & RB_HALT) == 0 && panicstr == NULL) {
363 char *filename = NULL; 362 char *filename = NULL;
364 363
365 if ((howto & RB_STRING) && (bootstr != NULL)) { 364 if ((howto & RB_STRING) && (bootstr != NULL)) {
366 if (parseboot(bootstr, &filename, &kloader_howto) == 0){ 365 if (parseboot(bootstr, &filename, &kloader_howto) == 0){
367 filename = NULL; 366 filename = NULL;
368 kloader_howto = 0; 367 kloader_howto = 0;
369 } 368 }
370 } 369 }
371 if (kloader_howto != 0) { 370 if (kloader_howto != 0) {
372 printf("howto: 0x%x\n", kloader_howto); 371 printf("howto: 0x%x\n", kloader_howto);
373 } 372 }
374 if (filename != NULL) { 373 if (filename != NULL) {
375 kloader_reboot_setup(filename); 374 kloader_reboot_setup(filename);
376 } else { 375 } else {
377 kloader_reboot_setup(KLOADER_KERNEL_PATH); 376 kloader_reboot_setup(KLOADER_KERNEL_PATH);
378 } 377 }
379 } 378 }
380#endif 379#endif
381 380
382 /* 381 /*
383 * If RB_NOSYNC was not specified sync the discs. 382 * If RB_NOSYNC was not specified sync the discs.
384 * Note: Unless cold is set to 1 here, syslogd will die during the 383 * Note: Unless cold is set to 1 here, syslogd will die during the
385 * unmount. It looks like syslogd is getting woken up only to find 384 * unmount. It looks like syslogd is getting woken up only to find
386 * that it cannot page part of the binary in as the filesystem has 385 * that it cannot page part of the binary in as the filesystem has
387 * been unmounted. 386 * been unmounted.
388 */ 387 */
389 if (!(howto & RB_NOSYNC)) { 388 if (!(howto & RB_NOSYNC)) {
390 bootsync(); 389 bootsync();
391 /* 390 /*
392 * If we've been adjusting the clock, the todr 391 * If we've been adjusting the clock, the todr
393 * will be out of synch; adjust it now. 392 * will be out of synch; adjust it now.
394 */ 393 */
395 resettodr(); 394 resettodr();
396 } 395 }
397 396
398 /* Wait 3s */ 397 /* Wait 3s */
399 delay(3 * 1000 * 1000); 398 delay(3 * 1000 * 1000);
400 399
401 /* Say NO to interrupts */ 400 /* Say NO to interrupts */
402 splhigh(); 401 splhigh();
403 402
404 /* Do a dump if requested. */ 403 /* Do a dump if requested. */
405 if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP) 404 if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
406 dumpsys(); 405 dumpsys();
407 406
408haltsys: 407haltsys:
409 /* Run any shutdown hooks */ 408 /* Run any shutdown hooks */
410 doshutdownhooks(); 409 doshutdownhooks();
411 410
412 pmf_system_shutdown(boothowto); 411 pmf_system_shutdown(boothowto);
413 412
414 /* Make sure IRQ's are disabled */ 413 /* Make sure IRQ's are disabled */
415 IRQdisable; 414 IRQdisable;
416 415
417 if (howto & RB_HALT) { 416 if (howto & RB_HALT) {
418#if NAPM > 0 417#if NAPM > 0
419 if (howto & RB_POWERDOWN) { 418 if (howto & RB_POWERDOWN) {
420 printf("\nAttempting to power down...\n"); 419 printf("\nAttempting to power down...\n");
421 zapm_poweroff(); 420 zapm_poweroff();
422 } 421 }
423#endif 422#endif
424 printf("The operating system has halted.\n"); 423 printf("The operating system has halted.\n");
425 printf("Please press any key to reboot.\n\n"); 424 printf("Please press any key to reboot.\n\n");
426 cngetc(); 425 cngetc();
427 } 426 }
428#ifdef KLOADER 427#ifdef KLOADER
429 else if (panicstr == NULL) { 428 else if (panicstr == NULL) {
430 delay(1 * 1000 * 1000); 429 delay(1 * 1000 * 1000);
431 kloader_reboot(); 430 kloader_reboot();
432 printf("\n"); 431 printf("\n");
433 printf("Failed to load a new kernel.\n"); 432 printf("Failed to load a new kernel.\n");
434 printf("Please press any key to reboot.\n\n"); 433 printf("Please press any key to reboot.\n\n");
435 cngetc(); 434 cngetc();
436 } 435 }
437#endif 436#endif
438 437
439 printf("rebooting...\n"); 438 printf("rebooting...\n");
440 delay(1 * 1000 * 1000); 439 delay(1 * 1000 * 1000);
441 zaurus_restart(); 440 zaurus_restart();
442 441
443 printf("REBOOT FAILED!!!\n"); 442 printf("REBOOT FAILED!!!\n");
444 for (;;) 443 for (;;)
445 continue; 444 continue;
446 /*NOTREACHED*/ 445 /*NOTREACHED*/
447} 446}
448 447
449/* 448/*
450 * Do a GPIO reset, immediately causing the processor to begin the normal 449 * Do a GPIO reset, immediately causing the processor to begin the normal
451 * boot sequence. See 2.7 Reset in the PXA27x Developer's Manual for the 450 * boot sequence. See 2.7 Reset in the PXA27x Developer's Manual for the
452 * summary of effects of this kind of reset. 451 * summary of effects of this kind of reset.
453 */ 452 */
454void 453void
455zaurus_restart(void) 454zaurus_restart(void)
456{ 455{
457 uint32_t rv; 456 uint32_t rv;
458 457
459 rv = pxa2x0_memctl_read(MEMCTL_MSC0); 458 rv = pxa2x0_memctl_read(MEMCTL_MSC0);
460 if ((rv & 0xffff0000) == 0x7ff00000) { 459 if ((rv & 0xffff0000) == 0x7ff00000) {
461 pxa2x0_memctl_write(MEMCTL_MSC0, (rv & 0xffff) | 0x7ee00000); 460 pxa2x0_memctl_write(MEMCTL_MSC0, (rv & 0xffff) | 0x7ee00000);
462 } 461 }
463 462
464 /* External reset circuit presumably asserts nRESET_GPIO. */ 463 /* External reset circuit presumably asserts nRESET_GPIO. */
465 pxa2x0_gpio_set_function(89, GPIO_OUT | GPIO_SET); 464 pxa2x0_gpio_set_function(89, GPIO_OUT | GPIO_SET);
466 delay(1 * 1000* 1000); /* wait 1s */ 465 delay(1 * 1000* 1000); /* wait 1s */
467} 466}
468 467
469static inline pd_entry_t * 468static inline pd_entry_t *
470read_ttb(void) 469read_ttb(void)
471{ 470{
472 u_long ttb; 471 u_long ttb;
473 472
474 __asm volatile("mrc p15, 0, %0, c2, c0, 0" : "=r" (ttb)); 473 __asm volatile("mrc p15, 0, %0, c2, c0, 0" : "=r" (ttb));
475 474
476 return (pd_entry_t *)(ttb & ~((1 << 14) - 1)); 475 return (pd_entry_t *)(ttb & ~((1 << 14) - 1));
477} 476}
478 477
479/* 478/*
480 * Static device mappings. These peripheral registers are mapped at 479 * Static device mappings. These peripheral registers are mapped at
481 * fixed virtual addresses very early in initarm() so that we can use 480 * fixed virtual addresses very early in initarm() so that we can use
482 * them while booting the kernel, and stay at the same address 481 * them while booting the kernel, and stay at the same address
483 * throughout whole kernel's life time. 482 * throughout whole kernel's life time.
484 * 483 *
485 * We use this table twice; once with bootstrap page table, and once 484 * We use this table twice; once with bootstrap page table, and once
486 * with kernel's page table which we build up in initarm(). 485 * with kernel's page table which we build up in initarm().
487 * 486 *
488 * Since we map these registers into the bootstrap page table using 487 * Since we map these registers into the bootstrap page table using
489 * pmap_devmap_bootstrap() which calls pmap_map_chunk(), we map 488 * pmap_devmap_bootstrap() which calls pmap_map_chunk(), we map
490 * registers segment-aligned and segment-rounded in order to avoid 489 * registers segment-aligned and segment-rounded in order to avoid
491 * using the 2nd page tables. 490 * using the 2nd page tables.
492 */ 491 */
493#define _A(a) ((a) & ~L1_S_OFFSET) 492#define _A(a) ((a) & ~L1_S_OFFSET)
494#define _S(s) (((s) + L1_S_SIZE - 1) & ~(L1_S_SIZE-1)) 493#define _S(s) (((s) + L1_S_SIZE - 1) & ~(L1_S_SIZE-1))
495 494
496static const struct pmap_devmap zaurus_devmap[] = { 495static const struct pmap_devmap zaurus_devmap[] = {
497 { 496 {
498 ZAURUS_GPIO_VBASE, 497 ZAURUS_GPIO_VBASE,
499 _A(PXA2X0_GPIO_BASE), 498 _A(PXA2X0_GPIO_BASE),
500 _S(PXA2X0_GPIO_SIZE), 499 _S(PXA2X0_GPIO_SIZE),
501 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE, 500 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
502 }, 501 },
503 { 502 {
504 ZAURUS_CLKMAN_VBASE, 503 ZAURUS_CLKMAN_VBASE,
505 _A(PXA2X0_CLKMAN_BASE), 504 _A(PXA2X0_CLKMAN_BASE),
506 _S(PXA2X0_CLKMAN_SIZE), 505 _S(PXA2X0_CLKMAN_SIZE),
507 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE, 506 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
508 }, 507 },
509 { 508 {
510 ZAURUS_INTCTL_VBASE, 509 ZAURUS_INTCTL_VBASE,
511 _A(PXA2X0_INTCTL_BASE), 510 _A(PXA2X0_INTCTL_BASE),
512 _S(PXA2X0_INTCTL_SIZE), 511 _S(PXA2X0_INTCTL_SIZE),
513 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE, 512 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
514 }, 513 },
515 { 514 {
516 ZAURUS_MEMCTL_VBASE, 515 ZAURUS_MEMCTL_VBASE,
517 _A(PXA2X0_MEMCTL_BASE), 516 _A(PXA2X0_MEMCTL_BASE),
518 _S(PXA2X0_MEMCTL_SIZE), 517 _S(PXA2X0_MEMCTL_SIZE),
519 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE, 518 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
520 }, 519 },
521 { 520 {
522 ZAURUS_SCOOP0_VBASE, 521 ZAURUS_SCOOP0_VBASE,
523 _A(C3000_SCOOP0_BASE), 522 _A(C3000_SCOOP0_BASE),
524 _S(SCOOP_SIZE), 523 _S(SCOOP_SIZE),
525 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE, 524 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
526 }, 525 },
527 { 526 {
528 ZAURUS_SCOOP1_VBASE, 527 ZAURUS_SCOOP1_VBASE,
529 _A(C3000_SCOOP1_BASE), 528 _A(C3000_SCOOP1_BASE),
530 _S(SCOOP_SIZE), 529 _S(SCOOP_SIZE),
531 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE, 530 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
532 }, 531 },
533 { 532 {
534 ZAURUS_FFUART_VBASE, 533 ZAURUS_FFUART_VBASE,
535 _A(PXA2X0_FFUART_BASE), 534 _A(PXA2X0_FFUART_BASE),
536 _S(4 * COM_NPORTS), 535 _S(4 * COM_NPORTS),
537 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE, 536 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
538 }, 537 },
539 { 538 {
540 ZAURUS_BTUART_VBASE, 539 ZAURUS_BTUART_VBASE,
541 _A(PXA2X0_BTUART_BASE), 540 _A(PXA2X0_BTUART_BASE),
542 _S(4 * COM_NPORTS), 541 _S(4 * COM_NPORTS),
543 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE, 542 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
544 }, 543 },
545 { 544 {
546 ZAURUS_STUART_VBASE, 545 ZAURUS_STUART_VBASE,
547 _A(PXA2X0_STUART_BASE), 546 _A(PXA2X0_STUART_BASE),
548 _S(4 * COM_NPORTS), 547 _S(4 * COM_NPORTS),
549 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE, 548 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
550 }, 549 },
551 550
552 {0, 0, 0, 0, 0,} 551 {0, 0, 0, 0, 0,}
553}; 552};
554 553
555#undef _A 554#undef _A
556#undef _S 555#undef _S
557 556
558void green_on(int virt); 557void green_on(int virt);
559void 558void
560green_on(int virt) 559green_on(int virt)
561{ 560{
562 /* clobber green led p */ 561 /* clobber green led p */
563 volatile uint16_t *p; 562 volatile uint16_t *p;
564 563
565 if (virt) { 564 if (virt) {
566 p = (volatile uint16_t *)(ZAURUS_SCOOP0_VBASE + SCOOP_GPWR); 565 p = (volatile uint16_t *)(ZAURUS_SCOOP0_VBASE + SCOOP_GPWR);
567 } else { 566 } else {
568 p = (volatile uint16_t *)(C3000_SCOOP0_BASE + SCOOP_GPWR); 567 p = (volatile uint16_t *)(C3000_SCOOP0_BASE + SCOOP_GPWR);
569 } 568 }
570 569
571 *p |= (1 << SCOOP0_LED_GREEN); 570 *p |= (1 << SCOOP0_LED_GREEN);
572} 571}
573 572
574void irda_on(int virt); 573void irda_on(int virt);
575void 574void
576irda_on(int virt) 575irda_on(int virt)
577{ 576{
578 /* clobber IrDA led p */ 577 /* clobber IrDA led p */
579 volatile uint16_t *p; 578 volatile uint16_t *p;
580 579
581 if (virt) { 580 if (virt) {
582 /* XXX scoop1 registers are not page-aligned! */ 581 /* XXX scoop1 registers are not page-aligned! */
583 int o = C3000_SCOOP1_BASE - trunc_page(C3000_SCOOP1_BASE); 582 int o = C3000_SCOOP1_BASE - trunc_page(C3000_SCOOP1_BASE);
584 p = (volatile uint16_t *)(ZAURUS_SCOOP1_VBASE + o + SCOOP_GPWR); 583 p = (volatile uint16_t *)(ZAURUS_SCOOP1_VBASE + o + SCOOP_GPWR);
585 } else { 584 } else {
586 p = (volatile uint16_t *)(C3000_SCOOP1_BASE + SCOOP_GPWR); 585 p = (volatile uint16_t *)(C3000_SCOOP1_BASE + SCOOP_GPWR);
587 } 586 }
588 587
589 *p &= ~(1 << SCOOP1_IR_ON); 588 *p &= ~(1 << SCOOP1_IR_ON);
590} 589}
591 590
592static int 591static int
593hw_isc1000(void) 592hw_isc1000(void)
594{ 593{
595 /* XXX scoop1 registers are not page-aligned! */ 594 /* XXX scoop1 registers are not page-aligned! */
596 const u_long baseaddr = ZAURUS_SCOOP1_VBASE + 595 const u_long baseaddr = ZAURUS_SCOOP1_VBASE +
597 (C3000_SCOOP1_BASE - trunc_page(C3000_SCOOP1_BASE)); 596 (C3000_SCOOP1_BASE - trunc_page(C3000_SCOOP1_BASE));
598 uint16_t mcr, cdr, csr, cpr, ccr, irr, irm, imr, isr; 597 uint16_t mcr, cdr, csr, cpr, ccr, irr, irm, imr, isr;
599 uint16_t gpcr, gpwr, gprr; 598 uint16_t gpcr, gpwr, gprr;
600 599
601 mcr = ioreg16_read(baseaddr + SCOOP_MCR); 600 mcr = ioreg16_read(baseaddr + SCOOP_MCR);
602 cdr = ioreg16_read(baseaddr + SCOOP_CDR); 601 cdr = ioreg16_read(baseaddr + SCOOP_CDR);
603 csr = ioreg16_read(baseaddr + SCOOP_CSR); 602 csr = ioreg16_read(baseaddr + SCOOP_CSR);
604 cpr = ioreg16_read(baseaddr + SCOOP_CPR); 603 cpr = ioreg16_read(baseaddr + SCOOP_CPR);
605 ccr = ioreg16_read(baseaddr + SCOOP_CCR); 604 ccr = ioreg16_read(baseaddr + SCOOP_CCR);
606 irr = ioreg16_read(baseaddr + SCOOP_IRR); 605 irr = ioreg16_read(baseaddr + SCOOP_IRR);
607 irm = ioreg16_read(baseaddr + SCOOP_IRM); 606 irm = ioreg16_read(baseaddr + SCOOP_IRM);
608 imr = ioreg16_read(baseaddr + SCOOP_IMR); 607 imr = ioreg16_read(baseaddr + SCOOP_IMR);
609 isr = ioreg16_read(baseaddr + SCOOP_ISR); 608 isr = ioreg16_read(baseaddr + SCOOP_ISR);
610 gpcr = ioreg16_read(baseaddr + SCOOP_GPCR); 609 gpcr = ioreg16_read(baseaddr + SCOOP_GPCR);
611 gpwr = ioreg16_read(baseaddr + SCOOP_GPWR); 610 gpwr = ioreg16_read(baseaddr + SCOOP_GPWR);
612 gprr = ioreg16_read(baseaddr + SCOOP_GPRR); 611 gprr = ioreg16_read(baseaddr + SCOOP_GPRR);
613 612
614 if (mcr == 0 && cdr == 0 && csr == 0 && cpr == 0 && ccr == 0 && 613 if (mcr == 0 && cdr == 0 && csr == 0 && cpr == 0 && ccr == 0 &&
615 irr == 0 && irm == 0 && imr == 0 && isr == 0 && 614 irr == 0 && irm == 0 && imr == 0 && isr == 0 &&
616 gpcr == 0 && gpwr == 0 && gprr == 0) { 615 gpcr == 0 && gpwr == 0 && gprr == 0) {
617 /* scoop1 isn't found: hardware is SL-C1000 */ 616 /* scoop1 isn't found: hardware is SL-C1000 */
618 return 1; 617 return 1;
619 } 618 }
620 return 0; 619 return 0;
621} 620}
622 621
623/* 622/*
624 * u_int initarm(...) 623 * u_int initarm(...)
625 * 624 *
626 * Initial entry point on startup. This gets called before main() is 625 * Initial entry point on startup. This gets called before main() is
627 * entered. 626 * entered.
628 * It should be responsible for setting up everything that must be 627 * It should be responsible for setting up everything that must be
629 * in place when main is called. 628 * in place when main is called.
630 * This includes 629 * This includes
631 * Taking a copy of the boot configuration structure. 630 * Taking a copy of the boot configuration structure.
632 * Initialising the physical console so characters can be printed. 631 * Initialising the physical console so characters can be printed.
633 * Setting up page tables for the kernel 632 * Setting up page tables for the kernel
634 * Relocating the kernel to the bottom of physical memory 633 * Relocating the kernel to the bottom of physical memory
635 */ 634 */
636u_int 635u_int
637initarm(void *arg) 636initarm(void *arg)
638{ 637{
639#ifdef DIAGNOSTIC 638#ifdef DIAGNOSTIC
640 extern vsize_t xscale_minidata_clean_size; /* used in KASSERT */ 639 extern vsize_t xscale_minidata_clean_size; /* used in KASSERT */
641#endif 640#endif
642 extern vaddr_t xscale_cache_clean_addr; 641 extern vaddr_t xscale_cache_clean_addr;
 642 extern char KERNEL_BASE_phys[], KERNEL_BASE_virt[];
643 int loop; 643 int loop;
644 int loop1; 644 int loop1;
645 u_int l1pagetable; 645 u_int l1pagetable;
646 paddr_t memstart; 646 paddr_t memstart;
647 psize_t memsize; 647 psize_t memsize;
648 struct pxa2x0_gpioconf **zaurus_gpioconf; 648 struct pxa2x0_gpioconf **zaurus_gpioconf;
649 u_int *magicaddr; 649 u_int *magicaddr;
650 650
651 /* Get ready for zaurus_restart() */ 651 /* Get ready for zaurus_restart() */
652 pxa2x0_memctl_bootstrap(PXA2X0_MEMCTL_BASE); 652 pxa2x0_memctl_bootstrap(PXA2X0_MEMCTL_BASE);
653 653
654 /* 654 /*
655 * Heads up ... Setup the CPU / MMU / TLB functions 655 * Heads up ... Setup the CPU / MMU / TLB functions
656 */ 656 */
657 if (set_cpufuncs()) 657 if (set_cpufuncs())
658 panic("cpu not recognized!"); 658 panic("cpu not recognized!");
659 659
660 /* Get ready for splfoo() */ 660 /* Get ready for splfoo() */
661 pxa2x0_intr_bootstrap(PXA2X0_INTCTL_BASE); 661 pxa2x0_intr_bootstrap(PXA2X0_INTCTL_BASE);
662 662
663 /* map some peripheral registers at static I/O area */ 663 /* map some peripheral registers at static I/O area */
664 pmap_devmap_bootstrap((vaddr_t)read_ttb(), zaurus_devmap); 664 pmap_devmap_bootstrap((vaddr_t)read_ttb(), zaurus_devmap);
665 665
666 /* set new memctl register address so that zaurus_restart() doesn't 666 /* set new memctl register address so that zaurus_restart() doesn't
667 touch illegal address. */ 667 touch illegal address. */
668 pxa2x0_memctl_bootstrap(ZAURUS_MEMCTL_VBASE); 668 pxa2x0_memctl_bootstrap(ZAURUS_MEMCTL_VBASE);
669 669
670 /* set new intc register address so that splfoo() doesn't 670 /* set new intc register address so that splfoo() doesn't
671 touch illegal address. */ 671 touch illegal address. */
672 pxa2x0_intr_bootstrap(ZAURUS_INTCTL_VBASE); 672 pxa2x0_intr_bootstrap(ZAURUS_INTCTL_VBASE);
673 673
674 /* 674 /*
675 * Examine the boot args string for options we need to know about 675 * Examine the boot args string for options we need to know about
676 * now. 676 * now.
677 */ 677 */
678 magicaddr = (u_int *)(KERNEL_BASE_PHYS - BOOTARGS_BUFSIZ); 678 magicaddr = (u_int *)(KERNEL_BASE_PHYS - BOOTARGS_BUFSIZ);
679 if (*magicaddr == BOOTARGS_MAGIC) { 679 if (*magicaddr == BOOTARGS_MAGIC) {
680#ifdef KLOADER 680#ifdef KLOADER
681 bootinfo = &kbootinfo.bootinfo; 681 bootinfo = &kbootinfo.bootinfo;
682#else 682#else
683 bootinfo = &_bootinfo; 683 bootinfo = &_bootinfo;
684#endif 684#endif
685 memcpy(bootinfo, (void *)(KERNEL_BASE_PHYS - BOOTINFO_MAXSIZE), 685 memcpy(bootinfo, (void *)(KERNEL_BASE_PHYS - BOOTINFO_MAXSIZE),
686 BOOTINFO_MAXSIZE); 686 BOOTINFO_MAXSIZE);
687 bi_howto = lookup_bootinfo(BTINFO_HOWTO); 687 bi_howto = lookup_bootinfo(BTINFO_HOWTO);
688 boothowto = (bi_howto != NULL) ? bi_howto->howto : RB_AUTOBOOT; 688 boothowto = (bi_howto != NULL) ? bi_howto->howto : RB_AUTOBOOT;
689 } else { 689 } else {
690 boothowto = RB_AUTOBOOT; 690 boothowto = RB_AUTOBOOT;
691 } 691 }
692 *magicaddr = 0xdeadbeef; 692 *magicaddr = 0xdeadbeef;
693#ifdef RAMDISK_HOOKS 693#ifdef RAMDISK_HOOKS
694 boothowto |= RB_DFLTROOT; 694 boothowto |= RB_DFLTROOT;
695#endif /* RAMDISK_HOOKS */ 695#endif /* RAMDISK_HOOKS */
696 if (boothowto & RB_MD1) { 696 if (boothowto & RB_MD1) {
697 /* serial console */ 697 /* serial console */
698 console = "ffuart"; 698 console = "ffuart";
699 } 699 }
700 700
701 memstart = PXA2X0_SDRAM0_START; 701 memstart = PXA2X0_SDRAM0_START;
702 memsize = 0x04000000; /* 64MB */ 702 memsize = 0x04000000; /* 64MB */
703 703
704 /* 704 /*
705 * This test will work for now but has to be revised when support 705 * This test will work for now but has to be revised when support
706 * for other models is added. 706 * for other models is added.
707 */ 707 */
708 if ((cputype & ~CPU_ID_XSCALE_COREREV_MASK) == CPU_ID_PXA27X) { 708 if ((cputype & ~CPU_ID_XSCALE_COREREV_MASK) == CPU_ID_PXA27X) {
709 if (hw_isc1000()) 709 if (hw_isc1000())
710 zaurusmod = ZAURUS_C1000; /* SL-C1000 */ 710 zaurusmod = ZAURUS_C1000; /* SL-C1000 */
711 else 711 else
712 zaurusmod = ZAURUS_C3000; /* SL-C3x00 */ 712 zaurusmod = ZAURUS_C3000; /* SL-C3x00 */
713 zaurus_gpioconf = pxa27x_zaurus_gpioconf; 713 zaurus_gpioconf = pxa27x_zaurus_gpioconf;
714 } else { 714 } else {
715 zaurusmod = ZAURUS_C860; /* SL-C7x0/860 */ 715 zaurusmod = ZAURUS_C860; /* SL-C7x0/860 */
716 if (cputype == CPU_ID_PXA250B) { 716 if (cputype == CPU_ID_PXA250B) {
717 /* SL-C700 */ 717 /* SL-C700 */
718 memsize = 0x02000000; /* 32MB */ 718 memsize = 0x02000000; /* 32MB */
719 } 719 }
720 zaurus_gpioconf = pxa25x_zaurus_gpioconf; 720 zaurus_gpioconf = pxa25x_zaurus_gpioconf;
721 } 721 }
722 722
723 /* setup a serial console for very early boot */ 723 /* setup a serial console for very early boot */
724 pxa2x0_gpio_bootstrap(ZAURUS_GPIO_VBASE); 724 pxa2x0_gpio_bootstrap(ZAURUS_GPIO_VBASE);
725 pxa2x0_gpio_config(zaurus_gpioconf); 725 pxa2x0_gpio_config(zaurus_gpioconf);
726 pxa2x0_clkman_bootstrap(ZAURUS_CLKMAN_VBASE); 726 pxa2x0_clkman_bootstrap(ZAURUS_CLKMAN_VBASE);
727 if (strcmp(console, "glass") != 0) 727 if (strcmp(console, "glass") != 0)
728 consinit(); 728 consinit();
729#ifdef KGDB 729#ifdef KGDB
730 kgdb_port_init(); 730 kgdb_port_init();
731#endif 731#endif
732 732
733#ifdef VERBOSE_INIT_ARM 733#ifdef VERBOSE_INIT_ARM
734 /* Talk to the user */ 734 /* Talk to the user */
735 printf("\nNetBSD/zaurus booting ...\n"); 735 printf("\nNetBSD/zaurus booting ...\n");
736#endif 736#endif
737 737
738#ifdef KLOADER 738#ifdef KLOADER
739 /* copy boot parameter for kloader */ 739 /* copy boot parameter for kloader */
740 kloader_bootinfo_set(&kbootinfo, 0, NULL, NULL, true); 740 kloader_bootinfo_set(&kbootinfo, 0, NULL, NULL, true);
741#endif 741#endif
742 742
743#ifdef VERBOSE_INIT_ARM 743#ifdef VERBOSE_INIT_ARM
744 printf("initarm: Configuring system ...\n"); 744 printf("initarm: Configuring system ...\n");
745#endif 745#endif
746 746
747 /* Fake bootconfig structure for the benefit of pmap.c */ 747 /* Fake bootconfig structure for the benefit of pmap.c */
748 /* XXX must make the memory description h/w independent */ 748 /* XXX must make the memory description h/w independent */
749 bootconfig.dramblocks = 1; 749 bootconfig.dramblocks = 1;
750 bootconfig.dram[0].address = memstart; 750 bootconfig.dram[0].address = memstart;
751 bootconfig.dram[0].pages = memsize / PAGE_SIZE; 751 bootconfig.dram[0].pages = memsize / PAGE_SIZE;
752 752
753 /* 753 /*
754 * Set up the variables that define the availablilty of 754 * Set up the variables that define the availablilty of
755 * physical memory. For now, we're going to set 755 * physical memory. For now, we're going to set
756 * physical_freestart to 0xa0200000 (where the kernel 756 * physical_freestart to 0xa0200000 (where the kernel
757 * was loaded), and allocate the memory we need downwards. 757 * was loaded), and allocate the memory we need downwards.
758 * If we get too close to the page tables that RedBoot 758 * If we get too close to the page tables that RedBoot
759 * set up, we will panic. We will update physical_freestart 759 * set up, we will panic. We will update physical_freestart
760 * and physical_freeend later to reflect what pmap_bootstrap() 760 * and physical_freeend later to reflect what pmap_bootstrap()
761 * wants to see. 761 * wants to see.
762 * 762 *
763 * XXX pmap_bootstrap() needs an enema. 763 * XXX pmap_bootstrap() needs an enema.
764 */ 764 */
765 physical_start = bootconfig.dram[0].address; 765 physical_start = bootconfig.dram[0].address;
766 physical_end = physical_start + (bootconfig.dram[0].pages * PAGE_SIZE); 766 physical_end = physical_start + (bootconfig.dram[0].pages * PAGE_SIZE);
767 767
768 physical_freestart = PXA2X0_SDRAM0_START + 0x9000; 768 physical_freestart = PXA2X0_SDRAM0_START + 0x9000;
769 physical_freeend = BOOTINFO_PAGE; 769 physical_freeend = BOOTINFO_PAGE;
770 770
771 physmem = (physical_end - physical_start) / PAGE_SIZE; 771 physmem = (physical_end - physical_start) / PAGE_SIZE;
772 772
773#ifdef VERBOSE_INIT_ARM 773#ifdef VERBOSE_INIT_ARM
774 /* Tell the user about the memory */ 774 /* Tell the user about the memory */
775 printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem, 775 printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
776 physical_start, physical_end - 1); 776 physical_start, physical_end - 1);
777#endif 777#endif
778 778
779 /* 779 /*
780 * Okay, the kernel starts 2MB in from the bottom of physical 780 * Okay, the kernel starts 2MB in from the bottom of physical
781 * memory. We are going to allocate our bootstrap pages downwards 781 * memory. We are going to allocate our bootstrap pages downwards
782 * from there. 782 * from there.
783 * 783 *
784 * We need to allocate some fixed page tables to get the kernel 784 * We need to allocate some fixed page tables to get the kernel
785 * going. We allocate one page directory and a number of page 785 * going. We allocate one page directory and a number of page
786 * tables and store the physical addresses in the kernel_pt_table 786 * tables and store the physical addresses in the kernel_pt_table
787 * array. 787 * array.
788 * 788 *
789 * The kernel page directory must be on a 16K boundary. The page 789 * The kernel page directory must be on a 16K boundary. The page
790 * tables must be on 4K bounaries. What we do is allocate the 790 * tables must be on 4K bounaries. What we do is allocate the
791 * page directory on the first 16K boundary that we encounter, and 791 * page directory on the first 16K boundary that we encounter, and
792 * the page tables on 4K boundaries otherwise. Since we allocate 792 * the page tables on 4K boundaries otherwise. Since we allocate
793 * at least 3 L2 page tables, we are guaranteed to encounter at 793 * at least 3 L2 page tables, we are guaranteed to encounter at
794 * least one 16K aligned region. 794 * least one 16K aligned region.
795 */ 795 */
796 796
797#ifdef VERBOSE_INIT_ARM 797#ifdef VERBOSE_INIT_ARM
798 printf("Allocating page tables\n"); 798 printf("Allocating page tables\n");
799#endif 799#endif
800 800
801 free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE; 801 free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
802 802
803#ifdef VERBOSE_INIT_ARM 803#ifdef VERBOSE_INIT_ARM
804 printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n", 804 printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n",
805 physical_freestart, free_pages, free_pages); 805 physical_freestart, free_pages, free_pages);
806#endif 806#endif
807 807
808 /* Define a macro to simplify memory allocation */ 808 /* Define a macro to simplify memory allocation */
809#define valloc_pages(var, np) \ 809#define valloc_pages(var, np) \
810 alloc_pages((var).pv_pa, (np)); \ 810 alloc_pages((var).pv_pa, (np)); \
811 (var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start; 811 (var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
812 812
813#define alloc_pages(var, np) \ 813#define alloc_pages(var, np) \
814 physical_freeend -= ((np) * PAGE_SIZE); \ 814 physical_freeend -= ((np) * PAGE_SIZE); \
815 if (physical_freeend < physical_freestart) \ 815 if (physical_freeend < physical_freestart) \
816 panic("initarm: out of memory"); \ 816 panic("initarm: out of memory"); \
817 (var) = physical_freeend; \ 817 (var) = physical_freeend; \
818 free_pages -= (np); \ 818 free_pages -= (np); \
819 memset((char *)(var), 0, ((np) * PAGE_SIZE)); 819 memset((char *)(var), 0, ((np) * PAGE_SIZE));
820 820
821 loop1 = 0; 821 loop1 = 0;
822 for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) { 822 for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
823 /* Are we 16KB aligned for an L1 ? */ 823 /* Are we 16KB aligned for an L1 ? */
824 if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0 824 if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0
825 && kernel_l1pt.pv_pa == 0) { 825 && kernel_l1pt.pv_pa == 0) {
826 valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE); 826 valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
827 } else { 827 } else {
828 valloc_pages(kernel_pt_table[loop1], 828 valloc_pages(kernel_pt_table[loop1],
829 L2_TABLE_SIZE / PAGE_SIZE); 829 L2_TABLE_SIZE / PAGE_SIZE);
830 ++loop1; 830 ++loop1;
831 } 831 }
832 } 832 }
833#ifdef KLOADER 833#ifdef KLOADER
834 valloc_pages(bootinfo_pt, L2_TABLE_SIZE / PAGE_SIZE); 834 valloc_pages(bootinfo_pt, L2_TABLE_SIZE / PAGE_SIZE);
835#endif 835#endif
836 836
837 /* This should never be able to happen but better confirm that. */ 837 /* This should never be able to happen but better confirm that. */
838 if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0) 838 if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
839 panic("initarm: Failed to align the kernel page directory"); 839 panic("initarm: Failed to align the kernel page directory");
840 840
841 /* 841 /*
842 * Allocate a page for the system page mapped to V0x00000000 842 * Allocate a page for the system page mapped to V0x00000000
843 * This page will just contain the system vectors and can be 843 * This page will just contain the system vectors and can be
844 * shared by all processes. 844 * shared by all processes.
845 */ 845 */
846 alloc_pages(systempage.pv_pa, 1); 846 alloc_pages(systempage.pv_pa, 1);
847 847
848 /* Allocate stacks for all modes */ 848 /* Allocate stacks for all modes */
849 valloc_pages(irqstack, IRQ_STACK_SIZE); 849 valloc_pages(irqstack, IRQ_STACK_SIZE);
850 valloc_pages(abtstack, ABT_STACK_SIZE); 850 valloc_pages(abtstack, ABT_STACK_SIZE);
851 valloc_pages(undstack, UND_STACK_SIZE); 851 valloc_pages(undstack, UND_STACK_SIZE);
852 valloc_pages(kernelstack, UPAGES); 852 valloc_pages(kernelstack, UPAGES);
853 853
854 /* Allocate enough pages for cleaning the Mini-Data cache. */ 854 /* Allocate enough pages for cleaning the Mini-Data cache. */
855 KASSERT(xscale_minidata_clean_size <= PAGE_SIZE); 855 KASSERT(xscale_minidata_clean_size <= PAGE_SIZE);
856 valloc_pages(minidataclean, 1); 856 valloc_pages(minidataclean, 1);
857 857
858#ifdef KLOADER 858#ifdef KLOADER
859 bootinfo_pg.pv_pa = BOOTINFO_PAGE; 859 bootinfo_pg.pv_pa = BOOTINFO_PAGE;
860 bootinfo_pg.pv_va = KERNEL_BASE + bootinfo_pg.pv_pa - physical_start; 860 bootinfo_pg.pv_va = KERNEL_BASE + bootinfo_pg.pv_pa - physical_start;
861#endif 861#endif
862 862
863#ifdef VERBOSE_INIT_ARM 863#ifdef VERBOSE_INIT_ARM
864 printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa, 864 printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
865 irqstack.pv_va);  865 irqstack.pv_va);
866 printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa, 866 printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
867 abtstack.pv_va);  867 abtstack.pv_va);
868 printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa, 868 printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
869 undstack.pv_va);  869 undstack.pv_va);
870 printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa, 870 printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
871 kernelstack.pv_va);  871 kernelstack.pv_va);
872 printf("minidataclean: p0x%08lx v0x%08lx, size = %ld\n", 872 printf("minidataclean: p0x%08lx v0x%08lx, size = %ld\n",
873 minidataclean.pv_pa, minidataclean.pv_va, 873 minidataclean.pv_pa, minidataclean.pv_va,
874 xscale_minidata_clean_size); 874 xscale_minidata_clean_size);
875#ifdef KLOADER 875#ifdef KLOADER
876 printf("bootinfo_pg: p0x%08lx v0x%08lx\n", bootinfo_pg.pv_pa, 876 printf("bootinfo_pg: p0x%08lx v0x%08lx\n", bootinfo_pg.pv_pa,
877 bootinfo_pg.pv_va); 877 bootinfo_pg.pv_va);
878#endif 878#endif
879#endif 879#endif
880 880
881 /* 881 /*
882 * XXX Defer this to later so that we can reclaim the memory 882 * XXX Defer this to later so that we can reclaim the memory
883 * XXX used by the RedBoot page tables. 883 * XXX used by the RedBoot page tables.
884 */ 884 */
885 alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE); 885 alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
886 886
887 /* 887 /*
888 * Ok we have allocated physical pages for the primary kernel 888 * Ok we have allocated physical pages for the primary kernel
889 * page tables 889 * page tables
890 */ 890 */
891 891
892#ifdef VERBOSE_INIT_ARM 892#ifdef VERBOSE_INIT_ARM
893 printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa); 893 printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
894#endif 894#endif
895 895
896 /* 896 /*
897 * Now we start construction of the L1 page table 897 * Now we start construction of the L1 page table
898 * We start by mapping the L2 page tables into the L1. 898 * We start by mapping the L2 page tables into the L1.
899 * This means that we can replace L1 mappings later on if necessary 899 * This means that we can replace L1 mappings later on if necessary
900 */ 900 */
901 l1pagetable = kernel_l1pt.pv_pa; 901 l1pagetable = kernel_l1pt.pv_pa;
902 902
903 /* Map the L2 pages tables in the L1 page table */ 903 /* Map the L2 pages tables in the L1 page table */
904 pmap_link_l2pt(l1pagetable, 0x00000000, 904 pmap_link_l2pt(l1pagetable, 0x00000000,
905 &kernel_pt_table[KERNEL_PT_SYS]); 905 &kernel_pt_table[KERNEL_PT_SYS]);
906 for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++) 906 for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
907 pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000, 907 pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
908 &kernel_pt_table[KERNEL_PT_KERNEL + loop]); 908 &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
909 for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++) 909 for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
910 pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000, 910 pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
911 &kernel_pt_table[KERNEL_PT_VMDATA + loop]); 911 &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
912#ifdef KLOADER 912#ifdef KLOADER
913 pmap_link_l2pt(l1pagetable, PXA2X0_SDRAM0_START, &bootinfo_pt); 913 pmap_link_l2pt(l1pagetable, PXA2X0_SDRAM0_START, &bootinfo_pt);
914#endif 914#endif
915 915
916 /* update the top of the kernel VM */ 916 /* update the top of the kernel VM */
917 pmap_curmaxkvaddr = 917 pmap_curmaxkvaddr =
918 KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000); 918 KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
919 919
920#ifdef VERBOSE_INIT_ARM 920#ifdef VERBOSE_INIT_ARM
921 printf("Mapping kernel\n"); 921 printf("Mapping kernel\n");
922#endif 922#endif
923 923
924 /* Now we fill in the L2 pagetable for the kernel static code/data 924 /* Now we fill in the L2 pagetable for the kernel static code/data
925 * and the symbol table. */ 925 * and the symbol table. */
926 { 926 {
927 extern char etext[], _end[]; 927 extern char etext[], _end[];
928 size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE; 928 size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE;
929 size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE; 929 size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE;
930 u_int logical; 930 u_int logical;
931 931
932 textsize = (textsize + PGOFSET) & ~PGOFSET; 932 textsize = (textsize + PGOFSET) & ~PGOFSET;
933 totalsize = (totalsize + PGOFSET) & ~PGOFSET; 933 totalsize = (totalsize + PGOFSET) & ~PGOFSET;
934  934
935 logical = KERNEL_TEXT_OFFSET; /* offset of kernel in RAM */ 935 /* offset of kernel in RAM */
 936 logical = KERNEL_TEXT_BASE - KERNEL_BASE;
936 937
937 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical, 938 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
938 physical_start + logical, textsize, 939 physical_start + logical, textsize,
939 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 940 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
940 pmap_map_chunk(l1pagetable, KERNEL_BASE + logical, 941 pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
941 physical_start + logical, totalsize - textsize, 942 physical_start + logical, totalsize - textsize,
942 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 943 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
943 } 944 }
944 945
945#ifdef VERBOSE_INIT_ARM 946#ifdef VERBOSE_INIT_ARM
946 printf("Constructing L2 page tables\n"); 947 printf("Constructing L2 page tables\n");
947#endif 948#endif
948 949
949 /* Map the stack pages */ 950 /* Map the stack pages */
950 pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa, 951 pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
951 IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 952 IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
952 pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa, 953 pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
953 ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 954 ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
954 pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa, 955 pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
955 UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 956 UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
956 pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa, 957 pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
957 UPAGES * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 958 UPAGES * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
958 959
959 pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa, 960 pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
960 L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE); 961 L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
961 962
962 for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) { 963 for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
963 pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va, 964 pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
964 kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE, 965 kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
965 VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE); 966 VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
966 } 967 }
967 968
968#ifdef KLOADER 969#ifdef KLOADER
969 pmap_map_chunk(l1pagetable, bootinfo_pt.pv_va, bootinfo_pt.pv_pa, 970 pmap_map_chunk(l1pagetable, bootinfo_pt.pv_va, bootinfo_pt.pv_pa,
970 L2_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE); 971 L2_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
971 pmap_map_chunk(l1pagetable, bootinfo_pg.pv_va, bootinfo_pg.pv_pa, 972 pmap_map_chunk(l1pagetable, bootinfo_pg.pv_va, bootinfo_pg.pv_pa,
972 PAGE_SIZE, VM_PROT_ALL, PTE_CACHE); 973 PAGE_SIZE, VM_PROT_ALL, PTE_CACHE);
973#endif 974#endif
974 975
975 /* Map the Mini-Data cache clean area. */ 976 /* Map the Mini-Data cache clean area. */
976 xscale_setup_minidata(l1pagetable, minidataclean.pv_va, 977 xscale_setup_minidata(l1pagetable, minidataclean.pv_va,
977 minidataclean.pv_pa); 978 minidataclean.pv_pa);
978 979
979 /* Map the vector page. */ 980 /* Map the vector page. */
980#if 0 981#if 0
981 /* MULTI-ICE requires that page 0 is NC/NB so that it can download the 982 /* MULTI-ICE requires that page 0 is NC/NB so that it can download the
982 * cache-clean code there. */ 983 * cache-clean code there. */
983 pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa, 984 pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa,
984 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE); 985 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
985#else 986#else
986 pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa, 987 pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa,
987 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); 988 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
988#endif 989#endif
989 990
990 /* 991 /*
991 * map integrated peripherals at same address in l1pagetable 992 * map integrated peripherals at same address in l1pagetable
992 * so that we can continue to use console. 993 * so that we can continue to use console.
993 */ 994 */
994 pmap_devmap_bootstrap(l1pagetable, zaurus_devmap); 995 pmap_devmap_bootstrap(l1pagetable, zaurus_devmap);
995 996
996 /* 997 /*
997 * Give the XScale global cache clean code an appropriately 998 * Give the XScale global cache clean code an appropriately
998 * sized chunk of unmapped VA space starting at 0xff000000 999 * sized chunk of unmapped VA space starting at 0xff000000
999 * (our device mappings end before this address). 1000 * (our device mappings end before this address).
1000 */ 1001 */
1001 xscale_cache_clean_addr = 0xff000000U; 1002 xscale_cache_clean_addr = 0xff000000U;
1002 1003
1003 /* 1004 /*
1004 * Now we have the real page tables in place so we can switch to them. 1005 * Now we have the real page tables in place so we can switch to them.
1005 * Once this is done we will be running with the REAL kernel page 1006 * Once this is done we will be running with the REAL kernel page
1006 * tables. 1007 * tables.
1007 */ 1008 */
1008 1009
1009 /* 1010 /*
1010 * Update the physical_freestart/physical_freeend/free_pages 1011 * Update the physical_freestart/physical_freeend/free_pages
1011 * variables. 1012 * variables.
1012 */ 1013 */
1013 { 1014 {
1014 extern char _end[]; 1015 extern char _end[];
1015 1016
1016 physical_freestart = physical_start + 1017 physical_freestart = physical_start +
1017 ((((uintptr_t) _end + PGOFSET) & ~PGOFSET) - KERNEL_BASE); 1018 ((((uintptr_t) _end + PGOFSET) & ~PGOFSET) - KERNEL_BASE);
1018 physical_freeend = physical_end; 1019 physical_freeend = physical_end;
1019 free_pages = 1020 free_pages =
1020 (physical_freeend - physical_freestart) / PAGE_SIZE; 1021 (physical_freeend - physical_freestart) / PAGE_SIZE;
1021 } 1022 }
1022 1023
1023 /* Switch tables */ 1024 /* Switch tables */
1024#ifdef VERBOSE_INIT_ARM 1025#ifdef VERBOSE_INIT_ARM
1025 printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n", 1026 printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
1026 physical_freestart, free_pages, free_pages); 1027 physical_freestart, free_pages, free_pages);
1027 printf("switching to new L1 page table @%#lx...", kernel_l1pt.pv_pa); 1028 printf("switching to new L1 page table @%#lx...", kernel_l1pt.pv_pa);
1028#endif 1029#endif
1029 1030
1030 cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT); 1031 cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
1031 cpu_setttb(kernel_l1pt.pv_pa); 1032 cpu_setttb(kernel_l1pt.pv_pa);
1032 cpu_tlb_flushID(); 1033 cpu_tlb_flushID();
1033 cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)); 1034 cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
1034 1035
1035 /* 1036 /*
1036 * Moved from cpu_startup() as data_abort_handler() references 1037 * Moved from cpu_startup() as data_abort_handler() references
1037 * this during uvm init 1038 * this during uvm init
1038 */ 1039 */
1039 uvm_lwp_setuarea(&lwp0, kernelstack.pv_va); 1040 uvm_lwp_setuarea(&lwp0, kernelstack.pv_va);
1040 1041
1041#ifdef VERBOSE_INIT_ARM 1042#ifdef VERBOSE_INIT_ARM
1042 printf("bootstrap done.\n"); 1043 printf("bootstrap done.\n");
1043#endif 1044#endif
1044 1045
1045 arm32_vector_init(ARM_VECTORS_LOW, ARM_VEC_ALL); 1046 arm32_vector_init(ARM_VECTORS_LOW, ARM_VEC_ALL);
1046 1047
1047 /* 1048 /*
1048 * Pages were allocated during the secondary bootstrap for the 1049 * Pages were allocated during the secondary bootstrap for the
1049 * stacks for different CPU modes. 1050 * stacks for different CPU modes.
1050 * We must now set the r13 registers in the different CPU modes to 1051 * We must now set the r13 registers in the different CPU modes to
1051 * point to these stacks. 1052 * point to these stacks.
1052 * Since the ARM stacks use STMFD etc. we must set r13 to the top end 1053 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
1053 * of the stack memory. 1054 * of the stack memory.
1054 */ 1055 */
1055#ifdef VERBOSE_INIT_ARM 1056#ifdef VERBOSE_INIT_ARM
1056 printf("init subsystems: stacks "); 1057 printf("init subsystems: stacks ");
1057#endif 1058#endif
1058 1059
1059 set_stackptr(PSR_IRQ32_MODE, 1060 set_stackptr(PSR_IRQ32_MODE,
1060 irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE); 1061 irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
1061 set_stackptr(PSR_ABT32_MODE, 1062 set_stackptr(PSR_ABT32_MODE,
1062 abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE); 1063 abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
1063 set_stackptr(PSR_UND32_MODE, 1064 set_stackptr(PSR_UND32_MODE,
1064 undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE); 1065 undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
1065 1066
1066 /* 1067 /*
1067 * Well we should set a data abort handler. 1068 * Well we should set a data abort handler.
1068 * Once things get going this will change as we will need a proper 1069 * Once things get going this will change as we will need a proper
1069 * handler. 1070 * handler.
1070 * Until then we will use a handler that just panics but tells us 1071 * Until then we will use a handler that just panics but tells us
1071 * why. 1072 * why.
1072 * Initialisation of the vectors will just panic on a data abort. 1073 * Initialisation of the vectors will just panic on a data abort.
1073 * This just fills in a slighly better one. 1074 * This just fills in a slighly better one.
1074 */ 1075 */
1075#ifdef VERBOSE_INIT_ARM 1076#ifdef VERBOSE_INIT_ARM
1076 printf("vectors "); 1077 printf("vectors ");
1077#endif 1078#endif
1078 data_abort_handler_address = (u_int)data_abort_handler; 1079 data_abort_handler_address = (u_int)data_abort_handler;
1079 prefetch_abort_handler_address = (u_int)prefetch_abort_handler; 1080 prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
1080 undefined_handler_address = (u_int)undefinedinstruction_bounce; 1081 undefined_handler_address = (u_int)undefinedinstruction_bounce;
1081 1082
1082 /* Initialise the undefined instruction handlers */ 1083 /* Initialise the undefined instruction handlers */
1083#ifdef VERBOSE_INIT_ARM 1084#ifdef VERBOSE_INIT_ARM
1084 printf("undefined "); 1085 printf("undefined ");
1085#endif 1086#endif
1086 undefined_init(); 1087 undefined_init();
1087 1088
1088 /* Load memory into UVM. */ 1089 /* Load memory into UVM. */
1089#ifdef VERBOSE_INIT_ARM 1090#ifdef VERBOSE_INIT_ARM
1090 printf("page "); 1091 printf("page ");
1091#endif 1092#endif
1092 uvm_setpagesize(); /* initialize PAGE_SIZE-dependent variables */ 1093 uvm_setpagesize(); /* initialize PAGE_SIZE-dependent variables */
1093 uvm_page_physload(atop(physical_freestart), atop(physical_freeend), 1094 uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
1094 atop(physical_freestart), atop(physical_freeend), 1095 atop(physical_freestart), atop(physical_freeend),
1095 VM_FREELIST_DEFAULT); 1096 VM_FREELIST_DEFAULT);
1096 1097
1097 /* Boot strap pmap telling it where the kernel page table is */ 1098 /* Boot strap pmap telling it where the kernel page table is */
1098#ifdef VERBOSE_INIT_ARM 1099#ifdef VERBOSE_INIT_ARM
1099 printf("pmap "); 1100 printf("pmap ");
1100#endif 1101#endif
1101 pmap_bootstrap(KERNEL_VM_BASE, KERNEL_VM_BASE + KERNEL_VM_SIZE); 1102 pmap_bootstrap(KERNEL_VM_BASE, KERNEL_VM_BASE + KERNEL_VM_SIZE);
1102 1103
1103#ifdef VERBOSE_INIT_ARM 1104#ifdef VERBOSE_INIT_ARM
1104 printf("\n"); 1105 printf("\n");
1105#endif 1106#endif
1106 1107
1107#ifdef __HAVE_MEMORY_DISK__ 1108#ifdef __HAVE_MEMORY_DISK__
1108 md_root_setconf(memory_disk, sizeof memory_disk); 1109 md_root_setconf(memory_disk, sizeof memory_disk);
1109#endif 1110#endif
1110 1111
1111#if NKSYMS || defined(DDB) || defined(MODULAR) 1112#if NKSYMS || defined(DDB) || defined(MODULAR)
1112 /* Firmware doesn't load symbols. */ 1113 /* Firmware doesn't load symbols. */
1113 ddb_init(0, NULL, NULL); 1114 ddb_init(0, NULL, NULL);
1114#endif 1115#endif
1115 1116
1116#ifdef KGDB 1117#ifdef KGDB
1117 if (boothowto & RB_KDB) { 1118 if (boothowto & RB_KDB) {
1118 kgdb_debug_init = 1; 1119 kgdb_debug_init = 1;
1119 kgdb_connect(1); 1120 kgdb_connect(1);
1120 } 1121 }
1121#endif 1122#endif
1122 1123
1123#ifdef DDB 1124#ifdef DDB
1124 db_machine_init(); 1125 db_machine_init();
1125 if (boothowto & RB_KDB) 1126 if (boothowto & RB_KDB)
1126 Debugger(); 1127 Debugger();
1127#endif 1128#endif
1128 1129
1129 /* We return the new stack pointer address */ 1130 /* We return the new stack pointer address */
1130 return (kernelstack.pv_va + USPACE_SVC_STACK_TOP); 1131 return (kernelstack.pv_va + USPACE_SVC_STACK_TOP);
1131} 1132}
1132 1133
1133void * 1134void *
1134lookup_bootinfo(int type) 1135lookup_bootinfo(int type)
1135{ 1136{
1136 struct btinfo_common *help; 1137 struct btinfo_common *help;
1137 int n; 1138 int n;
1138 1139
1139 if (bootinfo == NULL) 1140 if (bootinfo == NULL)
1140 return (NULL); 1141 return (NULL);
1141 1142
1142 n = bootinfo->nentries; 1143 n = bootinfo->nentries;
1143 help = (struct btinfo_common *)(bootinfo->info); 1144 help = (struct btinfo_common *)(bootinfo->info);
1144 while (n--) { 1145 while (n--) {
1145 if (help->type == type) 1146 if (help->type == type)
1146 return (help); 1147 return (help);
1147 help = (struct btinfo_common *)((char *)help + help->len); 1148 help = (struct btinfo_common *)((char *)help + help->len);
1148 } 1149 }
1149 return (NULL); 1150 return (NULL);
1150} 1151}
1151 1152
1152#ifdef KLOADER 1153#ifdef KLOADER
1153static int 1154static int
1154parseboot(char *arg, char **filename, int *howto) 1155parseboot(char *arg, char **filename, int *howto)
1155{ 1156{
1156 char *opts = NULL; 1157 char *opts = NULL;
1157 1158
1158 *filename = NULL; 1159 *filename = NULL;
1159 *howto = 0; 1160 *howto = 0;
1160 1161
1161 /* if there were no arguments */ 1162 /* if there were no arguments */
1162 if (arg == NULL || *arg == '\0') 1163 if (arg == NULL || *arg == '\0')
1163 return 1; 1164 return 1;
1164 1165
1165 /* format is... */ 1166 /* format is... */
1166 /* [[xxNx:]filename] [-adqsv] */ 1167 /* [[xxNx:]filename] [-adqsv] */
1167 1168
1168 /* check for just args */ 1169 /* check for just args */
1169 if (arg[0] == '-') { 1170 if (arg[0] == '-') {
1170 opts = arg; 1171 opts = arg;
1171 } else { 1172 } else {
1172 /* there's a file name */ 1173 /* there's a file name */
1173 *filename = arg; 1174 *filename = arg;
1174 1175
1175 opts = gettrailer(arg); 1176 opts = gettrailer(arg);
1176 if (opts == NULL || *opts == '\0') { 1177 if (opts == NULL || *opts == '\0') {
1177 opts = NULL; 1178 opts = NULL;
1178 } else if (*opts != '-') { 1179 } else if (*opts != '-') {
1179 printf("invalid arguments\n"); 1180 printf("invalid arguments\n");
1180 return 0; 1181 return 0;
1181 } 1182 }
1182 } 1183 }
1183 1184
1184 /* at this point, we have dealt with filenames. */ 1185 /* at this point, we have dealt with filenames. */
1185 1186
1186 /* now, deal with options */ 1187 /* now, deal with options */
1187 if (opts) { 1188 if (opts) {
1188 if (parseopts(opts, howto) == 0) { 1189 if (parseopts(opts, howto) == 0) {
1189 return 0; 1190 return 0;
1190 } 1191 }
1191 } 1192 }
1192 return 1; 1193 return 1;
1193} 1194}
1194 1195
1195static char * 1196static char *
1196gettrailer(char *arg) 1197gettrailer(char *arg)
1197{ 1198{
1198 static char nullstr[] = ""; 1199 static char nullstr[] = "";
1199 char *options; 1200 char *options;
1200 1201
1201 if ((options = strchr(arg, ' ')) == NULL) 1202 if ((options = strchr(arg, ' ')) == NULL)
1202 return nullstr; 1203 return nullstr;
1203 else 1204 else
1204 *options++ = '\0'; 1205 *options++ = '\0';
1205 1206
1206 /* trim leading blanks */ 1207 /* trim leading blanks */
1207 while (*options && *options == ' ') 1208 while (*options && *options == ' ')
1208 options++; 1209 options++;
1209 1210
1210 return options; 1211 return options;
1211} 1212}
1212 1213
1213static int 1214static int
1214parseopts(const char *opts, int *howto) 1215parseopts(const char *opts, int *howto)
1215{ 1216{
1216 int r, tmpopt = *howto; 1217 int r, tmpopt = *howto;
1217 1218
1218 opts++; /* skip - */ 1219 opts++; /* skip - */
1219 while (*opts && *opts != ' ') { 1220 while (*opts && *opts != ' ') {
1220 r = 0; 1221 r = 0;
1221 BOOT_FLAG(*opts, r); 1222 BOOT_FLAG(*opts, r);
1222 if (r == 0) { 1223 if (r == 0) {
1223 printf("-%c: unknown flag\n", *opts); 1224 printf("-%c: unknown flag\n", *opts);
1224 return 0; 1225 return 0;
1225 } 1226 }
1226 tmpopt |= r; 1227 tmpopt |= r;
1227 opts++; 1228 opts++;
1228 } 1229 }
1229 1230
1230 *howto = tmpopt; 1231 *howto = tmpopt;
1231 return 1; 1232 return 1;
1232} 1233}
1233#endif 1234#endif
1234 1235
1235/* 1236/*
1236 * Console 1237 * Console
1237 */ 1238 */
1238#include "com.h" 1239#include "com.h"
1239#if (NCOM > 0) 1240#if (NCOM > 0)
1240#include <dev/ic/comvar.h> 1241#include <dev/ic/comvar.h>
1241#endif 1242#endif
1242 1243
1243#include "wsdisplay.h" 1244#include "wsdisplay.h"
1244 1245
1245#ifndef CONSPEED 1246#ifndef CONSPEED
1246#define CONSPEED B9600 1247#define CONSPEED B9600
1247#endif 1248#endif
1248#ifndef CONMODE 1249#ifndef CONMODE
1249#define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */ 1250#define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
1250#endif 1251#endif
1251 1252
1252int comcnspeed = CONSPEED; 1253int comcnspeed = CONSPEED;
1253int comcnmode = CONMODE; 1254int comcnmode = CONMODE;
1254 1255
1255#ifdef KGDB 1256#ifdef KGDB
1256#ifndef KGDB_DEVNAME 1257#ifndef KGDB_DEVNAME
1257#define KGDB_DEVNAME "ffuart" 1258#define KGDB_DEVNAME "ffuart"
1258#endif 1259#endif
1259const char kgdb_devname[] = KGDB_DEVNAME; 1260const char kgdb_devname[] = KGDB_DEVNAME;
1260 1261
1261#if (NCOM > 0) 1262#if (NCOM > 0)
1262#ifndef KGDB_DEVMODE 1263#ifndef KGDB_DEVMODE
1263#define KGDB_DEVMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */ 1264#define KGDB_DEVMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
1264#endif 1265#endif
1265int comkgdbmode = KGDB_DEVMODE; 1266int comkgdbmode = KGDB_DEVMODE;
1266#endif /* NCOM */ 1267#endif /* NCOM */
1267#endif /* KGDB */ 1268#endif /* KGDB */
1268 1269
1269void 1270void
1270consinit(void) 1271consinit(void)
1271{ 1272{
1272 static int consinit_called = 0; 1273 static int consinit_called = 0;
1273#if (NCOM > 0) && defined(COM_PXA2X0) 1274#if (NCOM > 0) && defined(COM_PXA2X0)
1274 paddr_t paddr; 1275 paddr_t paddr;
1275 u_int cken = 0; 1276 u_int cken = 0;
1276#endif 1277#endif
1277 1278
1278 if (consinit_called) 1279 if (consinit_called)
1279 return; 1280 return;
1280 consinit_called = 1; 1281 consinit_called = 1;
1281 1282
1282#if (NCOM > 0) && defined(COM_PXA2X0) 1283#if (NCOM > 0) && defined(COM_PXA2X0)
1283#ifdef KGDB 1284#ifdef KGDB
1284 if (strcmp(kgdb_devname, console) == 0) { 1285 if (strcmp(kgdb_devname, console) == 0) {
1285 /* port is reserved for kgdb */ 1286 /* port is reserved for kgdb */
1286 } else 1287 } else
1287#endif 1288#endif
1288 if (strcmp(console, "ffuart") == 0) { 1289 if (strcmp(console, "ffuart") == 0) {
1289 paddr = PXA2X0_FFUART_BASE; 1290 paddr = PXA2X0_FFUART_BASE;
1290 cken = CKEN_FFUART; 1291 cken = CKEN_FFUART;
1291 } else if (strcmp(console, "btuart") == 0) { 1292 } else if (strcmp(console, "btuart") == 0) {
1292 paddr = PXA2X0_BTUART_BASE; 1293 paddr = PXA2X0_BTUART_BASE;
1293 cken = CKEN_BTUART; 1294 cken = CKEN_BTUART;
1294 } else if (strcmp(console, "stuart") == 0) { 1295 } else if (strcmp(console, "stuart") == 0) {
1295 paddr = PXA2X0_STUART_BASE; 1296 paddr = PXA2X0_STUART_BASE;
1296 cken = CKEN_STUART; 1297 cken = CKEN_STUART;
1297 irda_on(0); 1298 irda_on(0);
1298 } else 1299 } else
1299#endif 1300#endif
1300 if (strcmp(console, "glass") == 0) { 1301 if (strcmp(console, "glass") == 0) {
1301#if (NLCD > 0) && (NWSDISPLAY > 0) 1302#if (NLCD > 0) && (NWSDISPLAY > 0)
1302 glass_console = 1; 1303 glass_console = 1;
1303 lcd_cnattach(); 1304 lcd_cnattach();
1304#endif 1305#endif
1305 } 1306 }
1306 1307
1307#if (NCOM > 0) && defined(COM_PXA2X0) 1308#if (NCOM > 0) && defined(COM_PXA2X0)
1308 if (cken != 0 && comcnattach(&pxa2x0_a4x_bs_tag, paddr, comcnspeed, 1309 if (cken != 0 && comcnattach(&pxa2x0_a4x_bs_tag, paddr, comcnspeed,
1309 PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode) == 0) { 1310 PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode) == 0) {
1310 pxa2x0_clkman_config(cken, 1); 1311 pxa2x0_clkman_config(cken, 1);
1311 } 1312 }
1312#endif 1313#endif
1313} 1314}
1314 1315
1315#ifdef KGDB 1316#ifdef KGDB
1316void 1317void
1317kgdb_port_init(void) 1318kgdb_port_init(void)
1318{ 1319{
1319#if (NCOM > 0) && defined(COM_PXA2X0) 1320#if (NCOM > 0) && defined(COM_PXA2X0)
1320 paddr_t paddr; 1321 paddr_t paddr;
1321 u_int cken; 1322 u_int cken;
1322 1323
1323 if (strcmp(kgdb_devname, "ffuart") == 0) { 1324 if (strcmp(kgdb_devname, "ffuart") == 0) {
1324 paddr = PXA2X0_FFUART_BASE; 1325 paddr = PXA2X0_FFUART_BASE;
1325 cken = CKEN_FFUART; 1326 cken = CKEN_FFUART;
1326 } else if (strcmp(kgdb_devname, "btuart") == 0) { 1327 } else if (strcmp(kgdb_devname, "btuart") == 0) {
1327 paddr = PXA2X0_BTUART_BASE; 1328 paddr = PXA2X0_BTUART_BASE;
1328 cken = CKEN_BTUART; 1329 cken = CKEN_BTUART;
1329 } else if (strcmp(kgdb_devname, "stuart") == 0) { 1330 } else if (strcmp(kgdb_devname, "stuart") == 0) {
1330 paddr = PXA2X0_STUART_BASE; 1331 paddr = PXA2X0_STUART_BASE;
1331 cken = CKEN_STUART; 1332 cken = CKEN_STUART;
1332 irda_on(0); 1333 irda_on(0);
1333 } else 1334 } else
1334 return; 1335 return;
1335 1336
1336 if (com_kgdb_attach(&pxa2x0_a4x_bs_tag, paddr, 1337 if (com_kgdb_attach(&pxa2x0_a4x_bs_tag, paddr,
1337 kgdb_rate, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comkgdbmode) == 0) { 1338 kgdb_rate, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comkgdbmode) == 0) {
1338 pxa2x0_clkman_config(cken, 1); 1339 pxa2x0_clkman_config(cken, 1);
1339 } 1340 }
1340#endif 1341#endif
1341} 1342}
1342#endif 1343#endif