summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFurquan Shaikh <furquan@google.com>2020-05-11 16:43:37 -0700
committerFurquan Shaikh <furquan@google.com>2020-05-12 20:05:27 +0000
commit470f627c2bbfda9ff7e42801fa93b5205e0ba654 (patch)
treed7c6f212aeb6a79562c2d888025759bdcf45cb8e
parentf3ac812e022f70d54dfcb94510eafa3d14462627 (diff)
espi: Add some helper functions for espi capability check
This change adds helper functions that can be used to check support for different slave capabilities. BUG=b:153675913 Signed-off-by: Furquan Shaikh <furquan@google.com> Change-Id: Ic66b06f9efcafd0eda4c6029fa67489de76bbed4 Reviewed-on: https://review.coreboot.org/c/coreboot/+/41253 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Raul Rangel <rrangel@chromium.org> Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
-rw-r--r--src/include/espi.h92
1 files changed, 92 insertions, 0 deletions
diff --git a/src/include/espi.h b/src/include/espi.h
index 171b1b8831..f0ae37383a 100644
--- a/src/include/espi.h
+++ b/src/include/espi.h
@@ -4,6 +4,8 @@
#ifndef __ESPI_H__
#define __ESPI_H__
+#include <stdint.h>
+
/* ESPI Slave Registers (Document # 327432-004 Revision 1.0 Chapter 7) */
#define ESPI_SLAVE_DEVICE_ID 0x04
@@ -226,4 +228,94 @@
#define ESPI_VW_VALUE(x, v) ((v) << (x))
#define ESPI_VW_SIGNAL_HIGH(x) (ESPI_VW_VALID(x) | ESPI_VW_VALUE(1, x))
#define ESPI_VW_SIGNAL_LOW(x) (ESPI_VW_VALID(x) | ESPI_VW_VALUE(0, x))
+
+static inline bool espi_slave_supports_quad_io(uint32_t gen_caps)
+{
+ uint32_t mode = gen_caps & ESPI_SLAVE_IO_MODE_SUPP_MASK;
+ return (mode == ESPI_SLAVE_IO_MODE_SUPP_SINGLE_QUAD) ||
+ (mode == ESPI_SLAVE_IO_MODE_SUPP_SINGLE_DUAL_QUAD);
+}
+
+static inline bool espi_slave_supports_dual_io(uint32_t gen_caps)
+{
+ uint32_t mode = gen_caps & ESPI_SLAVE_IO_MODE_SUPP_MASK;
+ return (mode == ESPI_SLAVE_IO_MODE_SUPP_SINGLE_DUAL) ||
+ (mode == ESPI_SLAVE_IO_MODE_SUPP_SINGLE_DUAL_QUAD);
+}
+
+static inline bool espi_slave_supports_66_mhz(uint32_t gen_caps)
+{
+ uint32_t freq = gen_caps & ESPI_SLAVE_OP_FREQ_SUPP_MASK;
+ return freq == ESPI_SLAVE_OP_FREQ_SUPP_66_MHZ;
+}
+
+static inline bool espi_slave_supports_50_mhz(uint32_t gen_caps)
+{
+ uint32_t freq = gen_caps & ESPI_SLAVE_OP_FREQ_SUPP_MASK;
+ return freq == ESPI_SLAVE_OP_FREQ_SUPP_50_MHZ;
+}
+
+static inline bool espi_slave_supports_33_mhz(uint32_t gen_caps)
+{
+ uint32_t freq = gen_caps & ESPI_SLAVE_OP_FREQ_SUPP_MASK;
+ return freq == ESPI_SLAVE_OP_FREQ_SUPP_33_MHZ;
+}
+
+static inline bool espi_slave_supports_25_mhz(uint32_t gen_caps)
+{
+ uint32_t freq = gen_caps & ESPI_SLAVE_OP_FREQ_SUPP_MASK;
+ return freq == ESPI_SLAVE_OP_FREQ_SUPP_25_MHZ;
+}
+
+static inline bool espi_slave_supports_20_mhz(uint32_t gen_caps)
+{
+ uint32_t freq = gen_caps & ESPI_SLAVE_OP_FREQ_SUPP_MASK;
+ return freq == ESPI_SLAVE_OP_FREQ_SUPP_20_MHZ;
+}
+
+static inline int espi_slave_max_speed_mhz_supported(uint32_t gen_caps)
+{
+ if (espi_slave_supports_66_mhz(gen_caps))
+ return 66;
+ else if (espi_slave_supports_50_mhz(gen_caps))
+ return 50;
+ else if (espi_slave_supports_33_mhz(gen_caps))
+ return 33;
+ else if (espi_slave_supports_25_mhz(gen_caps))
+ return 25;
+ else if (espi_slave_supports_20_mhz(gen_caps))
+ return 20;
+ return 0;
+}
+
+static inline bool espi_slave_supports_vw_channel(uint32_t gen_caps)
+{
+ return !!(gen_caps & ESPI_SLAVE_VW_CH_SUPP);
+}
+
+static inline bool espi_slave_supports_periph_channel(uint32_t gen_caps)
+{
+ return !!(gen_caps & ESPI_SLAVE_PERIPH_CH_SUPP);
+}
+
+static inline bool espi_slave_supports_oob_channel(uint32_t gen_caps)
+{
+ return !!(gen_caps & ESPI_SLAVE_OOB_CH_SUPP);
+}
+
+static inline bool espi_slave_supports_flash_channel(uint32_t gen_caps)
+{
+ return !!(gen_caps & ESPI_SLAVE_FLASH_CH_SUPP);
+}
+
+static inline bool espi_slave_is_channel_ready(uint32_t config)
+{
+ return !!(config & ESPI_SLAVE_CHANNEL_READY);
+}
+
+static inline uint32_t espi_slave_get_vw_count_supp(uint32_t vw_caps)
+{
+ return (vw_caps & ESPI_SLAVE_VW_COUNT_SUPP_MASK) >> ESPI_SLAVE_VW_COUNT_SUPP_SHIFT;
+}
+
#endif /* __ESPI_H__ */