diff options
author | Stephen Hemminger <shemminger@vyatta.com> | 2008-12-18 12:17:16 -0500 |
---|---|---|
committer | Jesse Barnes <jbarnes@virtuousgeek.org> | 2009-01-07 14:13:17 -0500 |
commit | 287d19ce2e67c15e79a187b3bdcbbea1a0a51a7d (patch) | |
tree | 128d9c67557a4fe5e5e910b8ca2d50aedee31b7c /drivers/pci/pci-sysfs.c | |
parent | 1120f8b8169fb2cb51219d326892d963e762edb6 (diff) |
PCI: revise VPD access interface
Change PCI VPD API which was only used by sysfs to something usable
in drivers.
* move iteration over multiple words to the low level
* use conventional types for arguments
* add exportable wrapper
Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>
Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
Diffstat (limited to 'drivers/pci/pci-sysfs.c')
-rw-r--r-- | drivers/pci/pci-sysfs.c | 38 |
1 files changed, 8 insertions, 30 deletions
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index ea54cedcdfc6..c23619fb6c4b 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c | |||
@@ -371,55 +371,33 @@ pci_write_config(struct kobject *kobj, struct bin_attribute *bin_attr, | |||
371 | } | 371 | } |
372 | 372 | ||
373 | static ssize_t | 373 | static ssize_t |
374 | pci_read_vpd(struct kobject *kobj, struct bin_attribute *bin_attr, | 374 | read_vpd_attr(struct kobject *kobj, struct bin_attribute *bin_attr, |
375 | char *buf, loff_t off, size_t count) | 375 | char *buf, loff_t off, size_t count) |
376 | { | 376 | { |
377 | struct pci_dev *dev = | 377 | struct pci_dev *dev = |
378 | to_pci_dev(container_of(kobj, struct device, kobj)); | 378 | to_pci_dev(container_of(kobj, struct device, kobj)); |
379 | int end; | ||
380 | int ret; | ||
381 | 379 | ||
382 | if (off > bin_attr->size) | 380 | if (off > bin_attr->size) |
383 | count = 0; | 381 | count = 0; |
384 | else if (count > bin_attr->size - off) | 382 | else if (count > bin_attr->size - off) |
385 | count = bin_attr->size - off; | 383 | count = bin_attr->size - off; |
386 | end = off + count; | ||
387 | |||
388 | while (off < end) { | ||
389 | ret = dev->vpd->ops->read(dev, off, end - off, buf); | ||
390 | if (ret < 0) | ||
391 | return ret; | ||
392 | buf += ret; | ||
393 | off += ret; | ||
394 | } | ||
395 | 384 | ||
396 | return count; | 385 | return pci_read_vpd(dev, off, count, buf); |
397 | } | 386 | } |
398 | 387 | ||
399 | static ssize_t | 388 | static ssize_t |
400 | pci_write_vpd(struct kobject *kobj, struct bin_attribute *bin_attr, | 389 | write_vpd_attr(struct kobject *kobj, struct bin_attribute *bin_attr, |
401 | char *buf, loff_t off, size_t count) | 390 | char *buf, loff_t off, size_t count) |
402 | { | 391 | { |
403 | struct pci_dev *dev = | 392 | struct pci_dev *dev = |
404 | to_pci_dev(container_of(kobj, struct device, kobj)); | 393 | to_pci_dev(container_of(kobj, struct device, kobj)); |
405 | int end; | ||
406 | int ret; | ||
407 | 394 | ||
408 | if (off > bin_attr->size) | 395 | if (off > bin_attr->size) |
409 | count = 0; | 396 | count = 0; |
410 | else if (count > bin_attr->size - off) | 397 | else if (count > bin_attr->size - off) |
411 | count = bin_attr->size - off; | 398 | count = bin_attr->size - off; |
412 | end = off + count; | ||
413 | |||
414 | while (off < end) { | ||
415 | ret = dev->vpd->ops->write(dev, off, end - off, buf); | ||
416 | if (ret < 0) | ||
417 | return ret; | ||
418 | buf += ret; | ||
419 | off += ret; | ||
420 | } | ||
421 | 399 | ||
422 | return count; | 400 | return pci_write_vpd(dev, off, count, buf); |
423 | } | 401 | } |
424 | 402 | ||
425 | #ifdef HAVE_PCI_LEGACY | 403 | #ifdef HAVE_PCI_LEGACY |
@@ -845,8 +823,8 @@ static int pci_create_capabilities_sysfs(struct pci_dev *dev) | |||
845 | attr->size = dev->vpd->len; | 823 | attr->size = dev->vpd->len; |
846 | attr->attr.name = "vpd"; | 824 | attr->attr.name = "vpd"; |
847 | attr->attr.mode = S_IRUSR | S_IWUSR; | 825 | attr->attr.mode = S_IRUSR | S_IWUSR; |
848 | attr->read = pci_read_vpd; | 826 | attr->read = read_vpd_attr; |
849 | attr->write = pci_write_vpd; | 827 | attr->write = write_vpd_attr; |
850 | retval = sysfs_create_bin_file(&dev->dev.kobj, attr); | 828 | retval = sysfs_create_bin_file(&dev->dev.kobj, attr); |
851 | if (retval) { | 829 | if (retval) { |
852 | kfree(dev->vpd->attr); | 830 | kfree(dev->vpd->attr); |