function locateAcpiDevice(dev) {
  if (!dev.isDevice()) {
    return null;
  }

  const addr = dev.address();
  const slotId = ((addr >>> 16) & 0xffff) >>> 0;
  const funcId = (addr & 0xffff) >>> 0;
  let busId = 0;

  if (dev.isRootBridge()) {
    busId = dev.getRootBridgeBusNumber();

    return {
      bus: busId,
      slot: slotId,
      func: funcId,
    };
  }

  const parentDev = dev.parent();
  if (parentDev === null) {
    return null;
  }

  if (!parentDev.isDevice()) {
    return null;
  }

  if (parentDev.isRootBridge()) {
    busId = parentDev.getRootBridgeBusNumber();

    return {
      bus: busId,
      slot: slotId,
      func: funcId,
    };
  }

  const parentLocation = locateAcpiDevice(parentDev);
  if (parentLocation === null) {
    return null;
  }

  const pciParent = pciAccessorFactory.get({
    bus: parentLocation.bus,
    slot: parentLocation.slot,
    func: parentLocation.func,
  });

  const header = pciParent.read(pciParent.fields().HEADER_TYPE);

  // Mask multifunction bit
  const headerType = (header & 0x7f) >>> 0;
  if (headerType !== 0x01 && headerType !== 0x02) {
    return null;
  }

  const bridgeBus = pciParent.read(pciParent.bridgeFields().SECONDARY_BUS);

  return {
    bus: bridgeBus,
    slot: slotId,
    func: funcId,
  };
}
function locateAcpiDevice(dev) {
  if (!dev.isDevice()) {
    return null;
  }

  const addr = dev.address();
  const slotId = ((addr >>> 16) & 0xffff) >>> 0;
  const funcId = (addr & 0xffff) >>> 0;
  let busId = 0;

  if (dev.isRootBridge()) {
    busId = dev.getRootBridgeBusNumber();

    return {
      bus: busId,
      slot: slotId,
      func: funcId,
    };
  }

  const parentDev = dev.parent();
  if (parentDev === null) {
    return null;
  }

  if (!parentDev.isDevice()) {
    return null;
  }

  if (parentDev.isRootBridge()) {
    busId = parentDev.getRootBridgeBusNumber();

    return {
      bus: busId,
      slot: slotId,
      func: funcId,
    };
  }

  const parentLocation = locateAcpiDevice(parentDev);
  if (parentLocation === null) {
    return null;
  }

  const pciParent = pciAccessorFactory.get({
    bus: parentLocation.bus,
    slot: parentLocation.slot,
    func: parentLocation.func,
  });

  const header = pciParent.read(pciParent.fields().HEADER_TYPE);

  
  const headerType = (header & 0x7f) >>> 0;
  if (headerType !== 0x01 && headerType !== 0x02) {
    return null;
  }

  const bridgeBus = pciParent.read(pciParent.bridgeFields().SECONDARY_BUS);

  return {
    bus: bridgeBus,
    slot: slotId,
    func: funcId,
  };
}
function locateAcpiDevice ( dev ) { if ( ! dev . isDevice ( ) ) { return null ; } const addr = dev . address ( ) ; const slotId = ( ( addr >>> 16 ) & 0xffff ) >>> 0 ; const funcId = ( addr & 0xffff ) >>> 0 ; let busId = 0 ; if ( dev . isRootBridge ( ) ) { busId = dev . getRootBridgeBusNumber ( ) ; return { bus : busId , slot : slotId , func : funcId , } ; } const parentDev = dev . parent ( ) ; if ( parentDev === null ) { return null ; } if ( ! parentDev . isDevice ( ) ) { return null ; } if ( parentDev . isRootBridge ( ) ) { busId = parentDev . getRootBridgeBusNumber ( ) ; return { bus : busId , slot : slotId , func : funcId , } ; } const parentLocation = locateAcpiDevice ( parentDev ) ; if ( parentLocation === null ) { return null ; } const pciParent = pciAccessorFactory . get ( { bus : parentLocation . bus , slot : parentLocation . slot , func : parentLocation . func , } ) ; const header = pciParent . read ( pciParent . fields ( ) . HEADER_TYPE ) ; // Mask multifunction bit const headerType = ( header & 0x7f ) >>> 0 ; if ( headerType !== 0x01 && headerType !== 0x02 ) { return null ; } const bridgeBus = pciParent . read ( pciParent . bridgeFields ( ) . SECONDARY_BUS ) ; return { bus : bridgeBus , slot : slotId , func : funcId , } ; }
Find ACPI PCI device bus, slot and function
Find ACPI PCI device bus slot and function