Skip to content

Commit a7e7984

Browse files
Richard Kuotorvalds
authored andcommitted
Hexagon: Add page table header files & etc.
Signed-off-by: Richard Kuo <rkuo@codeaurora.org> Signed-off-by: Linas Vepstas <linas@codeaurora.org> Acked-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent b7f3785 commit a7e7984

7 files changed

Lines changed: 1054 additions & 0 deletions

File tree

‎arch/hexagon/include/asm/fixmap.h‎

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Fixmap support for Hexagon - enough to support highmem features
3+
*
4+
* Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
5+
*
6+
* This program is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License version 2 and
8+
* only version 2 as published by the Free Software Foundation.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program; if not, write to the Free Software
17+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18+
* 02110-1301, USA.
19+
*/
20+
21+
#ifndef _ASM_FIXMAP_H
22+
#define _ASM_FIXMAP_H
23+
24+
/*
25+
* A lot of the fixmap info is already in mem-layout.h
26+
*/
27+
#include <asm/mem-layout.h>
28+
29+
/*
30+
* Full fixmap support involves set_fixmap() functions, but
31+
* these may not be needed if all we're after is an area for
32+
* highmem kernel mappings.
33+
*/
34+
#define __fix_to_virt(x) (FIXADDR_TOP - ((x) << PAGE_SHIFT))
35+
#define __virt_to_fix(x) ((FIXADDR_TOP - ((x)&PAGE_MASK)) >> PAGE_SHIFT)
36+
37+
extern void __this_fixmap_does_not_exist(void);
38+
39+
/**
40+
* fix_to_virt -- "index to address" translation.
41+
*
42+
* If anyone tries to use the idx directly without translation,
43+
* we catch the bug with a NULL-deference kernel oops. Illegal
44+
* ranges of incoming indices are caught too.
45+
*/
46+
static inline unsigned long fix_to_virt(const unsigned int idx)
47+
{
48+
/*
49+
* This branch gets completely eliminated after inlining,
50+
* except when someone tries to use fixaddr indices in an
51+
* illegal way. (such as mixing up address types or using
52+
* out-of-range indices).
53+
*
54+
* If it doesn't get removed, the linker will complain
55+
* loudly with a reasonably clear error message..
56+
*/
57+
if (idx >= __end_of_fixed_addresses)
58+
__this_fixmap_does_not_exist();
59+
60+
return __fix_to_virt(idx);
61+
}
62+
63+
static inline unsigned long virt_to_fix(const unsigned long vaddr)
64+
{
65+
BUG_ON(vaddr >= FIXADDR_TOP || vaddr < FIXADDR_START);
66+
return __virt_to_fix(vaddr);
67+
}
68+
69+
#define kmap_get_fixmap_pte(vaddr) \
70+
pte_offset_kernel(pmd_offset(pud_offset(pgd_offset_k(vaddr), \
71+
(vaddr)), (vaddr)), (vaddr))
72+
73+
#endif

