.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * memconsole-coreboot.c |
---|
3 | 4 | * |
---|
4 | 5 | * Memory based BIOS console accessed through coreboot table. |
---|
5 | 6 | * |
---|
6 | 7 | * 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. |
---|
16 | 8 | */ |
---|
17 | 9 | |
---|
18 | 10 | #include <linux/device.h> |
---|
| 11 | +#include <linux/io.h> |
---|
19 | 12 | #include <linux/kernel.h> |
---|
20 | 13 | #include <linux/module.h> |
---|
21 | 14 | |
---|
.. | .. |
---|
28 | 21 | struct cbmem_cons { |
---|
29 | 22 | u32 size_dont_access_after_boot; |
---|
30 | 23 | u32 cursor; |
---|
31 | | - u8 body[0]; |
---|
| 24 | + u8 body[]; |
---|
32 | 25 | } __packed; |
---|
33 | 26 | |
---|
34 | 27 | #define CURSOR_MASK ((1 << 28) - 1) |
---|
35 | 28 | #define OVERFLOW (1 << 31) |
---|
36 | 29 | |
---|
37 | | -static struct cbmem_cons __iomem *cbmem_console; |
---|
| 30 | +static struct cbmem_cons *cbmem_console; |
---|
38 | 31 | static u32 cbmem_console_size; |
---|
39 | 32 | |
---|
40 | 33 | /* |
---|
.. | .. |
---|
75 | 68 | |
---|
76 | 69 | static int memconsole_probe(struct coreboot_device *dev) |
---|
77 | 70 | { |
---|
78 | | - struct cbmem_cons __iomem *tmp_cbmc; |
---|
| 71 | + struct cbmem_cons *tmp_cbmc; |
---|
79 | 72 | |
---|
80 | 73 | tmp_cbmc = memremap(dev->cbmem_ref.cbmem_addr, |
---|
81 | 74 | sizeof(*tmp_cbmc), MEMREMAP_WB); |
---|
.. | .. |
---|
85 | 78 | |
---|
86 | 79 | /* Read size only once to prevent overrun attack through /dev/mem. */ |
---|
87 | 80 | cbmem_console_size = tmp_cbmc->size_dont_access_after_boot; |
---|
88 | | - cbmem_console = memremap(dev->cbmem_ref.cbmem_addr, |
---|
| 81 | + cbmem_console = devm_memremap(&dev->dev, dev->cbmem_ref.cbmem_addr, |
---|
89 | 82 | cbmem_console_size + sizeof(*cbmem_console), |
---|
90 | 83 | MEMREMAP_WB); |
---|
91 | 84 | memunmap(tmp_cbmc); |
---|
92 | 85 | |
---|
93 | | - if (!cbmem_console) |
---|
94 | | - return -ENOMEM; |
---|
| 86 | + if (IS_ERR(cbmem_console)) |
---|
| 87 | + return PTR_ERR(cbmem_console); |
---|
95 | 88 | |
---|
96 | 89 | memconsole_setup(memconsole_coreboot_read); |
---|
97 | 90 | |
---|
.. | .. |
---|
101 | 94 | static int memconsole_remove(struct coreboot_device *dev) |
---|
102 | 95 | { |
---|
103 | 96 | memconsole_exit(); |
---|
104 | | - |
---|
105 | | - if (cbmem_console) |
---|
106 | | - memunmap(cbmem_console); |
---|
107 | 97 | |
---|
108 | 98 | return 0; |
---|
109 | 99 | } |
---|
.. | .. |
---|
116 | 106 | }, |
---|
117 | 107 | .tag = CB_TAG_CBMEM_CONSOLE, |
---|
118 | 108 | }; |
---|
119 | | - |
---|
120 | | -static void coreboot_memconsole_exit(void) |
---|
121 | | -{ |
---|
122 | | - coreboot_driver_unregister(&memconsole_driver); |
---|
123 | | -} |
---|
124 | | - |
---|
125 | | -static int __init coreboot_memconsole_init(void) |
---|
126 | | -{ |
---|
127 | | - return coreboot_driver_register(&memconsole_driver); |
---|
128 | | -} |
---|
129 | | - |
---|
130 | | -module_exit(coreboot_memconsole_exit); |
---|
131 | | -module_init(coreboot_memconsole_init); |
---|
| 109 | +module_coreboot_driver(memconsole_driver); |
---|
132 | 110 | |
---|
133 | 111 | MODULE_AUTHOR("Google, Inc."); |
---|
134 | 112 | MODULE_LICENSE("GPL"); |
---|