12#ifndef ZEPHYR_INCLUDE_ESPI_SAF_H_
13#define ZEPHYR_INCLUDE_ESPI_SAF_H_
115struct espi_saf_hw_cfg;
116struct espi_saf_flash_cfg;
150typedef int (*espi_saf_api_config)(
const struct device *dev,
153typedef int (*espi_saf_api_set_protection_regions)(
155 const struct espi_saf_protection *pr);
157typedef int (*espi_saf_api_activate)(
const struct device *dev);
159typedef bool (*espi_saf_api_get_channel_status)(
const struct device *dev);
161typedef int (*espi_saf_api_flash_read)(
const struct device *dev,
163typedef int (*espi_saf_api_flash_write)(
const struct device *dev,
165typedef int (*espi_saf_api_flash_erase)(
const struct device *dev,
167typedef int (*espi_saf_api_flash_unsuccess)(
const struct device *dev,
170typedef int (*espi_saf_api_manage_callback)(
const struct device *dev,
171 struct espi_callback *callback,
174__subsystem
struct espi_saf_driver_api {
175 espi_saf_api_config config;
176 espi_saf_api_set_protection_regions set_protection_regions;
177 espi_saf_api_activate activate;
178 espi_saf_api_get_channel_status get_channel_status;
182 espi_saf_api_flash_unsuccess flash_unsuccess;
183 espi_saf_api_manage_callback manage_callback;
241static inline int z_impl_espi_saf_config(
const struct device *dev,
263 const struct espi_saf_protection *pr);
265static inline int z_impl_espi_saf_set_protection_regions(
267 const struct espi_saf_protection *pr)
269 return DEVICE_API_GET(espi_saf, dev)->set_protection_regions(dev, pr);
286static inline int z_impl_espi_saf_activate(
const struct device *dev)
303static inline bool z_impl_espi_saf_get_channel_status(
325static inline int z_impl_espi_saf_flash_read(
const struct device *dev,
328 const struct espi_saf_driver_api *api =
DEVICE_API_GET(espi_saf, dev);
330 if (!api->flash_read) {
334 return api->flash_read(dev, pckt);
353static inline int z_impl_espi_saf_flash_write(
const struct device *dev,
356 const struct espi_saf_driver_api *api =
DEVICE_API_GET(espi_saf, dev);
358 if (!api->flash_write) {
362 return api->flash_write(dev, pckt);
381static inline int z_impl_espi_saf_flash_erase(
const struct device *dev,
384 const struct espi_saf_driver_api *api =
DEVICE_API_GET(espi_saf, dev);
386 if (!api->flash_erase) {
390 return api->flash_erase(dev, pckt);
409static inline int z_impl_espi_saf_flash_unsuccess(
const struct device *dev,
412 const struct espi_saf_driver_api *api =
DEVICE_API_GET(espi_saf, dev);
414 if (!api->flash_unsuccess) {
418 return api->flash_unsuccess(dev, pckt);
495 __ASSERT(callback,
"Callback pointer should not be NULL");
496 __ASSERT(handler,
"Callback handler pointer should not be NULL");
498 callback->handler = handler;
499 callback->evt_type = evt_type;
515 struct espi_callback *callback)
517 const struct espi_saf_driver_api *api =
DEVICE_API_GET(espi_saf, dev);
519 if (!api->manage_callback) {
523 return api->manage_callback(dev, callback,
true);
543 struct espi_callback *callback)
545 const struct espi_saf_driver_api *api =
DEVICE_API_GET(espi_saf, dev);
547 if (!api->manage_callback) {
551 return api->manage_callback(dev, callback,
false);
561#include <zephyr/syscalls/espi_saf.h>
#define DEVICE_API_GET(_class, _dev)
Expands to the pointer of a device's API for a given class.
Definition device.h:1449
espi_bus_event
eSPI bus event.
Definition espi.h:121
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:603
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 an erase 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:491
int espi_saf_config(const struct device *dev, const struct espi_saf_cfg *cfg)
Configure operation of a eSPI controller.
espi_taf_event
eSPI TAF notification type.
Definition espi_saf.h:104
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:514
static int espi_saf_remove_callback(const struct device *dev, struct espi_callback *callback)
Remove an application callback.
Definition espi_saf.h:542
@ ESPI_TAF_EVENT_HOST_REQUEST
TAF flash access request was from the Host eSPI controller.
Definition espi_saf.h:108
@ ESPI_TAF_EVENT_NO_REQUEST
TAF generic event.
Definition espi_saf.h:106
@ ESPI_TAF_EVENT_EC0_REQUEST
TAF flash access request was from EC firmware portal 0.
Definition espi_saf.h:110
@ ESPI_TAF_EVENT_MAX_REQUEST
maximum request
Definition espi_saf.h:112
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:513
eSPI SAF configuration parameters
Definition espi_saf.h:122
struct espi_saf_hw_cfg hwcfg
Definition espi_saf.h:124
struct espi_saf_flash_cfg * flash_cfgs
Definition espi_saf.h:125
uint8_t nflash_devices
Definition espi_saf.h:123
eSPI SAF transaction packet format
Definition espi_saf.h:131
uint8_t * buf
Definition espi_saf.h:133
uint32_t flash_addr
Definition espi_saf.h:132
uint32_t len
Definition espi_saf.h:134