Skip to content

Commit 66eab4d

Browse files
committed
lib: add GENERIC_PCI_IOMAP
Many architectures want a generic pci_iomap but not the rest of iomap.c. Split that to a separate .c file and add a new config symbol. select automatically by GENERIC_IOMAP. Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
1 parent 4673ca8 commit 66eab4d

File tree

7 files changed

+85
-44
lines changed

7 files changed

+85
-44
lines changed

include/asm-generic/io.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include <asm-generic/iomap.h>
2020
#endif
2121

22+
#include <asm-generic/pci_iomap.h>
23+
2224
#ifndef mmiowb
2325
#define mmiowb() do {} while (0)
2426
#endif
@@ -283,9 +285,7 @@ static inline void writesb(const void __iomem *addr, const void *buf, int len)
283285
#define __io_virt(x) ((void __force *) (x))
284286

285287
#ifndef CONFIG_GENERIC_IOMAP
286-
/* Create a virtual mapping cookie for a PCI BAR (memory or IO) */
287288
struct pci_dev;
288-
extern void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max);
289289
static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)
290290
{
291291
}

include/asm-generic/iomap.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,15 @@ extern void ioport_unmap(void __iomem *);
6767
#endif
6868

6969
#ifdef CONFIG_PCI
70-
/* Create a virtual mapping cookie for a PCI BAR (memory or IO) */
70+
/* Destroy a virtual mapping cookie for a PCI BAR (memory or IO) */
7171
struct pci_dev;
72-
extern void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max);
7372
extern void pci_iounmap(struct pci_dev *dev, void __iomem *);
7473
#else
7574
struct pci_dev;
76-
static inline void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max)
77-
{
78-
return NULL;
79-
}
8075
static inline void pci_iounmap(struct pci_dev *dev, void __iomem *addr)
8176
{ }
8277
#endif
8378

79+
#include <asm-generic/pci_iomap.h>
80+
8481
#endif

include/asm-generic/pci_iomap.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/* Generic I/O port emulation, based on MN10300 code
2+
*
3+
* Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
4+
* Written by David Howells (dhowells@redhat.com)
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU General Public Licence
8+
* as published by the Free Software Foundation; either version
9+
* 2 of the Licence, or (at your option) any later version.
10+
*/
11+
#ifndef __ASM_GENERIC_PCI_IOMAP_H
12+
#define __ASM_GENERIC_PCI_IOMAP_H
13+
14+
struct pci_dev;
15+
#ifdef CONFIG_PCI
16+
/* Create a virtual mapping cookie for a PCI BAR (memory or IO) */
17+
extern void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max);
18+
#else
19+
static inline void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max)
20+
{
21+
return NULL;
22+
}
23+
#endif
24+
25+
#endif /* __ASM_GENERIC_IO_H */

lib/Kconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@ config RATIONAL
1919
config GENERIC_FIND_FIRST_BIT
2020
bool
2121

22+
config GENERIC_PCI_IOMAP
23+
bool
24+
2225
config GENERIC_IOMAP
2326
bool
27+
select GENERIC_PCI_IOMAP
2428

2529
config CRC_CCITT
2630
tristate "CRC-CCITT functions"

lib/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ endif
3333

3434
lib-$(CONFIG_HOTPLUG) += kobject_uevent.o
3535
obj-$(CONFIG_GENERIC_IOMAP) += iomap.o
36+
obj-$(CONFIG_GENERIC_PCI_IOMAP) += pci_iomap.o
3637
obj-$(CONFIG_HAS_IOMEM) += iomap_copy.o devres.o
3738
obj-$(CONFIG_CHECK_SIGNATURE) += check_signature.o
3839
obj-$(CONFIG_DEBUG_LOCKING_API_SELFTESTS) += locking-selftest.o

lib/iomap.c

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -242,45 +242,11 @@ EXPORT_SYMBOL(ioport_unmap);
242242
#endif /* CONFIG_HAS_IOPORT */
243243

244244
#ifdef CONFIG_PCI
245-
/**
246-
* pci_iomap - create a virtual mapping cookie for a PCI BAR
247-
* @dev: PCI device that owns the BAR
248-
* @bar: BAR number
249-
* @maxlen: length of the memory to map
250-
*
251-
* Using this function you will get a __iomem address to your device BAR.
252-
* You can access it using ioread*() and iowrite*(). These functions hide
253-
* the details if this is a MMIO or PIO address space and will just do what
254-
* you expect from them in the correct way.
255-
*
256-
* @maxlen specifies the maximum length to map. If you want to get access to
257-
* the complete BAR without checking for its length first, pass %0 here.
258-
* */
259-
void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
260-
{
261-
resource_size_t start = pci_resource_start(dev, bar);
262-
resource_size_t len = pci_resource_len(dev, bar);
263-
unsigned long flags = pci_resource_flags(dev, bar);
264-
265-
if (!len || !start)
266-
return NULL;
267-
if (maxlen && len > maxlen)
268-
len = maxlen;
269-
if (flags & IORESOURCE_IO)
270-
return ioport_map(start, len);
271-
if (flags & IORESOURCE_MEM) {
272-
if (flags & IORESOURCE_CACHEABLE)
273-
return ioremap(start, len);
274-
return ioremap_nocache(start, len);
275-
}
276-
/* What? */
277-
return NULL;
278-
}
279-
245+
/* Hide the details if this is a MMIO or PIO address space and just do what
246+
* you expect in the correct way. */
280247
void pci_iounmap(struct pci_dev *dev, void __iomem * addr)
281248
{
282249
IO_COND(addr, /* nothing */, iounmap(addr));
283250
}
284-
EXPORT_SYMBOL(pci_iomap);
285251
EXPORT_SYMBOL(pci_iounmap);
286252
#endif /* CONFIG_PCI */

lib/pci_iomap.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Implement the default iomap interfaces
3+
*
4+
* (C) Copyright 2004 Linus Torvalds
5+
*/
6+
#include <linux/pci.h>
7+
#include <linux/io.h>
8+
9+
#include <linux/export.h>
10+
11+
#ifdef CONFIG_PCI
12+
/**
13+
* pci_iomap - create a virtual mapping cookie for a PCI BAR
14+
* @dev: PCI device that owns the BAR
15+
* @bar: BAR number
16+
* @maxlen: length of the memory to map
17+
*
18+
* Using this function you will get a __iomem address to your device BAR.
19+
* You can access it using ioread*() and iowrite*(). These functions hide
20+
* the details if this is a MMIO or PIO address space and will just do what
21+
* you expect from them in the correct way.
22+
*
23+
* @maxlen specifies the maximum length to map. If you want to get access to
24+
* the complete BAR without checking for its length first, pass %0 here.
25+
* */
26+
void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
27+
{
28+
resource_size_t start = pci_resource_start(dev, bar);
29+
resource_size_t len = pci_resource_len(dev, bar);
30+
unsigned long flags = pci_resource_flags(dev, bar);
31+
32+
if (!len || !start)
33+
return NULL;
34+
if (maxlen && len > maxlen)
35+
len = maxlen;
36+
if (flags & IORESOURCE_IO)
37+
return ioport_map(start, len);
38+
if (flags & IORESOURCE_MEM) {
39+
if (flags & IORESOURCE_CACHEABLE)
40+
return ioremap(start, len);
41+
return ioremap_nocache(start, len);
42+
}
43+
/* What? */
44+
return NULL;
45+
}
46+
47+
EXPORT_SYMBOL(pci_iomap);
48+
#endif /* CONFIG_PCI */

0 commit comments

Comments
 (0)