From nobody Sat Sep 26 01:04:55 2026 Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4D99D344DB9 for ; Sun, 6 Sep 2026 20:29:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.69 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788726552; cv=none; b=jaS0JftewrXZdim0nCI+xnUxw8xkjz4TdpTv+8vwSGp/C8vVYM1ImnJ+ayU/T2VI4fWu5m0HzmBV29Ic4E0nL54RjQymdnDR+CxgUms/QuufRi6TRa9aKAvqpTZULPld209her2XqDErV1ufqHWVVhEF8ccON++bl1kuyz5OUxM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788726552; c=relaxed/simple; bh=76VAeUkXL3BlGk+9tfC+Eq+2Gm+mySXnTdEDQNC4wtY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=DGKuu7XUHGkT/F7pO3Gyy07OKsS7RjOYtEXHuX1cxim5sZkmVdfqcEw+YK7MS14/UNQiKiUyz6cO91BVaALsQsG9uPBSbDi05V/iPpNMvKb4xkdQbyI0E5ZFE0zg2D4/uR5uRVJgb8KjQl6jqc+Ni1AUl0PFdABPyhvmE0ODXAk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--samagazaryan.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=OYMp9zrd; arc=none smtp.client-ip=209.85.216.69 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--samagazaryan.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="OYMp9zrd" Received: by mail-pj1-f69.google.com with SMTP id 98e67ed59e1d1-39512608fb1so6474057a91.1 for ; Sun, 06 Sep 2026 13:29:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1788726550; x=1789331350; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=VbF+m1IWNGHjplX/XAIe8nP/a/sFZGH0R//WnioyHCM=; b=OYMp9zrdiCCr8Zf5+lvkcIgkPNO9tx1Hty/D+MeS914yGxysmH5T2SRX5l+JMB+Yvx chQmid153Oqj+Ckk3Lv/i+AChmyEB3tKeExJDCN4FOh4ZbbOXcOySvf4Ci/0kY3AgqOH GGzEIFkXKDYigkkdsTXJdT1Rx3d+KnfjjMhngEphSivEyYSKIgGL76HVWXR3oh/DnkkS AJEYbZ5ZoRbdZP89Bg/d5eJZ8Ng3jrfYsNby0C9xXx84K96C5P/lrdGyqCD+otkK+cL+ zZElH6r1cTxeRC/HOlTR7jUfGzbZVV7pKi6ap99p0hqhJrDIP/AcnaQQfvDpznFPspPh ILQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788726550; x=1789331350; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=VbF+m1IWNGHjplX/XAIe8nP/a/sFZGH0R//WnioyHCM=; b=ckGnQET62etFEiOOOou+3Lb180x6xcwD0qenTTxBBaCqi1v0YwVIfcd5P2qyelNpyA rn9896lry/qahnxTH+LCV59q0XPzUf/BPLVW3/1zUXFl2k3CvdEMR7a51D7Syp+S2BkF H/bknrNKKVTwXH+zo4G61ymKpIe0+fadhwsUuFlBDqowoIJLkKN0+7AkbAFfkINshwjN sSlwK6QX4TVFx09pSZoz5ls54iXb1mRadX2WK2gzV3QOCbHSHo4uuuvHInmtG5+GY+vb hhAbDVLh06bRp+lloCXXsx/4kCWBI5euTV+46K+0C0KACDu3/GG7VTJnIS7icP4PIOkk 5A3w== X-Forwarded-Encrypted: i=1; AKwUvBzjAep4sBCPjov0yp6GTfRV5CwpE0DVYEGqRFa11nRuIE7w5ncSCnxaOuM0IJICyJNJxr44bG0gQ/mMafY=@vger.kernel.org X-Gm-Message-State: AFuF++kVE0Ierj4PixLk5ZBemGkPcsWJRx7oNXfyOmFxCqLEP0lqENKa J6dSmq1Vbn1UwFiQNR/04gNNp/xwt+3Wam1n47ZF54Hw97q9XJP66hFMN1qH7tqouuoR7dWsWCt UYAN4Q/mtAacOQm9wa3bcsFgQLl8b2w== X-Received: from dybvt2.prod.google.com ([2002:a05:7301:78c2:b0:32f:1c5c:c8a5]) (user=samagazaryan job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:28cc:b0:36d:b424:4f17 with SMTP id 98e67ed59e1d1-39b260e13d5mr28750188a91.1.1788726550262; Sun, 06 Sep 2026 13:29:10 -0700 (PDT) Date: Sun, 6 Sep 2026 20:27:45 +0000 In-Reply-To: <20260906202747.4041389-1-samagazaryan@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260906202747.4041389-1-samagazaryan@google.com> X-Mailer: git-send-email 2.55.0.979.g7e5102b832-goog Message-ID: <20260906202747.4041389-2-samagazaryan@google.com> Subject: [PATCH v4 1/3] i3c: master: export i3c_masterdev_type From: Sam Agazaryan To: linux-i3c@lists.infradead.org Cc: Alexandre Belloni , Frank Li , Greg Kroah-Hartman , Arnd Bergmann , Vitor Soares , Oleksandr Shulzhenko , linux-kernel@vger.kernel.org, Sam Agazaryan Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Vitor Soares Export i3c_masterdev_type so i3cdev module can verify if an i3c device is a master. Signed-off-by: Vitor Soares Signed-off-by: Sam Agazaryan --- drivers/i3c/internals.h | 2 ++ drivers/i3c/master.c | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/i3c/internals.h b/drivers/i3c/internals.h index 86a36b951e0d..cbc00c862104 100644 --- a/drivers/i3c/internals.h +++ b/drivers/i3c/internals.h @@ -11,6 +11,8 @@ #include #include =20 +extern const struct device_type i3c_masterdev_type; + int __must_check i3c_bus_rpm_get(struct i3c_bus *bus); void i3c_bus_rpm_put(struct i3c_bus *bus); bool i3c_bus_rpm_ibi_allowed(struct i3c_bus *bus); diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c index afcd7a21a3e6..e8a9f8c3041e 100644 --- a/drivers/i3c/master.c +++ b/drivers/i3c/master.c @@ -864,9 +864,10 @@ static void i3c_masterdev_release(struct device *dev) i3c_master_free_i3c_dev(master->this); } =20 -static const struct device_type i3c_masterdev_type =3D { +const struct device_type i3c_masterdev_type =3D { .groups =3D i3c_masterdev_groups, }; +EXPORT_SYMBOL_GPL(i3c_masterdev_type); =20 static void i3c_master_shutdown(struct i3c_master_controller *master) { --=20 2.55.0.979.g7e5102b832-goog From nobody Sat Sep 26 01:04:55 2026 Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7EC3B3BD63C for ; Sun, 6 Sep 2026 20:29:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788726553; cv=none; b=TPrnS7Y8GtdbrD5Mk71mDQ5sJtGCAZJIypBSHg5SCLjUcpvtT3OgOtR6x12Ed6LCpyBveVBXomRir7pdz9ha4x5x+bYuo+IcaciMG1mEAA8OsJrfReYalb8iu3LnF40ggdL60p9tK+hSD8/sjwpKg/3MwSpsXA1S18FxfazBesM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788726553; c=relaxed/simple; bh=WNS1zRdSURpkdSXiB7VzYO5YC62mc5b+ZtjBUfeDwSs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=NR4gjR3k0DuQgttPvoDqL6Ul/1zMXy2ssld4kyFlUAhpmlz9LIpR4X/lf/BxDX62pXR0/HlCyadx82G4bCeh2iffLn3dMfa8r3elUEkTddS2qfzguVxBTGzPdnNWQryIfD8kBasbI4qmv+pkJU4ejQ+PSG9wJxWVjS2Ds2E2T2s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--samagazaryan.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=RJqkKu8j; arc=none smtp.client-ip=209.85.215.197 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--samagazaryan.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="RJqkKu8j" Received: by mail-pg1-f197.google.com with SMTP id 41be03b00d2f7-cb835525b10so3507775a12.2 for ; Sun, 06 Sep 2026 13:29:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1788726552; x=1789331352; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=7prt9MlqcUNMzUdkt0ytNZsIrDLRTQGTGe/hvHFR8Fs=; b=RJqkKu8j3I1f0S/Q88dM05quU/MhJoxM95W58yGbcelR0e/8BylEmbQYUQbF2OPDEG xlzw+yPjLx0Lj0sYAPQKo8UFQK2bTWoHiLV8J8FGGf2KnKd6c0E670JitrXxymSrv86I w8H2ci3BbMAIdtyGsFCesTcp6RipUK5sSeTwHaVvEZAJvBJgxF7uF9U6qSY2/6OQ7asF coFXn59tnpMBbQdhlnDOictd4JhXyH96S8uwLOHlDnZXYxRt2CoYsa/9Wq5Seog0c5cE 96l6SZWGqE/+o5vSRANk7DkwJKxcC0qjRH/XB7wEUh6Ef/DLfuQfQBNtNAIjKJTRGkfI 6ODg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788726552; x=1789331352; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=7prt9MlqcUNMzUdkt0ytNZsIrDLRTQGTGe/hvHFR8Fs=; b=rrTEeX2ZGtJmdyEX73gYwFhyTTVx+9JCFLQnc3c8BJ6SX+9H+PZVWIQ92HefVRj1+i VNxE5lXWR6JAAAL28nEw89M2ydYGyNdNa9trFbJctmyoM+ZCM8DD8W+9Iqa1eeeC1vDJ hGO4DACYysJhI6UkF1HiysKYFTLQxpVaMZ4BdXYEWnOQF0rQOireGtW46+msjT++LWZz XGQE2c2AHveXlIBIuttOM04yOf58dlMY/+o7XUH4iXaGxl5i4z9D1oNdwKDEa14s6NrL 0VxDBerW0J0Rp7DITB0bPO6gm3ieplXIIQ87prDN+gPWi1sLYln/cePzWDh+OH7+0gq4 NcZQ== X-Forwarded-Encrypted: i=1; AKwUvBz+XW4gGM1gINrY+y0vz94wPEy4F4cLoRPa6Sc0b0hJdPZoxy4tYEcBkvPTqvsp3wJHSjWV9NALEUp9dEo=@vger.kernel.org X-Gm-Message-State: AFuF++lFkYZ+F+lBQS3EX7kcxeb1d9eduxnzcUzz0mL27xf3haOXZq3q aJmBaI6whFERbaoO7ioqfg3906CpiHtuRVHE38bSscW9nITqpImpgTgR+S8eIf2AWdZWwyUSVAb uhuWD9piHijmDMZSIsOXDEXLkuCGc3Q== X-Received: from dynm18.prod.google.com ([2002:a05:7300:2a92:b0:336:3540:43fb]) (user=samagazaryan job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:6e04:b0:3c6:61b9:917c with SMTP id adf61e73a8af0-3da39cfee0dmr30467270637.11.1788726551480; Sun, 06 Sep 2026 13:29:11 -0700 (PDT) Date: Sun, 6 Sep 2026 20:27:46 +0000 In-Reply-To: <20260906202747.4041389-1-samagazaryan@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260906202747.4041389-1-samagazaryan@google.com> X-Mailer: git-send-email 2.55.0.979.g7e5102b832-goog Message-ID: <20260906202747.4041389-3-samagazaryan@google.com> Subject: [PATCH v4 2/3] i3c: master: add i3c_for_each_dev helper From: Sam Agazaryan To: linux-i3c@lists.infradead.org Cc: Alexandre Belloni , Frank Li , Greg Kroah-Hartman , Arnd Bergmann , Vitor Soares , Oleksandr Shulzhenko , linux-kernel@vger.kernel.org, Sam Agazaryan Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Vitor Soares Introduce i3c_for_each_dev(), an i3c device iterator for use by i3cdev. Signed-off-by: Vitor Soares Signed-off-by: Sam Agazaryan --- drivers/i3c/internals.h | 2 ++ drivers/i3c/master.c | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/drivers/i3c/internals.h b/drivers/i3c/internals.h index cbc00c862104..3c53a5108b81 100644 --- a/drivers/i3c/internals.h +++ b/drivers/i3c/internals.h @@ -79,4 +79,6 @@ static inline struct i3c_master_controller *i3c_bus_to_i3= c_master(struct i3c_bus return container_of(i3cbus, struct i3c_master_controller, bus); } =20 +int i3c_for_each_dev(void *data, int (*fn)(struct device *, void *)); + #endif /* I3C_INTERNAL_H */ diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c index e8a9f8c3041e..dd5071ca9195 100644 --- a/drivers/i3c/master.c +++ b/drivers/i3c/master.c @@ -4011,6 +4011,18 @@ void i3c_dev_free_ibi_locked(struct i3c_dev_desc *de= v) } EXPORT_SYMBOL_GPL(i3c_dev_free_ibi_locked); =20 +int i3c_for_each_dev(void *data, int (*fn)(struct device *, void *)) +{ + int res; + + mutex_lock(&i3c_core_lock); + res =3D bus_for_each_dev(&i3c_bus_type, NULL, data, fn); + mutex_unlock(&i3c_core_lock); + + return res; +} +EXPORT_SYMBOL_GPL(i3c_for_each_dev); + static int __init i3c_init(void) { int res; --=20 2.55.0.979.g7e5102b832-goog From nobody Sat Sep 26 01:04:55 2026 Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D45983C5DD4 for ; Sun, 6 Sep 2026 20:29:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.200 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788726555; cv=none; b=UbJPKCI2kmGCiVVYoo2vkrLgBgV4rpXIYOQOjBEZ4+CgxHDfkfXQQCKqIglSM6Q2cAuoVSTkShfbtcGc86aIxZtRBDKPEgWFm7so37JPvjb02efB9r4gIuyks2zA9CQPulrp1OrI7GqTOWLZZWQfABp3U8XUekWTYdC+fIwaTPk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788726555; c=relaxed/simple; bh=MYilus1I1mRBv1OhcUpWHsqytn8XOi6Xqlw4S+mYzuk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=WDRFw4OxIM5hkzlpZxfoW09hf/IV4fenKHPnUYNfpeVAZ7wlfA/6I50Cp6h2MCJmBWcgAn5esZskq/SJv2BX7GEHD6mLFobhObYIAvCwUjtupDxK9nc3kR2vK6hRxMl6cS1Ppf1VLLecAgKXVMbI4W/V+sOcti/37BdPYOJADAs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--samagazaryan.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=tuwBYSa7; arc=none smtp.client-ip=209.85.215.200 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--samagazaryan.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="tuwBYSa7" Received: by mail-pg1-f200.google.com with SMTP id 41be03b00d2f7-cc1cade6b71so2610035a12.0 for ; Sun, 06 Sep 2026 13:29:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1788726553; x=1789331353; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=N6P/Ig3rqwkwvLCIGd5vysxjswqU7tbeL2/LKN3cT/4=; b=tuwBYSa7aaEqEMgmygM3Z+A6aJecgG/UOwpdjkWQ4q93GCF7SihUyErznmlYNPcQUP 2Yre09sgeYTHpCikNVECDNORb6WsiuerGzlHrJo2hd8M/qqLog2AuUvQWcQFAokKt1Ez 8PgAizqsAUGoT5e0xb1UhdOwSMomy+VbLF2cSPI6Q2fcI+0BVoi1Igw0XkVe1J8Or9Vq nYBOS0rIJQQx2Hbgt746zaMw+a2f8wWFKQexINEhDzrzAiim+/WkGlZYL7K78fRFKw1P UrIGkOQnJRrtPDwdaOa0RFrz3kLTHjqUQWAxJATHxqGUzrMox87rLvaoxwk2givF9+UX 3buQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788726553; x=1789331353; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=N6P/Ig3rqwkwvLCIGd5vysxjswqU7tbeL2/LKN3cT/4=; b=Ghd6ni1YsNQAc8vS6bgHa3JdR0kuJ7RPJgZ8USE3+KueiAW2Vvk5J/xoVPUYndOcz1 fgvHW/DQ/pkzyu8bhk3thWHDGNz6j7sgUzmutoZRJ7IDiEL24uhxSk8hC2obsBAjNCvm CYdANhaA31vtyhQl+clVBSQokqfbm5dlwdc2sG7voRQ/e9j151fjaZTusaOcC+4b3j8p wBjPgeWBpCFk8SYksfrbobPEbd281XSFFuIWNzluZk+6SXICSfxJadeVZvuGn9XuofKh mx3NfzMqoYfU1Xve4CVdtttCy9VtZpDO+HHfRGCvpAszcwlCB5VAIdeqX/ZNMCZMz8V5 lHmA== X-Forwarded-Encrypted: i=1; AKwUvBzNzh3qQQVrwviJOTGm8k4cnPjv6q2H5/lEuJVWVwoGj4yz9QaiRildSGnvyiDGavckWJXDMz4fDtxcg74=@vger.kernel.org X-Gm-Message-State: AFuF++lXmep45CTv6/zt379RlnX7FLRuLtALsBVuifbftuxwvIsNGT/U OwWS56xFwZL+L4PwnqyhurE2RUdE762u3HDOXTOJbFX2PI2+ifo+K7J8JaLWgwGYGAaFcjBH4/e KLoNnO4gOJ8/5EGz0FbjIZxZ16GJpQg== X-Received: from dymj5.prod.google.com ([2002:a05:7300:6b05:b0:337:3bb8:d6c8]) (user=samagazaryan job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:1602:b0:3d3:aed2:6f23 with SMTP id adf61e73a8af0-3da21638008mr24550107637.23.1788726552696; Sun, 06 Sep 2026 13:29:12 -0700 (PDT) Date: Sun, 6 Sep 2026 20:27:47 +0000 In-Reply-To: <20260906202747.4041389-1-samagazaryan@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260906202747.4041389-1-samagazaryan@google.com> X-Mailer: git-send-email 2.55.0.979.g7e5102b832-goog Message-ID: <20260906202747.4041389-4-samagazaryan@google.com> Subject: [PATCH v4 3/3] i3c: add i3cdev module to expose i3c dev in /dev From: Sam Agazaryan To: linux-i3c@lists.infradead.org Cc: Alexandre Belloni , Frank Li , Greg Kroah-Hartman , Arnd Bergmann , Vitor Soares , Oleksandr Shulzhenko , linux-kernel@vger.kernel.org, Sam Agazaryan Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Vitor Soares This patch adds userspace character device support for I3C SDR private transfers via /dev. The module allows userspace programs to interact directly with I3C targets that do not have a kernel driver bound to them, such as devices in ROM/bootloader recovery mode (e.g. OCP Secure Firmware Recovery v1.1 and Caliptra Silicon Root of Trust recovery flows). Features: - Dynamically exposes /dev/bus/i3c/ character devices for I3C devices when unbound from kernel drivers. - Dynamically allocates character device minor numbers using the IDA allocator. - Implements private SDR read/write transfers via I3C_IOC_PRIV_XFER ioctl with 64-bit aligned UAPI data structures. - Supports compat_ptr_ioctl for 32-bit userspace on 64-bit kernels. - Uses cdev_device_add/cdev_device_del with device refcounting to ensure safe lifecycle management and prevent use-after-free on driver detach. Signed-off-by: Vitor Soares Co-developed-by: Oleksandr Shulzhenko Signed-off-by: Oleksandr Shulzhenko Co-developed-by: Sam Agazaryan Signed-off-by: Sam Agazaryan --- MAINTAINERS | 1 + drivers/i3c/Kconfig | 11 + drivers/i3c/Makefile | 1 + drivers/i3c/i3cdev.c | 445 ++++++++++++++++++++++++++++++++ include/uapi/linux/i3c/i3cdev.h | 37 +++ 5 files changed, 495 insertions(+) create mode 100644 drivers/i3c/i3cdev.c create mode 100644 include/uapi/linux/i3c/i3cdev.h diff --git a/MAINTAINERS b/MAINTAINERS index 81a9a02c919d..30a5cb12c4f0 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -12364,6 +12364,7 @@ F: Documentation/driver-api/i3c F: drivers/i3c/ F: include/dt-bindings/i3c/ F: include/linux/i3c/ +F: include/uapi/linux/i3c/ =20 IBM Operation Panel Input Driver M: Eddie James diff --git a/drivers/i3c/Kconfig b/drivers/i3c/Kconfig index 626c54b386d5..166875837ec6 100644 --- a/drivers/i3c/Kconfig +++ b/drivers/i3c/Kconfig @@ -20,6 +20,17 @@ menuconfig I3C will be called i3c. =20 if I3C + +config I3CDEV + tristate "I3C device interface" + help + Say Y here to use i3c-* device files, usually found in the /dev + directory on your system. They make it possible to have user-space + programs use the I3C devices. + + This support is also available as a module. If so, the module + will be called i3cdev. + source "drivers/i3c/master/Kconfig" endif # I3C =20 diff --git a/drivers/i3c/Makefile b/drivers/i3c/Makefile index 11982efbc6d9..606d422841b2 100644 --- a/drivers/i3c/Makefile +++ b/drivers/i3c/Makefile @@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 i3c-y :=3D device.o master.o obj-$(CONFIG_I3C) +=3D i3c.o +obj-$(CONFIG_I3CDEV) +=3D i3cdev.o obj-$(CONFIG_I3C) +=3D master/ diff --git a/drivers/i3c/i3cdev.c b/drivers/i3c/i3cdev.c new file mode 100644 index 000000000000..904ebfd48769 --- /dev/null +++ b/drivers/i3c/i3cdev.c @@ -0,0 +1,445 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2020 Synopsys, Inc. and/or its affiliates. + * + * Author: Vitor Soares + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "internals.h" + +struct i3cdev_data { + struct i3c_device *i3c; + struct device dev; + struct mutex xfer_lock; /* prevent detach while transferring */ + struct cdev cdev; + int id; +}; + +static DEFINE_IDA(i3cdev_ida); +static dev_t i3cdev_number; +#define I3C_MINORS (MINORMASK + 1) + +static void i3cdev_dev_release(struct device *dev) +{ + struct i3cdev_data *i3cdev =3D container_of(dev, struct i3cdev_data, dev); + + ida_free(&i3cdev_ida, i3cdev->id); + kfree(i3cdev); +} + +static struct i3cdev_data *get_free_i3cdev(struct i3c_device *i3c) +{ + struct i3cdev_data *i3cdev; + int id; + + id =3D ida_alloc(&i3cdev_ida, GFP_KERNEL); + if (id < 0) { + pr_err("i3cdev: no minor number available!\n"); + return ERR_PTR(id); + } + + i3cdev =3D kzalloc(sizeof(*i3cdev), GFP_KERNEL); + if (!i3cdev) { + ida_free(&i3cdev_ida, id); + return ERR_PTR(-ENOMEM); + } + + i3cdev->i3c =3D i3c; + i3cdev->id =3D id; + i3cdev_set_drvdata(i3c, i3cdev); + + return i3cdev; +} + +static ssize_t +i3cdev_read(struct file *file, char __user *buf, size_t count, loff_t *f_p= os) +{ + struct i3cdev_data *i3cdev =3D file->private_data; + struct i3c_device *i3c; + struct i3c_xfer xfers =3D { + .rnw =3D true, + .len =3D count, + }; + int ret =3D -ENODEV; + char *tmp; + + mutex_lock(&i3cdev->xfer_lock); + i3c =3D i3cdev->i3c; + if (!i3c || i3c->dev.driver) + goto err_out; + + tmp =3D kzalloc(count, GFP_KERNEL); + if (!tmp) { + ret =3D -ENOMEM; + goto err_out; + } + + xfers.data.in =3D tmp; + + dev_dbg(&i3c->dev, "Reading %zu bytes.\n", count); + + ret =3D i3c_device_do_xfers(i3c, &xfers, 1, I3C_SDR); + if (!ret) + ret =3D copy_to_user(buf, tmp, xfers.len) ? -EFAULT : xfers.len; + + kfree(tmp); + +err_out: + mutex_unlock(&i3cdev->xfer_lock); + return ret; +} + +static ssize_t +i3cdev_write(struct file *file, const char __user *buf, size_t count, + loff_t *f_pos) +{ + struct i3cdev_data *i3cdev =3D file->private_data; + struct i3c_device *i3c; + struct i3c_xfer xfers =3D { + .rnw =3D false, + .len =3D count, + }; + int ret =3D -ENODEV; + char *tmp; + + mutex_lock(&i3cdev->xfer_lock); + i3c =3D i3cdev->i3c; + if (!i3c || i3c->dev.driver) + goto err_out; + + tmp =3D memdup_user(buf, count); + if (IS_ERR(tmp)) { + ret =3D PTR_ERR(tmp); + goto err_out; + } + + xfers.data.out =3D tmp; + + dev_dbg(&i3c->dev, "Writing %zu bytes.\n", count); + + ret =3D i3c_device_do_xfers(i3c, &xfers, 1, I3C_SDR); + kfree(tmp); + +err_out: + mutex_unlock(&i3cdev->xfer_lock); + return (!ret) ? count : ret; +} + +static int +i3cdev_do_priv_xfer(struct i3c_device *dev, struct i3c_ioc_priv_xfer *xfer= s, + unsigned int nxfers) +{ + struct i3c_xfer *k_xfers; + u8 **data_ptrs; + int i, j, ret =3D 0; + + /* Since we have nxfers we may allocate k_xfer + *data_ptrs together */ + k_xfers =3D kcalloc(nxfers, sizeof(*k_xfers) + sizeof(*data_ptrs), + GFP_KERNEL); + if (!k_xfers) + return -ENOMEM; + + /* set data_ptrs to be after nxfers * i3c_xfer */ + data_ptrs =3D (void *)k_xfers + (nxfers * sizeof(*k_xfers)); + + for (i =3D 0; i < nxfers; i++) { + if (xfers[i].rnw) { + data_ptrs[i] =3D kzalloc(xfers[i].len, GFP_KERNEL); + if (!data_ptrs[i]) { + ret =3D -ENOMEM; + break; + } + k_xfers[i].rnw =3D true; + k_xfers[i].data.in =3D data_ptrs[i]; + } else { + data_ptrs[i] =3D memdup_user(u64_to_user_ptr(xfers[i].data), + xfers[i].len); + if (IS_ERR(data_ptrs[i])) { + ret =3D PTR_ERR(data_ptrs[i]); + break; + } + k_xfers[i].rnw =3D false; + k_xfers[i].data.out =3D data_ptrs[i]; + } + + k_xfers[i].len =3D xfers[i].len; + } + + if (ret < 0) + goto err_free_mem; + + ret =3D i3c_device_do_xfers(dev, k_xfers, nxfers, I3C_SDR); + if (ret) + goto err_free_mem; + + for (i =3D 0; i < nxfers; i++) { + if (xfers[i].rnw) { + if (copy_to_user(u64_to_user_ptr(xfers[i].data), + data_ptrs[i], xfers[i].len)) + ret =3D -EFAULT; + } + } + +err_free_mem: + for (j =3D 0; j < i; j++) + kfree(data_ptrs[j]); + kfree(k_xfers); + return ret; +} + +static struct i3c_ioc_priv_xfer * +i3cdev_get_ioc_priv_xfer(unsigned int cmd, struct i3c_ioc_priv_xfer *u_xfe= rs, + unsigned int *nxfers) +{ + u32 tmp =3D _IOC_SIZE(cmd); + + if ((tmp % sizeof(struct i3c_ioc_priv_xfer)) !=3D 0) + return ERR_PTR(-EINVAL); + + *nxfers =3D tmp / sizeof(struct i3c_ioc_priv_xfer); + if (*nxfers =3D=3D 0) + return ERR_PTR(-EINVAL); + + return memdup_user(u_xfers, tmp); +} + +static int +i3cdev_ioc_priv_xfer(struct i3c_device *i3c, unsigned int cmd, + struct i3c_ioc_priv_xfer *u_xfers) +{ + struct i3c_ioc_priv_xfer *k_xfers; + unsigned int nxfers; + int ret; + + k_xfers =3D i3cdev_get_ioc_priv_xfer(cmd, u_xfers, &nxfers); + if (IS_ERR(k_xfers)) + return PTR_ERR(k_xfers); + + ret =3D i3cdev_do_priv_xfer(i3c, k_xfers, nxfers); + + kfree(k_xfers); + + return ret; +} + +static long +i3cdev_ioctl(struct file *file, unsigned int cmd, unsigned long arg) +{ + struct i3cdev_data *i3cdev =3D file->private_data; + struct i3c_device *i3c; + int ret =3D -ENODEV; + + if (_IOC_TYPE(cmd) !=3D I3C_DEV_IOC_MAGIC) + return -ENOTTY; + + /* Use the xfer_lock to prevent device detach during ioctl call */ + mutex_lock(&i3cdev->xfer_lock); + i3c =3D i3cdev->i3c; + if (!i3c || i3c->dev.driver) + goto err_no_dev; + + dev_dbg(&i3c->dev, "ioctl, cmd=3D0x%02x, arg=3D0x%02lx\n", cmd, arg); + + /* Check command number and direction */ + if (_IOC_NR(cmd) =3D=3D _IOC_NR(I3C_IOC_PRIV_XFER(0)) && + _IOC_DIR(cmd) =3D=3D (_IOC_READ | _IOC_WRITE)) + ret =3D i3cdev_ioc_priv_xfer(i3c, cmd, + (struct i3c_ioc_priv_xfer __user *)arg); + else + ret =3D -ENOTTY; + +err_no_dev: + mutex_unlock(&i3cdev->xfer_lock); + return ret; +} + +static int i3cdev_open(struct inode *inode, struct file *file) +{ + struct i3cdev_data *i3cdev =3D container_of(inode->i_cdev, + struct i3cdev_data, + cdev); + file->private_data =3D i3cdev; + + return 0; +} + +static int i3cdev_release(struct inode *inode, struct file *file) +{ + file->private_data =3D NULL; + + return 0; +} + +static const struct file_operations i3cdev_fops =3D { + .owner =3D THIS_MODULE, + .read =3D i3cdev_read, + .write =3D i3cdev_write, + .unlocked_ioctl =3D i3cdev_ioctl, + .compat_ioctl =3D compat_ptr_ioctl, + .open =3D i3cdev_open, + .release =3D i3cdev_release, +}; + +/* -----------------------------------------------------------------------= -- */ + +static const struct class i3cdev_class =3D { + .name =3D "i3cdev", +}; + +static int i3cdev_attach(struct device *dev, void *dummy) +{ + struct i3cdev_data *i3cdev; + struct i3c_device *i3c; + int res; + + if (dev->type =3D=3D &i3c_masterdev_type || dev->driver) + return 0; + + i3c =3D dev_to_i3cdev(dev); + + /* Get a device */ + i3cdev =3D get_free_i3cdev(i3c); + if (IS_ERR(i3cdev)) + return PTR_ERR(i3cdev); + + mutex_init(&i3cdev->xfer_lock); + cdev_init(&i3cdev->cdev, &i3cdev_fops); + i3cdev->cdev.owner =3D THIS_MODULE; + + device_initialize(&i3cdev->dev); + i3cdev->dev.devt =3D MKDEV(MAJOR(i3cdev_number), i3cdev->id); + i3cdev->dev.class =3D &i3cdev_class; + i3cdev->dev.parent =3D &i3c->dev; + i3cdev->dev.release =3D i3cdev_dev_release; + + res =3D dev_set_name(&i3cdev->dev, "bus!i3c!%s", dev_name(&i3c->dev)); + if (res) + goto error_put_dev; + + res =3D cdev_device_add(&i3cdev->cdev, &i3cdev->dev); + if (res) + goto error_put_dev; + + pr_debug("i3cdev: I3C device [%s] registered as minor %d\n", + dev_name(&i3c->dev), i3cdev->id); + return 0; + +error_put_dev: + i3cdev_set_drvdata(i3c, NULL); + put_device(&i3cdev->dev); + return res; +} + +static int i3cdev_detach(struct device *dev, void *dummy) +{ + struct i3cdev_data *i3cdev; + struct i3c_device *i3c; + + if (dev->type =3D=3D &i3c_masterdev_type) + return 0; + + i3c =3D dev_to_i3cdev(dev); + + i3cdev =3D i3cdev_get_drvdata(i3c); + if (!i3cdev) + return 0; + + i3cdev_set_drvdata(i3c, NULL); + + /* Prevent transfers while cdev removal */ + mutex_lock(&i3cdev->xfer_lock); + i3cdev->i3c =3D NULL; + mutex_unlock(&i3cdev->xfer_lock); + + cdev_device_del(&i3cdev->cdev, &i3cdev->dev); + put_device(&i3cdev->dev); + + pr_debug("i3cdev: device [%s] unregistered\n", dev_name(&i3c->dev)); + + return 0; +} + +static int i3cdev_notifier_call(struct notifier_block *nb, + unsigned long action, + void *data) +{ + struct device *dev =3D data; + + switch (action) { + case BUS_NOTIFY_ADD_DEVICE: + case BUS_NOTIFY_UNBOUND_DRIVER: + return i3cdev_attach(dev, NULL); + case BUS_NOTIFY_DEL_DEVICE: + case BUS_NOTIFY_REMOVED_DEVICE: + case BUS_NOTIFY_BIND_DRIVER: + return i3cdev_detach(dev, NULL); + } + + return 0; +} + +static struct notifier_block i3cdev_notifier =3D { + .notifier_call =3D i3cdev_notifier_call, +}; + +static int __init i3cdev_init(void) +{ + int res; + + /* Dynamically request unused major number */ + res =3D alloc_chrdev_region(&i3cdev_number, 0, I3C_MINORS, "i3c"); + if (res) + goto out; + + /* Register device class to populate sysfs entries */ + res =3D class_register(&i3cdev_class); + if (res) + goto out_unreg_chrdev; + + /* Keep track of busses which have devices to add or remove later */ + res =3D bus_register_notifier(&i3c_bus_type, &i3cdev_notifier); + if (res) + goto out_unreg_class; + + /* Bind to already existing device without driver right away */ + i3c_for_each_dev(NULL, i3cdev_attach); + + return 0; + +out_unreg_class: + class_unregister(&i3cdev_class); +out_unreg_chrdev: + unregister_chrdev_region(i3cdev_number, I3C_MINORS); +out: + pr_err("%s: Driver Initialisation failed\n", __FILE__); + return res; +} + +static void __exit i3cdev_exit(void) +{ + bus_unregister_notifier(&i3c_bus_type, &i3cdev_notifier); + i3c_for_each_dev(NULL, i3cdev_detach); + class_unregister(&i3cdev_class); + unregister_chrdev_region(i3cdev_number, I3C_MINORS); +} + +MODULE_AUTHOR("Vitor Soares "); +MODULE_DESCRIPTION("I3C /dev entries driver"); +MODULE_LICENSE("GPL"); + +module_init(i3cdev_init); +module_exit(i3cdev_exit); diff --git a/include/uapi/linux/i3c/i3cdev.h b/include/uapi/linux/i3c/i3cde= v.h new file mode 100644 index 000000000000..5adc1e3e7c4f --- /dev/null +++ b/include/uapi/linux/i3c/i3cdev.h @@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* + * Copyright (c) 2020 Synopsys, Inc. and/or its affiliates. + * + * Author: Vitor Soares + */ + +#ifndef _UAPI_I3C_DEV_H_ +#define _UAPI_I3C_DEV_H_ + +#include +#include + +/* IOCTL commands */ +#define I3C_DEV_IOC_MAGIC 0x07 + +/** + * struct i3c_ioc_priv_xfer - I3C SDR ioctl private transfer + * @data: Holds pointer to userspace buffer with transmit data. + * @len: Length of data buffer buffers, in bytes. + * @rnw: encodes the transfer direction. true for a read, false for a write + */ +struct i3c_ioc_priv_xfer { + __u64 data; + __u16 len; + __u8 rnw; + __u8 pad[5]; +}; + +#define I3C_PRIV_XFER_SIZE(N) \ + ((((sizeof(struct i3c_ioc_priv_xfer)) * (N)) < (1 << _IOC_SIZEBITS)) \ + ? ((sizeof(struct i3c_ioc_priv_xfer)) * (N)) : 0) + +#define I3C_IOC_PRIV_XFER(N) \ + _IOC(_IOC_READ|_IOC_WRITE, I3C_DEV_IOC_MAGIC, 30, I3C_PRIV_XFER_SIZE(N)) + +#endif --=20 2.55.0.979.g7e5102b832-goog