drm/amdgpu: change gfx 11.0.4 external_id range
[linux-block.git] / drivers / firmware / iscsi_ibft_find.c
CommitLineData
d9523678 1// SPDX-License-Identifier: GPL-2.0-only
138fe4e0 2/*
4e639fdf 3 * Copyright 2007-2010 Red Hat, Inc.
138fe4e0
KR
4 * by Peter Jones <pjones@redhat.com>
5 * Copyright 2007 IBM, Inc.
6 * by Konrad Rzeszutek <konradr@linux.vnet.ibm.com>
7 * Copyright 2008
8 * by Konrad Rzeszutek <ketuzsezr@darnok.org>
9 *
10 * This code finds the iSCSI Boot Format Table.
138fe4e0
KR
11 */
12
57c8a661 13#include <linux/memblock.h>
138fe4e0
KR
14#include <linux/blkdev.h>
15#include <linux/ctype.h>
16#include <linux/device.h>
4e639fdf 17#include <linux/efi.h>
138fe4e0
KR
18#include <linux/err.h>
19#include <linux/init.h>
20#include <linux/limits.h>
21#include <linux/module.h>
22#include <linux/pci.h>
138fe4e0
KR
23#include <linux/stat.h>
24#include <linux/string.h>
25#include <linux/types.h>
4e639fdf
PJ
26#include <linux/acpi.h>
27#include <linux/iscsi_ibft.h>
138fe4e0
KR
28
29#include <asm/mmzone.h>
30
31/*
32 * Physical location of iSCSI Boot Format Table.
33 */
342f43af
ML
34phys_addr_t ibft_phys_addr;
35EXPORT_SYMBOL_GPL(ibft_phys_addr);
138fe4e0 36
14036350
MC
37static const struct {
38 char *sign;
39} ibft_signs[] = {
14036350
MC
40 { "iBFT" },
41 { "BIFT" }, /* Broadcom iSCSI Offload */
42};
43
138fe4e0
KR
44#define IBFT_SIGN_LEN 4
45#define IBFT_START 0x80000 /* 512kB */
46#define IBFT_END 0x100000 /* 1MB */
47#define VGA_MEM 0xA0000 /* VGA buffer */
48#define VGA_SIZE 0x20000 /* 128kB */
49
342f43af
ML
50/*
51 * Routine used to find and reserve the iSCSI Boot Format Table
52 */
53void __init reserve_ibft_region(void)
138fe4e0
KR
54{
55 unsigned long pos;
56 unsigned int len = 0;
57 void *virt;
14036350 58 int i;
138fe4e0 59
342f43af
ML
60 ibft_phys_addr = 0;
61
62 /* iBFT 1.03 section 1.4.3.1 mandates that UEFI machines will
63 * only use ACPI for this
64 */
65 if (efi_enabled(EFI_BOOT))
66 return;
67
138fe4e0
KR
68 for (pos = IBFT_START; pos < IBFT_END; pos += 16) {
69 /* The table can't be inside the VGA BIOS reserved space,
70 * so skip that area */
71 if (pos == VGA_MEM)
72 pos += VGA_SIZE;
ed3c6614 73 virt = isa_bus_to_virt(pos);
14036350
MC
74
75 for (i = 0; i < ARRAY_SIZE(ibft_signs); i++) {
76 if (memcmp(virt, ibft_signs[i].sign, IBFT_SIGN_LEN) ==
77 0) {
78 unsigned long *addr =
79 (unsigned long *)isa_bus_to_virt(pos + 4);
80 len = *addr;
81 /* if the length of the table extends past 1M,
82 * the table cannot be valid. */
83 if (pos + len <= (IBFT_END-1)) {
342f43af
ML
84 ibft_phys_addr = pos;
85 memblock_reserve(ibft_phys_addr, PAGE_ALIGN(len));
7fd1d00b 86 pr_info("iBFT found at %pa.\n", &ibft_phys_addr);
342f43af 87 return;
14036350 88 }
138fe4e0
KR
89 }
90 }
91 }
138fe4e0 92}