From patchwork Fri Aug 1 12:32:08 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jassi Brar X-Patchwork-Id: 34700 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f198.google.com (mail-ie0-f198.google.com [209.85.223.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 2BEEF20670 for ; Fri, 1 Aug 2014 12:32:40 +0000 (UTC) Received: by mail-ie0-f198.google.com with SMTP id rl12sf20369300iec.1 for ; Fri, 01 Aug 2014 05:32:39 -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=yiwynnQxLhxD+no+jb5OLGU5sGRYWMgnKl6Q4bGe3PM=; b=EoBjoct6aHmq3GOCpo2NrRwF2OufYiPhwJAd1yCGqcz0g2Ct4c0nAnlQNaA81eb4Yr zfaqlFzoMBuP1PkXo8er+NWTlGeE9LiORLLB/qzB45Z+uuaaxwEJGtZ7NP+VTyGx6vHT pCnpIZvgOEYDtkG7fpfDhYx/6iyepY51LR/K+1+izY/Kv0CRW5Lz9B8DV9poouWas//B Yn97zK19FMt/E85egCGG6Q8kTSdKgujsGWOswLZgdycVGDNqVQ5i6Dtizg7CJSeqHz7E enaf3GjualX4ZtfAX7VWm977GU7iUCItgosGxjJMZaXJNUO2Qoot8BZv1KvePrnUv/mX 2O7g== X-Gm-Message-State: ALoCoQmV2g2/U5pVaB+A6266IOd6EF3PqJb0a4/2Qnbz3NZJaNRXoJXHpqp3X0s4F96I52DLtrSs X-Received: by 10.50.153.98 with SMTP id vf2mr1917526igb.5.1406896359716; Fri, 01 Aug 2014 05:32:39 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.108.117 with SMTP id i108ls1386300qgf.76.gmail; Fri, 01 Aug 2014 05:32:39 -0700 (PDT) X-Received: by 10.52.101.168 with SMTP id fh8mr4710862vdb.34.1406896359616; Fri, 01 Aug 2014 05:32:39 -0700 (PDT) Received: from mail-vc0-f176.google.com (mail-vc0-f176.google.com [209.85.220.176]) by mx.google.com with ESMTPS id sx2si7054992vec.81.2014.08.01.05.32.39 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 01 Aug 2014 05:32:39 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.176 as permitted sender) client-ip=209.85.220.176; Received: by mail-vc0-f176.google.com with SMTP id id10so6446850vcb.35 for ; Fri, 01 Aug 2014 05:32:39 -0700 (PDT) X-Received: by 10.220.50.8 with SMTP id x8mr5609519vcf.18.1406896359477; Fri, 01 Aug 2014 05:32:39 -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 tc5csp106784vcb; Fri, 1 Aug 2014 05:32:38 -0700 (PDT) X-Received: by 10.66.97.7 with SMTP id dw7mr5544363pab.114.1406896358466; Fri, 01 Aug 2014 05:32:38 -0700 (PDT) Received: from mail-pa0-f51.google.com (mail-pa0-f51.google.com [209.85.220.51]) by mx.google.com with ESMTPS id r1si4821476pdf.127.2014.08.01.05.32.38 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 01 Aug 2014 05:32:38 -0700 (PDT) Received-SPF: pass (google.com: domain of jaswinder.singh@linaro.org designates 209.85.220.51 as permitted sender) client-ip=209.85.220.51; Received: by mail-pa0-f51.google.com with SMTP id ey11so5725132pad.24 for ; Fri, 01 Aug 2014 05:32:37 -0700 (PDT) X-Received: by 10.68.65.9 with SMTP id t9mr5618528pbs.77.1406896357548; Fri, 01 Aug 2014 05:32:37 -0700 (PDT) Received: from localhost.localdomain ([117.220.130.200]) by mx.google.com with ESMTPSA id fn1sm8576766pbc.77.2014.08.01.05.32.25 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 01 Aug 2014 05:32:36 -0700 (PDT) From: Jassi Brar To: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: ks.giri@samsung.com, arnd@arndb.de, ijc+devicetree@hellion.org.uk, mark.rutland@arm.com, robh+dt@kernel.org, pawel.moll@arm.com, courtney.cavin@sonymobile.com, mporter@linaro.org, slapdau@yahoo.com.au, lftan.linux@gmail.com, loic.pallardy@st.com, s-anna@ti.com, ashwin.chaugule@linaro.org, bjorn@kryo.se, patches@linaro.org, mollie.wu@linaro.org, t.takinishi@jp.fujitsu.com, broonie@linaro.org, khilman@linaro.org, lee.jones@linaro.org, andy.green@linaro.org, Jassi Brar Subject: [PATCHv10 3/4] doc: add documentation for mailbox framework Date: Fri, 1 Aug 2014 18:02:08 +0530 Message-Id: <1406896328-4912-1-git-send-email-jaswinder.singh@linaro.org> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1406896194-4667-1-git-send-email-jaswinder.singh@linaro.org> References: <1406896194-4667-1-git-send-email-jaswinder.singh@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: jaswinder.singh@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.176 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: , Some explanations with examples of how to write to implement users and providers of the mailbox framework. Signed-off-by: Jassi Brar --- Documentation/mailbox.txt | 122 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 Documentation/mailbox.txt diff --git a/Documentation/mailbox.txt b/Documentation/mailbox.txt new file mode 100644 index 0000000..60f43ff --- /dev/null +++ b/Documentation/mailbox.txt @@ -0,0 +1,122 @@ + The Common Mailbox Framework + Jassi Brar + + This document aims to help developers write client and controller +drivers for the API. But before we start, let us note that the +client (especially) and controller drivers are likely going to be +very platform specific because the remote firmware is likely to be +proprietary and implement non-standard protocol. So even if two +platforms employ, say, PL320 controller, the client drivers can't +be shared across them. Even the PL320 driver might need to accommodate +some platform specific quirks. So the API is meant mainly to avoid +similar copies of code written for each platform. Having said that, +nothing prevents the remote f/w to also be Linux based and use the +same api there. However none of that helps us locally because we only +ever deal at client's protocol level. + Some of the choices made during implementation are the result of this +peculiarity of this "common" framework. + + + + Part 1 - Controller Driver (See include/linux/mailbox_controller.h) + + Allocate mbox_controller and the array of mbox_chan. +Populate mbox_chan_ops, except peek_data() all are mandatory. +The controller driver might know a message has been consumed +by the remote by getting an IRQ or polling some hardware flag +or it can never know (the client knows by way of the protocol). +The method in order of preference is IRQ -> Poll -> None, which +the controller driver should set via 'txdone_irq' or 'txdone_poll' +or neither. + + + Part 2 - Client Driver (See include/linux/mailbox_client.h) + + The client might want to operate in blocking mode (synchronously +send a message through before returning) or non-blocking/async mode (submit +a message and a callback function to the API and return immediately). + + +struct demo_client { + struct mbox_client cl; + struct mbox_chan *mbox; + struct completion c; + bool async; + /* ... */ +}; + +/* + * This is the handler for data received from remote. The behaviour is purely + * dependent upon the protocol. This is just an example. + */ +static void message_from_remote(struct mbox_client *cl, void *mssg) +{ + struct demo_client *dc = container_of(mbox_client, + struct demo_client, cl); + if (dc->aysnc) { + if (is_an_ack(mssg)) { + /* An ACK to our last sample sent */ + return; /* Or do something else here */ + } else { /* A new message from remote */ + queue_req(mssg); + } + } else { + /* Remote f/w sends only ACK packets on this channel */ + return; + } +} + +static void sample_sent(struct mbox_client *cl, void *mssg, int r) +{ + struct demo_client *dc = container_of(mbox_client, + struct demo_client, cl); + complete(&dc->c); +} + +static void client_demo(struct platform_device *pdev) +{ + struct demo_client *dc_sync, *dc_async; + /* The controller already knows async_pkt and sync_pkt */ + struct async_pkt ap; + struct sync_pkt sp; + + dc_sync = kzalloc(sizeof(*dc_sync), GFP_KERNEL); + dc_async = kzalloc(sizeof(*dc_async), GFP_KERNEL); + + /* Populate non-blocking mode client */ + dc_async->cl.dev = &pdev->dev; + dc_async->cl.rx_callback = message_from_remote; + dc_async->cl.tx_done = sample_sent; + dc_async->cl.tx_block = false; + dc_async->cl.tx_tout = 0; /* doesn't matter here */ + dc_async->cl.knows_txdone = false; /* depending upon protocol */ + dc_async->async = true; + init_completion(&dc_async->c); + + /* Populate blocking mode client */ + dc_sync->cl.dev = &pdev->dev; + dc_sync->cl.rx_callback = message_from_remote; + dc_sync->cl.tx_done = NULL; /* operate in blocking mode */ + dc_sync->cl.tx_block = true; + dc_sync->cl.tx_tout = 500; /* by half a second */ + dc_sync->cl.knows_txdone = false; /* depending upon protocol */ + dc_sync->async = false; + + /* ASync mailbox is listed second in 'mboxes' property */ + dc_async->mbox = mbox_request_channel(&dc_async->cl, 1); + /* Populate data packet */ + /* ap.xxx = 123; etc */ + /* Send async message to remote */ + mbox_send_message(dc_async->mbox, &ap); + + /* Sync mailbox is listed first in 'mboxes' property */ + dc_sync->mbox = mbox_request_channel(&dc_sync->cl, 0); + /* Populate data packet */ + /* sp.abc = 123; etc */ + /* Send message to remote in blocking mode */ + mbox_send_message(dc_sync->mbox, &sp); + /* At this point 'sp' has been sent */ + + /* Now wait for async chan to be done */ + wait_for_completion(&dc_async->c); +}