35#include <sys/_eventhandler.h>
38#define PCI_MAXMAPS_0 6
39#define PCI_MAXMAPS_1 2
40#define PCI_MAXMAPS_2 1
175#define PCICFG_VF 0x0001
270#if BYTE_ORDER == LITTLE_ENDIAN
303#define PCI_DEV(v, d) \
304 .match_flag_vendor = 1, .vendor = (v), \
305 .match_flag_device = 1, .device = (d)
306#define PCI_SUBDEV(sv, sd) \
307 .match_flag_subvendor = 1, .subvendor = (sv), \
308 .match_flag_subdevice = 1, .subdevice = (sd)
309#define PCI_CLASS(x) \
310 .match_flag_class = 1, .class_id = (x)
311#define PCI_SUBCLASS(x) \
312 .match_flag_subclass = 1, .subclass = (x)
313#define PCI_REVID(x) \
314 .match_flag_revid = 1, .revid = (x)
315#define PCI_DESCR(x) \
318 "M16:mask;U16:vendor;U16:device;U16:subvendor;U16:subdevice;" \
319 "U16:class;U16:subclass;U16:revid;"
320#define PCI_PNP_INFO(table) \
321 MODULE_PNP_INFO(PCI_PNP_STR, pci, table, table, \
322 sizeof(table) / sizeof(table[0]))
326#define PCI_MATCH(child, table) \
327 pci_match_device(child, (table), nitems(table));
330#if defined(_SYS_BUS_H_) && defined(_SYS_PCIIO_H_)
332 STAILQ_ENTRY(pci_devinfo) pci_links;
333 struct resource_list resources;
335 struct pci_conf conf;
343enum pci_device_ivars {
370#define PCI_ACCESSOR(var, ivar, type) \
371 __BUS_ACCESSOR(pci, var, PCI, ivar, type)
373PCI_ACCESSOR(subvendor, SUBVENDOR, uint16_t)
374PCI_ACCESSOR(subdevice, SUBDEVICE, uint16_t)
375PCI_ACCESSOR(vendor, VENDOR, uint16_t)
376PCI_ACCESSOR(device, DEVICE, uint16_t)
377PCI_ACCESSOR(devid, DEVID, uint32_t)
378PCI_ACCESSOR(
class, CLASS, uint8_t)
379PCI_ACCESSOR(
subclass, SUBCLASS, uint8_t)
380PCI_ACCESSOR(progif, PROGIF, uint8_t)
381PCI_ACCESSOR(revid, REVID, uint8_t)
382PCI_ACCESSOR(intpin, INTPIN, uint8_t)
383PCI_ACCESSOR(
irq, IRQ, uint8_t)
384PCI_ACCESSOR(domain, DOMAIN, uint32_t)
385PCI_ACCESSOR(
bus, BUS, uint8_t)
386PCI_ACCESSOR(
slot, SLOT, uint8_t)
387PCI_ACCESSOR(function, FUNCTION, uint8_t)
388PCI_ACCESSOR(ether, ETHADDR, uint8_t *)
389PCI_ACCESSOR(cmdreg, CMDREG, uint8_t)
390PCI_ACCESSOR(cachelnsz, CACHELNSZ, uint8_t)
391PCI_ACCESSOR(mingnt, MINGNT, uint8_t)
392PCI_ACCESSOR(maxlat, MAXLAT, uint8_t)
393PCI_ACCESSOR(lattimer, LATTIMER, uint8_t)
400static __inline uint32_t
417enum pcib_device_ivars {
422#define PCIB_ACCESSOR(var, ivar, type) \
423 __BUS_ACCESSOR(pcib, var, PCIB, ivar, type)
425PCIB_ACCESSOR(domain, DOMAIN, uint32_t)
426PCIB_ACCESSOR(
bus, BUS, uint32_t)
435#define PCI_INVALID_IRQ 255
436#define PCI_INTERRUPT_VALID(x) ((x) != PCI_INVALID_IRQ)
445pci_enable_busmaster(device_t
dev)
447 return(PCI_ENABLE_BUSMASTER(device_get_parent(
dev),
dev));
451pci_disable_busmaster(device_t
dev)
453 return(PCI_DISABLE_BUSMASTER(device_get_parent(
dev),
dev));
457pci_enable_io(device_t
dev,
int space)
459 return(PCI_ENABLE_IO(device_get_parent(
dev),
dev,
space));
463pci_disable_io(device_t
dev,
int space)
465 return(PCI_DISABLE_IO(device_get_parent(
dev),
dev,
space));
469pci_get_vpd_ident(device_t
dev,
const char **
identptr)
475pci_get_vpd_readonly(device_t
dev,
const char *
kw,
const char **
vptr)
477 return(PCI_GET_VPD_READONLY(device_get_parent(
dev),
dev,
kw,
vptr));
484pci_is_vga_ioport_range(rman_res_t
start, rman_res_t end)
487 return (((
start >= 0x3b0 && end <= 0x3bb) ||
488 (
start >= 0x3c0 && end <= 0x3df)) ? 1 : 0);
492pci_is_vga_memory_range(rman_res_t
start, rman_res_t end)
495 return ((
start >= 0xa0000 && end <= 0xbffff) ? 1 : 0);
513#define PCI_POWERSTATE_D0 0
514#define PCI_POWERSTATE_D1 1
515#define PCI_POWERSTATE_D2 2
516#define PCI_POWERSTATE_D3 3
517#define PCI_POWERSTATE_UNKNOWN -1
520pci_set_powerstate(device_t
dev,
int state)
522 return PCI_SET_POWERSTATE(device_get_parent(
dev),
dev,
state);
526pci_get_powerstate(device_t
dev)
528 return PCI_GET_POWERSTATE(device_get_parent(
dev),
dev);
571pci_alloc_msi(device_t
dev,
int *
count)
573 return (PCI_ALLOC_MSI(device_get_parent(
dev),
dev,
count));
577pci_alloc_msix(device_t
dev,
int *
count)
579 return (PCI_ALLOC_MSIX(device_get_parent(
dev),
dev,
count));
595pci_disable_msi(device_t
dev)
597 PCI_DISABLE_MSI(device_get_parent(
dev),
dev);
607pci_release_msi(device_t
dev)
609 return (PCI_RELEASE_MSI(device_get_parent(
dev),
dev));
613pci_msi_count(device_t
dev)
615 return (PCI_MSI_COUNT(device_get_parent(
dev),
dev));
619pci_msix_count(device_t
dev)
621 return (PCI_MSIX_COUNT(device_get_parent(
dev),
dev));
625pci_msix_pba_bar(device_t
dev)
627 return (PCI_MSIX_PBA_BAR(device_get_parent(
dev),
dev));
631pci_msix_table_bar(device_t
dev)
633 return (PCI_MSIX_TABLE_BAR(device_get_parent(
dev),
dev));
639 return (PCI_GET_ID(device_get_parent(
dev),
dev,
type,
id));
647static __inline uint16_t
648pci_get_rid(device_t
dev)
659pci_child_added(device_t
dev)
662 return (PCI_CHILD_ADDED(device_get_parent(
dev),
dev));
692bool pcie_flr(device_t
dev, u_int max_delay,
bool force);
718#define VGA_PCI_BIOS_SHADOW_ADDR 0xC0000
719#define VGA_PCI_BIOS_SHADOW_SIZE 131072
device_t pci_find_pcie_root_port(device_t dev)
int pcie_link_reset(device_t port, int pcie_location)
void pcie_apei_error(device_t dev, int sev, uint8_t *aerp)
device_t pci_find_dbsf(uint32_t domain, uint8_t bus, uint8_t slot, uint8_t func)
uint32_t pcie_read_config(device_t dev, int reg, int width)
device_t pci_find_class(uint8_t class, uint8_t subclass)
int pci_msi_device_blacklisted(device_t dev)
int pci_get_max_read_req(device_t dev)
device_t pci_find_class_from(uint8_t class, uint8_t subclass, device_t from)
void pci_print_faulted_dev(void)
int pci_set_max_read_req(device_t dev, int size)
bool pcie_wait_for_pending_transactions(device_t dev, u_int max_delay)
int pci_pending_msix(device_t dev, u_int index)
device_t pci_find_device(uint16_t vendor, uint16_t device)
int pci_power_reset(device_t dev)
int pci_get_max_payload(device_t dev)
void pcie_write_config(device_t dev, int reg, uint32_t value, int width)
int pci_get_relaxed_ordering_enabled(device_t dev)
bool pcie_flr(device_t dev, u_int max_delay, bool force)
uint32_t pcie_adjust_config(device_t dev, int reg, uint32_t mask, uint32_t value, int width)
void pci_restore_state(device_t dev)
int pci_msix_device_blacklisted(device_t dev)
device_t pci_find_bsf(uint8_t bus, uint8_t slot, uint8_t func)
void pci_ht_map_msi(device_t dev, uint64_t addr)
int pcie_get_max_completion_timeout(device_t dev)
void pci_save_state(device_t dev)
void * vga_pci_map_bios(device_t dev, size_t *size)
struct pci_map * pci_find_bar(device_t dev, int reg)
EVENTHANDLER_DECLARE(pci_add_device, pci_event_fn)
STAILQ_HEAD(devlist, pci_devinfo)
int vga_pci_repost(device_t dev)
int pci_bar_enabled(device_t dev, struct pci_map *pm)
void(* pci_event_fn)(void *arg, device_t dev)
struct pcicfg_vpd * pci_fetch_vpd_list(device_t dev)
const struct pci_device_table * pci_match_device(device_t child, const struct pci_device_table *id, size_t nelt)
void vga_pci_unmap_bios(device_t dev, void *bios)
int vga_pci_is_boot_display(device_t dev)
uint16_t match_flag_subvendor
uint16_t match_flag_unused
uint16_t match_flag_subdevice
uint16_t match_flag_revid
uint16_t match_flag_device
uint16_t match_flag_class
uint16_t match_flag_vendor
uint16_t match_flag_subclass
STAILQ_ENTRY(pci_ea_entry) eae_link
STAILQ_ENTRY(pci_map) pm_link
STAILQ_HEAD(, pci_ea_entry) ea_entries
struct msix_vector * msix_vectors
struct msix_table_entry * msix_table
uint32_t msix_table_offset
struct resource * msix_table_res
struct resource * msix_pba_res
uint16_t pcie_device_ctl2
struct vpd_readonly * vpd_ros
STAILQ_HEAD(, pci_map) maps
struct pcicfg_bridge bridge