blob: 166f07c68c02c895b93a8bd881516c3afcc92329 [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
Julius Werner7918cfc2017-05-02 15:16:29 -070025static ssize_t (*memconsole_read_func)(char *, loff_t, size_t);
Mike Waychisone561bc42011-04-29 17:39:25 -070026
27static ssize_t memconsole_read(struct file *filp, struct kobject *kobp,
28 struct bin_attribute *bin_attr, char *buf,
29 loff_t pos, size_t count)
30{
Julius Werner7918cfc2017-05-02 15:16:29 -070031 if (WARN_ON_ONCE(!memconsole_read_func))
32 return -EIO;
33 return memconsole_read_func(buf, pos, count);
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
Julius Werner7918cfc2017-05-02 15:16:29 -070041void memconsole_setup(ssize_t (*read_func)(char *, loff_t, size_t))
Mike Waychisone561bc42011-04-29 17:39:25 -070042{
Julius Werner7918cfc2017-05-02 15:16:29 -070043 memconsole_read_func = read_func;
Mike Waychisone561bc42011-04-29 17:39:25 -070044}
Thierry Escandeafe9dba42017-03-28 18:11:26 +020045EXPORT_SYMBOL(memconsole_setup);
Mike Waychisone561bc42011-04-29 17:39:25 -070046
Thierry Escandeafe9dba42017-03-28 18:11:26 +020047int memconsole_sysfs_init(void)
Mike Waychisone561bc42011-04-29 17:39:25 -070048{
Michel Lespinassecb887592014-01-28 05:06:22 -080049 return sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
Mike Waychisone561bc42011-04-29 17:39:25 -070050}
Thierry Escandeafe9dba42017-03-28 18:11:26 +020051EXPORT_SYMBOL(memconsole_sysfs_init);
Mike Waychisone561bc42011-04-29 17:39:25 -070052
Thierry Escandeafe9dba42017-03-28 18:11:26 +020053void memconsole_exit(void)
Mike Waychisone561bc42011-04-29 17:39:25 -070054{
55 sysfs_remove_bin_file(firmware_kobj, &memconsole_bin_attr);
56}
Thierry Escandeafe9dba42017-03-28 18:11:26 +020057EXPORT_SYMBOL(memconsole_exit);
Mike Waychisone561bc42011-04-29 17:39:25 -070058
59MODULE_AUTHOR("Google, Inc.");
60MODULE_LICENSE("GPL");