/** * struct iproc_msi_grp - iProc MSI group * * One MSI group is allocated per GIC interrupt, serviced by one iProc MSI * event queue. * * @msi: pointer to iProc MSI data * @gic_irq: GIC interrupt * @eq: Event queue number
*/ struct iproc_msi_grp { struct iproc_msi *msi; int gic_irq; unsignedint eq;
};
/** * struct iproc_msi - iProc event queue based MSI * * Only meant to be used on platforms without MSI support integrated into the * GIC. * * @pcie: pointer to iProc PCIe data * @reg_offsets: MSI register offsets * @grps: MSI groups * @nr_irqs: number of total interrupts connected to GIC * @nr_cpus: number of toal CPUs * @has_inten_reg: indicates the MSI interrupt enable register needs to be * set explicitly (required for some legacy platforms) * @bitmap: MSI vector bitmap * @bitmap_lock: lock to protect access to the MSI bitmap * @nr_msi_vecs: total number of MSI vectors * @inner_domain: inner IRQ domain * @nr_eq_region: required number of 4K aligned memory region for MSI event * queues * @nr_msi_region: required number of 4K aligned address region for MSI posted * writes * @eq_cpu: pointer to allocated memory region for MSI event queues * @eq_dma: DMA address of MSI event queues * @msi_addr: MSI address
*/ struct iproc_msi { struct iproc_pcie *pcie; const u16 (*reg_offsets)[IPROC_MSI_REG_SIZE]; struct iproc_msi_grp *grps; int nr_irqs; int nr_cpus; bool has_inten_reg; unsignedlong *bitmap; struct mutex bitmap_lock; unsignedint nr_msi_vecs; struct irq_domain *inner_domain; unsignedint nr_eq_region; unsignedint nr_msi_region; void *eq_cpu;
dma_addr_t eq_dma;
phys_addr_t msi_addr;
};
staticstruct msi_parent_ops iproc_msi_parent_ops = {
.required_flags = IPROC_MSI_FLAGS_REQUIRED,
.supported_flags = IPROC_MSI_FLAGS_SUPPORTED,
.bus_select_token = DOMAIN_BUS_PCI_MSI,
.prefix = "iProc-",
.init_dev_msi_info = msi_lib_init_dev_msi_info,
}; /* * In iProc PCIe core, each MSI group is serviced by a GIC interrupt and a * dedicated event queue. Each MSI group can support up to 64 MSI vectors. * * The number of MSI groups varies between different iProc SoCs. The total * number of CPU cores also varies. To support MSI IRQ affinity, we * distribute GIC interrupts across all available CPUs. MSI vector is moved * from one GIC interrupt to another to steer to the target CPU. * * Assuming: * - the number of MSI groups is M * - the number of CPU cores is N * - M is always a multiple of N * * Total number of raw MSI vectors = M * 64 * Total number of supported MSI vectors = (M * 64) / N
*/ staticinlineint hwirq_to_cpu(struct iproc_msi *msi, unsignedlong hwirq)
{ return (hwirq % msi->nr_cpus);
}
if (msi->nr_cpus > 1 && nr_irqs > 1) return -EINVAL;
mutex_lock(&msi->bitmap_lock);
/* * Allocate 'nr_irqs' multiplied by 'nr_cpus' number of MSI vectors * each time
*/
hwirq = bitmap_find_free_region(msi->bitmap, msi->nr_msi_vecs,
order_base_2(msi->nr_cpus * nr_irqs));
mutex_unlock(&msi->bitmap_lock);
if (hwirq < 0) return -ENOSPC;
for (i = 0; i < nr_irqs; i++) {
irq_domain_set_info(domain, virq + i, hwirq + i,
&iproc_msi_bottom_irq_chip,
domain->host_data, handle_simple_irq,
NULL, NULL);
}
/* * Since we have multiple hwirq mapped to a single MSI vector, * now we need to derive the hwirq at CPU0. It can then be used to * mapped back to virq.
*/ return hwirq_to_canonical_hwirq(msi, hwirq);
}
/* * iProc MSI event queue is tracked by head and tail pointers. Head * pointer indicates the next entry (MSI data) to be consumed by SW in * the queue and needs to be updated by SW. iProc MSI core uses the * tail pointer as the next data insertion point. * * Entries between head and tail pointers contain valid MSI data. MSI * data is guaranteed to be in the event queue memory before the tail * pointer is updated by the iProc MSI core.
*/
head = iproc_msi_read_reg(msi, IPROC_MSI_EQ_HEAD,
eq) & IPROC_MSI_EQ_MASK; do {
tail = iproc_msi_read_reg(msi, IPROC_MSI_EQ_TAIL,
eq) & IPROC_MSI_EQ_MASK;
/* * Figure out total number of events (MSI data) to be * processed.
*/
nr_events = (tail < head) ?
(EQ_LEN - (head - tail)) : (tail - head); if (!nr_events) break;
/* process all outstanding events */ while (nr_events--) {
hwirq = decode_msi_hwirq(msi, eq, head);
generic_handle_domain_irq(msi->inner_domain, hwirq);
head++;
head %= EQ_LEN;
}
/* * Now all outstanding events have been processed. Update the * head pointer.
*/
iproc_msi_write_reg(msi, IPROC_MSI_EQ_HEAD, eq, head);
/* * Now go read the tail pointer again to see if there are new * outstanding events that came in during the above window.
*/
} while (true);
chained_irq_exit(chip, desc);
}
staticvoid iproc_msi_enable(struct iproc_msi *msi)
{ int i, eq;
u32 val;
/* Program memory region for each event queue */ for (i = 0; i < msi->nr_eq_region; i++) {
dma_addr_t addr = msi->eq_dma + (i * EQ_MEM_REGION_SIZE);
iproc_msi_write_reg(msi, IPROC_MSI_EQ_PAGE, i,
lower_32_bits(addr));
iproc_msi_write_reg(msi, IPROC_MSI_EQ_PAGE_UPPER, i,
upper_32_bits(addr));
}
/* Program address region for MSI posted writes */ for (i = 0; i < msi->nr_msi_region; i++) {
phys_addr_t addr = msi->msi_addr + (i * MSI_MEM_REGION_SIZE);
iproc_msi_write_reg(msi, IPROC_MSI_PAGE, i,
lower_32_bits(addr));
iproc_msi_write_reg(msi, IPROC_MSI_PAGE_UPPER, i,
upper_32_bits(addr));
}
/* * Some legacy platforms require the MSI interrupt enable * register to be set explicitly.
*/ if (msi->has_inten_reg) {
val = iproc_msi_read_reg(msi, IPROC_MSI_INTS_EN, eq);
val |= BIT(eq);
iproc_msi_write_reg(msi, IPROC_MSI_INTS_EN, eq, val);
}
}
}
msi->inner_domain = msi_create_parent_irq_domain(&info, &iproc_msi_parent_ops); if (!msi->inner_domain) return -ENOMEM;
return 0;
}
staticvoid iproc_msi_free_domains(struct iproc_msi *msi)
{ if (msi->inner_domain)
irq_domain_remove(msi->inner_domain);
}
staticvoid iproc_msi_irq_free(struct iproc_msi *msi, unsignedint cpu)
{ int i;
for (i = cpu; i < msi->nr_irqs; i += msi->nr_cpus) {
irq_set_chained_handler_and_data(msi->grps[i].gic_irq,
NULL, NULL);
}
}
staticint iproc_msi_irq_setup(struct iproc_msi *msi, unsignedint cpu)
{ int i, ret;
cpumask_var_t mask; struct iproc_pcie *pcie = msi->pcie;
for (i = cpu; i < msi->nr_irqs; i += msi->nr_cpus) {
irq_set_chained_handler_and_data(msi->grps[i].gic_irq,
iproc_msi_handler,
&msi->grps[i]); /* Dedicate GIC interrupt to each CPU core */ if (alloc_cpumask_var(&mask, GFP_KERNEL)) {
cpumask_clear(mask);
cpumask_set_cpu(cpu, mask);
ret = irq_set_affinity(msi->grps[i].gic_irq, mask); if (ret)
dev_err(pcie->dev, "failed to set affinity for IRQ%d\n",
msi->grps[i].gic_irq);
free_cpumask_var(mask);
} else {
dev_err(pcie->dev, "failed to alloc CPU mask\n");
ret = -EINVAL;
}
if (ret) { /* Free all configured/unconfigured IRQs */
iproc_msi_irq_free(msi, cpu); return ret;
}
}
return 0;
}
int iproc_msi_init(struct iproc_pcie *pcie, struct device_node *node)
{ struct iproc_msi *msi; int i, ret; unsignedint cpu;
if (!of_device_is_compatible(node, "brcm,iproc-msi")) return -ENODEV;
if (!of_property_read_bool(node, "msi-controller")) return -ENODEV;
if (pcie->msi) return -EBUSY;
msi = devm_kzalloc(pcie->dev, sizeof(*msi), GFP_KERNEL); if (!msi) return -ENOMEM;
msi->grps = devm_kcalloc(pcie->dev, msi->nr_irqs, sizeof(*msi->grps),
GFP_KERNEL); if (!msi->grps) return -ENOMEM;
for (i = 0; i < msi->nr_irqs; i++) { unsignedint irq = irq_of_parse_and_map(node, i);
if (!irq) {
dev_err(pcie->dev, "unable to parse/map interrupt\n");
ret = -ENODEV; goto free_irqs;
}
msi->grps[i].gic_irq = irq;
msi->grps[i].msi = msi;
msi->grps[i].eq = i;
}
/* Reserve memory for event queue and make sure memories are zeroed */
msi->eq_cpu = dma_alloc_coherent(pcie->dev,
msi->nr_eq_region * EQ_MEM_REGION_SIZE,
&msi->eq_dma, GFP_KERNEL); if (!msi->eq_cpu) {
ret = -ENOMEM; goto free_irqs;
}
ret = iproc_msi_alloc_domains(node, msi); if (ret) {
dev_err(pcie->dev, "failed to create MSI domains\n"); goto free_eq_dma;
}
for_each_online_cpu(cpu) {
ret = iproc_msi_irq_setup(msi, cpu); if (ret) goto free_msi_irq;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.