addrspace.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright (C) 2006 Atmel Corporation
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #ifndef __ASM_AVR32_ADDRSPACE_H
  7. #define __ASM_AVR32_ADDRSPACE_H
  8. #include <asm/types.h>
  9. /* Memory segments when segmentation is enabled */
  10. #define P0SEG 0x00000000
  11. #define P1SEG 0x80000000
  12. #define P2SEG 0xa0000000
  13. #define P3SEG 0xc0000000
  14. #define P4SEG 0xe0000000
  15. /* Returns the privileged segment base of a given address */
  16. #define PXSEG(a) (((unsigned long)(a)) & 0xe0000000)
  17. /* Returns the physical address of a PnSEG (n=1,2) address */
  18. #define PHYSADDR(a) (((unsigned long)(a)) & 0x1fffffff)
  19. /*
  20. * Map an address to a certain privileged segment
  21. */
  22. #define P1SEGADDR(a) ((__typeof__(a))(((unsigned long)(a) & 0x1fffffff) | P1SEG))
  23. #define P2SEGADDR(a) ((__typeof__(a))(((unsigned long)(a) & 0x1fffffff) | P2SEG))
  24. #define P3SEGADDR(a) ((__typeof__(a))(((unsigned long)(a) & 0x1fffffff) | P3SEG))
  25. #define P4SEGADDR(a) ((__typeof__(a))(((unsigned long)(a) & 0x1fffffff) | P4SEG))
  26. /* virt_to_phys will only work when address is in P1 or P2 */
  27. static inline unsigned long virt_to_phys(volatile void *address)
  28. {
  29. return PHYSADDR(address);
  30. }
  31. static inline void * phys_to_virt(unsigned long address)
  32. {
  33. return (void *)P1SEGADDR(address);
  34. }
  35. #define cached(addr) ((void *)P1SEGADDR(addr))
  36. #define uncached(addr) ((void *)P2SEGADDR(addr))
  37. /*
  38. * Given a physical address and a length, return a virtual address
  39. * that can be used to access the memory range with the caching
  40. * properties specified by "flags".
  41. *
  42. * This implementation works for memory below 512MiB (flash, etc.) as
  43. * well as above 3.5GiB (internal peripherals.)
  44. */
  45. #define MAP_NOCACHE (0)
  46. #define MAP_WRCOMBINE (1 << 7)
  47. #define MAP_WRBACK (MAP_WRCOMBINE | (1 << 9))
  48. #define MAP_WRTHROUGH (MAP_WRBACK | (1 << 0))
  49. static inline void *
  50. map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
  51. {
  52. return (void *)paddr;
  53. }
  54. #endif /* __ASM_AVR32_ADDRSPACE_H */