Mike Waychison | e561bc4 | 2011-04-29 17:39:25 -0700 | [diff] [blame] | 1 | /* |
| 2 | * memconsole.c |
| 3 | * |
Thierry Escande | afe9dba4 | 2017-03-28 18:11:26 +0200 | [diff] [blame] | 4 | * Architecture-independent parts of the memory based BIOS console. |
Mike Waychison | e561bc4 | 2011-04-29 17:39:25 -0700 | [diff] [blame] | 5 | * |
Thierry Escande | afe9dba4 | 2017-03-28 18:11:26 +0200 | [diff] [blame] | 6 | * 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 Waychison | e561bc4 | 2011-04-29 17:39:25 -0700 | [diff] [blame] | 16 | */ |
| 17 | |
Mike Waychison | e561bc4 | 2011-04-29 17:39:25 -0700 | [diff] [blame] | 18 | #include <linux/init.h> |
Mike Waychison | e561bc4 | 2011-04-29 17:39:25 -0700 | [diff] [blame] | 19 | #include <linux/sysfs.h> |
| 20 | #include <linux/kobject.h> |
| 21 | #include <linux/module.h> |
Mike Waychison | e561bc4 | 2011-04-29 17:39:25 -0700 | [diff] [blame] | 22 | |
Thierry Escande | afe9dba4 | 2017-03-28 18:11:26 +0200 | [diff] [blame] | 23 | #include "memconsole.h" |
Mike Waychison | e561bc4 | 2011-04-29 17:39:25 -0700 | [diff] [blame] | 24 | |
Thierry Escande | afe9dba4 | 2017-03-28 18:11:26 +0200 | [diff] [blame] | 25 | static char *memconsole_baseaddr; |
Mike Waychison | e561bc4 | 2011-04-29 17:39:25 -0700 | [diff] [blame] | 26 | static size_t memconsole_length; |
| 27 | |
| 28 | static 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 Escande | afe9dba4 | 2017-03-28 18:11:26 +0200 | [diff] [blame] | 32 | return memory_read_from_buffer(buf, count, &pos, memconsole_baseaddr, |
| 33 | memconsole_length); |
Mike Waychison | e561bc4 | 2011-04-29 17:39:25 -0700 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | static struct bin_attribute memconsole_bin_attr = { |
| 37 | .attr = {.name = "log", .mode = 0444}, |
| 38 | .read = memconsole_read, |
| 39 | }; |
| 40 | |
Thierry Escande | afe9dba4 | 2017-03-28 18:11:26 +0200 | [diff] [blame] | 41 | void memconsole_setup(void *baseaddr, size_t length) |
Mike Waychison | e561bc4 | 2011-04-29 17:39:25 -0700 | [diff] [blame] | 42 | { |
Thierry Escande | afe9dba4 | 2017-03-28 18:11:26 +0200 | [diff] [blame] | 43 | memconsole_baseaddr = baseaddr; |
| 44 | memconsole_length = length; |
Mike Waychison | e561bc4 | 2011-04-29 17:39:25 -0700 | [diff] [blame] | 45 | } |
Thierry Escande | afe9dba4 | 2017-03-28 18:11:26 +0200 | [diff] [blame] | 46 | EXPORT_SYMBOL(memconsole_setup); |
Mike Waychison | e561bc4 | 2011-04-29 17:39:25 -0700 | [diff] [blame] | 47 | |
Thierry Escande | afe9dba4 | 2017-03-28 18:11:26 +0200 | [diff] [blame] | 48 | int memconsole_sysfs_init(void) |
Mike Waychison | e561bc4 | 2011-04-29 17:39:25 -0700 | [diff] [blame] | 49 | { |
Mike Waychison | e561bc4 | 2011-04-29 17:39:25 -0700 | [diff] [blame] | 50 | memconsole_bin_attr.size = memconsole_length; |
Michel Lespinasse | cb88759 | 2014-01-28 05:06:22 -0800 | [diff] [blame] | 51 | return sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr); |
Mike Waychison | e561bc4 | 2011-04-29 17:39:25 -0700 | [diff] [blame] | 52 | } |
Thierry Escande | afe9dba4 | 2017-03-28 18:11:26 +0200 | [diff] [blame] | 53 | EXPORT_SYMBOL(memconsole_sysfs_init); |
Mike Waychison | e561bc4 | 2011-04-29 17:39:25 -0700 | [diff] [blame] | 54 | |
Thierry Escande | afe9dba4 | 2017-03-28 18:11:26 +0200 | [diff] [blame] | 55 | void memconsole_exit(void) |
Mike Waychison | e561bc4 | 2011-04-29 17:39:25 -0700 | [diff] [blame] | 56 | { |
| 57 | sysfs_remove_bin_file(firmware_kobj, &memconsole_bin_attr); |
| 58 | } |
Thierry Escande | afe9dba4 | 2017-03-28 18:11:26 +0200 | [diff] [blame] | 59 | EXPORT_SYMBOL(memconsole_exit); |
Mike Waychison | e561bc4 | 2011-04-29 17:39:25 -0700 | [diff] [blame] | 60 | |
| 61 | MODULE_AUTHOR("Google, Inc."); |
| 62 | MODULE_LICENSE("GPL"); |