git: 4cb3cb2de206 - main - LinuxKPI: Add pci_power querying for drm-kmod

From: Emmanuel Vadot <manu_at_FreeBSD.org>
Date: Thu, 06 Oct 2022 08:16:43 UTC
The branch main has been updated by manu:

URL: https://cgit.FreeBSD.org/src/commit/?id=4cb3cb2de2065bccbab65b0139c1be65f1da3fdf

commit 4cb3cb2de2065bccbab65b0139c1be65f1da3fdf
Author:     Jake Freeland <jfree@FreeBSD.org>
AuthorDate: 2022-10-06 08:15:41 +0000
Commit:     Emmanuel Vadot <manu@FreeBSD.org>
CommitDate: 2022-10-06 08:15:41 +0000

    LinuxKPI: Add pci_power querying for drm-kmod
    
    Adds a few struct members and a function to get i915_runtime_pm_status()
    to compile in drm-kmod.
    
    Differential Revision:  https://reviews.freebsd.org/D36749
    Sponsored by:   Google, Inc. (GSoC 2022)
---
 sys/compat/linuxkpi/common/include/linux/device.h |  2 ++
 sys/compat/linuxkpi/common/include/linux/pci.h    | 14 ++++++++++++++
 sys/compat/linuxkpi/common/include/linux/pm.h     |  6 ++++++
 sys/compat/linuxkpi/common/src/linux_pci.c        |  4 ++++
 4 files changed, 26 insertions(+)

diff --git a/sys/compat/linuxkpi/common/include/linux/device.h b/sys/compat/linuxkpi/common/include/linux/device.h
index 32195ad5b0a6..f3e2c4697562 100644
--- a/sys/compat/linuxkpi/common/include/linux/device.h
+++ b/sys/compat/linuxkpi/common/include/linux/device.h
@@ -127,6 +127,8 @@ struct device {
 
 	spinlock_t	devres_lock;
 	struct list_head devres_head;
+
+	struct dev_pm_info	power;
 };
 
 extern struct device linux_root_device;
diff --git a/sys/compat/linuxkpi/common/include/linux/pci.h b/sys/compat/linuxkpi/common/include/linux/pci.h
index 34076e0ff1d5..775bac72a145 100644
--- a/sys/compat/linuxkpi/common/include/linux/pci.h
+++ b/sys/compat/linuxkpi/common/include/linux/pci.h
@@ -202,6 +202,8 @@ typedef int pci_power_t;
 
 #define PCI_POWER_ERROR	PCI_POWERSTATE_UNKNOWN
 
+extern const char *pci_power_names[6];
+
 #define	PCI_ERR_ROOT_COMMAND		PCIR_AER_ROOTERR_CMD
 #define	PCI_ERR_ROOT_ERR_SRC		PCIR_AER_COR_SOURCE_ID
 
@@ -288,6 +290,7 @@ struct pci_dev {
 	struct pci_driver	*pdrv;
 	struct pci_bus		*bus;
 	struct pci_dev		*root;
+	pci_power_t		current_state;
 	uint16_t		device;
 	uint16_t		vendor;
 	uint16_t		subsystem_vendor;
@@ -1576,6 +1579,17 @@ pci_ignore_hotplug(struct pci_dev *pdev)
 {
 }
 
+static inline const char *
+pci_power_name(pci_power_t state)
+{
+	int pstate = state + 1;
+
+	if (pstate >= 0 && pstate < nitems(pci_power_names))
+		return (pci_power_names[pstate]);
+	else
+		return (pci_power_names[0]);
+}
+
 static inline int
 pcie_get_readrq(struct pci_dev *dev)
 {
diff --git a/sys/compat/linuxkpi/common/include/linux/pm.h b/sys/compat/linuxkpi/common/include/linux/pm.h
index d67cebb9764a..d054a95f17a3 100644
--- a/sys/compat/linuxkpi/common/include/linux/pm.h
+++ b/sys/compat/linuxkpi/common/include/linux/pm.h
@@ -33,6 +33,8 @@
 #ifndef	_LINUXKPI_LINUX_PM_H
 #define	_LINUXKPI_LINUX_PM_H
 
+#include <asm/atomic.h>
+
 /* Needed but breaks linux_usb.c */
 /* #include <linux/completion.h> */
 /* #include <linux/wait.h> */
@@ -44,6 +46,10 @@ typedef struct pm_message {
 struct dev_pm_domain {
 };
 
+struct dev_pm_info {
+	atomic_t usage_count;
+};
+
 #define	PM_EVENT_FREEZE		0x0001
 #define	PM_EVENT_SUSPEND	0x0002
 
diff --git a/sys/compat/linuxkpi/common/src/linux_pci.c b/sys/compat/linuxkpi/common/src/linux_pci.c
index aaa6d646f04d..aab4bfb6650d 100644
--- a/sys/compat/linuxkpi/common/src/linux_pci.c
+++ b/sys/compat/linuxkpi/common/src/linux_pci.c
@@ -117,6 +117,10 @@ static device_method_t pci_methods[] = {
 	DEVMETHOD_END
 };
 
+const char *pci_power_names[] = {
+	"UNKNOWN", "D0", "D1", "D2", "D3hot", "D3cold"
+};
+
 struct linux_dma_priv {
 	uint64_t	dma_mask;
 	bus_dma_tag_t	dmat;