xref: /openbmc/linux/arch/microblaze/pci/iomap.c (revision 5cfe469c)
1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
2a6475c13SMichal Simek /*
3a6475c13SMichal Simek  * ppc64 "iomap" interface implementation.
4a6475c13SMichal Simek  *
5a6475c13SMichal Simek  * (C) Copyright 2004 Linus Torvalds
6a6475c13SMichal Simek  */
7a6475c13SMichal Simek #include <linux/init.h>
8a6475c13SMichal Simek #include <linux/pci.h>
9a6475c13SMichal Simek #include <linux/mm.h>
1066421a64SPaul Gortmaker #include <linux/export.h>
116bd55f0bSMichal Simek #include <linux/io.h>
12a6475c13SMichal Simek #include <asm/pci-bridge.h>
13a6475c13SMichal Simek 
14*5cfe469cSThippeswamy Havalige static DEFINE_SPINLOCK(hose_spinlock);
15*5cfe469cSThippeswamy Havalige LIST_HEAD(hose_list);
16*5cfe469cSThippeswamy Havalige 
17*5cfe469cSThippeswamy Havalige unsigned long isa_io_base;
18*5cfe469cSThippeswamy Havalige EXPORT_SYMBOL(isa_io_base);
19*5cfe469cSThippeswamy Havalige 
pcibios_io_size(const struct pci_controller * hose)20*5cfe469cSThippeswamy Havalige static resource_size_t pcibios_io_size(const struct pci_controller *hose)
21*5cfe469cSThippeswamy Havalige {
22*5cfe469cSThippeswamy Havalige 	return resource_size(&hose->io_resource);
23*5cfe469cSThippeswamy Havalige }
24*5cfe469cSThippeswamy Havalige 
pcibios_vaddr_is_ioport(void __iomem * address)25*5cfe469cSThippeswamy Havalige int pcibios_vaddr_is_ioport(void __iomem *address)
26*5cfe469cSThippeswamy Havalige {
27*5cfe469cSThippeswamy Havalige 	int ret = 0;
28*5cfe469cSThippeswamy Havalige 	struct pci_controller *hose;
29*5cfe469cSThippeswamy Havalige 	resource_size_t size;
30*5cfe469cSThippeswamy Havalige 
31*5cfe469cSThippeswamy Havalige 	spin_lock(&hose_spinlock);
32*5cfe469cSThippeswamy Havalige 	list_for_each_entry(hose, &hose_list, list_node) {
33*5cfe469cSThippeswamy Havalige 		size = pcibios_io_size(hose);
34*5cfe469cSThippeswamy Havalige 		if (address >= hose->io_base_virt &&
35*5cfe469cSThippeswamy Havalige 		    address < (hose->io_base_virt + size)) {
36*5cfe469cSThippeswamy Havalige 			ret = 1;
37*5cfe469cSThippeswamy Havalige 			break;
38*5cfe469cSThippeswamy Havalige 		}
39*5cfe469cSThippeswamy Havalige 	}
40*5cfe469cSThippeswamy Havalige 	spin_unlock(&hose_spinlock);
41*5cfe469cSThippeswamy Havalige 	return ret;
42*5cfe469cSThippeswamy Havalige }
43*5cfe469cSThippeswamy Havalige 
44*5cfe469cSThippeswamy Havalige /* Display the domain number in /proc */
pci_proc_domain(struct pci_bus * bus)45*5cfe469cSThippeswamy Havalige int pci_proc_domain(struct pci_bus *bus)
46*5cfe469cSThippeswamy Havalige {
47*5cfe469cSThippeswamy Havalige 	return pci_domain_nr(bus);
48*5cfe469cSThippeswamy Havalige }
49*5cfe469cSThippeswamy Havalige 
pci_iounmap(struct pci_dev * dev,void __iomem * addr)50a6475c13SMichal Simek void pci_iounmap(struct pci_dev *dev, void __iomem *addr)
51a6475c13SMichal Simek {
52a6475c13SMichal Simek 	if (isa_vaddr_is_ioport(addr))
53a6475c13SMichal Simek 		return;
54a6475c13SMichal Simek 	if (pcibios_vaddr_is_ioport(addr))
55a6475c13SMichal Simek 		return;
56a6475c13SMichal Simek 	iounmap(addr);
57a6475c13SMichal Simek }
58a6475c13SMichal Simek EXPORT_SYMBOL(pci_iounmap);
59