From patchwork Thu Mar 1 18:11:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 130378 Delivered-To: patch@linaro.org Received: by 10.80.172.228 with SMTP id x91csp3117710edc; Thu, 1 Mar 2018 10:12:14 -0800 (PST) X-Google-Smtp-Source: AG47ELvtTgq6eXFgTWDo62Q8GU1uhaWhyJV22UVruVc91s9l5GZlUMe2fkOf4vvV3ukH6bpNnssN X-Received: by 10.99.47.132 with SMTP id v126mr2284838pgv.42.1519927933886; Thu, 01 Mar 2018 10:12:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519927933; cv=none; d=google.com; s=arc-20160816; b=r2vWBxEh1IiPfaTCat/M3L6LxxPytIbu50v0DR7Y8kjvJP/1VcIErdwHhQhdMkh/yy IrVWt8MmYOlKEAJY/KRETGLODijrsaoi1zHHY265zpjua+UW7uHtVqtE++KfMC+VJP3N hVAyuFdQ4VXHMjmhNgXRL32ntB3822KJvEv530Os6tjQrlhPQqLuHKjb9HTw/Nf8iJ0E 0o3ojgvtH71EfV8GXlbbbga8ZyUNRE3HWxzRcNwgCTM6/qYS5cJ/SMTg+owNEFIKbepo kyiUj/14/ZaqnrLlKGz7r9VPGJ8sbmMToJd238PQ+Af74mqiEHH3r/9EUB6Qt5sylcbZ /STg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=gJdpRWz5RzKcDAqG9H3U7cwuUn68NydRuioLcrK+uEU=; b=ZFuGaIfFmgMofwjm55YS1BIOd/TUAoos+wUmfkZS5x1LE4LsOhYSsMwa+yw1Gw30Q1 aEPnY4cgbQpwkndPFwItY4gUoMXhjipA3fkj7bwEHoGSe1JlC2yoxxzA+GiUcCLov+wS RM70PPW5W7HB2tZnPe2sKJusejM0+PwcJCQ+hVJKfccJZLfnsJJwJaQZX86S9sOdvvkK lHgNEGgrtA6dZaPHPrSgifOIJPqo0lzIBiXucH1swRMFjpiSzSBWSLUdITw2ZeVdzkyU QZuv5M2efQIcWH7hN8yubHMVJX58hErnpTihKs+ScjSwdLkTR5BIOI88ikm1jsEY10kq 8qkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=WoB1PwYp; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [198.145.21.10]) by mx.google.com with ESMTPS id n10-v6si3312389plk.255.2018.03.01.10.12.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Mar 2018 10:12:13 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) client-ip=198.145.21.10; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=WoB1PwYp; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 9B395224511B1; Thu, 1 Mar 2018 10:06:04 -0800 (PST) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:400c:c09::241; helo=mail-wm0-x241.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wm0-x241.google.com (mail-wm0-x241.google.com [IPv6:2a00:1450:400c:c09::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 F2E0B22423858 for ; Thu, 1 Mar 2018 10:06:02 -0800 (PST) Received: by mail-wm0-x241.google.com with SMTP id z9so13854174wmb.3 for ; Thu, 01 Mar 2018 10:12:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=xfXEQI+MZ2WZJtzDwSAWYPZ9yP3J7+TSpRJ7XO1N6PE=; b=WoB1PwYpPSNW3AZQXcbAHn3v3pg8t9Mmgxa7GurOPMLF6sgkkRAQgNCou7leP1wbpd ZwTSZ+eaTHWmda/YuoJTRheRImtHQnGxn76z08lZRVbhdUSKr3aKwOsX4Sd9bbLdTEox yrrInJ15pQxetOuyBkjJSzHKEkMDzxmeJQ7gM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=xfXEQI+MZ2WZJtzDwSAWYPZ9yP3J7+TSpRJ7XO1N6PE=; b=i8hQiJo8kwdvnSQG4H4knOJu4wwvWDcGU2+SKOhXJ3C09SWjgFPGpJp/tU5Kq2h4F5 5op+Xe7lvS4WJcXelIiBy2lEoJ7JgfDtEV5Pyx6BsT/0IFkqLnRoubYI0wkSz9OGPlO7 ZI65RS8FFUDzbBXKUY0JArvnKBYShds+oeZQ0oCZbdaf3AtDNYHCKqjHADdw4faSryig F+FWgH7DhHuhBlGUpquCoFXJnUhC1zkjfTPqTYClP+l9zkDVX04KSK5U5amQKwuuIuZT rPdwxG8Nj6VdQGfyd3AayrAwmoJrDLq0cy57Re8wdDQsICGSJWyvzQD05F+B/uL2xiTV eBmg== X-Gm-Message-State: AElRT7H1awUDJAE9R+RgC64ftx6e05nel/xydyFFYxuB/kjN2ZdfxeFn lbMqZWjgi5hE0W0kjfkEf0Nve8N/dts= X-Received: by 10.28.166.201 with SMTP id p192mr2359222wme.132.1519927929927; Thu, 01 Mar 2018 10:12:09 -0800 (PST) Received: from localhost.localdomain ([196.71.216.221]) by smtp.gmail.com with ESMTPSA id w195sm78568wmw.9.2018.03.01.10.12.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Mar 2018 10:12:07 -0800 (PST) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Thu, 1 Mar 2018 18:11:42 +0000 Message-Id: <20180301181142.16817-5-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180301181142.16817-1-ard.biesheuvel@linaro.org> References: <20180301181142.16817-1-ard.biesheuvel@linaro.org> Subject: [edk2] [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: , Cc: eric.dong@intel.com, Ard Biesheuvel , leif.lindholm@linaro.org, heyi.guo@linaro.org, liming.gao@intel.com, michael.d.kinney@intel.com, lersek@redhat.com, star.zeng@intel.com MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" 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 --- ArmPlatformPkg/Drivers/PL011RuntimeDebugOutputDxe/PL011RuntimeDebugOutputDxe.c | 144 ++++++++++++++++++++ ArmPlatformPkg/Drivers/PL011RuntimeDebugOutputDxe/PL011RuntimeDebugOutputDxe.inf | 62 +++++++++ 2 files changed, 206 insertions(+) -- 2.11.0 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel Reviewed-by: Leif Lindholm Reviewed-by: Leif Lindholm 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