On Fri, Oct 14, 2016 at 12:44:19PM +0200, Marcin Wojtas wrote:
From: Bartosz Szczepanek bsz@semihalf.com
MvResetSystemLib implements functionality required to restart the platform. This approach implements Reset in a way that is compatible with ResetSystem runtime service.
Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Bartosz Szczepanek bsz@semihalf.com Signed-off-by: Jan Dabros jsd@semihalf.com Signed-off-by: Marcin Wojtas mw@semihalf.com
Documentation/Marvell/PortingGuide/Reset.txt | 7 + .../Library/ResetSystemLib/MvResetSystemLib.c | 153 +++++++++++++++++++++ .../Library/ResetSystemLib/MvResetSystemLib.inf | 58 ++++++++ Platforms/Marvell/Marvell.dec | 4 + 4 files changed, 222 insertions(+) create mode 100644 Documentation/Marvell/PortingGuide/Reset.txt create mode 100644 Platforms/Marvell/Library/ResetSystemLib/MvResetSystemLib.c create mode 100644 Platforms/Marvell/Library/ResetSystemLib/MvResetSystemLib.inf
diff --git a/Documentation/Marvell/PortingGuide/Reset.txt b/Documentation/Marvell/PortingGuide/Reset.txt new file mode 100644 index 0000000..30dec86 --- /dev/null +++ b/Documentation/Marvell/PortingGuide/Reset.txt @@ -0,0 +1,7 @@ +MarvellResetSystemLib configuration +----------------------------------- +This simple library allows to mask given bits in given reg at UEFI 'reset' +command call. These variables are configurable through PCDs:
- gMarvellTokenSpaceGuid.PcdResetRegAddress
- gMarvellTokenSpaceGuid.PcdResetRegMask
diff --git a/Platforms/Marvell/Library/ResetSystemLib/MvResetSystemLib.c b/Platforms/Marvell/Library/ResetSystemLib/MvResetSystemLib.c new file mode 100644 index 0000000..b60a727 --- /dev/null +++ b/Platforms/Marvell/Library/ResetSystemLib/MvResetSystemLib.c @@ -0,0 +1,153 @@ +/******************************************************************************** +Copyright (C) 2016 Marvell International Ltd.
+Marvell BSD License Option
+If you received this File from Marvell, you may opt to use, redistribute and/or +modify this File under the following licensing terms. +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- Neither the name of Marvell nor the names of its contributors may be
- used to endorse or promote products derived from this software without
- specific prior written permission.
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*******************************************************************************/
+#include <PiDxe.h> +#include <Uefi.h>
+#include <Library/BaseLib.h> +#include <Library/DebugLib.h> +#include <Library/DxeServicesTableLib.h> +#include <Library/IoLib.h> +#include <Library/UefiLib.h> +#include <Library/UefiBootServicesTableLib.h> +#include <Library/UefiRuntimeLib.h> +#include <Library/UefiRuntimeServicesTableLib.h>
+#include <Guid/EventGroup.h>
+STATIC EFI_EVENT mResetSystemVirtualAddrChangeEvent; +STATIC UINT64 mAddress;
+VOID +EFIAPI
Not changed to STATIC and no comment given w.r.t. this suggestion from first round.
+LibResetSystemVirtualNotifyEvent (
- IN EFI_EVENT Event,
- IN VOID *Context
- )
+{
- //
- // Convert physical address to virtual address.
- //
- EfiConvertPointer (0x0, (VOID**)&mAddress);
- return;
+}
+/**
- Resets the entire platform.
- @param ResetType The type of reset to perform.
- @param ResetStatus The status code for the reset.
- @param DataSize The size, in bytes, of WatchdogData.
- @param ResetData For a ResetType of EfiResetCold, EfiResetWarm,
or EfiResetShutdown the data buffer starts with
a Null-terminated Unicode string, optionally
followed by additional binary data.
+**/ +EFI_STATUS +EFIAPI +LibResetSystem (
- IN EFI_RESET_TYPE ResetType,
- IN EFI_STATUS ResetStatus,
- IN UINTN DataSize,
- IN VOID *ResetData OPTIONAL
- )
+{
- UINT32 Data;
- switch (ResetType) {
- case EfiResetCold:
- case EfiResetWarm:
- Data = MmioRead32 (mAddress);
- Data &= ~PcdGet32 (PcdResetRegMask);
- MmioWrite32 (mAddress, Data);
- break;
- case EfiResetShutdown:
- break;
OK, so there is no support to power off the platform? That deserves a comment pointing it out.
- default:
- break;
- }
- return EFI_DEVICE_ERROR;
+}
+EFI_STATUS +EFIAPI +LibInitializeResetSystem (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
- )
+{
- EFI_STATUS Status;
- mAddress = PcdGet64 (PcdResetRegAddress);
- //
- // Add 64KB aligned and 64KB long memory space
- //
- Status = gDS->AddMemorySpace (
EfiGcdMemoryTypeMemoryMappedIo,
mAddress & ~0xFFFFULL, SIZE_64KB,
Prettier with ~(SIZE_64KB - 1).
EFI_MEMORY_UC | EFI_MEMORY_RUNTIME
);
- if (EFI_ERROR (Status)) {
- ASSERT_EFI_ERROR (Status);
- return Status;
- }
- //
- // Mark 64KB aligned and 64KB long memory space as runtime
- //
- Status = gDS->SetMemorySpaceAttributes (mAddress & ~0xFFFFULL, SIZE_64KB,
...which could go into a temporary variable used here again.
Regards,
Leif
- EFI_MEMORY_UC | EFI_MEMORY_RUNTIME);
- if (EFI_ERROR (Status)) {
- ASSERT_EFI_ERROR (Status);
- return Status;
- }
- //
- // Register for the virtual address change event
- //
- Status = gBS->CreateEventEx (
EVT_NOTIFY_SIGNAL,
TPL_NOTIFY,
LibResetSystemVirtualNotifyEvent,
NULL,
&gEfiEventVirtualAddressChangeGuid,
&mResetSystemVirtualAddrChangeEvent
);
- ASSERT_EFI_ERROR (Status);
- return Status;
+} diff --git a/Platforms/Marvell/Library/ResetSystemLib/MvResetSystemLib.inf b/Platforms/Marvell/Library/ResetSystemLib/MvResetSystemLib.inf new file mode 100644 index 0000000..87fff57 --- /dev/null +++ b/Platforms/Marvell/Library/ResetSystemLib/MvResetSystemLib.inf @@ -0,0 +1,58 @@ +# Copyright (C) 2016 Marvell International Ltd. +# +# Marvell BSD License Option +# +# If you received this File from Marvell, you may opt to use, redistribute and/or +# modify this File under the following licensing terms. +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# * Neither the name of Marvell nor the names of its contributors may be +# used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#
+[Defines]
- INF_VERSION = 0x00010019
- BASE_NAME = Reset
- FILE_GUID = 9d1373c0-6fac-432c-88e7-818744dc45d9
- MODULE_TYPE = BASE
- VERSION_STRING = 1.0
- LIBRARY_CLASS = EfiResetSystemLib
+[Sources.common]
- MvResetSystemLib.c
+[Packages]
- MdePkg/MdePkg.dec
- OpenPlatformPkg/Platforms/Marvell/Marvell.dec
+[LibraryClasses]
- DebugLib
- DxeServicesTableLib
- IoLib
- UefiBootServicesTableLib
- UefiLib
- UefiRuntimeLib
+[Pcd]
- gMarvellTokenSpaceGuid.PcdResetRegAddress
- gMarvellTokenSpaceGuid.PcdResetRegMask
diff --git a/Platforms/Marvell/Marvell.dec b/Platforms/Marvell/Marvell.dec index 31236a3..0044da0 100644 --- a/Platforms/Marvell/Marvell.dec +++ b/Platforms/Marvell/Marvell.dec @@ -193,6 +193,10 @@ gMarvellTokenSpaceGuid.PcdPhyDeviceIds|{ 0 }|VOID*|0x3000095 gMarvellTokenSpaceGuid.PcdPhyStartupAutoneg|FALSE|BOOLEAN|0x3000070 +#ResetLib
- gMarvellTokenSpaceGuid.PcdResetRegAddress|0|UINT64|0x40000050
- gMarvellTokenSpaceGuid.PcdResetRegMask|0|UINT32|0x4000051
[Protocols] gMarvellEepromProtocolGuid = { 0xcd728a1f, 0x45b5, 0x4feb, { 0x98, 0xc8, 0x31, 0x3d, 0xa8, 0x11, 0x74, 0x62 }} gMarvellMdioProtocolGuid = { 0x0d728a1f, 0x45b5, 0x4feb, { 0x98, 0xc8, 0x31, 0x3d, 0xa8, 0x11, 0x74, 0x62 }} -- 1.8.3.1