obio.c revision 1.4 1 1.4 drochner /* $NetBSD: obio.c,v 1.4 2004/09/08 20:08:46 drochner 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.1 matt /*
41 1.1 matt * gt.c -- GT system controller driver
42 1.1 matt */
43 1.3 lukem
44 1.3 lukem #include <sys/cdefs.h>
45 1.4 drochner __KERNEL_RCSID(0, "$NetBSD: obio.c,v 1.4 2004/09/08 20:08:46 drochner Exp $");
46 1.1 matt
47 1.1 matt #include "opt_marvell.h"
48 1.1 matt
49 1.1 matt #include <sys/param.h>
50 1.1 matt #include <sys/types.h>
51 1.1 matt #include <sys/cdefs.h>
52 1.1 matt #include <sys/extent.h>
53 1.1 matt #include <sys/device.h>
54 1.1 matt #include <sys/kernel.h>
55 1.1 matt #include <sys/malloc.h>
56 1.1 matt
57 1.1 matt #define _BUS_SPACE_PRIVATE
58 1.1 matt #define _BUS_DMA_PRIVATE
59 1.1 matt #include <machine/bus.h>
60 1.1 matt
61 1.1 matt #include <powerpc/spr.h>
62 1.1 matt #include <powerpc/oea/hid.h>
63 1.1 matt
64 1.1 matt #include <dev/pci/pcivar.h>
65 1.1 matt #include <dev/marvell/gtreg.h>
66 1.1 matt #include <dev/marvell/gtvar.h>
67 1.1 matt
68 1.1 matt #ifdef DEBUG
69 1.1 matt #include <sys/systm.h> /* for Debugger() */
70 1.1 matt #endif
71 1.1 matt
72 1.1 matt static int obio_cfprint(void *, const char *);
73 1.1 matt static int obio_cfmatch(struct device *, struct cfdata *, void *);
74 1.4 drochner static int obio_cfsearch(struct device *, struct cfdata *,
75 1.4 drochner const locdesc_t *, void *);
76 1.1 matt static void obio_cfattach(struct device *, struct device *, void *);
77 1.1 matt
78 1.1 matt struct obio_softc {
79 1.1 matt struct device sc_dev;
80 1.1 matt bus_space_tag_t sc_memt;
81 1.1 matt bus_space_tag_t sc_gt_memt;
82 1.1 matt bus_space_tag_t sc_gt_memh;
83 1.1 matt };
84 1.1 matt
85 1.1 matt CFATTACH_DECL(obio, sizeof(struct obio_softc),
86 1.1 matt obio_cfmatch, obio_cfattach, NULL, NULL);
87 1.1 matt
88 1.1 matt extern struct cfdriver obio_cd;
89 1.1 matt
90 1.1 matt static const struct {
91 1.1 matt bus_addr_t low_decode;
92 1.1 matt bus_addr_t high_decode;
93 1.1 matt } obio_info[5] = {
94 1.1 matt { GT_CS0_Low_Decode, GT_CS0_High_Decode, },
95 1.1 matt { GT_CS1_Low_Decode, GT_CS1_High_Decode, },
96 1.1 matt { GT_CS2_Low_Decode, GT_CS2_High_Decode, },
97 1.1 matt { GT_CS3_Low_Decode, GT_CS3_High_Decode, },
98 1.1 matt { GT_BootCS_Low_Decode, GT_BootCS_High_Decode, },
99 1.1 matt };
100 1.1 matt
101 1.1 matt extern bus_space_tag_t obio_bs_tags[5];
102 1.1 matt
103 1.1 matt int
104 1.1 matt obio_cfprint(void *aux, const char *pnp)
105 1.1 matt {
106 1.1 matt struct obio_attach_args *oa = aux;
107 1.1 matt
108 1.1 matt if (pnp) {
109 1.1 matt aprint_normal("%s at %s", oa->oa_name, pnp);
110 1.1 matt }
111 1.2 matt aprint_normal(" offset %#x size %#x", oa->oa_offset, oa->oa_size);
112 1.2 matt if (oa->oa_irq != OBIO_UNK_IRQ)
113 1.2 matt aprint_normal(" irq %d", oa->oa_irq);
114 1.1 matt
115 1.1 matt return (UNCONF);
116 1.1 matt }
117 1.1 matt
118 1.1 matt
119 1.1 matt int
120 1.4 drochner obio_cfsearch(struct device *parent, struct cfdata *cf,
121 1.4 drochner const locdesc_t *ldesc, void *aux)
122 1.1 matt {
123 1.1 matt struct obio_softc *sc = (struct obio_softc *) parent;
124 1.1 matt struct obio_attach_args oa;
125 1.1 matt
126 1.1 matt oa.oa_name = cf->cf_name;
127 1.1 matt oa.oa_memt = sc->sc_memt;
128 1.1 matt oa.oa_offset = cf->obiocf_offset;
129 1.1 matt oa.oa_size = cf->obiocf_size;
130 1.1 matt oa.oa_irq = cf->obiocf_irq;
131 1.1 matt
132 1.1 matt if (config_match(parent, cf, &oa) > 0)
133 1.1 matt config_attach(parent, cf, &oa, obio_cfprint);
134 1.1 matt
135 1.1 matt return (0);
136 1.1 matt }
137 1.1 matt
138 1.1 matt int
139 1.1 matt obio_cfmatch(struct device *parent, struct cfdata *cf, void *aux)
140 1.1 matt {
141 1.1 matt struct gt_softc * const gt = (struct gt_softc *)parent;
142 1.1 matt struct gt_attach_args * const ga = aux;
143 1.1 matt
144 1.1 matt return GT_OBIOOK(gt, ga, &obio_cd);
145 1.1 matt }
146 1.1 matt
147 1.1 matt void
148 1.1 matt obio_cfattach(struct device *parent, struct device *self, void *aux)
149 1.1 matt {
150 1.1 matt struct gt_softc * const gt = (struct gt_softc *)parent;
151 1.1 matt struct obio_softc *sc = (struct obio_softc *)self;
152 1.1 matt struct gt_attach_args *ga = aux;
153 1.1 matt uint32_t datal, datah;
154 1.1 matt
155 1.1 matt GT_OBIOFOUND(gt, ga);
156 1.1 matt
157 1.1 matt datal = bus_space_read_4(ga->ga_memt, ga->ga_memh,
158 1.1 matt obio_info[ga->ga_unit].low_decode);
159 1.1 matt datah = bus_space_read_4(ga->ga_memt, ga->ga_memh,
160 1.1 matt obio_info[ga->ga_unit].high_decode);
161 1.1 matt
162 1.1 matt if (GT_LowAddr_GET(datal) > GT_HighAddr_GET(datah)) {
163 1.1 matt aprint_normal(": disabled\n");
164 1.1 matt return;
165 1.1 matt }
166 1.1 matt
167 1.1 matt sc->sc_memt = obio_bs_tags[ga->ga_unit];
168 1.1 matt if (sc->sc_memt == NULL) {
169 1.1 matt aprint_normal(": unused\n");
170 1.1 matt return;
171 1.1 matt }
172 1.1 matt
173 1.1 matt aprint_normal(": addr %#x-%#x, %s-endian\n",
174 1.1 matt GT_LowAddr_GET(datal), GT_HighAddr_GET(datah),
175 1.1 matt GT_PCISwap_GET(datal) == 1 ? "little" : "big");
176 1.1 matt
177 1.4 drochner config_search_ia(obio_cfsearch, &sc->sc_dev, "obio", NULL);
178 1.1 matt }
179