From patchwork Thu Nov 12 17:58:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikas Gupta X-Patchwork-Id: 11900917 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 EB856C6369E for ; Thu, 12 Nov 2020 18:01:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8C8712223C for ; Thu, 12 Nov 2020 18:01:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="QtWpuolF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726984AbgKLSBh (ORCPT ); Thu, 12 Nov 2020 13:01:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726426AbgKLR7K (ORCPT ); Thu, 12 Nov 2020 12:59:10 -0500 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88836C061A49 for ; Thu, 12 Nov 2020 09:59:09 -0800 (PST) Received: by mail-pf1-x441.google.com with SMTP id q5so5247370pfk.6 for ; Thu, 12 Nov 2020 09:59:09 -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=PuUUU3p4QVu/Pg/pLrotXd8fVuKl/UFHWCvdQMnFV/A=; b=QtWpuolFjfwWayF+iM+Kx5bF9ELZg3e0z2vz7ZE3EnonI8SqN9JDCJ7amklQIUFErC 5phfYVRzX+u8RVLCwrLIHaUy9bLTY/IitELKWrf2iZa6Z4SoSIE9NOvVM/CrXWx+2I4H g0k2q4p3Bu82m1zXEtFMFYmReiUmBmgQM9tlU= 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=PuUUU3p4QVu/Pg/pLrotXd8fVuKl/UFHWCvdQMnFV/A=; b=awulOsso5FuYhEc4PAkNmzcc2Zuwz0cAJCR8JZOrjjiIXmxAxHc0BBueUsc8p5isjC uzSbZy5bGxG5IwYN7GOTob+5mr1GCAaotxeR4rbjnY/m7OhvD5IXF3x4Egigog2ukZkI 0D5MVZHrKsvdpoBO5a1d/ywygoLkiXf2cnPAUZjLXvvlNt7hbVXkc0pfJoueA1UbVaeG xmu9C/jvaRQ20FcktDUDnNVDCynLrk3D6fZg55UQDFJJENg4+Jx1p140FZc0q/114Apq 6zlyaNs0biyzwC35i5iL25cB2/1vUPx3Hk2pyc5tTluU0MwNM+ZsfBCpocnbS6H3XAic oRIA== X-Gm-Message-State: AOAM532S1Uz68unJiib7EZLDTlqCQSUL66M/shu4RbhHiJgZEnrzoPxx jZRGy8fW7vb75eX3VJLXp0u76A== X-Google-Smtp-Source: ABdhPJy1GJBC7yz+eSn937IoFvW91G5+hjuiJAzTKYCu6D5Yy1VQny5ExJzX6Osa660WGp7YCp6G7A== X-Received: by 2002:a63:a65:: with SMTP id z37mr518139pgk.361.1605203948839; Thu, 12 Nov 2020 09:59:08 -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.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Nov 2020 09:59:08 -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 1/3] vfio/platform: add support for msi Date: Thu, 12 Nov 2020 23:28:50 +0530 Message-Id: <20201112175852.21572-2-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 MSI support for platform devices. Signed-off-by: Vikas Gupta --- drivers/vfio/platform/vfio_platform_common.c | 84 ++++++- drivers/vfio/platform/vfio_platform_irq.c | 238 +++++++++++++++++- drivers/vfio/platform/vfio_platform_private.h | 23 ++ 3 files changed, 331 insertions(+), 14 deletions(-) diff --git a/drivers/vfio/platform/vfio_platform_common.c b/drivers/vfio/platform/vfio_platform_common.c index c0771a9567fb..226aa8083751 100644 --- a/drivers/vfio/platform/vfio_platform_common.c +++ b/drivers/vfio/platform/vfio_platform_common.c @@ -26,6 +26,10 @@ #define VFIO_PLATFORM_IS_ACPI(vdev) ((vdev)->acpihid != NULL) static LIST_HEAD(reset_list); + +/* devices having MSI support */ +static LIST_HEAD(msi_list); + static DEFINE_MUTEX(driver_lock); static vfio_platform_reset_fn_t vfio_platform_lookup_reset(const char *compat, @@ -47,6 +51,26 @@ static vfio_platform_reset_fn_t vfio_platform_lookup_reset(const char *compat, return reset_fn; } +static bool vfio_platform_lookup_msi(struct vfio_platform_device *vdev) +{ + bool has_msi = false; + struct vfio_platform_msi_node *iter; + + mutex_lock(&driver_lock); + list_for_each_entry(iter, &msi_list, link) { + if (!strcmp(iter->compat, vdev->compat) && + try_module_get(iter->owner)) { + vdev->msi_module = iter->owner; + vdev->of_get_msi = iter->of_get_msi; + vdev->of_msi_write = iter->of_msi_write; + has_msi = true; + break; + } + } + mutex_unlock(&driver_lock); + return has_msi; +} + static int vfio_platform_acpi_probe(struct vfio_platform_device *vdev, struct device *dev) { @@ -126,6 +150,19 @@ static int vfio_platform_get_reset(struct vfio_platform_device *vdev) return vdev->of_reset ? 0 : -ENOENT; } +static int vfio_platform_get_msi(struct vfio_platform_device *vdev) +{ + bool has_msi; + + has_msi = vfio_platform_lookup_msi(vdev); + if (!has_msi) { + request_module("vfio-msi:%s", vdev->compat); + has_msi = vfio_platform_lookup_msi(vdev); + } + + return has_msi ? 0 : -ENOENT; +} + static void vfio_platform_put_reset(struct vfio_platform_device *vdev) { if (VFIO_PLATFORM_IS_ACPI(vdev)) @@ -135,6 +172,12 @@ static void vfio_platform_put_reset(struct vfio_platform_device *vdev) module_put(vdev->reset_module); } +static void vfio_platform_put_msi(struct vfio_platform_device *vdev) +{ + if (vdev->of_get_msi) + module_put(vdev->msi_module); +} + static int vfio_platform_regions_init(struct vfio_platform_device *vdev) { int cnt = 0, i; @@ -313,6 +356,7 @@ static long vfio_platform_ioctl(void *device_data, if (vfio_platform_has_reset(vdev)) vdev->flags |= VFIO_DEVICE_FLAGS_RESET; + info.flags = vdev->flags; info.num_regions = vdev->num_regions; info.num_irqs = vdev->num_irqs; @@ -366,6 +410,7 @@ static long vfio_platform_ioctl(void *device_data, struct vfio_irq_set hdr; u8 *data = NULL; int ret = 0; + int max; size_t data_size = 0; minsz = offsetofend(struct vfio_irq_set, count); @@ -373,7 +418,12 @@ static long vfio_platform_ioctl(void *device_data, if (copy_from_user(&hdr, (void __user *)arg, minsz)) return -EFAULT; - ret = vfio_set_irqs_validate_and_prepare(&hdr, vdev->num_irqs, + if (hdr.index >= vdev->num_irqs) + return -EINVAL; + + max = vdev->irqs[hdr.index].count; + + ret = vfio_set_irqs_validate_and_prepare(&hdr, max, vdev->num_irqs, &data_size); if (ret) return ret; @@ -679,11 +729,15 @@ int vfio_platform_probe_common(struct vfio_platform_device *vdev, return ret; } + ret = vfio_platform_get_msi(vdev); + if (ret) + dev_info(vdev->device, "msi not supported\n"); + group = vfio_iommu_group_get(dev); if (!group) { dev_err(dev, "No IOMMU group for device %s\n", vdev->name); ret = -EINVAL; - goto put_reset; + goto put_msi; } ret = vfio_add_group_dev(dev, &vfio_platform_ops, vdev); @@ -697,6 +751,8 @@ int vfio_platform_probe_common(struct vfio_platform_device *vdev, put_iommu: vfio_iommu_group_put(group, dev); +put_msi: + vfio_platform_put_msi(vdev); put_reset: vfio_platform_put_reset(vdev); return ret; @@ -745,6 +801,30 @@ void vfio_platform_unregister_reset(const char *compat, } EXPORT_SYMBOL_GPL(vfio_platform_unregister_reset); +void __vfio_platform_register_msi(struct vfio_platform_msi_node *node) +{ + mutex_lock(&driver_lock); + list_add(&node->link, &msi_list); + mutex_unlock(&driver_lock); +} +EXPORT_SYMBOL_GPL(__vfio_platform_register_msi); + +void vfio_platform_unregister_msi(const char *compat) +{ + struct vfio_platform_msi_node *iter, *temp; + + mutex_lock(&driver_lock); + list_for_each_entry_safe(iter, temp, &msi_list, link) { + if (!strcmp(iter->compat, compat)) { + list_del(&iter->link); + break; + } + } + + mutex_unlock(&driver_lock); +} +EXPORT_SYMBOL_GPL(vfio_platform_unregister_msi); + MODULE_VERSION(DRIVER_VERSION); MODULE_LICENSE("GPL v2"); MODULE_AUTHOR(DRIVER_AUTHOR); diff --git a/drivers/vfio/platform/vfio_platform_irq.c b/drivers/vfio/platform/vfio_platform_irq.c index c5b09ec0a3c9..3ee736dcb3c5 100644 --- a/drivers/vfio/platform/vfio_platform_irq.c +++ b/drivers/vfio/platform/vfio_platform_irq.c @@ -8,10 +8,12 @@ #include #include +#include #include #include #include #include +#include #include "vfio_platform_private.h" @@ -253,6 +255,176 @@ static int vfio_platform_set_irq_trigger(struct vfio_platform_device *vdev, return 0; } +/* MSI/MSIX */ +static irqreturn_t vfio_msihandler(int irq, void *arg) +{ + struct eventfd_ctx *trigger = arg; + + eventfd_signal(trigger, 1); + return IRQ_HANDLED; +} + +static void msi_write(struct msi_desc *desc, struct msi_msg *msg) +{ + struct device *dev = msi_desc_to_dev(desc); + struct vfio_device *device = dev_get_drvdata(dev); + struct vfio_platform_device *vdev = (struct vfio_platform_device *) + vfio_device_data(device); + + vdev->of_msi_write(vdev, desc, msg); +} + +static int vfio_msi_enable(struct vfio_platform_device *vdev, int nvec) +{ + int ret; + int msi_idx = 0; + struct msi_desc *desc; + struct device *dev = vdev->device; + int msi_off = vdev->num_irqs - 1; + + /* Allocate platform MSIs */ + ret = platform_msi_domain_alloc_irqs(dev, nvec, msi_write); + if (ret < 0) + return ret; + + for_each_msi_entry(desc, dev) { + vdev->irqs[msi_off + msi_idx].hwirq = desc->irq; + msi_idx++; + } + + vdev->num_msis = nvec; + vdev->config_msi = 1; + + return 0; +} + +static int vfio_msi_set_vector_signal(struct vfio_platform_device *vdev, + int vector, int fd) +{ + struct eventfd_ctx *trigger; + int irq, ret; + int msi_off = vdev->num_irqs - 1; + + if (vector < 0 || vector >= vdev->num_msis) + return -EINVAL; + + irq = vdev->irqs[msi_off + vector].hwirq; + + if (vdev->irqs[vector].trigger) { + free_irq(irq, vdev->irqs[vector].trigger); + kfree(vdev->irqs[vector].name); + eventfd_ctx_put(vdev->irqs[vector].trigger); + vdev->irqs[vector].trigger = NULL; + } + + if (fd < 0) + return 0; + + vdev->irqs[vector].name = kasprintf(GFP_KERNEL, + "vfio-msi[%d]", vector); + if (!vdev->irqs[vector].name) + return -ENOMEM; + + trigger = eventfd_ctx_fdget(fd); + if (IS_ERR(trigger)) { + kfree(vdev->irqs[vector].name); + return PTR_ERR(trigger); + } + + ret = request_irq(irq, vfio_msihandler, 0, + vdev->irqs[vector].name, trigger); + if (ret) { + kfree(vdev->irqs[vector].name); + eventfd_ctx_put(trigger); + return ret; + } + + vdev->irqs[vector].trigger = trigger; + + return 0; +} + +static int vfio_msi_set_block(struct vfio_platform_device *vdev, unsigned int start, + unsigned int count, int32_t *fds) +{ + int i, j, ret = 0; + + if (start >= vdev->num_msis || start + count > vdev->num_msis) + return -EINVAL; + + for (i = 0, j = start; i < count && !ret; i++, j++) { + int fd = fds ? fds[i] : -1; + + ret = vfio_msi_set_vector_signal(vdev, j, fd); + } + + if (ret) { + for (--j; j >= (int)start; j--) + vfio_msi_set_vector_signal(vdev, j, -1); + } + + return ret; +} + +static void vfio_msi_disable(struct vfio_platform_device *vdev) +{ + struct device *dev = vdev->device; + + vfio_msi_set_block(vdev, 0, vdev->num_msis, NULL); + platform_msi_domain_free_irqs(dev); + + vdev->config_msi = 0; + vdev->num_msis = 0; +} + +static int vfio_set_msi_trigger(struct vfio_platform_device *vdev, + unsigned int index, unsigned int start, + unsigned int count, uint32_t flags, void *data) +{ + int i; + + if (start + count > vdev->num_msis) + return -EINVAL; + + if (!count && (flags & VFIO_IRQ_SET_DATA_NONE)) { + vfio_msi_disable(vdev); + return 0; + } + + if (flags & VFIO_IRQ_SET_DATA_EVENTFD) { + s32 *fds = data; + int ret; + + if (vdev->config_msi) + return vfio_msi_set_block(vdev, start, count, + fds); + ret = vfio_msi_enable(vdev, start + count); + if (ret) + return ret; + + ret = vfio_msi_set_block(vdev, start, count, fds); + if (ret) + vfio_msi_disable(vdev); + + return ret; + } + + for (i = start; i < start + count; i++) { + if (!vdev->irqs[i].trigger) + continue; + if (flags & VFIO_IRQ_SET_DATA_NONE) { + eventfd_signal(vdev->irqs[i].trigger, 1); + } else if (flags & VFIO_IRQ_SET_DATA_BOOL) { + u8 *bools = data; + + if (bools[i - start]) + eventfd_signal(vdev->irqs[i].trigger, 1); + } + } + + return 0; +} + int vfio_platform_set_irqs_ioctl(struct vfio_platform_device *vdev, uint32_t flags, unsigned index, unsigned start, unsigned count, void *data) @@ -261,16 +433,29 @@ int vfio_platform_set_irqs_ioctl(struct vfio_platform_device *vdev, unsigned start, unsigned count, uint32_t flags, void *data) = NULL; - switch (flags & VFIO_IRQ_SET_ACTION_TYPE_MASK) { - case VFIO_IRQ_SET_ACTION_MASK: - func = vfio_platform_set_irq_mask; - break; - case VFIO_IRQ_SET_ACTION_UNMASK: - func = vfio_platform_set_irq_unmask; - break; - case VFIO_IRQ_SET_ACTION_TRIGGER: - func = vfio_platform_set_irq_trigger; - break; + struct vfio_platform_irq *irq = &vdev->irqs[index]; + + if (!irq->is_msi) { + switch (flags & VFIO_IRQ_SET_ACTION_TYPE_MASK) { + case VFIO_IRQ_SET_ACTION_MASK: + func = vfio_platform_set_irq_mask; + break; + case VFIO_IRQ_SET_ACTION_UNMASK: + func = vfio_platform_set_irq_unmask; + break; + case VFIO_IRQ_SET_ACTION_TRIGGER: + func = vfio_platform_set_irq_trigger; + break; + } + } else { + switch (flags & VFIO_IRQ_SET_ACTION_TYPE_MASK) { + case VFIO_IRQ_SET_ACTION_MASK: + case VFIO_IRQ_SET_ACTION_UNMASK: + break; + case VFIO_IRQ_SET_ACTION_TRIGGER: + func = vfio_set_msi_trigger; + break; + } } if (!func) @@ -282,11 +467,17 @@ int vfio_platform_set_irqs_ioctl(struct vfio_platform_device *vdev, int vfio_platform_irq_init(struct vfio_platform_device *vdev) { int cnt = 0, i; + int msi_cnt = 0; while (vdev->get_irq(vdev, cnt) >= 0) cnt++; - vdev->irqs = kcalloc(cnt, sizeof(struct vfio_platform_irq), GFP_KERNEL); + if (vdev->of_get_msi) + msi_cnt = vdev->of_get_msi(vdev); + vdev->num_msis = msi_cnt; + + vdev->irqs = kcalloc(cnt + msi_cnt, sizeof(struct vfio_platform_irq), + GFP_KERNEL); if (!vdev->irqs) return -ENOMEM; @@ -311,6 +502,21 @@ int vfio_platform_irq_init(struct vfio_platform_device *vdev) vdev->num_irqs = cnt; + /* + * MSI(s) are counted as '1' as far as number of IRQs + * is concerned and it is at last index. We fill the + * count in the first index of MSI(s). + */ + if (msi_cnt > 0) { + vdev->irqs[i].flags = VFIO_IRQ_INFO_EVENTFD; + vdev->irqs[i].count = msi_cnt; + vdev->irqs[i].hwirq = 0; + vdev->irqs[i].masked = false; + vdev->irqs[i].is_msi = true; + + vdev->num_irqs++; + } + return 0; err: kfree(vdev->irqs); @@ -320,10 +526,18 @@ int vfio_platform_irq_init(struct vfio_platform_device *vdev) void vfio_platform_irq_cleanup(struct vfio_platform_device *vdev) { int i; + int non_msi_irqs = vdev->num_msis > 0 ? + vdev->num_irqs - 1 : vdev->num_irqs; - for (i = 0; i < vdev->num_irqs; i++) + for (i = 0; i < non_msi_irqs; i++) vfio_set_trigger(vdev, i, -1, NULL); + if (vdev->num_msis) { + vfio_set_msi_trigger(vdev, 0, 0, 0, + VFIO_IRQ_SET_DATA_NONE, NULL); + vdev->num_msis = 0; + } + vdev->num_irqs = 0; kfree(vdev->irqs); } diff --git a/drivers/vfio/platform/vfio_platform_private.h b/drivers/vfio/platform/vfio_platform_private.h index 289089910643..2aea445e1071 100644 --- a/drivers/vfio/platform/vfio_platform_private.h +++ b/drivers/vfio/platform/vfio_platform_private.h @@ -9,6 +9,7 @@ #include #include +#include #define VFIO_PLATFORM_OFFSET_SHIFT 40 #define VFIO_PLATFORM_OFFSET_MASK (((u64)(1) << VFIO_PLATFORM_OFFSET_SHIFT) - 1) @@ -26,6 +27,7 @@ struct vfio_platform_irq { char *name; struct eventfd_ctx *trigger; bool masked; + bool is_msi; spinlock_t lock; struct virqfd *unmask; struct virqfd *mask; @@ -46,13 +48,16 @@ struct vfio_platform_device { u32 num_regions; struct vfio_platform_irq *irqs; u32 num_irqs; + u32 num_msis; int refcnt; struct mutex igate; struct module *parent_module; const char *compat; const char *acpihid; struct module *reset_module; + struct module *msi_module; struct device *device; + int config_msi; /* * These fields should be filled by the bus specific binder @@ -65,11 +70,19 @@ struct vfio_platform_device { (*get_resource)(struct vfio_platform_device *vdev, int i); int (*get_irq)(struct vfio_platform_device *vdev, int i); int (*of_reset)(struct vfio_platform_device *vdev); + u32 (*of_get_msi)(struct vfio_platform_device *vdev); + int (*of_msi_write)(struct vfio_platform_device *vdev, + struct msi_desc *desc, + struct msi_msg *msg); bool reset_required; }; typedef int (*vfio_platform_reset_fn_t)(struct vfio_platform_device *vdev); +typedef u32 (*vfio_platform_get_msi_fn_t)(struct vfio_platform_device *vdev); +typedef int (*vfio_platform_msi_write_fn_t)(struct vfio_platform_device *vdev, + struct msi_desc *desc, + struct msi_msg *msg); struct vfio_platform_reset_node { struct list_head link; @@ -78,6 +91,14 @@ struct vfio_platform_reset_node { vfio_platform_reset_fn_t of_reset; }; +struct vfio_platform_msi_node { + struct list_head link; + char *compat; + struct module *owner; + vfio_platform_get_msi_fn_t of_get_msi; + vfio_platform_msi_write_fn_t of_msi_write; +}; + extern int vfio_platform_probe_common(struct vfio_platform_device *vdev, struct device *dev); extern struct vfio_platform_device *vfio_platform_remove_common @@ -94,6 +115,8 @@ extern int vfio_platform_set_irqs_ioctl(struct vfio_platform_device *vdev, extern void __vfio_platform_register_reset(struct vfio_platform_reset_node *n); extern void vfio_platform_unregister_reset(const char *compat, vfio_platform_reset_fn_t fn); +void __vfio_platform_register_msi(struct vfio_platform_msi_node *n); +void vfio_platform_unregister_msi(const char *compat); #define vfio_platform_register_reset(__compat, __reset) \ static struct vfio_platform_reset_node __reset ## _node = { \ .owner = THIS_MODULE, \ From patchwork Thu Nov 12 17:58:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikas Gupta X-Patchwork-Id: 11900913 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 165B1C2D0E4 for ; Thu, 12 Nov 2020 18:01:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AAD9722240 for ; Thu, 12 Nov 2020 18:01:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="RwOx1L8D" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726943AbgKLSBX (ORCPT ); Thu, 12 Nov 2020 13:01:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726497AbgKLR7N (ORCPT ); Thu, 12 Nov 2020 12:59:13 -0500 Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B1E8C0613D6 for ; Thu, 12 Nov 2020 09:59:13 -0800 (PST) Received: by mail-pf1-x442.google.com with SMTP id 10so5256831pfp.5 for ; Thu, 12 Nov 2020 09:59:13 -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=vx/V2yPC1oda+++yIiTI4nNtRf5AYxolRV1TUuH5zOU=; b=RwOx1L8DUhVhKOPYnLi7bsdXoZ/yPCr6fReu1GWRHlk5cb3f52VUscEvO0q22snZIT 1Be0VCHqgVsx/BxYw1uHctznBG6f8f8RF0bfANMx3MYC/IGUR2oMsGY6op1vzcqCsN3r 1cLrA/UaWeXPb70l9yTode2Ptg+4s5YksO9Ww= 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=vx/V2yPC1oda+++yIiTI4nNtRf5AYxolRV1TUuH5zOU=; b=c9kHZYCTPoSyTQOeUBa9p/60KBQxc/H/lDziQmfGr4L5pFEqhTr0XP4VFiiSBpr7xu 7ZYS20xklInCCbh3jk79egplAvSRutnvQx52Z61yzOMEaI5sthkyzkpC0Te1cWKyAY95 Ga+BuDAb7QxOEy1IA9f2vFXFUgshZNtvvwWzwslenUxGyucSXvuKSsBHN2ELZZtzrfbt 3D7RGWY4iLZCpH+RruYP+e1Lv4gpUz1LqIHXLcqhbKFFRExGT0lKITPEgIpn9V3lMlOC PPFyyiMEIZdbUIibSZsK47RUvwYgreWbMfT9Gjb2gHfFGrhnAPFEukJKP4WdNuyV6gAu CoTw== X-Gm-Message-State: AOAM533ma8xLpuNBVcWaivN+RhHXHyqYlnSWjdwXLlfTWsMC2JcSiJzu yBOMUpWTnIoBqSQOpfKkdrjP3Q== X-Google-Smtp-Source: ABdhPJx6e6qTX1p4SvCxoSACcyaECsmm+Op8sR6k+fbs6JZXKGAbZ6VDImRZFtzsWVOj6e1LHIuQUQ== X-Received: by 2002:a63:5159:: with SMTP id r25mr567387pgl.43.1605203952543; Thu, 12 Nov 2020 09:59:12 -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.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Nov 2020 09:59:11 -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 2/3] vfio/platform: change cleanup order Date: Thu, 12 Nov 2020 23:28:51 +0530 Message-Id: <20201112175852.21572-3-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 In the case of msi, vendor specific msi module may require region access to handle msi cleanup so we need to cleanup region after irq cleanup only. Signed-off-by: Vikas Gupta --- drivers/vfio/platform/vfio_platform_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/vfio/platform/vfio_platform_common.c b/drivers/vfio/platform/vfio_platform_common.c index 226aa8083751..ca4a01c488b8 100644 --- a/drivers/vfio/platform/vfio_platform_common.c +++ b/drivers/vfio/platform/vfio_platform_common.c @@ -278,8 +278,8 @@ static void vfio_platform_release(void *device_data) WARN_ON(1); } pm_runtime_put(vdev->device); - vfio_platform_regions_cleanup(vdev); vfio_platform_irq_cleanup(vdev); + vfio_platform_regions_cleanup(vdev); } mutex_unlock(&driver_lock); 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");