From mboxrd@z Thu Jan 1 00:00:00 1970 From: Wei Wang2 Subject: [PATCH 3/3] AMD IOMMU: add s3 suspend & resume support Date: Fri, 3 Jul 2009 17:24:44 +0200 Message-ID: <200907031724.44255.wei.wang2@amd.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="Boundary-00=_8KiTKwNfKRT4kkf" Return-path: Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org --Boundary-00=_8KiTKwNfKRT4kkf Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Add suspend and resume support for amd iommu. Signed-off-by: Wei Wang =2D- AMD GmbH, Germany Operating System Research Center =20 Legal Information: Advanced Micro Devices GmbH Karl-Hammerschmidt-Str. 34 85609 Dornach b. M=FCnchen =20 Gesch=E4ftsf=FChrer: Jochen Polster, Thomas M. McCoy, Giuliano Meroni Sitz: Dornach, Gemeinde Aschheim, Landkreis M=FCnchen Registergericht M=FCnchen, HRB Nr. 43632 --Boundary-00=_8KiTKwNfKRT4kkf Content-Type: text/x-diff; charset="iso-8859-1"; name="iommu_s3.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="iommu_s3.patch" diff -r 785dfbf2c01f xen/drivers/passthrough/amd/iommu_init.c --- a/xen/drivers/passthrough/amd/iommu_init.c Fri Jul 03 14:14:31 2009 +0200 +++ b/xen/drivers/passthrough/amd/iommu_init.c Fri Jul 03 14:18:57 2009 +0200 @@ -716,3 +716,83 @@ error_out: } return -ENOMEM; } + +static void disable_iommu(struct amd_iommu *iommu) +{ + unsigned long flags; + + spin_lock_irqsave(&iommu->lock, flags); + + if ( !iommu->enabled ) + { + spin_unlock_irqrestore(&iommu->lock, flags); + return; + } + + 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); + set_iommu_translation_control(iommu, IOMMU_CONTROL_DISABLED); + + iommu->enabled = 0; + + spin_unlock_irqrestore(&iommu->lock, flags); + +} + +static void invalidate_all_domain_pages(void) +{ + struct domain *d; + for_each_domain( d ) + invalidate_all_iommu_pages(d); +} + +static void invalidate_all_devices(void) +{ + u16 bus, devfn, bdf, req_id; + unsigned long flags; + struct amd_iommu *iommu; + + for ( bdf = 0; bdf < ivrs_bdf_entries; bdf++ ) + { + bus = bdf >> 8; + devfn = bdf & 0xFF; + iommu = find_iommu_for_device(bus, devfn); + req_id = ivrs_mappings[bdf].dte_requestor_id; + if ( iommu ) + { + spin_lock_irqsave(&iommu->lock, flags); + invalidate_dev_table_entry(iommu, req_id); + invalidate_interrupt_table(iommu, req_id); + flush_command_buffer(iommu); + spin_unlock_irqrestore(&iommu->lock, flags); + } + } +} + +void amd_iommu_suspend(void) +{ + struct amd_iommu *iommu; + + for_each_amd_iommu ( iommu ) + disable_iommu(iommu); +} + +void amd_iommu_resume(void) +{ + struct amd_iommu *iommu; + + for_each_amd_iommu ( iommu ) + { + /* + * To make sure that iommus have not been touched + * before re-enablement + */ + disable_iommu(iommu); + enable_iommu(iommu); + } + + /* flush all cache entries after iommu re-enabled */ + invalidate_all_devices(); + invalidate_all_domain_pages(); +} --Boundary-00=_8KiTKwNfKRT4kkf Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --Boundary-00=_8KiTKwNfKRT4kkf--