From patchwork Thu Jun 12 16:48:10 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ashwin Chaugule X-Patchwork-Id: 31850 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ve0-f200.google.com (mail-ve0-f200.google.com [209.85.128.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0DE6D2054B for ; Thu, 12 Jun 2014 16:48:25 +0000 (UTC) Received: by mail-ve0-f200.google.com with SMTP id oz11sf5780840veb.11 for ; Thu, 12 Jun 2014 09:48:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=Nyf4bAIxdU5mLDQqz+CfNf4cRLchUmlQEoiXYBRwzC8=; b=WFhkl7BYIQ9N0tEStWUxX5ckOcddBbKeciJ4TNa5Vm6Y6okzJ2/OtqOwaDiXpPcuy/ ySE5VlwTJdm8qSC9FbLBCcLsQ/B34MXmWCxM8AJ7SellHLvZ1yRBg8OKcA0F60P4aTPN bzAquj5kmQGQEHGKOfpXohFq08HFV8Z5291pLAQdpIFFjIzyqCbKHNg4cSxDCJlUU/55 1v2Yju0LleeW+IUUigBXcPnLBL4j2CxJwapnntOAZWoyS37sTMZ6gNd97nR/zG08G8aU ruy6aOdvM/D42ejcXqThoEDmoMPBKXSi7JX8oTD9CS+uJ4cDlu6azgM7pZcVIkA+Gwgf Qf5A== X-Gm-Message-State: ALoCoQnzfzZnes+Euq4vhjUUs648EAT1PB+RabUEQd+5Efj8lKkNU0SroTmB0jaJSi4x8S4gNvVC X-Received: by 10.236.175.42 with SMTP id y30mr2314685yhl.42.1402591704848; Thu, 12 Jun 2014 09:48:24 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.97.7 with SMTP id l7ls378848qge.63.gmail; Thu, 12 Jun 2014 09:48:24 -0700 (PDT) X-Received: by 10.220.114.140 with SMTP id e12mr1075574vcq.37.1402591704725; Thu, 12 Jun 2014 09:48:24 -0700 (PDT) Received: from mail-vc0-f182.google.com (mail-vc0-f182.google.com [209.85.220.182]) by mx.google.com with ESMTPS id x5si495126vei.12.2014.06.12.09.48.24 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 12 Jun 2014 09:48:24 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.182 as permitted sender) client-ip=209.85.220.182; Received: by mail-vc0-f182.google.com with SMTP id il7so1096436vcb.41 for ; Thu, 12 Jun 2014 09:48:24 -0700 (PDT) X-Received: by 10.52.52.168 with SMTP id u8mr8942088vdo.25.1402591704615; Thu, 12 Jun 2014 09:48:24 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.221.54.6 with SMTP id vs6csp418066vcb; Thu, 12 Jun 2014 09:48:24 -0700 (PDT) X-Received: by 10.66.191.9 with SMTP id gu9mr22367169pac.27.1402591703586; Thu, 12 Jun 2014 09:48:23 -0700 (PDT) Received: from mail-pa0-f52.google.com (mail-pa0-f52.google.com [209.85.220.52]) by mx.google.com with ESMTPS id fg5si1677455pad.120.2014.06.12.09.48.23 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 12 Jun 2014 09:48:23 -0700 (PDT) Received-SPF: pass (google.com: domain of ashwin.chaugule@linaro.org designates 209.85.220.52 as permitted sender) client-ip=209.85.220.52; Received: by mail-pa0-f52.google.com with SMTP id eu11so1193704pac.39 for ; Thu, 12 Jun 2014 09:48:23 -0700 (PDT) X-Received: by 10.69.17.230 with SMTP id gh6mr14120953pbd.0.1402591703144; Thu, 12 Jun 2014 09:48:23 -0700 (PDT) Received: from linaro5.qualcomm.com (rrcs-67-52-130-30.west.biz.rr.com. [67.52.130.30]) by mx.google.com with ESMTPSA id xz7sm7701153pac.3.2014.06.12.09.48.20 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 12 Jun 2014 09:48:22 -0700 (PDT) From: Ashwin Chaugule To: linux-acpi@vger.kernel.org Cc: linaro-acpi@lists.linaro.org, broonie@kernel.org, jassisinghbrar@gmail.com, linux-arm-kernel@lists.infradead.org, rjw@rjwysocki.net, patches@linaro.org, Ashwin Chaugule Subject: [RFC v2 1/3] Mailbox: Add support for ACPI Date: Thu, 12 Jun 2014 12:48:10 -0400 Message-Id: <1402591692-7736-2-git-send-email-ashwin.chaugule@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1402591692-7736-1-git-send-email-ashwin.chaugule@linaro.org> References: <1402591692-7736-1-git-send-email-ashwin.chaugule@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ashwin.chaugule@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.182 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , The current mailbox framework only supports DT based bindings. Add another mechanism for mailbox clients to register with mailbox controllers and request for specific mailbox channels. This enables usage of the mailbox framework on kernels with ACPI support. Signed-off-by: Ashwin Chaugule --- drivers/mailbox/mailbox.c | 155 ++++++++++++++++++++++++------------- include/linux/mailbox_client.h | 3 + include/linux/mailbox_controller.h | 6 ++ 3 files changed, 112 insertions(+), 52 deletions(-) diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c index d83d12c..c7d17f8 100644 --- a/drivers/mailbox/mailbox.c +++ b/drivers/mailbox/mailbox.c @@ -273,100 +273,143 @@ int mbox_send_message(struct mbox_chan *chan, void *mssg) } EXPORT_SYMBOL_GPL(mbox_send_message); -/** - * mbox_request_channel - Request a mailbox channel. - * @cl: Identity of the client requesting the channel. - * - * The Client specifies its requirements and capabilities while asking for - * a mailbox channel by name. It can't be called from atomic context. - * The channel is exclusively allocated and can't be used by another - * client before the owner calls mbox_free_channel. - * After assignment, any packet received on this channel will be - * handed over to the client via the 'rx_callback'. - * - * Return: Pointer to the channel assigned to the client if successful. - * ERR_PTR for request failure. - */ -struct mbox_chan *mbox_request_channel(struct mbox_client *cl) +static int init_channel(struct mbox_chan *chan, + struct mbox_client *cl) +{ + unsigned long flags; + int ret; + + spin_lock_irqsave(&chan->lock, flags); + chan->msg_free = 0; + chan->msg_count = 0; + chan->active_req = NULL; + chan->cl = cl; + + if (!cl->tx_tout) /* wait for ever */ + cl->tx_tout = msecs_to_jiffies(3600000); + else + cl->tx_tout = msecs_to_jiffies(cl->tx_tout); + if (chan->txdone_method == TXDONE_BY_POLL + && cl->knows_txdone) + chan->txdone_method |= TXDONE_BY_ACK; + spin_unlock_irqrestore(&chan->lock, flags); + + ret = chan->mbox->ops->startup(chan); + if (ret) { + pr_err("Unable to startup the chan\n"); + mbox_free_channel(chan); + chan = ERR_PTR(ret); + } + + return ret; +} + +#ifdef CONFIG_ACPI +static int get_acpi_mbox_chan(struct mbox_client *cl, + struct mbox_chan **chan) +{ + struct mbox_controller *mbox; + int i; + + list_for_each_entry(mbox, &mbox_cons, node) { + if (!strcmp(cl->ctrl_name, mbox->name)) { + for (i = 0; i < mbox->num_chans; i++) { + *chan = &mbox->chans[i]; + if (!strcmp(cl->chan_name, (*chan)->name)) + return init_channel(*chan, cl); + } + } + } + + return -ENODEV; +} +#endif + +static int get_of_mbox_chan(struct mbox_client *cl, + struct mbox_chan **chan) { struct device *dev = cl->dev; struct mbox_controller *mbox; struct of_phandle_args spec; - struct mbox_chan *chan; - unsigned long flags; int count, i, ret; if (!dev || !dev->of_node) { pr_err("%s: No owner device node\n", __func__); - return ERR_PTR(-ENODEV); + return -ENODEV; } count = of_property_count_strings(dev->of_node, "mbox-names"); if (count < 0) { pr_err("%s: mbox-names property of node '%s' missing\n", __func__, dev->of_node->full_name); - return ERR_PTR(-ENODEV); + return -ENODEV; } - - mutex_lock(&con_mutex); - - ret = -ENODEV; for (i = 0; i < count; i++) { const char *s; if (of_property_read_string_index(dev->of_node, - "mbox-names", i, &s)) + "mbox-names", i, &s)) continue; if (strcmp(cl->chan_name, s)) continue; if (of_parse_phandle_with_args(dev->of_node, - "mbox", "#mbox-cells", i, &spec)) + "mbox", "#mbox-cells", i, &spec)) continue; - chan = NULL; list_for_each_entry(mbox, &mbox_cons, node) if (mbox->dev->of_node == spec.np) { - chan = mbox->of_xlate(mbox, &spec); + *chan = mbox->of_xlate(mbox, &spec); break; } of_node_put(spec.np); - if (!chan) + if (!(*chan)) continue; ret = -EBUSY; - if (!chan->cl && try_module_get(mbox->dev->driver->owner)) + if (!(*chan)->cl && try_module_get(mbox->dev->driver->owner)) break; } if (i == count) { mutex_unlock(&con_mutex); - return ERR_PTR(ret); + return ret; } - spin_lock_irqsave(&chan->lock, flags); - chan->msg_free = 0; - chan->msg_count = 0; - chan->active_req = NULL; - chan->cl = cl; - if (!cl->tx_tout) /* wait for ever */ - cl->tx_tout = msecs_to_jiffies(3600000); - else - cl->tx_tout = msecs_to_jiffies(cl->tx_tout); - if (chan->txdone_method == TXDONE_BY_POLL - && cl->knows_txdone) - chan->txdone_method |= TXDONE_BY_ACK; - spin_unlock_irqrestore(&chan->lock, flags); + return init_channel(*chan, cl); +} - ret = chan->mbox->ops->startup(chan); - if (ret) { - pr_err("Unable to startup the chan\n"); - mbox_free_channel(chan); - chan = ERR_PTR(ret); - } +/** + * mbox_request_channel - Request a mailbox channel. + * @cl: Identity of the client requesting the channel. + * + * The Client specifies its requirements and capabilities while asking for + * a mailbox channel by name. It can't be called from atomic context. + * The channel is exclusively allocated and can't be used by another + * client before the owner calls mbox_free_channel. + * After assignment, any packet received on this channel will be + * handed over to the client via the 'rx_callback'. + * + * Return: Pointer to the channel assigned to the client if successful. + * ERR_PTR for request failure. + */ +struct mbox_chan *mbox_request_channel(struct mbox_client *cl) +{ + struct mbox_chan *chan = NULL; + int ret; + + mutex_lock(&con_mutex); + + ret = get_of_mbox_chan(cl, &chan); + +#ifdef CONFIG_ACPI + ret = get_acpi_mbox_chan(cl, &chan); +#endif + if (ret) + pr_err("No mailbox channels found\n"); mutex_unlock(&con_mutex); return chan; @@ -394,11 +437,14 @@ void mbox_free_channel(struct mbox_chan *chan) if (chan->txdone_method == (TXDONE_BY_POLL | TXDONE_BY_ACK)) chan->txdone_method = TXDONE_BY_POLL; +#ifndef CONFIG_ACPI module_put(chan->mbox->dev->driver->owner); +#endif spin_unlock_irqrestore(&chan->lock, flags); } EXPORT_SYMBOL_GPL(mbox_free_channel); +#ifndef CONFIG_ACPI static struct mbox_chan * of_mbox_index_xlate(struct mbox_controller *mbox, const struct of_phandle_args *sp) @@ -410,7 +456,7 @@ of_mbox_index_xlate(struct mbox_controller *mbox, return &mbox->chans[ind]; } - +#endif /** * mbox_controller_register - Register the mailbox controller * @mbox: Pointer to the mailbox controller. @@ -422,9 +468,13 @@ int mbox_controller_register(struct mbox_controller *mbox) int i, txdone; /* Sanity check */ - if (!mbox || !mbox->dev || !mbox->ops || !mbox->num_chans) + if (!mbox || !mbox->ops || !mbox->num_chans) return -EINVAL; +#ifndef CONFIG_ACPI + if (!mbox->dev) + return -EINVAL; +#endif if (mbox->txdone_irq) txdone = TXDONE_BY_IRQ; else if (mbox->txdone_poll) @@ -446,9 +496,10 @@ int mbox_controller_register(struct mbox_controller *mbox) spin_lock_init(&chan->lock); } +#ifndef CONFIG_ACPI if (!mbox->of_xlate) mbox->of_xlate = of_mbox_index_xlate; - +#endif mutex_lock(&con_mutex); list_add_tail(&mbox->node, &mbox_cons); mutex_unlock(&con_mutex); diff --git a/include/linux/mailbox_client.h b/include/linux/mailbox_client.h index bbac2d2..21568a1 100644 --- a/include/linux/mailbox_client.h +++ b/include/linux/mailbox_client.h @@ -35,6 +35,9 @@ struct mbox_client { bool tx_block; unsigned long tx_tout; bool knows_txdone; +#ifdef CONFIG_ACPI + const char *ctrl_name; +#endif }; struct mbox_chan *mbox_request_channel(struct mbox_client *cl); diff --git a/include/linux/mailbox_controller.h b/include/linux/mailbox_controller.h index cf81e80..dc9d290 100644 --- a/include/linux/mailbox_controller.h +++ b/include/linux/mailbox_controller.h @@ -78,6 +78,9 @@ struct mbox_controller { unsigned period; /* Hook to add to the global controller list */ struct list_head node; +#ifdef CONFIG_ACPI + char *name; +#endif } __aligned(32); /* @@ -111,6 +114,9 @@ struct mbox_chan { /* Private data for controller */ void *con_priv; +#ifdef CONFIG_ACPI + char *name; +#endif } __aligned(32); int mbox_controller_register(struct mbox_controller *mbox);