All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Ellerman <michael@ellerman.id.au>
To: linux-pci@atrey.karlin.mff.cuni.cz
Cc: Greg Kroah-Hartman <greg@kroah.com>,
	Kyle McMartin <kyle@parisc-linux.org>,
	linuxppc-dev@ozlabs.org, Brice Goglin <brice@myri.com>,
	shaohua.li@intel.com, "David S. Miller" <davem@davemloft.net>,
	"Eric W. Biederman" <ebiederm@xmission.com>
Subject: [RFC/PATCH 9/16] RTAS MSI implementation
Date: Thu, 25 Jan 2007 19:34:12 +1100	[thread overview]
Message-ID: <20070125083414.35F4FDE37E@ozlabs.org> (raw)
In-Reply-To: <1169714047.65693.647693675533.qpush@cradle>

Powerpc MSI support via RTAS.

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
---

 drivers/pci/msi/Makefile  |    1 
 drivers/pci/msi/rtas.c    |  268 ++++++++++++++++++++++++++++++++++++++++++++++
 include/asm-powerpc/msi.h |    6 +
 3 files changed, 275 insertions(+)

Index: msi/drivers/pci/msi/Makefile
===================================================================
--- msi.orig/drivers/pci/msi/Makefile
+++ msi/drivers/pci/msi/Makefile
@@ -3,6 +3,7 @@
 #
 
 obj-y			+= core.o raw.o
+obj-$(CONFIG_PPC_RTAS)	+= rtas.o
 
 ifeq ($(CONFIG_PCI_MSI_DEBUG),y)
 EXTRA_CFLAGS += -DDEBUG
