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