From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E8E2BC4332F for ; Fri, 24 Sep 2021 02:51:05 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 71C3B61090 for ; Fri, 24 Sep 2021 02:51:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 71C3B61090 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2F6138342D; Fri, 24 Sep 2021 04:51:03 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="jqxE4FCf"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id F236583394; Fri, 24 Sep 2021 04:50:09 +0200 (CEST) Received: from mail-vs1-xe36.google.com (mail-vs1-xe36.google.com [IPv6:2607:f8b0:4864:20::e36]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id EB44B8344C for ; Fri, 24 Sep 2021 04:49:39 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@google.com Received: by mail-vs1-xe36.google.com with SMTP id az15so8581976vsb.8 for ; Thu, 23 Sep 2021 19:49:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=KeLACWakBdPEqEYsBr/O7F4zHaRPk0YwIf8ueKAkBic=; b=jqxE4FCf9cum+QfcH4fSrgXlm9SOJNWY6bJVokyeuJtyCFCz+LvnHum9xKFpTkUSvV 0RKStBAOUHgLfhPPssZX1/xQFjg93V7eSjyFtz7ZOw3LVEgkQP/liqdpp6k7yYTRLk0Z uDHyz5gaa53Mgo2gKdZRIryc6qpqr4Gp5BRX8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=KeLACWakBdPEqEYsBr/O7F4zHaRPk0YwIf8ueKAkBic=; b=BpDFQ+a2YJWsl5aR8MaE0Njq7q7tDvtk9j02Vh628XjHlawpN5fAwTEOj4trj3fj0a FlUlsBDYfMZ7PH6cy5N6TrXpfn0C4Y/Bp2Ag5avhDTa9RAdLFF+LtYJpUQjcovzFAdTo fgT1/IdYNBOgL4O51mNzWE3OX/j2rPVMgO6VETcUKWduUhlVqmKQqK3kdmKUffhziTbo Mg7+VIMQpSZOYV6GbOwSd41mHll09zeUdXrFhi88TyKuFRHXQcTG2EcNHcesv74LePWc RzZYUICyzEY1vagCTFH0i4oTtCSRqBiIDg8m/E+sxb25Y6BrZa2iMEasGR0eJocgLuDx HNjg== X-Gm-Message-State: AOAM533RDKe6WE0swmocXZwjKZZ6RcSqIG/DG/JAcQIt/jbwuMilU4tB WeQgS4YNoGhm8NfmuBU7eG/0bio/SwnDA7KnaTgYEQ== X-Google-Smtp-Source: ABdhPJxX28xoOyzj2p9BrbsYxIWlBMc5ji5gGSYakdysURINp5PD2UsMa+aQbCh1i6WnBI2wLUNz0/Fszx1sXcDA5Qw= X-Received: by 2002:a05:6102:3a59:: with SMTP id c25mr7437603vsu.15.1632451778330; Thu, 23 Sep 2021 19:49:38 -0700 (PDT) MIME-Version: 1.0 References: <20210923164649.214770-1-aouledameur@baylibre.com> <20210923164649.214770-6-aouledameur@baylibre.com> In-Reply-To: <20210923164649.214770-6-aouledameur@baylibre.com> From: Simon Glass Date: Thu, 23 Sep 2021 20:49:27 -0600 Message-ID: Subject: Re: [PATCH 05/10] remoteproc: uclass: Add remoteproc resource handling helpers To: Amjad Ouled-Ameur Cc: U-Boot Mailing List , Keerthy , Andy Shevchenko , Patrick Delaunay , Pratyush Yadav , Sean Anderson Content-Type: text/plain; charset="UTF-8" X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean Hi Amjad, On Thu, 23 Sept 2021 at 10:47, Amjad Ouled-Ameur wrote: > > From: Keerthy > > Add remoteproc resource handling helpers. These functions > are primarily to parse the resource table and to handle > different types of resources. Carveout, devmem, trace & > vring resources are handled. > > Signed-off-by: Keerthy > [Amjad: fix redefinition of "struct resource_table" and compile warnings ] > Signed-off-by: Amjad Ouled-Ameur > --- > > drivers/remoteproc/rproc-uclass.c | 562 ++++++++++++++++++++++++++++++ > include/remoteproc.h | 384 +++++++++++++++++++- > 2 files changed, 945 insertions(+), 1 deletion(-) > > diff --git a/drivers/remoteproc/rproc-uclass.c b/drivers/remoteproc/rproc-uclass.c > index 64c47c1e7225..3f7096045548 100644 > --- a/drivers/remoteproc/rproc-uclass.c > +++ b/drivers/remoteproc/rproc-uclass.c > @@ -8,6 +8,7 @@ > > #define pr_fmt(fmt) "%s: " fmt, __func__ > #include > +#include > #include > #include > #include > @@ -19,9 +20,21 @@ > #include > #include > #include > +#include > > DECLARE_GLOBAL_DATA_PTR; > > +struct resource_table { > + u32 ver; > + u32 num; > + u32 reserved[2]; > + u32 offset[0]; > +} __packed; > + > +typedef int (*handle_resource_t) (struct udevice *, void *, int offset, int avail); > + > +static struct resource_table *rsc_table; > + > /** > * for_each_remoteproc_device() - iterate through the list of rproc devices > * @fn: check function to call per match, if this function returns fail, > @@ -208,6 +221,86 @@ static int rproc_post_probe(struct udevice *dev) > return 0; > } > > +/** > + * rproc_add_res() - After parsing the resource table add the mappings > + * @dev: device we finished probing > + * @mapping: rproc_mem_entry for the resource > + * > + * Return: if the remote proc driver has a add_res routine, invokes it and > + * hands over the return value. overall, 0 if all went well, else appropriate > + * error value. > + */ > +static int rproc_add_res(struct udevice *dev, struct rproc_mem_entry *mapping) > +{ > + const struct dm_rproc_ops *ops; > + > + ops = rproc_get_ops(dev); > + if (!ops) { > + debug("%s driver has no ops?\n", dev->name); > + return -EINVAL; > + } Please don't check this as it just bloats the code. The ops must be provided. Please fix throughout. > + > + if (ops->add_res) > + return ops->add_res(dev, mapping); Don't you want to return -ENOSYS if there is no method here? > + > + return 0; > +} > + > +/** > + * rproc_alloc_mem() - After parsing the resource table allocat mem > + * @dev: device we finished probing > + * @len: rproc_mem_entry for the resource > + * @align: alignment for the resource > + * > + * Return: if the remote proc driver has a add_res routine, invokes it and > + * hands over the return value. overall, 0 if all went well, else appropriate > + * error value. > + */ > +static void *rproc_alloc_mem(struct udevice *dev, unsigned long len, > + unsigned long align) > +{ > + const struct dm_rproc_ops *ops; > + > + ops = rproc_get_ops(dev); > + if (!ops) { > + debug("%s driver has no ops?\n", dev->name); > + return NULL; > + } > + > + if (ops->alloc_mem) > + return ops->alloc_mem(dev, len, align); > + > + return NULL; > +} > + > +/** > + * rproc_config_pagetable() - Configure page table for remote processor > + * @dev: device we finished probing > + * @virt: Virtual address of the resource > + * @phys: Physical address the resource > + * @len: length the resource > + * > + * Return: if the remote proc driver has a add_res routine, invokes it and > + * hands over the return value. overall, 0 if all went well, else appropriate > + * error value. > + */ > +static int rproc_config_pagetable(struct udevice *dev, unsigned int virt, > + unsigned int phys, unsigned int len) > +{ > + const struct dm_rproc_ops *ops; > + > + ops = rproc_get_ops(dev); > + if (!ops) { > + debug("%s driver has no ops?\n", dev->name); > + return -EINVAL; > + } > + > + if (ops->config_pagetable) > + return ops->config_pagetable(dev, virt, phys, len); > + > + return 0; > +} > + > UCLASS_DRIVER(rproc) = { > .id = UCLASS_REMOTEPROC, > .name = "remoteproc", > @@ -438,3 +531,472 @@ int rproc_is_running(int id) > { > return _rproc_ops_wrapper(id, RPROC_RUNNING); > }; > + > +/* > + * Virtio ring descriptors: 16 bytes. These can chain together via > + * "next". What is this code doing in the uclass: > + */ > +struct vring_desc { > + u64 addr; > + u32 len; > + u16 flags; > + u16 next; > +}; > + > +/* > + * u32 is used here for ids for padding reasons. > + */ > +struct vring_used_elem { > + u32 id; > + u32 len; > +}; > + > +static unsigned int vring_size(unsigned int num, unsigned long align) > +{ > + return ((sizeof(struct vring_desc) * num + sizeof(u16) * (3 + num) > + + align - 1) & ~(align - 1)) > + + sizeof(u16) * 3 + sizeof(struct vring_used_elem) * num; > +} > + [..] Regards, Simon