Josh Triplett | 2223af3 | 2012-09-28 17:57:05 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 Intel Corporation |
| 3 | * Author: Josh Triplett <josh@joshtriplett.org> |
| 4 | * |
| 5 | * Based on the bgrt driver: |
| 6 | * Copyright 2012 Red Hat, Inc <mjg@redhat.com> |
| 7 | * Author: Matthew Garrett |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License version 2 as |
| 11 | * published by the Free Software Foundation. |
| 12 | */ |
Matt Fleming | 26d7f65 | 2015-10-25 10:26:35 +0000 | [diff] [blame] | 13 | |
| 14 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 15 | |
Josh Triplett | 2223af3 | 2012-09-28 17:57:05 -0700 | [diff] [blame] | 16 | #include <linux/kernel.h> |
Jan Beulich | 13f0e4d | 2012-11-23 16:30:07 +0000 | [diff] [blame] | 17 | #include <linux/init.h> |
Josh Triplett | 2223af3 | 2012-09-28 17:57:05 -0700 | [diff] [blame] | 18 | #include <linux/acpi.h> |
| 19 | #include <linux/efi.h> |
| 20 | #include <linux/efi-bgrt.h> |
| 21 | |
Dave Young | 7b0a911 | 2017-01-31 13:21:40 +0000 | [diff] [blame] | 22 | struct acpi_table_bgrt bgrt_tab; |
Jan Beulich | 13f0e4d | 2012-11-23 16:30:07 +0000 | [diff] [blame] | 23 | size_t __initdata bgrt_image_size; |
Josh Triplett | 2223af3 | 2012-09-28 17:57:05 -0700 | [diff] [blame] | 24 | |
| 25 | struct bmp_header { |
| 26 | u16 id; |
| 27 | u32 size; |
| 28 | } __packed; |
| 29 | |
Dave Young | 7b0a911 | 2017-01-31 13:21:40 +0000 | [diff] [blame] | 30 | void __init efi_bgrt_init(struct acpi_table_header *table) |
Josh Triplett | 2223af3 | 2012-09-28 17:57:05 -0700 | [diff] [blame] | 31 | { |
Sai Praneeth | 50a0cb5 | 2015-12-09 15:41:08 -0800 | [diff] [blame] | 32 | void *image; |
Josh Triplett | 2223af3 | 2012-09-28 17:57:05 -0700 | [diff] [blame] | 33 | struct bmp_header bmp_header; |
Dave Young | 7b0a911 | 2017-01-31 13:21:40 +0000 | [diff] [blame] | 34 | struct acpi_table_bgrt *bgrt = &bgrt_tab; |
Josh Triplett | 2223af3 | 2012-09-28 17:57:05 -0700 | [diff] [blame] | 35 | |
| 36 | if (acpi_disabled) |
| 37 | return; |
| 38 | |
Dave Young | 7425826 | 2017-05-26 12:36:51 +0100 | [diff] [blame] | 39 | if (!efi_enabled(EFI_BOOT)) |
| 40 | return; |
| 41 | |
Dave Young | 7b0a911 | 2017-01-31 13:21:40 +0000 | [diff] [blame] | 42 | if (table->length < sizeof(bgrt_tab)) { |
Josh Boyer | 7f9b474 | 2016-05-03 20:29:41 +0100 | [diff] [blame] | 43 | pr_notice("Ignoring BGRT: invalid length %u (expected %zu)\n", |
Dave Young | 7b0a911 | 2017-01-31 13:21:40 +0000 | [diff] [blame] | 44 | table->length, sizeof(bgrt_tab)); |
Jan Beulich | 5d6d578 | 2012-11-07 16:46:08 +0000 | [diff] [blame] | 45 | return; |
Josh Triplett | 1282278 | 2014-07-30 12:23:32 -0700 | [diff] [blame] | 46 | } |
Dave Young | 7b0a911 | 2017-01-31 13:21:40 +0000 | [diff] [blame] | 47 | *bgrt = *(struct acpi_table_bgrt *)table; |
| 48 | if (bgrt->version != 1) { |
Josh Boyer | 7f9b474 | 2016-05-03 20:29:41 +0100 | [diff] [blame] | 49 | pr_notice("Ignoring BGRT: invalid version %u (expected 1)\n", |
Dave Young | 7b0a911 | 2017-01-31 13:21:40 +0000 | [diff] [blame] | 50 | bgrt->version); |
| 51 | goto out; |
Josh Triplett | 1282278 | 2014-07-30 12:23:32 -0700 | [diff] [blame] | 52 | } |
Dave Young | 7b0a911 | 2017-01-31 13:21:40 +0000 | [diff] [blame] | 53 | if (bgrt->status & 0xfe) { |
Josh Boyer | 7f9b474 | 2016-05-03 20:29:41 +0100 | [diff] [blame] | 54 | pr_notice("Ignoring BGRT: reserved status bits are non-zero %u\n", |
Dave Young | 7b0a911 | 2017-01-31 13:21:40 +0000 | [diff] [blame] | 55 | bgrt->status); |
| 56 | goto out; |
Josh Triplett | 1282278 | 2014-07-30 12:23:32 -0700 | [diff] [blame] | 57 | } |
Dave Young | 7b0a911 | 2017-01-31 13:21:40 +0000 | [diff] [blame] | 58 | if (bgrt->image_type != 0) { |
Josh Boyer | 7f9b474 | 2016-05-03 20:29:41 +0100 | [diff] [blame] | 59 | pr_notice("Ignoring BGRT: invalid image type %u (expected 0)\n", |
Dave Young | 7b0a911 | 2017-01-31 13:21:40 +0000 | [diff] [blame] | 60 | bgrt->image_type); |
| 61 | goto out; |
Josh Triplett | 1282278 | 2014-07-30 12:23:32 -0700 | [diff] [blame] | 62 | } |
Dave Young | 7b0a911 | 2017-01-31 13:21:40 +0000 | [diff] [blame] | 63 | if (!bgrt->image_address) { |
Josh Boyer | 7f9b474 | 2016-05-03 20:29:41 +0100 | [diff] [blame] | 64 | pr_notice("Ignoring BGRT: null image address\n"); |
Dave Young | 7b0a911 | 2017-01-31 13:21:40 +0000 | [diff] [blame] | 65 | goto out; |
Josh Triplett | 1282278 | 2014-07-30 12:23:32 -0700 | [diff] [blame] | 66 | } |
Josh Triplett | 2223af3 | 2012-09-28 17:57:05 -0700 | [diff] [blame] | 67 | |
Dave Young | 7b0a911 | 2017-01-31 13:21:40 +0000 | [diff] [blame] | 68 | image = early_memremap(bgrt->image_address, sizeof(bmp_header)); |
Josh Triplett | 2223af3 | 2012-09-28 17:57:05 -0700 | [diff] [blame] | 69 | if (!image) { |
Josh Boyer | 7f9b474 | 2016-05-03 20:29:41 +0100 | [diff] [blame] | 70 | pr_notice("Ignoring BGRT: failed to map image header memory\n"); |
Dave Young | 7b0a911 | 2017-01-31 13:21:40 +0000 | [diff] [blame] | 71 | goto out; |
Josh Triplett | 2223af3 | 2012-09-28 17:57:05 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Sai Praneeth | 50a0cb5 | 2015-12-09 15:41:08 -0800 | [diff] [blame] | 74 | memcpy(&bmp_header, image, sizeof(bmp_header)); |
Dave Young | 7b0a911 | 2017-01-31 13:21:40 +0000 | [diff] [blame] | 75 | early_memunmap(image, sizeof(bmp_header)); |
Môshe van der Sterre | 66dbe99 | 2016-02-01 22:07:03 +0000 | [diff] [blame] | 76 | if (bmp_header.id != 0x4d42) { |
Josh Boyer | 7f9b474 | 2016-05-03 20:29:41 +0100 | [diff] [blame] | 77 | pr_notice("Ignoring BGRT: Incorrect BMP magic number 0x%x (expected 0x4d42)\n", |
Môshe van der Sterre | 66dbe99 | 2016-02-01 22:07:03 +0000 | [diff] [blame] | 78 | bmp_header.id); |
Dave Young | 7b0a911 | 2017-01-31 13:21:40 +0000 | [diff] [blame] | 79 | goto out; |
Môshe van der Sterre | 66dbe99 | 2016-02-01 22:07:03 +0000 | [diff] [blame] | 80 | } |
Josh Triplett | 2223af3 | 2012-09-28 17:57:05 -0700 | [diff] [blame] | 81 | bgrt_image_size = bmp_header.size; |
Dave Young | 7b0a911 | 2017-01-31 13:21:40 +0000 | [diff] [blame] | 82 | efi_mem_reserve(bgrt->image_address, bgrt_image_size); |
Josh Triplett | 2223af3 | 2012-09-28 17:57:05 -0700 | [diff] [blame] | 83 | |
Dave Young | 7b0a911 | 2017-01-31 13:21:40 +0000 | [diff] [blame] | 84 | return; |
| 85 | out: |
| 86 | memset(bgrt, 0, sizeof(bgrt_tab)); |
Josh Triplett | 2223af3 | 2012-09-28 17:57:05 -0700 | [diff] [blame] | 87 | } |