blob: 4da4eb9ae92604c35349ebaeb39b4a612bac3ed6 [file] [log] [blame]
Konrad Rzeszutek138fe4e2008-04-09 19:50:41 -07001/*
Peter Jones4e639fd2010-02-25 15:37:17 -05002 * Copyright 2007-2010 Red Hat, Inc.
Konrad Rzeszutek138fe4e2008-04-09 19:50:41 -07003 * by Peter Jones <pjones@redhat.com>
4 * Copyright 2007 IBM, Inc.
5 * by Konrad Rzeszutek <konradr@linux.vnet.ibm.com>
6 * Copyright 2008
7 * by Konrad Rzeszutek <ketuzsezr@darnok.org>
8 *
9 * This code finds the iSCSI Boot Format Table.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License v2.0 as published by
13 * the Free Software Foundation
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */
20
21#include <linux/bootmem.h>
22#include <linux/blkdev.h>
23#include <linux/ctype.h>
24#include <linux/device.h>
Peter Jones4e639fd2010-02-25 15:37:17 -050025#include <linux/efi.h>
Konrad Rzeszutek138fe4e2008-04-09 19:50:41 -070026#include <linux/err.h>
27#include <linux/init.h>
28#include <linux/limits.h>
29#include <linux/module.h>
30#include <linux/pci.h>
Konrad Rzeszutek138fe4e2008-04-09 19:50:41 -070031#include <linux/stat.h>
32#include <linux/string.h>
33#include <linux/types.h>
Peter Jones4e639fd2010-02-25 15:37:17 -050034#include <linux/acpi.h>
35#include <linux/iscsi_ibft.h>
Konrad Rzeszutek138fe4e2008-04-09 19:50:41 -070036
37#include <asm/mmzone.h>
38
39/*
40 * Physical location of iSCSI Boot Format Table.
41 */
Peter Jones4e639fd2010-02-25 15:37:17 -050042struct acpi_table_ibft *ibft_addr;
Konrad Rzeszutek138fe4e2008-04-09 19:50:41 -070043EXPORT_SYMBOL_GPL(ibft_addr);
44
Mike Christie14036352011-04-14 23:50:57 -040045static const struct {
46 char *sign;
47} ibft_signs[] = {
Mike Christie14036352011-04-14 23:50:57 -040048 { "iBFT" },
49 { "BIFT" }, /* Broadcom iSCSI Offload */
50};
51
Konrad Rzeszutek138fe4e2008-04-09 19:50:41 -070052#define IBFT_SIGN_LEN 4
53#define IBFT_START 0x80000 /* 512kB */
54#define IBFT_END 0x100000 /* 1MB */
55#define VGA_MEM 0xA0000 /* VGA buffer */
56#define VGA_SIZE 0x20000 /* 128kB */
57
Konrad Rzeszutek Wilk1303a352010-04-08 12:35:55 -040058static int __init find_ibft_in_mem(void)
Konrad Rzeszutek138fe4e2008-04-09 19:50:41 -070059{
60 unsigned long pos;
61 unsigned int len = 0;
62 void *virt;
Mike Christie14036352011-04-14 23:50:57 -040063 int i;
Konrad Rzeszutek138fe4e2008-04-09 19:50:41 -070064
Konrad Rzeszutek138fe4e2008-04-09 19:50:41 -070065 for (pos = IBFT_START; pos < IBFT_END; pos += 16) {
66 /* The table can't be inside the VGA BIOS reserved space,
67 * so skip that area */
68 if (pos == VGA_MEM)
69 pos += VGA_SIZE;
Jan Beuliched3c6612009-10-02 16:12:39 +010070 virt = isa_bus_to_virt(pos);
Mike Christie14036352011-04-14 23:50:57 -040071
72 for (i = 0; i < ARRAY_SIZE(ibft_signs); i++) {
73 if (memcmp(virt, ibft_signs[i].sign, IBFT_SIGN_LEN) ==
74 0) {
75 unsigned long *addr =
76 (unsigned long *)isa_bus_to_virt(pos + 4);
77 len = *addr;
78 /* if the length of the table extends past 1M,
79 * the table cannot be valid. */
80 if (pos + len <= (IBFT_END-1)) {
81 ibft_addr = (struct acpi_table_ibft *)virt;
Yinghai Lu935a9fe2011-12-12 12:39:14 -080082 pr_info("iBFT found at 0x%lx.\n", pos);
Mike Christie14036352011-04-14 23:50:57 -040083 goto done;
84 }
Konrad Rzeszutek138fe4e2008-04-09 19:50:41 -070085 }
86 }
87 }
Mike Christie14036352011-04-14 23:50:57 -040088done:
Konrad Rzeszutek Wilk1303a352010-04-08 12:35:55 -040089 return len;
90}
91/*
92 * Routine used to find the iSCSI Boot Format Table. The logical
93 * kernel address is set in the ibft_addr global variable.
94 */
95unsigned long __init find_ibft_region(unsigned long *sizep)
96{
Konrad Rzeszutek Wilk1303a352010-04-08 12:35:55 -040097 ibft_addr = NULL;
98
Konrad Rzeszutek Wilk1303a352010-04-08 12:35:55 -040099 /* iBFT 1.03 section 1.4.3.1 mandates that UEFI machines will
100 * only use ACPI for this */
101
Yinghai Lu935a9fe2011-12-12 12:39:14 -0800102 if (!efi_enabled)
Konrad Rzeszutek Wilk1303a352010-04-08 12:35:55 -0400103 find_ibft_in_mem();
104
Yinghai Lu042be382010-04-01 14:32:43 -0700105 if (ibft_addr) {
Peter Jones4e639fd2010-02-25 15:37:17 -0500106 *sizep = PAGE_ALIGN(ibft_addr->header.length);
107 return (u64)isa_virt_to_bus(ibft_addr);
Yinghai Lu042be382010-04-01 14:32:43 -0700108 }
109
110 *sizep = 0;
111 return 0;
Konrad Rzeszutek138fe4e2008-04-09 19:50:41 -0700112}