iscsi_ibft_find.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright 2007-2010 Red Hat, Inc.
  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.
  11. */
  12. #include <linux/memblock.h>
  13. #include <linux/blkdev.h>
  14. #include <linux/ctype.h>
  15. #include <linux/device.h>
  16. #include <linux/efi.h>
  17. #include <linux/err.h>
  18. #include <linux/init.h>
  19. #include <linux/limits.h>
  20. #include <linux/module.h>
  21. #include <linux/pci.h>
  22. #include <linux/stat.h>
  23. #include <linux/string.h>
  24. #include <linux/types.h>
  25. #include <linux/acpi.h>
  26. #include <linux/iscsi_ibft.h>
  27. #include <asm/mmzone.h>
  28. /*
  29. * Physical location of iSCSI Boot Format Table.
  30. */
  31. phys_addr_t ibft_phys_addr;
  32. EXPORT_SYMBOL_GPL(ibft_phys_addr);
  33. static const struct {
  34. char *sign;
  35. } ibft_signs[] = {
  36. { "iBFT" },
  37. { "BIFT" }, /* Broadcom iSCSI Offload */
  38. };
  39. #define IBFT_SIGN_LEN 4
  40. #define VGA_MEM 0xA0000 /* VGA buffer */
  41. #define VGA_SIZE 0x20000 /* 128kB */
  42. /*
  43. * Routine used to find and reserve the iSCSI Boot Format Table
  44. */
  45. void __init reserve_ibft_region(void)
  46. {
  47. unsigned long pos, virt_pos = 0;
  48. unsigned int len = 0;
  49. void *virt = NULL;
  50. int i;
  51. ibft_phys_addr = 0;
  52. /* iBFT 1.03 section 1.4.3.1 mandates that UEFI machines will
  53. * only use ACPI for this
  54. */
  55. if (efi_enabled(EFI_BOOT))
  56. return;
  57. 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;
  62. /* Map page by page */
  63. if (offset_in_page(pos) == 0) {
  64. if (virt)
  65. early_memunmap(virt, PAGE_SIZE);
  66. virt = early_memremap_ro(pos, PAGE_SIZE);
  67. virt_pos = pos;
  68. }
  69. for (i = 0; i < ARRAY_SIZE(ibft_signs); i++) {
  70. if (memcmp(virt + (pos - virt_pos), ibft_signs[i].sign,
  71. IBFT_SIGN_LEN) == 0) {
  72. unsigned long *addr =
  73. (unsigned long *)(virt + pos - virt_pos + 4);
  74. len = *addr;
  75. /* if the length of the table extends past 1M,
  76. * the table cannot be valid. */
  77. if (pos + len <= (IBFT_END-1)) {
  78. ibft_phys_addr = pos;
  79. memblock_reserve(ibft_phys_addr, PAGE_ALIGN(len));
  80. pr_info("iBFT found at %pa.\n", &ibft_phys_addr);
  81. goto out;
  82. }
  83. }
  84. }
  85. }
  86. out:
  87. early_memunmap(virt, PAGE_SIZE);
  88. }