Zephyr API Documentation 4.0.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
espi_saf.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 Intel Corporation.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
12#ifndef ZEPHYR_INCLUDE_ESPI_SAF_H_
13#define ZEPHYR_INCLUDE_ESPI_SAF_H_
14
15#include <zephyr/sys/__assert.h>
16#include <zephyr/types.h>
17#include <zephyr/device.h>
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
96struct espi_saf_hw_cfg;
97struct espi_saf_flash_cfg;
98struct espi_saf_pr;
99
105 struct espi_saf_hw_cfg hwcfg;
106 struct espi_saf_flash_cfg *flash_cfgs;
107};
108
117
118/*
119 *defined in espi.h
120 * struct espi_callback
121 * typedef void (*espi_callback_handler_t)()
122 */
123
131typedef int (*espi_saf_api_config)(const struct device *dev,
132 const struct espi_saf_cfg *cfg);
133
134typedef int (*espi_saf_api_set_protection_regions)(
135 const struct device *dev,
136 const struct espi_saf_protection *pr);
137
138typedef int (*espi_saf_api_activate)(const struct device *dev);
139
140typedef bool (*espi_saf_api_get_channel_status)(const struct device *dev);
141
142typedef int (*espi_saf_api_flash_read)(const struct device *dev,
143 struct espi_saf_packet *pckt);
144typedef int (*espi_saf_api_flash_write)(const struct device *dev,
145 struct espi_saf_packet *pckt);
146typedef int (*espi_saf_api_flash_erase)(const struct device *dev,
147 struct espi_saf_packet *pckt);
148typedef int (*espi_saf_api_flash_unsuccess)(const struct device *dev,
149 struct espi_saf_packet *pckt);
150/* Callbacks and traffic intercept */
151typedef int (*espi_saf_api_manage_callback)(const struct device *dev,
152 struct espi_callback *callback,
153 bool set);
154
155__subsystem struct espi_saf_driver_api {
156 espi_saf_api_config config;
157 espi_saf_api_set_protection_regions set_protection_regions;
158 espi_saf_api_activate activate;
159 espi_saf_api_get_channel_status get_channel_status;
160 espi_saf_api_flash_read flash_read;
161 espi_saf_api_flash_write flash_write;
162 espi_saf_api_flash_erase flash_erase;
163 espi_saf_api_flash_unsuccess flash_unsuccess;
164 espi_saf_api_manage_callback manage_callback;
165};
166
219__syscall int espi_saf_config(const struct device *dev,
220 const struct espi_saf_cfg *cfg);
221
222static inline int z_impl_espi_saf_config(const struct device *dev,
223 const struct espi_saf_cfg *cfg)
224{
225 const struct espi_saf_driver_api *api =
226 (const struct espi_saf_driver_api *)dev->api;
227
228 return api->config(dev, cfg);
229}
230
246 const struct device *dev,
247 const struct espi_saf_protection *pr);
248
249static inline int z_impl_espi_saf_set_protection_regions(
250 const struct device *dev,
251 const struct espi_saf_protection *pr)
252{
253 const struct espi_saf_driver_api *api =
254 (const struct espi_saf_driver_api *)dev->api;
255
256 return api->set_protection_regions(dev, pr);
257}
258
271__syscall int espi_saf_activate(const struct device *dev);
272
273static inline int z_impl_espi_saf_activate(const struct device *dev)
274{
275 const struct espi_saf_driver_api *api =
276 (const struct espi_saf_driver_api *)dev->api;
277
278 return api->activate(dev);
279}
280
291__syscall bool espi_saf_get_channel_status(const struct device *dev);
292
293static inline bool z_impl_espi_saf_get_channel_status(
294 const struct device *dev)
295{
296 const struct espi_saf_driver_api *api =
297 (const struct espi_saf_driver_api *)dev->api;
298
299 return api->get_channel_status(dev);
300}
301
315__syscall int espi_saf_flash_read(const struct device *dev,
316 struct espi_saf_packet *pckt);
317
318static inline int z_impl_espi_saf_flash_read(const struct device *dev,
319 struct espi_saf_packet *pckt)
320{
321 const struct espi_saf_driver_api *api =
322 (const struct espi_saf_driver_api *)dev->api;
323
324 if (!api->flash_read) {
325 return -ENOTSUP;
326 }
327
328 return api->flash_read(dev, pckt);
329}
330
344__syscall int espi_saf_flash_write(const struct device *dev,
345 struct espi_saf_packet *pckt);
346
347static inline int z_impl_espi_saf_flash_write(const struct device *dev,
348 struct espi_saf_packet *pckt)
349{
350 const struct espi_saf_driver_api *api =
351 (const struct espi_saf_driver_api *)dev->api;
352
353 if (!api->flash_write) {
354 return -ENOTSUP;
355 }
356
357 return api->flash_write(dev, pckt);
358}
359
373__syscall int espi_saf_flash_erase(const struct device *dev,
374 struct espi_saf_packet *pckt);
375
376static inline int z_impl_espi_saf_flash_erase(const struct device *dev,
377 struct espi_saf_packet *pckt)
378{
379 const struct espi_saf_driver_api *api =
380 (const struct espi_saf_driver_api *)dev->api;
381
382 if (!api->flash_erase) {
383 return -ENOTSUP;
384 }
385
386 return api->flash_erase(dev, pckt);
387}
388
402__syscall int espi_saf_flash_unsuccess(const struct device *dev,
403 struct espi_saf_packet *pckt);
404
405static inline int z_impl_espi_saf_flash_unsuccess(const struct device *dev,
406 struct espi_saf_packet *pckt)
407{
408 const struct espi_saf_driver_api *api =
409 (const struct espi_saf_driver_api *)dev->api;
410
411 if (!api->flash_unsuccess) {
412 return -ENOTSUP;
413 }
414
415 return api->flash_unsuccess(dev, pckt);
416}
417
488static inline void espi_saf_init_callback(struct espi_callback *callback,
490 enum espi_bus_event evt_type)
491{
492 __ASSERT(callback, "Callback pointer should not be NULL");
493 __ASSERT(handler, "Callback handler pointer should not be NULL");
494
495 callback->handler = handler;
496 callback->evt_type = evt_type;
497}
498
511static inline int espi_saf_add_callback(const struct device *dev,
512 struct espi_callback *callback)
513{
514 const struct espi_saf_driver_api *api =
515 (const struct espi_saf_driver_api *)dev->api;
516
517 if (!api->manage_callback) {
518 return -ENOTSUP;
519 }
520
521 return api->manage_callback(dev, callback, true);
522}
523
540static inline int espi_saf_remove_callback(const struct device *dev,
541 struct espi_callback *callback)
542{
543 const struct espi_saf_driver_api *api =
544 (const struct espi_saf_driver_api *)dev->api;
545
546 if (!api->manage_callback) {
547 return -ENOTSUP;
548 }
549
550 return api->manage_callback(dev, callback, false);
551}
552
553#ifdef __cplusplus
554}
555#endif
556
560#include <zephyr/syscalls/espi_saf.h>
561#endif /* ZEPHYR_INCLUDE_ESPI_SAF_H_ */
int espi_saf_flash_read(const struct device *dev, struct espi_saf_packet *pckt)
Sends a read request packet for slave attached flash.
int espi_saf_flash_write(const struct device *dev, struct espi_saf_packet *pckt)
Sends a write request packet for slave attached flash.
int espi_saf_flash_erase(const struct device *dev, struct espi_saf_packet *pckt)
Sends a write request packet for slave attached flash.
int espi_saf_set_protection_regions(const struct device *dev, const struct espi_saf_protection *pr)
Set one or more SAF protection regions.
static void espi_saf_init_callback(struct espi_callback *callback, espi_callback_handler_t handler, enum espi_bus_event evt_type)
Callback model.
Definition espi_saf.h:488
int espi_saf_config(const struct device *dev, const struct espi_saf_cfg *cfg)
Configure operation of a eSPI controller.
espi_bus_event
eSPI bus event.
Definition espi.h:114
int espi_saf_flash_unsuccess(const struct device *dev, struct espi_saf_packet *pckt)
Response unsuccessful completion for slave attached flash.
bool espi_saf_get_channel_status(const struct device *dev)
Query to see if SAF is ready.
void(* espi_callback_handler_t)(const struct device *dev, struct espi_callback *cb, struct espi_event espi_evt)
Define the application callback handler function signature.
Definition espi.h:413
int espi_saf_activate(const struct device *dev)
Activate SAF block.
static int espi_saf_add_callback(const struct device *dev, struct espi_callback *callback)
Add an application callback.
Definition espi_saf.h:511
static int espi_saf_remove_callback(const struct device *dev, struct espi_callback *callback)
Remove an application callback.
Definition espi_saf.h:540
int flash_erase(const struct device *dev, off_t offset, size_t size)
Erase part or all of a flash memory.
int flash_write(const struct device *dev, off_t offset, const void *data, size_t len)
Write buffer into flash memory.
int flash_read(const struct device *dev, off_t offset, void *data, size_t len)
Read data from flash.
#define ENOTSUP
Unsupported value.
Definition errno.h:114
#define bool
Definition stdbool.h:13
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
Runtime device structure (in ROM) per driver instance.
Definition device.h:412
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:418
eSPI SAF configuration parameters
Definition espi_saf.h:103
struct espi_saf_hw_cfg hwcfg
Definition espi_saf.h:105
struct espi_saf_flash_cfg * flash_cfgs
Definition espi_saf.h:106
uint8_t nflash_devices
Definition espi_saf.h:104
eSPI SAF transaction packet format
Definition espi_saf.h:112
uint8_t * buf
Definition espi_saf.h:114
uint32_t flash_addr
Definition espi_saf.h:113
uint32_t len
Definition espi_saf.h:115