pci-dma.c 15.9 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4
/*
** PARISC 1.1 Dynamic DMA mapping support.
** This implementation is for PA-RISC platforms that do not support
** I/O TLBs (aka DMA address translation hardware).
P
Paul Bolle 已提交
5
** See Documentation/DMA-API-HOWTO.txt for interface definitions.
L
Linus Torvalds 已提交
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
**
**      (c) Copyright 1999,2000 Hewlett-Packard Company
**      (c) Copyright 2000 Grant Grundler
**	(c) Copyright 2000 Philipp Rumpf <prumpf@tux.org>
**      (c) Copyright 2000 John Marvin
**
** "leveraged" from 2.3.47: arch/ia64/kernel/pci-dma.c.
** (I assume it's from David Mosberger-Tang but there was no Copyright)
**
** AFAIK, all PA7100LC and PA7300LC platforms can use this code.
**
** - ggg
*/

#include <linux/init.h>
21
#include <linux/gfp.h>
L
Linus Torvalds 已提交
22 23 24
#include <linux/mm.h>
#include <linux/pci.h>
#include <linux/proc_fs.h>
25
#include <linux/seq_file.h>
L
Linus Torvalds 已提交
26 27
#include <linux/string.h>
#include <linux/types.h>
F
FUJITA Tomonori 已提交
28
#include <linux/scatterlist.h>
29
#include <linux/export.h>
L
Linus Torvalds 已提交
30 31 32 33 34 35

#include <asm/cacheflush.h>
#include <asm/dma.h>    /* for DMA_CHUNK_SIZE */
#include <asm/io.h>
#include <asm/page.h>	/* get_order */
#include <asm/pgalloc.h>
36
#include <linux/uaccess.h>
37
#include <asm/tlbflush.h>	/* for purge_tlb_*() macros */
L
Linus Torvalds 已提交
38

39 40 41
static struct proc_dir_entry * proc_gsc_root __read_mostly = NULL;
static unsigned long pcxl_used_bytes __read_mostly = 0;
static unsigned long pcxl_used_pages __read_mostly = 0;
L
Linus Torvalds 已提交
42 43

extern unsigned long pcxl_dma_start; /* Start of pcxl dma mapping area */
44
static DEFINE_SPINLOCK(pcxl_res_lock);
L
Linus Torvalds 已提交
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
static char    *pcxl_res_map;
static int     pcxl_res_hint;
static int     pcxl_res_size;

#ifdef DEBUG_PCXL_RESOURCE
#define DBG_RES(x...)	printk(x)
#else
#define DBG_RES(x...)
#endif


/*
** Dump a hex representation of the resource map.
*/

#ifdef DUMP_RESMAP
static
void dump_resmap(void)
{
	u_long *res_ptr = (unsigned long *)pcxl_res_map;
	u_long i = 0;

	printk("res_map: ");
	for(; i < (pcxl_res_size / sizeof(unsigned long)); ++i, ++res_ptr)
		printk("%08lx ", *res_ptr);

	printk("\n");
}
#else
static inline void dump_resmap(void) {;}
#endif

static int pa11_dma_supported( struct device *dev, u64 mask)
{
	return 1;
}

static inline int map_pte_uncached(pte_t * pte,
		unsigned long vaddr,
		unsigned long size, unsigned long *paddr_ptr)
{
	unsigned long end;
	unsigned long orig_vaddr = vaddr;

	vaddr &= ~PMD_MASK;
	end = vaddr + size;
	if (end > PMD_SIZE)
		end = PMD_SIZE;
	do {
94 95
		unsigned long flags;

L
Linus Torvalds 已提交
96 97
		if (!pte_none(*pte))
			printk(KERN_ERR "map_pte_uncached: page already exists\n");
98
		purge_tlb_start(flags);
J
John David Anglin 已提交
99
		set_pte(pte, __mk_pte(*paddr_ptr, PAGE_KERNEL_UNC));
L
Linus Torvalds 已提交
100
		pdtlb_kernel(orig_vaddr);
101
		purge_tlb_end(flags);
L
Linus Torvalds 已提交
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
		vaddr += PAGE_SIZE;
		orig_vaddr += PAGE_SIZE;
		(*paddr_ptr) += PAGE_SIZE;
		pte++;
	} while (vaddr < end);
	return 0;
}

