pci_machdep.c revision 1.8 1 /* $NetBSD: pci_machdep.c,v 1.8 1998/01/12 18:04:20 thorpej Exp $ */
2
3 /*
4 * Copyright (c) 1996 Leo Weppelman. All rights reserved.
5 * Copyright (c) 1996, 1997 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 int
69 pcibusmatch(pdp, cfp, auxp)
70 struct device *pdp;
71 struct cfdata *cfp;
72 void *auxp;
73 {
74 if(atari_realconfig == 0)
75 return (0);
76 if (strcmp((char *)auxp, "pcibus") || cfp->cf_unit != 0)
77 return(0);
78 return(machineid & ATARI_HADES ? 1 : 0);
79 }
80
81 void
82 pcibusattach(pdp, dp, auxp)
83 struct device *pdp, *dp;
84 void *auxp;
85 {
86 struct pcibus_attach_args pba;
87
88 pba.pba_busname = "pci";
89 pba.pba_pc = NULL;
90 pba.pba_bus = 0;
91 pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED;
92
93 printf("\n");
94
95 config_found(dp, &pba, pcibusprint);
96 }
97
98 int
99 pcibusprint(auxp, name)
100 void *auxp;
101 const char *name;
102 {
103 if(name == NULL)
104 return(UNCONF);
105 return(QUIET);
106 }
107
108 void
109 pci_attach_hook(parent, self, pba)
110 struct device *parent, *self;
111 struct pcibus_attach_args *pba;
112 {
113 }
114
115 /*
116 * Atari_init.c maps the config areas NBPG bytes apart....
117 */
118 static int pci_config_offset(tag)
119 pcitag_t tag;
120 {
121 int device;
122
123 device = (tag >> 11) & 0x1f;
124 return(device * NBPG);
125 }
126
127 int
128 pci_bus_maxdevs(pc, busno)
129 pci_chipset_tag_t pc;
130 int busno;
131 {
132 return (4);
133 }
134
135 pcitag_t
136 pci_make_tag(pc, bus, device, function)
137 pci_chipset_tag_t pc;
138 int bus, device, function;
139 {
140 return ((bus << 16) | (device << 11) | (function << 8));
141 }
142
143 pcireg_t
144 pci_conf_read(pc, tag, reg)
145 pci_chipset_tag_t pc;
146 pcitag_t tag;
147 int reg;
148 {
149 u_long data;
150
151 data = *(u_long *)(pci_conf_addr + pci_config_offset(tag) + reg);
152 swapl(data);
153 return(data);
154 }
155
156 void
157 pci_conf_write(pc, tag, reg, data)
158 pci_chipset_tag_t pc;
159 pcitag_t tag;
160 int reg;
161 pcireg_t data;
162 {
163 swapl(data);
164 *((u_long *)(pci_conf_addr + pci_config_offset(tag) + reg)) = data;
165 }
166
167 /*
168 * XXX: All pci_intr_*() functions are no-op's for now...
169 */
170 int
171 pci_intr_map(pc, intrtag, pin, line, ihp)
172 pci_chipset_tag_t pc;
173 pcitag_t intrtag;
174 int pin, line;
175 pci_intr_handle_t *ihp;
176 {
177 /* XXXXXXXXX */
178 *ihp = -1;
179 return 1;
180 }
181
182 const char *
183 pci_intr_string(pc, ih)
184 pci_chipset_tag_t pc;
185 pci_intr_handle_t ih;
186 {
187 static char irqstr[8]; /* 4 + 2 + NULL + sanity */
188
189 if (ih == 0)
190 panic("pci_intr_string: bogus handle 0x%x\n", ih);
191
192 sprintf(irqstr, "irq %d", ih);
193 return (irqstr);
194
195 }
196
197 void *
198 pci_intr_establish(pc, ih, level, func, arg)
199 pci_chipset_tag_t pc;
200 pci_intr_handle_t ih;
201 int level, (*func) __P((void *));
202 void *arg;
203 {
204 /* XXXX */
205 return NULL;
206 }
207
208 void
209 pci_intr_disestablish(pc, cookie)
210 pci_chipset_tag_t pc;
211 void *cookie;
212 {
213 /* XXXX */
214 }
215