Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 1 | /* |
Ambroise Vincent | b237bca | 2019-02-13 15:58:00 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2019, ARM Limited and Contributors. All rights reserved. |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
Antonio Nino Diaz | 5eb8837 | 2018-11-08 10:20:19 +0000 | [diff] [blame] | 7 | #ifndef SCMI_H |
| 8 | #define SCMI_H |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 9 | |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 10 | #include <stddef.h> |
| 11 | #include <stdint.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 12 | |
| 13 | #include <lib/bakery_lock.h> |
| 14 | #include <lib/psci/psci.h> |
| 15 | #include <lib/spinlock.h> |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 16 | |
| 17 | /* Supported SCMI Protocol Versions */ |
Dimitris Papastamos | aeaf1f0 | 2018-04-03 14:58:17 +0100 | [diff] [blame] | 18 | #define SCMI_AP_CORE_PROTO_VER MAKE_SCMI_VERSION(1, 0) |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 19 | #define SCMI_PWR_DMN_PROTO_VER MAKE_SCMI_VERSION(1, 0) |
| 20 | #define SCMI_SYS_PWR_PROTO_VER MAKE_SCMI_VERSION(1, 0) |
| 21 | |
| 22 | #define GET_SCMI_MAJOR_VER(ver) (((ver) >> 16) & 0xffff) |
| 23 | #define GET_SCMI_MINOR_VER(ver) ((ver) & 0xffff) |
| 24 | |
| 25 | #define MAKE_SCMI_VERSION(maj, min) \ |
| 26 | ((((maj) & 0xffff) << 16) | ((min) & 0xffff)) |
| 27 | |
| 28 | /* Macro to check if the driver is compatible with the SCMI version reported */ |
| 29 | #define is_scmi_version_compatible(drv, scmi) \ |
| 30 | ((GET_SCMI_MAJOR_VER(drv) == GET_SCMI_MAJOR_VER(scmi)) && \ |
| 31 | (GET_SCMI_MINOR_VER(drv) <= GET_SCMI_MINOR_VER(scmi))) |
| 32 | |
| 33 | /* SCMI Protocol identifiers */ |
| 34 | #define SCMI_PWR_DMN_PROTO_ID 0x11 |
| 35 | #define SCMI_SYS_PWR_PROTO_ID 0x12 |
Dimitris Papastamos | aeaf1f0 | 2018-04-03 14:58:17 +0100 | [diff] [blame] | 36 | /* The AP core protocol is a CSS platform-specific extension */ |
| 37 | #define SCMI_AP_CORE_PROTO_ID 0x90 |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 38 | |
| 39 | /* Mandatory messages IDs for all SCMI protocols */ |
| 40 | #define SCMI_PROTO_VERSION_MSG 0x0 |
| 41 | #define SCMI_PROTO_ATTR_MSG 0x1 |
| 42 | #define SCMI_PROTO_MSG_ATTR_MSG 0x2 |
| 43 | |
| 44 | /* SCMI power domain management protocol message IDs */ |
| 45 | #define SCMI_PWR_STATE_SET_MSG 0x4 |
| 46 | #define SCMI_PWR_STATE_GET_MSG 0x5 |
| 47 | |
| 48 | /* SCMI system power management protocol message IDs */ |
| 49 | #define SCMI_SYS_PWR_STATE_SET_MSG 0x3 |
| 50 | #define SCMI_SYS_PWR_STATE_GET_MSG 0x4 |
| 51 | |
Dimitris Papastamos | aeaf1f0 | 2018-04-03 14:58:17 +0100 | [diff] [blame] | 52 | /* SCMI AP core protocol message IDs */ |
| 53 | #define SCMI_AP_CORE_RESET_ADDR_SET_MSG 0x3 |
| 54 | #define SCMI_AP_CORE_RESET_ADDR_GET_MSG 0x4 |
| 55 | |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 56 | /* Helper macros for system power management protocol commands */ |
| 57 | |
| 58 | /* |
| 59 | * Macros to describe the bit-fields of the `attribute` of system power domain |
| 60 | * protocol PROTOCOL_MSG_ATTRIBUTE message. |
| 61 | */ |
| 62 | #define SYS_PWR_ATTR_WARM_RESET_SHIFT 31 |
| 63 | #define SCMI_SYS_PWR_WARM_RESET_SUPPORTED (1U << SYS_PWR_ATTR_WARM_RESET_SHIFT) |
| 64 | |
| 65 | #define SYS_PWR_ATTR_SUSPEND_SHIFT 30 |
| 66 | #define SCMI_SYS_PWR_SUSPEND_SUPPORTED (1 << SYS_PWR_ATTR_SUSPEND_SHIFT) |
| 67 | |
| 68 | /* |
| 69 | * Macros to describe the bit-fields of the `flags` parameter of system power |
| 70 | * domain protocol SYSTEM_POWER_STATE_SET message. |
| 71 | */ |
| 72 | #define SYS_PWR_SET_GRACEFUL_REQ_SHIFT 0 |
| 73 | #define SCMI_SYS_PWR_GRACEFUL_REQ (1 << SYS_PWR_SET_GRACEFUL_REQ_SHIFT) |
| 74 | #define SCMI_SYS_PWR_FORCEFUL_REQ (0 << SYS_PWR_SET_GRACEFUL_REQ_SHIFT) |
| 75 | |
| 76 | /* |
| 77 | * Macros to describe the `system_state` parameter of system power |
| 78 | * domain protocol SYSTEM_POWER_STATE_SET message. |
| 79 | */ |
| 80 | #define SCMI_SYS_PWR_SHUTDOWN 0x0 |
| 81 | #define SCMI_SYS_PWR_COLD_RESET 0x1 |
| 82 | #define SCMI_SYS_PWR_WARM_RESET 0x2 |
| 83 | #define SCMI_SYS_PWR_POWER_UP 0x3 |
| 84 | #define SCMI_SYS_PWR_SUSPEND 0x4 |
| 85 | |
Dimitris Papastamos | aeaf1f0 | 2018-04-03 14:58:17 +0100 | [diff] [blame] | 86 | /* |
| 87 | * Macros to describe the bit-fields of the `attribute` of AP core protocol |
| 88 | * AP_CORE_RESET_ADDR set/get messages. |
| 89 | */ |
| 90 | #define SCMI_AP_CORE_LOCK_ATTR_SHIFT 0x0 |
| 91 | #define SCMI_AP_CORE_LOCK_ATTR (1U << SCMI_AP_CORE_LOCK_ATTR_SHIFT) |
| 92 | |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 93 | /* SCMI Error code definitions */ |
| 94 | #define SCMI_E_QUEUED 1 |
| 95 | #define SCMI_E_SUCCESS 0 |
| 96 | #define SCMI_E_NOT_SUPPORTED -1 |
| 97 | #define SCMI_E_INVALID_PARAM -2 |
| 98 | #define SCMI_E_DENIED -3 |
| 99 | #define SCMI_E_NOT_FOUND -4 |
| 100 | #define SCMI_E_OUT_OF_RANGE -5 |
| 101 | #define SCMI_E_BUSY -6 |
| 102 | |
| 103 | /* |
| 104 | * SCMI driver platform information. The details of the doorbell mechanism |
| 105 | * can be found in the SCMI specification. |
| 106 | */ |
| 107 | typedef struct scmi_channel_plat_info { |
| 108 | /* SCMI mailbox memory */ |
| 109 | uintptr_t scmi_mbx_mem; |
| 110 | /* The door bell register address */ |
| 111 | uintptr_t db_reg_addr; |
| 112 | /* The bit mask that need to be preserved when ringing doorbell */ |
| 113 | uint32_t db_preserve_mask; |
| 114 | /* The bit mask that need to be set to ring doorbell */ |
| 115 | uint32_t db_modify_mask; |
Samarth Parikh | 59cfa13 | 2017-11-23 14:23:21 +0530 | [diff] [blame] | 116 | /* The handler for ringing doorbell */ |
| 117 | void (*ring_doorbell)(struct scmi_channel_plat_info *plat_info); |
| 118 | /* cookie is unused now. But added for future enhancements. */ |
| 119 | void *cookie; |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 120 | } scmi_channel_plat_info_t; |
| 121 | |
Roberto Vargas | 0099694 | 2017-11-13 13:41:58 +0000 | [diff] [blame] | 122 | |
| 123 | #if HW_ASSISTED_COHERENCY |
| 124 | typedef spinlock_t scmi_lock_t; |
| 125 | #else |
| 126 | typedef bakery_lock_t scmi_lock_t; |
| 127 | #endif |
| 128 | |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 129 | /* |
| 130 | * Structure to represent an SCMI channel. |
| 131 | */ |
| 132 | typedef struct scmi_channel { |
| 133 | scmi_channel_plat_info_t *info; |
| 134 | /* The lock for channel access */ |
Roberto Vargas | 0099694 | 2017-11-13 13:41:58 +0000 | [diff] [blame] | 135 | scmi_lock_t *lock; |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 136 | /* Indicate whether the channel is initialized */ |
| 137 | int is_initialized; |
| 138 | } scmi_channel_t; |
| 139 | |
| 140 | /* External Common API */ |
| 141 | void *scmi_init(scmi_channel_t *ch); |
| 142 | int scmi_proto_msg_attr(void *p, uint32_t proto_id, uint32_t command_id, |
| 143 | uint32_t *attr); |
| 144 | int scmi_proto_version(void *p, uint32_t proto_id, uint32_t *version); |
| 145 | |
| 146 | /* |
| 147 | * Power domain protocol commands. Refer to the SCMI specification for more |
| 148 | * details on these commands. |
| 149 | */ |
| 150 | int scmi_pwr_state_set(void *p, uint32_t domain_id, uint32_t scmi_pwr_state); |
| 151 | int scmi_pwr_state_get(void *p, uint32_t domain_id, uint32_t *scmi_pwr_state); |
| 152 | |
| 153 | /* |
| 154 | * System power management protocol commands. Refer SCMI specification for more |
| 155 | * details on these commands. |
| 156 | */ |
| 157 | int scmi_sys_pwr_state_set(void *p, uint32_t flags, uint32_t system_state); |
| 158 | int scmi_sys_pwr_state_get(void *p, uint32_t *system_state); |
| 159 | |
Dimitris Papastamos | aeaf1f0 | 2018-04-03 14:58:17 +0100 | [diff] [blame] | 160 | /* SCMI AP core configuration protocol commands. */ |
| 161 | int scmi_ap_core_set_reset_addr(void *p, uint64_t reset_addr, uint32_t attr); |
| 162 | int scmi_ap_core_get_reset_addr(void *p, uint64_t *reset_addr, uint32_t *attr); |
| 163 | |
Chandni Cherukuri | 61f3a7c | 2018-10-11 14:08:08 +0530 | [diff] [blame] | 164 | /* API to get the platform specific SCMI channel information. */ |
Ambroise Vincent | b237bca | 2019-02-13 15:58:00 +0000 | [diff] [blame] | 165 | scmi_channel_plat_info_t *plat_css_get_scmi_info(void); |
Chandni Cherukuri | 61f3a7c | 2018-10-11 14:08:08 +0530 | [diff] [blame] | 166 | |
Chandni Cherukuri | e4bf6a0 | 2018-11-14 13:43:59 +0530 | [diff] [blame] | 167 | /* API to override default PSCI callbacks for platforms that support SCMI. */ |
| 168 | const plat_psci_ops_t *css_scmi_override_pm_ops(plat_psci_ops_t *ops); |
| 169 | |
Antonio Nino Diaz | 5eb8837 | 2018-11-08 10:20:19 +0000 | [diff] [blame] | 170 | #endif /* SCMI_H */ |