cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

dma-mapping.h (4714B)


      1/* SPDX-License-Identifier: GPL-2.0 */
      2#ifndef ASMARM_DMA_MAPPING_H
      3#define ASMARM_DMA_MAPPING_H
      4
      5#ifdef __KERNEL__
      6
      7#include <linux/mm_types.h>
      8#include <linux/scatterlist.h>
      9
     10#include <xen/xen.h>
     11#include <asm/xen/hypervisor.h>
     12
     13extern const struct dma_map_ops arm_dma_ops;
     14extern const struct dma_map_ops arm_coherent_dma_ops;
     15
     16static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus)
     17{
     18	if (IS_ENABLED(CONFIG_MMU) && !IS_ENABLED(CONFIG_ARM_LPAE))
     19		return &arm_dma_ops;
     20	return NULL;
     21}
     22
     23/**
     24 * arm_dma_alloc - allocate consistent memory for DMA
     25 * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
     26 * @size: required memory size
     27 * @handle: bus-specific DMA address
     28 * @attrs: optinal attributes that specific mapping properties
     29 *
     30 * Allocate some memory for a device for performing DMA.  This function
     31 * allocates pages, and will return the CPU-viewed address, and sets @handle
     32 * to be the device-viewed address.
     33 */
     34extern void *arm_dma_alloc(struct device *dev, size_t size, dma_addr_t *handle,
     35			   gfp_t gfp, unsigned long attrs);
     36
     37/**
     38 * arm_dma_free - free memory allocated by arm_dma_alloc
     39 * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
     40 * @size: size of memory originally requested in dma_alloc_coherent
     41 * @cpu_addr: CPU-view address returned from dma_alloc_coherent
     42 * @handle: device-view address returned from dma_alloc_coherent
     43 * @attrs: optinal attributes that specific mapping properties
     44 *
     45 * Free (and unmap) a DMA buffer previously allocated by
     46 * arm_dma_alloc().
     47 *
     48 * References to memory and mappings associated with cpu_addr/handle
     49 * during and after this call executing are illegal.
     50 */
     51extern void arm_dma_free(struct device *dev, size_t size, void *cpu_addr,
     52			 dma_addr_t handle, unsigned long attrs);
     53
     54/**
     55 * arm_dma_mmap - map a coherent DMA allocation into user space
     56 * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
     57 * @vma: vm_area_struct describing requested user mapping
     58 * @cpu_addr: kernel CPU-view address returned from dma_alloc_coherent
     59 * @handle: device-view address returned from dma_alloc_coherent
     60 * @size: size of memory originally requested in dma_alloc_coherent
     61 * @attrs: optinal attributes that specific mapping properties
     62 *
     63 * Map a coherent DMA buffer previously allocated by dma_alloc_coherent
     64 * into user space.  The coherent DMA buffer must not be freed by the
     65 * driver until the user space mapping has been released.
     66 */
     67extern int arm_dma_mmap(struct device *dev, struct vm_area_struct *vma,
     68			void *cpu_addr, dma_addr_t dma_addr, size_t size,
     69			unsigned long attrs);
     70
     71/*
     72 * For SA-1111, IXP425, and ADI systems  the dma-mapping functions are "magic"
     73 * and utilize bounce buffers as needed to work around limited DMA windows.
     74 *
     75 * On the SA-1111, a bug limits DMA to only certain regions of RAM.
     76 * On the IXP425, the PCI inbound window is 64MB (256MB total RAM)
     77 * On some ADI engineering systems, PCI inbound window is 32MB (12MB total RAM)
     78 *
     79 * The following are helper functions used by the dmabounce subystem
     80 *
     81 */
     82
     83/**
     84 * dmabounce_register_dev
     85 *
     86 * @dev: valid struct device pointer
     87 * @small_buf_size: size of buffers to use with small buffer pool
     88 * @large_buf_size: size of buffers to use with large buffer pool (can be 0)
     89 * @needs_bounce_fn: called to determine whether buffer needs bouncing
     90 *
     91 * This function should be called by low-level platform code to register
     92 * a device as requireing DMA buffer bouncing. The function will allocate
     93 * appropriate DMA pools for the device.
     94 */
     95extern int dmabounce_register_dev(struct device *, unsigned long,
     96		unsigned long, int (*)(struct device *, dma_addr_t, size_t));
     97
     98/**
     99 * dmabounce_unregister_dev
    100 *
    101 * @dev: valid struct device pointer
    102 *
    103 * This function should be called by low-level platform code when device
    104 * that was previously registered with dmabounce_register_dev is removed
    105 * from the system.
    106 *
    107 */
    108extern void dmabounce_unregister_dev(struct device *);
    109
    110
    111
    112/*
    113 * The scatter list versions of the above methods.
    114 */
    115extern int arm_dma_map_sg(struct device *, struct scatterlist *, int,
    116		enum dma_data_direction, unsigned long attrs);
    117extern void arm_dma_unmap_sg(struct device *, struct scatterlist *, int,
    118		enum dma_data_direction, unsigned long attrs);
    119extern void arm_dma_sync_sg_for_cpu(struct device *, struct scatterlist *, int,
    120		enum dma_data_direction);
    121extern void arm_dma_sync_sg_for_device(struct device *, struct scatterlist *, int,
    122		enum dma_data_direction);
    123extern int arm_dma_get_sgtable(struct device *dev, struct sg_table *sgt,
    124		void *cpu_addr, dma_addr_t dma_addr, size_t size,
    125		unsigned long attrs);
    126
    127#endif /* __KERNEL__ */
    128#endif