2015-11-13 06:00:47 +08:00
|
|
|
/* ipm_console.c - Console messages to/from another processor */
|
2015-09-11 04:26:27 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2015 Intel Corporation
|
|
|
|
*
|
2015-10-07 00:00:37 +08:00
|
|
|
* 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
|
2015-09-11 04:26:27 +08:00
|
|
|
*
|
2015-10-07 00:00:37 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2015-09-11 04:26:27 +08:00
|
|
|
*
|
2015-10-07 00:00:37 +08:00
|
|
|
* 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.
|
2015-09-11 04:26:27 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <nanokernel.h>
|
|
|
|
#include <misc/ring_buffer.h>
|
|
|
|
#include <misc/printk.h>
|
|
|
|
#include <stdio.h>
|
2015-11-13 06:00:47 +08:00
|
|
|
#include <ipm.h>
|
|
|
|
#include <console/ipm_console.h>
|
2015-09-11 04:26:27 +08:00
|
|
|
|
2015-11-13 06:00:47 +08:00
|
|
|
static void ipm_console_fiber(int arg1, int arg2)
|
2015-09-11 04:26:27 +08:00
|
|
|
{
|
|
|
|
uint8_t size32;
|
|
|
|
uint16_t type;
|
|
|
|
int ret;
|
|
|
|
struct device *d;
|
2015-11-13 06:00:47 +08:00
|
|
|
struct ipm_console_receiver_config_info *config_info;
|
|
|
|
struct ipm_console_receiver_runtime_data *driver_data;
|
2015-09-11 04:26:27 +08:00
|
|
|
int pos;
|
|
|
|
|
|
|
|
d = (struct device *)arg1;
|
|
|
|
driver_data = d->driver_data;
|
|
|
|
config_info = d->config->config_info;
|
|
|
|
ARG_UNUSED(arg2);
|
|
|
|
size32 = 0;
|
|
|
|
pos = 0;
|
|
|
|
|
|
|
|
while (1) {
|
2015-12-19 04:36:34 +08:00
|
|
|
nano_fiber_sem_take(&driver_data->sem, TICKS_UNLIMITED);
|
2015-09-22 01:30:01 +08:00
|
|
|
|
2015-09-11 04:26:27 +08:00
|
|
|
ret = sys_ring_buf_get(&driver_data->rb, &type,
|
|
|
|
(uint8_t *)&config_info->line_buf[pos],
|
|
|
|
NULL, &size32);
|
|
|
|
if (ret) {
|
|
|
|
/* Shouldn't ever happen... */
|
2015-11-13 06:00:47 +08:00
|
|
|
printk("ipm console ring buffer error: %d\n", ret);
|
2015-09-11 04:26:27 +08:00
|
|
|
size32 = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (config_info->line_buf[pos] == '\n' ||
|
2015-10-15 05:31:32 +08:00
|
|
|
pos == config_info->lb_size - 2) {
|
2015-09-11 04:26:27 +08:00
|
|
|
if (pos != config_info->lb_size - 2) {
|
|
|
|
config_info->line_buf[pos] = '\0';
|
|
|
|
} else {
|
|
|
|
config_info->line_buf[pos + 1] = '\0';
|
|
|
|
}
|
2015-11-13 06:00:47 +08:00
|
|
|
if (config_info->flags & IPM_CONSOLE_PRINTK) {
|
2016-01-07 04:21:30 +08:00
|
|
|
printk("%s: '%s'\n", d->config->name,
|
2015-09-11 04:26:27 +08:00
|
|
|
config_info->line_buf);
|
|
|
|
}
|
2015-11-13 06:00:47 +08:00
|
|
|
if (config_info->flags & IPM_CONSOLE_STDOUT) {
|
2016-01-07 04:21:30 +08:00
|
|
|
printf("%s: '%s'\n", d->config->name,
|
2015-09-11 04:26:27 +08:00
|
|
|
config_info->line_buf);
|
|
|
|
}
|
|
|
|
pos = 0;
|
|
|
|
} else {
|
|
|
|
++pos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-13 06:00:47 +08:00
|
|
|
static void ipm_console_receive_callback(void *context, uint32_t id,
|
2015-09-11 04:26:27 +08:00
|
|
|
volatile void *data)
|
|
|
|
{
|
|
|
|
struct device *d;
|
2015-11-13 06:00:47 +08:00
|
|
|
struct ipm_console_receiver_runtime_data *driver_data;
|
2015-09-11 04:26:27 +08:00
|
|
|
|
|
|
|
ARG_UNUSED(data);
|
|
|
|
d = context;
|
|
|
|
driver_data = d->driver_data;
|
2015-09-22 01:30:01 +08:00
|
|
|
if (!sys_ring_buf_put(&driver_data->rb, 0, id, NULL, 0)) {
|
|
|
|
nano_isr_sem_give(&driver_data->sem);
|
|
|
|
}
|
2015-09-11 04:26:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-11-13 06:00:47 +08:00
|
|
|
int ipm_console_receiver_init(struct device *d)
|
2015-09-11 04:26:27 +08:00
|
|
|
{
|
2015-11-13 06:00:47 +08:00
|
|
|
struct ipm_console_receiver_config_info *config_info =
|
2015-09-11 04:26:27 +08:00
|
|
|
d->config->config_info;
|
2015-11-13 06:00:47 +08:00
|
|
|
struct ipm_console_receiver_runtime_data *driver_data = d->driver_data;
|
|
|
|
struct device *ipm;
|
2015-09-11 04:26:27 +08:00
|
|
|
|
2015-11-13 06:00:47 +08:00
|
|
|
ipm = device_get_binding(config_info->bind_to);
|
2015-09-11 04:26:27 +08:00
|
|
|
|
2015-11-13 06:00:47 +08:00
|
|
|
if (!ipm) {
|
|
|
|
printk("unable to bind IPM console receiver to '%s'\n",
|
2015-09-11 04:26:27 +08:00
|
|
|
__func__, config_info->bind_to);
|
|
|
|
return DEV_INVALID_CONF;
|
|
|
|
}
|
|
|
|
|
2015-11-13 06:00:47 +08:00
|
|
|
if (ipm_max_id_val_get(ipm) < 0xFF) {
|
|
|
|
printk("IPM driver %s doesn't support 8-bit id values",
|
2015-09-11 04:26:27 +08:00
|
|
|
config_info->bind_to);
|
|
|
|
return DEV_INVALID_CONF;
|
|
|
|
}
|
|
|
|
|
|
|
|
nano_sem_init(&driver_data->sem);
|
|
|
|
sys_ring_buf_init(&driver_data->rb, config_info->rb_size32,
|
|
|
|
config_info->ring_buf_data);
|
|
|
|
|
2015-11-13 06:00:47 +08:00
|
|
|
ipm_register_callback(ipm, ipm_console_receive_callback, d);
|
2015-09-11 04:26:27 +08:00
|
|
|
|
2015-11-13 06:00:47 +08:00
|
|
|
task_fiber_start(config_info->fiber_stack, IPM_CONSOLE_STACK_SIZE,
|
|
|
|
ipm_console_fiber, (int)d, 0,
|
|
|
|
IPM_CONSOLE_PRI, 0);
|
|
|
|
ipm_set_enabled(ipm, 1);
|
2015-09-11 04:26:27 +08:00
|
|
|
|
|
|
|
return DEV_OK;
|
|
|
|
}
|
|
|
|
|