From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: None (no SPF record) identity=mailfrom; client-ip=2607:f8b0:4864:20::143; helo=mail-it1-x143.google.com; envelope-from=mw@semihalf.com; receiver=edk2-devel@lists.01.org Received: from mail-it1-x143.google.com (mail-it1-x143.google.com [IPv6:2607:f8b0:4864:20::143]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 636E1211B6C35 for ; Thu, 17 Jan 2019 06:40:09 -0800 (PST) Received: by mail-it1-x143.google.com with SMTP id g76so1668848itg.2 for ; Thu, 17 Jan 2019 06:40:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=Cvv7xYvgALAelRGpH2IsMd52CpTvn4P3aFicz/kzbAc=; b=uiQsrX2dFNc7lwO2HDC7xule3TvmIsBPuplwwDsB5SZAicRB0A3Pmn3De9HR6gxtVQ 4gcdePi6lAJzJjtPyY9jYkAYksa1qgK1wuOM6kZa+Ye/mWlwbQpPzdCcPdA+eL6iL15a e8blp2snUptRaji9zZxm2KwkcCSViv/hpZsjFettkvHSV0JioaWyEcZV7fd988tCdOVR ewV/EfLsJS9OplfUx6gS86Yzk54Y3sC6iWcWOjf4dRuOUvEtpkJhhInPYkMTNu/TgHrv C6OZE8kC6ZxndZLdNJ1wmNkt5wMW02B2VWczaLpLeu71w7VsjiWvRewMSt5fCftcGJSo bFZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=Cvv7xYvgALAelRGpH2IsMd52CpTvn4P3aFicz/kzbAc=; b=H0IS/CQi44/UqWGoemMg41ArgKL31I+55I4uARnA3CmmOIooln+GNsdQdZ5QT14irV nDXxs6MzZZIrzGTAO75zf5D2sTT5GdjkizdQw4dyP0krS4LQ5WwmHaSK7LaeiVj5PA0N dQtLWfG/HRxBw1KpXNR9GRBddVY1Qp0A/eb/UZgd3+W971G0FBtKeWp4mGPOYWBgc3cw O/frjyZYB/DPI9fExO8CoBkwpXGKeKfRx3IjUrEhWJX50MxfqGxwsLfgh2c8UyQweNa/ Fo5p0batzPUbjGtX8nxB+lPCGk3Gyuem+iZor+vY4NyTD43pjGm/BbshuSr79yvis55q JMDg== X-Gm-Message-State: AJcUukdZiFWYtiyHhXWyzVMwAfPTJjnX2DxC/2nrxihHLcPZjxPxMg3X qHlE3y1vbQVnd9cf5YAo9jakLEtKG1VIMYcVmwwGxw== X-Google-Smtp-Source: ALg8bN4Gta8eJkHpYHR2uRd3htnCdQ5SiZwim2VOfPmHRrx/+EJBKzJ6TLR+tY3sdck5Y31LOGJymfocodo7YIYNeSs= X-Received: by 2002:a02:7696:: with SMTP id z144mr7937601jab.102.1547736008403; Thu, 17 Jan 2019 06:40:08 -0800 (PST) MIME-Version: 1.0 References: <1547723715-4562-1-git-send-email-mw@semihalf.com> <1547723715-4562-4-git-send-email-mw@semihalf.com> <20190117113305.muntfdgceho4safl@bivouac.eciton.net> <20190117141853.qioramxzdh2zaymh@bivouac.eciton.net> In-Reply-To: <20190117141853.qioramxzdh2zaymh@bivouac.eciton.net> From: Marcin Wojtas Date: Thu, 17 Jan 2019 15:39:56 +0100 Message-ID: To: Leif Lindholm Cc: edk2-devel-01 , Ard Biesheuvel , nadavh@marvell.com, "jsd@semihalf.com" , Grzegorz Jaszczyk , Kostya Porotchkin Subject: Re: [platforms: PATCH v3 03/12] Marvell/Library: Introduce MvGpioLib class X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Jan 2019 14:40:09 -0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Thanks a lot! Best regards, Marcin czw., 17 sty 2019 o 15:18 Leif Lindholm napisa= =C5=82(a): > > Series pushed as 944fbb62d6..9b725b6ebb > > Thanks! > > On Thu, Jan 17, 2019 at 01:19:52PM +0100, Marcin Wojtas wrote: > > Hi Leif, > > > > Sorry for omitting. I confirm the patch is: > > Contributed-under: TianoCore Contribution Agreement 1.1 > > > > Will you add it (as well as remove class from the subject) or should I = resubmit? > > > > Thanks, > > Marcin > > > > czw., 17 sty 2019 o 12:33 Leif Lindholm napi= sa=C5=82(a): > > > > > > (Can drop the "class" from subject line) > > > > > > With that: > > > Reviewed-by: Leif Lindholm > > > > > > On Thu, Jan 17, 2019 at 12:15:06PM +0100, Marcin Wojtas wrote: > > > > Following patches will add two drivers that are capable > > > > of producing the generic EMBEDDED_GPIO protocol. In order > > > > to handle a situation, when the consumer module attempts > > > > to locate and open a proper protocol, add a library > > > > helper function. > > > > > > > > In order to ease description of used GPIO pins and controllers > > > > of the Armada 7k8k platforms, add the common enum types. > > > > > > > > Signed-off-by: Marcin Wojtas > > > > --- > > > > Silicon/Marvell/Marvell.dec | 1 + > > > > Silicon/Marvell/Library/MvGpioLib/MvGpioLib.inf | 32 +++++ > > > > Silicon/Marvell/Include/Library/MvGpioLib.h | 68 ++++++++++ > > > > Silicon/Marvell/Library/MvGpioLib/MvGpioLib.c | 132 ++++++++++++= ++++++++ > > > > 4 files changed, 233 insertions(+) > > > > create mode 100644 Silicon/Marvell/Library/MvGpioLib/MvGpioLib.inf > > > > create mode 100644 Silicon/Marvell/Include/Library/MvGpioLib.h > > > > create mode 100644 Silicon/Marvell/Library/MvGpioLib/MvGpioLib.c > > > > > > > > diff --git a/Silicon/Marvell/Marvell.dec b/Silicon/Marvell/Marvell.= dec > > > > index 616624e..ac922a0 100644 > > > > --- a/Silicon/Marvell/Marvell.dec > > > > +++ b/Silicon/Marvell/Marvell.dec > > > > @@ -63,6 +63,7 @@ > > > > ArmadaBoardDescLib|Include/Library/ArmadaBoardDescLib.h > > > > ArmadaIcuLib|Include/Library/ArmadaIcuLib.h > > > > ArmadaSoCDescLib|Include/Library/ArmadaSoCDescLib.h > > > > + MvGpioLib|Include/Library/MvGpioLib.h > > > > SampleAtResetLib|Include/Library/SampleAtResetLib.h > > > > > > > > [Protocols] > > > > diff --git a/Silicon/Marvell/Library/MvGpioLib/MvGpioLib.inf b/Sili= con/Marvell/Library/MvGpioLib/MvGpioLib.inf > > > > new file mode 100644 > > > > index 0000000..3bc54ce > > > > --- /dev/null > > > > +++ b/Silicon/Marvell/Library/MvGpioLib/MvGpioLib.inf > > > > @@ -0,0 +1,32 @@ > > > > +## @file > > > > +# > > > > +# Copyright (C) 2018, Marvell International Ltd. and its affiliat= es
> > > > +# > > > > +# This program and the accompanying materials are licensed and ma= de available > > > > +# under the terms and conditions of the BSD License which accompa= nies 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 EXPRE= SS OR > > > > +# IMPLIED. > > > > +# > > > > +## > > > > + > > > > +[Defines] > > > > + INF_VERSION =3D 0x0001001A > > > > + BASE_NAME =3D MvGpioLib > > > > + FILE_GUID =3D f4386b44-6bc2-4fa1-9989-8513b= bb22692 > > > > + MODULE_TYPE =3D BASE > > > > + VERSION_STRING =3D 1.0 > > > > + LIBRARY_CLASS =3D MvGpioLib > > > > + > > > > +[Sources] > > > > + MvGpioLib.c > > > > + > > > > +[Packages] > > > > + EmbeddedPkg/EmbeddedPkg.dec > > > > + MdePkg/MdePkg.dec > > > > + Silicon/Marvell/Marvell.dec > > > > + > > > > +[LibraryClasses] > > > > + DebugLib > > > > diff --git a/Silicon/Marvell/Include/Library/MvGpioLib.h b/Silicon/= Marvell/Include/Library/MvGpioLib.h > > > > new file mode 100644 > > > > index 0000000..a14acdf > > > > --- /dev/null > > > > +++ b/Silicon/Marvell/Include/Library/MvGpioLib.h > > > > @@ -0,0 +1,68 @@ > > > > +/** > > > > +* > > > > +* Copyright (C) 2018, Marvell International Ltd. and its affiliat= es. > > > > +* > > > > +* This program and the accompanying materials are licensed and ma= de available > > > > +* under the terms and conditions of the BSD License which accompa= nies 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 EXPRE= SS OR IMPLIED. > > > > +* > > > > +**/ > > > > +#ifndef __MV_GPIO_LIB_H__ > > > > +#define __MV_GPIO_LIB_H__ > > > > + > > > > +#include > > > > + > > > > +typedef enum { > > > > + MV_GPIO_DRIVER_TYPE_SOC_CONTROLLER, > > > > + MV_GPIO_DRIVER_TYPE_PCA95XX, > > > > +} MV_GPIO_DRIVER_TYPE; > > > > + > > > > +typedef enum { > > > > + MV_GPIO_AP806_CONTROLLER0, > > > > + MV_GPIO_CP0_CONTROLLER0, > > > > + MV_GPIO_CP0_CONTROLLER1, > > > > + MV_GPIO_CP1_CONTROLLER0, > > > > + MV_GPIO_CP1_CONTROLLER1, > > > > + MV_GPIO_CP2_CONTROLLER0, > > > > + MV_GPIO_CP2_CONTROLLER1, > > > > +} MV_GPIO_SOC_CONTROLLER_TYPE; > > > > + > > > > +typedef enum { > > > > + PCA9505_ID, > > > > + PCA9534_ID, > > > > + PCA9535_ID, > > > > + PCA9536_ID, > > > > + PCA9537_ID, > > > > + PCA9538_ID, > > > > + PCA9539_ID, > > > > + PCA9554_ID, > > > > + PCA9555_ID, > > > > + PCA9556_ID, > > > > + PCA9557_ID, > > > > + PCA95XX_MAX_ID, > > > > +} MV_GPIO_EXPANDER_TYPE_PCA95XX; > > > > + > > > > +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; > > > > + > > > > +EFI_STATUS > > > > +EFIAPI > > > > +MvGpioGetProtocol ( > > > > + IN MV_GPIO_DRIVER_TYPE GpioDriverType, > > > > + IN OUT EMBEDDED_GPIO **GpioProtocol > > > > + ); > > > > + > > > > +#endif // __MV_GPIO_LIB_H__ > > > > diff --git a/Silicon/Marvell/Library/MvGpioLib/MvGpioLib.c b/Silico= n/Marvell/Library/MvGpioLib/MvGpioLib.c > > > > new file mode 100644 > > > > index 0000000..a95d5ae > > > > --- /dev/null > > > > +++ b/Silicon/Marvell/Library/MvGpioLib/MvGpioLib.c > > > > @@ -0,0 +1,132 @@ > > > > +/** > > > > +* > > > > +* Copyright (C) 2018, Marvell International Ltd. and its affiliat= es. > > > > +* > > > > +* This program and the accompanying materials are licensed and ma= de available > > > > +* under the terms and conditions of the BSD License which accompa= nies 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 EXPRE= SS OR IMPLIED. > > > > +* > > > > +**/ > > > > +#include > > > > + > > > > +#include > > > > +#include > > > > +#include > > > > +#include > > > > +#include > > > > + > > > > +#include > > > > + > > > > +/* > > > > + * Check if the driver type matches the requested value. > > > > + * In case of the success open the GPIO protocol and return. > > > > + */ > > > > +STATIC > > > > +EFI_STATUS > > > > +MvGpioFindMatchingDriver ( > > > > + 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 pat= h */ > > > > + GpioDevicePath =3D (MV_GPIO_DEVICE_PATH *)DevicePath; > > > > + if (GpioDevicePath->GpioDriverType !=3D GpioDriverType) { > > > > + DevicePath =3D NextDevicePathNode (DevicePath); > > > > + continue; > > > > + } > > > > + > > > > + /* > > > > + * Open GpioProtocol. With EFI_OPEN_PROTOCOL_GET_PROTOCOL attr= ibute > > > > + * the consumer is not obliged to call CloseProtocol. > > > > + */ > > > > + Status =3D 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. > > > > + */ > > > > +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 =3D gBS->LocateHandleBuffer (ByProtocol, > > > > + &gEmbeddedGpioProtocolGuid, > > > > + NULL, > > > > + &HandleCount, > > > > + &HandleBuffer); > > > > + if (EFI_ERROR (Status)) { > > > > + DEBUG ((DEBUG_ERROR, "%a: Unable to locate handles\n", __FUNCT= ION__)); > > > > + return Status; > > > > + } > > > > + > > > > + /* Iterate over all protocol producers */ > > > > + for (Index =3D 0; Index < HandleCount; Index++) { > > > > + /* Open device path protocol installed on each handle */ > > > > + Status =3D 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", __FU= NCTION__)); > > > > + 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 =3D MvGpioFindMatchingDriver (GpioDriverType, > > > > + HandleBuffer[Index], > > > > + DevicePath, > > > > + GpioProtocol); > > > > + if (Status =3D=3D 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; > > > > +} > > > > -- > > > > 2.7.4 > > > >