From patchwork Tue Aug 26 19:35:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ashwin Chaugule X-Patchwork-Id: 4783761 Return-Path: X-Original-To: patchwork-linux-acpi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 02F5BC0338 for ; Tue, 26 Aug 2014 19:36:36 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CCCC2201EF for ; Tue, 26 Aug 2014 19:36:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8A8CC201C0 for ; Tue, 26 Aug 2014 19:36:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753700AbaHZTgd (ORCPT ); Tue, 26 Aug 2014 15:36:33 -0400 Received: from mail-qa0-f49.google.com ([209.85.216.49]:40224 "EHLO mail-qa0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752339AbaHZTgc (ORCPT ); Tue, 26 Aug 2014 15:36:32 -0400 Received: by mail-qa0-f49.google.com with SMTP id dc16so14206502qab.36 for ; Tue, 26 Aug 2014 12:36:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=nkCkbPsRo/dEzReNYulvzNjHpF+chAnL92paPx9Saew=; b=Wy/n915Danu6F+UNHL3bp2R5HCouT+VfdbLwRrrbkT6x+m9V9ZzHdN/2sX09XBifyn sAiRvhNWeIAq+3vSsguFF1OE46FntddkK4D2zGJgKQJVnjYxiX5pmQvflcCJoy6SxEpT ZV6j0g+wg6+iRlHbwo6xSWta8FAGAvQBG9X9f5HodTwur4JRxOGlDU+OPxZRDqv46oZs JowEeuOCrf5dlZEX3LWCYAHcaP6veRCdSGN6b3eovUVZ0RKpsFI1wSsrrVN9UdyQjQbH Dl6nq9qJDAAPVITDqKSq0CNRtPvxmxbbEeiG1si+fAOe044/iXnrkMxRK8OcXtrpBDJz PjLA== X-Gm-Message-State: ALoCoQmEh2tXTBdp2UyBJm6M5etbW7L5sB8V/a3tNXU2alOFvRlDh5TlVDbAgo2AmEnlQw1bW3Qb X-Received: by 10.224.21.68 with SMTP id i4mr42490771qab.83.1409081791926; Tue, 26 Aug 2014 12:36:31 -0700 (PDT) Received: from esagroth.qualcomm.com (rrcs-67-52-130-30.west.biz.rr.com. [67.52.130.30]) by mx.google.com with ESMTPSA id x3sm12217376qam.15.2014.08.26.12.36.30 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 26 Aug 2014 12:36:31 -0700 (PDT) From: Ashwin Chaugule To: arnd@arndb.de Cc: Ashwin Chaugule , linux-acpi@vger.kernel.org, linaro-acpi@lists.linaro.org, rjw@rjwysocki.net, broonie@kernel.org Subject: [PATCH v3 1/3] Mailbox: Add support for PCC mailbox and channels Date: Tue, 26 Aug 2014 15:35:36 -0400 Message-Id: <1409081738-5602-2-git-send-email-ashwin.chaugule@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1409081738-5602-1-git-send-email-ashwin.chaugule@linaro.org> References: <1409081738-5602-1-git-send-email-ashwin.chaugule@linaro.org> Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The PCC (Platform Communication Channel) is a generic mailbox to be used by PCC clients such as CPPC, RAS and MPST as defined in the ACPI 5.0+ spec. This patch modifies the Mailbox framework to lookup PCC mailbox controllers and channels such that PCC drivers can work with or without ACPI support in the kernel. Signed-off-by: Ashwin Chaugule --- drivers/mailbox/mailbox.c | 118 ++++++++++++++++++++++++++++++++++--- include/linux/mailbox_client.h | 6 ++ include/linux/mailbox_controller.h | 1 + 3 files changed, 118 insertions(+), 7 deletions(-) diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c index 63ecc17..09ad488 100644 --- a/drivers/mailbox/mailbox.c +++ b/drivers/mailbox/mailbox.c @@ -356,6 +356,14 @@ struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index) } EXPORT_SYMBOL_GPL(mbox_request_channel); +static void inline free_channel(struct mbox_chan *chan) +{ + chan->cl = NULL; + chan->active_req = NULL; + if (chan->txdone_method == (TXDONE_BY_POLL | TXDONE_BY_ACK)) + chan->txdone_method = TXDONE_BY_POLL; +} + /** * mbox_free_channel - The client relinquishes control of a mailbox * channel by this call. @@ -369,14 +377,9 @@ void mbox_free_channel(struct mbox_chan *chan) return; chan->mbox->ops->shutdown(chan); - /* The queued TX requests are simply aborted, no callbacks are made */ spin_lock_irqsave(&chan->lock, flags); - chan->cl = NULL; - chan->active_req = NULL; - if (chan->txdone_method == (TXDONE_BY_POLL | TXDONE_BY_ACK)) - chan->txdone_method = TXDONE_BY_POLL; - + free_channel(chan); module_put(chan->mbox->dev->driver->owner); spin_unlock_irqrestore(&chan->lock, flags); } @@ -394,6 +397,97 @@ of_mbox_index_xlate(struct mbox_controller *mbox, return &mbox->chans[ind]; } +#ifdef CONFIG_PCC +/* + * The PCC (Platform Communication Channel) is + * defined in the ACPI 5.0+ spec. It is a generic + * mailbox interface between an OS and a Platform + * such as a BMC. The PCCT (Mailbox controller) has + * its own ACPI specific way to describe PCC clients + * and their subspace ids (Mailbox channels/clients). + * + * The following API is added such that PCC + * drivers continue to work with this Mailbox + * framework with or without ACPI. + */ + +static struct mbox_controller * +mbox_find_pcc_controller(char *name) +{ + struct mbox_controller *mbox; + list_for_each_entry(mbox, &mbox_cons, node) { + if (mbox->name) + if (!strcmp(mbox->name, name)) + return mbox; + } + + return NULL; +} + +struct mbox_chan * +pcc_mbox_request_channel(struct mbox_client *cl, + char *name, unsigned chan_id) +{ + struct mbox_controller *mbox; + struct mbox_chan *pcc_chan; + unsigned long flags; + int ret; + + mutex_lock(&con_mutex); + mbox = mbox_find_pcc_controller(name); + + if (!mbox) { + pr_err("PCC mbox %s not found.\n", name); + mutex_unlock(&con_mutex); + return ERR_PTR(-ENODEV); + } + + pcc_chan = &mbox->chans[chan_id]; + + spin_lock_irqsave(&pcc_chan->lock, flags); + pcc_chan->msg_free = 0; + pcc_chan->msg_count = 0; + pcc_chan->active_req = NULL; + pcc_chan->cl = cl; + init_completion(&pcc_chan->tx_complete); + + if (pcc_chan->txdone_method == TXDONE_BY_POLL && cl->knows_txdone) + pcc_chan->txdone_method |= TXDONE_BY_ACK; + + spin_unlock_irqrestore(&pcc_chan->lock, flags); + + ret = pcc_chan->mbox->ops->startup(pcc_chan); + if (ret) { + pr_err("Unable to startup the PCC channel (%d)\n", ret); + mbox_free_channel(pcc_chan); + mutex_unlock(&con_mutex); + return ERR_PTR(-ENODEV); + } + + mutex_unlock(&con_mutex); + + return pcc_chan; +} + +EXPORT_SYMBOL_GPL(pcc_mbox_request_channel); + +void pcc_mbox_free_channel(struct mbox_chan *chan) +{ + unsigned long flags; + + if (!chan || !chan->cl) + return; + + chan->mbox->ops->shutdown(chan); + + spin_lock_irqsave(&chan->lock, flags); + free_channel(chan); + spin_unlock_irqrestore(&chan->lock, flags); +} +EXPORT_SYMBOL_GPL(pcc_mbox_free_channel); + +#endif + /** * mbox_controller_register - Register the mailbox controller * @mbox: Pointer to the mailbox controller. @@ -405,7 +499,17 @@ int mbox_controller_register(struct mbox_controller *mbox) int i, txdone; /* Sanity check */ - if (!mbox || !mbox->dev || !mbox->ops || !mbox->num_chans) + + /* + * PCC clients and controllers are currently not backed by + * platform device structures. + */ +#ifndef CONFIG_PCC + if (!mbox->dev) + return -EINVAL; +#endif + + if (!mbox || !mbox->ops || !mbox->num_chans) return -EINVAL; if (mbox->txdone_irq) diff --git a/include/linux/mailbox_client.h b/include/linux/mailbox_client.h index 307d9ca..6a78df0 100644 --- a/include/linux/mailbox_client.h +++ b/include/linux/mailbox_client.h @@ -37,6 +37,12 @@ struct mbox_client { void (*tx_done)(struct mbox_client *cl, void *mssg, int r); }; +#ifdef CONFIG_PCC +struct mbox_chan *pcc_mbox_request_channel(struct mbox_client *c, + char *name, unsigned int chan_id); +void pcc_mbox_free_channel(struct mbox_chan *chan); /* may sleep */ +#endif + struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index); int mbox_send_message(struct mbox_chan *chan, void *mssg); void mbox_client_txdone(struct mbox_chan *chan, int r); /* atomic */ diff --git a/include/linux/mailbox_controller.h b/include/linux/mailbox_controller.h index 9ee195b..9f0ae42 100644 --- a/include/linux/mailbox_controller.h +++ b/include/linux/mailbox_controller.h @@ -81,6 +81,7 @@ struct mbox_controller { unsigned txpoll_period; struct mbox_chan *(*of_xlate)(struct mbox_controller *mbox, const struct of_phandle_args *sp); + char *name; /* Internal to API */ struct timer_list poll; unsigned period;