/****************************************************************
 ****************************************************************
 **                                                            **
 **    (C)Copyright 2005-2006, American Megatrends Inc.        **
 **                                                            **
 **            All Rights Reserved.                            **
 **                                                            **
 **        6145-F, Northbelt Parkway, Norcross,                **
 **                                                            **
 **        Georgia - 30071, USA. Phone-(770)-246-8600.         **
 **                                                            **
 ****************************************************************
 ****************************************************************
 ****************************************************************
 ******************************************************************
 *
 * ipmi_fru.h
 * IPMI fru structures
 *
 *  Author: Rama Bisa <govindk@ami.com>
 *
 ******************************************************************/
#ifndef IPMI_FRU_H
#define IPMI_FRU_H

#include <stdint.h>

#define FRU_COMMON_HEADER           1
#define FRU_INTERNAL_USE_AREA       2
#define FRU_CHASSIS_INFO_AREA       3
#define FRU_BOARD_INFO_AREA         4
#define FRU_PRODUCT_INFO_AREA       5
#define FRU_MULTI_RECORD_AREA       6
#define FRU_MULTI_RECORD_HEADER     FRU_MULTI_RECORD_AREA
#define FRU_MULTI_RECORD_DATA       7

#define FRU_END_OF_RECORD           0xF

#define FRU_BLOCK_SIZE              8

#pragma pack(1)

/* FRUInventoryAreaInfoReq_T */
typedef struct
{
    uint8_t FRUDeviceID;  /* 0xff is reserved */

}   FRUInventoryAreaInfoReq_T;


/* FRUInventoryAreaInfoRes_T */
typedef struct
{
    uint8_t   CompletionCode;
    uint16_t  Size;
    uint8_t   DeviceAccessMode;

}   FRUInventoryAreaInfoRes_T;


/* FRUReadReq_T */
typedef struct
{
    uint8_t   FRUDeviceID;
    uint16_t  Offset;
    uint8_t   CountToRead;

}   FRUReadReq_T;


/* FRUReadRes_T */
typedef struct
{
    uint8_t   CompletionCode;
    uint8_t   CountReturned;

}   FRUReadRes_T;


/* FRUWriteReq_T */
typedef struct
{
    uint8_t   FRUDeviceID;
    uint16_t  Offset;

}   FRUWriteReq_T;


/* FRUWriteRes_T */
typedef struct
{
    uint8_t   CompletionCode;
    uint8_t   CountWritten;

}   FRUWriteRes_T;

/**************************************************************/
/* FRU Data structures */
/**************************************************************/

/* Common Header */
typedef struct
{
    uint8_t   CommonHeaderFormatVersion;
    uint8_t   InternalUseAreaStartOffset; /* In multiple of 8 bytes. 0 means area not present */
    uint8_t   ChassisInfoAreaStartOffset; /* In multiple of 8 bytes. 0 means area not present */
    uint8_t   BoardInfoAreaStartOffset; 	/* In multiple of 8 bytes. 0 means area not present */
    uint8_t   ProductInfoAreaStartOffset; /* In multiple of 8 bytes. 0 means area not present */
    uint8_t   MultiRecordAreaStartOffset; /* In multiple of 8 bytes. 0 means area not present */
    uint8_t   PAD;			/* 0x00 */
    uint8_t   ZeroChecksum;		/* Common Header Zero checksum */
}   FRUCommonHeader_T;

/* Internal Use Area */
typedef struct
{
    uint8_t   FormatVersion;
    uint8_t   *Data;
}   FRUInternalInfo_T;

/* Chassis Info Area */
typedef enum
{
    Other = 0x01,
    ChassisUnknown,
    Desktop,
    LowProfileDesktop,
    PizzaBox,
    MiniTower,
    Tower,
    Portable,
    LapTop,
    Notebook,
    HandHeld,
    DockingStation,
    AllinOne,
    SubNotebook,
    SpaceSaving,
    LunchBox,
    MainServerChassis,
    ExpansionChassis,
    SubChassis,
    BusExpansionChassis,
    PeripheralChassis,
    RAIDChassis,
    RackMountChassis
} ChassisType_T;

typedef struct
{
    uint8_t		ChassisInfoAreaFormatVersion;
    uint8_t		ChassisInfoAreaLength;	/* In multiple of 8 bytes. */
    uint8_t		*ChassisType;
    uint8_t   		ChassisPartNumTypeLength;
    uint8_t   		*ChassisPartNum;
    uint8_t   		ChassisSerialNumTypeLength;
    uint8_t   		*ChassisSerialNum;
    uint8_t   		**CustomFields;
    uint8_t           Total_Chassis_CustomField;
}   FRUChassisInfo_T;

/* Board Info Area */
typedef enum
{
    English = 0
} LanguageType_T;

