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