From patchwork Fri Jun 20 18:57:25 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ashwin Chaugule X-Patchwork-Id: 32296 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ig0-f197.google.com (mail-ig0-f197.google.com [209.85.213.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 954CB203C2 for ; Fri, 20 Jun 2014 18:57:28 +0000 (UTC) Received: by mail-ig0-f197.google.com with SMTP id r10sf2844335igi.8 for ; Fri, 20 Jun 2014 11:57:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:mime-version:in-reply-to:references :date:message-id:subject:from:to:cc:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe:content-type; bh=1Z2z70u+Vs9zS8hd4VAFw6orJiFixXCjfcStDfutoSc=; b=JC3doKS+MkGFPcjJjz61+C8V6GQpf1PIwuaxNBsTmpM0TMc6ULqbCG9d+94TDFRSYD 3z7VvC9c5Z6KttpoaMo8lHJWNGyjNgqOX1bY9IMS2yGAl+ePrwHNV7n/h/5q+gOeyhwe vyNwdcVWvl/xl32wfxVM+xdh5r//1w/faCAu7FWNo4vsI2c5/VjcKbpfyJT93twWJl3r X+hVhWs2boUVsDoF/0Ib0kFlefEZsIWE64a14zemgArqOQAUEC4CR4A8DEd5+sq0eSJQ 1rp8f5Qm/QLrZSMVwLLcl1gtI/2z9OgBBBNIvYGUr2wcqJ+OAkzGAteHIKeug4C1IfAH ySXQ== X-Gm-Message-State: ALoCoQmt9toLxoBE5AlmXWBsPkvs9MfFBqkApwNqDfROALRL5YWV/vkIgpWCXbE4tZO3ocJjSdxa X-Received: by 10.50.138.194 with SMTP id qs2mr2134366igb.6.1403290647946; Fri, 20 Jun 2014 11:57:27 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.92.68 with SMTP id a62ls1076298qge.79.gmail; Fri, 20 Jun 2014 11:57:27 -0700 (PDT) X-Received: by 10.58.68.129 with SMTP id w1mr2065574vet.49.1403290647849; Fri, 20 Jun 2014 11:57:27 -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 u5si3473803vei.26.2014.06.20.11.57.27 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 20 Jun 2014 11:57:27 -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 il7so3805332vcb.13 for ; Fri, 20 Jun 2014 11:57:27 -0700 (PDT) X-Received: by 10.220.53.72 with SMTP id l8mr4615176vcg.16.1403290647766; Fri, 20 Jun 2014 11:57:27 -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.37.5 with SMTP id tc5csp43933vcb; Fri, 20 Jun 2014 11:57:26 -0700 (PDT) X-Received: by 10.195.11.34 with SMTP id ef2mr5729194wjd.123.1403290646202; Fri, 20 Jun 2014 11:57:26 -0700 (PDT) Received: from mail-wi0-f175.google.com (mail-wi0-f175.google.com [209.85.212.175]) by mx.google.com with ESMTPS id a15si12296208wjz.50.2014.06.20.11.57.25 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 20 Jun 2014 11:57:26 -0700 (PDT) Received-SPF: pass (google.com: domain of ashwin.chaugule@linaro.org designates 209.85.212.175 as permitted sender) client-ip=209.85.212.175; Received: by mail-wi0-f175.google.com with SMTP id r20so1314549wiv.8 for ; Fri, 20 Jun 2014 11:57:25 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.194.200.3 with SMTP id jo3mr6078510wjc.110.1403290645635; Fri, 20 Jun 2014 11:57:25 -0700 (PDT) Received: by 10.217.67.6 with HTTP; Fri, 20 Jun 2014 11:57:25 -0700 (PDT) In-Reply-To: References: <1402591692-7736-1-git-send-email-ashwin.chaugule@linaro.org> <1402591692-7736-2-git-send-email-ashwin.chaugule@linaro.org> <4476889.LvjMyVbGZ8@wuerfel> Date: Fri, 20 Jun 2014 14:57:25 -0400 Message-ID: Subject: Re: [RFC v2 1/3] Mailbox: Add support for ACPI From: Ashwin Chaugule To: Arnd Bergmann Cc: "linux-arm-kernel@lists.infradead.org" , linux-acpi@vger.kernel.org, Patch Tracking , Jassi Brar , rjw@rjwysocki.net, "linaro-acpi@lists.linaro.org" , Mark Brown 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: , On 20 June 2014 14:55, Ashwin Chaugule wrote: > Hello, > > On 12 June 2014 13:14, Ashwin Chaugule wrote: >> On 12 June 2014 13:02, Arnd Bergmann wrote: >>> On Thursday 12 June 2014 12:48:10 Ashwin Chaugule wrote: >>>> >>>> +#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); >>>> >>> >>> You can't do #ifndef here, the driver must still work if >>> both OF and ACPI are enabled. >> >> Ok. Here we could skip the macro altogether, since of_xlate wont be >> called with ACPI anyway. >> >> Will need to look into using/faking mbox->dev to remove the other ifndefs. > > > So, in order to get an mbox->dev for ACPI platforms, we'd need an > entry in the DSDT table. That seems rather pointless, since the DSDT > is reserved for devices and is supposed to be OS agnostic. Since the > mailbox controller itself is not really a "device" with a resource > descriptor, I dont see the point in adding a dummy DSDT entry for the > sake of getting this `struct device`. Also, I'm told adding new > entries to this table requires registering a unique 4 character > identifier and approval from some committees. If there are other ways > to get this structure I'd like to hear about it. > > The other alternative would be to piggy back on the ACPI CPU detection > code, which looks for the ACPI0007 device node in the DSDT and use > that as the mbox controller device. This node is already registered > and is an established method to detect CPUs. But I'm not sure what > happens when CPUs are hotplugged off, we surely dont want mailbox > clients such as PCC to break. > > The third alternative is to ignore the dev refcounts for ACPI as shown > in this totally untested patch: > > ----------------8<---------------------------------------- > > > From 6fe6e583f0b23b08643a4a85545a9a5338b9b1a0 Mon Sep 17 00:00:00 2001 > From: Ashwin Chaugule > Date: Wed, 11 Jun 2014 16:09:35 -0400 > Subject: [PATCH] Mailbox: Add support for ACPI > > 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 | 177 ++++++++++++++++++++++++++----------- > include/linux/mailbox_client.h | 2 +- > include/linux/mailbox_controller.h | 1 + > 3 files changed, 129 insertions(+), 51 deletions(-) > > -------------------------8<------------------------------- > > Btw I havent rebased to v7 of the mailbox patchwork yet, since I'd > like to hear feedback on the direction I'm taking with ACPI before I > rebase. > > That probably messed up the formatting.. Attaching the patch. >From 6fe6e583f0b23b08643a4a85545a9a5338b9b1a0 Mon Sep 17 00:00:00 2001 From: Ashwin Chaugule Date: Wed, 11 Jun 2014 16:09:35 -0400 Subject: [PATCH] Mailbox: Add support for ACPI 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 | 177 ++++++++++++++++++++++++++----------- include/linux/mailbox_client.h | 2 +- include/linux/mailbox_controller.h | 1 + 3 files changed, 129 insertions(+), 51 deletions(-) diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c index d83d12c..e2704f5 100644 --- a/drivers/mailbox/mailbox.c +++ b/drivers/mailbox/mailbox.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -273,100 +274,166 @@ 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; + + if (!chan) { + pr_err("No mailbox channel specified\n"); + return -EINVAL; + } + + 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; +} + +static int get_acpi_mbox_chan(struct mbox_client *cl, + struct mbox_chan **chan) +{ + struct mbox_controller *mbox; + int chan_id, ret, len; + char *chan_ptr; + + if (!cl->chan_name) + return -ENODEV; + + list_for_each_entry(mbox, &mbox_cons, node) { + if (mbox->name) { + /* + * The cl->chan_name has the format => controller:channel + * as described in mailbox_client.h + */ + + len = strlen(mbox->name); + chan_ptr = cl->chan_name + len + 1; + + ret = kstrtou32(cl->chan_name, 0, &chan_id); + + if (ret < 0) { + pr_err("Err while parsing mailbox:%s channel idx\n", + mbox->name); + continue; + } + + if (!strncmp(cl->chan_name, mbox->name, len)) { + *chan = &mbox->chans[chan_id]; + return init_channel(*chan, cl); + } + } + } + + return -ENODEV; +} + +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 && acpi_disabled && + 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); + return init_channel(*chan, cl); +} + +/** + * 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); + + if (acpi_disabled) + ret = get_of_mbox_chan(cl, &chan); 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 = get_acpi_mbox_chan(cl, &chan); - ret = chan->mbox->ops->startup(chan); - if (ret) { - pr_err("Unable to startup the chan\n"); - mbox_free_channel(chan); - chan = ERR_PTR(ret); - } + if (ret) + pr_err("No mailbox channels found\n"); mutex_unlock(&con_mutex); return chan; @@ -394,7 +461,9 @@ void mbox_free_channel(struct mbox_chan *chan) if (chan->txdone_method == (TXDONE_BY_POLL | TXDONE_BY_ACK)) chan->txdone_method = TXDONE_BY_POLL; - module_put(chan->mbox->dev->driver->owner); + if (chan->mbox->dev) + module_put(chan->mbox->dev->driver->owner); + spin_unlock_irqrestore(&chan->lock, flags); } EXPORT_SYMBOL_GPL(mbox_free_channel); @@ -422,7 +491,15 @@ 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; + + /* + * For ACPI platforms, to get mbox->dev, we'd need to + * have a fake meaningless entry in the DSDT for the + * mailbox controller. + */ + if (acpi_disabled && !mbox->dev) return -EINVAL; if (mbox->txdone_irq) diff --git a/include/linux/mailbox_client.h b/include/linux/mailbox_client.h index bbac2d2..716fbae 100644 --- a/include/linux/mailbox_client.h +++ b/include/linux/mailbox_client.h @@ -29,7 +29,7 @@ struct mbox_chan; */ struct mbox_client { struct device *dev; - const char *chan_name; + char *chan_name; void (*rx_callback)(struct mbox_client *cl, void *mssg); void (*tx_done)(struct mbox_client *cl, void *mssg, enum mbox_result r); bool tx_block; diff --git a/include/linux/mailbox_controller.h b/include/linux/mailbox_controller.h index cf81e80..06476ef 100644 --- a/include/linux/mailbox_controller.h +++ b/include/linux/mailbox_controller.h @@ -78,6 +78,7 @@ struct mbox_controller { unsigned period; /* Hook to add to the global controller list */ struct list_head node; + char *name; } __aligned(32); /* -- 1.8.3.2