From patchwork Thu Sep 4 02:09:55 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laszlo Ersek X-Patchwork-Id: 36678 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f197.google.com (mail-ie0-f197.google.com [209.85.223.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 44B31204FF for ; Thu, 4 Sep 2014 02:10:44 +0000 (UTC) Received: by mail-ie0-f197.google.com with SMTP id rp18sf48525636iec.0 for ; Wed, 03 Sep 2014 19:10:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:subject:precedence:reply-to:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version :errors-to:x-original-sender:x-original-authentication-results :mailing-list:content-type:content-transfer-encoding; bh=DiYBP6FGYABqUWENaPiVHntIGJRUP+NdsXSqnlhYLN0=; b=VMjch8pLj10NmKCfojD8CVLF393DHu6VC8l8Z/KHu+ovrHg9QXutiV+oSy75fAZ93x Zlpi3pDaZi/2OJMlOa/Vq1TMtfNG2bDAA96uB/4DsW1MnWFml/VBcPTWryHVd81Ka1Df l37mUJHKRM8WG/3ouiUjYQ0mekHapS/+yVT5ofhQ/0Xrsvfks7PzrZOa7SwJC3v9cDe2 KvMaO+/3YUjkP94dQTbKZYutMNQpYNMwbzU0hejmhYCZN/3VtMqqH4EGtOdrXLlOMveS 76vDj/A3NaJwM3eo2xDwGd9F50URmgHguoMOwRY90QUxTyFug1MGAUBlkxizC765bXk/ talA== X-Gm-Message-State: ALoCoQlOJo8NWOo9DkDoezDNdge2o3N6Hizq9LvBdslDjl3xatAffYc2xofAluYLbyvFaQP6Es0C X-Received: by 10.50.28.68 with SMTP id z4mr902999igg.2.1409796643898; Wed, 03 Sep 2014 19:10:43 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.30.55 with SMTP id c52ls92991qgc.8.gmail; Wed, 03 Sep 2014 19:10:43 -0700 (PDT) X-Received: by 10.220.59.138 with SMTP id l10mr275704vch.59.1409796643779; Wed, 03 Sep 2014 19:10:43 -0700 (PDT) Received: from mail-vc0-f176.google.com (mail-vc0-f176.google.com [209.85.220.176]) by mx.google.com with ESMTPS id fd7si4913416vcb.71.2014.09.03.19.10.43 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 03 Sep 2014 19:10:43 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.176 as permitted sender) client-ip=209.85.220.176; Received: by mail-vc0-f176.google.com with SMTP id ik5so9917221vcb.35 for ; Wed, 03 Sep 2014 19:10:43 -0700 (PDT) X-Received: by 10.52.36.176 with SMTP id r16mr233054vdj.70.1409796643687; Wed, 03 Sep 2014 19:10:43 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.45.67 with SMTP id uj3csp767310vcb; Wed, 3 Sep 2014 19:10:43 -0700 (PDT) X-Received: by 10.42.81.146 with SMTP id z18mr39717ick.94.1409796642796; Wed, 03 Sep 2014 19:10:42 -0700 (PDT) Received: from lists.sourceforge.net (lists.sourceforge.net. [216.34.181.88]) by mx.google.com with ESMTPS id xc18si409029icb.78.2014.09.03.19.10.42 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 03 Sep 2014 19:10:42 -0700 (PDT) Received-SPF: pass (google.com: domain of edk2-devel-bounces@lists.sourceforge.net designates 216.34.181.88 as permitted sender) client-ip=216.34.181.88; Received: from localhost ([127.0.0.1] helo=sfs-ml-4.v29.ch3.sourceforge.com) by sfs-ml-4.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1XPMVO-0000Ha-GD; Thu, 04 Sep 2014 02:10:34 +0000 Received: from sog-mx-1.v43.ch3.sourceforge.com ([172.29.43.191] helo=mx.sourceforge.net) by sfs-ml-4.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1XPMVN-0000HV-Dz for edk2-devel@lists.sourceforge.net; Thu, 04 Sep 2014 02:10:33 +0000 Received-SPF: pass (sog-mx-1.v43.ch3.sourceforge.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=lersek@redhat.com; helo=mx1.redhat.com; Received: from mx1.redhat.com ([209.132.183.28]) by sog-mx-1.v43.ch3.sourceforge.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) id 1XPMVM-0006MD-9r for edk2-devel@lists.sourceforge.net; Thu, 04 Sep 2014 02:10:33 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s842AK5U027251 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 3 Sep 2014 22:10:20 -0400 Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-16.ams2.redhat.com [10.36.116.16]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s8429wjk009610; Wed, 3 Sep 2014 22:10:18 -0400 From: Laszlo Ersek To: ard.biesheuvel@linaro.org, edk2-devel@lists.sourceforge.net, olivier.martin@arm.com, peter.maydell@linaro.org, christoffer.dall@linaro.org, ilias.biris@linaro.org, leif.lindholm@linaro.org, michael.casadevall@linaro.org Date: Thu, 4 Sep 2014 04:09:55 +0200 Message-Id: <1409796596-12615-9-git-send-email-lersek@redhat.com> In-Reply-To: <1409796596-12615-1-git-send-email-lersek@redhat.com> References: <1409743096-14919-24-git-send-email-ard.biesheuvel@linaro.org> <1409796596-12615-1-git-send-email-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Spam-Score: -3.2 (---) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -1.7 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain X-Headers-End: 1XPMVM-0006MD-9r Subject: [edk2] [PATCH 8/9] FdtPL011SerialPortLib: add DXE_CORE implementation X-BeenThere: edk2-devel@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list Reply-To: edk2-devel@lists.sourceforge.net List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.sourceforge.net X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: lersek@redhat.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.176 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 DXE_CORE is special because it can use - neither the original, in-place DTB (since DXE_CORE itself reallocates that memory for DXE purposes), - nor any dynamic PCDs (because the PCD PPI's are no more available, and the PCD protocol is not yet available). Therefore we can only rely on the HOB where we stashed the UART base address. Accordingly, the FdtLib dependency is replaced with a HobLib dependency (relative to EarlyFdtPL011SerialPortLib), and so is the PcdPL011BaseAddress dependency (relative to FdtPL011SerialPortLib). Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek --- .../DxeCorePL011SerialPortLib.inf | 46 +++++++ .../DxeCorePL011SerialPortLib.c | 142 +++++++++++++++++++++ 2 files changed, 188 insertions(+) create mode 100644 ArmPlatformPkg/ArmVirtualizationPkg/Library/FdtPL011SerialPortLib/DxeCorePL011SerialPortLib.inf create mode 100644 ArmPlatformPkg/ArmVirtualizationPkg/Library/FdtPL011SerialPortLib/DxeCorePL011SerialPortLib.c diff --git a/ArmPlatformPkg/ArmVirtualizationPkg/Library/FdtPL011SerialPortLib/DxeCorePL011SerialPortLib.inf b/ArmPlatformPkg/ArmVirtualizationPkg/Library/FdtPL011SerialPortLib/DxeCorePL011SerialPortLib.inf new file mode 100644 index 0000000..19d9a1b --- /dev/null +++ b/ArmPlatformPkg/ArmVirtualizationPkg/Library/FdtPL011SerialPortLib/DxeCorePL011SerialPortLib.inf @@ -0,0 +1,46 @@ +#/** @file +# +# Component description file for DxeCorePL011SerialPortLib module +# +# Copyright (c) 2011-2012, ARM Ltd. All rights reserved.
+# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +#**/ + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = DxeCorePL011SerialPortLib + FILE_GUID = ED74F129-1287-4915-BA7A-1684A4C076F2 + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = SerialPortLib|DXE_CORE + CONSTRUCTOR = DxeCorePL011SerialPortLibInitialize + +[Sources.common] + DxeCorePL011SerialPortLib.c + +[LibraryClasses] + PL011UartLib + PcdLib + HobLib + +[Packages] + MdePkg/MdePkg.dec + ArmPlatformPkg/ArmPlatformPkg.dec + ArmPlatformPkg/ArmVirtualizationPkg/ArmVirtualizationPkg.dec + +[FixedPcd] + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultDataBits + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultParity + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultStopBits + +[Guids] + gEarlyPL011BaseAddressGuid diff --git a/ArmPlatformPkg/ArmVirtualizationPkg/Library/FdtPL011SerialPortLib/DxeCorePL011SerialPortLib.c b/ArmPlatformPkg/ArmVirtualizationPkg/Library/FdtPL011SerialPortLib/DxeCorePL011SerialPortLib.c new file mode 100644 index 0000000..3fbbf29 --- /dev/null +++ b/ArmPlatformPkg/ArmVirtualizationPkg/Library/FdtPL011SerialPortLib/DxeCorePL011SerialPortLib.c @@ -0,0 +1,142 @@ +/** @file + Serial I/O Port library functions with base address discovered from FDT + + Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.
+ Copyright (c) 2012 - 2013, ARM Ltd. All rights reserved.
+ Copyright (c) 2014, Linaro Ltd. All rights reserved.
+ Copyright (c) 2014, Red Hat, Inc.
+ + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +UINTN mSerialBaseAddress; + +RETURN_STATUS +EFIAPI +SerialPortInitialize ( + VOID + ) +{ + return RETURN_SUCCESS; +} + +RETURN_STATUS +EFIAPI +DxeCorePL011SerialPortLibInitialize ( + VOID + ) +{ + VOID *Hob; + CONST UINT64 *UartBase; + UINT64 BaudRate; + UINT32 ReceiveFifoDepth; + EFI_PARITY_TYPE Parity; + UINT8 DataBits; + EFI_STOP_BITS_TYPE StopBits; + + Hob = GetFirstGuidHob (&gEarlyPL011BaseAddressGuid); + if (Hob == NULL || GET_GUID_HOB_DATA_SIZE (Hob) != sizeof *UartBase) { + return RETURN_NOT_FOUND; + } + UartBase = GET_GUID_HOB_DATA (Hob); + + mSerialBaseAddress = (UINTN)*UartBase; + if (mSerialBaseAddress == 0) { + return RETURN_NOT_FOUND; + } + + BaudRate = (UINTN)PcdGet64 (PcdUartDefaultBaudRate); + ReceiveFifoDepth = 0; // Use the default value for Fifo depth + Parity = (EFI_PARITY_TYPE)PcdGet8 (PcdUartDefaultParity); + DataBits = PcdGet8 (PcdUartDefaultDataBits); + StopBits = (EFI_STOP_BITS_TYPE) PcdGet8 (PcdUartDefaultStopBits); + + return PL011UartInitializePort ( + mSerialBaseAddress, &BaudRate, &ReceiveFifoDepth, + &Parity, &DataBits, &StopBits); +} + +/** + Write data to serial device. + + @param Buffer Point of data buffer which need to be written. + @param NumberOfBytes Number of output bytes which are cached in Buffer. + + @retval 0 Write data failed. + @retval !0 Actual number of bytes written to serial device. + +**/ +UINTN +EFIAPI +SerialPortWrite ( + IN UINT8 *Buffer, + IN UINTN NumberOfBytes + ) +{ + if (mSerialBaseAddress != 0) { + return PL011UartWrite (mSerialBaseAddress, Buffer, NumberOfBytes); + } + return 0; +} + +/** + Read data from serial device and save the data in buffer. + + @param Buffer Point of data buffer which need to be written. + @param NumberOfBytes Number of output bytes which are cached in Buffer. + + @retval 0 Read data failed. + @retval !0 Actual number of bytes read from serial device. + +**/ +UINTN +EFIAPI +SerialPortRead ( + OUT UINT8 *Buffer, + IN UINTN NumberOfBytes +) +{ + if (mSerialBaseAddress != 0) { + return PL011UartRead (mSerialBaseAddress, Buffer, NumberOfBytes); + } + return 0; +} + +/** + Check to see if any data is available to be read from the debug device. + + @retval TRUE At least one byte of data is available to be read + @retval FALSE No data is available to be read + +**/ +BOOLEAN +EFIAPI +SerialPortPoll ( + VOID + ) +{ + if (mSerialBaseAddress != 0) { + return PL011UartPoll (mSerialBaseAddress); + } + return FALSE; +}