Ejemplo n.º 1
0
EFI_STATUS
LocateSerialIo (
    VOID
)
/*++

Routine Description:
  Build a list containing all serial devices

Arguments:

Returns:

--*/
{
    UINT8                     *Ptr;
    UINTN                     Index;
    UINTN                     Index2;
    UINTN                     NoHandles;
    EFI_HANDLE                *Handles;
    EFI_STATUS                Status;
    ACPI_HID_DEVICE_PATH      *Acpi;
    EFI_DEVICE_PATH_PROTOCOL  *DevicePath;
    UINT32                    Match;
    EFI_SERIAL_IO_PROTOCOL    *SerialIo;
    EFI_DEVICE_PATH_PROTOCOL  *OutDevicePath;
    EFI_DEVICE_PATH_PROTOCOL  *InpDevicePath;
    EFI_DEVICE_PATH_PROTOCOL  *ErrDevicePath;
    BM_MENU_ENTRY             *NewMenuEntry;
    BM_TERMINAL_CONTEXT       *NewTerminalContext;
    EFI_DEVICE_PATH_PROTOCOL  *NewDevicePath;
    VENDOR_DEVICE_PATH        Vendor;
    //
    // Get all handles that have SerialIo protocol installed
    //
    InitializeListHead (&TerminalMenu.Head);
    TerminalMenu.MenuNumber = 0;
    Status = gBS->LocateHandleBuffer (
                 ByProtocol,
                 &gEfiSerialIoProtocolGuid,
                 NULL,
                 &NoHandles,
                 &Handles
             );
    if (EFI_ERROR (Status)) {
        //
        // No serial ports present
        //
        return EFI_UNSUPPORTED;
    }

    //
    // Sort Uart handles array with Acpi->UID from low to high
    // then Terminal menu can be built from low Acpi->UID to high Acpi->UID
    //
    SortedUartHandle (Handles, NoHandles);

    for (Index = 0; Index < NoHandles; Index++) {
        //
        // Check to see whether the handle has DevicePath Protocol installed
        //
        gBS->HandleProtocol (
            Handles[Index],
            &gEfiDevicePathProtocolGuid,
            &DevicePath
        );
        Ptr = (UINT8 *) DevicePath;
        while (*Ptr != END_DEVICE_PATH_TYPE) {
            Ptr++;
        }

        Ptr   = Ptr - sizeof (UART_DEVICE_PATH) - sizeof (ACPI_HID_DEVICE_PATH);
        Acpi  = (ACPI_HID_DEVICE_PATH *) Ptr;
        Match = EISA_PNP_ID (0x0501);

        if (EfiCompareMem (&Acpi->HID, &Match, sizeof (UINT32)) == 0) {
            NewMenuEntry = BOpt_CreateMenuEntry (BM_TERMINAL_CONTEXT_SELECT);
            if (!NewMenuEntry) {
                SafeFreePool (Handles);
                return EFI_OUT_OF_RESOURCES;
            }

            NewTerminalContext = (BM_TERMINAL_CONTEXT *) NewMenuEntry->VariableContext;
            EfiCopyMem (&NewMenuEntry->OptionNumber, &Acpi->UID, sizeof (UINT32));
            NewTerminalContext->DevicePath = DevicePathInstanceDup (DevicePath);
            //
            // BugBug: I have no choice, calling EfiLibStrFromDatahub will hang the system!
            // coz' the misc data for each platform is not correct, actually it's the device path stored in
            // datahub which is not completed, so a searching for end of device path will enter a
            // dead-loop.
            //
            NewMenuEntry->DisplayString = EfiLibStrFromDatahub (DevicePath);
            if (NULL == NewMenuEntry->DisplayString) {
                NewMenuEntry->DisplayString = DevicePathToStr (DevicePath);
            }

            NewMenuEntry->HelpString = NULL;

            gBS->HandleProtocol (
                Handles[Index],
                &gEfiSerialIoProtocolGuid,
                &SerialIo
            );

            EfiCopyMem (
                &NewTerminalContext->BaudRate,
                &SerialIo->Mode->BaudRate,
                sizeof (UINT64)
            );

            EfiCopyMem (
                &NewTerminalContext->DataBits,
                &SerialIo->Mode->DataBits,
                sizeof (UINT8)
            );

            EfiCopyMem (
                &NewTerminalContext->Parity,
                &SerialIo->Mode->Parity,
                sizeof (UINT8)
            );

            EfiCopyMem (
                &NewTerminalContext->StopBits,
                &SerialIo->Mode->StopBits,
                sizeof (UINT8)
            );
            InsertTailList (&TerminalMenu.Head, &NewMenuEntry->Link);
            TerminalMenu.MenuNumber++;
        }
    }
    SafeFreePool (Handles);

    //
    // Get L"ConOut", L"ConIn" and L"ErrOut" from the Var
    //
    OutDevicePath = EfiLibGetVariable (L"ConOut", &gEfiGlobalVariableGuid);
    InpDevicePath = EfiLibGetVariable (L"ConIn", &gEfiGlobalVariableGuid);
    ErrDevicePath = EfiLibGetVariable (L"ErrOut", &gEfiGlobalVariableGuid);
    if (OutDevicePath) {
        UpdateComAttributeFromVariable (OutDevicePath);
    }

    if (InpDevicePath) {
        UpdateComAttributeFromVariable (InpDevicePath);
    }

    if (ErrDevicePath) {
        UpdateComAttributeFromVariable (ErrDevicePath);
    }

    for (Index = 0; Index < TerminalMenu.MenuNumber; Index++) {
        NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, Index);
        if (NULL == NewMenuEntry) {
            return EFI_NOT_FOUND;
        }

        NewTerminalContext                = (BM_TERMINAL_CONTEXT *) NewMenuEntry->VariableContext;

        NewTerminalContext->TerminalType  = 0;
        NewTerminalContext->IsConIn       = FALSE;
        NewTerminalContext->IsConOut      = FALSE;
        NewTerminalContext->IsStdErr      = FALSE;

        Vendor.Header.Type                = MESSAGING_DEVICE_PATH;
        Vendor.Header.SubType             = MSG_VENDOR_DP;

        for (Index2 = 0; Index2 < 4; Index2++) {
            EfiCopyMem (&Vendor.Guid, &Guid[Index2], sizeof (EFI_GUID));
            SetDevicePathNodeLength (&Vendor.Header, sizeof (VENDOR_DEVICE_PATH));
            NewDevicePath = EfiAppendDevicePathNode (
                                NewTerminalContext->DevicePath,
                                (EFI_DEVICE_PATH_PROTOCOL *) &Vendor
                            );
            SafeFreePool (NewMenuEntry->HelpString);
            //
            // NewMenuEntry->HelpString = DevicePathToStr (NewDevicePath);
            // NewMenuEntry->DisplayString = NewMenuEntry->HelpString;
            //
            NewMenuEntry->HelpString = NULL;

            if (BdsLibMatchDevicePaths (OutDevicePath, NewDevicePath)) {
                NewTerminalContext->IsConOut      = TRUE;
                NewTerminalContext->TerminalType  = (UINT8) Index2;
            }

            if (BdsLibMatchDevicePaths (InpDevicePath, NewDevicePath)) {
                NewTerminalContext->IsConIn       = TRUE;
                NewTerminalContext->TerminalType  = (UINT8) Index2;
            }

            if (BdsLibMatchDevicePaths (ErrDevicePath, NewDevicePath)) {
                NewTerminalContext->IsStdErr      = TRUE;
                NewTerminalContext->TerminalType  = (UINT8) Index2;
            }
        }
    }

    return EFI_SUCCESS;
}
Ejemplo n.º 2
0
/**
  Build a list containing all serial devices.


  @retval EFI_SUCCESS The function complete successfully.
  @retval EFI_UNSUPPORTED No serial ports present.

**/
EFI_STATUS
LocateSerialIo (
  VOID
  )
{
  UINTN                     Index;
  UINTN                     Index2;
  UINTN                     NoHandles;
  EFI_HANDLE                *Handles;
  EFI_STATUS                Status;
  ACPI_HID_DEVICE_PATH      *Acpi;
  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;
  EFI_SERIAL_IO_PROTOCOL    *SerialIo;
  EFI_DEVICE_PATH_PROTOCOL  *Node;
  EFI_DEVICE_PATH_PROTOCOL  *OutDevicePath;
  EFI_DEVICE_PATH_PROTOCOL  *InpDevicePath;
  EFI_DEVICE_PATH_PROTOCOL  *ErrDevicePath;
  BM_MENU_ENTRY             *NewMenuEntry;
  BM_TERMINAL_CONTEXT       *NewTerminalContext;
  EFI_DEVICE_PATH_PROTOCOL  *NewDevicePath;
  VENDOR_DEVICE_PATH        Vendor;
  UINT32                    FlowControl;
  //
  // Get all handles that have SerialIo protocol installed
  //
  InitializeListHead (&TerminalMenu.Head);
  TerminalMenu.MenuNumber = 0;
  Status = gBS->LocateHandleBuffer (
                  ByProtocol,
                  &gEfiSerialIoProtocolGuid,
                  NULL,
                  &NoHandles,
                  &Handles
                  );
  if (EFI_ERROR (Status)) {
    //
    // No serial ports present
    //
    return EFI_UNSUPPORTED;
  }

  //
  // Sort Uart handles array with Acpi->UID from low to high
  // then Terminal menu can be built from low Acpi->UID to high Acpi->UID
  //
  SortedUartHandle (Handles, NoHandles);

  for (Index = 0; Index < NoHandles; Index++) {
    //
    // Check to see whether the handle has DevicePath Protocol installed
    //
    gBS->HandleProtocol (
          Handles[Index],
          &gEfiDevicePathProtocolGuid,
          (VOID **) &DevicePath
          );

    Acpi = NULL;
    for (Node = DevicePath; !IsDevicePathEnd (Node); Node = NextDevicePathNode (Node)) {
      if ((DevicePathType (Node) == MESSAGING_DEVICE_PATH) && (DevicePathSubType (Node) == MSG_UART_DP)) {
        break;
      }
      //
      // Acpi points to the node before Uart node
      //
      Acpi = (ACPI_HID_DEVICE_PATH *) Node;
    }

    if ((Acpi != NULL) && IsIsaSerialNode (Acpi)) {
      NewMenuEntry = BOpt_CreateMenuEntry (BM_TERMINAL_CONTEXT_SELECT);
      if (NewMenuEntry == NULL) {
        FreePool (Handles);
        return EFI_OUT_OF_RESOURCES;
      }

      NewTerminalContext = (BM_TERMINAL_CONTEXT *) NewMenuEntry->VariableContext;
      CopyMem (&NewMenuEntry->OptionNumber, &Acpi->UID, sizeof (UINT32));
      NewTerminalContext->DevicePath = DuplicateDevicePath (DevicePath);
      //
      // BugBug: I have no choice, calling EfiLibStrFromDatahub will hang the system!
      // coz' the misc data for each platform is not correct, actually it's the device path stored in
      // datahub which is not completed, so a searching for end of device path will enter a
      // dead-loop.
      //
      NewMenuEntry->DisplayString = EfiLibStrFromDatahub (DevicePath);
      if (NULL == NewMenuEntry->DisplayString) {
        NewMenuEntry->DisplayString = DevicePathToStr (DevicePath);
      }

      NewMenuEntry->HelpString = NULL;

      gBS->HandleProtocol (
            Handles[Index],
            &gEfiSerialIoProtocolGuid,
            (VOID **) &SerialIo
            );

      CopyMem (
        &NewTerminalContext->BaudRate,
        &SerialIo->Mode->BaudRate,
        sizeof (UINT64)
        );

      CopyMem (
        &NewTerminalContext->DataBits,
        &SerialIo->Mode->DataBits,
        sizeof (UINT8)
        );

      CopyMem (
        &NewTerminalContext->Parity,
        &SerialIo->Mode->Parity,
        sizeof (UINT8)
        );

      CopyMem (
        &NewTerminalContext->StopBits,
        &SerialIo->Mode->StopBits,
        sizeof (UINT8)
        );

      NewTerminalContext->FlowControl = 0;
      SerialIo->GetControl(SerialIo, &FlowControl);
      if ((FlowControl & EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE) != 0) {
        NewTerminalContext->FlowControl = UART_FLOW_CONTROL_HARDWARE;
      }

      InsertTailList (&TerminalMenu.Head, &NewMenuEntry->Link);
      TerminalMenu.MenuNumber++;
    }
  }
  if (Handles != NULL) {
    FreePool (Handles);
  }

  //
  // Get L"ConOut", L"ConIn" and L"ErrOut" from the Var
  //
  OutDevicePath = EfiLibGetVariable (L"ConOut", &gEfiGlobalVariableGuid);
  InpDevicePath = EfiLibGetVariable (L"ConIn", &gEfiGlobalVariableGuid);
  ErrDevicePath = EfiLibGetVariable (L"ErrOut", &gEfiGlobalVariableGuid);
  if (OutDevicePath != NULL) {
    UpdateComAttributeFromVariable (OutDevicePath);
  }

  if (InpDevicePath != NULL) {
    UpdateComAttributeFromVariable (InpDevicePath);
  }

  if (ErrDevicePath != NULL) {
    UpdateComAttributeFromVariable (ErrDevicePath);
  }

  for (Index = 0; Index < TerminalMenu.MenuNumber; Index++) {
    NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, Index);
    if (NULL == NewMenuEntry) {
      return EFI_NOT_FOUND;
    }

    NewTerminalContext                = (BM_TERMINAL_CONTEXT *) NewMenuEntry->VariableContext;

    NewTerminalContext->TerminalType  = 0;
    NewTerminalContext->IsConIn       = FALSE;
    NewTerminalContext->IsConOut      = FALSE;
    NewTerminalContext->IsStdErr      = FALSE;

    Vendor.Header.Type                = MESSAGING_DEVICE_PATH;
    Vendor.Header.SubType             = MSG_VENDOR_DP;

    for (Index2 = 0; Index2 < 4; Index2++) {
      CopyMem (&Vendor.Guid, &TerminalTypeGuid[Index2], sizeof (EFI_GUID));
      SetDevicePathNodeLength (&Vendor.Header, sizeof (VENDOR_DEVICE_PATH));
      NewDevicePath = AppendDevicePathNode (
                        NewTerminalContext->DevicePath,
                        (EFI_DEVICE_PATH_PROTOCOL *) &Vendor
                        );
      if (NewMenuEntry->HelpString != NULL) {
        FreePool (NewMenuEntry->HelpString);
      }
      //
      // NewMenuEntry->HelpString = DevicePathToStr (NewDevicePath);
      // NewMenuEntry->DisplayString = NewMenuEntry->HelpString;
      //
      NewMenuEntry->HelpString = NULL;

      if (BdsLibMatchDevicePaths (OutDevicePath, NewDevicePath)) {
        NewTerminalContext->IsConOut      = TRUE;
        NewTerminalContext->TerminalType  = (UINT8) Index2;
      }

      if (BdsLibMatchDevicePaths (InpDevicePath, NewDevicePath)) {
        NewTerminalContext->IsConIn       = TRUE;
        NewTerminalContext->TerminalType  = (UINT8) Index2;
      }

      if (BdsLibMatchDevicePaths (ErrDevicePath, NewDevicePath)) {
        NewTerminalContext->IsStdErr      = TRUE;
        NewTerminalContext->TerminalType  = (UINT8) Index2;
      }
    }
  }

  return EFI_SUCCESS;
}