sparc: Remove SBUS layer resource and irq handling.
[firefly-linux-kernel-4.4.55.git] / arch / sparc / kernel / ioport.c
1 /*
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
28 #include <linux/module.h>
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>
38 #include <linux/scatterlist.h>
39 #include <linux/of_device.h>
40
41 #include <asm/io.h>
42 #include <asm/vaddrs.h>
43 #include <asm/oplib.h>
44 #include <asm/prom.h>
45 #include <asm/sbus.h>
46 #include <asm/page.h>
47 #include <asm/pgalloc.h>
48 #include <asm/dma.h>
49 #include <asm/iommu.h>
50 #include <asm/io-unit.h>
51
52 #include "dma.h"
53
54 #define mmu_inval_dma_area(p, l)        /* Anton pulled it out for 2.4.0-xx */
55
56 static struct resource *_sparc_find_resource(struct resource *r,
57                                              unsigned long);
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
64 static void register_proc_sparc_ioport(void);
65
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
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
164 void of_iounmap(struct resource *res, void __iomem *base, unsigned long size)
165 {
166         iounmap(base);
167 }
168 EXPORT_SYMBOL(of_iounmap);
169
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
235         return (void __iomem *)(unsigned long)(res->start + offset);
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;
246         BUG_ON((plen & (PAGE_SIZE-1)) != 0);
247         sparc_unmapiorange(res->start, plen);
248         release_resource(res);
249 }
250
251 #ifdef CONFIG_SBUS
252
253 void sbus_set_sbus64(struct device *dev, int x)
254 {
255         printk("sbus_set_sbus64: unsupported\n");
256 }
257
258 /*
259  * Allocate a chunk of memory suitable for DMA.
260  * Typically devices use them for control blocks.
261  * CPU may access them without any explicit flushing.
262  */
263 void *sbus_alloc_consistent(struct device *dev, long len, u32 *dma_addrp)
264 {
265         struct of_device *op = to_of_device(dev);
266         unsigned long len_total = (len + PAGE_SIZE-1) & PAGE_MASK;
267         unsigned long va;
268         struct resource *res;
269         int order;
270
271         /* XXX why are some lengths signed, others unsigned? */
272         if (len <= 0) {
273                 return NULL;
274         }
275         /* XXX So what is maxphys for us and how do drivers know it? */
276         if (len > 256*1024) {                   /* __get_free_pages() limit */
277                 return NULL;
278         }
279
280         order = get_order(len_total);
281         if ((va = __get_free_pages(GFP_KERNEL|__GFP_COMP, order)) == 0)
282                 goto err_nopages;
283
284         if ((res = kzalloc(sizeof(struct resource), GFP_KERNEL)) == NULL)
285                 goto err_nomem;
286
287         if (allocate_resource(&_sparc_dvma, res, len_total,
288             _sparc_dvma.start, _sparc_dvma.end, PAGE_SIZE, NULL, NULL) != 0) {
289                 printk("sbus_alloc_consistent: cannot occupy 0x%lx", len_total);
290                 goto err_nova;
291         }
292         mmu_inval_dma_area(va, len_total);
293         // XXX The mmu_map_dma_area does this for us below, see comments.
294         // sparc_mapiorange(0, virt_to_phys(va), res->start, len_total);
295         /*
296          * XXX That's where sdev would be used. Currently we load
297          * all iommu tables with the same translations.
298          */
299         if (mmu_map_dma_area(dev, dma_addrp, va, res->start, len_total) != 0)
300                 goto err_noiommu;
301
302         res->name = op->node->name;
303
304         return (void *)(unsigned long)res->start;
305
306 err_noiommu:
307         release_resource(res);
308 err_nova:
309         free_pages(va, order);
310 err_nomem:
311         kfree(res);
312 err_nopages:
313         return NULL;
314 }
315
316 void sbus_free_consistent(struct device *dev, long n, void *p, u32 ba)
317 {
318         struct resource *res;
319         struct page *pgv;
320
321         if ((res = _sparc_find_resource(&_sparc_dvma,
322             (unsigned long)p)) == NULL) {
323                 printk("sbus_free_consistent: cannot free %p\n", p);
324                 return;
325         }
326
327         if (((unsigned long)p & (PAGE_SIZE-1)) != 0) {
328                 printk("sbus_free_consistent: unaligned va %p\n", p);
329                 return;
330         }
331
332         n = (n + PAGE_SIZE-1) & PAGE_MASK;
333         if ((res->end-res->start)+1 != n) {
334                 printk("sbus_free_consistent: region 0x%lx asked 0x%lx\n",
335                     (long)((res->end-res->start)+1), n);
336                 return;
337         }
338
339         release_resource(res);
340         kfree(res);
341
342         /* mmu_inval_dma_area(va, n); */ /* it's consistent, isn't it */
343         pgv = virt_to_page(p);
344         mmu_unmap_dma_area(dev, ba, n);
345
346         __free_pages(pgv, get_order(n));
347 }
348
349 /*
350  * Map a chunk of memory so that devices can see it.
351  * CPU view of this memory may be inconsistent with
352  * a device view and explicit flushing is necessary.
353  */
354 dma_addr_t sbus_map_single(struct device *dev, void *va, size_t len, int direction)
355 {
356         /* XXX why are some lengths signed, others unsigned? */
357         if (len <= 0) {
358                 return 0;
359         }
360         /* XXX So what is maxphys for us and how do drivers know it? */
361         if (len > 256*1024) {                   /* __get_free_pages() limit */
362                 return 0;
363         }
364         return mmu_get_scsi_one(dev, va, len);
365 }
366
367 void sbus_unmap_single(struct device *dev, dma_addr_t ba, size_t n, int direction)
368 {
369         mmu_release_scsi_one(dev, ba, n);
370 }
371
372 int sbus_map_sg(struct device *dev, struct scatterlist *sg, int n, int direction)
373 {
374         mmu_get_scsi_sgl(dev, sg, n);
375
376         /*
377          * XXX sparc64 can return a partial length here. sun4c should do this
378          * but it currently panics if it can't fulfill the request - Anton
379          */
380         return n;
381 }
382
383 void sbus_unmap_sg(struct device *dev, struct scatterlist *sg, int n, int direction)
384 {
385         mmu_release_scsi_sgl(dev, sg, n);
386 }
387
388 void sbus_dma_sync_single_for_cpu(struct device *dev, dma_addr_t ba, size_t size, int direction)
389 {
390 }
391
392 void sbus_dma_sync_single_for_device(struct device *dev, dma_addr_t ba, size_t size, int direction)
393 {
394 }
395
396 /* Support code for sbus_init().  */
397 void __init sbus_setup_iommu(struct sbus_bus *sbus, struct device_node *dp)
398 {
399 #ifndef CONFIG_SUN4
400         struct device_node *parent = dp->parent;
401
402         if (sparc_cpu_model != sun4d &&
403             parent != NULL &&
404             !strcmp(parent->name, "iommu"))
405                 iommu_init(parent, sbus);
406
407         if (sparc_cpu_model == sun4d)
408                 iounit_init(sbus);
409 #endif
410 }
411
412 int __init sbus_arch_preinit(void)
413 {
414         register_proc_sparc_ioport();
415
416 #ifdef CONFIG_SUN4
417         {
418                 extern void sun4_dvma_init(void);
419                 sun4_dvma_init();
420         }
421         return 1;
422 #else
423         return 0;
424 #endif
425 }
426
427 void __init sbus_arch_postinit(void)
428 {
429         if (sparc_cpu_model == sun4d) {
430                 extern void sun4d_init_sbi_irq(void);
431                 sun4d_init_sbi_irq();
432         }
433 }
434 #endif /* CONFIG_SBUS */
435
436 #ifdef CONFIG_PCI
437
438 /* Allocate and map kernel buffer using consistent mode DMA for a device.
439  * hwdev should be valid struct pci_dev pointer for PCI devices.
440  */
441 void *pci_alloc_consistent(struct pci_dev *pdev, size_t len, dma_addr_t *pba)
442 {
443         unsigned long len_total = (len + PAGE_SIZE-1) & PAGE_MASK;
444         unsigned long va;
445         struct resource *res;
446         int order;
447
448         if (len == 0) {
449                 return NULL;
450         }
451         if (len > 256*1024) {                   /* __get_free_pages() limit */
452                 return NULL;
453         }
454
455         order = get_order(len_total);
456         va = __get_free_pages(GFP_KERNEL, order);
457         if (va == 0) {
458                 printk("pci_alloc_consistent: no %ld pages\n", len_total>>PAGE_SHIFT);
459                 return NULL;
460         }
461
462         if ((res = kzalloc(sizeof(struct resource), GFP_KERNEL)) == NULL) {
463                 free_pages(va, order);
464                 printk("pci_alloc_consistent: no core\n");
465                 return NULL;
466         }
467
468         if (allocate_resource(&_sparc_dvma, res, len_total,
469             _sparc_dvma.start, _sparc_dvma.end, PAGE_SIZE, NULL, NULL) != 0) {
470                 printk("pci_alloc_consistent: cannot occupy 0x%lx", len_total);
471                 free_pages(va, order);
472                 kfree(res);
473                 return NULL;
474         }
475         mmu_inval_dma_area(va, len_total);
476 #if 0
477 /* P3 */ printk("pci_alloc_consistent: kva %lx uncva %lx phys %lx size %lx\n",
478   (long)va, (long)res->start, (long)virt_to_phys(va), len_total);
479 #endif
480         sparc_mapiorange(0, virt_to_phys(va), res->start, len_total);
481
482         *pba = virt_to_phys(va); /* equals virt_to_bus (R.I.P.) for us. */
483         return (void *) res->start;
484 }
485
486 /* Free and unmap a consistent DMA buffer.
487  * cpu_addr is what was returned from pci_alloc_consistent,
488  * size must be the same as what as passed into pci_alloc_consistent,
489  * and likewise dma_addr must be the same as what *dma_addrp was set to.
490  *
491  * References to the memory and mappings associated with cpu_addr/dma_addr
492  * past this call are illegal.
493  */
494 void pci_free_consistent(struct pci_dev *pdev, size_t n, void *p, dma_addr_t ba)
495 {
496         struct resource *res;
497         unsigned long pgp;
498
499         if ((res = _sparc_find_resource(&_sparc_dvma,
500             (unsigned long)p)) == NULL) {
501                 printk("pci_free_consistent: cannot free %p\n", p);
502                 return;
503         }
504
505         if (((unsigned long)p & (PAGE_SIZE-1)) != 0) {
506                 printk("pci_free_consistent: unaligned va %p\n", p);
507                 return;
508         }
509
510         n = (n + PAGE_SIZE-1) & PAGE_MASK;
511         if ((res->end-res->start)+1 != n) {
512                 printk("pci_free_consistent: region 0x%lx asked 0x%lx\n",
513                     (long)((res->end-res->start)+1), (long)n);
514                 return;
515         }
516
517         pgp = (unsigned long) phys_to_virt(ba); /* bus_to_virt actually */
518         mmu_inval_dma_area(pgp, n);
519         sparc_unmapiorange((unsigned long)p, n);
520
521         release_resource(res);
522         kfree(res);
523
524         free_pages(pgp, get_order(n));
525 }
526
527 /* Map a single buffer of the indicated size for DMA in streaming mode.
528  * The 32-bit bus address to use is returned.
529  *
530  * Once the device is given the dma address, the device owns this memory
531  * until either pci_unmap_single or pci_dma_sync_single_* is performed.
532  */
533 dma_addr_t pci_map_single(struct pci_dev *hwdev, void *ptr, size_t size,
534     int direction)
535 {
536         BUG_ON(direction == PCI_DMA_NONE);
537         /* IIep is write-through, not flushing. */
538         return virt_to_phys(ptr);
539 }
540
541 /* Unmap a single streaming mode DMA translation.  The dma_addr and size
542  * must match what was provided for in a previous pci_map_single call.  All
543  * other usages are undefined.
544  *
545  * After this call, reads by the cpu to the buffer are guaranteed to see
546  * whatever the device wrote there.
547  */
548 void pci_unmap_single(struct pci_dev *hwdev, dma_addr_t ba, size_t size,
549     int direction)
550 {
551         BUG_ON(direction == PCI_DMA_NONE);
552         if (direction != PCI_DMA_TODEVICE) {
553                 mmu_inval_dma_area((unsigned long)phys_to_virt(ba),
554                     (size + PAGE_SIZE-1) & PAGE_MASK);
555         }
556 }
557
558 /*
559  * Same as pci_map_single, but with pages.
560  */
561 dma_addr_t pci_map_page(struct pci_dev *hwdev, struct page *page,
562                         unsigned long offset, size_t size, int direction)
563 {
564         BUG_ON(direction == PCI_DMA_NONE);
565         /* IIep is write-through, not flushing. */
566         return page_to_phys(page) + offset;
567 }
568
569 void pci_unmap_page(struct pci_dev *hwdev,
570                         dma_addr_t dma_address, size_t size, int direction)
571 {
572         BUG_ON(direction == PCI_DMA_NONE);
573         /* mmu_inval_dma_area XXX */
574 }
575
576 /* Map a set of buffers described by scatterlist in streaming
577  * mode for DMA.  This is the scather-gather version of the
578  * above pci_map_single interface.  Here the scatter gather list
579  * elements are each tagged with the appropriate dma address
580  * and length.  They are obtained via sg_dma_{address,length}(SG).
581  *
582  * NOTE: An implementation may be able to use a smaller number of
583  *       DMA address/length pairs than there are SG table elements.
584  *       (for example via virtual mapping capabilities)
585  *       The routine returns the number of addr/length pairs actually
586  *       used, at most nents.
587  *
588  * Device ownership issues as mentioned above for pci_map_single are
589  * the same here.
590  */
591 int pci_map_sg(struct pci_dev *hwdev, struct scatterlist *sgl, int nents,
592     int direction)
593 {
594         struct scatterlist *sg;
595         int n;
596
597         BUG_ON(direction == PCI_DMA_NONE);
598         /* IIep is write-through, not flushing. */
599         for_each_sg(sgl, sg, nents, n) {
600                 BUG_ON(page_address(sg_page(sg)) == NULL);
601                 sg->dvma_address = virt_to_phys(sg_virt(sg));
602                 sg->dvma_length = sg->length;
603         }
604         return nents;
605 }
606
607 /* Unmap a set of streaming mode DMA translations.
608  * Again, cpu read rules concerning calls here are the same as for
609  * pci_unmap_single() above.
610  */
611 void pci_unmap_sg(struct pci_dev *hwdev, struct scatterlist *sgl, int nents,
612     int direction)
613 {
614         struct scatterlist *sg;
615         int n;
616
617         BUG_ON(direction == PCI_DMA_NONE);
618         if (direction != PCI_DMA_TODEVICE) {
619                 for_each_sg(sgl, sg, nents, n) {
620                         BUG_ON(page_address(sg_page(sg)) == NULL);
621                         mmu_inval_dma_area(
622                             (unsigned long) page_address(sg_page(sg)),
623                             (sg->length + PAGE_SIZE-1) & PAGE_MASK);
624                 }
625         }
626 }
627
628 /* Make physical memory consistent for a single
629  * streaming mode DMA translation before or after a transfer.
630  *
631  * If you perform a pci_map_single() but wish to interrogate the
632  * buffer using the cpu, yet do not wish to teardown the PCI dma
633  * mapping, you must call this function before doing so.  At the
634  * next point you give the PCI dma address back to the card, you
635  * must first perform a pci_dma_sync_for_device, and then the
636  * device again owns the buffer.
637  */
638 void pci_dma_sync_single_for_cpu(struct pci_dev *hwdev, dma_addr_t ba, size_t size, int direction)
639 {
640         BUG_ON(direction == PCI_DMA_NONE);
641         if (direction != PCI_DMA_TODEVICE) {
642                 mmu_inval_dma_area((unsigned long)phys_to_virt(ba),
643                     (size + PAGE_SIZE-1) & PAGE_MASK);
644         }
645 }
646
647 void pci_dma_sync_single_for_device(struct pci_dev *hwdev, dma_addr_t ba, size_t size, int direction)
648 {
649         BUG_ON(direction == PCI_DMA_NONE);
650         if (direction != PCI_DMA_TODEVICE) {
651                 mmu_inval_dma_area((unsigned long)phys_to_virt(ba),
652                     (size + PAGE_SIZE-1) & PAGE_MASK);
653         }
654 }
655
656 /* Make physical memory consistent for a set of streaming
657  * mode DMA translations after a transfer.
658  *
659  * The same as pci_dma_sync_single_* but for a scatter-gather list,
660  * same rules and usage.
661  */
662 void pci_dma_sync_sg_for_cpu(struct pci_dev *hwdev, struct scatterlist *sgl, int nents, int direction)
663 {
664         struct scatterlist *sg;
665         int n;
666
667         BUG_ON(direction == PCI_DMA_NONE);
668         if (direction != PCI_DMA_TODEVICE) {
669                 for_each_sg(sgl, sg, nents, n) {
670                         BUG_ON(page_address(sg_page(sg)) == NULL);
671                         mmu_inval_dma_area(
672                             (unsigned long) page_address(sg_page(sg)),
673                             (sg->length + PAGE_SIZE-1) & PAGE_MASK);
674                 }
675         }
676 }
677
678 void pci_dma_sync_sg_for_device(struct pci_dev *hwdev, struct scatterlist *sgl, int nents, int direction)
679 {
680         struct scatterlist *sg;
681         int n;
682
683         BUG_ON(direction == PCI_DMA_NONE);
684         if (direction != PCI_DMA_TODEVICE) {
685                 for_each_sg(sgl, sg, nents, n) {
686                         BUG_ON(page_address(sg_page(sg)) == NULL);
687                         mmu_inval_dma_area(
688                             (unsigned long) page_address(sg_page(sg)),
689                             (sg->length + PAGE_SIZE-1) & PAGE_MASK);
690                 }
691         }
692 }
693 #endif /* CONFIG_PCI */
694
695 #ifdef CONFIG_PROC_FS
696
697 static int
698 _sparc_io_get_info(char *buf, char **start, off_t fpos, int length, int *eof,
699     void *data)
700 {
701         char *p = buf, *e = buf + length;
702         struct resource *r;
703         const char *nm;
704
705         for (r = ((struct resource *)data)->child; r != NULL; r = r->sibling) {
706                 if (p + 32 >= e)        /* Better than nothing */
707                         break;
708                 if ((nm = r->name) == 0) nm = "???";
709                 p += sprintf(p, "%016llx-%016llx: %s\n",
710                                 (unsigned long long)r->start,
711                                 (unsigned long long)r->end, nm);
712         }
713
714         return p-buf;
715 }
716
717 #endif /* CONFIG_PROC_FS */
718
719 /*
720  * This is a version of find_resource and it belongs to kernel/resource.c.
721  * Until we have agreement with Linus and Martin, it lingers here.
722  *
723  * XXX Too slow. Can have 8192 DVMA pages on sun4m in the worst case.
724  * This probably warrants some sort of hashing.
725  */
726 static struct resource *_sparc_find_resource(struct resource *root,
727                                              unsigned long hit)
728 {
729         struct resource *tmp;
730
731         for (tmp = root->child; tmp != 0; tmp = tmp->sibling) {
732                 if (tmp->start <= hit && tmp->end >= hit)
733                         return tmp;
734         }
735         return NULL;
736 }
737
738 static void register_proc_sparc_ioport(void)
739 {
740 #ifdef CONFIG_PROC_FS
741         create_proc_read_entry("io_map",0,NULL,_sparc_io_get_info,&sparc_iomap);
742         create_proc_read_entry("dvma_map",0,NULL,_sparc_io_get_info,&_sparc_dvma);
743 #endif
744 }