pci_machdep.c revision 1.5 1 /* $NetBSD: pci_machdep.c,v 1.5 1996/12/20 12:50:12 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 config_found(dp, &pba, pcibusprint);
97 }
98
99 int
100 pcibusprint(auxp, name)
101 void *auxp;
102 const char *name;
103 {
104 if(name == NULL)
105 return(UNCONF);
106 return(QUIET);
107 }
108
109 void
110 pci_attach_hook(parent, self, pba)
111 struct device *parent, *self;
112 struct pcibus_attach_args *pba;
113 {
114 }
115
116 /*
117 * Atari_init.c maps the config areas NBPG bytes apart....
118 */
119 static int pci_config_offset(tag)
120 pcitag_t tag;
121 {
122 int device;
123
124 device = (tag >> 11) & 0x1f;
125 return(device * NBPG);
126 }
127
128 int
129 pci_bus_maxdevs(pc, busno)
130 pci_chipset_tag_t pc;
131 int busno;
132 {
133 return (4);
134 }
135
136 pcitag_t
137 pci_make_tag(pc, bus, device, function)
138 pci_chipset_tag_t pc;
139 int bus, device, function;
140 {
141 return ((bus << 16) | (device << 11) | (function << 8));
142 }
143
144 pcireg_t
145 pci_conf_read(pc, tag, reg)
146 pci_chipset_tag_t pc;
147 pcitag_t tag;
148 int reg;
149 {
150 u_long data;
151
152 data = *(u_long *)(pci_conf_addr + pci_config_offset(tag) + reg);
153 swapl(data);
154 return(data);
155 }
156
157 void
158 pci_conf_write(pc, tag, reg, data)
159 pci_chipset_tag_t pc;
160 pcitag_t tag;
161 int reg;
162 pcireg_t data;
163 {
164 swapl(data);
165 *((u_long *)(pci_conf_addr + pci_config_offset(tag) + reg)) = data;
166 }
167
168 /*
169 * XXX: All pci_intr_*() functions are no-op's for now...
170 */
171 int
172 pci_intr_map(pc, intrtag, pin, line, ihp)
173 pci_chipset_tag_t pc;
174 pcitag_t intrtag;
175 int pin, line;
176 pci_intr_handle_t *ihp;
177 {
178 /* XXXXXXXXX */
179 *ihp = -1;
180 return 1;
181 }
182
183 const char *
184 pci_intr_string(pc, ih)
185 pci_chipset_tag_t pc;
186 pci_intr_handle_t ih;
187 {
188 static char irqstr[8]; /* 4 + 2 + NULL + sanity */
189
190 if (ih == 0)
191 panic("pci_intr_string: bogus handle 0x%x\n", ih);
192
193 sprintf(irqstr, "irq %d", ih);
194 return (irqstr);
195
196 }
197
198 void *
199 pci_intr_establish(pc, ih, level, func, arg)
200 pci_chipset_tag_t pc;
201 pci_intr_handle_t ih;
202 int level, (*func) __P((void *));
203 void *arg;
204 {
205 /* XXXX */
206 return NULL;
207 }
208
209 void
210 pci_intr_disestablish(pc, cookie)
211 pci_chipset_tag_t pc;
212 void *cookie;
213 {
214 /* XXXX */
215 }
216