Skip to content

Commit 8f5a0b9

Browse files
author
Richard Kuo
committed
Hexagon: add support for ARCH_PFN_OFFSET
Add support for loading the kernel at a physical offset. The offset should still be 4M aligned. Signed-off-by: Richard Kuo <rkuo@codeaurora.org>
1 parent e0025a7 commit 8f5a0b9

8 files changed

Lines changed: 91 additions & 55 deletions

File tree

‎arch/hexagon/Kconfig‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ config HEXAGON
3333
Qualcomm Hexagon is a processor architecture designed for high
3434
performance and low power across a wide variety of applications.
3535

36+
3637
config HEXAGON_ARCH_V1
3738
bool
3839

@@ -45,6 +46,11 @@ config HEXAGON_ARCH_V3
4546
config HEXAGON_ARCH_V4
4647
bool
4748

49+
config HEXAGON_PHYS_OFFSET
50+
def_bool y
51+
---help---
52+
Platforms that don't load the kernel at zero set this.
53+
4854
config FRAME_POINTER
4955
def_bool y
5056

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

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,26 @@
3131
* for tracing/debugging.
3232
*/
3333

34-
/*
35-
* Lets make this stuff visible only if configured,
36-
* so we can unconditionally include the file.
37-
*/
34+
#define HVM_TRAP1_VMVERSION 0
35+
#define HVM_TRAP1_VMRTE 1
36+
#define HVM_TRAP1_VMSETVEC 2
37+
#define HVM_TRAP1_VMSETIE 3
38+
#define HVM_TRAP1_VMGETIE 4
39+
#define HVM_TRAP1_VMINTOP 5
40+
#define HVM_TRAP1_VMCLRMAP 10
41+
#define HVM_TRAP1_VMNEWMAP 11
42+
#define HVM_TRAP1_FORMERLY_VMWIRE 12
43+
#define HVM_TRAP1_VMCACHE 13
44+
#define HVM_TRAP1_VMGETTIME 14
45+
#define HVM_TRAP1_VMSETTIME 15
46+
#define HVM_TRAP1_VMWAIT 16
47+
#define HVM_TRAP1_VMYIELD 17
48+
#define HVM_TRAP1_VMSTART 18
49+
#define HVM_TRAP1_VMSTOP 19
50+
#define HVM_TRAP1_VMVPID 20
51+
#define HVM_TRAP1_VMSETREGS 21
52+
#define HVM_TRAP1_VMGETREGS 22
53+
#define HVM_TRAP1_VMTIMEROP 24
3854

3955
#ifndef __ASSEMBLY__
4056

@@ -175,25 +191,6 @@ static inline long __vmintop_clear(long i)
175191

176192
#else /* Only assembly code should reference these */
177193

178-
#define HVM_TRAP1_VMRTE 1
179-
#define HVM_TRAP1_VMSETVEC 2
180-
#define HVM_TRAP1_VMSETIE 3
181-
#define HVM_TRAP1_VMGETIE 4
182-
#define HVM_TRAP1_VMINTOP 5
183-
#define HVM_TRAP1_VMCLRMAP 10
184-
#define HVM_TRAP1_VMNEWMAP 11
185-
#define HVM_TRAP1_FORMERLY_VMWIRE 12
186-
#define HVM_TRAP1_VMCACHE 13
187-
#define HVM_TRAP1_VMGETTIME 14
188-
#define HVM_TRAP1_VMSETTIME 15
189-
#define HVM_TRAP1_VMWAIT 16
190-
#define HVM_TRAP1_VMYIELD 17
191-
#define HVM_TRAP1_VMSTART 18
192-
#define HVM_TRAP1_VMSTOP 19
193-
#define HVM_TRAP1_VMVPID 20
194-
#define HVM_TRAP1_VMSETREGS 21
195-
#define HVM_TRAP1_VMGETREGS 22
196-
197194
#endif /* __ASSEMBLY__ */
198195

