From: Alex Elder <elder@linaro.org>
To: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>,
mhi@lists.linux.dev
Cc: quic_hemantk@quicinc.com, quic_bbhatt@quicinc.com,
quic_jhugo@quicinc.com, vinod.koul@linaro.org,
bjorn.andersson@linaro.org, dmitry.baryshkov@linaro.org,
quic_vbadigan@quicinc.com, quic_cang@quicinc.com,
quic_skananth@quicinc.com, linux-arm-msm@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 11/25] bus: mhi: ep: Add support for managing MMIO registers
Date: Tue, 15 Feb 2022 14:03:05 -0600 [thread overview]
Message-ID: <ca021c94-67ca-477d-57bc-6eceac4c3dae@linaro.org> (raw)
In-Reply-To: <20220212182117.49438-12-manivannan.sadhasivam@linaro.org>
On 2/12/22 12:21 PM, Manivannan Sadhasivam wrote:
> Add support for managing the Memory Mapped Input Output (MMIO) registers
> of the MHI bus. All MHI operations are carried out using the MMIO registers
> by both host and the endpoint device.
>
> The MMIO registers reside inside the endpoint device memory (fixed
> location based on the platform) and the address is passed by the MHI EP
> controller driver during its registration.
>
> Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
This is in pretty good shape, just a few comments.
-Alex
> ---
> drivers/bus/mhi/ep/Makefile | 2 +-
> drivers/bus/mhi/ep/internal.h | 37 +++++
> drivers/bus/mhi/ep/main.c | 6 +-
> drivers/bus/mhi/ep/mmio.c | 274 ++++++++++++++++++++++++++++++++++
> include/linux/mhi_ep.h | 18 +++
> 5 files changed, 335 insertions(+), 2 deletions(-)
> create mode 100644 drivers/bus/mhi/ep/mmio.c
>
> diff --git a/drivers/bus/mhi/ep/Makefile b/drivers/bus/mhi/ep/Makefile
> index 64e29252b608..a1555ae287ad 100644
> --- a/drivers/bus/mhi/ep/Makefile
> +++ b/drivers/bus/mhi/ep/Makefile
> @@ -1,2 +1,2 @@
> obj-$(CONFIG_MHI_BUS_EP) += mhi_ep.o
> -mhi_ep-y := main.o
> +mhi_ep-y := main.o mmio.o
> diff --git a/drivers/bus/mhi/ep/internal.h b/drivers/bus/mhi/ep/internal.h
> index e313a2546664..2c756a90774c 100644
> --- a/drivers/bus/mhi/ep/internal.h
> +++ b/drivers/bus/mhi/ep/internal.h
> @@ -101,6 +101,17 @@ struct mhi_generic_ctx {
> __u64 wp __packed __aligned(4);
> };
>
> +/**
> + * enum mhi_ep_execenv - MHI Endpoint Execution Environment
> + * @MHI_EP_SBL_EE: Secondary Bootloader
> + * @MHI_EP_AMSS_EE: Advanced Mode Subscriber Software
> + */
> +enum mhi_ep_execenv {
> + MHI_EP_SBL_EE = 1,
> + MHI_EP_AMSS_EE = 2,
> + MHI_EP_UNRESERVED
UNRESERVED? What does that mean?
> +};
> +
> enum mhi_ep_ring_type {
> RING_TYPE_CMD = 0,
> RING_TYPE_ER,
> @@ -157,4 +168,30 @@ struct mhi_ep_chan {
> bool skip_td;
> };
>
> +/* MMIO related functions */
> +u32 mhi_ep_mmio_read(struct mhi_ep_cntrl *mhi_cntrl, u32 offset);
> +void mhi_ep_mmio_write(struct mhi_ep_cntrl *mhi_cntrl, u32 offset, u32 val);
> +void mhi_ep_mmio_masked_write(struct mhi_ep_cntrl *mhi_cntrl, u32 offset, u32 mask, u32 val);
> +u32 mhi_ep_mmio_masked_read(struct mhi_ep_cntrl *dev, u32 offset, u32 mask);
> +void mhi_ep_mmio_enable_ctrl_interrupt(struct mhi_ep_cntrl *mhi_cntrl);
> +void mhi_ep_mmio_disable_ctrl_interrupt(struct mhi_ep_cntrl *mhi_cntrl);
> +void mhi_ep_mmio_enable_cmdb_interrupt(struct mhi_ep_cntrl *mhi_cntrl);
> +void mhi_ep_mmio_disable_cmdb_interrupt(struct mhi_ep_cntrl *mhi_cntrl);
> +void mhi_ep_mmio_enable_chdb_a7(struct mhi_ep_cntrl *mhi_cntrl, u32 chdb_id);
> +void mhi_ep_mmio_disable_chdb_a7(struct mhi_ep_cntrl *mhi_cntrl, u32 chdb_id);
> +void mhi_ep_mmio_enable_chdb_interrupts(struct mhi_ep_cntrl *mhi_cntrl);
> +void mhi_ep_mmio_read_chdb_status_interrupts(struct mhi_ep_cntrl *mhi_cntrl);
> +void mhi_ep_mmio_mask_interrupts(struct mhi_ep_cntrl *mhi_cntrl);
> +void mhi_ep_mmio_get_chc_base(struct mhi_ep_cntrl *mhi_cntrl);
> +void mhi_ep_mmio_get_erc_base(struct mhi_ep_cntrl *mhi_cntrl);
> +void mhi_ep_mmio_get_crc_base(struct mhi_ep_cntrl *mhi_cntrl);
> +u64 mhi_ep_mmio_get_db(struct mhi_ep_ring *ring);
> +void mhi_ep_mmio_set_env(struct mhi_ep_cntrl *mhi_cntrl, u32 value);
> +void mhi_ep_mmio_clear_reset(struct mhi_ep_cntrl *mhi_cntrl);
> +void mhi_ep_mmio_reset(struct mhi_ep_cntrl *mhi_cntrl);
> +void mhi_ep_mmio_get_mhi_state(struct mhi_ep_cntrl *mhi_cntrl, enum mhi_state *state,
> + bool *mhi_reset);
> +void mhi_ep_mmio_init(struct mhi_ep_cntrl *mhi_cntrl);
> +void mhi_ep_mmio_update_ner(struct mhi_ep_cntrl *mhi_cntrl);
> +
> #endif
> diff --git a/drivers/bus/mhi/ep/main.c b/drivers/bus/mhi/ep/main.c
> index fcaacf9ddbd1..950b5bcabe18 100644
> --- a/drivers/bus/mhi/ep/main.c
> +++ b/drivers/bus/mhi/ep/main.c
> @@ -205,7 +205,7 @@ int mhi_ep_register_controller(struct mhi_ep_cntrl *mhi_cntrl,
> struct mhi_ep_device *mhi_dev;
> int ret;
>
> - if (!mhi_cntrl || !mhi_cntrl->cntrl_dev)
> + if (!mhi_cntrl || !mhi_cntrl->cntrl_dev || !mhi_cntrl->mmio)
> return -EINVAL;
>
> ret = parse_ch_cfg(mhi_cntrl, config);
> @@ -218,6 +218,10 @@ int mhi_ep_register_controller(struct mhi_ep_cntrl *mhi_cntrl,
> goto err_free_ch;
> }
>
> + /* Set MHI version and AMSS EE before enumeration */
> + mhi_ep_mmio_write(mhi_cntrl, MHIVER, config->mhi_version);
> + mhi_ep_mmio_set_env(mhi_cntrl, MHI_EP_AMSS_EE);
> +
> /* Set controller index */
> mhi_cntrl->index = ida_alloc(&mhi_ep_cntrl_ida, GFP_KERNEL);
> if (mhi_cntrl->index < 0) {
> diff --git a/drivers/bus/mhi/ep/mmio.c b/drivers/bus/mhi/ep/mmio.c
> new file mode 100644
> index 000000000000..58e887beb050
> --- /dev/null
> +++ b/drivers/bus/mhi/ep/mmio.c
> @@ -0,0 +1,274 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Copyright (C) 2021 Linaro Ltd.
> + * Author: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> + */
> +
> +#include <linux/bitfield.h>
> +#include <linux/io.h>
> +#include <linux/mhi_ep.h>
> +
> +#include "internal.h"
> +
> +u32 mhi_ep_mmio_read(struct mhi_ep_cntrl *mhi_cntrl, u32 offset)
> +{
> + return readl(mhi_cntrl->mmio + offset);
> +}
> +
> +void mhi_ep_mmio_write(struct mhi_ep_cntrl *mhi_cntrl, u32 offset, u32 val)
> +{
> + writel(val, mhi_cntrl->mmio + offset);
> +}
> +
> +void mhi_ep_mmio_masked_write(struct mhi_ep_cntrl *mhi_cntrl, u32 offset, u32 mask, u32 val)
> +{
> + u32 regval;
> +
> + regval = mhi_ep_mmio_read(mhi_cntrl, offset);
> + regval &= ~mask;
> + regval |= ((val << __ffs(mask)) & mask);
One extra set of parentheses here is not needed. Assignment
is very low precedence in C.
> + mhi_ep_mmio_write(mhi_cntrl, offset, regval);
> +}
> +
> +u32 mhi_ep_mmio_masked_read(struct mhi_ep_cntrl *dev, u32 offset, u32 mask)
> +{
> + u32 regval;
> +
> + regval = mhi_ep_mmio_read(dev, offset);
> + regval &= mask;
> + regval >>= __ffs(mask);
> +
> + return regval;
> +}
> +
> +void mhi_ep_mmio_get_mhi_state(struct mhi_ep_cntrl *mhi_cntrl, enum mhi_state *state,
> + bool *mhi_reset)
> +{
> + u32 regval;
> +
> + regval = mhi_ep_mmio_read(mhi_cntrl, MHICTRL);
> + *state = FIELD_GET(MHICTRL_MHISTATE_MASK, regval);
> + *mhi_reset = !!FIELD_GET(MHICTRL_RESET_MASK, regval);
> +}
> +
What does "a7" mean to you. Is it the host, or the SDX AP?
Will "a7" always be the proper name for that CPU? (Maybe
it will be.)
> +static void mhi_ep_mmio_mask_set_chdb_int_a7(struct mhi_ep_cntrl *mhi_cntrl,
> + u32 chdb_id, bool enable)
I think "ch_id" would be a better name for the "chdb_id" argument.
If you agree, update other functions so it's consistent.
> +{
> + u32 chid_mask, chid_idx, chid_shift, val = 0;
> +
> + chid_shift = chdb_id % 32;
> + chid_mask = BIT(chid_shift);
> + chid_idx = chdb_id / 32;
I think "chdb_idx" would be a better name for this.
> +
> + WARN_ON(chid_idx >= MHI_MASK_ROWS_CH_EV_DB);
Can we tell by inspection that this will never be out
of range? If not, can we just test it once, early, so
there's no need to ever check later on?
> +
> + if (enable)
> + val = 1;
val = enable ? 1 : 0;
> + mhi_ep_mmio_masked_write(mhi_cntrl, MHI_CHDB_INT_MASK_A7_n(chid_idx),
> + chid_mask, val);
> +
> + /* Update the local copy of the channel mask */
> + mhi_cntrl->chdb[chid_idx].mask &= ~chid_mask;
> + mhi_cntrl->chdb[chid_idx].mask |= val << chid_shift;
> +}
> +
> +void mhi_ep_mmio_enable_chdb_a7(struct mhi_ep_cntrl *mhi_cntrl, u32 chdb_id)
> +{
> + mhi_ep_mmio_mask_set_chdb_int_a7(mhi_cntrl, chdb_id, true);
> +}
> +
> +void mhi_ep_mmio_disable_chdb_a7(struct mhi_ep_cntrl *mhi_cntrl, u32 chdb_id)
> +{
> + mhi_ep_mmio_mask_set_chdb_int_a7(mhi_cntrl, chdb_id, false);
> +}
> +
> +static void mhi_ep_mmio_set_chdb_interrupts(struct mhi_ep_cntrl *mhi_cntrl, bool enable)
> +{
> + u32 val = 0, i;
> +
> + if (enable)
> + val = MHI_CHDB_INT_MASK_A7_n_EN_ALL;
val = enable ? MHI_CHDB_INT_MASK_A7_n_EN_ALL : 0;
> +
> + for (i = 0; i < MHI_MASK_ROWS_CH_EV_DB; i++) {
> + mhi_ep_mmio_write(mhi_cntrl, MHI_CHDB_INT_MASK_A7_n(i), val);
> + mhi_cntrl->chdb[i].mask = val;
> + }
> +}
> +
No more comments on the rest of this file.
. . .
> diff --git a/include/linux/mhi_ep.h b/include/linux/mhi_ep.h
> index da865f9d3646..3d2ab7a5ccd7 100644
> --- a/include/linux/mhi_ep.h
> +++ b/include/linux/mhi_ep.h
This looks good too.
. . .
next prev parent reply other threads:[~2022-02-15 20:03 UTC|newest]
Thread overview: 92+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-12 18:20 [PATCH v3 00/25] Add initial support for MHI endpoint stack Manivannan Sadhasivam
2022-02-12 18:20 ` [PATCH v3 01/25] bus: mhi: Fix pm_state conversion to string Manivannan Sadhasivam
2022-02-15 20:01 ` Alex Elder
2022-02-16 11:33 ` Manivannan Sadhasivam
2022-02-16 13:41 ` Alex Elder
2022-02-12 18:20 ` [PATCH v3 02/25] bus: mhi: Fix MHI DMA structure endianness Manivannan Sadhasivam
2022-02-15 20:02 ` Alex Elder
2022-02-16 7:04 ` Manivannan Sadhasivam
2022-02-16 14:29 ` Alex Elder
2022-02-12 18:20 ` [PATCH v3 03/25] bus: mhi: Move host MHI code to "host" directory Manivannan Sadhasivam
2022-02-15 20:02 ` Alex Elder
2022-02-12 18:20 ` [PATCH v3 04/25] bus: mhi: Move common MHI definitions out of host directory Manivannan Sadhasivam
2022-02-15 0:28 ` Hemant Kumar
2022-02-15 20:02 ` Alex Elder
2022-02-12 18:20 ` [PATCH v3 05/25] bus: mhi: Make mhi_state_str[] array static inline and move to common.h Manivannan Sadhasivam
2022-02-15 0:31 ` Hemant Kumar
2022-02-15 20:02 ` Alex Elder
2022-02-16 11:39 ` Manivannan Sadhasivam
2022-02-16 14:30 ` Alex Elder
2022-02-12 18:20 ` [PATCH v3 06/25] bus: mhi: Cleanup the register definitions used in headers Manivannan Sadhasivam
2022-02-15 0:37 ` Hemant Kumar
2022-02-15 20:02 ` Alex Elder
2022-02-16 17:21 ` Manivannan Sadhasivam
2022-02-16 17:43 ` Manivannan Sadhasivam
2022-02-12 18:20 ` [PATCH v3 07/25] bus: mhi: Get rid of SHIFT macros and use bitfield operations Manivannan Sadhasivam
2022-02-15 20:02 ` Alex Elder
2022-02-16 16:45 ` Manivannan Sadhasivam
2022-02-12 18:21 ` [PATCH v3 08/25] bus: mhi: ep: Add support for registering MHI endpoint controllers Manivannan Sadhasivam
2022-02-15 1:04 ` Hemant Kumar
2022-02-16 17:33 ` Manivannan Sadhasivam
2022-02-15 20:02 ` Alex Elder
2022-02-17 9:53 ` Manivannan Sadhasivam
2022-02-17 14:47 ` Alex Elder
2022-03-04 21:46 ` Jeffrey Hugo
2022-02-12 18:21 ` [PATCH v3 09/25] bus: mhi: ep: Add support for registering MHI endpoint client drivers Manivannan Sadhasivam
2022-02-12 18:32 ` Manivannan Sadhasivam
2022-02-15 1:10 ` Hemant Kumar
2022-02-15 20:02 ` Alex Elder
2022-02-17 10:20 ` Manivannan Sadhasivam
2022-02-17 14:50 ` Alex Elder
2022-02-12 18:21 ` [PATCH v3 10/25] bus: mhi: ep: Add support for creating and destroying MHI EP devices Manivannan Sadhasivam
2022-02-15 20:02 ` Alex Elder
2022-02-17 12:04 ` Manivannan Sadhasivam
2022-02-12 18:21 ` [PATCH v3 11/25] bus: mhi: ep: Add support for managing MMIO registers Manivannan Sadhasivam
2022-02-15 1:14 ` Hemant Kumar
2022-02-15 20:03 ` Alex Elder [this message]
2022-02-12 18:21 ` [PATCH v3 12/25] bus: mhi: ep: Add support for ring management Manivannan Sadhasivam
2022-02-15 20:03 ` Alex Elder
2022-02-18 8:07 ` Manivannan Sadhasivam
2022-02-18 15:23 ` Manivannan Sadhasivam
2022-02-18 15:47 ` Alex Elder
2022-02-18 15:39 ` Alex Elder
2022-02-12 18:21 ` [PATCH v3 13/25] bus: mhi: ep: Add support for sending events to the host Manivannan Sadhasivam
2022-02-15 22:39 ` Alex Elder
2022-02-22 6:06 ` Manivannan Sadhasivam
2022-02-22 13:41 ` Alex Elder
2022-02-12 18:21 ` [PATCH v3 14/25] bus: mhi: ep: Add support for managing MHI state machine Manivannan Sadhasivam
2022-02-15 22:39 ` Alex Elder
2022-02-22 7:03 ` Manivannan Sadhasivam
2022-02-12 18:21 ` [PATCH v3 15/25] bus: mhi: ep: Add support for processing MHI endpoint interrupts Manivannan Sadhasivam
2022-02-15 22:39 ` Alex Elder
2022-02-22 8:18 ` Manivannan Sadhasivam
2022-02-22 14:08 ` Alex Elder
2022-02-12 18:21 ` [PATCH v3 16/25] bus: mhi: ep: Add support for powering up the MHI endpoint stack Manivannan Sadhasivam
2022-02-15 22:39 ` Alex Elder
2022-02-22 9:08 ` Manivannan Sadhasivam
2022-02-22 14:10 ` Alex Elder
2022-02-12 18:21 ` [PATCH v3 17/25] bus: mhi: ep: Add support for powering down " Manivannan Sadhasivam
2022-02-15 22:39 ` Alex Elder
2022-02-12 18:21 ` [PATCH v3 18/25] bus: mhi: ep: Add support for handling MHI_RESET Manivannan Sadhasivam
2022-02-15 22:39 ` Alex Elder
2022-02-12 18:21 ` [PATCH v3 19/25] bus: mhi: ep: Add support for handling SYS_ERR condition Manivannan Sadhasivam
2022-02-15 22:39 ` Alex Elder
2022-02-22 10:29 ` Manivannan Sadhasivam
2022-02-12 18:21 ` [PATCH v3 20/25] bus: mhi: ep: Add support for processing command ring Manivannan Sadhasivam
2022-02-15 22:40 ` Alex Elder
2022-02-22 10:35 ` Manivannan Sadhasivam
2022-02-12 18:21 ` [PATCH v3 21/25] bus: mhi: ep: Add support for reading from the host Manivannan Sadhasivam
2022-02-15 22:40 ` Alex Elder
2022-02-12 18:21 ` [PATCH v3 22/25] bus: mhi: ep: Add support for processing transfer ring Manivannan Sadhasivam
2022-02-15 22:40 ` Alex Elder
2022-02-22 10:50 ` Manivannan Sadhasivam
2022-02-12 18:21 ` [PATCH v3 23/25] bus: mhi: ep: Add support for queueing SKBs to the host Manivannan Sadhasivam
2022-02-15 22:40 ` Alex Elder
2022-02-22 14:38 ` Manivannan Sadhasivam
2022-02-22 15:18 ` Alex Elder
2022-02-22 16:05 ` Alex Elder
2022-02-12 18:21 ` [PATCH v3 24/25] bus: mhi: ep: Add support for suspending and resuming channels Manivannan Sadhasivam
2022-02-15 22:40 ` Alex Elder
2022-02-12 18:21 ` [PATCH v3 25/25] bus: mhi: ep: Add uevent support for module autoloading Manivannan Sadhasivam
2022-02-15 22:40 ` Alex Elder
2022-02-15 20:01 ` [PATCH v3 00/25] Add initial support for MHI endpoint stack Alex Elder
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ca021c94-67ca-477d-57bc-6eceac4c3dae@linaro.org \
--to=elder@linaro.org \
--cc=bjorn.andersson@linaro.org \
--cc=dmitry.baryshkov@linaro.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=manivannan.sadhasivam@linaro.org \
--cc=mhi@lists.linux.dev \
--cc=quic_bbhatt@quicinc.com \
--cc=quic_cang@quicinc.com \
--cc=quic_hemantk@quicinc.com \
--cc=quic_jhugo@quicinc.com \
--cc=quic_skananth@quicinc.com \
--cc=quic_vbadigan@quicinc.com \
--cc=vinod.koul@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®