public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* Problem in EFI_BOOT_SERVICES.OpenProtocol()
@ 2017-06-01 16:46 Amit kumar
  2017-06-01 16:58 ` Andrew Fish
  0 siblings, 1 reply; 8+ messages in thread
From: Amit kumar @ 2017-06-01 16:46 UTC (permalink / raw)
  To: edk2-devel@lists.01.org

Hi,
I am trying to open PciIoProtocol and facing some issue.

below is the code

EFI_PCI_IO_PROTOCOL *PciIo=NULL;
EFI_STATUS                      Status;

Status = gBS->OpenProtocol (
                  Controller,
                  &gEfiPciIoProtocolGuid,
                  (VOID **) &PciIo,
                  This->DriverBindingHandle,
                  Controller,
                  EFI_OPEN_PROTOCOL_BY_DRIVER
                  );

it returns Status = EFI_ALREADY_STARTED, but PciIo is not NULL.
Is it not supposed to return PciIo as NULL ?
As per UEFI 2.6 Spec Section 6.3 page 182. 

There are a number of reasons that this function call can return an error. If an error is returned, then
AgentHandle, ControllerHandle, and Attributes are not added to the list of agents
consuming the protocol interface specified by Handle and Protocol, and Interface is
returned unmodified.

Thanks And Regards
Amit 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Problem in EFI_BOOT_SERVICES.OpenProtocol()
  2017-06-01 16:46 Problem in EFI_BOOT_SERVICES.OpenProtocol() Amit kumar
@ 2017-06-01 16:58 ` Andrew Fish
  2017-06-01 17:13   ` Amit kumar
  0 siblings, 1 reply; 8+ messages in thread
From: Andrew Fish @ 2017-06-01 16:58 UTC (permalink / raw)
  To: Amit kumar; +Cc: edk2-devel@lists.01.org


> On Jun 1, 2017, at 9:46 AM, Amit kumar <akamit91@hotmail.com> wrote:
> 
> Hi,
> I am trying to open PciIoProtocol and facing some issue.
> 
> below is the code
> 
> EFI_PCI_IO_PROTOCOL *PciIo=NULL;
> EFI_STATUS                      Status;
> 
> Status = gBS->OpenProtocol (
>                  Controller,
>                  &gEfiPciIoProtocolGuid,
>                  (VOID **) &PciIo,
>                  This->DriverBindingHandle,
>                  Controller,
>                  EFI_OPEN_PROTOCOL_BY_DRIVER
>                  );
> 
> it returns Status = EFI_ALREADY_STARTED, but PciIo is not NULL.
> Is it not supposed to return PciIo as NULL ?
> As per UEFI 2.6 Spec Section 6.3 page 182. 
> 

Amit,

Look at the Status Codes Returned section at the end of that section. 

Attributes is BY_DRIVER and there is an item on the open list with an attribute of BY_DRIVER whose agent handle is the same as AgentHandle.

Attributes is BY_DRIVER|EXCLUSIVE and there is an item on the open list with an attribute of BY_DRIVER|EXCLUSIVE whose agent handle is the same as AgentHandle.

Thanks,

Andrew Fish

> There are a number of reasons that this function call can return an error. If an error is returned, then
> AgentHandle, ControllerHandle, and Attributes are not added to the list of agents
> consuming the protocol interface specified by Handle and Protocol, and Interface is
> returned unmodified.
> 
> Thanks And Regards
> Amit 
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Problem in EFI_BOOT_SERVICES.OpenProtocol()
  2017-06-01 16:58 ` Andrew Fish
@ 2017-06-01 17:13   ` Amit kumar
  2017-06-01 17:29     ` Andrew Fish
  0 siblings, 1 reply; 8+ messages in thread
From: Amit kumar @ 2017-06-01 17:13 UTC (permalink / raw)
  To: Andrew Fish; +Cc: edk2-devel@lists.01.org

Hello Andrew,

As per UEFI Spec EFI_ALREADY_STARTED is treated as error code, thus PciIo (The Interface 3rd parameter ) should remain NULL.
But after    OpenProtocol call even though Status = EFI_ALREADY_STARTED PciIo (The Interface 3rd parameter ) is getting modified and it not NULL anymore.
Is this not a problem ?

Status = gBS->OpenProtocol (
                  Controller,
                  &gEfiPciIoProtocolGuid,
                  (VOID **) &PciIo,
                  This->DriverBindingHandle,
                  Controller,
                  EFI_OPEN_PROTOCOL_BY_DRIVER
                  );

________________________________
From: afish@apple.com <afish@apple.com> on behalf of Andrew Fish <afish@apple.com>
Sent: Thursday, June 1, 2017 10:28:16 PM
To: Amit kumar
Cc: edk2-devel@lists.01.org
Subject: Re: [edk2] Problem in EFI_BOOT_SERVICES.OpenProtocol()


