blob: 64bb945232819b288e512c5f21ada5dd5773a390 [file] [log] [blame]
Thomas Gleixnerd9523672019-05-29 07:18:01 -07001// SPDX-License-Identifier: GPL-2.0-only
Konrad Rzeszutek138fe4e2008-04-09 19:50:41 -07002/*
Peter Jones4e639fd2010-02-25 15:37:17 -05003 * Copyright 2007-2010 Red Hat, Inc.
Konrad Rzeszutek138fe4e2008-04-09 19:50:41 -07004 * 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.
Konrad Rzeszutek138fe4e2008-04-09 19:50:41 -070011 */
12
Mike Rapoport57c8a662018-10-30 15:09:49 -070013#include <linux/memblock.h>
Konrad Rzeszutek138fe4e2008-04-09 19:50:41 -070014#include <linux/blkdev.h>
15#include <linux/ctype.h>
16#include <linux/device.h>
Peter Jones4e639fd2010-02-25 15:37:17 -050017#include <linux/efi.h>
Konrad Rzeszutek138fe4e2008-04-09 19:50:41 -070018#include <linux/err.h>
19#include <linux/init.h>
20#include <linux/limits.h>
21#include <linux/module.h>
22#include <linux/pci.h>
Konrad Rzeszutek138fe4e2008-04-09 19:50:41 -070023#include <linux/stat.h>
24#include <linux/string.h>
25#include <linux/types.h>
Peter Jones4e639fd2010-02-25 15:37:17 -050026#include <linux/acpi.h>
27#include <linux/iscsi_ibft.h>
Konrad Rzeszutek138fe4e2008-04-09 19:50:41 -070028
29#include <asm/mmzone.h>
30
31/*
32 * Physical location of iSCSI Boot Format Table.
33 */
Peter Jones4e639fd2010-02-25 15:37:17 -050034struct acpi_table_ibft *ibft_addr;
Konrad Rzeszutek138fe4e2008-04-09 19:50:41 -070035EXPORT_SYMBOL_GPL(ibft_addr);
36
Mike Christie14036352011-04-14 23:50:57 -040037static const struct {
38 char *sign;
39} ibft_signs[] = {
Mike Christie14036352011-04-14 23:50:57 -040040 { "iBFT" },
41 { "BIFT" }, /* Broadcom iSCSI Offload */
42};
43
Konrad Rzeszutek138fe4e2008-04-09 19:50:41 -070044#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
Konrad Rzeszutek Wilk1303a352010-04-08 12:35:55 -040050static int __init find_ibft_in_mem(void)
Konrad Rzeszutek138fe4e2008-04-09 19:50:41 -070051{
52 unsigned long pos;
53 unsigned int len = 0;
54 void *virt;
Mike Christie14036352011-04-14 23:50:57 -040055 int i;
Konrad Rzeszutek138fe4e2008-04-09 19:50:41 -070056
Konrad Rzeszutek138fe4e2008-04-09 19:50:41 -070057 for (pos = IBFT_START; pos < IBFT_END; pos += 16) {
58 /* The table can't be inside the VGA BIOS reserved space,
59 * so skip that area */
60 if (pos == VGA_MEM)
61 pos += VGA_SIZE;
Jan Beuliched3c6612009-10-02 16:12:39 +010062 virt = isa_bus_to_virt(pos);
Mike Christie14036352011-04-14 23:50:57 -040063
64 for (i = 0; i < ARRAY_SIZE(ibft_signs); i++) {
65 if (memcmp(virt, ibft_signs[i].sign, IBFT_SIGN_LEN) ==
66 0) {
67 unsigned long *addr =
68 (unsigned long *)isa_bus_to_virt(pos + 4);
69 len = *addr;
70 /* if the length of the table extends past 1M,
71 * the table cannot be valid. */
72 if (pos + len <= (IBFT_END-1)) {
73 ibft_addr = (struct acpi_table_ibft *)virt;
Yinghai Lu935a9fe2011-12-12 12:39:14 -080074 pr_info("iBFT found at 0x%lx.\n", pos);
Mike Christie14036352011-04-14 23:50:57 -040075 goto done;
76 }
Konrad Rzeszutek138fe4e2008-04-09 19:50:41 -070077 }
78 }
79 }
Mike Christie14036352011-04-14 23:50:57 -040080done:
Konrad Rzeszutek Wilk1303a352010-04-08 12:35:55 -040081 return len;
82}
83/*
84 * Routine used to find the iSCSI Boot Format Table. The logical
85 * kernel address is set in the ibft_addr global variable.
86 */
87unsigned long __init find_ibft_region(unsigned long *sizep)
88{
Konrad Rzeszutek Wilk1303a352010-04-08 12:35:55 -040089 ibft_addr = NULL;
90
Konrad Rzeszutek Wilk1303a352010-04-08 12:35:55 -040091 /* iBFT 1.03 section 1.4.3.1 mandates that UEFI machines will
92 * only use ACPI for this */
93
Matt Fleming83e68182012-11-14 09:42:35 +000094 if (!efi_enabled(EFI_BOOT))
Konrad Rzeszutek Wilk1303a352010-04-08 12:35:55 -040095 find_ibft_in_mem();
96
Yinghai Lu042be382010-04-01 14:32:43 -070097 if (ibft_addr) {
Peter Jones4e639fd2010-02-25 15:37:17 -050098 *sizep = PAGE_ALIGN(ibft_addr->header.length);
Christoph Hellwig8bd04c52019-02-11 14:46:42 +010099 return (u64)virt_to_phys(ibft_addr);
Yinghai Lu042be382010-04-01 14:32:43 -0700100 }
101
102 *sizep = 0;
103 return 0;
Konrad Rzeszutek138fe4e2008-04-09 19:50:41 -0700104}