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 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2E5AAC2BA18 for ; Thu, 20 Jun 2024 21:29:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=1B8n/9x5UV/1SNK0e2sD4WDigveg5fhKDxICWDMhEd8=; b=3RJAttDdexwqKHBlYkJIJJESxI rOjPawVJjPD5BOt7Fci8eDYk0iSxWvbMLlh/nrKIxR3+Dkl+DMHgclEbIYtyITF74pMvN2nWbkusY +zK+LJTpQ6CGRnMdJS/FkjCvN17iuHdICXU0QCuZFAjcnsmmgzL7u9/m2UXBbuWpTkleUKvqiv6Hf N0jBkvnqqr5Kc75Ck/0I3P+cGhBYxFoLHXPQ2pxM8ERR35I5UN+gvXHD6jz9kA/qLl0hUWYqE6kGF /M/FfuGQABsYBqkj7mmVwbich1nvP1MpSDJB+TU2BoTaYFsPTB9Ttj6pGvP3dA6giJLCKtphd+EdY tVT7c5Pg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKPLB-00000006mjK-0HMi; Thu, 20 Jun 2024 21:29:09 +0000 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKPL6-00000006mfC-1qBO for linux-arm-kernel@lists.infradead.org; Thu, 20 Jun 2024 21:29:06 +0000 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1f9e5fb4845so307385ad.0 for ; Thu, 20 Jun 2024 14:29:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1718918942; x=1719523742; darn=lists.infradead.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=1B8n/9x5UV/1SNK0e2sD4WDigveg5fhKDxICWDMhEd8=; b=V2UECWKkJbeefkjcvn1J7flVz/ytXsKt5gnPlpelcKHch04xsG7D6tKlphjiFq0kAw YVaMpPu2NLqMD2ltA12Bi3h5KZIiyrdTmW2e92mnsVpyIQ9HarHR+6Cb1x6iB9oOn6H7 xW9AoX6OMFU0z8r9fkc3llsFDD0nraE/+u3X8uNCeuWpJIxoddu5xsZK/PKgL6wQS1Wn ldRfsKZsPmJrzjBz/Ie5hrsQvDuRMoTKxYiGq/MYLE8J1lb6wydeT5Jqn1cgbi2rPBXB 4hbzBg5FbGVv84US/xOrOOERsjGeMLBl1V5VbHm+YJvhfGhEgptXt8Gr1a9ALGGBYo6L uOvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718918942; x=1719523742; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=1B8n/9x5UV/1SNK0e2sD4WDigveg5fhKDxICWDMhEd8=; b=KFuZrbeWepSBvhhH9FaRPSgSMoWUHKjNl9xkfQwtMAJ1tGOaBPX8RxabRGe0jWPGjc BjS+aMr6cz59VFIo5SiF1wyTOfd659WgMgLOfyYSj15JHsLdAlb1S3EHfbB5GQi5Ig0f hlvGIzR16VRNwAhchAyDMK7SZeXjy1rX9Jv7k50ZMjjT9Oyt2r9IOXGlIKhAX16TGq0e xgtqOIrwSAo608Kyy1UZXsAF+gQouOBmmzQ0ExEnkI1DyqZJapMQcx70vbhiLnYOSYnJ uNgUgCaKlEN4c+cejEbFPTTF/hQqg+vHlkyU0Zo1p5rZJRJ5iJX5E8uW/gUBUzJo1ioY udzg== X-Forwarded-Encrypted: i=1; AJvYcCWGcytpcMP05crH8jyQQNmzTsaQ7uQUVZ/uPAGTkwnyKlDQGLODiQypJ4UUv6UVM2T9ca/4AyFbo71ajzlYJVzrfluBLGg/Nvwk7SmsAPEgR8UPuR8= X-Gm-Message-State: AOJu0YyDtIs2dpObVctiQ/T+NV7QXiwUqmFcjoMYZKVn+E4OG8yZm90M BCIFP/ILnTeT2r85Zq6gZGpEJjBMU9j9g4IQel5VlQjuLIEdZrYPaDDN8CUnGxg= X-Google-Smtp-Source: AGHT+IGRZRV15RUYJQ36Wvbuz7tQOaEP3gRrX62dbm+NaihBOC+cfum9DmWH761VwwydaedMpum6CQ== X-Received: by 2002:a17:902:daca:b0:1f8:66fb:1679 with SMTP id d9443c01a7336-1f9a9274fb1mr93302075ad.30.1718918942421; Thu, 20 Jun 2024 14:29:02 -0700 (PDT) Received: from p14s ([2604:3d09:148c:c800::9eba]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f9ebbbc1cbsm698255ad.282.2024.06.20.14.29.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 14:29:01 -0700 (PDT) Date: Thu, 20 Jun 2024 15:28:58 -0600 From: Mathieu Poirier To: Arnaud Pouliquen Cc: Bjorn Andersson , Jens Wiklander , Rob Herring , Krzysztof Kozlowski , Conor Dooley , linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, op-tee@lists.trustedfirmware.org, devicetree@vger.kernel.org Subject: Re: [PATCH v7 1/5] remoteproc: core: Introduce rproc_pa_to_va helper Message-ID: References: <20240611073904.475019-1-arnaud.pouliquen@foss.st.com> <20240611073904.475019-2-arnaud.pouliquen@foss.st.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240611073904.475019-2-arnaud.pouliquen@foss.st.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240620_142904_843838_F3434C3F X-CRM114-Status: GOOD ( 38.22 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, Jun 11, 2024 at 09:39:00AM +0200, Arnaud Pouliquen wrote: > When a resource table is loaded by an external entity such as U-boot or > OP-TEE, we do not necessary get the device address(da) but the physical s/necessary/necessarily > address(pa). > This helper performs similar translation than the rproc_da_to_va() > but based on a physical address. > > Signed-off-by: Arnaud Pouliquen > --- > drivers/remoteproc/remoteproc_core.c | 74 +++++++++++++++++++++++++++- > include/linux/remoteproc.h | 3 ++ > 2 files changed, 75 insertions(+), 2 deletions(-) > > diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c > index f276956f2c5c..3fdec0336fd6 100644 > --- a/drivers/remoteproc/remoteproc_core.c > +++ b/drivers/remoteproc/remoteproc_core.c > @@ -230,6 +230,77 @@ void *rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool *is_iomem) > } > EXPORT_SYMBOL(rproc_da_to_va); > > +/** > + * rproc_pa_to_va() - lookup the kernel virtual address for a physical address of a remoteproc > + * memory > + * > + * @rproc: handle of a remote processor > + * @pa: remoteproc physical address > + * @len: length of the memory region @pa is pointing to > + * @is_iomem: optional pointer filled in to indicate if @da is iomapped memory > + * > + * Some remote processors will ask us to allocate them physically contiguous > + * memory regions (which we call "carveouts"), and map them to specific > + * device addresses (which are hardcoded in the firmware). They may also have > + * dedicated memory regions internal to the processors, and use them either > + * exclusively or alongside carveouts. > + * > + * They may then ask us to copy objects into specific addresses (e.g. > + * code/data sections) or expose us certain symbols in other device address > + * (e.g. their trace buffer). > + * > + * This function is a helper function with which we can go over the allocated > + * carveouts and translate specific physical addresses to kernel virtual addresses > + * so we can access the referenced memory. This function also allows to perform > + * translations on the internal remoteproc memory regions through a platform > + * implementation specific pa_to_va ops, if present. > + * > + * Note: phys_to_virt(iommu_iova_to_phys(rproc->domain, da)) will work too, > + * but only on kernel direct mapped RAM memory. Instead, we're just using > + * here the output of the DMA API for the carveouts, which should be more > + * correct. No point in copying all this. Just say that it does the same thing as rproc_da_to_va(), but with the PA address. > + * > + * Return: a valid kernel address on success or NULL on failure > + */ > +void *rproc_pa_to_va(struct rproc *rproc, phys_addr_t pa, size_t len, bool *is_iomem) > +{ > + struct rproc_mem_entry *carveout; > + void *ptr = NULL; > + > + if (rproc->ops->da_to_va) { This is really wrong. > + ptr = rproc->ops->pa_to_va(rproc, pa, len); > + if (ptr) > + goto out; > + } There is no current customer for ops::pa_to_va() so please remove. Thanks, Mathieu > + > + list_for_each_entry(carveout, &rproc->carveouts, node) { > + int offset = pa - carveout->dma; > + > + /* Verify that carveout is allocated */ > + if (!carveout->va) > + continue; > + > + /* try next carveout if da is too small */ > + if (offset < 0) > + continue; > + > + /* try next carveout if da is too large */ > + if (offset + len > carveout->len) > + continue; > + > + ptr = carveout->va + offset; > + > + if (is_iomem) > + *is_iomem = carveout->is_iomem; > + > + break; > + } > + > +out: > + return ptr; > +} > +EXPORT_SYMBOL(rproc_pa_to_va); > + > /** > * rproc_find_carveout_by_name() - lookup the carveout region by a name > * @rproc: handle of a remote processor > @@ -724,8 +795,7 @@ static int rproc_alloc_carveout(struct rproc *rproc, > * firmware was compiled with. > * > * In this case, we must use the IOMMU API directly and map > - * the memory to the device address as expected by the remote > - * processor. > + * the memory to the device address as etable > * > * Obviously such remote processor devices should not be configured > * to use the iommu-based DMA API: we expect 'dma' to contain the > diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h > index b4795698d8c2..28aa62a3b505 100644 > --- a/include/linux/remoteproc.h > +++ b/include/linux/remoteproc.h > @@ -367,6 +367,7 @@ enum rsc_handling_status { > * @detach: detach from a device, leaving it powered up > * @kick: kick a virtqueue (virtqueue id given as a parameter) > * @da_to_va: optional platform hook to perform address translations > + * @pa_to_va: optional platform hook to perform address translations > * @parse_fw: parse firmware to extract information (e.g. resource table) > * @handle_rsc: optional platform hook to handle vendor resources. Should return > * RSC_HANDLED if resource was handled, RSC_IGNORED if not handled > @@ -391,6 +392,7 @@ struct rproc_ops { > int (*detach)(struct rproc *rproc); > void (*kick)(struct rproc *rproc, int vqid); > void * (*da_to_va)(struct rproc *rproc, u64 da, size_t len, bool *is_iomem); > + void * (*pa_to_va)(struct rproc *rproc, phys_addr_t da, size_t len); > int (*parse_fw)(struct rproc *rproc, const struct firmware *fw); > int (*handle_rsc)(struct rproc *rproc, u32 rsc_type, void *rsc, > int offset, int avail); > @@ -690,6 +692,7 @@ int rproc_detach(struct rproc *rproc); > int rproc_set_firmware(struct rproc *rproc, const char *fw_name); > void rproc_report_crash(struct rproc *rproc, enum rproc_crash_type type); > void *rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool *is_iomem); > +void *rproc_pa_to_va(struct rproc *rproc, phys_addr_t pa, size_t len, bool *is_iomem); > > /* from remoteproc_coredump.c */ > void rproc_coredump_cleanup(struct rproc *rproc); > -- > 2.25.1 >