‎arch/hexagon/include/asm/mmu.h‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License version 2 and
6+
* only version 2 as published by the Free Software Foundation.
7+
*
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* GNU General Public License for more details.
12+
*
13+
* You should have received a copy of the GNU General Public License
14+
* along with this program; if not, write to the Free Software
15+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16+
* 02110-1301, USA.
17+
*/
18+
19+
#ifndef _ASM_MMU_H
20+
#define _ASM_MMU_H
21+
22+
#include <asm/vdso.h>
23+
24+
/*
25+
* Architecture-specific state for a mm_struct.
26+
* For the Hexagon Virtual Machine, it can be a copy
27+
* of the pointer to the page table base.
28+
*/
29+
struct mm_context {
30+
unsigned long long generation;
31+
unsigned long ptbase;
32+
struct hexagon_vdso *vdso;
33+
};
34+
35+
typedef struct mm_context mm_context_t;
36+
37+
#endif
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
* MM context support for the Hexagon architecture
3+
*
4+
* Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
5+
*
6+
* This program is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License version 2 and
8+
* only version 2 as published by the Free Software Foundation.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program; if not, write to the Free Software
17+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18+
* 02110-1301, USA.
19+
*/
20+
21+
#ifndef _ASM_MMU_CONTEXT_H
22+
#define _ASM_MMU_CONTEXT_H
23+
24+
#include <asm/setup.h>
25+
#include <asm/page.h>
26+
#include <asm/pgalloc.h>
27+
#include <asm/mem-layout.h>
28+
29+
static inline void destroy_context(struct mm_struct *mm)
30+
{
31+
}
32+
33+
/*
34+
* VM port hides all TLB management, so "lazy TLB" isn't very
35+
* meaningful. Even for ports to architectures with visble TLBs,
36+
* this is almost invariably a null function.
37+
*/
38+
static inline void enter_lazy_tlb(struct mm_struct *mm,
39+
struct task_struct *tsk)
40+
{
41+
}
42+
43+
/*
44+
* Architecture-specific actions, if any, for memory map deactivation.
45+
*/
46+
static inline void deactivate_mm(struct task_struct *tsk,
47+
struct mm_struct *mm)
48+
{
49+
}
50+
51+
/**
52+
* init_new_context - initialize context related info for new mm_struct instance
53+
* @tsk: pointer to a task struct
54+
* @mm: pointer to a new mm struct
55+
*/
56+
static inline int init_new_context(struct task_struct *tsk,
57+
struct mm_struct *mm)
58+
{
59+
/* mm->context is set up by pgd_alloc */
60+
return 0;
61+
}
62+
63+
/*
64+
* Switch active mm context
65+
*/
66+
static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
67+
struct task_struct *tsk)
68+
{
69+
int l1;
70+
71+
/*
72+
* For virtual machine, we have to update system map if it's been
73+
* touched.
74+
*/
75+
if (next->context.generation < prev->context.generation) {
76+
for (l1 = MIN_KERNEL_SEG; l1 <= max_kernel_seg; l1++)
77+
next->pgd[l1] = init_mm.pgd[l1];
78+
79+
next->context.generation = prev->context.generation;
80+
}
81+
82+
__vmnewmap((void *)next->context.ptbase);
83+
}
84+
85+
/*
86+
* Activate new memory map for task
87+
*/
88+
static inline void activate_mm(struct mm_struct *prev, struct mm_struct *next)
89+
{
90+
unsigned long flags;
91+
92+
local_irq_save(flags);
93+
switch_mm(prev, next, current_thread_info()->task);
94+
local_irq_restore(flags);
95+
}
96+
97+
/* Generic hooks for arch_dup_mmap and arch_exit_mmap */
98+
#include <asm-generic/mm_hooks.h>
99+
100+
#endif

