Line data Source code
1 1 : /*
2 : * Copyright (c) 2020 Intel Corporation.
3 : *
4 : * SPDX-License-Identifier: Apache-2.0
5 : */
6 :
7 : /**
8 : * @file
9 : * @ingroup peci_interface
10 : * @brief Main header file for PECI (Platform Environment Control Interface) driver API.
11 : */
12 :
13 : #ifndef ZEPHYR_INCLUDE_DRIVERS_PECI_H_
14 : #define ZEPHYR_INCLUDE_DRIVERS_PECI_H_
15 :
16 : /**
17 : * @brief Interfaces for Platform Environment Control Interface (PECI)
18 : * devices.
19 : * @defgroup peci_interface PECI
20 : * @since 2.1
21 : * @version 1.0.0
22 : * @ingroup io_interfaces
23 : * @{
24 : */
25 :
26 : #include <errno.h>
27 : #include <zephyr/types.h>
28 : #include <stddef.h>
29 : #include <zephyr/device.h>
30 :
31 : #ifdef __cplusplus
32 : extern "C" {
33 : #endif
34 :
35 : /**
36 : * @brief PECI error codes.
37 : */
38 0 : enum peci_error_code {
39 : PECI_GENERAL_SENSOR_ERROR = 0x8000,
40 : PECI_UNDERFLOW_SENSOR_ERROR = 0x8002,
41 : PECI_OVERFLOW_SENSOR_ERROR = 0x8003,
42 : };
43 :
44 : /**
45 : * @brief PECI commands.
46 : */
47 0 : enum peci_command_code {
48 : PECI_CMD_PING = 0x00,
49 : PECI_CMD_GET_TEMP0 = 0x01,
50 : PECI_CMD_GET_TEMP1 = 0x02,
51 : PECI_CMD_RD_PCI_CFG0 = 0x61,
52 : PECI_CMD_RD_PCI_CFG1 = 0x62,
53 : PECI_CMD_WR_PCI_CFG0 = 0x65,
54 : PECI_CMD_WR_PCI_CFG1 = 0x66,
55 : PECI_CMD_RD_PKG_CFG0 = 0xA1,
56 : PECI_CMD_RD_PKG_CFG1 = 0xA,
57 : PECI_CMD_WR_PKG_CFG0 = 0xA5,
58 : PECI_CMD_WR_PKG_CFG1 = 0xA6,
59 : PECI_CMD_RD_IAMSR0 = 0xB1,
60 : PECI_CMD_RD_IAMSR1 = 0xB2,
61 : PECI_CMD_WR_IAMSR0 = 0xB5,
62 : PECI_CMD_WR_IAMSR1 = 0xB6,
63 : PECI_CMD_RD_PCI_CFG_LOCAL0 = 0xE1,
64 : PECI_CMD_RD_PCI_CFG_LOCAL1 = 0xE2,
65 : PECI_CMD_WR_PCI_CFG_LOCAL0 = 0xE5,
66 : PECI_CMD_WR_PCI_CFG_LOCAL1 = 0xE6,
67 : PECI_CMD_GET_DIB = 0xF7,
68 : };
69 :
70 : /**
71 : * @name PECI read/write supported responses.
72 : * @{
73 : */
74 0 : #define PECI_CC_RSP_SUCCESS (0x40U)
75 0 : #define PECI_CC_RSP_TIMEOUT (0x80U)
76 0 : #define PECI_CC_OUT_OF_RESOURCES_TIMEOUT (0x81U)
77 0 : #define PECI_CC_RESOURCES_LOWPWR_TIMEOUT (0x82U)
78 0 : #define PECI_CC_ILLEGAL_REQUEST (0x90U)
79 : /** @} */
80 :
81 : /**
82 : * @name Ping command format.
83 : * @{
84 : */
85 0 : #define PECI_PING_WR_LEN (0U)
86 0 : #define PECI_PING_RD_LEN (0U)
87 0 : #define PECI_PING_LEN (3U)
88 : /** @} */
89 :
90 : /**
91 : * @name GetDIB command format.
92 : * @{
93 : */
94 0 : #define PECI_GET_DIB_WR_LEN (1U)
95 0 : #define PECI_GET_DIB_RD_LEN (8U)
96 0 : #define PECI_GET_DIB_CMD_LEN (4U)
97 0 : #define PECI_GET_DIB_DEVINFO (0U)
98 0 : #define PECI_GET_DIB_REVNUM (1U)
99 0 : #define PECI_GET_DIB_DOMAIN_BIT_MASK (0x4U)
100 0 : #define PECI_GET_DIB_MAJOR_REV_MASK 0xF0
101 0 : #define PECI_GET_DIB_MINOR_REV_MASK 0x0F
102 : /** @} */
103 :
104 : /**
105 : * @name GetTemp command format.
106 : * @{
107 : */
108 0 : #define PECI_GET_TEMP_WR_LEN (1U)
109 0 : #define PECI_GET_TEMP_RD_LEN (2U)
110 0 : #define PECI_GET_TEMP_CMD_LEN (4U)
111 0 : #define PECI_GET_TEMP_LSB (0U)
112 0 : #define PECI_GET_TEMP_MSB (1U)
113 0 : #define PECI_GET_TEMP_ERR_MSB (0x80U)
114 0 : #define PECI_GET_TEMP_ERR_LSB_GENERAL (0x0U)
115 0 : #define PECI_GET_TEMP_ERR_LSB_RES (0x1U)
116 0 : #define PECI_GET_TEMP_ERR_LSB_TEMP_LO (0x2U)
117 0 : #define PECI_GET_TEMP_ERR_LSB_TEMP_HI (0x3U)
118 : /** @} */
119 :
120 : /**
121 : * @name RdPkgConfig command format.
122 : * @{
123 : */
124 0 : #define PECI_RD_PKG_WR_LEN (5U)
125 0 : #define PECI_RD_PKG_LEN_BYTE (2U)
126 0 : #define PECI_RD_PKG_LEN_WORD (3U)
127 0 : #define PECI_RD_PKG_LEN_DWORD (5U)
128 0 : #define PECI_RD_PKG_CMD_LEN (8U)
129 : /** @} */
130 :
131 : /**
132 : * @name WrPkgConfig command format.
133 : * @{
134 : */
135 0 : #define PECI_WR_PKG_RD_LEN (1U)
136 0 : #define PECI_WR_PKG_LEN_BYTE (7U)
137 0 : #define PECI_WR_PKG_LEN_WORD (8U)
138 0 : #define PECI_WR_PKG_LEN_DWORD (10U)
139 0 : #define PECI_WR_PKG_CMD_LEN (9U)
140 : /** @} */
141 :
142 : /**
143 : * @name RdIAMSR command format.
144 : * @{
145 : */
146 0 : #define PECI_RD_IAMSR_WR_LEN (5U)
147 0 : #define PECI_RD_IAMSR_LEN_BYTE (2U)
148 0 : #define PECI_RD_IAMSR_LEN_WORD (3U)
149 0 : #define PECI_RD_IAMSR_LEN_DWORD (5U)
150 0 : #define PECI_RD_IAMSR_LEN_QWORD (9U)
151 0 : #define PECI_RD_IAMSR_CMD_LEN (8U)
152 : /** @} */
153 :
154 : /**
155 : * @name WrIAMSR command format.
156 : * @{
157 : */
158 0 : #define PECI_WR_IAMSR_RD_LEN (1U)
159 0 : #define PECI_WR_IAMSR_LEN_BYTE (7U)
160 0 : #define PECI_WR_IAMSR_LEN_WORD (8U)
161 0 : #define PECI_WR_IAMSR_LEN_DWORD (10U)
162 0 : #define PECI_WR_IAMSR_LEN_QWORD (14U)
163 0 : #define PECI_WR_IAMSR_CMD_LEN (9U)
164 : /** @} */
165 :
166 : /**
167 : * @name RdPCIConfig command format.
168 : * @{
169 : */
170 0 : #define PECI_RD_PCICFG_WR_LEN (6U)
171 0 : #define PECI_RD_PCICFG_LEN_BYTE (2U)
172 0 : #define PECI_RD_PCICFG_LEN_WORD (3U)
173 0 : #define PECI_RD_PCICFG_LEN_DWORD (5U)
174 0 : #define PECI_RD_PCICFG_CMD_LEN (9U)
175 : /** @} */
176 :
177 : /**
178 : * @name WrPCIConfig command format.
179 : * @{
180 : */
181 0 : #define PECI_WR_PCICFG_RD_LEN (1U)
182 0 : #define PECI_WR_PCICFG_LEN_BYTE (8U)
183 0 : #define PECI_WR_PCICFG_LEN_WORD (9U)
184 0 : #define PECI_WR_PCICFG_LEN_DWORD (11U)
185 0 : #define PECI_WR_PCICFG_CMD_LEN (10U)
186 : /** @} */
187 :
188 : /**
189 : * @name RdPCIConfigLocal command format.
190 : * @{
191 : */
192 0 : #define PECI_RD_PCICFGL_WR_LEN (5U)
193 0 : #define PECI_RD_PCICFGL_RD_LEN_BYTE (2U)
194 0 : #define PECI_RD_PCICFGL_RD_LEN_WORD (3U)
195 0 : #define PECI_RD_PCICFGL_RD_LEN_DWORD (5U)
196 0 : #define PECI_RD_PCICFGL_CMD_LEN (8U)
197 : /** @} */
198 :
199 : /**
200 : * @name WrPCIConfigLocal command format.
201 : * @{
202 : */
203 0 : #define PECI_WR_PCICFGL_RD_LEN (1U)
204 0 : #define PECI_WR_PCICFGL_WR_LEN_BYTE (7U)
205 0 : #define PECI_WR_PCICFGL_WR_LEN_WORD (8U)
206 0 : #define PECI_WR_PCICFGL_WR_LEN_DWORD (10U)
207 0 : #define PECI_WR_PCICFGL_CMD_LEN (9U)
208 : /** @} */
209 :
210 : /**
211 : * @brief PECI buffer structure
212 : */
213 1 : struct peci_buf {
214 : /**
215 : * Valid pointer on a data buffer, or NULL otherwise.
216 : */
217 1 : uint8_t *buf;
218 : /**
219 : * Length of the data buffer expected to be received without considering
220 : * the frame check sequence byte.
221 : *
222 : * @note Frame check sequence byte is added into rx buffer: need to allocate
223 : * an additional byte for this in rx buffer.
224 : */
225 1 : size_t len;
226 : };
227 :
228 : /**
229 : * @brief PECI transaction packet format.
230 : */
231 1 : struct peci_msg {
232 : /** Client address */
233 1 : uint8_t addr;
234 : /** Command code */
235 1 : enum peci_command_code cmd_code;
236 : /** Pointer to buffer of write data */
237 1 : struct peci_buf tx_buffer;
238 : /** Pointer to buffer of read data */
239 1 : struct peci_buf rx_buffer;
240 : /** PECI msg flags */
241 1 : uint8_t flags;
242 : };
243 :
244 : /**
245 : * @cond INTERNAL_HIDDEN
246 : *
247 : * PECI driver API definition and system call entry points
248 : *
249 : * (Internal use only.)
250 : */
251 : typedef int (*peci_config_t)(const struct device *dev, uint32_t bitrate);
252 : typedef int (*peci_transfer_t)(const struct device *dev, struct peci_msg *msg);
253 : typedef int (*peci_disable_t)(const struct device *dev);
254 : typedef int (*peci_enable_t)(const struct device *dev);
255 :
256 : __subsystem struct peci_driver_api {
257 : peci_config_t config;
258 : peci_disable_t disable;
259 : peci_enable_t enable;
260 : peci_transfer_t transfer;
261 : };
262 :
263 : /**
264 : * @endcond
265 : */
266 :
267 : /**
268 : * @brief Configures the PECI interface.
269 : *
270 : * @param dev Pointer to the device structure for the driver instance.
271 : * @param bitrate the selected bitrate expressed in Kbps.
272 : *
273 : * @retval 0 If successful.
274 : * @retval Negative errno code if failure.
275 : */
276 1 : __syscall int peci_config(const struct device *dev, uint32_t bitrate);
277 :
278 : static inline int z_impl_peci_config(const struct device *dev,
279 : uint32_t bitrate)
280 : {
281 : struct peci_driver_api *api;
282 :
283 : api = (struct peci_driver_api *)dev->api;
284 : return api->config(dev, bitrate);
285 : }
286 :
287 : /**
288 : * @brief Enable PECI interface.
289 : *
290 : * @param dev Pointer to the device structure for the driver instance.
291 : *
292 : * @retval 0 If successful.
293 : * @retval Negative errno code if failure.
294 : */
295 1 : __syscall int peci_enable(const struct device *dev);
296 :
297 : static inline int z_impl_peci_enable(const struct device *dev)
298 : {
299 : struct peci_driver_api *api;
300 :
301 : api = (struct peci_driver_api *)dev->api;
302 : return api->enable(dev);
303 : }
304 :
305 : /**
306 : * @brief Disable PECI interface.
307 : *
308 : * @param dev Pointer to the device structure for the driver instance.
309 : *
310 : * @retval 0 If successful.
311 : * @retval Negative errno code if failure.
312 : */
313 1 : __syscall int peci_disable(const struct device *dev);
314 :
315 : static inline int z_impl_peci_disable(const struct device *dev)
316 : {
317 : struct peci_driver_api *api;
318 :
319 : api = (struct peci_driver_api *)dev->api;
320 : return api->disable(dev);
321 : }
322 :
323 : /**
324 : * @brief Performs a PECI transaction.
325 : *
326 : * @param dev Pointer to the device structure for the driver instance.
327 : * @param msg Structure representing a PECI transaction.
328 : *
329 : * @retval 0 If successful.
330 : * @retval Negative errno code if failure.
331 : */
332 :
333 1 : __syscall int peci_transfer(const struct device *dev, struct peci_msg *msg);
334 :
335 : static inline int z_impl_peci_transfer(const struct device *dev,
336 : struct peci_msg *msg)
337 : {
338 : struct peci_driver_api *api;
339 :
340 : api = (struct peci_driver_api *)dev->api;
341 : return api->transfer(dev, msg);
342 : }
343 :
344 :
345 : #ifdef __cplusplus
346 : }
347 : #endif
348 :
349 : /**
350 : * @}
351 : */
352 :
353 : #include <zephyr/syscalls/peci.h>
354 :
355 : #endif /* ZEPHYR_INCLUDE_DRIVERS_PECI_H_ */
|