hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/pci/hotplug/rpaphp_core.c
....@@ -52,7 +52,7 @@
5252 static int set_attention_status(struct hotplug_slot *hotplug_slot, u8 value)
5353 {
5454 int rc;
55
- struct slot *slot = (struct slot *)hotplug_slot->private;
55
+ struct slot *slot = to_slot(hotplug_slot);
5656
5757 switch (value) {
5858 case 0:
....@@ -66,7 +66,7 @@
6666
6767 rc = rtas_set_indicator(DR_INDICATOR, slot->index, value);
6868 if (!rc)
69
- hotplug_slot->info->attention_status = value;
69
+ slot->attention_status = value;
7070
7171 return rc;
7272 }
....@@ -79,7 +79,7 @@
7979 static int get_power_status(struct hotplug_slot *hotplug_slot, u8 *value)
8080 {
8181 int retval, level;
82
- struct slot *slot = (struct slot *)hotplug_slot->private;
82
+ struct slot *slot = to_slot(hotplug_slot);
8383
8484 retval = rtas_get_power_level(slot->power_domain, &level);
8585 if (!retval)
....@@ -94,14 +94,14 @@
9494 */
9595 static int get_attention_status(struct hotplug_slot *hotplug_slot, u8 *value)
9696 {
97
- struct slot *slot = (struct slot *)hotplug_slot->private;
98
- *value = slot->hotplug_slot->info->attention_status;
97
+ struct slot *slot = to_slot(hotplug_slot);
98
+ *value = slot->attention_status;
9999 return 0;
100100 }
101101
102102 static int get_adapter_status(struct hotplug_slot *hotplug_slot, u8 *value)
103103 {
104
- struct slot *slot = (struct slot *)hotplug_slot->private;
104
+ struct slot *slot = to_slot(hotplug_slot);
105105 int rc, state;
106106
107107 rc = rpaphp_get_sensor_state(slot, &state);
....@@ -185,8 +185,8 @@
185185
186186
187187 /* Verify the existence of 'drc_name' and/or 'drc_type' within the
188
- * current node. First obtain it's my-drc-index property. Next,
189
- * obtain the DRC info from it's parent. Use the my-drc-index for
188
+ * current node. First obtain its my-drc-index property. Next,
189
+ * obtain the DRC info from its parent. Use the my-drc-index for
190190 * correlation, and obtain/validate the requested properties.
191191 */
192192
....@@ -288,11 +288,10 @@
288288
289289 static int is_php_type(char *drc_type)
290290 {
291
- unsigned long value;
292291 char *endptr;
293292
294293 /* PCI Hotplug nodes have an integer for drc_type */
295
- value = simple_strtoul(drc_type, &endptr, 10);
294
+ simple_strtoul(drc_type, &endptr, 10);
296295 if (endptr == drc_type)
297296 return 0;
298297
....@@ -330,32 +329,54 @@
330329 return 1;
331330 }
332331
333
-/**
334
- * rpaphp_add_slot -- declare a hotplug slot to the hotplug subsystem.
335
- * @dn: device node of slot
336
- *
337
- * This subroutine will register a hotpluggable slot with the
338
- * PCI hotplug infrastructure. This routine is typically called
339
- * during boot time, if the hotplug slots are present at boot time,
340
- * or is called later, by the dlpar add code, if the slot is
341
- * being dynamically added during runtime.
342
- *
343
- * If the device node points at an embedded (built-in) slot, this
344
- * routine will just return without doing anything, since embedded
345
- * slots cannot be hotplugged.
346
- *
347
- * To remove a slot, it suffices to call rpaphp_deregister_slot().
348
- */
349
-int rpaphp_add_slot(struct device_node *dn)
332
+static int rpaphp_drc_info_add_slot(struct device_node *dn)
333
+{
334
+ struct slot *slot;
335
+ struct property *info;
336
+ struct of_drc_info drc;
337
+ char drc_name[MAX_DRC_NAME_LEN];
338
+ const __be32 *cur;
339
+ u32 count;
340
+ int retval = 0;
341
+
342
+ info = of_find_property(dn, "ibm,drc-info", NULL);
343
+ if (!info)
344
+ return 0;
345
+
346
+ cur = of_prop_next_u32(info, NULL, &count);
347
+ if (cur)
348
+ cur++;
349
+ else
350
+ return 0;
351
+
352
+ of_read_drc_info_cell(&info, &cur, &drc);
353
+ if (!is_php_type(drc.drc_type))
354
+ return 0;
355
+
356
+ sprintf(drc_name, "%s%d", drc.drc_name_prefix, drc.drc_name_suffix_start);
357
+
358
+ slot = alloc_slot_struct(dn, drc.drc_index_start, drc_name, drc.drc_power_domain);
359
+ if (!slot)
360
+ return -ENOMEM;
361
+
362
+ slot->type = simple_strtoul(drc.drc_type, NULL, 10);
363
+ retval = rpaphp_enable_slot(slot);
364
+ if (!retval)
365
+ retval = rpaphp_register_slot(slot);
366
+
367
+ if (retval)
368
+ dealloc_slot_struct(slot);
369
+
370
+ return retval;
371
+}
372
+
373
+static int rpaphp_drc_add_slot(struct device_node *dn)
350374 {
351375 struct slot *slot;
352376 int retval = 0;
353377 int i;
354378 const __be32 *indexes, *names, *types, *power_domains;
355379 char *name, *type;
356
-
357
- if (!dn->name || strcmp(dn->name, "pci"))
358
- return 0;
359380
360381 /* If this is not a hotplug slot, return without doing anything. */
361382 if (!is_php_dn(dn, &indexes, &names, &types, &power_domains))
....@@ -395,6 +416,33 @@
395416 /* XXX FIXME: reports a failure only if last entry in loop failed */
396417 return retval;
397418 }
419
+
420
+/**
421
+ * rpaphp_add_slot -- declare a hotplug slot to the hotplug subsystem.
422
+ * @dn: device node of slot
423
+ *
424
+ * This subroutine will register a hotpluggable slot with the
425
+ * PCI hotplug infrastructure. This routine is typically called
426
+ * during boot time, if the hotplug slots are present at boot time,
427
+ * or is called later, by the dlpar add code, if the slot is
428
+ * being dynamically added during runtime.
429
+ *
430
+ * If the device node points at an embedded (built-in) slot, this
431
+ * routine will just return without doing anything, since embedded
432
+ * slots cannot be hotplugged.
433
+ *
434
+ * To remove a slot, it suffices to call rpaphp_deregister_slot().
435
+ */
436
+int rpaphp_add_slot(struct device_node *dn)
437
+{
438
+ if (!of_node_name_eq(dn, "pci"))
439
+ return 0;
440
+
441
+ if (of_find_property(dn, "ibm,drc-info", NULL))
442
+ return rpaphp_drc_info_add_slot(dn);
443
+ else
444
+ return rpaphp_drc_add_slot(dn);
445
+}
398446 EXPORT_SYMBOL_GPL(rpaphp_add_slot);
399447
400448 static void __exit cleanup_slots(void)
....@@ -409,10 +457,9 @@
409457 list_for_each_entry_safe(slot, next, &rpaphp_slot_head,
410458 rpaphp_slot_list) {
411459 list_del(&slot->rpaphp_slot_list);
412
- pci_hp_deregister(slot->hotplug_slot);
460
+ pci_hp_deregister(&slot->hotplug_slot);
413461 dealloc_slot_struct(slot);
414462 }
415
- return;
416463 }
417464
418465 static int __init rpaphp_init(void)
....@@ -434,7 +481,7 @@
434481
435482 static int enable_slot(struct hotplug_slot *hotplug_slot)
436483 {
437
- struct slot *slot = (struct slot *)hotplug_slot->private;
484
+ struct slot *slot = to_slot(hotplug_slot);
438485 int state;
439486 int retval;
440487
....@@ -446,6 +493,8 @@
446493 return retval;
447494
448495 if (state == PRESENT) {
496
+ pseries_eeh_init_edev_recursive(PCI_DN(slot->dn));
497
+
449498 pci_lock_rescan_remove();
450499 pci_hp_add_devices(slot->bus);
451500 pci_unlock_rescan_remove();
....@@ -464,7 +513,7 @@
464513
465514 static int disable_slot(struct hotplug_slot *hotplug_slot)
466515 {
467
- struct slot *slot = (struct slot *)hotplug_slot->private;
516
+ struct slot *slot = to_slot(hotplug_slot);
468517 if (slot->state == NOT_CONFIGURED)
469518 return -EINVAL;
470519
....@@ -477,7 +526,7 @@
477526 return 0;
478527 }
479528
480
-struct hotplug_slot_ops rpaphp_hotplug_slot_ops = {
529
+const struct hotplug_slot_ops rpaphp_hotplug_slot_ops = {
481530 .enable_slot = enable_slot,
482531 .disable_slot = disable_slot,
483532 .set_attention_status = set_attention_status,