iomap_32.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright © 2008 Ingo Molnar
  4. */
  5. #include <asm/iomap.h>
  6. #include <asm/memtype.h>
  7. #include <linux/export.h>
  8. #include <linux/highmem.h>
  9. static int is_io_mapping_possible(resource_size_t base, unsigned long size)
  10. {
  11. #if !defined(CONFIG_X86_PAE) && defined(CONFIG_PHYS_ADDR_T_64BIT)
  12. /* There is no way to map greater than 1 << 32 address without PAE */
  13. if (base + size > 0x100000000ULL)
  14. return 0;
  15. #endif
  16. return 1;
  17. }
  18. int iomap_create_wc(resource_size_t base, unsigned long size, pgprot_t *prot)
  19. {
  20. enum page_cache_mode pcm = _PAGE_CACHE_MODE_WC;
  21. int ret;
  22. if (!is_io_mapping_possible(base, size))
  23. return -EINVAL;
  24. ret = memtype_reserve_io(base, base + size, &pcm);
  25. if (ret)
  26. return ret;
  27. *prot = __pgprot(__PAGE_KERNEL | cachemode2protval(pcm));
  28. /* Filter out unsupported __PAGE_KERNEL* bits: */
  29. pgprot_val(*prot) &= __default_kernel_pte_mask;
  30. return 0;
  31. }
  32. EXPORT_SYMBOL_GPL(iomap_create_wc);
  33. void iomap_free(resource_size_t base, unsigned long size)
  34. {
  35. memtype_free_io(base, base + size);
  36. }
  37. EXPORT_SYMBOL_GPL(iomap_free);
  38. void __iomem *__iomap_local_pfn_prot(unsigned long pfn, pgprot_t prot)
  39. {
  40. /*
  41. * For non-PAT systems, translate non-WB request to UC- just in
  42. * case the caller set the PWT bit to prot directly without using
  43. * pgprot_writecombine(). UC- translates to uncached if the MTRR
  44. * is UC or WC. UC- gets the real intention, of the user, which is
  45. * "WC if the MTRR is WC, UC if you can't do that."
  46. */
  47. if (!pat_enabled() && pgprot2cachemode(prot) != _PAGE_CACHE_MODE_WB)
  48. prot = __pgprot(__PAGE_KERNEL |
  49. cachemode2protval(_PAGE_CACHE_MODE_UC_MINUS));
  50. /* Filter out unsupported __PAGE_KERNEL* bits: */
  51. pgprot_val(prot) &= __default_kernel_pte_mask;
  52. return (void __force __iomem *)__kmap_local_pfn_prot(pfn, prot);
  53. }
  54. EXPORT_SYMBOL_GPL(__iomap_local_pfn_prot);