Skip to content

Commit b019ee6

Browse files
Alex Chiangjbarnes993
authored andcommitted
PCI Hotplug: cpqphp: clean up accesses to pcibios_get_irq_routing_table()
Instead of making multiple calls to pcibios_get_irq_routing_table, let's just do it once and save the answer. The reason we were making multiple calls is because we liked to calculate its length and perform some loop over it. Instead of open-coding the length calculation every time, provide it in an inline helper function. Finally, since pci_print_IRQ_route() is used only for debug, let's only do it when cpqhp_debug is set. Signed-off-by: Alex Chiang <achiang@hp.com> Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
1 parent 1d2e8b1 commit b019ee6

File tree

3 files changed

+47
-70
lines changed

3 files changed

+47
-70
lines changed

drivers/pci/hotplug/cpqphp.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ extern int cpqhp_debug;
455455
extern int cpqhp_legacy_mode;
456456
extern struct controller *cpqhp_ctrl_list;
457457
extern struct pci_func *cpqhp_slot_list[256];
458+
extern struct irq_routing_table *cpqhp_routing_table;
458459

459460
/* these can be gotten rid of, but for debugging they are purty */
460461
extern u8 cpqhp_nic_irq;
@@ -733,4 +734,12 @@ static inline int wait_for_ctrl_irq(struct controller *ctrl)
733734
return retval;
734735
}
735736

737+
#include <asm/pci_x86.h>
738+
static inline int cpqhp_routing_table_length(void)
739+
{
740+
BUG_ON(cpqhp_routing_table == NULL);
741+
return ((cpqhp_routing_table->size - sizeof(struct irq_routing_table)) /
742+
sizeof(struct irq_info));
743+
}
744+
736745
#endif

drivers/pci/hotplug/cpqphp_core.c

Lines changed: 31 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@
4444

4545
#include "cpqphp.h"
4646
#include "cpqphp_nvram.h"
47-
#include <asm/pci_x86.h>
4847

4948

5049
/* Global variables */
5150
int cpqhp_debug;
5251
int cpqhp_legacy_mode;
5352
struct controller *cpqhp_ctrl_list; /* = NULL */
5453
struct pci_func *cpqhp_slot_list[256];
54+
struct irq_routing_table *cpqhp_routing_table;
5555

5656
/* local variables */
5757
static void __iomem *smbios_table;
@@ -154,40 +154,42 @@ static int init_SERR(struct controller * ctrl)
154154
return 0;
155155
}
156156

157-
/* nice debugging output */
158-
static int pci_print_IRQ_route (void)
157+
static int init_cpqhp_routing_table(void)
159158
{
160-
struct irq_routing_table *routing_table;
161159
int len;
162-
int loop;
163-
164-
u8 tbus, tdevice, tslot;
165160

166-
routing_table = pcibios_get_irq_routing_table();
167-
if (routing_table == NULL) {
168-
err("No BIOS Routing Table??? Not good\n");
161+
cpqhp_routing_table = pcibios_get_irq_routing_table();
162+
if (cpqhp_routing_table == NULL)
169163
return -ENOMEM;
170-
}
171164

172-
len = (routing_table->size - sizeof(struct irq_routing_table)) /
173-
sizeof(struct irq_info);
174-
/* Make sure I got at least one entry */
165+
len = cpqhp_routing_table_length();
175166
if (len == 0) {
176-
kfree(routing_table);
167+
kfree(cpqhp_routing_table);
168+
cpqhp_routing_table = NULL;
177169
return -1;
178170
}
179171

180-
dbg("bus dev func slot\n");
172+
return 0;
173+
}
174+
175+
/* nice debugging output */
176+
static void pci_print_IRQ_route(void)
177+
{
178+
int len;
179+
int loop;
180+
u8 tbus, tdevice, tslot;
181+
182+
len = cpqhp_routing_table_length();
181183

184+
dbg("bus dev func slot\n");
182185
for (loop = 0; loop < len; ++loop) {
183-
tbus = routing_table->slots[loop].bus;
184-
tdevice = routing_table->slots[loop].devfn;
185-
tslot = routing_table->slots[loop].slot;
186+
tbus = cpqhp_routing_table->slots[loop].bus;
187+
tdevice = cpqhp_routing_table->slots[loop].devfn;
188+
tslot = cpqhp_routing_table->slots[loop].slot;
186189
dbg("%d %d %d %d\n", tbus, tdevice >> 3, tdevice & 0x7, tslot);
187190

188191
}
189-
kfree(routing_table);
190-
return 0;
192+
return;
191193
}
192194

193195