static inline int map_pmd_uncached(pmd_t * pmd, unsigned long vaddr,
		unsigned long size, unsigned long *paddr_ptr)
{
	unsigned long end;
	unsigned long orig_vaddr = vaddr;

	vaddr &= ~PGDIR_MASK;
	end = vaddr + size;
	if (end > PGDIR_SIZE)
		end = PGDIR_SIZE;
	do {
H
Hugh Dickins 已提交
121
		pte_t * pte = pte_alloc_kernel(pmd, vaddr);
L
Linus Torvalds 已提交
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
		if (!pte)
			return -ENOMEM;
		if (map_pte_uncached(pte, orig_vaddr, end - vaddr, paddr_ptr))
			return -ENOMEM;
		vaddr = (vaddr + PMD_SIZE) & PMD_MASK;
		orig_vaddr += PMD_SIZE;
		pmd++;
	} while (vaddr < end);
	return 0;
}

static inline int map_uncached_pages(unsigned long vaddr, unsigned long size,
		unsigned long paddr)
{
	pgd_t * dir;
	unsigned long end = vaddr + size;

	dir = pgd_offset_k(vaddr);
	do {
		pmd_t *pmd;
		
		pmd = pmd_alloc(NULL, dir, vaddr);
		if (!pmd)
			return -ENOMEM;
		if (map_pmd_uncached(pmd, vaddr, end - vaddr, &paddr))
			return -ENOMEM;
		vaddr = vaddr + PGDIR_SIZE;
		dir++;
	} while (vaddr && (vaddr < end));
	return 0;
}

static inline void unmap_uncached_pte(pmd_t * pmd, unsigned long vaddr,
		unsigned long size)
{
	pte_t * pte;
	unsigned long end;
	unsigned long orig_vaddr = vaddr;

	if (pmd_none(*pmd))
		return;
	if (pmd_bad(*pmd)) {
		pmd_ERROR(*pmd);
		pmd_clear(pmd);
		return;
	}
	pte = pte_offset_map(pmd, vaddr);
	vaddr &= ~PMD_MASK;
	end = vaddr + size;
	if (end > PMD_SIZE)
		end = PMD_SIZE;
	do {
174
		unsigned long flags;
L
Linus Torvalds 已提交
175
		pte_t page = *pte;
176

L
Linus Torvalds 已提交
177
		pte_clear(&init_mm, vaddr, pte);
178
		purge_tlb_start(flags);
L
Linus Torvalds 已提交
179
		pdtlb_kernel(orig_vaddr);
180
		purge_tlb_end(flags);
L
Linus Torvalds 已提交
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338
		vaddr += PAGE_SIZE;
		orig_vaddr += PAGE_SIZE;
		pte++;
		if (pte_none(page) || pte_present(page))
			continue;
		printk(KERN_CRIT "Whee.. Swapped out page in kernel page table\n");
	} while (vaddr < end);
}

static inline void unmap_uncached_pmd(pgd_t * dir, unsigned long vaddr,
		unsigned long size)
{
	pmd_t * pmd;
	unsigned long end;
	unsigned long orig_vaddr = vaddr;

	if (pgd_none(*dir))
		return;
	if (pgd_bad(*dir)) {
		pgd_ERROR(*dir);
		pgd_clear(dir);
		return;
	}
	pmd = pmd_offset(dir, vaddr);
	vaddr &= ~PGDIR_MASK;
	end = vaddr + size;
	if (end > PGDIR_SIZE)
		end = PGDIR_SIZE;
	do {
		unmap_uncached_pte(pmd, orig_vaddr, end - vaddr);
		vaddr = (vaddr + PMD_SIZE) & PMD_MASK;
		orig_vaddr += PMD_SIZE;
		pmd++;
	} while (vaddr < end);
}

static void unmap_uncached_pages(unsigned long vaddr, unsigned long size)
{
	pgd_t * dir;
	unsigned long end = vaddr + size;

	dir = pgd_offset_k(vaddr);
	do {
		unmap_uncached_pmd(dir, vaddr, end - vaddr);
		vaddr = vaddr + PGDIR_SIZE;
		dir++;
	} while (vaddr && (vaddr < end));
}

#define PCXL_SEARCH_LOOP(idx, mask, size)  \
       for(; res_ptr < res_end; ++res_ptr) \
       { \
               if(0 == ((*res_ptr) & mask)) { \
                       *res_ptr |= mask; \
		       idx = (int)((u_long)res_ptr - (u_long)pcxl_res_map); \
		       pcxl_res_hint = idx + (size >> 3); \
                       goto resource_found; \
               } \
       }

