xref: /titanic_41/usr/src/uts/sun4v/sys/machsystm.h (revision 66f9d5cb3cc0652e2d9d1366fb950efbe4ca2f24)
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_alloc_align(size_t, size_t);
260 extern void contig_mem_free(void *, size_t);
261 
262 /*
263  * Caches
264  */
265 extern int vac;
266 extern int cache;
267 extern int use_mp;
268 extern uint_t vac_mask;
269 extern uint64_t ecache_flushaddr;
270 extern int ecache_alignsize;	/* Maximum ecache linesize for struct align */
271 extern int ecache_setsize;	/* Maximum ecache setsize possible */
272 extern int cpu_setsize;		/* Maximum ecache setsize of configured cpus */
273 
274 /*
275  * VM
276  */
277 extern int do_pg_coloring;
278 extern int do_virtual_coloring;
279 extern int use_page_coloring;
280 extern int use_virtual_coloring;
281 extern uint_t vac_colors_mask;
282 
283 extern void ndata_alloc_init(struct memlist *, uintptr_t, uintptr_t);
284 extern void *ndata_alloc(struct memlist *, size_t, size_t);
285 extern void *ndata_extra_base(struct memlist *, size_t);
286 extern size_t ndata_maxsize(struct memlist *);
287 extern size_t ndata_spare(struct memlist *, size_t, size_t);
288 extern caddr_t get_mmfsa_scratchpad(void);
289 extern void set_mmfsa_scratchpad(caddr_t);
290 extern int ndata_alloc_mmfsa(struct memlist *);
291 extern int ndata_alloc_cpus(struct memlist *);
292 extern int ndata_alloc_page_freelists(struct memlist *, int);
293 extern int ndata_alloc_dmv(struct memlist *);
294 extern int ndata_alloc_tsbs(struct memlist *, pgcnt_t);
295 extern int ndata_alloc_hat(struct memlist *, pgcnt_t, pgcnt_t);
296 extern caddr_t alloc_page_freelists(int, caddr_t, int);
297 extern caddr_t alloc_hme_buckets(caddr_t, int);
298 extern size_t page_ctrs_sz(void);
299 extern caddr_t page_ctrs_alloc(caddr_t);
300 extern void page_freelist_coalesce_all(int);
301 extern void ppmapinit(void);
302 extern void hwblkpagecopy(const void *, void *);
303 extern void hw_pa_bcopy32(uint64_t, uint64_t);
304 
305 extern int pp_slots;
306 extern int pp_consistent_coloring;
307 
308 /*
309  * ppcopy/hwblkpagecopy interaction.  See ppage.c.
310  */
311 #define	PPAGE_STORE_VCOLORING	0x1 /* use vcolors to maintain consistency */
312 #define	PPAGE_LOAD_VCOLORING	0x2 /* use vcolors to maintain consistency */
313 #define	PPAGE_STORES_POLLUTE	0x4 /* stores pollute VAC */
314 #define	PPAGE_LOADS_POLLUTE	0x8 /* loads pollute VAC */
315 
316 /*
317  * VIS-accelerated copy/zero
318  */
319 extern int use_hw_bcopy;
320 extern uint_t hw_copy_limit_1;
321 extern uint_t hw_copy_limit_2;
322 extern uint_t hw_copy_limit_4;
323 extern uint_t hw_copy_limit_8;
324 extern int use_hw_bzero;
325 
326 #ifdef CHEETAH
327 #define	VIS_COPY_THRESHOLD 256
328 #else
329 #define	VIS_COPY_THRESHOLD 900
330 #endif
331 
332 /*
333  * MP
334  */
335 extern void idle_other_cpus(void);
336 extern void resume_other_cpus(void);
337 extern void stop_other_cpus(void);
338 extern void idle_stop_xcall(void);
339 extern void set_idle_cpu(int);
340 extern void unset_idle_cpu(int);
341 extern void mp_cpu_quiesce(struct cpu *);
342 
343 /*
344  * Panic at TL > 0
345  */
346 extern uint64_t cpu_pa[];
347 extern void ptl1_init_cpu(struct cpu *);
348 
349 /*
350  * Defines for DR interfaces
351  */
352 #define	DEVI_BRANCH_CHILD	0x01	/* Walk immediate children of root  */
353 #define	DEVI_BRANCH_CONFIGURE	0x02	/* Configure branch after create    */
354 #define	DEVI_BRANCH_DESTROY	0x04	/* Destroy branch after unconfigure */
355 #define	DEVI_BRANCH_EVENT	0x08	/* Post NDI event		    */
356 #define	DEVI_BRANCH_PROM	0x10	/* Branches derived from PROM nodes */
357 #define	DEVI_BRANCH_SID		0x20	/* SID node branches		    */
358 #define	DEVI_BRANCH_ROOT	0x40	/* Node is the root of a branch	    */
359 
360 typedef struct devi_branch {
361 	void		*arg;
362 	void		(*devi_branch_callback)(dev_info_t *, void *, uint_t);
363 	int		type;
364 	union {
365 		int	(*prom_branch_select)(pnode_t, void *, uint_t);
366 		int	(*sid_branch_create)(dev_info_t *, void *, uint_t);
367 	} create;
368 } devi_branch_t;
369 
370 
371 /*
372  * Prototypes which really belongs to sunddi.c, and should be moved to
373  * sunddi.c if there is another platform using these calls.
374  */
375 extern int e_ddi_branch_create(dev_info_t *pdip, devi_branch_t *bp,
376     dev_info_t **dipp, uint_t flags);
377 extern int e_ddi_branch_configure(dev_info_t *rdip, dev_info_t **dipp,
378     uint_t flags);
379 extern int e_ddi_branch_unconfigure(dev_info_t *rdip, dev_info_t **dipp,
380     uint_t flags);
381 extern int e_ddi_branch_destroy(dev_info_t *rdip, dev_info_t **dipp,
382     uint_t flags);
383 extern void e_ddi_branch_hold(dev_info_t *rdip);
384 extern void e_ddi_branch_rele(dev_info_t *rdip);
385 extern int e_ddi_branch_held(dev_info_t *rdip);
386 extern int e_ddi_branch_referenced(dev_info_t *rdip,
387     int (*cb)(dev_info_t *dip, void *, uint_t), void *arg);
388 
389 /*
390  * Constants which define the "hole" in the 64-bit sfmmu address space.
391  * These are set to specific values by the CPU module code.
392  */
393 extern caddr_t	hole_start, hole_end;
394 
395 /* kpm mapping window */
396 extern size_t	kpm_size;
397 extern uchar_t	kpm_size_shift;
398 extern caddr_t	kpm_vbase;
399 
400 #define	INVALID_VADDR(a)	(((a) >= hole_start && (a) < hole_end))
401 
402 extern void adjust_hw_copy_limits(int);
403 
404 struct kdi;
405 
406 void	cpu_kdi_init(struct kdi *);
407 
408 /*
409  * flush instruction and data caches
410  */
411 void	kdi_flush_caches(void);
412 
413 struct async_flt;
414 
415 /*
416  * take pending fp traps if fpq present
417  * this function is also defined in fpusystm.h
418  */
419 void	syncfpu(void);
420 
421 void	cpu_flush_ecache(void);
422 void	cpu_faulted_enter(struct cpu *);
423 void	cpu_faulted_exit(struct cpu *);
424 
425 int	cpu_get_mem_name(uint64_t synd, uint64_t *afsr, uint64_t afar,
426 	    char *buf, int buflen, int *lenp);
427 int	cpu_get_mem_info(uint64_t synd, uint64_t afar,
428 	    uint64_t *mem_sizep, uint64_t *seg_sizep, uint64_t *bank_sizep,
429 	    int *segsp, int *banksp, int *mcidp);
430 size_t	cpu_get_name_bufsize();
431 
432 /*
433  * ecache scrub operations
434  */
435 void cpu_init_cache_scrub(void);
436 
437 /*
438  * clock/tick register operations
439  */
440 void	cpu_init_tick_freq(void);
441 
442 /*
443  * stick synchronization
444  */
445 void	sticksync_slave(void);
446 void	sticksync_master(void);
447 
448 #endif /* _ASM */
449 
450 /*
451  * Actions for set_error_enable_tl1
452  */
453 #define	EER_SET_ABSOLUTE	0x0
454 #define	EER_SET_SETBITS		0x1
455 #define	EER_SET_CLRBITS		0x2
456 
457 /*
458  * HVDUMP_SIZE_MAX set as 64k due to limitiation by intrq_alloc()
459  */
460 
461 #define	HVDUMP_SIZE_MAX		0x10000
462 #define	HVDUMP_SIZE_DEFAULT	0x8000
463 
464 /*
465  * HV TOD service retry in usecs
466  */
467 
468 #define	HV_TOD_RETRY_THRESH	100
469 #define	HV_TOD_WAIT_USEC	5
470 
471 #endif /* _KERNEL */
472 
473 #ifdef __cplusplus
474 }
475 #endif
476 
477 #endif	/* _SYS_MACHSYSTM_H */
478