‎arch/hexagon/include/asm/page.h‎

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
/*
2+
* Page management definitions for the Hexagon architecture
3+
*
4+
* Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
5+
*
6+
* This program is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License version 2 and
8+
* only version 2 as published by the Free Software Foundation.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program; if not, write to the Free Software
17+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18+
* 02110-1301, USA.
19+
*/
20+
21+
#ifndef _ASM_PAGE_H
22+
#define _ASM_PAGE_H
23+
24+
#include <linux/const.h>
25+
26+
/* This is probably not the most graceful way to handle this. */
27+
28+
#ifdef CONFIG_PAGE_SIZE_4KB
29+
#define PAGE_SHIFT 12
30+
#define HEXAGON_L1_PTE_SIZE __HVM_PDE_S_4KB
31+
#endif
32+
33+
#ifdef CONFIG_PAGE_SIZE_16KB
34+
#define PAGE_SHIFT 14
35+
#define HEXAGON_L1_PTE_SIZE __HVM_PDE_S_16KB
36+
#endif
37+
38+
#ifdef CONFIG_PAGE_SIZE_64KB
39+
#define PAGE_SHIFT 16
40+
#define HEXAGON_L1_PTE_SIZE __HVM_PDE_S_64KB
41+
#endif
42+
43+
#ifdef CONFIG_PAGE_SIZE_256KB
44+
#define PAGE_SHIFT 18
45+
#define HEXAGON_L1_PTE_SIZE __HVM_PDE_S_256KB
46+
#endif
47+
48+
#ifdef CONFIG_PAGE_SIZE_1MB
49+
#define PAGE_SHIFT 20
50+
#define HEXAGON_L1_PTE_SIZE __HVM_PDE_S_1MB
51+
#endif
52+
53+
/*
54+
* These should be defined in hugetlb.h, but apparently not.
55+
* "Huge" for us should be 4MB or 16MB, which are both represented
56+
* in L1 PTE's. Right now, it's set up for 4MB.
57+
*/
58+
#ifdef CONFIG_HUGETLB_PAGE
59+
#define HPAGE_SHIFT 22
60+
#define HPAGE_SIZE (1UL << HPAGE_SHIFT)
61+
#define HPAGE_MASK (~(HPAGE_SIZE-1))
62+
#define HUGETLB_PAGE_ORDER (HPAGE_SHIFT-PAGE_SHIFT)
63+
#define HVM_HUGEPAGE_SIZE 0x5
64+
#endif
65+
66+
#define PAGE_SIZE (1UL << PAGE_SHIFT)
67+
#define PAGE_MASK (~((1 << PAGE_SHIFT) - 1))
68+
69+
#ifdef __KERNEL__
70+
#ifndef __ASSEMBLY__
71+
72+
/*
73+
* This is for PFN_DOWN, which mm.h needs. Seems the right place to pull it in.
74+
*/
75+
#include <linux/pfn.h>
76+
77+
/*
78+
* We implement a two-level architecture-specific page table structure.
79+
* Null intermediate page table level (pmd, pud) definitions will come from
80+
* asm-generic/pagetable-nopmd.h and asm-generic/pagetable-nopud.h
81+
*/
82+
typedef struct { unsigned long pte; } pte_t;
83+
typedef struct { unsigned long pgd; } pgd_t;
84+
typedef struct { unsigned long pgprot; } pgprot_t;
85+
typedef struct page *pgtable_t;
86+
87+
#define pte_val(x) ((x).pte)
88+
#define pgd_val(x) ((x).pgd)
89+
#define pgprot_val(x) ((x).pgprot)
90+
#define __pte(x) ((pte_t) { (x) })
91+
#define __pgd(x) ((pgd_t) { (x) })
92+
#define __pgprot(x) ((pgprot_t) { (x) })
93+
94+
/*
95+
* We need a __pa and a __va routine for kernel space.
96+
* MIPS says they're only used during mem_init.
97+
* also, check if we need a PHYS_OFFSET.
98+
*/
99+
#define __pa(x) ((unsigned long)(x) - PAGE_OFFSET)
100+
#define __va(x) ((void *)((unsigned long)(x) + PAGE_OFFSET))
101+
102+
/* The "page frame" descriptor is defined in linux/mm.h */
103+
struct page;
104+
105+
/* Returns page frame descriptor for virtual address. */
106+
#define virt_to_page(kaddr) pfn_to_page(PFN_DOWN(__pa(kaddr)))
107+
108+
/* Default vm area behavior is non-executable. */
109+
#define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | \
110+
VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
111+
112+
#define pfn_valid(pfn) ((pfn) < max_mapnr)
113+
#define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
114+
115+
/* Need to not use a define for linesize; may move this to another file. */
116+
static inline void clear_page(void *page)
117+
{
118+
/* This can only be done on pages with L1 WB cache */
119+
asm volatile(
120+
" loop0(1f,%1);\n"
121+
"1: { dczeroa(%0);\n"
122+
" %0 = add(%0,#32); }:endloop0\n"
123+
: "+r" (page)
124+
: "r" (PAGE_SIZE/32)
125+
: "lc0", "sa0", "memory"
126+
);
127+
}
128+
129+
#define copy_page(to, from) memcpy((to), (from), PAGE_SIZE)
130+
131+
/*
132+
* Under assumption that kernel always "sees" user map...
133+
*/
134+
#define clear_user_page(page, vaddr, pg) clear_page(page)
135+
#define copy_user_page(to, from, vaddr, pg) copy_page(to, from)
136+
137+
/*
138+
* page_to_phys - convert page to physical address
139+
* @page - pointer to page entry in mem_map
140+
*/
141+
#define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT)
142+
143+
/*
144+
* For port to Hexagon Virtual Machine, MAYBE we check for attempts
145+
* to reference reserved HVM space, but in any case, the VM will be
146+
* protected.
147+
*/
148+
#define kern_addr_valid(addr) (1)
149+
150+
#include <asm-generic/memory_model.h>
151+
/* XXX Todo: implement assembly-optimized version of getorder. */
152+
#include <asm-generic/getorder.h>
153+
154+
#endif /* ifdef __ASSEMBLY__ */
155+
#endif /* ifdef __KERNEL__ */
156+
157+
#endif

0 commit comments

Comments
 (0)