Index: msi/drivers/pci/msi/rtas.c
===================================================================
--- /dev/null
+++ msi/drivers/pci/msi/rtas.c
@@ -0,0 +1,268 @@
+/*
+ * Copyright (C) 2006 Jake Moilanen <moilanen@austin.ibm.com>, IBM Corp.
+ * Copyright (C) 2006 Michael Ellerman, IBM Corp.
+ *
+ * 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/msi-ops.h>
+#include <asm/msi.h>
+#include <asm/rtas.h>
+#include <asm/hw_irq.h>
+#include <asm/ppc-pci.h>
+
+static int query_token, change_token;
+
+#define RTAS_QUERY_FN		0
+#define RTAS_CHANGE_FN		1
+#define RTAS_RESET_FN		2
+#define RTAS_CHANGE_MSI_FN	3
+#define RTAS_CHANGE_MSIX_FN	4
+
+static struct pci_dn *get_pdn(struct pci_dev *pdev)
+{
+	struct device_node *dn;
+	struct pci_dn *pdn;
+
+	dn = pci_device_to_OF_node(pdev);
+	if (!dn) {
+		msi_debug("No OF device node for %s\n", pci_name(pdev));
+		return NULL;
+	}
+
+	pdn = PCI_DN(dn);
+	if (!pdn) {
+		msi_debug("No PCI DN for %s\n", pci_name(pdev));
+		return NULL;
+	}
+
+	return pdn;
+}
+
+/* RTAS Helpers */
+
+static int rtas_change_msi(struct pci_dn *pdn, u32 func, u32 num_irqs)
+{
+	u32 addr, seq_num, rtas_ret[3];
+	unsigned long buid;
+	int rc;
+
+	addr = rtas_config_addr(pdn->busno, pdn->devfn, 0);
+	buid = pdn->phb->buid;
+
+	seq_num = 1;
+	do {
+		if (func == RTAS_CHANGE_MSI_FN || func == RTAS_CHANGE_MSIX_FN)
+			rc = rtas_call(change_token, 6, 4, rtas_ret, addr,
+					BUID_HI(buid), BUID_LO(buid),
+					func, num_irqs, seq_num);
+		else
+			rc = rtas_call(change_token, 6, 3, rtas_ret, addr,
+					BUID_HI(buid), BUID_LO(buid),
+					func, num_irqs, seq_num);
+
+		seq_num = rtas_ret[1];
+	} while (rtas_busy_delay(rc));
+
+	if (rc) {
+		msi_debug("error (%d) for %s\n", rc, pci_name(pdn->pcidev));
+		return rc;
+	}
+
+	return rtas_ret[0];
+}
+
+static void rtas_disable_msi(struct pci_dev *pdev)
+{
+	struct pci_dn *pdn;
+
+	pdn = get_pdn(pdev);
+	if (!pdn)
+		return;
+
+	if (rtas_change_msi(pdn, RTAS_CHANGE_FN, 0) != 0) {
+		msi_debug("Setting MSIs to 0 failed!\n");
+		BUG();
+	}
+}
+
+static int rtas_query_irq_number(struct pci_dn *pdn, int offset)
+{
+	u32 addr, rtas_ret[2];
+	unsigned long buid;
+	int rc;
+
+	addr = rtas_config_addr(pdn->busno, pdn->devfn, 0);
+	buid = pdn->phb->buid;
+
+	do {
+		rc = rtas_call(query_token, 4, 3, rtas_ret, addr,
+			       BUID_HI(buid), BUID_LO(buid), offset);
+	} while (rtas_busy_delay(rc));
+
+	if (rc) {
+		msi_debug("error (%d) querying source number for %s\n",
+				rc, pci_name(pdn->pcidev));
+		return rc;
+	}
+
+	return rtas_ret[0];
+}
+
+static void msi_rtas_free(struct pci_dev *pdev, int num,
+			struct msix_entry *entries, int type)
+{
+	int i;
+
+	for (i = 0; i < num; i++) {
+		irq_dispose_mapping(entries[i].vector);
+	}
+
+	rtas_disable_msi(pdev);
+}
+
+static int check_req_msi(struct pci_dev *pdev)
+{
+	struct device_node *dn;
+	struct pci_dn *pdn;
+	const u32 *req_msi;
+
+	pdn = get_pdn(pdev);
+	if (!pdn)
+		return -1;
+
+	dn = pdn->node;
+
+	req_msi = get_property(dn, "ibm,req#msi", NULL);
+	if (!req_msi) {
+		msi_debug("No ibm,req#msi for %s\n", pci_name(pdev));
+		return -1;
+	}
+
+	if (*req_msi == 0) {
+		msi_debug("ibm,req#msi requests 0 MSIs for %s\n",
+			  pci_name(pdev));
+		return -1;
+	}
+
+	return 0;
+}
+
+static int msi_rtas_check(struct pci_dev *pdev, int num,
+			struct msix_entry *entries, int type)
+{
+	int i, rc;
+
+	rc = check_req_msi(pdev);
+	if (rc)
+		return rc;
+
+	/*
+	 * Firmware gives us no control over which entries are allocated
+	 * for MSI-X, it seems to assume we want 0 - n. For now just insist
+	 * that the entries array entry members are 0 - n.
+	 */
+	for (i = 0; i < num; i++) {
+		if (entries[i].entry != i) {
+			msi_debug("entries[%d].entry (%d) != %d\n", i,
+					entries[i].entry, i);
+			return -1;
+		}
+	}
+
+	return 0;
+}
+
+static int msi_rtas_alloc(struct pci_dev *pdev, int num,
+			struct msix_entry *entries, int type)
+{
+	struct pci_dn *pdn;
+	int hwirq, virq, i, rc;
+
+	pdn = get_pdn(pdev);
+	if (!pdn)
+		return -1;
+
+	/*
+	 * Try the new more explicit firmware interface, if that fails fall
+	 * back to the old interface. The old interface is known to never
+	 * return MSI-Xs.
+	 */
+	if (type == PCI_CAP_ID_MSI) {
+		rc = rtas_change_msi(pdn, RTAS_CHANGE_MSI_FN, num);
+
+		if (rc != num) {
+			msi_debug("trying the old firmware interface.\n");
+			rc = rtas_change_msi(pdn, RTAS_CHANGE_FN, num);
+		}
+	} else
+		rc = rtas_change_msi(pdn, RTAS_CHANGE_MSIX_FN, num);
+
+	if (rc != num) {
+		msi_debug("rtas_change_msi() failed for %s\n", pci_name(pdev));
+
+		/*
+		 * In case of an error it's not clear whether the device is
+		 * left with MSI enabled or not, so we explicitly disable.
+		 */
+		goto out_free;
+	}
+
+	for (i = 0; i < num; i++) {
+		hwirq = rtas_query_irq_number(pdn, i);
+		if (hwirq < 0) {
+			msi_debug("error (%d) getting hwirq for %s\n",
+					hwirq, pci_name(pdev));
+			goto out_free;
+		}
+
+		virq = irq_create_mapping(NULL, hwirq);
+
+		if (virq == NO_IRQ) {
+			msi_debug("Failed mapping hwirq %d\n", hwirq);
+			goto out_free;
+		}
+
+		entries[i].vector = virq;
+	}
+
+	return 0;
+
+ out_free:
+	msi_rtas_free(pdev, num, entries, type);
+	return -1;
+}
+
+static struct msi_ops rtas_msi_ops = {
+	.check = msi_rtas_check,
+	.alloc = msi_rtas_alloc,
+	.free  = msi_rtas_free
+};
+
+static struct msi_ops *rtas_get_msi_ops(struct pci_dev *pdev)
+{
+	return &rtas_msi_ops;
+}
+
+int msi_rtas_init(void)
+{
+	query_token  = rtas_token("ibm,query-interrupt-source-number");
+	change_token = rtas_token("ibm,change-msi");
+
+	if ((query_token == RTAS_UNKNOWN_SERVICE) ||
+			(change_token == RTAS_UNKNOWN_SERVICE)) {
+		msi_debug("Couldn't find RTAS tokens, no MSI support.\n");
+		return -1;
+	}
+
+	msi_debug("Registering RTAS MSI ops.\n");
+
+	ppc_md.get_msi_ops = rtas_get_msi_ops;
+
+	return 0;
+}
Index: msi/include/asm-powerpc/msi.h
===================================================================
--- msi.orig/include/asm-powerpc/msi.h
+++ msi/include/asm-powerpc/msi.h
@@ -20,4 +20,10 @@ static inline struct msi_ops *arch_get_m
 	return NULL;
 }
 
