xref: /OK3568_Linux_fs/kernel/arch/sparc/include/asm/hypervisor.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun #ifndef _SPARC64_HYPERVISOR_H
3*4882a593Smuzhiyun #define _SPARC64_HYPERVISOR_H
4*4882a593Smuzhiyun 
5*4882a593Smuzhiyun /* Sun4v hypervisor interfaces and defines.
6*4882a593Smuzhiyun  *
7*4882a593Smuzhiyun  * Hypervisor calls are made via traps to software traps number 0x80
8*4882a593Smuzhiyun  * and above.  Registers %o0 to %o5 serve as argument, status, and
9*4882a593Smuzhiyun  * return value registers.
10*4882a593Smuzhiyun  *
11*4882a593Smuzhiyun  * There are two kinds of these traps.  First there are the normal
12*4882a593Smuzhiyun  * "fast traps" which use software trap 0x80 and encode the function
13*4882a593Smuzhiyun  * to invoke by number in register %o5.  Argument and return value
14*4882a593Smuzhiyun  * handling is as follows:
15*4882a593Smuzhiyun  *
16*4882a593Smuzhiyun  * -----------------------------------------------
17*4882a593Smuzhiyun  * |  %o5  | function number |     undefined     |
18*4882a593Smuzhiyun  * |  %o0  |   argument 0    |   return status   |
19*4882a593Smuzhiyun  * |  %o1  |   argument 1    |   return value 1  |
20*4882a593Smuzhiyun  * |  %o2  |   argument 2    |   return value 2  |
21*4882a593Smuzhiyun  * |  %o3  |   argument 3    |   return value 3  |
22*4882a593Smuzhiyun  * |  %o4  |   argument 4    |   return value 4  |
23*4882a593Smuzhiyun  * -----------------------------------------------
24*4882a593Smuzhiyun  *
25*4882a593Smuzhiyun  * The second type are "hyper-fast traps" which encode the function
26*4882a593Smuzhiyun  * number in the software trap number itself.  So these use trap
27*4882a593Smuzhiyun  * numbers > 0x80.  The register usage for hyper-fast traps is as
28*4882a593Smuzhiyun  * follows:
29*4882a593Smuzhiyun  *
30*4882a593Smuzhiyun  * -----------------------------------------------
31*4882a593Smuzhiyun  * |  %o0  |   argument 0    |   return status   |
32*4882a593Smuzhiyun  * |  %o1  |   argument 1    |   return value 1  |
33*4882a593Smuzhiyun  * |  %o2  |   argument 2    |   return value 2  |
34*4882a593Smuzhiyun  * |  %o3  |   argument 3    |   return value 3  |
35*4882a593Smuzhiyun  * |  %o4  |   argument 4    |   return value 4  |
36*4882a593Smuzhiyun  * -----------------------------------------------
37*4882a593Smuzhiyun  *
38*4882a593Smuzhiyun  * Registers providing explicit arguments to the hypervisor calls
39*4882a593Smuzhiyun  * are volatile across the call.  Upon return their values are
40*4882a593Smuzhiyun  * undefined unless explicitly specified as containing a particular
41*4882a593Smuzhiyun  * return value by the specific call.  The return status is always
42*4882a593Smuzhiyun  * returned in register %o0, zero indicates a successful execution of
43*4882a593Smuzhiyun  * the hypervisor call and other values indicate an error status as
44*4882a593Smuzhiyun  * defined below.  So, for example, if a hyper-fast trap takes
45*4882a593Smuzhiyun  * arguments 0, 1, and 2, then %o0, %o1, and %o2 are volatile across
46*4882a593Smuzhiyun  * the call and %o3, %o4, and %o5 would be preserved.
47*4882a593Smuzhiyun  *
48*4882a593Smuzhiyun  * If the hypervisor trap is invalid, or the fast trap function number
49*4882a593Smuzhiyun  * is invalid, HV_EBADTRAP will be returned in %o0.  Also, all 64-bits
50*4882a593Smuzhiyun  * of the argument and return values are significant.
51*4882a593Smuzhiyun  */
52*4882a593Smuzhiyun 
53*4882a593Smuzhiyun /* Trap numbers.  */
54*4882a593Smuzhiyun #define HV_FAST_TRAP		0x80
55*4882a593Smuzhiyun #define HV_MMU_MAP_ADDR_TRAP	0x83
56*4882a593Smuzhiyun #define HV_MMU_UNMAP_ADDR_TRAP	0x84
57*4882a593Smuzhiyun #define HV_TTRACE_ADDENTRY_TRAP	0x85
58*4882a593Smuzhiyun #define HV_CORE_TRAP		0xff
59*4882a593Smuzhiyun 
60*4882a593Smuzhiyun /* Error codes.  */
61*4882a593Smuzhiyun #define HV_EOK				0  /* Successful return            */
62*4882a593Smuzhiyun #define HV_ENOCPU			1  /* Invalid CPU id               */
63*4882a593Smuzhiyun #define HV_ENORADDR			2  /* Invalid real address         */
64*4882a593Smuzhiyun #define HV_ENOINTR			3  /* Invalid interrupt id         */
65*4882a593Smuzhiyun #define HV_EBADPGSZ			4  /* Invalid pagesize encoding    */
66*4882a593Smuzhiyun #define HV_EBADTSB			5  /* Invalid TSB description      */
67*4882a593Smuzhiyun #define HV_EINVAL			6  /* Invalid argument             */
68*4882a593Smuzhiyun #define HV_EBADTRAP			7  /* Invalid function number      */
69*4882a593Smuzhiyun #define HV_EBADALIGN			8  /* Invalid address alignment    */
70*4882a593Smuzhiyun #define HV_EWOULDBLOCK			9  /* Cannot complete w/o blocking */
71*4882a593Smuzhiyun #define HV_ENOACCESS			10 /* No access to resource        */
72*4882a593Smuzhiyun #define HV_EIO				11 /* I/O error                    */
73*4882a593Smuzhiyun #define HV_ECPUERROR			12 /* CPU in error state           */
74*4882a593Smuzhiyun #define HV_ENOTSUPPORTED		13 /* Function not supported       */
75*4882a593Smuzhiyun #define HV_ENOMAP			14 /* No mapping found             */
76*4882a593Smuzhiyun #define HV_ETOOMANY			15 /* Too many items specified     */
77*4882a593Smuzhiyun #define HV_ECHANNEL			16 /* Invalid LDC channel          */
78*4882a593Smuzhiyun #define HV_EBUSY			17 /* Resource busy                */
79*4882a593Smuzhiyun #define HV_EUNAVAILABLE			23 /* Resource or operation not
80*4882a593Smuzhiyun 					    * currently available, but may
81*4882a593Smuzhiyun 					    * become available in the future
82*4882a593Smuzhiyun 					    */
83*4882a593Smuzhiyun 
84*4882a593Smuzhiyun /* mach_exit()
85*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
86*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_MACH_EXIT
87*4882a593Smuzhiyun  * ARG0:	exit code
88*4882a593Smuzhiyun  * ERRORS:	This service does not return.
89*4882a593Smuzhiyun  *
90*4882a593Smuzhiyun  * Stop all CPUs in the virtual domain and place them into the stopped
91*4882a593Smuzhiyun  * state.  The 64-bit exit code may be passed to a service entity as
92*4882a593Smuzhiyun  * the domain's exit status.  On systems without a service entity, the
93*4882a593Smuzhiyun  * domain will undergo a reset, and the boot firmware will be
94*4882a593Smuzhiyun  * reloaded.
95*4882a593Smuzhiyun  *
96*4882a593Smuzhiyun  * This function will never return to the guest that invokes it.
97*4882a593Smuzhiyun  *
98*4882a593Smuzhiyun  * Note: By convention an exit code of zero denotes a successful exit by
99*4882a593Smuzhiyun  *       the guest code.  A non-zero exit code denotes a guest specific
100*4882a593Smuzhiyun  *       error indication.
101*4882a593Smuzhiyun  *
102*4882a593Smuzhiyun  */
103*4882a593Smuzhiyun #define HV_FAST_MACH_EXIT		0x00
104*4882a593Smuzhiyun 
105*4882a593Smuzhiyun #ifndef __ASSEMBLY__
106*4882a593Smuzhiyun void sun4v_mach_exit(unsigned long exit_code);
107*4882a593Smuzhiyun #endif
108*4882a593Smuzhiyun 
109*4882a593Smuzhiyun /* Domain services.  */
110*4882a593Smuzhiyun 
111*4882a593Smuzhiyun /* mach_desc()
112*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
113*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_MACH_DESC
114*4882a593Smuzhiyun  * ARG0:	buffer
115*4882a593Smuzhiyun  * ARG1:	length
116*4882a593Smuzhiyun  * RET0:	status
117*4882a593Smuzhiyun  * RET1:	length
118*4882a593Smuzhiyun  * ERRORS:	HV_EBADALIGN	Buffer is badly aligned
119*4882a593Smuzhiyun  *		HV_ENORADDR	Buffer is to an illegal real address.
120*4882a593Smuzhiyun  *		HV_EINVAL	Buffer length is too small for complete
121*4882a593Smuzhiyun  *				machine description.
122*4882a593Smuzhiyun  *
123*4882a593Smuzhiyun  * Copy the most current machine description into the buffer indicated
124*4882a593Smuzhiyun  * by the real address in ARG0.  The buffer provided must be 16 byte
125*4882a593Smuzhiyun  * aligned.  Upon success or HV_EINVAL, this service returns the
126*4882a593Smuzhiyun  * actual size of the machine description in the RET1 return value.
127*4882a593Smuzhiyun  *
128*4882a593Smuzhiyun  * Note: A method of determining the appropriate buffer size for the
129*4882a593Smuzhiyun  *       machine description is to first call this service with a buffer
130*4882a593Smuzhiyun  *       length of 0 bytes.
131*4882a593Smuzhiyun  */
132*4882a593Smuzhiyun #define HV_FAST_MACH_DESC		0x01
133*4882a593Smuzhiyun 
134*4882a593Smuzhiyun #ifndef __ASSEMBLY__
135*4882a593Smuzhiyun unsigned long sun4v_mach_desc(unsigned long buffer_pa,
136*4882a593Smuzhiyun 			      unsigned long buf_len,
137*4882a593Smuzhiyun 			      unsigned long *real_buf_len);
138*4882a593Smuzhiyun #endif
139*4882a593Smuzhiyun 
140*4882a593Smuzhiyun /* mach_sir()
141*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
142*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_MACH_SIR
143*4882a593Smuzhiyun  * ERRORS:	This service does not return.
144*4882a593Smuzhiyun  *
145*4882a593Smuzhiyun  * Perform a software initiated reset of the virtual machine domain.
146*4882a593Smuzhiyun  * All CPUs are captured as soon as possible, all hardware devices are
147*4882a593Smuzhiyun  * returned to the entry default state, and the domain is restarted at
148*4882a593Smuzhiyun  * the SIR (trap type 0x04) real trap table (RTBA) entry point on one
149*4882a593Smuzhiyun  * of the CPUs.  The single CPU restarted is selected as determined by
150*4882a593Smuzhiyun  * platform specific policy.  Memory is preserved across this
151*4882a593Smuzhiyun  * operation.
152*4882a593Smuzhiyun  */
153*4882a593Smuzhiyun #define HV_FAST_MACH_SIR		0x02
154*4882a593Smuzhiyun 
155*4882a593Smuzhiyun #ifndef __ASSEMBLY__
156*4882a593Smuzhiyun void sun4v_mach_sir(void);
157*4882a593Smuzhiyun #endif
158*4882a593Smuzhiyun 
159*4882a593Smuzhiyun /* mach_set_watchdog()
160*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
161*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_MACH_SET_WATCHDOG
162*4882a593Smuzhiyun  * ARG0:	timeout in milliseconds
163*4882a593Smuzhiyun  * RET0:	status
164*4882a593Smuzhiyun  * RET1:	time remaining in milliseconds
165*4882a593Smuzhiyun  *
166*4882a593Smuzhiyun  * A guest uses this API to set a watchdog timer.  Once the gues has set
167*4882a593Smuzhiyun  * the timer, it must call the timer service again either to disable or
168*4882a593Smuzhiyun  * postpone the expiration.  If the timer expires before being reset or
169*4882a593Smuzhiyun  * disabled, then the hypervisor take a platform specific action leading
170*4882a593Smuzhiyun  * to guest termination within a bounded time period.  The platform action
171*4882a593Smuzhiyun  * may include recovery actions such as reporting the expiration to a
172*4882a593Smuzhiyun  * Service Processor, and/or automatically restarting the gues.
173*4882a593Smuzhiyun  *
174*4882a593Smuzhiyun  * The 'timeout' parameter is specified in milliseconds, however the
175*4882a593Smuzhiyun  * implementated granularity is given by the 'watchdog-resolution'
176*4882a593Smuzhiyun  * property in the 'platform' node of the guest's machine description.
177*4882a593Smuzhiyun  * The largest allowed timeout value is specified by the
178*4882a593Smuzhiyun  * 'watchdog-max-timeout' property of the 'platform' node.
179*4882a593Smuzhiyun  *
180*4882a593Smuzhiyun  * If the 'timeout' argument is not zero, the watchdog timer is set to
181*4882a593Smuzhiyun  * expire after a minimum of 'timeout' milliseconds.
182*4882a593Smuzhiyun  *
183*4882a593Smuzhiyun  * If the 'timeout' argument is zero, the watchdog timer is disabled.
184*4882a593Smuzhiyun  *
185*4882a593Smuzhiyun  * If the 'timeout' value exceeds the value of the 'max-watchdog-timeout'
186*4882a593Smuzhiyun  * property, the hypervisor leaves the watchdog timer state unchanged,
187*4882a593Smuzhiyun  * and returns a status of EINVAL.
188*4882a593Smuzhiyun  *
189*4882a593Smuzhiyun  * The 'time remaining' return value is valid regardless of whether the
190*4882a593Smuzhiyun  * return status is EOK or EINVAL.  A non-zero return value indicates the
191*4882a593Smuzhiyun  * number of milliseconds that were remaining until the timer was to expire.
192*4882a593Smuzhiyun  * If less than one millisecond remains, the return value is '1'.  If the
193*4882a593Smuzhiyun  * watchdog timer was disabled at the time of the call, the return value is
194*4882a593Smuzhiyun  * zero.
195*4882a593Smuzhiyun  *
196*4882a593Smuzhiyun  * If the hypervisor cannot support the exact timeout value requested, but
197*4882a593Smuzhiyun  * can support a larger timeout value, the hypervisor may round the actual
198*4882a593Smuzhiyun  * timeout to a value larger than the requested timeout, consequently the
199*4882a593Smuzhiyun  * 'time remaining' return value may be larger than the previously requested
200*4882a593Smuzhiyun  * timeout value.
201*4882a593Smuzhiyun  *
202*4882a593Smuzhiyun  * Any guest OS debugger should be aware that the watchdog service may be in
203*4882a593Smuzhiyun  * use.  Consequently, it is recommended that the watchdog service is
204*4882a593Smuzhiyun  * disabled upon debugger entry (e.g. reaching a breakpoint), and then
205*4882a593Smuzhiyun  * re-enabled upon returning to normal execution.  The API has been designed
206*4882a593Smuzhiyun  * with this in mind, and the 'time remaining' result of the disable call may
207*4882a593Smuzhiyun  * be used directly as the timeout argument of the re-enable call.
208*4882a593Smuzhiyun  */
209*4882a593Smuzhiyun #define HV_FAST_MACH_SET_WATCHDOG	0x05
210*4882a593Smuzhiyun 
211*4882a593Smuzhiyun #ifndef __ASSEMBLY__
212*4882a593Smuzhiyun unsigned long sun4v_mach_set_watchdog(unsigned long timeout,
213*4882a593Smuzhiyun 				      unsigned long *orig_timeout);
214*4882a593Smuzhiyun #endif
215*4882a593Smuzhiyun 
216*4882a593Smuzhiyun /* CPU services.
217*4882a593Smuzhiyun  *
218*4882a593Smuzhiyun  * CPUs represent devices that can execute software threads.  A single
219*4882a593Smuzhiyun  * chip that contains multiple cores or strands is represented as
220*4882a593Smuzhiyun  * multiple CPUs with unique CPU identifiers.  CPUs are exported to
221*4882a593Smuzhiyun  * OBP via the machine description (and to the OS via the OBP device
222*4882a593Smuzhiyun  * tree).  CPUs are always in one of three states: stopped, running,
223*4882a593Smuzhiyun  * or error.
224*4882a593Smuzhiyun  *
225*4882a593Smuzhiyun  * A CPU ID is a pre-assigned 16-bit value that uniquely identifies a
226*4882a593Smuzhiyun  * CPU within a logical domain.  Operations that are to be performed
227*4882a593Smuzhiyun  * on multiple CPUs specify them via a CPU list.  A CPU list is an
228*4882a593Smuzhiyun  * array in real memory, of which each 16-bit word is a CPU ID.  CPU
229*4882a593Smuzhiyun  * lists are passed through the API as two arguments.  The first is
230*4882a593Smuzhiyun  * the number of entries (16-bit words) in the CPU list, and the
231*4882a593Smuzhiyun  * second is the (real address) pointer to the CPU ID list.
232*4882a593Smuzhiyun  */
233*4882a593Smuzhiyun 
234*4882a593Smuzhiyun /* cpu_start()
235*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
236*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_CPU_START
237*4882a593Smuzhiyun  * ARG0:	CPU ID
238*4882a593Smuzhiyun  * ARG1:	PC
239*4882a593Smuzhiyun  * ARG2:	RTBA
240*4882a593Smuzhiyun  * ARG3:	target ARG0
241*4882a593Smuzhiyun  * RET0:	status
242*4882a593Smuzhiyun  * ERRORS:	ENOCPU		Invalid CPU ID
243*4882a593Smuzhiyun  *		EINVAL		Target CPU ID is not in the stopped state
244*4882a593Smuzhiyun  *		ENORADDR	Invalid PC or RTBA real address
245*4882a593Smuzhiyun  *		EBADALIGN	Unaligned PC or unaligned RTBA
246*4882a593Smuzhiyun  *		EWOULDBLOCK	Starting resources are not available
247*4882a593Smuzhiyun  *
248*4882a593Smuzhiyun  * Start CPU with given CPU ID with PC in %pc and with a real trap
249*4882a593Smuzhiyun  * base address value of RTBA.  The indicated CPU must be in the
250*4882a593Smuzhiyun  * stopped state.  The supplied RTBA must be aligned on a 256 byte
251*4882a593Smuzhiyun  * boundary.  On successful completion, the specified CPU will be in
252*4882a593Smuzhiyun  * the running state and will be supplied with "target ARG0" in %o0
253*4882a593Smuzhiyun  * and RTBA in %tba.
254*4882a593Smuzhiyun  */
255*4882a593Smuzhiyun #define HV_FAST_CPU_START		0x10
256*4882a593Smuzhiyun 
257*4882a593Smuzhiyun #ifndef __ASSEMBLY__
258*4882a593Smuzhiyun unsigned long sun4v_cpu_start(unsigned long cpuid,
259*4882a593Smuzhiyun 			      unsigned long pc,
260*4882a593Smuzhiyun 			      unsigned long rtba,
261*4882a593Smuzhiyun 			      unsigned long arg0);
262*4882a593Smuzhiyun #endif
263*4882a593Smuzhiyun 
264*4882a593Smuzhiyun /* cpu_stop()
265*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
266*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_CPU_STOP
267*4882a593Smuzhiyun  * ARG0:	CPU ID
268*4882a593Smuzhiyun  * RET0:	status
269*4882a593Smuzhiyun  * ERRORS:	ENOCPU		Invalid CPU ID
270*4882a593Smuzhiyun  *		EINVAL		Target CPU ID is the current cpu
271*4882a593Smuzhiyun  *		EINVAL		Target CPU ID is not in the running state
272*4882a593Smuzhiyun  *		EWOULDBLOCK	Stopping resources are not available
273*4882a593Smuzhiyun  *		ENOTSUPPORTED	Not supported on this platform
274*4882a593Smuzhiyun  *
275*4882a593Smuzhiyun  * The specified CPU is stopped.  The indicated CPU must be in the
276*4882a593Smuzhiyun  * running state.  On completion, it will be in the stopped state.  It
277*4882a593Smuzhiyun  * is not legal to stop the current CPU.
278*4882a593Smuzhiyun  *
279*4882a593Smuzhiyun  * Note: As this service cannot be used to stop the current cpu, this service
280*4882a593Smuzhiyun  *       may not be used to stop the last running CPU in a domain.  To stop
281*4882a593Smuzhiyun  *       and exit a running domain, a guest must use the mach_exit() service.
282*4882a593Smuzhiyun  */
283*4882a593Smuzhiyun #define HV_FAST_CPU_STOP		0x11
284*4882a593Smuzhiyun 
285*4882a593Smuzhiyun #ifndef __ASSEMBLY__
286*4882a593Smuzhiyun unsigned long sun4v_cpu_stop(unsigned long cpuid);
287*4882a593Smuzhiyun #endif
288*4882a593Smuzhiyun 
289*4882a593Smuzhiyun /* cpu_yield()
290*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
291*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_CPU_YIELD
292*4882a593Smuzhiyun  * RET0:	status
293*4882a593Smuzhiyun  * ERRORS:	No possible error.
294*4882a593Smuzhiyun  *
295*4882a593Smuzhiyun  * Suspend execution on the current CPU.  Execution will resume when
296*4882a593Smuzhiyun  * an interrupt (device, %stick_compare, or cross-call) is targeted to
297*4882a593Smuzhiyun  * the CPU.  On some CPUs, this API may be used by the hypervisor to
298*4882a593Smuzhiyun  * save power by disabling hardware strands.
299*4882a593Smuzhiyun  */
300*4882a593Smuzhiyun #define HV_FAST_CPU_YIELD		0x12
301*4882a593Smuzhiyun 
302*4882a593Smuzhiyun #ifndef __ASSEMBLY__
303*4882a593Smuzhiyun unsigned long sun4v_cpu_yield(void);
304*4882a593Smuzhiyun #endif
305*4882a593Smuzhiyun 
306*4882a593Smuzhiyun /* cpu_poke()
307*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
308*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_CPU_POKE
309*4882a593Smuzhiyun  * RET0:	status
310*4882a593Smuzhiyun  * ERRORS:	ENOCPU		cpuid refers to a CPU that does not exist
311*4882a593Smuzhiyun  *		EINVAL		cpuid is current CPU
312*4882a593Smuzhiyun  *
313*4882a593Smuzhiyun  * Poke CPU cpuid. If the target CPU is currently suspended having
314*4882a593Smuzhiyun  * invoked the cpu-yield service, that vCPU will be resumed.
315*4882a593Smuzhiyun  * Poke interrupts may only be sent to valid, non-local CPUs.
316*4882a593Smuzhiyun  * It is not legal to poke the current vCPU.
317*4882a593Smuzhiyun  */
318*4882a593Smuzhiyun #define HV_FAST_CPU_POKE                0x13
319*4882a593Smuzhiyun 
320*4882a593Smuzhiyun #ifndef __ASSEMBLY__
321*4882a593Smuzhiyun unsigned long sun4v_cpu_poke(unsigned long cpuid);
322*4882a593Smuzhiyun #endif
323*4882a593Smuzhiyun 
324*4882a593Smuzhiyun /* cpu_qconf()
325*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
326*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_CPU_QCONF
327*4882a593Smuzhiyun  * ARG0:	queue
328*4882a593Smuzhiyun  * ARG1:	base real address
329*4882a593Smuzhiyun  * ARG2:	number of entries
330*4882a593Smuzhiyun  * RET0:	status
331*4882a593Smuzhiyun  * ERRORS:	ENORADDR	Invalid base real address
332*4882a593Smuzhiyun  *		EINVAL		Invalid queue or number of entries is less
333*4882a593Smuzhiyun  *				than 2 or too large.
334*4882a593Smuzhiyun  *		EBADALIGN	Base real address is not correctly aligned
335*4882a593Smuzhiyun  *				for size.
336*4882a593Smuzhiyun  *
337*4882a593Smuzhiyun  * Configure the given queue to be placed at the given base real
338*4882a593Smuzhiyun  * address, with the given number of entries.  The number of entries
339*4882a593Smuzhiyun  * must be a power of 2.  The base real address must be aligned
340*4882a593Smuzhiyun  * exactly to match the queue size.  Each queue entry is 64 bytes
341*4882a593Smuzhiyun  * long, so for example a 32 entry queue must be aligned on a 2048
342*4882a593Smuzhiyun  * byte real address boundary.
343*4882a593Smuzhiyun  *
344*4882a593Smuzhiyun  * The specified queue is unconfigured if the number of entries is given
345*4882a593Smuzhiyun  * as zero.
346*4882a593Smuzhiyun  *
347*4882a593Smuzhiyun  * For the current version of this API service, the argument queue is defined
348*4882a593Smuzhiyun  * as follows:
349*4882a593Smuzhiyun  *
350*4882a593Smuzhiyun  *	queue		description
351*4882a593Smuzhiyun  *	-----		-------------------------
352*4882a593Smuzhiyun  *	0x3c		cpu mondo queue
353*4882a593Smuzhiyun  *	0x3d		device mondo queue
354*4882a593Smuzhiyun  *	0x3e		resumable error queue
355*4882a593Smuzhiyun  *	0x3f		non-resumable error queue
356*4882a593Smuzhiyun  *
357*4882a593Smuzhiyun  * Note: The maximum number of entries for each queue for a specific cpu may
358*4882a593Smuzhiyun  *       be determined from the machine description.
359*4882a593Smuzhiyun  */
360*4882a593Smuzhiyun #define HV_FAST_CPU_QCONF		0x14
361*4882a593Smuzhiyun #define  HV_CPU_QUEUE_CPU_MONDO		 0x3c
362*4882a593Smuzhiyun #define  HV_CPU_QUEUE_DEVICE_MONDO	 0x3d
363*4882a593Smuzhiyun #define  HV_CPU_QUEUE_RES_ERROR		 0x3e
364*4882a593Smuzhiyun #define  HV_CPU_QUEUE_NONRES_ERROR	 0x3f
365*4882a593Smuzhiyun 
366*4882a593Smuzhiyun #ifndef __ASSEMBLY__
367*4882a593Smuzhiyun unsigned long sun4v_cpu_qconf(unsigned long type,
368*4882a593Smuzhiyun 			      unsigned long queue_paddr,
369*4882a593Smuzhiyun 			      unsigned long num_queue_entries);
370*4882a593Smuzhiyun #endif
371*4882a593Smuzhiyun 
372*4882a593Smuzhiyun /* cpu_qinfo()
373*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
374*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_CPU_QINFO
375*4882a593Smuzhiyun  * ARG0:	queue
376*4882a593Smuzhiyun  * RET0:	status
377*4882a593Smuzhiyun  * RET1:	base real address
378*4882a593Smuzhiyun  * RET1:	number of entries
379*4882a593Smuzhiyun  * ERRORS:	EINVAL		Invalid queue
380*4882a593Smuzhiyun  *
381*4882a593Smuzhiyun  * Return the configuration info for the given queue.  The base real
382*4882a593Smuzhiyun  * address and number of entries of the defined queue are returned.
383*4882a593Smuzhiyun  * The queue argument values are the same as for cpu_qconf() above.
384*4882a593Smuzhiyun  *
385*4882a593Smuzhiyun  * If the specified queue is a valid queue number, but no queue has
386*4882a593Smuzhiyun  * been defined, the number of entries will be set to zero and the
387*4882a593Smuzhiyun  * base real address returned is undefined.
388*4882a593Smuzhiyun  */
389*4882a593Smuzhiyun #define HV_FAST_CPU_QINFO		0x15
390*4882a593Smuzhiyun 
391*4882a593Smuzhiyun /* cpu_mondo_send()
392*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
393*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_CPU_MONDO_SEND
394*4882a593Smuzhiyun  * ARG0-1:	CPU list
395*4882a593Smuzhiyun  * ARG2:	data real address
396*4882a593Smuzhiyun  * RET0:	status
397*4882a593Smuzhiyun  * ERRORS:	EBADALIGN	Mondo data is not 64-byte aligned or CPU list
398*4882a593Smuzhiyun  *				is not 2-byte aligned.
399*4882a593Smuzhiyun  *		ENORADDR	Invalid data mondo address, or invalid cpu list
400*4882a593Smuzhiyun  *				address.
401*4882a593Smuzhiyun  *		ENOCPU		Invalid cpu in CPU list
402*4882a593Smuzhiyun  *		EWOULDBLOCK	Some or all of the listed CPUs did not receive
403*4882a593Smuzhiyun  *				the mondo
404*4882a593Smuzhiyun  *		ECPUERROR	One or more of the listed CPUs are in error
405*4882a593Smuzhiyun  *				state, use HV_FAST_CPU_STATE to see which ones
406*4882a593Smuzhiyun  *		EINVAL		CPU list includes caller's CPU ID
407*4882a593Smuzhiyun  *
408*4882a593Smuzhiyun  * Send a mondo interrupt to the CPUs in the given CPU list with the
409*4882a593Smuzhiyun  * 64-bytes at the given data real address.  The data must be 64-byte
410*4882a593Smuzhiyun  * aligned.  The mondo data will be delivered to the cpu_mondo queues
411*4882a593Smuzhiyun  * of the recipient CPUs.
412*4882a593Smuzhiyun  *
413*4882a593Smuzhiyun  * In all cases, error or not, the CPUs in the CPU list to which the
414*4882a593Smuzhiyun  * mondo has been successfully delivered will be indicated by having
415*4882a593Smuzhiyun  * their entry in CPU list updated with the value 0xffff.
416*4882a593Smuzhiyun  */
417*4882a593Smuzhiyun #define HV_FAST_CPU_MONDO_SEND		0x42
418*4882a593Smuzhiyun 
419*4882a593Smuzhiyun #ifndef __ASSEMBLY__
420*4882a593Smuzhiyun unsigned long sun4v_cpu_mondo_send(unsigned long cpu_count,
421*4882a593Smuzhiyun 				   unsigned long cpu_list_pa,
422*4882a593Smuzhiyun 				   unsigned long mondo_block_pa);
423*4882a593Smuzhiyun #endif
424*4882a593Smuzhiyun 
425*4882a593Smuzhiyun /* cpu_myid()
426*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
427*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_CPU_MYID
428*4882a593Smuzhiyun  * RET0:	status
429*4882a593Smuzhiyun  * RET1:	CPU ID
430*4882a593Smuzhiyun  * ERRORS:	No errors defined.
431*4882a593Smuzhiyun  *
432*4882a593Smuzhiyun  * Return the hypervisor ID handle for the current CPU.  Use by a
433*4882a593Smuzhiyun  * virtual CPU to discover it's own identity.
434*4882a593Smuzhiyun  */
435*4882a593Smuzhiyun #define HV_FAST_CPU_MYID		0x16
436*4882a593Smuzhiyun 
437*4882a593Smuzhiyun /* cpu_state()
438*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
439*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_CPU_STATE
440*4882a593Smuzhiyun  * ARG0:	CPU ID
441*4882a593Smuzhiyun  * RET0:	status
442*4882a593Smuzhiyun  * RET1:	state
443*4882a593Smuzhiyun  * ERRORS:	ENOCPU		Invalid CPU ID
444*4882a593Smuzhiyun  *
445*4882a593Smuzhiyun  * Retrieve the current state of the CPU with the given CPU ID.
446*4882a593Smuzhiyun  */
447*4882a593Smuzhiyun #define HV_FAST_CPU_STATE		0x17
448*4882a593Smuzhiyun #define  HV_CPU_STATE_STOPPED		 0x01
449*4882a593Smuzhiyun #define  HV_CPU_STATE_RUNNING		 0x02
450*4882a593Smuzhiyun #define  HV_CPU_STATE_ERROR		 0x03
451*4882a593Smuzhiyun 
452*4882a593Smuzhiyun #ifndef __ASSEMBLY__
453*4882a593Smuzhiyun long sun4v_cpu_state(unsigned long cpuid);
454*4882a593Smuzhiyun #endif
455*4882a593Smuzhiyun 
456*4882a593Smuzhiyun /* cpu_set_rtba()
457*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
458*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_CPU_SET_RTBA
459*4882a593Smuzhiyun  * ARG0:	RTBA
460*4882a593Smuzhiyun  * RET0:	status
461*4882a593Smuzhiyun  * RET1:	previous RTBA
462*4882a593Smuzhiyun  * ERRORS:	ENORADDR	Invalid RTBA real address
463*4882a593Smuzhiyun  *		EBADALIGN	RTBA is incorrectly aligned for a trap table
464*4882a593Smuzhiyun  *
465*4882a593Smuzhiyun  * Set the real trap base address of the local cpu to the given RTBA.
466*4882a593Smuzhiyun  * The supplied RTBA must be aligned on a 256 byte boundary.  Upon
467*4882a593Smuzhiyun  * success the previous value of the RTBA is returned in RET1.
468*4882a593Smuzhiyun  *
469*4882a593Smuzhiyun  * Note: This service does not affect %tba
470*4882a593Smuzhiyun  */
471*4882a593Smuzhiyun #define HV_FAST_CPU_SET_RTBA		0x18
472*4882a593Smuzhiyun 
473*4882a593Smuzhiyun /* cpu_set_rtba()
474*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
475*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_CPU_GET_RTBA
476*4882a593Smuzhiyun  * RET0:	status
477*4882a593Smuzhiyun  * RET1:	previous RTBA
478*4882a593Smuzhiyun  * ERRORS:	No possible error.
479*4882a593Smuzhiyun  *
480*4882a593Smuzhiyun  * Returns the current value of RTBA in RET1.
481*4882a593Smuzhiyun  */
482*4882a593Smuzhiyun #define HV_FAST_CPU_GET_RTBA		0x19
483*4882a593Smuzhiyun 
484*4882a593Smuzhiyun /* MMU services.
485*4882a593Smuzhiyun  *
486*4882a593Smuzhiyun  * Layout of a TSB description for mmu_tsb_ctx{,non}0() calls.
487*4882a593Smuzhiyun  */
488*4882a593Smuzhiyun #ifndef __ASSEMBLY__
489*4882a593Smuzhiyun struct hv_tsb_descr {
490*4882a593Smuzhiyun 	unsigned short		pgsz_idx;
491*4882a593Smuzhiyun 	unsigned short		assoc;
492*4882a593Smuzhiyun 	unsigned int		num_ttes;	/* in TTEs */
493*4882a593Smuzhiyun 	unsigned int		ctx_idx;
494*4882a593Smuzhiyun 	unsigned int		pgsz_mask;
495*4882a593Smuzhiyun 	unsigned long		tsb_base;
496*4882a593Smuzhiyun 	unsigned long		resv;
497*4882a593Smuzhiyun };
498*4882a593Smuzhiyun #endif
499*4882a593Smuzhiyun #define HV_TSB_DESCR_PGSZ_IDX_OFFSET	0x00
500*4882a593Smuzhiyun #define HV_TSB_DESCR_ASSOC_OFFSET	0x02
501*4882a593Smuzhiyun #define HV_TSB_DESCR_NUM_TTES_OFFSET	0x04
502*4882a593Smuzhiyun #define HV_TSB_DESCR_CTX_IDX_OFFSET	0x08
503*4882a593Smuzhiyun #define HV_TSB_DESCR_PGSZ_MASK_OFFSET	0x0c
504*4882a593Smuzhiyun #define HV_TSB_DESCR_TSB_BASE_OFFSET	0x10
505*4882a593Smuzhiyun #define HV_TSB_DESCR_RESV_OFFSET	0x18
506*4882a593Smuzhiyun 
507*4882a593Smuzhiyun /* Page size bitmask.  */
508*4882a593Smuzhiyun #define HV_PGSZ_MASK_8K			(1 << 0)
509*4882a593Smuzhiyun #define HV_PGSZ_MASK_64K		(1 << 1)
510*4882a593Smuzhiyun #define HV_PGSZ_MASK_512K		(1 << 2)
511*4882a593Smuzhiyun #define HV_PGSZ_MASK_4MB		(1 << 3)
512*4882a593Smuzhiyun #define HV_PGSZ_MASK_32MB		(1 << 4)
513*4882a593Smuzhiyun #define HV_PGSZ_MASK_256MB		(1 << 5)
514*4882a593Smuzhiyun #define HV_PGSZ_MASK_2GB		(1 << 6)
515*4882a593Smuzhiyun #define HV_PGSZ_MASK_16GB		(1 << 7)
516*4882a593Smuzhiyun 
517*4882a593Smuzhiyun /* Page size index.  The value given in the TSB descriptor must correspond
518*4882a593Smuzhiyun  * to the smallest page size specified in the pgsz_mask page size bitmask.
519*4882a593Smuzhiyun  */
520*4882a593Smuzhiyun #define HV_PGSZ_IDX_8K			0
521*4882a593Smuzhiyun #define HV_PGSZ_IDX_64K			1
522*4882a593Smuzhiyun #define HV_PGSZ_IDX_512K		2
523*4882a593Smuzhiyun #define HV_PGSZ_IDX_4MB			3
524*4882a593Smuzhiyun #define HV_PGSZ_IDX_32MB		4
525*4882a593Smuzhiyun #define HV_PGSZ_IDX_256MB		5
526*4882a593Smuzhiyun #define HV_PGSZ_IDX_2GB			6
527*4882a593Smuzhiyun #define HV_PGSZ_IDX_16GB		7
528*4882a593Smuzhiyun 
529*4882a593Smuzhiyun /* MMU fault status area.
530*4882a593Smuzhiyun  *
531*4882a593Smuzhiyun  * MMU related faults have their status and fault address information
532*4882a593Smuzhiyun  * placed into a memory region made available by privileged code.  Each
533*4882a593Smuzhiyun  * virtual processor must make a mmu_fault_area_conf() call to tell the
534*4882a593Smuzhiyun  * hypervisor where that processor's fault status should be stored.
535*4882a593Smuzhiyun  *
536*4882a593Smuzhiyun  * The fault status block is a multiple of 64-bytes and must be aligned
537*4882a593Smuzhiyun  * on a 64-byte boundary.
538*4882a593Smuzhiyun  */
539*4882a593Smuzhiyun #ifndef __ASSEMBLY__
540*4882a593Smuzhiyun struct hv_fault_status {
541*4882a593Smuzhiyun 	unsigned long		i_fault_type;
542*4882a593Smuzhiyun 	unsigned long		i_fault_addr;
543*4882a593Smuzhiyun 	unsigned long		i_fault_ctx;
544*4882a593Smuzhiyun 	unsigned long		i_reserved[5];
545*4882a593Smuzhiyun 	unsigned long		d_fault_type;
546*4882a593Smuzhiyun 	unsigned long		d_fault_addr;
547*4882a593Smuzhiyun 	unsigned long		d_fault_ctx;
548*4882a593Smuzhiyun 	unsigned long		d_reserved[5];
549*4882a593Smuzhiyun };
550*4882a593Smuzhiyun #endif
551*4882a593Smuzhiyun #define HV_FAULT_I_TYPE_OFFSET	0x00
552*4882a593Smuzhiyun #define HV_FAULT_I_ADDR_OFFSET	0x08
553*4882a593Smuzhiyun #define HV_FAULT_I_CTX_OFFSET	0x10
554*4882a593Smuzhiyun #define HV_FAULT_D_TYPE_OFFSET	0x40
555*4882a593Smuzhiyun #define HV_FAULT_D_ADDR_OFFSET	0x48
556*4882a593Smuzhiyun #define HV_FAULT_D_CTX_OFFSET	0x50
557*4882a593Smuzhiyun 
558*4882a593Smuzhiyun #define HV_FAULT_TYPE_FAST_MISS	1
559*4882a593Smuzhiyun #define HV_FAULT_TYPE_FAST_PROT	2
560*4882a593Smuzhiyun #define HV_FAULT_TYPE_MMU_MISS	3
561*4882a593Smuzhiyun #define HV_FAULT_TYPE_INV_RA	4
562*4882a593Smuzhiyun #define HV_FAULT_TYPE_PRIV_VIOL	5
563*4882a593Smuzhiyun #define HV_FAULT_TYPE_PROT_VIOL	6
564*4882a593Smuzhiyun #define HV_FAULT_TYPE_NFO	7
565*4882a593Smuzhiyun #define HV_FAULT_TYPE_NFO_SEFF	8
566*4882a593Smuzhiyun #define HV_FAULT_TYPE_INV_VA	9
567*4882a593Smuzhiyun #define HV_FAULT_TYPE_INV_ASI	10
568*4882a593Smuzhiyun #define HV_FAULT_TYPE_NC_ATOMIC	11
569*4882a593Smuzhiyun #define HV_FAULT_TYPE_PRIV_ACT	12
570*4882a593Smuzhiyun #define HV_FAULT_TYPE_RESV1	13
571*4882a593Smuzhiyun #define HV_FAULT_TYPE_UNALIGNED	14
572*4882a593Smuzhiyun #define HV_FAULT_TYPE_INV_PGSZ	15
573*4882a593Smuzhiyun #define HV_FAULT_TYPE_MCD	17
574*4882a593Smuzhiyun #define HV_FAULT_TYPE_MCD_DIS	18
575*4882a593Smuzhiyun /* Values 16 --> -2 are reserved.  */
576*4882a593Smuzhiyun #define HV_FAULT_TYPE_MULTIPLE	-1
577*4882a593Smuzhiyun 
578*4882a593Smuzhiyun /* Flags argument for mmu_{map,unmap}_addr(), mmu_demap_{page,context,all}(),
579*4882a593Smuzhiyun  * and mmu_{map,unmap}_perm_addr().
580*4882a593Smuzhiyun  */
581*4882a593Smuzhiyun #define HV_MMU_DMMU			0x01
582*4882a593Smuzhiyun #define HV_MMU_IMMU			0x02
583*4882a593Smuzhiyun #define HV_MMU_ALL			(HV_MMU_DMMU | HV_MMU_IMMU)
584*4882a593Smuzhiyun 
585*4882a593Smuzhiyun /* mmu_map_addr()
586*4882a593Smuzhiyun  * TRAP:	HV_MMU_MAP_ADDR_TRAP
587*4882a593Smuzhiyun  * ARG0:	virtual address
588*4882a593Smuzhiyun  * ARG1:	mmu context
589*4882a593Smuzhiyun  * ARG2:	TTE
590*4882a593Smuzhiyun  * ARG3:	flags (HV_MMU_{IMMU,DMMU})
591*4882a593Smuzhiyun  * ERRORS:	EINVAL		Invalid virtual address, mmu context, or flags
592*4882a593Smuzhiyun  *		EBADPGSZ	Invalid page size value
593*4882a593Smuzhiyun  *		ENORADDR	Invalid real address in TTE
594*4882a593Smuzhiyun  *
595*4882a593Smuzhiyun  * Create a non-permanent mapping using the given TTE, virtual
596*4882a593Smuzhiyun  * address, and mmu context.  The flags argument determines which
597*4882a593Smuzhiyun  * (data, or instruction, or both) TLB the mapping gets loaded into.
598*4882a593Smuzhiyun  *
599*4882a593Smuzhiyun  * The behavior is undefined if the valid bit is clear in the TTE.
600*4882a593Smuzhiyun  *
601*4882a593Smuzhiyun  * Note: This API call is for privileged code to specify temporary translation
602*4882a593Smuzhiyun  *       mappings without the need to create and manage a TSB.
603*4882a593Smuzhiyun  */
604*4882a593Smuzhiyun 
605*4882a593Smuzhiyun /* mmu_unmap_addr()
606*4882a593Smuzhiyun  * TRAP:	HV_MMU_UNMAP_ADDR_TRAP
607*4882a593Smuzhiyun  * ARG0:	virtual address
608*4882a593Smuzhiyun  * ARG1:	mmu context
609*4882a593Smuzhiyun  * ARG2:	flags (HV_MMU_{IMMU,DMMU})
610*4882a593Smuzhiyun  * ERRORS:	EINVAL		Invalid virtual address, mmu context, or flags
611*4882a593Smuzhiyun  *
612*4882a593Smuzhiyun  * Demaps the given virtual address in the given mmu context on this
613*4882a593Smuzhiyun  * CPU.  This function is intended to be used to demap pages mapped
614*4882a593Smuzhiyun  * with mmu_map_addr.  This service is equivalent to invoking
615*4882a593Smuzhiyun  * mmu_demap_page() with only the current CPU in the CPU list. The
616*4882a593Smuzhiyun  * flags argument determines which (data, or instruction, or both) TLB
617*4882a593Smuzhiyun  * the mapping gets unmapped from.
618*4882a593Smuzhiyun  *
619*4882a593Smuzhiyun  * Attempting to perform an unmap operation for a previously defined
620*4882a593Smuzhiyun  * permanent mapping will have undefined results.
621*4882a593Smuzhiyun  */
622*4882a593Smuzhiyun 
623*4882a593Smuzhiyun /* mmu_tsb_ctx0()
624*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
625*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_MMU_TSB_CTX0
626*4882a593Smuzhiyun  * ARG0:	number of TSB descriptions
627*4882a593Smuzhiyun  * ARG1:	TSB descriptions pointer
628*4882a593Smuzhiyun  * RET0:	status
629*4882a593Smuzhiyun  * ERRORS:	ENORADDR		Invalid TSB descriptions pointer or
630*4882a593Smuzhiyun  *					TSB base within a descriptor
631*4882a593Smuzhiyun  *		EBADALIGN		TSB descriptions pointer is not aligned
632*4882a593Smuzhiyun  *					to an 8-byte boundary, or TSB base
633*4882a593Smuzhiyun  *					within a descriptor is not aligned for
634*4882a593Smuzhiyun  *					the given TSB size
635*4882a593Smuzhiyun  *		EBADPGSZ		Invalid page size in a TSB descriptor
636*4882a593Smuzhiyun  *		EBADTSB			Invalid associativity or size in a TSB
637*4882a593Smuzhiyun  *					descriptor
638*4882a593Smuzhiyun  *		EINVAL			Invalid number of TSB descriptions, or
639*4882a593Smuzhiyun  *					invalid context index in a TSB
640*4882a593Smuzhiyun  *					descriptor, or index page size not
641*4882a593Smuzhiyun  *					equal to smallest page size in page
642*4882a593Smuzhiyun  *					size bitmask field.
643*4882a593Smuzhiyun  *
644*4882a593Smuzhiyun  * Configures the TSBs for the current CPU for virtual addresses with
645*4882a593Smuzhiyun  * context zero.  The TSB descriptions pointer is a pointer to an
646*4882a593Smuzhiyun  * array of the given number of TSB descriptions.
647*4882a593Smuzhiyun  *
648*4882a593Smuzhiyun  * Note: The maximum number of TSBs available to a virtual CPU is given by the
649*4882a593Smuzhiyun  *       mmu-max-#tsbs property of the cpu's corresponding "cpu" node in the
650*4882a593Smuzhiyun  *       machine description.
651*4882a593Smuzhiyun  */
652*4882a593Smuzhiyun #define HV_FAST_MMU_TSB_CTX0		0x20
653*4882a593Smuzhiyun 
654*4882a593Smuzhiyun #ifndef __ASSEMBLY__
655*4882a593Smuzhiyun unsigned long sun4v_mmu_tsb_ctx0(unsigned long num_descriptions,
656*4882a593Smuzhiyun 				 unsigned long tsb_desc_ra);
657*4882a593Smuzhiyun #endif
658*4882a593Smuzhiyun 
659*4882a593Smuzhiyun /* mmu_tsb_ctxnon0()
660*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
661*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_MMU_TSB_CTXNON0
662*4882a593Smuzhiyun  * ARG0:	number of TSB descriptions
663*4882a593Smuzhiyun  * ARG1:	TSB descriptions pointer
664*4882a593Smuzhiyun  * RET0:	status
665*4882a593Smuzhiyun  * ERRORS:	Same as for mmu_tsb_ctx0() above.
666*4882a593Smuzhiyun  *
667*4882a593Smuzhiyun  * Configures the TSBs for the current CPU for virtual addresses with
668*4882a593Smuzhiyun  * non-zero contexts.  The TSB descriptions pointer is a pointer to an
669*4882a593Smuzhiyun  * array of the given number of TSB descriptions.
670*4882a593Smuzhiyun  *
671*4882a593Smuzhiyun  * Note: A maximum of 16 TSBs may be specified in the TSB description list.
672*4882a593Smuzhiyun  */
673*4882a593Smuzhiyun #define HV_FAST_MMU_TSB_CTXNON0		0x21
674*4882a593Smuzhiyun 
675*4882a593Smuzhiyun /* mmu_demap_page()
676*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
677*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_MMU_DEMAP_PAGE
678*4882a593Smuzhiyun  * ARG0:	reserved, must be zero
679*4882a593Smuzhiyun  * ARG1:	reserved, must be zero
680*4882a593Smuzhiyun  * ARG2:	virtual address
681*4882a593Smuzhiyun  * ARG3:	mmu context
682*4882a593Smuzhiyun  * ARG4:	flags (HV_MMU_{IMMU,DMMU})
683*4882a593Smuzhiyun  * RET0:	status
684*4882a593Smuzhiyun  * ERRORS:	EINVAL			Invalid virtual address, context, or
685*4882a593Smuzhiyun  *					flags value
686*4882a593Smuzhiyun  *		ENOTSUPPORTED		ARG0 or ARG1 is non-zero
687*4882a593Smuzhiyun  *
688*4882a593Smuzhiyun  * Demaps any page mapping of the given virtual address in the given
689*4882a593Smuzhiyun  * mmu context for the current virtual CPU.  Any virtually tagged
690*4882a593Smuzhiyun  * caches are guaranteed to be kept consistent.  The flags argument
691*4882a593Smuzhiyun  * determines which TLB (instruction, or data, or both) participate in
692*4882a593Smuzhiyun  * the operation.
693*4882a593Smuzhiyun  *
694*4882a593Smuzhiyun  * ARG0 and ARG1 are both reserved and must be set to zero.
695*4882a593Smuzhiyun  */
696*4882a593Smuzhiyun #define HV_FAST_MMU_DEMAP_PAGE		0x22
697*4882a593Smuzhiyun 
698*4882a593Smuzhiyun /* mmu_demap_ctx()
699*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
700*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_MMU_DEMAP_CTX
701*4882a593Smuzhiyun  * ARG0:	reserved, must be zero
702*4882a593Smuzhiyun  * ARG1:	reserved, must be zero
703*4882a593Smuzhiyun  * ARG2:	mmu context
704*4882a593Smuzhiyun  * ARG3:	flags (HV_MMU_{IMMU,DMMU})
705*4882a593Smuzhiyun  * RET0:	status
706*4882a593Smuzhiyun  * ERRORS:	EINVAL			Invalid context or flags value
707*4882a593Smuzhiyun  *		ENOTSUPPORTED		ARG0 or ARG1 is non-zero
708*4882a593Smuzhiyun  *
709*4882a593Smuzhiyun  * Demaps all non-permanent virtual page mappings previously specified
710*4882a593Smuzhiyun  * for the given context for the current virtual CPU.  Any virtual
711*4882a593Smuzhiyun  * tagged caches are guaranteed to be kept consistent.  The flags
712*4882a593Smuzhiyun  * argument determines which TLB (instruction, or data, or both)
713*4882a593Smuzhiyun  * participate in the operation.
714*4882a593Smuzhiyun  *
715*4882a593Smuzhiyun  * ARG0 and ARG1 are both reserved and must be set to zero.
716*4882a593Smuzhiyun  */
717*4882a593Smuzhiyun #define HV_FAST_MMU_DEMAP_CTX		0x23
718*4882a593Smuzhiyun 
719*4882a593Smuzhiyun /* mmu_demap_all()
720*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
721*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_MMU_DEMAP_ALL
722*4882a593Smuzhiyun  * ARG0:	reserved, must be zero
723*4882a593Smuzhiyun  * ARG1:	reserved, must be zero
724*4882a593Smuzhiyun  * ARG2:	flags (HV_MMU_{IMMU,DMMU})
725*4882a593Smuzhiyun  * RET0:	status
726*4882a593Smuzhiyun  * ERRORS:	EINVAL			Invalid flags value
727*4882a593Smuzhiyun  *		ENOTSUPPORTED		ARG0 or ARG1 is non-zero
728*4882a593Smuzhiyun  *
729*4882a593Smuzhiyun  * Demaps all non-permanent virtual page mappings previously specified
730*4882a593Smuzhiyun  * for the current virtual CPU.  Any virtual tagged caches are
731*4882a593Smuzhiyun  * guaranteed to be kept consistent.  The flags argument determines
732*4882a593Smuzhiyun  * which TLB (instruction, or data, or both) participate in the
733*4882a593Smuzhiyun  * operation.
734*4882a593Smuzhiyun  *
735*4882a593Smuzhiyun  * ARG0 and ARG1 are both reserved and must be set to zero.
736*4882a593Smuzhiyun  */
737*4882a593Smuzhiyun #define HV_FAST_MMU_DEMAP_ALL		0x24
738*4882a593Smuzhiyun 
739*4882a593Smuzhiyun #ifndef __ASSEMBLY__
740*4882a593Smuzhiyun void sun4v_mmu_demap_all(void);
741*4882a593Smuzhiyun #endif
742*4882a593Smuzhiyun 
743*4882a593Smuzhiyun /* mmu_map_perm_addr()
744*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
745*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_MMU_MAP_PERM_ADDR
746*4882a593Smuzhiyun  * ARG0:	virtual address
747*4882a593Smuzhiyun  * ARG1:	reserved, must be zero
748*4882a593Smuzhiyun  * ARG2:	TTE
749*4882a593Smuzhiyun  * ARG3:	flags (HV_MMU_{IMMU,DMMU})
750*4882a593Smuzhiyun  * RET0:	status
751*4882a593Smuzhiyun  * ERRORS:	EINVAL			Invalid virtual address or flags value
752*4882a593Smuzhiyun  *		EBADPGSZ		Invalid page size value
753*4882a593Smuzhiyun  *		ENORADDR		Invalid real address in TTE
754*4882a593Smuzhiyun  *		ETOOMANY		Too many mappings (max of 8 reached)
755*4882a593Smuzhiyun  *
756*4882a593Smuzhiyun  * Create a permanent mapping using the given TTE and virtual address
757*4882a593Smuzhiyun  * for context 0 on the calling virtual CPU.  A maximum of 8 such
758*4882a593Smuzhiyun  * permanent mappings may be specified by privileged code.  Mappings
759*4882a593Smuzhiyun  * may be removed with mmu_unmap_perm_addr().
760*4882a593Smuzhiyun  *
761*4882a593Smuzhiyun  * The behavior is undefined if a TTE with the valid bit clear is given.
762*4882a593Smuzhiyun  *
763*4882a593Smuzhiyun  * Note: This call is used to specify address space mappings for which
764*4882a593Smuzhiyun  *       privileged code does not expect to receive misses.  For example,
765*4882a593Smuzhiyun  *       this mechanism can be used to map kernel nucleus code and data.
766*4882a593Smuzhiyun  */
767*4882a593Smuzhiyun #define HV_FAST_MMU_MAP_PERM_ADDR	0x25
768*4882a593Smuzhiyun 
769*4882a593Smuzhiyun #ifndef __ASSEMBLY__
770*4882a593Smuzhiyun unsigned long sun4v_mmu_map_perm_addr(unsigned long vaddr,
771*4882a593Smuzhiyun 				      unsigned long set_to_zero,
772*4882a593Smuzhiyun 				      unsigned long tte,
773*4882a593Smuzhiyun 				      unsigned long flags);
774*4882a593Smuzhiyun #endif
775*4882a593Smuzhiyun 
776*4882a593Smuzhiyun /* mmu_fault_area_conf()
777*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
778*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_MMU_FAULT_AREA_CONF
779*4882a593Smuzhiyun  * ARG0:	real address
780*4882a593Smuzhiyun  * RET0:	status
781*4882a593Smuzhiyun  * RET1:	previous mmu fault area real address
782*4882a593Smuzhiyun  * ERRORS:	ENORADDR		Invalid real address
783*4882a593Smuzhiyun  *		EBADALIGN		Invalid alignment for fault area
784*4882a593Smuzhiyun  *
785*4882a593Smuzhiyun  * Configure the MMU fault status area for the calling CPU.  A 64-byte
786*4882a593Smuzhiyun  * aligned real address specifies where MMU fault status information
787*4882a593Smuzhiyun  * is placed.  The return value is the previously specified area, or 0
788*4882a593Smuzhiyun  * for the first invocation.  Specifying a fault area at real address
789*4882a593Smuzhiyun  * 0 is not allowed.
790*4882a593Smuzhiyun  */
791*4882a593Smuzhiyun #define HV_FAST_MMU_FAULT_AREA_CONF	0x26
792*4882a593Smuzhiyun 
793*4882a593Smuzhiyun /* mmu_enable()
794*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
795*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_MMU_ENABLE
796*4882a593Smuzhiyun  * ARG0:	enable flag
797*4882a593Smuzhiyun  * ARG1:	return target address
798*4882a593Smuzhiyun  * RET0:	status
799*4882a593Smuzhiyun  * ERRORS:	ENORADDR		Invalid real address when disabling
800*4882a593Smuzhiyun  *					translation.
801*4882a593Smuzhiyun  *		EBADALIGN		The return target address is not
802*4882a593Smuzhiyun  *					aligned to an instruction.
803*4882a593Smuzhiyun  *		EINVAL			The enable flag request the current
804*4882a593Smuzhiyun  *					operating mode (e.g. disable if already
805*4882a593Smuzhiyun  *					disabled)
806*4882a593Smuzhiyun  *
807*4882a593Smuzhiyun  * Enable or disable virtual address translation for the calling CPU
808*4882a593Smuzhiyun  * within the virtual machine domain.  If the enable flag is zero,
809*4882a593Smuzhiyun  * translation is disabled, any non-zero value will enable
810*4882a593Smuzhiyun  * translation.
811*4882a593Smuzhiyun  *
812*4882a593Smuzhiyun  * When this function returns, the newly selected translation mode
813*4882a593Smuzhiyun  * will be active.  If the mmu is being enabled, then the return
814*4882a593Smuzhiyun  * target address is a virtual address else it is a real address.
815*4882a593Smuzhiyun  *
816*4882a593Smuzhiyun  * Upon successful completion, control will be returned to the given
817*4882a593Smuzhiyun  * return target address (ie. the cpu will jump to that address).  On
818*4882a593Smuzhiyun  * failure, the previous mmu mode remains and the trap simply returns
819*4882a593Smuzhiyun  * as normal with the appropriate error code in RET0.
820*4882a593Smuzhiyun  */
821*4882a593Smuzhiyun #define HV_FAST_MMU_ENABLE		0x27
822*4882a593Smuzhiyun 
823*4882a593Smuzhiyun /* mmu_unmap_perm_addr()
824*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
825*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_MMU_UNMAP_PERM_ADDR
826*4882a593Smuzhiyun  * ARG0:	virtual address
827*4882a593Smuzhiyun  * ARG1:	reserved, must be zero
828*4882a593Smuzhiyun  * ARG2:	flags (HV_MMU_{IMMU,DMMU})
829*4882a593Smuzhiyun  * RET0:	status
830*4882a593Smuzhiyun  * ERRORS:	EINVAL			Invalid virtual address or flags value
831*4882a593Smuzhiyun  *		ENOMAP			Specified mapping was not found
832*4882a593Smuzhiyun  *
833*4882a593Smuzhiyun  * Demaps any permanent page mapping (established via
834*4882a593Smuzhiyun  * mmu_map_perm_addr()) at the given virtual address for context 0 on
835*4882a593Smuzhiyun  * the current virtual CPU.  Any virtual tagged caches are guaranteed
836*4882a593Smuzhiyun  * to be kept consistent.
837*4882a593Smuzhiyun  */
838*4882a593Smuzhiyun #define HV_FAST_MMU_UNMAP_PERM_ADDR	0x28
839*4882a593Smuzhiyun 
840*4882a593Smuzhiyun /* mmu_tsb_ctx0_info()
841*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
842*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_MMU_TSB_CTX0_INFO
843*4882a593Smuzhiyun  * ARG0:	max TSBs
844*4882a593Smuzhiyun  * ARG1:	buffer pointer
845*4882a593Smuzhiyun  * RET0:	status
846*4882a593Smuzhiyun  * RET1:	number of TSBs
847*4882a593Smuzhiyun  * ERRORS:	EINVAL			Supplied buffer is too small
848*4882a593Smuzhiyun  *		EBADALIGN		The buffer pointer is badly aligned
849*4882a593Smuzhiyun  *		ENORADDR		Invalid real address for buffer pointer
850*4882a593Smuzhiyun  *
851*4882a593Smuzhiyun  * Return the TSB configuration as previous defined by mmu_tsb_ctx0()
852*4882a593Smuzhiyun  * into the provided buffer.  The size of the buffer is given in ARG1
853*4882a593Smuzhiyun  * in terms of the number of TSB description entries.
854*4882a593Smuzhiyun  *
855*4882a593Smuzhiyun  * Upon return, RET1 always contains the number of TSB descriptions
856*4882a593Smuzhiyun  * previously configured.  If zero TSBs were configured, EOK is
857*4882a593Smuzhiyun  * returned with RET1 containing 0.
858*4882a593Smuzhiyun  */
859*4882a593Smuzhiyun #define HV_FAST_MMU_TSB_CTX0_INFO	0x29
860*4882a593Smuzhiyun 
861*4882a593Smuzhiyun /* mmu_tsb_ctxnon0_info()
862*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
863*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_MMU_TSB_CTXNON0_INFO
864*4882a593Smuzhiyun  * ARG0:	max TSBs
865*4882a593Smuzhiyun  * ARG1:	buffer pointer
866*4882a593Smuzhiyun  * RET0:	status
867*4882a593Smuzhiyun  * RET1:	number of TSBs
868*4882a593Smuzhiyun  * ERRORS:	EINVAL			Supplied buffer is too small
869*4882a593Smuzhiyun  *		EBADALIGN		The buffer pointer is badly aligned
870*4882a593Smuzhiyun  *		ENORADDR		Invalid real address for buffer pointer
871*4882a593Smuzhiyun  *
872*4882a593Smuzhiyun  * Return the TSB configuration as previous defined by
873*4882a593Smuzhiyun  * mmu_tsb_ctxnon0() into the provided buffer.  The size of the buffer
874*4882a593Smuzhiyun  * is given in ARG1 in terms of the number of TSB description entries.
875*4882a593Smuzhiyun  *
876*4882a593Smuzhiyun  * Upon return, RET1 always contains the number of TSB descriptions
877*4882a593Smuzhiyun  * previously configured.  If zero TSBs were configured, EOK is
878*4882a593Smuzhiyun  * returned with RET1 containing 0.
879*4882a593Smuzhiyun  */
880*4882a593Smuzhiyun #define HV_FAST_MMU_TSB_CTXNON0_INFO	0x2a
881*4882a593Smuzhiyun 
882*4882a593Smuzhiyun /* mmu_fault_area_info()
883*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
884*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_MMU_FAULT_AREA_INFO
885*4882a593Smuzhiyun  * RET0:	status
886*4882a593Smuzhiyun  * RET1:	fault area real address
887*4882a593Smuzhiyun  * ERRORS:	No errors defined.
888*4882a593Smuzhiyun  *
889*4882a593Smuzhiyun  * Return the currently defined MMU fault status area for the current
890*4882a593Smuzhiyun  * CPU.  The real address of the fault status area is returned in
891*4882a593Smuzhiyun  * RET1, or 0 is returned in RET1 if no fault status area is defined.
892*4882a593Smuzhiyun  *
893*4882a593Smuzhiyun  * Note: mmu_fault_area_conf() may be called with the return value (RET1)
894*4882a593Smuzhiyun  *       from this service if there is a need to save and restore the fault
895*4882a593Smuzhiyun  *	 area for a cpu.
896*4882a593Smuzhiyun  */
897*4882a593Smuzhiyun #define HV_FAST_MMU_FAULT_AREA_INFO	0x2b
898*4882a593Smuzhiyun 
899*4882a593Smuzhiyun /* Cache and Memory services. */
900*4882a593Smuzhiyun 
901*4882a593Smuzhiyun /* mem_scrub()
902*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
903*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_MEM_SCRUB
904*4882a593Smuzhiyun  * ARG0:	real address
905*4882a593Smuzhiyun  * ARG1:	length
906*4882a593Smuzhiyun  * RET0:	status
907*4882a593Smuzhiyun  * RET1:	length scrubbed
908*4882a593Smuzhiyun  * ERRORS:	ENORADDR	Invalid real address
909*4882a593Smuzhiyun  *		EBADALIGN	Start address or length are not correctly
910*4882a593Smuzhiyun  *				aligned
911*4882a593Smuzhiyun  *		EINVAL		Length is zero
912*4882a593Smuzhiyun  *
913*4882a593Smuzhiyun  * Zero the memory contents in the range real address to real address
914*4882a593Smuzhiyun  * plus length minus 1.  Also, valid ECC will be generated for that
915*4882a593Smuzhiyun  * memory address range.  Scrubbing is started at the given real
916*4882a593Smuzhiyun  * address, but may not scrub the entire given length.  The actual
917*4882a593Smuzhiyun  * length scrubbed will be returned in RET1.
918*4882a593Smuzhiyun  *
919*4882a593Smuzhiyun  * The real address and length must be aligned on an 8K boundary, or
920*4882a593Smuzhiyun  * contain the start address and length from a sun4v error report.
921*4882a593Smuzhiyun  *
922*4882a593Smuzhiyun  * Note: There are two uses for this function.  The first use is to block clear
923*4882a593Smuzhiyun  *       and initialize memory and the second is to scrub an u ncorrectable
924*4882a593Smuzhiyun  *       error reported via a resumable or non-resumable trap.  The second
925*4882a593Smuzhiyun  *       use requires the arguments to be equal to the real address and length
926*4882a593Smuzhiyun  *       provided in a sun4v memory error report.
927*4882a593Smuzhiyun  */
928*4882a593Smuzhiyun #define HV_FAST_MEM_SCRUB		0x31
929*4882a593Smuzhiyun 
930*4882a593Smuzhiyun /* mem_sync()
931*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
932*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_MEM_SYNC
933*4882a593Smuzhiyun  * ARG0:	real address
934*4882a593Smuzhiyun  * ARG1:	length
935*4882a593Smuzhiyun  * RET0:	status
936*4882a593Smuzhiyun  * RET1:	length synced
937*4882a593Smuzhiyun  * ERRORS:	ENORADDR	Invalid real address
938*4882a593Smuzhiyun  *		EBADALIGN	Start address or length are not correctly
939*4882a593Smuzhiyun  *				aligned
940*4882a593Smuzhiyun  *		EINVAL		Length is zero
941*4882a593Smuzhiyun  *
942*4882a593Smuzhiyun  * Force the next access within the real address to real address plus
943*4882a593Smuzhiyun  * length minus 1 to be fetches from main system memory.  Less than
944*4882a593Smuzhiyun  * the given length may be synced, the actual amount synced is
945*4882a593Smuzhiyun  * returned in RET1.  The real address and length must be aligned on
946*4882a593Smuzhiyun  * an 8K boundary.
947*4882a593Smuzhiyun  */
948*4882a593Smuzhiyun #define HV_FAST_MEM_SYNC		0x32
949*4882a593Smuzhiyun 
950*4882a593Smuzhiyun /* Coprocessor services
951*4882a593Smuzhiyun  *
952*4882a593Smuzhiyun  * M7 and later processors provide an on-chip coprocessor which
953*4882a593Smuzhiyun  * accelerates database operations, and is known internally as
954*4882a593Smuzhiyun  * DAX.
955*4882a593Smuzhiyun  */
956*4882a593Smuzhiyun 
957*4882a593Smuzhiyun /* ccb_submit()
958*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
959*4882a593Smuzhiyun  * FUNCTION:	HV_CCB_SUBMIT
960*4882a593Smuzhiyun  * ARG0:	address of CCB array
961*4882a593Smuzhiyun  * ARG1:	size (in bytes) of CCB array being submitted
962*4882a593Smuzhiyun  * ARG2:	flags
963*4882a593Smuzhiyun  * ARG3:	reserved
964*4882a593Smuzhiyun  * RET0:	status (success or error code)
965*4882a593Smuzhiyun  * RET1:	size (in bytes) of CCB array that was accepted (might be less
966*4882a593Smuzhiyun  *		than arg1)
967*4882a593Smuzhiyun  * RET2:	status data
968*4882a593Smuzhiyun  *		if status == ENOMAP or ENOACCESS, identifies the VA in question
969*4882a593Smuzhiyun  *		if status == EUNAVAILBLE, unavailable code
970*4882a593Smuzhiyun  * RET3:	reserved
971*4882a593Smuzhiyun  *
972*4882a593Smuzhiyun  * ERRORS:	EOK		successful submission (check size)
973*4882a593Smuzhiyun  *		EWOULDBLOCK	could not finish submissions, try again
974*4882a593Smuzhiyun  *		EBADALIGN	array not 64B aligned or size not 64B multiple
975*4882a593Smuzhiyun  *		ENORADDR	invalid RA for array or in CCB
976*4882a593Smuzhiyun  *		ENOMAP		could not translate address (see status data)
977*4882a593Smuzhiyun  *		EINVAL		invalid ccb or arguments
978*4882a593Smuzhiyun  *		ETOOMANY	too many ccbs with all-or-nothing flag
979*4882a593Smuzhiyun  *		ENOACCESS	guest has no access to submit ccbs or address
980*4882a593Smuzhiyun  *				in CCB does not have correct permissions (check
981*4882a593Smuzhiyun  *				status data)
982*4882a593Smuzhiyun  *		EUNAVAILABLE	ccb operation could not be performed at this
983*4882a593Smuzhiyun  *				time (check status data)
984*4882a593Smuzhiyun  *				Status data codes:
985*4882a593Smuzhiyun  *					0 - exact CCB could not be executed
986*4882a593Smuzhiyun  *					1 - CCB opcode cannot be executed
987*4882a593Smuzhiyun  *					2 - CCB version cannot be executed
988*4882a593Smuzhiyun  *					3 - vcpu cannot execute CCBs
989*4882a593Smuzhiyun  *					4 - no CCBs can be executed
990*4882a593Smuzhiyun  */
991*4882a593Smuzhiyun 
992*4882a593Smuzhiyun #define HV_CCB_SUBMIT               0x34
993*4882a593Smuzhiyun #ifndef __ASSEMBLY__
994*4882a593Smuzhiyun unsigned long sun4v_ccb_submit(unsigned long ccb_buf,
995*4882a593Smuzhiyun 			       unsigned long len,
996*4882a593Smuzhiyun 			       unsigned long flags,
997*4882a593Smuzhiyun 			       unsigned long reserved,
998*4882a593Smuzhiyun 			       void *submitted_len,
999*4882a593Smuzhiyun 			       void *status_data);
1000*4882a593Smuzhiyun #endif
1001*4882a593Smuzhiyun 
1002*4882a593Smuzhiyun /* flags (ARG2) */
1003*4882a593Smuzhiyun #define HV_CCB_QUERY_CMD		BIT(1)
1004*4882a593Smuzhiyun #define HV_CCB_ARG0_TYPE_REAL		0UL
1005*4882a593Smuzhiyun #define HV_CCB_ARG0_TYPE_PRIMARY	BIT(4)
1006*4882a593Smuzhiyun #define HV_CCB_ARG0_TYPE_SECONDARY	BIT(5)
1007*4882a593Smuzhiyun #define HV_CCB_ARG0_TYPE_NUCLEUS	GENMASK(5, 4)
1008*4882a593Smuzhiyun #define HV_CCB_ARG0_PRIVILEGED		BIT(6)
1009*4882a593Smuzhiyun #define HV_CCB_ALL_OR_NOTHING		BIT(7)
1010*4882a593Smuzhiyun #define HV_CCB_QUEUE_INFO		BIT(8)
1011*4882a593Smuzhiyun #define HV_CCB_VA_REJECT		0UL
1012*4882a593Smuzhiyun #define HV_CCB_VA_SECONDARY		BIT(13)
1013*4882a593Smuzhiyun #define HV_CCB_VA_NUCLEUS		GENMASK(13, 12)
1014*4882a593Smuzhiyun #define HV_CCB_VA_PRIVILEGED		BIT(14)
1015*4882a593Smuzhiyun #define HV_CCB_VA_READ_ADI_DISABLE	BIT(15)	/* DAX2 only */
1016*4882a593Smuzhiyun 
1017*4882a593Smuzhiyun /* ccb_info()
1018*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
1019*4882a593Smuzhiyun  * FUNCTION:	HV_CCB_INFO
1020*4882a593Smuzhiyun  * ARG0:	real address of CCB completion area
1021*4882a593Smuzhiyun  * RET0:	status (success or error code)
1022*4882a593Smuzhiyun  * RET1:	info array
1023*4882a593Smuzhiyun  *			- RET1[0]: CCB state
1024*4882a593Smuzhiyun  *			- RET1[1]: dax unit
1025*4882a593Smuzhiyun  *			- RET1[2]: queue number
1026*4882a593Smuzhiyun  *			- RET1[3]: queue position
1027*4882a593Smuzhiyun  *
1028*4882a593Smuzhiyun  * ERRORS:	EOK		operation successful
1029*4882a593Smuzhiyun  *		EBADALIGN	address not 64B aligned
1030*4882a593Smuzhiyun  *		ENORADDR	RA in address not valid
1031*4882a593Smuzhiyun  *		EINVAL		CA not valid
1032*4882a593Smuzhiyun  *		EWOULDBLOCK	info not available for this CCB currently, try
1033*4882a593Smuzhiyun  *				again
1034*4882a593Smuzhiyun  *		ENOACCESS	guest cannot use dax
1035*4882a593Smuzhiyun  */
1036*4882a593Smuzhiyun 
1037*4882a593Smuzhiyun #define HV_CCB_INFO                 0x35
1038*4882a593Smuzhiyun #ifndef __ASSEMBLY__
1039*4882a593Smuzhiyun unsigned long sun4v_ccb_info(unsigned long ca,
1040*4882a593Smuzhiyun 			     void *info_arr);
1041*4882a593Smuzhiyun #endif
1042*4882a593Smuzhiyun 
1043*4882a593Smuzhiyun /* info array byte offsets (RET1) */
1044*4882a593Smuzhiyun #define CCB_INFO_OFFSET_CCB_STATE	0
1045*4882a593Smuzhiyun #define CCB_INFO_OFFSET_DAX_UNIT	2
1046*4882a593Smuzhiyun #define CCB_INFO_OFFSET_QUEUE_NUM	4
1047*4882a593Smuzhiyun #define CCB_INFO_OFFSET_QUEUE_POS	6
1048*4882a593Smuzhiyun 
1049*4882a593Smuzhiyun /* CCB state (RET1[0]) */
1050*4882a593Smuzhiyun #define HV_CCB_STATE_COMPLETED      0
1051*4882a593Smuzhiyun #define HV_CCB_STATE_ENQUEUED       1
1052*4882a593Smuzhiyun #define HV_CCB_STATE_INPROGRESS     2
1053*4882a593Smuzhiyun #define HV_CCB_STATE_NOTFOUND       3
1054*4882a593Smuzhiyun 
1055*4882a593Smuzhiyun /* ccb_kill()
1056*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
1057*4882a593Smuzhiyun  * FUNCTION:	HV_CCB_KILL
1058*4882a593Smuzhiyun  * ARG0:	real address of CCB completion area
1059*4882a593Smuzhiyun  * RET0:	status (success or error code)
1060*4882a593Smuzhiyun  * RET1:	CCB kill status
1061*4882a593Smuzhiyun  *
1062*4882a593Smuzhiyun  * ERRORS:	EOK		operation successful
1063*4882a593Smuzhiyun  *		EBADALIGN	address not 64B aligned
1064*4882a593Smuzhiyun  *		ENORADDR	RA in address not valid
1065*4882a593Smuzhiyun  *		EINVAL		CA not valid
1066*4882a593Smuzhiyun  *		EWOULDBLOCK	kill not available for this CCB currently, try
1067*4882a593Smuzhiyun  *				again
1068*4882a593Smuzhiyun  *		ENOACCESS	guest cannot use dax
1069*4882a593Smuzhiyun  */
1070*4882a593Smuzhiyun 
1071*4882a593Smuzhiyun #define HV_CCB_KILL                 0x36
1072*4882a593Smuzhiyun #ifndef __ASSEMBLY__
1073*4882a593Smuzhiyun unsigned long sun4v_ccb_kill(unsigned long ca,
1074*4882a593Smuzhiyun 			     void *kill_status);
1075*4882a593Smuzhiyun #endif
1076*4882a593Smuzhiyun 
1077*4882a593Smuzhiyun /* CCB kill status (RET1) */
1078*4882a593Smuzhiyun #define HV_CCB_KILL_COMPLETED       0
1079*4882a593Smuzhiyun #define HV_CCB_KILL_DEQUEUED        1
1080*4882a593Smuzhiyun #define HV_CCB_KILL_KILLED          2
1081*4882a593Smuzhiyun #define HV_CCB_KILL_NOTFOUND        3
1082*4882a593Smuzhiyun 
1083*4882a593Smuzhiyun /* Time of day services.
1084*4882a593Smuzhiyun  *
1085*4882a593Smuzhiyun  * The hypervisor maintains the time of day on a per-domain basis.
1086*4882a593Smuzhiyun  * Changing the time of day in one domain does not affect the time of
1087*4882a593Smuzhiyun  * day on any other domain.
1088*4882a593Smuzhiyun  *
1089*4882a593Smuzhiyun  * Time is described by a single unsigned 64-bit word which is the
1090*4882a593Smuzhiyun  * number of seconds since the UNIX Epoch (00:00:00 UTC, January 1,
1091*4882a593Smuzhiyun  * 1970).
1092*4882a593Smuzhiyun  */
1093*4882a593Smuzhiyun 
1094*4882a593Smuzhiyun /* tod_get()
1095*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
1096*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_TOD_GET
1097*4882a593Smuzhiyun  * RET0:	status
1098*4882a593Smuzhiyun  * RET1:	TOD
1099*4882a593Smuzhiyun  * ERRORS:	EWOULDBLOCK	TOD resource is temporarily unavailable
1100*4882a593Smuzhiyun  *		ENOTSUPPORTED	If TOD not supported on this platform
1101*4882a593Smuzhiyun  *
1102*4882a593Smuzhiyun  * Return the current time of day.  May block if TOD access is
1103*4882a593Smuzhiyun  * temporarily not possible.
1104*4882a593Smuzhiyun  */
1105*4882a593Smuzhiyun #define HV_FAST_TOD_GET			0x50
1106*4882a593Smuzhiyun 
1107*4882a593Smuzhiyun #ifndef __ASSEMBLY__
1108*4882a593Smuzhiyun unsigned long sun4v_tod_get(unsigned long *time);
1109*4882a593Smuzhiyun #endif
1110*4882a593Smuzhiyun 
1111*4882a593Smuzhiyun /* tod_set()
1112*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
1113*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_TOD_SET
1114*4882a593Smuzhiyun  * ARG0:	TOD
1115*4882a593Smuzhiyun  * RET0:	status
1116*4882a593Smuzhiyun  * ERRORS:	EWOULDBLOCK	TOD resource is temporarily unavailable
1117*4882a593Smuzhiyun  *		ENOTSUPPORTED	If TOD not supported on this platform
1118*4882a593Smuzhiyun  *
1119*4882a593Smuzhiyun  * The current time of day is set to the value specified in ARG0.  May
1120*4882a593Smuzhiyun  * block if TOD access is temporarily not possible.
1121*4882a593Smuzhiyun  */
1122*4882a593Smuzhiyun #define HV_FAST_TOD_SET			0x51
1123*4882a593Smuzhiyun 
1124*4882a593Smuzhiyun #ifndef __ASSEMBLY__
1125*4882a593Smuzhiyun unsigned long sun4v_tod_set(unsigned long time);
1126*4882a593Smuzhiyun #endif
1127*4882a593Smuzhiyun 
1128*4882a593Smuzhiyun /* Console services */
1129*4882a593Smuzhiyun 
1130*4882a593Smuzhiyun /* con_getchar()
1131*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
1132*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_CONS_GETCHAR
1133*4882a593Smuzhiyun  * RET0:	status
1134*4882a593Smuzhiyun  * RET1:	character
1135*4882a593Smuzhiyun  * ERRORS:	EWOULDBLOCK	No character available.
1136*4882a593Smuzhiyun  *
1137*4882a593Smuzhiyun  * Returns a character from the console device.  If no character is
1138*4882a593Smuzhiyun  * available then an EWOULDBLOCK error is returned.  If a character is
1139*4882a593Smuzhiyun  * available, then the returned status is EOK and the character value
1140*4882a593Smuzhiyun  * is in RET1.
1141*4882a593Smuzhiyun  *
1142*4882a593Smuzhiyun  * A virtual BREAK is represented by the 64-bit value -1.
1143*4882a593Smuzhiyun  *
1144*4882a593Smuzhiyun  * A virtual HUP signal is represented by the 64-bit value -2.
1145*4882a593Smuzhiyun  */
1146*4882a593Smuzhiyun #define HV_FAST_CONS_GETCHAR		0x60
1147*4882a593Smuzhiyun 
1148*4882a593Smuzhiyun /* con_putchar()
1149*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
1150*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_CONS_PUTCHAR
1151*4882a593Smuzhiyun  * ARG0:	character
1152*4882a593Smuzhiyun  * RET0:	status
1153*4882a593Smuzhiyun  * ERRORS:	EINVAL		Illegal character
1154*4882a593Smuzhiyun  *		EWOULDBLOCK	Output buffer currently full, would block
1155*4882a593Smuzhiyun  *
1156*4882a593Smuzhiyun  * Send a character to the console device.  Only character values
1157*4882a593Smuzhiyun  * between 0 and 255 may be used.  Values outside this range are
1158*4882a593Smuzhiyun  * invalid except for the 64-bit value -1 which is used to send a
1159*4882a593Smuzhiyun  * virtual BREAK.
1160*4882a593Smuzhiyun  */
1161*4882a593Smuzhiyun #define HV_FAST_CONS_PUTCHAR		0x61
1162*4882a593Smuzhiyun 
1163*4882a593Smuzhiyun /* con_read()
1164*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
1165*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_CONS_READ
1166*4882a593Smuzhiyun  * ARG0:	buffer real address
1167*4882a593Smuzhiyun  * ARG1:	buffer size in bytes
1168*4882a593Smuzhiyun  * RET0:	status
1169*4882a593Smuzhiyun  * RET1:	bytes read or BREAK or HUP
1170*4882a593Smuzhiyun  * ERRORS:	EWOULDBLOCK	No character available.
1171*4882a593Smuzhiyun  *
1172*4882a593Smuzhiyun  * Reads characters into a buffer from the console device.  If no
1173*4882a593Smuzhiyun  * character is available then an EWOULDBLOCK error is returned.
1174*4882a593Smuzhiyun  * If a character is available, then the returned status is EOK
1175*4882a593Smuzhiyun  * and the number of bytes read into the given buffer is provided
1176*4882a593Smuzhiyun  * in RET1.
1177*4882a593Smuzhiyun  *
1178*4882a593Smuzhiyun  * A virtual BREAK is represented by the 64-bit RET1 value -1.
1179*4882a593Smuzhiyun  *
1180*4882a593Smuzhiyun  * A virtual HUP signal is represented by the 64-bit RET1 value -2.
1181*4882a593Smuzhiyun  *
1182*4882a593Smuzhiyun  * If BREAK or HUP are indicated, no bytes were read into buffer.
1183*4882a593Smuzhiyun  */
1184*4882a593Smuzhiyun #define HV_FAST_CONS_READ		0x62
1185*4882a593Smuzhiyun 
1186*4882a593Smuzhiyun /* con_write()
1187*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
1188*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_CONS_WRITE
1189*4882a593Smuzhiyun  * ARG0:	buffer real address
1190*4882a593Smuzhiyun  * ARG1:	buffer size in bytes
1191*4882a593Smuzhiyun  * RET0:	status
1192*4882a593Smuzhiyun  * RET1:	bytes written
1193*4882a593Smuzhiyun  * ERRORS:	EWOULDBLOCK	Output buffer currently full, would block
1194*4882a593Smuzhiyun  *
1195*4882a593Smuzhiyun  * Send a characters in buffer to the console device.  Breaks must be
1196*4882a593Smuzhiyun  * sent using con_putchar().
1197*4882a593Smuzhiyun  */
1198*4882a593Smuzhiyun #define HV_FAST_CONS_WRITE		0x63
1199*4882a593Smuzhiyun 
1200*4882a593Smuzhiyun #ifndef __ASSEMBLY__
1201*4882a593Smuzhiyun long sun4v_con_getchar(long *status);
1202*4882a593Smuzhiyun long sun4v_con_putchar(long c);
1203*4882a593Smuzhiyun long sun4v_con_read(unsigned long buffer,
1204*4882a593Smuzhiyun 		    unsigned long size,
1205*4882a593Smuzhiyun 		    unsigned long *bytes_read);
1206*4882a593Smuzhiyun unsigned long sun4v_con_write(unsigned long buffer,
1207*4882a593Smuzhiyun 			      unsigned long size,
1208*4882a593Smuzhiyun 			      unsigned long *bytes_written);
1209*4882a593Smuzhiyun #endif
1210*4882a593Smuzhiyun 
1211*4882a593Smuzhiyun /* mach_set_soft_state()
1212*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
1213*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_MACH_SET_SOFT_STATE
1214*4882a593Smuzhiyun  * ARG0:	software state
1215*4882a593Smuzhiyun  * ARG1:	software state description pointer
1216*4882a593Smuzhiyun  * RET0:	status
1217*4882a593Smuzhiyun  * ERRORS:	EINVAL		software state not valid or software state
1218*4882a593Smuzhiyun  *				description is not NULL terminated
1219*4882a593Smuzhiyun  *		ENORADDR	software state description pointer is not a
1220*4882a593Smuzhiyun  *				valid real address
1221*4882a593Smuzhiyun  *		EBADALIGNED	software state description is not correctly
1222*4882a593Smuzhiyun  *				aligned
1223*4882a593Smuzhiyun  *
1224*4882a593Smuzhiyun  * This allows the guest to report it's soft state to the hypervisor.  There
1225*4882a593Smuzhiyun  * are two primary components to this state.  The first part states whether
1226*4882a593Smuzhiyun  * the guest software is running or not.  The second containts optional
1227*4882a593Smuzhiyun  * details specific to the software.
1228*4882a593Smuzhiyun  *
1229*4882a593Smuzhiyun  * The software state argument is defined below in HV_SOFT_STATE_*, and
1230*4882a593Smuzhiyun  * indicates whether the guest is operating normally or in a transitional
1231*4882a593Smuzhiyun  * state.
1232*4882a593Smuzhiyun  *
1233*4882a593Smuzhiyun  * The software state description argument is a real address of a data buffer
1234*4882a593Smuzhiyun  * of size 32-bytes aligned on a 32-byte boundary.  It is treated as a NULL
1235*4882a593Smuzhiyun  * terminated 7-bit ASCII string of up to 31 characters not including the
1236*4882a593Smuzhiyun  * NULL termination.
1237*4882a593Smuzhiyun  */
1238*4882a593Smuzhiyun #define HV_FAST_MACH_SET_SOFT_STATE	0x70
1239*4882a593Smuzhiyun #define  HV_SOFT_STATE_NORMAL		 0x01
1240*4882a593Smuzhiyun #define  HV_SOFT_STATE_TRANSITION	 0x02
1241*4882a593Smuzhiyun 
1242*4882a593Smuzhiyun #ifndef __ASSEMBLY__
1243*4882a593Smuzhiyun unsigned long sun4v_mach_set_soft_state(unsigned long soft_state,
1244*4882a593Smuzhiyun 				        unsigned long msg_string_ra);
1245*4882a593Smuzhiyun #endif
1246*4882a593Smuzhiyun 
1247*4882a593Smuzhiyun /* mach_get_soft_state()
1248*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
1249*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_MACH_GET_SOFT_STATE
1250*4882a593Smuzhiyun  * ARG0:	software state description pointer
1251*4882a593Smuzhiyun  * RET0:	status
1252*4882a593Smuzhiyun  * RET1:	software state
1253*4882a593Smuzhiyun  * ERRORS:	ENORADDR	software state description pointer is not a
1254*4882a593Smuzhiyun  *				valid real address
1255*4882a593Smuzhiyun  *		EBADALIGNED	software state description is not correctly
1256*4882a593Smuzhiyun  *				aligned
1257*4882a593Smuzhiyun  *
1258*4882a593Smuzhiyun  * Retrieve the current value of the guest's software state.  The rules
1259*4882a593Smuzhiyun  * for the software state pointer are the same as for mach_set_soft_state()
1260*4882a593Smuzhiyun  * above.
1261*4882a593Smuzhiyun  */
1262*4882a593Smuzhiyun #define HV_FAST_MACH_GET_SOFT_STATE	0x71
1263*4882a593Smuzhiyun 
1264*4882a593Smuzhiyun /* svc_send()
1265*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
1266*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_SVC_SEND
1267*4882a593Smuzhiyun  * ARG0:	service ID
1268*4882a593Smuzhiyun  * ARG1:	buffer real address
1269*4882a593Smuzhiyun  * ARG2:	buffer size
1270*4882a593Smuzhiyun  * RET0:	STATUS
1271*4882a593Smuzhiyun  * RET1:	sent_bytes
1272*4882a593Smuzhiyun  *
1273*4882a593Smuzhiyun  * Be careful, all output registers are clobbered by this operation,
1274*4882a593Smuzhiyun  * so for example it is not possible to save away a value in %o4
1275*4882a593Smuzhiyun  * across the trap.
1276*4882a593Smuzhiyun  */
1277*4882a593Smuzhiyun #define HV_FAST_SVC_SEND		0x80
1278*4882a593Smuzhiyun 
1279*4882a593Smuzhiyun /* svc_recv()
1280*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
1281*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_SVC_RECV
1282*4882a593Smuzhiyun  * ARG0:	service ID
1283*4882a593Smuzhiyun  * ARG1:	buffer real address
1284*4882a593Smuzhiyun  * ARG2:	buffer size
1285*4882a593Smuzhiyun  * RET0:	STATUS
1286*4882a593Smuzhiyun  * RET1:	recv_bytes
1287*4882a593Smuzhiyun  *
1288*4882a593Smuzhiyun  * Be careful, all output registers are clobbered by this operation,
1289*4882a593Smuzhiyun  * so for example it is not possible to save away a value in %o4
1290*4882a593Smuzhiyun  * across the trap.
1291*4882a593Smuzhiyun  */
1292*4882a593Smuzhiyun #define HV_FAST_SVC_RECV		0x81
1293*4882a593Smuzhiyun 
1294*4882a593Smuzhiyun /* svc_getstatus()
1295*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
1296*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_SVC_GETSTATUS
1297*4882a593Smuzhiyun  * ARG0:	service ID
1298*4882a593Smuzhiyun  * RET0:	STATUS
1299*4882a593Smuzhiyun  * RET1:	status bits
1300*4882a593Smuzhiyun  */
1301*4882a593Smuzhiyun #define HV_FAST_SVC_GETSTATUS		0x82
1302*4882a593Smuzhiyun 
1303*4882a593Smuzhiyun /* svc_setstatus()
1304*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
1305*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_SVC_SETSTATUS
1306*4882a593Smuzhiyun  * ARG0:	service ID
1307*4882a593Smuzhiyun  * ARG1:	bits to set
1308*4882a593Smuzhiyun  * RET0:	STATUS
1309*4882a593Smuzhiyun  */
1310*4882a593Smuzhiyun #define HV_FAST_SVC_SETSTATUS		0x83
1311*4882a593Smuzhiyun 
1312*4882a593Smuzhiyun /* svc_clrstatus()
1313*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
1314*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_SVC_CLRSTATUS
1315*4882a593Smuzhiyun  * ARG0:	service ID
1316*4882a593Smuzhiyun  * ARG1:	bits to clear
1317*4882a593Smuzhiyun  * RET0:	STATUS
1318*4882a593Smuzhiyun  */
1319*4882a593Smuzhiyun #define HV_FAST_SVC_CLRSTATUS		0x84
1320*4882a593Smuzhiyun 
1321*4882a593Smuzhiyun #ifndef __ASSEMBLY__
1322*4882a593Smuzhiyun unsigned long sun4v_svc_send(unsigned long svc_id,
1323*4882a593Smuzhiyun 			     unsigned long buffer,
1324*4882a593Smuzhiyun 			     unsigned long buffer_size,
1325*4882a593Smuzhiyun 			     unsigned long *sent_bytes);
1326*4882a593Smuzhiyun unsigned long sun4v_svc_recv(unsigned long svc_id,
1327*4882a593Smuzhiyun 			     unsigned long buffer,
1328*4882a593Smuzhiyun 			     unsigned long buffer_size,
1329*4882a593Smuzhiyun 			     unsigned long *recv_bytes);
1330*4882a593Smuzhiyun unsigned long sun4v_svc_getstatus(unsigned long svc_id,
1331*4882a593Smuzhiyun 				  unsigned long *status_bits);
1332*4882a593Smuzhiyun unsigned long sun4v_svc_setstatus(unsigned long svc_id,
1333*4882a593Smuzhiyun 				  unsigned long status_bits);
1334*4882a593Smuzhiyun unsigned long sun4v_svc_clrstatus(unsigned long svc_id,
1335*4882a593Smuzhiyun 				  unsigned long status_bits);
1336*4882a593Smuzhiyun #endif
1337*4882a593Smuzhiyun 
1338*4882a593Smuzhiyun /* Trap trace services.
1339*4882a593Smuzhiyun  *
1340*4882a593Smuzhiyun  * The hypervisor provides a trap tracing capability for privileged
1341*4882a593Smuzhiyun  * code running on each virtual CPU.  Privileged code provides a
1342*4882a593Smuzhiyun  * round-robin trap trace queue within which the hypervisor writes
1343*4882a593Smuzhiyun  * 64-byte entries detailing hyperprivileged traps taken n behalf of
1344*4882a593Smuzhiyun  * privileged code.  This is provided as a debugging capability for
1345*4882a593Smuzhiyun  * privileged code.
1346*4882a593Smuzhiyun  *
1347*4882a593Smuzhiyun  * The trap trace control structure is 64-bytes long and placed at the
1348*4882a593Smuzhiyun  * start (offset 0) of the trap trace buffer, and is described as
1349*4882a593Smuzhiyun  * follows:
1350*4882a593Smuzhiyun  */
1351*4882a593Smuzhiyun #ifndef __ASSEMBLY__
1352*4882a593Smuzhiyun struct hv_trap_trace_control {
1353*4882a593Smuzhiyun 	unsigned long		head_offset;
1354*4882a593Smuzhiyun 	unsigned long		tail_offset;
1355*4882a593Smuzhiyun 	unsigned long		__reserved[0x30 / sizeof(unsigned long)];
1356*4882a593Smuzhiyun };
1357*4882a593Smuzhiyun #endif
1358*4882a593Smuzhiyun #define HV_TRAP_TRACE_CTRL_HEAD_OFFSET	0x00
1359*4882a593Smuzhiyun #define HV_TRAP_TRACE_CTRL_TAIL_OFFSET	0x08
1360*4882a593Smuzhiyun 
1361*4882a593Smuzhiyun /* The head offset is the offset of the most recently completed entry
1362*4882a593Smuzhiyun  * in the trap-trace buffer.  The tail offset is the offset of the
1363*4882a593Smuzhiyun  * next entry to be written.  The control structure is owned and
1364*4882a593Smuzhiyun  * modified by the hypervisor.  A guest may not modify the control
1365*4882a593Smuzhiyun  * structure contents.  Attempts to do so will result in undefined
1366*4882a593Smuzhiyun  * behavior for the guest.
1367*4882a593Smuzhiyun  *
1368*4882a593Smuzhiyun  * Each trap trace buffer entry is laid out as follows:
1369*4882a593Smuzhiyun  */
1370*4882a593Smuzhiyun #ifndef __ASSEMBLY__
1371*4882a593Smuzhiyun struct hv_trap_trace_entry {
1372*4882a593Smuzhiyun 	unsigned char	type;		/* Hypervisor or guest entry?	*/
1373*4882a593Smuzhiyun 	unsigned char	hpstate;	/* Hyper-privileged state	*/
1374*4882a593Smuzhiyun 	unsigned char	tl;		/* Trap level			*/
1375*4882a593Smuzhiyun 	unsigned char	gl;		/* Global register level	*/
1376*4882a593Smuzhiyun 	unsigned short	tt;		/* Trap type			*/
1377*4882a593Smuzhiyun 	unsigned short	tag;		/* Extended trap identifier	*/
1378*4882a593Smuzhiyun 	unsigned long	tstate;		/* Trap state			*/
1379*4882a593Smuzhiyun 	unsigned long	tick;		/* Tick				*/
1380*4882a593Smuzhiyun 	unsigned long	tpc;		/* Trap PC			*/
1381*4882a593Smuzhiyun 	unsigned long	f1;		/* Entry specific		*/
1382*4882a593Smuzhiyun 	unsigned long	f2;		/* Entry specific		*/
1383*4882a593Smuzhiyun 	unsigned long	f3;		/* Entry specific		*/
1384*4882a593Smuzhiyun 	unsigned long	f4;		/* Entry specific		*/
1385*4882a593Smuzhiyun };
1386*4882a593Smuzhiyun #endif
1387*4882a593Smuzhiyun #define HV_TRAP_TRACE_ENTRY_TYPE	0x00
1388*4882a593Smuzhiyun #define HV_TRAP_TRACE_ENTRY_HPSTATE	0x01
1389*4882a593Smuzhiyun #define HV_TRAP_TRACE_ENTRY_TL		0x02
1390*4882a593Smuzhiyun #define HV_TRAP_TRACE_ENTRY_GL		0x03
1391*4882a593Smuzhiyun #define HV_TRAP_TRACE_ENTRY_TT		0x04
1392*4882a593Smuzhiyun #define HV_TRAP_TRACE_ENTRY_TAG		0x06
1393*4882a593Smuzhiyun #define HV_TRAP_TRACE_ENTRY_TSTATE	0x08
1394*4882a593Smuzhiyun #define HV_TRAP_TRACE_ENTRY_TICK	0x10
1395*4882a593Smuzhiyun #define HV_TRAP_TRACE_ENTRY_TPC		0x18
1396*4882a593Smuzhiyun #define HV_TRAP_TRACE_ENTRY_F1		0x20
1397*4882a593Smuzhiyun #define HV_TRAP_TRACE_ENTRY_F2		0x28
1398*4882a593Smuzhiyun #define HV_TRAP_TRACE_ENTRY_F3		0x30
1399*4882a593Smuzhiyun #define HV_TRAP_TRACE_ENTRY_F4		0x38
1400*4882a593Smuzhiyun 
1401*4882a593Smuzhiyun /* The type field is encoded as follows.  */
1402*4882a593Smuzhiyun #define HV_TRAP_TYPE_UNDEF		0x00 /* Entry content undefined     */
1403*4882a593Smuzhiyun #define HV_TRAP_TYPE_HV			0x01 /* Hypervisor trap entry       */
1404*4882a593Smuzhiyun #define HV_TRAP_TYPE_GUEST		0xff /* Added via ttrace_addentry() */
1405*4882a593Smuzhiyun 
1406*4882a593Smuzhiyun /* ttrace_buf_conf()
1407*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
1408*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_TTRACE_BUF_CONF
1409*4882a593Smuzhiyun  * ARG0:	real address
1410*4882a593Smuzhiyun  * ARG1:	number of entries
1411*4882a593Smuzhiyun  * RET0:	status
1412*4882a593Smuzhiyun  * RET1:	number of entries
1413*4882a593Smuzhiyun  * ERRORS:	ENORADDR	Invalid real address
1414*4882a593Smuzhiyun  *		EINVAL		Size is too small
1415*4882a593Smuzhiyun  *		EBADALIGN	Real address not aligned on 64-byte boundary
1416*4882a593Smuzhiyun  *
1417*4882a593Smuzhiyun  * Requests hypervisor trap tracing and declares a virtual CPU's trap
1418*4882a593Smuzhiyun  * trace buffer to the hypervisor.  The real address supplies the real
1419*4882a593Smuzhiyun  * base address of the trap trace queue and must be 64-byte aligned.
1420*4882a593Smuzhiyun  * Specifying a value of 0 for the number of entries disables trap
1421*4882a593Smuzhiyun  * tracing for the calling virtual CPU.  The buffer allocated must be
1422*4882a593Smuzhiyun  * sized for a power of two number of 64-byte trap trace entries plus
1423*4882a593Smuzhiyun  * an initial 64-byte control structure.
1424*4882a593Smuzhiyun  *
1425*4882a593Smuzhiyun  * This may be invoked any number of times so that a virtual CPU may
1426*4882a593Smuzhiyun  * relocate a trap trace buffer or create "snapshots" of information.
1427*4882a593Smuzhiyun  *
1428*4882a593Smuzhiyun  * If the real address is illegal or badly aligned, then trap tracing
1429*4882a593Smuzhiyun  * is disabled and an error is returned.
1430*4882a593Smuzhiyun  *
1431*4882a593Smuzhiyun  * Upon failure with EINVAL, this service call returns in RET1 the
1432*4882a593Smuzhiyun  * minimum number of buffer entries required.  Upon other failures
1433*4882a593Smuzhiyun  * RET1 is undefined.
1434*4882a593Smuzhiyun  */
1435*4882a593Smuzhiyun #define HV_FAST_TTRACE_BUF_CONF		0x90
1436*4882a593Smuzhiyun 
1437*4882a593Smuzhiyun /* ttrace_buf_info()
1438*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
1439*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_TTRACE_BUF_INFO
1440*4882a593Smuzhiyun  * RET0:	status
1441*4882a593Smuzhiyun  * RET1:	real address
1442*4882a593Smuzhiyun  * RET2:	size
1443*4882a593Smuzhiyun  * ERRORS:	None defined.
1444*4882a593Smuzhiyun  *
1445*4882a593Smuzhiyun  * Returns the size and location of the previously declared trap-trace
1446*4882a593Smuzhiyun  * buffer.  In the event that no buffer was previously defined, or the
1447*4882a593Smuzhiyun  * buffer is disabled, this call will return a size of zero bytes.
1448*4882a593Smuzhiyun  */
1449*4882a593Smuzhiyun #define HV_FAST_TTRACE_BUF_INFO		0x91
1450*4882a593Smuzhiyun 
1451*4882a593Smuzhiyun /* ttrace_enable()
1452*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
1453*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_TTRACE_ENABLE
1454*4882a593Smuzhiyun  * ARG0:	enable
1455*4882a593Smuzhiyun  * RET0:	status
1456*4882a593Smuzhiyun  * RET1:	previous enable state
1457*4882a593Smuzhiyun  * ERRORS:	EINVAL		No trap trace buffer currently defined
1458*4882a593Smuzhiyun  *
1459*4882a593Smuzhiyun  * Enable or disable trap tracing, and return the previous enabled
1460*4882a593Smuzhiyun  * state in RET1.  Future systems may define various flags for the
1461*4882a593Smuzhiyun  * enable argument (ARG0), for the moment a guest should pass
1462*4882a593Smuzhiyun  * "(uint64_t) -1" to enable, and "(uint64_t) 0" to disable all
1463*4882a593Smuzhiyun  * tracing - which will ensure future compatibility.
1464*4882a593Smuzhiyun  */
1465*4882a593Smuzhiyun #define HV_FAST_TTRACE_ENABLE		0x92
1466*4882a593Smuzhiyun 
1467*4882a593Smuzhiyun /* ttrace_freeze()
1468*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
1469*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_TTRACE_FREEZE
1470*4882a593Smuzhiyun  * ARG0:	freeze
1471*4882a593Smuzhiyun  * RET0:	status
1472*4882a593Smuzhiyun  * RET1:	previous freeze state
1473*4882a593Smuzhiyun  * ERRORS:	EINVAL		No trap trace buffer currently defined
1474*4882a593Smuzhiyun  *
1475*4882a593Smuzhiyun  * Freeze or unfreeze trap tracing, returning the previous freeze
1476*4882a593Smuzhiyun  * state in RET1.  A guest should pass a non-zero value to freeze and
1477*4882a593Smuzhiyun  * a zero value to unfreeze all tracing.  The returned previous state
1478*4882a593Smuzhiyun  * is 0 for not frozen and 1 for frozen.
1479*4882a593Smuzhiyun  */
1480*4882a593Smuzhiyun #define HV_FAST_TTRACE_FREEZE		0x93
1481*4882a593Smuzhiyun 
1482*4882a593Smuzhiyun /* ttrace_addentry()
1483*4882a593Smuzhiyun  * TRAP:	HV_TTRACE_ADDENTRY_TRAP
1484*4882a593Smuzhiyun  * ARG0:	tag (16-bits)
1485*4882a593Smuzhiyun  * ARG1:	data word 0
1486*4882a593Smuzhiyun  * ARG2:	data word 1
1487*4882a593Smuzhiyun  * ARG3:	data word 2
1488*4882a593Smuzhiyun  * ARG4:	data word 3
1489*4882a593Smuzhiyun  * RET0:	status
1490*4882a593Smuzhiyun  * ERRORS:	EINVAL		No trap trace buffer currently defined
1491*4882a593Smuzhiyun  *
1492*4882a593Smuzhiyun  * Add an entry to the trap trace buffer.  Upon return only ARG0/RET0
1493*4882a593Smuzhiyun  * is modified - none of the other registers holding arguments are
1494*4882a593Smuzhiyun  * volatile across this hypervisor service.
1495*4882a593Smuzhiyun  */
1496*4882a593Smuzhiyun 
1497*4882a593Smuzhiyun /* Core dump services.
1498*4882a593Smuzhiyun  *
1499*4882a593Smuzhiyun  * Since the hypervisor viraulizes and thus obscures a lot of the
1500*4882a593Smuzhiyun  * physical machine layout and state, traditional OS crash dumps can
1501*4882a593Smuzhiyun  * be difficult to diagnose especially when the problem is a
1502*4882a593Smuzhiyun  * configuration error of some sort.
1503*4882a593Smuzhiyun  *
1504*4882a593Smuzhiyun  * The dump services provide an opaque buffer into which the
1505*4882a593Smuzhiyun  * hypervisor can place it's internal state in order to assist in
1506*4882a593Smuzhiyun  * debugging such situations.  The contents are opaque and extremely
1507*4882a593Smuzhiyun  * platform and hypervisor implementation specific.  The guest, during
1508*4882a593Smuzhiyun  * a core dump, requests that the hypervisor update any information in
1509*4882a593Smuzhiyun  * the dump buffer in preparation to being dumped as part of the
1510*4882a593Smuzhiyun  * domain's memory image.
1511*4882a593Smuzhiyun  */
1512*4882a593Smuzhiyun 
1513*4882a593Smuzhiyun /* dump_buf_update()
1514*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
1515*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_DUMP_BUF_UPDATE
1516*4882a593Smuzhiyun  * ARG0:	real address
1517*4882a593Smuzhiyun  * ARG1:	size
1518*4882a593Smuzhiyun  * RET0:	status
1519*4882a593Smuzhiyun  * RET1:	required size of dump buffer
1520*4882a593Smuzhiyun  * ERRORS:	ENORADDR	Invalid real address
1521*4882a593Smuzhiyun  *		EBADALIGN	Real address is not aligned on a 64-byte
1522*4882a593Smuzhiyun  *				boundary
1523*4882a593Smuzhiyun  *		EINVAL		Size is non-zero but less than minimum size
1524*4882a593Smuzhiyun  *				required
1525*4882a593Smuzhiyun  *		ENOTSUPPORTED	Operation not supported on current logical
1526*4882a593Smuzhiyun  *				domain
1527*4882a593Smuzhiyun  *
1528*4882a593Smuzhiyun  * Declare a domain dump buffer to the hypervisor.  The real address
1529*4882a593Smuzhiyun  * provided for the domain dump buffer must be 64-byte aligned.  The
1530*4882a593Smuzhiyun  * size specifies the size of the dump buffer and may be larger than
1531*4882a593Smuzhiyun  * the minimum size specified in the machine description.  The
1532*4882a593Smuzhiyun  * hypervisor will fill the dump buffer with opaque data.
1533*4882a593Smuzhiyun  *
1534*4882a593Smuzhiyun  * Note: A guest may elect to include dump buffer contents as part of a crash
1535*4882a593Smuzhiyun  *       dump to assist with debugging.  This function may be called any number
1536*4882a593Smuzhiyun  *       of times so that a guest may relocate a dump buffer, or create
1537*4882a593Smuzhiyun  *       "snapshots" of any dump-buffer information.  Each call to
1538*4882a593Smuzhiyun  *       dump_buf_update() atomically declares the new dump buffer to the
1539*4882a593Smuzhiyun  *       hypervisor.
1540*4882a593Smuzhiyun  *
1541*4882a593Smuzhiyun  * A specified size of 0 unconfigures the dump buffer.  If the real
1542*4882a593Smuzhiyun  * address is illegal or badly aligned, then any currently active dump
1543*4882a593Smuzhiyun  * buffer is disabled and an error is returned.
1544*4882a593Smuzhiyun  *
1545*4882a593Smuzhiyun  * In the event that the call fails with EINVAL, RET1 contains the
1546*4882a593Smuzhiyun  * minimum size requires by the hypervisor for a valid dump buffer.
1547*4882a593Smuzhiyun  */
1548*4882a593Smuzhiyun #define HV_FAST_DUMP_BUF_UPDATE		0x94
1549*4882a593Smuzhiyun 
1550*4882a593Smuzhiyun /* dump_buf_info()
1551*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
1552*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_DUMP_BUF_INFO
1553*4882a593Smuzhiyun  * RET0:	status
1554*4882a593Smuzhiyun  * RET1:	real address of current dump buffer
1555*4882a593Smuzhiyun  * RET2:	size of current dump buffer
1556*4882a593Smuzhiyun  * ERRORS:	No errors defined.
1557*4882a593Smuzhiyun  *
1558*4882a593Smuzhiyun  * Return the currently configures dump buffer description.  A
1559*4882a593Smuzhiyun  * returned size of 0 bytes indicates an undefined dump buffer.  In
1560*4882a593Smuzhiyun  * this case the return address in RET1 is undefined.
1561*4882a593Smuzhiyun  */
1562*4882a593Smuzhiyun #define HV_FAST_DUMP_BUF_INFO		0x95
1563*4882a593Smuzhiyun 
1564*4882a593Smuzhiyun /* Device interrupt services.
1565*4882a593Smuzhiyun  *
1566*4882a593Smuzhiyun  * Device interrupts are allocated to system bus bridges by the hypervisor,
1567*4882a593Smuzhiyun  * and described to OBP in the machine description.  OBP then describes
1568*4882a593Smuzhiyun  * these interrupts to the OS via properties in the device tree.
1569*4882a593Smuzhiyun  *
1570*4882a593Smuzhiyun  * Terminology:
1571*4882a593Smuzhiyun  *
1572*4882a593Smuzhiyun  *	cpuid		Unique opaque value which represents a target cpu.
1573*4882a593Smuzhiyun  *
1574*4882a593Smuzhiyun  *	devhandle	Device handle.  It uniquely identifies a device, and
1575*4882a593Smuzhiyun  *			consistes of the lower 28-bits of the hi-cell of the
1576*4882a593Smuzhiyun  *			first entry of the device's "reg" property in the
1577*4882a593Smuzhiyun  *			OBP device tree.
1578*4882a593Smuzhiyun  *
1579*4882a593Smuzhiyun  *	devino		Device interrupt number.  Specifies the relative
1580*4882a593Smuzhiyun  *			interrupt number within the device.  The unique
1581*4882a593Smuzhiyun  *			combination of devhandle and devino are used to
1582*4882a593Smuzhiyun  *			identify a specific device interrupt.
1583*4882a593Smuzhiyun  *
1584*4882a593Smuzhiyun  *			Note: The devino value is the same as the values in the
1585*4882a593Smuzhiyun  *			      "interrupts" property or "interrupt-map" property
1586*4882a593Smuzhiyun  *			      in the OBP device tree for that device.
1587*4882a593Smuzhiyun  *
1588*4882a593Smuzhiyun  *	sysino		System interrupt number.  A 64-bit unsigned interger
1589*4882a593Smuzhiyun  *			representing a unique interrupt within a virtual
1590*4882a593Smuzhiyun  *			machine.
1591*4882a593Smuzhiyun  *
1592*4882a593Smuzhiyun  *	intr_state	A flag representing the interrupt state for a given
1593*4882a593Smuzhiyun  *			sysino.  The state values are defined below.
1594*4882a593Smuzhiyun  *
1595*4882a593Smuzhiyun  *	intr_enabled	A flag representing the 'enabled' state for a given
1596*4882a593Smuzhiyun  *			sysino.  The enable values are defined below.
1597*4882a593Smuzhiyun  */
1598*4882a593Smuzhiyun 
1599*4882a593Smuzhiyun #define HV_INTR_STATE_IDLE		0 /* Nothing pending */
1600*4882a593Smuzhiyun #define HV_INTR_STATE_RECEIVED		1 /* Interrupt received by hardware */
1601*4882a593Smuzhiyun #define HV_INTR_STATE_DELIVERED		2 /* Interrupt delivered to queue */
1602*4882a593Smuzhiyun 
1603*4882a593Smuzhiyun #define HV_INTR_DISABLED		0 /* sysino not enabled */
1604*4882a593Smuzhiyun #define HV_INTR_ENABLED			1 /* sysino enabled */
1605*4882a593Smuzhiyun 
1606*4882a593Smuzhiyun /* intr_devino_to_sysino()
1607*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
1608*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_INTR_DEVINO2SYSINO
1609*4882a593Smuzhiyun  * ARG0:	devhandle
1610*4882a593Smuzhiyun  * ARG1:	devino
1611*4882a593Smuzhiyun  * RET0:	status
1612*4882a593Smuzhiyun  * RET1:	sysino
1613*4882a593Smuzhiyun  * ERRORS:	EINVAL		Invalid devhandle/devino
1614*4882a593Smuzhiyun  *
1615*4882a593Smuzhiyun  * Converts a device specific interrupt number of the given
1616*4882a593Smuzhiyun  * devhandle/devino into a system specific ino (sysino).
1617*4882a593Smuzhiyun  */
1618*4882a593Smuzhiyun #define HV_FAST_INTR_DEVINO2SYSINO	0xa0
1619*4882a593Smuzhiyun 
1620*4882a593Smuzhiyun #ifndef __ASSEMBLY__
1621*4882a593Smuzhiyun unsigned long sun4v_devino_to_sysino(unsigned long devhandle,
1622*4882a593Smuzhiyun 				     unsigned long devino);
1623*4882a593Smuzhiyun #endif
1624*4882a593Smuzhiyun 
1625*4882a593Smuzhiyun /* intr_getenabled()
1626*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
1627*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_INTR_GETENABLED
1628*4882a593Smuzhiyun  * ARG0:	sysino
1629*4882a593Smuzhiyun  * RET0:	status
1630*4882a593Smuzhiyun  * RET1:	intr_enabled (HV_INTR_{DISABLED,ENABLED})
1631*4882a593Smuzhiyun  * ERRORS:	EINVAL		Invalid sysino
1632*4882a593Smuzhiyun  *
1633*4882a593Smuzhiyun  * Returns interrupt enabled state in RET1 for the interrupt defined
1634*4882a593Smuzhiyun  * by the given sysino.
1635*4882a593Smuzhiyun  */
1636*4882a593Smuzhiyun #define HV_FAST_INTR_GETENABLED		0xa1
1637*4882a593Smuzhiyun 
1638*4882a593Smuzhiyun #ifndef __ASSEMBLY__
1639*4882a593Smuzhiyun unsigned long sun4v_intr_getenabled(unsigned long sysino);
1640*4882a593Smuzhiyun #endif
1641*4882a593Smuzhiyun 
1642*4882a593Smuzhiyun /* intr_setenabled()
1643*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
1644*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_INTR_SETENABLED
1645*4882a593Smuzhiyun  * ARG0:	sysino
1646*4882a593Smuzhiyun  * ARG1:	intr_enabled (HV_INTR_{DISABLED,ENABLED})
1647*4882a593Smuzhiyun  * RET0:	status
1648*4882a593Smuzhiyun  * ERRORS:	EINVAL		Invalid sysino or intr_enabled value
1649*4882a593Smuzhiyun  *
1650*4882a593Smuzhiyun  * Set the 'enabled' state of the interrupt sysino.
1651*4882a593Smuzhiyun  */
1652*4882a593Smuzhiyun #define HV_FAST_INTR_SETENABLED		0xa2
1653*4882a593Smuzhiyun 
1654*4882a593Smuzhiyun #ifndef __ASSEMBLY__
1655*4882a593Smuzhiyun unsigned long sun4v_intr_setenabled(unsigned long sysino,
1656*4882a593Smuzhiyun 				    unsigned long intr_enabled);
1657*4882a593Smuzhiyun #endif
1658*4882a593Smuzhiyun 
1659*4882a593Smuzhiyun /* intr_getstate()
1660*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
1661*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_INTR_GETSTATE
1662*4882a593Smuzhiyun  * ARG0:	sysino
1663*4882a593Smuzhiyun  * RET0:	status
1664*4882a593Smuzhiyun  * RET1:	intr_state (HV_INTR_STATE_*)
1665*4882a593Smuzhiyun  * ERRORS:	EINVAL		Invalid sysino
1666*4882a593Smuzhiyun  *
1667*4882a593Smuzhiyun  * Returns current state of the interrupt defined by the given sysino.
1668*4882a593Smuzhiyun  */
1669*4882a593Smuzhiyun #define HV_FAST_INTR_GETSTATE		0xa3
1670*4882a593Smuzhiyun 
1671*4882a593Smuzhiyun #ifndef __ASSEMBLY__
1672*4882a593Smuzhiyun unsigned long sun4v_intr_getstate(unsigned long sysino);
1673*4882a593Smuzhiyun #endif
1674*4882a593Smuzhiyun 
1675*4882a593Smuzhiyun /* intr_setstate()
1676*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
1677*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_INTR_SETSTATE
1678*4882a593Smuzhiyun  * ARG0:	sysino
1679*4882a593Smuzhiyun  * ARG1:	intr_state (HV_INTR_STATE_*)
1680*4882a593Smuzhiyun  * RET0:	status
1681*4882a593Smuzhiyun  * ERRORS:	EINVAL		Invalid sysino or intr_state value
1682*4882a593Smuzhiyun  *
1683*4882a593Smuzhiyun  * Sets the current state of the interrupt described by the given sysino
1684*4882a593Smuzhiyun  * value.
1685*4882a593Smuzhiyun  *
1686*4882a593Smuzhiyun  * Note: Setting the state to HV_INTR_STATE_IDLE clears any pending
1687*4882a593Smuzhiyun  *       interrupt for sysino.
1688*4882a593Smuzhiyun  */
1689*4882a593Smuzhiyun #define HV_FAST_INTR_SETSTATE		0xa4
1690*4882a593Smuzhiyun 
1691*4882a593Smuzhiyun #ifndef __ASSEMBLY__
1692*4882a593Smuzhiyun unsigned long sun4v_intr_setstate(unsigned long sysino, unsigned long intr_state);
1693*4882a593Smuzhiyun #endif
1694*4882a593Smuzhiyun 
1695*4882a593Smuzhiyun /* intr_gettarget()
1696*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
1697*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_INTR_GETTARGET
1698*4882a593Smuzhiyun  * ARG0:	sysino
1699*4882a593Smuzhiyun  * RET0:	status
1700*4882a593Smuzhiyun  * RET1:	cpuid
1701*4882a593Smuzhiyun  * ERRORS:	EINVAL		Invalid sysino
1702*4882a593Smuzhiyun  *
1703*4882a593Smuzhiyun  * Returns CPU that is the current target of the interrupt defined by
1704*4882a593Smuzhiyun  * the given sysino.  The CPU value returned is undefined if the target
1705*4882a593Smuzhiyun  * has not been set via intr_settarget().
1706*4882a593Smuzhiyun  */
1707*4882a593Smuzhiyun #define HV_FAST_INTR_GETTARGET		0xa5
1708*4882a593Smuzhiyun 
1709*4882a593Smuzhiyun #ifndef __ASSEMBLY__
1710*4882a593Smuzhiyun unsigned long sun4v_intr_gettarget(unsigned long sysino);
1711*4882a593Smuzhiyun #endif
1712*4882a593Smuzhiyun 
1713*4882a593Smuzhiyun /* intr_settarget()
1714*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
1715*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_INTR_SETTARGET
1716*4882a593Smuzhiyun  * ARG0:	sysino
1717*4882a593Smuzhiyun  * ARG1:	cpuid
1718*4882a593Smuzhiyun  * RET0:	status
1719*4882a593Smuzhiyun  * ERRORS:	EINVAL		Invalid sysino
1720*4882a593Smuzhiyun  *		ENOCPU		Invalid cpuid
1721*4882a593Smuzhiyun  *
1722*4882a593Smuzhiyun  * Set the target CPU for the interrupt defined by the given sysino.
1723*4882a593Smuzhiyun  */
1724*4882a593Smuzhiyun #define HV_FAST_INTR_SETTARGET		0xa6
1725*4882a593Smuzhiyun 
1726*4882a593Smuzhiyun #ifndef __ASSEMBLY__
1727*4882a593Smuzhiyun unsigned long sun4v_intr_settarget(unsigned long sysino, unsigned long cpuid);
1728*4882a593Smuzhiyun #endif
1729*4882a593Smuzhiyun 
1730*4882a593Smuzhiyun /* vintr_get_cookie()
1731*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
1732*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_VINTR_GET_COOKIE
1733*4882a593Smuzhiyun  * ARG0:	device handle
1734*4882a593Smuzhiyun  * ARG1:	device ino
1735*4882a593Smuzhiyun  * RET0:	status
1736*4882a593Smuzhiyun  * RET1:	cookie
1737*4882a593Smuzhiyun  */
1738*4882a593Smuzhiyun #define HV_FAST_VINTR_GET_COOKIE	0xa7
1739*4882a593Smuzhiyun 
1740*4882a593Smuzhiyun /* vintr_set_cookie()
1741*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
1742*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_VINTR_SET_COOKIE
1743*4882a593Smuzhiyun  * ARG0:	device handle
1744*4882a593Smuzhiyun  * ARG1:	device ino
1745*4882a593Smuzhiyun  * ARG2:	cookie
1746*4882a593Smuzhiyun  * RET0:	status
1747*4882a593Smuzhiyun  */
1748*4882a593Smuzhiyun #define HV_FAST_VINTR_SET_COOKIE	0xa8
1749*4882a593Smuzhiyun 
1750*4882a593Smuzhiyun /* vintr_get_valid()
1751*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
1752*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_VINTR_GET_VALID
1753*4882a593Smuzhiyun  * ARG0:	device handle
1754*4882a593Smuzhiyun  * ARG1:	device ino
1755*4882a593Smuzhiyun  * RET0:	status
1756*4882a593Smuzhiyun  * RET1:	valid state
1757*4882a593Smuzhiyun  */
1758*4882a593Smuzhiyun #define HV_FAST_VINTR_GET_VALID		0xa9
1759*4882a593Smuzhiyun 
1760*4882a593Smuzhiyun /* vintr_set_valid()
1761*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
1762*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_VINTR_SET_VALID
1763*4882a593Smuzhiyun  * ARG0:	device handle
1764*4882a593Smuzhiyun  * ARG1:	device ino
1765*4882a593Smuzhiyun  * ARG2:	valid state
1766*4882a593Smuzhiyun  * RET0:	status
1767*4882a593Smuzhiyun  */
1768*4882a593Smuzhiyun #define HV_FAST_VINTR_SET_VALID		0xaa
1769*4882a593Smuzhiyun 
1770*4882a593Smuzhiyun /* vintr_get_state()
1771*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
1772*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_VINTR_GET_STATE
1773*4882a593Smuzhiyun  * ARG0:	device handle
1774*4882a593Smuzhiyun  * ARG1:	device ino
1775*4882a593Smuzhiyun  * RET0:	status
1776*4882a593Smuzhiyun  * RET1:	state
1777*4882a593Smuzhiyun  */
1778*4882a593Smuzhiyun #define HV_FAST_VINTR_GET_STATE		0xab
1779*4882a593Smuzhiyun 
1780*4882a593Smuzhiyun /* vintr_set_state()
1781*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
1782*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_VINTR_SET_STATE
1783*4882a593Smuzhiyun  * ARG0:	device handle
1784*4882a593Smuzhiyun  * ARG1:	device ino
1785*4882a593Smuzhiyun  * ARG2:	state
1786*4882a593Smuzhiyun  * RET0:	status
1787*4882a593Smuzhiyun  */
1788*4882a593Smuzhiyun #define HV_FAST_VINTR_SET_STATE		0xac
1789*4882a593Smuzhiyun 
1790*4882a593Smuzhiyun /* vintr_get_target()
1791*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
1792*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_VINTR_GET_TARGET
1793*4882a593Smuzhiyun  * ARG0:	device handle
1794*4882a593Smuzhiyun  * ARG1:	device ino
1795*4882a593Smuzhiyun  * RET0:	status
1796*4882a593Smuzhiyun  * RET1:	cpuid
1797*4882a593Smuzhiyun  */
1798*4882a593Smuzhiyun #define HV_FAST_VINTR_GET_TARGET	0xad
1799*4882a593Smuzhiyun 
1800*4882a593Smuzhiyun /* vintr_set_target()
1801*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
1802*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_VINTR_SET_TARGET
1803*4882a593Smuzhiyun  * ARG0:	device handle
1804*4882a593Smuzhiyun  * ARG1:	device ino
1805*4882a593Smuzhiyun  * ARG2:	cpuid
1806*4882a593Smuzhiyun  * RET0:	status
1807*4882a593Smuzhiyun  */
1808*4882a593Smuzhiyun #define HV_FAST_VINTR_SET_TARGET	0xae
1809*4882a593Smuzhiyun 
1810*4882a593Smuzhiyun #ifndef __ASSEMBLY__
1811*4882a593Smuzhiyun unsigned long sun4v_vintr_get_cookie(unsigned long dev_handle,
1812*4882a593Smuzhiyun 				     unsigned long dev_ino,
1813*4882a593Smuzhiyun 				     unsigned long *cookie);
1814*4882a593Smuzhiyun unsigned long sun4v_vintr_set_cookie(unsigned long dev_handle,
1815*4882a593Smuzhiyun 				     unsigned long dev_ino,
1816*4882a593Smuzhiyun 				     unsigned long cookie);
1817*4882a593Smuzhiyun unsigned long sun4v_vintr_get_valid(unsigned long dev_handle,
1818*4882a593Smuzhiyun 				    unsigned long dev_ino,
1819*4882a593Smuzhiyun 				    unsigned long *valid);
1820*4882a593Smuzhiyun unsigned long sun4v_vintr_set_valid(unsigned long dev_handle,
1821*4882a593Smuzhiyun 				    unsigned long dev_ino,
1822*4882a593Smuzhiyun 				    unsigned long valid);
1823*4882a593Smuzhiyun unsigned long sun4v_vintr_get_state(unsigned long dev_handle,
1824*4882a593Smuzhiyun 				    unsigned long dev_ino,
1825*4882a593Smuzhiyun 				    unsigned long *state);
1826*4882a593Smuzhiyun unsigned long sun4v_vintr_set_state(unsigned long dev_handle,
1827*4882a593Smuzhiyun 				    unsigned long dev_ino,
1828*4882a593Smuzhiyun 				    unsigned long state);
1829*4882a593Smuzhiyun unsigned long sun4v_vintr_get_target(unsigned long dev_handle,
1830*4882a593Smuzhiyun 				     unsigned long dev_ino,
1831*4882a593Smuzhiyun 				     unsigned long *cpuid);
1832*4882a593Smuzhiyun unsigned long sun4v_vintr_set_target(unsigned long dev_handle,
1833*4882a593Smuzhiyun 				     unsigned long dev_ino,
1834*4882a593Smuzhiyun 				     unsigned long cpuid);
1835*4882a593Smuzhiyun #endif
1836*4882a593Smuzhiyun 
1837*4882a593Smuzhiyun /* PCI IO services.
1838*4882a593Smuzhiyun  *
1839*4882a593Smuzhiyun  * See the terminology descriptions in the device interrupt services
1840*4882a593Smuzhiyun  * section above as those apply here too.  Here are terminology
1841*4882a593Smuzhiyun  * definitions specific to these PCI IO services:
1842*4882a593Smuzhiyun  *
1843*4882a593Smuzhiyun  *	tsbnum		TSB number.  Indentifies which io-tsb is used.
1844*4882a593Smuzhiyun  *			For this version of the specification, tsbnum
1845*4882a593Smuzhiyun  *			must be zero.
1846*4882a593Smuzhiyun  *
1847*4882a593Smuzhiyun  *	tsbindex	TSB index.  Identifies which entry in the TSB
1848*4882a593Smuzhiyun  *			is used.  The first entry is zero.
1849*4882a593Smuzhiyun  *
1850*4882a593Smuzhiyun  *	tsbid		A 64-bit aligned data structure which contains
1851*4882a593Smuzhiyun  *			a tsbnum and a tsbindex.  Bits 63:32 contain the
1852*4882a593Smuzhiyun  *			tsbnum and bits 31:00 contain the tsbindex.
1853*4882a593Smuzhiyun  *
1854*4882a593Smuzhiyun  *			Use the HV_PCI_TSBID() macro to construct such
1855*4882a593Smuzhiyun  * 			values.
1856*4882a593Smuzhiyun  *
1857*4882a593Smuzhiyun  *	io_attributes	IO attributes for IOMMU mappings.  One of more
1858*4882a593Smuzhiyun  *			of the attritbute bits are stores in a 64-bit
1859*4882a593Smuzhiyun  *			value.  The values are defined below.
1860*4882a593Smuzhiyun  *
1861*4882a593Smuzhiyun  *	r_addr		64-bit real address
1862*4882a593Smuzhiyun  *
1863*4882a593Smuzhiyun  *	pci_device	PCI device address.  A PCI device address identifies
1864*4882a593Smuzhiyun  *			a specific device on a specific PCI bus segment.
1865*4882a593Smuzhiyun  *			A PCI device address ia a 32-bit unsigned integer
1866*4882a593Smuzhiyun  *			with the following format:
1867*4882a593Smuzhiyun  *
1868*4882a593Smuzhiyun  *				00000000.bbbbbbbb.dddddfff.00000000
1869*4882a593Smuzhiyun  *
1870*4882a593Smuzhiyun  *			Use the HV_PCI_DEVICE_BUILD() macro to construct
1871*4882a593Smuzhiyun  *			such values.
1872*4882a593Smuzhiyun  *
1873*4882a593Smuzhiyun  *	pci_config_offset
1874*4882a593Smuzhiyun  *			PCI configureation space offset.  For conventional
1875*4882a593Smuzhiyun  *			PCI a value between 0 and 255.  For extended
1876*4882a593Smuzhiyun  *			configuration space, a value between 0 and 4095.
1877*4882a593Smuzhiyun  *
1878*4882a593Smuzhiyun  *			Note: For PCI configuration space accesses, the offset
1879*4882a593Smuzhiyun  *			      must be aligned to the access size.
1880*4882a593Smuzhiyun  *
1881*4882a593Smuzhiyun  *	error_flag	A return value which specifies if the action succeeded
1882*4882a593Smuzhiyun  *			or failed.  0 means no error, non-0 means some error
1883*4882a593Smuzhiyun  *			occurred while performing the service.
1884*4882a593Smuzhiyun  *
1885*4882a593Smuzhiyun  *	io_sync_direction
1886*4882a593Smuzhiyun  *			Direction definition for pci_dma_sync(), defined
1887*4882a593Smuzhiyun  *			below in HV_PCI_SYNC_*.
1888*4882a593Smuzhiyun  *
1889*4882a593Smuzhiyun  *	io_page_list	A list of io_page_addresses, an io_page_address is
1890*4882a593Smuzhiyun  *			a real address.
1891*4882a593Smuzhiyun  *
1892*4882a593Smuzhiyun  *	io_page_list_p	A pointer to an io_page_list.
1893*4882a593Smuzhiyun  *
1894*4882a593Smuzhiyun  *	"size based byte swap" - Some functions do size based byte swapping
1895*4882a593Smuzhiyun  *				 which allows sw to access pointers and
1896*4882a593Smuzhiyun  *				 counters in native form when the processor
1897*4882a593Smuzhiyun  *				 operates in a different endianness than the
1898*4882a593Smuzhiyun  *				 IO bus.  Size-based byte swapping converts a
1899*4882a593Smuzhiyun  *				 multi-byte field between big-endian and
1900*4882a593Smuzhiyun  *				 little-endian format.
1901*4882a593Smuzhiyun  */
1902*4882a593Smuzhiyun 
1903*4882a593Smuzhiyun #define HV_PCI_MAP_ATTR_READ		0x01
1904*4882a593Smuzhiyun #define HV_PCI_MAP_ATTR_WRITE		0x02
1905*4882a593Smuzhiyun #define HV_PCI_MAP_ATTR_RELAXED_ORDER	0x04
1906*4882a593Smuzhiyun 
1907*4882a593Smuzhiyun #define HV_PCI_DEVICE_BUILD(b,d,f)	\
1908*4882a593Smuzhiyun 	((((b) & 0xff) << 16) | \
1909*4882a593Smuzhiyun 	 (((d) & 0x1f) << 11) | \
1910*4882a593Smuzhiyun 	 (((f) & 0x07) <<  8))
1911*4882a593Smuzhiyun 
1912*4882a593Smuzhiyun #define HV_PCI_TSBID(__tsb_num, __tsb_index) \
1913*4882a593Smuzhiyun 	((((u64)(__tsb_num)) << 32UL) | ((u64)(__tsb_index)))
1914*4882a593Smuzhiyun 
1915*4882a593Smuzhiyun #define HV_PCI_SYNC_FOR_DEVICE		0x01
1916*4882a593Smuzhiyun #define HV_PCI_SYNC_FOR_CPU		0x02
1917*4882a593Smuzhiyun 
1918*4882a593Smuzhiyun /* pci_iommu_map()
1919*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
1920*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_PCI_IOMMU_MAP
1921*4882a593Smuzhiyun  * ARG0:	devhandle
1922*4882a593Smuzhiyun  * ARG1:	tsbid
1923*4882a593Smuzhiyun  * ARG2:	#ttes
1924*4882a593Smuzhiyun  * ARG3:	io_attributes
1925*4882a593Smuzhiyun  * ARG4:	io_page_list_p
1926*4882a593Smuzhiyun  * RET0:	status
1927*4882a593Smuzhiyun  * RET1:	#ttes mapped
1928*4882a593Smuzhiyun  * ERRORS:	EINVAL		Invalid devhandle/tsbnum/tsbindex/io_attributes
1929*4882a593Smuzhiyun  *		EBADALIGN	Improperly aligned real address
1930*4882a593Smuzhiyun  *		ENORADDR	Invalid real address
1931*4882a593Smuzhiyun  *
1932*4882a593Smuzhiyun  * Create IOMMU mappings in the sun4v device defined by the given
1933*4882a593Smuzhiyun  * devhandle.  The mappings are created in the TSB defined by the
1934*4882a593Smuzhiyun  * tsbnum component of the given tsbid.  The first mapping is created
1935*4882a593Smuzhiyun  * in the TSB i ndex defined by the tsbindex component of the given tsbid.
1936*4882a593Smuzhiyun  * The call creates up to #ttes mappings, the first one at tsbnum, tsbindex,
1937*4882a593Smuzhiyun  * the second at tsbnum, tsbindex + 1, etc.
1938*4882a593Smuzhiyun  *
1939*4882a593Smuzhiyun  * All mappings are created with the attributes defined by the io_attributes
1940*4882a593Smuzhiyun  * argument.  The page mapping addresses are described in the io_page_list
1941*4882a593Smuzhiyun  * defined by the given io_page_list_p, which is a pointer to the io_page_list.
1942*4882a593Smuzhiyun  * The first entry in the io_page_list is the address for the first iotte, the
1943*4882a593Smuzhiyun  * 2nd for the 2nd iotte, and so on.
1944*4882a593Smuzhiyun  *
1945*4882a593Smuzhiyun  * Each io_page_address in the io_page_list must be appropriately aligned.
1946*4882a593Smuzhiyun  * #ttes must be greater than zero.  For this version of the spec, the tsbnum
1947*4882a593Smuzhiyun  * component of the given tsbid must be zero.
1948*4882a593Smuzhiyun  *
1949*4882a593Smuzhiyun  * Returns the actual number of mappings creates, which may be less than
1950*4882a593Smuzhiyun  * or equal to the argument #ttes.  If the function returns a value which
1951*4882a593Smuzhiyun  * is less than the #ttes, the caller may continus to call the function with
1952*4882a593Smuzhiyun  * an updated tsbid, #ttes, io_page_list_p arguments until all pages are
1953*4882a593Smuzhiyun  * mapped.
1954*4882a593Smuzhiyun  *
1955*4882a593Smuzhiyun  * Note: This function does not imply an iotte cache flush.  The guest must
1956*4882a593Smuzhiyun  *       demap an entry before re-mapping it.
1957*4882a593Smuzhiyun  */
1958*4882a593Smuzhiyun #define HV_FAST_PCI_IOMMU_MAP		0xb0
1959*4882a593Smuzhiyun 
1960*4882a593Smuzhiyun /* pci_iommu_demap()
1961*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
1962*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_PCI_IOMMU_DEMAP
1963*4882a593Smuzhiyun  * ARG0:	devhandle
1964*4882a593Smuzhiyun  * ARG1:	tsbid
1965*4882a593Smuzhiyun  * ARG2:	#ttes
1966*4882a593Smuzhiyun  * RET0:	status
1967*4882a593Smuzhiyun  * RET1:	#ttes demapped
1968*4882a593Smuzhiyun  * ERRORS:	EINVAL		Invalid devhandle/tsbnum/tsbindex
1969*4882a593Smuzhiyun  *
1970*4882a593Smuzhiyun  * Demap and flush IOMMU mappings in the device defined by the given
1971*4882a593Smuzhiyun  * devhandle.  Demaps up to #ttes entries in the TSB defined by the tsbnum
1972*4882a593Smuzhiyun  * component of the given tsbid, starting at the TSB index defined by the
1973*4882a593Smuzhiyun  * tsbindex component of the given tsbid.
1974*4882a593Smuzhiyun  *
1975*4882a593Smuzhiyun  * For this version of the spec, the tsbnum of the given tsbid must be zero.
1976*4882a593Smuzhiyun  * #ttes must be greater than zero.
1977*4882a593Smuzhiyun  *
1978*4882a593Smuzhiyun  * Returns the actual number of ttes demapped, which may be less than or equal
1979*4882a593Smuzhiyun  * to the argument #ttes.  If #ttes demapped is less than #ttes, the caller
1980*4882a593Smuzhiyun  * may continue to call this function with updated tsbid and #ttes arguments
1981*4882a593Smuzhiyun  * until all pages are demapped.
1982*4882a593Smuzhiyun  *
1983*4882a593Smuzhiyun  * Note: Entries do not have to be mapped to be demapped.  A demap of an
1984*4882a593Smuzhiyun  *       unmapped page will flush the entry from the tte cache.
1985*4882a593Smuzhiyun  */
1986*4882a593Smuzhiyun #define HV_FAST_PCI_IOMMU_DEMAP		0xb1
1987*4882a593Smuzhiyun 
1988*4882a593Smuzhiyun /* pci_iommu_getmap()
1989*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
1990*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_PCI_IOMMU_GETMAP
1991*4882a593Smuzhiyun  * ARG0:	devhandle
1992*4882a593Smuzhiyun  * ARG1:	tsbid
1993*4882a593Smuzhiyun  * RET0:	status
1994*4882a593Smuzhiyun  * RET1:	io_attributes
1995*4882a593Smuzhiyun  * RET2:	real address
1996*4882a593Smuzhiyun  * ERRORS:	EINVAL		Invalid devhandle/tsbnum/tsbindex
1997*4882a593Smuzhiyun  *		ENOMAP		Mapping is not valid, no translation exists
1998*4882a593Smuzhiyun  *
1999*4882a593Smuzhiyun  * Read and return the mapping in the device described by the given devhandle
2000*4882a593Smuzhiyun  * and tsbid.  If successful, the io_attributes shall be returned in RET1
2001*4882a593Smuzhiyun  * and the page address of the mapping shall be returned in RET2.
2002*4882a593Smuzhiyun  *
2003*4882a593Smuzhiyun  * For this version of the spec, the tsbnum component of the given tsbid
2004*4882a593Smuzhiyun  * must be zero.
2005*4882a593Smuzhiyun  */
2006*4882a593Smuzhiyun #define HV_FAST_PCI_IOMMU_GETMAP	0xb2
2007*4882a593Smuzhiyun 
2008*4882a593Smuzhiyun /* pci_iommu_getbypass()
2009*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
2010*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_PCI_IOMMU_GETBYPASS
2011*4882a593Smuzhiyun  * ARG0:	devhandle
2012*4882a593Smuzhiyun  * ARG1:	real address
2013*4882a593Smuzhiyun  * ARG2:	io_attributes
2014*4882a593Smuzhiyun  * RET0:	status
2015*4882a593Smuzhiyun  * RET1:	io_addr
2016*4882a593Smuzhiyun  * ERRORS:	EINVAL		Invalid devhandle/io_attributes
2017*4882a593Smuzhiyun  *		ENORADDR	Invalid real address
2018*4882a593Smuzhiyun  *		ENOTSUPPORTED	Function not supported in this implementation.
2019*4882a593Smuzhiyun  *
2020*4882a593Smuzhiyun  * Create a "special" mapping in the device described by the given devhandle,
2021*4882a593Smuzhiyun  * for the given real address and attributes.  Return the IO address in RET1
2022*4882a593Smuzhiyun  * if successful.
2023*4882a593Smuzhiyun  */
2024*4882a593Smuzhiyun #define HV_FAST_PCI_IOMMU_GETBYPASS	0xb3
2025*4882a593Smuzhiyun 
2026*4882a593Smuzhiyun /* pci_config_get()
2027*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
2028*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_PCI_CONFIG_GET
2029*4882a593Smuzhiyun  * ARG0:	devhandle
2030*4882a593Smuzhiyun  * ARG1:	pci_device
2031*4882a593Smuzhiyun  * ARG2:	pci_config_offset
2032*4882a593Smuzhiyun  * ARG3:	size
2033*4882a593Smuzhiyun  * RET0:	status
2034*4882a593Smuzhiyun  * RET1:	error_flag
2035*4882a593Smuzhiyun  * RET2:	data
2036*4882a593Smuzhiyun  * ERRORS:	EINVAL		Invalid devhandle/pci_device/offset/size
2037*4882a593Smuzhiyun  *		EBADALIGN	pci_config_offset not size aligned
2038*4882a593Smuzhiyun  *		ENOACCESS	Access to this offset is not permitted
2039*4882a593Smuzhiyun  *
2040*4882a593Smuzhiyun  * Read PCI configuration space for the adapter described by the given
2041*4882a593Smuzhiyun  * devhandle.  Read size (1, 2, or 4) bytes of data from the given
2042*4882a593Smuzhiyun  * pci_device, at pci_config_offset from the beginning of the device's
2043*4882a593Smuzhiyun  * configuration space.  If there was no error, RET1 is set to zero and
2044*4882a593Smuzhiyun  * RET2 is set to the data read.  Insignificant bits in RET2 are not
2045*4882a593Smuzhiyun  * guaranteed to have any specific value and therefore must be ignored.
2046*4882a593Smuzhiyun  *
2047*4882a593Smuzhiyun  * The data returned in RET2 is size based byte swapped.
2048*4882a593Smuzhiyun  *
2049*4882a593Smuzhiyun  * If an error occurs during the read, set RET1 to a non-zero value.  The
2050*4882a593Smuzhiyun  * given pci_config_offset must be 'size' aligned.
2051*4882a593Smuzhiyun  */
2052*4882a593Smuzhiyun #define HV_FAST_PCI_CONFIG_GET		0xb4
2053*4882a593Smuzhiyun 
2054*4882a593Smuzhiyun /* pci_config_put()
2055*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
2056*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_PCI_CONFIG_PUT
2057*4882a593Smuzhiyun  * ARG0:	devhandle
2058*4882a593Smuzhiyun  * ARG1:	pci_device
2059*4882a593Smuzhiyun  * ARG2:	pci_config_offset
2060*4882a593Smuzhiyun  * ARG3:	size
2061*4882a593Smuzhiyun  * ARG4:	data
2062*4882a593Smuzhiyun  * RET0:	status
2063*4882a593Smuzhiyun  * RET1:	error_flag
2064*4882a593Smuzhiyun  * ERRORS:	EINVAL		Invalid devhandle/pci_device/offset/size
2065*4882a593Smuzhiyun  *		EBADALIGN	pci_config_offset not size aligned
2066*4882a593Smuzhiyun  *		ENOACCESS	Access to this offset is not permitted
2067*4882a593Smuzhiyun  *
2068*4882a593Smuzhiyun  * Write PCI configuration space for the adapter described by the given
2069*4882a593Smuzhiyun  * devhandle.  Write size (1, 2, or 4) bytes of data in a single operation,
2070*4882a593Smuzhiyun  * at pci_config_offset from the beginning of the device's configuration
2071*4882a593Smuzhiyun  * space.  The data argument contains the data to be written to configuration
2072*4882a593Smuzhiyun  * space.  Prior to writing, the data is size based byte swapped.
2073*4882a593Smuzhiyun  *
2074*4882a593Smuzhiyun  * If an error occurs during the write access, do not generate an error
2075*4882a593Smuzhiyun  * report, do set RET1 to a non-zero value.  Otherwise RET1 is zero.
2076*4882a593Smuzhiyun  * The given pci_config_offset must be 'size' aligned.
2077*4882a593Smuzhiyun  *
2078*4882a593Smuzhiyun  * This function is permitted to read from offset zero in the configuration
2079*4882a593Smuzhiyun  * space described by the given pci_device if necessary to ensure that the
2080*4882a593Smuzhiyun  * write access to config space completes.
2081*4882a593Smuzhiyun  */
2082*4882a593Smuzhiyun #define HV_FAST_PCI_CONFIG_PUT		0xb5
2083*4882a593Smuzhiyun 
2084*4882a593Smuzhiyun /* pci_peek()
2085*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
2086*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_PCI_PEEK
2087*4882a593Smuzhiyun  * ARG0:	devhandle
2088*4882a593Smuzhiyun  * ARG1:	real address
2089*4882a593Smuzhiyun  * ARG2:	size
2090*4882a593Smuzhiyun  * RET0:	status
2091*4882a593Smuzhiyun  * RET1:	error_flag
2092*4882a593Smuzhiyun  * RET2:	data
2093*4882a593Smuzhiyun  * ERRORS:	EINVAL		Invalid devhandle or size
2094*4882a593Smuzhiyun  *		EBADALIGN	Improperly aligned real address
2095*4882a593Smuzhiyun  *		ENORADDR	Bad real address
2096*4882a593Smuzhiyun  *		ENOACCESS	Guest access prohibited
2097*4882a593Smuzhiyun  *
2098*4882a593Smuzhiyun  * Attempt to read the IO address given by the given devhandle, real address,
2099*4882a593Smuzhiyun  * and size.  Size must be 1, 2, 4, or 8.  The read is performed as a single
2100*4882a593Smuzhiyun  * access operation using the given size.  If an error occurs when reading
2101*4882a593Smuzhiyun  * from the given location, do not generate an error report, but return a
2102*4882a593Smuzhiyun  * non-zero value in RET1.  If the read was successful, return zero in RET1
2103*4882a593Smuzhiyun  * and return the actual data read in RET2.  The data returned is size based
2104*4882a593Smuzhiyun  * byte swapped.
2105*4882a593Smuzhiyun  *
2106*4882a593Smuzhiyun  * Non-significant bits in RET2 are not guaranteed to have any specific value
2107*4882a593Smuzhiyun  * and therefore must be ignored.  If RET1 is returned as non-zero, the data
2108*4882a593Smuzhiyun  * value is not guaranteed to have any specific value and should be ignored.
2109*4882a593Smuzhiyun  *
2110*4882a593Smuzhiyun  * The caller must have permission to read from the given devhandle, real
2111*4882a593Smuzhiyun  * address, which must be an IO address.  The argument real address must be a
2112*4882a593Smuzhiyun  * size aligned address.
2113*4882a593Smuzhiyun  *
2114*4882a593Smuzhiyun  * The hypervisor implementation of this function must block access to any
2115*4882a593Smuzhiyun  * IO address that the guest does not have explicit permission to access.
2116*4882a593Smuzhiyun  */
2117*4882a593Smuzhiyun #define HV_FAST_PCI_PEEK		0xb6
2118*4882a593Smuzhiyun 
2119*4882a593Smuzhiyun /* pci_poke()
2120*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
2121*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_PCI_POKE
2122*4882a593Smuzhiyun  * ARG0:	devhandle
2123*4882a593Smuzhiyun  * ARG1:	real address
2124*4882a593Smuzhiyun  * ARG2:	size
2125*4882a593Smuzhiyun  * ARG3:	data
2126*4882a593Smuzhiyun  * ARG4:	pci_device
2127*4882a593Smuzhiyun  * RET0:	status
2128*4882a593Smuzhiyun  * RET1:	error_flag
2129*4882a593Smuzhiyun  * ERRORS:	EINVAL		Invalid devhandle, size, or pci_device
2130*4882a593Smuzhiyun  *		EBADALIGN	Improperly aligned real address
2131*4882a593Smuzhiyun  *		ENORADDR	Bad real address
2132*4882a593Smuzhiyun  *		ENOACCESS	Guest access prohibited
2133*4882a593Smuzhiyun  *		ENOTSUPPORTED	Function is not supported by implementation
2134*4882a593Smuzhiyun  *
2135*4882a593Smuzhiyun  * Attempt to write data to the IO address given by the given devhandle,
2136*4882a593Smuzhiyun  * real address, and size.  Size must be 1, 2, 4, or 8.  The write is
2137*4882a593Smuzhiyun  * performed as a single access operation using the given size. Prior to
2138*4882a593Smuzhiyun  * writing the data is size based swapped.
2139*4882a593Smuzhiyun  *
2140*4882a593Smuzhiyun  * If an error occurs when writing to the given location, do not generate an
2141*4882a593Smuzhiyun  * error report, but return a non-zero value in RET1.  If the write was
2142*4882a593Smuzhiyun  * successful, return zero in RET1.
2143*4882a593Smuzhiyun  *
2144*4882a593Smuzhiyun  * pci_device describes the configuration address of the device being
2145*4882a593Smuzhiyun  * written to.  The implementation may safely read from offset 0 with
2146*4882a593Smuzhiyun  * the configuration space of the device described by devhandle and
2147*4882a593Smuzhiyun  * pci_device in order to guarantee that the write portion of the operation
2148*4882a593Smuzhiyun  * completes
2149*4882a593Smuzhiyun  *
2150*4882a593Smuzhiyun  * Any error that occurs due to the read shall be reported using the normal
2151*4882a593Smuzhiyun  * error reporting mechanisms .. the read error is not suppressed.
2152*4882a593Smuzhiyun  *
2153*4882a593Smuzhiyun  * The caller must have permission to write to the given devhandle, real
2154*4882a593Smuzhiyun  * address, which must be an IO address.  The argument real address must be a
2155*4882a593Smuzhiyun  * size aligned address.  The caller must have permission to read from
2156*4882a593Smuzhiyun  * the given devhandle, pci_device cofiguration space offset 0.
2157*4882a593Smuzhiyun  *
2158*4882a593Smuzhiyun  * The hypervisor implementation of this function must block access to any
2159*4882a593Smuzhiyun  * IO address that the guest does not have explicit permission to access.
2160*4882a593Smuzhiyun  */
2161*4882a593Smuzhiyun #define HV_FAST_PCI_POKE		0xb7
2162*4882a593Smuzhiyun 
2163*4882a593Smuzhiyun /* pci_dma_sync()
2164*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
2165*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_PCI_DMA_SYNC
2166*4882a593Smuzhiyun  * ARG0:	devhandle
2167*4882a593Smuzhiyun  * ARG1:	real address
2168*4882a593Smuzhiyun  * ARG2:	size
2169*4882a593Smuzhiyun  * ARG3:	io_sync_direction
2170*4882a593Smuzhiyun  * RET0:	status
2171*4882a593Smuzhiyun  * RET1:	#synced
2172*4882a593Smuzhiyun  * ERRORS:	EINVAL		Invalid devhandle or io_sync_direction
2173*4882a593Smuzhiyun  *		ENORADDR	Bad real address
2174*4882a593Smuzhiyun  *
2175*4882a593Smuzhiyun  * Synchronize a memory region described by the given real address and size,
2176*4882a593Smuzhiyun  * for the device defined by the given devhandle using the direction(s)
2177*4882a593Smuzhiyun  * defined by the given io_sync_direction.  The argument size is the size of
2178*4882a593Smuzhiyun  * the memory region in bytes.
2179*4882a593Smuzhiyun  *
2180*4882a593Smuzhiyun  * Return the actual number of bytes synchronized in the return value #synced,
2181*4882a593Smuzhiyun  * which may be less than or equal to the argument size.  If the return
2182*4882a593Smuzhiyun  * value #synced is less than size, the caller must continue to call this
2183*4882a593Smuzhiyun  * function with updated real address and size arguments until the entire
2184*4882a593Smuzhiyun  * memory region is synchronized.
2185*4882a593Smuzhiyun  */
2186*4882a593Smuzhiyun #define HV_FAST_PCI_DMA_SYNC		0xb8
2187*4882a593Smuzhiyun 
2188*4882a593Smuzhiyun /* PCI MSI services.  */
2189*4882a593Smuzhiyun 
2190*4882a593Smuzhiyun #define HV_MSITYPE_MSI32		0x00
2191*4882a593Smuzhiyun #define HV_MSITYPE_MSI64		0x01
2192*4882a593Smuzhiyun 
2193*4882a593Smuzhiyun #define HV_MSIQSTATE_IDLE		0x00
2194*4882a593Smuzhiyun #define HV_MSIQSTATE_ERROR		0x01
2195*4882a593Smuzhiyun 
2196*4882a593Smuzhiyun #define HV_MSIQ_INVALID			0x00
2197*4882a593Smuzhiyun #define HV_MSIQ_VALID			0x01
2198*4882a593Smuzhiyun 
2199*4882a593Smuzhiyun #define HV_MSISTATE_IDLE		0x00
2200*4882a593Smuzhiyun #define HV_MSISTATE_DELIVERED		0x01
2201*4882a593Smuzhiyun 
2202*4882a593Smuzhiyun #define HV_MSIVALID_INVALID		0x00
2203*4882a593Smuzhiyun #define HV_MSIVALID_VALID		0x01
2204*4882a593Smuzhiyun 
2205*4882a593Smuzhiyun #define HV_PCIE_MSGTYPE_PME_MSG		0x18
2206*4882a593Smuzhiyun #define HV_PCIE_MSGTYPE_PME_ACK_MSG	0x1b
2207*4882a593Smuzhiyun #define HV_PCIE_MSGTYPE_CORR_MSG	0x30
2208*4882a593Smuzhiyun #define HV_PCIE_MSGTYPE_NONFATAL_MSG	0x31
2209*4882a593Smuzhiyun #define HV_PCIE_MSGTYPE_FATAL_MSG	0x33
2210*4882a593Smuzhiyun 
2211*4882a593Smuzhiyun #define HV_MSG_INVALID			0x00
2212*4882a593Smuzhiyun #define HV_MSG_VALID			0x01
2213*4882a593Smuzhiyun 
2214*4882a593Smuzhiyun /* pci_msiq_conf()
2215*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
2216*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_PCI_MSIQ_CONF
2217*4882a593Smuzhiyun  * ARG0:	devhandle
2218*4882a593Smuzhiyun  * ARG1:	msiqid
2219*4882a593Smuzhiyun  * ARG2:	real address
2220*4882a593Smuzhiyun  * ARG3:	number of entries
2221*4882a593Smuzhiyun  * RET0:	status
2222*4882a593Smuzhiyun  * ERRORS:	EINVAL		Invalid devhandle, msiqid or nentries
2223*4882a593Smuzhiyun  *		EBADALIGN	Improperly aligned real address
2224*4882a593Smuzhiyun  *		ENORADDR	Bad real address
2225*4882a593Smuzhiyun  *
2226*4882a593Smuzhiyun  * Configure the MSI queue given by the devhandle and msiqid arguments,
2227*4882a593Smuzhiyun  * and to be placed at the given real address and be of the given
2228*4882a593Smuzhiyun  * number of entries.  The real address must be aligned exactly to match
2229*4882a593Smuzhiyun  * the queue size.  Each queue entry is 64-bytes long, so f.e. a 32 entry
2230*4882a593Smuzhiyun  * queue must be aligned on a 2048 byte real address boundary.  The MSI-EQ
2231*4882a593Smuzhiyun  * Head and Tail are initialized so that the MSI-EQ is 'empty'.
2232*4882a593Smuzhiyun  *
2233*4882a593Smuzhiyun  * Implementation Note: Certain implementations have fixed sized queues.  In
2234*4882a593Smuzhiyun  *                      that case, number of entries must contain the correct
2235*4882a593Smuzhiyun  *                      value.
2236*4882a593Smuzhiyun  */
2237*4882a593Smuzhiyun #define HV_FAST_PCI_MSIQ_CONF		0xc0
2238*4882a593Smuzhiyun 
2239*4882a593Smuzhiyun /* pci_msiq_info()
2240*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
2241*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_PCI_MSIQ_INFO
2242*4882a593Smuzhiyun  * ARG0:	devhandle
2243*4882a593Smuzhiyun  * ARG1:	msiqid
2244*4882a593Smuzhiyun  * RET0:	status
2245*4882a593Smuzhiyun  * RET1:	real address
2246*4882a593Smuzhiyun  * RET2:	number of entries
2247*4882a593Smuzhiyun  * ERRORS:	EINVAL		Invalid devhandle or msiqid
2248*4882a593Smuzhiyun  *
2249*4882a593Smuzhiyun  * Return the configuration information for the MSI queue described
2250*4882a593Smuzhiyun  * by the given devhandle and msiqid.  The base address of the queue
2251*4882a593Smuzhiyun  * is returned in ARG1 and the number of entries is returned in ARG2.
2252*4882a593Smuzhiyun  * If the queue is unconfigured, the real address is undefined and the
2253*4882a593Smuzhiyun  * number of entries will be returned as zero.
2254*4882a593Smuzhiyun  */
2255*4882a593Smuzhiyun #define HV_FAST_PCI_MSIQ_INFO		0xc1
2256*4882a593Smuzhiyun 
2257*4882a593Smuzhiyun /* pci_msiq_getvalid()
2258*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
2259*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_PCI_MSIQ_GETVALID
2260*4882a593Smuzhiyun  * ARG0:	devhandle
2261*4882a593Smuzhiyun  * ARG1:	msiqid
2262*4882a593Smuzhiyun  * RET0:	status
2263*4882a593Smuzhiyun  * RET1:	msiqvalid	(HV_MSIQ_VALID or HV_MSIQ_INVALID)
2264*4882a593Smuzhiyun  * ERRORS:	EINVAL		Invalid devhandle or msiqid
2265*4882a593Smuzhiyun  *
2266*4882a593Smuzhiyun  * Get the valid state of the MSI-EQ described by the given devhandle and
2267*4882a593Smuzhiyun  * msiqid.
2268*4882a593Smuzhiyun  */
2269*4882a593Smuzhiyun #define HV_FAST_PCI_MSIQ_GETVALID	0xc2
2270*4882a593Smuzhiyun 
2271*4882a593Smuzhiyun /* pci_msiq_setvalid()
2272*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
2273*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_PCI_MSIQ_SETVALID
2274*4882a593Smuzhiyun  * ARG0:	devhandle
2275*4882a593Smuzhiyun  * ARG1:	msiqid
2276*4882a593Smuzhiyun  * ARG2:	msiqvalid	(HV_MSIQ_VALID or HV_MSIQ_INVALID)
2277*4882a593Smuzhiyun  * RET0:	status
2278*4882a593Smuzhiyun  * ERRORS:	EINVAL		Invalid devhandle or msiqid or msiqvalid
2279*4882a593Smuzhiyun  *				value or MSI EQ is uninitialized
2280*4882a593Smuzhiyun  *
2281*4882a593Smuzhiyun  * Set the valid state of the MSI-EQ described by the given devhandle and
2282*4882a593Smuzhiyun  * msiqid to the given msiqvalid.
2283*4882a593Smuzhiyun  */
2284*4882a593Smuzhiyun #define HV_FAST_PCI_MSIQ_SETVALID	0xc3
2285*4882a593Smuzhiyun 
2286*4882a593Smuzhiyun /* pci_msiq_getstate()
2287*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
2288*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_PCI_MSIQ_GETSTATE
2289*4882a593Smuzhiyun  * ARG0:	devhandle
2290*4882a593Smuzhiyun  * ARG1:	msiqid
2291*4882a593Smuzhiyun  * RET0:	status
2292*4882a593Smuzhiyun  * RET1:	msiqstate	(HV_MSIQSTATE_IDLE or HV_MSIQSTATE_ERROR)
2293*4882a593Smuzhiyun  * ERRORS:	EINVAL		Invalid devhandle or msiqid
2294*4882a593Smuzhiyun  *
2295*4882a593Smuzhiyun  * Get the state of the MSI-EQ described by the given devhandle and
2296*4882a593Smuzhiyun  * msiqid.
2297*4882a593Smuzhiyun  */
2298*4882a593Smuzhiyun #define HV_FAST_PCI_MSIQ_GETSTATE	0xc4
2299*4882a593Smuzhiyun 
2300*4882a593Smuzhiyun /* pci_msiq_getvalid()
2301*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
2302*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_PCI_MSIQ_GETVALID
2303*4882a593Smuzhiyun  * ARG0:	devhandle
2304*4882a593Smuzhiyun  * ARG1:	msiqid
2305*4882a593Smuzhiyun  * ARG2:	msiqstate	(HV_MSIQSTATE_IDLE or HV_MSIQSTATE_ERROR)
2306*4882a593Smuzhiyun  * RET0:	status
2307*4882a593Smuzhiyun  * ERRORS:	EINVAL		Invalid devhandle or msiqid or msiqstate
2308*4882a593Smuzhiyun  *				value or MSI EQ is uninitialized
2309*4882a593Smuzhiyun  *
2310*4882a593Smuzhiyun  * Set the state of the MSI-EQ described by the given devhandle and
2311*4882a593Smuzhiyun  * msiqid to the given msiqvalid.
2312*4882a593Smuzhiyun  */
2313*4882a593Smuzhiyun #define HV_FAST_PCI_MSIQ_SETSTATE	0xc5
2314*4882a593Smuzhiyun 
2315*4882a593Smuzhiyun /* pci_msiq_gethead()
2316*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
2317*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_PCI_MSIQ_GETHEAD
2318*4882a593Smuzhiyun  * ARG0:	devhandle
2319*4882a593Smuzhiyun  * ARG1:	msiqid
2320*4882a593Smuzhiyun  * RET0:	status
2321*4882a593Smuzhiyun  * RET1:	msiqhead
2322*4882a593Smuzhiyun  * ERRORS:	EINVAL		Invalid devhandle or msiqid
2323*4882a593Smuzhiyun  *
2324*4882a593Smuzhiyun  * Get the current MSI EQ queue head for the MSI-EQ described by the
2325*4882a593Smuzhiyun  * given devhandle and msiqid.
2326*4882a593Smuzhiyun  */
2327*4882a593Smuzhiyun #define HV_FAST_PCI_MSIQ_GETHEAD	0xc6
2328*4882a593Smuzhiyun 
2329*4882a593Smuzhiyun /* pci_msiq_sethead()
2330*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
2331*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_PCI_MSIQ_SETHEAD
2332*4882a593Smuzhiyun  * ARG0:	devhandle
2333*4882a593Smuzhiyun  * ARG1:	msiqid
2334*4882a593Smuzhiyun  * ARG2:	msiqhead
2335*4882a593Smuzhiyun  * RET0:	status
2336*4882a593Smuzhiyun  * ERRORS:	EINVAL		Invalid devhandle or msiqid or msiqhead,
2337*4882a593Smuzhiyun  *				or MSI EQ is uninitialized
2338*4882a593Smuzhiyun  *
2339*4882a593Smuzhiyun  * Set the current MSI EQ queue head for the MSI-EQ described by the
2340*4882a593Smuzhiyun  * given devhandle and msiqid.
2341*4882a593Smuzhiyun  */
2342*4882a593Smuzhiyun #define HV_FAST_PCI_MSIQ_SETHEAD	0xc7
2343*4882a593Smuzhiyun 
2344*4882a593Smuzhiyun /* pci_msiq_gettail()
2345*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
2346*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_PCI_MSIQ_GETTAIL
2347*4882a593Smuzhiyun  * ARG0:	devhandle
2348*4882a593Smuzhiyun  * ARG1:	msiqid
2349*4882a593Smuzhiyun  * RET0:	status
2350*4882a593Smuzhiyun  * RET1:	msiqtail
2351*4882a593Smuzhiyun  * ERRORS:	EINVAL		Invalid devhandle or msiqid
2352*4882a593Smuzhiyun  *
2353*4882a593Smuzhiyun  * Get the current MSI EQ queue tail for the MSI-EQ described by the
2354*4882a593Smuzhiyun  * given devhandle and msiqid.
2355*4882a593Smuzhiyun  */
2356*4882a593Smuzhiyun #define HV_FAST_PCI_MSIQ_GETTAIL	0xc8
2357*4882a593Smuzhiyun 
2358*4882a593Smuzhiyun /* pci_msi_getvalid()
2359*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
2360*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_PCI_MSI_GETVALID
2361*4882a593Smuzhiyun  * ARG0:	devhandle
2362*4882a593Smuzhiyun  * ARG1:	msinum
2363*4882a593Smuzhiyun  * RET0:	status
2364*4882a593Smuzhiyun  * RET1:	msivalidstate
2365*4882a593Smuzhiyun  * ERRORS:	EINVAL		Invalid devhandle or msinum
2366*4882a593Smuzhiyun  *
2367*4882a593Smuzhiyun  * Get the current valid/enabled state for the MSI defined by the
2368*4882a593Smuzhiyun  * given devhandle and msinum.
2369*4882a593Smuzhiyun  */
2370*4882a593Smuzhiyun #define HV_FAST_PCI_MSI_GETVALID	0xc9
2371*4882a593Smuzhiyun 
2372*4882a593Smuzhiyun /* pci_msi_setvalid()
2373*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
2374*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_PCI_MSI_SETVALID
2375*4882a593Smuzhiyun  * ARG0:	devhandle
2376*4882a593Smuzhiyun  * ARG1:	msinum
2377*4882a593Smuzhiyun  * ARG2:	msivalidstate
2378*4882a593Smuzhiyun  * RET0:	status
2379*4882a593Smuzhiyun  * ERRORS:	EINVAL		Invalid devhandle or msinum or msivalidstate
2380*4882a593Smuzhiyun  *
2381*4882a593Smuzhiyun  * Set the current valid/enabled state for the MSI defined by the
2382*4882a593Smuzhiyun  * given devhandle and msinum.
2383*4882a593Smuzhiyun  */
2384*4882a593Smuzhiyun #define HV_FAST_PCI_MSI_SETVALID	0xca
2385*4882a593Smuzhiyun 
2386*4882a593Smuzhiyun /* pci_msi_getmsiq()
2387*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
2388*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_PCI_MSI_GETMSIQ
2389*4882a593Smuzhiyun  * ARG0:	devhandle
2390*4882a593Smuzhiyun  * ARG1:	msinum
2391*4882a593Smuzhiyun  * RET0:	status
2392*4882a593Smuzhiyun  * RET1:	msiqid
2393*4882a593Smuzhiyun  * ERRORS:	EINVAL		Invalid devhandle or msinum or MSI is unbound
2394*4882a593Smuzhiyun  *
2395*4882a593Smuzhiyun  * Get the MSI EQ that the MSI defined by the given devhandle and
2396*4882a593Smuzhiyun  * msinum is bound to.
2397*4882a593Smuzhiyun  */
2398*4882a593Smuzhiyun #define HV_FAST_PCI_MSI_GETMSIQ		0xcb
2399*4882a593Smuzhiyun 
2400*4882a593Smuzhiyun /* pci_msi_setmsiq()
2401*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
2402*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_PCI_MSI_SETMSIQ
2403*4882a593Smuzhiyun  * ARG0:	devhandle
2404*4882a593Smuzhiyun  * ARG1:	msinum
2405*4882a593Smuzhiyun  * ARG2:	msitype
2406*4882a593Smuzhiyun  * ARG3:	msiqid
2407*4882a593Smuzhiyun  * RET0:	status
2408*4882a593Smuzhiyun  * ERRORS:	EINVAL		Invalid devhandle or msinum or msiqid
2409*4882a593Smuzhiyun  *
2410*4882a593Smuzhiyun  * Set the MSI EQ that the MSI defined by the given devhandle and
2411*4882a593Smuzhiyun  * msinum is bound to.
2412*4882a593Smuzhiyun  */
2413*4882a593Smuzhiyun #define HV_FAST_PCI_MSI_SETMSIQ		0xcc
2414*4882a593Smuzhiyun 
2415*4882a593Smuzhiyun /* pci_msi_getstate()
2416*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
2417*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_PCI_MSI_GETSTATE
2418*4882a593Smuzhiyun  * ARG0:	devhandle
2419*4882a593Smuzhiyun  * ARG1:	msinum
2420*4882a593Smuzhiyun  * RET0:	status
2421*4882a593Smuzhiyun  * RET1:	msistate
2422*4882a593Smuzhiyun  * ERRORS:	EINVAL		Invalid devhandle or msinum
2423*4882a593Smuzhiyun  *
2424*4882a593Smuzhiyun  * Get the state of the MSI defined by the given devhandle and msinum.
2425*4882a593Smuzhiyun  * If not initialized, return HV_MSISTATE_IDLE.
2426*4882a593Smuzhiyun  */
2427*4882a593Smuzhiyun #define HV_FAST_PCI_MSI_GETSTATE	0xcd
2428*4882a593Smuzhiyun 
2429*4882a593Smuzhiyun /* pci_msi_setstate()
2430*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
2431*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_PCI_MSI_SETSTATE
2432*4882a593Smuzhiyun  * ARG0:	devhandle
2433*4882a593Smuzhiyun  * ARG1:	msinum
2434*4882a593Smuzhiyun  * ARG2:	msistate
2435*4882a593Smuzhiyun  * RET0:	status
2436*4882a593Smuzhiyun  * ERRORS:	EINVAL		Invalid devhandle or msinum or msistate
2437*4882a593Smuzhiyun  *
2438*4882a593Smuzhiyun  * Set the state of the MSI defined by the given devhandle and msinum.
2439*4882a593Smuzhiyun  */
2440*4882a593Smuzhiyun #define HV_FAST_PCI_MSI_SETSTATE	0xce
2441*4882a593Smuzhiyun 
2442*4882a593Smuzhiyun /* pci_msg_getmsiq()
2443*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
2444*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_PCI_MSG_GETMSIQ
2445*4882a593Smuzhiyun  * ARG0:	devhandle
2446*4882a593Smuzhiyun  * ARG1:	msgtype
2447*4882a593Smuzhiyun  * RET0:	status
2448*4882a593Smuzhiyun  * RET1:	msiqid
2449*4882a593Smuzhiyun  * ERRORS:	EINVAL		Invalid devhandle or msgtype
2450*4882a593Smuzhiyun  *
2451*4882a593Smuzhiyun  * Get the MSI EQ of the MSG defined by the given devhandle and msgtype.
2452*4882a593Smuzhiyun  */
2453*4882a593Smuzhiyun #define HV_FAST_PCI_MSG_GETMSIQ		0xd0
2454*4882a593Smuzhiyun 
2455*4882a593Smuzhiyun /* pci_msg_setmsiq()
2456*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
2457*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_PCI_MSG_SETMSIQ
2458*4882a593Smuzhiyun  * ARG0:	devhandle
2459*4882a593Smuzhiyun  * ARG1:	msgtype
2460*4882a593Smuzhiyun  * ARG2:	msiqid
2461*4882a593Smuzhiyun  * RET0:	status
2462*4882a593Smuzhiyun  * ERRORS:	EINVAL		Invalid devhandle, msgtype, or msiqid
2463*4882a593Smuzhiyun  *
2464*4882a593Smuzhiyun  * Set the MSI EQ of the MSG defined by the given devhandle and msgtype.
2465*4882a593Smuzhiyun  */
2466*4882a593Smuzhiyun #define HV_FAST_PCI_MSG_SETMSIQ		0xd1
2467*4882a593Smuzhiyun 
2468*4882a593Smuzhiyun /* pci_msg_getvalid()
2469*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
2470*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_PCI_MSG_GETVALID
2471*4882a593Smuzhiyun  * ARG0:	devhandle
2472*4882a593Smuzhiyun  * ARG1:	msgtype
2473*4882a593Smuzhiyun  * RET0:	status
2474*4882a593Smuzhiyun  * RET1:	msgvalidstate
2475*4882a593Smuzhiyun  * ERRORS:	EINVAL		Invalid devhandle or msgtype
2476*4882a593Smuzhiyun  *
2477*4882a593Smuzhiyun  * Get the valid/enabled state of the MSG defined by the given
2478*4882a593Smuzhiyun  * devhandle and msgtype.
2479*4882a593Smuzhiyun  */
2480*4882a593Smuzhiyun #define HV_FAST_PCI_MSG_GETVALID	0xd2
2481*4882a593Smuzhiyun 
2482*4882a593Smuzhiyun /* pci_msg_setvalid()
2483*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
2484*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_PCI_MSG_SETVALID
2485*4882a593Smuzhiyun  * ARG0:	devhandle
2486*4882a593Smuzhiyun  * ARG1:	msgtype
2487*4882a593Smuzhiyun  * ARG2:	msgvalidstate
2488*4882a593Smuzhiyun  * RET0:	status
2489*4882a593Smuzhiyun  * ERRORS:	EINVAL		Invalid devhandle or msgtype or msgvalidstate
2490*4882a593Smuzhiyun  *
2491*4882a593Smuzhiyun  * Set the valid/enabled state of the MSG defined by the given
2492*4882a593Smuzhiyun  * devhandle and msgtype.
2493*4882a593Smuzhiyun  */
2494*4882a593Smuzhiyun #define HV_FAST_PCI_MSG_SETVALID	0xd3
2495*4882a593Smuzhiyun 
2496*4882a593Smuzhiyun /* PCI IOMMU v2 definitions and services
2497*4882a593Smuzhiyun  *
2498*4882a593Smuzhiyun  * While the PCI IO definitions above is valid IOMMU v2 adds new PCI IO
2499*4882a593Smuzhiyun  * definitions and services.
2500*4882a593Smuzhiyun  *
2501*4882a593Smuzhiyun  *	CTE		Clump Table Entry. First level table entry in the ATU.
2502*4882a593Smuzhiyun  *
2503*4882a593Smuzhiyun  *	pci_device_list
2504*4882a593Smuzhiyun  *			A 32-bit aligned list of pci_devices.
2505*4882a593Smuzhiyun  *
2506*4882a593Smuzhiyun  *	pci_device_listp
2507*4882a593Smuzhiyun  *			real address of a pci_device_list. 32-bit aligned.
2508*4882a593Smuzhiyun  *
2509*4882a593Smuzhiyun  *	iotte		IOMMU translation table entry.
2510*4882a593Smuzhiyun  *
2511*4882a593Smuzhiyun  *	iotte_attributes
2512*4882a593Smuzhiyun  *			IO Attributes for IOMMU v2 mappings. In addition to
2513*4882a593Smuzhiyun  *			read, write IOMMU v2 supports relax ordering
2514*4882a593Smuzhiyun  *
2515*4882a593Smuzhiyun  *	io_page_list	A 64-bit aligned list of real addresses. Each real
2516*4882a593Smuzhiyun  *			address in an io_page_list must be properly aligned
2517*4882a593Smuzhiyun  *			to the pagesize of the given IOTSB.
2518*4882a593Smuzhiyun  *
2519*4882a593Smuzhiyun  *	io_page_list_p	Real address of an io_page_list, 64-bit aligned.
2520*4882a593Smuzhiyun  *
2521*4882a593Smuzhiyun  *	IOTSB		IO Translation Storage Buffer. An aligned table of
2522*4882a593Smuzhiyun  *			IOTTEs. Each IOTSB has a pagesize, table size, and
2523*4882a593Smuzhiyun  *			virtual address associated with it that must match
2524*4882a593Smuzhiyun  *			a pagesize and table size supported by the un-derlying
2525*4882a593Smuzhiyun  *			hardware implementation. The alignment requirements
2526*4882a593Smuzhiyun  *			for an IOTSB depend on the pagesize used for that IOTSB.
2527*4882a593Smuzhiyun  *			Each IOTTE in an IOTSB maps one pagesize-sized page.
2528*4882a593Smuzhiyun  *			The size of the IOTSB dictates how large of a virtual
2529*4882a593Smuzhiyun  *			address space the IOTSB is capable of mapping.
2530*4882a593Smuzhiyun  *
2531*4882a593Smuzhiyun  *	iotsb_handle	An opaque identifier for an IOTSB. A devhandle plus
2532*4882a593Smuzhiyun  *			iotsb_handle represents a binding of an IOTSB to a
2533*4882a593Smuzhiyun  *			PCI root complex.
2534*4882a593Smuzhiyun  *
2535*4882a593Smuzhiyun  *	iotsb_index	Zero-based IOTTE number within an IOTSB.
2536*4882a593Smuzhiyun  */
2537*4882a593Smuzhiyun 
2538*4882a593Smuzhiyun /* The index_count argument consists of two fields:
2539*4882a593Smuzhiyun  * bits 63:48 #iottes and bits 47:0 iotsb_index
2540*4882a593Smuzhiyun  */
2541*4882a593Smuzhiyun #define HV_PCI_IOTSB_INDEX_COUNT(__iottes, __iotsb_index) \
2542*4882a593Smuzhiyun 	(((u64)(__iottes) << 48UL) | ((u64)(__iotsb_index)))
2543*4882a593Smuzhiyun 
2544*4882a593Smuzhiyun /* pci_iotsb_conf()
2545*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
2546*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_PCI_IOTSB_CONF
2547*4882a593Smuzhiyun  * ARG0:	devhandle
2548*4882a593Smuzhiyun  * ARG1:	r_addr
2549*4882a593Smuzhiyun  * ARG2:	size
2550*4882a593Smuzhiyun  * ARG3:	pagesize
2551*4882a593Smuzhiyun  * ARG4:	iova
2552*4882a593Smuzhiyun  * RET0:	status
2553*4882a593Smuzhiyun  * RET1:	iotsb_handle
2554*4882a593Smuzhiyun  * ERRORS:	EINVAL		Invalid devhandle, size, iova, or pagesize
2555*4882a593Smuzhiyun  *		EBADALIGN	r_addr is not properly aligned
2556*4882a593Smuzhiyun  *		ENORADDR	r_addr is not a valid real address
2557*4882a593Smuzhiyun  *		ETOOMANY	No further IOTSBs may be configured
2558*4882a593Smuzhiyun  *		EBUSY		Duplicate devhandle, raddir, iova combination
2559*4882a593Smuzhiyun  *
2560*4882a593Smuzhiyun  * Create an IOTSB suitable for the PCI root complex identified by devhandle,
2561*4882a593Smuzhiyun  * for the DMA virtual address defined by the argument iova.
2562*4882a593Smuzhiyun  *
2563*4882a593Smuzhiyun  * r_addr is the properly aligned base address of the IOTSB and size is the
2564*4882a593Smuzhiyun  * IOTSB (table) size in bytes.The IOTSB is required to be zeroed prior to
2565*4882a593Smuzhiyun  * being configured. If it contains any values other than zeros then the
2566*4882a593Smuzhiyun  * behavior is undefined.
2567*4882a593Smuzhiyun  *
2568*4882a593Smuzhiyun  * pagesize is the size of each page in the IOTSB. Note that the combination of
2569*4882a593Smuzhiyun  * size (table size) and pagesize must be valid.
2570*4882a593Smuzhiyun  *
2571*4882a593Smuzhiyun  * virt is the DMA virtual address this IOTSB will map.
2572*4882a593Smuzhiyun  *
2573*4882a593Smuzhiyun  * If successful, the opaque 64-bit handle iotsb_handle is returned in ret1.
2574*4882a593Smuzhiyun  * Once configured, privileged access to the IOTSB memory is prohibited and
2575*4882a593Smuzhiyun  * creates undefined behavior. The only permitted access is indirect via these
2576*4882a593Smuzhiyun  * services.
2577*4882a593Smuzhiyun  */
2578*4882a593Smuzhiyun #define HV_FAST_PCI_IOTSB_CONF		0x190
2579*4882a593Smuzhiyun 
2580*4882a593Smuzhiyun /* pci_iotsb_info()
2581*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
2582*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_PCI_IOTSB_INFO
2583*4882a593Smuzhiyun  * ARG0:	devhandle
2584*4882a593Smuzhiyun  * ARG1:	iotsb_handle
2585*4882a593Smuzhiyun  * RET0:	status
2586*4882a593Smuzhiyun  * RET1:	r_addr
2587*4882a593Smuzhiyun  * RET2:	size
2588*4882a593Smuzhiyun  * RET3:	pagesize
2589*4882a593Smuzhiyun  * RET4:	iova
2590*4882a593Smuzhiyun  * RET5:	#bound
2591*4882a593Smuzhiyun  * ERRORS:	EINVAL	Invalid devhandle or iotsb_handle
2592*4882a593Smuzhiyun  *
2593*4882a593Smuzhiyun  * This service returns configuration information about an IOTSB previously
2594*4882a593Smuzhiyun  * created with pci_iotsb_conf.
2595*4882a593Smuzhiyun  *
2596*4882a593Smuzhiyun  * iotsb_handle value 0 may be used with this service to inquire about the
2597*4882a593Smuzhiyun  * legacy IOTSB that may or may not exist. If the service succeeds, the return
2598*4882a593Smuzhiyun  * values describe the legacy IOTSB and I/O virtual addresses mapped by that
2599*4882a593Smuzhiyun  * table. However, the table base address r_addr may contain the value -1 which
2600*4882a593Smuzhiyun  * indicates a memory range that cannot be accessed or be reclaimed.
2601*4882a593Smuzhiyun  *
2602*4882a593Smuzhiyun  * The return value #bound contains the number of PCI devices that iotsb_handle
2603*4882a593Smuzhiyun  * is currently bound to.
2604*4882a593Smuzhiyun  */
2605*4882a593Smuzhiyun #define HV_FAST_PCI_IOTSB_INFO		0x191
2606*4882a593Smuzhiyun 
2607*4882a593Smuzhiyun /* pci_iotsb_unconf()
2608*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
2609*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_PCI_IOTSB_UNCONF
2610*4882a593Smuzhiyun  * ARG0:	devhandle
2611*4882a593Smuzhiyun  * ARG1:	iotsb_handle
2612*4882a593Smuzhiyun  * RET0:	status
2613*4882a593Smuzhiyun  * ERRORS:	EINVAL	Invalid devhandle or iotsb_handle
2614*4882a593Smuzhiyun  *		EBUSY	The IOTSB is bound and may not be unconfigured
2615*4882a593Smuzhiyun  *
2616*4882a593Smuzhiyun  * This service unconfigures the IOTSB identified by the devhandle and
2617*4882a593Smuzhiyun  * iotsb_handle arguments, previously created with pci_iotsb_conf.
2618*4882a593Smuzhiyun  * The IOTSB must not be currently bound to any device or the service will fail
2619*4882a593Smuzhiyun  *
2620*4882a593Smuzhiyun  * If the call succeeds, iotsb_handle is no longer valid.
2621*4882a593Smuzhiyun  */
2622*4882a593Smuzhiyun #define HV_FAST_PCI_IOTSB_UNCONF	0x192
2623*4882a593Smuzhiyun 
2624*4882a593Smuzhiyun /* pci_iotsb_bind()
2625*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
2626*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_PCI_IOTSB_BIND
2627*4882a593Smuzhiyun  * ARG0:	devhandle
2628*4882a593Smuzhiyun  * ARG1:	iotsb_handle
2629*4882a593Smuzhiyun  * ARG2:	pci_device
2630*4882a593Smuzhiyun  * RET0:	status
2631*4882a593Smuzhiyun  * ERRORS:	EINVAL	Invalid devhandle, iotsb_handle, or pci_device
2632*4882a593Smuzhiyun  *		EBUSY	A PCI function is already bound to an IOTSB at the same
2633*4882a593Smuzhiyun  *			address range as specified by devhandle, iotsb_handle.
2634*4882a593Smuzhiyun  *
2635*4882a593Smuzhiyun  * This service binds the PCI function specified by the argument pci_device to
2636*4882a593Smuzhiyun  * the IOTSB specified by the arguments devhandle and iotsb_handle.
2637*4882a593Smuzhiyun  *
2638*4882a593Smuzhiyun  * The PCI device function is bound to the specified IOTSB with the IOVA range
2639*4882a593Smuzhiyun  * specified when the IOTSB was configured via pci_iotsb_conf. If the function
2640*4882a593Smuzhiyun  * is already bound then it is unbound first.
2641*4882a593Smuzhiyun  */
2642*4882a593Smuzhiyun #define HV_FAST_PCI_IOTSB_BIND		0x193
2643*4882a593Smuzhiyun 
2644*4882a593Smuzhiyun /* pci_iotsb_unbind()
2645*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
2646*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_PCI_IOTSB_UNBIND
2647*4882a593Smuzhiyun  * ARG0:	devhandle
2648*4882a593Smuzhiyun  * ARG1:	iotsb_handle
2649*4882a593Smuzhiyun  * ARG2:	pci_device
2650*4882a593Smuzhiyun  * RET0:	status
2651*4882a593Smuzhiyun  * ERRORS:	EINVAL	Invalid devhandle, iotsb_handle, or pci_device
2652*4882a593Smuzhiyun  *		ENOMAP	The PCI function was not bound to the specified IOTSB
2653*4882a593Smuzhiyun  *
2654*4882a593Smuzhiyun  * This service unbinds the PCI device specified by the argument pci_device
2655*4882a593Smuzhiyun  * from the IOTSB identified  * by the arguments devhandle and iotsb_handle.
2656*4882a593Smuzhiyun  *
2657*4882a593Smuzhiyun  * If the PCI device is not bound to the specified IOTSB then this service will
2658*4882a593Smuzhiyun  * fail with status ENOMAP
2659*4882a593Smuzhiyun  */
2660*4882a593Smuzhiyun #define HV_FAST_PCI_IOTSB_UNBIND	0x194
2661*4882a593Smuzhiyun 
2662*4882a593Smuzhiyun /* pci_iotsb_get_binding()
2663*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
2664*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_PCI_IOTSB_GET_BINDING
2665*4882a593Smuzhiyun  * ARG0:	devhandle
2666*4882a593Smuzhiyun  * ARG1:	iotsb_handle
2667*4882a593Smuzhiyun  * ARG2:	iova
2668*4882a593Smuzhiyun  * RET0:	status
2669*4882a593Smuzhiyun  * RET1:	iotsb_handle
2670*4882a593Smuzhiyun  * ERRORS:	EINVAL	Invalid devhandle, pci_device, or iova
2671*4882a593Smuzhiyun  *		ENOMAP	The PCI function is not bound to an IOTSB at iova
2672*4882a593Smuzhiyun  *
2673*4882a593Smuzhiyun  * This service returns the IOTSB binding, iotsb_handle, for a given pci_device
2674*4882a593Smuzhiyun  * and DMA virtual address, iova.
2675*4882a593Smuzhiyun  *
2676*4882a593Smuzhiyun  * iova must be the base address of a DMA virtual address range as defined by
2677*4882a593Smuzhiyun  * the iommu-address-ranges property in the root complex device node defined
2678*4882a593Smuzhiyun  * by the argument devhandle.
2679*4882a593Smuzhiyun  */
2680*4882a593Smuzhiyun #define HV_FAST_PCI_IOTSB_GET_BINDING	0x195
2681*4882a593Smuzhiyun 
2682*4882a593Smuzhiyun /* pci_iotsb_map()
2683*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
2684*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_PCI_IOTSB_MAP
2685*4882a593Smuzhiyun  * ARG0:	devhandle
2686*4882a593Smuzhiyun  * ARG1:	iotsb_handle
2687*4882a593Smuzhiyun  * ARG2:	index_count
2688*4882a593Smuzhiyun  * ARG3:	iotte_attributes
2689*4882a593Smuzhiyun  * ARG4:	io_page_list_p
2690*4882a593Smuzhiyun  * RET0:	status
2691*4882a593Smuzhiyun  * RET1:	#mapped
2692*4882a593Smuzhiyun  * ERRORS:	EINVAL		Invalid devhandle, iotsb_handle, #iottes,
2693*4882a593Smuzhiyun  *				iotsb_index or iotte_attributes
2694*4882a593Smuzhiyun  *		EBADALIGN	Improperly aligned io_page_list_p or I/O page
2695*4882a593Smuzhiyun  *				address in the I/O page list.
2696*4882a593Smuzhiyun  *		ENORADDR	Invalid io_page_list_p or I/O page address in
2697*4882a593Smuzhiyun  *				the I/O page list.
2698*4882a593Smuzhiyun  *
2699*4882a593Smuzhiyun  * This service creates and flushes mappings in the IOTSB defined by the
2700*4882a593Smuzhiyun  * arguments devhandle, iotsb.
2701*4882a593Smuzhiyun  *
2702*4882a593Smuzhiyun  * The index_count argument consists of two fields. Bits 63:48 contain #iotte
2703*4882a593Smuzhiyun  * and bits 47:0 contain iotsb_index
2704*4882a593Smuzhiyun  *
2705*4882a593Smuzhiyun  * The first mapping is created in the IOTSB index specified by iotsb_index.
2706*4882a593Smuzhiyun  * Subsequent mappings are  created at iotsb_index+1 and so on.
2707*4882a593Smuzhiyun  *
2708*4882a593Smuzhiyun  * The attributes of each mapping are defined by the argument iotte_attributes.
2709*4882a593Smuzhiyun  *
2710*4882a593Smuzhiyun  * The io_page_list_p specifies the real address of the 64-bit-aligned list of
2711*4882a593Smuzhiyun  * #iottes I/O page addresses. Each page address must be a properly aligned
2712*4882a593Smuzhiyun  * real address of a page to be mapped in the IOTSB. The first entry in the I/O
2713*4882a593Smuzhiyun  * page list contains the real address of the first page, the 2nd entry for the
2714*4882a593Smuzhiyun  * 2nd page, and so on.
2715*4882a593Smuzhiyun  *
2716*4882a593Smuzhiyun  * #iottes must be greater than zero.
2717*4882a593Smuzhiyun  *
2718*4882a593Smuzhiyun  * The return value #mapped is the actual number of mappings created, which may
2719*4882a593Smuzhiyun  * be less than or equal to the argument #iottes. If the function returns
2720*4882a593Smuzhiyun  * successfully with a #mapped value less than the requested #iottes then the
2721*4882a593Smuzhiyun  * caller should continue to invoke the service with updated iotsb_index,
2722*4882a593Smuzhiyun  * #iottes, and io_page_list_p arguments until all pages are mapped.
2723*4882a593Smuzhiyun  *
2724*4882a593Smuzhiyun  * This service must not be used to demap a mapping. In other words, all
2725*4882a593Smuzhiyun  * mappings must be valid and have  one or both of the RW attribute bits set.
2726*4882a593Smuzhiyun  *
2727*4882a593Smuzhiyun  * Note:
2728*4882a593Smuzhiyun  * It is implementation-defined whether I/O page real address validity checking
2729*4882a593Smuzhiyun  * is done at time mappings are established or deferred until they are
2730*4882a593Smuzhiyun  * accessed.
2731*4882a593Smuzhiyun  */
2732*4882a593Smuzhiyun #define HV_FAST_PCI_IOTSB_MAP		0x196
2733*4882a593Smuzhiyun 
2734*4882a593Smuzhiyun /* pci_iotsb_map_one()
2735*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
2736*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_PCI_IOTSB_MAP_ONE
2737*4882a593Smuzhiyun  * ARG0:	devhandle
2738*4882a593Smuzhiyun  * ARG1:	iotsb_handle
2739*4882a593Smuzhiyun  * ARG2:	iotsb_index
2740*4882a593Smuzhiyun  * ARG3:	iotte_attributes
2741*4882a593Smuzhiyun  * ARG4:	r_addr
2742*4882a593Smuzhiyun  * RET0:	status
2743*4882a593Smuzhiyun  * ERRORS:	EINVAL		Invalid devhandle,iotsb_handle, iotsb_index
2744*4882a593Smuzhiyun  *				or iotte_attributes
2745*4882a593Smuzhiyun  *		EBADALIGN	Improperly aligned r_addr
2746*4882a593Smuzhiyun  *		ENORADDR	Invalid r_addr
2747*4882a593Smuzhiyun  *
2748*4882a593Smuzhiyun  * This service creates and flushes a single mapping in the IOTSB defined by the
2749*4882a593Smuzhiyun  * arguments devhandle, iotsb.
2750*4882a593Smuzhiyun  *
2751*4882a593Smuzhiyun  * The mapping for the page at r_addr is created at the IOTSB index specified by
2752*4882a593Smuzhiyun  * iotsb_index with  the attributes iotte_attributes.
2753*4882a593Smuzhiyun  *
2754*4882a593Smuzhiyun  * This service must not be used to demap a mapping. In other words, the mapping
2755*4882a593Smuzhiyun  * must be valid and have one or both of the RW attribute bits set.
2756*4882a593Smuzhiyun  *
2757*4882a593Smuzhiyun  * Note:
2758*4882a593Smuzhiyun  * It is implementation-defined whether I/O page real address validity checking
2759*4882a593Smuzhiyun  * is done at time mappings are established or deferred until they are
2760*4882a593Smuzhiyun  * accessed.
2761*4882a593Smuzhiyun  */
2762*4882a593Smuzhiyun #define HV_FAST_PCI_IOTSB_MAP_ONE	0x197
2763*4882a593Smuzhiyun 
2764*4882a593Smuzhiyun /* pci_iotsb_demap()
2765*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
2766*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_PCI_IOTSB_DEMAP
2767*4882a593Smuzhiyun  * ARG0:	devhandle
2768*4882a593Smuzhiyun  * ARG1:	iotsb_handle
2769*4882a593Smuzhiyun  * ARG2:	iotsb_index
2770*4882a593Smuzhiyun  * ARG3:	#iottes
2771*4882a593Smuzhiyun  * RET0:	status
2772*4882a593Smuzhiyun  * RET1:	#unmapped
2773*4882a593Smuzhiyun  * ERRORS:	EINVAL	Invalid devhandle, iotsb_handle, iotsb_index or #iottes
2774*4882a593Smuzhiyun  *
2775*4882a593Smuzhiyun  * This service unmaps and flushes up to #iottes mappings starting at index
2776*4882a593Smuzhiyun  * iotsb_index from the IOTSB defined by the arguments devhandle, iotsb.
2777*4882a593Smuzhiyun  *
2778*4882a593Smuzhiyun  * #iottes must be greater than zero.
2779*4882a593Smuzhiyun  *
2780*4882a593Smuzhiyun  * The actual number of IOTTEs unmapped is returned in #unmapped and may be less
2781*4882a593Smuzhiyun  * than or equal to the requested number of IOTTEs, #iottes.
2782*4882a593Smuzhiyun  *
2783*4882a593Smuzhiyun  * If #unmapped is less than #iottes, the caller should continue to invoke this
2784*4882a593Smuzhiyun  * service with updated iotsb_index and #iottes arguments until all pages are
2785*4882a593Smuzhiyun  * demapped.
2786*4882a593Smuzhiyun  */
2787*4882a593Smuzhiyun #define HV_FAST_PCI_IOTSB_DEMAP		0x198
2788*4882a593Smuzhiyun 
2789*4882a593Smuzhiyun /* pci_iotsb_getmap()
2790*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
2791*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_PCI_IOTSB_GETMAP
2792*4882a593Smuzhiyun  * ARG0:	devhandle
2793*4882a593Smuzhiyun  * ARG1:	iotsb_handle
2794*4882a593Smuzhiyun  * ARG2:	iotsb_index
2795*4882a593Smuzhiyun  * RET0:	status
2796*4882a593Smuzhiyun  * RET1:	r_addr
2797*4882a593Smuzhiyun  * RET2:	iotte_attributes
2798*4882a593Smuzhiyun  * ERRORS:	EINVAL	Invalid devhandle, iotsb_handle, or iotsb_index
2799*4882a593Smuzhiyun  *		ENOMAP	No mapping was found
2800*4882a593Smuzhiyun  *
2801*4882a593Smuzhiyun  * This service returns the mapping specified by index iotsb_index from the
2802*4882a593Smuzhiyun  * IOTSB defined by the arguments devhandle, iotsb.
2803*4882a593Smuzhiyun  *
2804*4882a593Smuzhiyun  * Upon success, the real address of the mapping shall be returned in
2805*4882a593Smuzhiyun  * r_addr and thethe IOTTE mapping attributes shall be returned in
2806*4882a593Smuzhiyun  * iotte_attributes.
2807*4882a593Smuzhiyun  *
2808*4882a593Smuzhiyun  * The return value iotte_attributes may not include optional features used in
2809*4882a593Smuzhiyun  * the call to create the  mapping.
2810*4882a593Smuzhiyun  */
2811*4882a593Smuzhiyun #define HV_FAST_PCI_IOTSB_GETMAP	0x199
2812*4882a593Smuzhiyun 
2813*4882a593Smuzhiyun /* pci_iotsb_sync_mappings()
2814*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
2815*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_PCI_IOTSB_SYNC_MAPPINGS
2816*4882a593Smuzhiyun  * ARG0:	devhandle
2817*4882a593Smuzhiyun  * ARG1:	iotsb_handle
2818*4882a593Smuzhiyun  * ARG2:	iotsb_index
2819*4882a593Smuzhiyun  * ARG3:	#iottes
2820*4882a593Smuzhiyun  * RET0:	status
2821*4882a593Smuzhiyun  * RET1:	#synced
2822*4882a593Smuzhiyun  * ERROS:	EINVAL	Invalid devhandle, iotsb_handle, iotsb_index, or #iottes
2823*4882a593Smuzhiyun  *
2824*4882a593Smuzhiyun  * This service synchronizes #iottes mappings starting at index iotsb_index in
2825*4882a593Smuzhiyun  * the IOTSB defined by the arguments devhandle, iotsb.
2826*4882a593Smuzhiyun  *
2827*4882a593Smuzhiyun  * #iottes must be greater than zero.
2828*4882a593Smuzhiyun  *
2829*4882a593Smuzhiyun  * The actual number of IOTTEs synchronized is returned in #synced, which may
2830*4882a593Smuzhiyun  * be less than or equal to the requested number, #iottes.
2831*4882a593Smuzhiyun  *
2832*4882a593Smuzhiyun  * Upon a successful return, #synced is less than #iottes, the caller should
2833*4882a593Smuzhiyun  * continue to invoke this service with updated iotsb_index and #iottes
2834*4882a593Smuzhiyun  * arguments until all pages are synchronized.
2835*4882a593Smuzhiyun  */
2836*4882a593Smuzhiyun #define HV_FAST_PCI_IOTSB_SYNC_MAPPINGS	0x19a
2837*4882a593Smuzhiyun 
2838*4882a593Smuzhiyun /* Logical Domain Channel services.  */
2839*4882a593Smuzhiyun 
2840*4882a593Smuzhiyun #define LDC_CHANNEL_DOWN		0
2841*4882a593Smuzhiyun #define LDC_CHANNEL_UP			1
2842*4882a593Smuzhiyun #define LDC_CHANNEL_RESETTING		2
2843*4882a593Smuzhiyun 
2844*4882a593Smuzhiyun /* ldc_tx_qconf()
2845*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
2846*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_LDC_TX_QCONF
2847*4882a593Smuzhiyun  * ARG0:	channel ID
2848*4882a593Smuzhiyun  * ARG1:	real address base of queue
2849*4882a593Smuzhiyun  * ARG2:	num entries in queue
2850*4882a593Smuzhiyun  * RET0:	status
2851*4882a593Smuzhiyun  *
2852*4882a593Smuzhiyun  * Configure transmit queue for the LDC endpoint specified by the
2853*4882a593Smuzhiyun  * given channel ID, to be placed at the given real address, and
2854*4882a593Smuzhiyun  * be of the given num entries.  Num entries must be a power of two.
2855*4882a593Smuzhiyun  * The real address base of the queue must be aligned on the queue
2856*4882a593Smuzhiyun  * size.  Each queue entry is 64-bytes, so for example, a 32 entry
2857*4882a593Smuzhiyun  * queue must be aligned on a 2048 byte real address boundary.
2858*4882a593Smuzhiyun  *
2859*4882a593Smuzhiyun  * Upon configuration of a valid transmit queue the head and tail
2860*4882a593Smuzhiyun  * pointers are set to a hypervisor specific identical value indicating
2861*4882a593Smuzhiyun  * that the queue initially is empty.
2862*4882a593Smuzhiyun  *
2863*4882a593Smuzhiyun  * The endpoint's transmit queue is un-configured if num entries is zero.
2864*4882a593Smuzhiyun  *
2865*4882a593Smuzhiyun  * The maximum number of entries for each queue for a specific cpu may be
2866*4882a593Smuzhiyun  * determined from the machine description.  A transmit queue may be
2867*4882a593Smuzhiyun  * specified even in the event that the LDC is down (peer endpoint has no
2868*4882a593Smuzhiyun  * receive queue specified).  Transmission will begin as soon as the peer
2869*4882a593Smuzhiyun  * endpoint defines a receive queue.
2870*4882a593Smuzhiyun  *
2871*4882a593Smuzhiyun  * It is recommended that a guest wait for a transmit queue to empty prior
2872*4882a593Smuzhiyun  * to reconfiguring it, or un-configuring it.  Re or un-configuring of a
2873*4882a593Smuzhiyun  * non-empty transmit queue behaves exactly as defined above, however it
2874*4882a593Smuzhiyun  * is undefined as to how many of the pending entries in the original queue
2875*4882a593Smuzhiyun  * will be delivered prior to the re-configuration taking effect.
2876*4882a593Smuzhiyun  * Furthermore, as the queue configuration causes a reset of the head and
2877*4882a593Smuzhiyun  * tail pointers there is no way for a guest to determine how many entries
2878*4882a593Smuzhiyun  * have been sent after the configuration operation.
2879*4882a593Smuzhiyun  */
2880*4882a593Smuzhiyun #define HV_FAST_LDC_TX_QCONF		0xe0
2881*4882a593Smuzhiyun 
2882*4882a593Smuzhiyun /* ldc_tx_qinfo()
2883*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
2884*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_LDC_TX_QINFO
2885*4882a593Smuzhiyun  * ARG0:	channel ID
2886*4882a593Smuzhiyun  * RET0:	status
2887*4882a593Smuzhiyun  * RET1:	real address base of queue
2888*4882a593Smuzhiyun  * RET2:	num entries in queue
2889*4882a593Smuzhiyun  *
2890*4882a593Smuzhiyun  * Return the configuration info for the transmit queue of LDC endpoint
2891*4882a593Smuzhiyun  * defined by the given channel ID.  The real address is the currently
2892*4882a593Smuzhiyun  * defined real address base of the defined queue, and num entries is the
2893*4882a593Smuzhiyun  * size of the queue in terms of number of entries.
2894*4882a593Smuzhiyun  *
2895*4882a593Smuzhiyun  * If the specified channel ID is a valid endpoint number, but no transmit
2896*4882a593Smuzhiyun  * queue has been defined this service will return success, but with num
2897*4882a593Smuzhiyun  * entries set to zero and the real address will have an undefined value.
2898*4882a593Smuzhiyun  */
2899*4882a593Smuzhiyun #define HV_FAST_LDC_TX_QINFO		0xe1
2900*4882a593Smuzhiyun 
2901*4882a593Smuzhiyun /* ldc_tx_get_state()
2902*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
2903*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_LDC_TX_GET_STATE
2904*4882a593Smuzhiyun  * ARG0:	channel ID
2905*4882a593Smuzhiyun  * RET0:	status
2906*4882a593Smuzhiyun  * RET1:	head offset
2907*4882a593Smuzhiyun  * RET2:	tail offset
2908*4882a593Smuzhiyun  * RET3:	channel state
2909*4882a593Smuzhiyun  *
2910*4882a593Smuzhiyun  * Return the transmit state, and the head and tail queue pointers, for
2911*4882a593Smuzhiyun  * the transmit queue of the LDC endpoint defined by the given channel ID.
2912*4882a593Smuzhiyun  * The head and tail values are the byte offset of the head and tail
2913*4882a593Smuzhiyun  * positions of the transmit queue for the specified endpoint.
2914*4882a593Smuzhiyun  */
2915*4882a593Smuzhiyun #define HV_FAST_LDC_TX_GET_STATE	0xe2
2916*4882a593Smuzhiyun 
2917*4882a593Smuzhiyun /* ldc_tx_set_qtail()
2918*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
2919*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_LDC_TX_SET_QTAIL
2920*4882a593Smuzhiyun  * ARG0:	channel ID
2921*4882a593Smuzhiyun  * ARG1:	tail offset
2922*4882a593Smuzhiyun  * RET0:	status
2923*4882a593Smuzhiyun  *
2924*4882a593Smuzhiyun  * Update the tail pointer for the transmit queue associated with the LDC
2925*4882a593Smuzhiyun  * endpoint defined by the given channel ID.  The tail offset specified
2926*4882a593Smuzhiyun  * must be aligned on a 64 byte boundary, and calculated so as to increase
2927*4882a593Smuzhiyun  * the number of pending entries on the transmit queue.  Any attempt to
2928*4882a593Smuzhiyun  * decrease the number of pending transmit queue entires is considered
2929*4882a593Smuzhiyun  * an invalid tail offset and will result in an EINVAL error.
2930*4882a593Smuzhiyun  *
2931*4882a593Smuzhiyun  * Since the tail of the transmit queue may not be moved backwards, the
2932*4882a593Smuzhiyun  * transmit queue may be flushed by configuring a new transmit queue,
2933*4882a593Smuzhiyun  * whereupon the hypervisor will configure the initial transmit head and
2934*4882a593Smuzhiyun  * tail pointers to be equal.
2935*4882a593Smuzhiyun  */
2936*4882a593Smuzhiyun #define HV_FAST_LDC_TX_SET_QTAIL	0xe3
2937*4882a593Smuzhiyun 
2938*4882a593Smuzhiyun /* ldc_rx_qconf()
2939*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
2940*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_LDC_RX_QCONF
2941*4882a593Smuzhiyun  * ARG0:	channel ID
2942*4882a593Smuzhiyun  * ARG1:	real address base of queue
2943*4882a593Smuzhiyun  * ARG2:	num entries in queue
2944*4882a593Smuzhiyun  * RET0:	status
2945*4882a593Smuzhiyun  *
2946*4882a593Smuzhiyun  * Configure receive queue for the LDC endpoint specified by the
2947*4882a593Smuzhiyun  * given channel ID, to be placed at the given real address, and
2948*4882a593Smuzhiyun  * be of the given num entries.  Num entries must be a power of two.
2949*4882a593Smuzhiyun  * The real address base of the queue must be aligned on the queue
2950*4882a593Smuzhiyun  * size.  Each queue entry is 64-bytes, so for example, a 32 entry
2951*4882a593Smuzhiyun  * queue must be aligned on a 2048 byte real address boundary.
2952*4882a593Smuzhiyun  *
2953*4882a593Smuzhiyun  * The endpoint's transmit queue is un-configured if num entries is zero.
2954*4882a593Smuzhiyun  *
2955*4882a593Smuzhiyun  * If a valid receive queue is specified for a local endpoint the LDC is
2956*4882a593Smuzhiyun  * in the up state for the purpose of transmission to this endpoint.
2957*4882a593Smuzhiyun  *
2958*4882a593Smuzhiyun  * The maximum number of entries for each queue for a specific cpu may be
2959*4882a593Smuzhiyun  * determined from the machine description.
2960*4882a593Smuzhiyun  *
2961*4882a593Smuzhiyun  * As receive queue configuration causes a reset of the queue's head and
2962*4882a593Smuzhiyun  * tail pointers there is no way for a gues to determine how many entries
2963*4882a593Smuzhiyun  * have been received between a preceding ldc_get_rx_state() API call
2964*4882a593Smuzhiyun  * and the completion of the configuration operation.  It should be noted
2965*4882a593Smuzhiyun  * that datagram delivery is not guaranteed via domain channels anyway,
2966*4882a593Smuzhiyun  * and therefore any higher protocol should be resilient to datagram
2967*4882a593Smuzhiyun  * loss if necessary.  However, to overcome this specific race potential
2968*4882a593Smuzhiyun  * it is recommended, for example, that a higher level protocol be employed
2969*4882a593Smuzhiyun  * to ensure either retransmission, or ensure that no datagrams are pending
2970*4882a593Smuzhiyun  * on the peer endpoint's transmit queue prior to the configuration process.
2971*4882a593Smuzhiyun  */
2972*4882a593Smuzhiyun #define HV_FAST_LDC_RX_QCONF		0xe4
2973*4882a593Smuzhiyun 
2974*4882a593Smuzhiyun /* ldc_rx_qinfo()
2975*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
2976*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_LDC_RX_QINFO
2977*4882a593Smuzhiyun  * ARG0:	channel ID
2978*4882a593Smuzhiyun  * RET0:	status
2979*4882a593Smuzhiyun  * RET1:	real address base of queue
2980*4882a593Smuzhiyun  * RET2:	num entries in queue
2981*4882a593Smuzhiyun  *
2982*4882a593Smuzhiyun  * Return the configuration info for the receive queue of LDC endpoint
2983*4882a593Smuzhiyun  * defined by the given channel ID.  The real address is the currently
2984*4882a593Smuzhiyun  * defined real address base of the defined queue, and num entries is the
2985*4882a593Smuzhiyun  * size of the queue in terms of number of entries.
2986*4882a593Smuzhiyun  *
2987*4882a593Smuzhiyun  * If the specified channel ID is a valid endpoint number, but no receive
2988*4882a593Smuzhiyun  * queue has been defined this service will return success, but with num
2989*4882a593Smuzhiyun  * entries set to zero and the real address will have an undefined value.
2990*4882a593Smuzhiyun  */
2991*4882a593Smuzhiyun #define HV_FAST_LDC_RX_QINFO		0xe5
2992*4882a593Smuzhiyun 
2993*4882a593Smuzhiyun /* ldc_rx_get_state()
2994*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
2995*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_LDC_RX_GET_STATE
2996*4882a593Smuzhiyun  * ARG0:	channel ID
2997*4882a593Smuzhiyun  * RET0:	status
2998*4882a593Smuzhiyun  * RET1:	head offset
2999*4882a593Smuzhiyun  * RET2:	tail offset
3000*4882a593Smuzhiyun  * RET3:	channel state
3001*4882a593Smuzhiyun  *
3002*4882a593Smuzhiyun  * Return the receive state, and the head and tail queue pointers, for
3003*4882a593Smuzhiyun  * the receive queue of the LDC endpoint defined by the given channel ID.
3004*4882a593Smuzhiyun  * The head and tail values are the byte offset of the head and tail
3005*4882a593Smuzhiyun  * positions of the receive queue for the specified endpoint.
3006*4882a593Smuzhiyun  */
3007*4882a593Smuzhiyun #define HV_FAST_LDC_RX_GET_STATE	0xe6
3008*4882a593Smuzhiyun 
3009*4882a593Smuzhiyun /* ldc_rx_set_qhead()
3010*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
3011*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_LDC_RX_SET_QHEAD
3012*4882a593Smuzhiyun  * ARG0:	channel ID
3013*4882a593Smuzhiyun  * ARG1:	head offset
3014*4882a593Smuzhiyun  * RET0:	status
3015*4882a593Smuzhiyun  *
3016*4882a593Smuzhiyun  * Update the head pointer for the receive queue associated with the LDC
3017*4882a593Smuzhiyun  * endpoint defined by the given channel ID.  The head offset specified
3018*4882a593Smuzhiyun  * must be aligned on a 64 byte boundary, and calculated so as to decrease
3019*4882a593Smuzhiyun  * the number of pending entries on the receive queue.  Any attempt to
3020*4882a593Smuzhiyun  * increase the number of pending receive queue entires is considered
3021*4882a593Smuzhiyun  * an invalid head offset and will result in an EINVAL error.
3022*4882a593Smuzhiyun  *
3023*4882a593Smuzhiyun  * The receive queue may be flushed by setting the head offset equal
3024*4882a593Smuzhiyun  * to the current tail offset.
3025*4882a593Smuzhiyun  */
3026*4882a593Smuzhiyun #define HV_FAST_LDC_RX_SET_QHEAD	0xe7
3027*4882a593Smuzhiyun 
3028*4882a593Smuzhiyun /* LDC Map Table Entry.  Each slot is defined by a translation table
3029*4882a593Smuzhiyun  * entry, as specified by the LDC_MTE_* bits below, and a 64-bit
3030*4882a593Smuzhiyun  * hypervisor invalidation cookie.
3031*4882a593Smuzhiyun  */
3032*4882a593Smuzhiyun #define LDC_MTE_PADDR	0x0fffffffffffe000 /* pa[55:13]          */
3033*4882a593Smuzhiyun #define LDC_MTE_COPY_W	0x0000000000000400 /* copy write access  */
3034*4882a593Smuzhiyun #define LDC_MTE_COPY_R	0x0000000000000200 /* copy read access   */
3035*4882a593Smuzhiyun #define LDC_MTE_IOMMU_W	0x0000000000000100 /* IOMMU write access */
3036*4882a593Smuzhiyun #define LDC_MTE_IOMMU_R	0x0000000000000080 /* IOMMU read access  */
3037*4882a593Smuzhiyun #define LDC_MTE_EXEC	0x0000000000000040 /* execute            */
3038*4882a593Smuzhiyun #define LDC_MTE_WRITE	0x0000000000000020 /* read               */
3039*4882a593Smuzhiyun #define LDC_MTE_READ	0x0000000000000010 /* write              */
3040*4882a593Smuzhiyun #define LDC_MTE_SZALL	0x000000000000000f /* page size bits     */
3041*4882a593Smuzhiyun #define LDC_MTE_SZ16GB	0x0000000000000007 /* 16GB page          */
3042*4882a593Smuzhiyun #define LDC_MTE_SZ2GB	0x0000000000000006 /* 2GB page           */
3043*4882a593Smuzhiyun #define LDC_MTE_SZ256MB	0x0000000000000005 /* 256MB page         */
3044*4882a593Smuzhiyun #define LDC_MTE_SZ32MB	0x0000000000000004 /* 32MB page          */
3045*4882a593Smuzhiyun #define LDC_MTE_SZ4MB	0x0000000000000003 /* 4MB page           */
3046*4882a593Smuzhiyun #define LDC_MTE_SZ512K	0x0000000000000002 /* 512K page          */
3047*4882a593Smuzhiyun #define LDC_MTE_SZ64K	0x0000000000000001 /* 64K page           */
3048*4882a593Smuzhiyun #define LDC_MTE_SZ8K	0x0000000000000000 /* 8K page            */
3049*4882a593Smuzhiyun 
3050*4882a593Smuzhiyun #ifndef __ASSEMBLY__
3051*4882a593Smuzhiyun struct ldc_mtable_entry {
3052*4882a593Smuzhiyun 	unsigned long	mte;
3053*4882a593Smuzhiyun 	unsigned long	cookie;
3054*4882a593Smuzhiyun };
3055*4882a593Smuzhiyun #endif
3056*4882a593Smuzhiyun 
3057*4882a593Smuzhiyun /* ldc_set_map_table()
3058*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
3059*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_LDC_SET_MAP_TABLE
3060*4882a593Smuzhiyun  * ARG0:	channel ID
3061*4882a593Smuzhiyun  * ARG1:	table real address
3062*4882a593Smuzhiyun  * ARG2:	num entries
3063*4882a593Smuzhiyun  * RET0:	status
3064*4882a593Smuzhiyun  *
3065*4882a593Smuzhiyun  * Register the MTE table at the given table real address, with the
3066*4882a593Smuzhiyun  * specified num entries, for the LDC indicated by the given channel
3067*4882a593Smuzhiyun  * ID.
3068*4882a593Smuzhiyun  */
3069*4882a593Smuzhiyun #define HV_FAST_LDC_SET_MAP_TABLE	0xea
3070*4882a593Smuzhiyun 
3071*4882a593Smuzhiyun /* ldc_get_map_table()
3072*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
3073*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_LDC_GET_MAP_TABLE
3074*4882a593Smuzhiyun  * ARG0:	channel ID
3075*4882a593Smuzhiyun  * RET0:	status
3076*4882a593Smuzhiyun  * RET1:	table real address
3077*4882a593Smuzhiyun  * RET2:	num entries
3078*4882a593Smuzhiyun  *
3079*4882a593Smuzhiyun  * Return the configuration of the current mapping table registered
3080*4882a593Smuzhiyun  * for the given channel ID.
3081*4882a593Smuzhiyun  */
3082*4882a593Smuzhiyun #define HV_FAST_LDC_GET_MAP_TABLE	0xeb
3083*4882a593Smuzhiyun 
3084*4882a593Smuzhiyun #define LDC_COPY_IN	0
3085*4882a593Smuzhiyun #define LDC_COPY_OUT	1
3086*4882a593Smuzhiyun 
3087*4882a593Smuzhiyun /* ldc_copy()
3088*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
3089*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_LDC_COPY
3090*4882a593Smuzhiyun  * ARG0:	channel ID
3091*4882a593Smuzhiyun  * ARG1:	LDC_COPY_* direction code
3092*4882a593Smuzhiyun  * ARG2:	target real address
3093*4882a593Smuzhiyun  * ARG3:	local real address
3094*4882a593Smuzhiyun  * ARG4:	length in bytes
3095*4882a593Smuzhiyun  * RET0:	status
3096*4882a593Smuzhiyun  * RET1:	actual length in bytes
3097*4882a593Smuzhiyun  */
3098*4882a593Smuzhiyun #define HV_FAST_LDC_COPY		0xec
3099*4882a593Smuzhiyun 
3100*4882a593Smuzhiyun #define LDC_MEM_READ	1
3101*4882a593Smuzhiyun #define LDC_MEM_WRITE	2
3102*4882a593Smuzhiyun #define LDC_MEM_EXEC	4
3103*4882a593Smuzhiyun 
3104*4882a593Smuzhiyun /* ldc_mapin()
3105*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
3106*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_LDC_MAPIN
3107*4882a593Smuzhiyun  * ARG0:	channel ID
3108*4882a593Smuzhiyun  * ARG1:	cookie
3109*4882a593Smuzhiyun  * RET0:	status
3110*4882a593Smuzhiyun  * RET1:	real address
3111*4882a593Smuzhiyun  * RET2:	LDC_MEM_* permissions
3112*4882a593Smuzhiyun  */
3113*4882a593Smuzhiyun #define HV_FAST_LDC_MAPIN		0xed
3114*4882a593Smuzhiyun 
3115*4882a593Smuzhiyun /* ldc_unmap()
3116*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
3117*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_LDC_UNMAP
3118*4882a593Smuzhiyun  * ARG0:	real address
3119*4882a593Smuzhiyun  * RET0:	status
3120*4882a593Smuzhiyun  */
3121*4882a593Smuzhiyun #define HV_FAST_LDC_UNMAP		0xee
3122*4882a593Smuzhiyun 
3123*4882a593Smuzhiyun /* ldc_revoke()
3124*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
3125*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_LDC_REVOKE
3126*4882a593Smuzhiyun  * ARG0:	channel ID
3127*4882a593Smuzhiyun  * ARG1:	cookie
3128*4882a593Smuzhiyun  * ARG2:	ldc_mtable_entry cookie
3129*4882a593Smuzhiyun  * RET0:	status
3130*4882a593Smuzhiyun  */
3131*4882a593Smuzhiyun #define HV_FAST_LDC_REVOKE		0xef
3132*4882a593Smuzhiyun 
3133*4882a593Smuzhiyun #ifndef __ASSEMBLY__
3134*4882a593Smuzhiyun unsigned long sun4v_ldc_tx_qconf(unsigned long channel,
3135*4882a593Smuzhiyun 				 unsigned long ra,
3136*4882a593Smuzhiyun 				 unsigned long num_entries);
3137*4882a593Smuzhiyun unsigned long sun4v_ldc_tx_qinfo(unsigned long channel,
3138*4882a593Smuzhiyun 				 unsigned long *ra,
3139*4882a593Smuzhiyun 				 unsigned long *num_entries);
3140*4882a593Smuzhiyun unsigned long sun4v_ldc_tx_get_state(unsigned long channel,
3141*4882a593Smuzhiyun 				     unsigned long *head_off,
3142*4882a593Smuzhiyun 				     unsigned long *tail_off,
3143*4882a593Smuzhiyun 				     unsigned long *chan_state);
3144*4882a593Smuzhiyun unsigned long sun4v_ldc_tx_set_qtail(unsigned long channel,
3145*4882a593Smuzhiyun 				     unsigned long tail_off);
3146*4882a593Smuzhiyun unsigned long sun4v_ldc_rx_qconf(unsigned long channel,
3147*4882a593Smuzhiyun 				 unsigned long ra,
3148*4882a593Smuzhiyun 				 unsigned long num_entries);
3149*4882a593Smuzhiyun unsigned long sun4v_ldc_rx_qinfo(unsigned long channel,
3150*4882a593Smuzhiyun 				 unsigned long *ra,
3151*4882a593Smuzhiyun 				 unsigned long *num_entries);
3152*4882a593Smuzhiyun unsigned long sun4v_ldc_rx_get_state(unsigned long channel,
3153*4882a593Smuzhiyun 				     unsigned long *head_off,
3154*4882a593Smuzhiyun 				     unsigned long *tail_off,
3155*4882a593Smuzhiyun 				     unsigned long *chan_state);
3156*4882a593Smuzhiyun unsigned long sun4v_ldc_rx_set_qhead(unsigned long channel,
3157*4882a593Smuzhiyun 				     unsigned long head_off);
3158*4882a593Smuzhiyun unsigned long sun4v_ldc_set_map_table(unsigned long channel,
3159*4882a593Smuzhiyun 				      unsigned long ra,
3160*4882a593Smuzhiyun 				      unsigned long num_entries);
3161*4882a593Smuzhiyun unsigned long sun4v_ldc_get_map_table(unsigned long channel,
3162*4882a593Smuzhiyun 				      unsigned long *ra,
3163*4882a593Smuzhiyun 				      unsigned long *num_entries);
3164*4882a593Smuzhiyun unsigned long sun4v_ldc_copy(unsigned long channel,
3165*4882a593Smuzhiyun 			     unsigned long dir_code,
3166*4882a593Smuzhiyun 			     unsigned long tgt_raddr,
3167*4882a593Smuzhiyun 			     unsigned long lcl_raddr,
3168*4882a593Smuzhiyun 			     unsigned long len,
3169*4882a593Smuzhiyun 			     unsigned long *actual_len);
3170*4882a593Smuzhiyun unsigned long sun4v_ldc_mapin(unsigned long channel,
3171*4882a593Smuzhiyun 			      unsigned long cookie,
3172*4882a593Smuzhiyun 			      unsigned long *ra,
3173*4882a593Smuzhiyun 			      unsigned long *perm);
3174*4882a593Smuzhiyun unsigned long sun4v_ldc_unmap(unsigned long ra);
3175*4882a593Smuzhiyun unsigned long sun4v_ldc_revoke(unsigned long channel,
3176*4882a593Smuzhiyun 			       unsigned long cookie,
3177*4882a593Smuzhiyun 			       unsigned long mte_cookie);
3178*4882a593Smuzhiyun #endif
3179*4882a593Smuzhiyun 
3180*4882a593Smuzhiyun /* Performance counter services.  */
3181*4882a593Smuzhiyun 
3182*4882a593Smuzhiyun #define HV_PERF_JBUS_PERF_CTRL_REG	0x00
3183*4882a593Smuzhiyun #define HV_PERF_JBUS_PERF_CNT_REG	0x01
3184*4882a593Smuzhiyun #define HV_PERF_DRAM_PERF_CTRL_REG_0	0x02
3185*4882a593Smuzhiyun #define HV_PERF_DRAM_PERF_CNT_REG_0	0x03
3186*4882a593Smuzhiyun #define HV_PERF_DRAM_PERF_CTRL_REG_1	0x04
3187*4882a593Smuzhiyun #define HV_PERF_DRAM_PERF_CNT_REG_1	0x05
3188*4882a593Smuzhiyun #define HV_PERF_DRAM_PERF_CTRL_REG_2	0x06
3189*4882a593Smuzhiyun #define HV_PERF_DRAM_PERF_CNT_REG_2	0x07
3190*4882a593Smuzhiyun #define HV_PERF_DRAM_PERF_CTRL_REG_3	0x08
3191*4882a593Smuzhiyun #define HV_PERF_DRAM_PERF_CNT_REG_3	0x09
3192*4882a593Smuzhiyun 
3193*4882a593Smuzhiyun /* get_perfreg()
3194*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
3195*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_GET_PERFREG
3196*4882a593Smuzhiyun  * ARG0:	performance reg number
3197*4882a593Smuzhiyun  * RET0:	status
3198*4882a593Smuzhiyun  * RET1:	performance reg value
3199*4882a593Smuzhiyun  * ERRORS:	EINVAL		Invalid performance register number
3200*4882a593Smuzhiyun  *		ENOACCESS	No access allowed to performance counters
3201*4882a593Smuzhiyun  *
3202*4882a593Smuzhiyun  * Read the value of the given DRAM/JBUS performance counter/control register.
3203*4882a593Smuzhiyun  */
3204*4882a593Smuzhiyun #define HV_FAST_GET_PERFREG		0x100
3205*4882a593Smuzhiyun 
3206*4882a593Smuzhiyun /* set_perfreg()
3207*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
3208*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_SET_PERFREG
3209*4882a593Smuzhiyun  * ARG0:	performance reg number
3210*4882a593Smuzhiyun  * ARG1:	performance reg value
3211*4882a593Smuzhiyun  * RET0:	status
3212*4882a593Smuzhiyun  * ERRORS:	EINVAL		Invalid performance register number
3213*4882a593Smuzhiyun  *		ENOACCESS	No access allowed to performance counters
3214*4882a593Smuzhiyun  *
3215*4882a593Smuzhiyun  * Write the given performance reg value to the given DRAM/JBUS
3216*4882a593Smuzhiyun  * performance counter/control register.
3217*4882a593Smuzhiyun  */
3218*4882a593Smuzhiyun #define HV_FAST_SET_PERFREG		0x101
3219*4882a593Smuzhiyun 
3220*4882a593Smuzhiyun #define HV_N2_PERF_SPARC_CTL		0x0
3221*4882a593Smuzhiyun #define HV_N2_PERF_DRAM_CTL0		0x1
3222*4882a593Smuzhiyun #define HV_N2_PERF_DRAM_CNT0		0x2
3223*4882a593Smuzhiyun #define HV_N2_PERF_DRAM_CTL1		0x3
3224*4882a593Smuzhiyun #define HV_N2_PERF_DRAM_CNT1		0x4
3225*4882a593Smuzhiyun #define HV_N2_PERF_DRAM_CTL2		0x5
3226*4882a593Smuzhiyun #define HV_N2_PERF_DRAM_CNT2		0x6
3227*4882a593Smuzhiyun #define HV_N2_PERF_DRAM_CTL3		0x7
3228*4882a593Smuzhiyun #define HV_N2_PERF_DRAM_CNT3		0x8
3229*4882a593Smuzhiyun 
3230*4882a593Smuzhiyun #define HV_FAST_N2_GET_PERFREG		0x104
3231*4882a593Smuzhiyun #define HV_FAST_N2_SET_PERFREG		0x105
3232*4882a593Smuzhiyun 
3233*4882a593Smuzhiyun #ifndef __ASSEMBLY__
3234*4882a593Smuzhiyun unsigned long sun4v_niagara_getperf(unsigned long reg,
3235*4882a593Smuzhiyun 				    unsigned long *val);
3236*4882a593Smuzhiyun unsigned long sun4v_niagara_setperf(unsigned long reg,
3237*4882a593Smuzhiyun 				    unsigned long val);
3238*4882a593Smuzhiyun unsigned long sun4v_niagara2_getperf(unsigned long reg,
3239*4882a593Smuzhiyun 				     unsigned long *val);
3240*4882a593Smuzhiyun unsigned long sun4v_niagara2_setperf(unsigned long reg,
3241*4882a593Smuzhiyun 				     unsigned long val);
3242*4882a593Smuzhiyun #endif
3243*4882a593Smuzhiyun 
3244*4882a593Smuzhiyun /* MMU statistics services.
3245*4882a593Smuzhiyun  *
3246*4882a593Smuzhiyun  * The hypervisor maintains MMU statistics and privileged code provides
3247*4882a593Smuzhiyun  * a buffer where these statistics can be collected.  It is continually
3248*4882a593Smuzhiyun  * updated once configured.  The layout is as follows:
3249*4882a593Smuzhiyun  */
3250*4882a593Smuzhiyun #ifndef __ASSEMBLY__
3251*4882a593Smuzhiyun struct hv_mmu_statistics {
3252*4882a593Smuzhiyun 	unsigned long immu_tsb_hits_ctx0_8k_tte;
3253*4882a593Smuzhiyun 	unsigned long immu_tsb_ticks_ctx0_8k_tte;
3254*4882a593Smuzhiyun 	unsigned long immu_tsb_hits_ctx0_64k_tte;
3255*4882a593Smuzhiyun 	unsigned long immu_tsb_ticks_ctx0_64k_tte;
3256*4882a593Smuzhiyun 	unsigned long __reserved1[2];
3257*4882a593Smuzhiyun 	unsigned long immu_tsb_hits_ctx0_4mb_tte;
3258*4882a593Smuzhiyun 	unsigned long immu_tsb_ticks_ctx0_4mb_tte;
3259*4882a593Smuzhiyun 	unsigned long __reserved2[2];
3260*4882a593Smuzhiyun 	unsigned long immu_tsb_hits_ctx0_256mb_tte;
3261*4882a593Smuzhiyun 	unsigned long immu_tsb_ticks_ctx0_256mb_tte;
3262*4882a593Smuzhiyun 	unsigned long __reserved3[4];
3263*4882a593Smuzhiyun 	unsigned long immu_tsb_hits_ctxnon0_8k_tte;
3264*4882a593Smuzhiyun 	unsigned long immu_tsb_ticks_ctxnon0_8k_tte;
3265*4882a593Smuzhiyun 	unsigned long immu_tsb_hits_ctxnon0_64k_tte;
3266*4882a593Smuzhiyun 	unsigned long immu_tsb_ticks_ctxnon0_64k_tte;
3267*4882a593Smuzhiyun 	unsigned long __reserved4[2];
3268*4882a593Smuzhiyun 	unsigned long immu_tsb_hits_ctxnon0_4mb_tte;
3269*4882a593Smuzhiyun 	unsigned long immu_tsb_ticks_ctxnon0_4mb_tte;
3270*4882a593Smuzhiyun 	unsigned long __reserved5[2];
3271*4882a593Smuzhiyun 	unsigned long immu_tsb_hits_ctxnon0_256mb_tte;
3272*4882a593Smuzhiyun 	unsigned long immu_tsb_ticks_ctxnon0_256mb_tte;
3273*4882a593Smuzhiyun 	unsigned long __reserved6[4];
3274*4882a593Smuzhiyun 	unsigned long dmmu_tsb_hits_ctx0_8k_tte;
3275*4882a593Smuzhiyun 	unsigned long dmmu_tsb_ticks_ctx0_8k_tte;
3276*4882a593Smuzhiyun 	unsigned long dmmu_tsb_hits_ctx0_64k_tte;
3277*4882a593Smuzhiyun 	unsigned long dmmu_tsb_ticks_ctx0_64k_tte;
3278*4882a593Smuzhiyun 	unsigned long __reserved7[2];
3279*4882a593Smuzhiyun 	unsigned long dmmu_tsb_hits_ctx0_4mb_tte;
3280*4882a593Smuzhiyun 	unsigned long dmmu_tsb_ticks_ctx0_4mb_tte;
3281*4882a593Smuzhiyun 	unsigned long __reserved8[2];
3282*4882a593Smuzhiyun 	unsigned long dmmu_tsb_hits_ctx0_256mb_tte;
3283*4882a593Smuzhiyun 	unsigned long dmmu_tsb_ticks_ctx0_256mb_tte;
3284*4882a593Smuzhiyun 	unsigned long __reserved9[4];
3285*4882a593Smuzhiyun 	unsigned long dmmu_tsb_hits_ctxnon0_8k_tte;
3286*4882a593Smuzhiyun 	unsigned long dmmu_tsb_ticks_ctxnon0_8k_tte;
3287*4882a593Smuzhiyun 	unsigned long dmmu_tsb_hits_ctxnon0_64k_tte;
3288*4882a593Smuzhiyun 	unsigned long dmmu_tsb_ticks_ctxnon0_64k_tte;
3289*4882a593Smuzhiyun 	unsigned long __reserved10[2];
3290*4882a593Smuzhiyun 	unsigned long dmmu_tsb_hits_ctxnon0_4mb_tte;
3291*4882a593Smuzhiyun 	unsigned long dmmu_tsb_ticks_ctxnon0_4mb_tte;
3292*4882a593Smuzhiyun 	unsigned long __reserved11[2];
3293*4882a593Smuzhiyun 	unsigned long dmmu_tsb_hits_ctxnon0_256mb_tte;
3294*4882a593Smuzhiyun 	unsigned long dmmu_tsb_ticks_ctxnon0_256mb_tte;
3295*4882a593Smuzhiyun 	unsigned long __reserved12[4];
3296*4882a593Smuzhiyun };
3297*4882a593Smuzhiyun #endif
3298*4882a593Smuzhiyun 
3299*4882a593Smuzhiyun /* mmustat_conf()
3300*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
3301*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_MMUSTAT_CONF
3302*4882a593Smuzhiyun  * ARG0:	real address
3303*4882a593Smuzhiyun  * RET0:	status
3304*4882a593Smuzhiyun  * RET1:	real address
3305*4882a593Smuzhiyun  * ERRORS:	ENORADDR	Invalid real address
3306*4882a593Smuzhiyun  *		EBADALIGN	Real address not aligned on 64-byte boundary
3307*4882a593Smuzhiyun  *		EBADTRAP	API not supported on this processor
3308*4882a593Smuzhiyun  *
3309*4882a593Smuzhiyun  * Enable MMU statistic gathering using the buffer at the given real
3310*4882a593Smuzhiyun  * address on the current virtual CPU.  The new buffer real address
3311*4882a593Smuzhiyun  * is given in ARG1, and the previously specified buffer real address
3312*4882a593Smuzhiyun  * is returned in RET1, or is returned as zero for the first invocation.
3313*4882a593Smuzhiyun  *
3314*4882a593Smuzhiyun  * If the passed in real address argument is zero, this will disable
3315*4882a593Smuzhiyun  * MMU statistic collection on the current virtual CPU.  If an error is
3316*4882a593Smuzhiyun  * returned then no statistics are collected.
3317*4882a593Smuzhiyun  *
3318*4882a593Smuzhiyun  * The buffer contents should be initialized to all zeros before being
3319*4882a593Smuzhiyun  * given to the hypervisor or else the statistics will be meaningless.
3320*4882a593Smuzhiyun  */
3321*4882a593Smuzhiyun #define HV_FAST_MMUSTAT_CONF		0x102
3322*4882a593Smuzhiyun 
3323*4882a593Smuzhiyun /* mmustat_info()
3324*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
3325*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_MMUSTAT_INFO
3326*4882a593Smuzhiyun  * RET0:	status
3327*4882a593Smuzhiyun  * RET1:	real address
3328*4882a593Smuzhiyun  * ERRORS:	EBADTRAP	API not supported on this processor
3329*4882a593Smuzhiyun  *
3330*4882a593Smuzhiyun  * Return the current state and real address of the currently configured
3331*4882a593Smuzhiyun  * MMU statistics buffer on the current virtual CPU.
3332*4882a593Smuzhiyun  */
3333*4882a593Smuzhiyun #define HV_FAST_MMUSTAT_INFO		0x103
3334*4882a593Smuzhiyun 
3335*4882a593Smuzhiyun #ifndef __ASSEMBLY__
3336*4882a593Smuzhiyun unsigned long sun4v_mmustat_conf(unsigned long ra, unsigned long *orig_ra);
3337*4882a593Smuzhiyun unsigned long sun4v_mmustat_info(unsigned long *ra);
3338*4882a593Smuzhiyun #endif
3339*4882a593Smuzhiyun 
3340*4882a593Smuzhiyun /* NCS crypto services  */
3341*4882a593Smuzhiyun 
3342*4882a593Smuzhiyun /* ncs_request() sub-function numbers */
3343*4882a593Smuzhiyun #define HV_NCS_QCONF			0x01
3344*4882a593Smuzhiyun #define HV_NCS_QTAIL_UPDATE		0x02
3345*4882a593Smuzhiyun 
3346*4882a593Smuzhiyun #ifndef __ASSEMBLY__
3347*4882a593Smuzhiyun struct hv_ncs_queue_entry {
3348*4882a593Smuzhiyun 	/* MAU Control Register */
3349*4882a593Smuzhiyun 	unsigned long	mau_control;
3350*4882a593Smuzhiyun #define MAU_CONTROL_INV_PARITY	0x0000000000002000
3351*4882a593Smuzhiyun #define MAU_CONTROL_STRAND	0x0000000000001800
3352*4882a593Smuzhiyun #define MAU_CONTROL_BUSY	0x0000000000000400
3353*4882a593Smuzhiyun #define MAU_CONTROL_INT		0x0000000000000200
3354*4882a593Smuzhiyun #define MAU_CONTROL_OP		0x00000000000001c0
3355*4882a593Smuzhiyun #define MAU_CONTROL_OP_SHIFT	6
3356*4882a593Smuzhiyun #define MAU_OP_LOAD_MA_MEMORY	0x0
3357*4882a593Smuzhiyun #define MAU_OP_STORE_MA_MEMORY	0x1
3358*4882a593Smuzhiyun #define MAU_OP_MODULAR_MULT	0x2
3359*4882a593Smuzhiyun #define MAU_OP_MODULAR_REDUCE	0x3
3360*4882a593Smuzhiyun #define MAU_OP_MODULAR_EXP_LOOP	0x4
3361*4882a593Smuzhiyun #define MAU_CONTROL_LEN		0x000000000000003f
3362*4882a593Smuzhiyun #define MAU_CONTROL_LEN_SHIFT	0
3363*4882a593Smuzhiyun 
3364*4882a593Smuzhiyun 	/* Real address of bytes to load or store bytes
3365*4882a593Smuzhiyun 	 * into/out-of the MAU.
3366*4882a593Smuzhiyun 	 */
3367*4882a593Smuzhiyun 	unsigned long	mau_mpa;
3368*4882a593Smuzhiyun 
3369*4882a593Smuzhiyun 	/* Modular Arithmetic MA Offset Register.  */
3370*4882a593Smuzhiyun 	unsigned long	mau_ma;
3371*4882a593Smuzhiyun 
3372*4882a593Smuzhiyun 	/* Modular Arithmetic N Prime Register.  */
3373*4882a593Smuzhiyun 	unsigned long	mau_np;
3374*4882a593Smuzhiyun };
3375*4882a593Smuzhiyun 
3376*4882a593Smuzhiyun struct hv_ncs_qconf_arg {
3377*4882a593Smuzhiyun 	unsigned long	mid;      /* MAU ID, 1 per core on Niagara */
3378*4882a593Smuzhiyun 	unsigned long	base;     /* Real address base of queue */
3379*4882a593Smuzhiyun 	unsigned long	end;	  /* Real address end of queue */
3380*4882a593Smuzhiyun 	unsigned long	num_ents; /* Number of entries in queue */
3381*4882a593Smuzhiyun };
3382*4882a593Smuzhiyun 
3383*4882a593Smuzhiyun struct hv_ncs_qtail_update_arg {
3384*4882a593Smuzhiyun 	unsigned long	mid;      /* MAU ID, 1 per core on Niagara */
3385*4882a593Smuzhiyun 	unsigned long	tail;     /* New tail index to use */
3386*4882a593Smuzhiyun 	unsigned long	syncflag; /* only SYNCFLAG_SYNC is implemented */
3387*4882a593Smuzhiyun #define HV_NCS_SYNCFLAG_SYNC	0x00
3388*4882a593Smuzhiyun #define HV_NCS_SYNCFLAG_ASYNC	0x01
3389*4882a593Smuzhiyun };
3390*4882a593Smuzhiyun #endif
3391*4882a593Smuzhiyun 
3392*4882a593Smuzhiyun /* ncs_request()
3393*4882a593Smuzhiyun  * TRAP:	HV_FAST_TRAP
3394*4882a593Smuzhiyun  * FUNCTION:	HV_FAST_NCS_REQUEST
3395*4882a593Smuzhiyun  * ARG0:	NCS sub-function
3396*4882a593Smuzhiyun  * ARG1:	sub-function argument real address
3397*4882a593Smuzhiyun  * ARG2:	size in bytes of sub-function argument
3398*4882a593Smuzhiyun  * RET0:	status
3399*4882a593Smuzhiyun  *
3400*4882a593Smuzhiyun  * The MAU chip of the Niagara processor is not directly accessible
3401*4882a593Smuzhiyun  * to privileged code, instead it is programmed indirectly via this
3402*4882a593Smuzhiyun  * hypervisor API.
3403*4882a593Smuzhiyun  *
3404*4882a593Smuzhiyun  * The interfaces defines a queue of MAU operations to perform.
3405*4882a593Smuzhiyun  * Privileged code registers a queue with the hypervisor by invoking
3406*4882a593Smuzhiyun  * this HVAPI with the HV_NCS_QCONF sub-function, which defines the
3407*4882a593Smuzhiyun  * base, end, and number of entries of the queue.  Each queue entry
3408*4882a593Smuzhiyun  * contains a MAU register struct block.
3409*4882a593Smuzhiyun  *
3410*4882a593Smuzhiyun  * The privileged code then proceeds to add entries to the queue and
3411*4882a593Smuzhiyun  * then invoke the HV_NCS_QTAIL_UPDATE sub-function.  Since only
3412*4882a593Smuzhiyun  * synchronous operations are supported by the current hypervisor,
3413*4882a593Smuzhiyun  * HV_NCS_QTAIL_UPDATE will run all the pending queue entries to
3414*4882a593Smuzhiyun  * completion and return HV_EOK, or return an error code.
3415*4882a593Smuzhiyun  *
3416*4882a593Smuzhiyun  * The real address of the sub-function argument must be aligned on at
3417*4882a593Smuzhiyun  * least an 8-byte boundary.
3418*4882a593Smuzhiyun  *
3419*4882a593Smuzhiyun  * The tail argument of HV_NCS_QTAIL_UPDATE is an index, not a byte
3420*4882a593Smuzhiyun  * offset, into the queue and must be less than or equal the 'num_ents'
3421*4882a593Smuzhiyun  * argument given in the HV_NCS_QCONF call.
3422*4882a593Smuzhiyun  */
3423*4882a593Smuzhiyun #define HV_FAST_NCS_REQUEST		0x110
3424*4882a593Smuzhiyun 
3425*4882a593Smuzhiyun #ifndef __ASSEMBLY__
3426*4882a593Smuzhiyun unsigned long sun4v_ncs_request(unsigned long request,
3427*4882a593Smuzhiyun 			        unsigned long arg_ra,
3428*4882a593Smuzhiyun 			        unsigned long arg_size);
3429*4882a593Smuzhiyun #endif
3430*4882a593Smuzhiyun 
3431*4882a593Smuzhiyun #define HV_FAST_FIRE_GET_PERFREG	0x120
3432*4882a593Smuzhiyun #define HV_FAST_FIRE_SET_PERFREG	0x121
3433*4882a593Smuzhiyun 
3434*4882a593Smuzhiyun #define HV_FAST_REBOOT_DATA_SET		0x172
3435*4882a593Smuzhiyun 
3436*4882a593Smuzhiyun #ifndef __ASSEMBLY__
3437*4882a593Smuzhiyun unsigned long sun4v_reboot_data_set(unsigned long ra,
3438*4882a593Smuzhiyun 				    unsigned long len);
3439*4882a593Smuzhiyun #endif
3440*4882a593Smuzhiyun 
3441*4882a593Smuzhiyun #define HV_FAST_VT_GET_PERFREG		0x184
3442*4882a593Smuzhiyun #define HV_FAST_VT_SET_PERFREG		0x185
3443*4882a593Smuzhiyun 
3444*4882a593Smuzhiyun #ifndef __ASSEMBLY__
3445*4882a593Smuzhiyun unsigned long sun4v_vt_get_perfreg(unsigned long reg_num,
3446*4882a593Smuzhiyun 				   unsigned long *reg_val);
3447*4882a593Smuzhiyun unsigned long sun4v_vt_set_perfreg(unsigned long reg_num,
3448*4882a593Smuzhiyun 				   unsigned long reg_val);
3449*4882a593Smuzhiyun #endif
3450*4882a593Smuzhiyun 
3451*4882a593Smuzhiyun #define	HV_FAST_T5_GET_PERFREG		0x1a8
3452*4882a593Smuzhiyun #define	HV_FAST_T5_SET_PERFREG		0x1a9
3453*4882a593Smuzhiyun 
3454*4882a593Smuzhiyun #ifndef	__ASSEMBLY__
3455*4882a593Smuzhiyun unsigned long sun4v_t5_get_perfreg(unsigned long reg_num,
3456*4882a593Smuzhiyun 				   unsigned long *reg_val);
3457*4882a593Smuzhiyun unsigned long sun4v_t5_set_perfreg(unsigned long reg_num,
3458*4882a593Smuzhiyun 				   unsigned long reg_val);
3459*4882a593Smuzhiyun #endif
3460*4882a593Smuzhiyun 
3461*4882a593Smuzhiyun 
3462*4882a593Smuzhiyun #define HV_FAST_M7_GET_PERFREG	0x43
3463*4882a593Smuzhiyun #define HV_FAST_M7_SET_PERFREG	0x44
3464*4882a593Smuzhiyun 
3465*4882a593Smuzhiyun #ifndef	__ASSEMBLY__
3466*4882a593Smuzhiyun unsigned long sun4v_m7_get_perfreg(unsigned long reg_num,
3467*4882a593Smuzhiyun 				      unsigned long *reg_val);
3468*4882a593Smuzhiyun unsigned long sun4v_m7_set_perfreg(unsigned long reg_num,
3469*4882a593Smuzhiyun 				      unsigned long reg_val);
3470*4882a593Smuzhiyun #endif
3471*4882a593Smuzhiyun 
3472*4882a593Smuzhiyun /* Function numbers for HV_CORE_TRAP.  */
3473*4882a593Smuzhiyun #define HV_CORE_SET_VER			0x00
3474*4882a593Smuzhiyun #define HV_CORE_PUTCHAR			0x01
3475*4882a593Smuzhiyun #define HV_CORE_EXIT			0x02
3476*4882a593Smuzhiyun #define HV_CORE_GET_VER			0x03
3477*4882a593Smuzhiyun 
3478*4882a593Smuzhiyun /* Hypervisor API groups for use with HV_CORE_SET_VER and
3479*4882a593Smuzhiyun  * HV_CORE_GET_VER.
3480*4882a593Smuzhiyun  */
3481*4882a593Smuzhiyun #define HV_GRP_SUN4V			0x0000
3482*4882a593Smuzhiyun #define HV_GRP_CORE			0x0001
3483*4882a593Smuzhiyun #define HV_GRP_INTR			0x0002
3484*4882a593Smuzhiyun #define HV_GRP_SOFT_STATE		0x0003
3485*4882a593Smuzhiyun #define HV_GRP_TM			0x0080
3486*4882a593Smuzhiyun #define HV_GRP_PCI			0x0100
3487*4882a593Smuzhiyun #define HV_GRP_LDOM			0x0101
3488*4882a593Smuzhiyun #define HV_GRP_SVC_CHAN			0x0102
3489*4882a593Smuzhiyun #define HV_GRP_NCS			0x0103
3490*4882a593Smuzhiyun #define HV_GRP_RNG			0x0104
3491*4882a593Smuzhiyun #define HV_GRP_PBOOT			0x0105
3492*4882a593Smuzhiyun #define HV_GRP_TPM			0x0107
3493*4882a593Smuzhiyun #define HV_GRP_SDIO			0x0108
3494*4882a593Smuzhiyun #define HV_GRP_SDIO_ERR			0x0109
3495*4882a593Smuzhiyun #define HV_GRP_REBOOT_DATA		0x0110
3496*4882a593Smuzhiyun #define HV_GRP_ATU			0x0111
3497*4882a593Smuzhiyun #define HV_GRP_DAX			0x0113
3498*4882a593Smuzhiyun #define HV_GRP_M7_PERF			0x0114
3499*4882a593Smuzhiyun #define HV_GRP_NIAG_PERF		0x0200
3500*4882a593Smuzhiyun #define HV_GRP_FIRE_PERF		0x0201
3501*4882a593Smuzhiyun #define HV_GRP_N2_CPU			0x0202
3502*4882a593Smuzhiyun #define HV_GRP_NIU			0x0204
3503*4882a593Smuzhiyun #define HV_GRP_VF_CPU			0x0205
3504*4882a593Smuzhiyun #define HV_GRP_KT_CPU			0x0209
3505*4882a593Smuzhiyun #define HV_GRP_VT_CPU			0x020c
3506*4882a593Smuzhiyun #define HV_GRP_T5_CPU			0x0211
3507*4882a593Smuzhiyun #define HV_GRP_DIAG			0x0300
3508*4882a593Smuzhiyun 
3509*4882a593Smuzhiyun #ifndef __ASSEMBLY__
3510*4882a593Smuzhiyun unsigned long sun4v_get_version(unsigned long group,
3511*4882a593Smuzhiyun 			        unsigned long *major,
3512*4882a593Smuzhiyun 			        unsigned long *minor);
3513*4882a593Smuzhiyun unsigned long sun4v_set_version(unsigned long group,
3514*4882a593Smuzhiyun 			        unsigned long major,
3515*4882a593Smuzhiyun 			        unsigned long minor,
3516*4882a593Smuzhiyun 			        unsigned long *actual_minor);
3517*4882a593Smuzhiyun 
3518*4882a593Smuzhiyun int sun4v_hvapi_register(unsigned long group, unsigned long major,
3519*4882a593Smuzhiyun 			 unsigned long *minor);
3520*4882a593Smuzhiyun void sun4v_hvapi_unregister(unsigned long group);
3521*4882a593Smuzhiyun int sun4v_hvapi_get(unsigned long group,
3522*4882a593Smuzhiyun 		    unsigned long *major,
3523*4882a593Smuzhiyun 		    unsigned long *minor);
3524*4882a593Smuzhiyun void sun4v_hvapi_init(void);
3525*4882a593Smuzhiyun #endif
3526*4882a593Smuzhiyun 
3527*4882a593Smuzhiyun #endif /* !(_SPARC64_HYPERVISOR_H) */
3528