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::141; helo=mail-it1-x141.google.com; envelope-from=mw@semihalf.com; receiver=edk2-devel@lists.01.org Received: from mail-it1-x141.google.com (mail-it1-x141.google.com [IPv6:2607:f8b0:4864:20::141]) (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 1E679211B736F for ; Mon, 14 Jan 2019 22:12:47 -0800 (PST) Received: by mail-it1-x141.google.com with SMTP id z7so3437107iti.0 for ; Mon, 14 Jan 2019 22:12:47 -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=/8Bax8Z3Ef/QZ+aqRoREYOdJDt4d2Vynj/LMLDGWR7g=; b=P0zdjFBPm4rjY/LP+rhemN9X66+VMm/ZPUV+3a1QnbXPWptuBEZmsWN0X0KikbisP1 sv2xjI4qpowZ5JycDyxOenVKuUcayrhpkBfqw0IF+ojLri/nxY9JhK1kvejy7VLw8a3d dnyTEmTZ5DS0Nzwne7sZX2EfneLv29R7U0IGBinYPVenKhxTE0RJEcHzSWTrBl9vEMkX f+jrS1oJ1nRNuT3N/htvkaDyqumHlbIB60NF96iTrCG9s9gUzhjf2AdapJ6NBceNZU6T 2FIuardw9gvxq1ZNCE4EGUm7nrW4WAY8M9PL6tfKu68j/dvV4xRekFpISnrdlVmGHDGi l0nA== 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=/8Bax8Z3Ef/QZ+aqRoREYOdJDt4d2Vynj/LMLDGWR7g=; b=jd035nuJuHe1qBf29WFG5VcZkwtqtXF2Y73p+Y/1PdrtD0rR+SJcgm7IHLEFBWp/MT 5no05HGZckZktcjYjt3vpUDRgOWvu80Rw48Ei9vpWMsx1CqZ4Ev8xS4rt/f5jYQK6p4N bm+C4bGuy600NkNNPk7XqHw0JAAvH/cceCO/cN0WnBfBGHPrdWKwVvI+xuGH9UP209/Q C2/LY+2Gyumso/XMBrq6plzH3sRo3yOFkC5jAGkvEAyIS+xyklKpe6VbJriH8Z/2FitT nF6sWu44fhNPbEKYShlM19we5MjVOcCYCNzBY6E3IS1QMjMKXUIGzgOF9bOxs7dgqq8x OBhQ== X-Gm-Message-State: AJcUukelr3iGFGpsRpBSaV/HdMJYHrkVhyW4mso3pA9/YiTjpOZkZlEh H8af7YIO7pMO0V9OEfdI7pLVk0vYQfyOot2L18cilwCo X-Google-Smtp-Source: ALg8bN580/LDN4cT6zzGTwKfj6ybt08zrsNfnJszlSFKEp+9CIgj0OuIEau6Lu7oHFn0WLU2l43PQVj68QUBZF3ZZAM= X-Received: by 2002:a05:660c:128c:: with SMTP id s12mr1310002ita.145.1547532766301; Mon, 14 Jan 2019 22:12:46 -0800 (PST) MIME-Version: 1.0 References: <1547084679-29597-1-git-send-email-mw@semihalf.com> <1547084679-29597-8-git-send-email-mw@semihalf.com> <20190114231203.vkbl2qlh245p4xhc@bivouac.eciton.net> In-Reply-To: <20190114231203.vkbl2qlh245p4xhc@bivouac.eciton.net> From: Marcin Wojtas Date: Tue, 15 Jan 2019 07:12:37 +0100 Message-ID: To: Leif Lindholm Cc: edk2-devel-01 , Ard Biesheuvel , nadavh@marvell.com, "jsd@semihalf.com" , Grzegorz Jaszczyk , Kostya Porotchkin , jinghua Subject: Re: [platforms: PATCH v2 07/12] Marvell/Protocol: Introduce GPIO helper header 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: Tue, 15 Jan 2019 06:12:47 -0000 X-List-Received-Date: Tue, 15 Jan 2019 06:12:47 -0000 X-List-Received-Date: Tue, 15 Jan 2019 06:12:47 -0000 X-List-Received-Date: Tue, 15 Jan 2019 06:12:47 -0000 X-List-Received-Date: Tue, 15 Jan 2019 06:12:47 -0000 X-List-Received-Date: Tue, 15 Jan 2019 06:12:47 -0000 X-List-Received-Date: Tue, 15 Jan 2019 06:12:47 -0000 X-List-Received-Date: Tue, 15 Jan 2019 06:12:47 -0000 X-List-Received-Date: Tue, 15 Jan 2019 06:12:47 -0000 X-List-Received-Date: Tue, 15 Jan 2019 06:12:47 -0000 X-List-Received-Date: Tue, 15 Jan 2019 06:12:47 -0000 X-List-Received-Date: Tue, 15 Jan 2019 06:12:47 -0000 X-List-Received-Date: Tue, 15 Jan 2019 06:12:47 -0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Leif, wt., 15 sty 2019 o 00:12 Leif Lindholm napisa=C5= =82(a): > > On Thu, Jan 10, 2019 at 02:44:34AM +0100, Marcin Wojtas wrote: > > From: jinghua > > > > 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 > > --- > > 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/Marvel= l/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 a= vailable > > +* 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" BASI= S, > > +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS O= R IMPLIED. > > +* > > +**/ > > +#ifndef __MV_GPIO_PROTOCOL_H__ > > +#define __MV_GPIO_PROTOCOL_H__ > > + > > +#include > > + > > +#include > > +#include > > +#include > > +#include > > + > > +#include > > + > > +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/con= tent/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 =3D (MV_GPIO_DEVICE_PATH *)DevicePath; > > + if (GpioDevicePath->GpioDriverType !=3D GpioDriverType) { > > + DevicePath =3D NextDevicePathNode (DevicePath); > > + continue; > > + } > > + > > + /* > > + * Open GpioProtocol. With EFI_OPEN_PROTOCOL_GET_PROTOCOL attribut= e > > + * 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. > > + */ > > +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 =3D 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 =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", __FUNCTI= ON__)); > > + 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; > > +} > > + > > +#endif // __MV_GPIO_PROTOCOL_H__ > > -- > > 2.7.4 > >