Skip to content

Commit

Permalink
opal-msg: Pass parameter size to _opal_queue_msg()
Browse files Browse the repository at this point in the history
Currently _opal_queue_msg() takes number of parameters. So far this was
fine as opal_queue_msg() was supporting only fixed number of parameters
(8 * 8 bytes). Soon we are going to introduce variable size parameter.
Hence num_params -> params_size.

Cc: Jeremy Kerr <jk@ozlabs.org>
Cc: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>
Cc: Shilpasri G Bhat <shilpa.bhat@linux.vnet.ibm.com>
Signed-off-by: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>
Acked-by Jeremy Kerr <jk@ozlabs.org>
Signed-off-by: Stewart Smith <stewart@linux.ibm.com>
  • Loading branch information
Vasant Hegde authored and stewartsmith committed Jun 3, 2019
1 parent ec9f67b commit 66d0ad6
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 20 deletions.
6 changes: 3 additions & 3 deletions core/hmi.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ static int setup_scom_addresses(void)

static int queue_hmi_event(struct OpalHMIEvent *hmi_evt, int recover, uint64_t *out_flags)
{
size_t num_params;
size_t size;

/* Don't queue up event if recover == -1 */
if (recover == -1)
Expand All @@ -307,13 +307,13 @@ static int queue_hmi_event(struct OpalHMIEvent *hmi_evt, int recover, uint64_t *
* num_params divide the struct size by 8 bytes to get exact
* num_params value.
*/
num_params = ALIGN_UP(sizeof(*hmi_evt), sizeof(u64)) / sizeof(u64);
size = ALIGN_UP(sizeof(*hmi_evt), sizeof(u64));

*out_flags |= OPAL_HMI_FLAGS_NEW_EVENT;

/* queue up for delivery to host. */
return _opal_queue_msg(OPAL_MSG_HMI_EVT, NULL, NULL,
num_params, (uint64_t *)hmi_evt);
size, hmi_evt);
}

static int read_core_fir(uint32_t chip_id, uint32_t core_id, uint64_t *core_fir)
Expand Down
8 changes: 4 additions & 4 deletions core/opal-msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static struct lock opal_msg_lock = LOCK_UNLOCKED;

