Back to home page

LXR

 
 

    


0001 /*
0002  *  lib/dma-noop.c
0003  *
0004  * Simple DMA noop-ops that map 1:1 with memory
0005  */
0006 #include <linux/export.h>
0007 #include <linux/mm.h>
0008 #include <linux/dma-mapping.h>
0009 #include <linux/scatterlist.h>
0010 
0011 static void *dma_noop_alloc(struct device *dev, size_t size,
0012                 dma_addr_t *dma_handle, gfp_t gfp,
0013                 unsigned long attrs)
0014 {
0015     void *ret;
0016 
0017     ret = (void *)__get_free_pages(gfp, get_order(size));
0018     if (ret)
0019         *dma_handle = virt_to_phys(ret);
0020     return ret;
0021 }
0022 
0023 static void dma_noop_free(struct device *dev, size_t size,
0024               void *cpu_addr, dma_addr_t dma_addr,
0025               unsigned long attrs)
0026 {
0027     free_pages((unsigned long)cpu_addr, get_order(size));
0028 }
0029 
0030 static dma_addr_t dma_noop_map_page(struct device *dev, struct page *page,
0031                       unsigned long offset, size_t size,
0032                       enum dma_data_direction dir,
0033                       unsigned long attrs)
0034 {
0035     return page_to_phys(page) + offset;
0036 }
0037 
0038 static int dma_noop_map_sg(struct device *dev, struct scatterlist *sgl, int nents,
0039                  enum dma_data_direction dir,
0040                  unsigned long attrs)
0041 {
0042     int i;
0043     struct scatterlist *sg;
0044 
0045     for_each_sg(sgl, sg, nents, i) {
0046         void *va;
0047 
0048         BUG_ON(!sg_page(sg));
0049         va = sg_virt(sg);
0050         sg_dma_address(sg) = (dma_addr_t)virt_to_phys(va);
0051         sg_dma_len(sg) = sg->length;
0052     }
0053 
0054     return nents;
0055 }
0056 
0057 static int dma_noop_mapping_error(struct device *dev, dma_addr_t dma_addr)
0058 {
0059     return 0;
0060 }
0061 
0062 static int dma_noop_supported(struct device *dev, u64 mask)
0063 {
0064     return 1;
0065 }
0066 
0067 struct dma_map_ops dma_noop_ops = {
0068     .alloc          = dma_noop_alloc,
0069     .free           = dma_noop_free,
0070     .map_page       = dma_noop_map_page,
0071     .map_sg         = dma_noop_map_sg,
0072     .mapping_error      = dma_noop_mapping_error,
0073     .dma_supported      = dma_noop_supported,
0074 };
0075 
0076 EXPORT_SYMBOL(dma_noop_ops);