blob: 04ca8764f0c096f4e3f006ab74e4dc55996735a1 [file] [log] [blame]
Josh Triplett2223af32012-09-28 17:57:05 -07001/*
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 Fleming26d7f652015-10-25 10:26:35 +000013
14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15
Josh Triplett2223af32012-09-28 17:57:05 -070016#include <linux/kernel.h>
Jan Beulich13f0e4d2012-11-23 16:30:07 +000017#include <linux/init.h>
Josh Triplett2223af32012-09-28 17:57:05 -070018#include <linux/acpi.h>
19#include <linux/efi.h>
20#include <linux/efi-bgrt.h>
21
Dave Young7b0a9112017-01-31 13:21:40 +000022struct acpi_table_bgrt bgrt_tab;
Jan Beulich13f0e4d2012-11-23 16:30:07 +000023size_t __initdata bgrt_image_size;
Josh Triplett2223af32012-09-28 17:57:05 -070024
25struct bmp_header {
26 u16 id;
27 u32 size;
28} __packed;
29
Dave Young7b0a9112017-01-31 13:21:40 +000030void __init efi_bgrt_init(struct acpi_table_header *table)
Josh Triplett2223af32012-09-28 17:57:05 -070031{
Sai Praneeth50a0cb52015-12-09 15:41:08 -080032 void *image;
Josh Triplett2223af32012-09-28 17:57:05 -070033 struct bmp_header bmp_header;
Dave Young7b0a9112017-01-31 13:21:40 +000034 struct acpi_table_bgrt *bgrt = &bgrt_tab;
Josh Triplett2223af32012-09-28 17:57:05 -070035
36 if (acpi_disabled)
37 return;
38
Dave Young7b0a9112017-01-31 13:21:40 +000039 if (table->length < sizeof(bgrt_tab)) {
Josh Boyer7f9b4742016-05-03 20:29:41 +010040 pr_notice("Ignoring BGRT: invalid length %u (expected %zu)\n",
Dave Young7b0a9112017-01-31 13:21:40 +000041 table->length, sizeof(bgrt_tab));
Jan Beulich5d6d5782012-11-07 16:46:08 +000042 return;
Josh Triplett12822782014-07-30 12:23:32 -070043 }
Dave Young7b0a9112017-01-31 13:21:40 +000044 *bgrt = *(struct acpi_table_bgrt *)table;
45 if (bgrt->version != 1) {
Josh Boyer7f9b4742016-05-03 20:29:41 +010046 pr_notice("Ignoring BGRT: invalid version %u (expected 1)\n",
Dave Young7b0a9112017-01-31 13:21:40 +000047 bgrt->version);
48 goto out;
Josh Triplett12822782014-07-30 12:23:32 -070049 }
Dave Young7b0a9112017-01-31 13:21:40 +000050 if (bgrt->status & 0xfe) {
Josh Boyer7f9b4742016-05-03 20:29:41 +010051 pr_notice("Ignoring BGRT: reserved status bits are non-zero %u\n",
Dave Young7b0a9112017-01-31 13:21:40 +000052 bgrt->status);
53 goto out;
Josh Triplett12822782014-07-30 12:23:32 -070054 }
Dave Young7b0a9112017-01-31 13:21:40 +000055 if (bgrt->image_type != 0) {
Josh Boyer7f9b4742016-05-03 20:29:41 +010056 pr_notice("Ignoring BGRT: invalid image type %u (expected 0)\n",
Dave Young7b0a9112017-01-31 13:21:40 +000057 bgrt->image_type);
58 goto out;
Josh Triplett12822782014-07-30 12:23:32 -070059 }
Dave Young7b0a9112017-01-31 13:21:40 +000060 if (!bgrt->image_address) {
Josh Boyer7f9b4742016-05-03 20:29:41 +010061 pr_notice("Ignoring BGRT: null image address\n");
Dave Young7b0a9112017-01-31 13:21:40 +000062 goto out;
Josh Triplett12822782014-07-30 12:23:32 -070063 }
Josh Triplett2223af32012-09-28 17:57:05 -070064
Dave Young7b0a9112017-01-31 13:21:40 +000065 image = early_memremap(bgrt->image_address, sizeof(bmp_header));
Josh Triplett2223af32012-09-28 17:57:05 -070066 if (!image) {
Josh Boyer7f9b4742016-05-03 20:29:41 +010067 pr_notice("Ignoring BGRT: failed to map image header memory\n");
Dave Young7b0a9112017-01-31 13:21:40 +000068 goto out;
Josh Triplett2223af32012-09-28 17:57:05 -070069 }
70
Sai Praneeth50a0cb52015-12-09 15:41:08 -080071 memcpy(&bmp_header, image, sizeof(bmp_header));
Dave Young7b0a9112017-01-31 13:21:40 +000072 early_memunmap(image, sizeof(bmp_header));
Môshe van der Sterre66dbe992016-02-01 22:07:03 +000073 if (bmp_header.id != 0x4d42) {
Josh Boyer7f9b4742016-05-03 20:29:41 +010074 pr_notice("Ignoring BGRT: Incorrect BMP magic number 0x%x (expected 0x4d42)\n",
Môshe van der Sterre66dbe992016-02-01 22:07:03 +000075 bmp_header.id);
Dave Young7b0a9112017-01-31 13:21:40 +000076 goto out;
Môshe van der Sterre66dbe992016-02-01 22:07:03 +000077 }
Josh Triplett2223af32012-09-28 17:57:05 -070078 bgrt_image_size = bmp_header.size;
Dave Young7b0a9112017-01-31 13:21:40 +000079 efi_mem_reserve(bgrt->image_address, bgrt_image_size);
Josh Triplett2223af32012-09-28 17:57:05 -070080
Dave Young7b0a9112017-01-31 13:21:40 +000081 return;
82out:
83 memset(bgrt, 0, sizeof(bgrt_tab));
Josh Triplett2223af32012-09-28 17:57:05 -070084}