2019-05-27 13:55:01 +07:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2014-10-08 15:54:57 +07:00
|
|
|
/*
|
|
|
|
* Copyright 2014 IBM Corp.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _ASM_PNV_PCI_H
|
|
|
|
#define _ASM_PNV_PCI_H
|
|
|
|
|
|
|
|
#include <linux/pci.h>
|
2016-07-14 04:17:12 +07:00
|
|
|
#include <linux/pci_hotplug.h>
|
2016-08-19 12:35:49 +07:00
|
|
|
#include <linux/irq.h>
|
2015-05-27 13:07:16 +07:00
|
|
|
#include <misc/cxl-base.h>
|
2016-05-20 13:41:41 +07:00
|
|
|
#include <asm/opal-api.h>
|
2014-10-08 15:54:57 +07:00
|
|
|
|
2016-08-02 11:10:31 +07:00
|
|
|
#define PCI_SLOT_ID_PREFIX (1UL << 63)
|
2016-05-20 13:41:38 +07:00
|
|
|
#define PCI_SLOT_ID(phb_id, bdfn) \
|
|
|
|
(PCI_SLOT_ID_PREFIX | ((uint64_t)(bdfn) << 16) | (phb_id))
|
|
|
|
|
2016-05-20 13:41:40 +07:00
|
|
|
extern int pnv_pci_get_slot_id(struct device_node *np, uint64_t *id);
|
2016-05-20 13:41:41 +07:00
|
|
|
extern int pnv_pci_get_device_tree(uint32_t phandle, void *buf, uint64_t len);
|
|
|
|
extern int pnv_pci_get_presence_state(uint64_t id, uint8_t *state);
|
|
|
|
extern int pnv_pci_get_power_state(uint64_t id, uint8_t *state);
|
|
|
|
extern int pnv_pci_set_power_state(uint64_t id, uint8_t state,
|
|
|
|
struct opal_msg *msg);
|
2016-05-20 13:41:40 +07:00
|
|
|
|
2018-03-02 16:56:11 +07:00
|
|
|
extern int pnv_pci_set_tunnel_bar(struct pci_dev *dev, uint64_t addr,
|
|
|
|
int enable);
|
2015-01-20 00:52:50 +07:00
|
|
|
int pnv_phb_to_cxl_mode(struct pci_dev *dev, uint64_t mode);
|
2014-10-08 15:54:57 +07:00
|
|
|
int pnv_cxl_ioda_msi_setup(struct pci_dev *dev, unsigned int hwirq,
|
|
|
|
unsigned int virq);
|
|
|
|
int pnv_cxl_alloc_hwirqs(struct pci_dev *dev, int num);
|
|
|
|
void pnv_cxl_release_hwirqs(struct pci_dev *dev, int hwirq, int num);
|
|
|
|
int pnv_cxl_get_irq_count(struct pci_dev *dev);
|
2015-01-29 09:16:04 +07:00
|
|
|
struct device_node *pnv_pci_get_phb_node(struct pci_dev *dev);
|
2016-08-19 12:35:49 +07:00
|
|
|
int64_t pnv_opal_pci_msi_eoi(struct irq_chip *chip, unsigned int hw_irq);
|
|
|
|
bool is_pnv_opal_msi(struct irq_chip *chip);
|
2014-10-08 15:54:57 +07:00
|
|
|
|
|
|
|
#ifdef CONFIG_CXL_BASE
|
|
|
|
int pnv_cxl_alloc_hwirq_ranges(struct cxl_irq_ranges *irqs,
|
|
|
|
struct pci_dev *dev, int num);
|
|
|
|
void pnv_cxl_release_hwirq_ranges(struct cxl_irq_ranges *irqs,
|
|
|
|
struct pci_dev *dev);
|
|
|
|
#endif
|
|
|
|
|
2016-07-14 04:17:12 +07:00
|
|
|
struct pnv_php_slot {
|
|
|
|
struct hotplug_slot slot;
|
|
|
|
uint64_t id;
|
|
|
|
char *name;
|
|
|
|
int slot_no;
|
2017-01-11 07:50:08 +07:00
|
|
|
unsigned int flags;
|
|
|
|
#define PNV_PHP_FLAG_BROKEN_PDC 0x1
|
2016-07-14 04:17:12 +07:00
|
|
|
struct kref kref;
|
|
|
|
#define PNV_PHP_STATE_INITIALIZED 0
|
|
|
|
#define PNV_PHP_STATE_REGISTERED 1
|
|
|
|
#define PNV_PHP_STATE_POPULATED 2
|
|
|
|
#define PNV_PHP_STATE_OFFLINE 3
|
|
|
|
int state;
|
2016-09-28 11:34:58 +07:00
|
|
|
int irq;
|
|
|
|
struct workqueue_struct *wq;
|
2016-07-14 04:17:12 +07:00
|
|
|
struct device_node *dn;
|
|
|
|
struct pci_dev *pdev;
|
|
|
|
struct pci_bus *bus;
|
|
|
|
bool power_state_check;
|
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 14:59:01 +07:00
|
|
|
u8 attention_state;
|
2016-07-14 04:17:12 +07:00
|
|
|
void *fdt;
|
|
|
|
void *dt;
|
|
|
|
struct of_changeset ocs;
|
|
|
|
struct pnv_php_slot *parent;
|
|
|
|
struct list_head children;
|
|
|
|
struct list_head link;
|
|
|
|
};
|
|
|
|
extern struct pnv_php_slot *pnv_php_find_slot(struct device_node *dn);
|
|
|
|
extern int pnv_php_set_slot_power_state(struct hotplug_slot *slot,
|
|
|
|
uint8_t state);
|
|
|
|
|
2014-10-08 15:54:57 +07:00
|
|
|
#endif
|