diff options
author | Anas Nashif <anas.nashif@intel.com> | 2016-12-17 17:48:47 -0500 |
---|---|---|
committer | Anas Nashif <anas.nashif@intel.com> | 2016-12-19 14:59:35 -0500 |
commit | d687a95611bbd737fa56ba0a99a3e65255715cac (patch) | |
tree | 7f472cc8d694f95b3dfdd5fcdcd03e824f5a43ef /kernel/device.c | |
parent | 9463dc0b8f0ae9916b410cb9e5f9ce8e758cc5ad (diff) |
kernel: move kernel code to kernel/ directly
Also remove mentions of unified kernel in various places in the kernel,
samples and documentation.
Change-Id: Ice43bc73badbe7e14bae40fd6f2a302f6528a77d
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Diffstat (limited to 'kernel/device.c')
-rw-r--r-- | kernel/device.c | 156 |
1 files changed, 156 insertions, 0 deletions
diff --git a/kernel/device.c b/kernel/device.c new file mode 100644 index 000000000..65d3616d0 --- /dev/null +++ b/kernel/device.c @@ -0,0 +1,156 @@ +/* + * Copyright (c) 2015-2016 Intel Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <errno.h> +#include <string.h> +#include <device.h> +#include <misc/util.h> +#include <atomic.h> + +extern struct device __device_init_start[]; +extern struct device __device_PRE_KERNEL_1_start[]; +extern struct device __device_PRE_KERNEL_2_start[]; +extern struct device __device_POST_KERNEL_start[]; +extern struct device __device_APPLICATION_start[]; + +/* Deprecated */ +extern struct device __device_PRIMARY_start[]; +extern struct device __device_SECONDARY_start[]; +extern struct device __device_NANOKERNEL_start[]; +extern struct device __device_MICROKERNEL_start[]; + +extern struct device __device_init_end[]; + +static struct device *config_levels[] = { + __device_PRE_KERNEL_1_start, + __device_PRE_KERNEL_2_start, + __device_POST_KERNEL_start, + __device_APPLICATION_start, + + /* Deprecated levels */ + __device_PRIMARY_start, + __device_SECONDARY_start, + __device_NANOKERNEL_start, + __device_MICROKERNEL_start, + + /* End marker */ + __device_init_end, +}; + +#ifdef CONFIG_DEVICE_POWER_MANAGEMENT +struct device_pm_ops device_pm_ops_nop = {device_pm_nop, device_pm_nop}; +extern uint32_t __device_busy_start[]; +extern uint32_t __device_busy_end[]; +#define DEVICE_BUSY_SIZE (__device_busy_end - __device_busy_start) +#endif + +/** + * @brief Execute all the device initialization functions at a given level + * + * @details Invokes the initialization routine for each device object + * created by the DEVICE_INIT() macro using the specified level. + * The linker script places the device objects in memory in the order + * they need to be invoked, with symbols indicating where one level leaves + * off and the next one begins. + * + * @param level init level to run. + */ +void _sys_device_do_config_level(int level) +{ + struct device *info; + + for (info = config_levels[level]; info < config_levels[level+1]; info++) { + struct device_config *device = info->config; + + device->init(info); + } +} + +struct device *device_get_binding(const char *name) +{ + struct device *info; + + for (info = __device_init_start; info != __device_init_end; info++) { + if (info->driver_api && !strcmp(name, info->config->name)) { + return info; + } + } + + return NULL; +} + +#ifdef CONFIG_DEVICE_POWER_MANAGEMENT +int device_pm_nop(struct device *unused_device, int unused_policy) +{ + return 0; +} + +int device_pm_control_nop(struct device *unused_device, + uint32_t unused_ctrl_command, void *unused_context) +{ + return 0; +} + +void device_list_get(struct device **device_list, int *device_count) +{ + + *device_list = __device_init_start; + *device_count = __device_init_end - __device_init_start; +} + + +int device_any_busy_check(void) +{ + int i = 0; + + for (i = 0; i < DEVICE_BUSY_SIZE; i++) { + if (__device_busy_start[i] != 0) { + return -EBUSY; + } + } + return 0; +} + +int device_busy_check(struct device *chk_dev) +{ + if (atomic_test_bit((const atomic_t *)__device_busy_start, + (chk_dev - __device_init_start))) { + return -EBUSY; + } + return 0; +} + +#endif + +void device_busy_set(struct device *busy_dev) +{ +#ifdef CONFIG_DEVICE_POWER_MANAGEMENT + atomic_set_bit((atomic_t *) __device_busy_start, + (busy_dev - __device_init_start)); +#else + ARG_UNUSED(busy_dev); +#endif +} + +void device_busy_clear(struct device *busy_dev) +{ +#ifdef CONFIG_DEVICE_POWER_MANAGEMENT + atomic_clear_bit((atomic_t *) __device_busy_start, + (busy_dev - __device_init_start)); +#else + ARG_UNUSED(busy_dev); +#endif +} |