Home | History | Annotate | Line # | Download | only in dev
sx.c revision 1.3
      1 /*	$NetBSD: sx.c,v 1.3 2014/04/15 10:24:54 macallan 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.3 2014/04/15 10:24:54 macallan 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 	uint32_t id;
     74     	int i;
     75 #ifdef SX_DEBUG
     76 	int j;
     77 #endif
     78 
     79 	printf("\n");
     80 
     81 	sc->sc_dev = self;
     82 	sc->sc_tag = ma->ma_bustag;
     83 	sc->sc_uregs = ma->ma_paddr + 0x1000;
     84 
     85 	if (bus_space_map(sc->sc_tag, ma->ma_paddr, 0x1000, 0, &sc->sc_regh)) {
     86 		aprint_error_dev(self, "failed to map registers\n");
     87 		return;
     88 	}
     89 
     90 	id = sx_read(sc, SX_ID);
     91 	aprint_normal_dev(self, "architecture rev. %d chip rev. %d\n",
     92 	    (id & SX_ARCHITECTURE_MASK),
     93 	    (id & SX_CHIP_REVISION) >> 8);
     94 
     95 	/* stop the processor */
     96 	sx_write(sc, SX_CONTROL_STATUS, 0);
     97 	/* initialize control registers, clear errors etc. */
     98 	sx_write(sc, SX_R0_INIT, 0);
     99 	sx_write(sc, SX_ERROR, 0);
    100 	/* default, to be overriden once cgfourteen takes over */
    101 	sx_write(sc, SX_PAGE_BOUND_LOWER, 0xfc000000);
    102 	/* cg14 takes up the whole 64MB chunk */
    103 	sx_write(sc, SX_PAGE_BOUND_UPPER, 0xffffffff);
    104 	sx_write(sc, SX_DIAGNOSTICS, 0);
    105 	sx_write(sc, SX_PLANEMASK, 0xffffffff);
    106 
    107 	/*
    108 	 * initialize all other registers
    109 	 * use the direct port since the processor is stopped
    110 	 */
    111 	for (i = 4; i < 0x200; i += 4)
    112 		sx_write(sc, SX_DIRECT_R0 + i, 0);
    113 
    114 	/* ... and start the processor again */
    115 	sx_write(sc, SX_CONTROL_STATUS, SX_PB | SX_GO);
    116 
    117 #ifdef SX_DEBUG
    118 	sta(0xfc000000, ASI_SX, SX_LD(8, 31, 0));
    119 	for (i = 1; i < 60; i++)
    120 		sta(0xfc000000 + (i * 1280), ASI_SX, SX_ST(8, 31, 0));
    121 	for (i = 900; i < 1000; i++)
    122 		sta(0xfc000000 + (i * 1280) + 600, ASI_SX, SX_ST(0, 31, 0));
    123 
    124     	for (i = 0; i < 0x30; i+= 16) {
    125     		printf("%08x:", i);
    126     		for (j = 0; j < 16; j += 4) {
    127 			if ((i + j) > 0x28) continue;
    128     			printf(" %08x",
    129     			    bus_space_read_4(sc->sc_tag, sc->sc_regh, i + j));
    130 		}
    131 		printf("\n");
    132 	}
    133 	printf("registers:\n");
    134     	for (i = 0x300; i < 0x500; i+= 16) {
    135     		printf("%08x:", i);
    136     		for (j = 0; j < 16; j += 4) {
    137     			printf(" %08x",
    138     			    bus_space_read_4(sc->sc_tag, sc->sc_regh,
    139     			        i + j));
    140 		}
    141 		printf("\n");
    142 	}
    143 #endif
    144 }
    145 
    146