12#ifndef ZEPHYR_INCLUDE_ESPI_SAF_H_
13#define ZEPHYR_INCLUDE_ESPI_SAF_H_
96struct espi_saf_hw_cfg;
97struct espi_saf_flash_cfg;
131typedef int (*espi_saf_api_config)(
const struct device *dev,
134typedef int (*espi_saf_api_set_protection_regions)(
136 const struct espi_saf_protection *pr);
138typedef int (*espi_saf_api_activate)(
const struct device *dev);
140typedef bool (*espi_saf_api_get_channel_status)(
const struct device *dev);
142typedef int (*espi_saf_api_flash_read)(
const struct device *dev,
144typedef int (*espi_saf_api_flash_write)(
const struct device *dev,
146typedef int (*espi_saf_api_flash_erase)(
const struct device *dev,
149typedef int (*espi_saf_api_manage_callback)(
const struct device *dev,
150 struct espi_callback *callback,
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;
161 espi_saf_api_manage_callback manage_callback;
219static inline int z_impl_espi_saf_config(
const struct device *dev,
222 const struct espi_saf_driver_api *api =
223 (
const struct espi_saf_driver_api *)dev->
api;
225 return api->config(dev, cfg);
244 const struct espi_saf_protection *pr);
246static inline int z_impl_espi_saf_set_protection_regions(
248 const struct espi_saf_protection *pr)
250 const struct espi_saf_driver_api *api =
251 (
const struct espi_saf_driver_api *)dev->
api;
253 return api->set_protection_regions(dev, pr);
270static inline int z_impl_espi_saf_activate(
const struct device *dev)
272 const struct espi_saf_driver_api *api =
273 (
const struct espi_saf_driver_api *)dev->
api;
275 return api->activate(dev);
290static inline bool z_impl_espi_saf_get_channel_status(
293 const struct espi_saf_driver_api *api =
294 (
const struct espi_saf_driver_api *)dev->
api;
296 return api->get_channel_status(dev);
315static inline int z_impl_espi_saf_flash_read(
const struct device *dev,
318 const struct espi_saf_driver_api *api =
319 (
const struct espi_saf_driver_api *)dev->
api;
321 if (!api->flash_read) {
325 return api->flash_read(dev, pckt);
344static inline int z_impl_espi_saf_flash_write(
const struct device *dev,
347 const struct espi_saf_driver_api *api =
348 (
const struct espi_saf_driver_api *)dev->
api;
350 if (!api->flash_write) {
354 return api->flash_write(dev, pckt);
373static inline int z_impl_espi_saf_flash_erase(
const struct device *dev,
376 const struct espi_saf_driver_api *api =
377 (
const struct espi_saf_driver_api *)dev->
api;
379 if (!api->flash_erase) {
383 return api->flash_erase(dev, pckt);
460 __ASSERT(callback,
"Callback pointer should not be NULL");
461 __ASSERT(handler,
"Callback handler pointer should not be NULL");
463 callback->handler = handler;
464 callback->evt_type = evt_type;
480 struct espi_callback *callback)
482 const struct espi_saf_driver_api *api =
483 (
const struct espi_saf_driver_api *)dev->
api;
485 if (!api->manage_callback) {
489 return api->manage_callback(dev, callback,
true);
509 struct espi_callback *callback)
511 const struct espi_saf_driver_api *api =
512 (
const struct espi_saf_driver_api *)dev->
api;
514 if (!api->manage_callback) {
518 return api->manage_callback(dev, callback,
false);
528#include <syscalls/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