resource.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include <linux/ioport.h>
  2. #include <asm/e820.h>
  3. static void resource_clip(struct resource *res, resource_size_t start,
  4. resource_size_t end)
  5. {
  6. resource_size_t low = 0, high = 0;
  7. if (res->end < start || res->start > end)
  8. return; /* no conflict */
  9. if (res->start < start)
  10. low = start - res->start;
  11. if (res->end > end)
  12. high = res->end - end;
  13. /* Keep the area above or below the conflict, whichever is larger */
  14. if (low > high)
  15. res->end = start - 1;
  16. else
  17. res->start = end + 1;
  18. }
  19. static void remove_e820_regions(struct resource *avail)
  20. {
  21. int i;
  22. struct e820entry *entry;
  23. for (i = 0; i < e820.nr_map; i++) {
  24. entry = &e820.map[i];
  25. resource_clip(avail, entry->addr,
  26. entry->addr + entry->size - 1);
  27. }
  28. }
  29. void arch_remove_reservations(struct resource *avail)
  30. {
  31. /* Trim out BIOS areas (low 1MB and high 2MB) and E820 regions */
  32. if (avail->flags & IORESOURCE_MEM) {
  33. if (avail->start < BIOS_END)
  34. avail->start = BIOS_END;
  35. resource_clip(avail, BIOS_ROM_BASE, BIOS_ROM_END);
  36. remove_e820_regions(avail);
  37. }
  38. }