2019-02-02 17:41:15 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2012-09-29 08:57:05 +08:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Intel Corporation
|
|
|
|
* Author: Josh Triplett <josh@joshtriplett.org>
|
|
|
|
*
|
|
|
|
* Based on the bgrt driver:
|
|
|
|
* Copyright 2012 Red Hat, Inc <mjg@redhat.com>
|
|
|
|
* Author: Matthew Garrett
|
|
|
|
*/
|
2015-10-25 18:26:35 +08:00
|
|
|
|
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
2012-09-29 08:57:05 +08:00
|
|
|
#include <linux/kernel.h>
|
2012-11-24 00:30:07 +08:00
|
|
|
#include <linux/init.h>
|
2012-09-29 08:57:05 +08:00
|
|
|
#include <linux/acpi.h>
|
|
|
|
#include <linux/efi.h>
|
|
|
|
#include <linux/efi-bgrt.h>
|
|
|
|
|
2017-01-31 21:21:40 +08:00
|
|
|
struct acpi_table_bgrt bgrt_tab;
|
2018-07-03 23:43:10 +08:00
|
|
|
size_t bgrt_image_size;
|
2012-09-29 08:57:05 +08:00
|
|
|
|
|
|
|
struct bmp_header {
|
|
|
|
u16 id;
|
|
|
|
u32 size;
|
|
|
|
} __packed;
|
|
|
|
|
2017-01-31 21:21:40 +08:00
|
|
|
void __init efi_bgrt_init(struct acpi_table_header *table)
|
2012-09-29 08:57:05 +08:00
|
|
|
{
|
2015-12-10 07:41:08 +08:00
|
|
|
void *image;
|
2012-09-29 08:57:05 +08:00
|
|
|
struct bmp_header bmp_header;
|
2017-01-31 21:21:40 +08:00
|
|
|
struct acpi_table_bgrt *bgrt = &bgrt_tab;
|
2012-09-29 08:57:05 +08:00
|
|
|
|
|
|
|
if (acpi_disabled)
|
|
|
|
return;
|
|
|
|
|
2017-06-09 16:45:58 +08:00
|
|
|
if (!efi_enabled(EFI_MEMMAP))
|
2017-05-26 19:36:51 +08:00
|
|
|
return;
|
|
|
|
|
2017-01-31 21:21:40 +08:00
|
|
|
if (table->length < sizeof(bgrt_tab)) {
|
2016-05-04 03:29:41 +08:00
|
|
|
pr_notice("Ignoring BGRT: invalid length %u (expected %zu)\n",
|
2017-01-31 21:21:40 +08:00
|
|
|
table->length, sizeof(bgrt_tab));
|
2012-11-08 00:46:08 +08:00
|
|
|
return;
|
2014-07-31 03:23:32 +08:00
|
|
|
}
|
2017-01-31 21:21:40 +08:00
|
|
|
*bgrt = *(struct acpi_table_bgrt *)table;
|
2020-01-31 21:06:23 +08:00
|
|
|
/*
|
|
|
|
* Only version 1 is defined but some older laptops (seen on Lenovo
|
|
|
|
* Ivy Bridge models) have a correct version 1 BGRT table with the
|
|
|
|
* version set to 0, so we accept version 0 and 1.
|
|
|
|
*/
|
|
|
|
if (bgrt->version > 1) {
|
2016-05-04 03:29:41 +08:00
|
|
|
pr_notice("Ignoring BGRT: invalid version %u (expected 1)\n",
|
2017-01-31 21:21:40 +08:00
|
|
|
bgrt->version);
|
|
|
|
goto out;
|
2014-07-31 03:23:32 +08:00
|
|
|
}
|
2017-01-31 21:21:40 +08:00
|
|
|
if (bgrt->image_type != 0) {
|
2016-05-04 03:29:41 +08:00
|
|
|
pr_notice("Ignoring BGRT: invalid image type %u (expected 0)\n",
|
2017-01-31 21:21:40 +08:00
|
|
|
bgrt->image_type);
|
|
|
|
goto out;
|
2014-07-31 03:23:32 +08:00
|
|
|
}
|
2017-01-31 21:21:40 +08:00
|
|
|
if (!bgrt->image_address) {
|
2016-05-04 03:29:41 +08:00
|
|
|
pr_notice("Ignoring BGRT: null image address\n");
|
2017-01-31 21:21:40 +08:00
|
|
|
goto out;
|
2014-07-31 03:23:32 +08:00
|
|
|
}
|
2012-09-29 08:57:05 +08:00
|
|
|
|
2017-08-25 23:50:19 +08:00
|
|
|
if (efi_mem_type(bgrt->image_address) != EFI_BOOT_SERVICES_DATA) {
|
2017-06-09 16:45:58 +08:00
|
|
|
pr_notice("Ignoring BGRT: invalid image address\n");
|
|
|
|
goto out;
|
|
|
|
}
|
2017-01-31 21:21:40 +08:00
|
|
|
image = early_memremap(bgrt->image_address, sizeof(bmp_header));
|
2012-09-29 08:57:05 +08:00
|
|
|
if (!image) {
|
2016-05-04 03:29:41 +08:00
|
|
|
pr_notice("Ignoring BGRT: failed to map image header memory\n");
|
2017-01-31 21:21:40 +08:00
|
|
|
goto out;
|
2012-09-29 08:57:05 +08:00
|
|
|
}
|
|
|
|
|
2015-12-10 07:41:08 +08:00
|
|
|
memcpy(&bmp_header, image, sizeof(bmp_header));
|
2017-01-31 21:21:40 +08:00
|
|
|
early_memunmap(image, sizeof(bmp_header));
|
2016-02-02 06:07:03 +08:00
|
|
|
if (bmp_header.id != 0x4d42) {
|
2016-05-04 03:29:41 +08:00
|
|
|
pr_notice("Ignoring BGRT: Incorrect BMP magic number 0x%x (expected 0x4d42)\n",
|
2016-02-02 06:07:03 +08:00
|
|
|
bmp_header.id);
|
2017-01-31 21:21:40 +08:00
|
|
|
goto out;
|
2016-02-02 06:07:03 +08:00
|
|
|
}
|
2012-09-29 08:57:05 +08:00
|
|
|
bgrt_image_size = bmp_header.size;
|
2017-01-31 21:21:40 +08:00
|
|
|
efi_mem_reserve(bgrt->image_address, bgrt_image_size);
|
2012-09-29 08:57:05 +08:00
|
|
|
|
2017-01-31 21:21:40 +08:00
|
|
|
return;
|
|
|
|
out:
|
|
|
|
memset(bgrt, 0, sizeof(bgrt_tab));
|
2012-09-29 08:57:05 +08:00
|
|
|
}
|