cache.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 2018 Free Software Foundation, Inc.
  4. *
  5. * GRUB is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * GRUB is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <grub/cache.h>
  19. #include <grub/misc.h>
  20. static grub_int64_t dlinesz;
  21. static grub_int64_t ilinesz;
  22. /* Prototypes for asm functions. */
  23. void grub_arch_clean_dcache_range (grub_addr_t beg, grub_addr_t end,
  24. grub_size_t line_size);
  25. void grub_arch_invalidate_icache_range (grub_addr_t beg, grub_addr_t end,
  26. grub_size_t line_size);
  27. static void
  28. probe_caches (void)
  29. {
  30. /* TODO */
  31. dlinesz = 32;
  32. ilinesz = 32;
  33. }
  34. void
  35. grub_arch_sync_caches (void *address, grub_size_t len)
  36. {
  37. grub_size_t start, end, max_align;
  38. if (dlinesz == 0)
  39. probe_caches();
  40. if (dlinesz == 0)
  41. grub_fatal ("Unknown cache line size!");
  42. max_align = dlinesz > ilinesz ? dlinesz : ilinesz;
  43. start = ALIGN_DOWN ((grub_size_t) address, max_align);
  44. end = ALIGN_UP ((grub_size_t) address + len, max_align);
  45. grub_arch_clean_dcache_range (start, end, dlinesz);
  46. grub_arch_invalidate_icache_range (start, end, ilinesz);
  47. }
  48. void
  49. grub_arch_sync_dma_caches (volatile void *address __attribute__((unused)),
  50. grub_size_t len __attribute__((unused)))
  51. {
  52. /* DMA incoherent devices not supported yet */
  53. }