setoptions.c

来自「EFI BIOS是Intel提出的下一代的BIOS标准。这里上传的Edk源代码是」· C语言 代码 · 共 870 行 · 第 1/3 页

C
870
字号
      // step3 : get the infos of child devices created by the driver
      //
      Status = GetChildDeviceHandlesManagedByDriver (
                DriverImageHandleBuffer[Index],
                ControllerHandleBuffer[ControllerHandleIndex],
                &ChildControllerHandleCount,      // Get managed devices count
                &ChildControllerHandleBuffer      // return all handles in buffer
                );

      for (ChildControllerHandleIndex = 0; ChildControllerHandleIndex < ChildControllerHandleCount; ChildControllerHandleIndex++) {
        //
        // Get the  managed child device name
        // First try to get its component name, if fail, get its device path then 
        // The component name string need not free pool, but the device path string  need safe free pool after export the string to Hii database
        //
        FreeChildControllerHandleName = FALSE;
        ChildControllerHandleName = NULL;
        Status = EFI_UNSUPPORTED;
        if ((ComponentName != NULL) && (ComponentName->GetDriverName != NULL)) {
          Status = ComponentName->GetControllerName (
                                    ComponentName,
                                    ControllerHandleBuffer[ControllerHandleIndex],
                                    ChildControllerHandleBuffer[ChildControllerHandleIndex],
                                    Language,
                                    &ChildControllerHandleName
                                    );
        }
        if (EFI_ERROR (Status)) {
          Status = gBS->OpenProtocol (
                          ChildControllerHandleBuffer[ChildControllerHandleIndex],
                          &gEfiDevicePathProtocolGuid,
                          (VOID **) &DevicePath,
                          NULL,
                          NULL,
                          EFI_OPEN_PROTOCOL_GET_PROTOCOL
                          );
          if (!EFI_ERROR (Status)) {
            ChildControllerHandleName = DevicePathToStr ( DevicePath );
            FreeChildControllerHandleName = TRUE; // the Child Controller Handle Name string need to free pool
          }
        } 
        if (ChildControllerHandleName == NULL) {
          ChildControllerHandleName = GetString (Private, (STRING_REF) STR_DRIVER_CHILD_CONTROLLER_DEFAULT_NAME);
          ASSERT (ChildControllerHandleName != NULL);
          FreeChildControllerHandleName = TRUE;  // the Controller Handle Name string need to free pool
        }

        //
        // do some alignment for NewString if needed
        //
        AlignmentItem (ChildControllerHandleName, L"     |--", &NewString);
        
        NewStringToken = mChoice[ChoiceIndex].DescriptionToken;
        Private->Hii->NewString ( 
                            Private->Hii,
                            NULL, 
                            Private->RegisteredHandle, 
                            &NewStringToken, 
                            NewString
                            );
        gBS->FreePool (NewString); 
        if (FreeChildControllerHandleName) {
          gBS->FreePool (ChildControllerHandleName);      
        }
        CreateGotoOpCode (
          0x1234,                 
          NewStringToken,                          // Description String Token
          STR_GOTO_HELP_CHILD_DEVICE,              // Description Help String Token
          EFI_IFR_FLAG_INTERACTIVE,                // Flag designating callback is active
          (UINT16) ChoiceIndex + 0x100,            // Callback key value
          Location                                 // Buffer to fill with op-code
          );
        //
        // Update the buffer items number and adjust next item address to new one
        //
        UpdateData->DataCount +=1 ;
        Location = Location + ((EFI_IFR_OP_HEADER *) Location)->Length;
        //
        // Associate callback key with  setoptions function related parameters to used by Task 1
        //
        mChoice[ChoiceIndex].DriverImageHandle = DriverImageHandleBuffer[Index];
        mChoice[ChoiceIndex].DriverConfiguration = DriverConfiguration;
        mChoice[ChoiceIndex].ControllerHandle = ControllerHandleBuffer[ControllerHandleIndex];
        mChoice[ChoiceIndex].ChildControllerHandle = ChildControllerHandleBuffer[ChildControllerHandleIndex];
        mChoice[ChoiceIndex].DescriptionToken = NewStringToken;
        ChoiceIndex++;
      }
      if (ChildControllerHandleBuffer != NULL) {
        gBS->FreePool (ChildControllerHandleBuffer);
      }
    }

    //
    // Update Set Option page form
    //
    Private->Hii->UpdateForm (
                    Private->Hii,
                    Private->RegisteredHandle,
                    (EFI_FORM_LABEL) 0x1234,
                    TRUE,
                    UpdateData
                    );    

    if (ControllerHandleBuffer != NULL) {
      gBS->FreePool (ControllerHandleBuffer);
    }
    
  }
  
  gBS->FreePool (UpdateData);  
  
  if (DriverImageHandleBuffer != NULL) {
    gBS->FreePool (DriverImageHandleBuffer);
  }

  return EFI_SUCCESS;
}

