public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Wu, Hao A" <hao.a.wu@intel.com>
To: "devel@edk2.groups.io" <devel@edk2.groups.io>,
	"Wu, Hao A" <hao.a.wu@intel.com>,
	"Bassa, Damian" <damian.bassa@intel.com>
Cc: "Rusocki, Krzysztof" <krzysztof.rusocki@intel.com>
Subject: Re: [edk2-devel] [PATCH] MdeModulePkg/RamDiskDxe: RamDisk driver to assign non-zero SPA range index
Date: Tue, 29 Jun 2021 00:31:03 +0000	[thread overview]
Message-ID: <BN8PR11MB36660118AC1DC88E1ABA61F3CA029@BN8PR11MB3666.namprd11.prod.outlook.com> (raw)
In-Reply-To: <BN8PR11MB3666CEB1919951A39A1E8920CA029@BN8PR11MB3666.namprd11.prod.outlook.com>

> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Wu, Hao A
> Sent: Tuesday, June 29, 2021 8:24 AM
> To: devel@edk2.groups.io; Bassa, Damian <damian.bassa@intel.com>
> Cc: Rusocki, Krzysztof <krzysztof.rusocki@intel.com>
> Subject: Re: [edk2-devel] [PATCH] MdeModulePkg/RamDiskDxe: RamDisk driver
> to assign non-zero SPA range index
> 
> > -----Original Message-----
> > From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Bassa,
> > Damian
> > Sent: Tuesday, June 29, 2021 2:22 AM
> > To: devel@edk2.groups.io
> > Cc: Rusocki, Krzysztof <krzysztof.rusocki@intel.com>
> > Subject: [edk2-devel] [PATCH] MdeModulePkg/RamDiskDxe: RamDisk driver
> > to assign non-zero SPA range index
> >
> > 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.
> 
> 
> Hello Damian Bassa,
> 
> Thanks a lot for the patch.
> 
> The reason the current implementation leave the 'SPARangeStructureIndex' field
> as value 0 for RamDisk is that in Section 5.2.25.2 of the ACPI 6.1 specification
> (also applies for ACPI 6.3):


Fix a typo: "also applies for ACPI 6.4"

Best Regards,
Hao Wu