+#ifdef CONFIG_PCI_MSI
+extern int msi_rtas_init(void);
+#else
+static inline int msi_rtas_init(void) { return -1; };
+#endif
+
 #endif /* __ASM_POWERPC_MSI_H */

  parent reply	other threads:[~2007-01-25  8:34 UTC|newest]

Thread overview: 178+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-01-25  8:34 [RFC/PATCH 0/16] Ops based MSI Implementation Michael Ellerman
2007-01-25  8:34 ` [RFC/PATCH 1/16] Replace pci_msi_quirk with calls to pci_no_msi() Michael Ellerman
2007-01-25 22:33   ` patch msi-replace-pci_msi_quirk-with-calls-to-pci_no_msi.patch added to gregkh-2.6 tree gregkh
2007-01-25  8:34 ` [RFC/PATCH 2/16] Remove pci_scan_msi_device() Michael Ellerman
2007-01-25 22:33   ` patch msi-remove-pci_scan_msi_device.patch added to gregkh-2.6 tree gregkh
2007-01-25  8:34 ` [RFC/PATCH 3/16] Combine pci_(save|restore)_msi/msix_state Michael Ellerman
2007-01-25 22:33   ` patch msi-combine-pci__msi-msix_state.patch added to gregkh-2.6 tree gregkh
2007-01-25  8:34 ` [RFC/PATCH 4/16] Abstract MSI suspend Michael Ellerman
2007-01-25 22:33   ` patch msi-abstract-msi-suspend.patch added to gregkh-2.6 tree gregkh
2007-01-28  8:27   ` [RFC/PATCH 4/16] Abstract MSI suspend Eric W. Biederman
2007-01-29  7:22     ` Michael Ellerman
2007-01-29  8:45       ` Eric W. Biederman
2007-01-29  9:47         ` Michael Ellerman
2007-01-29 16:52           ` Grant Grundler
2007-01-29 16:57             ` Roland Dreier
2007-01-29 17:02               ` Roland Dreier
2007-01-29 17:25                 ` Eric W. Biederman
2007-01-29 17:32                   ` Roland Dreier
2007-01-29 22:03               ` Grant Grundler
2007-01-29 17:20           ` Eric W. Biederman
2007-02-01  4:24       ` Greg KH
2007-01-25  8:34 ` [RFC/PATCH 5/16] Ops based MSI implementation Michael Ellerman
2007-01-25 21:52   ` Greg KH
2007-01-25 22:05     ` Roland Dreier
2007-01-25 22:10       ` Greg KH
2007-01-26  1:02     ` Michael Ellerman
2007-01-25  8:34 ` [RFC/PATCH 6/16] Add bare metal MSI enable & disable routines Michael Ellerman
2007-01-26  5:35   ` Eric W. Biederman
2007-01-25  8:34 ` [RFC/PATCH 7/16] Rip out the existing powerpc msi stubs Michael Ellerman
2007-01-25  8:34 ` [RFC/PATCH 8/16] Enable MSI on Powerpc Michael Ellerman
2007-01-25  8:34 ` Michael Ellerman [this message]
2007-01-25  8:34 ` [RFC/PATCH 10/16] Add a pci_irq_fixup for MSI via RTAS Michael Ellerman
2007-01-25  8:34 ` [RFC/PATCH 12/16] Tell firmware we support MSI Michael Ellerman
2007-01-25  8:34 ` [RFC/PATCH 11/16] Activate MSI via RTAS on pseries Michael Ellerman
2007-01-25  8:34 ` [RFC/PATCH 13/16] MPIC MSI allocator Michael Ellerman
2007-01-25  8:34 ` [RFC/PATCH 14/16] MPIC MSI backend Michael Ellerman
2007-01-26  6:43   ` Grant Grundler
2007-01-26  7:02     ` Eric W. Biederman
2007-01-26  8:47       ` Segher Boessenkool
2007-01-26 16:32         ` Eric W. Biederman
2007-01-26 17:19           ` Grant Grundler
2007-01-26 17:56             ` Eric W. Biederman
2007-01-26 22:48               ` Benjamin Herrenschmidt
2007-01-27  7:01               ` Michael Ellerman
2007-01-26 22:40             ` Benjamin Herrenschmidt
2007-01-27  2:11               ` David Miller
2007-01-26 22:08           ` Benjamin Herrenschmidt
2007-01-27  6:54             ` Michael Ellerman
2007-01-26 20:50       ` Benjamin Herrenschmidt
2007-01-26 22:46       ` Paul Mackerras
2007-01-27  2:46         ` Eric W. Biederman
2007-01-27  3:02           ` David Miller
2007-01-27  4:28             ` Eric W. Biederman
2007-01-27 18:30         ` Grant Grundler
2007-01-27 20:02           ` Benjamin Herrenschmidt
2007-01-26 20:41     ` Benjamin Herrenschmidt
2007-01-26  9:11   ` Segher Boessenkool
2007-01-27  6:33     ` Michael Ellerman
2007-01-25  8:34 ` [RFC/PATCH 15/16] Enable MSI mappings for MPIC Michael Ellerman
2007-01-25  8:34 ` [RFC/PATCH 16/16] Activate MSI for the MPIC backend on U3 Michael Ellerman
2007-01-25 21:53 ` [RFC/PATCH 0/16] Ops based MSI Implementation Greg KH
2007-01-25 21:55   ` David Miller
2007-01-26  1:05     ` Michael Ellerman
2007-01-26  1:03   ` Michael Ellerman
2007-01-26  6:18 ` Eric W. Biederman
2007-01-26  6:56   ` Grant Grundler
2007-01-26  7:15     ` Eric W. Biederman
2007-01-26  7:48       ` Grant Grundler
2007-01-26 15:26         ` Eric W. Biederman
2007-01-26 21:58         ` Benjamin Herrenschmidt
2007-01-26  8:57     ` Segher Boessenkool
2007-01-26 17:27       ` Grant Grundler
2007-01-26 20:57     ` Benjamin Herrenschmidt
2007-01-26 21:24   ` Benjamin Herrenschmidt
2007-01-27  5:41   ` Michael Ellerman
2007-01-28  6:16     ` Eric W. Biederman
2007-01-28  8:12       ` Michael Ellerman
2007-01-28  8:36         ` Eric W. Biederman
2007-01-28 20:14           ` Benjamin Herrenschmidt
2007-01-28 20:53             ` Eric W. Biederman
2007-01-28 21:17               ` Benjamin Herrenschmidt
2007-01-28 22:36                 ` Eric W. Biederman
2007-01-28 23:17                   ` Benjamin Herrenschmidt
2007-01-28 23:38                     ` Eric W. Biederman
2007-01-28 23:51                       ` David Miller
2007-01-29  0:58                         ` Benjamin Herrenschmidt
2007-01-29  1:13                           ` David Miller
2007-01-29  3:17                             ` Benjamin Herrenschmidt
2007-01-29  4:19                               ` David Miller
2007-01-29  4:44                                 ` Benjamin Herrenschmidt
2007-01-29  5:46                             ` Eric W. Biederman
2007-01-29  6:08                               ` Benjamin Herrenschmidt
2007-01-31  6:52                           ` David Miller
2007-01-31  7:40                             ` Eric W. Biederman
2007-02-01  0:55                               ` David Miller
2007-01-29  0:26                       ` Benjamin Herrenschmidt
2007-01-29  0:59                       ` Michael Ellerman
2007-01-28 23:31                   ` David Miller
2007-01-28 23:59                     ` Benjamin Herrenschmidt
2007-01-28 23:26               ` David Miller
2007-01-28 23:25             ` David Miller
2007-01-27  4:59 ` Michael Ellerman
2007-01-28 19:40 ` [PATCH 0/6] MSI portability cleanups Eric W. Biederman
2007-01-28 19:40   ` Eric W. Biederman
2007-01-28 19:42   ` [PATCH 1/6] msi: Kill msi_lookup_irq Eric W. Biederman
2007-01-28 19:42     ` Eric W. Biederman
2007-01-28 19:44     ` [PATCH 2/6] msi: Remove msi_lock Eric W. Biederman
2007-01-28 19:44       ` Eric W. Biederman
2007-01-28 19:45       ` [PATCH 3/6] msi: Fix msi_remove_pci_irq_vectors Eric W. Biederman
2007-01-28 19:45         ` Eric W. Biederman
2007-01-28 19:47         ` [PATCH 4/6] msi: Remove attach_msi_entry Eric W. Biederman
2007-01-28 19:47           ` Eric W. Biederman
2007-01-28 19:52           ` [PATCH 5/6] msi: Kill the msi_desc array Eric W. Biederman
2007-01-28 19:52             ` Eric W. Biederman
2007-01-28 19:56             ` [PATCH 6/6] msi: Make MSI useable more architectures Eric W. Biederman
2007-01-28 19:56               ` Eric W. Biederman
2007-02-01  6:08               ` patch msi-make-msi-useable-more-architectures.patch added to gregkh-2.6 tree gregkh
2007-02-01  6:07             ` patch msi-kill-the-msi_desc-array.patch " gregkh
2007-02-01  6:08           ` patch msi-remove-attach_msi_entry.patch " gregkh
2007-02-01  6:07         ` patch msi-fix-msi_remove_pci_irq_vectors.patch " gregkh
2007-02-01  6:08       ` patch msi-remove-msi_lock.patch " gregkh
2007-01-28 22:01     ` [PATCH 1/6] msi: Kill msi_lookup_irq Paul Mackerras
2007-01-28 22:01       ` Paul Mackerras
2007-01-28 22:18       ` Eric W. Biederman
2007-01-28 22:18         ` Eric W. Biederman
2007-02-01  6:07     ` patch msi-kill-msi_lookup_irq.patch added to gregkh-2.6 tree gregkh
2007-01-28 20:23   ` [PATCH 0/6] MSI portability cleanups Benjamin Herrenschmidt
2007-01-28 20:23     ` Benjamin Herrenschmidt
2007-01-28 20:47     ` Jeff Garzik
2007-01-28 20:47       ` Jeff Garzik
2007-01-28 21:20       ` Eric W. Biederman
2007-01-28 21:20         ` Eric W. Biederman
2007-01-28 21:26         ` Ingo Molnar
2007-01-28 21:26           ` Ingo Molnar
2007-01-28 22:09         ` Benjamin Herrenschmidt
2007-01-28 22:09           ` Benjamin Herrenschmidt
2007-01-28 23:26           ` Eric W. Biederman
2007-01-28 23:26             ` Eric W. Biederman
2007-01-28 23:37             ` David Miller
2007-01-28 23:37               ` David Miller
2007-01-29  5:18               ` Eric W. Biederman
2007-01-29  5:18                 ` Eric W. Biederman
2007-01-29  5:25                 ` David Miller
2007-01-29  5:25                   ` David Miller
2007-01-29  5:58                   ` Eric W. Biederman
2007-01-29  5:58                     ` Eric W. Biederman
2007-01-29  6:05                   ` Benjamin Herrenschmidt
2007-01-29  6:05                     ` Benjamin Herrenschmidt
2007-01-29  8:28                     ` Eric W. Biederman
2007-01-29  8:28                       ` Eric W. Biederman
2007-01-29  9:03                     ` Eric W. Biederman
2007-01-29  9:03                       ` Eric W. Biederman
2007-01-29 10:11                       ` Michael Ellerman
2007-01-29 10:11                         ` Michael Ellerman
2007-01-29 20:32                         ` Benjamin Herrenschmidt
2007-01-29 20:32                           ` Benjamin Herrenschmidt
2007-01-29 23:29                         ` Paul Mackerras
2007-01-29 23:29                           ` Paul Mackerras
2007-01-29 23:40                           ` Benjamin Herrenschmidt
2007-01-29 23:40                             ` Benjamin Herrenschmidt
2007-01-29 20:22                       ` Benjamin Herrenschmidt
2007-01-29 20:22                         ` Benjamin Herrenschmidt
2007-01-29 23:05                         ` Paul Mackerras
2007-01-29 23:05                           ` Paul Mackerras
2007-01-30 19:32                           ` Segher Boessenkool
2007-01-30 19:32                             ` Segher Boessenkool
2007-01-29  1:33             ` Benjamin Herrenschmidt
2007-01-29  1:33               ` Benjamin Herrenschmidt
2007-02-01  4:29           ` Greg KH
2007-02-01  4:29             ` Greg KH
2007-01-28 23:44         ` David Miller
2007-01-28 23:44           ` David Miller
2007-01-28 22:11       ` Eric W. Biederman
2007-01-28 22:11         ` Eric W. Biederman
2007-01-28 23:42       ` David Miller
2007-01-28 23:42         ` David Miller
2007-01-28 21:34     ` Eric W. Biederman
2007-01-28 21:34       ` Eric W. Biederman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070125083414.35F4FDE37E@ozlabs.org \
    --to=michael@ellerman.id.au \
    --cc=brice@myri.com \
    --cc=davem@davemloft.net \
    --cc=ebiederm@xmission.com \
    --cc=greg@kroah.com \
    --cc=kyle@parisc-linux.org \
    --cc=linux-pci@atrey.karlin.mff.cuni.cz \
    --cc=linuxppc-dev@ozlabs.org \
    --cc=shaohua.li@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.