obio.c revision 1.16 1 1.16 thorpej /* $NetBSD: obio.c,v 1.16 2021/04/24 23:36:56 thorpej Exp $ */
2 1.1 matt
3 1.1 matt /*
4 1.1 matt * Copyright (c) 2002 Allegro Networks, Inc., Wasabi Systems, Inc.
5 1.1 matt * All rights reserved.
6 1.1 matt *
7 1.1 matt * Redistribution and use in source and binary forms, with or without
8 1.1 matt * modification, are permitted provided that the following conditions
9 1.1 matt * are met:
10 1.1 matt * 1. Redistributions of source code must retain the above copyright
11 1.1 matt * notice, this list of conditions and the following disclaimer.
12 1.1 matt * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 matt * notice, this list of conditions and the following disclaimer in the
14 1.1 matt * documentation and/or other materials provided with the distribution.
15 1.1 matt * 3. All advertising materials mentioning features or use of this software
16 1.1 matt * must display the following acknowledgement:
17 1.1 matt * This product includes software developed for the NetBSD Project by
18 1.1 matt * Allegro Networks, Inc., and Wasabi Systems, Inc.
19 1.1 matt * 4. The name of Allegro Networks, Inc. may not be used to endorse
20 1.1 matt * or promote products derived from this software without specific prior
21 1.1 matt * written permission.
22 1.1 matt * 5. The name of Wasabi Systems, Inc. may not be used to endorse
23 1.1 matt * or promote products derived from this software without specific prior
24 1.1 matt * written permission.
25 1.1 matt *
26 1.1 matt * THIS SOFTWARE IS PROVIDED BY ALLEGRO NETWORKS, INC. AND
27 1.1 matt * WASABI SYSTEMS, INC. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
28 1.1 matt * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
29 1.1 matt * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
30 1.1 matt * IN NO EVENT SHALL EITHER ALLEGRO NETWORKS, INC. OR WASABI SYSTEMS, INC.
31 1.1 matt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 1.1 matt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 1.1 matt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 1.1 matt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 1.1 matt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 1.1 matt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 1.1 matt * POSSIBILITY OF SUCH DAMAGE.
38 1.1 matt */
39 1.1 matt
40 1.3 lukem #include <sys/cdefs.h>
41 1.16 thorpej __KERNEL_RCSID(0, "$NetBSD: obio.c,v 1.16 2021/04/24 23:36:56 thorpej Exp $");
42 1.1 matt
43 1.1 matt #include "opt_marvell.h"
44 1.1 matt
45 1.1 matt #include <sys/param.h>
46 1.1 matt #include <sys/types.h>
47 1.1 matt #include <sys/extent.h>
48 1.1 matt #include <sys/device.h>
49 1.1 matt #include <sys/kernel.h>
50 1.1 matt
51 1.1 matt #include <dev/pci/pcivar.h>
52 1.1 matt #include <dev/marvell/gtreg.h>
53 1.1 matt #include <dev/marvell/gtvar.h>
54 1.13 kiyohara #include <dev/marvell/gtdevbusvar.h>
55 1.13 kiyohara #include <dev/marvell/marvellvar.h>
56 1.13 kiyohara
57 1.13 kiyohara #include <prop/proplib.h>
58 1.1 matt
59 1.1 matt #ifdef DEBUG
60 1.1 matt #include <sys/systm.h> /* for Debugger() */
61 1.1 matt #endif
62 1.1 matt
63 1.5 drochner #include "locators.h"
64 1.5 drochner
65 1.13 kiyohara
66 1.13 kiyohara static int obio_match(device_t, cfdata_t, void *);
67 1.13 kiyohara static void obio_attach(device_t, device_t, void *);
68 1.13 kiyohara
69 1.1 matt static int obio_cfprint(void *, const char *);
70 1.13 kiyohara static int obio_cfsearch(device_t, cfdata_t, const int *, void *);
71 1.13 kiyohara
72 1.1 matt
73 1.1 matt struct obio_softc {
74 1.13 kiyohara device_t sc_dev;
75 1.13 kiyohara bus_space_tag_t sc_iot;
76 1.1 matt };
77 1.1 matt
78 1.13 kiyohara CFATTACH_DECL_NEW(obio, sizeof(struct obio_softc),
79 1.13 kiyohara obio_match, obio_attach, NULL, NULL);
80 1.13 kiyohara
81 1.13 kiyohara
82 1.13 kiyohara /* ARGSUSED */
83 1.13 kiyohara int
84 1.13 kiyohara obio_match(device_t parent, cfdata_t cf, void *aux)
85 1.13 kiyohara {
86 1.13 kiyohara struct marvell_attach_args *mva = aux;
87 1.13 kiyohara
88 1.13 kiyohara if (strcmp(mva->mva_name, cf->cf_name) != 0)
89 1.13 kiyohara return 0;
90 1.13 kiyohara
91 1.13 kiyohara #define NUM_OBIO 5
92 1.15 kiyohara if (mva->mva_unit == MVA_UNIT_DEFAULT ||
93 1.13 kiyohara mva->mva_unit > NUM_OBIO)
94 1.13 kiyohara return 0;
95 1.1 matt
96 1.13 kiyohara return 1;
97 1.13 kiyohara }
98 1.13 kiyohara
99 1.13 kiyohara /* ARGSUSED */
100 1.13 kiyohara void
101 1.13 kiyohara obio_attach(device_t parent, device_t self, void *aux)
102 1.13 kiyohara {
103 1.13 kiyohara struct obio_softc *sc = device_private(self);
104 1.13 kiyohara struct marvell_attach_args *mva = aux;
105 1.13 kiyohara prop_data_t bst;
106 1.13 kiyohara uint32_t datal, datah;
107 1.13 kiyohara
108 1.13 kiyohara aprint_naive("\n");
109 1.13 kiyohara aprint_normal(": Device Bus\n");
110 1.13 kiyohara
111 1.13 kiyohara sc->sc_dev = self;
112 1.13 kiyohara
113 1.13 kiyohara if (gt_devbus_addr(parent, mva->mva_unit, &datal, &datah)) {
114 1.13 kiyohara aprint_error_dev(self, "unknown unit number %d\n",
115 1.13 kiyohara mva->mva_unit);
116 1.13 kiyohara return;
117 1.13 kiyohara }
118 1.13 kiyohara
119 1.13 kiyohara if (GT_LowAddr_GET(datal) > GT_HighAddr_GET(datah)) {
120 1.13 kiyohara aprint_normal_dev(self, "disabled\n");
121 1.13 kiyohara return;
122 1.13 kiyohara }
123 1.1 matt
124 1.13 kiyohara bst = prop_dictionary_get(device_properties(sc->sc_dev), "bus-tag");
125 1.13 kiyohara if (bst != NULL) {
126 1.13 kiyohara KASSERT(prop_object_type(bst) == PROP_TYPE_DATA);
127 1.13 kiyohara KASSERT(prop_data_size(bst) == sizeof(bus_space_tag_t));
128 1.13 kiyohara memcpy(&sc->sc_iot, prop_data_data_nocopy(bst),
129 1.13 kiyohara sizeof(bus_space_tag_t));
130 1.13 kiyohara } else
131 1.13 kiyohara sc->sc_iot = mva->mva_iot;
132 1.13 kiyohara if (sc->sc_iot == NULL) {
133 1.13 kiyohara aprint_normal_dev(self, "unused\n");
134 1.13 kiyohara return;
135 1.13 kiyohara }
136 1.13 kiyohara
137 1.13 kiyohara aprint_normal_dev(self, "addr %#x-%#x\n",
138 1.13 kiyohara GT_LowAddr_GET(datal), GT_HighAddr_GET(datah));
139 1.13 kiyohara
140 1.16 thorpej config_search(self, NULL,
141 1.16 thorpej CFARG_SEARCH, obio_cfsearch,
142 1.16 thorpej CFARG_EOL);
143 1.13 kiyohara }
144 1.1 matt
145 1.1 matt
146 1.1 matt int
147 1.1 matt obio_cfprint(void *aux, const char *pnp)
148 1.1 matt {
149 1.1 matt struct obio_attach_args *oa = aux;
150 1.1 matt
151 1.13 kiyohara if (pnp)
152 1.1 matt aprint_normal("%s at %s", oa->oa_name, pnp);
153 1.13 kiyohara aprint_normal(" addr %#x size %#x", oa->oa_offset, oa->oa_size);
154 1.5 drochner if (oa->oa_irq != OBIOCF_IRQ_DEFAULT)
155 1.2 matt aprint_normal(" irq %d", oa->oa_irq);
156 1.1 matt
157 1.13 kiyohara return UNCONF;
158 1.1 matt }
159 1.1 matt
160 1.1 matt
161 1.13 kiyohara /* ARGSUSED */
162 1.1 matt int
163 1.13 kiyohara obio_cfsearch(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
164 1.1 matt {
165 1.13 kiyohara struct obio_softc *sc = device_private(parent);
166 1.1 matt struct obio_attach_args oa;
167 1.1 matt
168 1.1 matt oa.oa_name = cf->cf_name;
169 1.13 kiyohara oa.oa_memt = sc->sc_iot;
170 1.5 drochner oa.oa_offset = cf->cf_loc[OBIOCF_OFFSET];
171 1.5 drochner oa.oa_size = cf->cf_loc[OBIOCF_SIZE];
172 1.5 drochner oa.oa_irq = cf->cf_loc[OBIOCF_IRQ];
173 1.1 matt
174 1.16 thorpej if (config_probe(parent, cf, &oa))
175 1.16 thorpej config_attach(parent, cf, &oa, obio_cfprint, CFARG_EOL);
176 1.1 matt
177 1.13 kiyohara return 0;
178 1.1 matt }
179