machdep.c revision 1.57
11.57Suebayasi/* $NetBSD: machdep.c,v 1.57 2006/03/17 16:06:51 uebayasi 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.48Sagc * 3. Neither the name of the University nor the names of its contributors 561.1Sitojun * may be used to endorse or promote products derived from this software 571.1Sitojun * without specific prior written permission. 581.1Sitojun * 591.1Sitojun * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 601.1Sitojun * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 611.1Sitojun * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 621.1Sitojun * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 631.1Sitojun * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 641.1Sitojun * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 651.1Sitojun * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 661.1Sitojun * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 671.1Sitojun * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 681.1Sitojun * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 691.1Sitojun * SUCH DAMAGE. 701.1Sitojun * 711.1Sitojun * @(#)machdep.c 7.4 (Berkeley) 6/3/91 721.1Sitojun */ 731.47Slukem 741.47Slukem#include <sys/cdefs.h> 751.57Suebayasi__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.57 2006/03/17 16:06:51 uebayasi Exp $"); 761.1Sitojun 771.1Sitojun#include "opt_ddb.h" 781.26Slukem#include "opt_kgdb.h" 791.1Sitojun#include "opt_memsize.h" 801.1Sitojun#include "opt_initbsc.h" 811.1Sitojun 821.1Sitojun#include <sys/param.h> 831.1Sitojun#include <sys/systm.h> 841.1Sitojun#include <sys/kernel.h> 851.1Sitojun#include <sys/user.h> 861.37Such#include <sys/mount.h> 871.1Sitojun#include <sys/reboot.h> 881.37Such#include <sys/sysctl.h> 891.46Sragge#include <sys/ksyms.h> 901.1Sitojun 911.37Such#include <uvm/uvm_extern.h> 921.1Sitojun 931.1Sitojun#include <dev/cons.h> 941.40Such 951.37Such#include <sh3/bscreg.h> 961.33Such#include <sh3/cpgreg.h> 971.33Such#include <sh3/cache_sh3.h> 981.40Such#include <sh3/cache_sh4.h> 991.40Such#include <sh3/exception.h> 1001.40Such 1011.40Such#include <machine/bus.h> 1021.40Such#include <machine/intr.h> 1031.40Such 1041.40Such#ifdef DDB 1051.40Such#include <machine/db_machdep.h> 1061.40Such#include <ddb/db_extern.h> 1071.40Such#endif 1081.1Sitojun 1091.46Sragge#include "ksyms.h" 1101.46Sragge 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.3Smsaitohvoid initSH3 __P((void *)); 1161.54Shevoid LoadAndReset __P((const char *)); 1171.3Smsaitohvoid XLoadAndReset __P((char *)); 1181.1Sitojun 1191.1Sitojun/* 1201.1Sitojun * Machine-dependent startup code 1211.1Sitojun * 1221.1Sitojun * This is called from main() in kern/main.c. 1231.1Sitojun */ 1241.1Sitojunvoid 1251.1Sitojuncpu_startup() 1261.1Sitojun{ 1271.1Sitojun 1281.39Such sh_startup(); 1291.1Sitojun} 1301.1Sitojun 1311.1Sitojun/* 1321.1Sitojun * machine dependent system variables. 1331.1Sitojun */ 1341.49Satatatstatic int 1351.49Satatatsysctl_machdep_loadandreset(SYSCTLFN_ARGS) 1361.1Sitojun{ 1371.54She const char *osimage; 1381.49Satatat int error; 1391.1Sitojun 1401.54She error = sysctl_lookup(SYSCTLFN_CALL(__UNCONST(rnode))); 1411.49Satatat if (error || newp == NULL) 1421.49Satatat return (error); 1431.49Satatat 1441.54She osimage = (const char *)(*(const u_long *)newp); 1451.49Satatat LoadAndReset(osimage); 1461.49Satatat /* not reach here */ 1471.49Satatat return (0); 1481.49Satatat} 1491.49Satatat 1501.49SatatatSYSCTL_SETUP(sysctl_machdep_setup, "sysctl machdep subtree setup") 1511.49Satatat{ 1521.49Satatat 1531.51Satatat sysctl_createv(clog, 0, NULL, NULL, 1541.51Satatat CTLFLAG_PERMANENT, 1551.49Satatat CTLTYPE_NODE, "machdep", NULL, 1561.49Satatat NULL, 0, NULL, 0, 1571.49Satatat CTL_MACHDEP, CTL_EOL); 1581.49Satatat 1591.51Satatat sysctl_createv(clog, 0, NULL, NULL, 1601.51Satatat CTLFLAG_PERMANENT, 1611.49Satatat CTLTYPE_STRUCT, "console_device", NULL, 1621.49Satatat sysctl_consdev, 0, NULL, sizeof(dev_t), 1631.49Satatat CTL_MACHDEP, CPU_CONSDEV, CTL_EOL); 1641.49Satatat/* 1651.49Satatat<atatat> okay...your turn to play. 1661.49Satatat<atatat> pick a number. 1671.49Satatat<kjk> 98752. 1681.49Satatat*/ 1691.51Satatat sysctl_createv(clog, 0, NULL, NULL, 1701.51Satatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE, 1711.49Satatat CTLTYPE_INT, "load_and_reset", NULL, 1721.49Satatat sysctl_machdep_loadandreset, 98752, NULL, 0, 1731.49Satatat CTL_MACHDEP, CPU_LOADANDRESET, CTL_EOL); 1741.1Sitojun} 1751.1Sitojun 1761.1Sitojunvoid 1771.1Sitojuncpu_reboot(howto, bootstr) 1781.1Sitojun int howto; 1791.1Sitojun char *bootstr; 1801.1Sitojun{ 1811.37Such static int waittime = -1; 1821.1Sitojun 1831.1Sitojun if (cold) { 1841.1Sitojun howto |= RB_HALT; 1851.1Sitojun goto haltsys; 1861.1Sitojun } 1871.1Sitojun 1881.1Sitojun boothowto = howto; 1891.1Sitojun if ((howto & RB_NOSYNC) == 0 && waittime < 0) { 1901.1Sitojun waittime = 0; 1911.1Sitojun vfs_shutdown(); 1921.1Sitojun /* 1931.1Sitojun * If we've been adjusting the clock, the todr 1941.1Sitojun * will be out of synch; adjust it now. 1951.1Sitojun */ 1961.1Sitojun /* resettodr(); */ 1971.1Sitojun } 1981.1Sitojun 1991.1Sitojun /* Disable interrupts. */ 2001.1Sitojun splhigh(); 2011.1Sitojun 2021.1Sitojun /* Do a dump if requested. */ 2031.1Sitojun if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP) 2041.1Sitojun dumpsys(); 2051.1Sitojun 2061.1Sitojunhaltsys: 2071.1Sitojun doshutdownhooks(); 2081.1Sitojun 2091.1Sitojun if (howto & RB_HALT) { 2101.1Sitojun printf("\n"); 2111.1Sitojun printf("The operating system has halted.\n"); 2121.1Sitojun printf("Please press any key to reboot.\n\n"); 2131.1Sitojun cngetc(); 2141.1Sitojun } 2151.1Sitojun 2161.1Sitojun printf("rebooting...\n"); 2171.1Sitojun cpu_reset(); 2181.1Sitojun for(;;) 2191.1Sitojun ; 2201.1Sitojun /*NOTREACHED*/ 2211.1Sitojun} 2221.1Sitojun 2231.1Sitojunvoid 2241.37SuchinitSH3(void *pc) /* XXX return address */ 2251.1Sitojun{ 2261.57Suebayasi extern char edata[], end[]; 2271.37Such vaddr_t kernend; 2281.3Smsaitoh 2291.37Such /* Clear bss */ 2301.57Suebayasi memset(edata, 0, end - edata); 2311.3Smsaitoh 2321.37Such /* Initilize CPU ops. */ 2331.30Such#if defined(SH3) && defined(SH4) 2341.30Such#error "don't define both SH3 and SH4" 2351.30Such#elif defined(SH3) 2361.40Such#if defined(SH7708) 2371.40Such sh_cpu_init(CPU_ARCH_SH3, CPU_PRODUCT_7708); 2381.40Such#elif defined(SH7708S) 2391.40Such sh_cpu_init(CPU_ARCH_SH3, CPU_PRODUCT_7708S); 2401.40Such#elif defined(SH7708R) 2411.40Such sh_cpu_init(CPU_ARCH_SH3, CPU_PRODUCT_7708R); 2421.40Such#elif defined(SH7709) 2431.40Such sh_cpu_init(CPU_ARCH_SH3, CPU_PRODUCT_7709); 2441.40Such#elif defined(SH7709A) 2451.40Such sh_cpu_init(CPU_ARCH_SH3, CPU_PRODUCT_7709A); 2461.40Such#else 2471.40Such#error "unsupported SH3 variants" 2481.40Such#endif 2491.30Such#elif defined(SH4) 2501.40Such#if defined(SH7750) 2511.40Such sh_cpu_init(CPU_ARCH_SH4, CPU_PRODUCT_7750); 2521.40Such#elif defined(SH7750S) 2531.40Such sh_cpu_init(CPU_ARCH_SH4, CPU_PRODUCT_7750S); 2541.40Such#else 2551.40Such#error "unsupported SH4 variants" 2561.40Such#endif 2571.30Such#else 2581.30Such#error "define SH3 or SH4" 2591.30Such#endif 2601.41Such /* Console */ 2611.41Such consinit(); 2621.41Such 2631.41Such /* Load memory to UVM */ 2641.57Suebayasi kernend = atop(round_page(SH3_P1SEG_TO_PHYS(end))); 2651.41Such physmem = atop(IOM_RAM_SIZE); 2661.41Such uvm_page_physload( 2671.41Such kernend, atop(IOM_RAM_BEGIN + IOM_RAM_SIZE), 2681.41Such kernend, atop(IOM_RAM_BEGIN + IOM_RAM_SIZE), 2691.41Such VM_FREELIST_DEFAULT); 2701.40Such 2711.41Such /* Initialize proc0 u-area */ 2721.41Such sh_proc0_init(); 2731.41Such 2741.41Such /* Initialize pmap and start to address translation */ 2751.41Such pmap_bootstrap(); 2761.1Sitojun 2771.46Sragge#if NKSYMS || defined(DDB) || defined(LKM) 2781.46Sragge ksyms_init(0, NULL, NULL); 2791.40Such#endif 2801.1Sitojun 2811.3Smsaitoh /* 2821.3Smsaitoh * XXX We can't return here, because we change stack pointer. 2831.3Smsaitoh * So jump to return address directly. 2841.3Smsaitoh */ 2851.56Sperry __asm volatile ( 2861.37Such "jmp @%0;" 2871.41Such "mov %1, r15" 2881.44Sthorpej :: "r"(pc),"r"(lwp0.l_md.md_pcb->pcb_sf.sf_r7_bank)); 2891.1Sitojun} 2901.1Sitojun 2911.1Sitojun/* 2921.1Sitojun * consinit: 2931.1Sitojun * initialize the system console. 2941.1Sitojun * XXX - shouldn't deal with this initted thing, but then, 2951.1Sitojun * it shouldn't be called from init386 either. 2961.1Sitojun */ 2971.1Sitojunvoid 2981.1Sitojunconsinit() 2991.1Sitojun{ 3001.1Sitojun static int initted; 3011.1Sitojun 3021.1Sitojun if (initted) 3031.1Sitojun return; 3041.1Sitojun initted = 1; 3051.1Sitojun 3061.1Sitojun cninit(); 3071.1Sitojun} 3081.1Sitojun 3091.1Sitojunint 3101.1Sitojunbus_space_map (t, addr, size, flags, bshp) 3111.1Sitojun bus_space_tag_t t; 3121.1Sitojun bus_addr_t addr; 3131.1Sitojun bus_size_t size; 3141.1Sitojun int flags; 3151.1Sitojun bus_space_handle_t *bshp; 3161.1Sitojun{ 3171.1Sitojun 3181.1Sitojun *bshp = (bus_space_handle_t)addr; 3191.1Sitojun 3201.1Sitojun return 0; 3211.1Sitojun} 3221.1Sitojun 3231.1Sitojunint 3241.1Sitojunsh_memio_subregion(t, bsh, offset, size, nbshp) 3251.1Sitojun bus_space_tag_t t; 3261.1Sitojun bus_space_handle_t bsh; 3271.1Sitojun bus_size_t offset, size; 3281.1Sitojun bus_space_handle_t *nbshp; 3291.1Sitojun{ 3301.1Sitojun 3311.1Sitojun *nbshp = bsh + offset; 3321.1Sitojun return (0); 3331.1Sitojun} 3341.1Sitojun 3351.1Sitojunint 3361.1Sitojunsh_memio_alloc(t, rstart, rend, size, alignment, boundary, flags, 3371.1Sitojun bpap, bshp) 3381.1Sitojun bus_space_tag_t t; 3391.1Sitojun bus_addr_t rstart, rend; 3401.1Sitojun bus_size_t size, alignment, boundary; 3411.1Sitojun int flags; 3421.1Sitojun bus_addr_t *bpap; 3431.1Sitojun bus_space_handle_t *bshp; 3441.1Sitojun{ 3451.1Sitojun *bshp = *bpap = rstart; 3461.1Sitojun 3471.1Sitojun return (0); 3481.1Sitojun} 3491.1Sitojun 3501.1Sitojunvoid 3511.1Sitojunsh_memio_free(t, bsh, size) 3521.1Sitojun bus_space_tag_t t; 3531.1Sitojun bus_space_handle_t bsh; 3541.1Sitojun bus_size_t size; 3551.1Sitojun{ 3561.1Sitojun 3571.1Sitojun} 3581.1Sitojun 3591.1Sitojunvoid 3601.1Sitojunsh_memio_unmap(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 return; 3661.1Sitojun} 3671.20Smsaitoh 3681.20Smsaitoh#ifdef SH4_PCMCIA 3691.20Smsaitoh 3701.20Smsaitohint 3711.20Smsaitohshpcmcia_memio_map(t, bpa, size, flags, bshp) 3721.20Smsaitoh bus_space_tag_t t; 3731.20Smsaitoh bus_addr_t bpa; 3741.20Smsaitoh bus_size_t size; 3751.20Smsaitoh int flags; 3761.20Smsaitoh bus_space_handle_t *bshp; 3771.20Smsaitoh{ 3781.20Smsaitoh int error; 3791.20Smsaitoh struct extent *ex; 3801.20Smsaitoh bus_space_tag_t pt = t & ~SH3_BUS_SPACE_PCMCIA_8BIT; 3811.20Smsaitoh 3821.20Smsaitoh if (pt != SH3_BUS_SPACE_PCMCIA_IO && 3831.20Smsaitoh pt != SH3_BUS_SPACE_PCMCIA_MEM && 3841.20Smsaitoh pt != SH3_BUS_SPACE_PCMCIA_ATT) { 3851.20Smsaitoh *bshp = (bus_space_handle_t)bpa; 3861.20Smsaitoh 3871.20Smsaitoh return 0; 3881.20Smsaitoh } 3891.20Smsaitoh 3901.20Smsaitoh ex = iomem_ex; 3911.20Smsaitoh 3921.20Smsaitoh#if 0 3931.20Smsaitoh /* 3941.20Smsaitoh * Before we go any further, let's make sure that this 3951.20Smsaitoh * region is available. 3961.20Smsaitoh */ 3971.20Smsaitoh error = extent_alloc_region(ex, bpa, size, 3981.20Smsaitoh EX_NOWAIT | EX_MALLOCOK ); 3991.20Smsaitoh if (error){ 4001.20Smsaitoh printf("sh3_pcmcia_memio_map:extent_alloc_region error\n"); 4011.20Smsaitoh return (error); 4021.20Smsaitoh } 4031.20Smsaitoh#endif 4041.20Smsaitoh 4051.20Smsaitoh /* 4061.20Smsaitoh * For memory space, map the bus physical address to 4071.20Smsaitoh * a kernel virtual address. 4081.20Smsaitoh */ 4091.20Smsaitoh error = shpcmcia_mem_add_mapping(bpa, size, (int)t, bshp ); 4101.20Smsaitoh#if 0 4111.20Smsaitoh if (error) { 4121.20Smsaitoh if (extent_free(ex, bpa, size, EX_NOWAIT | EX_MALLOCOK )) { 4131.20Smsaitoh printf("sh3_pcmcia_memio_map: pa 0x%lx, size 0x%lx\n", 4141.20Smsaitoh bpa, size); 4151.20Smsaitoh printf("sh3_pcmcia_memio_map: can't free region\n"); 4161.20Smsaitoh } 4171.20Smsaitoh } 4181.20Smsaitoh#endif 4191.20Smsaitoh 4201.20Smsaitoh return (error); 4211.20Smsaitoh} 4221.20Smsaitoh 4231.20Smsaitohint 4241.20Smsaitohshpcmcia_mem_add_mapping(bpa, size, type, bshp) 4251.20Smsaitoh bus_addr_t bpa; 4261.20Smsaitoh bus_size_t size; 4271.20Smsaitoh int type; 4281.20Smsaitoh bus_space_handle_t *bshp; 4291.20Smsaitoh{ 4301.20Smsaitoh u_long pa, endpa; 4311.20Smsaitoh vaddr_t va; 4321.20Smsaitoh pt_entry_t *pte; 4331.20Smsaitoh unsigned int m = 0; 4341.20Smsaitoh int io_type = type & ~SH3_BUS_SPACE_PCMCIA_8BIT; 4351.20Smsaitoh 4361.20Smsaitoh pa = sh3_trunc_page(bpa); 4371.20Smsaitoh endpa = sh3_round_page(bpa + size); 4381.20Smsaitoh 4391.20Smsaitoh#ifdef DIAGNOSTIC 4401.20Smsaitoh if (endpa <= pa) 4411.20Smsaitoh panic("sh3_pcmcia_mem_add_mapping: overflow"); 4421.20Smsaitoh#endif 4431.20Smsaitoh 4441.55Syamt va = uvm_km_alloc(kernel_map, endpa - pa, 0, 4451.55Syamt UVM_KMF_VAONLY | UVM_KMF_NOWAIT); 4461.20Smsaitoh if (va == 0){ 4471.20Smsaitoh printf("shpcmcia_add_mapping: nomem \n"); 4481.20Smsaitoh return (ENOMEM); 4491.20Smsaitoh } 4501.20Smsaitoh 4511.20Smsaitoh *bshp = (bus_space_handle_t)(va + (bpa & PGOFSET)); 4521.20Smsaitoh 4531.29Such#define MODE(t, s) \ 4541.29Such (t) & SH3_BUS_SPACE_PCMCIA_8BIT ? \ 4551.29Such _PG_PCMCIA_ ## s ## 8 : \ 4561.29Such _PG_PCMCIA_ ## s ## 16 4571.29Such switch (io_type) { 4581.29Such default: 4591.29Such panic("unknown pcmcia space."); 4601.29Such /* NOTREACHED */ 4611.29Such case SH3_BUS_SPACE_PCMCIA_IO: 4621.29Such m = MODE(type, IO); 4631.29Such break; 4641.29Such case SH3_BUS_SPACE_PCMCIA_MEM: 4651.29Such m = MODE(type, MEM); 4661.29Such break; 4671.29Such case SH3_BUS_SPACE_PCMCIA_ATT: 4681.29Such m = MODE(type, ATTR); 4691.29Such break; 4701.20Smsaitoh } 4711.29Such#undef MODE 4721.20Smsaitoh 4731.45Sthorpej for (; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) { 4741.41Such pmap_kenter_pa(va, pa, VM_PROT_READ | VM_PROT_WRITE); 4751.41Such pte = __pmap_kpte_lookup(va); 4761.41Such KDASSERT(pte); 4771.41Such *pte |= m; /* PTEA PCMCIA assistant bit */ 4781.41Such sh_tlb_update(0, va, *pte); 4791.41Such } 4801.20Smsaitoh 4811.20Smsaitoh return 0; 4821.20Smsaitoh} 4831.20Smsaitoh 4841.20Smsaitohvoid 4851.20Smsaitohshpcmcia_memio_unmap(t, bsh, size) 4861.20Smsaitoh bus_space_tag_t t; 4871.20Smsaitoh bus_space_handle_t bsh; 4881.20Smsaitoh bus_size_t size; 4891.20Smsaitoh{ 4901.20Smsaitoh struct extent *ex; 4911.20Smsaitoh u_long va, endva; 4921.20Smsaitoh bus_addr_t bpa; 4931.20Smsaitoh bus_space_tag_t pt = t & ~SH3_BUS_SPACE_PCMCIA_8BIT; 4941.20Smsaitoh 4951.20Smsaitoh if (pt != SH3_BUS_SPACE_PCMCIA_IO && 4961.20Smsaitoh pt != SH3_BUS_SPACE_PCMCIA_MEM && 4971.20Smsaitoh pt != SH3_BUS_SPACE_PCMCIA_ATT) { 4981.20Smsaitoh return ; 4991.20Smsaitoh } 5001.20Smsaitoh 5011.20Smsaitoh ex = iomem_ex; 5021.20Smsaitoh 5031.20Smsaitoh va = sh3_trunc_page(bsh); 5041.20Smsaitoh endva = sh3_round_page(bsh + size); 5051.20Smsaitoh 5061.20Smsaitoh#ifdef DIAGNOSTIC 5071.20Smsaitoh if (endva <= va) 5081.20Smsaitoh panic("sh3_pcmcia_memio_unmap: overflow"); 5091.20Smsaitoh#endif 5101.20Smsaitoh 5111.22Smsaitoh pmap_extract(pmap_kernel(), va, &bpa); 5121.24Sichiro bpa += bsh & PGOFSET; 5131.20Smsaitoh 5141.20Smsaitoh /* 5151.20Smsaitoh * Free the kernel virtual mapping. 5161.20Smsaitoh */ 5171.53Syamt pmap_kremove(va, endva - va); 5181.53Syamt pmap_update(pmap_kernel()); 5191.53Syamt uvm_km_free(kernel_map, va, endva - va, UVM_KMF_VAONLY); 5201.20Smsaitoh 5211.20Smsaitoh#if 0 5221.20Smsaitoh if (extent_free(ex, bpa, size, 5231.20Smsaitoh EX_NOWAIT | EX_MALLOCOK)) { 5241.20Smsaitoh printf("sh3_pcmcia_memio_unmap: %s 0x%lx, size 0x%lx\n", 5251.20Smsaitoh "pa", bpa, size); 5261.20Smsaitoh printf("sh3_pcmcia_memio_unmap: can't free region\n"); 5271.20Smsaitoh } 5281.20Smsaitoh#endif 5291.20Smsaitoh} 5301.20Smsaitoh 5311.20Smsaitohvoid 5321.20Smsaitohshpcmcia_memio_free(t, bsh, size) 5331.20Smsaitoh bus_space_tag_t t; 5341.20Smsaitoh bus_space_handle_t bsh; 5351.20Smsaitoh bus_size_t size; 5361.20Smsaitoh{ 5371.20Smsaitoh 5381.20Smsaitoh /* sh3_pcmcia_memio_unmap() does all that we need to do. */ 5391.20Smsaitoh shpcmcia_memio_unmap(t, bsh, size); 5401.20Smsaitoh} 5411.20Smsaitoh 5421.20Smsaitohint 5431.20Smsaitohshpcmcia_memio_subregion(t, bsh, offset, size, nbshp) 5441.20Smsaitoh bus_space_tag_t t; 5451.20Smsaitoh bus_space_handle_t bsh; 5461.20Smsaitoh bus_size_t offset, size; 5471.20Smsaitoh bus_space_handle_t *nbshp; 5481.20Smsaitoh{ 5491.20Smsaitoh 5501.20Smsaitoh *nbshp = bsh + offset; 5511.20Smsaitoh return (0); 5521.20Smsaitoh} 5531.20Smsaitoh 5541.20Smsaitoh#endif /* SH4_PCMCIA */ 5551.1Sitojun 5561.18Smsaitoh#if !defined(DONT_INIT_BSC) 5571.1Sitojun/* 5581.1Sitojun * InitializeBsc 5591.50Swiz * : BSC(Bus State Controller) 5601.1Sitojun */ 5611.1Sitojunvoid InitializeBsc __P((void)); 5621.1Sitojun 5631.1Sitojunvoid 5641.1SitojunInitializeBsc() 5651.1Sitojun{ 5661.1Sitojun 5671.1Sitojun /* 5681.1Sitojun * Drive RAS,CAS in stand by mode and bus release mode 5691.1Sitojun * Area0 = Normal memory, Area5,6=Normal(no burst) 5701.1Sitojun * Area2 = Normal memory, Area3 = SDRAM, Area5 = Normal memory 5711.1Sitojun * Area4 = Normal Memory 5721.1Sitojun * Area6 = Normal memory 5731.1Sitojun */ 5741.33Such#if defined(SH3) 5751.33Such _reg_write_2(SH3_BCR1, BSC_BCR1_VAL); 5761.33Such#elif defined(SH4) 5771.33Such _reg_write_4(SH4_BCR1, BSC_BCR1_VAL); 5781.33Such#endif 5791.1Sitojun 5801.1Sitojun /* 5811.1Sitojun * Bus Width 5821.1Sitojun * Area4: Bus width = 16bit 5831.1Sitojun * Area6,5 = 16bit 5841.1Sitojun * Area1 = 8bit 5851.1Sitojun * Area2,3: Bus width = 32bit 5861.1Sitojun */ 5871.33Such _reg_write_2(SH_(BCR2), BSC_BCR2_VAL); 5881.1Sitojun 5891.1Sitojun /* 5901.1Sitojun * Idle cycle number in transition area and read to write 5911.1Sitojun * Area6 = 3, Area5 = 3, Area4 = 3, Area3 = 3, Area2 = 3 5921.1Sitojun * Area1 = 3, Area0 = 3 5931.1Sitojun */ 5941.33Such#if defined(SH3) 5951.33Such _reg_write_2(SH3_WCR1, BSC_WCR1_VAL); 5961.33Such#elif defined(SH4) 5971.33Such _reg_write_4(SH4_WCR1, BSC_WCR1_VAL); 5981.33Such#endif 5991.1Sitojun 6001.1Sitojun /* 6011.1Sitojun * Wait cycle 6021.1Sitojun * Area 6 = 6 6031.1Sitojun * Area 5 = 2 6041.1Sitojun * Area 4 = 10 6051.1Sitojun * Area 3 = 3 6061.1Sitojun * Area 2,1 = 3 6071.1Sitojun * Area 0 = 6 6081.1Sitojun */ 6091.33Such#if defined(SH3) 6101.33Such _reg_write_2(SH3_WCR2, BSC_WCR2_VAL); 6111.33Such#elif defined(SH4) 6121.33Such _reg_write_4(SH4_WCR2, BSC_WCR2_VAL); 6131.33Such#endif 6141.1Sitojun 6151.13Smsaitoh#if defined(SH4) && defined(BSC_WCR3_VAL) 6161.33Such _reg_write_4(SH4_WCR3, BSC_WCR3_VAL); 6171.1Sitojun#endif 6181.1Sitojun 6191.1Sitojun /* 6201.1Sitojun * RAS pre-charge = 2cycle, RAS-CAS delay = 3 cycle, 6211.1Sitojun * write pre-charge=1cycle 6221.1Sitojun * CAS before RAS refresh RAS assert time = 3 cycle 6231.1Sitojun * Disable burst, Bus size=32bit, Column Address=10bit, Refresh ON 6241.1Sitojun * CAS before RAS refresh ON, EDO DRAM 6251.1Sitojun */ 6261.33Such#if defined(SH3) 6271.33Such _reg_write_2(SH3_MCR, BSC_MCR_VAL); 6281.33Such#elif defined(SH4) 6291.33Such _reg_write_4(SH4_MCR, BSC_MCR_VAL); 6301.33Such#endif 6311.1Sitojun 6321.11Smsaitoh#if defined(BSC_SDMR2_VAL) 6331.33Such _reg_write_1(BSC_SDMR2_VAL, 0); 6341.11Smsaitoh#endif 6351.11Smsaitoh 6361.11Smsaitoh#if defined(BSC_SDMR3_VAL) 6371.19Smsaitoh#if !(defined(COMPUTEXEVB) && defined(SH7709A)) 6381.33Such _reg_write_1(BSC_SDMR3_VAL, 0); 6391.1Sitojun#else 6401.33Such _reg_write_2(0x1a000000, 0); /* ADDSET */ 6411.33Such _reg_write_1(BSC_SDMR3_VAL, 0); 6421.33Such _reg_write_2(0x18000000, 0); /* ADDRST */ 6431.33Such#endif /* !(COMPUTEXEVB && SH7709A) */ 6441.33Such#endif /* BSC_SDMR3_VAL */ 6451.1Sitojun 6461.1Sitojun /* 6471.1Sitojun * PCMCIA Control Register 6481.1Sitojun * OE/WE assert delay 3.5 cycle 6491.1Sitojun * OE/WE negate-address delay 3.5 cycle 6501.1Sitojun */ 6511.1Sitojun#ifdef BSC_PCR_VAL 6521.33Such _reg_write_2(SH_(PCR), BSC_PCR_VAL); 6531.1Sitojun#endif 6541.1Sitojun 6551.1Sitojun /* 6561.1Sitojun * Refresh Timer Control/Status Register 6571.1Sitojun * Disable interrupt by CMF, closk 1/16, Disable OVF interrupt 6581.1Sitojun * Count Limit = 1024 6591.1Sitojun * In following statement, the reason why high byte = 0xa5(a4 in RFCR) 6601.1Sitojun * is the rule of SH3 in writing these register. 6611.1Sitojun */ 6621.33Such _reg_write_2(SH_(RTCSR), BSC_RTCSR_VAL); 6631.1Sitojun 6641.1Sitojun /* 6651.1Sitojun * Refresh Timer Counter 6661.1Sitojun * Initialize to 0 6671.1Sitojun */ 6681.9Smsaitoh#ifdef BSC_RTCNT_VAL 6691.33Such _reg_write_2(SH_(RTCNT), BSC_RTCNT_VAL); 6701.9Smsaitoh#endif 6711.1Sitojun 6721.1Sitojun /* set Refresh Time Constant Register */ 6731.33Such _reg_write_2(SH_(RTCOR), BSC_RTCOR_VAL); 6741.1Sitojun 6751.1Sitojun /* init Refresh Count Register */ 6761.1Sitojun#ifdef BSC_RFCR_VAL 6771.33Such _reg_write_2(SH_(RFCR), BSC_RFCR_VAL); 6781.1Sitojun#endif 6791.1Sitojun 6801.33Such /* 6811.33Such * Clock Pulse Generator 6821.33Such */ 6831.1Sitojun /* Set Clock mode (make internal clock double speed) */ 6841.33Such _reg_write_2(SH_(FRQCR), FRQCR_VAL); 6851.1Sitojun 6861.33Such /* 6871.33Such * Cache 6881.33Such */ 6891.33Such#ifndef CACHE_DISABLE 6901.1Sitojun /* Cache ON */ 6911.33Such _reg_write_4(SH_(CCR), 0x1); 6921.1Sitojun#endif 6931.1Sitojun} 6941.33Such#endif /* !DONT_INIT_BSC */ 6951.9Smsaitoh 6961.8Smsaitoh 6971.8Smsaitoh /* XXX This value depends on physical available memory */ 6981.8Smsaitoh#define OSIMAGE_BUF_ADDR (IOM_RAM_BEGIN + 0x00400000) 6991.8Smsaitoh 7001.1Sitojunvoid 7011.3SmsaitohLoadAndReset(osimage) 7021.54She const char *osimage; 7031.1Sitojun{ 7041.1Sitojun void *buf_addr; 7051.1Sitojun u_long size; 7061.54She const u_long *src; 7071.1Sitojun u_long *dest; 7081.1Sitojun u_long csum = 0; 7091.1Sitojun u_long csum2 = 0; 7101.1Sitojun u_long size2; 7111.1Sitojun 7121.3Smsaitoh printf("LoadAndReset: copy start\n"); 7131.1Sitojun buf_addr = (void *)OSIMAGE_BUF_ADDR; 7141.1Sitojun 7151.54She size = *(const u_long *)osimage; 7161.54She src = (const u_long *)osimage; 7171.1Sitojun dest = buf_addr; 7181.1Sitojun 7191.3Smsaitoh size = (size + sizeof(u_long) * 2 + 3) >> 2; 7201.1Sitojun size2 = size; 7211.1Sitojun 7221.3Smsaitoh while (size--) { 7231.1Sitojun csum += *src; 7241.1Sitojun *dest++ = *src++; 7251.1Sitojun } 7261.1Sitojun 7271.1Sitojun dest = buf_addr; 7281.1Sitojun while (size2--) 7291.1Sitojun csum2 += *dest++; 7301.1Sitojun 7311.3Smsaitoh printf("LoadAndReset: copy end[%lx,%lx]\n", csum, csum2); 7321.1Sitojun printf("start XLoadAndReset\n"); 7331.1Sitojun 7341.1Sitojun /* mask all externel interrupt (XXX) */ 7351.1Sitojun 7361.1Sitojun XLoadAndReset(buf_addr); 7371.40Such} 7381.40Such 7391.40Suchvoid 7401.40Suchintc_intr(int ssr, int spc, int ssp) 7411.40Such{ 7421.40Such struct intc_intrhand *ih; 7431.40Such struct clockframe cf; 7441.40Such int s, evtcode; 7451.40Such 7461.40Such switch (cpu_product) { 7471.40Such case CPU_PRODUCT_7708: 7481.40Such case CPU_PRODUCT_7708S: 7491.40Such case CPU_PRODUCT_7708R: 7501.40Such evtcode = _reg_read_4(SH3_INTEVT); 7511.40Such break; 7521.40Such case CPU_PRODUCT_7709: 7531.40Such case CPU_PRODUCT_7709A: 7541.40Such evtcode = _reg_read_4(SH7709_INTEVT2); 7551.40Such break; 7561.40Such case CPU_PRODUCT_7750: 7571.40Such case CPU_PRODUCT_7750S: 7581.40Such evtcode = _reg_read_4(SH4_INTEVT); 7591.40Such break; 7601.52Smatt default: 7611.52Smatt#ifdef DIAGNOSTIC 7621.52Smatt panic("intr_intc: cpu_product %d unhandled!", cpu_product); 7631.52Smatt#endif 7641.52Smatt return; 7651.40Such } 7661.40Such 7671.40Such ih = EVTCODE_IH(evtcode); 7681.40Such KDASSERT(ih->ih_func); 7691.40Such /* 7701.40Such * On entry, all interrrupts are disabled, 7711.40Such * and exception is enabled for P3 access. (kernel stack is P3, 7721.40Such * SH3 may or may not cause TLB miss when access stack.) 7731.40Such * Enable higher level interrupt here. 7741.40Such */ 7751.40Such s = _cpu_intr_resume(ih->ih_level); 7761.40Such 7771.40Such switch (evtcode) { 7781.40Such default: 7791.40Such (*ih->ih_func)(ih->ih_arg); 7801.40Such break; 7811.40Such case SH_INTEVT_TMU0_TUNI0: 7821.40Such cf.spc = spc; 7831.40Such cf.ssr = ssr; 7841.40Such cf.ssp = ssp; 7851.40Such (*ih->ih_func)(&cf); 7861.40Such break; 7871.40Such case SH_INTEVT_NMI: 7881.40Such printf("NMI ignored.\n"); 7891.40Such break; 7901.40Such } 7911.42Such} 7921.40Such 793