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.69]) by mx.groups.io with SMTP id smtpd.web10.3368.1590102204659388752 for ; Thu, 21 May 2020 16:03:25 -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=T730SV2d; spf=pass (domain: oss.nxp.com, ip: 40.107.2.69, mailfrom: wasim.khan@oss.nxp.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FYhJ4NfTl1rJAGELIePUpUw7gtXCKp3NDn8NWdhTmnzZmZFCbUYa3GcFt/szvQVA3u+WqE7RwPhC2yBJR2ck+Kq6DrhNSjwnkJWNw4JEUJWN5H83PJwbosyYnwNsAm/WwMqW6Ui4zhxrM4pkw37vNV7L0xw1SEeDxTCrQ+Spt7dVxOlTBF4pFsbaCAVMOqCcEU1Tg2/ze8Bg+2H2PAkgwEcg2n4vSSZLnJbr9MEi2o1vQ5hYc/eQxvLG8aOKeBD3Uo2FnMPf/kVvW0w3K2LyPQJodAt86/tX8n+9f2WvwReDgsxRPKp+JIU9DKCoDTDT2TDBfLPwk0NuNNhILXbqDw== 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=QvtbGjGRq53ISNkxWZXXCMIYALp2diBeVfjUPYjvj+U=; b=LXcFQpuPmbR3w5jo2uhIPdNvaFwHM9hKJn6jySG2D0ymLUCnbRgvcxndQjjNoPlKX2tsCXTfInLG9/Rth2kawCkRJVAZHqS6iNE6sV4n+susGO4mTOEBfeZBpLZDbueZ9pkNFWlyU22DarDbz3z+YDM1cSSm7IFTMny/qPkkE1oBGyl3PJBCjscxe6c3DnYXhw1h9aKswVLQjKrzeKMNzc0qsW5PIL1jo0sVj1evaSoLVNchV8o54wSXGv7aRFmIVoB6Dp2AhacpC5PX1HbkS3kx4lcSqnYr4DxAmhLQgNdnqOMxs1OsSCJSip2CWvh+IrUZEhayzOv0zTSiJwphwA== 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=QvtbGjGRq53ISNkxWZXXCMIYALp2diBeVfjUPYjvj+U=; b=T730SV2dK3NBUYb3xAzrD9O1G9OF2ccz5IvQKmuyvFm0dJeDYeJUCxQ6LrS/gGSimcv0WTTmP8VJ4F7jMt7IzE/1Sh4o0ZcQTiA8rROWIr6s2d9vpint06oYmaNZmXm9LLi6m5U8uOUD2obSYJef/5C3rt6SucE+08FEbYymjUM= 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:22 +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:22 +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 05/16] Silicon/NXP: PciHostBridgeLib: Setup PCIe LsGen4 Controller and ATU Windows Date: Fri, 22 May 2020 04:32:08 +0530 Message-ID: <1590102139-16588-6-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:19 +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: 69aa3d3e-bc79-440a-3f20-08d7fddb286e 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:4941; X-Forefront-PRVS: 041032FF37 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: O6TY1+1yZXQC3ULCaRlt7JpP4hrKUf0OUbAU6gk699O9+wFTNQ/zC0EZxDjAW0ywQE/mnH/YWngX7htUf8ttk91CQhb+biOFQuVP8p5WR7oZCNNvhstwjdjW8hBvVmgEQ8xQkSj4BzAfae82hq0JPoNA6sd9EEWoYKVLUcY5cL9EvhY+dAUajNARQSVeF8bXpkOUU41GCXIjjGrkxP2nGvpdUBAYulMw8H8vTZhAtRkpYsEo9+EieeFQG9PlTaJQwj4dUaMOv8YJVX2gLad6ui3CL9GUwqWxFMpbMSsfrJiW+tFpCcK+UQA3/0mE7vVZ5xuocnHPs62TkGS8Ojouxg== 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:(6029001)(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: pLouClPyT5MD4SkHvqTgeaKKw8L2WpMWeWQ4zHccoMjjwFUMgbYYT+vhgk6o1PoeaI32BIUnrF5FMSwHfj2nZXLpXwNWJSrQr47B3jRgHYFMtxJa48GHVCPT+iiUO8PyOp89u9hCrFpGg9XNrZcWcug34U04BFJ+eQ7gYXxWnQwfg+Ku9m3t86veT9YGoZ0Q7j7eAI5w3axr8oLfjFdUXHEwKYBqbVWBLoEbRLGu5t/XdyYs7NQ+iKxmJk+snzR+H9oI6P6KLdBFOduq/nhUtdnhBrI7sD6u47SfG45bJFnmU6uzTPWznRiGkQGYSVA3Qut8pNzayczms3cagm7rZ9zPxznfyBoczwO698sjvsC1K7S+oIoy/81FQicTA+W0NGx7w435Nnu+QoE1tN8+lZFJ7/6TUAmmRwWrkUra1mTqGnt/IOt7MbaQAE/eFJ9u69gIFgHaTJ2A8ZiYHRTmd3tH2oPTsZeYLxjQInGDMIE/MHnOfMOLOviVKPHwE3pW X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 69aa3d3e-bc79-440a-3f20-08d7fddb286e X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 May 2020 23:03:21.9560 (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: 6ezv3ldAeBvLinccDK8ydfZOnznALdkC8VJ0kS+rBEV3fM9tMnhSZqTbC9C5vGG8KVwUAJ5+41guVYgaabNIMA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB6381 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain From: Wasim Khan Setup PCIe LayerscapeGen4 controller and setup CFG, IO, MMIO and MMIO64 iATU windows. Check for PcdPciLsGen4Ctrl to enable LsGen4 PCIe controller. Signed-off-by: Vabhav Sharma Signed-off-by: Wasim Khan --- Silicon/NXP/NxpQoriqLs.dec | 1 + .../Library/PciHostBridgeLib/PciHostBridgeLib.inf | 1 + Silicon/NXP/Include/Pcie.h | 120 ++++++++++ .../Library/PciHostBridgeLib/PciHostBridgeLib.c | 255 +++++++++++++++++= ---- 4 files changed, 336 insertions(+), 41 deletions(-) diff --git a/Silicon/NXP/NxpQoriqLs.dec b/Silicon/NXP/NxpQoriqLs.dec index 293fd773fd3d..8271d19ed8e5 100644 --- a/Silicon/NXP/NxpQoriqLs.dec +++ b/Silicon/NXP/NxpQoriqLs.dec @@ -39,3 +39,4 @@ [PcdsFixedAtBuild.common] =20 [PcdsDynamic.common] gNxpQoriqLsTokenSpaceGuid.PcdPciCfgShiftEnable|FALSE|BOOLEAN|0x00000600 + gNxpQoriqLsTokenSpaceGuid.PcdPciLsGen4Ctrl|FALSE|BOOLEAN|0x00000601 diff --git a/Silicon/NXP/Library/PciHostBridgeLib/PciHostBridgeLib.inf b/Si= licon/NXP/Library/PciHostBridgeLib/PciHostBridgeLib.inf index 98cfb6aee6b0..b777acdc103f 100644 --- a/Silicon/NXP/Library/PciHostBridgeLib/PciHostBridgeLib.inf +++ b/Silicon/NXP/Library/PciHostBridgeLib/PciHostBridgeLib.inf @@ -41,3 +41,4 @@ [FixedPcd] =20 [Pcd] gNxpQoriqLsTokenSpaceGuid.PcdPciCfgShiftEnable + gNxpQoriqLsTokenSpaceGuid.PcdPciLsGen4Ctrl diff --git a/Silicon/NXP/Include/Pcie.h b/Silicon/NXP/Include/Pcie.h index ae85190180e8..4c41c3585a8b 100755 --- a/Silicon/NXP/Include/Pcie.h +++ b/Silicon/NXP/Include/Pcie.h @@ -84,5 +84,125 @@ #define SEG_IO_BUS 0x0 =20 #define CFG_SHIFT_ENABLE (PcdGetBool (PcdPciCfgShiftEnable)) +#define PCI_LS_GEN4_CTRL (PcdGetBool (PcdPciLsGen4Ctrl)) =20 +// PCIe Layerscape Gen4 Controller +#define GPEX_CLASSCODE 0x474 +#define GPEX_CLASSCODE_SHIFT 16 +#define GPEX_CLASSCODE_MASK 0xffff +#define PAB_AXI_PIO_CTRL(Idx) (0x840 + 0x10 * Idx) +#define APIO_EN 0x1 +#define MEM_WIN_EN 0x1 << 1 +#define IO_WIN_EN 0x1 << 2 +#define CFG_WIN_EN 0x1 << 3 +#define PAB_PEX_PIO_CTRL(Idx) (0x8c0 + 0x10 * Idx) +#define PPIO_EN (0x1 << 0) +#define PAB_PEX_PIO_STAT(Idx) (0x8c4 + 0x10 * Idx) +#define PAB_PEX_PIO_MT_STAT(Idx) (0x8c8 + 0x10 * Idx) +#define PEX_AMAP_CTRL_TYPE_SHIFT 0x1 +#define PEX_AMAP_CTRL_EN_SHIFT 0x0 +#define PEX_AMAP_CTRL_TYPE_MASK 0x3 +#define PEX_AMAP_CTRL_EN_MASK 0x1 +#define PAB_PEX_AMAP_CTRL(Idx) (0x4ba0 + 0x10 * Idx) +#define PAB_EXT_PEX_AMAP_SIZE(Idx) (0xbef0 + 0x04 * Idx) +#define PAB_PEX_AMAP_AXI_WIN(Idx) (0x4ba4 + 0x10 * Idx) +#define PAB_EXT_PEX_AMAP_AXI_WIN(Idx) (0xb4a0 + 0x04 * Idx) +#define PAB_PEX_AMAP_PEX_WIN_L(Idx) (0x4ba8 + 0x10 * Idx) +#define PAB_PEX_AMAP_PEX_WIN_H(Idx) (0x4bac + 0x10 * Idx) +#define PAB_CTRL 0x808 +#define PAB_CTRL_APIO_EN 0x1 +#define PAB_CTRL_PPIO_EN (0x1 << 1) +#define PAB_CTRL_PAGE_SEL_SHIFT 13 +#define PAB_CTRL_PAGE_SEL_MASK 0x3f +#define INDIRECT_ADDR_BNDRY 0xc00 +#define PAGE_IDX_SHIFT 10 +#define PAGE_ADDR_MASK 0x3ff +#define PAB_AXI_AMAP_CTRL(Idx) (0xba0 + 0x10 * Idx) +#define PAB_EXT_AXI_AMAP_SIZE(Idx) (0xbaf0 + 0x4 * Idx) +#define PAB_AXI_AMAP_AXI_WIN(Idx) (0xba4 + 0x10 * Idx) +#define PAB_EXT_AXI_AMAP_AXI_WIN(Idx) (0x80a0 + 0x4 * Idx) +#define PAB_AXI_AMAP_PEX_WIN_L(Idx) (0xba8 + 0x10 * Idx) +#define PAB_AXI_AMAP_PEX_WIN_H(Idx) (0xbac + 0x10 * Idx) +#define PAB_AXI_TYPE_CFG 0x00 +#define PAB_AXI_TYPE_IO 0x01 +#define PAB_AXI_TYPE_MEM 0x02 +#define AXI_AMAP_CTRL_EN 0x1 +#define AXI_AMAP_CTRL_TYPE_SHIFT 1 +#define AXI_AMAP_CTRL_TYPE_MASK 0x3 +#define AXI_AMAP_CTRL_SIZE_SHIFT 10 +#define AXI_AMAP_CTRL_SIZE_MASK 0x3fffff + + +#define OFFSET_TO_PAGE_IDX(Off) ((Off >> PAGE_IDX_SHIFT) \ + & PAB_CTRL_PAGE_SEL_MASK) + +#define OFFSET_TO_PAGE_ADDR(Off) ((Off & PAGE_ADDR_MASK) \ + | INDIRECT_ADDR_BNDRY) +/** + Function to set page for LsGen4 Ctrl + + @param Dbi GPEX host controller address. + @param PgIdx The page index to select + +**/ +STATIC inline VOID PciLsGen4SetPg ( + IN EFI_PHYSICAL_ADDRESS Dbi, + IN UINT8 PgIdx + ) +{ + UINT32 Val; + Val =3D MmioRead32 (Dbi + PAB_CTRL); + Val &=3D ~(PAB_CTRL_PAGE_SEL_MASK << PAB_CTRL_PAGE_SEL_SHIFT); + Val |=3D (PgIdx & PAB_CTRL_PAGE_SEL_MASK) << PAB_CTRL_PAGE_SEL_SHIFT; + MmioWrite32 (Dbi + PAB_CTRL, Val); +} + +/** + Function to read LsGen4 PCIe controller config space + LsGen4 PCIe controller requires page number to be set + in Bridge Control Register(PAB) for offset > 3KB. + + @param Dbi GPEX host controller address. + @param Offset Offset to read from + +**/ +STATIC inline INTN PciLsGen4Read32 ( + IN EFI_PHYSICAL_ADDRESS Dbi, + IN UINT32 Offset + ) +{ + if (Offset < INDIRECT_ADDR_BNDRY) { + PciLsGen4SetPg (Dbi, 0); + return MmioRead32 (Dbi + Offset); + } else { + // If Offset > 3KB, paging mechanism is used + // Select page index and offset within the page + PciLsGen4SetPg (Dbi, OFFSET_TO_PAGE_IDX (Offset)); + return MmioRead32 (Dbi + OFFSET_TO_PAGE_ADDR (Offset)); + } +} + +/** + Function to write to LsGen4 PCIe controller config space + LsGen4 PCIe controller requires page number to be set + in Bridge Control Register(PAB) for offset > 3KB. + + @param Dbi GPEX host controller address + @param Offset Offset to read from + +**/ +STATIC inline VOID PciLsGen4Write32 ( + IN EFI_PHYSICAL_ADDRESS Dbi, + IN UINT32 Offset, + IN UINT32 Value + ) +{ + if (Offset < INDIRECT_ADDR_BNDRY) { + PciLsGen4SetPg (Dbi, 0); + MmioWrite32 (Dbi + Offset, Value); + } else { + PciLsGen4SetPg (Dbi, OFFSET_TO_PAGE_IDX (Offset)); + MmioWrite32 (Dbi + OFFSET_TO_PAGE_ADDR (Offset), Value); + } +} #endif diff --git a/Silicon/NXP/Library/PciHostBridgeLib/PciHostBridgeLib.c b/Sili= con/NXP/Library/PciHostBridgeLib/PciHostBridgeLib.c index f92863c60868..d9944313da21 100644 --- a/Silicon/NXP/Library/PciHostBridgeLib/PciHostBridgeLib.c +++ b/Silicon/NXP/Library/PciHostBridgeLib/PciHostBridgeLib.c @@ -201,7 +201,11 @@ PcieLinkUp ( UINT32 State; UINT32 LtssmMask; =20 - LtssmMask =3D 0x3f; + if (PCI_LS_GEN4_CTRL) { + LtssmMask =3D 0x7f; + } else { + LtssmMask =3D 0x3f; + } =20 PcieOps =3D GetMmioOperations (FeaturePcdGet (PcdPciLutBigEndian)); State =3D PcieOps->Read32 ((UINTN)Pcie + PCI_LUT_BASE + PCI_LUT_DBG) & L= tssmMask; @@ -237,38 +241,58 @@ PcieOutboundSet ( IN UINT64 Size ) { - // PCIe Layerscape : Outbound Window - MmioWrite32 (Dbi + IATU_VIEWPORT_OFF, - (UINT32)(IATU_VIEWPORT_OUTBOUND | Idx)); + UINT32 Val; =20 - 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); - - if (CFG_SHIFT_ENABLE && - ((Type =3D=3D IATU_REGION_CTRL_1_OFF_OUTBOUND_0_TYPE_CFG0) || - (Type =3D=3D IATU_REGION_CTRL_1_OFF_OUTBOUND_0_TYPE_CFG1))) { - MmioWrite32 (Dbi + IATU_REGION_CTRL_2_OFF_OUTBOUND_0, - (IATU_REGION_CTRL_2_OFF_OUTBOUND_0_REGION_EN | - IATU_ENABLE_CFG_SHIFT_FEATURE) - ); + if (PCI_LS_GEN4_CTRL) { + // PCIe Layerscape Gen4: Outbound Window + Size =3D ~(Size -1 ); + Val =3D PciLsGen4Read32 ((UINTN)Dbi, PAB_AXI_AMAP_CTRL (Idx)); + Val &=3D ~((AXI_AMAP_CTRL_TYPE_MASK << AXI_AMAP_CTRL_TYPE_SHIFT) | + (AXI_AMAP_CTRL_SIZE_MASK << AXI_AMAP_CTRL_SIZE_SHIFT) | + AXI_AMAP_CTRL_EN); + Val |=3D ((Type & AXI_AMAP_CTRL_TYPE_MASK) << AXI_AMAP_CTRL_TYPE_SHIFT= ) | + (((UINT32)Size >> AXI_AMAP_CTRL_SIZE_SHIFT) << + AXI_AMAP_CTRL_SIZE_SHIFT) | AXI_AMAP_CTRL_EN; + PciLsGen4Write32 ((UINTN)Dbi, PAB_AXI_AMAP_CTRL (Idx), Val); + PciLsGen4Write32 ((UINTN)Dbi, PAB_AXI_AMAP_AXI_WIN (Idx), (UINT32)Phys= ); + PciLsGen4Write32 ((UINTN)Dbi, PAB_EXT_AXI_AMAP_AXI_WIN (Idx), Phys >> = 32); + PciLsGen4Write32 ((UINTN)Dbi, PAB_AXI_AMAP_PEX_WIN_L (Idx), (UINT32)Bu= sAddr); + PciLsGen4Write32 ((UINTN)Dbi, PAB_AXI_AMAP_PEX_WIN_H (Idx), BusAddr >>= 32); + PciLsGen4Write32 ((UINTN)Dbi, PAB_EXT_AXI_AMAP_SIZE (Idx), Size >> 32)= ; } else { - MmioWrite32 (Dbi + IATU_REGION_CTRL_2_OFF_OUTBOUND_0, - IATU_REGION_CTRL_2_OFF_OUTBOUND_0_REGION_EN); + // 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); + + if (CFG_SHIFT_ENABLE && + ((Type =3D=3D IATU_REGION_CTRL_1_OFF_OUTBOUND_0_TYPE_CFG0) || + (Type =3D=3D IATU_REGION_CTRL_1_OFF_OUTBOUND_0_TYPE_CFG1))) { + MmioWrite32 (Dbi + IATU_REGION_CTRL_2_OFF_OUTBOUND_0, + (IATU_REGION_CTRL_2_OFF_OUTBOUND_0_REGION_EN | + IATU_ENABLE_CFG_SHIFT_FEATURE) + ); + } else { + MmioWrite32 (Dbi + IATU_REGION_CTRL_2_OFF_OUTBOUND_0, + IATU_REGION_CTRL_2_OFF_OUTBOUND_0_REGION_EN); + } } } =20 @@ -387,6 +411,124 @@ PcieLsSetupAtu ( SEG_IO_SIZE ); } + +/** + Function to set-up ATU windows for PCIe LayerscapeGen4 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 +PcieLsGen4SetupAtu ( + 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 + ) +{ + // ATU : OUTBOUND WINDOW 1 : CFG0 + PcieOutboundSet (Pcie, IATU_REGION_INDEX0, + PAB_AXI_TYPE_CFG, + Cfg0Base, + SEG_CFG_BUS, + SEG_CFG_SIZE); + + // ATU : OUTBOUND WINDOW 2 : IO + PcieOutboundSet (Pcie, IATU_REGION_INDEX1, + PAB_AXI_TYPE_IO, + IoBase, + SEG_IO_BUS, + SEG_IO_SIZE); + + // ATU : OUTBOUND WINDOW 3 : MEM + PcieOutboundSet (Pcie, IATU_REGION_INDEX2, + PAB_AXI_TYPE_MEM, + MemBase, + SEG_MEM_BUS, + SEG_MEM_SIZE); + + // ATU : OUTBOUND WINDOW 4 : MMIO64 + PcieOutboundSet (Pcie, IATU_REGION_INDEX3, + PAB_AXI_TYPE_MEM, + Mem64Base, + Mem64Base, + SIZE_4GB); + Mem64Base +=3D SIZE_4GB; + + // ATU : OUTBOUND WINDOW 5 : MMIO64 + PcieOutboundSet (Pcie, IATU_REGION_INDEX4, + PAB_AXI_TYPE_MEM, + Mem64Base, + Mem64Base, + SIZE_4GB); + Mem64Base +=3D SIZE_4GB; + + // ATU : OUTBOUND WINDOW 6 : MMIO64 + PcieOutboundSet (Pcie, IATU_REGION_INDEX5, + PAB_AXI_TYPE_MEM, + Mem64Base, + Mem64Base, + SIZE_4GB); + Mem64Base +=3D SIZE_4GB; + + // ATU : OUTBOUND WINDOW 7 : MMIO64 + PcieOutboundSet (Pcie, IATU_REGION_INDEX6, + PAB_AXI_TYPE_MEM, + Mem64Base, + Mem64Base, + SIZE_4GB); +} + +/** + Function to set-up PCIe inbound window + + @param Pcie Address of PCIe host controller. + @param Idx Index of inbound window. + @param Type Type(Cfg/Mem/IO) of iATU outbound window. + @param Phys PCIe controller phy address for inbound window. + @param BusAdr PCIe controller bus address for inbound window. + @param Size Window size + +**/ + +STATIC +VOID +PciSetupInBoundWin ( + IN EFI_PHYSICAL_ADDRESS Pcie, + IN UINT32 Idx, + IN UINT32 Type, + IN UINT64 Phys, + IN UINT64 BusAddr, + IN UINT64 Size) +{ + UINT32 Val; + UINT64 WinSize; + + if (PCI_LS_GEN4_CTRL) { + Val =3D PciLsGen4Read32 ((UINTN)Pcie, PAB_PEX_AMAP_CTRL(Idx)); + Val &=3D ~(PEX_AMAP_CTRL_TYPE_MASK << PEX_AMAP_CTRL_TYPE_SHIFT); + Val &=3D ~(PEX_AMAP_CTRL_EN_MASK << PEX_AMAP_CTRL_EN_SHIFT); + Val =3D (Val | (Type << PEX_AMAP_CTRL_TYPE_SHIFT)); + Val =3D (Val | (1 << PEX_AMAP_CTRL_EN_SHIFT)); + + WinSize =3D ~(Size - 1); + PciLsGen4Write32 ((UINTN)Pcie, PAB_PEX_AMAP_CTRL(Idx), + (Val | (UINT32)WinSize)); + PciLsGen4Write32 ((UINTN)Pcie, PAB_EXT_PEX_AMAP_SIZE(Idx), (WinSize>>3= 2)); + PciLsGen4Write32 ((UINTN)Pcie, PAB_PEX_AMAP_AXI_WIN(Idx), (UINT32)Phys= ); + PciLsGen4Write32 ((UINTN)Pcie, PAB_EXT_PEX_AMAP_AXI_WIN(Idx), (Phys>>3= 2)); + PciLsGen4Write32 ((UINTN)Pcie, PAB_PEX_AMAP_PEX_WIN_L(Idx), (UINT32)Bu= sAddr); + PciLsGen4Write32 ((UINTN)Pcie, PAB_PEX_AMAP_PEX_WIN_H(Idx), (BusAddr >= >32)); + } +} + /** Helper function to set-up PCIe controller =20 @@ -411,16 +553,47 @@ PcieSetupCntrl ( { UINT32 Val; =20 - // 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); + if (PCI_LS_GEN4_CTRL) { + // PCIe LsGen4 Controller Setup + + //Fix Class Code + Val =3D PciLsGen4Read32 ((UINTN)Pcie, GPEX_CLASSCODE); + Val &=3D ~(GPEX_CLASSCODE_MASK << GPEX_CLASSCODE_SHIFT); + Val |=3D PCI_CLASS_BRIDGE_PCI << GPEX_CLASSCODE_SHIFT; + PciLsGen4Write32 ((UINTN)Pcie, GPEX_CLASSCODE, Val); + + // Enable APIO and Memory/IO/CFG Windows + Val =3D PciLsGen4Read32 ((UINTN)Pcie, PAB_AXI_PIO_CTRL (0)); + Val |=3D APIO_EN | MEM_WIN_EN | IO_WIN_EN | CFG_WIN_EN; + PciLsGen4Write32 ((UINTN)Pcie, PAB_AXI_PIO_CTRL (0), Val); + + // LsGen4 Inbound Window Setup + PciSetupInBoundWin (Pcie, 0, PAB_AXI_TYPE_MEM, 0 , 0, SIZE_1TB); + + // LsGen4 Outbound Window Setup + PcieLsGen4SetupAtu (Pcie, Cfg0Base, Cfg1Base, MemBase, Mem64Base, IoBa= se); + + // Enable AMBA & PEX PIO + Val =3D PciLsGen4Read32 ((UINTN)Pcie, PAB_CTRL); + Val |=3D PAB_CTRL_APIO_EN | PAB_CTRL_PPIO_EN; + PciLsGen4Write32 ((UINTN)Pcie, PAB_CTRL, Val); + + Val =3D PciLsGen4Read32 ((UINTN)Pcie, PAB_PEX_PIO_CTRL(0)); + Val |=3D PPIO_EN; + PciLsGen4Write32 ((UINTN)Pcie, PAB_PEX_PIO_CTRL(0), Val); + + } else { + // 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); + } } =20 /** --=20 2.7.4