xref: /openbsd-src/sys/arch/amd64/pci/pci_machdep.c (revision d13be5d47e4149db2549a9828e244d59dbc43f15)
1 /*	$OpenBSD: pci_machdep.c,v 1.51 2011/06/18 17:28:18 kettenis Exp $	*/
2 /*	$NetBSD: pci_machdep.c,v 1.3 2003/05/07 21:33:58 fvdl Exp $	*/
3 
4 /*-
5  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
6  * All rights reserved.
7  *
8  * This code is derived from software contributed to The NetBSD Foundation
9  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
10  * NASA Ames Research Center.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 /*
35  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
36  * Copyright (c) 1994 Charles M. Hannum.  All rights reserved.
37  *
38  * Redistribution and use in source and binary forms, with or without
39  * modification, are permitted provided that the following conditions
40  * are met:
41  * 1. Redistributions of source code must retain the above copyright
42  *    notice, this list of conditions and the following disclaimer.
43  * 2. Redistributions in binary form must reproduce the above copyright
44  *    notice, this list of conditions and the following disclaimer in the
45  *    documentation and/or other materials provided with the distribution.
46  * 3. All advertising materials mentioning features or use of this software
47  *    must display the following acknowledgement:
48  *	This product includes software developed by Charles M. Hannum.
49  * 4. The name of the author may not be used to endorse or promote products
50  *    derived from this software without specific prior written permission.
51  *
52  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
53  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
54  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
55  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
56  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
57  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
58  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
59  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
60  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
61  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62  */
63 
64 /*
65  * Machine-specific functions for PCI autoconfiguration.
66  */
67 
68 #include <sys/types.h>
69 #include <sys/param.h>
70 #include <sys/time.h>
71 #include <sys/systm.h>
72 #include <sys/errno.h>
73 #include <sys/device.h>
74 #include <sys/extent.h>
75 #include <sys/malloc.h>
76 
77 #include <uvm/uvm_extern.h>
78 
79 #include <machine/bus.h>
80 
81 #include <machine/pio.h>
82 #include <machine/intr.h>
83 #include <machine/biosvar.h>
84 
85 #include <dev/isa/isareg.h>
86 #include <dev/isa/isavar.h>
87 #include <dev/pci/pcivar.h>
88 #include <dev/pci/pcireg.h>
89 #include <dev/pci/pcidevs.h>
90 #include <dev/pci/ppbreg.h>
91 
92 #include "ioapic.h"
93 
94 #if NIOAPIC > 0
95 #include <machine/i82093var.h>
96 #include <machine/mpbiosvar.h>
97 #endif
98 
99 /*
100  * Memory Mapped Configuration space access.
101  *
102  * Since mapping the whole configuration space will cost us up to
103  * 256MB of kernel virtual memory, we use seperate mappings per bus.
104  * The mappings are created on-demand, such that we only use kernel
105  * virtual memory for busses that are actually present.
106  */
107 bus_addr_t pci_mcfg_addr;
108 int pci_mcfg_min_bus, pci_mcfg_max_bus;
109 bus_space_tag_t pci_mcfgt = X86_BUS_SPACE_MEM;
110 bus_space_handle_t pci_mcfgh[256];
111 void pci_mcfg_map_bus(int);
112 
113 struct mutex pci_conf_lock = MUTEX_INITIALIZER(IPL_HIGH);
114 
115 #define	PCI_CONF_LOCK()						\
116 do {									\
117 	mtx_enter(&pci_conf_lock);					\
118 } while (0)
119 
120 #define	PCI_CONF_UNLOCK()						\
121 do {									\
122 	mtx_leave(&pci_conf_lock);					\
123 } while (0)
124 
125 #define	PCI_MODE1_ENABLE	0x80000000UL
126 #define	PCI_MODE1_ADDRESS_REG	0x0cf8
127 #define	PCI_MODE1_DATA_REG	0x0cfc
128 
129 /*
130  * PCI doesn't have any special needs; just use the generic versions
131  * of these functions.
132  */
133 struct bus_dma_tag pci_bus_dma_tag = {
134 	NULL,			/* _may_bounce */
135 	_bus_dmamap_create,
136 	_bus_dmamap_destroy,
137 	_bus_dmamap_load,
138 	_bus_dmamap_load_mbuf,
139 	_bus_dmamap_load_uio,
140 	_bus_dmamap_load_raw,
141 	_bus_dmamap_unload,
142 	_bus_dmamap_sync,
143 	_bus_dmamem_alloc,
144 	_bus_dmamem_free,
145 	_bus_dmamem_map,
146 	_bus_dmamem_unmap,
147 	_bus_dmamem_mmap,
148 };
149 
150 void
151 pci_attach_hook(struct device *parent, struct device *self,
152     struct pcibus_attach_args *pba)
153 {
154 	pci_chipset_tag_t pc = pba->pba_pc;
155 	pcitag_t tag;
156 	pcireg_t id, class;
157 
158 	if (pba->pba_bus != 0)
159 		return;
160 
161 	/*
162 	 * In order to decide whether the system supports MSI we look
163 	 * at the host bridge, which should be device 0 function 0 on
164 	 * bus 0.  It is better to not enable MSI on systems that
165 	 * support it than the other way around, so be conservative
166 	 * here.  So we don't enable MSI if we don't find a host
167 	 * bridge there.  We also deliberately don't enable MSI on
168 	 * chipsets from low-end manifacturers like VIA and SiS.
169 	 */
170 	tag = pci_make_tag(pc, 0, 0, 0);
171 	id = pci_conf_read(pc, tag, PCI_ID_REG);
172 	class = pci_conf_read(pc, tag, PCI_CLASS_REG);
173 
174 	if (PCI_CLASS(class) != PCI_CLASS_BRIDGE ||
175 	    PCI_SUBCLASS(class) != PCI_SUBCLASS_BRIDGE_HOST)
176 		return;
177 
178 	switch (PCI_VENDOR(id)) {
179 	case PCI_VENDOR_INTEL:
180 		/*
181 		 * In the wonderful world of virtualization you can
182 		 * have the latest 64-bit AMD multicore CPU behind a
183 		 * prehistoric Intel host bridge.  Give them what they
184 		 * deserve.
185 		 */
186 		switch (PCI_PRODUCT(id)) {
187 		case PCI_PRODUCT_INTEL_82441FX:	/* QEMU */
188 		case PCI_PRODUCT_INTEL_82443BX:	/* VMWare */
189 			break;
190 		default:
191 			pba->pba_flags |= PCI_FLAGS_MSI_ENABLED;
192 			break;
193 		}
194 		break;
195 	case PCI_VENDOR_NVIDIA:
196 	case PCI_VENDOR_AMD:
197 		pba->pba_flags |= PCI_FLAGS_MSI_ENABLED;
198 		break;
199 	}
200 
201 	/*
202 	 * Don't enable MSI on a HyperTransport bus.  In order to
203 	 * determine that bus 0 is a HyperTransport bus, we look at
204 	 * device 24 function 0, which is the HyperTransport
205 	 * host/primary interface integrated on most 64-bit AMD CPUs.
206 	 * If that device has a HyperTransport capability, bus 0 must
207 	 * be a HyperTransport bus and we disable MSI.
208 	 */
209 	tag = pci_make_tag(pc, 0, 24, 0);
210 	if (pci_get_capability(pc, tag, PCI_CAP_HT, NULL, NULL))
211 		pba->pba_flags &= ~PCI_FLAGS_MSI_ENABLED;
212 }
213 
214 int
215 pci_bus_maxdevs(pci_chipset_tag_t pc, int busno)
216 {
217 	return (32);
218 }
219 
220 pcitag_t
221 pci_make_tag(pci_chipset_tag_t pc, int bus, int device, int function)
222 {
223 	if (bus >= 256 || device >= 32 || function >= 8)
224 		panic("pci_make_tag: bad request");
225 
226 	return (PCI_MODE1_ENABLE |
227 	    (bus << 16) | (device << 11) | (function << 8));
228 }
229 
230 void
231 pci_decompose_tag(pci_chipset_tag_t pc, pcitag_t tag, int *bp, int *dp, int *fp)
232 {
233 	if (bp != NULL)
234 		*bp = (tag >> 16) & 0xff;
235 	if (dp != NULL)
236 		*dp = (tag >> 11) & 0x1f;
237 	if (fp != NULL)
238 		*fp = (tag >> 8) & 0x7;
239 }
240 
241 int
242 pci_conf_size(pci_chipset_tag_t pc, pcitag_t tag)
243 {
244 	int bus;
245 
246 	if (pci_mcfg_addr) {
247 		pci_decompose_tag(pc, tag, &bus, NULL, NULL);
248 		if (bus >= pci_mcfg_min_bus && bus <= pci_mcfg_max_bus)
249 			return PCIE_CONFIG_SPACE_SIZE;
250 	}
251 
252 	return PCI_CONFIG_SPACE_SIZE;
253 }
254 
255 void
256 pci_mcfg_map_bus(int bus)
257 {
258 	if (pci_mcfgh[bus])
259 		return;
260 
261 	if (bus_space_map(pci_mcfgt, pci_mcfg_addr + (bus << 20), 1 << 20,
262 	    0, &pci_mcfgh[bus]))
263 		panic("pci_conf_read: cannot map mcfg space");
264 }
265 
266 pcireg_t
267 pci_conf_read(pci_chipset_tag_t pc, pcitag_t tag, int reg)
268 {
269 	pcireg_t data;
270 	int bus;
271 
272 	if (pci_mcfg_addr && reg >= PCI_CONFIG_SPACE_SIZE) {
273 		pci_decompose_tag(pc, tag, &bus, NULL, NULL);
274 		if (bus >= pci_mcfg_min_bus && bus <= pci_mcfg_max_bus) {
275 			pci_mcfg_map_bus(bus);
276 			data = bus_space_read_4(pci_mcfgt, pci_mcfgh[bus],
277 			    (tag & 0x000ff00) << 4 | reg);
278 			return data;
279 		}
280 	}
281 
282 	PCI_CONF_LOCK();
283 	outl(PCI_MODE1_ADDRESS_REG, tag | reg);
284 	data = inl(PCI_MODE1_DATA_REG);
285 	outl(PCI_MODE1_ADDRESS_REG, 0);
286 	PCI_CONF_UNLOCK();
287 
288 	return data;
289 }
290 
291 void
292 pci_conf_write(pci_chipset_tag_t pc, pcitag_t tag, int reg, pcireg_t data)
293 {
294 	int bus;
295 
296 	if (pci_mcfg_addr && reg >= PCI_CONFIG_SPACE_SIZE) {
297 		pci_decompose_tag(pc, tag, &bus, NULL, NULL);
298 		if (bus >= pci_mcfg_min_bus && bus <= pci_mcfg_max_bus) {
299 			pci_mcfg_map_bus(bus);
300 			bus_space_write_4(pci_mcfgt, pci_mcfgh[bus],
301 			    (tag & 0x000ff00) << 4 | reg, data);
302 			return;
303 		}
304 	}
305 
306 	PCI_CONF_LOCK();
307 	outl(PCI_MODE1_ADDRESS_REG, tag | reg);
308 	outl(PCI_MODE1_DATA_REG, data);
309 	outl(PCI_MODE1_ADDRESS_REG, 0);
310 	PCI_CONF_UNLOCK();
311 }
312 
313 void msi_hwmask(struct pic *, int);
314 void msi_hwunmask(struct pic *, int);
315 void msi_addroute(struct pic *, struct cpu_info *, int, int, int);
316 void msi_delroute(struct pic *, struct cpu_info *, int, int, int);
317 
318 struct pic msi_pic = {
319 	{0, {NULL}, NULL, 0, "msi", NULL, 0, 0},
320 	PIC_MSI,
321 #ifdef MULTIPROCESSOR
322 	{},
323 #endif
324 	msi_hwmask,
325 	msi_hwunmask,
326 	msi_addroute,
327 	msi_delroute,
328 	NULL,
329 	ioapic_edge_stubs
330 };
331 
332 void
333 msi_hwmask(struct pic *pic, int pin)
334 {
335 }
336 
337 void
338 msi_hwunmask(struct pic *pic, int pin)
339 {
340 }
341 
342 void
343 msi_addroute(struct pic *pic, struct cpu_info *ci, int pin, int vec, int type)
344 {
345 	pci_chipset_tag_t pc = NULL; /* XXX */
346 	pcitag_t tag = pin;
347 	pcireg_t reg, addr;
348 	int off;
349 
350 	if (pci_get_capability(pc, tag, PCI_CAP_MSI, &off, &reg) == 0)
351 		panic("%s: no msi capability", __func__);
352 
353 	addr = 0xfee00000UL | (ci->ci_apicid << 12);
354 
355 	if (reg & PCI_MSI_MC_C64) {
356 		pci_conf_write(pc, tag, off + PCI_MSI_MA, addr);
357 		pci_conf_write(pc, tag, off + PCI_MSI_MAU32, 0);
358 		pci_conf_write(pc, tag, off + PCI_MSI_MD64, vec);
359 	} else {
360 		pci_conf_write(pc, tag, off + PCI_MSI_MA, addr);
361 		pci_conf_write(pc, tag, off + PCI_MSI_MD32, vec);
362 	}
363 	pci_conf_write(pc, tag, off, reg | PCI_MSI_MC_MSIE);
364 }
365 
366 void
367 msi_delroute(struct pic *pic, struct cpu_info *ci, int pin, int vec, int type)
368 {
369 	pci_chipset_tag_t pc = NULL; /* XXX */
370 	pcitag_t tag = pin;
371 	pcireg_t reg;
372 	int off;
373 
374 	if (pci_get_capability(pc, tag, PCI_CAP_MSI, &off, &reg) == 0)
375 		panic("%s: no msi capability", __func__);
376 	pci_conf_write(pc, tag, off, reg & ~PCI_MSI_MC_MSIE);
377 }
378 
379 int
380 pci_intr_map_msi(struct pci_attach_args *pa, pci_intr_handle_t *ihp)
381 {
382 	pci_chipset_tag_t pc = pa->pa_pc;
383 	pcitag_t tag = pa->pa_tag;
384 
385 	if ((pa->pa_flags & PCI_FLAGS_MSI_ENABLED) == 0 || mp_busses == NULL ||
386 	    pci_get_capability(pc, tag, PCI_CAP_MSI, NULL, NULL) == 0)
387 		return 1;
388 
389 	ihp->tag = tag;
390 	ihp->line = APIC_INT_VIA_MSG;
391 	ihp->pin = 0;
392 	return 0;
393 }
394 
395 int
396 pci_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp)
397 {
398 	int pin = pa->pa_rawintrpin;
399 	int line = pa->pa_intrline;
400 #if NIOAPIC > 0
401 	int bus, dev, func;
402 	int mppin;
403 #endif
404 
405 	if (pin == 0) {
406 		/* No IRQ used. */
407 		goto bad;
408 	}
409 
410 	if (pin > PCI_INTERRUPT_PIN_MAX) {
411 		printf("pci_intr_map: bad interrupt pin %d\n", pin);
412 		goto bad;
413 	}
414 
415 	ihp->tag = pa->pa_tag;
416 	ihp->line = line;
417 	ihp->pin = pin;
418 
419 #if NIOAPIC > 0
420 	pci_decompose_tag(pa->pa_pc, pa->pa_tag, &bus, &dev, &func);
421 	if (mp_busses != NULL) {
422 		mppin = (dev << 2)|(pin - 1);
423 		if (intr_find_mpmapping(bus, mppin, &ihp->line) == 0) {
424 			ihp->line |= line;
425 			return 0;
426 		}
427 		if (pa->pa_bridgetag) {
428 			int swizpin = PPB_INTERRUPT_SWIZZLE(pin, dev);
429 			if (pa->pa_bridgeih[swizpin - 1].line != -1) {
430 				ihp->line = pa->pa_bridgeih[swizpin - 1].line;
431 				ihp->line |= line;
432 				return 0;
433 			}
434 		}
435 		/*
436 		 * No explicit PCI mapping found. This is not fatal,
437 		 * we'll try the ISA (or possibly EISA) mappings next.
438 		 */
439 	}
440 #endif
441 
442 	/*
443 	 * Section 6.2.4, `Miscellaneous Functions', says that 255 means
444 	 * `unknown' or `no connection' on a PC.  We assume that a device with
445 	 * `no connection' either doesn't have an interrupt (in which case the
446 	 * pin number should be 0, and would have been noticed above), or
447 	 * wasn't configured by the BIOS (in which case we punt, since there's
448 	 * no real way we can know how the interrupt lines are mapped in the
449 	 * hardware).
450 	 *
451 	 * XXX
452 	 * Since IRQ 0 is only used by the clock, and we can't actually be sure
453 	 * that the BIOS did its job, we also recognize that as meaning that
454 	 * the BIOS has not configured the device.
455 	 */
456 	if (line == 0 || line == X86_PCI_INTERRUPT_LINE_NO_CONNECTION)
457 		goto bad;
458 
459 	if (line >= NUM_LEGACY_IRQS) {
460 		printf("pci_intr_map: bad interrupt line %d\n", line);
461 		goto bad;
462 	}
463 	if (line == 2) {
464 		printf("pci_intr_map: changed line 2 to line 9\n");
465 		line = 9;
466 	}
467 
468 #if NIOAPIC > 0
469 	if (mp_busses != NULL) {
470 		if (mp_isa_bus != NULL &&
471 		    intr_find_mpmapping(mp_isa_bus->mb_idx, line, &ihp->line) == 0) {
472 			ihp->line |= line;
473 			return 0;
474 		}
475 #if NEISA > 0
476 		if (mp_eisa_bus != NULL &&
477 		    intr_find_mpmapping(mp_eisa_bus->mb_idx, line, &ihp->line) == 0) {
478 			ihp->line |= line;
479 			return 0;
480 		}
481 #endif
482 		printf("pci_intr_map: bus %d dev %d func %d pin %d; line %d\n",
483 		    bus, dev, func, pin, line);
484 		printf("pci_intr_map: no MP mapping found\n");
485 	}
486 #endif
487 
488 	return 0;
489 
490 bad:
491 	ihp->line = -1;
492 	return 1;
493 }
494 
495 const char *
496 pci_intr_string(pci_chipset_tag_t pc, pci_intr_handle_t ih)
497 {
498 	static char irqstr[64];
499 
500 	if (ih.line == 0)
501 		panic("pci_intr_string: bogus handle 0x%x", ih.line);
502 
503 	if (ih.line & APIC_INT_VIA_MSG)
504 		return ("msi");
505 
506 #if NIOAPIC > 0
507 	if (ih.line & APIC_INT_VIA_APIC)
508 		snprintf(irqstr, sizeof(irqstr), "apic %d int %d",
509 		    APIC_IRQ_APIC(ih.line), APIC_IRQ_PIN(ih.line));
510 	else
511 		snprintf(irqstr, sizeof(irqstr), "irq %d",
512 		    pci_intr_line(pc, ih));
513 #else
514 	snprintf(irqstr, sizeof(irqstr), "irq %d", pci_intr_line(pc, ih));
515 #endif
516 	return (irqstr);
517 }
518 
519 #include "acpiprt.h"
520 #if NACPIPRT > 0
521 void	acpiprt_route_interrupt(int bus, int dev, int pin);
522 #endif
523 
524 void *
525 pci_intr_establish(pci_chipset_tag_t pc, pci_intr_handle_t ih, int level,
526     int (*func)(void *), void *arg, const char *what)
527 {
528 	int pin, irq;
529 	int bus, dev;
530 	pcitag_t tag = ih.tag;
531 	struct pic *pic;
532 
533 	if (ih.line & APIC_INT_VIA_MSG) {
534 		return intr_establish(-1, &msi_pic, tag, IST_PULSE, level,
535 		    func, arg, what);
536 	}
537 
538 	pci_decompose_tag(pc, ih.tag, &bus, &dev, NULL);
539 #if NACPIPRT > 0
540 	acpiprt_route_interrupt(bus, dev, ih.pin);
541 #endif
542 
543 	pic = &i8259_pic;
544 	pin = irq = ih.line;
545 
546 #if NIOAPIC > 0
547 	if (ih.line & APIC_INT_VIA_APIC) {
548 		pic = (struct pic *)ioapic_find(APIC_IRQ_APIC(ih.line));
549 		if (pic == NULL) {
550 			printf("pci_intr_establish: bad ioapic %d\n",
551 			    APIC_IRQ_APIC(ih.line));
552 			return NULL;
553 		}
554 		pin = APIC_IRQ_PIN(ih.line);
555 		irq = APIC_IRQ_LEGACY_IRQ(ih.line);
556 		if (irq < 0 || irq >= NUM_LEGACY_IRQS)
557 			irq = -1;
558 	}
559 #endif
560 
561 	return intr_establish(irq, pic, pin, IST_LEVEL, level, func, arg, what);
562 }
563 
564 void
565 pci_intr_disestablish(pci_chipset_tag_t pc, void *cookie)
566 {
567 	intr_disestablish(cookie);
568 }
569 
570 struct extent *pciio_ex;
571 struct extent *pcimem_ex;
572 
573 void
574 pci_init_extents(void)
575 {
576 	bios_memmap_t *bmp;
577 	u_int64_t size;
578 
579 	if (pciio_ex == NULL) {
580 		/*
581 		 * We only have 64K of addressable I/O space.
582 		 * However, since BARs may contain garbage, we cover
583 		 * the full 32-bit address space defined by PCI of
584 		 * which we only make the first 64K available.
585 		 */
586 		pciio_ex = extent_create("pciio", 0, 0xffffffff, M_DEVBUF,
587 		    NULL, 0, EX_NOWAIT | EX_FILLED);
588 		if (pciio_ex == NULL)
589 			return;
590 		extent_free(pciio_ex, 0, 0x10000, M_NOWAIT);
591 	}
592 
593 	if (pcimem_ex == NULL) {
594 		/*
595 		 * Cover the 36-bit address space addressable by PAE
596 		 * here.  As long as vendors continue to support
597 		 * 32-bit operating systems, we should never see BARs
598 		 * outside that region.
599 		 */
600 		pcimem_ex = extent_create("pcimem", 0, 0xfffffffff, M_DEVBUF,
601 		    NULL, 0, EX_NOWAIT);
602 		if (pcimem_ex == NULL)
603 			return;
604 
605 		for (bmp = bios_memmap; bmp->type != BIOS_MAP_END; bmp++) {
606 			/*
607 			 * Ignore address space beyond 4G.
608 			 */
609 			if (bmp->addr >= 0x100000000ULL)
610 				continue;
611 			size = bmp->size;
612 			if (bmp->addr + size >= 0x100000000ULL)
613 				size = 0x100000000ULL - bmp->addr;
614 
615 			/* Ignore zero-sized regions. */
616 			if (size == 0)
617 				continue;
618 
619 			if (extent_alloc_region(pcimem_ex, bmp->addr, size,
620 			    EX_NOWAIT))
621 				printf("memory map conflict 0x%llx/0x%llx\n",
622 				    bmp->addr, bmp->size);
623 		}
624 
625 		/* Take out the video buffer area and BIOS areas. */
626 		extent_alloc_region(pcimem_ex, IOM_BEGIN, IOM_SIZE,
627 		    EX_CONFLICTOK | EX_NOWAIT);
628 	}
629 }
630 
631 #include "acpi.h"
632 #if NACPI > 0
633 void acpi_pci_match(struct device *, struct pci_attach_args *);
634 #endif
635 
636 void
637 pci_dev_postattach(struct device *dev, struct pci_attach_args *pa)
638 {
639 #if NACPI > 0
640 	acpi_pci_match(dev, pa);
641 #endif
642 }
643