Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1370619pxb; Thu, 28 Jan 2021 15:00:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJxbqv/p8mbWuUfZG6zSO8b2MC8AoSaSQIAXgmlMJjz9iB8w4gIm6vFlc9uApSsr6mo/dyK0 X-Received: by 2002:a17:906:c9d8:: with SMTP id hk24mr1790487ejb.468.1611874804704; Thu, 28 Jan 2021 15:00:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611874804; cv=none; d=google.com; s=arc-20160816; b=QCTQ50190ioy/O070iL/Y/ZCmR2K5lEW0hE8V06q54Yom3+k8SoRVclCvLLl+b0qsP WSwaD6mz6YY3/3434LVi5xHWE4idbDo/M6+m5TkJ5GwFLsQ4vk88/4kLdJSaQlSoNpNK DG9Ue27qjDQDzF3JeVb18aAJuE2Ke791qi7inOQP5De1OmaR3W6WyKAWJQKrz3UUULym Sb07D3C+m6UCCU+3dcQ6clKvXUzq/0N8MzF+F8rSPExNMivaFR+Vkagd0So/55nlE/TD aMHXtWx9hV/6B+Q+f0Xd/RzMd42TtzgBbvl6PThzFNdybZ+VsFE5FtZ6cqXWaMvYwugU 5/MQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:references:cc :to:from:subject:dkim-signature; bh=jonMZv526fvLfzZM6MKHRBQrNWc4O0SRB31532W4+KU=; b=kdlTvvpvIttxf7yTaK5QrGQxdq0wT/2e923usk5h/hPok+U5dbHtdmsZ2HgoBcN5wE hpqCzwJJ7TuwPyCji816Bj2YVJ2c4UCbd1D/BnxVEc7sKULoWvGpOBB5E7B0XZ+RGIk+ epT3e/AIQDGPN9l56jzHBfADKDK+47j241qizkLcuFd7lMeodmKuKIJ7lL1Ka48IOnYt M+jwgmQ+0ncojDuzsrpsllr8NDCpEaXG4Knt2owYadI5xPpNiH9lZ5f9Fpzsf7a3/8M+ OV2iWFzgtGYKFggAnFnYIXXIyn4JEij6LBH75yP0eDGUjZcztaM0EmCAq7hN2ac4E4M3 H8mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=xUhqGDFT; 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=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m26si4504777edp.591.2021.01.28.14.59.39; Thu, 28 Jan 2021 15:00:04 -0800 (PST) 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=@ti.com header.s=ti-com-17Q1 header.b=xUhqGDFT; 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=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231509AbhA1W6G (ORCPT + 99 others); Thu, 28 Jan 2021 17:58:06 -0500 Received: from fllv0016.ext.ti.com ([198.47.19.142]:53084 "EHLO fllv0016.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231646AbhA1W5f (ORCPT ); Thu, 28 Jan 2021 17:57:35 -0500 Received: from lelv0266.itg.ti.com ([10.180.67.225]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 10SMt95U097208; Thu, 28 Jan 2021 16:55:09 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1611874510; bh=jonMZv526fvLfzZM6MKHRBQrNWc4O0SRB31532W4+KU=; h=Subject:From:To:CC:References:Date:In-Reply-To; b=xUhqGDFTyCN3lfJIhQ+XBxnZZ2SrDFbAvF5aHn2SW7RO6f+2d/qXXFR6z12fqGNLM N+uwpJ7etWS13zGb0aqCvS18Vzq0PZUe6+5baqHU9vIqwz3DvVzleAOnaExKgav1ax 5be3EmHpe0st499SsQwLKO/qru3ZttPh1WA2Dhs4= Received: from DFLE102.ent.ti.com (dfle102.ent.ti.com [10.64.6.23]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 10SMt9j5015626 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 28 Jan 2021 16:55:09 -0600 Received: from DFLE111.ent.ti.com (10.64.6.32) by DFLE102.ent.ti.com (10.64.6.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3; Thu, 28 Jan 2021 16:55:09 -0600 Received: from fllv0040.itg.ti.com (10.64.41.20) by DFLE111.ent.ti.com (10.64.6.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3 via Frontend Transport; Thu, 28 Jan 2021 16:55:09 -0600 Received: from [10.250.35.71] (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0040.itg.ti.com (8.15.2/8.15.2) with ESMTP id 10SMt9KI010966; Thu, 28 Jan 2021 16:55:09 -0600 Subject: Re: [PATCH] remoteproc: pru: future-proof PRU ID matching From: Suman Anna To: David Lechner , CC: Ohad Ben-Cohen , Bjorn Andersson , Grzegorz Jaszczyk , References: <20210104211816.420602-1-david@lechnology.com> Message-ID: Date: Thu, 28 Jan 2021 16:55:04 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi David, On 1/15/21 6:53 PM, Suman Anna wrote: > On 1/4/21 3:18 PM, David Lechner wrote: >> Currently, to determine the ID (0 or 1) of a PRU core, the last 19 bits >> of the physical address of the cores IRAM are compared to known values. >> However, the PRUs on TI AM18XX have IRAM at 0x01c38000 and 0x01c3c000 >> respectively. The former conflicts with PRU1_IRAM_ADDR_MASK which could >> cause PRU0 to be detected as PRU1. (The latter also conflicts with >> TX_PRU1_IRAM_ADDR_MASK but it would still be correctly detected as >> PRU1.) >> >> This fixes the problem by moving the address matching offset values to >> the device-specific data. This way the compatible string does half of >> the work of narrowing down the addresses to two possibilities instead >> of checking the address against all possible PRU types. This also lets >> us narrow down the scope of the match from 19 bits to 16 bits for all >> PRU types. >> >> After this, the TI AM18XX PRUs will be able to be added without running >> into the problems stated above. >> >> We can also drop the local ret variable while touching this code. >> >> Signed-off-by: David Lechner > > Will test this patch on Mon/Tue on various platforms. > > Bjorn, > Please wait for my Ack on this before you pick this up. > > regards > Suman > >> --- >> drivers/remoteproc/pru_rproc.c | 49 ++++++++++++++-------------------- >> 1 file changed, 20 insertions(+), 29 deletions(-) >> >> diff --git a/drivers/remoteproc/pru_rproc.c b/drivers/remoteproc/pru_rproc.c >> index 2667919d76b3..94ce48df2f48 100644 >> --- a/drivers/remoteproc/pru_rproc.c >> +++ b/drivers/remoteproc/pru_rproc.c >> @@ -46,15 +46,6 @@ >> #define PRU_DEBUG_GPREG(x) (0x0000 + (x) * 4) >> #define PRU_DEBUG_CT_REG(x) (0x0080 + (x) * 4) >> >> -/* PRU/RTU/Tx_PRU Core IRAM address masks */ >> -#define PRU_IRAM_ADDR_MASK 0x3ffff >> -#define PRU0_IRAM_ADDR_MASK 0x34000 >> -#define PRU1_IRAM_ADDR_MASK 0x38000 >> -#define RTU0_IRAM_ADDR_MASK 0x4000 >> -#define RTU1_IRAM_ADDR_MASK 0x6000 >> -#define TX_PRU0_IRAM_ADDR_MASK 0xa000 >> -#define TX_PRU1_IRAM_ADDR_MASK 0xc000 >> - >> /* PRU device addresses for various type of PRU RAMs */ >> #define PRU_IRAM_DA 0 /* Instruction RAM */ >> #define PRU_PDRAM_DA 0 /* Primary Data RAM */ >> @@ -96,10 +87,14 @@ enum pru_type { >> /** >> * struct pru_private_data - device data for a PRU core >> * @type: type of the PRU core (PRU, RTU, Tx_PRU) >> + * @pru0_iram_offset: used to identify PRU core 0 >> + * @pru1_iram_offset: used to identify PRU core 1 >> * @is_k3: flag used to identify the need for special load handling >> */ >> struct pru_private_data { >> enum pru_type type; >> + u16 pru0_iram_offset; >> + u16 pru1_iram_offset; >> unsigned int is_k3 : 1; >> }; >> >> @@ -693,33 +688,21 @@ static int pru_rproc_parse_fw(struct rproc *rproc, const struct firmware *fw) >> } >> >> /* >> - * Compute PRU id based on the IRAM addresses. The PRU IRAMs are >> + * Compute PRU id based on the last 16 bits of IRAM addresses. The PRU IRAMs are >> * always at a particular offset within the PRUSS address space. >> */ >> static int pru_rproc_set_id(struct pru_rproc *pru) >> { >> - int ret = 0; >> - >> - switch (pru->mem_regions[PRU_IOMEM_IRAM].pa & PRU_IRAM_ADDR_MASK) { >> - case TX_PRU0_IRAM_ADDR_MASK: >> - fallthrough; >> - case RTU0_IRAM_ADDR_MASK: >> - fallthrough; >> - case PRU0_IRAM_ADDR_MASK: >> + u16 offset = pru->mem_regions[PRU_IOMEM_IRAM].pa; >> + >> + if (offset == pru->data->pru0_iram_offset) >> pru->id = 0; >> - break; >> - case TX_PRU1_IRAM_ADDR_MASK: >> - fallthrough; >> - case RTU1_IRAM_ADDR_MASK: >> - fallthrough; >> - case PRU1_IRAM_ADDR_MASK: >> + else if (offset == pru->data->pru1_iram_offset) >> pru->id = 1; >> - break; >> - default: >> - ret = -EINVAL; >> - } >> + else >> + return -EINVAL; >> >> - return ret; >> + return 0; While this logic does work, it is a bit convoluted IMO for any one reading the code. The offset here is kind of a misnomer, this logic is relying on only the least 16-bits of the address. I have actually used a different logic in our downstream code, and we chose the current approach to minimize the static data. https://git.ti.com/gitweb?p=rpmsg/remoteproc.git;a=blob;f=drivers/remoteproc/pru_rproc.c;h=cbcd8a6e420e61d60218a01ea0e76f0c9989a337;hb=refs/heads/rproc-linux-5.4.y#l1135 >> } >> >> static int pru_rproc_probe(struct platform_device *pdev) >> @@ -825,20 +808,28 @@ static int pru_rproc_remove(struct platform_device *pdev) >> >> static const struct pru_private_data pru_data = { >> .type = PRU_TYPE_PRU, >> + .pru0_iram_offset = 0x4000, >> + .pru1_iram_offset = 0x8000, The offsets for the PRU cores are actually 0x34000 and 0x38000 respectively from the base of the PRUSS on non-Davinci SoCs. If we were to use this static data approach, then we might as well continue to use the current address masking logic with the appropriate masks for Davinci (0x38000 and 0x3C000, not true offsets but as masks they would work). Davinci PRUSS is the only one with its differences being the first PRUSS IP, and I would prefer to keep the logic aligned to the IPs on all the recent SoCs on 3 different TI SoC families (OMAP, Keystone 2 and K3). Let me know what you think. regards Suman >> }; >> >> static const struct pru_private_data k3_pru_data = { >> .type = PRU_TYPE_PRU, >> + .pru0_iram_offset = 0x4000, >> + .pru1_iram_offset = 0x8000, >> .is_k3 = 1, >> }; >> >> static const struct pru_private_data k3_rtu_data = { >> .type = PRU_TYPE_RTU, >> + .pru0_iram_offset = 0x4000, >> + .pru1_iram_offset = 0x6000, >> .is_k3 = 1, >> }; >> >> static const struct pru_private_data k3_tx_pru_data = { >> .type = PRU_TYPE_TX_PRU, >> + .pru0_iram_offset = 0xa000, >> + .pru1_iram_offset = 0xc000, >> .is_k3 = 1, >> }; >> >> >