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 | 7b0a911 | 2017-01-31 13:21:40 +0000 | [diff] [blame] | 39 | if (table->length < sizeof(bgrt_tab)) { |
Josh Boyer | 7f9b474 | 2016-05-03 20:29:41 +0100 | [diff] [blame] | 40 | pr_notice("Ignoring BGRT: invalid length %u (expected %zu)\n", |
Dave Young | 7b0a911 | 2017-01-31 13:21:40 +0000 | [diff] [blame] | 41 | table->length, sizeof(bgrt_tab)); |
Jan Beulich | 5d6d578 | 2012-11-07 16:46:08 +0000 | [diff] [blame] | 42 | return; |
Josh Triplett | 1282278 | 2014-07-30 12:23:32 -0700 | [diff] [blame] | 43 | } |
Dave Young | 7b0a911 | 2017-01-31 13:21:40 +0000 | [diff] [blame] | 44 | *bgrt = *(struct acpi_table_bgrt *)table; |
| 45 | if (bgrt->version != 1) { |
Josh Boyer | 7f9b474 | 2016-05-03 20:29:41 +0100 | [diff] [blame] | 46 | pr_notice("Ignoring BGRT: invalid version %u (expected 1)\n", |
Dave Young | 7b0a911 | 2017-01-31 13:21:40 +0000 | [diff] [blame] | 47 | bgrt->version); |
| 48 | goto out; |
Josh Triplett | 1282278 | 2014-07-30 12:23:32 -0700 | [diff] [blame] | 49 | } |
Dave Young | 7b0a911 | 2017-01-31 13:21:40 +0000 | [diff] [blame] | 50 | if (bgrt->status & 0xfe) { |
Josh Boyer | 7f9b474 | 2016-05-03 20:29:41 +0100 | [diff] [blame] | 51 | pr_notice("Ignoring BGRT: reserved status bits are non-zero %u\n", |
Dave Young | 7b0a911 | 2017-01-31 13:21:40 +0000 | [diff] [blame] | 52 | bgrt->status); |
| 53 | goto out; |
Josh Triplett | 1282278 | 2014-07-30 12:23:32 -0700 | [diff] [blame] | 54 | } |
Dave Young | 7b0a911 | 2017-01-31 13:21:40 +0000 | [diff] [blame] | 55 | if (bgrt->image_type != 0) { |
Josh Boyer | 7f9b474 | 2016-05-03 20:29:41 +0100 | [diff] [blame] | 56 | pr_notice("Ignoring BGRT: invalid image type %u (expected 0)\n", |
Dave Young | 7b0a911 | 2017-01-31 13:21:40 +0000 | [diff] [blame] | 57 | bgrt->image_type); |
| 58 | goto out; |
Josh Triplett | 1282278 | 2014-07-30 12:23:32 -0700 | [diff] [blame] | 59 | } |
Dave Young | 7b0a911 | 2017-01-31 13:21:40 +0000 | [diff] [blame] | 60 | if (!bgrt->image_address) { |
Josh Boyer | 7f9b474 | 2016-05-03 20:29:41 +0100 | [diff] [blame] | 61 | pr_notice("Ignoring BGRT: null image address\n"); |
Dave Young | 7b0a911 | 2017-01-31 13:21:40 +0000 | [diff] [blame] | 62 | goto out; |
Josh Triplett | 1282278 | 2014-07-30 12:23:32 -0700 | [diff] [blame] | 63 | } |
Josh Triplett | 2223af3 | 2012-09-28 17:57:05 -0700 | [diff] [blame] | 64 | |
Dave Young | 7b0a911 | 2017-01-31 13:21:40 +0000 | [diff] [blame] | 65 | image = early_memremap(bgrt->image_address, sizeof(bmp_header)); |
Josh Triplett | 2223af3 | 2012-09-28 17:57:05 -0700 | [diff] [blame] | 66 | if (!image) { |
Josh Boyer | 7f9b474 | 2016-05-03 20:29:41 +0100 | [diff] [blame] | 67 | pr_notice("Ignoring BGRT: failed to map image header memory\n"); |
Dave Young | 7b0a911 | 2017-01-31 13:21:40 +0000 | [diff] [blame] | 68 | goto out; |
Josh Triplett | 2223af3 | 2012-09-28 17:57:05 -0700 | [diff] [blame] | 69 | } |
| 70 | |
Sai Praneeth | 50a0cb5 | 2015-12-09 15:41:08 -0800 | [diff] [blame] | 71 | memcpy(&bmp_header, image, sizeof(bmp_header)); |
Dave Young | 7b0a911 | 2017-01-31 13:21:40 +0000 | [diff] [blame] | 72 | early_memunmap(image, sizeof(bmp_header)); |
Môshe van der Sterre | 66dbe99 | 2016-02-01 22:07:03 +0000 | [diff] [blame] | 73 | if (bmp_header.id != 0x4d42) { |
Josh Boyer | 7f9b474 | 2016-05-03 20:29:41 +0100 | [diff] [blame] | 74 | 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] | 75 | bmp_header.id); |
Dave Young | 7b0a911 | 2017-01-31 13:21:40 +0000 | [diff] [blame] | 76 | goto out; |
Môshe van der Sterre | 66dbe99 | 2016-02-01 22:07:03 +0000 | [diff] [blame] | 77 | } |
Josh Triplett | 2223af3 | 2012-09-28 17:57:05 -0700 | [diff] [blame] | 78 | bgrt_image_size = bmp_header.size; |
Dave Young | 7b0a911 | 2017-01-31 13:21:40 +0000 | [diff] [blame] | 79 | efi_mem_reserve(bgrt->image_address, bgrt_image_size); |
Josh Triplett | 2223af3 | 2012-09-28 17:57:05 -0700 | [diff] [blame] | 80 | |
Dave Young | 7b0a911 | 2017-01-31 13:21:40 +0000 | [diff] [blame] | 81 | return; |
| 82 | out: |
| 83 | memset(bgrt, 0, sizeof(bgrt_tab)); |
Josh Triplett | 2223af3 | 2012-09-28 17:57:05 -0700 | [diff] [blame] | 84 | } |