1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * include/asm-parisc/processor.h
4  *
5  * Copyright (C) 1994 Linus Torvalds
6  * Copyright (C) 2001 Grant Grundler
7  */
8 
9 #ifndef __ASM_PARISC_PROCESSOR_H
10 #define __ASM_PARISC_PROCESSOR_H
11 
12 #ifndef __ASSEMBLY__
13 #include <linux/threads.h>
14 
15 #include <asm/assembly.h>
16 #include <asm/prefetch.h>
17 #include <asm/hardware.h>
18 #include <asm/pdc.h>
19 #include <asm/ptrace.h>
20 #include <asm/types.h>
21 #include <asm/percpu.h>
22 #endif /* __ASSEMBLY__ */
23 
24 #define HAVE_ARCH_PICK_MMAP_LAYOUT
25 
26 #define TASK_SIZE_OF(tsk)       ((tsk)->thread.task_size)
27 #define TASK_SIZE	        TASK_SIZE_OF(current)
28 #define TASK_UNMAPPED_BASE      (current->thread.map_base)
29 
30 #define DEFAULT_TASK_SIZE32	(0xFFF00000UL)
31 #define DEFAULT_MAP_BASE32	(0x40000000UL)
32 
33 #ifdef CONFIG_64BIT
34 #define DEFAULT_TASK_SIZE       (MAX_ADDRESS-0xf000000)
35 #define DEFAULT_MAP_BASE        (0x200000000UL)
36 #else
37 #define DEFAULT_TASK_SIZE	DEFAULT_TASK_SIZE32
38 #define DEFAULT_MAP_BASE	DEFAULT_MAP_BASE32
39 #endif
40 
41 /* XXX: STACK_TOP actually should be STACK_BOTTOM for parisc.
42  * prumpf */
43 
44 #define STACK_TOP	TASK_SIZE
45 #define STACK_TOP_MAX	DEFAULT_TASK_SIZE
46 
47 #ifndef __ASSEMBLY__
48 
49 unsigned long calc_max_stack_size(unsigned long stack_max);
50 
51 /*
52  * Data detected about CPUs at boot time which is the same for all CPU's.
53  * HP boxes are SMP - ie identical processors.
54  *
55  * FIXME: some CPU rev info may be processor specific...
56  */
57 struct system_cpuinfo_parisc {
58 	unsigned int	cpu_count;
59 	unsigned int	cpu_hz;
60 	unsigned int	hversion;
61 	unsigned int	sversion;
62 	enum cpu_type	cpu_type;
63 
64 	struct {
65 		struct pdc_model model;
66 		unsigned long versions;
67 		unsigned long cpuid;
68 		unsigned long capabilities;
69 		char   sys_model_name[81]; /* PDC-ROM returnes this model name */
70 	} pdc;
71 
72 	const char	*cpu_name;	/* e.g. "PA7300LC (PCX-L2)" */
73 	const char	*family_name;	/* e.g. "1.1e" */
74 };
75 
76 
77 /* Per CPU data structure - ie varies per CPU.  */
78 struct cpuinfo_parisc {
79 	unsigned long it_value;     /* Interval Timer at last timer Intr */
80 	unsigned long irq_count;    /* number of IRQ's since boot */
81 	unsigned long cpuid;        /* aka slot_number or set to NO_PROC_ID */
82 	unsigned long hpa;          /* Host Physical address */
83 	unsigned long txn_addr;     /* MMIO addr of EIR or id_eid */
84 #ifdef CONFIG_SMP
85 	unsigned long pending_ipi;  /* bitmap of type ipi_message_type */
86 #endif
87 	unsigned long bh_count;     /* number of times bh was invoked */
88 	unsigned long fp_rev;
89 	unsigned long fp_model;
90 	unsigned long cpu_num;      /* CPU number from PAT firmware */
91 	unsigned long cpu_loc;      /* CPU location from PAT firmware */
92 	unsigned int state;
93 	struct parisc_device *dev;
94 };
95 
96 extern struct system_cpuinfo_parisc boot_cpu_data;
97 DECLARE_PER_CPU(struct cpuinfo_parisc, cpu_data);
98 
99 #define CPU_HVERSION ((boot_cpu_data.hversion >> 4) & 0x0FFF)
100 
101 struct thread_struct {
102 	struct pt_regs regs;
103 	unsigned long  task_size;
104 	unsigned long  map_base;
105 	unsigned long  flags;
106 };
107 
108 #define task_pt_regs(tsk) ((struct pt_regs *)&((tsk)->thread.regs))
109 
110 /* Thread struct flags. */
111 #define PARISC_UAC_NOPRINT	(1UL << 0)	/* see prctl and unaligned.c */
112 #define PARISC_UAC_SIGBUS	(1UL << 1)
113 #define PARISC_KERNEL_DEATH	(1UL << 31)	/* see die_if_kernel()... */
114 
115 #define PARISC_UAC_SHIFT	0
116 #define PARISC_UAC_MASK		(PARISC_UAC_NOPRINT|PARISC_UAC_SIGBUS)
117 
118 #define SET_UNALIGN_CTL(task,value)                                       \
119         ({                                                                \
120         (task)->thread.flags = (((task)->thread.flags & ~PARISC_UAC_MASK) \
121                                 | (((value) << PARISC_UAC_SHIFT) &        \
122                                    PARISC_UAC_MASK));                     \
123         0;                                                                \
124         })
125 
126 #define GET_UNALIGN_CTL(task,addr)                                        \
127         ({                                                                \
128         put_user(((task)->thread.flags & PARISC_UAC_MASK)                 \
129                  >> PARISC_UAC_SHIFT, (int __user *) (addr));             \
130         })
131 
132 #define INIT_THREAD { \
133 	.regs = {	.gr	= { 0, }, \
134 			.fr	= { 0, }, \
135 			.sr	= { 0, }, \
136 			.iasq	= { 0, }, \
137 			.iaoq	= { 0, }, \
138 			.cr27	= 0, \
139 		}, \
140 	.task_size	= DEFAULT_TASK_SIZE, \
141 	.map_base	= DEFAULT_MAP_BASE, \
142 	.flags		= 0 \
143 	}
144 
145 struct task_struct;
146 void show_trace(struct task_struct *task, unsigned long *stack);
147 
148 /*
149  * Start user thread in another space.
150  *
151  * Note that we set both the iaoq and r31 to the new pc. When
152  * the kernel initially calls execve it will return through an
153  * rfi path that will use the values in the iaoq. The execve
154  * syscall path will return through the gateway page, and
155  * that uses r31 to branch to.
156  *
157  * For ELF we clear r23, because the dynamic linker uses it to pass
158  * the address of the finalizer function.
159  *
160  * We also initialize sr3 to an illegal value (illegal for our
161  * implementation, not for the architecture).
162  */
163 typedef unsigned int elf_caddr_t;
164 
165 /* The ELF abi wants things done a "wee bit" differently than
166  * som does.  Supporting this behavior here avoids
167  * having our own version of create_elf_tables.
168  *
169  * Oh, and yes, that is not a typo, we are really passing argc in r25
170  * and argv in r24 (rather than r26 and r25).  This is because that's
171  * where __libc_start_main wants them.
172  *
173  * Duplicated from dl-machine.h for the benefit of readers:
174  *
175  *  Our initial stack layout is rather different from everyone else's
176  *  due to the unique PA-RISC ABI.  As far as I know it looks like
177  *  this:
178 
179    -----------------------------------  (user startup code creates this frame)
180    |         32 bytes of magic       |
181    |---------------------------------|
182    | 32 bytes argument/sp save area  |
183    |---------------------------------| (bprm->p)
184    |	    ELF auxiliary info	     |
185    |         (up to 28 words)        |
186    |---------------------------------|
187    |		   NULL		     |
188    |---------------------------------|
189    |	   Environment pointers	     |
190    |---------------------------------|
191    |		   NULL		     |
192    |---------------------------------|
193    |        Argument pointers        |
194    |---------------------------------| <- argv
195    |          argc (1 word)          |
196    |---------------------------------| <- bprm->exec (HACK!)
197    |         N bytes of slack        |
198    |---------------------------------|
199    |	filename passed to execve    |
200    |---------------------------------| (mm->env_end)
201    |           env strings           |
202    |---------------------------------| (mm->env_start, mm->arg_end)
203    |           arg strings           |
204    |---------------------------------|
205    | additional faked arg strings if |
206    | we're invoked via binfmt_script |
207    |---------------------------------| (mm->arg_start)
208    stack base is at TASK_SIZE - rlim_max.
209 
210 on downward growing arches, it looks like this:
211    stack base at TASK_SIZE
212    | filename passed to execve
213    | env strings
214    | arg strings
215    | faked arg strings
216    | slack
217    | ELF
218    | envps
219    | argvs
220    | argc
221 
222  *  The pleasant part of this is that if we need to skip arguments we
223  *  can just decrement argc and move argv, because the stack pointer
224  *  is utterly unrelated to the location of the environment and
225  *  argument vectors.
226  *
227  * Note that the S/390 people took the easy way out and hacked their
228  * GCC to make the stack grow downwards.
229  *
230  * Final Note: For entry from syscall, the W (wide) bit of the PSW
231  * is stuffed into the lowest bit of the user sp (%r30), so we fill
232  * it in here from the current->personality
233  */
234 
235 #define USER_WIDE_MODE	(!is_32bit_task())
236 
237 #define start_thread(regs, new_pc, new_sp) do {		\
238 	elf_addr_t *sp = (elf_addr_t *)new_sp;		\
239 	__u32 spaceid = (__u32)current->mm->context;	\
240 	elf_addr_t pc = (elf_addr_t)new_pc | 3;		\
241 	elf_caddr_t *argv = (elf_caddr_t *)bprm->exec + 1;	\
242 							\
243 	regs->iasq[0] = spaceid;			\
244 	regs->iasq[1] = spaceid;			\
245 	regs->iaoq[0] = pc;				\
246 	regs->iaoq[1] = pc + 4;                         \
247 	regs->sr[2] = LINUX_GATEWAY_SPACE;              \
248 	regs->sr[3] = 0xffff;				\
249 	regs->sr[4] = spaceid;				\
250 	regs->sr[5] = spaceid;				\
251 	regs->sr[6] = spaceid;				\
252 	regs->sr[7] = spaceid;				\
253 	regs->gr[ 0] = USER_PSW | (USER_WIDE_MODE ? PSW_W : 0); \
254 	regs->fr[ 0] = 0LL;                            	\
255 	regs->fr[ 1] = 0LL;                            	\
256 	regs->fr[ 2] = 0LL;                            	\
257 	regs->fr[ 3] = 0LL;                            	\
258 	regs->gr[30] = (((unsigned long)sp + 63) &~ 63) | (USER_WIDE_MODE ? 1 : 0); \
259 	regs->gr[31] = pc;				\
260 							\
261 	get_user(regs->gr[25], (argv - 1));		\
262 	regs->gr[24] = (long) argv;			\
263 	regs->gr[23] = 0;				\
264 } while(0)
265 
266 struct mm_struct;
267 
268 /* Free all resources held by a thread. */
269 extern void release_thread(struct task_struct *);
270 
271 extern unsigned long __get_wchan(struct task_struct *p);
272 
273 #define KSTK_EIP(tsk)	((tsk)->thread.regs.iaoq[0])
274 #define KSTK_ESP(tsk)	((tsk)->thread.regs.gr[30])
275 
276 #define cpu_relax()	barrier()
277 
278 /*
279  * parisc_requires_coherency() is used to identify the combined VIPT/PIPT
280  * cached CPUs which require a guarantee of coherency (no inequivalent aliases
281  * with different data, whether clean or not) to operate
282  */
283 #ifdef CONFIG_PA8X00
284 extern int _parisc_requires_coherency;
285 #define parisc_requires_coherency()	_parisc_requires_coherency
286 #else
287 #define parisc_requires_coherency()	(0)
288 #endif
289 
290 extern int running_on_qemu;
291 
292 extern void __noreturn toc_intr(struct pt_regs *regs);
293 extern void toc_handler(void);
294 extern unsigned int toc_handler_size;
295 extern unsigned int toc_handler_csum;
296 
297 #endif /* __ASSEMBLY__ */
298 
299 #endif /* __ASM_PARISC_PROCESSOR_H */
300