pci_machdep.c revision 1.24 1 /* $NetBSD: pci_machdep.c,v 1.24 2014/03/29 19:28:30 christos Exp $ */
2
3 /*
4 * Copyright (c) 2000 Soren S. Jorvang
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed for the
18 * NetBSD Project. See http://www.NetBSD.org/ for
19 * information about NetBSD.
20 * 4. The name of the author may not be used to endorse or promote products
21 * derived from this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35 #include <sys/cdefs.h>
36 __KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.24 2014/03/29 19:28:30 christos Exp $");
37
38 #include "opt_pci.h"
39 #include "pci.h"
40
41 #include <sys/types.h>
42 #include <sys/param.h>
43 #include <sys/time.h>
44 #include <sys/systm.h>
45 #include <sys/errno.h>
46 #include <sys/device.h>
47
48 #include <uvm/uvm_extern.h>
49
50 #define _SGIMIPS_BUS_DMA_PRIVATE
51 #include <sys/bus.h>
52 #include <machine/intr.h>
53 #include <machine/sysconf.h>
54
55 #include <dev/pci/pcivar.h>
56 #include <dev/pci/pcireg.h>
57 #include <dev/pci/pcidevs.h>
58 #include <dev/pci/pciconf.h>
59
60 struct sgimips_bus_dma_tag pci_bus_dma_tag;
61
62 void
63 pci_attach_hook(device_t parent, device_t self, struct pcibus_attach_args *pba)
64 {
65 /*
66 * PCI doesn't have any special needs; just use
67 * the generic versions of these functions as
68 * established in sgimips_bus_dma_init().
69 */
70 pci_bus_dma_tag = sgimips_default_bus_dma_tag; /* struct copy */
71
72 /* XXX */
73
74 return;
75 }
76
77 int
78 pci_bus_maxdevs(pci_chipset_tag_t pc, int busno)
79 {
80
81 return (*pc->pc_bus_maxdevs)(pc, busno);
82 }
83
84 pcitag_t
85 pci_make_tag(pci_chipset_tag_t pc, int bus, int device, int function)
86 {
87
88 return (bus << 16) | (device << 11) | (function << 8);
89 }
90
91 void
92 pci_decompose_tag(pci_chipset_tag_t pc, pcitag_t tag, int *bp, int *dp, int *fp)
93 {
94
95 if (bp != NULL)
96 *bp = (tag >> 16) & 0xff;
97 if (dp != NULL)
98 *dp = (tag >> 11) & 0x1f;
99 if (fp != NULL)
100 *fp = (tag >> 8) & 0x07;
101 }
102
103 pcireg_t
104 pci_conf_read(pci_chipset_tag_t pc, pcitag_t tag, int reg)
105 {
106
107 return (*pc->pc_conf_read)(pc, tag, reg);
108 }
109
110 void
111 pci_conf_write(pci_chipset_tag_t pc, pcitag_t tag, int reg, pcireg_t data)
112 {
113
114 (*pc->pc_conf_write)(pc, tag, reg, data);
115 }
116
117 int
118 pci_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp)
119 {
120 return (*pa->pa_pc->pc_intr_map)(pa, ihp);
121 }
122
123 const char *
124 pci_intr_string(pci_chipset_tag_t pc, pci_intr_handle_t ih, char *buf,
125 size_t len)
126 {
127 return (*pc->pc_intr_string)(pc, ih, buf, len);
128 }
129
130 const struct evcnt *
131 pci_intr_evcnt(pci_chipset_tag_t pc, pci_intr_handle_t ih)
132 {
133
134 /* XXX for now, no evcnt parent reported */
135 return NULL;
136 }
137
138 int
139 pci_intr_setattr(pci_chipset_tag_t pc, pci_intr_handle_t *ih,
140 int attr, uint64_t data)
141 {
142
143 switch (attr) {
144 case PCI_INTR_MPSAFE:
145 return 0;
146 default:
147 return ENODEV;
148 }
149 }
150
151 void *
152 pci_intr_establish(pci_chipset_tag_t pc, pci_intr_handle_t ih, int level,
153 int (*func)(void *), void *arg)
154 {
155
156 return (void *)(*pc->intr_establish)(ih, 0, func, arg);
157 }
158
159 void
160 pci_intr_disestablish(pci_chipset_tag_t pc, void *cookie)
161 {
162
163 (*pc->intr_disestablish)(cookie);
164 }
165
166 #ifdef PCI_NETBSD_CONFIGURE
167 int
168 pci_conf_hook(pci_chipset_tag_t pc, int bus, int device, int function,
169 pcireg_t id)
170 {
171
172 if (pc->pc_conf_hook)
173 return (*pc->pc_conf_hook)(pc, bus, device, function, id);
174 else
175 return (PCI_CONF_DEFAULT);
176 }
177
178 void
179 pci_conf_interrupt(pci_chipset_tag_t pc, int bus, int dev, int pin, int swiz,
180 int *iline)
181 {
182
183 return;
184 }
185 #endif
186