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.web11.69745.1584370820057606187 for ; Mon, 16 Mar 2020 08:00:20 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=ZbbPMPYA; spf=pass (domain: oracle.com, ip: 156.151.31.86, mailfrom: liran.alon@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 02GEqih9088803; Mon, 16 Mar 2020 15:00:19 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=C2BQUV3hvJnkiQKotSo/wQ3k/aXNIavP+KLj5h3rQ+M=; b=ZbbPMPYAOGJN37nmpGHGPx5gCbbURmlWQXQzc75qv4QIraaHzp7xG7aIMC6dLkwQEtHf eTtX5KRr3Lqz2fMo5Z6+2oS26pt+RGoUCi6qbO2e0XudmvpFatYaoBz9K/CmLc+GKyKf 5o8m/i555s1QmNpb95bQ50pexSpJRGUOaXK1siIfSGf72tLLiXHFUn2MTLeGVcyjFgzb 50uwB4oM3kqpxGTzek8lKGyTswijvlATlrs/kV2nfDMXyMDlh9ShiHMQqceFl3HEbMTc dwtd682qEWESnxwp17VVc5iAxO1KqX5DjTPXnzVxTAySkrQvzJ36m/NCPkRXvuU1dNX2 +w== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2130.oracle.com with ESMTP id 2yrppqyfbh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 16 Mar 2020 15:00:19 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 02GEpX3Q074902; Mon, 16 Mar 2020 15:00:18 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3020.oracle.com with ESMTP id 2ys929utsd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 16 Mar 2020 15:00:17 +0000 Received: from abhmp0009.oracle.com (abhmp0009.oracle.com [141.146.116.15]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 02GF0FCi011437; Mon, 16 Mar 2020 15:00:16 GMT Received: from spark.ravello.local (/213.57.127.2) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 16 Mar 2020 08:00:15 -0700 From: "Liran Alon" To: devel@edk2.groups.io, lersek@redhat.com Cc: nikita.leshchenko@oracle.com, aaron.young@oracle.com, jordan.l.justen@intel.com, ard.biesheuvel@linaro.org, Liran Alon Subject: [PATCH 05/17] OvmfPkg/PvScsiDxe: Install stubbed EXT_SCSI_PASS_THRU Date: Mon, 16 Mar 2020 17:01:01 +0200 Message-Id: <20200316150113.104630-6-liran.alon@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200316150113.104630-1-liran.alon@oracle.com> References: <20200316150113.104630-1-liran.alon@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9561 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxlogscore=999 mlxscore=0 spamscore=0 bulkscore=0 adultscore=0 suspectscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2003160072 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9561 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 bulkscore=0 suspectscore=0 lowpriorityscore=0 phishscore=0 adultscore=0 clxscore=1015 impostorscore=0 priorityscore=1501 spamscore=0 mlxlogscore=999 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2003160072 Content-Transfer-Encoding: 8bit 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 -- 2.20.1