diff options
32 files changed, 431 insertions, 359 deletions
diff --git a/hw/fsp/fsp-attn.c b/hw/fsp/fsp-attn.c index 2c0260c..e121d8a 100644 --- a/hw/fsp/fsp-attn.c +++ b/hw/fsp/fsp-attn.c @@ -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) diff --git a/hw/fsp/fsp-codeupdate.c b/hw/fsp/fsp-codeupdate.c index 67732a7..13aa357 100644 --- a/hw/fsp/fsp-codeupdate.c +++ b/hw/fsp/fsp-codeupdate.c @@ -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(); } @@ -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(); } @@ -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; @@ -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); @@ -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; @@ -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: @@ -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; @@ -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; @@ -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: diff --git a/hw/fsp/fsp-codeupdate.h b/hw/fsp/fsp-codeupdate.h index 237043c..0262c69 100644 --- a/hw/fsp/fsp-codeupdate.h +++ b/hw/fsp/fsp-codeupdate.h @@ -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 */ @@ -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 */ }; @@ -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[]; }; @@ -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 */ }; /* @@ -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 */ }; /* @@ -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 */ diff --git a/hw/fsp/fsp-console.c b/hw/fsp/fsp-console.c index 624efb4..05feb71 100644 --- a/hw/fsp/fsp-console.c +++ b/hw/fsp/fsp-console.c @@ -22,16 +22,16 @@ DEFINE_LOG_ENTRY(OPAL_RC_CONSOLE_HANG, OPAL_PLATFORM_ERR_EVT, OPAL_CONSOLE, OPAL_PREDICTIVE_ERR_GENERAL, OPAL_NA); struct fsp_serbuf_hdr { - u16 partition_id; + __be16 partition_id; u8 session_id; u8 hmc_id; - u16 data_offset; - u16 last_valid; - u16 ovf_count; - u16 next_in; + __be16 data_offset; + __be16 last_valid; + __be16 ovf_count; + __be16 next_in; u8 flags; u8 reserved; - u16 next_out; + __be16 next_out; u8 data[]; }; #define SER_BUF_DATA_SIZE (0x10000 - sizeof(struct fsp_serbuf_hdr)) @@ -158,13 +158,13 @@ static size_t fsp_write_vserial(struct fsp_serial *fs, const char *buf, size_t len) { struct fsp_serbuf_hdr *sb = fs->out_buf; - u16 old_nin = sb->next_in; + u16 old_nin = be16_to_cpu(sb->next_in); u16 space, chunk; if (!fs->open) return 0; - space = (sb->next_out + SER_BUF_DATA_SIZE - old_nin - 1) + space = (be16_to_cpu(sb->next_out) + SER_BUF_DATA_SIZE - old_nin - 1) % SER_BUF_DATA_SIZE; if (space < len) len = space; @@ -178,10 +178,10 @@ static size_t fsp_write_vserial(struct fsp_serial *fs, const char *buf, if (chunk < len) memcpy(&sb->data[0], buf + chunk, len - chunk); lwsync(); - sb->next_in = (old_nin + len) % SER_BUF_DATA_SIZE; + sb->next_in = cpu_to_be16((old_nin + len) % SER_BUF_DATA_SIZE); sync(); - if (sb->next_out == old_nin && fs->poke_msg) { + if (be16_to_cpu(sb->next_out) == old_nin && fs->poke_msg) { if (fs->poke_msg->state == fsp_msg_unused) { if (fsp_queue_msg(fs->poke_msg, fsp_pokemsg_reclaim)) prerror("FSPCON: poke msg queuing failed\n"); @@ -229,8 +229,8 @@ static void fsp_open_vserial(struct fsp_msg *msg) { struct fsp_msg *resp; - u16 part_id = msg->data.words[0] & 0xffff; - u16 sess_id = msg->data.words[1] & 0xffff; + u16 part_id = fsp_msg_get_data_word(msg, 0) & 0xffff; + u16 sess_id = fsp_msg_get_data_word(msg, 1) & 0xffff; u8 hmc_sess = msg->data.bytes[0]; u8 hmc_indx = msg->data.bytes[1]; u8 authority = msg->data.bytes[4]; @@ -285,8 +285,8 @@ static void fsp_open_vserial(struct fsp_msg *msg) } fs->poke_msg = fsp_mkmsg(FSP_CMD_VSERIAL_OUT, 2, - msg->data.words[0], - msg->data.words[1] & 0xffff); + fsp_msg_get_data_word(msg, 0), + fsp_msg_get_data_word(msg, 1) & 0xffff); if (fs->poke_msg == NULL) { prerror("FSPCON: Failed to allocate poke_msg\n"); unlock(&fsp_con_lock); @@ -296,13 +296,13 @@ static void fsp_open_vserial(struct fsp_msg *msg) fs->open = true; fs->poke_msg->user_data = fs; - fs->in_buf->partition_id = fs->out_buf->partition_id = part_id; + fs->in_buf->partition_id = fs->out_buf->partition_id = cpu_to_be16(part_id); fs->in_buf->session_id = fs->out_buf->session_id = sess_id; fs->in_buf->hmc_id = fs->out_buf->hmc_id = hmc_indx; fs->in_buf->data_offset = fs->out_buf->data_offset = - sizeof(struct fsp_serbuf_hdr); + cpu_to_be16(sizeof(struct fsp_serbuf_hdr)); fs->in_buf->last_valid = fs->out_buf->last_valid = - SER_BUF_DATA_SIZE - 1; + cpu_to_be16(SER_BUF_DATA_SIZE - 1); fs->in_buf->ovf_count = fs->out_buf->ovf_count = 0; fs->in_buf->next_in = fs->out_buf->next_in = 0; fs->in_buf->flags = fs->out_buf->flags = 0; @@ -313,8 +313,8 @@ static void fsp_open_vserial(struct fsp_msg *msg) unlock(&fsp_con_lock); already_open: - resp = fsp_mkmsg(FSP_RSP_OPEN_VSERIAL, 6, msg->data.words[0], - msg->data.words[1] & 0xffff, 0, tce_in, 0, tce_out); + resp = fsp_mkmsg(FSP_RSP_OPEN_VSERIAL, 6, fsp_msg_get_data_word(msg, 0), + fsp_msg_get_data_word(msg, 1) & 0xffff, 0, tce_in, 0, tce_out); if (!resp) { prerror("FSPCON: Failed to allocate open msg response\n"); return; @@ -347,8 +347,8 @@ static void fsp_open_vserial(struct fsp_msg *msg) static void fsp_close_vserial(struct fsp_msg *msg) { - u16 part_id = msg->data.words[0] & 0xffff; - u16 sess_id = msg->data.words[1] & 0xffff; + u16 part_id = fsp_msg_get_data_word(msg, 0) & 0xffff; + u16 sess_id = fsp_msg_get_data_word(msg, 1) & 0xffff; u8 hmc_sess = msg->data.bytes[0]; u8 hmc_indx = msg->data.bytes[1]; u8 authority = msg->data.bytes[4]; @@ -399,8 +399,8 @@ static void fsp_close_vserial(struct fsp_msg *msg) } unlock(&fsp_con_lock); skip_close: - resp = fsp_mkmsg(FSP_RSP_CLOSE_VSERIAL, 2, msg->data.words[0], - msg->data.words[1] & 0xffff); + resp = fsp_mkmsg(FSP_RSP_CLOSE_VSERIAL, 2, fsp_msg_get_data_word(msg, 0), + fsp_msg_get_data_word(msg, 1) & 0xffff); if (!resp) { prerror("FSPCON: Failed to allocate close msg response\n"); return; @@ -437,7 +437,7 @@ static bool fsp_con_msg_hmc(u32 cmd_sub_mod, struct fsp_msg *msg) prlog(PR_DEBUG, "FSPCON: Got HMC interface query\n"); got_intf_query = true; resp = fsp_mkmsg(FSP_RSP_HMC_INTF_QUERY, 1, - msg->data.words[0] & 0x00ffffff); + fsp_msg_get_data_word(msg, 0) & 0x00ffffff); if (!resp) { prerror("FSPCON: Failed to allocate hmc intf response\n"); return true; @@ -453,7 +453,7 @@ static bool fsp_con_msg_hmc(u32 cmd_sub_mod, struct fsp_msg *msg) static bool fsp_con_msg_vt(u32 cmd_sub_mod, struct fsp_msg *msg) { - u16 sess_id = msg->data.words[1] & 0xffff; + u16 sess_id = fsp_msg_get_data_word(msg, 1) & 0xffff; if (cmd_sub_mod == FSP_CMD_VSERIAL_IN && sess_id < MAX_SERIAL) { struct fsp_serial *fs = &fsp_serials[sess_id]; @@ -610,7 +610,8 @@ static int64_t fsp_console_write(int64_t term_number, __be64 *__length, #ifdef OPAL_DEBUG_CONSOLE_IO prlog(PR_TRACE, "OPAL: console write req=%ld written=%ld" " ni=%d no=%d\n", - requested, written, fs->out_buf->next_in, fs->out_buf->next_out); + requested, written, be16_to_cpu(fs->out_buf->next_in), + be16_to_cpu(fs->out_buf->next_out)); prlog(PR_TRACE, " %02x %02x %02x %02x " "%02x \'%c\' %02x \'%c\' %02x \'%c\'.%02x \'%c\'..\n", buffer[0], buffer[1], buffer[2], buffer[3], @@ -646,7 +647,8 @@ static int64_t fsp_console_write_buffer_space(int64_t term_number, return OPAL_CLOSED; } sb = fs->out_buf; - length = (sb->next_out + SER_BUF_DATA_SIZE - sb->next_in - 1) + length = (be16_to_cpu(sb->next_out) + SER_BUF_DATA_SIZE + - be16_to_cpu(sb->next_in) - 1) % SER_BUF_DATA_SIZE; unlock(&fsp_con_lock); @@ -712,9 +714,9 @@ static int64_t fsp_console_read(int64_t term_number, __be64 *__length, if (fs->waiting) fs->waiting = 0; sb = fs->in_buf; - old_nin = sb->next_in; + old_nin = be16_to_cpu(sb->next_in); lwsync(); - n = (old_nin + SER_BUF_DATA_SIZE - sb->next_out) + n = (old_nin + SER_BUF_DATA_SIZE - be16_to_cpu(sb->next_out)) % SER_BUF_DATA_SIZE; if (n > req) { pending = true; @@ -722,17 +724,17 @@ static int64_t fsp_console_read(int64_t term_number, __be64 *__length, } *__length = cpu_to_be64(n); - chunk = SER_BUF_DATA_SIZE - sb->next_out; + chunk = SER_BUF_DATA_SIZE - be16_to_cpu(sb->next_out); if (chunk > n) chunk = n; - memcpy(buffer, &sb->data[sb->next_out], chunk); + memcpy(buffer, &sb->data[be16_to_cpu(sb->next_out)], chunk); if (chunk < n) memcpy(buffer + chunk, &sb->data[0], n - chunk); - sb->next_out = (sb->next_out + n) % SER_BUF_DATA_SIZE; + sb->next_out = cpu_to_be16(((be16_to_cpu(sb->next_out)) + n) % SER_BUF_DATA_SIZE); #ifdef OPAL_DEBUG_CONSOLE_IO prlog(PR_TRACE, "OPAL: console read req=%d read=%d ni=%d no=%d\n", - req, n, sb->next_in, sb->next_out); + req, n, be16_to_cpu(sb->next_in), be16_to_cpu(sb->next_out)); prlog(PR_TRACE, " %02x %02x %02x %02x %02x %02x %02x %02x ...\n", buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], buffer[5], buffer[6], buffer[7]); @@ -809,7 +811,8 @@ void fsp_console_poll(void *data __unused) if (debug < 5) { prlog(PR_DEBUG,"OPAL: %d still pending" " ni=%d no=%d\n", - i, sb->next_in, sb->next_out); + i, be16_to_cpu(sb->next_in), + be16_to_cpu(sb->next_out)); debug++; } #endif /* OPAL_DEBUG_CONSOLE_POLL */ @@ -918,8 +921,8 @@ static bool send_all_hvsi_close(void) /* Do we have room ? Wait a bit if not */ while(timeout--) { - space = (sb->next_out + SER_BUF_DATA_SIZE - - sb->next_in - 1) % SER_BUF_DATA_SIZE; + space = (be16_to_cpu(sb->next_out) + SER_BUF_DATA_SIZE - + be16_to_cpu(sb->next_in) - 1) % SER_BUF_DATA_SIZE; if (space >= 6) break; time_wait_ms(500); diff --git a/hw/fsp/fsp-diag.c b/hw/fsp/fsp-diag.c index 0ee8975..9d1a350 100644 --- a/hw/fsp/fsp-diag.c +++ b/hw/fsp/fsp-diag.c @@ -29,7 +29,7 @@ static bool fsp_diag_msg(u32 cmd_sub_mod, struct fsp_msg *msg) } printf("BUG: High Level ACK timeout (FSP_MCLASS_DIAG) for 0x%x\n", - msg->data.words[0] & 0xffff0000); + fsp_msg_get_data_word(msg, 0) & 0xffff0000); return true; } diff --git a/hw/fsp/fsp-dpo.c b/hw/fsp/fsp-dpo.c index 0796d9a..8f0861e 100644 --- a/hw/fsp/fsp-dpo.c +++ b/hw/fsp/fsp-dpo.c @@ -28,14 +28,14 @@ static unsigned long fsp_dpo_init_tb; * of seconds remaining for a forced system shutdown. This will enable * the host to schedule for shutdown voluntarily before timeout occurs. */ -static int64_t fsp_opal_get_dpo_status(int64_t *dpo_timeout) +static int64_t fsp_opal_get_dpo_status(__be64 *dpo_timeout) { if (!fsp_dpo_pending) { *dpo_timeout = 0; return OPAL_WRONG_STATE; } - *dpo_timeout = DPO_TIMEOUT - tb_to_secs(mftb() - fsp_dpo_init_tb); + *dpo_timeout = cpu_to_be64(DPO_TIMEOUT - tb_to_secs(mftb() - fsp_dpo_init_tb)); return OPAL_SUCCESS; } diff --git a/hw/fsp/fsp-dump.c b/hw/fsp/fsp-dump.c index 37efa9d..bf72438 100644 --- a/hw/fsp/fsp-dump.c +++ b/hw/fsp/fsp-dump.c @@ -356,8 +356,8 @@ static int64_t fsp_opal_dump_init(uint8_t dump_type) /* * OPAL interface to send dump information to Linux. */ -static int64_t fsp_opal_dump_info2(uint32_t *dump_id, uint32_t *dump_size, - uint32_t *dump_type) +static int64_t fsp_opal_dump_info2(__be32 *dump_id, __be32 *dump_size, + __be32 *dump_type) { struct dump_record *record; int rc = OPAL_SUCCESS; @@ -373,18 +373,18 @@ static int64_t fsp_opal_dump_info2(uint32_t *dump_id, uint32_t *dump_size, rc = OPAL_INTERNAL_ERROR; goto out; } - *dump_id = record->id; - *dump_size = record->size; - *dump_type = record->type; + *dump_id = cpu_to_be32(record->id); + *dump_size = cpu_to_be32(record->size); + *dump_type = cpu_to_be32(record->type); out: unlock(&dump_lock); return rc; } -static int64_t fsp_opal_dump_info(uint32_t *dump_id, uint32_t *dump_size) +static int64_t fsp_opal_dump_info(__be32 *dump_id, __be32 *dump_size) { - uint32_t dump_type; + __be32 dump_type; return fsp_opal_dump_info2(dump_id, dump_size, &dump_type); } @@ -505,11 +505,11 @@ static void dump_read_complete(struct fsp_msg *msg) bool compl = false; status = (msg->resp->word1 >> 8) & 0xff; - flags = (msg->data.words[0] >> 16) & 0xff; - id = msg->data.words[0] & 0xffff; - dump_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; + dump_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); fsp_freemsg(msg); @@ -654,9 +654,9 @@ static void dump_ack_complete(struct fsp_msg *msg) if (status) log_simple_error(&e_info(OPAL_RC_DUMP_ACK), "DUMP: ACK failed for ID: 0x%x\n", - msg->data.words[0]); + fsp_msg_get_data_word(msg, 0)); else - printf("DUMP: ACKed dump ID: 0x%x\n", msg->data.words[0]); + printf("DUMP: ACKed dump ID: 0x%x\n", fsp_msg_get_data_word(msg, 0)); fsp_freemsg(msg); } @@ -807,10 +807,11 @@ static bool fsp_sys_dump_notify(uint32_t cmd_sub_mod, struct fsp_msg *msg) return false; printf("DUMP: Platform dump available. ID = 0x%x [size: %d bytes]\n", - msg->data.words[0], msg->data.words[1]); + fsp_msg_get_data_word(msg, 0), fsp_msg_get_data_word(msg, 1)); add_dump_id_to_list(DUMP_TYPE_SYS, - msg->data.words[0], msg->data.words[1]); + fsp_msg_get_data_word(msg, 0), + fsp_msg_get_data_word(msg, 1)); return true; } diff --git a/hw/fsp/fsp-elog-read.c b/hw/fsp/fsp-elog-read.c index 5b373aa..fb81320 100644 --- a/hw/fsp/fsp-elog-read.c +++ b/hw/fsp/fsp-elog-read.c @@ -265,13 +265,13 @@ static void fsp_elog_queue_fetch(void) } /* OPAL interface for PowerNV to read log size and log ID from Sapphire. */ -static int64_t fsp_opal_elog_info(uint64_t *opal_elog_id, - uint64_t *opal_elog_size, uint64_t *elog_type) +static int64_t fsp_opal_elog_info(__be64 *opal_elog_id, + __be64 *opal_elog_size, __be64 *elog_type) { struct fsp_log_entry *log_data; /* Copy type of the error log */ - *elog_type = ELOG_TYPE_PEL; + *elog_type = cpu_to_be64(ELOG_TYPE_PEL); /* Check if any OPAL log needs to be reported to the host */ if (opal_elog_info(opal_elog_id, opal_elog_size)) @@ -298,15 +298,15 @@ static int64_t fsp_opal_elog_info(uint64_t *opal_elog_id, return OPAL_WRONG_STATE; } - *opal_elog_id = log_data->log_id; - *opal_elog_size = log_data->log_size; + *opal_elog_id = cpu_to_be64(log_data->log_id); + *opal_elog_size = cpu_to_be64(log_data->log_size); fsp_elog_set_head_state(ELOG_STATE_HOST_INFO); unlock(&elog_read_lock); return OPAL_SUCCESS; } /* OPAL interface for PowerNV to read log from Sapphire. */ -static int64_t fsp_opal_elog_read(uint64_t *buffer, uint64_t opal_elog_size, +static int64_t fsp_opal_elog_read(void *buffer, uint64_t opal_elog_size, uint64_t opal_elog_id) { int size = opal_elog_size; @@ -350,8 +350,8 @@ static int64_t fsp_opal_elog_read(uint64_t *buffer, uint64_t opal_elog_size, if (opal_elog_size > log_data->log_size) size = log_data->log_size; - memset((void *)buffer, 0, opal_elog_size); - memcpy((void *)buffer, elog_read_buffer, size); + memset(buffer, 0, opal_elog_size); + memcpy(buffer, elog_read_buffer, size); /* * Once log is read from linux move record from pending @@ -483,8 +483,8 @@ static bool fsp_elog_msg(uint32_t cmd_sub_mod, struct fsp_msg *msg) if (cmd_sub_mod != FSP_CMD_ERRLOG_NOTIFICATION) return false; - log_id = msg->data.words[0]; - log_size = msg->data.words[1]; + log_id = fsp_msg_get_data_word(msg, 0); + log_size = fsp_msg_get_data_word(msg, 1); prlog(PR_TRACE, "ELOG: Notified of log 0x%08x (size: %d)\n", log_id, log_size); diff --git a/hw/fsp/fsp-elog-write.c b/hw/fsp/fsp-elog-write.c index 6aa0c59..1776c96 100644 --- a/hw/fsp/fsp-elog-write.c +++ b/hw/fsp/fsp-elog-write.c @@ -122,7 +122,7 @@ static inline void fsp_elog_write_set_head_state(enum elog_head_state state) elog_write_to_host_head_state = state; } -bool opal_elog_info(uint64_t *opal_elog_id, uint64_t *opal_elog_size) +bool opal_elog_info(__be64 *opal_elog_id, __be64 *opal_elog_size) { struct errorlog *head; bool rc = false; @@ -143,8 +143,8 @@ bool opal_elog_info(uint64_t *opal_elog_id, uint64_t *opal_elog_size) __func__); fsp_elog_write_set_head_state(ELOG_STATE_NONE); } else { - *opal_elog_id = head->plid; - *opal_elog_size = head->log_size; + *opal_elog_id = cpu_to_be64(head->plid); + *opal_elog_size = cpu_to_be64(head->log_size); fsp_elog_write_set_head_state(ELOG_STATE_HOST_INFO); rc = true; } @@ -172,7 +172,7 @@ static void opal_commit_elog_in_host(void) unlock(&elog_write_to_host_lock); } -bool opal_elog_read(uint64_t *buffer, uint64_t opal_elog_size, +bool opal_elog_read(void *buffer, uint64_t opal_elog_size, uint64_t opal_elog_id) { struct errorlog *log_data; @@ -194,8 +194,7 @@ bool opal_elog_read(uint64_t *buffer, uint64_t opal_elog_size, return rc; } - memcpy((void *)buffer, elog_write_to_host_buffer, - opal_elog_size); + memcpy(buffer, elog_write_to_host_buffer, opal_elog_size); list_del(&log_data->link); list_add(&elog_write_to_host_processed, &log_data->link); fsp_elog_write_set_head_state(ELOG_STATE_NONE); diff --git a/hw/fsp/fsp-epow.c b/hw/fsp/fsp-epow.c index bac1d3d..300a441 100644 --- a/hw/fsp/fsp-epow.c +++ b/hw/fsp/fsp-epow.c @@ -120,11 +120,11 @@ static void fsp_process_epow(struct fsp_msg *msg, int epow_type) * and then updates the length variable back to reflect the * number of EPOW sub classes it has updated the buffer with. */ -static int64_t fsp_opal_get_epow_status(int16_t *out_epow, - int16_t *length) +static int64_t fsp_opal_get_epow_status(__be16 *out_epow, __be16 *length) { int i; int n_epow_class; + int l = be16_to_cpu(*length); /* * There can be situations where the host and the Sapphire versions @@ -144,16 +144,16 @@ static int64_t fsp_opal_get_epow_status(int16_t *out_epow, * Sapphire sends out EPOW status for sub classes host knows about * and can interpret correctly. */ - if (*length >= OPAL_SYSEPOW_MAX) { + if (l >= OPAL_SYSEPOW_MAX) { n_epow_class = OPAL_SYSEPOW_MAX; - *length = OPAL_SYSEPOW_MAX; + *length = cpu_to_be16(OPAL_SYSEPOW_MAX); } else { - n_epow_class = *length; + n_epow_class = l; } /* Transfer EPOW Status */ for (i = 0; i < n_epow_class; i++) - out_epow[i] = epow_status[i]; + out_epow[i] = cpu_to_be16(epow_status[i]); return OPAL_SUCCESS; } diff --git a/hw/fsp/fsp-ipmi.c b/hw/fsp/fsp-ipmi.c index f57a3df..f62f18c 100644 --- a/hw/fsp/fsp-ipmi.c +++ b/hw/fsp/fsp-ipmi.c @@ -85,7 +85,7 @@ static void fsp_ipmi_cmd_done(uint8_t cmd, uint8_t netfn, uint8_t cc) static void fsp_ipmi_req_complete(struct fsp_msg *msg) { uint8_t status = (msg->resp->word1 >> 8) & 0xff; - uint32_t length = msg->resp->data.words[0]; + uint32_t length = fsp_msg_get_data_word(msg->resp, 0); struct fsp_ipmi_msg *fsp_ipmi_msg = msg->user_data; struct ipmi_msg *ipmi_msg; @@ -308,8 +308,8 @@ static bool fsp_ipmi_send_response(uint32_t cmd) static bool fsp_ipmi_read_response(struct fsp_msg *msg) { uint8_t *resp_buf = fsp_ipmi.ipmi_resp_buf; - uint32_t status = msg->data.words[3]; - uint32_t length = msg->data.words[2]; + uint32_t status = fsp_msg_get_data_word(msg, 3); + uint32_t length = fsp_msg_get_data_word(msg, 2); struct ipmi_msg *ipmi_msg; uint8_t netfn, cmd, cc; @@ -317,7 +317,7 @@ static bool fsp_ipmi_read_response(struct fsp_msg *msg) ipmi_msg = &fsp_ipmi.cur_msg->ipmi_msg; /* Response TCE token */ - assert(msg->data.words[1] == PSI_DMA_PLAT_RESP_BUF); + assert(fsp_msg_get_data_word(msg, 1) == PSI_DMA_PLAT_RESP_BUF); if (status != FSP_STATUS_SUCCESS) { if(status == FSP_STATUS_DMA_ERROR) diff --git a/hw/fsp/fsp-leds.c b/hw/fsp/fsp-leds.c index 9e89f20..58dfab3 100644 --- a/hw/fsp/fsp-leds.c +++ b/hw/fsp/fsp-leds.c @@ -308,7 +308,7 @@ static void fsp_get_sai_complete(struct fsp_msg *msg) prlog(PR_ERR, "Read real SAI cmd failed [rc = 0x%x].\n", rc); } else { /* Update SAI state */ lock(&sai_lock); - sai_data.state = msg->resp->data.words[0] & 0xff; + sai_data.state = fsp_msg_get_data_word(msg->resp, 0) & 0xff; unlock(&sai_lock); prlog(PR_TRACE, "SAI initial state = 0x%x\n", sai_data.state); @@ -346,25 +346,25 @@ static void fsp_get_sai(void) static bool sai_update_notification(struct fsp_msg *msg) { - uint32_t *state = &msg->data.words[2]; - uint32_t param_id = msg->data.words[0]; - int len = msg->data.words[1] & 0xffff; + uint32_t state = fsp_msg_get_data_word(msg, 2); + uint32_t param_id = fsp_msg_get_data_word(msg, 0); + int len = fsp_msg_get_data_word(msg, 1) & 0xffff; if (param_id != SYS_PARAM_REAL_SAI && param_id != SYS_PARAM_PLAT_SAI) return false; - if ( len != 4) + if (len != 4) return false; - if (*state != LED_STATE_ON && *state != LED_STATE_OFF) + if (state != LED_STATE_ON && state != LED_STATE_OFF) return false; /* Update SAI state */ lock(&sai_lock); - sai_data.state = *state; + sai_data.state = state; unlock(&sai_lock); - prlog(PR_TRACE, "SAI updated. New SAI state = 0x%x\n", *state); + prlog(PR_TRACE, "SAI updated. New SAI state = 0x%x\n", state); return true; } @@ -559,7 +559,7 @@ static int fsp_msg_set_led_state(struct led_set_cmd *spcn_cmd) */ spcn_cmd->ckpt_status = led->status; spcn_cmd->ckpt_excl_bit = led->excl_bit; - sled.state = led->status; + sled.state = cpu_to_be16(led->status); /* Update the exclussive LED bits */ if (is_enclosure_led(spcn_cmd->loc_code)) { @@ -581,24 +581,24 @@ static int fsp_msg_set_led_state(struct led_set_cmd *spcn_cmd) /* LED FAULT commad */ if (spcn_cmd->command == LED_COMMAND_FAULT) { if (spcn_cmd->state == LED_STATE_ON) - sled.state |= SPCN_LED_FAULT_MASK; + sled.state |= cpu_to_be16(SPCN_LED_FAULT_MASK); if (spcn_cmd->state == LED_STATE_OFF) - sled.state &= ~SPCN_LED_FAULT_MASK; + sled.state &= cpu_to_be16(~SPCN_LED_FAULT_MASK); } /* LED IDENTIFY command */ if (spcn_cmd->command == LED_COMMAND_IDENTIFY) { if (spcn_cmd->state == LED_STATE_ON) - sled.state |= SPCN_LED_IDENTIFY_MASK; + sled.state |= cpu_to_be16(SPCN_LED_IDENTIFY_MASK); if (spcn_cmd->state == LED_STATE_OFF) - sled.state &= ~SPCN_LED_IDENTIFY_MASK; + sled.state &= cpu_to_be16(~SPCN_LED_IDENTIFY_MASK); } /* Write into SPCN TCE buffer */ buf_write(buf, u8, sled.lc_len); /* Location code length */ memcpy(buf, sled.lc_code, sled.lc_len); /* Location code */ buf += sled.lc_len; - buf_write(buf, u16, sled.state); /* LED state */ + buf_write(buf, __be16, sled.state); /* LED state */ msg = fsp_mkmsg(FSP_CMD_SPCN_PASSTHRU, 4, SPCN_ADDR_MODE_CEC_NODE, cmd_hdr, 0, PSI_DMA_LED_BUF); @@ -612,7 +612,7 @@ static int fsp_msg_set_led_state(struct led_set_cmd *spcn_cmd) * Update the local lists based on the attempted SPCN command to * set/reset an individual led (CEC or ENCL). */ - update_led_list(spcn_cmd->loc_code, sled.state, led->excl_bit); + update_led_list(spcn_cmd->loc_code, be16_to_cpu(sled.state), led->excl_bit); msg->user_data = spcn_cmd; rc = fsp_queue_msg(msg, fsp_spcn_set_led_completion); @@ -775,20 +775,20 @@ static u32 fsp_push_data_to_tce(struct fsp_led_data *led, u8 *out_data, lcode.fld_sz = sizeof(lcode.loc_code); /* Rest of the structure */ - lcode.size = sizeof(lcode); + lcode.size = cpu_to_be16(sizeof(lcode)); lcode.status &= 0x0f; /* * Check for outbound buffer overflow. If there are still * more LEDs to be sent across to FSP, don't send, ignore. */ - if ((total_size + lcode.size) > PSI_DMA_LOC_COD_BUF_SZ) + if ((total_size + be16_to_cpu(lcode.size)) > PSI_DMA_LOC_COD_BUF_SZ) return 0; /* Copy over to the buffer */ memcpy(out_data, &lcode, sizeof(lcode)); - return lcode.size; + return be16_to_cpu(lcode.size); } /* @@ -904,7 +904,7 @@ static void fsp_ret_loc_code_list(u16 req_type, char *loc_code) static void fsp_get_led_list(struct fsp_msg *msg) { struct fsp_loc_code_req req; - u32 tce_token = msg->data.words[1]; + u32 tce_token = fsp_msg_get_data_word(msg, 1); void *buf; /* Parse inbound buffer */ @@ -929,9 +929,9 @@ static void fsp_get_led_list(struct fsp_msg *msg) memcpy(&req, buf, sizeof(req)); prlog(PR_TRACE, "Request for loc code list type 0x%04x LC=%s\n", - req.req_type, req.loc_code); + be16_to_cpu(req.req_type), req.loc_code); - fsp_ret_loc_code_list(req.req_type, req.loc_code); + fsp_ret_loc_code_list(be16_to_cpu(req.req_type), req.loc_code); } /* @@ -944,7 +944,7 @@ static void fsp_get_led_list(struct fsp_msg *msg) */ static void fsp_free_led_list_buf(struct fsp_msg *msg) { - u32 tce_token = msg->data.words[1]; + u32 tce_token = fsp_msg_get_data_word(msg, 1); u32 cmd = FSP_RSP_RET_LED_BUFFER; struct fsp_msg *resp; @@ -1039,7 +1039,7 @@ static void fsp_ret_led_state(char *loc_code) static void fsp_get_led_state(struct fsp_msg *msg) { struct fsp_get_ind_state_req req; - u32 tce_token = msg->data.words[1]; + u32 tce_token = fsp_msg_get_data_word(msg, 1); void *buf; /* Parse the inbound buffer */ @@ -1091,7 +1091,7 @@ static void fsp_set_led_state(struct fsp_msg *msg) { struct fsp_set_ind_state_req req; struct fsp_led_data *led, *next; - u32 tce_token = msg->data.words[1]; + u32 tce_token = fsp_msg_get_data_word(msg, 1); bool command, state; void *buf; int rc; @@ -1107,8 +1107,8 @@ static void fsp_set_led_state(struct fsp_msg *msg) prlog(PR_TRACE, "%s: tce=0x%08x buf=%p rq.sz=%d rq.typ=0x%04x" " rq.lc_len=%d rq.fld_sz=%d LC: %02x %02x %02x %02x....\n", - __func__, tce_token, buf, req.size, req.lc_len, req.fld_sz, - req.req_type, + __func__, tce_token, buf, be16_to_cpu(req.size), req.lc_len, req.fld_sz, + be16_to_cpu(req.req_type), req.loc_code[0], req.loc_code[1], req.loc_code[2], req.loc_code[3]); @@ -1129,7 +1129,7 @@ static void fsp_set_led_state(struct fsp_msg *msg) LED_STATE_ON : LED_STATE_OFF; /* Handle requests */ - switch (req.req_type) { + switch (be16_to_cpu(req.req_type)) { case SET_IND_ENCLOSURE: list_for_each_safe(&cec_ledq, led, next, link) { /* Only descendants of the same enclosure */ @@ -1261,12 +1261,11 @@ static struct fsp_client fsp_indicator_client = { }; -static int fsp_opal_get_sai(u64 *led_mask, u64 *led_value) +static int fsp_opal_get_sai(__be64 *led_mask, __be64 *led_value) { - *led_mask |= OPAL_SLOT_LED_STATE_ON << OPAL_SLOT_LED_TYPE_ATTN; + *led_mask |= cpu_to_be64(OPAL_SLOT_LED_STATE_ON << OPAL_SLOT_LED_TYPE_ATTN); if (sai_data.state & OPAL_SLOT_LED_STATE_ON) - *led_value |= - OPAL_SLOT_LED_STATE_ON << OPAL_SLOT_LED_TYPE_ATTN; + *led_value |= cpu_to_be64(OPAL_SLOT_LED_STATE_ON << OPAL_SLOT_LED_TYPE_ATTN); return OPAL_SUCCESS; } @@ -1309,8 +1308,8 @@ static int fsp_opal_set_sai(uint64_t async_token, char *loc_code, * number of LED type it understands and updates 'led_mask', 'led_value' * based on that maximum value of LED types. */ -static int64_t fsp_opal_leds_get_ind(char *loc_code, u64 *led_mask, - u64 *led_value, u64 *max_led_type) +static int64_t fsp_opal_leds_get_ind(char *loc_code, __be64 *led_mask, + __be64 *led_value, __be64 *max_led_type) { bool supported = true; int64_t max; @@ -1325,14 +1324,16 @@ static int64_t fsp_opal_leds_get_ind(char *loc_code, u64 *led_mask, if (led_support != LED_STATE_PRESENT) return OPAL_HARDWARE; + max = be64_to_cpu(*max_led_type); + /* Adjust max LED type */ - if (*max_led_type > OPAL_SLOT_LED_TYPE_MAX) { + if (max > OPAL_SLOT_LED_TYPE_MAX) { supported = false; - *max_led_type = OPAL_SLOT_LED_TYPE_MAX; + max = OPAL_SLOT_LED_TYPE_MAX; + *max_led_type = cpu_to_be64(max); } /* Invalid parameter */ - max = *max_led_type; if (max <= 0) return OPAL_PARAMETER; @@ -1352,20 +1353,18 @@ static int64_t fsp_opal_leds_get_ind(char *loc_code, u64 *led_mask, /* Identify LED */ --max; - *led_mask |= OPAL_SLOT_LED_STATE_ON << OPAL_SLOT_LED_TYPE_ID; + *led_mask |= cpu_to_be64(OPAL_SLOT_LED_STATE_ON << OPAL_SLOT_LED_TYPE_ID); if (led->status & SPCN_LED_IDENTIFY_MASK) - *led_value |= - OPAL_SLOT_LED_STATE_ON << OPAL_SLOT_LED_TYPE_ID; + *led_value |= cpu_to_be64(OPAL_SLOT_LED_STATE_ON << OPAL_SLOT_LED_TYPE_ID); /* Fault LED */ if (!max) return OPAL_SUCCESS; --max; - *led_mask |= OPAL_SLOT_LED_STATE_ON << OPAL_SLOT_LED_TYPE_FAULT; + *led_mask |= cpu_to_be64(OPAL_SLOT_LED_STATE_ON << OPAL_SLOT_LED_TYPE_FAULT); if (led->status & SPCN_LED_FAULT_MASK) - *led_value |= - OPAL_SLOT_LED_STATE_ON << OPAL_SLOT_LED_TYPE_FAULT; + *led_value |= cpu_to_be64(OPAL_SLOT_LED_STATE_ON << OPAL_SLOT_LED_TYPE_FAULT); /* OPAL doesn't support all the LED type requested by payload */ if (!supported) @@ -1401,7 +1400,7 @@ static int64_t fsp_opal_leds_get_ind(char *loc_code, u64 *led_mask, */ static int64_t fsp_opal_leds_set_ind(uint64_t async_token, char *loc_code, const u64 led_mask, - const u64 led_value, u64 *max_led_type) + const u64 led_value, __be64 *max_led_type) { bool supported = true; int command, state, rc = OPAL_SUCCESS; @@ -1416,13 +1415,15 @@ static int64_t fsp_opal_leds_set_ind(uint64_t async_token, if (led_support != LED_STATE_PRESENT) return OPAL_HARDWARE; + max = be64_to_cpu(*max_led_type); + /* Adjust max LED type */ - if (*max_led_type > OPAL_SLOT_LED_TYPE_MAX) { + if (max > OPAL_SLOT_LED_TYPE_MAX) { supported = false; - *max_led_type = OPAL_SLOT_LED_TYPE_MAX; + max = OPAL_SLOT_LED_TYPE_MAX; + *max_led_type = cpu_to_be64(max); } - max = *max_led_type; /* Invalid parameter */ if (max <= 0) return OPAL_PARAMETER; @@ -1623,13 +1624,15 @@ static void fsp_process_leds_data(u16 len) buf = led_buffer; while (len) { size_t lc_len; + __be16 tmp; /* Prepare */ led_data = zalloc(sizeof(struct fsp_led_data)); assert(led_data); /* Resource ID */ - buf_read(buf, u16, &led_data->rid); + buf_read(buf, __be16, &tmp); + led_data->rid = be16_to_cpu(tmp); len -= sizeof(led_data->rid); /* Location code length */ @@ -1653,11 +1656,13 @@ static void fsp_process_leds_data(u16 len) len -= led_data->lc_len; /* Parameters */ - buf_read(buf, u16, &led_data->parms); + buf_read(buf, __be16, &tmp); + led_data->parms = be16_to_cpu(tmp); len -= sizeof(led_data->parms); /* Status */ - buf_read(buf, u16, &led_data->status); + buf_read(buf, __be16, &tmp); + led_data->status = be16_to_cpu(tmp); len -= sizeof(led_data->status); /* @@ -1744,8 +1749,8 @@ static void fsp_read_leds_data_complete(struct fsp_msg *msg) int rc = 0; u32 msg_status = resp->word1 & 0xff00; - u32 led_status = (resp->data.words[1] >> 24) & 0xff; - u16 data_len = (u16)(resp->data.words[1] & 0xffff); + u32 led_status = (fsp_msg_get_data_word(resp, 1) >> 24) & 0xff; + u16 data_len = (u16)(fsp_msg_get_data_word(resp, 1) & 0xffff); if (msg_status != FSP_STATUS_SUCCESS) { log_simple_error(&e_info(OPAL_RC_LED_SUPPORT), diff --git a/hw/fsp/fsp-mem-err.c b/hw/fsp/fsp-mem-err.c index 01b1e55..d64558a 100644 --- a/hw/fsp/fsp-mem-err.c +++ b/hw/fsp/fsp-mem-err.c @@ -345,13 +345,13 @@ static bool fsp_mem_err_msg(u32 cmd_sub_mod, struct fsp_msg *msg) * correctable/Uncorrectable/scrub UE errors with real * address of 4K memory page in which the error occurred. */ - paddr_start = be64_to_cpu(*((__be64 *)&msg->data.words[0])); + paddr_start = be64_to_cpu(*((__be64 *)&msg->data.bytes[0])); printf("Got memory resilience error message for " "paddr=0x%016llux\n", paddr_start); return handle_memory_resilience(cmd_sub_mod, paddr_start); case FSP_CMD_MEM_DYN_DEALLOC: - paddr_start = be64_to_cpu(*((__be64 *)&msg->data.words[0])); - paddr_end = be64_to_cpu(*((__be64 *)&msg->data.words[2])); + paddr_start = be64_to_cpu(*((__be64 *)&msg->data.bytes[0])); + paddr_end = be64_to_cpu(*((__be64 *)&msg->data.bytes[8])); printf("Got dynamic memory deallocation message: " "paddr_start=0x%016llux, paddr_end=0x%016llux\n", paddr_start, paddr_end); diff --git a/hw/fsp/fsp-nvram.c b/hw/fsp/fsp-nvram.c index 159a956..f5c6d66 100644 --- a/hw/fsp/fsp-nvram.c +++ b/hw/fsp/fsp-nvram.c @@ -45,9 +45,9 @@ #define NVRAM_BLKSIZE 0x1000 struct nvram_triplet { - uint64_t dma_addr; - uint32_t blk_offset; - uint32_t blk_count; + __be64 dma_addr; + __be32 blk_offset; + __be32 blk_count; } __packed; #define NVRAM_FLAG_CLEAR_WPEND 0x80000000 @@ -147,9 +147,9 @@ static void fsp_nvram_send_write(void) if (start > end || fsp_nvram_state != NVRAM_STATE_OPEN) return; count = (end - start) / NVRAM_BLKSIZE + 1; - fsp_nvram_triplet.dma_addr = PSI_DMA_NVRAM_BODY + start; - fsp_nvram_triplet.blk_offset = start / NVRAM_BLKSIZE; - fsp_nvram_triplet.blk_count = count; + fsp_nvram_triplet.dma_addr = cpu_to_be64(PSI_DMA_NVRAM_BODY + start); + fsp_nvram_triplet.blk_offset = cpu_to_be32(start / NVRAM_BLKSIZE); + fsp_nvram_triplet.blk_count = cpu_to_be32(count); fsp_nvram_msg = fsp_mkmsg(FSP_CMD_WRITE_VNVRAM, 6, 0, PSI_DMA_NVRAM_TRIPL, 1, NVRAM_FLAG_CLEAR_WPEND, 0, 0); @@ -269,7 +269,7 @@ static bool fsp_nvram_get_size(uint32_t *out_size) assert(msg); rc = fsp_sync_msg(msg, false); - size = msg->resp ? msg->resp->data.words[0] : 0; + size = msg->resp ? fsp_msg_get_data_word(msg->resp, 0) : 0; fsp_freemsg(msg); if (rc || size == 0) { log_simple_error(&e_info(OPAL_RC_NVRAM_SIZE), diff --git a/hw/fsp/fsp-occ.c b/hw/fsp/fsp-occ.c index 8164129..03ddc2c 100644 --- a/hw/fsp/fsp-occ.c +++ b/hw/fsp/fsp-occ.c @@ -381,8 +381,8 @@ static bool fsp_occ_msg(u32 cmd_sub_mod, struct fsp_msg *msg) * be nice and respond to OCC. */ scope = msg->data.bytes[3]; - dbob_id = msg->data.words[1]; - seq_id = msg->data.words[2]; + dbob_id = fsp_msg_get_data_word(msg, 1); + seq_id = fsp_msg_get_data_word(msg, 2); prlog(PR_INFO, "OCC: Got OCC Load message, scope=0x%x" " dbob=0x%x seq=0x%x\n", scope, dbob_id, seq_id); occ_do_load(scope, dbob_id, seq_id); @@ -394,8 +394,8 @@ static bool fsp_occ_msg(u32 cmd_sub_mod, struct fsp_msg *msg) * to reply something sensible or the FSP will get upset */ scope = msg->data.bytes[3]; - dbob_id = msg->data.words[1]; - seq_id = msg->data.words[2]; + dbob_id = fsp_msg_get_data_word(msg, 1); + seq_id = fsp_msg_get_data_word(msg, 2); prlog(PR_INFO, "OCC: Got OCC Reset message, scope=0x%x" " dbob=0x%x seq=0x%x\n", scope, dbob_id, seq_id); occ_do_reset(scope, dbob_id, seq_id); diff --git a/hw/fsp/fsp-op-panel.c b/hw/fsp/fsp-op-panel.c index 00d2751..9bd0247 100644 --- a/hw/fsp/fsp-op-panel.c +++ b/hw/fsp/fsp-op-panel.c @@ -119,16 +119,16 @@ struct op_src { uint8_t flags; uint8_t reserved; uint8_t hex_word_cnt; - uint16_t reserved2; - uint16_t total_size; - uint32_t word2; /* SRC format in low byte */ - uint32_t word3; - uint32_t word4; - uint32_t word5; - uint32_t word6; - uint32_t word7; - uint32_t word8; - uint32_t word9; + __be16 reserved2; + __be16 total_size; + __be32 word2; /* SRC format in low byte */ + __be32 word3; + __be32 word4; + __be32 word5; + __be32 word6; + __be32 word7; + __be32 word8; + __be32 word9; uint8_t ascii[OP_PANEL_NUM_LINES * OP_PANEL_LINE_LEN]; /* Word 11 */ } __packed __align(4); @@ -195,7 +195,7 @@ static int64_t __opal_write_oppanel(oppanel_line_t *lines, uint64_t num_lines, op_src.reserved = 0; op_src.hex_word_cnt = 1; /* header word only */ op_src.reserved2 = 0; - op_src.total_size = sizeof(op_src); + op_src.total_size = cpu_to_be16(sizeof(op_src)); op_src.word2 = 0; /* should be unneeded */ for (i = 0; i < num_lines; i++) { diff --git a/hw/fsp/fsp-rtc.c b/hw/fsp/fsp-rtc.c index ac12ddf..4e5a809 100644 --- a/hw/fsp/fsp-rtc.c +++ b/hw/fsp/fsp-rtc.c @@ -81,8 +81,8 @@ static bool rtc_tod_cache_dirty = false; struct opal_tpo_data { uint64_t tpo_async_token; - uint32_t *year_month_day; - uint32_t *hour_min; + __be32 *year_month_day; + __be32 *hour_min; }; /* Timebase value when we last initiated a RTC read request */ @@ -125,10 +125,9 @@ static void fsp_tpo_req_complete(struct fsp_msg *read_resp) case FSP_STATUS_SUCCESS: /* Save the read TPO value in our cache */ if (attr->year_month_day) - *(attr->year_month_day) = - read_resp->resp->data.words[0]; + *attr->year_month_day = cpu_to_be32(fsp_msg_get_data_word(read_resp->resp, 0)); if (attr->hour_min) - *(attr->hour_min) = read_resp->resp->data.words[1]; + *attr->hour_min = cpu_to_be32(fsp_msg_get_data_word(read_resp->resp, 1)); rc = OPAL_SUCCESS; break; @@ -170,8 +169,8 @@ static void fsp_rtc_process_read(struct fsp_msg *read_resp) case FSP_STATUS_SUCCESS: /* Save the read RTC value in our cache */ rtc_tod_state = RTC_TOD_VALID; - datetime_to_tm(read_resp->data.words[0], - (u64) read_resp->data.words[1] << 32, &tm); + datetime_to_tm(fsp_msg_get_data_word(read_resp, 0), + (u64)fsp_msg_get_data_word(read_resp, 1) << 32, &tm); rtc_cache_update(&tm); prlog(PR_TRACE, "FSP-RTC Got time: %d-%d-%d %d:%d:%d\n", tm.tm_year, tm.tm_mon, tm.tm_mday, @@ -442,8 +441,8 @@ static int64_t fsp_opal_tpo_write(uint64_t async_token, uint32_t y_m_d, } /* Read Timed power on (TPO) from FSP */ -static int64_t fsp_opal_tpo_read(uint64_t async_token, uint32_t *y_m_d, - uint32_t *hr_min) +static int64_t fsp_opal_tpo_read(uint64_t async_token, __be32 *y_m_d, + __be32 *hr_min) { static struct opal_tpo_data *attr; struct fsp_msg *msg; diff --git a/hw/fsp/fsp-sensor.c b/hw/fsp/fsp-sensor.c index 46385b0..5cff258 100644 --- a/hw/fsp/fsp-sensor.c +++ b/hw/fsp/fsp-sensor.c @@ -191,7 +191,7 @@ static uint32_t sensor_power_process_data(uint16_t rid, prlog(PR_TRACE, "Power[%d]: %d mW\n", i, power->supplies[i].milliwatts); if (rid == normalize_power_rid(power->supplies[i].rid)) - return power->supplies[i].milliwatts / 1000; + return be32_to_cpu(power->supplies[i].milliwatts) / 1000; } return 0; @@ -206,7 +206,7 @@ static void fsp_sensor_process_data(struct opal_sensor_data *attr) { uint8_t *sensor_buf_ptr = (uint8_t *)sensor_buffer; uint32_t sensor_data = INVALID_DATA; - uint16_t sensor_mod_data[8]; + __be16 sensor_mod_data[8]; int count; for (count = 0; count < spcn_mod_data[attr->mod_index].entry_count; @@ -220,18 +220,18 @@ static void fsp_sensor_process_data(struct opal_sensor_data *attr) sensor_data = sensor_power_process_data(attr->rid, (struct sensor_power *) sensor_buf_ptr); break; - } else if (sensor_mod_data[0] == attr->frc && - sensor_mod_data[1] == attr->rid) { + } else if (be16_to_cpu(sensor_mod_data[0]) == attr->frc && + be16_to_cpu(sensor_mod_data[1]) == attr->rid) { switch (attr->spcn_attr) { case SENSOR_STATUS: sensor_data = - convert_status_to_fault(sensor_mod_data[3]); + convert_status_to_fault(be16_to_cpu(sensor_mod_data[3])); break; case SENSOR_THRS: - sensor_data = sensor_mod_data[6]; + sensor_data = be16_to_cpu(sensor_mod_data[6]); break; case SENSOR_DATA: - sensor_data = sensor_mod_data[2]; + sensor_data = be16_to_cpu(sensor_mod_data[2]); break; default: break; @@ -259,7 +259,7 @@ static int fsp_sensor_process_read(struct fsp_msg *resp_msg) switch (mbx_rsp_status) { case SP_RSP_STATUS_VALID_DATA: sensor_state = SENSOR_VALID_DATA; - size = resp_msg->data.words[1] & 0xffff; + size = fsp_msg_get_data_word(resp_msg, 1) & 0xffff; break; case SP_RSP_STATUS_INVALID_DATA: log_simple_error(&e_info(OPAL_RC_SENSOR_READ), @@ -308,7 +308,7 @@ static void fsp_sensor_read_complete(struct fsp_msg *msg) prlog(PR_INSANE, "%s()\n", __func__); - status = (msg->resp->data.words[1] >> 24) & 0xff; + status = (fsp_msg_get_data_word(msg->resp, 1) >> 24) & 0xff; size = fsp_sensor_process_read(msg->resp); fsp_freemsg(msg); @@ -576,8 +576,7 @@ static struct dt_node *sensor_get_node(struct dt_node *sensors, * Just use the resource class name and resource id. This * should be obvious enough for a node name. */ - snprintf(name, sizeof(name), "%s#%d-%s", frc_names[header->frc], - header->rid, attrname); + snprintf(name, sizeof(name), "%s#%d-%s", frc_names[be16_to_cpu(header->frc)], be16_to_cpu(header->rid), attrname); /* * The same resources are reported by the different PRS @@ -592,7 +591,7 @@ static struct dt_node *sensor_get_node(struct dt_node *sensors, node = dt_new(sensors, name); snprintf(name, sizeof(name), "ibm,opal-sensor-%s", - frc_names[header->frc]); + frc_names[be16_to_cpu(header->frc)]); dt_add_property_string(node, "compatible", name); } else { /** @@ -608,7 +607,7 @@ static struct dt_node *sensor_get_node(struct dt_node *sensors, } #define sensor_handler(header, attr_num) \ - sensor_make_handler(SENSOR_FSP, (header).frc, (header).rid, attr_num) + sensor_make_handler(SENSOR_FSP, be16_to_cpu((header).frc), be16_to_cpu((header).rid), attr_num) static int add_sensor_prs(struct dt_node *sensors, struct sensor_prs *prs) { @@ -655,7 +654,7 @@ static int add_sensor_data(struct dt_node *sensors, * Some resource, like fans, get their status attribute from * three different commands ... */ - if (data->header.frc == SENSOR_FRC_AMB_TEMP) { + if (be16_to_cpu(data->header.frc) == SENSOR_FRC_AMB_TEMP) { node = sensor_get_node(sensors, &data->header, "faulted"); if (!node) return -1; @@ -677,15 +676,15 @@ static int add_sensor_power(struct dt_node *sensors, struct sensor_power *power) for (i = 0; i < sensor_power_count(power); i++) { struct sensor_header header = { - SENSOR_FRC_POWER_SUPPLY, - normalize_power_rid(power->supplies[i].rid) + cpu_to_be16(SENSOR_FRC_POWER_SUPPLY), + cpu_to_be16(normalize_power_rid(power->supplies[i].rid)) }; node = sensor_get_node(sensors, &header, "data"); prlog(PR_TRACE, "SENSOR: Power[%d] : %d mW\n", power->supplies[i].rid, - power->supplies[i].milliwatts); + be32_to_cpu(power->supplies[i].milliwatts)); dt_add_property_cells(node, "sensor-id", sensor_handler(header, SENSOR_DATA)); @@ -715,7 +714,7 @@ static void add_sensor_ids(struct dt_node *sensors) struct sensor_header *header = (struct sensor_header *) sensor_buf_ptr; - if (!sensor_frc_is_valid(header->frc)) + if (!sensor_frc_is_valid(be16_to_cpu(header->frc))) goto out_sensor; switch (smod->mod) { @@ -821,7 +820,7 @@ void fsp_init_sensor(void) rc = fsp_sync_msg(&msg, false); if (rc >= 0) { - status = (resp.data.words[1] >> 24) & 0xff; + status = (fsp_msg_get_data_word(&resp, 1) >> 24) & 0xff; size = fsp_sensor_process_read(&resp); psi_dma_offset += size; spcn_mod_data[index].entry_count += (size / diff --git a/hw/fsp/fsp-surveillance.c b/hw/fsp/fsp-surveillance.c index d774bea..0b7cc21 100644 --- a/hw/fsp/fsp-surveillance.c +++ b/hw/fsp/fsp-surveillance.c @@ -145,6 +145,7 @@ static void fsp_surv_got_param(uint32_t param_id __unused, int err_len, return; } + surv_state_param = be32_to_cpu((__be32)surv_state_param); if (!(surv_state_param & 0x01)) { prlog(PR_NOTICE, "SURV: Status from FSP: disabled\n"); return; diff --git a/hw/fsp/fsp-sysdump.c b/hw/fsp/fsp-sysdump.c index fd915f4..f2777be 100644 --- a/hw/fsp/fsp-sysdump.c +++ b/hw/fsp/fsp-sysdump.c @@ -231,7 +231,7 @@ static int __dump_region_add_entry(uint32_t id, uint64_t addr, uint32_t size) } /* Add entry to dump memory region table */ - dump_mem_region[cur_mdst_entry].data_region = (u8)cpu_to_be32(id); + dump_mem_region[cur_mdst_entry].data_region = (u8)id; dump_mem_region[cur_mdst_entry].addr = cpu_to_be64(addr); dump_mem_region[cur_mdst_entry].size = cpu_to_be32(size); diff --git a/hw/fsp/fsp-sysparam.c b/hw/fsp/fsp-sysparam.c index c7ed36e..2b8446c 100644 --- a/hw/fsp/fsp-sysparam.c +++ b/hw/fsp/fsp-sysparam.c @@ -69,18 +69,18 @@ static int fsp_sysparam_process(struct sysparam_req *r) if (r->msg.state != fsp_msg_done) { prerror("FSP: Request for sysparam 0x%x got FSP failure!\n", - r->msg.data.words[0]); + fsp_msg_get_data_word(&r->msg, 0)); stlen = -1; /* XXX Find saner error codes */ goto complete; } - param_id = r->resp.data.words[0]; - len = r->resp.data.words[1] & 0xffff; + param_id = fsp_msg_get_data_word(&r->resp, 0); + len = fsp_msg_get_data_word(&r->resp, 1) & 0xffff; /* Check params validity */ - if (param_id != r->msg.data.words[0]) { + if (param_id != fsp_msg_get_data_word(&r->msg, 0)) { prerror("FSP: Request for sysparam 0x%x got resp. for 0x%x!\n", - r->msg.data.words[0], param_id); + fsp_msg_get_data_word(&r->msg, 0), param_id); stlen = -2; /* XXX Sane error codes */ goto complete; } @@ -95,7 +95,7 @@ static int fsp_sysparam_process(struct sysparam_req *r) switch(fstat) { case 0x00: /* XXX Is that even possible ? */ case 0x11: /* Data in request */ - memcpy(r->ubuf, &r->resp.data.words[2], len); + memcpy(r->ubuf, &r->resp.data.bytes[8], len); /* fallthrough */ case 0x12: /* Data in TCE */ stlen = len; @@ -106,7 +106,7 @@ static int fsp_sysparam_process(struct sysparam_req *r) complete: /* Call completion if any */ if (comp) - comp(r->msg.data.words[0], stlen, cdata); + comp(fsp_msg_get_data_word(&r->msg, 0), stlen, cdata); free(r); @@ -208,15 +208,15 @@ static void fsp_opal_setparam_complete(struct fsp_msg *msg) if (msg->state != fsp_msg_done) { prerror("FSP: Request for set sysparam 0x%x got FSP failure!\n", - msg->data.words[0]); + fsp_msg_get_data_word(msg, 0)); rc = OPAL_INTERNAL_ERROR; goto out; } - param_id = msg->resp->data.words[0]; - if (param_id != msg->data.words[0]) { + param_id = fsp_msg_get_data_word(msg->resp, 0); + if (param_id != fsp_msg_get_data_word(msg, 0)) { prerror("FSP: Request for set sysparam 0x%x got resp. for 0x%x!" - "\n", msg->data.words[0], param_id); + "\n", fsp_msg_get_data_word(msg, 0), param_id); rc = OPAL_INTERNAL_ERROR; goto out; } @@ -399,7 +399,7 @@ static bool fsp_sysparam_msg(u32 cmd_sub_mod, struct fsp_msg *msg) case FSP_CMD_SP_SPARM_UPD_0: case FSP_CMD_SP_SPARM_UPD_1: printf("FSP: Got sysparam update, param ID 0x%x\n", - msg->data.words[0]); + fsp_msg_get_data_word(msg, 0)); sysparam_run_update_notifier(msg); @@ -424,7 +424,7 @@ static void add_opal_sysparam_node(void) { struct dt_node *sysparams; char *names, *s; - uint32_t *ids, *lens; + __be32 *ids, *lens; uint8_t *perms; unsigned int i, count, size = 0; diff --git a/hw/fsp/fsp.c b/hw/fsp/fsp.c index 2b2c537..1112fb7 100644 --- a/hw/fsp/fsp.c +++ b/hw/fsp/fsp.c @@ -91,7 +91,7 @@ static enum ipl_state ipl_state = ipl_initial; static struct fsp *first_fsp; static struct fsp *active_fsp; static u16 fsp_curseq = 0x8000; -static u64 *fsp_tce_table; +static __be64 *fsp_tce_table; #define FSP_INBOUND_SIZE 0x00100000UL static void *fsp_inbound_buf = NULL; @@ -181,8 +181,8 @@ static void fsp_trace_msg(struct fsp_msg *msg, u8 dir __unused) size_t len = offsetof(struct trace_fsp_msg, data[msg->dlen]); fsp.fsp_msg.dlen = msg->dlen; - fsp.fsp_msg.word0 = msg->word0; - fsp.fsp_msg.word1 = msg->word1; + fsp.fsp_msg.word0 = cpu_to_be32(msg->word0); + fsp.fsp_msg.word1 = cpu_to_be32(msg->word1); fsp.fsp_msg.dir = dir; memcpy(fsp.fsp_msg.data, msg->data.bytes, msg->dlen); trace_add(&fsp, TRACE_FSP_MSG, len); @@ -634,12 +634,12 @@ static void fsp_trace_event(struct fsp *fsp, u32 evt, #ifdef FSP_TRACE_EVENT size_t len = sizeof(struct trace_fsp_event); - tfsp.fsp_evt.event = evt; - tfsp.fsp_evt.fsp_state = fsp->state; - tfsp.fsp_evt.data[0] = data0; - tfsp.fsp_evt.data[1] = data1; - tfsp.fsp_evt.data[2] = data2; - tfsp.fsp_evt.data[3] = data3; + tfsp.fsp_evt.event = cpu_to_be16(evt); + tfsp.fsp_evt.fsp_state = cpu_to_be16(fsp->state); + tfsp.fsp_evt.data[0] = cpu_to_be32(data0); + tfsp.fsp_evt.data[1] = cpu_to_be32(data1); + tfsp.fsp_evt.data[2] = cpu_to_be32(data2); + tfsp.fsp_evt.data[3] = cpu_to_be32(data3); trace_add(&tfsp, TRACE_FSP_EVENT, len); #endif /* FSP_TRACE_EVENT */ } @@ -931,7 +931,7 @@ static bool fsp_post_msg(struct fsp *fsp, struct fsp_msg *msg) fsp_wreg(fsp, reg, msg->word1); reg += 4; wlen = (msg->dlen + 3) >> 2; for (i = 0; i < wlen; i++) { - fsp_wreg(fsp, reg, msg->data.words[i]); + fsp_wreg(fsp, reg, fsp_msg_get_data_word(msg, i)); reg += 4; } @@ -994,7 +994,7 @@ static void __fsp_fillmsg(struct fsp_msg *msg, u32 cmd_sub_mod, msg->dlen = add_words << 2; for (i = 0; i < add_words; i++) - msg->data.words[i] = va_arg(list, unsigned int); + fsp_msg_set_data_word(msg, i, va_arg(list, unsigned int)); va_end(list); } @@ -1141,8 +1141,8 @@ static void fsp_complete_send(struct fsp *fsp) static void fsp_alloc_inbound(struct fsp_msg *msg) { - u16 func_id = msg->data.words[0] & 0xffff; - u32 len = msg->data.words[1]; + u16 func_id = fsp_msg_get_data_word(msg, 0) & 0xffff; + u32 len = fsp_msg_get_data_word(msg, 1); u32 tce_token = 0, act_len = 0; u8 rc = 0; void *buf; @@ -1294,12 +1294,12 @@ static bool fsp_local_command(u32 cmd_sub_mod, struct fsp_msg *msg) return true; case FSP_CMD_SP_RELOAD_COMP: if (msg->data.bytes[3] & PPC_BIT8(0)) { - fsp_fips_dump_notify(msg->data.words[1], - msg->data.words[2]); + fsp_fips_dump_notify(fsp_msg_get_data_word(msg, 1), + fsp_msg_get_data_word(msg, 2)); if (msg->data.bytes[3] & PPC_BIT8(1)) prlog(PR_DEBUG, " PLID is %x\n", - msg->data.words[3]); + fsp_msg_get_data_word(msg, 3)); } if (msg->data.bytes[3] & PPC_BIT8(2)) { prlog(PR_INFO, "FSP: SP Reset/Reload was NOT done\n"); @@ -1407,7 +1407,7 @@ static void __fsp_fill_incoming(struct fsp *fsp, struct fsp_msg *msg, wlen = (dlen + 3) >> 2; reg = FSP_MBX1_FDATA_AREA + 8; for (i = 0; i < wlen; i++) { - msg->data.words[i] = fsp_rreg(fsp, reg); + fsp_msg_set_data_word(msg, i, fsp_rreg(fsp, reg)); reg += 4; } @@ -1842,7 +1842,7 @@ static int fsp_init_mbox(struct fsp *fsp) /* We use a single fixed TCE table for all PSI interfaces */ static void fsp_init_tce_table(void) { - fsp_tce_table = (u64 *)PSI_TCE_TABLE_BASE; + fsp_tce_table = (__be64 *)PSI_TCE_TABLE_BASE; memset(fsp_tce_table, 0, PSI_TCE_TABLE_SIZE); } @@ -1859,7 +1859,7 @@ void fsp_tce_map(u32 offset, void *addr, u32 size) offset >>= TCE_SHIFT; while(size--) { - fsp_tce_table[offset++] = raddr | 0x3; + fsp_tce_table[offset++] = cpu_to_be64(raddr | 0x3); raddr += TCE_PSIZE; } } @@ -2397,8 +2397,8 @@ static void fsp_fetch_lid_complete(struct fsp_msg *msg) last = list_top(&fsp_fetch_lid_queue, struct fsp_fetch_lid_item, link); fsp_tce_unmap(PSI_DMA_FETCH, last->bsize); - woffset = msg->resp->data.words[1]; - wlen = msg->resp->data.words[2]; + woffset = fsp_msg_get_data_word(msg->resp, 1); + wlen = fsp_msg_get_data_word(msg->resp, 2); rc = (msg->resp->word1 >> 8) & 0xff; /* Fall back to a PHYP LID for kernel loads */ diff --git a/include/fsp-attn.h b/include/fsp-attn.h index 4399ead..b2f007b 100644 --- a/include/fsp-attn.h +++ b/include/fsp-attn.h @@ -84,7 +84,7 @@ struct ti_attn { __be32 src_word[SRC_WORD_COUNT]; /* ASCII data */ char src[SRC_LEN]; - uint32_t msg_len; + __be32 msg_len; /* User data: Debug details */ struct user_data msg; } __packed __align(ATTN_AREA_SZ); diff --git a/include/fsp-elog.h b/include/fsp-elog.h index f24251d..2de1a04 100644 --- a/include/fsp-elog.h +++ b/include/fsp-elog.h @@ -29,9 +29,9 @@ enum elog_head_state { int elog_fsp_commit(struct errorlog *buf) __warn_unused_result; -bool opal_elog_info(uint64_t *opal_elog_id, uint64_t *opal_elog_size) __warn_unused_result; +bool opal_elog_info(__be64 *opal_elog_id, __be64 *opal_elog_size) __warn_unused_result; -bool opal_elog_read(uint64_t *buffer, uint64_t opal_elog_size, +bool opal_elog_read(void *buffer, uint64_t opal_elog_size, uint64_t opal_elog_id) __warn_unused_result; bool opal_elog_ack(uint64_t ack_id) __warn_unused_result; diff --git a/include/fsp-leds.h b/include/fsp-leds.h index 57b3d1f..d62505f 100644 --- a/include/fsp-leds.h +++ b/include/fsp-leds.h @@ -34,9 +34,9 @@ enum spcn_cmd_src { /* SPCN set LED */ struct spcn_led_data { u8 lc_len; - u16 state; + __be16 state; char lc_code[LOC_CODE_SIZE]; -}; +} __packed; /* LED data */ struct fsp_led_data { @@ -51,17 +51,17 @@ struct fsp_led_data { /* FSP location code request */ struct fsp_loc_code_req { - u16 len; - u16 req_type; + __be16 len; + __be16 req_type; u8 raw_len; u8 lc_sz; char loc_code[LOC_CODE_SIZE]; -}; +} __packed; /* FSP location code data */ struct fsp_loc_code_data { - u16 size; - u32 ccin; + __be16 size; + __be32 ccin; u8 status; u8 ind_state; u8 raw_len; @@ -81,22 +81,22 @@ struct fsp_loc_code_data { /* Get indicator state request */ struct fsp_get_ind_state_req { - u16 size; + __be16 size; u8 lc_len; u8 fld_sz; char loc_code[LOC_CODE_SIZE]; -}; +} __packed; /* Set indicator state request */ struct fsp_set_ind_state_req { - u16 size; - u16 req_type; + __be16 size; + __be16 req_type; u8 reserved[3]; u8 ind_state; u8 lc_len; u8 fld_sz; char loc_code[LOC_CODE_SIZE]; -}; +} __packed; /* LED set SPCN command */ struct led_set_cmd { diff --git a/include/fsp.h b/include/fsp.h index b2827b3..92f5459 100644 --- a/include/fsp.h +++ b/include/fsp.h @@ -604,7 +604,7 @@ struct fsp_msg { u32 word0; /* seq << 16 | cmd */ u32 word1; /* mod << 8 | sub */ union { - u32 words[14]; + __be32 words[14]; u8 bytes[56]; } data; @@ -629,6 +629,16 @@ struct fsp_msg { struct list_node link; }; +static inline u32 fsp_msg_get_data_word(struct fsp_msg *msg, unsigned long i) +{ + return be32_to_cpu(msg->data.words[i]); +} + +static inline void fsp_msg_set_data_word(struct fsp_msg *msg, unsigned long i, u32 w) +{ + msg->data.words[i] = cpu_to_be32(w); +} + /* This checks if a message is still "in progress" in the FSP driver */ static inline bool fsp_msg_busy(struct fsp_msg *msg) { diff --git a/include/spcn.h b/include/spcn.h index bec7134..3a99eac 100644 --- a/include/spcn.h +++ b/include/spcn.h @@ -78,8 +78,8 @@ enum { * Common to all PRS modifiers (subcommands) */ struct sensor_header { - uint16_t frc; /* Frame resource class */ - uint16_t rid; /* Resource ID */ + __be16 frc; /* Frame resource class */ + __be16 rid; /* Resource ID */ } __packed; /* @@ -87,8 +87,8 @@ struct sensor_header { */ struct sensor_prs { struct sensor_header header; - uint16_t src; /* unused */ - uint16_t status; + __be16 src; /* unused */ + __be16 status; } __packed; #define PRS_STATUS_ON_SUPPORTED 0x0010 @@ -104,8 +104,8 @@ struct sensor_param { struct sensor_header header; char location[4]; char __reserved[4]; - uint16_t threshold; - uint16_t status; + __be16 threshold; + __be16 status; } __packed; /* @@ -113,8 +113,8 @@ struct sensor_param { */ struct sensor_data { struct sensor_header header; - uint16_t data; - uint16_t status; + __be16 data; + __be16 status; } __packed; #define SENSOR_STATUS_EM_ALERT 0x0004 @@ -156,7 +156,7 @@ struct sensor_data { struct sensor_power_supply { uint8_t rid; /* Power supply ID */ - uint32_t milliwatts; + __be32 milliwatts; } __packed; struct sensor_power { diff --git a/platforms/ibm-fsp/common.c b/platforms/ibm-fsp/common.c index c288bff..b58b073 100644 --- a/platforms/ibm-fsp/common.c +++ b/platforms/ibm-fsp/common.c @@ -238,7 +238,7 @@ int64_t ibm_fsp_cec_power_down(uint64_t request) } int64_t ibm_fsp_sensor_read(uint32_t sensor_hndl, int token, - uint64_t *sensor_data) + __be64 *sensor_data) { return fsp_opal_read_sensor(sensor_hndl, token, sensor_data); } diff --git a/platforms/ibm-fsp/firenze-pci.c b/platforms/ibm-fsp/firenze-pci.c index da49672..6d5aab1 100644 --- a/platforms/ibm-fsp/firenze-pci.c +++ b/platforms/ibm-fsp/firenze-pci.c @@ -94,22 +94,22 @@ struct firenze_pci_slot_fixup_info { }; struct firenze_pci_inv { - uint32_t hw_proc_id; - uint16_t slot_idx; - uint16_t reserved; - uint16_t vendor_id; - uint16_t device_id; - uint16_t subsys_vendor_id; - uint16_t subsys_device_id; -}; + __be32 hw_proc_id; + __be16 slot_idx; + __be16 reserved; + __be16 vendor_id; + __be16 device_id; + __be16 subsys_vendor_id; + __be16 subsys_device_id; +} __packed; struct firenze_pci_inv_data { - uint32_t version; /* currently 1 */ - uint32_t num_entries; - uint32_t entry_size; - uint32_t entry_offset; + __be32 version; /* currently 1 */ + __be32 num_entries; + __be32 entry_size; + __be32 entry_offset; struct firenze_pci_inv entries[]; -}; +} __packed; /* * Note: According to Tuleta system workbook, I didn't figure @@ -159,6 +159,8 @@ static void firenze_pci_add_inventory(struct phb *phb, struct proc_chip *chip; size_t size; bool need_init = false; + u32 num_entries; + u16 tmp16; /* * Do we need to add that to the FSP inventory for power @@ -191,7 +193,7 @@ static void firenze_pci_add_inventory(struct phb *phb, /* Check if we need to do some (Re)allocation */ if (!firenze_inv_data || - firenze_inv_data->num_entries == firenze_inv_cnt) { + be32_to_cpu(firenze_inv_data->num_entries) == firenze_inv_cnt) { need_init = !firenze_inv_data; /* (Re)allocate the block to the new size */ @@ -203,16 +205,18 @@ static void firenze_pci_add_inventory(struct phb *phb, /* Initialize the header for a new inventory */ if (need_init) { - firenze_inv_data->version = 1; + firenze_inv_data->version = cpu_to_be32(1); firenze_inv_data->num_entries = 0; firenze_inv_data->entry_size = - sizeof(struct firenze_pci_inv); + cpu_to_be32(sizeof(struct firenze_pci_inv)); firenze_inv_data->entry_offset = - offsetof(struct firenze_pci_inv_data, entries); + cpu_to_be32(offsetof(struct firenze_pci_inv_data, entries)); } /* Append slot entry */ - entry = &firenze_inv_data->entries[firenze_inv_data->num_entries++]; + num_entries = be32_to_cpu(firenze_inv_data->num_entries); + firenze_inv_data->num_entries = cpu_to_be32(num_entries + 1); + entry = &firenze_inv_data->entries[num_entries]; chip = get_chip(dt_get_chip_id(phb->dt_node)); if (!chip) { /** @@ -227,36 +231,38 @@ static void firenze_pci_add_inventory(struct phb *phb, return; } - entry->hw_proc_id = chip->pcid; + entry->hw_proc_id = cpu_to_be32(chip->pcid); entry->reserved = 0; if (pd->parent && pd->parent->slot && pd->parent->slot->data) { lxvpd_slot = pd->parent->slot->data; - entry->slot_idx = lxvpd_slot->slot_index; + entry->slot_idx = cpu_to_be16(lxvpd_slot->slot_index); } - pci_cfg_read16(phb, pd->bdfn, PCI_CFG_VENDOR_ID, &entry->vendor_id); - pci_cfg_read16(phb, pd->bdfn, PCI_CFG_DEVICE_ID, &entry->device_id); + pci_cfg_read16(phb, pd->bdfn, PCI_CFG_VENDOR_ID, &tmp16); + entry->vendor_id = cpu_to_be16(tmp16); + pci_cfg_read16(phb, pd->bdfn, PCI_CFG_DEVICE_ID, &tmp16); + entry->device_id = cpu_to_be16(tmp16); if (pd->is_bridge) { int64_t ssvc = pci_find_cap(phb, pd->bdfn, PCI_CFG_CAP_ID_SUBSYS_VID); if (ssvc <= 0) { - entry->subsys_vendor_id = 0xffff; - entry->subsys_device_id = 0xffff; + entry->subsys_vendor_id = cpu_to_be16(0xffff); + entry->subsys_device_id = cpu_to_be16(0xffff); } else { pci_cfg_read16(phb, pd->bdfn, - ssvc + PCICAP_SUBSYS_VID_VENDOR, - &entry->subsys_vendor_id); + ssvc + PCICAP_SUBSYS_VID_VENDOR, &tmp16); + entry->subsys_vendor_id = cpu_to_be16(tmp16); pci_cfg_read16(phb, pd->bdfn, - ssvc + PCICAP_SUBSYS_VID_DEVICE, - &entry->subsys_device_id); + ssvc + PCICAP_SUBSYS_VID_DEVICE, &tmp16); + entry->subsys_device_id = cpu_to_be16(tmp16); } } else { - pci_cfg_read16(phb, pd->bdfn, PCI_CFG_SUBSYS_VENDOR_ID, - &entry->subsys_vendor_id); - pci_cfg_read16(phb, pd->bdfn, PCI_CFG_SUBSYS_ID, - &entry->subsys_device_id); + pci_cfg_read16(phb, pd->bdfn, PCI_CFG_SUBSYS_VENDOR_ID, &tmp16); + entry->subsys_vendor_id = cpu_to_be16(tmp16); + pci_cfg_read16(phb, pd->bdfn, PCI_CFG_SUBSYS_ID, &tmp16); + entry->subsys_device_id = cpu_to_be16(tmp16); } } @@ -272,13 +278,16 @@ static void firenze_dump_pci_inventory(void) prlog(PR_INFO, "Dumping Firenze PCI inventory\n"); prlog(PR_INFO, "HWP SLT VDID DVID SVID SDID\n"); prlog(PR_INFO, "---------------------------\n"); - for (i = 0; i < firenze_inv_data->num_entries; i++) { + for (i = 0; i < be32_to_cpu(firenze_inv_data->num_entries); i++) { e = &firenze_inv_data->entries[i]; prlog(PR_INFO, "%03d %03d %04x %04x %04x %04x\n", - e->hw_proc_id, e->slot_idx, - e->vendor_id, e->device_id, - e->subsys_vendor_id, e->subsys_device_id); + be32_to_cpu(e->hw_proc_id), + be16_to_cpu(e->slot_idx), + be16_to_cpu(e->vendor_id), + be16_to_cpu(e->device_id), + be16_to_cpu(e->subsys_vendor_id), + be16_to_cpu(e->subsys_device_id)); } #endif /* FIRENZE_PCI_INVENTORY_DUMP */ } @@ -293,14 +302,14 @@ void firenze_pci_send_inventory(void) /* Dump the inventory */ prlog(PR_INFO, "Sending %d inventory to FSP\n", - firenze_inv_data->num_entries); + be32_to_cpu(firenze_inv_data->num_entries)); firenze_dump_pci_inventory(); /* Memory location for inventory */ base = (uint64_t)firenze_inv_data; - end = base + - sizeof(struct firenze_pci_inv_data) + - firenze_inv_data->num_entries * firenze_inv_data->entry_size; + end = base + sizeof(struct firenze_pci_inv_data) + + be32_to_cpu(firenze_inv_data->num_entries) * + be32_to_cpu(firenze_inv_data->entry_size); abase = base & ~0xffful; aend = (end + 0xffful) & ~0xffful; offset = PSI_DMA_PCIE_INVENTORY + (base & 0xfff); diff --git a/platforms/ibm-fsp/hostservices.c b/platforms/ibm-fsp/hostservices.c index ab4c900..d93c4f6 100644 --- a/platforms/ibm-fsp/hostservices.c +++ b/platforms/ibm-fsp/hostservices.c @@ -873,8 +873,8 @@ static bool hservice_hbrt_msg_notify(uint32_t cmd_sub_mod, struct fsp_msg *msg) prlog(PR_TRACE, "HBRT: FSP - HBRT message generated\n"); - tce_token = msg->data.words[1]; - len = msg->data.words[2]; + tce_token = fsp_msg_get_data_word(msg, 1); + len = fsp_msg_get_data_word(msg, 2); buf = fsp_inbound_buf_from_tce(tce_token); if (!buf) { prlog(PR_DEBUG, "HBRT: Invalid inbound data\n"); diff --git a/platforms/ibm-fsp/lxvpd.c b/platforms/ibm-fsp/lxvpd.c index bdebc44..81cb612 100644 --- a/platforms/ibm-fsp/lxvpd.c +++ b/platforms/ibm-fsp/lxvpd.c @@ -275,7 +275,7 @@ void lxvpd_process_slot_entries(struct phb *phb, const void *lxvpd; const uint8_t *pr_rec, *pr_end, *sm; size_t lxvpd_size, pr_size; - const uint16_t *mf = NULL; + const beint16_t *mf = NULL; char record[5] = "PR00"; uint8_t mf_sz, sm_sz; bool found = false; @@ -317,8 +317,8 @@ void lxvpd_process_slot_entries(struct phb *phb, return; } - prlog(PR_DEBUG, "Found 0x%04x map...\n", *mf); - switch (*mf) { + prlog(PR_DEBUG, "Found 0x%04x map...\n", be16_to_cpu(*mf)); + switch (be16_to_cpu(*mf)) { case 0x1004: lxvpd_parse_1004_map(phb, sm + 1, sm_sz - 1, slot_size); found = true; diff --git a/platforms/ibm-fsp/lxvpd.h b/platforms/ibm-fsp/lxvpd.h index bc9daf5..46acf67 100644 --- a/platforms/ibm-fsp/lxvpd.h +++ b/platforms/ibm-fsp/lxvpd.h @@ -14,32 +14,54 @@ struct slot_p0 { union { uint8_t byte; struct { +#if HAVE_BIG_ENDIAN uint8_t pluggable:1; uint8_t pluggable_location:3; uint8_t power_ctl:1; uint8_t rsvd_5:1; uint8_t upstream_port:1; uint8_t alt_load_source:1; +#else + uint8_t alt_load_source:1; + uint8_t upstream_port:1; + uint8_t rsvd_5:1; + uint8_t power_ctl:1; + uint8_t pluggable_location:3; + uint8_t pluggable:1; +#endif }; }; }; struct slot_p1 { +#if HAVE_BIG_ENDIAN uint8_t rsvd_0:1; uint8_t wired_lanes:3; uint8_t rsvd_4:4; +#else + uint8_t rsvd_4:4; + uint8_t wired_lanes:3; + uint8_t rsvd_0:1; +#endif }; struct slot_p2 { +#if HAVE_BIG_ENDIAN uint8_t rsvd_0:1; uint8_t bus_clock:3; uint8_t connector_type:4; +#else + uint8_t connector_type:4; + uint8_t bus_clock:3; + uint8_t rsvd_0:1; +#endif }; struct slot_p3 { union { uint8_t byte; struct { +#if HAVE_BIG_ENDIAN uint8_t height:1; uint8_t length:1; uint8_t left_mech:1; @@ -48,6 +70,16 @@ struct slot_p3 { uint8_t pow_led_fsp:1; uint8_t attn_led_kvm:1; uint8_t attn_led_fsp:1; +#else + uint8_t attn_led_fsp:1; + uint8_t attn_led_kvm:1; + uint8_t pow_led_fsp:1; + uint8_t pow_led_kvm:1; + uint8_t right_mech:1; + uint8_t left_mech:1; + uint8_t length:1; + uint8_t height:1; +#endif }; }; }; @@ -57,7 +89,7 @@ struct pci_slot_entry_1004 { uint8_t sba; uint8_t phb_or_slot_type; char label[3]; - uint16_t bis; + __be16 bis; struct slot_p0 p0; struct slot_p1 p1; struct slot_p2 p2; @@ -73,13 +105,23 @@ struct pci_slot_entry_1005 { union { uint8_t pba; struct { +#if HAVE_BIG_ENDIAN uint8_t switch_id:4; uint8_t vswitch_id:4; +#else + uint8_t vswitch_id:4; + uint8_t switch_id:4; +#endif }; }; uint8_t switch_device_id; +#if HAVE_BIG_ENDIAN uint8_t slot_type:4; uint8_t phb_id:4; +#else + uint8_t phb_id:4; + uint8_t slot_type:4; +#endif char label[8]; uint8_t rsvd_11[4]; struct slot_p0 p0; |