xref: /linux/arch/parisc/include/asm/processor.h (revision 2da68a77)
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 extern int time_keeper_id;		/* CPU used for timekeeping */
99 
100 #define CPU_HVERSION ((boot_cpu_data.hversion >> 4) & 0x0FFF)
101 
102 struct thread_struct {
103 	struct pt_regs regs;
104 	unsigned long  task_size;
105 	unsigned long  map_base;
106 	unsigned long  flags;
107 };
108 
109 #define task_pt_regs(tsk) ((struct pt_regs *)&((tsk)->thread.regs))
110 
111 /* Thread struct flags. */
112 #define PARISC_UAC_NOPRINT	(1UL << 0)	/* see prctl and unaligned.c */
113 #define PARISC_UAC_SIGBUS	(1UL << 1)
114 #define PARISC_KERNEL_DEATH	(1UL << 31)	/* see die_if_kernel()... */
115 
116 #define PARISC_UAC_SHIFT	0
117 #define PARISC_UAC_MASK		(PARISC_UAC_NOPRINT|PARISC_UAC_SIGBUS)
118 
119 #define SET_UNALIGN_CTL(task,value)                                       \
120         ({                                                                \
121         (task)->thread.flags = (((task)->thread.flags & ~PARISC_UAC_MASK) \
122                                 | (((value) << PARISC_UAC_SHIFT) &        \
123                                    PARISC_UAC_MASK));                     \
124         0;                                                                \
125         })
126 
127 #define GET_UNALIGN_CTL(task,addr)                                        \
128         ({                                                                \
129         put_user(((task)->thread.flags & PARISC_UAC_MASK)                 \
130                  >> PARISC_UAC_SHIFT, (int __user *) (addr));             \
131         })
132 
133 #define INIT_THREAD { \
134 	.regs = {	.gr	= { 0, }, \
135 			.fr	= { 0, }, \
136 			.sr	= { 0, }, \
137 			.iasq	= { 0, }, \
138 			.iaoq	= { 0, }, \
139 			.cr27	= 0, \
140 		}, \
141 	.task_size	= DEFAULT_TASK_SIZE, \
142 	.map_base	= DEFAULT_MAP_BASE, \
143 	.flags		= 0 \
144 	}
145 
146 struct task_struct;
147 void show_trace(struct task_struct *task, unsigned long *stack);
148 
149 /*
150  * Start user thread in another space.
151  *
152  * Note that we set both the iaoq and r31 to the new pc. When
153  * the kernel initially calls execve it will return through an
154  * rfi path that will use the values in the iaoq. The execve
155  * syscall path will return through the gateway page, and
156  * that uses r31 to branch to.
157  *
158  * For ELF we clear r23, because the dynamic linker uses it to pass
159  * the address of the finalizer function.
160  *
161  * We also initialize sr3 to an illegal value (illegal for our
162  * implementation, not for the architecture).
163  */
164 typedef unsigned int elf_caddr_t;
165 
166 /* The ELF abi wants things done a "wee bit" differently than
167  * som does.  Supporting this behavior here avoids
168  * having our own version of create_elf_tables.
169  *
170  * Oh, and yes, that is not a typo, we are really passing argc in r25
171  * and argv in r24 (rather than r26 and r25).  This is because that's
172  * where __libc_start_main wants them.
173  *
174  * Duplicated from dl-machine.h for the benefit of readers:
175  *
176  *  Our initial stack layout is rather different from everyone else's
177  *  due to the unique PA-RISC ABI.  As far as I know it looks like
178  *  this:
179 
180    -----------------------------------  (user startup code creates this frame)
181    |         32 bytes of magic       |
182    |---------------------------------|
183    | 32 bytes argument/sp save area  |
184    |---------------------------------| (bprm->p)
185    |	    ELF auxiliary info	     |
186    |         (up to 28 words)        |
187    |---------------------------------|
188    |		   NULL		     |
189    |---------------------------------|
190    |	   Environment pointers	     |
191    |---------------------------------|
192    |		   NULL		     |
193    |---------------------------------|
194    |        Argument pointers        |
195    |---------------------------------| <- argv
196    |          argc (1 word)          |
197    |---------------------------------| <- bprm->exec (HACK!)
198    |         N bytes of slack        |
199    |---------------------------------|
200    |	filename passed to execve    |
201    |---------------------------------| (mm->env_end)
202    |           env strings           |
203    |---------------------------------| (mm->env_start, mm->arg_end)
204    |           arg strings           |
205    |---------------------------------|
206    | additional faked arg strings if |
207    | we're invoked via binfmt_script |
208    |---------------------------------| (mm->arg_start)
209    stack base is at TASK_SIZE - rlim_max.
210 
211 on downward growing arches, it looks like this:
212    stack base at TASK_SIZE
213    | filename passed to execve
214    | env strings
215    | arg strings
216    | faked arg strings
217    | slack
218    | ELF
219    | envps
220    | argvs
221    | argc
222 
223  *  The pleasant part of this is that if we need to skip arguments we
224  *  can just decrement argc and move argv, because the stack pointer
225  *  is utterly unrelated to the location of the environment and
226  *  argument vectors.
227  *
228  * Note that the S/390 people took the easy way out and hacked their
229  * GCC to make the stack grow downwards.
230  *
231  * Final Note: For entry from syscall, the W (wide) bit of the PSW
232  * is stuffed into the lowest bit of the user sp (%r30), so we fill
233  * it in here from the current->personality
234  */
235 
236 #define USER_WIDE_MODE	(!is_32bit_task())
237 
238 #define start_thread(regs, new_pc, new_sp) do {		\
239 	elf_addr_t *sp = (elf_addr_t *)new_sp;		\
240 	__u32 spaceid = (__u32)current->mm->context.space_id;	\
241 	elf_addr_t pc = (elf_addr_t)new_pc | 3;		\
242 	elf_caddr_t *argv = (elf_caddr_t *)bprm->exec + 1;	\
243 							\
244 	regs->iasq[0] = spaceid;			\
245 	regs->iasq[1] = spaceid;			\
246 	regs->iaoq[0] = pc;				\
247 	regs->iaoq[1] = pc + 4;                         \
248 	regs->sr[2] = LINUX_GATEWAY_SPACE;              \
249 	regs->sr[3] = 0xffff;				\
250 	regs->sr[4] = spaceid;				\
251 	regs->sr[5] = spaceid;				\
252 	regs->sr[6] = spaceid;				\
253 	regs->sr[7] = spaceid;				\
254 	regs->gr[ 0] = USER_PSW | (USER_WIDE_MODE ? PSW_W : 0); \
255 	regs->fr[ 0] = 0LL;                            	\
256 	regs->fr[ 1] = 0LL;                            	\
257 	regs->fr[ 2] = 0LL;                            	\
258 	regs->fr[ 3] = 0LL;                            	\
259 	regs->gr[30] = (((unsigned long)sp + 63) &~ 63) | (USER_WIDE_MODE ? 1 : 0); \
260 	regs->gr[31] = pc;				\
261 							\
262 	get_user(regs->gr[25], (argv - 1));		\
263 	regs->gr[24] = (long) argv;			\
264 	regs->gr[23] = 0;				\
265 } while(0)
266 
267 struct mm_struct;
268 
269 extern unsigned long __get_wchan(struct task_struct *p);
270 
271 #define KSTK_EIP(tsk)	((tsk)->thread.regs.iaoq[0])
272 #define KSTK_ESP(tsk)	((tsk)->thread.regs.gr[30])
273 
274 #define cpu_relax()	barrier()
275 
276 /*
277  * parisc_requires_coherency() is used to identify the combined VIPT/PIPT
278  * cached CPUs which require a guarantee of coherency (no inequivalent aliases
279  * with different data, whether clean or not) to operate
280  */
281 #ifdef CONFIG_PA8X00
282 extern int _parisc_requires_coherency;
283 #define parisc_requires_coherency()	_parisc_requires_coherency
284 #else
285 #define parisc_requires_coherency()	(0)
286 #endif
287 
288 extern int running_on_qemu;
289 
290 extern void __noreturn toc_intr(struct pt_regs *regs);
291 extern void toc_handler(void);
292 extern unsigned int toc_handler_size;
293 extern unsigned int toc_handler_csum;
294 
295 #endif /* __ASSEMBLY__ */
296 
297 #endif /* __ASM_PARISC_PROCESSOR_H */
298