From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=pass header.i=@semihalf-com.20150623.gappssmtp.com header.s=20150623 header.b=uxtEVBkZ; spf=none, err=SPF record not found (domain: semihalf.com, ip: 209.85.208.193, mailfrom: mw@semihalf.com) Received: from mail-lj1-f193.google.com (mail-lj1-f193.google.com [209.85.208.193]) by groups.io with SMTP; Thu, 09 May 2019 02:54:04 -0700 Received: by mail-lj1-f193.google.com with SMTP id d15so1460158ljc.7 for ; Thu, 09 May 2019 02:54:03 -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=juXgyobhVC3jcXzUyUBJWChMPqgqKWWOS/i55H1cgQk=; b=uxtEVBkZANhw4fUArOYfgSBJlerFTFfy7q7zUYlbZI0ThxSL9E89rrE59mDCcuZauy PLVu4/+98wnNIbMdKefUxjbZjOhUCJyb2niiCVVIKfyEGNpOqavFjXJ16xgcxi8aqA5c mk6JaGjxlVWbfVnQEfYph/EiegGVfd8TjMDK+VFlgdgud8GE+H5QNYpCiRBTIJigAw/n qfhcovl8jMc6dXaS4lKd1+7K5Sn5EzGkyWRXe8uIxhG0PugCuRdqZF36hOm4J5AhSSG7 M3m7Xta+WAyDBtLCWtQz6SweHWfDNgz5TKzBiNNGwYC5U1Ogje63KlAR2BaRpCv9SAxp yZZQ== 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=juXgyobhVC3jcXzUyUBJWChMPqgqKWWOS/i55H1cgQk=; b=sczkbJoJswktnE4/0I6G188lKTErGHvdh9lIUctGQ+13Q+l2otk3ccKq9gz7gwrV2T 9eDhnKcUOHIlE82ATMlAGckL6mF4CT26lA50nGAUQu+u1zDbcKdQoqYs5bZkHcn3Xdf2 tASYYHs7e7fJ3m66MAeug//Peh6tn3C8BN7hVvdoM/Tg5vu0oq8AdwGA8Z4tnSAB/lDo GVt1i5u2FmNPDhIMf8iYdli7Mp+R3MfeKqyiJcJBecp/2P13XxpINb23mmDGwIdag1LT b+B/jymfFp+ZRYG/tYpOg34lm+C7uDhlX9VwazgBkknGMkFTaofBcUszHrSZk1s6ZVKA VuhA== X-Gm-Message-State: APjAAAUf4uqmit1qPorRRJcxo3uZtFrGexyqtXw0yGXP95uZSHkFxx31 M/Q344Ew8E8RFnJB4yf+6cTRXtjzuTw= X-Google-Smtp-Source: APXvYqwDiWP/0rh50el7FWm4aNuuUz6pay90oOzQlJv1TNKmUTXCAleHz7+d5wMTA7MzlsmmcCdbow== X-Received: by 2002:a2e:9e9a:: with SMTP id f26mr1887145ljk.170.1557395641851; Thu, 09 May 2019 02:54:01 -0700 (PDT) Return-Path: Received: from gilgamesh.semihalf.com (31-172-191-173.noc.fibertech.net.pl. [31.172.191.173]) by smtp.gmail.com with ESMTPSA id l25sm276668lfk.57.2019.05.09.02.54.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 09 May 2019 02:54:01 -0700 (PDT) From: "Marcin Wojtas" To: devel@edk2.groups.io Cc: leif.lindholm@linaro.org, ard.biesheuvel@linaro.org, mw@semihalf.com, jsd@semihalf.com, jaz@semihalf.com, kostap@marvell.com, Jici.Gao@arm.com, rebecca@bluestop.org, kettenis@jive.eu Subject: [edk2-platforms: PATCH 05/14] Marvell/Armada7k8k: MvBoardDesc: Extend protocol with PCIE support Date: Thu, 9 May 2019 11:53:33 +0200 Message-Id: <1557395622-32425-6-git-send-email-mw@semihalf.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1557395622-32425-1-git-send-email-mw@semihalf.com> References: <1557395622-32425-1-git-send-email-mw@semihalf.com> Introduce new callback that can provide information about PCIE controllers, which are used on the platform. According ArmadaSoCDescLib ArmadaBoardDescLib routines are used for obtaining required data. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Marcin Wojtas --- Silicon/Marvell/Include/Protocol/BoardDesc.h | 22 +++++ Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.c | 86 ++++++++++++++++++++ 2 files changed, 108 insertions(+) diff --git a/Silicon/Marvell/Include/Protocol/BoardDesc.h b/Silicon/Marvell/Include/Protocol/BoardDesc.h index 02905ea..c38ad86 100644 --- a/Silicon/Marvell/Include/Protocol/BoardDesc.h +++ b/Silicon/Marvell/Include/Protocol/BoardDesc.h @@ -90,6 +90,27 @@ EFI_STATUS IN OUT MV_BOARD_XHCI_DESC **XhciDesc ); +/** + Return the description of PCIE controllers used on the platform. + + @param[in out] *This Pointer to board description protocol. + @param[in out] **PcieDescription Array containing PCIE controllers' + description. + + @retval EFI_SUCCESS The data were obtained successfully. + @retval EFI_NOT_FOUND None of the controllers is used. + @retval EFI_INVALID_PARAMETER Description wrongly defined. + @retval EFI_OUT_OF_RESOURCES Lack of resources. + @retval Other Return error status. + +**/ +typedef +EFI_STATUS +(EFIAPI *MV_BOARD_PCIE_DESCRIPTION_GET) ( + IN MARVELL_BOARD_DESC_PROTOCOL *This, + IN OUT MV_BOARD_PCIE_DESCRIPTION **PcieDescription + ); + typedef EFI_STATUS (EFIAPI *MV_BOARD_DESC_PP2_GET) ( @@ -121,6 +142,7 @@ struct _MARVELL_BOARD_DESC_PROTOCOL { MV_BOARD_DESC_XHCI_GET BoardDescXhciGet; MV_BOARD_DESC_FREE BoardDescFree; MV_BOARD_GPIO_DESCRIPTION_GET GpioDescriptionGet; + MV_BOARD_PCIE_DESCRIPTION_GET PcieDescriptionGet; }; #endif // __MARVELL_BOARD_DESC_PROTOCOL_H__ diff --git a/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.c b/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.c index 973c362..9cd95bd 100644 --- a/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.c +++ b/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.c @@ -36,6 +36,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. MV_BOARD_DESC *mBoardDescInstance; STATIC MV_BOARD_GPIO_DESCRIPTION *mGpioDescription; +STATIC MV_BOARD_PCIE_DESCRIPTION *mPcieDescription; STATIC EFI_STATUS @@ -444,6 +445,90 @@ MvBoardDescXhciGet ( return EFI_SUCCESS; } +/** + Return the description of PCIE controllers used on the platform. + + @param[in out] *This Pointer to board description protocol. + @param[in out] **PcieDescription Array containing PCIE controllers' + description. + + @retval EFI_SUCCESS The data were obtained successfully. + @retval EFI_NOT_FOUND None of the controllers is used. + @retval EFI_INVALID_PARAMETER Description wrongly defined. + @retval EFI_OUT_OF_RESOURCES Lack of resources. + @retval Other Return error status. + +**/ +STATIC +EFI_STATUS +MvBoardPcieDescriptionGet ( + IN MARVELL_BOARD_DESC_PROTOCOL *This, + IN OUT MV_BOARD_PCIE_DESCRIPTION **PcieDescription + ) +{ + UINTN SoCPcieControllerCount, BoardPcieControllerCount, SoCIndex, BoardIndex; + EFI_PHYSICAL_ADDRESS *PcieBaseAddresses; + MV_PCIE_CONTROLLER *PcieControllers; + EFI_STATUS Status; + + /* Use existing structure if already created. */ + if (mPcieDescription != NULL) { + *PcieDescription = mPcieDescription; + return EFI_SUCCESS; + } + + /* Get SoC data about all available PCIE controllers. */ + Status = ArmadaSoCPcieGet (&PcieBaseAddresses, &SoCPcieControllerCount); + if (EFI_ERROR (Status)) { + return Status; + } + + /* Get per-board information about all used PCIE controllers. */ + Status = ArmadaBoardPcieControllerGet (&PcieControllers, + &BoardPcieControllerCount); + if (EFI_ERROR (Status)) { + return Status; + } + + /* Sanity check of the board description. */ + if (BoardPcieControllerCount > SoCPcieControllerCount) { + DEBUG ((DEBUG_ERROR, "%a: Too many controllers described\n", __FUNCTION__)); + return EFI_INVALID_PARAMETER; + } + + for (BoardIndex = 0; BoardIndex < BoardPcieControllerCount; BoardIndex++) { + for (SoCIndex = 0; SoCIndex < SoCPcieControllerCount; SoCIndex++) { + if (PcieControllers[BoardIndex].PcieBaseAddress == + PcieBaseAddresses[SoCIndex]) { + /* Match found */ + break; + } + } + if (SoCIndex == SoCPcieControllerCount) { + DEBUG ((DEBUG_ERROR, + "%a: Controller #%d base address invalid: 0x%x\n", + __FUNCTION__, + BoardIndex, + PcieControllers[BoardIndex].PcieBaseAddress)); + return EFI_INVALID_PARAMETER; + } + } + + /* Allocate and fill board description. */ + mPcieDescription = AllocateZeroPool (sizeof (MV_BOARD_PCIE_DESCRIPTION)); + if (mPcieDescription == NULL) { + DEBUG ((DEBUG_ERROR, "%a: Cannot allocate memory\n", __FUNCTION__)); + return EFI_OUT_OF_RESOURCES; + } + + mPcieDescription->PcieControllers = PcieControllers; + mPcieDescription->PcieControllerCount = BoardPcieControllerCount; + + *PcieDescription = mPcieDescription; + + return EFI_SUCCESS; +} + STATIC EFI_STATUS MvBoardDescPp2Get ( @@ -621,6 +706,7 @@ MvBoardDescInitProtocol ( BoardDescProtocol->BoardDescXhciGet = MvBoardDescXhciGet; BoardDescProtocol->BoardDescFree = MvBoardDescFree; BoardDescProtocol->GpioDescriptionGet = MvBoardGpioDescriptionGet; + BoardDescProtocol->PcieDescriptionGet = MvBoardPcieDescriptionGet; return EFI_SUCCESS; } -- 2.7.4