blob: 5376e290744eff3d6fbdbb0fc92c6a886f461fc9 [file] [log] [blame]
/*
* Copyright (c) 2012 Google Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <stdint.h>
#include <stdlib.h>
#include "base/coreboot/sysinfo.h"
#include "base/fwdb.h"
#include "base/init_funcs.h"
#include "drivers/console/cbmem.h"
#include "drivers/console/console.h"
typedef struct {
Console console;
CbmemConsoleBuffer *buf;
} CbmemConsole;
static int cbmem_console_init(CbmemConsole *console)
{
FwdbEntry default_entry = {
.size = offsetof(CbmemConsoleBuffer, body) +
CONFIG_DRIVER_CONSOLE_CBMEM_SIZE,
};
FwdbEntry entry;
if (fwdb_access("cbmem console", &entry, &default_entry))
return 1;
CbmemConsoleBuffer *buf = entry.ptr;
if (!buf->size)
buf->size = CONFIG_DRIVER_CONSOLE_CBMEM_SIZE;
console->buf = buf;
return 0;
}
static void cbmem_console_write(ConsoleOutputOps *me,
const void *buffer, size_t count)
{
CbmemConsole *cbmem = container_of(me, CbmemConsole, console.output);
if (!cbmem->buf && cbmem_console_init(cbmem))
return;
if (cbmem->buf->cursor + count >= cbmem->buf->size)
return;
memcpy(cbmem->buf->body + cbmem->buf->cursor, buffer, count);
cbmem->buf->cursor += count;
}
static int cbmem_console_setup(void)
{
static CbmemConsole console = {
.console = {
.output = {
.write = &cbmem_console_write
},
},
};
list_insert_after(&console.console.list_node, &console_list);
return 0;
}
INIT_FUNC_CONSOLE(cbmem_console_setup)