From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=66.187.233.73; helo=mx1.redhat.com; envelope-from=lersek@redhat.com; receiver=edk2-devel@lists.01.org Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 02C5D2034D8F9 for ; Tue, 27 Feb 2018 07:53:25 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 30BD640201A5; Tue, 27 Feb 2018 15:59:30 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-120-21.rdu2.redhat.com [10.10.120.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4734BAFD5E; Tue, 27 Feb 2018 15:59:29 +0000 (UTC) To: Guo Heyi Cc: Ard Biesheuvel , "edk2-devel@lists.01.org" , Leif Lindholm References: <20180224142515.461-1-ard.biesheuvel@linaro.org> <20180227015036.GC2261@SZX1000114654> <27ef5753-9c6c-3b99-e732-084d9e444158@redhat.com> <20180227113042.GF3918@SZX1000114654> From: Laszlo Ersek Message-ID: <706092d9-679d-d1e7-2253-946eda2b1b87@redhat.com> Date: Tue, 27 Feb 2018 16:59:28 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <20180227113042.GF3918@SZX1000114654> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Tue, 27 Feb 2018 15:59:30 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Tue, 27 Feb 2018 15:59:30 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'lersek@redhat.com' RCPT:'' 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 15:53:26 -0000 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit On 02/27/18 12:30, Guo Heyi wrote: > On Tue, Feb 27, 2018 at 11:43:35AM +0100, 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. > > On our platforms, we actually use > IntelFrameworkModulePkg/PeiDxeDebugLibReportStatusCode, > MdeModulePkg/RuntimeDxeReportStatusCodeLib and > IntelFrameworkModulePkg/StatusCodeRuntimeDxe as the whole DebugLib call chain > for runtime drivers. Is StatusCodeRuntimeDxe a good place for GCD manipulation? Sure; if DebugLib (and the library instances below it) don't directly access hardware, but make calls to some shared code -- i.e. into another runtime DXE driver via a protocol interface originally looked up / stashed at boot time, and then converted to a virtual address --, then only that runtime DXE driver needs to manage the GCD map. > But I've no idea on how to distinguish the code between ARM and X86, for X86 > uses port IO for serial port access. If you can ascertain that the lib instance linked into StatusCodeRuntimeDxe (a) is not used by any other module, and (b) performs the hardware access, then you could push the GCD management into that lib instance. Or else, you could write a plug-in lib instance and hook that with NULL resolution into the driver. But, I guess, at this point it's simplest to modify PlatformPei or PlatformDxe to add that entry to GCD in advance, regardless of the actual number of runtime DXE drivers that will rely on the mapping. Laszlo