From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (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 E28A9309F09 for ; Mon, 17 Nov 2025 17:52:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763401950; cv=none; b=MuUjxXo9yyKUf6EWDKEebx012P6v7OntC1OoLA4kUFZ5+sLTKhWaMWBuARzKhjWpoeQxwvK/qgw0N/LEXiaPhfTGtqOFeKXP2b0U3ew9/tsqlqP50VLFvzO13gan6+1ue1r/c5z92NIL0q/wX/TepRfpCpvhTgiMvGeLmYevDGg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763401950; c=relaxed/simple; bh=j7juR+/XVeJU4C/31V9mX0gDA1eA9e1XUKn5lGCO8HU=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=WRrrA5B9BFtUSqJ4w+Ak5fYMNlIqVOZF7Ts8xJ2fIIH5t0uWIRe0S7zNVwD2ytwMsa2AZq7KRm57trjwDpIXW2v0eLiprHDXQWGQY+RQEjSP2W0epx3op8jxK8qna9PlLgpthMtEVgMzLrlfHuKV1ACazi9nmH2GEGwe9kEpUPc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=Prlmxie4; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=CyTnJpGj; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="Prlmxie4"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="CyTnJpGj" Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 5AHB2KEE3916357 for ; Mon, 17 Nov 2025 17:52:26 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= guTkQqA6wZDgu5rNo71qMOAbhvUpSh0i6lCnidrmG+s=; b=Prlmxie4+yYERLxx /+OuVVUO+N0fu5c7kFk6VzvvwoABHSUoe09BdigZwZzTmLL9jesvidMNmmvvoT6S j41q0uwKhIcSe0EnTzMxMxcWSyIQ9k+ucbUqpM0MmO1hWGnp+22tKCcvWHMU4jB3 mvYiTwgpATeDCt1GsGix+PC8KB+wZFyDeY2Z5/jMzUteyzLLmdHpYAOdKM2je9rc XiU6iM0Mf17SQP7R/J83OrMgDZgnSjQkACvWKAItw5DAPkPcyI8sVxytnb6H2RS1 sxmHgG2Q/Bywvg2u9QuVj0cmux2kmjvtd34wPcVu+W1u9QmyVahQd3FK9i23Jc9n GAqgnw== Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4ag2fx96c6-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Mon, 17 Nov 2025 17:52:26 +0000 (GMT) Received: by mail-pl1-f197.google.com with SMTP id d9443c01a7336-297fbfb4e53so81935325ad.1 for ; Mon, 17 Nov 2025 09:52:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1763401946; x=1764006746; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=guTkQqA6wZDgu5rNo71qMOAbhvUpSh0i6lCnidrmG+s=; b=CyTnJpGjwDCCo8kvCFmE4Xoo3z8J7l1iftu203GUcGwVZwSGGPQW9IMBoP6a6ciyXE 4HKoLLjSZYPzSAcQBPDFVOuWzF5pDiXhangbKeaKNTX7tsraCQtzFIvsrP8MvSAs7opC 5+gEFvtzxk8B2/zY1fZd9oTGh08zAS29LtiygwGME5qFrV6mRyKQr3nmHBI9jSkfrwLW a+XfSntpe/LJ2eBok2pI03+LUssSWsCNmXbJ3ac+3OzKz3srjM0Od/qP2iO9usKbGWcV l/XoI4Sr45F5bGo74NfehcADVk8aY8xM00dQAeG+QOuADj9QBryiYowdLfdAthBnQx/b b1ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763401946; x=1764006746; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=guTkQqA6wZDgu5rNo71qMOAbhvUpSh0i6lCnidrmG+s=; b=X2oHtD0oq7mg+SXVq24xxJKvUhyDOeskFpezzu9pJEBc4Xjl3Qshpwb4MBtt8n92ze PtEvu+uZdGTwS5CAgO6pZ1rln4cyfx+ZB1mM7M2MfsgspgXV4X+Hjpm/rIqta7Fn3G+Q 6f6r+YKsjJOvyOUB0yBSL7mMe0d22Xrd3sQcnOicJzbw8zZ/w807EK05zC//SCHcwfdn fQVko03o4CqU4UhpdBJHU9XX4UBr1utA4Tkk/du6oxxHIV3c+vRaNq/NAk0C30t6cuce KDRPLzuYRN0da90Cf9vLAojIHDcRYmR13U20IPdswAEMwfc+c1kxKja58GpNrFlK/Ll5 X94g== X-Forwarded-Encrypted: i=1; AJvYcCWwIZcGMZH/GXRJr9D46AI7R3mTWGQY1T+ecQ/2bKHD88468OelR0MVOWTaTXOhSip86zmDYeDijk9dMGs=@vger.kernel.org X-Gm-Message-State: AOJu0Yx1Jz7JqDamiG38urAh1u1rfoBVehBDnPVfT86uPEkZ09JpZQvA +otsDWrzp3k9Y4Go5jD/tKM6NKjPH26YQZtdfYne/Rzo2WAn1NvsKLy2qnzVxZG+7mlNxTIfk80 VhfHAXbjsEuo8ggmS7dwUcIj7rB/mjyTbXvEuvLgqTUWaAkPTGiBGY/pcDra4ZOQsPsk= X-Gm-Gg: ASbGncugrYoS3dvWPYLKkb+H6aT3vhelj+KdwSgw6r2bfVoO+XQb2gzhRWs4a3DWqHj y1UdN3QxuD2vSdsAIAcDikcFArcsje6XOvHg+7Oq86gnNboPh/qOO3itsirxnNDQtPru8bN0Oig GSRdxgOWdYMxcGK0ChhED4D4SpCcf2uOLqwfi1f2/UnSIsLEkRDiF7GLAE3l9WSQdP+DVZyCp/d bmLD9CH6B5JSaNPWpKJNhUC3TbYHF/5PBRfp25Ldui+fVTwDZWrLIz3NAqzoqaY+JpSXGJan3WH a1da8HzuF/P69R2FAfN961Z2H0qWLSmaDfQ2lHVGWkWwvDTXNpD7+s5HBCcx9SoEq/PeQwi9D97 l4PtBDEC8KtS8LLDE3geju4vedvE6XrzodA== X-Received: by 2002:a17:903:3c2b:b0:295:6d30:e25f with SMTP id d9443c01a7336-2986a75e7b9mr143345955ad.53.1763401945684; Mon, 17 Nov 2025 09:52:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IEWRzwGhq1DQhSIpL329PcW06uskMvINMd52o+8rAflr633fNQFaKCidj9r5mpG4u42nnL/WA== X-Received: by 2002:a17:903:3c2b:b0:295:6d30:e25f with SMTP id d9443c01a7336-2986a75e7b9mr143345685ad.53.1763401945207; Mon, 17 Nov 2025 09:52:25 -0800 (PST) Received: from [10.216.14.226] ([202.46.23.19]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2985c2b0d91sm147692395ad.63.2025.11.17.09.52.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 17 Nov 2025 09:52:24 -0800 (PST) Message-ID: <1c2963ff-fa1a-7e28-62bc-51bd2f6f3f5a@oss.qualcomm.com> Date: Mon, 17 Nov 2025 23:22:21 +0530 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.5.1 Subject: Re: [PATCH 2/2] power: reset: reboot-mode: Expose sysfs for registered reboot_modes Content-Language: en-US To: Bartosz Golaszewski Cc: Sebastian Reichel , Bjorn Andersson , linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-pm@vger.kernel.org References: <20251116-next-15nov_expose_sysfs-v1-0-3b7880e5b40e@oss.qualcomm.com> <20251116-next-15nov_expose_sysfs-v1-2-3b7880e5b40e@oss.qualcomm.com> From: Shivendra Pratap In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Proofpoint-ORIG-GUID: MKn4MypANiYvOmW7mYt29I7s3ohzs5Cq X-Authority-Analysis: v=2.4 cv=EIELElZC c=1 sm=1 tr=0 ts=691b60da cx=c_pps a=cmESyDAEBpBGqyK7t0alAg==:117 a=j4ogTh8yFefVWWEFDRgCtg==:17 a=IkcTkHD0fZMA:10 a=6UeiqGixMTsA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=EUspDBNiAAAA:8 a=l74xf_ZpDOHI644j0-EA:9 a=QEXdDO2ut3YA:10 a=1OuFwYUASf3TG4hYMiVC:22 X-Proofpoint-GUID: MKn4MypANiYvOmW7mYt29I7s3ohzs5Cq X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTE3MDE1MiBTYWx0ZWRfX1PlB/sE1Y0FF lKE6OzU9Ek6VwzeKy6ZqGy/EwKvqj8lODGgURnvaIuxpY6SJvUtI2bUu4W6Q18cBxEHAYaD05m6 yywJhHBQFHF/3GgRveZrRWNRUXwzCKJ330HRPs3HNJ1H9c04PNRoRZhIzg7WDAK644iNCzP2D8R rqJPym3U0wV2VKyNW3USyuva3s/41m2kxTTyZuhE0VVL5BBC8zAuJcJN4Q7PG2MtAr0GrngwreM QAbb17VsxTBDjAWt8Kkm+sFCsG3O0oju5W9+8CQZCdKP28GRdGVnnWDtbuM2oBqJp3nNTg15OUx ODdOTum58sxFik/3pxuZnF6OMgAcZEZCMrEKtFln9dMevJTZgRhbE3Iyz/SYB/U6uwVcgqZk0RR 88390KKjhRwN5DU/34JKTGryY8Qsjg== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.9,FMLib:17.12.100.49 definitions=2025-11-17_03,2025-11-13_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 spamscore=0 bulkscore=0 clxscore=1015 lowpriorityscore=0 phishscore=0 impostorscore=0 adultscore=0 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2510240001 definitions=main-2511170152 On 11/17/2025 6:55 PM, Bartosz Golaszewski wrote: > On Sun, 16 Nov 2025 at 16:20, Shivendra Pratap > wrote: >> >> Currently, there is no standardized mechanism for userspace to discover >> which reboot-modes are supported on a given platform. This limitation >> forces tools and scripts to rely on hardcoded assumptions about the >> supported reboot-modes. >> >> Create a class 'reboot-mode' and a device under it to expose a sysfs >> interface to show the available reboot mode arguments to userspace. Use >> the driver_name field of the struct reboot_mode_driver to create the >> device. For device-based drivers, configure the device driver name as >> driver_name. >> >> This results in the creation of: >> /sys/class/reboot-mode//reboot_modes >> >> This read-only sysfs file will exposes the list of supported reboot >> modes arguments provided by the driver, enabling userspace to query the >> list of arguments. >> >> Signed-off-by: Shivendra Pratap >> --- >> drivers/power/reset/reboot-mode.c | 72 +++++++++++++++++++++++++++++++++++++++ >> include/linux/reboot-mode.h | 3 ++ >> 2 files changed, 75 insertions(+) >> >> diff --git a/drivers/power/reset/reboot-mode.c b/drivers/power/reset/reboot-mode.c >> index fba53f638da04655e756b5f8b7d2d666d1379535..062df67735c4818cfeb894941e537f19ea9d4ccb 100644 >> --- a/drivers/power/reset/reboot-mode.c >> +++ b/drivers/power/reset/reboot-mode.c >> @@ -7,18 +7,77 @@ >> #include >> #include >> #include >> +#include >> #include >> #include >> #include >> >> #define PREFIX "mode-" >> >> +static DEFINE_MUTEX(reboot_mode_mutex); >> + >> struct mode_info { >> const char *mode; >> u32 magic; >> struct list_head list; >> }; >> >> +static ssize_t reboot_modes_show(struct device *dev, struct device_attribute *attr, char *buf) >> +{ >> + struct reboot_mode_driver *reboot; >> + struct mode_info *info; >> + ssize_t size = 0; >> + >> + reboot = container_of(dev, struct reboot_mode_driver, reboot_mode_device); >> + if (!reboot) >> + return -ENODATA; >> + >> + list_for_each_entry(info, &reboot->head, list) >> + size += sysfs_emit_at(buf, size, "%s ", info->mode); >> + >> + if (!size) >> + return -ENODATA; >> + >> + return size + sysfs_emit_at(buf, size - 1, "\n"); >> +} >> +static DEVICE_ATTR_RO(reboot_modes); >> + >> +static struct attribute *reboot_mode_attrs[] = { >> + &dev_attr_reboot_modes.attr, >> + NULL, >> +}; >> +ATTRIBUTE_GROUPS(reboot_mode); >> + >> +static const struct class reboot_mode_class = { >> + .name = "reboot-mode", >> + .dev_groups = reboot_mode_groups, >> +}; >> + >> +static void reboot_mode_device_release(struct device *dev) >> +{ >> + /* place holder to avoid warning on device_unregister. nothing to free */ >> +} >> + >> +static void reboot_mode_create_device(struct reboot_mode_driver *reboot) >> +{ >> + static bool is_class_registered; >> + >> + reboot->reboot_mode_device_registered = false; >> + >> + scoped_guard(mutex, &reboot_mode_mutex) { >> + if (!is_class_registered) { >> + if (!class_register(&reboot_mode_class)) >> + is_class_registered = true; >> + } >> + } > > This could be achieved with DO_ONCE() but you still haven't explained > why this needs to be done here. Why not in the module's > subsys_initcall()? As of now, the class will not appear in sysfs until > the first device is registered which isn't a very common behavior. sure will add a subsys_initcall() and add it there. thanks, Shivendra