> On Jun 1, 2017, at 9:46 AM, Amit kumar <akamit91@hotmail.com> wrote:
>
> Hi,
> I am trying to open PciIoProtocol and facing some issue.
>
> below is the code
>
> EFI_PCI_IO_PROTOCOL *PciIo=NULL;
> EFI_STATUS                      Status;
>
> Status = gBS->OpenProtocol (
>                  Controller,
>                  &gEfiPciIoProtocolGuid,
>                  (VOID **) &PciIo,
>                  This->DriverBindingHandle,
>                  Controller,
>                  EFI_OPEN_PROTOCOL_BY_DRIVER
>                  );
>
> it returns Status = EFI_ALREADY_STARTED, but PciIo is not NULL.
> Is it not supposed to return PciIo as NULL ?
> As per UEFI 2.6 Spec Section 6.3 page 182.
>

Amit,

Look at the Status Codes Returned section at the end of that section.

Attributes is BY_DRIVER and there is an item on the open list with an attribute of BY_DRIVER whose agent handle is the same as AgentHandle.

Attributes is BY_DRIVER|EXCLUSIVE and there is an item on the open list with an attribute of BY_DRIVER|EXCLUSIVE whose agent handle is the same as AgentHandle.

Thanks,

Andrew Fish

> There are a number of reasons that this function call can return an error. If an error is returned, then
> AgentHandle, ControllerHandle, and Attributes are not added to the list of agents
> consuming the protocol interface specified by Handle and Protocol, and Interface is
> returned unmodified.
>
> Thanks And Regards
> Amit
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Problem in EFI_BOOT_SERVICES.OpenProtocol()
  2017-06-01 17:13   ` Amit kumar
@ 2017-06-01 17:29     ` Andrew Fish
  2017-06-01 17:37       ` Amit kumar
  0 siblings, 1 reply; 8+ messages in thread
From: Andrew Fish @ 2017-06-01 17:29 UTC (permalink / raw)
  To: Amit kumar; +Cc: edk2-devel@lists.01.org


> On Jun 1, 2017, at 10:13 AM, Amit kumar <akamit91@hotmail.com> wrote:
> 
> Hello Andrew,
> 
> As per UEFI Spec EFI_ALREADY_STARTED is treated as error code, thus PciIo (The Interface 3rd parameter ) should remain NULL.
> But after    OpenProtocol call even though Status = EFI_ALREADY_STARTED PciIo (The Interface 3rd parameter ) is getting modified and it not NULL anymore.
> Is this not a problem ?
> 

Amit,

I agree it looks like the code will fill in the Interface and return EFI_ALREADY_STARTED. And that does seem to conflict with the section of the spec you quote. Good catch. 

https://github.com/tianocore/edk2/blob/master/MdeModulePkg/Core/Dxe/Hand/Handle.c#L1097
  //
  // This is the protocol interface entry for this protocol
  //
  if (Attributes != EFI_OPEN_PROTOCOL_TEST_PROTOCOL) {
    *Interface = Prot->Interface;
  }
  Status = EFI_SUCCESS;

  ByDriver        = FALSE;
  Exclusive       = FALSE;
  for ( Link = Prot->OpenList.ForwardLink; Link != &Prot->OpenList; Link = Link->ForwardLink) {
    OpenData = CR (Link, OPEN_PROTOCOL_DATA, Link, OPEN_PROTOCOL_DATA_SIGNATURE);
    ExactMatch =  (BOOLEAN)((OpenData->AgentHandle == ImageHandle) &&
                            (OpenData->Attributes == Attributes)  &&
                            (OpenData->ControllerHandle == ControllerHandle));
    if ((OpenData->Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) != 0) {
      ByDriver = TRUE;
      if (ExactMatch) {
        Status = EFI_ALREADY_STARTED;
        goto Done;
      }
    }
    if ((OpenData->Attributes & EFI_OPEN_PROTOCOL_EXCLUSIVE) != 0) {
      Exclusive = TRUE;
    } else if (ExactMatch) {
      OpenData->OpenCount++;
      Status = EFI_SUCCESS;
      goto Done;
    }
  }

Thanks,

Andrew Fish

> Status = gBS->OpenProtocol (
>                  Controller,
>                  &gEfiPciIoProtocolGuid,
>                  (VOID **) &PciIo,
>                  This->DriverBindingHandle,
>                  Controller,
>                  EFI_OPEN_PROTOCOL_BY_DRIVER
>                  );
> 
> ________________________________
> From: afish@apple.com <afish@apple.com> on behalf of Andrew Fish <afish@apple.com>
> Sent: Thursday, June 1, 2017 10:28:16 PM
> To: Amit kumar
> Cc: edk2-devel@lists.01.org
> Subject: Re: [edk2] Problem in EFI_BOOT_SERVICES.OpenProtocol()
> 
> 
>> On Jun 1, 2017, at 9:46 AM, Amit kumar <akamit91@hotmail.com> wrote:
>> 
>> Hi,
>> I am trying to open PciIoProtocol and facing some issue.
>> 
>> below is the code
>> 
>> EFI_PCI_IO_PROTOCOL *PciIo=NULL;
>> EFI_STATUS                      Status;
>> 
>> Status = gBS->OpenProtocol (
>>                 Controller,
>>                 &gEfiPciIoProtocolGuid,
>>                 (VOID **) &PciIo,
>>                 This->DriverBindingHandle,
>>                 Controller,
>>                 EFI_OPEN_PROTOCOL_BY_DRIVER
>>                 );
>> 
>> it returns Status = EFI_ALREADY_STARTED, but PciIo is not NULL.
>> Is it not supposed to return PciIo as NULL ?
>> As per UEFI 2.6 Spec Section 6.3 page 182.
>> 
> 
> Amit,
> 
> Look at the Status Codes Returned section at the end of that section.
> 
> Attributes is BY_DRIVER and there is an item on the open list with an attribute of BY_DRIVER whose agent handle is the same as AgentHandle.
> 
> Attributes is BY_DRIVER|EXCLUSIVE and there is an item on the open list with an attribute of BY_DRIVER|EXCLUSIVE whose agent handle is the same as AgentHandle.
> 
> Thanks,
> 
> Andrew Fish
> 
>> There are a number of reasons that this function call can return an error. If an error is returned, then
>> AgentHandle, ControllerHandle, and Attributes are not added to the list of agents
>> consuming the protocol interface specified by Handle and Protocol, and Interface is
>> returned unmodified.
>> 
>> Thanks And Regards
>> Amit
>> _______________________________________________
>> edk2-devel mailing list
>> edk2-devel@lists.01.org
>> https://lists.01.org/mailman/listinfo/edk2-devel
> 
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Problem in EFI_BOOT_SERVICES.OpenProtocol()
  2017-06-01 17:29     ` Andrew Fish
