Newer
Older
AMI-Aptio-BIOS-Reversed / AmiTsePkg / EDK / MiniSetup / AMITSE / AMITSE.h
@Ajax Dong Ajax Dong 2 days ago 10 KB Full restructure
/**
 * AMITSE.h - Type definitions for AMITSE.efi (Tiano Shell Extension)
 * Lenovo HR650X BIOS, UEFI DXE driver
 *
 * This module implements the Aptio Setup Utility (TSE) user interface,
 * providing the BIOS Setup menu, boot management, HDD security, and
 * related platform configuration services.
 */

#ifndef __AMITSE_H__
#define __AMITSE_H__

#include <Uefi.h>
#include <Protocol/HiiDatabase.h>
#include <Protocol/HiiPackageList.h>
#include <Protocol/GraphicsOutput.h>
#include <Protocol/SimpleTextOut.h>
#include <Protocol/SimpleTextIn.h>
#include <Protocol/DebugSupport.h>
#include <Protocol/LoadedImage.h>
#include <Protocol/DevicePath.h>
#include <Protocol/DriverHealth.h>
#include <Protocol/PciIo.h>
#include <Protocol/NvmExpressPassThru.h>

#pragma pack(push, 1)

//
// AMITSE protocol GUID: {430A3B43-2B1C-4A1E-8E3B-9B3F2C5A1E4D}
// (InstallAmiTseProtocol at 0x40E4)
//
typedef struct _AMITSE_PROTOCOL AMITSE_PROTOCOL;

//
// TSE Menu Database header
// Parsed by TseParseMenuDatabase at 0xF6D0
//
typedef struct {
    UINT32  Signature;       // "AMITSE" magic
    UINT32  HeaderSize;
    UINT32  EntryCount;
    UINT32  StringTableOffset;
    UINT32  FormSetOffset;
    UINT32  FormOffset;
    UINT32  VariableOffset;
    UINT32  OptionOffset;
    UINT32  DefaultOffset;
    UINT32  MenuKeyOffset;
} TSE_MENU_DATABASE_HEADER;

//
// TSE Menu Entry
//
typedef struct {
    UINT16  FormId;
    UINT16  TitleStringId;
    UINT16  HelpStringId;
    UINT16  Flags;
    UINT16  Width;
    UINT16  Height;
    UINT32  CallbackFunction;
    UINT32  SubMenuOffset;
} TSE_MENU_ENTRY;

//
// TSE Boot Option structure (16 bytes per entry)
// Referenced by TseBootOptionsInit at 0x2558
//
typedef struct {
    UINT16  BootOptionNumber;      // Boot#### number
    UINT16  BootOptionFlags;       // LOAD_OPTION_ACTIVE, etc.
    CHAR16  *Description;          // Boot option description string
    UINTN   OptionSize;            // Size of optional data
} TSE_BOOT_OPTION_ENTRY;

//
// TSE Menu state structure (80 bytes, allocated at qword_74798)
//
typedef struct {
    UINT64  VideoBufferBase;       // +0x00: Framebuffer base address
    UINT64  VideoBufferSize;       // +0x08: Framebuffer size
    UINT64  ScreenWidth;           // +0x10: Screen width in pixels
    UINT64  ScreenHeight;          // +0x18: Screen height in pixels
    UINT64  GopHandle;             // +0x20: GOP protocol handle
    UINT64  BackBuffer;            // +0x28: Back buffer
    UINT64  FrontBuffer;           // +0x30: Front buffer
    UINT64  ProgressMax;           // +0x38: Progress bar maximum
    UINT64  RowCount;              // +0x40: Text row count
    UINT64  ColCount;              // +0x48: Text column count
    UINT64  CursorX;               // +0x50: Cursor X position
    UINT64  CursorY;               // +0x58: Cursor Y position
    BOOLEAN RedrawNeeded;          // +0x60: Redraw flag
    BOOLEAN Initialized;           // +0x61: Initialization flag
    UINT8   Reserved[6];           // +0x62-0x67: Padding
} TSE_MENU_STATE;

//
// TSE Language descriptor (32 bytes per entry)
// Parsed by TseInitPlatformLanguages at 0x8DF4
//
typedef struct {
    CHAR8   *LanguageCode;         // +0x00: e.g. "en-US"
    CHAR16  *LanguageString;       // +0x08: e.g. "English"
    UINT64  PackageHandle;         // +0x10: HII package list handle
    UINT64  Reserved;              // +0x18
} TSE_LANGUAGE_DESCRIPTOR;

//
// Setup Variable / BIOS settings storage
//
typedef struct {
    UINT8   BootOrder[128];
    UINT8   BootOptionSupport;
    UINT16  BootTimeOut;
    UINT32  BootNext;
    UINT16  BootNowCount;
    UINT8   BootFlow;
    UINT8   BootMenuType;
    UINT8   SetupMode;
    UINT8   BootOptionCategory;
    UINT8   NetworkStack;
    UINT8   UsbBoot;
    UINT8   LegacyBoot;
    UINT8   UefiBoot;
    UINT8   SkipBbsMenu;
    UINT8   QuietBoot;
    UINT8   FastBoot;
    UINT8   PxeBootOnce;
    UINT8   UsbBootOnce;
    UINT8   CdRomBootOnce;
    UINT8   HddBootOnce;
    UINT8   BeepOnError;
    UINT8   SetupPromptTimeout;
    UINT8   BootOptionPriority[64];
    UINT8   HddSecurity[32];
    UINT16  CmosData[64];
} TSE_SETUP_VARIABLE;

//
// FixedBootOrder configuration
// Referenced by FixedBootOrderTSE.c strings
//
typedef struct {
    UINT16  DeviceType;
    UINT16  SubClass;
    UINT16  VendorId;
    UINT16  DeviceId;
    UINT8   BusNumber;
    UINT8   DeviceNumber;
    UINT8   FunctionNumber;
    UINT8   Reserved;
} TSE_FIXED_BOOT_DEVICE;

//
// TSE HDD Security device descriptor
// Referenced by ForceHddPassword.c
//
typedef struct {
    UINT16  VendorId;
    UINT16  DeviceId;
    UINT8   BarIndex;
    UINT8   SecurityCap;
    UINT16  PasswordStatus;
    UINT8   SecurityLevel;
    UINT8   MasterCapability;
    UINT8   MasterPasswordId;
    UINT8   Reserved;
} TSE_HDD_SECURITY_ENTRY;

//
// TSE GPIO configuration
//
typedef struct {
    UINT32  Pad;                   // GPIO pad number
    UINT32  Group;                 // GPIO group
    UINT32  Ownership;             // Host vs. PMC ownership
    UINT32  Config;                // Configuration register value
} TSE_GPIO_CONFIG;

//
// TSE Progress bar configuration
// Used by TseDrawProgressBar at 0x32A0
//
#define TSE_PROGRESS_BAR_WIDTH  40
#define TSE_PROGRESS_BAR_HEIGHT 4

//
// Known TSE version string
// Set by TseSetupTitleVersion at 0x120C
//
#define TSE_TITLE_FORMAT       L"Aptio Setup Utility - Copyright (C) %04x American Megatrends, Inc."
#define TSE_VERSION_FORMAT     L"Version %x.%02x.%04x. Copyright (C) %04x American Megatrends, Inc."

//
// TSE callback IDs used with TseInvokeCallbackOrDirect
//
#define TSE_CALLBACK_ENTER_SETUP       4294901761  // 0xFFFF0001
#define TSE_CALLBACK_PROCEED_TO_BOOT   4294901762  // 0xFFFF0002
#define TSE_CALLBACK_DRIVER_HEALTH     4294901763  // 0xFFFF0003
#define TSE_CALLBACK_LOAD_OPTIONS      4294901764  // 0xFFFF0004
#define TSE_CALLBACK_BOOT_NEXT         4294901765  // 0xFFFF0005
#define TSE_CALLBACK_NULL              4294901766  // 0xFFFF0006
#define TSE_CALLBACK_ENTRY_SETUP       4294901787  // 0xFFFF001B - Entry setup
#define TSE_CALLBACK_AFTER_SETUP       4294901788  // 0xFFFF001C - After setup
#define TSE_CALLBACK_DEBUG_SWITCH      4294901798  // 0xFFFF0026 - Debug switch

//
// TSE protocol interface (AMITSE_PROTOCOL)
// Installed at qword_66D18
//
typedef
EFI_STATUS
(EFIAPI *AMITSE_ENTRY_POINT)(
    VOID
    );

typedef
EFI_STATUS
(EFIAPI *AMITSE_SETUP_PAGE)(
    UINT16  FormId,
    UINT16  VariableId,
    UINTN   Callback
    );

typedef
EFI_STATUS
(EFIAPI *AMITSE_POPUP_MESSAGE)(
    UINT16      StringId,
    UINT16      Timeout,
    UINT16      Flags,
    UINT32      *UserResponse
    );

struct _AMITSE_PROTOCOL {
    UINT64              Signature;          // AMITSE protocol signature
    AMITSE_ENTRY_POINT  EntryPoint;         // Enter setup
    AMITSE_SETUP_PAGE   ShowSetupPage;      // Display setup page
    AMITSE_POPUP_MESSAGE ShowPopup;         // Show popup message
    AMITSE_ENTRY_POINT  Refresh;            // Refresh current page
    // Additional methods follow...
};

#pragma pack(pop)

//
// Global variable declarations
//
extern EFI_SYSTEM_TABLE        *gST;
extern EFI_BOOT_SERVICES       *gBS;
extern EFI_RUNTIME_SERVICES    *gRT;
extern UINT64                  gImageHandle;
extern UINT64                  SystemTable_0;
extern UINT64                  BootServices_0;
extern UINT64                  RuntimeServices_0;
extern UINT64                  n6;               // Menu timeout value
extern UINT64                  qword_66D18;      // AMITSE protocol instance
extern UINT64                  qword_66D48;      // Boot option array
extern UINT64                  qword_66D10;      // Menu storage buffer
extern UINT64                  qword_66CA0;      // Debug/ConOut protocol
extern UINT64                  qword_66CB0;      // MmPciBase protocol
extern UINT64                  qword_66CF0;      // IPMI protocol
extern UINT64                  qword_66D60;      // Console handle
extern UINT64                  qword_66D70;      // GOP handle
extern UINT64                  qword_66D80;      // Timer event
extern UINT64                  qword_64160;      // Screen row stride
extern UINT64                  qword_74780;      // Menu database base
extern UINT64                  qword_74798;      // TSE_MENU_STATE
extern UINT64                  qword_747A0;      // Setup data buffer
extern UINT64                  qword_747A8;      // HII package list handle
extern UINT64                  qword_747B0;      // Setup variable store
extern UINT64                  qword_747C0;      // Boot option list
extern UINT64                  qword_74758;      // Language count
extern UINT64                  qword_74760;      // Language table
extern UINT64                  qword_746C8;      // Menu entry count pointer
extern UINT64                  qword_746F0;      // Menu database base copy
extern UINT64                  qword_746B0;      // Formset base
extern UINT64                  qword_746A0;      // Option block base
extern UINT64                  qword_746A8;      // Default block base
extern UINT64                  qword_746B8;      // Option block (copy)
extern UINT64                  qword_74690;      // Menu key base
extern UINT64                  qword_746C0;      // Form block base
extern UINT64                  qword_746D0;      // Form block (copy)
extern UINT64                  qword_746E0;      // Current form pointer
extern UINT64                  qword_746E8;      // Variable block base
extern UINT64                  qword_746F8;      // Default block base copy
extern UINT64                  qword_74748;      // Callback table pointer
extern UINT64                  qword_74750;      // Language selection
extern UINT64                  qword_74740;      // Boot option ready flag
extern UINT16                  word_747B8;       // Current boot option
extern UINT64                  qword_74770;      // PCI enumeration state
extern UINT16                  word_74710;       // Disable character
extern UINT16                  word_74720;       // Enable character
extern UINT64                  qword_66DB0;      // Cursor row
extern UINT64                  n9_0;             // Cursor column
extern UINT8                   byte_66D00;       // BBS menu flag
extern UINT8                   byte_66D28;       // Timeout reachable flag
extern UINT8                   byte_66D51;       // Boot ready flag
extern UINT8                   byte_66D68;       // Boot menu skip flag
extern UINT8                   byte_66D78;       // Skip menu flag
extern UINT8                   byte_66DC8;       // Setup active flag
extern UINT8                   byte_64168;       // TSE installed flag
extern UINT32                  dword_66D08;      // Current boot entry index
extern UINT64                  qword_67008;      // ConSpl (console splitter)

#endif // __AMITSE_H__