@@ -331,7 +333,6 @@ static int ctrl_slot_cleanup (struct controller * ctrl)
331333
static int
332334
get_slot_mapping(struct pci_bus *bus, u8 bus_num, u8 dev_num, u8 *slot)
333335
{
334-
struct irq_routing_table *PCIIRQRoutingInfoLength;
335336
u32 work;
336337
long len;
337338
long loop;
@@ -342,26 +343,14 @@ get_slot_mapping(struct pci_bus *bus, u8 bus_num, u8 dev_num, u8 *slot)
342343

343344
bridgeSlot = 0xFF;
344345

345-
PCIIRQRoutingInfoLength = pcibios_get_irq_routing_table();
346-
if (!PCIIRQRoutingInfoLength)
347-
return -1;
348-
349-
len = (PCIIRQRoutingInfoLength->size -
350-
sizeof(struct irq_routing_table)) / sizeof(struct irq_info);
351-
/* Make sure I got at least one entry */
352-
if (len == 0) {
353-
kfree(PCIIRQRoutingInfoLength);
354-
return -1;
355-
}
356-
346+
len = cpqhp_routing_table_length();
357347
for (loop = 0; loop < len; ++loop) {
358-
tbus = PCIIRQRoutingInfoLength->slots[loop].bus;
359-
tdevice = PCIIRQRoutingInfoLength->slots[loop].devfn >> 3;
360-
tslot = PCIIRQRoutingInfoLength->slots[loop].slot;
348+
tbus = cpqhp_routing_table->slots[loop].bus;
349+
tdevice = cpqhp_routing_table->slots[loop].devfn >> 3;
350+
tslot = cpqhp_routing_table->slots[loop].slot;
361351

362352
if ((tbus == bus_num) && (tdevice == dev_num)) {
363353
*slot = tslot;
364-
kfree(PCIIRQRoutingInfoLength);
365354
return 0;
366355
} else {
367356
/* Did not get a match on the target PCI device. Check
@@ -396,10 +385,8 @@ get_slot_mapping(struct pci_bus *bus, u8 bus_num, u8 dev_num, u8 *slot)
396385
*/
397386
if (bridgeSlot != 0xFF) {
398387
*slot = bridgeSlot;
399-
kfree(PCIIRQRoutingInfoLength);
400388
return 0;
401389
}
402-
kfree(PCIIRQRoutingInfoLength);
403390
/* Couldn't find an entry in the routing table for this PCI device */
404391
return -1;
405392
}
@@ -782,10 +769,13 @@ static int one_time_init(void)
782769

783770
power_mode = 0;
784771

785-
retval = pci_print_IRQ_route();
772+
retval = init_cpqhp_routing_table();
786773
if (retval)
787774
goto error;
788775

776+
if (cpqhp_debug)
777+
pci_print_IRQ_route();
778+
789779
dbg("Initialize + Start the notification mechanism \n");
790780

791781
retval = cpqhp_event_start_thread();

drivers/pci/hotplug/cpqphp_pci.c

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
#include "../pci.h"
3838
#include "cpqphp.h"
3939
#include "cpqphp_nvram.h"
40-
#include <asm/pci_x86.h>
4140

4241

4342
u8 cpqhp_nic_irq;
@@ -244,39 +243,23 @@ static int PCI_ScanBusForNonBridge(struct controller *ctrl, u8 bus_num, u8 * dev
244243

245244
static int PCI_GetBusDevHelper(struct controller *ctrl, u8 *bus_num, u8 *dev_num, u8 slot, u8 nobridge)
246245
{
247-
struct irq_routing_table *PCIIRQRoutingInfoLength;
248-
long len;
249-
long loop;
246+
int loop, len;
250247
u32 work;
251-
252248
u8 tbus, tdevice, tslot;
253249

254-
PCIIRQRoutingInfoLength = pcibios_get_irq_routing_table();
255-
if (!PCIIRQRoutingInfoLength)
256-
return -1;
257-
258-
len = (PCIIRQRoutingInfoLength->size -
259-
sizeof(struct irq_routing_table)) / sizeof(struct irq_info);
260-
/* Make sure I got at least one entry */
261-
if (len == 0) {
262-
kfree(PCIIRQRoutingInfoLength );
263-
return -1;
264-
}
265-
250+
len = cpqhp_routing_table_length();
266251
for (loop = 0; loop < len; ++loop) {
267-
tbus = PCIIRQRoutingInfoLength->slots[loop].bus;
268-
tdevice = PCIIRQRoutingInfoLength->slots[loop].devfn;
269-
tslot = PCIIRQRoutingInfoLength->slots[loop].slot;
252+
tbus = cpqhp_routing_table->slots[loop].bus;
253+
tdevice = cpqhp_routing_table->slots[loop].devfn;
254+
tslot = cpqhp_routing_table->slots[loop].slot;
270255

271256
if (tslot == slot) {
272257
*bus_num = tbus;
273258
*dev_num = tdevice;
274259
ctrl->pci_bus->number = tbus;
275260
pci_bus_read_config_dword (ctrl->pci_bus, *dev_num, PCI_VENDOR_ID, &work);
276-
if (!nobridge || (work == 0xffffffff)) {
277-
kfree(PCIIRQRoutingInfoLength );
261+
if (!nobridge || (work == 0xffffffff))
278262
return 0;
279-
}
280263

281264
dbg("bus_num %d devfn %d\n", *bus_num, *dev_num);
282265
pci_bus_read_config_dword (ctrl->pci_bus, *dev_num, PCI_CLASS_REVISION, &work);
@@ -287,17 +270,12 @@ static int PCI_GetBusDevHelper(struct controller *ctrl, u8 *bus_num, u8 *dev_num
287270
dbg("Scan bus for Non Bridge: bus %d\n", tbus);
288271
if (PCI_ScanBusForNonBridge(ctrl, tbus, dev_num) == 0) {
289272
*bus_num = tbus;
290-
kfree(PCIIRQRoutingInfoLength );
291273
return 0;
292274
}
293-
} else {
294-
kfree(PCIIRQRoutingInfoLength );
275+
} else
295276
return 0;
296-
}
297-
298277
}
299278
}
300-
kfree(PCIIRQRoutingInfoLength );
301279
return -1;
302280
}
303281

0 commit comments

Comments
 (0)