* [PATCH 0/3] Additional AMD IOMMUv2 patches
@ 2011-12-15 10:23 Joerg Roedel
2011-12-15 10:23 ` [PATCH 1/3] iommu/amd: Adapt IOMMU driver to PCI register name changes Joerg Roedel
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Joerg Roedel @ 2011-12-15 10:23 UTC (permalink / raw)
To: iommu; +Cc: linux-kernel
Hi,
here are 3 additional patches I have in my queue for the AMD IOMMUv2 driver.
The patches extend the exposed API a little bit and fix the build error in
linux-next.
Regards,
Joerg
Diffstat:
drivers/iommu/amd_iommu.c | 59 ++++++++++++++++++++++++++++++++++++-----
drivers/iommu/amd_iommu_v2.c | 35 +++++++++++++++++++++++++
include/linux/amd-iommu.h | 43 ++++++++++++++++++++++++++++++
3 files changed, 129 insertions(+), 8 deletions(-)
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/3] iommu/amd: Adapt IOMMU driver to PCI register name changes
2011-12-15 10:23 [PATCH 0/3] Additional AMD IOMMUv2 patches Joerg Roedel
@ 2011-12-15 10:23 ` Joerg Roedel
2011-12-15 10:23 ` [PATCH 2/3] iommu/amd: Add amd_iommu_device_info() function Joerg Roedel
2011-12-15 10:23 ` [PATCH 3/3] iommu/amd: Add invalidate-context call-back Joerg Roedel
2 siblings, 0 replies; 4+ messages in thread
From: Joerg Roedel @ 2011-12-15 10:23 UTC (permalink / raw)
To: iommu; +Cc: linux-kernel, Joerg Roedel
The symbolic register names for PCI and PASID changed in
PCI code. This patch adapts the AMD IOMMU driver to these
changes.
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
---
drivers/iommu/amd_iommu.c | 16 ++++++++--------
1 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index a7cbcd4..d5074f4 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -176,8 +176,8 @@ static bool pci_iommuv2_capable(struct pci_dev *pdev)
{
static const int caps[] = {
PCI_EXT_CAP_ID_ATS,
- PCI_PRI_CAP,
- PCI_PASID_CAP,
+ PCI_EXT_CAP_ID_PRI,
+ PCI_EXT_CAP_ID_PASID,
};
int i, pos;
@@ -1978,13 +1978,13 @@ static int pri_reset_while_enabled(struct pci_dev *pdev)
u16 control;
int pos;
- pos = pci_find_ext_capability(pdev, PCI_PRI_CAP);
+ pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_PRI);
if (!pos)
return -EINVAL;
- pci_read_config_word(pdev, pos + PCI_PRI_CONTROL_OFF, &control);
- control |= PCI_PRI_RESET;
- pci_write_config_word(pdev, pos + PCI_PRI_CONTROL_OFF, control);
+ pci_read_config_word(pdev, pos + PCI_PRI_CTRL, &control);
+ control |= PCI_PRI_CTRL_RESET;
+ pci_write_config_word(pdev, pos + PCI_PRI_CTRL, control);
return 0;
}
@@ -2042,11 +2042,11 @@ bool pci_pri_tlp_required(struct pci_dev *pdev)
u16 control;
int pos;
- pos = pci_find_ext_capability(pdev, PCI_PRI_CAP);
+ pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_PRI);
if (!pos)
return false;
- pci_read_config_word(pdev, pos + PCI_PRI_CONTROL_OFF, &control);
+ pci_read_config_word(pdev, pos + PCI_PRI_CTRL, &control);
return (control & PCI_PRI_TLP_OFF) ? true : false;
}
--
1.7.5.4
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 2/3] iommu/amd: Add amd_iommu_device_info() function
2011-12-15 10:23 [PATCH 0/3] Additional AMD IOMMUv2 patches Joerg Roedel
2011-12-15 10:23 ` [PATCH 1/3] iommu/amd: Adapt IOMMU driver to PCI register name changes Joerg Roedel
@ 2011-12-15 10:23 ` Joerg Roedel
2011-12-15 10:23 ` [PATCH 3/3] iommu/amd: Add invalidate-context call-back Joerg Roedel
2 siblings, 0 replies; 4+ messages in thread
From: Joerg Roedel @ 2011-12-15 10:23 UTC (permalink / raw)
To: iommu; +Cc: linux-kernel, Joerg Roedel
This function can be used to find out which features
necessary for IOMMUv2 usage are available on a given device.
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
---
drivers/iommu/amd_iommu.c | 43 +++++++++++++++++++++++++++++++++++++++++++
include/linux/amd-iommu.h | 26 ++++++++++++++++++++++++++
2 files changed, 69 insertions(+), 0 deletions(-)
diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index d5074f4..03944e7 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -3565,3 +3565,46 @@ void amd_iommu_enable_device_erratum(struct pci_dev *pdev, u32 erratum)
dev_data->errata |= (1 << erratum);
}
EXPORT_SYMBOL(amd_iommu_enable_device_erratum);
+
+int amd_iommu_device_info(struct pci_dev *pdev,
+ struct amd_iommu_device_info *info)
+{
+ int max_pasids;
+ int pos;
+
+ if (pdev == NULL || info == NULL)
+ return -EINVAL;
+
+ if (!amd_iommu_v2_supported())
+ return -EINVAL;
+
+ memset(info, 0, sizeof(*info));
+
+ pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_ATS);
+ if (pos)
+ info->flags |= AMD_IOMMU_DEVICE_FLAG_ATS_SUP;
+
+ pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_PRI);
+ if (pos)
+ info->flags |= AMD_IOMMU_DEVICE_FLAG_PRI_SUP;
+
+ pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_PASID);
+ if (pos) {
+ int features;
+
+ max_pasids = 1 << (9 * (amd_iommu_max_glx_val + 1));
+ max_pasids = min(max_pasids, (1 << 20));
+
+ info->flags |= AMD_IOMMU_DEVICE_FLAG_PASID_SUP;
+ info->max_pasids = min(pci_max_pasids(pdev), max_pasids);
+
+ features = pci_pasid_features(pdev);
+ if (features & PCI_PASID_CAP_EXEC)
+ info->flags |= AMD_IOMMU_DEVICE_FLAG_EXEC_SUP;
+ if (features & PCI_PASID_CAP_PRIV)
+ info->flags |= AMD_IOMMU_DEVICE_FLAG_PRIV_SUP;
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL(amd_iommu_device_info);
diff --git a/include/linux/amd-iommu.h b/include/linux/amd-iommu.h
index 06688c4..c03c281 100644
--- a/include/linux/amd-iommu.h
+++ b/include/linux/amd-iommu.h
@@ -119,6 +119,32 @@ typedef int (*amd_iommu_invalid_ppr_cb)(struct pci_dev *pdev,
extern int amd_iommu_set_invalid_ppr_cb(struct pci_dev *pdev,
amd_iommu_invalid_ppr_cb cb);
+/**
+ * amd_iommu_device_info() - Get information about IOMMUv2 support of a
+ * PCI device
+ * @pdev: PCI device to query information from
+ * @info: A pointer to an amd_iommu_device_info structure which will contain
+ * the information about the PCI device
+ *
+ * Returns 0 on success, negative value on error
+ */
+
+#define AMD_IOMMU_DEVICE_FLAG_ATS_SUP 0x1 /* ATS feature supported */
+#define AMD_IOMMU_DEVICE_FLAG_PRI_SUP 0x2 /* PRI feature supported */
+#define AMD_IOMMU_DEVICE_FLAG_PASID_SUP 0x4 /* PASID context supported */
+#define AMD_IOMMU_DEVICE_FLAG_EXEC_SUP 0x8 /* Device may request execution
+ on memory pages */
+#define AMD_IOMMU_DEVICE_FLAG_PRIV_SUP 0x10 /* Device may request
+ super-user privileges */
+
+struct amd_iommu_device_info {
+ int max_pasids;
+ u32 flags;
+};
+
+extern int amd_iommu_device_info(struct pci_dev *pdev,
+ struct amd_iommu_device_info *info);
+
#else
static inline int amd_iommu_detect(void) { return -ENODEV; }
--
1.7.5.4
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 3/3] iommu/amd: Add invalidate-context call-back
2011-12-15 10:23 [PATCH 0/3] Additional AMD IOMMUv2 patches Joerg Roedel
2011-12-15 10:23 ` [PATCH 1/3] iommu/amd: Adapt IOMMU driver to PCI register name changes Joerg Roedel
2011-12-15 10:23 ` [PATCH 2/3] iommu/amd: Add amd_iommu_device_info() function Joerg Roedel
@ 2011-12-15 10:23 ` Joerg Roedel
2 siblings, 0 replies; 4+ messages in thread
From: Joerg Roedel @ 2011-12-15 10:23 UTC (permalink / raw)
To: iommu; +Cc: linux-kernel, Joerg Roedel
This call-back is invoked when the task that is bound to a
pasid is about to exit. The driver can use it to shutdown
all context related to that context in a safe way.
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
---
drivers/iommu/amd_iommu_v2.c | 35 +++++++++++++++++++++++++++++++++++
include/linux/amd-iommu.h | 17 +++++++++++++++++
2 files changed, 52 insertions(+), 0 deletions(-)
diff --git a/drivers/iommu/amd_iommu_v2.c b/drivers/iommu/amd_iommu_v2.c
index fe812e2..8add9f1 100644
--- a/drivers/iommu/amd_iommu_v2.c
+++ b/drivers/iommu/amd_iommu_v2.c
@@ -63,6 +63,7 @@ struct device_state {
int pasid_levels;
int max_pasids;
amd_iommu_invalid_ppr_cb inv_ppr_cb;
+ amd_iommu_invalidate_ctx inv_ctx_cb;
spinlock_t lock;
wait_queue_head_t wq;
};
@@ -637,6 +638,9 @@ again:
dev_state = pasid_state->device_state;
pasid = pasid_state->pasid;
+ if (pasid_state->device_state->inv_ctx_cb)
+ dev_state->inv_ctx_cb(dev_state->pdev, pasid);
+
unbind_pasid(dev_state, pasid);
/* Task may be in the list multiple times */
@@ -881,6 +885,37 @@ out_unlock:
}
EXPORT_SYMBOL(amd_iommu_set_invalid_ppr_cb);
+int amd_iommu_set_invalidate_ctx_cb(struct pci_dev *pdev,
+ amd_iommu_invalidate_ctx cb)
+{
+ struct device_state *dev_state;
+ unsigned long flags;
+ u16 devid;
+ int ret;
+
+ if (!amd_iommu_v2_supported())
+ return -ENODEV;
+
+ devid = device_id(pdev);
+
+ spin_lock_irqsave(&state_lock, flags);
+
+ ret = -EINVAL;
+ dev_state = state_table[devid];
+ if (dev_state == NULL)
+ goto out_unlock;
+
+ dev_state->inv_ctx_cb = cb;
+
+ ret = 0;
+
+out_unlock:
+ spin_unlock_irqrestore(&state_lock, flags);
+
+ return ret;
+}
+EXPORT_SYMBOL(amd_iommu_set_invalidate_ctx_cb);
+
static int __init amd_iommu_v2_init(void)
{
size_t state_table_size;
diff --git a/include/linux/amd-iommu.h b/include/linux/amd-iommu.h
index c03c281..ef00610 100644
--- a/include/linux/amd-iommu.h
+++ b/include/linux/amd-iommu.h
@@ -145,6 +145,23 @@ struct amd_iommu_device_info {
extern int amd_iommu_device_info(struct pci_dev *pdev,
struct amd_iommu_device_info *info);
+/**
+ * amd_iommu_set_invalidate_ctx_cb() - Register a call-back for invalidating
+ * a pasid context. This call-back is
+ * invoked when the IOMMUv2 driver needs to
+ * invalidate a PASID context, for example
+ * because the task that is bound to that
+ * context is about to exit.
+ *
+ * @pdev: The PCI device the call-back should be registered for
+ * @cb: The call-back function
+ */
+
+typedef void (*amd_iommu_invalidate_ctx)(struct pci_dev *pdev, int pasid);
+
+extern int amd_iommu_set_invalidate_ctx_cb(struct pci_dev *pdev,
+ amd_iommu_invalidate_ctx cb);
+
#else
static inline int amd_iommu_detect(void) { return -ENODEV; }
--
1.7.5.4
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-12-15 10:23 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-15 10:23 [PATCH 0/3] Additional AMD IOMMUv2 patches Joerg Roedel
2011-12-15 10:23 ` [PATCH 1/3] iommu/amd: Adapt IOMMU driver to PCI register name changes Joerg Roedel
2011-12-15 10:23 ` [PATCH 2/3] iommu/amd: Add amd_iommu_device_info() function Joerg Roedel
2011-12-15 10:23 ` [PATCH 3/3] iommu/amd: Add invalidate-context call-back Joerg Roedel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®