Home | History | Annotate | Line # | Download | only in dev
sx.c revision 1.7
      1 /*	$NetBSD: sx.c,v 1.7 2023/06/13 10:09:31 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.7 2023/06/13 10:09:31 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 #include "opt_sx.h"
     53 
     54 /* autoconfiguration driver */
     55 static	int sx_match(device_t, struct cfdata *, void *);
     56 static	void sx_attach(device_t, device_t, void *);
     57 
     58 CFATTACH_DECL_NEW(sx, sizeof(struct sx_softc),
     59     sx_match, sx_attach, NULL, NULL);
     60 
     61 static struct sx_softc *sx0 = NULL;
     62 
     63 static int
     64 sx_match(device_t parent, struct cfdata *cf, void *aux)
     65 {
     66 	struct mainbus_attach_args *ma = aux;
     67 
     68 	return (strcmp("SUNW,sx", ma->ma_name) == 0);
     69 }
     70 
     71 static void
     72 sx_attach(device_t parent, device_t self, void *aux)
     73 {
     74 	struct sx_softc *sc = device_private(self);
     75 	struct mainbus_attach_args *ma = aux;
     76 	uint32_t id;
     77     	int i;
     78 #ifdef SX_DEBUG
     79 	int j;
     80 #endif
     81 
     82 	printf("\n");
     83 
     84 	sc->sc_dev = self;
     85 	sc->sc_tag = ma->ma_bustag;
     86 	sc->sc_uregs = ma->ma_paddr + 0x1000;
     87 	sc->sc_cnt = 0;
     88 
     89 	if (bus_space_map(sc->sc_tag, ma->ma_paddr, 0x1000, 0, &sc->sc_regh)) {
     90 		aprint_error_dev(self, "failed to map registers\n");
     91 		return;
     92 	}
     93 
     94 	id = sx_read(sc, SX_ID);
     95 	aprint_normal_dev(self, "architecture rev. %d chip rev. %d\n",
     96 	    (id & SX_ARCHITECTURE_MASK),
     97 	    (id & SX_CHIP_REVISION) >> 3);
     98 
     99 	/* stop the processor */
    100 	sx_write(sc, SX_CONTROL_STATUS, 0);
    101 	/* initialize control registers, clear errors etc. */
    102 	sx_write(sc, SX_R0_INIT, 0);
    103 	sx_write(sc, SX_ERROR, 0);
    104 	/* default, to be overridden once cgfourteen takes over */
    105 	sx_write(sc, SX_PAGE_BOUND_LOWER, 0xfc000000);
    106 	/* cg14 takes up the whole 64MB chunk */
    107 	sx_write(sc, SX_PAGE_BOUND_UPPER, 0xffffffff);
    108 	sx_write(sc, SX_DIAGNOSTICS, SX_DIAG_INIT);
    109 	sx_write(sc, SX_PLANEMASK, 0xffffffff);
    110 
    111 	/*
    112 	 * initialize all other registers
    113 	 * use the direct port since the processor is stopped
    114 	 */
    115 	for (i = 4; i < 0x200; i += 4)
    116 		sx_write(sc, SX_DIRECT_R0 + i, 0);
    117 
    118 	/* ... and start the processor again */
    119 	sx_write(sc, SX_CONTROL_STATUS, SX_PB | SX_GO);
    120 
    121 	sx0 = sc;
    122 
    123 #ifdef SX_DEBUG
    124 	sta(0xfc000000, ASI_SX, SX_LD(8, 31, 0));
    125 	for (i = 1; i < 60; i++)
    126 		sta(0xfc000000 + (i * 1280), ASI_SX, SX_ST(8, 31, 0));
    127 	for (i = 900; i < 1000; i++)
    128 		sta(0xfc000000 + (i * 1280) + 600, ASI_SX, SX_ST(0, 31, 0));
    129 
    130     	for (i = 0; i < 0x30; i+= 16) {
    131     		printf("%08x:", i);
    132     		for (j = 0; j < 16; j += 4) {
    133 			if ((i + j) > 0x28) continue;
    134     			printf(" %08x",
    135     			    bus_space_read_4(sc->sc_tag, sc->sc_regh, i + j));
    136 		}
    137 		printf("\n");
    138 	}
    139 	printf("registers:\n");
    140     	for (i = 0x300; i < 0x500; i+= 16) {
    141     		printf("%08x:", i);
    142     		for (j = 0; j < 16; j += 4) {
    143     			printf(" %08x",
    144     			    bus_space_read_4(sc->sc_tag, sc->sc_regh,
    145     			        i + j));
    146 		}
    147 		printf("\n");
    148 	}
    149 #endif
    150 }
    151 
    152 void
    153 sx_dump(void)
    154 {
    155 	if (sx0 == NULL)
    156 		return;
    157 	printf("SX STATUS: %08x\n",
    158 	    bus_space_read_4(sx0->sc_tag, sx0->sc_regh, SX_CONTROL_STATUS));
    159 	printf("SX ERROR : %08x\n",
    160 	    bus_space_read_4(sx0->sc_tag, sx0->sc_regh, SX_ERROR));
    161 	printf("SX DIAG  : %08x\n",
    162 	    bus_space_read_4(sx0->sc_tag, sx0->sc_regh, SX_DIAGNOSTICS));
    163 }
    164