intel: common: Fix non-MISRA compliant code v2

This patch is used to fix remaining non compliant code for Intel
SoCFPGA's mailbox and sip driver. These changes include:
- Change non-interface required uint32_t into unsigned int
- Change non-negative variable to unsigned int
- Remove obsolete variable initialization to 0

Signed-off-by: Abdul Halim, Muhammad Hadi Asyrafi <muhammad.hadi.asyrafi.abdul.halim@intel.com>
Change-Id: I3a16c7621a5fc75eb614d97d72e44c86e7d53bf5
This commit is contained in:
Abdul Halim, Muhammad Hadi Asyrafi 2020-10-15 15:27:18 +08:00
parent 9e285909ae
commit d57318b7c9
3 changed files with 85 additions and 76 deletions

View File

@ -136,17 +136,22 @@
/* Mailbox Function Definitions */
void mailbox_set_int(int interrupt_input);
void mailbox_set_int(uint32_t interrupt_input);
int mailbox_init(void);
void mailbox_set_qspi_close(void);
void mailbox_set_qspi_open(void);
void mailbox_set_qspi_direct(void);
int mailbox_send_cmd(uint32_t job_id, unsigned int cmd, uint32_t *args,
int len, int urgent, uint32_t *response, int resp_len);
int mailbox_send_cmd_async(uint32_t *job_id, unsigned int cmd, uint32_t *args,
int len, int indirect);
int mailbox_read_response(uint32_t *job_id, uint32_t *response, int resp_len);
int iterate_resp(int mbox_resp_len, uint32_t *resp_buf, int resp_len);
int mailbox_send_cmd(uint32_t job_id, uint32_t cmd, uint32_t *args,
unsigned int len, uint32_t urgent, uint32_t *response,
unsigned int resp_len);
int mailbox_send_cmd_async(uint32_t *job_id, uint32_t cmd, uint32_t *args,
unsigned int len, unsigned int indirect);
int mailbox_read_response(uint32_t *job_id, uint32_t *response,
unsigned int resp_len);
unsigned int iterate_resp(uint32_t mbox_resp_len, uint32_t *resp_buf,
unsigned int resp_len);
void mailbox_reset_cold(void);
void mailbox_clear_response(void);

View File

