2 * Copyright (c) 1997, Stefan Esser <se@freebsd.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice unmodified, this list of conditions, and the following
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.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 * $FreeBSD: src/sys/pci/pci.c,v 1.141.2.15 2002/04/30 17:48:18 tmm Exp $
27 * $DragonFly: src/sys/bus/pci/pci.c,v 1.17 2004/02/21 06:37:05 dillon Exp $
34 #include "opt_simos.h"
35 #include "opt_compat_oldpci.h"
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/malloc.h>
40 #include <sys/module.h>
41 #include <sys/fcntl.h>
43 #include <sys/kernel.h>
44 #include <sys/queue.h>
45 #include <sys/types.h>
50 #include <vm/vm_extern.h>
53 #include <machine/bus.h>
55 #include <machine/resource.h>
56 #include <machine/md_var.h> /* For the Alpha */
58 #include <bus/pci/i386/pci_cfgreg.h>
61 #include <sys/pciio.h>
64 #include "pci_private.h"
69 #include <machine/rpb.h>
73 #include <machine/smp.h>
76 devclass_t pci_devclass;
78 static void pci_read_extcap(device_t dev, pcicfgregs *cfg);
81 u_int32_t devid; /* Vendor/device of the card */
83 #define PCI_QUIRK_MAP_REG 1 /* PCI map register in weird place */
88 struct pci_quirk pci_quirks[] = {
90 * The Intel 82371AB and 82443MX has a map register at offset 0x90.
92 { 0x71138086, PCI_QUIRK_MAP_REG, 0x90, 0 },
93 { 0x719b8086, PCI_QUIRK_MAP_REG, 0x90, 0 },
98 /* map register information */
99 #define PCI_MAPMEM 0x01 /* memory map */
100 #define PCI_MAPMEMP 0x02 /* prefetchable memory map */
101 #define PCI_MAPPORT 0x04 /* port map */
103 static STAILQ_HEAD(devlist, pci_devinfo) pci_devq;
104 u_int32_t pci_numdevs = 0;
105 static u_int32_t pci_generation = 0;
108 pci_find_bsf (u_int8_t bus, u_int8_t slot, u_int8_t func)
110 struct pci_devinfo *dinfo;
112 STAILQ_FOREACH(dinfo, &pci_devq, pci_links) {
113 if ((dinfo->cfg.bus == bus) &&
114 (dinfo->cfg.slot == slot) &&
115 (dinfo->cfg.func == func)) {
116 return (dinfo->cfg.dev);
124 pci_find_device (u_int16_t vendor, u_int16_t device)
126 struct pci_devinfo *dinfo;
128 STAILQ_FOREACH(dinfo, &pci_devq, pci_links) {
129 if ((dinfo->cfg.vendor == vendor) &&
130 (dinfo->cfg.device == device)) {
131 return (dinfo->cfg.dev);
138 /* return base address of memory or port map */
141 pci_mapbase(unsigned mapreg)
144 if ((mapreg & 0x01) == 0)
146 return (mapreg & ~mask);
149 /* return map type of memory or port map */
152 pci_maptype(unsigned mapreg)
154 static u_int8_t maptype[0x10] = {
155 PCI_MAPMEM, PCI_MAPPORT,
157 PCI_MAPMEM, PCI_MAPPORT,
159 PCI_MAPMEM|PCI_MAPMEMP, PCI_MAPPORT,
160 PCI_MAPMEM|PCI_MAPMEMP, 0,
161 PCI_MAPMEM|PCI_MAPMEMP, PCI_MAPPORT,
165 return maptype[mapreg & 0x0f];
168 /* return log2 of map size decoded for memory or port map */
171 pci_mapsize(unsigned testval)
175 testval = pci_mapbase(testval);
178 while ((testval & 1) == 0)
187 /* return log2 of address range supported by map register */
190 pci_maprange(unsigned mapreg)
193 switch (mapreg & 0x07) {
209 /* adjust some values from PCI 1.0 devices to match 2.0 standards ... */
212 pci_fixancient(pcicfgregs *cfg)
214 if (cfg->hdrtype != 0)
217 /* PCI to PCI bridges use header type 1 */
218 if (cfg->baseclass == PCIC_BRIDGE && cfg->subclass == PCIS_BRIDGE_PCI)
222 /* read config data specific to header type 1 device (PCI to PCI bridge) */
225 pci_readppb(device_t pcib, int b, int s, int f)
229 p = malloc(sizeof (pcih1cfgregs), M_DEVBUF, M_WAITOK | M_ZERO);
233 p->secstat = PCIB_READ_CONFIG(pcib, b, s, f, PCIR_SECSTAT_1, 2);
234 p->bridgectl = PCIB_READ_CONFIG(pcib, b, s, f, PCIR_BRIDGECTL_1, 2);
236 p->seclat = PCIB_READ_CONFIG(pcib, b, s, f, PCIR_SECLAT_1, 1);
238 p->iobase = PCI_PPBIOBASE (PCIB_READ_CONFIG(pcib, b, s, f,
240 PCIB_READ_CONFIG(pcib, b, s, f,
242 p->iolimit = PCI_PPBIOLIMIT (PCIB_READ_CONFIG(pcib, b, s, f,
244 PCIB_READ_CONFIG(pcib, b, s, f,
245 PCIR_IOLIMITL_1, 1));
247 p->membase = PCI_PPBMEMBASE (0,
248 PCIB_READ_CONFIG(pcib, b, s, f,
250 p->memlimit = PCI_PPBMEMLIMIT (0,
251 PCIB_READ_CONFIG(pcib, b, s, f,
252 PCIR_MEMLIMIT_1, 2));
254 p->pmembase = PCI_PPBMEMBASE (
255 (pci_addr_t)PCIB_READ_CONFIG(pcib, b, s, f, PCIR_PMBASEH_1, 4),
256 PCIB_READ_CONFIG(pcib, b, s, f, PCIR_PMBASEL_1, 2));
258 p->pmemlimit = PCI_PPBMEMLIMIT (
259 (pci_addr_t)PCIB_READ_CONFIG(pcib, b, s, f,
261 PCIB_READ_CONFIG(pcib, b, s, f, PCIR_PMLIMITL_1, 2));
266 /* read config data specific to header type 2 device (PCI to CardBus bridge) */
269 pci_readpcb(device_t pcib, int b, int s, int f)
273 p = malloc(sizeof (pcih2cfgregs), M_DEVBUF, M_WAITOK | M_ZERO);
277 p->secstat = PCIB_READ_CONFIG(pcib, b, s, f, PCIR_SECSTAT_2, 2);
278 p->bridgectl = PCIB_READ_CONFIG(pcib, b, s, f, PCIR_BRIDGECTL_2, 2);
280 p->seclat = PCIB_READ_CONFIG(pcib, b, s, f, PCIR_SECLAT_2, 1);
282 p->membase0 = PCIB_READ_CONFIG(pcib, b, s, f, PCIR_MEMBASE0_2, 4);
283 p->memlimit0 = PCIB_READ_CONFIG(pcib, b, s, f, PCIR_MEMLIMIT0_2, 4);
284 p->membase1 = PCIB_READ_CONFIG(pcib, b, s, f, PCIR_MEMBASE1_2, 4);
285 p->memlimit1 = PCIB_READ_CONFIG(pcib, b, s, f, PCIR_MEMLIMIT1_2, 4);
287 p->iobase0 = PCIB_READ_CONFIG(pcib, b, s, f, PCIR_IOBASE0_2, 4);
288 p->iolimit0 = PCIB_READ_CONFIG(pcib, b, s, f, PCIR_IOLIMIT0_2, 4);
289 p->iobase1 = PCIB_READ_CONFIG(pcib, b, s, f, PCIR_IOBASE1_2, 4);
290 p->iolimit1 = PCIB_READ_CONFIG(pcib, b, s, f, PCIR_IOLIMIT1_2, 4);
292 p->pccardif = PCIB_READ_CONFIG(pcib, b, s, f, PCIR_PCCARDIF_2, 4);
296 /* extract header type specific config data */
299 pci_hdrtypedata(device_t pcib, int b, int s, int f, pcicfgregs *cfg)
301 #define REG(n,w) PCIB_READ_CONFIG(pcib, b, s, f, n, w)
302 switch (cfg->hdrtype) {
304 cfg->subvendor = REG(PCIR_SUBVEND_0, 2);
305 cfg->subdevice = REG(PCIR_SUBDEV_0, 2);
306 cfg->nummaps = PCI_MAXMAPS_0;
309 cfg->subvendor = REG(PCIR_SUBVEND_1, 2);
310 cfg->subdevice = REG(PCIR_SUBDEV_1, 2);
311 cfg->secondarybus = REG(PCIR_SECBUS_1, 1);
312 cfg->subordinatebus = REG(PCIR_SUBBUS_1, 1);
313 cfg->nummaps = PCI_MAXMAPS_1;
314 cfg->hdrspec = pci_readppb(pcib, b, s, f);
317 cfg->subvendor = REG(PCIR_SUBVEND_2, 2);
318 cfg->subdevice = REG(PCIR_SUBDEV_2, 2);
319 cfg->secondarybus = REG(PCIR_SECBUS_2, 1);
320 cfg->subordinatebus = REG(PCIR_SUBBUS_2, 1);
321 cfg->nummaps = PCI_MAXMAPS_2;
322 cfg->hdrspec = pci_readpcb(pcib, b, s, f);
328 /* read configuration header into pcicfgrect structure */
331 pci_read_device(device_t pcib, int b, int s, int f, int width)
333 #define REG(n, w) PCIB_READ_CONFIG(pcib, b, s, f, n, w)
335 pcicfgregs *cfg = NULL;
336 struct pci_devinfo *devlist_entry;
337 struct devlist *devlist_head;
339 devlist_head = &pci_devq;
341 devlist_entry = NULL;
343 if (PCIB_READ_CONFIG(pcib, b, s, f, PCIR_DEVVENDOR, 4) != -1) {
345 devlist_entry = malloc(width,
346 M_DEVBUF, M_WAITOK | M_ZERO);
347 if (devlist_entry == NULL)
350 cfg = &devlist_entry->cfg;
355 cfg->vendor = REG(PCIR_VENDOR, 2);
356 cfg->device = REG(PCIR_DEVICE, 2);
357 cfg->cmdreg = REG(PCIR_COMMAND, 2);
358 cfg->statreg = REG(PCIR_STATUS, 2);
359 cfg->baseclass = REG(PCIR_CLASS, 1);
360 cfg->subclass = REG(PCIR_SUBCLASS, 1);
361 cfg->progif = REG(PCIR_PROGIF, 1);
362 cfg->revid = REG(PCIR_REVID, 1);
363 cfg->hdrtype = REG(PCIR_HDRTYPE, 1);
364 cfg->cachelnsz = REG(PCIR_CACHELNSZ, 1);
365 cfg->lattimer = REG(PCIR_LATTIMER, 1);
366 cfg->intpin = REG(PCIR_INTPIN, 1);
367 cfg->intline = REG(PCIR_INTLINE, 1);
369 alpha_platform_assign_pciintr(cfg);
373 if (cfg->intpin != 0) {
376 airq = pci_apic_irq(cfg->bus, cfg->slot, cfg->intpin);
378 /* PCI specific entry found in MP table */
379 if (airq != cfg->intline) {
380 undirect_pci_irq(cfg->intline);
385 * PCI interrupts might be redirected to the
386 * ISA bus according to some MP tables. Use the
387 * same methods as used by the ISA devices
388 * devices to find the proper IOAPIC int pin.
390 airq = isa_apic_irq(cfg->intline);
391 if ((airq >= 0) && (airq != cfg->intline)) {
392 /* XXX: undirect_pci_irq() ? */
393 undirect_isa_irq(cfg->intline);
400 cfg->mingnt = REG(PCIR_MINGNT, 1);
401 cfg->maxlat = REG(PCIR_MAXLAT, 1);
403 cfg->mfdev = (cfg->hdrtype & PCIM_MFDEV) != 0;
404 cfg->hdrtype &= ~PCIM_MFDEV;
407 pci_hdrtypedata(pcib, b, s, f, cfg);
409 if (REG(PCIR_STATUS, 2) & PCIM_STATUS_CAPPRESENT)
410 pci_read_extcap(pcib, cfg);
412 STAILQ_INSERT_TAIL(devlist_head, devlist_entry, pci_links);
414 devlist_entry->conf.pc_sel.pc_bus = cfg->bus;
415 devlist_entry->conf.pc_sel.pc_dev = cfg->slot;
416 devlist_entry->conf.pc_sel.pc_func = cfg->func;
417 devlist_entry->conf.pc_hdr = cfg->hdrtype;
419 devlist_entry->conf.pc_subvendor = cfg->subvendor;
420 devlist_entry->conf.pc_subdevice = cfg->subdevice;
421 devlist_entry->conf.pc_vendor = cfg->vendor;
422 devlist_entry->conf.pc_device = cfg->device;
424 devlist_entry->conf.pc_class = cfg->baseclass;
425 devlist_entry->conf.pc_subclass = cfg->subclass;
426 devlist_entry->conf.pc_progif = cfg->progif;
427 devlist_entry->conf.pc_revid = cfg->revid;
432 return (devlist_entry);
437 pci_read_extcap(device_t pcib, pcicfgregs *cfg)
439 #define REG(n, w) PCIB_READ_CONFIG(pcib, cfg->bus, cfg->slot, cfg->func, n, w)
440 int ptr, nextptr, ptrptr;
442 switch (cfg->hdrtype) {
450 return; /* no extended capabilities support */
452 nextptr = REG(ptrptr, 1); /* sanity check? */
455 * Read capability entries.
457 while (nextptr != 0) {
460 printf("illegal PCI extended capability offset %d\n",
464 /* Find the next entry */
466 nextptr = REG(ptr + 1, 1);
468 /* Process this entry */
469 switch (REG(ptr, 1)) {
470 case 0x01: /* PCI power management */
471 if (cfg->pp_cap == 0) {
472 cfg->pp_cap = REG(ptr + PCIR_POWER_CAP, 2);
473 cfg->pp_status = ptr + PCIR_POWER_STATUS;
474 cfg->pp_pmcsr = ptr + PCIR_POWER_PMCSR;
475 if ((nextptr - ptr) > PCIR_POWER_DATA)
476 cfg->pp_data = ptr + PCIR_POWER_DATA;
486 /* free pcicfgregs structure and all depending data structures */
489 pci_freecfg(struct pci_devinfo *dinfo)
491 struct devlist *devlist_head;
493 devlist_head = &pci_devq;
495 if (dinfo->cfg.hdrspec != NULL)
496 free(dinfo->cfg.hdrspec, M_DEVBUF);
497 /* XXX this hasn't been tested */
498 STAILQ_REMOVE(devlist_head, dinfo, pci_devinfo, pci_links);
499 free(dinfo, M_DEVBUF);
501 /* increment the generation count */
504 /* we're losing one device */
511 * PCI power manangement
514 pci_set_powerstate_method(device_t dev, device_t child, int state)
516 struct pci_devinfo *dinfo = device_get_ivars(child);
517 pcicfgregs *cfg = &dinfo->cfg;
521 if (cfg->pp_cap != 0) {
522 status = PCI_READ_CONFIG(dev, child, cfg->pp_status, 2) & ~PCIM_PSTAT_DMASK;
525 case PCI_POWERSTATE_D0:
526 status |= PCIM_PSTAT_D0;
528 case PCI_POWERSTATE_D1:
529 if (cfg->pp_cap & PCIM_PCAP_D1SUPP) {
530 status |= PCIM_PSTAT_D1;
535 case PCI_POWERSTATE_D2:
536 if (cfg->pp_cap & PCIM_PCAP_D2SUPP) {
537 status |= PCIM_PSTAT_D2;
542 case PCI_POWERSTATE_D3:
543 status |= PCIM_PSTAT_D3;
549 PCI_WRITE_CONFIG(dev, child, cfg->pp_status, status, 2);
557 pci_get_powerstate_method(device_t dev, device_t child)
559 struct pci_devinfo *dinfo = device_get_ivars(child);
560 pcicfgregs *cfg = &dinfo->cfg;
564 if (cfg->pp_cap != 0) {
565 status = PCI_READ_CONFIG(dev, child, cfg->pp_status, 2);
566 switch (status & PCIM_PSTAT_DMASK) {
568 result = PCI_POWERSTATE_D0;
571 result = PCI_POWERSTATE_D1;
574 result = PCI_POWERSTATE_D2;
577 result = PCI_POWERSTATE_D3;
580 result = PCI_POWERSTATE_UNKNOWN;
584 /* No support, device is always at D0 */
585 result = PCI_POWERSTATE_D0;
591 * Some convenience functions for PCI device drivers.
595 pci_set_command_bit(device_t dev, device_t child, u_int16_t bit)
599 command = PCI_READ_CONFIG(dev, child, PCIR_COMMAND, 2);
601 PCI_WRITE_CONFIG(dev, child, PCIR_COMMAND, command, 2);
605 pci_clear_command_bit(device_t dev, device_t child, u_int16_t bit)
609 command = PCI_READ_CONFIG(dev, child, PCIR_COMMAND, 2);
611 PCI_WRITE_CONFIG(dev, child, PCIR_COMMAND, command, 2);
615 pci_enable_busmaster_method(device_t dev, device_t child)
617 pci_set_command_bit(dev, child, PCIM_CMD_BUSMASTEREN);
622 pci_disable_busmaster_method(device_t dev, device_t child)
624 pci_clear_command_bit(dev, child, PCIM_CMD_BUSMASTEREN);
629 pci_enable_io_method(device_t dev, device_t child, int space)
640 bit = PCIM_CMD_PORTEN;
644 bit = PCIM_CMD_MEMEN;
650 pci_set_command_bit(dev, child, bit);
651 command = PCI_READ_CONFIG(dev, child, PCIR_COMMAND, 2);
654 device_printf(child, "failed to enable %s mapping!\n", error);
659 pci_disable_io_method(device_t dev, device_t child, int space)
670 bit = PCIM_CMD_PORTEN;
674 bit = PCIM_CMD_MEMEN;
680 pci_clear_command_bit(dev, child, bit);
681 command = PCI_READ_CONFIG(dev, child, PCIR_COMMAND, 2);
683 device_printf(child, "failed to disable %s mapping!\n", error);
690 * This is the user interface to PCI configuration space.
694 pci_open(dev_t dev, int oflags, int devtype, struct thread *td)
696 if ((oflags & FWRITE) && securelevel > 0) {
703 pci_close(dev_t dev, int flag, int devtype, struct thread *td)
709 * Match a single pci_conf structure against an array of pci_match_conf
710 * structures. The first argument, 'matches', is an array of num_matches
711 * pci_match_conf structures. match_buf is a pointer to the pci_conf
712 * structure that will be compared to every entry in the matches array.
713 * This function returns 1 on failure, 0 on success.
716 pci_conf_match(struct pci_match_conf *matches, int num_matches,
717 struct pci_conf *match_buf)
721 if ((matches == NULL) || (match_buf == NULL) || (num_matches <= 0))
724 for (i = 0; i < num_matches; i++) {
726 * I'm not sure why someone would do this...but...
728 if (matches[i].flags == PCI_GETCONF_NO_MATCH)
732 * Look at each of the match flags. If it's set, do the
733 * comparison. If the comparison fails, we don't have a
734 * match, go on to the next item if there is one.
736 if (((matches[i].flags & PCI_GETCONF_MATCH_BUS) != 0)
737 && (match_buf->pc_sel.pc_bus != matches[i].pc_sel.pc_bus))
740 if (((matches[i].flags & PCI_GETCONF_MATCH_DEV) != 0)
741 && (match_buf->pc_sel.pc_dev != matches[i].pc_sel.pc_dev))
744 if (((matches[i].flags & PCI_GETCONF_MATCH_FUNC) != 0)
745 && (match_buf->pc_sel.pc_func != matches[i].pc_sel.pc_func))
748 if (((matches[i].flags & PCI_GETCONF_MATCH_VENDOR) != 0)
749 && (match_buf->pc_vendor != matches[i].pc_vendor))
752 if (((matches[i].flags & PCI_GETCONF_MATCH_DEVICE) != 0)
753 && (match_buf->pc_device != matches[i].pc_device))
756 if (((matches[i].flags & PCI_GETCONF_MATCH_CLASS) != 0)
757 && (match_buf->pc_class != matches[i].pc_class))
760 if (((matches[i].flags & PCI_GETCONF_MATCH_UNIT) != 0)
761 && (match_buf->pd_unit != matches[i].pd_unit))
764 if (((matches[i].flags & PCI_GETCONF_MATCH_NAME) != 0)
765 && (strncmp(matches[i].pd_name, match_buf->pd_name,
766 sizeof(match_buf->pd_name)) != 0))
776 * Locate the parent of a PCI device by scanning the PCI devlist
777 * and return the entry for the parent.
778 * For devices on PCI Bus 0 (the host bus), this is the PCI Host.
779 * For devices on secondary PCI busses, this is that bus' PCI-PCI Bridge.
783 pci_devlist_get_parent(pcicfgregs *cfg)
785 struct devlist *devlist_head;
786 struct pci_devinfo *dinfo;
787 pcicfgregs *bridge_cfg;
790 dinfo = STAILQ_FIRST(devlist_head = &pci_devq);
792 /* If the device is on PCI bus 0, look for the host */
794 for (i = 0; (dinfo != NULL) && (i < pci_numdevs);
795 dinfo = STAILQ_NEXT(dinfo, pci_links), i++) {
796 bridge_cfg = &dinfo->cfg;
797 if (bridge_cfg->baseclass == PCIC_BRIDGE
798 && bridge_cfg->subclass == PCIS_BRIDGE_HOST
799 && bridge_cfg->bus == cfg->bus) {
805 /* If the device is not on PCI bus 0, look for the PCI-PCI bridge */
807 for (i = 0; (dinfo != NULL) && (i < pci_numdevs);
808 dinfo = STAILQ_NEXT(dinfo, pci_links), i++) {
809 bridge_cfg = &dinfo->cfg;
810 if (bridge_cfg->baseclass == PCIC_BRIDGE
811 && bridge_cfg->subclass == PCIS_BRIDGE_PCI
812 && bridge_cfg->secondarybus == cfg->bus) {
822 pci_ioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct thread *td)
829 if (!(flag & FWRITE))
836 struct pci_devinfo *dinfo;
837 struct pci_conf_io *cio;
838 struct devlist *devlist_head;
839 struct pci_match_conf *pattern_buf;
844 cio = (struct pci_conf_io *)data;
850 * Hopefully the user won't pass in a null pointer, but it
851 * can't hurt to check.
859 * If the user specified an offset into the device list,
860 * but the list has changed since they last called this
861 * ioctl, tell them that the list has changed. They will
862 * have to get the list from the beginning.
864 if ((cio->offset != 0)
865 && (cio->generation != pci_generation)){
866 cio->num_matches = 0;
867 cio->status = PCI_GETCONF_LIST_CHANGED;
873 * Check to see whether the user has asked for an offset
874 * past the end of our list.
876 if (cio->offset >= pci_numdevs) {
877 cio->num_matches = 0;
878 cio->status = PCI_GETCONF_LAST_DEVICE;
883 /* get the head of the device queue */
884 devlist_head = &pci_devq;
887 * Determine how much room we have for pci_conf structures.
888 * Round the user's buffer size down to the nearest
889 * multiple of sizeof(struct pci_conf) in case the user
890 * didn't specify a multiple of that size.
892 iolen = min(cio->match_buf_len -
893 (cio->match_buf_len % sizeof(struct pci_conf)),
894 pci_numdevs * sizeof(struct pci_conf));
897 * Since we know that iolen is a multiple of the size of
898 * the pciconf union, it's okay to do this.
900 ionum = iolen / sizeof(struct pci_conf);
903 * If this test is true, the user wants the pci_conf
904 * structures returned to match the supplied entries.
906 if ((cio->num_patterns > 0)
907 && (cio->pat_buf_len > 0)) {
909 * pat_buf_len needs to be:
910 * num_patterns * sizeof(struct pci_match_conf)
911 * While it is certainly possible the user just
912 * allocated a large buffer, but set the number of
913 * matches correctly, it is far more likely that
914 * their kernel doesn't match the userland utility
915 * they're using. It's also possible that the user
916 * forgot to initialize some variables. Yes, this
917 * may be overly picky, but I hazard to guess that
918 * it's far more likely to just catch folks that
919 * updated their kernel but not their userland.
921 if ((cio->num_patterns *
922 sizeof(struct pci_match_conf)) != cio->pat_buf_len){
923 /* The user made a mistake, return an error*/
924 cio->status = PCI_GETCONF_ERROR;
925 printf("pci_ioctl: pat_buf_len %d != "
926 "num_patterns (%d) * sizeof(struct "
927 "pci_match_conf) (%d)\npci_ioctl: "
928 "pat_buf_len should be = %d\n",
929 cio->pat_buf_len, cio->num_patterns,
930 (int)sizeof(struct pci_match_conf),
931 (int)sizeof(struct pci_match_conf) *
933 printf("pci_ioctl: do your headers match your "
935 cio->num_matches = 0;
941 * Check the user's buffer to make sure it's readable.
943 if (!useracc((caddr_t)cio->patterns,
944 cio->pat_buf_len, VM_PROT_READ)) {
945 printf("pci_ioctl: pattern buffer %p, "
946 "length %u isn't user accessible for"
947 " READ\n", cio->patterns,
953 * Allocate a buffer to hold the patterns.
955 pattern_buf = malloc(cio->pat_buf_len, M_TEMP,
957 error = copyin(cio->patterns, pattern_buf,
961 num_patterns = cio->num_patterns;
963 } else if ((cio->num_patterns > 0)
964 || (cio->pat_buf_len > 0)) {
966 * The user made a mistake, spit out an error.
968 cio->status = PCI_GETCONF_ERROR;
969 cio->num_matches = 0;
970 printf("pci_ioctl: invalid GETCONF arguments\n");
977 * Make sure we can write to the match buffer.
979 if (!useracc((caddr_t)cio->matches,
980 cio->match_buf_len, VM_PROT_WRITE)) {
981 printf("pci_ioctl: match buffer %p, length %u "
982 "isn't user accessible for WRITE\n",
983 cio->matches, cio->match_buf_len);
989 * Go through the list of devices and copy out the devices
990 * that match the user's criteria.
992 for (cio->num_matches = 0, error = 0, i = 0,
993 dinfo = STAILQ_FIRST(devlist_head);
994 (dinfo != NULL) && (cio->num_matches < ionum)
995 && (error == 0) && (i < pci_numdevs);
996 dinfo = STAILQ_NEXT(dinfo, pci_links), i++) {
1001 /* Populate pd_name and pd_unit */
1003 if (dinfo->cfg.dev && dinfo->conf.pd_name[0] == '\0')
1004 name = device_get_name(dinfo->cfg.dev);
1006 strncpy(dinfo->conf.pd_name, name,
1007 sizeof(dinfo->conf.pd_name));
1008 dinfo->conf.pd_name[PCI_MAXNAMELEN] = 0;
1009 dinfo->conf.pd_unit =
1010 device_get_unit(dinfo->cfg.dev);
1013 if ((pattern_buf == NULL) ||
1014 (pci_conf_match(pattern_buf, num_patterns,
1015 &dinfo->conf) == 0)) {
1018 * If we've filled up the user's buffer,
1019 * break out at this point. Since we've
1020 * got a match here, we'll pick right back
1021 * up at the matching entry. We can also
1022 * tell the user that there are more matches
1025 if (cio->num_matches >= ionum)
1028 error = copyout(&dinfo->conf,
1029 &cio->matches[cio->num_matches],
1030 sizeof(struct pci_conf));
1036 * Set the pointer into the list, so if the user is getting
1037 * n records at a time, where n < pci_numdevs,
1042 * Set the generation, the user will need this if they make
1043 * another ioctl call with offset != 0.
1045 cio->generation = pci_generation;
1048 * If this is the last device, inform the user so he won't
1049 * bother asking for more devices. If dinfo isn't NULL, we
1050 * know that there are more matches in the list because of
1051 * the way the traversal is done.
1054 cio->status = PCI_GETCONF_LAST_DEVICE;
1056 cio->status = PCI_GETCONF_MORE_DEVS;
1058 if (pattern_buf != NULL)
1059 free(pattern_buf, M_TEMP);
1064 io = (struct pci_io *)data;
1065 switch(io->pi_width) {
1070 * Assume that the user-level bus number is
1071 * actually the pciN instance number. We map
1072 * from that to the real pcib+bus combination.
1074 pci = devclass_get_device(pci_devclass,
1077 int b = pcib_get_bus(pci);
1078 pcib = device_get_parent(pci);
1080 PCIB_READ_CONFIG(pcib,
1098 io = (struct pci_io *)data;
1099 switch(io->pi_width) {
1104 * Assume that the user-level bus number is
1105 * actually the pciN instance number. We map
1106 * from that to the real pcib+bus combination.
1108 pci = devclass_get_device(pci_devclass,
1111 int b = pcib_get_bus(pci);
1112 pcib = device_get_parent(pci);
1113 PCIB_WRITE_CONFIG(pcib,
1141 static struct cdevsw pcicdev = {
1148 /* open */ pci_open,
1149 /* close */ pci_close,
1151 /* write */ nowrite,
1152 /* ioctl */ pci_ioctl,
1155 /* strategy */ nostrategy,
1163 * New style pci driver. Parent device is either a pci-host-bridge or a
1164 * pci-pci-bridge. Both kinds are represented by instances of pcib.
1168 pci_print_verbose(struct pci_devinfo *dinfo)
1171 pcicfgregs *cfg = &dinfo->cfg;
1173 printf("found->\tvendor=0x%04x, dev=0x%04x, revid=0x%02x\n",
1174 cfg->vendor, cfg->device, cfg->revid);
1175 printf("\tbus=%d, slot=%d, func=%d\n",
1176 cfg->bus, cfg->slot, cfg->func);
1177 printf("\tclass=%02x-%02x-%02x, hdrtype=0x%02x, mfdev=%d\n",
1178 cfg->baseclass, cfg->subclass, cfg->progif,
1179 cfg->hdrtype, cfg->mfdev);
1180 printf("\tsubordinatebus=%x \tsecondarybus=%x\n",
1181 cfg->subordinatebus, cfg->secondarybus);
1183 printf("\tcmdreg=0x%04x, statreg=0x%04x, cachelnsz=%d (dwords)\n",
1184 cfg->cmdreg, cfg->statreg, cfg->cachelnsz);
1185 printf("\tlattimer=0x%02x (%d ns), mingnt=0x%02x (%d ns), maxlat=0x%02x (%d ns)\n",
1186 cfg->lattimer, cfg->lattimer * 30,
1187 cfg->mingnt, cfg->mingnt * 250, cfg->maxlat, cfg->maxlat * 250);
1188 #endif /* PCI_DEBUG */
1189 if (cfg->intpin > 0)
1190 printf("\tintpin=%c, irq=%d\n", cfg->intpin +'a' -1, cfg->intline);
1195 pci_porten(device_t pcib, int b, int s, int f)
1197 return (PCIB_READ_CONFIG(pcib, b, s, f, PCIR_COMMAND, 2)
1198 & PCIM_CMD_PORTEN) != 0;
1202 pci_memen(device_t pcib, int b, int s, int f)
1204 return (PCIB_READ_CONFIG(pcib, b, s, f, PCIR_COMMAND, 2)
1205 & PCIM_CMD_MEMEN) != 0;
1209 * Add a resource based on a pci map register. Return 1 if the map
1210 * register is a 32bit map register or 2 if it is a 64bit register.
1213 pci_add_map(device_t pcib, int b, int s, int f, int reg,
1214 struct resource_list *rl)
1223 #ifdef PCI_ENABLE_IO_MODES
1228 map = PCIB_READ_CONFIG(pcib, b, s, f, reg, 4);
1230 if (map == 0 || map == 0xffffffff)
1231 return 1; /* skip invalid entry */
1233 PCIB_WRITE_CONFIG(pcib, b, s, f, reg, 0xffffffff, 4);
1234 testval = PCIB_READ_CONFIG(pcib, b, s, f, reg, 4);
1235 PCIB_WRITE_CONFIG(pcib, b, s, f, reg, map, 4);
1237 base = pci_mapbase(map);
1238 if (pci_maptype(map) & PCI_MAPMEM)
1239 type = SYS_RES_MEMORY;
1241 type = SYS_RES_IOPORT;
1242 ln2size = pci_mapsize(testval);
1243 ln2range = pci_maprange(testval);
1244 if (ln2range == 64) {
1245 /* Read the other half of a 64bit map register */
1246 base |= (u_int64_t) PCIB_READ_CONFIG(pcib, b, s, f, reg+4, 4);
1250 * This code theoretically does the right thing, but has
1251 * undesirable side effects in some cases where
1252 * peripherals respond oddly to having these bits
1253 * enabled. Leave them alone by default.
1255 #ifdef PCI_ENABLE_IO_MODES
1256 if (type == SYS_RES_IOPORT && !pci_porten(pcib, b, s, f)) {
1257 cmd = PCIB_READ_CONFIG(pcib, b, s, f, PCIR_COMMAND, 2);
1258 cmd |= PCIM_CMD_PORTEN;
1259 PCIB_WRITE_CONFIG(pcib, b, s, f, PCIR_COMMAND, cmd, 2);
1261 if (type == SYS_RES_MEMORY && !pci_memen(pcib, b, s, f)) {
1262 cmd = PCIB_READ_CONFIG(pcib, b, s, f, PCIR_COMMAND, 2);
1263 cmd |= PCIM_CMD_MEMEN;
1264 PCIB_WRITE_CONFIG(pcib, b, s, f, PCIR_COMMAND, cmd, 2);
1267 if (type == SYS_RES_IOPORT && !pci_porten(pcib, b, s, f))
1269 if (type == SYS_RES_MEMORY && !pci_memen(pcib, b, s, f))
1273 resource_list_add(rl, type, reg,
1274 base, base + (1 << ln2size) - 1,
1278 printf("\tmap[%02x]: type %x, range %2d, base %08x, size %2d\n",
1279 reg, pci_maptype(base), ln2range,
1280 (unsigned int) base, ln2size);
1283 return (ln2range == 64) ? 2 : 1;
1287 pci_add_resources(device_t pcib, device_t bus, device_t dev)
1289 struct pci_devinfo *dinfo = device_get_ivars(dev);
1290 pcicfgregs *cfg = &dinfo->cfg;
1291 struct resource_list *rl = &dinfo->resources;
1292 struct pci_quirk *q;
1294 #if 0 /* WILL BE USED WITH ADDITIONAL IMPORT FROM FREEBSD-5 XXX */
1301 for (i = 0; i < cfg->nummaps;) {
1302 i += pci_add_map(pcib, b, s, f, PCIR_BAR(i),rl);
1305 for (q = &pci_quirks[0]; q->devid; q++) {
1306 if (q->devid == ((cfg->device << 16) | cfg->vendor)
1307 && q->type == PCI_QUIRK_MAP_REG)
1308 pci_add_map(pcib, b, s, f, q->arg1, rl);
1311 if (cfg->intpin > 0 && cfg->intline != 255)
1312 resource_list_add(rl, SYS_RES_IRQ, 0,
1313 cfg->intline, cfg->intline, 1);
1317 pci_add_children(device_t dev, int busno, size_t dinfo_size)
1319 #define REG(n, w) PCIB_READ_CONFIG(pcib, busno, s, f, n, w)
1320 device_t pcib = device_get_parent(dev);
1321 struct pci_devinfo *dinfo;
1323 int s, f, pcifunchigh;
1326 KKASSERT(dinfo_size >= sizeof(struct pci_devinfo));
1328 maxslots = PCIB_MAXSLOTS(pcib);
1330 for (s = 0; s <= maxslots; s++) {
1333 hdrtype = REG(PCIR_HDRTYPE, 1);
1334 if ((hdrtype & PCIM_HDRTYPE) > PCI_MAXHDRTYPE)
1336 if (hdrtype & PCIM_MFDEV)
1337 pcifunchigh = PCI_FUNCMAX;
1338 for (f = 0; f <= pcifunchigh; f++) {
1339 dinfo = pci_read_device(pcib, busno, s, f, dinfo_size);
1340 if (dinfo != NULL) {
1341 pci_add_child(dev, dinfo);
1349 pci_add_child(device_t bus, struct pci_devinfo *dinfo)
1353 pcib = device_get_parent(bus);
1354 dinfo->cfg.dev = device_add_child(bus, NULL, -1);
1355 device_set_ivars(dinfo->cfg.dev, dinfo);
1356 pci_add_resources(pcib, bus, dinfo->cfg.dev);
1357 pci_print_verbose(dinfo);
1361 pci_probe(device_t dev)
1363 static int once, busno;
1365 device_set_desc(dev, "PCI bus");
1368 device_printf(dev, "physical bus=%d\n", pcib_get_bus(dev));
1371 * Since there can be multiple independently numbered PCI
1372 * busses on some large alpha systems, we can't use the unit
1373 * number to decide what bus we are probing. We ask the parent
1374 * pcib what our bus number is.
1376 busno = pcib_get_bus(dev);
1379 pci_add_children(dev, busno, sizeof(struct pci_devinfo));
1382 make_dev(&pcicdev, 0, UID_ROOT, GID_WHEEL, 0644, "pci");
1390 pci_attach(device_t dev)
1395 * Since there can be multiple independantly numbered PCI
1396 * busses on some large alpha systems, we can't use the unit
1397 * number to decide what bus we are probing. We ask the parent
1398 * pcib what our bus number is.
1400 busno = pcib_get_bus(dev);
1402 device_printf(dev, "physical bus=%d\n", busno);
1404 pci_add_children(dev, busno, sizeof(struct pci_devinfo));
1406 return (bus_generic_attach(dev));
1410 pci_print_resources(struct resource_list *rl, const char *name, int type,
1413 struct resource_list_entry *rle;
1414 int printed, retval;
1418 /* Yes, this is kinda cheating */
1419 SLIST_FOREACH(rle, rl, link) {
1420 if (rle->type == type) {
1422 retval += printf(" %s ", name);
1423 else if (printed > 0)
1424 retval += printf(",");
1426 retval += printf(format, rle->start);
1427 if (rle->count > 1) {
1428 retval += printf("-");
1429 retval += printf(format, rle->start +
1438 pci_print_child(device_t dev, device_t child)
1440 struct pci_devinfo *dinfo;
1441 struct resource_list *rl;
1445 dinfo = device_get_ivars(child);
1447 rl = &dinfo->resources;
1449 retval += bus_print_child_header(dev, child);
1451 retval += pci_print_resources(rl, "port", SYS_RES_IOPORT, "%#lx");
1452 retval += pci_print_resources(rl, "mem", SYS_RES_MEMORY, "%#lx");
1453 retval += pci_print_resources(rl, "irq", SYS_RES_IRQ, "%ld");
1454 if (device_get_flags(dev))
1455 retval += printf(" flags %#x", device_get_flags(dev));
1457 retval += printf(" at device %d.%d", pci_get_slot(child),
1458 pci_get_function(child));
1460 retval += bus_print_child_footer(dev, child);
1466 pci_probe_nomatch(device_t dev, device_t child)
1468 struct pci_devinfo *dinfo;
1474 dinfo = device_get_ivars(child);
1476 desc = pci_ata_match(child);
1477 if (!desc) desc = pci_usb_match(child);
1478 if (!desc) desc = pci_vga_match(child);
1479 if (!desc) desc = pci_chip_match(child);
1481 desc = "unknown card";
1484 device_printf(dev, "<%s>", desc);
1485 if (bootverbose || unknown) {
1486 printf(" (vendor=0x%04x, dev=0x%04x)",
1491 pci_get_slot(child),
1492 pci_get_function(child));
1493 if (cfg->intpin > 0 && cfg->intline != 255) {
1494 printf(" irq %d", cfg->intline);
1502 pci_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
1504 struct pci_devinfo *dinfo;
1507 dinfo = device_get_ivars(child);
1511 case PCI_IVAR_SUBVENDOR:
1512 *result = cfg->subvendor;
1514 case PCI_IVAR_SUBDEVICE:
1515 *result = cfg->subdevice;
1517 case PCI_IVAR_VENDOR:
1518 *result = cfg->vendor;
1520 case PCI_IVAR_DEVICE:
1521 *result = cfg->device;
1523 case PCI_IVAR_DEVID:
1524 *result = (cfg->device << 16) | cfg->vendor;
1526 case PCI_IVAR_CLASS:
1527 *result = cfg->baseclass;
1529 case PCI_IVAR_SUBCLASS:
1530 *result = cfg->subclass;
1532 case PCI_IVAR_PROGIF:
1533 *result = cfg->progif;
1535 case PCI_IVAR_REVID:
1536 *result = cfg->revid;
1538 case PCI_IVAR_INTPIN:
1539 *result = cfg->intpin;
1542 *result = cfg->intline;
1548 *result = cfg->slot;
1550 case PCI_IVAR_FUNCTION:
1551 *result = cfg->func;
1553 case PCI_IVAR_SECONDARYBUS:
1554 *result = cfg->secondarybus;
1556 case PCI_IVAR_SUBORDINATEBUS:
1557 *result = cfg->subordinatebus;
1559 case PCI_IVAR_ETHADDR:
1561 * The generic accessor doesn't deal with failure, so
1562 * we set the return value, then return an error.
1573 pci_write_ivar(device_t dev, device_t child, int which, uintptr_t value)
1575 struct pci_devinfo *dinfo;
1578 dinfo = device_get_ivars(child);
1582 case PCI_IVAR_SUBVENDOR:
1583 case PCI_IVAR_SUBDEVICE:
1584 case PCI_IVAR_VENDOR:
1585 case PCI_IVAR_DEVICE:
1586 case PCI_IVAR_DEVID:
1587 case PCI_IVAR_CLASS:
1588 case PCI_IVAR_SUBCLASS:
1589 case PCI_IVAR_PROGIF:
1590 case PCI_IVAR_REVID:
1591 case PCI_IVAR_INTPIN:
1595 case PCI_IVAR_FUNCTION:
1596 case PCI_IVAR_ETHADDR:
1597 return EINVAL; /* disallow for now */
1599 case PCI_IVAR_SECONDARYBUS:
1600 cfg->secondarybus = value;
1602 case PCI_IVAR_SUBORDINATEBUS:
1603 cfg->subordinatebus = value;
1611 static struct resource *
1612 pci_alloc_resource(device_t dev, device_t child, int type, int *rid,
1613 u_long start, u_long end, u_long count, u_int flags)
1615 struct pci_devinfo *dinfo = device_get_ivars(child);
1616 struct resource_list *rl = &dinfo->resources;
1619 pcicfgregs *cfg = &dinfo->cfg;
1621 * Perform lazy resource allocation
1623 * XXX add support here for SYS_RES_IOPORT and SYS_RES_MEMORY
1625 if (device_get_parent(child) == dev) {
1627 * If device doesn't have an interrupt routed, and is
1628 * deserving of an interrupt, try to assign it one.
1630 if ((type == SYS_RES_IRQ) &&
1631 (cfg->intline == 255 || cfg->intline == 0) &&
1632 (cfg->intpin != 0) && (start == 0) && (end == ~0UL)) {
1633 cfg->intline = PCIB_ROUTE_INTERRUPT(
1634 device_get_parent(dev), child,
1636 if (cfg->intline != 255) {
1637 pci_write_config(child, PCIR_INTLINE,
1639 resource_list_add(rl, SYS_RES_IRQ, 0,
1640 cfg->intline, cfg->intline, 1);
1645 return resource_list_alloc(rl, dev, child, type, rid,
1646 start, end, count, flags);
1650 pci_release_resource(device_t dev, device_t child, int type, int rid,
1653 struct pci_devinfo *dinfo = device_get_ivars(child);
1654 struct resource_list *rl = &dinfo->resources;
1656 return resource_list_release(rl, dev, child, type, rid, r);
1660 pci_set_resource(device_t dev, device_t child, int type, int rid,
1661 u_long start, u_long count)
1663 struct pci_devinfo *dinfo = device_get_ivars(child);
1664 struct resource_list *rl = &dinfo->resources;
1666 resource_list_add(rl, type, rid, start, start + count - 1, count);
1671 pci_get_resource(device_t dev, device_t child, int type, int rid,
1672 u_long *startp, u_long *countp)
1674 struct pci_devinfo *dinfo = device_get_ivars(child);
1675 struct resource_list *rl = &dinfo->resources;
1676 struct resource_list_entry *rle;
1678 rle = resource_list_find(rl, type, rid);
1683 *startp = rle->start;
1685 *countp = rle->count;
1691 pci_delete_resource(device_t dev, device_t child, int type, int rid)
1693 printf("pci_delete_resource: PCI resources can not be deleted\n");
1696 struct resource_list *
1697 pci_get_resource_list (device_t dev, device_t child)
1699 struct pci_devinfo * dinfo = device_get_ivars(child);
1700 struct resource_list * rl = &dinfo->resources;
1709 pci_read_config_method(device_t dev, device_t child, int reg, int width)
1711 struct pci_devinfo *dinfo = device_get_ivars(child);
1712 pcicfgregs *cfg = &dinfo->cfg;
1714 return PCIB_READ_CONFIG(device_get_parent(dev),
1715 cfg->bus, cfg->slot, cfg->func,
1720 pci_write_config_method(device_t dev, device_t child, int reg,
1721 u_int32_t val, int width)
1723 struct pci_devinfo *dinfo = device_get_ivars(child);
1724 pcicfgregs *cfg = &dinfo->cfg;
1726 PCIB_WRITE_CONFIG(device_get_parent(dev),
1727 cfg->bus, cfg->slot, cfg->func,
1732 pci_child_location_str_method(device_t cbdev, device_t child, char *buf,
1735 struct pci_devinfo *dinfo;
1737 dinfo = device_get_ivars(child);
1738 snprintf(buf, buflen, "slot=%d function=%d", pci_get_slot(child),
1739 pci_get_function(child));
1744 pci_child_pnpinfo_str_method(device_t cbdev, device_t child, char *buf,
1747 struct pci_devinfo *dinfo;
1750 dinfo = device_get_ivars(child);
1752 snprintf(buf, buflen, "vendor=0x%04x device=0x%04x subvendor=0x%04x "
1753 "subdevice=0x%04x class=0x%02x%02x%02x", cfg->vendor, cfg->device,
1754 cfg->subvendor, cfg->subdevice, cfg->baseclass, cfg->subclass,
1760 pci_assign_interrupt_method(device_t dev, device_t child)
1762 struct pci_devinfo *dinfo = device_get_ivars(child);
1763 pcicfgregs *cfg = &dinfo->cfg;
1765 return (PCIB_ROUTE_INTERRUPT(device_get_parent(dev), child,
1770 pci_modevent(module_t mod, int what, void *arg)
1774 STAILQ_INIT(&pci_devq);
1785 pci_resume(device_t dev)
1791 struct pci_devinfo *dinfo;
1794 device_get_children(dev, &children, &numdevs);
1796 for (i = 0; i < numdevs; i++) {
1797 child = children[i];
1799 dinfo = device_get_ivars(child);
1801 if (cfg->intpin > 0 && PCI_INTERRUPT_VALID(cfg->intline)) {
1802 cfg->intline = PCI_ASSIGN_INTERRUPT(dev, child);
1803 if (PCI_INTERRUPT_VALID(cfg->intline)) {
1804 pci_write_config(child, PCIR_INTLINE,
1810 free(children, M_TEMP);
1812 return (bus_generic_resume(dev));
1815 static device_method_t pci_methods[] = {
1816 /* Device interface */
1817 DEVMETHOD(device_probe, pci_probe),
1818 DEVMETHOD(device_attach, pci_attach),
1819 DEVMETHOD(device_shutdown, bus_generic_shutdown),
1820 DEVMETHOD(device_suspend, bus_generic_suspend),
1821 DEVMETHOD(device_resume, pci_resume),
1824 DEVMETHOD(bus_print_child, pci_print_child),
1825 DEVMETHOD(bus_probe_nomatch, pci_probe_nomatch),
1826 DEVMETHOD(bus_read_ivar, pci_read_ivar),
1827 DEVMETHOD(bus_write_ivar, pci_write_ivar),
1828 DEVMETHOD(bus_driver_added, bus_generic_driver_added),
1829 DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
1830 DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
1832 DEVMETHOD(bus_get_resource_list,pci_get_resource_list),
1833 DEVMETHOD(bus_set_resource, pci_set_resource),
1834 DEVMETHOD(bus_get_resource, pci_get_resource),
1835 DEVMETHOD(bus_delete_resource, pci_delete_resource),
1836 DEVMETHOD(bus_alloc_resource, pci_alloc_resource),
1837 DEVMETHOD(bus_release_resource, pci_release_resource),
1838 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
1839 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
1840 DEVMETHOD(bus_child_pnpinfo_str, pci_child_pnpinfo_str_method),
1841 DEVMETHOD(bus_child_location_str, pci_child_location_str_method),
1844 DEVMETHOD(pci_read_config, pci_read_config_method),
1845 DEVMETHOD(pci_write_config, pci_write_config_method),
1846 DEVMETHOD(pci_enable_busmaster, pci_enable_busmaster_method),
1847 DEVMETHOD(pci_disable_busmaster, pci_disable_busmaster_method),
1848 DEVMETHOD(pci_enable_io, pci_enable_io_method),
1849 DEVMETHOD(pci_disable_io, pci_disable_io_method),
1850 DEVMETHOD(pci_get_powerstate, pci_get_powerstate_method),
1851 DEVMETHOD(pci_set_powerstate, pci_set_powerstate_method),
1852 DEVMETHOD(pci_assign_interrupt, pci_assign_interrupt_method),
1857 static driver_t pci_driver = {
1863 DRIVER_MODULE(pci, pcib, pci_driver, pci_devclass, pci_modevent, 0);