iscsi_ibft_find.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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/slab.h>
  30. #include <linux/stat.h>
  31. #include <linux/string.h>
  32. #include <linux/types.h>
  33. #include <asm/mmzone.h>
  34. /*
  35. * Physical location of iSCSI Boot Format Table.
  36. */
  37. struct ibft_table_header *ibft_addr;
  38. EXPORT_SYMBOL_GPL(ibft_addr);
  39. #define IBFT_SIGN "iBFT"
  40. #define IBFT_SIGN_LEN 4
  41. #define IBFT_START 0x80000 /* 512kB */
  42. #define IBFT_END 0x100000 /* 1MB */
  43. #define VGA_MEM 0xA0000 /* VGA buffer */
  44. #define VGA_SIZE 0x20000 /* 128kB */
  45. /*
  46. * Routine used to find the iSCSI Boot Format Table. The logical
  47. * kernel address is set in the ibft_addr global variable.
  48. */
  49. void __init reserve_ibft_region(void)
  50. {
  51. unsigned long pos;
  52. unsigned int len = 0;
  53. void *virt;
  54. ibft_addr = NULL;
  55. for (pos = IBFT_START; pos < IBFT_END; pos += 16) {
  56. /* The table can't be inside the VGA BIOS reserved space,
  57. * so skip that area */
  58. if (pos == VGA_MEM)
  59. pos += VGA_SIZE;
  60. virt = phys_to_virt(pos);
  61. if (memcmp(virt, IBFT_SIGN, IBFT_SIGN_LEN) == 0) {
  62. unsigned long *addr =
  63. (unsigned long *)phys_to_virt(pos + 4);
  64. len = *addr;
  65. /* if the length of the table extends past 1M,
  66. * the table cannot be valid. */
  67. if (pos + len <= (IBFT_END-1)) {
  68. ibft_addr = (struct ibft_table_header *)virt;
  69. break;
  70. }
  71. }
  72. }
  73. if (ibft_addr)
  74. reserve_bootmem(pos, PAGE_ALIGN(len), BOOTMEM_DEFAULT);
  75. }