public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Marcin Wojtas <mw@semihalf.com>
To: Leif Lindholm <leif.lindholm@linaro.org>
Cc: edk2-devel-01 <edk2-devel@lists.01.org>,
	Ard Biesheuvel <ard.biesheuvel@linaro.org>,
	 nadavh@marvell.com, "jsd@semihalf.com" <jsd@semihalf.com>,
	Grzegorz Jaszczyk <jaz@semihalf.com>,
	 Kostya Porotchkin <kostap@marvell.com>,
	jinghua <jinghua@marvell.com>
Subject: Re: [platforms: PATCH v2 07/12] Marvell/Protocol: Introduce GPIO helper header
Date: Tue, 15 Jan 2019 07:12:37 +0100	[thread overview]
Message-ID: <CAPv3WKeT_ugM6wh3vjDH72sTVw_XjiOhWVQN7AyXs9WekO90Jg@mail.gmail.com> (raw)
In-Reply-To: <20190114231203.vkbl2qlh245p4xhc@bivouac.eciton.net>

Hi Leif,

wt., 15 sty 2019 o 00:12 Leif Lindholm <leif.lindholm@linaro.org> napisał(a):
>
> On Thu, Jan 10, 2019 at 02:44:34AM +0100, Marcin Wojtas wrote:
> > From: jinghua <jinghua@marvell.com>
> >
> > This patch introduces a helper header that can be used by
> > multiple EMBEDDED_GPIO protocol producers (e.g. platform
> > driver or GPIO expanders). The drives are differentiated by
> > MV_GPIO_DRIVER_TYPE field of driver's MV_GPIO_DEVICE_PATH.
> >
> > In order to ease selection of the desired GPIO controller
> > a helper function was added - MarvellGpioGetProtocol().
> >
> > Contributed-under: TianoCore Contribution Agreement 1.1
> > Signed-off-by: Marcin Wojtas <mw@semihalf.com>
> > ---
> >  Silicon/Marvell/Include/Protocol/MvGpio.h | 156 ++++++++++++++++++++
> >  1 file changed, 156 insertions(+)
> >  create mode 100644 Silicon/Marvell/Include/Protocol/MvGpio.h
> >
> > diff --git a/Silicon/Marvell/Include/Protocol/MvGpio.h b/Silicon/Marvell/Include/Protocol/MvGpio.h
> > new file mode 100644
> > index 0000000..c9f1007
> > --- /dev/null
> > +++ b/Silicon/Marvell/Include/Protocol/MvGpio.h
> > @@ -0,0 +1,156 @@
> > +/**
> > +*
> > +*  Copyright (C) 2018, Marvell International Ltd. and its affiliates.
> > +*
> > +*  This program and the accompanying materials are licensed and made available
> > +*  under the terms and conditions of the BSD 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 IMPLIED.
> > +*
> > +**/
> > +#ifndef __MV_GPIO_PROTOCOL_H__
> > +#define __MV_GPIO_PROTOCOL_H__
> > +
> > +#include <Uefi.h>
> > +
> > +#include <Library/DebugLib.h>
> > +#include <Library/DevicePathLib.h>
> > +#include <Library/MemoryAllocationLib.h>
> > +#include <Library/UefiBootServicesTableLib.h>
> > +
> > +#include <Protocol/EmbeddedGpio.h>
> > +
> > +typedef enum {
> > +  MV_GPIO_DRIVER_TYPE_SOC_CONTROLLER,
> > +} MV_GPIO_DRIVER_TYPE;
> > +
> > +typedef struct {
> > +  VENDOR_DEVICE_PATH        Header;
> > +  MV_GPIO_DRIVER_TYPE       GpioDriverType;
> > +  EFI_DEVICE_PATH_PROTOCOL  End;
> > +} MV_GPIO_DEVICE_PATH;
> > +
> > +typedef struct {
> > +  UINTN    ControllerId;
> > +  UINTN    PinNumber;
> > +  BOOLEAN  ActiveHigh;
> > +} MV_GPIO_PIN;
> > +
> > +/*
> > + * Check if the driver type matches the requested value.
> > + * In case of the success open the GPIO protocol and return.
> > + */
> > +STATIC
> > +inline
> > +EFI_STATUS
> > +EFIAPI
> > +MvGpioFindMatchingDriver (
>
> Eep!
> I missed this in v1 (I assumed I'd missed the new file indicator
> whilst scrolling) - please move these functions out of this .h file.
> https://edk2-docs.gitbooks.io/edk-ii-c-coding-standards-specification/content/v/release/2.20/5_source_files/53_include_files.html#537-include-files-shall-not-generate-code-or-define-data-variables
>
> This makes me take a closer look at the rest of the patch ... and this
> just isn't a protocol - it's a library. Please restrucure it as such
> and move the header file to Include/Library rather than
> Include/Protocol.
>

Initially it was a header for MvGpioProtocol + this inline C addition
at the end... I will change it to the library.

Thanks,
Marcin

> /
>     Leif
>
> > +  IN     MV_GPIO_DRIVER_TYPE    GpioDriverType,
> > +  IN     EFI_HANDLE             HandleBuffer,
> > +  IN     EFI_DEVICE_PATH       *DevicePath,
> > +  IN OUT EMBEDDED_GPIO        **GpioProtocol
> > +  )
> > +{
> > +  MV_GPIO_DEVICE_PATH *GpioDevicePath;
> > +  EFI_STATUS           Status;
> > +
> > +  while (!IsDevicePathEndType (DevicePath)) {
> > +    /* Check if GpioDriverType matches one found in the device path */
> > +    GpioDevicePath = (MV_GPIO_DEVICE_PATH *)DevicePath;
> > +    if (GpioDevicePath->GpioDriverType != GpioDriverType) {
> > +      DevicePath = NextDevicePathNode (DevicePath);
> > +      continue;
> > +    }
> > +
> > +    /*
> > +     * Open GpioProtocol. With EFI_OPEN_PROTOCOL_GET_PROTOCOL attribute
> > +     * the consumer is not obliged to call CloseProtocol.
> > +     */
> > +    Status = gBS->OpenProtocol (HandleBuffer,
> > +                    &gEmbeddedGpioProtocolGuid,
> > +                    (VOID **)GpioProtocol,
> > +                    gImageHandle,
> > +                    NULL,
> > +                    EFI_OPEN_PROTOCOL_GET_PROTOCOL);
> > +    return Status;
> > +  }
> > +
> > +  return EFI_NOT_FOUND;
> > +}
> > +
> > +/*
> > + * Select desired protocol producer upon MV_GPIO_DRIVER_TYPE
> > + * field of driver's MV_GPIO_DEVICE_PATH.
> > + */
> > +STATIC
> > +inline
> > +EFI_STATUS
> > +EFIAPI
> > +MvGpioGetProtocol (
> > +  IN     MV_GPIO_DRIVER_TYPE    GpioDriverType,
> > +  IN OUT EMBEDDED_GPIO        **GpioProtocol
> > +  )
> > +{
> > +  EFI_DEVICE_PATH     *DevicePath;
> > +  EFI_HANDLE          *HandleBuffer;
> > +  EFI_STATUS           Status;
> > +  UINTN                HandleCount;
> > +  UINTN                Index;
> > +
> > +  /* Locate Handles of all EMBEDDED_GPIO producers */
> > +  Status = gBS->LocateHandleBuffer (ByProtocol,
> > +                  &gEmbeddedGpioProtocolGuid,
> > +                  NULL,
> > +                  &HandleCount,
> > +                  &HandleBuffer);
> > +  if (EFI_ERROR (Status)) {
> > +    DEBUG ((DEBUG_ERROR, "%a: Unable to locate handles\n", __FUNCTION__));
> > +    return Status;
> > +  }
> > +
> > +  /* Iterate over all protocol producers */
> > +  for (Index = 0; Index < HandleCount; Index++) {
> > +    /* Open device path protocol installed on each handle */
> > +    Status = gBS->OpenProtocol (HandleBuffer[Index],
> > +                    &gEfiDevicePathProtocolGuid,
> > +                    (VOID **)&DevicePath,
> > +                    gImageHandle,
> > +                    NULL,
> > +                    EFI_OPEN_PROTOCOL_GET_PROTOCOL);
> > +    if (EFI_ERROR (Status)) {
> > +      DEBUG ((DEBUG_ERROR, "%a: Unable to find DevicePath\n", __FUNCTION__));
> > +      continue;
> > +    }
> > +
> > +    /*
> > +     * Check if the driver type matches the requested value.
> > +     * In case of the success open the GPIO protocol and return.
> > +     * If there is no match, repeat procedure with the next handle.
> > +     */
> > +    Status = MvGpioFindMatchingDriver (GpioDriverType,
> > +               HandleBuffer[Index],
> > +               DevicePath,
> > +               GpioProtocol);
> > +    if (Status == EFI_NOT_FOUND) {
> > +      continue;
> > +    } else if (EFI_ERROR (Status)) {
> > +      DEBUG ((DEBUG_ERROR,
> > +        "%a: Unable to open GPIO protocol\n",
> > +        __FUNCTION__));
> > +    }
> > +
> > +    gBS->FreePool (HandleBuffer);
> > +
> > +    return Status;
> > +  }
> > +
> > +  /* No matching GPIO protocol producer was found */
> > +  gBS->FreePool (HandleBuffer);
> > +
> > +  return EFI_NOT_FOUND;
> > +}
> > +
> > +#endif // __MV_GPIO_PROTOCOL_H__
> > --
> > 2.7.4
> >


  reply	other threads:[~2019-01-15  6:12 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-10  1:44 [platforms: PATCH v2 00/12] Armada 7k8k GPIO support Marcin Wojtas
2019-01-10  1:44 ` [platforms: PATCH v2 01/12] Marvell/Library: ArmadaSoCDescLib: Add GPIO information Marcin Wojtas
2019-01-14 23:45   ` Leif Lindholm
2019-01-10  1:44 ` [platforms: PATCH v2 02/12] Marvell/Library: ArmadaBoardDescLib: " Marcin Wojtas
2019-01-14 23:46   ` Leif Lindholm
2019-01-10  1:44 ` [platforms: PATCH v2 03/12] SolidRun/Armada80x0McBin: Extend board description library with GPIO Marcin Wojtas
2019-01-14 23:46   ` Leif Lindholm
2019-01-10  1:44 ` [platforms: PATCH v2 04/12] Marvell/Armada70x0Db: " Marcin Wojtas
2019-01-14 22:41   ` Leif Lindholm
2019-01-15  5:48     ` Marcin Wojtas
2019-01-10  1:44 ` [platforms: PATCH v2 05/12] Marvell/Armada80x0Db: " Marcin Wojtas
2019-01-14 22:44   ` Leif Lindholm
2019-01-10  1:44 ` [platforms: PATCH v2 06/12] Marvell/Drivers: MvBoardDesc: Extend protocol with GPIO support Marcin Wojtas
2019-01-14 22:58   ` Leif Lindholm
2019-01-15  6:05     ` Marcin Wojtas
2019-01-15  9:56       ` Leif Lindholm
2019-01-15 10:05         ` Marcin Wojtas
2019-01-15 10:12           ` Leif Lindholm
2019-01-15 10:14             ` Marcin Wojtas
2019-01-15 10:26               ` Leif Lindholm
2019-01-10  1:44 ` [platforms: PATCH v2 07/12] Marvell/Protocol: Introduce GPIO helper header Marcin Wojtas
2019-01-14 23:12   ` Leif Lindholm
2019-01-15  6:12     ` Marcin Wojtas [this message]
2019-01-10  1:44 ` [platforms: PATCH v2 08/12] Marvell/Drivers: MvGpioDxe: Introduce platform GPIO driver Marcin Wojtas
2019-01-14 23:32   ` Leif Lindholm
2019-01-15  6:19     ` Marcin Wojtas
2019-01-15 10:04       ` Leif Lindholm
2019-01-15 10:06         ` Marcin Wojtas
2019-01-10  1:44 ` [platforms: PATCH v2 09/12] Marvell/Drivers: I2c: Use common header for macros Marcin Wojtas
2019-01-10  1:44 ` [platforms: PATCH v2 10/12] Marvell/Drivers: MvPca95xxDxe: Introduce GPIO expander driver Marcin Wojtas
2019-01-14 23:40   ` Leif Lindholm
2019-01-10  1:44 ` [platforms: PATCH v2 11/12] Marvell/Armada7k8k: Enable GPIO drivers compilation Marcin Wojtas
2019-01-10  1:44 ` [platforms: PATCH v2 12/12] Marvell/Armada7k8k: Introduce NonDiscoverable device init routines Marcin Wojtas
2019-01-14 23:44   ` Leif Lindholm

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=CAPv3WKeT_ugM6wh3vjDH72sTVw_XjiOhWVQN7AyXs9WekO90Jg@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