#define PCXL_FIND_FREE_MAPPING(idx, mask, size)  { \
       u##size *res_ptr = (u##size *)&(pcxl_res_map[pcxl_res_hint & ~((size >> 3) - 1)]); \
       u##size *res_end = (u##size *)&pcxl_res_map[pcxl_res_size]; \
       PCXL_SEARCH_LOOP(idx, mask, size); \
       res_ptr = (u##size *)&pcxl_res_map[0]; \
       PCXL_SEARCH_LOOP(idx, mask, size); \
}

unsigned long
pcxl_alloc_range(size_t size)
{
	int res_idx;
	u_long mask, flags;
	unsigned int pages_needed = size >> PAGE_SHIFT;

	mask = (u_long) -1L;
 	mask >>= BITS_PER_LONG - pages_needed;

	DBG_RES("pcxl_alloc_range() size: %d pages_needed %d pages_mask 0x%08lx\n", 
		size, pages_needed, mask);

	spin_lock_irqsave(&pcxl_res_lock, flags);

	if(pages_needed <= 8) {
		PCXL_FIND_FREE_MAPPING(res_idx, mask, 8);
	} else if(pages_needed <= 16) {
		PCXL_FIND_FREE_MAPPING(res_idx, mask, 16);
	} else if(pages_needed <= 32) {
		PCXL_FIND_FREE_MAPPING(res_idx, mask, 32);
	} else {
		panic("%s: pcxl_alloc_range() Too many pages to map.\n",
		      __FILE__);
	}

	dump_resmap();
	panic("%s: pcxl_alloc_range() out of dma mapping resources\n",
	      __FILE__);
	
resource_found:
	
	DBG_RES("pcxl_alloc_range() res_idx %d mask 0x%08lx res_hint: %d\n",
		res_idx, mask, pcxl_res_hint);

	pcxl_used_pages += pages_needed;
	pcxl_used_bytes += ((pages_needed >> 3) ? (pages_needed >> 3) : 1);

	spin_unlock_irqrestore(&pcxl_res_lock, flags);

	dump_resmap();

	/* 
	** return the corresponding vaddr in the pcxl dma map
	*/
	return (pcxl_dma_start + (res_idx << (PAGE_SHIFT + 3)));
}

#define PCXL_FREE_MAPPINGS(idx, m, size) \
		u##size *res_ptr = (u##size *)&(pcxl_res_map[(idx) + (((size >> 3) - 1) & (~((size >> 3) - 1)))]); \
		/* BUG_ON((*res_ptr & m) != m); */ \
		*res_ptr &= ~m;

/*
** clear bits in the pcxl resource map
*/
static void
pcxl_free_range(unsigned long vaddr, size_t size)
{
	u_long mask, flags;
	unsigned int res_idx = (vaddr - pcxl_dma_start) >> (PAGE_SHIFT + 3);
	unsigned int pages_mapped = size >> PAGE_SHIFT;

	mask = (u_long) -1L;
 	mask >>= BITS_PER_LONG - pages_mapped;

	DBG_RES("pcxl_free_range() res_idx: %d size: %d pages_mapped %d mask 0x%08lx\n", 
		res_idx, size, pages_mapped, mask);

	spin_lock_irqsave(&pcxl_res_lock, flags);

	if(pages_mapped <= 8) {
		PCXL_FREE_MAPPINGS(res_idx, mask, 8);
	} else if(pages_mapped <= 16) {
		PCXL_FREE_MAPPINGS(res_idx, mask, 16);
	} else if(pages_mapped <= 32) {
		PCXL_FREE_MAPPINGS(res_idx, mask, 32);
	} else {
		panic("%s: pcxl_free_range() Too many pages to unmap.\n",
		      __FILE__);
	}
	
	pcxl_used_pages -= (pages_mapped ? pages_mapped : 1);
	pcxl_used_bytes -= ((pages_mapped >> 3) ? (pages_mapped >> 3) : 1);

	spin_unlock_irqrestore(&pcxl_res_lock, flags);

	dump_resmap();
}

