probe_roms_32.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. #include <linux/sched.h>
  2. #include <linux/mm.h>
  3. #include <linux/uaccess.h>
  4. #include <linux/mmzone.h>
  5. #include <linux/ioport.h>
  6. #include <linux/seq_file.h>
  7. #include <linux/console.h>
  8. #include <linux/init.h>
  9. #include <linux/edd.h>
  10. #include <linux/dmi.h>
  11. #include <linux/pfn.h>
  12. #include <linux/pci.h>
  13. #include <asm/pci-direct.h>
  14. #include <asm/e820.h>
  15. #include <asm/mmzone.h>
  16. #include <asm/setup.h>
  17. #include <asm/sections.h>
  18. #include <asm/io.h>
  19. #include <asm/setup_arch.h>
  20. static struct resource system_rom_resource = {
  21. .name = "System ROM",
  22. .start = 0xf0000,
  23. .end = 0xfffff,
  24. .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
  25. };
  26. static struct resource extension_rom_resource = {
  27. .name = "Extension ROM",
  28. .start = 0xe0000,
  29. .end = 0xeffff,
  30. .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
  31. };
  32. static struct resource adapter_rom_resources[] = { {
  33. .name = "Adapter ROM",
  34. .start = 0xc8000,
  35. .end = 0,
  36. .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
  37. }, {
  38. .name = "Adapter ROM",
  39. .start = 0,
  40. .end = 0,
  41. .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
  42. }, {
  43. .name = "Adapter ROM",
  44. .start = 0,
  45. .end = 0,
  46. .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
  47. }, {
  48. .name = "Adapter ROM",
  49. .start = 0,
  50. .end = 0,
  51. .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
  52. }, {
  53. .name = "Adapter ROM",
  54. .start = 0,
  55. .end = 0,
  56. .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
  57. }, {
  58. .name = "Adapter ROM",
  59. .start = 0,
  60. .end = 0,
  61. .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
  62. } };
  63. static struct resource video_rom_resource = {
  64. .name = "Video ROM",
  65. .start = 0xc0000,
  66. .end = 0xc7fff,
  67. .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
  68. };
  69. #define ROMSIGNATURE 0xaa55
  70. static int __init romsignature(const unsigned char *rom)
  71. {
  72. const unsigned short * const ptr = (const unsigned short *)rom;
  73. unsigned short sig;
  74. return probe_kernel_address(ptr, sig) == 0 && sig == ROMSIGNATURE;
  75. }
  76. static int __init romchecksum(const unsigned char *rom, unsigned long length)
  77. {
  78. unsigned char sum, c;
  79. for (sum = 0; length && probe_kernel_address(rom++, c) == 0; length--)
  80. sum += c;
  81. return !length && !sum;
  82. }
  83. void __init probe_roms(void)
  84. {
  85. const unsigned char *rom;
  86. unsigned long start, length, upper;
  87. unsigned char c;
  88. int i;
  89. /* video rom */
  90. upper = adapter_rom_resources[0].start;
  91. for (start = video_rom_resource.start; start < upper; start += 2048) {
  92. rom = isa_bus_to_virt(start);
  93. if (!romsignature(rom))
  94. continue;
  95. video_rom_resource.start = start;
  96. if (probe_kernel_address(rom + 2, c) != 0)
  97. continue;
  98. /* 0 < length <= 0x7f * 512, historically */
  99. length = c * 512;
  100. /* if checksum okay, trust length byte */
  101. if (length && romchecksum(rom, length))
  102. video_rom_resource.end = start + length - 1;
  103. request_resource(&iomem_resource, &video_rom_resource);
  104. break;
  105. }
  106. start = (video_rom_resource.end + 1 + 2047) & ~2047UL;
  107. if (start < upper)
  108. start = upper;
  109. /* system rom */
  110. request_resource(&iomem_resource, &system_rom_resource);
  111. upper = system_rom_resource.start;
  112. /* check for extension rom (ignore length byte!) */
  113. rom = isa_bus_to_virt(extension_rom_resource.start);
  114. if (romsignature(rom)) {
  115. length = extension_rom_resource.end - extension_rom_resource.start + 1;
  116. if (romchecksum(rom, length)) {
  117. request_resource(&iomem_resource, &extension_rom_resource);
  118. upper = extension_rom_resource.start;
  119. }
  120. }
  121. /* check for adapter roms on 2k boundaries */
  122. for (i = 0; i < ARRAY_SIZE(adapter_rom_resources) && start < upper; start += 2048) {
  123. rom = isa_bus_to_virt(start);
  124. if (!romsignature(rom))
  125. continue;
  126. if (probe_kernel_address(rom + 2, c) != 0)
  127. continue;
  128. /* 0 < length <= 0x7f * 512, historically */
  129. length = c * 512;
  130. /* but accept any length that fits if checksum okay */
  131. if (!length || start + length > upper || !romchecksum(rom, length))
  132. continue;
  133. adapter_rom_resources[i].start = start;
  134. adapter_rom_resources[i].end = start + length - 1;
  135. request_resource(&iomem_resource, &adapter_rom_resources[i]);
  136. start = adapter_rom_resources[i++].end & ~2047UL;
  137. }
  138. }