Separate coreboot related functions to coreboot_table.c to provide common methods for other firmware drivers. BUG=chrome-os-partner:39945 TEST=`emerge-oak chromeos-kernel-3_18` Signed-off-by: Wei-Ning Huang <wnhuang@google.com> Reviewed-on: https://chromium-review.googlesource.com/285380 Reviewed-by: Daniel Kurtz <djkurtz@chromium.org> Commit-Queue: Wei-Ning Huang <wnhuang@chromium.org> Tested-by: Wei-Ning Huang <wnhuang@chromium.org> (cherry picked from commit cc27c869c48c80ec7d89629f6cf112ef89818c78) Change-Id: Ie71f246d958c77b0721918167933de026d161bcb Reviewed-on: https://chromium-review.googlesource.com/294777 Reviewed-by: Yuji Sasaki <sasakiy@google.com> Reviewed-by: Wei-Ning Huang <wnhuang@chromium.org> Commit-Queue: Yuji Sasaki <sasakiy@google.com> Tested-by: Yuji Sasaki <sasakiy@google.com>
85 lines
1.9 KiB
C
85 lines
1.9 KiB
C
/*
|
|
* memconsole.c
|
|
*
|
|
* Architecture-independent parts of the memory based BIOS console.
|
|
*
|
|
* Copyright 2014 Google Inc.
|
|
*/
|
|
|
|
#include <linux/init.h>
|
|
#include <linux/sysfs.h>
|
|
#include <linux/kobject.h>
|
|
|
|
#include "memconsole.h"
|
|
|
|
static char *memconsole_baseaddr;
|
|
static size_t memconsole_length;
|
|
|
|
static ssize_t memconsole_read(struct file *filp, struct kobject *kobp,
|
|
struct bin_attribute *bin_attr, char *buf,
|
|
loff_t pos, size_t count)
|
|
{
|
|
return memory_read_from_buffer(buf, count, &pos, memconsole_baseaddr,
|
|
memconsole_length);
|
|
}
|
|
|
|
static struct bin_attribute memconsole_bin_attr = {
|
|
.attr = {.name = "log", .mode = 0444},
|
|
.read = memconsole_read,
|
|
};
|
|
|
|
/* CBMEM firmware console log descriptor. */
|
|
struct cbmem_cons {
|
|
u32 buffer_size;
|
|
u32 buffer_cursor;
|
|
u8 buffer_body[0];
|
|
} __packed;
|
|
|
|
static struct cbmem_cons __iomem *cbmem_console;
|
|
|
|
void memconsole_setup(void *baseaddr, size_t length)
|
|
{
|
|
memconsole_baseaddr = baseaddr;
|
|
memconsole_length = length;
|
|
}
|
|
EXPORT_SYMBOL(memconsole_setup);
|
|
|
|
int memconsole_coreboot_init(phys_addr_t physaddr)
|
|
{
|
|
struct cbmem_cons __iomem *tmp_cbmc;
|
|
|
|
tmp_cbmc = ioremap_cache(physaddr, sizeof(*tmp_cbmc));
|
|
|
|
if (tmp_cbmc == NULL)
|
|
return -ENOMEM;
|
|
|
|
cbmem_console = ioremap_cache(physaddr, tmp_cbmc->buffer_size +
|
|
sizeof(*cbmem_console)); /* Don't forget counting the header. */
|
|
|
|
iounmap(tmp_cbmc);
|
|
|
|
if (cbmem_console == NULL)
|
|
return -ENOMEM;
|
|
|
|
memconsole_setup(cbmem_console->buffer_body,
|
|
min(cbmem_console->buffer_cursor, cbmem_console->buffer_size));
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL(memconsole_coreboot_init);
|
|
|
|
int memconsole_sysfs_init(void)
|
|
{
|
|
memconsole_bin_attr.size = memconsole_length;
|
|
return sysfs_create_bin_file(firmware_kobj,
|
|
&memconsole_bin_attr);
|
|
}
|
|
EXPORT_SYMBOL(memconsole_sysfs_init);
|
|
|
|
void memconsole_exit(void)
|
|
{
|
|
if (cbmem_console)
|
|
iounmap(cbmem_console);
|
|
sysfs_remove_bin_file(firmware_kobj, &memconsole_bin_attr);
|
|
}
|
|
EXPORT_SYMBOL(memconsole_exit);
|