339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386
static int proc_pcxl_dma_show(struct seq_file *m, void *v)
{
#if 0
	u_long i = 0;
	unsigned long *res_ptr = (u_long *)pcxl_res_map;
#endif
	unsigned long total_pages = pcxl_res_size << 3;   /* 8 bits per byte */

	seq_printf(m, "\nDMA Mapping Area size    : %d bytes (%ld pages)\n",
		PCXL_DMA_MAP_SIZE, total_pages);

	seq_printf(m, "Resource bitmap : %d bytes\n", pcxl_res_size);

	seq_puts(m,  "     	  total:    free:    used:   % used:\n");
	seq_printf(m, "blocks  %8d %8ld %8ld %8ld%%\n", pcxl_res_size,
		pcxl_res_size - pcxl_used_bytes, pcxl_used_bytes,
		(pcxl_used_bytes * 100) / pcxl_res_size);

	seq_printf(m, "pages   %8ld %8ld %8ld %8ld%%\n", total_pages,
		total_pages - pcxl_used_pages, pcxl_used_pages,
		(pcxl_used_pages * 100 / total_pages));

#if 0
	seq_puts(m, "\nResource bitmap:");

	for(; i < (pcxl_res_size / sizeof(u_long)); ++i, ++res_ptr) {
		if ((i & 7) == 0)
		    seq_puts(m,"\n   ");
		seq_printf(m, "%s %08lx", buf, *res_ptr);
	}
#endif
	seq_putc(m, '\n');
	return 0;
}

static int proc_pcxl_dma_open(struct inode *inode, struct file *file)
{
	return single_open(file, proc_pcxl_dma_show, NULL);
}

static const struct file_operations proc_pcxl_dma_ops = {
	.owner		= THIS_MODULE,
	.open		= proc_pcxl_dma_open,
	.read		= seq_read,
	.llseek		= seq_lseek,
	.release	= single_release,
};

L
Linus Torvalds 已提交
387 388 389
static int __init
pcxl_dma_init(void)
{
390 391
	if (pcxl_dma_start == 0)
		return 0;
L
Linus Torvalds 已提交
392

393 394 395
	pcxl_res_size = PCXL_DMA_MAP_SIZE >> (PAGE_SHIFT + 3);
	pcxl_res_hint = 0;
	pcxl_res_map = (char *)__get_free_pages(GFP_KERNEL,
L
Linus Torvalds 已提交
396
					    get_order(pcxl_res_size));
397
	memset(pcxl_res_map, 0, pcxl_res_size);
M
Matthew Wilcox 已提交
398
	proc_gsc_root = proc_mkdir("gsc", NULL);
399 400 401 402 403
	if (!proc_gsc_root)
    		printk(KERN_WARNING
			"pcxl_dma_init: Unable to create gsc /proc dir entry\n");
	else {
		struct proc_dir_entry* ent;
404 405 406
		ent = proc_create("pcxl_dma", 0, proc_gsc_root,
				  &proc_pcxl_dma_ops);
		if (!ent)
407 408 409 410
			printk(KERN_WARNING
				"pci-dma.c: Unable to create pcxl_dma /proc entry.\n");
	}
	return 0;
L
Linus Torvalds 已提交
411 412 413 414
}

__initcall(pcxl_dma_init);

415
static void *pa11_dma_alloc(struct device *dev, size_t size,
416
		dma_addr_t *dma_handle, gfp_t flag, unsigned long attrs)
L
Linus Torvalds 已提交
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441
{
	unsigned long vaddr;
	unsigned long paddr;
	int order;

	order = get_order(size);
	size = 1 << (order + PAGE_SHIFT);
	vaddr = pcxl_alloc_range(size);
	paddr = __get_free_pages(flag, order);
	flush_kernel_dcache_range(paddr, size);
	paddr = __pa(paddr);
	map_uncached_pages(vaddr, size, paddr);
	*dma_handle = (dma_addr_t) paddr;

#if 0
/* This probably isn't needed to support EISA cards.
** ISA cards will certainly only support 24-bit DMA addressing.
** Not clear if we can, want, or need to support ISA.
*/
	if (!dev || *dev->coherent_dma_mask < 0xffffffff)
		gfp |= GFP_DMA;
#endif
	return (void *)vaddr;
}

442
static void pa11_dma_free(struct device *dev, size_t size, void *vaddr,
443
		dma_addr_t dma_handle, unsigned long attrs)
L
Linus Torvalds 已提交
444 445 446 447 448 449 450 451 452 453
{
	int order;

	order = get_order(size);
	size = 1 << (order + PAGE_SHIFT);
	unmap_uncached_pages((unsigned long)vaddr, size);
	pcxl_free_range((unsigned long)vaddr, size);
	free_pages((unsigned long)__va(dma_handle), order);
}

454 455
static dma_addr_t pa11_dma_map_page(struct device *dev, struct page *page,
		unsigned long offset, size_t size,
456
		enum dma_data_direction direction, unsigned long attrs)
