direct-io.hg

view linux-2.6-xen-sparse/drivers/xen/pciback/conf_space_quirks.c @ 14330:a6316fc7a87f

pci back: Various fixes.

- remove superfluous call to pciback_field_is_dup()
- fix a variable type mismatch in pciback_field_is_dup()
- make readability improvements by using the OFFSET macro
- revises quirk data output via the sysfs quirks node so that
- displayed offset information includes base_offset.

Thanks to Jambunathan K. for giving such specific bug diagnosis.

Signed-off-by: Chris Bookholt <hap10@tycho.ncsc.mil>
author kfraser@localhost.localdomain
date Sat Mar 10 17:01:21 2007 +0000 (2007-03-10)
parents 4c97599398fe
children
line source
1 /*
2 * PCI Backend - Handle special overlays for broken devices.
3 *
4 * Author: Ryan Wilson <hap9@epoch.ncsc.mil>
5 * Author: Chris Bookholt <hap10@epoch.ncsc.mil>
6 */
8 #include <linux/kernel.h>
9 #include <linux/pci.h>
10 #include "pciback.h"
11 #include "conf_space.h"
12 #include "conf_space_quirks.h"
14 LIST_HEAD(pciback_quirks);
16 struct pciback_config_quirk *pciback_find_quirk(struct pci_dev *dev)
17 {
18 struct pciback_config_quirk *tmp_quirk;
20 list_for_each_entry(tmp_quirk, &pciback_quirks, quirks_list)
21 if (pci_match_id(&tmp_quirk->devid, dev))
22 goto out;
23 tmp_quirk = NULL;
24 printk(KERN_DEBUG
25 "quirk didn't match any device pciback knows about\n");
26 out:
27 return tmp_quirk;
28 }
30 static inline void register_quirk(struct pciback_config_quirk *quirk)
31 {
32 list_add_tail(&quirk->quirks_list, &pciback_quirks);
33 }
35 int pciback_field_is_dup(struct pci_dev *dev, unsigned int reg)
36 {
37 int ret = 0;
38 struct pciback_dev_data *dev_data = pci_get_drvdata(dev);
39 struct config_field_entry *cfg_entry;
41 list_for_each_entry(cfg_entry, &dev_data->config_fields, list) {
42 if ( OFFSET(cfg_entry) == reg) {
43 ret = 1;
44 break;
45 }
46 }
47 return ret;
48 }
50 int pciback_config_quirks_add_field(struct pci_dev *dev, struct config_field
51 *field)
52 {
53 int err = 0;
55 switch (field->size) {
56 case 1:
57 field->u.b.read = pciback_read_config_byte;
58 field->u.b.write = pciback_write_config_byte;
59 break;
60 case 2:
61 field->u.w.read = pciback_read_config_word;
62 field->u.w.write = pciback_write_config_word;
63 break;
64 case 4:
65 field->u.dw.read = pciback_read_config_dword;
66 field->u.dw.write = pciback_write_config_dword;
67 break;
68 default:
69 err = -EINVAL;
70 goto out;
71 }
73 pciback_config_add_field(dev, field);
75 out:
76 return err;
77 }
79 int pciback_config_quirks_init(struct pci_dev *dev)
80 {
81 struct pciback_config_quirk *quirk;
82 int ret = 0;
84 quirk = kzalloc(sizeof(*quirk), GFP_ATOMIC);
85 if (!quirk) {
86 ret = -ENOMEM;
87 goto out;
88 }
90 quirk->devid.vendor = dev->vendor;
91 quirk->devid.device = dev->device;
92 quirk->devid.subvendor = dev->subsystem_vendor;
93 quirk->devid.subdevice = dev->subsystem_device;
94 quirk->devid.class = 0;
95 quirk->devid.class_mask = 0;
96 quirk->devid.driver_data = 0UL;
98 quirk->pdev = dev;
100 register_quirk(quirk);
101 out:
102 return ret;
103 }
105 void pciback_config_field_free(struct config_field *field)
106 {
107 kfree(field);
108 }
110 int pciback_config_quirk_release(struct pci_dev *dev)
111 {
112 struct pciback_config_quirk *quirk;
113 int ret = 0;
115 quirk = pciback_find_quirk(dev);
116 if (!quirk) {
117 ret = -ENXIO;
118 goto out;
119 }
121 list_del(&quirk->quirks_list);
122 kfree(quirk);
124 out:
125 return ret;
126 }