/*1* Copyright 2010 Tilera Corporation. All Rights Reserved.2*3* This program is free software; you can redistribute it and/or4* modify it under the terms of the GNU General Public License5* as published by the Free Software Foundation, version 2.6*7* This program is distributed in the hope that it will be useful, but8* WITHOUT ANY WARRANTY; without even the implied warranty of9* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or10* NON INFRINGEMENT. See the GNU General Public License for11* more details.12*13* TILE startup code.14*/1516#include <linux/linkage.h>17#include <linux/init.h>18#include <asm/page.h>19#include <asm/pgtable.h>20#include <asm/thread_info.h>21#include <asm/processor.h>22#include <asm/asm-offsets.h>23#include <hv/hypervisor.h>24#include <arch/chip.h>25#include <arch/spr_def.h>2627/*28* This module contains the entry code for kernel images. It performs the29* minimal setup needed to call the generic C routines.30*/3132__HEAD33ENTRY(_start)34/* Notify the hypervisor of what version of the API we want */35{36movei r1, TILE_CHIP37movei r2, TILE_CHIP_REV38}39{40moveli r0, _HV_VERSION41jal hv_init42}43/* Get a reasonable default ASID in r0 */44{45move r0, zero46jal hv_inquire_asid47}48/* Install the default page table */49{50moveli r6, lo16(swapper_pgprot - PAGE_OFFSET)51move r4, r0 /* use starting ASID of range for this page table */52}53{54moveli r0, lo16(swapper_pg_dir - PAGE_OFFSET)55auli r6, r6, ha16(swapper_pgprot - PAGE_OFFSET)56}57{58lw r2, r659addi r6, r6, 460}61{62lw r3, r663auli r0, r0, ha16(swapper_pg_dir - PAGE_OFFSET)64}65{66inv r667move r1, zero /* high 32 bits of CPA is zero */68}69{70moveli lr, lo16(1f)71move r5, zero72}73{74auli lr, lr, ha16(1f)75j hv_install_context76}771:7879/* Get our processor number and save it away in SAVE_K_0. */80jal hv_inquire_topology81mulll_uu r4, r1, r2 /* r1 == y, r2 == width */82add r4, r4, r0 /* r0 == x, so r4 == cpu == y*width + x */8384#ifdef CONFIG_SMP85/*86* Load up our per-cpu offset. When the first (master) tile87* boots, this value is still zero, so we will load boot_pc88* with start_kernel, and boot_sp with init_stack + THREAD_SIZE.89* The master tile initializes the per-cpu offset array, so that90* when subsequent (secondary) tiles boot, they will instead load91* from their per-cpu versions of boot_sp and boot_pc.92*/93moveli r5, lo16(__per_cpu_offset)94auli r5, r5, ha16(__per_cpu_offset)95s2a r5, r4, r596lw r5, r597bnz r5, 1f9899/*100* Save the width and height to the smp_topology variable101* for later use.102*/103moveli r0, lo16(smp_topology + HV_TOPOLOGY_WIDTH_OFFSET)104auli r0, r0, ha16(smp_topology + HV_TOPOLOGY_WIDTH_OFFSET)105{106sw r0, r2107addi r0, r0, (HV_TOPOLOGY_HEIGHT_OFFSET - HV_TOPOLOGY_WIDTH_OFFSET)108}109sw r0, r31101:111#else112move r5, zero113#endif114115/* Load and go with the correct pc and sp. */116{117addli r1, r5, lo16(boot_sp)118addli r0, r5, lo16(boot_pc)119}120{121auli r1, r1, ha16(boot_sp)122auli r0, r0, ha16(boot_pc)123}124lw r0, r0125lw sp, r1126or r4, sp, r4127mtspr SPR_SYSTEM_SAVE_K_0, r4 /* save ksp0 + cpu */128addi sp, sp, -STACK_TOP_DELTA129{130move lr, zero /* stop backtraces in the called function */131jr r0132}133ENDPROC(_start)134135__PAGE_ALIGNED_BSS136.align PAGE_SIZE137ENTRY(empty_zero_page)138.fill PAGE_SIZE,1,0139END(empty_zero_page)140141.macro PTE va, cpa, bits1, no_org=0142.ifeq \no_org143.org swapper_pg_dir + HV_L1_INDEX(\va) * HV_PTE_SIZE144.endif145.word HV_PTE_PAGE | HV_PTE_DIRTY | HV_PTE_PRESENT | HV_PTE_ACCESSED | \146(HV_PTE_MODE_CACHE_NO_L3 << HV_PTE_INDEX_MODE)147.word (\bits1) | (HV_CPA_TO_PFN(\cpa) << (HV_PTE_INDEX_PFN - 32))148.endm149150__PAGE_ALIGNED_DATA151.align PAGE_SIZE152ENTRY(swapper_pg_dir)153/*154* All data pages from PAGE_OFFSET to MEM_USER_INTRPT are mapped as155* VA = PA + PAGE_OFFSET. We remap things with more precise access156* permissions and more respect for size of RAM later.157*/158.set addr, 0159.rept (MEM_USER_INTRPT - PAGE_OFFSET) >> PGDIR_SHIFT160PTE addr + PAGE_OFFSET, addr, (1 << (HV_PTE_INDEX_READABLE - 32)) | \161(1 << (HV_PTE_INDEX_WRITABLE - 32))162.set addr, addr + PGDIR_SIZE163.endr164165/* The true text VAs are mapped as VA = PA + MEM_SV_INTRPT */166PTE MEM_SV_INTRPT, 0, (1 << (HV_PTE_INDEX_READABLE - 32)) | \167(1 << (HV_PTE_INDEX_EXECUTABLE - 32))168.org swapper_pg_dir + HV_L1_SIZE169END(swapper_pg_dir)170171/*172* Isolate swapper_pgprot to its own cache line, since each cpu173* starting up will read it using VA-is-PA and local homing.174* This would otherwise likely conflict with other data on the cache175* line, once we have set its permanent home in the page tables.176*/177__INITDATA178.align CHIP_L2_LINE_SIZE()179ENTRY(swapper_pgprot)180PTE 0, 0, (1 << (HV_PTE_INDEX_READABLE - 32)) | \181(1 << (HV_PTE_INDEX_WRITABLE - 32)), 1182.align CHIP_L2_LINE_SIZE()183END(swapper_pgprot)184185186