diff options
Diffstat (limited to 'drivers/pci/hotplug/pciehprm_nonacpi.c')
-rw-r--r-- | drivers/pci/hotplug/pciehprm_nonacpi.c | 347 |
1 files changed, 0 insertions, 347 deletions
diff --git a/drivers/pci/hotplug/pciehprm_nonacpi.c b/drivers/pci/hotplug/pciehprm_nonacpi.c index 76c727c74cc0..ed68c3dd0f08 100644 --- a/drivers/pci/hotplug/pciehprm_nonacpi.c +++ b/drivers/pci/hotplug/pciehprm_nonacpi.c | |||
@@ -35,12 +35,7 @@ | |||
35 | #include <linux/pci.h> | 35 | #include <linux/pci.h> |
36 | #include <linux/init.h> | 36 | #include <linux/init.h> |
37 | #include <linux/slab.h> | 37 | #include <linux/slab.h> |
38 | |||
39 | #include <asm/uaccess.h> | 38 | #include <asm/uaccess.h> |
40 | #ifdef CONFIG_IA64 | ||
41 | #include <asm/iosapic.h> | ||
42 | #endif | ||
43 | |||
44 | #include "pciehp.h" | 39 | #include "pciehp.h" |
45 | #include "pciehprm.h" | 40 | #include "pciehprm.h" |
46 | #include "pciehprm_nonacpi.h" | 41 | #include "pciehprm_nonacpi.h" |
@@ -51,11 +46,6 @@ void pciehprm_cleanup(void) | |||
51 | return; | 46 | return; |
52 | } | 47 | } |
53 | 48 | ||
54 | int pciehprm_print_pirt(void) | ||
55 | { | ||
56 | return 0; | ||
57 | } | ||
58 | |||
59 | int pciehprm_get_physical_slot_number(struct controller *ctrl, u32 *sun, u8 busnum, u8 devnum) | 49 | int pciehprm_get_physical_slot_number(struct controller *ctrl, u32 *sun, u8 busnum, u8 devnum) |
60 | { | 50 | { |
61 | 51 | ||
@@ -63,343 +53,6 @@ int pciehprm_get_physical_slot_number(struct controller *ctrl, u32 *sun, u8 busn | |||
63 | return 0; | 53 | return 0; |
64 | } | 54 | } |
65 | 55 | ||
66 | |||
67 | static void print_pci_resource ( struct pci_resource *aprh) | ||
68 | { | ||
69 | struct pci_resource *res; | ||
70 | |||
71 | for (res = aprh; res; res = res->next) | ||
72 | dbg(" base= 0x%x length= 0x%x\n", res->base, res->length); | ||
73 | } | ||
74 | |||
75 | |||
76 | static void phprm_dump_func_res( struct pci_func *fun) | ||
77 | { | ||
78 | struct pci_func *func = fun; | ||
79 | |||
80 | if (func->bus_head) { | ||
81 | dbg(": BUS Resources:\n"); | ||
82 | print_pci_resource (func->bus_head); | ||
83 | } | ||
84 | if (func->io_head) { | ||
85 | dbg(": IO Resources:\n"); | ||
86 | print_pci_resource (func->io_head); | ||
87 | } | ||
88 | if (func->mem_head) { | ||
89 | dbg(": MEM Resources:\n"); | ||
90 | print_pci_resource (func->mem_head); | ||
91 | } | ||
92 | if (func->p_mem_head) { | ||
93 | dbg(": PMEM Resources:\n"); | ||
94 | print_pci_resource (func->p_mem_head); | ||
95 | } | ||
96 | } | ||
97 | |||
98 | static int phprm_get_used_resources ( | ||
99 | struct controller *ctrl, | ||
100 | struct pci_func *func | ||
101 | ) | ||
102 | { | ||
103 | return pciehp_save_used_resources (ctrl, func, !DISABLE_CARD); | ||
104 | } | ||
105 | |||
106 | static int phprm_delete_resource( | ||
107 | struct pci_resource **aprh, | ||
108 | ulong base, | ||
109 | ulong size) | ||
110 | { | ||
111 | struct pci_resource *res; | ||
112 | struct pci_resource *prevnode; | ||
113 | struct pci_resource *split_node; | ||
114 | ulong tbase; | ||
115 | |||
116 | pciehp_resource_sort_and_combine(aprh); | ||
117 | |||
118 | for (res = *aprh; res; res = res->next) { | ||
119 | if (res->base > base) | ||
120 | continue; | ||
121 | |||
122 | if ((res->base + res->length) < (base + size)) | ||
123 | continue; | ||
124 | |||
125 | if (res->base < base) { | ||
126 | tbase = base; | ||
127 | |||
128 | if ((res->length - (tbase - res->base)) < size) | ||
129 | continue; | ||
130 | |||
131 | split_node = (struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL); | ||
132 | if (!split_node) | ||
133 | return -ENOMEM; | ||
134 | |||
135 | split_node->base = res->base; | ||
136 | split_node->length = tbase - res->base; | ||
137 | res->base = tbase; | ||
138 | res->length -= split_node->length; | ||
139 | |||
140 | split_node->next = res->next; | ||
141 | res->next = split_node; | ||
142 | } | ||
143 | |||
144 | if (res->length >= size) { | ||
145 | split_node = (struct pci_resource*) kmalloc(sizeof(struct pci_resource), GFP_KERNEL); | ||
146 | if (!split_node) | ||
147 | return -ENOMEM; | ||
148 | |||
149 | split_node->base = res->base + size; | ||
150 | split_node->length = res->length - size; | ||
151 | res->length = size; | ||
152 | |||
153 | split_node->next = res->next; | ||
154 | res->next = split_node; | ||
155 | } | ||
156 | |||
157 | if (*aprh == res) { | ||
158 | *aprh = res->next; | ||
159 | } else { | ||
160 | prevnode = *aprh; | ||
161 | while (prevnode->next != res) | ||
162 | prevnode = prevnode->next; | ||
163 | |||
164 | prevnode->next = res->next; | ||
165 | } | ||
166 | res->next = NULL; | ||
167 | kfree(res); | ||
168 | break; | ||
169 | } | ||
170 | |||
171 | return 0; | ||
172 | } | ||
173 | |||
174 | |||
175 | static int phprm_delete_resources( | ||
176 | struct pci_resource **aprh, | ||
177 | struct pci_resource *this | ||
178 | ) | ||
179 | { | ||
180 | struct pci_resource *res; | ||
181 | |||
182 | for (res = this; res; res = res->next) | ||
183 | phprm_delete_resource(aprh, res->base, res->length); | ||
184 | |||
185 | return 0; | ||
186 | } | ||
187 | |||
188 | |||
189 | static int configure_existing_function( | ||
190 | struct controller *ctrl, | ||
191 | struct pci_func *func | ||
192 | ) | ||
193 | { | ||
194 | int rc; | ||
195 | |||
196 | /* see how much resources the func has used. */ | ||
197 | rc = phprm_get_used_resources (ctrl, func); | ||
198 | |||
199 | if (!rc) { | ||
200 | /* subtract the resources used by the func from ctrl resources */ | ||
201 | rc = phprm_delete_resources (&ctrl->bus_head, func->bus_head); | ||
202 | rc |= phprm_delete_resources (&ctrl->io_head, func->io_head); | ||
203 | rc |= phprm_delete_resources (&ctrl->mem_head, func->mem_head); | ||
204 | rc |= phprm_delete_resources (&ctrl->p_mem_head, func->p_mem_head); | ||
205 | if (rc) | ||
206 | warn("aCEF: cannot del used resources\n"); | ||
207 | } else | ||
208 | err("aCEF: cannot get used resources\n"); | ||
209 | |||
210 | return rc; | ||
211 | } | ||
212 | |||
213 | static int pciehprm_delete_resource( | ||
214 | struct pci_resource **aprh, | ||
215 | ulong base, | ||
216 | ulong size) | ||
217 | { | ||
218 | struct pci_resource *res; | ||
219 | struct pci_resource *prevnode; | ||
220 | struct pci_resource *split_node; | ||
221 | ulong tbase; | ||
222 | |||
223 | pciehp_resource_sort_and_combine(aprh); | ||
224 | |||
225 | for (res = *aprh; res; res = res->next) { | ||
226 | if (res->base > base) | ||
227 | continue; | ||
228 | |||
229 | if ((res->base + res->length) < (base + size)) | ||
230 | continue; | ||
231 | |||
232 | if (res->base < base) { | ||
233 | tbase = base; | ||
234 | |||
235 | if ((res->length - (tbase - res->base)) < size) | ||
236 | continue; | ||
237 | |||
238 | split_node = (struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL); | ||
239 | if (!split_node) | ||
240 | return -ENOMEM; | ||
241 | |||
242 | split_node->base = res->base; | ||
243 | split_node->length = tbase - res->base; | ||
244 | res->base = tbase; | ||
245 | res->length -= split_node->length; | ||
246 | |||
247 | split_node->next = res->next; | ||
248 | res->next = split_node; | ||
249 | } | ||
250 | |||
251 | if (res->length >= size) { | ||
252 | split_node = (struct pci_resource*) kmalloc(sizeof(struct pci_resource), GFP_KERNEL); | ||
253 | if (!split_node) | ||
254 | return -ENOMEM; | ||
255 | |||
256 | split_node->base = res->base + size; | ||
257 | split_node->length = res->length - size; | ||
258 | res->length = size; | ||
259 | |||
260 | split_node->next = res->next; | ||
261 | res->next = split_node; | ||
262 | } | ||
263 | |||
264 | if (*aprh == res) { | ||
265 | *aprh = res->next; | ||
266 | } else { | ||
267 | prevnode = *aprh; | ||
268 | while (prevnode->next != res) | ||
269 | prevnode = prevnode->next; | ||
270 | |||
271 | prevnode->next = res->next; | ||
272 | } | ||
273 | res->next = NULL; | ||
274 | kfree(res); | ||
275 | break; | ||
276 | } | ||
277 | |||
278 | return 0; | ||
279 | } | ||
280 | |||
281 | static int bind_pci_resources_to_slots ( struct controller *ctrl) | ||
282 | { | ||
283 | struct pci_func *func, new_func; | ||
284 | int busn = ctrl->slot_bus; | ||
285 | int devn, funn; | ||
286 | u32 vid; | ||
287 | |||
288 | for (devn = 0; devn < 32; devn++) { | ||
289 | for (funn = 0; funn < 8; funn++) { | ||
290 | /* | ||
291 | if (devn == ctrl->device && funn == ctrl->function) | ||
292 | continue; | ||
293 | */ | ||
294 | /* find out if this entry is for an occupied slot */ | ||
295 | vid = 0xFFFFFFFF; | ||
296 | |||
297 | pci_bus_read_config_dword(ctrl->pci_dev->subordinate, PCI_DEVFN(devn, funn), PCI_VENDOR_ID, &vid); | ||
298 | |||
299 | if (vid != 0xFFFFFFFF) { | ||
300 | dbg("%s: vid = %x bus %x dev %x fun %x\n", __FUNCTION__, | ||
301 | vid, busn, devn, funn); | ||
302 | func = pciehp_slot_find(busn, devn, funn); | ||
303 | dbg("%s: func = %p\n", __FUNCTION__,func); | ||
304 | if (!func) { | ||
305 | memset(&new_func, 0, sizeof(struct pci_func)); | ||
306 | new_func.bus = busn; | ||
307 | new_func.device = devn; | ||
308 | new_func.function = funn; | ||
309 | new_func.is_a_board = 1; | ||
310 | configure_existing_function(ctrl, &new_func); | ||
311 | phprm_dump_func_res(&new_func); | ||
312 | } else { | ||
313 | configure_existing_function(ctrl, func); | ||
314 | phprm_dump_func_res(func); | ||
315 | } | ||
316 | dbg("aCCF:existing PCI 0x%x Func ResourceDump\n", ctrl->bus); | ||
317 | } | ||
318 | } | ||
319 | } | ||
320 | |||
321 | return 0; | ||
322 | } | ||
323 | |||
324 | static void phprm_dump_ctrl_res( struct controller *ctlr) | ||
325 | { | ||
326 | struct controller *ctrl = ctlr; | ||
327 | |||
328 | if (ctrl->bus_head) { | ||
329 | dbg(": BUS Resources:\n"); | ||
330 | print_pci_resource (ctrl->bus_head); | ||
331 | } | ||
332 | if (ctrl->io_head) { | ||
333 | dbg(": IO Resources:\n"); | ||
334 | print_pci_resource (ctrl->io_head); | ||
335 | } | ||
336 | if (ctrl->mem_head) { | ||
337 | dbg(": MEM Resources:\n"); | ||
338 | print_pci_resource (ctrl->mem_head); | ||
339 | } | ||
340 | if (ctrl->p_mem_head) { | ||
341 | dbg(": PMEM Resources:\n"); | ||
342 | print_pci_resource (ctrl->p_mem_head); | ||
343 | } | ||
344 | } | ||
345 | |||
346 | /* | ||
347 | * phprm_find_available_resources | ||
348 | * | ||
349 | * Finds available memory, IO, and IRQ resources for programming | ||
350 | * devices which may be added to the system | ||
351 | * this function is for hot plug ADD! | ||
352 | * | ||
353 | * returns 0 if success | ||
354 | */ | ||
355 | int pciehprm_find_available_resources(struct controller *ctrl) | ||
356 | { | ||
357 | struct pci_func func; | ||
358 | u32 rc; | ||
359 | |||
360 | memset(&func, 0, sizeof(struct pci_func)); | ||
361 | |||
362 | func.bus = ctrl->bus; | ||
363 | func.device = ctrl->device; | ||
364 | func.function = ctrl->function; | ||
365 | func.is_a_board = 1; | ||
366 | |||
367 | /* Get resources for this PCI bridge */ | ||
368 | rc = pciehp_save_used_resources (ctrl, &func, !DISABLE_CARD); | ||
369 | dbg("%s: pciehp_save_used_resources rc = %d\n", __FUNCTION__, rc); | ||
370 | |||
371 | if (func.mem_head) | ||
372 | func.mem_head->next = ctrl->mem_head; | ||
373 | ctrl->mem_head = func.mem_head; | ||
374 | |||
375 | if (func.p_mem_head) | ||
376 | func.p_mem_head->next = ctrl->p_mem_head; | ||
377 | ctrl->p_mem_head = func.p_mem_head; | ||
378 | |||
379 | if (func.io_head) | ||
380 | func.io_head->next = ctrl->io_head; | ||
381 | ctrl->io_head = func.io_head; | ||
382 | |||
383 | if(func.bus_head) | ||
384 | func.bus_head->next = ctrl->bus_head; | ||
385 | ctrl->bus_head = func.bus_head; | ||
386 | |||
387 | if (ctrl->bus_head) | ||
388 | pciehprm_delete_resource(&ctrl->bus_head, ctrl->pci_dev->subordinate->number, 1); | ||
389 | |||
390 | dbg("%s:pre-Bind PCI 0x%x Ctrl Resource Dump\n", __FUNCTION__, ctrl->bus); | ||
391 | phprm_dump_ctrl_res(ctrl); | ||
392 | |||
393 | dbg("%s: before bind_pci_resources_to slots\n", __FUNCTION__); | ||
394 | |||
395 | bind_pci_resources_to_slots (ctrl); | ||
396 | |||
397 | dbg("%s:post-Bind PCI 0x%x Ctrl Resource Dump\n", __FUNCTION__, ctrl->bus); | ||
398 | phprm_dump_ctrl_res(ctrl); | ||
399 | |||
400 | return (rc); | ||
401 | } | ||
402 | |||
403 | int pciehprm_set_hpp( | 56 | int pciehprm_set_hpp( |
404 | struct controller *ctrl, | 57 | struct controller *ctrl, |
405 | struct pci_func *func, | 58 | struct pci_func *func, |