From patchwork Fri Feb 14 14:00:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 865095 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:1568:b0:38f:210b:807b with SMTP id 8csp169245wrz; Fri, 14 Feb 2025 06:01:04 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWCo+aOXooDq7QVcZWxi100v19u4Rndzb2IQ5/yG7s46IfuCqYL3OiSvntWg8vOUHWhUdGiBw==@linaro.org X-Google-Smtp-Source: AGHT+IE2wXHjEYKkUv3RDPcxoMXBuvBEldy2Rm1X/AOOP0+cvPFp4lVGuhKLQbgIcDnCDhJfW8Lv X-Received: by 2002:a05:600c:c8c:b0:439:4499:54de with SMTP id 5b1f17b1804b1-439601afaf0mr104964225e9.31.1739541663989; Fri, 14 Feb 2025 06:01:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1739541663; cv=none; d=google.com; s=arc-20240605; b=i2ZvZPHp/GZta/UT5iHahfWnVZ45r1vHisAoPjEixB6g5I0hZ0rBQPm+06yPC5DnVt 6aE/ReZWvpOIicBKzER3om2bYYYO94UvoI3E7bIj/d5ORLlCoo9tZUXLcgbxoeXrLJYC 4lV4GjVdilVmN00bm+QB2GYrEqp/+S9jplGNmzSqhESN9o0Ybz5mqq6kFAe5LXbnnc+1 yUs+Oan99KpEJSSnoAafEkY8c4vsL9Pr96i5bkZiF82Q1g8IeapVJQgF+GQ/C0f7GDHE 925FKqWSCv1hQQpl1y9ffkTh7ACf9oF5wASPbc+xctArUoswiwId4JnYcmVjgZ3WxMcj Cutw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=pJ/WOo4fTLMKMXvV7x5SKkbdsCeYlarnyOLSSxr3gnM=; fh=P5shqnZkgEpyixYF9GD1hH2/X8D3w3mrpJ0uSB5lpbk=; b=iP0qw6t0OL0+XVazqyprQgWuI7a/Zeq3P7R1/Tww02nUR8ZUs1jqeERiuLAdVdYqdK 3StC4rGs/Nl0UX9faMvZB+xW61zyLv/d5VVu3k1S5X7AqUrTPqa0X1B5eUgCfglZ3I9a jkKqdPYHKQbncmP9G6XAvkSRlomPwnUZYyPsrJdvwPgMb7JnnplwCHxrGcQafc6VVsqJ l897muwHDTqPp2tA7Nl/ahn+bptw4RjKRMBCF8kfj846PDoI0P7h9AIPCgVl1BlT8R1I aMVgJcQZkpgjEbsSVhOYbX236S0ubEgwt7thjWM+4psmZZvCKn34JBsqtzP2VJWjdeyb SdQA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QD7BGyyn; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id 5b1f17b1804b1-43959d49c18si62576265e9.55.2025.02.14.06.01.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Feb 2025 06:01:03 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QD7BGyyn; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 678E680B98; Fri, 14 Feb 2025 15:01:02 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="QD7BGyyn"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B4C6B80EAF; Fri, 14 Feb 2025 15:01:00 +0100 (CET) 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,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) (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 9368A80756 for ; Fri, 14 Feb 2025 15:00:58 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-43690d4605dso13744295e9.0 for ; Fri, 14 Feb 2025 06:00:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1739541658; x=1740146458; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=pJ/WOo4fTLMKMXvV7x5SKkbdsCeYlarnyOLSSxr3gnM=; b=QD7BGyynAUcYKovHDQ5QZyWCCM2bMrVjbXgvQBxbB/mXJvxMr+Cx6FK63Mz1/Hu5Zz StnRLy1InPzjFGEO4rn3wuHMQrkjfgW1cxfWJf0ATsNx5YjUqhHICghvmFMyPa50j9S6 +znX5MVgB6HqPjmClqmPyD5Vle51hXgveSqJm2vFayCNo45TgLCTi+qKROe2+7P6Ivkm pGNlX8h19LLPuMKiQ55YqSe6Zm5qiuz6uK1GCvT8gQEFPeKfg7XLCm2M3VKJ7vjtzgGG klRTmK3kfvK9kZj69Bai0t7SSIxXcVUsBTF2qzzfn6XiMTB9THo3a/NhnZdZYHjNv2TO Jz/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739541658; x=1740146458; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pJ/WOo4fTLMKMXvV7x5SKkbdsCeYlarnyOLSSxr3gnM=; b=b10GyyRo7grc5I8sGb+f6/2cVpngtTXzaGEpVUycwTZ0YR/vVtDD67XqkahF1hCykc H+6Rd17nPAZuu/aaeXOJQq/hF456kyhQ6g011D25hTjknb4TZKo4CaMK7jhNXakiLQio LS2zhpu6N3RCJKF6iw2vMD3awoaqpwaH/ETDAjRo91pzzHMkxFCJRUPMCZGwNHQFqaU0 Q1F14AJ4mcL7Kdg5M8d3f9xWSzHPQSHN0Xc1D+IhXyy9gBk/fXImPN/sVLTVumI6w7zk DlDHaKhunFaFtYd++QEUGr1Fiow8ytdp8hfD7+q8ysr7Y3MbJWOfpaNC4pkP1xOxP61d FU8A== X-Gm-Message-State: AOJu0Yy/xKRoz/P/UtY9pvDaQpv4fi+DuLA5qd+3udBAwnqElLXaw7qD Htxpy8VfTxOXxCqEQgqWZEd8lL6rwZQAmpWX5o2CPPVm5hN7UOGWk8TXZd5LmlIOT7kb9subTLP fUXvKPg== X-Gm-Gg: ASbGnctwYdoLIItYWz/qRD+QH1zbmQpeYVoczqFHsCGNWF6IdkXmDbizvhpNrNR4Gqd bqr+9UTJSE2+126ATEPVHN6+X9/bBFV9suBF9m5sGn5QfaMxF8SjefoTBE6JMnzrgbSKySy+eBF xRKQqLxiD5RQGhdFyREdsY+I6EXxOdyCgjOlLDobsdMAWrZZABSMxW7s53k5qhmh3jL00J8bCvY aIjsuVfIqLxasBS980ApdE/yrMIp1SSbZMeKDueFYe18qa+AsU3xDctvTR/NUXFB1x8VCfxN7QH LyLj/HsGpJj1ipitp77N3IPd X-Received: by 2002:a05:600c:548e:b0:439:5aa1:1efa with SMTP id 5b1f17b1804b1-439601a119bmr96458835e9.22.1739541657624; Fri, 14 Feb 2025 06:00:57 -0800 (PST) Received: from builder.. ([2a01:e0a:3cb:7bb0:65ac:d875:2c3e:607f]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38f258fc7e0sm4666391f8f.48.2025.02.14.06.00.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Feb 2025 06:00:57 -0800 (PST) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Tom Rini , Simon Glass , Heinrich Schuchardt , Dan Carpenter , Andrew Goodbody , Yu-Chien Peter Lin , Jiaxun Yang Subject: [RFC PATCH 01/10] arch: introduce symbol HAVE_INITJMP Date: Fri, 14 Feb 2025 15:00:16 +0100 Message-ID: <20250214140031.484344-2-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250214140031.484344-1-jerome.forissier@linaro.org> References: <20250214140031.484344-1-jerome.forissier@linaro.org> MIME-Version: 1.0 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 HAVE_INIJMP will be set by architectures that support initjmp(), a non-standard extension to setjmp()/longjmp() allowing to initialize a jump buffer with a function pointer and a stack pointer. This will be useful to later introduce threads. Signed-off-by: Jerome Forissier --- arch/Kconfig | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/Kconfig b/arch/Kconfig index 35b19f9bfdc..8d5b54031b3 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -13,6 +13,12 @@ config HAVE_SETJMP help The architecture supports setjmp() and longjmp(). +config HAVE_INITJMP + bool + help + The architecture supports initjmp(), a non-standard companion to + setjmp() and longjmp(). + config SUPPORT_BIG_ENDIAN bool From patchwork Fri Feb 14 14:00:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 865097 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:1568:b0:38f:210b:807b with SMTP id 8csp169521wrz; Fri, 14 Feb 2025 06:01:29 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCU0eZiMPiIdaPgSTy3iiscevghzFw0uypuvgVgb/x86rjmx4PwAx3H0VqdhDd5S4/rc1eKNbA==@linaro.org X-Google-Smtp-Source: AGHT+IFbhMErqa8xIGlkLep1vcmluQg4VM5GqT76ANk5Brk8hPdDNAG4AVY2rX5MnUmkx9Tkbn2S X-Received: by 2002:a05:6000:1fac:b0:38c:5da8:5f88 with SMTP id ffacd0b85a97d-38f24f9d072mr8784907f8f.28.1739541688435; Fri, 14 Feb 2025 06:01:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1739541688; cv=none; d=google.com; s=arc-20240605; b=I33s2xj8QuzMPD6Z8KWa95AxXQZvszq7NQR19NPm1bu2Wt5l8zmDtQSma5MgCp6w0c SyArft7AwA7jTvto/i/Ri/ZGIT3c0rWrrxepADz0iIsdMDXqJy/b1e88WbOM+tyXvUSn uGa9f02DI6ZSh0vscWdCgkzGP6AUdj8X8XNyvgjVDE/2MqweNsa8jKiO+9JtmDtjxNEu 92kxHQYZovoXZ5hQfK0wkUzK7OwhkcNGXkeig39NqnnZymwBrmwCtXPLpKaOanTQ2tXQ Nez1OMoGMifWGQxpW79D3uCMd0Lijke47TfoplAsUrXYdJccSx5+C9mtHn+sFZSQpLd8 LOzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=UCu7qj8HR3Py0+iZlP/oCbK1XsWURJ6VtwUuKp1Xrk8=; fh=FhTR/HYFjVJm5nKG6DJlJyLy4qB8PFMCIJrjVwIuP/o=; b=R21dgLKEhhoKtStfghPDRR160cMa79ueiQTjNgBCOcZ9fE9H1HFmNCba7wBX754eUZ 8I4CtB7qmBr0tAJP5ISZMrgXHWQYGB3WCQJ2Ph+gsRdFyBlBzjar0WS3C5bdOrStjxyO 3SZI9qEvY06KGBVBIYKhdyw0CXJM46+cp1u8fFcSUeH3rfzuI3zQakwWIxq6L5TMuhrl 8b2u53BwakE0Rf3C+BQX5fz1gJ0j06HFqpepsKUYb3vjk1s0YZoU8Ba2rpsYRUJ3WozS 4mZpbz/+cBEKsXgiG8WbFbDOo5pGSjyOmiLh5cmtTQfAutRxtAlefdbpyUs2K96bNiyd 3lrw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Tb1C+31+; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id ffacd0b85a97d-38f258e1024si4455767f8f.96.2025.02.14.06.01.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Feb 2025 06:01:28 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Tb1C+31+; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4D59180EC1; Fri, 14 Feb 2025 15:01:04 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="Tb1C+31+"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C22F080EB5; Fri, 14 Feb 2025 15:01:02 +0100 (CET) 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,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) (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 8E25380C96 for ; Fri, 14 Feb 2025 15:00:59 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-38f2c4382d1so473121f8f.0 for ; Fri, 14 Feb 2025 06:00:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1739541659; x=1740146459; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UCu7qj8HR3Py0+iZlP/oCbK1XsWURJ6VtwUuKp1Xrk8=; b=Tb1C+31+OurP1EhwUn6n6yF1pwloUF66LCqIT57iNSG3K2XLpNN+ijps7PQC3h/djh aOutKwsH5UQZhkAuqXCSipfV+c16YzenZhLDKDrsorYizElcjyiXl2kFh5VH/FWFGDBB pskav4vPkLTk+djvTww48T1CYYQXkjay0rozdUkdx85ljuF0CKPfs93HNW/5cOat1tKf z9lo+le323IXxWyo04P9S894ImXITC4g8dHu0yHIzxJPh9reRcx7jJyWcHCHnP+UUuVF FFuMoal2EjqBrc6536jZVldgltqJNug0vdwVZ7KRgxLP2rJfHhJxwkEVTKBRSYrr9dou PHyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739541659; x=1740146459; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UCu7qj8HR3Py0+iZlP/oCbK1XsWURJ6VtwUuKp1Xrk8=; b=ifM/v0CUfOnNn9kp72r26o6aT3QGaVFBAQ4SBHxLSL47w8V8t9+eDdT6oWId1kHc85 zl7AI1fPYwJvucbmFg5O2YnGEiGKEYwsFJRiqWd4Z0SCMsK1YDNoxTZQrpEJrchhbBX+ tdhKLBecwyB+l1LZ8XyvaIwjIGnayeKqRV9gtsx3hZb2I2ZQ021uiYHkcw+Ls0PE8Lc+ aOzgJyRqX2n3KqrjYsIB9TQSZ0TFWGKCSZoptWIVqIuXAjllUwyzi/Duj46yURXhmS7K J7sHwy/sFN3N9uduoWb0gw0dQi8eyOQvElilrkeXR67ZauG8n6mx58duZlUfyplf9B3n GyZw== X-Gm-Message-State: AOJu0YxtrelHwNqYBauGR8a/xMqsPXyQGO5RVQO9B+7JElkQxDUevTZC h61hrFUoD4x7gC2iQnEfN2ema5/rc4wm7w2Lb9c9HCt4j/fTgMNEjoHHaNTZfR2jYRcNWueFguH 7Z9rx+A== X-Gm-Gg: ASbGncvcyb/dL1rXoFD/pSYJaTJ1oAeIttZ6FgmS/ZcguKCIkviRMHEL+ajkFlHmKMc ngf+GYWe0qRdLuVTj9VBHvqTyN59EHBqnPwd4SMK86YSNrHgvQMr+vBm29ObZfoBzvP7xKhPURx adpXu8id25cecEV3nFMZsCD+Iu3HiLlI3HDrKQhUi8oYaOizu4GAXmgRVHCTOERT7ZoMVNJ9fSq 0RwZsj1MkzevhIo2Uge77IdXGavpVyrnSpYtmdbCjMn7mgLamgE4uNg9zSMnl6rbsx1KlCOjFob HLsh7nWKi3/Z0SXEQz+AXlGy X-Received: by 2002:a05:6000:4024:b0:38d:d8f7:8f75 with SMTP id ffacd0b85a97d-38f24d74d98mr8650343f8f.17.1739541658682; Fri, 14 Feb 2025 06:00:58 -0800 (PST) Received: from builder.. ([2a01:e0a:3cb:7bb0:65ac:d875:2c3e:607f]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38f258fc7e0sm4666391f8f.48.2025.02.14.06.00.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Feb 2025 06:00:58 -0800 (PST) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Tom Rini , Dan Carpenter , Simon Glass , Heinrich Schuchardt , Jiaxun Yang , Yu-Chien Peter Lin , Andrew Goodbody Subject: [RFC PATCH 02/10] arm: add initjmp() Date: Fri, 14 Feb 2025 15:00:17 +0100 Message-ID: <20250214140031.484344-3-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250214140031.484344-1-jerome.forissier@linaro.org> References: <20250214140031.484344-1-jerome.forissier@linaro.org> MIME-Version: 1.0 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 Implement initjmp() for Arm. Signed-off-by: Jerome Forissier --- arch/Kconfig | 1 + arch/arm/include/asm/setjmp.h | 1 + arch/arm/lib/setjmp.S | 11 +++++++++++ arch/arm/lib/setjmp_aarch64.S | 9 +++++++++ 4 files changed, 22 insertions(+) diff --git a/arch/Kconfig b/arch/Kconfig index 8d5b54031b3..57695fada8d 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -94,6 +94,7 @@ config ARC config ARM bool "ARM architecture" select HAVE_SETJMP + select HAVE_INITJMP select ARCH_SUPPORTS_LTO select CREATE_ARCH_SYMLINK select HAVE_PRIVATE_LIBGCC if !ARM64 diff --git a/arch/arm/include/asm/setjmp.h b/arch/arm/include/asm/setjmp.h index 662bec86321..1ad5b500f2a 100644 --- a/arch/arm/include/asm/setjmp.h +++ b/arch/arm/include/asm/setjmp.h @@ -23,5 +23,6 @@ typedef struct jmp_buf_data jmp_buf[1]; int setjmp(jmp_buf jmp); void longjmp(jmp_buf jmp, int ret); +int initjmp(jmp_buf jmp, void __noreturn (*func)(void), void *stack_top); #endif /* _SETJMP_H_ */ diff --git a/arch/arm/lib/setjmp.S b/arch/arm/lib/setjmp.S index 2f041aeef01..320ddea85f9 100644 --- a/arch/arm/lib/setjmp.S +++ b/arch/arm/lib/setjmp.S @@ -34,3 +34,14 @@ ENTRY(longjmp) ret lr ENDPROC(longjmp) .popsection + +.pushsection .text.initjmp, "ax" +ENTRY(initjmp) + stm a1, {v1-v8} + /* a2: entry point address, a3: stack top */ + str a3, [a1, #32] /* where setjmp would save sp */ + str a2, [a1, #36] /* where setjmp would save lr */ + mov a1, #0 + ret lr +ENDPROC(initjmp) +.popsection diff --git a/arch/arm/lib/setjmp_aarch64.S b/arch/arm/lib/setjmp_aarch64.S index 1b8d000eb48..074320d25fb 100644 --- a/arch/arm/lib/setjmp_aarch64.S +++ b/arch/arm/lib/setjmp_aarch64.S @@ -39,3 +39,12 @@ ENTRY(longjmp) ret ENDPROC(longjmp) .popsection + +.pushsection .text.initjmp, "ax" +ENTRY(initjmp) + /* x1: entry point address, x2: stack top */ + stp x1, x2, [x0,#88] + mov x0, #0 + ret +ENDPROC(initjmp) +.popsection From patchwork Fri Feb 14 14:00:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 865098 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:1568:b0:38f:210b:807b with SMTP id 8csp169619wrz; Fri, 14 Feb 2025 06:01:35 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCU22WPyDf9KdKgaHv1ELodAQFlOtnzyxEZ+4n45uzLSfnUa3luRRWU52zfMlRxwdwvuIHJwxQ==@linaro.org X-Google-Smtp-Source: AGHT+IGbluniCdOl0KBipXKkJa3WhVpH2y3Tw7IIEkLBn9en+EgRMncdkkRGAcbwA9/t6PgFnXDK X-Received: by 2002:a5d:5f93:0:b0:385:d7f9:f157 with SMTP id ffacd0b85a97d-38f2451820emr10720228f8f.36.1739541694993; Fri, 14 Feb 2025 06:01:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1739541694; cv=none; d=google.com; s=arc-20240605; b=RAabSBPdBfrhird2PYKPPdkQK0ihQsFv7VjexX6lhprCP4fqkEpQVvewOviRhrudvr XT5trzN8OklXhiV/cr3tjH9aF9Kket7V9dZ5i200MWYuVLF39cHOPW4nm3j/YdwP3vFy WTjxGkVUK2epEWucQGBA8D10GN5V3FaSg5HKAJYG4nkBZKQdcvahwLCS6iDbVGvjEbAi k1iKv08S5a3zkrrSmBKmCJ+z+mB2L04omhhpkIMTn9AVbGmDDMkfXKJUx/E4F1ihP+hk /W5fiI4XwKJClSXMkNA3j54qD6AfJ9ocQIVEOHIpJRpbcnCos9fvycsMNL4DhvWwPAM4 a1fA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=FNw2IjE2pzkh8kOG8gbCKeyHG7nPC9wPKaPR6juqTg0=; fh=LyRrfH6tkLxJI8wGoUGiWzEgg9hAMxKG0hULJNbv3lU=; b=EZXa9qSMu0xa6aG2HbcIcOP8ZSyK1pwhb32M7sdfDU4HkF3ZL3CU8HMvQPhxhk/sb9 aTptg0hJDSqrSvi3pDx4sr9t/u/6HaTb19ZUNQoG1ltI2KB1rgWlrnk4rMNUctw+jzZr +q5mMil6LGzpgEBORr49KNW92EbLYl+PEpHi+m/gIrowWKcM2RdgnHlhopOmGU8vIG1O p/T7enaRT3wkYlclZuRpoeqoQOo2IcGPRyoqn9TAxIKgcw4Rqa4lZAwN0QKgcn815h3i PTZiA2fiJVCmcWL1Sx1IM8zs4ZShJ4OMXGLRdGL1GznEYltZLRZ2mdnWpenukAZUM+no dUug==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bu7F8xSb; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id ffacd0b85a97d-38f25a4404asi4482875f8f.864.2025.02.14.06.01.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Feb 2025 06:01:34 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bu7F8xSb; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9F7C080EEF; Fri, 14 Feb 2025 15:01:04 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="bu7F8xSb"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 685B080EB7; Fri, 14 Feb 2025 15:01:03 +0100 (CET) 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,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) (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 99E5180E88 for ; Fri, 14 Feb 2025 15:01:00 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-38f22fe889aso1569903f8f.3 for ; Fri, 14 Feb 2025 06:01:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1739541660; x=1740146460; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FNw2IjE2pzkh8kOG8gbCKeyHG7nPC9wPKaPR6juqTg0=; b=bu7F8xSbbNDDGK6VWfTM1D6wiLYHY2kpAoLtNuMz3KDY1reyx+BNDdnsa9DkEBmYYp ir+Pb4IovjWDzkZYqmzI4/a0mNYMs7Nb3swHaCQgnuofgTICSYfNJa5gjskVTLF67Fo9 RnO71LPKmRWcLMj6YZUbuikRJ3GwQNC+sEhxLSPw2m98iJSWAhLLpd7C7/jxXpd/DAyb 9gNtsor0Pvc8sMHgSWULgHOKcebHl486X5KSx1D0YksvpbP09MZL6N4drDwq/YDNk+t/ rm2dOc2He9sCG0nkseHKVZfoH2NWFiZ+qBsI8/tkxps3RlH1c0EoedlhXq63Ot+Q1vPi 1QnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739541660; x=1740146460; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FNw2IjE2pzkh8kOG8gbCKeyHG7nPC9wPKaPR6juqTg0=; b=anVZvjj0TkA3QgAAeKREHX8NUuFdRZUBW0QiBXNa6JlofnA6EWrjQLKkCEuCP4yE4G m4OwceqZaWS/3qGLZxk925dBwWKBinZzVA9BZNQ00vy3F4JTvjtQmsLvYAMFAagDwRo3 pZJhu5PKcEb8/hhudt3c/WB6Gw3gG1YwGLL8bQnxi/XgCy9mt2kCLsPgigrpJNhng+kN QkksKaS/pwnHiV82mFSUgbXwHdPX+eQJDCSjhnb7es11USVkemd7n+ORGecs1GiaMN3f lyny0ZQU6F7L8fWvRKgPXItsLWs60Y3PsZfbdkUjbQepaRGmgAu1KeiKyUTsPVHiv9SC 92yg== X-Gm-Message-State: AOJu0YzsthoDPQv0JNrOP+0SsJmNzI3pMBN0bXCUSHbQBJYAO9/X6lSh 876a0MqJOD1kNSzBmCD1fPCKx2+yHh57AIqATVmzIj/L882gxnZ+TFotCU0hDhhrLyKUFhsH9lF vo3S4Bg== X-Gm-Gg: ASbGncsVCy4JvhXu0RAuWrjjvfpHGCrI4PQuCm62QBTGvMIAbPq+DnVxZ3yGDL136l5 PMbKByuHuVWzcZKq0Fui94LfoNq/YIvdwPU2sgn2+/t4rszE25HkmE8QdBDkmVpfppxe9LC73gT 51vqef6Kdd2BTu1PJ+vUA0K0oRwMplAr3Fm7ztn79V3CHXXhPk59GG7W/HXGIxhPqQk54bTjQPC /vlB/1mo1INhl9SKfLLO6SNZnd8leN2woPVq8z9SCUVvU0VRIOK12x2iea1++FiTTO7BLzLJd3c LoX3fQdyS/iBXo/z2XLf2nZx X-Received: by 2002:a05:6000:120f:b0:38f:220d:9d3a with SMTP id ffacd0b85a97d-38f244ec272mr8173808f8f.22.1739541659693; Fri, 14 Feb 2025 06:00:59 -0800 (PST) Received: from builder.. ([2a01:e0a:3cb:7bb0:65ac:d875:2c3e:607f]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38f258fc7e0sm4666391f8f.48.2025.02.14.06.00.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Feb 2025 06:00:59 -0800 (PST) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Tom Rini , Rick Chen , Leo , Dan Carpenter , Simon Glass , Heinrich Schuchardt , Jiaxun Yang , Andrew Goodbody , Yu-Chien Peter Lin Subject: [RFC PATCH 03/10] riscv: add initjmp() Date: Fri, 14 Feb 2025 15:00:18 +0100 Message-ID: <20250214140031.484344-4-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250214140031.484344-1-jerome.forissier@linaro.org> References: <20250214140031.484344-1-jerome.forissier@linaro.org> MIME-Version: 1.0 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 Implement initjmp() for RISC-V. Signed-off-by: Jerome Forissier --- arch/Kconfig | 1 + arch/riscv/include/asm/setjmp.h | 1 + arch/riscv/lib/setjmp.S | 10 ++++++++++ 3 files changed, 12 insertions(+) diff --git a/arch/Kconfig b/arch/Kconfig index 57695fada8d..b745222bfbe 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -152,6 +152,7 @@ config RISCV bool "RISC-V architecture" select CREATE_ARCH_SYMLINK select HAVE_SETJMP + select HAVE_INITJMP select SUPPORT_ACPI select SUPPORT_LITTLE_ENDIAN select SUPPORT_OF_CONTROL diff --git a/arch/riscv/include/asm/setjmp.h b/arch/riscv/include/asm/setjmp.h index 72383d43303..98ea157eb3b 100644 --- a/arch/riscv/include/asm/setjmp.h +++ b/arch/riscv/include/asm/setjmp.h @@ -21,5 +21,6 @@ typedef struct jmp_buf_data jmp_buf[1]; int setjmp(jmp_buf jmp); void longjmp(jmp_buf jmp, int ret); +int initjmp(jmp_buf jmp, void __noreturn (*func)(void), void *stack_top); #endif /* _SETJMP_H_ */ diff --git a/arch/riscv/lib/setjmp.S b/arch/riscv/lib/setjmp.S index 99d6195827e..6f952a16eee 100644 --- a/arch/riscv/lib/setjmp.S +++ b/arch/riscv/lib/setjmp.S @@ -59,3 +59,13 @@ ENTRY(longjmp) ret ENDPROC(longjmp) .popsection + +.pushsection .text.initjmp, "ax" +ENTRY(initjmp) + /* a1: entry point address, a2: stack top */ + STORE_IDX(a1, 12) + STORE_IDX(a2, 13) + li a0, 0 + ret +ENDPROC(initjmp) +.popsection From patchwork Fri Feb 14 14:00:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 865099 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:1568:b0:38f:210b:807b with SMTP id 8csp169765wrz; Fri, 14 Feb 2025 06:01:45 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCX8XaK1z5LdCv3lwwl0EGa2/DTtBmD2TpmMV38g5ecg9r6xvSOSJRZL5r6C9lYewdhVRdyXsQ==@linaro.org X-Google-Smtp-Source: AGHT+IHaIf5YTpYvN1VMCHZm/J1II/kyTzYd1rD2RCd6Mjm+EKUjHHTZcsL+f0tUbs157ASmGOkM X-Received: by 2002:a05:6000:1252:b0:38d:e2c1:9749 with SMTP id ffacd0b85a97d-38f24512c78mr9222928f8f.35.1739541705259; Fri, 14 Feb 2025 06:01:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1739541705; cv=none; d=google.com; s=arc-20240605; b=ZHXyva9aW5OuopiS21IGb7ycoM5+8P72xiXVjvDZBp+uuM8YgXJe7OvKVqlJ0PdTzn QBsi7/e/eAOyJn33QDhCO6U2rAyz4scRqXRS72Tw3uRgsBSfd7CkVr3rofbIisXPL6Mg MUcKVaFOX+mIjJXW6CdFztFEH0hkV4ISw14M3vKxB5qSxFvWjinXXDAJjaj5g2pAsuWL 1YKEqJDPOICunKtU8BJJHoTGakKZd9Y8AYzyR3xZnZscbPLHC/xeqcam8J76/XtyvWhC RDOj4wEyRbdRNXIzpu8ajML7NCzB2Tf1uQR0OFkMcQNPZGHLPWLPw7wv+RWRlhuHvIFg 5XjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=zc5YqeOWjVFGOI9lQwk18URjr1oDar0gNQj5WjUOp00=; fh=HaKHCOHL46OAAPpM3W6HDLkDmJxXWc+qggc/xnkS9u8=; b=G0Skh6yUU4hpjVVl632hVL03ftZ01XIH/kFa38+bqH+4LJ6r1G/+fb3Oku9S0r7E6k LIc0Bsg9sVSO3u8DwEpOYPGvTiN5GN7Ss9T0nzge0M037f5qW4AsK1VTss5WoIkYTTZC 7c8mlgkqR466E/YqlstF8GJFdXzx2I7whzh8ap5dakCgQOYnu7VS7wvbxRiLluJous/6 nyJPfdMgQjL//uszorI5dyshs/hJjMUaFe34ABifdFUVYfXCdWs3RJF3htNNh+gsBdxd tsi7Zie9lZckjv2EJB0NeBv/DMkUe2lAZA1LoHSWBlgX+7MP/lsCbW+lXJgauFvn+2zo eG/Q==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MGq3WpY4; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id ffacd0b85a97d-38f258e0ee1si4572152f8f.141.2025.02.14.06.01.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Feb 2025 06:01:45 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MGq3WpY4; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id F278F80EAF; Fri, 14 Feb 2025 15:01:06 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="MGq3WpY4"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 230F580F0A; Fri, 14 Feb 2025 15:01:05 +0100 (CET) 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,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) (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 7E32880C83 for ; Fri, 14 Feb 2025 15:01:02 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-388cae9eb9fso1049669f8f.3 for ; Fri, 14 Feb 2025 06:01:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1739541662; x=1740146462; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zc5YqeOWjVFGOI9lQwk18URjr1oDar0gNQj5WjUOp00=; b=MGq3WpY4/qrbCv2mDbpHVVQWRyEznH3KcwzrJJ0C18R+0v2T72sH3TTIPFlUKJ48xf 0hCrzUSIAmhAwnByVAEoepkOVEaT+q3v0VLlW0p4Ch5osQ5/y0eh2cjhBuREvG4Ajq2r vVnv8SJsZxBoUC25/Qfk+SgqnMbKJ+CH1oelky5sXmdpqeKaDNhrTOmmYaMP0rWIiao8 rTDrICL90YjkEKUF09axbHwjfBrhAZgibrAt0KoMGoA+vIWLTX49VMzyZzpahGmspnZf kszPItOAcAzRDjx4jASQAJA48H3dxT+s9KSWC3bCl0uAOb15Gs/BHIUAPAplKIGnYCBR wW1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739541662; x=1740146462; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zc5YqeOWjVFGOI9lQwk18URjr1oDar0gNQj5WjUOp00=; b=eG7rIry4pM5BYM1CEsyMD9WDKZo7PiFmo+JdvNmdTVwI8Ic7C6cg95u3Ol55AE4vtA Y6Pl5uwPFwgEBVIex5cASTf4GiGBn7/JaqHJQRlPY5mVhMAVAmTj6xX0pZ3RS4LI+bO3 NkSdRd7/zIjTBDZLGYXoMa2igAkXieYCwXj/IE6laaNp12TUwZY6fERjLQgPeRZJbuKi /g4XUfoMmr7g5ipF7MpG99RWe6PzGZ6sqA+6kltzui71DDCis/e1UZPXvmmpPv7mxtpE rlRbNKkPUSDpNn8NktPp74mIwvKbLC3CMTw7hri7CrU4lS2BkNEv38nMrmQDpBteylwF jxEQ== X-Gm-Message-State: AOJu0YwR0lEsZQMrCvJNBKeB+mX0FTUfDme0unIR0O1nC8W16kGFlsxs rbXb2XZT6fbQL/03ci9h7vBu9uT4yYLTgkAz0oYPxLadeR5E/bRURU0zA1hoErQA/AS8Rj55n+2 uuSOj3Q== X-Gm-Gg: ASbGncvE1sDlWs2f1ZbNNmvZfCk0bzR3mNKhbu9qrDax1Y2H/6vSb/h4PalA+Wmj9ig 3XVw9vnJYVC3YuYnkQiscxskLVUJVD49jIy5jr/kUu8J405HsO+K4XXiUPY9AUT5FZcXBraVCEg 9K7a8w5Us+Z7LEtQML3TN938lG5F71N+pfhW1J1H+q/Qc7V8LOlA15IYKl5ripKU26aQx6jGHSb 79Rp16c5JVv0+fhNIGddDM0AfefruqLLz9Nno3axFe1ZRQARpjL5b6iPow1AfHtlu2apRXHR8ua vUlVvUON8PX8T6hbXLYMEicR X-Received: by 2002:adf:e386:0:b0:38e:c2de:70d4 with SMTP id ffacd0b85a97d-38f24512d6amr7751638f8f.42.1739541661170; Fri, 14 Feb 2025 06:01:01 -0800 (PST) Received: from builder.. ([2a01:e0a:3cb:7bb0:65ac:d875:2c3e:607f]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38f258fc7e0sm4666391f8f.48.2025.02.14.06.01.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Feb 2025 06:01:00 -0800 (PST) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Simon Glass , Tom Rini Subject: [RFC PATCH 04/10] sandbox: add initjmp() Date: Fri, 14 Feb 2025 15:00:19 +0100 Message-ID: <20250214140031.484344-5-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250214140031.484344-1-jerome.forissier@linaro.org> References: <20250214140031.484344-1-jerome.forissier@linaro.org> MIME-Version: 1.0 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 Add ininijmp() to sandbox. The implementation is taken verbatim from barebox [1]. It is quite complex because contrary to U-Boot platform code we don't know how the system's C library implements the jump buffer, so we can't just write the function and stack pointers into it. FIXME: this patch should make SANDBOX select HAVE_INITJMP (in arch/Kconfig). It does not due to the following error detected by CI: _________________________ test_ut[ut_lib_lib_initjmp] __________________________ test/py/tests/test_ut.py:608: in test_ut output = u_boot_console.run_command('ut ' + ut_subtest) test/py/u_boot_console_base.py:334: in run_command m = self.p.expect([self.prompt_compiled] + self.bad_patterns) test/py/u_boot_spawn.py:296: in expect c = self.receive(1024) test/py/u_boot_spawn.py:235: in receive raise err test/py/u_boot_spawn.py:227: in receive c = os.read(self.fd, num_bytes).decode(errors='replace') E OSError: [Errno 5] Input/output error ----------------------------- Captured stdout call ----------------------------- => ut lib lib_initjmp Test: lib_initjmp: initjmp.c Failures: 0 common/dlmalloc.c:796: do_check_free_chunk: Assertion `next == top || inuse(next)' failed.common/dlmalloc.c:796: do_check_free_chunk: Assertion `next == top || inuse(next)' failed. ---------------- generated xml file: /tmp/sandbox64/results.xml ---------------- On x86 the dmalloc error is not printed but the I/O error is still there. [1] https://github.com/barebox/barebox/blob/b2a15c383ddc/arch/sandbox/os/setjmp.c Signed-off-by: Jerome Forissier --- arch/sandbox/cpu/Makefile | 11 +- arch/sandbox/cpu/initjmp.c | 172 ++++++++++++++++++++++++++++++ arch/sandbox/include/asm/setjmp.h | 5 + 3 files changed, 187 insertions(+), 1 deletion(-) create mode 100644 arch/sandbox/cpu/initjmp.c diff --git a/arch/sandbox/cpu/Makefile b/arch/sandbox/cpu/Makefile index bfcdc335d32..038ad78accc 100644 --- a/arch/sandbox/cpu/Makefile +++ b/arch/sandbox/cpu/Makefile @@ -5,7 +5,7 @@ # (C) Copyright 2000-2003 # Wolfgang Denk, DENX Software Engineering, wd@denx.de. -obj-y := cache.o cpu.o state.o +obj-y := cache.o cpu.o state.o initjmp.o extra-y := start.o os.o extra-$(CONFIG_SANDBOX_SDL) += sdl.o obj-$(CONFIG_XPL_BUILD) += spl.o @@ -29,6 +29,15 @@ cmd_cc_eth-raw-os.o = $(CC) $(filter-out -nostdinc, \ $(obj)/eth-raw-os.o: $(src)/eth-raw-os.c FORCE $(call if_changed_dep,cc_eth-raw-os.o) +# initjmp.c is build in the system environment, so needs standard includes +# CFLAGS_REMOVE_initjmp.o cannot be used to drop header include path +quiet_cmd_cc_initjmp.o = CC $(quiet_modtag) $@ +cmd_cc_initjmp.o = $(CC) $(filter-out -nostdinc, \ + $(patsubst -I%,-idirafter%,$(c_flags))) -c -o $@ $< + +$(obj)/initjmp.o: $(src)/initjmp.c FORCE + $(call if_changed_dep,cc_initjmp.o) + # sdl.c fails to build with -fshort-wchar using musl cmd_cc_sdl.o = $(CC) $(filter-out -nostdinc -fshort-wchar, \ $(patsubst -I%,-idirafter%,$(c_flags))) -fno-lto -c -o $@ $< diff --git a/arch/sandbox/cpu/initjmp.c b/arch/sandbox/cpu/initjmp.c new file mode 100644 index 00000000000..c99721423c5 --- /dev/null +++ b/arch/sandbox/cpu/initjmp.c @@ -0,0 +1,172 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* + * An implementation of initjmp() in C, that plays well with the system's + * setjmp() and longjmp() functions. + * Taken verbatim from arch/sandbox/os/setjmp.c in the barebox project. + * + * Copyright (C) 2006 Anthony Liguori + * Copyright (C) 2011 Kevin Wolf + * Copyright (C) 2012 Alex Barcelo + * Copyright (C) 2021 Ahmad Fatoum, Pengutronix + * This file is partly based on pth_mctx.c, from the GNU Portable Threads + * Copyright (c) 1999-2006 Ralf S. Engelschall + */ + +/* XXX Is there a nicer way to disable glibc's stack check for longjmp? */ +#ifdef _FORTIFY_SOURCE +#undef _FORTIFY_SOURCE +#endif + +#include +#include +#include +#include +#include + +typedef sigjmp_buf _jmp_buf __attribute__((aligned((16)))); +_Static_assert(sizeof(_jmp_buf) <= 512, "sigjmp_buf size exceeds expectation"); + +/* + * Information for the signal handler (trampoline) + */ +static struct { + _jmp_buf *reenter; + void (*entry)(void); + volatile sig_atomic_t called; +} tr_state; + +/* + * "boot" function + * This is what starts the coroutine, is called from the trampoline + * (from the signal handler when it is not signal handling, read ahead + * for more information). + */ +static void __attribute__((noinline, noreturn)) +coroutine_bootstrap(void (*entry)(void)) +{ + for (;;) + entry(); +} + +/* + * This is used as the signal handler. This is called with the brand new stack + * (thanks to sigaltstack). We have to return, given that this is a signal + * handler and the sigmask and some other things are changed. + */ +static void coroutine_trampoline(int signal) +{ + /* Get the thread specific information */ + tr_state.called = 1; + + /* + * Here we have to do a bit of a ping pong between the caller, given that + * this is a signal handler and we have to do a return "soon". Then the + * caller can reestablish everything and do a siglongjmp here again. + */ + if (!sigsetjmp(*tr_state.reenter, 0)) { + return; + } + + /* + * Ok, the caller has siglongjmp'ed back to us, so now prepare + * us for the real machine state switching. We have to jump + * into another function here to get a new stack context for + * the auto variables (which have to be auto-variables + * because the start of the thread happens later). Else with + * PIC (i.e. Position Independent Code which is used when PTH + * is built as a shared library) most platforms would + * horrible core dump as experience showed. + */ + coroutine_bootstrap(tr_state.entry); +} + +int __attribute__((weak)) initjmp(_jmp_buf jmp, void (*func)(void), void *stack_top) +{ + struct sigaction sa; + struct sigaction osa; + stack_t ss; + stack_t oss; + sigset_t sigs; + sigset_t osigs; + + /* The way to manipulate stack is with the sigaltstack function. We + * prepare a stack, with it delivering a signal to ourselves and then + * put sigsetjmp/siglongjmp where needed. + * This has been done keeping coroutine-ucontext (from the QEMU project) + * as a model and with the pth ideas (GNU Portable Threads). + * See coroutine-ucontext for the basics of the coroutines and see + * pth_mctx.c (from the pth project) for the + * sigaltstack way of manipulating stacks. + */ + + tr_state.entry = func; + tr_state.reenter = (void *)jmp; + + /* + * Preserve the SIGUSR2 signal state, block SIGUSR2, + * and establish our signal handler. The signal will + * later transfer control onto the signal stack. + */ + sigemptyset(&sigs); + sigaddset(&sigs, SIGUSR2); + pthread_sigmask(SIG_BLOCK, &sigs, &osigs); + sa.sa_handler = coroutine_trampoline; + sigfillset(&sa.sa_mask); + sa.sa_flags = SA_ONSTACK; + if (sigaction(SIGUSR2, &sa, &osa) != 0) { + return -1; + } + + /* + * Set the new stack. + */ + ss.ss_sp = stack_top - CONFIG_STACK_SIZE; + ss.ss_size = CONFIG_STACK_SIZE; + ss.ss_flags = 0; + if (sigaltstack(&ss, &oss) < 0) { + return -1; + } + + /* + * Now transfer control onto the signal stack and set it up. + * It will return immediately via "return" after the sigsetjmp() + * was performed. Be careful here with race conditions. The + * signal can be delivered the first time sigsuspend() is + * called. + */ + tr_state.called = 0; + pthread_kill(pthread_self(), SIGUSR2); + sigfillset(&sigs); + sigdelset(&sigs, SIGUSR2); + while (!tr_state.called) { + sigsuspend(&sigs); + } + + /* + * Inform the system that we are back off the signal stack by + * removing the alternative signal stack. Be careful here: It + * first has to be disabled, before it can be removed. + */ + sigaltstack(NULL, &ss); + ss.ss_flags = SS_DISABLE; + if (sigaltstack(&ss, NULL) < 0) { + return -1; + } + sigaltstack(NULL, &ss); + if (!(oss.ss_flags & SS_DISABLE)) { + sigaltstack(&oss, NULL); + } + + /* + * Restore the old SIGUSR2 signal handler and mask + */ + sigaction(SIGUSR2, &osa, NULL); + pthread_sigmask(SIG_SETMASK, &osigs, NULL); + + /* + * jmp can now be used to enter the trampoline again, but not as a + * signal handler. Instead it's longjmp'd to directly. + */ + return 0; +} + diff --git a/arch/sandbox/include/asm/setjmp.h b/arch/sandbox/include/asm/setjmp.h index 001c7ea322d..d708e6da3fc 100644 --- a/arch/sandbox/include/asm/setjmp.h +++ b/arch/sandbox/include/asm/setjmp.h @@ -31,5 +31,10 @@ typedef struct jmp_buf_data jmp_buf[1]; */ int setjmp(jmp_buf jmp); __noreturn void longjmp(jmp_buf jmp, int ret); +/* + * initjmp() is non-standard, still it has to play well with the system versions + * of setjmp()/longjmp(). + */ +int initjmp(jmp_buf jmp, void __noreturn (*func)(void), void *stack_top); #endif /* _SETJMP_H_ */ From patchwork Fri Feb 14 14:00:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 865100 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:1568:b0:38f:210b:807b with SMTP id 8csp169913wrz; Fri, 14 Feb 2025 06:01:57 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWZv0WcQnzQzc2XVtNg/Gm2h8EZo/aueNodujQQPJ6/9F3Fsa19qc7wgt4XYowKk8PJLlmK2w==@linaro.org X-Google-Smtp-Source: AGHT+IF7PMm2O8ibpC+jRPWTrxLAEzNpj2RyTmryRN+B53hG47kMlRECHcaC35411rEqxxewY6Yi X-Received: by 2002:a05:6000:1562:b0:38d:e378:20f7 with SMTP id ffacd0b85a97d-38f24519c03mr10644201f8f.41.1739541717065; Fri, 14 Feb 2025 06:01:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1739541717; cv=none; d=google.com; s=arc-20240605; b=CRH96otkT1StVYeDrGslgCATO+TyevjeoGpWpsbWe75uipzClxBWbsISvm91hzUb1j cJVO4XoR2mlFrVgqHStiq8Eg9B+BPNcMLtwaLtqUXJNIIyYZa08+KNOFMmtIExW1TdAb 4sPxMBzvZQapO1a7Z6beeXCgfgZ8bPrQ1rvxd0xcmr/+tAvHSrOVS7EowLUBUtfIclVs xaI+R8gyggqChqHWYyFpaYmYv47wjYeYFuvB+ncjQFY1NMAm3eZ4FXeXI7USIIQGCiST an6TG1EhaaGGzr+/falPPJ9Imex66QcXOExQl5u2snTCVh4ZxReu7b2xZuhh9IZpeUtV NAUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=IJNaNPY3czlLhhfrH4SNPdHcNteu2M3lW9KGA73kCRE=; fh=5u8mhcT/cvD7c0jneSWBm/018GsimgfQmc5aiiIZNZM=; b=cMoNnrhopjzruwAnwx90u+bDXhFOSgp1cTzlHuyxQ/iaPfnWaqEczjnN5KdWytxjgA LLra8QrOyVH4aWLPxBUVXYOJ+w7g0fxq5/aW4klLizaC/EZv+WXiJ4Y6VPElCu59TSP7 qREYLNaj+BBVm2yKSw/yjt/Nyhw/gH8XMGdMfu76pqqlZ6ETokMfcsO3N0IxwOJP/zzD dh+h7FPIWe5V3bEkXrYagwwnGUidXsRqVrkHzBSAIZjfkan+vOCKz+EGH/kDpWNnUiQq YNF5DgcAv1pE27gvr0riaNsiIM52g4L7bbn+VZTFcavThDj3YsasknYTmI8AyDusZY/I JLoQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xg4b+rCA; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id ffacd0b85a97d-38f259f7ddcsi4588656f8f.500.2025.02.14.06.01.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Feb 2025 06:01:57 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xg4b+rCA; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4EEE780F16; Fri, 14 Feb 2025 15:01:07 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="xg4b+rCA"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 93EC680C83; Fri, 14 Feb 2025 15:01:05 +0100 (CET) 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,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) (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 77D3580E88 for ; Fri, 14 Feb 2025 15:01:03 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-4395817a7f2so14379115e9.1 for ; Fri, 14 Feb 2025 06:01:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1739541663; x=1740146463; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IJNaNPY3czlLhhfrH4SNPdHcNteu2M3lW9KGA73kCRE=; b=xg4b+rCA1QidJ4o3ykuBlUJ9tLdhuQKPfF02yuOacR2vrv6LTIIxj5W8v6/dD+ct1j B1+MI0rG3hswtgxnDosLf/mq+6vbLzkbcAxjBf0F++luQL3Y0Fsge2mF9d0+5dc75Wla YYdp9/bnitI7FNw83BN11uxTyghXlTTWyHCkhODq0z+Gt3130SUV8/uZSIjNf5+6rcyL ju5xiDfK9IWg301/r2g7wbvZl7LWJVfDd9vdiRBEIzh/fkqKWZaDyxQKWucnY05/pF7M eO3yZ6+JzjCdB+E2ULJK4ftnuNYsGg8ZupzrYGZ2wXJc9i29N4qwDHyLGpVHd7WUcLoY KERw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739541663; x=1740146463; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IJNaNPY3czlLhhfrH4SNPdHcNteu2M3lW9KGA73kCRE=; b=ZoMV1M9YoDhlf7xBXaqUT/NGUpB92FtBeus6a/7jojF9eSOpQdqyG3DL+wP7J2JBpI vIAZ9nCQQJ5RnXOQoy9VkqHgD4ZAYqFAlHAyquDHpPbXnLfRxGZDsF4ksef+Bq6RbUoi YhlPCHKTDjmc7GfLz9NbyxR+g/9sgmZzJkp80t+IFV/NyrOnQOCWbyZirSYoNMW2Wipv qio0PEffFB7LUovxiUPPNFUlabipuv1LiXyCuOI1O3K/XBqHfS6VURbTu4h5NjkCX0WS lzRbqvn8M39yB0ug5hHpqeU35dQ8kaBhSmIROwhirLj393Vgrz3Fkd9biBc1ser4gJTl DxGA== X-Gm-Message-State: AOJu0Yzi7QZhbmDL7fFPdtIyE4b0cMOaudXcSb/hyR2J5QHkTAL5X2rT RDgepUhzyK+uMXr5opu0d5s0wo8N5yQLFJkYM2tvfIDpKwYVMlvWHfM3S/l8ltEkcnBvansFVzn SUY9oBQ== X-Gm-Gg: ASbGncuSxE+we4sy7yEdK92HTfTflGO1qJ98xF9hZQU9vyeZQq0laAgKkwoKr8NhD4T Ml34dLFvLdV7mNZLVVW0M/Wwvgd4mU2nXare1XU7AFaYmjURRUc8sceLHmXbt2kY01cDEg99Tnv h+aCfWrwqO6EgOBOApdtBhX8dpCM9oEoEmpbkYQQJID2gBTy7z09geFzbq54FX7narjJiscF4K/ xojtOjEl3rz9YZkEKQCtvgu5+p67L40ZJqCCG6bDz3AnmAVQs7fu0+yTJ7rn1YK6e9R3gwm5Zwu d5G8swXq8tu2lbbWgrk8l3ud X-Received: by 2002:a05:600c:870a:b0:439:42c6:f11f with SMTP id 5b1f17b1804b1-43960169268mr101954885e9.4.1739541662448; Fri, 14 Feb 2025 06:01:02 -0800 (PST) Received: from builder.. ([2a01:e0a:3cb:7bb0:65ac:d875:2c3e:607f]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38f258fc7e0sm4666391f8f.48.2025.02.14.06.01.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Feb 2025 06:01:02 -0800 (PST) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Tom Rini , Simon Glass , Heinrich Schuchardt , Philippe Reynes , Raymond Mao Subject: [RFC PATCH 05/10] test: lib: add initjmp() test Date: Fri, 14 Feb 2025 15:00:20 +0100 Message-ID: <20250214140031.484344-6-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250214140031.484344-1-jerome.forissier@linaro.org> References: <20250214140031.484344-1-jerome.forissier@linaro.org> MIME-Version: 1.0 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 Test the initjmp() function when HAVE_INITJMP is set. Signed-off-by: Jerome Forissier --- test/lib/Makefile | 1 + test/lib/initjmp.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 test/lib/initjmp.c diff --git a/test/lib/Makefile b/test/lib/Makefile index 0e4cb8e3dfd..bf04685dae1 100644 --- a/test/lib/Makefile +++ b/test/lib/Makefile @@ -14,6 +14,7 @@ obj-y += hexdump.o obj-$(CONFIG_SANDBOX) += kconfig.o obj-y += lmb.o obj-$(CONFIG_HAVE_SETJMP) += longjmp.o +obj-$(CONFIG_HAVE_INITJMP) += initjmp.o obj-$(CONFIG_CONSOLE_RECORD) += test_print.o obj-$(CONFIG_SSCANF) += sscanf.o obj-$(CONFIG_$(PHASE_)STRTO) += str.o diff --git a/test/lib/initjmp.c b/test/lib/initjmp.c new file mode 100644 index 00000000000..52bbda8cc60 --- /dev/null +++ b/test/lib/initjmp.c @@ -0,0 +1,72 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2025 Linaro Limited + * + * Unit test for initjmp() + */ + +#include +#include +#include +#include +#include +#include + +static bool ep_entered; +static jmp_buf return_buf; + +static void __noreturn entrypoint(void) +{ + ep_entered = true; + + /* Jump back to the main routine */ + longjmp(return_buf, 1); + + /* Not reached */ + panic("longjmp failed\n"); +} + +static int lib_initjmp(struct unit_test_state *uts) +{ + int ret; + void *stack; + jmp_buf buf; + int stack_sz = 1024; + + ep_entered = false; + + stack = malloc(stack_sz); + ut_assertnonnull(stack); + + ut_assert(!ep_entered); + + /* + * Prepare return_buf so that entrypoint may jump back just after the + * if() + */ + if (!setjmp(return_buf)) { + /* return_buf initialized, entrypoint not yet called */ + + /* + * Prepare another jump buffer to jump into entrypoint with the + * given stack + */ + ret = initjmp(buf, entrypoint, stack + stack_sz); + ut_assertok(ret); + + /* Jump into entrypoint */ + longjmp(buf, 1); + /* + * Not reached since entrypoint is expected to branch after + * the if() + */ + ut_assert(false); + } + + ut_assert(ep_entered); + + free(stack); + + return 0; +} +LIB_TEST(lib_initjmp, 0); From patchwork Fri Feb 14 14:00:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 865102 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:1568:b0:38f:210b:807b with SMTP id 8csp170239wrz; Fri, 14 Feb 2025 06:02:22 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWn8xlOjvQnKUXIKc/fOLTD9G/D0xSs3OTyUl+UeTs1R5vKHE8/k/oTRE3ZX4GfRbep/I8ASA==@linaro.org X-Google-Smtp-Source: AGHT+IF7Ny9qcdjSLukdP5WFhRrKUE0BebKvuQ43lDEJNvuS+VMxa/lNELQ/FmLLmvzev1PylC6x X-Received: by 2002:a5d:5849:0:b0:38a:8906:6b66 with SMTP id ffacd0b85a97d-38dea2e9632mr15754559f8f.38.1739541741295; Fri, 14 Feb 2025 06:02:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1739541741; cv=none; d=google.com; s=arc-20240605; b=bE9bo6F25J1bGYAnA3Dwk+W4xopy574St7ipOD03ZyQSuRLC2vq5M2DoNUWRIioHwq 2POfWbocWq16yZu772Wil7GKqysNH92BSJudbaq8HSiSselhkqHoZOtQP6YHI5oHzKML /zRlylUFAM4+2Lnxl+2WEOC8VRkhxlCbk4EF73hOPfWtVbdm3C9E+hlZXpKd758/MBdM Px5ghrL9TdWa4shGPouc19jhriv9fRx/7wYALKKJQXWakCsEpVMI6logOYvB+FKD0CCf 5YaWk2xIeLzLWt6ji1Z64gu7IPu8MqNsdQgKxT/SZJrPI65ap0Z1wcVGXzWJfNBjMSr5 c62Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=rQWcMVhiDsInzul+8CcxPqL1KlSPSKMbGE8a9Q4ktAU=; fh=TQ9l4ZhCz/Tf0/aj9oP7eJFW47zEyp6bK9wMMzlxmag=; b=WzXpo/izPED4wgNdwa4nSr2GPswU7JZ3Oe9E+B2bB90/AmBu7kqA3j7vN2XDVXxTLB bp7yVmOB5I2R4PSKSrf3YZyho9MFq2ssma/UMVNBi47d+mwNJa4giOvbQnzvyBgpPN9h PzQxolHqeb0ui0gwW3I5Bq+rS2w9mN4IOkze3zgHspLkmexR0E17N7hqSdidIbKGFyU5 okhX0El5DWzZemEsd+sOMPeCk/Qf7r2ney3sscQaggSvkJttK/jPWKjjVrdXCO/6k3DD ZFiQNVtcXbq5JT6hWLNVzgT+CrupuJsNz8PVjYzpqXj2xSJvZuwYfrx1ha9SzxSHdtWK 0nGw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hqWUFUKL; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id 5b1f17b1804b1-439618e5f62si44328015e9.165.2025.02.14.06.02.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Feb 2025 06:02:20 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hqWUFUKL; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id EA8BD80F57; Fri, 14 Feb 2025 15:01:10 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="hqWUFUKL"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6235980F3F; Fri, 14 Feb 2025 15:01:09 +0100 (CET) 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,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) (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 E807F80E88 for ; Fri, 14 Feb 2025 15:01:06 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-4395dddb07dso22069715e9.2 for ; Fri, 14 Feb 2025 06:01:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1739541666; x=1740146466; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rQWcMVhiDsInzul+8CcxPqL1KlSPSKMbGE8a9Q4ktAU=; b=hqWUFUKLqatwjZyIy0Ycz1gSu6QyGok7oySUh2Oj218Y8YyBpIOwgv/4ACj7MKBsYj DPlzNJnVv3l6Q4/V3GE0IcuGplYpJjgOJ3XawNSrlI0ABBR+riOs6iKUJWd2i9RLsnJc EjIOoI7KZkwfOvB35Yf4JdI5Zs6AXSH3gXmyM9JAsPu1ownxlFf66TxBtDec5NZcXCeD 1wKxcIZ32+GxsZHW8eVQ7P5elAs8yKcwPHeYWUSuX6u37H5lqFsYr9NaY7+X8TB4Xkvr UREkdmmdCsamJrJQ2a2EeDSnD+nt5sM8K24DIRoxWnvNB59cSTBgBMoaAuvNE60j0nhX 27ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739541666; x=1740146466; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rQWcMVhiDsInzul+8CcxPqL1KlSPSKMbGE8a9Q4ktAU=; b=Az6IL8ULO6c76N00ZPo1YFYPAL37k3gxmCBd6uWg79AE9l7ujS7/KAvw9M9TUbnMt3 GTz+fTbjCuNad03ddi8WhGWwcxG1mSWDG77NSdU30iyUj/PFbf86jMe6Ube/P+80bih3 cYpBRHftAIl4YGNUrXIRqxunElVpSgZJ2a3wf6D/Soz0JBn/Ngoja0awUcZTxUYLBRUt 0mPYubN1IkgMKFcOSV/gF69cj8qtVGKRVGJBo6SRYyD18l8UQsELBqRyRqoO5j2Mjuuu knsol+kHsA+/uEWJlNmFeB/WgrjHOrzzHRzLCA6RR2lUuS2Pbk5S7rScP4a1G51PRkA5 h4QQ== X-Gm-Message-State: AOJu0Yy1wYIyIR+iItWsyyE1tpAV2E5Go4pE7Oa79d/AptFgS9c31JMY hy899AhVeInN93zELPjjPoYcFHDZsKEfQh2a/YaaMKBgdrgDe9FB0zsKY7gj4t+OpUMOXDKCQky nC83RTA== X-Gm-Gg: ASbGncsepO3E+683rLgYbPRYqDcfZVCC0V9jNuP5mmc6XVW3cJQQgLPiC/qFSk3xTwb yHs4c15jKyPjxihXQ1K54dXWwBzeQPNV2klIH8BjMo2+k1gyBpSWNzoCnyupXKLAchgLEdRoQbE pUUJP+cghUxlmrjqe7LHo2bRjCL9M8eJcJnuZk+fbF79GSArp0y8j40JjimkYb2LfK73JroM/aC kN5qlID6NXQRMK7/6GjKunq7n4PFtqR4BH7Nx8lRtOptN1u/t5QxywsoQHQncAVkHc1v945xpX3 BO/g+MC1su/OpzCzHucetjjE X-Received: by 2002:a05:600c:1e18:b0:439:6589:e1de with SMTP id 5b1f17b1804b1-4396589e306mr54809285e9.26.1739541664219; Fri, 14 Feb 2025 06:01:04 -0800 (PST) Received: from builder.. ([2a01:e0a:3cb:7bb0:65ac:d875:2c3e:607f]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38f258fc7e0sm4666391f8f.48.2025.02.14.06.01.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Feb 2025 06:01:03 -0800 (PST) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Tom Rini , Simon Glass , Sughosh Ganu , Raymond Mao , Patrick Rudolph , Michal Simek Subject: [RFC PATCH 06/10] uthread: add cooperative multi-tasking interface Date: Fri, 14 Feb 2025 15:00:21 +0100 Message-ID: <20250214140031.484344-7-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250214140031.484344-1-jerome.forissier@linaro.org> References: <20250214140031.484344-1-jerome.forissier@linaro.org> MIME-Version: 1.0 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 Add an new internal API called uthread (Kconfig symbol: UTHREAD) which provides cooperative multi-tasking. The goal is to be able to improve the performance of some parts of U-Boot by overlapping lengthy operations. Each uthread has its own stack allocated on the heap. The default stack size is defined by the UTHREAD_STACK_SIZE symbol and is used when uthread_create() is passed zero for the stack_sz argument. The implementation is based on context-switching via initjmp()/setjmp()/ longjmp() and is inspired from barebox threads [1]. [1] https://github.com/barebox/barebox/blob/master/common/bthread.c Signed-off-by: Jerome Forissier --- include/uthread.h | 31 ++++++++++++++ lib/Kconfig | 19 ++++++++ lib/Makefile | 2 + lib/uthread.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 159 insertions(+) create mode 100644 include/uthread.h create mode 100644 lib/uthread.c diff --git a/include/uthread.h b/include/uthread.h new file mode 100644 index 00000000000..ea1389e82c6 --- /dev/null +++ b/include/uthread.h @@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright 2025 Linaro Limited + */ + +#include + +#ifndef _UTHREAD_H_ +#define _UTHREAD_H_ + +#ifdef CONFIG_UTHREAD + +int uthread_create(void (*fn)(void *), void *arg, size_t stack_sz); +void uthread_free_all(void); +/* Returns false when all threads are done */ +bool uthread_schedule(void); + +#else + +static inline int uthread_create(void (*fn)(void *), void *arg, size_t stack_sz) +{ + fn(arg); + return 0; +} + +static inline void uthread_free_all(void) { } + +static inline bool uthread_schedule(void) { return false; } + +#endif /* CONFIG_UTHREAD */ +#endif /* _UTHREAD_H_ */ diff --git a/lib/Kconfig b/lib/Kconfig index 1a683dea670..c3416bbd0be 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -1255,6 +1255,25 @@ config PHANDLE_CHECK_SEQ enable this config option to distinguish them using phandles in fdtdec_get_alias_seq() function. +config UTHREAD + bool "Enable thread support" + depends on HAVE_INITJMP + help + Implement a simple form of cooperative multi-tasking based on + context-switching via initjmp(), setjmp() and longjmp(). The + uthread_ interface enables the main thread of execution to create + one or more secondary threads and schedule them until they all have + returned. At any point a thread may suspend its execution and + schedule another thread, which allows for the efficient multiplexing + of leghthy operations. + +config UTHREAD_STACK_SIZE + int "Default uthread stack size" + depends on UTHREAD + default 32168 + help + The default stask size for uthreads. Each uthread has its own stack. + endmenu source "lib/fwu_updates/Kconfig" diff --git a/lib/Makefile b/lib/Makefile index a7bc2f3134a..3610694de7a 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -164,6 +164,8 @@ obj-$(CONFIG_LIB_ELF) += elf.o obj-$(CONFIG_$(PHASE_)SEMIHOSTING) += semihosting.o +obj-$(CONFIG_UTHREAD) += uthread.o + # # Build a fast OID lookup registry from include/linux/oid_registry.h # diff --git a/lib/uthread.c b/lib/uthread.c new file mode 100644 index 00000000000..bb132001fb6 --- /dev/null +++ b/lib/uthread.c @@ -0,0 +1,107 @@ +// SPDX-License-Identifier: GPL-2.0-only +// +// Copyright (C) 2021 Ahmad Fatoum, Pengutronix +// Copyright (C) 2025 Linaro Limited +// +// An implementation of cooperative multi-tasking inspired from barebox threads +// https://github.com/barebox/barebox/blob/master/common/bthread.c + +#include +#include +#include +#include +#include +#include +#include + +static struct uthread { + void (*fn)(void *); + void *arg; + jmp_buf ctx; + void *stack; + bool done; + struct list_head list; +} main_thread = { + .list = LIST_HEAD_INIT(main_thread.list), +}; + +static struct uthread *current = &main_thread; + +static void __noreturn uthread_trampoline(void) +{ + current->fn(current->arg); + current->done = true; + current = &main_thread; + longjmp(current->ctx, 1); + /* Not reached */ + while (true) + ; +} + +static void uthread_free(struct uthread *uthread) +{ + if (!uthread) + return; + free(uthread->stack); + free(uthread); +} + +int uthread_create(void (*fn)(void *), void *arg, size_t stack_sz) +{ + struct uthread *uthread; + + if (!stack_sz) + stack_sz = CONFIG_UTHREAD_STACK_SIZE; + + uthread = calloc(1, sizeof(*uthread)); + if (!uthread) + return -1; + + uthread->stack = memalign(16, stack_sz); + if (!uthread->stack) + goto err; + + uthread->fn = fn; + uthread->arg = arg; + + list_add_tail(&uthread->list, ¤t->list); + + initjmp(uthread->ctx, uthread_trampoline, uthread->stack + stack_sz); + + return 0; +err: + uthread_free(uthread); + return -1; +} + +void uthread_free_all(void) +{ + struct uthread *next; + struct uthread *tmp; + + list_for_each_entry_safe(next, tmp, ¤t->list, list) { + list_del(&next->list); + uthread_free(next); + } +} + +static void uthread_resume(struct uthread *uthread) +{ + if (!setjmp(current->ctx)) { + current = uthread; + longjmp(uthread->ctx, 1); + } +} + +bool uthread_schedule(void) +{ + struct uthread *next; + + list_for_each_entry(next, ¤t->list, list) { + if (!next->done) { + uthread_resume(next); + return true; + } + } + return false; +} From patchwork Fri Feb 14 14:00:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 865101 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:1568:b0:38f:210b:807b with SMTP id 8csp170048wrz; Fri, 14 Feb 2025 06:02:10 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVXNArbLxKpJUOBOGwPXPgAKLmPW4zsTFZKL7DGmjrMiEAL8UkA86KtHtJomNOaai+34JT4iw==@linaro.org X-Google-Smtp-Source: AGHT+IEl+jrkY+BGQkvwPuo3cTib9ruQG0LjvBzgQUmTF6evQrLTLKYVXlQBeMA/h4L9gVtuH+Nc X-Received: by 2002:a05:6000:144b:b0:38d:e0a9:7e5e with SMTP id ffacd0b85a97d-38f24ce7791mr9353920f8f.6.1739541729154; Fri, 14 Feb 2025 06:02:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1739541729; cv=none; d=google.com; s=arc-20240605; b=Mp/t8brvDTpvP4f6SUXBMhggyZ+lkMwWgKn8dr3QUoHrPxXxWWWEN0n3Of0Iy9FayD gFJff1kBrfxEKhmkiklaZ96XcqkIc4OwDQi6+Ye01LJcYNxVI+m76v14ZxpFBSklMc6H WfaWNaNGYHLuF93L6ghpwQ+ClY9AwDGFU3aROKeHCyZ/ceVsSiqdxa2Z/qxTfyOWRedM cHYpq84t9eiaz/XpPz9PiWwRE8HARuxMj1D/niQlOaxsp/rp32Sy2ypdUr5fOsRp4uql 0m3lcUTsHRCOWS9JHXsM+WWZe3NgyMJM7jNYQyKcMBVlSZbYm9iODAy3O1YRthgBjIjI t3Zg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=WsZGwPqorEyyIVDUz+JMZwFYfCF74UByryXvgOhuuVY=; fh=WSXgq+dxaJSHadwMDVBKq11PIkESctA8ND/ZfWAV8a0=; b=StZcC5IKTd6pig43pkIm/F/Pthqo0VsHig2vptmEQqqaZfHVTD3vTzVXLoFFHD+7Qm 2udu0WSAZoawHNUUfjxXd6ajzl3LkWclXrSyKsnZeR4rKhvbC8bW04k4NyF/BnRXeb/r jJOKCxecMqZQNPPgDvb7fQFF8zoVem0T4uu9KdTz+o43wiJyV4XWOxOwy3d0Fr+d3kK7 ykNjQAWwHQArXVixrgRG12ZntKUaG4eSfpA4kiRN9hWgnCN3vQicIEXDcQjBqVjW5XNW m5dtXFyxgDqZj4tbb5O3QMdr1lOInVuAZMdjYg/bO21v0qtwpeTOgx36m0ki1+HyIfIy ZIMQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WTXmLkPG; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id ffacd0b85a97d-38f258e10f2si4552478f8f.30.2025.02.14.06.02.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Feb 2025 06:02:09 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WTXmLkPG; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 99B4E80E94; Fri, 14 Feb 2025 15:01:09 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="WTXmLkPG"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 03B7B80F30; Fri, 14 Feb 2025 15:01:08 +0100 (CET) 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,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) (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 005ED80C83 for ; Fri, 14 Feb 2025 15:01:05 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-4394829ef0fso20028515e9.0 for ; Fri, 14 Feb 2025 06:01:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1739541665; x=1740146465; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=WsZGwPqorEyyIVDUz+JMZwFYfCF74UByryXvgOhuuVY=; b=WTXmLkPG42pPEZI1qo+1HFc9MjIzyO+rciND4+SI1Ev4iZZC8vIZaxTBOW2r1oAFhd gzWUfzyF2W8eD34qntVOon1uk8piSCQ0Zr2GTBCFuc789MKp3xjt+hkkTDFtNs7dK+h+ iBUfYIETjx3jv9ywPQuA67km2aZW5KjwEcdP/ShNH6TQ7UmkaLf8JnETuS+ZEsfSGyBh wNjEAsZ11sNLhKLUUecs1fomnkukYob+LJloyQScSmstZu/NmJ8Eu8sASoUgkqFeKnr6 hg4mL5OoDGtkse4t/p3M7SgmL0Ce76WkGKdGZdhS4qsAaEKjcb/OVsw15m+YAe7me3ZG tTIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739541665; x=1740146465; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WsZGwPqorEyyIVDUz+JMZwFYfCF74UByryXvgOhuuVY=; b=cVRMBbImYNtyizQfx6UxU8xL+14CV7nX+uqGcwrA7tGxamhrv2TakPBHBdUw3bUnqr Vs3O/auMabMtBYN238qmf5MnFiISXD+MphOYcQAX5/1ApGSS0LF1yRPInZ4jwA3f7cQU i1IeH4HubD/qhBBjEjzwGwYJULJrjCuV0YxnzyIkLcwEo/xcsBHNeTYSY17iztpy3SIa GEyov5DqTlceDkDLxMYV+lIgPiLR1632nTb2QdbwNuElsiv6fmmWiCgK3mkYv4Jabk71 ezbS/WuCpk73Xqj/nr15TstbiPSRggVRvuEyUm+CYywU9I0BDRRjSiY96qpID2NirqCO ra5A== X-Gm-Message-State: AOJu0YyF07pDS39BkA+IiiFH7v64ywb+MygUiG8BZQzvG0pnkEBnppak BGkDljeEghDzMMRXJEfJ64owTDOimirdqUqLd1Ek0rozKPw5b8ozBNRBizRt2Hdt3CVmpvyHylF UWtC9MA== X-Gm-Gg: ASbGncsGgeDvCChZyE2QkPvBUSM75t7G4/V2a4He394L9oZNZpY5Y/4IR4lovWG9Y8n sspuz/w/9WWxN5//lDEojcqHNOzwjhDs1hGwIN2KHn39kMnFMNUt9oi5Jh4cQ4Nfy1p81MXVLwl 322j6wfIbFo/pdnt4sgRaFgSSLbCD7cLrjSUITCyc2Jnmj3tKI2I0Nrx6dUSpZnzDhoWUID437R pUf5a5Aj9G3VF9yLnKqr5rcsW638oepe3VYwGB2NsK3epGlaniN5qaNCRtNDScGMd/blVDoE9Cc rgaWpV4887W4scDEn4082+mQ X-Received: by 2002:a5d:6d09:0:b0:38d:d414:124d with SMTP id ffacd0b85a97d-38f24d74196mr9250091f8f.19.1739541665009; Fri, 14 Feb 2025 06:01:05 -0800 (PST) Received: from builder.. ([2a01:e0a:3cb:7bb0:65ac:d875:2c3e:607f]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38f258fc7e0sm4666391f8f.48.2025.02.14.06.01.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Feb 2025 06:01:04 -0800 (PST) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Tom Rini , Simon Glass Subject: [RFC PATCH 07/10] lib: time: hook uthread_schedule() into udelay() Date: Fri, 14 Feb 2025 15:00:22 +0100 Message-ID: <20250214140031.484344-8-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250214140031.484344-1-jerome.forissier@linaro.org> References: <20250214140031.484344-1-jerome.forissier@linaro.org> MIME-Version: 1.0 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 Introduce a uthread scheduling call into udelay() when CONFIG_UTHREAD is enabled. This means that any uthread calling into udelay() may yield to uthread and be scheduled again later. TBD: check if udelay_yield is really necessary. Signed-off-by: Jerome Forissier --- lib/time.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/time.c b/lib/time.c index d88edafb196..55e41c92210 100644 --- a/lib/time.c +++ b/lib/time.c @@ -17,6 +17,7 @@ #include #include #include +#include #ifndef CFG_WD_PERIOD # define CFG_WD_PERIOD (10 * 1000 * 1000) /* 10 seconds default */ @@ -190,6 +191,10 @@ void __weak __udelay(unsigned long usec) /* ------------------------------------------------------------------------- */ +#if CONFIG_IS_ENABLED(UTHREAD) +int udelay_yield; +#endif + void udelay(unsigned long usec) { ulong kv; @@ -197,7 +202,17 @@ void udelay(unsigned long usec) do { schedule(); kv = usec > CFG_WD_PERIOD ? CFG_WD_PERIOD : usec; - __udelay(kv); +#if CONFIG_IS_ENABLED(UTHREAD) + if (udelay_yield == 0xCAFEDECA) { + ulong t0 = timer_get_us(); + while (timer_get_us() < t0 + kv) + uthread_schedule(); + } else { +#endif + __udelay(kv); +#if CONFIG_IS_ENABLED(UTHREAD) + } +#endif usec -= kv; } while(usec); } From patchwork Fri Feb 14 14:00:23 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 865103 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:1568:b0:38f:210b:807b with SMTP id 8csp170393wrz; Fri, 14 Feb 2025 06:02:33 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXUgtA8x75bdUA19J8GCcj9LANjUzSSjmaGYuo7SrWqGHnRV5c5HLcNdR4l6EWejMVzV10qRQ==@linaro.org X-Google-Smtp-Source: AGHT+IEMd0a8arGJvAVrKUakE+p/28DrKozWv57bHlCnQWwps8/ihc1gZoVd2SA49Q37WttOrbjT X-Received: by 2002:a5d:64ec:0:b0:38d:ba8e:7327 with SMTP id ffacd0b85a97d-38f24f2bac1mr9841271f8f.8.1739541752701; Fri, 14 Feb 2025 06:02:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1739541752; cv=none; d=google.com; s=arc-20240605; b=YErEhQTi9SLOVxUN5gIKR8OwLu3nO4+X7QkhdK/3Zc2k+59eLywRt5jN53K+kJ9Scb ShmUbA0sNjBmOUedNmSZdJ2el3/3IQlb5i3fK5YNokL+m15h7b+lLdyqXS9JqxeECKpp g2YaozkRNeJ7VhcZqKC0SWbgwbWRYy6AQTDyXPI0DoTWEfPsWAAHBEurFc1LKCtHW9jI Cp7LZ6VKi0FpiTH3XtYCTDLCp2Ea0pybEMRpJclp5Gy8aqTD3kcCfoQvnoAxsp60CM2+ F2QtQDhlp/9BzlumfEs5RjZxUof9jm4hDqvJEzDFQuNFlVHUojzuuJ/RecwxzyNPkT6E gtxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Utnn1RiTgA8y5KAA6XU2ZUyWE7GhPINWCZVBuQFSuLE=; fh=fR0UVWovEQaeizUbW6NYRhJaKj1baCbm+MM7JESBVRo=; b=k6MPvBc4CW1mSALRCRODvfatN8lKlSm3Ev4m86qlFwKJ0fdWIG+CKBf9UN15es5yER mflxi0ka76mrGnq9hd/OYTJtBeFupiU6KrY1CbIuIWo4VwF9+8RTtrK2F/PI0oW+VpQx F29rHH5444tTWBfJGBZ0hSiSdMALtivk/u9jWLbs7QpF9SKD8dj7A4rBZCqCga+eS9U3 bvgg781PbFg56XcMY4fy7Jj5tP/m3kKhTDNtjZQyHTPc3uG/wplCsj7ijfdz+xB4Jwi1 R/ybu24Eg1X2Q+Iyme5g9I4qC4L1z+c4/wRN7FOztZr7mKlONSVmzTd1XWLvlINo7c1+ OXNg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fRgT0aK3; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id ffacd0b85a97d-38f258f8cbbsi4632607f8f.192.2025.02.14.06.02.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Feb 2025 06:02:32 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fRgT0aK3; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4C13180F42; Fri, 14 Feb 2025 15:01:12 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="fRgT0aK3"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id AC7FF80F56; Fri, 14 Feb 2025 15:01:10 +0100 (CET) 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,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) (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 979DA80C83 for ; Fri, 14 Feb 2025 15:01:08 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-4394829ef0fso20028945e9.0 for ; Fri, 14 Feb 2025 06:01:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1739541668; x=1740146468; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Utnn1RiTgA8y5KAA6XU2ZUyWE7GhPINWCZVBuQFSuLE=; b=fRgT0aK3kP4sXPAFXHTRTSiwzBB9ACpd5Seh/n75f06PWC55FcRjdpw/3FsYsD6lqG oEg/b3Vh96y20siOHMZulBh0opX5MPHVuHgkuA8Eu1S6gzk5x+muwV1nRWMKS3+rirdw 5LgocY0jg1yC8mGnziktDwb5xOytzz5dt4jO5WbSF7Im2LGNBEHnmyQatuT2XS2RpjB/ QVmSctifaLC/jQ2OQX3wg4Rmc7UsrmFrJMr8dpnF7/ExY+PCJIhpVrlnFGGmDaqPnYC/ /mdw2ZLzf67MsvsCfWzURNU4bDRR3pXB3/K7Hcu3ZkGLcMHCt/UTS//YFvnsTu1FxT3y 7RNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739541668; x=1740146468; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Utnn1RiTgA8y5KAA6XU2ZUyWE7GhPINWCZVBuQFSuLE=; b=w7ilrN6PJe5DEVUez6UnBgt0NeK67csZy/4aBdVcQX4A2TWNaTlJoMptt8w4M4bXMt q6SCekxZ2EuK0DEZ9cgWZ2nCWPbhiQOcYv4hzKQrv+PjCMlDCtgqak6pSADZothzau+9 bVWZ9AKf5CBI27pfO8G8fvexTYY46DEfmwV7sKffdO9C8o0r0rD2H3eF7q9yLM333BsT ekdoTdrJO1abfyklB0xjldrdiwXAaHZCXJ/ZVdRwMJCSG0AR8kgOWKCnPD6G9OipLBFL STRj0XQTgKyW92SfEJty9kDwfhOxRWRpx1cUneAO4QOCuLd8/kRHQnc0IW6VDfp/tVXv +2wA== X-Gm-Message-State: AOJu0Yzaz4qiFjWBcaW218220FWC9AnbMptbYHs27geZ4Nz9JBVNqvrY SeykQOlw4d/k2LQKprMGxkAWH6lP4hTBRuUPC0cEZTKObvD539kvu4D9RLojXIXPc+K3VDzmUL+ dmDCCSw== X-Gm-Gg: ASbGncs9UCoWCUzI/q2dc5ydMqdVO3OlcNeld+4m8RiaZz53wRHf/WRtBQZr0zPH+XL xvg9EoGcDEjsr5rwPBjMRubJK8T/9RBe4ivi5HAeht/KNU7s2HeUgeHPOfkN8Vr8pGxKiO0V2bM ezYQ7uciQwDA/DyIXA/sa0HJy7brO8+G+a9qcNQPU1TLuHRp1mq5ZLnzbdeNTj4AJHaGn8m3Mf1 8wVDoLaSJz8sDnbJDr1xZZki1P6yMPA8mapFJ9OU5nCB4Y7NMTHeIVNXvFy8o2OUo+dKatp0i/1 Op5lKQJXaUK85rL/2H6Oxbz+ X-Received: by 2002:a5d:6f19:0:b0:386:374b:e8bc with SMTP id ffacd0b85a97d-38f24d10851mr8582269f8f.15.1739541666046; Fri, 14 Feb 2025 06:01:06 -0800 (PST) Received: from builder.. ([2a01:e0a:3cb:7bb0:65ac:d875:2c3e:607f]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38f258fc7e0sm4666391f8f.48.2025.02.14.06.01.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Feb 2025 06:01:05 -0800 (PST) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Marek Vasut , Tom Rini , Mattijs Korpershoek , Caleb Connolly , Dragan Simic , Heinrich Schuchardt Subject: [RFC PATCH 08/10] dm: usb: move bus initialization into new static function usb_init_bus() Date: Fri, 14 Feb 2025 15:00:23 +0100 Message-ID: <20250214140031.484344-9-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250214140031.484344-1-jerome.forissier@linaro.org> References: <20250214140031.484344-1-jerome.forissier@linaro.org> MIME-Version: 1.0 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 To prepare for the introduction of coroutines in the USB initialization sequence, move code out of usb_init() into a new helper function: usb_init_bus(). No functional change. Signed-off-by: Jerome Forissier --- drivers/usb/host/usb-uclass.c | 88 +++++++++++++++++++---------------- 1 file changed, 48 insertions(+), 40 deletions(-) diff --git a/drivers/usb/host/usb-uclass.c b/drivers/usb/host/usb-uclass.c index bfec303e7af..cc803241461 100644 --- a/drivers/usb/host/usb-uclass.c +++ b/drivers/usb/host/usb-uclass.c @@ -287,9 +287,55 @@ static int usb_probe_companion(struct udevice *bus) return 0; } +static int controllers_initialized; + +static void usb_init_bus(struct udevice *bus) +{ + int ret; + + /* init low_level USB */ + printf("Bus %s: ", bus->name); + + /* + * For Sandbox, we need scan the device tree each time when we + * start the USB stack, in order to re-create the emulated USB + * devices and bind drivers for them before we actually do the + * driver probe. + * + * For USB onboard HUB, we need to do some non-trivial init + * like enabling a power regulator, before enumeration. + */ + if (IS_ENABLED(CONFIG_SANDBOX) || + IS_ENABLED(CONFIG_USB_ONBOARD_HUB)) { + ret = dm_scan_fdt_dev(bus); + if (ret) { + printf("USB device scan from fdt failed (%d)", ret); + return; + } + } + + ret = device_probe(bus); + if (ret == -ENODEV) { /* No such device. */ + puts("Port not available.\n"); + controllers_initialized++; + return; + } + + if (ret) { /* Other error. */ + printf("probe failed, error %d\n", ret); + return; + } + + ret = usb_probe_companion(bus); + if (ret) + return; + + controllers_initialized++; + usb_started = true; +} + int usb_init(void) { - int controllers_initialized = 0; struct usb_uclass_priv *uc_priv; struct usb_bus_priv *priv; struct udevice *bus; @@ -305,45 +351,7 @@ int usb_init(void) uc_priv = uclass_get_priv(uc); uclass_foreach_dev(bus, uc) { - /* init low_level USB */ - printf("Bus %s: ", bus->name); - - /* - * For Sandbox, we need scan the device tree each time when we - * start the USB stack, in order to re-create the emulated USB - * devices and bind drivers for them before we actually do the - * driver probe. - * - * For USB onboard HUB, we need to do some non-trivial init - * like enabling a power regulator, before enumeration. - */ - if (IS_ENABLED(CONFIG_SANDBOX) || - IS_ENABLED(CONFIG_USB_ONBOARD_HUB)) { - ret = dm_scan_fdt_dev(bus); - if (ret) { - printf("USB device scan from fdt failed (%d)", ret); - continue; - } - } - - ret = device_probe(bus); - if (ret == -ENODEV) { /* No such device. */ - puts("Port not available.\n"); - controllers_initialized++; - continue; - } - - if (ret) { /* Other error. */ - printf("probe failed, error %d\n", ret); - continue; - } - - ret = usb_probe_companion(bus); - if (ret) - continue; - - controllers_initialized++; - usb_started = true; + usb_init_bus(bus); } /* From patchwork Fri Feb 14 14:00:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 865104 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:1568:b0:38f:210b:807b with SMTP id 8csp170498wrz; Fri, 14 Feb 2025 06:02:40 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVAHAQax5sJrhTh4RrYQmojiUGoB+HNewOz+G71o6xJ3adjkAvwRU6R9IPzUaLcz1YuBieEfQ==@linaro.org X-Google-Smtp-Source: AGHT+IFLAewk9D5E4ugJEKoZ1jHu33bKI7+mtBtjIO4iVpcW0SZht1Np0Ok35IuLXH2g/HWQlHYx X-Received: by 2002:a05:600c:310a:b0:439:46b9:325 with SMTP id 5b1f17b1804b1-439581ca5c0mr114064945e9.26.1739541759962; Fri, 14 Feb 2025 06:02:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1739541759; cv=none; d=google.com; s=arc-20240605; b=AYBighouVv3nQh3sz/C+TZ+vfaMLPcejdKD9jgFbo2psT+4AgycMzsW2NN5EMlw880 lkikCsJuyuYQqCPNt5/ajzLgIQgm0ZiIm/zLxwzkV+G/cy2FZVTOq3ki3Wg5sIx5hm1G V1UdrechYm0FRM9cZoiBLS9phlliutQ7UhSpGX4gQgqdnoUTbbBwQzDAe3ftMskdRwTw VzzqF39a4re0hyFc2LEUWIDoFOVDFaukcy5Q9CE5sibsFE55TyIFRySIf/kaLdHleHNg 2shkmvy3MvgA/kpMEZtBXGj6w0/3SKOr8LqVnFeGItlMapJ0roV8Mc6KQ33oczh7dIEE Tvpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=LYFOqE5NmJ4XXQy/WhbiSVaIyZeC2lUXjTfLpdD0Ky8=; fh=O/nFA/EbThK+69UbO/58FcY+e8SZ1SxsFcdF/GIe8iY=; b=lVhH6eslKK5mKwvZd/xNH/iVquanMxv/Oa9Ch4bAZhoMLAaRhiGhE5yJKPhgeIHtRE WBfbQGyY6rE8X/r/GTF8LpfYelz9x46A5r4rVAC9tg1NFKDspPInM+FyKd0kG1X6aiTE Gv7kQeUOvGpsrNXl/prq6GC38nH8M8YiOINCXzRhr1OuCqpemPQHAUjUT8Shn78S5em4 onJ/w1p5O8L8LucatboEmmqKnGo7mqTMTQmX/NfwBpNLqYXHF5dg9TtRkppckg1w4lO1 SiTy7rrIWg1HZ9Q997v0+OkQYRklJ3F81rtfLnprQIsU1gFhPq9rFaQ9H88GBssv0ngo c/qg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GNcEUalW; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id 5b1f17b1804b1-43959d495f1si61327365e9.42.2025.02.14.06.02.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Feb 2025 06:02:39 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GNcEUalW; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 98F5780C96; Fri, 14 Feb 2025 15:01:14 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="GNcEUalW"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D668880F62; Fri, 14 Feb 2025 15:01:11 +0100 (CET) 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,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) (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 1F9DA80F30 for ; Fri, 14 Feb 2025 15:01:09 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-38dd14c99c3so1024850f8f.3 for ; Fri, 14 Feb 2025 06:01:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1739541668; x=1740146468; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LYFOqE5NmJ4XXQy/WhbiSVaIyZeC2lUXjTfLpdD0Ky8=; b=GNcEUalWls9qqcf2bXWsyN2/dZrDD6aOWjnobrLv2WIe2f5xDGM/WQAUkeDEB+LNKA dy93h8rQEKYoGiDpVRgfodwGs2r/hQKbaQy/GE8ABST3uhRpb2v3r0xDQZg633sbepam UTo5Nb5VbsVJ7P73CsdUd9SS6QmZZSw1IXtWdunaLLNQBxPi+6wyVeSx9JFNAJtToMG2 gEZ13ypfzlGImUM3eA5UPuVqUhbm+w1LCcKjQndhxVVhfrAO9zD4aAC9R8ZNqNX/ysz9 jQSEwrJBGUAKOVOTWHCwN17IkZ47YG6CnNlir45kYCKXDzk/0P05OL0OP+g28HcX4bOv AE1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739541668; x=1740146468; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LYFOqE5NmJ4XXQy/WhbiSVaIyZeC2lUXjTfLpdD0Ky8=; b=X5MNomuTdgaWDFspM6UjWjT3lkWyv/tOvi46DO9PE5cKkj0OUm/a4xc6DwkthPzKui lkP2K0kE5HmSpct+uFr8rfnsUSvL+/u8xYgfiC7wzbgPepkwK/KjnsAK+R+nRmyY+lRt E6meawyjHsrtbp8StFnH8DRWJvqAqNi3swHuoJthm/p4n/ZjNzYusDY39IBeqbrwY4rV IfS6bV4gPKf9mkT4u4jXURWGqzSdQiECeNKWGpULJYLALd3lqPgC6dzQxcbEqyiQhB4G CCeAA86dk9hD6KlxMyuwYYBfUb3zzxmap0eOtDQjhQzT/bbJGbWjEtFmvzjLA+Qanhej mULQ== X-Gm-Message-State: AOJu0YxJ5MpBcFZ8Lud+t/+DFizpQnB6opZ2Srp8jJJ34sayJ8CopHRh mV81I6Wd6MA1NuFBf38dRBZvmiCHFQhHCv9Y3dtzbaGp6Pm/QlOaWtisQnYFRYeAU5nOmHdkUFj +7HDPjQ== X-Gm-Gg: ASbGnctxIPB7ffqHV59osYdecdZPbK8zPw+jMllJMeSITRtPZvfEeIejvNg5ji+DCRY R3fpFiVbq5aW0HeKEMKWs7XoZxgBOZwzmxkMVYyCKJTboprlIy/tBDpULYQPpAQkVfYf2HC7Smd 8vdB5DteyXgJQozSo3KV76R8tVdoRTbBnSKI0Xu6ijvFfbvR1x2ATCUOoB/qxQgc1dLQeh/AYfO aoWKVWJElw84vY3IHP7MDj/11wUUhl6NIDvAkT9H//0lxsSZN6x0a+DdYOc6IqU2fn2CRGD1Mr0 l8n5JqOuiR9P+rI+YbYpx0HN X-Received: by 2002:a5d:6d0e:0:b0:38a:5a37:4a46 with SMTP id ffacd0b85a97d-38dea26eafamr11348238f8f.17.1739541667185; Fri, 14 Feb 2025 06:01:07 -0800 (PST) Received: from builder.. ([2a01:e0a:3cb:7bb0:65ac:d875:2c3e:607f]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38f258fc7e0sm4666391f8f.48.2025.02.14.06.01.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Feb 2025 06:01:06 -0800 (PST) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Marek Vasut , Tom Rini , Simon Glass , Mattijs Korpershoek , Dragan Simic , Caleb Connolly , Heinrich Schuchardt , Julius Lehmann , Guillaume La Roque Subject: [RFC PATCH 09/10] dm: usb: initialize and scan multiple buses simultaneously with uthread Date: Fri, 14 Feb 2025 15:00:24 +0100 Message-ID: <20250214140031.484344-10-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250214140031.484344-1-jerome.forissier@linaro.org> References: <20250214140031.484344-1-jerome.forissier@linaro.org> MIME-Version: 1.0 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 Use the uthread framework to initialize and scan USB buses in parallel for better performance. Tested on two platforms: 1. arm64 QEMU on a somewhat contrived example (4 USB buses, each with one audio device, one keyboard, one mouse and one tablet) $ make qemu_arm64_defconfig $ make -j$(nproc) CROSS_COMPILE="ccache aarch64-linux-gnu-" $ qemu-system-aarch64 -M virt -nographic -cpu max -bios u-boot.bin \ $(for i in {1..4}; do echo -device qemu-xhci,id=xhci$i \ -device\ usb-{audio,kbd,mouse,tablet},bus=xhci$i.0; \ done) 2. i.MX93 EVK (imx93_11x11_evk_defconfig) with two USB hubs, each with one webcam and one ethernet adapter, resulting in the following device tree: USB device tree: 1 Hub (480 Mb/s, 0mA) | u-boot EHCI Host Controller | +-2 Hub (480 Mb/s, 100mA) | GenesysLogic USB2.1 Hub | +-3 Vendor specific (480 Mb/s, 350mA) | Realtek USB 10/100/1000 LAN 001000001 | +-4 (480 Mb/s, 500mA) HD Pro Webcam C920 8F7CD51F 1 Hub (480 Mb/s, 0mA) | u-boot EHCI Host Controller | +-2 Hub (480 Mb/s, 100mA) | USB 2.0 Hub | +-3 Vendor specific (480 Mb/s, 200mA) | Realtek USB 10/100/1000 LAN 000001 | +-4 (480 Mb/s, 500mA) Generic OnLan-CS30 201801010008 Note that i.MX was tested on top of the downstream repository [1] since USB doesn't work in the upstream master branch. [1] https://github.com/nxp-imx/uboot-imx/tree/lf-6.6.52-2.2.0 commit 6c4545203d12 ("LF-13928 update key for capsule") The time spent in usb_init() ("usb start" command) is reported on the console. Here are the results: | CONFIG_UTHREAD=n | CONFIG_UTHREAD=y --------+------------------+----------------- QEMU | 5628 ms | 2212 ms i.MX93 | 4591 ms | 2441 ms Signed-off-by: Jerome Forissier --- drivers/usb/host/usb-uclass.c | 89 ++++++++++++++++++++++++++++------- test/boot/bootdev.c | 14 +++--- test/boot/bootflow.c | 3 +- 3 files changed, 82 insertions(+), 24 deletions(-) diff --git a/drivers/usb/host/usb-uclass.c b/drivers/usb/host/usb-uclass.c index cc803241461..eedf4e1c3fb 100644 --- a/drivers/usb/host/usb-uclass.c +++ b/drivers/usb/host/usb-uclass.c @@ -9,6 +9,7 @@ #define LOG_CATEGORY UCLASS_USB #include +#include #include #include #include @@ -17,6 +18,7 @@ #include #include #include +#include static bool asynch_allowed; @@ -221,25 +223,18 @@ int usb_stop(void) return err; } -static void usb_scan_bus(struct udevice *bus, bool recurse) +static void _usb_scan_bus(void *arg) { + struct udevice *bus = (struct udevice *)arg; struct usb_bus_priv *priv; struct udevice *dev; int ret; priv = dev_get_uclass_priv(bus); - assert(recurse); /* TODO: Support non-recusive */ - - printf("scanning bus %s for devices... ", bus->name); - debug("\n"); ret = usb_scan_device(bus, 0, USB_SPEED_FULL, &dev); if (ret) - printf("failed, error %d\n", ret); - else if (priv->next_addr == 0) - printf("No USB Device found\n"); - else - printf("%d USB Device(s) found\n", priv->next_addr); + printf("Scanning bus %s failed, error %d\n", bus->name, ret); } static void remove_inactive_children(struct uclass *uc, struct udevice *bus) @@ -289,12 +284,12 @@ static int usb_probe_companion(struct udevice *bus) static int controllers_initialized; -static void usb_init_bus(struct udevice *bus) +static void _usb_init_bus(void *arg) { + struct udevice *bus = (struct udevice *)arg; int ret; /* init low_level USB */ - printf("Bus %s: ", bus->name); /* * For Sandbox, we need scan the device tree each time when we @@ -309,20 +304,21 @@ static void usb_init_bus(struct udevice *bus) IS_ENABLED(CONFIG_USB_ONBOARD_HUB)) { ret = dm_scan_fdt_dev(bus); if (ret) { - printf("USB device scan from fdt failed (%d)", ret); + printf("Bus %s: USB device scan from fdt failed (%d)\n", + bus->name, ret); return; } } ret = device_probe(bus); if (ret == -ENODEV) { /* No such device. */ - puts("Port not available.\n"); + printf("Bus %s: Port not available.\n", bus->name); controllers_initialized++; return; } if (ret) { /* Other error. */ - printf("probe failed, error %d\n", ret); + printf("Bus %s: probe failed, error %d\n", bus->name, ret); return; } @@ -334,8 +330,57 @@ static void usb_init_bus(struct udevice *bus) usb_started = true; } +#if CONFIG_IS_ENABLED(UTHREAD) +extern int udelay_yield; +#endif +static int nthr; + +static void usb_init_bus(struct udevice *bus) +{ + if (!uthread_create(_usb_init_bus, (void *)bus, 0)) + nthr++; +} + +static void usb_scan_bus(struct udevice *bus, bool recurse) +{ + if (!uthread_create(_usb_scan_bus, (void *)bus, 0)) + nthr++; +} + +static void usb_report_devices(struct uclass *uc) +{ + struct usb_bus_priv *priv; + struct udevice *bus; + + uclass_foreach_dev(bus, uc) { + if (!device_active(bus)) + continue; + priv = dev_get_uclass_priv(bus); + printf("Bus %s: ", bus->name); + if (priv->next_addr == 0) + printf("No USB Device found\n"); + else + printf("%d USB Device(s) found\n", priv->next_addr); + } +} + +static void run_threads(void) +{ +#if CONFIG_IS_ENABLED(UTHREAD) + if (!nthr) + return; + udelay_yield = 0xCAFEDECA; + while (uthread_schedule()) + /* Nothing */; + udelay_yield = 0; + uthread_free_all(); + nthr = 0; +#endif +} + int usb_init(void) { + unsigned long t0 = timer_get_us(); struct usb_uclass_priv *uc_priv; struct usb_bus_priv *priv; struct udevice *bus; @@ -354,6 +399,9 @@ int usb_init(void) usb_init_bus(bus); } + if (CONFIG_IS_ENABLED(UTHREAD)) + run_threads(); + /* * lowlevel init done, now scan the bus for devices i.e. search HUBs * and configure them, first scan primary controllers. @@ -367,6 +415,9 @@ int usb_init(void) usb_scan_bus(bus, true); } + if (CONFIG_IS_ENABLED(UTHREAD)) + run_threads(); + /* * Now that the primary controllers have been scanned and have handed * over any devices they do not understand to their companions, scan @@ -383,7 +434,10 @@ int usb_init(void) } } - debug("scan end\n"); + if (CONFIG_IS_ENABLED(UTHREAD)) + run_threads(); + + usb_report_devices(uc); /* Remove any devices that were not found on this scan */ remove_inactive_children(uc, bus); @@ -397,6 +451,9 @@ int usb_init(void) if (controllers_initialized == 0) printf("No USB controllers found\n"); + debug("USB initialized in %ld ms\n", + (timer_get_us() - t0) / 1000); + return usb_started ? 0 : -ENOENT; } diff --git a/test/boot/bootdev.c b/test/boot/bootdev.c index 8c44afd9297..956320f1daa 100644 --- a/test/boot/bootdev.c +++ b/test/boot/bootdev.c @@ -393,8 +393,8 @@ static int bootdev_test_hunter(struct unit_test_state *uts) ut_assert_console_end(); ut_assertok(bootdev_hunt("usb1", false)); - ut_assert_nextline( - "Bus usb@1: scanning bus usb@1 for devices... 5 USB Device(s) found"); + ut_assert_skip_to_line( + "Bus usb@1: 5 USB Device(s) found"); ut_assert_console_end(); /* USB is 7th in the list, so bit 8 */ @@ -449,8 +449,8 @@ static int bootdev_test_cmd_hunt(struct unit_test_state *uts) ut_assert_nextline("scanning bus for devices..."); ut_assert_skip_to_line("Hunting with: spi_flash"); ut_assert_nextline("Hunting with: usb"); - ut_assert_nextline( - "Bus usb@1: scanning bus usb@1 for devices... 5 USB Device(s) found"); + ut_assert_skip_to_line( + "Bus usb@1: 5 USB Device(s) found"); ut_assert_nextline("Hunting with: virtio"); ut_assert_console_end(); @@ -551,8 +551,8 @@ static int bootdev_test_hunt_prio(struct unit_test_state *uts) ut_assertok(bootdev_hunt_prio(BOOTDEVP_5_SCAN_SLOW, true)); ut_assert_nextline("Hunting with: ide"); ut_assert_nextline("Hunting with: usb"); - ut_assert_nextline( - "Bus usb@1: scanning bus usb@1 for devices... 5 USB Device(s) found"); + ut_assert_skip_to_line( + "Bus usb@1: 5 USB Device(s) found"); ut_assert_console_end(); return 0; @@ -604,7 +604,7 @@ static int bootdev_test_hunt_label(struct unit_test_state *uts) ut_assertnonnull(dev); ut_asserteq_str("usb_mass_storage.lun0.bootdev", dev->name); ut_asserteq(BOOTFLOW_METHF_SINGLE_UCLASS, mflags); - ut_assert_nextlinen("Bus usb@1: scanning bus usb@1"); + ut_assert_nextline("Bus usb@1: 5 USB Device(s) found"); ut_assert_console_end(); return 0; diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c index a8735c1c23d..67ee1777d01 100644 --- a/test/boot/bootflow.c +++ b/test/boot/bootflow.c @@ -1289,8 +1289,9 @@ static int bootflow_efi(struct unit_test_state *uts) bootstd_reset_usb(); ut_assertok(run_command("bootflow scan", 0)); + ut_assert_skip_to_line( - "Bus usb@1: scanning bus usb@1 for devices... 5 USB Device(s) found"); + "Bus usb@1: 5 USB Device(s) found"); ut_assertok(run_command("bootflow list", 0)); From patchwork Fri Feb 14 14:00:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 865105 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:1568:b0:38f:210b:807b with SMTP id 8csp170640wrz; Fri, 14 Feb 2025 06:02:50 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUhi1c74dRPHL5NoReCTB3CgJ89CLYh45RKvOOroPCuzcInNqhcQDImwTMYC6WbVAQpXXCX0Q==@linaro.org X-Google-Smtp-Source: AGHT+IFgBduo3DM+SY6n+2WimlFVIyR7gNcDHpkm86zTg0eySuQWHTs/HQguUDfL9W6ji6jKVhTY X-Received: by 2002:a05:6000:1ac8:b0:38e:ae25:6d66 with SMTP id ffacd0b85a97d-38f244e4874mr9316472f8f.19.1739541769829; Fri, 14 Feb 2025 06:02:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1739541769; cv=none; d=google.com; s=arc-20240605; b=XlZJi82XmJCL7mCDfSgdF1bLlCMmTOcy+aSuQ5FlCNudSHrS/6jUxDxYF6T7CTcOhr sh/McVoooNJmyX9j7kLVEUFk0fM3g7adNIcpyftTib/H6t78zaBgKY+ntMrw2aMF5nLR Q9NRYtKJAtQI/XKLp3hq/DjgfYeEjk7X/z0l8UE0IhpX/hPE90Si1IdsfOdvFAOYXayD pKDYaJaBfJZkS1KSMNFOqhU++Njke8gDkXqS7fvd7nl3xp9VkNRbQ+3L7xXp9WexpF8v YH6lnBaLO9WAHnG/UUXMP62YsysjItH/RPjbUPuYBPa5XdB+f1/+ab3ffIygajou62LB 3gTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=vw5QNJq6rc3BmUwd+FgBXihOmD2gLyqDw2aIcses8Oc=; fh=Jew6Njx5SZzV76Z+XfelCXw/h2sdJWu6FVVJm8KM3pI=; b=PGPzJlceHqu3JT9tLguwP6lj981hJHHuOygVwj/8fElGimnFzT9FG7H02Fu1a6GZbT lUCFrckBsXdK2FCO4B9y8Ts5/DxdF62W6PNE87B039XwFi0DCN3rJGDnsZp0jxW1G+k7 e3OROHqP7iChzDeJdwTvtk7YxKRfdiFS0zld2jyU3Js8Yr5gVG5ZvvUutFXDMU9ouxn7 H9pJml4/G5bfcHPDWSRCCGxuhwX8lHSJYL0HUOyLif7kls3c8S23/xiV0Mf8roOE0hc2 xY8KqwoDQ4QHSUXnsLcm4NuREqJ61u46RM7t+KcDEZekqcbViW87f3kGaZsmON/9V0M6 XUgA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=R7l5uCgC; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id ffacd0b85a97d-38f25a1024esi4588975f8f.629.2025.02.14.06.02.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Feb 2025 06:02:49 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=R7l5uCgC; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E7EAB80F4E; Fri, 14 Feb 2025 15:01:14 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="R7l5uCgC"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 41B2E80F30; Fri, 14 Feb 2025 15:01:12 +0100 (CET) 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,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) (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 21ADB80F42 for ; Fri, 14 Feb 2025 15:01:10 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-38de17a5fc9so1119847f8f.3 for ; Fri, 14 Feb 2025 06:01:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1739541669; x=1740146469; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vw5QNJq6rc3BmUwd+FgBXihOmD2gLyqDw2aIcses8Oc=; b=R7l5uCgCzIaStf8A5dmtSr8Y4RY2cCVVQ5wzy7GsXAzODZv7UrPCvqSyC5Hg+vW03W iARmZhQ9uhAxLcguOSKp15Rrfd5zJUZqZwT+Aj7k9e0U3Es3OKSb00pgB5cVluV+r/LM 6CqzAm4dTv/+Mk1A2cjd9cu/rLssvvYMaLMaW/baqj+CKMcWRs7NhAV3vf1R4A3diUxX JZpLHwYpaisS00a1nqrxNwVu0wOT+93uJuyTU4fd7+GSEFglVyOTHGto//tSdVh4/4r/ G9KYQW0nmOiYkmWB3FEwklnRx56Yg1kpFed7bnXXiqATeJ9Br1WY25+fgAUWq4f+031W M5Dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739541669; x=1740146469; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vw5QNJq6rc3BmUwd+FgBXihOmD2gLyqDw2aIcses8Oc=; b=A++W8PJ4urZudVmv0uU5isgYw+R8VWUyTokHX7/E47JDUfiWhkCD8Gv1n1ZzJZlVL3 0pLx2dJ7JeXh6guG77Phrz/0sRGqsVmMJiqvpj/Pgh7QrihcG2YfrSvCvMPms2u8P314 ZbbPCoOiHPanNoSlowVpqRdCw6Y/4jOnDCMNaKpBto9tGE8s3zUlc6bNLdxoz9WRsTRJ GavpjDXckRtU9Zpl2CdV3zALiXC6Ah7lKktwVALovhYrb+9UGczPMaS+ZmX8Z3+kCrSv j8aGi3PrmValYJQ1VnO7AooCODyoBTepDyi85p9zkQyxe+p1PQ4fGNNBy/aNydQNfOdm tvAg== X-Gm-Message-State: AOJu0Yz9ZGZwrvUUjmyP7Z5WJ+NOnE7s5kfqF5xVeXTeZqezBLZUAeiE ptCQ+5CumoPEdzdpQEBxcoD8VAEBcuXyT5Lc5Jc4FQBlm9Ph3lywScWso1C0rR2MnI9KAF16amr xQ2p9IQ== X-Gm-Gg: ASbGncucxZIn1bHj86QNbf8rhmeDNajmvWrZGlyEitxPunhV9pvNLhGfHNp6dDzQpT2 ap1VVaMKAXixxt2PIykpL4fqshhCQSQfG/tAWCpdURL1z54xiJT+Jg+f3anchEVRMFgMl/XyPcl 9KrjokMgxu6Z8Gi/sBr/WcI+5Vp5M7WU2X4opddz/t9bdZD83/6SCCATciQdEDBia9az/dog3j8 7iQ+rCr4dvXsalQaQhfstF6WDK9P1n4fUdTqKVubLbmuAuYlAshr9MsNVZPQzWQ7Dh1BTnXouF7 6y+gjyjtqh2X9TBPf5r1JJKJ X-Received: by 2002:a05:6000:1f81:b0:38a:8ed1:c5c7 with SMTP id ffacd0b85a97d-38f24528db4mr8934108f8f.46.1739541669158; Fri, 14 Feb 2025 06:01:09 -0800 (PST) Received: from builder.. ([2a01:e0a:3cb:7bb0:65ac:d875:2c3e:607f]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38f258fc7e0sm4666391f8f.48.2025.02.14.06.01.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Feb 2025 06:01:08 -0800 (PST) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Tom Rini , Simon Glass , Heinrich Schuchardt , Raymond Mao , Philippe Reynes Subject: [RFC PATCH 10/10] test: lib: add uthread test Date: Fri, 14 Feb 2025 15:00:25 +0100 Message-ID: <20250214140031.484344-11-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250214140031.484344-1-jerome.forissier@linaro.org> References: <20250214140031.484344-1-jerome.forissier@linaro.org> MIME-Version: 1.0 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 Test uthread scheduling. Signed-off-by: Jerome Forissier --- lib/uthread.c | 3 ++- test/lib/Makefile | 1 + test/lib/uthread.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 test/lib/uthread.c diff --git a/lib/uthread.c b/lib/uthread.c index bb132001fb6..1f8e6d0fa80 100644 --- a/lib/uthread.c +++ b/lib/uthread.c @@ -76,10 +76,11 @@ err: void uthread_free_all(void) { + struct uthread *main = &main_thread; struct uthread *next; struct uthread *tmp; - list_for_each_entry_safe(next, tmp, ¤t->list, list) { + list_for_each_entry_safe(next, tmp, &main->list, list) { list_del(&next->list); uthread_free(next); } diff --git a/test/lib/Makefile b/test/lib/Makefile index bf04685dae1..c991dff1c63 100644 --- a/test/lib/Makefile +++ b/test/lib/Makefile @@ -31,6 +31,7 @@ obj-$(CONFIG_CRC8) += test_crc8.o obj-$(CONFIG_UT_LIB_CRYPT) += test_crypt.o obj-$(CONFIG_UT_TIME) += time.o obj-$(CONFIG_$(XPL_)UT_UNICODE) += unicode.o +obj-$(CONFIG_UTHREAD) += uthread.o obj-$(CONFIG_LIB_UUID) += uuid.o else obj-$(CONFIG_SANDBOX) += kconfig_spl.o diff --git a/test/lib/uthread.c b/test/lib/uthread.c new file mode 100644 index 00000000000..c9d030dc778 --- /dev/null +++ b/test/lib/uthread.c @@ -0,0 +1,58 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2025 Linaro Limited + * + * Unit test for uthread + */ + +#include +#include +#include +#include + +static int count; + +static void worker(void *arg) +{ + int loops = (int)(unsigned long)arg; + int i; + + for (i = 0; i < loops; i++) { + count++; + uthread_schedule(); + } +} + +static int lib_uthread(struct unit_test_state *uts) +{ + int i; + + count = 0; + ut_assertok(uthread_create(worker, (void *)5, 0)); + ut_assertok(uthread_create(worker, (void *)10, 0)); + /* + * The first call is expected to schedule the first worker, which will + * schedule the second one, which will schedule back to the main thread + * (here). Therefore count should be 2. + */ + ut_assert(uthread_schedule()); + ut_asserteq(2, count); + /* Four more calls should bring the count to 10 */ + for (i = 0; i < 4; i++) + ut_assert(uthread_schedule()); + ut_asserteq(10, count); + /* This one allows the first worker to exit */ + ut_assert(uthread_schedule()); + /* Five more calls for the second worker to finish incrementing */ + for (i = 0; i < 5; i++) + ut_assert(uthread_schedule()); + ut_asserteq(15, count); + /* Plus one call to let the second worker return from its entry point */ + ut_assert(uthread_schedule()); + /* Now both tasks should be done, schedule should return false */ + ut_assert(!uthread_schedule()); + uthread_free_all(); + + return 0; +} +LIB_TEST(lib_uthread, 0);