All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrii Tseglytskyi <andrii.tseglytskyi@globallogic.com>
To: xen-devel@lists.xen.org
Subject: [PATCH v02 3/7] arm: omap: introduce iommu translation for GPU remoteproc
Date: Thu, 26 Jun 2014 14:07:02 +0300	[thread overview]
Message-ID: <1403780826-22123-4-git-send-email-andrii.tseglytskyi@globallogic.com> (raw)
In-Reply-To: <1403780826-22123-1-git-send-email-andrii.tseglytskyi@globallogic.com>

The following patch introduced platform specific MMU data
definitions and pagetable translation function for OMAP5 GPU
remoteproc. Typically GPU MMU performs uses two level address
translation, so algorithm is quite straightforward here -
pagetables are enumerated and all pfns are updated with
corresponding mfns.

Current patch adds functionality, needed for proper handling of
GPU MMU, which is very similar to existing IPU/DSP MMUs.

Change-Id: I129da9485c61cc94801c6b243498e31db33f5d30
Signed-off-by: Andrii Tseglytskyi <andrii.tseglytskyi@globallogic.com>
---
 xen/arch/arm/platforms/omap_iommu.c |   86 +++++++++++++++++++++++++++++++++++
 xen/arch/arm/remoteproc_iommu.c     |    1 +
 xen/include/xen/remoteproc_iommu.h  |    1 +
 3 files changed, 88 insertions(+)

diff --git a/xen/arch/arm/platforms/omap_iommu.c b/xen/arch/arm/platforms/omap_iommu.c
index e0c4633..bbaa7bc 100644
--- a/xen/arch/arm/platforms/omap_iommu.c
+++ b/xen/arch/arm/platforms/omap_iommu.c
@@ -32,12 +32,23 @@
 /* register where address of pagetable is stored */
 #define MMU_IPU_TTB_OFFSET          0x4c
 
+#define MMU_SGX_TTB_OFFSET_00		0xc84
+#define MMU_SGX_TTB_OFFSET_01		0xc38
+#define MMU_SGX_TTB_OFFSET_02		0xc3c
+#define MMU_SGX_TTB_OFFSET_03		0xc40
+#define MMU_SGX_TTB_OFFSET_04		0xc44
+#define MMU_SGX_TTB_OFFSET_05		0xc48
+#define MMU_SGX_TTB_OFFSET_06		0xc4c
+#define MMU_SGX_TTB_OFFSET_07		0xc50
+
 /* 1st level translation */
 #define MMU_OMAP_PGD_SHIFT          20
 #define MMU_OMAP_SUPER_SHIFT        24	/* "supersection" - 16 Mb */
 #define MMU_OMAP_SECTION_SHIFT      20	/* "section"  - 1 Mb */
 #define MMU_OMAP_SECOND_LEVEL_SHIFT 10
 
+#define MMU_SGX_PGD_SHIFT			22	/* SGX section */
+
 /* 2nd level translation */
 #define MMU_OMAP_PTE_SMALL_SHIFT    12	/* "small page" - 4Kb */
 #define MMU_OMAP_PTE_LARGE_SHIFT    16	/* "large page" - 64 Kb */
@@ -57,13 +68,26 @@
 #define PTE_LARGE       (1 << 0)
 
 #define	OMAP_IPU_MMU_MEM_BASE   0x55082000
+#define	OMAP_SGX_MMU_MEM_BASE	0x56000000
 
 static u32 mmu_ipu_translate_pagetable(struct mmu_info *mmu, struct mmu_pagetable *pgt);
+static u32 mmu_sgx_translate_pagetable(struct mmu_info *mmu, struct mmu_pagetable *pgt);
 
 static u32 ipu_trap_offsets[] = {
     MMU_IPU_TTB_OFFSET,
 };
 
