Zephyr Project API 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
150typedef int (*espi_saf_api_config)(const struct device *dev,
151 const struct espi_saf_cfg *cfg);
152
153typedef int (*espi_saf_api_set_protection_regions)(
154 const struct device *dev,
155 const struct espi_saf_protection *pr);
156
157typedef int (*espi_saf_api_activate)(const struct device *dev);
158
159typedef bool (*espi_saf_api_get_channel_status)(const struct device *dev);
160
161typedef int (*espi_saf_api_flash_read)(const struct device *dev,
162 struct espi_saf_packet *pckt);
163typedef int (*espi_saf_api_flash_write)(const struct device *dev,
164 struct espi_saf_packet *pckt);
165typedef int (*espi_saf_api_flash_erase)(const struct device *dev,
166 struct espi_saf_packet *pckt);
167typedef int (*espi_saf_api_flash_unsuccess)(const struct device *dev,
168 struct espi_saf_packet *pckt);
169/* Callbacks and traffic intercept */
170typedef int (*espi_saf_api_manage_callback)(const struct device *dev,
171 struct espi_callback *callback,
172 bool set);
173
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;
179 espi_saf_api_flash_read flash_read;
180 espi_saf_api_flash_write flash_write;
181 espi_saf_api_flash_erase flash_erase;
182 espi_saf_api_flash_unsuccess flash_unsuccess;
183 espi_saf_api_manage_callback manage_callback;
184};
185
189
238__syscall int espi_saf_config(const struct device *dev,
239 const struct espi_saf_cfg *cfg);
240
241static inline int z_impl_espi_saf_config(const struct device *dev,
242 const struct espi_saf_cfg *cfg)
243{
244 return DEVICE_API_GET(espi_saf, dev)->config(dev, cfg);
245}
246
262 const struct device *dev,
263 const struct espi_saf_protection *pr);
264
265static inline int z_impl_espi_saf_set_protection_regions(
266 const struct device *dev,
267 const struct espi_saf_protection *pr)
268{
269 return DEVICE_API_GET(espi_saf, dev)->set_protection_regions(dev, pr);
270}
271
284__syscall int espi_saf_activate(const struct device *dev);
285
286static inline int z_impl_espi_saf_activate(const struct device *dev)
287{
288 return DEVICE_API_GET(espi_saf, dev)->activate(dev);
289}
290
301__syscall bool espi_saf_get_channel_status(const struct device *dev);
302
303static inline bool z_impl_espi_saf_get_channel_status(
304 const struct device *dev)
305{
306 return DEVICE_API_GET(espi_saf, dev)->get_channel_status(dev);
307}
308
322__syscall int espi_saf_flash_read(const struct device *dev,
323 struct espi_saf_packet *pckt);
324
325static inline int z_impl_espi_saf_flash_read(const struct device *dev,
326 struct espi_saf_packet *pckt)
327{
328 const struct espi_saf_driver_api *api = DEVICE_API_GET(espi_saf, dev);
329
330 if (!api->flash_read) {
331 return -ENOTSUP;
332 }
333
334 return api->flash_read(dev, pckt);
335}
336
350__syscall int espi_saf_flash_write(const struct device *dev,
351 struct espi_saf_packet *pckt);
352
353static inline int z_impl_espi_saf_flash_write(const struct device *dev,
354 struct espi_saf_packet *pckt)
355{
356 const struct espi_saf_driver_api *api = DEVICE_API_GET(espi_saf, dev);
357
358 if (!api->flash_write) {
359 return -ENOTSUP;
360 }
361
362 return api->flash_write(dev, pckt);
363}
364
378__syscall int espi_saf_flash_erase(const struct device *dev,
379 struct espi_saf_packet *pckt);
380
381static inline int z_impl_espi_saf_flash_erase(const struct device *dev,
382 struct espi_saf_packet *pckt)
383{
384 const struct espi_saf_driver_api *api = DEVICE_API_GET(espi_saf, dev);
385
386 if (!api->flash_erase) {
387 return -ENOTSUP;
388 }
389
390 return api->flash_erase(dev, pckt);
391}
392
406__syscall int espi_saf_flash_unsuccess(const struct device *dev,
407 struct espi_saf_packet *pckt);
408
409static inline int z_impl_espi_saf_flash_unsuccess(const struct device *dev,
410 struct espi_saf_packet *pckt)
411{
412 const struct espi_saf_driver_api *api = DEVICE_API_GET(espi_saf, dev);
413
414 if (!api->flash_unsuccess) {
415 return -ENOTSUP;
416 }
417
418 return api->flash_unsuccess(dev, pckt);
419}
420
482
491static inline void espi_saf_init_callback(struct espi_callback *callback,
493 enum espi_bus_event evt_type)
494{
495 __ASSERT(callback, "Callback pointer should not be NULL");
496 __ASSERT(handler, "Callback handler pointer should not be NULL");
497
498 callback->handler = handler;
499 callback->evt_type = evt_type;
500}
501
514static inline int espi_saf_add_callback(const struct device *dev,
515 struct espi_callback *callback)
516{
517 const struct espi_saf_driver_api *api = DEVICE_API_GET(espi_saf, dev);
518
519 if (!api->manage_callback) {
520 return -ENOTSUP;
521 }
522
523 return api->manage_callback(dev, callback, true);
524}
525
542static inline int espi_saf_remove_callback(const struct device *dev,
543 struct espi_callback *callback)
544{
545 const struct espi_saf_driver_api *api = DEVICE_API_GET(espi_saf, dev);
546
547 if (!api->manage_callback) {
548 return -ENOTSUP;
549 }
550
551 return api->manage_callback(dev, callback, false);
552}
553
554#ifdef __cplusplus
555}
556#endif
557
561#include <zephyr/syscalls/espi_saf.h>
562#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_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