L
Linus Torvalds 已提交
457
{
458
	void *addr = page_address(page) + offset;
H
Helge Deller 已提交
459
	BUG_ON(direction == DMA_NONE);
L
Linus Torvalds 已提交
460

461 462 463
	if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC))
		flush_kernel_dcache_range((unsigned long) addr, size);

L
Linus Torvalds 已提交
464 465 466
	return virt_to_phys(addr);
}

467 468
static void pa11_dma_unmap_page(struct device *dev, dma_addr_t dma_handle,
		size_t size, enum dma_data_direction direction,
469
		unsigned long attrs)
L
Linus Torvalds 已提交
470
{
H
Helge Deller 已提交
471
	BUG_ON(direction == DMA_NONE);
L
Linus Torvalds 已提交
472

473 474 475
	if (attrs & DMA_ATTR_SKIP_CPU_SYNC)
		return;

L
Linus Torvalds 已提交
476
	if (direction == DMA_TO_DEVICE)
477
		return;
L
Linus Torvalds 已提交
478 479 480 481 482 483 484 485 486 487

	/*
	 * For PCI_DMA_FROMDEVICE this flush is not necessary for the
	 * simple map/unmap case. However, it IS necessary if if
	 * pci_dma_sync_single_* has been called and the buffer reused.
	 */

	flush_kernel_dcache_range((unsigned long) phys_to_virt(dma_handle), size);
}

488 489
static int pa11_dma_map_sg(struct device *dev, struct scatterlist *sglist,
		int nents, enum dma_data_direction direction,
490
		unsigned long attrs)
L
Linus Torvalds 已提交
491 492
{
	int i;
A
Akinobu Mita 已提交
493
	struct scatterlist *sg;
L
Linus Torvalds 已提交
494

H
Helge Deller 已提交
495
	BUG_ON(direction == DMA_NONE);
L
Linus Torvalds 已提交
496

A
Akinobu Mita 已提交
497 498 499 500 501
	for_each_sg(sglist, sg, nents, i) {
		unsigned long vaddr = (unsigned long)sg_virt(sg);

		sg_dma_address(sg) = (dma_addr_t) virt_to_phys(vaddr);
		sg_dma_len(sg) = sg->length;
502 503 504 505

		if (attrs & DMA_ATTR_SKIP_CPU_SYNC)
			continue;

A
Akinobu Mita 已提交
506
		flush_kernel_dcache_range(vaddr, sg->length);
L
Linus Torvalds 已提交
507 508 509 510
	}
	return nents;
}

511 512
static void pa11_dma_unmap_sg(struct device *dev, struct scatterlist *sglist,
		int nents, enum dma_data_direction direction,
513
		unsigned long attrs)
L
Linus Torvalds 已提交
514 515
{
	int i;
A
Akinobu Mita 已提交
516
	struct scatterlist *sg;
L
Linus Torvalds 已提交
517

H
Helge Deller 已提交
518
	BUG_ON(direction == DMA_NONE);
L
Linus Torvalds 已提交
519

520 521 522
	if (attrs & DMA_ATTR_SKIP_CPU_SYNC)
		return;

L
Linus Torvalds 已提交
523
	if (direction == DMA_TO_DEVICE)
524
		return;
L
Linus Torvalds 已提交
525 526 527

	/* once we do combining we'll need to use phys_to_virt(sg_dma_address(sglist)) */

A
Akinobu Mita 已提交
528 529
	for_each_sg(sglist, sg, nents, i)
		flush_kernel_vmap_range(sg_virt(sg), sg->length);
L
Linus Torvalds 已提交
530 531
}

532 533 534
static void pa11_dma_sync_single_for_cpu(struct device *dev,
		dma_addr_t dma_handle, size_t size,
		enum dma_data_direction direction)
L
Linus Torvalds 已提交
535
{
H
Helge Deller 已提交
536
	BUG_ON(direction == DMA_NONE);
L
Linus Torvalds 已提交
537

538 539
	flush_kernel_dcache_range((unsigned long) phys_to_virt(dma_handle),
			size);
L
Linus Torvalds 已提交
540 541
}

542 543 544
static void pa11_dma_sync_single_for_device(struct device *dev,
		dma_addr_t dma_handle, size_t size,
		enum dma_data_direction direction)
L
Linus Torvalds 已提交
545
{
H
Helge Deller 已提交
546
	BUG_ON(direction == DMA_NONE);
L
Linus Torvalds 已提交
547

548 549
	flush_kernel_dcache_range((unsigned long) phys_to_virt(dma_handle),
			size);
L
Linus Torvalds 已提交
550 551 552 553 554
}