@ 2017-06-01 17:37       ` Amit kumar
  2017-06-01 17:38         ` Andrew Fish
  0 siblings, 1 reply; 8+ messages in thread
From: Amit kumar @ 2017-06-01 17:37 UTC (permalink / raw)
  To: Andrew Fish; +Cc: edk2-devel@lists.01.org

Hello Andrew,


Thanks for quick reply and acknowledging my query.


Amit

________________________________
From: afish@apple.com <afish@apple.com> on behalf of Andrew Fish <afish@apple.com>
Sent: Thursday, June 1, 2017 10:59:03 PM
To: Amit kumar
Cc: edk2-devel@lists.01.org
Subject: Re: [edk2] Problem in EFI_BOOT_SERVICES.OpenProtocol()


> On Jun 1, 2017, at 10:13 AM, Amit kumar <akamit91@hotmail.com> wrote:
>
> Hello Andrew,
>
> As per UEFI Spec EFI_ALREADY_STARTED is treated as error code, thus PciIo (The Interface 3rd parameter ) should remain NULL.
> But after    OpenProtocol call even though Status = EFI_ALREADY_STARTED PciIo (The Interface 3rd parameter ) is getting modified and it not NULL anymore.
> Is this not a problem ?
>

Amit,

I agree it looks like the code will fill in the Interface and return EFI_ALREADY_STARTED. And that does seem to conflict with the section of the spec you quote. Good catch.

https://github.com/tianocore/edk2/blob/master/MdeModulePkg/Core/Dxe/Hand/Handle.c#L1097
  //
  // This is the protocol interface entry for this protocol
  //
  if (Attributes != EFI_OPEN_PROTOCOL_TEST_PROTOCOL) {
    *Interface = Prot->Interface;
  }
  Status = EFI_SUCCESS;

  ByDriver        = FALSE;
  Exclusive       = FALSE;
  for ( Link = Prot->OpenList.ForwardLink; Link != &Prot->OpenList; Link = Link->ForwardLink) {
    OpenData = CR (Link, OPEN_PROTOCOL_DATA, Link, OPEN_PROTOCOL_DATA_SIGNATURE);
    ExactMatch =  (BOOLEAN)((OpenData->AgentHandle == ImageHandle) &&
                            (OpenData->Attributes == Attributes)  &&
                            (OpenData->ControllerHandle == ControllerHandle));
    if ((OpenData->Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) != 0) {
      ByDriver = TRUE;
      if (ExactMatch) {
        Status = EFI_ALREADY_STARTED;
        goto Done;
      }
    }
    if ((OpenData->Attributes & EFI_OPEN_PROTOCOL_EXCLUSIVE) != 0) {
      Exclusive = TRUE;
    } else if (ExactMatch) {
      OpenData->OpenCount++;
      Status = EFI_SUCCESS;
      goto Done;
    }
  }

Thanks,

Andrew Fish

