12874c5fdSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */ 280c49c7eSIan Munsie /* 380c49c7eSIan Munsie * Copyright 2014 IBM Corp. 480c49c7eSIan Munsie */ 580c49c7eSIan Munsie 680c49c7eSIan Munsie #ifndef _ASM_PNV_PCI_H 780c49c7eSIan Munsie #define _ASM_PNV_PCI_H 880c49c7eSIan Munsie 980c49c7eSIan Munsie #include <linux/pci.h> 1089379f16SAndrew Donnellan #include <linux/pci_hotplug.h> 114ee11c1aSSuresh Warrier #include <linux/irq.h> 12*e6f6390aSChristophe Leroy #include <linux/of.h> 13ec249dd8SMichael Neuling #include <misc/cxl-base.h> 14ea0d856cSGavin Shan #include <asm/opal-api.h> 1580c49c7eSIan Munsie 16066bcd78SGavin Shan #define PCI_SLOT_ID_PREFIX (1UL << 63) 17ebe22531SGavin Shan #define PCI_SLOT_ID(phb_id, bdfn) \ 18ebe22531SGavin Shan (PCI_SLOT_ID_PREFIX | ((uint64_t)(bdfn) << 16) | (phb_id)) 19bbb78904SFrederic Barrat #define PCI_PHB_SLOT_ID(phb_id) (phb_id) 20ebe22531SGavin Shan 217e19bf32SGavin Shan extern int pnv_pci_get_slot_id(struct device_node *np, uint64_t *id); 22ea0d856cSGavin Shan extern int pnv_pci_get_device_tree(uint32_t phandle, void *buf, uint64_t len); 23ea0d856cSGavin Shan extern int pnv_pci_get_presence_state(uint64_t id, uint8_t *state); 24ea0d856cSGavin Shan extern int pnv_pci_get_power_state(uint64_t id, uint8_t *state); 25ea0d856cSGavin Shan extern int pnv_pci_set_power_state(uint64_t id, uint8_t state, 26ea0d856cSGavin Shan struct opal_msg *msg); 277e19bf32SGavin Shan 28d6a90bb8SPhilippe Bergheaud extern int pnv_pci_set_tunnel_bar(struct pci_dev *dev, uint64_t addr, 29d6a90bb8SPhilippe Bergheaud int enable); 301212aa1cSRyan Grimm int pnv_phb_to_cxl_mode(struct pci_dev *dev, uint64_t mode); 3180c49c7eSIan Munsie int pnv_cxl_ioda_msi_setup(struct pci_dev *dev, unsigned int hwirq, 3280c49c7eSIan Munsie unsigned int virq); 3380c49c7eSIan Munsie int pnv_cxl_alloc_hwirqs(struct pci_dev *dev, int num); 3480c49c7eSIan Munsie void pnv_cxl_release_hwirqs(struct pci_dev *dev, int hwirq, int num); 3580c49c7eSIan Munsie int pnv_cxl_get_irq_count(struct pci_dev *dev); 366f963ec2SRyan Grimm struct device_node *pnv_pci_get_phb_node(struct pci_dev *dev); 37c325712bSCédric Le Goater int64_t pnv_opal_pci_msi_eoi(struct irq_data *d); 384ee11c1aSSuresh Warrier bool is_pnv_opal_msi(struct irq_chip *chip); 3980c49c7eSIan Munsie 4080c49c7eSIan Munsie #ifdef CONFIG_CXL_BASE 4180c49c7eSIan Munsie int pnv_cxl_alloc_hwirq_ranges(struct cxl_irq_ranges *irqs, 4280c49c7eSIan Munsie struct pci_dev *dev, int num); 4380c49c7eSIan Munsie void pnv_cxl_release_hwirq_ranges(struct cxl_irq_ranges *irqs, 4480c49c7eSIan Munsie struct pci_dev *dev); 4580c49c7eSIan Munsie #endif 4680c49c7eSIan Munsie 4789379f16SAndrew Donnellan struct pnv_php_slot { 4889379f16SAndrew Donnellan struct hotplug_slot slot; 4989379f16SAndrew Donnellan uint64_t id; 5089379f16SAndrew Donnellan char *name; 5189379f16SAndrew Donnellan int slot_no; 52454593e5SGavin Shan unsigned int flags; 53454593e5SGavin Shan #define PNV_PHP_FLAG_BROKEN_PDC 0x1 5489379f16SAndrew Donnellan struct kref kref; 5589379f16SAndrew Donnellan #define PNV_PHP_STATE_INITIALIZED 0 5689379f16SAndrew Donnellan #define PNV_PHP_STATE_REGISTERED 1 5789379f16SAndrew Donnellan #define PNV_PHP_STATE_POPULATED 2 5889379f16SAndrew Donnellan #define PNV_PHP_STATE_OFFLINE 3 5989379f16SAndrew Donnellan int state; 60360aebd8SGavin Shan int irq; 61360aebd8SGavin Shan struct workqueue_struct *wq; 6289379f16SAndrew Donnellan struct device_node *dn; 6389379f16SAndrew Donnellan struct pci_dev *pdev; 6489379f16SAndrew Donnellan struct pci_bus *bus; 6589379f16SAndrew Donnellan bool power_state_check; 66a7da2161SLukas Wunner u8 attention_state; 6789379f16SAndrew Donnellan void *fdt; 6889379f16SAndrew Donnellan void *dt; 6989379f16SAndrew Donnellan struct of_changeset ocs; 7089379f16SAndrew Donnellan struct pnv_php_slot *parent; 7189379f16SAndrew Donnellan struct list_head children; 7289379f16SAndrew Donnellan struct list_head link; 7389379f16SAndrew Donnellan }; 7489379f16SAndrew Donnellan extern struct pnv_php_slot *pnv_php_find_slot(struct device_node *dn); 7589379f16SAndrew Donnellan extern int pnv_php_set_slot_power_state(struct hotplug_slot *slot, 7689379f16SAndrew Donnellan uint8_t state); 7789379f16SAndrew Donnellan 7880c49c7eSIan Munsie #endif 79