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,
148typedef int (*espi_saf_api_flash_unsuccess)(
const struct device *dev,
151typedef int (*espi_saf_api_manage_callback)(
const struct device *dev,
152 struct espi_callback *callback,
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;
163 espi_saf_api_flash_unsuccess flash_unsuccess;
164 espi_saf_api_manage_callback manage_callback;
222static inline int z_impl_espi_saf_config(
const struct device *dev,
225 const struct espi_saf_driver_api *api =
226 (
const struct espi_saf_driver_api *)dev->
api;
228 return api->config(dev, cfg);
247 const struct espi_saf_protection *pr);
249static inline int z_impl_espi_saf_set_protection_regions(
251 const struct espi_saf_protection *pr)
253 const struct espi_saf_driver_api *api =
254 (
const struct espi_saf_driver_api *)dev->
api;
256 return api->set_protection_regions(dev, pr);
273static inline int z_impl_espi_saf_activate(
const struct device *dev)
275 const struct espi_saf_driver_api *api =
276 (
const struct espi_saf_driver_api *)dev->
api;
278 return api->activate(dev);
293static inline bool z_impl_espi_saf_get_channel_status(
296 const struct espi_saf_driver_api *api =
297 (
const struct espi_saf_driver_api *)dev->
api;
299 return api->get_channel_status(dev);
318static inline int z_impl_espi_saf_flash_read(
const struct device *dev,
321 const struct espi_saf_driver_api *api =
322 (
const struct espi_saf_driver_api *)dev->
api;
324 if (!api->flash_read) {
328 return api->flash_read(dev, pckt);
347static inline int z_impl_espi_saf_flash_write(
const struct device *dev,
350 const struct espi_saf_driver_api *api =
351 (
const struct espi_saf_driver_api *)dev->
api;
353 if (!api->flash_write) {
357 return api->flash_write(dev, pckt);
376static inline int z_impl_espi_saf_flash_erase(
const struct device *dev,
379 const struct espi_saf_driver_api *api =
380 (
const struct espi_saf_driver_api *)dev->
api;
382 if (!api->flash_erase) {
386 return api->flash_erase(dev, pckt);
405static inline int z_impl_espi_saf_flash_unsuccess(
const struct device *dev,
408 const struct espi_saf_driver_api *api =
409 (
const struct espi_saf_driver_api *)dev->
api;
411 if (!api->flash_unsuccess) {
415 return api->flash_unsuccess(dev, pckt);
492 __ASSERT(callback,
"Callback pointer should not be NULL");
493 __ASSERT(handler,
"Callback handler pointer should not be NULL");
495 callback->handler = handler;
496 callback->evt_type = evt_type;
512 struct espi_callback *callback)
514 const struct espi_saf_driver_api *api =
515 (
const struct espi_saf_driver_api *)dev->
api;
517 if (!api->manage_callback) {
521 return api->manage_callback(dev, callback,
true);
541 struct espi_callback *callback)
543 const struct espi_saf_driver_api *api =
544 (
const struct espi_saf_driver_api *)dev->
api;
546 if (!api->manage_callback) {
550 return api->manage_callback(dev, callback,
false);
560#include <zephyr/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:413
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.
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:403
const void * api
Address of the API structure exposed by the device instance.
Definition: device.h:409
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