iscsi_ibft_find.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. struct acpi_table_ibft *ibft_addr;
  32. EXPORT_SYMBOL_GPL(ibft_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 IBFT_START 0x80000 /* 512kB */
  41. #define IBFT_END 0x100000 /* 1MB */
  42. #define VGA_MEM 0xA0000 /* VGA buffer */
  43. #define VGA_SIZE 0x20000 /* 128kB */
  44. static int __init find_ibft_in_mem(void)
  45. {
  46. unsigned long pos;
  47. unsigned int len = 0;
  48. void *virt;
  49. int i;
  50. for (pos = IBFT_START; pos < IBFT_END; pos += 16) {
  51. /* The table can't be inside the VGA BIOS reserved space,
  52. * so skip that area */
  53. if (pos == VGA_MEM)
  54. pos += VGA_SIZE;
  55. virt = isa_bus_to_virt(pos);
  56. for (i = 0; i < ARRAY_SIZE(ibft_signs); i++) {
  57. if (memcmp(virt, ibft_signs[i].sign, IBFT_SIGN_LEN) ==
  58. 0) {
  59. unsigned long *addr =
  60. (unsigned long *)isa_bus_to_virt(pos + 4);
  61. len = *addr;
  62. /* if the length of the table extends past 1M,
  63. * the table cannot be valid. */
  64. if (pos + len <= (IBFT_END-1)) {
  65. ibft_addr = (struct acpi_table_ibft *)virt;
  66. pr_info("iBFT found at 0x%lx.\n", pos);
  67. goto done;
  68. }
  69. }
  70. }
  71. }
  72. done:
  73. return len;
  74. }
  75. /*
  76. * Routine used to find the iSCSI Boot Format Table. The logical
  77. * kernel address is set in the ibft_addr global variable.
  78. */
  79. unsigned long __init find_ibft_region(unsigned long *sizep)
  80. {
  81. ibft_addr = NULL;
  82. /* iBFT 1.03 section 1.4.3.1 mandates that UEFI machines will
  83. * only use ACPI for this */
  84. if (!efi_enabled(EFI_BOOT))
  85. find_ibft_in_mem();
  86. if (ibft_addr) {
  87. *sizep = PAGE_ALIGN(ibft_addr->header.length);
  88. return (u64)virt_to_phys(ibft_addr);
  89. }
  90. *sizep = 0;
  91. return 0;
  92. }