1 /* $Id: ioport.c,v 1.45 2001/10/30 04:54:21 davem Exp $
2 * ioport.c: Simple io mapping allocator.
4 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
5 * Copyright (C) 1995 Miguel de Icaza (miguel@nuclecu.unam.mx)
7 * 1996: sparc_free_io, 1999: ioremap()/iounmap() by Pete Zaitcev.
10 * <rth> zait: as long as pci_alloc_consistent produces something addressable,
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()))
17 * <zaitcev> Suppose I did this remap_it_my_way(virt_to_phys(get_free_page())).
19 * <zaitcev> Now, driver calls pci_free_consistent(with result of
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.
25 * <zaitcev> Sounds reasonable
28 #include <linux/config.h>
29 #include <linux/module.h>
30 #include <linux/sched.h>
31 #include <linux/kernel.h>
32 #include <linux/errno.h>
33 #include <linux/types.h>
34 #include <linux/ioport.h>
36 #include <linux/slab.h>
37 #include <linux/pci.h> /* struct pci_dev */
38 #include <linux/proc_fs.h>
41 #include <asm/vaddrs.h>
42 #include <asm/oplib.h>
44 #include <asm/of_device.h>
47 #include <asm/pgalloc.h>
50 #define mmu_inval_dma_area(p, l) /* Anton pulled it out for 2.4.0-xx */
52 struct resource
*_sparc_find_resource(struct resource
*r
, unsigned long);
54 static void __iomem
*_sparc_ioremap(struct resource
*res
, u32 bus
, u32 pa
, int sz
);
55 static void __iomem
*_sparc_alloc_io(unsigned int busno
, unsigned long phys
,
56 unsigned long size
, char *name
);
57 static void _sparc_free_io(struct resource
*res
);
59 /* This points to the next to use virtual memory for DVMA mappings */
60 static struct resource _sparc_dvma
= {
61 .name
= "sparc_dvma", .start
= DVMA_VADDR
, .end
= DVMA_END
- 1
63 /* This points to the start of I/O mappings, cluable from outside. */
64 /*ext*/ struct resource sparc_iomap
= {
65 .name
= "sparc_iomap", .start
= IOBASE_VADDR
, .end
= IOBASE_END
- 1
69 * Our mini-allocator...
70 * Boy this is gross! We need it because we must map I/O for
71 * timers and interrupt controller before the kmalloc is available.
75 #define XNRES 10 /* SS-10 uses 8 */
78 struct resource xres
; /* Must be first */
79 int xflag
; /* 1 == used */
83 static struct xresource xresv
[XNRES
];
85 static struct xresource
*xres_alloc(void) {
86 struct xresource
*xrp
;
90 for (n
= 0; n
< XNRES
; n
++) {
91 if (xrp
->xflag
== 0) {
100 static void xres_free(struct xresource
*xrp
) {
105 * These are typically used in PCI drivers
106 * which are trying to be cross-platform.
108 * Bus type is always zero on IIep.
110 void __iomem
*ioremap(unsigned long offset
, unsigned long size
)
114 sprintf(name
, "phys_%08x", (u32
)offset
);
115 return _sparc_alloc_io(0, offset
, size
, name
);
119 * Comlimentary to ioremap().
121 void iounmap(volatile void __iomem
*virtual)
123 unsigned long vaddr
= (unsigned long) virtual & PAGE_MASK
;
124 struct resource
*res
;
126 if ((res
= _sparc_find_resource(&sparc_iomap
, vaddr
)) == NULL
) {
127 printk("free_io/iounmap: cannot free %lx\n", vaddr
);
132 if ((char *)res
>= (char*)xresv
&& (char *)res
< (char *)&xresv
[XNRES
]) {
133 xres_free((struct xresource
*)res
);
141 void __iomem
*sbus_ioremap(struct resource
*phyres
, unsigned long offset
,
142 unsigned long size
, char *name
)
144 return _sparc_alloc_io(phyres
->flags
& 0xF,
145 phyres
->start
+ offset
, size
, name
);
148 void __iomem
*of_ioremap(struct resource
*res
, unsigned long offset
,
149 unsigned long size
, char *name
)
151 return _sparc_alloc_io(res
->flags
& 0xF,
155 EXPORT_SYMBOL(of_ioremap
);
157 void of_iounmap(void __iomem
*base
, unsigned long size
)
161 EXPORT_SYMBOL(of_iounmap
);
165 void sbus_iounmap(volatile void __iomem
*addr
, unsigned long size
)
173 static void __iomem
*_sparc_alloc_io(unsigned int busno
, unsigned long phys
,
174 unsigned long size
, char *name
)
176 static int printed_full
;
177 struct xresource
*xres
;
178 struct resource
*res
;
181 void __iomem
*va
; /* P3 diag */
183 if (name
== NULL
) name
= "???";
185 if ((xres
= xres_alloc()) != 0) {
190 printk("ioremap: done with statics, switching to malloc\n");
194 tack
= kmalloc(sizeof (struct resource
) + tlen
+ 1, GFP_KERNEL
);
195 if (tack
== NULL
) return NULL
;
196 memset(tack
, 0, sizeof(struct resource
));
197 res
= (struct resource
*) tack
;
198 tack
+= sizeof (struct resource
);
201 strlcpy(tack
, name
, XNMLN
+1);
204 va
= _sparc_ioremap(res
, busno
, phys
, size
);
205 /* printk("ioremap(0x%x:%08lx[0x%lx])=%p\n", busno, phys, size, va); */ /* P3 diag */
211 static void __iomem
*
212 _sparc_ioremap(struct resource
*res
, u32 bus
, u32 pa
, int sz
)
214 unsigned long offset
= ((unsigned long) pa
) & (~PAGE_MASK
);
216 if (allocate_resource(&sparc_iomap
, res
,
217 (offset
+ sz
+ PAGE_SIZE
-1) & PAGE_MASK
,
218 sparc_iomap
.start
, sparc_iomap
.end
, PAGE_SIZE
, NULL
, NULL
) != 0) {
219 /* Usually we cannot see printks in this case. */
220 prom_printf("alloc_io_res(%s): cannot occupy\n",
221 (res
->name
!= NULL
)? res
->name
: "???");
226 sparc_mapiorange(bus
, pa
, res
->start
, res
->end
- res
->start
+ 1);
228 return (void __iomem
*)(unsigned long)(res
->start
+ offset
);
232 * Comlimentary to _sparc_ioremap().
234 static void _sparc_free_io(struct resource
*res
)
238 plen
= res
->end
- res
->start
+ 1;
239 BUG_ON((plen
& (PAGE_SIZE
-1)) != 0);
240 sparc_unmapiorange(res
->start
, plen
);
241 release_resource(res
);
246 void sbus_set_sbus64(struct sbus_dev
*sdev
, int x
)
248 printk("sbus_set_sbus64: unsupported\n");
251 extern unsigned int sun4d_build_irq(struct sbus_dev
*sdev
, int irq
);
252 void __init
sbus_fill_device_irq(struct sbus_dev
*sdev
)
254 struct linux_prom_irqs irqs
[PROMINTR_MAX
];
257 len
= prom_getproperty(sdev
->prom_node
, "intr",
258 (char *)irqs
, sizeof(irqs
));
260 sdev
->num_irqs
= len
/ 8;
261 if (sdev
->num_irqs
== 0) {
263 } else if (sparc_cpu_model
== sun4d
) {
264 for (len
= 0; len
< sdev
->num_irqs
; len
++)
266 sun4d_build_irq(sdev
, irqs
[len
].pri
);
268 for (len
= 0; len
< sdev
->num_irqs
; len
++)
269 sdev
->irqs
[len
] = irqs
[len
].pri
;
272 int interrupts
[PROMINTR_MAX
];
274 /* No "intr" node found-- check for "interrupts" node.
275 * This node contains SBus interrupt levels, not IPLs
276 * as in "intr", and no vector values. We convert
277 * SBus interrupt levels to PILs (platform specific).
279 len
= prom_getproperty(sdev
->prom_node
, "interrupts",
280 (char *)interrupts
, sizeof(interrupts
));
285 sdev
->num_irqs
= len
/ sizeof(int);
286 for (len
= 0; len
< sdev
->num_irqs
; len
++) {
288 sbint_to_irq(sdev
, interrupts
[len
]);
295 * Allocate a chunk of memory suitable for DMA.
296 * Typically devices use them for control blocks.
297 * CPU may access them without any explicit flushing.
299 * XXX Some clever people know that sdev is not used and supply NULL. Watch.
301 void *sbus_alloc_consistent(struct sbus_dev
*sdev
, long len
, u32
*dma_addrp
)
303 unsigned long len_total
= (len
+ PAGE_SIZE
-1) & PAGE_MASK
;
305 struct resource
*res
;
308 /* XXX why are some lenghts signed, others unsigned? */
312 /* XXX So what is maxphys for us and how do drivers know it? */
313 if (len
> 256*1024) { /* __get_free_pages() limit */
317 order
= get_order(len_total
);
318 if ((va
= __get_free_pages(GFP_KERNEL
|__GFP_COMP
, order
)) == 0)
321 if ((res
= kmalloc(sizeof(struct resource
), GFP_KERNEL
)) == NULL
)
323 memset((char*)res
, 0, sizeof(struct resource
));
325 if (allocate_resource(&_sparc_dvma
, res
, len_total
,
326 _sparc_dvma
.start
, _sparc_dvma
.end
, PAGE_SIZE
, NULL
, NULL
) != 0) {
327 printk("sbus_alloc_consistent: cannot occupy 0x%lx", len_total
);
330 mmu_inval_dma_area(va
, len_total
);
331 // XXX The mmu_map_dma_area does this for us below, see comments.
332 // sparc_mapiorange(0, virt_to_phys(va), res->start, len_total);
334 * XXX That's where sdev would be used. Currently we load
335 * all iommu tables with the same translations.
337 if (mmu_map_dma_area(dma_addrp
, va
, res
->start
, len_total
) != 0)
340 /* Set the resource name, if known. */
342 res
->name
= sdev
->prom_name
;
345 return (void *)(unsigned long)res
->start
;
348 release_resource(res
);
350 free_pages(va
, order
);
357 void sbus_free_consistent(struct sbus_dev
*sdev
, long n
, void *p
, u32 ba
)
359 struct resource
*res
;
362 if ((res
= _sparc_find_resource(&_sparc_dvma
,
363 (unsigned long)p
)) == NULL
) {
364 printk("sbus_free_consistent: cannot free %p\n", p
);
368 if (((unsigned long)p
& (PAGE_SIZE
-1)) != 0) {
369 printk("sbus_free_consistent: unaligned va %p\n", p
);
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
);
380 release_resource(res
);
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
);
387 __free_pages(pgv
, get_order(n
));
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.
395 dma_addr_t
sbus_map_single(struct sbus_dev
*sdev
, void *va
, size_t len
, int direction
)
397 /* XXX why are some lenghts signed, others unsigned? */
401 /* XXX So what is maxphys for us and how do drivers know it? */
402 if (len
> 256*1024) { /* __get_free_pages() limit */
405 return mmu_get_scsi_one(va
, len
, sdev
->bus
);
408 void sbus_unmap_single(struct sbus_dev
*sdev
, dma_addr_t ba
, size_t n
, int direction
)
410 mmu_release_scsi_one(ba
, n
, sdev
->bus
);
413 int sbus_map_sg(struct sbus_dev
*sdev
, struct scatterlist
*sg
, int n
, int direction
)
415 mmu_get_scsi_sgl(sg
, n
, sdev
->bus
);
418 * XXX sparc64 can return a partial length here. sun4c should do this
419 * but it currently panics if it can't fulfill the request - Anton
424 void sbus_unmap_sg(struct sbus_dev
*sdev
, struct scatterlist
*sg
, int n
, int direction
)
426 mmu_release_scsi_sgl(sg
, n
, sdev
->bus
);
431 void sbus_dma_sync_single_for_cpu(struct sbus_dev
*sdev
, dma_addr_t ba
, size_t size
, int direction
)
435 struct resource
*res
;
437 /* We do not need the resource, just print a message if invalid. */
438 res
= _sparc_find_resource(&_sparc_dvma
, ba
);
440 panic("sbus_dma_sync_single: 0x%x\n", ba
);
442 va
= page_address(mmu_translate_dvma(ba
)); /* XXX higmem */
444 * XXX This bogosity will be fixed with the iommu rewrite coming soon
445 * to a kernel near you. - Anton
447 /* mmu_inval_dma_area(va, (size + PAGE_SIZE-1) & PAGE_MASK); */
451 void sbus_dma_sync_single_for_device(struct sbus_dev
*sdev
, dma_addr_t ba
, size_t size
, int direction
)
455 struct resource
*res
;
457 /* We do not need the resource, just print a message if invalid. */
458 res
= _sparc_find_resource(&_sparc_dvma
, ba
);
460 panic("sbus_dma_sync_single: 0x%x\n", ba
);
462 va
= page_address(mmu_translate_dvma(ba
)); /* XXX higmem */
464 * XXX This bogosity will be fixed with the iommu rewrite coming soon
465 * to a kernel near you. - Anton
467 /* mmu_inval_dma_area(va, (size + PAGE_SIZE-1) & PAGE_MASK); */
471 void sbus_dma_sync_sg_for_cpu(struct sbus_dev
*sdev
, struct scatterlist
*sg
, int n
, int direction
)
473 printk("sbus_dma_sync_sg_for_cpu: not implemented yet\n");
476 void sbus_dma_sync_sg_for_device(struct sbus_dev
*sdev
, struct scatterlist
*sg
, int n
, int direction
)
478 printk("sbus_dma_sync_sg_for_device: not implemented yet\n");
481 /* Support code for sbus_init(). */
483 * XXX This functions appears to be a distorted version of
484 * prom_sbus_ranges_init(), with all sun4d stuff cut away.
485 * Ask DaveM what is going on here, how is sun4d supposed to work... XXX
487 /* added back sun4d patch from Thomas Bogendoerfer - should be OK (crn) */
488 void __init
sbus_arch_bus_ranges_init(struct device_node
*pn
, struct sbus_bus
*sbus
)
490 int parent_node
= pn
->node
;
492 if (sparc_cpu_model
== sun4d
) {
493 struct linux_prom_ranges iounit_ranges
[PROMREG_MAX
];
494 int num_iounit_ranges
, len
;
496 len
= prom_getproperty(parent_node
, "ranges",
497 (char *) iounit_ranges
,
498 sizeof (iounit_ranges
));
501 (len
/ sizeof(struct linux_prom_ranges
));
502 prom_adjust_ranges(sbus
->sbus_ranges
,
503 sbus
->num_sbus_ranges
,
504 iounit_ranges
, num_iounit_ranges
);
509 void __init
sbus_setup_iommu(struct sbus_bus
*sbus
, struct device_node
*dp
)
512 struct device_node
*parent
= dp
->parent
;
514 if (sparc_cpu_model
!= sun4d
&&
516 !strcmp(parent
->name
, "iommu")) {
517 extern void iommu_init(int iommu_node
, struct sbus_bus
*sbus
);
519 iommu_init(parent
->node
, sbus
);
522 if (sparc_cpu_model
== sun4d
) {
523 extern void iounit_init(int sbi_node
, int iounit_node
,
524 struct sbus_bus
*sbus
);
526 iounit_init(dp
->node
, parent
->node
, sbus
);
531 void __init
sbus_setup_arch_props(struct sbus_bus
*sbus
, struct device_node
*dp
)
533 if (sparc_cpu_model
== sun4d
) {
534 struct device_node
*parent
= dp
->parent
;
536 sbus
->devid
= of_getintprop_default(parent
, "device-id", 0);
537 sbus
->board
= of_getintprop_default(parent
, "board#", 0);
541 int __init
sbus_arch_preinit(void)
543 extern void register_proc_sparc_ioport(void);
545 register_proc_sparc_ioport();
549 extern void sun4_dvma_init(void);
558 void __init
sbus_arch_postinit(void)
560 if (sparc_cpu_model
== sun4d
) {
561 extern void sun4d_init_sbi_irq(void);
562 sun4d_init_sbi_irq();
565 #endif /* CONFIG_SBUS */
569 /* Allocate and map kernel buffer using consistent mode DMA for a device.
570 * hwdev should be valid struct pci_dev pointer for PCI devices.
572 void *pci_alloc_consistent(struct pci_dev
*pdev
, size_t len
, dma_addr_t
*pba
)
574 unsigned long len_total
= (len
+ PAGE_SIZE
-1) & PAGE_MASK
;
576 struct resource
*res
;
582 if (len
> 256*1024) { /* __get_free_pages() limit */
586 order
= get_order(len_total
);
587 va
= __get_free_pages(GFP_KERNEL
, order
);
589 printk("pci_alloc_consistent: no %ld pages\n", len_total
>>PAGE_SHIFT
);
593 if ((res
= kmalloc(sizeof(struct resource
), GFP_KERNEL
)) == NULL
) {
594 free_pages(va
, order
);
595 printk("pci_alloc_consistent: no core\n");
598 memset((char*)res
, 0, sizeof(struct resource
));
600 if (allocate_resource(&_sparc_dvma
, res
, len_total
,
601 _sparc_dvma
.start
, _sparc_dvma
.end
, PAGE_SIZE
, NULL
, NULL
) != 0) {
602 printk("pci_alloc_consistent: cannot occupy 0x%lx", len_total
);
603 free_pages(va
, order
);
607 mmu_inval_dma_area(va
, len_total
);
609 /* P3 */ printk("pci_alloc_consistent: kva %lx uncva %lx phys %lx size %lx\n",
610 (long)va
, (long)res
->start
, (long)virt_to_phys(va
), len_total
);
612 sparc_mapiorange(0, virt_to_phys(va
), res
->start
, len_total
);
614 *pba
= virt_to_phys(va
); /* equals virt_to_bus (R.I.P.) for us. */
615 return (void *) res
->start
;
618 /* Free and unmap a consistent DMA buffer.
619 * cpu_addr is what was returned from pci_alloc_consistent,
620 * size must be the same as what as passed into pci_alloc_consistent,
621 * and likewise dma_addr must be the same as what *dma_addrp was set to.
623 * References to the memory and mappings assosciated with cpu_addr/dma_addr
624 * past this call are illegal.
626 void pci_free_consistent(struct pci_dev
*pdev
, size_t n
, void *p
, dma_addr_t ba
)
628 struct resource
*res
;
631 if ((res
= _sparc_find_resource(&_sparc_dvma
,
632 (unsigned long)p
)) == NULL
) {
633 printk("pci_free_consistent: cannot free %p\n", p
);
637 if (((unsigned long)p
& (PAGE_SIZE
-1)) != 0) {
638 printk("pci_free_consistent: unaligned va %p\n", p
);
642 n
= (n
+ PAGE_SIZE
-1) & PAGE_MASK
;
643 if ((res
->end
-res
->start
)+1 != n
) {
644 printk("pci_free_consistent: region 0x%lx asked 0x%lx\n",
645 (long)((res
->end
-res
->start
)+1), (long)n
);
649 pgp
= (unsigned long) phys_to_virt(ba
); /* bus_to_virt actually */
650 mmu_inval_dma_area(pgp
, n
);
651 sparc_unmapiorange((unsigned long)p
, n
);
653 release_resource(res
);
656 free_pages(pgp
, get_order(n
));
659 /* Map a single buffer of the indicated size for DMA in streaming mode.
660 * The 32-bit bus address to use is returned.
662 * Once the device is given the dma address, the device owns this memory
663 * until either pci_unmap_single or pci_dma_sync_single_* is performed.
665 dma_addr_t
pci_map_single(struct pci_dev
*hwdev
, void *ptr
, size_t size
,
668 BUG_ON(direction
== PCI_DMA_NONE
);
669 /* IIep is write-through, not flushing. */
670 return virt_to_phys(ptr
);
673 /* Unmap a single streaming mode DMA translation. The dma_addr and size
674 * must match what was provided for in a previous pci_map_single call. All
675 * other usages are undefined.
677 * After this call, reads by the cpu to the buffer are guaranteed to see
678 * whatever the device wrote there.
680 void pci_unmap_single(struct pci_dev
*hwdev
, dma_addr_t ba
, size_t size
,
683 BUG_ON(direction
== PCI_DMA_NONE
);
684 if (direction
!= PCI_DMA_TODEVICE
) {
685 mmu_inval_dma_area((unsigned long)phys_to_virt(ba
),
686 (size
+ PAGE_SIZE
-1) & PAGE_MASK
);
691 * Same as pci_map_single, but with pages.
693 dma_addr_t
pci_map_page(struct pci_dev
*hwdev
, struct page
*page
,
694 unsigned long offset
, size_t size
, int direction
)
696 BUG_ON(direction
== PCI_DMA_NONE
);
697 /* IIep is write-through, not flushing. */
698 return page_to_phys(page
) + offset
;
701 void pci_unmap_page(struct pci_dev
*hwdev
,
702 dma_addr_t dma_address
, size_t size
, int direction
)
704 BUG_ON(direction
== PCI_DMA_NONE
);
705 /* mmu_inval_dma_area XXX */
708 /* Map a set of buffers described by scatterlist in streaming
709 * mode for DMA. This is the scather-gather version of the
710 * above pci_map_single interface. Here the scatter gather list
711 * elements are each tagged with the appropriate dma address
712 * and length. They are obtained via sg_dma_{address,length}(SG).
714 * NOTE: An implementation may be able to use a smaller number of
715 * DMA address/length pairs than there are SG table elements.
716 * (for example via virtual mapping capabilities)
717 * The routine returns the number of addr/length pairs actually
718 * used, at most nents.
720 * Device ownership issues as mentioned above for pci_map_single are
723 int pci_map_sg(struct pci_dev
*hwdev
, struct scatterlist
*sg
, int nents
,
728 BUG_ON(direction
== PCI_DMA_NONE
);
729 /* IIep is write-through, not flushing. */
730 for (n
= 0; n
< nents
; n
++) {
731 BUG_ON(page_address(sg
->page
) == NULL
);
732 sg
->dvma_address
= virt_to_phys(page_address(sg
->page
));
733 sg
->dvma_length
= sg
->length
;
739 /* Unmap a set of streaming mode DMA translations.
740 * Again, cpu read rules concerning calls here are the same as for
741 * pci_unmap_single() above.
743 void pci_unmap_sg(struct pci_dev
*hwdev
, struct scatterlist
*sg
, int nents
,
748 BUG_ON(direction
== PCI_DMA_NONE
);
749 if (direction
!= PCI_DMA_TODEVICE
) {
750 for (n
= 0; n
< nents
; n
++) {
751 BUG_ON(page_address(sg
->page
) == NULL
);
753 (unsigned long) page_address(sg
->page
),
754 (sg
->length
+ PAGE_SIZE
-1) & PAGE_MASK
);
760 /* Make physical memory consistent for a single
761 * streaming mode DMA translation before or after a transfer.
763 * If you perform a pci_map_single() but wish to interrogate the
764 * buffer using the cpu, yet do not wish to teardown the PCI dma
765 * mapping, you must call this function before doing so. At the
766 * next point you give the PCI dma address back to the card, you
767 * must first perform a pci_dma_sync_for_device, and then the
768 * device again owns the buffer.
770 void pci_dma_sync_single_for_cpu(struct pci_dev
*hwdev
, dma_addr_t ba
, size_t size
, int direction
)
772 BUG_ON(direction
== PCI_DMA_NONE
);
773 if (direction
!= PCI_DMA_TODEVICE
) {
774 mmu_inval_dma_area((unsigned long)phys_to_virt(ba
),
775 (size
+ PAGE_SIZE
-1) & PAGE_MASK
);
779 void pci_dma_sync_single_for_device(struct pci_dev
*hwdev
, dma_addr_t ba
, size_t size
, int direction
)
781 BUG_ON(direction
== PCI_DMA_NONE
);
782 if (direction
!= PCI_DMA_TODEVICE
) {
783 mmu_inval_dma_area((unsigned long)phys_to_virt(ba
),
784 (size
+ PAGE_SIZE
-1) & PAGE_MASK
);
788 /* Make physical memory consistent for a set of streaming
789 * mode DMA translations after a transfer.
791 * The same as pci_dma_sync_single_* but for a scatter-gather list,
792 * same rules and usage.
794 void pci_dma_sync_sg_for_cpu(struct pci_dev
*hwdev
, struct scatterlist
*sg
, int nents
, int direction
)
798 BUG_ON(direction
== PCI_DMA_NONE
);
799 if (direction
!= PCI_DMA_TODEVICE
) {
800 for (n
= 0; n
< nents
; n
++) {
801 BUG_ON(page_address(sg
->page
) == NULL
);
803 (unsigned long) page_address(sg
->page
),
804 (sg
->length
+ PAGE_SIZE
-1) & PAGE_MASK
);
810 void pci_dma_sync_sg_for_device(struct pci_dev
*hwdev
, struct scatterlist
*sg
, int nents
, int direction
)
814 BUG_ON(direction
== PCI_DMA_NONE
);
815 if (direction
!= PCI_DMA_TODEVICE
) {
816 for (n
= 0; n
< nents
; n
++) {
817 BUG_ON(page_address(sg
->page
) == NULL
);
819 (unsigned long) page_address(sg
->page
),
820 (sg
->length
+ PAGE_SIZE
-1) & PAGE_MASK
);
825 #endif /* CONFIG_PCI */
827 #ifdef CONFIG_PROC_FS
830 _sparc_io_get_info(char *buf
, char **start
, off_t fpos
, int length
, int *eof
,
833 char *p
= buf
, *e
= buf
+ length
;
837 for (r
= ((struct resource
*)data
)->child
; r
!= NULL
; r
= r
->sibling
) {
838 if (p
+ 32 >= e
) /* Better than nothing */
840 if ((nm
= r
->name
) == 0) nm
= "???";
841 p
+= sprintf(p
, "%016llx-%016llx: %s\n",
842 (unsigned long long)r
->start
,
843 (unsigned long long)r
->end
, nm
);
849 #endif /* CONFIG_PROC_FS */
852 * This is a version of find_resource and it belongs to kernel/resource.c.
853 * Until we have agreement with Linus and Martin, it lingers here.
855 * XXX Too slow. Can have 8192 DVMA pages on sun4m in the worst case.
856 * This probably warrants some sort of hashing.
859 _sparc_find_resource(struct resource
*root
, unsigned long hit
)
861 struct resource
*tmp
;
863 for (tmp
= root
->child
; tmp
!= 0; tmp
= tmp
->sibling
) {
864 if (tmp
->start
<= hit
&& tmp
->end
>= hit
)
870 void register_proc_sparc_ioport(void)
872 #ifdef CONFIG_PROC_FS
873 create_proc_read_entry("io_map",0,NULL
,_sparc_io_get_info
,&sparc_iomap
);
874 create_proc_read_entry("dvma_map",0,NULL
,_sparc_io_get_info
,&_sparc_dvma
);