From patchwork Sat Feb 17 01:05:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 202546 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp91622dyc; Fri, 16 Feb 2024 17:22:05 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX9pHzkTSPGpc8nbrc2JyhBiDIYKEIY3vGeKxYRkoeU1t5j8Bf4TqSO7rzb68nFtI1zycJF0t7Vg82HLgmx92verLlKAA== X-Google-Smtp-Source: AGHT+IG2nnC1dFYDVFPmhBttWNXnJS+VjgATgtP3+Sci5FE+JvlVcMA1nojwsNGRv7Gy/SMNXWUk X-Received: by 2002:a17:90a:cb11:b0:297:efb:c33d with SMTP id z17-20020a17090acb1100b002970efbc33dmr5396110pjt.47.1708132925330; Fri, 16 Feb 2024 17:22:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708132925; cv=pass; d=google.com; s=arc-20160816; b=X72kifgSv6FpH10Ujm4CeXSzWOP2x8y/q6JgswaajYbkSxEw9vax3SDIcboR5Bqg1J A363j7yBhU90Uu5Zn9vsFftjXRaQN+xwV/Zl1iyT1k6FeiR10ITj6XywiMZKc877wmAk JLzlHvLpoBjuvM9qX8jtF/7mcsxpXYa6IOLeoDbylpbMpOekrnlkyxZK/b00akYaMWqJ B4CK4gL+u0fS38vVozfUiDoLlNcIAsAy0/idjmhvn4K5iZrfY2+Ipq8luNvo/ZzD8Olw Gk5uKxJjtrkawvurVVJr7f4mc4hj8JjCJptsbcHh2ygIwwHBslWpja0CnqjLuFifoPc4 QdZQ== 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=YL2CKQtR3hKwH4rwW9T0JOOnxDya8ZhtjXoYp3XFWPw=; b=hJ+EBXgvvx/xVLCTfkBaVTLav9zPT/vTwclKZdNUp7UjHG65zhwEVSZh6KR5hxtBQ0 raKVCFhLPKkkdHzJPXJsBctb4Ky88J8mibk5LDwMFg0OfXtPN+nF6Ax2d9FwvmCaEPQP 2jZ+SMBeWpgaEF91sznMYEVDn8uwrP0e0vc1Hsoxz6E3WVsARpejcZJafWk5tANxS1EA c3YaLH1GsvvsUaZxyZ2P/6GXbUsKG+VMI2Tb1t/WskGilBEiOz3UvZ2AMfb+rSc//y68 RiywEPcwvNO0HE6NXCNoP0ukFx8FA0Ub3q/aMNNW4h4nhw0e018L3fUZXqNqTtYsrIKl lGYQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=L8xIBjCa; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-69626-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69626-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id il8-20020a17090b164800b00297f281691asi768511pjb.98.2024.02.16.17.22.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 17:22:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69626-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=L8xIBjCa; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-69626-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69626-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 C67ECB20B1F for ; Sat, 17 Feb 2024 01:09:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2CE99208D3; Sat, 17 Feb 2024 01:06:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="L8xIBjCa" 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 678711E889; Sat, 17 Feb 2024 01:05:59 +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=1708131959; cv=none; b=H5YK78yQfdI1eUIfNWR2Fow0gMX622f4DVKDD2kJzL6oE5cgmvRX+fXy8+46bSxiF+1geLeaRIYGlAF0cpI2i32oxcyiM9Ay+vvKmUGkkz6osXNtqRdgjVdVAuhrmBMRIDiBDdkkwygOfMtqAdM4HYpJ8CYHol5m/6JH/fv5h0Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708131959; c=relaxed/simple; bh=Qt8ricOYsTKcXJqQzKSKsHiM2MHdHGBlaBkQ7xeVb1w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=K6q51ue4tCkcrRvh14h4jf2lq5DVsG3FlTLLJWklsUHUUeDnFF6WSSbZrj7gC7E3VrVgh087GB/7UbsJjTsH1rxtHBaSmQ+YCc4RUookdTDqvO/dKCIGGjLzlU6iOYtn9QQEYjv9b832buVbAw/JKC8GgKZo+KuuBT1cs8CmtYc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=L8xIBjCa; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85202C43390; Sat, 17 Feb 2024 01:05:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708131959; bh=Qt8ricOYsTKcXJqQzKSKsHiM2MHdHGBlaBkQ7xeVb1w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L8xIBjCa+dP4TX6pBp3oF6oHj02qDWwzqY5w06pu4FHMPm4oM9+4GnK7hf5lo+VW6 2PhfKNRoQPgxXisBnnsAXZ5oj4v4uKt3qaRh2dMgYSzp74qIOTG36ECnrrKJWd6Gxp +ecvRyAQwM3x1JuJba6WXapmpAKCdm8eSRGiU9p8mkN1XxFjmPHIhoWKTiFzdiJQs4 9ZK2Gchk2QqCFqUS7c9+oZoeDjD7SyQ+xcnDPpBDiWeZtpaXTNx0xGVkdlYOzqvP4t ESOs5SV9vbgJoDEkCAm5iVKsa9Qt6LOu34Dp8u1jevaN5YhRuDc5pe+VVlc7noE4gq tJba78OWDOnEQ== 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 v4 1/7] of: Always unflatten in unflatten_and_copy_device_tree() Date: Fri, 16 Feb 2024 17:05:50 -0800 Message-ID: <20240217010557.2381548-2-sboyd@kernel.org> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog In-Reply-To: <20240217010557.2381548-1-sboyd@kernel.org> References: <20240217010557.2381548-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: 1791107190363619480 X-GMAIL-MSGID: 1791107190363619480 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 Sat Feb 17 01:05:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 202542 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp87267dyc; Fri, 16 Feb 2024 17:10:22 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU36lYiA1TydCxv/YQX3Bhb7lFNI9+axxN71S0xfHQVBANdjVTgU9JU7AvW6bZxJ2EbHBPP0hy7JJjVH1ySZTVCQQmb9w== X-Google-Smtp-Source: AGHT+IEPsrwFc/z1oW4X19VxVCFRy6HVtUI1kXUoQMiY0JKb1mHNn3a6t1hQchXuTbN5JNsZlO6O X-Received: by 2002:a17:902:f68e:b0:1d8:aada:a7f5 with SMTP id l14-20020a170902f68e00b001d8aadaa7f5mr7453761plg.11.1708132222306; Fri, 16 Feb 2024 17:10:22 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708132222; cv=pass; d=google.com; s=arc-20160816; b=iqKT84PT1I6Nf9pr0x26o+l05OgXRQXaAGICM5DDiueEzUexymVWwXOWgXFfD/Cr9U zosrJqjB83sMu2IYB/oAmINoc8apiaYcA1hP+Yz0ErV3pqb25sBsfRv/KADhaY0m7LSy R+JxjedjZzo87co5kQMoCmmN2YwM1p3NzhWtmQ4lgAFm/IZ3QClifFicEXSYS7HeOqaB hz2wEkYKlqjU+Wl9cqWZ1uYQdaOIkE7Tc7nqUI6hZpxiuv+38wAIEGHdxoHY/9MFDmU8 GkmI4dWD6R3Zxo4e2gJ+gK4HYxE+cBZGL04zFK1dIKDFFjVEs1O6qaeSpIpgOVYNRlhf Ys+A== 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=DfuSqny34FTyvIax6XVMYeba2imfEJGlYeqlhgKMUH4=; fh=R/gIXN/nmdWOBYt8u4a8BOYYdlFigy1MtQckky2cQ+g=; b=jHHFFUkYcsEQl07c3m7WZV5XrWj6Hm9xz9UY3q4Jnl7/Itze3OQVb1ytZmcCNpA5Xk LoVhxs8K1K6rQQwqwAsIpr1ndCzgbHvlb8GdOWizqncJEVnzprxPIkYvwowoPPavJbZM eOlBsTXSzgE/0YofWipw8qXe1tmIaALcgmt7ldWoOYx8oUntCM2LSYREURAXJrcSyVUt G5APyFJ3Cu8mfwc/pJS9ePKsLHjT0CdYKJYP+jGnLHp0fQfnNnB+G4eexpF8nKf1Yl3m oWcxEH0Cvza7FVxrdxDiBXUDXSv8ygaQSJujIzYebn9wygs/ZU7DLwpkXi3z5UlW5EJm bq8w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SSj1rfpd; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-69627-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69627-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id iy6-20020a170903130600b001d8ecf3d0fbsi673102plb.511.2024.02.16.17.10.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 17:10:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69627-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=SSj1rfpd; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-69627-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69627-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 96C732841CA for ; Sat, 17 Feb 2024 01:09:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8A859210F2; Sat, 17 Feb 2024 01:06:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="SSj1rfpd" 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 16EA41EB48; Sat, 17 Feb 2024 01:05:59 +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=1708131960; cv=none; b=jAnyvgzOFqi2/9rDKoRasGB9kJvk8EGqFWKZZOBA/L4JPZf8USqq0clnpTTgqdy8QHLKNQqb/gGwX7C4w6lz790mG3N+WUQeIhksCAlBOwMcxbG20wxXTfyZySbj2Vh1FqmSby7yiCrs6XeE0IRxsK7CMVb53uqFD2R7vyXCORU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708131960; c=relaxed/simple; bh=Adk2ER9i3tlkVMjMvc73lVWXC0x+6cw5DiD7ugMcLx4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=H5KeXRlX91iHUHpIdIYUWvvtJ0AcRPz3WgJ/hvraXUJPSHAPvcElnRER8BVWb5vXorbfEsaWWp1OowR0RhA3Qdjrt962DAI1k8RNQvFhTPQn3y+sqo4bURIzA0O8DQifmeKDwEJc2cVOvGUtr0Caf3Nww5M9+XflNsq6GSKEOWo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SSj1rfpd; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 23BD7C43399; Sat, 17 Feb 2024 01:05:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708131959; bh=Adk2ER9i3tlkVMjMvc73lVWXC0x+6cw5DiD7ugMcLx4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SSj1rfpdp/LgJBx9pEFSrJOk1uA3JTbALooINRtm6utHvyq4jpfyeJ753lfzkz5pz HiIpJ1gyqXRxjur5l5XGhE5mm4Gc101MEJ8Ti2BzAwdOjjkgTieaui46RyNap7jTcW ReBay+Gh0CGQ2GKK1csuJbykz3QFLQJaXNyempBYfsnOwCeq1YFN2fCZld0q0ZaV4H imiiXhAex0Ts68id4UoTYc74JQFf3Rclqarri4dij9FVDlS9aPchE//SXbkRuXWgJn DMRjZmSQGb4uw1yOw58RHDtRaFQc8gdWqYdiWPGMBHjOpp7QtONgltEGWpfNDTS3GQ vyhdLagRyADEw== 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 v4 2/7] of: Create of_root if no dtb provided by firmware Date: Fri, 16 Feb 2024 17:05:51 -0800 Message-ID: <20240217010557.2381548-3-sboyd@kernel.org> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog In-Reply-To: <20240217010557.2381548-1-sboyd@kernel.org> References: <20240217010557.2381548-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: 1791106453093868718 X-GMAIL-MSGID: 1791106453093868718 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 empty root node is used. 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 | 5 ++--- 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, 55 insertions(+), 18 deletions(-) create mode 100644 drivers/of/empty_root.dts diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig index da9826accb1b..d738fbad9c36 100644 --- a/drivers/of/Kconfig +++ b/drivers/of/Kconfig @@ -14,9 +14,8 @@ if OF config OF_UNITTEST bool "Device Tree runtime unit tests" - depends on !SPARC + depends on OF_EARLY_FLATTREE select IRQ_DOMAIN - select OF_EARLY_FLATTREE select OF_RESOLVE help This option builds in test cases for the device tree infrastructure @@ -54,7 +53,7 @@ config OF_FLATTREE select CRC32 config OF_EARLY_FLATTREE - bool + def_bool OF && !(SPARC || ALPHA || HEXAGON || M68K || PARISC || S390) 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 b7708a06dc78..39c0ceee3e95 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -510,9 +510,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 Sat Feb 17 01:05:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 202547 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp91876dyc; Fri, 16 Feb 2024 17:22:53 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWykE1HBrkjurYArhGr3HqepQtNqRpv5zyXWmRCIExsGf7LdYSYfUP+LQ7UgGCaOyeh1sxbhkGtSFZACr+kKOzv5JzfIg== X-Google-Smtp-Source: AGHT+IGFUWf2Kl6OzxzBqp87nOTKpI5Dv2uzFbAG3LLyEguJwAUmEpnIyeQ4bC+SPx0KZEhZNgf8 X-Received: by 2002:a05:6e02:370a:b0:365:1578:8c17 with SMTP id ck10-20020a056e02370a00b0036515788c17mr2600818ilb.2.1708132972988; Fri, 16 Feb 2024 17:22:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708132972; cv=pass; d=google.com; s=arc-20160816; b=lz/Ol59eathz/1trQVST2PnOnJDRhfQv97KLUXniz2QdAu9lvfVAqtMxnYRjnypgNh H76hvbfYZ35AzM4+y8MaryQjxrRKdJD0PufDqPBk/x3PB8LZwgQY60ujcxeOxwy3X1jO XvKjPHv66TPpE8H7aXO3jcXTnU8uSaVt16EmMle2unQGhvXNdd6z2DsWNYBWCZbvZAvG KYJWuHwLojvLWB11wOFOQmpuAJW7ma6eKsle2cMxZky0FiqSNhXbuQNTh08mTqjkpHzZ SaoEpRhkRtRUaj7nL8iI7UliGax2XkJ3dnHpH/KtGpvO81/hkAt6qiHnKiIqWnYzsduE aSHw== 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=fu8ZVXP+jo7D5EaQ1/47p5cYa+9qDZG+rGOe1sBHnWk=; fh=sz1LeV376A5PAD24wWsZ2HxecezkpG42RO1kUhR4ZVE=; b=G2yAvcdw+ZjDjTSdMUX5X5k+tiQd7knkpbpyMuXRDot+gnj7z4LVf4b51FWDqiw2WW sCj5uRx97RPyYl9uPn8Z7Jcf4lzaGLUz77BzS8Xkjv5RV6NYmEm/qePCt3nbfLTUJmCr cww0TH5muse6qb+s4sLMWU1y4cTSQ3e+2gylvtGEuzwYrjRGKAYVeXBOW5Sygr8CL1Wb zwcwunAzxfM14CArAYEDKeJUstgJrONBaRL1tjZtJII+I6klCze9ZEESno4GIs77Ouka H33eH2DfzqYdrZwQUMmokk+uwEeU4G6ODPXA5CE5I0Fm+Yrj6iSpUB0YaIWMmZ7tH1St KZ4w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nWHPrdK5; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-69628-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69628-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id a20-20020a637f14000000b005dc8719cdfasi702402pgd.298.2024.02.16.17.22.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 17:22:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69628-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=nWHPrdK5; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-69628-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69628-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 C6227B224D0 for ; Sat, 17 Feb 2024 01:09:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 86E5E210ED; Sat, 17 Feb 2024 01:06:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="nWHPrdK5" 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 C7B2F200AD; Sat, 17 Feb 2024 01:06:00 +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=1708131960; cv=none; b=hGhvUpypWcAef3fk7Kxsgi+YPWHKRqXjhvSqYMdmq974s1c15ysXi3gR1LZe4Jj7flw5j5OIOlawu3vP2e42ffnR4sJezwg7qHEmlqJ7QXiV9gKgUNIYo4m+rJ2NzLgbmiqqUMu2eajoq32vVxmWUReFq8PNRPq7VQXyI7hTGgw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708131960; c=relaxed/simple; bh=bAiFEbT58TXbP+zf0tFWIGODmRi8LJ7psP4/tHXmMrI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oipN2FitzHPpQwjTmbtft5MGZAoxajicanu/Uft9bBX/lzx5JWGNLo7ixPXY9Z+xID/wl+dP/OP6ji/2eXylsTOGydGFQg+97IE5K3O9QeMGKMFASRWt8dFdNzREft5vEa4sPu4DSe7hLPV+N9icjQnCHXIbxEmtXEd+aGJw3Cw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nWHPrdK5; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id BBAC4C32789; Sat, 17 Feb 2024 01:05:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708131960; bh=bAiFEbT58TXbP+zf0tFWIGODmRi8LJ7psP4/tHXmMrI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nWHPrdK51ANKmmUE3NqJATrEVu6sf4ZIcdhvGIb1FIOmfGEAlBBUzElIK3HXYvtau HM8OPq8HMxmE9tV8EHUsdjlUrBVacmJLtTFqEgDvSIkYu//JsuZnSiCygfMUAUP5p2 WzURYNN7LTNRzRNRTMPM9s9UNIbyHCFzBjQQSta0mjCFfUeA2MLNLYbltHu4sA/nRK xAhmAwqIQ5hcPyyiybY2EYhSeBudz+h/5mDdVenucdfsF+wgwIZur9UXrCkkKGQ4EE 8ioWUb7gB4t06y/Xgd2WQLhkZe9z3EacufoevPtfc57OygRYn0npOjK9jtlF4dknIo FNcCYQOdi1FQw== 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 v4 3/7] um: Unconditionally call unflatten_device_tree() Date: Fri, 16 Feb 2024 17:05:52 -0800 Message-ID: <20240217010557.2381548-4-sboyd@kernel.org> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog In-Reply-To: <20240217010557.2381548-1-sboyd@kernel.org> References: <20240217010557.2381548-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: 1791107240204795543 X-GMAIL-MSGID: 1791107240204795543 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 cfd60e35a899..891752a20a5f 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -4087,10 +4087,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 Sat Feb 17 01:05:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 202548 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp92126dyc; Fri, 16 Feb 2024 17:23:30 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWYsJgjqHcyJUEPBu//q/3iKhbvMcBSnPomPxohU58DmhnNUXL2uj607OlylagQjcOKr7V6f7uKcuR7AZ7toCBFcZg+OA== X-Google-Smtp-Source: AGHT+IFJXgmPQP8D07Cm/zs5MBRbl2XAgaD51HrCl6T9xAQHmphnRFXaDytSc7syrzxPM1+YwG+5 X-Received: by 2002:a17:902:c085:b0:1d9:657c:2769 with SMTP id j5-20020a170902c08500b001d9657c2769mr6356153pld.19.1708133010767; Fri, 16 Feb 2024 17:23:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708133010; cv=pass; d=google.com; s=arc-20160816; b=yEZTb+tn15Zq5BLzkSl8jnr1wvpsgpIHJdxA+spJIkUy6fBTfuA9lZ2tEXnhjwKH6n iQWiSOChGaVbo/5XHsWViaK1oh1UaAn3SSyUKOTM0ZtljvbVr99TErbBBOpHgx2gMcx6 be/bAv3p+kFkkRNpAHvJmf8TNxVFokFqM05XRJOhvdslZnBRChcI6Iq8k032Pa4XB/+Z Raf/4AQOARKVlE/+LEHRgxk5fNJ4gYCVT9iT1avuwqEwp1PahgoqTA1Uoo5rnRIRD3OO 7SKUqupQby3TR3c56PQoxhGlJqk77bCFhixiocBtH8J9G99n0zdC04WNvGpsAmiDPdz9 VXWg== 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=YWxi4pmLeontrS8EkVTzHt4J8Of/kxPfQuPQpS8fPKQ=; fh=sCGGrJtNHD0fFefXPDGWzK/Cz39OQ7Rn/T9JzC1H5zk=; b=0GKFOaFLBnCAIyn79xvSz0vKbwYnf4J+dHQYct3Qvul/IHLBu73b6ffpeUKQMmR0/j gPKRtfU9LlvhQd9aqnvprrLUS4iOzJ+14ZqcibF6OGT42UPj47sSRJAOL6GXjh8AGpbW zr2kRDJGE/BZlVLCiWjzwPM321P3mVkgwvUUEAXS7Lei7sKrz86kKkj4094zQVSi4cO8 cB1KelMo4s41gACkB/jWih6mu0f1N94oKRHU0C7lRHoxFVV9kOllgPBNguGeM1z9Gjhl +nkIbC9QSqnybi9k7OEdfH0QxEEaXjwQHJHzX0api6gfYLjgY8sIrFyZdF5pH/C7CN6r T6Vw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OLeOAuh9; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-69629-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69629-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id i16-20020a170902cf1000b001db4210203fsi710807plg.122.2024.02.16.17.23.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 17:23:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69629-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=OLeOAuh9; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-69629-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69629-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 B1FFAB22550 for ; Sat, 17 Feb 2024 01:10:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6E7AD224CA; Sat, 17 Feb 2024 01:06:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OLeOAuh9" 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 BBE0C2032C; Sat, 17 Feb 2024 01:06:01 +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=1708131961; cv=none; b=mvrC1NehippbRrF7VFHsY/a/fyhWPCC3SZUo6SdshYr0rBqMYrF2bwHL7iLFWoETjZRnZkIbegDD1QMdIv38O17udZRhI4sDVR7uky43FdAtGAcMuWuZ9nLfwgo3tK91o7GQLxyBF/aRS8KPB4pT2omKshqsa02aI1K4RlA8wCs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708131961; c=relaxed/simple; bh=cR6lBuTsNe2p1GQlv5k9m41XDe+JPSu/qcoX4YFfeKQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QIef8BijBt+j81klcq42PA4IhK1boAlOiAXb1kwVFvtnORPO9KCj01mMVHFSUGvnaS6xJKfW2gq0MX7hQeMgfp3zCtz18NzQoTFqvQtPV07yLr3YxbfV8pQyCFie1QNRLK/afpK/IgFVSbYpc0Wt/L5b+PghWUOw8GnGk6ibWCw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OLeOAuh9; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7F5C5C433C7; Sat, 17 Feb 2024 01:06:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708131961; bh=cR6lBuTsNe2p1GQlv5k9m41XDe+JPSu/qcoX4YFfeKQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OLeOAuh9JcnWjMkP28AX6Wosr7CaT8IJDTe++OAPlHmV45oUdqI2baYVKvuONQLRM REHahxweGolZgJoq4cIcJM609d280RUEZ6QOylnu7b84K0JrmRW4grtFnLrDKr7DHm od2AR/PNbdj2WdEHoiw6v8AipspdwQHYwREzjurg2ModO/udqB4MN4PvqStRsntvhO wln6USBTGOZIWd5lhk/LBgFW7h/6nkbg9ak53wpgvk1GtkpGxA34gf8jlkqNrtppj+ JGioc/KE+Kekqcl6YX6Z2urk1MRDsmJJzTSr56lOvTWTsRk1loY1rrmLedb/9jx56h wnp6VBWh8/MAQ== 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 v4 4/7] x86/of: Unconditionally call unflatten_and_copy_device_tree() Date: Fri, 16 Feb 2024 17:05:53 -0800 Message-ID: <20240217010557.2381548-5-sboyd@kernel.org> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog In-Reply-To: <20240217010557.2381548-1-sboyd@kernel.org> References: <20240217010557.2381548-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: 1791107280029222501 X-GMAIL-MSGID: 1791107280029222501 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" Tested-by: 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 Sat Feb 17 01:05:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 202549 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp92322dyc; Fri, 16 Feb 2024 17:24:05 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXNwbGOda4qwD5ZE1tVvpjxZtYzV+RC4nByteufWEWv26TsHdtPNnvORvy3f/CNVZUDVfQvr1/nvVz5ulMb7+SylmjKSw== X-Google-Smtp-Source: AGHT+IE4pygy7JHBA1t33kDbH5nSkczWX9lH8M8jX+nwGNK8Z4JQkGPZnLZHnXB7jTWhoscgZL6Z X-Received: by 2002:a17:902:c20d:b0:1db:aac0:faf3 with SMTP id 13-20020a170902c20d00b001dbaac0faf3mr3039855pll.69.1708133045470; Fri, 16 Feb 2024 17:24:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708133045; cv=pass; d=google.com; s=arc-20160816; b=evd8UuXO+15wXtO3uyYbXKSBCaJpKEdbWS9UnrTxFj3409deqX5c1bwUQaG7VTb8Mw v/MlItrUhvb9yB99+QCoBFxI43hbhA6F/olD0Wy9JxWvrDXYXVtEiE9PnJDcNSCGvxPb bB6Ig1r1JtYU3+cNwu+WnkrUX1BezkjfH9SFqu4gU0Sfv30Bz5GPBsU8DSQxOeFra/9N AzNV+3ylTig08VSOCNc5KR/iYtCYXYu7yARO3+o7UTQoem4aCdSn3xDX0R49aEA5O0gu gU66eYmDKD1znVTGbvk/HnFItzIFap+zSpX793kdKmpLUR+RpZR/9xyxjD/DPhKt0Dam Tusg== 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=f6Ys8FPEhgXvqlylTOVJOo7KlGjQhGaUKR9xz0jyv0I=; fh=9xLTKyG5LLeWwVhC/s1cfm3V7bFxJkLIOBVCvZG8d5Q=; b=CjSLuAufo1xd9bWl/uAdeMB2phaOr7vpvM2T0mN7YR+A9ZPpbksvk3UoqK6lHhQfas ejOwBShheay/Oqw/mCZCCgnVa/30Si4j+lLz2gD2IVEdDIZ6H/982Wx/8ROWRau+8AtP sKkXt2yxlUfofSLIZiINY6zPIek992yx0CU+o6zwdakhtM1wv4NzKPWxoyMknB1XV8+2 A+qoKST2t92MdPS/2EIl4eHlX0jVC3bpSfIANKP7Flr4Z8PhR+nXheZfqkjZYFFdULy8 Bi5M4Vqe2EBII6wBiYy55p5pZd+XyrbQS6CW5sgxWlKMs6sqWWeYnlSGpl+1UsPe9CU9 JF2Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="mLu/fetq"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-69630-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69630-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id j6-20020a17090276c600b001db4585552bsi655398plt.426.2024.02.16.17.24.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 17:24:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69630-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="mLu/fetq"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-69630-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69630-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 4546CB25867 for ; Sat, 17 Feb 2024 01:10:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AB21B22F0E; Sat, 17 Feb 2024 01:06:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mLu/fetq" 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 08A5620DC4; Sat, 17 Feb 2024 01:06:02 +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=1708131963; cv=none; b=dOLlFoESSts2UCMHKLQiZhmY22N4DHzqqcwsIJE4ZTnpQ7NMhLzpWmIuh0LyYXidL5QAKicPrtxiOSZa1zZbEH69wZPnEGejkUfK2rBiGSZqTujCf2cr7WnVrcdalLb5pBSXA+3u7EescOIMHODRy8COY2Ye+D8Yl47HTFj7S+I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708131963; c=relaxed/simple; bh=1HWmL/t+ml480s8rBnTxQKeWVgi/0Mqu3CbJKyMEIU4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=W+y5L5PyH+VYeBMySDzAvoDfhvcv/XurRPybcTHWByhSoTEFIJAI3R8QZ3+SQyLBBtqEZQC/QlbKVOt5wECkAFUmLqFZXbCnZAvV3FklFDFzwROa1f80xj6v8GsHYBPMNWNr5JaSbn3vvE+ea0zDZeRWv27vdxIYyrYwxzIEE80= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mLu/fetq; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 68291C433B1; Sat, 17 Feb 2024 01:06:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708131962; bh=1HWmL/t+ml480s8rBnTxQKeWVgi/0Mqu3CbJKyMEIU4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mLu/fetqM+cb3tFtOHS4DOL5HzdsL62p8HCA7st+6zWovNRgJDBAgQnu6PXC1+c9G HFZmLUhjJAsUY3SYQrxRX0DJ51MCTu7WUqyLaRDBYT0p7U3hhqasKo3LofYMLnFUmS wyRODHMZMXZEjB75NprcfvwHNV/GncU03JL5Uh+3ni6KVVnTXs0sqEPcJRHZZ5VUhZ KDwZy/JMZPFcz3N3YG14+nEDcPwAloywz+fsCh01BgyNBj0GdXEtQLT9hc25xBrUQB JooWdwLPYjQZABiqq2n0BCu5ZwpDE4wcww/s7bAxn5H8dLXJcIiin859FkSNqXFBMd ex/bdl98FQEGg== 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 v4 5/7] arm64: Unconditionally call unflatten_device_tree() Date: Fri, 16 Feb 2024 17:05:54 -0800 Message-ID: <20240217010557.2381548-6-sboyd@kernel.org> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog In-Reply-To: <20240217010557.2381548-1-sboyd@kernel.org> References: <20240217010557.2381548-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: 1791107316263439254 X-GMAIL-MSGID: 1791107316263439254 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 Reviewed-by: Oreoluwa Babatunde --- 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 42c690bb2d60..0d210720d47d 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 Sat Feb 17 01:05:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 202543 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp87470dyc; Fri, 16 Feb 2024 17:10:52 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU3Tyo3lONF+jA17vHN7CSS/QzoAVFOeCUbwCQY86PKDuxOil4m1WBM55HmqUYmjFVWVzAltHhyn0xPPLaFRWFqUKjGWQ== X-Google-Smtp-Source: AGHT+IHgD8QEiBlLTBxvy4nW/zQjyA1otTNMfJt67lGAGJFu+GtuNX+jowLj5ZSTzhkvFvvso9/r X-Received: by 2002:a05:6358:56a8:b0:17a:f91c:8269 with SMTP id o40-20020a05635856a800b0017af91c8269mr7180605rwf.1.1708132252190; Fri, 16 Feb 2024 17:10:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708132252; cv=pass; d=google.com; s=arc-20160816; b=F3wy8CgxYX/0rN34wtvyszXR27I4c7AT38+50V8MrAYv0zqgYU2ewoo8eFUUsLlS2h HPpeZ/bInVmQ8o/DuoN90OdNKENawfqBo9OyQM17gRfnjyNoeUcD+ZDr91n3Kv6E8OyB ZaSWxttV0vcZ+US0GGr/7ey4Ono5J8MgZOR2wD4YjFB8P2UhzUbehn9wKCf+rkiH6HZC PUmBYJYmc1lV84gKeiSoS9+keyyeMq+CQYnylkHlKunyDOLYd7ifmX4U+QisJ/DmL6bW ZXYNgf9GSzdJWxep8h1u0U97kynOuh4hgASISKlc3y7nz2+LxjpPK5hyJNZArPZ9q77O vmUw== 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=ltXg5dLqXeEAw0B9ekuGlp0meqmOfPS4K+bnj0EGYEw=; fh=R/gIXN/nmdWOBYt8u4a8BOYYdlFigy1MtQckky2cQ+g=; b=ElKO8nPbfNoxw4lKRe6B3p37wuScc7iQKgeyE7nMLwz6jJ5IpzNFm965dzKf6IPOkK APRhwB1ejD+0DkHA9j6EpW3CwVJxs32b3swn7+CceS9DCYY0VvdYoIitOsC8kCKzErAQ 1TJVjbRqFD6qX/El9nGrhpCs0TvWVj8Wc2zYx6d9Ja2JUmgsxEJtv3OntYmR7lsHfK4q OszAUfBddGzWCo9M//MyBtnXELu6df6bR3aheD/+YVxn5fvcKRwz49AfrdNk/G6jxWwc z+TysCyDdloygKl8xdAhwOpohY3DibXEm5S+zt+Xdhd5DRXVhaGOYz8XqXht/XXLmaBe odhQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fR7K0DPm; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-69631-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69631-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id k66-20020a633d45000000b005dbdb1b0114si686608pga.773.2024.02.16.17.10.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 17:10:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69631-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=fR7K0DPm; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-69631-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69631-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 63C36283B0B for ; Sat, 17 Feb 2024 01:10:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B540222F0F; Sat, 17 Feb 2024 01:06:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="fR7K0DPm" 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 204FB20DC8; Sat, 17 Feb 2024 01:06:02 +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=1708131963; cv=none; b=RE73TTL+6qFg/1fDj7myE63Rrv+tWv9jr9giny4sYddvPJg2UWj8tX7fqhC52aTWcEclOHksiNq+DTbAAosi7Bg2+tyTCQeXl+eloE+NES2iE0Be6VqDxIS1BMMdbdlJmMIQ1SyD8v2ZFvLEPWkOpgaFjHqzGeneMYeMjJLeEHA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708131963; c=relaxed/simple; bh=a4ZJdi1g6SmL1slfPXA0Sdc1BiW+RCSDLbBzSuVLxg0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=amxE400CZoowsYw2zfkccLCxp1YC3F4ttIa8iOZILzt8MUB4b0Id6ZmxwrPwWrUGS3BHawDBfk3NcQDHnCidSL0mMUdRCxnOwpvajLfKrO+jGHmnjphmDOcxcj8K+gEtL+wN8uWVljmTlnMKV7cjqD6rpBaB/M/+oixXJX1J57o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fR7K0DPm; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 294E0C43394; Sat, 17 Feb 2024 01:06:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708131962; bh=a4ZJdi1g6SmL1slfPXA0Sdc1BiW+RCSDLbBzSuVLxg0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fR7K0DPmwLwliOjcvLTQMYx/yhvXd+Lt+J20YtU0eJg9BBupTobaTXvHDKz0ElN1w lyN91Teoqb6L2FiUFaTin94ppj2bXx/OQ+5Zh9nlGBCkw98caMK44i80kS9zuogCk7 mhCc644572dUf8Iq4dDijMBDhsqAR1qvwJuMq095NWCspfbOK6Sumcdd6hlvus4rY5 pJtJzorxKorAn51SisFu2bSBgpRVzJ6rZw7i2j2hIexRCBfO1hTtdhdRp1aExld7zC LS7kGmSBV76MFa+4KC96o2AvD8CCs6u81WWqcJQR/bglZGe4WFTGsxvKciZGKD270o ma7B4X6MmNn+A== 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 v4 6/7] of: unittest: treat missing of_root as error instead of fixing up Date: Fri, 16 Feb 2024 17:05:55 -0800 Message-ID: <20240217010557.2381548-7-sboyd@kernel.org> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog In-Reply-To: <20240217010557.2381548-1-sboyd@kernel.org> References: <20240217010557.2381548-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: 1791106484126903917 X-GMAIL-MSGID: 1791106484126903917 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 891752a20a5f..4c67de37bf26 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -1744,20 +1744,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 Sat Feb 17 01:05:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 202544 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp87518dyc; Fri, 16 Feb 2024 17:10:59 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVaJiW+ZnKOHEr9q+gcpn47xI4dXe8zK9VZwJnvCgUtqo3rRmFXGWMSPNsz0PMYTuCEJWkTPAp1d1oWQM21KWTTgIacCA== X-Google-Smtp-Source: AGHT+IE/ZlGlmYIUoJCK233GYjmTKCRoeeTKB436Xu0+t2KU6qVjT/Zb3hC+c+Cx6tyKpZnKRQ7F X-Received: by 2002:a17:902:db01:b0:1db:5ecd:1161 with SMTP id m1-20020a170902db0100b001db5ecd1161mr7352678plx.51.1708132258904; Fri, 16 Feb 2024 17:10:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708132258; cv=pass; d=google.com; s=arc-20160816; b=Ji8zqKKeo7gWOkodAqknr07N24edzBA6usNM2hJvYGWY0Ohfd6Ej2obumHgdUFmUrJ lFi+D9gvd+s9qxrefUffFwv5yHnn7s5dYFeFq80nehSGEn7De3fzPnbeQlQcYRX496yY A6HVuHt9lEN4YeXkGGycep5ZniIpUUpcXf1Ef87NVkypU66zpNAunLY/ZVmIB7L7H1r0 2pHyQ1p4SrGHcaSRqURaZTY7SOIegfI9nc60R1Tk4Fs+/Euuh7waCdlcaBiwYW7RfL0v flMF9zYytXEkqjw3mnDWwewSmhWWPc2jHw/HXib7+g6ArEa5huhCrbW5ahEkV8hCah5d 83Jg== 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=OTFQw0Hn2uCZGL+HqUSSxUyu22cZBVpRF4Ub3VDWb2Y=; fh=NN905Bm5DOuizDfzVeBP5HotAkNpWL5aoKUnZb+ES2Y=; b=xVaMcgXyOwkZ8z/Xlw97IujJ25Qlq8484Un0r4v2SjZeHDMMhZYJ+X30UEOsDz3F05 27SWPIPSP0LuXfR+SrkwG4FYdjVLCk03HVk9jYW8wrUtHUIvYm3IO5e2u14QutobxbXg ATIx+C9BUDvRTqSQ1xxxcOtP33D25esodlBp737fNKYoAxihYk74f8wTm3xwwA/6gQY2 TO+nj+8Ju4wTLwOx0k/JLJzIlfUK9viC1uwe3VZ9UWKr3bNBIhmu6F4Ij14AcuoFcPNY Wry5St3WssZIJgusqn6Xq9NEAK+TD9C/d6SaFO6LepoqK4OF2J/KADSo/BU3Ph7JeOQC v3TQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=EAOa4fi4; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-69632-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69632-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id iy6-20020a170903130600b001d8ecf3d0fbsi673102plb.511.2024.02.16.17.10.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 17:10:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69632-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=EAOa4fi4; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-69632-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69632-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 BF8BA28338D for ; Sat, 17 Feb 2024 01:10:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6F22D2375A; Sat, 17 Feb 2024 01:06:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="EAOa4fi4" 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 C07DC21112; Sat, 17 Feb 2024 01:06:03 +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=1708131963; cv=none; b=uIsQBiCmGM3StojGfCjgMquuorQ82bKQr0lVz1qxjzG/adnq/vZP9n4Hr34epCfwoo4JVz1TccCWg95TJ9upTS8+0GimjvQiBF4zVPWqjRmHWCmpP16eghHO4S63eeSZsFT1XNqabuFlomwsMK0h3oFrlvKO4SsYCyS3txKBneg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708131963; c=relaxed/simple; bh=J3WMalAjgz0rnHbmeT8QD4FpP4dD0hu4Yj+NzkEppQE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UoYrz9lO0oishzan+DgenCRJe2Xzc/3NpM1q4L+THlZXVmhNRSwZIkIi1tP0bBXZaa/5/hpUjvSZr6Ba3R8FG0j6z5Sr6OtfJxz7LqcwSAv9uPvIBA6SZz/uuT+Z39n344FcsoqvawWxbpslx9lOYbhmFAGoxUq0AzXsq7X7yRQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EAOa4fi4; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id BDE8DC433A6; Sat, 17 Feb 2024 01:06:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708131963; bh=J3WMalAjgz0rnHbmeT8QD4FpP4dD0hu4Yj+NzkEppQE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EAOa4fi46Q5W6L0e8l/qgg64ROvD783Ms6lXCLYZpxVg35KK7iz4ZOPqJG55vnPGq 3UeRnJKaA3I3cKg6k8nOeUWz9METclLEOdD2v/vwKpzE0krhoMDcnzcf32fLp60VJM TsuqeU8cRg0jhmjmGbtWhR66ChQwQ7qIhwKmEc6mNkXVzW0mVxPXvpIFCOvDJP4Ug0 5GQ1D1ccdPvjJlEHgSowFvSe0mQgCZKbefm6SWMC5Ip+4IplYU/9M+WdLtT1NdVNNg COT3rSgSj0bQbQPCU6igti603mJcNcGUWeyv11PFrXku2BBWdb9jKivpvYiB0ZyZVU Kkj8/nueN6ZGw== 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 v4 7/7] of: Add KUnit test to confirm DTB is loaded Date: Fri, 16 Feb 2024 17:05:56 -0800 Message-ID: <20240217010557.2381548-8-sboyd@kernel.org> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog In-Reply-To: <20240217010557.2381548-1-sboyd@kernel.org> References: <20240217010557.2381548-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: 1791106491523891937 X-GMAIL-MSGID: 1791106491523891937 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. We skip the test when CONFIG_OF_EARLY_FLATREE=n because in that case we know architecture code hasn't called unflatten_(and_copy_)?device_tree() which would populate some sort of root node. Cc: Rob Herring Cc: Frank Rowand Reviewed-by: David Gow Cc: Brendan Higgins Signed-off-by: Stephen Boyd --- drivers/of/.kunitconfig | 3 +++ drivers/of/Kconfig | 9 +++++++ drivers/of/Makefile | 2 ++ drivers/of/of_test.c | 57 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 71 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 d738fbad9c36..dd726c7056bf 100644 --- a/drivers/of/Kconfig +++ b/drivers/of/Kconfig @@ -36,6 +36,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..a9301d293f01 --- /dev/null +++ b/drivers/of/of_test.c @@ -0,0 +1,57 @@ +// 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 of_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. Remove this test once of_root is removed from global access. + */ +static void of_dtb_root_node_populates_of_root(struct kunit *test) +{ + KUNIT_EXPECT_NOT_ERR_OR_NULL(test, of_root); +} + +static struct kunit_case of_dtb_test_cases[] = { + KUNIT_CASE(of_dtb_root_node_found_by_path), + KUNIT_CASE(of_dtb_root_node_populates_of_root), + {} +}; + +static int of_dtb_test_init(struct kunit *test) +{ + if (!IS_ENABLED(CONFIG_OF_EARLY_FLATTREE)) + kunit_skip(test, "requires CONFIG_OF_EARLY_FLATTREE"); + + return 0; +} + +/* + * Test suite to confirm a DTB is loaded. + */ +static struct kunit_suite of_dtb_suite = { + .name = "of_dtb", + .test_cases = of_dtb_test_cases, + .init = of_dtb_test_init, +}; + +kunit_test_suites( + &of_dtb_suite, +); +MODULE_LICENSE("GPL");