iscsi_ibft_find.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * Copyright 2007-2010 Red Hat, Inc.
  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. #include <linux/bootmem.h>
  21. #include <linux/blkdev.h>
  22. #include <linux/ctype.h>
  23. #include <linux/device.h>
  24. #include <linux/efi.h>
  25. #include <linux/err.h>
  26. #include <linux/init.h>
  27. #include <linux/limits.h>
  28. #include <linux/module.h>
  29. #include <linux/pci.h>
  30. #include <linux/stat.h>
  31. #include <linux/string.h>
  32. #include <linux/types.h>
  33. #include <linux/acpi.h>
  34. #include <linux/iscsi_ibft.h>
  35. #include <asm/mmzone.h>
  36. /*
  37. * Physical location of iSCSI Boot Format Table.
  38. */
  39. struct acpi_table_ibft *ibft_addr;
  40. EXPORT_SYMBOL_GPL(ibft_addr);
  41. static const struct {
  42. char *sign;
  43. } ibft_signs[] = {
  44. #ifdef CONFIG_ACPI
  45. /*
  46. * One spec says "IBFT", the other says "iBFT". We have to check
  47. * for both.
  48. */
  49. { ACPI_SIG_IBFT },
  50. #endif
  51. { "iBFT" },
  52. { "BIFT" }, /* Broadcom iSCSI Offload */
  53. };
  54. #define IBFT_SIGN_LEN 4
  55. #define IBFT_START 0x80000 /* 512kB */
  56. #define IBFT_END 0x100000 /* 1MB */
  57. #define VGA_MEM 0xA0000 /* VGA buffer */
  58. #define VGA_SIZE 0x20000 /* 128kB */
  59. #ifdef CONFIG_ACPI
  60. static int __init acpi_find_ibft(struct acpi_table_header *header)
  61. {
  62. ibft_addr = (struct acpi_table_ibft *)header;
  63. return 0;
  64. }
  65. #endif /* CONFIG_ACPI */
  66. static int __init find_ibft_in_mem(void)
  67. {
  68. unsigned long pos;
  69. unsigned int len = 0;
  70. void *virt;
  71. int i;
  72. for (pos = IBFT_START; pos < IBFT_END; pos += 16) {
  73. /* The table can't be inside the VGA BIOS reserved space,
  74. * so skip that area */
  75. if (pos == VGA_MEM)
  76. pos += VGA_SIZE;
  77. virt = isa_bus_to_virt(pos);
  78. for (i = 0; i < ARRAY_SIZE(ibft_signs); i++) {
  79. if (memcmp(virt, ibft_signs[i].sign, IBFT_SIGN_LEN) ==
  80. 0) {
  81. unsigned long *addr =
  82. (unsigned long *)isa_bus_to_virt(pos + 4);
  83. len = *addr;
  84. /* if the length of the table extends past 1M,
  85. * the table cannot be valid. */
  86. if (pos + len <= (IBFT_END-1)) {
  87. ibft_addr = (struct acpi_table_ibft *)virt;
  88. goto done;
  89. }
  90. }
  91. }
  92. }
  93. done:
  94. return len;
  95. }
  96. /*
  97. * Routine used to find the iSCSI Boot Format Table. The logical
  98. * kernel address is set in the ibft_addr global variable.
  99. */
  100. unsigned long __init find_ibft_region(unsigned long *sizep)
  101. {
  102. #ifdef CONFIG_ACPI
  103. int i;
  104. #endif
  105. ibft_addr = NULL;
  106. #ifdef CONFIG_ACPI
  107. for (i = 0; i < ARRAY_SIZE(ibft_signs) && !ibft_addr; i++)
  108. acpi_table_parse(ibft_signs[i].sign, acpi_find_ibft);
  109. #endif /* CONFIG_ACPI */
  110. /* iBFT 1.03 section 1.4.3.1 mandates that UEFI machines will
  111. * only use ACPI for this */
  112. if (!ibft_addr && !efi_enabled)
  113. find_ibft_in_mem();
  114. if (ibft_addr) {
  115. *sizep = PAGE_ALIGN(ibft_addr->header.length);
  116. return (u64)isa_virt_to_bus(ibft_addr);
  117. }
  118. *sizep = 0;
  119. return 0;
  120. }