Path: blob/master/arch/powerpc/sysdev/mpic_pasemi_msi.c
10820 views
/*1* Copyright 2007, Olof Johansson, PA Semi2*3* Based on arch/powerpc/sysdev/mpic_u3msi.c:4*5* Copyright 2006, Segher Boessenkool, IBM Corporation.6* Copyright 2006-2007, Michael Ellerman, IBM Corporation.7*8* This program is free software; you can redistribute it and/or9* modify it under the terms of the GNU General Public License10* as published by the Free Software Foundation; version 2 of the11* License.12*13*/1415#undef DEBUG1617#include <linux/irq.h>18#include <linux/bootmem.h>19#include <linux/msi.h>20#include <asm/mpic.h>21#include <asm/prom.h>22#include <asm/hw_irq.h>23#include <asm/ppc-pci.h>24#include <asm/msi_bitmap.h>2526#include "mpic.h"2728/* Allocate 16 interrupts per device, to give an alignment of 16,29* since that's the size of the grouping w.r.t. affinity. If someone30* needs more than 32 MSI's down the road we'll have to rethink this,31* but it should be OK for now.32*/33#define ALLOC_CHUNK 163435#define PASEMI_MSI_ADDR 0xfc0800003637/* A bit ugly, can we get this from the pci_dev somehow? */38static struct mpic *msi_mpic;394041static void mpic_pasemi_msi_mask_irq(struct irq_data *data)42{43pr_debug("mpic_pasemi_msi_mask_irq %d\n", data->irq);44mask_msi_irq(data);45mpic_mask_irq(data);46}4748static void mpic_pasemi_msi_unmask_irq(struct irq_data *data)49{50pr_debug("mpic_pasemi_msi_unmask_irq %d\n", data->irq);51mpic_unmask_irq(data);52unmask_msi_irq(data);53}5455static struct irq_chip mpic_pasemi_msi_chip = {56.irq_shutdown = mpic_pasemi_msi_mask_irq,57.irq_mask = mpic_pasemi_msi_mask_irq,58.irq_unmask = mpic_pasemi_msi_unmask_irq,59.irq_eoi = mpic_end_irq,60.irq_set_type = mpic_set_irq_type,61.irq_set_affinity = mpic_set_affinity,62.name = "PASEMI-MSI",63};6465static int pasemi_msi_check_device(struct pci_dev *pdev, int nvec, int type)66{67if (type == PCI_CAP_ID_MSIX)68pr_debug("pasemi_msi: MSI-X untested, trying anyway\n");6970return 0;71}7273static void pasemi_msi_teardown_msi_irqs(struct pci_dev *pdev)74{75struct msi_desc *entry;7677pr_debug("pasemi_msi_teardown_msi_irqs, pdev %p\n", pdev);7879list_for_each_entry(entry, &pdev->msi_list, list) {80if (entry->irq == NO_IRQ)81continue;8283irq_set_msi_desc(entry->irq, NULL);84msi_bitmap_free_hwirqs(&msi_mpic->msi_bitmap,85virq_to_hw(entry->irq), ALLOC_CHUNK);86irq_dispose_mapping(entry->irq);87}8889return;90}9192static int pasemi_msi_setup_msi_irqs(struct pci_dev *pdev, int nvec, int type)93{94unsigned int virq;95struct msi_desc *entry;96struct msi_msg msg;97int hwirq;9899pr_debug("pasemi_msi_setup_msi_irqs, pdev %p nvec %d type %d\n",100pdev, nvec, type);101102msg.address_hi = 0;103msg.address_lo = PASEMI_MSI_ADDR;104105list_for_each_entry(entry, &pdev->msi_list, list) {106/* Allocate 16 interrupts for now, since that's the grouping for107* affinity. This can be changed later if it turns out 32 is too108* few MSIs for someone, but restrictions will apply to how the109* sources can be changed independently.110*/111hwirq = msi_bitmap_alloc_hwirqs(&msi_mpic->msi_bitmap,112ALLOC_CHUNK);113if (hwirq < 0) {114pr_debug("pasemi_msi: failed allocating hwirq\n");115return hwirq;116}117118virq = irq_create_mapping(msi_mpic->irqhost, hwirq);119if (virq == NO_IRQ) {120pr_debug("pasemi_msi: failed mapping hwirq 0x%x\n",121hwirq);122msi_bitmap_free_hwirqs(&msi_mpic->msi_bitmap, hwirq,123ALLOC_CHUNK);124return -ENOSPC;125}126127/* Vector on MSI is really an offset, the hardware adds128* it to the value written at the magic address. So set129* it to 0 to remain sane.130*/131mpic_set_vector(virq, 0);132133irq_set_msi_desc(virq, entry);134irq_set_chip(virq, &mpic_pasemi_msi_chip);135irq_set_irq_type(virq, IRQ_TYPE_EDGE_RISING);136137pr_debug("pasemi_msi: allocated virq 0x%x (hw 0x%x) " \138"addr 0x%x\n", virq, hwirq, msg.address_lo);139140/* Likewise, the device writes [0...511] into the target141* register to generate MSI [512...1023]142*/143msg.data = hwirq-0x200;144write_msi_msg(virq, &msg);145}146147return 0;148}149150int mpic_pasemi_msi_init(struct mpic *mpic)151{152int rc;153154if (!mpic->irqhost->of_node ||155!of_device_is_compatible(mpic->irqhost->of_node,156"pasemi,pwrficient-openpic"))157return -ENODEV;158159rc = mpic_msi_init_allocator(mpic);160if (rc) {161pr_debug("pasemi_msi: Error allocating bitmap!\n");162return rc;163}164165pr_debug("pasemi_msi: Registering PA Semi MPIC MSI callbacks\n");166167msi_mpic = mpic;168WARN_ON(ppc_md.setup_msi_irqs);169ppc_md.setup_msi_irqs = pasemi_msi_setup_msi_irqs;170ppc_md.teardown_msi_irqs = pasemi_msi_teardown_msi_irqs;171ppc_md.msi_check_device = pasemi_msi_check_device;172173return 0;174}175176177