From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR02-VE1-obe.outbound.protection.outlook.com (EUR02-VE1-obe.outbound.protection.outlook.com [40.107.2.50]) by mx.groups.io with SMTP id smtpd.web12.3373.1590102198777655074 for ; Thu, 21 May 2020 16:03:19 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@nxp1.onmicrosoft.com header.s=selector2-nxp1-onmicrosoft-com header.b=F6B5WIEy; spf=pass (domain: oss.nxp.com, ip: 40.107.2.50, mailfrom: wasim.khan@oss.nxp.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RuGHPXlDxNRQzLrpXyhg3JeGeOF1Dp2zYPMEBQIqLTHOpnaHifNHI7NjUFUJEccpdwelhW4y0UHiPmzviUA3ndxdl2bIaBB6igXkeRqfx4YRxf3ub7DrSI3TWOp425JLuRnc3KXvrUzSUc9S4oCV0GoZVARfKoxfGccCMXsmD7AwO0sFyoBkkA1nNguSZu6+zAyqRaT2G7KgkQJjyFURvDBoh0vMdKXSRqHFUknQjjoLJIIuWQyHIdOd1x4ABCz26lyU24C92zAdn9aMi1eqCkCr0uiIcVQBnJ3oyboo8v62+y9LTTV13CIa3kWJDQa2qkNUbFeYfCj1NEIPP7gI3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vQraIhq0cQogTpCMJoyBY2CNdHmjuonP2pnpAQFZjmk=; b=NjigiPjgTDbYEtxkiDcw9YhDaUhoCWGgLYwbbRgmiINS5adV6fmf2157wBi1dl0jraMaNLrCB306gHtBVFqpFlnxVDoHpiYZxOx4g8ePEVjWKPK5pb9d/C2EP8rfG17xFkQu5yL1WjIRAVInw7yf1QJXFOKqbb3lSb/DF3qJxFKpdoCHQMOQuCSJY4v5iCYchjGc8kPZ2IACSvBvJlj/FNUsr6+8CDItbsTwuSZuaqkZ81GtxXMwakAICVllerQPfWGeqWoK4r8lLr5xY4COtNmELZmZq27xOGtqUXZMWTeBN3ji5QeWODhAcOmT+fCG8UFR/CWZar8++ek6UaFw7Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector2-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vQraIhq0cQogTpCMJoyBY2CNdHmjuonP2pnpAQFZjmk=; b=F6B5WIEyzyTZBoR9t2PBCXe4UMr5AxeIB7N26y/nNuoAkLFbjn4N34m131IAEl4268vhYOF+DSZ+cGEHNBdCXUr85AgrM9240Db7JEEb06sSeXrjYshlyKke9Ku743Pq+mNaR2QahWWi4nQ2fqPsjO6wn8lFdeV6rTbvCnMi1U8= Authentication-Results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=oss.nxp.com; Received: from VE1PR04MB6702.eurprd04.prod.outlook.com (2603:10a6:803:123::13) by VE1PR04MB6381.eurprd04.prod.outlook.com (2603:10a6:803:119::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.27; Thu, 21 May 2020 23:03:16 +0000 Received: from VE1PR04MB6702.eurprd04.prod.outlook.com ([fe80::81c4:97a6:7592:f225]) by VE1PR04MB6702.eurprd04.prod.outlook.com ([fe80::81c4:97a6:7592:f225%7]) with mapi id 15.20.3021.020; Thu, 21 May 2020 23:03:16 +0000 From: Wasim Khan To: devel@edk2.groups.io, meenakshi.aggarwal@nxp.com, vabhav.sharma@nxp.com, V.Sethi@nxp.com, ard.biesheuvel@arm.com, leif@nuviainc.com, jon@solid-run.com CC: Wasim Khan Subject: [PATCH edk2-platforms 03/16] Silicon/NXP: Implement PciHostBridgeLib support Date: Fri, 22 May 2020 04:32:06 +0530 Message-ID: <1590102139-16588-4-git-send-email-wasim.khan@oss.nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1590102139-16588-1-git-send-email-wasim.khan@oss.nxp.com> References: <1590102139-16588-1-git-send-email-wasim.khan@oss.nxp.com> X-ClientProxiedBy: PN1PR01CA0071.INDPRD01.PROD.OUTLOOK.COM (2603:1096:c00:1::11) To VE1PR04MB6702.eurprd04.prod.outlook.com (2603:10a6:803:123::13) Return-Path: wasim.khan@oss.nxp.com MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from wasimk-VirtualBox.nxp.com (157.47.200.219) by PN1PR01CA0071.INDPRD01.PROD.OUTLOOK.COM (2603:1096:c00:1::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.20.3021.23 via Frontend Transport; Thu, 21 May 2020 23:03:13 +0000 X-Mailer: git-send-email 2.7.4 X-Originating-IP: [157.47.200.219] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 339875ef-44d3-47b8-e399-08d7fddb251d X-MS-TrafficTypeDiagnostic: VE1PR04MB6381: X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:97; X-Forefront-PRVS: 041032FF37 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rAjALFlQnMuWyO2BQUwZ9SRpTi36loMMMXbbrvLoGh59zSiE2O9w/IoK6xkw1kj7Jy8ssEGM74h7ur0W1d9JmteB1Qwpshmc1Uuv5HcO2PVp/pmCAxHi670Cz42j2akY2g0EFWhsNIwM/MTCDNbvgvdvmaYGLAsLUx1txSdw2XtUMvzIo10JsXnQlOrbdbMs8DazwBt6nBbuEIkdS8jyPCCZXq4HpxyhQxFKtLg1ZY6oqG2eU6QIb2A+mfg5wFNKNpKZmhHA0DBkgmkKVckaZlayWK2CA+sjbxx4811Ye+8H8zJmcw3DqBRGNfwl1GdHsLVUSwlk+b3nfNIOH4emNw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VE1PR04MB6702.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(346002)(376002)(136003)(366004)(396003)(39860400002)(6506007)(52116002)(66476007)(2616005)(956004)(44832011)(66946007)(8936002)(8676002)(4326008)(316002)(478600001)(2906002)(16526019)(186003)(66556008)(86362001)(6512007)(19627235002)(5660300002)(6666004)(6486002)(30864003)(26005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: EEOd8PzjLrzlD0lZA/z15o3W/urFw/wriP12mKX4sb416/GKUTE8cn1b5W0qhY2ksixfQB9LigPLhODMx3ygnwsSLcLfKG/G78oeG1SirvsAnTIoqEHV/o8Qrtmca2IYeHRlAFMOCelDjwi0Agizt5VdbCGdFJCZ5l3BVH+aWXpWmf4UWev19wlssFqx8/AzNaPxdXCXDXap1Q7kDq80uTg+QD45POzh2NZ3W0cfsMpC17OOvhektZdQNYgaL6AhwZ153Km4VVAO9gcT5ESmio2nmevlfE1aWJEF/0j6RBrXsyZeHglWHOQFVhmAwUNOkggehyRzbu3SV2zsPw46/Sz9ANoHQ/xjmJ6ZwnrgJzUvHfUCYwYMZALWYhmpF9fEzUpIFv2nzonMz7ESRoGw6a2nLICZkG2x5/E7tu9y+ykZycArFyZcmuMCmlv1Ro1fizWivcMNhp3uouQpltEDQDT3GisevMf2ICbsNmJ9nIpnrlDy8vAz8EaLMU6JAM4Q X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 339875ef-44d3-47b8-e399-08d7fddb251d X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 May 2020 23:03:16.1463 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 7ZIqj4jhDqCULEn9GAu8TIWwgCx+8HIZfQKKdV5FZvyNdL1dhZVhbdZFKOJn/rjslNLUdc9k/WF4QBVaaHYbcw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB6381 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain From: Wasim Khan Implement PciHostBridgeLib that exposes the PCIe root complexes to the generic PCI host bridge driver. Setup PCIe Layerscape Controller and setup CFG, IO, MMIO and MMIO64 iATU windows. Signed-off-by: Vabhav Sharma Signed-off-by: Wasim Khan --- .../Library/PciHostBridgeLib/PciHostBridgeLib.inf | 40 ++ Silicon/NXP/Include/Pcie.h | 85 +++ .../Library/PciHostBridgeLib/PciHostBridgeLib.c | 568 +++++++++++++++++= ++++ 3 files changed, 693 insertions(+) create mode 100644 Silicon/NXP/Library/PciHostBridgeLib/PciHostBridgeLib.i= nf create mode 100755 Silicon/NXP/Include/Pcie.h create mode 100644 Silicon/NXP/Library/PciHostBridgeLib/PciHostBridgeLib.c diff --git a/Silicon/NXP/Library/PciHostBridgeLib/PciHostBridgeLib.inf b/Si= licon/NXP/Library/PciHostBridgeLib/PciHostBridgeLib.inf new file mode 100644 index 000000000000..5ddb96e4fa6a --- /dev/null +++ b/Silicon/NXP/Library/PciHostBridgeLib/PciHostBridgeLib.inf @@ -0,0 +1,40 @@ +## @file +# PCI Host Bridge Library instance for NXP ARM SOC +# +# Copyright 2018-2020 NXP +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION =3D 0x0001001A + BASE_NAME =3D PciHostBridgeLib + FILE_GUID =3D f4c99bcc-5c95-49ad-b0f3-fc5b611dc9c1 + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D PciHostBridgeLib + +[Sources] + PciHostBridgeLib.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + EmbeddedPkg/EmbeddedPkg.dec + Silicon/NXP/NxpQoriqLs.dec + +[LibraryClasses] + DebugLib + DevicePathLib + IoAccessLib + MemoryAllocationLib + PcdLib + +[FeaturePcd] + gNxpQoriqLsTokenSpaceGuid.PcdPciLutBigEndian + +[FixedPcd] + gNxpQoriqLsTokenSpaceGuid.PcdPciExp1BaseAddr + gNxpQoriqLsTokenSpaceGuid.PcdNumPciController + gNxpQoriqLsTokenSpaceGuid.PcdPcieLutBase + gNxpQoriqLsTokenSpaceGuid.PcdPcieLutDbg diff --git a/Silicon/NXP/Include/Pcie.h b/Silicon/NXP/Include/Pcie.h new file mode 100755 index 000000000000..d5b5a3884e0a --- /dev/null +++ b/Silicon/NXP/Include/Pcie.h @@ -0,0 +1,85 @@ +/** @file + PCI memory configuration for NXP + + Copyright 2018-2020 NXP + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#ifndef __PCI_H__ +#define __PCI_H__ + +#define PCI_SEG0_NUM 0 +#define PCI_SEG1_NUM 1 +#define PCI_SEG2_NUM 2 +#define PCI_SEG3_NUM 3 +#define PCI_SEG4_NUM 4 +#define PCI_SEG5_NUM 5 +#define PCI_SEG0_MMIO_MEMBASE FixedPcdGet64 (PcdPciExp1BaseAddr) +#define PCI_SEG0_DBI_BASE 0x03400000 + +#define PCI_LINK_DOWN 0x0 +#define PCI_LINK_UP 0x1 + +// Segment configuration +#define PCI_SEG_BUSNUM_MIN 0x0 +#define PCI_SEG_BUSNUM_MAX 0xff +#define PCI_SEG_PORTIO_MIN 0x0 +#define PCI_SEG_PORTIO_MAX 0xffff +#define SEG_CFG_SIZE 0x00001000 +#define SEG_MEM_BASE 0x40000000 +#define SEG_MEM_SIZE 0xC0000000 +#define SEG_MEM_LIMIT SEG_MEM_BASE + (SEG_MEM_SIZE -1) +#define SEG_IO_BASE 0x10000000 +#define SEG_MEM64_BASE 0x400000000 +#define PCI_BASE_DIFF 0x800000000 +#define PCI_DBI_SIZE_DIFF 0x100000 +#define PCI_SEG0_PHY_CFG0_BASE PCI_SEG0_MMIO_MEMBASE +#define PCI_SEG0_PHY_CFG1_BASE PCI_SEG0_PHY_CFG0_BASE + SEG_CFG_SIZE +#define PCI_SEG0_PHY_MEM_BASE PCI_SEG0_MMIO_MEMBASE + SEG_MEM_BASE +#define PCI_SEG0_PHY_MEM64_BASE PCI_SEG0_MMIO_MEMBASE + SEG_MEM64_BASE +#define PCI_SEG0_PHY_IO_BASE PCI_SEG0_MMIO_MEMBASE + SEG_IO_BASE + +// PCIe Controller configuration +#define NUM_PCIE_CONTROLLER FixedPcdGet32 (PcdNumPciController) +#define PCI_LUT_DBG FixedPcdGet32 (PcdPcieLutDbg) +#define PCI_LUT_BASE FixedPcdGet32 (PcdPcieLutBase) +#define LTSSM_PCIE_L0 0x11 + +#define PCI_CLASS_BRIDGE_PCI 0x0604 +#define PCI_CLASS_DEVICE 0x8 +#define PCI_DBI_RO_WR_EN 0x8bc +#define CLASS_CODE_MASK 0xffff +#define CLASS_CODE_SHIFT 0x10 + +// PCIe Layerscape Controller +#define IATU_VIEWPORT_OFF 0x900 +#define IATU_REGION_CTRL_1_OFF_OUTBOUND_0 0x904 +#define IATU_REGION_CTRL_2_OFF_OUTBOUND_0 0x908 +#define IATU_LWR_BASE_ADDR_OFF_OUTBOUND_0 0x90C +#define IATU_UPPER_BASE_ADDR_OFF_OUTBOUND_0 0x910 +#define IATU_LIMIT_ADDR_OFF_OUTBOUND_0 0x914 +#define IATU_LWR_TARGET_ADDR_OFF_OUTBOUND_0 0x918 +#define IATU_UPPER_TARGET_ADDR_OFF_OUTBOUND_0 0x91C +#define IATU_VIEWPORT_OUTBOUND 0x0 +#define IATU_REGION_CTRL_2_OFF_OUTBOUND_0_REGION_EN BIT31 + +// ATU Programming +#define IATU_REGION_CTRL_1_OFF_OUTBOUND_0_TYPE_MEM 0x0 +#define IATU_REGION_CTRL_1_OFF_OUTBOUND_0_TYPE_IO 0x2 +#define IATU_REGION_CTRL_1_OFF_OUTBOUND_0_TYPE_CFG0 0x4 +#define IATU_REGION_CTRL_1_OFF_OUTBOUND_0_TYPE_CFG1 0x5 +#define IATU_REGION_INDEX0 0x0 +#define IATU_REGION_INDEX1 0x1 +#define IATU_REGION_INDEX2 0x2 +#define IATU_REGION_INDEX3 0x3 +#define IATU_REGION_INDEX4 0x4 +#define IATU_REGION_INDEX5 0x5 +#define IATU_REGION_INDEX6 0x6 +#define IATU_REGION_INDEX7 0x7 +#define SEG_CFG_BUS 0x00000000 +#define SEG_MEM_BUS 0x40000000 +#define SEG_IO_SIZE 0x10000 +#define SEG_IO_BUS 0x0 + +#endif diff --git a/Silicon/NXP/Library/PciHostBridgeLib/PciHostBridgeLib.c b/Sili= con/NXP/Library/PciHostBridgeLib/PciHostBridgeLib.c new file mode 100644 index 000000000000..cf872370c7cd --- /dev/null +++ b/Silicon/NXP/Library/PciHostBridgeLib/PciHostBridgeLib.c @@ -0,0 +1,568 @@ +/** @file + PCI Host Bridge Library instance for NXP SoCs + + Copyright 2018-2020 NXP + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#pragma pack(1) +typedef struct { + ACPI_HID_DEVICE_PATH AcpiDevicePath; + EFI_DEVICE_PATH_PROTOCOL EndDevicePath; +} EFI_PCI_ROOT_BRIDGE_DEVICE_PATH; +#pragma pack () + +STATIC CONST EFI_PCI_ROOT_BRIDGE_DEVICE_PATH mEfiPciRootBridgeDevicePath[]= =3D { + { + { + { + ACPI_DEVICE_PATH, + ACPI_DP, + { + (UINT8)(sizeof (ACPI_HID_DEVICE_PATH)), + (UINT8)(sizeof (ACPI_HID_DEVICE_PATH) >> 8) + } + }, + EISA_PNP_ID (0x0A08), // PCI Express + PCI_SEG0_NUM + }, + + { + END_DEVICE_PATH_TYPE, + END_ENTIRE_DEVICE_PATH_SUBTYPE, + { + END_DEVICE_PATH_LENGTH, + 0 + } + } + }, + { + { + { + ACPI_DEVICE_PATH, + ACPI_DP, + { + (UINT8)(sizeof (ACPI_HID_DEVICE_PATH)), + (UINT8)(sizeof (ACPI_HID_DEVICE_PATH) >> 8) + } + }, + EISA_PNP_ID (0x0A08), // PCI Express + PCI_SEG1_NUM + }, + + { + END_DEVICE_PATH_TYPE, + END_ENTIRE_DEVICE_PATH_SUBTYPE, + { + END_DEVICE_PATH_LENGTH, + 0 + } + } + }, + { + { + { + ACPI_DEVICE_PATH, + ACPI_DP, + { + (UINT8)(sizeof (ACPI_HID_DEVICE_PATH)), + (UINT8)(sizeof (ACPI_HID_DEVICE_PATH) >> 8) + } + }, + EISA_PNP_ID (0x0A08), // PCI Express + PCI_SEG2_NUM + }, + + { + END_DEVICE_PATH_TYPE, + END_ENTIRE_DEVICE_PATH_SUBTYPE, + { + END_DEVICE_PATH_LENGTH, + 0 + } + } + }, + { + { + { + ACPI_DEVICE_PATH, + ACPI_DP, + { + (UINT8)(sizeof (ACPI_HID_DEVICE_PATH)), + (UINT8)(sizeof (ACPI_HID_DEVICE_PATH) >> 8) + } + }, + EISA_PNP_ID (0x0A08), // PCI Express + PCI_SEG3_NUM + }, + + { + END_DEVICE_PATH_TYPE, + END_ENTIRE_DEVICE_PATH_SUBTYPE, + { + END_DEVICE_PATH_LENGTH, + 0 + } + } + }, + { + { + { + ACPI_DEVICE_PATH, + ACPI_DP, + { + (UINT8)(sizeof (ACPI_HID_DEVICE_PATH)), + (UINT8)(sizeof (ACPI_HID_DEVICE_PATH) >> 8) + } + }, + EISA_PNP_ID (0x0A08), // PCI Express + PCI_SEG4_NUM + }, + + { + END_DEVICE_PATH_TYPE, + END_ENTIRE_DEVICE_PATH_SUBTYPE, + { + END_DEVICE_PATH_LENGTH, + 0 + } + } + }, + { + { + { + ACPI_DEVICE_PATH, + ACPI_DP, + { + (UINT8)(sizeof (ACPI_HID_DEVICE_PATH)), + (UINT8)(sizeof (ACPI_HID_DEVICE_PATH) >> 8) + } + }, + EISA_PNP_ID (0x0A08), // PCI Express + PCI_SEG5_NUM + }, + + { + END_DEVICE_PATH_TYPE, + END_ENTIRE_DEVICE_PATH_SUBTYPE, + { + END_DEVICE_PATH_LENGTH, + 0 + } + } + } +}; + +STATIC +GLOBAL_REMOVE_IF_UNREFERENCED +CHAR16 *mPciHostBridgeLibAcpiAddressSpaceTypeStr[] =3D { + L"Mem", L"I/O", L"Bus" +}; + +#define PCI_ALLOCATION_ATTRIBUTES EFI_PCI_HOST_BRIDGE_COMBINE_MEM_PM= EM | \ + EFI_PCI_HOST_BRIDGE_MEM64_DECODE + +#define PCI_SUPPORT_ATTRIBUTES EFI_PCI_ATTRIBUTE_ISA_IO_16 | \ + EFI_PCI_ATTRIBUTE_ISA_MOTHERBOARD_= IO | \ + EFI_PCI_ATTRIBUTE_VGA_MEMORY | \ + EFI_PCI_ATTRIBUTE_VGA_IO_16 | \ + EFI_PCI_ATTRIBUTE_VGA_PALETTE_IO_1= 6 + +PCI_ROOT_BRIDGE mPciRootBridges[NUM_PCIE_CONTROLLER]; + +/** + Helper function to check PCIe link state + + @param Pcie Address of PCIe host controller. + +**/ +STATIC +INTN +PcieLinkUp ( + IN EFI_PHYSICAL_ADDRESS Pcie, + IN UINT32 Idx + ) +{ + MMIO_OPERATIONS *PcieOps; + UINT32 State; + UINT32 LtssmMask; + + LtssmMask =3D 0x3f; + + PcieOps =3D GetMmioOperations (FeaturePcdGet (PcdPciLutBigEndian)); + State =3D PcieOps->Read32 ((UINTN)Pcie + PCI_LUT_BASE + PCI_LUT_DBG) & L= tssmMask; + + if (State < LTSSM_PCIE_L0) { + DEBUG ((DEBUG_INFO,"PCIE%d : reg @ 0x%lx, no link: LTSSM=3D0x%02x\n", + Idx + 1, Pcie, State)); + return PCI_LINK_DOWN; + } + + return PCI_LINK_UP; +} + +/** + Function to set-up PCIe outbound window + + @param Dbi Address of PCIe host controller. + @param Idx Index of iATU outbound window. + @param Type Type(Cfg0/Cfg1/Mem/IO) of iATU outbound window. + @param Phys PCIe controller phy address for outbound window. + @param BusAdr PCIe controller bus address for outbound window. + @param Size Window size + +**/ +STATIC +VOID +PcieOutboundSet ( + IN EFI_PHYSICAL_ADDRESS Dbi, + IN UINT32 Idx, + IN UINT32 Type, + IN UINT64 Phys, + IN UINT64 BusAddr, + IN UINT64 Size + ) +{ + // PCIe Layerscape : Outbound Window + MmioWrite32 (Dbi + IATU_VIEWPORT_OFF, + (UINT32)(IATU_VIEWPORT_OUTBOUND | Idx)); + + MmioWrite32 (Dbi + IATU_LWR_BASE_ADDR_OFF_OUTBOUND_0, + (UINT32)Phys); + + MmioWrite32 (Dbi + IATU_UPPER_BASE_ADDR_OFF_OUTBOUND_0, + (UINT32)(Phys >> 32)); + + MmioWrite32 (Dbi + IATU_LIMIT_ADDR_OFF_OUTBOUND_0, + (UINT32)(Phys + Size - BIT0)); + + MmioWrite32 (Dbi + IATU_LWR_TARGET_ADDR_OFF_OUTBOUND_0, + (UINT32)BusAddr); + + MmioWrite32 (Dbi + IATU_UPPER_TARGET_ADDR_OFF_OUTBOUND_0, + (UINT32)(BusAddr >> 32)); + + MmioWrite32 (Dbi + IATU_REGION_CTRL_1_OFF_OUTBOUND_0, + (UINT32)Type); + + MmioWrite32 (Dbi + IATU_REGION_CTRL_2_OFF_OUTBOUND_0, + IATU_REGION_CTRL_2_OFF_OUTBOUND_0_REGION_EN); +} + +/** + Function to set-up iATU windows for Layerscape PCIe controller + + @param Pcie Address of PCIe host controller + @param Cfg0Base PCIe controller phy address Type0 Configuration Space. + @param Cfg1Base PCIe controller phy address Type1 Configuration Space. + @param MemBase PCIe controller phy address Memory Space. + @param Mem64Base PCIe controller phy address MMIO64 Space. + @param IoBase PCIe controller phy address IO Space. +**/ +STATIC +VOID +PcieLsSetupAtu ( + IN EFI_PHYSICAL_ADDRESS Pcie, + IN EFI_PHYSICAL_ADDRESS Cfg0Base, + IN EFI_PHYSICAL_ADDRESS Cfg1Base, + IN EFI_PHYSICAL_ADDRESS MemBase, + IN EFI_PHYSICAL_ADDRESS Mem64Base, + IN EFI_PHYSICAL_ADDRESS IoBase + ) +{ + UINT64 Cfg0BaseAddr; + UINT64 Cfg1BaseAddr; + UINT64 Cfg0BusAddress; + UINT64 Cfg1BusAddress; + UINT64 Cfg0Size; + UINT64 Cfg1Size; + + Cfg0BaseAddr =3D Cfg0Base; + Cfg1BaseAddr =3D Cfg1Base; + Cfg0BusAddress =3D SEG_CFG_BUS; + Cfg1BusAddress =3D SEG_CFG_BUS; + Cfg0Size =3D SEG_CFG_SIZE; + Cfg1Size =3D SEG_CFG_SIZE; + + // iATU : OUTBOUND WINDOW 1 : CFG0 + PcieOutboundSet (Pcie, + IATU_REGION_INDEX0, + IATU_REGION_CTRL_1_OFF_OUTBOUND_0_TYPE_CFG0, + Cfg0BaseAddr, + Cfg0BusAddress, + Cfg0Size); + + // iATU : OUTBOUND WINDOW 2 : CFG1 + PcieOutboundSet (Pcie, + IATU_REGION_INDEX1, + IATU_REGION_CTRL_1_OFF_OUTBOUND_0_TYPE_CFG1, + Cfg1BaseAddr, + Cfg1BusAddress, + Cfg1Size); + + // iATU : OUTBOUND WINDOW 3 : MEM + PcieOutboundSet (Pcie, + IATU_REGION_INDEX2, + IATU_REGION_CTRL_1_OFF_OUTBOUND_0_TYPE_MEM, + MemBase, + SEG_MEM_BUS, + SEG_MEM_SIZE); + + // iATU : OUTBOUND WINDOW 4 : MMIO64 + PcieOutboundSet (Pcie, + IATU_REGION_INDEX3, + IATU_REGION_CTRL_1_OFF_OUTBOUND_0_TYPE_MEM, + Mem64Base, + Mem64Base, + SIZE_4GB); + Mem64Base +=3D SIZE_4GB; + + // iATU : OUTBOUND WINDOW 5 : MMIO64 + PcieOutboundSet (Pcie, + IATU_REGION_INDEX4, + IATU_REGION_CTRL_1_OFF_OUTBOUND_0_TYPE_MEM, + Mem64Base, + Mem64Base, + SIZE_4GB); + Mem64Base +=3D SIZE_4GB; + + // iATU : OUTBOUND WINDOW 6 : MMIO64 + PcieOutboundSet (Pcie, + IATU_REGION_INDEX5, + IATU_REGION_CTRL_1_OFF_OUTBOUND_0_TYPE_MEM, + Mem64Base, + Mem64Base, + SIZE_4GB + ); + Mem64Base +=3D SIZE_4GB; + + // iATU : OUTBOUND WINDOW 7 : MMIO64 + PcieOutboundSet (Pcie, + IATU_REGION_INDEX6, + IATU_REGION_CTRL_1_OFF_OUTBOUND_0_TYPE_MEM, + Mem64Base, + Mem64Base, + SIZE_4GB + ); + + // iATU : OUTBOUND WINDOW 8: IO + PcieOutboundSet (Pcie, + IATU_REGION_INDEX7, + IATU_REGION_CTRL_1_OFF_OUTBOUND_0_TYPE_IO, + IoBase, + SEG_IO_BUS, + SEG_IO_SIZE + ); +} +/** + Helper function to set-up PCIe controller + + @param Pcie Address of PCIe host controller + @param Cfg0Base PCIe controller phy address Type0 Configuration Space. + @param Cfg1Base PCIe controller phy address Type1 Configuration Space. + @param MemBase PCIe controller phy address Memory Space. + @param Mem64Base PCIe controller phy address MMIO64 Space. + @param IoBase PCIe controller phy address IO Space. + +**/ +STATIC +VOID +PcieSetupCntrl ( + IN EFI_PHYSICAL_ADDRESS Pcie, + IN EFI_PHYSICAL_ADDRESS Cfg0Base, + IN EFI_PHYSICAL_ADDRESS Cfg1Base, + IN EFI_PHYSICAL_ADDRESS MemBase, + IN EFI_PHYSICAL_ADDRESS Mem64Base, + IN EFI_PHYSICAL_ADDRESS IoBase + ) +{ + UINT32 Val; + + // PCIe Layerscape Controller Setup + PcieLsSetupAtu (Pcie, Cfg0Base, Cfg1Base, MemBase, Mem64Base, IoBase); + + // Program Class code for Layerscape PCIe controller + MmioWrite32 ((UINTN)Pcie + PCI_DBI_RO_WR_EN, 1); + Val =3D MmioRead32 ((UINTN)Pcie + PCI_CLASS_DEVICE); + Val &=3D ~(CLASS_CODE_MASK << CLASS_CODE_SHIFT); + Val |=3D (PCI_CLASS_BRIDGE_PCI << CLASS_CODE_SHIFT); + MmioWrite32 ((UINTN)Pcie + PCI_CLASS_DEVICE, Val); + MmioWrite32 ((UINTN)Pcie + PCI_DBI_RO_WR_EN, 0); +} + +/** + Return all the root bridge instances in an array. + + @param Count Return the count of root bridge instances. + + @return All the root bridge instances in an array. + +**/ +PCI_ROOT_BRIDGE * +EFIAPI +PciHostBridgeGetRootBridges ( + OUT UINTN *Count + ) +{ + UINTN Idx; + UINTN Loop; + UINT64 PciPhyMemAddr[NUM_PCIE_CONTROLLER]; + UINT64 PciPhyMem64Addr[NUM_PCIE_CONTROLLER]; + UINT64 PciPhyCfg0Addr[NUM_PCIE_CONTROLLER]; + UINT64 PciPhyCfg1Addr[NUM_PCIE_CONTROLLER]; + UINT64 PciPhyIoAddr[NUM_PCIE_CONTROLLER]; + UINT64 Regs[NUM_PCIE_CONTROLLER]; + INTN LinkUp; + + for (Idx =3D 0, Loop =3D 0; Idx < NUM_PCIE_CONTROLLER; Idx++) { + PciPhyMemAddr[Idx] =3D PCI_SEG0_PHY_MEM_BASE + (PCI_BASE_DIFF * Idx); + PciPhyMem64Addr[Idx] =3D PCI_SEG0_PHY_MEM64_BASE + (PCI_BASE_DIFF * Id= x); + PciPhyCfg0Addr[Idx] =3D PCI_SEG0_PHY_CFG0_BASE + (PCI_BASE_DIFF * Idx)= ; + PciPhyCfg1Addr[Idx] =3D PCI_SEG0_PHY_CFG1_BASE + (PCI_BASE_DIFF * Idx)= ; + PciPhyIoAddr [Idx] =3D PCI_SEG0_PHY_IO_BASE + (PCI_BASE_DIFF * Idx); + Regs[Idx] =3D PCI_SEG0_DBI_BASE + (PCI_DBI_SIZE_DIFF * Idx); + + // Check PCIe Link + LinkUp =3D PcieLinkUp(Regs[Idx], Idx); + + if (!LinkUp) { + continue; + } + DEBUG ((DEBUG_INFO, "PCIE%d Passed Linkup Phase\n", Idx + 1)); + // Set up PCIe Controller and ATU windows + PcieSetupCntrl (Regs[Idx], + PciPhyCfg0Addr[Idx], + PciPhyCfg1Addr[Idx], + PciPhyMemAddr[Idx], + PciPhyMem64Addr[Idx], + PciPhyIoAddr[Idx]); + + mPciRootBridges[Loop].Segment =3D Idx; + mPciRootBridges[Loop].Supports =3D PCI_SUPPORT_ATTRIBUTES= ; + mPciRootBridges[Loop].Attributes =3D PCI_SUPPORT_ATTRIBUTES= ; + mPciRootBridges[Loop].DmaAbove4G =3D TRUE; + mPciRootBridges[Loop].NoExtendedConfigSpace =3D FALSE; + mPciRootBridges[Loop].ResourceAssigned =3D FALSE; + mPciRootBridges[Loop].AllocationAttributes =3D PCI_ALLOCATION_ATTRIBU= TES; + + mPciRootBridges[Loop].Bus.Base =3D PCI_SEG_BUSNUM_MIN; + mPciRootBridges[Loop].Bus.Limit =3D PCI_SEG_BUSNUM_MAX; + + mPciRootBridges[Loop].Io.Base =3D PCI_SEG_PORTIO_MIN; + mPciRootBridges[Loop].Io.Limit =3D PCI_SEG_PORTIO_MAX; + mPciRootBridges[Loop].Io.Translation =3D MAX_UINT64 - + (SEG_IO_SIZE * Idx) + 1; + + mPciRootBridges[Loop].Mem.Base =3D SEG_MEM_BASE; + mPciRootBridges[Loop].Mem.Limit =3D SEG_MEM_LIMIT; + mPciRootBridges[Loop].Mem.Translation =3D MAX_UINT64 - + (PCI_SEG0_MMIO_MEMBASE + + (PCI_BASE_DIFF * + Idx)) + 1; + + mPciRootBridges[Loop].MemAbove4G.Base =3D PciPhyMem64Addr[Idx]; + mPciRootBridges[Loop].MemAbove4G.Limit =3D PciPhyMem64Addr[Idx] + + (SIZE_16GB - 1); + + mPciRootBridges[Loop].PMem.Base =3D MAX_UINT64; + mPciRootBridges[Loop].PMem.Limit =3D 0; + mPciRootBridges[Loop].PMemAbove4G.Base =3D MAX_UINT64; + mPciRootBridges[Loop].PMemAbove4G.Limit =3D 0; + mPciRootBridges[Loop].DevicePath =3D (EFI_DEVICE_PATH_PROTO= COL *)&mEfiPciRootBridgeDevicePath[Idx]; + Loop++; + } + + if (Loop =3D=3D 0) { + return NULL; + } + + *Count =3D Loop; + return mPciRootBridges; +} + +/** + Free the root bridge instances array returned from PciHostBridgeGetRootB= ridges(). + + @param Bridges The root bridge instances array. + @param Count The count of the array. +**/ +VOID +EFIAPI +PciHostBridgeFreeRootBridges ( + PCI_ROOT_BRIDGE *Bridges, + UINTN Count + ) +{ +} + +/** + Inform the platform that the resource conflict happens. + + @param HostBridgeHandle Handle of the Host Bridge. + @param Configuration Pointer to PCI I/O and PCI memory resource + descriptors. The Configuration contains the reso= urces + for all the root bridges. The resource for each = root + bridge is terminated with END descriptor and an + additional END is appended indicating the end of= the + entire resources. The resource descriptor field + values follow the description in + EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL + .SubmitResources(). + +**/ +VOID +EFIAPI +PciHostBridgeResourceConflict ( + EFI_HANDLE HostBridgeHandle, + VOID *Configuration + ) +{ + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Descriptor; + UINTN RootBridgeIndex; + DEBUG ((DEBUG_ERROR, "PciHostBridge: Resource conflict happens!\n")); + + RootBridgeIndex =3D 0; + Descriptor =3D (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *) Configuration; + while (Descriptor->Desc =3D=3D ACPI_ADDRESS_SPACE_DESCRIPTOR) { + DEBUG ((DEBUG_ERROR, "RootBridge[%d]:\n", RootBridgeIndex++)); + for (; Descriptor->Desc =3D=3D ACPI_ADDRESS_SPACE_DESCRIPTOR; Descript= or++) { + ASSERT (Descriptor->ResType < + ARRAY_SIZE (mPciHostBridgeLibAcpiAddressSpaceTypeStr)); + DEBUG ((DEBUG_ERROR, " %s: Length/Alignment =3D 0x%lx / 0x%lx\n", + mPciHostBridgeLibAcpiAddressSpaceTypeStr[Descriptor->ResType= ], + Descriptor->AddrLen, Descriptor->AddrRangeMax + )); + if (Descriptor->ResType =3D=3D ACPI_ADDRESS_SPACE_TYPE_MEM) { + DEBUG ((DEBUG_ERROR, " Granularity/SpecificFlag =3D %ld / %02x= %s\n", + Descriptor->AddrSpaceGranularity, Descriptor->SpecificFlag= , + ((Descriptor->SpecificFlag & + EFI_ACPI_MEMORY_RESOURCE_SPECIFIC_FLAG_CACHEABLE_PREFETC= HABLE + ) !=3D 0) ? L" (Prefetchable)" : L"" + )); + } + } + // + // Skip the END descriptor for root bridge + // + ASSERT (Descriptor->Desc =3D=3D ACPI_END_TAG_DESCRIPTOR); + Descriptor =3D (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *)( + (EFI_ACPI_END_TAG_DESCRIPTOR *)Descriptor + 1 + ); + } + + return; +} --=20 2.7.4