aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorKenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>2006-12-21 20:01:02 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2007-02-07 18:50:04 -0500
commita0b1725720d9a023a1dee129234f5972056038c6 (patch)
tree9c8d4049e46a968547750ad0f1b77f2117ddb2e3 /drivers
parent429538ad3eeffec4199d8adddd1e9e4c80b2c08b (diff)
pciehp: cleanup init_slot()
This patch cleans up init_slots() in pciehp_core.c based on pcihp_skeleton.c. This has no functional change. Signed-off-by: Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com> Signed-off-by: Kristen Carlson Accardi <kristen.c.accardi@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/pci/hotplug/pciehp.h10
-rw-r--r--drivers/pci/hotplug/pciehp_core.c90
2 files changed, 37 insertions, 63 deletions
diff --git a/drivers/pci/hotplug/pciehp.h b/drivers/pci/hotplug/pciehp.h
index 4fb12fcda563..6a2f427768ca 100644
--- a/drivers/pci/hotplug/pciehp.h
+++ b/drivers/pci/hotplug/pciehp.h
@@ -50,7 +50,7 @@ extern int pciehp_force;
50#define info(format, arg...) printk(KERN_INFO "%s: " format, MY_NAME , ## arg) 50#define info(format, arg...) printk(KERN_INFO "%s: " format, MY_NAME , ## arg)
51#define warn(format, arg...) printk(KERN_WARNING "%s: " format, MY_NAME , ## arg) 51#define warn(format, arg...) printk(KERN_WARNING "%s: " format, MY_NAME , ## arg)
52 52
53 53#define SLOT_NAME_SIZE 10
54struct slot { 54struct slot {
55 struct slot *next; 55 struct slot *next;
56 u8 bus; 56 u8 bus;
@@ -63,6 +63,7 @@ struct slot {
63 struct hpc_ops *hpc_ops; 63 struct hpc_ops *hpc_ops;
64 struct hotplug_slot *hotplug_slot; 64 struct hotplug_slot *hotplug_slot;
65 struct list_head slot_list; 65 struct list_head slot_list;
66 char name[SLOT_NAME_SIZE];
66}; 67};
67 68
68struct event_info { 69struct event_info {
@@ -233,13 +234,6 @@ static inline int wait_for_ctrl_irq(struct controller *ctrl)
233 return retval; 234 return retval;
234} 235}
235 236
236#define SLOT_NAME_SIZE 10
237
238static inline void make_slot_name(char *buffer, int buffer_size, struct slot *slot)
239{
240 snprintf(buffer, buffer_size, "%04d_%04d", slot->bus, slot->number);
241}
242
243enum php_ctlr_type { 237enum php_ctlr_type {
244 PCI, 238 PCI,
245 ISA, 239 ISA,
diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
index f13f31323e85..051d228e634e 100644
--- a/drivers/pci/hotplug/pciehp_core.c
+++ b/drivers/pci/hotplug/pciehp_core.c
@@ -98,101 +98,81 @@ static void release_slot(struct hotplug_slot *hotplug_slot)
98 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); 98 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
99 99
100 kfree(slot->hotplug_slot->info); 100 kfree(slot->hotplug_slot->info);
101 kfree(slot->hotplug_slot->name);
102 kfree(slot->hotplug_slot); 101 kfree(slot->hotplug_slot);
103 kfree(slot); 102 kfree(slot);
104} 103}
105 104
105static void make_slot_name(struct slot *slot)
106{
107 snprintf(slot->hotplug_slot->name, SLOT_NAME_SIZE, "%04d_%04d",
108 slot->bus, slot->number);
109}
110
106static int init_slots(struct controller *ctrl) 111static int init_slots(struct controller *ctrl)
107{ 112{
108 struct slot *slot; 113 struct slot *slot;
109 struct hpc_ops *hpc_ops;
110 struct hotplug_slot *hotplug_slot; 114 struct hotplug_slot *hotplug_slot;
111 struct hotplug_slot_info *hotplug_slot_info; 115 struct hotplug_slot_info *info;
112 u8 number_of_slots; 116 int retval = -ENOMEM;
113 u8 slot_device; 117 int i;
114 u32 slot_number;
115 int result = -ENOMEM;
116 118
117 number_of_slots = ctrl->num_slots; 119 for (i = 0; i < ctrl->num_slots; i++) {
118 slot_device = ctrl->slot_device_offset;
119 slot_number = ctrl->first_slot;
120
121 while (number_of_slots) {
122 slot = kzalloc(sizeof(*slot), GFP_KERNEL); 120 slot = kzalloc(sizeof(*slot), GFP_KERNEL);
123 if (!slot) 121 if (!slot)
124 goto error; 122 goto error;
125 123
126 slot->hotplug_slot = 124 hotplug_slot = kzalloc(sizeof(*hotplug_slot), GFP_KERNEL);
127 kzalloc(sizeof(*(slot->hotplug_slot)), 125 if (!hotplug_slot)
128 GFP_KERNEL);
129 if (!slot->hotplug_slot)
130 goto error_slot; 126 goto error_slot;
131 hotplug_slot = slot->hotplug_slot; 127 slot->hotplug_slot = hotplug_slot;
132 128
133 hotplug_slot->info = 129 info = kzalloc(sizeof(*info), GFP_KERNEL);
134 kzalloc(sizeof(*(hotplug_slot->info)), 130 if (!info)
135 GFP_KERNEL);
136 if (!hotplug_slot->info)
137 goto error_hpslot; 131 goto error_hpslot;
138 hotplug_slot_info = hotplug_slot->info; 132 hotplug_slot->info = info;
139 hotplug_slot->name = kmalloc(SLOT_NAME_SIZE, GFP_KERNEL);
140 if (!hotplug_slot->name)
141 goto error_info;
142 133
143 slot->ctrl = ctrl; 134 hotplug_slot->name = slot->name;
144 slot->bus = ctrl->slot_bus;
145 slot->device = slot_device;
146 slot->hpc_ops = hpc_ops = ctrl->hpc_ops;
147 135
136 slot->hp_slot = i;
137 slot->ctrl = ctrl;
138 slot->bus = ctrl->pci_dev->subordinate->number;
139 slot->device = ctrl->slot_device_offset + i;
140 slot->hpc_ops = ctrl->hpc_ops;
148 slot->number = ctrl->first_slot; 141 slot->number = ctrl->first_slot;
149 slot->hp_slot = slot_device - ctrl->slot_device_offset;
150 142
151 /* register this slot with the hotplug pci core */ 143 /* register this slot with the hotplug pci core */
152 hotplug_slot->private = slot; 144 hotplug_slot->private = slot;
153 hotplug_slot->release = &release_slot; 145 hotplug_slot->release = &release_slot;
154 make_slot_name(hotplug_slot->name, SLOT_NAME_SIZE, slot); 146 make_slot_name(slot);
155 hotplug_slot->ops = &pciehp_hotplug_slot_ops; 147 hotplug_slot->ops = &pciehp_hotplug_slot_ops;
156 148
157 hpc_ops->get_power_status(slot, 149 get_power_status(hotplug_slot, &info->power_status);
158 &(hotplug_slot_info->power_status)); 150 get_attention_status(hotplug_slot, &info->attention_status);
159 hpc_ops->get_attention_status(slot, 151 get_latch_status(hotplug_slot, &info->latch_status);
160 &(hotplug_slot_info->attention_status)); 152 get_adapter_status(hotplug_slot, &info->adapter_status);
161 hpc_ops->get_latch_status(slot,
162 &(hotplug_slot_info->latch_status));
163 hpc_ops->get_adapter_status(slot,
164 &(hotplug_slot_info->adapter_status));
165 153
166 dbg("Registering bus=%x dev=%x hp_slot=%x sun=%x " 154 dbg("Registering bus=%x dev=%x hp_slot=%x sun=%x "
167 "slot_device_offset=%x\n", 155 "slot_device_offset=%x\n", slot->bus, slot->device,
168 slot->bus, slot->device, slot->hp_slot, slot->number, 156 slot->hp_slot, slot->number, ctrl->slot_device_offset);
169 ctrl->slot_device_offset); 157 retval = pci_hp_register(hotplug_slot);
170 result = pci_hp_register(hotplug_slot); 158 if (retval) {
171 if (result) { 159 err ("pci_hp_register failed with error %d\n", retval);
172 err ("pci_hp_register failed with error %d\n", result); 160 goto error_info;
173 goto error_name;
174 } 161 }
175 162
176 slot->next = ctrl->slot; 163 slot->next = ctrl->slot;
177 ctrl->slot = slot; 164 ctrl->slot = slot;
178
179 number_of_slots--;
180 slot_device++;
181 slot_number += ctrl->slot_num_inc;
182 } 165 }
183 166
184 return 0; 167 return 0;
185
186error_name:
187 kfree(hotplug_slot->name);
188error_info: 168error_info:
189 kfree(hotplug_slot_info); 169 kfree(info);
190error_hpslot: 170error_hpslot:
191 kfree(hotplug_slot); 171 kfree(hotplug_slot);
192error_slot: 172error_slot:
193 kfree(slot); 173 kfree(slot);
194error: 174error:
195 return result; 175 return retval;
196} 176}
197 177
198 178