diff options
author | Ralf Baechle <ralf@linux-mips.org> | 2006-12-07 09:35:43 -0500 |
---|---|---|
committer | Ralf Baechle <ralf@linux-mips.org> | 2007-02-18 16:31:34 -0500 |
commit | 140c1729a221dc6eacfcbf2a073dbf00fad13e43 (patch) | |
tree | b6baff7c6e68f7ca45aacded88b02ccb5f2cd286 /arch/mips/lib/iomap-pci.c | |
parent | 4c1569949a756327aa0ad7aa15a62266b6a00c3e (diff) |
[MIPS] Iomap implementation.
This implementation has support for the concept of one separate ioport
address space by PCI domain. A pointer to the virtual address where
the port space of a domain has been mapped has been added to struct
pci_controller and systems should be fixed to fill in this value. For
single domain systems this will be the same value as passed to
set_io_port_base().
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Diffstat (limited to 'arch/mips/lib/iomap-pci.c')
-rw-r--r-- | arch/mips/lib/iomap-pci.c | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/arch/mips/lib/iomap-pci.c b/arch/mips/lib/iomap-pci.c new file mode 100644 index 000000000000..c11b2494bb6e --- /dev/null +++ b/arch/mips/lib/iomap-pci.c | |||
@@ -0,0 +1,74 @@ | |||
1 | /* | ||
2 | * Implement the default iomap interfaces | ||
3 | * | ||
4 | * (C) Copyright 2004 Linus Torvalds | ||
5 | * (C) Copyright 2006 Ralf Baechle <ralf@linux-mips.org> | ||
6 | * (C) Copyright 2007 MIPS Technologies, Inc. | ||
7 | * written by Ralf Baechle <ralf@linux-mips.org> | ||
8 | */ | ||
9 | #include <linux/pci.h> | ||
10 | #include <linux/module.h> | ||
11 | #include <asm/io.h> | ||
12 | |||
13 | static void __iomem *ioport_map_pci(struct pci_dev *dev, | ||
14 | unsigned long port, unsigned int nr) | ||
15 | { | ||
16 | struct pci_controller *ctrl = dev->bus->sysdata; | ||
17 | unsigned long base = ctrl->io_map_base; | ||
18 | |||
19 | /* This will eventually become a BUG_ON but for now be gentle */ | ||
20 | if (unlikely(!ctrl->io_map_base)) { | ||
21 | struct pci_bus *bus = dev->bus; | ||
22 | char name[8]; | ||
23 | |||
24 | while (bus->parent) | ||
25 | bus = bus->parent; | ||
26 | |||
27 | ctrl->io_map_base = base = mips_io_port_base; | ||
28 | |||
29 | sprintf(name, "%04x:%02x", pci_domain_nr(bus), bus->number); | ||
30 | printk(KERN_WARNING "io_map_base of root PCI bus %s unset. " | ||
31 | "Trying to continue but you better\nfix this issue or " | ||
32 | "report it to linux-mips@linux-mips.org or your " | ||
33 | "vendor.\n", name); | ||
34 | #ifdef CONFIG_PCI_DOMAINS | ||
35 | panic("To avoid data corruption io_map_base MUST be set with " | ||
36 | "multiple PCI domains."); | ||
37 | #endif | ||
38 | } | ||
39 | |||
40 | return (void __iomem *) (ctrl->io_map_base + port); | ||
41 | } | ||
42 | |||
43 | /* | ||
44 | * Create a virtual mapping cookie for a PCI BAR (memory or IO) | ||
45 | */ | ||
46 | void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen) | ||
47 | { | ||
48 | unsigned long start = pci_resource_start(dev, bar); | ||
49 | unsigned long len = pci_resource_len(dev, bar); | ||
50 | unsigned long flags = pci_resource_flags(dev, bar); | ||
51 | |||
52 | if (!len || !start) | ||
53 | return NULL; | ||
54 | if (maxlen && len > maxlen) | ||
55 | len = maxlen; | ||
56 | if (flags & IORESOURCE_IO) | ||
57 | return ioport_map_pci(dev, start, len); | ||
58 | if (flags & IORESOURCE_MEM) { | ||
59 | if (flags & IORESOURCE_CACHEABLE) | ||
60 | return ioremap(start, len); | ||
61 | return ioremap_nocache(start, len); | ||
62 | } | ||
63 | /* What? */ | ||
64 | return NULL; | ||
65 | } | ||
66 | |||
67 | EXPORT_SYMBOL(pci_iomap); | ||
68 | |||
69 | void pci_iounmap(struct pci_dev *dev, void __iomem * addr) | ||
70 | { | ||
71 | iounmap(addr); | ||
72 | } | ||
73 | |||
74 | EXPORT_SYMBOL(pci_iounmap); | ||