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