forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-04 1543e317f1da31b75942316931e8f491a8920811
kernel/drivers/pci/hotplug/cpci_hotplug_core.c
....@@ -57,7 +57,7 @@
5757 static int get_adapter_status(struct hotplug_slot *slot, u8 *value);
5858 static int get_latch_status(struct hotplug_slot *slot, u8 *value);
5959
60
-static struct hotplug_slot_ops cpci_hotplug_slot_ops = {
60
+static const struct hotplug_slot_ops cpci_hotplug_slot_ops = {
6161 .enable_slot = enable_slot,
6262 .disable_slot = disable_slot,
6363 .set_attention_status = set_attention_status,
....@@ -68,29 +68,9 @@
6868 };
6969
7070 static int
71
-update_latch_status(struct hotplug_slot *hotplug_slot, u8 value)
72
-{
73
- struct hotplug_slot_info info;
74
-
75
- memcpy(&info, hotplug_slot->info, sizeof(struct hotplug_slot_info));
76
- info.latch_status = value;
77
- return pci_hp_change_slot_info(hotplug_slot, &info);
78
-}
79
-
80
-static int
81
-update_adapter_status(struct hotplug_slot *hotplug_slot, u8 value)
82
-{
83
- struct hotplug_slot_info info;
84
-
85
- memcpy(&info, hotplug_slot->info, sizeof(struct hotplug_slot_info));
86
- info.adapter_status = value;
87
- return pci_hp_change_slot_info(hotplug_slot, &info);
88
-}
89
-
90
-static int
9171 enable_slot(struct hotplug_slot *hotplug_slot)
9272 {
93
- struct slot *slot = hotplug_slot->private;
73
+ struct slot *slot = to_slot(hotplug_slot);
9474 int retval = 0;
9575
9676 dbg("%s - physical_slot = %s", __func__, slot_name(slot));
....@@ -103,7 +83,7 @@
10383 static int
10484 disable_slot(struct hotplug_slot *hotplug_slot)
10585 {
106
- struct slot *slot = hotplug_slot->private;
86
+ struct slot *slot = to_slot(hotplug_slot);
10787 int retval = 0;
10888
10989 dbg("%s - physical_slot = %s", __func__, slot_name(slot));
....@@ -135,8 +115,7 @@
135115 goto disable_error;
136116 }
137117
138
- if (update_adapter_status(slot->hotplug_slot, 0))
139
- warn("failure to update adapter file");
118
+ slot->adapter_status = 0;
140119
141120 if (slot->extracting) {
142121 slot->extracting = 0;
....@@ -160,7 +139,7 @@
160139 static int
161140 get_power_status(struct hotplug_slot *hotplug_slot, u8 *value)
162141 {
163
- struct slot *slot = hotplug_slot->private;
142
+ struct slot *slot = to_slot(hotplug_slot);
164143
165144 *value = cpci_get_power_status(slot);
166145 return 0;
....@@ -169,7 +148,7 @@
169148 static int
170149 get_attention_status(struct hotplug_slot *hotplug_slot, u8 *value)
171150 {
172
- struct slot *slot = hotplug_slot->private;
151
+ struct slot *slot = to_slot(hotplug_slot);
173152
174153 *value = cpci_get_attention_status(slot);
175154 return 0;
....@@ -178,27 +157,29 @@
178157 static int
179158 set_attention_status(struct hotplug_slot *hotplug_slot, u8 status)
180159 {
181
- return cpci_set_attention_status(hotplug_slot->private, status);
160
+ return cpci_set_attention_status(to_slot(hotplug_slot), status);
182161 }
183162
184163 static int
185164 get_adapter_status(struct hotplug_slot *hotplug_slot, u8 *value)
186165 {
187
- *value = hotplug_slot->info->adapter_status;
166
+ struct slot *slot = to_slot(hotplug_slot);
167
+
168
+ *value = slot->adapter_status;
188169 return 0;
189170 }
190171
191172 static int
192173 get_latch_status(struct hotplug_slot *hotplug_slot, u8 *value)
193174 {
194
- *value = hotplug_slot->info->latch_status;
175
+ struct slot *slot = to_slot(hotplug_slot);
176
+
177
+ *value = slot->latch_status;
195178 return 0;
196179 }
197180
198181 static void release_slot(struct slot *slot)
199182 {
200
- kfree(slot->hotplug_slot->info);
201
- kfree(slot->hotplug_slot);
202183 pci_dev_put(slot->dev);
203184 kfree(slot);
204185 }
....@@ -209,8 +190,6 @@
209190 cpci_hp_register_bus(struct pci_bus *bus, u8 first, u8 last)
210191 {
211192 struct slot *slot;
212
- struct hotplug_slot *hotplug_slot;
213
- struct hotplug_slot_info *info;
214193 char name[SLOT_NAME_SIZE];
215194 int status;
216195 int i;
....@@ -229,43 +208,19 @@
229208 goto error;
230209 }
231210
232
- hotplug_slot =
233
- kzalloc(sizeof(struct hotplug_slot), GFP_KERNEL);
234
- if (!hotplug_slot) {
235
- status = -ENOMEM;
236
- goto error_slot;
237
- }
238
- slot->hotplug_slot = hotplug_slot;
239
-
240
- info = kzalloc(sizeof(struct hotplug_slot_info), GFP_KERNEL);
241
- if (!info) {
242
- status = -ENOMEM;
243
- goto error_hpslot;
244
- }
245
- hotplug_slot->info = info;
246
-
247211 slot->bus = bus;
248212 slot->number = i;
249213 slot->devfn = PCI_DEVFN(i, 0);
250214
251215 snprintf(name, SLOT_NAME_SIZE, "%02x:%02x", bus->number, i);
252216
253
- hotplug_slot->private = slot;
254
- hotplug_slot->ops = &cpci_hotplug_slot_ops;
255
-
256
- /*
257
- * Initialize the slot info structure with some known
258
- * good values.
259
- */
260
- dbg("initializing slot %s", name);
261
- info->power_status = cpci_get_power_status(slot);
262
- info->attention_status = cpci_get_attention_status(slot);
217
+ slot->hotplug_slot.ops = &cpci_hotplug_slot_ops;
263218
264219 dbg("registering slot %s", name);
265
- status = pci_hp_register(slot->hotplug_slot, bus, i, name);
220
+ status = pci_hp_register(&slot->hotplug_slot, bus, i, name);
266221 if (status) {
267222 err("pci_hp_register failed with error %d", status);
268
- goto error_info;
223
+ goto error_slot;
269224 }
270225 dbg("slot registered with name: %s", slot_name(slot));
271226
....@@ -276,10 +231,6 @@
276231 up_write(&list_rwsem);
277232 }
278233 return 0;
279
-error_info:
280
- kfree(info);
281
-error_hpslot:
282
- kfree(hotplug_slot);
283234 error_slot:
284235 kfree(slot);
285236 error:
....@@ -305,7 +256,7 @@
305256 slots--;
306257
307258 dbg("deregistering slot %s", slot_name(slot));
308
- pci_hp_deregister(slot->hotplug_slot);
259
+ pci_hp_deregister(&slot->hotplug_slot);
309260 release_slot(slot);
310261 }
311262 }
....@@ -359,10 +310,8 @@
359310 __func__, slot_name(slot));
360311 dev = pci_get_slot(slot->bus, PCI_DEVFN(slot->number, 0));
361312 if (dev) {
362
- if (update_adapter_status(slot->hotplug_slot, 1))
363
- warn("failure to update adapter file");
364
- if (update_latch_status(slot->hotplug_slot, 1))
365
- warn("failure to update latch file");
313
+ slot->adapter_status = 1;
314
+ slot->latch_status = 1;
366315 slot->dev = dev;
367316 }
368317 }
....@@ -424,11 +373,8 @@
424373 dbg("%s - slot %s HS_CSR (2) = %04x",
425374 __func__, slot_name(slot), hs_csr);
426375
427
- if (update_latch_status(slot->hotplug_slot, 1))
428
- warn("failure to update latch file");
429
-
430
- if (update_adapter_status(slot->hotplug_slot, 1))
431
- warn("failure to update adapter file");
376
+ slot->latch_status = 1;
377
+ slot->adapter_status = 1;
432378
433379 cpci_led_off(slot);
434380
....@@ -449,9 +395,7 @@
449395 __func__, slot_name(slot), hs_csr);
450396
451397 if (!slot->extracting) {
452
- if (update_latch_status(slot->hotplug_slot, 0))
453
- warn("failure to update latch file");
454
-
398
+ slot->latch_status = 0;
455399 slot->extracting = 1;
456400 atomic_inc(&extracting);
457401 }
....@@ -465,8 +409,7 @@
465409 */
466410 err("card in slot %s was improperly removed",
467411 slot_name(slot));
468
- if (update_adapter_status(slot->hotplug_slot, 0))
469
- warn("failure to update adapter file");
412
+ slot->adapter_status = 0;
470413 slot->extracting = 0;
471414 atomic_dec(&extracting);
472415 }
....@@ -615,12 +558,11 @@
615558 goto cleanup_null;
616559 list_for_each_entry_safe(slot, tmp, &slot_list, slot_list) {
617560 list_del(&slot->slot_list);
618
- pci_hp_deregister(slot->hotplug_slot);
561
+ pci_hp_deregister(&slot->hotplug_slot);
619562 release_slot(slot);
620563 }
621564 cleanup_null:
622565 up_write(&list_rwsem);
623
- return;
624566 }
625567
626568 int