From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [63.128.21.74]) by mx.groups.io with SMTP id smtpd.web12.5019.1585054061817977842 for ; Tue, 24 Mar 2020 05:47:42 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=GbhTt1v/; spf=pass (domain: redhat.com, ip: 63.128.21.74, mailfrom: lersek@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585054061; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2VPJjHFefm9nk83cM/gOSZapfy/GyBU2ijrXaHF+wqc=; b=GbhTt1v/qD437qLIRdC9G0kJaSv7hk+azJnC3WPuQxSC8GhCRBb1R1DsPMiUMmbgn5dOku L0HT2XW+rLVjWZp4dUnoN39SX+SWBhy/4Yt7E6mOeOmJGTGh8ci7dWvWz6tzdvx5Ugjr7v yZ8kQ8hQwlYevL4BLOexLHvyfp3/7As= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-490-AxwEZ4eCNAiFIqUwUWZvCQ-1; Tue, 24 Mar 2020 08:47:39 -0400 X-MC-Unique: AxwEZ4eCNAiFIqUwUWZvCQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E1123A0CC0; Tue, 24 Mar 2020 12:47:37 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-115-139.ams2.redhat.com [10.36.115.139]) by smtp.corp.redhat.com (Postfix) with ESMTP id 000615D9E5; Tue, 24 Mar 2020 12:47:34 +0000 (UTC) Subject: Re: [edk2-devel] [PATCH 05/17] OvmfPkg/PvScsiDxe: Install stubbed EXT_SCSI_PASS_THRU From: "Laszlo Ersek" To: devel@edk2.groups.io, liran.alon@oracle.com Cc: nikita.leshchenko@oracle.com, aaron.young@oracle.com, jordan.l.justen@intel.com, ard.biesheuvel@linaro.org References: <20200316150113.104630-1-liran.alon@oracle.com> <20200316150113.104630-6-liran.alon@oracle.com> <6e9f1702-5c10-6b84-6497-a32ee119acd1@redhat.com> Message-ID: <857644e5-4345-29d1-1015-2c19142f5203@redhat.com> Date: Tue, 24 Mar 2020 13:47:34 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <6e9f1702-5c10-6b84-6497-a32ee119acd1@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit On 03/24/20 13:27, Laszlo Ersek wrote: > On 03/16/20 16:01, Liran Alon wrote: >> Support dynamic insertion and removal of the protocol. >> >> Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2567 >> Reviewed-by: Nikita Leshenko >> Signed-off-by: Liran Alon >> --- >> OvmfPkg/PvScsiDxe/PvScsi.c | 209 ++++++++++++++++++++++++++++++++++- >> OvmfPkg/PvScsiDxe/PvScsi.h | 29 +++++ >> OvmfPkg/PvScsiDxe/PvScsi.inf | 5 +- >> 3 files changed, 240 insertions(+), 3 deletions(-) >> create mode 100644 OvmfPkg/PvScsiDxe/PvScsi.h >> >> diff --git a/OvmfPkg/PvScsiDxe/PvScsi.c b/OvmfPkg/PvScsiDxe/PvScsi.c >> index f1fffe962233..46b430a34a57 100644 >> --- a/OvmfPkg/PvScsiDxe/PvScsi.c >> +++ b/OvmfPkg/PvScsiDxe/PvScsi.c >> @@ -11,16 +11,155 @@ >> >> #include >> #include >> +#include >> #include >> #include >> #include >> >> +#include "PvScsi.h" >> + >> // >> // Higher versions will be used before lower, 0x10-0xffffffef is the version >> // range for IVH (Indie Hardware Vendors) >> // >> #define PVSCSI_BINDING_VERSION 0x10 >> >> +// >> +// Ext SCSI Pass Thru >> +// >> + >> +STATIC >> +EFI_STATUS >> +EFIAPI >> +PvScsiPassThru ( >> + IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This, >> + IN UINT8 *Target, >> + IN UINT64 Lun, >> + IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet, >> + IN EFI_EVENT Event OPTIONAL >> + ) >> +{ >> + return EFI_UNSUPPORTED; >> +} >> + >> +STATIC >> +EFI_STATUS >> +EFIAPI >> +PvScsiGetNextTargetLun ( >> + IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This, >> + IN OUT UINT8 **Target, >> + IN OUT UINT64 *Lun >> + ) >> +{ >> + return EFI_UNSUPPORTED; >> +} >> + >> +STATIC >> +EFI_STATUS >> +EFIAPI >> +PvScsiBuildDevicePath ( >> + IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This, >> + IN UINT8 *Target, >> + IN UINT64 Lun, >> + IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath >> + ) >> +{ >> + return EFI_UNSUPPORTED; >> +} >> + >> +STATIC >> +EFI_STATUS >> +EFIAPI >> +PvScsiGetTargetLun ( >> + IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This, >> + IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, >> + OUT UINT8 **Target, >> + OUT UINT64 *Lun >> + ) >> +{ >> + return EFI_UNSUPPORTED; >> +} >> + >> +STATIC >> +EFI_STATUS >> +EFIAPI >> +PvScsiResetChannel ( >> + IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This >> + ) >> +{ >> + return EFI_UNSUPPORTED; >> +} >> + >> +STATIC >> +EFI_STATUS >> +EFIAPI >> +PvScsiResetTargetLun ( >> + IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This, >> + IN UINT8 *Target, >> + IN UINT64 Lun >> + ) >> +{ >> + return EFI_UNSUPPORTED; >> +} >> + >> +STATIC >> +EFI_STATUS >> +EFIAPI >> +PvScsiGetNextTarget ( >> + IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This, >> + IN OUT UINT8 **Target >> + ) >> +{ >> + return EFI_UNSUPPORTED; >> +} >> + >> +STATIC >> +EFI_STATUS >> +PvScsiInit ( >> + IN OUT PVSCSI_DEV *Dev >> + ) >> +{ >> + // >> + // Populate the exported interface's attributes >> + // >> + Dev->PassThru.Mode = &Dev->PassThruMode; >> + Dev->PassThru.PassThru = &PvScsiPassThru; >> + Dev->PassThru.GetNextTargetLun = &PvScsiGetNextTargetLun; >> + Dev->PassThru.BuildDevicePath = &PvScsiBuildDevicePath; >> + Dev->PassThru.GetTargetLun = &PvScsiGetTargetLun; >> + Dev->PassThru.ResetChannel = &PvScsiResetChannel; >> + Dev->PassThru.ResetTargetLun = &PvScsiResetTargetLun; >> + Dev->PassThru.GetNextTarget = &PvScsiGetNextTarget; >> + >> + // >> + // AdapterId is a target for which no handle will be created during bus scan. >> + // Prevent any conflict with real devices. >> + // >> + Dev->PassThruMode.AdapterId = MAX_UINT32; >> + >> + // >> + // Set both physical and logical attributes for non-RAID SCSI channel >> + // >> + Dev->PassThruMode.Attributes = EFI_EXT_SCSI_PASS_THRU_ATTRIBUTES_PHYSICAL | >> + EFI_EXT_SCSI_PASS_THRU_ATTRIBUTES_LOGICAL; >> + >> + // >> + // No restriction on transfer buffer alignment >> + // >> + Dev->PassThruMode.IoAlign = 0; >> + >> + return EFI_SUCCESS; >> +} >> + >> +STATIC >> +VOID >> +PvScsiUninit ( >> + IN OUT PVSCSI_DEV *Dev >> + ) >> +{ >> + // Currently nothing to do here >> +} >> + >> // >> // Driver Binding >> // >> @@ -89,7 +228,42 @@ PvScsiDriverBindingStart ( >> IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL >> ) >> { >> - return EFI_UNSUPPORTED; >> + PVSCSI_DEV *Dev; >> + EFI_STATUS Status; >> + >> + Dev = (PVSCSI_DEV *) AllocateZeroPool (sizeof (*Dev)); >> + if (Dev == NULL) { >> + return EFI_OUT_OF_RESOURCES; >> + } >> + >> + Status = PvScsiInit (Dev); >> + if (EFI_ERROR (Status)) { >> + goto FreePvScsi; >> + } >> + >> + // >> + // Setup complete, attempt to export the driver instance's PassThru interface >> + // >> + Dev->Signature = PVSCSI_SIG; >> + Status = gBS->InstallProtocolInterface ( >> + &ControllerHandle, >> + &gEfiExtScsiPassThruProtocolGuid, >> + EFI_NATIVE_INTERFACE, >> + &Dev->PassThru >> + ); >> + if (EFI_ERROR (Status)) { >> + goto UninitDev; >> + } >> + >> + return EFI_SUCCESS; >> + >> +UninitDev: >> + PvScsiUninit (Dev); >> + >> +FreePvScsi: >> + FreePool (Dev); >> + >> + return Status; >> } >> >> STATIC >> @@ -102,7 +276,38 @@ PvScsiDriverBindingStop ( >> IN EFI_HANDLE *ChildHandleBuffer >> ) >> { >> - return EFI_UNSUPPORTED; >> + EFI_STATUS Status; >> + EFI_EXT_SCSI_PASS_THRU_PROTOCOL *PassThru; >> + PVSCSI_DEV *Dev; >> + >> + Status = gBS->OpenProtocol ( >> + ControllerHandle, >> + &gEfiExtScsiPassThruProtocolGuid, >> + (VOID **)&PassThru, >> + This->DriverBindingHandle, >> + ControllerHandle, >> + EFI_OPEN_PROTOCOL_GET_PROTOCOL // Lookup only >> + ); >> + if (EFI_ERROR (Status)) { >> + return Status; >> + } >> + >> + Dev = PVSCSI_FROM_PASS_THRU (PassThru); >> + >> + Status = gBS->UninstallProtocolInterface ( >> + ControllerHandle, >> + &gEfiExtScsiPassThruProtocolGuid, >> + &Dev->PassThru >> + ); >> + if (EFI_ERROR (Status)) { >> + return Status; >> + } >> + >> + PvScsiUninit (Dev); >> + >> + FreePool (Dev); >> + >> + return EFI_SUCCESS; >> } >> >> STATIC >> diff --git a/OvmfPkg/PvScsiDxe/PvScsi.h b/OvmfPkg/PvScsiDxe/PvScsi.h >> new file mode 100644 >> index 000000000000..3940b4c20019 >> --- /dev/null >> +++ b/OvmfPkg/PvScsiDxe/PvScsi.h >> @@ -0,0 +1,29 @@ >> +/** @file >> + >> + Internal definitions for the PVSCSI driver, which produces Extended SCSI >> + Pass Thru Protocol instances for pvscsi devices. >> + >> + Copyright (C) 2020, Oracle and/or its affiliates. >> + >> + SPDX-License-Identifier: BSD-2-Clause-Patent >> + >> +**/ >> + >> +#ifndef __PVSCSI_DXE_H_ >> +#define __PVSCSI_DXE_H_ >> + >> +#include >> +#include >> + >> +#define PVSCSI_SIG SIGNATURE_32 ('P', 'S', 'C', 'S') >> + >> +typedef struct { >> + UINT32 Signature; >> + EFI_EXT_SCSI_PASS_THRU_PROTOCOL PassThru; >> + EFI_EXT_SCSI_PASS_THRU_MODE PassThruMode; >> +} PVSCSI_DEV; >> + >> +#define PVSCSI_FROM_PASS_THRU(PassThruPointer) \ >> + CR (PassThruPointer, PVSCSI_DEV, PassThru, PVSCSI_SIG) >> + >> +#endif // __PVSCSI_DXE_H_ >> diff --git a/OvmfPkg/PvScsiDxe/PvScsi.inf b/OvmfPkg/PvScsiDxe/PvScsi.inf >> index c1f0663832ed..3a8b07872ba3 100644 >> --- a/OvmfPkg/PvScsiDxe/PvScsi.inf >> +++ b/OvmfPkg/PvScsiDxe/PvScsi.inf >> @@ -25,9 +25,12 @@ >> OvmfPkg/OvmfPkg.dec >> >> [LibraryClasses] >> + DebugLib >> + MemoryAllocationLib >> UefiBootServicesTableLib >> UefiDriverEntryPoint >> UefiLib >> >> [Protocols] >> - gEfiPciIoProtocolGuid ## TO_START >> + gEfiPciIoProtocolGuid ## TO_START >> + gEfiExtScsiPassThruProtocolGuid ## BY_START >> > > (1) In the [Sources] section of the INF file, please list the new header > file ("PvScsi.h"). (2) Please keep the list of protocols lexicographically sorted. (I understand that you may have intended to place BY_START logically under TO_START -- that looks simple enough initially, but with time it can get messy. With normal sorting, there's never any doubt though.) > > With that: > > Reviewed-by: Laszlo Ersek This stands. Thanks Laszlo