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> 15ec249dd8SMichael Neuling #include <misc/cxl-base.h> 16ea0d856cSGavin Shan #include <asm/opal-api.h> 1780c49c7eSIan Munsie 18ebe22531SGavin Shan #define PCI_SLOT_ID_PREFIX 0x8000000000000000 19ebe22531SGavin Shan #define PCI_SLOT_ID(phb_id, bdfn) \ 20ebe22531SGavin Shan (PCI_SLOT_ID_PREFIX | ((uint64_t)(bdfn) << 16) | (phb_id)) 21ebe22531SGavin Shan 227e19bf32SGavin Shan extern int pnv_pci_get_slot_id(struct device_node *np, uint64_t *id); 23ea0d856cSGavin Shan extern int pnv_pci_get_device_tree(uint32_t phandle, void *buf, uint64_t len); 24ea0d856cSGavin Shan extern int pnv_pci_get_presence_state(uint64_t id, uint8_t *state); 25ea0d856cSGavin Shan extern int pnv_pci_get_power_state(uint64_t id, uint8_t *state); 26ea0d856cSGavin Shan extern int pnv_pci_set_power_state(uint64_t id, uint8_t state, 27ea0d856cSGavin Shan struct opal_msg *msg); 287e19bf32SGavin Shan 291212aa1cSRyan Grimm int pnv_phb_to_cxl_mode(struct pci_dev *dev, uint64_t mode); 3080c49c7eSIan Munsie int pnv_cxl_ioda_msi_setup(struct pci_dev *dev, unsigned int hwirq, 3180c49c7eSIan Munsie unsigned int virq); 3280c49c7eSIan Munsie int pnv_cxl_alloc_hwirqs(struct pci_dev *dev, int num); 3380c49c7eSIan Munsie void pnv_cxl_release_hwirqs(struct pci_dev *dev, int hwirq, int num); 3480c49c7eSIan Munsie int pnv_cxl_get_irq_count(struct pci_dev *dev); 356f963ec2SRyan Grimm struct device_node *pnv_pci_get_phb_node(struct pci_dev *dev); 3680c49c7eSIan Munsie 3780c49c7eSIan Munsie #ifdef CONFIG_CXL_BASE 3880c49c7eSIan Munsie int pnv_cxl_alloc_hwirq_ranges(struct cxl_irq_ranges *irqs, 3980c49c7eSIan Munsie struct pci_dev *dev, int num); 4080c49c7eSIan Munsie void pnv_cxl_release_hwirq_ranges(struct cxl_irq_ranges *irqs, 4180c49c7eSIan Munsie struct pci_dev *dev); 424361b034SIan Munsie 434361b034SIan Munsie /* Support for the cxl kernel api on the real PHB (instead of vPHB) */ 444361b034SIan Munsie int pnv_cxl_enable_phb_kernel_api(struct pci_controller *hose, bool enable); 454361b034SIan Munsie bool pnv_pci_on_cxl_phb(struct pci_dev *dev); 464361b034SIan Munsie struct cxl_afu *pnv_cxl_phb_to_afu(struct pci_controller *hose); 474361b034SIan Munsie void pnv_cxl_phb_set_peer_afu(struct pci_dev *dev, struct cxl_afu *afu); 484361b034SIan Munsie 4980c49c7eSIan Munsie #endif 5080c49c7eSIan Munsie 5189379f16SAndrew Donnellan struct pnv_php_slot { 5289379f16SAndrew Donnellan struct hotplug_slot slot; 5389379f16SAndrew Donnellan struct hotplug_slot_info slot_info; 5489379f16SAndrew Donnellan uint64_t id; 5589379f16SAndrew Donnellan char *name; 5689379f16SAndrew Donnellan int slot_no; 5789379f16SAndrew Donnellan struct kref kref; 5889379f16SAndrew Donnellan #define PNV_PHP_STATE_INITIALIZED 0 5989379f16SAndrew Donnellan #define PNV_PHP_STATE_REGISTERED 1 6089379f16SAndrew Donnellan #define PNV_PHP_STATE_POPULATED 2 6189379f16SAndrew Donnellan #define PNV_PHP_STATE_OFFLINE 3 6289379f16SAndrew Donnellan int state; 6389379f16SAndrew Donnellan struct device_node *dn; 6489379f16SAndrew Donnellan struct pci_dev *pdev; 6589379f16SAndrew Donnellan struct pci_bus *bus; 6689379f16SAndrew Donnellan bool power_state_check; 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