180c49c7eSIan Munsie /* 280c49c7eSIan Munsie * Copyright 2014 IBM Corp. 380c49c7eSIan Munsie * 480c49c7eSIan Munsie * This program is free software; you can redistribute it and/or 580c49c7eSIan Munsie * modify it under the terms of the GNU General Public License 680c49c7eSIan Munsie * as published by the Free Software Foundation; either version 780c49c7eSIan Munsie * 2 of the License, or (at your option) any later version. 880c49c7eSIan Munsie */ 980c49c7eSIan Munsie 1080c49c7eSIan Munsie #ifndef _ASM_PNV_PCI_H 1180c49c7eSIan Munsie #define _ASM_PNV_PCI_H 1280c49c7eSIan Munsie 1380c49c7eSIan Munsie #include <linux/pci.h> 1489379f16SAndrew Donnellan #include <linux/pci_hotplug.h> 154ee11c1aSSuresh Warrier #include <linux/irq.h> 16ec249dd8SMichael Neuling #include <misc/cxl-base.h> 17ea0d856cSGavin Shan #include <asm/opal-api.h> 1880c49c7eSIan Munsie 19ebe22531SGavin Shan #define PCI_SLOT_ID_PREFIX 0x8000000000000000 20ebe22531SGavin Shan #define PCI_SLOT_ID(phb_id, bdfn) \ 21ebe22531SGavin Shan (PCI_SLOT_ID_PREFIX | ((uint64_t)(bdfn) << 16) | (phb_id)) 22ebe22531SGavin Shan 237e19bf32SGavin Shan extern int pnv_pci_get_slot_id(struct device_node *np, uint64_t *id); 24ea0d856cSGavin Shan extern int pnv_pci_get_device_tree(uint32_t phandle, void *buf, uint64_t len); 25ea0d856cSGavin Shan extern int pnv_pci_get_presence_state(uint64_t id, uint8_t *state); 26ea0d856cSGavin Shan extern int pnv_pci_get_power_state(uint64_t id, uint8_t *state); 27ea0d856cSGavin Shan extern int pnv_pci_set_power_state(uint64_t id, uint8_t state, 28ea0d856cSGavin Shan struct opal_msg *msg); 297e19bf32SGavin Shan 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); 374ee11c1aSSuresh Warrier int64_t pnv_opal_pci_msi_eoi(struct irq_chip *chip, unsigned int hw_irq); 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); 454361b034SIan Munsie 464361b034SIan Munsie /* Support for the cxl kernel api on the real PHB (instead of vPHB) */ 474361b034SIan Munsie int pnv_cxl_enable_phb_kernel_api(struct pci_controller *hose, bool enable); 484361b034SIan Munsie bool pnv_pci_on_cxl_phb(struct pci_dev *dev); 494361b034SIan Munsie struct cxl_afu *pnv_cxl_phb_to_afu(struct pci_controller *hose); 504361b034SIan Munsie void pnv_cxl_phb_set_peer_afu(struct pci_dev *dev, struct cxl_afu *afu); 514361b034SIan Munsie 5280c49c7eSIan Munsie #endif 5380c49c7eSIan Munsie 5489379f16SAndrew Donnellan struct pnv_php_slot { 5589379f16SAndrew Donnellan struct hotplug_slot slot; 5689379f16SAndrew Donnellan struct hotplug_slot_info slot_info; 5789379f16SAndrew Donnellan uint64_t id; 5889379f16SAndrew Donnellan char *name; 5989379f16SAndrew Donnellan int slot_no; 6089379f16SAndrew Donnellan struct kref kref; 6189379f16SAndrew Donnellan #define PNV_PHP_STATE_INITIALIZED 0 6289379f16SAndrew Donnellan #define PNV_PHP_STATE_REGISTERED 1 6389379f16SAndrew Donnellan #define PNV_PHP_STATE_POPULATED 2 6489379f16SAndrew Donnellan #define PNV_PHP_STATE_OFFLINE 3 6589379f16SAndrew Donnellan int state; 6689379f16SAndrew Donnellan struct device_node *dn; 6789379f16SAndrew Donnellan struct pci_dev *pdev; 6889379f16SAndrew Donnellan struct pci_bus *bus; 6989379f16SAndrew Donnellan bool power_state_check; 7089379f16SAndrew Donnellan void *fdt; 7189379f16SAndrew Donnellan void *dt; 7289379f16SAndrew Donnellan struct of_changeset ocs; 7389379f16SAndrew Donnellan struct pnv_php_slot *parent; 7489379f16SAndrew Donnellan struct list_head children; 7589379f16SAndrew Donnellan struct list_head link; 7689379f16SAndrew Donnellan }; 7789379f16SAndrew Donnellan extern struct pnv_php_slot *pnv_php_find_slot(struct device_node *dn); 7889379f16SAndrew Donnellan extern int pnv_php_set_slot_power_state(struct hotplug_slot *slot, 7989379f16SAndrew Donnellan uint8_t state); 8089379f16SAndrew Donnellan 8180c49c7eSIan Munsie #endif 82