iscsi_ibft_find.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright 2007 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/err.h>
  25. #include <linux/init.h>
  26. #include <linux/limits.h>
  27. #include <linux/module.h>
  28. #include <linux/pci.h>
  29. #include <linux/stat.h>
  30. #include <linux/string.h>
  31. #include <linux/types.h>
  32. #include <asm/mmzone.h>
  33. /*
  34. * Physical location of iSCSI Boot Format Table.
  35. */
  36. struct ibft_table_header *ibft_addr;
  37. EXPORT_SYMBOL_GPL(ibft_addr);
  38. #define IBFT_SIGN "iBFT"
  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. /*
  45. * Routine used to find the iSCSI Boot Format Table. The logical
  46. * kernel address is set in the ibft_addr global variable.
  47. */
  48. unsigned long __init find_ibft_region(unsigned long *sizep)
  49. {
  50. unsigned long pos;
  51. unsigned int len = 0;
  52. void *virt;
  53. ibft_addr = NULL;
  54. for (pos = IBFT_START; pos < IBFT_END; pos += 16) {
  55. /* The table can't be inside the VGA BIOS reserved space,
  56. * so skip that area */
  57. if (pos == VGA_MEM)
  58. pos += VGA_SIZE;
  59. virt = isa_bus_to_virt(pos);
  60. if (memcmp(virt, IBFT_SIGN, IBFT_SIGN_LEN) == 0) {
  61. unsigned long *addr =
  62. (unsigned long *)isa_bus_to_virt(pos + 4);
  63. len = *addr;
  64. /* if the length of the table extends past 1M,
  65. * the table cannot be valid. */
  66. if (pos + len <= (IBFT_END-1)) {
  67. ibft_addr = (struct ibft_table_header *)virt;
  68. break;
  69. }
  70. }
  71. }
  72. if (ibft_addr) {
  73. *sizep = PAGE_ALIGN(len);
  74. return pos;
  75. }
  76. *sizep = 0;
  77. return 0;
  78. }