> Status = gBS->OpenProtocol (
>                  Controller,
>                  &gEfiPciIoProtocolGuid,
>                  (VOID **) &PciIo,
>                  This->DriverBindingHandle,
>                  Controller,
>                  EFI_OPEN_PROTOCOL_BY_DRIVER
>                  );
>
> ________________________________
> From: afish@apple.com <afish@apple.com> on behalf of Andrew Fish <afish@apple.com>
> Sent: Thursday, June 1, 2017 10:28:16 PM
> To: Amit kumar
> Cc: edk2-devel@lists.01.org
> Subject: Re: [edk2] Problem in EFI_BOOT_SERVICES.OpenProtocol()
>
>
>> On Jun 1, 2017, at 9:46 AM, Amit kumar <akamit91@hotmail.com> wrote:
>>
>> Hi,
>> I am trying to open PciIoProtocol and facing some issue.
>>
>> below is the code
>>
>> EFI_PCI_IO_PROTOCOL *PciIo=NULL;
>> EFI_STATUS                      Status;
>>
>> Status = gBS->OpenProtocol (
>>                 Controller,
>>                 &gEfiPciIoProtocolGuid,
>>                 (VOID **) &PciIo,
>>                 This->DriverBindingHandle,
>>                 Controller,
>>                 EFI_OPEN_PROTOCOL_BY_DRIVER
>>                 );
>>
>> it returns Status = EFI_ALREADY_STARTED, but PciIo is not NULL.
>> Is it not supposed to return PciIo as NULL ?
>> As per UEFI 2.6 Spec Section 6.3 page 182.
>>
>
> Amit,
>
> Look at the Status Codes Returned section at the end of that section.
>
> Attributes is BY_DRIVER and there is an item on the open list with an attribute of BY_DRIVER whose agent handle is the same as AgentHandle.
>
> Attributes is BY_DRIVER|EXCLUSIVE and there is an item on the open list with an attribute of BY_DRIVER|EXCLUSIVE whose agent handle is the same as AgentHandle.
>
> Thanks,
>
> Andrew Fish
>
>> There are a number of reasons that this function call can return an error. If an error is returned, then
>> AgentHandle, ControllerHandle, and Attributes are not added to the list of agents
>> consuming the protocol interface specified by Handle and Protocol, and Interface is
>> returned unmodified.
>>
>> Thanks And Regards
>> Amit
>> _______________________________________________
>> edk2-devel mailing list
>> edk2-devel@lists.01.org
>> https://lists.01.org/mailman/listinfo/edk2-devel
>
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Problem in EFI_BOOT_SERVICES.OpenProtocol()
  2017-06-01 17:37       ` Amit kumar
@ 2017-06-01 17:38         ` Andrew Fish
  2017-06-01 17:40           ` Amit kumar
  0 siblings, 1 reply; 8+ messages in thread
From: Andrew Fish @ 2017-06-01 17:38 UTC (permalink / raw)
  To: Amit kumar; +Cc: edk2-devel@lists.01.org


> On Jun 1, 2017, at 10:37 AM, Amit kumar <akamit91@hotmail.com> wrote:
> 
> Hello Andrew,
> 
> Thanks for quick reply and acknowledging my query.
> 

Please file a bugzilla against the code. 

Thanks,

Andrew Fish

> Amit   
> From: afish@apple.com <mailto:afish@apple.com> <afish@apple.com <mailto:afish@apple.com>> on behalf of Andrew Fish <afish@apple.com <mailto:afish@apple.com>>
> Sent: Thursday, June 1, 2017 10:59:03 PM
> To: Amit kumar
> Cc: edk2-devel@lists.01.org <mailto:edk2-devel@lists.01.org>
> Subject: Re: [edk2] Problem in EFI_BOOT_SERVICES.OpenProtocol()
>  
> 
> > On Jun 1, 2017, at 10:13 AM, Amit kumar <akamit91@hotmail.com <mailto:akamit91@hotmail.com>> wrote:
> > 
> > Hello Andrew,
> > 
> > As per UEFI Spec EFI_ALREADY_STARTED is treated as error code, thus PciIo (The Interface 3rd parameter ) should remain NULL.
> > But after    OpenProtocol call even though Status = EFI_ALREADY_STARTED PciIo (The Interface 3rd parameter ) is getting modified and it not NULL anymore.
> > Is this not a problem ?
> > 
> 
> Amit,
> 
> I agree it looks like the code will fill in the Interface and return EFI_ALREADY_STARTED. And that does seem to conflict with the section of the spec you quote. Good catch. 
> 
> https://github.com/tianocore/edk2/blob/master/MdeModulePkg/Core/Dxe/Hand/Handle.c#L1097 <https://github.com/tianocore/edk2/blob/master/MdeModulePkg/Core/Dxe/Hand/Handle.c#L1097>
>   //
>   // This is the protocol interface entry for this protocol
>   //
>   if (Attributes != EFI_OPEN_PROTOCOL_TEST_PROTOCOL) {
>     *Interface = Prot->Interface;
>   }
>   Status = EFI_SUCCESS;
> 
>   ByDriver        = FALSE;
>   Exclusive       = FALSE;
>   for ( Link = Prot->OpenList.ForwardLink; Link != &Prot->OpenList; Link = Link->ForwardLink) {
>     OpenData = CR (Link, OPEN_PROTOCOL_DATA, Link, OPEN_PROTOCOL_DATA_SIGNATURE);
>     ExactMatch =  (BOOLEAN)((OpenData->AgentHandle == ImageHandle) &&
>                             (OpenData->Attributes == Attributes)  &&
>                             (OpenData->ControllerHandle == ControllerHandle));
>     if ((OpenData->Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) != 0) {
>       ByDriver = TRUE;
>       if (ExactMatch) {
>         Status = EFI_ALREADY_STARTED;
>         goto Done;
>       }
>     }
>     if ((OpenData->Attributes & EFI_OPEN_PROTOCOL_EXCLUSIVE) != 0) {
>       Exclusive = TRUE;
>     } else if (ExactMatch) {
>       OpenData->OpenCount++;
>       Status = EFI_SUCCESS;
>       goto Done;
>     }
>   }
> 
> Thanks,
> 
> Andrew Fish
> 
> > Status = gBS->OpenProtocol (
> >                  Controller,
> >                  &gEfiPciIoProtocolGuid,
> >                  (VOID **) &PciIo,
> >                  This->DriverBindingHandle,
> >                  Controller,
> >                  EFI_OPEN_PROTOCOL_BY_DRIVER
> >                  );
> > 
> > ________________________________
> > From: afish@apple.com <mailto:afish@apple.com> <afish@apple.com <mailto:afish@apple.com>> on behalf of Andrew Fish <afish@apple.com <mailto:afish@apple.com>>
> > Sent: Thursday, June 1, 2017 10:28:16 PM
> > To: Amit kumar
> > Cc: edk2-devel@lists.01.org <mailto:edk2-devel@lists.01.org>
> > Subject: Re: [edk2] Problem in EFI_BOOT_SERVICES.OpenProtocol()
> > 
> > 
> >> On Jun 1, 2017, at 9:46 AM, Amit kumar <akamit91@hotmail.com <mailto:akamit91@hotmail.com>> wrote:
> >> 
> >> Hi,
> >> I am trying to open PciIoProtocol and facing some issue.
> >> 
> >> below is the code
> >> 
> >> EFI_PCI_IO_PROTOCOL *PciIo=NULL;
> >> EFI_STATUS                      Status;
> >> 
> >> Status = gBS->OpenProtocol (
> >>                 Controller,
> >>                 &gEfiPciIoProtocolGuid,
> >>                 (VOID **) &PciIo,
> >>                 This->DriverBindingHandle,
> >>                 Controller,
> >>                 EFI_OPEN_PROTOCOL_BY_DRIVER
> >>                 );
> >> 
> >> it returns Status = EFI_ALREADY_STARTED, but PciIo is not NULL.
> >> Is it not supposed to return PciIo as NULL ?
> >> As per UEFI 2.6 Spec Section 6.3 page 182.
> >> 
> > 
> > Amit,
> > 
> > Look at the Status Codes Returned section at the end of that section.
> > 
> > Attributes is BY_DRIVER and there is an item on the open list with an attribute of BY_DRIVER whose agent handle is the same as AgentHandle.
> > 
> > Attributes is BY_DRIVER|EXCLUSIVE and there is an item on the open list with an attribute of BY_DRIVER|EXCLUSIVE whose agent handle is the same as AgentHandle.
> > 
> > Thanks,
> > 
> > Andrew Fish
> > 
> >> There are a number of reasons that this function call can return an error. If an error is returned, then
> >> AgentHandle, ControllerHandle, and Attributes are not added to the list of agents
> >> consuming the protocol interface specified by Handle and Protocol, and Interface is
> >> returned unmodified.
> >> 
> >> Thanks And Regards
> >> Amit
> >> _______________________________________________
> >> edk2-devel mailing list
> >> edk2-devel@lists.01.org <mailto:edk2-devel@lists.01.org>
> >> https://lists.01.org/mailman/listinfo/edk2-devel <https://lists.01.org/mailman/listinfo/edk2-devel>
> > 
> > _______________________________________________
> > edk2-devel mailing list
> > edk2-devel@lists.01.org <mailto:edk2-devel@lists.01.org>
> > https://lists.01.org/mailman/listinfo/edk2-devel <https://lists.01.org/mailman/listinfo/edk2-devel>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Problem in EFI_BOOT_SERVICES.OpenProtocol()
  2017-06-01 17:38         ` Andrew Fish
