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