From: Wei Wang <wei.wang2@amd.com>
To: JBeulich@suse.com, keir@xen.org
Cc: xen-devel@lists.xensource.com
Subject: [PATCH 04 of 16] amd iommu: Enable ppr log
Date: Wed, 14 Dec 2011 16:29:25 +0100 [thread overview]
Message-ID: <d3aa7f936872abacb7e0.1323876565@gran.amd.com> (raw)
In-Reply-To: <patchbomb.1323876561@gran.amd.com>
# HG changeset patch
# User Wei Wang <wei.wang2@amd.com>
# Date 1323875319 -3600
# Node ID d3aa7f936872abacb7e059393fa8963db35c4045
# Parent ea52a2b93dffe708084fdc6ee663bd5eee8c1031
amd iommu: Enable ppr log.
IOMMUv2 writes peripheral page service request (PPR) records into ppr log
to report DMA page request from ATS devices to OS.
Signed-off-by: Wei Wang <wei.wang2@amd.com>
diff -r ea52a2b93dff -r d3aa7f936872 xen/drivers/passthrough/amd/iommu_init.c
--- a/xen/drivers/passthrough/amd/iommu_init.c Wed Dec 14 12:58:17 2011 +0100
+++ b/xen/drivers/passthrough/amd/iommu_init.c Wed Dec 14 16:08:39 2011 +0100
@@ -178,6 +178,34 @@ static void register_iommu_event_log_in_
writel(entry, iommu->mmio_base+IOMMU_EVENT_LOG_BASE_HIGH_OFFSET);
}
+static void register_iommu_ppr_log_in_mmio_space(struct amd_iommu *iommu)
+{
+ u64 addr_64, addr_lo, addr_hi;
+ u32 power_of2_entries;
+ u32 entry;
+
+ ASSERT ( iommu->ppr_log.buffer );
+
+ addr_64 = (u64)virt_to_maddr(iommu->ppr_log.buffer);
+ addr_lo = addr_64 & DMA_32BIT_MASK;
+ addr_hi = addr_64 >> 32;
+
+ entry = 0;
+ iommu_set_addr_lo_to_reg(&entry, addr_lo >> PAGE_SHIFT);
+ writel(entry, iommu->mmio_base + IOMMU_PPR_LOG_BASE_LOW_OFFSET);
+
+ power_of2_entries = get_order_from_bytes(iommu->ppr_log.alloc_size) +
+ IOMMU_PPR_LOG_POWER_OF2_ENTRIES_PER_PAGE;
+
+ entry = 0;
+ iommu_set_addr_hi_to_reg(&entry, addr_hi);
+ set_field_in_reg_u32(power_of2_entries, entry,
+ IOMMU_PPR_LOG_LENGTH_MASK,
+ IOMMU_PPR_LOG_LENGTH_SHIFT, &entry);
+ writel(entry, iommu->mmio_base + IOMMU_PPR_LOG_BASE_HIGH_OFFSET);
+}
+
+
static void set_iommu_translation_control(struct amd_iommu *iommu,
int enable)
{
@@ -278,6 +306,35 @@ static void set_iommu_event_log_control(
writel(entry, iommu->mmio_base + IOMMU_CONTROL_MMIO_OFFSET);
}
+static void set_iommu_ppr_log_control(struct amd_iommu *iommu,
+ int enable)
+{
+ u32 entry;
+
+ entry = readl(iommu->mmio_base + IOMMU_CONTROL_MMIO_OFFSET);
+
+ /*reset head and tail pointer manually before enablement */
+ if ( enable )
+ {
+ writel(0x0, iommu->mmio_base + IOMMU_PPR_LOG_HEAD_OFFSET);
+ writel(0x0, iommu->mmio_base + IOMMU_PPR_LOG_TAIL_OFFSET);
+
+ iommu_set_bit(&entry, IOMMU_CONTROL_PPR_ENABLE_SHIFT);
+ iommu_set_bit(&entry, IOMMU_CONTROL_PPR_INT_SHIFT);
+ iommu_set_bit(&entry, IOMMU_CONTROL_PPR_LOG_ENABLE_SHIFT);
+ }
+ else
+ {
+ iommu_clear_bit(&entry, IOMMU_CONTROL_PPR_ENABLE_SHIFT);
+ iommu_clear_bit(&entry, IOMMU_CONTROL_PPR_INT_SHIFT);
+ iommu_clear_bit(&entry, IOMMU_CONTROL_PPR_LOG_ENABLE_SHIFT);
+ }
+
+ writel(entry, iommu->mmio_base + IOMMU_CONTROL_MMIO_OFFSET);
+ if ( enable )
+ AMD_IOMMU_DEBUG("PPR Log Enabled.\n");
+}
+
static void parse_event_log_entry(struct amd_iommu *, u32 entry[]);
static int amd_iommu_read_event_log(struct amd_iommu *iommu)
@@ -585,12 +642,19 @@ static void enable_iommu(struct amd_iomm
register_iommu_event_log_in_mmio_space(iommu);
register_iommu_exclusion_range(iommu);
+ if ( iommu_has_feature(iommu, IOMMU_EXT_FEATURE_PPRSUP_SHIFT) )
+ register_iommu_ppr_log_in_mmio_space(iommu);
+
iommu_msi_set_affinity(irq_to_desc(iommu->irq), &cpu_online_map);
amd_iommu_msi_enable(iommu, IOMMU_CONTROL_ENABLED);
set_iommu_ht_flags(iommu);
set_iommu_command_buffer_control(iommu, IOMMU_CONTROL_ENABLED);
set_iommu_event_log_control(iommu, IOMMU_CONTROL_ENABLED);
+
+ if ( iommu_has_feature(iommu, IOMMU_EXT_FEATURE_PPRSUP_SHIFT) )
+ set_iommu_ppr_log_control(iommu, IOMMU_CONTROL_ENABLED);
+
set_iommu_translation_control(iommu, IOMMU_CONTROL_ENABLED);
if ( iommu_has_feature(iommu, IOMMU_EXT_FEATURE_IASUP_SHIFT) )
@@ -672,16 +736,29 @@ static void * __init allocate_event_log(
IOMMU_EVENT_LOG_DEFAULT_ENTRIES, "Event Log");
}
+static void * __init allocate_ppr_log(struct amd_iommu *iommu)
+{
+ /* allocate 'ppr log' in power of 2 increments of 4K */
+ return allocate_ring_buffer(&iommu->ppr_log, sizeof(ppr_entry_t),
+ IOMMU_PPR_LOG_DEFAULT_ENTRIES, "PPR Log");
+}
+
static int __init amd_iommu_init_one(struct amd_iommu *iommu)
{
+ if ( map_iommu_mmio_region(iommu) != 0 )
+ goto error_out;
+
+ get_iommu_features(iommu);
+
if ( allocate_cmd_buffer(iommu) == NULL )
goto error_out;
if ( allocate_event_log(iommu) == NULL )
goto error_out;
- if ( map_iommu_mmio_region(iommu) != 0 )
- goto error_out;
+ if ( iommu_has_feature(iommu, IOMMU_EXT_FEATURE_PPRSUP_SHIFT) )
+ if ( allocate_ppr_log(iommu) == NULL )
+ goto error_out;
if ( set_iommu_interrupt_handler(iommu) == 0 )
goto error_out;
@@ -694,8 +771,6 @@ static int __init amd_iommu_init_one(str
iommu->dev_table.entries = device_table.entries;
iommu->dev_table.buffer = device_table.buffer;
- get_iommu_features(iommu);
-
enable_iommu(iommu);
printk("AMD-Vi: IOMMU %d Enabled.\n", nr_amd_iommus );
nr_amd_iommus++;
@@ -718,6 +793,7 @@ static void __init amd_iommu_init_cleanu
{
deallocate_ring_buffer(&iommu->cmd_buffer);
deallocate_ring_buffer(&iommu->event_log);
+ deallocate_ring_buffer(&iommu->ppr_log);
unmap_iommu_mmio_region(iommu);
}
xfree(iommu);
@@ -916,6 +992,10 @@ static void disable_iommu(struct amd_iom
amd_iommu_msi_enable(iommu, IOMMU_CONTROL_DISABLED);
set_iommu_command_buffer_control(iommu, IOMMU_CONTROL_DISABLED);
set_iommu_event_log_control(iommu, IOMMU_CONTROL_DISABLED);
+
+ if ( iommu_has_feature(iommu, IOMMU_EXT_FEATURE_PPRSUP_SHIFT) )
+ set_iommu_ppr_log_control(iommu, IOMMU_CONTROL_DISABLED);
+
set_iommu_translation_control(iommu, IOMMU_CONTROL_DISABLED);
iommu->enabled = 0;
diff -r ea52a2b93dff -r d3aa7f936872 xen/include/asm-x86/amd-iommu.h
--- a/xen/include/asm-x86/amd-iommu.h Wed Dec 14 12:58:17 2011 +0100
+++ b/xen/include/asm-x86/amd-iommu.h Wed Dec 14 16:08:39 2011 +0100
@@ -94,6 +94,7 @@ struct amd_iommu {
struct table_struct dev_table;
struct ring_buffer cmd_buffer;
struct ring_buffer event_log;
+ struct ring_buffer ppr_log;
int exclusion_enable;
int exclusion_allow_all;
diff -r ea52a2b93dff -r d3aa7f936872 xen/include/asm-x86/hvm/svm/amd-iommu-defs.h
--- a/xen/include/asm-x86/hvm/svm/amd-iommu-defs.h Wed Dec 14 12:58:17 2011 +0100
+++ b/xen/include/asm-x86/hvm/svm/amd-iommu-defs.h Wed Dec 14 16:08:39 2011 +0100
@@ -27,6 +27,9 @@
/* IOMMU Event Log entries: in power of 2 increments, minimum of 256 */
#define IOMMU_EVENT_LOG_DEFAULT_ENTRIES 512
+/* IOMMU PPR Log entries: in power of 2 increments, minimum of 256 */
+#define IOMMU_PPR_LOG_DEFAULT_ENTRIES 512
+
#define PTE_PER_TABLE_SHIFT 9
#define PTE_PER_TABLE_SIZE (1 << PTE_PER_TABLE_SHIFT)
#define PTE_PER_TABLE_MASK (~(PTE_PER_TABLE_SIZE - 1))
next prev parent reply other threads:[~2011-12-14 15:29 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-14 15:29 [PATCH 00 of 16] [RFC] amd iommu: support ATS device passthru on IOMMUv2 systems Wei Wang
2011-12-14 15:29 ` [PATCH 01 of 16] amd iommu: Refactoring iommu ring buffer definition Wei Wang
2011-12-14 15:29 ` [PATCH 02 of 16] amd iommu: Introduces new helper functions to simplify iommu bitwise operations Wei Wang
2011-12-14 15:29 ` [PATCH 03 of 16] amd iommu: Add iommu emulation for hvm guest Wei Wang
2011-12-15 13:35 ` Tim Deegan
2011-12-15 14:09 ` Wei Wang2
2011-12-15 14:13 ` Jan Beulich
2011-12-15 14:30 ` Wei Wang2
2011-12-14 15:29 ` Wei Wang [this message]
2011-12-14 15:29 ` [PATCH 05 of 16] amd iommu: Enable guest level translation Wei Wang
2011-12-14 15:29 ` [PATCH 06 of 16] amd iommu: add ppr log processing into iommu interrupt handling Wei Wang
2011-12-14 15:29 ` [PATCH 07 of 16] amd iommu: Add 2 hypercalls for libxc Wei Wang
2011-12-14 16:44 ` Jan Beulich
2011-12-14 16:57 ` Wei Wang2
2011-12-14 17:03 ` Jan Beulich
2011-12-15 10:02 ` Wei Wang2
2011-12-14 15:29 ` [PATCH 08 of 16] amd iommu: Add a hypercall for hvmloader Wei Wang
2011-12-14 15:29 ` [PATCH 09 of 16] amd iommu: add iommu mmio handler Wei Wang
2011-12-14 15:29 ` [PATCH 10 of 16] amd iommu: Enable FC bit in iommu host level PTE Wei Wang
2011-12-14 15:29 ` [PATCH 11 of 16] amd iommu: Add a new flag to indication iommuv2 feature enabled or not Wei Wang
2011-12-15 13:39 ` Tim Deegan
2011-12-15 14:05 ` Wei Wang2
2011-12-14 15:29 ` [PATCH 12 of 16] hvmloader: Build IVRS table Wei Wang
2011-12-15 12:29 ` Ian Campbell
2011-12-14 15:29 ` [PATCH 13 of 16] libxc: add wrappers for new hypercalls Wei Wang
2011-12-14 15:29 ` [PATCH 14 of 16] libxl: bind virtual bdf to physical bdf after device assignment Wei Wang
2011-12-15 14:26 ` Ian Campbell
2011-12-14 15:29 ` [PATCH 15 of 16] libxl: Introduce a new guest config file parameter Wei Wang
2011-12-15 16:27 ` Ian Jackson
2011-12-14 15:29 ` [PATCH 16 of 16] libxl: add iommu parameter to qemu-dm Wei Wang
2011-12-15 14:30 ` Ian Campbell
2011-12-15 14:52 ` Wei Wang2
2011-12-15 16:59 ` Ian Campbell
2011-12-15 17:10 ` Wei Wang2
2011-12-16 11:44 ` Ian Campbell
2011-12-15 10:23 ` [PATCH 00 of 16] [RFC] amd iommu: support ATS device passthru on IOMMUv2 systems Jan Beulich
2011-12-15 11:18 ` Wei Wang2
-- strict thread matches above, loose matches on Subject: below --
2011-12-23 11:29 [PATCH 00 of 16] [V2] " Wei Wang
2011-12-23 11:29 ` [PATCH 04 of 16] amd iommu: Enable ppr log Wei Wang
2012-01-02 13:10 ` Jan Beulich
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=d3aa7f936872abacb7e0.1323876565@gran.amd.com \
--to=wei.wang2@amd.com \
--cc=JBeulich@suse.com \
--cc=keir@xen.org \
--cc=xen-devel@lists.xensource.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).