Skip to content

Commit

Permalink
fsp: endian conversions
Browse files Browse the repository at this point in the history
Reviewed-by: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
  • Loading branch information
npiggin authored and oohal committed Dec 16, 2019
1 parent 390c4f5 commit e3934d8
Show file tree
Hide file tree
Showing 32 changed files with 431 additions and 359 deletions.
4 changes: 2 additions & 2 deletions hw/fsp/fsp-attn.c
Expand Up @@ -106,8 +106,8 @@ static void update_sp_attn_area(const char *msg)
backtrace_print(bt_buf, &metadata, ti_attn->msg.bt_buf, &len, false);
snprintf(ti_attn->msg.file_info, FILE_INFO_LEN, "%s", msg);

ti_attn->msg_len = VERSION_LEN + BT_FRAME_LEN +
strlen(ti_attn->msg.file_info);
ti_attn->msg_len = cpu_to_be32(VERSION_LEN + BT_FRAME_LEN +
strlen(ti_attn->msg.file_info));
}

void __attribute__((noreturn)) ibm_fsp_terminate(const char *msg)
Expand Down
48 changes: 26 additions & 22 deletions hw/fsp/fsp-codeupdate.c
Expand Up @@ -148,9 +148,11 @@ static void got_code_update_policy(uint32_t param_id __unused, int err_len,
if (err_len != 4) {
log_simple_error(&e_info(OPAL_RC_CU_INIT), "CUPD: Error "
"retrieving code update policy: %d\n", err_len);
} else
} else {
update_policy = be32_to_cpu((__be32)update_policy);
prlog(PR_NOTICE, "CUPD: Code update policy from FSP: %d\n",
update_policy);
}

dec_in_flight_param();
}
Expand All @@ -175,9 +177,11 @@ static void got_platform_hmc_managed(uint32_t param_id __unused, int err_len,
if (err_len != 4) {
log_simple_error(&e_info(OPAL_RC_CU_INIT), "CUPD: Error "
"retrieving hmc managed status: %d\n", err_len);
} else
} else {
hmc_managed = be32_to_cpu((__be32)hmc_managed);
prlog(PR_NOTICE, "CUPD: HMC managed status from FSP: %d\n",
hmc_managed);
}

dec_in_flight_param();
}
Expand All @@ -198,9 +202,9 @@ static void get_platform_hmc_managed(void)

static bool fw_ipl_side_update_notify(struct fsp_msg *msg)
{
u32 param_id = msg->data.words[0];
int dlen = msg->data.words[1] & 0xffff;
uint32_t state = msg->data.words[2];
u32 param_id = fsp_msg_get_data_word(msg, 0);
int dlen = fsp_msg_get_data_word(msg, 1) & 0xffff;
uint32_t state = fsp_msg_get_data_word(msg, 2);

if (param_id != SYS_PARAM_FW_IPL_SIDE)
return false;
Expand Down Expand Up @@ -322,15 +326,15 @@ static void fetch_lid_data_complete(struct fsp_msg *msg)
int rc;

status = (msg->resp->word1 >> 8) & 0xff;
flags = (msg->data.words[0] >> 16) & 0xff;
id = msg->data.words[0] & 0xffff;
lid_id = msg->data.words[1];
offset = msg->resp->data.words[1];
length = msg->resp->data.words[2];
flags = (fsp_msg_get_data_word(msg, 0) >> 16) & 0xff;
id = fsp_msg_get_data_word(msg, 0) & 0xffff;
lid_id = fsp_msg_get_data_word(msg, 1);
offset = fsp_msg_get_data_word(msg->resp, 1);
length = fsp_msg_get_data_word(msg->resp, 2);

prlog(PR_NOTICE, "CUPD: Marker LID id : size : status = "
"0x%x : 0x%x : 0x%x\n",
msg->data.words[1], msg->resp->data.words[2], status);
fsp_msg_get_data_word(msg, 1), fsp_msg_get_data_word(msg->resp, 2), status);

fsp_freemsg(msg);