@ 2017-06-01 17:40           ` Amit kumar
  2017-06-01 17:41             ` Andrew Fish
  0 siblings, 1 reply; 8+ messages in thread
From: Amit kumar @ 2017-06-01 17:40 UTC (permalink / raw)
  To: Andrew Fish; +Cc: edk2-devel@lists.01.org

Certainly i will do that.

Meanwhile can i submit the patch too ?

Amit

________________________________
From: afish@apple.com <afish@apple.com> on behalf of Andrew Fish <afish@apple.com>
Sent: Thursday, June 1, 2017 11:08:59 PM
To: Amit kumar
Cc: edk2-devel@lists.01.org
Subject: Re: [edk2] Problem in EFI_BOOT_SERVICES.OpenProtocol()


On Jun 1, 2017, at 10:37 AM, Amit kumar <akamit91@hotmail.com<mailto:akamit91@hotmail.com>> wrote:

Hello Andrew,

Thanks for quick reply and acknowledging my query.


Please file a bugzilla against the code.

Thanks,

Andrew Fish

Amit
________________________________
From: afish@apple.com<mailto:afish@apple.com> <afish@apple.com<mailto:afish@apple.com>> on behalf of Andrew Fish <afish@apple.com<mailto:afish@apple.com>>
Sent: Thursday, June 1, 2017 10:59:03 PM
To: Amit kumar
Cc: edk2-devel@lists.01.org<mailto:edk2-devel@lists.01.org>
Subject: Re: [edk2] Problem in EFI_BOOT_SERVICES.OpenProtocol()


