2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * Copyright (c) 2009 Isaku Yamahata
17 * VA Linux Systems Japan K.K.
20 #include <linux/kernel.h>
21 #include <linux/list.h>
22 #include <linux/pci.h>
24 #define PCI_NUM_BARS 6
25 #define PCI_NUM_FUNC 8
27 struct pci_iomul_func {
32 /* only start and end are used */
33 unsigned long io_size;
35 struct resource resource[PCI_NUM_BARS];
36 struct resource dummy_parent;
39 struct pci_iomul_switch {
40 struct list_head list; /* bus_list_lock protects */
43 * This lock the following entry and following
44 * pci_iomul_slot/pci_iomul_func.
49 struct resource io_resource;
50 struct resource *io_region;
52 struct pci_dev *current_pdev;
60 /* func which has the largeset io size*/
61 struct pci_iomul_func *func;
63 struct list_head slots;
66 static inline void pci_iomul_switch_get(struct pci_iomul_switch *sw)
71 static inline void pci_iomul_switch_release(struct kref *kref)
73 struct pci_iomul_switch *sw = container_of(kref,
74 struct pci_iomul_switch,
79 static inline void pci_iomul_switch_put(struct pci_iomul_switch *sw)
81 kref_put(&sw->kref, &pci_iomul_switch_release);
84 struct pci_iomul_slot {
85 struct list_head sibling;
89 * when pcie, the primary busnr of the PCI-PCI bridge on which
93 struct resource dummy_parent[PCI_NUM_RESOURCES - PCI_BRIDGE_RESOURCES];
100 struct pci_iomul_func *func[PCI_NUM_FUNC];
103 static inline void pci_iomul_slot_get(struct pci_iomul_slot *slot)
105 kref_get(&slot->kref);
108 static inline void pci_iomul_slot_release(struct kref *kref)
110 struct pci_iomul_slot *slot = container_of(kref, struct pci_iomul_slot,
115 static inline void pci_iomul_slot_put(struct pci_iomul_slot *slot)
117 kref_put(&slot->kref, &pci_iomul_slot_release);
120 int pci_iomul_switch_io_allocated(const struct pci_iomul_switch *);
121 void pci_iomul_get_lock_switch(struct pci_dev *, struct pci_iomul_switch **,
122 struct pci_iomul_slot **);