Expand Down Expand Up @@ -783,7 +787,7 @@ static int validate_candidate_image(uint64_t buffer,
memcpy(validate_buf, (void *)buffer, VALIDATE_BUF_SIZE);
header = (struct update_image_header *)validate_buf;

if (validate_magic_num(be32_to_cpu(header->magic)) != 0) {
if (validate_magic_num(be16_to_cpu(header->magic)) != 0) {
*result = VALIDATE_INVALID_IMG;
rc = OPAL_SUCCESS;
goto out;
Expand Down Expand Up @@ -936,14 +940,15 @@ static int validate_ipl_side(void)
}

static int64_t fsp_opal_validate_flash(uint64_t buffer,
uint32_t *size, uint32_t *result)
__be32 *size, __be32 *result)
{
int64_t rc = 0;
int offset;
uint32_t r;

lock(&flash_lock);

rc = validate_candidate_image(buffer, *size, result);
rc = validate_candidate_image(buffer, be32_to_cpu(*size), &r);
/* Fill output buffer
*
* Format:
Expand All @@ -952,16 +957,15 @@ static int64_t fsp_opal_validate_flash(uint64_t buffer,
* ML<sp>current-T-image<sp>current-P-image<0x0A>
* ML<sp>new-T-image<sp>new-P-image<0x0A>
*/
if (!rc && (*result != VALIDATE_FLASH_AUTH &&
*result != VALIDATE_INVALID_IMG)) {
if (!rc && (r != VALIDATE_FLASH_AUTH && r != VALIDATE_INVALID_IMG)) {
/* Clear output buffer */
memset((void *)buffer, 0, VALIDATE_BUF_SIZE);

offset = validate_out_buf_mi_data((void *)buffer, 0, *result);
offset += validate_out_buf_ml_data((void *)buffer,
offset, *result);
*size = offset;
offset = validate_out_buf_mi_data((void *)buffer, 0, r);
offset += validate_out_buf_ml_data((void *)buffer, offset, r);
*size = cpu_to_be32(offset);
}
*result = cpu_to_be32(r);

unlock(&flash_lock);
return rc;
Expand Down Expand Up @@ -1125,7 +1129,7 @@ static int64_t validate_sglist(struct opal_sg_list *list)
return OPAL_PARAMETER;

/* All non-terminal entries size must be aligned */
if (prev_entry && (prev_entry->length & 0xfff))
if (prev_entry && (be64_to_cpu(prev_entry->length) & 0xfff))
return OPAL_PARAMETER;

prev_entry = entry;
Expand Down Expand Up @@ -1200,7 +1204,7 @@ static bool code_update_notify(uint32_t cmd_sub_mod, struct fsp_msg *msg)
case FSP_CMD_FLASH_CACHE:
cmd = FSP_CMD_FLASH_CACHE_RSP;
prlog(PR_NOTICE, "CUPD: Update LID cache event [data = 0x%x]\n",
msg->data.words[0]);
fsp_msg_get_data_word(msg, 0));
break;
case FSP_CMD_FLASH_OUTC:
case FSP_CMD_FLASH_OUTR:
Expand Down
86 changes: 43 additions & 43 deletions hw/fsp/fsp-codeupdate.h
Expand Up @@ -76,17 +76,17 @@ struct fw_image_vpd {
struct master_lid_header {
char key[3]; /* "MLH" */
uint8_t version; /* 0x02 */
uint16_t header_size;
uint16_t entry_size;
__be16 header_size;
__be16 entry_size;
uint8_t reserved[56];
};

/* LID index entry */
struct lid_index_entry {
uint32_t id;
uint32_t size;
uint32_t offset;
uint32_t crc;
__be32 id;
__be32 size;
__be32 offset;
__be32 crc;
};

/* SP flags */
Expand All @@ -99,7 +99,7 @@ struct lid_index_entry {
* sp_flag addr = header->data + header->ext_fw_id_size
*/
struct update_image_ga_date {
uint32_t sp_flag;
__be32 sp_flag;
char sp_ga_date[8]; /* YYYYMMDD */
};

Expand All @@ -108,39 +108,39 @@ struct update_image_ga_date {

/* Image header structure */
struct update_image_header {
uint16_t magic;
uint16_t version;
uint32_t package_size;
uint32_t crc;
uint16_t lid_index_offset;
uint16_t number_lids;
uint16_t package_flags;
uint16_t mi_keyword_size;
__be16 magic;
__be16 version;
__be32 package_size;
__be32 crc;
__be16 lid_index_offset;
__be16 number_lids;
__be16 package_flags;
__be16 mi_keyword_size;
char mi_keyword_data[40];
uint16_t ext_fw_id_size;
__be16 ext_fw_id_size;
/* Rest of the image data including ext fw id, sp flags */
char data[];
};

/* FipS header */
struct fips_header {
uint16_t magic;
uint16_t version;
uint32_t lid_id;
uint32_t lid_date; /* YYYYMMDD */
uint16_t lid_time; /* HHMM */
uint16_t lid_class;
uint32_t crc;
uint32_t lid_size; /* Number of bytes below header */
uint32_t header_size;
__be16 magic;
__be16 version;
__be32 lid_id;
__be32 lid_date; /* YYYYMMDD */
__be16 lid_time; /* HHMM */
__be16 lid_class;
__be32 crc;
__be32 lid_size; /* Number of bytes below header */
__be32 header_size;
uint8_t mtd_number;
uint8_t valid; /* 1 = valid, 0 = invalid */
uint8_t reserved;
uint8_t lid_info_size;
char lid_info[64]; /* code level */
uint32_t update_date; /* YYYYMMDD */
uint16_t update_time; /* HHMM */
uint16_t phylum_len;
__be32 update_date; /* YYYYMMDD */
__be16 update_time; /* HHMM */
__be16 phylum_len;
uint8_t lid_phylum[];
};

Expand All @@ -165,30 +165,30 @@ struct fips_header {
* not all ADF sections in common marker LID.
*/
struct com_marker_header {
uint32_t version;
uint32_t MI_offset; /* Offset to MI section */
uint32_t iseries_offset;
__be32 version;
__be32 MI_offset; /* Offset to MI section */
__be32 iseries_offset;
};

/* MI Keyword section */
struct com_marker_mi_section {
uint32_t MI_size;
__be32 MI_size;
char mi_keyword[40]; /* MI Keyword */
char lst_disrupt_fix_lvl[3];
char skip[21]; /* Skip not interested fields */
uint32_t adf_offset; /* Offset to ADF section */
__be32 adf_offset; /* Offset to ADF section */
};

/* Additional Data Fields */
struct com_marker_adf_sec {
uint32_t adf_cnt; /* ADF count */
__be32 adf_cnt; /* ADF count */
char adf_data[]; /* ADF data */
};

/* ADF common header */
struct com_marker_adf_header {
uint32_t size; /* Section size */
uint32_t name; /* Section name */
__be32 size; /* Section size */
__be32 name; /* Section name */
};

/*
Expand All @@ -200,9 +200,9 @@ struct com_marker_adf_header {
struct com_marker_adf_sp
{
struct com_marker_adf_header header;
uint32_t sp_name_offset; /* Offset from start of ADF */
uint32_t sp_name_size;
uint32_t skip[4]; /* Skip rest of fields */
__be32 sp_name_offset; /* Offset from start of ADF */
__be32 sp_name_size;
__be32 skip[4]; /* Skip rest of fields */
};

/*
Expand All @@ -213,10 +213,10 @@ struct com_marker_adf_sp
#define ADF_NAME_FW_IP 0x46495050 /* FIPP */
struct com_marker_fw_ip {
struct com_marker_adf_header header;
uint32_t sp_flag_offset; /* Offset from start of ADF */
uint32_t sp_flag_size;
uint32_t sp_ga_offset; /* Offset from start of ADF*/
uint32_t sp_ga_size;
__be32 sp_flag_offset; /* Offset from start of ADF */
__be32 sp_flag_size;
__be32 sp_ga_offset; /* Offset from start of ADF*/
__be32 sp_ga_size;
};

#endif /* __CODEUPDATE_H */

0 comments on commit e3934d8

Please sign in to comment.