pci_machdep.c revision 1.1 1 /* $NetBSD: pci_machdep.c,v 1.1 1995/06/28 01:25:56 cgd Exp $ */
2
3 /*
4 * Copyright (c) 1994 Charles Hannum. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Charles Hannum.
17 * 4. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 /*
33 * Machine-specific functions for PCI autoconfiguration.
34 */
35
36 #include <sys/types.h>
37 #include <sys/param.h>
38 #include <sys/time.h>
39 #include <sys/systm.h>
40 #include <sys/errno.h>
41 #include <sys/device.h>
42
43 #include <vm/vm.h>
44
45 #include <dev/isa/isavar.h>
46 #include <dev/pci/pcivar.h>
47 #include <dev/pci/pcireg.h>
48 #include <alpha/pci/pci_chipset.h>
49
50 int pcimatch __P((struct device *, void *, void *));
51 void pciattach __P((struct device *, struct device *, void *));
52
53 struct cfdriver pcicd = {
54 NULL, "pci", pcimatch, pciattach, DV_DULL, sizeof(struct device)
55 };
56
57 int
58 pcimatch(parent, match, aux)
59 struct device *parent;
60 void *match, *aux;
61 {
62
63 return 1;
64 }
65
66 void
67 pciattach(parent, self, aux)
68 struct device *parent, *self;
69 void *aux;
70 {
71
72 printf("\n");
73 (*pci_cs_fcns->cs_setup)();
74 (*pci_cfg_fcns->cfg_attach)(parent, self, aux);
75 }
76
77 pcitag_t
78 pci_make_tag(bus, device, function)
79 int bus, device, function;
80 {
81
82 return (*pci_cs_fcns->cs_make_tag)(bus, device, function);
83 }
84
85 pcireg_t
86 pci_conf_read(tag, offset)
87 pcitag_t tag;
88 int offset; /* XXX */
89 {
90
91 return (*pci_cs_fcns->cs_conf_read)(tag, offset);
92 }
93
94 void
95 pci_conf_write(tag, offset, data)
96 pcitag_t tag;
97 int offset; /* XXX */
98 pcireg_t data;
99 {
100
101 (*pci_cs_fcns->cs_conf_write)(tag, offset, data);
102 }
103
104 int
105 pci_map_io(tag, reg, iobasep)
106 pcitag_t tag;
107 int reg;
108 int *iobasep;
109 {
110
111 /*
112 * XXX should be a chipset-dependent function, but...
113 * what would it do, and what would use it?
114 */
115 panic("pci_map_io: not implemented");
116 }
117
118 int
119 pci_map_mem(tag, reg, vap, pap)
120 pcitag_t tag;
121 int reg;
122 vm_offset_t *vap, *pap;
123 {
124
125 return (*pci_cs_fcns->cs_map_mem)(tag, reg, vap, pap);
126 }
127
128 int
129 pcidma_map(addr, size, mappings)
130 caddr_t addr;
131 vm_size_t size;
132 vm_offset_t *mappings;
133 {
134
135 return (*pci_cs_fcns->cs_pcidma_map)(addr, size, mappings);
136 }
137
138 void
139 pcidma_unmap(addr, size, nmappings, mappings)
140 caddr_t addr;
141 vm_size_t size;
142 int nmappings;
143 vm_offset_t *mappings;
144 {
145
146 (*pci_cs_fcns->cs_pcidma_unmap)(addr, size, nmappings, mappings);
147 }
148
149 void *
150 pci_map_int(tag, level, func, arg)
151 pcitag_t tag;
152 pci_intrlevel level;
153 int (*func) __P((void *));
154 void *arg;
155 {
156 pcireg_t data;
157 int pin;
158
159 data = pci_conf_read(tag, PCI_INTERRUPT_REG);
160
161 pin = PCI_INTERRUPT_PIN(data);
162
163 if (pin == 0) {
164 /* No IRQ used. */
165 return 0;
166 }
167
168 if (pin > 4) {
169 printf("pci_map_int: bad interrupt pin %d\n", pin);
170 return NULL;
171 }
172
173 return (*pci_cfg_fcns->cfg_map_int)(tag, level, func, arg, pin);
174 }
175
176 isa_intrlevel
177 pcilevel_to_isa(level)
178 pci_intrlevel level;
179 {
180
181 switch (level) {
182 case PCI_IPL_NONE:
183 return (ISA_IPL_NONE);
184
185 case PCI_IPL_BIO:
186 return (ISA_IPL_BIO);
187
188 case PCI_IPL_NET:
189 return (ISA_IPL_NET);
190
191 case PCI_IPL_TTY:
192 return (ISA_IPL_TTY);
193
194 case PCI_IPL_CLOCK:
195 return (ISA_IPL_CLOCK);
196
197 default:
198 panic("pcilevel_to_isa: unknown level %d\n", level);
199 }
200 }
201