From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: None (no SPF record) identity=mailfrom; client-ip=2a00:1450:4010:c07::241; helo=mail-lf0-x241.google.com; envelope-from=mw@semihalf.com; receiver=edk2-devel@lists.01.org Received: from mail-lf0-x241.google.com (mail-lf0-x241.google.com [IPv6:2a00:1450:4010:c07::241]) (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 3D665209605C7 for ; Sun, 17 Jun 2018 13:12:33 -0700 (PDT) Received: by mail-lf0-x241.google.com with SMTP id p23-v6so9859789lfh.11 for ; Sun, 17 Jun 2018 13:12:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=OX506bKF0y6Un0Dq3tLGxcjtvYVs/ZxFA6HsOmmjtHo=; b=bKSXtVnTDimfsNrcL/XOK0l4LkMQzvle2mGSmg08X38mfbRSlwD4TJcl0AcTYgKM6T yvLwKM57HfR7MN6/TT7w0Q394JByYJxj/tz6sOmntPq5PbrKBeXBKYoKKRxUJL7JAPnF 0tGfZj+ms8sbQpgxpMSHP6OZT/acyH755eIPb0AVjtLb0j2/vF/MWeFf+J30HliWpdNT XvQe5IWehxTS9QyTnp5b9y3Ip22vC+ss3/trz3J1xyLX0cydBy/8p5dPSdZ4DctGIhsS EEtXrtcwENIRxYgre/yR8uKKpXvOfQJUnMpnOOJXdi2DzaYdX66Vj9CE1ZzLUS04RsNy Ss7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=OX506bKF0y6Un0Dq3tLGxcjtvYVs/ZxFA6HsOmmjtHo=; b=FIbya94qmZeWpmM6WGdX8TmXMurNgALyrecZK5CGhwKUwcrrWvss4cdzoqj2NNMyJx xGqJKjg7kT6LNkces3YzhKf30N4tANe6bogslXh2I5MkVJFtl3tkfdd4V1b2iI7yBB8B oHyemC80R0q9gKFrJ6Iex7q+wa0EJMWfMy/95rC0Uw5COEi05p+rH2jVYM41/akx59JG qoG8Coghu+R/83mfFDn36pOJQRy7Tvo0xOVsrR02VZPYwaXb8+4M3V5UV3KVdI6I+/Kr GFlm20cZpcUGwHS3GYIOLU5Y/W2XuuWL+FyreVsVSOv9OZidQl0ijKASQuYEn7akhlc/ fT3A== X-Gm-Message-State: APt69E1w8LbMEEADs9ZEbdsd0YS6uc9rXfysvmpQAWshCmBNO9v4IFva XpjK9ZZ992bzXe3wmRHQaBgHi/vTO0s= X-Google-Smtp-Source: ADUXVKLRnLmo99eY49WuJqmQpvBeOwy0gSK0DT0eYAdMMDLRuuhTEBxQAm7T783b2J1QSOAHESrCrA== X-Received: by 2002:a2e:1414:: with SMTP id u20-v6mr6535390ljd.134.1529266351248; Sun, 17 Jun 2018 13:12:31 -0700 (PDT) Received: from gilgamesh.semihalf.com (31-172-191-173.noc.fibertech.net.pl. [31.172.191.173]) by smtp.gmail.com with ESMTPSA id q75-v6sm387272lfq.47.2018.06.17.13.12.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 17 Jun 2018 13:12:30 -0700 (PDT) From: Marcin Wojtas To: edk2-devel@lists.01.org Cc: leif.lindholm@linaro.org, ard.biesheuvel@linaro.org, nadavh@marvell.com, jinghua@marvell.com, mw@semihalf.com, jsd@semihalf.com, jaz@semihalf.com Date: Sun, 17 Jun 2018 22:11:44 +0200 Message-Id: <1529266325-18371-5-git-send-email-mw@semihalf.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1529266325-18371-1-git-send-email-mw@semihalf.com> References: <1529266325-18371-1-git-send-email-mw@semihalf.com> Subject: [platforms: PATCH v2 04/25] Marvell/Drivers: MvBoardDesc: Introduce board description driver X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 17 Jun 2018 20:12:33 -0000 From: jinghua This patch introduces a producer of MARVELL_BOARD_DESC_PROTOCOL, which gets SoC description from ArmadaSoCDescLib, then based on dsc file, provide only enabled hardware module controllers for the consumers, which are typically controllers' drivers. Thanks to that there is a separation between obtaining the platform description and the drivers. A first example of the board description callback is information about UTMI controllers and type. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: jinghua Signed-off-by: Marcin Wojtas --- Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.inf | 65 ++++++++ Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.h | 57 +++++++ Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.c | 176 ++++++++++++++++++++ 3 files changed, 298 insertions(+) create mode 100644 Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.inf create mode 100644 Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.h create mode 100644 Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.c diff --git a/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.inf b/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.inf new file mode 100644 index 0000000..5da5f21 --- /dev/null +++ b/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.inf @@ -0,0 +1,65 @@ +# +# Marvell BSD License Option +# +# If you received this File from Marvell, you may opt to use, redistribute +# and/or modify this File under the following licensing terms. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# * Neither the name of Marvell nor the names of its contributors may be +# used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# + +[Defines] + INF_VERSION = 0x0001001A + BASE_NAME = BoardDescDxe + FILE_GUID = 4ed385f9-5d2c-4774-95c5-d5d9d70b3c37 + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + ENTRY_POINT = MvBoardDescEntryPoint + +[Sources] + MvBoardDescDxe.c + MvBoardDescDxe.h + +[Packages] + MdeModulePkg/MdeModulePkg.dec + MdePkg/MdePkg.dec + Silicon/Marvell/Marvell.dec + +[LibraryClasses] + ArmadaSoCDescLib + DebugLib + MemoryAllocationLib + UefiDriverEntryPoint + UefiLib + +[Protocols] + gMarvellBoardDescProtocolGuid + +[Pcd] + gMarvellTokenSpaceGuid.PcdPciEXhci + gMarvellTokenSpaceGuid.PcdUtmiControllersEnabled + gMarvellTokenSpaceGuid.PcdUtmiPortType + +[Depex] + TRUE diff --git a/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.h b/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.h new file mode 100644 index 0000000..2813f0d --- /dev/null +++ b/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.h @@ -0,0 +1,57 @@ +/******************************************************************************* +Copyright (C) 2018 Marvell International Ltd. +Marvell BSD License Option + +If you received this File from Marvell, you may opt to use, redistribute and/or +modify this File under the following licensing terms. +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +* Neither the name of Marvell nor the names of its contributors may be + used to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*******************************************************************************/ +#ifndef __MV_BOARD_DESC_H__ +#define __MV_BOARD_DESC_H__ + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +#define MV_BOARD_DESC_SIGNATURE SIGNATURE_64 ('M', 'V', 'B', 'R', 'D', 'D', 'S', 'C') + +typedef struct { + MARVELL_BOARD_DESC_PROTOCOL BoardDescProtocol; + UINTN Signature; + EFI_HANDLE Handle; + EFI_LOCK Lock; +} MV_BOARD_DESC; + +#endif // __MV_BOARD_DESC_H__ diff --git a/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.c b/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.c new file mode 100644 index 0000000..0232a21 --- /dev/null +++ b/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.c @@ -0,0 +1,176 @@ +/******************************************************************************* +Copyright (C) 2018 Marvell International Ltd. + +Marvell BSD License Option + +If you received this File from Marvell, you may opt to use, redistribute and/or +modify this File under the following licensing terms. +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +* Neither the name of Marvell nor the names of its contributors may be + used to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*******************************************************************************/ +#include "MvBoardDescDxe.h" + +MV_BOARD_DESC *mBoardDescInstance; + +STATIC +EFI_STATUS +MvBoardDescUtmiGet ( + IN MARVELL_BOARD_DESC_PROTOCOL *This, + IN OUT MV_BOARD_UTMI_DESC **UtmiDesc + ) +{ + UINT8 *UtmiDeviceEnabled, *XhciDeviceEnabled, *UtmiPortType; + UINTN UtmiCount, UtmiDeviceTableSize, UtmiIndex, Index; + MV_BOARD_UTMI_DESC *BoardDesc; + MV_SOC_UTMI_DESC *SoCDesc; + EFI_STATUS Status; + + /* Get SoC data about all available UTMI controllers */ + Status = ArmadaSoCDescUtmiGet (&SoCDesc, &UtmiCount); + if (EFI_ERROR (Status)) { + return Status; + } + + /* + * Obtain table with enabled Utmi PHY's, + * which is represented as an array of UINT8 values + * (0x0 - disabled, 0x1 enabled). + */ + UtmiDeviceEnabled = PcdGetPtr (PcdUtmiControllersEnabled); + if (UtmiDeviceEnabled == NULL) { + /* No UTMI PHY on platform */ + return EFI_SUCCESS; + } + + /* Make sure XHCI controllers table is present */ + XhciDeviceEnabled = PcdGetPtr (PcdPciEXhci); + if (XhciDeviceEnabled == NULL) { + DEBUG ((DEBUG_ERROR, "%a: Missing PcdPciEXhci\n", __FUNCTION__)); + return EFI_INVALID_PARAMETER; + } + + UtmiDeviceTableSize = PcdGetSize (PcdUtmiControllersEnabled); + + /* Check if PCD with UTMI PHYs is correctly defined */ + if ((UtmiDeviceTableSize > UtmiCount) || + (UtmiDeviceTableSize > PcdGetSize (PcdPciEXhci))) { + DEBUG ((DEBUG_ERROR, + "%a: Wrong PcdUtmiControllersEnabled format\n", + __FUNCTION__)); + return EFI_INVALID_PARAMETER; + } + + /* Obtain port type table - also stored as UINT8 array */ + UtmiPortType = PcdGetPtr (PcdUtmiPortType); + if ((UtmiPortType == NULL) || + (PcdGetSize (PcdUtmiPortType) != UtmiDeviceTableSize)) { + DEBUG ((DEBUG_ERROR, "%a: Wrong PcdUtmiPortType format\n", __FUNCTION__)); + return EFI_INVALID_PARAMETER; + } + + /* Allocate and fill board description */ + BoardDesc = AllocateZeroPool (UtmiDeviceTableSize * sizeof (MV_BOARD_UTMI_DESC)); + if (BoardDesc == NULL) { + DEBUG ((DEBUG_ERROR, "%a: Cannot allocate memory\n", __FUNCTION__)); + return EFI_OUT_OF_RESOURCES; + } + + UtmiIndex = 0; + for (Index = 0; Index < UtmiDeviceTableSize; Index++) { + if (!UtmiDeviceEnabled[Index]) { + continue; + } + + /* UTMI PHY without enabled XHCI controller is useless */ + if (!XhciDeviceEnabled[Index]) { + DEBUG ((DEBUG_ERROR, + "%a: Disabled Xhci controller %d\n", + Index, + __FUNCTION__)); + return EFI_INVALID_PARAMETER; + } + + BoardDesc[UtmiIndex].SoC = &SoCDesc[Index]; + BoardDesc[UtmiIndex].UtmiPortType = UtmiPortType[Index]; + UtmiIndex++; + } + + BoardDesc->UtmiDevCount = UtmiIndex; + + *UtmiDesc = BoardDesc; + + return EFI_SUCCESS; +} + +STATIC +VOID +MvBoardDescFree ( + IN VOID *BoardDesc + ) +{ + FreePool (BoardDesc); +} + +STATIC +EFI_STATUS +MvBoardDescInitProtocol ( + IN MARVELL_BOARD_DESC_PROTOCOL *BoardDescProtocol + ) +{ + BoardDescProtocol->BoardDescUtmiGet = MvBoardDescUtmiGet; + BoardDescProtocol->BoardDescFree = MvBoardDescFree; + + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +MvBoardDescEntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + mBoardDescInstance = AllocateZeroPool (sizeof (MV_BOARD_DESC)); + if (mBoardDescInstance == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + MvBoardDescInitProtocol (&mBoardDescInstance->BoardDescProtocol); + + mBoardDescInstance->Signature = MV_BOARD_DESC_SIGNATURE; + + Status = gBS->InstallMultipleProtocolInterfaces (&(mBoardDescInstance->Handle), + &gMarvellBoardDescProtocolGuid, + &(mBoardDescInstance->BoardDescProtocol)); + if (EFI_ERROR (Status)) { + FreePool (mBoardDescInstance); + return Status; + } + + return EFI_SUCCESS; +} -- 2.7.4