sys: Use is_pci_device instead of direct comparisons to devclasses
Reviewed by: bz Sponsored by: Chelsio Communications Differential Revision: https://reviews.freebsd.org/D56997
This commit is contained in:
@@ -760,8 +760,6 @@ thunder_pem_attach(device_t dev)
|
||||
{
|
||||
struct resource_map_request req;
|
||||
struct resource_map map;
|
||||
devclass_t pci_class;
|
||||
device_t parent;
|
||||
struct thunder_pem_softc *sc;
|
||||
int error;
|
||||
int rid;
|
||||
@@ -773,9 +771,7 @@ thunder_pem_attach(device_t dev)
|
||||
sc->dev = dev;
|
||||
|
||||
/* Allocate memory for resource */
|
||||
pci_class = devclass_find("pci");
|
||||
parent = device_get_parent(dev);
|
||||
if (device_get_devclass(parent) == pci_class)
|
||||
if (is_pci_device(dev))
|
||||
rid = PCIR_BAR(0);
|
||||
else
|
||||
rid = RID_PEM_SPACE;
|
||||
|
||||
@@ -1825,7 +1825,6 @@ smmu_ctx_init(device_t dev, struct iommu_ctx *ioctx)
|
||||
struct iommu_domain *iodom;
|
||||
struct smmu_softc *sc;
|
||||
struct smmu_ctx *ctx;
|
||||
devclass_t pci_class;
|
||||
u_int sid;
|
||||
int err;
|
||||
|
||||
@@ -1836,8 +1835,7 @@ smmu_ctx_init(device_t dev, struct iommu_ctx *ioctx)
|
||||
domain = ctx->domain;
|
||||
iodom = (struct iommu_domain *)domain;
|
||||
|
||||
pci_class = devclass_find("pci");
|
||||
if (device_get_devclass(device_get_parent(ctx->dev)) == pci_class) {
|
||||
if (is_pci_device(ctx->dev)) {
|
||||
err = smmu_pci_get_sid(ctx->dev, NULL, &sid);
|
||||
if (err)
|
||||
return (err);
|
||||
@@ -1863,7 +1861,7 @@ smmu_ctx_init(device_t dev, struct iommu_ctx *ioctx)
|
||||
|
||||
smmu_init_ste(sc, domain->cd, ctx->sid, ctx->bypass);
|
||||
|
||||
if (device_get_devclass(device_get_parent(ctx->dev)) == pci_class)
|
||||
if (is_pci_device((ctx->dev))
|
||||
if (iommu_is_buswide_ctx(iodom->iommu, pci_get_bus(ctx->dev)))
|
||||
smmu_set_buswide(dev, domain, ctx);
|
||||
|
||||
|
||||
@@ -399,8 +399,7 @@ int _lkpi_pci_enable_msi_range(struct pci_dev *pdev, int minvec, int maxvec);
|
||||
static inline bool
|
||||
dev_is_pci(struct device *dev)
|
||||
{
|
||||
return (device_get_devclass(device_get_parent(dev->bsddev)) ==
|
||||
devclass_find("pci"));
|
||||
return (is_pci_device(dev->bsddev));
|
||||
}
|
||||
|
||||
static inline uint16_t
|
||||
@@ -556,8 +555,7 @@ pci_upstream_bridge(struct pci_dev *pdev)
|
||||
bridge = device_get_parent(bridge);
|
||||
if (bridge == NULL)
|
||||
goto done;
|
||||
if (device_get_devclass(device_get_parent(bridge)) !=
|
||||
devclass_find("pci"))
|
||||
if (!is_pci_device(bridge))
|
||||
goto done;
|
||||
|
||||
/*
|
||||
|
||||
@@ -1176,8 +1176,7 @@ ataaction(struct cam_sim *sim, union ccb *ccb)
|
||||
cpi->protocol = PROTO_ATA;
|
||||
cpi->protocol_version = PROTO_VERSION_UNSPECIFIED;
|
||||
cpi->maxio = ch->dma.max_iosize ? ch->dma.max_iosize : DFLTPHYS;
|
||||
if (device_get_devclass(device_get_parent(parent)) ==
|
||||
devclass_find("pci")) {
|
||||
if (is_pci_device(parent)) {
|
||||
cpi->hba_vendor = pci_get_vendor(parent);
|
||||
cpi->hba_device = pci_get_device(parent);
|
||||
cpi->hba_subvendor = pci_get_subvendor(parent);
|
||||
|
||||
+3
-10
@@ -3202,20 +3202,13 @@ bge_mbox_reorder(struct bge_softc *sc)
|
||||
} mbox_reorder_lists[] = {
|
||||
{ 0x1022, 0x7450, "AMD-8131 PCI-X Bridge" },
|
||||
};
|
||||
devclass_t pci, pcib;
|
||||
device_t bus, dev;
|
||||
device_t dev;
|
||||
int i;
|
||||
|
||||
pci = devclass_find("pci");
|
||||
pcib = devclass_find("pcib");
|
||||
dev = sc->bge_dev;
|
||||
bus = device_get_parent(dev);
|
||||
for (;;) {
|
||||
dev = device_get_parent(bus);
|
||||
bus = device_get_parent(dev);
|
||||
if (device_get_devclass(dev) != pcib)
|
||||
break;
|
||||
if (device_get_devclass(bus) != pci)
|
||||
dev = device_get_parent(device_get_parent(dev));
|
||||
if (!is_pci_device(dev))
|
||||
break;
|
||||
for (i = 0; i < nitems(mbox_reorder_lists); i++) {
|
||||
if (pci_get_vendor(dev) ==
|
||||
|
||||
@@ -561,13 +561,12 @@ static device_t
|
||||
ichwd_find_ich_lpc_bridge(device_t isa, struct ichwd_device **id_p)
|
||||
{
|
||||
struct ichwd_device *id;
|
||||
device_t isab, pci;
|
||||
device_t isab;
|
||||
uint16_t devid;
|
||||
|
||||
/* Check whether parent ISA bridge looks familiar. */
|
||||
isab = device_get_parent(isa);
|
||||
pci = device_get_parent(isab);
|
||||
if (pci == NULL || device_get_devclass(pci) != devclass_find("pci"))
|
||||
if (!is_pci_device(isab))
|
||||
return (NULL);
|
||||
if (pci_get_vendor(isab) != VENDORID_INTEL)
|
||||
return (NULL);
|
||||
|
||||
@@ -117,17 +117,14 @@ iommu_bus_dma_is_dev_disabled(int domain, int bus, int slot, int func)
|
||||
int
|
||||
iommu_get_requester(device_t dev, device_t *requesterp, uint16_t *rid)
|
||||
{
|
||||
devclass_t pci_class;
|
||||
device_t l, pci, pcib, pcip, pcibp, requester;
|
||||
int cap_offset;
|
||||
uint16_t pcie_flags;
|
||||
bool bridge_is_pcie;
|
||||
|
||||
pci_class = devclass_find("pci");
|
||||
l = requester = dev;
|
||||
|
||||
pci = device_get_parent(dev);
|
||||
if (pci == NULL || device_get_devclass(pci) != pci_class) {
|
||||
if (!is_pci_device(dev)) {
|
||||
*rid = 0; /* XXXKIB: Could be ACPI HID */
|
||||
*requesterp = NULL;
|
||||
return (ENOTTY);
|
||||
@@ -141,29 +138,18 @@ iommu_get_requester(device_t dev, device_t *requesterp, uint16_t *rid)
|
||||
* unit.
|
||||
*/
|
||||
for (;;) {
|
||||
pci = device_get_parent(l);
|
||||
if (pci == NULL) {
|
||||
if (!is_pci_device(l)) {
|
||||
if (bootverbose) {
|
||||
printf(
|
||||
"iommu_get_requester(%s): NULL parent for %s\n",
|
||||
"iommu_get_requester(%s): non-pci ancestor %s\n",
|
||||
device_get_name(dev), device_get_name(l));
|
||||
}
|
||||
*rid = 0;
|
||||
*requesterp = NULL;
|
||||
return (ENXIO);
|
||||
}
|
||||
if (device_get_devclass(pci) != pci_class) {
|
||||
if (bootverbose) {
|
||||
printf(
|
||||
"iommu_get_requester(%s): non-pci parent %s for %s\n",
|
||||
device_get_name(dev), device_get_name(pci),
|
||||
device_get_name(l));
|
||||
}
|
||||
*rid = 0;
|
||||
*requesterp = NULL;
|
||||
return (ENXIO);
|
||||
}
|
||||
|
||||
pci = device_get_parent(l);
|
||||
pcib = device_get_parent(pci);
|
||||
if (pcib == NULL) {
|
||||
if (bootverbose) {
|
||||
@@ -182,10 +168,8 @@ iommu_get_requester(device_t dev, device_t *requesterp, uint16_t *rid)
|
||||
* port, and the requester ID won't be translated
|
||||
* further.
|
||||
*/
|
||||
pcip = device_get_parent(pcib);
|
||||
if (device_get_devclass(pcip) != pci_class)
|
||||
if (!is_pci_device(pcib))
|
||||
break;
|
||||
pcibp = device_get_parent(pcip);
|
||||
|
||||
if (pci_find_cap(l, PCIY_EXPRESS, &cap_offset) == 0) {
|
||||
/*
|
||||
@@ -212,6 +196,8 @@ iommu_get_requester(device_t dev, device_t *requesterp, uint16_t *rid)
|
||||
* PCI bridge, then we know pcib is actually a
|
||||
* PCIe/PCI bridge.
|
||||
*/
|
||||
pcip = device_get_parent(pcib);
|
||||
pcibp = device_get_parent(pcip);
|
||||
if (!bridge_is_pcie && pci_find_cap(pcibp,
|
||||
PCIY_EXPRESS, &cap_offset) == 0) {
|
||||
pcie_flags = pci_read_config(pcibp,
|
||||
@@ -337,11 +323,9 @@ bool
|
||||
bus_dma_iommu_set_buswide(device_t dev)
|
||||
{
|
||||
struct iommu_unit *unit;
|
||||
device_t parent;
|
||||
u_int busno, slot, func;
|
||||
|
||||
parent = device_get_parent(dev);
|
||||
if (device_get_devclass(parent) != devclass_find("pci"))
|
||||
if (!is_pci_device(dev))
|
||||
return (false);
|
||||
unit = iommu_find(dev, bootverbose);
|
||||
if (unit == NULL)
|
||||
|
||||
+2
-8
@@ -6535,11 +6535,9 @@ device_t
|
||||
pci_find_pcie_root_port(device_t dev)
|
||||
{
|
||||
struct pci_devinfo *dinfo;
|
||||
devclass_t pci_class;
|
||||
device_t pcib, bus;
|
||||
|
||||
pci_class = devclass_find("pci");
|
||||
KASSERT(device_get_devclass(device_get_parent(dev)) == pci_class,
|
||||
KASSERT(is_pci_device(dev),
|
||||
("%s: non-pci device %s", __func__, device_get_nameunit(dev)));
|
||||
|
||||
/*
|
||||
@@ -6555,11 +6553,7 @@ pci_find_pcie_root_port(device_t dev)
|
||||
KASSERT(pcib != NULL, ("%s: null bridge of %s", __func__,
|
||||
device_get_nameunit(bus)));
|
||||
|
||||
/*
|
||||
* pcib's parent must be a PCI bus for this to be a
|
||||
* PCI-PCI bridge.
|
||||
*/
|
||||
if (device_get_devclass(device_get_parent(pcib)) != pci_class)
|
||||
if (!is_pci_device(pcib))
|
||||
return (NULL);
|
||||
|
||||
dinfo = device_get_ivars(pcib);
|
||||
|
||||
@@ -111,8 +111,7 @@ vga_pci_is_boot_display(device_t dev)
|
||||
*/
|
||||
|
||||
pcib = device_get_parent(device_get_parent(dev));
|
||||
if (device_get_devclass(device_get_parent(pcib)) ==
|
||||
devclass_find("pci")) {
|
||||
if (is_pci_device(pcib)) {
|
||||
/*
|
||||
* The parent bridge is a PCI-to-PCI bridge: check the
|
||||
* value of the "VGA Enable" bit.
|
||||
@@ -186,8 +185,7 @@ vga_pci_map_bios(device_t dev, size_t *size)
|
||||
#endif
|
||||
|
||||
pcib = device_get_parent(device_get_parent(dev));
|
||||
if (device_get_devclass(device_get_parent(pcib)) ==
|
||||
devclass_find("pci")) {
|
||||
if (is_pci_device(pcib)) {
|
||||
/*
|
||||
* The parent bridge is a PCI-to-PCI bridge: check the
|
||||
* value of the "VGA Enable" bit.
|
||||
|
||||
@@ -285,11 +285,9 @@ bgx_fdt_traverse_nodes(uint8_t unit, phandle_t start, char *name,
|
||||
static device_t
|
||||
bgx_find_root_pcib(device_t dev)
|
||||
{
|
||||
devclass_t pci_class;
|
||||
device_t pcib, bus;
|
||||
|
||||
pci_class = devclass_find("pci");
|
||||
KASSERT(device_get_devclass(device_get_parent(dev)) == pci_class,
|
||||
KASSERT(is_pci_device(dev),
|
||||
("%s: non-pci device %s", __func__, device_get_nameunit(dev)));
|
||||
|
||||
/* Walk the bridge hierarchy until we find a non-PCI device */
|
||||
@@ -298,9 +296,6 @@ bgx_find_root_pcib(device_t dev)
|
||||
KASSERT(bus != NULL, ("%s: null parent of %s", __func__,
|
||||
device_get_nameunit(dev)));
|
||||
|
||||
if (device_get_devclass(bus) != pci_class)
|
||||
return (NULL);
|
||||
|
||||
pcib = device_get_parent(bus);
|
||||
KASSERT(pcib != NULL, ("%s: null bridge of %s", __func__,
|
||||
device_get_nameunit(bus)));
|
||||
@@ -309,7 +304,7 @@ bgx_find_root_pcib(device_t dev)
|
||||
* If the parent of this PCIB is not PCI
|
||||
* then we found our root PCIB.
|
||||
*/
|
||||
if (device_get_devclass(device_get_parent(pcib)) != pci_class)
|
||||
if (!is_pci_device(pcib))
|
||||
return (pcib);
|
||||
|
||||
dev = pcib;
|
||||
|
||||
@@ -894,8 +894,7 @@ amdiommu_find_unit(device_t dev, struct amdiommu_unit **unitp, uint16_t *ridp,
|
||||
if (!amdiommu_enable)
|
||||
return (ENXIO);
|
||||
|
||||
if (device_get_devclass(device_get_parent(dev)) !=
|
||||
devclass_find("pci"))
|
||||
if (!is_pci_device(dev))
|
||||
return (ENXIO);
|
||||
|
||||
bzero(&ifu, sizeof(ifu));
|
||||
|
||||
@@ -605,16 +605,13 @@ dmar_print_path(int busno, int depth, const ACPI_DMAR_PCI_PATH *path)
|
||||
int
|
||||
dmar_dev_depth(device_t child)
|
||||
{
|
||||
devclass_t pci_class;
|
||||
device_t bus, pcib;
|
||||
int depth;
|
||||
|
||||
pci_class = devclass_find("pci");
|
||||
for (depth = 1; ; depth++) {
|
||||
bus = device_get_parent(child);
|
||||
pcib = device_get_parent(bus);
|
||||
if (device_get_devclass(device_get_parent(pcib)) !=
|
||||
pci_class)
|
||||
if (!is_pci_device(pcib))
|
||||
return (depth);
|
||||
child = pcib;
|
||||
}
|
||||
@@ -623,19 +620,16 @@ dmar_dev_depth(device_t child)
|
||||
void
|
||||
dmar_dev_path(device_t child, int *busno, void *path1, int depth)
|
||||
{
|
||||
devclass_t pci_class;
|
||||
device_t bus, pcib;
|
||||
ACPI_DMAR_PCI_PATH *path;
|
||||
|
||||
pci_class = devclass_find("pci");
|
||||
path = path1;
|
||||
for (depth--; depth != -1; depth--) {
|
||||
path[depth].Device = pci_get_slot(child);
|
||||
path[depth].Function = pci_get_function(child);
|
||||
bus = device_get_parent(child);
|
||||
pcib = device_get_parent(bus);
|
||||
if (device_get_devclass(device_get_parent(pcib)) !=
|
||||
pci_class) {
|
||||
if (!is_pci_device(pcib)) {
|
||||
/* reached a host bridge */
|
||||
*busno = pcib_get_bus(bus);
|
||||
return;
|
||||
@@ -765,8 +759,7 @@ dmar_find(device_t dev, bool verbose)
|
||||
/*
|
||||
* This function can only handle PCI(e) devices.
|
||||
*/
|
||||
if (device_get_devclass(device_get_parent(dev)) !=
|
||||
devclass_find("pci"))
|
||||
if (!is_pci_device(dev))
|
||||
return (NULL);
|
||||
|
||||
dev_domain = pci_get_domain(dev);
|
||||
|
||||
Reference in New Issue
Block a user