Zephyr API Documentation  3.5.0
A Scalable Open Source RTOS
3.5.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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
116};
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);
148/* Callbacks and traffic intercept */
149typedef int (*espi_saf_api_manage_callback)(const struct device *dev,
150 struct espi_callback *callback,
151 bool set);
152
153__subsystem struct espi_saf_driver_api {
154 espi_saf_api_config config;
155 espi_saf_api_set_protection_regions set_protection_regions;
156 espi_saf_api_activate activate;
157 espi_saf_api_get_channel_status get_channel_status;
158 espi_saf_api_flash_read flash_read;
159 espi_saf_api_flash_write flash_write;
160 espi_saf_api_flash_erase flash_erase;
161 espi_saf_api_manage_callback manage_callback;
162};
163
216__syscall int espi_saf_config(const struct device *dev,
217 const struct espi_saf_cfg *cfg);
218
219static inline int z_impl_espi_saf_config(const struct device *dev,
220 const struct espi_saf_cfg *cfg)
221{
222 const struct espi_saf_driver_api *api =
223 (const struct espi_saf_driver_api *)dev->api;
224
225 return api->config(dev, cfg);
226}
227
243 const struct device *dev,
244 const struct espi_saf_protection *pr);
245
246static inline int z_impl_espi_saf_set_protection_regions(
247 const struct device *dev,
248 const struct espi_saf_protection *pr)
249{
250 const struct espi_saf_driver_api *api =
251 (const struct espi_saf_driver_api *)dev->api;
252
253 return api->set_protection_regions(dev, pr);
254}
255
268__syscall int espi_saf_activate(const struct device *dev);
269
270static inline int z_impl_espi_saf_activate(const struct device *dev)
271{
272 const struct espi_saf_driver_api *api =
273 (const struct espi_saf_driver_api *)dev->api;
274
275 return api->activate(dev);
276}
277
288__syscall bool espi_saf_get_channel_status(const struct device *dev);
289
290static inline bool z_impl_espi_saf_get_channel_status(
291 const struct device *dev)
292{
293 const struct espi_saf_driver_api *api =
294 (const struct espi_saf_driver_api *)dev->api;
295
296 return api->get_channel_status(dev);
297}
298
312__syscall int espi_saf_flash_read(const struct device *dev,
313 struct espi_saf_packet *pckt);
314
315static inline int z_impl_espi_saf_flash_read(const struct device *dev,
316 struct espi_saf_packet *pckt)
317{
318 const struct espi_saf_driver_api *api =
319 (const struct espi_saf_driver_api *)dev->api;
320
321 if (!api->flash_read) {
322 return -ENOTSUP;
323 }
324
325 return api->flash_read(dev, pckt);
326}
327
341__syscall int espi_saf_flash_write(const struct device *dev,
342 struct espi_saf_packet *pckt);
343
344static inline int z_impl_espi_saf_flash_write(const struct device *dev,
345 struct espi_saf_packet *pckt)
346{
347 const struct espi_saf_driver_api *api =
348 (const struct espi_saf_driver_api *)dev->api;
349
350 if (!api->flash_write) {
351 return -ENOTSUP;
352 }
353
354 return api->flash_write(dev, pckt);
355}
356
370__syscall int espi_saf_flash_erase(const struct device *dev,
371 struct espi_saf_packet *pckt);
372
373static inline int z_impl_espi_saf_flash_erase(const struct device *dev,
374 struct espi_saf_packet *pckt)
375{
376 const struct espi_saf_driver_api *api =
377 (const struct espi_saf_driver_api *)dev->api;
378
379 if (!api->flash_erase) {
380 return -ENOTSUP;
381 }
382
383 return api->flash_erase(dev, pckt);
384}
385
456static inline void espi_saf_init_callback(struct espi_callback *callback,
458 enum espi_bus_event evt_type)
459{
460 __ASSERT(callback, "Callback pointer should not be NULL");
461 __ASSERT(handler, "Callback handler pointer should not be NULL");
462
463 callback->handler = handler;
464 callback->evt_type = evt_type;
465}
466
479static inline int espi_saf_add_callback(const struct device *dev,
480 struct espi_callback *callback)
481{
482 const struct espi_saf_driver_api *api =
483 (const struct espi_saf_driver_api *)dev->api;
484
485 if (!api->manage_callback) {
486 return -ENOTSUP;
487 }
488
489 return api->manage_callback(dev, callback, true);
490}
491
508static inline int espi_saf_remove_callback(const struct device *dev,
509 struct espi_callback *callback)
510{
511 const struct espi_saf_driver_api *api =
512 (const struct espi_saf_driver_api *)dev->api;
513
514 if (!api->manage_callback) {
515 return -ENOTSUP;
516 }
517
518 return api->manage_callback(dev, callback, false);
519}
520
521#ifdef __cplusplus
522}
523#endif
524
528#include <syscalls/espi_saf.h>
529#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.
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:383
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:456
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
bool espi_saf_get_channel_status(const struct device *dev)
Query to see if SAF is ready.
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:479
static int espi_saf_remove_callback(const struct device *dev, struct espi_callback *callback)
Remove an application callback.
Definition: espi_saf.h:508
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:115
#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:381
const void * api
Address of the API structure exposed by the device instance.
Definition: device.h:387
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