From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51852) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aagLy-0001Qk-1S for qemu-devel@nongnu.org; Tue, 01 Mar 2016 04:12:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aagLt-0007ZM-Hr for qemu-devel@nongnu.org; Tue, 01 Mar 2016 04:12:25 -0500 Received: from e23smtp03.au.ibm.com ([202.81.31.145]:59609) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aagLq-0007XP-Mp for qemu-devel@nongnu.org; Tue, 01 Mar 2016 04:12:21 -0500 Received: from localhost by e23smtp03.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 1 Mar 2016 19:12:16 +1000 From: Alexey Kardashevskiy Date: Tue, 1 Mar 2016 20:10:33 +1100 Message-Id: <1456823441-46757-9-git-send-email-aik@ozlabs.ru> In-Reply-To: <1456823441-46757-1-git-send-email-aik@ozlabs.ru> References: <1456823441-46757-1-git-send-email-aik@ozlabs.ru> Subject: [Qemu-devel] [PATCH qemu v13 08/16] memory: Add reporting of supported page sizes List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Alexey Kardashevskiy , Alex Williamson , qemu-ppc@nongnu.org Every IOMMU has some granularity which MemoryRegionIOMMUOps::translate uses when translating, however this information is not available outside the translate context for various checks. This adds a get_page_sizes callback to MemoryRegionIOMMUOps and a wrapper for it so IOMMU users (such as VFIO) can know the actual page size(s) used by an IOMMU. The qemu_real_host_page_mask is used as fallback. Signed-off-by: Alexey Kardashevskiy --- Changes: v4: * s/1<owner, tcet, attached); } +static uint64_t spapr_tce_get_page_sizes(MemoryRegion *iommu) +{ + sPAPRTCETable *tcet = container_of(iommu, sPAPRTCETable, iommu); + + return 1ULL << tcet->page_shift; +} + static int spapr_tce_table_post_load(void *opaque, int version_id) { sPAPRTCETable *tcet = SPAPR_TCE_TABLE(opaque); @@ -175,6 +182,7 @@ static const VMStateDescription vmstate_spapr_tce_table = { static MemoryRegionIOMMUOps spapr_iommu_ops = { .translate = spapr_tce_translate_iommu, .vfio_notify = spapr_tce_vfio_notify, + .get_page_sizes = spapr_tce_get_page_sizes, }; static int spapr_tce_table_realize(DeviceState *dev) diff --git a/include/exec/memory.h b/include/exec/memory.h index 9f82629..c34e67c 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -152,6 +152,8 @@ struct MemoryRegionIOMMUOps { IOMMUTLBEntry (*translate)(MemoryRegion *iommu, hwaddr addr, bool is_write); /* Called when VFIO starts/stops using this */ int (*vfio_notify)(MemoryRegion *iommu, bool attached); + /* Returns supported page sizes */ + uint64_t (*get_page_sizes)(MemoryRegion *iommu); }; typedef struct CoalescedMemoryRange CoalescedMemoryRange; @@ -576,6 +578,15 @@ static inline bool memory_region_is_iommu(MemoryRegion *mr) /** + * memory_region_iommu_get_page_sizes: get supported page sizes in an iommu + * + * Returns %bitmap of supported page sizes for an iommu. + * + * @mr: the memory region being queried + */ +uint64_t memory_region_iommu_get_page_sizes(MemoryRegion *mr); + +/** * memory_region_notify_iommu: notify a change in an IOMMU translation entry. * * @mr: the memory region that was changed diff --git a/memory.c b/memory.c index 0dd9695..5d8453d 100644 --- a/memory.c +++ b/memory.c @@ -1462,6 +1462,15 @@ void memory_region_notify_iommu(MemoryRegion *mr, notifier_list_notify(&mr->iommu_notify, &entry); } +uint64_t memory_region_iommu_get_page_sizes(MemoryRegion *mr) +{ + assert(memory_region_is_iommu(mr)); + if (mr->iommu_ops && mr->iommu_ops->get_page_sizes) { + return mr->iommu_ops->get_page_sizes(mr); + } + return qemu_real_host_page_size; +} + void memory_region_set_log(MemoryRegion *mr, bool log, unsigned client) { uint8_t mask = 1 << client; -- 2.5.0.rc3