* [PATCH 2/4 V6] MSI support on 83xx/85xx/86xx board
2008-05-20 8:07 [PATCH 1/4 V4] " Jason Jin
@ 2008-05-20 8:07 ` Jason Jin
0 siblings, 0 replies; 14+ messages in thread
From: Jason Jin @ 2008-05-20 8:07 UTC (permalink / raw)
To: galak; +Cc: linuxppc-dev, Jason Jin
This MSI driver can be used on 83xx/85xx/86xx board.
In this driver, virtual interrupt host and chip were
setup. There are 256 MSI interrupts in this host, Every 32
MSI interrupts cascaded to one IPIC/MPIC interrupt.
The chip was treated as edge sensitive and some necessary
functions were setup for this chip.
Before using the MSI interrupt, PCI/PCIE device need to
ask for a MSI interrupt in the 256 MSI interrupts. A 256bit
bitmap show which MSI interrupt was used, reserve bit in
the bitmap can be used to force the device use some designate
MSI interrupt in the 256 MSI interrupts. Sometimes this is useful
for testing the all the MSI interrupts. The msi-available-ranges
property in the dts file was used for this purpose.
Signed-off-by: Jason Jin <Jason.jin@freescale.com>
---
In this V6 version,
change the compatible according to the change in dts
arch/powerpc/sysdev/Makefile | 3 +-
arch/powerpc/sysdev/fsl_msi.c | 436 +++++++++++++++++++++++++++++++++++++++++
arch/powerpc/sysdev/fsl_msi.h | 42 ++++
arch/powerpc/sysdev/fsl_pci.c | 14 ++
4 files changed, 494 insertions(+), 1 deletions(-)
create mode 100644 arch/powerpc/sysdev/fsl_msi.c
create mode 100644 arch/powerpc/sysdev/fsl_msi.h
diff --git a/arch/powerpc/sysdev/Makefile b/arch/powerpc/sysdev/Makefile
index 2cc5052..dd6dff3 100644
--- a/arch/powerpc/sysdev/Makefile
+++ b/arch/powerpc/sysdev/Makefile
@@ -4,6 +4,7 @@ endif
mpic-msi-obj-$(CONFIG_PCI_MSI) += mpic_msi.o mpic_u3msi.o mpic_pasemi_msi.o
obj-$(CONFIG_MPIC) += mpic.o $(mpic-msi-obj-y)
+fsl-msi-obj-$(CONFIG_PCI_MSI) += fsl_msi.o
obj-$(CONFIG_PPC_MPC106) += grackle.o
obj-$(CONFIG_PPC_DCR_NATIVE) += dcr-low.o
@@ -11,7 +12,7 @@ obj-$(CONFIG_PPC_PMI) += pmi.o
obj-$(CONFIG_U3_DART) += dart_iommu.o
obj-$(CONFIG_MMIO_NVRAM) += mmio_nvram.o
obj-$(CONFIG_FSL_SOC) += fsl_soc.o
-obj-$(CONFIG_FSL_PCI) += fsl_pci.o
+obj-$(CONFIG_FSL_PCI) += fsl_pci.o $(fsl-msi-obj-y)
obj-$(CONFIG_FSL_LBC) += fsl_lbc.o
obj-$(CONFIG_RAPIDIO) += fsl_rio.o
obj-$(CONFIG_TSI108_BRIDGE) += tsi108_pci.o tsi108_dev.o
diff --git a/arch/powerpc/sysdev/fsl_msi.c b/arch/powerpc/sysdev/fsl_msi.c
new file mode 100644
index 0000000..9d0685b
--- /dev/null
+++ b/arch/powerpc/sysdev/fsl_msi.c
@@ -0,0 +1,436 @@
+/*
+ * Copyright (C) 2007-2008 Freescale Semiconductor, Inc. All rights reserved.
+ *
+ * Author: Tony Li <tony.li@freescale.com>
+ * Jason Jin <Jason.jin@freescale.com>
+ *
+ * The hwirq alloc and free code reuse from sysdev/mpic_msi.c
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; version 2 of the
+ * License.
+ *
+ */
+#include <linux/irq.h>
+#include <linux/bootmem.h>
+#include <linux/bitmap.h>
+#include <linux/msi.h>
+#include <linux/pci.h>
+#include <linux/of_platform.h>
+#include <sysdev/fsl_soc.h>
+#include <asm/prom.h>
+#include <asm/hw_irq.h>
+#include <asm/ppc-pci.h>
+#include "fsl_msi.h"
+
+struct fsl_msi_feature {
+ u32 fsl_pic_ip;
+ u32 msiir_offset;
+};
+
+static struct fsl_msi *fsl_msi;
+
+static inline u32 fsl_msi_read(u32 __iomem *base, unsigned int reg)
+{
+ return in_be32(base + (reg >> 2));
+}
+
+static inline void fsl_msi_write(u32 __iomem *base,
+ unsigned int reg, u32 value)
+{
+ out_be32(base + (reg >> 2), value);
+}
+
+/*
+ * We do not need this actually. The MSIR register has been read once
+ * in the cascade interrupt. So, this MSI interrupt has been acked
+*/
+static void fsl_msi_end_irq(unsigned int virq)
+{
+}
+
+static struct irq_chip fsl_msi_chip = {
+ .mask = mask_msi_irq,
+ .unmask = unmask_msi_irq,
+ .ack = fsl_msi_end_irq,
+ .typename = " FSL-MSI ",
+};
+
+static int fsl_msi_host_map(struct irq_host *h, unsigned int virq,
+ irq_hw_number_t hw)
+{
+ struct irq_chip *chip = &fsl_msi_chip;
+
+ get_irq_desc(virq)->status |= IRQ_TYPE_EDGE_FALLING;
+
+ set_irq_chip_and_handler(virq, chip, handle_edge_irq);
+
+ return 0;
+}
+
+static struct irq_host_ops fsl_msi_host_ops = {
+ .map = fsl_msi_host_map,
+};
+
+irq_hw_number_t fsl_msi_alloc_hwirqs(struct fsl_msi *msi, int num)
+{
+ unsigned long flags;
+ int offset, order = get_count_order(num);
+
+ spin_lock_irqsave(&msi->bitmap_lock, flags);
+
+ offset = bitmap_find_free_region(msi->fsl_msi_bitmap,
+ NR_MSI_IRQS, order);
+
+ spin_unlock_irqrestore(&msi->bitmap_lock, flags);
+
+ pr_debug("%s: allocated 0x%x (2^%d) at offset 0x%x\n",
+ __func__, num, order, offset);
+
+ return offset;
+}
+
+void fsl_msi_free_hwirqs(struct fsl_msi *msi, int offset, int num)
+{
+ unsigned long flags;
+ int order = get_count_order(num);
+
+ pr_debug("%s: freeing 0x%x (2^%d) at offset 0x%x\n",
+ __func__, num, order, offset);
+
+ spin_lock_irqsave(&msi->bitmap_lock, flags);
+ bitmap_release_region(msi->fsl_msi_bitmap, offset, order);
+ spin_unlock_irqrestore(&msi->bitmap_lock, flags);
+}
+
+static int fsl_msi_free_dt_hwirqs(struct fsl_msi *msi)
+{
+ int i, len;
+ const u32 *p;
+
+ bitmap_allocate_region(msi->fsl_msi_bitmap, 0,
+ get_count_order(NR_MSI_IRQS));
+
+ p = of_get_property(msi->of_node, "msi-available-ranges", &len);
+
+ if (!p) {
+ /* No msi-available-ranges property,
+ * All the 256 MSI interrupts can be used
+ */
+ fsl_msi_free_hwirqs(msi, 0, 0x100);
+ return 0;
+ }
+
+ if ((len % (2 * sizeof(u32))) != 0) {
+ printk(KERN_WARNING "fsl_msi: Malformed msi-available-ranges "
+ "property on %s\n", msi->of_node->full_name);
+ return -EINVAL;
+ }
+
+ /* Format is: (<u32 start> <u32 count>)+ */
+ len /= 2 * sizeof(u32);
+ for (i = 0; i < len; i++, p += 2)
+ fsl_msi_free_hwirqs(msi, *p, *(p + 1));
+
+ return 0;
+}
+
+static int fsl_msi_init_allocator(struct fsl_msi *msi_data)
+{
+ int rc, size;
+
+ size = BITS_TO_LONGS(NR_MSI_IRQS) * sizeof(u32);
+
+ msi_data->fsl_msi_bitmap = kzalloc(size, GFP_KERNEL);
+
+ if (msi_data->fsl_msi_bitmap == NULL) {
+ pr_debug("%s: ENOMEM allocating allocator bitmap!\n",
+ __func__);
+ return -ENOMEM;
+ }
+
+ rc = fsl_msi_free_dt_hwirqs(msi_data);
+ if (rc)
+ goto out_free;
+
+ return 0;
+out_free:
+ kfree(msi_data->fsl_msi_bitmap);
+
+ msi_data->fsl_msi_bitmap = NULL;
+ return rc;
+
+}
+
+static int fsl_msi_check_device(struct pci_dev *pdev, int nvec, int type)
+{
+ if (type == PCI_CAP_ID_MSIX)
+ pr_debug("fslmsi: MSI-X untested, trying anyway.\n");
+
+ return 0;
+}
+
+static void fsl_teardown_msi_irqs(struct pci_dev *pdev)
+{
+ struct msi_desc *entry;
+ struct fsl_msi *msi_data = fsl_msi;
+
+ list_for_each_entry(entry, &pdev->msi_list, list) {
+ if (entry->irq == NO_IRQ)
+ continue;
+ set_irq_msi(entry->irq, NULL);
+ fsl_msi_free_hwirqs(msi_data, virq_to_hw(entry->irq), 1);
+ irq_dispose_mapping(entry->irq);
+ }
+
+ return;
+}
+
+static void fsl_compose_msi_msg(struct pci_dev *pdev, int hwirq,
+ struct msi_msg *msg)
+{
+ struct fsl_msi *msi_data = fsl_msi;
+
+ msg->address_lo = msi_data->msi_addr_lo;
+ msg->address_hi = msi_data->msi_addr_hi;
+ msg->data = hwirq;
+
+ pr_debug("%s: allocated srs: %d, ibs: %d\n",
+ __func__, hwirq / IRQS_PER_MSI_REG, hwirq % IRQS_PER_MSI_REG);
+}
+
+static int fsl_setup_msi_irqs(struct pci_dev *pdev, int nvec, int type)
+{
+ irq_hw_number_t hwirq;
+ int rc;
+ unsigned int virq;
+ struct msi_desc *entry;
+ struct msi_msg msg;
+ struct fsl_msi *msi_data = fsl_msi;
+
+ list_for_each_entry(entry, &pdev->msi_list, list) {
+ hwirq = fsl_msi_alloc_hwirqs(msi_data, 1);
+ if (hwirq < 0) {
+ rc = hwirq;
+ pr_debug("%s: fail allocating msi interrupt\n",
+ __func__);
+ goto out_free;
+ }
+
+ virq = irq_create_mapping(msi_data->irqhost, hwirq);
+
+ if (virq == NO_IRQ) {
+ pr_debug("%s: fail mapping hwirq 0x%lx\n",
+ __func__, hwirq);
+ fsl_msi_free_hwirqs(msi_data, hwirq, 1);
+ rc = -ENOSPC;
+ goto out_free;
+ }
+ set_irq_msi(virq, entry);
+
+ fsl_compose_msi_msg(pdev, hwirq, &msg);
+ write_msi_msg(virq, &msg);
+ }
+ return 0;
+
+out_free:
+ return rc;
+}
+
+void fsl_msi_cascade(unsigned int irq, struct irq_desc *desc)
+{
+ unsigned int cascade_irq;
+ struct fsl_msi *msi_data = fsl_msi;
+ int msir_index = -1;
+ u32 msir_value = 0;
+ u32 intr_index;
+ u32 have_shift = 0;
+
+ spin_lock(&desc->lock);
+ if ((msi_data->feature & FSL_PIC_IP_MASK) == FSL_PIC_IP_IPIC) {
+ if (desc->chip->mask_ack)
+ desc->chip->mask_ack(irq);
+ else {
+ desc->chip->mask(irq);
+ desc->chip->ack(irq);
+ }
+ }
+
+ if (unlikely(desc->status & IRQ_INPROGRESS))
+ goto unlock;
+
+ msir_index = (int)(desc->handler_data);
+
+ if (msir_index >= NR_MSI_REG)
+ cascade_irq = NO_IRQ;
+
+ desc->status |= IRQ_INPROGRESS;
+ switch (fsl_msi->feature & FSL_PIC_IP_MASK) {
+ case FSL_PIC_IP_MPIC:
+ msir_value = fsl_msi_read(msi_data->msi_regs,
+ msir_index * 0x10);
+ break;
+ case FSL_PIC_IP_IPIC:
+ msir_value = fsl_msi_read(msi_data->msi_regs, msir_index * 0x4);
+ break;
+ }
+
+ while (msir_value) {
+ intr_index = ffs(msir_value) - 1;
+
+ cascade_irq = irq_linear_revmap(msi_data->irqhost,
+ (msir_index * IRQS_PER_MSI_REG +
+ intr_index + have_shift));
+ if (cascade_irq != NO_IRQ)
+ generic_handle_irq(cascade_irq);
+ have_shift += (intr_index + 1);
+ msir_value = (msir_value >> (intr_index + 1));
+ }
+ desc->status &= ~IRQ_INPROGRESS;
+
+ switch (msi_data->feature & FSL_PIC_IP_MASK) {
+ case FSL_PIC_IP_MPIC:
+ desc->chip->eoi(irq);
+ break;
+ case FSL_PIC_IP_IPIC:
+ if (!(desc->status & IRQ_DISABLED) && desc->chip->unmask)
+ desc->chip->unmask(irq);
+ break;
+ }
+unlock:
+ spin_unlock(&desc->lock);
+}
+
+static int __devinit fsl_of_msi_probe(struct of_device *dev,
+ const struct of_device_id *match)
+{
+ struct fsl_msi *msi;
+ struct resource res;
+ int err, i, count;
+ int rc;
+ int virt_msir;
+ const u32 *p;
+ struct fsl_msi_feature *tmp_data;
+
+ printk(KERN_DEBUG "Setting up Freescale MSI support\n");
+
+ msi = kzalloc(sizeof(struct fsl_msi), GFP_KERNEL);
+ if (!msi) {
+ dev_err(&dev->dev, "No memory for MSI structure\n");
+ err = -ENOMEM;
+ goto error_out;
+ }
+
+ msi->of_node = of_node_get(dev->node);
+
+ msi->irqhost = irq_alloc_host(of_node_get(dev->node),
+ IRQ_HOST_MAP_LINEAR,
+ NR_MSI_IRQS, &fsl_msi_host_ops, 0);
+ if (msi->irqhost == NULL) {
+ dev_err(&dev->dev, "No memory for MSI irqhost\n");
+ of_node_put(dev->node);
+ err = -ENOMEM;
+ goto error_out;
+ }
+
+ /* Get the MSI reg base */
+ err = of_address_to_resource(dev->node, 0, &res);
+ if (err) {
+ dev_err(&dev->dev, "%s resource error!\n",
+ dev->node->full_name);
+ goto error_out;
+ }
+
+ msi->msi_regs = ioremap(res.start, res.end - res.start + 1);
+ if (!msi->msi_regs) {
+ dev_err(&dev->dev, "ioremap problem failed\n");
+ goto error_out;
+ }
+
+ tmp_data = (struct fsl_msi_feature *)match->data;
+
+ msi->feature = tmp_data->fsl_pic_ip;
+
+ msi->irqhost->host_data = msi;
+
+ msi->msi_addr_hi = 0x0;
+ msi->msi_addr_lo = res.start + tmp_data->msiir_offset;
+
+ rc = fsl_msi_init_allocator(msi);
+ if (rc) {
+ dev_err(&dev->dev, "Error allocating MSI bitmap\n");
+ goto error_out;
+ }
+
+ p = of_get_property(dev->node, "interrupts", &count);
+ if (!p) {
+ dev_err(&dev->dev, "no interrupts property found on %s\n",
+ dev->node->full_name);
+ err = -ENODEV;
+ goto error_out;
+ }
+ if (count % 8 != 0) {
+ dev_err(&dev->dev, "Malformed interrupts property on %s\n",
+ dev->node->full_name);
+ err = -EINVAL;
+ goto error_out;
+ }
+
+ count /= sizeof(u32);
+ for (i = 0; i < count / 2; i++) {
+ if (i > NR_MSI_REG)
+ break;
+ virt_msir = irq_of_parse_and_map(dev->node, i);
+ if (virt_msir != NO_IRQ) {
+ set_irq_data(virt_msir, (void *)i);
+ set_irq_chained_handler(virt_msir, fsl_msi_cascade);
+ }
+ }
+
+ fsl_msi = msi;
+
+ WARN_ON(ppc_md.setup_msi_irqs);
+ ppc_md.setup_msi_irqs = fsl_setup_msi_irqs;
+ ppc_md.teardown_msi_irqs = fsl_teardown_msi_irqs;
+ ppc_md.msi_check_device = fsl_msi_check_device;
+ return 0;
+error_out:
+ kfree(msi);
+ return err;
+}
+
+static const struct fsl_msi_feature mpic_msi_feature = {
+ .fsl_pic_ip = FSL_PIC_IP_MPIC,
+ .msiir_offset = 0x140,
+};
+
+static const struct fsl_msi_feature ipic_msi_feature = {
+ .fsl_pic_ip = FSL_PIC_IP_IPIC,
+ .msiir_offset = 0x38,
+};
+
+static const struct of_device_id fsl_of_msi_ids[] = {
+ {
+ .compatible = "fsl,mpic-msi",
+ .data = (void *)&mpic_msi_feature,
+ },
+ {
+ .compatible = "fsl,ipic-msi",
+ .data = (void *)&ipic_msi_feature,
+ },
+ {}
+};
+
+static struct of_platform_driver fsl_of_msi_driver = {
+ .name = "fsl-msi",
+ .match_table = fsl_of_msi_ids,
+ .probe = fsl_of_msi_probe,
+};
+
+static __init int fsl_of_msi_init(void)
+{
+ return of_register_platform_driver(&fsl_of_msi_driver);
+}
+
+subsys_initcall(fsl_of_msi_init);
diff --git a/arch/powerpc/sysdev/fsl_msi.h b/arch/powerpc/sysdev/fsl_msi.h
new file mode 100644
index 0000000..a653468
--- /dev/null
+++ b/arch/powerpc/sysdev/fsl_msi.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2007-2008 Freescale Semiconductor, Inc. All rights reserved.
+ *
+ * Author: Tony Li <tony.li@freescale.com>
+ * Jason Jin <Jason.jin@freescale.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; version 2 of the
+ * License.
+ *
+ */
+#ifndef _POWERPC_SYSDEV_FSL_MSI_H
+#define _POWERPC_SYSDEV_FSL_MSI_H
+
+#define NR_MSI_REG 8
+#define IRQS_PER_MSI_REG 32
+#define NR_MSI_IRQS (NR_MSI_REG * IRQS_PER_MSI_REG)
+
+#define FSL_PIC_IP_MASK 0x0000000F
+#define FSL_PIC_IP_MPIC 0x00000001
+#define FSL_PIC_IP_IPIC 0x00000002
+
+struct fsl_msi {
+ /* Device node of the MSI interrupt*/
+ struct device_node *of_node;
+
+ struct irq_host *irqhost;
+
+ unsigned long cascade_irq;
+
+ u32 msi_addr_lo;
+ u32 msi_addr_hi;
+ void __iomem *msi_regs;
+ u32 feature;
+
+ unsigned long *fsl_msi_bitmap;
+ spinlock_t bitmap_lock;
+};
+
+#endif /* _POWERPC_SYSDEV_FSL_MSI_H */
+
diff --git a/arch/powerpc/sysdev/fsl_pci.c b/arch/powerpc/sysdev/fsl_pci.c
index bf13c21..52a5f7f 100644
--- a/arch/powerpc/sysdev/fsl_pci.c
+++ b/arch/powerpc/sysdev/fsl_pci.c
@@ -106,6 +106,16 @@ void __init setup_pci_cmd(struct pci_controller *hose)
}
}
+#ifdef CONFIG_PCI_MSI
+void __init setup_pci_pcsrbar(struct pci_controller *hose)
+{
+ phys_addr_t immr_base;
+
+ immr_base = get_immrbase();
+ early_write_config_dword(hose, 0, 0, PCI_BASE_ADDRESS_0, immr_base);
+}
+#endif
+
static int fsl_pcie_bus_fixup;
static void __init quirk_fsl_pcie_header(struct pci_dev *dev)
@@ -211,6 +221,10 @@ int __init fsl_add_bridge(struct device_node *dev, int is_primary)
/* Setup PEX window registers */
setup_pci_atmu(hose, &rsrc);
+ /* Setup PEXCSRBAR */
+#ifdef CONFIG_PCI_MSI
+ setup_pci_pcsrbar(hose);
+#endif
return 0;
}
--
1.5.4
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 1/4 V5] booting-without-of for Freescale MSI
@ 2008-05-23 8:32 Jason Jin
2008-05-23 8:32 ` [PATCH 2/4 V6] MSI support on 83xx/85xx/86xx board Jason Jin
2008-05-23 13:05 ` [PATCH 1/4 V5] booting-without-of for Freescale MSI Kumar Gala
0 siblings, 2 replies; 14+ messages in thread
From: Jason Jin @ 2008-05-23 8:32 UTC (permalink / raw)
To: galak; +Cc: linuxppc-dev, Jason Jin
Binding document adding for Freescale MSI support.
Signed-off-by: Jason Jin <Jason.jin@freescale.com>
---
In this version:
The example node changed due to the hwirq num change of MSI.
Documentation/powerpc/booting-without-of.txt | 43 +++++++++++++++++++++++++-
1 files changed, 42 insertions(+), 1 deletions(-)
diff --git a/Documentation/powerpc/booting-without-of.txt b/Documentation/powerpc/booting-without-of.txt
index 1d2a772..c67d2f5 100644
--- a/Documentation/powerpc/booting-without-of.txt
+++ b/Documentation/powerpc/booting-without-of.txt
@@ -57,7 +57,10 @@ Table of Contents
n) 4xx/Axon EMAC ethernet nodes
o) Xilinx IP cores
p) Freescale Synchronous Serial Interface
- q) USB EHCI controllers
+ q) USB EHCI controllers
+ r) Freescale Display Interface Unit
+ s) Freescale on board FPGA
+ t) Freescael MSI interrupt controller
VII - Marvell Discovery mv64[345]6x System Controller chips
1) The /system-controller node
@@ -2870,6 +2873,44 @@ platforms are moved over to use the flattened-device-tree model.
reg = <0xe8000000 32>;
};
+ t) Freescale MSI interrupt controller
+
+ Reguired properities:
+ - compatible : compatible list, contains 2 entries,
+ first is "fsl,CHIP-msi", where CHIP is the processor(mpc8610, mpc8572,
+ etc.) and the second is "fsl,mpic-msi" or "fsl,ipic-msi" depending on
+ the parent type.
+ - reg : should contain the address and the length of the shared message
+ interrupt register set.
+ - msi-available-ranges: use <start count> style section to define which
+ msi interrupt can be used in the 256 msi interrupts. This property is
+ optional, without this, all the 256 MSI interrupts can be used.
+ - interrupts : each one of the interrupts here is one entry per 32 MSIs,
+ and routed to the host interrupt controller. the interrupts should
+ be set as edge sensitive.
+ - interrupt-parent: the phandle for the interrupt controller
+ that services interrupts for this device. for 83xx cpu, the interrupts
+ are routed to IPIC, and for 85xx/86xx cpu the interrupts are routed
+ to MPIC.
+
+ Example
+ msi@41600 {
+ compatible = "fsl,mpc8610-msi", "fsl,mpic-msi";
+ reg = <0x41600 0x80>;
+ msi-available-ranges = <0 0x100>;
+ interrupts = <
+ 0xe0 0
+ 0xe1 0
+ 0xe2 0
+ 0xe3 0
+ 0xe4 0
+ 0xe5 0
+ 0xe6 0
+ 0xe7 0>;
+ interrupt-parent = <&mpic>;
+ };
+
+
VII - Marvell Discovery mv64[345]6x System Controller chips
===========================================================
--
1.5.4
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 2/4 V6] MSI support on 83xx/85xx/86xx board
2008-05-23 8:32 [PATCH 1/4 V5] booting-without-of for Freescale MSI Jason Jin
@ 2008-05-23 8:32 ` Jason Jin
2008-05-23 8:32 ` [PATCH 3/4 V5] Enable MSI support for MPC8610HPCD board Jason Jin
` (2 more replies)
2008-05-23 13:05 ` [PATCH 1/4 V5] booting-without-of for Freescale MSI Kumar Gala
1 sibling, 3 replies; 14+ messages in thread
From: Jason Jin @ 2008-05-23 8:32 UTC (permalink / raw)
To: galak; +Cc: linuxppc-dev, Jason Jin
This MSI driver can be used on 83xx/85xx/86xx board.
In this driver, virtual interrupt host and chip were
setup. There are 256 MSI interrupts in this host, Every 32
MSI interrupts cascaded to one IPIC/MPIC interrupt.
The chip was treated as edge sensitive and some necessary
functions were setup for this chip.
Before using the MSI interrupt, PCI/PCIE device need to
ask for a MSI interrupt in the 256 MSI interrupts. A 256bit
bitmap show which MSI interrupt was used, reserve bit in
the bitmap can be used to force the device use some designate
MSI interrupt in the 256 MSI interrupts. Sometimes this is useful
for testing the all the MSI interrupts. The msi-available-ranges
property in the dts file was used for this purpose.
Signed-off-by: Jason Jin <Jason.jin@freescale.com>
---
No changes in this send, just sent with the patchset.
arch/powerpc/sysdev/Makefile | 3 +-
arch/powerpc/sysdev/fsl_msi.c | 436 +++++++++++++++++++++++++++++++++++++++++
arch/powerpc/sysdev/fsl_msi.h | 42 ++++
arch/powerpc/sysdev/fsl_pci.c | 14 ++
4 files changed, 494 insertions(+), 1 deletions(-)
create mode 100644 arch/powerpc/sysdev/fsl_msi.c
create mode 100644 arch/powerpc/sysdev/fsl_msi.h
diff --git a/arch/powerpc/sysdev/Makefile b/arch/powerpc/sysdev/Makefile
index 2cc5052..dd6dff3 100644
--- a/arch/powerpc/sysdev/Makefile
+++ b/arch/powerpc/sysdev/Makefile
@@ -4,6 +4,7 @@ endif
mpic-msi-obj-$(CONFIG_PCI_MSI) += mpic_msi.o mpic_u3msi.o mpic_pasemi_msi.o
obj-$(CONFIG_MPIC) += mpic.o $(mpic-msi-obj-y)
+fsl-msi-obj-$(CONFIG_PCI_MSI) += fsl_msi.o
obj-$(CONFIG_PPC_MPC106) += grackle.o
obj-$(CONFIG_PPC_DCR_NATIVE) += dcr-low.o
@@ -11,7 +12,7 @@ obj-$(CONFIG_PPC_PMI) += pmi.o
obj-$(CONFIG_U3_DART) += dart_iommu.o
obj-$(CONFIG_MMIO_NVRAM) += mmio_nvram.o
obj-$(CONFIG_FSL_SOC) += fsl_soc.o
-obj-$(CONFIG_FSL_PCI) += fsl_pci.o
+obj-$(CONFIG_FSL_PCI) += fsl_pci.o $(fsl-msi-obj-y)
obj-$(CONFIG_FSL_LBC) += fsl_lbc.o
obj-$(CONFIG_RAPIDIO) += fsl_rio.o
obj-$(CONFIG_TSI108_BRIDGE) += tsi108_pci.o tsi108_dev.o
diff --git a/arch/powerpc/sysdev/fsl_msi.c b/arch/powerpc/sysdev/fsl_msi.c
new file mode 100644
index 0000000..9d0685b
--- /dev/null
+++ b/arch/powerpc/sysdev/fsl_msi.c
@@ -0,0 +1,436 @@
+/*
+ * Copyright (C) 2007-2008 Freescale Semiconductor, Inc. All rights reserved.
+ *
+ * Author: Tony Li <tony.li@freescale.com>
+ * Jason Jin <Jason.jin@freescale.com>
+ *
+ * The hwirq alloc and free code reuse from sysdev/mpic_msi.c
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; version 2 of the
+ * License.
+ *
+ */
+#include <linux/irq.h>
+#include <linux/bootmem.h>
+#include <linux/bitmap.h>
+#include <linux/msi.h>
+#include <linux/pci.h>
+#include <linux/of_platform.h>
+#include <sysdev/fsl_soc.h>
+#include <asm/prom.h>
+#include <asm/hw_irq.h>
+#include <asm/ppc-pci.h>
+#include "fsl_msi.h"
+
+struct fsl_msi_feature {
+ u32 fsl_pic_ip;
+ u32 msiir_offset;
+};
+
+static struct fsl_msi *fsl_msi;
+
+static inline u32 fsl_msi_read(u32 __iomem *base, unsigned int reg)
+{
+ return in_be32(base + (reg >> 2));
+}
+
+static inline void fsl_msi_write(u32 __iomem *base,
+ unsigned int reg, u32 value)
+{
+ out_be32(base + (reg >> 2), value);
+}
+
+/*
+ * We do not need this actually. The MSIR register has been read once
+ * in the cascade interrupt. So, this MSI interrupt has been acked
+*/
+static void fsl_msi_end_irq(unsigned int virq)
+{
+}
+
+static struct irq_chip fsl_msi_chip = {
+ .mask = mask_msi_irq,
+ .unmask = unmask_msi_irq,
+ .ack = fsl_msi_end_irq,
+ .typename = " FSL-MSI ",
+};
+
+static int fsl_msi_host_map(struct irq_host *h, unsigned int virq,
+ irq_hw_number_t hw)
+{
+ struct irq_chip *chip = &fsl_msi_chip;
+
+ get_irq_desc(virq)->status |= IRQ_TYPE_EDGE_FALLING;
+
+ set_irq_chip_and_handler(virq, chip, handle_edge_irq);
+
+ return 0;
+}
+
+static struct irq_host_ops fsl_msi_host_ops = {
+ .map = fsl_msi_host_map,
+};
+
+irq_hw_number_t fsl_msi_alloc_hwirqs(struct fsl_msi *msi, int num)
+{
+ unsigned long flags;
+ int offset, order = get_count_order(num);
+
+ spin_lock_irqsave(&msi->bitmap_lock, flags);
+
+ offset = bitmap_find_free_region(msi->fsl_msi_bitmap,
+ NR_MSI_IRQS, order);
+
+ spin_unlock_irqrestore(&msi->bitmap_lock, flags);
+
+ pr_debug("%s: allocated 0x%x (2^%d) at offset 0x%x\n",
+ __func__, num, order, offset);
+
+ return offset;
+}
+
+void fsl_msi_free_hwirqs(struct fsl_msi *msi, int offset, int num)
+{
+ unsigned long flags;
+ int order = get_count_order(num);
+
+ pr_debug("%s: freeing 0x%x (2^%d) at offset 0x%x\n",
+ __func__, num, order, offset);
+
+ spin_lock_irqsave(&msi->bitmap_lock, flags);
+ bitmap_release_region(msi->fsl_msi_bitmap, offset, order);
+ spin_unlock_irqrestore(&msi->bitmap_lock, flags);
+}
+
+static int fsl_msi_free_dt_hwirqs(struct fsl_msi *msi)
+{
+ int i, len;
+ const u32 *p;
+
+ bitmap_allocate_region(msi->fsl_msi_bitmap, 0,
+ get_count_order(NR_MSI_IRQS));
+
+ p = of_get_property(msi->of_node, "msi-available-ranges", &len);
+
+ if (!p) {
+ /* No msi-available-ranges property,
+ * All the 256 MSI interrupts can be used
+ */
+ fsl_msi_free_hwirqs(msi, 0, 0x100);
+ return 0;
+ }
+
+ if ((len % (2 * sizeof(u32))) != 0) {
+ printk(KERN_WARNING "fsl_msi: Malformed msi-available-ranges "
+ "property on %s\n", msi->of_node->full_name);
+ return -EINVAL;
+ }
+
+ /* Format is: (<u32 start> <u32 count>)+ */
+ len /= 2 * sizeof(u32);
+ for (i = 0; i < len; i++, p += 2)
+ fsl_msi_free_hwirqs(msi, *p, *(p + 1));
+
+ return 0;
+}
+
+static int fsl_msi_init_allocator(struct fsl_msi *msi_data)
+{
+ int rc, size;
+
+ size = BITS_TO_LONGS(NR_MSI_IRQS) * sizeof(u32);
+
+ msi_data->fsl_msi_bitmap = kzalloc(size, GFP_KERNEL);
+
+ if (msi_data->fsl_msi_bitmap == NULL) {
+ pr_debug("%s: ENOMEM allocating allocator bitmap!\n",
+ __func__);
+ return -ENOMEM;
+ }
+
+ rc = fsl_msi_free_dt_hwirqs(msi_data);
+ if (rc)
+ goto out_free;
+
+ return 0;
+out_free:
+ kfree(msi_data->fsl_msi_bitmap);
+
+ msi_data->fsl_msi_bitmap = NULL;
+ return rc;
+
+}
+
+static int fsl_msi_check_device(struct pci_dev *pdev, int nvec, int type)
+{
+ if (type == PCI_CAP_ID_MSIX)
+ pr_debug("fslmsi: MSI-X untested, trying anyway.\n");
+
+ return 0;
+}
+
+static void fsl_teardown_msi_irqs(struct pci_dev *pdev)
+{
+ struct msi_desc *entry;
+ struct fsl_msi *msi_data = fsl_msi;
+
+ list_for_each_entry(entry, &pdev->msi_list, list) {
+ if (entry->irq == NO_IRQ)
+ continue;
+ set_irq_msi(entry->irq, NULL);
+ fsl_msi_free_hwirqs(msi_data, virq_to_hw(entry->irq), 1);
+ irq_dispose_mapping(entry->irq);
+ }
+
+ return;
+}
+
+static void fsl_compose_msi_msg(struct pci_dev *pdev, int hwirq,
+ struct msi_msg *msg)
+{
+ struct fsl_msi *msi_data = fsl_msi;
+
+ msg->address_lo = msi_data->msi_addr_lo;
+ msg->address_hi = msi_data->msi_addr_hi;
+ msg->data = hwirq;
+
+ pr_debug("%s: allocated srs: %d, ibs: %d\n",
+ __func__, hwirq / IRQS_PER_MSI_REG, hwirq % IRQS_PER_MSI_REG);
+}
+
+static int fsl_setup_msi_irqs(struct pci_dev *pdev, int nvec, int type)
+{
+ irq_hw_number_t hwirq;
+ int rc;
+ unsigned int virq;
+ struct msi_desc *entry;
+ struct msi_msg msg;
+ struct fsl_msi *msi_data = fsl_msi;
+
+ list_for_each_entry(entry, &pdev->msi_list, list) {
+ hwirq = fsl_msi_alloc_hwirqs(msi_data, 1);
+ if (hwirq < 0) {
+ rc = hwirq;
+ pr_debug("%s: fail allocating msi interrupt\n",
+ __func__);
+ goto out_free;
+ }
+
+ virq = irq_create_mapping(msi_data->irqhost, hwirq);
+
+ if (virq == NO_IRQ) {
+ pr_debug("%s: fail mapping hwirq 0x%lx\n",
+ __func__, hwirq);
+ fsl_msi_free_hwirqs(msi_data, hwirq, 1);
+ rc = -ENOSPC;
+ goto out_free;
+ }
+ set_irq_msi(virq, entry);
+
+ fsl_compose_msi_msg(pdev, hwirq, &msg);
+ write_msi_msg(virq, &msg);
+ }
+ return 0;
+
+out_free:
+ return rc;
+}
+
+void fsl_msi_cascade(unsigned int irq, struct irq_desc *desc)
+{
+ unsigned int cascade_irq;
+ struct fsl_msi *msi_data = fsl_msi;
+ int msir_index = -1;
+ u32 msir_value = 0;
+ u32 intr_index;
+ u32 have_shift = 0;
+
+ spin_lock(&desc->lock);
+ if ((msi_data->feature & FSL_PIC_IP_MASK) == FSL_PIC_IP_IPIC) {
+ if (desc->chip->mask_ack)
+ desc->chip->mask_ack(irq);
+ else {
+ desc->chip->mask(irq);
+ desc->chip->ack(irq);
+ }
+ }
+
+ if (unlikely(desc->status & IRQ_INPROGRESS))
+ goto unlock;
+
+ msir_index = (int)(desc->handler_data);
+
+ if (msir_index >= NR_MSI_REG)
+ cascade_irq = NO_IRQ;
+
+ desc->status |= IRQ_INPROGRESS;
+ switch (fsl_msi->feature & FSL_PIC_IP_MASK) {
+ case FSL_PIC_IP_MPIC:
+ msir_value = fsl_msi_read(msi_data->msi_regs,
+ msir_index * 0x10);
+ break;
+ case FSL_PIC_IP_IPIC:
+ msir_value = fsl_msi_read(msi_data->msi_regs, msir_index * 0x4);
+ break;
+ }
+
+ while (msir_value) {
+ intr_index = ffs(msir_value) - 1;
+
+ cascade_irq = irq_linear_revmap(msi_data->irqhost,
+ (msir_index * IRQS_PER_MSI_REG +
+ intr_index + have_shift));
+ if (cascade_irq != NO_IRQ)
+ generic_handle_irq(cascade_irq);
+ have_shift += (intr_index + 1);
+ msir_value = (msir_value >> (intr_index + 1));
+ }
+ desc->status &= ~IRQ_INPROGRESS;
+
+ switch (msi_data->feature & FSL_PIC_IP_MASK) {
+ case FSL_PIC_IP_MPIC:
+ desc->chip->eoi(irq);
+ break;
+ case FSL_PIC_IP_IPIC:
+ if (!(desc->status & IRQ_DISABLED) && desc->chip->unmask)
+ desc->chip->unmask(irq);
+ break;
+ }
+unlock:
+ spin_unlock(&desc->lock);
+}
+
+static int __devinit fsl_of_msi_probe(struct of_device *dev,
+ const struct of_device_id *match)
+{
+ struct fsl_msi *msi;
+ struct resource res;
+ int err, i, count;
+ int rc;
+ int virt_msir;
+ const u32 *p;
+ struct fsl_msi_feature *tmp_data;
+
+ printk(KERN_DEBUG "Setting up Freescale MSI support\n");
+
+ msi = kzalloc(sizeof(struct fsl_msi), GFP_KERNEL);
+ if (!msi) {
+ dev_err(&dev->dev, "No memory for MSI structure\n");
+ err = -ENOMEM;
+ goto error_out;
+ }
+
+ msi->of_node = of_node_get(dev->node);
+
+ msi->irqhost = irq_alloc_host(of_node_get(dev->node),
+ IRQ_HOST_MAP_LINEAR,
+ NR_MSI_IRQS, &fsl_msi_host_ops, 0);
+ if (msi->irqhost == NULL) {
+ dev_err(&dev->dev, "No memory for MSI irqhost\n");
+ of_node_put(dev->node);
+ err = -ENOMEM;
+ goto error_out;
+ }
+
+ /* Get the MSI reg base */
+ err = of_address_to_resource(dev->node, 0, &res);
+ if (err) {
+ dev_err(&dev->dev, "%s resource error!\n",
+ dev->node->full_name);
+ goto error_out;
+ }
+
+ msi->msi_regs = ioremap(res.start, res.end - res.start + 1);
+ if (!msi->msi_regs) {
+ dev_err(&dev->dev, "ioremap problem failed\n");
+ goto error_out;
+ }
+
+ tmp_data = (struct fsl_msi_feature *)match->data;
+
+ msi->feature = tmp_data->fsl_pic_ip;
+
+ msi->irqhost->host_data = msi;
+
+ msi->msi_addr_hi = 0x0;
+ msi->msi_addr_lo = res.start + tmp_data->msiir_offset;
+
+ rc = fsl_msi_init_allocator(msi);
+ if (rc) {
+ dev_err(&dev->dev, "Error allocating MSI bitmap\n");
+ goto error_out;
+ }
+
+ p = of_get_property(dev->node, "interrupts", &count);
+ if (!p) {
+ dev_err(&dev->dev, "no interrupts property found on %s\n",
+ dev->node->full_name);
+ err = -ENODEV;
+ goto error_out;
+ }
+ if (count % 8 != 0) {
+ dev_err(&dev->dev, "Malformed interrupts property on %s\n",
+ dev->node->full_name);
+ err = -EINVAL;
+ goto error_out;
+ }
+
+ count /= sizeof(u32);
+ for (i = 0; i < count / 2; i++) {
+ if (i > NR_MSI_REG)
+ break;
+ virt_msir = irq_of_parse_and_map(dev->node, i);
+ if (virt_msir != NO_IRQ) {
+ set_irq_data(virt_msir, (void *)i);
+ set_irq_chained_handler(virt_msir, fsl_msi_cascade);
+ }
+ }
+
+ fsl_msi = msi;
+
+ WARN_ON(ppc_md.setup_msi_irqs);
+ ppc_md.setup_msi_irqs = fsl_setup_msi_irqs;
+ ppc_md.teardown_msi_irqs = fsl_teardown_msi_irqs;
+ ppc_md.msi_check_device = fsl_msi_check_device;
+ return 0;
+error_out:
+ kfree(msi);
+ return err;
+}
+
+static const struct fsl_msi_feature mpic_msi_feature = {
+ .fsl_pic_ip = FSL_PIC_IP_MPIC,
+ .msiir_offset = 0x140,
+};
+
+static const struct fsl_msi_feature ipic_msi_feature = {
+ .fsl_pic_ip = FSL_PIC_IP_IPIC,
+ .msiir_offset = 0x38,
+};
+
+static const struct of_device_id fsl_of_msi_ids[] = {
+ {
+ .compatible = "fsl,mpic-msi",
+ .data = (void *)&mpic_msi_feature,
+ },
+ {
+ .compatible = "fsl,ipic-msi",
+ .data = (void *)&ipic_msi_feature,
+ },
+ {}
+};
+
+static struct of_platform_driver fsl_of_msi_driver = {
+ .name = "fsl-msi",
+ .match_table = fsl_of_msi_ids,
+ .probe = fsl_of_msi_probe,
+};
+
+static __init int fsl_of_msi_init(void)
+{
+ return of_register_platform_driver(&fsl_of_msi_driver);
+}
+
+subsys_initcall(fsl_of_msi_init);
diff --git a/arch/powerpc/sysdev/fsl_msi.h b/arch/powerpc/sysdev/fsl_msi.h
new file mode 100644
index 0000000..a653468
--- /dev/null
+++ b/arch/powerpc/sysdev/fsl_msi.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2007-2008 Freescale Semiconductor, Inc. All rights reserved.
+ *
+ * Author: Tony Li <tony.li@freescale.com>
+ * Jason Jin <Jason.jin@freescale.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; version 2 of the
+ * License.
+ *
+ */
+#ifndef _POWERPC_SYSDEV_FSL_MSI_H
+#define _POWERPC_SYSDEV_FSL_MSI_H
+
+#define NR_MSI_REG 8
+#define IRQS_PER_MSI_REG 32
+#define NR_MSI_IRQS (NR_MSI_REG * IRQS_PER_MSI_REG)
+
+#define FSL_PIC_IP_MASK 0x0000000F
+#define FSL_PIC_IP_MPIC 0x00000001
+#define FSL_PIC_IP_IPIC 0x00000002
+
+struct fsl_msi {
+ /* Device node of the MSI interrupt*/
+ struct device_node *of_node;
+
+ struct irq_host *irqhost;
+
+ unsigned long cascade_irq;
+
+ u32 msi_addr_lo;
+ u32 msi_addr_hi;
+ void __iomem *msi_regs;
+ u32 feature;
+
+ unsigned long *fsl_msi_bitmap;
+ spinlock_t bitmap_lock;
+};
+
+#endif /* _POWERPC_SYSDEV_FSL_MSI_H */
+
diff --git a/arch/powerpc/sysdev/fsl_pci.c b/arch/powerpc/sysdev/fsl_pci.c
index bf13c21..52a5f7f 100644
--- a/arch/powerpc/sysdev/fsl_pci.c
+++ b/arch/powerpc/sysdev/fsl_pci.c
@@ -106,6 +106,16 @@ void __init setup_pci_cmd(struct pci_controller *hose)
}
}
+#ifdef CONFIG_PCI_MSI
+void __init setup_pci_pcsrbar(struct pci_controller *hose)
+{
+ phys_addr_t immr_base;
+
+ immr_base = get_immrbase();
+ early_write_config_dword(hose, 0, 0, PCI_BASE_ADDRESS_0, immr_base);
+}
+#endif
+
static int fsl_pcie_bus_fixup;
static void __init quirk_fsl_pcie_header(struct pci_dev *dev)
@@ -211,6 +221,10 @@ int __init fsl_add_bridge(struct device_node *dev, int is_primary)
/* Setup PEX window registers */
setup_pci_atmu(hose, &rsrc);
+ /* Setup PEXCSRBAR */
+#ifdef CONFIG_PCI_MSI
+ setup_pci_pcsrbar(hose);
+#endif
return 0;
}
--
1.5.4
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 3/4 V5] Enable MSI support for MPC8610HPCD board
2008-05-23 8:32 ` [PATCH 2/4 V6] MSI support on 83xx/85xx/86xx board Jason Jin
@ 2008-05-23 8:32 ` Jason Jin
2008-05-23 8:32 ` [PATCH 4/4 V5] Enable MSI support for 85xxds board Jason Jin
2008-05-23 13:05 ` [PATCH 3/4 V5] Enable MSI support for MPC8610HPCD board Kumar Gala
2008-05-23 12:59 ` [PATCH 2/4 V6] MSI support on 83xx/85xx/86xx board Anton Vorontsov
2008-05-23 13:06 ` Kumar Gala
2 siblings, 2 replies; 14+ messages in thread
From: Jason Jin @ 2008-05-23 8:32 UTC (permalink / raw)
To: galak; +Cc: linuxppc-dev, Jason Jin
This patch enable the MSI on 8610hpcd board.
Through the msi-available-ranges property, All the 256
msi interrupts can be tested on this board.
Signed-off-by: Jason Jin <Jason.jin@freescale.com>
---
In this version:
Add a flag MPIC_BROKEN_FRR_NIRQS in mpic_alloc making the mpic use
irq_count instead of FRR[NIRQ] to initialize the interrupt controller.
So the hwirq num need to be changed.
arch/powerpc/boot/dts/mpc8610_hpcd.dts | 16 ++++++++++++++++
arch/powerpc/platforms/86xx/mpc8610_hpcd.c | 3 ++-
2 files changed, 18 insertions(+), 1 deletions(-)
diff --git a/arch/powerpc/boot/dts/mpc8610_hpcd.dts b/arch/powerpc/boot/dts/mpc8610_hpcd.dts
index 08a780d..fa9c297 100644
--- a/arch/powerpc/boot/dts/mpc8610_hpcd.dts
+++ b/arch/powerpc/boot/dts/mpc8610_hpcd.dts
@@ -182,6 +182,22 @@
big-endian;
};
+ msi@41600 {
+ compatible = "fsl,mpc8610-msi", "fsl,mpic-msi";
+ reg = <0x41600 0x80>;
+ msi-available-ranges = <0 0x100>;
+ interrupts = <
+ 0xe0 0
+ 0xe1 0
+ 0xe2 0
+ 0xe3 0
+ 0xe4 0
+ 0xe5 0
+ 0xe6 0
+ 0xe7 0>;
+ interrupt-parent = <&mpic>;
+ };
+
global-utilities@e0000 {
compatible = "fsl,mpc8610-guts";
reg = <0xe0000 0x1000>;
diff --git a/arch/powerpc/platforms/86xx/mpc8610_hpcd.c b/arch/powerpc/platforms/86xx/mpc8610_hpcd.c
index dea1320..eb16208 100644
--- a/arch/powerpc/platforms/86xx/mpc8610_hpcd.c
+++ b/arch/powerpc/platforms/86xx/mpc8610_hpcd.c
@@ -70,7 +70,8 @@ static void __init mpc86xx_hpcd_init_irq(void)
/* Alloc mpic structure and per isu has 16 INT entries. */
mpic1 = mpic_alloc(np, res.start,
- MPIC_PRIMARY | MPIC_WANTS_RESET | MPIC_BIG_ENDIAN,
+ MPIC_PRIMARY | MPIC_WANTS_RESET |
+ MPIC_BIG_ENDIAN | MPIC_BROKEN_FRR_NIRQS,
0, 256, " MPIC ");
BUG_ON(mpic1 == NULL);
--
1.5.4
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 4/4 V5] Enable MSI support for 85xxds board
2008-05-23 8:32 ` [PATCH 3/4 V5] Enable MSI support for MPC8610HPCD board Jason Jin
@ 2008-05-23 8:32 ` Jason Jin
2008-05-23 13:06 ` Kumar Gala
2008-05-23 13:05 ` [PATCH 3/4 V5] Enable MSI support for MPC8610HPCD board Kumar Gala
1 sibling, 1 reply; 14+ messages in thread
From: Jason Jin @ 2008-05-23 8:32 UTC (permalink / raw)
To: galak; +Cc: linuxppc-dev, Jason Jin
This patch enabled MSI on 8544ds and 8572ds board.
So far only one MSI interrupt can generate on 8544 board.
Signed-off-by: Jason Jin <Jason.jin@freescale.com>
---
In this version:
Add a flag MPIC_BROKEN_FRR_NIRQS in mpic_alloc making the mpic use
irq_count instead of FRR[NIRQ] to initialize the interrupt controller.
So the hwirq num need to be changed.
arch/powerpc/boot/dts/mpc8544ds.dts | 16 ++++++++++++++++
arch/powerpc/boot/dts/mpc8572ds.dts | 16 ++++++++++++++++
arch/powerpc/platforms/85xx/mpc85xx_ds.c | 4 +++-
3 files changed, 35 insertions(+), 1 deletions(-)
diff --git a/arch/powerpc/boot/dts/mpc8544ds.dts b/arch/powerpc/boot/dts/mpc8544ds.dts
index 6a0d8db..1cfd970 100644
--- a/arch/powerpc/boot/dts/mpc8544ds.dts
+++ b/arch/powerpc/boot/dts/mpc8544ds.dts
@@ -219,6 +219,22 @@
device_type = "open-pic";
big-endian;
};
+
+ msi@41600 {
+ compatible = "fsl,mpc8544-msi", "fsl,mpic-msi";
+ reg = <0x41600 0x80>;
+ msi-available-ranges = <0 0x100>;
+ interrupts = <
+ 0xe0 0
+ 0xe1 0
+ 0xe2 0
+ 0xe3 0
+ 0xe4 0
+ 0xe5 0
+ 0xe6 0
+ 0xe7 0>;
+ interrupt-parent = <&mpic>;
+ };
};
pci0: pci@e0008000 {
diff --git a/arch/powerpc/boot/dts/mpc8572ds.dts b/arch/powerpc/boot/dts/mpc8572ds.dts
index 66f27ab..174d51a 100644
--- a/arch/powerpc/boot/dts/mpc8572ds.dts
+++ b/arch/powerpc/boot/dts/mpc8572ds.dts
@@ -221,6 +221,22 @@
fsl,has-rstcr;
};
+ msi@41600 {
+ compatible = "fsl,mpc8572-msi", "fsl,mpic-msi";
+ reg = <0x41600 0x80>;
+ msi-available-ranges = <0 0x100>;
+ interrupts = <
+ 0xe0 0
+ 0xe1 0
+ 0xe2 0
+ 0xe3 0
+ 0xe4 0
+ 0xe5 0
+ 0xe6 0
+ 0xe7 0>;
+ interrupt-parent = <&mpic>;
+ };
+
mpic: pic@40000 {
clock-frequency = <0>;
interrupt-controller;
diff --git a/arch/powerpc/platforms/85xx/mpc85xx_ds.c b/arch/powerpc/platforms/85xx/mpc85xx_ds.c
index dfd8b4a..b010dc9 100644
--- a/arch/powerpc/platforms/85xx/mpc85xx_ds.c
+++ b/arch/powerpc/platforms/85xx/mpc85xx_ds.c
@@ -78,7 +78,8 @@ void __init mpc85xx_ds_pic_init(void)
}
mpic = mpic_alloc(np, r.start,
- MPIC_PRIMARY | MPIC_WANTS_RESET | MPIC_BIG_ENDIAN,
+ MPIC_PRIMARY | MPIC_WANTS_RESET |
+ MPIC_BIG_ENDIAN | MPIC_BROKEN_FRR_NIRQS,
0, 256, " OpenPIC ");
BUG_ON(mpic == NULL);
@@ -195,6 +196,7 @@ static int __init mpc85xxds_publish_devices(void)
return of_platform_bus_probe(NULL, mpc85xxds_ids, NULL);
}
machine_device_initcall(mpc8544_ds, mpc85xxds_publish_devices);
+machine_device_initcall(mpc8572_ds, mpc85xxds_publish_devices);
/*
* Called very early, device-tree isn't unflattened
--
1.5.4
^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH 2/4 V6] MSI support on 83xx/85xx/86xx board
2008-05-23 8:32 ` [PATCH 2/4 V6] MSI support on 83xx/85xx/86xx board Jason Jin
2008-05-23 8:32 ` [PATCH 3/4 V5] Enable MSI support for MPC8610HPCD board Jason Jin
@ 2008-05-23 12:59 ` Anton Vorontsov
2008-05-23 13:02 ` Kumar Gala
2008-05-23 13:06 ` Kumar Gala
2 siblings, 1 reply; 14+ messages in thread
From: Anton Vorontsov @ 2008-05-23 12:59 UTC (permalink / raw)
To: Jason Jin; +Cc: linuxppc-dev
On Fri, May 23, 2008 at 04:32:46PM +0800, Jason Jin wrote:
> This MSI driver can be used on 83xx/85xx/86xx board.
> In this driver, virtual interrupt host and chip were
> setup. There are 256 MSI interrupts in this host, Every 32
> MSI interrupts cascaded to one IPIC/MPIC interrupt.
> The chip was treated as edge sensitive and some necessary
> functions were setup for this chip.
>
> Before using the MSI interrupt, PCI/PCIE device need to
> ask for a MSI interrupt in the 256 MSI interrupts. A 256bit
> bitmap show which MSI interrupt was used, reserve bit in
> the bitmap can be used to force the device use some designate
> MSI interrupt in the 256 MSI interrupts. Sometimes this is useful
> for testing the all the MSI interrupts. The msi-available-ranges
> property in the dts file was used for this purpose.
>
> Signed-off-by: Jason Jin <Jason.jin@freescale.com>
> ---
Hello Jason,
Few comments below.
> No changes in this send, just sent with the patchset.
>
> arch/powerpc/sysdev/Makefile | 3 +-
> arch/powerpc/sysdev/fsl_msi.c | 436 +++++++++++++++++++++++++++++++++++++++++
> arch/powerpc/sysdev/fsl_msi.h | 42 ++++
> arch/powerpc/sysdev/fsl_pci.c | 14 ++
> 4 files changed, 494 insertions(+), 1 deletions(-)
> create mode 100644 arch/powerpc/sysdev/fsl_msi.c
> create mode 100644 arch/powerpc/sysdev/fsl_msi.h
>
> diff --git a/arch/powerpc/sysdev/Makefile b/arch/powerpc/sysdev/Makefile
> index 2cc5052..dd6dff3 100644
> --- a/arch/powerpc/sysdev/Makefile
> +++ b/arch/powerpc/sysdev/Makefile
> @@ -4,6 +4,7 @@ endif
>
> mpic-msi-obj-$(CONFIG_PCI_MSI) += mpic_msi.o mpic_u3msi.o mpic_pasemi_msi.o
> obj-$(CONFIG_MPIC) += mpic.o $(mpic-msi-obj-y)
> +fsl-msi-obj-$(CONFIG_PCI_MSI) += fsl_msi.o
>
> obj-$(CONFIG_PPC_MPC106) += grackle.o
> obj-$(CONFIG_PPC_DCR_NATIVE) += dcr-low.o
> @@ -11,7 +12,7 @@ obj-$(CONFIG_PPC_PMI) += pmi.o
> obj-$(CONFIG_U3_DART) += dart_iommu.o
> obj-$(CONFIG_MMIO_NVRAM) += mmio_nvram.o
> obj-$(CONFIG_FSL_SOC) += fsl_soc.o
> -obj-$(CONFIG_FSL_PCI) += fsl_pci.o
> +obj-$(CONFIG_FSL_PCI) += fsl_pci.o $(fsl-msi-obj-y)
> obj-$(CONFIG_FSL_LBC) += fsl_lbc.o
> obj-$(CONFIG_RAPIDIO) += fsl_rio.o
> obj-$(CONFIG_TSI108_BRIDGE) += tsi108_pci.o tsi108_dev.o
> diff --git a/arch/powerpc/sysdev/fsl_msi.c b/arch/powerpc/sysdev/fsl_msi.c
> new file mode 100644
> index 0000000..9d0685b
> --- /dev/null
> +++ b/arch/powerpc/sysdev/fsl_msi.c
> @@ -0,0 +1,436 @@
> +/*
> + * Copyright (C) 2007-2008 Freescale Semiconductor, Inc. All rights reserved.
> + *
> + * Author: Tony Li <tony.li@freescale.com>
> + * Jason Jin <Jason.jin@freescale.com>
> + *
> + * The hwirq alloc and free code reuse from sysdev/mpic_msi.c
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License
> + * as published by the Free Software Foundation; version 2 of the
> + * License.
> + *
> + */
> +#include <linux/irq.h>
> +#include <linux/bootmem.h>
> +#include <linux/bitmap.h>
> +#include <linux/msi.h>
> +#include <linux/pci.h>
> +#include <linux/of_platform.h>
> +#include <sysdev/fsl_soc.h>
> +#include <asm/prom.h>
> +#include <asm/hw_irq.h>
> +#include <asm/ppc-pci.h>
> +#include "fsl_msi.h"
> +
> +struct fsl_msi_feature {
> + u32 fsl_pic_ip;
> + u32 msiir_offset;
> +};
> +
> +static struct fsl_msi *fsl_msi;
> +
> +static inline u32 fsl_msi_read(u32 __iomem *base, unsigned int reg)
> +{
> + return in_be32(base + (reg >> 2));
> +}
> +
> +static inline void fsl_msi_write(u32 __iomem *base,
> + unsigned int reg, u32 value)
This function isn't used.
> +{
> + out_be32(base + (reg >> 2), value);
> +}
> +
> +/*
> + * We do not need this actually. The MSIR register has been read once
> + * in the cascade interrupt. So, this MSI interrupt has been acked
> +*/
> +static void fsl_msi_end_irq(unsigned int virq)
> +{
> +}
> +
> +static struct irq_chip fsl_msi_chip = {
> + .mask = mask_msi_irq,
> + .unmask = unmask_msi_irq,
> + .ack = fsl_msi_end_irq,
> + .typename = " FSL-MSI ",
> +};
> +
> +static int fsl_msi_host_map(struct irq_host *h, unsigned int virq,
> + irq_hw_number_t hw)
> +{
> + struct irq_chip *chip = &fsl_msi_chip;
> +
> + get_irq_desc(virq)->status |= IRQ_TYPE_EDGE_FALLING;
> +
> + set_irq_chip_and_handler(virq, chip, handle_edge_irq);
Two spaces.
> +
> + return 0;
> +}
> +
> +static struct irq_host_ops fsl_msi_host_ops = {
> + .map = fsl_msi_host_map,
> +};
> +
> +irq_hw_number_t fsl_msi_alloc_hwirqs(struct fsl_msi *msi, int num)
> +{
This isn't extern'ed function, this probably should be static.
> + unsigned long flags;
> + int offset, order = get_count_order(num);
int order = get_count_order(num);
int offset;
> + spin_lock_irqsave(&msi->bitmap_lock, flags);
> +
> + offset = bitmap_find_free_region(msi->fsl_msi_bitmap,
> + NR_MSI_IRQS, order);
> +
> + spin_unlock_irqrestore(&msi->bitmap_lock, flags);
> +
> + pr_debug("%s: allocated 0x%x (2^%d) at offset 0x%x\n",
> + __func__, num, order, offset);
> +
> + return offset;
> +}
> +
> +void fsl_msi_free_hwirqs(struct fsl_msi *msi, int offset, int num)
static?
> +{
> + unsigned long flags;
> + int order = get_count_order(num);
> +
> + pr_debug("%s: freeing 0x%x (2^%d) at offset 0x%x\n",
> + __func__, num, order, offset);
> +
> + spin_lock_irqsave(&msi->bitmap_lock, flags);
> + bitmap_release_region(msi->fsl_msi_bitmap, offset, order);
> + spin_unlock_irqrestore(&msi->bitmap_lock, flags);
> +}
> +
> +static int fsl_msi_free_dt_hwirqs(struct fsl_msi *msi)
> +{
> + int i, len;
> + const u32 *p;
> +
> + bitmap_allocate_region(msi->fsl_msi_bitmap, 0,
> + get_count_order(NR_MSI_IRQS));
> +
> + p = of_get_property(msi->of_node, "msi-available-ranges", &len);
> +
> + if (!p) {
> + /* No msi-available-ranges property,
> + * All the 256 MSI interrupts can be used
> + */
> + fsl_msi_free_hwirqs(msi, 0, 0x100);
> + return 0;
> + }
> +
> + if ((len % (2 * sizeof(u32))) != 0) {
> + printk(KERN_WARNING "fsl_msi: Malformed msi-available-ranges "
> + "property on %s\n", msi->of_node->full_name);
> + return -EINVAL;
> + }
> +
> + /* Format is: (<u32 start> <u32 count>)+ */
> + len /= 2 * sizeof(u32);
> + for (i = 0; i < len; i++, p += 2)
> + fsl_msi_free_hwirqs(msi, *p, *(p + 1));
> +
> + return 0;
> +}
> +
> +static int fsl_msi_init_allocator(struct fsl_msi *msi_data)
> +{
> + int rc, size;
> +
> + size = BITS_TO_LONGS(NR_MSI_IRQS) * sizeof(u32);
int rc;
int size = BITS_TO_LONGS(NR_MSI_IRQS) * sizeof(u32);
> + msi_data->fsl_msi_bitmap = kzalloc(size, GFP_KERNEL);
> +
> + if (msi_data->fsl_msi_bitmap == NULL) {
> + pr_debug("%s: ENOMEM allocating allocator bitmap!\n",
> + __func__);
> + return -ENOMEM;
> + }
> +
> + rc = fsl_msi_free_dt_hwirqs(msi_data);
> + if (rc)
> + goto out_free;
> +
> + return 0;
> +out_free:
> + kfree(msi_data->fsl_msi_bitmap);
> +
> + msi_data->fsl_msi_bitmap = NULL;
> + return rc;
> +
> +}
> +
> +static int fsl_msi_check_device(struct pci_dev *pdev, int nvec, int type)
> +{
> + if (type == PCI_CAP_ID_MSIX)
> + pr_debug("fslmsi: MSI-X untested, trying anyway.\n");
> +
> + return 0;
> +}
> +
> +static void fsl_teardown_msi_irqs(struct pci_dev *pdev)
> +{
> + struct msi_desc *entry;
> + struct fsl_msi *msi_data = fsl_msi;
> +
> + list_for_each_entry(entry, &pdev->msi_list, list) {
> + if (entry->irq == NO_IRQ)
> + continue;
> + set_irq_msi(entry->irq, NULL);
> + fsl_msi_free_hwirqs(msi_data, virq_to_hw(entry->irq), 1);
> + irq_dispose_mapping(entry->irq);
> + }
> +
> + return;
> +}
> +
> +static void fsl_compose_msi_msg(struct pci_dev *pdev, int hwirq,
> + struct msi_msg *msg)
> +{
> + struct fsl_msi *msi_data = fsl_msi;
> +
> + msg->address_lo = msi_data->msi_addr_lo;
> + msg->address_hi = msi_data->msi_addr_hi;
> + msg->data = hwirq;
> +
> + pr_debug("%s: allocated srs: %d, ibs: %d\n",
> + __func__, hwirq / IRQS_PER_MSI_REG, hwirq % IRQS_PER_MSI_REG);
> +}
> +
> +static int fsl_setup_msi_irqs(struct pci_dev *pdev, int nvec, int type)
> +{
> + irq_hw_number_t hwirq;
> + int rc;
> + unsigned int virq;
> + struct msi_desc *entry;
> + struct msi_msg msg;
> + struct fsl_msi *msi_data = fsl_msi;
> +
> + list_for_each_entry(entry, &pdev->msi_list, list) {
> + hwirq = fsl_msi_alloc_hwirqs(msi_data, 1);
> + if (hwirq < 0) {
> + rc = hwirq;
> + pr_debug("%s: fail allocating msi interrupt\n",
> + __func__);
> + goto out_free;
> + }
> +
> + virq = irq_create_mapping(msi_data->irqhost, hwirq);
> +
> + if (virq == NO_IRQ) {
> + pr_debug("%s: fail mapping hwirq 0x%lx\n",
> + __func__, hwirq);
> + fsl_msi_free_hwirqs(msi_data, hwirq, 1);
> + rc = -ENOSPC;
> + goto out_free;
> + }
> + set_irq_msi(virq, entry);
> +
> + fsl_compose_msi_msg(pdev, hwirq, &msg);
> + write_msi_msg(virq, &msg);
> + }
> + return 0;
> +
> +out_free:
> + return rc;
> +}
> +
> +void fsl_msi_cascade(unsigned int irq, struct irq_desc *desc)
> +{
static?
> + unsigned int cascade_irq;
> + struct fsl_msi *msi_data = fsl_msi;
> + int msir_index = -1;
> + u32 msir_value = 0;
> + u32 intr_index;
> + u32 have_shift = 0;
> +
> + spin_lock(&desc->lock);
> + if ((msi_data->feature & FSL_PIC_IP_MASK) == FSL_PIC_IP_IPIC) {
> + if (desc->chip->mask_ack)
> + desc->chip->mask_ack(irq);
> + else {
> + desc->chip->mask(irq);
> + desc->chip->ack(irq);
> + }
> + }
> +
> + if (unlikely(desc->status & IRQ_INPROGRESS))
> + goto unlock;
> +
> + msir_index = (int)(desc->handler_data);
Parentheses aren't necessary here.
> + if (msir_index >= NR_MSI_REG)
> + cascade_irq = NO_IRQ;
> +
> + desc->status |= IRQ_INPROGRESS;
> + switch (fsl_msi->feature & FSL_PIC_IP_MASK) {
> + case FSL_PIC_IP_MPIC:
> + msir_value = fsl_msi_read(msi_data->msi_regs,
> + msir_index * 0x10);
> + break;
> + case FSL_PIC_IP_IPIC:
> + msir_value = fsl_msi_read(msi_data->msi_regs, msir_index * 0x4);
> + break;
> + }
> +
> + while (msir_value) {
> + intr_index = ffs(msir_value) - 1;
> +
> + cascade_irq = irq_linear_revmap(msi_data->irqhost,
> + (msir_index * IRQS_PER_MSI_REG +
> + intr_index + have_shift));
Some parentheses aren't necessary here.
> + if (cascade_irq != NO_IRQ)
> + generic_handle_irq(cascade_irq);
> + have_shift += (intr_index + 1);
Parentheses..
> + msir_value = (msir_value >> (intr_index + 1));
Outermost parentheses.
> + }
> + desc->status &= ~IRQ_INPROGRESS;
> +
> + switch (msi_data->feature & FSL_PIC_IP_MASK) {
> + case FSL_PIC_IP_MPIC:
> + desc->chip->eoi(irq);
> + break;
> + case FSL_PIC_IP_IPIC:
> + if (!(desc->status & IRQ_DISABLED) && desc->chip->unmask)
> + desc->chip->unmask(irq);
> + break;
> + }
> +unlock:
> + spin_unlock(&desc->lock);
> +}
> +
> +static int __devinit fsl_of_msi_probe(struct of_device *dev,
> + const struct of_device_id *match)
> +{
> + struct fsl_msi *msi;
> + struct resource res;
> + int err, i, count;
> + int rc;
> + int virt_msir;
> + const u32 *p;
> + struct fsl_msi_feature *tmp_data;
(1) unfortunate name
> + printk(KERN_DEBUG "Setting up Freescale MSI support\n");
> +
> + msi = kzalloc(sizeof(struct fsl_msi), GFP_KERNEL);
> + if (!msi) {
> + dev_err(&dev->dev, "No memory for MSI structure\n");
> + err = -ENOMEM;
> + goto error_out;
> + }
> +
> + msi->of_node = of_node_get(dev->node);
> +
> + msi->irqhost = irq_alloc_host(of_node_get(dev->node),
> + IRQ_HOST_MAP_LINEAR,
> + NR_MSI_IRQS, &fsl_msi_host_ops, 0);
> + if (msi->irqhost == NULL) {
> + dev_err(&dev->dev, "No memory for MSI irqhost\n");
> + of_node_put(dev->node);
> + err = -ENOMEM;
> + goto error_out;
> + }
> +
> + /* Get the MSI reg base */
> + err = of_address_to_resource(dev->node, 0, &res);
> + if (err) {
> + dev_err(&dev->dev, "%s resource error!\n",
> + dev->node->full_name);
> + goto error_out;
> + }
> +
> + msi->msi_regs = ioremap(res.start, res.end - res.start + 1);
> + if (!msi->msi_regs) {
> + dev_err(&dev->dev, "ioremap problem failed\n");
> + goto error_out;
> + }
> +
> + tmp_data = (struct fsl_msi_feature *)match->data;
Cast isn't necessary, plus this could be placed in (1).
> +
> + msi->feature = tmp_data->fsl_pic_ip;
> +
> + msi->irqhost->host_data = msi;
> +
> + msi->msi_addr_hi = 0x0;
> + msi->msi_addr_lo = res.start + tmp_data->msiir_offset;
> +
> + rc = fsl_msi_init_allocator(msi);
> + if (rc) {
> + dev_err(&dev->dev, "Error allocating MSI bitmap\n");
> + goto error_out;
> + }
> +
> + p = of_get_property(dev->node, "interrupts", &count);
> + if (!p) {
> + dev_err(&dev->dev, "no interrupts property found on %s\n",
> + dev->node->full_name);
> + err = -ENODEV;
> + goto error_out;
> + }
> + if (count % 8 != 0) {
> + dev_err(&dev->dev, "Malformed interrupts property on %s\n",
> + dev->node->full_name);
> + err = -EINVAL;
> + goto error_out;
> + }
> +
> + count /= sizeof(u32);
> + for (i = 0; i < count / 2; i++) {
> + if (i > NR_MSI_REG)
> + break;
> + virt_msir = irq_of_parse_and_map(dev->node, i);
> + if (virt_msir != NO_IRQ) {
> + set_irq_data(virt_msir, (void *)i);
> + set_irq_chained_handler(virt_msir, fsl_msi_cascade);
> + }
> + }
> +
> + fsl_msi = msi;
> +
> + WARN_ON(ppc_md.setup_msi_irqs);
> + ppc_md.setup_msi_irqs = fsl_setup_msi_irqs;
> + ppc_md.teardown_msi_irqs = fsl_teardown_msi_irqs;
> + ppc_md.msi_check_device = fsl_msi_check_device;
> + return 0;
> +error_out:
> + kfree(msi);
> + return err;
> +}
> +
> +static const struct fsl_msi_feature mpic_msi_feature = {
> + .fsl_pic_ip = FSL_PIC_IP_MPIC,
> + .msiir_offset = 0x140,
> +};
> +
> +static const struct fsl_msi_feature ipic_msi_feature = {
> + .fsl_pic_ip = FSL_PIC_IP_IPIC,
> + .msiir_offset = 0x38,
> +};
> +
> +static const struct of_device_id fsl_of_msi_ids[] = {
> + {
> + .compatible = "fsl,mpic-msi",
> + .data = (void *)&mpic_msi_feature,
> + },
> + {
> + .compatible = "fsl,ipic-msi",
> + .data = (void *)&ipic_msi_feature,
> + },
> + {}
> +};
> +
> +static struct of_platform_driver fsl_of_msi_driver = {
> + .name = "fsl-msi",
> + .match_table = fsl_of_msi_ids,
> + .probe = fsl_of_msi_probe,
> +};
> +
> +static __init int fsl_of_msi_init(void)
> +{
> + return of_register_platform_driver(&fsl_of_msi_driver);
> +}
> +
> +subsys_initcall(fsl_of_msi_init);
> diff --git a/arch/powerpc/sysdev/fsl_msi.h b/arch/powerpc/sysdev/fsl_msi.h
> new file mode 100644
> index 0000000..a653468
> --- /dev/null
> +++ b/arch/powerpc/sysdev/fsl_msi.h
> @@ -0,0 +1,42 @@
> +/*
> + * Copyright (C) 2007-2008 Freescale Semiconductor, Inc. All rights reserved.
> + *
> + * Author: Tony Li <tony.li@freescale.com>
> + * Jason Jin <Jason.jin@freescale.com>
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License
> + * as published by the Free Software Foundation; version 2 of the
> + * License.
> + *
> + */
> +#ifndef _POWERPC_SYSDEV_FSL_MSI_H
> +#define _POWERPC_SYSDEV_FSL_MSI_H
> +
> +#define NR_MSI_REG 8
> +#define IRQS_PER_MSI_REG 32
> +#define NR_MSI_IRQS (NR_MSI_REG * IRQS_PER_MSI_REG)
> +
> +#define FSL_PIC_IP_MASK 0x0000000F
> +#define FSL_PIC_IP_MPIC 0x00000001
> +#define FSL_PIC_IP_IPIC 0x00000002
> +
> +struct fsl_msi {
> + /* Device node of the MSI interrupt*/
> + struct device_node *of_node;
> +
> + struct irq_host *irqhost;
> +
> + unsigned long cascade_irq;
> +
> + u32 msi_addr_lo;
> + u32 msi_addr_hi;
> + void __iomem *msi_regs;
> + u32 feature;
> +
> + unsigned long *fsl_msi_bitmap;
> + spinlock_t bitmap_lock;
> +};
> +
> +#endif /* _POWERPC_SYSDEV_FSL_MSI_H */
> +
> diff --git a/arch/powerpc/sysdev/fsl_pci.c b/arch/powerpc/sysdev/fsl_pci.c
> index bf13c21..52a5f7f 100644
> --- a/arch/powerpc/sysdev/fsl_pci.c
> +++ b/arch/powerpc/sysdev/fsl_pci.c
> @@ -106,6 +106,16 @@ void __init setup_pci_cmd(struct pci_controller *hose)
> }
> }
>
> +#ifdef CONFIG_PCI_MSI
> +void __init setup_pci_pcsrbar(struct pci_controller *hose)
static?
> +{
> + phys_addr_t immr_base;
> +
> + immr_base = get_immrbase();
> + early_write_config_dword(hose, 0, 0, PCI_BASE_ADDRESS_0, immr_base);
> +}
#else
static inline void setup_pci_pcsrbar(struct pci_controller *hose) {}
^^ with this you can avoid #ifdef below
> +#endif
> +
> static int fsl_pcie_bus_fixup;
>
> static void __init quirk_fsl_pcie_header(struct pci_dev *dev)
> @@ -211,6 +221,10 @@ int __init fsl_add_bridge(struct device_node *dev, int is_primary)
> /* Setup PEX window registers */
> setup_pci_atmu(hose, &rsrc);
>
> + /* Setup PEXCSRBAR */
> +#ifdef CONFIG_PCI_MSI
> + setup_pci_pcsrbar(hose);
> +#endif
> return 0;
> }
>
> --
> 1.5.4
--
Anton Vorontsov
email: cbouatmailru@gmail.com
irc://irc.freenode.net/bd2
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 2/4 V6] MSI support on 83xx/85xx/86xx board
2008-05-23 12:59 ` [PATCH 2/4 V6] MSI support on 83xx/85xx/86xx board Anton Vorontsov
@ 2008-05-23 13:02 ` Kumar Gala
2008-05-23 13:41 ` [PATCH] [POWERPC] fsl_msi: few (mostly cosmetic) fixes Anton Vorontsov
2008-05-23 14:31 ` [PATCH 2/4 V6] MSI support on 83xx/85xx/86xx board Michael Ellerman
0 siblings, 2 replies; 14+ messages in thread
From: Kumar Gala @ 2008-05-23 13:02 UTC (permalink / raw)
To: avorontsov; +Cc: linuxppc-dev, Jason Jin
On May 23, 2008, at 7:59 AM, Anton Vorontsov wrote:
> On Fri, May 23, 2008 at 04:32:46PM +0800, Jason Jin wrote:
>> This MSI driver can be used on 83xx/85xx/86xx board.
>> In this driver, virtual interrupt host and chip were
>> setup. There are 256 MSI interrupts in this host, Every 32
>> MSI interrupts cascaded to one IPIC/MPIC interrupt.
>> The chip was treated as edge sensitive and some necessary
>> functions were setup for this chip.
>>
>> Before using the MSI interrupt, PCI/PCIE device need to
>> ask for a MSI interrupt in the 256 MSI interrupts. A 256bit
>> bitmap show which MSI interrupt was used, reserve bit in
>> the bitmap can be used to force the device use some designate
>> MSI interrupt in the 256 MSI interrupts. Sometimes this is useful
>> for testing the all the MSI interrupts. The msi-available-ranges
>> property in the dts file was used for this purpose.
>>
>> Signed-off-by: Jason Jin <Jason.jin@freescale.com>
>> ---
>
> Hello Jason,
>
> Few comments below.
Jason, I'll apply this version. I expect some clean up based on Anton
and Stephen's comments.
- k
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 1/4 V5] booting-without-of for Freescale MSI
2008-05-23 8:32 [PATCH 1/4 V5] booting-without-of for Freescale MSI Jason Jin
2008-05-23 8:32 ` [PATCH 2/4 V6] MSI support on 83xx/85xx/86xx board Jason Jin
@ 2008-05-23 13:05 ` Kumar Gala
1 sibling, 0 replies; 14+ messages in thread
From: Kumar Gala @ 2008-05-23 13:05 UTC (permalink / raw)
To: Jason Jin; +Cc: linuxppc-dev
On May 23, 2008, at 3:32 AM, Jason Jin wrote:
> Binding document adding for Freescale MSI support.
>
> Signed-off-by: Jason Jin <Jason.jin@freescale.com>
applied.
- k
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 3/4 V5] Enable MSI support for MPC8610HPCD board
2008-05-23 8:32 ` [PATCH 3/4 V5] Enable MSI support for MPC8610HPCD board Jason Jin
2008-05-23 8:32 ` [PATCH 4/4 V5] Enable MSI support for 85xxds board Jason Jin
@ 2008-05-23 13:05 ` Kumar Gala
1 sibling, 0 replies; 14+ messages in thread
From: Kumar Gala @ 2008-05-23 13:05 UTC (permalink / raw)
To: Jason Jin; +Cc: linuxppc-dev
On May 23, 2008, at 3:32 AM, Jason Jin wrote:
> This patch enable the MSI on 8610hpcd board.
> Through the msi-available-ranges property, All the 256
> msi interrupts can be tested on this board.
>
> Signed-off-by: Jason Jin <Jason.jin@freescale.com>
applied.
- k
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 4/4 V5] Enable MSI support for 85xxds board
2008-05-23 8:32 ` [PATCH 4/4 V5] Enable MSI support for 85xxds board Jason Jin
@ 2008-05-23 13:06 ` Kumar Gala
0 siblings, 0 replies; 14+ messages in thread
From: Kumar Gala @ 2008-05-23 13:06 UTC (permalink / raw)
To: Jason Jin; +Cc: linuxppc-dev
On May 23, 2008, at 3:32 AM, Jason Jin wrote:
> This patch enabled MSI on 8544ds and 8572ds board.
> So far only one MSI interrupt can generate on 8544 board.
What is the issue on 8544?
> Signed-off-by: Jason Jin <Jason.jin@freescale.com>
applied.
- k
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 2/4 V6] MSI support on 83xx/85xx/86xx board
2008-05-23 8:32 ` [PATCH 2/4 V6] MSI support on 83xx/85xx/86xx board Jason Jin
2008-05-23 8:32 ` [PATCH 3/4 V5] Enable MSI support for MPC8610HPCD board Jason Jin
2008-05-23 12:59 ` [PATCH 2/4 V6] MSI support on 83xx/85xx/86xx board Anton Vorontsov
@ 2008-05-23 13:06 ` Kumar Gala
2 siblings, 0 replies; 14+ messages in thread
From: Kumar Gala @ 2008-05-23 13:06 UTC (permalink / raw)
To: Jason Jin; +Cc: linuxppc-dev
On May 23, 2008, at 3:32 AM, Jason Jin wrote:
> This MSI driver can be used on 83xx/85xx/86xx board.
> In this driver, virtual interrupt host and chip were
> setup. There are 256 MSI interrupts in this host, Every 32
> MSI interrupts cascaded to one IPIC/MPIC interrupt.
> The chip was treated as edge sensitive and some necessary
> functions were setup for this chip.
>
> Before using the MSI interrupt, PCI/PCIE device need to
> ask for a MSI interrupt in the 256 MSI interrupts. A 256bit
> bitmap show which MSI interrupt was used, reserve bit in
> the bitmap can be used to force the device use some designate
> MSI interrupt in the 256 MSI interrupts. Sometimes this is useful
> for testing the all the MSI interrupts. The msi-available-ranges
> property in the dts file was used for this purpose.
>
> Signed-off-by: Jason Jin <Jason.jin@freescale.com>
applied.
- k
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH] [POWERPC] fsl_msi: few (mostly cosmetic) fixes
2008-05-23 13:02 ` Kumar Gala
@ 2008-05-23 13:41 ` Anton Vorontsov
2008-05-24 4:48 ` Kumar Gala
2008-05-23 14:31 ` [PATCH 2/4 V6] MSI support on 83xx/85xx/86xx board Michael Ellerman
1 sibling, 1 reply; 14+ messages in thread
From: Anton Vorontsov @ 2008-05-23 13:41 UTC (permalink / raw)
To: Kumar Gala; +Cc: linuxppc-dev, Jason Jin
This patch fixes few cosmetic issues, also removes unused function,
makes some functions static and reduces #ifdef count.
Signed-off-by: Anton Vorontsov <avorontsov@ru.mvista.com>
---
On Fri, May 23, 2008 at 08:02:39AM -0500, Kumar Gala wrote:
>
> On May 23, 2008, at 7:59 AM, Anton Vorontsov wrote:
>
>> On Fri, May 23, 2008 at 04:32:46PM +0800, Jason Jin wrote:
>>> This MSI driver can be used on 83xx/85xx/86xx board.
>>> In this driver, virtual interrupt host and chip were
>>> setup. There are 256 MSI interrupts in this host, Every 32
>>> MSI interrupts cascaded to one IPIC/MPIC interrupt.
>>> The chip was treated as edge sensitive and some necessary
>>> functions were setup for this chip.
>>>
>>> Before using the MSI interrupt, PCI/PCIE device need to
>>> ask for a MSI interrupt in the 256 MSI interrupts. A 256bit
>>> bitmap show which MSI interrupt was used, reserve bit in
>>> the bitmap can be used to force the device use some designate
>>> MSI interrupt in the 256 MSI interrupts. Sometimes this is useful
>>> for testing the all the MSI interrupts. The msi-available-ranges
>>> property in the dts file was used for this purpose.
>>>
>>> Signed-off-by: Jason Jin <Jason.jin@freescale.com>
>>> ---
>>
>> Hello Jason,
>>
>> Few comments below.
>
> Jason, I'll apply this version. I expect some clean up based on Anton
> and Stephen's comments.
Yeah, was a bit late review. Just in case, here is the cleanup
based on my comments.
arch/powerpc/sysdev/fsl_msi.c | 43 +++++++++++++++++-----------------------
arch/powerpc/sysdev/fsl_pci.c | 8 ++----
2 files changed, 21 insertions(+), 30 deletions(-)
diff --git a/arch/powerpc/sysdev/fsl_msi.c b/arch/powerpc/sysdev/fsl_msi.c
index 9d0685b..2c5187c 100644
--- a/arch/powerpc/sysdev/fsl_msi.c
+++ b/arch/powerpc/sysdev/fsl_msi.c
@@ -36,12 +36,6 @@ static inline u32 fsl_msi_read(u32 __iomem *base, unsigned int reg)
return in_be32(base + (reg >> 2));
}
-static inline void fsl_msi_write(u32 __iomem *base,
- unsigned int reg, u32 value)
-{
- out_be32(base + (reg >> 2), value);
-}
-
/*
* We do not need this actually. The MSIR register has been read once
* in the cascade interrupt. So, this MSI interrupt has been acked
@@ -64,7 +58,7 @@ static int fsl_msi_host_map(struct irq_host *h, unsigned int virq,
get_irq_desc(virq)->status |= IRQ_TYPE_EDGE_FALLING;
- set_irq_chip_and_handler(virq, chip, handle_edge_irq);
+ set_irq_chip_and_handler(virq, chip, handle_edge_irq);
return 0;
}
@@ -73,10 +67,11 @@ static struct irq_host_ops fsl_msi_host_ops = {
.map = fsl_msi_host_map,
};
-irq_hw_number_t fsl_msi_alloc_hwirqs(struct fsl_msi *msi, int num)
+static irq_hw_number_t fsl_msi_alloc_hwirqs(struct fsl_msi *msi, int num)
{
unsigned long flags;
- int offset, order = get_count_order(num);
+ int order = get_count_order(num);
+ int offset;
spin_lock_irqsave(&msi->bitmap_lock, flags);
@@ -91,7 +86,7 @@ irq_hw_number_t fsl_msi_alloc_hwirqs(struct fsl_msi *msi, int num)
return offset;
}
-void fsl_msi_free_hwirqs(struct fsl_msi *msi, int offset, int num)
+static void fsl_msi_free_hwirqs(struct fsl_msi *msi, int offset, int num)
{
unsigned long flags;
int order = get_count_order(num);
@@ -106,7 +101,8 @@ void fsl_msi_free_hwirqs(struct fsl_msi *msi, int offset, int num)
static int fsl_msi_free_dt_hwirqs(struct fsl_msi *msi)
{
- int i, len;
+ int i;
+ int len;
const u32 *p;
bitmap_allocate_region(msi->fsl_msi_bitmap, 0,
@@ -138,9 +134,8 @@ static int fsl_msi_free_dt_hwirqs(struct fsl_msi *msi)
static int fsl_msi_init_allocator(struct fsl_msi *msi_data)
{
- int rc, size;
-
- size = BITS_TO_LONGS(NR_MSI_IRQS) * sizeof(u32);
+ int rc;
+ int size = BITS_TO_LONGS(NR_MSI_IRQS) * sizeof(u32);
msi_data->fsl_msi_bitmap = kzalloc(size, GFP_KERNEL);
@@ -238,7 +233,7 @@ out_free:
return rc;
}
-void fsl_msi_cascade(unsigned int irq, struct irq_desc *desc)
+static void fsl_msi_cascade(unsigned int irq, struct irq_desc *desc)
{
unsigned int cascade_irq;
struct fsl_msi *msi_data = fsl_msi;
@@ -260,7 +255,7 @@ void fsl_msi_cascade(unsigned int irq, struct irq_desc *desc)
if (unlikely(desc->status & IRQ_INPROGRESS))
goto unlock;
- msir_index = (int)(desc->handler_data);
+ msir_index = (int)desc->handler_data;
if (msir_index >= NR_MSI_REG)
cascade_irq = NO_IRQ;
@@ -280,12 +275,12 @@ void fsl_msi_cascade(unsigned int irq, struct irq_desc *desc)
intr_index = ffs(msir_value) - 1;
cascade_irq = irq_linear_revmap(msi_data->irqhost,
- (msir_index * IRQS_PER_MSI_REG +
- intr_index + have_shift));
+ msir_index * IRQS_PER_MSI_REG +
+ intr_index + have_shift);
if (cascade_irq != NO_IRQ)
generic_handle_irq(cascade_irq);
- have_shift += (intr_index + 1);
- msir_value = (msir_value >> (intr_index + 1));
+ have_shift += intr_index + 1;
+ msir_value = msir_value >> (intr_index + 1);
}
desc->status &= ~IRQ_INPROGRESS;
@@ -311,7 +306,7 @@ static int __devinit fsl_of_msi_probe(struct of_device *dev,
int rc;
int virt_msir;
const u32 *p;
- struct fsl_msi_feature *tmp_data;
+ struct fsl_msi_feature *features = match->data;
printk(KERN_DEBUG "Setting up Freescale MSI support\n");
@@ -348,14 +343,12 @@ static int __devinit fsl_of_msi_probe(struct of_device *dev,
goto error_out;
}
- tmp_data = (struct fsl_msi_feature *)match->data;
-
- msi->feature = tmp_data->fsl_pic_ip;
+ msi->feature = features->fsl_pic_ip;
msi->irqhost->host_data = msi;
msi->msi_addr_hi = 0x0;
- msi->msi_addr_lo = res.start + tmp_data->msiir_offset;
+ msi->msi_addr_lo = res.start + features->msiir_offset;
rc = fsl_msi_init_allocator(msi);
if (rc) {
diff --git a/arch/powerpc/sysdev/fsl_pci.c b/arch/powerpc/sysdev/fsl_pci.c
index 52a5f7f..489ca5a 100644
--- a/arch/powerpc/sysdev/fsl_pci.c
+++ b/arch/powerpc/sysdev/fsl_pci.c
@@ -106,15 +106,15 @@ void __init setup_pci_cmd(struct pci_controller *hose)
}
}
-#ifdef CONFIG_PCI_MSI
-void __init setup_pci_pcsrbar(struct pci_controller *hose)
+static void __init setup_pci_pcsrbar(struct pci_controller *hose)
{
+#ifdef CONFIG_PCI_MSI
phys_addr_t immr_base;
immr_base = get_immrbase();
early_write_config_dword(hose, 0, 0, PCI_BASE_ADDRESS_0, immr_base);
-}
#endif
+}
static int fsl_pcie_bus_fixup;
@@ -222,9 +222,7 @@ int __init fsl_add_bridge(struct device_node *dev, int is_primary)
setup_pci_atmu(hose, &rsrc);
/* Setup PEXCSRBAR */
-#ifdef CONFIG_PCI_MSI
setup_pci_pcsrbar(hose);
-#endif
return 0;
}
--
1.5.5.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH 2/4 V6] MSI support on 83xx/85xx/86xx board
2008-05-23 13:02 ` Kumar Gala
2008-05-23 13:41 ` [PATCH] [POWERPC] fsl_msi: few (mostly cosmetic) fixes Anton Vorontsov
@ 2008-05-23 14:31 ` Michael Ellerman
1 sibling, 0 replies; 14+ messages in thread
From: Michael Ellerman @ 2008-05-23 14:31 UTC (permalink / raw)
To: Kumar Gala; +Cc: linuxppc-dev, Jason Jin
[-- Attachment #1: Type: text/plain, Size: 1550 bytes --]
On Fri, 2008-05-23 at 08:02 -0500, Kumar Gala wrote:
> On May 23, 2008, at 7:59 AM, Anton Vorontsov wrote:
>
> > On Fri, May 23, 2008 at 04:32:46PM +0800, Jason Jin wrote:
> >> This MSI driver can be used on 83xx/85xx/86xx board.
> >> In this driver, virtual interrupt host and chip were
> >> setup. There are 256 MSI interrupts in this host, Every 32
> >> MSI interrupts cascaded to one IPIC/MPIC interrupt.
> >> The chip was treated as edge sensitive and some necessary
> >> functions were setup for this chip.
> >>
> >> Before using the MSI interrupt, PCI/PCIE device need to
> >> ask for a MSI interrupt in the 256 MSI interrupts. A 256bit
> >> bitmap show which MSI interrupt was used, reserve bit in
> >> the bitmap can be used to force the device use some designate
> >> MSI interrupt in the 256 MSI interrupts. Sometimes this is useful
> >> for testing the all the MSI interrupts. The msi-available-ranges
> >> property in the dts file was used for this purpose.
> >>
> >> Signed-off-by: Jason Jin <Jason.jin@freescale.com>
> >> ---
> >
> > Hello Jason,
> >
> > Few comments below.
>
> Jason, I'll apply this version. I expect some clean up based on Anton
> and Stephen's comments.
Version 4 or 5 of this patch had my ACK for the MSI bits FWIW.
cheers
--
Michael Ellerman
OzLabs, IBM Australia Development Lab
wwweb: http://michael.ellerman.id.au
phone: +61 2 6212 1183 (tie line 70 21183)
We do not inherit the earth from our ancestors,
we borrow it from our children. - S.M.A.R.T Person
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH] [POWERPC] fsl_msi: few (mostly cosmetic) fixes
2008-05-23 13:41 ` [PATCH] [POWERPC] fsl_msi: few (mostly cosmetic) fixes Anton Vorontsov
@ 2008-05-24 4:48 ` Kumar Gala
0 siblings, 0 replies; 14+ messages in thread
From: Kumar Gala @ 2008-05-24 4:48 UTC (permalink / raw)
To: avorontsov; +Cc: linuxppc-dev, Jason Jin
On May 23, 2008, at 8:41 AM, Anton Vorontsov wrote:
> This patch fixes few cosmetic issues, also removes unused function,
> makes some functions static and reduces #ifdef count.
>
> Signed-off-by: Anton Vorontsov <avorontsov@ru.mvista.com>
> ---
applied.
- k
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2008-05-24 4:49 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-05-23 8:32 [PATCH 1/4 V5] booting-without-of for Freescale MSI Jason Jin
2008-05-23 8:32 ` [PATCH 2/4 V6] MSI support on 83xx/85xx/86xx board Jason Jin
2008-05-23 8:32 ` [PATCH 3/4 V5] Enable MSI support for MPC8610HPCD board Jason Jin
2008-05-23 8:32 ` [PATCH 4/4 V5] Enable MSI support for 85xxds board Jason Jin
2008-05-23 13:06 ` Kumar Gala
2008-05-23 13:05 ` [PATCH 3/4 V5] Enable MSI support for MPC8610HPCD board Kumar Gala
2008-05-23 12:59 ` [PATCH 2/4 V6] MSI support on 83xx/85xx/86xx board Anton Vorontsov
2008-05-23 13:02 ` Kumar Gala
2008-05-23 13:41 ` [PATCH] [POWERPC] fsl_msi: few (mostly cosmetic) fixes Anton Vorontsov
2008-05-24 4:48 ` Kumar Gala
2008-05-23 14:31 ` [PATCH 2/4 V6] MSI support on 83xx/85xx/86xx board Michael Ellerman
2008-05-23 13:06 ` Kumar Gala
2008-05-23 13:05 ` [PATCH 1/4 V5] booting-without-of for Freescale MSI Kumar Gala
-- strict thread matches above, loose matches on Subject: below --
2008-05-20 8:07 [PATCH 1/4 V4] " Jason Jin
2008-05-20 8:07 ` [PATCH 2/4 V6] MSI support on 83xx/85xx/86xx board Jason Jin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).