From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=104.47.42.131; helo=nam03-by2-obe.outbound.protection.outlook.com; envelope-from=christopher.co@microsoft.com; receiver=edk2-devel@lists.01.org Received: from NAM03-BY2-obe.outbound.protection.outlook.com (mail-by2nam03on0131.outbound.protection.outlook.com [104.47.42.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 1A78420D7ADC5 for ; Thu, 19 Jul 2018 23:34:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=AV8Xp8qBrzUkU4iXxzTTPOjztxvmtGZ3DAN0MNA32sA=; b=kiNwgY0tk7UK4ewz2PuClVv12z+3scbDLPjuvSgXAGn5H+CkicaPCUhCKPOiaBGqZOHksvcyiek9GAmWfvDaZUCrnejR+EnLLpffwWvNI8A5vdezvleTPk87BPRW8TttCXrlaVJ4Ohx0Uep0PTsfxQfvY87O1aMj7vlVSNM6skk= Received: from SN6PR2101MB1136.namprd21.prod.outlook.com (52.132.114.25) by SN6PR2101MB1133.namprd21.prod.outlook.com (52.132.114.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.995.0; Fri, 20 Jul 2018 06:34:01 +0000 Received: from SN6PR2101MB1136.namprd21.prod.outlook.com ([fe80::78f8:214:33a:3c4]) by SN6PR2101MB1136.namprd21.prod.outlook.com ([fe80::78f8:214:33a:3c4%5]) with mapi id 15.20.0995.008; Fri, 20 Jul 2018 06:34:00 +0000 From: Chris Co To: "edk2-devel@lists.01.org" CC: Ard Biesheuvel , Leif Lindholm , Michael D Kinney Thread-Topic: [PATCH edk2-platforms 11/13] Silicon/NXP: Add i.MX6 PCIe DXE driver Thread-Index: AQHUH/OkQfo6AYnTl0m69bhE5GVbpg== Date: Fri, 20 Jul 2018 06:34:00 +0000 Message-ID: <20180720063328.26856-12-christopher.co@microsoft.com> References: <20180720063328.26856-1-christopher.co@microsoft.com> In-Reply-To: <20180720063328.26856-1-christopher.co@microsoft.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: CY4PR18CA0029.namprd18.prod.outlook.com (2603:10b6:903:9a::15) To SN6PR2101MB1136.namprd21.prod.outlook.com (2603:10b6:805:4::25) x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [2001:4898:80e8:a:75ac:13c7:7dde:5215] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; SN6PR2101MB1133; 6:BHf2RfMTc4LGrbhNv7j9ovy0TvHFQQPTQOymrw41NXSX+aI5+syHewikroWex94jD9t39aR6oaFVLGkMqOpgcP8dxz5ysJp2jfUEm7DtuONXfN32IZNNQmajMMMki19ynCtQXNbdDMI+bIiAbFdzgq4JBJYoiGsSwcHBYkjn8HXwG889Sq5bZRtOfYs73VWkbtvPoA3fb6s5j+oH05kHUxdCoytRHyJIA104v6jaMmsD0nIcm/7WbwkEXeYwRnrgwYthrtTgDnsNVJKDI2ylByiY7Am/87hJERlhHlqx2DXeGOVCKtpw6CpSRDbDSfBTaMWJuxV9BNl7qVMQHuMOHTu1xVGuBzLBnDfPCrWX74QQM0BXlWRVaCrVU0DFPTzQzF95QXIUF969JzSQznY6E2A1X4y4qeQjzcbQoSXCGNzI+DTNyYO6LT0aWOax4CmDk4RkUYFmIivYywlXA+vk9w==; 5:9a5k/MRD9j8i+7M1UcqFWmAZNtqhPi7f+6cG3nLkW97VDWVLrV9Kr5+8rIBsxnahXjQzQf2k8Smw30gaKNjr/2kufbJ/SwMWgiKdppj5CWpqpXlb5rnhiUBXs4ZCmdiFIWy2EKiIZY8YUtendvWzFqHzZmm4KRXxxDhd00b9Br8=; 7:v3fLXkw7ejjEemvHFmlKESsyiy0Ks0158ma5yd4orshvWJ6mmaY4DsCLHDadCreCo5xAnpA6OLswsK4BkcVXVIxyz8GXsbxZXlT4/dbZlzl3LV7WElXTJp0zQKGKrkZjHQaDG+e6BQ2PbV0OiCidIjUN4NCaSdLST4F5SjDV1AemYQGXSXnq+lRqbjByckYuaS1KukduZr2ivwO5d5wNU3L0Uv658/tNSpXaNkmuoh2WOcHP3IdoOVOt/GscNnhr x-ms-office365-filtering-correlation-id: 56d44d8f-fd57-408f-93f1-08d5ee0ac6e1 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989117)(5600067)(711020)(4618075)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(2017052603328)(7193020); SRVR:SN6PR2101MB1133; x-ms-traffictypediagnostic: SN6PR2101MB1133: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Christopher.Co@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(228905959029699); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(10201501046)(3002001)(3231311)(944501410)(52105095)(2018427008)(93006095)(93001095)(6055026)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123562045)(20161123560045)(20161123564045)(6072148)(201708071742011)(7699016); SRVR:SN6PR2101MB1133; BCL:0; PCL:0; RULEID:; SRVR:SN6PR2101MB1133; x-forefront-prvs: 073966E86B x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(1496009)(396003)(376002)(366004)(346002)(136003)(39860400002)(189003)(199004)(16200700003)(52116002)(16799955002)(53946003)(46003)(2906002)(2900100001)(15188155005)(36756003)(97736004)(386003)(256004)(99286004)(19627235002)(86612001)(575784001)(6506007)(14444005)(86362001)(186003)(76176011)(10090500001)(102836004)(1076002)(6306002)(6512007)(8936002)(6486002)(2616005)(476003)(5660300001)(486006)(478600001)(8676002)(6116002)(81156014)(81166006)(25786009)(4326008)(5640700003)(53376002)(53936002)(68736007)(6436002)(2501003)(10290500003)(22452003)(2351001)(7736002)(305945005)(5250100002)(6916009)(54906003)(14454004)(11346002)(72206003)(106356001)(966005)(316002)(446003)(105586002)(71600200003)(569006); DIR:OUT; SFP:1102; SCL:1; SRVR:SN6PR2101MB1133; H:SN6PR2101MB1136.namprd21.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: G5NzIjjkbd8VHRoctVj0jkavjLyiTlnwpeng3yw/W+etfp8Lz71l4C4nZRDZArf3tMzy6L7skxOGJ1PXlK2eKS3CjDyuR0s7KMYEFcH5ZR5PYu/QtD8fbajBSfvRFnJd6tScPA4NGCo/oPZs6riVV5f1Gwova9vO3mWUKEG1ac8ad6jdOIutELM6Cv9IPaPnCXYfiyPMany1jVSpW2XCIqxsSJB0ylVDh0JHt9QauuDHUvMEBa+6i3dxs3iUzkY6/3T4Z7ifXNPG8Lzbta/1AsW2x1ao5nPgI1TRmwv+Nt3Cx5ZvnexjYTV3SgJRMKdv/n1J67WULMdh1EEAJBmgc2pzOIfnianrjnhQ4ka5yEI= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 56d44d8f-fd57-408f-93f1-08d5ee0ac6e1 X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Jul 2018 06:34:00.4986 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR2101MB1133 Subject: [PATCH edk2-platforms 11/13] Silicon/NXP: Add i.MX6 PCIe DXE driver X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Jul 2018 06:34:03 -0000 Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable This adds DXE driver support for PCIe on NXP i.MX6 SoCs. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Christopher Co Cc: Ard Biesheuvel Cc: Leif Lindholm Cc: Michael D Kinney --- Silicon/NXP/iMX6Pkg/Drivers/PciExpress/iMX6PciExpress.c | 1219 +++++++++= +++++++++++ Silicon/NXP/iMX6Pkg/Drivers/PciExpress/iMX6PciExpress.h | 163 +++ Silicon/NXP/iMX6Pkg/Drivers/PciExpress/iMX6PciExpress.inf | 66 ++ 3 files changed, 1448 insertions(+) diff --git a/Silicon/NXP/iMX6Pkg/Drivers/PciExpress/iMX6PciExpress.c b/Sili= con/NXP/iMX6Pkg/Drivers/PciExpress/iMX6PciExpress.c new file mode 100644 index 000000000000..98f9cc034981 --- /dev/null +++ b/Silicon/NXP/iMX6Pkg/Drivers/PciExpress/iMX6PciExpress.c @@ -0,0 +1,1219 @@ +/** @file +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.
+* (C) Copyright 2015 Hewlett Packard Enterprise Development LP
+* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of the B= SD License +* which accompanies this distribution. The full text of the license may = be found at +* http://opensource.org/licenses/bsd-license.php +* +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IM= PLIED. +* +**/ + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include "iMX6PciExpress.h" + +PCI_RESOURCE PCIeResource[] =3D +{ + // + // Memory resource + // + { + PCIE_MEMORY_SPACE_BASE, + PCIE_MEMORY_SPACE_SIZE, + PCIE_MEMORY_SPACE_BASE + }, +}; + +// +// PCIe read and write function +// +EFI_STATUS PCIePciWrite ( + IN EFI_PCI_IO_PROTOCOL_WIDTH Width, + IN UINTN Address, + IN UINTN Count, + IN VOID *Buffer + ); + +EFI_STATUS PCIePciRead ( + IN EFI_PCI_IO_PROTOCOL_WIDTH Width, + IN UINTN Address, + IN UINTN Count, + IN VOID *Buffer + ); + +// +// Internal address translation unit configuration table. Map the PCIe dev= ice +// configuration baesd on configuration. PCI IO space is not supported on +// Windows. Memory space segment is just mapped back to the same address. +// +// The following table is used to setup basic translation setting on vario= us +// ATU (Address Translation Unit). The ATU is responsible to retranslate +// address for inbound and outbound message. +// +// Address match mode address translation is based on the following formul= a : +// Address =3D Address - Base Address + Target Address +// +// There really isnt a need to retranslate the address for iMX6 however pr= oceed +// the program the ATU to for configuration and memory message. +// + +IATU_SETTINGS iMX6iATUSettings[] =3D +{ + // + // Configuration message + // + { + OUTBOUND, + 0, + CFG0_TYPE, + PCIE_DEVICE_CONFIG_BASE_REG, + 0, + PCIE_DEVICE_CONFIG_BASE_REG + PCIE_DEVICE_CONFIG_SIZE - 1, + PCIE_DEVICE_CONFIG_BASE_REG, + 0, + REGION_ENABLE, + }, + + // + // Memory message + // + { + OUTBOUND, + 2, + MEMORY_TYPE, + PCIE_MEMORY_SPACE_BASE, + 0, + PCIE_MEMORY_SPACE_BASE + PCIE_MEMORY_SPACE_SIZE - 1, + PCIE_MEMORY_SPACE_BASE, + 0, + REGION_ENABLE, + }, +}; + +VOID PCIeSetupiATU ( + IN IATU_SETTINGS* SettingsPtr + ) +{ + volatile CSP_PCIE_PL_REGS* portLogicRegsPtr =3D + (CSP_PCIE_PL_REGS*)PCIE_CTRL_PORT_LOGIG_BASE_REG; + + ASSERT(SettingsPtr->RegionIndex < MAX_iATU_REGION); + + // + // Programs specific ATU region. Refer to the comment above + // iMX6iATUSettings table for more detail. + // + MmioWrite32( + (UINTN)&portLogicRegsPtr->PCIE_PL_iATUVR, + (SettingsPtr->RegionDirection << 31 | SettingsPtr->RegionIndex)); + + MmioWrite32( + (UINTN)&portLogicRegsPtr->PCIE_PL_iATURC2, + REGION_DISABLE); + + MmioWrite32( + (UINTN)&portLogicRegsPtr->PCIE_PL_iATURLBA, + SettingsPtr->LowerBaseAddr); + + MmioWrite32( + (UINTN)&portLogicRegsPtr->PCIE_PL_iATURUBA, + SettingsPtr->UpperBaseAddr); + + MmioWrite32( + (UINTN)&portLogicRegsPtr->PCIE_PL_iATURLA, + SettingsPtr->LimitAddr); + + MmioWrite32( + (UINTN)&portLogicRegsPtr->PCIE_PL_iATURLTA, + SettingsPtr->LowerTargetAddr); + + MmioWrite32( + (UINTN)&portLogicRegsPtr->PCIE_PL_iATURUTA, + SettingsPtr->UpperTargetAddr); + + MmioWrite32( + (UINTN)&portLogicRegsPtr->PCIE_PL_iATURC1, + SettingsPtr->Type); + + MmioWrite32( + (UINTN)&portLogicRegsPtr->PCIE_PL_iATURC2, + SettingsPtr->State); +} + +VOID PCIeSetupiATUSettings ( + VOID + ) +{ + UINT32 i; + + // + // Initialize internal address translation unit based on settings spec= ify + // in iMX6iATUSettings table. + // + for (i =3D 0; i < ARRAYSIZE (iMX6iATUSettings); ++i) { + PCIeSetupiATU(&iMX6iATUSettings[i]); + } + + return; +} + +EFI_STATUS PCIeSetPhyState ( + IN BOOLEAN State + ) +{ + IMX_IOMUXC_GPR1_REG gpr1Reg; + volatile IMX_IOMUXC_GPR_REGISTERS* ioMuxcGprRegisters =3D + (IMX_IOMUXC_GPR_REGISTERS*)IOMUXC_GPR_BASE_ADDRESS; + + gpr1Reg.AsUint32 =3D MmioRead32((UINTN)&ioMuxcGprRegisters->GPR1); + + if (State =3D=3D TRUE) { + gpr1Reg.REF_SSP_EN =3D 1; // Enable PCIe PHY + gpr1Reg.TEST_POWERDOWN =3D 0; // Power down is not requested + } else { + gpr1Reg.REF_SSP_EN =3D 0; // Disable PCIe PHY + gpr1Reg.TEST_POWERDOWN =3D 1; // Power down is requested + } + + MmioWrite32((UINTN)&ioMuxcGprRegisters->GPR1, gpr1Reg.AsUint32); + + return EFI_SUCCESS; +} + +EFI_STATUS PCIeSetupInitSetting ( + VOID + ) +{ + EFI_STATUS status; + IMX_IOMUXC_GPR1_REG gpr1Reg; + volatile IMX_IOMUXC_GPR_REGISTERS* ioMuxcGprRegisters =3D + (IMX_IOMUXC_GPR_REGISTERS*)IOMUXC_GPR_BASE_ADDRESS; + + // + // If PCIe PHY is already enabled we are in an unexpected state, just = exit + // and assume a bootloader has already setup PCIe and assigned resourc= es. + // + gpr1Reg.AsUint32 =3D MmioRead32((UINTN)&ioMuxcGprRegisters->GPR1); + + if (gpr1Reg.REF_SSP_EN =3D=3D 1) { + status =3D EFI_DEVICE_ERROR; + goto Exit; + } + + // + // Disable the PHY first, without this PCI link randomly does not come= up + // + status =3D PCIeSetPhyState(FALSE); + if (EFI_ERROR(status)) { + PCIE_ERROR("Failed to disable PCIe PHY\n"); + goto Exit; + } + + // + // First configure PCIe and PCIe PHY default setting + // + { + IMX_IOMUXC_GPR12_REG gpr12Reg; + IMX_IOMUXC_GPR8_REG gpr8Reg; + volatile IMX_IOMUXC_GPR_REGISTERS* ioMuxcGprRegisters =3D + (IMX_IOMUXC_GPR_REGISTERS*)IOMUXC_GPR_BASE_ADDRESS; + + gpr12Reg.AsUint32 =3D MmioRead32((UINTN)&ioMuxcGprRegisters->GPR12= ); + + gpr12Reg.APP_LTSSM_ENABLE =3D 0; // Set application not r= eady + gpr12Reg.DIA_STATUS_BUS_SELECT =3D 0xB; // Debug functionality + gpr12Reg.DEVICE_TYPE =3D 0x4; // Set to RC mode + gpr12Reg.LOS_LEVEL =3D 0x9; // Set to 0x9 per refere= nce manual + + MmioWrite32((UINTN)&ioMuxcGprRegisters->GPR12, gpr12Reg.AsUint32); + + // Gen1 | Gen2 3p5 | Gen2 6 | Swing full 127 | Swing low 127 + gpr8Reg.PCS_TX_DEEMPH_GEN1 =3D 0; + gpr8Reg.PCS_TX_DEEMPH_GEN2_3P5DB =3D 0; + gpr8Reg.PCS_TX_DEEMPH_GEN2_6DB =3D 20; + gpr8Reg.PCS_TX_SWING_FULL =3D 127; + gpr8Reg.PCS_TX_SWING_LOW =3D 127; + + MmioWrite32((UINTN)&ioMuxcGprRegisters->GPR8, gpr8Reg.AsUint32); + } + + status =3D EFI_SUCCESS; + +Exit: + return status; +} + +EFI_STATUS PCIeSetClockGate ( + IN IMX_CLOCK_GATE_STATE State + ) +{ + ImxClkPwrSetClockGate(IMX_PCIE_ROOT_ENABLE, State); + return EFI_SUCCESS; +} + +EFI_STATUS PCIeVerifyClocks ( + VOID + ) +{ + IMX_CCM_ANALOG_PLL_ENET_REG ccmAnalogPllReg; + volatile IMX_CCM_ANALOG_REGISTERS *ccmAnalogRegisters =3D + (IMX_CCM_ANALOG_REGISTERS *)IMX_CCM_ANALOG_BASE; + + ccmAnalogPllReg.AsUint32 =3D MmioRead32((UINTN)&ccmAnalogRegisters->PL= L_ENET); + + if ((ccmAnalogPllReg.POWERDOWN =3D=3D 0) && + (ccmAnalogPllReg.BYPASS =3D=3D 0) && + (ccmAnalogPllReg.ENABLE_125M =3D=3D 1) && + (ccmAnalogPllReg.LOCK =3D=3D 1)) { + return EFI_SUCCESS; + } + + return EFI_DEVICE_ERROR; +} + +VOID PCIeEnablePerstLine ( + VOID + ) +{ + // + // Enable board specific PERST line if one is defined + // + if (FixedPcdGet32(PcdPcieResetGpio)) { + ImxGpioWrite( + FixedPcdGet32(PcdPcieResetGpioBankNumber), + FixedPcdGet32(PcdPcieResetGpioIoNumber), + IMX_GPIO_HIGH); + gBS->Stall(20000); + } +} + +EFI_STATUS PCIeSetupPCIBridge ( + VOID + ) +{ + UINT8 classCode[0]; + + // + // Setup the bridge class + // + classCode[0] =3D PCI_IF_BRIDGE_P2P; + classCode[1] =3D PCI_CLASS_BRIDGE_P2P; + classCode[2] =3D PCI_CLASS_BRIDGE; + + return PCIePciWrite( + EfiPciIoWidthUint8, + PCIE_HOST_CONFIG_BASE_REG + PCI_CLASSCODE_OFFSET, + 3, + classCode); +} + +EFI_STATUS PCIeSetLinkStatus ( + IN BOOLEAN State + ) +{ + IMX_IOMUXC_GPR12_REG gpr12Reg; + volatile IMX_IOMUXC_GPR_REGISTERS* ioMuxcGprRegisters =3D + (IMX_IOMUXC_GPR_REGISTERS*)IOMUXC_GPR_BASE_ADDRESS; + + gpr12Reg.AsUint32 =3D MmioRead32((UINTN)&ioMuxcGprRegisters->GPR12); + + if (State =3D=3D TRUE) { + gpr12Reg.APP_LTSSM_ENABLE =3D 1; // Enable link + } else { + gpr12Reg.APP_LTSSM_ENABLE =3D 0; // Disable link + } + + MmioWrite32((UINTN)&ioMuxcGprRegisters->GPR12, gpr12Reg.AsUint32); + + return EFI_SUCCESS; +} + +BOOLEAN PCIeIsLinkUp ( + VOID + ) +{ + UINT32 debug1Reg; + volatile CSP_PCIE_PL_REGS* portLogicRegsPtr =3D + (CSP_PCIE_PL_REGS*)PCIE_CTRL_PORT_LOGIG_BASE_REG; + + debug1Reg =3D MmioRead32((UINTN)&portLogicRegsPtr->PCIE_PL_DEBUG1); + + return (debug1Reg & PCIE_PL_DEBUG1_PHY_LINK_UP) ? TRUE : FALSE; +} + +EFI_STATUS PCIeWaitForLink ( + VOID + ) +{ + UINT32 counter =3D 200; + BOOLEAN linkStatus; + + linkStatus =3D PCIeIsLinkUp(); + + // + // To optimize boot time, consider lowering timeout value + // + while (linkStatus =3D=3D FALSE && counter > 0) { + --counter; + gBS->Stall(1000); + linkStatus =3D PCIeIsLinkUp(); + } + + return (linkStatus) ? EFI_SUCCESS : EFI_DEVICE_ERROR; +} + +EFI_STATUS PCIeGetAlignAddress ( + IN UINTN Address, + IN UINTN AlignmentSize, + OUT UINTN *AlignAddress + ) +{ + EFI_STATUS status; + + *AlignAddress =3D 0; + + if ((AlignmentSize & (AlignmentSize - 1)) !=3D 0) { + status =3D EFI_INVALID_PARAMETER; + goto Exit; + } + + // + // Even though we do not add a (AlignmentSize + 1) to the incoming add= ress + // we would still align to the upper boundary as bit [19:00] is assume= d to + // be 0x000FFFFF per PCIe spec. + // + *AlignAddress =3D (Address) & ~(AlignmentSize - 1); + + status =3D EFI_SUCCESS; +Exit: + return status; +} + +EFI_STATUS PCIeGetPCIConfigAddress ( + IN UINTN BusNumber, + IN UINTN DevNumber, + IN UINTN FuncNumber, + IN UINTN Register, + OUT UINTN* Address + ) +{ + UINT64 offset; + EFI_STATUS status; + + // + // For now only support bus 0 and bus 1 with one device in each bus + // + if (BusNumber =3D=3D 0 && DevNumber =3D=3D 0) { + + offset =3D EFI_PCI_ADDRESS (BusNumber, DevNumber, FuncNumber, Regi= ster); + *Address =3D PCIE_HOST_CONFIG_BASE_REG + offset; + + status =3D EFI_SUCCESS; + + } else if (BusNumber =3D=3D 1 && DevNumber =3D=3D 0) { + + offset =3D EFI_PCI_ADDRESS (BusNumber, DevNumber, FuncNumber, Regi= ster); + offset -=3D EFI_PCI_ADDRESS (1, 0, FuncNumber, 0); + *Address =3D PCIE_DEVICE_CONFIG_BASE_REG + offset; + + status =3D EFI_SUCCESS; + + } else { + *Address =3D 0; + status =3D EFI_INVALID_PARAMETER; + } + + return status; +} + +EFI_STATUS PCIePciRead ( + IN EFI_PCI_IO_PROTOCOL_WIDTH Width, + IN UINTN Address, + IN UINTN Count, + OUT VOID *Buffer + ) +{ + PTR dest; + UINTN stride; + EFI_STATUS status; + + dest.ui =3D (UINTN)Buffer; + Width =3D (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH)(Width & 0x03); + stride =3D (UINTN)1 << Width; + + // + // Adopted from PciRootBridgeIoMemRW + // + switch (Width) { + case EfiPciWidthUint8: + for (; Count > 0; --Count, dest.buf +=3D stride, Address +=3D stri= de) { + *dest.ui8 =3D MmioRead8(Address); + } + status =3D EFI_SUCCESS; + break; + case EfiPciWidthUint16: + for (; Count > 0; --Count, dest.buf +=3D stride, Address +=3D stri= de) { + *dest.ui16 =3D MmioRead16(Address); + } + status =3D EFI_SUCCESS; + break; + case EfiPciWidthUint32: + for (; Count > 0; --Count, dest.buf +=3D stride, Address +=3D stri= de) { + *dest.ui32 =3D MmioRead32(Address); + } + status =3D EFI_SUCCESS; + break; + default: + status =3D EFI_INVALID_PARAMETER; + goto Exit; + } + +Exit: + return status; +} + +EFI_STATUS PCIePciWrite ( + IN EFI_PCI_IO_PROTOCOL_WIDTH Width, + IN UINTN Address, + IN UINTN Count, + IN VOID *Buffer + ) +{ + PTR src; + UINTN stride; + EFI_STATUS status; + + src.ui =3D (UINTN)Buffer; + Width =3D (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH)(Width & 0x03); + stride =3D (UINTN)1 << Width; + + // + // Adopted from PciRootBridgeIoMemRW + // + switch (Width) { + case EfiPciWidthUint8: + for (; Count > 0; --Count, src.buf +=3D stride, Address +=3D strid= e) { + MmioWrite8(Address, *src.ui8); + } + status =3D EFI_SUCCESS; + break; + case EfiPciWidthUint16: + for (; Count > 0; --Count, src.buf +=3D stride, Address +=3D strid= e) { + MmioWrite16(Address, *src.ui16); + } + status =3D EFI_SUCCESS; + break; + case EfiPciWidthUint32: + for (; Count > 0; --Count, src.buf +=3D stride, Address +=3D strid= e) { + MmioWrite32(Address, *src.ui32); + } + status =3D EFI_SUCCESS; + break; + default: + status =3D EFI_INVALID_PARAMETER; + goto Exit; + } + +Exit: + return status; +} + +EFI_STATUS PCIeDevicePresent ( + OUT PCI_TYPE00* PciDevice, + IN UINTN Bus, + IN UINTN Device, + IN UINTN Func + ) +{ + UINTN address; + EFI_STATUS status; + + // + // Create PCI address map in terms of Bus, Device, and Func + // + status =3D PCIeGetPCIConfigAddress(Bus, Device, Func, 0, &address); + if (EFI_ERROR(status)) { + status =3D EFI_NOT_FOUND; + goto Exit; + } + + // + // Read the Vendor ID register + // + status =3D PCIePciRead( + EfiPciWidthUint32, + address, + 1, + PciDevice); + if (!EFI_ERROR(status) && (PciDevice->Hdr).VendorId !=3D 0xffff) { + // + // Read the entire config header for the device + // + status =3D PCIePciRead( + EfiPciWidthUint32, + address, + sizeof (PCI_TYPE00) / sizeof (UINT32), + PciDevice); + if (EFI_ERROR(status)) { + PCIE_ERROR("Failed to read PCI config space\n"); + } + } else { + PCIE_INFO("No PCIe device found\n"); + status =3D EFI_NOT_FOUND; + } + +Exit: + return status; +} + +EFI_STATUS PCIeGetMemoryBarResource ( + IN UINTN BarSize, + IN UINTN* BarAddress, + IN BOOLEAN IsBridgeDevice + ) +{ + EFI_STATUS status; + + if (BarSize > PCIeResource->Size) { + PCIE_ERROR("Insufficient PCIe memory for 0x%08x (Current size 0x%0= 8x)\n", + BarSize, + PCIeResource->Size); + status =3D EFI_OUT_OF_RESOURCES; + goto Exit; + } + + *BarAddress =3D PCIeResource->Curr; + + if (IsBridgeDevice =3D=3D FALSE) { + PCIeResource->Curr +=3D BarSize; + PCIeResource->Size -=3D BarSize; + + PCIE_INFO("Allocating memory resource 0x%08x size 0x%08x\n", + *BarAddress, + BarSize); + } + + PCIE_INFO("Current memory resource 0x%08x Size 0x%08x\n", + PCIeResource->Curr, + PCIeResource->Size); + + status =3D EFI_SUCCESS; + +Exit: + return status; +} + +EFI_STATUS PCIeParseAssignBar ( + IN UINTN BaseAddress, + IN UINTN MaxBarIndex, + IN BOOLEAN IsBridgeDevice + ) +{ + EFI_STATUS status; + UINTN barIndex, barOffset; + UINT32 allOne32 =3D 0xFFFFFFFF; + + for (barOffset =3D 0x10, barIndex =3D 0; + barOffset <=3D 0x24 && barIndex < MaxBarIndex; + barOffset +=3D sizeof (UINT32), ++barIndex) { + + UINTN originalvalue, responseValue, barSize, resourceAddress; + + status =3D PCIePciRead( + EfiPciWidthUint32, + BaseAddress + barOffset, + 1, + &originalvalue); + ASSERT_EFI_ERROR(status); + + status =3D PCIePciWrite( + EfiPciIoWidthUint32, + BaseAddress + barOffset, + 1, + &allOne32); + ASSERT_EFI_ERROR(status); + + status =3D PCIePciRead( + EfiPciWidthUint32, + BaseAddress + barOffset, + 1, + &responseValue); + ASSERT_EFI_ERROR(status); + + // + // No support for IO memory + // Refer : PCI Local Bus Specification (6.2.5.1) + // + if ((responseValue & 0x01) =3D=3D 0x01) { + status =3D PCIePciWrite( + EfiPciIoWidthUint32, + BaseAddress + barOffset, + 1, + &originalvalue); + ASSERT_EFI_ERROR(status); + continue; + } + + // + // No support for prefetch memory + // + if (((responseValue & 0x01) =3D=3D 0x00) && + ((responseValue & 0x08) =3D=3D 0x08)) { + status =3D PCIePciWrite( + EfiPciIoWidthUint32, + BaseAddress + barOffset, + 1, + &originalvalue); + ASSERT_EFI_ERROR(status); + continue; + } + + barSize =3D (~(responseValue & 0xFFFFFFF0)) + 1; + + status =3D PCIeGetMemoryBarResource( + barSize, + &resourceAddress, + IsBridgeDevice); + if (EFI_ERROR(status)) { + PCIE_ERROR("Failed to acquire BAR resource\n"); + goto Exit; + } + + status =3D PCIePciWrite( + EfiPciIoWidthUint32, + BaseAddress + barOffset, + 1, + &resourceAddress); + ASSERT_EFI_ERROR(status); + + // + // The subsequent BAR is the upper 32 bit address + // + if (((responseValue & 0x04) =3D=3D 0x04) && + (barIndex + 1) < MaxBarIndex) { + + UINT32 allZero =3D 0; + barOffset +=3D sizeof (UINT32); + ++barIndex; + + status =3D PCIePciWrite( + EfiPciIoWidthUint32, + BaseAddress + barOffset, + 1, + &allZero); + ASSERT_EFI_ERROR(status); + + continue; + } + } + + status =3D EFI_SUCCESS; + +Exit: + return status; +} + +EFI_STATUS PCIeConfigureDevice ( + IN PCI_TYPE00 pciDevice, + IN UINTN BusNumber, + IN UINTN DevNumber, + IN UINTN FuncNumber + ) +{ + EFI_STATUS status; + UINTN baseAddress; + + PCIE_INFO( + "Configuring B:%02d D:%02d F:%02d\n", + BusNumber, + DevNumber, + FuncNumber); + + status =3D PCIeGetPCIConfigAddress( + BusNumber, + DevNumber, + FuncNumber, + 0, + &baseAddress); + ASSERT_EFI_ERROR(status); + + // + // Use a fixed cacheline size + // + { + UINT8 fixedCacheLineSize =3D 0x10; + + status =3D PCIePciWrite( + EfiPciIoWidthUint8, + baseAddress + PCI_CACHELINE_SIZE_OFFSET, + 1, + &fixedCacheLineSize); + ASSERT_EFI_ERROR(status); + } + + if (IS_PCI_BRIDGE (&pciDevice)) { + UINT32 allZero =3D 0; + + PCIE_INFO("PCI Bridge\n"); + + // + // PCIe initialization sequence, referenced from + // InitializePpb in MdeModulePkg/Bus/Pci/PciBusDxe + // No support for IO and prefetch memory + // + + status =3D PCIePciWrite( + EfiPciIoWidthUint8, + baseAddress + 0x1C, + 1, + &allZero); + ASSERT_EFI_ERROR(status); + + status =3D PCIePciWrite( + EfiPciIoWidthUint8, + baseAddress + 0x1D, + 1, + &allZero); + + status =3D PCIePciWrite( + EfiPciIoWidthUint16, + baseAddress + 0x24, + 1, + &allZero); + ASSERT_EFI_ERROR(status); + + status =3D PCIePciWrite( + EfiPciIoWidthUint16, + baseAddress + 0x26, + 1, + &allZero); + ASSERT_EFI_ERROR(status); + + status =3D PCIePciWrite( + EfiPciIoWidthUint32, + baseAddress + 0x28, + 1, + &allZero); + ASSERT_EFI_ERROR(status); + + status =3D PCIePciWrite( + EfiPciIoWidthUint32, + baseAddress + 0x2C, + 1, + &allZero); + ASSERT_EFI_ERROR(status); + + status =3D PCIePciWrite( + EfiPciIoWidthUint16, + baseAddress + 0x30, + 1, + &allZero); + ASSERT_EFI_ERROR(status); + + status =3D PCIePciWrite( + EfiPciIoWidthUint16, + baseAddress + 0x32, + 1, + &allZero); + ASSERT_EFI_ERROR(status); + + // + // Type 1 bridge only has 2 BAR register + // + status =3D PCIeParseAssignBar( + baseAddress, + 2, + TRUE); + if (EFI_ERROR(status)) { + PCIE_ERROR("Failed to assign resource to PCI bridge\n"); + goto Exit; + } + + } else { + + // + // Device specific configuration should be implemented here + // + PCIE_INFO("PCI device\n"); + + status =3D PCIeParseAssignBar( + baseAddress, + PCI_MAX_BAR, + FALSE); + if (EFI_ERROR(status)) { + PCIE_ERROR("Failed to assign resource to PCI device\n"); + goto Exit; + } + } + + { + UINT16 pciCommand; + + status =3D PCIePciRead( + EfiPciIoWidthUint16, + baseAddress + PCI_COMMAND_OFFSET, + 1, + &pciCommand); + ASSERT_EFI_ERROR(status); + + pciCommand |=3D + (EFI_PCI_COMMAND_MEMORY_SPACE | EFI_PCI_COMMAND_BUS_MASTER); + + status =3D PCIePciWrite( + EfiPciIoWidthUint16, + baseAddress + PCI_COMMAND_OFFSET, + 1, + &pciCommand); + ASSERT_EFI_ERROR(status); + } + + status =3D EFI_SUCCESS; + +Exit: + return status; +} + +EFI_STATUS PCIeSimpleScanBusAndAssignResource ( + IN UINTN BusNumber + ) +{ + EFI_STATUS status; + UINTN devNumber; + UINTN functionNumber; + PCI_TYPE00 pciDevice; + + for (devNumber =3D 0; devNumber <=3D PCI_MAX_DEVICE; ++devNumber) { + for (functionNumber =3D 0; functionNumber <=3D PCI_MAX_FUNC; ++fun= ctionNumber) { + + PCIE_INFO("Scanning device B: %02d D: %02d F: %02d\n", + BusNumber, + devNumber, + functionNumber); + + status =3D PCIeDevicePresent( + &pciDevice, + BusNumber, + devNumber, + functionNumber); + if (status =3D=3D EFI_NOT_FOUND) { + PCIE_INFO("No PCI device found\n"); + status =3D EFI_SUCCESS; + goto Exit; + } else if (EFI_ERROR(status)) { + PCIE_ERROR("Error detecting PCI device\n"); + goto Exit; + } + + status =3D PCIeConfigureDevice( + pciDevice, + BusNumber, + devNumber, + functionNumber); + if (EFI_ERROR(status)) { + PCIE_ERROR( + "Failed to configure device B:%02d D:%02d F:%02d\n", + BusNumber, + devNumber, + functionNumber); + continue; + } + + if (IS_PCI_BRIDGE (&pciDevice)) { + UINTN busBaseRegisterAddress; + UINTN resourceAddress, bridgeMemory; + UINTN bridgeMemoryBase, bridgeMemoryLimit; + UINT16 busRegister; + UINT8 subBus; + + busRegister =3D (UINT16)(((BusNumber + 1) << 8) | (UINT16)= BusNumber); + status =3D PCIeGetPCIConfigAddress( + BusNumber, + devNumber, + functionNumber, + 0, + &busBaseRegisterAddress); + + ASSERT_EFI_ERROR(status); + + status =3D PCIePciWrite( + EfiPciWidthUint16, + busBaseRegisterAddress + PCI_BRIDGE_PRIMARY_BUS_REGIST= ER_OFFSET, + 1, + &busRegister); + if (EFI_ERROR(status)) { + PCIE_ERROR("Failed to update bridge bus number %d\n", = BusNumber); + continue; + } + + // + // Temporarily set maximum subordinate bus number, althoug= h for now + // only support 2 buses. + // + subBus =3D 0XFF; + status =3D PCIePciWrite( + EfiPciWidthUint8, + busBaseRegisterAddress + PCI_BRIDGE_SUBORDINATE_BUS_RE= GISTER_OFFSET, + 1, + &subBus); + if (EFI_ERROR(status)) { + PCIE_ERROR("Failed to update bridge bus number %d\n", = BusNumber); + continue; + } + + // + // Setup the memory base. + // + status =3D PCIeGetMemoryBarResource( + 0, + &bridgeMemoryBase, + TRUE); + if (EFI_ERROR(status)) { + PCIE_ERROR("Failed to acquire BAR resource\n"); + goto Exit; + } + + bridgeMemory =3D (bridgeMemoryBase >> 16) & 0xFFF0; + + status =3D PCIePciWrite( + EfiPciIoWidthUint32, + busBaseRegisterAddress + 0x20, + 1, + &bridgeMemory); + ASSERT_EFI_ERROR(status); + + status =3D PCIeSimpleScanBusAndAssignResource( + BusNumber + 1); + if (EFI_ERROR(status)) { + PCIE_ERROR("Failed to scan new bus %d\n", BusNumber + = 1); + continue; + } + + // + // Setup the memory limit. + // + status =3D PCIeGetMemoryBarResource( + 0, + &resourceAddress, + TRUE); + if (EFI_ERROR(status)) { + PCIE_ERROR("Failed to acquire BAR resource\n"); + goto Exit; + } + + ASSERT(bridgeMemoryBase !=3D resourceAddress); + + // + // Per spec align address has to be 1MB boundary + // + PCIeGetAlignAddress( + resourceAddress, + 0x00100000, + &bridgeMemoryLimit); + ASSERT_EFI_ERROR(status); + + bridgeMemory |=3D bridgeMemoryLimit; + + status =3D PCIePciWrite( + EfiPciIoWidthUint32, + busBaseRegisterAddress + 0x20, + 1, + &bridgeMemory); + ASSERT_EFI_ERROR(status); + + subBus =3D (BusNumber + 1); + status =3D PCIePciWrite( + EfiPciWidthUint8, + busBaseRegisterAddress + + PCI_BRIDGE_SUBORDINATE_BUS_REGISTER_OFFSET, + 1, + &subBus); + if (EFI_ERROR(status)) { + PCIE_ERROR( + "Failed to update subordinate bus number %d\n", + BusNumber); + continue; + } + + // + // Claim any memory that is used for padding + // + status =3D PCIeGetMemoryBarResource( + (bridgeMemoryLimit + 0x00100000) - resourceAddress, + &resourceAddress, + FALSE); + if (EFI_ERROR(status)) { + PCIE_ERROR("Failed to realign resource\n"); + goto Exit; + } + } + + // + // Skip sub functions, this is not a multi function device + // + if (functionNumber =3D=3D 0 && !IS_PCI_MULTI_FUNC (&pciDevice)= ) { + + functionNumber =3D PCI_MAX_FUNC; + } + } + } + +Exit: + return status; +} + +EFI_STATUS PCIeInitialize ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE* SystemTablePtr + ) +{ + EFI_STATUS status; + + status =3D PCIeSetupInitSetting(); + if (EFI_ERROR(status)) { + + // + // EFI_DEVICE_ERROR indicate that a bootloader has already setup t= he + // PCIe controller. In this case just return success immediately + // + if (status =3D=3D EFI_DEVICE_ERROR) { + status =3D EFI_SUCCESS; + PCIE_WARNING("PCIe already initialized\n"); + goto Exit; + } + + PCIE_ERROR("Failed to enable PCIe gates\n"); + goto Exit; + } + + status =3D PCIeSetClockGate(IMX_CLOCK_GATE_STATE_ON); + if (EFI_ERROR(status)) { + PCIE_ERROR("Failed to enable PCIe gates\n"); + goto Exit; + } + + status =3D PCIeVerifyClocks(); + if (EFI_ERROR(status)) { + PCIE_ERROR("Failed to verify PCIe clocks, not configured!\n"); + goto Exit; + } + + status =3D PCIeSetPhyState(TRUE); + if (EFI_ERROR(status)) { + PCIE_ERROR("Failed to enable PCIe PHY\n"); + goto Exit; + } + + // + // Very important to wait for PCIe PHY to settle here or the controlle= r + // behaviour becomes unpredictable. + // + gBS->Stall(50000); + + PCIeEnablePerstLine(); + + status =3D PCIeSetupPCIBridge(); + if (EFI_ERROR(status)) { + PCIE_ERROR("Failed to setup PCI bridge\n"); + goto Exit; + } + + status =3D PCIeSetLinkStatus(TRUE); + if (EFI_ERROR(status)) { + PCIE_ERROR("Failed to enable PCIe link\n"); + goto Exit; + } + + status =3D PCIeWaitForLink(); + if (EFI_ERROR(status)) { + PCIE_ERROR("PCI link never came up\n"); + goto Exit; + } + + PCIeSetupiATUSettings(); + + // + // Start scanning from bus 0 onward + // + status =3D PCIeSimpleScanBusAndAssignResource(0); + if (EFI_ERROR(status)) { + PCIE_ERROR("PCIeSimpleScanBusAndAssignResource failed %r\n", statu= s); + goto Exit; + } + +#ifdef DEBUG + { + UINT32 printIndex =3D 0; + volatile UINT32* printAddr =3D (UINT32*)PCIE_HOST_CONFIG_BASE_REG; + + PCIE_INFO("=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D\n"); + PCIE_INFO("Host Device Configuration space\n"); + PCIE_INFO("=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D\n"); + for (; printIndex < 16; ++printIndex) { + PCIE_INFO("PCI [%02x] 0x%08x 0x%08x 0x%08x 0x%08x\n", \ + printIndex * 16, \ + printAddr[0], \ + printAddr[1], \ + printAddr[2], \ + printAddr[3]); + + printAddr +=3D 4; + } + + PCIE_INFO("=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D\n"); + PCIE_INFO("Device Configuration space 0x%08x\n", printAddr); + PCIE_INFO("=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D\n"); + for (printIndex =3D 0; printIndex < 16; ++printIndex) { + PCIE_INFO("PCI [%02x] 0x%08x 0x%08x 0x%08x 0x%08x\n", \ + printIndex * 16, \ + printAddr[0], \ + printAddr[1], \ + printAddr[2], \ + printAddr[3]); + + printAddr +=3D 4; + } + PCIE_INFO("=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D\n"); + } +#endif + +Exit: + + if (EFI_ERROR(status)) { + PCIE_ERROR("Failed to initialize PCIe, disabling controller\n"); + PCIeSetLinkStatus(FALSE); + PCIeSetPhyState(FALSE); + PCIeSetClockGate(IMX_CLOCK_GATE_STATE_OFF); + } + + // + // For debug printout the state of the PLL/PHY + // +#ifdef DEBUG + { + volatile IMX_CCM_ANALOG_REGISTERS* ccmAnalogRegsPtr =3D (IMX_CCM_ANALO= G_REGISTERS*)IMX_CCM_ANALOG_BASE; + volatile IMX_IOMUXC_GPR_REGISTERS* ioMuxcRegsPtr =3D (IMX_IOMUXC_GPR_R= EGISTERS*)IMX_IOMUXC_BASE; + + PCIE_INFO( "IMX_CCM_PLL_ENET 0x%08X\n", MmioRead32((UINTN) &ccmAnalogR= egsPtr->PLL_ENET)); + PCIE_INFO( "IOMUXC_GPR1 0x%08X\n", MmioRead32((UINTN) &ioMuxcRegsPtr->= GPR1)); + } +#endif + return status; +} diff --git a/Silicon/NXP/iMX6Pkg/Drivers/PciExpress/iMX6PciExpress.h b/Sili= con/NXP/iMX6Pkg/Drivers/PciExpress/iMX6PciExpress.h new file mode 100644 index 000000000000..fa7d275b4fbd --- /dev/null +++ b/Silicon/NXP/iMX6Pkg/Drivers/PciExpress/iMX6PciExpress.h @@ -0,0 +1,163 @@ +/** @file +* +* Copyright (c) Microsoft Corporation. All rights reserved. +* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of the B= SD License +* which accompanies this distribution. The full text of the license may = be found at +* http://opensource.org/licenses/bsd-license.php +* +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IM= PLIED. +* +**/ + +#pragma once + +#ifndef ARRAYSIZE +#define ARRAYSIZE(__array__) (sizeof((__array__))/sizeof((__array__[0]))) +#endif + +// +// Print macro +// +#define PCIE_INIT(PRINT_OUT, ...) \ + DEBUG((DEBUG_INIT, "iMX6PCIe:" PRINT_OUT, ##__VA_ARGS__)) +#define PCIE_INFO(PRINT_OUT, ...) \ + DEBUG((DEBUG_INFO, "iMX6PCIe:" PRINT_OUT, ##__VA_ARGS__)) +#define PCIE_WARNING(PRINT_OUT, ...) \ + DEBUG((DEBUG_WARN, "iMX6PCIe:" PRINT_OUT, ##__VA_ARGS__)) +#define PCIE_ERROR(PRINT_OUT, ...) \ + DEBUG((DEBUG_ERROR, "iMX6PCIe:" PRINT_OUT, ##__VA_ARGS__)) + +// +// PCIe related base address +// +#define PCIE_HOST_CONFIG_BASE_REG FixedPcdGet32(PcdPcieHostConfigBas= e) +#define PCIE_CTRL_PORT_LOGIG_BASE_REG 0x01FFC700 +#define PCIE_DEVICE_CONFIG_BASE_REG FixedPcdGet32(PcdPcieDeviceConfigB= ase) +#define PCIE_DEVICE_CONFIG_SIZE FixedPcdGet32(PcdPcieDeviceConfigS= ize) +#define PCIE_IO_SPACE_BASE FixedPcdGet32(PcdPcieIOBase) +#define PCIE_IO_SPACE_SIZE FixedPcdGet32(PcdPcieIOSize) +#define PCIE_MEMORY_SPACE_BASE FixedPcdGet32(PcdPciMemoryBase) +#define PCIE_MEMORY_SPACE_SIZE FixedPcdGet32(PcdPciMemorySize) +#define PCIE_PREFETCH_MEMORY_SPACE_BASE FixedPcdGet32(PcdPciPrefetchMemory= Base) +#define PCIE_PREFETCH_MEMORY_SPACE_SIZE FixedPcdGet32(PcdPciPrefetchMemory= Size) + +#pragma pack(push, 1) + +typedef union { + UINT8 volatile *buf; + UINT8 volatile *ui8; + UINT16 volatile *ui16; + UINT32 volatile *ui32; + UINT64 volatile *ui64; + UINTN volatile ui; +} PTR; + +typedef struct { + UINT64 Base; + UINT64 Size; + UINT64 Curr; +} PCI_RESOURCE; + +// +// Debug register related bits +// +#define PCIE_PL_DEBUG1_PHY_LINK_UP (1 << 4) +#define PCIE_PL_DEBUG1_LINK_IN_TRAINING (1 << 29) + +// +// Address Translation Unit related definition +// + +#define MAX_iATU_REGION 4 + +typedef enum _REGION_DIRECTION { + OUTBOUND, + INBOUND, +} REGION_DIRECTION; + +typedef enum _TLP_TYPE { + MEMORY_TYPE, + MEMORY_LOCK_TYPE, + IO_TYPE, + CFG0_TYPE =3D 4, + CFG1_TYPE =3D 5, +} TLP_TYPE; + +typedef enum _REGION_STATE { + REGION_DISABLE =3D 0, + REGION_ENABLE =3D 0x80000000, +} REGION_STATE; + +typedef struct { + + UINT32 PCIE_PL_ALTRTR; // ACK latency timer and replay timer + UINT32 PCIE_PL_VSDR; // Vendor specific DLLP + UINT32 PCIE_PL_PFLR; // Port force link + UINT32 PCIE_PL_AFLACR; // ACK frequency and L0-L1 ASPM contro= l + UINT32 PCIE_PL_PLCR; // Port link control + UINT32 PCIE_PL_LSR; // Lane skew + UINT32 PCIE_PL_SNR; // Symbol number + UINT32 PCIE_PL_STRFM1; // Symbol timer and filter mask 1 + UINT32 PCIE_PL_STRFM2; // Filter mask 2 + UINT32 PCIE_PL_AMODNPSR; // AMBA Multiple Outbound Decomposed N= P Sub-Requests Control + UINT32 PCIE_PL_DEBUG0; // Debug 0 + UINT32 PCIE_PL_DEBUG1; // Debug 1 + UINT32 PCIE_PL_TPFCSR; // Transmit Posted FC Credit Status + UINT32 PCIE_PL_TNFCSR; // Transmit Non-Posted FC Credit Statu= s + UINT32 PCIE_PL_TCFCSR; // Transmit Completion FC Credit Statu= s + UINT32 PCIE_PL_QSR; // Queue status + UINT32 PCIE_PL_VCTAR1; // Transmit Completion FC Status 1 + UINT32 PCIE_PL_VCTAR2; // Transmit Completion FC Status 1 + UINT32 PCIE_PL_VC0PRQC; // VC0 Posted Receive Queue Control + UINT32 PCIE_PL_VC0NRQC; // VC0 Non-Posted Receive Queue Contro= l + UINT32 PCIE_PL_VC0CRQC; // VC0 Completion Receive Queue Contro= l + UINT32 PCIE_PL_VCnPRQC; // VCn Posted Receive Queue Control + UINT32 PCIE_PL_VCnNRQC; // VCn Non-Posted Receive Queue Contro= l + UINT32 PCIE_PL_VCnCRQC; // VCn Completion Receive Queue Contro= l + UINT32 PCIE_PL_RESERVED_0[18]; + UINT32 PCIE_PL_VC0PBD; // VC0 Posted Buffer Depth + UINT32 PCIE_PL_VC0NPBD; // VC0 Non-Posted Buffer Depth + UINT32 PCIE_PL_VC0CBD; // VC0 Completion Buffer Depth + UINT32 PCIE_PL_VC1PBD; // VCn Posted Buffer Depth + UINT32 PCIE_PL_VC1NPBD; // VCn Non-Posted Buffer Depth + UINT32 PCIE_PL_VC1CBD; // VCn Completion Buffer Depth + UINT32 PCIE_PL_RESERVED_1[19]; + UINT32 PCIE_PL_G2CR; // Gen2 Control + UINT32 PCIE_PL_PHY_STATUS; // PHY status + UINT32 PCIE_PL_PHY_CTRL; // PHY control + UINT32 PCIE_PL_MRCCR0; // Master Response Composer Control 0 + UINT32 PCIE_PL_MRCCR1; // Master Response Composer Control 1 + UINT32 PCIE_PL_MSICA; // MSI Controller Address + UINT32 PCIE_PL_MSICUA; // MSI Controller Upper Address + UINT32 PCIE_PL_MSICIn_ENB; // MSI Controller Interrupt n Enable + UINT32 PCIE_PL_MSICIn_MASK; // MSI Controller Interrupt n Mask + UINT32 PCIE_PL_MSICIn_STATUS; // MSI Controller Interrupt n Status + UINT32 PCIE_PL_RESERVED_2[21]; + UINT32 PCIE_PL_MSICGPIO; // MSI Controller General Purpose IO + UINT32 PCIE_PL_RESERVED_3[29]; + UINT32 PCIE_PL_iATUVR; // iATU Viewport + UINT32 PCIE_PL_iATURC1; // iATU Control 1 + UINT32 PCIE_PL_iATURC2; // iATU Control 2 + UINT32 PCIE_PL_iATURLBA; // iATU Region Lower Base Address + UINT32 PCIE_PL_iATURUBA; // iATU Region Upper Base Address + UINT32 PCIE_PL_iATURLA; // iATU Region Limit Address + UINT32 PCIE_PL_iATURLTA; // iATU Region Lower Target Address + UINT32 PCIE_PL_iATURUTA; // iATU Region Upper Target Address +} CSP_PCIE_PL_REGS, *PCSP_PCIE_PL_REGS; + +typedef struct _IATU_SETTINGS { + UINT32 RegionDirection; + UINT32 RegionIndex; + TLP_TYPE Type; + UINT32 LowerBaseAddr; + UINT32 UpperBaseAddr; + UINT32 LimitAddr; + UINT32 LowerTargetAddr; + UINT32 UpperTargetAddr; + UINT32 State; +} IATU_SETTINGS, *PIATU_SETTINGS; + +#pragma pack(pop) diff --git a/Silicon/NXP/iMX6Pkg/Drivers/PciExpress/iMX6PciExpress.inf b/Si= licon/NXP/iMX6Pkg/Drivers/PciExpress/iMX6PciExpress.inf new file mode 100644 index 000000000000..e41c71b939cc --- /dev/null +++ b/Silicon/NXP/iMX6Pkg/Drivers/PciExpress/iMX6PciExpress.inf @@ -0,0 +1,66 @@ +## @file +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the B= SD License +# which accompanies this distribution. The full text of the license may = be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IM= PLIED. +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D iMX6PciExpress + FILE_GUID =3D 5A7FB871-8A19-48D5-A268-441E79AAFD9E + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D PCIeInitialize + +[Sources.common] + iMX6PciExpress.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + IntelFrameworkPkg/IntelFrameworkPkg.dec + ArmPkg/ArmPkg.dec + EmbeddedPkg/EmbeddedPkg.dec + Silicon/NXP/iMXPlatformPkg/iMXPlatformPkg.dec + Silicon/NXP/iMX6Pkg/iMX6Pkg.dec + +[LibraryClasses] + BaseLib + DxeServicesTableLib + UefiLib + UefiBootServicesTableLib + UefiDriverEntryPoint + UefiRuntimeServicesTableLib + IoLib + iMX6ClkPwrLib + +[Protocols] + +[Pcd] + giMX6TokenSpaceGuid.PcdPcieHostConfigBase + giMX6TokenSpaceGuid.PcdPcieDeviceConfigBase + giMX6TokenSpaceGuid.PcdPcieDeviceConfigSize + giMX6TokenSpaceGuid.PcdPcieIOBase + giMX6TokenSpaceGuid.PcdPcieIOSize + giMX6TokenSpaceGuid.PcdPciMemoryBase + giMX6TokenSpaceGuid.PcdPciMemorySize + giMX6TokenSpaceGuid.PcdPciPrefetchMemoryBase + giMX6TokenSpaceGuid.PcdPciPrefetchMemorySize + giMX6TokenSpaceGuid.PcdPcieResetGpio + giMX6TokenSpaceGuid.PcdPcieResetGpioBankNumber + giMX6TokenSpaceGuid.PcdPcieResetGpioIoNumber + +[FixedPcd] + giMXPlatformTokenSpaceGuid.PcdGpioBankMemoryRange + +[Depex] + gEfiMetronomeArchProtocolGuid AND + gEfiCpuArchProtocolGuid --=20 2.16.2.gvfs.1.33.gf5370f1