typedef struct
{
    uint8_t		BoardInfoAreaFormatVersion;
    uint8_t		BoardInfoAreaLength;	/* In multiple of 8 bytes. */
    uint8_t		Language;
    uint8_t   		MfgDateTime[3];
    uint8_t   		BoardMfrTypeLength;
    uint8_t   		*BoardMfr;
    uint8_t   		BoardProductNameTypeLength;
    uint8_t   		*BoardProductName;
    uint8_t   		BoardSerialNumTypeLength;
    uint8_t   		*BoardSerialNum;
    uint8_t   		BoardPartNumTypeLength;
    uint8_t   		*BoardPartNum;
    uint8_t   		FRUFileIDTypeLength;
    uint8_t   		*FRUFileID;
    uint8_t   		**CustomFields;
    uint8_t           Total_Board_CustomField;

}   FRUBoardInfo_T;

/* Product Info Area */
typedef struct
{
    uint8_t		ProductInfoAreaFormatVersion;
    uint8_t		ProductInfoAreaLength;	/* In multiple of 8 bytes. */
    uint8_t		Language;
    uint8_t   		MfrNameTypeLength;
    uint8_t   		*MfrName;
    uint8_t   		ProductNameTypeLength;
    uint8_t   		*ProductName;
    uint8_t   		ProductPartNumTypeLength;
    uint8_t   		*ProductPartNum;
    uint8_t   		ProductVersionTypeLength;
    uint8_t   		*ProductVersion;
    uint8_t   		ProductSerialNumTypeLength;
    uint8_t   		*ProductSerialNum;
    uint8_t   		AssetTagTypeLength;
    uint8_t   		*AssetTag;
    uint8_t   		FRUFileIDTypeLength;
    uint8_t   		*FRUFileID;
    uint8_t   		**CustomFields;
    uint8_t           Total_Product_CustomField;
}   FRUProductInfo_T;

/* MultiRecord Area */

typedef enum
{
    PowerSupplyInformation,
    DCOutput,
    DCLoad,
    ManagementAccessRecord,
    BaseCompatibilityRecord,
    ExtendedCompatibilityRecord
} RecordType_T;

typedef struct
{
    uint16_t	OverallCapacity;
    uint16_t	PeakVA;
    uint8_t	InrushCurrent;
    uint8_t	InrushIntervalinMSecs;
    uint16_t	LowEndInVoltageRange1;	/* 10mV */
    uint16_t	HighEndInVoltageRange1;	/* 10mV */
    uint16_t	LowEndInVoltageRange2;	/* 10mV. 0 if single range */
    uint16_t	HighEndInVoltageRange2;	/* 10mV. 0 if single range */
    uint8_t	LowEndInFreqRange;
    uint8_t	HighEndInFreqRange;
    uint8_t	ACDropoutToleranceinMSecs;
    uint8_t	FlagsPolarity;
    uint16_t	PeakWattage;
    uint8_t	CombinedWattage[3];
    uint8_t	TechMtrLowerThresh;
}   PowerSupplyInformation_T;

typedef struct
{
    uint8_t	OutputInfo;
    uint16_t	NominalVoltage;		/* 10mV */
    uint16_t	MaxNegVolDeviation;	/* 10mV */
    uint16_t	MaxPosVolDeviation;	/* 10mV */
    uint16_t	RippleNoise;		/* mV */
    uint16_t	MinCurrentDraw;		/* mA */
    uint16_t	MaxCurrentDraw;		/* mA */
}   DCOutput_T;

typedef struct
{
    uint8_t	VoltageReqd;
    uint16_t	NominalVoltage;		/* 10mV */
    uint16_t	SpecdMinVoltage;	/* 10mV */
    uint16_t	SpecdMaxVoltage;	/* 10mV */
    uint16_t	SpecdRippleNoise;	/* mV */
    uint16_t	MinCurrentLoad;		/* mA */
    uint16_t	MaxCurrentLoad;		/* mA */
}   DCLoad_T;

typedef struct
{
    uint8_t		RecordTypeID;
    uint8_t		RecordFormatVersionEOL;
    uint8_t		RecordLength;
    uint8_t		RecordChecksum;	/* zero checksum */
    uint8_t		HeaderChecksum;	/* zero checksum */
    uint8_t		*RecordData;
}   MultiRecordHeader_T;

typedef struct
{
    MultiRecordHeader_T	RecordHeader;
    uint8_t		*RecordData;
}   Record_T;

#define	MAX_MULTIRECORDS	64
typedef struct
{
    Record_T	MultiRecordsData[MAX_MULTIRECORDS];
}   FRUMultiRecordInfo_T;

/* Complete FRU Data */
typedef struct
{
    FRUCommonHeader_T   	CommonHeader;
    FRUInternalInfo_T		InternalInfo;
    FRUChassisInfo_T		ChassisInfo;
    FRUBoardInfo_T			BoardInfo;
    FRUProductInfo_T		ProductInfo;
    FRUMultiRecordInfo_T 	MultiRecordInfo;
}   FRUData_T;

#pragma pack()

#endif  /* IPMI_FRU_H */
