Adrian Bunk | 88278ca | 2008-05-19 16:53:02 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * ioport.c: Simple io mapping allocator. |
| 3 | * |
| 4 | * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu) |
| 5 | * Copyright (C) 1995 Miguel de Icaza (miguel@nuclecu.unam.mx) |
| 6 | * |
| 7 | * 1996: sparc_free_io, 1999: ioremap()/iounmap() by Pete Zaitcev. |
| 8 | * |
| 9 | * 2000/01/29 |
| 10 | * <rth> zait: as long as pci_alloc_consistent produces something addressable, |
| 11 | * things are ok. |
| 12 | * <zaitcev> rth: no, it is relevant, because get_free_pages returns you a |
| 13 | * pointer into the big page mapping |
| 14 | * <rth> zait: so what? |
| 15 | * <rth> zait: remap_it_my_way(virt_to_phys(get_free_page())) |
| 16 | * <zaitcev> Hmm |
| 17 | * <zaitcev> Suppose I did this remap_it_my_way(virt_to_phys(get_free_page())). |
| 18 | * So far so good. |
| 19 | * <zaitcev> Now, driver calls pci_free_consistent(with result of |
| 20 | * remap_it_my_way()). |
| 21 | * <zaitcev> How do you find the address to pass to free_pages()? |
| 22 | * <rth> zait: walk the page tables? It's only two or three level after all. |
| 23 | * <rth> zait: you have to walk them anyway to remove the mapping. |
| 24 | * <zaitcev> Hmm |
| 25 | * <zaitcev> Sounds reasonable |
| 26 | */ |
| 27 | |
David S. Miller | 3ca9fab | 2006-06-29 14:35:33 -0700 | [diff] [blame] | 28 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <linux/sched.h> |
| 30 | #include <linux/kernel.h> |
| 31 | #include <linux/errno.h> |
| 32 | #include <linux/types.h> |
| 33 | #include <linux/ioport.h> |
| 34 | #include <linux/mm.h> |
| 35 | #include <linux/slab.h> |
| 36 | #include <linux/pci.h> /* struct pci_dev */ |
| 37 | #include <linux/proc_fs.h> |
Jens Axboe | 0912a5d | 2007-05-14 15:44:38 +0200 | [diff] [blame] | 38 | #include <linux/scatterlist.h> |
Stephen Rothwell | 764f257 | 2008-08-07 15:33:36 -0700 | [diff] [blame] | 39 | #include <linux/of_device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
| 41 | #include <asm/io.h> |
| 42 | #include <asm/vaddrs.h> |
| 43 | #include <asm/oplib.h> |
David S. Miller | 576c352 | 2006-06-23 15:55:45 -0700 | [diff] [blame] | 44 | #include <asm/prom.h> |
| 45 | #include <asm/sbus.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #include <asm/page.h> |
| 47 | #include <asm/pgalloc.h> |
| 48 | #include <asm/dma.h> |
David S. Miller | e003934 | 2008-08-25 22:47:20 -0700 | [diff] [blame] | 49 | #include <asm/iommu.h> |
| 50 | #include <asm/io-unit.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
David S. Miller | 944c67df | 2008-08-27 18:01:36 -0700 | [diff] [blame] | 52 | #include "dma.h" |
| 53 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | #define mmu_inval_dma_area(p, l) /* Anton pulled it out for 2.4.0-xx */ |
| 55 | |
Adrian Bunk | c61c65c | 2008-06-05 11:40:58 -0700 | [diff] [blame] | 56 | static struct resource *_sparc_find_resource(struct resource *r, |
| 57 | unsigned long); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
| 59 | static void __iomem *_sparc_ioremap(struct resource *res, u32 bus, u32 pa, int sz); |
| 60 | static void __iomem *_sparc_alloc_io(unsigned int busno, unsigned long phys, |
| 61 | unsigned long size, char *name); |
| 62 | static void _sparc_free_io(struct resource *res); |
| 63 | |
Adrian Bunk | c61c65c | 2008-06-05 11:40:58 -0700 | [diff] [blame] | 64 | static void register_proc_sparc_ioport(void); |
| 65 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | /* This points to the next to use virtual memory for DVMA mappings */ |
| 67 | static struct resource _sparc_dvma = { |
| 68 | .name = "sparc_dvma", .start = DVMA_VADDR, .end = DVMA_END - 1 |
| 69 | }; |
| 70 | /* This points to the start of I/O mappings, cluable from outside. */ |
| 71 | /*ext*/ struct resource sparc_iomap = { |
| 72 | .name = "sparc_iomap", .start = IOBASE_VADDR, .end = IOBASE_END - 1 |
| 73 | }; |
| 74 | |
| 75 | /* |
| 76 | * Our mini-allocator... |
| 77 | * Boy this is gross! We need it because we must map I/O for |
| 78 | * timers and interrupt controller before the kmalloc is available. |
| 79 | */ |
| 80 | |
| 81 | #define XNMLN 15 |
| 82 | #define XNRES 10 /* SS-10 uses 8 */ |
| 83 | |
| 84 | struct xresource { |
| 85 | struct resource xres; /* Must be first */ |
| 86 | int xflag; /* 1 == used */ |
| 87 | char xname[XNMLN+1]; |
| 88 | }; |
| 89 | |
| 90 | static struct xresource xresv[XNRES]; |
| 91 | |
| 92 | static struct xresource *xres_alloc(void) { |
| 93 | struct xresource *xrp; |
| 94 | int n; |
| 95 | |
| 96 | xrp = xresv; |
| 97 | for (n = 0; n < XNRES; n++) { |
| 98 | if (xrp->xflag == 0) { |
| 99 | xrp->xflag = 1; |
| 100 | return xrp; |
| 101 | } |
| 102 | xrp++; |
| 103 | } |
| 104 | return NULL; |
| 105 | } |
| 106 | |
| 107 | static void xres_free(struct xresource *xrp) { |
| 108 | xrp->xflag = 0; |
| 109 | } |
| 110 | |
| 111 | /* |
| 112 | * These are typically used in PCI drivers |
| 113 | * which are trying to be cross-platform. |
| 114 | * |
| 115 | * Bus type is always zero on IIep. |
| 116 | */ |
| 117 | void __iomem *ioremap(unsigned long offset, unsigned long size) |
| 118 | { |
| 119 | char name[14]; |
| 120 | |
| 121 | sprintf(name, "phys_%08x", (u32)offset); |
| 122 | return _sparc_alloc_io(0, offset, size, name); |
| 123 | } |
| 124 | |
| 125 | /* |
| 126 | * Comlimentary to ioremap(). |
| 127 | */ |
| 128 | void iounmap(volatile void __iomem *virtual) |
| 129 | { |
| 130 | unsigned long vaddr = (unsigned long) virtual & PAGE_MASK; |
| 131 | struct resource *res; |
| 132 | |
| 133 | if ((res = _sparc_find_resource(&sparc_iomap, vaddr)) == NULL) { |
| 134 | printk("free_io/iounmap: cannot free %lx\n", vaddr); |
| 135 | return; |
| 136 | } |
| 137 | _sparc_free_io(res); |
| 138 | |
| 139 | if ((char *)res >= (char*)xresv && (char *)res < (char *)&xresv[XNRES]) { |
| 140 | xres_free((struct xresource *)res); |
| 141 | } else { |
| 142 | kfree(res); |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | /* |
| 147 | */ |
| 148 | void __iomem *sbus_ioremap(struct resource *phyres, unsigned long offset, |
| 149 | unsigned long size, char *name) |
| 150 | { |
| 151 | return _sparc_alloc_io(phyres->flags & 0xF, |
| 152 | phyres->start + offset, size, name); |
| 153 | } |
| 154 | |
David S. Miller | 3ca9fab | 2006-06-29 14:35:33 -0700 | [diff] [blame] | 155 | void __iomem *of_ioremap(struct resource *res, unsigned long offset, |
| 156 | unsigned long size, char *name) |
| 157 | { |
| 158 | return _sparc_alloc_io(res->flags & 0xF, |
| 159 | res->start + offset, |
| 160 | size, name); |
| 161 | } |
| 162 | EXPORT_SYMBOL(of_ioremap); |
| 163 | |
David S. Miller | e3a411a3 | 2006-12-28 21:01:32 -0800 | [diff] [blame] | 164 | void of_iounmap(struct resource *res, void __iomem *base, unsigned long size) |
David S. Miller | 3ca9fab | 2006-06-29 14:35:33 -0700 | [diff] [blame] | 165 | { |
| 166 | iounmap(base); |
| 167 | } |
| 168 | EXPORT_SYMBOL(of_iounmap); |
| 169 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | /* |
| 171 | */ |
| 172 | void sbus_iounmap(volatile void __iomem *addr, unsigned long size) |
| 173 | { |
| 174 | iounmap(addr); |
| 175 | } |
| 176 | |
| 177 | /* |
| 178 | * Meat of mapping |
| 179 | */ |
| 180 | static void __iomem *_sparc_alloc_io(unsigned int busno, unsigned long phys, |
| 181 | unsigned long size, char *name) |
| 182 | { |
| 183 | static int printed_full; |
| 184 | struct xresource *xres; |
| 185 | struct resource *res; |
| 186 | char *tack; |
| 187 | int tlen; |
| 188 | void __iomem *va; /* P3 diag */ |
| 189 | |
| 190 | if (name == NULL) name = "???"; |
| 191 | |
| 192 | if ((xres = xres_alloc()) != 0) { |
| 193 | tack = xres->xname; |
| 194 | res = &xres->xres; |
| 195 | } else { |
| 196 | if (!printed_full) { |
| 197 | printk("ioremap: done with statics, switching to malloc\n"); |
| 198 | printed_full = 1; |
| 199 | } |
| 200 | tlen = strlen(name); |
| 201 | tack = kmalloc(sizeof (struct resource) + tlen + 1, GFP_KERNEL); |
| 202 | if (tack == NULL) return NULL; |
| 203 | memset(tack, 0, sizeof(struct resource)); |
| 204 | res = (struct resource *) tack; |
| 205 | tack += sizeof (struct resource); |
| 206 | } |
| 207 | |
| 208 | strlcpy(tack, name, XNMLN+1); |
| 209 | res->name = tack; |
| 210 | |
| 211 | va = _sparc_ioremap(res, busno, phys, size); |
| 212 | /* printk("ioremap(0x%x:%08lx[0x%lx])=%p\n", busno, phys, size, va); */ /* P3 diag */ |
| 213 | return va; |
| 214 | } |
| 215 | |
| 216 | /* |
| 217 | */ |
| 218 | static void __iomem * |
| 219 | _sparc_ioremap(struct resource *res, u32 bus, u32 pa, int sz) |
| 220 | { |
| 221 | unsigned long offset = ((unsigned long) pa) & (~PAGE_MASK); |
| 222 | |
| 223 | if (allocate_resource(&sparc_iomap, res, |
| 224 | (offset + sz + PAGE_SIZE-1) & PAGE_MASK, |
| 225 | sparc_iomap.start, sparc_iomap.end, PAGE_SIZE, NULL, NULL) != 0) { |
| 226 | /* Usually we cannot see printks in this case. */ |
| 227 | prom_printf("alloc_io_res(%s): cannot occupy\n", |
| 228 | (res->name != NULL)? res->name: "???"); |
| 229 | prom_halt(); |
| 230 | } |
| 231 | |
| 232 | pa &= PAGE_MASK; |
| 233 | sparc_mapiorange(bus, pa, res->start, res->end - res->start + 1); |
| 234 | |
Greg Kroah-Hartman | d75fc8b | 2006-06-12 16:09:23 -0700 | [diff] [blame] | 235 | return (void __iomem *)(unsigned long)(res->start + offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | /* |
| 239 | * Comlimentary to _sparc_ioremap(). |
| 240 | */ |
| 241 | static void _sparc_free_io(struct resource *res) |
| 242 | { |
| 243 | unsigned long plen; |
| 244 | |
| 245 | plen = res->end - res->start + 1; |
Eric Sesterhenn | 30d4d1f | 2006-03-10 02:55:20 -0800 | [diff] [blame] | 246 | BUG_ON((plen & (PAGE_SIZE-1)) != 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | sparc_unmapiorange(res->start, plen); |
| 248 | release_resource(res); |
| 249 | } |
| 250 | |
| 251 | #ifdef CONFIG_SBUS |
| 252 | |
David S. Miller | 63237ee | 2008-08-26 23:33:42 -0700 | [diff] [blame^] | 253 | void sbus_set_sbus64(struct device *dev, int x) |
David S. Miller | 8fae097 | 2006-06-20 15:23:28 -0700 | [diff] [blame] | 254 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | printk("sbus_set_sbus64: unsupported\n"); |
| 256 | } |
| 257 | |
David S. Miller | 8fae097 | 2006-06-20 15:23:28 -0700 | [diff] [blame] | 258 | extern unsigned int sun4d_build_irq(struct sbus_dev *sdev, int irq); |
| 259 | void __init sbus_fill_device_irq(struct sbus_dev *sdev) |
| 260 | { |
| 261 | struct linux_prom_irqs irqs[PROMINTR_MAX]; |
| 262 | int len; |
| 263 | |
| 264 | len = prom_getproperty(sdev->prom_node, "intr", |
| 265 | (char *)irqs, sizeof(irqs)); |
| 266 | if (len != -1) { |
| 267 | sdev->num_irqs = len / 8; |
| 268 | if (sdev->num_irqs == 0) { |
| 269 | sdev->irqs[0] = 0; |
| 270 | } else if (sparc_cpu_model == sun4d) { |
| 271 | for (len = 0; len < sdev->num_irqs; len++) |
| 272 | sdev->irqs[len] = |
| 273 | sun4d_build_irq(sdev, irqs[len].pri); |
| 274 | } else { |
| 275 | for (len = 0; len < sdev->num_irqs; len++) |
| 276 | sdev->irqs[len] = irqs[len].pri; |
| 277 | } |
| 278 | } else { |
| 279 | int interrupts[PROMINTR_MAX]; |
| 280 | |
| 281 | /* No "intr" node found-- check for "interrupts" node. |
| 282 | * This node contains SBus interrupt levels, not IPLs |
| 283 | * as in "intr", and no vector values. We convert |
| 284 | * SBus interrupt levels to PILs (platform specific). |
| 285 | */ |
| 286 | len = prom_getproperty(sdev->prom_node, "interrupts", |
| 287 | (char *)interrupts, sizeof(interrupts)); |
| 288 | if (len == -1) { |
| 289 | sdev->irqs[0] = 0; |
| 290 | sdev->num_irqs = 0; |
| 291 | } else { |
| 292 | sdev->num_irqs = len / sizeof(int); |
| 293 | for (len = 0; len < sdev->num_irqs; len++) { |
| 294 | sdev->irqs[len] = |
| 295 | sbint_to_irq(sdev, interrupts[len]); |
| 296 | } |
| 297 | } |
| 298 | } |
| 299 | } |
| 300 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | /* |
| 302 | * Allocate a chunk of memory suitable for DMA. |
| 303 | * Typically devices use them for control blocks. |
| 304 | * CPU may access them without any explicit flushing. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | */ |
David S. Miller | 7a715f4 | 2008-08-27 18:37:58 -0700 | [diff] [blame] | 306 | void *sbus_alloc_consistent(struct device *dev, long len, u32 *dma_addrp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | { |
David S. Miller | 7a715f4 | 2008-08-27 18:37:58 -0700 | [diff] [blame] | 308 | struct of_device *op = to_of_device(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | unsigned long len_total = (len + PAGE_SIZE-1) & PAGE_MASK; |
| 310 | unsigned long va; |
| 311 | struct resource *res; |
| 312 | int order; |
| 313 | |
Paulius Zaleckas | efad798b | 2008-02-03 15:42:53 +0200 | [diff] [blame] | 314 | /* XXX why are some lengths signed, others unsigned? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | if (len <= 0) { |
| 316 | return NULL; |
| 317 | } |
| 318 | /* XXX So what is maxphys for us and how do drivers know it? */ |
| 319 | if (len > 256*1024) { /* __get_free_pages() limit */ |
| 320 | return NULL; |
| 321 | } |
| 322 | |
| 323 | order = get_order(len_total); |
Hugh Dickins | f3d48f0 | 2005-11-21 21:32:22 -0800 | [diff] [blame] | 324 | if ((va = __get_free_pages(GFP_KERNEL|__GFP_COMP, order)) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | goto err_nopages; |
| 326 | |
Yan Burman | c80892d | 2006-11-30 17:07:04 -0800 | [diff] [blame] | 327 | if ((res = kzalloc(sizeof(struct resource), GFP_KERNEL)) == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | goto err_nomem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | |
| 330 | if (allocate_resource(&_sparc_dvma, res, len_total, |
| 331 | _sparc_dvma.start, _sparc_dvma.end, PAGE_SIZE, NULL, NULL) != 0) { |
| 332 | printk("sbus_alloc_consistent: cannot occupy 0x%lx", len_total); |
| 333 | goto err_nova; |
| 334 | } |
| 335 | mmu_inval_dma_area(va, len_total); |
| 336 | // XXX The mmu_map_dma_area does this for us below, see comments. |
| 337 | // sparc_mapiorange(0, virt_to_phys(va), res->start, len_total); |
| 338 | /* |
| 339 | * XXX That's where sdev would be used. Currently we load |
| 340 | * all iommu tables with the same translations. |
| 341 | */ |
| 342 | if (mmu_map_dma_area(dma_addrp, va, res->start, len_total) != 0) |
| 343 | goto err_noiommu; |
| 344 | |
David S. Miller | 7a715f4 | 2008-08-27 18:37:58 -0700 | [diff] [blame] | 345 | res->name = op->node->name; |
Martin Habets | 4cfbd7e | 2006-05-07 23:43:19 -0700 | [diff] [blame] | 346 | |
Greg Kroah-Hartman | d75fc8b | 2006-06-12 16:09:23 -0700 | [diff] [blame] | 347 | return (void *)(unsigned long)res->start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | |
| 349 | err_noiommu: |
| 350 | release_resource(res); |
| 351 | err_nova: |
| 352 | free_pages(va, order); |
| 353 | err_nomem: |
| 354 | kfree(res); |
| 355 | err_nopages: |
| 356 | return NULL; |
| 357 | } |
| 358 | |
David S. Miller | 7a715f4 | 2008-08-27 18:37:58 -0700 | [diff] [blame] | 359 | void sbus_free_consistent(struct device *dev, long n, void *p, u32 ba) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | { |
| 361 | struct resource *res; |
| 362 | struct page *pgv; |
| 363 | |
| 364 | if ((res = _sparc_find_resource(&_sparc_dvma, |
| 365 | (unsigned long)p)) == NULL) { |
| 366 | printk("sbus_free_consistent: cannot free %p\n", p); |
| 367 | return; |
| 368 | } |
| 369 | |
| 370 | if (((unsigned long)p & (PAGE_SIZE-1)) != 0) { |
| 371 | printk("sbus_free_consistent: unaligned va %p\n", p); |
| 372 | return; |
| 373 | } |
| 374 | |
| 375 | n = (n + PAGE_SIZE-1) & PAGE_MASK; |
| 376 | if ((res->end-res->start)+1 != n) { |
| 377 | printk("sbus_free_consistent: region 0x%lx asked 0x%lx\n", |
| 378 | (long)((res->end-res->start)+1), n); |
| 379 | return; |
| 380 | } |
| 381 | |
| 382 | release_resource(res); |
| 383 | kfree(res); |
| 384 | |
| 385 | /* mmu_inval_dma_area(va, n); */ /* it's consistent, isn't it */ |
| 386 | pgv = mmu_translate_dvma(ba); |
| 387 | mmu_unmap_dma_area(ba, n); |
| 388 | |
| 389 | __free_pages(pgv, get_order(n)); |
| 390 | } |
| 391 | |
| 392 | /* |
| 393 | * Map a chunk of memory so that devices can see it. |
| 394 | * CPU view of this memory may be inconsistent with |
| 395 | * a device view and explicit flushing is necessary. |
| 396 | */ |
David S. Miller | 7a715f4 | 2008-08-27 18:37:58 -0700 | [diff] [blame] | 397 | dma_addr_t sbus_map_single(struct device *dev, void *va, size_t len, int direction) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | { |
Paulius Zaleckas | efad798b | 2008-02-03 15:42:53 +0200 | [diff] [blame] | 399 | /* XXX why are some lengths signed, others unsigned? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | if (len <= 0) { |
| 401 | return 0; |
| 402 | } |
| 403 | /* XXX So what is maxphys for us and how do drivers know it? */ |
| 404 | if (len > 256*1024) { /* __get_free_pages() limit */ |
| 405 | return 0; |
| 406 | } |
David S. Miller | 260489f | 2008-08-26 23:00:58 -0700 | [diff] [blame] | 407 | return mmu_get_scsi_one(dev, va, len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | } |
| 409 | |
David S. Miller | 7a715f4 | 2008-08-27 18:37:58 -0700 | [diff] [blame] | 410 | void sbus_unmap_single(struct device *dev, dma_addr_t ba, size_t n, int direction) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | { |
David S. Miller | 260489f | 2008-08-26 23:00:58 -0700 | [diff] [blame] | 412 | mmu_release_scsi_one(dev, ba, n); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | } |
| 414 | |
David S. Miller | 7a715f4 | 2008-08-27 18:37:58 -0700 | [diff] [blame] | 415 | int sbus_map_sg(struct device *dev, struct scatterlist *sg, int n, int direction) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | { |
David S. Miller | 260489f | 2008-08-26 23:00:58 -0700 | [diff] [blame] | 417 | mmu_get_scsi_sgl(dev, sg, n); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | |
| 419 | /* |
| 420 | * XXX sparc64 can return a partial length here. sun4c should do this |
| 421 | * but it currently panics if it can't fulfill the request - Anton |
| 422 | */ |
| 423 | return n; |
| 424 | } |
| 425 | |
David S. Miller | 7a715f4 | 2008-08-27 18:37:58 -0700 | [diff] [blame] | 426 | void sbus_unmap_sg(struct device *dev, struct scatterlist *sg, int n, int direction) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | { |
David S. Miller | 260489f | 2008-08-26 23:00:58 -0700 | [diff] [blame] | 428 | mmu_release_scsi_sgl(dev, sg, n); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | /* |
| 432 | */ |
David S. Miller | 7a715f4 | 2008-08-27 18:37:58 -0700 | [diff] [blame] | 433 | void sbus_dma_sync_single_for_cpu(struct device *dev, dma_addr_t ba, size_t size, int direction) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | { |
| 435 | #if 0 |
| 436 | unsigned long va; |
| 437 | struct resource *res; |
| 438 | |
| 439 | /* We do not need the resource, just print a message if invalid. */ |
| 440 | res = _sparc_find_resource(&_sparc_dvma, ba); |
| 441 | if (res == NULL) |
| 442 | panic("sbus_dma_sync_single: 0x%x\n", ba); |
| 443 | |
| 444 | va = page_address(mmu_translate_dvma(ba)); /* XXX higmem */ |
| 445 | /* |
| 446 | * XXX This bogosity will be fixed with the iommu rewrite coming soon |
| 447 | * to a kernel near you. - Anton |
| 448 | */ |
| 449 | /* mmu_inval_dma_area(va, (size + PAGE_SIZE-1) & PAGE_MASK); */ |
| 450 | #endif |
| 451 | } |
| 452 | |
David S. Miller | 7a715f4 | 2008-08-27 18:37:58 -0700 | [diff] [blame] | 453 | void sbus_dma_sync_single_for_device(struct device *dev, dma_addr_t ba, size_t size, int direction) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | { |
| 455 | #if 0 |
| 456 | unsigned long va; |
| 457 | struct resource *res; |
| 458 | |
| 459 | /* We do not need the resource, just print a message if invalid. */ |
| 460 | res = _sparc_find_resource(&_sparc_dvma, ba); |
| 461 | if (res == NULL) |
| 462 | panic("sbus_dma_sync_single: 0x%x\n", ba); |
| 463 | |
| 464 | va = page_address(mmu_translate_dvma(ba)); /* XXX higmem */ |
| 465 | /* |
| 466 | * XXX This bogosity will be fixed with the iommu rewrite coming soon |
| 467 | * to a kernel near you. - Anton |
| 468 | */ |
| 469 | /* mmu_inval_dma_area(va, (size + PAGE_SIZE-1) & PAGE_MASK); */ |
| 470 | #endif |
| 471 | } |
| 472 | |
David S. Miller | 576c352 | 2006-06-23 15:55:45 -0700 | [diff] [blame] | 473 | /* Support code for sbus_init(). */ |
| 474 | /* |
| 475 | * XXX This functions appears to be a distorted version of |
| 476 | * prom_sbus_ranges_init(), with all sun4d stuff cut away. |
| 477 | * Ask DaveM what is going on here, how is sun4d supposed to work... XXX |
| 478 | */ |
| 479 | /* added back sun4d patch from Thomas Bogendoerfer - should be OK (crn) */ |
| 480 | void __init sbus_arch_bus_ranges_init(struct device_node *pn, struct sbus_bus *sbus) |
| 481 | { |
| 482 | int parent_node = pn->node; |
| 483 | |
| 484 | if (sparc_cpu_model == sun4d) { |
| 485 | struct linux_prom_ranges iounit_ranges[PROMREG_MAX]; |
| 486 | int num_iounit_ranges, len; |
| 487 | |
| 488 | len = prom_getproperty(parent_node, "ranges", |
| 489 | (char *) iounit_ranges, |
| 490 | sizeof (iounit_ranges)); |
| 491 | if (len != -1) { |
| 492 | num_iounit_ranges = |
| 493 | (len / sizeof(struct linux_prom_ranges)); |
| 494 | prom_adjust_ranges(sbus->sbus_ranges, |
| 495 | sbus->num_sbus_ranges, |
| 496 | iounit_ranges, num_iounit_ranges); |
| 497 | } |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | void __init sbus_setup_iommu(struct sbus_bus *sbus, struct device_node *dp) |
| 502 | { |
Al Viro | 5932ef0 | 2006-09-23 01:26:02 +0100 | [diff] [blame] | 503 | #ifndef CONFIG_SUN4 |
David S. Miller | 576c352 | 2006-06-23 15:55:45 -0700 | [diff] [blame] | 504 | struct device_node *parent = dp->parent; |
| 505 | |
| 506 | if (sparc_cpu_model != sun4d && |
| 507 | parent != NULL && |
David S. Miller | e003934 | 2008-08-25 22:47:20 -0700 | [diff] [blame] | 508 | !strcmp(parent->name, "iommu")) |
| 509 | iommu_init(parent, sbus); |
David S. Miller | 576c352 | 2006-06-23 15:55:45 -0700 | [diff] [blame] | 510 | |
David S. Miller | e003934 | 2008-08-25 22:47:20 -0700 | [diff] [blame] | 511 | if (sparc_cpu_model == sun4d) |
| 512 | iounit_init(sbus); |
Al Viro | 5932ef0 | 2006-09-23 01:26:02 +0100 | [diff] [blame] | 513 | #endif |
David S. Miller | 576c352 | 2006-06-23 15:55:45 -0700 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | void __init sbus_setup_arch_props(struct sbus_bus *sbus, struct device_node *dp) |
| 517 | { |
| 518 | if (sparc_cpu_model == sun4d) { |
| 519 | struct device_node *parent = dp->parent; |
| 520 | |
| 521 | sbus->devid = of_getintprop_default(parent, "device-id", 0); |
| 522 | sbus->board = of_getintprop_default(parent, "board#", 0); |
| 523 | } |
| 524 | } |
| 525 | |
| 526 | int __init sbus_arch_preinit(void) |
| 527 | { |
David S. Miller | 576c352 | 2006-06-23 15:55:45 -0700 | [diff] [blame] | 528 | register_proc_sparc_ioport(); |
| 529 | |
| 530 | #ifdef CONFIG_SUN4 |
| 531 | { |
| 532 | extern void sun4_dvma_init(void); |
| 533 | sun4_dvma_init(); |
| 534 | } |
| 535 | return 1; |
| 536 | #else |
| 537 | return 0; |
| 538 | #endif |
| 539 | } |
| 540 | |
| 541 | void __init sbus_arch_postinit(void) |
| 542 | { |
| 543 | if (sparc_cpu_model == sun4d) { |
| 544 | extern void sun4d_init_sbi_irq(void); |
| 545 | sun4d_init_sbi_irq(); |
| 546 | } |
| 547 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | #endif /* CONFIG_SBUS */ |
| 549 | |
| 550 | #ifdef CONFIG_PCI |
| 551 | |
| 552 | /* Allocate and map kernel buffer using consistent mode DMA for a device. |
| 553 | * hwdev should be valid struct pci_dev pointer for PCI devices. |
| 554 | */ |
| 555 | void *pci_alloc_consistent(struct pci_dev *pdev, size_t len, dma_addr_t *pba) |
| 556 | { |
| 557 | unsigned long len_total = (len + PAGE_SIZE-1) & PAGE_MASK; |
| 558 | unsigned long va; |
| 559 | struct resource *res; |
| 560 | int order; |
| 561 | |
| 562 | if (len == 0) { |
| 563 | return NULL; |
| 564 | } |
| 565 | if (len > 256*1024) { /* __get_free_pages() limit */ |
| 566 | return NULL; |
| 567 | } |
| 568 | |
| 569 | order = get_order(len_total); |
| 570 | va = __get_free_pages(GFP_KERNEL, order); |
| 571 | if (va == 0) { |
| 572 | printk("pci_alloc_consistent: no %ld pages\n", len_total>>PAGE_SHIFT); |
| 573 | return NULL; |
| 574 | } |
| 575 | |
Yan Burman | c80892d | 2006-11-30 17:07:04 -0800 | [diff] [blame] | 576 | if ((res = kzalloc(sizeof(struct resource), GFP_KERNEL)) == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | free_pages(va, order); |
| 578 | printk("pci_alloc_consistent: no core\n"); |
| 579 | return NULL; |
| 580 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | |
| 582 | if (allocate_resource(&_sparc_dvma, res, len_total, |
| 583 | _sparc_dvma.start, _sparc_dvma.end, PAGE_SIZE, NULL, NULL) != 0) { |
| 584 | printk("pci_alloc_consistent: cannot occupy 0x%lx", len_total); |
| 585 | free_pages(va, order); |
| 586 | kfree(res); |
| 587 | return NULL; |
| 588 | } |
| 589 | mmu_inval_dma_area(va, len_total); |
| 590 | #if 0 |
| 591 | /* P3 */ printk("pci_alloc_consistent: kva %lx uncva %lx phys %lx size %lx\n", |
| 592 | (long)va, (long)res->start, (long)virt_to_phys(va), len_total); |
| 593 | #endif |
| 594 | sparc_mapiorange(0, virt_to_phys(va), res->start, len_total); |
| 595 | |
| 596 | *pba = virt_to_phys(va); /* equals virt_to_bus (R.I.P.) for us. */ |
| 597 | return (void *) res->start; |
| 598 | } |
| 599 | |
| 600 | /* Free and unmap a consistent DMA buffer. |
| 601 | * cpu_addr is what was returned from pci_alloc_consistent, |
| 602 | * size must be the same as what as passed into pci_alloc_consistent, |
| 603 | * and likewise dma_addr must be the same as what *dma_addrp was set to. |
| 604 | * |
Simon Arlott | d1a78c3 | 2007-05-11 13:51:23 -0700 | [diff] [blame] | 605 | * References to the memory and mappings associated with cpu_addr/dma_addr |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | * past this call are illegal. |
| 607 | */ |
| 608 | void pci_free_consistent(struct pci_dev *pdev, size_t n, void *p, dma_addr_t ba) |
| 609 | { |
| 610 | struct resource *res; |
| 611 | unsigned long pgp; |
| 612 | |
| 613 | if ((res = _sparc_find_resource(&_sparc_dvma, |
| 614 | (unsigned long)p)) == NULL) { |
| 615 | printk("pci_free_consistent: cannot free %p\n", p); |
| 616 | return; |
| 617 | } |
| 618 | |
| 619 | if (((unsigned long)p & (PAGE_SIZE-1)) != 0) { |
| 620 | printk("pci_free_consistent: unaligned va %p\n", p); |
| 621 | return; |
| 622 | } |
| 623 | |
| 624 | n = (n + PAGE_SIZE-1) & PAGE_MASK; |
| 625 | if ((res->end-res->start)+1 != n) { |
| 626 | printk("pci_free_consistent: region 0x%lx asked 0x%lx\n", |
| 627 | (long)((res->end-res->start)+1), (long)n); |
| 628 | return; |
| 629 | } |
| 630 | |
| 631 | pgp = (unsigned long) phys_to_virt(ba); /* bus_to_virt actually */ |
| 632 | mmu_inval_dma_area(pgp, n); |
| 633 | sparc_unmapiorange((unsigned long)p, n); |
| 634 | |
| 635 | release_resource(res); |
| 636 | kfree(res); |
| 637 | |
| 638 | free_pages(pgp, get_order(n)); |
| 639 | } |
| 640 | |
| 641 | /* Map a single buffer of the indicated size for DMA in streaming mode. |
| 642 | * The 32-bit bus address to use is returned. |
| 643 | * |
| 644 | * Once the device is given the dma address, the device owns this memory |
| 645 | * until either pci_unmap_single or pci_dma_sync_single_* is performed. |
| 646 | */ |
| 647 | dma_addr_t pci_map_single(struct pci_dev *hwdev, void *ptr, size_t size, |
| 648 | int direction) |
| 649 | { |
Eric Sesterhenn | 30d4d1f | 2006-03-10 02:55:20 -0800 | [diff] [blame] | 650 | BUG_ON(direction == PCI_DMA_NONE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | /* IIep is write-through, not flushing. */ |
| 652 | return virt_to_phys(ptr); |
| 653 | } |
| 654 | |
| 655 | /* Unmap a single streaming mode DMA translation. The dma_addr and size |
| 656 | * must match what was provided for in a previous pci_map_single call. All |
| 657 | * other usages are undefined. |
| 658 | * |
| 659 | * After this call, reads by the cpu to the buffer are guaranteed to see |
| 660 | * whatever the device wrote there. |
| 661 | */ |
| 662 | void pci_unmap_single(struct pci_dev *hwdev, dma_addr_t ba, size_t size, |
| 663 | int direction) |
| 664 | { |
Eric Sesterhenn | 30d4d1f | 2006-03-10 02:55:20 -0800 | [diff] [blame] | 665 | BUG_ON(direction == PCI_DMA_NONE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | if (direction != PCI_DMA_TODEVICE) { |
| 667 | mmu_inval_dma_area((unsigned long)phys_to_virt(ba), |
| 668 | (size + PAGE_SIZE-1) & PAGE_MASK); |
| 669 | } |
| 670 | } |
| 671 | |
| 672 | /* |
| 673 | * Same as pci_map_single, but with pages. |
| 674 | */ |
| 675 | dma_addr_t pci_map_page(struct pci_dev *hwdev, struct page *page, |
| 676 | unsigned long offset, size_t size, int direction) |
| 677 | { |
Eric Sesterhenn | 30d4d1f | 2006-03-10 02:55:20 -0800 | [diff] [blame] | 678 | BUG_ON(direction == PCI_DMA_NONE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | /* IIep is write-through, not flushing. */ |
| 680 | return page_to_phys(page) + offset; |
| 681 | } |
| 682 | |
| 683 | void pci_unmap_page(struct pci_dev *hwdev, |
| 684 | dma_addr_t dma_address, size_t size, int direction) |
| 685 | { |
Eric Sesterhenn | 30d4d1f | 2006-03-10 02:55:20 -0800 | [diff] [blame] | 686 | BUG_ON(direction == PCI_DMA_NONE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | /* mmu_inval_dma_area XXX */ |
| 688 | } |
| 689 | |
| 690 | /* Map a set of buffers described by scatterlist in streaming |
| 691 | * mode for DMA. This is the scather-gather version of the |
| 692 | * above pci_map_single interface. Here the scatter gather list |
| 693 | * elements are each tagged with the appropriate dma address |
| 694 | * and length. They are obtained via sg_dma_{address,length}(SG). |
| 695 | * |
| 696 | * NOTE: An implementation may be able to use a smaller number of |
| 697 | * DMA address/length pairs than there are SG table elements. |
| 698 | * (for example via virtual mapping capabilities) |
| 699 | * The routine returns the number of addr/length pairs actually |
| 700 | * used, at most nents. |
| 701 | * |
| 702 | * Device ownership issues as mentioned above for pci_map_single are |
| 703 | * the same here. |
| 704 | */ |
Jens Axboe | 0912a5d | 2007-05-14 15:44:38 +0200 | [diff] [blame] | 705 | int pci_map_sg(struct pci_dev *hwdev, struct scatterlist *sgl, int nents, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | int direction) |
| 707 | { |
Jens Axboe | 0912a5d | 2007-05-14 15:44:38 +0200 | [diff] [blame] | 708 | struct scatterlist *sg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | int n; |
| 710 | |
Eric Sesterhenn | 30d4d1f | 2006-03-10 02:55:20 -0800 | [diff] [blame] | 711 | BUG_ON(direction == PCI_DMA_NONE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | /* IIep is write-through, not flushing. */ |
Jens Axboe | 0912a5d | 2007-05-14 15:44:38 +0200 | [diff] [blame] | 713 | for_each_sg(sgl, sg, nents, n) { |
Jens Axboe | 58b053e | 2007-10-22 20:02:46 +0200 | [diff] [blame] | 714 | BUG_ON(page_address(sg_page(sg)) == NULL); |
| 715 | sg->dvma_address = virt_to_phys(sg_virt(sg)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | sg->dvma_length = sg->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | } |
| 718 | return nents; |
| 719 | } |
| 720 | |
| 721 | /* Unmap a set of streaming mode DMA translations. |
| 722 | * Again, cpu read rules concerning calls here are the same as for |
| 723 | * pci_unmap_single() above. |
| 724 | */ |
Jens Axboe | 0912a5d | 2007-05-14 15:44:38 +0200 | [diff] [blame] | 725 | void pci_unmap_sg(struct pci_dev *hwdev, struct scatterlist *sgl, int nents, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | int direction) |
| 727 | { |
Jens Axboe | 0912a5d | 2007-05-14 15:44:38 +0200 | [diff] [blame] | 728 | struct scatterlist *sg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | int n; |
| 730 | |
Eric Sesterhenn | 30d4d1f | 2006-03-10 02:55:20 -0800 | [diff] [blame] | 731 | BUG_ON(direction == PCI_DMA_NONE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | if (direction != PCI_DMA_TODEVICE) { |
Jens Axboe | 0912a5d | 2007-05-14 15:44:38 +0200 | [diff] [blame] | 733 | for_each_sg(sgl, sg, nents, n) { |
Jens Axboe | 58b053e | 2007-10-22 20:02:46 +0200 | [diff] [blame] | 734 | BUG_ON(page_address(sg_page(sg)) == NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | mmu_inval_dma_area( |
Jens Axboe | 58b053e | 2007-10-22 20:02:46 +0200 | [diff] [blame] | 736 | (unsigned long) page_address(sg_page(sg)), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | (sg->length + PAGE_SIZE-1) & PAGE_MASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | } |
| 739 | } |
| 740 | } |
| 741 | |
| 742 | /* Make physical memory consistent for a single |
| 743 | * streaming mode DMA translation before or after a transfer. |
| 744 | * |
| 745 | * If you perform a pci_map_single() but wish to interrogate the |
| 746 | * buffer using the cpu, yet do not wish to teardown the PCI dma |
| 747 | * mapping, you must call this function before doing so. At the |
| 748 | * next point you give the PCI dma address back to the card, you |
| 749 | * must first perform a pci_dma_sync_for_device, and then the |
| 750 | * device again owns the buffer. |
| 751 | */ |
| 752 | void pci_dma_sync_single_for_cpu(struct pci_dev *hwdev, dma_addr_t ba, size_t size, int direction) |
| 753 | { |
Eric Sesterhenn | 30d4d1f | 2006-03-10 02:55:20 -0800 | [diff] [blame] | 754 | BUG_ON(direction == PCI_DMA_NONE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | if (direction != PCI_DMA_TODEVICE) { |
| 756 | mmu_inval_dma_area((unsigned long)phys_to_virt(ba), |
| 757 | (size + PAGE_SIZE-1) & PAGE_MASK); |
| 758 | } |
| 759 | } |
| 760 | |
| 761 | void pci_dma_sync_single_for_device(struct pci_dev *hwdev, dma_addr_t ba, size_t size, int direction) |
| 762 | { |
Eric Sesterhenn | 30d4d1f | 2006-03-10 02:55:20 -0800 | [diff] [blame] | 763 | BUG_ON(direction == PCI_DMA_NONE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | if (direction != PCI_DMA_TODEVICE) { |
| 765 | mmu_inval_dma_area((unsigned long)phys_to_virt(ba), |
| 766 | (size + PAGE_SIZE-1) & PAGE_MASK); |
| 767 | } |
| 768 | } |
| 769 | |
| 770 | /* Make physical memory consistent for a set of streaming |
| 771 | * mode DMA translations after a transfer. |
| 772 | * |
| 773 | * The same as pci_dma_sync_single_* but for a scatter-gather list, |
| 774 | * same rules and usage. |
| 775 | */ |
Jens Axboe | 0912a5d | 2007-05-14 15:44:38 +0200 | [diff] [blame] | 776 | void pci_dma_sync_sg_for_cpu(struct pci_dev *hwdev, struct scatterlist *sgl, int nents, int direction) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | { |
Jens Axboe | 0912a5d | 2007-05-14 15:44:38 +0200 | [diff] [blame] | 778 | struct scatterlist *sg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | int n; |
| 780 | |
Eric Sesterhenn | 30d4d1f | 2006-03-10 02:55:20 -0800 | [diff] [blame] | 781 | BUG_ON(direction == PCI_DMA_NONE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | if (direction != PCI_DMA_TODEVICE) { |
Jens Axboe | 0912a5d | 2007-05-14 15:44:38 +0200 | [diff] [blame] | 783 | for_each_sg(sgl, sg, nents, n) { |
Jens Axboe | 58b053e | 2007-10-22 20:02:46 +0200 | [diff] [blame] | 784 | BUG_ON(page_address(sg_page(sg)) == NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | mmu_inval_dma_area( |
Jens Axboe | 58b053e | 2007-10-22 20:02:46 +0200 | [diff] [blame] | 786 | (unsigned long) page_address(sg_page(sg)), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | (sg->length + PAGE_SIZE-1) & PAGE_MASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | } |
| 789 | } |
| 790 | } |
| 791 | |
Jens Axboe | 0912a5d | 2007-05-14 15:44:38 +0200 | [diff] [blame] | 792 | void pci_dma_sync_sg_for_device(struct pci_dev *hwdev, struct scatterlist *sgl, int nents, int direction) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | { |
Jens Axboe | 0912a5d | 2007-05-14 15:44:38 +0200 | [diff] [blame] | 794 | struct scatterlist *sg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | int n; |
| 796 | |
Eric Sesterhenn | 30d4d1f | 2006-03-10 02:55:20 -0800 | [diff] [blame] | 797 | BUG_ON(direction == PCI_DMA_NONE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | if (direction != PCI_DMA_TODEVICE) { |
Jens Axboe | 0912a5d | 2007-05-14 15:44:38 +0200 | [diff] [blame] | 799 | for_each_sg(sgl, sg, nents, n) { |
Jens Axboe | 58b053e | 2007-10-22 20:02:46 +0200 | [diff] [blame] | 800 | BUG_ON(page_address(sg_page(sg)) == NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | mmu_inval_dma_area( |
Jens Axboe | 58b053e | 2007-10-22 20:02:46 +0200 | [diff] [blame] | 802 | (unsigned long) page_address(sg_page(sg)), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | (sg->length + PAGE_SIZE-1) & PAGE_MASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | } |
| 805 | } |
| 806 | } |
| 807 | #endif /* CONFIG_PCI */ |
| 808 | |
| 809 | #ifdef CONFIG_PROC_FS |
| 810 | |
| 811 | static int |
| 812 | _sparc_io_get_info(char *buf, char **start, off_t fpos, int length, int *eof, |
| 813 | void *data) |
| 814 | { |
| 815 | char *p = buf, *e = buf + length; |
| 816 | struct resource *r; |
| 817 | const char *nm; |
| 818 | |
| 819 | for (r = ((struct resource *)data)->child; r != NULL; r = r->sibling) { |
| 820 | if (p + 32 >= e) /* Better than nothing */ |
| 821 | break; |
| 822 | if ((nm = r->name) == 0) nm = "???"; |
Greg Kroah-Hartman | 685143ac | 2006-06-12 15:18:31 -0700 | [diff] [blame] | 823 | p += sprintf(p, "%016llx-%016llx: %s\n", |
| 824 | (unsigned long long)r->start, |
| 825 | (unsigned long long)r->end, nm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | } |
| 827 | |
| 828 | return p-buf; |
| 829 | } |
| 830 | |
| 831 | #endif /* CONFIG_PROC_FS */ |
| 832 | |
| 833 | /* |
| 834 | * This is a version of find_resource and it belongs to kernel/resource.c. |
| 835 | * Until we have agreement with Linus and Martin, it lingers here. |
| 836 | * |
| 837 | * XXX Too slow. Can have 8192 DVMA pages on sun4m in the worst case. |
| 838 | * This probably warrants some sort of hashing. |
| 839 | */ |
Adrian Bunk | c61c65c | 2008-06-05 11:40:58 -0700 | [diff] [blame] | 840 | static struct resource *_sparc_find_resource(struct resource *root, |
| 841 | unsigned long hit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | { |
| 843 | struct resource *tmp; |
| 844 | |
| 845 | for (tmp = root->child; tmp != 0; tmp = tmp->sibling) { |
| 846 | if (tmp->start <= hit && tmp->end >= hit) |
| 847 | return tmp; |
| 848 | } |
| 849 | return NULL; |
| 850 | } |
| 851 | |
Adrian Bunk | c61c65c | 2008-06-05 11:40:58 -0700 | [diff] [blame] | 852 | static void register_proc_sparc_ioport(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | { |
| 854 | #ifdef CONFIG_PROC_FS |
| 855 | create_proc_read_entry("io_map",0,NULL,_sparc_io_get_info,&sparc_iomap); |
| 856 | create_proc_read_entry("dvma_map",0,NULL,_sparc_io_get_info,&_sparc_dvma); |
| 857 | #endif |
| 858 | } |