From patchwork Tue Jan 30 00:45:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 13536602 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 D2974208C6; Tue, 30 Jan 2024 00:45:11 +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=1706575512; cv=none; b=QIgOTOip6OvZ6L1p+rrvP/PdZI65C6/L8vxpy6aNiSUdm0LvqKFFeZL3b6Z0haXMGNfbAACkIsddwMJMB7/RygScRwo4yBsJ10Pq2PwMQykHk+nD1z5dSk4upI3KV3ONcfvo1dYDwbnv+Rx5ZZUnvzA62qKt/on55F4QEEacRb4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706575512; c=relaxed/simple; bh=VXgzDqWTdPwPLTS+PDtQWtuCy7mpsGpCkHXI8WBQloU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Nhy/rI5rCxedljbzEJRjE7NYdt3h9MO0SknzAP+pLOtDs9JTKGwPcx8xcU79u8ZMS/qO88AQPW5/Bf+pYTX7D8Q0FfYLuQjTHmxfo3Z4eSfXN24dn33dLpEXlzOwb0P/XozLXZn8zL36LWtmeHVURl9JMhJthwaT4zB2IWh3Qdg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HXXuBRXI; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="HXXuBRXI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D15EFC43399; Tue, 30 Jan 2024 00:45:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706575511; bh=VXgzDqWTdPwPLTS+PDtQWtuCy7mpsGpCkHXI8WBQloU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HXXuBRXIKUnxuty7JtrN6gOE8EGXiTS/vVocrxqVOHD9u8eXJPZNAcWujnPKBxo1e VxixGTBUgU4e8M27QVG7vbXDPLdWyZaI2WBJ0ie6g+nRygM6aoSBqy9s3cPhVrF80A 8e+ipwBOhmcCAq5w1f5FrzEifL/zkRxhhz1IOxIVxIqv/LbCD5pKRoRECjmsxnJtXD sEpg7dYiG5yiHGRPRji5Q1tD2vIC8GqNjBHLc+xPsuJe4rNQHxIBu+qlp+KZuRPmx8 /9ZHH+fgKf7RppPgtpnyzdafGQ5MHgepOcTqIXjk+DAG6R0tsKb3gAD8EnkA9cxhuV v0+sc6RClMpTA== 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 v2 1/7] arm64: Unconditionally call unflatten_device_tree() Date: Mon, 29 Jan 2024 16:45:00 -0800 Message-ID: <20240130004508.1700335-2-sboyd@kernel.org> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog In-Reply-To: <20240130004508.1700335-1-sboyd@kernel.org> References: <20240130004508.1700335-1-sboyd@kernel.org> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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. Override 'initial_boot_params' to NULL when ACPI is in use but the bootloader has loaded a DTB so that we don't allow both ACPI and DT to be used during boot. If there isn't a valid initial_boot_params dtb then unflatten_device_tree() returns early so this is fine. 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 | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c index 417a8a86b2db..ffb1942724ae 100644 --- a/arch/arm64/kernel/setup.c +++ b/arch/arm64/kernel/setup.c @@ -351,8 +351,11 @@ 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(); + /* Don't use the FDT from boot if ACPI is in use */ + if (!acpi_disabled) + initial_boot_params = NULL; + + unflatten_device_tree(); bootmem_init(); From patchwork Tue Jan 30 00:45:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 13536603 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 78BD72E40E; Tue, 30 Jan 2024 00:45: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=1706575512; cv=none; b=L+VRFm7UR40tlEOCpWdkS0rT21EaqcnTZbcPO8emlJoxfcuROW7oGhsB9SLWVQrdqm8hsRd9LOddGYY4JzgAnEW5CvHmgkbuthcpPgkRTTeWeq+VBBBYmmOL8B7eRhQEkVMJQjZnvh3SV3dmk1WZ7HmMncV06RoPV0kYTLOajnM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706575512; c=relaxed/simple; bh=hCAh9IJVjneFBmTI7MeY6517yfTJZxfzJ8kdqiP/+uU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Bbq25jltsK+ePEgsIr4slaqedm01UB1MlNqAA2lSlzdmrFEiuHkD+cGd5Gp5q5XrBGKp0RP1my87FPRzyVoWcTnRmxxeDX7b9SZh41mPSfA4gEpGimp3deyRvvMzmSQ2+gMyIdJwpzA6apcVhEE7DC52mM4nYWvLbTGbCJ3WNlI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BQW+DxdZ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="BQW+DxdZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 88633C43330; Tue, 30 Jan 2024 00:45:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706575512; bh=hCAh9IJVjneFBmTI7MeY6517yfTJZxfzJ8kdqiP/+uU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BQW+DxdZHpADTKR91v4ppHkYQ9+QCKgvfLROiSuscRQCVoMwzgo9BkRP9t9Rzty6I hQgE6xH0BVaMuJAnGsZVpUTZS5T1isEPfc+PbG0YFm0ajE8H9pnCAtL1ONUGEa+PdK 5vGsUjPO+1tJEBKbpbgo7Ohq85IS/HcI8yqOxCOj1+0L97hmbkEl1sl/DuyrLYgqFG wkegUbFNEMkuAulGBRt+vVre0qdMwKrGUfyksKhK4dqFT8g2VqiwdPUJI+XlGmk7Hb 5XSKpvg+ks/MYUMJIGucojwHElxhYMaKL+EopAKboMDnd1KT/SL0wKjY8Jvbr8i8Qv N7QCp2+WUyLJg== 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 v2 2/7] um: Unconditionally call unflatten_device_tree() Date: Mon, 29 Jan 2024 16:45:01 -0800 Message-ID: <20240130004508.1700335-3-sboyd@kernel.org> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog In-Reply-To: <20240130004508.1700335-1-sboyd@kernel.org> References: <20240130004508.1700335-1-sboyd@kernel.org> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Tue Jan 30 00:45: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: 13536604 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 2391936114; Tue, 30 Jan 2024 00:45: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=1706575513; cv=none; b=iUQR5ux9RJFJ/h8Q8CMxvb8aZzQ4+RMySJetha4oaIBPG8uEpqktxJ9eShkVa+kYZKYFkk+7mhPmlkRiie0Q3rcQVr96Ls3byhyf9l/YV+WklQ7tQTIwU6gHgPiKuHxvxJf75sk48vOyA5VC4dg0gEdBKqM+YPs9kDAGfQ/FtlI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706575513; c=relaxed/simple; bh=RoHfW0J4DhoHi6CIUbHFtKoJEfAKysJC1Fo3xRXVigg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=D65D3EVIGKgalq+KrU0RXv9UUKLoNBrqm7IhhRns+xaILorxF9TArSpUSiIab3QiYa658HM39ClVaBtgU0XaoIAB4lMHSKzifk1SYY0v5EOeStaIMIIOjsfmtLDKdBcMnhF+VbJNzqZXsUUrkqlh6d9kkan9QGKJy+bgqUfkqyo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qAgYYRtb; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="qAgYYRtb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 430F2C4166C; Tue, 30 Jan 2024 00:45:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706575513; bh=RoHfW0J4DhoHi6CIUbHFtKoJEfAKysJC1Fo3xRXVigg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qAgYYRtbWJ5viR41vOf0Q8IcMgBCtlOzDpcv/45U9U4fYJYMSujLD6JfR2osY9ATY 4bStYc/TK7bqQzxeqWCsW9bvUgnTTtJJ8FKM0Kme5fVfrFfuPG6NDEZ8G+M9fe+crH 9ByGZOm401zpjqEGrrIHWvkq3Y6jn2TnJD6D7vJtCKzLG5iUGLZNqtGPq5D9/aESld EK4qSV4IXVc7i2yKDT4qA/2Ji5egQXFQIAAjoVgxvqb3Gqfsyw5YbBpJn7iyNgtMCd qBIGYbb+stxyLQrNEHZ+Z413GV36NRwX4SrxjuMtQxugmXLfho8V3HuuGCNZNsblTL vBQ1Ri0YWWNSg== 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 v2 3/7] x86/of: Unconditionally call unflatten_and_copy_device_tree() Date: Mon, 29 Jan 2024 16:45:02 -0800 Message-ID: <20240130004508.1700335-4-sboyd@kernel.org> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog In-Reply-To: <20240130004508.1700335-1-sboyd@kernel.org> References: <20240130004508.1700335-1-sboyd@kernel.org> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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. 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 Tested-by: Saurabh Sengar --- 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 Tue Jan 30 00:45: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: 13536605 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 15742364BA; Tue, 30 Jan 2024 00:45: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=1706575514; cv=none; b=dKVzWGO/VeyJuEegVdyXfe/CfYoF358obfPho4AAgRQF9wFmYPKTllmvo5jv2OjhT61dA/caIWA8ZxpvfxwGDyS+2QOqAipve0FMUMNNviglCvEvGtnYp5xk1tqO57jSBpCpyENduDVd60Oz9sXThB3b4vYAzCekLjuJDqS30pI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706575514; c=relaxed/simple; bh=1E4tLOV0ALY1Bfj9SzYihrCA2jRIId2N3gEBgK6iS+E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ShYGM9ShXNFrjPY1MYQF8dpWnMoNBqKWctu8GVe+yZY+QOQZH4FitKjHA6o3f7TaRyWj3UAfkFgkMpFY//wFUR2KUA/D39rH3Q4EIF7djsRRFB2YIotupVKiZQNxRRXh3usm39swDVF1aeGYQyhobk1OR+l6Z6RimASFcmc3uPI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Iz2zfn9a; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Iz2zfn9a" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 24BA9C433A6; Tue, 30 Jan 2024 00:45:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706575513; bh=1E4tLOV0ALY1Bfj9SzYihrCA2jRIId2N3gEBgK6iS+E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Iz2zfn9aqvK2c8BkZWCB3BAiuj857Wo7xdv7e2MGsiieVxtEq3tzTJQUvFm9+NaW3 PpxGQgfXslXyjDpqx7Cpd+3+ZAsqiGC9De6l1kwIHpC33MneTUcp0h/9TYnUuRaZPa tOIQo6Wjnc9dW1MXMwmUtGjqTyePE19xg4Y9ddsWcSXYierDRxrSujqGPcarNVHik2 5RGpnD6SxyNiWWdaVbtmJcXatXlru45w+1Gyy05Y2KfeZvClAbpN0YVOZ+Jv6IOzcZ eeUPiglgbn2Gc/3/k2jKOR6kXFwnoZ7eSy9AEPMgRlbKwt0e6lGMsLAbRd8tX5Ztwf gQGwkNDOAS8iA== 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 v2 4/7] of: Always unflatten in unflatten_and_copy_device_tree() Date: Mon, 29 Jan 2024 16:45:03 -0800 Message-ID: <20240130004508.1700335-5-sboyd@kernel.org> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog In-Reply-To: <20240130004508.1700335-1-sboyd@kernel.org> References: <20240130004508.1700335-1-sboyd@kernel.org> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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..b488ad86d456 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) +{ + int size; + void *dt; + + 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 - 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) + copy_device_tree(); - 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 Tue Jan 30 00:45: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: 13536606 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 80A9A36AE4; Tue, 30 Jan 2024 00:45: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=1706575514; cv=none; b=Le0lmI06wpZyXSwmmycs6b2lnPJxZjv7H2jr2VJ/08wkqeB7heKE4gEjX2ljvN9u3njLqA0bF8BJOGETdsXSRHS2cPyLdHlL1zruZQkNQiQlg2brnZoTDiCFVtMQRu3W4qbRgz/kwSOWGkf9+gpPjJx2ELKtYqbKbXFrjGhryF4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706575514; c=relaxed/simple; bh=hmcfZcHfNINwBnAg8u+eyBX+W/WQoRq0BbThFhRJmxg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CnoqbjTUSw1ldmr9xyIXIK/A911Coh4RV5SMSLnP7ylZHJ2pTEhaEGp4J5/QGmRPFD4X5/ALGEldoMe6VTUpPjYUDbyqo998FCt2esJ8NOs1YkQeBuYrZkvxoRNYzvVD1oBniJownpwf1KQ2GhvtJN8AamwYL6JKrHHplTiHP48= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=A6YZnVON; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="A6YZnVON" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B1F29C433C7; Tue, 30 Jan 2024 00:45:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706575514; bh=hmcfZcHfNINwBnAg8u+eyBX+W/WQoRq0BbThFhRJmxg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=A6YZnVONJIKoy/aVneDUKE/lqzWcU2BV1YPk4r+b+C9I38byOmV9GCQn+hoctkyW6 LYVIFGJRtQujgpvrTeirMXRuUVx8a/ulHPU4mxeeBAj9AEGfvZr/OUUT42u225TeR8 t7I4K6v3OxP/6nVIFrzs6cPOi9ubK8zGJvYCVML1PTxYkbzxt0Uf2KLIFfjRmNL5sZ 2RdWip4f+M5eU03Xl9IIoLxvUuAnaPmI5xkWjTnOB3afu9RPVJtf6LBbz+sqKGjmUV PmK049tUWVQqQzN3yLMG0xH47ynpdvOZiG8w+XqOUgTh3cNuSIwHZqX85wB8g+oUkG eW/9F4M5gh2KA== 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 v2 5/7] of: Create of_root if no dtb provided by firmware Date: Mon, 29 Jan 2024 16:45:04 -0800 Message-ID: <20240130004508.1700335-6-sboyd@kernel.org> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog In-Reply-To: <20240130004508.1700335-1-sboyd@kernel.org> References: <20240130004508.1700335-1-sboyd@kernel.org> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 | 20 ++++++++++++++++++++ drivers/of/platform.c | 3 --- include/linux/of.h | 25 +++++++++++++++---------- 6 files changed, 43 insertions(+), 15 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 b488ad86d456..f7dd7fd68d4d 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -32,6 +32,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,6 +1350,19 @@ static void __init copy_device_tree(void) */ void __init unflatten_device_tree(void) { + if (!initial_boot_params) { + initial_boot_params = (void *) __dtb_empty_root_begin; + /* fdt_totalsize() will be used for copy size */ + if (fdt_totalsize(initial_boot_params) > + __dtb_empty_root_end - __dtb_empty_root_begin) { + pr_err("invalid size in dtb_empty_root\n"); + return; + } + of_fdt_crc32 = crc32_be(~0, initial_boot_params, + fdt_totalsize(initial_boot_params)); + copy_device_tree(); + } + __unflatten_device_tree(initial_boot_params, NULL, &of_root, early_init_dt_alloc_memory_arch, false); 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 Tue Jan 30 00:45: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: 13536607 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 D91CE36B02; Tue, 30 Jan 2024 00:45: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=1706575515; cv=none; b=CmdTnOzxV4UL9ifg2zEv6f92Nn554VgpRdi9ZlhPugrGca61PaRoit63GPHHHP6UnqrchI+hc5YwdlTZOLHNFLydxcyqqX3OlHCjFdgRmzArWx5ya5lDSAUcYLJvs3vB/9RC55Hsfn0q8RDbnbMXs9y5xBoJfwQ4XEtWlyBcYbA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706575515; c=relaxed/simple; bh=QNmBS0brQeJSjUserQhzHk2Vt2IzcbhX82b9CN/v9CM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=emrrLAf/68NPd7ZuNnZCeNsWAVZcKU56fWYqXCutdKLNZ3tDHzSbTKRTTvkutd5EPhbPb9PanyKJ9+LLWbckQxX4UjFMu5xh7PXnmIacZV+ydkzVEAGvL/Oog9Wuw2oUzF/IeZdw8PFHJZzzP/rz6Cmk5vo/Q1SThHfZ0ZeHH5s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oAvRw3fA; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="oAvRw3fA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4C548C43399; Tue, 30 Jan 2024 00:45:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706575514; bh=QNmBS0brQeJSjUserQhzHk2Vt2IzcbhX82b9CN/v9CM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oAvRw3fAoNWjiVmINtzMu5LYHOPzthZ41RXtSehMcsOa5hH/n47mQJbwPX2YmtRQH bzWW1cBevhWm3guAvl0N4bT/8Is877dtInpWAtotrWqzYO0DdFYikRUBbXY+71z0iT /pv5C9PH8rC3AmSPrzXXEB7xIE4NlYtlu0suj1aSB3RA3o39qzMCUBpl27IdEdtupr jVCILCD5y8v/gEjL2xzgqAcFMBCJySfXA1Gwxafe26t3L/H+BORWJN4ONXYV3gI5gH CVpyf+GvJfjjAqShbWztM2Npaan26dTC/XaAATjqVlON4splpFImESEFk1h1AOMSWI +kqrvevHV7aEg== 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 v2 6/7] of: unittest: treat missing of_root as error instead of fixing up Date: Mon, 29 Jan 2024 16:45:05 -0800 Message-ID: <20240130004508.1700335-7-sboyd@kernel.org> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog In-Reply-To: <20240130004508.1700335-1-sboyd@kernel.org> References: <20240130004508.1700335-1-sboyd@kernel.org> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Tue Jan 30 00:45: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: 13536608 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 8617D3716F; Tue, 30 Jan 2024 00:45: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=1706575515; cv=none; b=kE+xAXOnLgozS9uHXvZlFkRTCGpECq8K6RvW/Z+BBwsd7461/0TzulTNxXS9bxBebdEVG/2gS4GtCVsYJR2zbwmZbasRNsJzO0zYYbqEPnNyUPRIn0bRQ88zhjJotEpVRNDqVIMV8WEpFRnAhucnyMufWVkN0fAyVHXzhZ2Y+CM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706575515; c=relaxed/simple; bh=PiweXFroDHF7yXaa82SMFRXH/FDbm1RzgiHTih6bLA8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LVlxJzGg/RC1xTQiLKm8w98HNxbY/KrcpkoLEA5heqfwXizIuwy3U+waXDa0/X0PRxhisHMGHaAv4KQ83j6v/7+DwJ5zFVfsj0bR/TrGDezEPgCauRPOjvvSomJQyFMMcV1eneDWZemjRdjC+VY42mNirJGlTTp2AhvUHw62U7s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TzGOXf0x; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TzGOXf0x" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DB6E4C43609; Tue, 30 Jan 2024 00:45:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706575515; bh=PiweXFroDHF7yXaa82SMFRXH/FDbm1RzgiHTih6bLA8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TzGOXf0xtEnuBMKuXJA6vqerJOp0D0uIDNQFWdGOH3l33XbaHnYJ9I3mYGODL2xxv FvYYJep2tflHq4V0UcqCEB2qc3z3xiIyVM65MQ8F12kGMHIq0zhX5iTNd0OwzHK3uJ +D5rvAm5GRr5SPCQ7vSVXDIJvzCWbXCZx1R6KdhL5mC8W37TCpLc6jZVKmF9iSNWQJ QLggfDM/lA5RPUFdkYhPg/HyXl5R+4b4rdKWSsuxduScfg/a0lFoiNIhC2yqRQoXdj ajXgXI0puNc540MbLYhob5cDaQwc0mvu8sBP/DHUYcm2YixEL2Rpls3ikHYNE9Xsnw cWSsF2qgM1ovg== 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 v2 7/7] of: Add KUnit test to confirm DTB is loaded Date: Mon, 29 Jan 2024 16:45:06 -0800 Message-ID: <20240130004508.1700335-8-sboyd@kernel.org> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog In-Reply-To: <20240130004508.1700335-1-sboyd@kernel.org> References: <20240130004508.1700335-1-sboyd@kernel.org> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 --- 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");