diff options
author | Paul Mackerras <paulus@samba.org> | 2007-07-10 23:28:26 -0400 |
---|---|---|
committer | Paul Mackerras <paulus@samba.org> | 2007-07-10 23:28:26 -0400 |
commit | bf22f6fe2d72b4d7e9035be8ceb340414cf490e3 (patch) | |
tree | 14085d90de0428316479fe6de8a0c6d32e6e65e2 /arch/powerpc/kernel/pci_64.c | |
parent | 4eb6bf6bfb580afaf1e1a1d30cba17a078530cf4 (diff) | |
parent | 93ab471889c6662b42ce7da257f31f24c08d7d9e (diff) |
Merge branch 'for-2.6.23' into merge
Diffstat (limited to 'arch/powerpc/kernel/pci_64.c')
-rw-r--r-- | arch/powerpc/kernel/pci_64.c | 750 |
1 files changed, 126 insertions, 624 deletions
diff --git a/arch/powerpc/kernel/pci_64.c b/arch/powerpc/kernel/pci_64.c index 249cca27a9b8..93b2920effc5 100644 --- a/arch/powerpc/kernel/pci_64.c +++ b/arch/powerpc/kernel/pci_64.c | |||
@@ -22,6 +22,7 @@ | |||
22 | #include <linux/list.h> | 22 | #include <linux/list.h> |
23 | #include <linux/syscalls.h> | 23 | #include <linux/syscalls.h> |
24 | #include <linux/irq.h> | 24 | #include <linux/irq.h> |
25 | #include <linux/vmalloc.h> | ||
25 | 26 | ||
26 | #include <asm/processor.h> | 27 | #include <asm/processor.h> |
27 | #include <asm/io.h> | 28 | #include <asm/io.h> |
@@ -41,35 +42,23 @@ | |||
41 | 42 | ||
42 | unsigned long pci_probe_only = 1; | 43 | unsigned long pci_probe_only = 1; |
43 | int pci_assign_all_buses = 0; | 44 | int pci_assign_all_buses = 0; |
44 | static int pci_initial_scan_done; | ||
45 | 45 | ||
46 | static void fixup_resource(struct resource *res, struct pci_dev *dev); | 46 | static void fixup_resource(struct resource *res, struct pci_dev *dev); |
47 | static void do_bus_setup(struct pci_bus *bus); | 47 | static void do_bus_setup(struct pci_bus *bus); |
48 | static void phbs_remap_io(void); | ||
49 | 48 | ||
50 | /* pci_io_base -- the base address from which io bars are offsets. | 49 | /* pci_io_base -- the base address from which io bars are offsets. |
51 | * This is the lowest I/O base address (so bar values are always positive), | 50 | * This is the lowest I/O base address (so bar values are always positive), |
52 | * and it *must* be the start of ISA space if an ISA bus exists because | 51 | * and it *must* be the start of ISA space if an ISA bus exists because |
53 | * ISA drivers use hard coded offsets. If no ISA bus exists a dummy | 52 | * ISA drivers use hard coded offsets. If no ISA bus exists nothing |
54 | * page is mapped and isa_io_limit prevents access to it. | 53 | * is mapped on the first 64K of IO space |
55 | */ | 54 | */ |
56 | unsigned long isa_io_base; /* NULL if no ISA bus */ | 55 | unsigned long pci_io_base = ISA_IO_BASE; |
57 | EXPORT_SYMBOL(isa_io_base); | ||
58 | unsigned long pci_io_base; | ||
59 | EXPORT_SYMBOL(pci_io_base); | 56 | EXPORT_SYMBOL(pci_io_base); |
60 | 57 | ||
61 | void iSeries_pcibios_init(void); | ||
62 | |||
63 | LIST_HEAD(hose_list); | 58 | LIST_HEAD(hose_list); |
64 | 59 | ||
65 | static struct dma_mapping_ops *pci_dma_ops; | 60 | static struct dma_mapping_ops *pci_dma_ops; |
66 | 61 | ||
67 | int global_phb_number; /* Global phb counter */ | ||
68 | |||
69 | /* Cached ISA bridge dev. */ | ||
70 | struct pci_dev *ppc64_isabridge_dev = NULL; | ||
71 | EXPORT_SYMBOL_GPL(ppc64_isabridge_dev); | ||
72 | |||
73 | void set_pci_dma_ops(struct dma_mapping_ops *dma_ops) | 62 | void set_pci_dma_ops(struct dma_mapping_ops *dma_ops) |
74 | { | 63 | { |
75 | pci_dma_ops = dma_ops; | 64 | pci_dma_ops = dma_ops; |
@@ -100,7 +89,7 @@ void pcibios_resource_to_bus(struct pci_dev *dev, struct pci_bus_region *region | |||
100 | return; | 89 | return; |
101 | 90 | ||
102 | if (res->flags & IORESOURCE_IO) | 91 | if (res->flags & IORESOURCE_IO) |
103 | offset = (unsigned long)hose->io_base_virt - pci_io_base; | 92 | offset = (unsigned long)hose->io_base_virt - _IO_BASE; |
104 | 93 | ||
105 | if (res->flags & IORESOURCE_MEM) | 94 | if (res->flags & IORESOURCE_MEM) |
106 | offset = hose->pci_mem_offset; | 95 | offset = hose->pci_mem_offset; |
@@ -119,7 +108,7 @@ void pcibios_bus_to_resource(struct pci_dev *dev, struct resource *res, | |||
119 | return; | 108 | return; |
120 | 109 | ||
121 | if (res->flags & IORESOURCE_IO) | 110 | if (res->flags & IORESOURCE_IO) |
122 | offset = (unsigned long)hose->io_base_virt - pci_io_base; | 111 | offset = (unsigned long)hose->io_base_virt - _IO_BASE; |
123 | 112 | ||
124 | if (res->flags & IORESOURCE_MEM) | 113 | if (res->flags & IORESOURCE_MEM) |
125 | offset = hose->pci_mem_offset; | 114 | offset = hose->pci_mem_offset; |
@@ -156,7 +145,7 @@ void pcibios_align_resource(void *data, struct resource *res, | |||
156 | 145 | ||
157 | if (res->flags & IORESOURCE_IO) { | 146 | if (res->flags & IORESOURCE_IO) { |
158 | unsigned long offset = (unsigned long)hose->io_base_virt - | 147 | unsigned long offset = (unsigned long)hose->io_base_virt - |
159 | pci_io_base; | 148 | _IO_BASE; |
160 | /* Make sure we start at our min on all hoses */ | 149 | /* Make sure we start at our min on all hoses */ |
161 | if (start - offset < PCIBIOS_MIN_IO) | 150 | if (start - offset < PCIBIOS_MIN_IO) |
162 | start = PCIBIOS_MIN_IO + offset; | 151 | start = PCIBIOS_MIN_IO + offset; |
@@ -180,55 +169,6 @@ void pcibios_align_resource(void *data, struct resource *res, | |||
180 | res->start = start; | 169 | res->start = start; |
181 | } | 170 | } |
182 | 171 | ||
183 | static DEFINE_SPINLOCK(hose_spinlock); | ||
184 | |||
185 | /* | ||
186 | * pci_controller(phb) initialized common variables. | ||
187 | */ | ||
188 | static void __devinit pci_setup_pci_controller(struct pci_controller *hose) | ||
189 | { | ||
190 | memset(hose, 0, sizeof(struct pci_controller)); | ||
191 | |||
192 | spin_lock(&hose_spinlock); | ||
193 | hose->global_number = global_phb_number++; | ||
194 | list_add_tail(&hose->list_node, &hose_list); | ||
195 | spin_unlock(&hose_spinlock); | ||
196 | } | ||
197 | |||
198 | struct pci_controller * pcibios_alloc_controller(struct device_node *dev) | ||
199 | { | ||
200 | struct pci_controller *phb; | ||
201 | |||
202 | if (mem_init_done) | ||
203 | phb = kmalloc(sizeof(struct pci_controller), GFP_KERNEL); | ||
204 | else | ||
205 | phb = alloc_bootmem(sizeof (struct pci_controller)); | ||
206 | if (phb == NULL) | ||
207 | return NULL; | ||
208 | pci_setup_pci_controller(phb); | ||
209 | phb->arch_data = dev; | ||
210 | phb->is_dynamic = mem_init_done; | ||
211 | if (dev) { | ||
212 | int nid = of_node_to_nid(dev); | ||
213 | |||
214 | if (nid < 0 || !node_online(nid)) | ||
215 | nid = -1; | ||
216 | |||
217 | PHB_SET_NODE(phb, nid); | ||
218 | } | ||
219 | return phb; | ||
220 | } | ||
221 | |||
222 | void pcibios_free_controller(struct pci_controller *phb) | ||
223 | { | ||
224 | spin_lock(&hose_spinlock); | ||
225 | list_del(&phb->list_node); | ||
226 | spin_unlock(&hose_spinlock); | ||
227 | |||
228 | if (phb->is_dynamic) | ||
229 | kfree(phb); | ||
230 | } | ||
231 | |||
232 | void __devinit pcibios_claim_one_bus(struct pci_bus *b) | 172 | void __devinit pcibios_claim_one_bus(struct pci_bus *b) |
233 | { | 173 | { |
234 | struct pci_dev *dev; | 174 | struct pci_dev *dev; |
@@ -291,7 +231,6 @@ static unsigned int pci_parse_of_flags(u32 addr0) | |||
291 | return flags; | 231 | return flags; |
292 | } | 232 | } |
293 | 233 | ||
294 | #define GET_64BIT(prop, i) ((((u64) (prop)[(i)]) << 32) | (prop)[(i)+1]) | ||
295 | 234 | ||
296 | static void pci_parse_of_addrs(struct device_node *node, struct pci_dev *dev) | 235 | static void pci_parse_of_addrs(struct device_node *node, struct pci_dev *dev) |
297 | { | 236 | { |
@@ -310,8 +249,8 @@ static void pci_parse_of_addrs(struct device_node *node, struct pci_dev *dev) | |||
310 | flags = pci_parse_of_flags(addrs[0]); | 249 | flags = pci_parse_of_flags(addrs[0]); |
311 | if (!flags) | 250 | if (!flags) |
312 | continue; | 251 | continue; |
313 | base = GET_64BIT(addrs, 1); | 252 | base = of_read_number(&addrs[1], 2); |
314 | size = GET_64BIT(addrs, 3); | 253 | size = of_read_number(&addrs[3], 2); |
315 | if (!size) | 254 | if (!size) |
316 | continue; | 255 | continue; |
317 | i = addrs[0] & 0xff; | 256 | i = addrs[0] & 0xff; |
@@ -477,7 +416,7 @@ void __devinit of_scan_pci_bridge(struct device_node *node, | |||
477 | i = 1; | 416 | i = 1; |
478 | for (; len >= 32; len -= 32, ranges += 8) { | 417 | for (; len >= 32; len -= 32, ranges += 8) { |
479 | flags = pci_parse_of_flags(ranges[0]); | 418 | flags = pci_parse_of_flags(ranges[0]); |
480 | size = GET_64BIT(ranges, 6); | 419 | size = of_read_number(&ranges[6], 2); |
481 | if (flags == 0 || size == 0) | 420 | if (flags == 0 || size == 0) |
482 | continue; | 421 | continue; |
483 | if (flags & IORESOURCE_IO) { | 422 | if (flags & IORESOURCE_IO) { |
@@ -496,7 +435,7 @@ void __devinit of_scan_pci_bridge(struct device_node *node, | |||
496 | res = bus->resource[i]; | 435 | res = bus->resource[i]; |
497 | ++i; | 436 | ++i; |
498 | } | 437 | } |
499 | res->start = GET_64BIT(ranges, 1); | 438 | res->start = of_read_number(&ranges[1], 2); |
500 | res->end = res->start + size - 1; | 439 | res->end = res->start + size - 1; |
501 | res->flags = flags; | 440 | res->flags = flags; |
502 | fixup_resource(res, dev); | 441 | fixup_resource(res, dev); |
@@ -535,10 +474,16 @@ void __devinit scan_phb(struct pci_controller *hose) | |||
535 | bus->secondary = hose->first_busno; | 474 | bus->secondary = hose->first_busno; |
536 | hose->bus = bus; | 475 | hose->bus = bus; |
537 | 476 | ||
477 | if (!firmware_has_feature(FW_FEATURE_ISERIES)) | ||
478 | pcibios_map_io_space(bus); | ||
479 | |||
538 | bus->resource[0] = res = &hose->io_resource; | 480 | bus->resource[0] = res = &hose->io_resource; |
539 | if (res->flags && request_resource(&ioport_resource, res)) | 481 | if (res->flags && request_resource(&ioport_resource, res)) { |
540 | printk(KERN_ERR "Failed to request PCI IO region " | 482 | printk(KERN_ERR "Failed to request PCI IO region " |
541 | "on PCI domain %04x\n", hose->global_number); | 483 | "on PCI domain %04x\n", hose->global_number); |
484 | DBG("res->start = 0x%016lx, res->end = 0x%016lx\n", | ||
485 | res->start, res->end); | ||
486 | } | ||
542 | 487 | ||
543 | for (i = 0; i < 3; ++i) { | 488 | for (i = 0; i < 3; ++i) { |
544 | res = &hose->mem_resources[i]; | 489 | res = &hose->mem_resources[i]; |
@@ -596,17 +541,6 @@ static int __init pcibios_init(void) | |||
596 | if (ppc_md.pcibios_fixup) | 541 | if (ppc_md.pcibios_fixup) |
597 | ppc_md.pcibios_fixup(); | 542 | ppc_md.pcibios_fixup(); |
598 | 543 | ||
599 | /* Cache the location of the ISA bridge (if we have one) */ | ||
600 | ppc64_isabridge_dev = pci_get_class(PCI_CLASS_BRIDGE_ISA << 8, NULL); | ||
601 | if (ppc64_isabridge_dev != NULL) | ||
602 | printk(KERN_DEBUG "ISA bridge at %s\n", pci_name(ppc64_isabridge_dev)); | ||
603 | |||
604 | if (!firmware_has_feature(FW_FEATURE_ISERIES)) | ||
605 | /* map in PCI I/O space */ | ||
606 | phbs_remap_io(); | ||
607 | |||
608 | pci_initial_scan_done = 1; | ||
609 | |||
610 | printk(KERN_DEBUG "PCI: Probing PCI hardware done\n"); | 544 | printk(KERN_DEBUG "PCI: Probing PCI hardware done\n"); |
611 | 545 | ||
612 | return 0; | 546 | return 0; |
@@ -614,11 +548,6 @@ static int __init pcibios_init(void) | |||
614 | 548 | ||
615 | subsys_initcall(pcibios_init); | 549 | subsys_initcall(pcibios_init); |
616 | 550 | ||
617 | char __init *pcibios_setup(char *str) | ||
618 | { | ||
619 | return str; | ||
620 | } | ||
621 | |||
622 | int pcibios_enable_device(struct pci_dev *dev, int mask) | 551 | int pcibios_enable_device(struct pci_dev *dev, int mask) |
623 | { | 552 | { |
624 | u16 cmd, oldcmd; | 553 | u16 cmd, oldcmd; |
@@ -649,22 +578,6 @@ int pcibios_enable_device(struct pci_dev *dev, int mask) | |||
649 | return 0; | 578 | return 0; |
650 | } | 579 | } |
651 | 580 | ||
652 | /* | ||
653 | * Return the domain number for this bus. | ||
654 | */ | ||
655 | int pci_domain_nr(struct pci_bus *bus) | ||
656 | { | ||
657 | if (firmware_has_feature(FW_FEATURE_ISERIES)) | ||
658 | return 0; | ||
659 | else { | ||
660 | struct pci_controller *hose = pci_bus_to_host(bus); | ||
661 | |||
662 | return hose->global_number; | ||
663 | } | ||
664 | } | ||
665 | |||
666 | EXPORT_SYMBOL(pci_domain_nr); | ||
667 | |||
668 | /* Decide whether to display the domain number in /proc */ | 581 | /* Decide whether to display the domain number in /proc */ |
669 | int pci_proc_domain(struct pci_bus *bus) | 582 | int pci_proc_domain(struct pci_bus *bus) |
670 | { | 583 | { |
@@ -676,281 +589,6 @@ int pci_proc_domain(struct pci_bus *bus) | |||
676 | } | 589 | } |
677 | } | 590 | } |
678 | 591 | ||
679 | /* | ||
680 | * Platform support for /proc/bus/pci/X/Y mmap()s, | ||
681 | * modelled on the sparc64 implementation by Dave Miller. | ||
682 | * -- paulus. | ||
683 | */ | ||
684 | |||
685 | /* | ||
686 | * Adjust vm_pgoff of VMA such that it is the physical page offset | ||
687 | * corresponding to the 32-bit pci bus offset for DEV requested by the user. | ||
688 | * | ||
689 | * Basically, the user finds the base address for his device which he wishes | ||
690 | * to mmap. They read the 32-bit value from the config space base register, | ||
691 | * add whatever PAGE_SIZE multiple offset they wish, and feed this into the | ||
692 | * offset parameter of mmap on /proc/bus/pci/XXX for that device. | ||
693 | * | ||
694 | * Returns negative error code on failure, zero on success. | ||
695 | */ | ||
696 | static struct resource *__pci_mmap_make_offset(struct pci_dev *dev, | ||
697 | resource_size_t *offset, | ||
698 | enum pci_mmap_state mmap_state) | ||
699 | { | ||
700 | struct pci_controller *hose = pci_bus_to_host(dev->bus); | ||
701 | unsigned long io_offset = 0; | ||
702 | int i, res_bit; | ||
703 | |||
704 | if (hose == 0) | ||
705 | return NULL; /* should never happen */ | ||
706 | |||
707 | /* If memory, add on the PCI bridge address offset */ | ||
708 | if (mmap_state == pci_mmap_mem) { | ||
709 | #if 0 /* See comment in pci_resource_to_user() for why this is disabled */ | ||
710 | *offset += hose->pci_mem_offset; | ||
711 | #endif | ||
712 | res_bit = IORESOURCE_MEM; | ||
713 | } else { | ||
714 | io_offset = (unsigned long)hose->io_base_virt - pci_io_base; | ||
715 | *offset += io_offset; | ||
716 | res_bit = IORESOURCE_IO; | ||
717 | } | ||
718 | |||
719 | /* | ||
720 | * Check that the offset requested corresponds to one of the | ||
721 | * resources of the device. | ||
722 | */ | ||
723 | for (i = 0; i <= PCI_ROM_RESOURCE; i++) { | ||
724 | struct resource *rp = &dev->resource[i]; | ||
725 | int flags = rp->flags; | ||
726 | |||
727 | /* treat ROM as memory (should be already) */ | ||
728 | if (i == PCI_ROM_RESOURCE) | ||
729 | flags |= IORESOURCE_MEM; | ||
730 | |||
731 | /* Active and same type? */ | ||
732 | if ((flags & res_bit) == 0) | ||
733 | continue; | ||
734 | |||
735 | /* In the range of this resource? */ | ||
736 | if (*offset < (rp->start & PAGE_MASK) || *offset > rp->end) | ||
737 | continue; | ||
738 | |||
739 | /* found it! construct the final physical address */ | ||
740 | if (mmap_state == pci_mmap_io) | ||
741 | *offset += hose->io_base_phys - io_offset; | ||
742 | return rp; | ||
743 | } | ||
744 | |||
745 | return NULL; | ||
746 | } | ||
747 | |||
748 | /* | ||
749 | * Set vm_page_prot of VMA, as appropriate for this architecture, for a pci | ||
750 | * device mapping. | ||
751 | */ | ||
752 | static pgprot_t __pci_mmap_set_pgprot(struct pci_dev *dev, struct resource *rp, | ||
753 | pgprot_t protection, | ||
754 | enum pci_mmap_state mmap_state, | ||
755 | int write_combine) | ||
756 | { | ||
757 | unsigned long prot = pgprot_val(protection); | ||
758 | |||
759 | /* Write combine is always 0 on non-memory space mappings. On | ||
760 | * memory space, if the user didn't pass 1, we check for a | ||
761 | * "prefetchable" resource. This is a bit hackish, but we use | ||
762 | * this to workaround the inability of /sysfs to provide a write | ||
763 | * combine bit | ||
764 | */ | ||
765 | if (mmap_state != pci_mmap_mem) | ||
766 | write_combine = 0; | ||
767 | else if (write_combine == 0) { | ||
768 | if (rp->flags & IORESOURCE_PREFETCH) | ||
769 | write_combine = 1; | ||
770 | } | ||
771 | |||
772 | /* XXX would be nice to have a way to ask for write-through */ | ||
773 | prot |= _PAGE_NO_CACHE; | ||
774 | if (write_combine) | ||
775 | prot &= ~_PAGE_GUARDED; | ||
776 | else | ||
777 | prot |= _PAGE_GUARDED; | ||
778 | |||
779 | return __pgprot(prot); | ||
780 | } | ||
781 | |||
782 | /* | ||
783 | * This one is used by /dev/mem and fbdev who have no clue about the | ||
784 | * PCI device, it tries to find the PCI device first and calls the | ||
785 | * above routine | ||
786 | */ | ||
787 | pgprot_t pci_phys_mem_access_prot(struct file *file, | ||
788 | unsigned long pfn, | ||
789 | unsigned long size, | ||
790 | pgprot_t protection) | ||
791 | { | ||
792 | struct pci_dev *pdev = NULL; | ||
793 | struct resource *found = NULL; | ||
794 | unsigned long prot = pgprot_val(protection); | ||
795 | unsigned long offset = pfn << PAGE_SHIFT; | ||
796 | int i; | ||
797 | |||
798 | if (page_is_ram(pfn)) | ||
799 | return __pgprot(prot); | ||
800 | |||
801 | prot |= _PAGE_NO_CACHE | _PAGE_GUARDED; | ||
802 | |||
803 | for_each_pci_dev(pdev) { | ||
804 | for (i = 0; i <= PCI_ROM_RESOURCE; i++) { | ||
805 | struct resource *rp = &pdev->resource[i]; | ||
806 | int flags = rp->flags; | ||
807 | |||
808 | /* Active and same type? */ | ||
809 | if ((flags & IORESOURCE_MEM) == 0) | ||
810 | continue; | ||
811 | /* In the range of this resource? */ | ||
812 | if (offset < (rp->start & PAGE_MASK) || | ||
813 | offset > rp->end) | ||
814 | continue; | ||
815 | found = rp; | ||
816 | break; | ||
817 | } | ||
818 | if (found) | ||
819 | break; | ||
820 | } | ||
821 | if (found) { | ||
822 | if (found->flags & IORESOURCE_PREFETCH) | ||
823 | prot &= ~_PAGE_GUARDED; | ||
824 | pci_dev_put(pdev); | ||
825 | } | ||
826 | |||
827 | DBG("non-PCI map for %lx, prot: %lx\n", offset, prot); | ||
828 | |||
829 | return __pgprot(prot); | ||
830 | } | ||
831 | |||
832 | |||
833 | /* | ||
834 | * Perform the actual remap of the pages for a PCI device mapping, as | ||
835 | * appropriate for this architecture. The region in the process to map | ||
836 | * is described by vm_start and vm_end members of VMA, the base physical | ||
837 | * address is found in vm_pgoff. | ||
838 | * The pci device structure is provided so that architectures may make mapping | ||
839 | * decisions on a per-device or per-bus basis. | ||
840 | * | ||
841 | * Returns a negative error code on failure, zero on success. | ||
842 | */ | ||
843 | int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma, | ||
844 | enum pci_mmap_state mmap_state, int write_combine) | ||
845 | { | ||
846 | resource_size_t offset = vma->vm_pgoff << PAGE_SHIFT; | ||
847 | struct resource *rp; | ||
848 | int ret; | ||
849 | |||
850 | rp = __pci_mmap_make_offset(dev, &offset, mmap_state); | ||
851 | if (rp == NULL) | ||
852 | return -EINVAL; | ||
853 | |||
854 | vma->vm_pgoff = offset >> PAGE_SHIFT; | ||
855 | vma->vm_page_prot = __pci_mmap_set_pgprot(dev, rp, | ||
856 | vma->vm_page_prot, | ||
857 | mmap_state, write_combine); | ||
858 | |||
859 | ret = remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff, | ||
860 | vma->vm_end - vma->vm_start, vma->vm_page_prot); | ||
861 | |||
862 | return ret; | ||
863 | } | ||
864 | |||
865 | static ssize_t pci_show_devspec(struct device *dev, | ||
866 | struct device_attribute *attr, char *buf) | ||
867 | { | ||
868 | struct pci_dev *pdev; | ||
869 | struct device_node *np; | ||
870 | |||
871 | pdev = to_pci_dev (dev); | ||
872 | np = pci_device_to_OF_node(pdev); | ||
873 | if (np == NULL || np->full_name == NULL) | ||
874 | return 0; | ||
875 | return sprintf(buf, "%s", np->full_name); | ||
876 | } | ||
877 | static DEVICE_ATTR(devspec, S_IRUGO, pci_show_devspec, NULL); | ||
878 | |||
879 | void pcibios_add_platform_entries(struct pci_dev *pdev) | ||
880 | { | ||
881 | device_create_file(&pdev->dev, &dev_attr_devspec); | ||
882 | } | ||
883 | |||
884 | #define ISA_SPACE_MASK 0x1 | ||
885 | #define ISA_SPACE_IO 0x1 | ||
886 | |||
887 | static void __devinit pci_process_ISA_OF_ranges(struct device_node *isa_node, | ||
888 | unsigned long phb_io_base_phys, | ||
889 | void __iomem * phb_io_base_virt) | ||
890 | { | ||
891 | /* Remove these asap */ | ||
892 | |||
893 | struct pci_address { | ||
894 | u32 a_hi; | ||
895 | u32 a_mid; | ||
896 | u32 a_lo; | ||
897 | }; | ||
898 | |||
899 | struct isa_address { | ||
900 | u32 a_hi; | ||
901 | u32 a_lo; | ||
902 | }; | ||
903 | |||
904 | struct isa_range { | ||
905 | struct isa_address isa_addr; | ||
906 | struct pci_address pci_addr; | ||
907 | unsigned int size; | ||
908 | }; | ||
909 | |||
910 | const struct isa_range *range; | ||
911 | unsigned long pci_addr; | ||
912 | unsigned int isa_addr; | ||
913 | unsigned int size; | ||
914 | int rlen = 0; | ||
915 | |||
916 | range = of_get_property(isa_node, "ranges", &rlen); | ||
917 | if (range == NULL || (rlen < sizeof(struct isa_range))) { | ||
918 | printk(KERN_ERR "no ISA ranges or unexpected isa range size," | ||
919 | "mapping 64k\n"); | ||
920 | __ioremap_explicit(phb_io_base_phys, | ||
921 | (unsigned long)phb_io_base_virt, | ||
922 | 0x10000, _PAGE_NO_CACHE | _PAGE_GUARDED); | ||
923 | return; | ||
924 | } | ||
925 | |||
926 | /* From "ISA Binding to 1275" | ||
927 | * The ranges property is laid out as an array of elements, | ||
928 | * each of which comprises: | ||
929 | * cells 0 - 1: an ISA address | ||
930 | * cells 2 - 4: a PCI address | ||
931 | * (size depending on dev->n_addr_cells) | ||
932 | * cell 5: the size of the range | ||
933 | */ | ||
934 | if ((range->isa_addr.a_hi && ISA_SPACE_MASK) == ISA_SPACE_IO) { | ||
935 | isa_addr = range->isa_addr.a_lo; | ||
936 | pci_addr = (unsigned long) range->pci_addr.a_mid << 32 | | ||
937 | range->pci_addr.a_lo; | ||
938 | |||
939 | /* Assume these are both zero */ | ||
940 | if ((pci_addr != 0) || (isa_addr != 0)) { | ||
941 | printk(KERN_ERR "unexpected isa to pci mapping: %s\n", | ||
942 | __FUNCTION__); | ||
943 | return; | ||
944 | } | ||
945 | |||
946 | size = PAGE_ALIGN(range->size); | ||
947 | |||
948 | __ioremap_explicit(phb_io_base_phys, | ||
949 | (unsigned long) phb_io_base_virt, | ||
950 | size, _PAGE_NO_CACHE | _PAGE_GUARDED); | ||
951 | } | ||
952 | } | ||
953 | |||
954 | void __devinit pci_process_bridge_OF_ranges(struct pci_controller *hose, | 592 | void __devinit pci_process_bridge_OF_ranges(struct pci_controller *hose, |
955 | struct device_node *dev, int prim) | 593 | struct device_node *dev, int prim) |
956 | { | 594 | { |
@@ -1045,155 +683,122 @@ void __devinit pci_process_bridge_OF_ranges(struct pci_controller *hose, | |||
1045 | } | 683 | } |
1046 | } | 684 | } |
1047 | 685 | ||
1048 | void __devinit pci_setup_phb_io(struct pci_controller *hose, int primary) | 686 | #ifdef CONFIG_HOTPLUG |
687 | |||
688 | int pcibios_unmap_io_space(struct pci_bus *bus) | ||
1049 | { | 689 | { |
1050 | unsigned long size = hose->pci_io_size; | 690 | struct pci_controller *hose; |
1051 | unsigned long io_virt_offset; | ||
1052 | struct resource *res; | ||
1053 | struct device_node *isa_dn; | ||
1054 | 691 | ||
1055 | if (size == 0) | 692 | WARN_ON(bus == NULL); |
1056 | return; | ||
1057 | 693 | ||
1058 | hose->io_base_virt = reserve_phb_iospace(size); | 694 | /* If this is not a PHB, we only flush the hash table over |
1059 | DBG("phb%d io_base_phys 0x%lx io_base_virt 0x%lx\n", | 695 | * the area mapped by this bridge. We don't play with the PTE |
1060 | hose->global_number, hose->io_base_phys, | 696 | * mappings since we might have to deal with sub-page alignemnts |
1061 | (unsigned long) hose->io_base_virt); | 697 | * so flushing the hash table is the only sane way to make sure |
1062 | 698 | * that no hash entries are covering that removed bridge area | |
1063 | if (primary) { | 699 | * while still allowing other busses overlapping those pages |
1064 | pci_io_base = (unsigned long)hose->io_base_virt; | 700 | */ |
1065 | isa_dn = of_find_node_by_type(NULL, "isa"); | 701 | if (bus->self) { |
1066 | if (isa_dn) { | 702 | struct resource *res = bus->resource[0]; |
1067 | isa_io_base = pci_io_base; | ||
1068 | pci_process_ISA_OF_ranges(isa_dn, hose->io_base_phys, | ||
1069 | hose->io_base_virt); | ||
1070 | of_node_put(isa_dn); | ||
1071 | } | ||
1072 | } | ||
1073 | 703 | ||
1074 | io_virt_offset = (unsigned long)hose->io_base_virt - pci_io_base; | 704 | DBG("IO unmapping for PCI-PCI bridge %s\n", |
1075 | res = &hose->io_resource; | 705 | pci_name(bus->self)); |
1076 | res->start += io_virt_offset; | ||
1077 | res->end += io_virt_offset; | ||
1078 | 706 | ||
1079 | /* If this is called after the initial PCI scan, then we need to | 707 | __flush_hash_table_range(&init_mm, res->start + _IO_BASE, |
1080 | * proceed to IO mappings now | 708 | res->end - res->start + 1); |
1081 | */ | 709 | return 0; |
1082 | if (pci_initial_scan_done) | 710 | } |
1083 | __ioremap_explicit(hose->io_base_phys, | ||
1084 | (unsigned long)hose->io_base_virt, | ||
1085 | hose->pci_io_size, | ||
1086 | _PAGE_NO_CACHE | _PAGE_GUARDED); | ||
1087 | } | ||
1088 | 711 | ||
1089 | void __devinit pci_setup_phb_io_dynamic(struct pci_controller *hose, | 712 | /* Get the host bridge */ |
1090 | int primary) | 713 | hose = pci_bus_to_host(bus); |
1091 | { | ||
1092 | unsigned long size = hose->pci_io_size; | ||
1093 | unsigned long io_virt_offset; | ||
1094 | struct resource *res; | ||
1095 | 714 | ||
1096 | if (size == 0) | 715 | /* Check if we have IOs allocated */ |
1097 | return; | 716 | if (hose->io_base_alloc == 0) |
717 | return 0; | ||
1098 | 718 | ||
1099 | hose->io_base_virt = __ioremap(hose->io_base_phys, size, | 719 | DBG("IO unmapping for PHB %s\n", |
1100 | _PAGE_NO_CACHE | _PAGE_GUARDED); | 720 | ((struct device_node *)hose->arch_data)->full_name); |
1101 | DBG("phb%d io_base_phys 0x%lx io_base_virt 0x%lx\n", | 721 | DBG(" alloc=0x%p\n", hose->io_base_alloc); |
1102 | hose->global_number, hose->io_base_phys, | ||
1103 | (unsigned long) hose->io_base_virt); | ||
1104 | 722 | ||
1105 | if (primary) | 723 | /* This is a PHB, we fully unmap the IO area */ |
1106 | pci_io_base = (unsigned long)hose->io_base_virt; | 724 | vunmap(hose->io_base_alloc); |
1107 | 725 | ||
1108 | io_virt_offset = (unsigned long)hose->io_base_virt - pci_io_base; | 726 | return 0; |
1109 | res = &hose->io_resource; | ||
1110 | res->start += io_virt_offset; | ||
1111 | res->end += io_virt_offset; | ||
1112 | } | 727 | } |
728 | EXPORT_SYMBOL_GPL(pcibios_unmap_io_space); | ||
1113 | 729 | ||
730 | #endif /* CONFIG_HOTPLUG */ | ||
1114 | 731 | ||
1115 | static int get_bus_io_range(struct pci_bus *bus, unsigned long *start_phys, | 732 | int __devinit pcibios_map_io_space(struct pci_bus *bus) |
1116 | unsigned long *start_virt, unsigned long *size) | ||
1117 | { | 733 | { |
1118 | struct pci_controller *hose = pci_bus_to_host(bus); | 734 | struct vm_struct *area; |
1119 | struct resource *res; | 735 | unsigned long phys_page; |
1120 | 736 | unsigned long size_page; | |
1121 | if (bus->self) | 737 | unsigned long io_virt_offset; |
1122 | res = bus->resource[0]; | 738 | struct pci_controller *hose; |
1123 | else | ||
1124 | /* Root Bus */ | ||
1125 | res = &hose->io_resource; | ||
1126 | |||
1127 | if (res->end == 0 && res->start == 0) | ||
1128 | return 1; | ||
1129 | 739 | ||
1130 | *start_virt = pci_io_base + res->start; | 740 | WARN_ON(bus == NULL); |
1131 | *start_phys = *start_virt + hose->io_base_phys | ||
1132 | - (unsigned long) hose->io_base_virt; | ||
1133 | 741 | ||
1134 | if (res->end > res->start) | 742 | /* If this not a PHB, nothing to do, page tables still exist and |
1135 | *size = res->end - res->start + 1; | 743 | * thus HPTEs will be faulted in when needed |
1136 | else { | 744 | */ |
1137 | printk("%s(): unexpected region 0x%lx->0x%lx\n", | 745 | if (bus->self) { |
1138 | __FUNCTION__, res->start, res->end); | 746 | DBG("IO mapping for PCI-PCI bridge %s\n", |
1139 | return 1; | 747 | pci_name(bus->self)); |
748 | DBG(" virt=0x%016lx...0x%016lx\n", | ||
749 | bus->resource[0]->start + _IO_BASE, | ||
750 | bus->resource[0]->end + _IO_BASE); | ||
751 | return 0; | ||
1140 | } | 752 | } |
1141 | 753 | ||
1142 | return 0; | 754 | /* Get the host bridge */ |
1143 | } | 755 | hose = pci_bus_to_host(bus); |
1144 | 756 | phys_page = _ALIGN_DOWN(hose->io_base_phys, PAGE_SIZE); | |
1145 | int unmap_bus_range(struct pci_bus *bus) | 757 | size_page = _ALIGN_UP(hose->pci_io_size, PAGE_SIZE); |
1146 | { | ||
1147 | unsigned long start_phys; | ||
1148 | unsigned long start_virt; | ||
1149 | unsigned long size; | ||
1150 | 758 | ||
1151 | if (!bus) { | 759 | /* Make sure IO area address is clear */ |
1152 | printk(KERN_ERR "%s() expected bus\n", __FUNCTION__); | 760 | hose->io_base_alloc = NULL; |
1153 | return 1; | ||
1154 | } | ||
1155 | |||
1156 | if (get_bus_io_range(bus, &start_phys, &start_virt, &size)) | ||
1157 | return 1; | ||
1158 | if (__iounmap_explicit((void __iomem *) start_virt, size)) | ||
1159 | return 1; | ||
1160 | |||
1161 | return 0; | ||
1162 | } | ||
1163 | EXPORT_SYMBOL(unmap_bus_range); | ||
1164 | 761 | ||
1165 | int remap_bus_range(struct pci_bus *bus) | 762 | /* If there's no IO to map on that bus, get away too */ |
1166 | { | 763 | if (hose->pci_io_size == 0 || hose->io_base_phys == 0) |
1167 | unsigned long start_phys; | 764 | return 0; |
1168 | unsigned long start_virt; | ||
1169 | unsigned long size; | ||
1170 | 765 | ||
1171 | if (!bus) { | 766 | /* Let's allocate some IO space for that guy. We don't pass |
1172 | printk(KERN_ERR "%s() expected bus\n", __FUNCTION__); | 767 | * VM_IOREMAP because we don't care about alignment tricks that |
1173 | return 1; | 768 | * the core does in that case. Maybe we should due to stupid card |
1174 | } | 769 | * with incomplete address decoding but I'd rather not deal with |
1175 | 770 | * those outside of the reserved 64K legacy region. | |
1176 | 771 | */ | |
1177 | if (get_bus_io_range(bus, &start_phys, &start_virt, &size)) | 772 | area = __get_vm_area(size_page, 0, PHB_IO_BASE, PHB_IO_END); |
1178 | return 1; | 773 | if (area == NULL) |
1179 | if (start_phys == 0) | 774 | return -ENOMEM; |
1180 | return 1; | 775 | hose->io_base_alloc = area->addr; |
1181 | printk(KERN_DEBUG "mapping IO %lx -> %lx, size: %lx\n", start_phys, start_virt, size); | 776 | hose->io_base_virt = (void __iomem *)(area->addr + |
1182 | if (__ioremap_explicit(start_phys, start_virt, size, | 777 | hose->io_base_phys - phys_page); |
1183 | _PAGE_NO_CACHE | _PAGE_GUARDED)) | 778 | |
1184 | return 1; | 779 | DBG("IO mapping for PHB %s\n", |
780 | ((struct device_node *)hose->arch_data)->full_name); | ||
781 | DBG(" phys=0x%016lx, virt=0x%p (alloc=0x%p)\n", | ||
782 | hose->io_base_phys, hose->io_base_virt, hose->io_base_alloc); | ||
783 | DBG(" size=0x%016lx (alloc=0x%016lx)\n", | ||
784 | hose->pci_io_size, size_page); | ||
785 | |||
786 | /* Establish the mapping */ | ||
787 | if (__ioremap_at(phys_page, area->addr, size_page, | ||
788 | _PAGE_NO_CACHE | _PAGE_GUARDED) == NULL) | ||
789 | return -ENOMEM; | ||
790 | |||
791 | /* Fixup hose IO resource */ | ||
792 | io_virt_offset = (unsigned long)hose->io_base_virt - _IO_BASE; | ||
793 | hose->io_resource.start += io_virt_offset; | ||
794 | hose->io_resource.end += io_virt_offset; | ||
795 | |||
796 | DBG(" hose->io_resource=0x%016lx...0x%016lx\n", | ||
797 | hose->io_resource.start, hose->io_resource.end); | ||
1185 | 798 | ||
1186 | return 0; | 799 | return 0; |
1187 | } | 800 | } |
1188 | EXPORT_SYMBOL(remap_bus_range); | 801 | EXPORT_SYMBOL_GPL(pcibios_map_io_space); |
1189 | |||
1190 | static void phbs_remap_io(void) | ||
1191 | { | ||
1192 | struct pci_controller *hose, *tmp; | ||
1193 | |||
1194 | list_for_each_entry_safe(hose, tmp, &hose_list, list_node) | ||
1195 | remap_bus_range(hose->bus); | ||
1196 | } | ||
1197 | 802 | ||
1198 | static void __devinit fixup_resource(struct resource *res, struct pci_dev *dev) | 803 | static void __devinit fixup_resource(struct resource *res, struct pci_dev *dev) |
1199 | { | 804 | { |
@@ -1201,8 +806,7 @@ static void __devinit fixup_resource(struct resource *res, struct pci_dev *dev) | |||
1201 | unsigned long offset; | 806 | unsigned long offset; |
1202 | 807 | ||
1203 | if (res->flags & IORESOURCE_IO) { | 808 | if (res->flags & IORESOURCE_IO) { |
1204 | offset = (unsigned long)hose->io_base_virt - pci_io_base; | 809 | offset = (unsigned long)hose->io_base_virt - _IO_BASE; |
1205 | |||
1206 | res->start += offset; | 810 | res->start += offset; |
1207 | res->end += offset; | 811 | res->end += offset; |
1208 | } else if (res->flags & IORESOURCE_MEM) { | 812 | } else if (res->flags & IORESOURCE_MEM) { |
@@ -1217,9 +821,20 @@ void __devinit pcibios_fixup_device_resources(struct pci_dev *dev, | |||
1217 | /* Update device resources. */ | 821 | /* Update device resources. */ |
1218 | int i; | 822 | int i; |
1219 | 823 | ||
1220 | for (i = 0; i < PCI_NUM_RESOURCES; i++) | 824 | DBG("%s: Fixup resources:\n", pci_name(dev)); |
1221 | if (dev->resource[i].flags) | 825 | for (i = 0; i < PCI_NUM_RESOURCES; i++) { |
1222 | fixup_resource(&dev->resource[i], dev); | 826 | struct resource *res = &dev->resource[i]; |
827 | if (!res->flags) | ||
828 | continue; | ||
829 | |||
830 | DBG(" 0x%02x < %08lx:0x%016lx...0x%016lx\n", | ||
831 | i, res->flags, res->start, res->end); | ||
832 | |||
833 | fixup_resource(res, dev); | ||
834 | |||
835 | DBG(" > %08lx:0x%016lx...0x%016lx\n", | ||
836 | res->flags, res->start, res->end); | ||
837 | } | ||
1223 | } | 838 | } |
1224 | EXPORT_SYMBOL(pcibios_fixup_device_resources); | 839 | EXPORT_SYMBOL(pcibios_fixup_device_resources); |
1225 | 840 | ||
@@ -1289,119 +904,6 @@ void __devinit pcibios_fixup_bus(struct pci_bus *bus) | |||
1289 | } | 904 | } |
1290 | EXPORT_SYMBOL(pcibios_fixup_bus); | 905 | EXPORT_SYMBOL(pcibios_fixup_bus); |
1291 | 906 | ||
1292 | /* | ||
1293 | * Reads the interrupt pin to determine if interrupt is use by card. | ||
1294 | * If the interrupt is used, then gets the interrupt line from the | ||
1295 | * openfirmware and sets it in the pci_dev and pci_config line. | ||
1296 | */ | ||
1297 | int pci_read_irq_line(struct pci_dev *pci_dev) | ||
1298 | { | ||
1299 | struct of_irq oirq; | ||
1300 | unsigned int virq; | ||
1301 | |||
1302 | DBG("Try to map irq for %s...\n", pci_name(pci_dev)); | ||
1303 | |||
1304 | #ifdef DEBUG | ||
1305 | memset(&oirq, 0xff, sizeof(oirq)); | ||
1306 | #endif | ||
1307 | /* Try to get a mapping from the device-tree */ | ||
1308 | if (of_irq_map_pci(pci_dev, &oirq)) { | ||
1309 | u8 line, pin; | ||
1310 | |||
1311 | /* If that fails, lets fallback to what is in the config | ||
1312 | * space and map that through the default controller. We | ||
1313 | * also set the type to level low since that's what PCI | ||
1314 | * interrupts are. If your platform does differently, then | ||
1315 | * either provide a proper interrupt tree or don't use this | ||
1316 | * function. | ||
1317 | */ | ||
1318 | if (pci_read_config_byte(pci_dev, PCI_INTERRUPT_PIN, &pin)) | ||
1319 | return -1; | ||
1320 | if (pin == 0) | ||
1321 | return -1; | ||
1322 | if (pci_read_config_byte(pci_dev, PCI_INTERRUPT_LINE, &line) || | ||
1323 | line == 0xff) { | ||
1324 | return -1; | ||
1325 | } | ||
1326 | DBG(" -> no map ! Using irq line %d from PCI config\n", line); | ||
1327 | |||
1328 | virq = irq_create_mapping(NULL, line); | ||
1329 | if (virq != NO_IRQ) | ||
1330 | set_irq_type(virq, IRQ_TYPE_LEVEL_LOW); | ||
1331 | } else { | ||
1332 | DBG(" -> got one, spec %d cells (0x%08x 0x%08x...) on %s\n", | ||
1333 | oirq.size, oirq.specifier[0], oirq.specifier[1], | ||
1334 | oirq.controller->full_name); | ||
1335 | |||
1336 | virq = irq_create_of_mapping(oirq.controller, oirq.specifier, | ||
1337 | oirq.size); | ||
1338 | } | ||
1339 | if(virq == NO_IRQ) { | ||
1340 | DBG(" -> failed to map !\n"); | ||
1341 | return -1; | ||
1342 | } | ||
1343 | |||
1344 | DBG(" -> mapped to linux irq %d\n", virq); | ||
1345 | |||
1346 | pci_dev->irq = virq; | ||
1347 | |||
1348 | return 0; | ||
1349 | } | ||
1350 | EXPORT_SYMBOL(pci_read_irq_line); | ||
1351 | |||
1352 | void pci_resource_to_user(const struct pci_dev *dev, int bar, | ||
1353 | const struct resource *rsrc, | ||
1354 | resource_size_t *start, resource_size_t *end) | ||
1355 | { | ||
1356 | struct pci_controller *hose = pci_bus_to_host(dev->bus); | ||
1357 | resource_size_t offset = 0; | ||
1358 | |||
1359 | if (hose == NULL) | ||
1360 | return; | ||
1361 | |||
1362 | if (rsrc->flags & IORESOURCE_IO) | ||
1363 | offset = (unsigned long)hose->io_base_virt - pci_io_base; | ||
1364 | |||
1365 | /* We pass a fully fixed up address to userland for MMIO instead of | ||
1366 | * a BAR value because X is lame and expects to be able to use that | ||
1367 | * to pass to /dev/mem ! | ||
1368 | * | ||
1369 | * That means that we'll have potentially 64 bits values where some | ||
1370 | * userland apps only expect 32 (like X itself since it thinks only | ||
1371 | * Sparc has 64 bits MMIO) but if we don't do that, we break it on | ||
1372 | * 32 bits CHRPs :-( | ||
1373 | * | ||
1374 | * Hopefully, the sysfs insterface is immune to that gunk. Once X | ||
1375 | * has been fixed (and the fix spread enough), we can re-enable the | ||
1376 | * 2 lines below and pass down a BAR value to userland. In that case | ||
1377 | * we'll also have to re-enable the matching code in | ||
1378 | * __pci_mmap_make_offset(). | ||
1379 | * | ||
1380 | * BenH. | ||
1381 | */ | ||
1382 | #if 0 | ||
1383 | else if (rsrc->flags & IORESOURCE_MEM) | ||
1384 | offset = hose->pci_mem_offset; | ||
1385 | #endif | ||
1386 | |||
1387 | *start = rsrc->start - offset; | ||
1388 | *end = rsrc->end - offset; | ||
1389 | } | ||
1390 | |||
1391 | struct pci_controller* pci_find_hose_for_OF_device(struct device_node* node) | ||
1392 | { | ||
1393 | if (!have_of) | ||
1394 | return NULL; | ||
1395 | while(node) { | ||
1396 | struct pci_controller *hose, *tmp; | ||
1397 | list_for_each_entry_safe(hose, tmp, &hose_list, list_node) | ||
1398 | if (hose->arch_data == node) | ||
1399 | return hose; | ||
1400 | node = node->parent; | ||
1401 | } | ||
1402 | return NULL; | ||
1403 | } | ||
1404 | |||
1405 | unsigned long pci_address_to_pio(phys_addr_t address) | 907 | unsigned long pci_address_to_pio(phys_addr_t address) |
1406 | { | 908 | { |
1407 | struct pci_controller *hose, *tmp; | 909 | struct pci_controller *hose, *tmp; |
@@ -1410,7 +912,7 @@ unsigned long pci_address_to_pio(phys_addr_t address) | |||
1410 | if (address >= hose->io_base_phys && | 912 | if (address >= hose->io_base_phys && |
1411 | address < (hose->io_base_phys + hose->pci_io_size)) { | 913 | address < (hose->io_base_phys + hose->pci_io_size)) { |
1412 | unsigned long base = | 914 | unsigned long base = |
1413 | (unsigned long)hose->io_base_virt - pci_io_base; | 915 | (unsigned long)hose->io_base_virt - _IO_BASE; |
1414 | return base + (address - hose->io_base_phys); | 916 | return base + (address - hose->io_base_phys); |
1415 | } | 917 | } |
1416 | } | 918 | } |