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