From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.4760.1588673133811378937 for ; Tue, 05 May 2020 03:05:34 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: ard.biesheuvel@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 68D1D31B; Tue, 5 May 2020 03:05:32 -0700 (PDT) Received: from [192.168.1.81] (unknown [10.37.8.24]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E50FB3F305; Tue, 5 May 2020 03:05:30 -0700 (PDT) Subject: Re: [edk2-platforms][PATCH 2/3] Platform/RPi/DualSerialPortLib: Fix miniUART serial divisor computation To: Pete Batard , devel@edk2.groups.io Cc: leif@nuviainc.com, awarkentin@vmware.com, Andrei Warkentin References: <20200504111548.11112-1-pete@akeo.ie> <20200504111548.11112-3-pete@akeo.ie> From: "Ard Biesheuvel" Message-ID: <905f3a90-276d-85a8-d7ed-669d10f99c17@arm.com> Date: Tue, 5 May 2020 12:05:28 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <20200504111548.11112-3-pete@akeo.ie> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit On 5/4/20 1:15 PM, Pete Batard wrote: > From: Andrei Warkentin > > Fix for https://github.com/raspberrypi/firmware/issues/1376. > > For the Pi 3, to properly configure miniUART, we need the core clock, > which can be vary between VideoCore firmare release or config.txt options. > > Unfortunately, it's painful to get - it's only available via the mailbox > interface. Additionally, SerialLib is a very limited environment, even > when linked in a DXE-mode component, because as part of a DebugLib > implementation it ends being the base prerequisite of everything. > That means a "normal" mailbox implementation like the one from > RpiFirmwareDxe (with dependencies on DmaLib) is out of the question. > Using a basic implementation such as the one in PlatformLib doesn't work > either because it operates in both environments with MMU on (DXE phase) > and MMU off (SEC/PrePi). > > Ideally, we read the value via mbox exactly once at boot (PlatformLib), > and then somehow stash it. A GUID Hob sounds appropriate, yet when > SerialPortLib operates in DXE components, we can't use the HobLib to > *locate* the Hob list itself (remember, SerialPortLib initializes > before any of HobLib's dependencies, like UeflLib...). > Yeah, the gift that keeps on giving :-) NXP are struggling with a similar issue. So the problem is that SerialPortInitialize() is called before we know what value to program, and we cannot rely on other libraries to discover this value because they may not work before their constructor has been called. So can we break the contents of SerialPortInitialize() into things that need to happen once (program the divisors etc) and things that need to happen each and every time (figure out which UART we are using in the first place)? If the second set does not suffer from the same issue, can we just move the entire logic that programs the UART block into PrePi, so that all subsequent users don't have to touch those registers at all? This means we may need two versions of DualSerialPortLib, where the one that PrePi uses may need to be attached to SerialDxe as well, so that it can reprogram the baud rate as needed. But for all the remaining DebugLib related uses, we don't really need to reprogram the UART at all afaics.