diff options
author | rajesh.shah@intel.com <rajesh.shah@intel.com> | 2005-10-13 15:05:36 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2005-10-28 18:36:59 -0400 |
commit | dbd7a78818d125a0ebd5507d4edb4dd5900006ab (patch) | |
tree | 682a1681aad47f70bfb760fca077f54589be92c6 /drivers/pci/hotplug/shpchprm_nonacpi.c | |
parent | e3b1bd572f1cdb247bb4266a593b6894dc578d6a (diff) |
[PATCH] shpchp: use the PCI core for hotplug resource management
This patch converts the standard hotplug controller driver to use
the PCI core for resource management. This eliminates a whole lot
of duplicated code, and integrates shpchp in the system's normal
PCI handling code.
Signed-off-by: Rajesh Shah <rajesh.shah@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/pci/hotplug/shpchprm_nonacpi.c')
-rw-r--r-- | drivers/pci/hotplug/shpchprm_nonacpi.c | 278 |
1 files changed, 0 insertions, 278 deletions
diff --git a/drivers/pci/hotplug/shpchprm_nonacpi.c b/drivers/pci/hotplug/shpchprm_nonacpi.c index 5f75ef7f3df2..9d4ccae5f78e 100644 --- a/drivers/pci/hotplug/shpchprm_nonacpi.c +++ b/drivers/pci/hotplug/shpchprm_nonacpi.c | |||
@@ -34,23 +34,14 @@ | |||
34 | #include <linux/pci.h> | 34 | #include <linux/pci.h> |
35 | #include <linux/init.h> | 35 | #include <linux/init.h> |
36 | #include <asm/uaccess.h> | 36 | #include <asm/uaccess.h> |
37 | #ifdef CONFIG_IA64 | ||
38 | #include <asm/iosapic.h> | ||
39 | #endif | ||
40 | #include "shpchp.h" | 37 | #include "shpchp.h" |
41 | #include "shpchprm.h" | 38 | #include "shpchprm.h" |
42 | #include "shpchprm_nonacpi.h" | ||
43 | 39 | ||
44 | void shpchprm_cleanup(void) | 40 | void shpchprm_cleanup(void) |
45 | { | 41 | { |
46 | return; | 42 | return; |
47 | } | 43 | } |
48 | 44 | ||
49 | int shpchprm_print_pirt(void) | ||
50 | { | ||
51 | return 0; | ||
52 | } | ||
53 | |||
54 | int shpchprm_get_physical_slot_number(struct controller *ctrl, u32 *sun, u8 busnum, u8 devnum) | 45 | int shpchprm_get_physical_slot_number(struct controller *ctrl, u32 *sun, u8 busnum, u8 devnum) |
55 | { | 46 | { |
56 | int offset = devnum - ctrl->slot_device_offset; | 47 | int offset = devnum - ctrl->slot_device_offset; |
@@ -60,275 +51,6 @@ int shpchprm_get_physical_slot_number(struct controller *ctrl, u32 *sun, u8 busn | |||
60 | return 0; | 51 | return 0; |
61 | } | 52 | } |
62 | 53 | ||
63 | static void print_pci_resource ( struct pci_resource *aprh) | ||
64 | { | ||
65 | struct pci_resource *res; | ||
66 | |||
67 | for (res = aprh; res; res = res->next) | ||
68 | dbg(" base= 0x%x length= 0x%x\n", res->base, res->length); | ||
69 | } | ||
70 | |||
71 | |||
72 | static void phprm_dump_func_res( struct pci_func *fun) | ||
73 | { | ||
74 | struct pci_func *func = fun; | ||
75 | |||
76 | if (func->bus_head) { | ||
77 | dbg(": BUS Resources:\n"); | ||
78 | print_pci_resource (func->bus_head); | ||
79 | } | ||
80 | if (func->io_head) { | ||
81 | dbg(": IO Resources:\n"); | ||
82 | print_pci_resource (func->io_head); | ||
83 | } | ||
84 | if (func->mem_head) { | ||
85 | dbg(": MEM Resources:\n"); | ||
86 | print_pci_resource (func->mem_head); | ||
87 | } | ||
88 | if (func->p_mem_head) { | ||
89 | dbg(": PMEM Resources:\n"); | ||
90 | print_pci_resource (func->p_mem_head); | ||
91 | } | ||
92 | } | ||
93 | |||
94 | static int phprm_get_used_resources ( | ||
95 | struct controller *ctrl, | ||
96 | struct pci_func *func | ||
97 | ) | ||
98 | { | ||
99 | return shpchp_save_used_resources (ctrl, func, !DISABLE_CARD); | ||
100 | } | ||
101 | |||
102 | static int phprm_delete_resource( | ||
103 | struct pci_resource **aprh, | ||
104 | ulong base, | ||
105 | ulong size) | ||
106 | { | ||
107 | struct pci_resource *res; | ||
108 | struct pci_resource *prevnode; | ||
109 | struct pci_resource *split_node; | ||
110 | ulong tbase; | ||
111 | |||
112 | shpchp_resource_sort_and_combine(aprh); | ||
113 | |||
114 | for (res = *aprh; res; res = res->next) { | ||
115 | if (res->base > base) | ||
116 | continue; | ||
117 | |||
118 | if ((res->base + res->length) < (base + size)) | ||
119 | continue; | ||
120 | |||
121 | if (res->base < base) { | ||
122 | tbase = base; | ||
123 | |||
124 | if ((res->length - (tbase - res->base)) < size) | ||
125 | continue; | ||
126 | |||
127 | split_node = (struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL); | ||
128 | if (!split_node) | ||
129 | return -ENOMEM; | ||
130 | |||
131 | split_node->base = res->base; | ||
132 | split_node->length = tbase - res->base; | ||
133 | res->base = tbase; | ||
134 | res->length -= split_node->length; | ||
135 | |||
136 | split_node->next = res->next; | ||
137 | res->next = split_node; | ||
138 | } | ||
139 | |||
140 | if (res->length >= size) { | ||
141 | split_node = (struct pci_resource*) kmalloc(sizeof(struct pci_resource), GFP_KERNEL); | ||
142 | if (!split_node) | ||
143 | return -ENOMEM; | ||
144 | |||
145 | split_node->base = res->base + size; | ||
146 | split_node->length = res->length - size; | ||
147 | res->length = size; | ||
148 | |||
149 | split_node->next = res->next; | ||
150 | res->next = split_node; | ||
151 | } | ||
152 | |||
153 | if (*aprh == res) { | ||
154 | *aprh = res->next; | ||
155 | } else { | ||
156 | prevnode = *aprh; | ||
157 | while (prevnode->next != res) | ||
158 | prevnode = prevnode->next; | ||
159 | |||
160 | prevnode->next = res->next; | ||
161 | } | ||
162 | res->next = NULL; | ||
163 | kfree(res); | ||
164 | break; | ||
165 | } | ||
166 | |||
167 | return 0; | ||
168 | } | ||
169 | |||
170 | |||
171 | static int phprm_delete_resources( | ||
172 | struct pci_resource **aprh, | ||
173 | struct pci_resource *this | ||
174 | ) | ||
175 | { | ||
176 | struct pci_resource *res; | ||
177 | |||
178 | for (res = this; res; res = res->next) | ||
179 | phprm_delete_resource(aprh, res->base, res->length); | ||
180 | |||
181 | return 0; | ||
182 | } | ||
183 | |||
184 | |||
185 | static int configure_existing_function( | ||
186 | struct controller *ctrl, | ||
187 | struct pci_func *func | ||
188 | ) | ||
189 | { | ||
190 | int rc; | ||
191 | |||
192 | /* see how much resources the func has used. */ | ||
193 | rc = phprm_get_used_resources (ctrl, func); | ||
194 | |||
195 | if (!rc) { | ||
196 | /* subtract the resources used by the func from ctrl resources */ | ||
197 | rc = phprm_delete_resources (&ctrl->bus_head, func->bus_head); | ||
198 | rc |= phprm_delete_resources (&ctrl->io_head, func->io_head); | ||
199 | rc |= phprm_delete_resources (&ctrl->mem_head, func->mem_head); | ||
200 | rc |= phprm_delete_resources (&ctrl->p_mem_head, func->p_mem_head); | ||
201 | if (rc) | ||
202 | warn("aCEF: cannot del used resources\n"); | ||
203 | } else | ||
204 | err("aCEF: cannot get used resources\n"); | ||
205 | |||
206 | return rc; | ||
207 | } | ||
208 | |||
209 | static int bind_pci_resources_to_slots ( struct controller *ctrl) | ||
210 | { | ||
211 | struct pci_func *func, new_func; | ||
212 | int busn = ctrl->slot_bus; | ||
213 | int devn, funn; | ||
214 | u32 vid; | ||
215 | |||
216 | for (devn = 0; devn < 32; devn++) { | ||
217 | for (funn = 0; funn < 8; funn++) { | ||
218 | /* | ||
219 | if (devn == ctrl->device && funn == ctrl->function) | ||
220 | continue; | ||
221 | */ | ||
222 | /* find out if this entry is for an occupied slot */ | ||
223 | vid = 0xFFFFFFFF; | ||
224 | |||
225 | pci_bus_read_config_dword(ctrl->pci_dev->subordinate, PCI_DEVFN(devn, funn), PCI_VENDOR_ID, &vid); | ||
226 | |||
227 | if (vid != 0xFFFFFFFF) { | ||
228 | func = shpchp_slot_find(busn, devn, funn); | ||
229 | if (!func) { | ||
230 | memset(&new_func, 0, sizeof(struct pci_func)); | ||
231 | new_func.bus = busn; | ||
232 | new_func.device = devn; | ||
233 | new_func.function = funn; | ||
234 | new_func.is_a_board = 1; | ||
235 | configure_existing_function(ctrl, &new_func); | ||
236 | phprm_dump_func_res(&new_func); | ||
237 | } else { | ||
238 | configure_existing_function(ctrl, func); | ||
239 | phprm_dump_func_res(func); | ||
240 | } | ||
241 | dbg("aCCF:existing PCI 0x%x Func ResourceDump\n", ctrl->bus); | ||
242 | } | ||
243 | } | ||
244 | } | ||
245 | |||
246 | return 0; | ||
247 | } | ||
248 | |||
249 | static void phprm_dump_ctrl_res( struct controller *ctlr) | ||
250 | { | ||
251 | struct controller *ctrl = ctlr; | ||
252 | |||
253 | if (ctrl->bus_head) { | ||
254 | dbg(": BUS Resources:\n"); | ||
255 | print_pci_resource (ctrl->bus_head); | ||
256 | } | ||
257 | if (ctrl->io_head) { | ||
258 | dbg(": IO Resources:\n"); | ||
259 | print_pci_resource (ctrl->io_head); | ||
260 | } | ||
261 | if (ctrl->mem_head) { | ||
262 | dbg(": MEM Resources:\n"); | ||
263 | print_pci_resource (ctrl->mem_head); | ||
264 | } | ||
265 | if (ctrl->p_mem_head) { | ||
266 | dbg(": PMEM Resources:\n"); | ||
267 | print_pci_resource (ctrl->p_mem_head); | ||
268 | } | ||
269 | } | ||
270 | |||
271 | /* | ||
272 | * phprm_find_available_resources | ||
273 | * | ||
274 | * Finds available memory, IO, and IRQ resources for programming | ||
275 | * devices which may be added to the system | ||
276 | * this function is for hot plug ADD! | ||
277 | * | ||
278 | * returns 0 if success | ||
279 | */ | ||
280 | int shpchprm_find_available_resources(struct controller *ctrl) | ||
281 | { | ||
282 | struct pci_func func; | ||
283 | u32 rc; | ||
284 | |||
285 | memset(&func, 0, sizeof(struct pci_func)); | ||
286 | |||
287 | func.bus = ctrl->bus; | ||
288 | func.device = ctrl->device; | ||
289 | func.function = ctrl->function; | ||
290 | func.is_a_board = 1; | ||
291 | |||
292 | /* Get resources for this PCI bridge */ | ||
293 | rc = shpchp_save_used_resources (ctrl, &func, !DISABLE_CARD); | ||
294 | dbg("%s: shpchp_save_used_resources rc = %d\n", __FUNCTION__, rc); | ||
295 | |||
296 | if (func.mem_head) | ||
297 | func.mem_head->next = ctrl->mem_head; | ||
298 | ctrl->mem_head = func.mem_head; | ||
299 | |||
300 | if (func.p_mem_head) | ||
301 | func.p_mem_head->next = ctrl->p_mem_head; | ||
302 | ctrl->p_mem_head = func.p_mem_head; | ||
303 | |||
304 | if (func.io_head) | ||
305 | func.io_head->next = ctrl->io_head; | ||
306 | ctrl->io_head = func.io_head; | ||
307 | |||
308 | if(func.bus_head) | ||
309 | func.bus_head->next = ctrl->bus_head; | ||
310 | ctrl->bus_head = func.bus_head; | ||
311 | if (ctrl->bus_head) | ||
312 | phprm_delete_resource(&ctrl->bus_head, ctrl->pci_dev->subordinate->number, 1); | ||
313 | |||
314 | dbg("%s:pre-Bind PCI 0x%x Ctrl Resource Dump\n", __FUNCTION__, ctrl->bus); | ||
315 | phprm_dump_ctrl_res(ctrl); | ||
316 | bind_pci_resources_to_slots (ctrl); | ||
317 | |||
318 | dbg("%s:post-Bind PCI 0x%x Ctrl Resource Dump\n", __FUNCTION__, ctrl->bus); | ||
319 | phprm_dump_ctrl_res(ctrl); | ||
320 | |||
321 | |||
322 | /* If all of the following fail, we don't have any resources for hot plug add */ | ||
323 | rc = 1; | ||
324 | rc &= shpchp_resource_sort_and_combine(&(ctrl->mem_head)); | ||
325 | rc &= shpchp_resource_sort_and_combine(&(ctrl->p_mem_head)); | ||
326 | rc &= shpchp_resource_sort_and_combine(&(ctrl->io_head)); | ||
327 | rc &= shpchp_resource_sort_and_combine(&(ctrl->bus_head)); | ||
328 | |||
329 | return (rc); | ||
330 | } | ||
331 | |||
332 | int shpchprm_set_hpp( | 54 | int shpchprm_set_hpp( |
333 | struct controller *ctrl, | 55 | struct controller *ctrl, |
334 | struct pci_func *func, | 56 | struct pci_func *func, |