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: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-Google-Smtp-Source: AG47ELsq77sl9+56udguBfzfY5NE2ZlN2e17Ud+8Of8nTg2J+MmJfj/LpWKUhp74P+LruiTEpgQeCw== 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 Cc: lersek@redhat.com, leif.lindholm@linaro.org, heyi.guo@linaro.org, star.zeng@intel.com, eric.dong@intel.com, michael.d.kinney@intel.com, liming.gao@intel.com, Ard Biesheuvel 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: [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: , X-List-Received-Date: Thu, 01 Mar 2018 18:06:00 -0000 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(-) 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 -- 2.11.0