> On Jun 1, 2017, at 10:13 AM, Amit kumar <akamit91@hotmail.com<mailto:akamit91@hotmail.com>> wrote:
>
> Hello Andrew,
>
> As per UEFI Spec EFI_ALREADY_STARTED is treated as error code, thus PciIo (The Interface 3rd parameter ) should remain NULL.
> But after    OpenProtocol call even though Status = EFI_ALREADY_STARTED PciIo (The Interface 3rd parameter ) is getting modified and it not NULL anymore.
> Is this not a problem ?
>

Amit,

I agree it looks like the code will fill in the Interface and return EFI_ALREADY_STARTED. And that does seem to conflict with the section of the spec you quote. Good catch.

https://github.com/tianocore/edk2/blob/master/MdeModulePkg/Core/Dxe/Hand/Handle.c#L1097
  //
  // This is the protocol interface entry for this protocol
  //
  if (Attributes != EFI_OPEN_PROTOCOL_TEST_PROTOCOL) {
    *Interface = Prot->Interface;
  }
  Status = EFI_SUCCESS;

  ByDriver        = FALSE;
  Exclusive       = FALSE;
  for ( Link = Prot->OpenList.ForwardLink; Link != &Prot->OpenList; Link = Link->ForwardLink) {
    OpenData = CR (Link, OPEN_PROTOCOL_DATA, Link, OPEN_PROTOCOL_DATA_SIGNATURE);
    ExactMatch =  (BOOLEAN)((OpenData->AgentHandle == ImageHandle) &&
                            (OpenData->Attributes == Attributes)  &&
                            (OpenData->ControllerHandle == ControllerHandle));
    if ((OpenData->Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) != 0) {
      ByDriver = TRUE;
      if (ExactMatch) {
        Status = EFI_ALREADY_STARTED;
        goto Done;
      }
    }
    if ((OpenData->Attributes & EFI_OPEN_PROTOCOL_EXCLUSIVE) != 0) {
      Exclusive = TRUE;
    } else if (ExactMatch) {
      OpenData->OpenCount++;
      Status = EFI_SUCCESS;
      goto Done;
    }
  }

Thanks,

Andrew Fish

> Status = gBS->OpenProtocol (
>                  Controller,
>                  &gEfiPciIoProtocolGuid,
>                  (VOID **) &PciIo,
>                  This->DriverBindingHandle,
>                  Controller,
>                  EFI_OPEN_PROTOCOL_BY_DRIVER
>                  );
>
> ________________________________
> From: afish@apple.com<mailto:afish@apple.com> <afish@apple.com<mailto:afish@apple.com>> on behalf of Andrew Fish <afish@apple.com<mailto:afish@apple.com>>
> Sent: Thursday, June 1, 2017 10:28:16 PM
> To: Amit kumar
> Cc: edk2-devel@lists.01.org<mailto:edk2-devel@lists.01.org>
> Subject: Re: [edk2] Problem in EFI_BOOT_SERVICES.OpenProtocol()
>
>
>> On Jun 1, 2017, at 9:46 AM, Amit kumar <akamit91@hotmail.com<mailto:akamit91@hotmail.com>> wrote:
>>
>> Hi,
>> I am trying to open PciIoProtocol and facing some issue.
>>
>> below is the code
>>
>> EFI_PCI_IO_PROTOCOL *PciIo=NULL;
>> EFI_STATUS                      Status;
>>
>> Status = gBS->OpenProtocol (
>>                 Controller,
>>                 &gEfiPciIoProtocolGuid,
>>                 (VOID **) &PciIo,
>>                 This->DriverBindingHandle,
>>                 Controller,
>>                 EFI_OPEN_PROTOCOL_BY_DRIVER
>>                 );
>>
>> it returns Status = EFI_ALREADY_STARTED, but PciIo is not NULL.
>> Is it not supposed to return PciIo as NULL ?
>> As per UEFI 2.6 Spec Section 6.3 page 182.
>>
>
> Amit,
>
> Look at the Status Codes Returned section at the end of that section.
>
> Attributes is BY_DRIVER and there is an item on the open list with an attribute of BY_DRIVER whose agent handle is the same as AgentHandle.
>
> Attributes is BY_DRIVER|EXCLUSIVE and there is an item on the open list with an attribute of BY_DRIVER|EXCLUSIVE whose agent handle is the same as AgentHandle.
>
> Thanks,
>
> Andrew Fish
>
>> There are a number of reasons that this function call can return an error. If an error is returned, then
>> AgentHandle, ControllerHandle, and Attributes are not added to the list of agents
>> consuming the protocol interface specified by Handle and Protocol, and Interface is
>> returned unmodified.
>>
>> Thanks And Regards
>> Amit
>> _______________________________________________
>> edk2-devel mailing list
>> edk2-devel@lists.01.org<mailto:edk2-devel@lists.01.org>
>> https://lists.01.org/mailman/listinfo/edk2-devel
>
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org<mailto:edk2-devel@lists.01.org>
> https://lists.01.org/mailman/listinfo/edk2-devel



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Problem in EFI_BOOT_SERVICES.OpenProtocol()
  2017-06-01 17:40           ` Amit kumar
@ 2017-06-01 17:41             ` Andrew Fish
  0 siblings, 0 replies; 8+ messages in thread