static void pa11_dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sglist, int nents, enum dma_data_direction direction)
{
	int i;
A
Akinobu Mita 已提交
555
	struct scatterlist *sg;
L
Linus Torvalds 已提交
556 557 558

	/* once we do combining we'll need to use phys_to_virt(sg_dma_address(sglist)) */

A
Akinobu Mita 已提交
559 560
	for_each_sg(sglist, sg, nents, i)
		flush_kernel_vmap_range(sg_virt(sg), sg->length);
L
Linus Torvalds 已提交
561 562 563 564 565
}

static void pa11_dma_sync_sg_for_device(struct device *dev, struct scatterlist *sglist, int nents, enum dma_data_direction direction)
{
	int i;
A
Akinobu Mita 已提交
566
	struct scatterlist *sg;
L
Linus Torvalds 已提交
567 568 569

	/* once we do combining we'll need to use phys_to_virt(sg_dma_address(sglist)) */

A
Akinobu Mita 已提交
570 571
	for_each_sg(sglist, sg, nents, i)
		flush_kernel_vmap_range(sg_virt(sg), sg->length);
L
Linus Torvalds 已提交
572 573
}

574 575 576 577 578 579
static void pa11_dma_cache_sync(struct device *dev, void *vaddr, size_t size,
	       enum dma_data_direction direction)
{
	flush_kernel_dcache_range((unsigned long)vaddr, size);
}

580
const struct dma_map_ops pcxl_dma_ops = {
L
Linus Torvalds 已提交
581
	.dma_supported =	pa11_dma_supported,
582 583 584 585
	.alloc =		pa11_dma_alloc,
	.free =			pa11_dma_free,
	.map_page =		pa11_dma_map_page,
	.unmap_page =		pa11_dma_unmap_page,
L
Linus Torvalds 已提交
586 587
	.map_sg =		pa11_dma_map_sg,
	.unmap_sg =		pa11_dma_unmap_sg,
588 589 590 591
	.sync_single_for_cpu =	pa11_dma_sync_single_for_cpu,
	.sync_single_for_device = pa11_dma_sync_single_for_device,
	.sync_sg_for_cpu =	pa11_dma_sync_sg_for_cpu,
	.sync_sg_for_device =	pa11_dma_sync_sg_for_device,
592
	.cache_sync =		pa11_dma_cache_sync,
L
Linus Torvalds 已提交
593 594
};

595
static void *pcx_dma_alloc(struct device *dev, size_t size,
596
		dma_addr_t *dma_handle, gfp_t flag, unsigned long attrs)
L
Linus Torvalds 已提交
597
{
598
	void *addr;
L
Linus Torvalds 已提交
599

600
	if ((attrs & DMA_ATTR_NON_CONSISTENT) == 0)
601 602
		return NULL;

603 604
	addr = (void *)__get_free_pages(flag, get_order(size));
	if (addr)
L
Linus Torvalds 已提交
605 606 607 608 609
		*dma_handle = (dma_addr_t)virt_to_phys(addr);

	return addr;
}

610
static void pcx_dma_free(struct device *dev, size_t size, void *vaddr,
611
		dma_addr_t iova, unsigned long attrs)
L
Linus Torvalds 已提交
612
{
613
	free_pages((unsigned long)vaddr, get_order(size));
L
Linus Torvalds 已提交
614 615 616
	return;
}

617
const struct dma_map_ops pcx_dma_ops = {
L
Linus Torvalds 已提交
618
	.dma_supported =	pa11_dma_supported,
619 620 621 622
	.alloc =		pcx_dma_alloc,
	.free =			pcx_dma_free,
	.map_page =		pa11_dma_map_page,
	.unmap_page =		pa11_dma_unmap_page,
L
Linus Torvalds 已提交
623 624
	.map_sg =		pa11_dma_map_sg,
	.unmap_sg =		pa11_dma_unmap_sg,
625 626 627 628
	.sync_single_for_cpu =	pa11_dma_sync_single_for_cpu,
	.sync_single_for_device = pa11_dma_sync_single_for_device,
	.sync_sg_for_cpu =	pa11_dma_sync_sg_for_cpu,
	.sync_sg_for_device =	pa11_dma_sync_sg_for_device,
629
	.cache_sync =		pa11_dma_cache_sync,
L
Linus Torvalds 已提交
630
};