Newer
Older
AMI-Aptio-BIOS-Reversed / AmiModulePkg / ACPI / FboGroupForm / FboGroupForm.h
@Ajax Dong Ajax Dong 2 days ago 5 KB Restructure the repo
/** @file
  FboGroupForm.h -- Header for Fixed Boot Order Group Form DXE driver.

  This DXE driver provides HII form callbacks and update logic for managing
  fixed boot order (FBO) groups. It supports two device categories:
    - Legacy devices (BIOS legacy option ROMs)
    - UEFI devices (UEFI boot option entries)

  The driver integrates with the AMI FixedBootOrder infrastructure and
  manages IFR form data via HII configuration routing protocols.

  Source: HR650X BIOS -- FboGroupForm.efi (0079)
  SHA256: e8bc42409ca8fb9e21cb6553c3ba3f421c1beedad86b2cf576542f0d1ab6877e
*/

#ifndef __FBOGROUPFORM_H__
#define __FBOGROUPFORM_H__

#include <Uefi.h>
#include <Library/DebugLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#include <Library/UefiHiiServicesLib.h>
#include <Library/HiiLib.h>
#include <Library/DevicePathLib.h>
#include <Protocol/HiiConfigAccess.h>
#include <Protocol/HiiConfigRouting.h>
#include <Protocol/FormBrowser2.h>

//
// GUID definitions
//
extern EFI_GUID  gFboGroupFormGuid;

//
// HII Vendor Device Path
//
extern UINT8     gFboGroupFormVendorDevicePath[];

//
// Global data pointers
//
extern UINT64    ImageHandle;
extern UINT64    SystemTable_0;
extern UINT64    BootServices_0;
extern UINT64    RuntimeServices_0;
extern UINT64    qword_5EA0;   ///< Optional legacy boot order override table
extern UINT64    qword_5EA8;   ///< Legacy boot order index table
extern UINT64    qword_5EB0;   ///< Master fixed boot order configuration table
extern UINT64    qword_5EB8;   ///< Legacy device IFRNV data storage
extern UINT64    qword_5EC0;   ///< UEFI device boot order index table
extern UINT64    qword_5EC8;   ///< Current FBO configuration context
extern UINT64    qword_5ED0;   ///< Browser callback status flag

//
// Constants
//
#define FBO_GROUP_FORM_KEY_MIN          0x1200
#define FBO_LEGACY_DEV_KEY_BASE         0x1200
#define FBO_UEFI_DEV_KEY_BASE           0x1344
#define FBO_MAX_GROUP_ENTRIES           18
#define FBO_GROUP_DATA_SIZE             648
#define FBO_BUFFER_ALLOCATION_SIZE      4096

//
// Function prototypes
//

//
// Entry point and initialization
//
EFI_STATUS
EFIAPI
ModuleEntryPoint (
  IN EFI_HANDLE        ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  );

//
// HII callback handler -- processes form browser interaction
//
EFI_STATUS
EFIAPI
FboGroupFormCallback (
  IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL  *This,
  IN EFI_BROWSER_ACTION                    Action,
  IN EFI_QUESTION_ID                       QuestionId,
  IN UINT8                                 Type,
  IN OUT EFI_IFR_TYPE_VALUE                *Value,
  OUT EFI_BROWSER_SETTINGS                 *ActionRequest
  );

//
// HII form update notification callback
//
VOID
EFIAPI
FboGroupFormNotify (
  IN EFI_EVENT  Event,
  IN VOID       *Context
  );

//
// Legacy device boot order update (key range 0x1200-0x1343)
//
EFI_STATUS
UpdateLegacyDeviceOrder (
  IN EFI_HANDLE              DriverHandle,
  IN UINT16                  KeyOffset,
  IN EFI_BROWSER_ACTION      Action,
  IN OUT UINT16              *SubMenuNvData,
  IN UINTN                   BufferSize,
  IN EFI_IFR_TYPE_VALUE      *Value
  );

//
// UEFI device boot order update (key range 0x1344-0x1588)
//
EFI_STATUS
UpdateUefiDeviceOrder (
  IN EFI_HANDLE              DriverHandle,
  IN UINT16                  KeyOffset,
  IN EFI_BROWSER_ACTION      Action,
  IN OUT UINT16              *SubMenuNvData,
  IN UINTN                   BufferSize,
  IN EFI_IFR_TYPE_VALUE      *Value
  );

//
// IFR buffer walker -- finds a form label and replaces its content
//
EFI_STATUS
FindAndReplaceFormLabel (
  IN  EFI_HANDLE              DriverHandle,
  IN  VOID                    *FormBuffer,
  IN  UINT16                  Label,
  IN  VOID                    *InsertBuffer,    OPTIONAL
  IN  UINTN                   InsertSize,
  OUT VOID                    **ResultBuffer,   OPTIONAL
  OUT UINTN                   *ResultSize        OPTIONAL
  );

//
// HII variable manipulation helpers
//
EFI_STATUS
HiiGetBrowserData (
  IN OUT UINTN           *BufferSize,
  OUT VOID               **Buffer
  );

EFI_STATUS
HiiSetBrowserData (
  IN UINTN               BufferSize,
  IN VOID                *Buffer
  );

//
// String formatting functions
//
UINTN
EFIAPI
MySPrint (
  OUT CHAR16       *Buffer,
  IN  UINTN        BufferSize,
  IN  CONST CHAR16 *Format,
  ...
  );

//
// Numeric conversion helpers
//
UINT8
DecimalToBcd (
  IN UINT8  Value
  );

UINT8
BcdToDecimal (
  IN UINT8  Value
  );

//
// GUID comparison
//
BOOLEAN
CompareGuid (
  IN CONST EFI_GUID  *Guid1,
  IN CONST EFI_GUID  *Guid2
  );

//
// HII configuration routing helpers
//
EFI_STATUS
HiiGetStringFromToken (
  IN  EFI_STRING_ID   Token,
  OUT CHAR16          **String
  );

EFI_STATUS
HiiGetRevisionString (
  IN  EFI_HII_HANDLE  HiiHandle,
  OUT CHAR16          **String
  );

//
// HII formset update
//
EFI_STATUS
HiiUpdateForm (
  IN EFI_HII_HANDLE             HiiHandle,
  IN EFI_GUID                   *FormSetGuid,
  IN EFI_FORM_ID                FormId,
  IN CONST VOID                 *FormBuffer,
  IN EFI_BROWSER_ACTION         Action
  );

//
// IFR GUID operation handler
//
BOOLEAN
HandleGuidOp (
  IN UINT8   *OpCodeData,
  IN UINTN   OpCodeLen,
  IN UINT16  TargetLabel
  );

//
// Boot option mapping
//
UINT16
LookupBootOptionIndex (
  IN UINT16  OptionKey
  );

//
// String assignment helper (copies at most 16 chars)
//
VOID
AssignFixedString (
  IN OUT CHAR16  *Dest,
  IN CHAR16      CharIndex,
  IN CHAR16      Value
  );

#endif /* __FBOGROUPFORM_H__ */