Lines Matching refs:pdev

245 static void check_pdev(const struct pci_dev *pdev)  in check_pdev()  argument
251 u16 seg = pdev->seg; in check_pdev()
252 u8 bus = pdev->bus; in check_pdev()
253 u8 dev = PCI_SLOT(pdev->devfn); in check_pdev()
254 u8 func = PCI_FUNC(pdev->devfn); in check_pdev()
302 struct pci_dev *pdev; in alloc_pdev() local
304 list_for_each_entry ( pdev, &pseg->alldevs_list, alldevs_list ) in alloc_pdev()
305 if ( pdev->bus == bus && pdev->devfn == devfn ) in alloc_pdev()
306 return pdev; in alloc_pdev()
308 pdev = xzalloc(struct pci_dev); in alloc_pdev()
309 if ( !pdev ) in alloc_pdev()
312 *(u16*) &pdev->seg = pseg->nr; in alloc_pdev()
313 *((u8*) &pdev->bus) = bus; in alloc_pdev()
314 *((u8*) &pdev->devfn) = devfn; in alloc_pdev()
315 pdev->domain = NULL; in alloc_pdev()
316 INIT_LIST_HEAD(&pdev->msi_list); in alloc_pdev()
325 xfree(pdev); in alloc_pdev()
329 pdev->msix = msix; in alloc_pdev()
332 list_add(&pdev->alldevs_list, &pseg->alldevs_list); in alloc_pdev()
335 switch ( pdev->type = pdev_type(pseg->nr, bus, devfn) ) in alloc_pdev()
366 pdev->phantom_stride = 8 >> MASK_EXTR(cap, in alloc_pdev()
368 if ( PCI_FUNC(devfn) >= pdev->phantom_stride ) in alloc_pdev()
369 pdev->phantom_stride = 0; in alloc_pdev()
381 pdev->phantom_stride = phantom_devs[i].stride; in alloc_pdev()
394 pseg->nr, bus, PCI_SLOT(devfn), PCI_FUNC(devfn), pdev->type); in alloc_pdev()
398 check_pdev(pdev); in alloc_pdev()
400 return pdev; in alloc_pdev()
403 static void free_pdev(struct pci_seg *pseg, struct pci_dev *pdev) in free_pdev() argument
406 switch ( pdev->type ) in free_pdev()
412 dev = PCI_SLOT(pdev->devfn); in free_pdev()
413 func = PCI_FUNC(pdev->devfn); in free_pdev()
414 sec_bus = pci_conf_read8(pseg->nr, pdev->bus, dev, func, in free_pdev()
416 sub_bus = pci_conf_read8(pseg->nr, pdev->bus, dev, func, in free_pdev()
421 pseg->bus2bridge[sec_bus] = pseg->bus2bridge[pdev->bus]; in free_pdev()
429 list_del(&pdev->alldevs_list); in free_pdev()
430 xfree(pdev->msix); in free_pdev()
431 xfree(pdev); in free_pdev()
434 static void _pci_hide_device(struct pci_dev *pdev) in _pci_hide_device() argument
436 if ( pdev->domain ) in _pci_hide_device()
438 pdev->domain = dom_xen; in _pci_hide_device()
439 list_add(&pdev->domain_list, &dom_xen->arch.pdev_list); in _pci_hide_device()
444 struct pci_dev *pdev; in pci_hide_device() local
448 pdev = alloc_pdev(get_pseg(0), bus, devfn); in pci_hide_device()
449 if ( pdev ) in pci_hide_device()
451 _pci_hide_device(pdev); in pci_hide_device()
462 struct pci_dev *pdev; in pci_ro_device() local
466 pdev = alloc_pdev(pseg, bus, devfn); in pci_ro_device()
467 if ( !pdev ) in pci_ro_device()
481 _pci_hide_device(pdev); in pci_ro_device()
489 struct pci_dev *pdev = NULL; in pci_get_pdev() local
504 list_for_each_entry ( pdev, &pseg->alldevs_list, alldevs_list ) in pci_get_pdev()
505 if ( (pdev->bus == bus || bus == -1) && in pci_get_pdev()
506 (pdev->devfn == devfn || devfn == -1) ) in pci_get_pdev()
507 return pdev; in pci_get_pdev()
516 struct pci_dev *pdev; in pci_get_real_pdev() local
522 for ( pdev = pci_get_pdev(seg, bus, devfn), stride = 4; in pci_get_real_pdev()
523 !pdev && stride; stride >>= 1 ) in pci_get_real_pdev()
527 pdev = pci_get_pdev(seg, bus, devfn & ~(8 - stride)); in pci_get_real_pdev()
528 if ( pdev && stride != pdev->phantom_stride ) in pci_get_real_pdev()
529 pdev = NULL; in pci_get_real_pdev()
532 return pdev; in pci_get_real_pdev()
539 struct pci_dev *pdev = NULL; in pci_get_pdev_by_domain() local
553 list_for_each_entry ( pdev, &pseg->alldevs_list, alldevs_list ) in pci_get_pdev_by_domain()
554 if ( (pdev->bus == bus || bus == -1) && in pci_get_pdev_by_domain()
555 (pdev->devfn == devfn || devfn == -1) && in pci_get_pdev_by_domain()
556 (pdev->domain == d) ) in pci_get_pdev_by_domain()
557 return pdev; in pci_get_pdev_by_domain()
568 static void pci_enable_acs(struct pci_dev *pdev) in pci_enable_acs() argument
571 u16 cap, ctrl, seg = pdev->seg; in pci_enable_acs()
572 u8 bus = pdev->bus; in pci_enable_acs()
573 u8 dev = PCI_SLOT(pdev->devfn); in pci_enable_acs()
574 u8 func = PCI_FUNC(pdev->devfn); in pci_enable_acs()
579 pos = pci_find_ext_capability(seg, bus, pdev->devfn, PCI_EXT_CAP_ID_ACS); in pci_enable_acs()
601 static int iommu_add_device(struct pci_dev *pdev);
602 static int iommu_enable_device(struct pci_dev *pdev);
603 static int iommu_remove_device(struct pci_dev *pdev);
609 struct pci_dev *pdev; in pci_add_device() local
620 pdev = pci_get_pdev(seg, info->physfn.bus, info->physfn.devfn); in pci_add_device()
621 if ( pdev ) in pci_add_device()
622 pf_is_extfn = pdev->info.is_extfn; in pci_add_device()
624 if ( !pdev ) in pci_add_device()
647 pdev = alloc_pdev(pseg, bus, devfn); in pci_add_device()
648 if ( !pdev ) in pci_add_device()
651 pdev->node = node; in pci_add_device()
655 pdev->info = *info; in pci_add_device()
660 if ( pdev->info.is_virtfn ) in pci_add_device()
661 pdev->info.is_extfn = pf_is_extfn; in pci_add_device()
663 else if ( !pdev->vf_rlen[0] ) in pci_add_device()
675 BUILD_BUG_ON(ARRAY_SIZE(pdev->vf_rlen) != PCI_SRIOV_NUM_BARS); in pci_add_device()
706 pdev->vf_rlen[i] = pci_conf_read32(seg, bus, slot, func, idx) & in pci_add_device()
711 pdev->vf_rlen[i] |= (u64)pci_conf_read32(seg, bus, in pci_add_device()
716 else if ( pdev->vf_rlen[i] ) in pci_add_device()
717 pdev->vf_rlen[i] |= (u64)~0 << 32; in pci_add_device()
719 pdev->vf_rlen[i] = -pdev->vf_rlen[i]; in pci_add_device()
732 check_pdev(pdev); in pci_add_device()
735 if ( !pdev->domain ) in pci_add_device()
737 pdev->domain = hardware_domain; in pci_add_device()
738 ret = iommu_add_device(pdev); in pci_add_device()
741 pdev->domain = NULL; in pci_add_device()
745 list_add(&pdev->domain_list, &hardware_domain->arch.pdev_list); in pci_add_device()
748 iommu_enable_device(pdev); in pci_add_device()
750 pci_enable_acs(pdev); in pci_add_device()
758 while ( pdev->phantom_stride ) in pci_add_device()
760 func += pdev->phantom_stride; in pci_add_device()
773 struct pci_dev *pdev; in pci_remove_device() local
786 list_for_each_entry ( pdev, &pseg->alldevs_list, alldevs_list ) in pci_remove_device()
787 if ( pdev->bus == bus && pdev->devfn == devfn ) in pci_remove_device()
789 ret = iommu_remove_device(pdev); in pci_remove_device()
790 if ( pdev->domain ) in pci_remove_device()
791 list_del(&pdev->domain_list); in pci_remove_device()
792 pci_cleanup_msi(pdev); in pci_remove_device()
793 free_pdev(pseg, pdev); in pci_remove_device()
853 struct pci_dev *pdev; in pci_release_devices() local
864 while ( (pdev = pci_get_pdev_by_domain(d, -1, -1, -1)) ) in pci_release_devices()
866 bus = pdev->bus; in pci_release_devices()
867 devfn = pdev->devfn; in pci_release_devices()
868 if ( deassign_device(d, pdev->seg, bus, devfn) ) in pci_release_devices()
870 d->domain_id, pdev->seg, bus, in pci_release_devices()
966 struct pci_dev *pdev; in pci_check_disable_device() local
971 pdev = pci_get_real_pdev(seg, bus, devfn); in pci_check_disable_device()
972 if ( pdev ) in pci_check_disable_device()
974 if ( now < pdev->fault.time || in pci_check_disable_device()
975 now - pdev->fault.time > MILLISECS(10) ) in pci_check_disable_device()
976 pdev->fault.count >>= 1; in pci_check_disable_device()
977 pdev->fault.time = now; in pci_check_disable_device()
978 if ( ++pdev->fault.count < PT_FAULT_THRESHOLD ) in pci_check_disable_device()
979 pdev = NULL; in pci_check_disable_device()
983 if ( !pdev ) in pci_check_disable_device()
988 devfn = pdev->devfn; in pci_check_disable_device()
1001 struct pci_dev *pdev; in _scan_pci_devices() local
1017 pdev = alloc_pdev(pseg, bus, PCI_DEVFN(dev, func)); in _scan_pci_devices()
1018 if ( !pdev ) in _scan_pci_devices()
1052 struct pci_dev *pdev) in setup_one_hwdom_device() argument
1054 u8 devfn = pdev->devfn; in setup_one_hwdom_device()
1057 int err = ctxt->handler(devfn, pdev); in setup_one_hwdom_device()
1062 pdev->seg, pdev->bus, PCI_SLOT(devfn), PCI_FUNC(devfn), in setup_one_hwdom_device()
1064 if ( devfn == pdev->devfn ) in setup_one_hwdom_device()
1067 devfn += pdev->phantom_stride; in setup_one_hwdom_device()
1068 } while ( devfn != pdev->devfn && in setup_one_hwdom_device()
1069 PCI_SLOT(devfn) == PCI_SLOT(pdev->devfn) ); in setup_one_hwdom_device()
1081 struct pci_dev *pdev = pci_get_pdev(pseg->nr, bus, devfn); in _setup_hwdom_pci_devices() local
1083 if ( !pdev ) in _setup_hwdom_pci_devices()
1086 if ( !pdev->domain ) in _setup_hwdom_pci_devices()
1088 pdev->domain = ctxt->d; in _setup_hwdom_pci_devices()
1089 list_add(&pdev->domain_list, &ctxt->d->arch.pdev_list); in _setup_hwdom_pci_devices()
1090 setup_one_hwdom_device(ctxt, pdev); in _setup_hwdom_pci_devices()
1092 else if ( pdev->domain == dom_xen ) in _setup_hwdom_pci_devices()
1094 pdev->domain = ctxt->d; in _setup_hwdom_pci_devices()
1095 setup_one_hwdom_device(ctxt, pdev); in _setup_hwdom_pci_devices()
1096 pdev->domain = dom_xen; in _setup_hwdom_pci_devices()
1098 else if ( pdev->domain != ctxt->d ) in _setup_hwdom_pci_devices()
1100 pdev->domain->domain_id, pseg->nr, bus, in _setup_hwdom_pci_devices()
1137 const struct pci_dev *pdev) in hest_match_pci() argument
1139 return ACPI_HEST_SEGMENT(p->bus) == pdev->seg && in hest_match_pci()
1140 ACPI_HEST_BUS(p->bus) == pdev->bus && in hest_match_pci()
1141 p->device == PCI_SLOT(pdev->devfn) && in hest_match_pci()
1142 p->function == PCI_FUNC(pdev->devfn); in hest_match_pci()
1146 const struct pci_dev *pdev) in hest_match_type() argument
1148 unsigned int pos = pci_find_cap_offset(pdev->seg, pdev->bus, in hest_match_type()
1149 PCI_SLOT(pdev->devfn), in hest_match_type()
1150 PCI_FUNC(pdev->devfn), in hest_match_type()
1152 u8 pcie = MASK_EXTR(pci_conf_read16(pdev->seg, pdev->bus, in hest_match_type()
1153 PCI_SLOT(pdev->devfn), in hest_match_type()
1154 PCI_FUNC(pdev->devfn), in hest_match_type()
1165 return pci_conf_read16(pdev->seg, pdev->bus, PCI_SLOT(pdev->devfn), in hest_match_type()
1166 PCI_FUNC(pdev->devfn), PCI_CLASS_DEVICE) == in hest_match_type()
1174 const struct pci_dev *pdev; member
1203 if ( !info->pdev ) in aer_hest_parse()
1211 hest_match_type(hest_hdr, info->pdev) : in aer_hest_parse()
1212 hest_match_pci(p, info->pdev) ) in aer_hest_parse()
1221 bool_t pcie_aer_get_firmware_first(const struct pci_dev *pdev) in pcie_aer_get_firmware_first() argument
1223 struct aer_hest_parse_info info = { .pdev = pdev }; in pcie_aer_get_firmware_first()
1225 return pci_find_cap_offset(pdev->seg, pdev->bus, PCI_SLOT(pdev->devfn), in pcie_aer_get_firmware_first()
1226 PCI_FUNC(pdev->devfn), PCI_CAP_ID_EXP) && in pcie_aer_get_firmware_first()
1234 struct pci_dev *pdev; in _dump_pci_devices() local
1239 list_for_each_entry ( pdev, &pseg->alldevs_list, alldevs_list ) in _dump_pci_devices()
1242 pseg->nr, pdev->bus, in _dump_pci_devices()
1243 PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn), in _dump_pci_devices()
1244 pdev->domain ? pdev->domain->domain_id : -1, in _dump_pci_devices()
1245 (pdev->node != NUMA_NO_NODE) ? pdev->node : -1); in _dump_pci_devices()
1246 list_for_each_entry ( msi, &pdev->msi_list, list ) in _dump_pci_devices()
1283 static int iommu_add_device(struct pci_dev *pdev) in iommu_add_device() argument
1289 if ( !pdev->domain ) in iommu_add_device()
1294 hd = dom_iommu(pdev->domain); in iommu_add_device()
1298 rc = hd->platform_ops->add_device(pdev->devfn, pci_to_dev(pdev)); in iommu_add_device()
1299 if ( rc || !pdev->phantom_stride ) in iommu_add_device()
1302 for ( devfn = pdev->devfn ; ; ) in iommu_add_device()
1304 devfn += pdev->phantom_stride; in iommu_add_device()
1305 if ( PCI_SLOT(devfn) != PCI_SLOT(pdev->devfn) ) in iommu_add_device()
1307 rc = hd->platform_ops->add_device(devfn, pci_to_dev(pdev)); in iommu_add_device()
1310 pdev->seg, pdev->bus, PCI_SLOT(devfn), PCI_FUNC(devfn), rc); in iommu_add_device()
1314 static int iommu_enable_device(struct pci_dev *pdev) in iommu_enable_device() argument
1318 if ( !pdev->domain ) in iommu_enable_device()
1323 hd = dom_iommu(pdev->domain); in iommu_enable_device()
1328 return hd->platform_ops->enable_device(pci_to_dev(pdev)); in iommu_enable_device()
1331 static int iommu_remove_device(struct pci_dev *pdev) in iommu_remove_device() argument
1336 if ( !pdev->domain ) in iommu_remove_device()
1339 hd = dom_iommu(pdev->domain); in iommu_remove_device()
1343 for ( devfn = pdev->devfn ; pdev->phantom_stride; ) in iommu_remove_device()
1347 devfn += pdev->phantom_stride; in iommu_remove_device()
1348 if ( PCI_SLOT(devfn) != PCI_SLOT(pdev->devfn) ) in iommu_remove_device()
1350 rc = hd->platform_ops->remove_device(devfn, pci_to_dev(pdev)); in iommu_remove_device()
1355 pdev->seg, pdev->bus, PCI_SLOT(devfn), PCI_FUNC(devfn), rc); in iommu_remove_device()
1359 return hd->platform_ops->remove_device(pdev->devfn, pci_to_dev(pdev)); in iommu_remove_device()
1368 struct pci_dev *pdev; in device_assigned() local
1371 pdev = pci_get_pdev_by_domain(hardware_domain, seg, bus, devfn); in device_assigned()
1374 return pdev ? 0 : -EBUSY; in device_assigned()
1380 struct pci_dev *pdev; in assign_device() local
1404 pdev = pci_get_pdev_by_domain(hardware_domain, seg, bus, devfn); in assign_device()
1405 if ( !pdev ) in assign_device()
1411 if ( pdev->msix ) in assign_device()
1414 pdev->fault.count = 0; in assign_device()
1416 if ( (rc = hd->platform_ops->assign_device(d, devfn, pci_to_dev(pdev), flag)) ) in assign_device()
1419 for ( ; pdev->phantom_stride; rc = 0 ) in assign_device()
1421 devfn += pdev->phantom_stride; in assign_device()
1422 if ( PCI_SLOT(devfn) != PCI_SLOT(pdev->devfn) ) in assign_device()
1424 rc = hd->platform_ops->assign_device(d, devfn, pci_to_dev(pdev), flag); in assign_device()
1443 struct pci_dev *pdev = NULL; in deassign_device() local
1450 pdev = pci_get_pdev_by_domain(d, seg, bus, devfn); in deassign_device()
1451 if ( !pdev ) in deassign_device()
1454 while ( pdev->phantom_stride ) in deassign_device()
1456 devfn += pdev->phantom_stride; in deassign_device()
1457 if ( PCI_SLOT(devfn) != PCI_SLOT(pdev->devfn) ) in deassign_device()
1460 pci_to_dev(pdev)); in deassign_device()
1469 devfn = pdev->devfn; in deassign_device()
1471 pci_to_dev(pdev)); in deassign_device()
1480 pdev->fault.count = 0; in deassign_device()
1493 struct pci_dev *pdev; in iommu_get_device_group() local
1505 for_each_pdev( d, pdev ) in iommu_get_device_group()
1507 if ( (pdev->seg != seg) || in iommu_get_device_group()
1508 ((pdev->bus == bus) && (pdev->devfn == devfn)) ) in iommu_get_device_group()
1511 if ( xsm_get_device_group(XSM_HOOK, (seg << 16) | (pdev->bus << 8) | pdev->devfn) ) in iommu_get_device_group()
1514 sdev_id = ops->get_device_group_id(seg, pdev->bus, pdev->devfn); in iommu_get_device_group()
1518 bdf |= (pdev->bus & 0xff) << 16; in iommu_get_device_group()
1519 bdf |= (pdev->devfn & 0xff) << 8; in iommu_get_device_group()
1535 void iommu_dev_iotlb_flush_timeout(struct domain *d, struct pci_dev *pdev) in iommu_dev_iotlb_flush_timeout() argument
1539 disable_ats_device(pdev); in iommu_dev_iotlb_flush_timeout()
1541 ASSERT(pdev->domain); in iommu_dev_iotlb_flush_timeout()
1542 if ( d != pdev->domain ) in iommu_dev_iotlb_flush_timeout()
1548 list_del(&pdev->domain_list); in iommu_dev_iotlb_flush_timeout()
1549 pdev->domain = NULL; in iommu_dev_iotlb_flush_timeout()
1550 _pci_hide_device(pdev); in iommu_dev_iotlb_flush_timeout()
1555 d->domain_id, pdev->seg, pdev->bus, PCI_SLOT(pdev->devfn), in iommu_dev_iotlb_flush_timeout()
1556 PCI_FUNC(pdev->devfn)); in iommu_dev_iotlb_flush_timeout()