1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds * Purpose: PCI Express Port Bus Driver's Internal Data Structures
41da177e4SLinus Torvalds *
51da177e4SLinus Torvalds * Copyright (C) 2004 Intel
61da177e4SLinus Torvalds * Copyright (C) Tom Long Nguyen (tom.l.nguyen@intel.com)
71da177e4SLinus Torvalds */
81da177e4SLinus Torvalds
91da177e4SLinus Torvalds #ifndef _PORTDRV_H_
101da177e4SLinus Torvalds #define _PORTDRV_H_
111da177e4SLinus Torvalds
123ec6a8d0SAndrew Morton #include <linux/compiler.h>
133ec6a8d0SAndrew Morton
14ef794260SBjorn Helgaas /* Service Type */
15ef794260SBjorn Helgaas #define PCIE_PORT_SERVICE_PME_SHIFT 0 /* Power Management Event */
16ef794260SBjorn Helgaas #define PCIE_PORT_SERVICE_PME (1 << PCIE_PORT_SERVICE_PME_SHIFT)
17ef794260SBjorn Helgaas #define PCIE_PORT_SERVICE_AER_SHIFT 1 /* Advanced Error Reporting */
18ef794260SBjorn Helgaas #define PCIE_PORT_SERVICE_AER (1 << PCIE_PORT_SERVICE_AER_SHIFT)
19ef794260SBjorn Helgaas #define PCIE_PORT_SERVICE_HP_SHIFT 2 /* Native Hotplug */
20ef794260SBjorn Helgaas #define PCIE_PORT_SERVICE_HP (1 << PCIE_PORT_SERVICE_HP_SHIFT)
21168f3ae5SBjorn Helgaas #define PCIE_PORT_SERVICE_DPC_SHIFT 3 /* Downstream Port Containment */
22ef794260SBjorn Helgaas #define PCIE_PORT_SERVICE_DPC (1 << PCIE_PORT_SERVICE_DPC_SHIFT)
23e8303bb7SAlexandru Gagniuc #define PCIE_PORT_SERVICE_BWNOTIF_SHIFT 4 /* Bandwidth notification */
24e8303bb7SAlexandru Gagniuc #define PCIE_PORT_SERVICE_BWNOTIF (1 << PCIE_PORT_SERVICE_BWNOTIF_SHIFT)
25ef794260SBjorn Helgaas
26e8303bb7SAlexandru Gagniuc #define PCIE_PORT_DEVICE_MAXSERVICES 5
27ef794260SBjorn Helgaas
2835a0b237SOlof Johansson extern bool pcie_ports_dpc_native;
2935a0b237SOlof Johansson
30c29de841SKeith Busch #ifdef CONFIG_PCIEAER
31c29de841SKeith Busch int pcie_aer_init(void);
32c29de841SKeith Busch #else
pcie_aer_init(void)33c29de841SKeith Busch static inline int pcie_aer_init(void) { return 0; }
34c29de841SKeith Busch #endif
35c29de841SKeith Busch
36c29de841SKeith Busch #ifdef CONFIG_HOTPLUG_PCI_PCIE
37c29de841SKeith Busch int pcie_hp_init(void);
38c29de841SKeith Busch #else
pcie_hp_init(void)39c29de841SKeith Busch static inline int pcie_hp_init(void) { return 0; }
40c29de841SKeith Busch #endif
41c29de841SKeith Busch
42c29de841SKeith Busch #ifdef CONFIG_PCIE_PME
43c29de841SKeith Busch int pcie_pme_init(void);
44c29de841SKeith Busch #else
pcie_pme_init(void)45c29de841SKeith Busch static inline int pcie_pme_init(void) { return 0; }
46c29de841SKeith Busch #endif
47c29de841SKeith Busch
48c29de841SKeith Busch #ifdef CONFIG_PCIE_DPC
49c29de841SKeith Busch int pcie_dpc_init(void);
50c29de841SKeith Busch #else
pcie_dpc_init(void)51c29de841SKeith Busch static inline int pcie_dpc_init(void) { return 0; }
52c29de841SKeith Busch #endif
53c29de841SKeith Busch
54ef794260SBjorn Helgaas /* Port Type */
55ef794260SBjorn Helgaas #define PCIE_ANY_PORT (~0)
56ef794260SBjorn Helgaas
57ef794260SBjorn Helgaas struct pcie_device {
58ef794260SBjorn Helgaas int irq; /* Service IRQ/MSI/MSI-X Vector */
59ef794260SBjorn Helgaas struct pci_dev *port; /* Root/Upstream/Downstream Port */
60ef794260SBjorn Helgaas u32 service; /* Port service this device represents */
61ef794260SBjorn Helgaas void *priv_data; /* Service Private Data */
62ef794260SBjorn Helgaas struct device device; /* Generic Device Interface */
63ef794260SBjorn Helgaas };
64ef794260SBjorn Helgaas #define to_pcie_device(d) container_of(d, struct pcie_device, device)
65ef794260SBjorn Helgaas
set_service_data(struct pcie_device * dev,void * data)66ef794260SBjorn Helgaas static inline void set_service_data(struct pcie_device *dev, void *data)
67ef794260SBjorn Helgaas {
68ef794260SBjorn Helgaas dev->priv_data = data;
69ef794260SBjorn Helgaas }
70ef794260SBjorn Helgaas
get_service_data(struct pcie_device * dev)71ef794260SBjorn Helgaas static inline void *get_service_data(struct pcie_device *dev)
72ef794260SBjorn Helgaas {
73ef794260SBjorn Helgaas return dev->priv_data;
74ef794260SBjorn Helgaas }
75ef794260SBjorn Helgaas
76ef794260SBjorn Helgaas struct pcie_port_service_driver {
77ef794260SBjorn Helgaas const char *name;
78ef794260SBjorn Helgaas int (*probe)(struct pcie_device *dev);
79ef794260SBjorn Helgaas void (*remove)(struct pcie_device *dev);
80ef794260SBjorn Helgaas int (*suspend)(struct pcie_device *dev);
8179037824SLukas Wunner int (*resume_noirq)(struct pcie_device *dev);
82ef794260SBjorn Helgaas int (*resume)(struct pcie_device *dev);
8394c7993fSMika Westerberg int (*runtime_suspend)(struct pcie_device *dev);
8494c7993fSMika Westerberg int (*runtime_resume)(struct pcie_device *dev);
85ef794260SBjorn Helgaas
86ea401499SLukas Wunner int (*slot_reset)(struct pcie_device *dev);
87ea401499SLukas Wunner
88ef794260SBjorn Helgaas int port_type; /* Type of the port this driver can handle */
89ef794260SBjorn Helgaas u32 service; /* Port service this device represents */
90ef794260SBjorn Helgaas
91ef794260SBjorn Helgaas struct device_driver driver;
92ef794260SBjorn Helgaas };
93ef794260SBjorn Helgaas #define to_service_driver(d) \
94ef794260SBjorn Helgaas container_of(d, struct pcie_port_service_driver, driver)
95ef794260SBjorn Helgaas
96ef794260SBjorn Helgaas int pcie_port_service_register(struct pcie_port_service_driver *new);
97ef794260SBjorn Helgaas void pcie_port_service_unregister(struct pcie_port_service_driver *new);
98ef794260SBjorn Helgaas
99*7adf6ac8SRicardo B. Marliere extern const struct bus_type pcie_port_bus_type;
1001da177e4SLinus Torvalds
10128eb5f27SRafael J. Wysocki struct pci_dev;
10228eb5f27SRafael J. Wysocki
103c39fae14SRafael J. Wysocki #ifdef CONFIG_PCIE_PME
104c39fae14SRafael J. Wysocki extern bool pcie_pme_msi_disabled;
105c39fae14SRafael J. Wysocki
pcie_pme_disable_msi(void)106c39fae14SRafael J. Wysocki static inline void pcie_pme_disable_msi(void)
107c39fae14SRafael J. Wysocki {
108c39fae14SRafael J. Wysocki pcie_pme_msi_disabled = true;
109c39fae14SRafael J. Wysocki }
110c39fae14SRafael J. Wysocki
pcie_pme_no_msi(void)111c39fae14SRafael J. Wysocki static inline bool pcie_pme_no_msi(void)
112c39fae14SRafael J. Wysocki {
113c39fae14SRafael J. Wysocki return pcie_pme_msi_disabled;
114c39fae14SRafael J. Wysocki }
11528eb5f27SRafael J. Wysocki
116f39d5b72SBjorn Helgaas void pcie_pme_interrupt_enable(struct pci_dev *dev, bool enable);
117c39fae14SRafael J. Wysocki #else /* !CONFIG_PCIE_PME */
pcie_pme_disable_msi(void)118c39fae14SRafael J. Wysocki static inline void pcie_pme_disable_msi(void) {}
pcie_pme_no_msi(void)119c39fae14SRafael J. Wysocki static inline bool pcie_pme_no_msi(void) { return false; }
pcie_pme_interrupt_enable(struct pci_dev * dev,bool en)12028eb5f27SRafael J. Wysocki static inline void pcie_pme_interrupt_enable(struct pci_dev *dev, bool en) {}
121c39fae14SRafael J. Wysocki #endif /* !CONFIG_PCIE_PME */
122c39fae14SRafael J. Wysocki
123e76d596aSOza Pawandeep struct device *pcie_port_find_device(struct pci_dev *dev, u32 service);
1241da177e4SLinus Torvalds #endif /* _PORTDRV_H_ */
125