xen/pciback: Print out the MSI/MSI-X (PIRQ) values
[pandora-kernel.git] / drivers / xen / xen-pciback / conf_space_capability_pm.c
1 /*
2  * PCI Backend - Configuration space overlay for power management
3  *
4  * Author: Ryan Wilson <hap9@epoch.ncsc.mil>
5  */
6
7 #include <linux/pci.h>
8 #include "conf_space.h"
9 #include "conf_space_capability.h"
10
11 static int pm_caps_read(struct pci_dev *dev, int offset, u16 *value,
12                         void *data)
13 {
14         int err;
15         u16 real_value;
16
17         err = pci_read_config_word(dev, offset, &real_value);
18         if (err)
19                 goto out;
20
21         *value = real_value & ~PCI_PM_CAP_PME_MASK;
22
23 out:
24         return err;
25 }
26
27 /* PM_OK_BITS specifies the bits that the driver domain is allowed to change.
28  * Can't allow driver domain to enable PMEs - they're shared */
29 #define PM_OK_BITS (PCI_PM_CTRL_PME_STATUS|PCI_PM_CTRL_DATA_SEL_MASK)
30
31 static int pm_ctrl_write(struct pci_dev *dev, int offset, u16 new_value,
32                          void *data)
33 {
34         int err;
35         u16 old_value;
36         pci_power_t new_state, old_state;
37
38         err = pci_read_config_word(dev, offset, &old_value);
39         if (err)
40                 goto out;
41
42         old_state = (pci_power_t)(old_value & PCI_PM_CTRL_STATE_MASK);
43         new_state = (pci_power_t)(new_value & PCI_PM_CTRL_STATE_MASK);
44
45         new_value &= PM_OK_BITS;
46         if ((old_value & PM_OK_BITS) != new_value) {
47                 new_value = (old_value & ~PM_OK_BITS) | new_value;
48                 err = pci_write_config_word(dev, offset, new_value);
49                 if (err)
50                         goto out;
51         }
52
53         /* Let pci core handle the power management change */
54         dev_dbg(&dev->dev, "set power state to %x\n", new_state);
55         err = pci_set_power_state(dev, new_state);
56         if (err) {
57                 err = PCIBIOS_SET_FAILED;
58                 goto out;
59         }
60
61  out:
62         return err;
63 }
64
65 /* Ensure PMEs are disabled */
66 static void *pm_ctrl_init(struct pci_dev *dev, int offset)
67 {
68         int err;
69         u16 value;
70
71         err = pci_read_config_word(dev, offset, &value);
72         if (err)
73                 goto out;
74
75         if (value & PCI_PM_CTRL_PME_ENABLE) {
76                 value &= ~PCI_PM_CTRL_PME_ENABLE;
77                 err = pci_write_config_word(dev, offset, value);
78         }
79
80 out:
81         return ERR_PTR(err);
82 }
83
84 static const struct config_field caplist_pm[] = {
85         {
86                 .offset     = PCI_PM_PMC,
87                 .size       = 2,
88                 .u.w.read   = pm_caps_read,
89         },
90         {
91                 .offset     = PCI_PM_CTRL,
92                 .size       = 2,
93                 .init       = pm_ctrl_init,
94                 .u.w.read   = pciback_read_config_word,
95                 .u.w.write  = pm_ctrl_write,
96         },
97         {
98                 .offset     = PCI_PM_PPB_EXTENSIONS,
99                 .size       = 1,
100                 .u.b.read   = pciback_read_config_byte,
101         },
102         {
103                 .offset     = PCI_PM_DATA_REGISTER,
104                 .size       = 1,
105                 .u.b.read   = pciback_read_config_byte,
106         },
107         {}
108 };
109
110 struct pciback_config_capability pciback_config_capability_pm = {
111         .capability = PCI_CAP_ID_PM,
112         .fields = caplist_pm,
113 };