arm-trusted-firmware/drivers/console/multi_console.c
Antonio Nino Diaz 09d40e0e08 Sanitise includes across codebase
Enforce full include path for includes. Deprecate old paths.

The following folders inside include/lib have been left unchanged:

- include/lib/cpus/${ARCH}
- include/lib/el3_runtime/${ARCH}

The reason for this change is that having a global namespace for
includes isn't a good idea. It defeats one of the advantages of having
folders and it introduces problems that are sometimes subtle (because
you may not know the header you are actually including if there are two
of them).

For example, this patch had to be created because two headers were
called the same way: e0ea0928d5 ("Fix gpio includes of mt8173 platform
to avoid collision."). More recently, this patch has had similar
problems: 46f9b2c3a2 ("drivers: add tzc380 support").

This problem was introduced in commit 4ecca33988 ("Move include and
source files to logical locations"). At that time, there weren't too
many headers so it wasn't a real issue. However, time has shown that
this creates problems.

Platforms that want to preserve the way they include headers may add the
removed paths to PLAT_INCLUDES, but this is discouraged.

Change-Id: I39dc53ed98f9e297a5966e723d1936d6ccf2fc8f
Signed-off-by: Antonio Nino Diaz <antonio.ninodiaz@arm.com>
2019-01-04 10:43:17 +00:00

123 lines
2.6 KiB
C

/*
* Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#if MULTI_CONSOLE_API
#include <assert.h>
#include <drivers/console.h>
console_t *console_list;
uint8_t console_state = CONSOLE_FLAG_BOOT;
int console_register(console_t *console)
{
IMPORT_SYM(console_t *, __STACKS_START__, stacks_start)
IMPORT_SYM(console_t *, __STACKS_END__, stacks_end)
/* Assert that the struct is not on the stack (common mistake). */
assert((console < stacks_start) || (console >= stacks_end));
/* Assert that we won't make a circle in the list. */
assert(!console_is_registered(console));
console->next = console_list;
console_list = console;
/* Return 1 for convenient tail-calling from console_xxx_register(). */
return 1;
}
console_t *console_unregister(console_t *to_be_deleted)
{
console_t **ptr;
assert(to_be_deleted != NULL);
for (ptr = &console_list; *ptr != NULL; ptr = &(*ptr)->next)
if (*ptr == to_be_deleted) {
*ptr = (*ptr)->next;
return to_be_deleted;
}
return NULL;
}
int console_is_registered(console_t *to_find)
{
console_t *console;
assert(to_find != NULL);
for (console = console_list; console != NULL; console = console->next)
if (console == to_find)
return 1;
return 0;
}
void console_switch_state(unsigned int new_state)
{
console_state = new_state;
}
void console_set_scope(console_t *console, unsigned int scope)
{
assert(console != NULL);
console->flags = (console->flags & ~CONSOLE_FLAG_SCOPE_MASK) | scope;
}
int console_putc(int c)
{
int err = ERROR_NO_VALID_CONSOLE;
console_t *console;
for (console = console_list; console != NULL; console = console->next)
if (console->flags & console_state) {
int ret = console->putc(c, console);
if ((err == ERROR_NO_VALID_CONSOLE) || (ret < err))
err = ret;
}
return err;
}
int console_getc(void)
{
int err = ERROR_NO_VALID_CONSOLE;
console_t *console;
do { /* Keep polling while at least one console works correctly. */
for (console = console_list; console != NULL;
console = console->next)
if (console->flags & console_state) {
int ret = console->getc(console);
if (ret >= 0)
return ret;
if (err != ERROR_NO_PENDING_CHAR)
err = ret;
}
} while (err == ERROR_NO_PENDING_CHAR);
return err;
}
int console_flush(void)
{
int err = ERROR_NO_VALID_CONSOLE;
console_t *console;
for (console = console_list; console != NULL; console = console->next)
if (console->flags & console_state) {
int ret = console->flush(console);
if ((err == ERROR_NO_VALID_CONSOLE) || (ret < err))
err = ret;
}
return err;
}
#endif /* MULTI_CONSOLE_API */