@ -28,7 +28,7 @@ static bool is_mailbox_cmdbuf_empty(uint32_t cin)
static int wait_for_mailbox_cmdbuf_empty(uint32_t cin)
{
uint32_t timeout = 200U;
unsigned int timeout = 200U;
do {
if (is_mailbox_cmdbuf_empty(cin)) {
@ -48,7 +48,7 @@ static int write_mailbox_cmd_buffer(uint32_t *cin, uint32_t cout,
uint32_t data,
bool *is_doorbell_triggered)
{
uint32_t timeout = 100U;
unsigned int timeout = 100U;
do {
if (is_mailbox_cmdbuf_full(*cin)) {
@ -81,10 +81,10 @@ static int write_mailbox_cmd_buffer(uint32_t *cin, uint32_t cout,
}
static int fill_mailbox_circular_buffer(uint32_t header_cmd, uint32_t *args,
int len)
unsigned int len)
{
uint32_t sdm_read_offset, cmd_free_offset;
uint32_t i;
unsigned int i;
int ret;
bool is_doorbell_triggered = false;
@ -130,12 +130,13 @@ restart_mailbox:
return MBOX_TIMEOUT;
}
int mailbox_read_response(uint32_t *job_id, uint32_t *response, int resp_len)
int mailbox_read_response(unsigned int *job_id, uint32_t *response,
unsigned int resp_len)
{
int rin = 0;
int rout = 0;
int resp_data = 0;
int ret_resp_len;
uint32_t rin;
uint32_t rout;
uint32_t resp_data;
unsigned int ret_resp_len;
if (mmio_read_32(MBOX_OFFSET + MBOX_DOORBELL_FROM_SDM) == 1U) {
mmio_write_32(MBOX_OFFSET + MBOX_DOORBELL_FROM_SDM, 0U);
@ -146,7 +147,7 @@ int mailbox_read_response(uint32_t *job_id, uint32_t *response, int resp_len)
if (rout != rin) {
resp_data = mmio_read_32(MBOX_OFFSET +
MBOX_RESP_BUFFER + ((rout++)*4));
MBOX_RESP_BUFFER + ((rout++)*4U));
rout %= MBOX_RESP_BUFFER_SIZE;
mmio_write_32(MBOX_OFFSET + MBOX_ROUT, rout);
@ -160,12 +161,12 @@ int mailbox_read_response(uint32_t *job_id, uint32_t *response, int resp_len)
ret_resp_len = MBOX_RESP_LEN(resp_data);
if (ret_resp_len != 0) {
if (ret_resp_len != 0U) {
ret_resp_len = iterate_resp(ret_resp_len, response,
resp_len);
}
if (MBOX_RESP_ERR(resp_data) > 0) {
if (MBOX_RESP_ERR(resp_data) > 0U) {
INFO("Error in response: %x\n", resp_data);
return -MBOX_RESP_ERR(resp_data);
}
@ -176,15 +177,15 @@ int mailbox_read_response(uint32_t *job_id, uint32_t *response, int resp_len)
}
int mailbox_poll_response(uint32_t job_id, int urgent, uint32_t *response,
int resp_len)
int mailbox_poll_response(uint32_t job_id, uint32_t urgent, uint32_t *response,
unsigned int resp_len)
{
uint32_t timeout = 40U;
uint32_t sdm_loop = 255U;
int rin = 0;
int rout = 0;
int resp_data = 0;
int ret_resp_len;
unsigned int timeout = 40U;
unsigned int sdm_loop = 255U;
unsigned int ret_resp_len;
uint32_t rin;
uint32_t rout;
uint32_t resp_data;
while (sdm_loop != 0U) {
@ -202,7 +203,7 @@ int mailbox_poll_response(uint32_t job_id, int urgent, uint32_t *response,
mmio_write_32(MBOX_OFFSET + MBOX_DOORBELL_FROM_SDM, 0U);
if ((urgent & 1) != 0) {
if ((urgent & 1U) != 0U) {
mdelay(5U);
if ((mmio_read_32(MBOX_OFFSET + MBOX_STATUS) &
MBOX_STATUS_UA_MASK) ^
@ -221,7 +222,7 @@ int mailbox_poll_response(uint32_t job_id, int urgent, uint32_t *response,
while (rout != rin) {
resp_data = mmio_read_32(MBOX_OFFSET +
MBOX_RESP_BUFFER + ((rout++)*4));
MBOX_RESP_BUFFER + ((rout++)*4U));
rout %= MBOX_RESP_BUFFER_SIZE;
mmio_write_32(MBOX_OFFSET + MBOX_ROUT, rout);
@ -233,13 +234,13 @@ int mailbox_poll_response(uint32_t job_id, int urgent, uint32_t *response,
ret_resp_len = MBOX_RESP_LEN(resp_data);
if (ret_resp_len != 0) {
if (ret_resp_len != 0U) {
ret_resp_len = iterate_resp(ret_resp_len,
response,
resp_len);
}
if (MBOX_RESP_ERR(resp_data) > 0) {
if (MBOX_RESP_ERR(resp_data) > 0U) {
INFO("Error in response: %x\n", resp_data);
return -MBOX_RESP_ERR(resp_data);
}
@ -254,20 +255,22 @@ int mailbox_poll_response(uint32_t job_id, int urgent, uint32_t *response,
return MBOX_TIMEOUT;
}
int iterate_resp(int mbox_resp_len, uint32_t *resp_buf, int resp_len)
unsigned int iterate_resp(uint32_t mbox_resp_len, uint32_t *resp_buf,
unsigned int resp_len)
{
uint32_t timeout;
int resp_data = 0, total_resp_len = 0;
int rin = mmio_read_32(MBOX_OFFSET + MBOX_RIN);
int rout = mmio_read_32(MBOX_OFFSET + MBOX_ROUT);
unsigned int timeout, total_resp_len = 0U;
uint32_t resp_data;
uint32_t rin = mmio_read_32(MBOX_OFFSET + MBOX_RIN);
uint32_t rout = mmio_read_32(MBOX_OFFSET + MBOX_ROUT);
while (mbox_resp_len > 0) {
while (mbox_resp_len > 0U) {
timeout = 100U;
mbox_resp_len--;
resp_data = mmio_read_32(MBOX_OFFSET +
MBOX_RESP_BUFFER +
(rout)*4);
if (resp_buf && resp_len) {
(rout)*4U);
if ((resp_buf != NULL) && (resp_len != 0U)) {
*(resp_buf + total_resp_len)
= resp_data;
resp_len--;
@ -285,7 +288,7 @@ int iterate_resp(int mbox_resp_len, uint32_t *resp_buf, int resp_len)
break;
}
timeout--;
} while ((mbox_resp_len > 0) && (timeout != 0U));
} while ((mbox_resp_len > 0U) && (timeout != 0U));
if (timeout == 0U) {
INFO("Timed out waiting for SDM\n");
@ -295,8 +298,8 @@ int iterate_resp(int mbox_resp_len, uint32_t *resp_buf, int resp_len)
return total_resp_len;
}
int mailbox_send_cmd_async(uint32_t *job_id, unsigned int cmd, uint32_t *args,
int len, int indirect)
int mailbox_send_cmd_async(uint32_t *job_id, uint32_t cmd, uint32_t *args,
unsigned int len, unsigned int indirect)
{
int status;
@ -315,12 +318,13 @@ int mailbox_send_cmd_async(uint32_t *job_id, unsigned int cmd, uint32_t *args,
return MBOX_RET_OK;
}
int mailbox_send_cmd(uint32_t job_id, unsigned int cmd, uint32_t *args,
int len, int urgent, uint32_t *response, int resp_len)
int mailbox_send_cmd(uint32_t job_id, uint32_t cmd, uint32_t *args,
unsigned int len, uint32_t urgent, uint32_t *response,
unsigned int resp_len)
{
int status = 0;
if (urgent != 0) {
if (urgent != 0U) {
urgent |= mmio_read_32(MBOX_OFFSET + MBOX_STATUS) &
MBOX_STATUS_UA_MASK;
mmio_write_32(MBOX_OFFSET + MBOX_URG, cmd);
@ -350,7 +354,7 @@ void mailbox_clear_response(void)
mmio_read_32(MBOX_OFFSET + MBOX_RIN));
}
void mailbox_set_int(int interrupt)
void mailbox_set_int(uint32_t interrupt)
{
mmio_write_32(MBOX_OFFSET+MBOX_INT, MBOX_COE_BIT(interrupt) |
@ -361,21 +365,21 @@ void mailbox_set_int(int interrupt)
void mailbox_set_qspi_open(void)
{
mailbox_set_int(MBOX_INT_FLAG_COE | MBOX_INT_FLAG_RIE);
mailbox_send_cmd(MBOX_JOB_ID, MBOX_CMD_QSPI_OPEN, NULL, 0,
CMD_CASUAL, NULL, 0);
mailbox_send_cmd(MBOX_JOB_ID, MBOX_CMD_QSPI_OPEN, NULL, 0U,
CMD_CASUAL, NULL, 0U);
}
void mailbox_set_qspi_direct(void)
{
mailbox_send_cmd(MBOX_JOB_ID, MBOX_CMD_QSPI_DIRECT, NULL, 0,
CMD_CASUAL, NULL, 0);
mailbox_send_cmd(MBOX_JOB_ID, MBOX_CMD_QSPI_DIRECT, NULL, 0U,
CMD_CASUAL, NULL, 0U);
}
void mailbox_set_qspi_close(void)
{
mailbox_set_int(MBOX_INT_FLAG_COE | MBOX_INT_FLAG_RIE);
mailbox_send_cmd(MBOX_JOB_ID, MBOX_CMD_QSPI_CLOSE, NULL, 0,
CMD_CASUAL, NULL, 0);
mailbox_send_cmd(MBOX_JOB_ID, MBOX_CMD_QSPI_CLOSE, NULL, 0U,
CMD_CASUAL, NULL, 0U);
}
void mailbox_qspi_set_cs(uint32_t device_select)
@ -386,20 +390,20 @@ void mailbox_qspi_set_cs(uint32_t device_select)
cs_setting = (device_select << 28);
mailbox_set_int(MBOX_INT_FLAG_COE | MBOX_INT_FLAG_RIE);
mailbox_send_cmd(MBOX_JOB_ID, MBOX_CMD_QSPI_SET_CS, &cs_setting,
1, CMD_CASUAL, NULL, 0);
1U, CMD_CASUAL, NULL, 0U);
}
void mailbox_reset_cold(void)
{
mailbox_set_int(MBOX_INT_FLAG_COE | MBOX_INT_FLAG_RIE);
mailbox_send_cmd(MBOX_JOB_ID, MBOX_CMD_REBOOT_HPS, NULL, 0,
CMD_CASUAL, NULL, 0);
mailbox_send_cmd(MBOX_JOB_ID, MBOX_CMD_REBOOT_HPS, NULL, 0U,
CMD_CASUAL, NULL, 0U);
}
int mailbox_rsu_get_spt_offset(uint32_t *resp_buf, uint32_t resp_buf_len)
int mailbox_rsu_get_spt_offset(uint32_t *resp_buf, unsigned int resp_buf_len)
{
return mailbox_send_cmd(MBOX_JOB_ID, MBOX_GET_SUBPARTITION_TABLE,
NULL, 0, CMD_CASUAL, (uint32_t *)resp_buf,
NULL, 0U, CMD_CASUAL, resp_buf,
resp_buf_len);
}
@ -413,15 +417,15 @@ struct rsu_status_info {
uint32_t retry_counter;
};
int mailbox_rsu_status(uint32_t *resp_buf, uint32_t resp_buf_len)
int mailbox_rsu_status(uint32_t *resp_buf, unsigned int resp_buf_len)
{
int ret;
struct rsu_status_info *info = (struct rsu_status_info *)resp_buf;
info->retry_counter = ~0U;
ret = mailbox_send_cmd(MBOX_JOB_ID, MBOX_RSU_STATUS, NULL, 0,
CMD_CASUAL, (uint32_t *)resp_buf,
ret = mailbox_send_cmd(MBOX_JOB_ID, MBOX_RSU_STATUS, NULL, 0U,
CMD_CASUAL, resp_buf,
resp_buf_len);
if (ret < 0) {
@ -440,28 +444,28 @@ int mailbox_rsu_status(uint32_t *resp_buf, uint32_t resp_buf_len)
int mailbox_rsu_update(uint32_t *flash_offset)
{
return mailbox_send_cmd(MBOX_JOB_ID, MBOX_RSU_UPDATE,
flash_offset, 2,
CMD_CASUAL, NULL, 0);
flash_offset, 2U,
CMD_CASUAL, NULL, 0U);
}
int mailbox_hps_stage_notify(uint32_t execution_stage)
{
return mailbox_send_cmd(MBOX_JOB_ID, MBOX_HPS_STAGE_NOTIFY,
&execution_stage, 1, CMD_CASUAL,
NULL, 0);
&execution_stage, 1U, CMD_CASUAL,
NULL, 0U);
}
int mailbox_init(void)
{
int status = 0;
int status;
mailbox_set_int(MBOX_INT_FLAG_COE | MBOX_INT_FLAG_RIE |
MBOX_INT_FLAG_UAE);
mmio_write_32(MBOX_OFFSET + MBOX_URG, 0U);
mmio_write_32(MBOX_OFFSET + MBOX_DOORBELL_FROM_SDM, 0U);
status = mailbox_send_cmd(0U, MBOX_CMD_RESTART, NULL, 0,
CMD_URGENT, NULL, 0);
status = mailbox_send_cmd(0U, MBOX_CMD_RESTART, NULL, 0U,
CMD_URGENT, NULL, 0U);
if (status != 0) {
return status;
@ -478,8 +482,8 @@ int intel_mailbox_get_config_status(uint32_t cmd)
int status;
uint32_t res, response[6];
status = mailbox_send_cmd(MBOX_JOB_ID, cmd, NULL, 0, CMD_CASUAL, response,
ARRAY_SIZE(response));
status = mailbox_send_cmd(MBOX_JOB_ID, cmd, NULL, 0U, CMD_CASUAL,
response, ARRAY_SIZE(response));
if (status < 0) {
return status;

View File

@ -60,7 +60,7 @@ static int intel_fpga_sdm_write_buffer(struct fpga_config_info *buffer)
buffer->size_written += args[2];
mailbox_send_cmd_async(&send_id, MBOX_RECONFIG_DATA, args,
3, CMD_INDIRECT);
3U, CMD_INDIRECT);
buffer->subblocks_sent++;
max_blocks--;
@ -190,9 +190,9 @@ static int intel_fpga_config_start(uint32_t config_type)
mailbox_clear_response();
mailbox_send_cmd(1, MBOX_CMD_CANCEL, NULL, 0, CMD_CASUAL, NULL, 0);
mailbox_send_cmd(1U, MBOX_CMD_CANCEL, NULL, 0U, CMD_CASUAL, NULL, 0U);
status = mailbox_send_cmd(1, MBOX_RECONFIG, NULL, 0, CMD_CASUAL,
status = mailbox_send_cmd(1U, MBOX_RECONFIG, NULL, 0U, CMD_CASUAL,
response, ARRAY_SIZE(response));
if (status < 0)
@ -351,7 +351,7 @@ uint32_t intel_secure_reg_update(uint64_t reg_addr, uint32_t mask,
/* Intel Remote System Update (RSU) services */
uint64_t intel_rsu_update_address;
static uint32_t intel_rsu_status(uint64_t *respbuf, uint32_t respbuf_sz)
static uint32_t intel_rsu_status(uint64_t *respbuf, unsigned int respbuf_sz)
{
if (mailbox_rsu_status((uint32_t *)respbuf, respbuf_sz) < 0)
return INTEL_SIP_SMC_RSU_ERROR;
@ -384,9 +384,9 @@ static uint32_t intel_rsu_retry_counter(uint32_t *respbuf, uint32_t respbuf_sz,
}
/* Mailbox services */
static uint32_t intel_mbox_send_cmd(uint32_t cmd, uint32_t *args, int len,
int urgent, uint32_t *response,
int resp_len, int *mbox_status,
static uint32_t intel_mbox_send_cmd(uint32_t cmd, uint32_t *args, uint32_t len,
uint32_t urgent, uint32_t *response,
uint32_t resp_len, int *mbox_status,
int *len_in_resp)
{
*len_in_resp = 0;