199196
/*
@@ -224,6 +221,8 @@ static inline long __vmintop_clear(long i)
224221
#define HVM_VMEST_UM_MSK 1
225222
#define HVM_VMEST_IE_SFT 30
226223
#define HVM_VMEST_IE_MSK 1
224+
#define HVM_VMEST_SS_SFT 29
225+
#define HVM_VMEST_SS_MSK 1
227226
#define HVM_VMEST_EVENTNUM_SFT 16
228227
#define HVM_VMEST_EVENTNUM_MSK 0xff
229228
#define HVM_VMEST_CAUSE_SFT 0
@@ -260,6 +259,8 @@ static inline long __vmintop_clear(long i)
260259
#define HVM_GE_C_INVI 0x15
261260
#define HVM_GE_C_PRIVI 0x1B
262261
#define HVM_GE_C_XMAL 0x1C
262+
#define HVM_GE_C_WREG 0x1D
263+
#define HVM_GE_C_PCAL 0x1E
263264
#define HVM_GE_C_RMAL 0x20
264265
#define HVM_GE_C_WMAL 0x21
265266
#define HVM_GE_C_RPROT 0x22

‎arch/hexagon/include/asm/mem-layout.h‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,25 @@
3232
#define PAGE_OFFSET _AC(0xc0000000, UL)
3333

3434
/*
35-
* LOAD_ADDRESS is the physical/linear address of where in memory
36-
* the kernel gets loaded. The 12 least significant bits must be zero (0)
37-
* due to limitations on setting the EVB
38-
*
35+
* Compiling for a platform that needs a crazy physical offset
36+
* (like if the memory starts at 1GB and up) means we need
37+
* an actual PHYS_OFFSET. Should be set up in head.S.
3938
*/
4039

41-
#ifndef LOAD_ADDRESS
42-
#define LOAD_ADDRESS 0x00000000
40+
#ifdef CONFIG_HEXAGON_PHYS_OFFSET
41+
#ifndef __ASSEMBLY__
42+
extern unsigned long __phys_offset;
43+
#endif
44+
#define PHYS_OFFSET __phys_offset
45+
#endif
46+
47+
#ifndef PHYS_OFFSET
48+
#define PHYS_OFFSET 0
4349
#endif
4450

51+
#define PHYS_PFN_OFFSET (PHYS_OFFSET >> PAGE_SHIFT)
52+
#define ARCH_PFN_OFFSET PHYS_PFN_OFFSET
53+
4554
#define TASK_SIZE (PAGE_OFFSET)
4655

4756
/* not sure how these are used yet */

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ typedef struct page *pgtable_t;
9696
* MIPS says they're only used during mem_init.
9797
* also, check if we need a PHYS_OFFSET.
9898
*/
99-
#define __pa(x) ((unsigned long)(x) - PAGE_OFFSET)
100-
#define __va(x) ((void *)((unsigned long)(x) + PAGE_OFFSET))
99+
#define __pa(x) ((unsigned long)(x) - PAGE_OFFSET + PHYS_OFFSET)
100+
#define __va(x) ((void *)((unsigned long)(x) - PHYS_OFFSET + PAGE_OFFSET))
101101

102102
/* The "page frame" descriptor is defined in linux/mm.h */
103103
struct page;
@@ -147,6 +147,7 @@ static inline void clear_page(void *page)
147147
*/
148148
#define kern_addr_valid(addr) (1)
149149

150+
#include <asm/mem-layout.h>
150151
#include <asm-generic/memory_model.h>
151152
/* XXX Todo: implement assembly-optimized version of getorder. */
152153
#include <asm-generic/getorder.h>

