Home | History | Annotate | Line # | Download | only in dev
sx.c revision 1.2.4.2
      1 /*	$NetBSD: sx.c,v 1.2.4.2 2013/02/25 00:28:57 tls Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2013 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Michael Lorenz.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #include <sys/cdefs.h>
     33 __KERNEL_RCSID(0, "$NetBSD: sx.c,v 1.2.4.2 2013/02/25 00:28:57 tls Exp $");
     34 
     35 #include "locators.h"
     36 
     37 #include <sys/param.h>
     38 #include <sys/systm.h>
     39 #include <sys/device.h>
     40 #include <sys/malloc.h>
     41 
     42 #include <uvm/uvm_extern.h>
     43 
     44 #include <sys/bus.h>
     45 #include <sparc/dev/sbusvar.h>
     46 #include <machine/autoconf.h>
     47 #include <machine/cpu.h>
     48 #include <machine/ctlreg.h>
     49 #include <sparc/sparc/asm.h>
     50 #include <sparc/dev/sxvar.h>
     51 #include <sparc/dev/sxreg.h>
     52 
     53 /* autoconfiguration driver */
     54 static	int sx_match(device_t, struct cfdata *, void *);
     55 static	void sx_attach(device_t, device_t, void *);
     56 
     57 CFATTACH_DECL_NEW(sx, sizeof(struct sx_softc),
     58     sx_match, sx_attach, NULL, NULL);
     59 
     60 static int
     61 sx_match(device_t parent, struct cfdata *cf, void *aux)
     62 {
     63 	struct mainbus_attach_args *ma = aux;
     64 
     65 	return (strcmp("SUNW,sx", ma->ma_name) == 0);
     66 }
     67 
     68 static void
     69 sx_attach(device_t parent, device_t self, void *aux)
     70 {
     71 	struct sx_softc *sc = device_private(self);
     72 	struct mainbus_attach_args *ma = aux;
     73     	int i;
     74 #ifdef SX_DEBUG
     75 	int j;
     76 #endif
     77 
     78 	printf("\n");
     79 
     80 	sc->sc_dev = self;
     81 	sc->sc_tag = ma->ma_bustag;
     82 	sc->sc_uregs = ma->ma_paddr + 0x1000;
     83 
     84 	if (bus_space_map(sc->sc_tag, ma->ma_paddr, 0x1000, 0, &sc->sc_regh)) {
     85 		aprint_error_dev(self, "failed to map registers\n");
     86 		return;
     87 	}
     88 
     89 	/* stop the processor */
     90 	sx_write(sc, SX_CONTROL_STATUS, 0);
     91 	/* initialize control registers, clear errors etc. */
     92 	sx_write(sc, SX_R0_INIT, 0);
     93 	sx_write(sc, SX_ERROR, 0);
     94 	/* default, to be overriden once cgfourteen takes over */
     95 	sx_write(sc, SX_PAGE_BOUND_LOWER, 0xfc000000);
     96 	/* cg14 takes up the whole 64MB chunk */
     97 	sx_write(sc, SX_PAGE_BOUND_UPPER, 0xffffffff);
     98 	sx_write(sc, SX_DIAGNOSTICS, 0);
     99 	sx_write(sc, SX_PLANEMASK, 0xffffffff);
    100 
    101 	/*
    102 	 * initialize all other registers
    103 	 * use the direct port since the processor is stopped
    104 	 */
    105 	for (i = 4; i < 0x200; i += 4)
    106 		sx_write(sc, SX_DIRECT_R0 + i, 0);
    107 
    108 	/* ... and start the processor again */
    109 	sx_write(sc, SX_CONTROL_STATUS, SX_PB | SX_GO);
    110 
    111 #ifdef SX_DEBUG
    112 	sta(0xfc000000, ASI_SX, SX_LD(8, 31, 0));
    113 	for (i = 1; i < 60; i++)
    114 		sta(0xfc000000 + (i * 1280), ASI_SX, SX_ST(8, 31, 0));
    115 	for (i = 900; i < 1000; i++)
    116 		sta(0xfc000000 + (i * 1280) + 600, ASI_SX, SX_ST(0, 31, 0));
    117 
    118     	for (i = 0; i < 0x30; i+= 16) {
    119     		printf("%08x:", i);
    120     		for (j = 0; j < 16; j += 4) {
    121 			if ((i + j) > 0x28) continue;
    122     			printf(" %08x",
    123     			    bus_space_read_4(sc->sc_tag, sc->sc_regh, i + j));
    124 		}
    125 		printf("\n");
    126 	}
    127 	printf("registers:\n");
    128     	for (i = 0x300; i < 0x500; i+= 16) {
    129     		printf("%08x:", i);
    130     		for (j = 0; j < 16; j += 4) {
    131     			printf(" %08x",
    132     			    bus_space_read_4(sc->sc_tag, sc->sc_regh,
    133     			        i + j));
    134 		}
    135 		printf("\n");
    136 	}
    137 #endif
    138 }
    139 
    140