diff options
-rw-r--r-- | drivers/pci/endpoint/functions/pci-epf-test.c | 60 |
1 files changed, 42 insertions, 18 deletions
diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index 1a27d7950f2c..e378dae9e510 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c | |||
@@ -54,6 +54,7 @@ static struct workqueue_struct *kpcitest_workqueue; | |||
54 | struct pci_epf_test { | 54 | struct pci_epf_test { |
55 | void *reg[6]; | 55 | void *reg[6]; |
56 | struct pci_epf *epf; | 56 | struct pci_epf *epf; |
57 | enum pci_barno test_reg_bar; | ||
57 | struct delayed_work cmd_handler; | 58 | struct delayed_work cmd_handler; |
58 | }; | 59 | }; |
59 | 60 | ||
@@ -74,7 +75,11 @@ static struct pci_epf_header test_header = { | |||
74 | .interrupt_pin = PCI_INTERRUPT_INTA, | 75 | .interrupt_pin = PCI_INTERRUPT_INTA, |
75 | }; | 76 | }; |
76 | 77 | ||
77 | static int bar_size[] = { 512, 1024, 16384, 131072, 1048576 }; | 78 | struct pci_epf_test_data { |
79 | enum pci_barno test_reg_bar; | ||
80 | }; | ||
81 | |||
82 | static int bar_size[] = { 512, 512, 1024, 16384, 131072, 1048576 }; | ||
78 | 83 | ||
79 | static int pci_epf_test_copy(struct pci_epf_test *epf_test) | 84 | static int pci_epf_test_copy(struct pci_epf_test *epf_test) |
80 | { | 85 | { |
@@ -86,7 +91,8 @@ static int pci_epf_test_copy(struct pci_epf_test *epf_test) | |||
86 | struct pci_epf *epf = epf_test->epf; | 91 | struct pci_epf *epf = epf_test->epf; |
87 | struct device *dev = &epf->dev; | 92 | struct device *dev = &epf->dev; |
88 | struct pci_epc *epc = epf->epc; | 93 | struct pci_epc *epc = epf->epc; |
89 | struct pci_epf_test_reg *reg = epf_test->reg[0]; | 94 | enum pci_barno test_reg_bar = epf_test->test_reg_bar; |
95 | struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar]; | ||
90 | 96 | ||
91 | src_addr = pci_epc_mem_alloc_addr(epc, &src_phys_addr, reg->size); | 97 | src_addr = pci_epc_mem_alloc_addr(epc, &src_phys_addr, reg->size); |
92 | if (!src_addr) { | 98 | if (!src_addr) { |
@@ -145,7 +151,8 @@ static int pci_epf_test_read(struct pci_epf_test *epf_test) | |||
145 | struct pci_epf *epf = epf_test->epf; | 151 | struct pci_epf *epf = epf_test->epf; |
146 | struct device *dev = &epf->dev; | 152 | struct device *dev = &epf->dev; |
147 | struct pci_epc *epc = epf->epc; | 153 | struct pci_epc *epc = epf->epc; |
148 | struct pci_epf_test_reg *reg = epf_test->reg[0]; | 154 | enum pci_barno test_reg_bar = epf_test->test_reg_bar; |
155 | struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar]; | ||
149 | 156 | ||
150 | src_addr = pci_epc_mem_alloc_addr(epc, &phys_addr, reg->size); | 157 | src_addr = pci_epc_mem_alloc_addr(epc, &phys_addr, reg->size); |
151 | if (!src_addr) { | 158 | if (!src_addr) { |
@@ -195,7 +202,8 @@ static int pci_epf_test_write(struct pci_epf_test *epf_test) | |||
195 | struct pci_epf *epf = epf_test->epf; | 202 | struct pci_epf *epf = epf_test->epf; |
196 | struct device *dev = &epf->dev; | 203 | struct device *dev = &epf->dev; |
197 | struct pci_epc *epc = epf->epc; | 204 | struct pci_epc *epc = epf->epc; |
198 | struct pci_epf_test_reg *reg = epf_test->reg[0]; | 205 | enum pci_barno test_reg_bar = epf_test->test_reg_bar; |
206 | struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar]; | ||
199 | 207 | ||
200 | dst_addr = pci_epc_mem_alloc_addr(epc, &phys_addr, reg->size); | 208 | dst_addr = pci_epc_mem_alloc_addr(epc, &phys_addr, reg->size); |
201 | if (!dst_addr) { | 209 | if (!dst_addr) { |
@@ -247,7 +255,8 @@ static void pci_epf_test_raise_irq(struct pci_epf_test *epf_test) | |||
247 | u8 msi_count; | 255 | u8 msi_count; |
248 | struct pci_epf *epf = epf_test->epf; | 256 | struct pci_epf *epf = epf_test->epf; |
249 | struct pci_epc *epc = epf->epc; | 257 | struct pci_epc *epc = epf->epc; |
250 | struct pci_epf_test_reg *reg = epf_test->reg[0]; | 258 | enum pci_barno test_reg_bar = epf_test->test_reg_bar; |
259 | struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar]; | ||
251 | 260 | ||
252 | reg->status |= STATUS_IRQ_RAISED; | 261 | reg->status |= STATUS_IRQ_RAISED; |
253 | msi_count = pci_epc_get_msi(epc); | 262 | msi_count = pci_epc_get_msi(epc); |
@@ -268,13 +277,15 @@ static void pci_epf_test_cmd_handler(struct work_struct *work) | |||
268 | cmd_handler.work); | 277 | cmd_handler.work); |
269 | struct pci_epf *epf = epf_test->epf; | 278 | struct pci_epf *epf = epf_test->epf; |
270 | struct pci_epc *epc = epf->epc; | 279 | struct pci_epc *epc = epf->epc; |
271 | volatile struct pci_epf_test_reg *reg = epf_test->reg[0]; | 280 | enum pci_barno test_reg_bar = epf_test->test_reg_bar; |
281 | struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar]; | ||
272 | 282 | ||
273 | command = reg->command; | 283 | command = reg->command; |
274 | if (!command) | 284 | if (!command) |
275 | goto reset_handler; | 285 | goto reset_handler; |
276 | 286 | ||
277 | reg->command = 0; | 287 | reg->command = 0; |
288 | reg->status = 0; | ||
278 | 289 | ||
279 | if (command & COMMAND_RAISE_LEGACY_IRQ) { | 290 | if (command & COMMAND_RAISE_LEGACY_IRQ) { |
280 | reg->status = STATUS_IRQ_RAISED; | 291 | reg->status = STATUS_IRQ_RAISED; |
@@ -360,6 +371,7 @@ static int pci_epf_test_set_bar(struct pci_epf *epf) | |||
360 | struct pci_epc *epc = epf->epc; | 371 | struct pci_epc *epc = epf->epc; |
361 | struct device *dev = &epf->dev; | 372 | struct device *dev = &epf->dev; |
362 | struct pci_epf_test *epf_test = epf_get_drvdata(epf); | 373 | struct pci_epf_test *epf_test = epf_get_drvdata(epf); |
374 | enum pci_barno test_reg_bar = epf_test->test_reg_bar; | ||
363 | 375 | ||
364 | flags = PCI_BASE_ADDRESS_SPACE_MEMORY | PCI_BASE_ADDRESS_MEM_TYPE_32; | 376 | flags = PCI_BASE_ADDRESS_SPACE_MEMORY | PCI_BASE_ADDRESS_MEM_TYPE_32; |
365 | if (sizeof(dma_addr_t) == 0x8) | 377 | if (sizeof(dma_addr_t) == 0x8) |
@@ -372,7 +384,7 @@ static int pci_epf_test_set_bar(struct pci_epf *epf) | |||
372 | if (ret) { | 384 | if (ret) { |
373 | pci_epf_free_space(epf, epf_test->reg[bar], bar); | 385 | pci_epf_free_space(epf, epf_test->reg[bar], bar); |
374 | dev_err(dev, "failed to set BAR%d\n", bar); | 386 | dev_err(dev, "failed to set BAR%d\n", bar); |
375 | if (bar == BAR_0) | 387 | if (bar == test_reg_bar) |
376 | return ret; | 388 | return ret; |
377 | } | 389 | } |
378 | } | 390 | } |
@@ -386,17 +398,20 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf) | |||
386 | struct device *dev = &epf->dev; | 398 | struct device *dev = &epf->dev; |
387 | void *base; | 399 | void *base; |
388 | int bar; | 400 | int bar; |
401 | enum pci_barno test_reg_bar = epf_test->test_reg_bar; | ||
389 | 402 | ||
390 | base = pci_epf_alloc_space(epf, sizeof(struct pci_epf_test_reg), | 403 | base = pci_epf_alloc_space(epf, sizeof(struct pci_epf_test_reg), |
391 | BAR_0); | 404 | test_reg_bar); |
392 | if (!base) { | 405 | if (!base) { |
393 | dev_err(dev, "failed to allocated register space\n"); | 406 | dev_err(dev, "failed to allocated register space\n"); |
394 | return -ENOMEM; | 407 | return -ENOMEM; |
395 | } | 408 | } |
396 | epf_test->reg[0] = base; | 409 | epf_test->reg[test_reg_bar] = base; |
397 | 410 | ||
398 | for (bar = BAR_1; bar <= BAR_5; bar++) { | 411 | for (bar = BAR_0; bar <= BAR_5; bar++) { |
399 | base = pci_epf_alloc_space(epf, bar_size[bar - 1], bar); | 412 | if (bar == test_reg_bar) |
413 | continue; | ||
414 | base = pci_epf_alloc_space(epf, bar_size[bar], bar); | ||
400 | if (!base) | 415 | if (!base) |
401 | dev_err(dev, "failed to allocate space for BAR%d\n", | 416 | dev_err(dev, "failed to allocate space for BAR%d\n", |
402 | bar); | 417 | bar); |
@@ -437,10 +452,25 @@ static int pci_epf_test_bind(struct pci_epf *epf) | |||
437 | return 0; | 452 | return 0; |
438 | } | 453 | } |
439 | 454 | ||
455 | static const struct pci_epf_device_id pci_epf_test_ids[] = { | ||
456 | { | ||
457 | .name = "pci_epf_test", | ||
458 | }, | ||
459 | {}, | ||
460 | }; | ||
461 | |||
440 | static int pci_epf_test_probe(struct pci_epf *epf) | 462 | static int pci_epf_test_probe(struct pci_epf *epf) |
441 | { | 463 | { |
442 | struct pci_epf_test *epf_test; | 464 | struct pci_epf_test *epf_test; |
443 | struct device *dev = &epf->dev; | 465 | struct device *dev = &epf->dev; |
466 | const struct pci_epf_device_id *match; | ||
467 | struct pci_epf_test_data *data; | ||
468 | enum pci_barno test_reg_bar = BAR_0; | ||
469 | |||
470 | match = pci_epf_match_device(pci_epf_test_ids, epf); | ||
471 | data = (struct pci_epf_test_data *)match->driver_data; | ||
472 | if (data) | ||
473 | test_reg_bar = data->test_reg_bar; | ||
444 | 474 | ||
445 | epf_test = devm_kzalloc(dev, sizeof(*epf_test), GFP_KERNEL); | 475 | epf_test = devm_kzalloc(dev, sizeof(*epf_test), GFP_KERNEL); |
446 | if (!epf_test) | 476 | if (!epf_test) |
@@ -448,6 +478,7 @@ static int pci_epf_test_probe(struct pci_epf *epf) | |||
448 | 478 | ||
449 | epf->header = &test_header; | 479 | epf->header = &test_header; |
450 | epf_test->epf = epf; | 480 | epf_test->epf = epf; |
481 | epf_test->test_reg_bar = test_reg_bar; | ||
451 | 482 | ||
452 | INIT_DELAYED_WORK(&epf_test->cmd_handler, pci_epf_test_cmd_handler); | 483 | INIT_DELAYED_WORK(&epf_test->cmd_handler, pci_epf_test_cmd_handler); |
453 | 484 | ||
@@ -469,13 +500,6 @@ static struct pci_epf_ops ops = { | |||
469 | .linkup = pci_epf_test_linkup, | 500 | .linkup = pci_epf_test_linkup, |
470 | }; | 501 | }; |
471 | 502 | ||
472 | static const struct pci_epf_device_id pci_epf_test_ids[] = { | ||
473 | { | ||
474 | .name = "pci_epf_test", | ||
475 | }, | ||
476 | {}, | ||
477 | }; | ||
478 | |||
479 | static struct pci_epf_driver test_driver = { | 503 | static struct pci_epf_driver test_driver = { |
480 | .driver.name = "pci_epf_test", | 504 | .driver.name = "pci_epf_test", |
481 | .probe = pci_epf_test_probe, | 505 | .probe = pci_epf_test_probe, |