From patchwork Tue Jul 25 14:06:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tanmay Shah X-Patchwork-Id: 1812716 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=BbqqzWLI; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4R9Lrc3Y6kz1yYc for ; Wed, 26 Jul 2023 01:42:40 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 93205867E2; Tue, 25 Jul 2023 17:41:45 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=amd.com 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=amd.com header.i=@amd.com header.b="BbqqzWLI"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id AC02C8637D; Tue, 25 Jul 2023 16:08:21 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam02on20613.outbound.protection.outlook.com [IPv6:2a01:111:f400:7eb2::613]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 2FED286682 for ; Tue, 25 Jul 2023 16:08:13 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=tanmay.shah@amd.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=i71H/IUyizOAMkwwFBxg/IJmz+vMGr76a+KntI8GOESDpRE0dgPhfI73qcv0TiXH6sZptReTWxsFKNnayPzOlRvYbSKeotHtXHXJn+znMoESfCHme4bALfSZT/2Y65cscjKcLQhJF21vqpIr7VcJSP56MOu5EhF21laX9JkZQa4MG28F2fJggCZAK8hbwYZopCBTRDv5BA/CUcOpzMRRoaNguUmaqvBsuJ1y3HPaN34EMmikL1MTrAfGPl0TahWCzkn314hm4LPWiMQIb9x/KldTZ5GSqPFTEFU1FsFEuo4vrEUZ8l62PyNOXlvEELffUTjrcVeYfc4kvIss5Bhd+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=9vFgsSguaxdNQVCWCzLhWlUD71n/QTIlY33zyCPNC+w=; b=RTJJB9PUGBV/4Z3v8g2Gki/lCxaluLrFRSksFe5c6k2Mk6yXk01+hTQjWQ2wLKSntG3IgGagrl9AQ0/uiGVth1cs7rNmemdCaEvswibbeOsyalyasDCvzFigRRVc866YrlG3W3lRpEm+TCvFHYZ8Pjbz6z+xIyY9xVK03AXRhmNgHD8k8v92e9Gp0q7Yp5WRtq9HEEuIrfjgvjMQuTu2FHoQr3co625DjgVcIbErn4a0BsVvlhlNREFIrLTSBgvy4op1U8tyndswcNvhSNHwrXG1zA90onqxf/js8TNVWSeRxABovZqIxawNUn8lBdk53Z1jwqPtr3C/7r8Q++O2nw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=chromium.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9vFgsSguaxdNQVCWCzLhWlUD71n/QTIlY33zyCPNC+w=; b=BbqqzWLIJXVF8Jf7cMXMSLasJ2G78Lfzy26TmPG8K/+SrrdfGwsLRt+cJAn41satYGsjidL0VoikNfyesthM4g+KK5F5y7DnyqpKEW8lqdWPjA50qZH7bPMbV2r8vaHHBD9kb6mgYuCZkLNHuTC1X+BWHFmDapmG9qdHtOKmROg= Received: from DS7PR05CA0064.namprd05.prod.outlook.com (2603:10b6:8:57::26) by MW4PR12MB5644.namprd12.prod.outlook.com (2603:10b6:303:189::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.33; Tue, 25 Jul 2023 14:08:08 +0000 Received: from DM6NAM11FT082.eop-nam11.prod.protection.outlook.com (2603:10b6:8:57:cafe::a7) by DS7PR05CA0064.outlook.office365.com (2603:10b6:8:57::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.25 via Frontend Transport; Tue, 25 Jul 2023 14:08:08 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT082.mail.protection.outlook.com (10.13.173.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6631.29 via Frontend Transport; Tue, 25 Jul 2023 14:08:08 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 25 Jul 2023 09:08:06 -0500 Received: from xsjtanmays50.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Tue, 25 Jul 2023 09:08:05 -0500 From: Tanmay Shah To: Simon Glass , Tom Rini CC: , , , Michal Simek , Venkatesh Abbarapu , Mathieu Poirier , Nishanth Menon , Tanmay Shah Subject: [RFC PATCH 07/10] remoteproc: add attach/detach commands Date: Tue, 25 Jul 2023 07:06:47 -0700 Message-ID: <20230725140650.951581-8-tanmay.shah@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230725140650.951581-1-tanmay.shah@amd.com> References: <20230725140650.951581-1-tanmay.shah@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT082:EE_|MW4PR12MB5644:EE_ X-MS-Office365-Filtering-Correlation-Id: 3cd30e50-eba2-4c08-1c98-08db8d1892db X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bTfHT0jpT7KMzzaR+9abxLFGw1A4H9XlxWDYdQrXLz1RVaYvt5ScEp2bajNPzQGAWOdk5TiYhrNRZPLnSh3K61wbJn7ijmxhVT7DdMD8LNhiKoMCE0aY9RDkaWFka/Sf2IVtI4XZldFrn1PWQojzXv1B5rIHwdVIUN2eKPmHAXsCb90SmjYzOH6tR6ZQRISWYq6luLsfE68fxa2//H4U4tN6Xc6tfPqgaz+ZP6GF50tkye0YDr5H8i5IkmmwVwaLQ709Qao8901fXHdIRPSGPLwaVAWg4vdu+oGwZga7mEBRvotmYyD8EK7w0PF/gv7ghbCk4tRxM6IPMX6elT9ppbCwfgMuoQ4aKg0biiB5JqAoaj+aqvtzGccTb41HQm4dJ1AO6EGbfP6j9H02EFES/l455WBwzs1CeTM4eaQJcBEN4iikE/DDTFuI85gRWcrt57FB1BwSJii3wTVYs6ld/dZJJsHbiLKV2a0+kj7Q0T3BGzd4XurOHrsYEfcH3PGcK/ozASjYFuTauo8gP5OCBFk8SDY1f6iEsEX+WfsVq/8dcdhpRe2KhoXfwwEAwfHjDja8y1l2QWrOnefUBI4xmJXJfzrPVq7Zw5qeQoR4kNNrD7wKRW8oIdow8bT75/TJjpWe0caPl9gjLBtLESuF3ZQ5fgq4qahUQviucc8YwPKyCVrpMLzzyUqCSTMWYoVqnbW+C/J5A7LT58B3eTS6Rcux9MjNR9KxXHHkgRUb+u2sAxLmaB0fCK4Q6lCBK5+8+O3dvco0ETAYhiYwSeNrTA== X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230028)(4636009)(376002)(39860400002)(136003)(396003)(346002)(82310400008)(451199021)(46966006)(40470700004)(36840700001)(54906003)(70206006)(70586007)(426003)(2616005)(47076005)(36756003)(83380400001)(36860700001)(40480700001)(86362001)(82740400003)(356005)(81166007)(478600001)(110136005)(336012)(26005)(186003)(1076003)(40460700003)(6666004)(41300700001)(5660300002)(2906002)(316002)(4326008)(8936002)(8676002)(44832011)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jul 2023 14:08:08.4840 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3cd30e50-eba2-4c08-1c98-08db8d1892db X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT082.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB5644 X-Mailman-Approved-At: Tue, 25 Jul 2023 17:40:30 +0200 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.8 at phobos.denx.de X-Virus-Status: Clean Current remoteproc framework provides commands to start/stop remote processor. However, If remote processor is already running before U-Boot then there is no way to connect to remote processor. Implements attach/detach commands to connect to already running remote processor. During attach operation, remoteproc framework gets resource table from remote processor using platform specific callback and then creates vdev devices and other resources accordingly. This approach is derived from the Linux kernel remoteproc framework. kernel version: 6.4-rc2 (d848a4819d85) file: drivers/remoteproc/remoteproc_core Signed-off-by: Tanmay Shah --- cmd/remoteproc.c | 14 +++++- drivers/remoteproc/rproc-uclass.c | 76 ++++++++++++++++++++++++++++++- include/remoteproc.h | 31 +++++++++++++ 3 files changed, 119 insertions(+), 2 deletions(-) diff --git a/cmd/remoteproc.c b/cmd/remoteproc.c index ca3b436242..200a233114 100644 --- a/cmd/remoteproc.c +++ b/cmd/remoteproc.c @@ -173,6 +173,10 @@ static int do_remoteproc_wrapper(struct cmd_tbl *cmdtp, int flag, int argc, ret = rproc_start(id); } else if (!strcmp(argv[0], "stop")) { ret = rproc_stop(id); + } else if (!strcmp(argv[0], "attach")) { + ret = rproc_attach(id); + } else if (!strcmp(argv[0], "detach")) { + ret = rproc_detach(id); } else if (!strcmp(argv[0], "reset")) { ret = rproc_reset(id); } else if (!strcmp(argv[0], "is_running")) { @@ -220,6 +224,12 @@ static struct cmd_tbl cmd_remoteproc_sub[] = { U_BOOT_CMD_MKENT(stop, 1, 1, do_remoteproc_wrapper, "Stop remote processor", "id - ID of the remote processor (see 'list' cmd)\n"), + U_BOOT_CMD_MKENT(attach, 1, 1, do_remoteproc_wrapper, + "Attach remote processor", + "id - ID of the remote processor (see 'list' cmd)\n"), + U_BOOT_CMD_MKENT(detach, 1, 1, do_remoteproc_wrapper, + "detach remote processor", + "id - ID of the remote processor (see 'list' cmd)\n"), U_BOOT_CMD_MKENT(reset, 1, 1, do_remoteproc_wrapper, "Reset remote processor", "id - ID of the remote processor (see 'list' cmd)\n"), @@ -262,7 +272,7 @@ static int do_remoteproc(struct cmd_tbl *cmdtp, int flag, int argc, U_BOOT_CMD(rproc, 5, 1, do_remoteproc, "Control operation of remote processors in an SoC", - " [init|list|load|start|stop|reset|is_running|ping]\n" + " [attach|detach|init|list|load|start|stop|reset|is_running|ping]\n" "\t\t Where:\n" "\t\t[addr] is a memory address\n" "\t\t is a numerical identifier for the remote processor\n" @@ -271,6 +281,8 @@ U_BOOT_CMD(rproc, 5, 1, do_remoteproc, "\t\tNote: Services are dependent on the driver capability\n" "\t\t 'list' command shows the capability of each device\n" "\n\tSubcommands:\n" + "\tattach - attach to already running remote processor\n" + "\tdetach - unbind driver with already attached device\n" "\tinit - Enumerate and initalize the remote processor.\n" "\t if id is not passed, initialize all the remote prcessors\n" "\tlist - list available remote processors\n" diff --git a/drivers/remoteproc/rproc-uclass.c b/drivers/remoteproc/rproc-uclass.c index 3aebaf6187..31d2e70a0c 100644 --- a/drivers/remoteproc/rproc-uclass.c +++ b/drivers/remoteproc/rproc-uclass.c @@ -170,7 +170,7 @@ static int rproc_pre_probe(struct udevice *dev) return -EINVAL; } - if (!ops->load || !ops->start) { + if ((!ops->load || !ops->start) && !ops->attach) { debug("%s driver has missing mandatory ops?\n", dev->name); return -EINVAL; } @@ -438,6 +438,8 @@ enum rproc_ops { RPROC_RESET, RPROC_PING, RPROC_RUNNING, + RPROC_ATTACH, + RPROC_DETACH, }; /** @@ -497,6 +499,14 @@ static int _rproc_ops_wrapper(int id, enum rproc_ops op) fn = ops->ping; op_str = "Pinging"; break; + case RPROC_ATTACH: + fn = ops->attach; + op_str = "Attaching"; + break; + case RPROC_DETACH: + fn = ops->detach; + op_str = "Detaching"; + break; default: debug("what is '%d' operation??\n", op); return -EINVAL; @@ -538,6 +548,15 @@ int rproc_is_running(int id) return _rproc_ops_wrapper(id, RPROC_RUNNING); }; +int rproc_attach(int id) +{ + return _rproc_ops_wrapper(id, RPROC_ATTACH); +}; + +int rproc_detach(int id) +{ + return _rproc_ops_wrapper(id, RPROC_DETACH); +}; static int handle_trace(struct udevice *dev, struct fw_rsc_trace *rsc, int offset, int avail) @@ -993,3 +1012,58 @@ unsigned long rproc_parse_resource_table(struct udevice *dev, struct rproc *cfg) return 1; } + +unsigned long rproc_attach_resource_table(struct udevice *dev) +{ + struct dm_rproc_ops *ops = rproc_get_ops(dev); + struct resource_table *ptable; + int tablesz = 0, ret; + struct rproc *rproc; + + if (!ops->get_loaded_rsc_table) { + debug("get loaded rsctable op not supported\n"); + return -ENOSYS; + } + + ptable = (struct resource_table *)ops->get_loaded_rsc_table(dev, &tablesz); + if (!ptable) { + debug("can't get loaded resource table\n"); + return -EINVAL; + } + + rproc = rproc_get_cfg(dev); + if (!rproc) { + debug("remoteproc configurations not available\n"); + return -EINVAL; + } + + rproc->table_ptr = ptable; + + rsc_table = kzalloc(tablesz, GFP_KERNEL); + if (!rsc_table) + return -ENOMEM; + + /* + * Copy the resource table into a local buffer before handling the + * resource table. + */ + memcpy(rsc_table, ptable, tablesz); + + ret = handle_resources(dev, tablesz, loading_handlers); + if (ret) { + debug("handle_resources failed: %d\n", ret); + return 0; + } + + /* + * Instead of trying to mimic the kernel flow of copying the + * processed resource table into its post ELF load location in DDR + * copying it into its original location. + */ + memcpy(ptable, rsc_table, tablesz); + + free(rsc_table); + rsc_table = NULL; + + return 0; +} diff --git a/include/remoteproc.h b/include/remoteproc.h index 4251af52bd..8b7be05435 100644 --- a/include/remoteproc.h +++ b/include/remoteproc.h @@ -498,6 +498,22 @@ struct dm_rproc_ops { */ int (*stop)(struct udevice *dev); + /** + * attach() - Attach the remoteproc device (optional) + * + * @dev: Remote proc device + * @return 0 if all ok, else appropriate error value. + */ + int (*attach)(struct udevice *dev); + + /** + * detach() - Detach the remoteproc device (optional) + * + * @dev: Remote proc device + * @return 0 if all ok, else appropriate error value. + */ + int (*detach)(struct udevice *dev); + /** * reset() - Reset the remoteproc device (optional) * @@ -600,6 +616,19 @@ int rproc_start(int id); */ int rproc_stop(int id); +/** + * rproc_attach() - Attach a remote processor + * @id: id of the remote processor + * Return: 0 if all ok, else appropriate error value. + */ +int rproc_attach(int id); + +/** + * rproc_detach() - Detach a remote processor + * @id: id of the remote processor + * Return: 0 if all ok, else appropriate error value. + */ +int rproc_detach(int id); /** * rproc_reset() - reset a remote processor * @id: id of the remote processor @@ -752,6 +781,8 @@ int rproc_elf_load_rsc_table(struct udevice *dev, ulong fw_addr, unsigned long rproc_parse_resource_table(struct udevice *dev, struct rproc *cfg); +unsigned long rproc_attach_resource_table(struct udevice *dev); + struct resource_table *rproc_find_resource_table(struct udevice *dev, unsigned int addr, int *tablesz);