diff options
author | venkatesh.pallipadi@intel.com <venkatesh.pallipadi@intel.com> | 2008-03-18 20:00:22 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2008-06-12 04:12:42 -0400 |
commit | 45aec1ae72fc592f231e9e73ed9ed4d10cfbc0b5 (patch) | |
tree | 758243a7f11d90ac4469144466be6ebb0272a8b4 /drivers/pci/pci-sysfs.c | |
parent | b7f09ae583c49d28b2796d2fa5893dcf822e3a10 (diff) |
x86: PAT export resource_wc in pci sysfs
For the ranges with IORESOURCE_PREFETCH, export a new resource_wc interface in
pci /sysfs along with resource (which is uncached).
Signed-off-by: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
Signed-off-by: Suresh Siddha <suresh.b.siddha@intel.com>
Acked-by: Jesse Barnes <jbarnes@virtuousgeek.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'drivers/pci/pci-sysfs.c')
-rw-r--r-- | drivers/pci/pci-sysfs.c | 84 |
1 files changed, 62 insertions, 22 deletions
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index 271d41cc05ab..9ec7d3977a82 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c | |||
@@ -489,13 +489,14 @@ pci_mmap_legacy_mem(struct kobject *kobj, struct bin_attribute *attr, | |||
489 | * @kobj: kobject for mapping | 489 | * @kobj: kobject for mapping |
490 | * @attr: struct bin_attribute for the file being mapped | 490 | * @attr: struct bin_attribute for the file being mapped |
491 | * @vma: struct vm_area_struct passed into the mmap | 491 | * @vma: struct vm_area_struct passed into the mmap |
492 | * @write_combine: 1 for write_combine mapping | ||
492 | * | 493 | * |
493 | * Use the regular PCI mapping routines to map a PCI resource into userspace. | 494 | * Use the regular PCI mapping routines to map a PCI resource into userspace. |
494 | * FIXME: write combining? maybe automatic for prefetchable regions? | 495 | * FIXME: write combining? maybe automatic for prefetchable regions? |
495 | */ | 496 | */ |
496 | static int | 497 | static int |
497 | pci_mmap_resource(struct kobject *kobj, struct bin_attribute *attr, | 498 | pci_mmap_resource(struct kobject *kobj, struct bin_attribute *attr, |
498 | struct vm_area_struct *vma) | 499 | struct vm_area_struct *vma, int write_combine) |
499 | { | 500 | { |
500 | struct pci_dev *pdev = to_pci_dev(container_of(kobj, | 501 | struct pci_dev *pdev = to_pci_dev(container_of(kobj, |
501 | struct device, kobj)); | 502 | struct device, kobj)); |
@@ -518,7 +519,21 @@ pci_mmap_resource(struct kobject *kobj, struct bin_attribute *attr, | |||
518 | vma->vm_pgoff += start >> PAGE_SHIFT; | 519 | vma->vm_pgoff += start >> PAGE_SHIFT; |
519 | mmap_type = res->flags & IORESOURCE_MEM ? pci_mmap_mem : pci_mmap_io; | 520 | mmap_type = res->flags & IORESOURCE_MEM ? pci_mmap_mem : pci_mmap_io; |
520 | 521 | ||
521 | return pci_mmap_page_range(pdev, vma, mmap_type, 0); | 522 | return pci_mmap_page_range(pdev, vma, mmap_type, write_combine); |
523 | } | ||
524 | |||
525 | static int | ||
526 | pci_mmap_resource_uc(struct kobject *kobj, struct bin_attribute *attr, | ||
527 | struct vm_area_struct *vma) | ||
528 | { | ||
529 | return pci_mmap_resource(kobj, attr, vma, 0); | ||
530 | } | ||
531 | |||
532 | static int | ||
533 | pci_mmap_resource_wc(struct kobject *kobj, struct bin_attribute *attr, | ||
534 | struct vm_area_struct *vma) | ||
535 | { | ||
536 | return pci_mmap_resource(kobj, attr, vma, 1); | ||
522 | } | 537 | } |
523 | 538 | ||
524 | /** | 539 | /** |
@@ -541,9 +556,46 @@ pci_remove_resource_files(struct pci_dev *pdev) | |||
541 | sysfs_remove_bin_file(&pdev->dev.kobj, res_attr); | 556 | sysfs_remove_bin_file(&pdev->dev.kobj, res_attr); |
542 | kfree(res_attr); | 557 | kfree(res_attr); |
543 | } | 558 | } |
559 | |||
560 | res_attr = pdev->res_attr_wc[i]; | ||
561 | if (res_attr) { | ||
562 | sysfs_remove_bin_file(&pdev->dev.kobj, res_attr); | ||
563 | kfree(res_attr); | ||
564 | } | ||
544 | } | 565 | } |
545 | } | 566 | } |
546 | 567 | ||
568 | static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine) | ||
569 | { | ||
570 | /* allocate attribute structure, piggyback attribute name */ | ||
571 | int name_len = write_combine ? 13 : 10; | ||
572 | struct bin_attribute *res_attr; | ||
573 | int retval; | ||
574 | |||
575 | res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC); | ||
576 | if (res_attr) { | ||
577 | char *res_attr_name = (char *)(res_attr + 1); | ||
578 | |||
579 | if (write_combine) { | ||
580 | pdev->res_attr_wc[num] = res_attr; | ||
581 | sprintf(res_attr_name, "resource%d_wc", num); | ||
582 | res_attr->mmap = pci_mmap_resource_wc; | ||
583 | } else { | ||
584 | pdev->res_attr[num] = res_attr; | ||
585 | sprintf(res_attr_name, "resource%d", num); | ||
586 | res_attr->mmap = pci_mmap_resource_uc; | ||
587 | } | ||
588 | res_attr->attr.name = res_attr_name; | ||
589 | res_attr->attr.mode = S_IRUSR | S_IWUSR; | ||
590 | res_attr->size = pci_resource_len(pdev, num); | ||
591 | res_attr->private = &pdev->resource[num]; | ||
592 | retval = sysfs_create_bin_file(&pdev->dev.kobj, res_attr); | ||
593 | } else | ||
594 | retval = -ENOMEM; | ||
595 | |||
596 | return retval; | ||
597 | } | ||
598 | |||
547 | /** | 599 | /** |
548 | * pci_create_resource_files - create resource files in sysfs for @dev | 600 | * pci_create_resource_files - create resource files in sysfs for @dev |
549 | * @dev: dev in question | 601 | * @dev: dev in question |
@@ -557,31 +609,19 @@ static int pci_create_resource_files(struct pci_dev *pdev) | |||
557 | 609 | ||
558 | /* Expose the PCI resources from this device as files */ | 610 | /* Expose the PCI resources from this device as files */ |
559 | for (i = 0; i < PCI_ROM_RESOURCE; i++) { | 611 | for (i = 0; i < PCI_ROM_RESOURCE; i++) { |
560 | struct bin_attribute *res_attr; | ||
561 | 612 | ||
562 | /* skip empty resources */ | 613 | /* skip empty resources */ |
563 | if (!pci_resource_len(pdev, i)) | 614 | if (!pci_resource_len(pdev, i)) |
564 | continue; | 615 | continue; |
565 | 616 | ||
566 | /* allocate attribute structure, piggyback attribute name */ | 617 | retval = pci_create_attr(pdev, i, 0); |
567 | res_attr = kzalloc(sizeof(*res_attr) + 10, GFP_ATOMIC); | 618 | /* for prefetchable resources, create a WC mappable file */ |
568 | if (res_attr) { | 619 | if (!retval && pdev->resource[i].flags & IORESOURCE_PREFETCH) |
569 | char *res_attr_name = (char *)(res_attr + 1); | 620 | retval = pci_create_attr(pdev, i, 1); |
570 | 621 | ||
571 | pdev->res_attr[i] = res_attr; | 622 | if (retval) { |
572 | sprintf(res_attr_name, "resource%d", i); | 623 | pci_remove_resource_files(pdev); |
573 | res_attr->attr.name = res_attr_name; | 624 | return retval; |
574 | res_attr->attr.mode = S_IRUSR | S_IWUSR; | ||
575 | res_attr->size = pci_resource_len(pdev, i); | ||
576 | res_attr->mmap = pci_mmap_resource; | ||
577 | res_attr->private = &pdev->resource[i]; | ||
578 | retval = sysfs_create_bin_file(&pdev->dev.kobj, res_attr); | ||
579 | if (retval) { | ||
580 | pci_remove_resource_files(pdev); | ||
581 | return retval; | ||
582 | } | ||
583 | } else { | ||
584 | return -ENOMEM; | ||
585 | } | 625 | } |
586 | } | 626 | } |
587 | return 0; | 627 | return 0; |