Path: blob/master/arch/microblaze/include/asm/dma-mapping.h
15126 views
/*1* Implements the generic device dma API for microblaze and the pci2*3* Copyright (C) 2009-2010 Michal Simek <[email protected]>4* Copyright (C) 2009-2010 PetaLogix5*6* This file is subject to the terms and conditions of the GNU General7* Public License. See the file COPYING in the main directory of this8* archive for more details.9*10* This file is base on powerpc and x86 dma-mapping.h versions11* Copyright (C) 2004 IBM12*/1314#ifndef _ASM_MICROBLAZE_DMA_MAPPING_H15#define _ASM_MICROBLAZE_DMA_MAPPING_H1617/*18* See Documentation/PCI/PCI-DMA-mapping.txt and19* Documentation/DMA-API.txt for documentation.20*/2122#include <linux/types.h>23#include <linux/cache.h>24#include <linux/mm.h>25#include <linux/scatterlist.h>26#include <linux/dma-debug.h>27#include <linux/dma-attrs.h>28#include <asm/io.h>29#include <asm-generic/dma-coherent.h>3031#define DMA_ERROR_CODE (~(dma_addr_t)0x0)3233#define __dma_alloc_coherent(dev, gfp, size, handle) NULL34#define __dma_free_coherent(size, addr) ((void)0)35#define __dma_sync(addr, size, rw) ((void)0)3637static inline unsigned long device_to_mask(struct device *dev)38{39if (dev->dma_mask && *dev->dma_mask)40return *dev->dma_mask;41/* Assume devices without mask can take 32 bit addresses */42return 0xfffffffful;43}4445extern struct dma_map_ops *dma_ops;4647/*48* Available generic sets of operations49*/50extern struct dma_map_ops dma_direct_ops;5152static inline struct dma_map_ops *get_dma_ops(struct device *dev)53{54/* We don't handle the NULL dev case for ISA for now. We could55* do it via an out of line call but it is not needed for now. The56* only ISA DMA device we support is the floppy and we have a hack57* in the floppy driver directly to get a device for us.58*/59if (unlikely(!dev) || !dev->archdata.dma_ops)60return NULL;6162return dev->archdata.dma_ops;63}6465static inline void set_dma_ops(struct device *dev, struct dma_map_ops *ops)66{67dev->archdata.dma_ops = ops;68}6970static inline int dma_supported(struct device *dev, u64 mask)71{72struct dma_map_ops *ops = get_dma_ops(dev);7374if (unlikely(!ops))75return 0;76if (!ops->dma_supported)77return 1;78return ops->dma_supported(dev, mask);79}8081static inline int dma_set_mask(struct device *dev, u64 dma_mask)82{83struct dma_map_ops *ops = get_dma_ops(dev);8485if (unlikely(ops == NULL))86return -EIO;87if (ops->set_dma_mask)88return ops->set_dma_mask(dev, dma_mask);89if (!dev->dma_mask || !dma_supported(dev, dma_mask))90return -EIO;91*dev->dma_mask = dma_mask;92return 0;93}9495#include <asm-generic/dma-mapping-common.h>9697static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)98{99struct dma_map_ops *ops = get_dma_ops(dev);100if (ops->mapping_error)101return ops->mapping_error(dev, dma_addr);102103return (dma_addr == DMA_ERROR_CODE);104}105106#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)107#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)108109static inline void *dma_alloc_coherent(struct device *dev, size_t size,110dma_addr_t *dma_handle, gfp_t flag)111{112struct dma_map_ops *ops = get_dma_ops(dev);113void *memory;114115BUG_ON(!ops);116117memory = ops->alloc_coherent(dev, size, dma_handle, flag);118119debug_dma_alloc_coherent(dev, size, *dma_handle, memory);120return memory;121}122123static inline void dma_free_coherent(struct device *dev, size_t size,124void *cpu_addr, dma_addr_t dma_handle)125{126struct dma_map_ops *ops = get_dma_ops(dev);127128BUG_ON(!ops);129debug_dma_free_coherent(dev, size, cpu_addr, dma_handle);130ops->free_coherent(dev, size, cpu_addr, dma_handle);131}132133static inline void dma_cache_sync(struct device *dev, void *vaddr, size_t size,134enum dma_data_direction direction)135{136BUG_ON(direction == DMA_NONE);137__dma_sync(vaddr, size, (int)direction);138}139140#endif /* _ASM_MICROBLAZE_DMA_MAPPING_H */141142143