aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kernel/pci-gart_64.c
diff options
context:
space:
mode:
authorIngo Molnar <mingo@elte.hu>2009-11-15 07:19:52 -0500
committerIngo Molnar <mingo@elte.hu>2009-11-17 01:57:00 -0500
commit123bf0e2eddcda36a33bdfc87aa1fb07229f07b5 (patch)
treeaf96e64096e2cb723935433b657b40fc62720e43 /arch/x86/kernel/pci-gart_64.c
parent1f7564ca831a00b21bb493ef174c845b2ba9e64d (diff)
x86: gart: Clean up the code a bit
Clean up various small stylistic details in the GART code. No functionality changed. Cc: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> Cc: Jesse Barnes <jbarnes@virtuousgeek.org> Cc: muli@il.ibm.com Cc: joerg.roedel@amd.com LKML-Reference: <1258287594-8777-2-git-send-email-fujita.tomonori@lab.ntt.co.jp> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'arch/x86/kernel/pci-gart_64.c')
-rw-r--r--arch/x86/kernel/pci-gart_64.c116
1 files changed, 61 insertions, 55 deletions
diff --git a/arch/x86/kernel/pci-gart_64.c b/arch/x86/kernel/pci-gart_64.c
index 61c4d1e41a6b..e6a0d402f171 100644
--- a/arch/x86/kernel/pci-gart_64.c
+++ b/arch/x86/kernel/pci-gart_64.c
@@ -95,7 +95,7 @@ static unsigned long alloc_iommu(struct device *dev, int size,
95 95
96 base_index = ALIGN(iommu_bus_base & dma_get_seg_boundary(dev), 96 base_index = ALIGN(iommu_bus_base & dma_get_seg_boundary(dev),
97 PAGE_SIZE) >> PAGE_SHIFT; 97 PAGE_SIZE) >> PAGE_SHIFT;
98 boundary_size = ALIGN((unsigned long long)dma_get_seg_boundary(dev) + 1, 98 boundary_size = ALIGN((u64)dma_get_seg_boundary(dev) + 1,
99 PAGE_SIZE) >> PAGE_SHIFT; 99 PAGE_SIZE) >> PAGE_SHIFT;
100 100
101 spin_lock_irqsave(&iommu_bitmap_lock, flags); 101 spin_lock_irqsave(&iommu_bitmap_lock, flags);
@@ -297,7 +297,7 @@ static int dma_map_sg_nonforce(struct device *dev, struct scatterlist *sg,
297 int i; 297 int i;
298 298
299#ifdef CONFIG_IOMMU_DEBUG 299#ifdef CONFIG_IOMMU_DEBUG
300 printk(KERN_DEBUG "dma_map_sg overflow\n"); 300 pr_debug("dma_map_sg overflow\n");
301#endif 301#endif
302 302
303 for_each_sg(sg, s, nents, i) { 303 for_each_sg(sg, s, nents, i) {
@@ -392,12 +392,14 @@ static int gart_map_sg(struct device *dev, struct scatterlist *sg, int nents,
392 if (!dev) 392 if (!dev)
393 dev = &x86_dma_fallback_dev; 393 dev = &x86_dma_fallback_dev;
394 394
395 out = 0; 395 out = 0;
396 start = 0; 396 start = 0;
397 start_sg = sgmap = sg; 397 start_sg = sg;
398 seg_size = 0; 398 sgmap = sg;
399 max_seg_size = dma_get_max_seg_size(dev); 399 seg_size = 0;
400 ps = NULL; /* shut up gcc */ 400 max_seg_size = dma_get_max_seg_size(dev);
401 ps = NULL; /* shut up gcc */
402
401 for_each_sg(sg, s, nents, i) { 403 for_each_sg(sg, s, nents, i) {
402 dma_addr_t addr = sg_phys(s); 404 dma_addr_t addr = sg_phys(s);
403 405
@@ -420,11 +422,12 @@ static int gart_map_sg(struct device *dev, struct scatterlist *sg, int nents,
420 sgmap, pages, need) < 0) 422 sgmap, pages, need) < 0)
421 goto error; 423 goto error;
422 out++; 424 out++;
423 seg_size = 0; 425
424 sgmap = sg_next(sgmap); 426 seg_size = 0;
425 pages = 0; 427 sgmap = sg_next(sgmap);
426 start = i; 428 pages = 0;
427 start_sg = s; 429 start = i;
430 start_sg = s;
428 } 431 }
429 } 432 }
430 433
@@ -523,7 +526,7 @@ static __init unsigned long check_iommu_size(unsigned long aper, u64 aper_size)
523 iommu_size -= round_up(a, PMD_PAGE_SIZE) - a; 526 iommu_size -= round_up(a, PMD_PAGE_SIZE) - a;
524 527
525 if (iommu_size < 64*1024*1024) { 528 if (iommu_size < 64*1024*1024) {
526 printk(KERN_WARNING 529 pr_warning(
527 "PCI-DMA: Warning: Small IOMMU %luMB." 530 "PCI-DMA: Warning: Small IOMMU %luMB."
528 " Consider increasing the AGP aperture in BIOS\n", 531 " Consider increasing the AGP aperture in BIOS\n",
529 iommu_size >> 20); 532 iommu_size >> 20);
@@ -578,28 +581,32 @@ void set_up_gart_resume(u32 aper_order, u32 aper_alloc)
578 aperture_alloc = aper_alloc; 581 aperture_alloc = aper_alloc;
579} 582}
580 583
581static int gart_resume(struct sys_device *dev) 584static void gart_fixup_northbridges(struct sys_device *dev)
582{ 585{
583 printk(KERN_INFO "PCI-DMA: Resuming GART IOMMU\n"); 586 int i;
584 587
585 if (fix_up_north_bridges) { 588 if (!fix_up_north_bridges)
586 int i; 589 return;
587 590
588 printk(KERN_INFO "PCI-DMA: Restoring GART aperture settings\n"); 591 pr_info("PCI-DMA: Restoring GART aperture settings\n");
589 592
590 for (i = 0; i < num_k8_northbridges; i++) { 593 for (i = 0; i < num_k8_northbridges; i++) {
591 struct pci_dev *dev = k8_northbridges[i]; 594 struct pci_dev *dev = k8_northbridges[i];
592 595
593 /* 596 /*
594 * Don't enable translations just yet. That is the next 597 * Don't enable translations just yet. That is the next
595 * step. Restore the pre-suspend aperture settings. 598 * step. Restore the pre-suspend aperture settings.
596 */ 599 */
597 pci_write_config_dword(dev, AMD64_GARTAPERTURECTL, 600 pci_write_config_dword(dev, AMD64_GARTAPERTURECTL, aperture_order << 1);
598 aperture_order << 1); 601 pci_write_config_dword(dev, AMD64_GARTAPERTUREBASE, aperture_alloc >> 25);
599 pci_write_config_dword(dev, AMD64_GARTAPERTUREBASE,
600 aperture_alloc >> 25);
601 }
602 } 602 }
603}
604
605static int gart_resume(struct sys_device *dev)
606{
607 pr_info("PCI-DMA: Resuming GART IOMMU\n");
608
609 gart_fixup_northbridges(dev);
603 610
604 enable_gart_translations(); 611 enable_gart_translations();
605 612
@@ -612,15 +619,14 @@ static int gart_suspend(struct sys_device *dev, pm_message_t state)
612} 619}
613 620
614static struct sysdev_class gart_sysdev_class = { 621static struct sysdev_class gart_sysdev_class = {
615 .name = "gart", 622 .name = "gart",
616 .suspend = gart_suspend, 623 .suspend = gart_suspend,
617 .resume = gart_resume, 624 .resume = gart_resume,
618 625
619}; 626};
620 627
621static struct sys_device device_gart = { 628static struct sys_device device_gart = {
622 .id = 0, 629 .cls = &gart_sysdev_class,
623 .cls = &gart_sysdev_class,
624}; 630};
625 631
626/* 632/*
@@ -635,7 +641,8 @@ static __init int init_k8_gatt(struct agp_kern_info *info)
635 void *gatt; 641 void *gatt;
636 int i, error; 642 int i, error;
637 643
638 printk(KERN_INFO "PCI-DMA: Disabling AGP.\n"); 644 pr_info("PCI-DMA: Disabling AGP.\n");
645
639 aper_size = aper_base = info->aper_size = 0; 646 aper_size = aper_base = info->aper_size = 0;
640 dev = NULL; 647 dev = NULL;
641 for (i = 0; i < num_k8_northbridges; i++) { 648 for (i = 0; i < num_k8_northbridges; i++) {
@@ -653,6 +660,7 @@ static __init int init_k8_gatt(struct agp_kern_info *info)
653 } 660 }
654 if (!aper_base) 661 if (!aper_base)
655 goto nommu; 662 goto nommu;
663
656 info->aper_base = aper_base; 664 info->aper_base = aper_base;
657 info->aper_size = aper_size >> 20; 665 info->aper_size = aper_size >> 20;
658 666
@@ -675,14 +683,14 @@ static __init int init_k8_gatt(struct agp_kern_info *info)
675 683
676 flush_gart(); 684 flush_gart();
677 685
678 printk(KERN_INFO "PCI-DMA: aperture base @ %x size %u KB\n", 686 pr_info("PCI-DMA: aperture base @ %x size %u KB\n",
679 aper_base, aper_size>>10); 687 aper_base, aper_size>>10);
680 688
681 return 0; 689 return 0;
682 690
683 nommu: 691 nommu:
684 /* Should not happen anymore */ 692 /* Should not happen anymore */
685 printk(KERN_WARNING "PCI-DMA: More than 4GB of RAM and no IOMMU\n" 693 pr_warning("PCI-DMA: More than 4GB of RAM and no IOMMU\n"
686 "falling back to iommu=soft.\n"); 694 "falling back to iommu=soft.\n");
687 return -1; 695 return -1;
688} 696}
@@ -744,23 +752,23 @@ int __init gart_iommu_init(void)
744 !gart_iommu_aperture || 752 !gart_iommu_aperture ||
745 (no_agp && init_k8_gatt(&info) < 0)) { 753 (no_agp && init_k8_gatt(&info) < 0)) {
746 if (max_pfn > MAX_DMA32_PFN) { 754 if (max_pfn > MAX_DMA32_PFN) {
747 printk(KERN_WARNING "More than 4GB of memory " 755 pr_warning("More than 4GB of memory but GART IOMMU not available.\n");
748 "but GART IOMMU not available.\n"); 756 pr_warning("falling back to iommu=soft.\n");
749 printk(KERN_WARNING "falling back to iommu=soft.\n");
750 } 757 }
751 return 0; 758 return 0;
752 } 759 }
753 760
754 /* need to map that range */ 761 /* need to map that range */
755 aper_size = info.aper_size << 20; 762 aper_size = info.aper_size << 20;
756 aper_base = info.aper_base; 763 aper_base = info.aper_base;
757 end_pfn = (aper_base>>PAGE_SHIFT) + (aper_size>>PAGE_SHIFT); 764 end_pfn = (aper_base>>PAGE_SHIFT) + (aper_size>>PAGE_SHIFT);
765
758 if (end_pfn > max_low_pfn_mapped) { 766 if (end_pfn > max_low_pfn_mapped) {
759 start_pfn = (aper_base>>PAGE_SHIFT); 767 start_pfn = (aper_base>>PAGE_SHIFT);
760 init_memory_mapping(start_pfn<<PAGE_SHIFT, end_pfn<<PAGE_SHIFT); 768 init_memory_mapping(start_pfn<<PAGE_SHIFT, end_pfn<<PAGE_SHIFT);
761 } 769 }
762 770
763 printk(KERN_INFO "PCI-DMA: using GART IOMMU.\n"); 771 pr_info("PCI-DMA: using GART IOMMU.\n");
764 iommu_size = check_iommu_size(info.aper_base, aper_size); 772 iommu_size = check_iommu_size(info.aper_base, aper_size);
765 iommu_pages = iommu_size >> PAGE_SHIFT; 773 iommu_pages = iommu_size >> PAGE_SHIFT;
766 774
@@ -775,8 +783,7 @@ int __init gart_iommu_init(void)
775 783
776 ret = dma_debug_resize_entries(iommu_pages); 784 ret = dma_debug_resize_entries(iommu_pages);
777 if (ret) 785 if (ret)
778 printk(KERN_DEBUG 786 pr_debug("PCI-DMA: Cannot trace all the entries\n");
779 "PCI-DMA: Cannot trace all the entries\n");
780 } 787 }
781#endif 788#endif
782 789
@@ -786,15 +793,14 @@ int __init gart_iommu_init(void)
786 */ 793 */
787 iommu_area_reserve(iommu_gart_bitmap, 0, EMERGENCY_PAGES); 794 iommu_area_reserve(iommu_gart_bitmap, 0, EMERGENCY_PAGES);
788 795
789 agp_memory_reserved = iommu_size; 796 pr_info("PCI-DMA: Reserving %luMB of IOMMU area in the AGP aperture\n",
790 printk(KERN_INFO
791 "PCI-DMA: Reserving %luMB of IOMMU area in the AGP aperture\n",
792 iommu_size >> 20); 797 iommu_size >> 20);
793 798
794 iommu_start = aper_size - iommu_size; 799 agp_memory_reserved = iommu_size;
795 iommu_bus_base = info.aper_base + iommu_start; 800 iommu_start = aper_size - iommu_size;
796 bad_dma_addr = iommu_bus_base; 801 iommu_bus_base = info.aper_base + iommu_start;
797 iommu_gatt_base = agp_gatt_table + (iommu_start>>PAGE_SHIFT); 802 bad_dma_addr = iommu_bus_base;
803 iommu_gatt_base = agp_gatt_table + (iommu_start>>PAGE_SHIFT);
798 804
799 /* 805 /*
800 * Unmap the IOMMU part of the GART. The alias of the page is 806 * Unmap the IOMMU part of the GART. The alias of the page is
@@ -816,7 +822,7 @@ int __init gart_iommu_init(void)
816 * the pages as Not-Present: 822 * the pages as Not-Present:
817 */ 823 */
818 wbinvd(); 824 wbinvd();
819 825
820 /* 826 /*
821 * Now all caches are flushed and we can safely enable 827 * Now all caches are flushed and we can safely enable
822 * GART hardware. Doing it early leaves the possibility 828 * GART hardware. Doing it early leaves the possibility