2018-01-27 04:22:04 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* PCI Hot Plug Controller Driver for RPA-compliant PPC64 platform.
|
|
|
|
* Copyright (C) 2003 Linda Xie <lxie@us.ibm.com>
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Send feedback to <lxie@us.ibm.com>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/moduleparam.h>
|
|
|
|
#include <linux/pci.h>
|
2006-10-14 11:05:19 +08:00
|
|
|
#include <linux/pci_hotplug.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/smp.h>
|
|
|
|
#include <linux/init.h>
|
2010-04-06 23:03:40 +08:00
|
|
|
#include <linux/vmalloc.h>
|
hotplug/drc-info: Add code to search ibm,drc-info property
rpadlpar_core.c: Provide parallel routines to search the older device-
tree properties ("ibm,drc-indexes", "ibm,drc-names", "ibm,drc-types"
and "ibm,drc-power-domains"), or the new property "ibm,drc-info".
The interface to examine the DRC information is changed from a "get"
function that returns values for local verification elsewhere, to a
"check" function that validates the 'name' and/or 'type' of a device
node. This update hides the format of the underlying device-tree
properties, and concentrates the value checks into a single function
without requiring the user to verify whether a search was successful.
Signed-off-by: Michael Bringmann <mwb@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2017-12-02 07:19:48 +08:00
|
|
|
#include <asm/firmware.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <asm/eeh.h> /* for eeh_add_device() */
|
|
|
|
#include <asm/rtas.h> /* rtas_call */
|
|
|
|
#include <asm/pci-bridge.h> /* for pci_controller */
|
|
|
|
#include "../pci.h" /* for pci_add_new_bus */
|
|
|
|
/* and pci_do_scan_bus */
|
|
|
|
#include "rpaphp.h"
|
|
|
|
|
2012-01-13 07:02:20 +08:00
|
|
|
bool rpaphp_debug;
|
2005-04-17 06:20:36 +08:00
|
|
|
LIST_HEAD(rpaphp_slot_head);
|
2014-04-26 04:32:25 +08:00
|
|
|
EXPORT_SYMBOL_GPL(rpaphp_slot_head);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#define DRIVER_VERSION "0.1"
|
|
|
|
#define DRIVER_AUTHOR "Linda Xie <lxie@us.ibm.com>"
|
|
|
|
#define DRIVER_DESC "RPA HOT Plug PCI Controller Driver"
|
|
|
|
|
|
|
|
#define MAX_LOC_CODE 128
|
|
|
|
|
|
|
|
MODULE_AUTHOR(DRIVER_AUTHOR);
|
|
|
|
MODULE_DESCRIPTION(DRIVER_DESC);
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
2008-10-14 00:59:12 +08:00
|
|
|
module_param_named(debug, rpaphp_debug, bool, 0644);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* set_attention_status - set attention LED
|
2007-11-29 01:04:30 +08:00
|
|
|
* @hotplug_slot: target &hotplug_slot
|
|
|
|
* @value: LED control value
|
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
* echo 0 > attention -- set LED OFF
|
|
|
|
* echo 1 > attention -- set LED ON
|
|
|
|
* echo 2 > attention -- set LED ID(identify, light is blinking)
|
|
|
|
*/
|
|
|
|
static int set_attention_status(struct hotplug_slot *hotplug_slot, u8 value)
|
|
|
|
{
|
2007-04-14 06:34:18 +08:00
|
|
|
int rc;
|
2018-09-08 15:59:01 +08:00
|
|
|
struct slot *slot = to_slot(hotplug_slot);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
switch (value) {
|
|
|
|
case 0:
|
|
|
|
case 1:
|
|
|
|
case 2:
|
2007-04-14 06:34:18 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
value = 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
}
|
2007-04-14 06:34:18 +08:00
|
|
|
|
|
|
|
rc = rtas_set_indicator(DR_INDICATOR, slot->index, value);
|
|
|
|
if (!rc)
|
PCI: hotplug: Drop hotplug_slot_info
Ever since the PCI hotplug core was introduced in 2002, drivers had to
allocate and register a struct hotplug_slot_info for every slot:
https://git.kernel.org/tglx/history/c/a8a2069f432c
Apparently the idea was that drivers furnish the hotplug core with an
up-to-date card presence status, power status, latch status and
attention indicator status as well as notify the hotplug core of changes
thereof. However only 4 out of 12 hotplug drivers bother to notify the
hotplug core with pci_hp_change_slot_info() and the hotplug core never
made any use of the information: There is just a single macro in
pci_hotplug_core.c, GET_STATUS(), which uses the hotplug_slot_info if
the driver lacks the corresponding callback in hotplug_slot_ops. The
macro is called when the user reads the attribute via sysfs.
Now, if the callback isn't defined, the attribute isn't exposed in sysfs
in the first place (see e.g. has_power_file()). There are only two
situations when the hotplug_slot_info would actually be accessed:
* If the driver defines ->enable_slot or ->disable_slot but not
->get_power_status.
* If the driver defines ->set_attention_status but not
->get_attention_status.
There is no driver doing the former and just a single driver doing the
latter, namely pnv_php.c. Amend it with a ->get_attention_status
callback. With that, the hotplug_slot_info becomes completely unused by
the PCI hotplug core. But a few drivers use it internally as a cache:
cpcihp uses it to cache the latch_status and adapter_status.
cpqhp uses it to cache the adapter_status.
pnv_php and rpaphp use it to cache the attention_status.
shpchp uses it to cache all four values.
Amend these drivers to cache the information in their private slot
struct. shpchp's slot struct already contains members to cache the
power_status and adapter_status, so additional members are only needed
for the other two values. In the case of cpqphp, the cached value is
only accessed in a single place, so instead of caching it, read the
current value from the hardware.
Caution: acpiphp, cpci, cpqhp, shpchp, asus-wmi and eeepc-laptop
populate the hotplug_slot_info with initial values on probe. That code
is herewith removed. There is a theoretical chance that the code has
side effects without which the driver fails to function, e.g. if the
ACPI method to read the adapter status needs to be executed at least
once on probe. That seems unlikely to me, still maintainers should
review the changes carefully for this possibility.
Rafael adds: "I'm not aware of any case in which it will break anything,
[...] but if that happens, it may be necessary to add the execution of
the control methods in question directly to the initialization part."
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Tyrel Datwyler <tyreld@linux.vnet.ibm.com> # drivers/pci/hotplug/rpa*
Acked-by: Sebastian Ott <sebott@linux.ibm.com> # drivers/pci/hotplug/s390*
Acked-by: Andy Shevchenko <andy.shevchenko@gmail.com> # drivers/platform/x86
Cc: Len Brown <lenb@kernel.org>
Cc: Scott Murray <scott@spiteful.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Oliver OHalloran <oliveroh@au1.ibm.com>
Cc: Gavin Shan <gwshan@linux.vnet.ibm.com>
Cc: Gerald Schaefer <gerald.schaefer@de.ibm.com>
Cc: Corentin Chary <corentin.chary@gmail.com>
Cc: Darren Hart <dvhart@infradead.org>
2018-09-08 15:59:01 +08:00
|
|
|
slot->attention_status = value;
|
2007-04-14 06:34:18 +08:00
|
|
|
|
|
|
|
return rc;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get_power_status - get power status of a slot
|
|
|
|
* @hotplug_slot: slot to get status
|
|
|
|
* @value: pointer to store status
|
|
|
|
*/
|
2014-04-19 08:13:49 +08:00
|
|
|
static int get_power_status(struct hotplug_slot *hotplug_slot, u8 *value)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2007-04-14 06:34:13 +08:00
|
|
|
int retval, level;
|
2018-09-08 15:59:01 +08:00
|
|
|
struct slot *slot = to_slot(hotplug_slot);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-12-28 05:21:11 +08:00
|
|
|
retval = rtas_get_power_level(slot->power_domain, &level);
|
2007-04-14 06:34:13 +08:00
|
|
|
if (!retval)
|
|
|
|
*value = level;
|
2005-04-17 06:20:36 +08:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get_attention_status - get attention LED status
|
2007-11-29 01:04:30 +08:00
|
|
|
* @hotplug_slot: slot to get status
|
|
|
|
* @value: pointer to store status
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2014-04-19 08:13:49 +08:00
|
|
|
static int get_attention_status(struct hotplug_slot *hotplug_slot, u8 *value)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2018-09-08 15:59:01 +08:00
|
|
|
struct slot *slot = to_slot(hotplug_slot);
|
PCI: hotplug: Drop hotplug_slot_info
Ever since the PCI hotplug core was introduced in 2002, drivers had to
allocate and register a struct hotplug_slot_info for every slot:
https://git.kernel.org/tglx/history/c/a8a2069f432c
Apparently the idea was that drivers furnish the hotplug core with an
up-to-date card presence status, power status, latch status and
attention indicator status as well as notify the hotplug core of changes
thereof. However only 4 out of 12 hotplug drivers bother to notify the
hotplug core with pci_hp_change_slot_info() and the hotplug core never
made any use of the information: There is just a single macro in
pci_hotplug_core.c, GET_STATUS(), which uses the hotplug_slot_info if
the driver lacks the corresponding callback in hotplug_slot_ops. The
macro is called when the user reads the attribute via sysfs.
Now, if the callback isn't defined, the attribute isn't exposed in sysfs
in the first place (see e.g. has_power_file()). There are only two
situations when the hotplug_slot_info would actually be accessed:
* If the driver defines ->enable_slot or ->disable_slot but not
->get_power_status.
* If the driver defines ->set_attention_status but not
->get_attention_status.
There is no driver doing the former and just a single driver doing the
latter, namely pnv_php.c. Amend it with a ->get_attention_status
callback. With that, the hotplug_slot_info becomes completely unused by
the PCI hotplug core. But a few drivers use it internally as a cache:
cpcihp uses it to cache the latch_status and adapter_status.
cpqhp uses it to cache the adapter_status.
pnv_php and rpaphp use it to cache the attention_status.
shpchp uses it to cache all four values.
Amend these drivers to cache the information in their private slot
struct. shpchp's slot struct already contains members to cache the
power_status and adapter_status, so additional members are only needed
for the other two values. In the case of cpqphp, the cached value is
only accessed in a single place, so instead of caching it, read the
current value from the hardware.
Caution: acpiphp, cpci, cpqhp, shpchp, asus-wmi and eeepc-laptop
populate the hotplug_slot_info with initial values on probe. That code
is herewith removed. There is a theoretical chance that the code has
side effects without which the driver fails to function, e.g. if the
ACPI method to read the adapter status needs to be executed at least
once on probe. That seems unlikely to me, still maintainers should
review the changes carefully for this possibility.
Rafael adds: "I'm not aware of any case in which it will break anything,
[...] but if that happens, it may be necessary to add the execution of
the control methods in question directly to the initialization part."
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Tyrel Datwyler <tyreld@linux.vnet.ibm.com> # drivers/pci/hotplug/rpa*
Acked-by: Sebastian Ott <sebott@linux.ibm.com> # drivers/pci/hotplug/s390*
Acked-by: Andy Shevchenko <andy.shevchenko@gmail.com> # drivers/platform/x86
Cc: Len Brown <lenb@kernel.org>
Cc: Scott Murray <scott@spiteful.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Oliver OHalloran <oliveroh@au1.ibm.com>
Cc: Gavin Shan <gwshan@linux.vnet.ibm.com>
Cc: Gerald Schaefer <gerald.schaefer@de.ibm.com>
Cc: Corentin Chary <corentin.chary@gmail.com>
Cc: Darren Hart <dvhart@infradead.org>
2018-09-08 15:59:01 +08:00
|
|
|
*value = slot->attention_status;
|
2007-04-14 06:34:15 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2014-04-19 08:13:49 +08:00
|
|
|
static int get_adapter_status(struct hotplug_slot *hotplug_slot, u8 *value)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2018-09-08 15:59:01 +08:00
|
|
|
struct slot *slot = to_slot(hotplug_slot);
|
2007-04-14 06:34:14 +08:00
|
|
|
int rc, state;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-04-14 06:34:14 +08:00
|
|
|
rc = rpaphp_get_sensor_state(slot, &state);
|
|
|
|
|
|
|
|
*value = NOT_VALID;
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
if (state == EMPTY)
|
|
|
|
*value = EMPTY;
|
|
|
|
else if (state == PRESENT)
|
|
|
|
*value = slot->state;
|
|
|
|
|
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2009-12-13 21:11:32 +08:00
|
|
|
static enum pci_bus_speed get_max_bus_speed(struct slot *slot)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-12-13 21:11:32 +08:00
|
|
|
enum pci_bus_speed speed;
|
2005-04-17 06:20:36 +08:00
|
|
|
switch (slot->type) {
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
case 4:
|
|
|
|
case 5:
|
|
|
|
case 6:
|
2009-12-13 21:11:32 +08:00
|
|
|
speed = PCI_SPEED_33MHz; /* speed for case 1-6 */
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
case 8:
|
2009-12-13 21:11:32 +08:00
|
|
|
speed = PCI_SPEED_66MHz;
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case 11:
|
|
|
|
case 14:
|
2009-12-13 21:11:32 +08:00
|
|
|
speed = PCI_SPEED_66MHz_PCIX;
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case 12:
|
|
|
|
case 15:
|
2009-12-13 21:11:32 +08:00
|
|
|
speed = PCI_SPEED_100MHz_PCIX;
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case 13:
|
|
|
|
case 16:
|
2009-12-13 21:11:32 +08:00
|
|
|
speed = PCI_SPEED_133MHz_PCIX;
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
default:
|
2009-12-13 21:11:32 +08:00
|
|
|
speed = PCI_SPEED_UNKNOWN;
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
}
|
2009-12-13 21:11:32 +08:00
|
|
|
|
|
|
|
return speed;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2019-11-11 13:21:35 +08:00
|
|
|
static int get_children_props(struct device_node *dn, const __be32 **drc_indexes,
|
|
|
|
const __be32 **drc_names, const __be32 **drc_types,
|
|
|
|
const __be32 **drc_power_domains)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2019-11-11 13:21:35 +08:00
|
|
|
const __be32 *indexes, *names, *types, *domains;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-05-01 11:54:02 +08:00
|
|
|
indexes = of_get_property(dn, "ibm,drc-indexes", NULL);
|
|
|
|
names = of_get_property(dn, "ibm,drc-names", NULL);
|
|
|
|
types = of_get_property(dn, "ibm,drc-types", NULL);
|
|
|
|
domains = of_get_property(dn, "ibm,drc-power-domains", NULL);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (!indexes || !names || !types || !domains) {
|
|
|
|
/* Slot does not have dynamically-removable children */
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
if (drc_indexes)
|
|
|
|
*drc_indexes = indexes;
|
|
|
|
if (drc_names)
|
|
|
|
/* &drc_names[1] contains NULL terminated slot names */
|
|
|
|
*drc_names = names;
|
|
|
|
if (drc_types)
|
|
|
|
/* &drc_types[1] contains NULL terminated slot types */
|
|
|
|
*drc_types = types;
|
|
|
|
if (drc_power_domains)
|
|
|
|
*drc_power_domains = domains;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
hotplug/drc-info: Add code to search ibm,drc-info property
rpadlpar_core.c: Provide parallel routines to search the older device-
tree properties ("ibm,drc-indexes", "ibm,drc-names", "ibm,drc-types"
and "ibm,drc-power-domains"), or the new property "ibm,drc-info".
The interface to examine the DRC information is changed from a "get"
function that returns values for local verification elsewhere, to a
"check" function that validates the 'name' and/or 'type' of a device
node. This update hides the format of the underlying device-tree
properties, and concentrates the value checks into a single function
without requiring the user to verify whether a search was successful.
Signed-off-by: Michael Bringmann <mwb@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2017-12-02 07:19:48 +08:00
|
|
|
|
|
|
|
/* Verify the existence of 'drc_name' and/or 'drc_type' within the
|
2019-10-16 06:11:22 +08:00
|
|
|
* current node. First obtain its my-drc-index property. Next,
|
|
|
|
* obtain the DRC info from its parent. Use the my-drc-index for
|
hotplug/drc-info: Add code to search ibm,drc-info property
rpadlpar_core.c: Provide parallel routines to search the older device-
tree properties ("ibm,drc-indexes", "ibm,drc-names", "ibm,drc-types"
and "ibm,drc-power-domains"), or the new property "ibm,drc-info".
The interface to examine the DRC information is changed from a "get"
function that returns values for local verification elsewhere, to a
"check" function that validates the 'name' and/or 'type' of a device
node. This update hides the format of the underlying device-tree
properties, and concentrates the value checks into a single function
without requiring the user to verify whether a search was successful.
Signed-off-by: Michael Bringmann <mwb@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2017-12-02 07:19:48 +08:00
|
|
|
* correlation, and obtain/validate the requested properties.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
hotplug/drc-info: Add code to search ibm,drc-info property
rpadlpar_core.c: Provide parallel routines to search the older device-
tree properties ("ibm,drc-indexes", "ibm,drc-names", "ibm,drc-types"
and "ibm,drc-power-domains"), or the new property "ibm,drc-info".
The interface to examine the DRC information is changed from a "get"
function that returns values for local verification elsewhere, to a
"check" function that validates the 'name' and/or 'type' of a device
node. This update hides the format of the underlying device-tree
properties, and concentrates the value checks into a single function
without requiring the user to verify whether a search was successful.
Signed-off-by: Michael Bringmann <mwb@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2017-12-02 07:19:48 +08:00
|
|
|
|
|
|
|
static int rpaphp_check_drc_props_v1(struct device_node *dn, char *drc_name,
|
|
|
|
char *drc_type, unsigned int my_index)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
hotplug/drc-info: Add code to search ibm,drc-info property
rpadlpar_core.c: Provide parallel routines to search the older device-
tree properties ("ibm,drc-indexes", "ibm,drc-names", "ibm,drc-types"
and "ibm,drc-power-domains"), or the new property "ibm,drc-info".
The interface to examine the DRC information is changed from a "get"
function that returns values for local verification elsewhere, to a
"check" function that validates the 'name' and/or 'type' of a device
node. This update hides the format of the underlying device-tree
properties, and concentrates the value checks into a single function
without requiring the user to verify whether a search was successful.
Signed-off-by: Michael Bringmann <mwb@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2017-12-02 07:19:48 +08:00
|
|
|
char *name_tmp, *type_tmp;
|
2019-11-11 13:21:35 +08:00
|
|
|
const __be32 *indexes, *names;
|
|
|
|
const __be32 *types, *domains;
|
2005-04-17 06:20:36 +08:00
|
|
|
int i, rc;
|
|
|
|
|
|
|
|
rc = get_children_props(dn->parent, &indexes, &names, &types, &domains);
|
|
|
|
if (rc < 0) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
name_tmp = (char *) &names[1];
|
|
|
|
type_tmp = (char *) &types[1];
|
|
|
|
|
|
|
|
/* Iterate through parent properties, looking for my-drc-index */
|
2014-04-10 21:02:13 +08:00
|
|
|
for (i = 0; i < be32_to_cpu(indexes[0]); i++) {
|
2019-11-11 13:21:35 +08:00
|
|
|
if (be32_to_cpu(indexes[i + 1]) == my_index)
|
hotplug/drc-info: Add code to search ibm,drc-info property
rpadlpar_core.c: Provide parallel routines to search the older device-
tree properties ("ibm,drc-indexes", "ibm,drc-names", "ibm,drc-types"
and "ibm,drc-power-domains"), or the new property "ibm,drc-info".
The interface to examine the DRC information is changed from a "get"
function that returns values for local verification elsewhere, to a
"check" function that validates the 'name' and/or 'type' of a device
node. This update hides the format of the underlying device-tree
properties, and concentrates the value checks into a single function
without requiring the user to verify whether a search was successful.
Signed-off-by: Michael Bringmann <mwb@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2017-12-02 07:19:48 +08:00
|
|
|
break;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
name_tmp += (strlen(name_tmp) + 1);
|
|
|
|
type_tmp += (strlen(type_tmp) + 1);
|
|
|
|
}
|
|
|
|
|
hotplug/drc-info: Add code to search ibm,drc-info property
rpadlpar_core.c: Provide parallel routines to search the older device-
tree properties ("ibm,drc-indexes", "ibm,drc-names", "ibm,drc-types"
and "ibm,drc-power-domains"), or the new property "ibm,drc-info".
The interface to examine the DRC information is changed from a "get"
function that returns values for local verification elsewhere, to a
"check" function that validates the 'name' and/or 'type' of a device
node. This update hides the format of the underlying device-tree
properties, and concentrates the value checks into a single function
without requiring the user to verify whether a search was successful.
Signed-off-by: Michael Bringmann <mwb@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2017-12-02 07:19:48 +08:00
|
|
|
if (((drc_name == NULL) || (drc_name && !strcmp(drc_name, name_tmp))) &&
|
|
|
|
((drc_type == NULL) || (drc_type && !strcmp(drc_type, type_tmp))))
|
|
|
|
return 0;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
hotplug/drc-info: Add code to search ibm,drc-info property
rpadlpar_core.c: Provide parallel routines to search the older device-
tree properties ("ibm,drc-indexes", "ibm,drc-names", "ibm,drc-types"
and "ibm,drc-power-domains"), or the new property "ibm,drc-info".
The interface to examine the DRC information is changed from a "get"
function that returns values for local verification elsewhere, to a
"check" function that validates the 'name' and/or 'type' of a device
node. This update hides the format of the underlying device-tree
properties, and concentrates the value checks into a single function
without requiring the user to verify whether a search was successful.
Signed-off-by: Michael Bringmann <mwb@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2017-12-02 07:19:48 +08:00
|
|
|
|
|
|
|
static int rpaphp_check_drc_props_v2(struct device_node *dn, char *drc_name,
|
|
|
|
char *drc_type, unsigned int my_index)
|
|
|
|
{
|
|
|
|
struct property *info;
|
|
|
|
unsigned int entries;
|
|
|
|
struct of_drc_info drc;
|
|
|
|
const __be32 *value;
|
|
|
|
char cell_drc_name[MAX_DRC_NAME_LEN];
|
2019-06-04 06:11:58 +08:00
|
|
|
int j;
|
hotplug/drc-info: Add code to search ibm,drc-info property
rpadlpar_core.c: Provide parallel routines to search the older device-
tree properties ("ibm,drc-indexes", "ibm,drc-names", "ibm,drc-types"
and "ibm,drc-power-domains"), or the new property "ibm,drc-info".
The interface to examine the DRC information is changed from a "get"
function that returns values for local verification elsewhere, to a
"check" function that validates the 'name' and/or 'type' of a device
node. This update hides the format of the underlying device-tree
properties, and concentrates the value checks into a single function
without requiring the user to verify whether a search was successful.
Signed-off-by: Michael Bringmann <mwb@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2017-12-02 07:19:48 +08:00
|
|
|
|
|
|
|
info = of_find_property(dn->parent, "ibm,drc-info", NULL);
|
|
|
|
if (info == NULL)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
value = of_prop_next_u32(info, NULL, &entries);
|
|
|
|
if (!value)
|
|
|
|
return -EINVAL;
|
2019-11-11 13:21:31 +08:00
|
|
|
else
|
|
|
|
value++;
|
hotplug/drc-info: Add code to search ibm,drc-info property
rpadlpar_core.c: Provide parallel routines to search the older device-
tree properties ("ibm,drc-indexes", "ibm,drc-names", "ibm,drc-types"
and "ibm,drc-power-domains"), or the new property "ibm,drc-info".
The interface to examine the DRC information is changed from a "get"
function that returns values for local verification elsewhere, to a
"check" function that validates the 'name' and/or 'type' of a device
node. This update hides the format of the underlying device-tree
properties, and concentrates the value checks into a single function
without requiring the user to verify whether a search was successful.
Signed-off-by: Michael Bringmann <mwb@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2017-12-02 07:19:48 +08:00
|
|
|
|
|
|
|
for (j = 0; j < entries; j++) {
|
|
|
|
of_read_drc_info_cell(&info, &value, &drc);
|
|
|
|
|
|
|
|
/* Should now know end of current entry */
|
|
|
|
|
2019-06-04 06:11:58 +08:00
|
|
|
/* Found it */
|
2019-11-11 13:21:36 +08:00
|
|
|
if (my_index >= drc.drc_index_start && my_index <= drc.last_drc_index) {
|
|
|
|
int index = my_index - drc.drc_index_start;
|
2019-06-04 06:11:58 +08:00
|
|
|
sprintf(cell_drc_name, "%s%d", drc.drc_name_prefix,
|
2019-11-11 13:21:36 +08:00
|
|
|
drc.drc_name_suffix_start + index);
|
2019-06-04 06:11:58 +08:00
|
|
|
break;
|
|
|
|
}
|
hotplug/drc-info: Add code to search ibm,drc-info property
rpadlpar_core.c: Provide parallel routines to search the older device-
tree properties ("ibm,drc-indexes", "ibm,drc-names", "ibm,drc-types"
and "ibm,drc-power-domains"), or the new property "ibm,drc-info".
The interface to examine the DRC information is changed from a "get"
function that returns values for local verification elsewhere, to a
"check" function that validates the 'name' and/or 'type' of a device
node. This update hides the format of the underlying device-tree
properties, and concentrates the value checks into a single function
without requiring the user to verify whether a search was successful.
Signed-off-by: Michael Bringmann <mwb@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2017-12-02 07:19:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (((drc_name == NULL) ||
|
|
|
|
(drc_name && !strcmp(drc_name, cell_drc_name))) &&
|
|
|
|
((drc_type == NULL) ||
|
|
|
|
(drc_type && !strcmp(drc_type, drc.drc_type))))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int rpaphp_check_drc_props(struct device_node *dn, char *drc_name,
|
|
|
|
char *drc_type)
|
|
|
|
{
|
2019-11-11 13:21:35 +08:00
|
|
|
const __be32 *my_index;
|
hotplug/drc-info: Add code to search ibm,drc-info property
rpadlpar_core.c: Provide parallel routines to search the older device-
tree properties ("ibm,drc-indexes", "ibm,drc-names", "ibm,drc-types"
and "ibm,drc-power-domains"), or the new property "ibm,drc-info".
The interface to examine the DRC information is changed from a "get"
function that returns values for local verification elsewhere, to a
"check" function that validates the 'name' and/or 'type' of a device
node. This update hides the format of the underlying device-tree
properties, and concentrates the value checks into a single function
without requiring the user to verify whether a search was successful.
Signed-off-by: Michael Bringmann <mwb@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2017-12-02 07:19:48 +08:00
|
|
|
|
|
|
|
my_index = of_get_property(dn, "ibm,my-drc-index", NULL);
|
|
|
|
if (!my_index) {
|
|
|
|
/* Node isn't DLPAR/hotplug capable */
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
PCI: rpaphp: Don't rely on firmware feature to imply drc-info support
In the event that the partition is migrated to a platform with older
firmware that doesn't support the ibm,drc-info property the device
tree is modified to remove the ibm,drc-info property and replace it
with the older style ibm,drc-* properties for types, names, indexes,
and power-domains. One of the requirements of the drc-info firmware
feature is that the client is able to handle both the new property,
and old style properties at runtime. Therefore we can't rely on the
firmware feature alone to dictate which property is currently
present in the device tree.
Fix this short coming by checking explicitly for the ibm,drc-info
property, and falling back to the older ibm,drc-* properties if it
doesn't exist.
Signed-off-by: Tyrel Datwyler <tyreld@linux.ibm.com>
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/1573449697-5448-6-git-send-email-tyreld@linux.ibm.com
2019-11-11 13:21:32 +08:00
|
|
|
if (of_find_property(dn->parent, "ibm,drc-info", NULL))
|
hotplug/drc-info: Add code to search ibm,drc-info property
rpadlpar_core.c: Provide parallel routines to search the older device-
tree properties ("ibm,drc-indexes", "ibm,drc-names", "ibm,drc-types"
and "ibm,drc-power-domains"), or the new property "ibm,drc-info".
The interface to examine the DRC information is changed from a "get"
function that returns values for local verification elsewhere, to a
"check" function that validates the 'name' and/or 'type' of a device
node. This update hides the format of the underlying device-tree
properties, and concentrates the value checks into a single function
without requiring the user to verify whether a search was successful.
Signed-off-by: Michael Bringmann <mwb@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2017-12-02 07:19:48 +08:00
|
|
|
return rpaphp_check_drc_props_v2(dn, drc_name, drc_type,
|
2019-11-11 13:21:35 +08:00
|
|
|
be32_to_cpu(*my_index));
|
hotplug/drc-info: Add code to search ibm,drc-info property
rpadlpar_core.c: Provide parallel routines to search the older device-
tree properties ("ibm,drc-indexes", "ibm,drc-names", "ibm,drc-types"
and "ibm,drc-power-domains"), or the new property "ibm,drc-info".
The interface to examine the DRC information is changed from a "get"
function that returns values for local verification elsewhere, to a
"check" function that validates the 'name' and/or 'type' of a device
node. This update hides the format of the underlying device-tree
properties, and concentrates the value checks into a single function
without requiring the user to verify whether a search was successful.
Signed-off-by: Michael Bringmann <mwb@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2017-12-02 07:19:48 +08:00
|
|
|
else
|
|
|
|
return rpaphp_check_drc_props_v1(dn, drc_name, drc_type,
|
2019-11-11 13:21:35 +08:00
|
|
|
be32_to_cpu(*my_index));
|
hotplug/drc-info: Add code to search ibm,drc-info property
rpadlpar_core.c: Provide parallel routines to search the older device-
tree properties ("ibm,drc-indexes", "ibm,drc-names", "ibm,drc-types"
and "ibm,drc-power-domains"), or the new property "ibm,drc-info".
The interface to examine the DRC information is changed from a "get"
function that returns values for local verification elsewhere, to a
"check" function that validates the 'name' and/or 'type' of a device
node. This update hides the format of the underlying device-tree
properties, and concentrates the value checks into a single function
without requiring the user to verify whether a search was successful.
Signed-off-by: Michael Bringmann <mwb@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2017-12-02 07:19:48 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(rpaphp_check_drc_props);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static int is_php_type(char *drc_type)
|
|
|
|
{
|
|
|
|
char *endptr;
|
|
|
|
|
|
|
|
/* PCI Hotplug nodes have an integer for drc_type */
|
2020-03-12 22:04:12 +08:00
|
|
|
simple_strtoul(drc_type, &endptr, 10);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (endptr == drc_type)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2007-04-14 06:34:22 +08:00
|
|
|
/**
|
|
|
|
* is_php_dn() - return 1 if this is a hotpluggable pci slot, else 0
|
2007-11-29 01:04:30 +08:00
|
|
|
* @dn: target &device_node
|
|
|
|
* @indexes: passed to get_children_props()
|
|
|
|
* @names: passed to get_children_props()
|
|
|
|
* @types: returned from get_children_props()
|
|
|
|
* @power_domains:
|
2007-04-14 06:34:22 +08:00
|
|
|
*
|
|
|
|
* This routine will return true only if the device node is
|
|
|
|
* a hotpluggable slot. This routine will return false
|
|
|
|
* for built-in pci slots (even when the built-in slots are
|
|
|
|
* dlparable.)
|
|
|
|
*/
|
2019-11-11 13:21:35 +08:00
|
|
|
static int is_php_dn(struct device_node *dn, const __be32 **indexes,
|
|
|
|
const __be32 **names, const __be32 **types,
|
|
|
|
const __be32 **power_domains)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2019-11-11 13:21:35 +08:00
|
|
|
const __be32 *drc_types;
|
2005-04-17 06:20:36 +08:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = get_children_props(dn, indexes, names, &drc_types, power_domains);
|
2007-04-14 06:34:22 +08:00
|
|
|
if (rc < 0)
|
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-04-14 06:34:22 +08:00
|
|
|
if (!is_php_type((char *) &drc_types[1]))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
*types = drc_types;
|
|
|
|
return 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2019-11-11 13:21:33 +08:00
|
|
|
static int rpaphp_drc_info_add_slot(struct device_node *dn)
|
|
|
|
{
|
|
|
|
struct slot *slot;
|
|
|
|
struct property *info;
|
|
|
|
struct of_drc_info drc;
|
|
|
|
char drc_name[MAX_DRC_NAME_LEN];
|
|
|
|
const __be32 *cur;
|
|
|
|
u32 count;
|
|
|
|
int retval = 0;
|
|
|
|
|
|
|
|
info = of_find_property(dn, "ibm,drc-info", NULL);
|
|
|
|
if (!info)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
cur = of_prop_next_u32(info, NULL, &count);
|
|
|
|
if (cur)
|
|
|
|
cur++;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
of_read_drc_info_cell(&info, &cur, &drc);
|
|
|
|
if (!is_php_type(drc.drc_type))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
sprintf(drc_name, "%s%d", drc.drc_name_prefix, drc.drc_name_suffix_start);
|
|
|
|
|
|
|
|
slot = alloc_slot_struct(dn, drc.drc_index_start, drc_name, drc.drc_power_domain);
|
|
|
|
if (!slot)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
slot->type = simple_strtoul(drc.drc_type, NULL, 10);
|
|
|
|
retval = rpaphp_enable_slot(slot);
|
|
|
|
if (!retval)
|
|
|
|
retval = rpaphp_register_slot(slot);
|
|
|
|
|
|
|
|
if (retval)
|
|
|
|
dealloc_slot_struct(slot);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rpaphp_drc_add_slot(struct device_node *dn)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct slot *slot;
|
|
|
|
int retval = 0;
|
2005-07-25 23:17:03 +08:00
|
|
|
int i;
|
2019-11-11 13:21:35 +08:00
|
|
|
const __be32 *indexes, *names, *types, *power_domains;
|
2005-04-17 06:20:36 +08:00
|
|
|
char *name, *type;
|
|
|
|
|
2007-04-14 06:34:22 +08:00
|
|
|
/* If this is not a hotplug slot, return without doing anything. */
|
2007-04-14 06:34:07 +08:00
|
|
|
if (!is_php_dn(dn, &indexes, &names, &types, &power_domains))
|
|
|
|
return 0;
|
|
|
|
|
2017-07-19 05:43:21 +08:00
|
|
|
dbg("Entry %s: dn=%pOF\n", __func__, dn);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* register PCI devices */
|
2007-04-14 06:34:07 +08:00
|
|
|
name = (char *) &names[1];
|
|
|
|
type = (char *) &types[1];
|
2014-04-10 21:02:13 +08:00
|
|
|
for (i = 0; i < be32_to_cpu(indexes[0]); i++) {
|
|
|
|
int index;
|
2007-04-14 06:34:07 +08:00
|
|
|
|
2014-04-10 21:02:13 +08:00
|
|
|
index = be32_to_cpu(indexes[i + 1]);
|
|
|
|
slot = alloc_slot_struct(dn, index, name,
|
|
|
|
be32_to_cpu(power_domains[i + 1]));
|
2007-04-14 06:34:07 +08:00
|
|
|
if (!slot)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
slot->type = simple_strtoul(type, NULL, 10);
|
2013-11-15 02:28:18 +08:00
|
|
|
|
2007-04-14 06:34:07 +08:00
|
|
|
dbg("Found drc-index:0x%x drc-name:%s drc-type:%s\n",
|
2014-04-10 21:02:13 +08:00
|
|
|
index, name, type);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-04-14 06:34:20 +08:00
|
|
|
retval = rpaphp_enable_slot(slot);
|
2007-04-14 06:34:19 +08:00
|
|
|
if (!retval)
|
|
|
|
retval = rpaphp_register_slot(slot);
|
|
|
|
|
2007-04-14 06:34:09 +08:00
|
|
|
if (retval)
|
|
|
|
dealloc_slot_struct(slot);
|
|
|
|
|
2007-04-14 06:34:07 +08:00
|
|
|
name += strlen(name) + 1;
|
|
|
|
type += strlen(type) + 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2008-03-04 11:09:46 +08:00
|
|
|
dbg("%s - Exit: rc[%d]\n", __func__, retval);
|
2007-04-14 06:34:09 +08:00
|
|
|
|
|
|
|
/* XXX FIXME: reports a failure only if last entry in loop failed */
|
2005-04-17 06:20:36 +08:00
|
|
|
return retval;
|
|
|
|
}
|
2019-11-11 13:21:33 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* rpaphp_add_slot -- declare a hotplug slot to the hotplug subsystem.
|
|
|
|
* @dn: device node of slot
|
|
|
|
*
|
|
|
|
* This subroutine will register a hotpluggable slot with the
|
|
|
|
* PCI hotplug infrastructure. This routine is typically called
|
|
|
|
* during boot time, if the hotplug slots are present at boot time,
|
|
|
|
* or is called later, by the dlpar add code, if the slot is
|
|
|
|
* being dynamically added during runtime.
|
|
|
|
*
|
|
|
|
* If the device node points at an embedded (built-in) slot, this
|
|
|
|
* routine will just return without doing anything, since embedded
|
|
|
|
* slots cannot be hotplugged.
|
|
|
|
*
|
|
|
|
* To remove a slot, it suffices to call rpaphp_deregister_slot().
|
|
|
|
*/
|
|
|
|
int rpaphp_add_slot(struct device_node *dn)
|
|
|
|
{
|
2020-04-17 05:51:14 +08:00
|
|
|
if (!of_node_name_eq(dn, "pci"))
|
2019-11-11 13:21:33 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (of_find_property(dn, "ibm,drc-info", NULL))
|
|
|
|
return rpaphp_drc_info_add_slot(dn);
|
|
|
|
else
|
|
|
|
return rpaphp_drc_add_slot(dn);
|
|
|
|
}
|
2014-04-26 04:32:25 +08:00
|
|
|
EXPORT_SYMBOL_GPL(rpaphp_add_slot);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static void __exit cleanup_slots(void)
|
|
|
|
{
|
2015-12-12 21:36:57 +08:00
|
|
|
struct slot *slot, *next;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Unregister all of our slots with the pci_hotplug subsystem,
|
|
|
|
* and free up all memory that we had allocated.
|
|
|
|
*/
|
|
|
|
|
2015-12-12 21:36:57 +08:00
|
|
|
list_for_each_entry_safe(slot, next, &rpaphp_slot_head,
|
|
|
|
rpaphp_slot_list) {
|
2005-04-17 06:20:36 +08:00
|
|
|
list_del(&slot->rpaphp_slot_list);
|
2018-09-08 15:59:01 +08:00
|
|
|
pci_hp_deregister(&slot->hotplug_slot);
|
PCI: hotplug: Demidlayer registration with the core
When a hotplug driver calls pci_hp_register(), all steps necessary for
registration are carried out in one go, including creation of a kobject
and addition to sysfs. That's a problem for pciehp once it's converted
to enable/disable the slot exclusively from the IRQ thread: The thread
needs to be spawned after creation of the kobject (because it uses the
kobject's name), but before addition to sysfs (because it will handle
enable/disable requests submitted via sysfs).
pci_hp_deregister() does offer a ->release callback that's invoked
after deletion from sysfs and before destruction of the kobject. But
because pci_hp_register() doesn't offer a counterpart, hotplug drivers'
->probe and ->remove code becomes asymmetric, which is error prone
as recently discovered use-after-free bugs in pciehp's ->remove hook
have shown.
In a sense, this appears to be a case of the midlayer antipattern:
"The core thesis of the "midlayer mistake" is that midlayers are
bad and should not exist. That common functionality which it is
so tempting to put in a midlayer should instead be provided as
library routines which can [be] used, augmented, or ignored by
each bottom level driver independently. Thus every subsystem
that supports multiple implementations (or drivers) should
provide a very thin top layer which calls directly into the
bottom layer drivers, and a rich library of support code that
eases the implementation of those drivers. This library is
available to, but not forced upon, those drivers."
-- Neil Brown (2009), https://lwn.net/Articles/336262/
The presence of midlayer traits in the PCI hotplug core might be ascribed
to its age: When it was introduced in February 2002, the blessings of a
library approach might not have been well known:
https://git.kernel.org/tglx/history/c/a8a2069f432c
For comparison, the driver core does offer split functions for creating
a kobject (device_initialize()) and addition to sysfs (device_add()) as
an alternative to carrying out everything at once (device_register()).
This was introduced in October 2002:
https://git.kernel.org/tglx/history/c/8b290eb19962
The odd ->release callback in the PCI hotplug core was added in 2003:
https://git.kernel.org/tglx/history/c/69f8d663b595
Clearly, a library approach would not force every hotplug driver to
implement a ->release callback, but rather allow the driver to remove
the sysfs files, release its data structures and finally destroy the
kobject. Alternatively, a driver may choose to remove everything with
pci_hp_deregister(), then release its data structures.
To this end, offer drivers pci_hp_initialize() and pci_hp_add() as a
split-up version of pci_hp_register(). Likewise, offer pci_hp_del()
and pci_hp_destroy() as a split-up version of pci_hp_deregister().
Eliminate the ->release callback and move its code into each driver's
teardown routine.
Declare pci_hp_deregister() void, in keeping with the usual kernel
pattern that enablement can fail, but disablement cannot. It only
returned an error if the caller passed in a NULL pointer or a slot which
has never or is no longer registered or is sharing its name with another
slot. Those would be bugs, so WARN about them. Few hotplug drivers
actually checked the return value and those that did only printed a
useless error message to dmesg. Remove that.
For most drivers the conversion was straightforward since it doesn't
matter whether the code in the ->release callback is executed before or
after destruction of the kobject. But in the case of ibmphp, it was
unclear to me whether setting slot_cur->ctrl and slot_cur->bus_on to
NULL needs to happen before the kobject is destroyed, so I erred on
the side of caution and ensured that the order stays the same. Another
nontrivial case is pnv_php, I've found the list and kref logic difficult
to understand, however my impression was that it is safe to delete the
list element and drop the references until after the kobject is
destroyed.
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Acked-by: Andy Shevchenko <andy.shevchenko@gmail.com> # drivers/platform/x86
Cc: Rafael J. Wysocki <rjw@rjwysocki.net>
Cc: Len Brown <lenb@kernel.org>
Cc: Scott Murray <scott@spiteful.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Gavin Shan <gwshan@linux.vnet.ibm.com>
Cc: Sebastian Ott <sebott@linux.vnet.ibm.com>
Cc: Gerald Schaefer <gerald.schaefer@de.ibm.com>
Cc: Corentin Chary <corentin.chary@gmail.com>
Cc: Darren Hart <dvhart@infradead.org>
Cc: Andy Shevchenko <andy@infradead.org>
2018-07-20 06:27:43 +08:00
|
|
|
dealloc_slot_struct(slot);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __init rpaphp_init(void)
|
|
|
|
{
|
2014-06-04 23:42:26 +08:00
|
|
|
struct device_node *dn;
|
2005-07-25 23:16:42 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
info(DRIVER_DESC " version: " DRIVER_VERSION "\n");
|
2005-07-25 23:16:42 +08:00
|
|
|
|
2014-06-04 23:42:26 +08:00
|
|
|
for_each_node_by_name(dn, "pci")
|
2005-07-25 23:16:42 +08:00
|
|
|
rpaphp_add_slot(dn);
|
|
|
|
|
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit rpaphp_exit(void)
|
|
|
|
{
|
|
|
|
cleanup_slots();
|
|
|
|
}
|
|
|
|
|
2007-04-14 06:34:25 +08:00
|
|
|
static int enable_slot(struct hotplug_slot *hotplug_slot)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2018-09-08 15:59:01 +08:00
|
|
|
struct slot *slot = to_slot(hotplug_slot);
|
2006-01-13 08:28:22 +08:00
|
|
|
int state;
|
|
|
|
int retval;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-01-13 08:28:22 +08:00
|
|
|
if (slot->state == CONFIGURED)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
retval = rpaphp_get_sensor_state(slot, &state);
|
|
|
|
if (retval)
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
if (state == PRESENT) {
|
2020-03-06 15:39:03 +08:00
|
|
|
pseries_eeh_init_edev_recursive(PCI_DN(slot->dn));
|
2020-03-06 15:39:01 +08:00
|
|
|
|
2014-01-15 03:03:14 +08:00
|
|
|
pci_lock_rescan_remove();
|
2016-05-03 13:41:37 +08:00
|
|
|
pci_hp_add_devices(slot->bus);
|
2014-01-15 03:03:14 +08:00
|
|
|
pci_unlock_rescan_remove();
|
2006-01-13 08:28:22 +08:00
|
|
|
slot->state = CONFIGURED;
|
|
|
|
} else if (state == EMPTY) {
|
|
|
|
slot->state = EMPTY;
|
|
|
|
} else {
|
2008-03-04 11:09:46 +08:00
|
|
|
err("%s: slot[%s] is in invalid state\n", __func__, slot->name);
|
2006-01-13 08:28:22 +08:00
|
|
|
slot->state = NOT_VALID;
|
|
|
|
return -EINVAL;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2009-12-13 21:11:32 +08:00
|
|
|
|
|
|
|
slot->bus->max_bus_speed = get_max_bus_speed(slot);
|
2006-01-13 08:28:22 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-04-14 06:34:25 +08:00
|
|
|
static int disable_slot(struct hotplug_slot *hotplug_slot)
|
2006-01-13 08:28:22 +08:00
|
|
|
{
|
2018-09-08 15:59:01 +08:00
|
|
|
struct slot *slot = to_slot(hotplug_slot);
|
2006-01-13 08:26:27 +08:00
|
|
|
if (slot->state == NOT_CONFIGURED)
|
|
|
|
return -EINVAL;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2014-01-15 03:03:14 +08:00
|
|
|
pci_lock_rescan_remove();
|
2016-05-03 13:41:37 +08:00
|
|
|
pci_hp_remove_devices(slot->bus);
|
2014-01-15 03:03:14 +08:00
|
|
|
pci_unlock_rescan_remove();
|
2010-04-06 23:03:40 +08:00
|
|
|
vm_unmap_aliases();
|
|
|
|
|
2006-01-13 08:26:27 +08:00
|
|
|
slot->state = NOT_CONFIGURED;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-09-08 15:59:01 +08:00
|
|
|
const struct hotplug_slot_ops rpaphp_hotplug_slot_ops = {
|
2006-01-13 08:32:58 +08:00
|
|
|
.enable_slot = enable_slot,
|
|
|
|
.disable_slot = disable_slot,
|
|
|
|
.set_attention_status = set_attention_status,
|
|
|
|
.get_power_status = get_power_status,
|
|
|
|
.get_attention_status = get_attention_status,
|
|
|
|
.get_adapter_status = get_adapter_status,
|
|
|
|
};
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
module_init(rpaphp_init);
|
|
|
|
module_exit(rpaphp_exit);
|