예제 #1
0
파일: SnpShutdown.c 프로젝트: vathpela/edk2
EFI_STATUS
EFIAPI
VirtioNetShutdown (
  IN EFI_SIMPLE_NETWORK_PROTOCOL *This
  )
{
  VNET_DEV   *Dev;
  EFI_TPL    OldTpl;
  EFI_STATUS Status;

  if (This == NULL) {
    return EFI_INVALID_PARAMETER;
  }

  Dev = VIRTIO_NET_FROM_SNP (This);
  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
  switch (Dev->Snm.State) {
  case EfiSimpleNetworkStopped:
    Status = EFI_NOT_STARTED;
    goto Exit;
  case EfiSimpleNetworkStarted:
    Status = EFI_DEVICE_ERROR;
    goto Exit;
  default:
    break;
  }

  Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, 0);
  VirtioNetShutdownRx (Dev);
  VirtioNetShutdownTx (Dev);
  VirtioRingUninit (Dev->VirtIo, &Dev->TxRing);
  VirtioRingUninit (Dev->VirtIo, &Dev->RxRing);

  Dev->Snm.State = EfiSimpleNetworkStarted;
  Status = EFI_SUCCESS;

Exit:
  gBS->RestoreTPL (OldTpl);
  return Status;
}
예제 #2
0
/**
  Stops a device controller or a bus controller.

  The Stop() function is designed to be invoked from the EFI boot service
  DisconnectController().  As a result, much of the error checking on the
  parameters to Stop() has been moved  into this common boot service. It is
  legal to call Stop() from other locations,  but the following calling
  restrictions must be followed, or the system behavior will not be
  deterministic.
  1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous
     call to this same driver's Start() function.
  2. The first NumberOfChildren handles of ChildHandleBuffer must all be a
     valid EFI_HANDLE. In addition, all of these handles must have been created
     in this driver's Start() function, and the Start() function must have
     called OpenProtocol() on ControllerHandle with an Attribute of
     EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.

  @param[in]  This              A pointer to the EFI_DRIVER_BINDING_PROTOCOL
                                instance.
  @param[in]  ControllerHandle  A handle to the device being stopped. The
                                handle must  support a bus specific I/O
                                protocol for the driver  to use to stop the
                                device.
  @param[in]  NumberOfChildren  The number of child device handles in
                                ChildHandleBuffer.
  @param[in]  ChildHandleBuffer An array of child handles to be freed. May be
                                NULL  if NumberOfChildren is 0.

  @retval EFI_SUCCESS           The device was stopped.
  @retval EFI_DEVICE_ERROR      The device could not be stopped due to a device
                                error.

**/
STATIC
EFI_STATUS
EFIAPI
VirtioNetDriverBindingStop (
  IN EFI_DRIVER_BINDING_PROTOCOL *This,
  IN EFI_HANDLE                  DeviceHandle,
  IN UINTN                       NumberOfChildren,
  IN EFI_HANDLE                  *ChildHandleBuffer
  )
{
  if (NumberOfChildren > 0) {
    //
    // free all resources for whose access we need the child handle, because
    // the child handle is going away
    //
    EFI_STATUS                  Status;
    EFI_SIMPLE_NETWORK_PROTOCOL *Snp;
    VNET_DEV                    *Dev;
    EFI_TPL                     OldTpl;

    ASSERT (NumberOfChildren == 1);

    Status = gBS->OpenProtocol (ChildHandleBuffer[0],
                    &gEfiSimpleNetworkProtocolGuid, (VOID **)&Snp,
                    This->DriverBindingHandle, DeviceHandle,
                    EFI_OPEN_PROTOCOL_GET_PROTOCOL);
    ASSERT_EFI_ERROR (Status);
    Dev = VIRTIO_NET_FROM_SNP (Snp);

    //
    // prevent any interference with WaitForPacket
    //
    OldTpl = gBS->RaiseTPL (TPL_CALLBACK);

    ASSERT (Dev->MacHandle == ChildHandleBuffer[0]);
    if (Dev->Snm.State != EfiSimpleNetworkStopped) {
      //
      // device in use, cannot stop driver instance
      //
      Status = EFI_DEVICE_ERROR;
    }
    else {
      gBS->CloseProtocol (DeviceHandle, &gVirtioDeviceProtocolGuid,
             This->DriverBindingHandle, Dev->MacHandle);
      gBS->UninstallMultipleProtocolInterfaces (Dev->MacHandle,
             &gEfiDevicePathProtocolGuid,    Dev->MacDevicePath,
             &gEfiSimpleNetworkProtocolGuid, &Dev->Snp,
             NULL);
      FreePool (Dev->MacDevicePath);
      VirtioNetSnpEvacuate (Dev);
      FreePool (Dev);
    }

    gBS->RestoreTPL (OldTpl);
    return Status;
  }

  //
  // release remaining resources, tied directly to the parent handle
  //
  gBS->CloseProtocol (DeviceHandle, &gVirtioDeviceProtocolGuid,
         This->DriverBindingHandle, DeviceHandle);

  return EFI_SUCCESS;
}