12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <linux/pci.h>
19 static bool permissive;
24 #define DEFINE_PCI_CONFIG(op, size, type) \
25 int xen_pcibk_##op##_config_##size \
26 (struct pci_dev *dev, int offset, type value, void *data) \
28 return pci_##op##_config_##size(dev, offset, value); \
48 switch (field->
size) {
51 ret = field->
u.
b.read(dev, offset, (
u8 *) value,
56 ret = field->
u.
w.read(dev, offset, (
u16 *) value,
61 ret = field->
u.
dw.read(dev, offset, value, entry->data);
67 static int conf_space_write(
struct pci_dev *
dev,
74 switch (field->
size) {
77 ret = field->
u.
b.write(dev, offset, (
u8) value,
82 ret = field->
u.
w.write(dev, offset, (
u16) value,
86 if (field->
u.
dw.write)
87 ret = field->
u.
dw.write(dev, offset, value,
94 static inline u32 get_mask(
int size)
104 static inline int valid_request(
int offset,
int size)
107 if ((size == 1 || size == 2 || size == 4) && (offset % size) == 0)
116 new_val_mask <<= (offset * 8);
117 new_val <<= (offset * 8);
119 new_val_mask >>= (offset * -8);
120 new_val >>= (offset * -8);
122 val = (val & ~new_val_mask) | (new_val & new_val_mask);
127 static int xen_pcibios_err_to_errno(
int err)
151 int req_start, req_end, field_start, field_end;
154 u32 value = 0, tmp_val;
158 pci_name(dev), size, offset);
160 if (!valid_request(offset, size)) {
168 err = pci_read_config_byte(dev, offset, (
u8 *) &value);
171 err = pci_read_config_word(dev, offset, (
u16 *) &value);
174 err = pci_read_config_dword(dev, offset, &value);
179 field = cfg_entry->
field;
182 req_end = offset +
size;
183 field_start =
OFFSET(cfg_entry);
186 if ((req_start >= field_start && req_start < field_end)
187 || (req_end > field_start && req_end <= field_end)) {
188 err = conf_space_read(dev, cfg_entry, field_start,
193 value = merge_value(value, tmp_val,
194 get_mask(field->
size),
195 field_start - req_start);
202 pci_name(dev), size, offset, value);
205 return xen_pcibios_err_to_errno(err);
210 int err = 0, handled = 0;
215 int req_start, req_end, field_start, field_end;
219 DRV_NAME ": %s: write request %d bytes at 0x%x = %x\n",
220 pci_name(dev), size, offset, value);
222 if (!valid_request(offset, size))
226 field = cfg_entry->
field;
229 req_end = offset +
size;
230 field_start =
OFFSET(cfg_entry);
233 if ((req_start >= field_start && req_start < field_end)
234 || (req_end > field_start && req_end <= field_end)) {
238 field->
size, &tmp_val);
242 tmp_val = merge_value(tmp_val, value, get_mask(size),
243 req_start - field_start);
245 err = conf_space_write(dev, cfg_entry, field_start,
258 if (!handled && !err) {
268 err = pci_write_config_byte(dev, offset,
272 err = pci_write_config_word(dev, offset,
276 err = pci_write_config_dword(dev, offset,
283 "read-only configuration space field at offset"
284 " 0x%x, size %d. This may be harmless, but if "
285 "you have problems with your device:\n"
286 "1) see permissive attribute in sysfs\n"
287 "2) report problems to the xen-devel "
288 "mailing list along with details of your "
289 "device obtained from lspci.\n", offset, size);
293 return xen_pcibios_err_to_errno(err);
302 dev_dbg(&dev->
dev,
"free-ing dynamically allocated virtual "
303 "configuration space fields\n");
308 field = cfg_entry->
field;
328 dev_dbg(&dev->
dev,
"resetting virtual configuration space\n");
333 field = cfg_entry->
field;
346 dev_dbg(&dev->
dev,
"free-ing virtual configuration space fields\n");
353 field = cfg_entry->
field;
397 dev_dbg(&dev->
dev,
"added config field at offset 0x%02x\n",
417 dev_dbg(&dev->
dev,
"initializing virtual configuration space\n");