public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Ard Biesheuvel <ard.biesheuvel@linaro.org>
To: Laszlo Ersek <lersek@redhat.com>
Cc: "edk2-devel@lists.01.org" <edk2-devel@lists.01.org>,
	Leif Lindholm <leif.lindholm@linaro.org>,
	 Marcin Wojtas <marcin.wojtas@semihalf.com>,
	Alexander Graf <agraf@suse.de>
Subject: Re: [PATCH] EmbeddedPkg: add DT platform driver to select between DT and ACPI
Date: Tue, 28 Mar 2017 11:51:01 +0100	[thread overview]
Message-ID: <CAKv+Gu9zBKPncXjCTpR5avBiSedGx-0sd0xz4cCr8EiU6QwhVw@mail.gmail.com> (raw)
In-Reply-To: <383c1aff-9a8a-b8c4-a0c4-c5d272f52c36@redhat.com>

On 28 March 2017 at 11:49, Laszlo Ersek <lersek@redhat.com> wrote:
> On 03/28/17 12:43, Laszlo Ersek wrote:
>> Ard,
>>
>> On 03/27/17 12:07, Ard Biesheuvel wrote:
>
> [snip]
>
>>> +/**
>>> +  The entry point for DtPlatformDxe driver.
>>> +
>>> +  @param[in] ImageHandle     The image handle of the driver.
>>> +  @param[in] SystemTable     The system table.
>>> +
>>> +  @retval EFI_ALREADY_STARTED     The driver already exists in system.
>>> +  @retval EFI_OUT_OF_RESOURCES    Fail to execute entry point due to lack of
>>> +                                  resources.
>>> +  @retval EFI_SUCCES              All the related protocols are installed on
>>> +                                  the driver.
>>> +
>>> +**/
>>> +EFI_STATUS
>>> +EFIAPI
>>> +DtPlatformDxeEntryPoint (
>>> +  IN EFI_HANDLE                   ImageHandle,
>>> +  IN EFI_SYSTEM_TABLE             *SystemTable
>>> +  )
>>> +{
>>> +  EFI_STATUS                      Status;
>>> +  EFI_HANDLE                      DriverHandle;
>>> +  DT_ACPI_VARSTORE_DATA           DtAcpiPref;
>>> +  UINTN                           BufferSize;
>>> +  VOID                            *Dtb;
>>> +  UINTN                           DtbSize;
>>> +  VOID                            *DtbCopy;
>>> +
>>> +  //
>>> +  // Check whether a DTB blob is included in the firmware image.
>>> +  //
>>> +  Dtb = NULL;
>>> +  Status = GetSectionFromAnyFv (&gDtPlatformDefaultDtbFileGuid,
>>> +             EFI_SECTION_RAW, 0, &Dtb, &DtbSize);
>>> +  if (EFI_ERROR (Status)) {
>>> +    DEBUG ((DEBUG_WARN, "%a: no DTB blob found, defaulting to ACPI\n",
>>> +      __FUNCTION__));
>>> +    DtAcpiPref.Pref = DT_ACPI_SELECT_ACPI;
>>> +  } else {
>>> +    //
>>> +    // Get the current ACPI/DT preference from the AcpiDtPref variable.
>>> +    //
>>
>> The comment says "AcpiDtPref variable" (which corresponds to the name under which the VFR also refers to the variable), but below the variable services actually get a "DtAcpiPref" argument as variable name.
>>
>> Please fix this inconsistency together with the other instances.
>>
>>> +    BufferSize = sizeof (DtAcpiPref);
>>> +    Status = gRT->GetVariable(L"DtAcpiPref", &gDtPlatformFormSetGuid, NULL,
>>> +                    &BufferSize, &DtAcpiPref);
>>> +    if (EFI_ERROR (Status)) {
>>> +      DEBUG ((DEBUG_WARN, "%a: no DT/ACPI preference found, defaulting to DT\n",
>>> +        __FUNCTION__));
>>> +      DtAcpiPref.Pref = DT_ACPI_SELECT_DT;
>>> +    }
>>> +  }
>>> +
>>> +  if (!EFI_ERROR (Status) &&
>>> +      DtAcpiPref.Pref != DT_ACPI_SELECT_ACPI &&
>>> +      DtAcpiPref.Pref != DT_ACPI_SELECT_DT) {
>>> +    DEBUG ((DEBUG_WARN, "%a: illegal value for DtAcpiPref, defaulting to DT\n",
>>> +      __FUNCTION__));
>>
>> Personal request: please replace "illegal" with "invalid".
>>
>>> +    DtAcpiPref.Pref = DT_ACPI_SELECT_DT;
>>> +    Status = EFI_INVALID_PARAMETER; // trigger setvar below
>>> +  }
>>> +
>>> +  //
>>> +  // Write the newly selected default value back to the variable store.
>>> +  //
>>> +  if (EFI_ERROR (Status)) {
>>> +    Status = gRT->SetVariable(L"DtAcpiPref", &gDtPlatformFormSetGuid,
>>> +                    EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
>>> +                    sizeof (DtAcpiPref), &DtAcpiPref);
>>
>> I suggest to use a macro for the variable name...
>>
>>> +    if (EFI_ERROR (Status)) {
>>> +      return Status;
>>> +    }
>>> +  }
>>> +
>>> +  if (DtAcpiPref.Pref == DT_ACPI_SELECT_ACPI) {
>>> +    //
>>> +    // ACPI was selected: install the gEdkiiPlatformHasAcpiGuid GUID as a
>>> +    // NULL protocol to unlock dispatch of ACPI related drivers.
>>> +    //
>>> +    DriverHandle = NULL;
>>> +    Status = gBS->InstallMultipleProtocolInterfaces (&DriverHandle,
>>> +                    gEdkiiPlatformHasAcpiGuid, NULL, NULL);
>>> +    if (EFI_ERROR (Status)) {
>>> +      DEBUG ((DEBUG_ERROR,
>>> +        "%a: failed to install gEdkiiPlatformHasAcpiGuid as a protocol\n",
>>> +        __FUNCTION__));
>>> +      return Status;
>>> +    }
>>
>> I think you don't need to create a new controller handle for gEdkiiPlatformHasAcpiGuid; using ImageHandle should be fine.
>>
>> (Same for gEfiDevicePathProtocolGuid in InstallHiiPages().)
>>
>> Not critical though, just simpler perhaps.
>>
>>> +  } else if (DtAcpiPref.Pref == DT_ACPI_SELECT_DT) {
>>> +    //
>>> +    // DT was selected: copy the blob into newly allocated memory and install
>>> +    // a reference to it as the FDT configuration table.
>>> +    //
>>> +    DtbCopy = AllocateCopyPool (DtbSize, Dtb);
>>> +    if (DtbCopy == NULL) {
>>> +      return EFI_OUT_OF_RESOURCES;
>>> +    }
>>> +    Status = gBS->InstallConfigurationTable (&gFdtTableGuid, DtbCopy);
>>> +    if (EFI_ERROR (Status)) {
>>> +      DEBUG ((DEBUG_ERROR, "%a: failed to install FDT configuration table\n",
>>> +        __FUNCTION__));
>>> +      FreePool (DtbCopy);
>>> +      return Status;
>>> +    }
>>
>> Looks good. The original DTB (found in the FV section) lives in flash, generally speaking, right?
>>
>>> +  } else {
>>> +    ASSERT (FALSE);
>>> +  }
>>> +
>>> +  //
>>> +  // No point in installing the HII pages if ACPI is the only description
>>> +  // we have
>>> +  //
>>> +  if (Dtb == NULL) {
>>> +    return EFI_SUCCESS;
>>> +  }
>>> +
>>> +  return InstallHiiPages ();
>>> +}
>
> Consider uninstalling the FDT config table / the "has ACPI" protocol if
> InstallHiiPages() fails and the driver exits with error (it gets
> unloaded)? My inner pedant wants you to do this, although I do realize
> that neither the FDT config table nor the NULL "has ACPI" protocol hook
> back into this driver.
>

That was my reasoning, yes. I will add a comment to that effect, but I
am reluctant to break the boot entirely just because we failed to
register the HII pages.


  reply	other threads:[~2017-03-28 10:51 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-27 10:07 [PATCH] EmbeddedPkg: add DT platform driver to select between DT and ACPI Ard Biesheuvel
2017-03-28 10:43 ` Laszlo Ersek
2017-03-28 10:47   ` Ard Biesheuvel
2017-03-28 10:49   ` Laszlo Ersek
2017-03-28 10:51     ` Ard Biesheuvel [this message]
2017-03-28 10:58       ` Laszlo Ersek

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=CAKv+Gu9zBKPncXjCTpR5avBiSedGx-0sd0xz4cCr8EiU6QwhVw@mail.gmail.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