From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from userp2130.oracle.com (userp2130.oracle.com [156.151.31.86]) by mx.groups.io with SMTP id smtpd.web12.10854.1582735233286776522 for ; Wed, 26 Feb 2020 08:40:33 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=zP/kK+ys; spf=pass (domain: oracle.com, ip: 156.151.31.86, mailfrom: nikita.leshchenko@oracle.com) Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01QGNU7k078105; Wed, 26 Feb 2020 16:40:32 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2020-01-29; bh=DZpHTOU8uJVoUNH4S/U0zqPF8gzm6ePJfj9OGvX7g7U=; b=zP/kK+ysjRpJqB7oKf54RzBVQsYbdeMWCCImxux7NDofPH2RiRc3vhveyxLBLORQ0ooN zJLFgpIpOxh2sythvSm8Kb+VLmTQU7Cggnv3TGhukbK35Wxol98rBn/DL9VW/OAFd8Gy 3by8NFrZBJimxKwxjNd2xU4eGkrkX3bKRQf4aI2VuISHeBDIK1cs9sLHX+n0lGD5pb6m JmYj+9ssy+qICDEHMx6x7M51q6uhUwuaLCkNwA9gXWALogsBvNNj2yimeXtHmw2P2qYg GTgj5FXnvP3eiHixa2lrLD/jqj7oAX69wI4l+4wR+Pg2iCanQM1TlE5ByMt2de3LfOfW VA== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2130.oracle.com with ESMTP id 2ydcsncvu6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 26 Feb 2020 16:40:32 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01QGMhXs076573; Wed, 26 Feb 2020 16:40:31 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3030.oracle.com with ESMTP id 2ydcsa6pqa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 26 Feb 2020 16:40:31 +0000 Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 01QGeVrU010522; Wed, 26 Feb 2020 16:40:31 GMT Received: from spark.ravello.local (/213.57.127.2) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 26 Feb 2020 08:40:31 -0800 From: "Nikita Leshenko" To: devel@edk2.groups.io Cc: liran.alon@oracle.com, aaron.young@oracle.com, jordan.l.justen@intel.com, lersek@redhat.com, ard.biesheuvel@linaro.org, Nikita Leshenko Subject: [PATCH v2 05/13] OvmfPkg/MptScsiDxe: Install stubbed EXT_SCSI_PASS_THRU Date: Wed, 26 Feb 2020 18:41:43 +0200 Message-Id: <20200226164151.125182-6-nikita.leshchenko@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200226164151.125182-1-nikita.leshchenko@oracle.com> References: <20200226164151.125182-1-nikita.leshchenko@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9543 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 bulkscore=0 spamscore=0 mlxlogscore=999 mlxscore=0 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002260112 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9543 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 malwarescore=0 bulkscore=0 lowpriorityscore=0 mlxlogscore=999 phishscore=0 spamscore=0 adultscore=0 suspectscore=0 impostorscore=0 clxscore=1015 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002260112 Content-Transfer-Encoding: 8bit Support dynamic insertion and removal of the protocol Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2390 Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Nikita Leshenko Reviewed-by: Konrad Rzeszutek Wilk Reviewed-by: Aaron Young Reviewed-by: Liran Alon --- OvmfPkg/MptScsiDxe/MptScsi.c | 178 +++++++++++++++++++++++++++++- OvmfPkg/MptScsiDxe/MptScsiDxe.inf | 5 +- 2 files changed, 180 insertions(+), 3 deletions(-) diff --git a/OvmfPkg/MptScsiDxe/MptScsi.c b/OvmfPkg/MptScsiDxe/MptScsi.c index 6dc6257eba..b8eabfb23c 100644 --- a/OvmfPkg/MptScsiDxe/MptScsi.c +++ b/OvmfPkg/MptScsiDxe/MptScsi.c @@ -17,10 +17,13 @@ #include #include +#include #include +#include #include #include #include +#include // // Higher versions will be used before lower, 0x10-0xffffffef is the version @@ -28,6 +31,109 @@ // #define MPT_SCSI_BINDING_VERSION 0x10 +// +// Runtime Structures +// + +#define MPT_SCSI_DEV_SIGNATURE SIGNATURE_32 ('M','P','T','S') +typedef struct { + UINT32 Signature; + EFI_EXT_SCSI_PASS_THRU_PROTOCOL PassThru; + EFI_EXT_SCSI_PASS_THRU_MODE PassThruMode; +} MPT_SCSI_DEV; + +#define MPT_SCSI_FROM_PASS_THRU(PassThruPtr) \ + CR (PassThruPtr, MPT_SCSI_DEV, PassThru, MPT_SCSI_DEV_SIGNATURE) + +// +// Ext SCSI Pass Thru +// + +STATIC +EFI_STATUS +EFIAPI +MptScsiPassThru ( + 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 +MptScsiGetNextTargetLun ( + IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This, + IN OUT UINT8 **Target, + IN OUT UINT64 *Lun + ) +{ + return EFI_UNSUPPORTED; +} + +STATIC +EFI_STATUS +EFIAPI +MptScsiGetNextTarget ( + IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This, + IN OUT UINT8 **Target + ) +{ + return EFI_UNSUPPORTED; +} + +STATIC +EFI_STATUS +EFIAPI +MptScsiBuildDevicePath ( + 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 +MptScsiGetTargetLun ( + 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 +MptScsiResetChannel ( + IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This + ) +{ + return EFI_UNSUPPORTED; +} + +STATIC +EFI_STATUS +EFIAPI +MptScsiResetTargetLun ( + IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This, + IN UINT8 *Target, + IN UINT64 Lun + ) +{ + return EFI_UNSUPPORTED; +} + // // Driver Binding // @@ -96,7 +202,49 @@ MptScsiControllerStart ( IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL ) { - return EFI_UNSUPPORTED; + EFI_STATUS Status; + MPT_SCSI_DEV *Dev; + + Dev = AllocateZeroPool (sizeof (*Dev)); + if (Dev == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + Dev->Signature = MPT_SCSI_DEV_SIGNATURE; + + // + // Host adapter channel, doesn't exist + // + Dev->PassThruMode.AdapterId = MAX_UINT32; + Dev->PassThruMode.Attributes = + EFI_EXT_SCSI_PASS_THRU_ATTRIBUTES_PHYSICAL + | EFI_EXT_SCSI_PASS_THRU_ATTRIBUTES_LOGICAL; + + Dev->PassThru.Mode = &Dev->PassThruMode; + Dev->PassThru.PassThru = &MptScsiPassThru; + Dev->PassThru.GetNextTargetLun = &MptScsiGetNextTargetLun; + Dev->PassThru.BuildDevicePath = &MptScsiBuildDevicePath; + Dev->PassThru.GetTargetLun = &MptScsiGetTargetLun; + Dev->PassThru.ResetChannel = &MptScsiResetChannel; + Dev->PassThru.ResetTargetLun = &MptScsiResetTargetLun; + Dev->PassThru.GetNextTarget = &MptScsiGetNextTarget; + + Status = gBS->InstallProtocolInterface ( + &ControllerHandle, + &gEfiExtScsiPassThruProtocolGuid, + EFI_NATIVE_INTERFACE, + &Dev->PassThru + ); + if (EFI_ERROR (Status)) { + goto Done; + } + +Done: + if (EFI_ERROR (Status)) { + FreePool (Dev); + } + + return Status; } STATIC @@ -109,7 +257,33 @@ MptScsiControllerStop ( IN EFI_HANDLE *ChildHandleBuffer ) { - return EFI_UNSUPPORTED; + EFI_STATUS Status; + EFI_EXT_SCSI_PASS_THRU_PROTOCOL *PassThru; + MPT_SCSI_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 = MPT_SCSI_FROM_PASS_THRU (PassThru); + + gBS->UninstallProtocolInterface ( + ControllerHandle, + &gEfiExtScsiPassThruProtocolGuid, + &Dev->PassThru + ); + + FreePool (Dev); + + return Status; } STATIC diff --git a/OvmfPkg/MptScsiDxe/MptScsiDxe.inf b/OvmfPkg/MptScsiDxe/MptScsiDxe.inf index dc3795c867..1cb5df4233 100644 --- a/OvmfPkg/MptScsiDxe/MptScsiDxe.inf +++ b/OvmfPkg/MptScsiDxe/MptScsiDxe.inf @@ -30,10 +30,13 @@ OvmfPkg/OvmfPkg.dec [LibraryClasses] + BaseMemoryLib DebugLib + MemoryAllocationLib UefiBootServicesTableLib UefiDriverEntryPoint UefiLib [Protocols] - gEfiPciIoProtocolGuid ## TO_START + gEfiPciIoProtocolGuid ## TO_START + gEfiExtScsiPassThruProtocolGuid ## BY_START -- 2.20.1