| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * apple-properties.c - EFI device properties on Macs |
|---|
| 3 | 4 | * Copyright (C) 2016 Lukas Wunner <lukas@wunner.de> |
|---|
| 4 | 5 | * |
|---|
| 5 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 6 | | - * it under the terms of the GNU General Public License (version 2) as |
|---|
| 7 | | - * published by the Free Software Foundation. |
|---|
| 8 | | - * |
|---|
| 9 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 10 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 11 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 12 | | - * GNU General Public License for more details. |
|---|
| 13 | | - * |
|---|
| 14 | | - * You should have received a copy of the GNU General Public License |
|---|
| 15 | | - * along with this program; if not, see <http://www.gnu.org/licenses/>. |
|---|
| 16 | | - * |
|---|
| 17 | | - * Note, all properties are considered as u8 arrays. |
|---|
| 18 | | - * To get a value of any of them the caller must use device_property_read_u8_array(). |
|---|
| 6 | + * Properties are stored either as: |
|---|
| 7 | + * u8 arrays which can be retrieved with device_property_read_u8_array() or |
|---|
| 8 | + * booleans which can be queried with device_property_present(). |
|---|
| 19 | 9 | */ |
|---|
| 20 | 10 | |
|---|
| 21 | 11 | #define pr_fmt(fmt) "apple-properties: " fmt |
|---|
| 22 | 12 | |
|---|
| 23 | | -#include <linux/bootmem.h> |
|---|
| 13 | +#include <linux/memblock.h> |
|---|
| 24 | 14 | #include <linux/efi.h> |
|---|
| 25 | 15 | #include <linux/io.h> |
|---|
| 26 | 16 | #include <linux/platform_data/x86/apple.h> |
|---|
| .. | .. |
|---|
| 34 | 24 | static int __init dump_properties_enable(char *arg) |
|---|
| 35 | 25 | { |
|---|
| 36 | 26 | dump_properties = true; |
|---|
| 37 | | - return 0; |
|---|
| 27 | + return 1; |
|---|
| 38 | 28 | } |
|---|
| 39 | 29 | |
|---|
| 40 | 30 | __setup("dump_apple_properties", dump_properties_enable); |
|---|
| .. | .. |
|---|
| 42 | 32 | struct dev_header { |
|---|
| 43 | 33 | u32 len; |
|---|
| 44 | 34 | u32 prop_count; |
|---|
| 45 | | - struct efi_dev_path path[0]; |
|---|
| 35 | + struct efi_dev_path path[]; |
|---|
| 46 | 36 | /* |
|---|
| 47 | 37 | * followed by key/value pairs, each key and value preceded by u32 len, |
|---|
| 48 | 38 | * len includes itself, value may be empty (in which case its len is 4) |
|---|
| .. | .. |
|---|
| 53 | 43 | u32 len; |
|---|
| 54 | 44 | u32 version; |
|---|
| 55 | 45 | u32 dev_count; |
|---|
| 56 | | - struct dev_header dev_header[0]; |
|---|
| 46 | + struct dev_header dev_header[]; |
|---|
| 57 | 47 | }; |
|---|
| 58 | 48 | |
|---|
| 59 | 49 | static void __init unmarshal_key_value_pairs(struct dev_header *dev_header, |
|---|
| 60 | | - struct device *dev, void *ptr, |
|---|
| 50 | + struct device *dev, const void *ptr, |
|---|
| 61 | 51 | struct property_entry entry[]) |
|---|
| 62 | 52 | { |
|---|
| 63 | 53 | int i; |
|---|
| 64 | 54 | |
|---|
| 65 | 55 | for (i = 0; i < dev_header->prop_count; i++) { |
|---|
| 66 | 56 | int remaining = dev_header->len - (ptr - (void *)dev_header); |
|---|
| 67 | | - u32 key_len, val_len; |
|---|
| 57 | + u32 key_len, val_len, entry_len; |
|---|
| 58 | + const u8 *entry_data; |
|---|
| 68 | 59 | char *key; |
|---|
| 69 | 60 | |
|---|
| 70 | 61 | if (sizeof(key_len) > remaining) |
|---|
| .. | .. |
|---|
| 96 | 87 | ucs2_as_utf8(key, ptr + sizeof(key_len), |
|---|
| 97 | 88 | key_len - sizeof(key_len)); |
|---|
| 98 | 89 | |
|---|
| 99 | | - entry[i].name = key; |
|---|
| 100 | | - entry[i].length = val_len - sizeof(val_len); |
|---|
| 101 | | - entry[i].is_array = !!entry[i].length; |
|---|
| 102 | | - entry[i].type = DEV_PROP_U8; |
|---|
| 103 | | - entry[i].pointer.u8_data = ptr + key_len + sizeof(val_len); |
|---|
| 90 | + entry_data = ptr + key_len + sizeof(val_len); |
|---|
| 91 | + entry_len = val_len - sizeof(val_len); |
|---|
| 92 | + if (entry_len) |
|---|
| 93 | + entry[i] = PROPERTY_ENTRY_U8_ARRAY_LEN(key, entry_data, |
|---|
| 94 | + entry_len); |
|---|
| 95 | + else |
|---|
| 96 | + entry[i] = PROPERTY_ENTRY_BOOL(key); |
|---|
| 104 | 97 | |
|---|
| 105 | 98 | if (dump_properties) { |
|---|
| 106 | | - dev_info(dev, "property: %s\n", entry[i].name); |
|---|
| 99 | + dev_info(dev, "property: %s\n", key); |
|---|
| 107 | 100 | print_hex_dump(KERN_INFO, pr_fmt(), DUMP_PREFIX_OFFSET, |
|---|
| 108 | | - 16, 1, entry[i].pointer.u8_data, |
|---|
| 109 | | - entry[i].length, true); |
|---|
| 101 | + 16, 1, entry_data, entry_len, true); |
|---|
| 110 | 102 | } |
|---|
| 111 | 103 | |
|---|
| 112 | 104 | ptr += key_len + val_len; |
|---|
| .. | .. |
|---|
| 130 | 122 | while (offset + sizeof(struct dev_header) < properties->len) { |
|---|
| 131 | 123 | struct dev_header *dev_header = (void *)properties + offset; |
|---|
| 132 | 124 | struct property_entry *entry = NULL; |
|---|
| 125 | + const struct efi_dev_path *ptr; |
|---|
| 133 | 126 | struct device *dev; |
|---|
| 134 | 127 | size_t len; |
|---|
| 135 | 128 | int ret, i; |
|---|
| 136 | | - void *ptr; |
|---|
| 137 | 129 | |
|---|
| 138 | 130 | if (offset + dev_header->len > properties->len || |
|---|
| 139 | 131 | dev_header->len <= sizeof(*dev_header)) { |
|---|
| .. | .. |
|---|
| 144 | 136 | ptr = dev_header->path; |
|---|
| 145 | 137 | len = dev_header->len - sizeof(*dev_header); |
|---|
| 146 | 138 | |
|---|
| 147 | | - dev = efi_get_device_by_path((struct efi_dev_path **)&ptr, &len); |
|---|
| 139 | + dev = efi_get_device_by_path(&ptr, &len); |
|---|
| 148 | 140 | if (IS_ERR(dev)) { |
|---|
| 149 | 141 | pr_err("device path parse error %ld at %#zx:\n", |
|---|
| 150 | | - PTR_ERR(dev), ptr - (void *)dev_header); |
|---|
| 142 | + PTR_ERR(dev), (void *)ptr - (void *)dev_header); |
|---|
| 151 | 143 | print_hex_dump(KERN_ERR, pr_fmt(), DUMP_PREFIX_OFFSET, |
|---|
| 152 | 144 | 16, 1, dev_header, dev_header->len, true); |
|---|
| 153 | 145 | dev = NULL; |
|---|
| .. | .. |
|---|
| 235 | 227 | */ |
|---|
| 236 | 228 | data->len = 0; |
|---|
| 237 | 229 | memunmap(data); |
|---|
| 238 | | - free_bootmem_late(pa_data + sizeof(*data), data_len); |
|---|
| 230 | + memblock_free_late(pa_data + sizeof(*data), data_len); |
|---|
| 239 | 231 | |
|---|
| 240 | 232 | return ret; |
|---|
| 241 | 233 | } |
|---|