From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:400c:c0c::241; helo=mail-wr0-x241.google.com; envelope-from=leif.lindholm@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wr0-x241.google.com (mail-wr0-x241.google.com [IPv6:2a00:1450:400c:c0c::241]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id BE3B720956061 for ; Thu, 15 Mar 2018 05:43:08 -0700 (PDT) Received: by mail-wr0-x241.google.com with SMTP id k3so8150317wrg.6 for ; Thu, 15 Mar 2018 05:49:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=l7x6m2jjSKQUB65eXVXfgoMHaNYqLDCEeDJ9taizWio=; b=aejhR9d7V+aQ6+1LlVpIdAilKY7AZqLwyz5inq8pceGcM3iVtT2tmXk9Te+j5k9IMf TasMH6G8X3cC8bOJV7O2OgDU4sgq54u10JUVTHvfYOBj3pu3z4229Fp2DWpkAYetwW4F pyXBGtK4eiEJw3ZV2g9xuYGLSKb6t5SCjpkWE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=l7x6m2jjSKQUB65eXVXfgoMHaNYqLDCEeDJ9taizWio=; b=M38zNySPMPaX5CSSdEJ7gsKpKce74jiv/CHxCFJj4oZxEGaa+CzEaxBl3PRL9T9e+S 9ARLoDzvpbNpkDBjfEA0iSzUpNNu/DjNFwgYybEdfkGcTcGmEgwdO8RQa78Yb/gsbES0 cdbSEY9UUZ4U58S6Lp98qS0RQyGAPFNddEkDFXaU/U0lgUy9duMdyqieHf63dK2r/6D+ aURoaOy2p/k6DejyFoWiy7B48Tssx99IGTaYPkzZyubjxp0mnJBrZZCwuIuy3gaMplfv +POcLzWazV/8thnByScbZxFw1420wrrJdouTw0/aatLDbfkF+RHfrzM9hctRrbYSlNYP lgRw== X-Gm-Message-State: AElRT7HQ2Y7lDxxQW4c5+fNMakQ3ECzZw6f14rGCzQlbmSqPtnMViuMW wSbcSkmwjiEom9Eosh+HetgD2g== X-Google-Smtp-Source: AG47ELv5VPLBKXZwCa7zWcTSq2NMdkBmAUQ/2DGmiwReORUkI5oXsho+E3yf8M5GrORrihAHWq2c7A== X-Received: by 10.223.172.167 with SMTP id o36mr7471581wrc.34.1521118170311; Thu, 15 Mar 2018 05:49:30 -0700 (PDT) Received: from bivouac.eciton.net (bivouac.eciton.net. [2a00:1098:0:86:1000:23:0:2]) by smtp.gmail.com with ESMTPSA id 7sm7161871wry.18.2018.03.15.05.49.28 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 15 Mar 2018 05:49:28 -0700 (PDT) Date: Thu, 15 Mar 2018 12:49:27 +0000 From: Leif Lindholm To: Ard Biesheuvel Cc: edk2-devel@lists.01.org, lersek@redhat.com, heyi.guo@linaro.org, star.zeng@intel.com, eric.dong@intel.com, michael.d.kinney@intel.com, liming.gao@intel.com Message-ID: <20180315124927.shp2tb5njtc5drlk@bivouac.eciton.net> References: <20180301181142.16817-1-ard.biesheuvel@linaro.org> <20180301181142.16817-5-ard.biesheuvel@linaro.org> MIME-Version: 1.0 In-Reply-To: <20180301181142.16817-5-ard.biesheuvel@linaro.org> User-Agent: NeoMutt/20170113 (1.7.2) Subject: Re: [PATCH 4/4] ArmPlatformPkg: add PL011 UART runtime debug driver X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Mar 2018 12:43:09 -0000 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Thu, Mar 01, 2018 at 06:11:42PM +0000, Ard Biesheuvel wrote: > Implement the new runtime debug output protocol on top of a PL011 UART. > > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Ard Biesheuvel LGTM Reviewed-by: Leif Lindholm > --- > ArmPlatformPkg/Drivers/PL011RuntimeDebugOutputDxe/PL011RuntimeDebugOutputDxe.c | 144 ++++++++++++++++++++ > ArmPlatformPkg/Drivers/PL011RuntimeDebugOutputDxe/PL011RuntimeDebugOutputDxe.inf | 62 +++++++++ > 2 files changed, 206 insertions(+) > > diff --git a/ArmPlatformPkg/Drivers/PL011RuntimeDebugOutputDxe/PL011RuntimeDebugOutputDxe.c b/ArmPlatformPkg/Drivers/PL011RuntimeDebugOutputDxe/PL011RuntimeDebugOutputDxe.c > new file mode 100644 > index 000000000000..155b2c50d463 > --- /dev/null > +++ b/ArmPlatformPkg/Drivers/PL011RuntimeDebugOutputDxe/PL011RuntimeDebugOutputDxe.c > @@ -0,0 +1,144 @@ > +/** @file > + Runtime driver to produce debug output on a PL011 UART > + > + Copyright (c) 2018, Linaro, Ltd. 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 > + http://opensource.org/licenses/bsd-license.php > + > + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, > + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. > + > +**/ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +STATIC UINTN mUartBase; > +STATIC EFI_EVENT mVirtualAddressChangeEvent; > + > +/** > + Write data from buffer to debug output device > + > + Writes NumberOfBytes data bytes from Buffer to the debug output device. > + The number of bytes actually written to the device is returned. > + If the return value is less than NumberOfBytes, then the write operation > + failed. > + If NumberOfBytes is zero, then return 0. > + > + @param Buffer Pointer to the data buffer to be written. > + @param NumberOfBytes Number of bytes to written to the device. > + > + @retval 0 NumberOfBytes is 0. > + @retval >0 The number of bytes written to the serial device. > + If this value is less than NumberOfBytes, then the > + write operation failed. > + > +**/ > +STATIC > +UINTN > +PL011RuntimeDebugOutputWrite ( > + IN EDK2_RUNTIME_DEBUG_OUTPUT_PROTOCOL *This, > + IN UINT8 *Buffer, > + IN UINTN NumberOfBytes > + ) > +{ > + return PL011UartWrite (mUartBase, Buffer, NumberOfBytes); > +} > + > +STATIC EDK2_RUNTIME_DEBUG_OUTPUT_PROTOCOL mRuntimeDebugOutput = { > + PL011RuntimeDebugOutputWrite > +}; > + > +/** > + Fixup internal data so that EFI can be called in virtual mode. > + > + @param[in] Event The Event that is being processed > + @param[in] Context Event Context > +**/ > +STATIC > +VOID > +EFIAPI > +VirtualNotifyEvent ( > + IN EFI_EVENT Event, > + IN VOID *Context > + ) > +{ > + EfiConvertPointer (0x0, (VOID **)&mUartBase); > +} > + > +EFI_STATUS > +EFIAPI > +PL011RuntimeDebugOutputDxeEntry ( > + IN EFI_HANDLE ImageHandle, > + IN EFI_SYSTEM_TABLE *SystemTable > + ) > +{ > + EFI_STATUS Status; > + EFI_HANDLE Handle; > + UINT64 BaudRate; > + UINT32 ReceiveFifoDepth; > + EFI_PARITY_TYPE Parity; > + UINT8 DataBits; > + EFI_STOP_BITS_TYPE StopBits; > + > + mUartBase = (UINTN)FixedPcdGet64 (PcdSerialRegisterBase); > + BaudRate = FixedPcdGet64 (PcdUartDefaultBaudRate); > + ReceiveFifoDepth = 0; // Use default FIFO depth > + Parity = (EFI_PARITY_TYPE)FixedPcdGet8 (PcdUartDefaultParity); > + DataBits = FixedPcdGet8 (PcdUartDefaultDataBits); > + StopBits = (EFI_STOP_BITS_TYPE) FixedPcdGet8 (PcdUartDefaultStopBits); > + > + Status = PL011UartInitializePort (mUartBase, FixedPcdGet32 (PL011UartClkInHz), > + &BaudRate, &ReceiveFifoDepth, &Parity, &DataBits, &StopBits); > + if (EFI_ERROR (Status)) { > + return Status; > + } > + > + // > + // Register for the virtual address change event > + // > + Status = gBS->CreateEventEx (EVT_NOTIFY_SIGNAL, TPL_NOTIFY, > + VirtualNotifyEvent, NULL, &gEfiEventVirtualAddressChangeGuid, > + &mVirtualAddressChangeEvent); > + if (EFI_ERROR (Status)) { > + return Status; > + } > + > + // > + // Declare the UART MMIO region as EFI_MEMORY_RUNTIME > + // > + Status = gDS->AddMemorySpace (EfiGcdMemoryTypeMemoryMappedIo, mUartBase, > + SIZE_4KB, EFI_MEMORY_UC | EFI_MEMORY_RUNTIME); > + if (EFI_ERROR (Status)) { > + goto CloseEvent; > + } > + > + Status = gDS->SetMemorySpaceAttributes (mUartBase, SIZE_4KB, > + EFI_MEMORY_UC | EFI_MEMORY_RUNTIME); > + if (EFI_ERROR (Status)) { > + goto CloseEvent; > + } > + > + Handle = NULL; > + Status = gBS->InstallMultipleProtocolInterfaces (&Handle, > + &gEdkiiRuntimeDebugOutputProtocolGuid, &mRuntimeDebugOutput, > + NULL); > + if (EFI_ERROR (Status)) { > + goto CloseEvent; > + } > + > + return EFI_SUCCESS; > + > +CloseEvent: > + gBS->CloseEvent (mVirtualAddressChangeEvent); > + > + return Status; > +} > diff --git a/ArmPlatformPkg/Drivers/PL011RuntimeDebugOutputDxe/PL011RuntimeDebugOutputDxe.inf b/ArmPlatformPkg/Drivers/PL011RuntimeDebugOutputDxe/PL011RuntimeDebugOutputDxe.inf > new file mode 100644 > index 000000000000..28a8e514552e > --- /dev/null > +++ b/ArmPlatformPkg/Drivers/PL011RuntimeDebugOutputDxe/PL011RuntimeDebugOutputDxe.inf > @@ -0,0 +1,62 @@ > +#/** @file > +# Runtime driver to produce debug output on a PL011 UART > +# > +# Copyright (c) 2018, Linaro, Ltd. 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 > +# http://opensource.org/licenses/bsd-license.php > +# > +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, > +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. > +# > +# > +#**/ > + > +[Defines] > + INF_VERSION = 0x0001001A > + BASE_NAME = PL011RuntimeDebugOutputDxe > + FILE_GUID = 494297ca-9205-463a-aae5-215ffd067cbb > + MODULE_TYPE = DXE_RUNTIME_DRIVER > + VERSION_STRING = 1.0 > + ENTRY_POINT = PL011RuntimeDebugOutputDxeEntry > + > +# > +# The following information is for reference only and not required by the build tools. > +# > +# VALID_ARCHITECTURES = AARCH64 ARM > +# > + > +[Sources.common] > + PL011RuntimeDebugOutputDxe.c > + > +[Packages] > + ArmPlatformPkg/ArmPlatformPkg.dec > + MdeModulePkg/MdeModulePkg.dec > + MdePkg/MdePkg.dec > + > +[LibraryClasses] > + DxeServicesTableLib > + PcdLib > + PL011UartLib > + UefiBootServicesTableLib > + UefiDriverEntryPoint > + UefiRuntimeLib > + > +[Guids] > + gEfiEventVirtualAddressChangeGuid ## CONSUMES # Event > + > +[Protocols] > + gEdkiiRuntimeDebugOutputProtocolGuid ## PROTOCOL ALWAYS_PRODUCED > + > +[FixedPcd] > + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase > + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate > + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultDataBits > + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultParity > + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultStopBits > + gArmPlatformTokenSpaceGuid.PL011UartClkInHz > + > +[Depex] > + TRUE > -- > 2.11.0 >