1 | #include <linux/pci.h>
|
---|
2 | #include <asm/io.h>
|
---|
3 | #include <sound/config.h>
|
---|
4 |
|
---|
5 | #ifndef fastcall
|
---|
6 | #define fastcall
|
---|
7 | #endif
|
---|
8 |
|
---|
9 | /*
|
---|
10 | * the following code is stripped from linux/lib/iomap.c
|
---|
11 | */
|
---|
12 |
|
---|
13 | #define PIO_OFFSET 0x10000UL
|
---|
14 | #define PIO_MASK 0x0ffffUL
|
---|
15 | #define PIO_RESERVED 0x40000UL
|
---|
16 |
|
---|
17 | #define IO_COND(addr, is_pio, is_mmio) do { \
|
---|
18 | unsigned long port = (unsigned long)addr; \
|
---|
19 | if (port < PIO_RESERVED) { \
|
---|
20 | port &= PIO_MASK; \
|
---|
21 | is_pio; \
|
---|
22 | } else { \
|
---|
23 | is_mmio; \
|
---|
24 | } \
|
---|
25 | } while (0)
|
---|
26 |
|
---|
27 | unsigned int fastcall ioread8(void __iomem *addr)
|
---|
28 | {
|
---|
29 | IO_COND(addr, return inb(port), return readb(addr));
|
---|
30 | }
|
---|
31 | unsigned int fastcall ioread16(void __iomem *addr)
|
---|
32 | {
|
---|
33 | IO_COND(addr, return inw(port), return readw(addr));
|
---|
34 | }
|
---|
35 | unsigned int fastcall ioread32(void __iomem *addr)
|
---|
36 | {
|
---|
37 | IO_COND(addr, return inl(port), return readl(addr));
|
---|
38 | }
|
---|
39 |
|
---|
40 | void fastcall iowrite8(u8 val, void __iomem *addr)
|
---|
41 | {
|
---|
42 | IO_COND(addr, outb(val,port), writeb(val, addr));
|
---|
43 | }
|
---|
44 | void fastcall iowrite16(u16 val, void __iomem *addr)
|
---|
45 | {
|
---|
46 | IO_COND(addr, outw(val,port), writew(val, addr));
|
---|
47 | }
|
---|
48 | void fastcall iowrite32(u32 val, void __iomem *addr)
|
---|
49 | {
|
---|
50 | IO_COND(addr, outl(val,port), writel(val, addr));
|
---|
51 | }
|
---|
52 |
|
---|
53 | /* Create a virtual mapping cookie for an IO port range */
|
---|
54 | void __iomem *ioport_map(unsigned long port, unsigned int nr)
|
---|
55 | {
|
---|
56 | if (port > PIO_MASK)
|
---|
57 | return NULL;
|
---|
58 | return (void __iomem *) (unsigned long) (port + PIO_OFFSET);
|
---|
59 | }
|
---|
60 |
|
---|
61 | void ioport_unmap(void __iomem *addr)
|
---|
62 | {
|
---|
63 | /* Nothing to do */
|
---|
64 | }
|
---|
65 |
|
---|
66 | /* Create a virtual mapping cookie for a PCI BAR (memory or IO) */
|
---|
67 | void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
|
---|
68 | {
|
---|
69 | unsigned long start = pci_resource_start(dev, bar);
|
---|
70 | unsigned long len = pci_resource_len(dev, bar);
|
---|
71 | unsigned long flags = pci_resource_flags(dev, bar);
|
---|
72 |
|
---|
73 | if (!len || !start)
|
---|
74 | return NULL;
|
---|
75 | if (maxlen && len > maxlen)
|
---|
76 | len = maxlen;
|
---|
77 | if (flags & IORESOURCE_IO)
|
---|
78 | return ioport_map(start, len);
|
---|
79 | if (flags & IORESOURCE_MEM) {
|
---|
80 | if (flags & IORESOURCE_CACHEABLE)
|
---|
81 | return ioremap(start, len);
|
---|
82 | return ioremap_nocache(start, len);
|
---|
83 | }
|
---|
84 | /* What? */
|
---|
85 | return NULL;
|
---|
86 | }
|
---|
87 |
|
---|
88 | void pci_iounmap(struct pci_dev *dev, void __iomem * addr)
|
---|
89 | {
|
---|
90 | IO_COND(addr, /* nothing */, iounmap(addr));
|
---|
91 | }
|
---|