intel: common: Improve readability of mailbox read response

Rename variables to improve readability of mailbox read response and
mailbox poll response flow.

Signed-off-by: Abdul Halim, Muhammad Hadi Asyrafi <muhammad.hadi.asyrafi.abdul.halim@intel.com>
Change-Id: Icd33ff1d2abb28eeead15e4eb9c7f9629f8cb402
This commit is contained in:
Abdul Halim, Muhammad Hadi Asyrafi 2020-02-12 19:57:44 +08:00
parent 1ae7b6f6b1
commit 941fc5c0d2
1 changed files with 31 additions and 28 deletions

View File

@ -39,9 +39,10 @@ int mailbox_read_response(int job_id, uint32_t *response, int resp_len)
{ {
int rin = 0; int rin = 0;
int rout = 0; int rout = 0;
int response_length = 0; int mbox_resp_len = 0;
int resp = 0; int resp_data = 0;
int total_resp_len = 0; int total_resp_len = 0;
uint32_t *resp_buf = response;
if (mmio_read_32(MBOX_OFFSET + MBOX_DOORBELL_FROM_SDM)) if (mmio_read_32(MBOX_OFFSET + MBOX_DOORBELL_FROM_SDM))
mmio_write_32(MBOX_OFFSET + MBOX_DOORBELL_FROM_SDM, 0); mmio_write_32(MBOX_OFFSET + MBOX_DOORBELL_FROM_SDM, 0);
@ -50,31 +51,31 @@ int mailbox_read_response(int job_id, uint32_t *response, int resp_len)
rout = mmio_read_32(MBOX_OFFSET + MBOX_ROUT); rout = mmio_read_32(MBOX_OFFSET + MBOX_ROUT);
if (rout != rin) { if (rout != rin) {
resp = mmio_read_32(MBOX_OFFSET + resp_data = mmio_read_32(MBOX_OFFSET +
MBOX_RESP_BUFFER + ((rout++)*4)); MBOX_RESP_BUFFER + ((rout++)*4));
rout %= MBOX_RESP_BUFFER_SIZE; rout %= MBOX_RESP_BUFFER_SIZE;
mmio_write_32(MBOX_OFFSET + MBOX_ROUT, rout); mmio_write_32(MBOX_OFFSET + MBOX_ROUT, rout);
if (MBOX_RESP_CLIENT_ID(resp) != MBOX_ATF_CLIENT_ID || if (MBOX_RESP_CLIENT_ID(resp_data) != MBOX_ATF_CLIENT_ID ||
MBOX_RESP_JOB_ID(resp) != job_id) { MBOX_RESP_JOB_ID(resp_data) != job_id) {
return MBOX_WRONG_ID; return MBOX_WRONG_ID;
} }
if (MBOX_RESP_ERR(resp) > 0) { if (MBOX_RESP_ERR(resp_data) > 0) {
INFO("Error in response: %x\n", resp); INFO("Error in response: %x\n", resp_data);
return -resp; return -resp_data;
} }
response_length = MBOX_RESP_LEN(resp); mbox_resp_len = MBOX_RESP_LEN(resp_data);
while (response_length) { while (mbox_resp_len > 0) {
response_length--; mbox_resp_len--;
resp = mmio_read_32(MBOX_OFFSET + resp_data = mmio_read_32(MBOX_OFFSET +
MBOX_RESP_BUFFER + MBOX_RESP_BUFFER +
(rout)*4); (rout)*4);
if (response && resp_len) { if (resp_buf && resp_len) {
*(response + total_resp_len) = resp; *(resp_buf + total_resp_len) = resp_data;
resp_len--; resp_len--;
total_resp_len++; total_resp_len++;
} }
@ -95,9 +96,10 @@ int mailbox_poll_response(int job_id, int urgent, uint32_t *response,
int timeout = 0xFFFFFF; int timeout = 0xFFFFFF;
int rin = 0; int rin = 0;
int rout = 0; int rout = 0;
int response_length = 0; int mbox_resp_len = 0;
int resp = 0; int resp_data = 0;
int total_resp_len = 0; int total_resp_len = 0;
uint32_t *resp_buf = response;
while (1) { while (1) {
@ -132,29 +134,30 @@ int mailbox_poll_response(int job_id, int urgent, uint32_t *response,
rout = mmio_read_32(MBOX_OFFSET + MBOX_ROUT); rout = mmio_read_32(MBOX_OFFSET + MBOX_ROUT);
while (rout != rin) { while (rout != rin) {
resp = mmio_read_32(MBOX_OFFSET + resp_data = mmio_read_32(MBOX_OFFSET +
MBOX_RESP_BUFFER + ((rout++)*4)); MBOX_RESP_BUFFER + ((rout++)*4));
rout %= MBOX_RESP_BUFFER_SIZE; rout %= MBOX_RESP_BUFFER_SIZE;
mmio_write_32(MBOX_OFFSET + MBOX_ROUT, rout); mmio_write_32(MBOX_OFFSET + MBOX_ROUT, rout);
if (MBOX_RESP_CLIENT_ID(resp) != MBOX_ATF_CLIENT_ID || if (MBOX_RESP_CLIENT_ID(resp_data) != MBOX_ATF_CLIENT_ID
MBOX_RESP_JOB_ID(resp) != job_id) || MBOX_RESP_JOB_ID(resp_data) != job_id)
continue; continue;
if (MBOX_RESP_ERR(resp) > 0) { if (MBOX_RESP_ERR(resp_data) > 0) {
INFO("Error in response: %x\n", resp); INFO("Error in response: %x\n", resp_data);
return -MBOX_RESP_ERR(resp); return -MBOX_RESP_ERR(resp_data);
} }
response_length = MBOX_RESP_LEN(resp); mbox_resp_len = MBOX_RESP_LEN(resp_data);
while (response_length) { while (mbox_resp_len > 0) {
response_length--; mbox_resp_len--;
resp = mmio_read_32(MBOX_OFFSET + resp_data = mmio_read_32(MBOX_OFFSET +
MBOX_RESP_BUFFER + MBOX_RESP_BUFFER +
(rout)*4); (rout)*4);
if (response && resp_len) { if (resp_buf && resp_len) {
*(response + total_resp_len) = resp; *(resp_buf + total_resp_len)
= resp_data;
resp_len--; resp_len--;
total_resp_len++; total_resp_len++;
} }