diff options
-rw-r--r-- | arch/powerpc/kernel/pci-common.c | 292 | ||||
-rw-r--r-- | arch/powerpc/kernel/pci_32.c | 246 | ||||
-rw-r--r-- | arch/powerpc/kernel/pci_64.c | 118 | ||||
-rw-r--r-- | arch/powerpc/platforms/powermac/pci.c | 3 | ||||
-rw-r--r-- | include/asm-powerpc/pci.h | 8 |
5 files changed, 311 insertions, 356 deletions
diff --git a/arch/powerpc/kernel/pci-common.c b/arch/powerpc/kernel/pci-common.c index c61e9324f770..d804c8d0be00 100644 --- a/arch/powerpc/kernel/pci-common.c +++ b/arch/powerpc/kernel/pci-common.c | |||
@@ -53,6 +53,8 @@ static int global_phb_number; /* Global phb counter */ | |||
53 | /* ISA Memory physical address */ | 53 | /* ISA Memory physical address */ |
54 | resource_size_t isa_mem_base; | 54 | resource_size_t isa_mem_base; |
55 | 55 | ||
56 | /* Default PCI flags is 0 */ | ||
57 | unsigned int ppc_pci_flags; | ||
56 | 58 | ||
57 | struct pci_controller *pcibios_alloc_controller(struct device_node *dev) | 59 | struct pci_controller *pcibios_alloc_controller(struct device_node *dev) |
58 | { | 60 | { |
@@ -821,3 +823,293 @@ void __devinit pcibios_fixup_of_probed_bus(struct pci_bus *bus) | |||
821 | { | 823 | { |
822 | __pcibios_fixup_bus(bus); | 824 | __pcibios_fixup_bus(bus); |
823 | } | 825 | } |
826 | |||
827 | static int skip_isa_ioresource_align(struct pci_dev *dev) | ||
828 | { | ||
829 | if ((ppc_pci_flags & PPC_PCI_CAN_SKIP_ISA_ALIGN) && | ||
830 | !(dev->bus->bridge_ctl & PCI_BRIDGE_CTL_ISA)) | ||
831 | return 1; | ||
832 | return 0; | ||
833 | } | ||
834 | |||
835 | /* | ||
836 | * We need to avoid collisions with `mirrored' VGA ports | ||
837 | * and other strange ISA hardware, so we always want the | ||
838 | * addresses to be allocated in the 0x000-0x0ff region | ||
839 | * modulo 0x400. | ||
840 | * | ||
841 | * Why? Because some silly external IO cards only decode | ||
842 | * the low 10 bits of the IO address. The 0x00-0xff region | ||
843 | * is reserved for motherboard devices that decode all 16 | ||
844 | * bits, so it's ok to allocate at, say, 0x2800-0x28ff, | ||
845 | * but we want to try to avoid allocating at 0x2900-0x2bff | ||
846 | * which might have be mirrored at 0x0100-0x03ff.. | ||
847 | */ | ||
848 | void pcibios_align_resource(void *data, struct resource *res, | ||
849 | resource_size_t size, resource_size_t align) | ||
850 | { | ||
851 | struct pci_dev *dev = data; | ||
852 | |||
853 | if (res->flags & IORESOURCE_IO) { | ||
854 | resource_size_t start = res->start; | ||
855 | |||
856 | if (skip_isa_ioresource_align(dev)) | ||
857 | return; | ||
858 | if (start & 0x300) { | ||
859 | start = (start + 0x3ff) & ~0x3ff; | ||
860 | res->start = start; | ||
861 | } | ||
862 | } | ||
863 | } | ||
864 | EXPORT_SYMBOL(pcibios_align_resource); | ||
865 | |||
866 | /* | ||
867 | * Reparent resource children of pr that conflict with res | ||
868 | * under res, and make res replace those children. | ||
869 | */ | ||
870 | static int __init reparent_resources(struct resource *parent, | ||
871 | struct resource *res) | ||
872 | { | ||
873 | struct resource *p, **pp; | ||
874 | struct resource **firstpp = NULL; | ||
875 | |||
876 | for (pp = &parent->child; (p = *pp) != NULL; pp = &p->sibling) { | ||
877 | if (p->end < res->start) | ||
878 | continue; | ||
879 | if (res->end < p->start) | ||
880 | break; | ||
881 | if (p->start < res->start || p->end > res->end) | ||
882 | return -1; /* not completely contained */ | ||
883 | if (firstpp == NULL) | ||
884 | firstpp = pp; | ||
885 | } | ||
886 | if (firstpp == NULL) | ||
887 | return -1; /* didn't find any conflicting entries? */ | ||
888 | res->parent = parent; | ||
889 | res->child = *firstpp; | ||
890 | res->sibling = *pp; | ||
891 | *firstpp = res; | ||
892 | *pp = NULL; | ||
893 | for (p = res->child; p != NULL; p = p->sibling) { | ||
894 | p->parent = res; | ||
895 | DBG(KERN_INFO "PCI: reparented %s [%llx..%llx] under %s\n", | ||
896 | p->name, | ||
897 | (unsigned long long)p->start, | ||
898 | (unsigned long long)p->end, res->name); | ||
899 | } | ||
900 | return 0; | ||
901 | } | ||
902 | |||
903 | /* | ||
904 | * Handle resources of PCI devices. If the world were perfect, we could | ||
905 | * just allocate all the resource regions and do nothing more. It isn't. | ||
906 | * On the other hand, we cannot just re-allocate all devices, as it would | ||
907 | * require us to know lots of host bridge internals. So we attempt to | ||
908 | * keep as much of the original configuration as possible, but tweak it | ||
909 | * when it's found to be wrong. | ||
910 | * | ||
911 | * Known BIOS problems we have to work around: | ||
912 | * - I/O or memory regions not configured | ||
913 | * - regions configured, but not enabled in the command register | ||
914 | * - bogus I/O addresses above 64K used | ||
915 | * - expansion ROMs left enabled (this may sound harmless, but given | ||
916 | * the fact the PCI specs explicitly allow address decoders to be | ||
917 | * shared between expansion ROMs and other resource regions, it's | ||
918 | * at least dangerous) | ||
919 | * | ||
920 | * Our solution: | ||
921 | * (1) Allocate resources for all buses behind PCI-to-PCI bridges. | ||
922 | * This gives us fixed barriers on where we can allocate. | ||
923 | * (2) Allocate resources for all enabled devices. If there is | ||
924 | * a collision, just mark the resource as unallocated. Also | ||
925 | * disable expansion ROMs during this step. | ||
926 | * (3) Try to allocate resources for disabled devices. If the | ||
927 | * resources were assigned correctly, everything goes well, | ||
928 | * if they weren't, they won't disturb allocation of other | ||
929 | * resources. | ||
930 | * (4) Assign new addresses to resources which were either | ||
931 | * not configured at all or misconfigured. If explicitly | ||
932 | * requested by the user, configure expansion ROM address | ||
933 | * as well. | ||
934 | */ | ||
935 | |||
936 | static void __init pcibios_allocate_bus_resources(struct list_head *bus_list) | ||
937 | { | ||
938 | struct pci_bus *bus; | ||
939 | int i; | ||
940 | struct resource *res, *pr; | ||
941 | |||
942 | /* Depth-First Search on bus tree */ | ||
943 | list_for_each_entry(bus, bus_list, node) { | ||
944 | for (i = 0; i < PCI_BUS_NUM_RESOURCES; ++i) { | ||
945 | if ((res = bus->resource[i]) == NULL || !res->flags | ||
946 | || res->start > res->end) | ||
947 | continue; | ||
948 | if (bus->parent == NULL) | ||
949 | pr = (res->flags & IORESOURCE_IO)? | ||
950 | &ioport_resource : &iomem_resource; | ||
951 | else { | ||
952 | /* Don't bother with non-root busses when | ||
953 | * re-assigning all resources. We clear the | ||
954 | * resource flags as if they were colliding | ||
955 | * and as such ensure proper re-allocation | ||
956 | * later. | ||
957 | */ | ||
958 | if (ppc_pci_flags & PPC_PCI_REASSIGN_ALL_RSRC) | ||
959 | goto clear_resource; | ||
960 | pr = pci_find_parent_resource(bus->self, res); | ||
961 | if (pr == res) { | ||
962 | /* this happens when the generic PCI | ||
963 | * code (wrongly) decides that this | ||
964 | * bridge is transparent -- paulus | ||
965 | */ | ||
966 | continue; | ||
967 | } | ||
968 | } | ||
969 | |||
970 | DBG("PCI: %s (bus %d) bridge rsrc %d: %016llx-%016llx " | ||
971 | "[0x%x], parent %p (%s)\n", | ||
972 | bus->self ? pci_name(bus->self) : "PHB", | ||
973 | bus->number, i, | ||
974 | (unsigned long long)res->start, | ||
975 | (unsigned long long)res->end, | ||
976 | (unsigned int)res->flags, | ||
977 | pr, (pr && pr->name) ? pr->name : "nil"); | ||
978 | |||
979 | if (pr && !(pr->flags & IORESOURCE_UNSET)) { | ||
980 | if (request_resource(pr, res) == 0) | ||
981 | continue; | ||
982 | /* | ||
983 | * Must be a conflict with an existing entry. | ||
984 | * Move that entry (or entries) under the | ||
985 | * bridge resource and try again. | ||
986 | */ | ||
987 | if (reparent_resources(pr, res) == 0) | ||
988 | continue; | ||
989 | } | ||
990 | printk(KERN_WARNING | ||
991 | "PCI: Cannot allocate resource region " | ||
992 | "%d of PCI bridge %d, will remap\n", | ||
993 | i, bus->number); | ||
994 | clear_resource: | ||
995 | res->flags = 0; | ||
996 | } | ||
997 | pcibios_allocate_bus_resources(&bus->children); | ||
998 | } | ||
999 | } | ||
1000 | |||
1001 | static inline void __devinit alloc_resource(struct pci_dev *dev, int idx) | ||
1002 | { | ||
1003 | struct resource *pr, *r = &dev->resource[idx]; | ||
1004 | |||
1005 | DBG("PCI: Allocating %s: Resource %d: %016llx..%016llx [%x]\n", | ||
1006 | pci_name(dev), idx, | ||
1007 | (unsigned long long)r->start, | ||
1008 | (unsigned long long)r->end, | ||
1009 | (unsigned int)r->flags); | ||
1010 | |||
1011 | pr = pci_find_parent_resource(dev, r); | ||
1012 | if (!pr || (pr->flags & IORESOURCE_UNSET) || | ||
1013 | request_resource(pr, r) < 0) { | ||
1014 | printk(KERN_WARNING "PCI: Cannot allocate resource region %d" | ||
1015 | " of device %s, will remap\n", idx, pci_name(dev)); | ||
1016 | if (pr) | ||
1017 | DBG("PCI: parent is %p: %016llx-%016llx [%x]\n", pr, | ||
1018 | (unsigned long long)pr->start, | ||
1019 | (unsigned long long)pr->end, | ||
1020 | (unsigned int)pr->flags); | ||
1021 | /* We'll assign a new address later */ | ||
1022 | r->flags |= IORESOURCE_UNSET; | ||
1023 | r->end -= r->start; | ||
1024 | r->start = 0; | ||
1025 | } | ||
1026 | } | ||
1027 | |||
1028 | static void __init pcibios_allocate_resources(int pass) | ||
1029 | { | ||
1030 | struct pci_dev *dev = NULL; | ||
1031 | int idx, disabled; | ||
1032 | u16 command; | ||
1033 | struct resource *r; | ||
1034 | |||
1035 | for_each_pci_dev(dev) { | ||
1036 | pci_read_config_word(dev, PCI_COMMAND, &command); | ||
1037 | for (idx = 0; idx < 6; idx++) { | ||
1038 | r = &dev->resource[idx]; | ||
1039 | if (r->parent) /* Already allocated */ | ||
1040 | continue; | ||
1041 | if (!r->flags || (r->flags & IORESOURCE_UNSET)) | ||
1042 | continue; /* Not assigned at all */ | ||
1043 | if (r->flags & IORESOURCE_IO) | ||
1044 | disabled = !(command & PCI_COMMAND_IO); | ||
1045 | else | ||
1046 | disabled = !(command & PCI_COMMAND_MEMORY); | ||
1047 | if (pass == disabled) | ||
1048 | alloc_resource(dev, idx); | ||
1049 | } | ||
1050 | if (pass) | ||
1051 | continue; | ||
1052 | r = &dev->resource[PCI_ROM_RESOURCE]; | ||
1053 | if (r->flags & IORESOURCE_ROM_ENABLE) { | ||
1054 | /* Turn the ROM off, leave the resource region, | ||
1055 | * but keep it unregistered. | ||
1056 | */ | ||
1057 | u32 reg; | ||
1058 | DBG("PCI: Switching off ROM of %s\n", pci_name(dev)); | ||
1059 | r->flags &= ~IORESOURCE_ROM_ENABLE; | ||
1060 | pci_read_config_dword(dev, dev->rom_base_reg, ®); | ||
1061 | pci_write_config_dword(dev, dev->rom_base_reg, | ||
1062 | reg & ~PCI_ROM_ADDRESS_ENABLE); | ||
1063 | } | ||
1064 | } | ||
1065 | } | ||
1066 | |||
1067 | void __init pcibios_resource_survey(void) | ||
1068 | { | ||
1069 | /* Allocate and assign resources. If we re-assign everything, then | ||
1070 | * we skip the allocate phase | ||
1071 | */ | ||
1072 | pcibios_allocate_bus_resources(&pci_root_buses); | ||
1073 | |||
1074 | if (!(ppc_pci_flags & PPC_PCI_REASSIGN_ALL_RSRC)) { | ||
1075 | pcibios_allocate_resources(0); | ||
1076 | pcibios_allocate_resources(1); | ||
1077 | } | ||
1078 | |||
1079 | if (!(ppc_pci_flags & PPC_PCI_PROBE_ONLY)) { | ||
1080 | DBG("PCI: Assigning unassigned resouces...\n"); | ||
1081 | pci_assign_unassigned_resources(); | ||
1082 | } | ||
1083 | |||
1084 | /* Call machine dependent fixup */ | ||
1085 | if (ppc_md.pcibios_fixup) | ||
1086 | ppc_md.pcibios_fixup(); | ||
1087 | } | ||
1088 | |||
1089 | #ifdef CONFIG_HOTPLUG | ||
1090 | /* This is used by the pSeries hotplug driver to allocate resource | ||
1091 | * of newly plugged busses. We can try to consolidate with the | ||
1092 | * rest of the code later, for now, keep it as-is | ||
1093 | */ | ||
1094 | void __devinit pcibios_claim_one_bus(struct pci_bus *bus) | ||
1095 | { | ||
1096 | struct pci_dev *dev; | ||
1097 | struct pci_bus *child_bus; | ||
1098 | |||
1099 | list_for_each_entry(dev, &bus->devices, bus_list) { | ||
1100 | int i; | ||
1101 | |||
1102 | for (i = 0; i < PCI_NUM_RESOURCES; i++) { | ||
1103 | struct resource *r = &dev->resource[i]; | ||
1104 | |||
1105 | if (r->parent || !r->start || !r->flags) | ||
1106 | continue; | ||
1107 | pci_claim_resource(dev, i); | ||
1108 | } | ||
1109 | } | ||
1110 | |||
1111 | list_for_each_entry(child_bus, &bus->children, node) | ||
1112 | pcibios_claim_one_bus(child_bus); | ||
1113 | } | ||
1114 | EXPORT_SYMBOL_GPL(pcibios_claim_one_bus); | ||
1115 | #endif /* CONFIG_HOTPLUG */ | ||
diff --git a/arch/powerpc/kernel/pci_32.c b/arch/powerpc/kernel/pci_32.c index 717c554d4658..ce7c20c8191f 100644 --- a/arch/powerpc/kernel/pci_32.c +++ b/arch/powerpc/kernel/pci_32.c | |||
@@ -35,13 +35,9 @@ unsigned long isa_io_base = 0; | |||
35 | unsigned long pci_dram_offset = 0; | 35 | unsigned long pci_dram_offset = 0; |
36 | int pcibios_assign_bus_offset = 1; | 36 | int pcibios_assign_bus_offset = 1; |
37 | 37 | ||
38 | /* Default PCI flags is 0 */ | ||
39 | unsigned int ppc_pci_flags; | ||
40 | |||
41 | void pcibios_make_OF_bus_map(void); | 38 | void pcibios_make_OF_bus_map(void); |
42 | 39 | ||
43 | static void fixup_broken_pcnet32(struct pci_dev* dev); | 40 | static void fixup_broken_pcnet32(struct pci_dev* dev); |
44 | static int reparent_resources(struct resource *parent, struct resource *res); | ||
45 | static void fixup_cpc710_pci64(struct pci_dev* dev); | 41 | static void fixup_cpc710_pci64(struct pci_dev* dev); |
46 | #ifdef CONFIG_PPC_OF | 42 | #ifdef CONFIG_PPC_OF |
47 | static u8* pci_to_OF_bus_map; | 43 | static u8* pci_to_OF_bus_map; |
@@ -97,170 +93,6 @@ fixup_cpc710_pci64(struct pci_dev* dev) | |||
97 | } | 93 | } |
98 | DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CPC710_PCI64, fixup_cpc710_pci64); | 94 | DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CPC710_PCI64, fixup_cpc710_pci64); |
99 | 95 | ||
100 | static int skip_isa_ioresource_align(struct pci_dev *dev) | ||
101 | { | ||
102 | if ((ppc_pci_flags & PPC_PCI_CAN_SKIP_ISA_ALIGN) && | ||
103 | !(dev->bus->bridge_ctl & PCI_BRIDGE_CTL_ISA)) | ||
104 | return 1; | ||
105 | return 0; | ||
106 | } | ||
107 | |||
108 | /* | ||
109 | * We need to avoid collisions with `mirrored' VGA ports | ||
110 | * and other strange ISA hardware, so we always want the | ||
111 | * addresses to be allocated in the 0x000-0x0ff region | ||
112 | * modulo 0x400. | ||
113 | * | ||
114 | * Why? Because some silly external IO cards only decode | ||
115 | * the low 10 bits of the IO address. The 0x00-0xff region | ||
116 | * is reserved for motherboard devices that decode all 16 | ||
117 | * bits, so it's ok to allocate at, say, 0x2800-0x28ff, | ||
118 | * but we want to try to avoid allocating at 0x2900-0x2bff | ||
119 | * which might have be mirrored at 0x0100-0x03ff.. | ||
120 | */ | ||
121 | void pcibios_align_resource(void *data, struct resource *res, | ||
122 | resource_size_t size, resource_size_t align) | ||
123 | { | ||
124 | struct pci_dev *dev = data; | ||
125 | |||
126 | if (res->flags & IORESOURCE_IO) { | ||
127 | resource_size_t start = res->start; | ||
128 | |||
129 | if (skip_isa_ioresource_align(dev)) | ||
130 | return; | ||
131 | if (start & 0x300) { | ||
132 | start = (start + 0x3ff) & ~0x3ff; | ||
133 | res->start = start; | ||
134 | } | ||
135 | } | ||
136 | } | ||
137 | EXPORT_SYMBOL(pcibios_align_resource); | ||
138 | |||
139 | /* | ||
140 | * Handle resources of PCI devices. If the world were perfect, we could | ||
141 | * just allocate all the resource regions and do nothing more. It isn't. | ||
142 | * On the other hand, we cannot just re-allocate all devices, as it would | ||
143 | * require us to know lots of host bridge internals. So we attempt to | ||
144 | * keep as much of the original configuration as possible, but tweak it | ||
145 | * when it's found to be wrong. | ||
146 | * | ||
147 | * Known BIOS problems we have to work around: | ||
148 | * - I/O or memory regions not configured | ||
149 | * - regions configured, but not enabled in the command register | ||
150 | * - bogus I/O addresses above 64K used | ||
151 | * - expansion ROMs left enabled (this may sound harmless, but given | ||
152 | * the fact the PCI specs explicitly allow address decoders to be | ||
153 | * shared between expansion ROMs and other resource regions, it's | ||
154 | * at least dangerous) | ||
155 | * | ||
156 | * Our solution: | ||
157 | * (1) Allocate resources for all buses behind PCI-to-PCI bridges. | ||
158 | * This gives us fixed barriers on where we can allocate. | ||
159 | * (2) Allocate resources for all enabled devices. If there is | ||
160 | * a collision, just mark the resource as unallocated. Also | ||
161 | * disable expansion ROMs during this step. | ||
162 | * (3) Try to allocate resources for disabled devices. If the | ||
163 | * resources were assigned correctly, everything goes well, | ||
164 | * if they weren't, they won't disturb allocation of other | ||
165 | * resources. | ||
166 | * (4) Assign new addresses to resources which were either | ||
167 | * not configured at all or misconfigured. If explicitly | ||
168 | * requested by the user, configure expansion ROM address | ||
169 | * as well. | ||
170 | */ | ||
171 | |||
172 | static void __init | ||
173 | pcibios_allocate_bus_resources(struct list_head *bus_list) | ||
174 | { | ||
175 | struct pci_bus *bus; | ||
176 | int i; | ||
177 | struct resource *res, *pr; | ||
178 | |||
179 | /* Depth-First Search on bus tree */ | ||
180 | list_for_each_entry(bus, bus_list, node) { | ||
181 | for (i = 0; i < 4; ++i) { | ||
182 | if ((res = bus->resource[i]) == NULL || !res->flags | ||
183 | || res->start > res->end) | ||
184 | continue; | ||
185 | if (bus->parent == NULL) | ||
186 | pr = (res->flags & IORESOURCE_IO)? | ||
187 | &ioport_resource : &iomem_resource; | ||
188 | else { | ||
189 | /* Don't bother with non-root busses when | ||
190 | * re-assigning all resources. | ||
191 | */ | ||
192 | if (ppc_pci_flags & PPC_PCI_REASSIGN_ALL_RSRC) | ||
193 | continue; | ||
194 | pr = pci_find_parent_resource(bus->self, res); | ||
195 | if (pr == res) { | ||
196 | /* this happens when the generic PCI | ||
197 | * code (wrongly) decides that this | ||
198 | * bridge is transparent -- paulus | ||
199 | */ | ||
200 | continue; | ||
201 | } | ||
202 | } | ||
203 | |||
204 | DBG("PCI: dev %s (bus 0x%02x) bridge rsrc %d: %016llx..%016llx " | ||
205 | "(f:0x%08lx), parent %p\n", | ||
206 | bus->self ? pci_name(bus->self) : "PHB", bus->number, i, | ||
207 | (u64)res->start, (u64)res->end, res->flags, pr); | ||
208 | |||
209 | if (pr && !(pr->flags & IORESOURCE_UNSET)) { | ||
210 | if (request_resource(pr, res) == 0) | ||
211 | continue; | ||
212 | /* | ||
213 | * Must be a conflict with an existing entry. | ||
214 | * Move that entry (or entries) under the | ||
215 | * bridge resource and try again. | ||
216 | */ | ||
217 | if (reparent_resources(pr, res) == 0) | ||
218 | continue; | ||
219 | } | ||
220 | printk(KERN_WARNING | ||
221 | "PCI: Cannot allocate resource region " | ||
222 | "%d of PCI bridge %d, will remap\n", | ||
223 | i, bus->number); | ||
224 | res->flags |= IORESOURCE_UNSET; | ||
225 | } | ||
226 | pcibios_allocate_bus_resources(&bus->children); | ||
227 | } | ||
228 | } | ||
229 | |||
230 | /* | ||
231 | * Reparent resource children of pr that conflict with res | ||
232 | * under res, and make res replace those children. | ||
233 | */ | ||
234 | static int __init | ||
235 | reparent_resources(struct resource *parent, struct resource *res) | ||
236 | { | ||
237 | struct resource *p, **pp; | ||
238 | struct resource **firstpp = NULL; | ||
239 | |||
240 | for (pp = &parent->child; (p = *pp) != NULL; pp = &p->sibling) { | ||
241 | if (p->end < res->start) | ||
242 | continue; | ||
243 | if (res->end < p->start) | ||
244 | break; | ||
245 | if (p->start < res->start || p->end > res->end) | ||
246 | return -1; /* not completely contained */ | ||
247 | if (firstpp == NULL) | ||
248 | firstpp = pp; | ||
249 | } | ||
250 | if (firstpp == NULL) | ||
251 | return -1; /* didn't find any conflicting entries? */ | ||
252 | res->parent = parent; | ||
253 | res->child = *firstpp; | ||
254 | res->sibling = *pp; | ||
255 | *firstpp = res; | ||
256 | *pp = NULL; | ||
257 | for (p = res->child; p != NULL; p = p->sibling) { | ||
258 | p->parent = res; | ||
259 | DBG(KERN_INFO "PCI: reparented %s [%llx..%llx] under %s\n", | ||
260 | p->name, (u64)p->start, (u64)p->end, res->name); | ||
261 | } | ||
262 | return 0; | ||
263 | } | ||
264 | 96 | ||
265 | void __init | 97 | void __init |
266 | update_bridge_resource(struct pci_dev *dev, struct resource *res) | 98 | update_bridge_resource(struct pci_dev *dev, struct resource *res) |
@@ -318,63 +150,6 @@ update_bridge_resource(struct pci_dev *dev, struct resource *res) | |||
318 | pci_write_config_word(dev, PCI_COMMAND, cmd); | 150 | pci_write_config_word(dev, PCI_COMMAND, cmd); |
319 | } | 151 | } |
320 | 152 | ||
321 | static inline void alloc_resource(struct pci_dev *dev, int idx) | ||
322 | { | ||
323 | struct resource *pr, *r = &dev->resource[idx]; | ||
324 | |||
325 | DBG("PCI: Allocating %s: Resource %d: %016llx..%016llx (f=%lx)\n", | ||
326 | pci_name(dev), idx, (u64)r->start, (u64)r->end, r->flags); | ||
327 | pr = pci_find_parent_resource(dev, r); | ||
328 | if (!pr || (pr->flags & IORESOURCE_UNSET) || request_resource(pr, r) < 0) { | ||
329 | printk(KERN_WARNING "PCI: Cannot allocate resource region %d" | ||
330 | " of device %s, will remap\n", idx, pci_name(dev)); | ||
331 | if (pr) | ||
332 | DBG("PCI: parent is %p: %016llx-%016llx (f=%lx)\n", | ||
333 | pr, (u64)pr->start, (u64)pr->end, pr->flags); | ||
334 | /* We'll assign a new address later */ | ||
335 | r->flags |= IORESOURCE_UNSET; | ||
336 | r->end -= r->start; | ||
337 | r->start = 0; | ||
338 | } | ||
339 | } | ||
340 | |||
341 | static void __init | ||
342 | pcibios_allocate_resources(int pass) | ||
343 | { | ||
344 | struct pci_dev *dev = NULL; | ||
345 | int idx, disabled; | ||
346 | u16 command; | ||
347 | struct resource *r; | ||
348 | |||
349 | for_each_pci_dev(dev) { | ||
350 | pci_read_config_word(dev, PCI_COMMAND, &command); | ||
351 | for (idx = 0; idx < 6; idx++) { | ||
352 | r = &dev->resource[idx]; | ||
353 | if (r->parent) /* Already allocated */ | ||
354 | continue; | ||
355 | if (!r->flags || (r->flags & IORESOURCE_UNSET)) | ||
356 | continue; /* Not assigned at all */ | ||
357 | if (r->flags & IORESOURCE_IO) | ||
358 | disabled = !(command & PCI_COMMAND_IO); | ||
359 | else | ||
360 | disabled = !(command & PCI_COMMAND_MEMORY); | ||
361 | if (pass == disabled) | ||
362 | alloc_resource(dev, idx); | ||
363 | } | ||
364 | if (pass) | ||
365 | continue; | ||
366 | r = &dev->resource[PCI_ROM_RESOURCE]; | ||
367 | if (r->flags & IORESOURCE_ROM_ENABLE) { | ||
368 | /* Turn the ROM off, leave the resource region, but keep it unregistered. */ | ||
369 | u32 reg; | ||
370 | DBG("PCI: Switching off ROM of %s\n", pci_name(dev)); | ||
371 | r->flags &= ~IORESOURCE_ROM_ENABLE; | ||
372 | pci_read_config_dword(dev, dev->rom_base_reg, ®); | ||
373 | pci_write_config_dword(dev, dev->rom_base_reg, | ||
374 | reg & ~PCI_ROM_ADDRESS_ENABLE); | ||
375 | } | ||
376 | } | ||
377 | } | ||
378 | 153 | ||
379 | #ifdef CONFIG_PPC_OF | 154 | #ifdef CONFIG_PPC_OF |
380 | /* | 155 | /* |
@@ -649,8 +424,7 @@ void pcibios_make_OF_bus_map(void) | |||
649 | } | 424 | } |
650 | #endif /* CONFIG_PPC_OF */ | 425 | #endif /* CONFIG_PPC_OF */ |
651 | 426 | ||
652 | static int __init | 427 | static int __init pcibios_init(void) |
653 | pcibios_init(void) | ||
654 | { | 428 | { |
655 | struct pci_controller *hose, *tmp; | 429 | struct pci_controller *hose, *tmp; |
656 | struct pci_bus *bus; | 430 | struct pci_bus *bus; |
@@ -683,22 +457,8 @@ pcibios_init(void) | |||
683 | if (pci_assign_all_buses && have_of) | 457 | if (pci_assign_all_buses && have_of) |
684 | pcibios_make_OF_bus_map(); | 458 | pcibios_make_OF_bus_map(); |
685 | 459 | ||
686 | /* Call machine dependent fixup */ | 460 | /* Call common code to handle resource allocation */ |
687 | if (ppc_md.pcibios_fixup) | 461 | pcibios_resource_survey(); |
688 | ppc_md.pcibios_fixup(); | ||
689 | |||
690 | /* Allocate and assign resources. If we re-assign everything, then | ||
691 | * we skip the allocate phase | ||
692 | */ | ||
693 | pcibios_allocate_bus_resources(&pci_root_buses); | ||
694 | if (!(ppc_pci_flags & PPC_PCI_REASSIGN_ALL_RSRC)) { | ||
695 | pcibios_allocate_resources(0); | ||
696 | pcibios_allocate_resources(1); | ||
697 | } | ||
698 | if (!(ppc_pci_flags & PPC_PCI_PROBE_ONLY)) { | ||
699 | DBG("PCI: Assigning unassigned resouces...\n"); | ||
700 | pci_assign_unassigned_resources(); | ||
701 | } | ||
702 | 462 | ||
703 | /* Call machine dependent post-init code */ | 463 | /* Call machine dependent post-init code */ |
704 | if (ppc_md.pcibios_after_init) | 464 | if (ppc_md.pcibios_after_init) |
diff --git a/arch/powerpc/kernel/pci_64.c b/arch/powerpc/kernel/pci_64.c index b9619b9e5e02..794359d8686b 100644 --- a/arch/powerpc/kernel/pci_64.c +++ b/arch/powerpc/kernel/pci_64.c | |||
@@ -91,85 +91,6 @@ static void fixup_broken_pcnet32(struct pci_dev* dev) | |||
91 | DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_TRIDENT, PCI_ANY_ID, fixup_broken_pcnet32); | 91 | DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_TRIDENT, PCI_ANY_ID, fixup_broken_pcnet32); |
92 | 92 | ||
93 | 93 | ||
94 | /* | ||
95 | * We need to avoid collisions with `mirrored' VGA ports | ||
96 | * and other strange ISA hardware, so we always want the | ||
97 | * addresses to be allocated in the 0x000-0x0ff region | ||
98 | * modulo 0x400. | ||
99 | * | ||
100 | * Why? Because some silly external IO cards only decode | ||
101 | * the low 10 bits of the IO address. The 0x00-0xff region | ||
102 | * is reserved for motherboard devices that decode all 16 | ||
103 | * bits, so it's ok to allocate at, say, 0x2800-0x28ff, | ||
104 | * but we want to try to avoid allocating at 0x2900-0x2bff | ||
105 | * which might have be mirrored at 0x0100-0x03ff.. | ||
106 | */ | ||
107 | void pcibios_align_resource(void *data, struct resource *res, | ||
108 | resource_size_t size, resource_size_t align) | ||
109 | { | ||
110 | struct pci_dev *dev = data; | ||
111 | struct pci_controller *hose = pci_bus_to_host(dev->bus); | ||
112 | resource_size_t start = res->start; | ||
113 | unsigned long alignto; | ||
114 | |||
115 | if (res->flags & IORESOURCE_IO) { | ||
116 | unsigned long offset = (unsigned long)hose->io_base_virt - | ||
117 | _IO_BASE; | ||
118 | /* Make sure we start at our min on all hoses */ | ||
119 | if (start - offset < PCIBIOS_MIN_IO) | ||
120 | start = PCIBIOS_MIN_IO + offset; | ||
121 | |||
122 | /* | ||
123 | * Put everything into 0x00-0xff region modulo 0x400 | ||
124 | */ | ||
125 | if (start & 0x300) | ||
126 | start = (start + 0x3ff) & ~0x3ff; | ||
127 | |||
128 | } else if (res->flags & IORESOURCE_MEM) { | ||
129 | /* Make sure we start at our min on all hoses */ | ||
130 | if (start - hose->pci_mem_offset < PCIBIOS_MIN_MEM) | ||
131 | start = PCIBIOS_MIN_MEM + hose->pci_mem_offset; | ||
132 | |||
133 | /* Align to multiple of size of minimum base. */ | ||
134 | alignto = max(0x1000UL, align); | ||
135 | start = ALIGN(start, alignto); | ||
136 | } | ||
137 | |||
138 | res->start = start; | ||
139 | } | ||
140 | |||
141 | void __devinit pcibios_claim_one_bus(struct pci_bus *b) | ||
142 | { | ||
143 | struct pci_dev *dev; | ||
144 | struct pci_bus *child_bus; | ||
145 | |||
146 | list_for_each_entry(dev, &b->devices, bus_list) { | ||
147 | int i; | ||
148 | |||
149 | for (i = 0; i < PCI_NUM_RESOURCES; i++) { | ||
150 | struct resource *r = &dev->resource[i]; | ||
151 | |||
152 | if (r->parent || !r->start || !r->flags) | ||
153 | continue; | ||
154 | pci_claim_resource(dev, i); | ||
155 | } | ||
156 | } | ||
157 | |||
158 | list_for_each_entry(child_bus, &b->children, node) | ||
159 | pcibios_claim_one_bus(child_bus); | ||
160 | } | ||
161 | #ifdef CONFIG_HOTPLUG | ||
162 | EXPORT_SYMBOL_GPL(pcibios_claim_one_bus); | ||
163 | #endif | ||
164 | |||
165 | static void __init pcibios_claim_of_setup(void) | ||
166 | { | ||
167 | struct pci_bus *b; | ||
168 | |||
169 | list_for_each_entry(b, &pci_root_buses, node) | ||
170 | pcibios_claim_one_bus(b); | ||
171 | } | ||
172 | |||
173 | static u32 get_int_prop(struct device_node *np, const char *name, u32 def) | 94 | static u32 get_int_prop(struct device_node *np, const char *name, u32 def) |
174 | { | 95 | { |
175 | const u32 *prop; | 96 | const u32 *prop; |
@@ -440,6 +361,7 @@ void __devinit scan_phb(struct pci_controller *hose) | |||
440 | 361 | ||
441 | DBG("Scanning PHB %s\n", node ? node->full_name : "<NO NAME>"); | 362 | DBG("Scanning PHB %s\n", node ? node->full_name : "<NO NAME>"); |
442 | 363 | ||
364 | /* Create an empty bus for the toplevel */ | ||
443 | bus = pci_create_bus(hose->parent, hose->first_busno, hose->ops, node); | 365 | bus = pci_create_bus(hose->parent, hose->first_busno, hose->ops, node); |
444 | if (bus == NULL) { | 366 | if (bus == NULL) { |
445 | printk(KERN_ERR "Failed to create bus for PCI domain %04x\n", | 367 | printk(KERN_ERR "Failed to create bus for PCI domain %04x\n", |
@@ -449,26 +371,16 @@ void __devinit scan_phb(struct pci_controller *hose) | |||
449 | bus->secondary = hose->first_busno; | 371 | bus->secondary = hose->first_busno; |
450 | hose->bus = bus; | 372 | hose->bus = bus; |
451 | 373 | ||
374 | /* Get some IO space for the new PHB */ | ||
452 | pcibios_map_io_space(bus); | 375 | pcibios_map_io_space(bus); |
453 | 376 | ||
377 | /* Wire up PHB bus resources */ | ||
454 | bus->resource[0] = res = &hose->io_resource; | 378 | bus->resource[0] = res = &hose->io_resource; |
455 | if (res->flags && request_resource(&ioport_resource, res)) { | 379 | for (i = 0; i < 3; ++i) |
456 | printk(KERN_ERR "Failed to request PCI IO region " | 380 | bus->resource[i+1] = &hose->mem_resources[i]; |
457 | "on PCI domain %04x\n", hose->global_number); | ||
458 | DBG("res->start = 0x%016lx, res->end = 0x%016lx\n", | ||
459 | res->start, res->end); | ||
460 | } | ||
461 | |||
462 | for (i = 0; i < 3; ++i) { | ||
463 | res = &hose->mem_resources[i]; | ||
464 | bus->resource[i+1] = res; | ||
465 | if (res->flags && request_resource(&iomem_resource, res)) | ||
466 | printk(KERN_ERR "Failed to request PCI memory region " | ||
467 | "on PCI domain %04x\n", hose->global_number); | ||
468 | } | ||
469 | 381 | ||
382 | /* Get probe mode and perform scan */ | ||
470 | mode = PCI_PROBE_NORMAL; | 383 | mode = PCI_PROBE_NORMAL; |
471 | |||
472 | if (node && ppc_md.pci_probe_mode) | 384 | if (node && ppc_md.pci_probe_mode) |
473 | mode = ppc_md.pci_probe_mode(bus); | 385 | mode = ppc_md.pci_probe_mode(bus); |
474 | DBG(" probe mode: %d\n", mode); | 386 | DBG(" probe mode: %d\n", mode); |
@@ -485,12 +397,15 @@ static int __init pcibios_init(void) | |||
485 | { | 397 | { |
486 | struct pci_controller *hose, *tmp; | 398 | struct pci_controller *hose, *tmp; |
487 | 399 | ||
400 | printk(KERN_INFO "PCI: Probing PCI hardware\n"); | ||
401 | |||
488 | /* For now, override phys_mem_access_prot. If we need it, | 402 | /* For now, override phys_mem_access_prot. If we need it, |
489 | * later, we may move that initialization to each ppc_md | 403 | * later, we may move that initialization to each ppc_md |
490 | */ | 404 | */ |
491 | ppc_md.phys_mem_access_prot = pci_phys_mem_access_prot; | 405 | ppc_md.phys_mem_access_prot = pci_phys_mem_access_prot; |
492 | 406 | ||
493 | printk(KERN_DEBUG "PCI: Probing PCI hardware\n"); | 407 | if (pci_probe_only) |
408 | ppc_pci_flags |= PPC_PCI_PROBE_ONLY; | ||
494 | 409 | ||
495 | /* Scan all of the recorded PCI controllers. */ | 410 | /* Scan all of the recorded PCI controllers. */ |
496 | list_for_each_entry_safe(hose, tmp, &hose_list, list_node) { | 411 | list_for_each_entry_safe(hose, tmp, &hose_list, list_node) { |
@@ -498,17 +413,8 @@ static int __init pcibios_init(void) | |||
498 | pci_bus_add_devices(hose->bus); | 413 | pci_bus_add_devices(hose->bus); |
499 | } | 414 | } |
500 | 415 | ||
501 | if (pci_probe_only) | 416 | /* Call common code to handle resource allocation */ |
502 | pcibios_claim_of_setup(); | 417 | pcibios_resource_survey(); |
503 | else | ||
504 | /* FIXME: `else' will be removed when | ||
505 | pci_assign_unassigned_resources() is able to work | ||
506 | correctly with [partially] allocated PCI tree. */ | ||
507 | pci_assign_unassigned_resources(); | ||
508 | |||
509 | /* Call machine dependent final fixup */ | ||
510 | if (ppc_md.pcibios_fixup) | ||
511 | ppc_md.pcibios_fixup(); | ||
512 | 418 | ||
513 | printk(KERN_DEBUG "PCI: Probing PCI hardware done\n"); | 419 | printk(KERN_DEBUG "PCI: Probing PCI hardware done\n"); |
514 | 420 | ||
diff --git a/arch/powerpc/platforms/powermac/pci.c b/arch/powerpc/platforms/powermac/pci.c index a2e9b36f61ef..6bbf3c881711 100644 --- a/arch/powerpc/platforms/powermac/pci.c +++ b/arch/powerpc/platforms/powermac/pci.c | |||
@@ -994,9 +994,8 @@ void __init pmac_pci_init(void) | |||
994 | struct device_node *np, *root; | 994 | struct device_node *np, *root; |
995 | struct device_node *ht = NULL; | 995 | struct device_node *ht = NULL; |
996 | 996 | ||
997 | #ifdef CONFIG_PPC32 | ||
998 | ppc_pci_flags = PPC_PCI_CAN_SKIP_ISA_ALIGN; | 997 | ppc_pci_flags = PPC_PCI_CAN_SKIP_ISA_ALIGN; |
999 | #endif | 998 | |
1000 | root = of_find_node_by_path("/"); | 999 | root = of_find_node_by_path("/"); |
1001 | if (root == NULL) { | 1000 | if (root == NULL) { |
1002 | printk(KERN_CRIT "pmac_pci_init: can't find root " | 1001 | printk(KERN_CRIT "pmac_pci_init: can't find root " |
diff --git a/include/asm-powerpc/pci.h b/include/asm-powerpc/pci.h index 9899d893c162..a05a942b1c25 100644 --- a/include/asm-powerpc/pci.h +++ b/include/asm-powerpc/pci.h | |||
@@ -36,14 +36,10 @@ struct pci_dev; | |||
36 | 36 | ||
37 | /* | 37 | /* |
38 | * Set this to 1 if you want the kernel to re-assign all PCI | 38 | * Set this to 1 if you want the kernel to re-assign all PCI |
39 | * bus numbers | 39 | * bus numbers (don't do that on ppc64 yet !) |
40 | */ | 40 | */ |
41 | #ifdef CONFIG_PPC64 | ||
42 | #define pcibios_assign_all_busses() 0 | ||
43 | #else | ||
44 | #define pcibios_assign_all_busses() (ppc_pci_flags & \ | 41 | #define pcibios_assign_all_busses() (ppc_pci_flags & \ |
45 | PPC_PCI_REASSIGN_ALL_BUS) | 42 | PPC_PCI_REASSIGN_ALL_BUS) |
46 | #endif | ||
47 | #define pcibios_scan_all_fns(a, b) 0 | 43 | #define pcibios_scan_all_fns(a, b) 0 |
48 | 44 | ||
49 | static inline void pcibios_set_master(struct pci_dev *dev) | 45 | static inline void pcibios_set_master(struct pci_dev *dev) |
@@ -200,6 +196,8 @@ extern void pcibios_setup_new_device(struct pci_dev *dev); | |||
200 | 196 | ||
201 | extern void pcibios_claim_one_bus(struct pci_bus *b); | 197 | extern void pcibios_claim_one_bus(struct pci_bus *b); |
202 | 198 | ||
199 | extern void pcibios_resource_survey(void); | ||
200 | |||
203 | extern struct pci_controller *init_phb_dynamic(struct device_node *dn); | 201 | extern struct pci_controller *init_phb_dynamic(struct device_node *dn); |
204 | 202 | ||
205 | extern struct pci_dev *of_create_pci_dev(struct device_node *node, | 203 | extern struct pci_dev *of_create_pci_dev(struct device_node *node, |