/* Copyright 2021 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#if !defined(__CROS_EC_HOST_COMMAND_H) || \
	defined(__CROS_EC_ZEPHYR_HOST_COMMAND_H)
#error "This file must only be included from host_command.h. " \
	"Include host_command.h directly"
#endif
#define __CROS_EC_ZEPHYR_HOST_COMMAND_H

#include <init.h>

#ifdef CONFIG_PLATFORM_EC_HOSTCMD

/**
 * See include/host_command.h for documentation.
 */
#define DECLARE_HOST_COMMAND(_command, _routine, _version_mask)            \
	STRUCT_SECTION_ITERABLE(host_command, _cros_hcmd_##_command) = {   \
		.command = _command,                                       \
		.handler = _routine,                                       \
		.version_mask = _version_mask,                             \
	}
#else /* !CONFIG_PLATFORM_EC_HOSTCMD */
#ifdef __clang__
#define DECLARE_HOST_COMMAND(command, routine, version_mask)
#else
#define DECLARE_HOST_COMMAND(command, routine, version_mask)         \
	enum ec_status (routine)(struct host_cmd_handler_args *args) \
		__attribute__((unused))
#endif /* __clang__ */
#endif /* CONFIG_PLATFORM_EC_HOSTCMD */

/* Copyright 2021 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#if !defined(__CROS_EC_HOST_COMMAND_H) || \
	defined(__CROS_EC_ZEPHYR_HOST_COMMAND_H)
#error "This file must only be included from host_command.h. " \
	"Include host_command.h directly"
#endif
#define __CROS_EC_ZEPHYR_HOST_COMMAND_H

#include <init.h>

#ifdef CONFIG_PLATFORM_EC_HOSTCMD

/**
 * See include/host_command.h for documentation.
 */
#define DECLARE_HOST_COMMAND(_command, _routine, _version_mask)            \
	STRUCT_SECTION_ITERABLE(host_command, _cros_hcmd_##_command) = {   \
		.command = _command,                                       \
		.handler = _routine,                                       \
		.version_mask = _version_mask,                             \
	}
#else /* !CONFIG_PLATFORM_EC_HOSTCMD */

/*
 * Create a fake routine to call the function. The linker should
 * garbage-collect it since it is behind 'if (0)'
 */
#define DECLARE_HOST_COMMAND(command, routine, version_mask)		\
	int __remove_ ## command(void)					\
	{								\
		if (0)							\
			routine(NULL);					\
		return 0;						\
	}

#endif /* CONFIG_PLATFORM_EC_HOSTCMD */

Use a different way of handling no host commands
zephyr: Use a different way of handling no host commands

When CONFIG_PLATFORM_EC_HOSTCMD is not enabled we want to silently drop
the handler routines from the build. The current approach works for gcc
but not for clang.

Use an exported function instead.

BUG=b:208648337
BRANCH=none
TEST=CQ and gitlab

Signed-off-by: Simon Glass <c00b0378376498bd9cd974c388df8854c0131d27@chromium.org>
Change-Id: I63f74e8081556c726472782f60bddbbfbc3e9bf0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3313320
Reviewed-by: Jeremy Bettis <4df7b5147fee087dca33c181f288ee7dbf56e022@chromium.org>
