obio.c revision 1.12.4.2 1 1.12.4.2 rmind /* $NetBSD: obio.c,v 1.12.4.2 2010/07/03 01:19:36 rmind 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.12.4.2 rmind __KERNEL_RCSID(0, "$NetBSD: obio.c,v 1.12.4.2 2010/07/03 01:19:36 rmind 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.12.4.1 rmind #include <dev/marvell/gtdevbusvar.h>
55 1.12.4.1 rmind #include <dev/marvell/marvellvar.h>
56 1.12.4.1 rmind
57 1.12.4.1 rmind #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.12.4.1 rmind
66 1.12.4.1 rmind static int obio_match(device_t, cfdata_t, void *);
67 1.12.4.1 rmind static void obio_attach(device_t, device_t, void *);
68 1.12.4.1 rmind
69 1.1 matt static int obio_cfprint(void *, const char *);
70 1.12.4.1 rmind static int obio_cfsearch(device_t, cfdata_t, const int *, void *);
71 1.12.4.1 rmind
72 1.1 matt
73 1.1 matt struct obio_softc {
74 1.12.4.1 rmind device_t sc_dev;
75 1.12.4.1 rmind bus_space_tag_t sc_iot;
76 1.1 matt };
77 1.1 matt
78 1.12.4.1 rmind CFATTACH_DECL_NEW(obio, sizeof(struct obio_softc),
79 1.12.4.1 rmind obio_match, obio_attach, NULL, NULL);
80 1.1 matt
81 1.1 matt
82 1.12.4.1 rmind /* ARGSUSED */
83 1.12.4.1 rmind int
84 1.12.4.1 rmind obio_match(device_t parent, cfdata_t cf, void *aux)
85 1.12.4.1 rmind {
86 1.12.4.1 rmind struct marvell_attach_args *mva = aux;
87 1.12.4.1 rmind
88 1.12.4.1 rmind if (strcmp(mva->mva_name, cf->cf_name) != 0)
89 1.12.4.1 rmind return 0;
90 1.12.4.1 rmind
91 1.12.4.1 rmind #define NUM_OBIO 5
92 1.12.4.1 rmind if (mva->mva_unit == GTCF_UNIT_DEFAULT ||
93 1.12.4.1 rmind mva->mva_unit > NUM_OBIO)
94 1.12.4.1 rmind return 0;
95 1.12.4.1 rmind
96 1.12.4.1 rmind return 1;
97 1.12.4.1 rmind }
98 1.12.4.1 rmind
99 1.12.4.1 rmind /* ARGSUSED */
100 1.12.4.1 rmind void
101 1.12.4.1 rmind obio_attach(device_t parent, device_t self, void *aux)
102 1.12.4.1 rmind {
103 1.12.4.1 rmind struct obio_softc *sc = device_private(self);
104 1.12.4.1 rmind struct marvell_attach_args *mva = aux;
105 1.12.4.1 rmind prop_data_t bst;
106 1.12.4.1 rmind uint32_t datal, datah;
107 1.12.4.1 rmind
108 1.12.4.1 rmind aprint_naive("\n");
109 1.12.4.1 rmind aprint_normal(": Device Bus\n");
110 1.12.4.1 rmind
111 1.12.4.1 rmind sc->sc_dev = self;
112 1.12.4.1 rmind
113 1.12.4.1 rmind if (gt_devbus_addr(parent, mva->mva_unit, &datal, &datah)) {
114 1.12.4.1 rmind aprint_error_dev(self, "unknown unit number %d\n",
115 1.12.4.1 rmind mva->mva_unit);
116 1.12.4.1 rmind return;
117 1.12.4.1 rmind }
118 1.12.4.1 rmind
119 1.12.4.1 rmind if (GT_LowAddr_GET(datal) > GT_HighAddr_GET(datah)) {
120 1.12.4.1 rmind aprint_normal_dev(self, "disabled\n");
121 1.12.4.1 rmind return;
122 1.12.4.1 rmind }
123 1.12.4.1 rmind
124 1.12.4.1 rmind bst = prop_dictionary_get(device_properties(sc->sc_dev), "bus-tag");
125 1.12.4.1 rmind if (bst != NULL) {
126 1.12.4.1 rmind KASSERT(prop_object_type(bst) == PROP_TYPE_DATA);
127 1.12.4.1 rmind KASSERT(prop_data_size(bst) == sizeof(bus_space_tag_t));
128 1.12.4.1 rmind memcpy(&sc->sc_iot, prop_data_data_nocopy(bst),
129 1.12.4.1 rmind sizeof(bus_space_tag_t));
130 1.12.4.1 rmind } else
131 1.12.4.1 rmind sc->sc_iot = mva->mva_iot;
132 1.12.4.1 rmind if (sc->sc_iot == NULL) {
133 1.12.4.1 rmind aprint_normal_dev(self, "unused\n");
134 1.12.4.1 rmind return;
135 1.12.4.1 rmind }
136 1.12.4.1 rmind
137 1.12.4.1 rmind aprint_normal_dev(self, "addr %#x-%#x\n",
138 1.12.4.1 rmind GT_LowAddr_GET(datal), GT_HighAddr_GET(datah));
139 1.12.4.1 rmind
140 1.12.4.1 rmind config_search_ia(obio_cfsearch, self, "obio", NULL);
141 1.12.4.1 rmind }
142 1.1 matt
143 1.1 matt
144 1.1 matt int
145 1.1 matt obio_cfprint(void *aux, const char *pnp)
146 1.1 matt {
147 1.1 matt struct obio_attach_args *oa = aux;
148 1.1 matt
149 1.12.4.1 rmind if (pnp)
150 1.1 matt aprint_normal("%s at %s", oa->oa_name, pnp);
151 1.12.4.1 rmind aprint_normal(" addr %#x size %#x", oa->oa_offset, oa->oa_size);
152 1.5 drochner if (oa->oa_irq != OBIOCF_IRQ_DEFAULT)
153 1.2 matt aprint_normal(" irq %d", oa->oa_irq);
154 1.1 matt
155 1.12.4.1 rmind return UNCONF;
156 1.1 matt }
157 1.1 matt
158 1.1 matt
159 1.12.4.1 rmind /* ARGSUSED */
160 1.1 matt int
161 1.12.4.1 rmind obio_cfsearch(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
162 1.1 matt {
163 1.12.4.1 rmind struct obio_softc *sc = device_private(parent);
164 1.1 matt struct obio_attach_args oa;
165 1.1 matt
166 1.1 matt oa.oa_name = cf->cf_name;
167 1.12.4.1 rmind oa.oa_memt = sc->sc_iot;
168 1.5 drochner oa.oa_offset = cf->cf_loc[OBIOCF_OFFSET];
169 1.5 drochner oa.oa_size = cf->cf_loc[OBIOCF_SIZE];
170 1.5 drochner oa.oa_irq = cf->cf_loc[OBIOCF_IRQ];
171 1.1 matt
172 1.1 matt if (config_match(parent, cf, &oa) > 0)
173 1.1 matt config_attach(parent, cf, &oa, obio_cfprint);
174 1.1 matt
175 1.12.4.1 rmind return 0;
176 1.1 matt }
177