xref: /openbmc/linux/arch/sparc/include/asm/leon.h (revision 597473720f4dc69749542bfcfed4a927a43d935e)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
25213a780SKonrad Eisele /*
35213a780SKonrad Eisele  * Copyright (C) 2004 Konrad Eisele (eiselekd@web.de,konrad@gaisler.com) Gaisler Research
45213a780SKonrad Eisele  * Copyright (C) 2004 Stefan Holst (mail@s-holst.de) Uni-Stuttgart
55213a780SKonrad Eisele  * Copyright (C) 2009 Daniel Hellstrom (daniel@gaisler.com) Aeroflex Gaisler AB
65213a780SKonrad Eisele  * Copyright (C) 2009 Konrad Eisele (konrad@gaisler.com) Aeroflex Gaisler AB
75213a780SKonrad Eisele  */
85213a780SKonrad Eisele 
95213a780SKonrad Eisele #ifndef LEON_H_INCLUDE
105213a780SKonrad Eisele #define LEON_H_INCLUDE
115213a780SKonrad Eisele 
125213a780SKonrad Eisele /* mmu register access, ASI_LEON_MMUREGS */
135213a780SKonrad Eisele #define LEON_CNR_CTRL		0x000
145213a780SKonrad Eisele #define LEON_CNR_CTXP		0x100
155213a780SKonrad Eisele #define LEON_CNR_CTX		0x200
165213a780SKonrad Eisele #define LEON_CNR_F		0x300
175213a780SKonrad Eisele #define LEON_CNR_FADDR		0x400
185213a780SKonrad Eisele 
195213a780SKonrad Eisele #define LEON_CNR_CTX_NCTX	256	/*number of MMU ctx */
205213a780SKonrad Eisele 
215213a780SKonrad Eisele #define LEON_CNR_CTRL_TLBDIS	0x80000000
225213a780SKonrad Eisele 
235213a780SKonrad Eisele #define LEON_MMUTLB_ENT_MAX	64
245213a780SKonrad Eisele 
255213a780SKonrad Eisele /*
265213a780SKonrad Eisele  * diagnostic access from mmutlb.vhd:
275213a780SKonrad Eisele  * 0: pte address
285213a780SKonrad Eisele  * 4: pte
295213a780SKonrad Eisele  * 8: additional flags
305213a780SKonrad Eisele  */
315213a780SKonrad Eisele #define LEON_DIAGF_LVL		0x3
325213a780SKonrad Eisele #define LEON_DIAGF_WR		0x8
335213a780SKonrad Eisele #define LEON_DIAGF_WR_SHIFT	3
345213a780SKonrad Eisele #define LEON_DIAGF_HIT		0x10
355213a780SKonrad Eisele #define LEON_DIAGF_HIT_SHIFT	4
365213a780SKonrad Eisele #define LEON_DIAGF_CTX		0x1fe0
375213a780SKonrad Eisele #define LEON_DIAGF_CTX_SHIFT	5
385213a780SKonrad Eisele #define LEON_DIAGF_VALID	0x2000
395213a780SKonrad Eisele #define LEON_DIAGF_VALID_SHIFT	13
405213a780SKonrad Eisele 
415213a780SKonrad Eisele /* irq masks */
425213a780SKonrad Eisele #define LEON_HARD_INT(x)	(1 << (x))	/* irq 0-15 */
435213a780SKonrad Eisele #define LEON_IRQMASK_R		0x0000fffe	/* bit 15- 1 of lregs.irqmask */
445213a780SKonrad Eisele #define LEON_IRQPRIO_R		0xfffe0000	/* bit 31-17 of lregs.irqmask */
455213a780SKonrad Eisele 
465213a780SKonrad Eisele #define LEON_MCFG2_SRAMDIS		0x00002000
475213a780SKonrad Eisele #define LEON_MCFG2_SDRAMEN		0x00004000
485213a780SKonrad Eisele #define LEON_MCFG2_SRAMBANKSZ		0x00001e00	/* [12-9] */
495213a780SKonrad Eisele #define LEON_MCFG2_SRAMBANKSZ_SHIFT	9
505213a780SKonrad Eisele #define LEON_MCFG2_SDRAMBANKSZ		0x03800000	/* [25-23] */
515213a780SKonrad Eisele #define LEON_MCFG2_SDRAMBANKSZ_SHIFT	23
525213a780SKonrad Eisele 
535213a780SKonrad Eisele #define LEON_TCNT0_MASK	0x7fffff
545213a780SKonrad Eisele 
555213a780SKonrad Eisele 
565213a780SKonrad Eisele #define ASI_LEON3_SYSCTRL		0x02
575213a780SKonrad Eisele #define ASI_LEON3_SYSCTRL_ICFG		0x08
585213a780SKonrad Eisele #define ASI_LEON3_SYSCTRL_DCFG		0x0c
595213a780SKonrad Eisele #define ASI_LEON3_SYSCTRL_CFG_SNOOPING (1 << 27)
605213a780SKonrad Eisele #define ASI_LEON3_SYSCTRL_CFG_SSIZE(c) (1 << ((c >> 20) & 0xf))
615213a780SKonrad Eisele 
625213a780SKonrad Eisele #ifndef __ASSEMBLY__
635213a780SKonrad Eisele 
645213a780SKonrad Eisele /* do a physical address bypass write, i.e. for 0x80000000 */
leon_store_reg(unsigned long paddr,unsigned long value)655213a780SKonrad Eisele static inline void leon_store_reg(unsigned long paddr, unsigned long value)
665213a780SKonrad Eisele {
675213a780SKonrad Eisele 	__asm__ __volatile__("sta %0, [%1] %2\n\t" : : "r"(value), "r"(paddr),
685213a780SKonrad Eisele 			     "i"(ASI_LEON_BYPASS) : "memory");
695213a780SKonrad Eisele }
705213a780SKonrad Eisele 
715213a780SKonrad Eisele /* do a physical address bypass load, i.e. for 0x80000000 */
leon_load_reg(unsigned long paddr)725213a780SKonrad Eisele static inline unsigned long leon_load_reg(unsigned long paddr)
735213a780SKonrad Eisele {
745213a780SKonrad Eisele 	unsigned long retval;
755213a780SKonrad Eisele 	__asm__ __volatile__("lda [%1] %2, %0\n\t" :
765213a780SKonrad Eisele 			     "=r"(retval) : "r"(paddr), "i"(ASI_LEON_BYPASS));
775213a780SKonrad Eisele 	return retval;
785213a780SKonrad Eisele }
795213a780SKonrad Eisele 
805213a780SKonrad Eisele /* macro access for leon_load_reg() and leon_store_reg() */
815213a780SKonrad Eisele #define LEON3_BYPASS_LOAD_PA(x)	    (leon_load_reg((unsigned long)(x)))
825213a780SKonrad Eisele #define LEON3_BYPASS_STORE_PA(x, v) (leon_store_reg((unsigned long)(x), (unsigned long)(v)))
835213a780SKonrad Eisele #define LEON_BYPASS_LOAD_PA(x)      leon_load_reg((unsigned long)(x))
845213a780SKonrad Eisele #define LEON_BYPASS_STORE_PA(x, v)  leon_store_reg((unsigned long)(x), (unsigned long)(v))
855213a780SKonrad Eisele 
86f05a6865SSam Ravnborg void leon_switch_mm(void);
87f05a6865SSam Ravnborg void leon_init_IRQ(void);
885213a780SKonrad Eisele 
sparc_leon3_get_dcachecfg(void)894309e568SKristoffer Glembo static inline unsigned long sparc_leon3_get_dcachecfg(void)
905213a780SKonrad Eisele {
915213a780SKonrad Eisele 	unsigned int retval;
925213a780SKonrad Eisele 	__asm__ __volatile__("lda [%1] %2, %0\n\t" :
935213a780SKonrad Eisele 			     "=r"(retval) :
945213a780SKonrad Eisele 			     "r"(ASI_LEON3_SYSCTRL_DCFG),
955213a780SKonrad Eisele 			     "i"(ASI_LEON3_SYSCTRL));
965213a780SKonrad Eisele 	return retval;
975213a780SKonrad Eisele }
985213a780SKonrad Eisele 
995213a780SKonrad Eisele /* enable snooping */
sparc_leon3_enable_snooping(void)1004309e568SKristoffer Glembo static inline void sparc_leon3_enable_snooping(void)
1015213a780SKonrad Eisele {
1025213a780SKonrad Eisele 	__asm__ __volatile__ ("lda [%%g0] 2, %%l1\n\t"
1035213a780SKonrad Eisele 			  "set 0x800000, %%l2\n\t"
1045213a780SKonrad Eisele 			  "or  %%l2, %%l1, %%l2\n\t"
1055213a780SKonrad Eisele 			  "sta %%l2, [%%g0] 2\n\t" : : : "l1", "l2");
1065213a780SKonrad Eisele };
1075213a780SKonrad Eisele 
sparc_leon3_snooping_enabled(void)1084309e568SKristoffer Glembo static inline int sparc_leon3_snooping_enabled(void)
1094309e568SKristoffer Glembo {
1104309e568SKristoffer Glembo 	u32 cctrl;
1114309e568SKristoffer Glembo 	__asm__ __volatile__("lda [%%g0] 2, %0\n\t" : "=r"(cctrl));
112e8e2bfd1SAndreas Larsson 	return ((cctrl >> 23) & 1) && ((cctrl >> 17) & 1);
1134309e568SKristoffer Glembo };
1144309e568SKristoffer Glembo 
sparc_leon3_disable_cache(void)1154309e568SKristoffer Glembo static inline void sparc_leon3_disable_cache(void)
1165213a780SKonrad Eisele {
1175213a780SKonrad Eisele 	__asm__ __volatile__ ("lda [%%g0] 2, %%l1\n\t"
1185213a780SKonrad Eisele 			  "set 0x00000f, %%l2\n\t"
1195213a780SKonrad Eisele 			  "andn  %%l2, %%l1, %%l2\n\t"
1205213a780SKonrad Eisele 			  "sta %%l2, [%%g0] 2\n\t" : : : "l1", "l2");
1215213a780SKonrad Eisele };
1225213a780SKonrad Eisele 
sparc_leon3_asr17(void)123e2305e37SDaniel Hellstrom static inline unsigned long sparc_leon3_asr17(void)
124e2305e37SDaniel Hellstrom {
125e2305e37SDaniel Hellstrom 	u32 asr17;
126e2305e37SDaniel Hellstrom 	__asm__ __volatile__ ("rd %%asr17, %0\n\t" : "=r"(asr17));
127e2305e37SDaniel Hellstrom 	return asr17;
128e2305e37SDaniel Hellstrom };
129e2305e37SDaniel Hellstrom 
sparc_leon3_cpuid(void)130e2305e37SDaniel Hellstrom static inline int sparc_leon3_cpuid(void)
131e2305e37SDaniel Hellstrom {
132e2305e37SDaniel Hellstrom 	return sparc_leon3_asr17() >> 28;
133e2305e37SDaniel Hellstrom }
134e2305e37SDaniel Hellstrom 
1355213a780SKonrad Eisele #endif /*!__ASSEMBLY__*/
1365213a780SKonrad Eisele 
1375213a780SKonrad Eisele #ifdef CONFIG_SMP
1381ca0c808SDaniel Hellstrom # define LEON3_IRQ_IPI_DEFAULT		13
1391ffbc51aSAndreas Larsson # define LEON3_IRQ_TICKER		(leon3_gptimer_irq)
1405213a780SKonrad Eisele # define LEON3_IRQ_CROSS_CALL		15
1415213a780SKonrad Eisele #endif
1425213a780SKonrad Eisele 
1435213a780SKonrad Eisele #if defined(PAGE_SIZE_LEON_8K)
1445213a780SKonrad Eisele #define LEON_PAGE_SIZE_LEON 1
1455213a780SKonrad Eisele #elif defined(PAGE_SIZE_LEON_16K)
1465213a780SKonrad Eisele #define LEON_PAGE_SIZE_LEON 2)
1475213a780SKonrad Eisele #else
1485213a780SKonrad Eisele #define LEON_PAGE_SIZE_LEON 0
1495213a780SKonrad Eisele #endif
1505213a780SKonrad Eisele 
1515213a780SKonrad Eisele #if LEON_PAGE_SIZE_LEON == 0
1525213a780SKonrad Eisele /* [ 8, 6, 6 ] + 12 */
1535213a780SKonrad Eisele #define LEON_PGD_SH    24
1545213a780SKonrad Eisele #define LEON_PGD_M     0xff
1555213a780SKonrad Eisele #define LEON_PMD_SH    18
1565213a780SKonrad Eisele #define LEON_PMD_SH_V  (LEON_PGD_SH-2)
1575213a780SKonrad Eisele #define LEON_PMD_M     0x3f
1585213a780SKonrad Eisele #define LEON_PTE_SH    12
1595213a780SKonrad Eisele #define LEON_PTE_M     0x3f
1605213a780SKonrad Eisele #elif LEON_PAGE_SIZE_LEON == 1
1615213a780SKonrad Eisele /* [ 7, 6, 6 ] + 13 */
1625213a780SKonrad Eisele #define LEON_PGD_SH    25
1635213a780SKonrad Eisele #define LEON_PGD_M     0x7f
1645213a780SKonrad Eisele #define LEON_PMD_SH    19
1655213a780SKonrad Eisele #define LEON_PMD_SH_V  (LEON_PGD_SH-1)
1665213a780SKonrad Eisele #define LEON_PMD_M     0x3f
1675213a780SKonrad Eisele #define LEON_PTE_SH    13
1685213a780SKonrad Eisele #define LEON_PTE_M     0x3f
1695213a780SKonrad Eisele #elif LEON_PAGE_SIZE_LEON == 2
1705213a780SKonrad Eisele /* [ 6, 6, 6 ] + 14 */
1715213a780SKonrad Eisele #define LEON_PGD_SH    26
1725213a780SKonrad Eisele #define LEON_PGD_M     0x3f
1735213a780SKonrad Eisele #define LEON_PMD_SH    20
1745213a780SKonrad Eisele #define LEON_PMD_SH_V  (LEON_PGD_SH-0)
1755213a780SKonrad Eisele #define LEON_PMD_M     0x3f
1765213a780SKonrad Eisele #define LEON_PTE_SH    14
1775213a780SKonrad Eisele #define LEON_PTE_M     0x3f
1785213a780SKonrad Eisele #elif LEON_PAGE_SIZE_LEON == 3
1795213a780SKonrad Eisele /* [ 4, 7, 6 ] + 15 */
1805213a780SKonrad Eisele #define LEON_PGD_SH    28
1815213a780SKonrad Eisele #define LEON_PGD_M     0x0f
1825213a780SKonrad Eisele #define LEON_PMD_SH    21
1835213a780SKonrad Eisele #define LEON_PMD_SH_V  (LEON_PGD_SH-0)
1845213a780SKonrad Eisele #define LEON_PMD_M     0x7f
1855213a780SKonrad Eisele #define LEON_PTE_SH    15
1865213a780SKonrad Eisele #define LEON_PTE_M     0x3f
1875213a780SKonrad Eisele #else
1885213a780SKonrad Eisele #error cannot determine LEON_PAGE_SIZE_LEON
1895213a780SKonrad Eisele #endif
1905213a780SKonrad Eisele 
1915213a780SKonrad Eisele #define LEON3_XCCR_SETS_MASK  0x07000000UL
1925213a780SKonrad Eisele #define LEON3_XCCR_SSIZE_MASK 0x00f00000UL
1935213a780SKonrad Eisele 
1945213a780SKonrad Eisele #define LEON2_CCR_DSETS_MASK 0x03000000UL
1955213a780SKonrad Eisele #define LEON2_CFG_SSIZE_MASK 0x00007000UL
1965213a780SKonrad Eisele 
1975213a780SKonrad Eisele #ifndef __ASSEMBLY__
198f6678d3bSSam Ravnborg struct vm_area_struct;
199f6678d3bSSam Ravnborg 
200f05a6865SSam Ravnborg unsigned long leon_swprobe(unsigned long vaddr, unsigned long *paddr);
201f05a6865SSam Ravnborg void leon_flush_icache_all(void);
202f05a6865SSam Ravnborg void leon_flush_dcache_all(void);
203f05a6865SSam Ravnborg void leon_flush_cache_all(void);
204f05a6865SSam Ravnborg void leon_flush_tlb_all(void);
2055213a780SKonrad Eisele extern int leon_flush_during_switch;
206f05a6865SSam Ravnborg int leon_flush_needed(void);
207f05a6865SSam Ravnborg void leon_flush_pcache_all(struct vm_area_struct *vma, unsigned long page);
2085213a780SKonrad Eisele 
2095213a780SKonrad Eisele /* struct that hold LEON3 cache configuration registers */
2105213a780SKonrad Eisele struct leon3_cacheregs {
2115213a780SKonrad Eisele 	unsigned long ccr;	/* 0x00 - Cache Control Register  */
2125213a780SKonrad Eisele 	unsigned long iccr;     /* 0x08 - Instruction Cache Configuration Register */
2135213a780SKonrad Eisele 	unsigned long dccr;	/* 0x0c - Data Cache Configuration Register */
2145213a780SKonrad Eisele };
2155213a780SKonrad Eisele 
216e49e6ff5SSam Ravnborg #include <linux/irq.h>
2175213a780SKonrad Eisele #include <linux/interrupt.h>
2185213a780SKonrad Eisele 
2195213a780SKonrad Eisele struct device_node;
220f0a2bc7eSThomas Gleixner struct task_struct;
221f05a6865SSam Ravnborg unsigned int leon_build_device_irq(unsigned int real_irq,
2224c6773c3SDaniel Hellstrom 				   irq_flow_handler_t flow_handler,
2234c6773c3SDaniel Hellstrom 				   const char *name, int do_ack);
224f05a6865SSam Ravnborg void leon_update_virq_handling(unsigned int virq,
2255d07b786SDaniel Hellstrom 			       irq_flow_handler_t flow_handler,
2265d07b786SDaniel Hellstrom 			       const char *name, int do_ack);
227f05a6865SSam Ravnborg void leon_init_timers(void);
228f05a6865SSam Ravnborg void leon_node_init(struct device_node *dp, struct device_node ***nextp);
229f05a6865SSam Ravnborg void init_leon(void);
230f05a6865SSam Ravnborg void poke_leonsparc(void);
231f05a6865SSam Ravnborg void leon3_getCacheRegs(struct leon3_cacheregs *regs);
2322cf95304SDaniel Hellstrom extern int leon3_ticker_irq;
2335213a780SKonrad Eisele 
2348401707fSKonrad Eisele #ifdef CONFIG_SMP
235f05a6865SSam Ravnborg int leon_smp_nrcpus(void);
236f05a6865SSam Ravnborg void leon_clear_profile_irq(int cpu);
237f05a6865SSam Ravnborg void leon_smp_done(void);
238f05a6865SSam Ravnborg void leon_boot_cpus(void);
239f05a6865SSam Ravnborg int leon_boot_one_cpu(int i, struct task_struct *);
2408401707fSKonrad Eisele void leon_init_smp(void);
2418401707fSKonrad Eisele void leon_enable_irq_cpu(unsigned int irq_nr, unsigned int cpu);
242f05a6865SSam Ravnborg irqreturn_t leon_percpu_timer_interrupt(int irq, void *unused);
2438401707fSKonrad Eisele 
2441ca0c808SDaniel Hellstrom extern unsigned int smpleon_ipi[];
24593bb32f6SSam Ravnborg extern unsigned int linux_trap_ipi15_leon[];
2461ca0c808SDaniel Hellstrom extern int leon_ipi_irq;
2478401707fSKonrad Eisele 
2488401707fSKonrad Eisele #endif /* CONFIG_SMP */
2498401707fSKonrad Eisele 
2505213a780SKonrad Eisele #endif /* __ASSEMBLY__ */
2515213a780SKonrad Eisele 
2525213a780SKonrad Eisele /* macros used in leon_mm.c */
2535213a780SKonrad Eisele #define PFN(x)           ((x) >> PAGE_SHIFT)
2545213a780SKonrad Eisele #define _pfn_valid(pfn)	 ((pfn < last_valid_pfn) && (pfn >= PFN(phys_base)))
2555213a780SKonrad Eisele #define _SRMMU_PTE_PMASK_LEON 0xffffffff
2565213a780SKonrad Eisele 
257*b535d1fcSChristoph Hellwig /*
258*b535d1fcSChristoph Hellwig  * On LEON PCI Memory space is mapped 1:1 with physical address space.
259*b535d1fcSChristoph Hellwig  *
260*b535d1fcSChristoph Hellwig  * I/O space is located at low 64Kbytes in PCI I/O space. The I/O addresses
261*b535d1fcSChristoph Hellwig  * are converted into CPU addresses to virtual addresses that are mapped with
262*b535d1fcSChristoph Hellwig  * MMU to the PCI Host PCI I/O space window which are translated to the low
263*b535d1fcSChristoph Hellwig  * 64Kbytes by the Host controller.
264*b535d1fcSChristoph Hellwig  */
265*b535d1fcSChristoph Hellwig 
2665213a780SKonrad Eisele #endif
267