1*1dc652efSthorpej /* $NetBSD: sx.c,v 1.8 2023/12/20 05:33:18 thorpej Exp $ */
23b60920aSmacallan
33b60920aSmacallan /*-
43b60920aSmacallan * Copyright (c) 2013 The NetBSD Foundation, Inc.
53b60920aSmacallan * All rights reserved.
63b60920aSmacallan *
73b60920aSmacallan * This code is derived from software contributed to The NetBSD Foundation
83b60920aSmacallan * by Michael Lorenz.
93b60920aSmacallan *
103b60920aSmacallan * Redistribution and use in source and binary forms, with or without
113b60920aSmacallan * modification, are permitted provided that the following conditions
123b60920aSmacallan * are met:
133b60920aSmacallan * 1. Redistributions of source code must retain the above copyright
143b60920aSmacallan * notice, this list of conditions and the following disclaimer.
153b60920aSmacallan * 2. Redistributions in binary form must reproduce the above copyright
163b60920aSmacallan * notice, this list of conditions and the following disclaimer in the
173b60920aSmacallan * documentation and/or other materials provided with the distribution.
183b60920aSmacallan *
193b60920aSmacallan * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
203b60920aSmacallan * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
213b60920aSmacallan * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
223b60920aSmacallan * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
233b60920aSmacallan * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
243b60920aSmacallan * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
253b60920aSmacallan * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
263b60920aSmacallan * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
273b60920aSmacallan * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
283b60920aSmacallan * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
293b60920aSmacallan * POSSIBILITY OF SUCH DAMAGE.
303b60920aSmacallan */
313b60920aSmacallan
323b60920aSmacallan #include <sys/cdefs.h>
33*1dc652efSthorpej __KERNEL_RCSID(0, "$NetBSD: sx.c,v 1.8 2023/12/20 05:33:18 thorpej Exp $");
343b60920aSmacallan
353b60920aSmacallan #include "locators.h"
363b60920aSmacallan
373b60920aSmacallan #include <sys/param.h>
383b60920aSmacallan #include <sys/systm.h>
393b60920aSmacallan #include <sys/device.h>
403b60920aSmacallan
413b60920aSmacallan #include <uvm/uvm_extern.h>
423b60920aSmacallan
433b60920aSmacallan #include <sys/bus.h>
443b60920aSmacallan #include <sparc/dev/sbusvar.h>
453b60920aSmacallan #include <machine/autoconf.h>
463b60920aSmacallan #include <machine/cpu.h>
473b60920aSmacallan #include <machine/ctlreg.h>
483b60920aSmacallan #include <sparc/sparc/asm.h>
493b60920aSmacallan #include <sparc/dev/sxvar.h>
503b60920aSmacallan #include <sparc/dev/sxreg.h>
5104a1595bSmacallan #include "opt_sx.h"
523b60920aSmacallan
533b60920aSmacallan /* autoconfiguration driver */
543b60920aSmacallan static int sx_match(device_t, struct cfdata *, void *);
553b60920aSmacallan static void sx_attach(device_t, device_t, void *);
563b60920aSmacallan
573b60920aSmacallan CFATTACH_DECL_NEW(sx, sizeof(struct sx_softc),
583b60920aSmacallan sx_match, sx_attach, NULL, NULL);
593b60920aSmacallan
6004a1595bSmacallan static struct sx_softc *sx0 = NULL;
6104a1595bSmacallan
623b60920aSmacallan static int
sx_match(device_t parent,struct cfdata * cf,void * aux)633b60920aSmacallan sx_match(device_t parent, struct cfdata *cf, void *aux)
643b60920aSmacallan {
653b60920aSmacallan struct mainbus_attach_args *ma = aux;
663b60920aSmacallan
673b60920aSmacallan return (strcmp("SUNW,sx", ma->ma_name) == 0);
683b60920aSmacallan }
693b60920aSmacallan
703b60920aSmacallan static void
sx_attach(device_t parent,device_t self,void * aux)713b60920aSmacallan sx_attach(device_t parent, device_t self, void *aux)
723b60920aSmacallan {
733b60920aSmacallan struct sx_softc *sc = device_private(self);
743b60920aSmacallan struct mainbus_attach_args *ma = aux;
75a825263fSmacallan uint32_t id;
763b60920aSmacallan int i;
773b60920aSmacallan #ifdef SX_DEBUG
783b60920aSmacallan int j;
793b60920aSmacallan #endif
803b60920aSmacallan
813b60920aSmacallan printf("\n");
823b60920aSmacallan
833b60920aSmacallan sc->sc_dev = self;
843b60920aSmacallan sc->sc_tag = ma->ma_bustag;
853b60920aSmacallan sc->sc_uregs = ma->ma_paddr + 0x1000;
86a570f712Smacallan sc->sc_cnt = 0;
873b60920aSmacallan
883b60920aSmacallan if (bus_space_map(sc->sc_tag, ma->ma_paddr, 0x1000, 0, &sc->sc_regh)) {
893b60920aSmacallan aprint_error_dev(self, "failed to map registers\n");
903b60920aSmacallan return;
913b60920aSmacallan }
923b60920aSmacallan
93a825263fSmacallan id = sx_read(sc, SX_ID);
94a825263fSmacallan aprint_normal_dev(self, "architecture rev. %d chip rev. %d\n",
95a825263fSmacallan (id & SX_ARCHITECTURE_MASK),
9604a1595bSmacallan (id & SX_CHIP_REVISION) >> 3);
97a825263fSmacallan
983b60920aSmacallan /* stop the processor */
993b60920aSmacallan sx_write(sc, SX_CONTROL_STATUS, 0);
1003b60920aSmacallan /* initialize control registers, clear errors etc. */
1013b60920aSmacallan sx_write(sc, SX_R0_INIT, 0);
1023b60920aSmacallan sx_write(sc, SX_ERROR, 0);
103207defd0Sandvar /* default, to be overridden once cgfourteen takes over */
1043b60920aSmacallan sx_write(sc, SX_PAGE_BOUND_LOWER, 0xfc000000);
1053b60920aSmacallan /* cg14 takes up the whole 64MB chunk */
1063b60920aSmacallan sx_write(sc, SX_PAGE_BOUND_UPPER, 0xffffffff);
1079f195db1Smacallan sx_write(sc, SX_DIAGNOSTICS, SX_DIAG_INIT);
1083b60920aSmacallan sx_write(sc, SX_PLANEMASK, 0xffffffff);
1093b60920aSmacallan
1103b60920aSmacallan /*
1113b60920aSmacallan * initialize all other registers
1123b60920aSmacallan * use the direct port since the processor is stopped
1133b60920aSmacallan */
1143b60920aSmacallan for (i = 4; i < 0x200; i += 4)
1153b60920aSmacallan sx_write(sc, SX_DIRECT_R0 + i, 0);
1163b60920aSmacallan
1173b60920aSmacallan /* ... and start the processor again */
1183b60920aSmacallan sx_write(sc, SX_CONTROL_STATUS, SX_PB | SX_GO);
1193b60920aSmacallan
12004a1595bSmacallan sx0 = sc;
12104a1595bSmacallan
1223b60920aSmacallan #ifdef SX_DEBUG
123d211f15bSmacallan sta(0xfc000000, ASI_SX, SX_LD(8, 31, 0));
1243b60920aSmacallan for (i = 1; i < 60; i++)
125d211f15bSmacallan sta(0xfc000000 + (i * 1280), ASI_SX, SX_ST(8, 31, 0));
1263b60920aSmacallan for (i = 900; i < 1000; i++)
127d211f15bSmacallan sta(0xfc000000 + (i * 1280) + 600, ASI_SX, SX_ST(0, 31, 0));
1283b60920aSmacallan
1293b60920aSmacallan for (i = 0; i < 0x30; i+= 16) {
1303b60920aSmacallan printf("%08x:", i);
1313b60920aSmacallan for (j = 0; j < 16; j += 4) {
1323b60920aSmacallan if ((i + j) > 0x28) continue;
1333b60920aSmacallan printf(" %08x",
1343b60920aSmacallan bus_space_read_4(sc->sc_tag, sc->sc_regh, i + j));
1353b60920aSmacallan }
1363b60920aSmacallan printf("\n");
1373b60920aSmacallan }
1383b60920aSmacallan printf("registers:\n");
1393b60920aSmacallan for (i = 0x300; i < 0x500; i+= 16) {
1403b60920aSmacallan printf("%08x:", i);
1413b60920aSmacallan for (j = 0; j < 16; j += 4) {
1423b60920aSmacallan printf(" %08x",
1433b60920aSmacallan bus_space_read_4(sc->sc_tag, sc->sc_regh,
1443b60920aSmacallan i + j));
1453b60920aSmacallan }
1463b60920aSmacallan printf("\n");
1473b60920aSmacallan }
1483b60920aSmacallan #endif
1493b60920aSmacallan }
1503b60920aSmacallan
15104a1595bSmacallan void
sx_dump(void)15204a1595bSmacallan sx_dump(void)
15304a1595bSmacallan {
15404a1595bSmacallan if (sx0 == NULL)
15504a1595bSmacallan return;
15604a1595bSmacallan printf("SX STATUS: %08x\n",
15704a1595bSmacallan bus_space_read_4(sx0->sc_tag, sx0->sc_regh, SX_CONTROL_STATUS));
15804a1595bSmacallan printf("SX ERROR : %08x\n",
15904a1595bSmacallan bus_space_read_4(sx0->sc_tag, sx0->sc_regh, SX_ERROR));
16004a1595bSmacallan printf("SX DIAG : %08x\n",
16104a1595bSmacallan bus_space_read_4(sx0->sc_tag, sx0->sc_regh, SX_DIAGNOSTICS));
16204a1595bSmacallan }
163