From: Viktor Prutyanov <viktor@daynix.com>
To: mst@redhat.com, jasowang@redhat.com, peterx@redhat.com,
marcel.apfelbaum@gmail.com
Cc: qemu-devel@nongnu.org, viktor@daynix.com, yan@daynix.com,
yuri.benditovich@daynix.com
Subject: [RFC PATCH v2 1/4] pci: add handling of Enable bit in ATS Control Register
Date: Mon, 1 May 2023 05:02:18 +0300 [thread overview]
Message-ID: <20230501020221.188376-2-viktor@daynix.com> (raw)
In-Reply-To: <20230501020221.188376-1-viktor@daynix.com>
According to PCIe Address Translation Services specification 5.1.3.,
ATS Control Register has Enable bit to enable/disable ATS.
A trigger function is called at the Enable bit change, so that PCIe
devices can handle ATS enable/disable.
Signed-off-by: Viktor Prutyanov <viktor@daynix.com>
---
hw/pci/pcie.c | 22 ++++++++++++++++++++++
include/hw/pci/pcie.h | 5 +++++
2 files changed, 27 insertions(+)
diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c
index b8c24cf45f..14ac1b0fb9 100644
--- a/hw/pci/pcie.c
+++ b/hw/pci/pcie.c
@@ -1063,6 +1063,28 @@ void pcie_ats_init(PCIDevice *dev, uint16_t offset, bool aligned)
pci_set_word(dev->wmask + dev->exp.ats_cap + PCI_ATS_CTRL, 0x800f);
}
+void pcie_ats_config_write(PCIDevice *dev, uint32_t address,
+ uint32_t val, int len,
+ void (*trigger_func)(PCIDevice *dev, bool enable))
+{
+ uint32_t off;
+ uint16_t ats_cap = dev->exp.ats_cap;
+
+ if (!ats_cap || address < ats_cap) {
+ return;
+ }
+ off = address - ats_cap;
+ if (off >= PCI_EXT_CAP_ATS_SIZEOF) {
+ return;
+ }
+
+ if (range_covers_byte(off, len, PCI_ATS_CTRL + 1)) {
+ if (trigger_func) {
+ trigger_func(dev, !!(val & PCI_ATS_CTRL_ENABLE));
+ }
+ }
+}
+
/* ACS (Access Control Services) */
void pcie_acs_init(PCIDevice *dev, uint16_t offset)
{
diff --git a/include/hw/pci/pcie.h b/include/hw/pci/pcie.h
index 3cc2b15957..f5571527d3 100644
--- a/include/hw/pci/pcie.h
+++ b/include/hw/pci/pcie.h
@@ -146,4 +146,9 @@ void pcie_cap_slot_unplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
Error **errp);
void pcie_cap_slot_unplug_request_cb(HotplugHandler *hotplug_dev,
DeviceState *dev, Error **errp);
+
+void pcie_ats_config_write(PCIDevice *dev, uint32_t address,
+ uint32_t val, int len,
+ void (*trigger_func)(PCIDevice *dev, bool enable));
+
#endif /* QEMU_PCIE_H */
--
2.35.1
next prev parent reply other threads:[~2023-05-01 2:03 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-01 2:02 [RFC PATCH v2 0/4] vhost: register and change IOMMU flag depending on ATS state Viktor Prutyanov
2023-05-01 2:02 ` Viktor Prutyanov [this message]
2023-05-01 2:02 ` [RFC PATCH v2 2/4] virtio-pci: add handling of ATS and Device-TLB enable Viktor Prutyanov
2023-05-08 4:14 ` Jason Wang
2023-05-01 2:02 ` [RFC PATCH v2 3/4] vhost: register and change IOMMU flag depending on Device-TLB state Viktor Prutyanov
2023-05-08 5:25 ` Jason Wang
2023-05-08 5:28 ` Jason Wang
2023-05-12 14:13 ` Viktor Prutyanov
2023-05-01 2:02 ` [RFC PATCH v2 4/4] virtio-net: pass Device-TLB enable/disable events to vhost Viktor Prutyanov
2023-05-08 5:26 ` Jason Wang
2023-05-12 14:06 ` Viktor Prutyanov
2023-05-08 4:09 ` [RFC PATCH v2 0/4] vhost: register and change IOMMU flag depending on ATS state Jason Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230501020221.188376-2-viktor@daynix.com \
--to=viktor@daynix.com \
--cc=jasowang@redhat.com \
--cc=marcel.apfelbaum@gmail.com \
--cc=mst@redhat.com \
--cc=peterx@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=yan@daynix.com \
--cc=yuri.benditovich@daynix.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).