2 * File: drivers/pci/pcie/aspm.c
3 * Enabling PCIE link L0s/L1 state and Clock Power Management
5 * Copyright (C) 2007 Intel
6 * Copyright (C) Zhang Yanmin (yanmin.zhang@intel.com)
7 * Copyright (C) Shaohua Li (shaohua.li@intel.com)
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>
17 #include <linux/init.h>
18 #include <linux/slab.h>
19 #include <linux/jiffies.h>
20 #include <linux/pci-aspm.h>
23 #ifdef MODULE_PARAM_PREFIX
24 #undef MODULE_PARAM_PREFIX
26 #define MODULE_PARAM_PREFIX "pcie_aspm."
28 struct endpoint_state {
29 unsigned int l0s_acceptable_latency;
30 unsigned int l1_acceptable_latency;
33 struct pcie_link_state {
34 struct list_head sibiling;
38 unsigned int support_state;
39 unsigned int enabled_state;
40 unsigned int bios_aspm_state;
41 /* upstream component */
42 unsigned int l0s_upper_latency;
43 unsigned int l1_upper_latency;
44 /* downstream component */
45 unsigned int l0s_down_latency;
46 unsigned int l1_down_latency;
48 unsigned int clk_pm_capable;
49 unsigned int clk_pm_enabled;
50 unsigned int bios_clk_state;
53 * A pcie downstream port only has one slot under it, so at most there
56 struct endpoint_state endpoints[8];
59 static int aspm_disabled, aspm_force;
60 static DEFINE_MUTEX(aspm_lock);
61 static LIST_HEAD(link_list);
63 #define POLICY_DEFAULT 0 /* BIOS default setting */
64 #define POLICY_PERFORMANCE 1 /* high performance */
65 #define POLICY_POWERSAVE 2 /* high power saving */
66 static int aspm_policy;
67 static const char *policy_str[] = {
68 [POLICY_DEFAULT] = "default",
69 [POLICY_PERFORMANCE] = "performance",
70 [POLICY_POWERSAVE] = "powersave"
73 static int policy_to_aspm_state(struct pci_dev *pdev)
75 struct pcie_link_state *link_state = pdev->link_state;
77 switch (aspm_policy) {
78 case POLICY_PERFORMANCE:
79 /* Disable ASPM and Clock PM */
81 case POLICY_POWERSAVE:
82 /* Enable ASPM L0s/L1 */
83 return PCIE_LINK_STATE_L0S|PCIE_LINK_STATE_L1;
85 return link_state->bios_aspm_state;
90 static int policy_to_clkpm_state(struct pci_dev *pdev)
92 struct pcie_link_state *link_state = pdev->link_state;
94 switch (aspm_policy) {
95 case POLICY_PERFORMANCE:
96 /* Disable ASPM and Clock PM */
98 case POLICY_POWERSAVE:
99 /* Disable Clock PM */
102 return link_state->bios_clk_state;
107 static void pcie_set_clock_pm(struct pci_dev *pdev, int enable)
109 struct pci_dev *child_dev;
112 struct pcie_link_state *link_state = pdev->link_state;
114 list_for_each_entry(child_dev, &pdev->subordinate->devices, bus_list) {
115 pos = pci_find_capability(child_dev, PCI_CAP_ID_EXP);
118 pci_read_config_word(child_dev, pos + PCI_EXP_LNKCTL, ®16);
120 reg16 |= PCI_EXP_LNKCTL_CLKREQ_EN;
122 reg16 &= ~PCI_EXP_LNKCTL_CLKREQ_EN;
123 pci_write_config_word(child_dev, pos + PCI_EXP_LNKCTL, reg16);
125 link_state->clk_pm_enabled = !!enable;
128 static void pcie_check_clock_pm(struct pci_dev *pdev)
133 int capable = 1, enabled = 1;
134 struct pci_dev *child_dev;
135 struct pcie_link_state *link_state = pdev->link_state;
137 /* All functions should have the same cap and state, take the worst */
138 list_for_each_entry(child_dev, &pdev->subordinate->devices, bus_list) {
139 pos = pci_find_capability(child_dev, PCI_CAP_ID_EXP);
142 pci_read_config_dword(child_dev, pos + PCI_EXP_LNKCAP, ®32);
143 if (!(reg32 & PCI_EXP_LNKCAP_CLKPM)) {
148 pci_read_config_word(child_dev, pos + PCI_EXP_LNKCTL, ®16);
149 if (!(reg16 & PCI_EXP_LNKCTL_CLKREQ_EN))
152 link_state->clk_pm_capable = capable;
153 link_state->clk_pm_enabled = enabled;
154 link_state->bios_clk_state = enabled;
155 pcie_set_clock_pm(pdev, policy_to_clkpm_state(pdev));
159 * pcie_aspm_configure_common_clock: check if the 2 ends of a link
160 * could use common clock. If they are, configure them to use the
161 * common clock. That will reduce the ASPM state exit latency.
163 static void pcie_aspm_configure_common_clock(struct pci_dev *pdev)
165 int pos, child_pos, i = 0;
167 struct pci_dev *child_dev;
169 unsigned long start_jiffies;
170 u16 child_regs[8], parent_reg;
172 * all functions of a slot should have the same Slot Clock
173 * Configuration, so just check one function
175 child_dev = list_entry(pdev->subordinate->devices.next, struct pci_dev,
177 BUG_ON(!child_dev->is_pcie);
179 /* Check downstream component if bit Slot Clock Configuration is 1 */
180 child_pos = pci_find_capability(child_dev, PCI_CAP_ID_EXP);
181 pci_read_config_word(child_dev, child_pos + PCI_EXP_LNKSTA, ®16);
182 if (!(reg16 & PCI_EXP_LNKSTA_SLC))
185 /* Check upstream component if bit Slot Clock Configuration is 1 */
186 pos = pci_find_capability(pdev, PCI_CAP_ID_EXP);
187 pci_read_config_word(pdev, pos + PCI_EXP_LNKSTA, ®16);
188 if (!(reg16 & PCI_EXP_LNKSTA_SLC))
191 /* Configure downstream component, all functions */
192 list_for_each_entry(child_dev, &pdev->subordinate->devices, bus_list) {
193 child_pos = pci_find_capability(child_dev, PCI_CAP_ID_EXP);
194 pci_read_config_word(child_dev, child_pos + PCI_EXP_LNKCTL,
196 child_regs[i] = reg16;
198 reg16 |= PCI_EXP_LNKCTL_CCC;
200 reg16 &= ~PCI_EXP_LNKCTL_CCC;
201 pci_write_config_word(child_dev, child_pos + PCI_EXP_LNKCTL,
206 /* Configure upstream component */
207 pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, ®16);
210 reg16 |= PCI_EXP_LNKCTL_CCC;
212 reg16 &= ~PCI_EXP_LNKCTL_CCC;
213 pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, reg16);
216 reg16 |= PCI_EXP_LNKCTL_RL;
217 pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, reg16);
219 /* Wait for link training end */
220 /* break out after waiting for 1 second */
221 start_jiffies = jiffies;
222 while ((jiffies - start_jiffies) < HZ) {
223 pci_read_config_word(pdev, pos + PCI_EXP_LNKSTA, ®16);
224 if (!(reg16 & PCI_EXP_LNKSTA_LT))
228 /* training failed -> recover */
229 if ((jiffies - start_jiffies) >= HZ) {
230 dev_printk (KERN_ERR, &pdev->dev, "ASPM: Could not configure"
233 list_for_each_entry(child_dev, &pdev->subordinate->devices,
235 child_pos = pci_find_capability(child_dev,
237 pci_write_config_word(child_dev,
238 child_pos + PCI_EXP_LNKCTL,
242 pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, parent_reg);
247 * calc_L0S_latency: Convert L0s latency encoding to ns
249 static unsigned int calc_L0S_latency(unsigned int latency_encoding, int ac)
251 unsigned int ns = 64;
253 if (latency_encoding == 0x7) {
257 ns = 5*1000; /* > 4us */
259 ns *= (1 << latency_encoding);
264 * calc_L1_latency: Convert L1 latency encoding to ns
266 static unsigned int calc_L1_latency(unsigned int latency_encoding, int ac)
268 unsigned int ns = 1000;
270 if (latency_encoding == 0x7) {
274 ns = 65*1000; /* > 64us */
276 ns *= (1 << latency_encoding);
280 static void pcie_aspm_get_cap_device(struct pci_dev *pdev, u32 *state,
281 unsigned int *l0s, unsigned int *l1, unsigned int *enabled)
286 unsigned int latency;
288 pos = pci_find_capability(pdev, PCI_CAP_ID_EXP);
289 pci_read_config_dword(pdev, pos + PCI_EXP_LNKCAP, ®32);
290 *state = (reg32 & PCI_EXP_LNKCAP_ASPMS) >> 10;
291 if (*state != PCIE_LINK_STATE_L0S &&
292 *state != (PCIE_LINK_STATE_L1|PCIE_LINK_STATE_L0S))
297 latency = (reg32 & PCI_EXP_LNKCAP_L0SEL) >> 12;
298 *l0s = calc_L0S_latency(latency, 0);
299 if (*state & PCIE_LINK_STATE_L1) {
300 latency = (reg32 & PCI_EXP_LNKCAP_L1EL) >> 15;
301 *l1 = calc_L1_latency(latency, 0);
303 pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, ®16);
304 *enabled = reg16 & (PCIE_LINK_STATE_L0S|PCIE_LINK_STATE_L1);
307 static void pcie_aspm_cap_init(struct pci_dev *pdev)
309 struct pci_dev *child_dev;
311 struct pcie_link_state *link_state = pdev->link_state;
313 /* upstream component states */
314 pcie_aspm_get_cap_device(pdev, &link_state->support_state,
315 &link_state->l0s_upper_latency,
316 &link_state->l1_upper_latency,
317 &link_state->enabled_state);
318 /* downstream component states, all functions have the same setting */
319 child_dev = list_entry(pdev->subordinate->devices.next, struct pci_dev,
321 pcie_aspm_get_cap_device(child_dev, &state,
322 &link_state->l0s_down_latency,
323 &link_state->l1_down_latency,
325 link_state->support_state &= state;
326 if (!link_state->support_state)
328 link_state->enabled_state &= link_state->support_state;
329 link_state->bios_aspm_state = link_state->enabled_state;
332 list_for_each_entry(child_dev, &pdev->subordinate->devices, bus_list) {
335 unsigned int latency;
336 struct endpoint_state *ep_state =
337 &link_state->endpoints[PCI_FUNC(child_dev->devfn)];
339 if (child_dev->pcie_type != PCI_EXP_TYPE_ENDPOINT &&
340 child_dev->pcie_type != PCI_EXP_TYPE_LEG_END)
343 pos = pci_find_capability(child_dev, PCI_CAP_ID_EXP);
344 pci_read_config_dword(child_dev, pos + PCI_EXP_DEVCAP, ®32);
345 latency = (reg32 & PCI_EXP_DEVCAP_L0S) >> 6;
346 latency = calc_L0S_latency(latency, 1);
347 ep_state->l0s_acceptable_latency = latency;
348 if (link_state->support_state & PCIE_LINK_STATE_L1) {
349 latency = (reg32 & PCI_EXP_DEVCAP_L1) >> 9;
350 latency = calc_L1_latency(latency, 1);
351 ep_state->l1_acceptable_latency = latency;
356 static unsigned int __pcie_aspm_check_state_one(struct pci_dev *pdev,
359 struct pci_dev *parent_dev, *tmp_dev;
360 unsigned int latency, l1_latency = 0;
361 struct pcie_link_state *link_state;
362 struct endpoint_state *ep_state;
364 parent_dev = pdev->bus->self;
365 link_state = parent_dev->link_state;
366 state &= link_state->support_state;
369 ep_state = &link_state->endpoints[PCI_FUNC(pdev->devfn)];
372 * Check latency for endpoint device.
373 * TBD: The latency from the endpoint to root complex vary per
374 * switch's upstream link state above the device. Here we just do a
375 * simple check which assumes all links above the device can be in L1
376 * state, that is we just consider the worst case. If switch's upstream
377 * link can't be put into L0S/L1, then our check is too strictly.
380 while (state & (PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1)) {
381 parent_dev = tmp_dev->bus->self;
382 link_state = parent_dev->link_state;
383 if (state & PCIE_LINK_STATE_L0S) {
384 latency = max_t(unsigned int,
385 link_state->l0s_upper_latency,
386 link_state->l0s_down_latency);
387 if (latency > ep_state->l0s_acceptable_latency)
388 state &= ~PCIE_LINK_STATE_L0S;
390 if (state & PCIE_LINK_STATE_L1) {
391 latency = max_t(unsigned int,
392 link_state->l1_upper_latency,
393 link_state->l1_down_latency);
394 if (latency + l1_latency >
395 ep_state->l1_acceptable_latency)
396 state &= ~PCIE_LINK_STATE_L1;
398 if (!parent_dev->bus->self) /* parent_dev is a root port */
402 * parent_dev is the downstream port of a switch, make
403 * tmp_dev the upstream port of the switch
405 tmp_dev = parent_dev->bus->self;
407 * every switch on the path to root complex need 1 more
408 * microsecond for L1. Spec doesn't mention L0S.
410 if (state & PCIE_LINK_STATE_L1)
417 static unsigned int pcie_aspm_check_state(struct pci_dev *pdev,
420 struct pci_dev *child_dev;
422 /* If no child, disable the link */
423 if (list_empty(&pdev->subordinate->devices))
425 list_for_each_entry(child_dev, &pdev->subordinate->devices, bus_list) {
426 if (child_dev->pcie_type == PCI_EXP_TYPE_PCI_BRIDGE) {
428 * If downstream component of a link is pci bridge, we
429 * disable ASPM for now for the link
434 if ((child_dev->pcie_type != PCI_EXP_TYPE_ENDPOINT &&
435 child_dev->pcie_type != PCI_EXP_TYPE_LEG_END))
437 /* Device not in D0 doesn't need check latency */
438 if (child_dev->current_state == PCI_D1 ||
439 child_dev->current_state == PCI_D2 ||
440 child_dev->current_state == PCI_D3hot ||
441 child_dev->current_state == PCI_D3cold)
443 state = __pcie_aspm_check_state_one(child_dev, state);
448 static void __pcie_aspm_config_one_dev(struct pci_dev *pdev, unsigned int state)
451 int pos = pci_find_capability(pdev, PCI_CAP_ID_EXP);
453 pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, ®16);
456 pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, reg16);
459 static void __pcie_aspm_config_link(struct pci_dev *pdev, unsigned int state)
461 struct pci_dev *child_dev;
463 struct pcie_link_state *link_state = pdev->link_state;
466 * if the downstream component has pci bridge function, don't do ASPM
469 list_for_each_entry(child_dev, &pdev->subordinate->devices, bus_list) {
470 if (child_dev->pcie_type == PCI_EXP_TYPE_PCI_BRIDGE) {
479 * spec 2.0 suggests all functions should be configured the same
480 * setting for ASPM. Enabling ASPM L1 should be done in upstream
481 * component first and then downstream, and vice versa for disabling
482 * ASPM L1. Spec doesn't mention L0S.
484 if (state & PCIE_LINK_STATE_L1)
485 __pcie_aspm_config_one_dev(pdev, state);
487 list_for_each_entry(child_dev, &pdev->subordinate->devices, bus_list)
488 __pcie_aspm_config_one_dev(child_dev, state);
490 if (!(state & PCIE_LINK_STATE_L1))
491 __pcie_aspm_config_one_dev(pdev, state);
493 link_state->enabled_state = state;
496 static void __pcie_aspm_configure_link_state(struct pci_dev *pdev,
499 struct pcie_link_state *link_state = pdev->link_state;
501 if (link_state->support_state == 0)
503 state &= PCIE_LINK_STATE_L0S|PCIE_LINK_STATE_L1;
505 /* state 0 means disabling aspm */
506 state = pcie_aspm_check_state(pdev, state);
507 if (link_state->enabled_state == state)
509 __pcie_aspm_config_link(pdev, state);
513 * pcie_aspm_configure_link_state: enable/disable PCI express link state
514 * @pdev: the root port or switch downstream port
516 static void pcie_aspm_configure_link_state(struct pci_dev *pdev,
519 down_read(&pci_bus_sem);
520 mutex_lock(&aspm_lock);
521 __pcie_aspm_configure_link_state(pdev, state);
522 mutex_unlock(&aspm_lock);
523 up_read(&pci_bus_sem);
526 static void free_link_state(struct pci_dev *pdev)
528 kfree(pdev->link_state);
529 pdev->link_state = NULL;
532 static int pcie_aspm_sanity_check(struct pci_dev *pdev)
534 struct pci_dev *child_dev;
539 * Some functions in a slot might not all be PCIE functions, very
540 * strange. Disable ASPM for the whole slot
542 list_for_each_entry(child_dev, &pdev->subordinate->devices, bus_list) {
543 child_pos = pci_find_capability(child_dev, PCI_CAP_ID_EXP);
548 * Disable ASPM for pre-1.1 PCIe device, we follow MS to use
549 * RBER bit to determine if a function is 1.1 version device
551 pci_read_config_dword(child_dev, child_pos + PCI_EXP_DEVCAP,
553 if (!(reg32 & PCI_EXP_DEVCAP_RBER) && !aspm_force) {
554 dev_printk(KERN_INFO, &child_dev->dev, "disabling ASPM"
555 " on pre-1.1 PCIe device. You can enable it"
556 " with 'pcie_aspm=force'\n");
564 * pcie_aspm_init_link_state: Initiate PCI express link state.
565 * It is called after the pcie and its children devices are scaned.
566 * @pdev: the root port or switch downstream port
568 void pcie_aspm_init_link_state(struct pci_dev *pdev)
571 struct pcie_link_state *link_state;
574 if (aspm_disabled || !pdev->is_pcie || pdev->link_state)
576 if (pdev->pcie_type != PCI_EXP_TYPE_ROOT_PORT &&
577 pdev->pcie_type != PCI_EXP_TYPE_DOWNSTREAM)
579 down_read(&pci_bus_sem);
580 if (list_empty(&pdev->subordinate->devices))
583 if (pcie_aspm_sanity_check(pdev))
586 mutex_lock(&aspm_lock);
588 link_state = kzalloc(sizeof(*link_state), GFP_KERNEL);
591 pdev->link_state = link_state;
593 pcie_aspm_configure_common_clock(pdev);
595 pcie_aspm_cap_init(pdev);
597 /* config link state to avoid BIOS error */
598 state = pcie_aspm_check_state(pdev, policy_to_aspm_state(pdev));
599 __pcie_aspm_config_link(pdev, state);
601 pcie_check_clock_pm(pdev);
603 link_state->pdev = pdev;
604 list_add(&link_state->sibiling, &link_list);
608 free_link_state(pdev);
609 mutex_unlock(&aspm_lock);
611 up_read(&pci_bus_sem);
614 /* @pdev: the endpoint device */
615 void pcie_aspm_exit_link_state(struct pci_dev *pdev)
617 struct pci_dev *parent = pdev->bus->self;
618 struct pcie_link_state *link_state = parent->link_state;
620 if (aspm_disabled || !pdev->is_pcie || !parent || !link_state)
622 if (parent->pcie_type != PCI_EXP_TYPE_ROOT_PORT &&
623 parent->pcie_type != PCI_EXP_TYPE_DOWNSTREAM)
625 down_read(&pci_bus_sem);
626 mutex_lock(&aspm_lock);
629 * All PCIe functions are in one slot, remove one function will remove
630 * the the whole slot, so just wait
632 if (!list_empty(&parent->subordinate->devices))
635 /* All functions are removed, so just disable ASPM for the link */
636 __pcie_aspm_config_one_dev(parent, 0);
637 list_del(&link_state->sibiling);
638 /* Clock PM is for endpoint device */
640 free_link_state(parent);
642 mutex_unlock(&aspm_lock);
643 up_read(&pci_bus_sem);
646 /* @pdev: the root port or switch downstream port */
647 void pcie_aspm_pm_state_change(struct pci_dev *pdev)
649 struct pcie_link_state *link_state = pdev->link_state;
651 if (aspm_disabled || !pdev->is_pcie || !pdev->link_state)
653 if (pdev->pcie_type != PCI_EXP_TYPE_ROOT_PORT &&
654 pdev->pcie_type != PCI_EXP_TYPE_DOWNSTREAM)
657 * devices changed PM state, we should recheck if latency meets all
658 * functions' requirement
660 pcie_aspm_configure_link_state(pdev, link_state->enabled_state);
664 * pci_disable_link_state - disable pci device's link state, so the link will
665 * never enter specific states
667 void pci_disable_link_state(struct pci_dev *pdev, int state)
669 struct pci_dev *parent = pdev->bus->self;
670 struct pcie_link_state *link_state;
672 if (aspm_disabled || !pdev->is_pcie)
674 if (pdev->pcie_type == PCI_EXP_TYPE_ROOT_PORT ||
675 pdev->pcie_type == PCI_EXP_TYPE_DOWNSTREAM)
677 if (!parent || !parent->link_state)
680 down_read(&pci_bus_sem);
681 mutex_lock(&aspm_lock);
682 link_state = parent->link_state;
683 link_state->support_state &=
684 ~(state & (PCIE_LINK_STATE_L0S|PCIE_LINK_STATE_L1));
685 if (state & PCIE_LINK_STATE_CLKPM)
686 link_state->clk_pm_capable = 0;
688 __pcie_aspm_configure_link_state(parent, link_state->enabled_state);
689 if (!link_state->clk_pm_capable && link_state->clk_pm_enabled)
690 pcie_set_clock_pm(parent, 0);
691 mutex_unlock(&aspm_lock);
692 up_read(&pci_bus_sem);
694 EXPORT_SYMBOL(pci_disable_link_state);
696 static int pcie_aspm_set_policy(const char *val, struct kernel_param *kp)
699 struct pci_dev *pdev;
700 struct pcie_link_state *link_state;
702 for (i = 0; i < ARRAY_SIZE(policy_str); i++)
703 if (!strncmp(val, policy_str[i], strlen(policy_str[i])))
705 if (i >= ARRAY_SIZE(policy_str))
707 if (i == aspm_policy)
710 down_read(&pci_bus_sem);
711 mutex_lock(&aspm_lock);
713 list_for_each_entry(link_state, &link_list, sibiling) {
714 pdev = link_state->pdev;
715 __pcie_aspm_configure_link_state(pdev,
716 policy_to_aspm_state(pdev));
717 if (link_state->clk_pm_capable &&
718 link_state->clk_pm_enabled != policy_to_clkpm_state(pdev))
719 pcie_set_clock_pm(pdev, policy_to_clkpm_state(pdev));
722 mutex_unlock(&aspm_lock);
723 up_read(&pci_bus_sem);
727 static int pcie_aspm_get_policy(char *buffer, struct kernel_param *kp)
730 for (i = 0; i < ARRAY_SIZE(policy_str); i++)
731 if (i == aspm_policy)
732 cnt += sprintf(buffer + cnt, "[%s] ", policy_str[i]);
734 cnt += sprintf(buffer + cnt, "%s ", policy_str[i]);
738 module_param_call(policy, pcie_aspm_set_policy, pcie_aspm_get_policy,
741 #ifdef CONFIG_PCIEASPM_DEBUG
742 static ssize_t link_state_show(struct device *dev,
743 struct device_attribute *attr,
746 struct pci_dev *pci_device = to_pci_dev(dev);
747 struct pcie_link_state *link_state = pci_device->link_state;
749 return sprintf(buf, "%d\n", link_state->enabled_state);
752 static ssize_t link_state_store(struct device *dev,
753 struct device_attribute *attr,
757 struct pci_dev *pci_device = to_pci_dev(dev);
763 if (state >= 0 && state <= 3) {
764 /* setup link aspm state */
765 pcie_aspm_configure_link_state(pci_device, state);
772 static ssize_t clk_ctl_show(struct device *dev,
773 struct device_attribute *attr,
776 struct pci_dev *pci_device = to_pci_dev(dev);
777 struct pcie_link_state *link_state = pci_device->link_state;
779 return sprintf(buf, "%d\n", link_state->clk_pm_enabled);
782 static ssize_t clk_ctl_store(struct device *dev,
783 struct device_attribute *attr,
787 struct pci_dev *pci_device = to_pci_dev(dev);
794 down_read(&pci_bus_sem);
795 mutex_lock(&aspm_lock);
796 pcie_set_clock_pm(pci_device, !!state);
797 mutex_unlock(&aspm_lock);
798 up_read(&pci_bus_sem);
803 static DEVICE_ATTR(link_state, 0644, link_state_show, link_state_store);
804 static DEVICE_ATTR(clk_ctl, 0644, clk_ctl_show, clk_ctl_store);
806 static char power_group[] = "power";
807 void pcie_aspm_create_sysfs_dev_files(struct pci_dev *pdev)
809 struct pcie_link_state *link_state = pdev->link_state;
811 if (!pdev->is_pcie || (pdev->pcie_type != PCI_EXP_TYPE_ROOT_PORT &&
812 pdev->pcie_type != PCI_EXP_TYPE_DOWNSTREAM) || !link_state)
815 if (link_state->support_state)
816 sysfs_add_file_to_group(&pdev->dev.kobj,
817 &dev_attr_link_state.attr, power_group);
818 if (link_state->clk_pm_capable)
819 sysfs_add_file_to_group(&pdev->dev.kobj,
820 &dev_attr_clk_ctl.attr, power_group);
823 void pcie_aspm_remove_sysfs_dev_files(struct pci_dev *pdev)
825 struct pcie_link_state *link_state = pdev->link_state;
827 if (!pdev->is_pcie || (pdev->pcie_type != PCI_EXP_TYPE_ROOT_PORT &&
828 pdev->pcie_type != PCI_EXP_TYPE_DOWNSTREAM) || !link_state)
831 if (link_state->support_state)
832 sysfs_remove_file_from_group(&pdev->dev.kobj,
833 &dev_attr_link_state.attr, power_group);
834 if (link_state->clk_pm_capable)
835 sysfs_remove_file_from_group(&pdev->dev.kobj,
836 &dev_attr_clk_ctl.attr, power_group);
840 static int __init pcie_aspm_disable(char *str)
842 if (!strcmp(str, "off")) {
844 printk(KERN_INFO "PCIe ASPM is disabled\n");
845 } else if (!strcmp(str, "force")) {
847 printk(KERN_INFO "PCIe ASPM is forcedly enabled\n");
852 __setup("pcie_aspm=", pcie_aspm_disable);
854 void pcie_no_aspm(void)
861 * pcie_aspm_enabled - is PCIe ASPM enabled?
863 * Returns true if ASPM has not been disabled by the command-line option
866 int pcie_aspm_enabled(void)
868 return !aspm_disabled;
870 EXPORT_SYMBOL(pcie_aspm_enabled);