2015-06-01 20:11:39 +02:00
|
|
|
|
2015-10-06 18:00:37 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015 Intel Corporation.
|
2015-06-01 20:11:39 +02:00
|
|
|
*
|
2017-01-19 02:01:01 +01:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2015-06-01 20:11:39 +02:00
|
|
|
*/
|
|
|
|
|
2018-09-14 19:43:44 +02:00
|
|
|
#ifndef ZEPHYR_INCLUDE_DEVICE_H_
|
|
|
|
#define ZEPHYR_INCLUDE_DEVICE_H_
|
2015-06-01 20:11:39 +02:00
|
|
|
|
2017-04-04 19:16:57 +02:00
|
|
|
#include <kernel.h>
|
2016-09-12 13:35:13 +02:00
|
|
|
|
2016-02-14 17:11:04 +01:00
|
|
|
/**
|
|
|
|
* @brief Device Driver APIs
|
|
|
|
* @defgroup io_interfaces Device Driver APIs
|
|
|
|
* @{
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @brief Device Model APIs
|
|
|
|
* @defgroup device_model Device Model APIs
|
|
|
|
* @{
|
|
|
|
*/
|
2016-09-01 08:01:10 +02:00
|
|
|
|
Introduce new sized integer typedefs
This is a start to move away from the C99 {u}int{8,16,32,64}_t types to
Zephyr defined u{8,16,32,64}_t and s{8,16,32,64}_t. This allows Zephyr
to define the sized types in a consistent manor across all the
architectures we support and not conflict with what various compilers
and libc might do with regards to the C99 types.
We introduce <zephyr/types.h> as part of this and have it include
<stdint.h> for now until we transition all the code away from the C99
types.
We go with u{8,16,32,64}_t and s{8,16,32,64}_t as there are some
existing variables defined u8 & u16 as well as to be consistent with
Zephyr naming conventions.
Jira: ZEP-2051
Change-Id: I451fed0623b029d65866622e478225dfab2c0ca8
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-19 17:32:08 +02:00
|
|
|
#include <zephyr/types.h>
|
2016-09-01 08:01:10 +02:00
|
|
|
|
2016-01-22 18:38:49 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2018-11-12 19:25:12 +01:00
|
|
|
#define Z_DEVICE_MAX_NAME_LEN 48
|
2016-11-08 20:06:55 +01:00
|
|
|
|
2016-01-27 21:55:32 +01:00
|
|
|
/**
|
|
|
|
* @def DEVICE_INIT
|
|
|
|
*
|
2016-04-14 18:28:33 +02:00
|
|
|
* @brief Create device object and set it up for boot time initialization.
|
2016-01-27 21:55:32 +01:00
|
|
|
*
|
|
|
|
* @details This macro defines a device object that is automatically
|
2018-12-03 18:04:21 +01:00
|
|
|
* configured by the kernel during system initialization. Note that
|
|
|
|
* devices set up with this macro will not be accessible from user mode
|
|
|
|
* since the API is not specified; whenever possible, use DEVICE_AND_API_INIT
|
|
|
|
* instead.
|
2016-01-27 21:55:32 +01:00
|
|
|
*
|
2018-11-12 19:25:12 +01:00
|
|
|
* @param dev_name Device name. This must be less than Z_DEVICE_MAX_NAME_LEN
|
|
|
|
* characters in order to be looked up from user mode with device_get_binding().
|
2016-01-27 21:55:32 +01:00
|
|
|
*
|
|
|
|
* @param drv_name The name this instance of the driver exposes to
|
|
|
|
* the system.
|
|
|
|
*
|
|
|
|
* @param init_fn Address to the init function of the driver.
|
|
|
|
*
|
|
|
|
* @param data Pointer to the device's configuration data.
|
|
|
|
*
|
|
|
|
* @param cfg_info The address to the structure containing the
|
|
|
|
* configuration information for this instance of the driver.
|
|
|
|
*
|
|
|
|
* @param level The initialization level at which configuration occurs.
|
|
|
|
* Must be one of the following symbols, which are listed in the order
|
|
|
|
* they are performed by the kernel:
|
2016-04-14 18:28:33 +02:00
|
|
|
* \n
|
2016-11-08 20:06:55 +01:00
|
|
|
* \li PRE_KERNEL_1: Used for devices that have no dependencies, such as those
|
2016-01-27 21:55:32 +01:00
|
|
|
* that rely solely on hardware present in the processor/SOC. These devices
|
|
|
|
* cannot use any kernel services during configuration, since they are not
|
|
|
|
* yet available.
|
2016-04-14 18:28:33 +02:00
|
|
|
* \n
|
2016-11-08 20:06:55 +01:00
|
|
|
* \li PRE_KERNEL_2: Used for devices that rely on the initialization of devices
|
2018-12-03 18:02:32 +01:00
|
|
|
* initialized as part of the PRE_KERNEL_1 level. These devices cannot use any
|
2016-01-27 21:55:32 +01:00
|
|
|
* kernel services during configuration, since they are not yet available.
|
2016-04-14 18:28:33 +02:00
|
|
|
* \n
|
2016-11-08 20:06:55 +01:00
|
|
|
* \li POST_KERNEL: Used for devices that require kernel services during
|
2016-01-27 21:55:32 +01:00
|
|
|
* configuration.
|
2016-04-14 18:28:33 +02:00
|
|
|
* \n
|
|
|
|
* \li APPLICATION: Used for application components (i.e. non-kernel components)
|
2016-01-27 21:55:32 +01:00
|
|
|
* that need automatic configuration. These devices can use all services
|
|
|
|
* provided by the kernel during configuration.
|
|
|
|
*
|
|
|
|
* @param prio The initialization priority of the device, relative to
|
|
|
|
* other devices of the same initialization level. Specified as an integer
|
|
|
|
* value in the range 0 to 99; lower values indicate earlier initialization.
|
|
|
|
* Must be a decimal integer literal without leading zeroes or sign (e.g. 32),
|
2016-02-11 17:58:59 +01:00
|
|
|
* or an equivalent symbolic name (e.g. \#define MY_INIT_PRIO 32); symbolic
|
2016-01-27 21:55:32 +01:00
|
|
|
* expressions are *not* permitted
|
|
|
|
* (e.g. CONFIG_KERNEL_INIT_PRIORITY_DEFAULT + 5).
|
|
|
|
*/
|
2018-03-26 15:31:51 +02:00
|
|
|
#define DEVICE_INIT(dev_name, drv_name, init_fn, data, cfg_info, level, prio) \
|
2018-12-09 18:47:34 +01:00
|
|
|
DEVICE_AND_API_INIT(dev_name, drv_name, init_fn,\
|
|
|
|
data, cfg_info, level, prio, NULL)
|
2018-03-26 15:31:51 +02:00
|
|
|
|
2016-01-27 21:55:32 +01:00
|
|
|
|
2016-04-14 18:28:33 +02:00
|
|
|
/**
|
|
|
|
* @def DEVICE_AND_API_INIT
|
|
|
|
*
|
|
|
|
* @brief Create device object and set it up for boot time initialization,
|
|
|
|
* with the option to set driver_api.
|
|
|
|
*
|
2016-06-17 04:42:04 +02:00
|
|
|
* @copydetails DEVICE_INIT
|
2016-04-14 18:28:33 +02:00
|
|
|
* @param api Provides an initial pointer to the API function struct
|
|
|
|
* used by the driver. Can be NULL.
|
2016-06-17 04:42:04 +02:00
|
|
|
* @details The driver api is also set here, eliminating the need to do that
|
|
|
|
* during initialization.
|
2016-04-14 18:28:33 +02:00
|
|
|
*/
|
2016-03-24 07:23:10 +01:00
|
|
|
#ifndef CONFIG_DEVICE_POWER_MANAGEMENT
|
2018-02-07 05:31:50 +01:00
|
|
|
#define DEVICE_AND_API_INIT(dev_name, drv_name, init_fn, data, cfg_info, \
|
|
|
|
level, prio, api) \
|
|
|
|
static struct device_config _CONCAT(__config_, dev_name) __used \
|
|
|
|
__attribute__((__section__(".devconfig.init"))) = { \
|
|
|
|
.name = drv_name, .init = (init_fn), \
|
|
|
|
.config_info = (cfg_info) \
|
|
|
|
}; \
|
|
|
|
static struct device _CONCAT(__device_, dev_name) __used \
|
2016-01-27 21:55:32 +01:00
|
|
|
__attribute__((__section__(".init_" #level STRINGIFY(prio)))) = { \
|
2018-02-07 05:31:50 +01:00
|
|
|
.config = &_CONCAT(__config_, dev_name), \
|
|
|
|
.driver_api = api, \
|
|
|
|
.driver_data = data \
|
2016-01-27 21:55:32 +01:00
|
|
|
}
|
2016-03-24 07:23:10 +01:00
|
|
|
#else
|
2018-03-26 15:31:51 +02:00
|
|
|
/*
|
|
|
|
* Use the default device_pm_control for devices that do not call the
|
|
|
|
* DEVICE_DEFINE macro so that caller of hook functions
|
|
|
|
* need not check device_pm_control != NULL.
|
|
|
|
*/
|
|
|
|
#define DEVICE_AND_API_INIT(dev_name, drv_name, init_fn, data, cfg_info, \
|
|
|
|
level, prio, api) \
|
|
|
|
DEVICE_DEFINE(dev_name, drv_name, init_fn, \
|
|
|
|
device_pm_control_nop, data, cfg_info, level, \
|
|
|
|
prio, api)
|
|
|
|
#endif
|
2016-07-01 03:46:24 +02:00
|
|
|
|
2016-03-24 07:23:10 +01:00
|
|
|
/**
|
2017-03-22 13:49:34 +01:00
|
|
|
* @def DEVICE_DEFINE
|
2016-09-12 13:35:13 +02:00
|
|
|
*
|
2016-04-14 18:28:33 +02:00
|
|
|
* @brief Create device object and set it up for boot time initialization,
|
2017-03-22 13:49:34 +01:00
|
|
|
* with the option to device_pm_control.
|
2016-03-24 07:23:10 +01:00
|
|
|
*
|
2017-03-22 13:49:34 +01:00
|
|
|
* @copydetails DEVICE_AND_API_INIT
|
|
|
|
* @param pm_control_fn Pointer to device_pm_control function.
|
|
|
|
* Can be empty function (device_pm_control_nop) if not implemented.
|
2016-03-24 07:23:10 +01:00
|
|
|
*/
|
2018-03-26 15:31:51 +02:00
|
|
|
#ifndef CONFIG_DEVICE_POWER_MANAGEMENT
|
|
|
|
#define DEVICE_DEFINE(dev_name, drv_name, init_fn, pm_control_fn, \
|
|
|
|
data, cfg_info, level, prio, api) \
|
|
|
|
DEVICE_AND_API_INIT(dev_name, drv_name, init_fn, data, cfg_info, \
|
|
|
|
level, prio, api)
|
|
|
|
#else
|
2018-02-07 05:31:50 +01:00
|
|
|
#define DEVICE_DEFINE(dev_name, drv_name, init_fn, pm_control_fn, \
|
|
|
|
data, cfg_info, level, prio, api) \
|
|
|
|
static struct device_config _CONCAT(__config_, dev_name) __used \
|
|
|
|
__attribute__((__section__(".devconfig.init"))) = { \
|
|
|
|
.name = drv_name, .init = (init_fn), \
|
|
|
|
.device_pm_control = (pm_control_fn), \
|
|
|
|
.config_info = (cfg_info) \
|
|
|
|
}; \
|
|
|
|
static struct device _CONCAT(__device_, dev_name) __used \
|
2016-09-01 08:01:10 +02:00
|
|
|
__attribute__((__section__(".init_" #level STRINGIFY(prio)))) = { \
|
2018-02-07 05:31:50 +01:00
|
|
|
.config = &_CONCAT(__config_, dev_name), \
|
|
|
|
.driver_api = api, \
|
|
|
|
.driver_data = data \
|
2016-09-01 08:01:10 +02:00
|
|
|
}
|
2016-07-01 03:46:24 +02:00
|
|
|
#endif
|
|
|
|
|
2016-01-27 20:40:06 +01:00
|
|
|
/**
|
|
|
|
* @def DEVICE_NAME_GET
|
|
|
|
*
|
|
|
|
* @brief Expands to the full name of a global device object
|
|
|
|
*
|
|
|
|
* @details Return the full name of a device object symbol created by
|
2016-02-11 17:58:59 +01:00
|
|
|
* DEVICE_INIT(), using the dev_name provided to DEVICE_INIT().
|
2016-01-27 20:40:06 +01:00
|
|
|
*
|
|
|
|
* It is meant to be used for declaring extern symbols pointing on device
|
|
|
|
* objects before using the DEVICE_GET macro to get the device object.
|
|
|
|
*
|
2016-01-28 20:53:28 +01:00
|
|
|
* @param name The same as dev_name provided to DEVICE_INIT()
|
2016-01-27 20:40:06 +01:00
|
|
|
*
|
2017-04-19 00:56:26 +02:00
|
|
|
* @return The expanded name of the device object created by DEVICE_INIT()
|
2016-01-27 20:40:06 +01:00
|
|
|
*/
|
2016-01-28 20:55:27 +01:00
|
|
|
#define DEVICE_NAME_GET(name) (_CONCAT(__device_, name))
|
2016-01-27 20:40:06 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @def DEVICE_GET
|
|
|
|
*
|
|
|
|
* @brief Obtain a pointer to a device object by name
|
|
|
|
*
|
|
|
|
* @details Return the address of a device object created by
|
2016-02-11 17:58:59 +01:00
|
|
|
* DEVICE_INIT(), using the dev_name provided to DEVICE_INIT().
|
2016-01-27 20:40:06 +01:00
|
|
|
*
|
2016-01-28 20:53:28 +01:00
|
|
|
* @param name The same as dev_name provided to DEVICE_INIT()
|
2016-01-27 20:40:06 +01:00
|
|
|
*
|
2016-01-28 20:53:28 +01:00
|
|
|
* @return A pointer to the device object created by DEVICE_INIT()
|
2016-01-27 20:40:06 +01:00
|
|
|
*/
|
|
|
|
#define DEVICE_GET(name) (&DEVICE_NAME_GET(name))
|
|
|
|
|
2018-02-07 05:31:50 +01:00
|
|
|
/** @def DEVICE_DECLARE
|
|
|
|
*
|
|
|
|
* @brief Declare a static device object
|
|
|
|
*
|
|
|
|
* This macro can be used at the top-level to declare a device, such
|
|
|
|
* that DEVICE_GET() may be used before the full declaration in
|
|
|
|
* DEVICE_INIT().
|
|
|
|
*
|
|
|
|
* This is often useful when configuring interrupts statically in a
|
|
|
|
* device's init or per-instance config function, as the init function
|
|
|
|
* itself is required by DEVICE_INIT() and use of DEVICE_GET()
|
|
|
|
* inside it creates a circular dependency.
|
|
|
|
*
|
|
|
|
* @param name Device name
|
|
|
|
*/
|
2017-03-14 21:39:04 +01:00
|
|
|
#define DEVICE_DECLARE(name) static struct device DEVICE_NAME_GET(name)
|
2016-01-26 01:23:42 +01:00
|
|
|
|
2015-06-01 20:11:39 +02:00
|
|
|
struct device;
|
|
|
|
|
2016-03-24 07:23:10 +01:00
|
|
|
|
2015-07-10 20:52:53 +02:00
|
|
|
/**
|
|
|
|
* @brief Static device information (In ROM) Per driver instance
|
2016-09-12 13:35:13 +02:00
|
|
|
*
|
2015-07-10 20:52:53 +02:00
|
|
|
* @param name name of the device
|
|
|
|
* @param init init function for the driver
|
|
|
|
* @param config_info address of driver instance config information
|
|
|
|
*/
|
2015-06-01 20:11:39 +02:00
|
|
|
struct device_config {
|
2018-03-17 12:44:40 +01:00
|
|
|
const char *name;
|
2015-06-01 20:11:39 +02:00
|
|
|
int (*init)(struct device *device);
|
2016-03-24 07:23:10 +01:00
|
|
|
#ifdef CONFIG_DEVICE_POWER_MANAGEMENT
|
2017-04-21 17:55:34 +02:00
|
|
|
int (*device_pm_control)(struct device *device, u32_t command,
|
2018-02-07 05:31:50 +01:00
|
|
|
void *context);
|
2016-03-24 07:23:10 +01:00
|
|
|
#endif
|
2016-10-08 22:48:10 +02:00
|
|
|
const void *config_info;
|
2015-06-01 20:11:39 +02:00
|
|
|
};
|
|
|
|
|
2015-07-10 20:52:53 +02:00
|
|
|
/**
|
|
|
|
* @brief Runtime device structure (In memory) Per driver instance
|
|
|
|
* @param device_config Build time config information
|
2015-08-29 17:41:58 +02:00
|
|
|
* @param driver_api pointer to structure containing the API functions for
|
2015-07-10 20:52:53 +02:00
|
|
|
* the device type. This pointer is filled in by the driver at init time.
|
2016-06-09 09:46:13 +02:00
|
|
|
* @param driver_data driver instance data. For driver use only
|
2015-07-10 20:52:53 +02:00
|
|
|
*/
|
2015-06-01 20:11:39 +02:00
|
|
|
struct device {
|
|
|
|
struct device_config *config;
|
2016-10-22 11:04:24 +02:00
|
|
|
const void *driver_api;
|
2015-06-01 20:11:39 +02:00
|
|
|
void *driver_data;
|
arch/x86_64: New architecture added
This patch adds a x86_64 architecture and qemu_x86_64 board to Zephyr.
Only the basic architecture support needed to run 64 bit code is
added; no drivers are added, though a low-level console exists and is
wired to printk().
The support is built on top of a "X86 underkernel" layer, which can be
built in isolation as a unit test on a Linux host.
Limitations:
+ Right now the SDK lacks an x86_64 toolchain. The build will fall
back to a host toolchain if it finds no cross compiler defined,
which is tested to work on gcc 8.2.1 right now.
+ No x87/SSE/AVX usage is allowed. This is a stronger limitation than
other architectures where the instructions work from one thread even
if the context switch code doesn't support it. We are passing
-no-sse to prevent gcc from automatically generating SSE
instructions for non-floating-point purposes, which has the side
effect of changing the ABI. Future work to handle the FPU registers
will need to be combined with an "application" ABI distinct from the
kernel one (or just to require USERSPACE).
+ Paging is enabled (it has to be in long mode), but is a 1:1 mapping
of all memory. No MMU/USERSPACE support yet.
+ We are building with -mno-red-zone for stack size reasons, but this
is a valuable optimization. Enabling it requires automatic stack
switching, which requires a TSS, which means it has to happen after
MMU support.
+ The OS runs in 64 bit mode, but for compatibility reasons is
compiled to the 32 bit "X32" ABI. So while the full 64 bit
registers and instruction set are available, C pointers are 32 bits
long and Zephyr is constrained to run in the bottom 4G of memory.
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-08-19 21:24:48 +02:00
|
|
|
#if defined(__x86_64) && __SIZEOF_POINTER__ == 4
|
|
|
|
/* The x32 ABI hits an edge case. This is a 12 byte struct,
|
|
|
|
* but the x86_64 linker will pack them only in units of 8
|
|
|
|
* bytes, leading to alignment problems when iterating over
|
|
|
|
* the link-time array.
|
|
|
|
*/
|
|
|
|
void *padding;
|
|
|
|
#endif
|
2015-06-01 20:11:39 +02:00
|
|
|
};
|
|
|
|
|
2018-10-25 08:34:25 +02:00
|
|
|
void _sys_device_do_config_level(s32_t level);
|
2016-05-08 05:47:44 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Retrieve the device structure for a driver by name
|
|
|
|
*
|
|
|
|
* @details Device objects are created via the DEVICE_INIT() macro and
|
|
|
|
* placed in memory by the linker. If a driver needs to bind to another driver
|
|
|
|
* it can use this function to retrieve the device structure of the lower level
|
|
|
|
* driver by the name the driver exposes to the system.
|
|
|
|
*
|
|
|
|
* @param name device name to search for.
|
|
|
|
*
|
|
|
|
* @return pointer to device structure; NULL if not found or cannot be used.
|
|
|
|
*/
|
2018-11-12 19:25:12 +01:00
|
|
|
__syscall struct device *device_get_binding(const char *name);
|
2015-06-01 20:11:39 +02:00
|
|
|
|
2018-12-08 19:22:15 +01:00
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
2016-04-21 21:18:12 +02:00
|
|
|
/**
|
|
|
|
* @brief Device Power Management APIs
|
|
|
|
* @defgroup device_power_management_api Device Power Management APIs
|
|
|
|
* @ingroup power_management_api
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2018-02-07 05:24:47 +01:00
|
|
|
#ifdef CONFIG_DEVICE_POWER_MANAGEMENT
|
|
|
|
|
|
|
|
/** @def DEVICE_PM_ACTIVE_STATE
|
|
|
|
*
|
|
|
|
* @brief device is in ACTIVE power state
|
|
|
|
*
|
|
|
|
* @details Normal operation of the device. All device context is retained.
|
|
|
|
*/
|
2018-02-07 05:31:50 +01:00
|
|
|
#define DEVICE_PM_ACTIVE_STATE 1
|
2018-02-07 05:24:47 +01:00
|
|
|
|
|
|
|
/** @def DEVICE_PM_LOW_POWER_STATE
|
|
|
|
*
|
|
|
|
* @brief device is in LOW power state
|
|
|
|
*
|
|
|
|
* @details Device context is preserved by the HW and need not be
|
|
|
|
* restored by the driver.
|
|
|
|
*/
|
2018-02-07 05:31:50 +01:00
|
|
|
#define DEVICE_PM_LOW_POWER_STATE 2
|
2018-02-07 05:24:47 +01:00
|
|
|
|
|
|
|
/** @def DEVICE_PM_SUSPEND_STATE
|
|
|
|
*
|
|
|
|
* @brief device is in SUSPEND power state
|
|
|
|
*
|
|
|
|
* @details Most device context is lost by the hardware.
|
|
|
|
* Device drivers must save and restore or reinitialize any context
|
|
|
|
* lost by the hardware
|
|
|
|
*/
|
2018-02-07 05:31:50 +01:00
|
|
|
#define DEVICE_PM_SUSPEND_STATE 3
|
2018-02-07 05:24:47 +01:00
|
|
|
|
2018-10-09 07:36:02 +02:00
|
|
|
/** @def DEVICE_PM_FORCE_SUSPEND_STATE
|
|
|
|
*
|
|
|
|
* @brief device is in force SUSPEND power state
|
|
|
|
*
|
|
|
|
* @details Driver puts the device in suspended state after
|
|
|
|
* completing the ongoing transactions and will not process any
|
|
|
|
* queued work or will not take any new requests for processing.
|
|
|
|
* Most device context is lost by the hardware. Device drivers must
|
|
|
|
* save and restore or reinitialize any context lost by the hardware.
|
|
|
|
*/
|
|
|
|
#define DEVICE_PM_FORCE_SUSPEND_STATE 4
|
|
|
|
|
2018-02-07 05:24:47 +01:00
|
|
|
/** @def DEVICE_PM_OFF_STATE
|
|
|
|
*
|
|
|
|
* @brief device is in OFF power state
|
|
|
|
*
|
|
|
|
* @details - Power has been fully removed from the device.
|
|
|
|
* The device context is lost when this state is entered, so the OS
|
|
|
|
* software will reinitialize the device when powering it back on
|
|
|
|
*/
|
2018-10-09 07:36:02 +02:00
|
|
|
#define DEVICE_PM_OFF_STATE 5
|
2018-02-07 05:24:47 +01:00
|
|
|
|
|
|
|
/* Constants defining support device power commands */
|
2018-02-07 05:31:50 +01:00
|
|
|
#define DEVICE_PM_SET_POWER_STATE 1
|
|
|
|
#define DEVICE_PM_GET_POWER_STATE 2
|
2018-02-07 05:24:47 +01:00
|
|
|
|
|
|
|
#endif /* CONFIG_DEVICE_POWER_MANAGEMENT */
|
|
|
|
|
2016-04-08 21:38:57 +02:00
|
|
|
/**
|
|
|
|
* @brief Indicate that the device is in the middle of a transaction
|
|
|
|
*
|
|
|
|
* Called by a device driver to indicate that it is in the middle of a
|
|
|
|
* transaction.
|
|
|
|
*
|
|
|
|
* @param busy_dev Pointer to device structure of the driver instance.
|
|
|
|
*/
|
|
|
|
void device_busy_set(struct device *busy_dev);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Indicate that the device has completed its transaction
|
|
|
|
*
|
|
|
|
* Called by a device driver to indicate the end of a transaction.
|
|
|
|
*
|
|
|
|
* @param busy_dev Pointer to device structure of the driver instance.
|
|
|
|
*/
|
|
|
|
void device_busy_clear(struct device *busy_dev);
|
|
|
|
|
2016-03-24 07:23:10 +01:00
|
|
|
#ifdef CONFIG_DEVICE_POWER_MANAGEMENT
|
2016-04-21 21:18:12 +02:00
|
|
|
/*
|
2016-03-24 07:23:10 +01:00
|
|
|
* Device PM functions
|
|
|
|
*/
|
|
|
|
|
2016-09-01 08:01:10 +02:00
|
|
|
/**
|
|
|
|
* @brief No-op function to initialize unimplemented hook
|
|
|
|
*
|
|
|
|
* This function should be used to initialize device hook
|
2016-10-08 02:07:04 +02:00
|
|
|
* for which a device has no PM operations.
|
2016-09-01 08:01:10 +02:00
|
|
|
*
|
|
|
|
* @param unused_device Unused
|
|
|
|
* @param unused_ctrl_command Unused
|
|
|
|
* @param unused_context Unused
|
|
|
|
*
|
|
|
|
* @retval 0 Always returns 0
|
|
|
|
*/
|
2016-10-08 02:07:04 +02:00
|
|
|
int device_pm_control_nop(struct device *unused_device,
|
2018-02-07 05:31:50 +01:00
|
|
|
u32_t unused_ctrl_command, void *unused_context);
|
2016-09-01 08:01:10 +02:00
|
|
|
/**
|
|
|
|
* @brief Call the set power state function of a device
|
|
|
|
*
|
|
|
|
* Called by the application or power management service to let the device do
|
|
|
|
* required operations when moving to the required power state
|
|
|
|
* Note that devices may support just some of the device power states
|
|
|
|
* @param device Pointer to device structure of the driver instance.
|
|
|
|
* @param device_power_state Device power state to be set
|
|
|
|
*
|
|
|
|
* @retval 0 If successful.
|
|
|
|
* @retval Errno Negative errno code if failure.
|
|
|
|
*/
|
|
|
|
static inline int device_set_power_state(struct device *device,
|
2017-04-21 17:55:34 +02:00
|
|
|
u32_t device_power_state)
|
2016-09-01 08:01:10 +02:00
|
|
|
{
|
2016-10-08 02:07:04 +02:00
|
|
|
return device->config->device_pm_control(device,
|
2018-02-07 05:31:50 +01:00
|
|
|
DEVICE_PM_SET_POWER_STATE,
|
|
|
|
&device_power_state);
|
2016-09-01 08:01:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Call the get power state function of a device
|
|
|
|
*
|
|
|
|
* This function lets the caller know the current device
|
|
|
|
* power state at any time. This state will be one of the defined
|
|
|
|
* power states allowed for the devices in that system
|
|
|
|
*
|
|
|
|
* @param device pointer to device structure of the driver instance.
|
|
|
|
* @param device_power_state Device power state to be filled by the device
|
|
|
|
*
|
|
|
|
* @retval 0 If successful.
|
|
|
|
* @retval Errno Negative errno code if failure.
|
|
|
|
*/
|
|
|
|
static inline int device_get_power_state(struct device *device,
|
2017-04-21 17:55:34 +02:00
|
|
|
u32_t *device_power_state)
|
2016-09-01 08:01:10 +02:00
|
|
|
{
|
2016-10-08 02:07:04 +02:00
|
|
|
return device->config->device_pm_control(device,
|
2018-02-07 05:31:50 +01:00
|
|
|
DEVICE_PM_GET_POWER_STATE,
|
|
|
|
device_power_state);
|
2016-09-01 08:01:10 +02:00
|
|
|
}
|
|
|
|
|
2016-03-24 07:23:10 +01:00
|
|
|
/**
|
|
|
|
* @brief Gets the device structure list array and device count
|
|
|
|
*
|
|
|
|
* Called by the Power Manager application to get the list of
|
|
|
|
* device structures associated with the devices in the system.
|
|
|
|
* The PM app would use this list to create its own sorted list
|
|
|
|
* based on the order it wishes to suspend or resume the devices.
|
|
|
|
*
|
|
|
|
* @param device_list Pointer to receive the device list array
|
|
|
|
* @param device_count Pointer to receive the device count
|
|
|
|
*/
|
|
|
|
void device_list_get(struct device **device_list, int *device_count);
|
|
|
|
|
2016-04-08 21:38:57 +02:00
|
|
|
/**
|
|
|
|
* @brief Check if any device is in the middle of a transaction
|
|
|
|
*
|
|
|
|
* Called by an application to see if any device is in the middle
|
|
|
|
* of a critical transaction that cannot be interrupted.
|
|
|
|
*
|
|
|
|
* @retval 0 if no device is busy
|
|
|
|
* @retval -EBUSY if any device is busy
|
|
|
|
*/
|
|
|
|
int device_any_busy_check(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Check if a specific device is in the middle of a transaction
|
|
|
|
*
|
|
|
|
* Called by an application to see if a particular device is in the
|
|
|
|
* middle of a critical transaction that cannot be interrupted.
|
|
|
|
*
|
|
|
|
* @param chk_dev Pointer to device structure of the specific device driver
|
|
|
|
* the caller is interested in.
|
|
|
|
* @retval 0 if the device is not busy
|
|
|
|
* @retval -EBUSY if the device is busy
|
|
|
|
*/
|
|
|
|
int device_busy_check(struct device *chk_dev);
|
|
|
|
|
2016-03-24 07:23:10 +01:00
|
|
|
#endif
|
|
|
|
|
2016-04-21 21:18:12 +02:00
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
2018-11-12 19:25:12 +01:00
|
|
|
#include <syscalls/device.h>
|
|
|
|
|
2016-01-22 18:38:49 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
2018-09-14 19:43:44 +02:00
|
|
|
#endif /* ZEPHYR_INCLUDE_DEVICE_H_ */
|