blob: 94e200ddb4faf870d6d35f81313771ba90d5d70b [file] [log] [blame]
Mike Waychisone561bc42011-04-29 17:39:25 -07001/*
2 * memconsole.c
3 *
Thierry Escandeafe9dba42017-03-28 18:11:26 +02004 * Architecture-independent parts of the memory based BIOS console.
Mike Waychisone561bc42011-04-29 17:39:25 -07005 *
Thierry Escandeafe9dba42017-03-28 18:11:26 +02006 * Copyright 2017 Google Inc.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License v2.0 as published by
10 * the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
Mike Waychisone561bc42011-04-29 17:39:25 -070016 */
17
Mike Waychisone561bc42011-04-29 17:39:25 -070018#include <linux/init.h>
Mike Waychisone561bc42011-04-29 17:39:25 -070019#include <linux/sysfs.h>
20#include <linux/kobject.h>
21#include <linux/module.h>
Mike Waychisone561bc42011-04-29 17:39:25 -070022
Thierry Escandeafe9dba42017-03-28 18:11:26 +020023#include "memconsole.h"
Mike Waychisone561bc42011-04-29 17:39:25 -070024
Thierry Escandeafe9dba42017-03-28 18:11:26 +020025static char *memconsole_baseaddr;
Mike Waychisone561bc42011-04-29 17:39:25 -070026static size_t memconsole_length;
27
28static ssize_t memconsole_read(struct file *filp, struct kobject *kobp,
29 struct bin_attribute *bin_attr, char *buf,
30 loff_t pos, size_t count)
31{
Thierry Escandeafe9dba42017-03-28 18:11:26 +020032 return memory_read_from_buffer(buf, count, &pos, memconsole_baseaddr,
33 memconsole_length);
Mike Waychisone561bc42011-04-29 17:39:25 -070034}
35
36static struct bin_attribute memconsole_bin_attr = {
37 .attr = {.name = "log", .mode = 0444},
38 .read = memconsole_read,
39};
40
Thierry Escandeafe9dba42017-03-28 18:11:26 +020041void memconsole_setup(void *baseaddr, size_t length)
Mike Waychisone561bc42011-04-29 17:39:25 -070042{
Thierry Escandeafe9dba42017-03-28 18:11:26 +020043 memconsole_baseaddr = baseaddr;
44 memconsole_length = length;
Mike Waychisone561bc42011-04-29 17:39:25 -070045}
Thierry Escandeafe9dba42017-03-28 18:11:26 +020046EXPORT_SYMBOL(memconsole_setup);
Mike Waychisone561bc42011-04-29 17:39:25 -070047
Thierry Escandeafe9dba42017-03-28 18:11:26 +020048int memconsole_sysfs_init(void)
Mike Waychisone561bc42011-04-29 17:39:25 -070049{
Mike Waychisone561bc42011-04-29 17:39:25 -070050 memconsole_bin_attr.size = memconsole_length;
Michel Lespinassecb887592014-01-28 05:06:22 -080051 return sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
Mike Waychisone561bc42011-04-29 17:39:25 -070052}
Thierry Escandeafe9dba42017-03-28 18:11:26 +020053EXPORT_SYMBOL(memconsole_sysfs_init);
Mike Waychisone561bc42011-04-29 17:39:25 -070054
Thierry Escandeafe9dba42017-03-28 18:11:26 +020055void memconsole_exit(void)
Mike Waychisone561bc42011-04-29 17:39:25 -070056{
57 sysfs_remove_bin_file(firmware_kobj, &memconsole_bin_attr);
58}
Thierry Escandeafe9dba42017-03-28 18:11:26 +020059EXPORT_SYMBOL(memconsole_exit);
Mike Waychisone561bc42011-04-29 17:39:25 -070060
61MODULE_AUTHOR("Google, Inc.");
62MODULE_LICENSE("GPL");