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