Zephyr API Documentation 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
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
11
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
32
88
89
94
95
97
114
115struct espi_saf_hw_cfg;
116struct espi_saf_flash_cfg;
117struct espi_saf_pr;
118
124 struct espi_saf_hw_cfg hwcfg;
125 struct espi_saf_flash_cfg *flash_cfgs;
126};
127
136
137/*
138 *defined in espi.h
139 * struct espi_callback
140 * typedef void (*espi_callback_handler_t)()
141 */
142
147
152typedef int (*espi_saf_api_config)(const struct device *dev,
153 const struct espi_saf_cfg *cfg);
154
160 const struct device *dev,
161 const struct espi_saf_protection *pr);
162
167typedef int (*espi_saf_api_activate)(const struct device *dev);
168
173typedef bool (*espi_saf_api_get_channel_status)(const struct device *dev);
174
179typedef int (*espi_saf_api_flash_read)(const struct device *dev,
180 struct espi_saf_packet *pckt);
185typedef int (*espi_saf_api_flash_write)(const struct device *dev,
186 struct espi_saf_packet *pckt);
191typedef int (*espi_saf_api_flash_erase)(const struct device *dev,
192 struct espi_saf_packet *pckt);
197typedef int (*espi_saf_api_flash_unsuccess)(const struct device *dev,
198 struct espi_saf_packet *pckt);
203typedef int (*espi_saf_api_manage_callback)(const struct device *dev,
204 struct espi_callback *callback,
205 bool set);
206
230
232
281__syscall int espi_saf_config(const struct device *dev,
282 const struct espi_saf_cfg *cfg);
283
284static inline int z_impl_espi_saf_config(const struct device *dev,
285 const struct espi_saf_cfg *cfg)
286{
287 return DEVICE_API_GET(espi_saf, dev)->config(dev, cfg);
288}
289
305 const struct device *dev,
306 const struct espi_saf_protection *pr);
307
308static inline int z_impl_espi_saf_set_protection_regions(
309 const struct device *dev,
310 const struct espi_saf_protection *pr)
311{
312 return DEVICE_API_GET(espi_saf, dev)->set_protection_regions(dev, pr);
313}
314
327__syscall int espi_saf_activate(const struct device *dev);
328
329static inline int z_impl_espi_saf_activate(const struct device *dev)
330{
331 return DEVICE_API_GET(espi_saf, dev)->activate(dev);
332}
333
344__syscall bool espi_saf_get_channel_status(const struct device *dev);
345
346static inline bool z_impl_espi_saf_get_channel_status(
347 const struct device *dev)
348{
349 return DEVICE_API_GET(espi_saf, dev)->get_channel_status(dev);
350}
351
365__syscall int espi_saf_flash_read(const struct device *dev,
366 struct espi_saf_packet *pckt);
367
368static inline int z_impl_espi_saf_flash_read(const struct device *dev,
369 struct espi_saf_packet *pckt)
370{
371 const struct espi_saf_driver_api *api = DEVICE_API_GET(espi_saf, dev);
372
373 if (!api->flash_read) {
374 return -ENOTSUP;
375 }
376
377 return api->flash_read(dev, pckt);
378}
379
393__syscall int espi_saf_flash_write(const struct device *dev,
394 struct espi_saf_packet *pckt);
395
396static inline int z_impl_espi_saf_flash_write(const struct device *dev,
397 struct espi_saf_packet *pckt)
398{
399 const struct espi_saf_driver_api *api = DEVICE_API_GET(espi_saf, dev);
400
401 if (!api->flash_write) {
402 return -ENOTSUP;
403 }
404
405 return api->flash_write(dev, pckt);
406}
407
421__syscall int espi_saf_flash_erase(const struct device *dev,
422 struct espi_saf_packet *pckt);
423
424static inline int z_impl_espi_saf_flash_erase(const struct device *dev,
425 struct espi_saf_packet *pckt)
426{
427 const struct espi_saf_driver_api *api = DEVICE_API_GET(espi_saf, dev);
428
429 if (!api->flash_erase) {
430 return -ENOTSUP;
431 }
432
433 return api->flash_erase(dev, pckt);
434}
435
449__syscall int espi_saf_flash_unsuccess(const struct device *dev,
450 struct espi_saf_packet *pckt);
451
452static inline int z_impl_espi_saf_flash_unsuccess(const struct device *dev,
453 struct espi_saf_packet *pckt)
454{
455 const struct espi_saf_driver_api *api = DEVICE_API_GET(espi_saf, dev);
456
457 if (!api->flash_unsuccess) {
458 return -ENOTSUP;
459 }
460
461 return api->flash_unsuccess(dev, pckt);
462}
463
525
534static inline void espi_saf_init_callback(struct espi_callback *callback,
536 enum espi_bus_event evt_type)
537{
538 __ASSERT(callback, "Callback pointer should not be NULL");
539 __ASSERT(handler, "Callback handler pointer should not be NULL");
540
541 callback->handler = handler;
542 callback->evt_type = evt_type;
543}
544
557static inline int espi_saf_add_callback(const struct device *dev,
558 struct espi_callback *callback)
559{
560 const struct espi_saf_driver_api *api = DEVICE_API_GET(espi_saf, dev);
561
562 if (!api->manage_callback) {
563 return -ENOTSUP;
564 }
565
566 return api->manage_callback(dev, callback, true);
567}
568
585static inline int espi_saf_remove_callback(const struct device *dev,
586 struct espi_callback *callback)
587{
588 const struct espi_saf_driver_api *api = DEVICE_API_GET(espi_saf, dev);
589
590 if (!api->manage_callback) {
591 return -ENOTSUP;
592 }
593
594 return api->manage_callback(dev, callback, false);
595}
596
597#ifdef __cplusplus
598}
599#endif
600
604#include <zephyr/syscalls/espi_saf.h>
605#endif /* ZEPHYR_INCLUDE_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_api_activate)(const struct device *dev)
Callback API to activate the SAF block.
Definition espi_saf.h:167
int(* espi_saf_api_manage_callback)(const struct device *dev, struct espi_callback *callback, bool set)
Callback API to manage (add or remove) application callbacks.
Definition espi_saf.h:203
int(* espi_saf_api_flash_write)(const struct device *dev, struct espi_saf_packet *pckt)
Callback API to send a write request for slave attached flash.
Definition espi_saf.h:185
int(* espi_saf_api_flash_erase)(const struct device *dev, struct espi_saf_packet *pckt)
Callback API to send an erase request for slave attached flash.
Definition espi_saf.h:191
int(* espi_saf_api_config)(const struct device *dev, const struct espi_saf_cfg *cfg)
Callback API to configure the eSPI SAF controller.
Definition espi_saf.h:152
int(* espi_saf_api_flash_read)(const struct device *dev, struct espi_saf_packet *pckt)
Callback API to send a read request for slave attached flash.
Definition espi_saf.h:179
bool(* espi_saf_api_get_channel_status)(const struct device *dev)
Callback API to query if SAF is ready.
Definition espi_saf.h:173
int(* espi_saf_api_flash_unsuccess)(const struct device *dev, struct espi_saf_packet *pckt)
Callback API to respond unsuccessful completion for slave attached flash.
Definition espi_saf.h:197
int(* espi_saf_api_set_protection_regions)(const struct device *dev, const struct espi_saf_protection *pr)
Callback API to set one or more SAF protection regions.
Definition espi_saf.h:159
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:534
int espi_saf_config(const struct device *dev, const struct espi_saf_cfg *cfg)
Configure operation of an 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:557
static int espi_saf_remove_callback(const struct device *dev, struct espi_callback *callback)
Remove an application callback.
Definition espi_saf.h:585
@ 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
#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
<span class="mlabel">Driver Operations</span> eSPI SAF driver operations
Definition espi_saf.h:210
espi_saf_api_get_channel_status get_channel_status
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition espi_saf.h:218
espi_saf_api_activate activate
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition espi_saf.h:216
espi_saf_api_flash_read flash_read
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition espi_saf.h:220
espi_saf_api_set_protection_regions set_protection_regions
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition espi_saf.h:214
espi_saf_api_config config
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition espi_saf.h:212
espi_saf_api_flash_write flash_write
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition espi_saf.h:222
espi_saf_api_flash_erase flash_erase
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition espi_saf.h:224
espi_saf_api_flash_unsuccess flash_unsuccess
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition espi_saf.h:226
espi_saf_api_manage_callback manage_callback
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition espi_saf.h:228
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