From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) by mx.groups.io with SMTP id smtpd.web11.1478.1641521745639113798 for ; Thu, 06 Jan 2022 18:15:45 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20210112 header.b=HGxmvE9C; spf=pass (domain: gmail.com, ip: 209.85.215.178, mailfrom: kuqin12@gmail.com) Received: by mail-pg1-f178.google.com with SMTP id y9so4161979pgr.11 for ; Thu, 06 Jan 2022 18:15:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pMb3ffAvsSGb1r7nckC4p5rI/LAHOLkV0yZ8S01bMzA=; b=HGxmvE9CrhXzmmv0AVJzhjAa3FYu9SiVG6EdZrPepE7ABJqhYrt0pfv330aPzuJd1D 97QwGOjcvG8wbyOYKLJkAX51uGvkfw5aenlikYvzx4KYg+nQ4QIRAkD8uO+QsgXamNrm XzeYRIZfprHYjU96tkaWTHKElnx0eIQpetC2FLZCkU5wB/FBKeQUhx+JnkfuQM/GCmhC E0n2xuv+nDtfMZZIzl4ZuC+xJQVJzhQNpL4aseSAkmG0CjKUkrvWVLcFw2wprlOOQdAI 1BZQ3mvKW1sOOoGBgmM4FybUQvxAutWLFtT3mYqnMguLRp39/PvhqNo+DYnC4Z5uRn20 kjSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pMb3ffAvsSGb1r7nckC4p5rI/LAHOLkV0yZ8S01bMzA=; b=pIafCzF8fGDTCJjrLpZHDurQfO1jylGCXzrmvHV+8p/0/lb5WbuvyzTd8qrZL7XvmC r/0KfTdaLKFpa+EbLVDiTDIw8hEape2uIiFx1v6mG/MuV4oSR0plm8c1XcVxA1mAatu/ yBM5t8FBILdi8AIKZnr+DMolj5U3cYMfnXaRepjUFWH4Qcy5kJF6uJFZR76LaDBxwX1i mne1+oeZVYC7+mwy26770DGex6qfpthnB46GNZGKapCpFBpWFZbaI4KJ40KwwXIEIV/f THzwGQKoC/w7XEEdyXKvKbppohWjnjrqap+qk6fRp6UE25QBF7A3/SLuhOpIaZ3K24o4 HjGg== X-Gm-Message-State: AOAM530MADG0hGHQLXq3WTTqXQAeXa1HAwD6HZG7JloiFbqN330KQ4bx fN3eaae+1pc5ft0mQ+t1kdNjcGW7XZs= X-Google-Smtp-Source: ABdhPJwPGD29o9BIjhYDMUpYRaZ4ppbddv+TPuPnD1aiCq/kayjkoPNg6u6dGem4oSfhdKw5ae/JUQ== X-Received: by 2002:a63:5fc6:: with SMTP id t189mr55364905pgb.249.1641521745088; Thu, 06 Jan 2022 18:15:45 -0800 (PST) Return-Path: Received: from localhost.localdomain ([50.35.74.198]) by smtp.gmail.com with ESMTPSA id j3sm3894875pfc.196.2022.01.06.18.15.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jan 2022 18:15:44 -0800 (PST) From: "Kun Qin" To: devel@edk2.groups.io Cc: Michael D Kinney , Liming Gao , Zhiguang Liu , Hao A Wu , =?UTF-8?q?Marvin=20H=C3=A4user?= , Bret Barkelew , Michael Kubacki Subject: [PATCH v4 2/7] MdePkg: MmCommunication: Introduce EFI_MM_COMMUNICATE_HEADER_V3 to MdePkg Date: Thu, 6 Jan 2022 18:15:27 -0800 Message-Id: <20220107021532.1322-3-kuqin12@gmail.com> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20220107021532.1322-1-kuqin12@gmail.com> References: <20220107021532.1322-1-kuqin12@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3398 REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3430 This change introduces a new definition for MM communicate header structure, intending to provide better portability between different architectures (IA32 & X64) and adapt to flexible array supported by modern compilers. The original MessageLength field of EFI_MM_COMMUNICATE_HEADER, as a generic definition, was used for both PEI and DXE MM communication. On a system that supports PEI MM launch, but operates PEI in 32bit mode and MM foundation in 64bit, the current EFI_MM_COMMUNICATE_HEADER definition will cause structure parse error due to UINTN used. This introduction removes the architecture dependent field by defining this field as UINT64. The new signature could help identifying whether the data received is compiliant with this new data structure, which will help for binary release modules to identify usage of legacy data structure. Version field is also added to indicate the current version of header in case there is need for minor modification in the future. The data field of MM communicate message is replaced with flexible array to allow users not having to consume extra data during communicate and author code more intrinsically. Cc: Michael D Kinney Cc: Liming Gao Cc: Zhiguang Liu Cc: Hao A Wu Cc: Marvin Häuser Cc: Bret Barkelew Cc: Michael Kubacki Signed-off-by: Kun Qin --- Notes: v3: - Newly introduced communicate v3 - Used flexible arrays [Marvin] - Added static assert [Michael] v4: - Rebased with uncrusitify changes. MdePkg/Include/Pi/PiMultiPhase.h | 57 ++++++++++++++++++++ MdePkg/MdePkg.dec | 5 ++ 2 files changed, 62 insertions(+) diff --git a/MdePkg/Include/Pi/PiMultiPhase.h b/MdePkg/Include/Pi/PiMultiPhase.h index a7e95820ef65..178606eacfb0 100644 --- a/MdePkg/Include/Pi/PiMultiPhase.h +++ b/MdePkg/Include/Pi/PiMultiPhase.h @@ -103,6 +103,17 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #define EFI_SMRAM_CLOSED EFI_MMRAM_CLOSED #define EFI_SMRAM_LOCKED EFI_MMRAM_LOCKED +/// +/// MM Communicate header constants +/// +#define COMMUNICATE_HEADER_V3_GUID \ + { \ + 0x68e8c853, 0x2ba9, 0x4dd7, { 0x9a, 0xc0, 0x91, 0xe1, 0x61, 0x55, 0xc9, 0x35 } \ + } + +#define EFI_MM_COMMUNICATE_HEADER_V3_SIGNATURE 0x4D434833 // "MCH3" +#define EFI_MM_COMMUNICATE_HEADER_V3_VERSION 3 + /// /// Structure describing a MMRAM region and its accessibility attributes. /// @@ -149,6 +160,50 @@ typedef struct _EFI_MM_RESERVED_MMRAM_REGION { UINT64 MmramReservedSize; } EFI_MM_RESERVED_MMRAM_REGION; +#pragma pack(1) + +/// +/// To avoid confusion in interpreting frames, the buffer communicating to MM core through +/// EFI_MM_COMMUNICATE3 or later should always start with EFI_MM_COMMUNICATE_HEADER_V3. +/// +typedef struct { + /// + /// Indicator GUID for MM core that the communication buffer is compliant with this v3 header. + /// Must be gCommunicateHeaderV3Guid. + /// + EFI_GUID HeaderGuid; + /// + /// Signature to indicate data is compliant with new MM communicate header structure. + /// Must be "MCH3". + /// + UINT32 Signature; + /// + /// MM communicate data format version, MM foundation entry point should check if incoming + /// data is a supported format before proceeding. + /// Must be 3. + /// + UINT32 Version; + /// + /// Allows for disambiguation of the message format. + /// + EFI_GUID MessageGuid; + /// + /// Describes the size of MessageData (in bytes) and does not include the size of the header. + /// + UINT64 MessageSize; + /// + /// Designates an array of bytes that is MessageSize in size. + /// + UINT8 MessageData[]; +} EFI_MM_COMMUNICATE_HEADER_V3; + +#pragma pack() + +STATIC_ASSERT ( + (sizeof (EFI_MM_COMMUNICATE_HEADER_V3) == OFFSET_OF (EFI_MM_COMMUNICATE_HEADER_V3, MessageData)), \ + "sizeof (EFI_MM_COMMUNICATE_HEADER_V3) does not align with the beginning of flexible array MessageData" + ); + typedef enum { EFI_PCD_TYPE_8, EFI_PCD_TYPE_16, @@ -208,4 +263,6 @@ EFI_STATUS IN VOID *ProcedureArgument ); +extern EFI_GUID gCommunicateHeaderV3Guid; + #endif diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec index 59b405928bf8..11c08e617511 100644 --- a/MdePkg/MdePkg.dec +++ b/MdePkg/MdePkg.dec @@ -826,6 +826,11 @@ [Guids] ## Include/Protocol/CcMeasurement.h gEfiCcFinalEventsTableGuid = { 0xdd4a4648, 0x2de7, 0x4665, { 0x96, 0x4d, 0x21, 0xd9, 0xef, 0x5f, 0xb4, 0x46 }} + # + # GUID indicates the MM communication data is compliant with v3 communication header. + # + gCommunicateHeaderV3Guid = { 0x68e8c853, 0x2ba9, 0x4dd7, { 0x9a, 0xc0, 0x91, 0xe1, 0x61, 0x55, 0xc9, 0x35 } } + [Guids.IA32, Guids.X64] ## Include/Guid/Cper.h gEfiIa32X64ErrorTypeCacheCheckGuid = { 0xA55701F5, 0xE3EF, 0x43de, { 0xAC, 0x72, 0x24, 0x9B, 0x57, 0x3F, 0xAD, 0x2C }} -- 2.34.1.windows.1