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