From: Andrew Fish @ 2017-06-01 17:41 UTC (permalink / raw)
  To: Amit kumar; +Cc: edk2-devel@lists.01.org


> On Jun 1, 2017, at 10:40 AM, Amit kumar <akamit91@hotmail.com> wrote:
> 
> Certainly i will do that.
> Meanwhile can i submit the patch too ?

Yes as long as you follow the process. 

Thanks,

Andrew Fish

> Amit
> From: afish@apple.com <mailto:afish@apple.com> <afish@apple.com <mailto:afish@apple.com>> on behalf of Andrew Fish <afish@apple.com <mailto:afish@apple.com>>
> Sent: Thursday, June 1, 2017 11:08:59 PM
> To: Amit kumar
> Cc: edk2-devel@lists.01.org <mailto:edk2-devel@lists.01.org>
> Subject: Re: [edk2] Problem in EFI_BOOT_SERVICES.OpenProtocol()
>  
> 
>> On Jun 1, 2017, at 10:37 AM, Amit kumar <akamit91@hotmail.com <mailto:akamit91@hotmail.com>> wrote:
>> 
>> Hello Andrew,
>> 
>> Thanks for quick reply and acknowledging my query.
>> 
> 
> Please file a bugzilla against the code. 
> 
> Thanks,
> 
> Andrew Fish
> 
>> Amit   
>> From: afish@apple.com <mailto:afish@apple.com> <afish@apple.com <mailto:afish@apple.com>> on behalf of Andrew Fish <afish@apple.com <mailto:afish@apple.com>>
>> Sent: Thursday, June 1, 2017 10:59:03 PM
>> To: Amit kumar
>> Cc: edk2-devel@lists.01.org <mailto:edk2-devel@lists.01.org>
>> Subject: Re: [edk2] Problem in EFI_BOOT_SERVICES.OpenProtocol()
>>  
>> 
>> > On Jun 1, 2017, at 10:13 AM, Amit kumar <akamit91@hotmail.com <mailto:akamit91@hotmail.com>> wrote:
>> > 
>> > Hello Andrew,
>> > 
>> > As per UEFI Spec EFI_ALREADY_STARTED is treated as error code, thus PciIo (The Interface 3rd parameter ) should remain NULL.
>> > But after    OpenProtocol call even though Status = EFI_ALREADY_STARTED PciIo (The Interface 3rd parameter ) is getting modified and it not NULL anymore.
>> > Is this not a problem ?
>> > 
>> 
>> Amit,
>> 
>> I agree it looks like the code will fill in the Interface and return EFI_ALREADY_STARTED. And that does seem to conflict with the section of the spec you quote. Good catch. 
>> 
>> https://github.com/tianocore/edk2/blob/master/MdeModulePkg/Core/Dxe/Hand/Handle.c#L1097 <https://github.com/tianocore/edk2/blob/master/MdeModulePkg/Core/Dxe/Hand/Handle.c#L1097>
>>   //
>>   // This is the protocol interface entry for this protocol
>>   //
>>   if (Attributes != EFI_OPEN_PROTOCOL_TEST_PROTOCOL) {
>>     *Interface = Prot->Interface;
>>   }
>>   Status = EFI_SUCCESS;
>> 
>>   ByDriver        = FALSE;
>>   Exclusive       = FALSE;
>>   for ( Link = Prot->OpenList.ForwardLink; Link != &Prot->OpenList; Link = Link->ForwardLink) {
>>     OpenData = CR (Link, OPEN_PROTOCOL_DATA, Link, OPEN_PROTOCOL_DATA_SIGNATURE);
>>     ExactMatch =  (BOOLEAN)((OpenData->AgentHandle == ImageHandle) &&
>>                             (OpenData->Attributes == Attributes)  &&
>>                             (OpenData->ControllerHandle == ControllerHandle));
>>     if ((OpenData->Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) != 0) {
>>       ByDriver = TRUE;
>>       if (ExactMatch) {
>>         Status = EFI_ALREADY_STARTED;
>>         goto Done;
>>       }
>>     }
>>     if ((OpenData->Attributes & EFI_OPEN_PROTOCOL_EXCLUSIVE) != 0) {
>>       Exclusive = TRUE;
>>     } else if (ExactMatch) {
>>       OpenData->OpenCount++;
>>       Status = EFI_SUCCESS;
>>       goto Done;
>>     }
>>   }
>> 
>> Thanks,
>> 
>> Andrew Fish
>> 
>> > Status = gBS->OpenProtocol (
>> >                  Controller,
>> >                  &gEfiPciIoProtocolGuid,
>> >                  (VOID **) &PciIo,
>> >                  This->DriverBindingHandle,
>> >                  Controller,
>> >                  EFI_OPEN_PROTOCOL_BY_DRIVER
>> >                  );
>> > 
>> > ________________________________
>> > From: afish@apple.com <mailto:afish@apple.com> <afish@apple.com <mailto:afish@apple.com>> on behalf of Andrew Fish <afish@apple.com <mailto:afish@apple.com>>
>> > Sent: Thursday, June 1, 2017 10:28:16 PM
>> > To: Amit kumar
>> > Cc: edk2-devel@lists.01.org <mailto:edk2-devel@lists.01.org>
>> > Subject: Re: [edk2] Problem in EFI_BOOT_SERVICES.OpenProtocol()
>> > 
>> > 
>> >> On Jun 1, 2017, at 9:46 AM, Amit kumar <akamit91@hotmail.com <mailto:akamit91@hotmail.com>> wrote:
>> >> 
>> >> Hi,
>> >> I am trying to open PciIoProtocol and facing some issue.
>> >> 
>> >> below is the code
>> >> 
>> >> EFI_PCI_IO_PROTOCOL *PciIo=NULL;
>> >> EFI_STATUS                      Status;
>> >> 
>> >> Status = gBS->OpenProtocol (
>> >>                 Controller,
>> >>                 &gEfiPciIoProtocolGuid,
>> >>                 (VOID **) &PciIo,
>> >>                 This->DriverBindingHandle,
>> >>                 Controller,
>> >>                 EFI_OPEN_PROTOCOL_BY_DRIVER
>> >>                 );
>> >> 
>> >> it returns Status = EFI_ALREADY_STARTED, but PciIo is not NULL.
>> >> Is it not supposed to return PciIo as NULL ?
>> >> As per UEFI 2.6 Spec Section 6.3 page 182.
>> >> 
>> > 
>> > Amit,
>> > 
>> > Look at the Status Codes Returned section at the end of that section.
>> > 
>> > Attributes is BY_DRIVER and there is an item on the open list with an attribute of BY_DRIVER whose agent handle is the same as AgentHandle.
>> > 
>> > Attributes is BY_DRIVER|EXCLUSIVE and there is an item on the open list with an attribute of BY_DRIVER|EXCLUSIVE whose agent handle is the same as AgentHandle.
>> > 
>> > Thanks,
>> > 
>> > Andrew Fish
>> > 
>> >> There are a number of reasons that this function call can return an error. If an error is returned, then
>> >> AgentHandle, ControllerHandle, and Attributes are not added to the list of agents
>> >> consuming the protocol interface specified by Handle and Protocol, and Interface is
>> >> returned unmodified.
>> >> 
>> >> Thanks And Regards
>> >> Amit
>> >> _______________________________________________
>> >> edk2-devel mailing list
>> >> edk2-devel@lists.01.org <mailto:edk2-devel@lists.01.org>
>> >> https://lists.01.org/mailman/listinfo/edk2-devel <https://lists.01.org/mailman/listinfo/edk2-devel>
>> > 
>> > _______________________________________________
>> > edk2-devel mailing list
>> > edk2-devel@lists.01.org <mailto:edk2-devel@lists.01.org>
>> > https://lists.01.org/mailman/listinfo/edk2-devel <https://lists.01.org/mailman/listinfo/edk2-devel>


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2017-06-01 17:40 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-01 16:46 Problem in EFI_BOOT_SERVICES.OpenProtocol() Amit kumar
2017-06-01 16:58 ` Andrew Fish
2017-06-01 17:13   ` Amit kumar
2017-06-01 17:29     ` Andrew Fish
2017-06-01 17:37       ` Amit kumar
2017-06-01 17:38         ` Andrew Fish
2017-06-01 17:40           ` Amit kumar
2017-06-01 17:41             ` Andrew Fish

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox