/** @file
HddSmart.h -- Header for HddSmart
Copyright (c) HR650X BIOS Decompilation Project
**/
#ifndef __HDDSMART_H__
#define __HDDSMART_H__
#include "../uefi_headers/Uefi.h"
//
// Function Prototypes
//
EFI_STATUS
EFIAPI
HddSmartInternalAllocateBuffer(
VOID
);
EFI_STATUS
EFIAPI
HddSmartInternalFreeBuffer(
VOID
);
EFI_STATUS
EFIAPI
LShiftU64(
VOID
);
EFI_STATUS
EFIAPI
ReadUnaligned64(
VOID
);
EFI_STATUS
EFIAPI
CompareHobGuid(
VOID
);
EFI_STATUS
EFIAPI
HddSmartInitHobList(
VOID
);
EFI_STATUS
EFIAPI
HddSmartGetDebugLevel(
VOID
);
EFI_STATUS
EFIAPI
HddSmartDebugPrint(
VOID
);
EFI_STATUS
EFIAPI
HddSmartAssert(
VOID
);
EFI_STATUS
EFIAPI
HddSmartAtaCommand(
VOID
);
EFI_STATUS
EFIAPI
HddSmartBlockIoRead(
VOID
);
EFI_STATUS
EFIAPI
HddSmartHiiCallback(
VOID
);
EFI_STATUS
EFIAPI
HddSmartDriverEntry(
VOID
);
EFI_STATUS
EFIAPI
HddSmartTimerPoll(
VOID
);
EFI_STATUS
EFIAPI
HddSmartNotify(
VOID
);
EFI_STATUS
EFIAPI
HddSmartCheckStatus(
VOID
);
EFI_STATUS
EFIAPI
HddSmartUninstall(
VOID
);
EFI_STATUS
EFIAPI
HddSmartGetDeviceName(
VOID
);
EFI_STATUS
EFIAPI
HddSmartStartController(
VOID
);
EFI_STATUS
EFIAPI
HddSmartOpenController(
VOID
);
EFI_STATUS
EFIAPI
HddSmartReadIdentify(
VOID
);
EFI_STATUS
EFIAPI
HddSmartReadSmartData(
VOID
);
EFI_STATUS
EFIAPI
HddSmartBlockIoReadExt(
VOID
);
EFI_STATUS
EFIAPI
HddSmartBlockIoWriteExt(
VOID
);
EFI_STATUS
EFIAPI
HddSmartDeferredTimer(
VOID
);
EFI_STATUS
EFIAPI
ModuleEntryPoint(
VOID
);
EFI_STATUS
EFIAPI
referenced by the driver (defined in .rdata / HII package list)(
VOID
);
EFI_STATUS
EFIAPI
EFI_GUID gHddSmartFormSetGuid;(
VOID
);
EFI_STATUS
EFIAPI
Vendor Device Path (used to publish HII forms)(
VOID
);
EFI_STATUS
EFIAPI
struct {(
VOID
);
EFI_STATUS
EFIAPI
function prototypes (forward declarations)(
VOID
);
EFI_STATUS
EFIAPI
/ BaseLib stubs provided by this module(
VOID
);
EFI_STATUS
EFIAPI
the HOB list to find the system-table HOB.(
VOID
);
EFI_STATUS
EFIAPI
the DXE phase the HOB list is cached elsewhere.(
VOID
);
EFI_STATUS
EFIAPI
/ Protocol cache (sub_2064 family)(
VOID
);
EFI_STATUS
EFIAPI
the boot-services table for a HOB-format entry.(
VOID
);
EFI_STATUS
EFIAPI
Index;(
VOID
);
EFI_STATUS
EFIAPI
}(
VOID
);
EFI_STATUS
EFIAPI
print if the current debug level matches.(
VOID
);
EFI_STATUS
EFIAPI
(gHddSmartInstance == NULL) {(
VOID
);
/// attempt to locate the debug protocol directly.
EFI_STATUS
EFIAPI
instance yet(
VOID
);
EFI_STATUS
EFIAPI
= gBS->LocateProtocol (&gEfiDebugPortProtocolGuid(
VOID
);
EFI_STATUS
EFIAPI
%s to %a in the format string (in-place modification).(
VOID
);
EFI_STATUS
EFIAPI
Pass-through Helpers(
VOID
);
EFI_STATUS
EFIAPI
Pass-through helper (sub_B7C)(
VOID
);
EFI_STATUS
EFIAPI
data-in commands, allocate a bounce buffer and issue the(
VOID
);
EFI_STATUS
EFIAPI
(DataBuffer != NULL && DataSize > 0) {(
VOID
);
EFI_STATUS
EFIAPI
I/O wrapper (sub_5A4)(
VOID
);
EFI_STATUS
EFIAPI
byte count, aligned to 4KB boundary.(
VOID
);
EFI_STATUS
EFIAPI
= 1 << Device->SpinupTime; // Approximate capacity(
VOID
);
EFI_STATUS
EFIAPI
IDENTIFY / READ command.(
VOID
);
EFI_STATUS
EFIAPI
(BlockCount == 1 && Lba == 0) {(
VOID
);
EFI_STATUS
EFIAPI
DEVICE(
VOID
);
EFI_STATUS
EFIAPI
be resolved from the instance(
VOID
);
EFI_STATUS
EFIAPI
callback (sub_D44)(
VOID
);
EFI_STATUS
EFIAPI
a local 512-byte IDENTIFY buffer.(
VOID
);
EFI_STATUS
EFIAPI
(SerialBuf, sizeof (SerialBuf));(
VOID
);
EFI_STATUS
EFIAPI
size for "Setup" variable(
VOID
);
EFI_STATUS
EFIAPI
all drive data: copy IDENTIFY buffer into serial strings.(
VOID
);
EFI_STATUS
EFIAPI
(Index = 0; Index < Instance->DeviceCount; Index++) {(
VOID
);
EFI_STATUS
EFIAPI
the 512-byte IDENTIFY buffer into a 128-byte display area.(
VOID
);
EFI_STATUS
EFIAPI
(SerialBuf, Device->SerialNumber, 40);(
VOID
);
EFI_STATUS
EFIAPI
return status from device.(
VOID
);
EFI_STATUS
EFIAPI
= HddSmartCheckStatus (Device, Action, &PredictedFailure);(
VOID
);
EFI_STATUS
EFIAPI
the "Setup" NVRAM variable to refresh the stored serial numbers.(
VOID
);
EFI_STATUS
EFIAPI
SMART data for all devices.(
VOID
);
EFI_STATUS
EFIAPI
SMART data changed, fire the notification.(
VOID
);
EFI_STATUS
EFIAPI
(!PredictedFailure) {(
VOID
);
EFI_STATUS
EFIAPI
an action variable is set, post a deferred timer event.(
VOID
);
EFI_STATUS
EFIAPI
(Instance->Initialized) {(
VOID
);
EFI_STATUS
EFIAPI
entry point (sub_928)(
VOID
);
EFI_STATUS
EFIAPI
global pointers.(
VOID
);
EFI_STATUS
EFIAPI
(gST == NULL) {(
VOID
);
EFI_STATUS
EFIAPI
the HII Package List protocol on our own image handle.(
VOID
);
EFI_STATUS
EFIAPI
= gBS->OpenProtocol ((
VOID
);
EFI_STATUS
EFIAPI
the HII Database protocol.(
VOID
);
EFI_STATUS
EFIAPI
= gBS->LocateProtocol ((
VOID
);
EFI_STATUS
EFIAPI
the HII package list with the database.(
VOID
);
EFI_STATUS
EFIAPI
= HiiDatabase->NewPackageList ((
VOID
);
EFI_STATUS
EFIAPI
the global instance structure.(
VOID
);
EFI_STATUS
EFIAPI
= gBS->AllocatePool ((
VOID
);
EFI_STATUS
EFIAPI
function pointers.(
VOID
);
EFI_STATUS
EFIAPI
the HII Config Access protocol.(
VOID
);
EFI_STATUS
EFIAPI
= (EFI_HII_CONFIG_ACCESS_PROTOCOL *)gHddSmartInstance;(
VOID
);
EFI_STATUS
EFIAPI
the driver binding protocol.(
VOID
);
EFI_STATUS
EFIAPI
= gBS->InstallMultipleProtocolInterfaces ((
VOID
);
EFI_STATUS
EFIAPI
a notification for driver binding start.(
VOID
);
EFI_STATUS
EFIAPI
= gBS->RegisterProtocolNotify ((
VOID
);
EFI_STATUS
EFIAPI
HII formset package.(
VOID
);
EFI_STATUS
EFIAPI
= gBS->InstallProtocolInterface ((
VOID
);
EFI_STATUS
EFIAPI
timer callback (sub_758)(
VOID
);
EFI_STATUS
EFIAPI
all handles that support Block IO.(
VOID
);
EFI_STATUS
EFIAPI
= gBS->LocateHandleBuffer ((
VOID
);
EFI_STATUS
EFIAPI
the Block IO protocol on this handle.(
VOID
);
EFI_STATUS
EFIAPI
to open ATA Pass-Through on this handle.(
VOID
);
EFI_STATUS
EFIAPI
(gHddSmartInstance->AtaPassThru == NULL) {(
VOID
);
EFI_STATUS
EFIAPI
SMART data into a local buffer and check for failure.(
VOID
);
EFI_STATUS
EFIAPI
(SmartBuf, sizeof (SmartBuf));(
VOID
);
EFI_STATUS
EFIAPI
the first byte for the SMART threshold-exceeded indicator.(
VOID
);
EFI_STATUS
EFIAPI
((SmartBuf[0] & 0x1F) != 0) {(
VOID
);
/// fire the notification.
EFI_STATUS
EFIAPI
failure detected(
VOID
);
EFI_STATUS
EFIAPI
();(
VOID
);
EFI_STATUS
EFIAPI
the local buffer for the next iteration.(
VOID
);
EFI_STATUS
EFIAPI
helper (sub_21C4)(
VOID
);
EFI_STATUS
EFIAPI
a platform SMI protocol is available, use it to signal the BIOS.(
VOID
);
EFI_STATUS
EFIAPI
(gHddSmartInstance != NULL && gHddSmartInstance->Initialized) {(
VOID
);
EFI_STATUS
EFIAPI
the SMI trigger value (0x2080002 = SMI port, 0 = data).(
VOID
);
EFI_STATUS
EFIAPI
= 0x2080002;(
VOID
);
/// send SMI via the ACPI enable register.
EFI_STATUS
EFIAPI
is available(
VOID
);
EFI_STATUS
EFIAPI
(0xB2, 0x2080002);(
VOID
);
EFI_STATUS
EFIAPI
back: open the platform-specific protocol.(
VOID
);
EFI_STATUS
EFIAPI
= HddSmartGetDebugLevel (); // Dummy call to init cache(
VOID
);
EFI_STATUS
EFIAPI
data interpretation (sub_1080 / sub_18D0 / sub_1A60)(
VOID
);
EFI_STATUS
EFIAPI
type 1 (IDENTIFY), check the IDENTIFY data words.(
VOID
);
EFI_STATUS
EFIAPI
(CommandType == 1) {(
VOID
);
EFI_STATUS
EFIAPI
a 49-byte descriptor for SCSI pass-through.(
VOID
);
EFI_STATUS
EFIAPI
RETURN STATUS(
VOID
);
EFI_STATUS
EFIAPI
code(
VOID
);
EFI_STATUS
EFIAPI
control(
VOID
);
EFI_STATUS
EFIAPI
page code(
VOID
);
EFI_STATUS
EFIAPI
the SCSI pass-through command if available.(
VOID
);
EFI_STATUS
EFIAPI
(Device->SmartCapable == 1) {(
VOID
);
EFI_STATUS
EFIAPI
call ExtScsiPassThru(
VOID
);
EFI_STATUS
EFIAPI
if the device supports SMART (word 64 of IDENTIFY data).(
VOID
);
EFI_STATUS
EFIAPI
(Device->SmartCapable) {(
VOID
);
EFI_STATUS
EFIAPI
type 2, issue the SMART READ DATA command.(
VOID
);
EFI_STATUS
EFIAPI
(Buffer, sizeof (Buffer));(
VOID
);
EFI_STATUS
EFIAPI
word 0 (offline data structure revision) for threshold-exceeded.(
VOID
);
EFI_STATUS
EFIAPI
protocol callback wrapper (sub_1624)(
VOID
);
EFI_STATUS
EFIAPI
dispatch / I/O wrapper (sub_16A0)(
VOID
);
EFI_STATUS
EFIAPI
SMART feature: READ LOG(
VOID
);
EFI_STATUS
EFIAPI
Binding start callback (sub_1714)(
VOID
);
EFI_STATUS
EFIAPI
a 49-byte SCSI pass-through descriptor for IDENTIFY.(
VOID
);
EFI_STATUS
EFIAPI
(Desc, sizeof (Desc));(
VOID
);
EFI_STATUS
EFIAPI
feature: IDENTIFY(
VOID
);
EFI_STATUS
EFIAPI
page length(
VOID
);
EFI_STATUS
EFIAPI
the ATA pass-through command.(
VOID
);
EFI_STATUS
EFIAPI
HddSmartCheckStatus (&Instance->Devices[0], 1, &SmartEnabled);(
VOID
);
EFI_STATUS
EFIAPI
Binding open controller (sub_17B4)(
VOID
);
EFI_STATUS
EFIAPI
IDE/legacy or RAID, issue a direct ATA READ SECTORS.(
VOID
);
EFI_STATUS
EFIAPI
HddSmartBlockIoRead (&Instance->Devices[0], 0, 1, *Buffer, NULL);(
VOID
);
EFI_STATUS
EFIAPI
native (AHCI), use the SCSI pass-through descriptor.(
VOID
);
EFI_STATUS
EFIAPI
/ flags(
VOID
);
EFI_STATUS
EFIAPI
high byte(
VOID
);
EFI_STATUS
EFIAPI
feature: READ DATA(
VOID
);
EFI_STATUS
EFIAPI
bytes zeroed by ZeroMem above(
VOID
);
EFI_STATUS
EFIAPI
identify data (sub_18D0)(
VOID
);
EFI_STATUS
EFIAPI
a 512-byte buffer for IDENTIFY data.(
VOID
);
EFI_STATUS
EFIAPI
= gBS->AllocatePool (EfiBootServicesData, 512, &Buffer);(
VOID
);
EFI_STATUS
EFIAPI
the SCSI pass-through descriptor.(
VOID
);
EFI_STATUS
EFIAPI
DATA(
VOID
);
EFI_STATUS
EFIAPI
the power-on hours nibble at offset 363 (word 181).(
VOID
);
EFI_STATUS
EFIAPI
= ((UINT8 *)Buffer)[363] >> 4;(
VOID
);
EFI_STATUS
EFIAPI
useful data; compute from word 0.(
VOID
);
/// mark as -1.
EFI_STATUS
EFIAPI
data(
VOID
);
EFI_STATUS
EFIAPI
path.(
VOID
);
EFI_STATUS
EFIAPI
SMART data (sub_1A70)(
VOID
);
EFI_STATUS
EFIAPI
whether the flag byte indicates we should use the(
VOID
);
EFI_STATUS
EFIAPI
pass-through or the direct ATA command path.(
VOID
);
EFI_STATUS
EFIAPI
the 49-byte SCSI pass-through descriptor.(
VOID
);
EFI_STATUS
EFIAPI
ENABLE OPERATIONS(
VOID
);
EFI_STATUS
EFIAPI
the command via the protocol callback.(
VOID
);
EFI_STATUS
EFIAPI
= HddSmartCheckStatus (Device, 1, &Predicted);(
VOID
);
EFI_STATUS
EFIAPI
I/O wrapper (sub_1BFC)(
VOID
);
EFI_STATUS
EFIAPI
HddSmartBlockIoRead (&Instance->Devices[0], 0(
VOID
);
EFI_STATUS
EFIAPI
command via the Ext SCSI Pass Thru protocol.(
VOID
);
EFI_STATUS
EFIAPI
(Instance->Devices[0].ControllerType == 1) {(
VOID
);
EFI_STATUS
EFIAPI
read to init(
VOID
);
EFI_STATUS
EFIAPI
I/O write wrapper (sub_1D34)(
VOID
);
EFI_STATUS
EFIAPI
timer callback (sub_1E70)(
VOID
);
EFI_STATUS
EFIAPI
module entry point(
VOID
);
EFI_STATUS
EFIAPI
and UefiRuntimeServicesTableLib(
VOID
);
EFI_STATUS
EFIAPI
(handled by constructor in the library).(
VOID
);
EFI_STATUS
EFIAPI
also initialise our module-level copies.(
VOID
);
EFI_STATUS
EFIAPI
HddSmartDriverEntry (ImageHandle, SystemTable);(
VOID
);
EFI_STATUS
EFIAPI
functions(
VOID
);
/// copy backward.
EFI_STATUS
EFIAPI
and source precedes destination(
VOID
);
EFI_STATUS
EFIAPI
+= n;(
VOID
);
EFI_STATUS
EFIAPI
both buffers are large enough and well-spaced, use 64-bit copies.(
VOID
);
EFI_STATUS
EFIAPI
(n >= 8 && ((UINTN)Src8 - (UINTN)Dst8 >= 8 ||(
VOID
);
EFI_STATUS
EFIAPI
source to 8 bytes if needed.(
VOID
);
EFI_STATUS
EFIAPI
= (UINTN)Src8 & 7;(
VOID
);
EFI_STATUS
EFIAPI
both pointers to 8-byte boundary.(
VOID
);
EFI_STATUS
EFIAPI
(!Backward) {(
VOID
);
EFI_STATUS
EFIAPI
8 bytes at a time.(
VOID
);
EFI_STATUS
EFIAPI
= n >> 3;(
VOID
);
#endif /* __HDDSMART_H__ */