From patchwork Thu Mar 1 18:11:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 130377 Delivered-To: patch@linaro.org Received: by 10.80.172.228 with SMTP id x91csp3117647edc; Thu, 1 Mar 2018 10:12:10 -0800 (PST) X-Google-Smtp-Source: AG47ELvte6Syv5WhOT0pcXTE94RfhdODNprmUFrWaOucQG8yCkfYvgIpZjMpO8zJkrpJ8rbMDAUz X-Received: by 2002:a17:902:33a5:: with SMTP id b34-v6mr2645730plc.263.1519927930444; Thu, 01 Mar 2018 10:12:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519927930; cv=none; d=google.com; s=arc-20160816; b=gHjRfy7ttPT2AJKG6oe6+SfLs5NMUeOjThUwLx5++zWUeNzpQ/MpIK2hZN2pBQSBfy gmjQHQT9+BqVamhKwQj/BeI0PNPrRadBxePMdIkhk5QhMhjSDvsJ25JMJezdTK2vmNZg cPwCufa6Y6HLDHQnM8ryvvnZxTltgB/vjns3o7waO5SkRCeE/Rd961VXLVtMbJFc6tog rK66xPB6OEpv7nog57xFc+/hcmUQ6N42DKTIS8ooeMliBkqZtodwhFRca1jYNlXwYjpG H5wAsvfGKL75zUUh8pae7SxefQsEgbsOPSOc88zgsnknLXNpASSU1QnSFp58D3eI1GD7 MDew== 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=OYZSIXn4ULgHgMcIt2A2F+jfqPHxCqZGR9AO9KGknnA=; b=fKRlpcrUZRqKnOUpsIpOgCQyj8Dgh5T0D2lGF2HOk9Y4pHCADqfk4Q8aenRnqsIwQ4 kR7q5NnvKlrnMai9TxviLQv0VQQllQe8ptL0xwVWGTU6eizIaFtXiDKQhx3O/J1KkWVL 2sQVjH0Ij0EUn6ih8JGd67CugKglsmz3/WKjSdVByc1RJLjtJ25wQdUZKgCg1qZOVrFL 6yblDSrgnDZjLQUP2TOM9BGHVmR2RnDgJ/8J7tjXy8q3VPXsBUQa/P+7eGlZbxEcya/V y88tXLtvVTBZeJikPxRkhohRqSvf4PbM18xCttdYyfO7tnVKSO3IMYHp8HAucRkw0lfi nzIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=i35oCirD; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 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. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id b92-v6si3359716plb.747.2018.03.01.10.12.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Mar 2018 10:12:10 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=i35oCirD; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 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 43E7E224511AD; Thu, 1 Mar 2018 10:06:01 -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::243; helo=mail-wm0-x243.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wm0-x243.google.com (mail-wm0-x243.google.com [IPv6:2a00:1450:400c:c09::243]) (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 8B3F22245119D for ; Thu, 1 Mar 2018 10:05:59 -0800 (PST) Received: by mail-wm0-x243.google.com with SMTP id 139so13960134wmn.2 for ; Thu, 01 Mar 2018 10:12:08 -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=3ygqM//nCAp++782fDBzQCvuU0N1w/DbwKSmjE8OADo=; b=i35oCirDcqAStzIb6qAQ3UP/hYxDU9OUuJu0LDn6v1gjVQi9WG9mjYRLxQOe5XoAmV Wx8nMQonKsYaK8wmINgBW6oLFetI/46VnYM/LLu1fRFwIFX3KxG+zhFICHLdyU0ytwPy WMCfC+TnY+5S5FryLz/H0Kw4flk3cCSBQzHUY= 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=3ygqM//nCAp++782fDBzQCvuU0N1w/DbwKSmjE8OADo=; b=rq2ain9xD+HAiHbFEG7hglpANqwo/4Qx16ITsySdTS61Lw3ErMWm7a+6CqoKHKG1NW BpczFvhsRQYcluR7jwYKm8hIsMI7Vl5+tj84fYJXkveqsqQbzix9kOsQFwml2UKVOpdh PEUgzMFOHlbZrYcfba1LMHRG3eu3uMlg8LdSUP2WklKMVA+JyC8A4tUSsERPyRpd9U3r q8yan7/De3dohrsqflQoxPAHKkdcRnIrO7GemZM7MI0v5Os6nhXMSRQXpYJX+Dn4R51K B+Galm7BIlsgpz58MEEKTBiRLraLloLblqGfDKuCSDZ+dOkOS2KofrifbiIL1moeygk0 wuxg== X-Gm-Message-State: AElRT7GJOk20Y+f/hbPsX4jdvGGZtip3n5JgtA+zE0oDt5XvPjb0nd1A MMy4sRI9yIXFguaYSi+EvR1rWUELjkI= X-Received: by 10.28.220.66 with SMTP id t63mr2464678wmg.100.1519927926315; Thu, 01 Mar 2018 10:12:06 -0800 (PST) Received: from localhost.localdomain ([196.71.216.221]) by smtp.gmail.com with ESMTPSA id w195sm78568wmw.9.2018.03.01.10.12.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Mar 2018 10:12:05 -0800 (PST) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Thu, 1 Mar 2018 18:11:41 +0000 Message-Id: <20180301181142.16817-4-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 3/4] MdeModulePkg/DxeRuntimeDebugLibSerialPort: invoke RuntimeDebugOutputProtocol 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" Extend the functionality of DxeRuntimeDebugLibSerialPort by invoking any available RuntimeDebugOutputProtocol to emit debug output at runtime rather than staying silent. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel --- MdeModulePkg/Library/DxeRuntimeDebugLibSerialPort/DebugLib.c | 155 +++++++++++++++++--- MdeModulePkg/Library/DxeRuntimeDebugLibSerialPort/DxeRuntimeDebugLibSerialPort.inf | 5 + 2 files changed, 143 insertions(+), 17 deletions(-) -- 2.11.0 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/MdeModulePkg/Library/DxeRuntimeDebugLibSerialPort/DebugLib.c b/MdeModulePkg/Library/DxeRuntimeDebugLibSerialPort/DebugLib.c index e1266f77fa41..b5460f10ebb6 100644 --- a/MdeModulePkg/Library/DxeRuntimeDebugLibSerialPort/DebugLib.c +++ b/MdeModulePkg/Library/DxeRuntimeDebugLibSerialPort/DebugLib.c @@ -25,10 +25,16 @@ #include #include #include +#include STATIC EFI_EVENT mEfiExitBootServicesEvent; +STATIC EFI_EVENT mEfiVirtualAddressChangeEvent; +STATIC EFI_EVENT mRegisterRuntimeDebugOutputProtocolEvent; +STATIC VOID *mRegisterProtocolRegistration; STATIC BOOLEAN mEfiAtRuntime = FALSE; +STATIC EDK2_RUNTIME_DEBUG_OUTPUT_PROTOCOL *mRuntimeOutput = NULL; + // // Define the maximum debug and assert message length that this library supports // @@ -53,6 +59,58 @@ ExitBootServicesEvent ( } /** + Attach to the RuntimeDebugOutputProtocol as soon as it gets registered + + @param[in] Event The Event that is being processed. + @param[in] Context The Event Context. + +**/ +STATIC +VOID +EFIAPI +RegisterRuntimeDebugOutputProtocolEvent ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + EFI_STATUS Status; + EFI_BOOT_SERVICES *BS; + + BS = Context; + + Status = BS->LocateProtocol (&gEdkiiRuntimeDebugOutputProtocolGuid, + mRegisterProtocolRegistration, + (VOID **)&mRuntimeOutput); + if (EFI_ERROR (Status)) { + return; + } + + BS->CloseEvent (Event); +} + +/** + Fix up virtual address of the runtime debug output protocol + + @param[in] Event The Event that is being processed. + @param[in] Context The Event Context. + +**/ +STATIC +VOID +EFIAPI +VirtualAddressChangeEvent ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + EFI_RUNTIME_SERVICES *RT; + + RT = Context; + + RT->ConvertPointer (0x0, (VOID **)&mRuntimeOutput); +} + +/** The constructor function to initialize the Serial Port library and register a callback for the ExitBootServices event. @@ -70,17 +128,64 @@ DxeRuntimeDebugLibSerialPortConstructor ( IN EFI_SYSTEM_TABLE *SystemTable ) { - EFI_STATUS Status; + EFI_STATUS Status; + EFI_BOOT_SERVICES *BS; Status = SerialPortInitialize (); if (EFI_ERROR (Status)) { return Status; } - return SystemTable->BootServices->CreateEventEx (EVT_NOTIFY_SIGNAL, - TPL_NOTIFY, ExitBootServicesEvent, NULL, - &gEfiEventExitBootServicesGuid, - &mEfiExitBootServicesEvent); + BS = SystemTable->BootServices; + + Status = BS->CreateEvent (EVT_NOTIFY_SIGNAL, TPL_NOTIFY, + RegisterRuntimeDebugOutputProtocolEvent, BS, + &mRegisterRuntimeDebugOutputProtocolEvent); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Register for protocol notifications on this event + // + Status = BS->RegisterProtocolNotify (&gEdkiiRuntimeDebugOutputProtocolGuid, + mRegisterRuntimeDebugOutputProtocolEvent, + &mRegisterProtocolRegistration); + if (EFI_ERROR (Status)) { + goto CloseProtocolEvent; + } + + // + // Kick the event so we will perform an initial pass of + // current installed drivers + // + BS->SignalEvent (mRegisterRuntimeDebugOutputProtocolEvent); + + Status = BS->CreateEventEx (EVT_NOTIFY_SIGNAL, TPL_NOTIFY, + ExitBootServicesEvent, NULL, + &gEfiEventExitBootServicesGuid, + &mEfiExitBootServicesEvent); + if (EFI_ERROR (Status)) { + goto CloseProtocolEvent; + } + + Status = BS->CreateEventEx (EVT_NOTIFY_SIGNAL, TPL_NOTIFY, + VirtualAddressChangeEvent, SystemTable->RuntimeServices, + &gEfiEventVirtualAddressChangeGuid, + &mEfiVirtualAddressChangeEvent); + if (EFI_ERROR (Status)) { + goto CloseExitBootServicesEvent; + } + + return EFI_SUCCESS; + +CloseExitBootServicesEvent: + BS->CloseEvent (mEfiExitBootServicesEvent); + +CloseProtocolEvent: + BS->CloseEvent (mRegisterRuntimeDebugOutputProtocolEvent); + + return Status; } /** @@ -100,7 +205,29 @@ DxeRuntimeDebugLibSerialPortDestructor ( IN EFI_SYSTEM_TABLE *SystemTable ) { - return SystemTable->BootServices->CloseEvent (mEfiExitBootServicesEvent); + EFI_BOOT_SERVICES *BS; + + BS = SystemTable->BootServices; + + BS->CloseEvent (mRegisterRuntimeDebugOutputProtocolEvent); + BS->CloseEvent (mEfiExitBootServicesEvent); + + return EFI_SUCCESS; +} + +STATIC +UINTN +DebugWriteOutput ( + IN UINT8 *Buffer, + IN UINTN NumberOfBytes + ) +{ + if (!mEfiAtRuntime) { + return SerialPortWrite (Buffer, NumberOfBytes); + } else if (mRuntimeOutput != NULL) { + return mRuntimeOutput->Write (mRuntimeOutput, Buffer, NumberOfBytes); + } + return 0; } /** @@ -129,10 +256,6 @@ DebugPrint ( CHAR8 Buffer[MAX_DEBUG_MESSAGE_LENGTH]; VA_LIST Marker; - if (mEfiAtRuntime) { - return; - } - // // If Format is NULL, then ASSERT(). // @@ -155,7 +278,7 @@ DebugPrint ( // // Send the print string to a Serial Port // - SerialPortWrite ((UINT8 *)Buffer, AsciiStrLen (Buffer)); + DebugWriteOutput ((UINT8 *)Buffer, AsciiStrLen (Buffer)); } @@ -196,12 +319,10 @@ DebugAssert ( AsciiSPrint (Buffer, sizeof (Buffer), "ASSERT [%a] %a(%d): %a\n", gEfiCallerBaseName, FileName, LineNumber, Description); - if (!mEfiAtRuntime) { - // - // Send the print string to the Console Output device - // - SerialPortWrite ((UINT8 *)Buffer, AsciiStrLen (Buffer)); - } + // + // Send the print string to the Console Output device + // + DebugWriteOutput ((UINT8 *)Buffer, AsciiStrLen (Buffer)); // // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings diff --git a/MdeModulePkg/Library/DxeRuntimeDebugLibSerialPort/DxeRuntimeDebugLibSerialPort.inf b/MdeModulePkg/Library/DxeRuntimeDebugLibSerialPort/DxeRuntimeDebugLibSerialPort.inf index 813358096982..d2fbdde25f1d 100644 --- a/MdeModulePkg/Library/DxeRuntimeDebugLibSerialPort/DxeRuntimeDebugLibSerialPort.inf +++ b/MdeModulePkg/Library/DxeRuntimeDebugLibSerialPort/DxeRuntimeDebugLibSerialPort.inf @@ -36,6 +36,7 @@ [Sources] DebugLib.c [Packages] + MdeModulePkg/MdeModulePkg.dec MdePkg/MdePkg.dec [LibraryClasses] @@ -48,6 +49,10 @@ [LibraryClasses] [Guids] gEfiEventExitBootServicesGuid ## CONSUMES ## Event + gEfiEventVirtualAddressChangeGuid ## CONSUMES ## Event + +[Protocols] + gEdkiiRuntimeDebugOutputProtocolGuid ## SOMETIMES_CONSUMES [Pcd] gEfiMdePkgTokenSpaceGuid.PcdDebugClearMemoryValue ## SOMETIMES_CONSUMES