gt.c revision 1.6 1 1.6 fvdl /* $NetBSD: gt.c,v 1.6 2003/06/15 23:08:59 fvdl Exp $ */
2 1.1 simonb
3 1.1 simonb /*
4 1.1 simonb * Copyright 2002 Wasabi Systems, Inc.
5 1.1 simonb * All rights reserved.
6 1.1 simonb *
7 1.1 simonb * Written by Jason R. Thorpe and Simon Burge for Wasabi Systems, Inc.
8 1.1 simonb *
9 1.1 simonb * Redistribution and use in source and binary forms, with or without
10 1.1 simonb * modification, are permitted provided that the following conditions
11 1.1 simonb * are met:
12 1.1 simonb * 1. Redistributions of source code must retain the above copyright
13 1.1 simonb * notice, this list of conditions and the following disclaimer.
14 1.1 simonb * 2. Redistributions in binary form must reproduce the above copyright
15 1.1 simonb * notice, this list of conditions and the following disclaimer in the
16 1.1 simonb * documentation and/or other materials provided with the distribution.
17 1.1 simonb * 3. All advertising materials mentioning features or use of this software
18 1.1 simonb * must display the following acknowledgement:
19 1.1 simonb * This product includes software developed for the NetBSD Project by
20 1.1 simonb * Wasabi Systems, Inc.
21 1.1 simonb * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 1.1 simonb * or promote products derived from this software without specific prior
23 1.1 simonb * written permission.
24 1.1 simonb *
25 1.1 simonb * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 1.1 simonb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 1.1 simonb * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 1.1 simonb * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 1.1 simonb * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 1.1 simonb * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 1.1 simonb * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 1.1 simonb * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 1.1 simonb * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 1.1 simonb * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 1.1 simonb * POSSIBILITY OF SUCH DAMAGE.
36 1.1 simonb */
37 1.1 simonb
38 1.1 simonb #include <sys/param.h>
39 1.1 simonb #include <sys/systm.h>
40 1.1 simonb #include <sys/device.h>
41 1.1 simonb
42 1.1 simonb #include <dev/pci/pcivar.h>
43 1.1 simonb
44 1.1 simonb #include <evbmips/malta/maltareg.h>
45 1.1 simonb #include <evbmips/malta/maltavar.h>
46 1.1 simonb
47 1.1 simonb #include <evbmips/malta/dev/gtreg.h>
48 1.1 simonb #include <evbmips/malta/dev/gtvar.h>
49 1.1 simonb
50 1.1 simonb #include "pci.h"
51 1.1 simonb
52 1.1 simonb /*
53 1.1 simonb * Galileo systems (so far) are always single-processor, so this is sufficient.
54 1.1 simonb */
55 1.1 simonb #define PCI_CONF_LOCK(s) (s) = splhigh()
56 1.1 simonb #define PCI_CONF_UNLOCK(s) splx((s))
57 1.1 simonb
58 1.1 simonb static void gt_attach_hook(struct device *, struct device *,
59 1.1 simonb struct pcibus_attach_args *);
60 1.1 simonb static int gt_bus_maxdevs(void *, int);
61 1.1 simonb static pcitag_t gt_make_tag(void *, int, int, int);
62 1.1 simonb static void gt_decompose_tag(void *, pcitag_t, int *, int *, int *);
63 1.1 simonb static pcireg_t gt_conf_read(void *, pcitag_t, int);
64 1.1 simonb static void gt_conf_write(void *, pcitag_t, int, pcireg_t);
65 1.1 simonb
66 1.1 simonb void
67 1.1 simonb gt_pci_init(pci_chipset_tag_t pc, struct gt_config *mcp)
68 1.1 simonb {
69 1.1 simonb
70 1.1 simonb pc->pc_conf_v = mcp;
71 1.1 simonb pc->pc_attach_hook = gt_attach_hook;
72 1.1 simonb pc->pc_bus_maxdevs = gt_bus_maxdevs;
73 1.1 simonb pc->pc_make_tag = gt_make_tag;
74 1.1 simonb pc->pc_decompose_tag = gt_decompose_tag;
75 1.1 simonb pc->pc_conf_read = gt_conf_read;
76 1.1 simonb pc->pc_conf_write = gt_conf_write;
77 1.1 simonb }
78 1.1 simonb
79 1.1 simonb static void
80 1.1 simonb gt_attach_hook(struct device *parent, struct device *self,
81 1.1 simonb struct pcibus_attach_args *pba)
82 1.1 simonb {
83 1.1 simonb
84 1.1 simonb /* Nothing to do... */
85 1.1 simonb }
86 1.1 simonb
87 1.1 simonb static int gt_match(struct device *, struct cfdata *, void *);
88 1.1 simonb static void gt_attach(struct device *, struct device *, void *);
89 1.1 simonb static int gt_print(void *aux, const char *pnp);
90 1.1 simonb
91 1.4 thorpej CFATTACH_DECL(gt, sizeof(struct device),
92 1.5 thorpej gt_match, gt_attach, NULL, NULL);
93 1.1 simonb
94 1.1 simonb static int
95 1.1 simonb gt_match(parent, match, aux)
96 1.1 simonb struct device *parent;
97 1.1 simonb struct cfdata *match;
98 1.1 simonb void *aux;
99 1.1 simonb {
100 1.1 simonb return 1;
101 1.1 simonb }
102 1.1 simonb
103 1.1 simonb static void
104 1.1 simonb gt_attach(parent, self, aux)
105 1.1 simonb struct device *parent;
106 1.1 simonb struct device *self;
107 1.1 simonb void *aux;
108 1.1 simonb {
109 1.1 simonb struct malta_config *mcp = &malta_configuration;
110 1.1 simonb struct pcibus_attach_args pba;
111 1.1 simonb
112 1.1 simonb printf("\n");
113 1.1 simonb
114 1.1 simonb #if NPCI > 0
115 1.1 simonb pba.pba_busname = "pci";
116 1.1 simonb pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED;
117 1.1 simonb pba.pba_bus = 0;
118 1.2 thorpej pba.pba_bridgetag = NULL;
119 1.1 simonb pba.pba_iot = &mcp->mc_iot;
120 1.1 simonb pba.pba_memt = &mcp->mc_memt;
121 1.1 simonb pba.pba_dmat = &mcp->mc_pci_dmat; /* pci_bus_dma_tag */
122 1.6 fvdl pba.pba_dmat64 = NULL;
123 1.1 simonb pba.pba_pc = &mcp->mc_pc;
124 1.1 simonb
125 1.1 simonb config_found(self, &pba, gt_print);
126 1.1 simonb #endif
127 1.1 simonb return;
128 1.1 simonb }
129 1.1 simonb
130 1.1 simonb static int
131 1.1 simonb gt_print(aux, pnp)
132 1.1 simonb void *aux;
133 1.1 simonb const char *pnp;
134 1.1 simonb {
135 1.1 simonb /* XXX */
136 1.1 simonb return 0;
137 1.1 simonb }
138 1.1 simonb
139 1.1 simonb static int
140 1.1 simonb gt_bus_maxdevs(void *v, int busno)
141 1.1 simonb {
142 1.1 simonb
143 1.1 simonb /* The galileo has problems accessing device 31. */
144 1.1 simonb if (busno == 0)
145 1.1 simonb return (31);
146 1.1 simonb return (32);
147 1.1 simonb }
148 1.1 simonb
149 1.1 simonb static pcitag_t
150 1.1 simonb gt_make_tag(void *v, int b, int d, int f)
151 1.1 simonb {
152 1.1 simonb
153 1.1 simonb return ((b << 16) | (d << 11) | (f << 8));
154 1.1 simonb }
155 1.1 simonb
156 1.1 simonb static void
157 1.1 simonb gt_decompose_tag(void *v, pcitag_t tag, int *bp, int *dp, int *fp)
158 1.1 simonb {
159 1.1 simonb
160 1.1 simonb if (bp != NULL)
161 1.1 simonb *bp = (tag >> 16) & 0xff;
162 1.1 simonb if (dp != NULL)
163 1.1 simonb *dp = (tag >> 11) & 0x1f;
164 1.1 simonb if (fp != NULL)
165 1.1 simonb *fp = (tag >> 8) & 0x7;
166 1.1 simonb }
167 1.1 simonb
168 1.1 simonb static pcireg_t
169 1.1 simonb gt_conf_read(void *v, pcitag_t tag, int offset)
170 1.1 simonb {
171 1.1 simonb pcireg_t data;
172 1.1 simonb int bus, dev, func, s;
173 1.1 simonb
174 1.1 simonb gt_decompose_tag(NULL /* XXX */, tag, &bus, &dev, &func);
175 1.1 simonb
176 1.1 simonb /* The galileo has problems accessing device 31. */
177 1.1 simonb if (bus == 0 && dev == 31)
178 1.1 simonb return ((pcireg_t) -1);
179 1.1 simonb
180 1.1 simonb /* XXX: no support for bus > 0 yet */
181 1.1 simonb if (bus > 0)
182 1.1 simonb return ((pcireg_t) -1);
183 1.1 simonb
184 1.1 simonb PCI_CONF_LOCK(s);
185 1.1 simonb
186 1.1 simonb /* Clear cause register bits. */
187 1.1 simonb GT_REGVAL(GT_INTR_CAUSE) = 0;
188 1.1 simonb
189 1.1 simonb GT_REGVAL(GT_PCI0_CFG_ADDR) = (1 << 31) | tag | offset;
190 1.1 simonb data = GT_REGVAL(GT_PCI0_CFG_DATA);
191 1.1 simonb
192 1.1 simonb /* Check for master abort. */
193 1.1 simonb if (GT_REGVAL(GT_INTR_CAUSE) & (GTIC_MASABORT0 | GTIC_TARABORT0))
194 1.1 simonb data = (pcireg_t) -1;
195 1.1 simonb
196 1.1 simonb PCI_CONF_UNLOCK(s);
197 1.1 simonb
198 1.1 simonb return (data);
199 1.1 simonb }
200 1.1 simonb
201 1.1 simonb static void
202 1.1 simonb gt_conf_write(void *v, pcitag_t tag, int offset, pcireg_t data)
203 1.1 simonb {
204 1.1 simonb int bus, dev, func, s;
205 1.1 simonb
206 1.1 simonb gt_decompose_tag(NULL /* XXX */, tag, &bus, &dev, &func);
207 1.1 simonb
208 1.1 simonb /* The galileo has problems accessing device 31. */
209 1.1 simonb if (bus == 0 && dev == 31)
210 1.1 simonb return;
211 1.1 simonb
212 1.1 simonb /* XXX: no support for bus > 0 yet */
213 1.1 simonb if (bus > 0)
214 1.1 simonb return;
215 1.1 simonb
216 1.1 simonb PCI_CONF_LOCK(s);
217 1.1 simonb
218 1.1 simonb /* Clear cause register bits. */
219 1.1 simonb GT_REGVAL(GT_INTR_CAUSE) = 0;
220 1.1 simonb
221 1.1 simonb GT_REGVAL(GT_PCI0_CFG_ADDR) = (1 << 31) | tag | offset;
222 1.1 simonb GT_REGVAL(GT_PCI0_CFG_DATA) = data;
223 1.1 simonb
224 1.1 simonb PCI_CONF_UNLOCK(s);
225 1.1 simonb }
226