From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.65; helo=mga03.intel.com; envelope-from=jaben.carsey@intel.com; receiver=edk2-devel@lists.01.org Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) (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 037E421FCA296 for ; Wed, 1 Nov 2017 11:12:04 -0700 (PDT) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 01 Nov 2017 11:15:57 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,330,1505804400"; d="scan'208";a="1238307086" Received: from fmsmsx105.amr.corp.intel.com ([10.18.124.203]) by fmsmga002.fm.intel.com with ESMTP; 01 Nov 2017 11:15:56 -0700 Received: from FMSMSX109.amr.corp.intel.com (10.18.116.9) by FMSMSX105.amr.corp.intel.com (10.18.124.203) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 1 Nov 2017 11:15:56 -0700 Received: from fmsmsx103.amr.corp.intel.com ([169.254.2.117]) by FMSMSX109.amr.corp.intel.com ([169.254.15.122]) with mapi id 14.03.0319.002; Wed, 1 Nov 2017 11:15:56 -0700 From: "Carsey, Jaben" To: "Ni, Ruiyu" , "edk2-devel@lists.01.org" Thread-Topic: [PATCH] ShellPkg/hexeditor: Use CpuIo for memory access Thread-Index: AQHTUvoRECF7aRrjaUqmNVuGvFBEYqL/1PEQ Date: Wed, 1 Nov 2017 18:15:56 +0000 Message-ID: References: <20171101101316.59648-1-ruiyu.ni@intel.com> In-Reply-To: <20171101101316.59648-1-ruiyu.ni@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiOTRiOGQ0ZDgtOWQ1YS00YjlhLWI5YzYtNmVkM2JhZDU5MmEyIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX0lDIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE2LjUuOS4zIiwiVHJ1c3RlZExhYmVsSGFzaCI6IkY1RGVnOHJLK0tBZ1hxMFJ4TzVNS1dISXFpZDlsem1xTmpmUTlzNFRQYnM9In0= x-ctpclassification: CTP_IC x-originating-ip: [10.1.200.106] MIME-Version: 1.0 Subject: Re: [PATCH] ShellPkg/hexeditor: Use CpuIo for memory access X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Nov 2017 18:12:05 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Jaben Carsey > -----Original Message----- > From: Ni, Ruiyu > Sent: Wednesday, November 01, 2017 3:13 AM > To: edk2-devel@lists.01.org > Cc: Carsey, Jaben > Subject: [PATCH] ShellPkg/hexeditor: Use CpuIo for memory access > Importance: High >=20 > The original code uses PciRootBridgeIo for memory access. > It worked before MdeModulePkg/PciHostBridgeDxe driver was checked in. > But MdeModulePkg/PciHostBridgeDxe adds checks to ensure the MMIO > access request is in the scope of the current RootBridgeIo instance. > It causes "hexeditor -m 0 2" reports error because memory address 0 > surely is not in the scope of any RootBridgeIo instance. > In fact only accessing the MMIO space occupied by the RootBridgeIo > can work. >=20 > The patch changes hexeditor to use CpuIo for memory access. >=20 > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Ruiyu Ni > Cc: Jaben Carsey > --- > .../HexEdit/HexEditorTypes.h | 9 ++- > .../UefiShellDebug1CommandsLib/HexEdit/MemImage.c | 65 +---------------= - > ----- > 2 files changed, 6 insertions(+), 68 deletions(-) >=20 > diff --git > a/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/HexEditorTypes. > h > b/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/HexEditorTypes. > h > index ddd6070c94..8f0da3b667 100644 > --- > a/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/HexEditorTypes. > h > +++ > b/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/HexEditorTypes. > h > @@ -1,7 +1,7 @@ > /** @file > data types that are used by editor >=20 > - Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. > + Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved. > This program and the accompanying materials > are licensed and made available under the terms and conditions of the = BSD > License > which accompanies this distribution. The full text of the license may= be > found at > @@ -78,10 +78,9 @@ typedef struct { > } HEFI_EDITOR_DISK_IMAGE; >=20 > typedef struct { > - EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *IoFncs; > - > - UINTN Offset; > - UINTN Size; > + EFI_CPU_IO2_PROTOCOL *IoFncs; > + UINTN Offset; > + UINTN Size; > } HEFI_EDITOR_MEM_IMAGE; >=20 > typedef struct { > diff --git > a/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/MemImage.c > b/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/MemImage.c > index 300c67f0d4..fce9bbe0e6 100644 > --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/MemImage.c > +++ > b/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/MemImage.c > @@ -1,7 +1,7 @@ > /** @file > Functions to deal with Mem buffer >=20 > - Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. > + Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved. > This program and the accompanying materials > are licensed and made available under the terms and conditions of the = BSD > License > which accompanies this distribution. The full text of the license may= be > found at > @@ -27,8 +27,6 @@ extern HEFI_EDITOR_GLOBAL_EDITOR HMainEditor; > HEFI_EDITOR_MEM_IMAGE HMemImage; > HEFI_EDITOR_MEM_IMAGE HMemImageBackupVar; >=20 > -EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL DummyPciRootBridgeIo; > - > // > // for basic initialization of HDiskImage > // > @@ -39,54 +37,6 @@ HEFI_EDITOR_MEM_IMAGE HMemImageConst > =3D { > }; >=20 > /** > - Empty function. always returns the same. > - > - @param[in] This Ignored. > - @param[in] Width Ignored. > - @param[in] Address Ignored. > - @param[in] Count Ignored. > - @param[in, out] Buffer Ignored. > - > - @retval EFI_UNSUPPORTED. > -**/ > -EFI_STATUS > -EFIAPI > -DummyMemRead ( > - IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL * This, > - IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width, > - IN UINT64 Address, > - IN UINTN Count, > - IN OUT VOID *Buffer > - ) > -{ > - return EFI_UNSUPPORTED; > -} > - > -/** > - Empty function. always returns the same. > - > - @param[in] This Ignored. > - @param[in] Width Ignored. > - @param[in] Address Ignored. > - @param[in] Count Ignored. > - @param[in, out] Buffer Ignored. > - > - @retval EFI_UNSUPPORTED. > -**/ > -EFI_STATUS > -EFIAPI > -DummyMemWrite ( > - IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL * This, > - IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width, > - IN UINT64 Address, > - IN UINTN Count, > - IN OUT VOID *Buffer > - ) > -{ > - return EFI_UNSUPPORTED; > -} > - > -/** > Initialization function for HDiskImage. >=20 > @retval EFI_SUCCESS The operation was successful. > @@ -105,21 +55,10 @@ HMemImageInit ( > CopyMem (&HMemImage, &HMemImageConst, sizeof (HMemImage)); >=20 > Status =3D gBS->LocateProtocol ( > - &gEfiPciRootBridgeIoProtocolGuid, > + &gEfiCpuIo2ProtocolGuid, > NULL, > (VOID**)&HMemImage.IoFncs > ); > - if (Status =3D=3D EFI_NOT_FOUND) { > - // > - // For NT32, no EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL is available > - // Use Dummy PciRootBridgeIo for memory access > - // > - ZeroMem (&DummyPciRootBridgeIo, sizeof > (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL)); > - DummyPciRootBridgeIo.Mem.Read =3D DummyMemRead; > - DummyPciRootBridgeIo.Mem.Write =3D DummyMemWrite; > - HMemImage.IoFncs =3D &DummyPciRootBridgeIo; > - Status =3D EFI_SUCCESS; > - } > if (!EFI_ERROR (Status)) { > return EFI_SUCCESS; > } else { > -- > 2.12.2.windows.2