Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp122454pxj; Thu, 27 May 2021 23:18:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwNo7Z4wC8bdLpYbJaTS8HSDTAtcVTnfg1OdxJu8E9BLlOTKbevipXD+DKTpgtuYwJO3687 X-Received: by 2002:a05:6402:124f:: with SMTP id l15mr5310069edw.94.1622182718890; Thu, 27 May 2021 23:18:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622182718; cv=none; d=google.com; s=arc-20160816; b=LjYQGsVpeZYdxHcE73s3LIM1qjnz7eAWorK1Zloyl/yP7xBotoaAW5BJlA0mWjV+u7 o91hJtuf+Sq4gInefjqpRi/C9edldi78Upce8/fGsoeCUGIWnyG4FsO9AGya75cZubEA nt7ozoDAPYH8csIWCOriQy6/fShhFDWOumIimX1CwheMtiy+nJSprFlm7DVLTwEtiFLP qKYsEcXhRX7A/tRwuyh4RpU6rL/VnvW3HPjFrClHdYewM3cFgkwgwOSIbMFUawnavV3a NTJLIesq1lTsf/oryAclo451au9EatFL8oYgE3ZbLkdMB2xYcCGxmPCJmoeZ3Sx3J3xz MMRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=oO0Aknxz9u4e0kiIsDD+kH6mpiBoFt6uSgG3WOZetc4=; b=S8MPeBaqAN5kXr30e3nIs8gKrdA6uKp4BGEvHPlClbJt3ii/OWxweum+0SJrTkfTEv ljMlfbJlz+tSoBcdXI+PJN9XFFRvoYycrQKvWnf+TnBNZ9ggYESnMzYsXeiPYMuHI1qv hb9PDSRNr7A6AvcZqOvAEs1Bu+xxHfWxHkh4QDOHN3zqwpCBG7ay/eJXY/V1A75ciKQ7 PXX4LhQgqanSedT4PqFZirql/usreaDZBABrrheLobWZKvB2PTCQI0t+PcCJ2sUjL8a1 uc572cA/my2COQh9wmgTyKb8RGuo9rzt/AIIX5ASoWQ0ag/b/yB1nurbt802HI/TaZfb dZCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wH2vPsuP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t19si4411061ejb.193.2021.05.27.23.18.06; Thu, 27 May 2021 23:18:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wH2vPsuP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230344AbhE1Ehp (ORCPT + 99 others); Fri, 28 May 2021 00:37:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230283AbhE1Eho (ORCPT ); Fri, 28 May 2021 00:37:44 -0400 Received: from mail-ot1-x335.google.com (mail-ot1-x335.google.com [IPv6:2607:f8b0:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FAC4C06174A for ; Thu, 27 May 2021 21:36:10 -0700 (PDT) Received: by mail-ot1-x335.google.com with SMTP id n3-20020a9d74030000b029035e65d0a0b8so2345182otk.9 for ; Thu, 27 May 2021 21:36:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=oO0Aknxz9u4e0kiIsDD+kH6mpiBoFt6uSgG3WOZetc4=; b=wH2vPsuPWzXihvscH3830cVHcmYHrQd3tFW1NtOR2nycU0azENoIGxkUB4gIDUi1OI m/f6IN+nbxR1dQtpA9a2QfynXwSzZXQ1mR5vxKD8ALWbOcRbjuKEYvto6kEPjMgE9BhC 0VpCGKRfRL6XAj5TEh8AQxBEnNYlHuZt1VKAVEdORftnx/9n63yNZ2uOorD/MG5Rm6Bm 4hwR93izgoIweZZEanoPJHXlOcJ2ds+0rRly+Bnbb5UCigouBF0LaMKXqpT+4PMwXqDS QqZrOCkuGYn1uvOkK6ocw46QUMHAlS9wbbFT3Q5qDemUxcSFYuRKQFZimQUe7dtHmWjN zlkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=oO0Aknxz9u4e0kiIsDD+kH6mpiBoFt6uSgG3WOZetc4=; b=Tyy0/6v0N2JEjIDEnZrrWDhPRhMrLlAippfMFtc7jXPyO/X8dasfsaQMS9FOH/lEJD 3NeeN/jYD5UZrNud7t1KynswDthqKJtQPUObFTpC7XfPAsGWP0YRShuv7jiLW2/W8HHO afHYtHaSGh3T9j9pCLoitjlNInv43bdD1xDIIV3qaNCvg84uNIqakOLeZnOuDla6VV8l 1piChlIAukUH5BO8XLG3vjd7C8MCStrtt7uJBfUmGAqo+dcA6DxueHssJmlQxd8YZrrr qktiCwGO53aEqDZPL+djm7ZxAjALIA4/oWZ10kvmp+5jtYFnzm31+4eSrYx3SzplE4mb 3yTg== X-Gm-Message-State: AOAM532EGLZfKdZAHmrzH+6nLOV4M89UijFX3L1JaW8oZ++6Ij6BNNcT 3e15/S1bTV4oyjRFqrUcz9O89g== X-Received: by 2002:a05:6830:3115:: with SMTP id b21mr5266488ots.291.1622176569502; Thu, 27 May 2021 21:36:09 -0700 (PDT) Received: from builder.lan (104-57-184-186.lightspeed.austtx.sbcglobal.net. [104.57.184.186]) by smtp.gmail.com with ESMTPSA id x9sm876748ooo.27.2021.05.27.21.36.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 May 2021 21:36:09 -0700 (PDT) Date: Thu, 27 May 2021 23:36:07 -0500 From: Bjorn Andersson To: Suman Anna Cc: Mathieu Poirier , Lokesh Vutla , Tero Kristo , linux-remoteproc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 6/6] remoteproc: k3-dsp: Add support for IPC-only mode for all K3 DSPs Message-ID: References: <20210522000309.26134-1-s-anna@ti.com> <20210522000309.26134-7-s-anna@ti.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210522000309.26134-7-s-anna@ti.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri 21 May 19:03 CDT 2021, Suman Anna wrote: > Add support to the K3 DSP remoteproc driver to configure all the C66x > and C71x cores on J721E SoCs to be either in IPC-only mode or the > traditional remoteproc mode. The IPC-only mode expects that the remote > processors are already booted by the bootloader, and only perform the > minimum steps required to initialize and deinitialize the virtio IPC > transports. The remoteproc mode allows the kernel remoteproc driver to > do the regular load and boot and other device management operations for > a DSP. > > The IPC-only mode for a DSP is detected and configured at driver probe > time by querying the System Firmware for the DSP power and reset state > and/or status and making sure that the DSP is indeed started by the > bootloaders, otherwise the device is configured for remoteproc mode. > > Support for IPC-only mode is achieved through .attach(), .detach() and > .get_loaded_rsc_table() callback ops and various other flags in both > remoteproc core and the K3 DSP remoteproc driver. The resource table > follows a design-by-contract approach and is expected to be at the base > of the DDR firmware region reserved for each remoteproc, it is mostly > expected to contain only the virtio device and trace resource entries. > > NOTE: > The driver cannot configure a DSP core for remoteproc mode by any > means without rebooting the kernel if that R5F core has been started > by a bootloader. > > Signed-off-by: Suman Anna > --- > drivers/remoteproc/ti_k3_dsp_remoteproc.c | 151 ++++++++++++++++++++-- > 1 file changed, 138 insertions(+), 13 deletions(-) > > diff --git a/drivers/remoteproc/ti_k3_dsp_remoteproc.c b/drivers/remoteproc/ti_k3_dsp_remoteproc.c > index faf60a274e8d..b154a52f1fa6 100644 > --- a/drivers/remoteproc/ti_k3_dsp_remoteproc.c > +++ b/drivers/remoteproc/ti_k3_dsp_remoteproc.c > @@ -76,6 +76,7 @@ struct k3_dsp_dev_data { > * @ti_sci_id: TI-SCI device identifier > * @mbox: mailbox channel handle > * @client: mailbox client to request the mailbox channel > + * @ipc_only: flag to indicate IPC-only mode > */ > struct k3_dsp_rproc { > struct device *dev; > @@ -91,6 +92,7 @@ struct k3_dsp_rproc { > u32 ti_sci_id; > struct mbox_chan *mbox; > struct mbox_client client; > + bool ipc_only; > }; > > /** > @@ -268,6 +270,10 @@ static int k3_dsp_rproc_prepare(struct rproc *rproc) > struct device *dev = kproc->dev; > int ret; > > + /* IPC-only mode does not require the core to be released from reset */ > + if (kproc->ipc_only) Rather than saying "prepare shouldn't do anything", how about not actually providing prepare/unprepare ops when ipc_only? > + return 0; > + > ret = kproc->ti_sci->ops.dev_ops.get_device(kproc->ti_sci, > kproc->ti_sci_id); > if (ret) > @@ -292,6 +298,10 @@ static int k3_dsp_rproc_unprepare(struct rproc *rproc) > struct device *dev = kproc->dev; > int ret; > > + /* do not put back the cores into reset in IPC-only mode */ > + if (kproc->ipc_only) > + return 0; > + > ret = kproc->ti_sci->ops.dev_ops.put_device(kproc->ti_sci, > kproc->ti_sci_id); > if (ret) > @@ -314,6 +324,12 @@ static int k3_dsp_rproc_start(struct rproc *rproc) > u32 boot_addr; > int ret; > > + if (kproc->ipc_only) { It doesn't seem to make sense to start a remoteproc in ipc_only mode, so how about not registering the start ops? > + dev_err(dev, "%s cannot be invoked in IPC-only mode\n", > + __func__); > + return -EINVAL; > + } > + > ret = k3_dsp_rproc_request_mbox(rproc); > if (ret) > return ret; > @@ -351,6 +367,13 @@ static int k3_dsp_rproc_start(struct rproc *rproc) > static int k3_dsp_rproc_stop(struct rproc *rproc) > { > struct k3_dsp_rproc *kproc = rproc->priv; > + struct device *dev = kproc->dev; > + > + if (kproc->ipc_only) { > + dev_err(dev, "%s cannot be invoked in IPC-only mode\n", > + __func__); > + return -EINVAL; > + } > > mbox_free_channel(kproc->mbox); > > @@ -359,6 +382,85 @@ static int k3_dsp_rproc_stop(struct rproc *rproc) > return 0; > } > > +/* > + * Attach to a running DSP remote processor (IPC-only mode) > + * > + * This rproc attach callback only needs to request the mailbox, the remote > + * processor is already booted, so there is no need to issue any TI-SCI > + * commands to boot the DSP core. > + */ > +static int k3_dsp_rproc_attach(struct rproc *rproc) > +{ > + struct k3_dsp_rproc *kproc = rproc->priv; > + struct device *dev = kproc->dev; > + int ret; > + > + if (!kproc->ipc_only || rproc->state != RPROC_DETACHED) { As attach only makes sense when ipc_only, how about not specifying the attach ops when !ipc_only? > + dev_err(dev, "DSP is expected to be in IPC-only mode and RPROC_DETACHED state\n"); > + return -EINVAL; > + } > + > + ret = k3_dsp_rproc_request_mbox(rproc); > + if (ret) > + return ret; > + > + dev_err(dev, "DSP initialized in IPC-only mode\n"); > + return 0; > +} > + > +/* > + * Detach from a running DSP remote processor (IPC-only mode) > + * > + * This rproc detach callback performs the opposite operation to attach callback > + * and only needs to release the mailbox, the DSP core is not stopped and will > + * be left to continue to run its booted firmware. > + */ > +static int k3_dsp_rproc_detach(struct rproc *rproc) > +{ > + struct k3_dsp_rproc *kproc = rproc->priv; > + struct device *dev = kproc->dev; > + > + if (!kproc->ipc_only || rproc->state != RPROC_ATTACHED) { Ditto. > + dev_err(dev, "DSP is expected to be in IPC-only mode and RPROC_ATTACHED state\n"); > + return -EINVAL; > + } > + > + mbox_free_channel(kproc->mbox); > + dev_err(dev, "DSP deinitialized in IPC-only mode\n"); > + return 0; > +} > + > +/* > + * This function implements the .get_loaded_rsc_table() callback and is used > + * to provide the resource table for a booted DSP in IPC-only mode. The K3 DSP > + * firmwares follow a design-by-contract approach and are expected to have the > + * resource table at the base of the DDR region reserved for firmware usage. > + * This provides flexibility for the remote processor to be booted by different > + * bootloaders that may or may not have the ability to publish the resource table > + * address and size through a DT property. > + */ > +static struct resource_table *k3_dsp_get_loaded_rsc_table(struct rproc *rproc, > + size_t *rsc_table_sz) > +{ > + struct k3_dsp_rproc *kproc = rproc->priv; > + struct device *dev = kproc->dev; > + > + if (!kproc->rmem[0].cpu_addr) { > + dev_err(dev, "memory-region #1 does not exist, loaded rsc table can't be found"); > + return ERR_PTR(-ENOMEM); > + } > + > + /* > + * NOTE: The resource table size is currently hard-coded to a maximum > + * of 256 bytes. The most common resource table usage for K3 firmwares > + * is to only have the vdev resource entry and an optional trace entry. > + * The exact size could be computed based on resource table address, but > + * the hard-coded value suffices to support the IPC-only mode. > + */ > + *rsc_table_sz = 256; Why can't you use kproc->rmem[0].size here? > + return (struct resource_table *)kproc->rmem[0].cpu_addr; > +} > + > /* > * Custom function to translate a DSP device address (internal RAMs only) to a > * kernel virtual address. The DSPs can access their RAMs at either an internal > @@ -421,8 +523,11 @@ static void *k3_dsp_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool > static const struct rproc_ops k3_dsp_rproc_ops = { So in essence, I suggest that you create a separate k3_dsp_ipc_only_ops. > .start = k3_dsp_rproc_start, > .stop = k3_dsp_rproc_stop, > + .attach = k3_dsp_rproc_attach, > + .detach = k3_dsp_rproc_detach, > .kick = k3_dsp_rproc_kick, > .da_to_va = k3_dsp_rproc_da_to_va, > + .get_loaded_rsc_table = k3_dsp_get_loaded_rsc_table, > }; > > static int k3_dsp_rproc_of_get_memories(struct platform_device *pdev, > @@ -605,6 +710,8 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev) > struct k3_dsp_rproc *kproc; > struct rproc *rproc; > const char *fw_name; > + bool r_state = false; > + bool p_state = false; > int ret = 0; > int ret1; > > @@ -683,19 +790,37 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev) > goto release_tsp; > } > > - /* > - * ensure the DSP local reset is asserted to ensure the DSP doesn't > - * execute bogus code in .prepare() when the module reset is released. > - */ > - if (data->uses_lreset) { > - ret = reset_control_status(kproc->reset); > - if (ret < 0) { > - dev_err(dev, "failed to get reset status, status = %d\n", > - ret); > - goto release_mem; > - } else if (ret == 0) { > - dev_warn(dev, "local reset is deasserted for device\n"); > - k3_dsp_rproc_reset(kproc); > + ret = kproc->ti_sci->ops.dev_ops.is_on(kproc->ti_sci, kproc->ti_sci_id, > + &r_state, &p_state); You can pass NULL instead of &r_state, as you don't use it anyways. > + if (ret) { > + dev_err(dev, "failed to get initial state, mode cannot be determined, ret = %d\n", > + ret); > + goto release_mem; > + } > + > + /* configure J721E devices for either remoteproc or IPC-only mode */ > + if (p_state) { > + dev_err(dev, "configured DSP for IPC-only mode\n"); This sounds like a good thing, so perhaps dev_info() rather than err? > + rproc->state = RPROC_DETACHED; > + rproc->detach_on_shutdown = true; > + kproc->ipc_only = true; > + } else { > + dev_err(dev, "configured DSP for remoteproc mode\n"); Ditto Regards, Bjorn > + /* > + * ensure the DSP local reset is asserted to ensure the DSP > + * doesn't execute bogus code in .prepare() when the module > + * reset is released. > + */ > + if (data->uses_lreset) { > + ret = reset_control_status(kproc->reset); > + if (ret < 0) { > + dev_err(dev, "failed to get reset status, status = %d\n", > + ret); > + goto release_mem; > + } else if (ret == 0) { > + dev_warn(dev, "local reset is deasserted for device\n"); > + k3_dsp_rproc_reset(kproc); > + } > } > } > > -- > 2.30.1 >