mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-29 01:50:53 +00:00
This patch introduces a facility which would allow to compile in callbacks for arbitrary commands passed over various communication protocols. Typically this will be used for testing, when various test commands are multiplexed over an existing protocol. The callbacks are associated with 16 bit command codes. On input the callback receives a buffer, containing the command's argument, the size of the command argument and the maximum size of the buffer. On output the callback stores processing result in the same buffer and updates the size to the actual amount of returned data. Callback descriptors are stored in a dedicated read only section which is scanned by extension_route_command() to find a callback associated with a certain command code. A console channel is also being introduced to allow controlling console output generated by extension commands handlers. BRANCH=none BUG=chrome-os-partner:47524 TEST=none yet Change-Id: I8ae16a78ca7d72176a5e7f74dd7a232078e7c06c Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/312586 Reviewed-by: Randall Spangler <rspangler@chromium.org>
197 lines
4.3 KiB
C
197 lines
4.3 KiB
C
/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
/* Console output module for Chrome EC */
|
|
|
|
#include "console.h"
|
|
#include "uart.h"
|
|
#include "usb_console.h"
|
|
#include "util.h"
|
|
|
|
/* Default to all channels active */
|
|
#ifndef CC_DEFAULT
|
|
#define CC_DEFAULT CC_ALL
|
|
#endif
|
|
static uint32_t channel_mask = CC_DEFAULT;
|
|
static uint32_t channel_mask_saved = CC_DEFAULT;
|
|
|
|
/*
|
|
* List of channel names; must match enum console_channel.
|
|
*
|
|
* We could do something fancy and macro-y with this like ec.tasklist, so that
|
|
* the channel name list and console_channel enum come from the same header
|
|
* file. That's clever, but I'm not convinced it's more readable or
|
|
* maintainable than the two simple lists we have now.
|
|
*
|
|
* We could also try to get clever with #ifdefs or board-specific lists of
|
|
* channel names, so that for example boards without port80 support don't waste
|
|
* binary size on the channel name string for "port80". Pruning the channel
|
|
* list might also become more important if we have >32 channels - for example,
|
|
* if we decide to replace enum console_channel with enum module_id.
|
|
*/
|
|
static const char * const channel_names[] = {
|
|
"command",
|
|
"accel",
|
|
"charger",
|
|
"chipset",
|
|
"clock",
|
|
"dma",
|
|
"events",
|
|
#ifdef CONFIG_EXTENSION_COMMAND
|
|
"extension",
|
|
#endif
|
|
"gesture",
|
|
"gpio",
|
|
"hostcmd",
|
|
"i2c",
|
|
"keyboard",
|
|
"keyscan",
|
|
"lidangle",
|
|
#ifdef HAS_TASK_LIGHTBAR
|
|
"lightbar",
|
|
#endif
|
|
"lpc",
|
|
"motionlid",
|
|
"motionsense",
|
|
#ifdef HAS_TASK_PDCMD
|
|
"pdhostcmd",
|
|
#endif
|
|
"port80",
|
|
"pwm",
|
|
"spi",
|
|
#ifdef CONFIG_SPS
|
|
"sps",
|
|
#endif
|
|
"switch",
|
|
"system",
|
|
"task",
|
|
"thermal",
|
|
"tpm",
|
|
"usb",
|
|
"usbcharge",
|
|
"usbpd",
|
|
"vboot",
|
|
"hook",
|
|
};
|
|
BUILD_ASSERT(ARRAY_SIZE(channel_names) == CC_CHANNEL_COUNT);
|
|
/* ensure that we are not silently masking additional channels */
|
|
BUILD_ASSERT(CC_CHANNEL_COUNT <= 8*sizeof(uint32_t));
|
|
|
|
/*****************************************************************************/
|
|
/* Channel-based console output */
|
|
|
|
int cputs(enum console_channel channel, const char *outstr)
|
|
{
|
|
int rv1, rv2;
|
|
|
|
/* Filter out inactive channels */
|
|
if (!(CC_MASK(channel) & channel_mask))
|
|
return EC_SUCCESS;
|
|
|
|
rv1 = usb_puts(outstr);
|
|
rv2 = uart_puts(outstr);
|
|
|
|
return rv1 == EC_SUCCESS ? rv2 : rv1;
|
|
}
|
|
|
|
int cprintf(enum console_channel channel, const char *format, ...)
|
|
{
|
|
int rv1, rv2;
|
|
va_list args;
|
|
|
|
/* Filter out inactive channels */
|
|
if (!(CC_MASK(channel) & channel_mask))
|
|
return EC_SUCCESS;
|
|
|
|
usb_va_start(args, format);
|
|
rv1 = usb_vprintf(format, args);
|
|
usb_va_end(args);
|
|
|
|
va_start(args, format);
|
|
rv2 = uart_vprintf(format, args);
|
|
va_end(args);
|
|
|
|
return rv1 == EC_SUCCESS ? rv2 : rv1;
|
|
}
|
|
|
|
int cprints(enum console_channel channel, const char *format, ...)
|
|
{
|
|
int r, rv;
|
|
va_list args;
|
|
|
|
/* Filter out inactive channels */
|
|
if (!(CC_MASK(channel) & channel_mask))
|
|
return EC_SUCCESS;
|
|
|
|
rv = cprintf(channel, "[%T ");
|
|
|
|
va_start(args, format);
|
|
r = uart_vprintf(format, args);
|
|
if (r)
|
|
rv = r;
|
|
va_end(args);
|
|
|
|
usb_va_start(args, format);
|
|
r = usb_vprintf(format, args);
|
|
if (r)
|
|
rv = r;
|
|
usb_va_end(args);
|
|
|
|
r = cputs(channel, "]\n");
|
|
return r ? r : rv;
|
|
}
|
|
|
|
void cflush(void)
|
|
{
|
|
uart_flush_output();
|
|
}
|
|
|
|
/*****************************************************************************/
|
|
/* Console commands */
|
|
|
|
/* Set active channels */
|
|
static int command_ch(int argc, char **argv)
|
|
{
|
|
int i;
|
|
char *e;
|
|
|
|
/* If one arg, save / restore, or set the mask */
|
|
if (argc == 2) {
|
|
if (strcasecmp(argv[1], "save") == 0) {
|
|
channel_mask_saved = channel_mask;
|
|
return EC_SUCCESS;
|
|
} else if (strcasecmp(argv[1], "restore") == 0) {
|
|
channel_mask = channel_mask_saved;
|
|
return EC_SUCCESS;
|
|
|
|
} else {
|
|
/* Set the mask */
|
|
int m = strtoi(argv[1], &e, 0);
|
|
if (*e)
|
|
return EC_ERROR_PARAM1;
|
|
|
|
/* No disabling the command output channel */
|
|
channel_mask = m | CC_MASK(CC_COMMAND);
|
|
|
|
return EC_SUCCESS;
|
|
}
|
|
}
|
|
|
|
/* Print the list of channels */
|
|
ccputs(" # Mask E Channel\n");
|
|
for (i = 0; i < CC_CHANNEL_COUNT; i++) {
|
|
ccprintf("%2d %08x %c %s\n",
|
|
i, CC_MASK(i),
|
|
(channel_mask & CC_MASK(i)) ? '*' : ' ',
|
|
channel_names[i]);
|
|
cflush();
|
|
}
|
|
return EC_SUCCESS;
|
|
};
|
|
DECLARE_CONSOLE_COMMAND(chan, command_ch,
|
|
"[ save | restore | <mask> ]",
|
|
"Save, restore, get or set console channel mask",
|
|
NULL);
|