| Konrad Rzeszutek | 138fe4e | 2008-04-09 19:50:41 -0700 | [diff] [blame] | 1 | /* | 
| Peter Jones | 4e639fd | 2010-02-25 15:37:17 -0500 | [diff] [blame] | 2 | *  Copyright 2007-2010 Red Hat, Inc. | 
| Konrad Rzeszutek | 138fe4e | 2008-04-09 19:50:41 -0700 | [diff] [blame] | 3 | *  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 Jones | 4e639fd | 2010-02-25 15:37:17 -0500 | [diff] [blame] | 25 | #include <linux/efi.h> | 
| Konrad Rzeszutek | 138fe4e | 2008-04-09 19:50:41 -0700 | [diff] [blame] | 26 | #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 Rzeszutek | 138fe4e | 2008-04-09 19:50:41 -0700 | [diff] [blame] | 31 | #include <linux/stat.h> | 
|  | 32 | #include <linux/string.h> | 
|  | 33 | #include <linux/types.h> | 
| Peter Jones | 4e639fd | 2010-02-25 15:37:17 -0500 | [diff] [blame] | 34 | #include <linux/acpi.h> | 
|  | 35 | #include <linux/iscsi_ibft.h> | 
| Konrad Rzeszutek | 138fe4e | 2008-04-09 19:50:41 -0700 | [diff] [blame] | 36 |  | 
|  | 37 | #include <asm/mmzone.h> | 
|  | 38 |  | 
|  | 39 | /* | 
|  | 40 | * Physical location of iSCSI Boot Format Table. | 
|  | 41 | */ | 
| Peter Jones | 4e639fd | 2010-02-25 15:37:17 -0500 | [diff] [blame] | 42 | struct acpi_table_ibft *ibft_addr; | 
| Konrad Rzeszutek | 138fe4e | 2008-04-09 19:50:41 -0700 | [diff] [blame] | 43 | EXPORT_SYMBOL_GPL(ibft_addr); | 
|  | 44 |  | 
|  | 45 | #define IBFT_SIGN "iBFT" | 
|  | 46 | #define IBFT_SIGN_LEN 4 | 
|  | 47 | #define IBFT_START 0x80000 /* 512kB */ | 
|  | 48 | #define IBFT_END 0x100000 /* 1MB */ | 
|  | 49 | #define VGA_MEM 0xA0000 /* VGA buffer */ | 
|  | 50 | #define VGA_SIZE 0x20000 /* 128kB */ | 
|  | 51 |  | 
| Peter Jones | 4e639fd | 2010-02-25 15:37:17 -0500 | [diff] [blame] | 52 | #ifdef CONFIG_ACPI | 
|  | 53 | static int __init acpi_find_ibft(struct acpi_table_header *header) | 
|  | 54 | { | 
|  | 55 | ibft_addr = (struct acpi_table_ibft *)header; | 
|  | 56 | return 0; | 
|  | 57 | } | 
|  | 58 | #endif /* CONFIG_ACPI */ | 
| Konrad Rzeszutek | 138fe4e | 2008-04-09 19:50:41 -0700 | [diff] [blame] | 59 |  | 
| Konrad Rzeszutek Wilk | 1303a35 | 2010-04-08 12:35:55 -0400 | [diff] [blame] | 60 | static int __init find_ibft_in_mem(void) | 
| Konrad Rzeszutek | 138fe4e | 2008-04-09 19:50:41 -0700 | [diff] [blame] | 61 | { | 
|  | 62 | unsigned long pos; | 
|  | 63 | unsigned int len = 0; | 
|  | 64 | void *virt; | 
|  | 65 |  | 
| Konrad Rzeszutek | 138fe4e | 2008-04-09 19:50:41 -0700 | [diff] [blame] | 66 | for (pos = IBFT_START; pos < IBFT_END; pos += 16) { | 
|  | 67 | /* The table can't be inside the VGA BIOS reserved space, | 
|  | 68 | * so skip that area */ | 
|  | 69 | if (pos == VGA_MEM) | 
|  | 70 | pos += VGA_SIZE; | 
| Jan Beulich | ed3c661 | 2009-10-02 16:12:39 +0100 | [diff] [blame] | 71 | virt = isa_bus_to_virt(pos); | 
| Konrad Rzeszutek | 138fe4e | 2008-04-09 19:50:41 -0700 | [diff] [blame] | 72 | if (memcmp(virt, IBFT_SIGN, IBFT_SIGN_LEN) == 0) { | 
|  | 73 | unsigned long *addr = | 
| Jan Beulich | ed3c661 | 2009-10-02 16:12:39 +0100 | [diff] [blame] | 74 | (unsigned long *)isa_bus_to_virt(pos + 4); | 
| Konrad Rzeszutek | 138fe4e | 2008-04-09 19:50:41 -0700 | [diff] [blame] | 75 | len = *addr; | 
|  | 76 | /* if the length of the table extends past 1M, | 
|  | 77 | * the table cannot be valid. */ | 
|  | 78 | if (pos + len <= (IBFT_END-1)) { | 
| Peter Jones | 4e639fd | 2010-02-25 15:37:17 -0500 | [diff] [blame] | 79 | ibft_addr = (struct acpi_table_ibft *)virt; | 
| Konrad Rzeszutek | 138fe4e | 2008-04-09 19:50:41 -0700 | [diff] [blame] | 80 | break; | 
|  | 81 | } | 
|  | 82 | } | 
|  | 83 | } | 
| Konrad Rzeszutek Wilk | 1303a35 | 2010-04-08 12:35:55 -0400 | [diff] [blame] | 84 | return len; | 
|  | 85 | } | 
|  | 86 | /* | 
|  | 87 | * Routine used to find the iSCSI Boot Format Table. The logical | 
|  | 88 | * kernel address is set in the ibft_addr global variable. | 
|  | 89 | */ | 
|  | 90 | unsigned long __init find_ibft_region(unsigned long *sizep) | 
|  | 91 | { | 
|  | 92 |  | 
|  | 93 | ibft_addr = NULL; | 
|  | 94 |  | 
| Peter Jones | 4e639fd | 2010-02-25 15:37:17 -0500 | [diff] [blame] | 95 | #ifdef CONFIG_ACPI | 
|  | 96 | /* | 
|  | 97 | * One spec says "IBFT", the other says "iBFT". We have to check | 
|  | 98 | * for both. | 
|  | 99 | */ | 
|  | 100 | if (!ibft_addr) | 
|  | 101 | acpi_table_parse(ACPI_SIG_IBFT, acpi_find_ibft); | 
|  | 102 | if (!ibft_addr) | 
| Peter Jones | 57a5f3c | 2010-05-12 10:12:53 -0400 | [diff] [blame] | 103 | acpi_table_parse(IBFT_SIGN, acpi_find_ibft); | 
| Peter Jones | 4e639fd | 2010-02-25 15:37:17 -0500 | [diff] [blame] | 104 | #endif /* CONFIG_ACPI */ | 
| Konrad Rzeszutek Wilk | 1303a35 | 2010-04-08 12:35:55 -0400 | [diff] [blame] | 105 |  | 
|  | 106 | /* iBFT 1.03 section 1.4.3.1 mandates that UEFI machines will | 
|  | 107 | * only use ACPI for this */ | 
|  | 108 |  | 
|  | 109 | if (!ibft_addr && !efi_enabled) | 
|  | 110 | find_ibft_in_mem(); | 
|  | 111 |  | 
| Yinghai Lu | 042be38 | 2010-04-01 14:32:43 -0700 | [diff] [blame] | 112 | if (ibft_addr) { | 
| Peter Jones | 4e639fd | 2010-02-25 15:37:17 -0500 | [diff] [blame] | 113 | *sizep = PAGE_ALIGN(ibft_addr->header.length); | 
|  | 114 | return (u64)isa_virt_to_bus(ibft_addr); | 
| Yinghai Lu | 042be38 | 2010-04-01 14:32:43 -0700 | [diff] [blame] | 115 | } | 
|  | 116 |  | 
|  | 117 | *sizep = 0; | 
|  | 118 | return 0; | 
| Konrad Rzeszutek | 138fe4e | 2008-04-09 19:50:41 -0700 | [diff] [blame] | 119 | } |