kmap.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * arch/sh/mm/kmap.c
  4. *
  5. * Copyright (C) 1999, 2000, 2002 Niibe Yutaka
  6. * Copyright (C) 2002 - 2009 Paul Mundt
  7. */
  8. #include <linux/mm.h>
  9. #include <linux/init.h>
  10. #include <linux/mutex.h>
  11. #include <linux/fs.h>
  12. #include <linux/highmem.h>
  13. #include <linux/module.h>
  14. #include <asm/mmu_context.h>
  15. #include <asm/cacheflush.h>
  16. static pte_t *kmap_coherent_pte;
  17. void __init kmap_coherent_init(void)
  18. {
  19. unsigned long vaddr;
  20. /* cache the first coherent kmap pte */
  21. vaddr = __fix_to_virt(FIX_CMAP_BEGIN);
  22. kmap_coherent_pte = virt_to_kpte(vaddr);
  23. }
  24. void *kmap_coherent(struct page *page, unsigned long addr)
  25. {
  26. enum fixed_addresses idx;
  27. unsigned long vaddr;
  28. BUG_ON(!test_bit(PG_dcache_clean, &page->flags));
  29. preempt_disable();
  30. pagefault_disable();
  31. idx = FIX_CMAP_END -
  32. (((addr >> PAGE_SHIFT) & (FIX_N_COLOURS - 1)) +
  33. (FIX_N_COLOURS * smp_processor_id()));
  34. vaddr = __fix_to_virt(idx);
  35. BUG_ON(!pte_none(*(kmap_coherent_pte - idx)));
  36. set_pte(kmap_coherent_pte - idx, mk_pte(page, PAGE_KERNEL));
  37. return (void *)vaddr;
  38. }
  39. void kunmap_coherent(void *kvaddr)
  40. {
  41. if (kvaddr >= (void *)FIXADDR_START) {
  42. unsigned long vaddr = (unsigned long)kvaddr & PAGE_MASK;
  43. enum fixed_addresses idx = __virt_to_fix(vaddr);
  44. /* XXX.. Kill this later, here for sanity at the moment.. */
  45. __flush_purge_region((void *)vaddr, PAGE_SIZE);
  46. pte_clear(&init_mm, vaddr, kmap_coherent_pte - idx);
  47. local_flush_tlb_one(get_asid(), vaddr);
  48. }
  49. pagefault_enable();
  50. preempt_enable();
  51. }