+static u32 sgx_trap_offsets[] = {
+    MMU_SGX_TTB_OFFSET_00,
+    MMU_SGX_TTB_OFFSET_01,
+    MMU_SGX_TTB_OFFSET_02,
+    MMU_SGX_TTB_OFFSET_03,
+    MMU_SGX_TTB_OFFSET_04,
+    MMU_SGX_TTB_OFFSET_05,
+    MMU_SGX_TTB_OFFSET_06,
+    MMU_SGX_TTB_OFFSET_07,
+};
+
 static const struct pagetable_data pagetable_ipu_data = {
     .pgd_shift          = MMU_OMAP_PGD_SHIFT,
     .super_shift        = MMU_OMAP_SUPER_SHIFT,
@@ -82,6 +106,23 @@ struct mmu_info omap_ipu_mmu = {
     .translate_pfunc	= mmu_ipu_translate_pagetable,
 };
 
+static const struct pagetable_data pagetable_sgx_data = {
+    .pgd_shift      = MMU_SGX_PGD_SHIFT,
+    .super_shift    = MMU_SGX_PGD_SHIFT,
+    .section_shift  = MMU_SGX_PGD_SHIFT,
+    .pte_shift      = MMU_OMAP_PTE_SMALL_SHIFT,	/* the same as IPU */
+};
+
+struct mmu_info omap_sgx_mmu = {
+    .name           = "SGX_L2_MMU",
+    .pg_data        = &pagetable_sgx_data,
+    .trap_offsets   = sgx_trap_offsets,
+    .mem_start      = OMAP_SGX_MMU_MEM_BASE,
+    .mem_size       = 0x1000,
+    .num_traps      = ARRAY_SIZE(sgx_trap_offsets),
+    .translate_pfunc    = mmu_sgx_translate_pagetable,
+};
+
 static bool translate_supersections_to_pages = true;
 static bool translate_sections_to_pages = true;
 
@@ -237,6 +278,51 @@ static u32 mmu_ipu_translate_pagetable(struct mmu_info *mmu, struct mmu_pagetabl
     return __pa(hyp_pgt);
 }
 
+static u32 mmu_sgx_translate_pagetable(struct mmu_info *mmu, struct mmu_pagetable *pgt)
+{
+    u32 *kern_pgt, *hyp_pgt;
+    u32 i;
+
+    ASSERT(mmu);
+    ASSERT(pgt);
+
+    kern_pgt = pgt->kern_pagetable;
+    hyp_pgt = pgt->hyp_pagetable;
+    pgt->page_counter = 0;
+
+    /* 1-st level translation */
+    for ( i = 0; i < MMU_PTRS_PER_PGD(mmu); i++ )
+    {
+        paddr_t pd_maddr, pd_paddr, pd_flags;
+        u32 pgd, pd_mask = MMU_SECTION_MASK(mmu->pg_data->pte_shift);
+
+        pgd = kern_pgt[i];
+        if ( !pgd )
+        {
+            /* handle the case when second level translation table
+             * was removed from kernel */
+            if ( unlikely(hyp_pgt[i]) )
+            {
+                xfree(__va(hyp_pgt[i] & pd_mask));
+                hyp_pgt[i] = 0;
+            }
+            continue;
+        }
+
+        pd_paddr = pgd & pd_mask;
+        pd_flags = pgd & ~pd_mask;
+        pd_maddr = p2m_lookup(current->domain, pd_paddr, NULL);
+        ASSERT(pd_maddr != INVALID_PADDR);
+
+        /* 2-nd level translation */
+        hyp_pgt[i] = mmu_translate_second_level(mmu, pgt, pd_maddr, hyp_pgt[i]);
+        hyp_pgt[i] |= pd_flags;
+    }
+
+    clean_and_invalidate_xen_dcache_va_range(hyp_pgt, MMU_PGD_TABLE_SIZE(mmu));
+    return __pa(hyp_pgt);
+}
+
 /*
  * Local variables:
  * mode: C
diff --git a/xen/arch/arm/remoteproc_iommu.c b/xen/arch/arm/remoteproc_iommu.c
index 8291f3f..3b3da3b 100644
--- a/xen/arch/arm/remoteproc_iommu.c
+++ b/xen/arch/arm/remoteproc_iommu.c
@@ -34,6 +34,7 @@
 
 static struct mmu_info *mmu_list[] = {
     &omap_ipu_mmu,
+    &omap_sgx_mmu,
 };
 
 #define mmu_for_each(pfunc, data)                       \
diff --git a/xen/include/xen/remoteproc_iommu.h b/xen/include/xen/remoteproc_iommu.h
index ff1c439..d69c85e 100644
--- a/xen/include/xen/remoteproc_iommu.h
+++ b/xen/include/xen/remoteproc_iommu.h
@@ -77,5 +77,6 @@ u32 mmu_translate_second_level(struct mmu_info *mmu, struct mmu_pagetable *pgt,
                                u32 maddr, u32 hyp_addr);
 
 extern struct mmu_info omap_ipu_mmu;
+extern struct mmu_info omap_sgx_mmu;
 
 #endif /* _REMOTEPROC_IOMMU_H_ */
-- 
1.7.9.5

  parent reply	other threads:[~2014-06-26 11:07 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-26 11:06 [PATCH v02 0/7] arm: introduce remoteprocessor iommu module Andrii Tseglytskyi
2014-06-26 11:07 ` [PATCH v02 1/7] " Andrii Tseglytskyi
2014-06-29 18:00   ` Julien Grall
2014-07-22 15:20     ` Andrii Tseglytskyi
2014-07-22 16:29       ` Julien Grall
2014-07-31 11:59       ` Andrii Tseglytskyi
2014-07-31 12:11         ` Julien Grall
2014-07-31 12:49           ` Andrii Tseglytskyi
2014-07-04 13:59   ` Stefano Stabellini
2014-07-16 15:19     ` Ian Campbell
2014-07-22 12:42       ` Stefano Stabellini
2014-07-22 13:29         ` Julien Grall
2014-07-22 16:31           ` Andrii Tseglytskyi
2014-07-22 17:22         ` Andrii Tseglytskyi
2014-07-23 10:32           ` Stefano Stabellini
2014-07-23 10:54             ` Andrii Tseglytskyi
2014-07-22 15:40       ` Andrii Tseglytskyi
2014-07-22 15:32     ` Andrii Tseglytskyi
2014-08-01 10:06       ` Andrii Tseglytskyi
2014-08-01 10:32         ` Julien Grall
2014-08-01 10:34           ` Andrii Tseglytskyi
2014-08-01 10:37             ` Julien Grall
2014-08-01 10:43               ` Andrii Tseglytskyi
2014-08-20 19:40     ` Andrii Tseglytskyi
2014-08-21 15:30       ` Andrii Tseglytskyi
2014-08-21 23:41         ` Stefano Stabellini
2014-08-21 23:43       ` Stefano Stabellini
2014-07-16 15:29   ` Ian Campbell
2014-07-16 15:34     ` Ian Campbell
2014-07-22 16:24       ` Andrii Tseglytskyi
2014-07-22 16:14     ` Andrii Tseglytskyi
2014-06-26 11:07 ` [PATCH v02 2/7] arm: omap: introduce iommu translation for IPU remoteproc Andrii Tseglytskyi
2014-07-04 14:01   ` Stefano Stabellini
2014-07-22 16:56     ` Andrii Tseglytskyi
2014-07-04 14:30   ` Julien Grall
2014-07-22 16:58     ` Andrii Tseglytskyi
2014-07-16 15:36   ` Ian Campbell
2014-07-22 17:16     ` Andrii Tseglytskyi
2014-06-26 11:07 ` Andrii Tseglytskyi [this message]
2014-06-26 11:07 ` [PATCH v02 4/7] arm: omap: introduce print pagetable function " Andrii Tseglytskyi
2014-07-16 15:38   ` Ian Campbell
2014-07-22 16:55     ` Andrii Tseglytskyi
2014-06-26 11:07 ` [PATCH v02 5/7] arm: omap: introduce print pagetable function for GPU remoteproc Andrii Tseglytskyi
2014-06-26 11:07 ` [PATCH v02 6/7] arm: introduce do_translate_pagetable hypercall Andrii Tseglytskyi
2014-07-04 14:05   ` Stefano Stabellini
2014-07-16 15:42     ` Ian Campbell
2014-07-22 16:47       ` Andrii Tseglytskyi
2014-07-22 16:37     ` Andrii Tseglytskyi
2014-07-04 14:35   ` Julien Grall
2014-07-16 15:43     ` Ian Campbell
2014-07-22 16:50       ` Andrii Tseglytskyi
2014-07-22 16:39     ` Andrii Tseglytskyi
2014-07-22 16:44       ` Julien Grall
2014-07-22 16:48         ` Andrii Tseglytskyi
2014-06-26 11:07 ` [PATCH v02 7/7] arm: add trap for remoteproc mmio accesses Andrii Tseglytskyi
2014-06-26 16:52   ` Julien Grall
2014-06-27  8:36     ` Andrii Tseglytskyi

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=1403780826-22123-4-git-send-email-andrii.tseglytskyi@globallogic.com \
    --to=andrii.tseglytskyi@globallogic.com \
    --cc=xen-devel@lists.xen.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.