pci_machdep.c revision 1.6 1 /* $NetBSD: pci_machdep.c,v 1.6 1997/01/27 10:19:33 leo Exp $ */
2
3 /*
4 * Copyright (c) 1996 Leo Weppelman. All rights reserved.
5 * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
6 * Copyright (c) 1994 Charles Hannum. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by Charles Hannum.
19 * 4. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 #include <sys/types.h>
35 #include <sys/param.h>
36 #include <sys/time.h>
37 #include <sys/systm.h>
38 #include <sys/errno.h>
39 #include <sys/device.h>
40
41 #include <vm/vm.h>
42 #include <vm/vm_kern.h>
43
44 #include <dev/pci/pcivar.h>
45 #include <dev/pci/pcireg.h>
46
47 #include <machine/cpu.h>
48 #include <machine/iomap.h>
49 #include <atari/atari/device.h>
50
51 int pcibusprint __P((void *auxp, const char *));
52 int pcibusmatch __P((struct device *, struct cfdata *, void *));
53 void pcibusattach __P((struct device *, struct device *, void *));
54
55 static int pci_config_offset __P((pcitag_t));
56
57 /*
58 * Swap a long (abcd -> dcba). The pci-config area has the wrong
59 * endianess....
60 */
61 #define swapl(x) \
62 { asm volatile ("rorw #8,%0\nswap %0\nrorw #8,%0" : : "r" (x)); }
63
64 struct cfattach pcibus_ca = {
65 sizeof(struct device), pcibusmatch, pcibusattach
66 };
67
68 struct cfdriver pcibus_cd = {
69 NULL, "pcibus", DV_DULL
70 };
71
72 int
73 pcibusmatch(pdp, cfp, auxp)
74 struct device *pdp;
75 struct cfdata *cfp;
76 void *auxp;
77 {
78 if(atari_realconfig == 0)
79 return (0);
80 if (strcmp((char *)auxp, "pcibus") || cfp->cf_unit != 0)
81 return(0);
82 return(machineid & ATARI_HADES ? 1 : 0);
83 }
84
85 void
86 pcibusattach(pdp, dp, auxp)
87 struct device *pdp, *dp;
88 void *auxp;
89 {
90 struct pcibus_attach_args pba;
91
92 pba.pba_busname = "pci";
93 pba.pba_pc = NULL;
94 pba.pba_bus = 0;
95
96 printf("\n");
97
98 config_found(dp, &pba, pcibusprint);
99 }
100
101 int
102 pcibusprint(auxp, name)
103 void *auxp;
104 const char *name;
105 {
106 if(name == NULL)
107 return(UNCONF);
108 return(QUIET);
109 }
110
111 void
112 pci_attach_hook(parent, self, pba)
113 struct device *parent, *self;
114 struct pcibus_attach_args *pba;
115 {
116 }
117
118 /*
119 * Atari_init.c maps the config areas NBPG bytes apart....
120 */
121 static int pci_config_offset(tag)
122 pcitag_t tag;
123 {
124 int device;
125
126 device = (tag >> 11) & 0x1f;
127 return(device * NBPG);
128 }
129
130 int
131 pci_bus_maxdevs(pc, busno)
132 pci_chipset_tag_t pc;
133 int busno;
134 {
135 return (4);
136 }
137
138 pcitag_t
139 pci_make_tag(pc, bus, device, function)
140 pci_chipset_tag_t pc;
141 int bus, device, function;
142 {
143 return ((bus << 16) | (device << 11) | (function << 8));
144 }
145
146 pcireg_t
147 pci_conf_read(pc, tag, reg)
148 pci_chipset_tag_t pc;
149 pcitag_t tag;
150 int reg;
151 {
152 u_long data;
153
154 data = *(u_long *)(pci_conf_addr + pci_config_offset(tag) + reg);
155 swapl(data);
156 return(data);
157 }
158
159 void
160 pci_conf_write(pc, tag, reg, data)
161 pci_chipset_tag_t pc;
162 pcitag_t tag;
163 int reg;
164 pcireg_t data;
165 {
166 swapl(data);
167 *((u_long *)(pci_conf_addr + pci_config_offset(tag) + reg)) = data;
168 }
169
170 /*
171 * XXX: All pci_intr_*() functions are no-op's for now...
172 */
173 int
174 pci_intr_map(pc, intrtag, pin, line, ihp)
175 pci_chipset_tag_t pc;
176 pcitag_t intrtag;
177 int pin, line;
178 pci_intr_handle_t *ihp;
179 {
180 /* XXXXXXXXX */
181 *ihp = -1;
182 return 1;
183 }
184
185 const char *
186 pci_intr_string(pc, ih)
187 pci_chipset_tag_t pc;
188 pci_intr_handle_t ih;
189 {
190 static char irqstr[8]; /* 4 + 2 + NULL + sanity */
191
192 if (ih == 0)
193 panic("pci_intr_string: bogus handle 0x%x\n", ih);
194
195 sprintf(irqstr, "irq %d", ih);
196 return (irqstr);
197
198 }
199
200 void *
201 pci_intr_establish(pc, ih, level, func, arg)
202 pci_chipset_tag_t pc;
203 pci_intr_handle_t ih;
204 int level, (*func) __P((void *));
205 void *arg;
206 {
207 /* XXXX */
208 return NULL;
209 }
210
211 void
212 pci_intr_disestablish(pc, cookie)
213 pci_chipset_tag_t pc;
214 void *cookie;
215 {
216 /* XXXX */
217 }
218