From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:4001:c0b::231; helo=mail-it0-x231.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-it0-x231.google.com (mail-it0-x231.google.com [IPv6:2607:f8b0:4001:c0b::231]) (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 1781C22436952 for ; Tue, 27 Feb 2018 06:15:10 -0800 (PST) Received: by mail-it0-x231.google.com with SMTP id o9so15251732itc.1 for ; Tue, 27 Feb 2018 06:21:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=mjX04dXesa26Na42fYf/MebrIMrsLCVRS96FiQG1b3E=; b=HIa+ZRTjvLD5Fqt6YctMgiFiPUGU7PLMDn2scB3aGHy8HqrO6HYwX6LrTViOwH1BCh HmPM1MwyJrWGdioBTKoSm77x7TFOUAEAn7TJBoZDRMIw+/nPViezRM6dWoBP+dIXnXEg qYH86kkmzGQHFo4P3+PvGjRpoWiRCV0Yen+tg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=mjX04dXesa26Na42fYf/MebrIMrsLCVRS96FiQG1b3E=; b=h9vZKjs3FdTz0ze9WpknBWxK2a/+6itdDxih8rmSKOmU5/CP/MDsD/qNxpxjKQTpjF G2Ctj1QYxJNwhixVMeFaksSPLSe6tdNh92LvBxoXm6NxscoUlJzjf70tJOyh5HinvaVr c5p4830wkUmFQvZUtqa9FT2+IXI/5CjzhAbcRmcogqrhMbZ+mNzDN5QmDICj1SWizR/L vNdKYFIr1a5L5zrXcqQ0SKEN3mIAysgKmhj+GW3Zj4hOOpSttkBPiUruUWwNmjyGc9ct Du3TUGfUDfdswSXS+ZSTn1C5lxruMkIj2Ouhfi6zN9jEQAI4hhH6xTNKPMdSjP64FUT4 a7vA== X-Gm-Message-State: APf1xPDbiewdyjjIo0VFLzdv82wx6Z/67l9xeQwP4nEwWNKXvEbYzlRl hb9881BI52xCFJ0lKdNzmb6zLHn6DJOL04FS43dv1w== X-Google-Smtp-Source: AH8x225q3fnWHIxOS6A0YuzYQRiSOkYK011+LRblTqwNkADUCjLyFEkKSofiw+D7J++HytY6Om4KOoUHrxCSRjCBo58= X-Received: by 10.36.217.22 with SMTP id p22mr16767294itg.106.1519741276089; Tue, 27 Feb 2018 06:21:16 -0800 (PST) MIME-Version: 1.0 Received: by 10.107.138.209 with HTTP; Tue, 27 Feb 2018 06:21:15 -0800 (PST) In-Reply-To: <27ef5753-9c6c-3b99-e732-084d9e444158@redhat.com> References: <20180224142515.461-1-ard.biesheuvel@linaro.org> <20180227015036.GC2261@SZX1000114654> <27ef5753-9c6c-3b99-e732-084d9e444158@redhat.com> From: Ard Biesheuvel Date: Tue, 27 Feb 2018 14:21:15 +0000 Message-ID: To: Laszlo Ersek Cc: Guo Heyi , "edk2-devel@lists.01.org" , Leif Lindholm Subject: Re: [PATCH edk2-platforms 1/2] Platform, Silicon: use DxeRuntimeDebugLibSerialPort for runtime DXE drivers 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: Tue, 27 Feb 2018 14:15:11 -0000 Content-Type: text/plain; charset="UTF-8" On 27 February 2018 at 10:43, Laszlo Ersek wrote: > On 02/27/18 10:23, Ard Biesheuvel wrote: >> On 27 February 2018 at 01:50, Guo Heyi wrote: >>> Hi Ard, >>> >>> Sorry for the late of seeing this patch. I have one question: why don't we >>> implement a runtime serial port lib, which will switch UART base address in >>> virtual address map change? I think this will be useful when we want to debug >>> runtime driver in OS stage. And if we have a runtime version of SerialPortLib, >>> then we don't need a runtime version of DebugLib which just disable touching >>> serial port. >>> >> >> Well, only if the serial port is not exposed to the OS as well. The >> Linux PL011 driver is especially easy to confuse, and having both the >> firmware and the OS control it at the same time is likely to cause >> problems. >> >> However, I do agree that having the ability to assign a UART to DEBUG >> at runtime is useful, and so I do intend to create a runtime version >> of the PL011 library, in which case DxeRuntimeDebugLibSerialPort can >> be replaced with BaseDebugLibSerialPort for DXE_RUNTIME_DRIVER >> modules. >> > > Converting the PL011 base address from phys to virt can be done in the > library instance, yes (and then every runtime driver module linked > against this library instance will individually convert the address for > its own use). The messier aspect is getting the PL011 base address into > the UEFI memmap, marked as MMIO / RUNTIME, so that the OS assign a > virtual mapping to it in the first place. > > The flash drivers generally do this with AddMemorySpace / > SetMemorySpaceAttributes. > > (Side point: while I agree that those are good APIs to invoke, I think > they should also call AllocateMemorySpace right after; otherwise a > "stray" AllocateMemorySpace elsewhere could allocate a chunk out of the > middle of what the flash driver *thinks* it owns.) > > The question is where this pair (or triplet) of GCD APIs should be called: > > - In a platform DXE driver? Perhaps. > > - In the DebugLib instance constructor / destructor? That could result > in some ugly reference counting -- you might want to keep the PL011 area > registered in GCD as long as *at least one* such runtime driver is loaded. > > This is different from the flash driver because the flash driver is the > sole runtime DXE (or SMM) driver that accesses & owns the flash MMIO > range. With the PL011 register block, that's not the case; all runtime > drivers that produce debug messages own it co-operatively. > Given that this SerialPortLib will be of the DXE_RUNTIME_DRIVER type anyway, couldn't we base it on a generic RuntimeUart protocol that we can depex on in the library, and produce in a separate [singleton] runtime DXE driver, which takes care of the UART initialization as well as the GCD memory space handling? In fact, we could modify DxeRuntimeDebugLibSerialPort to attach to this protocol if it exists at EndOfDxe, and either do nothing at runtime (as it does currently) or produce UART output via the protocol if it exists.