From c01b28e5da86b783917523beaa97b1b81d38019c Mon Sep 17 00:00:00 2001 From: Keith Short Date: Thu, 15 Apr 2021 09:28:43 -0600 Subject: zephyr: validate interrupt flags at build time The name spaces for GPIO interrupt flags are similar between Chromium EC and Zephyr. Add a build time check that the flags are valid for Zephyr. BUG=b:182398910 BRANCH=none TEST=zmake testall TEST=Set a GPIO interrupt flag to an invalid value and verify build error. Cq-Depend: chromium:2825909 Signed-off-by: Keith Short Change-Id: I27caff1fed3827c09450c743cb62ce8a7cbdaac4 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2826415 Reviewed-by: Jack Rosenthal Commit-Queue: Jack Rosenthal --- zephyr/shim/src/gpio.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/zephyr/shim/src/gpio.c b/zephyr/shim/src/gpio.c index 37cfe3e3b4..30a074b9fd 100644 --- a/zephyr/shim/src/gpio.c +++ b/zephyr/shim/src/gpio.c @@ -80,6 +80,29 @@ static void gpio_handler_shim(const struct device *port, gpio->irq_handler(gpio->signal); } +/* + * Validate interrupt flags are valid for the Zephyr GPIO driver. + */ +#define IS_GPIO_INTERRUPT_FLAG(flag, mask) ((flag & mask) == mask) +#define VALID_GPIO_INTERRUPT_FLAG(flag) \ + (IS_GPIO_INTERRUPT_FLAG(flag, GPIO_INT_EDGE_RISING) || \ + IS_GPIO_INTERRUPT_FLAG(flag, GPIO_INT_EDGE_FALLING) || \ + IS_GPIO_INTERRUPT_FLAG(flag, GPIO_INT_EDGE_BOTH) || \ + IS_GPIO_INTERRUPT_FLAG(flag, GPIO_INT_LEVEL_LOW) || \ + IS_GPIO_INTERRUPT_FLAG(flag, GPIO_INT_LEVEL_HIGH) || \ + IS_GPIO_INTERRUPT_FLAG(flag, GPIO_INT_EDGE_TO_INACTIVE) || \ + IS_GPIO_INTERRUPT_FLAG(flag, GPIO_INT_EDGE_TO_ACTIVE) || \ + IS_GPIO_INTERRUPT_FLAG(flag, GPIO_INT_LEVEL_INACTIVE) || \ + IS_GPIO_INTERRUPT_FLAG(flag, GPIO_INT_LEVEL_ACTIVE)) + +#define GPIO_INT(sig, f, cb) \ + BUILD_ASSERT(VALID_GPIO_INTERRUPT_FLAG(f), \ + STRINGIFY(sig) " is not using Zephyr interrupt flags"); +#ifdef EC_CROS_GPIO_INTERRUPTS +EC_CROS_GPIO_INTERRUPTS +#endif +#undef GPIO_INT + /* * Each zephyr project should define EC_CROS_GPIO_INTERRUPTS in their gpio_map.h * file if there are any interrupts that should be registered. The -- cgit v1.2.1