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