init.c (50501936288d6a29d7ef78f25d00e33240fad45f) init.c (f5ccf55e10281ae4523b83fe87f2c27fd634dc9d)
1// SPDX-License-Identifier: GPL-2.0
2/* Copyright(c) 2019 Intel Corporation. All rights rsvd. */
3#include <linux/init.h>
4#include <linux/kernel.h>
5#include <linux/module.h>
6#include <linux/slab.h>
7#include <linux/pci.h>
8#include <linux/interrupt.h>

--- 536 unchanged lines hidden (view full) ---

545 spin_lock_init(&idxd->dev_lock);
546 spin_lock_init(&idxd->cmd_lock);
547
548 return idxd;
549}
550
551static int idxd_enable_system_pasid(struct idxd_device *idxd)
552{
1// SPDX-License-Identifier: GPL-2.0
2/* Copyright(c) 2019 Intel Corporation. All rights rsvd. */
3#include <linux/init.h>
4#include <linux/kernel.h>
5#include <linux/module.h>
6#include <linux/slab.h>
7#include <linux/pci.h>
8#include <linux/interrupt.h>

--- 536 unchanged lines hidden (view full) ---

545 spin_lock_init(&idxd->dev_lock);
546 spin_lock_init(&idxd->cmd_lock);
547
548 return idxd;
549}
550
551static int idxd_enable_system_pasid(struct idxd_device *idxd)
552{
553 return -EOPNOTSUPP;
553 struct pci_dev *pdev = idxd->pdev;
554 struct device *dev = &pdev->dev;
555 struct iommu_domain *domain;
556 ioasid_t pasid;
557 int ret;
558
559 /*
560 * Attach a global PASID to the DMA domain so that we can use ENQCMDS
561 * to submit work on buffers mapped by DMA API.
562 */
563 domain = iommu_get_domain_for_dev(dev);
564 if (!domain)
565 return -EPERM;
566
567 pasid = iommu_alloc_global_pasid(dev);
568 if (pasid == IOMMU_PASID_INVALID)
569 return -ENOSPC;
570
571 /*
572 * DMA domain is owned by the driver, it should support all valid
573 * types such as DMA-FQ, identity, etc.
574 */
575 ret = iommu_attach_device_pasid(domain, dev, pasid);
576 if (ret) {
577 dev_err(dev, "failed to attach device pasid %d, domain type %d",
578 pasid, domain->type);
579 iommu_free_global_pasid(pasid);
580 return ret;
581 }
582
583 /* Since we set user privilege for kernel DMA, enable completion IRQ */
584 idxd_set_user_intr(idxd, 1);
585 idxd->pasid = pasid;
586
587 return ret;
554}
555
556static void idxd_disable_system_pasid(struct idxd_device *idxd)
557{
588}
589
590static void idxd_disable_system_pasid(struct idxd_device *idxd)
591{
592 struct pci_dev *pdev = idxd->pdev;
593 struct device *dev = &pdev->dev;
594 struct iommu_domain *domain;
558
595
559 iommu_sva_unbind_device(idxd->sva);
596 domain = iommu_get_domain_for_dev(dev);
597 if (!domain)
598 return;
599
600 iommu_detach_device_pasid(domain, dev, idxd->pasid);
601 iommu_free_global_pasid(idxd->pasid);
602
603 idxd_set_user_intr(idxd, 0);
560 idxd->sva = NULL;
604 idxd->sva = NULL;
605 idxd->pasid = IOMMU_PASID_INVALID;
561}
562
563static int idxd_enable_sva(struct pci_dev *pdev)
564{
565 int ret;
566
567 ret = iommu_dev_enable_feature(&pdev->dev, IOMMU_DEV_FEAT_IOPF);
568 if (ret)

--- 26 unchanged lines hidden (view full) ---

595 dev_dbg(dev, "IDXD reset complete\n");
596
597 if (IS_ENABLED(CONFIG_INTEL_IDXD_SVM) && sva) {
598 if (idxd_enable_sva(pdev)) {
599 dev_warn(dev, "Unable to turn on user SVA feature.\n");
600 } else {
601 set_bit(IDXD_FLAG_USER_PASID_ENABLED, &idxd->flags);
602
606}
607
608static int idxd_enable_sva(struct pci_dev *pdev)
609{
610 int ret;
611
612 ret = iommu_dev_enable_feature(&pdev->dev, IOMMU_DEV_FEAT_IOPF);
613 if (ret)

--- 26 unchanged lines hidden (view full) ---

640 dev_dbg(dev, "IDXD reset complete\n");
641
642 if (IS_ENABLED(CONFIG_INTEL_IDXD_SVM) && sva) {
643 if (idxd_enable_sva(pdev)) {
644 dev_warn(dev, "Unable to turn on user SVA feature.\n");
645 } else {
646 set_bit(IDXD_FLAG_USER_PASID_ENABLED, &idxd->flags);
647
603 if (idxd_enable_system_pasid(idxd))
604 dev_warn(dev, "No in-kernel DMA with PASID.\n");
648 rc = idxd_enable_system_pasid(idxd);
649 if (rc)
650 dev_warn(dev, "No in-kernel DMA with PASID. %d\n", rc);
605 else
606 set_bit(IDXD_FLAG_PASID_ENABLED, &idxd->flags);
607 }
608 } else if (!sva) {
609 dev_warn(dev, "User forced SVA off via module param.\n");
610 }
611
612 idxd_read_caps(idxd);

--- 255 unchanged lines hidden ---
651 else
652 set_bit(IDXD_FLAG_PASID_ENABLED, &idxd->flags);
653 }
654 } else if (!sva) {
655 dev_warn(dev, "User forced SVA off via module param.\n");
656 }
657
658 idxd_read_caps(idxd);

--- 255 unchanged lines hidden ---