// SPDX-License-Identifier: GPL-2.0/* * Enable PCIe link L0s/L1 state and Clock Power Management * * Copyright (C) 2007 Intel * Copyright (C) Zhang Yanmin (yanmin.zhang@intel.com) * Copyright (C) Shaohua Li (shaohua.li@intel.com) */#include<linux/kernel.h>#include<linux/math.h>#include<linux/module.h>#include<linux/moduleparam.h>#include<linux/pci.h>#include<linux/pci_regs.h>#include<linux/errno.h>#include<linux/pm.h>#include<linux/init.h>#include<linux/slab.h>#include<linux/jiffies.h>#include<linux/delay.h>#include"../pci.h"#ifdef MODULE_PARAM_PREFIX#undef MODULE_PARAM_PREFIX#endif#define MODULE_PARAM_PREFIX "pcie_aspm."/* Note: those are not register definitions */#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */#define ASPM_STATE_L1 (4) /* L1 state */#define ASPM_STATE_L1_1 (8) /* ASPM L1.1 state */#define ASPM_STATE_L1_2 (0x10) /* ASPM L1.2 state */#define ASPM_STATE_L1_1_PCIPM (0x20) /* PCI PM L1.1 state */#define ASPM_STATE_L1_2_PCIPM (0x40) /* PCI PM L1.2 state */#define ASPM_STATE_L1_SS_PCIPM (ASPM_STATE_L1_1_PCIPM | ASPM_STATE_L1_2_PCIPM)#define ASPM_STATE_L1_2_MASK (ASPM_STATE_L1_2 | ASPM_STATE_L1_2_PCIPM)#define ASPM_STATE_L1SS (ASPM_STATE_L1_1 | ASPM_STATE_L1_1_PCIPM |\ ASPM_STATE_L1_2_MASK)#define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)#define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1 | \ ASPM_STATE_L1SS)structpcie_link_state{structpci_dev*pdev;/* Upstream component of the Link */structpci_dev*downstream;/* Downstream component, function 0 */structpcie_link_state*root;/* pointer to the root port link */structpcie_link_state*parent;/* pointer to the parent Link state */structlist_headsibling;/* node in link_list *//* ASPM state */u32aspm_support:7;/* Supported ASPM state */u32aspm_enabled:7;/* Enabled ASPM state */u32aspm_capable:7;/* Capable ASPM state with latency */u32aspm_default:7;/* Default ASPM state by BIOS */u32aspm_disable:7;/* Disabled ASPM state *//* Clock PM state */u32clkpm_capable:1;/* Clock PM capable? */u32clkpm_enabled:1;/* Current Clock PM state */u32clkpm_default:1;/* Default Clock PM state by BIOS */u32clkpm_disable:1;/* Clock PM disabled */};staticintaspm_disabled,aspm_force;staticboolaspm_support_enabled=true;staticDEFINE_MUTEX(aspm_lock);staticLIST_HEAD(link_list);#define POLICY_DEFAULT 0 /* BIOS default setting */#define POLICY_PERFORMANCE 1 /* high performance */#define POLICY_POWERSAVE 2 /* high power saving */#define POLICY_POWER_SUPERSAVE 3 /* possibly even more power saving */#ifdef CONFIG_PCIEASPM_PERFORMANCEstaticintaspm_policy=POLICY_PERFORMANCE;#elif defined CONFIG_PCIEASPM_POWERSAVEstaticintaspm_policy=POLICY_POWERSAVE;#elif defined CONFIG_PCIEASPM_POWER_SUPERSAVE