aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/xen/xen-pciback
diff options
context:
space:
mode:
authorKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>2011-07-19 19:40:51 -0400
committerKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>2011-07-19 20:58:35 -0400
commita92336a1176b2119eaa990a1e8bf3109665fdbc6 (patch)
treeaf8ac49b47136acddb5320b9a62be2361bfaf99c /drivers/xen/xen-pciback
parentc288b67b9b4d65790e1a1a1fd982330730b68f46 (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')
-rw-r--r--drivers/xen/xen-pciback/Makefile5
-rw-r--r--drivers/xen/xen-pciback/conf_space.c55
-rw-r--r--drivers/xen/xen-pciback/conf_space.h42
-rw-r--r--drivers/xen/xen-pciback/conf_space_capability.c161
-rw-r--r--drivers/xen/xen-pciback/conf_space_capability.h26
-rw-r--r--drivers/xen/xen-pciback/conf_space_capability_msi.c142
-rw-r--r--drivers/xen/xen-pciback/conf_space_capability_pm.c113
-rw-r--r--drivers/xen/xen-pciback/conf_space_capability_vpd.c40
-rw-r--r--drivers/xen/xen-pciback/conf_space_header.c49
-rw-r--r--drivers/xen/xen-pciback/conf_space_quirks.c50
-rw-r--r--drivers/xen/xen-pciback/conf_space_quirks.h16
-rw-r--r--drivers/xen/xen-pciback/controller.c442
-rw-r--r--drivers/xen/xen-pciback/passthrough.c30
-rw-r--r--drivers/xen/xen-pciback/pci_stub.c217
-rw-r--r--drivers/xen/xen-pciback/pciback.h107
-rw-r--r--drivers/xen/xen-pciback/pciback_ops.c198
-rw-r--r--drivers/xen/xen-pciback/slot.c191
-rw-r--r--drivers/xen/xen-pciback/vpci.c36
-rw-r--r--drivers/xen/xen-pciback/xenbus.c128
19 files changed, 679 insertions, 1369 deletions
diff --git a/drivers/xen/xen-pciback/Makefile b/drivers/xen/xen-pciback/Makefile
index 38bc123841e7..e79c518afc9a 100644
--- a/drivers/xen/xen-pciback/Makefile
+++ b/drivers/xen/xen-pciback/Makefile
@@ -3,14 +3,9 @@ obj-$(CONFIG_XEN_PCIDEV_BACKEND) += xen-pciback.o
3xen-pciback-y := pci_stub.o pciback_ops.o xenbus.o 3xen-pciback-y := pci_stub.o pciback_ops.o xenbus.o
4xen-pciback-y += conf_space.o conf_space_header.o \ 4xen-pciback-y += conf_space.o conf_space_header.o \
5 conf_space_capability.o \ 5 conf_space_capability.o \
6 conf_space_capability_vpd.o \
7 conf_space_capability_pm.o \
8 conf_space_quirks.o 6 conf_space_quirks.o
9xen-pciback-$(CONFIG_PCI_MSI) += conf_space_capability_msi.o
10xen-pciback-$(CONFIG_XEN_PCIDEV_BACKEND_VPCI) += vpci.o 7xen-pciback-$(CONFIG_XEN_PCIDEV_BACKEND_VPCI) += vpci.o
11xen-pciback-$(CONFIG_XEN_PCIDEV_BACKEND_SLOT) += slot.o
12xen-pciback-$(CONFIG_XEN_PCIDEV_BACKEND_PASS) += passthrough.o 8xen-pciback-$(CONFIG_XEN_PCIDEV_BACKEND_PASS) += passthrough.o
13xen-pciback-$(CONFIG_XEN_PCIDEV_BACKEND_CONTROLLER) += controller.o
14 9
15ifeq ($(CONFIG_XEN_PCIDEV_BE_DEBUG),y) 10ifeq ($(CONFIG_XEN_PCIDEV_BE_DEBUG),y)
16EXTRA_CFLAGS += -DDEBUG 11EXTRA_CFLAGS += -DDEBUG
diff --git a/drivers/xen/xen-pciback/conf_space.c b/drivers/xen/xen-pciback/conf_space.c
index eb6bba044438..a8031445d94e 100644
--- a/drivers/xen/xen-pciback/conf_space.c
+++ b/drivers/xen/xen-pciback/conf_space.c
@@ -15,11 +15,14 @@
15#include "conf_space.h" 15#include "conf_space.h"
16#include "conf_space_quirks.h" 16#include "conf_space_quirks.h"
17 17
18#define DRV_NAME "xen-pciback"
18static int permissive; 19static int permissive;
19module_param(permissive, bool, 0644); 20module_param(permissive, bool, 0644);
20 21
22/* This is where xen_pcibk_read_config_byte, xen_pcibk_read_config_word,
23 * xen_pcibk_write_config_word, and xen_pcibk_write_config_byte are created. */
21#define DEFINE_PCI_CONFIG(op, size, type) \ 24#define DEFINE_PCI_CONFIG(op, size, type) \
22int pciback_##op##_config_##size \ 25int xen_pcibk_##op##_config_##size \
23(struct pci_dev *dev, int offset, type value, void *data) \ 26(struct pci_dev *dev, int offset, type value, void *data) \
24{ \ 27{ \
25 return pci_##op##_config_##size(dev, offset, value); \ 28 return pci_##op##_config_##size(dev, offset, value); \
@@ -138,11 +141,11 @@ static int pcibios_err_to_errno(int err)
138 return err; 141 return err;
139} 142}
140 143
141int pciback_config_read(struct pci_dev *dev, int offset, int size, 144int xen_pcibk_config_read(struct pci_dev *dev, int offset, int size,
142 u32 *ret_val) 145 u32 *ret_val)
143{ 146{
144 int err = 0; 147 int err = 0;
145 struct pciback_dev_data *dev_data = pci_get_drvdata(dev); 148 struct xen_pcibk_dev_data *dev_data = pci_get_drvdata(dev);
146 const struct config_field_entry *cfg_entry; 149 const struct config_field_entry *cfg_entry;
147 const struct config_field *field; 150 const struct config_field *field;
148 int req_start, req_end, field_start, field_end; 151 int req_start, req_end, field_start, field_end;
@@ -151,7 +154,7 @@ int pciback_config_read(struct pci_dev *dev, int offset, int size,
151 u32 value = 0, tmp_val; 154 u32 value = 0, tmp_val;
152 155
153 if (unlikely(verbose_request)) 156 if (unlikely(verbose_request))
154 printk(KERN_DEBUG "pciback: %s: read %d bytes at 0x%x\n", 157 printk(KERN_DEBUG DRV_NAME ": %s: read %d bytes at 0x%x\n",
155 pci_name(dev), size, offset); 158 pci_name(dev), size, offset);
156 159
157 if (!valid_request(offset, size)) { 160 if (!valid_request(offset, size)) {
@@ -195,17 +198,17 @@ int pciback_config_read(struct pci_dev *dev, int offset, int size,
195 198
196out: 199out:
197 if (unlikely(verbose_request)) 200 if (unlikely(verbose_request))
198 printk(KERN_DEBUG "pciback: %s: read %d bytes at 0x%x = %x\n", 201 printk(KERN_DEBUG DRV_NAME ": %s: read %d bytes at 0x%x = %x\n",
199 pci_name(dev), size, offset, value); 202 pci_name(dev), size, offset, value);
200 203
201 *ret_val = value; 204 *ret_val = value;
202 return pcibios_err_to_errno(err); 205 return pcibios_err_to_errno(err);
203} 206}
204 207
205int pciback_config_write(struct pci_dev *dev, int offset, int size, u32 value) 208int xen_pcibk_config_write(struct pci_dev *dev, int offset, int size, u32 value)
206{ 209{
207 int err = 0, handled = 0; 210 int err = 0, handled = 0;
208 struct pciback_dev_data *dev_data = pci_get_drvdata(dev); 211 struct xen_pcibk_dev_data *dev_data = pci_get_drvdata(dev);
209 const struct config_field_entry *cfg_entry; 212 const struct config_field_entry *cfg_entry;
210 const struct config_field *field; 213 const struct config_field *field;
211 u32 tmp_val; 214 u32 tmp_val;
@@ -213,7 +216,7 @@ int pciback_config_write(struct pci_dev *dev, int offset, int size, u32 value)
213 216
214 if (unlikely(verbose_request)) 217 if (unlikely(verbose_request))
215 printk(KERN_DEBUG 218 printk(KERN_DEBUG
216 "pciback: %s: write request %d bytes at 0x%x = %x\n", 219 DRV_NAME ": %s: write request %d bytes at 0x%x = %x\n",
217 pci_name(dev), size, offset, value); 220 pci_name(dev), size, offset, value);
218 221
219 if (!valid_request(offset, size)) 222 if (!valid_request(offset, size))
@@ -231,7 +234,7 @@ int pciback_config_write(struct pci_dev *dev, int offset, int size, u32 value)
231 || (req_end > field_start && req_end <= field_end)) { 234 || (req_end > field_start && req_end <= field_end)) {
232 tmp_val = 0; 235 tmp_val = 0;
233 236
234 err = pciback_config_read(dev, field_start, 237 err = xen_pcibk_config_read(dev, field_start,
235 field->size, &tmp_val); 238 field->size, &tmp_val);
236 if (err) 239 if (err)
237 break; 240 break;
@@ -290,9 +293,9 @@ int pciback_config_write(struct pci_dev *dev, int offset, int size, u32 value)
290 return pcibios_err_to_errno(err); 293 return pcibios_err_to_errno(err);
291} 294}
292 295
293void pciback_config_free_dyn_fields(struct pci_dev *dev) 296void xen_pcibk_config_free_dyn_fields(struct pci_dev *dev)
294{ 297{
295 struct pciback_dev_data *dev_data = pci_get_drvdata(dev); 298 struct xen_pcibk_dev_data *dev_data = pci_get_drvdata(dev);
296 struct config_field_entry *cfg_entry, *t; 299 struct config_field_entry *cfg_entry, *t;
297 const struct config_field *field; 300 const struct config_field *field;
298 301
@@ -316,9 +319,9 @@ void pciback_config_free_dyn_fields(struct pci_dev *dev)
316 } 319 }
317} 320}
318 321
319void pciback_config_reset_dev(struct pci_dev *dev) 322void xen_pcibk_config_reset_dev(struct pci_dev *dev)
320{ 323{
321 struct pciback_dev_data *dev_data = pci_get_drvdata(dev); 324 struct xen_pcibk_dev_data *dev_data = pci_get_drvdata(dev);
322 const struct config_field_entry *cfg_entry; 325 const struct config_field_entry *cfg_entry;
323 const struct config_field *field; 326 const struct config_field *field;
324 327
@@ -334,9 +337,9 @@ void pciback_config_reset_dev(struct pci_dev *dev)
334 } 337 }
335} 338}
336 339
337void pciback_config_free_dev(struct pci_dev *dev) 340void xen_pcibk_config_free_dev(struct pci_dev *dev)
338{ 341{
339 struct pciback_dev_data *dev_data = pci_get_drvdata(dev); 342 struct xen_pcibk_dev_data *dev_data = pci_get_drvdata(dev);
340 struct config_field_entry *cfg_entry, *t; 343 struct config_field_entry *cfg_entry, *t;
341 const struct config_field *field; 344 const struct config_field *field;
342 345
@@ -356,12 +359,12 @@ void pciback_config_free_dev(struct pci_dev *dev)
356 } 359 }
357} 360}
358 361
359int pciback_config_add_field_offset(struct pci_dev *dev, 362int xen_pcibk_config_add_field_offset(struct pci_dev *dev,
360 const struct config_field *field, 363 const struct config_field *field,
361 unsigned int base_offset) 364 unsigned int base_offset)
362{ 365{
363 int err = 0; 366 int err = 0;
364 struct pciback_dev_data *dev_data = pci_get_drvdata(dev); 367 struct xen_pcibk_dev_data *dev_data = pci_get_drvdata(dev);
365 struct config_field_entry *cfg_entry; 368 struct config_field_entry *cfg_entry;
366 void *tmp; 369 void *tmp;
367 370
@@ -376,7 +379,7 @@ int pciback_config_add_field_offset(struct pci_dev *dev,
376 cfg_entry->base_offset = base_offset; 379 cfg_entry->base_offset = base_offset;
377 380
378 /* silently ignore duplicate fields */ 381 /* silently ignore duplicate fields */
379 err = pciback_field_is_dup(dev, OFFSET(cfg_entry)); 382 err = xen_pcibk_field_is_dup(dev, OFFSET(cfg_entry));
380 if (err) 383 if (err)
381 goto out; 384 goto out;
382 385
@@ -406,30 +409,30 @@ out:
406 * certain registers (like the base address registers (BARs) so that we can 409 * certain registers (like the base address registers (BARs) so that we can
407 * keep the client from manipulating them directly. 410 * keep the client from manipulating them directly.
408 */ 411 */
409int pciback_config_init_dev(struct pci_dev *dev) 412int xen_pcibk_config_init_dev(struct pci_dev *dev)
410{ 413{
411 int err = 0; 414 int err = 0;
412 struct pciback_dev_data *dev_data = pci_get_drvdata(dev); 415 struct xen_pcibk_dev_data *dev_data = pci_get_drvdata(dev);
413 416
414 dev_dbg(&dev->dev, "initializing virtual configuration space\n"); 417 dev_dbg(&dev->dev, "initializing virtual configuration space\n");
415 418
416 INIT_LIST_HEAD(&dev_data->config_fields); 419 INIT_LIST_HEAD(&dev_data->config_fields);
417 420
418 err = pciback_config_header_add_fields(dev); 421 err = xen_pcibk_config_header_add_fields(dev);
419 if (err) 422 if (err)
420 goto out; 423 goto out;
421 424
422 err = pciback_config_capability_add_fields(dev); 425 err = xen_pcibk_config_capability_add_fields(dev);
423 if (err) 426 if (err)
424 goto out; 427 goto out;
425 428
426 err = pciback_config_quirks_init(dev); 429 err = xen_pcibk_config_quirks_init(dev);
427 430
428out: 431out:
429 return err; 432 return err;
430} 433}
431 434
432int pciback_config_init(void) 435int xen_pcibk_config_init(void)
433{ 436{
434 return pciback_config_capability_init(); 437 return xen_pcibk_config_capability_init();
435} 438}
diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
index 50ebef216828..e56c934ad137 100644
--- a/drivers/xen/xen-pciback/conf_space.h
+++ b/drivers/xen/xen-pciback/conf_space.h
@@ -69,35 +69,35 @@ struct config_field_entry {
69/* Add fields to a device - the add_fields macro expects to get a pointer to 69/* Add fields to a device - the add_fields macro expects to get a pointer to
70 * the first entry in an array (of which the ending is marked by size==0) 70 * the first entry in an array (of which the ending is marked by size==0)
71 */ 71 */
72int pciback_config_add_field_offset(struct pci_dev *dev, 72int xen_pcibk_config_add_field_offset(struct pci_dev *dev,
73 const struct config_field *field, 73 const struct config_field *field,
74 unsigned int offset); 74 unsigned int offset);
75 75
76static inline int pciback_config_add_field(struct pci_dev *dev, 76static inline int xen_pcibk_config_add_field(struct pci_dev *dev,
77 const struct config_field *field) 77 const struct config_field *field)
78{ 78{
79 return pciback_config_add_field_offset(dev, field, 0); 79 return xen_pcibk_config_add_field_offset(dev, field, 0);
80} 80}
81 81
82static inline int pciback_config_add_fields(struct pci_dev *dev, 82static inline int xen_pcibk_config_add_fields(struct pci_dev *dev,
83 const struct config_field *field) 83 const struct config_field *field)
84{ 84{
85 int i, err = 0; 85 int i, err = 0;
86 for (i = 0; field[i].size != 0; i++) { 86 for (i = 0; field[i].size != 0; i++) {
87 err = pciback_config_add_field(dev, &field[i]); 87 err = xen_pcibk_config_add_field(dev, &field[i]);
88 if (err) 88 if (err)
89 break; 89 break;
90 } 90 }
91 return err; 91 return err;
92} 92}
93 93
94static inline int pciback_config_add_fields_offset(struct pci_dev *dev, 94static inline int xen_pcibk_config_add_fields_offset(struct pci_dev *dev,
95 const struct config_field *field, 95 const struct config_field *field,
96 unsigned int offset) 96 unsigned int offset)
97{ 97{
98 int i, err = 0; 98 int i, err = 0;
99 for (i = 0; field[i].size != 0; i++) { 99 for (i = 0; field[i].size != 0; i++) {
100 err = pciback_config_add_field_offset(dev, &field[i], offset); 100 err = xen_pcibk_config_add_field_offset(dev, &field[i], offset);
101 if (err) 101 if (err)
102 break; 102 break;
103 } 103 }
@@ -105,22 +105,22 @@ static inline int pciback_config_add_fields_offset(struct pci_dev *dev,
105} 105}
106 106
107/* Read/Write the real configuration space */ 107/* Read/Write the real configuration space */
108int pciback_read_config_byte(struct pci_dev *dev, int offset, u8 *value, 108int xen_pcibk_read_config_byte(struct pci_dev *dev, int offset, u8 *value,
109 void *data);
110int pciback_read_config_word(struct pci_dev *dev, int offset, u16 *value,
111 void *data);
112int pciback_read_config_dword(struct pci_dev *dev, int offset, u32 *value,
113 void *data);
114int pciback_write_config_byte(struct pci_dev *dev, int offset, u8 value,
115 void *data);
116int pciback_write_config_word(struct pci_dev *dev, int offset, u16 value,
117 void *data);
118int pciback_write_config_dword(struct pci_dev *dev, int offset, u32 value,
119 void *data); 109 void *data);
110int xen_pcibk_read_config_word(struct pci_dev *dev, int offset, u16 *value,
111 void *data);
112int xen_pcibk_read_config_dword(struct pci_dev *dev, int offset, u32 *value,
113 void *data);
114int xen_pcibk_write_config_byte(struct pci_dev *dev, int offset, u8 value,
115 void *data);
116int xen_pcibk_write_config_word(struct pci_dev *dev, int offset, u16 value,
117 void *data);
118int xen_pcibk_write_config_dword(struct pci_dev *dev, int offset, u32 value,
119 void *data);
120 120
121int pciback_config_capability_init(void); 121int xen_pcibk_config_capability_init(void);
122 122
123int pciback_config_header_add_fields(struct pci_dev *dev); 123int xen_pcibk_config_header_add_fields(struct pci_dev *dev);
124int pciback_config_capability_add_fields(struct pci_dev *dev); 124int xen_pcibk_config_capability_add_fields(struct pci_dev *dev);
125 125
126#endif /* __XEN_PCIBACK_CONF_SPACE_H__ */ 126#endif /* __XEN_PCIBACK_CONF_SPACE_H__ */
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
14static LIST_HEAD(capabilities); 13static LIST_HEAD(capabilities);
14struct 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
16static const struct config_field caplist_header[] = { 23static 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
26static inline void register_capability(struct pciback_config_capability *cap) 33static 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
31int pciback_config_capability_add_fields(struct pci_dev *dev) 38int 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
60int pciback_config_capability_init(void) 67static 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
77static 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
93static 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
105out:
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
113static 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 */
148static 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
162out:
163 return ERR_PTR(err);
164}
165
166static 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
192static struct xen_pcibk_config_capability xen_pcibk_config_capability_pm = {
193 .capability = PCI_CAP_ID_PM,
194 .fields = caplist_pm,
195};
196static struct xen_pcibk_config_capability xen_pcibk_config_capability_vpd = {
197 .capability = PCI_CAP_ID_VPD,
198 .fields = caplist_vpd,
199};
200
201int 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}
diff --git a/drivers/xen/xen-pciback/conf_space_capability.h b/drivers/xen/xen-pciback/conf_space_capability.h
deleted file mode 100644
index 8da3ac415f29..000000000000
--- a/drivers/xen/xen-pciback/conf_space_capability.h
+++ /dev/null
@@ -1,26 +0,0 @@
1/*
2 * PCI Backend - Data structures for special overlays for structures on
3 * the capability list.
4 *
5 * Author: Ryan Wilson <hap9@epoch.ncsc.mil>
6 */
7
8#ifndef __PCIBACK_CONFIG_CAPABILITY_H__
9#define __PCIBACK_CONFIG_CAPABILITY_H__
10
11#include <linux/pci.h>
12#include <linux/list.h>
13
14struct pciback_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};
22
23extern struct pciback_config_capability pciback_config_capability_vpd;
24extern struct pciback_config_capability pciback_config_capability_pm;
25
26#endif
diff --git a/drivers/xen/xen-pciback/conf_space_capability_msi.c b/drivers/xen/xen-pciback/conf_space_capability_msi.c
deleted file mode 100644
index 6e876b600e66..000000000000
--- a/drivers/xen/xen-pciback/conf_space_capability_msi.c
+++ /dev/null
@@ -1,142 +0,0 @@
1/*
2 * PCI Backend -- Configuration overlay for MSI capability
3 */
4#include <linux/pci.h>
5#include <linux/slab.h>
6#include "conf_space.h"
7#include "conf_space_capability.h"
8#include <xen/interface/io/pciif.h>
9#include <xen/events.h>
10#include "pciback.h"
11
12int pciback_enable_msi(struct pciback_device *pdev,
13 struct pci_dev *dev, struct xen_pci_op *op)
14{
15 struct pciback_dev_data *dev_data;
16 int otherend = pdev->xdev->otherend_id;
17 int status;
18
19 if (unlikely(verbose_request))
20 printk(KERN_DEBUG "pciback: %s: enable MSI\n", pci_name(dev));
21
22 status = pci_enable_msi(dev);
23
24 if (status) {
25 printk(KERN_ERR "error enable msi for guest %x status %x\n",
26 otherend, status);
27 op->value = 0;
28 return XEN_PCI_ERR_op_failed;
29 }
30
31 /* The value the guest needs is actually the IDT vector, not the
32 * the local domain's IRQ number. */
33
34 op->value = dev->irq ? xen_pirq_from_irq(dev->irq) : 0;
35 if (unlikely(verbose_request))
36 printk(KERN_DEBUG "pciback: %s: MSI: %d\n", pci_name(dev),
37 op->value);
38
39 dev_data = pci_get_drvdata(dev);
40 if (dev_data)
41 dev_data->ack_intr = 0;
42
43 return 0;
44}
45
46int pciback_disable_msi(struct pciback_device *pdev,
47 struct pci_dev *dev, struct xen_pci_op *op)
48{
49 struct pciback_dev_data *dev_data;
50
51 if (unlikely(verbose_request))
52 printk(KERN_DEBUG "pciback: %s: disable MSI\n", pci_name(dev));
53
54 pci_disable_msi(dev);
55
56 op->value = dev->irq ? xen_pirq_from_irq(dev->irq) : 0;
57 if (unlikely(verbose_request))
58 printk(KERN_DEBUG "pciback: %s: MSI: %d\n", pci_name(dev),
59 op->value);
60 dev_data = pci_get_drvdata(dev);
61 if (dev_data)
62 dev_data->ack_intr = 1;
63 return 0;
64}
65
66int pciback_enable_msix(struct pciback_device *pdev,
67 struct pci_dev *dev, struct xen_pci_op *op)
68{
69 struct pciback_dev_data *dev_data;
70 int i, result;
71 struct msix_entry *entries;
72
73 if (unlikely(verbose_request))
74 printk(KERN_DEBUG "pciback: %s: enable MSI-X\n",
75 pci_name(dev));
76
77 if (op->value > SH_INFO_MAX_VEC)
78 return -EINVAL;
79
80 entries = kmalloc(op->value * sizeof(*entries), GFP_KERNEL);
81 if (entries == NULL)
82 return -ENOMEM;
83
84 for (i = 0; i < op->value; i++) {
85 entries[i].entry = op->msix_entries[i].entry;
86 entries[i].vector = op->msix_entries[i].vector;
87 }
88
89 result = pci_enable_msix(dev, entries, op->value);
90
91 if (result == 0) {
92 for (i = 0; i < op->value; i++) {
93 op->msix_entries[i].entry = entries[i].entry;
94 if (entries[i].vector)
95 op->msix_entries[i].vector =
96 xen_pirq_from_irq(entries[i].vector);
97 if (unlikely(verbose_request))
98 printk(KERN_DEBUG "pciback: %s: " \
99 "MSI-X[%d]: %d\n",
100 pci_name(dev), i,
101 op->msix_entries[i].vector);
102 }
103 } else {
104 printk(KERN_WARNING "pciback: %s: failed to enable MSI-X: err %d!\n",
105 pci_name(dev), result);
106 }
107 kfree(entries);
108
109 op->value = result;
110 dev_data = pci_get_drvdata(dev);
111 if (dev_data)
112 dev_data->ack_intr = 0;
113
114 return result;
115}
116
117int pciback_disable_msix(struct pciback_device *pdev,
118 struct pci_dev *dev, struct xen_pci_op *op)
119{
120 struct pciback_dev_data *dev_data;
121
122 if (unlikely(verbose_request))
123 printk(KERN_DEBUG "pciback: %s: disable MSI-X\n",
124 pci_name(dev));
125
126 pci_disable_msix(dev);
127
128 /*
129 * SR-IOV devices (which don't have any legacy IRQ) have
130 * an undefined IRQ value of zero.
131 */
132 op->value = dev->irq ? xen_pirq_from_irq(dev->irq) : 0;
133 if (unlikely(verbose_request))
134 printk(KERN_DEBUG "pciback: %s: MSI-X: %d\n", pci_name(dev),
135 op->value);
136 dev_data = pci_get_drvdata(dev);
137 if (dev_data)
138 dev_data->ack_intr = 1;
139
140 return 0;
141}
142
diff --git a/drivers/xen/xen-pciback/conf_space_capability_pm.c b/drivers/xen/xen-pciback/conf_space_capability_pm.c
deleted file mode 100644
index 04426165a9e5..000000000000
--- a/drivers/xen/xen-pciback/conf_space_capability_pm.c
+++ /dev/null
@@ -1,113 +0,0 @@
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
11static 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
23out:
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
31static 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 */
66static 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
80out:
81 return ERR_PTR(err);
82}
83
84static 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
110struct pciback_config_capability pciback_config_capability_pm = {
111 .capability = PCI_CAP_ID_PM,
112 .fields = caplist_pm,
113};
diff --git a/drivers/xen/xen-pciback/conf_space_capability_vpd.c b/drivers/xen/xen-pciback/conf_space_capability_vpd.c
deleted file mode 100644
index e7b4d662b53d..000000000000
--- a/drivers/xen/xen-pciback/conf_space_capability_vpd.c
+++ /dev/null
@@ -1,40 +0,0 @@
1/*
2 * PCI Backend - Configuration space overlay for Vital Product Data
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
11static int vpd_address_write(struct pci_dev *dev, int offset, u16 value,
12 void *data)
13{
14 /* Disallow writes to the vital product data */
15 if (value & PCI_VPD_ADDR_F)
16 return PCIBIOS_SET_FAILED;
17 else
18 return pci_write_config_word(dev, offset, value);
19}
20
21static const struct config_field caplist_vpd[] = {
22 {
23 .offset = PCI_VPD_ADDR,
24 .size = 2,
25 .u.w.read = pciback_read_config_word,
26 .u.w.write = vpd_address_write,
27 },
28 {
29 .offset = PCI_VPD_DATA,
30 .size = 4,
31 .u.dw.read = pciback_read_config_dword,
32 .u.dw.write = NULL,
33 },
34 {}
35};
36
37struct pciback_config_capability pciback_config_capability_vpd = {
38 .capability = PCI_CAP_ID_VPD,
39 .fields = caplist_vpd,
40};
diff --git a/drivers/xen/xen-pciback/conf_space_header.c b/drivers/xen/xen-pciback/conf_space_header.c
index 22ad0f560669..da3cbdfcb5dc 100644
--- a/drivers/xen/xen-pciback/conf_space_header.c
+++ b/drivers/xen/xen-pciback/conf_space_header.c
@@ -15,6 +15,7 @@ struct pci_bar_info {
15 int which; 15 int which;
16}; 16};
17 17
18#define DRV_NAME "xen-pciback"
18#define is_enable_cmd(value) ((value)&(PCI_COMMAND_MEMORY|PCI_COMMAND_IO)) 19#define is_enable_cmd(value) ((value)&(PCI_COMMAND_MEMORY|PCI_COMMAND_IO))
19#define is_master_cmd(value) ((value)&PCI_COMMAND_MASTER) 20#define is_master_cmd(value) ((value)&PCI_COMMAND_MASTER)
20 21
@@ -23,7 +24,7 @@ static int command_read(struct pci_dev *dev, int offset, u16 *value, void *data)
23 int i; 24 int i;
24 int ret; 25 int ret;
25 26
26 ret = pciback_read_config_word(dev, offset, value, data); 27 ret = xen_pcibk_read_config_word(dev, offset, value, data);
27 if (!atomic_read(&dev->enable_cnt)) 28 if (!atomic_read(&dev->enable_cnt))
28 return ret; 29 return ret;
29 30
@@ -39,13 +40,13 @@ static int command_read(struct pci_dev *dev, int offset, u16 *value, void *data)
39 40
40static int command_write(struct pci_dev *dev, int offset, u16 value, void *data) 41static int command_write(struct pci_dev *dev, int offset, u16 value, void *data)
41{ 42{
42 struct pciback_dev_data *dev_data; 43 struct xen_pcibk_dev_data *dev_data;
43 int err; 44 int err;
44 45
45 dev_data = pci_get_drvdata(dev); 46 dev_data = pci_get_drvdata(dev);
46 if (!pci_is_enabled(dev) && is_enable_cmd(value)) { 47 if (!pci_is_enabled(dev) && is_enable_cmd(value)) {
47 if (unlikely(verbose_request)) 48 if (unlikely(verbose_request))
48 printk(KERN_DEBUG "pciback: %s: enable\n", 49 printk(KERN_DEBUG DRV_NAME ": %s: enable\n",
49 pci_name(dev)); 50 pci_name(dev));
50 err = pci_enable_device(dev); 51 err = pci_enable_device(dev);
51 if (err) 52 if (err)
@@ -54,7 +55,7 @@ static int command_write(struct pci_dev *dev, int offset, u16 value, void *data)
54 dev_data->enable_intx = 1; 55 dev_data->enable_intx = 1;
55 } else if (pci_is_enabled(dev) && !is_enable_cmd(value)) { 56 } else if (pci_is_enabled(dev) && !is_enable_cmd(value)) {
56 if (unlikely(verbose_request)) 57 if (unlikely(verbose_request))
57 printk(KERN_DEBUG "pciback: %s: disable\n", 58 printk(KERN_DEBUG DRV_NAME ": %s: disable\n",
58 pci_name(dev)); 59 pci_name(dev));
59 pci_disable_device(dev); 60 pci_disable_device(dev);
60 if (dev_data) 61 if (dev_data)
@@ -63,7 +64,7 @@ static int command_write(struct pci_dev *dev, int offset, u16 value, void *data)
63 64
64 if (!dev->is_busmaster && is_master_cmd(value)) { 65 if (!dev->is_busmaster && is_master_cmd(value)) {
65 if (unlikely(verbose_request)) 66 if (unlikely(verbose_request))
66 printk(KERN_DEBUG "pciback: %s: set bus master\n", 67 printk(KERN_DEBUG DRV_NAME ": %s: set bus master\n",
67 pci_name(dev)); 68 pci_name(dev));
68 pci_set_master(dev); 69 pci_set_master(dev);
69 } 70 }
@@ -71,12 +72,12 @@ static int command_write(struct pci_dev *dev, int offset, u16 value, void *data)
71 if (value & PCI_COMMAND_INVALIDATE) { 72 if (value & PCI_COMMAND_INVALIDATE) {
72 if (unlikely(verbose_request)) 73 if (unlikely(verbose_request))
73 printk(KERN_DEBUG 74 printk(KERN_DEBUG
74 "pciback: %s: enable memory-write-invalidate\n", 75 DRV_NAME ": %s: enable memory-write-invalidate\n",
75 pci_name(dev)); 76 pci_name(dev));
76 err = pci_set_mwi(dev); 77 err = pci_set_mwi(dev);
77 if (err) { 78 if (err) {
78 printk(KERN_WARNING 79 printk(KERN_WARNING
79 "pciback: %s: cannot enable " 80 DRV_NAME ": %s: cannot enable "
80 "memory-write-invalidate (%d)\n", 81 "memory-write-invalidate (%d)\n",
81 pci_name(dev), err); 82 pci_name(dev), err);
82 value &= ~PCI_COMMAND_INVALIDATE; 83 value &= ~PCI_COMMAND_INVALIDATE;
@@ -91,7 +92,7 @@ static int rom_write(struct pci_dev *dev, int offset, u32 value, void *data)
91 struct pci_bar_info *bar = data; 92 struct pci_bar_info *bar = data;
92 93
93 if (unlikely(!bar)) { 94 if (unlikely(!bar)) {
94 printk(KERN_WARNING "pciback: driver data not found for %s\n", 95 printk(KERN_WARNING DRV_NAME ": driver data not found for %s\n",
95 pci_name(dev)); 96 pci_name(dev));
96 return XEN_PCI_ERR_op_failed; 97 return XEN_PCI_ERR_op_failed;
97 } 98 }
@@ -125,7 +126,7 @@ static int bar_write(struct pci_dev *dev, int offset, u32 value, void *data)
125 struct pci_bar_info *bar = data; 126 struct pci_bar_info *bar = data;
126 127
127 if (unlikely(!bar)) { 128 if (unlikely(!bar)) {
128 printk(KERN_WARNING "pciback: driver data not found for %s\n", 129 printk(KERN_WARNING DRV_NAME ": driver data not found for %s\n",
129 pci_name(dev)); 130 pci_name(dev));
130 return XEN_PCI_ERR_op_failed; 131 return XEN_PCI_ERR_op_failed;
131 } 132 }
@@ -153,7 +154,7 @@ static int bar_read(struct pci_dev *dev, int offset, u32 * value, void *data)
153 struct pci_bar_info *bar = data; 154 struct pci_bar_info *bar = data;
154 155
155 if (unlikely(!bar)) { 156 if (unlikely(!bar)) {
156 printk(KERN_WARNING "pciback: driver data not found for %s\n", 157 printk(KERN_WARNING DRV_NAME ": driver data not found for %s\n",
157 pci_name(dev)); 158 pci_name(dev));
158 return XEN_PCI_ERR_op_failed; 159 return XEN_PCI_ERR_op_failed;
159 } 160 }
@@ -227,7 +228,7 @@ static void bar_release(struct pci_dev *dev, int offset, void *data)
227 kfree(data); 228 kfree(data);
228} 229}
229 230
230static int pciback_read_vendor(struct pci_dev *dev, int offset, 231static int xen_pcibk_read_vendor(struct pci_dev *dev, int offset,
231 u16 *value, void *data) 232 u16 *value, void *data)
232{ 233{
233 *value = dev->vendor; 234 *value = dev->vendor;
@@ -235,7 +236,7 @@ static int pciback_read_vendor(struct pci_dev *dev, int offset,
235 return 0; 236 return 0;
236} 237}
237 238
238static int pciback_read_device(struct pci_dev *dev, int offset, 239static int xen_pcibk_read_device(struct pci_dev *dev, int offset,
239 u16 *value, void *data) 240 u16 *value, void *data)
240{ 241{
241 *value = dev->device; 242 *value = dev->device;
@@ -272,12 +273,12 @@ static const struct config_field header_common[] = {
272 { 273 {
273 .offset = PCI_VENDOR_ID, 274 .offset = PCI_VENDOR_ID,
274 .size = 2, 275 .size = 2,
275 .u.w.read = pciback_read_vendor, 276 .u.w.read = xen_pcibk_read_vendor,
276 }, 277 },
277 { 278 {
278 .offset = PCI_DEVICE_ID, 279 .offset = PCI_DEVICE_ID,
279 .size = 2, 280 .size = 2,
280 .u.w.read = pciback_read_device, 281 .u.w.read = xen_pcibk_read_device,
281 }, 282 },
282 { 283 {
283 .offset = PCI_COMMAND, 284 .offset = PCI_COMMAND,
@@ -293,24 +294,24 @@ static const struct config_field header_common[] = {
293 { 294 {
294 .offset = PCI_INTERRUPT_PIN, 295 .offset = PCI_INTERRUPT_PIN,
295 .size = 1, 296 .size = 1,
296 .u.b.read = pciback_read_config_byte, 297 .u.b.read = xen_pcibk_read_config_byte,
297 }, 298 },
298 { 299 {
299 /* Any side effects of letting driver domain control cache line? */ 300 /* Any side effects of letting driver domain control cache line? */
300 .offset = PCI_CACHE_LINE_SIZE, 301 .offset = PCI_CACHE_LINE_SIZE,
301 .size = 1, 302 .size = 1,
302 .u.b.read = pciback_read_config_byte, 303 .u.b.read = xen_pcibk_read_config_byte,
303 .u.b.write = pciback_write_config_byte, 304 .u.b.write = xen_pcibk_write_config_byte,
304 }, 305 },
305 { 306 {
306 .offset = PCI_LATENCY_TIMER, 307 .offset = PCI_LATENCY_TIMER,
307 .size = 1, 308 .size = 1,
308 .u.b.read = pciback_read_config_byte, 309 .u.b.read = xen_pcibk_read_config_byte,
309 }, 310 },
310 { 311 {
311 .offset = PCI_BIST, 312 .offset = PCI_BIST,
312 .size = 1, 313 .size = 1,
313 .u.b.read = pciback_read_config_byte, 314 .u.b.read = xen_pcibk_read_config_byte,
314 .u.b.write = bist_write, 315 .u.b.write = bist_write,
315 }, 316 },
316 {} 317 {}
@@ -356,26 +357,26 @@ static const struct config_field header_1[] = {
356 {} 357 {}
357}; 358};
358 359
359int pciback_config_header_add_fields(struct pci_dev *dev) 360int xen_pcibk_config_header_add_fields(struct pci_dev *dev)
360{ 361{
361 int err; 362 int err;
362 363
363 err = pciback_config_add_fields(dev, header_common); 364 err = xen_pcibk_config_add_fields(dev, header_common);
364 if (err) 365 if (err)
365 goto out; 366 goto out;
366 367
367 switch (dev->hdr_type) { 368 switch (dev->hdr_type) {
368 case PCI_HEADER_TYPE_NORMAL: 369 case PCI_HEADER_TYPE_NORMAL:
369 err = pciback_config_add_fields(dev, header_0); 370 err = xen_pcibk_config_add_fields(dev, header_0);
370 break; 371 break;
371 372
372 case PCI_HEADER_TYPE_BRIDGE: 373 case PCI_HEADER_TYPE_BRIDGE:
373 err = pciback_config_add_fields(dev, header_1); 374 err = xen_pcibk_config_add_fields(dev, header_1);
374 break; 375 break;
375 376
376 default: 377 default:
377 err = -EINVAL; 378 err = -EINVAL;
378 printk(KERN_ERR "pciback: %s: Unsupported header type %d!\n", 379 printk(KERN_ERR DRV_NAME ": %s: Unsupported header type %d!\n",
379 pci_name(dev), dev->hdr_type); 380 pci_name(dev), dev->hdr_type);
380 break; 381 break;
381 } 382 }
diff --git a/drivers/xen/xen-pciback/conf_space_quirks.c b/drivers/xen/xen-pciback/conf_space_quirks.c
index 45c31fb391ec..921a889e65eb 100644
--- a/drivers/xen/xen-pciback/conf_space_quirks.c
+++ b/drivers/xen/xen-pciback/conf_space_quirks.c
@@ -11,8 +11,8 @@
11#include "conf_space.h" 11#include "conf_space.h"
12#include "conf_space_quirks.h" 12#include "conf_space_quirks.h"
13 13
14LIST_HEAD(pciback_quirks); 14LIST_HEAD(xen_pcibk_quirks);
15 15#define DRV_NAME "xen-pciback"
16static inline const struct pci_device_id * 16static inline const struct pci_device_id *
17match_one_device(const struct pci_device_id *id, const struct pci_dev *dev) 17match_one_device(const struct pci_device_id *id, const struct pci_dev *dev)
18{ 18{
@@ -27,29 +27,29 @@ match_one_device(const struct pci_device_id *id, const struct pci_dev *dev)
27 return NULL; 27 return NULL;
28} 28}
29 29
30struct pciback_config_quirk *pciback_find_quirk(struct pci_dev *dev) 30static struct xen_pcibk_config_quirk *xen_pcibk_find_quirk(struct pci_dev *dev)
31{ 31{
32 struct pciback_config_quirk *tmp_quirk; 32 struct xen_pcibk_config_quirk *tmp_quirk;
33 33
34 list_for_each_entry(tmp_quirk, &pciback_quirks, quirks_list) 34 list_for_each_entry(tmp_quirk, &xen_pcibk_quirks, quirks_list)
35 if (match_one_device(&tmp_quirk->devid, dev) != NULL) 35 if (match_one_device(&tmp_quirk->devid, dev) != NULL)
36 goto out; 36 goto out;
37 tmp_quirk = NULL; 37 tmp_quirk = NULL;
38 printk(KERN_DEBUG 38 printk(KERN_DEBUG DRV_NAME
39 "quirk didn't match any device pciback knows about\n"); 39 ":quirk didn't match any device xen_pciback knows about\n");
40out: 40out:
41 return tmp_quirk; 41 return tmp_quirk;
42} 42}
43 43
44static inline void register_quirk(struct pciback_config_quirk *quirk) 44static inline void register_quirk(struct xen_pcibk_config_quirk *quirk)
45{ 45{
46 list_add_tail(&quirk->quirks_list, &pciback_quirks); 46 list_add_tail(&quirk->quirks_list, &xen_pcibk_quirks);
47} 47}
48 48
49int pciback_field_is_dup(struct pci_dev *dev, unsigned int reg) 49int xen_pcibk_field_is_dup(struct pci_dev *dev, unsigned int reg)
50{ 50{
51 int ret = 0; 51 int ret = 0;
52 struct pciback_dev_data *dev_data = pci_get_drvdata(dev); 52 struct xen_pcibk_dev_data *dev_data = pci_get_drvdata(dev);
53 struct config_field_entry *cfg_entry; 53 struct config_field_entry *cfg_entry;
54 54
55 list_for_each_entry(cfg_entry, &dev_data->config_fields, list) { 55 list_for_each_entry(cfg_entry, &dev_data->config_fields, list) {
@@ -61,38 +61,38 @@ int pciback_field_is_dup(struct pci_dev *dev, unsigned int reg)
61 return ret; 61 return ret;
62} 62}
63 63
64int pciback_config_quirks_add_field(struct pci_dev *dev, struct config_field 64int xen_pcibk_config_quirks_add_field(struct pci_dev *dev, struct config_field
65 *field) 65 *field)
66{ 66{
67 int err = 0; 67 int err = 0;
68 68
69 switch (field->size) { 69 switch (field->size) {
70 case 1: 70 case 1:
71 field->u.b.read = pciback_read_config_byte; 71 field->u.b.read = xen_pcibk_read_config_byte;
72 field->u.b.write = pciback_write_config_byte; 72 field->u.b.write = xen_pcibk_write_config_byte;
73 break; 73 break;
74 case 2: 74 case 2:
75 field->u.w.read = pciback_read_config_word; 75 field->u.w.read = xen_pcibk_read_config_word;
76 field->u.w.write = pciback_write_config_word; 76 field->u.w.write = xen_pcibk_write_config_word;
77 break; 77 break;
78 case 4: 78 case 4:
79 field->u.dw.read = pciback_read_config_dword; 79 field->u.dw.read = xen_pcibk_read_config_dword;
80 field->u.dw.write = pciback_write_config_dword; 80 field->u.dw.write = xen_pcibk_write_config_dword;
81 break; 81 break;
82 default: 82 default:
83 err = -EINVAL; 83 err = -EINVAL;
84 goto out; 84 goto out;
85 } 85 }
86 86
87 pciback_config_add_field(dev, field); 87 xen_pcibk_config_add_field(dev, field);
88 88
89out: 89out:
90 return err; 90 return err;
91} 91}
92 92
93int pciback_config_quirks_init(struct pci_dev *dev) 93int xen_pcibk_config_quirks_init(struct pci_dev *dev)
94{ 94{
95 struct pciback_config_quirk *quirk; 95 struct xen_pcibk_config_quirk *quirk;
96 int ret = 0; 96 int ret = 0;
97 97
98 quirk = kzalloc(sizeof(*quirk), GFP_ATOMIC); 98 quirk = kzalloc(sizeof(*quirk), GFP_ATOMIC);
@@ -116,17 +116,17 @@ out:
116 return ret; 116 return ret;
117} 117}
118 118
119void pciback_config_field_free(struct config_field *field) 119void xen_pcibk_config_field_free(struct config_field *field)
120{ 120{
121 kfree(field); 121 kfree(field);
122} 122}
123 123
124int pciback_config_quirk_release(struct pci_dev *dev) 124int xen_pcibk_config_quirk_release(struct pci_dev *dev)
125{ 125{
126 struct pciback_config_quirk *quirk; 126 struct xen_pcibk_config_quirk *quirk;
127 int ret = 0; 127 int ret = 0;
128 128
129 quirk = pciback_find_quirk(dev); 129 quirk = xen_pcibk_find_quirk(dev);
130 if (!quirk) { 130 if (!quirk) {
131 ret = -ENXIO; 131 ret = -ENXIO;
132 goto out; 132 goto out;
diff --git a/drivers/xen/xen-pciback/conf_space_quirks.h b/drivers/xen/xen-pciback/conf_space_quirks.h
index acd0e1ae8fc5..cfcc517e4570 100644
--- a/drivers/xen/xen-pciback/conf_space_quirks.h
+++ b/drivers/xen/xen-pciback/conf_space_quirks.h
@@ -11,25 +11,23 @@
11#include <linux/pci.h> 11#include <linux/pci.h>
12#include <linux/list.h> 12#include <linux/list.h>
13 13
14struct pciback_config_quirk { 14struct xen_pcibk_config_quirk {
15 struct list_head quirks_list; 15 struct list_head quirks_list;
16 struct pci_device_id devid; 16 struct pci_device_id devid;
17 struct pci_dev *pdev; 17 struct pci_dev *pdev;
18}; 18};
19 19
20struct pciback_config_quirk *pciback_find_quirk(struct pci_dev *dev); 20int xen_pcibk_config_quirks_add_field(struct pci_dev *dev, struct config_field
21
22int pciback_config_quirks_add_field(struct pci_dev *dev, struct config_field
23 *field); 21 *field);
24 22
25int pciback_config_quirks_remove_field(struct pci_dev *dev, int reg); 23int xen_pcibk_config_quirks_remove_field(struct pci_dev *dev, int reg);
26 24
27int pciback_config_quirks_init(struct pci_dev *dev); 25int xen_pcibk_config_quirks_init(struct pci_dev *dev);
28 26
29void pciback_config_field_free(struct config_field *field); 27void xen_pcibk_config_field_free(struct config_field *field);
30 28
31int pciback_config_quirk_release(struct pci_dev *dev); 29int xen_pcibk_config_quirk_release(struct pci_dev *dev);
32 30
33int pciback_field_is_dup(struct pci_dev *dev, unsigned int reg); 31int xen_pcibk_field_is_dup(struct pci_dev *dev, unsigned int reg);
34 32
35#endif 33#endif
diff --git a/drivers/xen/xen-pciback/controller.c b/drivers/xen/xen-pciback/controller.c
deleted file mode 100644
index 7f04f116daec..000000000000
--- a/drivers/xen/xen-pciback/controller.c
+++ /dev/null
@@ -1,442 +0,0 @@
1/*
2 * Copyright (C) 2007 Hewlett-Packard Development Company, L.P.
3 * Alex Williamson <alex.williamson@hp.com>
4 *
5 * PCI "Controller" Backend - virtualize PCI bus topology based on PCI
6 * controllers. Devices under the same PCI controller are exposed on the
7 * same virtual domain:bus. Within a bus, device slots are virtualized
8 * to compact the bus.
9 *
10 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25 */
26
27#include <linux/acpi.h>
28#include <linux/list.h>
29#include <linux/pci.h>
30#include <linux/spinlock.h>
31#include "pciback.h"
32
33#define PCI_MAX_BUSSES 255
34#define PCI_MAX_SLOTS 32
35
36struct controller_dev_entry {
37 struct list_head list;
38 struct pci_dev *dev;
39 unsigned int devfn;
40};
41
42struct controller_list_entry {
43 struct list_head list;
44 struct pci_controller *controller;
45 unsigned int domain;
46 unsigned int bus;
47 unsigned int next_devfn;
48 struct list_head dev_list;
49};
50
51struct controller_dev_data {
52 struct list_head list;
53 unsigned int next_domain;
54 unsigned int next_bus;
55 spinlock_t lock;
56};
57
58struct walk_info {
59 struct pciback_device *pdev;
60 int resource_count;
61 int root_num;
62};
63
64struct pci_dev *pciback_get_pci_dev(struct pciback_device *pdev,
65 unsigned int domain, unsigned int bus,
66 unsigned int devfn)
67{
68 struct controller_dev_data *dev_data = pdev->pci_dev_data;
69 struct controller_dev_entry *dev_entry;
70 struct controller_list_entry *cntrl_entry;
71 struct pci_dev *dev = NULL;
72 unsigned long flags;
73
74 spin_lock_irqsave(&dev_data->lock, flags);
75
76 list_for_each_entry(cntrl_entry, &dev_data->list, list) {
77 if (cntrl_entry->domain != domain ||
78 cntrl_entry->bus != bus)
79 continue;
80
81 list_for_each_entry(dev_entry, &cntrl_entry->dev_list, list) {
82 if (devfn == dev_entry->devfn) {
83 dev = dev_entry->dev;
84 goto found;
85 }
86 }
87 }
88found:
89 spin_unlock_irqrestore(&dev_data->lock, flags);
90
91 return dev;
92}
93
94int pciback_add_pci_dev(struct pciback_device *pdev, struct pci_dev *dev,
95 int devid, publish_pci_dev_cb publish_cb)
96{
97 struct controller_dev_data *dev_data = pdev->pci_dev_data;
98 struct controller_dev_entry *dev_entry;
99 struct controller_list_entry *cntrl_entry;
100 struct pci_controller *dev_controller = PCI_CONTROLLER(dev);
101 unsigned long flags;
102 int ret = 0, found = 0;
103
104 spin_lock_irqsave(&dev_data->lock, flags);
105
106 /* Look to see if we already have a domain:bus for this controller */
107 list_for_each_entry(cntrl_entry, &dev_data->list, list) {
108 if (cntrl_entry->controller == dev_controller) {
109 found = 1;
110 break;
111 }
112 }
113
114 if (!found) {
115 cntrl_entry = kmalloc(sizeof(*cntrl_entry), GFP_ATOMIC);
116 if (!cntrl_entry) {
117 ret = -ENOMEM;
118 goto out;
119 }
120
121 cntrl_entry->controller = dev_controller;
122 cntrl_entry->next_devfn = PCI_DEVFN(0, 0);
123
124 cntrl_entry->domain = dev_data->next_domain;
125 cntrl_entry->bus = dev_data->next_bus++;
126 if (dev_data->next_bus > PCI_MAX_BUSSES) {
127 dev_data->next_domain++;
128 dev_data->next_bus = 0;
129 }
130
131 INIT_LIST_HEAD(&cntrl_entry->dev_list);
132
133 list_add_tail(&cntrl_entry->list, &dev_data->list);
134 }
135
136 if (PCI_SLOT(cntrl_entry->next_devfn) > PCI_MAX_SLOTS) {
137 /*
138 * While it seems unlikely, this can actually happen if
139 * a controller has P2P bridges under it.
140 */
141 xenbus_dev_fatal(pdev->xdev, -ENOSPC, "Virtual bus %04x:%02x "
142 "is full, no room to export %04x:%02x:%02x.%x",
143 cntrl_entry->domain, cntrl_entry->bus,
144 pci_domain_nr(dev->bus), dev->bus->number,
145 PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn));
146 ret = -ENOSPC;
147 goto out;
148 }
149
150 dev_entry = kmalloc(sizeof(*dev_entry), GFP_ATOMIC);
151 if (!dev_entry) {
152 if (list_empty(&cntrl_entry->dev_list)) {
153 list_del(&cntrl_entry->list);
154 kfree(cntrl_entry);
155 }
156 ret = -ENOMEM;
157 goto out;
158 }
159
160 dev_entry->dev = dev;
161 dev_entry->devfn = cntrl_entry->next_devfn;
162
163 list_add_tail(&dev_entry->list, &cntrl_entry->dev_list);
164
165 cntrl_entry->next_devfn += PCI_DEVFN(1, 0);
166
167out:
168 spin_unlock_irqrestore(&dev_data->lock, flags);
169
170 /* TODO: Publish virtual domain:bus:slot.func here. */
171
172 return ret;
173}
174
175void pciback_release_pci_dev(struct pciback_device *pdev, struct pci_dev *dev)
176{
177 struct controller_dev_data *dev_data = pdev->pci_dev_data;
178 struct controller_list_entry *cntrl_entry;
179 struct controller_dev_entry *dev_entry = NULL;
180 struct pci_dev *found_dev = NULL;
181 unsigned long flags;
182
183 spin_lock_irqsave(&dev_data->lock, flags);
184
185 list_for_each_entry(cntrl_entry, &dev_data->list, list) {
186 if (cntrl_entry->controller != PCI_CONTROLLER(dev))
187 continue;
188
189 list_for_each_entry(dev_entry, &cntrl_entry->dev_list, list) {
190 if (dev_entry->dev == dev) {
191 found_dev = dev_entry->dev;
192 break;
193 }
194 }
195 }
196
197 if (!found_dev) {
198 spin_unlock_irqrestore(&dev_data->lock, flags);
199 return;
200 }
201
202 list_del(&dev_entry->list);
203 kfree(dev_entry);
204
205 if (list_empty(&cntrl_entry->dev_list)) {
206 list_del(&cntrl_entry->list);
207 kfree(cntrl_entry);
208 }
209
210 spin_unlock_irqrestore(&dev_data->lock, flags);
211 pcistub_put_pci_dev(found_dev);
212}
213
214int pciback_init_devices(struct pciback_device *pdev)
215{
216 struct controller_dev_data *dev_data;
217
218 dev_data = kmalloc(sizeof(*dev_data), GFP_KERNEL);
219 if (!dev_data)
220 return -ENOMEM;
221
222 spin_lock_init(&dev_data->lock);
223
224 INIT_LIST_HEAD(&dev_data->list);
225
226 /* Starting domain:bus numbers */
227 dev_data->next_domain = 0;
228 dev_data->next_bus = 0;
229
230 pdev->pci_dev_data = dev_data;
231
232 return 0;
233}
234
235static acpi_status write_xenbus_resource(struct acpi_resource *res, void *data)
236{
237 struct walk_info *info = data;
238 struct acpi_resource_address64 addr;
239 acpi_status status;
240 int i, len, err;
241 char str[32], tmp[3];
242 unsigned char *ptr, *buf;
243
244 status = acpi_resource_to_address64(res, &addr);
245
246 /* Do we care about this range? Let's check. */
247 if (!ACPI_SUCCESS(status) ||
248 !(addr.resource_type == ACPI_MEMORY_RANGE ||
249 addr.resource_type == ACPI_IO_RANGE) ||
250 !addr.address_length || addr.producer_consumer != ACPI_PRODUCER)
251 return AE_OK;
252
253 /*
254 * Furthermore, we really only care to tell the guest about
255 * address ranges that require address translation of some sort.
256 */
257 if (!(addr.resource_type == ACPI_MEMORY_RANGE &&
258 addr.info.mem.translation) &&
259 !(addr.resource_type == ACPI_IO_RANGE &&
260 addr.info.io.translation))
261 return AE_OK;
262
263 /* Store the resource in xenbus for the guest */
264 len = snprintf(str, sizeof(str), "root-%d-resource-%d",
265 info->root_num, info->resource_count);
266 if (unlikely(len >= (sizeof(str) - 1)))
267 return AE_OK;
268
269 buf = kzalloc((sizeof(*res) * 2) + 1, GFP_KERNEL);
270 if (!buf)
271 return AE_OK;
272
273 /* Clean out resource_source */
274 res->data.address64.resource_source.index = 0xFF;
275 res->data.address64.resource_source.string_length = 0;
276 res->data.address64.resource_source.string_ptr = NULL;
277
278 ptr = (unsigned char *)res;
279
280 /* Turn the acpi_resource into an ASCII byte stream */
281 for (i = 0; i < sizeof(*res); i++) {
282 snprintf(tmp, sizeof(tmp), "%02x", ptr[i]);
283 strncat(buf, tmp, 2);
284 }
285
286 err = xenbus_printf(XBT_NIL, info->pdev->xdev->nodename,
287 str, "%s", buf);
288
289 if (!err)
290 info->resource_count++;
291
292 kfree(buf);
293
294 return AE_OK;
295}
296
297int pciback_publish_pci_roots(struct pciback_device *pdev,
298 publish_pci_root_cb publish_root_cb)
299{
300 struct controller_dev_data *dev_data = pdev->pci_dev_data;
301 struct controller_list_entry *cntrl_entry;
302 int i, root_num, len, err = 0;
303 unsigned int domain, bus;
304 char str[64];
305 struct walk_info info;
306
307 spin_lock(&dev_data->lock);
308
309 list_for_each_entry(cntrl_entry, &dev_data->list, list) {
310 /* First publish all the domain:bus info */
311 err = publish_root_cb(pdev, cntrl_entry->domain,
312 cntrl_entry->bus);
313 if (err)
314 goto out;
315
316 /*
317 * Now figure out which root-%d this belongs to
318 * so we can associate resources with it.
319 */
320 err = xenbus_scanf(XBT_NIL, pdev->xdev->nodename,
321 "root_num", "%d", &root_num);
322
323 if (err != 1)
324 goto out;
325
326 for (i = 0; i < root_num; i++) {
327 len = snprintf(str, sizeof(str), "root-%d", i);
328 if (unlikely(len >= (sizeof(str) - 1))) {
329 err = -ENOMEM;
330 goto out;
331 }
332
333 err = xenbus_scanf(XBT_NIL, pdev->xdev->nodename,
334 str, "%x:%x", &domain, &bus);
335 if (err != 2)
336 goto out;
337
338 /* Is this the one we just published? */
339 if (domain == cntrl_entry->domain &&
340 bus == cntrl_entry->bus)
341 break;
342 }
343
344 if (i == root_num)
345 goto out;
346
347 info.pdev = pdev;
348 info.resource_count = 0;
349 info.root_num = i;
350
351 /* Let ACPI do the heavy lifting on decoding resources */
352 acpi_walk_resources(cntrl_entry->controller->acpi_handle,
353 METHOD_NAME__CRS, write_xenbus_resource,
354 &info);
355
356 /* No resouces. OK. On to the next one */
357 if (!info.resource_count)
358 continue;
359
360 /* Store the number of resources we wrote for this root-%d */
361 len = snprintf(str, sizeof(str), "root-%d-resources", i);
362 if (unlikely(len >= (sizeof(str) - 1))) {
363 err = -ENOMEM;
364 goto out;
365 }
366
367 err = xenbus_printf(XBT_NIL, pdev->xdev->nodename, str,
368 "%d", info.resource_count);
369 if (err)
370 goto out;
371 }
372
373 /* Finally, write some magic to synchronize with the guest. */
374 len = snprintf(str, sizeof(str), "root-resource-magic");
375 if (unlikely(len >= (sizeof(str) - 1))) {
376 err = -ENOMEM;
377 goto out;
378 }
379
380 err = xenbus_printf(XBT_NIL, pdev->xdev->nodename, str,
381 "%lx", (sizeof(struct acpi_resource) * 2) + 1);
382
383out:
384 spin_unlock(&dev_data->lock);
385
386 return err;
387}
388
389void pciback_release_devices(struct pciback_device *pdev)
390{
391 struct controller_dev_data *dev_data = pdev->pci_dev_data;
392 struct controller_list_entry *cntrl_entry, *c;
393 struct controller_dev_entry *dev_entry, *d;
394
395 list_for_each_entry_safe(cntrl_entry, c, &dev_data->list, list) {
396 list_for_each_entry_safe(dev_entry, d,
397 &cntrl_entry->dev_list, list) {
398 list_del(&dev_entry->list);
399 pcistub_put_pci_dev(dev_entry->dev);
400 kfree(dev_entry);
401 }
402 list_del(&cntrl_entry->list);
403 kfree(cntrl_entry);
404 }
405
406 kfree(dev_data);
407 pdev->pci_dev_data = NULL;
408}
409
410int pciback_get_pcifront_dev(struct pci_dev *pcidev,
411 struct pciback_device *pdev,
412 unsigned int *domain, unsigned int *bus, unsigned int *devfn)
413{
414 struct controller_dev_data *dev_data = pdev->pci_dev_data;
415 struct controller_dev_entry *dev_entry;
416 struct controller_list_entry *cntrl_entry;
417 unsigned long flags;
418 int found = 0;
419 spin_lock_irqsave(&dev_data->lock, flags);
420
421 list_for_each_entry(cntrl_entry, &dev_data->list, list) {
422 list_for_each_entry(dev_entry, &cntrl_entry->dev_list, list) {
423 if ((dev_entry->dev->bus->number ==
424 pcidev->bus->number) &&
425 (dev_entry->dev->devfn ==
426 pcidev->devfn) &&
427 (pci_domain_nr(dev_entry->dev->bus) ==
428 pci_domain_nr(pcidev->bus))) {
429 found = 1;
430 *domain = cntrl_entry->domain;
431 *bus = cntrl_entry->bus;
432 *devfn = dev_entry->devfn;
433 goto out;
434 }
435 }
436 }
437out:
438 spin_unlock_irqrestore(&dev_data->lock, flags);
439 return found;
440
441}
442
diff --git a/drivers/xen/xen-pciback/passthrough.c b/drivers/xen/xen-pciback/passthrough.c
index 6e3999b997d4..b451cb8dd2ff 100644
--- a/drivers/xen/xen-pciback/passthrough.c
+++ b/drivers/xen/xen-pciback/passthrough.c
@@ -16,9 +16,9 @@ struct passthrough_dev_data {
16 spinlock_t lock; 16 spinlock_t lock;
17}; 17};
18 18
19struct pci_dev *pciback_get_pci_dev(struct pciback_device *pdev, 19struct pci_dev *xen_pcibk_get_pci_dev(struct xen_pcibk_device *pdev,
20 unsigned int domain, unsigned int bus, 20 unsigned int domain, unsigned int bus,
21 unsigned int devfn) 21 unsigned int devfn)
22{ 22{
23 struct passthrough_dev_data *dev_data = pdev->pci_dev_data; 23 struct passthrough_dev_data *dev_data = pdev->pci_dev_data;
24 struct pci_dev_entry *dev_entry; 24 struct pci_dev_entry *dev_entry;
@@ -41,8 +41,8 @@ struct pci_dev *pciback_get_pci_dev(struct pciback_device *pdev,
41 return dev; 41 return dev;
42} 42}
43 43
44int pciback_add_pci_dev(struct pciback_device *pdev, struct pci_dev *dev, 44int xen_pcibk_add_pci_dev(struct xen_pcibk_device *pdev, struct pci_dev *dev,
45 int devid, publish_pci_dev_cb publish_cb) 45 int devid, publish_pci_dev_cb publish_cb)
46{ 46{
47 struct passthrough_dev_data *dev_data = pdev->pci_dev_data; 47 struct passthrough_dev_data *dev_data = pdev->pci_dev_data;
48 struct pci_dev_entry *dev_entry; 48 struct pci_dev_entry *dev_entry;
@@ -68,7 +68,8 @@ int pciback_add_pci_dev(struct pciback_device *pdev, struct pci_dev *dev,
68 return err; 68 return err;
69} 69}
70 70
71void pciback_release_pci_dev(struct pciback_device *pdev, struct pci_dev *dev) 71void xen_pcibk_release_pci_dev(struct xen_pcibk_device *pdev,
72 struct pci_dev *dev)
72{ 73{
73 struct passthrough_dev_data *dev_data = pdev->pci_dev_data; 74 struct passthrough_dev_data *dev_data = pdev->pci_dev_data;
74 struct pci_dev_entry *dev_entry, *t; 75 struct pci_dev_entry *dev_entry, *t;
@@ -91,7 +92,7 @@ void pciback_release_pci_dev(struct pciback_device *pdev, struct pci_dev *dev)
91 pcistub_put_pci_dev(found_dev); 92 pcistub_put_pci_dev(found_dev);
92} 93}
93 94
94int pciback_init_devices(struct pciback_device *pdev) 95int xen_pcibk_init_devices(struct xen_pcibk_device *pdev)
95{ 96{
96 struct passthrough_dev_data *dev_data; 97 struct passthrough_dev_data *dev_data;
97 98
@@ -108,8 +109,8 @@ int pciback_init_devices(struct pciback_device *pdev)
108 return 0; 109 return 0;
109} 110}
110 111
111int pciback_publish_pci_roots(struct pciback_device *pdev, 112int xen_pcibk_publish_pci_roots(struct xen_pcibk_device *pdev,
112 publish_pci_root_cb publish_root_cb) 113 publish_pci_root_cb publish_root_cb)
113{ 114{
114 int err = 0; 115 int err = 0;
115 struct passthrough_dev_data *dev_data = pdev->pci_dev_data; 116 struct passthrough_dev_data *dev_data = pdev->pci_dev_data;
@@ -153,7 +154,7 @@ int pciback_publish_pci_roots(struct pciback_device *pdev,
153 return err; 154 return err;
154} 155}
155 156
156void pciback_release_devices(struct pciback_device *pdev) 157void xen_pcibk_release_devices(struct xen_pcibk_device *pdev)
157{ 158{
158 struct passthrough_dev_data *dev_data = pdev->pci_dev_data; 159 struct passthrough_dev_data *dev_data = pdev->pci_dev_data;
159 struct pci_dev_entry *dev_entry, *t; 160 struct pci_dev_entry *dev_entry, *t;
@@ -168,11 +169,10 @@ void pciback_release_devices(struct pciback_device *pdev)
168 pdev->pci_dev_data = NULL; 169 pdev->pci_dev_data = NULL;
169} 170}
170 171
171int pciback_get_pcifront_dev(struct pci_dev *pcidev, 172int xen_pcibk_get_pcifront_dev(struct pci_dev *pcidev,
172 struct pciback_device *pdev, 173 struct xen_pcibk_device *pdev,
173 unsigned int *domain, unsigned int *bus, 174 unsigned int *domain, unsigned int *bus,
174 unsigned int *devfn) 175 unsigned int *devfn)
175
176{ 176{
177 *domain = pci_domain_nr(pcidev->bus); 177 *domain = pci_domain_nr(pcidev->bus);
178 *bus = pcidev->bus->number; 178 *bus = pcidev->bus->number;
diff --git a/drivers/xen/xen-pciback/pci_stub.c b/drivers/xen/xen-pciback/pci_stub.c
index c4d1071ebbe6..aec214ac0a14 100644
--- a/drivers/xen/xen-pciback/pci_stub.c
+++ b/drivers/xen/xen-pciback/pci_stub.c
@@ -21,12 +21,12 @@
21#include "conf_space.h" 21#include "conf_space.h"
22#include "conf_space_quirks.h" 22#include "conf_space_quirks.h"
23 23
24#define DRV_NAME "pciback" 24#define DRV_NAME "xen-pciback"
25 25
26static char *pci_devs_to_hide; 26static char *pci_devs_to_hide;
27wait_queue_head_t aer_wait_queue; 27wait_queue_head_t xen_pcibk_aer_wait_queue;
28/*Add sem for sync AER handling and pciback remove/reconfigue ops, 28/*Add sem for sync AER handling and xen_pcibk remove/reconfigue ops,
29* We want to avoid in middle of AER ops, pciback devices is being removed 29* We want to avoid in middle of AER ops, xen_pcibk devices is being removed
30*/ 30*/
31static DECLARE_RWSEM(pcistub_sem); 31static DECLARE_RWSEM(pcistub_sem);
32module_param_named(hide, pci_devs_to_hide, charp, 0444); 32module_param_named(hide, pci_devs_to_hide, charp, 0444);
@@ -46,7 +46,7 @@ struct pcistub_device {
46 spinlock_t lock; 46 spinlock_t lock;
47 47
48 struct pci_dev *dev; 48 struct pci_dev *dev;
49 struct pciback_device *pdev;/* non-NULL if struct pci_dev is in use */ 49 struct xen_pcibk_device *pdev;/* non-NULL if struct pci_dev is in use */
50}; 50};
51 51
52/* Access to pcistub_devices & seized_devices lists and the initialize_devices 52/* Access to pcistub_devices & seized_devices lists and the initialize_devices
@@ -95,9 +95,9 @@ static void pcistub_device_release(struct kref *kref)
95 xen_unregister_device_domain_owner(psdev->dev); 95 xen_unregister_device_domain_owner(psdev->dev);
96 96
97 /* Clean-up the device */ 97 /* Clean-up the device */
98 pciback_reset_device(psdev->dev); 98 xen_pcibk_reset_device(psdev->dev);
99 pciback_config_free_dyn_fields(psdev->dev); 99 xen_pcibk_config_free_dyn_fields(psdev->dev);
100 pciback_config_free_dev(psdev->dev); 100 xen_pcibk_config_free_dev(psdev->dev);
101 kfree(pci_get_drvdata(psdev->dev)); 101 kfree(pci_get_drvdata(psdev->dev));
102 pci_set_drvdata(psdev->dev, NULL); 102 pci_set_drvdata(psdev->dev, NULL);
103 103
@@ -142,7 +142,7 @@ out:
142 return psdev; 142 return psdev;
143} 143}
144 144
145static struct pci_dev *pcistub_device_get_pci_dev(struct pciback_device *pdev, 145static struct pci_dev *pcistub_device_get_pci_dev(struct xen_pcibk_device *pdev,
146 struct pcistub_device *psdev) 146 struct pcistub_device *psdev)
147{ 147{
148 struct pci_dev *pci_dev = NULL; 148 struct pci_dev *pci_dev = NULL;
@@ -163,7 +163,7 @@ static struct pci_dev *pcistub_device_get_pci_dev(struct pciback_device *pdev,
163 return pci_dev; 163 return pci_dev;
164} 164}
165 165
166struct pci_dev *pcistub_get_pci_dev_by_slot(struct pciback_device *pdev, 166struct pci_dev *pcistub_get_pci_dev_by_slot(struct xen_pcibk_device *pdev,
167 int domain, int bus, 167 int domain, int bus,
168 int slot, int func) 168 int slot, int func)
169{ 169{
@@ -187,7 +187,7 @@ struct pci_dev *pcistub_get_pci_dev_by_slot(struct pciback_device *pdev,
187 return found_dev; 187 return found_dev;
188} 188}
189 189
190struct pci_dev *pcistub_get_pci_dev(struct pciback_device *pdev, 190struct pci_dev *pcistub_get_pci_dev(struct xen_pcibk_device *pdev,
191 struct pci_dev *dev) 191 struct pci_dev *dev)
192{ 192{
193 struct pcistub_device *psdev; 193 struct pcistub_device *psdev;
@@ -224,15 +224,15 @@ void pcistub_put_pci_dev(struct pci_dev *dev)
224 spin_unlock_irqrestore(&pcistub_devices_lock, flags); 224 spin_unlock_irqrestore(&pcistub_devices_lock, flags);
225 225
226 /*hold this lock for avoiding breaking link between 226 /*hold this lock for avoiding breaking link between
227 * pcistub and pciback when AER is in processing 227 * pcistub and xen_pcibk when AER is in processing
228 */ 228 */
229 down_write(&pcistub_sem); 229 down_write(&pcistub_sem);
230 /* Cleanup our device 230 /* Cleanup our device
231 * (so it's ready for the next domain) 231 * (so it's ready for the next domain)
232 */ 232 */
233 pciback_reset_device(found_psdev->dev); 233 xen_pcibk_reset_device(found_psdev->dev);
234 pciback_config_free_dyn_fields(found_psdev->dev); 234 xen_pcibk_config_free_dyn_fields(found_psdev->dev);
235 pciback_config_reset_dev(found_psdev->dev); 235 xen_pcibk_config_reset_dev(found_psdev->dev);
236 236
237 spin_lock_irqsave(&found_psdev->lock, flags); 237 spin_lock_irqsave(&found_psdev->lock, flags);
238 found_psdev->pdev = NULL; 238 found_psdev->pdev = NULL;
@@ -282,13 +282,13 @@ static int __devinit pcistub_match(struct pci_dev *dev)
282 282
283static int __devinit pcistub_init_device(struct pci_dev *dev) 283static int __devinit pcistub_init_device(struct pci_dev *dev)
284{ 284{
285 struct pciback_dev_data *dev_data; 285 struct xen_pcibk_dev_data *dev_data;
286 int err = 0; 286 int err = 0;
287 287
288 dev_dbg(&dev->dev, "initializing...\n"); 288 dev_dbg(&dev->dev, "initializing...\n");
289 289
290 /* The PCI backend is not intended to be a module (or to work with 290 /* The PCI backend is not intended to be a module (or to work with
291 * removable PCI devices (yet). If it were, pciback_config_free() 291 * removable PCI devices (yet). If it were, xen_pcibk_config_free()
292 * would need to be called somewhere to free the memory allocated 292 * would need to be called somewhere to free the memory allocated
293 * here and then to call kfree(pci_get_drvdata(psdev->dev)). 293 * here and then to call kfree(pci_get_drvdata(psdev->dev)).
294 */ 294 */
@@ -308,8 +308,8 @@ static int __devinit pcistub_init_device(struct pci_dev *dev)
308 308
309 dev_dbg(&dev->dev, "initializing config\n"); 309 dev_dbg(&dev->dev, "initializing config\n");
310 310
311 init_waitqueue_head(&aer_wait_queue); 311 init_waitqueue_head(&xen_pcibk_aer_wait_queue);
312 err = pciback_config_init_dev(dev); 312 err = xen_pcibk_config_init_dev(dev);
313 if (err) 313 if (err)
314 goto out; 314 goto out;
315 315
@@ -329,12 +329,12 @@ static int __devinit pcistub_init_device(struct pci_dev *dev)
329 * data is setup before we export) 329 * data is setup before we export)
330 */ 330 */
331 dev_dbg(&dev->dev, "reset device\n"); 331 dev_dbg(&dev->dev, "reset device\n");
332 pciback_reset_device(dev); 332 xen_pcibk_reset_device(dev);
333 333
334 return 0; 334 return 0;
335 335
336config_release: 336config_release:
337 pciback_config_free_dev(dev); 337 xen_pcibk_config_free_dev(dev);
338 338
339out: 339out:
340 pci_set_drvdata(dev, NULL); 340 pci_set_drvdata(dev, NULL);
@@ -354,7 +354,7 @@ static int __init pcistub_init_devices_late(void)
354 unsigned long flags; 354 unsigned long flags;
355 int err = 0; 355 int err = 0;
356 356
357 pr_debug("pciback: pcistub_init_devices_late\n"); 357 pr_debug(DRV_NAME ": pcistub_init_devices_late\n");
358 358
359 spin_lock_irqsave(&pcistub_devices_lock, flags); 359 spin_lock_irqsave(&pcistub_devices_lock, flags);
360 360
@@ -458,7 +458,7 @@ static void pcistub_remove(struct pci_dev *dev)
458 458
459 spin_lock_irqsave(&pcistub_devices_lock, flags); 459 spin_lock_irqsave(&pcistub_devices_lock, flags);
460 460
461 pciback_config_quirk_release(dev); 461 xen_pcibk_config_quirk_release(dev);
462 462
463 list_for_each_entry(psdev, &pcistub_devices, dev_list) { 463 list_for_each_entry(psdev, &pcistub_devices, dev_list) {
464 if (psdev->dev == dev) { 464 if (psdev->dev == dev) {
@@ -474,17 +474,17 @@ static void pcistub_remove(struct pci_dev *dev)
474 found_psdev->pdev); 474 found_psdev->pdev);
475 475
476 if (found_psdev->pdev) { 476 if (found_psdev->pdev) {
477 printk(KERN_WARNING "pciback: ****** removing device " 477 printk(KERN_WARNING DRV_NAME ": ****** removing device "
478 "%s while still in-use! ******\n", 478 "%s while still in-use! ******\n",
479 pci_name(found_psdev->dev)); 479 pci_name(found_psdev->dev));
480 printk(KERN_WARNING "pciback: ****** driver domain may " 480 printk(KERN_WARNING DRV_NAME ": ****** driver domain may"
481 "still access this device's i/o resources!\n"); 481 " still access this device's i/o resources!\n");
482 printk(KERN_WARNING "pciback: ****** shutdown driver " 482 printk(KERN_WARNING DRV_NAME ": ****** shutdown driver "
483 "domain before binding device\n"); 483 "domain before binding device\n");
484 printk(KERN_WARNING "pciback: ****** to other drivers " 484 printk(KERN_WARNING DRV_NAME ": ****** to other drivers "
485 "or domains\n"); 485 "or domains\n");
486 486
487 pciback_release_pci_dev(found_psdev->pdev, 487 xen_pcibk_release_pci_dev(found_psdev->pdev,
488 found_psdev->dev); 488 found_psdev->dev);
489 } 489 }
490 490
@@ -541,11 +541,12 @@ again:
541} 541}
542 542
543/* For each aer recovery step error_detected, mmio_enabled, etc, front_end and 543/* For each aer recovery step error_detected, mmio_enabled, etc, front_end and
544 * backend need to have cooperation. In pciback, those steps will do similar 544 * backend need to have cooperation. In xen_pcibk, those steps will do similar
545 * jobs: send service request and waiting for front_end response. 545 * jobs: send service request and waiting for front_end response.
546*/ 546*/
547static pci_ers_result_t common_process(struct pcistub_device *psdev, 547static pci_ers_result_t common_process(struct pcistub_device *psdev,
548 pci_channel_state_t state, int aer_cmd, pci_ers_result_t result) 548 pci_channel_state_t state, int aer_cmd,
549 pci_ers_result_t result)
549{ 550{
550 pci_ers_result_t res = result; 551 pci_ers_result_t res = result;
551 struct xen_pcie_aer_op *aer_op; 552 struct xen_pcie_aer_op *aer_op;
@@ -557,21 +558,21 @@ static pci_ers_result_t common_process(struct pcistub_device *psdev,
557 /*useful for error_detected callback*/ 558 /*useful for error_detected callback*/
558 aer_op->err = state; 559 aer_op->err = state;
559 /*pcifront_end BDF*/ 560 /*pcifront_end BDF*/
560 ret = pciback_get_pcifront_dev(psdev->dev, psdev->pdev, 561 ret = xen_pcibk_get_pcifront_dev(psdev->dev, psdev->pdev,
561 &aer_op->domain, &aer_op->bus, &aer_op->devfn); 562 &aer_op->domain, &aer_op->bus, &aer_op->devfn);
562 if (!ret) { 563 if (!ret) {
563 dev_err(&psdev->dev->dev, 564 dev_err(&psdev->dev->dev,
564 "pciback: failed to get pcifront device\n"); 565 DRV_NAME ": failed to get pcifront device\n");
565 return PCI_ERS_RESULT_NONE; 566 return PCI_ERS_RESULT_NONE;
566 } 567 }
567 wmb(); 568 wmb();
568 569
569 dev_dbg(&psdev->dev->dev, 570 dev_dbg(&psdev->dev->dev,
570 "pciback: aer_op %x dom %x bus %x devfn %x\n", 571 DRV_NAME ": aer_op %x dom %x bus %x devfn %x\n",
571 aer_cmd, aer_op->domain, aer_op->bus, aer_op->devfn); 572 aer_cmd, aer_op->domain, aer_op->bus, aer_op->devfn);
572 /*local flag to mark there's aer request, pciback callback will use this 573 /*local flag to mark there's aer request, xen_pcibk callback will use
573 * flag to judge whether we need to check pci-front give aer service 574 * this flag to judge whether we need to check pci-front give aer
574 * ack signal 575 * service ack signal
575 */ 576 */
576 set_bit(_PCIB_op_pending, (unsigned long *)&psdev->pdev->flags); 577 set_bit(_PCIB_op_pending, (unsigned long *)&psdev->pdev->flags);
577 578
@@ -584,8 +585,9 @@ static pci_ers_result_t common_process(struct pcistub_device *psdev,
584 wmb(); 585 wmb();
585 notify_remote_via_irq(psdev->pdev->evtchn_irq); 586 notify_remote_via_irq(psdev->pdev->evtchn_irq);
586 587
587 ret = wait_event_timeout(aer_wait_queue, !(test_bit(_XEN_PCIB_active, 588 ret = wait_event_timeout(xen_pcibk_aer_wait_queue,
588 (unsigned long *)&psdev->pdev->sh_info->flags)), 300*HZ); 589 !(test_bit(_XEN_PCIB_active, (unsigned long *)
590 &psdev->pdev->sh_info->flags)), 300*HZ);
589 591
590 if (!ret) { 592 if (!ret) {
591 if (test_bit(_XEN_PCIB_active, 593 if (test_bit(_XEN_PCIB_active,
@@ -603,8 +605,8 @@ static pci_ers_result_t common_process(struct pcistub_device *psdev,
603 if (test_bit(_XEN_PCIF_active, 605 if (test_bit(_XEN_PCIF_active,
604 (unsigned long *)&psdev->pdev->sh_info->flags)) { 606 (unsigned long *)&psdev->pdev->sh_info->flags)) {
605 dev_dbg(&psdev->dev->dev, 607 dev_dbg(&psdev->dev->dev,
606 "schedule pci_conf service in pciback\n"); 608 "schedule pci_conf service in xen_pcibk\n");
607 test_and_schedule_op(psdev->pdev); 609 xen_pcibk_test_and_schedule_op(psdev->pdev);
608 } 610 }
609 611
610 res = (pci_ers_result_t)aer_op->err; 612 res = (pci_ers_result_t)aer_op->err;
@@ -612,19 +614,19 @@ static pci_ers_result_t common_process(struct pcistub_device *psdev,
612} 614}
613 615
614/* 616/*
615* pciback_slot_reset: it will send the slot_reset request to pcifront in case 617* xen_pcibk_slot_reset: it will send the slot_reset request to pcifront in case
616* of the device driver could provide this service, and then wait for pcifront 618* of the device driver could provide this service, and then wait for pcifront
617* ack. 619* ack.
618* @dev: pointer to PCI devices 620* @dev: pointer to PCI devices
619* return value is used by aer_core do_recovery policy 621* return value is used by aer_core do_recovery policy
620*/ 622*/
621static pci_ers_result_t pciback_slot_reset(struct pci_dev *dev) 623static pci_ers_result_t xen_pcibk_slot_reset(struct pci_dev *dev)
622{ 624{
623 struct pcistub_device *psdev; 625 struct pcistub_device *psdev;
624 pci_ers_result_t result; 626 pci_ers_result_t result;
625 627
626 result = PCI_ERS_RESULT_RECOVERED; 628 result = PCI_ERS_RESULT_RECOVERED;
627 dev_dbg(&dev->dev, "pciback_slot_reset(bus:%x,devfn:%x)\n", 629 dev_dbg(&dev->dev, "xen_pcibk_slot_reset(bus:%x,devfn:%x)\n",
628 dev->bus->number, dev->devfn); 630 dev->bus->number, dev->devfn);
629 631
630 down_write(&pcistub_sem); 632 down_write(&pcistub_sem);
@@ -635,12 +637,12 @@ static pci_ers_result_t pciback_slot_reset(struct pci_dev *dev)
635 637
636 if (!psdev || !psdev->pdev) { 638 if (!psdev || !psdev->pdev) {
637 dev_err(&dev->dev, 639 dev_err(&dev->dev,
638 "pciback device is not found/assigned\n"); 640 DRV_NAME " device is not found/assigned\n");
639 goto end; 641 goto end;
640 } 642 }
641 643
642 if (!psdev->pdev->sh_info) { 644 if (!psdev->pdev->sh_info) {
643 dev_err(&dev->dev, "pciback device is not connected or owned" 645 dev_err(&dev->dev, DRV_NAME " device is not connected or owned"
644 " by HVM, kill it\n"); 646 " by HVM, kill it\n");
645 kill_domain_by_device(psdev); 647 kill_domain_by_device(psdev);
646 goto release; 648 goto release;
@@ -669,20 +671,20 @@ end:
669} 671}
670 672
671 673
672/*pciback_mmio_enabled: it will send the mmio_enabled request to pcifront 674/*xen_pcibk_mmio_enabled: it will send the mmio_enabled request to pcifront
673* in case of the device driver could provide this service, and then wait 675* in case of the device driver could provide this service, and then wait
674* for pcifront ack 676* for pcifront ack
675* @dev: pointer to PCI devices 677* @dev: pointer to PCI devices
676* return value is used by aer_core do_recovery policy 678* return value is used by aer_core do_recovery policy
677*/ 679*/
678 680
679static pci_ers_result_t pciback_mmio_enabled(struct pci_dev *dev) 681static pci_ers_result_t xen_pcibk_mmio_enabled(struct pci_dev *dev)
680{ 682{
681 struct pcistub_device *psdev; 683 struct pcistub_device *psdev;
682 pci_ers_result_t result; 684 pci_ers_result_t result;
683 685
684 result = PCI_ERS_RESULT_RECOVERED; 686 result = PCI_ERS_RESULT_RECOVERED;
685 dev_dbg(&dev->dev, "pciback_mmio_enabled(bus:%x,devfn:%x)\n", 687 dev_dbg(&dev->dev, "xen_pcibk_mmio_enabled(bus:%x,devfn:%x)\n",
686 dev->bus->number, dev->devfn); 688 dev->bus->number, dev->devfn);
687 689
688 down_write(&pcistub_sem); 690 down_write(&pcistub_sem);
@@ -693,12 +695,12 @@ static pci_ers_result_t pciback_mmio_enabled(struct pci_dev *dev)
693 695
694 if (!psdev || !psdev->pdev) { 696 if (!psdev || !psdev->pdev) {
695 dev_err(&dev->dev, 697 dev_err(&dev->dev,
696 "pciback device is not found/assigned\n"); 698 DRV_NAME " device is not found/assigned\n");
697 goto end; 699 goto end;
698 } 700 }
699 701
700 if (!psdev->pdev->sh_info) { 702 if (!psdev->pdev->sh_info) {
701 dev_err(&dev->dev, "pciback device is not connected or owned" 703 dev_err(&dev->dev, DRV_NAME " device is not connected or owned"
702 " by HVM, kill it\n"); 704 " by HVM, kill it\n");
703 kill_domain_by_device(psdev); 705 kill_domain_by_device(psdev);
704 goto release; 706 goto release;
@@ -725,7 +727,7 @@ end:
725 return result; 727 return result;
726} 728}
727 729
728/*pciback_error_detected: it will send the error_detected request to pcifront 730/*xen_pcibk_error_detected: it will send the error_detected request to pcifront
729* in case of the device driver could provide this service, and then wait 731* in case of the device driver could provide this service, and then wait
730* for pcifront ack. 732* for pcifront ack.
731* @dev: pointer to PCI devices 733* @dev: pointer to PCI devices
@@ -733,14 +735,14 @@ end:
733* return value is used by aer_core do_recovery policy 735* return value is used by aer_core do_recovery policy
734*/ 736*/
735 737
736static pci_ers_result_t pciback_error_detected(struct pci_dev *dev, 738static pci_ers_result_t xen_pcibk_error_detected(struct pci_dev *dev,
737 pci_channel_state_t error) 739 pci_channel_state_t error)
738{ 740{
739 struct pcistub_device *psdev; 741 struct pcistub_device *psdev;
740 pci_ers_result_t result; 742 pci_ers_result_t result;
741 743
742 result = PCI_ERS_RESULT_CAN_RECOVER; 744 result = PCI_ERS_RESULT_CAN_RECOVER;
743 dev_dbg(&dev->dev, "pciback_error_detected(bus:%x,devfn:%x)\n", 745 dev_dbg(&dev->dev, "xen_pcibk_error_detected(bus:%x,devfn:%x)\n",
744 dev->bus->number, dev->devfn); 746 dev->bus->number, dev->devfn);
745 747
746 down_write(&pcistub_sem); 748 down_write(&pcistub_sem);
@@ -751,12 +753,12 @@ static pci_ers_result_t pciback_error_detected(struct pci_dev *dev,
751 753
752 if (!psdev || !psdev->pdev) { 754 if (!psdev || !psdev->pdev) {
753 dev_err(&dev->dev, 755 dev_err(&dev->dev,
754 "pciback device is not found/assigned\n"); 756 DRV_NAME " device is not found/assigned\n");
755 goto end; 757 goto end;
756 } 758 }
757 759
758 if (!psdev->pdev->sh_info) { 760 if (!psdev->pdev->sh_info) {
759 dev_err(&dev->dev, "pciback device is not connected or owned" 761 dev_err(&dev->dev, DRV_NAME " device is not connected or owned"
760 " by HVM, kill it\n"); 762 " by HVM, kill it\n");
761 kill_domain_by_device(psdev); 763 kill_domain_by_device(psdev);
762 goto release; 764 goto release;
@@ -784,17 +786,17 @@ end:
784 return result; 786 return result;
785} 787}
786 788
787/*pciback_error_resume: it will send the error_resume request to pcifront 789/*xen_pcibk_error_resume: it will send the error_resume request to pcifront
788* in case of the device driver could provide this service, and then wait 790* in case of the device driver could provide this service, and then wait
789* for pcifront ack. 791* for pcifront ack.
790* @dev: pointer to PCI devices 792* @dev: pointer to PCI devices
791*/ 793*/
792 794
793static void pciback_error_resume(struct pci_dev *dev) 795static void xen_pcibk_error_resume(struct pci_dev *dev)
794{ 796{
795 struct pcistub_device *psdev; 797 struct pcistub_device *psdev;
796 798
797 dev_dbg(&dev->dev, "pciback_error_resume(bus:%x,devfn:%x)\n", 799 dev_dbg(&dev->dev, "xen_pcibk_error_resume(bus:%x,devfn:%x)\n",
798 dev->bus->number, dev->devfn); 800 dev->bus->number, dev->devfn);
799 801
800 down_write(&pcistub_sem); 802 down_write(&pcistub_sem);
@@ -805,12 +807,12 @@ static void pciback_error_resume(struct pci_dev *dev)
805 807
806 if (!psdev || !psdev->pdev) { 808 if (!psdev || !psdev->pdev) {
807 dev_err(&dev->dev, 809 dev_err(&dev->dev,
808 "pciback device is not found/assigned\n"); 810 DRV_NAME " device is not found/assigned\n");
809 goto end; 811 goto end;
810 } 812 }
811 813
812 if (!psdev->pdev->sh_info) { 814 if (!psdev->pdev->sh_info) {
813 dev_err(&dev->dev, "pciback device is not connected or owned" 815 dev_err(&dev->dev, DRV_NAME " device is not connected or owned"
814 " by HVM, kill it\n"); 816 " by HVM, kill it\n");
815 kill_domain_by_device(psdev); 817 kill_domain_by_device(psdev);
816 goto release; 818 goto release;
@@ -832,12 +834,12 @@ end:
832 return; 834 return;
833} 835}
834 836
835/*add pciback AER handling*/ 837/*add xen_pcibk AER handling*/
836static struct pci_error_handlers pciback_error_handler = { 838static struct pci_error_handlers xen_pcibk_error_handler = {
837 .error_detected = pciback_error_detected, 839 .error_detected = xen_pcibk_error_detected,
838 .mmio_enabled = pciback_mmio_enabled, 840 .mmio_enabled = xen_pcibk_mmio_enabled,
839 .slot_reset = pciback_slot_reset, 841 .slot_reset = xen_pcibk_slot_reset,
840 .resume = pciback_error_resume, 842 .resume = xen_pcibk_error_resume,
841}; 843};
842 844
843/* 845/*
@@ -845,12 +847,14 @@ static struct pci_error_handlers pciback_error_handler = {
845 * for a normal device. I don't want it to be loaded automatically. 847 * for a normal device. I don't want it to be loaded automatically.
846 */ 848 */
847 849
848static struct pci_driver pciback_pci_driver = { 850static struct pci_driver xen_pcibk_pci_driver = {
849 .name = DRV_NAME, 851 /* The name should be xen_pciback, but until the tools are updated
852 * we will keep it as pciback. */
853 .name = "pciback",
850 .id_table = pcistub_ids, 854 .id_table = pcistub_ids,
851 .probe = pcistub_probe, 855 .probe = pcistub_probe,
852 .remove = pcistub_remove, 856 .remove = pcistub_remove,
853 .err_handler = &pciback_error_handler, 857 .err_handler = &xen_pcibk_error_handler,
854}; 858};
855 859
856static inline int str_to_slot(const char *buf, int *domain, int *bus, 860static inline int str_to_slot(const char *buf, int *domain, int *bus,
@@ -899,7 +903,7 @@ static int pcistub_device_id_add(int domain, int bus, int slot, int func)
899 pci_dev_id->bus = bus; 903 pci_dev_id->bus = bus;
900 pci_dev_id->devfn = PCI_DEVFN(slot, func); 904 pci_dev_id->devfn = PCI_DEVFN(slot, func);
901 905
902 pr_debug("pciback: wants to seize %04x:%02x:%02x.%01x\n", 906 pr_debug(DRV_NAME ": wants to seize %04x:%02x:%02x.%01x\n",
903 domain, bus, slot, func); 907 domain, bus, slot, func);
904 908
905 spin_lock_irqsave(&device_ids_lock, flags); 909 spin_lock_irqsave(&device_ids_lock, flags);
@@ -929,7 +933,7 @@ static int pcistub_device_id_remove(int domain, int bus, int slot, int func)
929 933
930 err = 0; 934 err = 0;
931 935
932 pr_debug("pciback: removed %04x:%02x:%02x.%01x from " 936 pr_debug(DRV_NAME ": removed %04x:%02x:%02x.%01x from "
933 "seize list\n", domain, bus, slot, func); 937 "seize list\n", domain, bus, slot, func);
934 } 938 }
935 } 939 }
@@ -965,9 +969,9 @@ static int pcistub_reg_add(int domain, int bus, int slot, int func, int reg,
965 field->init = NULL; 969 field->init = NULL;
966 field->reset = NULL; 970 field->reset = NULL;
967 field->release = NULL; 971 field->release = NULL;
968 field->clean = pciback_config_field_free; 972 field->clean = xen_pcibk_config_field_free;
969 973
970 err = pciback_config_quirks_add_field(dev, field); 974 err = xen_pcibk_config_quirks_add_field(dev, field);
971 if (err) 975 if (err)
972 kfree(field); 976 kfree(field);
973out: 977out:
@@ -1041,7 +1045,7 @@ DRIVER_ATTR(slots, S_IRUSR, pcistub_slot_show, NULL);
1041static ssize_t pcistub_irq_handler_show(struct device_driver *drv, char *buf) 1045static ssize_t pcistub_irq_handler_show(struct device_driver *drv, char *buf)
1042{ 1046{
1043 struct pcistub_device *psdev; 1047 struct pcistub_device *psdev;
1044 struct pciback_dev_data *dev_data; 1048 struct xen_pcibk_dev_data *dev_data;
1045 size_t count = 0; 1049 size_t count = 0;
1046 unsigned long flags; 1050 unsigned long flags;
1047 1051
@@ -1073,7 +1077,7 @@ static ssize_t pcistub_irq_handler_switch(struct device_driver *drv,
1073 size_t count) 1077 size_t count)
1074{ 1078{
1075 struct pcistub_device *psdev; 1079 struct pcistub_device *psdev;
1076 struct pciback_dev_data *dev_data; 1080 struct xen_pcibk_dev_data *dev_data;
1077 int domain, bus, slot, func; 1081 int domain, bus, slot, func;
1078 int err = -ENOENT; 1082 int err = -ENOENT;
1079 1083
@@ -1127,13 +1131,13 @@ static ssize_t pcistub_quirk_show(struct device_driver *drv, char *buf)
1127{ 1131{
1128 int count = 0; 1132 int count = 0;
1129 unsigned long flags; 1133 unsigned long flags;
1130 struct pciback_config_quirk *quirk; 1134 struct xen_pcibk_config_quirk *quirk;
1131 struct pciback_dev_data *dev_data; 1135 struct xen_pcibk_dev_data *dev_data;
1132 const struct config_field *field; 1136 const struct config_field *field;
1133 const struct config_field_entry *cfg_entry; 1137 const struct config_field_entry *cfg_entry;
1134 1138
1135 spin_lock_irqsave(&device_ids_lock, flags); 1139 spin_lock_irqsave(&device_ids_lock, flags);
1136 list_for_each_entry(quirk, &pciback_quirks, quirks_list) { 1140 list_for_each_entry(quirk, &xen_pcibk_quirks, quirks_list) {
1137 if (count >= PAGE_SIZE) 1141 if (count >= PAGE_SIZE)
1138 goto out; 1142 goto out;
1139 1143
@@ -1175,7 +1179,7 @@ static ssize_t permissive_add(struct device_driver *drv, const char *buf,
1175 int domain, bus, slot, func; 1179 int domain, bus, slot, func;
1176 int err; 1180 int err;
1177 struct pcistub_device *psdev; 1181 struct pcistub_device *psdev;
1178 struct pciback_dev_data *dev_data; 1182 struct xen_pcibk_dev_data *dev_data;
1179 err = str_to_slot(buf, &domain, &bus, &slot, &func); 1183 err = str_to_slot(buf, &domain, &bus, &slot, &func);
1180 if (err) 1184 if (err)
1181 goto out; 1185 goto out;
@@ -1213,7 +1217,7 @@ out:
1213static ssize_t permissive_show(struct device_driver *drv, char *buf) 1217static ssize_t permissive_show(struct device_driver *drv, char *buf)
1214{ 1218{
1215 struct pcistub_device *psdev; 1219 struct pcistub_device *psdev;
1216 struct pciback_dev_data *dev_data; 1220 struct xen_pcibk_dev_data *dev_data;
1217 size_t count = 0; 1221 size_t count = 0;
1218 unsigned long flags; 1222 unsigned long flags;
1219 spin_lock_irqsave(&pcistub_devices_lock, flags); 1223 spin_lock_irqsave(&pcistub_devices_lock, flags);
@@ -1237,17 +1241,18 @@ DRIVER_ATTR(permissive, S_IRUSR | S_IWUSR, permissive_show, permissive_add);
1237 1241
1238static void pcistub_exit(void) 1242static void pcistub_exit(void)
1239{ 1243{
1240 driver_remove_file(&pciback_pci_driver.driver, &driver_attr_new_slot); 1244 driver_remove_file(&xen_pcibk_pci_driver.driver, &driver_attr_new_slot);
1241 driver_remove_file(&pciback_pci_driver.driver, 1245 driver_remove_file(&xen_pcibk_pci_driver.driver,
1242 &driver_attr_remove_slot); 1246 &driver_attr_remove_slot);
1243 driver_remove_file(&pciback_pci_driver.driver, &driver_attr_slots); 1247 driver_remove_file(&xen_pcibk_pci_driver.driver, &driver_attr_slots);
1244 driver_remove_file(&pciback_pci_driver.driver, &driver_attr_quirks); 1248 driver_remove_file(&xen_pcibk_pci_driver.driver, &driver_attr_quirks);
1245 driver_remove_file(&pciback_pci_driver.driver, &driver_attr_permissive); 1249 driver_remove_file(&xen_pcibk_pci_driver.driver,
1246 driver_remove_file(&pciback_pci_driver.driver, 1250 &driver_attr_permissive);
1251 driver_remove_file(&xen_pcibk_pci_driver.driver,
1247 &driver_attr_irq_handlers); 1252 &driver_attr_irq_handlers);
1248 driver_remove_file(&pciback_pci_driver.driver, 1253 driver_remove_file(&xen_pcibk_pci_driver.driver,
1249 &driver_attr_irq_handler_state); 1254 &driver_attr_irq_handler_state);
1250 pci_unregister_driver(&pciback_pci_driver); 1255 pci_unregister_driver(&xen_pcibk_pci_driver);
1251} 1256}
1252 1257
1253static int __init pcistub_init(void) 1258static int __init pcistub_init(void)
@@ -1286,30 +1291,30 @@ static int __init pcistub_init(void)
1286 * first one to get offered PCI devices as they become 1291 * first one to get offered PCI devices as they become
1287 * available (and thus we can be the first to grab them) 1292 * available (and thus we can be the first to grab them)
1288 */ 1293 */
1289 err = pci_register_driver(&pciback_pci_driver); 1294 err = pci_register_driver(&xen_pcibk_pci_driver);
1290 if (err < 0) 1295 if (err < 0)
1291 goto out; 1296 goto out;
1292 1297
1293 err = driver_create_file(&pciback_pci_driver.driver, 1298 err = driver_create_file(&xen_pcibk_pci_driver.driver,
1294 &driver_attr_new_slot); 1299 &driver_attr_new_slot);
1295 if (!err) 1300 if (!err)
1296 err = driver_create_file(&pciback_pci_driver.driver, 1301 err = driver_create_file(&xen_pcibk_pci_driver.driver,
1297 &driver_attr_remove_slot); 1302 &driver_attr_remove_slot);
1298 if (!err) 1303 if (!err)
1299 err = driver_create_file(&pciback_pci_driver.driver, 1304 err = driver_create_file(&xen_pcibk_pci_driver.driver,
1300 &driver_attr_slots); 1305 &driver_attr_slots);
1301 if (!err) 1306 if (!err)
1302 err = driver_create_file(&pciback_pci_driver.driver, 1307 err = driver_create_file(&xen_pcibk_pci_driver.driver,
1303 &driver_attr_quirks); 1308 &driver_attr_quirks);
1304 if (!err) 1309 if (!err)
1305 err = driver_create_file(&pciback_pci_driver.driver, 1310 err = driver_create_file(&xen_pcibk_pci_driver.driver,
1306 &driver_attr_permissive); 1311 &driver_attr_permissive);
1307 1312
1308 if (!err) 1313 if (!err)
1309 err = driver_create_file(&pciback_pci_driver.driver, 1314 err = driver_create_file(&xen_pcibk_pci_driver.driver,
1310 &driver_attr_irq_handlers); 1315 &driver_attr_irq_handlers);
1311 if (!err) 1316 if (!err)
1312 err = driver_create_file(&pciback_pci_driver.driver, 1317 err = driver_create_file(&xen_pcibk_pci_driver.driver,
1313 &driver_attr_irq_handler_state); 1318 &driver_attr_irq_handler_state);
1314 if (err) 1319 if (err)
1315 pcistub_exit(); 1320 pcistub_exit();
@@ -1318,7 +1323,7 @@ out:
1318 return err; 1323 return err;
1319 1324
1320parse_error: 1325parse_error:
1321 printk(KERN_ERR "pciback: Error parsing pci_devs_to_hide at \"%s\"\n", 1326 printk(KERN_ERR DRV_NAME ": Error parsing pci_devs_to_hide at \"%s\"\n",
1322 pci_devs_to_hide + pos); 1327 pci_devs_to_hide + pos);
1323 return -EINVAL; 1328 return -EINVAL;
1324} 1329}
@@ -1326,7 +1331,7 @@ parse_error:
1326#ifndef MODULE 1331#ifndef MODULE
1327/* 1332/*
1328 * fs_initcall happens before device_initcall 1333 * fs_initcall happens before device_initcall
1329 * so pciback *should* get called first (b/c we 1334 * so xen_pcibk *should* get called first (b/c we
1330 * want to suck up any device before other drivers 1335 * want to suck up any device before other drivers
1331 * get a chance by being the first pci device 1336 * get a chance by being the first pci device
1332 * driver to register) 1337 * driver to register)
@@ -1334,14 +1339,14 @@ parse_error:
1334fs_initcall(pcistub_init); 1339fs_initcall(pcistub_init);
1335#endif 1340#endif
1336 1341
1337static int __init pciback_init(void) 1342static int __init xen_pcibk_init(void)
1338{ 1343{
1339 int err; 1344 int err;
1340 1345
1341 if (!xen_initial_domain()) 1346 if (!xen_initial_domain())
1342 return -ENODEV; 1347 return -ENODEV;
1343 1348
1344 err = pciback_config_init(); 1349 err = xen_pcibk_config_init();
1345 if (err) 1350 if (err)
1346 return err; 1351 return err;
1347 1352
@@ -1352,20 +1357,20 @@ static int __init pciback_init(void)
1352#endif 1357#endif
1353 1358
1354 pcistub_init_devices_late(); 1359 pcistub_init_devices_late();
1355 err = pciback_xenbus_register(); 1360 err = xen_pcibk_xenbus_register();
1356 if (err) 1361 if (err)
1357 pcistub_exit(); 1362 pcistub_exit();
1358 1363
1359 return err; 1364 return err;
1360} 1365}
1361 1366
1362static void __exit pciback_cleanup(void) 1367static void __exit xen_pcibk_cleanup(void)
1363{ 1368{
1364 pciback_xenbus_unregister(); 1369 xen_pcibk_xenbus_unregister();
1365 pcistub_exit(); 1370 pcistub_exit();
1366} 1371}
1367 1372
1368module_init(pciback_init); 1373module_init(xen_pcibk_init);
1369module_exit(pciback_cleanup); 1374module_exit(xen_pcibk_cleanup);
1370 1375
1371MODULE_LICENSE("Dual BSD/GPL"); 1376MODULE_LICENSE("Dual BSD/GPL");
diff --git a/drivers/xen/xen-pciback/pciback.h b/drivers/xen/xen-pciback/pciback.h
index 5c140200a5ea..427b7fd01356 100644
--- a/drivers/xen/xen-pciback/pciback.h
+++ b/drivers/xen/xen-pciback/pciback.h
@@ -25,25 +25,19 @@ struct pci_dev_entry {
25#define _PCIB_op_pending (1) 25#define _PCIB_op_pending (1)
26#define PCIB_op_pending (1<<(_PCIB_op_pending)) 26#define PCIB_op_pending (1<<(_PCIB_op_pending))
27 27
28struct pciback_device { 28struct xen_pcibk_device {
29 void *pci_dev_data; 29 void *pci_dev_data;
30 spinlock_t dev_lock; 30 spinlock_t dev_lock;
31
32 struct xenbus_device *xdev; 31 struct xenbus_device *xdev;
33
34 struct xenbus_watch be_watch; 32 struct xenbus_watch be_watch;
35 u8 be_watching; 33 u8 be_watching;
36
37 int evtchn_irq; 34 int evtchn_irq;
38
39 struct xen_pci_sharedinfo *sh_info; 35 struct xen_pci_sharedinfo *sh_info;
40
41 unsigned long flags; 36 unsigned long flags;
42
43 struct work_struct op_work; 37 struct work_struct op_work;
44}; 38};
45 39
46struct pciback_dev_data { 40struct xen_pcibk_dev_data {
47 struct list_head config_fields; 41 struct list_head config_fields;
48 unsigned int permissive:1; 42 unsigned int permissive:1;
49 unsigned int warned_on_write:1; 43 unsigned int warned_on_write:1;
@@ -52,91 +46,78 @@ struct pciback_dev_data {
52 unsigned int ack_intr:1; /* .. and ACK-ing */ 46 unsigned int ack_intr:1; /* .. and ACK-ing */
53 unsigned long handled; 47 unsigned long handled;
54 unsigned int irq; /* Saved in case device transitions to MSI/MSI-X */ 48 unsigned int irq; /* Saved in case device transitions to MSI/MSI-X */
55 char irq_name[0]; /* pciback[000:04:00.0] */ 49 char irq_name[0]; /* xen-pcibk[000:04:00.0] */
56}; 50};
57 51
58/* Used by XenBus and pciback_ops.c */ 52/* Used by XenBus and xen_pcibk_ops.c */
59extern wait_queue_head_t aer_wait_queue; 53extern wait_queue_head_t xen_pcibk_aer_wait_queue;
60extern struct workqueue_struct *pciback_wq; 54extern struct workqueue_struct *xen_pcibk_wq;
61/* Used by pcistub.c and conf_space_quirks.c */ 55/* Used by pcistub.c and conf_space_quirks.c */
62extern struct list_head pciback_quirks; 56extern struct list_head xen_pcibk_quirks;
63 57
64/* Get/Put PCI Devices that are hidden from the PCI Backend Domain */ 58/* Get/Put PCI Devices that are hidden from the PCI Backend Domain */
65struct pci_dev *pcistub_get_pci_dev_by_slot(struct pciback_device *pdev, 59struct pci_dev *pcistub_get_pci_dev_by_slot(struct xen_pcibk_device *pdev,
66 int domain, int bus, 60 int domain, int bus,
67 int slot, int func); 61 int slot, int func);
68struct pci_dev *pcistub_get_pci_dev(struct pciback_device *pdev, 62struct pci_dev *pcistub_get_pci_dev(struct xen_pcibk_device *pdev,
69 struct pci_dev *dev); 63 struct pci_dev *dev);
70void pcistub_put_pci_dev(struct pci_dev *dev); 64void pcistub_put_pci_dev(struct pci_dev *dev);
71 65
72/* Ensure a device is turned off or reset */ 66/* Ensure a device is turned off or reset */
73void pciback_reset_device(struct pci_dev *pdev); 67void xen_pcibk_reset_device(struct pci_dev *pdev);
74 68
75/* Access a virtual configuration space for a PCI device */ 69/* Access a virtual configuration space for a PCI device */
76int pciback_config_init(void); 70int xen_pcibk_config_init(void);
77int pciback_config_init_dev(struct pci_dev *dev); 71int xen_pcibk_config_init_dev(struct pci_dev *dev);
78void pciback_config_free_dyn_fields(struct pci_dev *dev); 72void xen_pcibk_config_free_dyn_fields(struct pci_dev *dev);
79void pciback_config_reset_dev(struct pci_dev *dev); 73void xen_pcibk_config_reset_dev(struct pci_dev *dev);
80void pciback_config_free_dev(struct pci_dev *dev); 74void xen_pcibk_config_free_dev(struct pci_dev *dev);
81int pciback_config_read(struct pci_dev *dev, int offset, int size, 75int xen_pcibk_config_read(struct pci_dev *dev, int offset, int size,
82 u32 *ret_val); 76 u32 *ret_val);
83int pciback_config_write(struct pci_dev *dev, int offset, int size, u32 value); 77int xen_pcibk_config_write(struct pci_dev *dev, int offset, int size,
78 u32 value);
84 79
85/* Handle requests for specific devices from the frontend */ 80/* Handle requests for specific devices from the frontend */
86typedef int (*publish_pci_dev_cb) (struct pciback_device *pdev, 81typedef int (*publish_pci_dev_cb) (struct xen_pcibk_device *pdev,
87 unsigned int domain, unsigned int bus, 82 unsigned int domain, unsigned int bus,
88 unsigned int devfn, unsigned int devid); 83 unsigned int devfn, unsigned int devid);
89typedef int (*publish_pci_root_cb) (struct pciback_device *pdev, 84typedef int (*publish_pci_root_cb) (struct xen_pcibk_device *pdev,
90 unsigned int domain, unsigned int bus); 85 unsigned int domain, unsigned int bus);
91int pciback_add_pci_dev(struct pciback_device *pdev, struct pci_dev *dev, 86int xen_pcibk_add_pci_dev(struct xen_pcibk_device *pdev, struct pci_dev *dev,
92 int devid, publish_pci_dev_cb publish_cb); 87 int devid, publish_pci_dev_cb publish_cb);
93void pciback_release_pci_dev(struct pciback_device *pdev, struct pci_dev *dev); 88void xen_pcibk_release_pci_dev(struct xen_pcibk_device *pdev,
94struct pci_dev *pciback_get_pci_dev(struct pciback_device *pdev, 89 struct pci_dev *dev);
95 unsigned int domain, unsigned int bus, 90struct pci_dev *xen_pcibk_get_pci_dev(struct xen_pcibk_device *pdev,
96 unsigned int devfn); 91 unsigned int domain, unsigned int bus,
92 unsigned int devfn);
97 93
98/** 94/**
99* Add for domain0 PCIE-AER handling. Get guest domain/bus/devfn in pciback 95* Add for domain0 PCIE-AER handling. Get guest domain/bus/devfn in xen_pcibk
100* before sending aer request to pcifront, so that guest could identify 96* before sending aer request to pcifront, so that guest could identify
101* device, coopearte with pciback to finish aer recovery job if device driver 97* device, coopearte with xen_pcibk to finish aer recovery job if device driver
102* has the capability 98* has the capability
103*/ 99*/
104 100
105int pciback_get_pcifront_dev(struct pci_dev *pcidev, 101int xen_pcibk_get_pcifront_dev(struct pci_dev *pcidev,
106 struct pciback_device *pdev, 102 struct xen_pcibk_device *pdev,
107 unsigned int *domain, unsigned int *bus, 103 unsigned int *domain, unsigned int *bus,
108 unsigned int *devfn); 104 unsigned int *devfn);
109int pciback_init_devices(struct pciback_device *pdev); 105int xen_pcibk_init_devices(struct xen_pcibk_device *pdev);
110int pciback_publish_pci_roots(struct pciback_device *pdev, 106int xen_pcibk_publish_pci_roots(struct xen_pcibk_device *pdev,
111 publish_pci_root_cb cb); 107 publish_pci_root_cb cb);
112void pciback_release_devices(struct pciback_device *pdev); 108void xen_pcibk_release_devices(struct xen_pcibk_device *pdev);
113 109
114/* Handles events from front-end */ 110/* Handles events from front-end */
115irqreturn_t pciback_handle_event(int irq, void *dev_id); 111irqreturn_t xen_pcibk_handle_event(int irq, void *dev_id);
116void pciback_do_op(struct work_struct *data); 112void xen_pcibk_do_op(struct work_struct *data);
117 113
118int pciback_xenbus_register(void); 114int xen_pcibk_xenbus_register(void);
119void pciback_xenbus_unregister(void); 115void xen_pcibk_xenbus_unregister(void);
120 116
121#ifdef CONFIG_PCI_MSI
122int pciback_enable_msi(struct pciback_device *pdev,
123 struct pci_dev *dev, struct xen_pci_op *op);
124
125int pciback_disable_msi(struct pciback_device *pdev,
126 struct pci_dev *dev, struct xen_pci_op *op);
127
128
129int pciback_enable_msix(struct pciback_device *pdev,
130 struct pci_dev *dev, struct xen_pci_op *op);
131
132int pciback_disable_msix(struct pciback_device *pdev,
133 struct pci_dev *dev, struct xen_pci_op *op);
134#endif
135extern int verbose_request; 117extern int verbose_request;
136 118
137void test_and_schedule_op(struct pciback_device *pdev); 119void xen_pcibk_test_and_schedule_op(struct xen_pcibk_device *pdev);
138#endif 120#endif
139 121
140/* Handles shared IRQs that can to device domain and control domain. */ 122/* Handles shared IRQs that can to device domain and control domain. */
141void pciback_irq_handler(struct pci_dev *dev, int reset); 123void xen_pcibk_irq_handler(struct pci_dev *dev, int reset);
142irqreturn_t pciback_guest_interrupt(int irq, void *dev_id);
diff --git a/drivers/xen/xen-pciback/pciback_ops.c b/drivers/xen/xen-pciback/pciback_ops.c
index 28a2a5584831..8c95c3415b75 100644
--- a/drivers/xen/xen-pciback/pciback_ops.c
+++ b/drivers/xen/xen-pciback/pciback_ops.c
@@ -10,16 +10,19 @@
10#include <linux/sched.h> 10#include <linux/sched.h>
11#include "pciback.h" 11#include "pciback.h"
12 12
13#define DRV_NAME "xen-pciback"
13int verbose_request; 14int verbose_request;
14module_param(verbose_request, int, 0644); 15module_param(verbose_request, int, 0644);
15 16
17static irqreturn_t xen_pcibk_guest_interrupt(int irq, void *dev_id);
18
16/* Ensure a device is has the fake IRQ handler "turned on/off" and is 19/* Ensure a device is has the fake IRQ handler "turned on/off" and is
17 * ready to be exported. This MUST be run after pciback_reset_device 20 * ready to be exported. This MUST be run after xen_pcibk_reset_device
18 * which does the actual PCI device enable/disable. 21 * which does the actual PCI device enable/disable.
19 */ 22 */
20void pciback_control_isr(struct pci_dev *dev, int reset) 23static void xen_pcibk_control_isr(struct pci_dev *dev, int reset)
21{ 24{
22 struct pciback_dev_data *dev_data; 25 struct xen_pcibk_dev_data *dev_data;
23 int rc; 26 int rc;
24 int enable = 0; 27 int enable = 0;
25 28
@@ -66,7 +69,7 @@ void pciback_control_isr(struct pci_dev *dev, int reset)
66 69
67 if (enable) { 70 if (enable) {
68 rc = request_irq(dev_data->irq, 71 rc = request_irq(dev_data->irq,
69 pciback_guest_interrupt, IRQF_SHARED, 72 xen_pcibk_guest_interrupt, IRQF_SHARED,
70 dev_data->irq_name, dev); 73 dev_data->irq_name, dev);
71 if (rc) { 74 if (rc) {
72 dev_err(&dev->dev, "%s: failed to install fake IRQ " \ 75 dev_err(&dev->dev, "%s: failed to install fake IRQ " \
@@ -92,14 +95,14 @@ out:
92} 95}
93 96
94/* Ensure a device is "turned off" and ready to be exported. 97/* Ensure a device is "turned off" and ready to be exported.
95 * (Also see pciback_config_reset to ensure virtual configuration space is 98 * (Also see xen_pcibk_config_reset to ensure virtual configuration space is
96 * ready to be re-exported) 99 * ready to be re-exported)
97 */ 100 */
98void pciback_reset_device(struct pci_dev *dev) 101void xen_pcibk_reset_device(struct pci_dev *dev)
99{ 102{
100 u16 cmd; 103 u16 cmd;
101 104
102 pciback_control_isr(dev, 1 /* reset device */); 105 xen_pcibk_control_isr(dev, 1 /* reset device */);
103 106
104 /* Disable devices (but not bridges) */ 107 /* Disable devices (but not bridges) */
105 if (dev->hdr_type == PCI_HEADER_TYPE_NORMAL) { 108 if (dev->hdr_type == PCI_HEADER_TYPE_NORMAL) {
@@ -126,43 +129,176 @@ void pciback_reset_device(struct pci_dev *dev)
126 } 129 }
127 } 130 }
128} 131}
132
133#ifdef CONFIG_PCI_MSI
134static
135int xen_pcibk_enable_msi(struct xen_pcibk_device *pdev,
136 struct pci_dev *dev, struct xen_pci_op *op)
137{
138 struct xen_pcibk_dev_data *dev_data;
139 int otherend = pdev->xdev->otherend_id;
140 int status;
141
142 if (unlikely(verbose_request))
143 printk(KERN_DEBUG DRV_NAME ": %s: enable MSI\n", pci_name(dev));
144
145 status = pci_enable_msi(dev);
146
147 if (status) {
148 printk(KERN_ERR "error enable msi for guest %x status %x\n",
149 otherend, status);
150 op->value = 0;
151 return XEN_PCI_ERR_op_failed;
152 }
153
154 /* The value the guest needs is actually the IDT vector, not the
155 * the local domain's IRQ number. */
156
157 op->value = dev->irq ? xen_pirq_from_irq(dev->irq) : 0;
158 if (unlikely(verbose_request))
159 printk(KERN_DEBUG DRV_NAME ": %s: MSI: %d\n", pci_name(dev),
160 op->value);
161
162 dev_data = pci_get_drvdata(dev);
163 if (dev_data)
164 dev_data->ack_intr = 0;
165
166 return 0;
167}
168
169static
170int xen_pcibk_disable_msi(struct xen_pcibk_device *pdev,
171 struct pci_dev *dev, struct xen_pci_op *op)
172{
173 struct xen_pcibk_dev_data *dev_data;
174
175 if (unlikely(verbose_request))
176 printk(KERN_DEBUG DRV_NAME ": %s: disable MSI\n",
177 pci_name(dev));
178 pci_disable_msi(dev);
179
180 op->value = dev->irq ? xen_pirq_from_irq(dev->irq) : 0;
181 if (unlikely(verbose_request))
182 printk(KERN_DEBUG DRV_NAME ": %s: MSI: %d\n", pci_name(dev),
183 op->value);
184 dev_data = pci_get_drvdata(dev);
185 if (dev_data)
186 dev_data->ack_intr = 1;
187 return 0;
188}
189
190static
191int xen_pcibk_enable_msix(struct xen_pcibk_device *pdev,
192 struct pci_dev *dev, struct xen_pci_op *op)
193{
194 struct xen_pcibk_dev_data *dev_data;
195 int i, result;
196 struct msix_entry *entries;
197
198 if (unlikely(verbose_request))
199 printk(KERN_DEBUG DRV_NAME ": %s: enable MSI-X\n",
200 pci_name(dev));
201 if (op->value > SH_INFO_MAX_VEC)
202 return -EINVAL;
203
204 entries = kmalloc(op->value * sizeof(*entries), GFP_KERNEL);
205 if (entries == NULL)
206 return -ENOMEM;
207
208 for (i = 0; i < op->value; i++) {
209 entries[i].entry = op->msix_entries[i].entry;
210 entries[i].vector = op->msix_entries[i].vector;
211 }
212
213 result = pci_enable_msix(dev, entries, op->value);
214
215 if (result == 0) {
216 for (i = 0; i < op->value; i++) {
217 op->msix_entries[i].entry = entries[i].entry;
218 if (entries[i].vector)
219 op->msix_entries[i].vector =
220 xen_pirq_from_irq(entries[i].vector);
221 if (unlikely(verbose_request))
222 printk(KERN_DEBUG DRV_NAME ": %s: " \
223 "MSI-X[%d]: %d\n",
224 pci_name(dev), i,
225 op->msix_entries[i].vector);
226 }
227 } else {
228 printk(KERN_WARNING DRV_NAME ": %s: failed to enable MSI-X: err %d!\n",
229 pci_name(dev), result);
230 }
231 kfree(entries);
232
233 op->value = result;
234 dev_data = pci_get_drvdata(dev);
235 if (dev_data)
236 dev_data->ack_intr = 0;
237
238 return result;
239}
240
241static
242int xen_pcibk_disable_msix(struct xen_pcibk_device *pdev,
243 struct pci_dev *dev, struct xen_pci_op *op)
244{
245 struct xen_pcibk_dev_data *dev_data;
246 if (unlikely(verbose_request))
247 printk(KERN_DEBUG DRV_NAME ": %s: disable MSI-X\n",
248 pci_name(dev));
249 pci_disable_msix(dev);
250
251 /*
252 * SR-IOV devices (which don't have any legacy IRQ) have
253 * an undefined IRQ value of zero.
254 */
255 op->value = dev->irq ? xen_pirq_from_irq(dev->irq) : 0;
256 if (unlikely(verbose_request))
257 printk(KERN_DEBUG DRV_NAME ": %s: MSI-X: %d\n", pci_name(dev),
258 op->value);
259 dev_data = pci_get_drvdata(dev);
260 if (dev_data)
261 dev_data->ack_intr = 1;
262 return 0;
263}
264#endif
129/* 265/*
130* Now the same evtchn is used for both pcifront conf_read_write request 266* Now the same evtchn is used for both pcifront conf_read_write request
131* as well as pcie aer front end ack. We use a new work_queue to schedule 267* as well as pcie aer front end ack. We use a new work_queue to schedule
132* pciback conf_read_write service for avoiding confict with aer_core 268* xen_pcibk conf_read_write service for avoiding confict with aer_core
133* do_recovery job which also use the system default work_queue 269* do_recovery job which also use the system default work_queue
134*/ 270*/
135void test_and_schedule_op(struct pciback_device *pdev) 271void xen_pcibk_test_and_schedule_op(struct xen_pcibk_device *pdev)
136{ 272{
137 /* Check that frontend is requesting an operation and that we are not 273 /* Check that frontend is requesting an operation and that we are not
138 * already processing a request */ 274 * already processing a request */
139 if (test_bit(_XEN_PCIF_active, (unsigned long *)&pdev->sh_info->flags) 275 if (test_bit(_XEN_PCIF_active, (unsigned long *)&pdev->sh_info->flags)
140 && !test_and_set_bit(_PDEVF_op_active, &pdev->flags)) { 276 && !test_and_set_bit(_PDEVF_op_active, &pdev->flags)) {
141 queue_work(pciback_wq, &pdev->op_work); 277 queue_work(xen_pcibk_wq, &pdev->op_work);
142 } 278 }
143 /*_XEN_PCIB_active should have been cleared by pcifront. And also make 279 /*_XEN_PCIB_active should have been cleared by pcifront. And also make
144 sure pciback is waiting for ack by checking _PCIB_op_pending*/ 280 sure xen_pcibk is waiting for ack by checking _PCIB_op_pending*/
145 if (!test_bit(_XEN_PCIB_active, (unsigned long *)&pdev->sh_info->flags) 281 if (!test_bit(_XEN_PCIB_active, (unsigned long *)&pdev->sh_info->flags)
146 && test_bit(_PCIB_op_pending, &pdev->flags)) { 282 && test_bit(_PCIB_op_pending, &pdev->flags)) {
147 wake_up(&aer_wait_queue); 283 wake_up(&xen_pcibk_aer_wait_queue);
148 } 284 }
149} 285}
150 286
151/* Performing the configuration space reads/writes must not be done in atomic 287/* Performing the configuration space reads/writes must not be done in atomic
152 * context because some of the pci_* functions can sleep (mostly due to ACPI 288 * context because some of the pci_* functions can sleep (mostly due to ACPI
153 * use of semaphores). This function is intended to be called from a work 289 * use of semaphores). This function is intended to be called from a work
154 * queue in process context taking a struct pciback_device as a parameter */ 290 * queue in process context taking a struct xen_pcibk_device as a parameter */
155 291
156void pciback_do_op(struct work_struct *data) 292void xen_pcibk_do_op(struct work_struct *data)
157{ 293{
158 struct pciback_device *pdev = 294 struct xen_pcibk_device *pdev =
159 container_of(data, struct pciback_device, op_work); 295 container_of(data, struct xen_pcibk_device, op_work);
160 struct pci_dev *dev; 296 struct pci_dev *dev;
161 struct pciback_dev_data *dev_data = NULL; 297 struct xen_pcibk_dev_data *dev_data = NULL;
162 struct xen_pci_op *op = &pdev->sh_info->op; 298 struct xen_pci_op *op = &pdev->sh_info->op;
163 int test_intx = 0; 299 int test_intx = 0;
164 300
165 dev = pciback_get_pci_dev(pdev, op->domain, op->bus, op->devfn); 301 dev = xen_pcibk_get_pci_dev(pdev, op->domain, op->bus, op->devfn);
166 302
167 if (dev == NULL) 303 if (dev == NULL)
168 op->err = XEN_PCI_ERR_dev_not_found; 304 op->err = XEN_PCI_ERR_dev_not_found;
@@ -172,25 +308,25 @@ void pciback_do_op(struct work_struct *data)
172 test_intx = dev_data->enable_intx; 308 test_intx = dev_data->enable_intx;
173 switch (op->cmd) { 309 switch (op->cmd) {
174 case XEN_PCI_OP_conf_read: 310 case XEN_PCI_OP_conf_read:
175 op->err = pciback_config_read(dev, 311 op->err = xen_pcibk_config_read(dev,
176 op->offset, op->size, &op->value); 312 op->offset, op->size, &op->value);
177 break; 313 break;
178 case XEN_PCI_OP_conf_write: 314 case XEN_PCI_OP_conf_write:
179 op->err = pciback_config_write(dev, 315 op->err = xen_pcibk_config_write(dev,
180 op->offset, op->size, op->value); 316 op->offset, op->size, op->value);
181 break; 317 break;
182#ifdef CONFIG_PCI_MSI 318#ifdef CONFIG_PCI_MSI
183 case XEN_PCI_OP_enable_msi: 319 case XEN_PCI_OP_enable_msi:
184 op->err = pciback_enable_msi(pdev, dev, op); 320 op->err = xen_pcibk_enable_msi(pdev, dev, op);
185 break; 321 break;
186 case XEN_PCI_OP_disable_msi: 322 case XEN_PCI_OP_disable_msi:
187 op->err = pciback_disable_msi(pdev, dev, op); 323 op->err = xen_pcibk_disable_msi(pdev, dev, op);
188 break; 324 break;
189 case XEN_PCI_OP_enable_msix: 325 case XEN_PCI_OP_enable_msix:
190 op->err = pciback_enable_msix(pdev, dev, op); 326 op->err = xen_pcibk_enable_msix(pdev, dev, op);
191 break; 327 break;
192 case XEN_PCI_OP_disable_msix: 328 case XEN_PCI_OP_disable_msix:
193 op->err = pciback_disable_msix(pdev, dev, op); 329 op->err = xen_pcibk_disable_msix(pdev, dev, op);
194 break; 330 break;
195#endif 331#endif
196 default: 332 default:
@@ -201,7 +337,7 @@ void pciback_do_op(struct work_struct *data)
201 if (!op->err && dev && dev_data) { 337 if (!op->err && dev && dev_data) {
202 /* Transition detected */ 338 /* Transition detected */
203 if ((dev_data->enable_intx != test_intx)) 339 if ((dev_data->enable_intx != test_intx))
204 pciback_control_isr(dev, 0 /* no reset */); 340 xen_pcibk_control_isr(dev, 0 /* no reset */);
205 } 341 }
206 /* Tell the driver domain that we're done. */ 342 /* Tell the driver domain that we're done. */
207 wmb(); 343 wmb();
@@ -216,21 +352,21 @@ void pciback_do_op(struct work_struct *data)
216 /* Check to see if the driver domain tried to start another request in 352 /* Check to see if the driver domain tried to start another request in
217 * between clearing _XEN_PCIF_active and clearing _PDEVF_op_active. 353 * between clearing _XEN_PCIF_active and clearing _PDEVF_op_active.
218 */ 354 */
219 test_and_schedule_op(pdev); 355 xen_pcibk_test_and_schedule_op(pdev);
220} 356}
221 357
222irqreturn_t pciback_handle_event(int irq, void *dev_id) 358irqreturn_t xen_pcibk_handle_event(int irq, void *dev_id)
223{ 359{
224 struct pciback_device *pdev = dev_id; 360 struct xen_pcibk_device *pdev = dev_id;
225 361
226 test_and_schedule_op(pdev); 362 xen_pcibk_test_and_schedule_op(pdev);
227 363
228 return IRQ_HANDLED; 364 return IRQ_HANDLED;
229} 365}
230irqreturn_t pciback_guest_interrupt(int irq, void *dev_id) 366static irqreturn_t xen_pcibk_guest_interrupt(int irq, void *dev_id)
231{ 367{
232 struct pci_dev *dev = (struct pci_dev *)dev_id; 368 struct pci_dev *dev = (struct pci_dev *)dev_id;
233 struct pciback_dev_data *dev_data = pci_get_drvdata(dev); 369 struct xen_pcibk_dev_data *dev_data = pci_get_drvdata(dev);
234 370
235 if (dev_data->isr_on && dev_data->ack_intr) { 371 if (dev_data->isr_on && dev_data->ack_intr) {
236 dev_data->handled++; 372 dev_data->handled++;
diff --git a/drivers/xen/xen-pciback/slot.c b/drivers/xen/xen-pciback/slot.c
deleted file mode 100644
index efb922d6f78e..000000000000
--- a/drivers/xen/xen-pciback/slot.c
+++ /dev/null
@@ -1,191 +0,0 @@
1/*
2 * PCI Backend - Provides a Virtual PCI bus (with real devices)
3 * to the frontend
4 *
5 * Author: Ryan Wilson <hap9@epoch.ncsc.mil> (vpci.c)
6 * Author: Tristan Gingold <tristan.gingold@bull.net>, from vpci.c
7 */
8
9#include <linux/list.h>
10#include <linux/slab.h>
11#include <linux/pci.h>
12#include <linux/spinlock.h>
13#include "pciback.h"
14
15/* There are at most 32 slots in a pci bus. */
16#define PCI_SLOT_MAX 32
17
18#define PCI_BUS_NBR 2
19
20struct slot_dev_data {
21 /* Access to dev_list must be protected by lock */
22 struct pci_dev *slots[PCI_BUS_NBR][PCI_SLOT_MAX];
23 spinlock_t lock;
24};
25
26struct pci_dev *pciback_get_pci_dev(struct pciback_device *pdev,
27 unsigned int domain, unsigned int bus,
28 unsigned int devfn)
29{
30 struct pci_dev *dev = NULL;
31 struct slot_dev_data *slot_dev = pdev->pci_dev_data;
32 unsigned long flags;
33
34 if (domain != 0 || PCI_FUNC(devfn) != 0)
35 return NULL;
36
37 if (PCI_SLOT(devfn) >= PCI_SLOT_MAX || bus >= PCI_BUS_NBR)
38 return NULL;
39
40 spin_lock_irqsave(&slot_dev->lock, flags);
41 dev = slot_dev->slots[bus][PCI_SLOT(devfn)];
42 spin_unlock_irqrestore(&slot_dev->lock, flags);
43
44 return dev;
45}
46
47int pciback_add_pci_dev(struct pciback_device *pdev, struct pci_dev *dev,
48 int devid, publish_pci_dev_cb publish_cb)
49{
50 int err = 0, slot, bus;
51 struct slot_dev_data *slot_dev = pdev->pci_dev_data;
52 unsigned long flags;
53
54 if ((dev->class >> 24) == PCI_BASE_CLASS_BRIDGE) {
55 err = -EFAULT;
56 xenbus_dev_fatal(pdev->xdev, err,
57 "Can't export bridges on the virtual PCI bus");
58 goto out;
59 }
60
61 spin_lock_irqsave(&slot_dev->lock, flags);
62
63 /* Assign to a new slot on the virtual PCI bus */
64 for (bus = 0; bus < PCI_BUS_NBR; bus++)
65 for (slot = 0; slot < PCI_SLOT_MAX; slot++) {
66 if (slot_dev->slots[bus][slot] == NULL) {
67 printk(KERN_INFO
68 "pciback: slot: %s: assign to virtual "
69 "slot %d, bus %d\n",
70 pci_name(dev), slot, bus);
71 slot_dev->slots[bus][slot] = dev;
72 goto unlock;
73 }
74 }
75
76 err = -ENOMEM;
77 xenbus_dev_fatal(pdev->xdev, err,
78 "No more space on root virtual PCI bus");
79
80unlock:
81 spin_unlock_irqrestore(&slot_dev->lock, flags);
82
83 /* Publish this device. */
84 if (!err)
85 err = publish_cb(pdev, 0, 0, PCI_DEVFN(slot, 0), devid);
86
87out:
88 return err;
89}
90
91void pciback_release_pci_dev(struct pciback_device *pdev, struct pci_dev *dev)
92{
93 int slot, bus;
94 struct slot_dev_data *slot_dev = pdev->pci_dev_data;
95 struct pci_dev *found_dev = NULL;
96 unsigned long flags;
97
98 spin_lock_irqsave(&slot_dev->lock, flags);
99
100 for (bus = 0; bus < PCI_BUS_NBR; bus++)
101 for (slot = 0; slot < PCI_SLOT_MAX; slot++) {
102 if (slot_dev->slots[bus][slot] == dev) {
103 slot_dev->slots[bus][slot] = NULL;
104 found_dev = dev;
105 goto out;
106 }
107 }
108
109out:
110 spin_unlock_irqrestore(&slot_dev->lock, flags);
111
112 if (found_dev)
113 pcistub_put_pci_dev(found_dev);
114}
115
116int pciback_init_devices(struct pciback_device *pdev)
117{
118 int slot, bus;
119 struct slot_dev_data *slot_dev;
120
121 slot_dev = kmalloc(sizeof(*slot_dev), GFP_KERNEL);
122 if (!slot_dev)
123 return -ENOMEM;
124
125 spin_lock_init(&slot_dev->lock);
126
127 for (bus = 0; bus < PCI_BUS_NBR; bus++)
128 for (slot = 0; slot < PCI_SLOT_MAX; slot++)
129 slot_dev->slots[bus][slot] = NULL;
130
131 pdev->pci_dev_data = slot_dev;
132
133 return 0;
134}
135
136int pciback_publish_pci_roots(struct pciback_device *pdev,
137 publish_pci_root_cb publish_cb)
138{
139 /* The Virtual PCI bus has only one root */
140 return publish_cb(pdev, 0, 0);
141}
142
143void pciback_release_devices(struct pciback_device *pdev)
144{
145 int slot, bus;
146 struct slot_dev_data *slot_dev = pdev->pci_dev_data;
147 struct pci_dev *dev;
148
149 for (bus = 0; bus < PCI_BUS_NBR; bus++)
150 for (slot = 0; slot < PCI_SLOT_MAX; slot++) {
151 dev = slot_dev->slots[bus][slot];
152 if (dev != NULL)
153 pcistub_put_pci_dev(dev);
154 }
155
156 kfree(slot_dev);
157 pdev->pci_dev_data = NULL;
158}
159
160int pciback_get_pcifront_dev(struct pci_dev *pcidev,
161 struct pciback_device *pdev,
162 unsigned int *domain, unsigned int *bus,
163 unsigned int *devfn)
164{
165 int slot, busnr;
166 struct slot_dev_data *slot_dev = pdev->pci_dev_data;
167 struct pci_dev *dev;
168 int found = 0;
169 unsigned long flags;
170
171 spin_lock_irqsave(&slot_dev->lock, flags);
172
173 for (busnr = 0; busnr < PCI_BUS_NBR; bus++)
174 for (slot = 0; slot < PCI_SLOT_MAX; slot++) {
175 dev = slot_dev->slots[busnr][slot];
176 if (dev && dev->bus->number == pcidev->bus->number
177 && dev->devfn == pcidev->devfn
178 && pci_domain_nr(dev->bus) ==
179 pci_domain_nr(pcidev->bus)) {
180 found = 1;
181 *domain = 0;
182 *bus = busnr;
183 *devfn = PCI_DEVFN(slot, 0);
184 goto out;
185 }
186 }
187out:
188 spin_unlock_irqrestore(&slot_dev->lock, flags);
189 return found;
190
191}
diff --git a/drivers/xen/xen-pciback/vpci.c b/drivers/xen/xen-pciback/vpci.c
index 2857ab892f02..7d5c192a1505 100644
--- a/drivers/xen/xen-pciback/vpci.c
+++ b/drivers/xen/xen-pciback/vpci.c
@@ -12,6 +12,7 @@
12#include "pciback.h" 12#include "pciback.h"
13 13
14#define PCI_SLOT_MAX 32 14#define PCI_SLOT_MAX 32
15#define DRV_NAME "xen-pciback"
15 16
16struct vpci_dev_data { 17struct vpci_dev_data {
17 /* Access to dev_list must be protected by lock */ 18 /* Access to dev_list must be protected by lock */
@@ -24,9 +25,9 @@ static inline struct list_head *list_first(struct list_head *head)
24 return head->next; 25 return head->next;
25} 26}
26 27
27struct pci_dev *pciback_get_pci_dev(struct pciback_device *pdev, 28struct pci_dev *xen_pcibk_get_pci_dev(struct xen_pcibk_device *pdev,
28 unsigned int domain, unsigned int bus, 29 unsigned int domain, unsigned int bus,
29 unsigned int devfn) 30 unsigned int devfn)
30{ 31{
31 struct pci_dev_entry *entry; 32 struct pci_dev_entry *entry;
32 struct pci_dev *dev = NULL; 33 struct pci_dev *dev = NULL;
@@ -62,8 +63,8 @@ static inline int match_slot(struct pci_dev *l, struct pci_dev *r)
62 return 0; 63 return 0;
63} 64}
64 65
65int pciback_add_pci_dev(struct pciback_device *pdev, struct pci_dev *dev, 66int xen_pcibk_add_pci_dev(struct xen_pcibk_device *pdev, struct pci_dev *dev,
66 int devid, publish_pci_dev_cb publish_cb) 67 int devid, publish_pci_dev_cb publish_cb)
67{ 68{
68 int err = 0, slot, func = -1; 69 int err = 0, slot, func = -1;
69 struct pci_dev_entry *t, *dev_entry; 70 struct pci_dev_entry *t, *dev_entry;
@@ -96,7 +97,7 @@ int pciback_add_pci_dev(struct pciback_device *pdev, struct pci_dev *dev,
96 struct pci_dev_entry, list); 97 struct pci_dev_entry, list);
97 98
98 if (match_slot(dev, t->dev)) { 99 if (match_slot(dev, t->dev)) {
99 pr_info("pciback: vpci: %s: " 100 pr_info(DRV_NAME ": vpci: %s: "
100 "assign to virtual slot %d func %d\n", 101 "assign to virtual slot %d func %d\n",
101 pci_name(dev), slot, 102 pci_name(dev), slot,
102 PCI_FUNC(dev->devfn)); 103 PCI_FUNC(dev->devfn));
@@ -111,8 +112,8 @@ int pciback_add_pci_dev(struct pciback_device *pdev, struct pci_dev *dev,
111 /* Assign to a new slot on the virtual PCI bus */ 112 /* Assign to a new slot on the virtual PCI bus */
112 for (slot = 0; slot < PCI_SLOT_MAX; slot++) { 113 for (slot = 0; slot < PCI_SLOT_MAX; slot++) {
113 if (list_empty(&vpci_dev->dev_list[slot])) { 114 if (list_empty(&vpci_dev->dev_list[slot])) {
114 printk(KERN_INFO 115 printk(KERN_INFO DRV_NAME
115 "pciback: vpci: %s: assign to virtual slot %d\n", 116 ": vpci: %s: assign to virtual slot %d\n",
116 pci_name(dev), slot); 117 pci_name(dev), slot);
117 list_add_tail(&dev_entry->list, 118 list_add_tail(&dev_entry->list,
118 &vpci_dev->dev_list[slot]); 119 &vpci_dev->dev_list[slot]);
@@ -136,7 +137,8 @@ out:
136 return err; 137 return err;
137} 138}
138 139
139void pciback_release_pci_dev(struct pciback_device *pdev, struct pci_dev *dev) 140void xen_pcibk_release_pci_dev(struct xen_pcibk_device *pdev,
141 struct pci_dev *dev)
140{ 142{
141 int slot; 143 int slot;
142 struct vpci_dev_data *vpci_dev = pdev->pci_dev_data; 144 struct vpci_dev_data *vpci_dev = pdev->pci_dev_data;
@@ -165,7 +167,7 @@ out:
165 pcistub_put_pci_dev(found_dev); 167 pcistub_put_pci_dev(found_dev);
166} 168}
167 169
168int pciback_init_devices(struct pciback_device *pdev) 170int xen_pcibk_init_devices(struct xen_pcibk_device *pdev)
169{ 171{
170 int slot; 172 int slot;
171 struct vpci_dev_data *vpci_dev; 173 struct vpci_dev_data *vpci_dev;
@@ -184,14 +186,14 @@ int pciback_init_devices(struct pciback_device *pdev)
184 return 0; 186 return 0;
185} 187}
186 188
187int pciback_publish_pci_roots(struct pciback_device *pdev, 189int xen_pcibk_publish_pci_roots(struct xen_pcibk_device *pdev,
188 publish_pci_root_cb publish_cb) 190 publish_pci_root_cb publish_cb)
189{ 191{
190 /* The Virtual PCI bus has only one root */ 192 /* The Virtual PCI bus has only one root */
191 return publish_cb(pdev, 0, 0); 193 return publish_cb(pdev, 0, 0);
192} 194}
193 195
194void pciback_release_devices(struct pciback_device *pdev) 196void xen_pcibk_release_devices(struct xen_pcibk_device *pdev)
195{ 197{
196 int slot; 198 int slot;
197 struct vpci_dev_data *vpci_dev = pdev->pci_dev_data; 199 struct vpci_dev_data *vpci_dev = pdev->pci_dev_data;
@@ -210,10 +212,10 @@ void pciback_release_devices(struct pciback_device *pdev)
210 pdev->pci_dev_data = NULL; 212 pdev->pci_dev_data = NULL;
211} 213}
212 214
213int pciback_get_pcifront_dev(struct pci_dev *pcidev, 215int xen_pcibk_get_pcifront_dev(struct pci_dev *pcidev,
214 struct pciback_device *pdev, 216 struct xen_pcibk_device *pdev,
215 unsigned int *domain, unsigned int *bus, 217 unsigned int *domain, unsigned int *bus,
216 unsigned int *devfn) 218 unsigned int *devfn)
217{ 219{
218 struct pci_dev_entry *entry; 220 struct pci_dev_entry *entry;
219 struct pci_dev *dev = NULL; 221 struct pci_dev *dev = NULL;
diff --git a/drivers/xen/xen-pciback/xenbus.c b/drivers/xen/xen-pciback/xenbus.c
index 70030c409212..1e5ba85c0d33 100644
--- a/drivers/xen/xen-pciback/xenbus.c
+++ b/drivers/xen/xen-pciback/xenbus.c
@@ -14,14 +14,15 @@
14#include <linux/workqueue.h> 14#include <linux/workqueue.h>
15#include "pciback.h" 15#include "pciback.h"
16 16
17#define DRV_NAME "xen-pciback"
17#define INVALID_EVTCHN_IRQ (-1) 18#define INVALID_EVTCHN_IRQ (-1)
18struct workqueue_struct *pciback_wq; 19struct workqueue_struct *xen_pcibk_wq;
19 20
20static struct pciback_device *alloc_pdev(struct xenbus_device *xdev) 21static struct xen_pcibk_device *alloc_pdev(struct xenbus_device *xdev)
21{ 22{
22 struct pciback_device *pdev; 23 struct xen_pcibk_device *pdev;
23 24
24 pdev = kzalloc(sizeof(struct pciback_device), GFP_KERNEL); 25 pdev = kzalloc(sizeof(struct xen_pcibk_device), GFP_KERNEL);
25 if (pdev == NULL) 26 if (pdev == NULL)
26 goto out; 27 goto out;
27 dev_dbg(&xdev->dev, "allocated pdev @ 0x%p\n", pdev); 28 dev_dbg(&xdev->dev, "allocated pdev @ 0x%p\n", pdev);
@@ -35,9 +36,9 @@ static struct pciback_device *alloc_pdev(struct xenbus_device *xdev)
35 pdev->evtchn_irq = INVALID_EVTCHN_IRQ; 36 pdev->evtchn_irq = INVALID_EVTCHN_IRQ;
36 pdev->be_watching = 0; 37 pdev->be_watching = 0;
37 38
38 INIT_WORK(&pdev->op_work, pciback_do_op); 39 INIT_WORK(&pdev->op_work, xen_pcibk_do_op);
39 40
40 if (pciback_init_devices(pdev)) { 41 if (xen_pcibk_init_devices(pdev)) {
41 kfree(pdev); 42 kfree(pdev);
42 pdev = NULL; 43 pdev = NULL;
43 } 44 }
@@ -45,7 +46,7 @@ out:
45 return pdev; 46 return pdev;
46} 47}
47 48
48static void pciback_disconnect(struct pciback_device *pdev) 49static void xen_pcibk_disconnect(struct xen_pcibk_device *pdev)
49{ 50{
50 spin_lock(&pdev->dev_lock); 51 spin_lock(&pdev->dev_lock);
51 52
@@ -60,7 +61,7 @@ static void pciback_disconnect(struct pciback_device *pdev)
60 * before releasing the shared memory */ 61 * before releasing the shared memory */
61 62
62 /* Note, the workqueue does not use spinlocks at all.*/ 63 /* Note, the workqueue does not use spinlocks at all.*/
63 flush_workqueue(pciback_wq); 64 flush_workqueue(xen_pcibk_wq);
64 65
65 spin_lock(&pdev->dev_lock); 66 spin_lock(&pdev->dev_lock);
66 if (pdev->sh_info != NULL) { 67 if (pdev->sh_info != NULL) {
@@ -71,16 +72,16 @@ static void pciback_disconnect(struct pciback_device *pdev)
71 72
72} 73}
73 74
74static void free_pdev(struct pciback_device *pdev) 75static void free_pdev(struct xen_pcibk_device *pdev)
75{ 76{
76 if (pdev->be_watching) { 77 if (pdev->be_watching) {
77 unregister_xenbus_watch(&pdev->be_watch); 78 unregister_xenbus_watch(&pdev->be_watch);
78 pdev->be_watching = 0; 79 pdev->be_watching = 0;
79 } 80 }
80 81
81 pciback_disconnect(pdev); 82 xen_pcibk_disconnect(pdev);
82 83
83 pciback_release_devices(pdev); 84 xen_pcibk_release_devices(pdev);
84 85
85 dev_set_drvdata(&pdev->xdev->dev, NULL); 86 dev_set_drvdata(&pdev->xdev->dev, NULL);
86 pdev->xdev = NULL; 87 pdev->xdev = NULL;
@@ -88,7 +89,7 @@ static void free_pdev(struct pciback_device *pdev)
88 kfree(pdev); 89 kfree(pdev);
89} 90}
90 91
91static int pciback_do_attach(struct pciback_device *pdev, int gnt_ref, 92static int xen_pcibk_do_attach(struct xen_pcibk_device *pdev, int gnt_ref,
92 int remote_evtchn) 93 int remote_evtchn)
93{ 94{
94 int err = 0; 95 int err = 0;
@@ -110,8 +111,8 @@ static int pciback_do_attach(struct pciback_device *pdev, int gnt_ref,
110 spin_unlock(&pdev->dev_lock); 111 spin_unlock(&pdev->dev_lock);
111 112
112 err = bind_interdomain_evtchn_to_irqhandler( 113 err = bind_interdomain_evtchn_to_irqhandler(
113 pdev->xdev->otherend_id, remote_evtchn, pciback_handle_event, 114 pdev->xdev->otherend_id, remote_evtchn, xen_pcibk_handle_event,
114 0, "pciback", pdev); 115 0, DRV_NAME, pdev);
115 if (err < 0) { 116 if (err < 0) {
116 xenbus_dev_fatal(pdev->xdev, err, 117 xenbus_dev_fatal(pdev->xdev, err,
117 "Error binding event channel to IRQ"); 118 "Error binding event channel to IRQ");
@@ -128,7 +129,7 @@ out:
128 return err; 129 return err;
129} 130}
130 131
131static int pciback_attach(struct pciback_device *pdev) 132static int xen_pcibk_attach(struct xen_pcibk_device *pdev)
132{ 133{
133 int err = 0; 134 int err = 0;
134 int gnt_ref, remote_evtchn; 135 int gnt_ref, remote_evtchn;
@@ -161,12 +162,12 @@ static int pciback_attach(struct pciback_device *pdev)
161 if (magic == NULL || strcmp(magic, XEN_PCI_MAGIC) != 0) { 162 if (magic == NULL || strcmp(magic, XEN_PCI_MAGIC) != 0) {
162 xenbus_dev_fatal(pdev->xdev, -EFAULT, 163 xenbus_dev_fatal(pdev->xdev, -EFAULT,
163 "version mismatch (%s/%s) with pcifront - " 164 "version mismatch (%s/%s) with pcifront - "
164 "halting pciback", 165 "halting xen_pcibk",
165 magic, XEN_PCI_MAGIC); 166 magic, XEN_PCI_MAGIC);
166 goto out; 167 goto out;
167 } 168 }
168 169
169 err = pciback_do_attach(pdev, gnt_ref, remote_evtchn); 170 err = xen_pcibk_do_attach(pdev, gnt_ref, remote_evtchn);
170 if (err) 171 if (err)
171 goto out; 172 goto out;
172 173
@@ -185,7 +186,7 @@ out:
185 return err; 186 return err;
186} 187}
187 188
188static int pciback_publish_pci_dev(struct pciback_device *pdev, 189static int xen_pcibk_publish_pci_dev(struct xen_pcibk_device *pdev,
189 unsigned int domain, unsigned int bus, 190 unsigned int domain, unsigned int bus,
190 unsigned int devfn, unsigned int devid) 191 unsigned int devfn, unsigned int devid)
191{ 192{
@@ -207,7 +208,7 @@ out:
207 return err; 208 return err;
208} 209}
209 210
210static int pciback_export_device(struct pciback_device *pdev, 211static int xen_pcibk_export_device(struct xen_pcibk_device *pdev,
211 int domain, int bus, int slot, int func, 212 int domain, int bus, int slot, int func,
212 int devid) 213 int devid)
213{ 214{
@@ -228,7 +229,8 @@ static int pciback_export_device(struct pciback_device *pdev,
228 goto out; 229 goto out;
229 } 230 }
230 231
231 err = pciback_add_pci_dev(pdev, dev, devid, pciback_publish_pci_dev); 232 err = xen_pcibk_add_pci_dev(pdev, dev, devid,
233 xen_pcibk_publish_pci_dev);
232 if (err) 234 if (err)
233 goto out; 235 goto out;
234 236
@@ -253,7 +255,7 @@ out:
253 return err; 255 return err;
254} 256}
255 257
256static int pciback_remove_device(struct pciback_device *pdev, 258static int xen_pcibk_remove_device(struct xen_pcibk_device *pdev,
257 int domain, int bus, int slot, int func) 259 int domain, int bus, int slot, int func)
258{ 260{
259 int err = 0; 261 int err = 0;
@@ -262,7 +264,7 @@ static int pciback_remove_device(struct pciback_device *pdev,
262 dev_dbg(&pdev->xdev->dev, "removing dom %x bus %x slot %x func %x\n", 264 dev_dbg(&pdev->xdev->dev, "removing dom %x bus %x slot %x func %x\n",
263 domain, bus, slot, func); 265 domain, bus, slot, func);
264 266
265 dev = pciback_get_pci_dev(pdev, domain, bus, PCI_DEVFN(slot, func)); 267 dev = xen_pcibk_get_pci_dev(pdev, domain, bus, PCI_DEVFN(slot, func));
266 if (!dev) { 268 if (!dev) {
267 err = -EINVAL; 269 err = -EINVAL;
268 dev_dbg(&pdev->xdev->dev, "Couldn't locate PCI device " 270 dev_dbg(&pdev->xdev->dev, "Couldn't locate PCI device "
@@ -274,13 +276,13 @@ static int pciback_remove_device(struct pciback_device *pdev,
274 dev_dbg(&dev->dev, "unregistering for %d\n", pdev->xdev->otherend_id); 276 dev_dbg(&dev->dev, "unregistering for %d\n", pdev->xdev->otherend_id);
275 xen_unregister_device_domain_owner(dev); 277 xen_unregister_device_domain_owner(dev);
276 278
277 pciback_release_pci_dev(pdev, dev); 279 xen_pcibk_release_pci_dev(pdev, dev);
278 280
279out: 281out:
280 return err; 282 return err;
281} 283}
282 284
283static int pciback_publish_pci_root(struct pciback_device *pdev, 285static int xen_pcibk_publish_pci_root(struct xen_pcibk_device *pdev,
284 unsigned int domain, unsigned int bus) 286 unsigned int domain, unsigned int bus)
285{ 287{
286 unsigned int d, b; 288 unsigned int d, b;
@@ -340,7 +342,7 @@ out:
340 return err; 342 return err;
341} 343}
342 344
343static int pciback_reconfigure(struct pciback_device *pdev) 345static int xen_pcibk_reconfigure(struct xen_pcibk_device *pdev)
344{ 346{
345 int err = 0; 347 int err = 0;
346 int num_devs; 348 int num_devs;
@@ -411,14 +413,14 @@ static int pciback_reconfigure(struct pciback_device *pdev)
411 goto out; 413 goto out;
412 } 414 }
413 415
414 err = pciback_export_device(pdev, domain, bus, slot, 416 err = xen_pcibk_export_device(pdev, domain, bus, slot,
415 func, i); 417 func, i);
416 if (err) 418 if (err)
417 goto out; 419 goto out;
418 420
419 /* Publish pci roots. */ 421 /* Publish pci roots. */
420 err = pciback_publish_pci_roots(pdev, 422 err = xen_pcibk_publish_pci_roots(pdev,
421 pciback_publish_pci_root); 423 xen_pcibk_publish_pci_root);
422 if (err) { 424 if (err) {
423 xenbus_dev_fatal(pdev->xdev, err, 425 xenbus_dev_fatal(pdev->xdev, err,
424 "Error while publish PCI root" 426 "Error while publish PCI root"
@@ -465,7 +467,7 @@ static int pciback_reconfigure(struct pciback_device *pdev)
465 goto out; 467 goto out;
466 } 468 }
467 469
468 err = pciback_remove_device(pdev, domain, bus, slot, 470 err = xen_pcibk_remove_device(pdev, domain, bus, slot,
469 func); 471 func);
470 if (err) 472 if (err)
471 goto out; 473 goto out;
@@ -493,20 +495,20 @@ out:
493 return 0; 495 return 0;
494} 496}
495 497
496static void pciback_frontend_changed(struct xenbus_device *xdev, 498static void xen_pcibk_frontend_changed(struct xenbus_device *xdev,
497 enum xenbus_state fe_state) 499 enum xenbus_state fe_state)
498{ 500{
499 struct pciback_device *pdev = dev_get_drvdata(&xdev->dev); 501 struct xen_pcibk_device *pdev = dev_get_drvdata(&xdev->dev);
500 502
501 dev_dbg(&xdev->dev, "fe state changed %d\n", fe_state); 503 dev_dbg(&xdev->dev, "fe state changed %d\n", fe_state);
502 504
503 switch (fe_state) { 505 switch (fe_state) {
504 case XenbusStateInitialised: 506 case XenbusStateInitialised:
505 pciback_attach(pdev); 507 xen_pcibk_attach(pdev);
506 break; 508 break;
507 509
508 case XenbusStateReconfiguring: 510 case XenbusStateReconfiguring:
509 pciback_reconfigure(pdev); 511 xen_pcibk_reconfigure(pdev);
510 break; 512 break;
511 513
512 case XenbusStateConnected: 514 case XenbusStateConnected:
@@ -517,12 +519,12 @@ static void pciback_frontend_changed(struct xenbus_device *xdev,
517 break; 519 break;
518 520
519 case XenbusStateClosing: 521 case XenbusStateClosing:
520 pciback_disconnect(pdev); 522 xen_pcibk_disconnect(pdev);
521 xenbus_switch_state(xdev, XenbusStateClosing); 523 xenbus_switch_state(xdev, XenbusStateClosing);
522 break; 524 break;
523 525
524 case XenbusStateClosed: 526 case XenbusStateClosed:
525 pciback_disconnect(pdev); 527 xen_pcibk_disconnect(pdev);
526 xenbus_switch_state(xdev, XenbusStateClosed); 528 xenbus_switch_state(xdev, XenbusStateClosed);
527 if (xenbus_dev_is_online(xdev)) 529 if (xenbus_dev_is_online(xdev))
528 break; 530 break;
@@ -537,7 +539,7 @@ static void pciback_frontend_changed(struct xenbus_device *xdev,
537 } 539 }
538} 540}
539 541
540static int pciback_setup_backend(struct pciback_device *pdev) 542static int xen_pcibk_setup_backend(struct xen_pcibk_device *pdev)
541{ 543{
542 /* Get configuration from xend (if available now) */ 544 /* Get configuration from xend (if available now) */
543 int domain, bus, slot, func; 545 int domain, bus, slot, func;
@@ -590,7 +592,7 @@ static int pciback_setup_backend(struct pciback_device *pdev)
590 goto out; 592 goto out;
591 } 593 }
592 594
593 err = pciback_export_device(pdev, domain, bus, slot, func, i); 595 err = xen_pcibk_export_device(pdev, domain, bus, slot, func, i);
594 if (err) 596 if (err)
595 goto out; 597 goto out;
596 598
@@ -612,7 +614,7 @@ static int pciback_setup_backend(struct pciback_device *pdev)
612 } 614 }
613 } 615 }
614 616
615 err = pciback_publish_pci_roots(pdev, pciback_publish_pci_root); 617 err = xen_pcibk_publish_pci_roots(pdev, xen_pcibk_publish_pci_root);
616 if (err) { 618 if (err) {
617 xenbus_dev_fatal(pdev->xdev, err, 619 xenbus_dev_fatal(pdev->xdev, err,
618 "Error while publish PCI root buses " 620 "Error while publish PCI root buses "
@@ -628,20 +630,20 @@ static int pciback_setup_backend(struct pciback_device *pdev)
628out: 630out:
629 if (!err) 631 if (!err)
630 /* see if pcifront is already configured (if not, we'll wait) */ 632 /* see if pcifront is already configured (if not, we'll wait) */
631 pciback_attach(pdev); 633 xen_pcibk_attach(pdev);
632 634
633 return err; 635 return err;
634} 636}
635 637
636static void pciback_be_watch(struct xenbus_watch *watch, 638static void xen_pcibk_be_watch(struct xenbus_watch *watch,
637 const char **vec, unsigned int len) 639 const char **vec, unsigned int len)
638{ 640{
639 struct pciback_device *pdev = 641 struct xen_pcibk_device *pdev =
640 container_of(watch, struct pciback_device, be_watch); 642 container_of(watch, struct xen_pcibk_device, be_watch);
641 643
642 switch (xenbus_read_driver_state(pdev->xdev->nodename)) { 644 switch (xenbus_read_driver_state(pdev->xdev->nodename)) {
643 case XenbusStateInitWait: 645 case XenbusStateInitWait:
644 pciback_setup_backend(pdev); 646 xen_pcibk_setup_backend(pdev);
645 break; 647 break;
646 648
647 default: 649 default:
@@ -649,16 +651,16 @@ static void pciback_be_watch(struct xenbus_watch *watch,
649 } 651 }
650} 652}
651 653
652static int pciback_xenbus_probe(struct xenbus_device *dev, 654static int xen_pcibk_xenbus_probe(struct xenbus_device *dev,
653 const struct xenbus_device_id *id) 655 const struct xenbus_device_id *id)
654{ 656{
655 int err = 0; 657 int err = 0;
656 struct pciback_device *pdev = alloc_pdev(dev); 658 struct xen_pcibk_device *pdev = alloc_pdev(dev);
657 659
658 if (pdev == NULL) { 660 if (pdev == NULL) {
659 err = -ENOMEM; 661 err = -ENOMEM;
660 xenbus_dev_fatal(dev, err, 662 xenbus_dev_fatal(dev, err,
661 "Error allocating pciback_device struct"); 663 "Error allocating xen_pcibk_device struct");
662 goto out; 664 goto out;
663 } 665 }
664 666
@@ -669,7 +671,7 @@ static int pciback_xenbus_probe(struct xenbus_device *dev,
669 671
670 /* watch the backend node for backend configuration information */ 672 /* watch the backend node for backend configuration information */
671 err = xenbus_watch_path(dev, dev->nodename, &pdev->be_watch, 673 err = xenbus_watch_path(dev, dev->nodename, &pdev->be_watch,
672 pciback_be_watch); 674 xen_pcibk_be_watch);
673 if (err) 675 if (err)
674 goto out; 676 goto out;
675 677
@@ -678,15 +680,15 @@ static int pciback_xenbus_probe(struct xenbus_device *dev,
678 /* We need to force a call to our callback here in case 680 /* We need to force a call to our callback here in case
679 * xend already configured us! 681 * xend already configured us!
680 */ 682 */
681 pciback_be_watch(&pdev->be_watch, NULL, 0); 683 xen_pcibk_be_watch(&pdev->be_watch, NULL, 0);
682 684
683out: 685out:
684 return err; 686 return err;
685} 687}
686 688
687static int pciback_xenbus_remove(struct xenbus_device *dev) 689static int xen_pcibk_xenbus_remove(struct xenbus_device *dev)
688{ 690{
689 struct pciback_device *pdev = dev_get_drvdata(&dev->dev); 691 struct xen_pcibk_device *pdev = dev_get_drvdata(&dev->dev);
690 692
691 if (pdev != NULL) 693 if (pdev != NULL)
692 free_pdev(pdev); 694 free_pdev(pdev);
@@ -699,28 +701,28 @@ static const struct xenbus_device_id xenpci_ids[] = {
699 {""}, 701 {""},
700}; 702};
701 703
702static struct xenbus_driver xenbus_pciback_driver = { 704static struct xenbus_driver xenbus_xen_pcibk_driver = {
703 .name = "pciback", 705 .name = DRV_NAME,
704 .owner = THIS_MODULE, 706 .owner = THIS_MODULE,
705 .ids = xenpci_ids, 707 .ids = xenpci_ids,
706 .probe = pciback_xenbus_probe, 708 .probe = xen_pcibk_xenbus_probe,
707 .remove = pciback_xenbus_remove, 709 .remove = xen_pcibk_xenbus_remove,
708 .otherend_changed = pciback_frontend_changed, 710 .otherend_changed = xen_pcibk_frontend_changed,
709}; 711};
710 712
711int __init pciback_xenbus_register(void) 713int __init xen_pcibk_xenbus_register(void)
712{ 714{
713 pciback_wq = create_workqueue("pciback_workqueue"); 715 xen_pcibk_wq = create_workqueue("xen_pciback_workqueue");
714 if (!pciback_wq) { 716 if (!xen_pcibk_wq) {
715 printk(KERN_ERR "%s: create" 717 printk(KERN_ERR "%s: create"
716 "pciback_workqueue failed\n", __func__); 718 "xen_pciback_workqueue failed\n", __func__);
717 return -EFAULT; 719 return -EFAULT;
718 } 720 }
719 return xenbus_register_backend(&xenbus_pciback_driver); 721 return xenbus_register_backend(&xenbus_xen_pcibk_driver);
720} 722}
721 723
722void __exit pciback_xenbus_unregister(void) 724void __exit xen_pcibk_xenbus_unregister(void)
723{ 725{
724 destroy_workqueue(pciback_wq); 726 destroy_workqueue(xen_pcibk_wq);
725 xenbus_unregister_driver(&xenbus_pciback_driver); 727 xenbus_unregister_driver(&xenbus_xen_pcibk_driver);
726} 728}