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