From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:400c:c0c::241; helo=mail-wr0-x241.google.com; envelope-from=leif.lindholm@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wr0-x241.google.com (mail-wr0-x241.google.com [IPv6:2a00:1450:400c:c0c::241]) (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 2309D21E256AD for ; Thu, 25 Jan 2018 04:49:09 -0800 (PST) Received: by mail-wr0-x241.google.com with SMTP id v31so2186609wrc.11 for ; Thu, 25 Jan 2018 04:54:38 -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=Q0/sFSHtesVqyKo1USkcidV/6HaEoHmCVprGQiKKSZU=; b=i+XVrKY/0vz1Hei0ggaBam0Z3/zy7I9duulTV3nGC0dsZnBWjCCRFtbof+qKURTl0U vdMvpxOPtZIcGGa+U62tCmAcB2AuZlDcfXSYYeU8LanJT8s802tlsldeoaPrHH1PltzF dLoKvqYBqPtiUiGghpGxH323XsBm3zb9lHp4Q= 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=Q0/sFSHtesVqyKo1USkcidV/6HaEoHmCVprGQiKKSZU=; b=N4CKdFocdibaWevVQywrCY3QNKjyw1rZfDzaPlZ73LdpWQOFdFKpaN0TlI9/1PlWA9 AlFSs9QN6M7gpM/rX4zmXVKoKB4qWrxMSrpX/vy1MrrH2WQd+6AZM9lSycF+Mh81ahqP s8AAx/OMD6MqrOoY6KRgNe5IvyZVlyyulEn4bkVo9wwuACkzRYO93DdK8JPzNnaDYhTc ZVTz2oBDQFeozrDx3wTYK0u6Dil03Abpr29XQzyF6MT9aNMDPShu4J1nJgRfXmizIUm0 FjxkPO0iC4DgJfsCm2X3IHgyLQZd+B+3EzJFgJB3JQ5LnNhWhXnOB1E1r7fwXS9xd9QE BFxA== X-Gm-Message-State: AKwxyterttGKFHTnc40OtO1AtdqU4p1qvHh3J8IDmWcTrL4QTbgp9MaQ hPU1krmg5k2ztJBRKErgMJWS5A== X-Google-Smtp-Source: AH8x2260o9rN5CeQAtM6wpcc5UzlTnGtdFO8YG2Vw0NCQJs/80gNgrMdeATK+xiTNgvMGUUjzJG4Rg== X-Received: by 10.223.160.23 with SMTP id k23mr8969994wrk.116.1516884877058; Thu, 25 Jan 2018 04:54:37 -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 k40sm4822775wre.71.2018.01.25.04.54.35 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 25 Jan 2018 04:54:35 -0800 (PST) Date: Thu, 25 Jan 2018 12:54:34 +0000 From: Leif Lindholm To: Ard Biesheuvel Cc: edk2-devel@lists.01.org Message-ID: <20180125125434.553ff6xamfpnr6bd@bivouac.eciton.net> References: <20180125122736.5427-1-ard.biesheuvel@linaro.org> <20180125122736.5427-4-ard.biesheuvel@linaro.org> MIME-Version: 1.0 In-Reply-To: <20180125122736.5427-4-ard.biesheuvel@linaro.org> User-Agent: NeoMutt/20170113 (1.7.2) Subject: Re: [PATCH edk2-platforms 3/8] Silicon/NXP/Pcf8563RealTimeClockLib: avoid driver binding protocol X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Jan 2018 12:49:09 -0000 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Thu, Jan 25, 2018 at 12:27:31PM +0000, Ard Biesheuvel wrote: > Instead of registering a notification callback on the driver binding > protocol, and attempting to connect our I2C master handle each time > a new driver is registered, switch to the more obvious approach of > registering a notification callback on the I2C master protocol directly. > > The original code was written under the assumption that it would make > the RTC available at an earlier time, but given that all handles that > are created during the execution of a driver entry point are connected > by DXE core right away (i.e., before StartImage() returns), this is not > really necessary, and in fact, may result in the driver already having > been connected by the time we attempt to connect it. > > Note that it is now up to the platform to ensure that ConnectController() > is called for the handle if DXE core does not call it by itself, or does > call it but at a time when no I2C master protocol driver is available > yet. Presumably the platforms in edk2-platforms using this library already follow these constraints? If so: Reviewed-by: Leif Lindholm > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Ard Biesheuvel > --- > Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.c | 31 ++++++++------------ > Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.inf | 1 - > 2 files changed, 13 insertions(+), 19 deletions(-) > > diff --git a/Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.c b/Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.c > index 6bc4aef28849..fb58e1feb424 100644 > --- a/Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.c > +++ b/Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.c > @@ -41,7 +41,7 @@ > #define EPOCH_BASE 2000 > > STATIC EFI_HANDLE mI2cMasterHandle; > -STATIC VOID *mDriverEventRegistration; > +STATIC VOID *mI2cMasterEventRegistration; > STATIC EFI_I2C_MASTER_PROTOCOL *mI2cMaster; > STATIC EFI_EVENT mRtcVirtualAddrChangeEvent; > > @@ -263,12 +263,12 @@ LibSetWakeupTime ( > > STATIC > VOID > -DriverRegistrationEvent ( > +I2cMasterRegistrationEvent ( > IN EFI_EVENT Event, > IN VOID *Context > ) > { > - EFI_HANDLE Handle[2]; > + EFI_HANDLE Handle; > UINTN BufferSize; > EFI_STATUS Status; > EFI_I2C_MASTER_PROTOCOL *I2cMaster; > @@ -280,10 +280,10 @@ DriverRegistrationEvent ( > do { > BufferSize = sizeof (EFI_HANDLE); > Status = gBS->LocateHandle (ByRegisterNotify, > - &gEfiDriverBindingProtocolGuid, > - mDriverEventRegistration, > + &gEfiI2cMasterProtocolGuid, > + mI2cMasterEventRegistration, > &BufferSize, > - Handle); > + &Handle); > if (EFI_ERROR (Status)) { > if (Status != EFI_NOT_FOUND) { > DEBUG ((DEBUG_WARN, "%a: gBS->LocateHandle () returned %r\n", > @@ -292,12 +292,7 @@ DriverRegistrationEvent ( > break; > } > > - // > - // Check if we can connect our handle to this driver. > - // > - Handle[1] = NULL; > - Status = gBS->ConnectController (mI2cMasterHandle, Handle, NULL, FALSE); > - if (EFI_ERROR (Status)) { > + if (Handle != mI2cMasterHandle) { > continue; > } > > @@ -378,16 +373,16 @@ LibRtcInitialize ( > ASSERT_EFI_ERROR (Status); > > // > - // Register a protocol registration notification callback on the driver > - // binding protocol so we can attempt to connect our I2C master to it > - // as soon as it appears. > + // Register a protocol registration notification callback on the I2C master > + // protocol. This will notify us even if the protocol instance we are looking > + // for has already been installed. > // > EfiCreateProtocolNotifyEvent ( > - &gEfiDriverBindingProtocolGuid, > + &gEfiI2cMasterProtocolGuid, > TPL_CALLBACK, > - DriverRegistrationEvent, > + I2cMasterRegistrationEvent, > NULL, > - &mDriverEventRegistration); > + &mI2cMasterEventRegistration); > > // > // Register for the virtual address change event > diff --git a/Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.inf b/Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.inf > index 1a9a6f6c9cf3..e232902c6b5d 100644 > --- a/Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.inf > +++ b/Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.inf > @@ -40,7 +40,6 @@ [Guids] > gEfiEventVirtualAddressChangeGuid > > [Protocols] > - gEfiDriverBindingProtocolGuid ## CONSUMES > gEfiI2cMasterProtocolGuid ## CONSUMES > gPcf8563RealTimeClockLibI2cMasterProtocolGuid ## CONSUMES > > -- > 2.11.0 >