xref: /optee_os/core/arch/riscv/include/rpmi.h (revision d34de1de016972ad8fb4370ee353eafc1a69cbe3)
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright 2025 NXP
4  */
5 
6 #ifndef __RPMI_H
7 #define __RPMI_H
8 
9 #ifndef __ASSEMBLER__
10 
11 #include <compiler.h>
12 #include <stdint.h>
13 
14 /* RPMI error codes */
15 enum rpmi_error_codes {
16 	RPMI_SUCCESS			= 0,
17 	RPMI_ERR_FAILED			= -1,
18 	RPMI_ERR_NOTSUPP		= -2,
19 	RPMI_ERR_INVALID_PARAM		= -3,
20 	RPMI_ERR_DENIED			= -4,
21 	RPMI_ERR_INVALID_ADDR		= -5,
22 	RPMI_ERR_ALREADY		= -6,
23 	RPMI_ERR_EXTENSION		= -7,
24 	RPMI_ERR_HW_FAULT		= -8,
25 	RPMI_ERR_BUSY			= -9,
26 	RPMI_ERR_INVALID_STATE		= -10,
27 	RPMI_ERR_BAD_RANGE		= -11,
28 	RPMI_ERR_TIMEOUT		= -12,
29 	RPMI_ERR_IO			= -13,
30 	RPMI_ERR_NO_DATA		= -14,
31 	RPMI_ERR_RESERVED_START		= -15,
32 	RPMI_ERR_RESERVED_END		= -127,
33 	RPMI_ERR_VENDOR_START		= -128,
34 };
35 
36 /*
37  * struct rpmi_message_header - Header of an RPMI message
38  * @servicegroup_id:  Identifier for the service group
39  * @service_id:       Identifier for the service within the group
40  * @flags:            Message flags (e.g., request/response indicators)
41  * @datalen:          Length of the message data in bytes
42  * @token:            Message token used for matching responses
43  */
44 struct rpmi_message_header {
45 	uint16_t servicegroup_id;
46 	uint8_t service_id;
47 	uint8_t flags;
48 	uint16_t datalen;
49 	uint16_t token;
50 } __packed;
51 
52 /*
53  * struct rpmi_message - RPMI message including header and payload
54  * @header:           RPMI message header
55  * @data:             Payload of the message (variable length)
56  *
57  * This structure represents a full RPMI message. The @data buffer
58  * follows immediately after the header and its size is defined by
59  * @header.datalen.
60  */
61 struct rpmi_message {
62 	struct rpmi_message_header header;
63 	uint8_t data[];
64 } __packed;
65 
66 /*
67  * struct rpmi_notification_event - Notification message for events
68  * @event_datalen:    Size of the event data payload in bytes
69  * @event_id:         Identifier for the event type within the service group
70  * @reserved:         Reserved byte (must be zero)
71  * @event_data:       Event-specific payload (variable length)
72  *
73  * This structure defines the format of a notification event sent
74  * by RPMI-enabled services through MPXY.
75  */
76 struct rpmi_notification_event {
77 	uint16_t event_datalen;
78 	uint8_t event_id;
79 	uint8_t reserved;
80 	uint8_t event_data[];
81 };
82 
83 /* RPMI Messages Types */
84 enum rpmi_message_type {
85 	/* Normal request backed with ack */
86 	RPMI_MSG_NORMAL_REQUEST = 0x0,
87 	/* Request without any ack */
88 	RPMI_MSG_POSTED_REQUEST = 0x1,
89 	/* Acknowledgment for normal request message */
90 	RPMI_MSG_ACKNOWLEDGEMENT = 0x2,
91 	/* Notification message */
92 	RPMI_MSG_NOTIFICATION = 0x3,
93 };
94 
95 /* RPMI ServiceGroups IDs */
96 enum rpmi_servicegroup_id {
97 	RPMI_SRVGRP_ID_MIN = 0,
98 	RPMI_SRVGRP_BASE = 0x0001,
99 	RPMI_SRVGRP_SYSTEM_MSI = 0x0002,
100 	RPMI_SRVGRP_SYSTEM_RESET = 0x0003,
101 	RPMI_SRVGRP_SYSTEM_SUSPEND = 0x0004,
102 	RPMI_SRVGRP_HSM = 0x0005,
103 	RPMI_SRVGRP_CPPC = 0x0006,
104 	RPMI_SRVGRP_VOLTAGE = 0x0007,
105 	RPMI_SRVGRP_CLOCK = 0x0008,
106 	RPMI_SRVGRP_DEVICE_POWER = 0x0009,
107 	RPMI_SRVGRP_PERFORMANCE = 0x000A,
108 	RPMI_SRVGRP_MANAGEMENT_MODE = 0x000B,
109 	RPMI_SRVGRP_RAS_AGENT = 0x000C,
110 	RPMI_SRVGRP_REQUEST_FORWARD = 0x000D,
111 	RPMI_SRVGRP_ID_MAX_COUNT,
112 
113 	/* Reserved range for service groups */
114 	RPMI_SRVGRP_RESERVED_START = RPMI_SRVGRP_ID_MAX_COUNT,
115 	RPMI_SRVGRP_RESERVED_END = 0x7BFF,
116 
117 	/* Experimental service groups range */
118 	RPMI_SRVGRP_EXPERIMENTAL_START = 0x7C00,
119 	RPMI_SRVGRP_EXPERIMENTAL_END = 0x7FFF,
120 
121 	/* Vendor/Implementation-specific service groups range */
122 	RPMI_SRVGRP_VENDOR_START = 0x8000,
123 	RPMI_SRVGRP_VENDOR_END = 0xFFFF,
124 };
125 
126 #endif /*__ASSEMBLER__*/
127 #endif /*__RPMI_H*/
128