machdep.c revision 1.40
11.40Such/* $NetBSD: machdep.c,v 1.40 2002/03/24 18:21:16 uch Exp $ */ 21.1Sitojun 31.1Sitojun/*- 41.1Sitojun * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc. 51.1Sitojun * All rights reserved. 61.1Sitojun * 71.1Sitojun * This code is derived from software contributed to The NetBSD Foundation 81.1Sitojun * by Charles M. Hannum and by Jason R. Thorpe of the Numerical Aerospace 91.1Sitojun * Simulation Facility, NASA Ames Research Center. 101.1Sitojun * 111.1Sitojun * Redistribution and use in source and binary forms, with or without 121.1Sitojun * modification, are permitted provided that the following conditions 131.1Sitojun * are met: 141.1Sitojun * 1. Redistributions of source code must retain the above copyright 151.1Sitojun * notice, this list of conditions and the following disclaimer. 161.1Sitojun * 2. Redistributions in binary form must reproduce the above copyright 171.1Sitojun * notice, this list of conditions and the following disclaimer in the 181.1Sitojun * documentation and/or other materials provided with the distribution. 191.1Sitojun * 3. All advertising materials mentioning features or use of this software 201.1Sitojun * must display the following acknowledgement: 211.1Sitojun * This product includes software developed by the NetBSD 221.1Sitojun * Foundation, Inc. and its contributors. 231.1Sitojun * 4. Neither the name of The NetBSD Foundation nor the names of its 241.1Sitojun * contributors may be used to endorse or promote products derived 251.1Sitojun * from this software without specific prior written permission. 261.1Sitojun * 271.1Sitojun * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 281.1Sitojun * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 291.1Sitojun * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 301.1Sitojun * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 311.1Sitojun * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 321.1Sitojun * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 331.1Sitojun * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 341.1Sitojun * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 351.1Sitojun * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 361.1Sitojun * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 371.1Sitojun * POSSIBILITY OF SUCH DAMAGE. 381.1Sitojun */ 391.1Sitojun 401.1Sitojun/*- 411.1Sitojun * Copyright (c) 1982, 1987, 1990 The Regents of the University of California. 421.1Sitojun * All rights reserved. 431.1Sitojun * 441.1Sitojun * This code is derived from software contributed to Berkeley by 451.1Sitojun * William Jolitz. 461.1Sitojun * 471.1Sitojun * Redistribution and use in source and binary forms, with or without 481.1Sitojun * modification, are permitted provided that the following conditions 491.1Sitojun * are met: 501.1Sitojun * 1. Redistributions of source code must retain the above copyright 511.1Sitojun * notice, this list of conditions and the following disclaimer. 521.1Sitojun * 2. Redistributions in binary form must reproduce the above copyright 531.1Sitojun * notice, this list of conditions and the following disclaimer in the 541.1Sitojun * documentation and/or other materials provided with the distribution. 551.1Sitojun * 3. All advertising materials mentioning features or use of this software 561.1Sitojun * must display the following acknowledgement: 571.1Sitojun * This product includes software developed by the University of 581.1Sitojun * California, Berkeley and its contributors. 591.1Sitojun * 4. Neither the name of the University nor the names of its contributors 601.1Sitojun * may be used to endorse or promote products derived from this software 611.1Sitojun * without specific prior written permission. 621.1Sitojun * 631.1Sitojun * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 641.1Sitojun * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 651.1Sitojun * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 661.1Sitojun * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 671.1Sitojun * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 681.1Sitojun * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 691.1Sitojun * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 701.1Sitojun * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 711.1Sitojun * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 721.1Sitojun * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 731.1Sitojun * SUCH DAMAGE. 741.1Sitojun * 751.1Sitojun * @(#)machdep.c 7.4 (Berkeley) 6/3/91 761.1Sitojun */ 771.1Sitojun 781.1Sitojun#include "opt_ddb.h" 791.26Slukem#include "opt_kgdb.h" 801.15Ssoren#include "opt_syscall_debug.h" 811.1Sitojun#include "opt_memsize.h" 821.1Sitojun#include "opt_initbsc.h" 831.1Sitojun 841.1Sitojun#include <sys/param.h> 851.1Sitojun#include <sys/systm.h> 861.1Sitojun#include <sys/kernel.h> 871.1Sitojun#include <sys/user.h> 881.37Such#include <sys/mount.h> 891.1Sitojun#include <sys/reboot.h> 901.37Such#include <sys/sysctl.h> 911.1Sitojun#include <sys/msgbuf.h> 921.1Sitojun 931.37Such#include <uvm/uvm_extern.h> 941.1Sitojun 951.1Sitojun#include <dev/cons.h> 961.40Such 971.37Such#include <sh3/bscreg.h> 981.33Such#include <sh3/cpgreg.h> 991.33Such#include <sh3/cache_sh3.h> 1001.40Such#include <sh3/cache_sh4.h> 1011.40Such#include <sh3/exception.h> 1021.40Such 1031.40Such#include <machine/bus.h> 1041.40Such#include <machine/intr.h> 1051.40Such 1061.40Such#ifdef DDB 1071.40Such#include <machine/db_machdep.h> 1081.40Such#include <ddb/db_extern.h> 1091.40Such#endif 1101.1Sitojun 1111.1Sitojun/* the following is used externally (sysctl_hw) */ 1121.37Suchchar machine[] = MACHINE; /* evbsh3 */ 1131.37Suchchar machine_arch[] = MACHINE_ARCH; /* sh3eb or sh3el */ 1141.1Sitojun 1151.1Sitojunpaddr_t msgbuf_paddr; 1161.1Sitojunextern paddr_t avail_start, avail_end; 1171.40Suchextern char start[], etext[], edata[], end[]; 1181.1Sitojun 1191.1Sitojun#define IOM_RAM_END ((paddr_t)IOM_RAM_BEGIN + IOM_RAM_SIZE - 1) 1201.1Sitojun 1211.3Smsaitohvoid initSH3 __P((void *)); 1221.3Smsaitohvoid LoadAndReset __P((char *)); 1231.3Smsaitohvoid XLoadAndReset __P((char *)); 1241.1Sitojun 1251.1Sitojun/* 1261.1Sitojun * Machine-dependent startup code 1271.1Sitojun * 1281.1Sitojun * This is called from main() in kern/main.c. 1291.1Sitojun */ 1301.1Sitojunvoid 1311.1Sitojuncpu_startup() 1321.1Sitojun{ 1331.1Sitojun 1341.39Such sh_startup(); 1351.1Sitojun} 1361.1Sitojun 1371.1Sitojun/* 1381.1Sitojun * machine dependent system variables. 1391.1Sitojun */ 1401.1Sitojunint 1411.1Sitojuncpu_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p) 1421.1Sitojun int *name; 1431.1Sitojun u_int namelen; 1441.1Sitojun void *oldp; 1451.1Sitojun size_t *oldlenp; 1461.1Sitojun void *newp; 1471.1Sitojun size_t newlen; 1481.1Sitojun struct proc *p; 1491.1Sitojun{ 1501.1Sitojun dev_t consdev; 1511.1Sitojun char *osimage; 1521.1Sitojun 1531.1Sitojun /* all sysctl names at this level are terminal */ 1541.1Sitojun if (namelen != 1) 1551.1Sitojun return (ENOTDIR); /* overloaded */ 1561.1Sitojun 1571.1Sitojun switch (name[0]) { 1581.1Sitojun case CPU_CONSDEV: 1591.1Sitojun if (cn_tab != NULL) 1601.1Sitojun consdev = cn_tab->cn_dev; 1611.1Sitojun else 1621.1Sitojun consdev = NODEV; 1631.1Sitojun return (sysctl_rdstruct(oldp, oldlenp, newp, &consdev, 1641.1Sitojun sizeof consdev)); 1651.1Sitojun 1661.1Sitojun case CPU_LOADANDRESET: 1671.1Sitojun if (newp != NULL) { 1681.1Sitojun osimage = (char *)(*(u_long *)newp); 1691.1Sitojun 1701.1Sitojun LoadAndReset(osimage); 1711.1Sitojun /* not reach here */ 1721.1Sitojun } 1731.1Sitojun return (0); 1741.1Sitojun 1751.1Sitojun default: 1761.1Sitojun return (EOPNOTSUPP); 1771.1Sitojun } 1781.1Sitojun /* NOTREACHED */ 1791.1Sitojun} 1801.1Sitojun 1811.1Sitojunvoid 1821.1Sitojuncpu_reboot(howto, bootstr) 1831.1Sitojun int howto; 1841.1Sitojun char *bootstr; 1851.1Sitojun{ 1861.37Such static int waittime = -1; 1871.1Sitojun 1881.1Sitojun if (cold) { 1891.1Sitojun howto |= RB_HALT; 1901.1Sitojun goto haltsys; 1911.1Sitojun } 1921.1Sitojun 1931.1Sitojun boothowto = howto; 1941.1Sitojun if ((howto & RB_NOSYNC) == 0 && waittime < 0) { 1951.1Sitojun waittime = 0; 1961.1Sitojun vfs_shutdown(); 1971.1Sitojun /* 1981.1Sitojun * If we've been adjusting the clock, the todr 1991.1Sitojun * will be out of synch; adjust it now. 2001.1Sitojun */ 2011.1Sitojun /* resettodr(); */ 2021.1Sitojun } 2031.1Sitojun 2041.1Sitojun /* Disable interrupts. */ 2051.1Sitojun splhigh(); 2061.1Sitojun 2071.1Sitojun /* Do a dump if requested. */ 2081.1Sitojun if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP) 2091.1Sitojun dumpsys(); 2101.1Sitojun 2111.1Sitojunhaltsys: 2121.1Sitojun doshutdownhooks(); 2131.1Sitojun 2141.1Sitojun if (howto & RB_HALT) { 2151.1Sitojun printf("\n"); 2161.1Sitojun printf("The operating system has halted.\n"); 2171.1Sitojun printf("Please press any key to reboot.\n\n"); 2181.1Sitojun cngetc(); 2191.1Sitojun } 2201.1Sitojun 2211.1Sitojun printf("rebooting...\n"); 2221.1Sitojun cpu_reset(); 2231.1Sitojun for(;;) 2241.1Sitojun ; 2251.1Sitojun /*NOTREACHED*/ 2261.1Sitojun} 2271.1Sitojun 2281.1Sitojunvoid 2291.37SuchinitSH3(void *pc) /* XXX return address */ 2301.1Sitojun{ 2311.37Such vaddr_t kernend; 2321.37Such vsize_t sz; 2331.3Smsaitoh 2341.37Such /* Clear bss */ 2351.37Such memset(edata, 0, end - edata); 2361.3Smsaitoh 2371.37Such /* Initilize CPU ops. */ 2381.30Such#if defined(SH3) && defined(SH4) 2391.30Such#error "don't define both SH3 and SH4" 2401.30Such#elif defined(SH3) 2411.40Such#if defined(SH7708) 2421.40Such sh_cpu_init(CPU_ARCH_SH3, CPU_PRODUCT_7708); 2431.40Such#elif defined(SH7708S) 2441.40Such sh_cpu_init(CPU_ARCH_SH3, CPU_PRODUCT_7708S); 2451.40Such#elif defined(SH7708R) 2461.40Such sh_cpu_init(CPU_ARCH_SH3, CPU_PRODUCT_7708R); 2471.40Such#elif defined(SH7709) 2481.40Such sh_cpu_init(CPU_ARCH_SH3, CPU_PRODUCT_7709); 2491.40Such#elif defined(SH7709A) 2501.40Such sh_cpu_init(CPU_ARCH_SH3, CPU_PRODUCT_7709A); 2511.40Such#else 2521.40Such#error "unsupported SH3 variants" 2531.40Such#endif 2541.30Such#elif defined(SH4) 2551.40Such#if defined(SH7750) 2561.40Such sh_cpu_init(CPU_ARCH_SH4, CPU_PRODUCT_7750); 2571.40Such#elif defined(SH7750S) 2581.40Such sh_cpu_init(CPU_ARCH_SH4, CPU_PRODUCT_7750S); 2591.40Such#else 2601.40Such#error "unsupported SH4 variants" 2611.40Such#endif 2621.30Such#else 2631.30Such#error "define SH3 or SH4" 2641.30Such#endif 2651.40Such 2661.37Such /* Initialize proc0 and enable MMU. */ 2671.40Such kernend = sh3_round_page(end); 2681.37Such sz = sh_proc0_init(kernend, IOM_RAM_BEGIN, IOM_RAM_END); 2691.3Smsaitoh 2701.37Such /* Number of pages of physmem addr space */ 2711.37Such physmem = atop(IOM_RAM_END - IOM_RAM_BEGIN + 1); 2721.3Smsaitoh 2731.3Smsaitoh /* avail_start is first available physical memory address */ 2741.37Such avail_start = kernend + sz; 2751.37Such avail_end = IOM_RAM_END + 1; 2761.1Sitojun 2771.37Such consinit(); 2781.40Such#ifdef DDB 2791.40Such ddb_init(0, NULL, NULL); 2801.40Such#endif 2811.1Sitojun 2821.1Sitojun /* Call pmap initialization to make new kernel address space */ 2831.37Such pmap_bootstrap(VM_MIN_KERNEL_ADDRESS); 2841.1Sitojun 2851.1Sitojun /* 2861.1Sitojun * Initialize error message buffer (at end of core). 2871.1Sitojun */ 2881.1Sitojun initmsgbuf((caddr_t)msgbuf_paddr, round_page(MSGBUFSIZE)); 2891.1Sitojun 2901.3Smsaitoh /* 2911.3Smsaitoh * XXX We can't return here, because we change stack pointer. 2921.3Smsaitoh * So jump to return address directly. 2931.3Smsaitoh */ 2941.40Such 2951.37Such __asm __volatile ( 2961.37Such "jmp @%0;" 2971.38Such "mov %1, r15" :: "r"(pc), "r"(proc0.p_addr->u_pcb.pcb_sp)); 2981.1Sitojun} 2991.1Sitojun 3001.1Sitojun/* 3011.1Sitojun * consinit: 3021.1Sitojun * initialize the system console. 3031.1Sitojun * XXX - shouldn't deal with this initted thing, but then, 3041.1Sitojun * it shouldn't be called from init386 either. 3051.1Sitojun */ 3061.1Sitojunvoid 3071.1Sitojunconsinit() 3081.1Sitojun{ 3091.1Sitojun static int initted; 3101.1Sitojun 3111.1Sitojun if (initted) 3121.1Sitojun return; 3131.1Sitojun initted = 1; 3141.1Sitojun 3151.1Sitojun cninit(); 3161.1Sitojun} 3171.1Sitojun 3181.1Sitojunint 3191.1Sitojunbus_space_map (t, addr, size, flags, bshp) 3201.1Sitojun bus_space_tag_t t; 3211.1Sitojun bus_addr_t addr; 3221.1Sitojun bus_size_t size; 3231.1Sitojun int flags; 3241.1Sitojun bus_space_handle_t *bshp; 3251.1Sitojun{ 3261.1Sitojun 3271.1Sitojun *bshp = (bus_space_handle_t)addr; 3281.1Sitojun 3291.1Sitojun return 0; 3301.1Sitojun} 3311.1Sitojun 3321.1Sitojunint 3331.1Sitojunsh_memio_subregion(t, bsh, offset, size, nbshp) 3341.1Sitojun bus_space_tag_t t; 3351.1Sitojun bus_space_handle_t bsh; 3361.1Sitojun bus_size_t offset, size; 3371.1Sitojun bus_space_handle_t *nbshp; 3381.1Sitojun{ 3391.1Sitojun 3401.1Sitojun *nbshp = bsh + offset; 3411.1Sitojun return (0); 3421.1Sitojun} 3431.1Sitojun 3441.1Sitojunint 3451.1Sitojunsh_memio_alloc(t, rstart, rend, size, alignment, boundary, flags, 3461.1Sitojun bpap, bshp) 3471.1Sitojun bus_space_tag_t t; 3481.1Sitojun bus_addr_t rstart, rend; 3491.1Sitojun bus_size_t size, alignment, boundary; 3501.1Sitojun int flags; 3511.1Sitojun bus_addr_t *bpap; 3521.1Sitojun bus_space_handle_t *bshp; 3531.1Sitojun{ 3541.1Sitojun *bshp = *bpap = rstart; 3551.1Sitojun 3561.1Sitojun return (0); 3571.1Sitojun} 3581.1Sitojun 3591.1Sitojunvoid 3601.1Sitojunsh_memio_free(t, bsh, size) 3611.1Sitojun bus_space_tag_t t; 3621.1Sitojun bus_space_handle_t bsh; 3631.1Sitojun bus_size_t size; 3641.1Sitojun{ 3651.1Sitojun 3661.1Sitojun} 3671.1Sitojun 3681.1Sitojunvoid 3691.1Sitojunsh_memio_unmap(t, bsh, size) 3701.1Sitojun bus_space_tag_t t; 3711.1Sitojun bus_space_handle_t bsh; 3721.1Sitojun bus_size_t size; 3731.1Sitojun{ 3741.1Sitojun return; 3751.1Sitojun} 3761.20Smsaitoh 3771.20Smsaitoh#ifdef SH4_PCMCIA 3781.20Smsaitoh 3791.20Smsaitohint 3801.20Smsaitohshpcmcia_memio_map(t, bpa, size, flags, bshp) 3811.20Smsaitoh bus_space_tag_t t; 3821.20Smsaitoh bus_addr_t bpa; 3831.20Smsaitoh bus_size_t size; 3841.20Smsaitoh int flags; 3851.20Smsaitoh bus_space_handle_t *bshp; 3861.20Smsaitoh{ 3871.20Smsaitoh int error; 3881.20Smsaitoh struct extent *ex; 3891.20Smsaitoh bus_space_tag_t pt = t & ~SH3_BUS_SPACE_PCMCIA_8BIT; 3901.20Smsaitoh 3911.20Smsaitoh if (pt != SH3_BUS_SPACE_PCMCIA_IO && 3921.20Smsaitoh pt != SH3_BUS_SPACE_PCMCIA_MEM && 3931.20Smsaitoh pt != SH3_BUS_SPACE_PCMCIA_ATT) { 3941.20Smsaitoh *bshp = (bus_space_handle_t)bpa; 3951.20Smsaitoh 3961.20Smsaitoh return 0; 3971.20Smsaitoh } 3981.20Smsaitoh 3991.20Smsaitoh ex = iomem_ex; 4001.20Smsaitoh 4011.20Smsaitoh#if 0 4021.20Smsaitoh /* 4031.20Smsaitoh * Before we go any further, let's make sure that this 4041.20Smsaitoh * region is available. 4051.20Smsaitoh */ 4061.20Smsaitoh error = extent_alloc_region(ex, bpa, size, 4071.20Smsaitoh EX_NOWAIT | EX_MALLOCOK ); 4081.20Smsaitoh if (error){ 4091.20Smsaitoh printf("sh3_pcmcia_memio_map:extent_alloc_region error\n"); 4101.20Smsaitoh return (error); 4111.20Smsaitoh } 4121.20Smsaitoh#endif 4131.20Smsaitoh 4141.20Smsaitoh /* 4151.20Smsaitoh * For memory space, map the bus physical address to 4161.20Smsaitoh * a kernel virtual address. 4171.20Smsaitoh */ 4181.20Smsaitoh error = shpcmcia_mem_add_mapping(bpa, size, (int)t, bshp ); 4191.20Smsaitoh#if 0 4201.20Smsaitoh if (error) { 4211.20Smsaitoh if (extent_free(ex, bpa, size, EX_NOWAIT | EX_MALLOCOK )) { 4221.20Smsaitoh printf("sh3_pcmcia_memio_map: pa 0x%lx, size 0x%lx\n", 4231.20Smsaitoh bpa, size); 4241.20Smsaitoh printf("sh3_pcmcia_memio_map: can't free region\n"); 4251.20Smsaitoh } 4261.20Smsaitoh } 4271.20Smsaitoh#endif 4281.20Smsaitoh 4291.20Smsaitoh return (error); 4301.20Smsaitoh} 4311.20Smsaitoh 4321.20Smsaitohint 4331.20Smsaitohshpcmcia_mem_add_mapping(bpa, size, type, bshp) 4341.20Smsaitoh bus_addr_t bpa; 4351.20Smsaitoh bus_size_t size; 4361.20Smsaitoh int type; 4371.20Smsaitoh bus_space_handle_t *bshp; 4381.20Smsaitoh{ 4391.20Smsaitoh u_long pa, endpa; 4401.20Smsaitoh vaddr_t va; 4411.20Smsaitoh pt_entry_t *pte; 4421.20Smsaitoh unsigned int m = 0; 4431.20Smsaitoh int io_type = type & ~SH3_BUS_SPACE_PCMCIA_8BIT; 4441.20Smsaitoh 4451.20Smsaitoh pa = sh3_trunc_page(bpa); 4461.20Smsaitoh endpa = sh3_round_page(bpa + size); 4471.20Smsaitoh 4481.20Smsaitoh#ifdef DIAGNOSTIC 4491.20Smsaitoh if (endpa <= pa) 4501.20Smsaitoh panic("sh3_pcmcia_mem_add_mapping: overflow"); 4511.20Smsaitoh#endif 4521.20Smsaitoh 4531.20Smsaitoh va = uvm_km_valloc(kernel_map, endpa - pa); 4541.20Smsaitoh if (va == 0){ 4551.20Smsaitoh printf("shpcmcia_add_mapping: nomem \n"); 4561.20Smsaitoh return (ENOMEM); 4571.20Smsaitoh } 4581.20Smsaitoh 4591.20Smsaitoh *bshp = (bus_space_handle_t)(va + (bpa & PGOFSET)); 4601.20Smsaitoh 4611.29Such#define MODE(t, s) \ 4621.29Such (t) & SH3_BUS_SPACE_PCMCIA_8BIT ? \ 4631.29Such _PG_PCMCIA_ ## s ## 8 : \ 4641.29Such _PG_PCMCIA_ ## s ## 16 4651.29Such switch (io_type) { 4661.29Such default: 4671.29Such panic("unknown pcmcia space."); 4681.29Such /* NOTREACHED */ 4691.29Such case SH3_BUS_SPACE_PCMCIA_IO: 4701.29Such m = MODE(type, IO); 4711.29Such break; 4721.29Such case SH3_BUS_SPACE_PCMCIA_MEM: 4731.29Such m = MODE(type, MEM); 4741.29Such break; 4751.29Such case SH3_BUS_SPACE_PCMCIA_ATT: 4761.29Such m = MODE(type, ATTR); 4771.29Such break; 4781.20Smsaitoh } 4791.29Such#undef MODE 4801.20Smsaitoh 4811.20Smsaitoh for (; pa < endpa; pa += NBPG, va += NBPG) { 4821.20Smsaitoh pmap_enter(pmap_kernel(), va, pa, 4831.22Smsaitoh VM_PROT_READ | VM_PROT_WRITE, PMAP_WIRED); 4841.20Smsaitoh 4851.20Smsaitoh pte = kvtopte(va); 4861.20Smsaitoh *pte &= ~PG_N; 4871.20Smsaitoh *pte |= m; 4881.20Smsaitoh pmap_update_pg(va); 4891.20Smsaitoh } 4901.28Schris pmap_update(pmap_kernel()); 4911.20Smsaitoh 4921.20Smsaitoh return 0; 4931.20Smsaitoh} 4941.20Smsaitoh 4951.20Smsaitohvoid 4961.20Smsaitohshpcmcia_memio_unmap(t, bsh, size) 4971.20Smsaitoh bus_space_tag_t t; 4981.20Smsaitoh bus_space_handle_t bsh; 4991.20Smsaitoh bus_size_t size; 5001.20Smsaitoh{ 5011.20Smsaitoh struct extent *ex; 5021.20Smsaitoh u_long va, endva; 5031.20Smsaitoh bus_addr_t bpa; 5041.20Smsaitoh bus_space_tag_t pt = t & ~SH3_BUS_SPACE_PCMCIA_8BIT; 5051.20Smsaitoh 5061.20Smsaitoh if (pt != SH3_BUS_SPACE_PCMCIA_IO && 5071.20Smsaitoh pt != SH3_BUS_SPACE_PCMCIA_MEM && 5081.20Smsaitoh pt != SH3_BUS_SPACE_PCMCIA_ATT) { 5091.20Smsaitoh return ; 5101.20Smsaitoh } 5111.20Smsaitoh 5121.20Smsaitoh ex = iomem_ex; 5131.20Smsaitoh 5141.20Smsaitoh va = sh3_trunc_page(bsh); 5151.20Smsaitoh endva = sh3_round_page(bsh + size); 5161.20Smsaitoh 5171.20Smsaitoh#ifdef DIAGNOSTIC 5181.20Smsaitoh if (endva <= va) 5191.20Smsaitoh panic("sh3_pcmcia_memio_unmap: overflow"); 5201.20Smsaitoh#endif 5211.20Smsaitoh 5221.22Smsaitoh pmap_extract(pmap_kernel(), va, &bpa); 5231.24Sichiro bpa += bsh & PGOFSET; 5241.20Smsaitoh 5251.20Smsaitoh /* 5261.20Smsaitoh * Free the kernel virtual mapping. 5271.20Smsaitoh */ 5281.20Smsaitoh uvm_km_free(kernel_map, va, endva - va); 5291.20Smsaitoh 5301.20Smsaitoh#if 0 5311.20Smsaitoh if (extent_free(ex, bpa, size, 5321.20Smsaitoh EX_NOWAIT | EX_MALLOCOK)) { 5331.20Smsaitoh printf("sh3_pcmcia_memio_unmap: %s 0x%lx, size 0x%lx\n", 5341.20Smsaitoh "pa", bpa, size); 5351.20Smsaitoh printf("sh3_pcmcia_memio_unmap: can't free region\n"); 5361.20Smsaitoh } 5371.20Smsaitoh#endif 5381.20Smsaitoh} 5391.20Smsaitoh 5401.20Smsaitohvoid 5411.20Smsaitohshpcmcia_memio_free(t, bsh, size) 5421.20Smsaitoh bus_space_tag_t t; 5431.20Smsaitoh bus_space_handle_t bsh; 5441.20Smsaitoh bus_size_t size; 5451.20Smsaitoh{ 5461.20Smsaitoh 5471.20Smsaitoh /* sh3_pcmcia_memio_unmap() does all that we need to do. */ 5481.20Smsaitoh shpcmcia_memio_unmap(t, bsh, size); 5491.20Smsaitoh} 5501.20Smsaitoh 5511.20Smsaitohint 5521.20Smsaitohshpcmcia_memio_subregion(t, bsh, offset, size, nbshp) 5531.20Smsaitoh bus_space_tag_t t; 5541.20Smsaitoh bus_space_handle_t bsh; 5551.20Smsaitoh bus_size_t offset, size; 5561.20Smsaitoh bus_space_handle_t *nbshp; 5571.20Smsaitoh{ 5581.20Smsaitoh 5591.20Smsaitoh *nbshp = bsh + offset; 5601.20Smsaitoh return (0); 5611.20Smsaitoh} 5621.20Smsaitoh 5631.20Smsaitoh#endif /* SH4_PCMCIA */ 5641.1Sitojun 5651.18Smsaitoh#if !defined(DONT_INIT_BSC) 5661.1Sitojun/* 5671.1Sitojun * InitializeBsc 5681.1Sitojun * : BSC(Bus State Controler) 5691.1Sitojun */ 5701.1Sitojunvoid InitializeBsc __P((void)); 5711.1Sitojun 5721.1Sitojunvoid 5731.1SitojunInitializeBsc() 5741.1Sitojun{ 5751.1Sitojun 5761.1Sitojun /* 5771.1Sitojun * Drive RAS,CAS in stand by mode and bus release mode 5781.1Sitojun * Area0 = Normal memory, Area5,6=Normal(no burst) 5791.1Sitojun * Area2 = Normal memory, Area3 = SDRAM, Area5 = Normal memory 5801.1Sitojun * Area4 = Normal Memory 5811.1Sitojun * Area6 = Normal memory 5821.1Sitojun */ 5831.33Such#if defined(SH3) 5841.33Such _reg_write_2(SH3_BCR1, BSC_BCR1_VAL); 5851.33Such#elif defined(SH4) 5861.33Such _reg_write_4(SH4_BCR1, BSC_BCR1_VAL); 5871.33Such#endif 5881.1Sitojun 5891.1Sitojun /* 5901.1Sitojun * Bus Width 5911.1Sitojun * Area4: Bus width = 16bit 5921.1Sitojun * Area6,5 = 16bit 5931.1Sitojun * Area1 = 8bit 5941.1Sitojun * Area2,3: Bus width = 32bit 5951.1Sitojun */ 5961.33Such _reg_write_2(SH_(BCR2), BSC_BCR2_VAL); 5971.1Sitojun 5981.1Sitojun /* 5991.1Sitojun * Idle cycle number in transition area and read to write 6001.1Sitojun * Area6 = 3, Area5 = 3, Area4 = 3, Area3 = 3, Area2 = 3 6011.1Sitojun * Area1 = 3, Area0 = 3 6021.1Sitojun */ 6031.33Such#if defined(SH3) 6041.33Such _reg_write_2(SH3_WCR1, BSC_WCR1_VAL); 6051.33Such#elif defined(SH4) 6061.33Such _reg_write_4(SH4_WCR1, BSC_WCR1_VAL); 6071.33Such#endif 6081.1Sitojun 6091.1Sitojun /* 6101.1Sitojun * Wait cycle 6111.1Sitojun * Area 6 = 6 6121.1Sitojun * Area 5 = 2 6131.1Sitojun * Area 4 = 10 6141.1Sitojun * Area 3 = 3 6151.1Sitojun * Area 2,1 = 3 6161.1Sitojun * Area 0 = 6 6171.1Sitojun */ 6181.33Such#if defined(SH3) 6191.33Such _reg_write_2(SH3_WCR2, BSC_WCR2_VAL); 6201.33Such#elif defined(SH4) 6211.33Such _reg_write_4(SH4_WCR2, BSC_WCR2_VAL); 6221.33Such#endif 6231.1Sitojun 6241.13Smsaitoh#if defined(SH4) && defined(BSC_WCR3_VAL) 6251.33Such _reg_write_4(SH4_WCR3, BSC_WCR3_VAL); 6261.1Sitojun#endif 6271.1Sitojun 6281.1Sitojun /* 6291.1Sitojun * RAS pre-charge = 2cycle, RAS-CAS delay = 3 cycle, 6301.1Sitojun * write pre-charge=1cycle 6311.1Sitojun * CAS before RAS refresh RAS assert time = 3 cycle 6321.1Sitojun * Disable burst, Bus size=32bit, Column Address=10bit, Refresh ON 6331.1Sitojun * CAS before RAS refresh ON, EDO DRAM 6341.1Sitojun */ 6351.33Such#if defined(SH3) 6361.33Such _reg_write_2(SH3_MCR, BSC_MCR_VAL); 6371.33Such#elif defined(SH4) 6381.33Such _reg_write_4(SH4_MCR, BSC_MCR_VAL); 6391.33Such#endif 6401.1Sitojun 6411.11Smsaitoh#if defined(BSC_SDMR2_VAL) 6421.33Such _reg_write_1(BSC_SDMR2_VAL, 0); 6431.11Smsaitoh#endif 6441.11Smsaitoh 6451.11Smsaitoh#if defined(BSC_SDMR3_VAL) 6461.19Smsaitoh#if !(defined(COMPUTEXEVB) && defined(SH7709A)) 6471.33Such _reg_write_1(BSC_SDMR3_VAL, 0); 6481.1Sitojun#else 6491.33Such _reg_write_2(0x1a000000, 0); /* ADDSET */ 6501.33Such _reg_write_1(BSC_SDMR3_VAL, 0); 6511.33Such _reg_write_2(0x18000000, 0); /* ADDRST */ 6521.33Such#endif /* !(COMPUTEXEVB && SH7709A) */ 6531.33Such#endif /* BSC_SDMR3_VAL */ 6541.1Sitojun 6551.1Sitojun /* 6561.1Sitojun * PCMCIA Control Register 6571.1Sitojun * OE/WE assert delay 3.5 cycle 6581.1Sitojun * OE/WE negate-address delay 3.5 cycle 6591.1Sitojun */ 6601.1Sitojun#ifdef BSC_PCR_VAL 6611.33Such _reg_write_2(SH_(PCR), BSC_PCR_VAL); 6621.1Sitojun#endif 6631.1Sitojun 6641.1Sitojun /* 6651.1Sitojun * Refresh Timer Control/Status Register 6661.1Sitojun * Disable interrupt by CMF, closk 1/16, Disable OVF interrupt 6671.1Sitojun * Count Limit = 1024 6681.1Sitojun * In following statement, the reason why high byte = 0xa5(a4 in RFCR) 6691.1Sitojun * is the rule of SH3 in writing these register. 6701.1Sitojun */ 6711.33Such _reg_write_2(SH_(RTCSR), BSC_RTCSR_VAL); 6721.1Sitojun 6731.1Sitojun /* 6741.1Sitojun * Refresh Timer Counter 6751.1Sitojun * Initialize to 0 6761.1Sitojun */ 6771.9Smsaitoh#ifdef BSC_RTCNT_VAL 6781.33Such _reg_write_2(SH_(RTCNT), BSC_RTCNT_VAL); 6791.9Smsaitoh#endif 6801.1Sitojun 6811.1Sitojun /* set Refresh Time Constant Register */ 6821.33Such _reg_write_2(SH_(RTCOR), BSC_RTCOR_VAL); 6831.1Sitojun 6841.1Sitojun /* init Refresh Count Register */ 6851.1Sitojun#ifdef BSC_RFCR_VAL 6861.33Such _reg_write_2(SH_(RFCR), BSC_RFCR_VAL); 6871.1Sitojun#endif 6881.1Sitojun 6891.33Such /* 6901.33Such * Clock Pulse Generator 6911.33Such */ 6921.1Sitojun /* Set Clock mode (make internal clock double speed) */ 6931.33Such _reg_write_2(SH_(FRQCR), FRQCR_VAL); 6941.1Sitojun 6951.33Such /* 6961.33Such * Cache 6971.33Such */ 6981.33Such#ifndef CACHE_DISABLE 6991.1Sitojun /* Cache ON */ 7001.33Such _reg_write_4(SH_(CCR), 0x1); 7011.1Sitojun#endif 7021.1Sitojun} 7031.33Such#endif /* !DONT_INIT_BSC */ 7041.9Smsaitoh 7051.8Smsaitoh 7061.8Smsaitoh /* XXX This value depends on physical available memory */ 7071.8Smsaitoh#define OSIMAGE_BUF_ADDR (IOM_RAM_BEGIN + 0x00400000) 7081.8Smsaitoh 7091.1Sitojunvoid 7101.3SmsaitohLoadAndReset(osimage) 7111.3Smsaitoh char *osimage; 7121.1Sitojun{ 7131.1Sitojun void *buf_addr; 7141.1Sitojun u_long size; 7151.1Sitojun u_long *src; 7161.1Sitojun u_long *dest; 7171.1Sitojun u_long csum = 0; 7181.1Sitojun u_long csum2 = 0; 7191.1Sitojun u_long size2; 7201.1Sitojun 7211.3Smsaitoh printf("LoadAndReset: copy start\n"); 7221.1Sitojun buf_addr = (void *)OSIMAGE_BUF_ADDR; 7231.1Sitojun 7241.1Sitojun size = *(u_long *)osimage; 7251.1Sitojun src = (u_long *)osimage; 7261.1Sitojun dest = buf_addr; 7271.1Sitojun 7281.3Smsaitoh size = (size + sizeof(u_long) * 2 + 3) >> 2; 7291.1Sitojun size2 = size; 7301.1Sitojun 7311.3Smsaitoh while (size--) { 7321.1Sitojun csum += *src; 7331.1Sitojun *dest++ = *src++; 7341.1Sitojun } 7351.1Sitojun 7361.1Sitojun dest = buf_addr; 7371.1Sitojun while (size2--) 7381.1Sitojun csum2 += *dest++; 7391.1Sitojun 7401.3Smsaitoh printf("LoadAndReset: copy end[%lx,%lx]\n", csum, csum2); 7411.1Sitojun printf("start XLoadAndReset\n"); 7421.1Sitojun 7431.1Sitojun /* mask all externel interrupt (XXX) */ 7441.1Sitojun 7451.1Sitojun XLoadAndReset(buf_addr); 7461.40Such} 7471.40Such 7481.40Suchvoid 7491.40Suchintc_intr(int ssr, int spc, int ssp) 7501.40Such{ 7511.40Such struct intc_intrhand *ih; 7521.40Such struct clockframe cf; 7531.40Such int s, evtcode; 7541.40Such 7551.40Such switch (cpu_product) { 7561.40Such case CPU_PRODUCT_7708: 7571.40Such case CPU_PRODUCT_7708S: 7581.40Such case CPU_PRODUCT_7708R: 7591.40Such evtcode = _reg_read_4(SH3_INTEVT); 7601.40Such break; 7611.40Such case CPU_PRODUCT_7709: 7621.40Such case CPU_PRODUCT_7709A: 7631.40Such evtcode = _reg_read_4(SH7709_INTEVT2); 7641.40Such break; 7651.40Such case CPU_PRODUCT_7750: 7661.40Such case CPU_PRODUCT_7750S: 7671.40Such evtcode = _reg_read_4(SH4_INTEVT); 7681.40Such break; 7691.40Such } 7701.40Such 7711.40Such ih = EVTCODE_IH(evtcode); 7721.40Such KDASSERT(ih->ih_func); 7731.40Such /* 7741.40Such * On entry, all interrrupts are disabled, 7751.40Such * and exception is enabled for P3 access. (kernel stack is P3, 7761.40Such * SH3 may or may not cause TLB miss when access stack.) 7771.40Such * Enable higher level interrupt here. 7781.40Such */ 7791.40Such s = _cpu_intr_resume(ih->ih_level); 7801.40Such 7811.40Such switch (evtcode) { 7821.40Such default: 7831.40Such (*ih->ih_func)(ih->ih_arg); 7841.40Such break; 7851.40Such case SH_INTEVT_TMU0_TUNI0: 7861.40Such cf.spc = spc; 7871.40Such cf.ssr = ssr; 7881.40Such cf.ssp = ssp; 7891.40Such (*ih->ih_func)(&cf); 7901.40Such break; 7911.40Such case SH_INTEVT_NMI: 7921.40Such printf("NMI ignored.\n"); 7931.40Such break; 7941.40Such } 7951.40Such 7961.40Such /* Return to old interrupt level. */ 7971.40Such _cpu_intr_resume(ssr & 0xf0); 7981.1Sitojun} 799