diff options
author | Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> | 2011-07-19 19:40:51 -0400 |
---|---|---|
committer | Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> | 2011-07-19 20:58:35 -0400 |
commit | a92336a1176b2119eaa990a1e8bf3109665fdbc6 (patch) | |
tree | af8ac49b47136acddb5320b9a62be2361bfaf99c /drivers/xen/xen-pciback/conf_space_capability.c | |
parent | c288b67b9b4d65790e1a1a1fd982330730b68f46 (diff) |
xen/pciback: Drop two backends, squash and cleanup some code.
- Remove the slot and controller controller backend as they
are not used.
- Document the find pciback_[read|write]_config_[byte|word|dword]
to make it easier to find.
- Collapse the code from conf_space_capability_msi into pciback_ops.c
- Collapse conf_space_capability_[pm|vpd].c in conf_space_capability.c
[and remove the conf_space_capability.h file]
- Rename all visible functions from pciback to xen_pcibk.
- Rename all the printk/pr_info, etc that use the "pciback" to say
"xen-pciback".
- Convert functions that are not referenced outside the code to be
static to save on name space.
- Do the same thing for structures that are internal to the driver.
- Run checkpatch.pl after the renames and fixup its warnings and
fix any compile errors caused by the variable rename
- Cleanup any structs that checkpath.pl commented about or just
look odd.
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Diffstat (limited to 'drivers/xen/xen-pciback/conf_space_capability.c')
-rw-r--r-- | drivers/xen/xen-pciback/conf_space_capability.c | 161 |
1 files changed, 151 insertions, 10 deletions
diff --git a/drivers/xen/xen-pciback/conf_space_capability.c b/drivers/xen/xen-pciback/conf_space_capability.c index 0ea84d6335f4..7f83e9083e9d 100644 --- a/drivers/xen/xen-pciback/conf_space_capability.c +++ b/drivers/xen/xen-pciback/conf_space_capability.c | |||
@@ -9,29 +9,36 @@ | |||
9 | #include <linux/pci.h> | 9 | #include <linux/pci.h> |
10 | #include "pciback.h" | 10 | #include "pciback.h" |
11 | #include "conf_space.h" | 11 | #include "conf_space.h" |
12 | #include "conf_space_capability.h" | ||
13 | 12 | ||
14 | static LIST_HEAD(capabilities); | 13 | static LIST_HEAD(capabilities); |
14 | struct xen_pcibk_config_capability { | ||
15 | struct list_head cap_list; | ||
16 | |||
17 | int capability; | ||
18 | |||
19 | /* If the device has the capability found above, add these fields */ | ||
20 | const struct config_field *fields; | ||
21 | }; | ||
15 | 22 | ||
16 | static const struct config_field caplist_header[] = { | 23 | static const struct config_field caplist_header[] = { |
17 | { | 24 | { |
18 | .offset = PCI_CAP_LIST_ID, | 25 | .offset = PCI_CAP_LIST_ID, |
19 | .size = 2, /* encompass PCI_CAP_LIST_ID & PCI_CAP_LIST_NEXT */ | 26 | .size = 2, /* encompass PCI_CAP_LIST_ID & PCI_CAP_LIST_NEXT */ |
20 | .u.w.read = pciback_read_config_word, | 27 | .u.w.read = xen_pcibk_read_config_word, |
21 | .u.w.write = NULL, | 28 | .u.w.write = NULL, |
22 | }, | 29 | }, |
23 | {} | 30 | {} |
24 | }; | 31 | }; |
25 | 32 | ||
26 | static inline void register_capability(struct pciback_config_capability *cap) | 33 | static inline void register_capability(struct xen_pcibk_config_capability *cap) |
27 | { | 34 | { |
28 | list_add_tail(&cap->cap_list, &capabilities); | 35 | list_add_tail(&cap->cap_list, &capabilities); |
29 | } | 36 | } |
30 | 37 | ||
31 | int pciback_config_capability_add_fields(struct pci_dev *dev) | 38 | int xen_pcibk_config_capability_add_fields(struct pci_dev *dev) |
32 | { | 39 | { |
33 | int err = 0; | 40 | int err = 0; |
34 | struct pciback_config_capability *cap; | 41 | struct xen_pcibk_config_capability *cap; |
35 | int cap_offset; | 42 | int cap_offset; |
36 | 43 | ||
37 | list_for_each_entry(cap, &capabilities, cap_list) { | 44 | list_for_each_entry(cap, &capabilities, cap_list) { |
@@ -40,12 +47,12 @@ int pciback_config_capability_add_fields(struct pci_dev *dev) | |||
40 | dev_dbg(&dev->dev, "Found capability 0x%x at 0x%x\n", | 47 | dev_dbg(&dev->dev, "Found capability 0x%x at 0x%x\n", |
41 | cap->capability, cap_offset); | 48 | cap->capability, cap_offset); |
42 | 49 | ||
43 | err = pciback_config_add_fields_offset(dev, | 50 | err = xen_pcibk_config_add_fields_offset(dev, |
44 | caplist_header, | 51 | caplist_header, |
45 | cap_offset); | 52 | cap_offset); |
46 | if (err) | 53 | if (err) |
47 | goto out; | 54 | goto out; |
48 | err = pciback_config_add_fields_offset(dev, | 55 | err = xen_pcibk_config_add_fields_offset(dev, |
49 | cap->fields, | 56 | cap->fields, |
50 | cap_offset); | 57 | cap_offset); |
51 | if (err) | 58 | if (err) |
@@ -57,10 +64,144 @@ out: | |||
57 | return err; | 64 | return err; |
58 | } | 65 | } |
59 | 66 | ||
60 | int pciback_config_capability_init(void) | 67 | static int vpd_address_write(struct pci_dev *dev, int offset, u16 value, |
68 | void *data) | ||
69 | { | ||
70 | /* Disallow writes to the vital product data */ | ||
71 | if (value & PCI_VPD_ADDR_F) | ||
72 | return PCIBIOS_SET_FAILED; | ||
73 | else | ||
74 | return pci_write_config_word(dev, offset, value); | ||
75 | } | ||
76 | |||
77 | static const struct config_field caplist_vpd[] = { | ||
78 | { | ||
79 | .offset = PCI_VPD_ADDR, | ||
80 | .size = 2, | ||
81 | .u.w.read = xen_pcibk_read_config_word, | ||
82 | .u.w.write = vpd_address_write, | ||
83 | }, | ||
84 | { | ||
85 | .offset = PCI_VPD_DATA, | ||
86 | .size = 4, | ||
87 | .u.dw.read = xen_pcibk_read_config_dword, | ||
88 | .u.dw.write = NULL, | ||
89 | }, | ||
90 | {} | ||
91 | }; | ||
92 | |||
93 | static int pm_caps_read(struct pci_dev *dev, int offset, u16 *value, | ||
94 | void *data) | ||
95 | { | ||
96 | int err; | ||
97 | u16 real_value; | ||
98 | |||
99 | err = pci_read_config_word(dev, offset, &real_value); | ||
100 | if (err) | ||
101 | goto out; | ||
102 | |||
103 | *value = real_value & ~PCI_PM_CAP_PME_MASK; | ||
104 | |||
105 | out: | ||
106 | return err; | ||
107 | } | ||
108 | |||
109 | /* PM_OK_BITS specifies the bits that the driver domain is allowed to change. | ||
110 | * Can't allow driver domain to enable PMEs - they're shared */ | ||
111 | #define PM_OK_BITS (PCI_PM_CTRL_PME_STATUS|PCI_PM_CTRL_DATA_SEL_MASK) | ||
112 | |||
113 | static int pm_ctrl_write(struct pci_dev *dev, int offset, u16 new_value, | ||
114 | void *data) | ||
115 | { | ||
116 | int err; | ||
117 | u16 old_value; | ||
118 | pci_power_t new_state, old_state; | ||
119 | |||
120 | err = pci_read_config_word(dev, offset, &old_value); | ||
121 | if (err) | ||
122 | goto out; | ||
123 | |||
124 | old_state = (pci_power_t)(old_value & PCI_PM_CTRL_STATE_MASK); | ||
125 | new_state = (pci_power_t)(new_value & PCI_PM_CTRL_STATE_MASK); | ||
126 | |||
127 | new_value &= PM_OK_BITS; | ||
128 | if ((old_value & PM_OK_BITS) != new_value) { | ||
129 | new_value = (old_value & ~PM_OK_BITS) | new_value; | ||
130 | err = pci_write_config_word(dev, offset, new_value); | ||
131 | if (err) | ||
132 | goto out; | ||
133 | } | ||
134 | |||
135 | /* Let pci core handle the power management change */ | ||
136 | dev_dbg(&dev->dev, "set power state to %x\n", new_state); | ||
137 | err = pci_set_power_state(dev, new_state); | ||
138 | if (err) { | ||
139 | err = PCIBIOS_SET_FAILED; | ||
140 | goto out; | ||
141 | } | ||
142 | |||
143 | out: | ||
144 | return err; | ||
145 | } | ||
146 | |||
147 | /* Ensure PMEs are disabled */ | ||
148 | static void *pm_ctrl_init(struct pci_dev *dev, int offset) | ||
149 | { | ||
150 | int err; | ||
151 | u16 value; | ||
152 | |||
153 | err = pci_read_config_word(dev, offset, &value); | ||
154 | if (err) | ||
155 | goto out; | ||
156 | |||
157 | if (value & PCI_PM_CTRL_PME_ENABLE) { | ||
158 | value &= ~PCI_PM_CTRL_PME_ENABLE; | ||
159 | err = pci_write_config_word(dev, offset, value); | ||
160 | } | ||
161 | |||
162 | out: | ||
163 | return ERR_PTR(err); | ||
164 | } | ||
165 | |||
166 | static const struct config_field caplist_pm[] = { | ||
167 | { | ||
168 | .offset = PCI_PM_PMC, | ||
169 | .size = 2, | ||
170 | .u.w.read = pm_caps_read, | ||
171 | }, | ||
172 | { | ||
173 | .offset = PCI_PM_CTRL, | ||
174 | .size = 2, | ||
175 | .init = pm_ctrl_init, | ||
176 | .u.w.read = xen_pcibk_read_config_word, | ||
177 | .u.w.write = pm_ctrl_write, | ||
178 | }, | ||
179 | { | ||
180 | .offset = PCI_PM_PPB_EXTENSIONS, | ||
181 | .size = 1, | ||
182 | .u.b.read = xen_pcibk_read_config_byte, | ||
183 | }, | ||
184 | { | ||
185 | .offset = PCI_PM_DATA_REGISTER, | ||
186 | .size = 1, | ||
187 | .u.b.read = xen_pcibk_read_config_byte, | ||
188 | }, | ||
189 | {} | ||
190 | }; | ||
191 | |||
192 | static struct xen_pcibk_config_capability xen_pcibk_config_capability_pm = { | ||
193 | .capability = PCI_CAP_ID_PM, | ||
194 | .fields = caplist_pm, | ||
195 | }; | ||
196 | static struct xen_pcibk_config_capability xen_pcibk_config_capability_vpd = { | ||
197 | .capability = PCI_CAP_ID_VPD, | ||
198 | .fields = caplist_vpd, | ||
199 | }; | ||
200 | |||
201 | int xen_pcibk_config_capability_init(void) | ||
61 | { | 202 | { |
62 | register_capability(&pciback_config_capability_vpd); | 203 | register_capability(&xen_pcibk_config_capability_vpd); |
63 | register_capability(&pciback_config_capability_pm); | 204 | register_capability(&xen_pcibk_config_capability_pm); |
64 | 205 | ||
65 | return 0; | 206 | return 0; |
66 | } | 207 | } |