| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * arch/sh/pci/dma-dreamcast.c | 
|  | 3 | * | 
|  | 4 | * PCI DMA support for the Sega Dreamcast | 
|  | 5 | * | 
|  | 6 | * Copyright (C) 2001, 2002  M. R. Brown | 
|  | 7 | * Copyright (C) 2002, 2003  Paul Mundt | 
|  | 8 | * | 
|  | 9 | * This file originally bore the message (with enclosed-$): | 
|  | 10 | *	Id: pci.c,v 1.3 2003/05/04 19:29:46 lethal Exp | 
|  | 11 | *	Dreamcast PCI: Supports SEGA Broadband Adaptor only. | 
|  | 12 | * | 
|  | 13 | * This file is subject to the terms and conditions of the GNU General Public | 
|  | 14 | * License.  See the file "COPYING" in the main directory of this archive | 
|  | 15 | * for more details. | 
|  | 16 | */ | 
|  | 17 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/sched.h> | 
|  | 19 | #include <linux/kernel.h> | 
|  | 20 | #include <linux/param.h> | 
|  | 21 | #include <linux/interrupt.h> | 
|  | 22 | #include <linux/init.h> | 
|  | 23 | #include <linux/irq.h> | 
|  | 24 | #include <linux/pci.h> | 
|  | 25 | #include <linux/dma-mapping.h> | 
|  | 26 | #include <linux/device.h> | 
|  | 27 |  | 
|  | 28 | #include <asm/io.h> | 
|  | 29 | #include <asm/irq.h> | 
|  | 30 | #include <asm/mach/pci.h> | 
|  | 31 |  | 
|  | 32 | static int gapspci_dma_used = 0; | 
|  | 33 |  | 
|  | 34 | void *dreamcast_consistent_alloc(struct device *dev, size_t size, | 
| Al Viro | 6dae2c2 | 2005-10-21 03:21:38 -0400 | [diff] [blame] | 35 | dma_addr_t *dma_handle, gfp_t flag) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | { | 
|  | 37 | unsigned long buf; | 
|  | 38 |  | 
|  | 39 | if (dev && dev->bus != &pci_bus_type) | 
|  | 40 | return NULL; | 
|  | 41 |  | 
|  | 42 | if (gapspci_dma_used + size > GAPSPCI_DMA_SIZE) | 
|  | 43 | return ERR_PTR(-EINVAL); | 
|  | 44 |  | 
|  | 45 | buf = GAPSPCI_DMA_BASE + gapspci_dma_used; | 
|  | 46 |  | 
|  | 47 | gapspci_dma_used = PAGE_ALIGN(gapspci_dma_used+size); | 
|  | 48 |  | 
|  | 49 | *dma_handle = (dma_addr_t)buf; | 
|  | 50 |  | 
|  | 51 | buf = P2SEGADDR(buf); | 
|  | 52 |  | 
|  | 53 | /* Flush the dcache before we hand off the buffer */ | 
|  | 54 | dma_cache_wback_inv((void *)buf, size); | 
|  | 55 |  | 
|  | 56 | return (void *)buf; | 
|  | 57 | } | 
|  | 58 |  | 
|  | 59 | int dreamcast_consistent_free(struct device *dev, size_t size, | 
|  | 60 | void *vaddr, dma_addr_t dma_handle) | 
|  | 61 | { | 
|  | 62 | if (dev && dev->bus != &pci_bus_type) | 
|  | 63 | return -EINVAL; | 
|  | 64 |  | 
|  | 65 | /* XXX */ | 
|  | 66 | gapspci_dma_used = 0; | 
|  | 67 |  | 
|  | 68 | return 0; | 
|  | 69 | } | 
|  | 70 |  |