cleanup: include/: move entropy.h to drivers/entropy.h

move entropy.h to drivers/entropy.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
Anas Nashif 2019-06-25 15:53:49 -04:00
commit 969f8f1c68
24 changed files with 145 additions and 130 deletions

View file

@ -6,7 +6,7 @@
#include <kernel.h> #include <kernel.h>
#include <device.h> #include <device.h>
#include <entropy.h> #include <drivers/entropy.h>
#include <irq.h> #include <irq.h>
#include <ring_buffer.h> #include <ring_buffer.h>
#include <sys/sys_io.h> #include <sys/sys_io.h>

View file

@ -5,7 +5,7 @@
*/ */
#include <string.h> #include <string.h>
#include <entropy.h> #include <drivers/entropy.h>
static inline u32_t entropy_esp32_get_u32(void) static inline u32_t entropy_esp32_get_u32(void)
{ {

View file

@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
#include <entropy.h> #include <drivers/entropy.h>
#include <syscall_handler.h> #include <syscall_handler.h>
Z_SYSCALL_HANDLER(entropy_get_entropy, dev, buffer, len) Z_SYSCALL_HANDLER(entropy_get_entropy, dev, buffer, len)

View file

@ -5,7 +5,7 @@
*/ */
#include <device.h> #include <device.h>
#include <entropy.h> #include <drivers/entropy.h>
#include <random/rand32.h> #include <random/rand32.h>
#include <init.h> #include <init.h>

View file

@ -5,7 +5,7 @@
*/ */
#include <device.h> #include <device.h>
#include <entropy.h> #include <drivers/entropy.h>
#include <random/rand32.h> #include <random/rand32.h>
#include <init.h> #include <init.h>

View file

@ -5,7 +5,7 @@
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
#include <entropy.h> #include <drivers/entropy.h>
#include <sys/atomic.h> #include <sys/atomic.h>
#include <soc.h> #include <soc.h>
#include "nrf_rng.h" #include "nrf_rng.h"

View file

@ -5,7 +5,7 @@
*/ */
#include <device.h> #include <device.h>
#include <entropy.h> #include <drivers/entropy.h>
#include <errno.h> #include <errno.h>
#include <init.h> #include <init.h>
#include <soc.h> #include <soc.h>

View file

@ -6,7 +6,7 @@
#include <kernel.h> #include <kernel.h>
#include <device.h> #include <device.h>
#include <entropy.h> #include <drivers/entropy.h>
#include <random/rand32.h> #include <random/rand32.h>
#include <init.h> #include <init.h>
#include <misc/__assert.h> #include <misc/__assert.h>

View file

@ -12,7 +12,7 @@
*/ */
#include "device.h" #include "device.h"
#include "entropy.h" #include <drivers/entropy.h>
#include "init.h" #include "init.h"
#include "misc/util.h" #include "misc/util.h"
#include <stdlib.h> #include <stdlib.h>

119
include/drivers/entropy.h Normal file
View file

@ -0,0 +1,119 @@
/**
* @file entropy.h
*
* @brief Public APIs for the entropy driver.
*/
/*
* Copyright (c) 2016 ARM Ltd.
* Copyright (c) 2017 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef ZEPHYR_INCLUDE_DRIVERS_ENTROPY_H_
#define ZEPHYR_INCLUDE_DRIVERS_ENTROPY_H_
/**
* @brief Entropy Interface
* @defgroup entropy_interface Entropy Interface
* @ingroup io_interfaces
* @{
*/
#include <zephyr/types.h>
#include <device.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @typedef entropy_get_entropy_t
* @brief Callback API to get entropy.
*
* See entropy_get_entropy() for argument description
*/
typedef int (*entropy_get_entropy_t)(struct device *dev,
u8_t *buffer,
u16_t length);
/**
* @typedef entropy_get_entropy_isr_t
* @brief Callback API to get entropy from an ISR.
*
* See entropy_get_entropy_isr() for argument description
*/
typedef int (*entropy_get_entropy_isr_t)(struct device *dev,
u8_t *buffer,
u16_t length,
u32_t flags);
struct entropy_driver_api {
entropy_get_entropy_t get_entropy;
entropy_get_entropy_isr_t get_entropy_isr;
};
/**
* @brief Fills a buffer with entropy. Blocks if required in order to
* generate the necessary random data.
*
* @param dev Pointer to the entropy device.
* @param buffer Buffer to fill with entropy.
* @param length Buffer length.
* @retval 0 on success.
* @retval -ERRNO errno code on error.
*/
__syscall int entropy_get_entropy(struct device *dev,
u8_t *buffer,
u16_t length);
static inline int z_impl_entropy_get_entropy(struct device *dev,
u8_t *buffer,
u16_t length)
{
const struct entropy_driver_api *api =
(const struct entropy_driver_api *)dev->driver_api;
__ASSERT(api->get_entropy != NULL,
"Callback pointer should not be NULL");
return api->get_entropy(dev, buffer, length);
}
/* Busy-wait for random data to be ready */
#define ENTROPY_BUSYWAIT BIT(0)
/**
* @brief Fills a buffer with entropy in a non-blocking or busy-wait manner.
* Callable from ISRs.
*
* @param dev Pointer to the device structure.
* @param buffer Buffer to fill with entropy.
* @param length Buffer length.
* @param flags Flags to modify the behavior of the call.
* @retval number of bytes filled with entropy or -error.
*/
static inline int entropy_get_entropy_isr(struct device *dev,
u8_t *buffer,
u16_t length,
u32_t flags)
{
const struct entropy_driver_api *api =
(const struct entropy_driver_api *)dev->driver_api;
if (unlikely(!api->get_entropy_isr)) {
return -ENOTSUP;
}
return api->get_entropy_isr(dev, buffer, length, flags);
}
#ifdef __cplusplus
}
#endif
/**
* @}
*/
#include <syscalls/entropy.h>
#endif /* ZEPHYR_INCLUDE_DRIVERS_ENTROPY_H_ */

View file

@ -1,119 +1,15 @@
/**
* @file entropy.h
*
* @brief Public APIs for the entropy driver.
*/
/* /*
* Copyright (c) 2016 ARM Ltd. * Copyright (c) 2019 Intel Corporation
* Copyright (c) 2017 Intel Corporation
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
#ifndef ZEPHYR_INCLUDE_ENTROPY_H_ #ifndef ZEPHYR_INCLUDE_ENTROPY_H_
#define ZEPHYR_INCLUDE_ENTROPY_H_ #define ZEPHYR_INCLUDE_ENTROPY_H_
/** #ifndef CONFIG_COMPAT_INCLUDES
* @brief Entropy Interface #warning "This header file has moved, include <drivers/entropy.h> instead."
* @defgroup entropy_interface Entropy Interface
* @ingroup io_interfaces
* @{
*/
#include <zephyr/types.h>
#include <device.h>
#ifdef __cplusplus
extern "C" {
#endif #endif
/** #include <drivers/entropy.h>
* @typedef entropy_get_entropy_t
* @brief Callback API to get entropy.
*
* See entropy_get_entropy() for argument description
*/
typedef int (*entropy_get_entropy_t)(struct device *dev,
u8_t *buffer,
u16_t length);
/**
* @typedef entropy_get_entropy_isr_t
* @brief Callback API to get entropy from an ISR.
*
* See entropy_get_entropy_isr() for argument description
*/
typedef int (*entropy_get_entropy_isr_t)(struct device *dev,
u8_t *buffer,
u16_t length,
u32_t flags);
struct entropy_driver_api {
entropy_get_entropy_t get_entropy;
entropy_get_entropy_isr_t get_entropy_isr;
};
/**
* @brief Fills a buffer with entropy. Blocks if required in order to
* generate the necessary random data.
*
* @param dev Pointer to the entropy device.
* @param buffer Buffer to fill with entropy.
* @param length Buffer length.
* @retval 0 on success.
* @retval -ERRNO errno code on error.
*/
__syscall int entropy_get_entropy(struct device *dev,
u8_t *buffer,
u16_t length);
static inline int z_impl_entropy_get_entropy(struct device *dev,
u8_t *buffer,
u16_t length)
{
const struct entropy_driver_api *api =
(const struct entropy_driver_api *)dev->driver_api;
__ASSERT(api->get_entropy != NULL,
"Callback pointer should not be NULL");
return api->get_entropy(dev, buffer, length);
}
/* Busy-wait for random data to be ready */
#define ENTROPY_BUSYWAIT BIT(0)
/**
* @brief Fills a buffer with entropy in a non-blocking or busy-wait manner.
* Callable from ISRs.
*
* @param dev Pointer to the device structure.
* @param buffer Buffer to fill with entropy.
* @param length Buffer length.
* @param flags Flags to modify the behavior of the call.
* @retval number of bytes filled with entropy or -error.
*/
static inline int entropy_get_entropy_isr(struct device *dev,
u8_t *buffer,
u16_t length,
u32_t flags)
{
const struct entropy_driver_api *api =
(const struct entropy_driver_api *)dev->driver_api;
if (unlikely(!api->get_entropy_isr)) {
return -ENOTSUP;
}
return api->get_entropy_isr(dev, buffer, length, flags);
}
#ifdef __cplusplus
}
#endif
/**
* @}
*/
#include <syscalls/entropy.h>
#endif /* ZEPHYR_INCLUDE_ENTROPY_H_ */ #endif /* ZEPHYR_INCLUDE_ENTROPY_H_ */

View file

@ -29,7 +29,7 @@
#include <misc/dlist.h> #include <misc/dlist.h>
#include <kernel_internal.h> #include <kernel_internal.h>
#include <kswap.h> #include <kswap.h>
#include <entropy.h> #include <drivers/entropy.h>
#include <logging/log_ctrl.h> #include <logging/log_ctrl.h>
#include <debug/tracing.h> #include <debug/tracing.h>
#include <stdbool.h> #include <stdbool.h>

View file

@ -5,7 +5,7 @@
*/ */
#include <zephyr.h> #include <zephyr.h>
#include <entropy.h> #include <drivers/entropy.h>
#include <stdio.h> #include <stdio.h>
void main(void) void main(void)

View file

@ -13,7 +13,7 @@ LOG_MODULE_DECLARE(net_google_iot_mqtt, LOG_LEVEL_DBG);
#include <zephyr.h> #include <zephyr.h>
#include <string.h> #include <string.h>
#include <data/jwt.h> #include <data/jwt.h>
#include <entropy.h> #include <drivers/entropy.h>
#include <net/tls_credentials.h> #include <net/tls_credentials.h>
#include <net/mqtt.h> #include <net/mqtt.h>

View file

@ -11,7 +11,7 @@
#include <soc.h> #include <soc.h>
#include <device.h> #include <device.h>
#include <entropy.h> #include <drivers/entropy.h>
#include <drivers/clock_control.h> #include <drivers/clock_control.h>
#include <bluetooth/hci.h> #include <bluetooth/hci.h>
#include <misc/util.h> #include <misc/util.h>

View file

@ -7,7 +7,7 @@
#include <errno.h> #include <errno.h>
#include <zephyr/types.h> #include <zephyr/types.h>
#include <device.h> #include <device.h>
#include <entropy.h> #include <drivers/entropy.h>
#include <drivers/clock_control.h> #include <drivers/clock_control.h>
#include <drivers/clock_control/nrf_clock_control.h> #include <drivers/clock_control/nrf_clock_control.h>

View file

@ -10,7 +10,7 @@
#include <zephyr/types.h> #include <zephyr/types.h>
#include <device.h> #include <device.h>
#include <entropy.h> #include <drivers/entropy.h>
#include <bluetooth/hci.h> #include <bluetooth/hci.h>
#include "hal/cntr.h" #include "hal/cntr.h"

View file

@ -7,7 +7,7 @@
#include <stddef.h> #include <stddef.h>
#include <zephyr.h> #include <zephyr.h>
#include <device.h> #include <device.h>
#include <entropy.h> #include <drivers/entropy.h>
#include <bluetooth/bluetooth.h> #include <bluetooth/bluetooth.h>
#include <misc/byteorder.h> #include <misc/byteorder.h>

View file

@ -11,7 +11,7 @@
LOG_MODULE_REGISTER(net_sock_can, CONFIG_NET_SOCKETS_LOG_LEVEL); LOG_MODULE_REGISTER(net_sock_can, CONFIG_NET_SOCKETS_LOG_LEVEL);
#include <kernel.h> #include <kernel.h>
#include <entropy.h> #include <drivers/entropy.h>
#include <misc/util.h> #include <misc/util.h>
#include <net/net_context.h> #include <net/net_context.h>
#include <net/net_pkt.h> #include <net/net_pkt.h>

View file

@ -11,7 +11,7 @@
LOG_MODULE_REGISTER(net_sock_packet, CONFIG_NET_SOCKETS_LOG_LEVEL); LOG_MODULE_REGISTER(net_sock_packet, CONFIG_NET_SOCKETS_LOG_LEVEL);
#include <kernel.h> #include <kernel.h>
#include <entropy.h> #include <drivers/entropy.h>
#include <misc/util.h> #include <misc/util.h>
#include <net/net_context.h> #include <net/net_context.h>
#include <net/net_pkt.h> #include <net/net_pkt.h>

View file

@ -12,7 +12,7 @@
LOG_MODULE_REGISTER(net_sock_tls, CONFIG_NET_SOCKETS_LOG_LEVEL); LOG_MODULE_REGISTER(net_sock_tls, CONFIG_NET_SOCKETS_LOG_LEVEL);
#include <init.h> #include <init.h>
#include <entropy.h> #include <drivers/entropy.h>
#include <misc/util.h> #include <misc/util.h>
#include <net/net_context.h> #include <net/net_context.h>
#include <net/socket.h> #include <net/socket.h>

View file

@ -6,7 +6,7 @@
#include <sys/atomic.h> #include <sys/atomic.h>
#include <kernel.h> #include <kernel.h>
#include <entropy.h> #include <drivers/entropy.h>
static struct device *entropy_driver; static struct device *entropy_driver;

View file

@ -39,7 +39,7 @@
#include <init.h> #include <init.h>
#include <device.h> #include <device.h>
#include <entropy.h> #include <drivers/entropy.h>
#include <kernel.h> #include <kernel.h>
static u64_t state[2]; static u64_t state[2];

View file

@ -3,7 +3,7 @@
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
#include <entropy.h> #include <drivers/entropy.h>
#include <ztest.h> #include <ztest.h>
/* /*