Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 1 | /* |
Lan Chunhe-B25806 | 8081881 | 2010-03-15 06:38:33 +0000 | [diff] [blame] | 2 | * Copyright (C) 2007-2010 Freescale Semiconductor, Inc. |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 3 | * |
| 4 | * Author: Tony Li <tony.li@freescale.com> |
| 5 | * Jason Jin <Jason.jin@freescale.com> |
| 6 | * |
| 7 | * The hwirq alloc and free code reuse from sysdev/mpic_msi.c |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License |
| 11 | * as published by the Free Software Foundation; version 2 of the |
| 12 | * License. |
| 13 | * |
| 14 | */ |
| 15 | #include <linux/irq.h> |
| 16 | #include <linux/bootmem.h> |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 17 | #include <linux/msi.h> |
| 18 | #include <linux/pci.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 19 | #include <linux/slab.h> |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 20 | #include <linux/of_platform.h> |
| 21 | #include <sysdev/fsl_soc.h> |
| 22 | #include <asm/prom.h> |
| 23 | #include <asm/hw_irq.h> |
| 24 | #include <asm/ppc-pci.h> |
Li Yang | 02adac6 | 2010-04-22 16:31:35 +0800 | [diff] [blame] | 25 | #include <asm/mpic.h> |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 26 | #include "fsl_msi.h" |
| 27 | |
Li Yang | 694a7a3 | 2010-04-22 16:31:36 +0800 | [diff] [blame] | 28 | LIST_HEAD(msi_head); |
| 29 | |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 30 | struct fsl_msi_feature { |
| 31 | u32 fsl_pic_ip; |
| 32 | u32 msiir_offset; |
| 33 | }; |
| 34 | |
Li Yang | 02adac6 | 2010-04-22 16:31:35 +0800 | [diff] [blame] | 35 | struct fsl_msi_cascade_data { |
| 36 | struct fsl_msi *msi_data; |
| 37 | int index; |
| 38 | }; |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 39 | |
| 40 | static inline u32 fsl_msi_read(u32 __iomem *base, unsigned int reg) |
| 41 | { |
| 42 | return in_be32(base + (reg >> 2)); |
| 43 | } |
| 44 | |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 45 | /* |
| 46 | * We do not need this actually. The MSIR register has been read once |
| 47 | * in the cascade interrupt. So, this MSI interrupt has been acked |
| 48 | */ |
| 49 | static void fsl_msi_end_irq(unsigned int virq) |
| 50 | { |
| 51 | } |
| 52 | |
| 53 | static struct irq_chip fsl_msi_chip = { |
| 54 | .mask = mask_msi_irq, |
| 55 | .unmask = unmask_msi_irq, |
| 56 | .ack = fsl_msi_end_irq, |
Anton Blanchard | fc380c0 | 2010-01-31 20:33:41 +0000 | [diff] [blame] | 57 | .name = "FSL-MSI", |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | static int fsl_msi_host_map(struct irq_host *h, unsigned int virq, |
| 61 | irq_hw_number_t hw) |
| 62 | { |
Lan Chunhe-B25806 | 8081881 | 2010-03-15 06:38:33 +0000 | [diff] [blame] | 63 | struct fsl_msi *msi_data = h->host_data; |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 64 | struct irq_chip *chip = &fsl_msi_chip; |
| 65 | |
Michael Ellerman | 6cff46f | 2009-10-13 19:44:51 +0000 | [diff] [blame] | 66 | irq_to_desc(virq)->status |= IRQ_TYPE_EDGE_FALLING; |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 67 | |
Lan Chunhe-B25806 | 8081881 | 2010-03-15 06:38:33 +0000 | [diff] [blame] | 68 | set_irq_chip_data(virq, msi_data); |
Anton Vorontsov | 692d103 | 2008-05-23 17:41:02 +0400 | [diff] [blame] | 69 | set_irq_chip_and_handler(virq, chip, handle_edge_irq); |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 70 | |
| 71 | return 0; |
| 72 | } |
| 73 | |
| 74 | static struct irq_host_ops fsl_msi_host_ops = { |
| 75 | .map = fsl_msi_host_map, |
| 76 | }; |
| 77 | |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 78 | static int fsl_msi_init_allocator(struct fsl_msi *msi_data) |
| 79 | { |
Anton Vorontsov | 692d103 | 2008-05-23 17:41:02 +0400 | [diff] [blame] | 80 | int rc; |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 81 | |
Michael Ellerman | 7e7ab36 | 2008-08-06 09:10:02 +1000 | [diff] [blame] | 82 | rc = msi_bitmap_alloc(&msi_data->bitmap, NR_MSI_IRQS, |
| 83 | msi_data->irqhost->of_node); |
| 84 | if (rc) |
| 85 | return rc; |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 86 | |
Michael Ellerman | 7e7ab36 | 2008-08-06 09:10:02 +1000 | [diff] [blame] | 87 | rc = msi_bitmap_reserve_dt_hwirqs(&msi_data->bitmap); |
| 88 | if (rc < 0) { |
| 89 | msi_bitmap_free(&msi_data->bitmap); |
| 90 | return rc; |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 91 | } |
| 92 | |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 93 | return 0; |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | static int fsl_msi_check_device(struct pci_dev *pdev, int nvec, int type) |
| 97 | { |
| 98 | if (type == PCI_CAP_ID_MSIX) |
| 99 | pr_debug("fslmsi: MSI-X untested, trying anyway.\n"); |
| 100 | |
| 101 | return 0; |
| 102 | } |
| 103 | |
| 104 | static void fsl_teardown_msi_irqs(struct pci_dev *pdev) |
| 105 | { |
| 106 | struct msi_desc *entry; |
Lan Chunhe-B25806 | 8081881 | 2010-03-15 06:38:33 +0000 | [diff] [blame] | 107 | struct fsl_msi *msi_data; |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 108 | |
| 109 | list_for_each_entry(entry, &pdev->msi_list, list) { |
| 110 | if (entry->irq == NO_IRQ) |
| 111 | continue; |
Li Yang | 02adac6 | 2010-04-22 16:31:35 +0800 | [diff] [blame] | 112 | msi_data = get_irq_data(entry->irq); |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 113 | set_irq_msi(entry->irq, NULL); |
Michael Ellerman | 7e7ab36 | 2008-08-06 09:10:02 +1000 | [diff] [blame] | 114 | msi_bitmap_free_hwirqs(&msi_data->bitmap, |
| 115 | virq_to_hw(entry->irq), 1); |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 116 | irq_dispose_mapping(entry->irq); |
| 117 | } |
| 118 | |
| 119 | return; |
| 120 | } |
| 121 | |
| 122 | static void fsl_compose_msi_msg(struct pci_dev *pdev, int hwirq, |
Lan Chunhe-B25806 | 8081881 | 2010-03-15 06:38:33 +0000 | [diff] [blame] | 123 | struct msi_msg *msg, |
| 124 | struct fsl_msi *fsl_msi_data) |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 125 | { |
Lan Chunhe-B25806 | 8081881 | 2010-03-15 06:38:33 +0000 | [diff] [blame] | 126 | struct fsl_msi *msi_data = fsl_msi_data; |
Kumar Gala | 3da34aa | 2009-05-12 15:51:56 -0500 | [diff] [blame] | 127 | struct pci_controller *hose = pci_bus_to_host(pdev->bus); |
| 128 | u32 base = 0; |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 129 | |
Kumar Gala | 3da34aa | 2009-05-12 15:51:56 -0500 | [diff] [blame] | 130 | pci_bus_read_config_dword(hose->bus, |
| 131 | PCI_DEVFN(0, 0), PCI_BASE_ADDRESS_0, &base); |
| 132 | |
| 133 | msg->address_lo = msi_data->msi_addr_lo + base; |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 134 | msg->address_hi = msi_data->msi_addr_hi; |
| 135 | msg->data = hwirq; |
| 136 | |
| 137 | pr_debug("%s: allocated srs: %d, ibs: %d\n", |
| 138 | __func__, hwirq / IRQS_PER_MSI_REG, hwirq % IRQS_PER_MSI_REG); |
| 139 | } |
| 140 | |
| 141 | static int fsl_setup_msi_irqs(struct pci_dev *pdev, int nvec, int type) |
| 142 | { |
Li Yang | 694a7a3 | 2010-04-22 16:31:36 +0800 | [diff] [blame] | 143 | int rc, hwirq = -ENOMEM; |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 144 | unsigned int virq; |
| 145 | struct msi_desc *entry; |
| 146 | struct msi_msg msg; |
Lan Chunhe-B25806 | 8081881 | 2010-03-15 06:38:33 +0000 | [diff] [blame] | 147 | struct fsl_msi *msi_data; |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 148 | |
| 149 | list_for_each_entry(entry, &pdev->msi_list, list) { |
Li Yang | 694a7a3 | 2010-04-22 16:31:36 +0800 | [diff] [blame] | 150 | list_for_each_entry(msi_data, &msi_head, list) { |
| 151 | hwirq = msi_bitmap_alloc_hwirqs(&msi_data->bitmap, 1); |
| 152 | if (hwirq >= 0) |
| 153 | break; |
| 154 | } |
Lan Chunhe-B25806 | 8081881 | 2010-03-15 06:38:33 +0000 | [diff] [blame] | 155 | |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 156 | if (hwirq < 0) { |
| 157 | rc = hwirq; |
| 158 | pr_debug("%s: fail allocating msi interrupt\n", |
| 159 | __func__); |
| 160 | goto out_free; |
| 161 | } |
| 162 | |
| 163 | virq = irq_create_mapping(msi_data->irqhost, hwirq); |
| 164 | |
| 165 | if (virq == NO_IRQ) { |
Michael Ellerman | 7e7ab36 | 2008-08-06 09:10:02 +1000 | [diff] [blame] | 166 | pr_debug("%s: fail mapping hwirq 0x%x\n", |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 167 | __func__, hwirq); |
Michael Ellerman | 7e7ab36 | 2008-08-06 09:10:02 +1000 | [diff] [blame] | 168 | msi_bitmap_free_hwirqs(&msi_data->bitmap, hwirq, 1); |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 169 | rc = -ENOSPC; |
| 170 | goto out_free; |
| 171 | } |
Li Yang | 02adac6 | 2010-04-22 16:31:35 +0800 | [diff] [blame] | 172 | set_irq_data(virq, msi_data); |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 173 | set_irq_msi(virq, entry); |
| 174 | |
Lan Chunhe-B25806 | 8081881 | 2010-03-15 06:38:33 +0000 | [diff] [blame] | 175 | fsl_compose_msi_msg(pdev, hwirq, &msg, msi_data); |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 176 | write_msi_msg(virq, &msg); |
| 177 | } |
| 178 | return 0; |
| 179 | |
| 180 | out_free: |
Li Yang | 694a7a3 | 2010-04-22 16:31:36 +0800 | [diff] [blame] | 181 | /* free by the caller of this function */ |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 182 | return rc; |
| 183 | } |
| 184 | |
Anton Vorontsov | 692d103 | 2008-05-23 17:41:02 +0400 | [diff] [blame] | 185 | static void fsl_msi_cascade(unsigned int irq, struct irq_desc *desc) |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 186 | { |
| 187 | unsigned int cascade_irq; |
Li Yang | 02adac6 | 2010-04-22 16:31:35 +0800 | [diff] [blame] | 188 | struct fsl_msi *msi_data; |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 189 | int msir_index = -1; |
| 190 | u32 msir_value = 0; |
| 191 | u32 intr_index; |
| 192 | u32 have_shift = 0; |
Li Yang | 02adac6 | 2010-04-22 16:31:35 +0800 | [diff] [blame] | 193 | struct fsl_msi_cascade_data *cascade_data; |
| 194 | |
| 195 | cascade_data = (struct fsl_msi_cascade_data *)get_irq_data(irq); |
| 196 | msi_data = cascade_data->msi_data; |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 197 | |
Thomas Gleixner | 239007b | 2009-11-17 16:46:45 +0100 | [diff] [blame] | 198 | raw_spin_lock(&desc->lock); |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 199 | if ((msi_data->feature & FSL_PIC_IP_MASK) == FSL_PIC_IP_IPIC) { |
| 200 | if (desc->chip->mask_ack) |
| 201 | desc->chip->mask_ack(irq); |
| 202 | else { |
| 203 | desc->chip->mask(irq); |
| 204 | desc->chip->ack(irq); |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | if (unlikely(desc->status & IRQ_INPROGRESS)) |
| 209 | goto unlock; |
| 210 | |
Li Yang | 02adac6 | 2010-04-22 16:31:35 +0800 | [diff] [blame] | 211 | msir_index = cascade_data->index; |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 212 | |
| 213 | if (msir_index >= NR_MSI_REG) |
| 214 | cascade_irq = NO_IRQ; |
| 215 | |
| 216 | desc->status |= IRQ_INPROGRESS; |
Lan Chunhe-B25806 | 8081881 | 2010-03-15 06:38:33 +0000 | [diff] [blame] | 217 | switch (msi_data->feature & FSL_PIC_IP_MASK) { |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 218 | case FSL_PIC_IP_MPIC: |
| 219 | msir_value = fsl_msi_read(msi_data->msi_regs, |
| 220 | msir_index * 0x10); |
| 221 | break; |
| 222 | case FSL_PIC_IP_IPIC: |
| 223 | msir_value = fsl_msi_read(msi_data->msi_regs, msir_index * 0x4); |
| 224 | break; |
| 225 | } |
| 226 | |
| 227 | while (msir_value) { |
| 228 | intr_index = ffs(msir_value) - 1; |
| 229 | |
| 230 | cascade_irq = irq_linear_revmap(msi_data->irqhost, |
Anton Vorontsov | 692d103 | 2008-05-23 17:41:02 +0400 | [diff] [blame] | 231 | msir_index * IRQS_PER_MSI_REG + |
| 232 | intr_index + have_shift); |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 233 | if (cascade_irq != NO_IRQ) |
| 234 | generic_handle_irq(cascade_irq); |
Anton Vorontsov | 692d103 | 2008-05-23 17:41:02 +0400 | [diff] [blame] | 235 | have_shift += intr_index + 1; |
| 236 | msir_value = msir_value >> (intr_index + 1); |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 237 | } |
| 238 | desc->status &= ~IRQ_INPROGRESS; |
| 239 | |
| 240 | switch (msi_data->feature & FSL_PIC_IP_MASK) { |
| 241 | case FSL_PIC_IP_MPIC: |
| 242 | desc->chip->eoi(irq); |
| 243 | break; |
| 244 | case FSL_PIC_IP_IPIC: |
| 245 | if (!(desc->status & IRQ_DISABLED) && desc->chip->unmask) |
| 246 | desc->chip->unmask(irq); |
| 247 | break; |
| 248 | } |
| 249 | unlock: |
Thomas Gleixner | 239007b | 2009-11-17 16:46:45 +0100 | [diff] [blame] | 250 | raw_spin_unlock(&desc->lock); |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 251 | } |
| 252 | |
Li Yang | 4805999 | 2010-04-22 16:31:39 +0800 | [diff] [blame] | 253 | static int fsl_of_msi_remove(struct of_device *ofdev) |
| 254 | { |
| 255 | struct fsl_msi *msi = ofdev->dev.platform_data; |
| 256 | int virq, i; |
| 257 | struct fsl_msi_cascade_data *cascade_data; |
| 258 | |
| 259 | if (msi->list.prev != NULL) |
| 260 | list_del(&msi->list); |
| 261 | for (i = 0; i < NR_MSI_REG; i++) { |
| 262 | virq = msi->msi_virqs[i]; |
| 263 | if (virq != NO_IRQ) { |
| 264 | cascade_data = get_irq_data(virq); |
| 265 | kfree(cascade_data); |
| 266 | irq_dispose_mapping(virq); |
| 267 | } |
| 268 | } |
| 269 | if (msi->bitmap.bitmap) |
| 270 | msi_bitmap_free(&msi->bitmap); |
| 271 | iounmap(msi->msi_regs); |
| 272 | kfree(msi); |
| 273 | |
| 274 | return 0; |
| 275 | } |
| 276 | |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 277 | static int __devinit fsl_of_msi_probe(struct of_device *dev, |
| 278 | const struct of_device_id *match) |
| 279 | { |
| 280 | struct fsl_msi *msi; |
| 281 | struct resource res; |
| 282 | int err, i, count; |
| 283 | int rc; |
| 284 | int virt_msir; |
| 285 | const u32 *p; |
Anton Vorontsov | 692d103 | 2008-05-23 17:41:02 +0400 | [diff] [blame] | 286 | struct fsl_msi_feature *features = match->data; |
Li Yang | 02adac6 | 2010-04-22 16:31:35 +0800 | [diff] [blame] | 287 | struct fsl_msi_cascade_data *cascade_data = NULL; |
Li Yang | 061ca4a | 2010-04-22 16:31:37 +0800 | [diff] [blame] | 288 | int len; |
| 289 | u32 offset; |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 290 | |
| 291 | printk(KERN_DEBUG "Setting up Freescale MSI support\n"); |
| 292 | |
| 293 | msi = kzalloc(sizeof(struct fsl_msi), GFP_KERNEL); |
| 294 | if (!msi) { |
| 295 | dev_err(&dev->dev, "No memory for MSI structure\n"); |
Li Yang | 4805999 | 2010-04-22 16:31:39 +0800 | [diff] [blame] | 296 | return -ENOMEM; |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 297 | } |
Li Yang | 4805999 | 2010-04-22 16:31:39 +0800 | [diff] [blame] | 298 | dev->dev.platform_data = msi; |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 299 | |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 300 | msi->irqhost = irq_alloc_host(dev->dev.of_node, IRQ_HOST_MAP_LINEAR, |
Michael Ellerman | 611cd90 | 2008-08-06 09:10:00 +1000 | [diff] [blame] | 301 | NR_MSI_IRQS, &fsl_msi_host_ops, 0); |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 302 | |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 303 | if (msi->irqhost == NULL) { |
| 304 | dev_err(&dev->dev, "No memory for MSI irqhost\n"); |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 305 | err = -ENOMEM; |
| 306 | goto error_out; |
| 307 | } |
| 308 | |
| 309 | /* Get the MSI reg base */ |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 310 | err = of_address_to_resource(dev->dev.of_node, 0, &res); |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 311 | if (err) { |
| 312 | dev_err(&dev->dev, "%s resource error!\n", |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 313 | dev->dev.of_node->full_name); |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 314 | goto error_out; |
| 315 | } |
| 316 | |
| 317 | msi->msi_regs = ioremap(res.start, res.end - res.start + 1); |
| 318 | if (!msi->msi_regs) { |
| 319 | dev_err(&dev->dev, "ioremap problem failed\n"); |
| 320 | goto error_out; |
| 321 | } |
| 322 | |
Anton Vorontsov | 692d103 | 2008-05-23 17:41:02 +0400 | [diff] [blame] | 323 | msi->feature = features->fsl_pic_ip; |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 324 | |
| 325 | msi->irqhost->host_data = msi; |
| 326 | |
| 327 | msi->msi_addr_hi = 0x0; |
Kumar Gala | 3da34aa | 2009-05-12 15:51:56 -0500 | [diff] [blame] | 328 | msi->msi_addr_lo = features->msiir_offset + (res.start & 0xfffff); |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 329 | |
| 330 | rc = fsl_msi_init_allocator(msi); |
| 331 | if (rc) { |
| 332 | dev_err(&dev->dev, "Error allocating MSI bitmap\n"); |
| 333 | goto error_out; |
| 334 | } |
| 335 | |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 336 | p = of_get_property(dev->dev.of_node, "interrupts", &count); |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 337 | if (!p) { |
| 338 | dev_err(&dev->dev, "no interrupts property found on %s\n", |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 339 | dev->dev.of_node->full_name); |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 340 | err = -ENODEV; |
| 341 | goto error_out; |
| 342 | } |
| 343 | if (count % 8 != 0) { |
| 344 | dev_err(&dev->dev, "Malformed interrupts property on %s\n", |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 345 | dev->dev.of_node->full_name); |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 346 | err = -EINVAL; |
| 347 | goto error_out; |
| 348 | } |
Li Yang | 061ca4a | 2010-04-22 16:31:37 +0800 | [diff] [blame] | 349 | offset = 0; |
Wolfram Sang | ee227c5 | 2010-06-03 06:03:46 +0200 | [diff] [blame] | 350 | p = of_get_property(dev->dev.of_node, "msi-available-ranges", &len); |
Li Yang | 061ca4a | 2010-04-22 16:31:37 +0800 | [diff] [blame] | 351 | if (p) |
| 352 | offset = *p / IRQS_PER_MSI_REG; |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 353 | |
| 354 | count /= sizeof(u32); |
Li Yang | 4805999 | 2010-04-22 16:31:39 +0800 | [diff] [blame] | 355 | for (i = 0; i < min(count / 2, NR_MSI_REG); i++) { |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 356 | virt_msir = irq_of_parse_and_map(dev->dev.of_node, i); |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 357 | if (virt_msir != NO_IRQ) { |
Li Yang | 02adac6 | 2010-04-22 16:31:35 +0800 | [diff] [blame] | 358 | cascade_data = kzalloc( |
| 359 | sizeof(struct fsl_msi_cascade_data), |
| 360 | GFP_KERNEL); |
| 361 | if (!cascade_data) { |
| 362 | dev_err(&dev->dev, |
| 363 | "No memory for MSI cascade data\n"); |
| 364 | err = -ENOMEM; |
| 365 | goto error_out; |
| 366 | } |
Li Yang | 4805999 | 2010-04-22 16:31:39 +0800 | [diff] [blame] | 367 | msi->msi_virqs[i] = virt_msir; |
Li Yang | 061ca4a | 2010-04-22 16:31:37 +0800 | [diff] [blame] | 368 | cascade_data->index = i + offset; |
Li Yang | 02adac6 | 2010-04-22 16:31:35 +0800 | [diff] [blame] | 369 | cascade_data->msi_data = msi; |
| 370 | set_irq_data(virt_msir, (void *)cascade_data); |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 371 | set_irq_chained_handler(virt_msir, fsl_msi_cascade); |
| 372 | } |
| 373 | } |
| 374 | |
Li Yang | 694a7a3 | 2010-04-22 16:31:36 +0800 | [diff] [blame] | 375 | list_add_tail(&msi->list, &msi_head); |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 376 | |
Lan Chunhe-B25806 | 8081881 | 2010-03-15 06:38:33 +0000 | [diff] [blame] | 377 | /* The multiple setting ppc_md.setup_msi_irqs will not harm things */ |
| 378 | if (!ppc_md.setup_msi_irqs) { |
| 379 | ppc_md.setup_msi_irqs = fsl_setup_msi_irqs; |
| 380 | ppc_md.teardown_msi_irqs = fsl_teardown_msi_irqs; |
| 381 | ppc_md.msi_check_device = fsl_msi_check_device; |
| 382 | } else if (ppc_md.setup_msi_irqs != fsl_setup_msi_irqs) { |
| 383 | dev_err(&dev->dev, "Different MSI driver already installed!\n"); |
| 384 | err = -ENODEV; |
| 385 | goto error_out; |
| 386 | } |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 387 | return 0; |
| 388 | error_out: |
Li Yang | 4805999 | 2010-04-22 16:31:39 +0800 | [diff] [blame] | 389 | fsl_of_msi_remove(dev); |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 390 | return err; |
| 391 | } |
| 392 | |
| 393 | static const struct fsl_msi_feature mpic_msi_feature = { |
| 394 | .fsl_pic_ip = FSL_PIC_IP_MPIC, |
| 395 | .msiir_offset = 0x140, |
| 396 | }; |
| 397 | |
| 398 | static const struct fsl_msi_feature ipic_msi_feature = { |
| 399 | .fsl_pic_ip = FSL_PIC_IP_IPIC, |
| 400 | .msiir_offset = 0x38, |
| 401 | }; |
| 402 | |
| 403 | static const struct of_device_id fsl_of_msi_ids[] = { |
| 404 | { |
| 405 | .compatible = "fsl,mpic-msi", |
| 406 | .data = (void *)&mpic_msi_feature, |
| 407 | }, |
| 408 | { |
| 409 | .compatible = "fsl,ipic-msi", |
| 410 | .data = (void *)&ipic_msi_feature, |
| 411 | }, |
| 412 | {} |
| 413 | }; |
| 414 | |
| 415 | static struct of_platform_driver fsl_of_msi_driver = { |
Grant Likely | 4018294 | 2010-04-13 16:13:02 -0700 | [diff] [blame] | 416 | .driver = { |
| 417 | .name = "fsl-msi", |
| 418 | .owner = THIS_MODULE, |
| 419 | .of_match_table = fsl_of_msi_ids, |
| 420 | }, |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 421 | .probe = fsl_of_msi_probe, |
Li Yang | 4805999 | 2010-04-22 16:31:39 +0800 | [diff] [blame] | 422 | .remove = fsl_of_msi_remove, |
Jason Jin | 34e36c1 | 2008-05-23 16:32:46 +0800 | [diff] [blame] | 423 | }; |
| 424 | |
| 425 | static __init int fsl_of_msi_init(void) |
| 426 | { |
| 427 | return of_register_platform_driver(&fsl_of_msi_driver); |
| 428 | } |
| 429 | |
| 430 | subsys_initcall(fsl_of_msi_init); |