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 87F2C209574EF for ; Tue, 27 Feb 2018 02:37:31 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 51661402243B; Tue, 27 Feb 2018 10:43:37 +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 9735410B0F31; Tue, 27 Feb 2018 10:43:36 +0000 (UTC) To: Ard Biesheuvel , Guo Heyi Cc: "edk2-devel@lists.01.org" , Leif Lindholm References: <20180224142515.461-1-ard.biesheuvel@linaro.org> <20180227015036.GC2261@SZX1000114654> From: Laszlo Ersek Message-ID: <27ef5753-9c6c-3b99-e732-084d9e444158@redhat.com> Date: Tue, 27 Feb 2018 11:43:35 +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: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Tue, 27 Feb 2018 10:43:37 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Tue, 27 Feb 2018 10:43:37 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.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 10:37:33 -0000 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit 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. Thanks Laszlo