12#ifndef ZEPHYR_INCLUDE_ESPI_SAF_H_
13#define ZEPHYR_INCLUDE_ESPI_SAF_H_
94struct espi_saf_hw_cfg;
95struct espi_saf_flash_cfg;
129typedef int (*espi_saf_api_config)(
const struct device *dev,
132typedef int (*espi_saf_api_set_protection_regions)(
134 const struct espi_saf_protection *pr);
136typedef int (*espi_saf_api_activate)(
const struct device *dev);
138typedef bool (*espi_saf_api_get_channel_status)(
const struct device *dev);
140typedef int (*espi_saf_api_flash_read)(
const struct device *dev,
142typedef int (*espi_saf_api_flash_write)(
const struct device *dev,
144typedef int (*espi_saf_api_flash_erase)(
const struct device *dev,
147typedef int (*espi_saf_api_manage_callback)(
const struct device *dev,
148 struct espi_callback *callback,
151__subsystem
struct espi_saf_driver_api {
152 espi_saf_api_config config;
153 espi_saf_api_set_protection_regions set_protection_regions;
154 espi_saf_api_activate activate;
155 espi_saf_api_get_channel_status get_channel_status;
159 espi_saf_api_manage_callback manage_callback;
215static inline int z_impl_espi_saf_config(
const struct device *dev,
218 const struct espi_saf_driver_api *api =
219 (
const struct espi_saf_driver_api *)dev->
api;
221 return api->config(dev, cfg);
240 const struct espi_saf_protection *pr);
242static inline int z_impl_espi_saf_set_protection_regions(
244 const struct espi_saf_protection *pr)
246 const struct espi_saf_driver_api *api =
247 (
const struct espi_saf_driver_api *)dev->
api;
249 return api->set_protection_regions(dev, pr);
266static inline int z_impl_espi_saf_activate(
const struct device *dev)
268 const struct espi_saf_driver_api *api =
269 (
const struct espi_saf_driver_api *)dev->
api;
271 return api->activate(dev);
286static inline bool z_impl_espi_saf_get_channel_status(
289 const struct espi_saf_driver_api *api =
290 (
const struct espi_saf_driver_api *)dev->
api;
292 return api->get_channel_status(dev);
311static inline int z_impl_espi_saf_flash_read(
const struct device *dev,
314 const struct espi_saf_driver_api *api =
315 (
const struct espi_saf_driver_api *)dev->
api;
317 if (!api->flash_read) {
321 return api->flash_read(dev, pckt);
340static inline int z_impl_espi_saf_flash_write(
const struct device *dev,
343 const struct espi_saf_driver_api *api =
344 (
const struct espi_saf_driver_api *)dev->
api;
346 if (!api->flash_write) {
350 return api->flash_write(dev, pckt);
369static inline int z_impl_espi_saf_flash_erase(
const struct device *dev,
372 const struct espi_saf_driver_api *api =
373 (
const struct espi_saf_driver_api *)dev->
api;
375 if (!api->flash_erase) {
379 return api->flash_erase(dev, pckt);
454 __ASSERT(callback,
"Callback pointer should not be NULL");
455 __ASSERT(
handler,
"Callback handler pointer should not be NULL");
458 callback->evt_type = evt_type;
474 struct espi_callback *callback)
476 const struct espi_saf_driver_api *api =
477 (
const struct espi_saf_driver_api *)dev->
api;
479 if (!api->manage_callback) {
483 return api->manage_callback(dev, callback,
true);
503 struct espi_callback *callback)
505 const struct espi_saf_driver_api *api =
506 (
const struct espi_saf_driver_api *)dev->
api;
508 if (!api->manage_callback) {
512 return api->manage_callback(dev, callback,
false);
522#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:342
static void espi_saf_init_callback(struct espi_callback *callback, espi_callback_handler_t handler, enum espi_bus_event evt_type)
Helper to initialize a struct espi_callback properly.
Definition: espi_saf.h:450
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:110
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:473
static int espi_saf_remove_callback(const struct device *dev, struct espi_callback *callback)
Remove an application callback.
Definition: espi_saf.h:502
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
Definition: errno.h:115
#define bool
Definition: stdbool.h:13
__UINT32_TYPE__ uint32_t
Definition: stdint.h:60
__UINT8_TYPE__ uint8_t
Definition: stdint.h:58
Runtime device structure (in ROM) per driver instance.
Definition: device.h:367
const void * api
Definition: device.h:373
eSPI SAF configuration parameters
Definition: espi_saf.h:101
struct espi_saf_hw_cfg hwcfg
Definition: espi_saf.h:103
struct espi_saf_flash_cfg * flash_cfgs
Definition: espi_saf.h:104
uint8_t nflash_devices
Definition: espi_saf.h:102
eSPI SAF transaction packet format
Definition: espi_saf.h:110
uint8_t * buf
Definition: espi_saf.h:112
uint32_t flash_addr
Definition: espi_saf.h:111
uint32_t len
Definition: espi_saf.h:113
static void handler(struct k_timer *timer)
Definition: main.c:19