blob: a9d310de57da650ac7c3549774729c990ceac583 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
6 * Copyright (C) 2000,2002-2005 Silicon Graphics, Inc. All rights reserved.
7 *
8 * Routines for PCI DMA mapping. See Documentation/DMA-API.txt for
9 * a description of how these routines should be used.
10 */
11
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090012#include <linux/gfp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/module.h>
FUJITA Tomonorib4391dd2009-01-05 23:36:10 +090014#include <linux/dma-mapping.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <asm/dma.h>
Mark Maule83821d32006-04-14 16:03:54 -050016#include <asm/sn/intr.h>
Mark Maule9b08ebd2005-04-25 11:32:16 -070017#include <asm/sn/pcibus_provider_defs.h>
18#include <asm/sn/pcidev.h>
Prarit Bhargavac13cf372005-07-06 15:26:51 -070019#include <asm/sn/sn_sal.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
Jens Axboe58b053e2007-10-22 20:02:46 +020021#define SG_ENT_VIRT_ADDRESS(sg) (sg_virt((sg)))
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#define SG_ENT_PHYS_ADDRESS(SG) virt_to_phys(SG_ENT_VIRT_ADDRESS(SG))
23
24/**
25 * sn_dma_supported - test a DMA mask
26 * @dev: device to test
27 * @mask: DMA mask to test
28 *
29 * Return whether the given PCI device DMA address mask can be supported
30 * properly. For example, if your device can only drive the low 24-bits
31 * during PCI bus mastering, then you would pass 0x00ffffff as the mask to
32 * this function. Of course, SN only supports devices that have 32 or more
33 * address bits when using the PMU.
34 */
FUJITA Tomonoricdc28d52009-01-05 23:36:15 +090035static int sn_dma_supported(struct device *dev, u64 mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -070036{
37 BUG_ON(dev->bus != &pci_bus_type);
38
39 if (mask < 0x7fffffff)
40 return 0;
41 return 1;
42}
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
44/**
45 * sn_dma_set_mask - set the DMA mask
46 * @dev: device to set
47 * @dma_mask: new mask
48 *
49 * Set @dev's DMA mask if the hw supports it.
50 */
51int sn_dma_set_mask(struct device *dev, u64 dma_mask)
52{
53 BUG_ON(dev->bus != &pci_bus_type);
54
55 if (!sn_dma_supported(dev, dma_mask))
56 return 0;
57
58 *dev->dma_mask = dma_mask;
59 return 1;
60}
61EXPORT_SYMBOL(sn_dma_set_mask);
62
63/**
64 * sn_dma_alloc_coherent - allocate memory for coherent DMA
65 * @dev: device to allocate for
66 * @size: size of the region
67 * @dma_handle: DMA (bus) address
68 * @flags: memory allocation flags
69 *
70 * dma_alloc_coherent() returns a pointer to a memory region suitable for
71 * coherent DMA traffic to/from a PCI device. On SN platforms, this means
72 * that @dma_handle will have the %PCIIO_DMA_CMD flag set.
73 *
74 * This interface is usually used for "command" streams (e.g. the command
75 * queue for a SCSI controller). See Documentation/DMA-API.txt for
76 * more information.
77 */
FUJITA Tomonoricdc28d52009-01-05 23:36:15 +090078static void *sn_dma_alloc_coherent(struct device *dev, size_t size,
79 dma_addr_t * dma_handle, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -070080{
81 void *cpuaddr;
82 unsigned long phys_addr;
Christoph Lameter7c2a6c62005-07-12 16:03:00 -070083 int node;
Mark Maulee955d822005-04-25 11:26:03 -070084 struct pci_dev *pdev = to_pci_dev(dev);
85 struct sn_pcibus_provider *provider = SN_PCIDEV_BUSPROVIDER(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
87 BUG_ON(dev->bus != &pci_bus_type);
88
89 /*
90 * Allocate the memory.
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 */
Christoph Lameter7c2a6c62005-07-12 16:03:00 -070092 node = pcibus_to_node(pdev->bus);
93 if (likely(node >=0)) {
Mel Gorman6484eb32009-06-16 15:31:54 -070094 struct page *p = alloc_pages_exact_node(node,
95 flags, get_order(size));
Christoph Lameter7c2a6c62005-07-12 16:03:00 -070096
97 if (likely(p))
98 cpuaddr = page_address(p);
99 else
100 return NULL;
101 } else
Takashi Iwaidc641612006-01-24 14:30:56 -0800102 cpuaddr = (void *)__get_free_pages(flags, get_order(size));
Christoph Lameter7c2a6c62005-07-12 16:03:00 -0700103
104 if (unlikely(!cpuaddr))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 return NULL;
106
107 memset(cpuaddr, 0x0, size);
108
109 /* physical addr. of the memory we just got */
110 phys_addr = __pa(cpuaddr);
111
112 /*
113 * 64 bit address translations should never fail.
114 * 32 bit translations can fail if there are insufficient mapping
115 * resources.
116 */
117
Mark Maule83821d32006-04-14 16:03:54 -0500118 *dma_handle = provider->dma_map_consistent(pdev, phys_addr, size,
119 SN_DMA_ADDR_PHYS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 if (!*dma_handle) {
Harvey Harrisond4ed8082008-03-04 15:15:00 -0800121 printk(KERN_ERR "%s: out of ATEs\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 free_pages((unsigned long)cpuaddr, get_order(size));
123 return NULL;
124 }
125
126 return cpuaddr;
127}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128
129/**
130 * sn_pci_free_coherent - free memory associated with coherent DMAable region
131 * @dev: device to free for
132 * @size: size to free
133 * @cpu_addr: kernel virtual address to free
134 * @dma_handle: DMA address associated with this region
135 *
136 * Frees the memory allocated by dma_alloc_coherent(), potentially unmapping
137 * any associated IOMMU mappings.
138 */
FUJITA Tomonoricdc28d52009-01-05 23:36:15 +0900139static void sn_dma_free_coherent(struct device *dev, size_t size, void *cpu_addr,
140 dma_addr_t dma_handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141{
Mark Maulee955d822005-04-25 11:26:03 -0700142 struct pci_dev *pdev = to_pci_dev(dev);
143 struct sn_pcibus_provider *provider = SN_PCIDEV_BUSPROVIDER(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144
145 BUG_ON(dev->bus != &pci_bus_type);
146
Mark Maulee955d822005-04-25 11:26:03 -0700147 provider->dma_unmap(pdev, dma_handle, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 free_pages((unsigned long)cpu_addr, get_order(size));
149}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
151/**
Arthur Kepner309df0c2008-04-29 01:00:32 -0700152 * sn_dma_map_single_attrs - map a single page for DMA
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 * @dev: device to map for
154 * @cpu_addr: kernel virtual address of the region to map
155 * @size: size of the region
156 * @direction: DMA direction
Arthur Kepner309df0c2008-04-29 01:00:32 -0700157 * @attrs: optional dma attributes
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 *
159 * Map the region pointed to by @cpu_addr for DMA and return the
160 * DMA address.
161 *
162 * We map this to the one step pcibr_dmamap_trans interface rather than
163 * the two step pcibr_dmamap_alloc/pcibr_dmamap_addr because we have
164 * no way of saving the dmamap handle from the alloc to later free
165 * (which is pretty much unacceptable).
166 *
Arthur Kepner309df0c2008-04-29 01:00:32 -0700167 * mappings with the DMA_ATTR_WRITE_BARRIER get mapped with
168 * dma_map_consistent() so that writes force a flush of pending DMA.
169 * (See "SGI Altix Architecture Considerations for Linux Device Drivers",
170 * Document Number: 007-4763-001)
171 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 * TODO: simplify our interface;
173 * figure out how to save dmamap handle so can use two step.
174 */
FUJITA Tomonori160c1d82009-01-05 23:59:02 +0900175static dma_addr_t sn_dma_map_page(struct device *dev, struct page *page,
176 unsigned long offset, size_t size,
177 enum dma_data_direction dir,
178 struct dma_attrs *attrs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179{
FUJITA Tomonori160c1d82009-01-05 23:59:02 +0900180 void *cpu_addr = page_address(page) + offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 dma_addr_t dma_addr;
182 unsigned long phys_addr;
Mark Maulee955d822005-04-25 11:26:03 -0700183 struct pci_dev *pdev = to_pci_dev(dev);
184 struct sn_pcibus_provider *provider = SN_PCIDEV_BUSPROVIDER(pdev);
Arthur Kepner309df0c2008-04-29 01:00:32 -0700185 int dmabarr;
186
187 dmabarr = dma_get_attr(DMA_ATTR_WRITE_BARRIER, attrs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
189 BUG_ON(dev->bus != &pci_bus_type);
190
191 phys_addr = __pa(cpu_addr);
Arthur Kepner309df0c2008-04-29 01:00:32 -0700192 if (dmabarr)
193 dma_addr = provider->dma_map_consistent(pdev, phys_addr,
194 size, SN_DMA_ADDR_PHYS);
195 else
196 dma_addr = provider->dma_map(pdev, phys_addr, size,
197 SN_DMA_ADDR_PHYS);
198
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 if (!dma_addr) {
Harvey Harrisond4ed8082008-03-04 15:15:00 -0800200 printk(KERN_ERR "%s: out of ATEs\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 return 0;
202 }
203 return dma_addr;
204}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
206/**
Arthur Kepner309df0c2008-04-29 01:00:32 -0700207 * sn_dma_unmap_single_attrs - unamp a DMA mapped page
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 * @dev: device to sync
209 * @dma_addr: DMA address to sync
210 * @size: size of region
211 * @direction: DMA direction
Arthur Kepner309df0c2008-04-29 01:00:32 -0700212 * @attrs: optional dma attributes
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 *
214 * This routine is supposed to sync the DMA region specified
215 * by @dma_handle into the coherence domain. On SN, we're always cache
216 * coherent, so we just need to free any ATEs associated with this mapping.
217 */
FUJITA Tomonori160c1d82009-01-05 23:59:02 +0900218static void sn_dma_unmap_page(struct device *dev, dma_addr_t dma_addr,
219 size_t size, enum dma_data_direction dir,
220 struct dma_attrs *attrs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221{
Mark Maulee955d822005-04-25 11:26:03 -0700222 struct pci_dev *pdev = to_pci_dev(dev);
223 struct sn_pcibus_provider *provider = SN_PCIDEV_BUSPROVIDER(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224
225 BUG_ON(dev->bus != &pci_bus_type);
Mark Maulee955d822005-04-25 11:26:03 -0700226
FUJITA Tomonori160c1d82009-01-05 23:59:02 +0900227 provider->dma_unmap(pdev, dma_addr, dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229
230/**
FUJITA Tomonori160c1d82009-01-05 23:59:02 +0900231 * sn_dma_unmap_sg - unmap a DMA scatterlist
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 * @dev: device to unmap
233 * @sg: scatterlist to unmap
234 * @nhwentries: number of scatterlist entries
235 * @direction: DMA direction
Arthur Kepner309df0c2008-04-29 01:00:32 -0700236 * @attrs: optional dma attributes
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 *
238 * Unmap a set of streaming mode DMA translations.
239 */
FUJITA Tomonori160c1d82009-01-05 23:59:02 +0900240static void sn_dma_unmap_sg(struct device *dev, struct scatterlist *sgl,
241 int nhwentries, enum dma_data_direction dir,
242 struct dma_attrs *attrs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243{
244 int i;
Mark Maulee955d822005-04-25 11:26:03 -0700245 struct pci_dev *pdev = to_pci_dev(dev);
246 struct sn_pcibus_provider *provider = SN_PCIDEV_BUSPROVIDER(pdev);
Jens Axboe9b6eccf2007-10-16 11:27:26 +0200247 struct scatterlist *sg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
249 BUG_ON(dev->bus != &pci_bus_type);
250
Jens Axboe9b6eccf2007-10-16 11:27:26 +0200251 for_each_sg(sgl, sg, nhwentries, i) {
FUJITA Tomonori160c1d82009-01-05 23:59:02 +0900252 provider->dma_unmap(pdev, sg->dma_address, dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 sg->dma_address = (dma_addr_t) NULL;
254 sg->dma_length = 0;
255 }
256}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257
258/**
FUJITA Tomonori160c1d82009-01-05 23:59:02 +0900259 * sn_dma_map_sg - map a scatterlist for DMA
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 * @dev: device to map for
261 * @sg: scatterlist to map
262 * @nhwentries: number of entries
263 * @direction: direction of the DMA transaction
Arthur Kepner309df0c2008-04-29 01:00:32 -0700264 * @attrs: optional dma attributes
265 *
266 * mappings with the DMA_ATTR_WRITE_BARRIER get mapped with
267 * dma_map_consistent() so that writes force a flush of pending DMA.
268 * (See "SGI Altix Architecture Considerations for Linux Device Drivers",
269 * Document Number: 007-4763-001)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 *
271 * Maps each entry of @sg for DMA.
272 */
FUJITA Tomonori160c1d82009-01-05 23:59:02 +0900273static int sn_dma_map_sg(struct device *dev, struct scatterlist *sgl,
274 int nhwentries, enum dma_data_direction dir,
275 struct dma_attrs *attrs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276{
277 unsigned long phys_addr;
Jens Axboe9b6eccf2007-10-16 11:27:26 +0200278 struct scatterlist *saved_sg = sgl, *sg;
Mark Maulee955d822005-04-25 11:26:03 -0700279 struct pci_dev *pdev = to_pci_dev(dev);
280 struct sn_pcibus_provider *provider = SN_PCIDEV_BUSPROVIDER(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 int i;
Arthur Kepner309df0c2008-04-29 01:00:32 -0700282 int dmabarr;
283
284 dmabarr = dma_get_attr(DMA_ATTR_WRITE_BARRIER, attrs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285
286 BUG_ON(dev->bus != &pci_bus_type);
287
288 /*
289 * Setup a DMA address for each entry in the scatterlist.
290 */
Jens Axboe9b6eccf2007-10-16 11:27:26 +0200291 for_each_sg(sgl, sg, nhwentries, i) {
Arthur Kepner309df0c2008-04-29 01:00:32 -0700292 dma_addr_t dma_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 phys_addr = SG_ENT_PHYS_ADDRESS(sg);
Arthur Kepner309df0c2008-04-29 01:00:32 -0700294 if (dmabarr)
295 dma_addr = provider->dma_map_consistent(pdev,
296 phys_addr,
297 sg->length,
298 SN_DMA_ADDR_PHYS);
299 else
300 dma_addr = provider->dma_map(pdev, phys_addr,
301 sg->length,
302 SN_DMA_ADDR_PHYS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
Arthur Kepner309df0c2008-04-29 01:00:32 -0700304 sg->dma_address = dma_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 if (!sg->dma_address) {
Harvey Harrisond4ed8082008-03-04 15:15:00 -0800306 printk(KERN_ERR "%s: out of ATEs\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307
308 /*
309 * Free any successfully allocated entries.
310 */
311 if (i > 0)
FUJITA Tomonori160c1d82009-01-05 23:59:02 +0900312 sn_dma_unmap_sg(dev, saved_sg, i, dir, attrs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 return 0;
314 }
315
316 sg->dma_length = sg->length;
317 }
318
319 return nhwentries;
320}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321
FUJITA Tomonoricdc28d52009-01-05 23:36:15 +0900322static void sn_dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle,
FUJITA Tomonori160c1d82009-01-05 23:59:02 +0900323 size_t size, enum dma_data_direction dir)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324{
325 BUG_ON(dev->bus != &pci_bus_type);
326}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
FUJITA Tomonoricdc28d52009-01-05 23:36:15 +0900328static void sn_dma_sync_single_for_device(struct device *dev, dma_addr_t dma_handle,
FUJITA Tomonori160c1d82009-01-05 23:59:02 +0900329 size_t size,
330 enum dma_data_direction dir)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331{
332 BUG_ON(dev->bus != &pci_bus_type);
333}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334
FUJITA Tomonoricdc28d52009-01-05 23:36:15 +0900335static void sn_dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
FUJITA Tomonori160c1d82009-01-05 23:59:02 +0900336 int nelems, enum dma_data_direction dir)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337{
338 BUG_ON(dev->bus != &pci_bus_type);
339}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340
FUJITA Tomonoricdc28d52009-01-05 23:36:15 +0900341static void sn_dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
FUJITA Tomonori160c1d82009-01-05 23:59:02 +0900342 int nelems, enum dma_data_direction dir)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343{
344 BUG_ON(dev->bus != &pci_bus_type);
345}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
FUJITA Tomonoricdc28d52009-01-05 23:36:15 +0900347static int sn_dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348{
349 return 0;
350}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351
John Keller175add12008-11-24 16:47:17 -0600352u64 sn_dma_get_required_mask(struct device *dev)
353{
Yang Hongyang6a355282009-04-06 19:01:13 -0700354 return DMA_BIT_MASK(64);
John Keller175add12008-11-24 16:47:17 -0600355}
356EXPORT_SYMBOL_GPL(sn_dma_get_required_mask);
357
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358char *sn_pci_get_legacy_mem(struct pci_bus *bus)
359{
360 if (!SN_PCIBUS_BUSSOFT(bus))
361 return ERR_PTR(-ENODEV);
362
363 return (char *)(SN_PCIBUS_BUSSOFT(bus)->bs_legacy_mem | __IA64_UNCACHED_OFFSET);
364}
365
366int sn_pci_legacy_read(struct pci_bus *bus, u16 port, u32 *val, u8 size)
367{
368 unsigned long addr;
369 int ret;
Mark Maule61b9cf72005-09-23 12:31:53 -0500370 struct ia64_sal_retval isrv;
371
372 /*
373 * First, try the SN_SAL_IOIF_PCI_SAFE SAL call which can work
374 * around hw issues at the pci bus level. SGI proms older than
Simon Arlott72fdbdc2007-05-11 14:55:43 -0700375 * 4.10 don't implement this.
Mark Maule61b9cf72005-09-23 12:31:53 -0500376 */
377
378 SAL_CALL(isrv, SN_SAL_IOIF_PCI_SAFE,
Jes Sorensen8ed9b2c2006-02-13 05:29:57 -0500379 pci_domain_nr(bus), bus->number,
380 0, /* io */
381 0, /* read */
382 port, size, __pa(val));
Mark Maule61b9cf72005-09-23 12:31:53 -0500383
384 if (isrv.status == 0)
385 return size;
386
387 /*
388 * If the above failed, retry using the SAL_PROBE call which should
389 * be present in all proms (but which cannot work round PCI chipset
Simon Arlott72fdbdc2007-05-11 14:55:43 -0700390 * bugs). This code is retained for compatibility with old
Mark Maule61b9cf72005-09-23 12:31:53 -0500391 * pre-4.10 proms, and should be removed at some point in the future.
392 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393
394 if (!SN_PCIBUS_BUSSOFT(bus))
395 return -ENODEV;
396
397 addr = SN_PCIBUS_BUSSOFT(bus)->bs_legacy_io | __IA64_UNCACHED_OFFSET;
398 addr += port;
399
400 ret = ia64_sn_probe_mem(addr, (long)size, (void *)val);
401
402 if (ret == 2)
403 return -EINVAL;
404
405 if (ret == 1)
406 *val = -1;
407
408 return size;
409}
410
411int sn_pci_legacy_write(struct pci_bus *bus, u16 port, u32 val, u8 size)
412{
413 int ret = size;
414 unsigned long paddr;
415 unsigned long *addr;
Mark Maule61b9cf72005-09-23 12:31:53 -0500416 struct ia64_sal_retval isrv;
417
418 /*
419 * First, try the SN_SAL_IOIF_PCI_SAFE SAL call which can work
420 * around hw issues at the pci bus level. SGI proms older than
Simon Arlott72fdbdc2007-05-11 14:55:43 -0700421 * 4.10 don't implement this.
Mark Maule61b9cf72005-09-23 12:31:53 -0500422 */
423
424 SAL_CALL(isrv, SN_SAL_IOIF_PCI_SAFE,
Jes Sorensen8ed9b2c2006-02-13 05:29:57 -0500425 pci_domain_nr(bus), bus->number,
426 0, /* io */
427 1, /* write */
428 port, size, __pa(&val));
Mark Maule61b9cf72005-09-23 12:31:53 -0500429
430 if (isrv.status == 0)
431 return size;
432
433 /*
434 * If the above failed, retry using the SAL_PROBE call which should
435 * be present in all proms (but which cannot work round PCI chipset
Simon Arlott72fdbdc2007-05-11 14:55:43 -0700436 * bugs). This code is retained for compatibility with old
Mark Maule61b9cf72005-09-23 12:31:53 -0500437 * pre-4.10 proms, and should be removed at some point in the future.
438 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439
440 if (!SN_PCIBUS_BUSSOFT(bus)) {
441 ret = -ENODEV;
442 goto out;
443 }
444
445 /* Put the phys addr in uncached space */
446 paddr = SN_PCIBUS_BUSSOFT(bus)->bs_legacy_io | __IA64_UNCACHED_OFFSET;
447 paddr += port;
448 addr = (unsigned long *)paddr;
449
450 switch (size) {
451 case 1:
452 *(volatile u8 *)(addr) = (u8)(val);
453 break;
454 case 2:
455 *(volatile u16 *)(addr) = (u16)(val);
456 break;
457 case 4:
458 *(volatile u32 *)(addr) = (u32)(val);
459 break;
460 default:
461 ret = -EINVAL;
462 break;
463 }
464 out:
465 return ret;
466}
FUJITA Tomonorib4391dd2009-01-05 23:36:10 +0900467
FUJITA Tomonori160c1d82009-01-05 23:59:02 +0900468static struct dma_map_ops sn_dma_ops = {
FUJITA Tomonorib4391dd2009-01-05 23:36:10 +0900469 .alloc_coherent = sn_dma_alloc_coherent,
470 .free_coherent = sn_dma_free_coherent,
FUJITA Tomonori160c1d82009-01-05 23:59:02 +0900471 .map_page = sn_dma_map_page,
472 .unmap_page = sn_dma_unmap_page,
473 .map_sg = sn_dma_map_sg,
474 .unmap_sg = sn_dma_unmap_sg,
FUJITA Tomonorib4391dd2009-01-05 23:36:10 +0900475 .sync_single_for_cpu = sn_dma_sync_single_for_cpu,
476 .sync_sg_for_cpu = sn_dma_sync_sg_for_cpu,
477 .sync_single_for_device = sn_dma_sync_single_for_device,
478 .sync_sg_for_device = sn_dma_sync_sg_for_device,
479 .mapping_error = sn_dma_mapping_error,
FUJITA Tomonori160c1d82009-01-05 23:59:02 +0900480 .dma_supported = sn_dma_supported,
FUJITA Tomonorib4391dd2009-01-05 23:36:10 +0900481};
FUJITA Tomonori4d9b9772009-01-05 23:36:12 +0900482
483void sn_dma_init(void)
484{
485 dma_ops = &sn_dma_ops;
486}