‎arch/hexagon/kernel/head.S‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,21 @@ ENTRY(stext)
4343
* Symbol is kernel segment address, but we need
4444
* the logical/physical address.
4545
*/
46-
r24 = asl(r24, #2)
47-
r24 = lsr(r24, #2)
46+
r25 = pc;
47+
r2.h = #0xffc0;
48+
r2.l = #0x0000;
49+
r25 = and(r2,r25); /* R25 holds PHYS_OFFSET now */
50+
r1.h = #HI(PAGE_OFFSET);
51+
r1.l = #LO(PAGE_OFFSET);
52+
r24 = sub(r24,r1); /* swapper_pg_dir - PAGE_OFFSET */
53+
r24 = add(r24,r25); /* + PHYS_OFFSET */
4854

49-
r0 = r24
55+
r0 = r24; /* aka __pa(swapper_pg_dir) */
5056

5157
/*
52-
* Initialize a 16MB PTE to make the virtual and physical
58+
* Initialize page dir to make the virtual and physical
5359
* addresses where the kernel was loaded be identical.
60+
* Done in 4MB chunks.
5461
*/
5562
#define PTE_BITS ( __HVM_PTE_R | __HVM_PTE_W | __HVM_PTE_X \
5663
| __HEXAGON_C_WB_L2 << 6 \
@@ -143,6 +150,13 @@ __head_s_vaddr_target:
143150
r2 = sub(r2,r0);
144151
call memset;
145152

153+
/* Set PHYS_OFFSET; should still be in R25 */
154+
#ifdef CONFIG_HEXAGON_PHYS_OFFSET
155+
r0.l = #LO(__phys_offset);
156+
r0.h = #HI(__phys_offset);
157+
memw(r0) = r25;
158+
#endif
159+
146160
/* Time to make the doughnuts. */
147161
call start_kernel
148162

‎arch/hexagon/kernel/setup.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ void __init setup_arch(char **cmdline_p)
6868
*/
6969
__vmsetvec(_K_VM_event_vector);
7070

71+
printk(KERN_INFO "PHYS_OFFSET=0x%08x\n", PHYS_OFFSET);
72+
7173
/*
7274
* Simulator has a few differences from the hardware.
7375
* For now, check uninitialized-but-mapped memory

‎arch/hexagon/kernel/vmlinux.lds.S‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
* 02110-1301, USA.
1919
*/
2020

21-
#define LOAD_OFFSET PAGE_OFFSET
22-
2321
#include <asm-generic/vmlinux.lds.h>
2422
#include <asm/asm-offsets.h> /* Most of the kernel defines are here */
2523
#include <asm/mem-layout.h> /* except for page_offset */
@@ -36,13 +34,9 @@ See asm-generic/sections.h for seemingly required labels.
3634

3735
#define PAGE_SIZE _PAGE_SIZE
3836

39-
/* This LOAD_OFFSET is temporary for debugging on the simulator; it may change
40-
for hypervisor pseudo-physical memory. */
41-
42-
4337
SECTIONS
4438
{
45-
. = PAGE_OFFSET + LOAD_ADDRESS;
39+
. = PAGE_OFFSET;
4640

4741
__init_begin = .;
4842
HEAD_TEXT_SECTION
@@ -52,7 +46,7 @@ SECTIONS
5246

5347
. = ALIGN(_PAGE_SIZE);
5448
_stext = .;
55-
.text : AT(ADDR(.text) - LOAD_OFFSET) {
49+
.text : AT(ADDR(.text)) {
5650
_text = .;
5751
TEXT_TEXT
5852
SCHED_TEXT

‎arch/hexagon/mm/init.c‎

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@
3131
* Define a startpg just past the end of the kernel image and a lastpg
3232
* that corresponds to the end of real or simulated platform memory.
3333
*/
34-
#define bootmem_startpg (PFN_UP(((unsigned long) _end) - PAGE_OFFSET))
34+
#define bootmem_startpg (PFN_UP(((unsigned long) _end) - PAGE_OFFSET + PHYS_OFFSET))
3535

36-
unsigned long bootmem_lastpg; /* Should be set by platform code */
36+
unsigned long bootmem_lastpg; /* Should be set by platform code */
37+
unsigned long __phys_offset; /* physical kernel offset >> 12 */
3738

3839
/* Set as variable to limit PMD copies */
3940
int max_kernel_seg = 0x303;
@@ -44,7 +45,6 @@ unsigned long zero_page_mask;
4445
/* indicate pfn's of high memory */
4546
unsigned long highstart_pfn, highend_pfn;
4647

47-
/* struct mmu_gather defined in asm-generic.h; */
4848
DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);
4949

5050
/* Default cache attribute for newly created page tables */
@@ -71,7 +71,7 @@ void __init mem_init(void)
7171
{
7272
/* No idea where this is actually declared. Seems to evade LXR. */
7373
totalram_pages += free_all_bootmem();
74-
num_physpages = bootmem_lastpg; /* seriously, what? */
74+
num_physpages = bootmem_lastpg-ARCH_PFN_OFFSET;
7575

7676
printk(KERN_INFO "totalram_pages = %ld\n", totalram_pages);
7777

@@ -193,6 +193,9 @@ void __init setup_arch_memory(void)
193193
* This needs to change for highmem setups.
194194
*/
195195

196+
/* Prior to this, bootmem_lastpg is actually mem size */
197+
bootmem_lastpg += ARCH_PFN_OFFSET;
198+
196199
/* Memory size needs to be a multiple of 16M */
197200
bootmem_lastpg = PFN_DOWN((bootmem_lastpg << PAGE_SHIFT) &
198201
~((BIG_KERNEL_PAGE_SIZE) - 1));
@@ -201,12 +204,15 @@ void __init setup_arch_memory(void)
201204
* Reserve the top DMA_RESERVE bytes of RAM for DMA (uncached)
202205
* memory allocation
203206
*/
204-
bootmap_size = init_bootmem(bootmem_startpg, bootmem_lastpg -
205-
PFN_DOWN(DMA_RESERVED_BYTES));
207+
208+
max_low_pfn = bootmem_lastpg - PFN_DOWN(DMA_RESERVED_BYTES);
209+
min_low_pfn = ARCH_PFN_OFFSET;
210+
bootmap_size = init_bootmem_node(NODE_DATA(0), bootmem_startpg, min_low_pfn, max_low_pfn);
206211

207212
printk(KERN_INFO "bootmem_startpg: 0x%08lx\n", bootmem_startpg);
208213
printk(KERN_INFO "bootmem_lastpg: 0x%08lx\n", bootmem_lastpg);
209214
printk(KERN_INFO "bootmap_size: %d\n", bootmap_size);
215+
printk(KERN_INFO "min_low_pfn: 0x%08lx\n", min_low_pfn);
210216
printk(KERN_INFO "max_low_pfn: 0x%08lx\n", max_low_pfn);
211217

212218
/*
@@ -221,14 +227,17 @@ void __init setup_arch_memory(void)
221227
/* this actually only goes to the end of the first gig */
222228
segtable_end = segtable + (1<<(30-22));
223229

224-
/* Move forward to the start of empty pages */
225-
segtable += bootmem_lastpg >> (22-PAGE_SHIFT);
230+
/*
231+
* Move forward to the start of empty pages; take into account
232+
* phys_offset shift.
233+
*/
226234

235+
segtable += (bootmem_lastpg-ARCH_PFN_OFFSET)>>(22-PAGE_SHIFT);
227236
{
228-
int i;
237+
int i;
229238

230-
for (i = 1 ; i <= DMA_RESERVE ; i++)
231-
segtable[-i] = ((segtable[-i] & __HVM_PTE_PGMASK_4MB)
239+
for (i = 1 ; i <= DMA_RESERVE ; i++)
240+
segtable[-i] = ((segtable[-i] & __HVM_PTE_PGMASK_4MB)
232241
| __HVM_PTE_R | __HVM_PTE_W | __HVM_PTE_X
233242
| __HEXAGON_C_UNC << 6
234243
| __HVM_PDE_S_4MB);
@@ -256,7 +265,7 @@ void __init setup_arch_memory(void)
256265
* Free all the memory that wasn't taken up by the bootmap, the DMA
257266
* reserve, or kernel itself.
258267
*/
259-
free_bootmem(PFN_PHYS(bootmem_startpg)+bootmap_size,
268+
free_bootmem(PFN_PHYS(bootmem_startpg) + bootmap_size,
260269
PFN_PHYS(bootmem_lastpg - bootmem_startpg) - bootmap_size -
261270
DMA_RESERVED_BYTES);
262271

0 commit comments

Comments
 (0)