int _opal_queue_msg(enum opal_msg_type msg_type, void *data,
void (*consumed)(void *data, int status),
size_t num_params, const u64 *params)
size_t params_size, const void *params)
{
struct opal_msg_entry *entry;

Expand All @@ -57,11 +57,11 @@ int _opal_queue_msg(enum opal_msg_type msg_type, void *data,
entry->data = data;
entry->msg.msg_type = cpu_to_be32(msg_type);

if (num_params > ARRAY_SIZE(entry->msg.params)) {
if (params_size > OPAL_MSG_FIXED_PARAMS_SIZE) {
prerror("Discarding extra parameters\n");
num_params = ARRAY_SIZE(entry->msg.params);
params_size = OPAL_MSG_FIXED_PARAMS_SIZE;
}
memcpy(entry->msg.params, params, num_params*sizeof(u64));
memcpy(entry->msg.params, params, params_size);

list_add_tail(&msg_pending_list, &entry->link);
opal_update_pending_evt(OPAL_EVENT_MSG_PENDING,
Expand Down
16 changes: 9 additions & 7 deletions hw/occ.c
Original file line number Diff line number Diff line change
Expand Up @@ -908,8 +908,9 @@ static void occ_throttle_poll(void *data __unused)
occ_msg.type = cpu_to_be64(OCC_THROTTLE);
occ_msg.chip = 0;
occ_msg.throttle_status = 0;
rc = _opal_queue_msg(OPAL_MSG_OCC, NULL, NULL, 3,
(uint64_t *)&occ_msg);
rc = _opal_queue_msg(OPAL_MSG_OCC, NULL, NULL,
sizeof(struct opal_occ_msg),
&occ_msg);
if (!rc)
occ_reset = false;
}
Expand All @@ -929,7 +930,8 @@ static void occ_throttle_poll(void *data __unused)
occ_msg.throttle_status = cpu_to_be64(throttle);
rc = _opal_queue_msg(OPAL_MSG_OCC, NULL,
occ_msg_consumed,
3, (uint64_t *)&occ_msg);
sizeof(struct opal_occ_msg),
&occ_msg);
if (!rc) {
chip->throttle = throttle;
occ_opal_msg_outstanding = true;
Expand Down Expand Up @@ -1938,8 +1940,8 @@ static void __occ_do_load(u8 scope, u32 dbob_id __unused, u32 seq_id)
} else if (!rc) {
struct opal_occ_msg occ_msg = { CPU_TO_BE64(OCC_LOAD), 0, 0 };

rc = _opal_queue_msg(OPAL_MSG_OCC, NULL, NULL, 3,
(uint64_t *)&occ_msg);
rc = _opal_queue_msg(OPAL_MSG_OCC, NULL, NULL,
sizeof(struct opal_occ_msg), &occ_msg);
if (rc)
prlog(PR_INFO, "OCC: Failed to queue message %d\n",
OCC_LOAD);
Expand Down Expand Up @@ -2062,8 +2064,8 @@ int occ_msg_queue_occ_reset(void)
int rc;

lock(&occ_lock);
rc = _opal_queue_msg(OPAL_MSG_OCC, NULL, NULL, 3,
(uint64_t *)&occ_msg);
rc = _opal_queue_msg(OPAL_MSG_OCC, NULL, NULL,
sizeof(struct opal_occ_msg), &occ_msg);
if (rc) {
prlog(PR_INFO, "OCC: Failed to queue OCC_RESET message\n");
goto out;
Expand Down
8 changes: 4 additions & 4 deletions hw/prd.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ static void send_next_pending_event(void)
* disabled then we shouldn't propagate PRD events to the host.
*/
if (prd_enabled)
_opal_queue_msg(OPAL_MSG_PRD, prd_msg, prd_msg_consumed, 4,
(uint64_t *)prd_msg);
_opal_queue_msg(OPAL_MSG_PRD, prd_msg, prd_msg_consumed,
prd_msg->hdr.size, prd_msg);
}

static void __prd_event(uint32_t proc, uint8_t event)
Expand Down Expand Up @@ -421,8 +421,8 @@ static int prd_msg_handle_firmware_req(struct opal_prd_msg *msg)
}

if (!rc)
rc = _opal_queue_msg(OPAL_MSG_PRD, prd_msg, prd_msg_consumed, 4,
(uint64_t *) prd_msg);
rc = _opal_queue_msg(OPAL_MSG_PRD, prd_msg, prd_msg_consumed,
prd_msg->hdr.size, prd_msg);
else
prd_msg_inuse = false;

Expand Down
9 changes: 7 additions & 2 deletions include/opal-msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,18 @@
/* Max size of struct opal_msg */
#define OPAL_MSG_SIZE (64 * 1024)

/* opal_msg fixed parameters size */
#define OPAL_MSG_HDR_SIZE (offsetof(struct opal_msg, params))
#define OPAL_MSG_FIXED_PARAMS_SIZE \
(sizeof(struct opal_msg) - OPAL_MSG_HDR_SIZE)

int _opal_queue_msg(enum opal_msg_type msg_type, void *data,
void (*consumed)(void *data, int status),
size_t num_params, const u64 *params);
size_t params_size, const void *params);

#define opal_queue_msg(msg_type, data, cb, ...) \
_opal_queue_msg(msg_type, data, cb, \
sizeof((u64[]) {__VA_ARGS__})/sizeof(u64), \
sizeof((u64[]) {__VA_ARGS__}), \
(u64[]) {__VA_ARGS__});

void opal_init_msg(void);
Expand Down

0 comments on commit 66d0ad6

Please sign in to comment.