oem-ibm: Send the event to host when BIOS attribute changes

IBM has the requirement to send a hot update to host when the
BIOS attribute changes. This patch enables sending an OEM platform
event message to host with the details of the BIOS attributes that
changed on the BMC. Once the host acknowledges the event, then BMC
updates the BaseBiosTable in the bios-config-manager. The host comes
down and reads the changed BIOS attributes by calling the command
GetBIOSAttribute value.

Signed-off-by: Tom Joseph <tomjoseph@in.ibm.com>
Change-Id: Id1579bfed1967e653da743313c825b765d227681
diff --git a/oem/ibm/libpldm/platform_oem_ibm.c b/oem/ibm/libpldm/platform_oem_ibm.c
new file mode 100644
index 0000000..1cf7e86
--- /dev/null
+++ b/oem/ibm/libpldm/platform_oem_ibm.c
@@ -0,0 +1,52 @@
+#include "platform_oem_ibm.h"

+#include "platform.h"

+#include <string.h>

+

+int encode_bios_attribute_update_event_req(uint8_t instance_id,

+					   uint8_t format_version, uint8_t tid,

+					   uint8_t num_handles,

+					   const uint8_t *list_of_handles,

+					   size_t payload_length,

+					   struct pldm_msg *msg)

+{

+	struct pldm_header_info header = {0};

+	int rc = PLDM_SUCCESS;

+

+	header.msg_type = PLDM_REQUEST;

+	header.instance = instance_id;

+	header.pldm_type = PLDM_PLATFORM;

+	header.command = PLDM_PLATFORM_EVENT_MESSAGE;

+

+	if (format_version != 1) {

+		return PLDM_ERROR_INVALID_DATA;

+	}

+

+	if (msg == NULL || list_of_handles == NULL) {

+		return PLDM_ERROR_INVALID_DATA;

+	}

+

+	if (num_handles == 0) {

+		return PLDM_ERROR_INVALID_DATA;

+	}

+

+	if (payload_length !=

+	    (PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES + sizeof(num_handles) +

+	     (num_handles * sizeof(uint16_t)))) {

+		return PLDM_ERROR_INVALID_LENGTH;

+	}

+

+	if ((rc = pack_pldm_header(&header, &(msg->hdr))) > PLDM_SUCCESS) {

+		return rc;

+	}

+

+	struct pldm_bios_attribute_update_event_req *request =

+	    (struct pldm_bios_attribute_update_event_req *)msg->payload;

+	request->format_version = format_version;

+	request->tid = tid;

+	request->event_class = PLDM_EVENT_TYPE_OEM_EVENT_BIOS_ATTRIBUTE_UPDATE;

+	request->num_handles = num_handles;

+	memcpy(request->bios_attribute_handles, list_of_handles,

+	       num_handles * sizeof(uint16_t));

+

+	return PLDM_SUCCESS;

+}
\ No newline at end of file
diff --git a/oem/ibm/libpldm/platform_oem_ibm.h b/oem/ibm/libpldm/platform_oem_ibm.h
new file mode 100644
index 0000000..7d918e7
--- /dev/null
+++ b/oem/ibm/libpldm/platform_oem_ibm.h
@@ -0,0 +1,56 @@
+#ifndef PLATFORM_OEM_IBM_H

+#define PLATFORM_OEM_IBM_H

+

+#ifdef __cplusplus

+extern "C" {

+#endif

+

+#include "base.h"

+#include <stddef.h>

+#include <stdint.h>

+

+enum pldm_event_types_ibm_oem {

+	PLDM_EVENT_TYPE_OEM_EVENT_BIOS_ATTRIBUTE_UPDATE = 0xF0,

+};

+

+/** @struct pldm_bios_attribute_update_event_req

+ *

+ * 	Structure representing PlatformEventMessage command request data for OEM

+ *  event type BIOS attribute update.

+ */

+struct pldm_bios_attribute_update_event_req {

+	uint8_t format_version;

+	uint8_t tid;

+	uint8_t event_class;

+	uint8_t num_handles;

+	uint8_t bios_attribute_handles[1];

+} __attribute__((packed));

+

+/** @brief Encode PlatformEventMessage request data for BIOS attribute update

+ *

+ *  @param[in] instance_id - Message's instance id

+ *  @param[in] format_version - Version of the event format

+ *  @param[in] tid - Terminus ID for the terminus that originated the event

+ *                   message

+ *  @param[in] num_handles - Number of BIOS handles with an update

+ *  @param[in] list_of_handles - Pointer to the list of BIOS attribute handles

+ *  @param[in] payload_length - Length of request message payload

+ *  @param[out] msg - Message will be written to this

+ *

+ *  @return pldm_completion_codes

+ *

+ *  @note  Caller is responsible for memory alloc and dealloc of param

+ *         'msg.payload'

+ */

+int encode_bios_attribute_update_event_req(uint8_t instance_id,

+					   uint8_t format_version, uint8_t tid,

+					   uint8_t num_handles,

+					   const uint8_t *list_of_handles,

+					   size_t payload_length,

+					   struct pldm_msg *msg);

+

+#ifdef __cplusplus

+}

+#endif

+

+#endif /* PLATFORM_OEM_IBM_H */
\ No newline at end of file