Commit | Line | Data |
---|---|---|
2223af38 JT |
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 | */ | |
26d7f65f MF |
13 | |
14 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | |
15 | ||
2223af38 | 16 | #include <linux/kernel.h> |
13f0e4d2 | 17 | #include <linux/init.h> |
2223af38 JT |
18 | #include <linux/acpi.h> |
19 | #include <linux/efi.h> | |
20 | #include <linux/efi-bgrt.h> | |
21 | ||
22 | struct acpi_table_bgrt *bgrt_tab; | |
13f0e4d2 JB |
23 | void *__initdata bgrt_image; |
24 | size_t __initdata bgrt_image_size; | |
2223af38 JT |
25 | |
26 | struct bmp_header { | |
27 | u16 id; | |
28 | u32 size; | |
29 | } __packed; | |
30 | ||
13f0e4d2 | 31 | void __init efi_bgrt_init(void) |
2223af38 JT |
32 | { |
33 | acpi_status status; | |
50a0cb56 | 34 | void *image; |
2223af38 JT |
35 | struct bmp_header bmp_header; |
36 | ||
37 | if (acpi_disabled) | |
38 | return; | |
39 | ||
40 | status = acpi_get_table("BGRT", 0, | |
41 | (struct acpi_table_header **)&bgrt_tab); | |
42 | if (ACPI_FAILURE(status)) | |
43 | return; | |
44 | ||
1282278e | 45 | if (bgrt_tab->header.length < sizeof(*bgrt_tab)) { |
7f9b474c | 46 | pr_notice("Ignoring BGRT: invalid length %u (expected %zu)\n", |
1282278e | 47 | bgrt_tab->header.length, sizeof(*bgrt_tab)); |
5d6d578c | 48 | return; |
1282278e JT |
49 | } |
50 | if (bgrt_tab->version != 1) { | |
7f9b474c | 51 | pr_notice("Ignoring BGRT: invalid version %u (expected 1)\n", |
1282278e JT |
52 | bgrt_tab->version); |
53 | return; | |
54 | } | |
248fbcd5 | 55 | if (bgrt_tab->status & 0xfe) { |
7f9b474c | 56 | pr_notice("Ignoring BGRT: reserved status bits are non-zero %u\n", |
1282278e JT |
57 | bgrt_tab->status); |
58 | return; | |
59 | } | |
60 | if (bgrt_tab->image_type != 0) { | |
7f9b474c | 61 | pr_notice("Ignoring BGRT: invalid image type %u (expected 0)\n", |
1282278e | 62 | bgrt_tab->image_type); |
2223af38 | 63 | return; |
1282278e JT |
64 | } |
65 | if (!bgrt_tab->image_address) { | |
7f9b474c | 66 | pr_notice("Ignoring BGRT: null image address\n"); |
2223af38 | 67 | return; |
1282278e | 68 | } |
2223af38 | 69 | |
e2c90dd7 | 70 | image = memremap(bgrt_tab->image_address, sizeof(bmp_header), MEMREMAP_WB); |
2223af38 | 71 | if (!image) { |
7f9b474c | 72 | pr_notice("Ignoring BGRT: failed to map image header memory\n"); |
50a0cb56 | 73 | return; |
2223af38 JT |
74 | } |
75 | ||
50a0cb56 | 76 | memcpy(&bmp_header, image, sizeof(bmp_header)); |
e2c90dd7 | 77 | memunmap(image); |
66dbe99c | 78 | if (bmp_header.id != 0x4d42) { |
7f9b474c | 79 | pr_notice("Ignoring BGRT: Incorrect BMP magic number 0x%x (expected 0x4d42)\n", |
66dbe99c MS |
80 | bmp_header.id); |
81 | return; | |
82 | } | |
2223af38 JT |
83 | bgrt_image_size = bmp_header.size; |
84 | ||
1282278e JT |
85 | bgrt_image = kmalloc(bgrt_image_size, GFP_KERNEL | __GFP_NOWARN); |
86 | if (!bgrt_image) { | |
7f9b474c | 87 | pr_notice("Ignoring BGRT: failed to allocate memory for image (wanted %zu bytes)\n", |
1282278e | 88 | bgrt_image_size); |
2223af38 | 89 | return; |
1282278e | 90 | } |
2223af38 | 91 | |
e2c90dd7 | 92 | image = memremap(bgrt_tab->image_address, bmp_header.size, MEMREMAP_WB); |
50a0cb56 | 93 | if (!image) { |
7f9b474c | 94 | pr_notice("Ignoring BGRT: failed to map image memory\n"); |
50a0cb56 SP |
95 | kfree(bgrt_image); |
96 | bgrt_image = NULL; | |
97 | return; | |
2223af38 JT |
98 | } |
99 | ||
50a0cb56 | 100 | memcpy(bgrt_image, image, bgrt_image_size); |
e2c90dd7 | 101 | memunmap(image); |
2223af38 | 102 | } |