From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:4864:20::443; helo=mail-wr1-x443.google.com; envelope-from=leif.lindholm@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) (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 8CF7A211B5A5E for ; Mon, 14 Jan 2019 15:12:07 -0800 (PST) Received: by mail-wr1-x443.google.com with SMTP id l9so807346wrt.13 for ; Mon, 14 Jan 2019 15:12:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=n5VpdFFrh1TcQTdNP6IazaisukYpiHKkQ56tqT779NU=; b=EYmyBonoZD14bH296tHHFyjHVMK8fszIrV8Mp/ru44uwg1R1w0MkvHxgvnMZGxigDq 4flncrhZ6HP+UM3xeXOym51eFY6zwsZMsu91dm40y0prPdswEYDPZykUL9ZdyKOGYJS7 MpgojMykokqLf8GD/MHer4qMZFrL4qIosrLg0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=n5VpdFFrh1TcQTdNP6IazaisukYpiHKkQ56tqT779NU=; b=NWUI8bwZGPdS5+H888j/tGdW+4HWqWnodpzu1B2I3HixnmfV4dPiCHSLYcLBVncSmN zLvDdnWjjMkAMmXf8U1H0V5gVAOSRclunZlS63qacdwBjOr8K1Iq2W6RIKwTPADfjDOz S4dCeZnTdEJTtNV6nRUnA6sWfaxB/V93Pydk2vXJbiCz6OevHLwPls4KGyxiWi35B/vl og33TncurkikESDb3qmsMqbpRHkkPf0xPFUZWVcAmSEZ0xTRy47N9brutFUl74PvJVyf I5GShpJk7ODPemfvOFUaYFV+55Trw157j6cGaO/81HmJIvAiJ6IS0T1ZjUlT+/+E29rp tYnA== X-Gm-Message-State: AJcUukcIXVM4RedNDYnIyohKILzJzzxB2hEa8wZrKqi0wMQWDEgaVfvm SY+ywqDwaPz7h7i18vC71W75vw== X-Google-Smtp-Source: ALg8bN5aUw2v4yFcBajHfndZHLPgyLYTAZ6F5CWt+WiuopiHZCUb46AL+ID2L2qDAEEARL+VuvYoVg== X-Received: by 2002:adf:e891:: with SMTP id d17mr654194wrm.140.1547507525951; Mon, 14 Jan 2019 15:12:05 -0800 (PST) Received: from bivouac.eciton.net (bivouac.eciton.net. [2a00:1098:0:86:1000:23:0:2]) by smtp.gmail.com with ESMTPSA id c14sm25750941wme.13.2019.01.14.15.12.05 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 14 Jan 2019 15:12:05 -0800 (PST) Date: Mon, 14 Jan 2019 23:12:03 +0000 From: Leif Lindholm To: Marcin Wojtas Cc: edk2-devel@lists.01.org, ard.biesheuvel@linaro.org, nadavh@marvell.com, jsd@semihalf.com, jaz@semihalf.com, kostap@marvell.com, jinghua Message-ID: <20190114231203.vkbl2qlh245p4xhc@bivouac.eciton.net> References: <1547084679-29597-1-git-send-email-mw@semihalf.com> <1547084679-29597-8-git-send-email-mw@semihalf.com> MIME-Version: 1.0 In-Reply-To: <1547084679-29597-8-git-send-email-mw@semihalf.com> User-Agent: NeoMutt/20170113 (1.7.2) 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: Mon, 14 Jan 2019 23:12:07 -0000 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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/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 > + > +#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/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. / 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 >