Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 1 | /* |
| 2 | * File: drivers/pci/pcie/aspm.c |
| 3 | * Enabling PCIE link L0s/L1 state and Clock Power Management |
| 4 | * |
| 5 | * Copyright (C) 2007 Intel |
| 6 | * Copyright (C) Zhang Yanmin (yanmin.zhang@intel.com) |
| 7 | * Copyright (C) Shaohua Li (shaohua.li@intel.com) |
| 8 | */ |
| 9 | |
| 10 | #include <linux/kernel.h> |
| 11 | #include <linux/module.h> |
| 12 | #include <linux/moduleparam.h> |
| 13 | #include <linux/pci.h> |
| 14 | #include <linux/pci_regs.h> |
| 15 | #include <linux/errno.h> |
| 16 | #include <linux/pm.h> |
| 17 | #include <linux/init.h> |
| 18 | #include <linux/slab.h> |
Thomas Renninger | 2a42d9d | 2008-12-09 13:05:09 +0100 | [diff] [blame] | 19 | #include <linux/jiffies.h> |
Andrew Patterson | 987a4c7 | 2009-01-05 16:21:04 -0700 | [diff] [blame] | 20 | #include <linux/delay.h> |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 21 | #include <linux/pci-aspm.h> |
| 22 | #include "../pci.h" |
| 23 | |
| 24 | #ifdef MODULE_PARAM_PREFIX |
| 25 | #undef MODULE_PARAM_PREFIX |
| 26 | #endif |
| 27 | #define MODULE_PARAM_PREFIX "pcie_aspm." |
| 28 | |
Kenji Kaneshige | b6c2e54 | 2009-05-13 12:14:58 +0900 | [diff] [blame] | 29 | struct aspm_latency { |
| 30 | u32 l0s; /* L0s latency (nsec) */ |
| 31 | u32 l1; /* L1 latency (nsec) */ |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 32 | }; |
| 33 | |
| 34 | struct pcie_link_state { |
Kenji Kaneshige | 5cde89d | 2009-05-13 12:17:04 +0900 | [diff] [blame] | 35 | struct pci_dev *pdev; /* Upstream component of the Link */ |
Kenji Kaneshige | 5c92ffb | 2009-05-13 12:23:57 +0900 | [diff] [blame] | 36 | struct pcie_link_state *root; /* pointer to the root port link */ |
Kenji Kaneshige | 5cde89d | 2009-05-13 12:17:04 +0900 | [diff] [blame] | 37 | struct pcie_link_state *parent; /* pointer to the parent Link state */ |
| 38 | struct list_head sibling; /* node in link_list */ |
| 39 | struct list_head children; /* list of child link states */ |
| 40 | struct list_head link; /* node in parent's children list */ |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 41 | |
| 42 | /* ASPM state */ |
Kenji Kaneshige | 80bfdbe | 2009-05-13 12:12:43 +0900 | [diff] [blame] | 43 | u32 aspm_support:2; /* Supported ASPM state */ |
| 44 | u32 aspm_enabled:2; /* Enabled ASPM state */ |
Kenji Kaneshige | 07d9276 | 2009-08-19 11:00:25 +0900 | [diff] [blame] | 45 | u32 aspm_capable:2; /* Capable ASPM state with latency */ |
Kenji Kaneshige | 80bfdbe | 2009-05-13 12:12:43 +0900 | [diff] [blame] | 46 | u32 aspm_default:2; /* Default ASPM state by BIOS */ |
Kenji Kaneshige | f1c0ca2 | 2009-08-19 10:59:52 +0900 | [diff] [blame] | 47 | u32 aspm_disable:2; /* Disabled ASPM state */ |
Kenji Kaneshige | 80bfdbe | 2009-05-13 12:12:43 +0900 | [diff] [blame] | 48 | |
Kenji Kaneshige | 4d246e4 | 2009-05-13 12:15:38 +0900 | [diff] [blame] | 49 | /* Clock PM state */ |
| 50 | u32 clkpm_capable:1; /* Clock PM capable? */ |
| 51 | u32 clkpm_enabled:1; /* Current Clock PM state */ |
| 52 | u32 clkpm_default:1; /* Default Clock PM state by BIOS */ |
| 53 | |
Kenji Kaneshige | b6c2e54 | 2009-05-13 12:14:58 +0900 | [diff] [blame] | 54 | /* Latencies */ |
| 55 | struct aspm_latency latency; /* Exit latency */ |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 56 | /* |
Kenji Kaneshige | b6c2e54 | 2009-05-13 12:14:58 +0900 | [diff] [blame] | 57 | * Endpoint acceptable latencies. A pcie downstream port only |
| 58 | * has one slot under it, so at most there are 8 functions. |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 59 | */ |
Kenji Kaneshige | b6c2e54 | 2009-05-13 12:14:58 +0900 | [diff] [blame] | 60 | struct aspm_latency acceptable[8]; |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 61 | }; |
| 62 | |
Shaohua Li | d6d3857 | 2008-07-23 10:32:42 +0800 | [diff] [blame] | 63 | static int aspm_disabled, aspm_force; |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 64 | static DEFINE_MUTEX(aspm_lock); |
| 65 | static LIST_HEAD(link_list); |
| 66 | |
| 67 | #define POLICY_DEFAULT 0 /* BIOS default setting */ |
| 68 | #define POLICY_PERFORMANCE 1 /* high performance */ |
| 69 | #define POLICY_POWERSAVE 2 /* high power saving */ |
| 70 | static int aspm_policy; |
| 71 | static const char *policy_str[] = { |
| 72 | [POLICY_DEFAULT] = "default", |
| 73 | [POLICY_PERFORMANCE] = "performance", |
| 74 | [POLICY_POWERSAVE] = "powersave" |
| 75 | }; |
| 76 | |
Andrew Patterson | 987a4c7 | 2009-01-05 16:21:04 -0700 | [diff] [blame] | 77 | #define LINK_RETRAIN_TIMEOUT HZ |
| 78 | |
Kenji Kaneshige | 5aa6358 | 2009-05-13 12:17:44 +0900 | [diff] [blame] | 79 | static int policy_to_aspm_state(struct pcie_link_state *link) |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 80 | { |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 81 | switch (aspm_policy) { |
| 82 | case POLICY_PERFORMANCE: |
| 83 | /* Disable ASPM and Clock PM */ |
| 84 | return 0; |
| 85 | case POLICY_POWERSAVE: |
| 86 | /* Enable ASPM L0s/L1 */ |
Kenji Kaneshige | 80bfdbe | 2009-05-13 12:12:43 +0900 | [diff] [blame] | 87 | return PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1; |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 88 | case POLICY_DEFAULT: |
Kenji Kaneshige | 5aa6358 | 2009-05-13 12:17:44 +0900 | [diff] [blame] | 89 | return link->aspm_default; |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 90 | } |
| 91 | return 0; |
| 92 | } |
| 93 | |
Kenji Kaneshige | 5aa6358 | 2009-05-13 12:17:44 +0900 | [diff] [blame] | 94 | static int policy_to_clkpm_state(struct pcie_link_state *link) |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 95 | { |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 96 | switch (aspm_policy) { |
| 97 | case POLICY_PERFORMANCE: |
| 98 | /* Disable ASPM and Clock PM */ |
| 99 | return 0; |
| 100 | case POLICY_POWERSAVE: |
| 101 | /* Disable Clock PM */ |
| 102 | return 1; |
| 103 | case POLICY_DEFAULT: |
Kenji Kaneshige | 5aa6358 | 2009-05-13 12:17:44 +0900 | [diff] [blame] | 104 | return link->clkpm_default; |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 105 | } |
| 106 | return 0; |
| 107 | } |
| 108 | |
Kenji Kaneshige | 430842e | 2009-05-13 12:20:10 +0900 | [diff] [blame] | 109 | static void pcie_set_clkpm_nocheck(struct pcie_link_state *link, int enable) |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 110 | { |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 111 | int pos; |
| 112 | u16 reg16; |
Kenji Kaneshige | 5aa6358 | 2009-05-13 12:17:44 +0900 | [diff] [blame] | 113 | struct pci_dev *child; |
| 114 | struct pci_bus *linkbus = link->pdev->subordinate; |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 115 | |
Kenji Kaneshige | 5aa6358 | 2009-05-13 12:17:44 +0900 | [diff] [blame] | 116 | list_for_each_entry(child, &linkbus->devices, bus_list) { |
| 117 | pos = pci_find_capability(child, PCI_CAP_ID_EXP); |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 118 | if (!pos) |
| 119 | return; |
Kenji Kaneshige | 5aa6358 | 2009-05-13 12:17:44 +0900 | [diff] [blame] | 120 | pci_read_config_word(child, pos + PCI_EXP_LNKCTL, ®16); |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 121 | if (enable) |
| 122 | reg16 |= PCI_EXP_LNKCTL_CLKREQ_EN; |
| 123 | else |
| 124 | reg16 &= ~PCI_EXP_LNKCTL_CLKREQ_EN; |
Kenji Kaneshige | 5aa6358 | 2009-05-13 12:17:44 +0900 | [diff] [blame] | 125 | pci_write_config_word(child, pos + PCI_EXP_LNKCTL, reg16); |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 126 | } |
Kenji Kaneshige | 5aa6358 | 2009-05-13 12:17:44 +0900 | [diff] [blame] | 127 | link->clkpm_enabled = !!enable; |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 128 | } |
| 129 | |
Kenji Kaneshige | 430842e | 2009-05-13 12:20:10 +0900 | [diff] [blame] | 130 | static void pcie_set_clkpm(struct pcie_link_state *link, int enable) |
| 131 | { |
| 132 | /* Don't enable Clock PM if the link is not Clock PM capable */ |
| 133 | if (!link->clkpm_capable && enable) |
| 134 | return; |
| 135 | /* Need nothing if the specified equals to current state */ |
| 136 | if (link->clkpm_enabled == enable) |
| 137 | return; |
| 138 | pcie_set_clkpm_nocheck(link, enable); |
| 139 | } |
| 140 | |
Kenji Kaneshige | 8d349ac | 2009-05-13 12:18:22 +0900 | [diff] [blame] | 141 | static void pcie_clkpm_cap_init(struct pcie_link_state *link, int blacklist) |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 142 | { |
Kenji Kaneshige | 5aa6358 | 2009-05-13 12:17:44 +0900 | [diff] [blame] | 143 | int pos, capable = 1, enabled = 1; |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 144 | u32 reg32; |
| 145 | u16 reg16; |
Kenji Kaneshige | 5aa6358 | 2009-05-13 12:17:44 +0900 | [diff] [blame] | 146 | struct pci_dev *child; |
| 147 | struct pci_bus *linkbus = link->pdev->subordinate; |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 148 | |
| 149 | /* All functions should have the same cap and state, take the worst */ |
Kenji Kaneshige | 5aa6358 | 2009-05-13 12:17:44 +0900 | [diff] [blame] | 150 | list_for_each_entry(child, &linkbus->devices, bus_list) { |
| 151 | pos = pci_find_capability(child, PCI_CAP_ID_EXP); |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 152 | if (!pos) |
| 153 | return; |
Kenji Kaneshige | 5aa6358 | 2009-05-13 12:17:44 +0900 | [diff] [blame] | 154 | pci_read_config_dword(child, pos + PCI_EXP_LNKCAP, ®32); |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 155 | if (!(reg32 & PCI_EXP_LNKCAP_CLKPM)) { |
| 156 | capable = 0; |
| 157 | enabled = 0; |
| 158 | break; |
| 159 | } |
Kenji Kaneshige | 5aa6358 | 2009-05-13 12:17:44 +0900 | [diff] [blame] | 160 | pci_read_config_word(child, pos + PCI_EXP_LNKCTL, ®16); |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 161 | if (!(reg16 & PCI_EXP_LNKCTL_CLKREQ_EN)) |
| 162 | enabled = 0; |
| 163 | } |
Kenji Kaneshige | 5aa6358 | 2009-05-13 12:17:44 +0900 | [diff] [blame] | 164 | link->clkpm_enabled = enabled; |
| 165 | link->clkpm_default = enabled; |
Kenji Kaneshige | 8d349ac | 2009-05-13 12:18:22 +0900 | [diff] [blame] | 166 | link->clkpm_capable = (blacklist) ? 0 : capable; |
Shaohua Li | 46bbdfa | 2008-12-19 09:27:42 +0800 | [diff] [blame] | 167 | } |
| 168 | |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 169 | /* |
| 170 | * pcie_aspm_configure_common_clock: check if the 2 ends of a link |
| 171 | * could use common clock. If they are, configure them to use the |
| 172 | * common clock. That will reduce the ASPM state exit latency. |
| 173 | */ |
Kenji Kaneshige | 5aa6358 | 2009-05-13 12:17:44 +0900 | [diff] [blame] | 174 | static void pcie_aspm_configure_common_clock(struct pcie_link_state *link) |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 175 | { |
Kenji Kaneshige | 5aa6358 | 2009-05-13 12:17:44 +0900 | [diff] [blame] | 176 | int ppos, cpos, same_clock = 1; |
| 177 | u16 reg16, parent_reg, child_reg[8]; |
Thomas Renninger | 2a42d9d | 2008-12-09 13:05:09 +0100 | [diff] [blame] | 178 | unsigned long start_jiffies; |
Kenji Kaneshige | 5aa6358 | 2009-05-13 12:17:44 +0900 | [diff] [blame] | 179 | struct pci_dev *child, *parent = link->pdev; |
| 180 | struct pci_bus *linkbus = parent->subordinate; |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 181 | /* |
Kenji Kaneshige | 5aa6358 | 2009-05-13 12:17:44 +0900 | [diff] [blame] | 182 | * All functions of a slot should have the same Slot Clock |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 183 | * Configuration, so just check one function |
Kenji Kaneshige | 5aa6358 | 2009-05-13 12:17:44 +0900 | [diff] [blame] | 184 | */ |
| 185 | child = list_entry(linkbus->devices.next, struct pci_dev, bus_list); |
| 186 | BUG_ON(!child->is_pcie); |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 187 | |
| 188 | /* Check downstream component if bit Slot Clock Configuration is 1 */ |
Kenji Kaneshige | 5aa6358 | 2009-05-13 12:17:44 +0900 | [diff] [blame] | 189 | cpos = pci_find_capability(child, PCI_CAP_ID_EXP); |
| 190 | pci_read_config_word(child, cpos + PCI_EXP_LNKSTA, ®16); |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 191 | if (!(reg16 & PCI_EXP_LNKSTA_SLC)) |
| 192 | same_clock = 0; |
| 193 | |
| 194 | /* Check upstream component if bit Slot Clock Configuration is 1 */ |
Kenji Kaneshige | 5aa6358 | 2009-05-13 12:17:44 +0900 | [diff] [blame] | 195 | ppos = pci_find_capability(parent, PCI_CAP_ID_EXP); |
| 196 | pci_read_config_word(parent, ppos + PCI_EXP_LNKSTA, ®16); |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 197 | if (!(reg16 & PCI_EXP_LNKSTA_SLC)) |
| 198 | same_clock = 0; |
| 199 | |
| 200 | /* Configure downstream component, all functions */ |
Kenji Kaneshige | 5aa6358 | 2009-05-13 12:17:44 +0900 | [diff] [blame] | 201 | list_for_each_entry(child, &linkbus->devices, bus_list) { |
| 202 | cpos = pci_find_capability(child, PCI_CAP_ID_EXP); |
| 203 | pci_read_config_word(child, cpos + PCI_EXP_LNKCTL, ®16); |
| 204 | child_reg[PCI_FUNC(child->devfn)] = reg16; |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 205 | if (same_clock) |
| 206 | reg16 |= PCI_EXP_LNKCTL_CCC; |
| 207 | else |
| 208 | reg16 &= ~PCI_EXP_LNKCTL_CCC; |
Kenji Kaneshige | 5aa6358 | 2009-05-13 12:17:44 +0900 | [diff] [blame] | 209 | pci_write_config_word(child, cpos + PCI_EXP_LNKCTL, reg16); |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | /* Configure upstream component */ |
Kenji Kaneshige | 5aa6358 | 2009-05-13 12:17:44 +0900 | [diff] [blame] | 213 | pci_read_config_word(parent, ppos + PCI_EXP_LNKCTL, ®16); |
Thomas Renninger | 2a42d9d | 2008-12-09 13:05:09 +0100 | [diff] [blame] | 214 | parent_reg = reg16; |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 215 | if (same_clock) |
| 216 | reg16 |= PCI_EXP_LNKCTL_CCC; |
| 217 | else |
| 218 | reg16 &= ~PCI_EXP_LNKCTL_CCC; |
Kenji Kaneshige | 5aa6358 | 2009-05-13 12:17:44 +0900 | [diff] [blame] | 219 | pci_write_config_word(parent, ppos + PCI_EXP_LNKCTL, reg16); |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 220 | |
Kenji Kaneshige | 5aa6358 | 2009-05-13 12:17:44 +0900 | [diff] [blame] | 221 | /* Retrain link */ |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 222 | reg16 |= PCI_EXP_LNKCTL_RL; |
Kenji Kaneshige | 5aa6358 | 2009-05-13 12:17:44 +0900 | [diff] [blame] | 223 | pci_write_config_word(parent, ppos + PCI_EXP_LNKCTL, reg16); |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 224 | |
Kenji Kaneshige | 5aa6358 | 2009-05-13 12:17:44 +0900 | [diff] [blame] | 225 | /* Wait for link training end. Break out after waiting for timeout */ |
Thomas Renninger | 2a42d9d | 2008-12-09 13:05:09 +0100 | [diff] [blame] | 226 | start_jiffies = jiffies; |
Andrew Patterson | 987a4c7 | 2009-01-05 16:21:04 -0700 | [diff] [blame] | 227 | for (;;) { |
Kenji Kaneshige | 5aa6358 | 2009-05-13 12:17:44 +0900 | [diff] [blame] | 228 | pci_read_config_word(parent, ppos + PCI_EXP_LNKSTA, ®16); |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 229 | if (!(reg16 & PCI_EXP_LNKSTA_LT)) |
| 230 | break; |
Andrew Patterson | 987a4c7 | 2009-01-05 16:21:04 -0700 | [diff] [blame] | 231 | if (time_after(jiffies, start_jiffies + LINK_RETRAIN_TIMEOUT)) |
| 232 | break; |
| 233 | msleep(1); |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 234 | } |
Kenji Kaneshige | 5aa6358 | 2009-05-13 12:17:44 +0900 | [diff] [blame] | 235 | if (!(reg16 & PCI_EXP_LNKSTA_LT)) |
| 236 | return; |
| 237 | |
| 238 | /* Training failed. Restore common clock configurations */ |
| 239 | dev_printk(KERN_ERR, &parent->dev, |
| 240 | "ASPM: Could not configure common clock\n"); |
| 241 | list_for_each_entry(child, &linkbus->devices, bus_list) { |
| 242 | cpos = pci_find_capability(child, PCI_CAP_ID_EXP); |
| 243 | pci_write_config_word(child, cpos + PCI_EXP_LNKCTL, |
| 244 | child_reg[PCI_FUNC(child->devfn)]); |
Thomas Renninger | 2a42d9d | 2008-12-09 13:05:09 +0100 | [diff] [blame] | 245 | } |
Kenji Kaneshige | 5aa6358 | 2009-05-13 12:17:44 +0900 | [diff] [blame] | 246 | pci_write_config_word(parent, ppos + PCI_EXP_LNKCTL, parent_reg); |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 247 | } |
| 248 | |
Kenji Kaneshige | 5e0eaa7 | 2009-05-13 12:21:48 +0900 | [diff] [blame] | 249 | /* Convert L0s latency encoding to ns */ |
| 250 | static u32 calc_l0s_latency(u32 encoding) |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 251 | { |
Kenji Kaneshige | 5e0eaa7 | 2009-05-13 12:21:48 +0900 | [diff] [blame] | 252 | if (encoding == 0x7) |
| 253 | return (5 * 1000); /* > 4us */ |
| 254 | return (64 << encoding); |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 255 | } |
| 256 | |
Kenji Kaneshige | 5e0eaa7 | 2009-05-13 12:21:48 +0900 | [diff] [blame] | 257 | /* Convert L0s acceptable latency encoding to ns */ |
| 258 | static u32 calc_l0s_acceptable(u32 encoding) |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 259 | { |
Kenji Kaneshige | 5e0eaa7 | 2009-05-13 12:21:48 +0900 | [diff] [blame] | 260 | if (encoding == 0x7) |
| 261 | return -1U; |
| 262 | return (64 << encoding); |
| 263 | } |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 264 | |
Kenji Kaneshige | 5e0eaa7 | 2009-05-13 12:21:48 +0900 | [diff] [blame] | 265 | /* Convert L1 latency encoding to ns */ |
| 266 | static u32 calc_l1_latency(u32 encoding) |
| 267 | { |
| 268 | if (encoding == 0x7) |
| 269 | return (65 * 1000); /* > 64us */ |
| 270 | return (1000 << encoding); |
| 271 | } |
| 272 | |
| 273 | /* Convert L1 acceptable latency encoding to ns */ |
| 274 | static u32 calc_l1_acceptable(u32 encoding) |
| 275 | { |
| 276 | if (encoding == 0x7) |
| 277 | return -1U; |
| 278 | return (1000 << encoding); |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | static void pcie_aspm_get_cap_device(struct pci_dev *pdev, u32 *state, |
Kenji Kaneshige | 7ab7099 | 2009-05-13 12:20:48 +0900 | [diff] [blame] | 282 | u32 *l0s, u32 *l1, u32 *enabled) |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 283 | { |
| 284 | int pos; |
| 285 | u16 reg16; |
Kenji Kaneshige | 5e0eaa7 | 2009-05-13 12:21:48 +0900 | [diff] [blame] | 286 | u32 reg32, encoding; |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 287 | |
Kenji Kaneshige | 80bfdbe | 2009-05-13 12:12:43 +0900 | [diff] [blame] | 288 | *l0s = *l1 = *enabled = 0; |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 289 | pos = pci_find_capability(pdev, PCI_CAP_ID_EXP); |
| 290 | pci_read_config_dword(pdev, pos + PCI_EXP_LNKCAP, ®32); |
| 291 | *state = (reg32 & PCI_EXP_LNKCAP_ASPMS) >> 10; |
| 292 | if (*state != PCIE_LINK_STATE_L0S && |
Kenji Kaneshige | 7ab7099 | 2009-05-13 12:20:48 +0900 | [diff] [blame] | 293 | *state != (PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_L0S)) |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 294 | *state = 0; |
| 295 | if (*state == 0) |
| 296 | return; |
| 297 | |
Kenji Kaneshige | 5e0eaa7 | 2009-05-13 12:21:48 +0900 | [diff] [blame] | 298 | encoding = (reg32 & PCI_EXP_LNKCAP_L0SEL) >> 12; |
| 299 | *l0s = calc_l0s_latency(encoding); |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 300 | if (*state & PCIE_LINK_STATE_L1) { |
Kenji Kaneshige | 5e0eaa7 | 2009-05-13 12:21:48 +0900 | [diff] [blame] | 301 | encoding = (reg32 & PCI_EXP_LNKCAP_L1EL) >> 15; |
| 302 | *l1 = calc_l1_latency(encoding); |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 303 | } |
| 304 | pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, ®16); |
Kenji Kaneshige | 7ab7099 | 2009-05-13 12:20:48 +0900 | [diff] [blame] | 305 | *enabled = reg16 & (PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1); |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 306 | } |
| 307 | |
Kenji Kaneshige | 07d9276 | 2009-08-19 11:00:25 +0900 | [diff] [blame] | 308 | static void pcie_aspm_check_latency(struct pci_dev *endpoint) |
| 309 | { |
| 310 | u32 l1_switch_latency = 0; |
| 311 | struct aspm_latency *acceptable; |
| 312 | struct pcie_link_state *link; |
| 313 | |
| 314 | /* Device not in D0 doesn't need latency check */ |
| 315 | if ((endpoint->current_state != PCI_D0) && |
| 316 | (endpoint->current_state != PCI_UNKNOWN)) |
| 317 | return; |
| 318 | |
| 319 | link = endpoint->bus->self->link_state; |
| 320 | acceptable = &link->acceptable[PCI_FUNC(endpoint->devfn)]; |
| 321 | |
| 322 | while (link) { |
| 323 | /* Check L0s latency */ |
| 324 | if ((link->aspm_capable & PCIE_LINK_STATE_L0S) && |
| 325 | (link->latency.l0s > acceptable->l0s)) |
| 326 | link->aspm_capable &= ~PCIE_LINK_STATE_L0S; |
| 327 | /* |
| 328 | * Check L1 latency. |
| 329 | * Every switch on the path to root complex need 1 |
| 330 | * more microsecond for L1. Spec doesn't mention L0s. |
| 331 | */ |
| 332 | if ((link->aspm_capable & PCIE_LINK_STATE_L1) && |
| 333 | (link->latency.l1 + l1_switch_latency > acceptable->l1)) |
| 334 | link->aspm_capable &= ~PCIE_LINK_STATE_L1; |
| 335 | l1_switch_latency += 1000; |
| 336 | |
| 337 | link = link->parent; |
| 338 | } |
| 339 | } |
| 340 | |
Kenji Kaneshige | 8d349ac | 2009-05-13 12:18:22 +0900 | [diff] [blame] | 341 | static void pcie_aspm_cap_init(struct pcie_link_state *link, int blacklist) |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 342 | { |
Kenji Kaneshige | 80bfdbe | 2009-05-13 12:12:43 +0900 | [diff] [blame] | 343 | u32 support, l0s, l1, enabled; |
Kenji Kaneshige | 5aa6358 | 2009-05-13 12:17:44 +0900 | [diff] [blame] | 344 | struct pci_dev *child, *parent = link->pdev; |
| 345 | struct pci_bus *linkbus = parent->subordinate; |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 346 | |
Kenji Kaneshige | 8d349ac | 2009-05-13 12:18:22 +0900 | [diff] [blame] | 347 | if (blacklist) { |
Kenji Kaneshige | f1c0ca2 | 2009-08-19 10:59:52 +0900 | [diff] [blame] | 348 | /* Set enabled/disable so that we will disable ASPM later */ |
Kenji Kaneshige | 8d349ac | 2009-05-13 12:18:22 +0900 | [diff] [blame] | 349 | link->aspm_enabled = PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1; |
Kenji Kaneshige | f1c0ca2 | 2009-08-19 10:59:52 +0900 | [diff] [blame] | 350 | link->aspm_disable = PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1; |
Kenji Kaneshige | 8d349ac | 2009-05-13 12:18:22 +0900 | [diff] [blame] | 351 | return; |
| 352 | } |
| 353 | |
| 354 | /* Configure common clock before checking latencies */ |
| 355 | pcie_aspm_configure_common_clock(link); |
| 356 | |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 357 | /* upstream component states */ |
Kenji Kaneshige | 5aa6358 | 2009-05-13 12:17:44 +0900 | [diff] [blame] | 358 | pcie_aspm_get_cap_device(parent, &support, &l0s, &l1, &enabled); |
| 359 | link->aspm_support = support; |
| 360 | link->latency.l0s = l0s; |
| 361 | link->latency.l1 = l1; |
| 362 | link->aspm_enabled = enabled; |
Kenji Kaneshige | 80bfdbe | 2009-05-13 12:12:43 +0900 | [diff] [blame] | 363 | |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 364 | /* downstream component states, all functions have the same setting */ |
Kenji Kaneshige | 5aa6358 | 2009-05-13 12:17:44 +0900 | [diff] [blame] | 365 | child = list_entry(linkbus->devices.next, struct pci_dev, bus_list); |
| 366 | pcie_aspm_get_cap_device(child, &support, &l0s, &l1, &enabled); |
| 367 | link->aspm_support &= support; |
| 368 | link->latency.l0s = max_t(u32, link->latency.l0s, l0s); |
| 369 | link->latency.l1 = max_t(u32, link->latency.l1, l1); |
Kenji Kaneshige | 80bfdbe | 2009-05-13 12:12:43 +0900 | [diff] [blame] | 370 | |
Kenji Kaneshige | b127bd5 | 2009-08-19 10:57:31 +0900 | [diff] [blame] | 371 | /* Save default state */ |
| 372 | link->aspm_default = link->aspm_enabled; |
Kenji Kaneshige | 07d9276 | 2009-08-19 11:00:25 +0900 | [diff] [blame] | 373 | |
| 374 | /* Setup initial capable state. Will be updated later */ |
| 375 | link->aspm_capable = link->aspm_support; |
Kenji Kaneshige | f1c0ca2 | 2009-08-19 10:59:52 +0900 | [diff] [blame] | 376 | /* |
| 377 | * If the downstream component has pci bridge function, don't |
| 378 | * do ASPM for now. |
| 379 | */ |
| 380 | list_for_each_entry(child, &linkbus->devices, bus_list) { |
| 381 | if (child->pcie_type == PCI_EXP_TYPE_PCI_BRIDGE) { |
| 382 | link->aspm_disable = |
| 383 | PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1; |
| 384 | break; |
| 385 | } |
| 386 | } |
Kenji Kaneshige | b127bd5 | 2009-08-19 10:57:31 +0900 | [diff] [blame] | 387 | |
Kenji Kaneshige | b7206cb | 2009-08-19 11:01:37 +0900 | [diff] [blame^] | 388 | /* Get and check endpoint acceptable latencies */ |
Kenji Kaneshige | 5aa6358 | 2009-05-13 12:17:44 +0900 | [diff] [blame] | 389 | list_for_each_entry(child, &linkbus->devices, bus_list) { |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 390 | int pos; |
Kenji Kaneshige | 5e0eaa7 | 2009-05-13 12:21:48 +0900 | [diff] [blame] | 391 | u32 reg32, encoding; |
Kenji Kaneshige | b6c2e54 | 2009-05-13 12:14:58 +0900 | [diff] [blame] | 392 | struct aspm_latency *acceptable = |
Kenji Kaneshige | 5aa6358 | 2009-05-13 12:17:44 +0900 | [diff] [blame] | 393 | &link->acceptable[PCI_FUNC(child->devfn)]; |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 394 | |
Kenji Kaneshige | 5aa6358 | 2009-05-13 12:17:44 +0900 | [diff] [blame] | 395 | if (child->pcie_type != PCI_EXP_TYPE_ENDPOINT && |
| 396 | child->pcie_type != PCI_EXP_TYPE_LEG_END) |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 397 | continue; |
| 398 | |
Kenji Kaneshige | 5aa6358 | 2009-05-13 12:17:44 +0900 | [diff] [blame] | 399 | pos = pci_find_capability(child, PCI_CAP_ID_EXP); |
| 400 | pci_read_config_dword(child, pos + PCI_EXP_DEVCAP, ®32); |
Kenji Kaneshige | 07d9276 | 2009-08-19 11:00:25 +0900 | [diff] [blame] | 401 | /* Calculate endpoint L0s acceptable latency */ |
Kenji Kaneshige | 5e0eaa7 | 2009-05-13 12:21:48 +0900 | [diff] [blame] | 402 | encoding = (reg32 & PCI_EXP_DEVCAP_L0S) >> 6; |
| 403 | acceptable->l0s = calc_l0s_acceptable(encoding); |
Kenji Kaneshige | 07d9276 | 2009-08-19 11:00:25 +0900 | [diff] [blame] | 404 | /* Calculate endpoint L1 acceptable latency */ |
| 405 | encoding = (reg32 & PCI_EXP_DEVCAP_L1) >> 9; |
| 406 | acceptable->l1 = calc_l1_acceptable(encoding); |
| 407 | |
| 408 | pcie_aspm_check_latency(child); |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 409 | } |
| 410 | } |
| 411 | |
Kenji Kaneshige | b7206cb | 2009-08-19 11:01:37 +0900 | [diff] [blame^] | 412 | static void pcie_config_aspm_dev(struct pci_dev *pdev, u32 state) |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 413 | { |
| 414 | u16 reg16; |
| 415 | int pos = pci_find_capability(pdev, PCI_CAP_ID_EXP); |
| 416 | |
| 417 | pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, ®16); |
| 418 | reg16 &= ~0x3; |
| 419 | reg16 |= state; |
| 420 | pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, reg16); |
| 421 | } |
| 422 | |
Kenji Kaneshige | b7206cb | 2009-08-19 11:01:37 +0900 | [diff] [blame^] | 423 | static void pcie_config_aspm_link(struct pcie_link_state *link, u32 state) |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 424 | { |
Kenji Kaneshige | 5aa6358 | 2009-05-13 12:17:44 +0900 | [diff] [blame] | 425 | struct pci_dev *child, *parent = link->pdev; |
| 426 | struct pci_bus *linkbus = parent->subordinate; |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 427 | |
Kenji Kaneshige | f1c0ca2 | 2009-08-19 10:59:52 +0900 | [diff] [blame] | 428 | /* Nothing to do if the link is already in the requested state */ |
Kenji Kaneshige | b7206cb | 2009-08-19 11:01:37 +0900 | [diff] [blame^] | 429 | state &= (link->aspm_capable & ~link->aspm_disable); |
Kenji Kaneshige | f1c0ca2 | 2009-08-19 10:59:52 +0900 | [diff] [blame] | 430 | if (link->aspm_enabled == state) |
| 431 | return; |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 432 | /* |
Kenji Kaneshige | 5aa6358 | 2009-05-13 12:17:44 +0900 | [diff] [blame] | 433 | * Spec 2.0 suggests all functions should be configured the |
| 434 | * same setting for ASPM. Enabling ASPM L1 should be done in |
| 435 | * upstream component first and then downstream, and vice |
| 436 | * versa for disabling ASPM L1. Spec doesn't mention L0S. |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 437 | */ |
| 438 | if (state & PCIE_LINK_STATE_L1) |
Kenji Kaneshige | b7206cb | 2009-08-19 11:01:37 +0900 | [diff] [blame^] | 439 | pcie_config_aspm_dev(parent, state); |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 440 | |
Kenji Kaneshige | 5aa6358 | 2009-05-13 12:17:44 +0900 | [diff] [blame] | 441 | list_for_each_entry(child, &linkbus->devices, bus_list) |
Kenji Kaneshige | b7206cb | 2009-08-19 11:01:37 +0900 | [diff] [blame^] | 442 | pcie_config_aspm_dev(child, state); |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 443 | |
| 444 | if (!(state & PCIE_LINK_STATE_L1)) |
Kenji Kaneshige | b7206cb | 2009-08-19 11:01:37 +0900 | [diff] [blame^] | 445 | pcie_config_aspm_dev(parent, state); |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 446 | |
Kenji Kaneshige | 5aa6358 | 2009-05-13 12:17:44 +0900 | [diff] [blame] | 447 | link->aspm_enabled = state; |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 448 | } |
| 449 | |
Kenji Kaneshige | b7206cb | 2009-08-19 11:01:37 +0900 | [diff] [blame^] | 450 | static void pcie_config_aspm_path(struct pcie_link_state *link) |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 451 | { |
Kenji Kaneshige | b7206cb | 2009-08-19 11:01:37 +0900 | [diff] [blame^] | 452 | while (link) { |
| 453 | pcie_config_aspm_link(link, policy_to_aspm_state(link)); |
| 454 | link = link->parent; |
Shaohua Li | 46bbdfa | 2008-12-19 09:27:42 +0800 | [diff] [blame] | 455 | } |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 456 | } |
| 457 | |
Kenji Kaneshige | 5aa6358 | 2009-05-13 12:17:44 +0900 | [diff] [blame] | 458 | static void free_link_state(struct pcie_link_state *link) |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 459 | { |
Kenji Kaneshige | 5aa6358 | 2009-05-13 12:17:44 +0900 | [diff] [blame] | 460 | link->pdev->link_state = NULL; |
| 461 | kfree(link); |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 462 | } |
| 463 | |
Shaohua Li | ddc9753 | 2008-05-21 16:58:40 +0800 | [diff] [blame] | 464 | static int pcie_aspm_sanity_check(struct pci_dev *pdev) |
| 465 | { |
Kenji Kaneshige | 3647584 | 2009-05-13 12:23:09 +0900 | [diff] [blame] | 466 | struct pci_dev *child; |
| 467 | int pos; |
Shaohua Li | 149e163 | 2008-07-23 10:32:31 +0800 | [diff] [blame] | 468 | u32 reg32; |
Shaohua Li | ddc9753 | 2008-05-21 16:58:40 +0800 | [diff] [blame] | 469 | /* |
Kenji Kaneshige | 3647584 | 2009-05-13 12:23:09 +0900 | [diff] [blame] | 470 | * Some functions in a slot might not all be PCIE functions, |
| 471 | * very strange. Disable ASPM for the whole slot |
Shaohua Li | ddc9753 | 2008-05-21 16:58:40 +0800 | [diff] [blame] | 472 | */ |
Kenji Kaneshige | 3647584 | 2009-05-13 12:23:09 +0900 | [diff] [blame] | 473 | list_for_each_entry(child, &pdev->subordinate->devices, bus_list) { |
| 474 | pos = pci_find_capability(child, PCI_CAP_ID_EXP); |
| 475 | if (!pos) |
Shaohua Li | ddc9753 | 2008-05-21 16:58:40 +0800 | [diff] [blame] | 476 | return -EINVAL; |
Shaohua Li | 149e163 | 2008-07-23 10:32:31 +0800 | [diff] [blame] | 477 | /* |
| 478 | * Disable ASPM for pre-1.1 PCIe device, we follow MS to use |
| 479 | * RBER bit to determine if a function is 1.1 version device |
| 480 | */ |
Kenji Kaneshige | 3647584 | 2009-05-13 12:23:09 +0900 | [diff] [blame] | 481 | pci_read_config_dword(child, pos + PCI_EXP_DEVCAP, ®32); |
Sitsofe Wheeler | e1f4f59 | 2008-09-16 14:27:13 +0100 | [diff] [blame] | 482 | if (!(reg32 & PCI_EXP_DEVCAP_RBER) && !aspm_force) { |
Kenji Kaneshige | 3647584 | 2009-05-13 12:23:09 +0900 | [diff] [blame] | 483 | dev_printk(KERN_INFO, &child->dev, "disabling ASPM" |
Vincent Legoll | f393d9b | 2008-10-12 12:26:12 +0200 | [diff] [blame] | 484 | " on pre-1.1 PCIe device. You can enable it" |
| 485 | " with 'pcie_aspm=force'\n"); |
Shaohua Li | 149e163 | 2008-07-23 10:32:31 +0800 | [diff] [blame] | 486 | return -EINVAL; |
| 487 | } |
Shaohua Li | ddc9753 | 2008-05-21 16:58:40 +0800 | [diff] [blame] | 488 | } |
| 489 | return 0; |
| 490 | } |
| 491 | |
Kenji Kaneshige | b7206cb | 2009-08-19 11:01:37 +0900 | [diff] [blame^] | 492 | static struct pcie_link_state *alloc_pcie_link_state(struct pci_dev *pdev) |
Kenji Kaneshige | 8d349ac | 2009-05-13 12:18:22 +0900 | [diff] [blame] | 493 | { |
| 494 | struct pcie_link_state *link; |
Kenji Kaneshige | 8d349ac | 2009-05-13 12:18:22 +0900 | [diff] [blame] | 495 | |
| 496 | link = kzalloc(sizeof(*link), GFP_KERNEL); |
| 497 | if (!link) |
| 498 | return NULL; |
| 499 | INIT_LIST_HEAD(&link->sibling); |
| 500 | INIT_LIST_HEAD(&link->children); |
| 501 | INIT_LIST_HEAD(&link->link); |
| 502 | link->pdev = pdev; |
Kenji Kaneshige | 8d349ac | 2009-05-13 12:18:22 +0900 | [diff] [blame] | 503 | if (pdev->pcie_type == PCI_EXP_TYPE_DOWNSTREAM) { |
| 504 | struct pcie_link_state *parent; |
| 505 | parent = pdev->bus->parent->self->link_state; |
| 506 | if (!parent) { |
| 507 | kfree(link); |
| 508 | return NULL; |
| 509 | } |
| 510 | link->parent = parent; |
| 511 | list_add(&link->link, &parent->children); |
| 512 | } |
Kenji Kaneshige | 5c92ffb | 2009-05-13 12:23:57 +0900 | [diff] [blame] | 513 | /* Setup a pointer to the root port link */ |
| 514 | if (!link->parent) |
| 515 | link->root = link; |
| 516 | else |
| 517 | link->root = link->parent->root; |
| 518 | |
Kenji Kaneshige | 8d349ac | 2009-05-13 12:18:22 +0900 | [diff] [blame] | 519 | list_add(&link->sibling, &link_list); |
Kenji Kaneshige | 8d349ac | 2009-05-13 12:18:22 +0900 | [diff] [blame] | 520 | pdev->link_state = link; |
Kenji Kaneshige | 8d349ac | 2009-05-13 12:18:22 +0900 | [diff] [blame] | 521 | return link; |
| 522 | } |
| 523 | |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 524 | /* |
| 525 | * pcie_aspm_init_link_state: Initiate PCI express link state. |
| 526 | * It is called after the pcie and its children devices are scaned. |
| 527 | * @pdev: the root port or switch downstream port |
| 528 | */ |
| 529 | void pcie_aspm_init_link_state(struct pci_dev *pdev) |
| 530 | { |
Kenji Kaneshige | 8d349ac | 2009-05-13 12:18:22 +0900 | [diff] [blame] | 531 | struct pcie_link_state *link; |
Kenji Kaneshige | b7206cb | 2009-08-19 11:01:37 +0900 | [diff] [blame^] | 532 | int blacklist = !!pcie_aspm_sanity_check(pdev); |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 533 | |
| 534 | if (aspm_disabled || !pdev->is_pcie || pdev->link_state) |
| 535 | return; |
| 536 | if (pdev->pcie_type != PCI_EXP_TYPE_ROOT_PORT && |
Kenji Kaneshige | 8d349ac | 2009-05-13 12:18:22 +0900 | [diff] [blame] | 537 | pdev->pcie_type != PCI_EXP_TYPE_DOWNSTREAM) |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 538 | return; |
Kenji Kaneshige | 8d349ac | 2009-05-13 12:18:22 +0900 | [diff] [blame] | 539 | |
Shaohua Li | 8e822df | 2009-06-08 09:27:25 +0800 | [diff] [blame] | 540 | /* VIA has a strange chipset, root port is under a bridge */ |
| 541 | if (pdev->pcie_type == PCI_EXP_TYPE_ROOT_PORT && |
Kenji Kaneshige | 8d349ac | 2009-05-13 12:18:22 +0900 | [diff] [blame] | 542 | pdev->bus->self) |
Shaohua Li | 8e822df | 2009-06-08 09:27:25 +0800 | [diff] [blame] | 543 | return; |
Kenji Kaneshige | 8d349ac | 2009-05-13 12:18:22 +0900 | [diff] [blame] | 544 | |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 545 | down_read(&pci_bus_sem); |
| 546 | if (list_empty(&pdev->subordinate->devices)) |
| 547 | goto out; |
| 548 | |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 549 | mutex_lock(&aspm_lock); |
Kenji Kaneshige | b7206cb | 2009-08-19 11:01:37 +0900 | [diff] [blame^] | 550 | link = alloc_pcie_link_state(pdev); |
Kenji Kaneshige | 8d349ac | 2009-05-13 12:18:22 +0900 | [diff] [blame] | 551 | if (!link) |
| 552 | goto unlock; |
| 553 | /* |
Kenji Kaneshige | b7206cb | 2009-08-19 11:01:37 +0900 | [diff] [blame^] | 554 | * Setup initial ASPM state. Note that we need to configure |
| 555 | * upstream links also because capable state of them can be |
| 556 | * update through pcie_aspm_cap_init(). |
Kenji Kaneshige | 8d349ac | 2009-05-13 12:18:22 +0900 | [diff] [blame] | 557 | */ |
Kenji Kaneshige | b7206cb | 2009-08-19 11:01:37 +0900 | [diff] [blame^] | 558 | pcie_aspm_cap_init(link, blacklist); |
| 559 | pcie_config_aspm_path(link); |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 560 | |
Kenji Kaneshige | 8d349ac | 2009-05-13 12:18:22 +0900 | [diff] [blame] | 561 | /* Setup initial Clock PM state */ |
Kenji Kaneshige | b7206cb | 2009-08-19 11:01:37 +0900 | [diff] [blame^] | 562 | pcie_clkpm_cap_init(link, blacklist); |
| 563 | pcie_set_clkpm(link, policy_to_clkpm_state(link)); |
Kenji Kaneshige | 8d349ac | 2009-05-13 12:18:22 +0900 | [diff] [blame] | 564 | unlock: |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 565 | mutex_unlock(&aspm_lock); |
| 566 | out: |
| 567 | up_read(&pci_bus_sem); |
| 568 | } |
| 569 | |
Kenji Kaneshige | 07d9276 | 2009-08-19 11:00:25 +0900 | [diff] [blame] | 570 | /* Recheck latencies and update aspm_capable for links under the root */ |
| 571 | static void pcie_update_aspm_capable(struct pcie_link_state *root) |
| 572 | { |
| 573 | struct pcie_link_state *link; |
| 574 | BUG_ON(root->parent); |
| 575 | list_for_each_entry(link, &link_list, sibling) { |
| 576 | if (link->root != root) |
| 577 | continue; |
| 578 | link->aspm_capable = link->aspm_support; |
| 579 | } |
| 580 | list_for_each_entry(link, &link_list, sibling) { |
| 581 | struct pci_dev *child; |
| 582 | struct pci_bus *linkbus = link->pdev->subordinate; |
| 583 | if (link->root != root) |
| 584 | continue; |
| 585 | list_for_each_entry(child, &linkbus->devices, bus_list) { |
| 586 | if ((child->pcie_type != PCI_EXP_TYPE_ENDPOINT) && |
| 587 | (child->pcie_type != PCI_EXP_TYPE_LEG_END)) |
| 588 | continue; |
| 589 | pcie_aspm_check_latency(child); |
| 590 | } |
| 591 | } |
| 592 | } |
| 593 | |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 594 | /* @pdev: the endpoint device */ |
| 595 | void pcie_aspm_exit_link_state(struct pci_dev *pdev) |
| 596 | { |
| 597 | struct pci_dev *parent = pdev->bus->self; |
Kenji Kaneshige | b7206cb | 2009-08-19 11:01:37 +0900 | [diff] [blame^] | 598 | struct pcie_link_state *link, *root, *parent_link; |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 599 | |
Kenji Kaneshige | fc87e91 | 2009-08-19 10:58:46 +0900 | [diff] [blame] | 600 | if (aspm_disabled || !pdev->is_pcie || !parent || !parent->link_state) |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 601 | return; |
Kenji Kaneshige | b7206cb | 2009-08-19 11:01:37 +0900 | [diff] [blame^] | 602 | if ((parent->pcie_type != PCI_EXP_TYPE_ROOT_PORT) && |
| 603 | (parent->pcie_type != PCI_EXP_TYPE_DOWNSTREAM)) |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 604 | return; |
Kenji Kaneshige | fc87e91 | 2009-08-19 10:58:46 +0900 | [diff] [blame] | 605 | |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 606 | down_read(&pci_bus_sem); |
| 607 | mutex_lock(&aspm_lock); |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 608 | /* |
| 609 | * All PCIe functions are in one slot, remove one function will remove |
Alex Chiang | 3419c75 | 2009-01-28 14:59:18 -0700 | [diff] [blame] | 610 | * the whole slot, so just wait until we are the last function left. |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 611 | */ |
Alex Chiang | 3419c75 | 2009-01-28 14:59:18 -0700 | [diff] [blame] | 612 | if (!list_is_last(&pdev->bus_list, &parent->subordinate->devices)) |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 613 | goto out; |
| 614 | |
Kenji Kaneshige | fc87e91 | 2009-08-19 10:58:46 +0900 | [diff] [blame] | 615 | link = parent->link_state; |
Kenji Kaneshige | 07d9276 | 2009-08-19 11:00:25 +0900 | [diff] [blame] | 616 | root = link->root; |
Kenji Kaneshige | b7206cb | 2009-08-19 11:01:37 +0900 | [diff] [blame^] | 617 | parent_link = link->parent; |
Kenji Kaneshige | fc87e91 | 2009-08-19 10:58:46 +0900 | [diff] [blame] | 618 | |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 619 | /* All functions are removed, so just disable ASPM for the link */ |
Kenji Kaneshige | b7206cb | 2009-08-19 11:01:37 +0900 | [diff] [blame^] | 620 | pcie_config_aspm_link(link, 0); |
Kenji Kaneshige | fc87e91 | 2009-08-19 10:58:46 +0900 | [diff] [blame] | 621 | list_del(&link->sibling); |
| 622 | list_del(&link->link); |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 623 | /* Clock PM is for endpoint device */ |
Kenji Kaneshige | fc87e91 | 2009-08-19 10:58:46 +0900 | [diff] [blame] | 624 | free_link_state(link); |
Kenji Kaneshige | 07d9276 | 2009-08-19 11:00:25 +0900 | [diff] [blame] | 625 | |
| 626 | /* Recheck latencies and configure upstream links */ |
| 627 | pcie_update_aspm_capable(root); |
Kenji Kaneshige | b7206cb | 2009-08-19 11:01:37 +0900 | [diff] [blame^] | 628 | pcie_config_aspm_path(parent_link); |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 629 | out: |
| 630 | mutex_unlock(&aspm_lock); |
| 631 | up_read(&pci_bus_sem); |
| 632 | } |
| 633 | |
| 634 | /* @pdev: the root port or switch downstream port */ |
| 635 | void pcie_aspm_pm_state_change(struct pci_dev *pdev) |
| 636 | { |
Kenji Kaneshige | 07d9276 | 2009-08-19 11:00:25 +0900 | [diff] [blame] | 637 | struct pcie_link_state *link = pdev->link_state; |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 638 | |
Kenji Kaneshige | 07d9276 | 2009-08-19 11:00:25 +0900 | [diff] [blame] | 639 | if (aspm_disabled || !pdev->is_pcie || !link) |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 640 | return; |
Kenji Kaneshige | 07d9276 | 2009-08-19 11:00:25 +0900 | [diff] [blame] | 641 | if ((pdev->pcie_type != PCI_EXP_TYPE_ROOT_PORT) && |
| 642 | (pdev->pcie_type != PCI_EXP_TYPE_DOWNSTREAM)) |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 643 | return; |
| 644 | /* |
Kenji Kaneshige | 07d9276 | 2009-08-19 11:00:25 +0900 | [diff] [blame] | 645 | * Devices changed PM state, we should recheck if latency |
| 646 | * meets all functions' requirement |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 647 | */ |
Kenji Kaneshige | 07d9276 | 2009-08-19 11:00:25 +0900 | [diff] [blame] | 648 | down_read(&pci_bus_sem); |
| 649 | mutex_lock(&aspm_lock); |
| 650 | pcie_update_aspm_capable(link->root); |
Kenji Kaneshige | b7206cb | 2009-08-19 11:01:37 +0900 | [diff] [blame^] | 651 | pcie_config_aspm_path(link); |
Kenji Kaneshige | 07d9276 | 2009-08-19 11:00:25 +0900 | [diff] [blame] | 652 | mutex_unlock(&aspm_lock); |
| 653 | up_read(&pci_bus_sem); |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | /* |
| 657 | * pci_disable_link_state - disable pci device's link state, so the link will |
| 658 | * never enter specific states |
| 659 | */ |
| 660 | void pci_disable_link_state(struct pci_dev *pdev, int state) |
| 661 | { |
| 662 | struct pci_dev *parent = pdev->bus->self; |
Kenji Kaneshige | f1c0ca2 | 2009-08-19 10:59:52 +0900 | [diff] [blame] | 663 | struct pcie_link_state *link; |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 664 | |
| 665 | if (aspm_disabled || !pdev->is_pcie) |
| 666 | return; |
| 667 | if (pdev->pcie_type == PCI_EXP_TYPE_ROOT_PORT || |
| 668 | pdev->pcie_type == PCI_EXP_TYPE_DOWNSTREAM) |
| 669 | parent = pdev; |
| 670 | if (!parent || !parent->link_state) |
| 671 | return; |
| 672 | |
| 673 | down_read(&pci_bus_sem); |
| 674 | mutex_lock(&aspm_lock); |
Kenji Kaneshige | f1c0ca2 | 2009-08-19 10:59:52 +0900 | [diff] [blame] | 675 | link = parent->link_state; |
| 676 | link->aspm_disable |= state; |
Kenji Kaneshige | b7206cb | 2009-08-19 11:01:37 +0900 | [diff] [blame^] | 677 | pcie_config_aspm_link(link, policy_to_aspm_state(link)); |
| 678 | |
Kenji Kaneshige | 430842e | 2009-05-13 12:20:10 +0900 | [diff] [blame] | 679 | if (state & PCIE_LINK_STATE_CLKPM) { |
Kenji Kaneshige | f1c0ca2 | 2009-08-19 10:59:52 +0900 | [diff] [blame] | 680 | link->clkpm_capable = 0; |
| 681 | pcie_set_clkpm(link, 0); |
Kenji Kaneshige | 430842e | 2009-05-13 12:20:10 +0900 | [diff] [blame] | 682 | } |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 683 | mutex_unlock(&aspm_lock); |
| 684 | up_read(&pci_bus_sem); |
| 685 | } |
| 686 | EXPORT_SYMBOL(pci_disable_link_state); |
| 687 | |
| 688 | static int pcie_aspm_set_policy(const char *val, struct kernel_param *kp) |
| 689 | { |
| 690 | int i; |
Kenji Kaneshige | b7206cb | 2009-08-19 11:01:37 +0900 | [diff] [blame^] | 691 | struct pcie_link_state *link; |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 692 | |
| 693 | for (i = 0; i < ARRAY_SIZE(policy_str); i++) |
| 694 | if (!strncmp(val, policy_str[i], strlen(policy_str[i]))) |
| 695 | break; |
| 696 | if (i >= ARRAY_SIZE(policy_str)) |
| 697 | return -EINVAL; |
| 698 | if (i == aspm_policy) |
| 699 | return 0; |
| 700 | |
| 701 | down_read(&pci_bus_sem); |
| 702 | mutex_lock(&aspm_lock); |
| 703 | aspm_policy = i; |
Kenji Kaneshige | b7206cb | 2009-08-19 11:01:37 +0900 | [diff] [blame^] | 704 | list_for_each_entry(link, &link_list, sibling) { |
| 705 | pcie_config_aspm_link(link, policy_to_aspm_state(link)); |
| 706 | pcie_set_clkpm(link, policy_to_clkpm_state(link)); |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 707 | } |
| 708 | mutex_unlock(&aspm_lock); |
| 709 | up_read(&pci_bus_sem); |
| 710 | return 0; |
| 711 | } |
| 712 | |
| 713 | static int pcie_aspm_get_policy(char *buffer, struct kernel_param *kp) |
| 714 | { |
| 715 | int i, cnt = 0; |
| 716 | for (i = 0; i < ARRAY_SIZE(policy_str); i++) |
| 717 | if (i == aspm_policy) |
| 718 | cnt += sprintf(buffer + cnt, "[%s] ", policy_str[i]); |
| 719 | else |
| 720 | cnt += sprintf(buffer + cnt, "%s ", policy_str[i]); |
| 721 | return cnt; |
| 722 | } |
| 723 | |
| 724 | module_param_call(policy, pcie_aspm_set_policy, pcie_aspm_get_policy, |
| 725 | NULL, 0644); |
| 726 | |
| 727 | #ifdef CONFIG_PCIEASPM_DEBUG |
| 728 | static ssize_t link_state_show(struct device *dev, |
| 729 | struct device_attribute *attr, |
| 730 | char *buf) |
| 731 | { |
| 732 | struct pci_dev *pci_device = to_pci_dev(dev); |
| 733 | struct pcie_link_state *link_state = pci_device->link_state; |
| 734 | |
Kenji Kaneshige | 80bfdbe | 2009-05-13 12:12:43 +0900 | [diff] [blame] | 735 | return sprintf(buf, "%d\n", link_state->aspm_enabled); |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | static ssize_t link_state_store(struct device *dev, |
| 739 | struct device_attribute *attr, |
| 740 | const char *buf, |
| 741 | size_t n) |
| 742 | { |
Kenji Kaneshige | 5aa6358 | 2009-05-13 12:17:44 +0900 | [diff] [blame] | 743 | struct pci_dev *pdev = to_pci_dev(dev); |
Kenji Kaneshige | b7206cb | 2009-08-19 11:01:37 +0900 | [diff] [blame^] | 744 | struct pcie_link_state *link, *root = pdev->link_state->root; |
| 745 | u32 state = buf[0] - '0'; |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 746 | |
Kenji Kaneshige | b7206cb | 2009-08-19 11:01:37 +0900 | [diff] [blame^] | 747 | if (n < 1 || state > 3) |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 748 | return -EINVAL; |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 749 | |
Kenji Kaneshige | b7206cb | 2009-08-19 11:01:37 +0900 | [diff] [blame^] | 750 | down_read(&pci_bus_sem); |
| 751 | mutex_lock(&aspm_lock); |
| 752 | list_for_each_entry(link, &link_list, sibling) { |
| 753 | if (link->root != root) |
| 754 | continue; |
| 755 | pcie_config_aspm_link(link, state); |
| 756 | } |
| 757 | mutex_unlock(&aspm_lock); |
| 758 | up_read(&pci_bus_sem); |
| 759 | return n; |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | static ssize_t clk_ctl_show(struct device *dev, |
| 763 | struct device_attribute *attr, |
| 764 | char *buf) |
| 765 | { |
| 766 | struct pci_dev *pci_device = to_pci_dev(dev); |
| 767 | struct pcie_link_state *link_state = pci_device->link_state; |
| 768 | |
Kenji Kaneshige | 4d246e4 | 2009-05-13 12:15:38 +0900 | [diff] [blame] | 769 | return sprintf(buf, "%d\n", link_state->clkpm_enabled); |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | static ssize_t clk_ctl_store(struct device *dev, |
| 773 | struct device_attribute *attr, |
| 774 | const char *buf, |
| 775 | size_t n) |
| 776 | { |
Kenji Kaneshige | 430842e | 2009-05-13 12:20:10 +0900 | [diff] [blame] | 777 | struct pci_dev *pdev = to_pci_dev(dev); |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 778 | int state; |
| 779 | |
| 780 | if (n < 1) |
| 781 | return -EINVAL; |
| 782 | state = buf[0]-'0'; |
| 783 | |
| 784 | down_read(&pci_bus_sem); |
| 785 | mutex_lock(&aspm_lock); |
Kenji Kaneshige | 430842e | 2009-05-13 12:20:10 +0900 | [diff] [blame] | 786 | pcie_set_clkpm_nocheck(pdev->link_state, !!state); |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 787 | mutex_unlock(&aspm_lock); |
| 788 | up_read(&pci_bus_sem); |
| 789 | |
| 790 | return n; |
| 791 | } |
| 792 | |
| 793 | static DEVICE_ATTR(link_state, 0644, link_state_show, link_state_store); |
| 794 | static DEVICE_ATTR(clk_ctl, 0644, clk_ctl_show, clk_ctl_store); |
| 795 | |
| 796 | static char power_group[] = "power"; |
| 797 | void pcie_aspm_create_sysfs_dev_files(struct pci_dev *pdev) |
| 798 | { |
| 799 | struct pcie_link_state *link_state = pdev->link_state; |
| 800 | |
| 801 | if (!pdev->is_pcie || (pdev->pcie_type != PCI_EXP_TYPE_ROOT_PORT && |
| 802 | pdev->pcie_type != PCI_EXP_TYPE_DOWNSTREAM) || !link_state) |
| 803 | return; |
| 804 | |
Kenji Kaneshige | 80bfdbe | 2009-05-13 12:12:43 +0900 | [diff] [blame] | 805 | if (link_state->aspm_support) |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 806 | sysfs_add_file_to_group(&pdev->dev.kobj, |
| 807 | &dev_attr_link_state.attr, power_group); |
Kenji Kaneshige | 4d246e4 | 2009-05-13 12:15:38 +0900 | [diff] [blame] | 808 | if (link_state->clkpm_capable) |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 809 | sysfs_add_file_to_group(&pdev->dev.kobj, |
| 810 | &dev_attr_clk_ctl.attr, power_group); |
| 811 | } |
| 812 | |
| 813 | void pcie_aspm_remove_sysfs_dev_files(struct pci_dev *pdev) |
| 814 | { |
| 815 | struct pcie_link_state *link_state = pdev->link_state; |
| 816 | |
| 817 | if (!pdev->is_pcie || (pdev->pcie_type != PCI_EXP_TYPE_ROOT_PORT && |
| 818 | pdev->pcie_type != PCI_EXP_TYPE_DOWNSTREAM) || !link_state) |
| 819 | return; |
| 820 | |
Kenji Kaneshige | 80bfdbe | 2009-05-13 12:12:43 +0900 | [diff] [blame] | 821 | if (link_state->aspm_support) |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 822 | sysfs_remove_file_from_group(&pdev->dev.kobj, |
| 823 | &dev_attr_link_state.attr, power_group); |
Kenji Kaneshige | 4d246e4 | 2009-05-13 12:15:38 +0900 | [diff] [blame] | 824 | if (link_state->clkpm_capable) |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 825 | sysfs_remove_file_from_group(&pdev->dev.kobj, |
| 826 | &dev_attr_clk_ctl.attr, power_group); |
| 827 | } |
| 828 | #endif |
| 829 | |
| 830 | static int __init pcie_aspm_disable(char *str) |
| 831 | { |
Shaohua Li | d6d3857 | 2008-07-23 10:32:42 +0800 | [diff] [blame] | 832 | if (!strcmp(str, "off")) { |
| 833 | aspm_disabled = 1; |
| 834 | printk(KERN_INFO "PCIe ASPM is disabled\n"); |
| 835 | } else if (!strcmp(str, "force")) { |
| 836 | aspm_force = 1; |
| 837 | printk(KERN_INFO "PCIe ASPM is forcedly enabled\n"); |
| 838 | } |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 839 | return 1; |
| 840 | } |
| 841 | |
Shaohua Li | d6d3857 | 2008-07-23 10:32:42 +0800 | [diff] [blame] | 842 | __setup("pcie_aspm=", pcie_aspm_disable); |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 843 | |
Shaohua Li | 5fde244 | 2008-07-23 10:32:24 +0800 | [diff] [blame] | 844 | void pcie_no_aspm(void) |
| 845 | { |
Shaohua Li | d6d3857 | 2008-07-23 10:32:42 +0800 | [diff] [blame] | 846 | if (!aspm_force) |
| 847 | aspm_disabled = 1; |
Shaohua Li | 5fde244 | 2008-07-23 10:32:24 +0800 | [diff] [blame] | 848 | } |
| 849 | |
Andrew Patterson | 3e1b160 | 2008-11-10 15:30:55 -0700 | [diff] [blame] | 850 | /** |
| 851 | * pcie_aspm_enabled - is PCIe ASPM enabled? |
| 852 | * |
| 853 | * Returns true if ASPM has not been disabled by the command-line option |
| 854 | * pcie_aspm=off. |
| 855 | **/ |
| 856 | int pcie_aspm_enabled(void) |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 857 | { |
Andrew Patterson | 3e1b160 | 2008-11-10 15:30:55 -0700 | [diff] [blame] | 858 | return !aspm_disabled; |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 859 | } |
Andrew Patterson | 3e1b160 | 2008-11-10 15:30:55 -0700 | [diff] [blame] | 860 | EXPORT_SYMBOL(pcie_aspm_enabled); |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 861 | |