xref: /titanic_44/usr/src/uts/sun4v/ml/hcall.s (revision ffbafc5382b8d46def826aec8c419ad31dff8ebd)
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 (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21/*
22 * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23 * Use is subject to license terms.
24 */
25
26#pragma ident	"%Z%%M%	%I%	%E% SMI"
27
28/*
29 * Hypervisor calls
30 */
31
32#include <sys/asm_linkage.h>
33#include <sys/machasi.h>
34#include <sys/machparam.h>
35#include <sys/hypervisor_api.h>
36
37#if defined(lint) || defined(__lint)
38
39/*ARGSUSED*/
40int64_t
41hv_cnputchar(uint8_t ch)
42{ return (0); }
43
44/*ARGSUSED*/
45int64_t
46hv_cngetchar(uint8_t *ch)
47{ return (0); }
48
49/*ARGSUSED*/
50uint64_t
51hv_tod_get(uint64_t *seconds)
52{ return (0); }
53
54/*ARGSUSED*/
55uint64_t
56hv_tod_set(uint64_t seconds)
57{ return (0);}
58
59/*ARGSUSED*/
60uint64_t
61hv_mmu_map_perm_addr(void *vaddr, int ctx, uint64_t tte, int flags)
62{ return (0); }
63
64/*ARGSUSED*/
65uint64_t
66hv_mmu_unmap_perm_addr(void *vaddr, int ctx, int flags)
67{ return (0); }
68
69/*ARGSUSED*/
70uint64_t
71hv_set_ctx0(uint64_t ntsb_descriptor, uint64_t desc_ra)
72{ return (0); }
73
74/*ARGSUSED*/
75uint64_t
76hv_set_ctxnon0(uint64_t ntsb_descriptor, uint64_t desc_ra)
77{ return (0); }
78
79#ifdef SET_MMU_STATS
80/*ARGSUSED*/
81uint64_t
82hv_mmu_set_stat_area(uint64_t rstatarea, uint64_t size)
83{ return (0); }
84#endif /* SET_MMU_STATS */
85
86/*ARGSUSED*/
87uint64_t
88hv_cpu_qconf(int queue, uint64_t paddr, int size)
89{ return (0); }
90
91/*ARGSUSED*/
92uint64_t
93hvio_intr_devino_to_sysino(uint64_t dev_hdl, uint32_t devino, uint64_t *sysino)
94{ return (0); }
95
96/*ARGSUSED*/
97uint64_t
98hvio_intr_getvalid(uint64_t sysino, int *intr_valid_state)
99{ return (0); }
100
101/*ARGSUSED*/
102uint64_t
103hvio_intr_setvalid(uint64_t sysino, int intr_valid_state)
104{ return (0); }
105
106/*ARGSUSED*/
107uint64_t
108hvio_intr_getstate(uint64_t sysino, int *intr_state)
109{ return (0); }
110
111/*ARGSUSED*/
112uint64_t
113hvio_intr_setstate(uint64_t sysino, int intr_state)
114{ return (0); }
115
116/*ARGSUSED*/
117uint64_t
118hvio_intr_gettarget(uint64_t sysino, uint32_t *cpuid)
119{ return (0); }
120
121/*ARGSUSED*/
122uint64_t
123hvio_intr_settarget(uint64_t sysino, uint32_t cpuid)
124{ return (0); }
125
126uint64_t
127hv_cpu_yield(void)
128{ return (0); }
129
130/*ARGSUSED*/
131uint64_t
132hv_service_recv(uint64_t s_id, uint64_t buf_pa, uint64_t size,
133    uint64_t *recv_bytes)
134{ return (0); }
135
136/*ARGSUSED*/
137uint64_t
138hv_service_send(uint64_t s_id, uint64_t buf_pa, uint64_t size,
139    uint64_t *send_bytes)
140{ return (0); }
141
142/*ARGSUSED*/
143uint64_t
144hv_service_getstatus(uint64_t s_id, uint64_t *vreg)
145{ return (0); }
146
147/*ARGSUSED*/
148uint64_t
149hv_service_setstatus(uint64_t s_id, uint64_t bits)
150{ return (0); }
151
152/*ARGSUSED*/
153uint64_t
154hv_service_clrstatus(uint64_t s_id, uint64_t bits)
155{ return (0); }
156
157/*ARGSUSED*/
158uint64_t
159hv_cpu_state(uint64_t cpuid, uint64_t *cpu_state)
160{ return (0); }
161
162/*ARGSUSED*/
163uint64_t
164hv_dump_buf_update(uint64_t paddr, uint64_t size, uint64_t *minsize)
165{ return (0); }
166
167/*ARGSUSED*/
168uint64_t
169hv_mem_scrub(uint64_t real_addr, uint64_t length, uint64_t *scrubbed_len)
170{ return (0); }
171
172/*ARGSUSED*/
173uint64_t
174hv_mem_sync(uint64_t real_addr, uint64_t length, uint64_t *flushed_len)
175{ return (0); }
176
177/*ARGSUSED*/
178uint64_t
179hv_ttrace_buf_conf(uint64_t paddr, uint64_t size, uint64_t *size1)
180{ return (0); }
181
182/*ARGSUSED*/
183uint64_t
184hv_ttrace_buf_info(uint64_t *paddr, uint64_t *size)
185{ return (0); }
186
187/*ARGSUSED*/
188uint64_t
189hv_ttrace_enable(uint64_t enable, uint64_t *prev_enable)
190{ return (0); }
191
192/*ARGSUSED*/
193uint64_t
194hv_ttrace_freeze(uint64_t freeze, uint64_t *prev_freeze)
195{ return (0); }
196
197/*ARGSUSED*/
198uint64_t
199hv_mach_desc(uint64_t buffer_ra, uint64_t *buffer_sizep)
200{ return (0); }
201
202/*ARGSUSED*/
203uint64_t
204hv_ncs_request(int cmd, uint64_t realaddr, size_t sz)
205{ return (0); }
206
207/*ARGSUSED*/
208uint64_t
209hv_ra2pa(uint64_t ra)
210{ return (0); }
211
212/*ARGSUSED*/
213uint64_t
214hv_hpriv(void *func, uint64_t arg1, uint64_t arg2, uint64_t arg3)
215{ return (0); }
216
217#else	/* lint || __lint */
218
219	/*
220	 * %o0 - character
221	 */
222	ENTRY(hv_cnputchar)
223	mov	CONS_WRITE, %o5
224	ta	FAST_TRAP
225	tst	%o0
226	retl
227	movnz	%xcc, -1, %o0
228	SET_SIZE(hv_cnputchar)
229
230	/*
231	 * %o0 pointer to character buffer
232	 * return values:
233	 * 0 success
234	 * hv_errno failure
235	 */
236	ENTRY(hv_cngetchar)
237	mov	%o0, %o2
238	mov	CONS_READ, %o5
239	ta	FAST_TRAP
240	brnz,a	%o0, 1f		! failure, just return error
241	mov	1, %o0
242
243	cmp	%o1, H_BREAK
244	be	1f
245	mov	%o1, %o0
246
247	cmp	%o1, H_HUP
248	be	1f
249	mov	%o1, %o0
250
251	stb	%o1, [%o2]	! success, save character and return 0
252	mov	0, %o0
2531:
254	retl
255	nop
256	SET_SIZE(hv_cngetchar)
257
258	ENTRY(hv_tod_get)
259	mov	%o0, %o4
260	mov	TOD_GET, %o5
261	ta	FAST_TRAP
262	retl
263	  stx	%o1, [%o4]
264	SET_SIZE(hv_tod_get)
265
266	ENTRY(hv_tod_set)
267	mov	TOD_SET, %o5
268	ta	FAST_TRAP
269	retl
270	nop
271	SET_SIZE(hv_tod_set)
272
273	/*
274	 * Map permanent address
275	 * arg0 vaddr (%o0)
276	 * arg1 context (%o1)
277	 * arg2 tte (%o2)
278	 * arg3 flags (%o3)  0x1=d 0x2=i
279	 */
280	ENTRY(hv_mmu_map_perm_addr)
281	mov	MAP_PERM_ADDR, %o5
282	ta	FAST_TRAP
283	retl
284	nop
285	SET_SIZE(hv_mmu_map_perm_addr)
286
287	/*
288	 * Unmap permanent address
289	 * arg0 vaddr (%o0)
290	 * arg1 context (%o1)
291	 * arg2 flags (%o2)  0x1=d 0x2=i
292	 */
293	ENTRY(hv_mmu_unmap_perm_addr)
294	mov	UNMAP_PERM_ADDR, %o5
295	ta	FAST_TRAP
296	retl
297	nop
298	SET_SIZE(hv_mmu_unmap_perm_addr)
299
300	/*
301	 * Set TSB for context 0
302	 * arg0 ntsb_descriptor (%o0)
303	 * arg1 desc_ra (%o1)
304	 */
305	ENTRY(hv_set_ctx0)
306	mov	MMU_TSB_CTX0, %o5
307	ta	FAST_TRAP
308	retl
309	nop
310	SET_SIZE(hv_set_ctx0)
311
312	/*
313	 * Set TSB for context non0
314	 * arg0 ntsb_descriptor (%o0)
315	 * arg1 desc_ra (%o1)
316	 */
317	ENTRY(hv_set_ctxnon0)
318	mov	MMU_TSB_CTXNON0, %o5
319	ta	FAST_TRAP
320	retl
321	nop
322	SET_SIZE(hv_set_ctxnon0)
323
324#ifdef SET_MMU_STATS
325	/*
326	 * Returns old stat area on success
327	 */
328	ENTRY(hv_mmu_set_stat_area)
329	mov	MMU_STAT_AREA, %o5
330	ta	FAST_TRAP
331	retl
332	nop
333	SET_SIZE(hv_mmu_set_stat_area)
334#endif /* SET_MMU_STATS */
335
336	/*
337	 * CPU Q Configure
338	 * arg0 queue (%o0)
339	 * arg1 Base address RA (%o1)
340	 * arg2 Size (%o2)
341	 */
342	ENTRY(hv_cpu_qconf)
343	mov	CPU_QCONF, %o5
344	ta	FAST_TRAP
345	retl
346	nop
347	SET_SIZE(hv_cpu_qconf)
348
349	/*
350	 * arg0 - devhandle
351	 * arg1 - devino
352	 *
353	 * ret0 - status
354	 * ret1 - sysino
355	 */
356	ENTRY(hvio_intr_devino_to_sysino)
357	mov	HVIO_INTR_DEVINO2SYSINO, %o5
358	ta	FAST_TRAP
359	brz,a	%o0, 1f
360	stx	%o1, [%o2]
3611:	retl
362	nop
363	SET_SIZE(hvio_intr_devino_to_sysino)
364
365	/*
366	 * arg0 - sysino
367	 *
368	 * ret0 - status
369	 * ret1 - intr_valid_state
370	 */
371	ENTRY(hvio_intr_getvalid)
372	mov	%o1, %o2
373	mov	HVIO_INTR_GETVALID, %o5
374	ta	FAST_TRAP
375	brz,a	%o0, 1f
376	stuw	%o1, [%o2]
3771:	retl
378	nop
379	SET_SIZE(hvio_intr_getvalid)
380
381	/*
382	 * arg0 - sysino
383	 * arg1 - intr_valid_state
384	 *
385	 * ret0 - status
386	 */
387	ENTRY(hvio_intr_setvalid)
388	mov	HVIO_INTR_SETVALID, %o5
389	ta	FAST_TRAP
390	retl
391	nop
392	SET_SIZE(hvio_intr_setvalid)
393
394	/*
395	 * arg0 - sysino
396	 *
397	 * ret0 - status
398	 * ret1 - intr_state
399	 */
400	ENTRY(hvio_intr_getstate)
401	mov	%o1, %o2
402	mov	HVIO_INTR_GETSTATE, %o5
403	ta	FAST_TRAP
404	brz,a	%o0, 1f
405	stuw	%o1, [%o2]
4061:	retl
407	nop
408	SET_SIZE(hvio_intr_getstate)
409
410	/*
411	 * arg0 - sysino
412	 * arg1 - intr_state
413	 *
414	 * ret0 - status
415	 */
416	ENTRY(hvio_intr_setstate)
417	mov	HVIO_INTR_SETSTATE, %o5
418	ta	FAST_TRAP
419	retl
420	nop
421	SET_SIZE(hvio_intr_setstate)
422
423	/*
424	 * arg0 - sysino
425	 *
426	 * ret0 - status
427	 * ret1 - cpu_id
428	 */
429	ENTRY(hvio_intr_gettarget)
430	mov	%o1, %o2
431	mov	HVIO_INTR_GETTARGET, %o5
432	ta	FAST_TRAP
433	brz,a	%o0, 1f
434	stuw	%o1, [%o2]
4351:	retl
436	nop
437	SET_SIZE(hvio_intr_gettarget)
438
439	/*
440	 * arg0 - sysino
441	 * arg1 - cpu_id
442	 *
443	 * ret0 - status
444	 */
445	ENTRY(hvio_intr_settarget)
446	mov	HVIO_INTR_SETTARGET, %o5
447	ta	FAST_TRAP
448	retl
449	nop
450	SET_SIZE(hvio_intr_settarget)
451
452	/*
453	 * hv_cpu_yield(void)
454	 */
455	ENTRY(hv_cpu_yield)
456	mov	HV_CPU_YIELD, %o5
457	ta	FAST_TRAP
458	retl
459	nop
460	SET_SIZE(hv_cpu_yield)
461
462	/*
463	 * hv_service_recv(uint64_t s_id, uint64_t buf_pa,
464	 *     uint64_t size, uint64_t *recv_bytes);
465	 */
466	ENTRY(hv_service_recv)
467	save	%sp, -SA(MINFRAME), %sp
468	mov	%i0, %o0
469	mov	%i1, %o1
470	mov	%i2, %o2
471	mov	%i3, %o3
472	mov	SVC_RECV, %o5
473	ta	FAST_TRAP
474	brnz	%o0, 1f
475	mov	%o0, %i0
476	stx	%o1, [%i3]
4771:
478	ret
479	restore
480	SET_SIZE(hv_service_recv)
481
482	/*
483	 * hv_service_send(uint64_t s_id, uint64_t buf_pa,
484	 *     uint64_t size, uint64_t *recv_bytes);
485	 */
486	ENTRY(hv_service_send)
487	save	%sp, -SA(MINFRAME), %sp
488	mov	%i0, %o0
489	mov	%i1, %o1
490	mov	%i2, %o2
491	mov	%i3, %o3
492	mov	SVC_SEND, %o5
493	ta	FAST_TRAP
494	brnz	%o0, 1f
495	mov	%o0, %i0
496	stx	%o1, [%i3]
4971:
498	ret
499	restore
500	SET_SIZE(hv_service_send)
501
502	/*
503	 * hv_service_getstatus(uint64_t s_id, uint64_t *vreg);
504	 */
505	ENTRY(hv_service_getstatus)
506	mov	%o1, %o4			! save datap
507	mov	SVC_GETSTATUS, %o5
508	ta	FAST_TRAP
509	brz,a	%o0, 1f
510	stx	%o1, [%o4]
5111:
512	retl
513	nop
514	SET_SIZE(hv_service_getstatus)
515
516	/*
517	 * hv_service_setstatus(uint64_t s_id, uint64_t bits);
518	 */
519	ENTRY(hv_service_setstatus)
520	mov	SVC_SETSTATUS, %o5
521	ta	FAST_TRAP
522	retl
523	nop
524	SET_SIZE(hv_service_setstatus)
525
526	/*
527	 * hv_service_clrstatus(uint64_t s_id, uint64_t bits);
528	 */
529	ENTRY(hv_service_clrstatus)
530	mov	SVC_CLRSTATUS, %o5
531	ta	FAST_TRAP
532	retl
533	nop
534	SET_SIZE(hv_service_clrstatus)
535
536	/*
537	 * int hv_cpu_state(uint64_t cpuid, uint64_t *cpu_state);
538	 */
539	ENTRY(hv_cpu_state)
540	mov	%o1, %o4			! save datap
541	mov	HV_CPU_STATE, %o5
542	ta	FAST_TRAP
543	brz,a	%o0, 1f
544	stx	%o1, [%o4]
5451:
546	retl
547	nop
548	SET_SIZE(hv_cpu_state)
549
550	/*
551	 * HV state dump zone Configure
552	 * arg0 real adrs of dump buffer (%o0)
553	 * arg1 size of dump buffer (%o1)
554	 * ret0 status (%o0)
555	 * ret1 size of buffer on success and min size on EINVAL (%o1)
556	 * hv_dump_buf_update(uint64_t paddr, uint64_t size, uint64_t *ret_size)
557	 */
558	ENTRY(hv_dump_buf_update)
559	mov	DUMP_BUF_UPDATE, %o5
560	ta	FAST_TRAP
561	retl
562	stx	%o1, [%o2]
563	SET_SIZE(hv_dump_buf_update)
564
565
566	/*
567	 * For memory scrub
568	 * int hv_mem_scrub(uint64_t real_addr, uint64_t length,
569	 * 	uint64_t *scrubbed_len);
570	 * Retun %o0 -- status
571	 *       %o1 -- bytes scrubbed
572	 */
573	ENTRY(hv_mem_scrub)
574	mov	%o2, %o4
575	mov	HV_MEM_SCRUB, %o5
576	ta	FAST_TRAP
577	retl
578	stx	%o1, [%o4]
579	SET_SIZE(hv_mem_scrub)
580
581	/*
582	 * Flush ecache
583	 * int hv_mem_sync(uint64_t real_addr, uint64_t length,
584	 * 	uint64_t *flushed_len);
585	 * Retun %o0 -- status
586	 *       %o1 -- bytes flushed
587	 */
588	ENTRY(hv_mem_sync)
589	mov	%o2, %o4
590	mov	HV_MEM_SYNC, %o5
591	ta	FAST_TRAP
592	retl
593	stx	%o1, [%o4]
594	SET_SIZE(hv_mem_sync)
595
596	/*
597	 * TTRACE_BUF_CONF Configure
598	 * arg0 RA base of buffer (%o0)
599	 * arg1 buf size in no. of entries (%o1)
600	 * ret0 status (%o0)
601	 * ret1 minimum size in no. of entries on failure,
602	 * actual size in no. of entries on success (%o1)
603	 */
604	ENTRY(hv_ttrace_buf_conf)
605	mov	TTRACE_BUF_CONF, %o5
606	ta	FAST_TRAP
607	retl
608	stx	%o1, [%o2]
609	SET_SIZE(hv_ttrace_buf_conf)
610
611	 /*
612	 * TTRACE_BUF_INFO
613	 * ret0 status (%o0)
614	 * ret1 RA base of buffer (%o1)
615	 * ret2 size in no. of entries (%o2)
616	 */
617	ENTRY(hv_ttrace_buf_info)
618	mov	%o0, %o3
619	mov	%o1, %o4
620	mov	TTRACE_BUF_INFO, %o5
621	ta	FAST_TRAP
622	stx	%o1, [%o3]
623	retl
624	stx	%o2, [%o4]
625	SET_SIZE(hv_ttrace_buf_info)
626
627	/*
628	 * TTRACE_ENABLE
629	 * arg0 enable/ disable (%o0)
630	 * ret0 status (%o0)
631	 * ret1 previous enable state (%o1)
632	 */
633	ENTRY(hv_ttrace_enable)
634	mov	%o1, %o2
635	mov	TTRACE_ENABLE, %o5
636	ta	FAST_TRAP
637	retl
638	stx	%o1, [%o2]
639	SET_SIZE(hv_ttrace_enable)
640
641	/*
642	 * TTRACE_FREEZE
643	 * arg0 enable/ freeze (%o0)
644	 * ret0 status (%o0)
645	 * ret1 previous freeze state (%o1)
646	*/
647	ENTRY(hv_ttrace_freeze)
648	mov	%o1, %o2
649	mov	TTRACE_FREEZE, %o5
650	ta	FAST_TRAP
651	retl
652	stx	%o1, [%o2]
653	SET_SIZE(hv_ttrace_freeze)
654
655	/*
656	 * MACH_DESC
657	 * arg0 buffer real address
658	 * arg1 pointer to uint64_t for size of buffer
659	 * ret0 status
660	 * ret1 return required size of buffer / returned data size
661	 */
662	ENTRY(hv_mach_desc)
663	mov     %o1, %o4                ! save datap
664	ldx     [%o1], %o1
665	mov     HV_MACH_DESC, %o5
666	ta      FAST_TRAP
667	retl
668	stx   %o1, [%o4]
669	SET_SIZE(hv_mach_desc)
670
671	/*
672	 * hv_ncs_request(int cmd, uint64_t realaddr, size_t sz)
673	 */
674	ENTRY(hv_ncs_request)
675	mov	HV_NCS_REQUEST, %o5
676	ta	FAST_TRAP
677	retl
678	nop
679	SET_SIZE(hv_ncs_request)
680
681	/*
682	 * hv_ra2pa(uint64_t ra)
683	 *
684	 * MACH_DESC
685	 * arg0 Real address to convert
686	 * ret0 Returned physical address or -1 on error
687	 */
688	ENTRY(hv_ra2pa)
689	mov	HV_RA2PA, %o5
690	ta	FAST_TRAP
691	cmp	%o0, 0
692	move	%xcc, %o1, %o0
693	movne	%xcc, -1, %o0
694	retl
695	nop
696	SET_SIZE(hv_ra2pa)
697
698	/*
699	 * hv_hpriv(void *func, uint64_t arg1, uint64_t arg2, uint64_t arg3)
700	 *
701	 * MACH_DESC
702	 * arg0 OS function to call
703	 * arg1 First arg to OS function
704	 * arg2 Second arg to OS function
705	 * arg3 Third arg to OS function
706	 * ret0 Returned value from function
707	 */
708
709	ENTRY(hv_hpriv)
710	mov	HV_HPRIV, %o5
711	ta	FAST_TRAP
712	retl
713	nop
714	SET_SIZE(hv_hpriv)
715
716#endif	/* lint || __lint */
717