xref: /dflybsd-src/sys/dev/drm/linux_dma.c (revision 9eb960773498463a0345970327518dc99f07e96b)
18eafc851SFrançois Tigeot /*
28eafc851SFrançois Tigeot  * Copyright (c) 2016 Sascha Wildner <saw@online.de>
38eafc851SFrançois Tigeot  * All rights reserved.
48eafc851SFrançois Tigeot  *
58eafc851SFrançois Tigeot  * Redistribution and use in source and binary forms, with or without
68eafc851SFrançois Tigeot  * modification, are permitted provided that the following conditions
78eafc851SFrançois Tigeot  * are met:
88eafc851SFrançois Tigeot  * 1. Redistributions of source code must retain the above copyright
98eafc851SFrançois Tigeot  *    notice unmodified, this list of conditions, and the following
108eafc851SFrançois Tigeot  *    disclaimer.
118eafc851SFrançois Tigeot  * 2. Redistributions in binary form must reproduce the above copyright
128eafc851SFrançois Tigeot  *    notice, this list of conditions and the following disclaimer in the
138eafc851SFrançois Tigeot  *    documentation and/or other materials provided with the distribution.
148eafc851SFrançois Tigeot  *
158eafc851SFrançois Tigeot  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
168eafc851SFrançois Tigeot  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
178eafc851SFrançois Tigeot  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
188eafc851SFrançois Tigeot  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
198eafc851SFrançois Tigeot  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
208eafc851SFrançois Tigeot  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
218eafc851SFrançois Tigeot  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
228eafc851SFrançois Tigeot  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
238eafc851SFrançois Tigeot  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
248eafc851SFrançois Tigeot  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
258eafc851SFrançois Tigeot  */
268eafc851SFrançois Tigeot 
278eafc851SFrançois Tigeot #include <linux/dma-mapping.h>
288eafc851SFrançois Tigeot 
298eafc851SFrançois Tigeot #include <vm/vm_extern.h>
308eafc851SFrançois Tigeot 
318eafc851SFrançois Tigeot void *
dma_alloc_coherent(struct device * dev,size_t size,dma_addr_t * dma_handle,gfp_t flag)328eafc851SFrançois Tigeot dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
338eafc851SFrançois Tigeot     gfp_t flag)
348eafc851SFrançois Tigeot {
358eafc851SFrançois Tigeot 	vm_paddr_t high;
368eafc851SFrançois Tigeot 	size_t align;
378eafc851SFrançois Tigeot 	void *mem;
388eafc851SFrançois Tigeot 
398eafc851SFrançois Tigeot #if 0 /* XXX swildner */
408eafc851SFrançois Tigeot 	if (dev->dma_mask)
418eafc851SFrançois Tigeot 		high = *dev->dma_mask;
428eafc851SFrançois Tigeot 	else
438eafc851SFrançois Tigeot #endif
448eafc851SFrançois Tigeot 		high = BUS_SPACE_MAXADDR_32BIT;
458eafc851SFrançois Tigeot 	align = PAGE_SIZE << get_order(size);
468eafc851SFrançois Tigeot 	mem = (void *)kmem_alloc_contig(size, 0, high, align);
478eafc851SFrançois Tigeot 	if (mem)
488eafc851SFrançois Tigeot 		*dma_handle = vtophys(mem);
498eafc851SFrançois Tigeot 	else
508eafc851SFrançois Tigeot 		*dma_handle = 0;
518eafc851SFrançois Tigeot 	return (mem);
528eafc851SFrançois Tigeot }
538eafc851SFrançois Tigeot 
548eafc851SFrançois Tigeot void
dma_free_coherent(struct device * dev,size_t size,void * cpu_addr,dma_addr_t dma_handle)558eafc851SFrançois Tigeot dma_free_coherent(struct device *dev, size_t size, void *cpu_addr,
568eafc851SFrançois Tigeot     dma_addr_t dma_handle)
578eafc851SFrançois Tigeot {
588eafc851SFrançois Tigeot 
59*9eb96077SSergey Zigachev 	kmem_free(kernel_map, (vm_offset_t)cpu_addr, size);
608eafc851SFrançois Tigeot }
61