From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mx.groups.io with SMTP id smtpd.web12.15402.1624904514278907785 for ; Mon, 28 Jun 2021 11:21:54 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=vCMrflvN; spf=pass (domain: intel.com, ip: 134.134.136.100, mailfrom: damian.bassa@intel.com) X-IronPort-AV: E=McAfee;i="6200,9189,10029"; a="271866912" X-IronPort-AV: E=Sophos;i="5.83,306,1616482800"; d="scan'208";a="271866912" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jun 2021 11:21:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,306,1616482800"; d="scan'208";a="488983734" Received: from orsmsx602.amr.corp.intel.com ([10.22.229.15]) by orsmga001.jf.intel.com with ESMTP; 28 Jun 2021 11:21:50 -0700 Received: from orsmsx609.amr.corp.intel.com (10.22.229.22) by ORSMSX602.amr.corp.intel.com (10.22.229.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.4; Mon, 28 Jun 2021 11:21:49 -0700 Received: from orsmsx604.amr.corp.intel.com (10.22.229.17) by ORSMSX609.amr.corp.intel.com (10.22.229.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.4; Mon, 28 Jun 2021 11:21:49 -0700 Received: from ORSEDG602.ED.cps.intel.com (10.7.248.7) by orsmsx604.amr.corp.intel.com (10.22.229.17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.4 via Frontend Transport; Mon, 28 Jun 2021 11:21:49 -0700 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (104.47.55.101) by edgegateway.intel.com (134.134.137.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2242.4; Mon, 28 Jun 2021 11:21:49 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QVoCV0wfouM3D7+GMGtOCzabAGxgJKcpRKMyDUddYeHDZBwDuDiDdx6PTVnD721qg5aR29OV6eMzV5fa+tqfbwWjOrBOH2ePTF51ntJHZR1J3rMCMJiPFJqQHlcL7vWSZ8JXmweHUEkJYeC3y1u5yVzHKkTPJIJTQp3p7bJEhrNmqnzqvlYdi+hiQAWjLphNKjNfJVRSm+G3odfBq/DWvpr7CLrXPpBFGgSWgfCQmEPzvDvfL7FjGfa3czt4V6NnUdAp3f9ExzQunAmzocvaN4/ytCeLsGwz2Va2rPng7hVzKnFU7CiHjUQgQhLpkDedgtEGlt5KbMugT3pg3eMQdg== 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=KjucTOiVLFFCiYQdu0667sanYkRGfQe70Te5KuRvu4o=; b=Ieq/RpzZagpFGtZ/DUs698wjsGeidmrZl5YhFY9CWFvLJIKCZwvnIQxcNq5imApSXmP4Ovd5XSgHpbNtaQ+pzWooq/oSVbQKelHPCxko35oudrZTgOUC85X2np6/ofEwNRcgl7cHkuk5i1CKVcnkGg58seQCWMgs07W4sAEcABrGrm4YdT78Ja289xaIBsh2rcqUnXT6FvIXbh1Dt9F7y3XWJCzG/eTmpDOBqqCcZwrkh3WROxh8N9ih7kcBW6O7yUx+BXUziPCZ0b9yM0na13xK+zJc6pXMTYpzr9SKPF2Bh4opykO7Ws5IcpU1v48RoCRGqFpPMSBLsVr3CA699w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KjucTOiVLFFCiYQdu0667sanYkRGfQe70Te5KuRvu4o=; b=vCMrflvNUu9+aLq8Wsxzp8wVEe3bT13XJrE5/PaScj9CFgnwIDua8y8yX29mDTWbwj+2lNUw0UIvnzQEKCrrDkp6hdZsh3PeiYuSLWQE6v1LVXUHGQqrjrN+Mu8KjgB3RDYdpxE5dhXVmIeSFY7DbvuSGPFbOEk+swT04fP6QJU= Received: from CO1PR11MB5187.namprd11.prod.outlook.com (2603:10b6:303:95::15) by MW3PR11MB4522.namprd11.prod.outlook.com (2603:10b6:303:2d::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4264.18; Mon, 28 Jun 2021 18:21:48 +0000 Received: from CO1PR11MB5187.namprd11.prod.outlook.com ([fe80::745a:9e48:6593:f580]) by CO1PR11MB5187.namprd11.prod.outlook.com ([fe80::745a:9e48:6593:f580%3]) with mapi id 15.20.4264.026; Mon, 28 Jun 2021 18:21:48 +0000 From: "Bassa, Damian" To: "devel@edk2.groups.io" CC: "Rusocki, Krzysztof" Subject: [PATCH] MdeModulePkg/RamDiskDxe: RamDisk driver to assign non-zero SPA range index Thread-Topic: [PATCH] MdeModulePkg/RamDiskDxe: RamDisk driver to assign non-zero SPA range index Thread-Index: AddsONUgby5jzvH7RlyOzRrwimnSFA== Date: Mon, 28 Jun 2021 18:21:48 +0000 Message-ID: Accept-Language: pl-PL, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-reaction: no-action dlp-version: 11.5.1.3 authentication-results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=intel.com; x-originating-ip: [109.197.66.180] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: b9b49b68-c90e-4f07-ccfc-08d93a6197e4 x-ms-traffictypediagnostic: MW3PR11MB4522: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:7691; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: uVcwJUIo6UbYH8IkPzxamXz05HNfTb0B36KgiAqkWejcvRulw60xJ0GZzgTmHnPLeCg8KH8cq81yNIXZQkyJBox/Ytp3yH2ET5wGMAizTodQrosNjdd/loXRsCHYaxAXnSE+F1gYB7ug2BvO6ZQ1R8P4wc+PsRheHtg6L2SnxenpXGgTF24OtYsm2xuxFYvaqs2ZhqcGp50vhDpTaRFIsmse5rXHLKO0p9FTlDGRTCDo1EBH3oxsWBfb3uF+GHo5g9bCK7JjnXv5T97jG19eKwqFG/B5XrSo9qLi7pobtr20+AAqE4Hreg2W28HUrZqGG1FSCwegJK3lLDvS1tovo5SKb/kdc+AujHLeaLaK35Qfu74pICgSpVc29tQuTXcVGUWZkr/bvuyEMlNWn4tnnRt+jmVrIoHu0LKAT3qHi4GAX6LHrF8Env6rObdrSOuSABdxTwMSxUnEdeYszniRStNEUrnaCbz303YXlBNsB0WE92qJssxZG0eX7qoaoFkqTYFDd1MpOw5NS4SyDoMJCIYOmM1qHdapILsZfP+mMVGFmneI4NQNnTpFVr6k37Wq5M+UcxpllN7H4P1nLtueX9Hhh+xxLOBAm7pUbJRWDdX17JxXlyN3+gYo2lcu1X98puvOZToTINNKo3sMAN+FBLpfBIw7kn0LhjkANMPfvkk9avNjt8fKy5/LM4UQSKRv1MTfL579KHh+0uKa7d+OZg== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CO1PR11MB5187.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(396003)(366004)(346002)(376002)(39860400002)(136003)(71200400001)(4326008)(186003)(33656002)(55016002)(38100700002)(7696005)(122000001)(9686003)(6916009)(316002)(26005)(8936002)(8676002)(6506007)(66946007)(2906002)(86362001)(52536014)(64756008)(66556008)(66476007)(5660300002)(107886003)(76116006)(66446008)(478600001)(44824005);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?bdqYsnYwM/ndfI0gA+/S7ehp08+JQrsp1yInckwn6Me3FOzuwu2ITYPfzPb2?= =?us-ascii?Q?uNpehQL9SJKe4NeGl/EENtsixBADQ/cTbzMFo3zzmBhQxSR4vHWWxYOe1M+V?= =?us-ascii?Q?jPpMK5vNyaxC9atacJEDbhwUTEn+Odne6G6LNNBtKEGoXigo5dIWGccxVbJL?= =?us-ascii?Q?/obIAq3hN6ZCCa8tCU2brhBAeX4386GtM/W5kESdzYHeOrXrpunY83MG0nhb?= =?us-ascii?Q?aRU7uUTenJW/qCzzy8SjyyiN4Cp1oLhJOtG54RE4XG8zVNAwS40CDux2h9/e?= =?us-ascii?Q?N4adr0EBPKVZoIMgBvdLukLLIJZweAG+NEHJz5m1vQbOGMdeZb6gsy3bjOvJ?= =?us-ascii?Q?84/SM6Ll97oKMD0IFWBK/QuJApeH6eyLfIQJOl2ZMQYw2feUvVGY/0uWsMCr?= =?us-ascii?Q?pBGkIuRna2a+xOXD76A1mM1WBWUeCrg65e3IbPfL6dQhM22Sx6WB5AcfzrHW?= =?us-ascii?Q?o7vqy2jSD4xPj6RrZvH3OdNuY6si2BkQJLfvy5DTyHI0Hslps0HtKDJsK6G7?= =?us-ascii?Q?5+58smfHhyeJMJygP/K0jQ1Npqbyb+h2IZAc6/28DqylJkKPp1eIomlnFieN?= =?us-ascii?Q?k1MWSLfhuNJ8gF5snQee5gQLuc81t/bUc5KWCtap8mGgNZuCwS2F/Ks30HdZ?= =?us-ascii?Q?CtQgrdf4PKUfwNpAxDkIwrEYrskao7PJuJCuNaoNFWJRMItgpO3mm5RVqYMi?= =?us-ascii?Q?/WlV0sy433XJuHON6QALETBCZxFRp/MBAMs+MrUWVS2yT3u2QtLg8h+bbUpu?= =?us-ascii?Q?6rlhDBsH0KsOj+FgjNrngXihEHEtAl2hUAC0J7ptkovyf+BMdnIRFXAMq2VO?= =?us-ascii?Q?rVLSPBoo05IsG0Qgl8sa+7Bilgqmbq4OYG0pHRdS/k63SXt9a2tQlW4RN+SQ?= =?us-ascii?Q?VTsUJB1eciFf2PGBlxUkfC0lDPh6bNE4dtG1edPCXozMzZk79y/eGVq9iBlg?= =?us-ascii?Q?7TwkLd0egCJC5mQfYdlKl/AOkunDBfunAHprJHAKDjfagN5lzbN4ep6kfIVt?= =?us-ascii?Q?PmU9V2LIGwphsvV+zqkkqSzwAsHXFM8m4c5hG/rmeIhvM650q0bir0KxOSD9?= =?us-ascii?Q?vemwbjiaW3fdhVIyHlm4r21atIow+txL55NH2T9qwf9V8JGjaAA7HUEpXnlJ?= =?us-ascii?Q?xyT15P99WdXycTSuev39AjlSCmgqExcN/waNM8td6pnmNss5FAQtY0kjPK+x?= =?us-ascii?Q?20qFcStccpCT//13T2zM4cr0GPZdts69w/5weYju8BSTW2ggj7gq3z4D/Yc9?= =?us-ascii?Q?6h7ywIFNUhyR80Sr318hfpyi9ElJUUwVxyk4GVCX1jipUcuGcA96vTQrN5q/?= =?us-ascii?Q?798SkJ0Nrxr/lmS0mwMQYo/B?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: CO1PR11MB5187.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: b9b49b68-c90e-4f07-ccfc-08d93a6197e4 X-MS-Exchange-CrossTenant-originalarrivaltime: 28 Jun 2021 18:21:48.2526 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: A9xjyKxNhEVTF8UyruLrlnA3YMmXciX7Bo9SwzbhQV9NqYvi26bkQ9YhMyP+w9reCemZvCiqB7iHk5d3oABJ5A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW3PR11MB4522 Return-Path: damian.bassa@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Driver should not use default zero value to assign SPA range since it is invalid value according to ACPI spec. After the change driver will look for highest index existing in the table. If maximum number is already taken it will look for holes in table. Signed-off-by: Damian Bassa --- .../Disk/RamDiskDxe/RamDiskProtocol.c | 131 ++++++++++++++++++ 1 file changed, 131 insertions(+) diff --git a/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskProtocol.c b/Mde= ModulePkg/Universal/Disk/RamDiskDxe/RamDiskProtocol.c index 4333e00053..b47e3af929 100644 --- a/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskProtocol.c +++ b/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskProtocol.c @@ -116,6 +116,136 @@ RamDiskPublishSsdt ( return Status; } = +/** + Finds highest Spa Range Index in Nfit table. + + @param[in] TableHeader Points to Nfit table. + + @retval Index Highest Spa range index + @retval 0 Free index not found +**/ +UINT16 +GetHighestSpaRangeIndex ( + VOID *TableHeader + ) +{ + INT32 Length; + UINT16 HighestIndex; + + HighestIndex =3D 0; + + EFI_ACPI_6_1_NFIT_STRUCTURE_HEADER *NfitStructHea= der; + EFI_ACPI_6_1_NFIT_SYSTEM_PHYSICAL_ADDRESS_RANGE_STRUCTURE *SpaRange; + + Length =3D ((EFI_ACPI_DESCRIPTION_HEADER *)TableHeader)->Length - sizeof= (EFI_ACPI_6_1_NVDIMM_FIRMWARE_INTERFACE_TABLE); + NfitStructHeader =3D (EFI_ACPI_6_1_NFIT_STRUCTURE_HEADER *) + ((UINT8 *)TableHeader + sizeof (EFI_ACPI_6_1_NVDIMM_F= IRMWARE_INTERFACE_TABLE)); + + while (Length > sizeof(EFI_ACPI_6_1_NFIT_STRUCTURE_HEADER)) { + if (NfitStructHeader->Length < sizeof(EFI_ACPI_6_1_NFIT_STRUCTURE_HEAD= ER)) { + break; + } + if ((NfitStructHeader->Type =3D=3D EFI_ACPI_6_1_NFIT_SYSTEM_PHYSICAL_A= DDRESS_RANGE_STRUCTURE_TYPE) && + (NfitStructHeader->Length >=3D sizeof (EFI_ACPI_6_1_NFIT_SYSTEM_PH= YSICAL_ADDRESS_RANGE_STRUCTURE))) { + SpaRange =3D (EFI_ACPI_6_1_NFIT_SYSTEM_PHYSICAL_ADDRESS_RANGE_STR= UCTURE *)NfitStructHeader; + if (SpaRange->SPARangeStructureIndex > HighestIndex) { + HighestIndex =3D SpaRange->SPARangeStructureIndex; + } + } + + // + // Move to the header of next NFIT structure. + // + Length -=3D NfitStructHeader->Length; + NfitStructHeader =3D (EFI_ACPI_6_1_NFIT_STRUCTURE_HEADER *) + ((UINT8 *)NfitStructHeader + NfitStructHeader->Leng= th); + } + return HighestIndex; +} + +/** + Finds if Spa range index exists in Nfit table. + + @param[in] SpaRangeIndex Number of index to look for. + @param[in] TableHeader Points to Nfit table. + + @retval TRUE Index number already exists in the tab= le + @retval FALSE Index number doesn't exist in the table +**/ +BOOLEAN +DoesSpaIndexExist ( + UINT16 SpaRangeIndex, + VOID *TableHeader + ) +{ + INT32 Length; + EFI_ACPI_6_1_NFIT_STRUCTURE_HEADER *NfitStructHea= der; + EFI_ACPI_6_1_NFIT_SYSTEM_PHYSICAL_ADDRESS_RANGE_STRUCTURE *SpaRange; + + Length =3D ((EFI_ACPI_DESCRIPTION_HEADER *)TableHeader)->Length - + siz= eof (EFI_ACPI_6_1_NVDIMM_FIRMWARE_INTERFACE_TABLE); + NfitStructHeader =3D (EFI_ACPI_6_1_NFIT_STRUCTURE_HEADER *) + ((UINT8 *)TableHeader + sizeof (EFI_ACPI_6_1_NVDIMM_F= IRMWARE_INTERFACE_TABLE)); + + while (Length > sizeof(EFI_ACPI_6_1_NFIT_STRUCTURE_HEADER)) { + if (NfitStructHeader->Length < sizeof(EFI_ACPI_6_1_NFIT_STRUCTURE_HEAD= ER)) { + break; + } + if ((NfitStructHeader->Type =3D=3D EFI_ACPI_6_1_NFIT_SYSTEM_PHYSICAL_A= DDRESS_RANGE_STRUCTURE_TYPE) && + (NfitStructHeader->Length >=3D sizeof (EFI_ACPI_6_1_NFIT_SYSTEM_PH= YSICAL_ADDRESS_RANGE_STRUCTURE))) { + SpaRange =3D (EFI_ACPI_6_1_NFIT_SYSTEM_PHYSICAL_ADDRESS_RANGE_STR= UCTURE *)NfitStructHeader; + if (SpaRange->SPARangeStructureIndex =3D=3D SpaRangeIndex) { + return TRUE; + } + } + + // + // Move to the header of next NFIT structure. + // + Length -=3D NfitStructHeader->Length; + NfitStructHeader =3D (EFI_ACPI_6_1_NFIT_STRUCTURE_HEADER *) + ((UINT8 *)NfitStructHeader + NfitStructHeader->Leng= th); + } + return FALSE; +} + +/** + Finds lowest available Spa range index in Nfit table. + + @param[in] TableHeader Points to Nfit table. + + @retval Index Lowest free Spa range index + @retval 0 Free index not found +**/ +UINT16 +GetFreeSpaIndex ( + VOID *TableHeader + ) +{ + UINT16 Index; + + Index =3D GetHighestSpaRangeIndex (TableHeader); + + // + // If highest range found is not maximum allowed number use value increa= sed by 1 + // + if (Index !=3D MAX_UINT16) { + return Index + 1; + } + // + // If highest possible index value is already used, see if there is any = that is not taken + // + for (Index =3D 1; Index < MAX_UINT16; Index++) + { + if (!DoesSpaIndexExist(Index, TableHeader)) { + return Index; + } + } + DEBUG (( + EFI_D_ERROR, + "GetFreeSpaIndex: Nfit index not found, table is full\n" + )); + return 0; +} = /** Publish the RAM disk NVDIMM Firmware Interface Table (NFIT) to the ACPI @@ -334,6 +464,7 @@ RamDiskPublishNfit ( SpaRange->Length =3D sizeof (EFI_ACPI_6_1_NFIT_SYSTEM_PHYSICAL_ADDRESS_R= ANGE_STRUCTURE); SpaRange->SystemPhysicalAddressRangeBase =3D PrivateData->StartingAddr; SpaRange->SystemPhysicalAddressRangeLength =3D PrivateData->Size; + SpaRange->SPARangeStructureIndex =3D GetFreeSpaIndex (Nfit); CopyGuid (&SpaRange->AddressRangeTypeGUID, &PrivateData->TypeGuid); = Checksum =3D CalculateCheckSum8((UINT8 *)Nfit, NfitHeader->L= ength); -- = 2.27.0.windows.1 Intel Technology Poland sp. z o.o. ul. Sowackiego 173 | 80-298 Gdask | Sd Rejonowy Gdask Pnoc | VII Wydzia Gos= podarczy Krajowego Rejestru Sdowego - KRS 101882 | NIP 957-07-52-316 | Kapi= ta zakadowy 200.000 PLN. Ta wiadomo wraz z zacznikami jest przeznaczona dla okrelonego adresata i mo= e zawiera informacje poufne. W razie przypadkowego otrzymania tej wiadomoci= , prosimy o powiadomienie nadawcy oraz trwae jej usunicie; jakiekolwiek prz= egldanie lub rozpowszechnianie jest zabronione. This e-mail and any attachments may contain confidential material for the s= ole use of the intended recipient(s). If you are not the intended recipient= , please contact the sender and delete all copies; any review or distributi= on by others is strictly prohibited.