Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1280328ybi; Wed, 17 Jul 2019 12:27:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqwQNscfFfkMfAYAp7tY30PF4YqN7p6Ze8lSJnIKQI425ckvV6XCP62Knn/DRzsk82xpYgJA X-Received: by 2002:a17:902:9689:: with SMTP id n9mr45829772plp.241.1563391671566; Wed, 17 Jul 2019 12:27:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563391671; cv=none; d=google.com; s=arc-20160816; b=kTnAsmgLD8MUB8F5QLCZPnvYXMQTHW7PFVpr4O4y+ostXYWYMm6Rv+0/A0uOpnUxAP 8rTU0+rijGJSlau2gg2vQCUKMLj4udOiOsN0IPvmUP3vioBOhtQ29y2rmHerbuec2Skb /rzubkcgfszHe8pSzqqe59qN8+ckj2YcvjYvNfxYJl0iYtmVpEhC+FIWi15ya5BtFUhj Y1bjsZXMiAus4J1/6QZnCB4TdknrGsbEVvP0XTZ5HRM3+Pj2/kkWYUAyP/V0s9QR52VI D+5T6bTW0XFRaS9/uKvWh9A0fDUrnIEfM+tBy1E9mJG/48IqToCECXtsET9ncXV0/Bsc lqeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=I1MbKJ0i4lcLgytdGcGjE76pdg6qLH27z52oFhcBPnE=; b=sgGa5HWBebH4BXNGwgZml0rX4fnyX62b3E6295vtdCaYqVem/vfGEaUSqooVHRjRaD HWdh+qyHkAslnFw3mIrnvsuKfqly/k7OySEL6awlm09jcl6S7n5vCqDFbxBBMF/fGHT5 6Z/tL8eFSx6q84xVK33S3dS8AzgeEe5jKnSqtJ690gPHyQm+Sfau+lx/qcsihMBYWW7H b6JXz+v1/Qc2oix+7zcmZvk+VbbfbMihcfIBHGAB7CxEIkCEkkJSMqVm8lT6B+UVlTA0 N+a/PDaxe3Je9FD9j0fgb+rBqX+3iuFx0mzNG7r68N4kMaNuwS5etT8f1bUSozUh4PB3 p4bQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w21si25055671pff.263.2019.07.17.12.27.35; Wed, 17 Jul 2019 12:27:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727495AbfGQT0p (ORCPT + 99 others); Wed, 17 Jul 2019 15:26:45 -0400 Received: from foss.arm.com ([217.140.110.172]:50286 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727270AbfGQT0o (ORCPT ); Wed, 17 Jul 2019 15:26:44 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 19D84344; Wed, 17 Jul 2019 12:26:43 -0700 (PDT) Received: from tuskha01.cambridge.arm.com (tuskha01.cambridge.arm.com [10.1.196.61]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id EDDEF3F71A; Wed, 17 Jul 2019 12:26:41 -0700 (PDT) From: Tushar Khandelwal To: linux-kernel@vger.kernel.org Cc: tushar.2nov@gmail.com, morten_bp@live.dk, jassisinghbrar@gmail.com, nd@arm.com, Morten Borup Petersen , Tushar Khandelwal , devicetree@vger.kernel.org Subject: [PATCH 3/4] mailbox: arm_mhuv2: add doorbell transport protocol operations Date: Wed, 17 Jul 2019 20:26:15 +0100 Message-Id: <20190717192616.1731-4-tushar.khandelwal@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190717192616.1731-1-tushar.khandelwal@arm.com> References: <20190717192616.1731-1-tushar.khandelwal@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Morten Borup Petersen In doorbell mode, the mailbox controller will provide a mailbox for each flag bit available in the combined number of channel windows available within the MHU device. When in doorbell mode, the MHU should be used solely as an interrupt generating mechanism. If data is to be transmitted, this must be done out-band, ie. through shared memory, by a driving utilizing the mailbox for interrupt generation. Signed-off-by: Morten Borup Petersen Signed-off-by: Tushar Khandelwal Cc:Jassi Brar reg.recv->channel[ch_window_idx].STAT_CLEAR); + return 0; +} + +static inline int mhuv2_send_data_doorbell(struct arm_mhuv2 *mhuv2, + struct mbox_chan *chan, + const struct arm_mbox_msg *msg) +{ + const u32 ch_mbox_idx = mhuv2_chan_idx(chan); + const u32 ch_window_idx = ch_mbox_idx / MHUV2_STAT_BITS; + const u32 ch_window_reg_idx = ch_mbox_idx % MHUV2_STAT_BITS; + + writel_relaxed( + readl_relaxed(&mhuv2->reg.send->channel[ch_window_idx].STAT) | + BIT(ch_window_reg_idx), + &mhuv2->reg.send->channel[ch_window_idx].STAT_SET); + return 0; +} + +static inline int mhuv2_last_tx_done_doorbell(struct arm_mhuv2 *mhuv2, + struct mbox_chan *chan) +{ + const u32 ch_mbox_idx = mhuv2_chan_idx(chan); + const u32 ch_window_idx = ch_mbox_idx / MHUV2_STAT_BITS; + const u32 ch_window_reg_idx = ch_mbox_idx % MHUV2_STAT_BITS; + + return (readl_relaxed(&mhuv2->reg.send->channel[ch_window_idx].STAT) & + BIT(ch_window_reg_idx)) == 0; +} + +static inline int mhuv2_setup_doorbell(struct arm_mhuv2 *mhuv2) +{ + int i; + const u32 channel_windows = + readl_relaxed_bitfield(mhuv2->frame == RECEIVER_FRAME ? + &mhuv2->reg.recv->MHU_CFG : + &mhuv2->reg.send->MHU_CFG, + NUM_CH); + + mhuv2->mbox.num_chans = MHUV2_STAT_BITS * channel_windows; + mhuv2->mbox.chans = + devm_kzalloc(mhuv2->dev, + mhuv2->mbox.num_chans * sizeof(struct mbox_chan), + GFP_KERNEL); + + for (i = 0; i < mhuv2->mbox.num_chans; i++) { + mhuv2->mbox.chans[i].con_priv = + devm_kzalloc(mhuv2->dev, + sizeof(struct arm_mhuv2_mbox_chan_priv), + GFP_KERNEL); + mhuv2_chan_idx(&mhuv2->mbox.chans[i]) = i; + } + + if (mhuv2->frame == RECEIVER_FRAME) { + /* Ensure all status registers are unmasked */ + for (i = 0; i < channel_windows; i++) { + writel_relaxed(0x0, + &mhuv2->reg.recv->channel[i].MASK_SET); + } + } + + return 0; +} + +static inline struct mbox_chan * + mhuv2_get_active_mbox_chan_doorbell(struct arm_mhuv2 *mhuv2) +{ + const u32 ch_window_idx = mhuv2_combint_idx(mhuv2); + const u32 ch_window_reg_idx = __find_set_bit( + readl_relaxed(&mhuv2->reg.recv->channel[ch_window_idx].STAT)); + if (ch_window_reg_idx == -1) + return ERR_PTR(-EIO); + + return &mhuv2->mbox.chans[ch_window_reg_idx + + ch_window_idx * MHUV2_STAT_BITS]; +} + +static const struct mhuv2_ops mhuv2_doorbell_ops = { + .read_data = mhuv2_read_data_doorbell, + .clear_data = mhuv2_clear_data_doorbell, + .send_data = mhuv2_send_data_doorbell, + .setup = mhuv2_setup_doorbell, + .last_tx_done = mhuv2_last_tx_done_doorbell, + .get_active_mbox_chan = mhuv2_get_active_mbox_chan_doorbell, +}; +/* ========================================================================== */ + /* * MHUv2 receiver interrupt service routine * @@ -638,6 +743,9 @@ static int mhuv2_probe(struct amba_device *adev, const struct amba_id *id) case SINGLE_WORD: mhuv2->ops = &mhuv2_single_word_ops; break; + case DOORBELL: + mhuv2->ops = &mhuv2_doorbell_ops; + break; default: return -ENODEV; } -- 2.17.1