GNU Linux-libre 4.14.303-gnu1
[releases.git] / drivers / staging / media / atomisp / pci / atomisp2 / mmu / sh_mmu_mrfld.c
1 /*
2  * Support for Merrifield PNW Camera Imaging ISP subsystem.
3  *
4  * Copyright (c) 2012 Intel Corporation. All Rights Reserved.
5  *
6  * Copyright (c) 2012 Silicon Hive www.siliconhive.com.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License version
10  * 2 as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20  * 02110-1301, USA.
21  *
22  */
23 #include "type_support.h"
24 #include "mmu/isp_mmu.h"
25 #include "memory_access/memory_access.h"
26 #include "atomisp_compat.h"
27
28 #define MERR_VALID_PTE_MASK     0x80000000
29
30 /*
31  * include SH header file here
32  */
33
34 static unsigned int sh_phys_to_pte(struct isp_mmu *mmu,
35                                    phys_addr_t phys)
36 {
37         return phys >> ISP_PAGE_OFFSET;
38 }
39
40 static phys_addr_t sh_pte_to_phys(struct isp_mmu *mmu,
41                                   unsigned int pte)
42 {
43         unsigned int mask = mmu->driver->pte_valid_mask;
44         return (phys_addr_t)((pte & ~mask) << ISP_PAGE_OFFSET);
45 }
46
47 /*
48  * set page directory base address (physical address).
49  *
50  * must be provided.
51  */
52 static int sh_set_pd_base(struct isp_mmu *mmu,
53                           phys_addr_t phys)
54 {
55         unsigned int pte = sh_phys_to_pte(mmu, phys);
56         /*mmgr_set_base_address(HOST_ADDRESS(pte));*/
57         atomisp_css_mmu_set_page_table_base_index(HOST_ADDRESS(pte));
58         return 0;
59 }
60
61 static unsigned int sh_get_pd_base(struct isp_mmu *mmu,
62                                    phys_addr_t phys)
63 {
64         unsigned int pte = sh_phys_to_pte(mmu, phys);
65         return HOST_ADDRESS(pte);
66 }
67
68 /*
69  * callback to flush tlb.
70  *
71  * tlb_flush_range will at least flush TLBs containing
72  * address mapping from addr to addr + size.
73  *
74  * tlb_flush_all will flush all TLBs.
75  *
76  * tlb_flush_all is must be provided. if tlb_flush_range is
77  * not valid, it will set to tlb_flush_all by default.
78  */
79 static void sh_tlb_flush(struct isp_mmu *mmu)
80 {
81         atomisp_css_mmu_invalidate_cache();
82 }
83
84 struct isp_mmu_client sh_mmu_mrfld = {
85         .name = "Silicon Hive ISP3000 MMU",
86         .pte_valid_mask = MERR_VALID_PTE_MASK,
87         .null_pte = ~MERR_VALID_PTE_MASK,
88         .set_pd_base = sh_set_pd_base,
89         .get_pd_base = sh_get_pd_base,
90         .tlb_flush_all = sh_tlb_flush,
91         .phys_to_pte = sh_phys_to_pte,
92         .pte_to_phys = sh_pte_to_phys,
93 };