From patchwork Fri Feb 2 19:59:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 196013 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp667580dyc; Fri, 2 Feb 2024 12:00:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IEujkHrXzlzGwk0YRgmDj1P5D0bSAJ9NbvnUXd23EGk+6yRNjC0/GoVHAqohF/X8hi94GUB X-Received: by 2002:a05:6a20:b811:b0:19e:44c9:cdd4 with SMTP id fi17-20020a056a20b81100b0019e44c9cdd4mr2526839pzb.14.1706904014755; Fri, 02 Feb 2024 12:00:14 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706904014; cv=pass; d=google.com; s=arc-20160816; b=yvFao6f1zB+ETls+mGdga4QOXR4mzNtT/uxHWF9v32sDO/4c3DFSIg3aN/eoTwZVyr Iy8XUq6EZwl1DFSDrHDuRSM4cS54uYiZf8Jvrrg/aDip97b+IEmXEjbfVEnkEPyFeJ0j OexhZHCatL9zpPc6XP3Ar2t46vjyu5Yb4yGdpBiAlZuatOthcYGqqNcLM+8NiLJSxC4a wZsLfuz2F8y/t5VIqPRIlNu6QW+oF7S6I5dQKPRwM4jAGEAXEfpRent9mF//DXRDpqb3 NdgAmqLbaQmWmrS/J8+XXYT85koHs189C6YSbBjOxjbprBpojRzI6VauVHJi3fqIz4H0 iUqg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=txjo7axD3IOMj2sG8qZ7bqcXfpbTutPS/3Sn6RhFLnE=; fh=YMou7Fs6yeNU5V2t0zpuDInc1hQp8BYB3JHNQzBDoBs=; b=zUR85eLdh0rFXBBJK+4ebiWtv/6J4uJUGPpHxy/itjpLOC2+LT3lWtXH3RksU6Q7Qf Yqy6VQjLudQiaRGcGmSlnG+KxGcde8keQW4qhSJlZbopJLLVo8TcL/CRjp0IrW2dvCWH U+PFcIPvlNiEqNA6bvjQLcz9NVomP3hA2Yy7Aa3irtuvlUYQM7+kYLUhOWQsjilfb6f1 bc9zzywYwd42fotUJjV5+W7E6LRp4zPYE5eWODEH7op/KzOrRPNAFFLjqnwtJRQ7pdZm lVlL/Pd9860+vqXvYAe5Rb/DR4jhDJrBNZeeWNdF+icZZHAL0f+4kgyNuwQDR05s4VVZ N8jQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lolArgXV; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-50510-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50510-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCXYXQVvAlm3pSx5mq6MNVmUSk5Xh7wlUNBeQ7mxnlCl/QhrEjgrjXV8HCs3plQ38f16Fe2pfwftII39v90KgyY2oHvUYQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id lm10-20020a056a003c8a00b006dff98a5709si1444755pfb.14.2024.02.02.12.00.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 12:00:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50510-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lolArgXV; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-50510-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50510-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 85D58287786 for ; Fri, 2 Feb 2024 20:00:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6F41783A10; Fri, 2 Feb 2024 19:59:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lolArgXV" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AFDA415E5D1; Fri, 2 Feb 2024 19:59:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706903952; cv=none; b=pYwMq01Q80au2/KoeutfK0LycXDn+c0TiZ3rY/P88CI3IYa+bnWN9C4zXqa9Zjmr3K0J8ldEPPfSbMWoXaz3TAwSFwnQ/y+w7hKMrN/Wha9vFUT0xAQAyzjY7q6CkhYSewPyhxkZhIKyS1NwL5JwXtkg8VHEPcQmU5Z6ogvx1HQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706903952; c=relaxed/simple; bh=Qt8ricOYsTKcXJqQzKSKsHiM2MHdHGBlaBkQ7xeVb1w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XFOrt6ZLOtlz7b9cZr4PxSmRlWLuusczuTSLAdkEh/bjKl4QTFmQH3G42rUq/sJWg/lH267HByjLqptev8tf2q58mmbZVEyPdOYqORfN2Ls+AjowZNcaeibRHaD4kcls7DvEEGi+J/Qy09qWYEyMM1uXdAbLutWgxUO3QHE2dRY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lolArgXV; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id D5BC6C433A6; Fri, 2 Feb 2024 19:59:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706903952; bh=Qt8ricOYsTKcXJqQzKSKsHiM2MHdHGBlaBkQ7xeVb1w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lolArgXVyTaONkcJ5g+Q0I74VOq82JrEMP+bi1sJfx15lGiKzZRLSxhR7HPZQO9o+ Vk7IRVNvNklfw0NMszumwTcFm9jgJBwhoUs6umQ55RBhjMrFu52cy4n/gJ4BbpE2HX lIg2PWCeBkrRkSrM123IFh1gZLL78hdg113f6j5P9rjYmbPOyEBq9F+7wne+BJLnAP 8ntDegcw+g3r3b7BJaeyLoqw7DvIKZXgU+luSg2rfc6tqGJZNT2rjuMRYmox0btctH Bx9iZO9QAEpH+NXjlocxZnEWB2f7RqplqHjGB7yVg/0KTomqx4izsjaFh3vB/qkVbN 8btpvM4BTB31w== From: Stephen Boyd To: Rob Herring Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, linux-um@lists.infradead.org, linux-arm-kernel@lists.infradead.org, kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, devicetree@vger.kernel.org, Frank Rowand Subject: [PATCH v3 1/7] of: Always unflatten in unflatten_and_copy_device_tree() Date: Fri, 2 Feb 2024 11:59:02 -0800 Message-ID: <20240202195909.3458162-2-sboyd@kernel.org> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog In-Reply-To: <20240202195909.3458162-1-sboyd@kernel.org> References: <20240202195909.3458162-1-sboyd@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789818584007797027 X-GMAIL-MSGID: 1789818584007797027 We want to populate an empty DT whenever CONFIG_OF is enabled so that overlays can be applied and the DT unit tests can be run. Make unflatten_and_copy_device_tree() stop printing a warning if the 'initial_boot_params' pointer is NULL. Instead, simply copy the dtb if there is one and then unflatten it. If there isn't a DT to copy, then the call to unflatten_device_tree() is largely a no-op, so nothing really changes here. Cc: Rob Herring Cc: Frank Rowand Signed-off-by: Stephen Boyd --- drivers/of/fdt.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index bf502ba8da95..dfeba8b8ce94 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -1318,6 +1318,21 @@ bool __init early_init_dt_scan(void *params) return true; } +static void *__init copy_device_tree(void *fdt) +{ + int size; + void *dt; + + size = fdt_totalsize(fdt); + dt = early_init_dt_alloc_memory_arch(size, + roundup_pow_of_two(FDT_V17_SIZE)); + + if (dt) + memcpy(dt, fdt, size); + + return dt; +} + /** * unflatten_device_tree - create tree of device_nodes from flat blob * @@ -1350,22 +1365,9 @@ void __init unflatten_device_tree(void) */ void __init unflatten_and_copy_device_tree(void) { - int size; - void *dt; + if (initial_boot_params) + initial_boot_params = copy_device_tree(initial_boot_params); - if (!initial_boot_params) { - pr_warn("No valid device tree found, continuing without\n"); - return; - } - - size = fdt_totalsize(initial_boot_params); - dt = early_init_dt_alloc_memory_arch(size, - roundup_pow_of_two(FDT_V17_SIZE)); - - if (dt) { - memcpy(dt, initial_boot_params, size); - initial_boot_params = dt; - } unflatten_device_tree(); } From patchwork Fri Feb 2 19:59:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 196014 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp667962dyc; Fri, 2 Feb 2024 12:00:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IEHEh3nYhfxSO+TDmJdS1L53GjMZ/cTU06NL0O3hg/yDsTBTNiUosV5GU6W/Wnm2lZDbfNW X-Received: by 2002:a17:902:ce8e:b0:1d7:89a8:39e8 with SMTP id f14-20020a170902ce8e00b001d789a839e8mr8315162plg.4.1706904049679; Fri, 02 Feb 2024 12:00:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706904049; cv=pass; d=google.com; s=arc-20160816; b=iPvrvPokpA3S22pJBOozb3EuOUDOLKLQlfJ+Ea6qWwAty00ZCnTHwjLDd3OPMXtnEf eVPU+cYkXE2OBjzNmNnBho08L1s2tOEQSCgEBNj/kqalj+hghvqzk9bB8T3olKr4LJKo sauYnW9WwOgpH2FMPM5dcHp+Zj2FhiQN3O4GlbdVtvJokBCMdZeaFtBexYakSr+9gISg gHtzIqtxFBObmoi5AfuVTbyHyxJCJ/nS4+7wKPeEb5NC0HwpAT06ZSf55dKVdgLJ9pbD 8Zm6G7ZiZWNI/sY3K90NRfj+4aHPC9HmOcd/wvREUEQOOVlkzyLMbG0EIiifK+TcTeDT iM7g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=vkC0MOvasOfRptlueg7DMIAScqcI1y89NBjfSLlZCkI=; fh=rUZtW8m2LxGAW5lbkAB6G7RtctFwwYoJ78KSMfTT6jo=; b=UtyimLiZTJw3Ek2xJX3gHTDX+6opLV/SIS9ZH2cDSiU+4FVTDfiZgFw7t8XOaly3UD QJWXAc10Ng/NYk5HIqVg1zO1regT0IlXhxWg9wMdn3AOE8RsCyspkMZIjIv9tDRk/Ghy 2SK2QCav/w7cqwKatnx3IWkgV9/UPHHWBzKpmAqJ4Tg1axKf27PHqRdqR5BAEIFUgF4T FxWZ/AIiTodoLiLwzviSgHsejKAJ8gqmvtjYEANjTsW269dSj5dOyg2E4Y/SyrBoaV1j IbqV3qW+TSoB8q9ZhsWFWl8KfJljw4UxzRoGBhUWOV+EdbJNoGvXmH+Bw9uXc1fsUfkZ EQYA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XD5VFquk; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-50511-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50511-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCWgm3Jztkh7VhvUh1btxujq2gALyb2KnRNYLbUPLAEcxA+6lPDtxk9comQlXOHr23Qj+HzI2LwLJ9l3vnB3RXHQsIatEg== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id u16-20020a170902e81000b001d93b220500si2249268plg.97.2024.02.02.12.00.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 12:00:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50511-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XD5VFquk; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-50511-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50511-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 6D6E828CECD for ; Fri, 2 Feb 2024 20:00:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C40FD85957; Fri, 2 Feb 2024 19:59:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XD5VFquk" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 514BA8172B; Fri, 2 Feb 2024 19:59:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706903953; cv=none; b=rM2W+fA71SMaSpNQ9i6EFOmd8KRrX1UrSNgBjw7u/yo1qbmgrfEGSvODvA9i017yGKbZqzw2amRuGzRl40Y3l2QfQpoDSkR+zT8TMLJgmsMB/4EUx1oTLneX3r/OTBowRkPDBTXaAzzWMKuf9tTvDCk/ILiRLJNdjDp6nyF7X7Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706903953; c=relaxed/simple; bh=t4kGvcZAyPHW38f5oPy9NpKLy61UGodk/h/wXqd7kZc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=epMgpyn/SwIzI9G0sctzNT0dPVmgTofS+/TcjistdbiLTc2R/IBoRr9HsWy3OXyBGVFFVIbDHWMeZD05E3IhUUhZR2IOoh7/8YYr6FHn7VTg2GRJV0+Ny/pr1jg5nZC4s8f6OuhJLuTSA68vTX8iiLYgaNxpkYn2aHrUaiH0INI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XD5VFquk; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 72B3FC433B2; Fri, 2 Feb 2024 19:59:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706903952; bh=t4kGvcZAyPHW38f5oPy9NpKLy61UGodk/h/wXqd7kZc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XD5VFqukR7gqnIKSizGUPqXYHzgBeBJKgezSNDvrQQLwE+RLJIVEvo9kg+1ZLkSFP Rf0j8e4dZ8e02j/OJ5AF4IKu2oYfj4c8jDUeRGvFIMdBTpsYyfnzMC72xo89VizRmV t3LOQEwJvqHf6mlYvPdgQA2Yh4DPd2t+pbBTM6SNAfTuU4RZen6SmDT78SLYhCMS8B Ov9qHuZmwYX/g+HGG+LunPPZ5umeevN1FE6zIf04gXUwOz6ZmiiGCICGMhwCrom4DE en1VjYRQ68hjitBZfGCLeJCu5Lux1RHGhwzNeoD5fd7gERQzCKm+5crygydWH43/z3 MvLbg0Q3I5rXw== From: Stephen Boyd To: Rob Herring Cc: Frank Rowand , linux-kernel@vger.kernel.org, patches@lists.linux.dev, linux-um@lists.infradead.org, linux-arm-kernel@lists.infradead.org, kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v3 2/7] of: Create of_root if no dtb provided by firmware Date: Fri, 2 Feb 2024 11:59:03 -0800 Message-ID: <20240202195909.3458162-3-sboyd@kernel.org> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog In-Reply-To: <20240202195909.3458162-1-sboyd@kernel.org> References: <20240202195909.3458162-1-sboyd@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789818621146870370 X-GMAIL-MSGID: 1789818621146870370 From: Frank Rowand When enabling CONFIG_OF on a platform where 'of_root' is not populated by firmware, we end up without a root node. In order to apply overlays and create subnodes of the root node, we need one. Create this root node by unflattening an empty builtin dtb. If firmware provides a flattened device tree (FDT) then the FDT is unflattened via setup_arch(). Otherwise, the call to unflatten(_and_copy)?_device_tree() will create an empty root node. We make of_have_populated_dt() return true only if the DTB was loaded by firmware so that existing callers don't change behavior after this patch. The call in the of platform code is removed because it prevents overlays from creating platform devices when the platform bus isn't fully initialized. Signed-off-by: Frank Rowand Link: https://lore.kernel.org/r/20230317053415.2254616-2-frowand.list@gmail.com Cc: Rob Herring [sboyd@kernel.org: Update of_have_populated_dt() to treat this empty dtb as not populated. Drop setup_of() initcall] Signed-off-by: Stephen Boyd --- drivers/of/Kconfig | 2 +- drivers/of/Makefile | 2 +- drivers/of/empty_root.dts | 6 ++++++ drivers/of/fdt.c | 32 +++++++++++++++++++++++++++++++- drivers/of/platform.c | 3 --- include/linux/of.h | 25 +++++++++++++++---------- 6 files changed, 54 insertions(+), 16 deletions(-) create mode 100644 drivers/of/empty_root.dts diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig index da9826accb1b..17733285b415 100644 --- a/drivers/of/Kconfig +++ b/drivers/of/Kconfig @@ -54,7 +54,7 @@ config OF_FLATTREE select CRC32 config OF_EARLY_FLATTREE - bool + def_bool OF && !SPARC select DMA_DECLARE_COHERENT if HAS_DMA && HAS_IOMEM select OF_FLATTREE diff --git a/drivers/of/Makefile b/drivers/of/Makefile index eff624854575..df305348d1cb 100644 --- a/drivers/of/Makefile +++ b/drivers/of/Makefile @@ -2,7 +2,7 @@ obj-y = base.o cpu.o device.o module.o platform.o property.o obj-$(CONFIG_OF_KOBJ) += kobj.o obj-$(CONFIG_OF_DYNAMIC) += dynamic.o -obj-$(CONFIG_OF_FLATTREE) += fdt.o +obj-$(CONFIG_OF_FLATTREE) += fdt.o empty_root.dtb.o obj-$(CONFIG_OF_EARLY_FLATTREE) += fdt_address.o obj-$(CONFIG_OF_PROMTREE) += pdt.o obj-$(CONFIG_OF_ADDRESS) += address.o diff --git a/drivers/of/empty_root.dts b/drivers/of/empty_root.dts new file mode 100644 index 000000000000..cf9e97a60f48 --- /dev/null +++ b/drivers/of/empty_root.dts @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0-only +/dts-v1/; + +/ { + +}; diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index dfeba8b8ce94..e5a385285149 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -8,6 +8,7 @@ #define pr_fmt(fmt) "OF: fdt: " fmt +#include #include #include #include @@ -32,6 +33,13 @@ #include "of_private.h" +/* + * __dtb_empty_root_begin[] and __dtb_empty_root_end[] magically created by + * cmd_dt_S_dtb in scripts/Makefile.lib + */ +extern uint8_t __dtb_empty_root_begin[]; +extern uint8_t __dtb_empty_root_end[]; + /* * of_fdt_limit_memory - limit the number of regions in the /memory node * @limit: maximum entries @@ -1343,7 +1351,29 @@ static void *__init copy_device_tree(void *fdt) */ void __init unflatten_device_tree(void) { - __unflatten_device_tree(initial_boot_params, NULL, &of_root, + void *fdt = initial_boot_params; + + /* Don't use the bootloader provided DTB if ACPI is enabled */ + if (!acpi_disabled) + fdt = NULL; + + /* + * Populate an empty root node when ACPI is enabled or bootloader + * doesn't provide one. + */ + if (!fdt) { + fdt = (void *) __dtb_empty_root_begin; + /* fdt_totalsize() will be used for copy size */ + if (fdt_totalsize(fdt) > + __dtb_empty_root_end - __dtb_empty_root_begin) { + pr_err("invalid size in dtb_empty_root\n"); + return; + } + of_fdt_crc32 = crc32_be(~0, fdt, fdt_totalsize(fdt)); + fdt = copy_device_tree(fdt); + } + + __unflatten_device_tree(fdt, NULL, &of_root, early_init_dt_alloc_memory_arch, false); /* Get pointer to "/chosen" and "/aliases" nodes for use everywhere */ diff --git a/drivers/of/platform.c b/drivers/of/platform.c index 126d265aa7d8..20087bb8a46b 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -549,9 +549,6 @@ static int __init of_platform_default_populate_init(void) device_links_supplier_sync_state_pause(); - if (!of_have_populated_dt()) - return -ENODEV; - if (IS_ENABLED(CONFIG_PPC)) { struct device_node *boot_display = NULL; struct platform_device *dev; diff --git a/include/linux/of.h b/include/linux/of.h index 6a9ddf20e79a..52f6ad6a1c8c 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -180,11 +180,6 @@ static inline bool is_of_node(const struct fwnode_handle *fwnode) &__of_fwnode_handle_node->fwnode : NULL; \ }) -static inline bool of_have_populated_dt(void) -{ - return of_root != NULL; -} - static inline bool of_node_is_root(const struct device_node *node) { return node && (node->parent == NULL); @@ -549,11 +544,6 @@ static inline struct device_node *of_find_node_with_property( #define of_fwnode_handle(node) NULL -static inline bool of_have_populated_dt(void) -{ - return false; -} - static inline struct device_node *of_get_compatible_child(const struct device_node *parent, const char *compatible) { @@ -1634,6 +1624,21 @@ static inline bool of_device_is_system_power_controller(const struct device_node return of_property_read_bool(np, "system-power-controller"); } +/** + * of_have_populated_dt() - Has DT been populated by bootloader + * + * Return: True if a DTB has been populated by the bootloader and it isn't the + * empty builtin one. False otherwise. + */ +static inline bool of_have_populated_dt(void) +{ +#ifdef CONFIG_OF + return of_property_present(of_root, "compatible"); +#else + return false; +#endif +} + /* * Overlay support */ From patchwork Fri Feb 2 19:59:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 196015 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp668030dyc; Fri, 2 Feb 2024 12:00:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IHQuxi1aeh1x+33oh45tLTF8c7As5n6lh7AK2Hm5fjGrgBPyyLyd0HGewU5o1EGdY/qMgIg X-Received: by 2002:a17:902:ec90:b0:1d9:3320:14b2 with SMTP id x16-20020a170902ec9000b001d9332014b2mr4312086plg.46.1706904053375; Fri, 02 Feb 2024 12:00:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706904053; cv=pass; d=google.com; s=arc-20160816; b=QIFiKClDI3ktaOJsbH8C7qLgntHFr0/bqKiZYGSjdqCMpwAZQqzLelumIgly/3L7yR HC2FUoTkkPa1aGcF7AWkATI5yZ+bezSSOXbdsDSw3VsVTvEsOo3SmBeBcDuzsMFagk9P wIVp62bDaQ2cfAnczG7PrOZ8OnUNQ3hdlzNMIfInU66AE/BppciyEe3bxpV+XALqsPxa pR5ufCOv6KHMcQ/3FkW2TXEGwaceHwVk1md+/XgeKmDYZCtf6FzHTVuZqfx/LdNe518h zWUpKFq9IvtSFa4HkPZCIDbD+8mvDIhMblH0Pkz1m9tbuQwIJLWsdW3hy/6S6u2mqJ89 MMQg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=aq0wQCSGkYOTPQQZka2W9Tc3A/BNjaFDxorl+wK66v4=; fh=kTcpWcepvewse6hJ7I9l5SGFXm/9Ww70Ft9XQVNpeV8=; b=imAzE0PfvMYVm37kI3hiJF0b5J+hx+qf/nq15mlggCxlk56iSqYWU4V1kBcoPd4ATR gihiyuNKey0hS73MMZ84J0tBdjbGrGiAkOW1Ggvw9uUQAKHPkbBCGHqciTbMlu4TpGNd Ud7FVEutiSLS/4G7vzEHPyePYClJ+8LRwKfkIr3/ISwIWoJ94MdsLscBuzW9Ut0fWxIO Y9/GqenxZErQgtcEyV53w5NVwe9GSms65HvvmtWLExnzJw/JF0vVv63e2GtQtxdW7UDI 4GNN0l+B6MG56J1Tdfd7NRncGNGoXVzfnbmqZvREMsE7+ZdAm5Hugl7e+h2VLO93n4ZX AT/w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Oe5mTlqQ; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-50512-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50512-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCUf0SnHPvXShLeIyjQNeRPKGHjzJ0GtrtwRbbKgkSI9ZUSJkGOcsCj+KWfmSeplLgOpR0mO3vWzyQQmosUrgZYRCKvMLQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id u16-20020a170902e81000b001d93b220500si2249268plg.97.2024.02.02.12.00.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 12:00:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50512-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Oe5mTlqQ; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-50512-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50512-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 27CC028D070 for ; Fri, 2 Feb 2024 20:00:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E99ED8595F; Fri, 2 Feb 2024 19:59:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Oe5mTlqQ" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1B80C81748; Fri, 2 Feb 2024 19:59:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706903954; cv=none; b=gvOiKvW05enLKlRwKrCWOTa8qvIStWvf0bAxtIVmfRj/BlcTcEOeAJX7Fk9X3rUVzwu5uBiwif+mxkUnlBwnuJD0KWxAQ605WE2dMyX+G9/L+o2JkVt8qZ/UUz6LmzQ6xjVika0uMDlUSRrW5v33B2ae3Xe/Ujlc6vt+o7rOFNw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706903954; c=relaxed/simple; bh=hCAh9IJVjneFBmTI7MeY6517yfTJZxfzJ8kdqiP/+uU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lXWUNX0Pji0M6zGmgtyZH3IchbNt84920vL8kMWlbCOapGqHV9ehnA+1EfyHe+ihHUERwcy4u3ZI1mGTlYguLFBxAaPQ+pCUoeP141Qx8WTXuZV9VZt4oYO0jc5OKExfEuDsvf64nvfq2EeJj1MflcWzV/Taaz9OpUr3WCGoKsw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Oe5mTlqQ; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0EA47C43390; Fri, 2 Feb 2024 19:59:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706903953; bh=hCAh9IJVjneFBmTI7MeY6517yfTJZxfzJ8kdqiP/+uU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Oe5mTlqQV4TxhihRvuWjgYd5mxic2ugd/H4tFQBcJ/U405XynzpfABSFHTa+Foabt nGUgMGsnJ7GPKJm90IUmijMHgVU34jyZ32du/2NiMbIrfr+4NzpMSpNF0ofS3N2yK6 CFGHkLMXYwt2V3Zl50Q0AcnPcrEYu/FF/JMS8QO6pKTK8VNYZkkksNgTetK25izGPV rl+jjk+FQadEwPmK8WcaQKd6vA5wD9GqrqVe4coMaA6xgtc1xb/8LHDTbsoZVVN+3I p9/nRIR4huLAAKk4VnEmgaiGqJRIIQjY4z/H3bzHkJkNg16kubZMki/t2r5Lqzo8+Y R2crPQ+Zr50rQ== From: Stephen Boyd To: Rob Herring Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, linux-um@lists.infradead.org, linux-arm-kernel@lists.infradead.org, kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, devicetree@vger.kernel.org, Frank Rowand , Richard Weinberger , Anton Ivanov , Johannes Berg Subject: [PATCH v3 3/7] um: Unconditionally call unflatten_device_tree() Date: Fri, 2 Feb 2024 11:59:04 -0800 Message-ID: <20240202195909.3458162-4-sboyd@kernel.org> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog In-Reply-To: <20240202195909.3458162-1-sboyd@kernel.org> References: <20240202195909.3458162-1-sboyd@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789818624728639603 X-GMAIL-MSGID: 1789818624728639603 Call this function unconditionally so that we can populate an empty DTB on platforms that don't boot with a command line provided DTB. There's no harm in calling unflatten_device_tree() unconditionally. If there isn't a valid initial_boot_params dtb then unflatten_device_tree() returns early. Cc: Rob Herring Cc: Frank Rowand Cc: Richard Weinberger Cc: Anton Ivanov Cc: Johannes Berg Cc: Signed-off-by: Stephen Boyd --- arch/um/kernel/dtb.c | 14 +++++++------- drivers/of/unittest.c | 4 ---- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/arch/um/kernel/dtb.c b/arch/um/kernel/dtb.c index 484141b06938..4954188a6a09 100644 --- a/arch/um/kernel/dtb.c +++ b/arch/um/kernel/dtb.c @@ -16,16 +16,16 @@ void uml_dtb_init(void) void *area; area = uml_load_file(dtb, &size); - if (!area) - return; + if (area) { + if (!early_init_dt_scan(area)) { + pr_err("invalid DTB %s\n", dtb); + memblock_free(area, size); + return; + } - if (!early_init_dt_scan(area)) { - pr_err("invalid DTB %s\n", dtb); - memblock_free(area, size); - return; + early_init_fdt_scan_reserved_mem(); } - early_init_fdt_scan_reserved_mem(); unflatten_device_tree(); } diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index e9e90e96600e..a8b27dd16ecf 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -4075,10 +4075,6 @@ static int __init of_unittest(void) add_taint(TAINT_TEST, LOCKDEP_STILL_OK); /* adding data for unittest */ - - if (IS_ENABLED(CONFIG_UML)) - unittest_unflatten_overlay_base(); - res = unittest_data_add(); if (res) return res; From patchwork Fri Feb 2 19:59:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 196023 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp682183dyc; Fri, 2 Feb 2024 12:28:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IHjj7z3iJa+QzVvAdklyla/EPliDUJtV1artnpK2wDyyaNcMY0ZbIoCODoYrsCxom02QNSd X-Received: by 2002:a17:902:784a:b0:1d7:67ed:f359 with SMTP id e10-20020a170902784a00b001d767edf359mr6636532pln.4.1706905707379; Fri, 02 Feb 2024 12:28:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706905707; cv=pass; d=google.com; s=arc-20160816; b=sQOPPbEB1N6SUTWDBhnAv1bnPOpL8stCLLXm9bY4KkwlTwENTjq4EvOs0U9kcPwLYv xj6KOfzb1i9L3bsGXo07I6iiq5y4aQuJO7lkSC3kM23np+lLfIKR1yE0b6giKv0zxqG6 blg7WrGNon08kJh4tDhEYpbM2yOWShEL7avHXd17vz3wjYKrYQzU5e7DG9X8E+0TdE1h obVS5sH4SmCMkpYJ5cqUNybiTs8chmAySYO4fb7M6Rg0wgfo1PZA54Efw/PHOmAUsT0g e0y+73O7IIKOsXgg7d2i93u4OzW6HM3hrU/3HzwYIY7lfT+tBrVHxJVIzdNAek81UfxL JNkQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=lN+ZxRXMPbv6Q4AYpHtIShePhFIex51fo0wm/eE8eLA=; fh=2L9rVPzC3a1sZX+bD7uhYmUL+/HiPe/P2tB866jiyUU=; b=EWLWtt4R3PfIS0QDtFrAbwuNWpaQzXueTfUxyYK3uaW849uraC3n/IFV21m1KP5q1D OOakBocx9TG90XTgThPaWdcBGggbtms63yI8XooEaOhYEpSMqrunpJ+6r17QrIPvGJVm LedVh7SeHpJ8GgRJ7cu7NuUzhnmlvAsiPJIZ1Mv1KqHYxAZG4IdIoghKD/11+7sZsANJ vx3AEIoy/7T1MaqgGSHbBWxOYOpBX6E6nBFzRsdcUZksdFvbVFN7Ed2OM5JWzQrzWjB4 +kKn43Njq/uhE9MJwslmr1RWb7ckQtLf+8GqdCxWH/gTQl0jQgqlTr1bTbNqyoHR1/wc qBvQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jS3LgOUj; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-50513-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50513-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCX3Y8kPJJ/3qA5nc0C6PyPDt1OKXo4zGhKgtEdlIeY4h5UthUuaeH/dm3JrajsZyQRz7cbTmRmtRsDGyQCKMwUDJJs17g== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id p2-20020a170902e34200b001d76ec124d9si2111628plc.320.2024.02.02.12.28.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 12:28:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50513-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jS3LgOUj; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-50513-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50513-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 1C2AAB29146 for ; Fri, 2 Feb 2024 20:01:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C2946126F2C; Fri, 2 Feb 2024 19:59:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jS3LgOUj" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EDF78839F5; Fri, 2 Feb 2024 19:59:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706903955; cv=none; b=Gc7PwZiu3rmjRuZoG9e9CBM0TawHibkCWelNLh1NBmClqPXp5wGmb73xx1K3arZCRolgr1J3zpM7xXd3Adi3oNcEfVXch8p9srfmCcM7RwxRvpkBK6UTRVsmTh4KWIcn40tWFEGtTsdpwuT45OfpG5KZq2f2fuPQhWT2mOocddU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706903955; c=relaxed/simple; bh=7MNLMqC60PFypfikGUyizgcmoz6K4dXFYuG0uw1c2t8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iHcRtcN9gENRAxh2zy02hjmQMvDCuPQa/PqHPMrruPqt1aJKLCl9iELanC2REGNIsDuoDzZbYR4FlJG46+xUrniVHbcYeqy/nZ2tylqFkz+XeYRu/nKJoJvxOxmBDoSCc2Q5vT09Sb3x8BQpWkFt9dFEmnm9hzH/7CFN35hLlfg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jS3LgOUj; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id BF0DDC43399; Fri, 2 Feb 2024 19:59:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706903954; bh=7MNLMqC60PFypfikGUyizgcmoz6K4dXFYuG0uw1c2t8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jS3LgOUje0AaKkELyp5yo7o5rXijBOH/s1SqcpneNP1bmifPs+GO78P9aJ4YubATC 8sKniHp9zGS1eDFh8lXedC38t2er4z9+fcgEtzZ+Cfa/CiwuSxbYvk9XGQ/faguy/b HzYgwsTF7FeWgJsUPKxKL3ZTRrW5jMd3ZYR+JCgciTsP3A0ktn9GMKrB+0xiJF1mJN 1KEkX2f0kRgxfTpsBQlCJ5USqFnwAUaVfGm3HXryx7e+RTuFgXu/Ff8NqhQVoXyj+L aR6bimdFvj35OMLhKthnfc8oRpd1WjEefi61aEyghyRTtvCCi3tZrb8vgBrqcp8ejY Dyrq2kwDoiwpw== From: Stephen Boyd To: Rob Herring Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, linux-um@lists.infradead.org, linux-arm-kernel@lists.infradead.org, kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, devicetree@vger.kernel.org, Frank Rowand , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Saurabh Sengar Subject: [PATCH v3 4/7] x86/of: Unconditionally call unflatten_and_copy_device_tree() Date: Fri, 2 Feb 2024 11:59:05 -0800 Message-ID: <20240202195909.3458162-5-sboyd@kernel.org> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog In-Reply-To: <20240202195909.3458162-1-sboyd@kernel.org> References: <20240202195909.3458162-1-sboyd@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789820358644578889 X-GMAIL-MSGID: 1789820358644578889 Call this function unconditionally so that we can populate an empty DTB on platforms that don't boot with a firmware provided or builtin DTB. There's no harm in calling unflatten_device_tree() unconditionally here. If there isn't a non-NULL 'initial_boot_params' pointer then unflatten_device_tree() returns early. Cc: Rob Herring Cc: Frank Rowand Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: Cc: "H. Peter Anvin" Cc: Saurabh Sengar Signed-off-by: Stephen Boyd --- arch/x86/kernel/devicetree.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/arch/x86/kernel/devicetree.c b/arch/x86/kernel/devicetree.c index afd09924094e..650752d112a6 100644 --- a/arch/x86/kernel/devicetree.c +++ b/arch/x86/kernel/devicetree.c @@ -283,22 +283,24 @@ void __init x86_flattree_get_config(void) u32 size, map_len; void *dt; - if (!initial_dtb) - return; + if (initial_dtb) { + map_len = max(PAGE_SIZE - (initial_dtb & ~PAGE_MASK), (u64)128); - map_len = max(PAGE_SIZE - (initial_dtb & ~PAGE_MASK), (u64)128); + dt = early_memremap(initial_dtb, map_len); + size = fdt_totalsize(dt); + if (map_len < size) { + early_memunmap(dt, map_len); + dt = early_memremap(initial_dtb, size); + map_len = size; + } - dt = early_memremap(initial_dtb, map_len); - size = fdt_totalsize(dt); - if (map_len < size) { - early_memunmap(dt, map_len); - dt = early_memremap(initial_dtb, size); - map_len = size; + early_init_dt_verify(dt); } - early_init_dt_verify(dt); unflatten_and_copy_device_tree(); - early_memunmap(dt, map_len); + + if (initial_dtb) + early_memunmap(dt, map_len); } #endif From patchwork Fri Feb 2 19:59:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 196016 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp668475dyc; Fri, 2 Feb 2024 12:01:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IGsL5Z1eQEv5n6atBTGrvvhKlsWRn/NZ3vWEQZTvE8MXPAIP4eQo0TARW2RmWSr79gbM8Qn X-Received: by 2002:a67:f4d2:0:b0:46d:7a:70e7 with SMTP id s18-20020a67f4d2000000b0046d007a70e7mr2828288vsn.10.1706904086513; Fri, 02 Feb 2024 12:01:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706904086; cv=pass; d=google.com; s=arc-20160816; b=P9K9Ku+swhjJjJmL+344I47+DlCfs9Vm/rSwxAHig21kNfFOuQefuHTVwYfCBF4Cdd hyEbV+Z2rWV6whsE9ArtGtq4sOpVh5wtAG9pVEgsIFYfsGiL4FH0y8FpHTIK04V22lw5 TvDz0J5kaJVC/+Yb7f4bDzVx7Na23EYfHf1EhYpjENrmMzz528csT901bw1mWABI6pLt 5FebO+3ymEJCrQhmGE31ndysWSDOVbsozBReFFf5YxPIJUDzSIlHapK5Ep2ZUGxODVz2 rB0kKRrn8zPVMz/rffHfR+domfDh7TF0AZ3ZIDijDkEkWqbsT2I3Q1rIssOMmmvJKPh2 yFmg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=6ibBvNWtj9I8biZ96CkFZ4v4tfreGCPhIbpTACz17i8=; fh=h0xJcp2ZGP5h/yXu0TVeZ3UUUJGOKI4Q7upqZ8akbcU=; b=ZwmWf7dUKGEXcQwS0RlSYKRzPbf4tH8KPf9D/mtfkHbVOMMu1l73H7X3oKg5jK7/rT P5ybXKZGx6g+P7qnZTvUJU8vifx2ULvmfy5Pad2/wYLBluE+IgTKgNAQ12mkGyZthBaP 0grToTItRvRI9CU+XmsaKTCELfV5taaQhETfxeAzIPgjZCJoUCeM6m7Wvn25Um0wrpaF IDIIh5DUE0fvHYqmj55fmOas/+FoltGSAo9Bkwc2i5OaEm1ll6ohHpAUuE3oLcRhiYe7 Jb61/lqOq63idiUiDt6NFmI3Y8Q/FL4VuwYqhl5iRvWABEUfBSrOxV0RZ5CCmh4FQ1dC xpvA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CKk7oRVP; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-50514-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50514-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCWGrq5rcVXDVghffdGaa+NBFqlFPW1FPB3z5wOtD8xaphhnlhG1Mdr20XKkNPNeUoggmuy4T5H7aT7aa+Ar+bAdqztGmg== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id dd11-20020a056102568b00b0046b471d791bsi427153vsb.450.2024.02.02.12.01.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 12:01:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50514-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CKk7oRVP; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-50514-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50514-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 4898E1C24B18 for ; Fri, 2 Feb 2024 20:01:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 98F7312C7EA; Fri, 2 Feb 2024 19:59:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CKk7oRVP" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B68CC81732; Fri, 2 Feb 2024 19:59:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706903955; cv=none; b=SZ9kB11jMULlBfJHTJh7tr9kwQK1sE68c5kDPaE80tbRnFH+W0C1slKHkUcpa6Y5SVkWtGBWz2taGPMhlxeCyBV0Ju0uW8net/Y9VTa59PvXqf/jPnBUldeVzA/C5mn3JMagYRFcwrN2TkOmw7viAihy86HgJd+wtErTG9Gac7I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706903955; c=relaxed/simple; bh=Ik7PysFz2Q/PQymMpEmnCsC39bu2MIXYeb1T3HpNV9c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=plsQUWDOW+J4pBC4W5n8jkeSx+ZbdaaUPTxiPUknGRLE5WHrQB9k2/89O4pSTLzwZiPImNA7RwlzALUeM0DHopW1hEmj+fQnaWKUbnhxsIquqCmx0YAcoXfxiR7WZFisAMrXQd3ndPz1TtKBBjAQpJLRl1y5ujxzhtegvsBATsA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CKk7oRVP; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id A256FC43601; Fri, 2 Feb 2024 19:59:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706903955; bh=Ik7PysFz2Q/PQymMpEmnCsC39bu2MIXYeb1T3HpNV9c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CKk7oRVPGb6C4HwkiFVL7iT8eK5Iik/EDFzYFOWPTWd77I5UUfPzNd7aKEoHobNdK k6Iw7l3n0kK1QlfHNjMomlOOIirYwU1YpZobTyaCqSTvK63/LTQWC3U/94Wr+aCo1K 394zegdhvm14D9LJ9NsIivpUSTTgKA8VMQ+qda/ZZNZWNO9pqhQWXlJ356r8GK1dg/ Y9EE2/Xe7HhWLyB8r206UzMDMPWCWCqSs4f0n5ApmA9aFdeFK0zgM70sRYd1vQf03A xHklCpZJB3PdHRb1/vDAF5/fzpbWmHhXlWWWVeSgi2bjCoLOEJCf9ZpZ0n4+cooxP7 oZE/QJs34kWsw== From: Stephen Boyd To: Rob Herring Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, linux-um@lists.infradead.org, linux-arm-kernel@lists.infradead.org, kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, devicetree@vger.kernel.org, Frank Rowand , Catalin Marinas , Will Deacon , Mark Rutland Subject: [PATCH v3 5/7] arm64: Unconditionally call unflatten_device_tree() Date: Fri, 2 Feb 2024 11:59:06 -0800 Message-ID: <20240202195909.3458162-6-sboyd@kernel.org> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog In-Reply-To: <20240202195909.3458162-1-sboyd@kernel.org> References: <20240202195909.3458162-1-sboyd@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789818658916378796 X-GMAIL-MSGID: 1789818658916378796 Call this function unconditionally so that we can populate an empty DTB on platforms that don't boot with a firmware provided or builtin DTB. When ACPI is in use, unflatten_device_tree() ignores the 'initial_boot_params' pointer so the live DT on those systems won't be whatever that's pointing to. Similarly, when kexec copies the DT data the previous kernel to the new one on ACPI systems, of_kexec_alloc_and_setup_fdt() will ignore the live DT (the empty root one) and copy the 'initial_boot_params' data. Cc: Rob Herring Cc: Frank Rowand Cc: Catalin Marinas Cc: Will Deacon Cc: Mark Rutland Cc: Signed-off-by: Stephen Boyd --- arch/arm64/kernel/setup.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c index 417a8a86b2db..ede3d59dabf0 100644 --- a/arch/arm64/kernel/setup.c +++ b/arch/arm64/kernel/setup.c @@ -351,8 +351,7 @@ void __init __no_sanitize_address setup_arch(char **cmdline_p) /* Parse the ACPI tables for possible boot-time configuration */ acpi_boot_table_init(); - if (acpi_disabled) - unflatten_device_tree(); + unflatten_device_tree(); bootmem_init(); From patchwork Fri Feb 2 19:59:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 196017 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp668514dyc; Fri, 2 Feb 2024 12:01:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IG99/otXhsNZqUFBnUA0ZSimgpbOujhCuytGCerCEib21nAuOWOmgmeEcSfZx4zEdcv/JTi X-Received: by 2002:a17:903:4289:b0:1d8:d6f2:5ee0 with SMTP id ju9-20020a170903428900b001d8d6f25ee0mr6502426plb.8.1706904089110; Fri, 02 Feb 2024 12:01:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706904089; cv=pass; d=google.com; s=arc-20160816; b=v0IqDDMDQA+KZ7+MYwAyvZNs/3WH9P7RREKGWHxl9agJ4bYFxxeTm/R0q8olsM1stw y+xafJlJg7dd/s39d10KnubeTfj7/DqqUbruorya54UoQ2wflwgqneKq8bW18AVa20p/ 4xv+gFeInyJ+hsgwpvSlMyxMAk0Ru9kD5QzizA7ZTHUvwoxM9qm5iuGJ/vHPSC7QTkzI TN3ju/eaOLfVMZbkef2vIFWJtt9chiagW/PnbySVTifYsupvTM4bvfFyaqTOSVYcPQLn x9V8mT/xt59PvFHMQPdAOcdMZ96e+pv7/ee2OBYaLtR9v6kCic2UJxBmHauf8PJZpDZh XARQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Vxm7GroJb1jr7a7SKxct7zVVLJ9MIYxfQSDNcHJxJs8=; fh=+eNSuoHAPUHx6ftvK6JyMPCiLtoCbLqExckzJHX/pR0=; b=ozkupklV5M5/Aou3iSDdWEI3K+tHObc337ISjxjbskgn3LaO5PjVuVQHjcKgtn64/b YWGJ3XODm9r+JeUKmOWbh1Ayagk+JYYvnpfGVQRQKbOXLdjm0QwFTG7d0PY8joiW3EvB 3/OuniK95mVXkqp2DvEA7oT7H+3J86WIyCwIJM8ek1bWVoCcGWtOwdx0n6v4ssYCRQPV 3KjpXm6YCcWsRDJFWmCyFck23ay+ya+Ar9CJBlJ2PRAPelUk1VtYGbXT8UW1iuHDbFNc Rp+KiQPlnO1p6/EekzqtE/5Xi10FGklud6WYnhd3EPh4TUsYQI88+v/zL3twxoM5vU7R zA3w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rqr1TVIk; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-50515-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50515-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCUjulWnYpScXoBYj6pbh0YP6LCjDNAm3AQATRBPGolb2tXRykWLoZh/12+ZYI1cilj+ta0AUvAV93qQ4jfXJv9bqjT3/A== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d6-20020a170903230600b001d70fef0d09si2309858plh.52.2024.02.02.12.01.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 12:01:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50515-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rqr1TVIk; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-50515-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50515-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id DC8E028D102 for ; Fri, 2 Feb 2024 20:01:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D0E1912C7F0; Fri, 2 Feb 2024 19:59:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="rqr1TVIk" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0465485929; Fri, 2 Feb 2024 19:59:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706903956; cv=none; b=eRb7AJQOiPgL/JnlJcDNDsfNEdR4t/Uw9hMDQV79yX22a2BrxoYp5TpIfxLKVZ8oXlaEkNeGE3KTQQCc8Gbq4xmkSPn/0+/YHA6kME+aaTIU3QFnFCIC7qIymIR6goR/qhrBd/vIRuE+6TjHr74s5IEqWOzHTnUwXayqKP34Mfs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706903956; c=relaxed/simple; bh=QNmBS0brQeJSjUserQhzHk2Vt2IzcbhX82b9CN/v9CM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g7/jreHac22fAhfkEtVSnWkp1hNn1GMUX7S7YYIPWGJzlFOD91MZgAZ3tboTw8kFxVhVldPTJWwivsTvOyTxH5mAD6WhAvrHxGXyV3XJZOhD1MlGlMDDXoNttc7t2msE7pIPtOe+AzvNblT3qWHMaSHQ4bH9r/l+XMb7PVZZdIo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rqr1TVIk; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5EB81C43141; Fri, 2 Feb 2024 19:59:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706903955; bh=QNmBS0brQeJSjUserQhzHk2Vt2IzcbhX82b9CN/v9CM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rqr1TVIkELbYe8QcCaThgPp5LfWi4EUBvIMppFR3VVYloXIkVaSj1nLdUvXnARg9u W4AepGXy6uRZGg2L9PFyE7fy9ii7eFqT6dlWogyio4PE7QIoBYNy7tMnDPJ8UfC7hG XFbmaFzRY/46VmL/ZfeffKX1wCpke+epxasSxyVyG3ZE8GhMyOB43ybYp65Se6knYS adbMjrvYBVdu4eZEpmkn75FnBt+KEP63nyZeBhz6u4l5XoVWgDQlttPxbupz2oLhsm s7YXw3hJ2rRF52Uz2vwU3YR5WfwgKeeO2H4/PfvHfC78HwzoSD7g5UczgKO8C9fD6x i93LlSW/kUN1g== From: Stephen Boyd To: Rob Herring Cc: Frank Rowand , linux-kernel@vger.kernel.org, patches@lists.linux.dev, linux-um@lists.infradead.org, linux-arm-kernel@lists.infradead.org, kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v3 6/7] of: unittest: treat missing of_root as error instead of fixing up Date: Fri, 2 Feb 2024 11:59:07 -0800 Message-ID: <20240202195909.3458162-7-sboyd@kernel.org> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog In-Reply-To: <20240202195909.3458162-1-sboyd@kernel.org> References: <20240202195909.3458162-1-sboyd@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789818662649520585 X-GMAIL-MSGID: 1789818662649520585 From: Frank Rowand unflatten_device_tree() now ensures that the 'of_root' node is populated with the root of a default empty devicetree. Remove the unittest code that created 'of_root' if it was missing. Verify that 'of_root' is valid before attempting to attach the testcase-data subtree. Remove the unittest code that unflattens the unittest overlay base if architecture is UML because that is always done now. Signed-off-by: Frank Rowand Link: https://lore.kernel.org/r/20230317053415.2254616-3-frowand.list@gmail.com Cc: Rob Herring Signed-off-by: Stephen Boyd --- drivers/of/unittest.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index a8b27dd16ecf..742d919e8ab4 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -1732,20 +1732,16 @@ static int __init unittest_data_add(void) return -EINVAL; } + /* attach the sub-tree to live tree */ if (!of_root) { - of_root = unittest_data_node; - for_each_of_allnodes(np) - __of_attach_node_sysfs(np); - of_aliases = of_find_node_by_path("/aliases"); - of_chosen = of_find_node_by_path("/chosen"); - of_overlay_mutex_unlock(); - return 0; + pr_warn("%s: no live tree to attach sub-tree\n", __func__); + kfree(unittest_data); + return -ENODEV; } EXPECT_BEGIN(KERN_INFO, "Duplicate name in testcase-data, renamed to \"duplicate-name#1\""); - /* attach the sub-tree to live tree */ np = unittest_data_node->child; while (np) { struct device_node *next = np->sibling; From patchwork Fri Feb 2 19:59:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 196018 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp668607dyc; Fri, 2 Feb 2024 12:01:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IEF2Vo6laJvt634EXEvdyY77p4gZHb9KXdCZgPgXuqDdkPBvJaY7WJNumwf8SWcAQImb1df X-Received: by 2002:a05:622a:13d2:b0:42a:a166:16a with SMTP id p18-20020a05622a13d200b0042aa166016amr9315137qtk.52.1706904096399; Fri, 02 Feb 2024 12:01:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706904096; cv=pass; d=google.com; s=arc-20160816; b=ELs2q31VQr46GyspIsNL7DBDkrgVaBYEabg+JR/hC6l0HF6tqafc15iC6rYqWBp9j/ KnCjk9YrjS9XEyVy/keOZJoAOCv1FreluHg8l6ftCp7AbrUi9MC6NztjHe9/dXkS02q8 waCd6kj/xaFXCr/GlgCok4OcuCXlXm+hbiUh4hCNFJvqElPtG1t4U/olqhSmP5Le2wNx a4AG7abjGBhC+W35d68tMQQ9QWl+FU4PlqUnlKPpPRG7XD2CAKZcr/xo/9RgN0tbrqjl TkeOALPvK4JG7NDgQs49CSzRPMGeQ8YpC1zyc8138s3UgIw2ceThFT1nEuSCSgWTy1mi fHDA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=9nr8KgIXSlmrBRc5eTEs4Ft1WJ6sE76s1g3Xw61O8GM=; fh=d8ySrDEE1vqD4SlGM/BxyavV5CxwWpd4FMSQflDXFrY=; b=oQXLwLcSnupraVDFYE90BLdm04tB5Z1eNsYwsZ85+GjlBrpE/Wx7iRlixK5cZOzjnt kuTxLN7yr6jxS6JeJAUgknyy54aWCbcKAgt402jGapTVO/eUAoHKKb/xqkxKnhVKOQg9 s46q53mO8e1s3kVxklQ6IFRVAFx2I/4rACZcoA/t4Llwt8irlqvhvsBJIwLkpim7jtzn ekBu3svH6j6ZY+2V3OMzXZc7W4CmHOEpV+8yY8Yu76bthqGiY6emERlzvJRsMG1PPMui nO7iMBzB9ncqFxzkzdzjm+fMFntfruY5UnVwez09LWRl/vPhaqS5rgh1+4GtbO7xaVN6 Yyjg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LUsABn4B; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-50516-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50516-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCW9N9tdrRAAHSvTX6V8tk6FtMOYoXOVuy+vpZgKzmTjqzwux0khttnYfOVUHcdTrS/QbCtOLVqLCzNYzIxY3creZ8dPQg== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id c22-20020ac87dd6000000b0042bf725393csi2823184qte.54.2024.02.02.12.01.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 12:01:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50516-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LUsABn4B; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-50516-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50516-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 346701C24B24 for ; Fri, 2 Feb 2024 20:01:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AA24912C805; Fri, 2 Feb 2024 19:59:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="LUsABn4B" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EE9B1126F01; Fri, 2 Feb 2024 19:59:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706903957; cv=none; b=nzD4ffN0CepjBF+gTwe/lnMmHrrYGXVu7LLJ+I0KbU+5PqmCV3j7Fiwho06r7E86lzegfotTrDft72eeWoIH3AeEff5jZjx5rDt94mVcHqCu9jq2MlQPTmdURgQJRVBpHiGjRHWmmR3GVVaPoeqThK9DqPt4n9i640sg/4ZCLdM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706903957; c=relaxed/simple; bh=PiweXFroDHF7yXaa82SMFRXH/FDbm1RzgiHTih6bLA8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lG22swlSyaidBABSLfN58GNfQpu5CNXjMMDY7I9h+PbrxzXGV53XzEOAdMLs/KF2t3E3EuyDxA6PxquCHK2L5kqrsmo3JDHdp1TNTyYIp9HZFLeBAREGKh79lvrqDZSbD9eMfhFkPJFcx/5WCXxKjJcUfl/kDvGoLS8DjIJHrek= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LUsABn4B; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id F0422C43390; Fri, 2 Feb 2024 19:59:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706903956; bh=PiweXFroDHF7yXaa82SMFRXH/FDbm1RzgiHTih6bLA8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LUsABn4BtEE+3rLzRs0MQ2C02aC4eRavx+NnUEigQIDN5hEhEZNBOQJZPL8COpFiE lorefdZOxB8OV+F2B33bLbZYuCDULzTivEsiui+momrj0H+Q4M8bILqL6UXIb2VZG8 2a4s2d8yNcFame9bG1gYjm7fRnJ0b1loqO9DK41wYC40o8K8MLf+BOFe1Y+PHMhias njRXktKCexQ9Yv8x4+YTqiHhB31aR091ZwIt79dQ9s29u1QvLULGcboC0mabkoiOis bdoKOrdCx2OSnf4HWEb5yIMklX06Ug8ejLsbsHsTP/c7+WG2Qd9+ZAF9Hq4PyzUetv l0y+61kYAJv5Q== From: Stephen Boyd To: Rob Herring Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, linux-um@lists.infradead.org, linux-arm-kernel@lists.infradead.org, kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, devicetree@vger.kernel.org, Frank Rowand , David Gow , Brendan Higgins Subject: [PATCH v3 7/7] of: Add KUnit test to confirm DTB is loaded Date: Fri, 2 Feb 2024 11:59:08 -0800 Message-ID: <20240202195909.3458162-8-sboyd@kernel.org> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog In-Reply-To: <20240202195909.3458162-1-sboyd@kernel.org> References: <20240202195909.3458162-1-sboyd@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789818669908903614 X-GMAIL-MSGID: 1789818669908903614 Add a KUnit test that confirms a DTB has been loaded, i.e. there is a root node, and that the of_have_populated_dt() API works properly. Cc: Rob Herring Cc: Frank Rowand Cc: David Gow Cc: Brendan Higgins Signed-off-by: Stephen Boyd Reviewed-by: David Gow --- drivers/of/.kunitconfig | 3 +++ drivers/of/Kconfig | 9 ++++++++ drivers/of/Makefile | 2 ++ drivers/of/of_test.c | 48 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+) create mode 100644 drivers/of/.kunitconfig create mode 100644 drivers/of/of_test.c diff --git a/drivers/of/.kunitconfig b/drivers/of/.kunitconfig new file mode 100644 index 000000000000..5a8fee11978c --- /dev/null +++ b/drivers/of/.kunitconfig @@ -0,0 +1,3 @@ +CONFIG_KUNIT=y +CONFIG_OF=y +CONFIG_OF_KUNIT_TEST=y diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig index 17733285b415..53d1b5dd89e8 100644 --- a/drivers/of/Kconfig +++ b/drivers/of/Kconfig @@ -37,6 +37,15 @@ config OF_UNITTEST If unsure, say N here. This option is not safe to enable. +config OF_KUNIT_TEST + tristate "Devicetree KUnit Test" if !KUNIT_ALL_TESTS + depends on KUNIT + default KUNIT_ALL_TESTS + help + This option builds KUnit unit tests for device tree infrastructure. + + If unsure, say N here, but this option is safe to enable. + config OF_ALL_DTBS bool "Build all Device Tree Blobs" depends on COMPILE_TEST diff --git a/drivers/of/Makefile b/drivers/of/Makefile index df305348d1cb..251d33532148 100644 --- a/drivers/of/Makefile +++ b/drivers/of/Makefile @@ -19,4 +19,6 @@ obj-y += kexec.o endif endif +obj-$(CONFIG_OF_KUNIT_TEST) += of_test.o + obj-$(CONFIG_OF_UNITTEST) += unittest-data/ diff --git a/drivers/of/of_test.c b/drivers/of/of_test.c new file mode 100644 index 000000000000..71a767b42b43 --- /dev/null +++ b/drivers/of/of_test.c @@ -0,0 +1,48 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * KUnit tests for OF APIs + */ +#include +#include + +#include + +/* + * Test that the root node "/" can be found by path. + */ +static void dtb_root_node_found_by_path(struct kunit *test) +{ + struct device_node *np; + + np = of_find_node_by_path("/"); + KUNIT_EXPECT_NOT_ERR_OR_NULL(test, np); + of_node_put(np); +} + +/* + * Test that the 'of_root' global variable is always populated when DT code is + * enabled. + */ +static void dtb_root_node_populates_of_root(struct kunit *test) +{ + KUNIT_EXPECT_NOT_ERR_OR_NULL(test, of_root); +} + +static struct kunit_case dtb_test_cases[] = { + KUNIT_CASE(dtb_root_node_found_by_path), + KUNIT_CASE(dtb_root_node_populates_of_root), + {} +}; + +/* + * Test suite to confirm a DTB is loaded. + */ +static struct kunit_suite dtb_suite = { + .name = "dtb", + .test_cases = dtb_test_cases, +}; + +kunit_test_suites( + &dtb_suite, +); +MODULE_LICENSE("GPL");