Home | History | Annotate | Line # | Download | only in vr
vr.c revision 1.1
      1  1.1  takemura /*	$NetBSD: vr.c,v 1.1 1999/09/16 12:23:32 takemura Exp $	*/
      2  1.1  takemura 
      3  1.1  takemura /*-
      4  1.1  takemura  * Copyright (c) 1999
      5  1.1  takemura  *         Shin Takemura and PocketBSD Project. All rights reserved.
      6  1.1  takemura  *
      7  1.1  takemura  * Redistribution and use in source and binary forms, with or without
      8  1.1  takemura  * modification, are permitted provided that the following conditions
      9  1.1  takemura  * are met:
     10  1.1  takemura  * 1. Redistributions of source code must retain the above copyright
     11  1.1  takemura  *    notice, this list of conditions and the following disclaimer.
     12  1.1  takemura  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  takemura  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  takemura  *    documentation and/or other materials provided with the distribution.
     15  1.1  takemura  * 3. All advertising materials mentioning features or use of this software
     16  1.1  takemura  *    must display the following acknowledgement:
     17  1.1  takemura  *	This product includes software developed by the PocketBSD project
     18  1.1  takemura  *	and its contributors.
     19  1.1  takemura  * 4. Neither the name of the project nor the names of its contributors
     20  1.1  takemura  *    may be used to endorse or promote products derived from this software
     21  1.1  takemura  *    without specific prior written permission.
     22  1.1  takemura  *
     23  1.1  takemura  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24  1.1  takemura  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  1.1  takemura  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  1.1  takemura  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27  1.1  takemura  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  1.1  takemura  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  1.1  takemura  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  1.1  takemura  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  1.1  takemura  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  1.1  takemura  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  1.1  takemura  * SUCH DAMAGE.
     34  1.1  takemura  *
     35  1.1  takemura  */
     36  1.1  takemura #include <sys/param.h>
     37  1.1  takemura #include <sys/types.h>
     38  1.1  takemura #include <sys/systm.h>
     39  1.1  takemura #include <sys/device.h>
     40  1.1  takemura 
     41  1.1  takemura #include <machine/cpu.h>
     42  1.1  takemura #include <machine/intr.h>
     43  1.1  takemura #include <machine/reg.h>
     44  1.1  takemura #include <machine/psl.h>
     45  1.1  takemura #include <machine/locore.h>
     46  1.1  takemura #include <machine/sysconf.h>
     47  1.1  takemura #include <machine/bus.h>
     48  1.1  takemura #include <machine/autoconf.h>
     49  1.1  takemura 
     50  1.1  takemura #include <mips/mips_param.h>		/* hokey spl()s */
     51  1.1  takemura #include <mips/mips/mips_mcclock.h>	/* mcclock CPUspeed estimation */
     52  1.1  takemura 
     53  1.1  takemura #include <hpcmips/vr/vr.h>
     54  1.1  takemura #include <hpcmips/vr/rtcreg.h>
     55  1.1  takemura #include <hpcmips/hpcmips/machdep.h>	/* XXXjrs replace with vectors */
     56  1.1  takemura #include <machine/bootinfo.h>
     57  1.1  takemura 
     58  1.1  takemura #include "com.h"
     59  1.1  takemura #if NCOM > 0
     60  1.1  takemura #include <sys/termios.h>
     61  1.1  takemura #include <sys/ttydefaults.h>
     62  1.1  takemura #include <dev/ic/comreg.h>
     63  1.1  takemura #include <dev/ic/comvar.h>
     64  1.1  takemura #include <hpcmips/vr/siureg.h>
     65  1.1  takemura #include <hpcmips/vr/com_vripvar.h>
     66  1.1  takemura #ifndef CONSPEED
     67  1.1  takemura #define CONSPEED TTYDEF_SPEED
     68  1.1  takemura #endif
     69  1.1  takemura #endif
     70  1.1  takemura 
     71  1.1  takemura void	vr_init __P((void));
     72  1.1  takemura void	vr_os_init __P((void));
     73  1.1  takemura void	vr_bus_reset __P((void));
     74  1.1  takemura int	vr_intr __P((u_int32_t mask, u_int32_t pc, u_int32_t statusReg, u_int32_t causeReg));
     75  1.1  takemura void	vr_cons_init __P((void));
     76  1.1  takemura void	vr_device_register __P((struct device *, void *));
     77  1.1  takemura 
     78  1.1  takemura char	*vrbcu_vrip_getcpuname __P((void));
     79  1.1  takemura int	vrbcu_vrip_getcpumajor __P((void));
     80  1.1  takemura int	vrbcu_vrip_getcpuminor __P((void));
     81  1.1  takemura 
     82  1.1  takemura extern unsigned nullclkread __P((void));
     83  1.1  takemura extern unsigned (*clkread) __P((void));
     84  1.1  takemura 
     85  1.1  takemura /*
     86  1.1  takemura  * CPU interrupt dispatch table (HwInt[0:3])
     87  1.1  takemura  */
     88  1.1  takemura int null_handler __P((void*, u_int32_t, u_int32_t));
     89  1.1  takemura static int (*intr_handler[4]) __P((void*, u_int32_t, u_int32_t)) =
     90  1.1  takemura {
     91  1.1  takemura 	null_handler,
     92  1.1  takemura 	null_handler,
     93  1.1  takemura 	null_handler,
     94  1.1  takemura 	null_handler
     95  1.1  takemura };
     96  1.1  takemura static void *intr_arg[4];
     97  1.1  takemura 
     98  1.1  takemura void
     99  1.1  takemura vr_init()
    100  1.1  takemura {
    101  1.1  takemura 	/*
    102  1.1  takemura 	 * Platform Information.
    103  1.1  takemura 	 */
    104  1.1  takemura 
    105  1.1  takemura 	/*
    106  1.1  takemura 	 * Platform Specific Function Hooks
    107  1.1  takemura 	 */
    108  1.1  takemura 	platform.os_init = vr_os_init;
    109  1.1  takemura 	platform.bus_reset = vr_bus_reset;
    110  1.1  takemura 	platform.cons_init = vr_cons_init;
    111  1.1  takemura 	platform.device_register = vr_device_register;
    112  1.1  takemura 
    113  1.1  takemura 	sprintf(cpu_model, "NEC %s rev%d.%d",
    114  1.1  takemura 		vrbcu_vrip_getcpuname(),
    115  1.1  takemura 		vrbcu_vrip_getcpumajor(),
    116  1.1  takemura 		vrbcu_vrip_getcpuminor());
    117  1.1  takemura }
    118  1.1  takemura 
    119  1.1  takemura void
    120  1.1  takemura vr_os_init()
    121  1.1  takemura {
    122  1.1  takemura 	/*
    123  1.1  takemura 	 * Set up interrupt handling and I/O addresses.
    124  1.1  takemura 	 */
    125  1.1  takemura 	mips_hardware_intr = vr_intr;
    126  1.1  takemura 
    127  1.1  takemura 	splvec.splbio = MIPS_SPL0;
    128  1.1  takemura 	splvec.splnet = MIPS_SPL0;
    129  1.1  takemura 	splvec.spltty = MIPS_SPL0;
    130  1.1  takemura 	splvec.splimp = MIPS_SPL0;
    131  1.1  takemura 	splvec.splclock = MIPS_SPL_0_1;
    132  1.1  takemura 	splvec.splstatclock = MIPS_SPL_0_1;
    133  1.1  takemura 
    134  1.1  takemura 	/* no high resolution timer circuit; possibly never called */
    135  1.1  takemura 	clkread = nullclkread;
    136  1.1  takemura 
    137  1.1  takemura #ifdef NOT_YET
    138  1.1  takemura 	mcclock_addr = (volatile struct chiptime *)
    139  1.1  takemura 		MIPS_PHYS_TO_KSEG1(Vr_SYS_CLOCK);
    140  1.1  takemura 	mc_cpuspeed(mcclock_addr, MIPS_INT_MASK_1);
    141  1.1  takemura #else
    142  1.1  takemura 	printf("%s(%d): cpuspeed estimation is notimplemented\n",
    143  1.1  takemura 	       __FILE__, __LINE__);
    144  1.1  takemura #endif
    145  1.1  takemura #ifdef HPCMIPS_L1CACHE_DISABLE
    146  1.1  takemura 	cpuspeed = 1;	/* XXX, CPU is very very slow because L1 cache is */
    147  1.1  takemura 	/* disabled. */
    148  1.1  takemura #endif /*  HPCMIPS_L1CAHCE_DISABLE */
    149  1.1  takemura }
    150  1.1  takemura 
    151  1.1  takemura 
    152  1.1  takemura /*
    153  1.1  takemura  * Initalize the memory system and I/O buses.
    154  1.1  takemura  */
    155  1.1  takemura void
    156  1.1  takemura vr_bus_reset()
    157  1.1  takemura {
    158  1.1  takemura 	printf("%s(%d): vr_bus_reset() not implemented.\n",
    159  1.1  takemura 	       __FILE__, __LINE__);
    160  1.1  takemura }
    161  1.1  takemura 
    162  1.1  takemura void
    163  1.1  takemura vr_cons_init()
    164  1.1  takemura {
    165  1.1  takemura #if NCOM > 0
    166  1.1  takemura 	extern bus_space_tag_t system_bus_iot;
    167  1.1  takemura 	extern bus_space_tag_t mb_bus_space_init __P((void));
    168  1.1  takemura #endif
    169  1.1  takemura 
    170  1.1  takemura #if NCOM > 0
    171  1.1  takemura 	if (bootinfo->bi_cnuse & BI_CNUSE_SERIAL) {
    172  1.1  takemura 		/* Serial console */
    173  1.1  takemura 		mb_bus_space_init(); /* At this time, not initialized yet */
    174  1.1  takemura 		if(com_vrip_cnattach(system_bus_iot, 0x0c000000, CONSPEED,
    175  1.1  takemura 				     VRCOM_FREQ,
    176  1.1  takemura 				     (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8)) {
    177  1.1  takemura 			printf("%s(%d): can't init serial console", __FILE__, __LINE__);
    178  1.1  takemura 		} else {
    179  1.1  takemura 			return;
    180  1.1  takemura 		}
    181  1.1  takemura 	}
    182  1.1  takemura #endif
    183  1.1  takemura 
    184  1.1  takemura }
    185  1.1  takemura 
    186  1.1  takemura void
    187  1.1  takemura vr_device_register(dev, aux)
    188  1.1  takemura 	struct device *dev;
    189  1.1  takemura 	void *aux;
    190  1.1  takemura {
    191  1.1  takemura 	printf("%s(%d): vr_bus_reset() not implemented.\n",
    192  1.1  takemura 	       __FILE__, __LINE__);
    193  1.1  takemura 	panic("abort");
    194  1.1  takemura }
    195  1.1  takemura 
    196  1.1  takemura void *
    197  1.1  takemura vr_intr_establish(line, ih_fun, ih_arg)
    198  1.1  takemura 	int line;
    199  1.1  takemura 	int (*ih_fun) __P((void*, u_int32_t, u_int32_t));
    200  1.1  takemura 	void *ih_arg;
    201  1.1  takemura {
    202  1.1  takemura 	if (intr_handler[line] != null_handler) {
    203  1.1  takemura 		panic("vr_intr_establish: can't establish duplicated intr handler.");
    204  1.1  takemura 	}
    205  1.1  takemura 	intr_handler[line] = ih_fun;
    206  1.1  takemura 	intr_arg[line] = ih_arg;
    207  1.1  takemura 
    208  1.1  takemura 	return (void*)line;
    209  1.1  takemura }
    210  1.1  takemura 
    211  1.1  takemura 
    212  1.1  takemura void
    213  1.1  takemura vr_intr_disestablish(ih)
    214  1.1  takemura 	void *ih;
    215  1.1  takemura {
    216  1.1  takemura 	int line = (int)ih;
    217  1.1  takemura 	intr_handler[line] = null_handler;
    218  1.1  takemura 	intr_arg[line] = NULL;
    219  1.1  takemura }
    220  1.1  takemura 
    221  1.1  takemura int
    222  1.1  takemura null_handler(arg, pc, statusReg)
    223  1.1  takemura 	void *arg;
    224  1.1  takemura 	u_int32_t pc;
    225  1.1  takemura 	u_int32_t statusReg;
    226  1.1  takemura {
    227  1.1  takemura 	printf("null_handler\n");
    228  1.1  takemura 	return 0;
    229  1.1  takemura }
    230  1.1  takemura 
    231  1.1  takemura /*
    232  1.1  takemura  * Handle interrupts.
    233  1.1  takemura  */
    234  1.1  takemura int
    235  1.1  takemura vr_intr(mask, pc, status, cause)
    236  1.1  takemura 	u_int32_t mask;
    237  1.1  takemura 	u_int32_t pc;
    238  1.1  takemura 	u_int32_t status;
    239  1.1  takemura 	u_int32_t cause;
    240  1.1  takemura {
    241  1.1  takemura 	int hwintr;
    242  1.1  takemura 
    243  1.1  takemura 	hwintr = (ffs(mask >> 10) -1) & 0x3;
    244  1.1  takemura 	(*intr_handler[hwintr])(intr_arg[hwintr], pc, status);
    245  1.1  takemura 	return (MIPS_SR_INT_IE | (status & ~cause & MIPS_HARD_INT_MASK));
    246  1.1  takemura }
    247