Home | History | Annotate | Line # | Download | only in vr
vrdsu.c revision 1.12
      1 /*	$NetBSD: vrdsu.c,v 1.12 2015/06/09 22:46:36 matt Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1999 Shin Takemura All rights reserved.
      5  * Copyright (c) 1999 PocketBSD Project. All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  * SUCH DAMAGE.
     27  */
     28 
     29 #include <sys/cdefs.h>
     30 __KERNEL_RCSID(0, "$NetBSD: vrdsu.c,v 1.12 2015/06/09 22:46:36 matt Exp $");
     31 
     32 #include <sys/param.h>
     33 #include <sys/bus.h>
     34 #include <sys/device.h>
     35 #include <sys/systm.h>
     36 
     37 #include <uvm/uvm_extern.h>
     38 
     39 #include <mips/cpuregs.h>
     40 
     41 #include <hpcmips/vr/vripif.h>
     42 #include <hpcmips/vr/dsureg.h>
     43 #include <hpcmips/vr/vrdsuvar.h>
     44 
     45 struct vrdsu_softc {
     46 	bus_space_tag_t sc_iot;
     47 	bus_space_handle_t sc_ioh;
     48 };
     49 
     50 static int vrdsumatch(device_t, cfdata_t, void *);
     51 static void vrdsuattach(device_t, device_t, void *);
     52 
     53 static void vrdsu_write(struct vrdsu_softc *, int, unsigned short);
     54 static unsigned short vrdsu_read(struct vrdsu_softc *, int);
     55 
     56 CFATTACH_DECL_NEW(vrdsu, sizeof(struct vrdsu_softc),
     57     vrdsumatch, vrdsuattach, NULL, NULL);
     58 
     59 struct vrdsu_softc *the_dsu_sc = NULL;
     60 
     61 static inline void
     62 vrdsu_write(struct vrdsu_softc *sc, int port, unsigned short val)
     63 {
     64 
     65 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, port, val);
     66 }
     67 
     68 static inline unsigned short
     69 vrdsu_read(struct vrdsu_softc *sc, int port)
     70 {
     71 
     72 	return (bus_space_read_2(sc->sc_iot, sc->sc_ioh, port));
     73 }
     74 
     75 static int
     76 vrdsumatch(device_t parent, cfdata_t cf, void *aux)
     77 {
     78 
     79 	return (1);
     80 }
     81 
     82 static void
     83 vrdsuattach(device_t parent, device_t self, void *aux)
     84 {
     85 	struct vrdsu_softc *sc = device_private(self);
     86 	struct vrip_attach_args *va = aux;
     87 
     88 	sc->sc_iot = va->va_iot;
     89 	if (bus_space_map(va->va_iot, va->va_addr, va->va_size,
     90 	    0, &sc->sc_ioh)) {
     91 		printf(": can't map bus space\n");
     92 		return;
     93 	}
     94 	printf("\n");
     95 	the_dsu_sc = sc;
     96 }
     97 
     98 void
     99 vrdsu_reset(void)
    100 {
    101 
    102 	if (the_dsu_sc) {
    103 		splhigh();
    104 		vrdsu_write(the_dsu_sc, DSUSET_REG_W, 1); /* 1 sec */
    105 		vrdsu_write(the_dsu_sc, DSUCNT_REG_W, DSUCNT_DSWEN);
    106 		/*
    107 		 * wipe out all physical memory for clean WinCE boot.
    108 		 */
    109 		memset((void *)MIPS_PHYS_TO_KSEG1(0), 0, ptoa(physmem) - 0);
    110 		while (1);
    111 	} else {
    112 		printf("%s(%d): There is no DSU.", __FILE__, __LINE__);
    113 	}
    114 }
    115