From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=141.146.126.79; helo=aserp2130.oracle.com; envelope-from=nikita.leshchenko@oracle.com; receiver=edk2-devel@lists.01.org Received: from aserp2130.oracle.com (aserp2130.oracle.com [141.146.126.79]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 0F473211C385E for ; Thu, 31 Jan 2019 02:08:08 -0800 (PST) Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id x0VA4jAd154387 for ; Thu, 31 Jan 2019 10:08:08 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-2018-07-02; bh=Ab4Rd1JJw9Fxboo/ux5xqvvqkPB5QZdzo+8gfP8hS9Q=; b=lg7dubxWumfQ6iXAr/MAKfGhvXLg+ZUvB0385oTWC2XrxUHbXPB/yBmKDl6jMqsHeUhI 9p9oUj11hTXSmzkqs7HxhDHppHXb6sBE9L0oNuMtGb7WiQeTX4xud39hbvQj2XYC9sVu 7KDe+uh49C0Ye1ouck06xMwit2GQQwZ6PhvI5Yy+LM1GyQK1Us/D4GSa2rbbOYzf/OEY wuv0hMgbIrWMcniV37NOhIbpKYWpJLjxzA8kTsb4O1b9u2Nc5lsy3M1v3aVh9uHPDNjk bGtNQnxMf6NWsTCxihHag3g7yy3B/mue6szpR6dYO0zMvqJE2v7D2aJ/x7eS73rcEP/5 iw== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp2130.oracle.com with ESMTP id 2q8d2efvah-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 31 Jan 2019 10:08:08 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x0VA87lL004680 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 31 Jan 2019 10:08:07 GMT Received: from abhmp0013.oracle.com (abhmp0013.oracle.com [141.146.116.19]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x0VA875v012890 for ; Thu, 31 Jan 2019 10:08:07 GMT Received: from spark.ravello.local (/213.57.127.2) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 31 Jan 2019 02:08:07 -0800 From: Nikita Leshenko To: edk2-devel@lists.01.org Cc: liran.alon@oracle.com, Nikita Leshenko Date: Thu, 31 Jan 2019 12:07:15 +0200 Message-Id: <20190131100724.20907-6-nikita.leshchenko@oracle.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190131100724.20907-1-nikita.leshchenko@oracle.com> References: <20190131100724.20907-1-nikita.leshchenko@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9152 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1901310080 Subject: [PATCH 05/14] OvmfPkg/MptScsiDxe: Install stubbed EXT_SCSI_PASS_THRU X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 31 Jan 2019 10:08:09 -0000 Content-Transfer-Encoding: 8bit Support dynamic insertion and removal of the protocol 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 | 204 +++++++++++++++++++++++++++++- OvmfPkg/MptScsiDxe/MptScsiDxe.inf | 5 +- 2 files changed, 205 insertions(+), 4 deletions(-) diff --git a/OvmfPkg/MptScsiDxe/MptScsi.c b/OvmfPkg/MptScsiDxe/MptScsi.c index 57a17ca0cb..6b655d9fe8 100644 --- a/OvmfPkg/MptScsiDxe/MptScsi.c +++ b/OvmfPkg/MptScsiDxe/MptScsi.c @@ -16,10 +16,13 @@ **/ #include +#include #include +#include #include #include #include +#include // // Device offsets and constants @@ -30,6 +33,118 @@ #define LSI_SAS1068_PCI_DEVICE_ID 0x0054 #define LSI_SAS1068E_PCI_DEVICE_ID 0x0058 +// +// 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 + ) +{ + DEBUG ((EFI_D_INFO, "MptScsiPassThru Direction %d In %d Out %d\n", + Packet->DataDirection, + Packet->InTransferLength, Packet->OutTransferLength)); + return EFI_UNSUPPORTED; +} + +STATIC +EFI_STATUS +EFIAPI +MptScsiGetNextTargetLun ( + IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This, + IN OUT UINT8 **Target, + IN OUT UINT64 *Lun + ) +{ + DEBUG ((EFI_D_INFO, "MptScsiGetNextTargetLun %d %d\n", **Target, *Lun)); + return EFI_UNSUPPORTED; +} + +STATIC +EFI_STATUS +EFIAPI +MptScsiGetNextTarget ( + IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This, + IN OUT UINT8 **Target + ) +{ + DEBUG ((EFI_D_INFO, "MptScsiGetNextTarget\n")); + 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 + ) +{ + DEBUG ((EFI_D_INFO, "MptScsiBuildDevicePath %d %d\n", *Target, Lun)); + 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 + ) +{ + DEBUG ((EFI_D_INFO, "MptScsiGetTargetLun\n")); + return EFI_UNSUPPORTED; +} + +STATIC +EFI_STATUS +EFIAPI +MptScsiResetChannel ( + IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This + ) +{ + DEBUG ((EFI_D_INFO, "MptScsiResetChannel\n")); + return EFI_UNSUPPORTED; +} + +STATIC +EFI_STATUS +EFIAPI +MptScsiResetTargetLun ( + IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This, + IN UINT8 *Target, + IN UINT64 Lun + ) +{ + DEBUG ((EFI_D_INFO, "MptScsiResetTargetLun\n")); + return EFI_UNSUPPORTED; +} + // // Driver Binding // @@ -94,8 +209,65 @@ MptScsiControllerStart ( IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL ) { - DEBUG ((EFI_D_INFO, "Attempted to start MptScsi\n")); - return EFI_UNSUPPORTED; + EFI_STATUS Status; + EFI_PHYSICAL_ADDRESS PhysicalAddress; + MPT_SCSI_DEV *Dev; + + DEBUG ((EFI_D_INFO, "Starting MptScsi\n")); + + // + // MPT_SCSI_DEV contains descriptors that are passed to the controller. The + // controller doesn't easily support addresses larger than 4GB, so we allocate + // the struct below 4GB. (Technically we can use HostMfaHighAddr and make sure + // all descriptors have the same high address but it's more complicated than + // just allocating below 4GB. Also, we allocate it only once per device so the + // overhead of allocating a whole page is minimal.) + // + PhysicalAddress = MAX_UINT32; + Status = gBS->AllocatePages ( + AllocateMaxAddress, + EfiRuntimeServicesData, + EFI_SIZE_TO_PAGES (sizeof (*Dev)), + &PhysicalAddress + ); + if (EFI_ERROR (Status)) { + return EFI_OUT_OF_RESOURCES; + } + + // PhysicalAddress is page aligned, so MPT_SCSI_DEV alignment is correct + Dev = (MPT_SCSI_DEV *) (UINTN) PhysicalAddress; + ZeroMem (Dev, sizeof (*Dev)); + Dev->Signature = MPT_SCSI_DEV_SIGNATURE; + + Dev->PassThruMode.AdapterId = MAX_UINT32; // Host adapter channel, doesn't exist + 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; + } + + DEBUG ((EFI_D_INFO, "MptScsi Installed\n")); +Done: + if (EFI_ERROR (Status)) { + gBS->FreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) Dev, EFI_SIZE_TO_PAGES (sizeof (*Dev))); + } + + return Status; } STATIC @@ -108,7 +280,33 @@ MptScsiControllerStop ( IN EFI_HANDLE *ChildHandleBuffer ) { - return EFI_UNSUPPORTED; + EFI_STATUS Status; + EFI_EXT_SCSI_PASS_THRU_PROTOCOL *PassThru; + MPT_SCSI_DEV *Dev = NULL; + + DEBUG ((EFI_D_INFO, "Stopping MptScsi\n")); + + 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); + + gBS->FreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) Dev, EFI_SIZE_TO_PAGES (sizeof (*Dev))); + + return Status; } // Higher versions will be used before lower, 0x10-0xffffffef is the version diff --git a/OvmfPkg/MptScsiDxe/MptScsiDxe.inf b/OvmfPkg/MptScsiDxe/MptScsiDxe.inf index 3608cecaab..5d424606a5 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 \ No newline at end of file + gEfiPciIoProtocolGuid ## TO_START + gEfiExtScsiPassThruProtocolGuid ## BY_START -- 2.20.1