obio.c revision 1.3 1 1.3 lukem /* $NetBSD: obio.c,v 1.3 2003/07/14 15:47:18 lukem 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.3 lukem __KERNEL_RCSID(0, "$NetBSD: obio.c,v 1.3 2003/07/14 15:47:18 lukem 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.1 matt static int obio_cfsearch(struct device *, struct cfdata *, void *);
75 1.1 matt static void obio_cfattach(struct device *, struct device *, void *);
76 1.1 matt
77 1.1 matt struct obio_softc {
78 1.1 matt struct device sc_dev;
79 1.1 matt bus_space_tag_t sc_memt;
80 1.1 matt bus_space_tag_t sc_gt_memt;
81 1.1 matt bus_space_tag_t sc_gt_memh;
82 1.1 matt };
83 1.1 matt
84 1.1 matt CFATTACH_DECL(obio, sizeof(struct obio_softc),
85 1.1 matt obio_cfmatch, obio_cfattach, NULL, NULL);
86 1.1 matt
87 1.1 matt extern struct cfdriver obio_cd;
88 1.1 matt
89 1.1 matt static const struct {
90 1.1 matt bus_addr_t low_decode;
91 1.1 matt bus_addr_t high_decode;
92 1.1 matt } obio_info[5] = {
93 1.1 matt { GT_CS0_Low_Decode, GT_CS0_High_Decode, },
94 1.1 matt { GT_CS1_Low_Decode, GT_CS1_High_Decode, },
95 1.1 matt { GT_CS2_Low_Decode, GT_CS2_High_Decode, },
96 1.1 matt { GT_CS3_Low_Decode, GT_CS3_High_Decode, },
97 1.1 matt { GT_BootCS_Low_Decode, GT_BootCS_High_Decode, },
98 1.1 matt };
99 1.1 matt
100 1.1 matt extern bus_space_tag_t obio_bs_tags[5];
101 1.1 matt
102 1.1 matt int
103 1.1 matt obio_cfprint(void *aux, const char *pnp)
104 1.1 matt {
105 1.1 matt struct obio_attach_args *oa = aux;
106 1.1 matt
107 1.1 matt if (pnp) {
108 1.1 matt aprint_normal("%s at %s", oa->oa_name, pnp);
109 1.1 matt }
110 1.2 matt aprint_normal(" offset %#x size %#x", oa->oa_offset, oa->oa_size);
111 1.2 matt if (oa->oa_irq != OBIO_UNK_IRQ)
112 1.2 matt aprint_normal(" irq %d", oa->oa_irq);
113 1.1 matt
114 1.1 matt return (UNCONF);
115 1.1 matt }
116 1.1 matt
117 1.1 matt
118 1.1 matt int
119 1.1 matt obio_cfsearch(struct device *parent, struct cfdata *cf, void *aux)
120 1.1 matt {
121 1.1 matt struct obio_softc *sc = (struct obio_softc *) parent;
122 1.1 matt struct obio_attach_args oa;
123 1.1 matt
124 1.1 matt oa.oa_name = cf->cf_name;
125 1.1 matt oa.oa_memt = sc->sc_memt;
126 1.1 matt oa.oa_offset = cf->obiocf_offset;
127 1.1 matt oa.oa_size = cf->obiocf_size;
128 1.1 matt oa.oa_irq = cf->obiocf_irq;
129 1.1 matt
130 1.1 matt if (config_match(parent, cf, &oa) > 0)
131 1.1 matt config_attach(parent, cf, &oa, obio_cfprint);
132 1.1 matt
133 1.1 matt return (0);
134 1.1 matt }
135 1.1 matt
136 1.1 matt int
137 1.1 matt obio_cfmatch(struct device *parent, struct cfdata *cf, void *aux)
138 1.1 matt {
139 1.1 matt struct gt_softc * const gt = (struct gt_softc *)parent;
140 1.1 matt struct gt_attach_args * const ga = aux;
141 1.1 matt
142 1.1 matt return GT_OBIOOK(gt, ga, &obio_cd);
143 1.1 matt }
144 1.1 matt
145 1.1 matt void
146 1.1 matt obio_cfattach(struct device *parent, struct device *self, void *aux)
147 1.1 matt {
148 1.1 matt struct gt_softc * const gt = (struct gt_softc *)parent;
149 1.1 matt struct obio_softc *sc = (struct obio_softc *)self;
150 1.1 matt struct gt_attach_args *ga = aux;
151 1.1 matt uint32_t datal, datah;
152 1.1 matt
153 1.1 matt GT_OBIOFOUND(gt, ga);
154 1.1 matt
155 1.1 matt datal = bus_space_read_4(ga->ga_memt, ga->ga_memh,
156 1.1 matt obio_info[ga->ga_unit].low_decode);
157 1.1 matt datah = bus_space_read_4(ga->ga_memt, ga->ga_memh,
158 1.1 matt obio_info[ga->ga_unit].high_decode);
159 1.1 matt
160 1.1 matt if (GT_LowAddr_GET(datal) > GT_HighAddr_GET(datah)) {
161 1.1 matt aprint_normal(": disabled\n");
162 1.1 matt return;
163 1.1 matt }
164 1.1 matt
165 1.1 matt sc->sc_memt = obio_bs_tags[ga->ga_unit];
166 1.1 matt if (sc->sc_memt == NULL) {
167 1.1 matt aprint_normal(": unused\n");
168 1.1 matt return;
169 1.1 matt }
170 1.1 matt
171 1.1 matt aprint_normal(": addr %#x-%#x, %s-endian\n",
172 1.1 matt GT_LowAddr_GET(datal), GT_HighAddr_GET(datah),
173 1.1 matt GT_PCISwap_GET(datal) == 1 ? "little" : "big");
174 1.1 matt
175 1.1 matt config_search(obio_cfsearch, &sc->sc_dev, NULL);
176 1.1 matt }
177 1.1 matt
178