From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR04-DB3-obe.outbound.protection.outlook.com (EUR04-DB3-obe.outbound.protection.outlook.com [40.107.6.84]) by mx.groups.io with SMTP id smtpd.web10.47041.1590482297439758293 for ; Tue, 26 May 2020 01:38:17 -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=BT8koWeB; spf=pass (domain: oss.nxp.com, ip: 40.107.6.84, mailfrom: wasim.khan@oss.nxp.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YFwwmDJZJFLvtxSCrI8IXwuHSBpvysRuBhltFyatd+vQxBPRdjTpxKFyInlt1D2qZ7q2S3lit2sJq8/G7bSP3k/vkzu7KoYGgrOXVqATP2iqat0lmEz+sC8Mvg4oE3Df7j3RKzdrcF5NfqqQua46Rhewx0cHkApOc/Ry5+EGWYtlf1Pj468DY74Bbb0EhT13u1fkfJ2gsSlry3MwUW+EmLG2cpuHdVbzR45k0tgxIKCxDbnJ6vvoMcaqCioiEBI91q7XACqM5p4emczJbmsmbZuDn1lyikzcemocQq5xjoui723y87ZAK76zFjm884/W4TOtQ85Ua64jfkc2cJli7A== 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=gHeYp8eZHTUXky+bJzvqeof7Mw8uMaoHebwHfVxIJWQ=; b=c3Gc6Tdx/qUbShCzkO1qV/ArStM2DRlOfCT55W/hMQe6efdZQ4PnTLy/IZcfaSSOh2xWaxplYXYtcsiEy7S9+BNbRtWmWPujNsBGA0aDkzTQpJTxJlrWsplPAa24tuQw3CjHyekem45r0aslcdCF2t19A5swkkHcOZ/gQETc69QNCIuRStpS4BknD7dm4mfL1o9rflltJmjKy181QgLYqaplIwWPK/v6h2zDtrknJH4Txbc961wOHsFgGFWSkZuynwzLdUzthp3jT1RtKVZYaEpwYw7vB3y9BQuhUbaWW3IjeGosfWVd4Hr19En+N/SSq05FbDNGEgoyYbO07lsI/A== 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=gHeYp8eZHTUXky+bJzvqeof7Mw8uMaoHebwHfVxIJWQ=; b=BT8koWeBSUVZ3jxMJyH3fyulPyWz7ZCFDsXS1yIrEvtXpcrAuyc2hF+CtiycjPkhKhIHmHrq3aABNUwCO6e/Lqzl3o0KSZqEIvkiIWqhGGkU0hgckchzUc52qW8hoehVaEdL6Ry1/w+yl88ju0oA1UecQlqfAe0WBfhTzvtIn/w= 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 VE1PR04MB6367.eurprd04.prod.outlook.com (2603:10a6:803:11a::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.27; Tue, 26 May 2020 08:38:15 +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.029; Tue, 26 May 2020 08:38:15 +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 v2 03/16] Silicon/NXP: Implement PciHostBridgeLib support Date: Tue, 26 May 2020 14:07:08 +0530 Message-ID: <1590482241-13132-4-git-send-email-wasim.khan@oss.nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1590482241-13132-1-git-send-email-wasim.khan@oss.nxp.com> References: <1590482241-13132-1-git-send-email-wasim.khan@oss.nxp.com> X-ClientProxiedBy: BM1PR0101CA0015.INDPRD01.PROD.OUTLOOK.COM (2603:1096:b00:18::25) 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 (171.79.147.152) by BM1PR0101CA0015.INDPRD01.PROD.OUTLOOK.COM (2603:1096:b00:18::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.20.3021.23 via Frontend Transport; Tue, 26 May 2020 08:38:06 +0000 X-Mailer: git-send-email 2.7.4 X-Originating-IP: [171.79.147.152] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 9032c3f8-5d90-45d2-89ca-08d801501eac X-MS-TrafficTypeDiagnostic: VE1PR04MB6367: X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:120; X-Forefront-PRVS: 041517DFAB X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OX+HXJz7kQd4PPg9Pc4DV5NpKI/LQD0ZemMlGXyTAJoAOhVizIiyn+katcr2lbFjBOg5hbAxO9KSUeilbQqHhRqQZ1N+Yruspni//4/rrv+6CWGgPKh+j/gjq3a9/x6So1746y/j0BKEgLdUUIwgoLGUhHYa00WXdVDK1VvhFpnoE7Z7lUFO8dcoaGdTaQJrP/Wn9d9Hkc24+6IQ5ryZcg6fk/Hy6yQFVhb8+CgWSNyAjtKR+kfhrY9StkR7+hkJfqYjzzjCZncNIu0ayujNr6cyjpCB6Nk22fzrwG+yrDf+HX/dspqY9nWWHJi++yzE4tgsVwu6ROohD88j8AanNA== 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)(376002)(396003)(346002)(39860400002)(366004)(136003)(478600001)(30864003)(66946007)(86362001)(956004)(66476007)(44832011)(5660300002)(19627235002)(66556008)(316002)(2616005)(8936002)(2906002)(8676002)(6506007)(4326008)(16526019)(6486002)(52116002)(26005)(186003)(6512007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: WwRSbMVhmaSSrzY3vfmlpP5kovrKvgPeXEtBICcfHOIhva+R/HWrsWm2GzmylLXeJY70/wKEQDbOm1KqJ01yNQ397haOfOdf8+dfD7TcR95+I1lPZFzUJLAg/zMN64wSyqu/a1xtHAuItUDXNGjZSMZAHy4owwxWUgGmIwYfOCi3vtqr87BhrqdJ6TxiJHww4fDhMpRehUOGLdj6CgZWLtxiYfpLBwhvrm4tRUlpOJu87Fx64KRaukDqIuMtOaVYVMXOUZHRB1XQv/H5SR/1XpQh8W5lrv8Pkx00L/YtZ9613HWu3/Mvc8y8B9mCMuINYGXA2cD1DdSGhB32g6rPe02w2r54ZxxI4G81s26OGgXRByxbpsbPjKU4Mq9+qlfiDDL+BZ3Po6nEOwBhqZcQp+Nn/I+9JQPvW+spPq7sAdYJeDoBgxfEkNoA7bzT24QiI1MsyjXDDt25vCxznPIed2jPveDKTppFRzmdMhvNIuZWXPHqY5CeH1qHMlyXRqYR X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9032c3f8-5d90-45d2-89ca-08d801501eac X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 May 2020 08:38:14.9200 (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: oyVjK16QDsi1rGenH//6Ac7mqOodBEZmNtvpJs5Kggrn1kRp3kna+l+OOQrnzLHLxVMWKfGrDfhZbMKwXKpgww== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB6367 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. Co-authored-by: Vabhav Sharma Co-authored-by: Wasim Khan Signed-off-by: Wasim Khan --- Notes: V2: - Removed Signed-off and added Co-authored-by for co-author - Added logic to create MMIO64 windows based on MMIO64 available space - Drop EmbeddedPkg/EmbeddedPkg.dec - Removed "__" from header file inclusion Silicon/NXP/Library/PciHostBridgeLib/PciHostBridgeLib.inf | 39 ++ Silicon/NXP/Include/Pcie.h | 80 +++ Silicon/NXP/Library/PciHostBridgeLib/PciHostBridgeLib.c | 558 ++++++++++= ++++++++++ 3 files changed, 677 insertions(+) diff --git a/Silicon/NXP/Library/PciHostBridgeLib/PciHostBridgeLib.inf b/Si= licon/NXP/Library/PciHostBridgeLib/PciHostBridgeLib.inf new file mode 100644 index 000000000000..aa4802b019f6 --- /dev/null +++ b/Silicon/NXP/Library/PciHostBridgeLib/PciHostBridgeLib.inf @@ -0,0 +1,39 @@ +## @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 + 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..9dbe876b9c1a --- /dev/null +++ b/Silicon/NXP/Include/Pcie.h @@ -0,0 +1,80 @@ +/** @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_MMIO64_WIN_SIZE SIZE_16GB +#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 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..230fcf57690e --- /dev/null +++ b/Silicon/NXP/Library/PciHostBridgeLib/PciHostBridgeLib.c @@ -0,0 +1,558 @@ +/** @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; + UINT64 Mem64End; + UINT32 Index; + + 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; + + Index =3D 0; + // iATU : OUTBOUND WINDOW 1 : CFG0 + PcieOutboundSet (Pcie, + Index++, + IATU_REGION_CTRL_1_OFF_OUTBOUND_0_TYPE_CFG0, + Cfg0BaseAddr, + Cfg0BusAddress, + Cfg0Size); + + // iATU : OUTBOUND WINDOW 2 : CFG1 + PcieOutboundSet (Pcie, + Index++, + IATU_REGION_CTRL_1_OFF_OUTBOUND_0_TYPE_CFG1, + Cfg1BaseAddr, + Cfg1BusAddress, + Cfg1Size); + + // iATU : OUTBOUND WINDOW 3 : MEM + PcieOutboundSet (Pcie, + Index++, + IATU_REGION_CTRL_1_OFF_OUTBOUND_0_TYPE_MEM, + MemBase, + SEG_MEM_BUS, + SEG_MEM_SIZE); + + // + // To allow maximum MMIO64 space, MMIO64 window + // size must be multiple of max iATU size (4GB) + // + ASSERT ((PCI_MMIO64_WIN_SIZE & (SIZE_4GB - 1)) =3D=3D 0); + + Mem64End =3D Mem64Base + PCI_MMIO64_WIN_SIZE - 1; + while (Mem64Base < Mem64End) { + // iATU : OUTBOUND WINDOWs : MMIO64 + PcieOutboundSet (Pcie, + Index++, + IATU_REGION_CTRL_1_OFF_OUTBOUND_0_TYPE_MEM, + Mem64Base, + Mem64Base, + SIZE_4GB); + Mem64Base +=3D SIZE_4GB; + } + + // iATU : OUTBOUND WINDOW : IO + PcieOutboundSet (Pcie, + Index++, + 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] + + (PCI_MMIO64_WIN_SIZE - 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