From patchwork Thu Nov 12 17:58:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikas Gupta X-Patchwork-Id: 11900915 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,MIME_HEADER_CTYPE_ONLY,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,T_TVD_MIME_NO_HEADERS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED44EC2D0E4 for ; Thu, 12 Nov 2020 18:01:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 848DD22201 for ; Thu, 12 Nov 2020 18:01:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="SKQzcMGr" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726560AbgKLSBS (ORCPT ); Thu, 12 Nov 2020 13:01:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726530AbgKLR7Q (ORCPT ); Thu, 12 Nov 2020 12:59:16 -0500 Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53177C0613D1 for ; Thu, 12 Nov 2020 09:59:16 -0800 (PST) Received: by mail-pl1-x642.google.com with SMTP id j5so3184473plk.7 for ; Thu, 12 Nov 2020 09:59:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=+2E0mvmNgJ7XpC+sQ+NOvEv+zkMfA4r/PTBbUkrbL/w=; b=SKQzcMGrPfPgREcyg033sqfNVqFUwNzXgH/CVdrrVXb1iTFbbTk1+cPuqrDKjQYs0w xnPD55nG8D87cwQVtxPsx3x/WbSnBVplloQcnEu8eJnGo6dA9c7wzV3od6915RU/GwKp aFWK1ZewW7QrX57B5tiz1dFgCJA3e8fmqZSHI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+2E0mvmNgJ7XpC+sQ+NOvEv+zkMfA4r/PTBbUkrbL/w=; b=DJA9uk2uKm9q83R89a6tC1cVreqDCrU1Eo1cBx86qqDx8VVc24sem4qVLDEzFf+8i2 QRjfL7mrAJLQ3CUnvsG89yCTD7yZm6bDzdtvFRQ2N6h66MDNX4POQQYEb32BpbAEE2K6 PRWYoNWSWif/yqSkdjmjMGI5cvs6FfSxWFfgq7ZJtaUGZpr0npw5/DobT9F2lOjfwoBl W/KrBZ5U52pMpChwSK6LhbaMWbNAuuqx0u6MwPHt4yq20oYFX6NNlgFrFRtAUPgDJTT3 VSKiaSWfm7CuxaAB0oIoM1jZK5iUxrE3V5M12ApzL5SbI072rwK1MQYf0dFNapqTK6y4 B9Dw== X-Gm-Message-State: AOAM530efZDAYAWmEra3jsxY3AVneBA4YCAoLt1xwcP4LmBEdZfsKHlQ oQVBTONaSygu70SGSYkfqOB14sTs0e2/wLJhJck= X-Google-Smtp-Source: ABdhPJz+gu5zf5HyLECfUNwTCTiyTQEeeU4UhsPMYECZ7Nh+H4xbEhqG9jst4d/d27y2Oj/DU3b0+A== X-Received: by 2002:a17:902:c10c:b029:d8:c028:5ceb with SMTP id 12-20020a170902c10cb02900d8c0285cebmr532571pli.36.1605203955729; Thu, 12 Nov 2020 09:59:15 -0800 (PST) Received: from rahul_yocto_ubuntu18.ibn.broadcom.net ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id r6sm7237894pjd.39.2020.11.12.09.59.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Nov 2020 09:59:15 -0800 (PST) From: Vikas Gupta To: eric.auger@redhat.com, alex.williamson@redhat.com, cohuck@redhat.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: vikram.prakash@broadcom.com, srinath.mannam@broadcom.com, Vikas Gupta Subject: [RFC v1 3/3] vfio/platform: add Broadcom msi module Date: Thu, 12 Nov 2020 23:28:52 +0530 Message-Id: <20201112175852.21572-4-vikas.gupta@broadcom.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201112175852.21572-1-vikas.gupta@broadcom.com> References: <20201105060257.35269-1-vikas.gupta@broadcom.com> <20201112175852.21572-1-vikas.gupta@broadcom.com> Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Add Broadcom msi module for platform devices. Signed-off-by: Vikas Gupta --- drivers/vfio/platform/Kconfig | 1 + drivers/vfio/platform/Makefile | 1 + drivers/vfio/platform/msi/Kconfig | 9 +++ drivers/vfio/platform/msi/Makefile | 2 + .../vfio/platform/msi/vfio_platform_bcmplt.c | 74 +++++++++++++++++++ 5 files changed, 87 insertions(+) create mode 100644 drivers/vfio/platform/msi/Kconfig create mode 100644 drivers/vfio/platform/msi/Makefile create mode 100644 drivers/vfio/platform/msi/vfio_platform_bcmplt.c diff --git a/drivers/vfio/platform/Kconfig b/drivers/vfio/platform/Kconfig index dc1a3c44f2c6..7b8696febe61 100644 --- a/drivers/vfio/platform/Kconfig +++ b/drivers/vfio/platform/Kconfig @@ -21,3 +21,4 @@ config VFIO_AMBA If you don't know what to do here, say N. source "drivers/vfio/platform/reset/Kconfig" +source "drivers/vfio/platform/msi/Kconfig" diff --git a/drivers/vfio/platform/Makefile b/drivers/vfio/platform/Makefile index 3f3a24e7c4ef..9ccdcdbf0e7e 100644 --- a/drivers/vfio/platform/Makefile +++ b/drivers/vfio/platform/Makefile @@ -5,6 +5,7 @@ vfio-platform-y := vfio_platform.o obj-$(CONFIG_VFIO_PLATFORM) += vfio-platform.o obj-$(CONFIG_VFIO_PLATFORM) += vfio-platform-base.o obj-$(CONFIG_VFIO_PLATFORM) += reset/ +obj-$(CONFIG_VFIO_PLATFORM) += msi/ vfio-amba-y := vfio_amba.o diff --git a/drivers/vfio/platform/msi/Kconfig b/drivers/vfio/platform/msi/Kconfig new file mode 100644 index 000000000000..54d6b70e1e32 --- /dev/null +++ b/drivers/vfio/platform/msi/Kconfig @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0-only +config VFIO_PLATFORM_BCMPLT_MSI + tristate "MSI support for Broadcom platform devices" + depends on VFIO_PLATFORM && (ARCH_BCM_IPROC || COMPILE_TEST) + default ARCH_BCM_IPROC + help + Enables the VFIO platform driver to handle msi for Broadcom devices + + If you don't know what to do here, say N. diff --git a/drivers/vfio/platform/msi/Makefile b/drivers/vfio/platform/msi/Makefile new file mode 100644 index 000000000000..27422d45cecb --- /dev/null +++ b/drivers/vfio/platform/msi/Makefile @@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0 +obj-$(CONFIG_VFIO_PLATFORM_BCMPLT_MSI) += vfio_platform_bcmplt.o diff --git a/drivers/vfio/platform/msi/vfio_platform_bcmplt.c b/drivers/vfio/platform/msi/vfio_platform_bcmplt.c new file mode 100644 index 000000000000..7f44d7d0c95d --- /dev/null +++ b/drivers/vfio/platform/msi/vfio_platform_bcmplt.c @@ -0,0 +1,74 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright 2020 Broadcom. + */ + +#include +#include +#include +#include +#include + +#include "../vfio_platform_private.h" + +#define RING_SIZE (64 << 10) + +#define RING_MSI_ADDR_LS 0x03c +#define RING_MSI_ADDR_MS 0x040 +#define RING_MSI_DATA_VALUE 0x064 + +static u32 bcm_num_msi(struct vfio_platform_device *vdev) +{ + struct vfio_platform_region *reg = &vdev->regions[0]; + + return (reg->size / RING_SIZE); +} + +static int bcm_write_msi(struct vfio_platform_device *vdev, + struct msi_desc *desc, + struct msi_msg *msg) +{ + void __iomem *ring; + int msi_off = vdev->num_irqs - 1; + int ring_num = desc->irq - vdev->irqs[msi_off].hwirq; + struct vfio_platform_region *reg = &vdev->regions[0]; + + if (!reg->ioaddr) { + reg->ioaddr = ioremap(reg->addr, reg->size); + if (!reg->ioaddr) + return -ENOMEM; + } + + ring = reg->ioaddr + ring_num * RING_SIZE; + + writel_relaxed(msg->address_lo, ring + RING_MSI_ADDR_LS); + writel_relaxed(msg->address_hi, ring + RING_MSI_ADDR_MS); + writel_relaxed(msg->data, ring + RING_MSI_DATA_VALUE); + + return 0; +} + +static struct vfio_platform_msi_node vfio_platform_bcmflexrm_msi_node = { + .owner = THIS_MODULE, + .compat = "brcm,iproc-flexrm-mbox", + .of_get_msi = bcm_num_msi, + .of_msi_write = bcm_write_msi +}; + +static int __init vfio_platform_bcmflexrm_msi_module_init(void) +{ + __vfio_platform_register_msi(&vfio_platform_bcmflexrm_msi_node); + + return 0; +} + +static void __exit vfio_platform_bcmflexrm_msi_module_exit(void) +{ + vfio_platform_unregister_msi("brcm,iproc-flexrm-mbox"); +} + +module_init(vfio_platform_bcmflexrm_msi_module_init); +module_exit(vfio_platform_bcmflexrm_msi_module_exit); + +MODULE_LICENSE("GPL v2"); +MODULE_AUTHOR("Broadcom");