Skip to content
Permalink
Browse files

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>
  • Loading branch information...
nashif committed Jun 25, 2019
1 parent 46a5d1e commit 969f8f1c68f91b43b81f4346402e7d3506079ca7
@@ -6,7 +6,7 @@

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

#include <string.h>
#include <entropy.h>
#include <drivers/entropy.h>

static inline u32_t entropy_esp32_get_u32(void)
{
@@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include <entropy.h>
#include <drivers/entropy.h>
#include <syscall_handler.h>

Z_SYSCALL_HANDLER(entropy_get_entropy, dev, buffer, len)
@@ -5,7 +5,7 @@
*/

#include <device.h>
#include <entropy.h>
#include <drivers/entropy.h>
#include <random/rand32.h>
#include <init.h>

@@ -5,7 +5,7 @@
*/

#include <device.h>
#include <entropy.h>
#include <drivers/entropy.h>
#include <random/rand32.h>
#include <init.h>

@@ -5,7 +5,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include <entropy.h>
#include <drivers/entropy.h>
#include <sys/atomic.h>
#include <soc.h>
#include "nrf_rng.h"
@@ -5,7 +5,7 @@
*/

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

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

#include "device.h"
#include "entropy.h"
#include <drivers/entropy.h>
#include "init.h"
#include "misc/util.h"
#include <stdlib.h>
@@ -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_ */
@@ -1,119 +1,15 @@
/**
* @file entropy.h
*
* @brief Public APIs for the entropy driver.
*/

/*
* Copyright (c) 2016 ARM Ltd.
* Copyright (c) 2017 Intel Corporation
* Copyright (c) 2019 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef ZEPHYR_INCLUDE_ENTROPY_H_
#define ZEPHYR_INCLUDE_ENTROPY_H_

/**
* @brief Entropy Interface
* @defgroup entropy_interface Entropy Interface
* @ingroup io_interfaces
* @{
*/

#include <zephyr/types.h>
#include <device.h>

#ifdef __cplusplus
extern "C" {
#ifndef CONFIG_COMPAT_INCLUDES
#warning "This header file has moved, include <drivers/entropy.h> instead."
#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>
#include <drivers/entropy.h>

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

#include <zephyr.h>
#include <entropy.h>
#include <drivers/entropy.h>
#include <stdio.h>

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

#include <net/tls_credentials.h>
#include <net/mqtt.h>
@@ -11,7 +11,7 @@

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

@@ -10,7 +10,7 @@

#include <zephyr/types.h>
#include <device.h>
#include <entropy.h>
#include <drivers/entropy.h>
#include <bluetooth/hci.h>

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

@@ -11,7 +11,7 @@
LOG_MODULE_REGISTER(net_sock_can, CONFIG_NET_SOCKETS_LOG_LEVEL);

#include <kernel.h>
#include <entropy.h>
#include <drivers/entropy.h>
#include <misc/util.h>
#include <net/net_context.h>
#include <net/net_pkt.h>

0 comments on commit 969f8f1

Please sign in to comment.
You can’t perform that action at this time.