From nobody Sun Nov 2 22:44:54 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1746550343; cv=none; d=zohomail.com; s=zohoarc; b=ddzIOrGvfPov27CfUyCX3pGZzul/hx7iuvzWIEGYnwSR5vTHUnqBQJKOW9WONYcWaD4z9DaBYyuIQQLfwvJy4XOR2qSBuAkIvqJn9OaMSQHHhlE8+O1Cn71LTdzIr1QRrsnZYDWVQNdfCNrNcv9gtStRW77GSDiwEiNdQ2CLjGU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1746550343; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=z/SOhxgkw308OBnI/WK3THzBCPwOXi+kerygsTpNW/c=; b=X5NfLCDs6wWqpvx5s15RJr2NyK43fvhBr1y0GqYIgHIcVJx1iySmKd+W6dJ6FCp01TZ/b/6+QnWciezV0qtdrwQa+U+7p3xtAhU3vfB0sxJ/DQzUbb0g9AFxhozgwshk0uuQSmc+5ou2BmGKs7QNz3VJR/MAwOGShASHuLm2fns= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1746550343260485.75514269768894; Tue, 6 May 2025 09:52:23 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.977626.1364642 (Exim 4.92) (envelope-from ) id 1uCLWZ-0006n6-0L; Tue, 06 May 2025 16:52:07 +0000 Received: by outflank-mailman (output) from mailman id 977626.1364642; Tue, 06 May 2025 16:52:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uCLWY-0006lF-Nq; Tue, 06 May 2025 16:52:06 +0000 Received: by outflank-mailman (input) for mailman id 977626; Tue, 06 May 2025 16:52:05 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uCLWX-00058E-8i for xen-devel@lists.xenproject.org; Tue, 06 May 2025 16:52:05 +0000 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [2a00:1450:4864:20::633]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 70383527-2a9a-11f0-9eb4-5ba50f476ded; Tue, 06 May 2025 18:52:04 +0200 (CEST) Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-ad1e8e2ad6bso10302866b.0 for ; Tue, 06 May 2025 09:52:04 -0700 (PDT) Received: from fedora.. (user-109-243-69-225.play-internet.pl. [109.243.69.225]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ad1891a3cb9sm740295366b.60.2025.05.06.09.52.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 May 2025 09:52:03 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 70383527-2a9a-11f0-9eb4-5ba50f476ded DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1746550324; x=1747155124; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=z/SOhxgkw308OBnI/WK3THzBCPwOXi+kerygsTpNW/c=; b=D4NOB6ptEIxC5npJN0Sk9fwO6z/0WMtE/RYMOvzbgeXd+iAkzP8l2xyP8YWYwaFgkW H8GMJaJEQ4iddQvRffS52Gc4JzYUsIedTgATvXUtGMi+x3Chr3qeK9YebVIyx2SSUslY 2q8PEPV7vUnxstz3LONA4/3wvXEqkgadVTHeMBW4Cjs6e3UrVQWdsFZWUU138UW/Rny8 s9+UcyK6YoxCucFPz8ZOQ5TFgE2Ik/2mzgj4j9rEoYyjLvUj/xNZ8YbCHagF+KCW3dBv d6fJYhFLFCNaCD6AHhZuE0JmBo5T0W6zOGceNnde2MkFjcEbhaQW/QrmN8RFl2Q1iEXe ow8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746550324; x=1747155124; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=z/SOhxgkw308OBnI/WK3THzBCPwOXi+kerygsTpNW/c=; b=arRqC/O080TUGHsM8aBTb/ftlJqPoYCP1zgwi82hJBq3WXY7TGSE2NmauzWXa4t6fi J534qU5CWhxC1W7gwI2VlkZF9p4gMybYbzJpPdLIha1EtYhVgD5j1R1IU1LFeAXae2BI NXiuiaYdv9UD8QqNoARkHeZa18ZEovdd0uthgLf8YjeltBgxNlVMIXV17eVi54flmb3h 4U/GnHdKvevaEQxFF98CMq9HncasBfFBlXSUZHXKKAHn5bXaT79RMQzURftLkgL/6icr y3U+9mSwkOs9zlmD5JM95V3+4TjZcG7ofO8F/00Y5jj7MAen0MaGKjs3r51iIbYLRiVI m+6w== X-Gm-Message-State: AOJu0Yyx34/xt4tpn0L0WsZxGUQ0gZ1LXh6WKpTPN7cqVHSB9A3sEomn NCUMh/TB50qGirgMFhbw6C4tsUFpW2L47NgSyCWBdBQSD4d3qZ6GjVPUoA== X-Gm-Gg: ASbGncsGvQkJ+8U9pVLH5w4rXah0E8fUJLjUmZ5h+ghpN3KKqBxODK/kSTa5k5LrLuW q23bay797GPnOy0h9/ke4whGpyF5YpOsYHCdi/Jhueeqp8p9HKXOTgGXvWUx584timmspqMWaMu JB7ntrEiTkkmuMrssGPGA4yVGrKrRNKnbu5cVIFGeY3Flt1diLMGPSHfpBmVyQKdj8q3WUNMFUl T4dAhAFoePJCDa1gwRJ3i/wlVvthRZDTtRk5sxkHWzUgQXw7QocaTwr6BsqQreMQPDhcTKko1/5 s7+HJEh6v6cubrJtpg+QL5UFct8s2iB/NTiQdn4dvTZKP+w99KPpaYTlo0bxk9m62rMMwyHyzsy JzBw6DwdJUQ== X-Google-Smtp-Source: AGHT+IF+FS9dHY4GSxXwKN6enokBJRUqaQYv2BAPkxz/tU1ShkpWmC/odJCtGf+4FrCKRACOPu0VRg== X-Received: by 2002:a17:907:3e9b:b0:aca:a539:be04 with SMTP id a640c23a62f3a-ad1e8c8bfecmr20744966b.4.1746550323669; Tue, 06 May 2025 09:52:03 -0700 (PDT) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Oleksii Kurochko , Alistair Francis , Bob Eshleman , Connor Davis , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini Subject: [PATCH v2 08/16] xen/riscv: dt_processor_cpuid() implementation Date: Tue, 6 May 2025 18:51:38 +0200 Message-ID: <4e4b3a018e8dacbe85cc080d9209e2ba3cdf4330.1746530883.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1746550344684019000 Content-Type: text/plain; charset="utf-8" Implements dt_processor_hartid() to get the hart ID of the given device tree node and do some checks if CPU is available and given device tree node has proper riscv,isa property. As a helper function dt_get_cpuid() is introduced to deal specifically with reg propery of a CPU device node. Signed-off-by: Oleksii Kurochko --- Changes in V2: - s/of_get_cpu_hwid()/dt_get_cpu_id(). - Update prototype of dt_get_cpu_hwid(), use pointer-to-const for cpun arg. - Add empty line before last return in dt_get_cpu_hwid(). - s/riscv_of_processor_hartid/dt_processor_cpuid(). - Use pointer-to_const for node argument of dt_processor_cpuid(). - Use for hart_id unsigned long type as according to the spec for RV128 mhartid register will be 128 bit long. - Update commit message and subject. - use 'CPU' instead of 'HART'. - Drop thread argument of dt_get_cpu_id() (of_get_cpu_hwid) as it is expected to be always 0 according to RISC-V's DTS binding. --- xen/arch/riscv/include/asm/smp.h | 3 ++ xen/arch/riscv/smpboot.c | 66 ++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/xen/arch/riscv/include/asm/smp.h b/xen/arch/riscv/include/asm/= smp.h index 5e170b57b3..9d846a1338 100644 --- a/xen/arch/riscv/include/asm/smp.h +++ b/xen/arch/riscv/include/asm/smp.h @@ -26,6 +26,9 @@ static inline void set_cpuid_to_hartid(unsigned long cpui= d, =20 void setup_tp(unsigned int cpuid); =20 +struct dt_device_node; +int dt_processor_cpuid(const struct dt_device_node *node, unsigned long *c= puid); + #endif =20 /* diff --git a/xen/arch/riscv/smpboot.c b/xen/arch/riscv/smpboot.c index 0371dfa53e..0b00dd0eb2 100644 --- a/xen/arch/riscv/smpboot.c +++ b/xen/arch/riscv/smpboot.c @@ -1,5 +1,8 @@ #include +#include +#include #include +#include #include =20 cpumask_t __read_mostly cpu_online_map; @@ -10,3 +13,66 @@ void __init smp_prepare_boot_cpu(void) cpumask_set_cpu(0, &cpu_possible_map); cpumask_set_cpu(0, &cpu_online_map); } + +/** + * dt_get_cpuid - Get the cpuid from a CPU device node + * + * @cpun: CPU number(logical index) for which device node is required + * + * Return: The cpuid for the CPU node or ~0ULL if not found. + */ +static unsigned long dt_get_cpuid(const struct dt_device_node *cpun) +{ + const __be32 *cell; + int ac; + uint32_t len; + + ac =3D dt_n_addr_cells(cpun); + cell =3D dt_get_property(cpun, "reg", &len); + if ( !cell || !ac || ((sizeof(*cell) * ac) > len) ) + return ~0ULL; + + return dt_read_number(cell, ac); +} + +/* + * Returns the cpuid of the given device tree node, or -ENODEV if the node + * isn't an enabled and valid RISC-V hart node. + */ +int dt_processor_cpuid(const struct dt_device_node *node, unsigned long *c= puid) +{ + const char *isa; + + if ( !dt_device_is_compatible(node, "riscv") ) + { + printk("Found incompatible CPU\n"); + return -ENODEV; + } + + *cpuid =3D dt_get_cpuid(node); + if ( *cpuid =3D=3D ~0UL ) + { + printk("Found CPU without CPU ID\n"); + return -ENODEV; + } + + if ( !dt_device_is_available(node)) + { + printk("CPU with cpuid=3D%lu is not available\n", *cpuid); + return -ENODEV; + } + + if ( dt_property_read_string(node, "riscv,isa", &isa) ) + { + printk("CPU with cpuid=3D%lu has no \"riscv,isa\" property\n", *cp= uid); + return -ENODEV; + } + + if ( isa[0] !=3D 'r' || isa[1] !=3D 'v' ) + { + printk("CPU with cpuid=3D%lu has an invalid ISA of \"%s\"\n", *cpu= id, isa); + return -ENODEV; + } + + return 0; +} --=20 2.49.0