> 
> |> For Virtual CD Region and Virtual Disk Region (both volatile and
> |> persistent), the following fields - Proximity Domain, SPA Range
> |> Structure Index, Flags, and Address Range Memory Mapping Attribute, are
> not relevant and shall be set to 0.
> 
> Assigning a non-zero value proposed in this patch seems not following the above
> statement.
> 
> Best Regards,
> Hao Wu
> 
> 
> >
> > Signed-off-by: Damian Bassa <damian.bassa@intel.com>
> > ---
> >  .../Disk/RamDiskDxe/RamDiskProtocol.c         | 131 ++++++++++++++++++
> >  1 file changed, 131 insertions(+)
> >
> > diff --git a/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskProtocol.c
> > b/MdeModulePkg/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 = 0;
> > +
> > +  EFI_ACPI_6_1_NFIT_STRUCTURE_HEADER                        *NfitStructHeader;
> > +  EFI_ACPI_6_1_NFIT_SYSTEM_PHYSICAL_ADDRESS_RANGE_STRUCTURE
> > *SpaRange;
> > +
> > +  Length = ((EFI_ACPI_DESCRIPTION_HEADER *)TableHeader)->Length -
> > + sizeof (EFI_ACPI_6_1_NVDIMM_FIRMWARE_INTERFACE_TABLE);
> > +  NfitStructHeader = (EFI_ACPI_6_1_NFIT_STRUCTURE_HEADER *)
> > +                     ((UINT8 *)TableHeader + sizeof
> > + (EFI_ACPI_6_1_NVDIMM_FIRMWARE_INTERFACE_TABLE));
> > +
> > +  while (Length > sizeof(EFI_ACPI_6_1_NFIT_STRUCTURE_HEADER)) {
> > +    if (NfitStructHeader->Length <
> > sizeof(EFI_ACPI_6_1_NFIT_STRUCTURE_HEADER)) {
> > +      break;
> > +    }
> > +    if ((NfitStructHeader->Type ==
> > EFI_ACPI_6_1_NFIT_SYSTEM_PHYSICAL_ADDRESS_RANGE_STRUCTURE_TYPE)
> > &&
> > +        (NfitStructHeader->Length >= sizeof
> > (EFI_ACPI_6_1_NFIT_SYSTEM_PHYSICAL_ADDRESS_RANGE_STRUCTURE))) {
> > +         SpaRange =
> > (EFI_ACPI_6_1_NFIT_SYSTEM_PHYSICAL_ADDRESS_RANGE_STRUCTURE
> > *)NfitStructHeader;
> > +         if (SpaRange->SPARangeStructureIndex > HighestIndex) {
> > +           HighestIndex = SpaRange->SPARangeStructureIndex;
> > +         }
> > +    }
> > +
> > +    //
> > +    // Move to the header of next NFIT structure.
> > +    //
> > +    Length       -= NfitStructHeader->Length;
> > +    NfitStructHeader = (EFI_ACPI_6_1_NFIT_STRUCTURE_HEADER *)
> > +                       ((UINT8 *)NfitStructHeader +
> > +NfitStructHeader->Length);
> > +  }
> > +  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 table
> > +  @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                        *NfitStructHeader;
> > +  EFI_ACPI_6_1_NFIT_SYSTEM_PHYSICAL_ADDRESS_RANGE_STRUCTURE
> > *SpaRange;
> > +
> > +  Length = ((EFI_ACPI_DESCRIPTION_HEADER *)TableHeader)->Length -  +
> > + sizeof (EFI_ACPI_6_1_NVDIMM_FIRMWARE_INTERFACE_TABLE);
> > +  NfitStructHeader = (EFI_ACPI_6_1_NFIT_STRUCTURE_HEADER *)
> > +                     ((UINT8 *)TableHeader + sizeof
> > + (EFI_ACPI_6_1_NVDIMM_FIRMWARE_INTERFACE_TABLE));
> > +
> > +  while (Length > sizeof(EFI_ACPI_6_1_NFIT_STRUCTURE_HEADER)) {
> > +    if (NfitStructHeader->Length <
> > sizeof(EFI_ACPI_6_1_NFIT_STRUCTURE_HEADER)) {
> > +      break;
> > +    }
> > +    if ((NfitStructHeader->Type ==
> > EFI_ACPI_6_1_NFIT_SYSTEM_PHYSICAL_ADDRESS_RANGE_STRUCTURE_TYPE)
> > &&
> > +        (NfitStructHeader->Length >= sizeof
> > (EFI_ACPI_6_1_NFIT_SYSTEM_PHYSICAL_ADDRESS_RANGE_STRUCTURE))) {
> > +         SpaRange =
> > (EFI_ACPI_6_1_NFIT_SYSTEM_PHYSICAL_ADDRESS_RANGE_STRUCTURE
> > *)NfitStructHeader;
> > +         if (SpaRange->SPARangeStructureIndex == SpaRangeIndex) {
> > +           return TRUE;
> > +         }
> > +    }
> > +
> > +    //
> > +    // Move to the header of next NFIT structure.
> > +    //
> > +    Length       -= NfitStructHeader->Length;
> > +    NfitStructHeader = (EFI_ACPI_6_1_NFIT_STRUCTURE_HEADER *)
> > +                       ((UINT8 *)NfitStructHeader +
> > +NfitStructHeader->Length);
> > +  }
> > +  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 = GetHighestSpaRangeIndex (TableHeader);
> > +
> > +  //
> > +  // If highest range found is not maximum allowed number use value
> > +increased by 1
> > +  //
> > +  if (Index != MAX_UINT16) {
> > +    return Index + 1;
> > +  }
> > +  //
> > +  // If highest possible index value is already used, see if there is
> > +any that is not taken
> > +  //
> > +  for (Index = 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 = sizeof
> > (EFI_ACPI_6_1_NFIT_SYSTEM_PHYSICAL_ADDRESS_RANGE_STRUCTURE);
> >    SpaRange->SystemPhysicalAddressRangeBase   = PrivateData->StartingAddr;
> >    SpaRange->SystemPhysicalAddressRangeLength = PrivateData->Size;
> > +  SpaRange->SPARangeStructureIndex = GetFreeSpaIndex (Nfit);
> >    CopyGuid (&SpaRange->AddressRangeTypeGUID, &PrivateData->TypeGuid);
> >
> >    Checksum             = CalculateCheckSum8((UINT8 *)Nfit, NfitHeader->Length);
> > --
> > 2.27.0.windows.1
> >
> > Intel Technology Poland sp. z o.o.
> > ul. Sowackiego 173 | 80-298 Gdask | Sd Rejonowy Gdask Pnoc | VII
> > Wydzia Gospodarczy Krajowego Rejestru Sdowego - KRS 101882 | NIP
> > 957-07-52-316 | Kapita zakadowy 200.000 PLN.
> > Ta wiadomo wraz z zacznikami jest przeznaczona dla okrelonego adresata
> > i moe zawiera informacje poufne. W razie przypadkowego otrzymania tej
> > wiadomoci, prosimy o powiadomienie nadawcy oraz trwae jej usunicie;
> > jakiekolwiek przegldanie lub rozpowszechnianie jest zabronione.
> > This e-mail and any attachments may contain confidential material for
> > the sole use of the intended recipient(s). If you are not the intended
> > recipient, please contact the sender and delete all copies; any review
> > or distribution by others is strictly prohibited.
> >
> >
> >
> >
> >
> 
> 
> 
> 
> 


      reply	other threads:[~2021-06-29  0:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-28 18:21 [PATCH] MdeModulePkg/RamDiskDxe: RamDisk driver to assign non-zero SPA range index Bassa, Damian
2021-06-29  0:23 ` Wu, Hao A
2021-06-29  0:31   ` Wu, Hao A [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BN8PR11MB36660118AC1DC88E1ABA61F3CA029@BN8PR11MB3666.namprd11.prod.outlook.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox