xref: /openbsd-src/sys/arch/sparc64/dev/fhc_central.c (revision 47c47feae40d23b370daf5f162f0e605e186b16a)
1*47c47feaSjsg /*	$OpenBSD: fhc_central.c,v 1.8 2022/10/16 01:22:39 jsg Exp $	*/
2f63ee831Sjason 
3f63ee831Sjason /*
4f63ee831Sjason  * Copyright (c) 2004 Jason L. Wright (jason@thought.net).
5f63ee831Sjason  * All rights reserved.
6f63ee831Sjason  *
7f63ee831Sjason  * Redistribution and use in source and binary forms, with or without
8f63ee831Sjason  * modification, are permitted provided that the following conditions
9f63ee831Sjason  * are met:
10f63ee831Sjason  * 1. Redistributions of source code must retain the above copyright
11f63ee831Sjason  *    notice, this list of conditions and the following disclaimer.
12f63ee831Sjason  * 2. Redistributions in binary form must reproduce the above copyright
13f63ee831Sjason  *    notice, this list of conditions and the following disclaimer in the
14f63ee831Sjason  *    documentation and/or other materials provided with the distribution.
15f63ee831Sjason  *
16f63ee831Sjason  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17f63ee831Sjason  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18f63ee831Sjason  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19f63ee831Sjason  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
20f63ee831Sjason  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21f63ee831Sjason  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22f63ee831Sjason  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23f63ee831Sjason  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24f63ee831Sjason  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
25f63ee831Sjason  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26f63ee831Sjason  * POSSIBILITY OF SUCH DAMAGE.
27f63ee831Sjason  */
28f63ee831Sjason 
29f63ee831Sjason #include <sys/param.h>
30f63ee831Sjason #include <sys/systm.h>
31f63ee831Sjason #include <sys/kernel.h>
32f63ee831Sjason #include <sys/device.h>
33f63ee831Sjason #include <sys/conf.h>
34f63ee831Sjason #include <sys/timeout.h>
35f63ee831Sjason 
36f63ee831Sjason #include <machine/bus.h>
37f63ee831Sjason #include <machine/autoconf.h>
38f63ee831Sjason #include <machine/openfirm.h>
39f63ee831Sjason 
40f63ee831Sjason #include <sparc64/dev/centralvar.h>
41488cebfbSjason #include <sparc64/dev/fhcreg.h>
42f63ee831Sjason #include <sparc64/dev/fhcvar.h>
43f63ee831Sjason 
44f63ee831Sjason int	fhc_central_match(struct device *, void *, void *);
45f63ee831Sjason void	fhc_central_attach(struct device *, struct device *, void *);
46f63ee831Sjason 
47eb7eaf8dSmpi const struct cfattach fhc_central_ca = {
48f63ee831Sjason 	sizeof(struct fhc_softc), fhc_central_match, fhc_central_attach
49f63ee831Sjason };
50f63ee831Sjason 
51f63ee831Sjason int
fhc_central_match(struct device * parent,void * match,void * aux)52*47c47feaSjsg fhc_central_match(struct device *parent, void *match, void *aux)
53f63ee831Sjason {
54f63ee831Sjason 	struct central_attach_args *ca = aux;
55f63ee831Sjason 
56f63ee831Sjason 	if (strcmp(ca->ca_name, "fhc") == 0)
57f63ee831Sjason 		return (1);
58f63ee831Sjason 	return (0);
59f63ee831Sjason }
60f63ee831Sjason 
61f63ee831Sjason void
fhc_central_attach(struct device * parent,struct device * self,void * aux)62*47c47feaSjsg fhc_central_attach(struct device *parent, struct device *self, void *aux)
63f63ee831Sjason {
64f63ee831Sjason 	struct fhc_softc *sc = (struct fhc_softc *)self;
65f63ee831Sjason 	struct central_attach_args *ca = aux;
66d435f11cSjason 	u_int32_t board;
67f63ee831Sjason 
68f63ee831Sjason 	sc->sc_node = ca->ca_node;
69f63ee831Sjason 	sc->sc_bt = ca->ca_bustag;
70c7a321c7Sjason 	sc->sc_is_central = 1;
71f63ee831Sjason 
72f63ee831Sjason 	if (central_bus_map(sc->sc_bt, ca->ca_reg[0].cbr_slot,
73f63ee831Sjason 	    ca->ca_reg[0].cbr_offset, ca->ca_reg[0].cbr_size, 0,
74f63ee831Sjason 	    &sc->sc_preg)) {
75f63ee831Sjason 		printf(": failed to map preg\n");
76f63ee831Sjason 		return;
77f63ee831Sjason 	}
78f63ee831Sjason 
79f63ee831Sjason 	if (central_bus_map(sc->sc_bt, ca->ca_reg[1].cbr_slot,
80f63ee831Sjason 	    ca->ca_reg[1].cbr_offset, ca->ca_reg[1].cbr_size, 0,
81f63ee831Sjason 	    &sc->sc_ireg)) {
82f63ee831Sjason 		printf(": failed to map ireg\n");
83f63ee831Sjason 		return;
84f63ee831Sjason 	}
85f63ee831Sjason 
86f63ee831Sjason 	if (central_bus_map(sc->sc_bt, ca->ca_reg[2].cbr_slot,
87488cebfbSjason 	    ca->ca_reg[2].cbr_offset, ca->ca_reg[2].cbr_size,
88488cebfbSjason 	    BUS_SPACE_MAP_LINEAR, &sc->sc_freg)) {
89f63ee831Sjason 		printf(": failed to map freg\n");
90f63ee831Sjason 		return;
91f63ee831Sjason 	}
92f63ee831Sjason 
93f63ee831Sjason 	if (central_bus_map(sc->sc_bt, ca->ca_reg[3].cbr_slot,
94488cebfbSjason 	    ca->ca_reg[3].cbr_offset, ca->ca_reg[3].cbr_size,
95488cebfbSjason 	    BUS_SPACE_MAP_LINEAR, &sc->sc_sreg)) {
96f63ee831Sjason 		printf(": failed to map sreg\n");
97f63ee831Sjason 		return;
98f63ee831Sjason 	}
99f63ee831Sjason 
100f63ee831Sjason 	if (central_bus_map(sc->sc_bt, ca->ca_reg[4].cbr_slot,
101488cebfbSjason 	    ca->ca_reg[4].cbr_offset, ca->ca_reg[4].cbr_size,
102488cebfbSjason 	    BUS_SPACE_MAP_LINEAR, &sc->sc_ureg)) {
103f63ee831Sjason 		printf(": failed to map ureg\n");
104f63ee831Sjason 		return;
105f63ee831Sjason 	}
106f63ee831Sjason 
107f63ee831Sjason 	if (central_bus_map(sc->sc_bt, ca->ca_reg[5].cbr_slot,
108488cebfbSjason 	    ca->ca_reg[5].cbr_offset, ca->ca_reg[5].cbr_size,
109488cebfbSjason 	    BUS_SPACE_MAP_LINEAR, &sc->sc_treg)) {
110f63ee831Sjason 		printf(": failed to map treg\n");
111f63ee831Sjason 		return;
112f63ee831Sjason 	}
113f63ee831Sjason 
114d435f11cSjason 	board = bus_space_read_4(sc->sc_bt, sc->sc_preg, FHC_P_BSR);
115d435f11cSjason 	sc->sc_board = ((board >> 16) & 0x1) | ((board >> 12) & 0xe);
116d435f11cSjason 
117f63ee831Sjason 	fhc_attach(sc);
118f63ee831Sjason 	return;
119f63ee831Sjason }
120