EFI_STATUS
ProcessActionRequired (
  IN  EFI_FORM_BROWSER_PROTOCOL                 *FormBrowser,
  IN  EFI_CALLBACK_INFO                         *Private,
  IN  EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED  ActionRequired,
  IN  EFI_HANDLE                                DriverImageHandle,
  IN  EFI_HANDLE                                ControllerHandle,
  IN  EFI_HANDLE                                ChildControllerHandle
  )
/*++
  
  Routine Description:
    Notify user the action required after SetOptions function finish, and do the action according to user's intent
        
  Arguments:
    FormBrowser - Form Configuration protocol used to give popup menu if needed
    ActionRequired - SetOPtions function returned data, refer to driver configuration protocol spec
    DriverImageHandle - The driver image handle which support driver configuration protocol 
    ControllerHandle - The device controller handle to set option, refer to driver configuration protocol spec
    ChildControllerHandle - The child device controller handle to set option, refer to driver configuration protocol spec
    
  Returns:
    EFI_STATUS
  
--*/ 
{
  CHAR16                        *String;
  CHAR16                        *SelectString;
  UINTN                         Status;
  EFI_INPUT_KEY                 Key;
  EFI_HANDLE                    DriverImageHandleList[2];
  
  if ((DriverImageHandle == NULL) || 
      (FormBrowser == NULL)   ||
      ((ControllerHandle == NULL) && (ChildControllerHandle != NULL))
     ) {
    return EFI_INVALID_PARAMETER;
  }
  
  SelectString = GetString (Private, (STRING_REF) STR_ACTION_REQUIRED_ACTION_NOW);
  ASSERT (SelectString != NULL);

  
  switch (ActionRequired) {
  case EfiDriverConfigurationActionNone:
    gBS->FreePool (SelectString);
    SelectString = GetString (Private, (STRING_REF) STR_ACTION_REQUIRED_CONTINUE);
    ASSERT (SelectString != NULL);

    String = GetString (Private, (STRING_REF) STR_ACTION_REQUIRED_NONE);
    ASSERT (String != NULL);
    
    break;
    
  case EfiDriverConfigurationActionStopController:
    String = GetString (Private, (STRING_REF) STR_ACTION_REQUIRED_STOP_CONTROLLER);
    ASSERT (String != NULL);
    
    break;
    
  case EfiDriverConfigurationActionRestartController:
    String = GetString (Private, (STRING_REF) STR_ACTION_REQUIRED_RESTART_CONTROLLER);
    ASSERT (String != NULL);

    break;
    
  case EfiDriverConfigurationActionRestartPlatform:
    String = GetString (Private, (STRING_REF) STR_ACTION_REQUIRED_RESTART_PLATFORM);
    ASSERT (String != NULL);
    
    break;
    
  default:
    gBS->FreePool (SelectString);
    return EFI_INVALID_PARAMETER;
  }
  //
  // Popup a menu to notice user
  // 
  do {
    FormBrowser->CreatePopUp (2, TRUE, 0, NULL, &Key, String, SelectString);
  } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));
  gBS->FreePool (SelectString);
  gBS->FreePool (String);  
  
  Status = EFI_SUCCESS;
  if ((Key.UnicodeChar == CHAR_CARRIAGE_RETURN)) {
    switch (ActionRequired) {
    case EfiDriverConfigurationActionStopController:
      //
      // If user select a bus driver item
      //
      if ((ControllerHandle == NULL)) {
        gST->ConOut->ClearScreen (gST->ConOut);
        String = GetString (Private, (STRING_REF) STR_ACTION_REQUIRED_STOP_SELECT_ERROR);
        ASSERT (String != NULL);
        FormBrowser->CreatePopUp ((UINTN)1, TRUE, 0, NULL, &Key, String);
        gBS->FreePool (String); 
        break;
      }

      //
      // If user select a device or child device controller item
      //
      if ((ControllerHandle != NULL)) {
        Status = gBS->DisconnectController (ControllerHandle, DriverImageHandle, ChildControllerHandle);
        if (EFI_ERROR(Status)) {
          gST->ConOut->ClearScreen (gST->ConOut);
          String = GetString (Private, (STRING_REF) STR_ACTION_REQUIRED_DISCON_CONTRO_ERROR);
          ASSERT (String != NULL);
          FormBrowser->CreatePopUp ((UINTN)1, TRUE, 0, NULL, &Key, String);
          gBS->FreePool (String); 
          break;         
        }
      }
      break;
      
    case EfiDriverConfigurationActionRestartController:
      //
      // If user select a bus driver item
      //
      if ((ControllerHandle == NULL)) {
        gST->ConOut->ClearScreen (gST->ConOut);
        String = GetString (Private, (STRING_REF) STR_ACTION_REQUIRED_START_SELECT_ERROR);
        ASSERT (String != NULL);
        FormBrowser->CreatePopUp ((UINTN)1, TRUE, 0, NULL, &Key, String);
        gBS->FreePool (String); 
        break;
      }
      //
      // If user select a device or child device controller item, disconnect the driver from device and all its children first, then 
      // connect the driver to all of them.
      // Since the driver must be a driver-model driver, and the managed device or child device should be reconnected successful multi times,
      //  to be simple, merge the restart action for both  device and child device. 
      //
      if ((ControllerHandle != NULL)) {
        Status = gBS->DisconnectController (ControllerHandle, DriverImageHandle, NULL);
        if (EFI_ERROR(Status)) {
          gST->ConOut->ClearScreen (gST->ConOut);
          String = GetString (Private, (STRING_REF) STR_ACTION_REQUIRED_DISCON_CHILCON_ERROR);
          ASSERT (String != NULL);
          FormBrowser->CreatePopUp ((UINTN)1, TRUE, 0, NULL, &Key, String);
          gBS->FreePool (String); 
          break;         
        }
        
        DriverImageHandleList[0]  = DriverImageHandle;
        DriverImageHandleList[1]  = NULL;
        Status = gBS->ConnectController (ControllerHandle, DriverImageHandleList, NULL, TRUE);
        if (EFI_ERROR(Status)) {
          gST->ConOut->ClearScreen (gST->ConOut);
          String = GetString (Private, (STRING_REF) STR_ACTION_REQUIRED_CONNECT_CONTRO_ERROR);
          ASSERT (String != NULL);
          FormBrowser->CreatePopUp ((UINTN)1, TRUE, 0, NULL, &Key, String);
          gBS->FreePool (String); 
          break;          
        }
      }
      
      break;
      
    case EfiDriverConfigurationActionRestartPlatform:
      gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL);
      break;
      
    default:
      break;
    }
  }
  return Status;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?