From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=pass header.i=@infradead.org header.s=merlin.20170209 header.b=JXRdycTs; spf=none, err=permanent DNS error (domain: merlin.srs.infradead.org, ip: 205.233.59.134, mailfrom: batv+4a5a9edcbe01b6acb2b7+5785+infradead.org+dwmw2@merlin.srs.infradead.org) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by groups.io with SMTP; Wed, 26 Jun 2019 04:37:45 -0700 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=4lpnJwQsZZ/jqB6Fd/yH6C35fALzzH+062JnOt+a5vs=; b=JXRdycTsuJOq5jzUfoiepGkMfe yTzipu0VxmAD4o1UZ4LHTW8RZtXiEfP/4A+gxXUwld791P2zYVX2l68qVEXKyBGKE7EAMLdPH/EJ3 Bxe7qibRgbll8NrXTe6j2btU9vgkHoEuFlogbFnGP5DPD/voLVpcCmmXxw2ycCkoVvR78qzXoWvkC 4lo1faqD9mkIaxoPF7N5FrlHOZyTjFqW9DoBt21iw2j7JqQbvoB5dy7CtJKUTrRkn1lLRLgQksh/A Hb5Mvka7jW4HeGLHiHKJidFVq0lOWkR5EIlMuVzJzq5gkafc0zA5U9qXmo1PqZCDb3C5Md5wWNkQ4 7oEESHog==; Received: from [2001:8b0:10b:1::425] (helo=i7.infradead.org) by merlin.infradead.org with esmtpsa (Exim 4.92 #3 (Red Hat Linux)) id 1hg6FD-0006UA-DZ; Wed, 26 Jun 2019 11:37:43 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.92 #3 (Red Hat Linux)) id 1hg6FC-003RKF-Kj; Wed, 26 Jun 2019 12:37:42 +0100 From: "David Woodhouse" To: devel@edk2.groups.io Cc: Laszlo Ersek Subject: [PATCH v3 2/4] OvmfPkg/LegacyBbs: Add boot entries for VirtIO and NVME devices Date: Wed, 26 Jun 2019 12:37:40 +0100 Message-Id: <20190626113742.819933-3-dwmw2@infradead.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190626113742.819933-1-dwmw2@infradead.org> References: <20190626113742.819933-1-dwmw2@infradead.org> MIME-Version: 1.0 Sender: David Woodhouse X-SRS-Rewrite: SMTP reverse-path rewritten from by merlin.infradead.org. See http://www.infradead.org/rpr.html Content-Transfer-Encoding: 8bit Iterate over the available block devices in much the same way as BdsLibEnumerateAllBootOption() does, but limiting to those devices which are PCI-backed, which can be represented in the BbsTable. One day we might need to extend the BbsTable to allow us to distinguish between different NVMe namespaces on a device. Signed-off-by: David Woodhouse Acked-by: Laszlo Ersek --- OvmfPkg/Csm/LegacyBiosDxe/LegacyBbs.c | 157 +++++++++++++++++++++++++- 1 file changed, 152 insertions(+), 5 deletions(-) diff --git a/OvmfPkg/Csm/LegacyBiosDxe/LegacyBbs.c b/OvmfPkg/Csm/LegacyBiosDxe/LegacyBbs.c index 6b1dd344f344..5e4c7a249ef1 100644 --- a/OvmfPkg/Csm/LegacyBiosDxe/LegacyBbs.c +++ b/OvmfPkg/Csm/LegacyBiosDxe/LegacyBbs.c @@ -140,10 +140,14 @@ LegacyBiosBuildBbs ( IN BBS_TABLE *BbsTable ) { - UINTN BbsIndex; - HDD_INFO *HddInfo; - UINTN HddIndex; - UINTN Index; + UINTN BbsIndex; + HDD_INFO *HddInfo; + UINTN HddIndex; + UINTN Index; + EFI_HANDLE *BlockIoHandles; + UINTN NumberBlockIoHandles; + UINTN BlockIndex; + EFI_STATUS Status; // // First entry is floppy. @@ -252,8 +256,151 @@ LegacyBiosBuildBbs ( } } + // + // Add non-IDE block devices + // + BbsIndex = HddIndex * 2 + 1; + + Status = gBS->LocateHandleBuffer ( + ByProtocol, + &gEfiBlockIoProtocolGuid, + NULL, + &NumberBlockIoHandles, + &BlockIoHandles + ); + + if (!EFI_ERROR (Status)) { + UINTN Removable; + EFI_BLOCK_IO_PROTOCOL *BlkIo; + EFI_PCI_IO_PROTOCOL *PciIo; + EFI_DEVICE_PATH_PROTOCOL *DevicePath; + EFI_DEVICE_PATH_PROTOCOL *DevicePathNode; + EFI_HANDLE PciHandle; + UINTN SegNum; + UINTN BusNum; + UINTN DevNum; + UINTN FuncNum; + + for (Removable = 0; Removable < 2; Removable++) { + for (BlockIndex = 0; BlockIndex < NumberBlockIoHandles; BlockIndex++) { + Status = gBS->HandleProtocol ( + BlockIoHandles[BlockIndex], + &gEfiBlockIoProtocolGuid, + (VOID **) &BlkIo + ); + + if (EFI_ERROR (Status)) { + continue; + } + + // + // Skip the logical partitions + // + if (BlkIo->Media->LogicalPartition) { + continue; + } + + // + // Skip the fixed block io then the removable block io + // + if (BlkIo->Media->RemovableMedia == ((Removable == 0) ? FALSE : TRUE)) { + continue; + } + + // + // Get Device Path + // + Status = gBS->HandleProtocol ( + BlockIoHandles[BlockIndex], + &gEfiDevicePathProtocolGuid, + (VOID **) &DevicePath + ); + if (EFI_ERROR (Status)) { + continue; + } + + // + // Skip ATA devices as they have already been handled + // + DevicePathNode = DevicePath; + while (!IsDevicePathEnd (DevicePathNode)) { + if (DevicePathType (DevicePathNode) == MESSAGING_DEVICE_PATH && + DevicePathSubType (DevicePathNode) == MSG_ATAPI_DP) { + break; + } + DevicePathNode = NextDevicePathNode (DevicePathNode); + } + if (!IsDevicePathEnd (DevicePathNode)) { + continue; + } + + // + // Locate which PCI device + // + Status = gBS->LocateDevicePath ( + &gEfiPciIoProtocolGuid, + &DevicePath, + &PciHandle + ); + if (EFI_ERROR (Status)) { + continue; + } + + Status = gBS->HandleProtocol ( + PciHandle, + &gEfiPciIoProtocolGuid, + (VOID **) &PciIo + ); + if (EFI_ERROR (Status)) { + continue; + } + + Status = PciIo->GetLocation ( + PciIo, + &SegNum, + &BusNum, + &DevNum, + &FuncNum + ); + if (EFI_ERROR (Status)) { + continue; + } + + if (SegNum != 0) { + DEBUG ((DEBUG_WARN, "CSM cannot use PCI devices in segment %Lu\n", + (UINT64) SegNum)); + continue; + } + + DEBUG ((DEBUG_INFO, "Add Legacy Bbs entry for PCI %d/%d/%d\n", + BusNum, DevNum, FuncNum)); + + BbsTable[BbsIndex].Bus = BusNum; + BbsTable[BbsIndex].Device = DevNum; + BbsTable[BbsIndex].Function = FuncNum; + BbsTable[BbsIndex].Class = 1; + BbsTable[BbsIndex].SubClass = 0x80; + BbsTable[BbsIndex].StatusFlags.OldPosition = 0; + BbsTable[BbsIndex].StatusFlags.Reserved1 = 0; + BbsTable[BbsIndex].StatusFlags.Enabled = 0; + BbsTable[BbsIndex].StatusFlags.Failed = 0; + BbsTable[BbsIndex].StatusFlags.MediaPresent = 0; + BbsTable[BbsIndex].StatusFlags.Reserved2 = 0; + BbsTable[BbsIndex].DeviceType = BBS_HARDDISK; + BbsTable[BbsIndex].BootPriority = BBS_UNPRIORITIZED_ENTRY; + BbsIndex++; + + if (BbsIndex == MAX_BBS_ENTRIES) { + Removable = 2; + break; + } + } + } + + FreePool (BlockIoHandles); + } + return EFI_SUCCESS; - } -- 2.21.0