xref: /openbsd/sys/arch/sparc64/dev/fhc_central.c (revision 771fbea0)
1 /*	$OpenBSD: fhc_central.c,v 1.6 2017/09/08 05:36:52 deraadt 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 struct cfattach fhc_central_ca = {
48 	sizeof(struct fhc_softc), fhc_central_match, fhc_central_attach
49 };
50 
51 int
52 fhc_central_match(parent, match, aux)
53 	struct device *parent;
54 	void *match, *aux;
55 {
56 	struct central_attach_args *ca = aux;
57 
58 	if (strcmp(ca->ca_name, "fhc") == 0)
59 		return (1);
60 	return (0);
61 }
62 
63 void
64 fhc_central_attach(parent, self, aux)
65 	struct device *parent, *self;
66 	void *aux;
67 {
68 	struct fhc_softc *sc = (struct fhc_softc *)self;
69 	struct central_attach_args *ca = aux;
70 	u_int32_t board;
71 
72 	sc->sc_node = ca->ca_node;
73 	sc->sc_bt = ca->ca_bustag;
74 	sc->sc_is_central = 1;
75 
76 	if (central_bus_map(sc->sc_bt, ca->ca_reg[0].cbr_slot,
77 	    ca->ca_reg[0].cbr_offset, ca->ca_reg[0].cbr_size, 0,
78 	    &sc->sc_preg)) {
79 		printf(": failed to map preg\n");
80 		return;
81 	}
82 
83 	if (central_bus_map(sc->sc_bt, ca->ca_reg[1].cbr_slot,
84 	    ca->ca_reg[1].cbr_offset, ca->ca_reg[1].cbr_size, 0,
85 	    &sc->sc_ireg)) {
86 		printf(": failed to map ireg\n");
87 		return;
88 	}
89 
90 	if (central_bus_map(sc->sc_bt, ca->ca_reg[2].cbr_slot,
91 	    ca->ca_reg[2].cbr_offset, ca->ca_reg[2].cbr_size,
92 	    BUS_SPACE_MAP_LINEAR, &sc->sc_freg)) {
93 		printf(": failed to map freg\n");
94 		return;
95 	}
96 
97 	if (central_bus_map(sc->sc_bt, ca->ca_reg[3].cbr_slot,
98 	    ca->ca_reg[3].cbr_offset, ca->ca_reg[3].cbr_size,
99 	    BUS_SPACE_MAP_LINEAR, &sc->sc_sreg)) {
100 		printf(": failed to map sreg\n");
101 		return;
102 	}
103 
104 	if (central_bus_map(sc->sc_bt, ca->ca_reg[4].cbr_slot,
105 	    ca->ca_reg[4].cbr_offset, ca->ca_reg[4].cbr_size,
106 	    BUS_SPACE_MAP_LINEAR, &sc->sc_ureg)) {
107 		printf(": failed to map ureg\n");
108 		return;
109 	}
110 
111 	if (central_bus_map(sc->sc_bt, ca->ca_reg[5].cbr_slot,
112 	    ca->ca_reg[5].cbr_offset, ca->ca_reg[5].cbr_size,
113 	    BUS_SPACE_MAP_LINEAR, &sc->sc_treg)) {
114 		printf(": failed to map treg\n");
115 		return;
116 	}
117 
118 	board = bus_space_read_4(sc->sc_bt, sc->sc_preg, FHC_P_BSR);
119 	sc->sc_board = ((board >> 16) & 0x1) | ((board >> 12) & 0xe);
120 
121 	fhc_attach(sc);
122 	return;
123 }
124