entry.c 2.11 KB
Newer Older
1
2
3
4
5
6
7
8
// SPDX-License-Identifier: BSD-3-Clause
/*
 * Copyright (c) 2015-2020, Arm Limited and Contributors. All rights reserved.
 * Copyright (c) 2019-2020, Linaro Limited
 */

#include <assert.h>

Peng Fan's avatar
Peng Fan committed
9
10
#include <drivers/scmi-msg.h>
#include <drivers/scmi.h>
11
12
13

#include "common.h"

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#pragma weak scmi_msg_get_clock_handler
#pragma weak scmi_msg_get_rstd_handler
#pragma weak scmi_msg_get_pd_handler
#pragma weak scmi_msg_get_voltage_handler

scmi_msg_handler_t scmi_msg_get_clock_handler(struct scmi_msg *msg __unused)
{
	return NULL;
}

scmi_msg_handler_t scmi_msg_get_rstd_handler(struct scmi_msg *msg __unused)
{
	return NULL;
}

scmi_msg_handler_t scmi_msg_get_pd_handler(struct scmi_msg *msg __unused)
{
	return NULL;
}

scmi_msg_handler_t scmi_msg_get_voltage_handler(struct scmi_msg *msg __unused)
{
	return NULL;
}

39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
void scmi_status_response(struct scmi_msg *msg, int32_t status)
{
	assert(msg->out && msg->out_size >= sizeof(int32_t));

	memcpy(msg->out, &status, sizeof(int32_t));
	msg->out_size_out = sizeof(int32_t);
}

void scmi_write_response(struct scmi_msg *msg, void *payload, size_t size)
{
	/*
	 * Output payload shall be at least the size of the status
	 * Output buffer shall be at least be the size of the status
	 * Output paylaod shall fit in output buffer
	 */
	assert(payload && size >= sizeof(int32_t) && size <= msg->out_size &&
	       msg->out && msg->out_size >= sizeof(int32_t));

	memcpy(msg->out, payload, size);
	msg->out_size_out = size;
}

void scmi_process_message(struct scmi_msg *msg)
{
	scmi_msg_handler_t handler = NULL;

	switch (msg->protocol_id) {
	case SCMI_PROTOCOL_ID_BASE:
		handler = scmi_msg_get_base_handler(msg);
		break;
69
70
71
	case SCMI_PROTOCOL_ID_CLOCK:
		handler = scmi_msg_get_clock_handler(msg);
		break;
72
73
74
	case SCMI_PROTOCOL_ID_RESET_DOMAIN:
		handler = scmi_msg_get_rstd_handler(msg);
		break;
75
76
77
	case SCMI_PROTOCOL_ID_POWER_DOMAIN:
		handler = scmi_msg_get_pd_handler(msg);
		break;
78
79
80
81
82
83
84
85
86
87
88
89
90
91
	default:
		break;
	}

	if (handler) {
		handler(msg);
		return;
	}

	ERROR("Agent %u Protocol 0x%x Message 0x%x: not supported",
	      msg->agent_id, msg->protocol_id, msg->message_id);

	scmi_status_response(msg, SCMI_NOT_SUPPORTED);
}