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>
35 #include <linux/slab.h>
36 #include <linux/pci.h>
44 #include <asm/oplib.h>
47 #include <asm/pgalloc.h>
49 #include <asm/iommu.h>
58 static inline void dma_make_coherent(
unsigned long pa,
unsigned long len)
61 if (!sparc_leon3_snooping_enabled())
67 static void __iomem *_sparc_alloc_io(
unsigned int busno,
unsigned long phys,
71 static void register_proc_sparc_ioport(
void);
74 static struct resource _sparc_dvma = {
99 static struct xresource *xres_alloc(
void) {
104 for (n = 0; n <
XNRES; n++) {
105 if (xrp->
xflag == 0) {
114 static void xres_free(
struct xresource *xrp) {
129 return _sparc_alloc_io(0, offset, size, name);
146 printk(
"free_io/iounmap: cannot free %lx\n", vaddr);
151 if ((
char *)res >= (
char*)xresv && (
char *)res < (
char *)&xresv[XNRES]) {
162 return _sparc_alloc_io(res->
flags & 0xF,
177 static void __iomem *_sparc_alloc_io(
unsigned int busno,
unsigned long phys,
180 static int printed_full;
187 if (name ==
NULL) name =
"???";
189 if ((xres = xres_alloc()) != 0) {
194 printk(
"ioremap: done with statics, switching to malloc\n");
208 va = _sparc_ioremap(res, busno, phys, size);
225 (res->
name != NULL)? res->
name:
"???");
238 static void _sparc_free_io(
struct resource *res)
242 plen = resource_size(res);
252 printk(
"sbus_set_sbus64: unsupported\n");
261 static void *sbus_alloc_coherent(
struct device *
dev,
size_t len,
276 if (len > 256*1024) {
289 printk(
"sbus_alloc_consistent: cannot occupy 0x%lx", len_total);
299 if (sbus_map_dma_area(dev, dma_addrp, va, res->
start, len_total) != 0)
302 res->
name = op->
dev.of_node->name;
304 return (
void *)(
unsigned long)res->
start;
316 static void sbus_free_coherent(
struct device *dev,
size_t n,
void *
p,
323 (
unsigned long)p)) == NULL) {
324 printk(
"sbus_free_consistent: cannot free %p\n", p);
328 if (((
unsigned long)p & (
PAGE_SIZE-1)) != 0) {
329 printk(
"sbus_free_consistent: unaligned va %p\n", p);
334 if (resource_size(res) != n) {
335 printk(
"sbus_free_consistent: region 0x%lx asked 0x%zx\n",
336 (
long)resource_size(res), n);
344 sbus_unmap_dma_area(dev, ba, n);
355 unsigned long offset,
size_t len,
366 if (len > 256*1024) {
369 return mmu_get_scsi_one(dev, va, len);
375 mmu_release_scsi_one(dev, ba, n);
381 mmu_get_scsi_sgl(dev, sg, n);
388 mmu_release_scsi_sgl(dev, sg, n);
404 .
alloc = sbus_alloc_coherent,
405 .free = sbus_free_coherent,
406 .map_page = sbus_map_page,
407 .unmap_page = sbus_unmap_page,
408 .map_sg = sbus_map_sg,
409 .unmap_sg = sbus_unmap_sg,
410 .sync_sg_for_cpu = sbus_sync_sg_for_cpu,
411 .sync_sg_for_device = sbus_sync_sg_for_device,
414 static int __init sparc_register_ioport(
void)
416 register_proc_sparc_ioport();
429 static void *pci32_alloc_coherent(
struct device *dev,
size_t len,
441 if (len > 256*1024) {
453 printk(
"pci_alloc_consistent: no core\n");
459 printk(
"pci_alloc_consistent: cannot occupy 0x%lx", len_total);
465 return (
void *) res->
start;
483 static void pci32_free_coherent(
struct device *dev,
size_t n,
void *p,
489 (
unsigned long)p)) == NULL) {
490 printk(
"pci_free_consistent: cannot free %p\n", p);
494 if (((
unsigned long)p & (
PAGE_SIZE-1)) != 0) {
495 printk(
"pci_free_consistent: unaligned va %p\n", p);
500 if (resource_size(res) != n) {
501 printk(
"pci_free_consistent: region 0x%lx asked 0x%lx\n",
502 (
long)resource_size(res), (
long)n);
506 dma_make_coherent(ba, n);
518 unsigned long offset,
size_t size,
526 static void pci32_unmap_page(
struct device *dev,
dma_addr_t ba,
size_t size,
558 sg->dma_length = sg->
length;
640 .alloc = pci32_alloc_coherent,
641 .free = pci32_free_coherent,
642 .map_page = pci32_map_page,
643 .unmap_page = pci32_unmap_page,
644 .map_sg = pci32_map_sg,
645 .unmap_sg = pci32_unmap_sg,
646 .sync_single_for_cpu = pci32_sync_single_for_cpu,
647 .sync_single_for_device = pci32_sync_single_for_device,
648 .sync_sg_for_cpu = pci32_sync_sg_for_cpu,
649 .sync_sg_for_device = pci32_sync_sg_for_device,
677 #ifdef CONFIG_PROC_FS
679 static int sparc_io_proc_show(
struct seq_file *
m,
void *
v)
684 for (
r = root->
child;
r != NULL;
r =
r->sibling) {
685 if ((nm =
r->name) == 0) nm =
"???";
687 (
unsigned long long)
r->start,
688 (
unsigned long long)
r->end, nm);
701 .open = sparc_io_proc_open,
708 static void register_proc_sparc_ioport(
void)
710 #ifdef CONFIG_PROC_FS