Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Paul Burton | 01b7a9b | 2017-09-14 15:05:01 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Generic I/O functions. |
| 4 | * |
| 5 | * Copyright (c) 2016 Imagination Technologies Ltd. |
Paul Burton | 01b7a9b | 2017-09-14 15:05:01 -0700 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #ifndef __ASM_GENERIC_IO_H__ |
| 9 | #define __ASM_GENERIC_IO_H__ |
| 10 | |
| 11 | /* |
| 12 | * This file should be included at the end of each architecture-specific |
| 13 | * asm/io.h such that we may provide generic implementations without |
| 14 | * conflicting with architecture-specific code. |
| 15 | */ |
| 16 | |
| 17 | #ifndef __ASSEMBLY__ |
| 18 | |
| 19 | /** |
| 20 | * phys_to_virt() - Return a virtual address mapped to a given physical address |
| 21 | * @paddr: the physical address |
| 22 | * |
| 23 | * Returns a virtual address which the CPU can access that maps to the physical |
| 24 | * address @paddr. This should only be used where it is known that no dynamic |
| 25 | * mapping is required. In general, map_physmem should be used instead. |
| 26 | * |
| 27 | * Returns: a virtual address which maps to @paddr |
| 28 | */ |
| 29 | #ifndef phys_to_virt |
| 30 | static inline void *phys_to_virt(phys_addr_t paddr) |
| 31 | { |
| 32 | return (void *)(unsigned long)paddr; |
| 33 | } |
| 34 | #endif |
| 35 | |
| 36 | /** |
| 37 | * virt_to_phys() - Return the physical address that a virtual address maps to |
| 38 | * @vaddr: the virtual address |
| 39 | * |
| 40 | * Returns the physical address which the CPU-accessible virtual address @vaddr |
| 41 | * maps to. |
| 42 | * |
| 43 | * Returns: the physical address which @vaddr maps to |
| 44 | */ |
| 45 | #ifndef virt_to_phys |
| 46 | static inline phys_addr_t virt_to_phys(void *vaddr) |
| 47 | { |
| 48 | return (phys_addr_t)((unsigned long)vaddr); |
| 49 | } |
| 50 | #endif |
| 51 | |
| 52 | /* |
| 53 | * Flags for use with map_physmem() & unmap_physmem(). Architectures need not |
| 54 | * support all of these, in which case they will be defined as zero here & |
| 55 | * ignored. Callers that may run on multiple architectures should therefore |
| 56 | * treat them as hints rather than requirements. |
| 57 | */ |
| 58 | #ifndef MAP_NOCACHE |
| 59 | # define MAP_NOCACHE 0 /* Produce an uncached mapping */ |
| 60 | #endif |
| 61 | #ifndef MAP_WRCOMBINE |
| 62 | # define MAP_WRCOMBINE 0 /* Allow write-combining on the mapping */ |
| 63 | #endif |
| 64 | #ifndef MAP_WRBACK |
| 65 | # define MAP_WRBACK 0 /* Map using write-back caching */ |
| 66 | #endif |
| 67 | #ifndef MAP_WRTHROUGH |
| 68 | # define MAP_WRTHROUGH 0 /* Map using write-through caching */ |
| 69 | #endif |
| 70 | |
| 71 | /** |
| 72 | * map_physmem() - Return a virtual address mapped to a given physical address |
| 73 | * @paddr: the physical address |
| 74 | * @len: the length of the required mapping |
| 75 | * @flags: flags affecting the type of mapping |
| 76 | * |
| 77 | * Return a virtual address through which the CPU may access the memory at |
| 78 | * physical address @paddr. The mapping will be valid for at least @len bytes, |
| 79 | * and may be affected by flags passed to the @flags argument. This function |
| 80 | * may create new mappings, so should generally be paired with a matching call |
| 81 | * to unmap_physmem once the caller is finished with the memory in question. |
| 82 | * |
| 83 | * Returns: a virtual address suitably mapped to @paddr |
| 84 | */ |
| 85 | #ifndef map_physmem |
| 86 | static inline void *map_physmem(phys_addr_t paddr, unsigned long len, |
| 87 | unsigned long flags) |
| 88 | { |
| 89 | return phys_to_virt(paddr); |
| 90 | } |
| 91 | #endif |
| 92 | |
| 93 | /** |
| 94 | * unmap_physmem() - Remove mappings created by a prior call to map_physmem() |
| 95 | * @vaddr: the virtual address which map_physmem() previously returned |
| 96 | * @flags: flags matching those originally passed to map_physmem() |
| 97 | * |
| 98 | * Unmap memory which was previously mapped by a call to map_physmem(). If |
| 99 | * map_physmem() dynamically created a mapping for the memory in question then |
| 100 | * unmap_physmem() will remove that mapping. |
| 101 | */ |
| 102 | #ifndef unmap_physmem |
| 103 | static inline void unmap_physmem(void *vaddr, unsigned long flags) |
| 104 | { |
| 105 | } |
| 106 | #endif |
| 107 | |
| 108 | #endif /* !__ASSEMBLY__ */ |
| 109 | #endif /* __ASM_GENERIC_IO_H__ */ |