xref: /titanic_44/usr/src/uts/sun4v/sys/machsystm.h (revision 8eea8e29cc4374d1ee24c25a07f45af132db3499)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _SYS_MACHSYSTM_H
28 #define	_SYS_MACHSYSTM_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 /*
33  * Numerous platform-dependent interfaces that don't seem to belong
34  * in any other header file.
35  *
36  * This file should not be included by code that purports to be
37  * platform-independent.
38  */
39 
40 #ifndef _ASM
41 #include <sys/types.h>
42 #include <sys/scb.h>
43 #include <sys/varargs.h>
44 #include <sys/machparam.h>
45 #include <sys/thread.h>
46 #include <vm/seg_enum.h>
47 #include <sys/processor.h>
48 #include <sys/sunddi.h>
49 #include <sys/memlist.h>
50 #endif /* _ASM */
51 
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55 
56 #ifdef _KERNEL
57 
58 #ifndef _ASM
59 /*
60  * The following enum types determine how interrupts are distributed
61  * on a sun4u system.
62  */
63 enum intr_policies {
64 	/*
65 	 * Target interrupt at the CPU running the add_intrspec
66 	 * thread. Also used to target all interrupts at the panicing
67 	 * CPU.
68 	 */
69 	INTR_CURRENT_CPU = 0,
70 
71 	/*
72 	 * Target all interrupts at the boot cpu
73 	 */
74 	INTR_BOOT_CPU,
75 
76 	/*
77 	 * Flat distribution of all interrupts
78 	 */
79 	INTR_FLAT_DIST,
80 
81 	/*
82 	 * Weighted distribution of all interrupts
83 	 */
84 	INTR_WEIGHTED_DIST
85 };
86 
87 
88 /*
89  * Structure that defines the interrupt distribution list. It contains
90  * enough info about the interrupt so that it can callback the parent
91  * nexus driver and retarget the interrupt to a different CPU.
92  */
93 struct intr_dist {
94 	struct intr_dist *next;	/* link to next in list */
95 	void (*func)(void *);	/* Callback function */
96 	void *arg;		/* Nexus parent callback arg 1 */
97 };
98 
99 /*
100  * Miscellaneous cpu_state changes
101  */
102 extern void power_down(const char *);
103 extern void do_shutdown(void);
104 
105 /*
106  * Number of seconds until power is shut off
107  */
108 extern int thermal_powerdown_delay;
109 
110 
111 /*
112  * prom-related
113  */
114 extern int obpdebug;
115 extern int forthdebug_supported;
116 extern uint_t tba_taken_over;
117 extern void forthdebug_init(void);
118 extern void init_vx_handler(void);
119 extern void kern_preprom(void);
120 extern void kern_postprom(void);
121 
122 /*
123  * externally (debugger or prom) initiated panic
124  */
125 extern struct regs sync_reg_buf;
126 extern uint64_t sync_tt;
127 extern void sync_handler(void);
128 
129 /*
130  * Trap-related
131  */
132 struct regs;
133 extern void trap(struct regs *rp, caddr_t addr, uint32_t type,
134     uint32_t mmu_fsr);
135 extern void *get_tba(void);
136 extern void *set_tba(void *);
137 extern caddr_t set_trap_table(void);
138 extern struct scb trap_table;
139 
140 struct trap_info {
141 	struct regs *trap_regs;
142 	uint_t	trap_type;
143 	caddr_t trap_addr;
144 	uint_t	trap_mmu_fsr;
145 };
146 
147 /*
148  * misc. primitives
149  */
150 #define	PROM_CFGHDL_TO_CPUID(x)	 (x  & ~(0xful << 28))
151 
152 extern void debug_flush_windows(void);
153 extern void flush_windows(void);
154 extern int getprocessorid(void);
155 extern void reestablish_curthread(void);
156 
157 extern void stphys(uint64_t physaddr, int value);
158 extern int ldphys(uint64_t physaddr);
159 extern void stdphys(uint64_t physaddr, uint64_t value);
160 extern uint64_t lddphys(uint64_t physaddr);
161 
162 extern void stphysio(u_longlong_t physaddr, uint_t value);
163 extern uint_t ldphysio(u_longlong_t physaddr);
164 extern void sthphysio(u_longlong_t physaddr, ushort_t value);
165 extern ushort_t ldhphysio(u_longlong_t physaddr);
166 extern void stbphysio(u_longlong_t physaddr, uchar_t value);
167 extern uchar_t ldbphysio(u_longlong_t physaddr);
168 extern void stdphysio(u_longlong_t physaddr, u_longlong_t value);
169 extern u_longlong_t lddphysio(u_longlong_t physaddr);
170 
171 extern int pf_is_dmacapable(pfn_t);
172 
173 extern int dip_to_cpu_id(dev_info_t *dip, processorid_t *cpu_id);
174 
175 extern void set_cmp_error_steering(void);
176 
177 /*
178  * SPARCv9 %ver register and field definitions
179  */
180 
181 #define	ULTRA_VER_MANUF(x)	((x) >> 48)
182 #define	ULTRA_VER_IMPL(x)	(((x) >> 32) & 0xFFFF)
183 #define	ULTRA_VER_MASK(x)	(((x) >> 24) & 0xFF)
184 
185 extern uint64_t ultra_getver(void);
186 
187 /*
188  * bootup-time
189  */
190 extern int ncpunode;
191 extern int niobus;
192 
193 extern void segnf_init(void);
194 extern void kern_setup1(void);
195 extern void startup(void);
196 extern void post_startup(void);
197 extern void install_va_to_tte(void);
198 extern void setwstate(uint_t);
199 extern void create_va_to_tte(void);
200 extern int memscrub_init(void);
201 
202 extern void kcpc_hw_init(void);
203 extern void kcpc_hw_startup_cpu(ushort_t);
204 extern int kcpc_hw_load_pcbe(void);
205 
206 /*
207  * Interrupts
208  */
209 struct cpu;
210 extern struct cpu cpu0;
211 extern size_t intr_add_pools;
212 extern struct intr_req *intr_add_head;
213 extern struct intr_req *intr_add_tail;
214 extern struct scb *set_tbr(struct scb *);
215 
216 extern void init_intr_threads(struct cpu *);
217 extern uint_t disable_vec_intr(void);
218 extern void enable_vec_intr(uint_t);
219 extern void setintrenable(int);
220 
221 extern void intr_dist_add(void (*f)(void *), void *);
222 extern void intr_dist_rem(void (*f)(void *), void *);
223 extern void intr_dist_add_weighted(void (*f)(void *, int32_t, int32_t), void *);
224 extern void intr_dist_rem_weighted(void (*f)(void *, int32_t, int32_t), void *);
225 
226 extern uint32_t intr_dist_cpuid(void);
227 extern uint32_t intr_dist_mycpuid(void);
228 
229 void intr_dist_cpuid_add_device_weight(uint32_t cpuid, dev_info_t *dip,
230 		int32_t weight);
231 void intr_dist_cpuid_rem_device_weight(uint32_t cpuid, dev_info_t *dip);
232 
233 extern void intr_redist_all_cpus(void);
234 extern void intr_redist_all_cpus_shutdown(void);
235 
236 extern void send_dirint(int, int);
237 extern void setsoftint(uint_t);
238 extern void setsoftint_tl1(uint64_t, uint64_t);
239 extern void siron(void);
240 extern void intr_enqueue_req(uint_t pil, uint32_t inum);
241 extern void intr_dequeue_req(uint_t pil, uint32_t inum);
242 extern void wr_clr_softint(uint_t);
243 
244 /*
245  * Time- and %tick-related
246  */
247 extern hrtime_t rdtick(void);
248 extern void tick_write_delta(uint64_t);
249 extern void tickcmpr_set(uint64_t);
250 extern void tickcmpr_reset(void);
251 extern void tickcmpr_disable(void);
252 extern int tickcmpr_disabled(void);
253 extern uint32_t cbe_level14_inum;
254 
255 /*
256  * contiguous memory
257  */
258 extern void *contig_mem_alloc(size_t);
259 extern void contig_mem_free(void *, size_t);
260 
261 /*
262  * Caches
263  */
264 extern int vac;
265 extern int cache;
266 extern int use_mp;
267 extern uint_t vac_mask;
268 extern uint64_t ecache_flushaddr;
269 extern int ecache_alignsize;	/* Maximum ecache linesize for struct align */
270 extern int ecache_setsize;	/* Maximum ecache setsize possible */
271 extern int cpu_setsize;		/* Maximum ecache setsize of configured cpus */
272 
273 /*
274  * VM
275  */
276 extern int do_pg_coloring;
277 extern int do_virtual_coloring;
278 extern int use_page_coloring;
279 extern int use_virtual_coloring;
280 extern uint_t vac_colors_mask;
281 
282 extern void ndata_alloc_init(struct memlist *, uintptr_t, uintptr_t);
283 extern void *ndata_alloc(struct memlist *, size_t, size_t);
284 extern void *ndata_extra_base(struct memlist *, size_t);
285 extern size_t ndata_maxsize(struct memlist *);
286 extern size_t ndata_spare(struct memlist *, size_t, size_t);
287 extern caddr_t get_mmfsa_scratchpad(void);
288 extern void set_mmfsa_scratchpad(caddr_t);
289 extern int ndata_alloc_mmfsa(struct memlist *);
290 extern int ndata_alloc_cpus(struct memlist *);
291 extern int ndata_alloc_page_freelists(struct memlist *, int);
292 extern int ndata_alloc_dmv(struct memlist *);
293 extern int ndata_alloc_tsbs(struct memlist *, pgcnt_t);
294 extern int ndata_alloc_hat(struct memlist *, pgcnt_t, pgcnt_t);
295 extern caddr_t alloc_page_freelists(int, caddr_t, int);
296 extern caddr_t alloc_hme_buckets(caddr_t, int);
297 extern size_t page_ctrs_sz(void);
298 extern caddr_t page_ctrs_alloc(caddr_t);
299 extern void page_freelist_coalesce_all(int);
300 extern void ppmapinit(void);
301 extern void hwblkpagecopy(const void *, void *);
302 extern void hw_pa_bcopy32(uint64_t, uint64_t);
303 
304 extern int pp_slots;
305 extern int pp_consistent_coloring;
306 
307 /*
308  * ppcopy/hwblkpagecopy interaction.  See ppage.c.
309  */
310 #define	PPAGE_STORE_VCOLORING	0x1 /* use vcolors to maintain consistency */
311 #define	PPAGE_LOAD_VCOLORING	0x2 /* use vcolors to maintain consistency */
312 #define	PPAGE_STORES_POLLUTE	0x4 /* stores pollute VAC */
313 #define	PPAGE_LOADS_POLLUTE	0x8 /* loads pollute VAC */
314 
315 /*
316  * VIS-accelerated copy/zero
317  */
318 extern int use_hw_bcopy;
319 extern uint_t hw_copy_limit_1;
320 extern uint_t hw_copy_limit_2;
321 extern uint_t hw_copy_limit_4;
322 extern uint_t hw_copy_limit_8;
323 extern int use_hw_bzero;
324 
325 #ifdef CHEETAH
326 #define	VIS_COPY_THRESHOLD 256
327 #else
328 #define	VIS_COPY_THRESHOLD 900
329 #endif
330 
331 /*
332  * MP
333  */
334 extern void idle_other_cpus(void);
335 extern void resume_other_cpus(void);
336 extern void stop_other_cpus(void);
337 extern void idle_stop_xcall(void);
338 extern void set_idle_cpu(int);
339 extern void unset_idle_cpu(int);
340 extern void mp_cpu_quiesce(struct cpu *);
341 
342 /*
343  * Panic at TL > 0
344  */
345 extern uint64_t cpu_pa[];
346 extern void ptl1_init_cpu(struct cpu *);
347 
348 /*
349  * Defines for DR interfaces
350  */
351 #define	DEVI_BRANCH_CHILD	0x01	/* Walk immediate children of root  */
352 #define	DEVI_BRANCH_CONFIGURE	0x02	/* Configure branch after create    */
353 #define	DEVI_BRANCH_DESTROY	0x04	/* Destroy branch after unconfigure */
354 #define	DEVI_BRANCH_EVENT	0x08	/* Post NDI event		    */
355 #define	DEVI_BRANCH_PROM	0x10	/* Branches derived from PROM nodes */
356 #define	DEVI_BRANCH_SID		0x20	/* SID node branches		    */
357 #define	DEVI_BRANCH_ROOT	0x40	/* Node is the root of a branch	    */
358 
359 typedef struct devi_branch {
360 	void		*arg;
361 	void		(*devi_branch_callback)(dev_info_t *, void *, uint_t);
362 	int		type;
363 	union {
364 		int	(*prom_branch_select)(dnode_t, void *, uint_t);
365 		int	(*sid_branch_create)(dev_info_t *, void *, uint_t);
366 	} create;
367 } devi_branch_t;
368 
369 
370 /*
371  * Prototypes which really belongs to sunddi.c, and should be moved to
372  * sunddi.c if there is another platform using these calls.
373  */
374 extern int e_ddi_branch_create(dev_info_t *pdip, devi_branch_t *bp,
375     dev_info_t **dipp, uint_t flags);
376 extern int e_ddi_branch_configure(dev_info_t *rdip, dev_info_t **dipp,
377     uint_t flags);
378 extern int e_ddi_branch_unconfigure(dev_info_t *rdip, dev_info_t **dipp,
379     uint_t flags);
380 extern int e_ddi_branch_destroy(dev_info_t *rdip, dev_info_t **dipp,
381     uint_t flags);
382 extern void e_ddi_branch_hold(dev_info_t *rdip);
383 extern void e_ddi_branch_rele(dev_info_t *rdip);
384 extern int e_ddi_branch_held(dev_info_t *rdip);
385 extern int e_ddi_branch_referenced(dev_info_t *rdip,
386     int (*cb)(dev_info_t *dip, void *, uint_t), void *arg);
387 
388 /*
389  * Constants which define the "hole" in the 64-bit sfmmu address space.
390  * These are set to specific values by the CPU module code.
391  */
392 extern caddr_t	hole_start, hole_end;
393 
394 /* kpm mapping window */
395 extern size_t	kpm_size;
396 extern uchar_t	kpm_size_shift;
397 extern caddr_t	kpm_vbase;
398 
399 #define	INVALID_VADDR(a)	(((a) >= hole_start && (a) < hole_end))
400 
401 extern void adjust_hw_copy_limits(int);
402 
403 struct kdi;
404 
405 void	cpu_kdi_init(struct kdi *);
406 
407 /*
408  * flush instruction and data caches
409  */
410 void	kdi_flush_caches(void);
411 
412 struct async_flt;
413 
414 /*
415  * take pending fp traps if fpq present
416  * this function is also defined in fpusystm.h
417  */
418 void	syncfpu(void);
419 
420 void	cpu_flush_ecache(void);
421 void	cpu_faulted_enter(struct cpu *);
422 void	cpu_faulted_exit(struct cpu *);
423 
424 int	cpu_get_mem_name(uint64_t synd, uint64_t *afsr, uint64_t afar,
425 	    char *buf, int buflen, int *lenp);
426 int	cpu_get_mem_info(uint64_t synd, uint64_t afar,
427 	    uint64_t *mem_sizep, uint64_t *seg_sizep, uint64_t *bank_sizep,
428 	    int *segsp, int *banksp, int *mcidp);
429 size_t	cpu_get_name_bufsize();
430 
431 /*
432  * ecache scrub operations
433  */
434 void cpu_init_cache_scrub(void);
435 
436 /*
437  * clock/tick register operations
438  */
439 void	cpu_init_tick_freq(void);
440 
441 /*
442  * stick synchronization
443  */
444 void	sticksync_slave(void);
445 void	sticksync_master(void);
446 
447 #endif /* _ASM */
448 
449 /*
450  * Actions for set_error_enable_tl1
451  */
452 #define	EER_SET_ABSOLUTE	0x0
453 #define	EER_SET_SETBITS		0x1
454 #define	EER_SET_CLRBITS		0x2
455 
456 /*
457  * HVDUMP_SIZE_MAX set as 64k due to limitiation by intrq_alloc()
458  */
459 
460 #define	HVDUMP_SIZE_MAX		0x10000
461 #define	HVDUMP_SIZE_DEFAULT	0x8000
462 
463 /*
464  * HV TOD service retry in usecs
465  */
466 
467 #define	HV_TOD_RETRY_THRESH	100
468 #define	HV_TOD_WAIT_USEC	5
469 
470 #endif /* _KERNEL */
471 
472 #ifdef __cplusplus
473 }
474 #endif
475 
476 #endif	/* _SYS_MACHSYSTM_H */
477