io.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
  4. */
  5. #ifndef _ASM_IO_H
  6. #define _ASM_IO_H
  7. #define ARCH_HAS_IOREMAP_WC
  8. #include <linux/kernel.h>
  9. #include <linux/types.h>
  10. #include <asm/addrspace.h>
  11. #include <asm/cpu.h>
  12. #include <asm/page.h>
  13. #include <asm/pgtable-bits.h>
  14. #include <asm/string.h>
  15. /*
  16. * Change "struct page" to physical address.
  17. */
  18. #define page_to_phys(page) ((phys_addr_t)page_to_pfn(page) << PAGE_SHIFT)
  19. extern void __init __iomem *early_ioremap(u64 phys_addr, unsigned long size);
  20. extern void __init early_iounmap(void __iomem *addr, unsigned long size);
  21. #define early_memremap early_ioremap
  22. #define early_memunmap early_iounmap
  23. #ifdef CONFIG_ARCH_IOREMAP
  24. static inline void __iomem *ioremap_prot(phys_addr_t offset, unsigned long size,
  25. unsigned long prot_val)
  26. {
  27. if (prot_val & _CACHE_CC)
  28. return (void __iomem *)(unsigned long)(CACHE_BASE + offset);
  29. else
  30. return (void __iomem *)(unsigned long)(UNCACHE_BASE + offset);
  31. }
  32. #define ioremap(offset, size) \
  33. ioremap_prot((offset), (size), pgprot_val(PAGE_KERNEL_SUC))
  34. #define iounmap(addr) ((void)(addr))
  35. #endif
  36. /*
  37. * On LoongArch, ioremap() has two variants, ioremap_wc() and ioremap_cache().
  38. * They map bus memory into CPU space, the mapped memory is marked uncachable
  39. * (_CACHE_SUC), uncachable but accelerated by write-combine (_CACHE_WUC) and
  40. * cachable (_CACHE_CC) respectively for CPU access.
  41. *
  42. * @offset: bus address of the memory
  43. * @size: size of the resource to map
  44. */
  45. #define ioremap_wc(offset, size) \
  46. ioremap_prot((offset), (size), pgprot_val(PAGE_KERNEL_WUC))
  47. #define ioremap_cache(offset, size) \
  48. ioremap_prot((offset), (size), pgprot_val(PAGE_KERNEL))
  49. #define mmiowb() asm volatile ("dbar 0" ::: "memory")
  50. /*
  51. * String version of I/O memory access operations.
  52. */
  53. extern void __memset_io(volatile void __iomem *dst, int c, size_t count);
  54. extern void __memcpy_toio(volatile void __iomem *to, const void *from, size_t count);
  55. extern void __memcpy_fromio(void *to, const volatile void __iomem *from, size_t count);
  56. #define memset_io(c, v, l) __memset_io((c), (v), (l))
  57. #define memcpy_fromio(a, c, l) __memcpy_fromio((a), (c), (l))
  58. #define memcpy_toio(c, a, l) __memcpy_toio((c), (a), (l))
  59. #include <asm-generic/io.h>
  60. #define ARCH_HAS_VALID_PHYS_ADDR_RANGE
  61. extern int valid_phys_addr_range(phys_addr_t addr, size_t size);
  62. extern int valid_mmap_phys_addr_range(unsigned long pfn, size_t size);
  63. #endif /* _ASM_IO_H */