Home | History | Annotate | Line # | Download | only in tx
tx39.c revision 1.39.18.2
      1  1.39.18.2      matt /*	$NetBSD: tx39.c,v 1.39.18.2 2010/12/29 08:16:22 matt Exp $ */
      2        1.1       uch 
      3       1.17       uch /*-
      4       1.20       uch  * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
      5       1.20       uch  * All rights reserved.
      6       1.20       uch  *
      7       1.20       uch  * This code is derived from software contributed to The NetBSD Foundation
      8       1.20       uch  * by UCHIYAMA Yasushi.
      9        1.1       uch  *
     10        1.1       uch  * Redistribution and use in source and binary forms, with or without
     11        1.1       uch  * modification, are permitted provided that the following conditions
     12        1.1       uch  * are met:
     13        1.1       uch  * 1. Redistributions of source code must retain the above copyright
     14        1.1       uch  *    notice, this list of conditions and the following disclaimer.
     15       1.16       uch  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.16       uch  *    notice, this list of conditions and the following disclaimer in the
     17       1.16       uch  *    documentation and/or other materials provided with the distribution.
     18        1.1       uch  *
     19       1.20       uch  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20       1.20       uch  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21       1.20       uch  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22       1.20       uch  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23       1.20       uch  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24       1.20       uch  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25       1.20       uch  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26       1.20       uch  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27       1.20       uch  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28       1.20       uch  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29       1.20       uch  * POSSIBILITY OF SUCH DAMAGE.
     30        1.1       uch  */
     31       1.33     lukem 
     32       1.33     lukem #include <sys/cdefs.h>
     33  1.39.18.2      matt __KERNEL_RCSID(0, "$NetBSD: tx39.c,v 1.39.18.2 2010/12/29 08:16:22 matt Exp $");
     34        1.1       uch 
     35       1.27       uch #include "opt_vr41xx.h"
     36       1.27       uch #include "opt_tx39xx.h"
     37        1.5       uch #include "m38813c.h"
     38        1.6       uch #include "tc5165buf.h"
     39        1.1       uch 
     40        1.1       uch #include <sys/param.h>
     41        1.1       uch #include <sys/systm.h>
     42  1.39.18.2      matt #include <sys/intr.h>
     43        1.1       uch 
     44       1.32   thorpej #include <uvm/uvm_extern.h>
     45       1.32   thorpej 
     46       1.28       uch #include <mips/cache.h>
     47       1.28       uch 
     48        1.1       uch #include <machine/bootinfo.h> /* bootinfo */
     49        1.1       uch #include <machine/sysconf.h>  /* platform */
     50        1.1       uch 
     51        1.6       uch #include <machine/platid.h>
     52        1.6       uch #include <machine/platid_mask.h>
     53        1.6       uch 
     54        1.1       uch #include <machine/bus.h>
     55        1.1       uch 
     56        1.1       uch #include <hpcmips/tx/tx39biureg.h>
     57        1.1       uch #include <hpcmips/tx/tx39reg.h>
     58        1.1       uch #include <hpcmips/tx/tx39var.h>
     59        1.1       uch #ifdef TX391X
     60        1.1       uch #include <hpcmips/tx/tx3912videovar.h>
     61        1.1       uch #endif
     62        1.1       uch 
     63        1.1       uch #include <sys/termios.h>
     64        1.1       uch #include <sys/ttydefaults.h>
     65        1.1       uch #include <hpcmips/tx/tx39uartvar.h>
     66        1.1       uch #ifndef CONSPEED
     67        1.1       uch #define CONSPEED TTYDEF_SPEED
     68        1.1       uch #endif
     69        1.1       uch 
     70        1.5       uch /* console keyboard */
     71        1.5       uch #if NM38813C > 0
     72        1.5       uch #include <hpcmips/dev/m38813cvar.h>
     73        1.1       uch #endif
     74        1.6       uch #if NTC5165BUF > 0
     75        1.6       uch #include <hpcmips/dev/tc5165bufvar.h>
     76        1.6       uch #endif
     77        1.1       uch 
     78        1.1       uch struct tx_chipset_tag tx_chipset;
     79        1.1       uch 
     80       1.20       uch void	tx_init(void);
     81       1.27       uch #if defined(VR41XX) && defined(TX39XX)
     82       1.27       uch #define	TX_INTR	tx_intr
     83       1.27       uch #else
     84       1.27       uch #define	TX_INTR	cpu_intr	/* locore_mips3 directly call this */
     85       1.27       uch #endif
     86       1.27       uch 
     87  1.39.18.2      matt extern void TX_INTR(int, vaddr_t, uint32_t);
     88       1.27       uch 
     89       1.26       uch void	tx39clock_cpuspeed(int *, int *);
     90        1.1       uch 
     91        1.1       uch /* TX39-specific initialization vector */
     92       1.20       uch void	tx_cons_init(void);
     93       1.36  christos void    tx_fb_init(void **);
     94       1.20       uch void    tx_mem_init(paddr_t);
     95       1.20       uch void	tx_find_dram(paddr_t, paddr_t);
     96       1.20       uch void	tx_reboot(int, char *);
     97        1.1       uch 
     98        1.1       uch void
     99        1.1       uch tx_init()
    100        1.1       uch {
    101        1.1       uch 	tx_chipset_tag_t tc;
    102        1.1       uch 	int model, rev;
    103        1.8       uch 	int cpuclock;
    104        1.1       uch 
    105        1.1       uch 	tc = tx_conf_get_tag();
    106        1.1       uch 	/*
    107        1.1       uch 	 * Platform Specific Function Hooks
    108        1.1       uch 	 */
    109       1.27       uch 	platform.cpu_intr	= TX_INTR;
    110       1.25       uch 	platform.cpu_idle	= NULL; /* not implemented yet */
    111       1.25       uch 	platform.cons_init	= tx_cons_init;
    112       1.25       uch 	platform.fb_init	= tx_fb_init;
    113       1.25       uch 	platform.mem_init	= tx_mem_init;
    114       1.25       uch 	platform.reboot		= tx_reboot;
    115       1.27       uch 
    116        1.1       uch 
    117  1.39.18.1      matt 	model = MIPS_PRID_REV(mips_options.mips_cpu_id);
    118        1.1       uch 
    119        1.1       uch 	switch (model) {
    120        1.1       uch 	default:
    121       1.23       uch 		/* Unknown TOSHIBA TX39-series */
    122       1.19       cgd 		sprintf(cpu_name, "Unknown TOSHIBA TX39-series %x", model);
    123        1.1       uch 		break;
    124        1.1       uch 	case TMPR3912:
    125        1.8       uch 		tx39clock_cpuspeed(&cpuclock, &cpuspeed);
    126        1.8       uch 
    127       1.13      sato 		sprintf(cpu_name, "TOSHIBA TMPR3912 %d.%02d MHz",
    128       1.23       uch 		    cpuclock / 1000000, (cpuclock % 1000000) / 10000);
    129       1.20       uch 		tc->tc_chipset = __TX391X;
    130        1.1       uch 		break;
    131        1.1       uch 	case TMPR3922:
    132        1.8       uch 		tx39clock_cpuspeed(&cpuclock, &cpuspeed);
    133        1.1       uch 		rev = tx_conf_read(tc, TX3922_REVISION_REG);
    134        1.8       uch 
    135       1.13      sato 		sprintf(cpu_name, "TOSHIBA TMPR3922 rev. %x.%x "
    136       1.23       uch 		    "%d.%02d MHz", (rev >> 4) & 0xf, rev & 0xf,
    137       1.23       uch 		    cpuclock / 1000000, (cpuclock % 1000000) / 10000);
    138       1.20       uch 		tc->tc_chipset = __TX392X;
    139        1.1       uch 		break;
    140        1.1       uch 	}
    141        1.1       uch }
    142        1.1       uch 
    143        1.1       uch void
    144       1.36  christos tx_fb_init(void **kernend)
    145        1.1       uch {
    146        1.1       uch #ifdef TX391X
    147       1.16       uch 	paddr_t fb_end;
    148        1.1       uch 
    149       1.16       uch 	fb_end = MIPS_KSEG0_TO_PHYS(mem_clusters[0].start +
    150       1.23       uch 	    mem_clusters[0].size - 1);
    151       1.16       uch 	tx3912video_init(MIPS_KSEG0_TO_PHYS(*kernend), &fb_end);
    152       1.16       uch 
    153        1.1       uch 	/* Skip V-RAM area */
    154       1.36  christos 	*kernend = (void *)MIPS_PHYS_TO_KSEG0(fb_end);
    155        1.1       uch #endif /* TX391X */
    156        1.1       uch #ifdef TX392X
    157        1.1       uch 	/*
    158        1.1       uch 	 *  Plum V-RAM isn't accessible until pmap_bootstrap,
    159        1.7       uch 	 * at this time, frame buffer device is disabled.
    160        1.1       uch 	 */
    161        1.1       uch 	bootinfo->fb_addr = 0;
    162        1.1       uch #endif /* TX392X */
    163        1.1       uch }
    164        1.1       uch 
    165       1.14      shin void
    166       1.26       uch tx_mem_init(paddr_t kernend)
    167        1.1       uch {
    168       1.26       uch 
    169       1.14      shin 	mem_clusters[0].start = 0;
    170       1.14      shin 	mem_clusters[0].size = kernend;
    171       1.14      shin 	mem_cluster_cnt = 1;
    172       1.14      shin 	/* search DRAM bank 0 */
    173       1.14      shin 	tx_find_dram(kernend, 0x02000000);
    174        1.1       uch 
    175       1.14      shin 	/* search DRAM bank 1 */
    176       1.14      shin 	tx_find_dram(0x02000000, 0x04000000);
    177        1.2  takemura }
    178        1.2  takemura 
    179        1.2  takemura void
    180       1.26       uch tx_find_dram(paddr_t start, paddr_t end)
    181        1.2  takemura {
    182       1.38        he 	char *page, *startaddr, *endaddr;
    183  1.39.18.2      matt 	uint32_t magic0, magic1;
    184  1.39.18.2      matt #define MAGIC0		(*(volatile uint32_t *)(page + 0))
    185  1.39.18.2      matt #define MAGIC1		(*(volatile uint32_t *)(page + 4))
    186       1.14      shin 
    187       1.38        he 	startaddr = (char *)MIPS_PHYS_TO_KSEG1(start);
    188       1.38        he 	endaddr = (char *)MIPS_PHYS_TO_KSEG1(end);
    189        1.1       uch 
    190        1.1       uch 	page = startaddr;
    191       1.14      shin 	if (badaddr(page, 4))
    192       1.14      shin 		return;
    193       1.14      shin 
    194       1.28       uch 	do {
    195       1.28       uch 		magic0 = random();
    196       1.28       uch 		magic1 = random();
    197       1.28       uch 	} while (MAGIC0 == magic0 || MAGIC0 == magic1);
    198       1.28       uch 
    199       1.28       uch 	MAGIC0 = magic0;
    200       1.28       uch 	MAGIC1 = magic1;
    201       1.14      shin 	wbflush();
    202       1.14      shin 
    203       1.28       uch 	if (MAGIC0 != magic0 || MAGIC1 != magic1)
    204       1.14      shin 		return;
    205       1.14      shin 
    206       1.32   thorpej 	for (page += PAGE_SIZE; page < endaddr; page += PAGE_SIZE) {
    207       1.14      shin 		if (badaddr(page, 4))
    208       1.14      shin 			return;
    209       1.28       uch 		if (MAGIC0 == magic0 &&
    210       1.28       uch 		    MAGIC1 == magic1) {
    211       1.17       uch 			goto memend_found;
    212        1.1       uch 		}
    213        1.1       uch 	}
    214       1.14      shin 
    215       1.17       uch 	/* check for 32MByte memory */
    216       1.32   thorpej 	page -= PAGE_SIZE;
    217       1.28       uch 	MAGIC0 = magic0;
    218       1.28       uch 	MAGIC1 = magic1;
    219       1.17       uch 	wbflush();
    220       1.28       uch 	if (MAGIC0 != magic0 || MAGIC1 != magic1)
    221       1.17       uch 		return; /* no memory in this bank */
    222       1.17       uch 
    223       1.17       uch  memend_found:
    224       1.17       uch 	mem_clusters[mem_cluster_cnt].start = start;
    225       1.17       uch 	mem_clusters[mem_cluster_cnt].size = page - startaddr;
    226       1.29       uch 
    227       1.29       uch 	/* skip kernel area */
    228       1.29       uch 	if (mem_cluster_cnt == 1)
    229       1.29       uch 		mem_clusters[mem_cluster_cnt].size -= start;
    230       1.29       uch 
    231       1.17       uch 	mem_cluster_cnt++;
    232       1.28       uch #undef MAGIC0
    233       1.28       uch #undef MAGIC1
    234       1.14      shin }
    235       1.14      shin 
    236       1.14      shin void
    237       1.26       uch tx_reboot(int howto, char *bootstr)
    238       1.14      shin {
    239       1.26       uch 
    240  1.39.18.2      matt 	goto *(uint32_t *)MIPS_RESET_EXC_VEC;
    241        1.1       uch }
    242        1.1       uch 
    243        1.1       uch void
    244        1.1       uch tx_cons_init()
    245        1.1       uch {
    246        1.1       uch 	int slot;
    247       1.20       uch #define CONSPLATIDMATCH(p)						\
    248        1.6       uch 	platid_match(&platid, &platid_mask_MACH_##p)
    249        1.1       uch 
    250        1.1       uch #ifdef SERIALCONSSLOT
    251        1.1       uch 	slot = SERIALCONSSLOT;
    252        1.1       uch #else
    253        1.1       uch 	slot = TX39_UARTA;
    254        1.1       uch #endif
    255        1.1       uch 	if (bootinfo->bi_cnuse & BI_CNUSE_SERIAL) {
    256       1.23       uch 		if(txcom_cnattach(slot, CONSPEED,
    257       1.23       uch 		    (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8)) {
    258        1.1       uch 			panic("tx_cons_init: can't attach serial console.");
    259        1.1       uch 		}
    260        1.5       uch 	} else {
    261        1.6       uch #if NM38813C > 0
    262        1.6       uch 		if(CONSPLATIDMATCH(VICTOR_INTERLINK) &&
    263       1.23       uch 		    m38813c_cnattach(TX39_SYSADDR_CARD1)) {
    264       1.10       uch 			goto panic;
    265        1.6       uch 		}
    266        1.6       uch #endif
    267        1.6       uch #if NTC5165BUF > 0
    268       1.10       uch 		if(CONSPLATIDMATCH(COMPAQ_C) &&
    269       1.23       uch 		    tc5165buf_cnattach(TX39_SYSADDR_CS3)) {
    270       1.10       uch 			goto panic;
    271       1.10       uch 		}
    272       1.10       uch 
    273        1.6       uch 		if(CONSPLATIDMATCH(SHARP_TELIOS) &&
    274       1.23       uch 		    tc5165buf_cnattach(TX39_SYSADDR_CS1)) {
    275       1.10       uch 			goto panic;
    276       1.10       uch 		}
    277       1.10       uch 
    278       1.10       uch 		if(CONSPLATIDMATCH(SHARP_MOBILON) &&
    279       1.23       uch 		    tc5165buf_cnattach(TX39_SYSADDR_MCS0)) {
    280       1.10       uch 			goto panic;
    281        1.5       uch 		}
    282        1.5       uch #endif
    283        1.1       uch 	}
    284       1.10       uch 
    285       1.10       uch 	return;
    286       1.10       uch  panic:
    287       1.10       uch 	panic("tx_cons_init: can't init console");
    288       1.10       uch 	/* NOTREACHED */
    289        1.1       uch }
    290        1.1       uch 
    291        1.1       uch void
    292       1.26       uch tx_conf_register_intr(tx_chipset_tag_t t, void *intrt)
    293        1.1       uch {
    294       1.26       uch 
    295       1.20       uch 	KASSERT(t == &tx_chipset);
    296        1.1       uch 	tx_chipset.tc_intrt = intrt;
    297        1.1       uch }
    298        1.1       uch 
    299        1.9       uch void
    300       1.26       uch tx_conf_register_power(tx_chipset_tag_t t, void *powert)
    301        1.9       uch {
    302       1.26       uch 
    303       1.20       uch 	KASSERT(t == &tx_chipset);
    304        1.9       uch 	tx_chipset.tc_powert = powert;
    305        1.9       uch }
    306        1.9       uch 
    307        1.9       uch void
    308       1.26       uch tx_conf_register_clock(tx_chipset_tag_t t, void *clockt)
    309        1.9       uch {
    310       1.26       uch 
    311       1.20       uch 	KASSERT(t == &tx_chipset);
    312        1.9       uch 	tx_chipset.tc_clockt = clockt;
    313       1.11       uch }
    314       1.11       uch 
    315       1.11       uch void
    316       1.26       uch tx_conf_register_sound(tx_chipset_tag_t t, void *soundt)
    317       1.11       uch {
    318       1.26       uch 
    319       1.20       uch 	KASSERT(t == &tx_chipset);
    320       1.11       uch 	tx_chipset.tc_soundt = soundt;
    321       1.18       uch }
    322       1.18       uch 
    323       1.18       uch void
    324       1.26       uch tx_conf_register_video(tx_chipset_tag_t t, void *videot)
    325       1.18       uch {
    326       1.26       uch 
    327       1.20       uch 	KASSERT(t == &tx_chipset);
    328       1.18       uch 	tx_chipset.tc_videot = videot;
    329        1.1       uch }
    330