diff options
Diffstat (limited to 'arch/x86/pci/i386.c')
-rw-r--r-- | arch/x86/pci/i386.c | 85 |
1 files changed, 84 insertions, 1 deletions
diff --git a/arch/x86/pci/i386.c b/arch/x86/pci/i386.c index 91821a1a0c3a..831971e731f7 100644 --- a/arch/x86/pci/i386.c +++ b/arch/x86/pci/i386.c | |||
@@ -39,6 +39,87 @@ | |||
39 | #include <asm/io_apic.h> | 39 | #include <asm/io_apic.h> |
40 | 40 | ||
41 | 41 | ||
42 | /* | ||
43 | * This list of dynamic mappings is for temporarily maintaining | ||
44 | * original BIOS BAR addresses for possible reinstatement. | ||
45 | */ | ||
46 | struct pcibios_fwaddrmap { | ||
47 | struct list_head list; | ||
48 | struct pci_dev *dev; | ||
49 | resource_size_t fw_addr[DEVICE_COUNT_RESOURCE]; | ||
50 | }; | ||
51 | |||
52 | static LIST_HEAD(pcibios_fwaddrmappings); | ||
53 | static DEFINE_SPINLOCK(pcibios_fwaddrmap_lock); | ||
54 | |||
55 | /* Must be called with 'pcibios_fwaddrmap_lock' lock held. */ | ||
56 | static struct pcibios_fwaddrmap *pcibios_fwaddrmap_lookup(struct pci_dev *dev) | ||
57 | { | ||
58 | struct pcibios_fwaddrmap *map; | ||
59 | |||
60 | WARN_ON(!spin_is_locked(&pcibios_fwaddrmap_lock)); | ||
61 | |||
62 | list_for_each_entry(map, &pcibios_fwaddrmappings, list) | ||
63 | if (map->dev == dev) | ||
64 | return map; | ||
65 | |||
66 | return NULL; | ||
67 | } | ||
68 | |||
69 | static void | ||
70 | pcibios_save_fw_addr(struct pci_dev *dev, int idx, resource_size_t fw_addr) | ||
71 | { | ||
72 | unsigned long flags; | ||
73 | struct pcibios_fwaddrmap *map; | ||
74 | |||
75 | spin_lock_irqsave(&pcibios_fwaddrmap_lock, flags); | ||
76 | map = pcibios_fwaddrmap_lookup(dev); | ||
77 | if (!map) { | ||
78 | spin_unlock_irqrestore(&pcibios_fwaddrmap_lock, flags); | ||
79 | map = kzalloc(sizeof(*map), GFP_KERNEL); | ||
80 | if (!map) | ||
81 | return; | ||
82 | |||
83 | map->dev = pci_dev_get(dev); | ||
84 | map->fw_addr[idx] = fw_addr; | ||
85 | INIT_LIST_HEAD(&map->list); | ||
86 | |||
87 | spin_lock_irqsave(&pcibios_fwaddrmap_lock, flags); | ||
88 | list_add_tail(&map->list, &pcibios_fwaddrmappings); | ||
89 | } else | ||
90 | map->fw_addr[idx] = fw_addr; | ||
91 | spin_unlock_irqrestore(&pcibios_fwaddrmap_lock, flags); | ||
92 | } | ||
93 | |||
94 | resource_size_t pcibios_retrieve_fw_addr(struct pci_dev *dev, int idx) | ||
95 | { | ||
96 | unsigned long flags; | ||
97 | struct pcibios_fwaddrmap *map; | ||
98 | resource_size_t fw_addr = 0; | ||
99 | |||
100 | spin_lock_irqsave(&pcibios_fwaddrmap_lock, flags); | ||
101 | map = pcibios_fwaddrmap_lookup(dev); | ||
102 | if (map) | ||
103 | fw_addr = map->fw_addr[idx]; | ||
104 | spin_unlock_irqrestore(&pcibios_fwaddrmap_lock, flags); | ||
105 | |||
106 | return fw_addr; | ||
107 | } | ||
108 | |||
109 | static void pcibios_fw_addr_list_del(void) | ||
110 | { | ||
111 | unsigned long flags; | ||
112 | struct pcibios_fwaddrmap *entry, *next; | ||
113 | |||
114 | spin_lock_irqsave(&pcibios_fwaddrmap_lock, flags); | ||
115 | list_for_each_entry_safe(entry, next, &pcibios_fwaddrmappings, list) { | ||
116 | list_del(&entry->list); | ||
117 | pci_dev_put(entry->dev); | ||
118 | kfree(entry); | ||
119 | } | ||
120 | spin_unlock_irqrestore(&pcibios_fwaddrmap_lock, flags); | ||
121 | } | ||
122 | |||
42 | static int | 123 | static int |
43 | skip_isa_ioresource_align(struct pci_dev *dev) { | 124 | skip_isa_ioresource_align(struct pci_dev *dev) { |
44 | 125 | ||
@@ -182,7 +263,8 @@ static void __init pcibios_allocate_resources(int pass) | |||
182 | idx, r, disabled, pass); | 263 | idx, r, disabled, pass); |
183 | if (pci_claim_resource(dev, idx) < 0) { | 264 | if (pci_claim_resource(dev, idx) < 0) { |
184 | /* We'll assign a new address later */ | 265 | /* We'll assign a new address later */ |
185 | dev->fw_addr[idx] = r->start; | 266 | pcibios_save_fw_addr(dev, |
267 | idx, r->start); | ||
186 | r->end -= r->start; | 268 | r->end -= r->start; |
187 | r->start = 0; | 269 | r->start = 0; |
188 | } | 270 | } |
@@ -228,6 +310,7 @@ static int __init pcibios_assign_resources(void) | |||
228 | } | 310 | } |
229 | 311 | ||
230 | pci_assign_unassigned_resources(); | 312 | pci_assign_unassigned_resources(); |
313 | pcibios_fw_addr_list_del(); | ||
231 | 314 | ||
232 | return 0; | 315 | return 0; |
233 | } | 316 | } |