2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
15 #include <linux/kernel.h>
16 #include <linux/mmzone.h>
17 #include <linux/pci.h>
18 #include <linux/delay.h>
19 #include <linux/string.h>
20 #include <linux/init.h>
21 #include <linux/capability.h>
22 #include <linux/sched.h>
23 #include <linux/errno.h>
24 #include <linux/irq.h>
25 #include <linux/msi.h>
27 #include <linux/uaccess.h>
28 #include <linux/ctype.h>
30 #include <asm/processor.h>
31 #include <asm/sections.h>
32 #include <asm/byteorder.h>
34 #include <gxio/iorpc_globals.h>
35 #include <gxio/kiorpc.h>
36 #include <gxio/trio.h>
37 #include <gxio/iorpc_trio.h>
38 #include <hv/drv_trio_intf.h>
43 * This file containes the routines to search for PCI buses,
44 * enumerate the buses, and configure any attached devices.
47 #define DEBUG_PCI_CFG 0
50 #define TRACE_CFG_WR(size, val, bus, dev, func, offset) \
51 pr_info("CFG WR %d-byte VAL %#x to bus %d dev %d func %d addr %u\n", \
52 size, val, bus, dev, func, offset & 0xFFF);
53 #define TRACE_CFG_RD(size, val, bus, dev, func, offset) \
54 pr_info("CFG RD %d-byte VAL %#x from bus %d dev %d func %d addr %u\n", \
55 size, val, bus, dev, func, offset & 0xFFF);
57 #define TRACE_CFG_WR(...)
58 #define TRACE_CFG_RD(...)
61 static int pci_probe
= 1;
63 /* Information on the PCIe RC ports configuration. */
64 static int pcie_rc
[TILEGX_NUM_TRIO
][TILEGX_TRIO_PCIES
];
67 * On some platforms with one or more Gx endpoint ports, we need to
68 * delay the PCIe RC port probe for a few seconds to work around
69 * a HW PCIe link-training bug. The exact delay is specified with
70 * a kernel boot argument in the form of "pcie_rc_delay=T,P,S",
71 * where T is the TRIO instance number, P is the port number and S is
72 * the delay in seconds. If the argument is specified, but the delay is
73 * not provided, the value will be DEFAULT_RC_DELAY.
75 static int rc_delay
[TILEGX_NUM_TRIO
][TILEGX_TRIO_PCIES
];
77 /* Default number of seconds that the PCIe RC port probe can be delayed. */
78 #define DEFAULT_RC_DELAY 10
80 /* The PCI I/O space size in each PCI domain. */
81 #define IO_SPACE_SIZE 0x10000
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
93 /* Array of the PCIe ports configuration info obtained from the BIB. */
94 struct pcie_trio_ports_property pcie_ports
[TILEGX_NUM_TRIO
];
96 /* Number of configured TRIO instances. */
99 /* All drivers share the TRIO contexts defined here. */
100 gxio_trio_context_t trio_contexts
[TILEGX_NUM_TRIO
];
102 /* Pointer to an array of PCIe RC controllers. */
103 struct pci_controller pci_controllers
[TILEGX_NUM_TRIO
* TILEGX_TRIO_PCIES
];
104 int num_rc_controllers
;
106 static struct pci_ops tile_cfg_ops
;
108 /* Mask of CPUs that should receive PCIe interrupts. */
109 static struct cpumask intr_cpus_map
;
111 /* We don't need to worry about the alignment of resources. */
112 resource_size_t
pcibios_align_resource(void *data
, const struct resource
*res
,
113 resource_size_t size
,
114 resource_size_t align
)
118 EXPORT_SYMBOL(pcibios_align_resource
);
121 * Pick a CPU to receive and handle the PCIe interrupts, based on the IRQ #.
122 * For now, we simply send interrupts to non-dataplane CPUs.
123 * We may implement methods to allow user to specify the target CPUs,
124 * e.g. via boot arguments.
126 static int tile_irq_cpu(int irq
)
132 count
= cpumask_weight(&intr_cpus_map
);
133 if (unlikely(count
== 0)) {
134 pr_warn("intr_cpus_map empty, interrupts will be delievered to dataplane tiles\n");
135 return irq
% (smp_height
* smp_width
);
139 for_each_cpu(cpu
, &intr_cpus_map
) {
146 /* Open a file descriptor to the TRIO shim. */
147 static int tile_pcie_open(int trio_index
)
149 gxio_trio_context_t
*context
= &trio_contexts
[trio_index
];
153 /* This opens a file descriptor to the TRIO shim. */
154 ret
= gxio_trio_init(context
, trio_index
);
156 goto gxio_trio_init_failure
;
158 /* Allocate an ASID for the kernel. */
159 ret
= gxio_trio_alloc_asids(context
, 1, 0, 0);
161 pr_err("PCI: ASID alloc failure on TRIO %d, give up\n",
163 goto asid_alloc_failure
;
168 #ifdef USE_SHARED_PCIE_CONFIG_REGION
170 * Alloc a PIO region for config access, shared by all MACs per TRIO.
171 * This shouldn't fail since the kernel is supposed to the first
172 * client of the TRIO's PIO regions.
174 ret
= gxio_trio_alloc_pio_regions(context
, 1, 0, 0);
176 pr_err("PCI: CFG PIO alloc failure on TRIO %d, give up\n",
178 goto pio_alloc_failure
;
181 context
->pio_cfg_index
= ret
;
184 * For PIO CFG, the bus_address_hi parameter is 0. The mac parameter
185 * is also 0 because it is specified in PIO_REGION_SETUP_CFG_ADDR.
187 ret
= gxio_trio_init_pio_region_aux(context
, context
->pio_cfg_index
,
188 0, 0, HV_TRIO_PIO_FLAG_CONFIG_SPACE
);
190 pr_err("PCI: CFG PIO init failure on TRIO %d, give up\n",
192 goto pio_alloc_failure
;
196 /* Get the properties of the PCIe ports on this TRIO instance. */
197 ret
= gxio_trio_get_port_property(context
, &pcie_ports
[trio_index
]);
199 pr_err("PCI: PCIE_GET_PORT_PROPERTY failure, error %d, on TRIO %d\n",
201 goto get_port_property_failure
;
204 context
->mmio_base_mac
=
205 iorpc_ioremap(context
->fd
, 0, HV_TRIO_CONFIG_IOREMAP_SIZE
);
206 if (context
->mmio_base_mac
== NULL
) {
207 pr_err("PCI: TRIO config space mapping failure, error %d, on TRIO %d\n",
211 goto trio_mmio_mapping_failure
;
214 /* Check the port strap state which will override the BIB setting. */
215 for (mac
= 0; mac
< TILEGX_TRIO_PCIES
; mac
++) {
216 TRIO_PCIE_INTFC_PORT_CONFIG_t port_config
;
217 unsigned int reg_offset
;
219 /* Ignore ports that are not specified in the BIB. */
220 if (!pcie_ports
[trio_index
].ports
[mac
].allow_rc
&&
221 !pcie_ports
[trio_index
].ports
[mac
].allow_ep
)
225 (TRIO_PCIE_INTFC_PORT_CONFIG
<<
226 TRIO_CFG_REGION_ADDR__REG_SHIFT
) |
227 (TRIO_CFG_REGION_ADDR__INTFC_VAL_MAC_INTERFACE
<<
228 TRIO_CFG_REGION_ADDR__INTFC_SHIFT
) |
229 (mac
<< TRIO_CFG_REGION_ADDR__MAC_SEL_SHIFT
);
232 __gxio_mmio_read(context
->mmio_base_mac
+ reg_offset
);
234 if (port_config
.strap_state
!= AUTO_CONFIG_RC
&&
235 port_config
.strap_state
!= AUTO_CONFIG_RC_G1
) {
237 * If this is really intended to be an EP port, record
238 * it so that the endpoint driver will know about it.
240 if (port_config
.strap_state
== AUTO_CONFIG_EP
||
241 port_config
.strap_state
== AUTO_CONFIG_EP_G1
)
242 pcie_ports
[trio_index
].ports
[mac
].allow_ep
= 1;
248 trio_mmio_mapping_failure
:
249 get_port_property_failure
:
251 #ifdef USE_SHARED_PCIE_CONFIG_REGION
254 hv_dev_close(context
->fd
);
255 gxio_trio_init_failure
:
261 static int __init
tile_trio_init(void)
265 /* We loop over all the TRIO shims. */
266 for (i
= 0; i
< TILEGX_NUM_TRIO
; i
++) {
267 if (tile_pcie_open(i
) < 0)
274 postcore_initcall(tile_trio_init
);
276 static void tilegx_legacy_irq_ack(struct irq_data
*d
)
278 __insn_mtspr(SPR_IPI_EVENT_RESET_K
, 1UL << d
->irq
);
281 static void tilegx_legacy_irq_mask(struct irq_data
*d
)
283 __insn_mtspr(SPR_IPI_MASK_SET_K
, 1UL << d
->irq
);
286 static void tilegx_legacy_irq_unmask(struct irq_data
*d
)
288 __insn_mtspr(SPR_IPI_MASK_RESET_K
, 1UL << d
->irq
);
291 static struct irq_chip tilegx_legacy_irq_chip
= {
292 .name
= "tilegx_legacy_irq",
293 .irq_ack
= tilegx_legacy_irq_ack
,
294 .irq_mask
= tilegx_legacy_irq_mask
,
295 .irq_unmask
= tilegx_legacy_irq_unmask
,
297 /* TBD: support set_affinity. */
301 * This is a wrapper function of the kernel level-trigger interrupt
302 * handler handle_level_irq() for PCI legacy interrupts. The TRIO
303 * is configured such that only INTx Assert interrupts are proxied
304 * to Linux which just calls handle_level_irq() after clearing the
305 * MAC INTx Assert status bit associated with this interrupt.
307 static void trio_handle_level_irq(unsigned int __irq
, struct irq_desc
*desc
)
309 struct pci_controller
*controller
= irq_desc_get_handler_data(desc
);
310 gxio_trio_context_t
*trio_context
= controller
->trio
;
311 uint64_t intx
= (uint64_t)irq_desc_get_chip_data(desc
);
312 unsigned int irq
= irq_desc_get_irq(desc
);
313 int mac
= controller
->mac
;
314 unsigned int reg_offset
;
317 handle_level_irq(irq
, desc
);
320 * Clear the INTx Level status, otherwise future interrupts are
323 reg_offset
= (TRIO_PCIE_INTFC_MAC_INT_STS
<<
324 TRIO_CFG_REGION_ADDR__REG_SHIFT
) |
325 (TRIO_CFG_REGION_ADDR__INTFC_VAL_MAC_INTERFACE
<<
326 TRIO_CFG_REGION_ADDR__INTFC_SHIFT
) |
327 (mac
<< TRIO_CFG_REGION_ADDR__MAC_SEL_SHIFT
);
329 level_mask
= TRIO_PCIE_INTFC_MAC_INT_STS__INT_LEVEL_MASK
<< intx
;
331 __gxio_mmio_write(trio_context
->mmio_base_mac
+ reg_offset
, level_mask
);
335 * Create kernel irqs and set up the handlers for the legacy interrupts.
336 * Also some minimum initialization for the MSI support.
338 static int tile_init_irqs(struct pci_controller
*controller
)
345 cpumask_copy(&intr_cpus_map
, cpu_online_mask
);
348 for (i
= 0; i
< 4; i
++) {
349 gxio_trio_context_t
*context
= controller
->trio
;
352 /* Ask the kernel to allocate an IRQ. */
353 irq
= irq_alloc_hwirq(-1);
355 pr_err("PCI: no free irq vectors, failed for %d\n", i
);
358 controller
->irq_intx_table
[i
] = irq
;
360 /* Distribute the 4 IRQs to different tiles. */
361 cpu
= tile_irq_cpu(irq
);
363 /* Configure the TRIO intr binding for this IRQ. */
364 result
= gxio_trio_config_legacy_intr(context
, cpu_x(cpu
),
365 cpu_y(cpu
), KERNEL_PL
,
366 irq
, controller
->mac
, i
);
368 pr_err("PCI: MAC intx config failed for %d\n", i
);
373 /* Register the IRQ handler with the kernel. */
374 irq_set_chip_and_handler(irq
, &tilegx_legacy_irq_chip
,
375 trio_handle_level_irq
);
376 irq_set_chip_data(irq
, (void *)(uint64_t)i
);
377 irq_set_handler_data(irq
, controller
);
383 for (j
= 0; j
< i
; j
++)
384 irq_free_hwirq(controller
->irq_intx_table
[j
]);
390 * Return 1 if the port is strapped to operate in RC mode.
393 strapped_for_rc(gxio_trio_context_t
*trio_context
, int mac
)
395 TRIO_PCIE_INTFC_PORT_CONFIG_t port_config
;
396 unsigned int reg_offset
;
398 /* Check the port configuration. */
400 (TRIO_PCIE_INTFC_PORT_CONFIG
<<
401 TRIO_CFG_REGION_ADDR__REG_SHIFT
) |
402 (TRIO_CFG_REGION_ADDR__INTFC_VAL_MAC_INTERFACE
<<
403 TRIO_CFG_REGION_ADDR__INTFC_SHIFT
) |
404 (mac
<< TRIO_CFG_REGION_ADDR__MAC_SEL_SHIFT
);
406 __gxio_mmio_read(trio_context
->mmio_base_mac
+ reg_offset
);
408 if (port_config
.strap_state
== AUTO_CONFIG_RC
||
409 port_config
.strap_state
== AUTO_CONFIG_RC_G1
)
416 * Find valid controllers and fill in pci_controller structs for each
419 * Return the number of controllers discovered.
421 int __init
tile_pci_init(void)
427 pr_info("PCI: disabled by boot argument\n");
431 pr_info("PCI: Searching for controllers...\n");
433 if (num_trio_shims
== 0 || sim_is_simulator())
437 * Now determine which PCIe ports are configured to operate in RC
438 * mode. There is a differece in the port configuration capability
439 * between the Gx36 and Gx72 devices.
441 * The Gx36 has configuration capability for each of the 3 PCIe
442 * interfaces (disable, auto endpoint, auto RC, etc.).
443 * On the Gx72, you can only select one of the 3 PCIe interfaces per
444 * TRIO to train automatically. Further, the allowable training modes
445 * are reduced to four options (auto endpoint, auto RC, stream x1,
448 * For Gx36 ports, it must be allowed to be in RC mode by the
449 * Board Information Block, and the hardware strapping pins must be
452 * For Gx72 ports, the port will operate in RC mode if either of the
454 * 1. It is allowed to be in RC mode by the Board Information Block,
455 * and the BIB doesn't allow the EP mode.
456 * 2. It is allowed to be in either the RC or the EP mode by the BIB,
457 * and the hardware strapping pin is set to RC mode.
459 for (i
= 0; i
< TILEGX_NUM_TRIO
; i
++) {
460 gxio_trio_context_t
*context
= &trio_contexts
[i
];
465 for (j
= 0; j
< TILEGX_TRIO_PCIES
; j
++) {
468 if (pcie_ports
[i
].is_gx72
&&
469 pcie_ports
[i
].ports
[j
].allow_rc
) {
470 if (!pcie_ports
[i
].ports
[j
].allow_ep
||
471 strapped_for_rc(context
, j
))
473 } else if (pcie_ports
[i
].ports
[j
].allow_rc
&&
474 strapped_for_rc(context
, j
)) {
479 num_rc_controllers
++;
484 /* Return if no PCIe ports are configured to operate in RC mode. */
485 if (num_rc_controllers
== 0)
488 /* Set the TRIO pointer and MAC index for each PCIe RC port. */
489 for (i
= 0; i
< TILEGX_NUM_TRIO
; i
++) {
490 for (j
= 0; j
< TILEGX_TRIO_PCIES
; j
++) {
492 pci_controllers
[ctl_index
].trio
=
494 pci_controllers
[ctl_index
].mac
= j
;
495 pci_controllers
[ctl_index
].trio_index
= i
;
497 if (ctl_index
== num_rc_controllers
)
504 /* Configure each PCIe RC port. */
505 for (i
= 0; i
< num_rc_controllers
; i
++) {
507 /* Configure the PCIe MAC to run in RC mode. */
508 struct pci_controller
*controller
= &pci_controllers
[i
];
510 controller
->index
= i
;
511 controller
->ops
= &tile_cfg_ops
;
513 controller
->io_space
.start
= PCIBIOS_MIN_IO
+
515 controller
->io_space
.end
= controller
->io_space
.start
+
517 BUG_ON(controller
->io_space
.end
> IO_SPACE_LIMIT
);
518 controller
->io_space
.flags
= IORESOURCE_IO
;
519 snprintf(controller
->io_space_name
,
520 sizeof(controller
->io_space_name
),
521 "PCI I/O domain %d", i
);
522 controller
->io_space
.name
= controller
->io_space_name
;
525 * The PCI memory resource is located above the PA space.
526 * For every host bridge, the BAR window or the MMIO aperture
527 * is in range [3GB, 4GB - 1] of a 4GB space beyond the
530 controller
->mem_offset
= TILE_PCI_MEM_START
+
531 (i
* TILE_PCI_BAR_WINDOW_TOP
);
532 controller
->mem_space
.start
= controller
->mem_offset
+
533 TILE_PCI_BAR_WINDOW_TOP
- TILE_PCI_BAR_WINDOW_SIZE
;
534 controller
->mem_space
.end
= controller
->mem_offset
+
535 TILE_PCI_BAR_WINDOW_TOP
- 1;
536 controller
->mem_space
.flags
= IORESOURCE_MEM
;
537 snprintf(controller
->mem_space_name
,
538 sizeof(controller
->mem_space_name
),
539 "PCI mem domain %d", i
);
540 controller
->mem_space
.name
= controller
->mem_space_name
;
543 return num_rc_controllers
;
547 * (pin - 1) converts from the PCI standard's [1:4] convention to
548 * a normal [0:3] range.
550 static int tile_map_irq(const struct pci_dev
*dev
, u8 device
, u8 pin
)
552 struct pci_controller
*controller
=
553 (struct pci_controller
*)dev
->sysdata
;
554 return controller
->irq_intx_table
[pin
- 1];
557 static void fixup_read_and_payload_sizes(struct pci_controller
*controller
)
559 gxio_trio_context_t
*trio_context
= controller
->trio
;
560 struct pci_bus
*root_bus
= controller
->root_bus
;
561 TRIO_PCIE_RC_DEVICE_CONTROL_t dev_control
;
562 TRIO_PCIE_RC_DEVICE_CAP_t rc_dev_cap
;
563 unsigned int reg_offset
;
564 struct pci_bus
*child
;
568 mac
= controller
->mac
;
570 /* Set our max read request size to be 4KB. */
572 (TRIO_PCIE_RC_DEVICE_CONTROL
<<
573 TRIO_CFG_REGION_ADDR__REG_SHIFT
) |
574 (TRIO_CFG_REGION_ADDR__INTFC_VAL_MAC_STANDARD
<<
575 TRIO_CFG_REGION_ADDR__INTFC_SHIFT
) |
576 (mac
<< TRIO_CFG_REGION_ADDR__MAC_SEL_SHIFT
);
578 dev_control
.word
= __gxio_mmio_read32(trio_context
->mmio_base_mac
+
580 dev_control
.max_read_req_sz
= 5;
581 __gxio_mmio_write32(trio_context
->mmio_base_mac
+ reg_offset
,
585 * Set the max payload size supported by this Gx PCIe MAC.
586 * Though Gx PCIe supports Max Payload Size of up to 1024 bytes,
587 * experiments have shown that setting MPS to 256 yields the
591 (TRIO_PCIE_RC_DEVICE_CAP
<<
592 TRIO_CFG_REGION_ADDR__REG_SHIFT
) |
593 (TRIO_CFG_REGION_ADDR__INTFC_VAL_MAC_STANDARD
<<
594 TRIO_CFG_REGION_ADDR__INTFC_SHIFT
) |
595 (mac
<< TRIO_CFG_REGION_ADDR__MAC_SEL_SHIFT
);
597 rc_dev_cap
.word
= __gxio_mmio_read32(trio_context
->mmio_base_mac
+
599 rc_dev_cap
.mps_sup
= 1;
600 __gxio_mmio_write32(trio_context
->mmio_base_mac
+ reg_offset
,
603 /* Configure PCI Express MPS setting. */
604 list_for_each_entry(child
, &root_bus
->children
, node
)
605 pcie_bus_configure_settings(child
);
608 * Set the mac_config register in trio based on the MPS/MRS of the link.
611 (TRIO_PCIE_RC_DEVICE_CONTROL
<<
612 TRIO_CFG_REGION_ADDR__REG_SHIFT
) |
613 (TRIO_CFG_REGION_ADDR__INTFC_VAL_MAC_STANDARD
<<
614 TRIO_CFG_REGION_ADDR__INTFC_SHIFT
) |
615 (mac
<< TRIO_CFG_REGION_ADDR__MAC_SEL_SHIFT
);
617 dev_control
.word
= __gxio_mmio_read32(trio_context
->mmio_base_mac
+
620 err
= gxio_trio_set_mps_mrs(trio_context
,
621 dev_control
.max_payload_size
,
622 dev_control
.max_read_req_sz
,
625 pr_err("PCI: PCIE_CONFIGURE_MAC_MPS_MRS failure, MAC %d on TRIO %d\n",
626 mac
, controller
->trio_index
);
630 static int setup_pcie_rc_delay(char *str
)
632 unsigned long delay
= 0;
633 unsigned long trio_index
;
636 if (str
== NULL
|| !isdigit(*str
))
638 trio_index
= simple_strtoul(str
, (char **)&str
, 10);
639 if (trio_index
>= TILEGX_NUM_TRIO
)
648 mac
= simple_strtoul(str
, (char **)&str
, 10);
649 if (mac
>= TILEGX_TRIO_PCIES
)
659 delay
= simple_strtoul(str
, (char **)&str
, 10);
662 rc_delay
[trio_index
][mac
] = delay
? : DEFAULT_RC_DELAY
;
665 early_param("pcie_rc_delay", setup_pcie_rc_delay
);
667 /* PCI initialization entry point, called by subsys_initcall. */
668 int __init
pcibios_init(void)
670 resource_size_t offset
;
671 LIST_HEAD(resources
);
677 if (num_rc_controllers
== 0)
681 * Delay a bit in case devices aren't ready. Some devices are
682 * known to require at least 20ms here, but we use a more
683 * conservative value.
687 /* Scan all of the recorded PCI controllers. */
688 for (next_busno
= 0, i
= 0; i
< num_rc_controllers
; i
++) {
689 struct pci_controller
*controller
= &pci_controllers
[i
];
690 gxio_trio_context_t
*trio_context
= controller
->trio
;
691 TRIO_PCIE_INTFC_PORT_STATUS_t port_status
;
692 TRIO_PCIE_INTFC_TX_FIFO_CTL_t tx_fifo_ctl
;
694 unsigned int reg_offset
;
695 unsigned int class_code_revision
;
700 if (trio_context
->fd
< 0)
703 trio_index
= controller
->trio_index
;
704 mac
= controller
->mac
;
707 * Check for PCIe link-up status to decide if we need
708 * to force the link to come up.
711 (TRIO_PCIE_INTFC_PORT_STATUS
<<
712 TRIO_CFG_REGION_ADDR__REG_SHIFT
) |
713 (TRIO_CFG_REGION_ADDR__INTFC_VAL_MAC_INTERFACE
<<
714 TRIO_CFG_REGION_ADDR__INTFC_SHIFT
) |
715 (mac
<< TRIO_CFG_REGION_ADDR__MAC_SEL_SHIFT
);
718 __gxio_mmio_read(trio_context
->mmio_base_mac
+
720 if (!port_status
.dl_up
) {
721 if (rc_delay
[trio_index
][mac
]) {
722 pr_info("Delaying PCIe RC TRIO init %d sec on MAC %d on TRIO %d\n",
723 rc_delay
[trio_index
][mac
], mac
,
725 msleep(rc_delay
[trio_index
][mac
] * 1000);
727 ret
= gxio_trio_force_rc_link_up(trio_context
, mac
);
729 pr_err("PCI: PCIE_FORCE_LINK_UP failure, MAC %d on TRIO %d\n",
733 pr_info("PCI: Found PCI controller #%d on TRIO %d MAC %d\n",
734 i
, trio_index
, controller
->mac
);
736 /* Delay the bus probe if needed. */
737 if (rc_delay
[trio_index
][mac
]) {
738 pr_info("Delaying PCIe RC bus enumerating %d sec on MAC %d on TRIO %d\n",
739 rc_delay
[trio_index
][mac
], mac
, trio_index
);
740 msleep(rc_delay
[trio_index
][mac
] * 1000);
743 * Wait a bit here because some EP devices
744 * take longer to come up.
749 /* Check for PCIe link-up status again. */
751 __gxio_mmio_read(trio_context
->mmio_base_mac
+
753 if (!port_status
.dl_up
) {
754 if (pcie_ports
[trio_index
].ports
[mac
].removable
) {
755 pr_info("PCI: link is down, MAC %d on TRIO %d\n",
757 pr_info("This is expected if no PCIe card is connected to this link\n");
759 pr_err("PCI: link is down, MAC %d on TRIO %d\n",
765 * Ensure that the link can come out of L1 power down state.
766 * Strictly speaking, this is needed only in the case of
767 * heavy RC-initiated DMAs.
770 (TRIO_PCIE_INTFC_TX_FIFO_CTL
<<
771 TRIO_CFG_REGION_ADDR__REG_SHIFT
) |
772 (TRIO_CFG_REGION_ADDR__INTFC_VAL_MAC_INTERFACE
<<
773 TRIO_CFG_REGION_ADDR__INTFC_SHIFT
) |
774 (mac
<< TRIO_CFG_REGION_ADDR__MAC_SEL_SHIFT
);
776 __gxio_mmio_read(trio_context
->mmio_base_mac
+
778 tx_fifo_ctl
.min_p_credits
= 0;
779 __gxio_mmio_write(trio_context
->mmio_base_mac
+ reg_offset
,
783 * Change the device ID so that Linux bus crawl doesn't confuse
784 * the internal bridge with any Tilera endpoints.
787 (TRIO_PCIE_RC_DEVICE_ID_VEN_ID
<<
788 TRIO_CFG_REGION_ADDR__REG_SHIFT
) |
789 (TRIO_CFG_REGION_ADDR__INTFC_VAL_MAC_STANDARD
<<
790 TRIO_CFG_REGION_ADDR__INTFC_SHIFT
) |
791 (mac
<< TRIO_CFG_REGION_ADDR__MAC_SEL_SHIFT
);
793 __gxio_mmio_write32(trio_context
->mmio_base_mac
+ reg_offset
,
794 (TILERA_GX36_RC_DEV_ID
<<
795 TRIO_PCIE_RC_DEVICE_ID_VEN_ID__DEV_ID_SHIFT
) |
798 /* Set the internal P2P bridge class code. */
800 (TRIO_PCIE_RC_REVISION_ID
<<
801 TRIO_CFG_REGION_ADDR__REG_SHIFT
) |
802 (TRIO_CFG_REGION_ADDR__INTFC_VAL_MAC_STANDARD
<<
803 TRIO_CFG_REGION_ADDR__INTFC_SHIFT
) |
804 (mac
<< TRIO_CFG_REGION_ADDR__MAC_SEL_SHIFT
);
806 class_code_revision
=
807 __gxio_mmio_read32(trio_context
->mmio_base_mac
+
809 class_code_revision
= (class_code_revision
& 0xff) |
810 (PCI_CLASS_BRIDGE_PCI
<< 16);
812 __gxio_mmio_write32(trio_context
->mmio_base_mac
+
813 reg_offset
, class_code_revision
);
815 #ifdef USE_SHARED_PCIE_CONFIG_REGION
817 /* Map in the MMIO space for the PIO region. */
818 offset
= HV_TRIO_PIO_OFFSET(trio_context
->pio_cfg_index
) |
819 (((unsigned long long)mac
) <<
820 TRIO_TILE_PIO_REGION_SETUP_CFG_ADDR__MAC_SHIFT
);
824 /* Alloc a PIO region for PCI config access per MAC. */
825 ret
= gxio_trio_alloc_pio_regions(trio_context
, 1, 0, 0);
827 pr_err("PCI: PCI CFG PIO alloc failure for mac %d on TRIO %d, give up\n",
833 trio_context
->pio_cfg_index
[mac
] = ret
;
835 /* For PIO CFG, the bus_address_hi parameter is 0. */
836 ret
= gxio_trio_init_pio_region_aux(trio_context
,
837 trio_context
->pio_cfg_index
[mac
],
838 mac
, 0, HV_TRIO_PIO_FLAG_CONFIG_SPACE
);
840 pr_err("PCI: PCI CFG PIO init failure for mac %d on TRIO %d, give up\n",
846 offset
= HV_TRIO_PIO_OFFSET(trio_context
->pio_cfg_index
[mac
]) |
847 (((unsigned long long)mac
) <<
848 TRIO_TILE_PIO_REGION_SETUP_CFG_ADDR__MAC_SHIFT
);
853 * To save VMALLOC space, we take advantage of the fact that
854 * bit 29 in the PIO CFG address format is reserved 0. With
855 * TRIO_TILE_PIO_REGION_SETUP_CFG_ADDR__MAC_SHIFT being 30,
856 * this cuts VMALLOC space usage from 1GB to 512MB per mac.
858 trio_context
->mmio_base_pio_cfg
[mac
] =
859 iorpc_ioremap(trio_context
->fd
, offset
, (1UL <<
860 (TRIO_TILE_PIO_REGION_SETUP_CFG_ADDR__MAC_SHIFT
- 1)));
861 if (trio_context
->mmio_base_pio_cfg
[mac
] == NULL
) {
862 pr_err("PCI: PIO map failure for mac %d on TRIO %d\n",
868 /* Initialize the PCIe interrupts. */
869 if (tile_init_irqs(controller
)) {
870 pr_err("PCI: IRQs init failure for mac %d on TRIO %d\n",
877 * The PCI memory resource is located above the PA space.
878 * The memory range for the PCI root bus should not overlap
879 * with the physical RAM.
881 pci_add_resource_offset(&resources
, &controller
->mem_space
,
882 controller
->mem_offset
);
883 pci_add_resource(&resources
, &controller
->io_space
);
884 controller
->first_busno
= next_busno
;
885 bus
= pci_scan_root_bus(NULL
, next_busno
, controller
->ops
,
886 controller
, &resources
);
887 controller
->root_bus
= bus
;
888 next_busno
= bus
->busn_res
.end
+ 1;
891 /* Do machine dependent PCI interrupt routing */
892 pci_fixup_irqs(pci_common_swizzle
, tile_map_irq
);
895 * This comes from the generic Linux PCI driver.
897 * It allocates all of the resources (I/O memory, etc)
898 * associated with the devices read in above.
900 pci_assign_unassigned_resources();
902 /* Record the I/O resources in the PCI controller structure. */
903 for (i
= 0; i
< num_rc_controllers
; i
++) {
904 struct pci_controller
*controller
= &pci_controllers
[i
];
905 gxio_trio_context_t
*trio_context
= controller
->trio
;
906 struct pci_bus
*root_bus
= pci_controllers
[i
].root_bus
;
911 * Skip controllers that are not properly initialized or
914 if (root_bus
== NULL
)
917 /* Configure the max_payload_size values for this domain. */
918 fixup_read_and_payload_sizes(controller
);
920 /* Alloc a PIO region for PCI memory access for each RC port. */
921 ret
= gxio_trio_alloc_pio_regions(trio_context
, 1, 0, 0);
923 pr_err("PCI: MEM PIO alloc failure on TRIO %d mac %d, give up\n",
924 controller
->trio_index
, controller
->mac
);
929 controller
->pio_mem_index
= ret
;
932 * For PIO MEM, the bus_address_hi parameter is hard-coded 0
933 * because we always assign 32-bit PCI bus BAR ranges.
935 ret
= gxio_trio_init_pio_region_aux(trio_context
,
936 controller
->pio_mem_index
,
941 pr_err("PCI: MEM PIO init failure on TRIO %d mac %d, give up\n",
942 controller
->trio_index
, controller
->mac
);
947 #ifdef CONFIG_TILE_PCI_IO
949 * Alloc a PIO region for PCI I/O space access for each RC port.
951 ret
= gxio_trio_alloc_pio_regions(trio_context
, 1, 0, 0);
953 pr_err("PCI: I/O PIO alloc failure on TRIO %d mac %d, give up\n",
954 controller
->trio_index
, controller
->mac
);
959 controller
->pio_io_index
= ret
;
962 * For PIO IO, the bus_address_hi parameter is hard-coded 0
963 * because PCI I/O address space is 32-bit.
965 ret
= gxio_trio_init_pio_region_aux(trio_context
,
966 controller
->pio_io_index
,
969 HV_TRIO_PIO_FLAG_IO_SPACE
);
971 pr_err("PCI: I/O PIO init failure on TRIO %d mac %d, give up\n",
972 controller
->trio_index
, controller
->mac
);
979 * Configure a Mem-Map region for each memory controller so
980 * that Linux can map all of its PA space to the PCI bus.
981 * Use the IOMMU to handle hash-for-home memory.
983 for_each_online_node(j
) {
984 unsigned long start_pfn
= node_start_pfn
[j
];
985 unsigned long end_pfn
= node_end_pfn
[j
];
986 unsigned long nr_pages
= end_pfn
- start_pfn
;
988 ret
= gxio_trio_alloc_memory_maps(trio_context
, 1, 0,
991 pr_err("PCI: Mem-Map alloc failure on TRIO %d mac %d for MC %d, give up\n",
992 controller
->trio_index
, controller
->mac
,
995 goto alloc_mem_map_failed
;
998 controller
->mem_maps
[j
] = ret
;
1001 * Initialize the Mem-Map and the I/O MMU so that all
1002 * the physical memory can be accessed by the endpoint
1003 * devices. The base bus address is set to the base CPA
1004 * of this memory controller plus an offset (see pci.h).
1005 * The region's base VA is set to the base CPA. The
1006 * I/O MMU table essentially translates the CPA to
1007 * the real PA. Implicitly, for node 0, we create
1008 * a separate Mem-Map region that serves as the inbound
1009 * window for legacy 32-bit devices. This is a direct
1010 * map of the low 4GB CPA space.
1012 ret
= gxio_trio_init_memory_map_mmu_aux(trio_context
,
1013 controller
->mem_maps
[j
],
1014 start_pfn
<< PAGE_SHIFT
,
1015 nr_pages
<< PAGE_SHIFT
,
1018 (start_pfn
<< PAGE_SHIFT
) +
1019 TILE_PCI_MEM_MAP_BASE_OFFSET
,
1021 GXIO_TRIO_ORDER_MODE_UNORDERED
);
1023 pr_err("PCI: Mem-Map init failure on TRIO %d mac %d for MC %d, give up\n",
1024 controller
->trio_index
, controller
->mac
,
1027 goto alloc_mem_map_failed
;
1031 alloc_mem_map_failed
:
1035 pci_bus_add_devices(root_bus
);
1040 subsys_initcall(pcibios_init
);
1042 /* No bus fixups needed. */
1043 void pcibios_fixup_bus(struct pci_bus
*bus
)
1047 /* Process any "pci=" kernel boot arguments. */
1048 char *__init
pcibios_setup(char *str
)
1050 if (!strcmp(str
, "off")) {
1058 * Called for each device after PCI setup is done.
1059 * We initialize the PCI device capabilities conservatively, assuming that
1060 * all devices can only address the 32-bit DMA space. The exception here is
1061 * that the device dma_offset is set to the value that matches the 64-bit
1062 * capable devices. This is OK because dma_offset is not used by legacy
1063 * dma_ops, nor by the hybrid dma_ops's streaming DMAs, which are 64-bit ops.
1064 * This implementation matches the kernel design of setting PCI devices'
1065 * coherent_dma_mask to 0xffffffffull by default, allowing the device drivers
1066 * to skip calling pci_set_consistent_dma_mask(DMA_BIT_MASK(32)).
1068 static void pcibios_fixup_final(struct pci_dev
*pdev
)
1070 set_dma_ops(&pdev
->dev
, gx_legacy_pci_dma_map_ops
);
1071 set_dma_offset(&pdev
->dev
, TILE_PCI_MEM_MAP_BASE_OFFSET
);
1072 pdev
->dev
.archdata
.max_direct_dma_addr
=
1073 TILE_PCI_MAX_DIRECT_DMA_ADDRESS
;
1074 pdev
->dev
.coherent_dma_mask
= TILE_PCI_MAX_DIRECT_DMA_ADDRESS
;
1076 DECLARE_PCI_FIXUP_FINAL(PCI_ANY_ID
, PCI_ANY_ID
, pcibios_fixup_final
);
1078 /* Map a PCI MMIO bus address into VA space. */
1079 void __iomem
*ioremap(resource_size_t phys_addr
, unsigned long size
)
1081 struct pci_controller
*controller
= NULL
;
1082 resource_size_t bar_start
;
1083 resource_size_t bar_end
;
1084 resource_size_t offset
;
1085 resource_size_t start
;
1086 resource_size_t end
;
1091 end
= phys_addr
+ size
- 1;
1094 * By searching phys_addr in each controller's mem_space, we can
1095 * determine the controller that should accept the PCI memory access.
1097 for (i
= 0; i
< num_rc_controllers
; i
++) {
1099 * Skip controllers that are not properly initialized or
1102 if (pci_controllers
[i
].root_bus
== NULL
)
1105 bar_start
= pci_controllers
[i
].mem_space
.start
;
1106 bar_end
= pci_controllers
[i
].mem_space
.end
;
1108 if ((start
>= bar_start
) && (end
<= bar_end
)) {
1109 controller
= &pci_controllers
[i
];
1114 if (controller
== NULL
)
1117 trio_fd
= controller
->trio
->fd
;
1119 /* Convert the resource start to the bus address offset. */
1120 start
= phys_addr
- controller
->mem_offset
;
1122 offset
= HV_TRIO_PIO_OFFSET(controller
->pio_mem_index
) + start
;
1124 /* We need to keep the PCI bus address's in-page offset in the VA. */
1125 return iorpc_ioremap(trio_fd
, offset
, size
) +
1126 (start
& (PAGE_SIZE
- 1));
1128 EXPORT_SYMBOL(ioremap
);
1130 #ifdef CONFIG_TILE_PCI_IO
1131 /* Map a PCI I/O address into VA space. */
1132 void __iomem
*ioport_map(unsigned long port
, unsigned int size
)
1134 struct pci_controller
*controller
= NULL
;
1135 resource_size_t bar_start
;
1136 resource_size_t bar_end
;
1137 resource_size_t offset
;
1138 resource_size_t start
;
1139 resource_size_t end
;
1144 end
= port
+ size
- 1;
1147 * By searching the port in each controller's io_space, we can
1148 * determine the controller that should accept the PCI I/O access.
1150 for (i
= 0; i
< num_rc_controllers
; i
++) {
1152 * Skip controllers that are not properly initialized or
1155 if (pci_controllers
[i
].root_bus
== NULL
)
1158 bar_start
= pci_controllers
[i
].io_space
.start
;
1159 bar_end
= pci_controllers
[i
].io_space
.end
;
1161 if ((start
>= bar_start
) && (end
<= bar_end
)) {
1162 controller
= &pci_controllers
[i
];
1167 if (controller
== NULL
)
1170 trio_fd
= controller
->trio
->fd
;
1172 /* Convert the resource start to the bus address offset. */
1173 port
-= controller
->io_space
.start
;
1175 offset
= HV_TRIO_PIO_OFFSET(controller
->pio_io_index
) + port
;
1177 /* We need to keep the PCI bus address's in-page offset in the VA. */
1178 return iorpc_ioremap(trio_fd
, offset
, size
) + (port
& (PAGE_SIZE
- 1));
1180 EXPORT_SYMBOL(ioport_map
);
1182 void ioport_unmap(void __iomem
*addr
)
1186 EXPORT_SYMBOL(ioport_unmap
);
1189 void pci_iounmap(struct pci_dev
*dev
, void __iomem
*addr
)
1193 EXPORT_SYMBOL(pci_iounmap
);
1195 /****************************************************************
1197 * Tile PCI config space read/write routines
1199 ****************************************************************/
1202 * These are the normal read and write ops
1203 * These are expanded with macros from pci_bus_read_config_byte() etc.
1205 * devfn is the combined PCI device & function.
1207 * offset is in bytes, from the start of config space for the
1208 * specified bus & device.
1210 static int tile_cfg_read(struct pci_bus
*bus
, unsigned int devfn
, int offset
,
1213 struct pci_controller
*controller
= bus
->sysdata
;
1214 gxio_trio_context_t
*trio_context
= controller
->trio
;
1215 int busnum
= bus
->number
& 0xff;
1216 int device
= PCI_SLOT(devfn
);
1217 int function
= PCI_FUNC(devfn
);
1218 int config_type
= 1;
1219 TRIO_TILE_PIO_REGION_SETUP_CFG_ADDR_t cfg_addr
;
1223 * Map all accesses to the local device on root bus into the
1224 * MMIO space of the MAC. Accesses to the downstream devices
1225 * go to the PIO space.
1227 if (pci_is_root_bus(bus
)) {
1230 * This is the internal downstream P2P bridge,
1233 unsigned int reg_offset
;
1235 reg_offset
= ((offset
& 0xFFF) <<
1236 TRIO_CFG_REGION_ADDR__REG_SHIFT
) |
1237 (TRIO_CFG_REGION_ADDR__INTFC_VAL_MAC_PROTECTED
1238 << TRIO_CFG_REGION_ADDR__INTFC_SHIFT
) |
1240 TRIO_CFG_REGION_ADDR__MAC_SEL_SHIFT
);
1242 mmio_addr
= trio_context
->mmio_base_mac
+ reg_offset
;
1248 * We fake an empty device for (device > 0),
1249 * since there is only one device on bus 0.
1251 goto invalid_device
;
1256 * Accesses to the directly attached device have to be
1257 * sent as type-0 configs.
1259 if (busnum
== (controller
->first_busno
+ 1)) {
1261 * There is only one device off of our built-in P2P bridge.
1264 goto invalid_device
;
1270 cfg_addr
.reg_addr
= (offset
& 0xFFF);
1271 cfg_addr
.fn
= function
;
1272 cfg_addr
.dev
= device
;
1273 cfg_addr
.bus
= busnum
;
1274 cfg_addr
.type
= config_type
;
1277 * Note that we don't set the mac field in cfg_addr because the
1278 * mapping is per port.
1280 mmio_addr
= trio_context
->mmio_base_pio_cfg
[controller
->mac
] +
1287 *val
= __gxio_mmio_read32(mmio_addr
);
1291 *val
= __gxio_mmio_read16(mmio_addr
);
1295 *val
= __gxio_mmio_read8(mmio_addr
);
1299 return PCIBIOS_FUNC_NOT_SUPPORTED
;
1302 TRACE_CFG_RD(size
, *val
, busnum
, device
, function
, offset
);
1322 return PCIBIOS_FUNC_NOT_SUPPORTED
;
1330 * See tile_cfg_read() for relevent comments.
1331 * Note that "val" is the value to write, not a pointer to that value.
1333 static int tile_cfg_write(struct pci_bus
*bus
, unsigned int devfn
, int offset
,
1336 struct pci_controller
*controller
= bus
->sysdata
;
1337 gxio_trio_context_t
*trio_context
= controller
->trio
;
1338 int busnum
= bus
->number
& 0xff;
1339 int device
= PCI_SLOT(devfn
);
1340 int function
= PCI_FUNC(devfn
);
1341 int config_type
= 1;
1342 TRIO_TILE_PIO_REGION_SETUP_CFG_ADDR_t cfg_addr
;
1344 u32 val_32
= (u32
)val
;
1345 u16 val_16
= (u16
)val
;
1349 * Map all accesses to the local device on root bus into the
1350 * MMIO space of the MAC. Accesses to the downstream devices
1351 * go to the PIO space.
1353 if (pci_is_root_bus(bus
)) {
1356 * This is the internal downstream P2P bridge,
1359 unsigned int reg_offset
;
1361 reg_offset
= ((offset
& 0xFFF) <<
1362 TRIO_CFG_REGION_ADDR__REG_SHIFT
) |
1363 (TRIO_CFG_REGION_ADDR__INTFC_VAL_MAC_PROTECTED
1364 << TRIO_CFG_REGION_ADDR__INTFC_SHIFT
) |
1366 TRIO_CFG_REGION_ADDR__MAC_SEL_SHIFT
);
1368 mmio_addr
= trio_context
->mmio_base_mac
+ reg_offset
;
1374 * We fake an empty device for (device > 0),
1375 * since there is only one device on bus 0.
1377 goto invalid_device
;
1382 * Accesses to the directly attached device have to be
1383 * sent as type-0 configs.
1385 if (busnum
== (controller
->first_busno
+ 1)) {
1387 * There is only one device off of our built-in P2P bridge.
1390 goto invalid_device
;
1396 cfg_addr
.reg_addr
= (offset
& 0xFFF);
1397 cfg_addr
.fn
= function
;
1398 cfg_addr
.dev
= device
;
1399 cfg_addr
.bus
= busnum
;
1400 cfg_addr
.type
= config_type
;
1403 * Note that we don't set the mac field in cfg_addr because the
1404 * mapping is per port.
1406 mmio_addr
= trio_context
->mmio_base_pio_cfg
[controller
->mac
] +
1413 __gxio_mmio_write32(mmio_addr
, val_32
);
1414 TRACE_CFG_WR(size
, val_32
, busnum
, device
, function
, offset
);
1418 __gxio_mmio_write16(mmio_addr
, val_16
);
1419 TRACE_CFG_WR(size
, val_16
, busnum
, device
, function
, offset
);
1423 __gxio_mmio_write8(mmio_addr
, val_8
);
1424 TRACE_CFG_WR(size
, val_8
, busnum
, device
, function
, offset
);
1428 return PCIBIOS_FUNC_NOT_SUPPORTED
;
1437 static struct pci_ops tile_cfg_ops
= {
1438 .read
= tile_cfg_read
,
1439 .write
= tile_cfg_write
,
1443 /* MSI support starts here. */
1444 static unsigned int tilegx_msi_startup(struct irq_data
*d
)
1446 if (irq_data_get_msi_desc(d
))
1447 pci_msi_unmask_irq(d
);
1452 static void tilegx_msi_ack(struct irq_data
*d
)
1454 __insn_mtspr(SPR_IPI_EVENT_RESET_K
, 1UL << d
->irq
);
1457 static void tilegx_msi_mask(struct irq_data
*d
)
1459 pci_msi_mask_irq(d
);
1460 __insn_mtspr(SPR_IPI_MASK_SET_K
, 1UL << d
->irq
);
1463 static void tilegx_msi_unmask(struct irq_data
*d
)
1465 __insn_mtspr(SPR_IPI_MASK_RESET_K
, 1UL << d
->irq
);
1466 pci_msi_unmask_irq(d
);
1469 static struct irq_chip tilegx_msi_chip
= {
1470 .name
= "tilegx_msi",
1471 .irq_startup
= tilegx_msi_startup
,
1472 .irq_ack
= tilegx_msi_ack
,
1473 .irq_mask
= tilegx_msi_mask
,
1474 .irq_unmask
= tilegx_msi_unmask
,
1476 /* TBD: support set_affinity. */
1479 int arch_setup_msi_irq(struct pci_dev
*pdev
, struct msi_desc
*desc
)
1481 struct pci_controller
*controller
;
1482 gxio_trio_context_t
*trio_context
;
1485 uint64_t mem_map_base
;
1486 uint64_t mem_map_limit
;
1493 irq
= irq_alloc_hwirq(-1);
1498 * Since we use a 64-bit Mem-Map to accept the MSI write, we fail
1499 * devices that are not capable of generating a 64-bit message address.
1500 * These devices will fall back to using the legacy interrupts.
1501 * Most PCIe endpoint devices do support 64-bit message addressing.
1503 if (desc
->msi_attrib
.is_64
== 0) {
1504 dev_info(&pdev
->dev
, "64-bit MSI message address not supported, falling back to legacy interrupts\n");
1510 default_irq
= desc
->msi_attrib
.default_irq
;
1511 controller
= irq_get_handler_data(default_irq
);
1513 BUG_ON(!controller
);
1515 trio_context
= controller
->trio
;
1518 * Allocate a scatter-queue that will accept the MSI write and
1519 * trigger the TILE-side interrupts. We use the scatter-queue regions
1520 * before the mem map regions, because the latter are needed by more
1523 mem_map
= gxio_trio_alloc_scatter_queues(trio_context
, 1, 0, 0);
1525 TRIO_MAP_SQ_DOORBELL_FMT_t doorbell_template
= {{
1530 mem_map
+= TRIO_NUM_MAP_MEM_REGIONS
;
1531 mem_map_base
= MEM_MAP_INTR_REGIONS_BASE
+
1532 mem_map
* MEM_MAP_INTR_REGION_SIZE
;
1533 mem_map_limit
= mem_map_base
+ MEM_MAP_INTR_REGION_SIZE
- 1;
1535 msi_addr
= mem_map_base
+ MEM_MAP_INTR_REGION_SIZE
- 8;
1536 msg
.data
= (unsigned int)doorbell_template
.word
;
1538 /* SQ regions are out, allocate from map mem regions. */
1539 mem_map
= gxio_trio_alloc_memory_maps(trio_context
, 1, 0, 0);
1541 dev_info(&pdev
->dev
, "%s Mem-Map alloc failure - failed to initialize MSI interrupts - falling back to legacy interrupts\n",
1542 desc
->msi_attrib
.is_msix
? "MSI-X" : "MSI");
1544 goto msi_mem_map_alloc_failure
;
1547 mem_map_base
= MEM_MAP_INTR_REGIONS_BASE
+
1548 mem_map
* MEM_MAP_INTR_REGION_SIZE
;
1549 mem_map_limit
= mem_map_base
+ MEM_MAP_INTR_REGION_SIZE
- 1;
1551 msi_addr
= mem_map_base
+ TRIO_MAP_MEM_REG_INT3
-
1552 TRIO_MAP_MEM_REG_INT0
;
1557 /* We try to distribute different IRQs to different tiles. */
1558 cpu
= tile_irq_cpu(irq
);
1561 * Now call up to the HV to configure the MSI interrupt and
1562 * set up the IPI binding.
1564 ret
= gxio_trio_config_msi_intr(trio_context
, cpu_x(cpu
), cpu_y(cpu
),
1565 KERNEL_PL
, irq
, controller
->mac
,
1566 mem_map
, mem_map_base
, mem_map_limit
,
1567 trio_context
->asid
);
1569 dev_info(&pdev
->dev
, "HV MSI config failed\n");
1571 goto hv_msi_config_failure
;
1574 irq_set_msi_desc(irq
, desc
);
1576 msg
.address_hi
= msi_addr
>> 32;
1577 msg
.address_lo
= msi_addr
& 0xffffffff;
1579 pci_write_msi_msg(irq
, &msg
);
1580 irq_set_chip_and_handler(irq
, &tilegx_msi_chip
, handle_level_irq
);
1581 irq_set_handler_data(irq
, controller
);
1585 hv_msi_config_failure
:
1587 msi_mem_map_alloc_failure
:
1589 irq_free_hwirq(irq
);
1593 void arch_teardown_msi_irq(unsigned int irq
)
1595 irq_free_hwirq(irq
);