18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (C) 2004 Konrad Eisele (eiselekd@web.de,konrad@gaisler.com) Gaisler Research 48c2ecf20Sopenharmony_ci * Copyright (C) 2004 Stefan Holst (mail@s-holst.de) Uni-Stuttgart 58c2ecf20Sopenharmony_ci * Copyright (C) 2009 Daniel Hellstrom (daniel@gaisler.com) Aeroflex Gaisler AB 68c2ecf20Sopenharmony_ci * Copyright (C) 2009 Konrad Eisele (konrad@gaisler.com) Aeroflex Gaisler AB 78c2ecf20Sopenharmony_ci */ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#ifndef LEON_H_INCLUDE 108c2ecf20Sopenharmony_ci#define LEON_H_INCLUDE 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci/* mmu register access, ASI_LEON_MMUREGS */ 138c2ecf20Sopenharmony_ci#define LEON_CNR_CTRL 0x000 148c2ecf20Sopenharmony_ci#define LEON_CNR_CTXP 0x100 158c2ecf20Sopenharmony_ci#define LEON_CNR_CTX 0x200 168c2ecf20Sopenharmony_ci#define LEON_CNR_F 0x300 178c2ecf20Sopenharmony_ci#define LEON_CNR_FADDR 0x400 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci#define LEON_CNR_CTX_NCTX 256 /*number of MMU ctx */ 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci#define LEON_CNR_CTRL_TLBDIS 0x80000000 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci#define LEON_MMUTLB_ENT_MAX 64 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci/* 268c2ecf20Sopenharmony_ci * diagnostic access from mmutlb.vhd: 278c2ecf20Sopenharmony_ci * 0: pte address 288c2ecf20Sopenharmony_ci * 4: pte 298c2ecf20Sopenharmony_ci * 8: additional flags 308c2ecf20Sopenharmony_ci */ 318c2ecf20Sopenharmony_ci#define LEON_DIAGF_LVL 0x3 328c2ecf20Sopenharmony_ci#define LEON_DIAGF_WR 0x8 338c2ecf20Sopenharmony_ci#define LEON_DIAGF_WR_SHIFT 3 348c2ecf20Sopenharmony_ci#define LEON_DIAGF_HIT 0x10 358c2ecf20Sopenharmony_ci#define LEON_DIAGF_HIT_SHIFT 4 368c2ecf20Sopenharmony_ci#define LEON_DIAGF_CTX 0x1fe0 378c2ecf20Sopenharmony_ci#define LEON_DIAGF_CTX_SHIFT 5 388c2ecf20Sopenharmony_ci#define LEON_DIAGF_VALID 0x2000 398c2ecf20Sopenharmony_ci#define LEON_DIAGF_VALID_SHIFT 13 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci/* irq masks */ 428c2ecf20Sopenharmony_ci#define LEON_HARD_INT(x) (1 << (x)) /* irq 0-15 */ 438c2ecf20Sopenharmony_ci#define LEON_IRQMASK_R 0x0000fffe /* bit 15- 1 of lregs.irqmask */ 448c2ecf20Sopenharmony_ci#define LEON_IRQPRIO_R 0xfffe0000 /* bit 31-17 of lregs.irqmask */ 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci#define LEON_MCFG2_SRAMDIS 0x00002000 478c2ecf20Sopenharmony_ci#define LEON_MCFG2_SDRAMEN 0x00004000 488c2ecf20Sopenharmony_ci#define LEON_MCFG2_SRAMBANKSZ 0x00001e00 /* [12-9] */ 498c2ecf20Sopenharmony_ci#define LEON_MCFG2_SRAMBANKSZ_SHIFT 9 508c2ecf20Sopenharmony_ci#define LEON_MCFG2_SDRAMBANKSZ 0x03800000 /* [25-23] */ 518c2ecf20Sopenharmony_ci#define LEON_MCFG2_SDRAMBANKSZ_SHIFT 23 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci#define LEON_TCNT0_MASK 0x7fffff 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci#define ASI_LEON3_SYSCTRL 0x02 578c2ecf20Sopenharmony_ci#define ASI_LEON3_SYSCTRL_ICFG 0x08 588c2ecf20Sopenharmony_ci#define ASI_LEON3_SYSCTRL_DCFG 0x0c 598c2ecf20Sopenharmony_ci#define ASI_LEON3_SYSCTRL_CFG_SNOOPING (1 << 27) 608c2ecf20Sopenharmony_ci#define ASI_LEON3_SYSCTRL_CFG_SSIZE(c) (1 << ((c >> 20) & 0xf)) 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__ 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci/* do a physical address bypass write, i.e. for 0x80000000 */ 658c2ecf20Sopenharmony_cistatic inline void leon_store_reg(unsigned long paddr, unsigned long value) 668c2ecf20Sopenharmony_ci{ 678c2ecf20Sopenharmony_ci __asm__ __volatile__("sta %0, [%1] %2\n\t" : : "r"(value), "r"(paddr), 688c2ecf20Sopenharmony_ci "i"(ASI_LEON_BYPASS) : "memory"); 698c2ecf20Sopenharmony_ci} 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci/* do a physical address bypass load, i.e. for 0x80000000 */ 728c2ecf20Sopenharmony_cistatic inline unsigned long leon_load_reg(unsigned long paddr) 738c2ecf20Sopenharmony_ci{ 748c2ecf20Sopenharmony_ci unsigned long retval; 758c2ecf20Sopenharmony_ci __asm__ __volatile__("lda [%1] %2, %0\n\t" : 768c2ecf20Sopenharmony_ci "=r"(retval) : "r"(paddr), "i"(ASI_LEON_BYPASS)); 778c2ecf20Sopenharmony_ci return retval; 788c2ecf20Sopenharmony_ci} 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci/* macro access for leon_load_reg() and leon_store_reg() */ 818c2ecf20Sopenharmony_ci#define LEON3_BYPASS_LOAD_PA(x) (leon_load_reg((unsigned long)(x))) 828c2ecf20Sopenharmony_ci#define LEON3_BYPASS_STORE_PA(x, v) (leon_store_reg((unsigned long)(x), (unsigned long)(v))) 838c2ecf20Sopenharmony_ci#define LEON_BYPASS_LOAD_PA(x) leon_load_reg((unsigned long)(x)) 848c2ecf20Sopenharmony_ci#define LEON_BYPASS_STORE_PA(x, v) leon_store_reg((unsigned long)(x), (unsigned long)(v)) 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_civoid leon_switch_mm(void); 878c2ecf20Sopenharmony_civoid leon_init_IRQ(void); 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_cistatic inline unsigned long sparc_leon3_get_dcachecfg(void) 908c2ecf20Sopenharmony_ci{ 918c2ecf20Sopenharmony_ci unsigned int retval; 928c2ecf20Sopenharmony_ci __asm__ __volatile__("lda [%1] %2, %0\n\t" : 938c2ecf20Sopenharmony_ci "=r"(retval) : 948c2ecf20Sopenharmony_ci "r"(ASI_LEON3_SYSCTRL_DCFG), 958c2ecf20Sopenharmony_ci "i"(ASI_LEON3_SYSCTRL)); 968c2ecf20Sopenharmony_ci return retval; 978c2ecf20Sopenharmony_ci} 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ci/* enable snooping */ 1008c2ecf20Sopenharmony_cistatic inline void sparc_leon3_enable_snooping(void) 1018c2ecf20Sopenharmony_ci{ 1028c2ecf20Sopenharmony_ci __asm__ __volatile__ ("lda [%%g0] 2, %%l1\n\t" 1038c2ecf20Sopenharmony_ci "set 0x800000, %%l2\n\t" 1048c2ecf20Sopenharmony_ci "or %%l2, %%l1, %%l2\n\t" 1058c2ecf20Sopenharmony_ci "sta %%l2, [%%g0] 2\n\t" : : : "l1", "l2"); 1068c2ecf20Sopenharmony_ci}; 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_cistatic inline int sparc_leon3_snooping_enabled(void) 1098c2ecf20Sopenharmony_ci{ 1108c2ecf20Sopenharmony_ci u32 cctrl; 1118c2ecf20Sopenharmony_ci __asm__ __volatile__("lda [%%g0] 2, %0\n\t" : "=r"(cctrl)); 1128c2ecf20Sopenharmony_ci return ((cctrl >> 23) & 1) && ((cctrl >> 17) & 1); 1138c2ecf20Sopenharmony_ci}; 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_cistatic inline void sparc_leon3_disable_cache(void) 1168c2ecf20Sopenharmony_ci{ 1178c2ecf20Sopenharmony_ci __asm__ __volatile__ ("lda [%%g0] 2, %%l1\n\t" 1188c2ecf20Sopenharmony_ci "set 0x00000f, %%l2\n\t" 1198c2ecf20Sopenharmony_ci "andn %%l2, %%l1, %%l2\n\t" 1208c2ecf20Sopenharmony_ci "sta %%l2, [%%g0] 2\n\t" : : : "l1", "l2"); 1218c2ecf20Sopenharmony_ci}; 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_cistatic inline unsigned long sparc_leon3_asr17(void) 1248c2ecf20Sopenharmony_ci{ 1258c2ecf20Sopenharmony_ci u32 asr17; 1268c2ecf20Sopenharmony_ci __asm__ __volatile__ ("rd %%asr17, %0\n\t" : "=r"(asr17)); 1278c2ecf20Sopenharmony_ci return asr17; 1288c2ecf20Sopenharmony_ci}; 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_cistatic inline int sparc_leon3_cpuid(void) 1318c2ecf20Sopenharmony_ci{ 1328c2ecf20Sopenharmony_ci return sparc_leon3_asr17() >> 28; 1338c2ecf20Sopenharmony_ci} 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_ci#endif /*!__ASSEMBLY__*/ 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_ci#ifdef CONFIG_SMP 1388c2ecf20Sopenharmony_ci# define LEON3_IRQ_IPI_DEFAULT 13 1398c2ecf20Sopenharmony_ci# define LEON3_IRQ_TICKER (leon3_gptimer_irq) 1408c2ecf20Sopenharmony_ci# define LEON3_IRQ_CROSS_CALL 15 1418c2ecf20Sopenharmony_ci#endif 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_ci#if defined(PAGE_SIZE_LEON_8K) 1448c2ecf20Sopenharmony_ci#define LEON_PAGE_SIZE_LEON 1 1458c2ecf20Sopenharmony_ci#elif defined(PAGE_SIZE_LEON_16K) 1468c2ecf20Sopenharmony_ci#define LEON_PAGE_SIZE_LEON 2) 1478c2ecf20Sopenharmony_ci#else 1488c2ecf20Sopenharmony_ci#define LEON_PAGE_SIZE_LEON 0 1498c2ecf20Sopenharmony_ci#endif 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_ci#if LEON_PAGE_SIZE_LEON == 0 1528c2ecf20Sopenharmony_ci/* [ 8, 6, 6 ] + 12 */ 1538c2ecf20Sopenharmony_ci#define LEON_PGD_SH 24 1548c2ecf20Sopenharmony_ci#define LEON_PGD_M 0xff 1558c2ecf20Sopenharmony_ci#define LEON_PMD_SH 18 1568c2ecf20Sopenharmony_ci#define LEON_PMD_SH_V (LEON_PGD_SH-2) 1578c2ecf20Sopenharmony_ci#define LEON_PMD_M 0x3f 1588c2ecf20Sopenharmony_ci#define LEON_PTE_SH 12 1598c2ecf20Sopenharmony_ci#define LEON_PTE_M 0x3f 1608c2ecf20Sopenharmony_ci#elif LEON_PAGE_SIZE_LEON == 1 1618c2ecf20Sopenharmony_ci/* [ 7, 6, 6 ] + 13 */ 1628c2ecf20Sopenharmony_ci#define LEON_PGD_SH 25 1638c2ecf20Sopenharmony_ci#define LEON_PGD_M 0x7f 1648c2ecf20Sopenharmony_ci#define LEON_PMD_SH 19 1658c2ecf20Sopenharmony_ci#define LEON_PMD_SH_V (LEON_PGD_SH-1) 1668c2ecf20Sopenharmony_ci#define LEON_PMD_M 0x3f 1678c2ecf20Sopenharmony_ci#define LEON_PTE_SH 13 1688c2ecf20Sopenharmony_ci#define LEON_PTE_M 0x3f 1698c2ecf20Sopenharmony_ci#elif LEON_PAGE_SIZE_LEON == 2 1708c2ecf20Sopenharmony_ci/* [ 6, 6, 6 ] + 14 */ 1718c2ecf20Sopenharmony_ci#define LEON_PGD_SH 26 1728c2ecf20Sopenharmony_ci#define LEON_PGD_M 0x3f 1738c2ecf20Sopenharmony_ci#define LEON_PMD_SH 20 1748c2ecf20Sopenharmony_ci#define LEON_PMD_SH_V (LEON_PGD_SH-0) 1758c2ecf20Sopenharmony_ci#define LEON_PMD_M 0x3f 1768c2ecf20Sopenharmony_ci#define LEON_PTE_SH 14 1778c2ecf20Sopenharmony_ci#define LEON_PTE_M 0x3f 1788c2ecf20Sopenharmony_ci#elif LEON_PAGE_SIZE_LEON == 3 1798c2ecf20Sopenharmony_ci/* [ 4, 7, 6 ] + 15 */ 1808c2ecf20Sopenharmony_ci#define LEON_PGD_SH 28 1818c2ecf20Sopenharmony_ci#define LEON_PGD_M 0x0f 1828c2ecf20Sopenharmony_ci#define LEON_PMD_SH 21 1838c2ecf20Sopenharmony_ci#define LEON_PMD_SH_V (LEON_PGD_SH-0) 1848c2ecf20Sopenharmony_ci#define LEON_PMD_M 0x7f 1858c2ecf20Sopenharmony_ci#define LEON_PTE_SH 15 1868c2ecf20Sopenharmony_ci#define LEON_PTE_M 0x3f 1878c2ecf20Sopenharmony_ci#else 1888c2ecf20Sopenharmony_ci#error cannot determine LEON_PAGE_SIZE_LEON 1898c2ecf20Sopenharmony_ci#endif 1908c2ecf20Sopenharmony_ci 1918c2ecf20Sopenharmony_ci#define LEON3_XCCR_SETS_MASK 0x07000000UL 1928c2ecf20Sopenharmony_ci#define LEON3_XCCR_SSIZE_MASK 0x00f00000UL 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_ci#define LEON2_CCR_DSETS_MASK 0x03000000UL 1958c2ecf20Sopenharmony_ci#define LEON2_CFG_SSIZE_MASK 0x00007000UL 1968c2ecf20Sopenharmony_ci 1978c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__ 1988c2ecf20Sopenharmony_cistruct vm_area_struct; 1998c2ecf20Sopenharmony_ci 2008c2ecf20Sopenharmony_ciunsigned long leon_swprobe(unsigned long vaddr, unsigned long *paddr); 2018c2ecf20Sopenharmony_civoid leon_flush_icache_all(void); 2028c2ecf20Sopenharmony_civoid leon_flush_dcache_all(void); 2038c2ecf20Sopenharmony_civoid leon_flush_cache_all(void); 2048c2ecf20Sopenharmony_civoid leon_flush_tlb_all(void); 2058c2ecf20Sopenharmony_ciextern int leon_flush_during_switch; 2068c2ecf20Sopenharmony_ciint leon_flush_needed(void); 2078c2ecf20Sopenharmony_civoid leon_flush_pcache_all(struct vm_area_struct *vma, unsigned long page); 2088c2ecf20Sopenharmony_ci 2098c2ecf20Sopenharmony_ci/* struct that hold LEON3 cache configuration registers */ 2108c2ecf20Sopenharmony_cistruct leon3_cacheregs { 2118c2ecf20Sopenharmony_ci unsigned long ccr; /* 0x00 - Cache Control Register */ 2128c2ecf20Sopenharmony_ci unsigned long iccr; /* 0x08 - Instruction Cache Configuration Register */ 2138c2ecf20Sopenharmony_ci unsigned long dccr; /* 0x0c - Data Cache Configuration Register */ 2148c2ecf20Sopenharmony_ci}; 2158c2ecf20Sopenharmony_ci 2168c2ecf20Sopenharmony_ci#include <linux/irq.h> 2178c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 2188c2ecf20Sopenharmony_ci 2198c2ecf20Sopenharmony_cistruct device_node; 2208c2ecf20Sopenharmony_cistruct task_struct; 2218c2ecf20Sopenharmony_ciunsigned int leon_build_device_irq(unsigned int real_irq, 2228c2ecf20Sopenharmony_ci irq_flow_handler_t flow_handler, 2238c2ecf20Sopenharmony_ci const char *name, int do_ack); 2248c2ecf20Sopenharmony_civoid leon_update_virq_handling(unsigned int virq, 2258c2ecf20Sopenharmony_ci irq_flow_handler_t flow_handler, 2268c2ecf20Sopenharmony_ci const char *name, int do_ack); 2278c2ecf20Sopenharmony_civoid leon_init_timers(void); 2288c2ecf20Sopenharmony_civoid leon_node_init(struct device_node *dp, struct device_node ***nextp); 2298c2ecf20Sopenharmony_civoid init_leon(void); 2308c2ecf20Sopenharmony_civoid poke_leonsparc(void); 2318c2ecf20Sopenharmony_civoid leon3_getCacheRegs(struct leon3_cacheregs *regs); 2328c2ecf20Sopenharmony_ciextern int leon3_ticker_irq; 2338c2ecf20Sopenharmony_ci 2348c2ecf20Sopenharmony_ci#ifdef CONFIG_SMP 2358c2ecf20Sopenharmony_ciint leon_smp_nrcpus(void); 2368c2ecf20Sopenharmony_civoid leon_clear_profile_irq(int cpu); 2378c2ecf20Sopenharmony_civoid leon_smp_done(void); 2388c2ecf20Sopenharmony_civoid leon_boot_cpus(void); 2398c2ecf20Sopenharmony_ciint leon_boot_one_cpu(int i, struct task_struct *); 2408c2ecf20Sopenharmony_civoid leon_init_smp(void); 2418c2ecf20Sopenharmony_civoid leon_enable_irq_cpu(unsigned int irq_nr, unsigned int cpu); 2428c2ecf20Sopenharmony_ciirqreturn_t leon_percpu_timer_interrupt(int irq, void *unused); 2438c2ecf20Sopenharmony_ci 2448c2ecf20Sopenharmony_ciextern unsigned int smpleon_ipi[]; 2458c2ecf20Sopenharmony_ciextern unsigned int linux_trap_ipi15_leon[]; 2468c2ecf20Sopenharmony_ciextern int leon_ipi_irq; 2478c2ecf20Sopenharmony_ci 2488c2ecf20Sopenharmony_ci#endif /* CONFIG_SMP */ 2498c2ecf20Sopenharmony_ci 2508c2ecf20Sopenharmony_ci#endif /* __ASSEMBLY__ */ 2518c2ecf20Sopenharmony_ci 2528c2ecf20Sopenharmony_ci/* macros used in leon_mm.c */ 2538c2ecf20Sopenharmony_ci#define PFN(x) ((x) >> PAGE_SHIFT) 2548c2ecf20Sopenharmony_ci#define _pfn_valid(pfn) ((pfn < last_valid_pfn) && (pfn >= PFN(phys_base))) 2558c2ecf20Sopenharmony_ci#define _SRMMU_PTE_PMASK_LEON 0xffffffff 2568c2ecf20Sopenharmony_ci 2578c2ecf20Sopenharmony_ci/* 2588c2ecf20Sopenharmony_ci * On LEON PCI Memory space is mapped 1:1 with physical address space. 2598c2ecf20Sopenharmony_ci * 2608c2ecf20Sopenharmony_ci * I/O space is located at low 64Kbytes in PCI I/O space. The I/O addresses 2618c2ecf20Sopenharmony_ci * are converted into CPU addresses to virtual addresses that are mapped with 2628c2ecf20Sopenharmony_ci * MMU to the PCI Host PCI I/O space window which are translated to the low 2638c2ecf20Sopenharmony_ci * 64Kbytes by the Host controller. 2648c2ecf20Sopenharmony_ci */ 2658c2ecf20Sopenharmony_ci 2668c2ecf20Sopenharmony_ci#endif 267