[RFC PATCH 6/7] tsm: Allow tsm connect ops to be used for multiple operations

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The connect sysfs file will be used in the guest for TDISP locking and
transitioning the device to the run state.

Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@xxxxxxxxxx>
---
 drivers/pci/tsm.c       | 16 +++++++---------
 include/linux/pci-tsm.h |  4 +++-
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/pci/tsm.c b/drivers/pci/tsm.c
index a0deddac6767..3251dc5eeef8 100644
--- a/drivers/pci/tsm.c
+++ b/drivers/pci/tsm.c
@@ -45,7 +45,7 @@ static int pci_tsm_disconnect(struct pci_dev *pdev)
 	return 0;
 }
 
-static int pci_tsm_connect(struct pci_dev *pdev)
+static int pci_tsm_connect(struct pci_dev *pdev, int new_state)
 {
 	struct pci_tsm *pci_tsm = pdev->tsm;
 	int rc;
@@ -53,15 +53,13 @@ static int pci_tsm_connect(struct pci_dev *pdev)
 	lockdep_assert_held(&pci_tsm_rwsem);
 
 	scoped_cond_guard(mutex_intr, return -EINTR, &pci_tsm->lock) {
-		if (pci_tsm->state >= PCI_TSM_CONNECT)
-			return 0;
+
 		if (pci_tsm->state < PCI_TSM_INIT)
 			return -ENXIO;
 
-		rc = tsm_ops->connect(pdev);
+		rc = tsm_ops->connect(pdev, new_state);
 		if (rc)
 			return rc;
-		pci_tsm->state = PCI_TSM_CONNECT;
 	}
 	return 0;
 }
@@ -70,16 +68,16 @@ static ssize_t connect_store(struct device *dev, struct device_attribute *attr,
 			     const char *buf, size_t len)
 {
 	int rc;
-	bool connect;
+	int connect;
 	struct pci_dev *pdev = to_pci_dev(dev);
 
-	rc = kstrtobool(buf, &connect);
+	rc = kstrtoint(buf, 0, &connect);
 	if (rc)
 		return rc;
 
 	scoped_cond_guard(rwsem_read_intr, return -EINTR, &pci_tsm_rwsem) {
 		if (connect)
-			rc = pci_tsm_connect(pdev);
+			rc = pci_tsm_connect(pdev, connect);
 		else
 			rc = pci_tsm_disconnect(pdev);
 		if (rc)
@@ -97,7 +95,7 @@ static ssize_t connect_show(struct device *dev, struct device_attribute *attr,
 	scoped_cond_guard(rwsem_read_intr, return -EINTR, &pci_tsm_rwsem) {
 		if (!pdev->tsm)
 			return -ENXIO;
-		connect_status = pdev->tsm->state >= PCI_TSM_CONNECT;
+		connect_status = pdev->tsm->state;
 	}
 	return sysfs_emit(buf, "%d\n", connect_status);
 }
diff --git a/include/linux/pci-tsm.h b/include/linux/pci-tsm.h
index 774496d7b37e..6ad2081a329d 100644
--- a/include/linux/pci-tsm.h
+++ b/include/linux/pci-tsm.h
@@ -19,6 +19,8 @@ enum pci_tsm_state {
 	PCI_TSM_INIT,
 	PCI_TSM_CONNECT,
 	PCI_TSM_BOUND,
+	PCI_TSM_LOCKED,
+	PCI_TSM_RUN,
 };
 
 /**
@@ -49,7 +51,7 @@ struct pci_tsm {
 struct pci_tsm_ops {
 	struct pci_dsm *(*probe)(struct pci_dev *pdev);
 	void (*remove)(struct pci_dsm *dsm);
-	int (*connect)(struct pci_dev *pdev);
+	int (*connect)(struct pci_dev *pdev, int new_state);
 	void (*disconnect)(struct pci_dev *pdev);
 	int (*bind)(struct vfio_device *vfio_dev, u32 guest_rid);
 	void (*unbind)(struct vfio_device *vfio_dev);
-- 
2.43.0





[Index of Archives]     [DMA Engine]     [Linux Coverity]     [Linux USB]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Greybus]

  Powered by Linux