Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp2176053lqe; Tue, 9 Apr 2024 11:36:42 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXL7MxOdcMfLWdv247shP/kQ2Ti9PwTK5STfvkPhV3U2oK8y5mcfYttZ8f9tXY15OZXukg4JEaBUnr8KIzrkBjVCO81ZE6NfXD2L0WNmA== X-Google-Smtp-Source: AGHT+IEpFHMz+Awe2i9hMqBvj2HZPl8EH3c/xO2qM5zBUBQXsBT0dGTiLMZ5+uUYfrpAxIN7QUsu X-Received: by 2002:a05:6e02:1c0d:b0:36a:d29:5401 with SMTP id l13-20020a056e021c0d00b0036a0d295401mr749173ilh.3.1712687801990; Tue, 09 Apr 2024 11:36:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712687801; cv=pass; d=google.com; s=arc-20160816; b=bmA/U38jYYzohsK06/M1/vhb7vUTSIERSo4FAULsGoqxzr8PC5AjqZreaqimLeWvHW hfTQh2nPxZvHk30zcZgXTPm2Kv7SD3ao05HGpxtS0/tqB94O5Tquw3NAM5aCXgQ4nwwb eiUthFwwx0xcJXDt+s85gg8fE4yiFsMp70VHs6QFEAy37UnH4d74OhLNggXGsztINP8G 8obihqUp004MGHy3t8hxu40Gnj3tV8BLlUwVDs3Z8poEFyJOAc88tbktBWnfNmtxJLSn oIlhbuLghXU972xNXM+yMKHs7A0dUdmV8OKen+R9iBB6qps5DVD5cEoRSXrLBbNNH3rR cV3g== 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=6UmcuCQ72fp6Cahtrj1U+7eJO6P8w7duBJ8wqAOb/u0=; fh=eulCrYuY4zK7Gxr6B+4yAHyThWGi9/x0Te9WMho9aNk=; b=N34FXElXPdL8NI92A/p5VQNN7JgNsUnZTPHyVY+SUpyEcgXTWzazrwQOKsPhzHGWtI fYFPBzYHIgvA7H+JBOM9tXnDj87JRwO4N+FKttvRO0Q0y4FEfKbQUlnhbqxU4dMCGC+3 Ege03/6u4g0abVS7fhGOrwdTL7NZBMMeQIAvCVrp/BVnBHU55mC6D6Hc31fgLdtmq82s V37akMT2nHQPln4l3m1jKzxrCXRs758ZXXI5pA9p6zGOQFc5z3tSDJXNaSDCoV+MFVgK 2Y2llDrqwJYnRer8baZflvTtv+2i6iZQtxENg32qKBTvrhSjUnyx1w6LLvGihpnAtJZ2 5Oww==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=qWLNTnOS; arc=pass (i=1 spf=pass spfdomain=amazon.co.uk dkim=pass dkdomain=amazon.com dmarc=pass fromdomain=amazon.com); spf=pass (google.com: domain of linux-kernel+bounces-137462-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-137462-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id y3-20020a63ce03000000b005e2b17cd8a0si8826057pgf.270.2024.04.09.11.36.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 11:36:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-137462-linux.lists.archive=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=@amazon.com header.s=amazon201209 header.b=qWLNTnOS; arc=pass (i=1 spf=pass spfdomain=amazon.co.uk dkim=pass dkdomain=amazon.com dmarc=pass fromdomain=amazon.com); spf=pass (google.com: domain of linux-kernel+bounces-137462-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-137462-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com 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 F0640B2416B for ; Tue, 9 Apr 2024 18:24:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2E734156C52; Tue, 9 Apr 2024 18:24:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="qWLNTnOS" Received: from smtp-fw-52004.amazon.com (smtp-fw-52004.amazon.com [52.119.213.154]) (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 5FCDE4C85; Tue, 9 Apr 2024 18:24:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=52.119.213.154 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712687065; cv=none; b=l+1rcCCCAuicuPeh/zhShtdSGO69QvC2cYo2Mr1Sswg+Uvfh1JpVaKQrIg4209e9Ro6RcvqzqzaCa1ARU+VQbV0IR6ANBXoYs7qJZ+/PvNdcSnbAubvnC6puzqEJi2dti1nbnD+BSlUSwYHkDASOjq5BhXJblmpDLnUFE48yVD8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712687065; c=relaxed/simple; bh=jW2XOtO9vH3fyORTD0njVKSTagn7WFaKPY/etiNC/h4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=IxKHWbxQ5WLXtT+XnK1bDX8vboSJ74TnJPVOGZuYBFR6jcSXGiw5+ez5vq6I5CKuuLhtbHHfvzKOfi5muEZVnl7CyvLsJ4c+skDUUvG5PBJI/Uj1Ekl1SRWTn3QZqxp7ews3Fvvtu8N8AIwFmiWRob7XgJ8AUBtzmc0KyDUYgck= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.co.uk; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b=qWLNTnOS; arc=none smtp.client-ip=52.119.213.154 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.co.uk DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1712687064; x=1744223064; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6UmcuCQ72fp6Cahtrj1U+7eJO6P8w7duBJ8wqAOb/u0=; b=qWLNTnOSCUj3nb9ZIXaXZfm8XXhMQQsc5IJ8Q+ITs1CQ92S+dzXnPgAd GD3SEKPj9mO8RqhcdxjDkWEUex8DiaN/1HSnZylJS7swpvVR2W6u2ng5q ap1Wepp1cLH0LTMq0Hz3aNXuttv0SRS0YH8HttZUDVv2Nn/tTTMG/55Sx k=; X-IronPort-AV: E=Sophos;i="6.07,190,1708387200"; d="scan'208";a="197485460" Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.43.8.2]) by smtp-border-fw-52004.iad7.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Apr 2024 18:14:15 +0000 Received: from EX19MTAEUA001.ant.amazon.com [10.0.10.100:64023] by smtpin.naws.eu-west-1.prod.farcaster.email.amazon.dev [10.0.25.48:2525] with esmtp (Farcaster) id 916869e4-5faf-4241-98ad-4ec9d41da4dc; Tue, 9 Apr 2024 18:14:13 +0000 (UTC) X-Farcaster-Flow-ID: 916869e4-5faf-4241-98ad-4ec9d41da4dc Received: from EX19D036EUC002.ant.amazon.com (10.252.61.191) by EX19MTAEUA001.ant.amazon.com (10.252.50.50) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.28; Tue, 9 Apr 2024 18:14:13 +0000 Received: from bcd074994f7f.amazon.com (10.95.97.144) by EX19D036EUC002.ant.amazon.com (10.252.61.191) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.28; Tue, 9 Apr 2024 18:14:08 +0000 From: Sudan Landge To: , , , , , , , , , , CC: , , , Subject: [PATCH v4 5/5] virt: vmgenid: add support for devicetree bindings Date: Tue, 9 Apr 2024 19:11:54 +0100 Message-ID: <20240409181154.9962-6-sudanl@amazon.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20240409181154.9962-1-sudanl@amazon.com> References: <20240409181154.9962-1-sudanl@amazon.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: EX19D039UWB003.ant.amazon.com (10.13.138.93) To EX19D036EUC002.ant.amazon.com (10.252.61.191) Extend the vmgenid platform driver to support devicetree bindings. With this support, hypervisors can send vmgenid notifications to the virtual machine without the need to enable ACPI. The bindings are located at: Documentation/devicetree/bindings/rng/microsoft,vmgenid.yaml Signed-off-by: Sudan Landge --- drivers/virt/vmgenid.c | 53 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/drivers/virt/vmgenid.c b/drivers/virt/vmgenid.c index 3d93e3fb94c4..e1ad74116c0c 100644 --- a/drivers/virt/vmgenid.c +++ b/drivers/virt/vmgenid.c @@ -2,12 +2,13 @@ /* * Copyright (C) 2022 Jason A. Donenfeld . All Rights Reserved. * - * The "Virtual Machine Generation ID" is exposed via ACPI and changes when a + * The "Virtual Machine Generation ID" is exposed via ACPI or DT and changes when a * virtual machine forks or is cloned. This driver exists for shepherding that * information to random.c. */ #include +#include #include #include #include @@ -20,6 +21,7 @@ enum { VMGENID_SIZE = 16 }; struct vmgenid_state { u8 *next_id; u8 this_id[VMGENID_SIZE]; + int irq; }; static void vmgenid_notify(struct device *device) @@ -43,6 +45,14 @@ vmgenid_acpi_handler(acpi_handle __always_unused handle, vmgenid_notify(dev); } +static __maybe_unused irqreturn_t +vmgenid_of_irq_handler(int __always_unused irq, void *dev) +{ + vmgenid_notify(dev); + + return IRQ_HANDLED; +} + static int __maybe_unused setup_vmgenid_state(struct vmgenid_state *state, u8 *next_id) { @@ -106,6 +116,35 @@ static int vmgenid_add_acpi(struct device __maybe_unused *dev, #endif } +static int vmgenid_add_of(struct platform_device *pdev, + struct vmgenid_state *state) +{ + u8 *virt_addr; + int ret = 0; + + virt_addr = (u8 *)devm_platform_get_and_ioremap_resource(pdev, 0, NULL); + if (IS_ERR(virt_addr)) + return PTR_ERR(virt_addr); + + ret = setup_vmgenid_state(state, virt_addr); + if (ret) + return ret; + + ret = platform_get_irq(pdev, 0); + if (ret < 0) + return ret; + + state->irq = ret; + pdev->dev.driver_data = state; + + ret = devm_request_irq(&pdev->dev, state->irq, vmgenid_of_irq_handler, + IRQF_SHARED, "vmgenid", &pdev->dev); + if (ret) + pdev->dev.driver_data = NULL; + + return ret; +} + static int vmgenid_add(struct platform_device *pdev) { struct vmgenid_state *state; @@ -116,7 +155,10 @@ static int vmgenid_add(struct platform_device *pdev) if (!state) return -ENOMEM; - ret = vmgenid_add_acpi(dev, state); + if (dev->of_node) + ret = vmgenid_add_of(pdev, state); + else + ret = vmgenid_add_acpi(dev, state); if (ret) devm_kfree(dev, state); @@ -124,6 +166,12 @@ static int vmgenid_add(struct platform_device *pdev) return ret; } +static const struct of_device_id vmgenid_of_ids[] = { + { .compatible = "microsoft,vmgenid", }, + { }, +}; +MODULE_DEVICE_TABLE(of, vmgenid_of_ids); + static const struct acpi_device_id vmgenid_acpi_ids[] = { { "VMGENCTR", 0 }, { "VM_GEN_COUNTER", 0 }, @@ -136,6 +184,7 @@ static struct platform_driver vmgenid_plaform_driver = { .driver = { .name = "vmgenid", .acpi_match_table = vmgenid_acpi_ids, + .of_match_table = vmgenid_of_ids, }, }; -- 2.34.1