diff options
author | Chris Metcalf <cmetcalf@tilera.com> | 2013-08-05 13:18:02 -0400 |
---|---|---|
committer | Chris Metcalf <cmetcalf@tilera.com> | 2013-08-06 12:55:40 -0400 |
commit | 1c43649a9929ca4394ae389b4510c61f3876a12b (patch) | |
tree | 0f8ed02e97c0bd3a5e4bb67ff87c64f9015d69c2 | |
parent | 9b6846cede40cf12429d0fa06b3af0a0f40ae596 (diff) |
tile PCI RC: restructure TRIO initialization
The TRIO shim initialization is shared with other kernel drivers
such as the endpoint and StreamIO drivers, so reorganize the
initialization flow to ensure that the root complex driver properly
initializes TRIO state regardless of what kind of TRIO driver will
end up using the shim.
Signed-off-by: Chris Metcalf <cmetcalf@tilera.com>
-rw-r--r-- | arch/tile/include/asm/pci.h | 1 | ||||
-rw-r--r-- | arch/tile/kernel/pci_gx.c | 209 |
2 files changed, 118 insertions, 92 deletions
diff --git a/arch/tile/include/asm/pci.h b/arch/tile/include/asm/pci.h index 9cf5308b1657..1f1b65443bad 100644 --- a/arch/tile/include/asm/pci.h +++ b/arch/tile/include/asm/pci.h | |||
@@ -180,6 +180,7 @@ struct pci_controller { | |||
180 | 180 | ||
181 | extern struct pci_controller pci_controllers[TILEGX_NUM_TRIO * TILEGX_TRIO_PCIES]; | 181 | extern struct pci_controller pci_controllers[TILEGX_NUM_TRIO * TILEGX_TRIO_PCIES]; |
182 | extern gxio_trio_context_t trio_contexts[TILEGX_NUM_TRIO]; | 182 | extern gxio_trio_context_t trio_contexts[TILEGX_NUM_TRIO]; |
183 | extern int num_trio_shims; | ||
183 | 184 | ||
184 | extern void pci_iounmap(struct pci_dev *dev, void __iomem *); | 185 | extern void pci_iounmap(struct pci_dev *dev, void __iomem *); |
185 | 186 | ||
diff --git a/arch/tile/kernel/pci_gx.c b/arch/tile/kernel/pci_gx.c index fde35891e9a7..805163838dce 100644 --- a/arch/tile/kernel/pci_gx.c +++ b/arch/tile/kernel/pci_gx.c | |||
@@ -80,16 +80,28 @@ static int rc_delay[TILEGX_NUM_TRIO][TILEGX_TRIO_PCIES]; | |||
80 | /* The PCI I/O space size in each PCI domain. */ | 80 | /* The PCI I/O space size in each PCI domain. */ |
81 | #define IO_SPACE_SIZE 0x10000 | 81 | #define IO_SPACE_SIZE 0x10000 |
82 | 82 | ||
83 | /* Provide shorter versions of some very long constant names. */ | ||
84 | #define AUTO_CONFIG_RC \ | ||
85 | TRIO_PCIE_INTFC_PORT_CONFIG__STRAP_STATE_VAL_AUTO_CONFIG_RC | ||
86 | #define AUTO_CONFIG_RC_G1 \ | ||
87 | TRIO_PCIE_INTFC_PORT_CONFIG__STRAP_STATE_VAL_AUTO_CONFIG_RC_G1 | ||
88 | #define AUTO_CONFIG_EP \ | ||
89 | TRIO_PCIE_INTFC_PORT_CONFIG__STRAP_STATE_VAL_AUTO_CONFIG_ENDPOINT | ||
90 | #define AUTO_CONFIG_EP_G1 \ | ||
91 | TRIO_PCIE_INTFC_PORT_CONFIG__STRAP_STATE_VAL_AUTO_CONFIG_ENDPOINT_G1 | ||
92 | |||
83 | /* Array of the PCIe ports configuration info obtained from the BIB. */ | 93 | /* Array of the PCIe ports configuration info obtained from the BIB. */ |
84 | struct pcie_port_property pcie_ports[TILEGX_NUM_TRIO][TILEGX_TRIO_PCIES]; | 94 | struct pcie_port_property pcie_ports[TILEGX_NUM_TRIO][TILEGX_TRIO_PCIES]; |
85 | 95 | ||
96 | /* Number of configured TRIO instances. */ | ||
97 | int num_trio_shims; | ||
98 | |||
86 | /* All drivers share the TRIO contexts defined here. */ | 99 | /* All drivers share the TRIO contexts defined here. */ |
87 | gxio_trio_context_t trio_contexts[TILEGX_NUM_TRIO]; | 100 | gxio_trio_context_t trio_contexts[TILEGX_NUM_TRIO]; |
88 | 101 | ||
89 | /* Pointer to an array of PCIe RC controllers. */ | 102 | /* Pointer to an array of PCIe RC controllers. */ |
90 | struct pci_controller pci_controllers[TILEGX_NUM_TRIO * TILEGX_TRIO_PCIES]; | 103 | struct pci_controller pci_controllers[TILEGX_NUM_TRIO * TILEGX_TRIO_PCIES]; |
91 | int num_rc_controllers; | 104 | int num_rc_controllers; |
92 | static int num_ep_controllers; | ||
93 | 105 | ||
94 | static struct pci_ops tile_cfg_ops; | 106 | static struct pci_ops tile_cfg_ops; |
95 | 107 | ||
@@ -141,13 +153,14 @@ static int tile_pcie_open(int trio_index) | |||
141 | { | 153 | { |
142 | gxio_trio_context_t *context = &trio_contexts[trio_index]; | 154 | gxio_trio_context_t *context = &trio_contexts[trio_index]; |
143 | int ret; | 155 | int ret; |
156 | int mac; | ||
144 | 157 | ||
145 | /* | 158 | /* |
146 | * This opens a file descriptor to the TRIO shim. | 159 | * This opens a file descriptor to the TRIO shim. |
147 | */ | 160 | */ |
148 | ret = gxio_trio_init(context, trio_index); | 161 | ret = gxio_trio_init(context, trio_index); |
149 | if (ret < 0) | 162 | if (ret < 0) |
150 | return ret; | 163 | goto gxio_trio_init_failure; |
151 | 164 | ||
152 | /* | 165 | /* |
153 | * Allocate an ASID for the kernel. | 166 | * Allocate an ASID for the kernel. |
@@ -189,17 +202,89 @@ static int tile_pcie_open(int trio_index) | |||
189 | } | 202 | } |
190 | #endif | 203 | #endif |
191 | 204 | ||
205 | /* Get the properties of the PCIe ports on this TRIO instance. */ | ||
206 | ret = hv_dev_pread(context->fd, 0, | ||
207 | (HV_VirtAddr)&pcie_ports[trio_index][0], | ||
208 | sizeof(struct pcie_port_property) * TILEGX_TRIO_PCIES, | ||
209 | GXIO_TRIO_OP_GET_PORT_PROPERTY); | ||
210 | if (ret < 0) { | ||
211 | pr_err("PCI: PCIE_GET_PORT_PROPERTY failure, error %d," | ||
212 | " on TRIO %d\n", ret, trio_index); | ||
213 | goto get_port_property_failure; | ||
214 | } | ||
215 | |||
216 | context->mmio_base_mac = | ||
217 | iorpc_ioremap(context->fd, 0, HV_TRIO_CONFIG_IOREMAP_SIZE); | ||
218 | if (context->mmio_base_mac == NULL) { | ||
219 | pr_err("PCI: TRIO config space mapping failure, error %d," | ||
220 | " on TRIO %d\n", ret, trio_index); | ||
221 | ret = -ENOMEM; | ||
222 | |||
223 | goto trio_mmio_mapping_failure; | ||
224 | } | ||
225 | |||
226 | /* Check the port strap state which will override the BIB setting. */ | ||
227 | for (mac = 0; mac < TILEGX_TRIO_PCIES; mac++) { | ||
228 | TRIO_PCIE_INTFC_PORT_CONFIG_t port_config; | ||
229 | unsigned int reg_offset; | ||
230 | |||
231 | /* Ignore ports that are not specified in the BIB. */ | ||
232 | if (!pcie_ports[trio_index][mac].allow_rc && | ||
233 | !pcie_ports[trio_index][mac].allow_ep) | ||
234 | continue; | ||
235 | |||
236 | reg_offset = | ||
237 | (TRIO_PCIE_INTFC_PORT_CONFIG << | ||
238 | TRIO_CFG_REGION_ADDR__REG_SHIFT) | | ||
239 | (TRIO_CFG_REGION_ADDR__INTFC_VAL_MAC_INTERFACE << | ||
240 | TRIO_CFG_REGION_ADDR__INTFC_SHIFT) | | ||
241 | (mac << TRIO_CFG_REGION_ADDR__MAC_SEL_SHIFT); | ||
242 | |||
243 | port_config.word = | ||
244 | __gxio_mmio_read(context->mmio_base_mac + reg_offset); | ||
245 | |||
246 | if (port_config.strap_state != AUTO_CONFIG_RC && | ||
247 | port_config.strap_state != AUTO_CONFIG_RC_G1) { | ||
248 | /* | ||
249 | * If this is really intended to be an EP port, record | ||
250 | * it so that the endpoint driver will know about it. | ||
251 | */ | ||
252 | if (port_config.strap_state == AUTO_CONFIG_EP || | ||
253 | port_config.strap_state == AUTO_CONFIG_EP_G1) | ||
254 | pcie_ports[trio_index][mac].allow_ep = 1; | ||
255 | } | ||
256 | } | ||
257 | |||
192 | return ret; | 258 | return ret; |
193 | 259 | ||
260 | trio_mmio_mapping_failure: | ||
261 | get_port_property_failure: | ||
194 | asid_alloc_failure: | 262 | asid_alloc_failure: |
195 | #ifdef USE_SHARED_PCIE_CONFIG_REGION | 263 | #ifdef USE_SHARED_PCIE_CONFIG_REGION |
196 | pio_alloc_failure: | 264 | pio_alloc_failure: |
197 | #endif | 265 | #endif |
198 | hv_dev_close(context->fd); | 266 | hv_dev_close(context->fd); |
267 | gxio_trio_init_failure: | ||
268 | context->fd = -1; | ||
199 | 269 | ||
200 | return ret; | 270 | return ret; |
201 | } | 271 | } |
202 | 272 | ||
273 | static int __init tile_trio_init(void) | ||
274 | { | ||
275 | int i; | ||
276 | |||
277 | /* We loop over all the TRIO shims. */ | ||
278 | for (i = 0; i < TILEGX_NUM_TRIO; i++) { | ||
279 | if (tile_pcie_open(i) < 0) | ||
280 | continue; | ||
281 | num_trio_shims++; | ||
282 | } | ||
283 | |||
284 | return 0; | ||
285 | } | ||
286 | postcore_initcall(tile_trio_init); | ||
287 | |||
203 | static void | 288 | static void |
204 | tilegx_legacy_irq_ack(struct irq_data *d) | 289 | tilegx_legacy_irq_ack(struct irq_data *d) |
205 | { | 290 | { |
@@ -320,14 +405,39 @@ free_irqs: | |||
320 | } | 405 | } |
321 | 406 | ||
322 | /* | 407 | /* |
408 | * Return 1 if the port is strapped to operate in RC mode. | ||
409 | */ | ||
410 | static int | ||
411 | strapped_for_rc(gxio_trio_context_t *trio_context, int mac) | ||
412 | { | ||
413 | TRIO_PCIE_INTFC_PORT_CONFIG_t port_config; | ||
414 | unsigned int reg_offset; | ||
415 | |||
416 | /* Check the port configuration. */ | ||
417 | reg_offset = | ||
418 | (TRIO_PCIE_INTFC_PORT_CONFIG << | ||
419 | TRIO_CFG_REGION_ADDR__REG_SHIFT) | | ||
420 | (TRIO_CFG_REGION_ADDR__INTFC_VAL_MAC_INTERFACE << | ||
421 | TRIO_CFG_REGION_ADDR__INTFC_SHIFT) | | ||
422 | (mac << TRIO_CFG_REGION_ADDR__MAC_SEL_SHIFT); | ||
423 | port_config.word = | ||
424 | __gxio_mmio_read(trio_context->mmio_base_mac + reg_offset); | ||
425 | |||
426 | if (port_config.strap_state == AUTO_CONFIG_RC || | ||
427 | port_config.strap_state == AUTO_CONFIG_RC_G1) | ||
428 | return 1; | ||
429 | else | ||
430 | return 0; | ||
431 | } | ||
432 | |||
433 | /* | ||
323 | * Find valid controllers and fill in pci_controller structs for each | 434 | * Find valid controllers and fill in pci_controller structs for each |
324 | * of them. | 435 | * of them. |
325 | * | 436 | * |
326 | * Returns the number of controllers discovered. | 437 | * Return the number of controllers discovered. |
327 | */ | 438 | */ |
328 | int __init tile_pci_init(void) | 439 | int __init tile_pci_init(void) |
329 | { | 440 | { |
330 | int num_trio_shims = 0; | ||
331 | int ctl_index = 0; | 441 | int ctl_index = 0; |
332 | int i, j; | 442 | int i, j; |
333 | 443 | ||
@@ -338,19 +448,6 @@ int __init tile_pci_init(void) | |||
338 | 448 | ||
339 | pr_info("PCI: Searching for controllers...\n"); | 449 | pr_info("PCI: Searching for controllers...\n"); |
340 | 450 | ||
341 | /* | ||
342 | * We loop over all the TRIO shims. | ||
343 | */ | ||
344 | for (i = 0; i < TILEGX_NUM_TRIO; i++) { | ||
345 | int ret; | ||
346 | |||
347 | ret = tile_pcie_open(i); | ||
348 | if (ret < 0) | ||
349 | continue; | ||
350 | |||
351 | num_trio_shims++; | ||
352 | } | ||
353 | |||
354 | if (num_trio_shims == 0 || sim_is_simulator()) | 451 | if (num_trio_shims == 0 || sim_is_simulator()) |
355 | return 0; | 452 | return 0; |
356 | 453 | ||
@@ -361,29 +458,16 @@ int __init tile_pci_init(void) | |||
361 | */ | 458 | */ |
362 | for (i = 0; i < TILEGX_NUM_TRIO; i++) { | 459 | for (i = 0; i < TILEGX_NUM_TRIO; i++) { |
363 | gxio_trio_context_t *context = &trio_contexts[i]; | 460 | gxio_trio_context_t *context = &trio_contexts[i]; |
364 | int ret; | ||
365 | 461 | ||
366 | if (context->fd < 0) | 462 | if (context->fd < 0) |
367 | continue; | 463 | continue; |
368 | 464 | ||
369 | ret = hv_dev_pread(context->fd, 0, | ||
370 | (HV_VirtAddr)&pcie_ports[i][0], | ||
371 | sizeof(struct pcie_port_property) * TILEGX_TRIO_PCIES, | ||
372 | GXIO_TRIO_OP_GET_PORT_PROPERTY); | ||
373 | if (ret < 0) { | ||
374 | pr_err("PCI: PCIE_GET_PORT_PROPERTY failure, error %d," | ||
375 | " on TRIO %d\n", ret, i); | ||
376 | continue; | ||
377 | } | ||
378 | |||
379 | for (j = 0; j < TILEGX_TRIO_PCIES; j++) { | 465 | for (j = 0; j < TILEGX_TRIO_PCIES; j++) { |
380 | if (pcie_ports[i][j].allow_rc) { | 466 | if (pcie_ports[i][j].allow_rc && |
467 | strapped_for_rc(context, j)) { | ||
381 | pcie_rc[i][j] = 1; | 468 | pcie_rc[i][j] = 1; |
382 | num_rc_controllers++; | 469 | num_rc_controllers++; |
383 | } | 470 | } |
384 | else if (pcie_ports[i][j].allow_ep) { | ||
385 | num_ep_controllers++; | ||
386 | } | ||
387 | } | 471 | } |
388 | } | 472 | } |
389 | 473 | ||
@@ -600,35 +684,10 @@ int __init pcibios_init(void) | |||
600 | 684 | ||
601 | tile_pci_init(); | 685 | tile_pci_init(); |
602 | 686 | ||
603 | if (num_rc_controllers == 0 && num_ep_controllers == 0) | 687 | if (num_rc_controllers == 0) |
604 | return 0; | 688 | return 0; |
605 | 689 | ||
606 | /* | 690 | /* |
607 | * We loop over all the TRIO shims and set up the MMIO mappings. | ||
608 | */ | ||
609 | for (i = 0; i < TILEGX_NUM_TRIO; i++) { | ||
610 | gxio_trio_context_t *context = &trio_contexts[i]; | ||
611 | |||
612 | if (context->fd < 0) | ||
613 | continue; | ||
614 | |||
615 | /* | ||
616 | * Map in the MMIO space for the MAC. | ||
617 | */ | ||
618 | offset = 0; | ||
619 | context->mmio_base_mac = | ||
620 | iorpc_ioremap(context->fd, offset, | ||
621 | HV_TRIO_CONFIG_IOREMAP_SIZE); | ||
622 | if (context->mmio_base_mac == NULL) { | ||
623 | pr_err("PCI: MAC map failure on TRIO %d\n", i); | ||
624 | |||
625 | hv_dev_close(context->fd); | ||
626 | context->fd = -1; | ||
627 | continue; | ||
628 | } | ||
629 | } | ||
630 | |||
631 | /* | ||
632 | * Delay a bit in case devices aren't ready. Some devices are | 691 | * Delay a bit in case devices aren't ready. Some devices are |
633 | * known to require at least 20ms here, but we use a more | 692 | * known to require at least 20ms here, but we use a more |
634 | * conservative value. | 693 | * conservative value. |
@@ -639,7 +698,6 @@ int __init pcibios_init(void) | |||
639 | for (next_busno = 0, i = 0; i < num_rc_controllers; i++) { | 698 | for (next_busno = 0, i = 0; i < num_rc_controllers; i++) { |
640 | struct pci_controller *controller = &pci_controllers[i]; | 699 | struct pci_controller *controller = &pci_controllers[i]; |
641 | gxio_trio_context_t *trio_context = controller->trio; | 700 | gxio_trio_context_t *trio_context = controller->trio; |
642 | TRIO_PCIE_INTFC_PORT_CONFIG_t port_config; | ||
643 | TRIO_PCIE_INTFC_PORT_STATUS_t port_status; | 701 | TRIO_PCIE_INTFC_PORT_STATUS_t port_status; |
644 | TRIO_PCIE_INTFC_TX_FIFO_CTL_t tx_fifo_ctl; | 702 | TRIO_PCIE_INTFC_TX_FIFO_CTL_t tx_fifo_ctl; |
645 | struct pci_bus *bus; | 703 | struct pci_bus *bus; |
@@ -656,39 +714,6 @@ int __init pcibios_init(void) | |||
656 | mac = controller->mac; | 714 | mac = controller->mac; |
657 | 715 | ||
658 | /* | 716 | /* |
659 | * Check the port strap state which will override the BIB | ||
660 | * setting. | ||
661 | */ | ||
662 | |||
663 | reg_offset = | ||
664 | (TRIO_PCIE_INTFC_PORT_CONFIG << | ||
665 | TRIO_CFG_REGION_ADDR__REG_SHIFT) | | ||
666 | (TRIO_CFG_REGION_ADDR__INTFC_VAL_MAC_INTERFACE << | ||
667 | TRIO_CFG_REGION_ADDR__INTFC_SHIFT ) | | ||
668 | (mac << TRIO_CFG_REGION_ADDR__MAC_SEL_SHIFT); | ||
669 | |||
670 | port_config.word = | ||
671 | __gxio_mmio_read(trio_context->mmio_base_mac + | ||
672 | reg_offset); | ||
673 | |||
674 | if ((port_config.strap_state != | ||
675 | TRIO_PCIE_INTFC_PORT_CONFIG__STRAP_STATE_VAL_AUTO_CONFIG_RC) && | ||
676 | (port_config.strap_state != | ||
677 | TRIO_PCIE_INTFC_PORT_CONFIG__STRAP_STATE_VAL_AUTO_CONFIG_RC_G1)) { | ||
678 | /* | ||
679 | * If this is really intended to be an EP port, | ||
680 | * record it so that the endpoint driver will know about it. | ||
681 | */ | ||
682 | if (port_config.strap_state == | ||
683 | TRIO_PCIE_INTFC_PORT_CONFIG__STRAP_STATE_VAL_AUTO_CONFIG_ENDPOINT || | ||
684 | port_config.strap_state == | ||
685 | TRIO_PCIE_INTFC_PORT_CONFIG__STRAP_STATE_VAL_AUTO_CONFIG_ENDPOINT_G1) | ||
686 | pcie_ports[trio_index][mac].allow_ep = 1; | ||
687 | |||
688 | continue; | ||
689 | } | ||
690 | |||
691 | /* | ||
692 | * Check for PCIe link-up status to decide if we need | 717 | * Check for PCIe link-up status to decide if we need |
693 | * to force the link to come up. | 718 | * to force the link to come up. |
694 | */ | 719 | */ |