tegra_pcie.c revision 1.1 1 1.1 jmcneill /* $NetBSD: tegra_pcie.c,v 1.1 2015/05/03 01:07:44 jmcneill Exp $ */
2 1.1 jmcneill
3 1.1 jmcneill /*-
4 1.1 jmcneill * Copyright (c) 2015 Jared D. McNeill <jmcneill (at) invisible.ca>
5 1.1 jmcneill * All rights reserved.
6 1.1 jmcneill *
7 1.1 jmcneill * Redistribution and use in source and binary forms, with or without
8 1.1 jmcneill * modification, are permitted provided that the following conditions
9 1.1 jmcneill * are met:
10 1.1 jmcneill * 1. Redistributions of source code must retain the above copyright
11 1.1 jmcneill * notice, this list of conditions and the following disclaimer.
12 1.1 jmcneill * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 jmcneill * notice, this list of conditions and the following disclaimer in the
14 1.1 jmcneill * documentation and/or other materials provided with the distribution.
15 1.1 jmcneill *
16 1.1 jmcneill * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.1 jmcneill * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.1 jmcneill * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.1 jmcneill * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.1 jmcneill * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 1.1 jmcneill * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 1.1 jmcneill * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 1.1 jmcneill * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 1.1 jmcneill * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.1 jmcneill * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.1 jmcneill * SUCH DAMAGE.
27 1.1 jmcneill */
28 1.1 jmcneill
29 1.1 jmcneill #include "locators.h"
30 1.1 jmcneill
31 1.1 jmcneill #include <sys/cdefs.h>
32 1.1 jmcneill __KERNEL_RCSID(0, "$NetBSD: tegra_pcie.c,v 1.1 2015/05/03 01:07:44 jmcneill Exp $");
33 1.1 jmcneill
34 1.1 jmcneill #include <sys/param.h>
35 1.1 jmcneill #include <sys/bus.h>
36 1.1 jmcneill #include <sys/device.h>
37 1.1 jmcneill #include <sys/intr.h>
38 1.1 jmcneill #include <sys/systm.h>
39 1.1 jmcneill #include <sys/kernel.h>
40 1.1 jmcneill #include <sys/extent.h>
41 1.1 jmcneill #include <sys/queue.h>
42 1.1 jmcneill #include <sys/mutex.h>
43 1.1 jmcneill #include <sys/kmem.h>
44 1.1 jmcneill
45 1.1 jmcneill #include <arm/cpufunc.h>
46 1.1 jmcneill
47 1.1 jmcneill #include <dev/pci/pcireg.h>
48 1.1 jmcneill #include <dev/pci/pcivar.h>
49 1.1 jmcneill #include <dev/pci/pciconf.h>
50 1.1 jmcneill
51 1.1 jmcneill #include <arm/nvidia/tegra_reg.h>
52 1.1 jmcneill #include <arm/nvidia/tegra_pciereg.h>
53 1.1 jmcneill #include <arm/nvidia/tegra_var.h>
54 1.1 jmcneill
55 1.1 jmcneill static int tegra_pcie_match(device_t, cfdata_t, void *);
56 1.1 jmcneill static void tegra_pcie_attach(device_t, device_t, void *);
57 1.1 jmcneill
58 1.1 jmcneill struct tegra_pcie_ih {
59 1.1 jmcneill int (*ih_callback)(void *);
60 1.1 jmcneill void *ih_arg;
61 1.1 jmcneill int ih_ipl;
62 1.1 jmcneill TAILQ_ENTRY(tegra_pcie_ih) ih_entry;
63 1.1 jmcneill };
64 1.1 jmcneill
65 1.1 jmcneill struct tegra_pcie_softc {
66 1.1 jmcneill device_t sc_dev;
67 1.1 jmcneill bus_dma_tag_t sc_dmat;
68 1.1 jmcneill bus_space_tag_t sc_bst;
69 1.1 jmcneill bus_space_handle_t sc_bsh_afi;
70 1.1 jmcneill bus_space_handle_t sc_bsh_a1;
71 1.1 jmcneill bus_space_handle_t sc_bsh_a2;
72 1.1 jmcneill int sc_intr;
73 1.1 jmcneill
74 1.1 jmcneill struct arm32_pci_chipset sc_pc;
75 1.1 jmcneill
76 1.1 jmcneill void *sc_ih;
77 1.1 jmcneill
78 1.1 jmcneill kmutex_t sc_lock;
79 1.1 jmcneill
80 1.1 jmcneill TAILQ_HEAD(, tegra_pcie_ih) sc_intrs;
81 1.1 jmcneill u_int sc_intrgen;
82 1.1 jmcneill };
83 1.1 jmcneill
84 1.1 jmcneill static int tegra_pcie_intr(void *);
85 1.1 jmcneill static void tegra_pcie_init(pci_chipset_tag_t, void *);
86 1.1 jmcneill static void tegra_pcie_enable(struct tegra_pcie_softc *);
87 1.1 jmcneill
88 1.1 jmcneill static void tegra_pcie_attach_hook(device_t, device_t,
89 1.1 jmcneill struct pcibus_attach_args *);
90 1.1 jmcneill static int tegra_pcie_bus_maxdevs(void *, int);
91 1.1 jmcneill static pcitag_t tegra_pcie_make_tag(void *, int, int, int);
92 1.1 jmcneill static void tegra_pcie_decompose_tag(void *, pcitag_t, int *, int *, int *);
93 1.1 jmcneill static pcireg_t tegra_pcie_conf_read(void *, pcitag_t, int);
94 1.1 jmcneill static void tegra_pcie_conf_write(void *, pcitag_t, int, pcireg_t);
95 1.1 jmcneill static int tegra_pcie_conf_hook(void *, int, int, int, pcireg_t);
96 1.1 jmcneill static void tegra_pcie_conf_interrupt(void *, int, int, int, int, int *);
97 1.1 jmcneill
98 1.1 jmcneill static int tegra_pcie_intr_map(const struct pci_attach_args *,
99 1.1 jmcneill pci_intr_handle_t *);
100 1.1 jmcneill static const char *tegra_pcie_intr_string(void *, pci_intr_handle_t,
101 1.1 jmcneill char *, size_t);
102 1.1 jmcneill const struct evcnt *tegra_pcie_intr_evcnt(void *, pci_intr_handle_t);
103 1.1 jmcneill static void * tegra_pcie_intr_establish(void *, pci_intr_handle_t,
104 1.1 jmcneill int, int (*)(void *), void *);
105 1.1 jmcneill static void tegra_pcie_intr_disestablish(void *, void *);
106 1.1 jmcneill
107 1.1 jmcneill CFATTACH_DECL_NEW(tegra_pcie, sizeof(struct tegra_pcie_softc),
108 1.1 jmcneill tegra_pcie_match, tegra_pcie_attach, NULL, NULL);
109 1.1 jmcneill
110 1.1 jmcneill static int
111 1.1 jmcneill tegra_pcie_match(device_t parent, cfdata_t cf, void *aux)
112 1.1 jmcneill {
113 1.1 jmcneill return 1;
114 1.1 jmcneill }
115 1.1 jmcneill
116 1.1 jmcneill static void
117 1.1 jmcneill tegra_pcie_attach(device_t parent, device_t self, void *aux)
118 1.1 jmcneill {
119 1.1 jmcneill struct tegra_pcie_softc * const sc = device_private(self);
120 1.1 jmcneill struct tegraio_attach_args * const tio = aux;
121 1.1 jmcneill const struct tegra_locators * const loc = &tio->tio_loc;
122 1.1 jmcneill struct extent *memext, *pmemext;
123 1.1 jmcneill struct pcibus_attach_args pba;
124 1.1 jmcneill int error;
125 1.1 jmcneill
126 1.1 jmcneill sc->sc_dev = self;
127 1.1 jmcneill sc->sc_dmat = tio->tio_coherent_dmat;
128 1.1 jmcneill sc->sc_bst = tio->tio_bst;
129 1.1 jmcneill sc->sc_intr = loc->loc_intr;
130 1.1 jmcneill if (bus_space_map(sc->sc_bst, TEGRA_PCIE_AFI_BASE, TEGRA_PCIE_AFI_SIZE,
131 1.1 jmcneill 0, &sc->sc_bsh_afi) != 0)
132 1.1 jmcneill panic("couldn't map PCIE AFI");
133 1.1 jmcneill if (bus_space_map(sc->sc_bst, TEGRA_PCIE_A1_BASE, TEGRA_PCIE_A1_SIZE,
134 1.1 jmcneill 0, &sc->sc_bsh_a1) != 0)
135 1.1 jmcneill panic("couldn't map PCIE A1");
136 1.1 jmcneill if (bus_space_map(sc->sc_bst, TEGRA_PCIE_A2_BASE, TEGRA_PCIE_A2_SIZE,
137 1.1 jmcneill 0, &sc->sc_bsh_a2) != 0)
138 1.1 jmcneill panic("couldn't map PCIE A2");
139 1.1 jmcneill
140 1.1 jmcneill TAILQ_INIT(&sc->sc_intrs);
141 1.1 jmcneill mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_VM);
142 1.1 jmcneill
143 1.1 jmcneill aprint_naive("\n");
144 1.1 jmcneill aprint_normal(": PCIE\n");
145 1.1 jmcneill
146 1.1 jmcneill sc->sc_ih = intr_establish(loc->loc_intr, IPL_VM, IST_LEVEL,
147 1.1 jmcneill tegra_pcie_intr, sc);
148 1.1 jmcneill if (sc->sc_ih == NULL) {
149 1.1 jmcneill aprint_error_dev(self, "failed to establish interrupt %d\n",
150 1.1 jmcneill loc->loc_intr);
151 1.1 jmcneill return;
152 1.1 jmcneill }
153 1.1 jmcneill aprint_normal_dev(self, "interrupting on irq %d\n", loc->loc_intr);
154 1.1 jmcneill
155 1.1 jmcneill tegra_pcie_init(&sc->sc_pc, sc);
156 1.1 jmcneill
157 1.1 jmcneill memext = extent_create("pcimem", TEGRA_PCIE_MEM_BASE,
158 1.1 jmcneill TEGRA_PCIE_MEM_BASE + TEGRA_PCIE_MEM_SIZE - 1,
159 1.1 jmcneill NULL, 0, EX_NOWAIT);
160 1.1 jmcneill pmemext = extent_create("pcipmem", TEGRA_PCIE_PMEM_BASE,
161 1.1 jmcneill TEGRA_PCIE_PMEM_BASE + TEGRA_PCIE_PMEM_SIZE - 1,
162 1.1 jmcneill NULL, 0, EX_NOWAIT);
163 1.1 jmcneill
164 1.1 jmcneill error = pci_configure_bus(&sc->sc_pc, NULL, memext, pmemext, 0,
165 1.1 jmcneill arm_dcache_align);
166 1.1 jmcneill
167 1.1 jmcneill extent_destroy(memext);
168 1.1 jmcneill extent_destroy(pmemext);
169 1.1 jmcneill
170 1.1 jmcneill if (error) {
171 1.1 jmcneill aprint_error_dev(self, "configuration failed (%d)\n",
172 1.1 jmcneill error);
173 1.1 jmcneill return;
174 1.1 jmcneill }
175 1.1 jmcneill
176 1.1 jmcneill tegra_pcie_enable(sc);
177 1.1 jmcneill
178 1.1 jmcneill memset(&pba, 0, sizeof(pba));
179 1.1 jmcneill pba.pba_flags = PCI_FLAGS_MRL_OKAY |
180 1.1 jmcneill PCI_FLAGS_MRM_OKAY |
181 1.1 jmcneill PCI_FLAGS_MWI_OKAY |
182 1.1 jmcneill PCI_FLAGS_MEM_OKAY;
183 1.1 jmcneill pba.pba_memt = sc->sc_bst;
184 1.1 jmcneill pba.pba_dmat = sc->sc_dmat;
185 1.1 jmcneill pba.pba_pc = &sc->sc_pc;
186 1.1 jmcneill pba.pba_bus = 0;
187 1.1 jmcneill
188 1.1 jmcneill config_found_ia(self, "pcibus", &pba, pcibusprint);
189 1.1 jmcneill }
190 1.1 jmcneill
191 1.1 jmcneill static int
192 1.1 jmcneill tegra_pcie_intr(void *priv)
193 1.1 jmcneill {
194 1.1 jmcneill struct tegra_pcie_softc *sc = priv;
195 1.1 jmcneill struct tegra_pcie_ih *pcie_ih;
196 1.1 jmcneill
197 1.1 jmcneill const uint32_t code = bus_space_read_4(sc->sc_bst, sc->sc_bsh_afi,
198 1.1 jmcneill AFI_INTR_CODE_REG);
199 1.1 jmcneill const uint32_t sig = bus_space_read_4(sc->sc_bst, sc->sc_bsh_afi,
200 1.1 jmcneill AFI_INTR_SIGNATURE_REG);
201 1.1 jmcneill bus_space_write_4(sc->sc_bst, sc->sc_bsh_afi, AFI_INTR_CODE_REG, 0);
202 1.1 jmcneill
203 1.1 jmcneill switch (__SHIFTOUT(code, AFI_INTR_CODE_INT_CODE)) {
204 1.1 jmcneill case AFI_INTR_CODE_SM_MSG:
205 1.1 jmcneill mutex_enter(&sc->sc_lock);
206 1.1 jmcneill const u_int lastgen = sc->sc_intrgen;
207 1.1 jmcneill TAILQ_FOREACH(pcie_ih, &sc->sc_intrs, ih_entry) {
208 1.1 jmcneill int (*callback)(void *) = pcie_ih->ih_callback;
209 1.1 jmcneill void *arg = pcie_ih->ih_arg;
210 1.1 jmcneill mutex_exit(&sc->sc_lock);
211 1.1 jmcneill const int rv = callback(arg);
212 1.1 jmcneill if (rv)
213 1.1 jmcneill return rv;
214 1.1 jmcneill mutex_enter(&sc->sc_lock);
215 1.1 jmcneill if (lastgen != sc->sc_intrgen)
216 1.1 jmcneill break;
217 1.1 jmcneill }
218 1.1 jmcneill mutex_exit(&sc->sc_lock);
219 1.1 jmcneill return 0;
220 1.1 jmcneill default:
221 1.1 jmcneill device_printf(sc->sc_dev, "intr: code %#x sig %#x\n",
222 1.1 jmcneill code, sig);
223 1.1 jmcneill return 1;
224 1.1 jmcneill }
225 1.1 jmcneill }
226 1.1 jmcneill
227 1.1 jmcneill static void
228 1.1 jmcneill tegra_pcie_enable(struct tegra_pcie_softc *sc)
229 1.1 jmcneill {
230 1.1 jmcneill bus_space_write_4(sc->sc_bst, sc->sc_bsh_afi,
231 1.1 jmcneill AFI_SM_INTR_ENABLE_REG, 0xffffffff);
232 1.1 jmcneill bus_space_write_4(sc->sc_bst, sc->sc_bsh_afi,
233 1.1 jmcneill AFI_AFI_INTR_ENABLE_REG, 0);
234 1.1 jmcneill bus_space_write_4(sc->sc_bst, sc->sc_bsh_afi, AFI_INTR_CODE_REG, 0);
235 1.1 jmcneill bus_space_write_4(sc->sc_bst, sc->sc_bsh_afi,
236 1.1 jmcneill AFI_INTR_MASK_REG, AFI_INTR_MASK_INT);
237 1.1 jmcneill }
238 1.1 jmcneill
239 1.1 jmcneill void
240 1.1 jmcneill tegra_pcie_init(pci_chipset_tag_t pc, void *priv)
241 1.1 jmcneill {
242 1.1 jmcneill pc->pc_conf_v = priv;
243 1.1 jmcneill pc->pc_attach_hook = tegra_pcie_attach_hook;
244 1.1 jmcneill pc->pc_bus_maxdevs = tegra_pcie_bus_maxdevs;
245 1.1 jmcneill pc->pc_make_tag = tegra_pcie_make_tag;
246 1.1 jmcneill pc->pc_decompose_tag = tegra_pcie_decompose_tag;
247 1.1 jmcneill pc->pc_conf_read = tegra_pcie_conf_read;
248 1.1 jmcneill pc->pc_conf_write = tegra_pcie_conf_write;
249 1.1 jmcneill pc->pc_conf_hook = tegra_pcie_conf_hook;
250 1.1 jmcneill pc->pc_conf_interrupt = tegra_pcie_conf_interrupt;
251 1.1 jmcneill
252 1.1 jmcneill pc->pc_intr_v = priv;
253 1.1 jmcneill pc->pc_intr_map = tegra_pcie_intr_map;
254 1.1 jmcneill pc->pc_intr_string = tegra_pcie_intr_string;
255 1.1 jmcneill pc->pc_intr_evcnt = tegra_pcie_intr_evcnt;
256 1.1 jmcneill pc->pc_intr_establish = tegra_pcie_intr_establish;
257 1.1 jmcneill pc->pc_intr_disestablish = tegra_pcie_intr_disestablish;
258 1.1 jmcneill }
259 1.1 jmcneill
260 1.1 jmcneill static void
261 1.1 jmcneill tegra_pcie_attach_hook(device_t parent, device_t self,
262 1.1 jmcneill struct pcibus_attach_args *pba)
263 1.1 jmcneill {
264 1.1 jmcneill }
265 1.1 jmcneill
266 1.1 jmcneill static int
267 1.1 jmcneill tegra_pcie_bus_maxdevs(void *v, int busno)
268 1.1 jmcneill {
269 1.1 jmcneill return busno == 0 ? 2 : 32;
270 1.1 jmcneill }
271 1.1 jmcneill
272 1.1 jmcneill static pcitag_t
273 1.1 jmcneill tegra_pcie_make_tag(void *v, int b, int d, int f)
274 1.1 jmcneill {
275 1.1 jmcneill return (b << 16) | (d << 11) | (f << 8);
276 1.1 jmcneill }
277 1.1 jmcneill
278 1.1 jmcneill static void
279 1.1 jmcneill tegra_pcie_decompose_tag(void *v, pcitag_t tag, int *bp, int *dp, int *fp)
280 1.1 jmcneill {
281 1.1 jmcneill if (bp)
282 1.1 jmcneill *bp = (tag >> 16) & 0xff;
283 1.1 jmcneill if (dp)
284 1.1 jmcneill *dp = (tag >> 11) & 0x1f;
285 1.1 jmcneill if (fp)
286 1.1 jmcneill *fp = (tag >> 8) & 0x7;
287 1.1 jmcneill }
288 1.1 jmcneill
289 1.1 jmcneill static pcireg_t
290 1.1 jmcneill tegra_pcie_conf_read(void *v, pcitag_t tag, int offset)
291 1.1 jmcneill {
292 1.1 jmcneill struct tegra_pcie_softc *sc = v;
293 1.1 jmcneill bus_space_handle_t bsh;
294 1.1 jmcneill int b, d, f;
295 1.1 jmcneill u_int reg;
296 1.1 jmcneill
297 1.1 jmcneill tegra_pcie_decompose_tag(v, tag, &b, &d, &f);
298 1.1 jmcneill
299 1.1 jmcneill if (b == 0) {
300 1.1 jmcneill reg = d * 0x1000 + offset;
301 1.1 jmcneill bsh = sc->sc_bsh_a1;
302 1.1 jmcneill } else {
303 1.1 jmcneill reg = tag | offset;
304 1.1 jmcneill bsh = sc->sc_bsh_a2;
305 1.1 jmcneill }
306 1.1 jmcneill
307 1.1 jmcneill return bus_space_read_4(sc->sc_bst, bsh, reg);
308 1.1 jmcneill }
309 1.1 jmcneill
310 1.1 jmcneill static void
311 1.1 jmcneill tegra_pcie_conf_write(void *v, pcitag_t tag, int offset, pcireg_t val)
312 1.1 jmcneill {
313 1.1 jmcneill struct tegra_pcie_softc *sc = v;
314 1.1 jmcneill bus_space_handle_t bsh;
315 1.1 jmcneill int b, d, f;
316 1.1 jmcneill u_int reg;
317 1.1 jmcneill
318 1.1 jmcneill tegra_pcie_decompose_tag(v, tag, &b, &d, &f);
319 1.1 jmcneill
320 1.1 jmcneill if (b == 0) {
321 1.1 jmcneill reg = d * 0x1000 + offset;
322 1.1 jmcneill bsh = sc->sc_bsh_a1;
323 1.1 jmcneill } else {
324 1.1 jmcneill reg = tag | offset;
325 1.1 jmcneill bsh = sc->sc_bsh_a2;
326 1.1 jmcneill }
327 1.1 jmcneill
328 1.1 jmcneill bus_space_write_4(sc->sc_bst, bsh, reg, val);
329 1.1 jmcneill }
330 1.1 jmcneill
331 1.1 jmcneill static int
332 1.1 jmcneill tegra_pcie_conf_hook(void *v, int b, int d, int f, pcireg_t id)
333 1.1 jmcneill {
334 1.1 jmcneill return PCI_CONF_ENABLE_MEM | PCI_CONF_MAP_MEM | PCI_CONF_ENABLE_BM;
335 1.1 jmcneill }
336 1.1 jmcneill
337 1.1 jmcneill static void
338 1.1 jmcneill tegra_pcie_conf_interrupt(void *v, int bus, int dev, int ipin, int swiz,
339 1.1 jmcneill int *ilinep)
340 1.1 jmcneill {
341 1.1 jmcneill *ilinep = 5;
342 1.1 jmcneill }
343 1.1 jmcneill
344 1.1 jmcneill static int
345 1.1 jmcneill tegra_pcie_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ih)
346 1.1 jmcneill {
347 1.1 jmcneill if (pa->pa_intrpin == 0)
348 1.1 jmcneill return EINVAL;
349 1.1 jmcneill *ih = pa->pa_intrpin;
350 1.1 jmcneill return 0;
351 1.1 jmcneill }
352 1.1 jmcneill
353 1.1 jmcneill static const char *
354 1.1 jmcneill tegra_pcie_intr_string(void *v, pci_intr_handle_t ih, char *buf, size_t len)
355 1.1 jmcneill {
356 1.1 jmcneill struct tegra_pcie_softc *sc = v;
357 1.1 jmcneill
358 1.1 jmcneill if (ih == PCI_INTERRUPT_PIN_NONE)
359 1.1 jmcneill return NULL;
360 1.1 jmcneill
361 1.1 jmcneill snprintf(buf, len, "irq %d", sc->sc_intr);
362 1.1 jmcneill return buf;
363 1.1 jmcneill }
364 1.1 jmcneill
365 1.1 jmcneill const struct evcnt *
366 1.1 jmcneill tegra_pcie_intr_evcnt(void *v, pci_intr_handle_t ih)
367 1.1 jmcneill {
368 1.1 jmcneill return NULL;
369 1.1 jmcneill }
370 1.1 jmcneill
371 1.1 jmcneill static void *
372 1.1 jmcneill tegra_pcie_intr_establish(void *v, pci_intr_handle_t ih, int ipl,
373 1.1 jmcneill int (*callback)(void *), void *arg)
374 1.1 jmcneill {
375 1.1 jmcneill struct tegra_pcie_softc *sc = v;
376 1.1 jmcneill struct tegra_pcie_ih *pcie_ih;
377 1.1 jmcneill
378 1.1 jmcneill if (ih == 0)
379 1.1 jmcneill return NULL;
380 1.1 jmcneill
381 1.1 jmcneill pcie_ih = kmem_alloc(sizeof(*pcie_ih), KM_SLEEP);
382 1.1 jmcneill pcie_ih->ih_callback = callback;
383 1.1 jmcneill pcie_ih->ih_arg = arg;
384 1.1 jmcneill pcie_ih->ih_ipl = ipl;
385 1.1 jmcneill
386 1.1 jmcneill mutex_enter(&sc->sc_lock);
387 1.1 jmcneill TAILQ_INSERT_TAIL(&sc->sc_intrs, pcie_ih, ih_entry);
388 1.1 jmcneill sc->sc_intrgen++;
389 1.1 jmcneill mutex_exit(&sc->sc_lock);
390 1.1 jmcneill
391 1.1 jmcneill return pcie_ih;
392 1.1 jmcneill }
393 1.1 jmcneill
394 1.1 jmcneill static void
395 1.1 jmcneill tegra_pcie_intr_disestablish(void *v, void *vih)
396 1.1 jmcneill {
397 1.1 jmcneill struct tegra_pcie_softc *sc = v;
398 1.1 jmcneill struct tegra_pcie_ih *pcie_ih = vih;
399 1.1 jmcneill
400 1.1 jmcneill mutex_enter(&sc->sc_lock);
401 1.1 jmcneill TAILQ_REMOVE(&sc->sc_intrs, pcie_ih, ih_entry);
402 1.1 jmcneill mutex_exit(&sc->sc_lock);
403 1.1 jmcneill
404 1.1 jmcneill kmem_free(pcie_ih, sizeof(*pcie_ih));
405 1.1 jmcneill }
406