resource.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/ioport.h>
  3. #include <asm/e820/api.h>
  4. static void resource_clip(struct resource *res, resource_size_t start,
  5. resource_size_t end)
  6. {
  7. resource_size_t low = 0, high = 0;
  8. if (res->end < start || res->start > end)
  9. return; /* no conflict */
  10. if (res->start < start)
  11. low = start - res->start;
  12. if (res->end > end)
  13. high = res->end - end;
  14. /* Keep the area above or below the conflict, whichever is larger */
  15. if (low > high)
  16. res->end = start - 1;
  17. else
  18. res->start = end + 1;
  19. }
  20. static void remove_e820_regions(struct resource *avail)
  21. {
  22. int i;
  23. struct e820_entry *entry;
  24. for (i = 0; i < e820_table->nr_entries; i++) {
  25. entry = &e820_table->entries[i];
  26. resource_clip(avail, entry->addr,
  27. entry->addr + entry->size - 1);
  28. }
  29. }
  30. void arch_remove_reservations(struct resource *avail)
  31. {
  32. /*
  33. * Trim out BIOS area (high 2MB) and E820 regions. We do not remove
  34. * the low 1MB unconditionally, as this area is needed for some ISA
  35. * cards requiring a memory range, e.g. the i82365 PCMCIA controller.
  36. */
  37. if (avail->flags & IORESOURCE_MEM) {
  38. resource_clip(avail, BIOS_ROM_BASE, BIOS_ROM_END);
  39. remove_e820_regions(avail);
  40. }
  41. }