18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright 2014 IBM Corp.
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#ifndef _ASM_PNV_PCI_H
78c2ecf20Sopenharmony_ci#define _ASM_PNV_PCI_H
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#include <linux/pci.h>
108c2ecf20Sopenharmony_ci#include <linux/pci_hotplug.h>
118c2ecf20Sopenharmony_ci#include <linux/irq.h>
128c2ecf20Sopenharmony_ci#include <misc/cxl-base.h>
138c2ecf20Sopenharmony_ci#include <asm/opal-api.h>
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#define PCI_SLOT_ID_PREFIX	(1UL << 63)
168c2ecf20Sopenharmony_ci#define PCI_SLOT_ID(phb_id, bdfn)	\
178c2ecf20Sopenharmony_ci	(PCI_SLOT_ID_PREFIX | ((uint64_t)(bdfn) << 16) | (phb_id))
188c2ecf20Sopenharmony_ci#define PCI_PHB_SLOT_ID(phb_id)		(phb_id)
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ciextern int pnv_pci_get_slot_id(struct device_node *np, uint64_t *id);
218c2ecf20Sopenharmony_ciextern int pnv_pci_get_device_tree(uint32_t phandle, void *buf, uint64_t len);
228c2ecf20Sopenharmony_ciextern int pnv_pci_get_presence_state(uint64_t id, uint8_t *state);
238c2ecf20Sopenharmony_ciextern int pnv_pci_get_power_state(uint64_t id, uint8_t *state);
248c2ecf20Sopenharmony_ciextern int pnv_pci_set_power_state(uint64_t id, uint8_t state,
258c2ecf20Sopenharmony_ci				   struct opal_msg *msg);
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ciextern int pnv_pci_set_tunnel_bar(struct pci_dev *dev, uint64_t addr,
288c2ecf20Sopenharmony_ci				  int enable);
298c2ecf20Sopenharmony_ciint pnv_phb_to_cxl_mode(struct pci_dev *dev, uint64_t mode);
308c2ecf20Sopenharmony_ciint pnv_cxl_ioda_msi_setup(struct pci_dev *dev, unsigned int hwirq,
318c2ecf20Sopenharmony_ci			   unsigned int virq);
328c2ecf20Sopenharmony_ciint pnv_cxl_alloc_hwirqs(struct pci_dev *dev, int num);
338c2ecf20Sopenharmony_civoid pnv_cxl_release_hwirqs(struct pci_dev *dev, int hwirq, int num);
348c2ecf20Sopenharmony_ciint pnv_cxl_get_irq_count(struct pci_dev *dev);
358c2ecf20Sopenharmony_cistruct device_node *pnv_pci_get_phb_node(struct pci_dev *dev);
368c2ecf20Sopenharmony_ciint64_t pnv_opal_pci_msi_eoi(struct irq_chip *chip, unsigned int hw_irq);
378c2ecf20Sopenharmony_cibool is_pnv_opal_msi(struct irq_chip *chip);
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci#ifdef CONFIG_CXL_BASE
408c2ecf20Sopenharmony_ciint pnv_cxl_alloc_hwirq_ranges(struct cxl_irq_ranges *irqs,
418c2ecf20Sopenharmony_ci			       struct pci_dev *dev, int num);
428c2ecf20Sopenharmony_civoid pnv_cxl_release_hwirq_ranges(struct cxl_irq_ranges *irqs,
438c2ecf20Sopenharmony_ci				  struct pci_dev *dev);
448c2ecf20Sopenharmony_ci#endif
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_cistruct pnv_php_slot {
478c2ecf20Sopenharmony_ci	struct hotplug_slot		slot;
488c2ecf20Sopenharmony_ci	uint64_t			id;
498c2ecf20Sopenharmony_ci	char				*name;
508c2ecf20Sopenharmony_ci	int				slot_no;
518c2ecf20Sopenharmony_ci	unsigned int			flags;
528c2ecf20Sopenharmony_ci#define PNV_PHP_FLAG_BROKEN_PDC		0x1
538c2ecf20Sopenharmony_ci	struct kref			kref;
548c2ecf20Sopenharmony_ci#define PNV_PHP_STATE_INITIALIZED	0
558c2ecf20Sopenharmony_ci#define PNV_PHP_STATE_REGISTERED	1
568c2ecf20Sopenharmony_ci#define PNV_PHP_STATE_POPULATED		2
578c2ecf20Sopenharmony_ci#define PNV_PHP_STATE_OFFLINE		3
588c2ecf20Sopenharmony_ci	int				state;
598c2ecf20Sopenharmony_ci	int				irq;
608c2ecf20Sopenharmony_ci	struct workqueue_struct		*wq;
618c2ecf20Sopenharmony_ci	struct device_node		*dn;
628c2ecf20Sopenharmony_ci	struct pci_dev			*pdev;
638c2ecf20Sopenharmony_ci	struct pci_bus			*bus;
648c2ecf20Sopenharmony_ci	bool				power_state_check;
658c2ecf20Sopenharmony_ci	u8				attention_state;
668c2ecf20Sopenharmony_ci	void				*fdt;
678c2ecf20Sopenharmony_ci	void				*dt;
688c2ecf20Sopenharmony_ci	struct of_changeset		ocs;
698c2ecf20Sopenharmony_ci	struct pnv_php_slot		*parent;
708c2ecf20Sopenharmony_ci	struct list_head		children;
718c2ecf20Sopenharmony_ci	struct list_head		link;
728c2ecf20Sopenharmony_ci};
738c2ecf20Sopenharmony_ciextern struct pnv_php_slot *pnv_php_find_slot(struct device_node *dn);
748c2ecf20Sopenharmony_ciextern int pnv_php_set_slot_power_state(struct hotplug_slot *slot,
758c2ecf20Sopenharmony_ci					uint8_t state);
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci#endif
78