[SPARC64]: Add sun4v_cpu_yield().
[powerpc.git] / include / asm-sparc64 / hypervisor.h
1 #ifndef _SPARC64_HYPERVISOR_H
2 #define _SPARC64_HYPERVISOR_H
3
4 /* Sun4v hypervisor interfaces and defines.
5  *
6  * Hypervisor calls are made via traps to software traps number 0x80
7  * and above.  Registers %o0 to %o5 serve as argument, status, and
8  * return value registers.
9  *
10  * There are two kinds of these traps.  First there are the normal
11  * "fast traps" which use software trap 0x80 and encode the function
12  * to invoke by number in register %o5.  Argument and return value
13  * handling is as follows:
14  *
15  * -----------------------------------------------
16  * |  %o5  | function number |     undefined     |
17  * |  %o0  |   argument 0    |   return status   |
18  * |  %o1  |   argument 1    |   return value 1  |
19  * |  %o2  |   argument 2    |   return value 2  |
20  * |  %o3  |   argument 3    |   return value 3  |
21  * |  %o4  |   argument 4    |   return value 4  |
22  * -----------------------------------------------
23  *
24  * The second type are "hyper-fast traps" which encode the function
25  * number in the software trap number itself.  So these use trap
26  * numbers > 0x80.  The register usage for hyper-fast traps is as
27  * follows:
28  *
29  * -----------------------------------------------
30  * |  %o0  |   argument 0    |   return status   |
31  * |  %o1  |   argument 1    |   return value 1  |
32  * |  %o2  |   argument 2    |   return value 2  |
33  * |  %o3  |   argument 3    |   return value 3  |
34  * |  %o4  |   argument 4    |   return value 4  |
35  * -----------------------------------------------
36  *
37  * Registers providing explicit arguments to the hypervisor calls
38  * are volatile across the call.  Upon return their values are
39  * undefined unless explicitly specified as containing a particular
40  * return value by the specific call.  The return status is always
41  * returned in register %o0, zero indicates a successful execution of
42  * the hypervisor call and other values indicate an error status as
43  * defined below.  So, for example, if a hyper-fast trap takes
44  * arguments 0, 1, and 2, then %o0, %o1, and %o2 are volatile across
45  * the call and %o3, %o4, and %o5 would be preserved.
46  *
47  * If the hypervisor trap is invalid, or the fast trap function number
48  * is invalid, HV_EBADTRAP will be returned in %o0.  Also, all 64-bits
49  * of the argument and return values are significant.
50  */
51
52 /* Trap numbers.  */
53 #define HV_FAST_TRAP            0x80
54 #define HV_MMU_MAP_ADDR_TRAP    0x83
55 #define HV_MMU_UNMAP_ADDR_TRAP  0x84
56 #define HV_TTRACE_ADDENTRY_TRAP 0x85
57 #define HV_CORE_TRAP            0xff
58
59 /* Error codes.  */
60 #define HV_EOK                          0  /* Successful return            */
61 #define HV_ENOCPU                       1  /* Invalid CPU id               */
62 #define HV_ENORADDR                     2  /* Invalid real address         */
63 #define HV_ENOINTR                      3  /* Invalid interrupt id         */
64 #define HV_EBADPGSZ                     4  /* Invalid pagesize encoding    */
65 #define HV_EBADTSB                      5  /* Invalid TSB description      */
66 #define HV_EINVAL                       6  /* Invalid argument             */
67 #define HV_EBADTRAP                     7  /* Invalid function number      */
68 #define HV_EBADALIGN                    8  /* Invalid address alignment    */
69 #define HV_EWOULDBLOCK                  9  /* Cannot complete w/o blocking */
70 #define HV_ENOACCESS                    10 /* No access to resource        */
71 #define HV_EIO                          11 /* I/O error                    */
72 #define HV_ECPUERROR                    12 /* CPU in error state           */
73 #define HV_ENOTSUPPORTED                13 /* Function not supported       */
74 #define HV_ENOMAP                       14 /* No mapping found             */
75 #define HV_ETOOMANY                     15 /* Too many items specified     */
76
77 /* mach_exit()
78  * TRAP:        HV_FAST_TRAP
79  * FUNCTION:    HV_FAST_MACH_EXIT
80  * ARG0:        exit code
81  * ERRORS:      This service does not return.
82  *
83  * Stop all CPUs in the virtual domain and place them into the stopped
84  * state.  The 64-bit exit code may be passed to a service entity as
85  * the domain's exit status.  On systems without a service entity, the
86  * domain will undergo a reset, and the boot firmware will be
87  * reloaded.
88  *
89  * This function will never return to the guest that invokes it.
90  *
91  * Note: By convention an exit code of zero denotes a successful exit by
92  *       the guest code.  A non-zero exit code denotes a guest specific
93  *       error indication.
94  *
95  */
96 #define HV_FAST_MACH_EXIT               0x00
97
98 /* Domain services.  */
99
100 /* mach_desc()
101  * TRAP:        HV_FAST_TRAP
102  * FUNCTION:    HV_FAST_MACH_DESC
103  * ARG0:        buffer
104  * ARG1:        length
105  * RET0:        status
106  * RET1:        length
107  * ERRORS:      HV_EBADALIGN    Buffer is badly aligned
108  *              HV_ENORADDR     Buffer is to an illegal real address.
109  *              HV_EINVAL       Buffer length is too small for complete
110  *                              machine description.
111  *
112  * Copy the most current machine description into the buffer indicated
113  * by the real address in ARG0.  The buffer provided must be 16 byte
114  * aligned.  Upon success or HV_EINVAL, this service returns the
115  * actual size of the machine description in the RET1 return value.
116  *
117  * Note: A method of determining the appropriate buffer size for the
118  *       machine description is to first call this service with a buffer
119  *       length of 0 bytes.
120  */
121 #define HV_FAST_MACH_DESC               0x01
122
123 /* mach_exit()
124  * TRAP:        HV_FAST_TRAP
125  * FUNCTION:    HV_FAST_MACH_SIR
126  * ERRORS:      This service does not return.
127  *
128  * Perform a software initiated reset of the virtual machine domain.
129  * All CPUs are captured as soon as possible, all hardware devices are
130  * returned to the entry default state, and the domain is restarted at
131  * the SIR (trap type 0x04) real trap table (RTBA) entry point on one
132  * of the CPUs.  The single CPU restarted is selected as determined by
133  * platform specific policy.  Memory is preserved across this
134  * operation.
135  */
136 #define HV_FAST_MACH_SIR                0x02
137
138 /* mach_set_soft_state()
139  * TRAP:        HV_FAST_TRAP
140  * FUNCTION:    HV_FAST_MACH_SET_SOFT_STATE
141  * ARG0:        software state
142  * ARG1:        software state description pointer
143  * RET0:        status
144  * ERRORS:      EINVAL          software state not valid or software state
145  *                              description is not NULL terminated
146  *              ENORADDR        software state description pointer is not a
147  *                              valid real address
148  *              EBADALIGNED     software state description is not correctly
149  *                              aligned
150  *
151  * This allows the guest to report it's soft state to the hypervisor.  There
152  * are two primary components to this state.  The first part states whether
153  * the guest software is running or not.  The second containts optional
154  * details specific to the software.
155  *
156  * The software state argument is defined below in HV_SOFT_STATE_*, and
157  * indicates whether the guest is operating normally or in a transitional
158  * state.
159  *
160  * The software state description argument is a real address of a data buffer
161  * of size 32-bytes aligned on a 32-byte boundary.  It is treated as a NULL
162  * terminated 7-bit ASCII string of up to 31 characters not including the
163  * NULL termination.
164  */
165 #define HV_FAST_MACH_SET_SOFT_STATE     0x03
166 #define  HV_SOFT_STATE_NORMAL            0x01
167 #define  HV_SOFT_STATE_TRANSITION        0x02
168
169 /* mach_get_soft_state()
170  * TRAP:        HV_FAST_TRAP
171  * FUNCTION:    HV_FAST_MACH_GET_SOFT_STATE
172  * ARG0:        software state description pointer
173  * RET0:        status
174  * RET1:        software state
175  * ERRORS:      ENORADDR        software state description pointer is not a
176  *                              valid real address
177  *              EBADALIGNED     software state description is not correctly
178  *                              aligned
179  *
180  * Retrieve the current value of the guest's software state.  The rules
181  * for the software state pointer are the same as for mach_set_soft_state()
182  * above.
183  */
184 #define HV_FAST_MACH_GET_SOFT_STATE     0x04
185
186 /* CPU services.
187  *
188  * CPUs represent devices that can execute software threads.  A single
189  * chip that contains multiple cores or strands is represented as
190  * multiple CPUs with unique CPU identifiers.  CPUs are exported to
191  * OBP via the machine description (and to the OS via the OBP device
192  * tree).  CPUs are always in one of three states: stopped, running,
193  * or error.
194  *
195  * A CPU ID is a pre-assigned 16-bit value that uniquely identifies a
196  * CPU within a logical domain.  Operations that are to be performed
197  * on multiple CPUs specify them via a CPU list.  A CPU list is an
198  * array in real memory, of which each 16-bit word is a CPU ID.  CPU
199  * lists are passed through the API as two arguments.  The first is
200  * the number of entries (16-bit words) in the CPU list, and the
201  * second is the (real address) pointer to the CPU ID list.
202  */
203
204 /* cpu_start()
205  * TRAP:        HV_FAST_TRAP
206  * FUNCTION:    HV_FAST_CPU_START
207  * ARG0:        CPU ID
208  * ARG1:        PC
209  * ARG1:        RTBA
210  * ARG1:        target ARG0
211  * RET0:        status
212  * ERRORS:      ENOCPU          Invalid CPU ID
213  *              EINVAL          Target CPU ID is not in the stopped state
214  *              ENORADDR        Invalid PC or RTBA real address
215  *              EBADALIGN       Unaligned PC or unaligned RTBA
216  *              EWOULDBLOCK     Starting resources are not available
217  *
218  * Start CPU with given CPU ID with PC in %pc and with a real trap
219  * base address value of RTBA.  The indicated CPU must be in the
220  * stopped state.  The supplied RTBA must be aligned on a 256 byte
221  * boundary.  On successful completion, the specified CPU will be in
222  * the running state and will be supplied with "target ARG0" in %o0
223  * and RTBA in %tba.
224  */
225 #define HV_FAST_CPU_START               0x10
226
227 /* cpu_stop()
228  * TRAP:        HV_FAST_TRAP
229  * FUNCTION:    HV_FAST_CPU_STOP
230  * ARG0:        CPU ID
231  * RET0:        status
232  * ERRORS:      ENOCPU          Invalid CPU ID
233  *              EINVAL          Target CPU ID is the current cpu
234  *              EINVAL          Target CPU ID is not in the running state
235  *              EWOULDBLOCK     Stopping resources are not available
236  *              ENOTSUPPORTED   Not supported on this platform
237  *
238  * The specified CPU is stopped.  The indicated CPU must be in the
239  * running state.  On completion, it will be in the stopped state.  It
240  * is not legal to stop the current CPU.
241  *
242  * Note: As this service cannot be used to stop the current cpu, this service
243  *       may not be used to stop the last running CPU in a domain.  To stop
244  *       and exit a running domain, a guest must use the mach_exit() service.
245  */
246 #define HV_FAST_CPU_STOP                0x11
247
248 /* cpu_yield()
249  * TRAP:        HV_FAST_TRAP
250  * FUNCTION:    HV_FAST_CPU_YIELD
251  * RET0:        status
252  * ERRORS:      No possible error.
253  *
254  * Suspend execution on the current CPU.  Execution will resume when
255  * an interrupt (device, %stick_compare, or cross-call) is targeted to
256  * the CPU.  On some CPUs, this API may be used by the hypervisor to
257  * save power by disabling hardware strands.
258  */
259 #define HV_FAST_CPU_YIELD               0x12
260
261 #ifndef __ASSEMBLY__
262 extern unsigned long sun4v_cpu_yield(void);
263 #endif
264
265 /* cpu_qconf()
266  * TRAP:        HV_FAST_TRAP
267  * FUNCTION:    HV_FAST_CPU_QCONF
268  * ARG0:        queue
269  * ARG1:        base real address
270  * ARG2:        number of entries
271  * RET0:        status
272  * ERRORS:      ENORADDR        Invalid base real address
273  *              EINVAL          Invalid queue or number of entries is less
274  *                              than 2 or too large.
275  *              EBADALIGN       Base real address is not correctly aligned
276  *                              for size.
277  *
278  * Configure the given queue to be placed at the given base real
279  * address, with the given number of entries.  The number of entries
280  * must be a power of 2.  The base real address must be aligned
281  * exactly to match the queue size.  Each queue entry is 64 bytes
282  * long, so for example a 32 entry queue must be aligned on a 2048
283  * byte real address boundary.
284  *
285  * The specified queue is unconfigured if the number of entries is given
286  * as zero.
287  *
288  * For the current version of this API service, the argument queue is defined
289  * as follows:
290  *
291  *      queue           description
292  *      -----           -------------------------
293  *      0x3c            cpu mondo queue
294  *      0x3d            device mondo queue
295  *      0x3e            resumable error queue
296  *      0x3f            non-resumable error queue
297  *
298  * Note: The maximum number of entries for each queue for a specific cpu may
299  *       be determined from the machine description.
300  */
301 #define HV_FAST_CPU_QCONF               0x14
302 #define  HV_CPU_QUEUE_CPU_MONDO          0x3c
303 #define  HV_CPU_QUEUE_DEVICE_MONDO       0x3d
304 #define  HV_CPU_QUEUE_RES_ERROR          0x3e
305 #define  HV_CPU_QUEUE_NONRES_ERROR       0x3f
306
307 #ifndef __ASSEMBLY__
308 extern unsigned long sun4v_cpu_qconf(unsigned long type,
309                                      unsigned long queue_paddr,
310                                      unsigned long num_queue_entries);
311 #endif
312
313 /* cpu_qinfo()
314  * TRAP:        HV_FAST_TRAP
315  * FUNCTION:    HV_FAST_CPU_QINFO
316  * ARG0:        queue
317  * RET0:        status
318  * RET1:        base real address
319  * RET1:        number of entries
320  * ERRORS:      EINVAL          Invalid queue
321  *
322  * Return the configuration info for the given queue.  The base real
323  * address and number of entries of the defined queue are returned.
324  * The queue argument values are the same as for cpu_qconf() above.
325  *
326  * If the specified queue is a valid queue number, but no queue has
327  * been defined, the number of entries will be set to zero and the
328  * base real address returned is undefined.
329  */
330 #define HV_FAST_CPU_QINFO               0x15
331
332 /* cpu_mondo_send()
333  * TRAP:        HV_FAST_TRAP
334  * FUNCTION:    HV_FAST_CPU_MONDO_SEND
335  * ARG0-1:      CPU list
336  * ARG2:        data real address
337  * RET0:        status
338  * ERRORS:      EBADALIGN       Mondo data is not 64-byte aligned or CPU list
339  *                              is not 2-byte aligned.
340  *              ENORADDR        Invalid data mondo address, or invalid cpu list
341  *                              address.
342  *              ENOCPU          Invalid cpu in CPU list
343  *              EWOULDBLOCK     Some or all of the listed CPUs did not receive
344  *                              the mondo
345  *              EINVAL          CPU list includes caller's CPU ID
346  *
347  * Send a mondo interrupt to the CPUs in the given CPU list with the
348  * 64-bytes at the given data real address.  The data must be 64-byte
349  * aligned.  The mondo data will be delivered to the cpu_mondo queues
350  * of the recipient CPUs.
351  *
352  * In all cases, error or not, the CPUs in the CPU list to which the
353  * mondo has been successfully delivered will be indicated by having
354  * their entry in CPU list updated with the value 0xffff.
355  */
356 #define HV_FAST_CPU_MONDO_SEND          0x42
357
358 /* cpu_myid()
359  * TRAP:        HV_FAST_TRAP
360  * FUNCTION:    HV_FAST_CPU_MYID
361  * RET0:        status
362  * RET1:        CPU ID
363  * ERRORS:      No errors defined.
364  *
365  * Return the hypervisor ID handle for the current CPU.  Use by a
366  * virtual CPU to discover it's own identity.
367  */
368 #define HV_FAST_CPU_MYID                0x16
369
370 /* cpu_state()
371  * TRAP:        HV_FAST_TRAP
372  * FUNCTION:    HV_FAST_CPU_STATE
373  * ARG0:        CPU ID
374  * RET0:        status
375  * RET1:        state
376  * ERRORS:      ENOCPU          Invalid CPU ID
377  *
378  * Retrieve the current state of the CPU with the given CPU ID.
379  */
380 #define HV_FAST_CPU_STATE               0x17
381 #define  HV_CPU_STATE_STOPPED            0x01
382 #define  HV_CPU_STATE_RUNNING            0x02
383 #define  HV_CPU_STATE_ERROR              0x03
384
385 /* cpu_set_rtba()
386  * TRAP:        HV_FAST_TRAP
387  * FUNCTION:    HV_FAST_CPU_SET_RTBA
388  * ARG0:        RTBA
389  * RET0:        status
390  * RET1:        previous RTBA
391  * ERRORS:      ENORADDR        Invalid RTBA real address
392  *              EBADALIGN       RTBA is incorrectly aligned for a trap table
393  *
394  * Set the real trap base address of the local cpu to the given RTBA.
395  * The supplied RTBA must be aligned on a 256 byte boundary.  Upon
396  * success the previous value of the RTBA is returned in RET1.
397  *
398  * Note: This service does not affect %tba
399  */
400 #define HV_FAST_CPU_SET_RTBA            0x18
401
402 /* cpu_set_rtba()
403  * TRAP:        HV_FAST_TRAP
404  * FUNCTION:    HV_FAST_CPU_GET_RTBA
405  * RET0:        status
406  * RET1:        previous RTBA
407  * ERRORS:      No possible error.
408  *
409  * Returns the current value of RTBA in RET1.
410  */
411 #define HV_FAST_CPU_GET_RTBA            0x19
412
413 /* MMU services.
414  *
415  * Layout of a TSB description for mmu_tsb_ctx{,non}0() calls.
416  */
417 #ifndef __ASSEMBLY__
418 struct hv_tsb_descr {
419         unsigned short          pgsz_idx;
420         unsigned short          assoc;
421         unsigned int            num_ttes;       /* in TTEs */
422         unsigned int            ctx_idx;
423         unsigned int            pgsz_mask;
424         unsigned long           tsb_base;
425         unsigned long           resv;
426 };
427 #endif
428 #define HV_TSB_DESCR_PGSZ_IDX_OFFSET    0x00
429 #define HV_TSB_DESCR_ASSOC_OFFSET       0x02
430 #define HV_TSB_DESCR_NUM_TTES_OFFSET    0x04
431 #define HV_TSB_DESCR_CTX_IDX_OFFSET     0x08
432 #define HV_TSB_DESCR_PGSZ_MASK_OFFSET   0x0c
433 #define HV_TSB_DESCR_TSB_BASE_OFFSET    0x10
434 #define HV_TSB_DESCR_RESV_OFFSET        0x18
435
436 /* Page size bitmask.  */
437 #define HV_PGSZ_MASK_8K                 (1 << 0)
438 #define HV_PGSZ_MASK_64K                (1 << 1)
439 #define HV_PGSZ_MASK_512K               (1 << 2)
440 #define HV_PGSZ_MASK_4MB                (1 << 3)
441 #define HV_PGSZ_MASK_32MB               (1 << 4)
442 #define HV_PGSZ_MASK_256MB              (1 << 5)
443 #define HV_PGSZ_MASK_2GB                (1 << 6)
444 #define HV_PGSZ_MASK_16GB               (1 << 7)
445
446 /* Page size index.  The value given in the TSB descriptor must correspond
447  * to the smallest page size specified in the pgsz_mask page size bitmask.
448  */
449 #define HV_PGSZ_IDX_8K                  0
450 #define HV_PGSZ_IDX_64K                 1
451 #define HV_PGSZ_IDX_512K                2
452 #define HV_PGSZ_IDX_4MB                 3
453 #define HV_PGSZ_IDX_32MB                4
454 #define HV_PGSZ_IDX_256MB               5
455 #define HV_PGSZ_IDX_2GB                 6
456 #define HV_PGSZ_IDX_16GB                7
457
458 /* MMU fault status area.
459  *
460  * MMU related faults have their status and fault address information
461  * placed into a memory region made available by privileged code.  Each
462  * virtual processor must make a mmu_fault_area_conf() call to tell the
463  * hypervisor where that processor's fault status should be stored.
464  *
465  * The fault status block is a multiple of 64-bytes and must be aligned
466  * on a 64-byte boundary.
467  */
468 #ifndef __ASSEMBLY__
469 struct hv_fault_status {
470         unsigned long           i_fault_type;
471         unsigned long           i_fault_addr;
472         unsigned long           i_fault_ctx;
473         unsigned long           i_reserved[5];
474         unsigned long           d_fault_type;
475         unsigned long           d_fault_addr;
476         unsigned long           d_fault_ctx;
477         unsigned long           d_reserved[5];
478 };
479 #endif
480 #define HV_FAULT_I_TYPE_OFFSET  0x00
481 #define HV_FAULT_I_ADDR_OFFSET  0x08
482 #define HV_FAULT_I_CTX_OFFSET   0x10
483 #define HV_FAULT_D_TYPE_OFFSET  0x40
484 #define HV_FAULT_D_ADDR_OFFSET  0x48
485 #define HV_FAULT_D_CTX_OFFSET   0x50
486
487 #define HV_FAULT_TYPE_FAST_MISS 1
488 #define HV_FAULT_TYPE_FAST_PROT 2
489 #define HV_FAULT_TYPE_MMU_MISS  3
490 #define HV_FAULT_TYPE_INV_RA    4
491 #define HV_FAULT_TYPE_PRIV_VIOL 5
492 #define HV_FAULT_TYPE_PROT_VIOL 6
493 #define HV_FAULT_TYPE_NFO       7
494 #define HV_FAULT_TYPE_NFO_SEFF  8
495 #define HV_FAULT_TYPE_INV_VA    9
496 #define HV_FAULT_TYPE_INV_ASI   10
497 #define HV_FAULT_TYPE_NC_ATOMIC 11
498 #define HV_FAULT_TYPE_PRIV_ACT  12
499 #define HV_FAULT_TYPE_RESV1     13
500 #define HV_FAULT_TYPE_UNALIGNED 14
501 #define HV_FAULT_TYPE_INV_PGSZ  15
502 /* Values 16 --> -2 are reserved.  */
503 #define HV_FAULT_TYPE_MULTIPLE  -1
504
505 /* Flags argument for mmu_{map,unmap}_addr(), mmu_demap_{page,context,all}(),
506  * and mmu_{map,unmap}_perm_addr().
507  */
508 #define HV_MMU_DMMU                     0x01
509 #define HV_MMU_IMMU                     0x02
510 #define HV_MMU_ALL                      (HV_MMU_DMMU | HV_MMU_IMMU)
511
512 /* mmu_map_addr()
513  * TRAP:        HV_MMU_MAP_ADDR_TRAP
514  * ARG0:        virtual address
515  * ARG1:        mmu context
516  * ARG2:        TTE
517  * ARG3:        flags (HV_MMU_{IMMU,DMMU})
518  * ERRORS:      EINVAL          Invalid virtual address, mmu context, or flags
519  *              EBADPGSZ        Invalid page size value
520  *              ENORADDR        Invalid real address in TTE
521  *
522  * Create a non-permanent mapping using the given TTE, virtual
523  * address, and mmu context.  The flags argument determines which
524  * (data, or instruction, or both) TLB the mapping gets loaded into.
525  *
526  * The behavior is undefined if the valid bit is clear in the TTE.
527  *
528  * Note: This API call is for privileged code to specify temporary translation
529  *       mappings without the need to create and manage a TSB.
530  */
531
532 /* mmu_unmap_addr()
533  * TRAP:        HV_MMU_UNMAP_ADDR_TRAP
534  * ARG0:        virtual address
535  * ARG1:        mmu context
536  * ARG2:        flags (HV_MMU_{IMMU,DMMU})
537  * ERRORS:      EINVAL          Invalid virtual address, mmu context, or flags
538  *
539  * Demaps the given virtual address in the given mmu context on this
540  * CPU.  This function is intended to be used to demap pages mapped
541  * with mmu_map_addr.  This service is equivalent to invoking
542  * mmu_demap_page() with only the current CPU in the CPU list. The
543  * flags argument determines which (data, or instruction, or both) TLB
544  * the mapping gets unmapped from.
545  *
546  * Attempting to perform an unmap operation for a previously defined
547  * permanent mapping will have undefined results.
548  */
549
550 /* mmu_tsb_ctx0()
551  * TRAP:        HV_FAST_TRAP
552  * FUNCTION:    HV_FAST_MMU_TSB_CTX0
553  * ARG0:        number of TSB descriptions
554  * ARG1:        TSB descriptions pointer
555  * RET0:        status
556  * ERRORS:      ENORADDR                Invalid TSB descriptions pointer or
557  *                                      TSB base within a descriptor
558  *              EBADALIGN               TSB descriptions pointer is not aligned
559  *                                      to an 8-byte boundary, or TSB base
560  *                                      within a descriptor is not aligned for
561  *                                      the given TSB size
562  *              EBADPGSZ                Invalid page size in a TSB descriptor
563  *              EBADTSB                 Invalid associativity or size in a TSB
564  *                                      descriptor
565  *              EINVAL                  Invalid number of TSB descriptions, or
566  *                                      invalid context index in a TSB
567  *                                      descriptor, or index page size not
568  *                                      equal to smallest page size in page
569  *                                      size bitmask field.
570  *
571  * Configures the TSBs for the current CPU for virtual addresses with
572  * context zero.  The TSB descriptions pointer is a pointer to an
573  * array of the given number of TSB descriptions.
574  *
575  * Note: The maximum number of TSBs available to a virtual CPU is given by the
576  *       mmu-max-#tsbs property of the cpu's corresponding "cpu" node in the
577  *       machine description.
578  */
579 #define HV_FAST_MMU_TSB_CTX0            0x20
580
581 /* mmu_tsb_ctxnon0()
582  * TRAP:        HV_FAST_TRAP
583  * FUNCTION:    HV_FAST_MMU_TSB_CTXNON0
584  * ARG0:        number of TSB descriptions
585  * ARG1:        TSB descriptions pointer
586  * RET0:        status
587  * ERRORS:      Same as for mmu_tsb_ctx0() above.
588  *
589  * Configures the TSBs for the current CPU for virtual addresses with
590  * non-zero contexts.  The TSB descriptions pointer is a pointer to an
591  * array of the given number of TSB descriptions.
592  *
593  * Note: A maximum of 16 TSBs may be specified in the TSB description list.
594  */
595 #define HV_FAST_MMU_TSB_CTXNON0         0x21
596
597 /* mmu_demap_page()
598  * TRAP:        HV_FAST_TRAP
599  * FUNCTION:    HV_FAST_MMU_DEMAP_PAGE
600  * ARG0:        reserved, must be zero
601  * ARG1:        reserved, must be zero
602  * ARG2:        virtual address
603  * ARG3:        mmu context
604  * ARG4:        flags (HV_MMU_{IMMU,DMMU})
605  * RET0:        status
606  * ERRORS:      EINVAL                  Invalid virutal address, context, or
607  *                                      flags value
608  *              ENOTSUPPORTED           ARG0 or ARG1 is non-zero
609  *
610  * Demaps any page mapping of the given virtual address in the given
611  * mmu context for the current virtual CPU.  Any virtually tagged
612  * caches are guaranteed to be kept consistent.  The flags argument
613  * determines which TLB (instruction, or data, or both) participate in
614  * the operation.
615  *
616  * ARG0 and ARG1 are both reserved and must be set to zero.
617  */
618 #define HV_FAST_MMU_DEMAP_PAGE          0x22
619
620 /* mmu_demap_ctx()
621  * TRAP:        HV_FAST_TRAP
622  * FUNCTION:    HV_FAST_MMU_DEMAP_CTX
623  * ARG0:        reserved, must be zero
624  * ARG1:        reserved, must be zero
625  * ARG2:        mmu context
626  * ARG3:        flags (HV_MMU_{IMMU,DMMU})
627  * RET0:        status
628  * ERRORS:      EINVAL                  Invalid context or flags value
629  *              ENOTSUPPORTED           ARG0 or ARG1 is non-zero
630  *
631  * Demaps all non-permanent virtual page mappings previously specified
632  * for the given context for the current virtual CPU.  Any virtual
633  * tagged caches are guaranteed to be kept consistent.  The flags
634  * argument determines which TLB (instruction, or data, or both)
635  * participate in the operation.
636  *
637  * ARG0 and ARG1 are both reserved and must be set to zero.
638  */
639 #define HV_FAST_MMU_DEMAP_CTX           0x23
640
641 /* mmu_demap_all()
642  * TRAP:        HV_FAST_TRAP
643  * FUNCTION:    HV_FAST_MMU_DEMAP_ALL
644  * ARG0:        reserved, must be zero
645  * ARG1:        reserved, must be zero
646  * ARG2:        flags (HV_MMU_{IMMU,DMMU})
647  * RET0:        status
648  * ERRORS:      EINVAL                  Invalid flags value
649  *              ENOTSUPPORTED           ARG0 or ARG1 is non-zero
650  *
651  * Demaps all non-permanent virtual page mappings previously specified
652  * for the current virtual CPU.  Any virtual tagged caches are
653  * guaranteed to be kept consistent.  The flags argument determines
654  * which TLB (instruction, or data, or both) participate in the
655  * operation.
656  *
657  * ARG0 and ARG1 are both reserved and must be set to zero.
658  */
659 #define HV_FAST_MMU_DEMAP_ALL           0x24
660
661 /* mmu_map_perm_addr()
662  * TRAP:        HV_FAST_TRAP
663  * FUNCTION:    HV_FAST_MMU_MAP_PERM_ADDR
664  * ARG0:        virtual address
665  * ARG1:        reserved, must be zero
666  * ARG2:        TTE
667  * ARG3:        flags (HV_MMU_{IMMU,DMMU})
668  * RET0:        status
669  * ERRORS:      EINVAL                  Invalid virutal address or flags value
670  *              EBADPGSZ                Invalid page size value
671  *              ENORADDR                Invalid real address in TTE
672  *              ETOOMANY                Too many mappings (max of 8 reached)
673  *
674  * Create a permanent mapping using the given TTE and virtual address
675  * for context 0 on the calling virtual CPU.  A maximum of 8 such
676  * permanent mappings may be specified by privileged code.  Mappings
677  * may be removed with mmu_unmap_perm_addr().
678  *
679  * The behavior is undefined if a TTE with the valid bit clear is given.
680  *
681  * Note: This call is used to specify address space mappings for which
682  *       privileged code does not expect to receive misses.  For example,
683  *       this mechanism can be used to map kernel nucleus code and data.
684  */
685 #define HV_FAST_MMU_MAP_PERM_ADDR       0x25
686
687 /* mmu_fault_area_conf()
688  * TRAP:        HV_FAST_TRAP
689  * FUNCTION:    HV_FAST_MMU_FAULT_AREA_CONF
690  * ARG0:        real address
691  * RET0:        status
692  * RET1:        previous mmu fault area real address
693  * ERRORS:      ENORADDR                Invalid real address
694  *              EBADALIGN               Invalid alignment for fault area
695  *
696  * Configure the MMU fault status area for the calling CPU.  A 64-byte
697  * aligned real address specifies where MMU fault status information
698  * is placed.  The return value is the previously specified area, or 0
699  * for the first invocation.  Specifying a fault area at real address
700  * 0 is not allowed.
701  */
702 #define HV_FAST_MMU_FAULT_AREA_CONF     0x26
703
704 /* mmu_enable()
705  * TRAP:        HV_FAST_TRAP
706  * FUNCTION:    HV_FAST_MMU_ENABLE
707  * ARG0:        enable flag
708  * ARG1:        return target address
709  * RET0:        status
710  * ERRORS:      ENORADDR                Invalid real address when disabling
711  *                                      translation.
712  *              EBADALIGN               The return target address is not
713  *                                      aligned to an instruction.
714  *              EINVAL                  The enable flag request the current
715  *                                      operating mode (e.g. disable if already
716  *                                      disabled)
717  *
718  * Enable or disable virtual address translation for the calling CPU
719  * within the virtual machine domain.  If the enable flag is zero,
720  * translation is disabled, any non-zero value will enable
721  * translation.
722  *
723  * When this function returns, the newly selected translation mode
724  * will be active.  If the mmu is being enabled, then the return
725  * target address is a virtual address else it is a real address.
726  *
727  * Upon successful completion, control will be returned to the given
728  * return target address (ie. the cpu will jump to that address).  On
729  * failure, the previous mmu mode remains and the trap simply returns
730  * as normal with the appropriate error code in RET0.
731  */
732 #define HV_FAST_MMU_ENABLE              0x27
733
734 /* mmu_unmap_perm_addr()
735  * TRAP:        HV_FAST_TRAP
736  * FUNCTION:    HV_FAST_MMU_UNMAP_PERM_ADDR
737  * ARG0:        virtual address
738  * ARG1:        reserved, must be zero
739  * ARG2:        flags (HV_MMU_{IMMU,DMMU})
740  * RET0:        status
741  * ERRORS:      EINVAL                  Invalid virutal address or flags value
742  *              ENOMAP                  Specified mapping was not found
743  *
744  * Demaps any permanent page mapping (established via
745  * mmu_map_perm_addr()) at the given virtual address for context 0 on
746  * the current virtual CPU.  Any virtual tagged caches are guaranteed
747  * to be kept consistent.
748  */
749 #define HV_FAST_MMU_UNMAP_PERM_ADDR     0x28
750
751 /* mmu_tsb_ctx0_info()
752  * TRAP:        HV_FAST_TRAP
753  * FUNCTION:    HV_FAST_MMU_TSB_CTX0_INFO
754  * ARG0:        max TSBs
755  * ARG1:        buffer pointer
756  * RET0:        status
757  * RET1:        number of TSBs
758  * ERRORS:      EINVAL                  Supplied buffer is too small
759  *              EBADALIGN               The buffer pointer is badly aligned
760  *              ENORADDR                Invalid real address for buffer pointer
761  *
762  * Return the TSB configuration as previous defined by mmu_tsb_ctx0()
763  * into the provided buffer.  The size of the buffer is given in ARG1
764  * in terms of the number of TSB description entries.
765  *
766  * Upon return, RET1 always contains the number of TSB descriptions
767  * previously configured.  If zero TSBs were configured, EOK is
768  * returned with RET1 containing 0.
769  */
770 #define HV_FAST_MMU_TSB_CTX0_INFO       0x29
771
772 /* mmu_tsb_ctxnon0_info()
773  * TRAP:        HV_FAST_TRAP
774  * FUNCTION:    HV_FAST_MMU_TSB_CTXNON0_INFO
775  * ARG0:        max TSBs
776  * ARG1:        buffer pointer
777  * RET0:        status
778  * RET1:        number of TSBs
779  * ERRORS:      EINVAL                  Supplied buffer is too small
780  *              EBADALIGN               The buffer pointer is badly aligned
781  *              ENORADDR                Invalid real address for buffer pointer
782  *
783  * Return the TSB configuration as previous defined by
784  * mmu_tsb_ctxnon0() into the provided buffer.  The size of the buffer
785  * is given in ARG1 in terms of the number of TSB description entries.
786  *
787  * Upon return, RET1 always contains the number of TSB descriptions
788  * previously configured.  If zero TSBs were configured, EOK is
789  * returned with RET1 containing 0.
790  */
791 #define HV_FAST_MMU_TSB_CTXNON0_INFO    0x2a
792
793 /* mmu_fault_area_info()
794  * TRAP:        HV_FAST_TRAP
795  * FUNCTION:    HV_FAST_MMU_FAULT_AREA_INFO
796  * RET0:        status
797  * RET1:        fault area real address
798  * ERRORS:      No errors defined.
799  *
800  * Return the currently defined MMU fault status area for the current
801  * CPU.  The real address of the fault status area is returned in
802  * RET1, or 0 is returned in RET1 if no fault status area is defined.
803  *
804  * Note: mmu_fault_area_conf() may be called with the return value (RET1)
805  *       from this service if there is a need to save and restore the fault
806  *       area for a cpu.
807  */
808 #define HV_FAST_MMU_FAULT_AREA_INFO     0x2b
809
810 /* Cache and Memory services. */
811
812 /* mem_scrub()
813  * TRAP:        HV_FAST_TRAP
814  * FUNCTION:    HV_FAST_MEM_SCRUB
815  * ARG0:        real address
816  * ARG1:        length
817  * RET0:        status
818  * RET1:        length scrubbed
819  * ERRORS:      ENORADDR        Invalid real address
820  *              EBADALIGN       Start address or length are not correctly
821  *                              aligned
822  *              EINVAL          Length is zero
823  *
824  * Zero the memory contents in the range real address to real address
825  * plus length minus 1.  Also, valid ECC will be generated for that
826  * memory address range.  Scrubbing is started at the given real
827  * address, but may not scrub the entire given length.  The actual
828  * length scrubbed will be returned in RET1.
829  *
830  * The real address and length must be aligned on an 8K boundary, or
831  * contain the start address and length from a sun4v error report.
832  *
833  * Note: There are two uses for this function.  The first use is to block clear
834  *       and initialize memory and the second is to scrub an u ncorrectable
835  *       error reported via a resumable or non-resumable trap.  The second
836  *       use requires the arguments to be equal to the real address and length
837  *       provided in a sun4v memory error report.
838  */
839 #define HV_FAST_MEM_SCRUB               0x31
840
841 /* mem_sync()
842  * TRAP:        HV_FAST_TRAP
843  * FUNCTION:    HV_FAST_MEM_SYNC
844  * ARG0:        real address
845  * ARG1:        length
846  * RET0:        status
847  * RET1:        length synced
848  * ERRORS:      ENORADDR        Invalid real address
849  *              EBADALIGN       Start address or length are not correctly
850  *                              aligned
851  *              EINVAL          Length is zero
852  *
853  * Force the next access within the real address to real address plus
854  * length minus 1 to be fetches from main system memory.  Less than
855  * the given length may be synced, the actual amount synced is
856  * returned in RET1.  The real address and length must be aligned on
857  * an 8K boundary.
858  */
859 #define HV_FAST_MEM_SYNC                0x32
860
861 /* Time of day services.
862  *
863  * The hypervisor maintains the time of day on a per-domain basis.
864  * Changing the time of day in one domain does not affect the time of
865  * day on any other domain.
866  *
867  * Time is described by a single unsigned 64-bit word which is the
868  * number of seconds since the UNIX Epoch (00:00:00 UTC, January 1,
869  * 1970).
870  */
871
872 /* tod_get()
873  * TRAP:        HV_FAST_TRAP
874  * FUNCTION:    HV_FAST_TOD_GET
875  * RET0:        status
876  * RET1:        TOD
877  * ERRORS:      EWOULDBLOCK     TOD resource is temporarily unavailable
878  *              ENOTSUPPORTED   If TOD not supported on this platform
879  *
880  * Return the current time of day.  May block if TOD access is
881  * temporarily not possible.
882  */
883 #define HV_FAST_TOD_GET                 0x50
884
885 /* tod_set()
886  * TRAP:        HV_FAST_TRAP
887  * FUNCTION:    HV_FAST_TOD_SET
888  * ARG0:        TOD
889  * RET0:        status
890  * ERRORS:      EWOULDBLOCK     TOD resource is temporarily unavailable
891  *              ENOTSUPPORTED   If TOD not supported on this platform
892  *
893  * The current time of day is set to the value specified in ARG0.  May
894  * block if TOD access is temporarily not possible.
895  */
896 #define HV_FAST_TOD_SET                 0x51
897
898 /* Console services */
899
900 /* con_getchar()
901  * TRAP:        HV_FAST_TRAP
902  * FUNCTION:    HV_FAST_CONS_GETCHAR
903  * RET0:        status
904  * RET1:        character
905  * ERRORS:      EWOULDBLOCK     No character available.
906  *
907  * Returns a character from the console device.  If no character is
908  * available then an EWOULDBLOCK error is returned.  If a character is
909  * available, then the returned status is EOK and the character value
910  * is in RET1.
911  *
912  * A virtual BREAK is represented by the 64-bit value -1.
913  *
914  * A virtual HUP signal is represented by the 64-bit value -2.
915  */
916 #define HV_FAST_CONS_GETCHAR            0x60
917
918 /* con_putchar()
919  * TRAP:        HV_FAST_TRAP
920  * FUNCTION:    HV_FAST_CONS_PUTCHAR
921  * ARG0:        character
922  * RET0:        status
923  * ERRORS:      EINVAL          Illegal character
924  *              EWOULDBLOCK     Output buffer currently full, would block
925  *
926  * Send a character to the console device.  Only character values
927  * between 0 and 255 may be used.  Values outside this range are
928  * invalid except for the 64-bit value -1 which is used to send a
929  * virtual BREAK.
930  */
931 #define HV_FAST_CONS_PUTCHAR            0x61
932
933 /* Trap trace services.
934  *
935  * The hypervisor provides a trap tracing capability for privileged
936  * code running on each virtual CPU.  Privileged code provides a
937  * round-robin trap trace queue within which the hypervisor writes
938  * 64-byte entries detailing hyperprivileged traps taken n behalf of
939  * privileged code.  This is provided as a debugging capability for
940  * privileged code.
941  *
942  * The trap trace control structure is 64-bytes long and placed at the
943  * start (offset 0) of the trap trace buffer, and is described as
944  * follows:
945  */
946 #ifndef __ASSEMBLY__
947 struct hv_trap_trace_control {
948         unsigned long           head_offset;
949         unsigned long           tail_offset;
950         unsigned long           __reserved[0x30 / sizeof(unsigned long)];
951 };
952 #endif
953 #define HV_TRAP_TRACE_CTRL_HEAD_OFFSET  0x00
954 #define HV_TRAP_TRACE_CTRL_TAIL_OFFSET  0x08
955
956 /* The head offset is the offset of the most recently completed entry
957  * in the trap-trace buffer.  The tail offset is the offset of the
958  * next entry to be written.  The control structure is owned and
959  * modified by the hypervisor.  A guest may not modify the control
960  * structure contents.  Attempts to do so will result in undefined
961  * behavior for the guest.
962  *
963  * Each trap trace buffer entry is layed out as follows:
964  */
965 #ifndef __ASSEMBLY__
966 struct hv_trap_trace_entry {
967         unsigned char   type;           /* Hypervisor or guest entry?   */
968         unsigned char   hpstate;        /* Hyper-privileged state       */
969         unsigned char   tl;             /* Trap level                   */
970         unsigned char   gl;             /* Global register level        */
971         unsigned short  tt;             /* Trap type                    */
972         unsigned short  tag;            /* Extended trap identifier     */
973         unsigned long   tstate;         /* Trap state                   */
974         unsigned long   tick;           /* Tick                         */
975         unsigned long   tpc;            /* Trap PC                      */
976         unsigned long   f1;             /* Entry specific               */
977         unsigned long   f2;             /* Entry specific               */
978         unsigned long   f3;             /* Entry specific               */
979         unsigned long   f4;             /* Entry specific               */
980 };
981 #endif
982 #define HV_TRAP_TRACE_ENTRY_TYPE        0x00
983 #define HV_TRAP_TRACE_ENTRY_HPSTATE     0x01
984 #define HV_TRAP_TRACE_ENTRY_TL          0x02
985 #define HV_TRAP_TRACE_ENTRY_GL          0x03
986 #define HV_TRAP_TRACE_ENTRY_TT          0x04
987 #define HV_TRAP_TRACE_ENTRY_TAG         0x06
988 #define HV_TRAP_TRACE_ENTRY_TSTATE      0x08
989 #define HV_TRAP_TRACE_ENTRY_TICK        0x10
990 #define HV_TRAP_TRACE_ENTRY_TPC         0x18
991 #define HV_TRAP_TRACE_ENTRY_F1          0x20
992 #define HV_TRAP_TRACE_ENTRY_F2          0x28
993 #define HV_TRAP_TRACE_ENTRY_F3          0x30
994 #define HV_TRAP_TRACE_ENTRY_F4          0x38
995
996 /* The type field is encoded as follows.  */
997 #define HV_TRAP_TYPE_UNDEF              0x00 /* Entry content undefined     */
998 #define HV_TRAP_TYPE_HV                 0x01 /* Hypervisor trap entry       */
999 #define HV_TRAP_TYPE_GUEST              0xff /* Added via ttrace_addentry() */
1000
1001 /* ttrace_buf_conf()
1002  * TRAP:        HV_FAST_TRAP
1003  * FUNCTION:    HV_FAST_TTRACE_BUF_CONF
1004  * ARG0:        real address
1005  * ARG1:        number of entries
1006  * RET0:        status
1007  * RET1:        number of entries
1008  * ERRORS:      ENORADDR        Invalid real address
1009  *              EINVAL          Size is too small
1010  *              EBADALIGN       Real address not aligned on 64-byte boundary
1011  *
1012  * Requests hypervisor trap tracing and declares a virtual CPU's trap
1013  * trace buffer to the hypervisor.  The real address supplies the real
1014  * base address of the trap trace queue and must be 64-byte aligned.
1015  * Specifying a value of 0 for the number of entries disables trap
1016  * tracing for the calling virtual CPU.  The buffer allocated must be
1017  * sized for a power of two number of 64-byte trap trace entries plus
1018  * an initial 64-byte control structure.
1019  * 
1020  * This may be invoked any number of times so that a virtual CPU may
1021  * relocate a trap trace buffer or create "snapshots" of information.
1022  *
1023  * If the real address is illegal or badly aligned, then trap tracing
1024  * is disabled and an error is returned.
1025  *
1026  * Upon failure with EINVAL, this service call returns in RET1 the
1027  * minimum number of buffer entries required.  Upon other failures
1028  * RET1 is undefined.
1029  */
1030 #define HV_FAST_TTRACE_BUF_CONF         0x90
1031
1032 /* ttrace_buf_info()
1033  * TRAP:        HV_FAST_TRAP
1034  * FUNCTION:    HV_FAST_TTRACE_BUF_INFO
1035  * RET0:        status
1036  * RET1:        real address
1037  * RET2:        size
1038  * ERRORS:      None defined.
1039  *
1040  * Returns the size and location of the previously declared trap-trace
1041  * buffer.  In the event that no buffer was previously defined, or the
1042  * buffer is disabled, this call will return a size of zero bytes.
1043  */
1044 #define HV_FAST_TTRACE_BUF_INFO         0x91
1045
1046 /* ttrace_enable()
1047  * TRAP:        HV_FAST_TRAP
1048  * FUNCTION:    HV_FAST_TTRACE_ENABLE
1049  * ARG0:        enable
1050  * RET0:        status
1051  * RET1:        previous enable state
1052  * ERRORS:      EINVAL          No trap trace buffer currently defined
1053  *
1054  * Enable or disable trap tracing, and return the previous enabled
1055  * state in RET1.  Future systems may define various flags for the
1056  * enable argument (ARG0), for the moment a guest should pass
1057  * "(uint64_t) -1" to enable, and "(uint64_t) 0" to disable all
1058  * tracing - which will ensure future compatability.
1059  */
1060 #define HV_FAST_TTRACE_ENABLE           0x92
1061
1062 /* ttrace_freeze()
1063  * TRAP:        HV_FAST_TRAP
1064  * FUNCTION:    HV_FAST_TTRACE_FREEZE
1065  * ARG0:        freeze
1066  * RET0:        status
1067  * RET1:        previous freeze state
1068  * ERRORS:      EINVAL          No trap trace buffer currently defined
1069  *
1070  * Freeze or unfreeze trap tracing, returning the previous freeze
1071  * state in RET1.  A guest should pass a non-zero value to freeze and
1072  * a zero value to unfreeze all tracing.  The returned previous state
1073  * is 0 for not frozen and 1 for frozen.
1074  */
1075 #define HV_FAST_TTRACE_FREEZE           0x93
1076
1077 /* ttrace_addentry()
1078  * TRAP:        HV_TTRACE_ADDENTRY_TRAP
1079  * ARG0:        tag (16-bits)
1080  * ARG1:        data word 0
1081  * ARG2:        data word 1
1082  * ARG3:        data word 2
1083  * ARG4:        data word 3
1084  * RET0:        status
1085  * ERRORS:      EINVAL          No trap trace buffer currently defined
1086  *
1087  * Add an entry to the trap trace buffer.  Upon return only ARG0/RET0
1088  * is modified - none of the other registers holding arguments are
1089  * volatile across this hypervisor service.
1090  */
1091
1092 /* Core dump services.
1093  *
1094  * Since the hypervisor viraulizes and thus obscures a lot of the
1095  * physical machine layout and state, traditional OS crash dumps can
1096  * be difficult to diagnose especially when the problem is a
1097  * configuration error of some sort.
1098  *
1099  * The dump services provide an opaque buffer into which the
1100  * hypervisor can place it's internal state in order to assist in
1101  * debugging such situations.  The contents are opaque and extremely
1102  * platform and hypervisor implementation specific.  The guest, during
1103  * a core dump, requests that the hypervisor update any information in
1104  * the dump buffer in preparation to being dumped as part of the
1105  * domain's memory image.
1106  */
1107
1108 /* dump_buf_update()
1109  * TRAP:        HV_FAST_TRAP
1110  * FUNCTION:    HV_FAST_DUMP_BUF_UPDATE
1111  * ARG0:        real address
1112  * ARG1:        size
1113  * RET0:        status
1114  * RET1:        required size of dump buffer
1115  * ERRORS:      ENORADDR        Invalid real address
1116  *              EBADALIGN       Real address is not aligned on a 64-byte
1117  *                              boundary
1118  *              EINVAL          Size is non-zero but less than minimum size
1119  *                              required
1120  *              ENOTSUPPORTED   Operation not supported on current logical
1121  *                              domain
1122  *
1123  * Declare a domain dump buffer to the hypervisor.  The real address
1124  * provided for the domain dump buffer must be 64-byte aligned.  The
1125  * size specifies the size of the dump buffer and may be larger than
1126  * the minimum size specified in the machine description.  The
1127  * hypervisor will fill the dump buffer with opaque data.
1128  *
1129  * Note: A guest may elect to include dump buffer contents as part of a crash
1130  *       dump to assist with debugging.  This function may be called any number
1131  *       of times so that a guest may relocate a dump buffer, or create
1132  *       "snapshots" of any dump-buffer information.  Each call to
1133  *       dump_buf_update() atomically declares the new dump buffer to the
1134  *       hypervisor.
1135  *
1136  * A specified size of 0 unconfigures the dump buffer.  If the real
1137  * address is illegal or badly aligned, then any currently active dump
1138  * buffer is disabled and an error is returned.
1139  *
1140  * In the event that the call fails with EINVAL, RET1 contains the
1141  * minimum size requires by the hypervisor for a valid dump buffer.
1142  */
1143 #define HV_FAST_DUMP_BUF_UPDATE         0x94
1144
1145 /* dump_buf_info()
1146  * TRAP:        HV_FAST_TRAP
1147  * FUNCTION:    HV_FAST_DUMP_BUF_INFO
1148  * RET0:        status
1149  * RET1:        real address of current dump buffer
1150  * RET2:        size of current dump buffer
1151  * ERRORS:      No errors defined.
1152  *
1153  * Return the currently configures dump buffer description.  A
1154  * returned size of 0 bytes indicates an undefined dump buffer.  In
1155  * this case the return address in RET1 is undefined.
1156  */
1157 #define HV_FAST_DUMP_BUF_INFO           0x95
1158
1159 /* Device interrupt services.
1160  *
1161  * Device interrupts are allocated to system bus bridges by the hypervisor,
1162  * and described to OBP in the machine description.  OBP then describes
1163  * these interrupts to the OS via properties in the device tree.
1164  *
1165  * Terminology:
1166  *
1167  *      cpuid           Unique opaque value which represents a target cpu.
1168  *
1169  *      devhandle       Device handle.  It uniquely identifies a device, and
1170  *                      consistes of the lower 28-bits of the hi-cell of the
1171  *                      first entry of the device's "reg" property in the
1172  *                      OBP device tree.
1173  *
1174  *      devino          Device interrupt number.  Specifies the relative
1175  *                      interrupt number within the device.  The unique
1176  *                      combination of devhandle and devino are used to
1177  *                      identify a specific device interrupt.
1178  *
1179  *                      Note: The devino value is the same as the values in the
1180  *                            "interrupts" property or "interrupt-map" property
1181  *                            in the OBP device tree for that device.
1182  *
1183  *      sysino          System interrupt number.  A 64-bit unsigned interger
1184  *                      representing a unique interrupt within a virtual
1185  *                      machine.
1186  *
1187  *      intr_state      A flag representing the interrupt state for a given
1188  *                      sysino.  The state values are defined below.
1189  *
1190  *      intr_enabled    A flag representing the 'enabled' state for a given
1191  *                      sysino.  The enable values are defined below.
1192  */
1193
1194 #define HV_INTR_STATE_IDLE              0 /* Nothing pending */
1195 #define HV_INTR_STATE_RECEIVED          1 /* Interrupt received by hardware */
1196 #define HV_INTR_STATE_DELIVERED         2 /* Interrupt delivered to queue */
1197
1198 #define HV_INTR_DISABLED                0 /* sysino not enabled */
1199 #define HV_INTR_ENABLED                 1 /* sysino enabled */
1200
1201 /* intr_devino_to_sysino()
1202  * TRAP:        HV_FAST_TRAP
1203  * FUNCTION:    HV_FAST_INTR_DEVINO2SYSINO
1204  * ARG0:        devhandle
1205  * ARG1:        devino
1206  * RET0:        status
1207  * RET1:        sysino
1208  * ERRORS:      EINVAL          Invalid devhandle/devino
1209  *
1210  * Converts a device specific interrupt number of the given
1211  * devhandle/devino into a system specific ino (sysino).
1212  */
1213 #define HV_FAST_INTR_DEVINO2SYSINO      0xa0
1214
1215 #ifndef __ASSEMBLY__
1216 extern unsigned long sun4v_devino_to_sysino(unsigned long devhandle,
1217                                             unsigned long devino);
1218 #endif
1219
1220 /* intr_getenabled()
1221  * TRAP:        HV_FAST_TRAP
1222  * FUNCTION:    HV_FAST_INTR_GETENABLED
1223  * ARG0:        sysino
1224  * RET0:        status
1225  * RET1:        intr_enabled (HV_INTR_{DISABLED,ENABLED})
1226  * ERRORS:      EINVAL          Invalid sysino
1227  *
1228  * Returns interrupt enabled state in RET1 for the interrupt defined
1229  * by the given sysino.
1230  */
1231 #define HV_FAST_INTR_GETENABLED         0xa1
1232
1233 #ifndef __ASSEMBLY__
1234 extern unsigned long sun4v_intr_getenabled(unsigned long sysino);
1235 #endif
1236
1237 /* intr_setenabled()
1238  * TRAP:        HV_FAST_TRAP
1239  * FUNCTION:    HV_FAST_INTR_SETENABLED
1240  * ARG0:        sysino
1241  * ARG1:        intr_enabled (HV_INTR_{DISABLED,ENABLED})
1242  * RET0:        status
1243  * ERRORS:      EINVAL          Invalid sysino or intr_enabled value
1244  *
1245  * Set the 'enabled' state of the interrupt sysino.
1246  */
1247 #define HV_FAST_INTR_SETENABLED         0xa2
1248
1249 #ifndef __ASSEMBLY__
1250 extern unsigned long sun4v_intr_setenabled(unsigned long sysino, unsigned long intr_enabled);
1251 #endif
1252
1253 /* intr_getstate()
1254  * TRAP:        HV_FAST_TRAP
1255  * FUNCTION:    HV_FAST_INTR_GETSTATE
1256  * ARG0:        sysino
1257  * RET0:        status
1258  * RET1:        intr_state (HV_INTR_STATE_*)
1259  * ERRORS:      EINVAL          Invalid sysino
1260  *
1261  * Returns current state of the interrupt defined by the given sysino.
1262  */
1263 #define HV_FAST_INTR_GETSTATE           0xa3
1264
1265 #ifndef __ASSEMBLY__
1266 extern unsigned long sun4v_intr_getstate(unsigned long sysino);
1267 #endif
1268
1269 /* intr_setstate()
1270  * TRAP:        HV_FAST_TRAP
1271  * FUNCTION:    HV_FAST_INTR_SETSTATE
1272  * ARG0:        sysino
1273  * ARG1:        intr_state (HV_INTR_STATE_*)
1274  * RET0:        status
1275  * ERRORS:      EINVAL          Invalid sysino or intr_state value
1276  *
1277  * Sets the current state of the interrupt described by the given sysino
1278  * value.
1279  *
1280  * Note: Setting the state to HV_INTR_STATE_IDLE clears any pending
1281  *       interrupt for sysino.
1282  */
1283 #define HV_FAST_INTR_SETSTATE           0xa4
1284
1285 #ifndef __ASSEMBLY__
1286 extern unsigned long sun4v_intr_setstate(unsigned long sysino, unsigned long intr_state);
1287 #endif
1288
1289 /* intr_gettarget()
1290  * TRAP:        HV_FAST_TRAP
1291  * FUNCTION:    HV_FAST_INTR_GETTARGET
1292  * ARG0:        sysino
1293  * RET0:        status
1294  * RET1:        cpuid
1295  * ERRORS:      EINVAL          Invalid sysino
1296  *
1297  * Returns CPU that is the current target of the interrupt defined by
1298  * the given sysino.  The CPU value returned is undefined if the target
1299  * has not been set via intr_settarget().
1300  */
1301 #define HV_FAST_INTR_GETTARGET          0xa5
1302
1303 #ifndef __ASSEMBLY__
1304 extern unsigned long sun4v_intr_gettarget(unsigned long sysino);
1305 #endif
1306
1307 /* intr_settarget()
1308  * TRAP:        HV_FAST_TRAP
1309  * FUNCTION:    HV_FAST_INTR_SETTARGET
1310  * ARG0:        sysino
1311  * ARG1:        cpuid
1312  * RET0:        status
1313  * ERRORS:      EINVAL          Invalid sysino
1314  *              ENOCPU          Invalid cpuid
1315  *
1316  * Set the target CPU for the interrupt defined by the given sysino.
1317  */
1318 #define HV_FAST_INTR_SETTARGET          0xa6
1319
1320 #ifndef __ASSEMBLY__
1321 extern unsigned long sun4v_intr_settarget(unsigned long sysino, unsigned long cpuid);
1322 #endif
1323
1324 /* PCI IO services.
1325  *
1326  * See the terminology descriptions in the device interrupt services
1327  * section above as those apply here too.  Here are terminology
1328  * definitions specific to these PCI IO services:
1329  *
1330  *      tsbnum          TSB number.  Indentifies which io-tsb is used.
1331  *                      For this version of the specification, tsbnum
1332  *                      must be zero.
1333  *
1334  *      tsbindex        TSB index.  Identifies which entry in the TSB
1335  *                      is used.  The first entry is zero.
1336  *
1337  *      tsbid           A 64-bit aligned data structure which contains
1338  *                      a tsbnum and a tsbindex.  Bits 63:32 contain the
1339  *                      tsbnum and bits 31:00 contain the tsbindex.
1340  *
1341  *                      Use the HV_PCI_TSBID() macro to construct such
1342  *                      values.
1343  *
1344  *      io_attributes   IO attributes for IOMMU mappings.  One of more
1345  *                      of the attritbute bits are stores in a 64-bit
1346  *                      value.  The values are defined below.
1347  *
1348  *      r_addr          64-bit real address
1349  *
1350  *      pci_device      PCI device address.  A PCI device address identifies
1351  *                      a specific device on a specific PCI bus segment.
1352  *                      A PCI device address ia a 32-bit unsigned integer
1353  *                      with the following format:
1354  *
1355  *                              00000000.bbbbbbbb.dddddfff.00000000
1356  *
1357  *                      Use the HV_PCI_DEVICE_BUILD() macro to construct
1358  *                      such values.
1359  *
1360  *      pci_config_offset
1361  *                      PCI configureation space offset.  For conventional
1362  *                      PCI a value between 0 and 255.  For extended
1363  *                      configuration space, a value between 0 and 4095.
1364  *
1365  *                      Note: For PCI configuration space accesses, the offset
1366  *                            must be aligned to the access size.
1367  *
1368  *      error_flag      A return value which specifies if the action succeeded
1369  *                      or failed.  0 means no error, non-0 means some error
1370  *                      occurred while performing the service.
1371  *
1372  *      io_sync_direction
1373  *                      Direction definition for pci_dma_sync(), defined
1374  *                      below in HV_PCI_SYNC_*.
1375  *
1376  *      io_page_list    A list of io_page_addresses, an io_page_address is
1377  *                      a real address.
1378  *
1379  *      io_page_list_p  A pointer to an io_page_list.
1380  *
1381  *      "size based byte swap" - Some functions do size based byte swapping
1382  *                               which allows sw to access pointers and
1383  *                               counters in native form when the processor
1384  *                               operates in a different endianness than the
1385  *                               IO bus.  Size-based byte swapping converts a
1386  *                               multi-byte field between big-endian and
1387  *                               little-endian format.
1388  */
1389
1390 #define HV_PCI_MAP_ATTR_READ            0x01
1391 #define HV_PCI_MAP_ATTR_WRITE           0x02
1392
1393 #define HV_PCI_DEVICE_BUILD(b,d,f)      \
1394         ((((b) & 0xff) << 16) | \
1395          (((d) & 0x1f) << 11) | \
1396          (((f) & 0x07) <<  8))
1397
1398 #define HV_PCI_TSBID(__tsb_num, __tsb_index) \
1399         ((((u64)(__tsb_num)) << 32UL) | ((u64)(__tsb_index)))
1400
1401 #define HV_PCI_SYNC_FOR_DEVICE          0x01
1402 #define HV_PCI_SYNC_FOR_CPU             0x02
1403
1404 /* pci_iommu_map()
1405  * TRAP:        HV_FAST_TRAP
1406  * FUNCTION:    HV_FAST_PCI_IOMMU_MAP
1407  * ARG0:        devhandle
1408  * ARG1:        tsbid
1409  * ARG2:        #ttes
1410  * ARG3:        io_attributes
1411  * ARG4:        io_page_list_p
1412  * RET0:        status
1413  * RET1:        #ttes mapped
1414  * ERRORS:      EINVAL          Invalid devhandle/tsbnum/tsbindex/io_attributes
1415  *              EBADALIGN       Improperly aligned real address
1416  *              ENORADDR        Invalid real address
1417  *
1418  * Create IOMMU mappings in the sun4v device defined by the given
1419  * devhandle.  The mappings are created in the TSB defined by the
1420  * tsbnum component of the given tsbid.  The first mapping is created
1421  * in the TSB i ndex defined by the tsbindex component of the given tsbid.
1422  * The call creates up to #ttes mappings, the first one at tsbnum, tsbindex,
1423  * the second at tsbnum, tsbindex + 1, etc.
1424  *
1425  * All mappings are created with the attributes defined by the io_attributes
1426  * argument.  The page mapping addresses are described in the io_page_list
1427  * defined by the given io_page_list_p, which is a pointer to the io_page_list.
1428  * The first entry in the io_page_list is the address for the first iotte, the
1429  * 2nd for the 2nd iotte, and so on.
1430  *
1431  * Each io_page_address in the io_page_list must be appropriately aligned.
1432  * #ttes must be greater than zero.  For this version of the spec, the tsbnum
1433  * component of the given tsbid must be zero.
1434  *
1435  * Returns the actual number of mappings creates, which may be less than
1436  * or equal to the argument #ttes.  If the function returns a value which
1437  * is less than the #ttes, the caller may continus to call the function with
1438  * an updated tsbid, #ttes, io_page_list_p arguments until all pages are
1439  * mapped.
1440  *
1441  * Note: This function does not imply an iotte cache flush.  The guest must
1442  *       demap an entry before re-mapping it.
1443  */
1444 #define HV_FAST_PCI_IOMMU_MAP           0xb0
1445
1446 /* pci_iommu_demap()
1447  * TRAP:        HV_FAST_TRAP
1448  * FUNCTION:    HV_FAST_PCI_IOMMU_DEMAP
1449  * ARG0:        devhandle
1450  * ARG1:        tsbid
1451  * ARG2:        #ttes
1452  * RET0:        status
1453  * RET1:        #ttes demapped
1454  * ERRORS:      EINVAL          Invalid devhandle/tsbnum/tsbindex
1455  *
1456  * Demap and flush IOMMU mappings in the device defined by the given
1457  * devhandle.  Demaps up to #ttes entries in the TSB defined by the tsbnum
1458  * component of the given tsbid, starting at the TSB index defined by the
1459  * tsbindex component of the given tsbid.
1460  *
1461  * For this version of the spec, the tsbnum of the given tsbid must be zero.
1462  * #ttes must be greater than zero.
1463  *
1464  * Returns the actual number of ttes demapped, which may be less than or equal
1465  * to the argument #ttes.  If #ttes demapped is less than #ttes, the caller
1466  * may continue to call this function with updated tsbid and #ttes arguments
1467  * until all pages are demapped.
1468  *
1469  * Note: Entries do not have to be mapped to be demapped.  A demap of an
1470  *       unmapped page will flush the entry from the tte cache.
1471  */
1472 #define HV_FAST_PCI_IOMMU_DEMAP         0xb1
1473
1474 /* pci_iommu_getmap()
1475  * TRAP:        HV_FAST_TRAP
1476  * FUNCTION:    HV_FAST_PCI_IOMMU_GETMAP
1477  * ARG0:        devhandle
1478  * ARG1:        tsbid
1479  * RET0:        status
1480  * RET1:        io_attributes
1481  * RET2:        real address
1482  * ERRORS:      EINVAL          Invalid devhandle/tsbnum/tsbindex
1483  *              ENOMAP          Mapping is not valid, no translation exists
1484  *
1485  * Read and return the mapping in the device described by the given devhandle
1486  * and tsbid.  If successful, the io_attributes shall be returned in RET1
1487  * and the page address of the mapping shall be returned in RET2.
1488  *
1489  * For this version of the spec, the tsbnum component of the given tsbid
1490  * must be zero.
1491  */
1492 #define HV_FAST_PCI_IOMMU_GETMAP        0xb2
1493
1494 /* pci_iommu_getbypass()
1495  * TRAP:        HV_FAST_TRAP
1496  * FUNCTION:    HV_FAST_PCI_IOMMU_GETBYPASS
1497  * ARG0:        devhandle
1498  * ARG1:        real address
1499  * ARG2:        io_attributes
1500  * RET0:        status
1501  * RET1:        io_addr
1502  * ERRORS:      EINVAL          Invalid devhandle/io_attributes
1503  *              ENORADDR        Invalid real address
1504  *              ENOTSUPPORTED   Function not supported in this implementation.
1505  *
1506  * Create a "special" mapping in the device described by the given devhandle,
1507  * for the given real address and attributes.  Return the IO address in RET1
1508  * if successful.
1509  */
1510 #define HV_FAST_PCI_IOMMU_GETBYPASS     0xb3
1511
1512 /* pci_config_get()
1513  * TRAP:        HV_FAST_TRAP
1514  * FUNCTION:    HV_FAST_PCI_CONFIG_GET
1515  * ARG0:        devhandle
1516  * ARG1:        pci_device
1517  * ARG2:        pci_config_offset
1518  * ARG3:        size
1519  * RET0:        status
1520  * RET1:        error_flag
1521  * RET2:        data
1522  * ERRORS:      EINVAL          Invalid devhandle/pci_device/offset/size
1523  *              EBADALIGN       pci_config_offset not size aligned
1524  *              ENOACCESS       Access to this offset is not permitted
1525  *
1526  * Read PCI configuration space for the adapter described by the given
1527  * devhandle.  Read size (1, 2, or 4) bytes of data from the given
1528  * pci_device, at pci_config_offset from the beginning of the device's
1529  * configuration space.  If there was no error, RET1 is set to zero and
1530  * RET2 is set to the data read.  Insignificant bits in RET2 are not
1531  * guarenteed to have any specific value and therefore must be ignored.
1532  *
1533  * The data returned in RET2 is size based byte swapped.
1534  *
1535  * If an error occurs during the read, set RET1 to a non-zero value.  The
1536  * given pci_config_offset must be 'size' aligned.
1537  */
1538 #define HV_FAST_PCI_CONFIG_GET          0xb4
1539
1540 /* pci_config_put()
1541  * TRAP:        HV_FAST_TRAP
1542  * FUNCTION:    HV_FAST_PCI_CONFIG_PUT
1543  * ARG0:        devhandle
1544  * ARG1:        pci_device
1545  * ARG2:        pci_config_offset
1546  * ARG3:        size
1547  * ARG4:        data
1548  * RET0:        status
1549  * RET1:        error_flag
1550  * ERRORS:      EINVAL          Invalid devhandle/pci_device/offset/size
1551  *              EBADALIGN       pci_config_offset not size aligned
1552  *              ENOACCESS       Access to this offset is not permitted
1553  *
1554  * Write PCI configuration space for the adapter described by the given
1555  * devhandle.  Write size (1, 2, or 4) bytes of data in a single operation,
1556  * at pci_config_offset from the beginning of the device's configuration
1557  * space.  The data argument contains the data to be written to configuration
1558  * space.  Prior to writing, the data is size based byte swapped.
1559  *
1560  * If an error occurs during the write access, do not generate an error
1561  * report, do set RET1 to a non-zero value.  Otherwise RET1 is zero.
1562  * The given pci_config_offset must be 'size' aligned.
1563  *
1564  * This function is permitted to read from offset zero in the configuration
1565  * space described by the given pci_device if necessary to ensure that the
1566  * write access to config space completes.
1567  */
1568 #define HV_FAST_PCI_CONFIG_PUT          0xb5
1569
1570 /* pci_peek()
1571  * TRAP:        HV_FAST_TRAP
1572  * FUNCTION:    HV_FAST_PCI_PEEK
1573  * ARG0:        devhandle
1574  * ARG1:        real address
1575  * ARG2:        size
1576  * RET0:        status
1577  * RET1:        error_flag
1578  * RET2:        data
1579  * ERRORS:      EINVAL          Invalid devhandle or size
1580  *              EBADALIGN       Improperly aligned real address
1581  *              ENORADDR        Bad real address
1582  *              ENOACCESS       Guest access prohibited
1583  *
1584  * Attempt to read the IO address given by the given devhandle, real address,
1585  * and size.  Size must be 1, 2, 4, or 8.  The read is performed as a single
1586  * access operation using the given size.  If an error occurs when reading
1587  * from the given location, do not generate an error report, but return a
1588  * non-zero value in RET1.  If the read was successful, return zero in RET1
1589  * and return the actual data read in RET2.  The data returned is size based
1590  * byte swapped.
1591  *
1592  * Non-significant bits in RET2 are not guarenteed to have any specific value
1593  * and therefore must be ignored.  If RET1 is returned as non-zero, the data 
1594  * value is not guarenteed to have any specific value and should be ignored.
1595  *
1596  * The caller must have permission to read from the given devhandle, real
1597  * address, which must be an IO address.  The argument real address must be a
1598  * size aligned address.
1599  *
1600  * The hypervisor implementation of this function must block access to any
1601  * IO address that the guest does not have explicit permission to access.
1602  */
1603 #define HV_FAST_PCI_PEEK                0xb6
1604
1605 /* pci_poke()
1606  * TRAP:        HV_FAST_TRAP
1607  * FUNCTION:    HV_FAST_PCI_POKE
1608  * ARG0:        devhandle
1609  * ARG1:        real address
1610  * ARG2:        size
1611  * ARG3:        data
1612  * ARG4:        pci_device
1613  * RET0:        status
1614  * RET1:        error_flag
1615  * ERRORS:      EINVAL          Invalid devhandle, size, or pci_device
1616  *              EBADALIGN       Improperly aligned real address
1617  *              ENORADDR        Bad real address
1618  *              ENOACCESS       Guest access prohibited
1619  *              ENOTSUPPORTED   Function is not supported by implementation
1620  *
1621  * Attempt to write data to the IO address given by the given devhandle,
1622  * real address, and size.  Size must be 1, 2, 4, or 8.  The write is
1623  * performed as a single access operation using the given size. Prior to
1624  * writing the data is size based swapped.
1625  *
1626  * If an error occurs when writing to the given location, do not generate an
1627  * error report, but return a non-zero value in RET1.  If the write was
1628  * successful, return zero in RET1.
1629  *
1630  * pci_device describes the configuration address of the device being
1631  * written to.  The implementation may safely read from offset 0 with
1632  * the configuration space of the device described by devhandle and
1633  * pci_device in order to guarantee that the write portion of the operation
1634  * completes
1635  *
1636  * Any error that occurs due to the read shall be reported using the normal
1637  * error reporting mechanisms .. the read error is not suppressed.
1638  *
1639  * The caller must have permission to write to the given devhandle, real
1640  * address, which must be an IO address.  The argument real address must be a
1641  * size aligned address.  The caller must have permission to read from
1642  * the given devhandle, pci_device cofiguration space offset 0.
1643  *
1644  * The hypervisor implementation of this function must block access to any
1645  * IO address that the guest does not have explicit permission to access.
1646  */
1647 #define HV_FAST_PCI_POKE                0xb7
1648
1649 /* pci_dma_sync()
1650  * TRAP:        HV_FAST_TRAP
1651  * FUNCTION:    HV_FAST_PCI_DMA_SYNC
1652  * ARG0:        devhandle
1653  * ARG1:        real address
1654  * ARG2:        size
1655  * ARG3:        io_sync_direction
1656  * RET0:        status
1657  * RET1:        #synced
1658  * ERRORS:      EINVAL          Invalid devhandle or io_sync_direction
1659  *              ENORADDR        Bad real address
1660  *
1661  * Synchronize a memory region described by the given real address and size,
1662  * for the device defined by the given devhandle using the direction(s)
1663  * defined by the given io_sync_direction.  The argument size is the size of
1664  * the memory region in bytes.
1665  *
1666  * Return the actual number of bytes synchronized in the return value #synced,
1667  * which may be less than or equal to the argument size.  If the return
1668  * value #synced is less than size, the caller must continue to call this
1669  * function with updated real address and size arguments until the entire
1670  * memory region is synchronized.
1671  */
1672 #define HV_FAST_PCI_DMA_SYNC            0xb8
1673
1674 /* PCI MSI services.  */
1675
1676 #define HV_MSITYPE_MSI32                0x00
1677 #define HV_MSITYPE_MSI64                0x01
1678
1679 #define HV_MSIQSTATE_IDLE               0x00
1680 #define HV_MSIQSTATE_ERROR              0x01
1681
1682 #define HV_MSIQ_INVALID                 0x00
1683 #define HV_MSIQ_VALID                   0x01
1684
1685 #define HV_MSISTATE_IDLE                0x00
1686 #define HV_MSISTATE_DELIVERED           0x01
1687
1688 #define HV_MSIVALID_INVALID             0x00
1689 #define HV_MSIVALID_VALID               0x01
1690
1691 #define HV_PCIE_MSGTYPE_PME_MSG         0x18
1692 #define HV_PCIE_MSGTYPE_PME_ACK_MSG     0x1b
1693 #define HV_PCIE_MSGTYPE_CORR_MSG        0x30
1694 #define HV_PCIE_MSGTYPE_NONFATAL_MSG    0x31
1695 #define HV_PCIE_MSGTYPE_FATAL_MSG       0x33
1696
1697 #define HV_MSG_INVALID                  0x00
1698 #define HV_MSG_VALID                    0x01
1699
1700 /* pci_msiq_conf()
1701  * TRAP:        HV_FAST_TRAP
1702  * FUNCTION:    HV_FAST_PCI_MSIQ_CONF
1703  * ARG0:        devhandle
1704  * ARG1:        msiqid
1705  * ARG2:        real address
1706  * ARG3:        number of entries
1707  * RET0:        status
1708  * ERRORS:      EINVAL          Invalid devhandle, msiqid or nentries
1709  *              EBADALIGN       Improperly aligned real address
1710  *              ENORADDR        Bad real address
1711  *
1712  * Configure the MSI queue given by the devhandle and msiqid arguments,
1713  * and to be placed at the given real address and be of the given
1714  * number of entries.  The real address must be aligned exactly to match
1715  * the queue size.  Each queue entry is 64-bytes long, so f.e. a 32 entry
1716  * queue must be aligned on a 2048 byte real address boundary.  The MSI-EQ
1717  * Head and Tail are initialized so that the MSI-EQ is 'empty'.
1718  *
1719  * Implementation Note: Certain implementations have fixed sized queues.  In
1720  *                      that case, number of entries must contain the correct
1721  *                      value.
1722  */
1723 #define HV_FAST_PCI_MSIQ_CONF           0xc0
1724
1725 /* pci_msiq_info()
1726  * TRAP:        HV_FAST_TRAP
1727  * FUNCTION:    HV_FAST_PCI_MSIQ_INFO
1728  * ARG0:        devhandle
1729  * ARG1:        msiqid
1730  * RET0:        status
1731  * RET1:        real address
1732  * RET2:        number of entries
1733  * ERRORS:      EINVAL          Invalid devhandle or msiqid
1734  *
1735  * Return the configuration information for the MSI queue described
1736  * by the given devhandle and msiqid.  The base address of the queue
1737  * is returned in ARG1 and the number of entries is returned in ARG2.
1738  * If the queue is unconfigured, the real address is undefined and the
1739  * number of entries will be returned as zero.
1740  */
1741 #define HV_FAST_PCI_MSIQ_INFO           0xc1
1742
1743 /* pci_msiq_getvalid()
1744  * TRAP:        HV_FAST_TRAP
1745  * FUNCTION:    HV_FAST_PCI_MSIQ_GETVALID
1746  * ARG0:        devhandle
1747  * ARG1:        msiqid
1748  * RET0:        status
1749  * RET1:        msiqvalid       (HV_MSIQ_VALID or HV_MSIQ_INVALID)
1750  * ERRORS:      EINVAL          Invalid devhandle or msiqid
1751  *
1752  * Get the valid state of the MSI-EQ described by the given devhandle and
1753  * msiqid.
1754  */
1755 #define HV_FAST_PCI_MSIQ_GETVALID       0xc2
1756
1757 /* pci_msiq_setvalid()
1758  * TRAP:        HV_FAST_TRAP
1759  * FUNCTION:    HV_FAST_PCI_MSIQ_SETVALID
1760  * ARG0:        devhandle
1761  * ARG1:        msiqid
1762  * ARG2:        msiqvalid       (HV_MSIQ_VALID or HV_MSIQ_INVALID)
1763  * RET0:        status
1764  * ERRORS:      EINVAL          Invalid devhandle or msiqid or msiqvalid
1765  *                              value or MSI EQ is uninitialized
1766  *
1767  * Set the valid state of the MSI-EQ described by the given devhandle and
1768  * msiqid to the given msiqvalid.
1769  */
1770 #define HV_FAST_PCI_MSIQ_SETVALID       0xc3
1771
1772 /* pci_msiq_getstate()
1773  * TRAP:        HV_FAST_TRAP
1774  * FUNCTION:    HV_FAST_PCI_MSIQ_GETSTATE
1775  * ARG0:        devhandle
1776  * ARG1:        msiqid
1777  * RET0:        status
1778  * RET1:        msiqstate       (HV_MSIQSTATE_IDLE or HV_MSIQSTATE_ERROR)
1779  * ERRORS:      EINVAL          Invalid devhandle or msiqid
1780  *
1781  * Get the state of the MSI-EQ described by the given devhandle and
1782  * msiqid.
1783  */
1784 #define HV_FAST_PCI_MSIQ_GETSTATE       0xc4
1785
1786 /* pci_msiq_getvalid()
1787  * TRAP:        HV_FAST_TRAP
1788  * FUNCTION:    HV_FAST_PCI_MSIQ_GETVALID
1789  * ARG0:        devhandle
1790  * ARG1:        msiqid
1791  * ARG2:        msiqstate       (HV_MSIQSTATE_IDLE or HV_MSIQSTATE_ERROR)
1792  * RET0:        status
1793  * ERRORS:      EINVAL          Invalid devhandle or msiqid or msiqstate
1794  *                              value or MSI EQ is uninitialized
1795  *
1796  * Set the state of the MSI-EQ described by the given devhandle and
1797  * msiqid to the given msiqvalid.
1798  */
1799 #define HV_FAST_PCI_MSIQ_SETSTATE       0xc5
1800
1801 /* pci_msiq_gethead()
1802  * TRAP:        HV_FAST_TRAP
1803  * FUNCTION:    HV_FAST_PCI_MSIQ_GETHEAD
1804  * ARG0:        devhandle
1805  * ARG1:        msiqid
1806  * RET0:        status
1807  * RET1:        msiqhead
1808  * ERRORS:      EINVAL          Invalid devhandle or msiqid
1809  *
1810  * Get the current MSI EQ queue head for the MSI-EQ described by the
1811  * given devhandle and msiqid.
1812  */
1813 #define HV_FAST_PCI_MSIQ_GETHEAD        0xc6
1814
1815 /* pci_msiq_sethead()
1816  * TRAP:        HV_FAST_TRAP
1817  * FUNCTION:    HV_FAST_PCI_MSIQ_SETHEAD
1818  * ARG0:        devhandle
1819  * ARG1:        msiqid
1820  * ARG2:        msiqhead
1821  * RET0:        status
1822  * ERRORS:      EINVAL          Invalid devhandle or msiqid or msiqhead,
1823  *                              or MSI EQ is uninitialized
1824  *
1825  * Set the current MSI EQ queue head for the MSI-EQ described by the
1826  * given devhandle and msiqid.
1827  */
1828 #define HV_FAST_PCI_MSIQ_SETHEAD        0xc7
1829
1830 /* pci_msiq_gettail()
1831  * TRAP:        HV_FAST_TRAP
1832  * FUNCTION:    HV_FAST_PCI_MSIQ_GETTAIL
1833  * ARG0:        devhandle
1834  * ARG1:        msiqid
1835  * RET0:        status
1836  * RET1:        msiqtail
1837  * ERRORS:      EINVAL          Invalid devhandle or msiqid
1838  *
1839  * Get the current MSI EQ queue tail for the MSI-EQ described by the
1840  * given devhandle and msiqid.
1841  */
1842 #define HV_FAST_PCI_MSIQ_GETTAIL        0xc8
1843
1844 /* pci_msi_getvalid()
1845  * TRAP:        HV_FAST_TRAP
1846  * FUNCTION:    HV_FAST_PCI_MSI_GETVALID
1847  * ARG0:        devhandle
1848  * ARG1:        msinum
1849  * RET0:        status
1850  * RET1:        msivalidstate
1851  * ERRORS:      EINVAL          Invalid devhandle or msinum
1852  *
1853  * Get the current valid/enabled state for the MSI defined by the
1854  * given devhandle and msinum.
1855  */
1856 #define HV_FAST_PCI_MSI_GETVALID        0xc9
1857
1858 /* pci_msi_setvalid()
1859  * TRAP:        HV_FAST_TRAP
1860  * FUNCTION:    HV_FAST_PCI_MSI_SETVALID
1861  * ARG0:        devhandle
1862  * ARG1:        msinum
1863  * ARG2:        msivalidstate
1864  * RET0:        status
1865  * ERRORS:      EINVAL          Invalid devhandle or msinum or msivalidstate
1866  *
1867  * Set the current valid/enabled state for the MSI defined by the
1868  * given devhandle and msinum.
1869  */
1870 #define HV_FAST_PCI_MSI_SETVALID        0xca
1871
1872 /* pci_msi_getmsiq()
1873  * TRAP:        HV_FAST_TRAP
1874  * FUNCTION:    HV_FAST_PCI_MSI_GETMSIQ
1875  * ARG0:        devhandle
1876  * ARG1:        msinum
1877  * RET0:        status
1878  * RET1:        msiqid
1879  * ERRORS:      EINVAL          Invalid devhandle or msinum or MSI is unbound
1880  *
1881  * Get the MSI EQ that the MSI defined by the given devhandle and
1882  * msinum is bound to.
1883  */
1884 #define HV_FAST_PCI_MSI_GETMSIQ         0xcb
1885
1886 /* pci_msi_setmsiq()
1887  * TRAP:        HV_FAST_TRAP
1888  * FUNCTION:    HV_FAST_PCI_MSI_SETMSIQ
1889  * ARG0:        devhandle
1890  * ARG1:        msinum
1891  * ARG2:        msitype
1892  * ARG3:        msiqid
1893  * RET0:        status
1894  * ERRORS:      EINVAL          Invalid devhandle or msinum or msiqid
1895  *
1896  * Set the MSI EQ that the MSI defined by the given devhandle and
1897  * msinum is bound to.
1898  */
1899 #define HV_FAST_PCI_MSI_SETMSIQ         0xcc
1900
1901 /* pci_msi_getstate()
1902  * TRAP:        HV_FAST_TRAP
1903  * FUNCTION:    HV_FAST_PCI_MSI_GETSTATE
1904  * ARG0:        devhandle
1905  * ARG1:        msinum
1906  * RET0:        status
1907  * RET1:        msistate
1908  * ERRORS:      EINVAL          Invalid devhandle or msinum
1909  *
1910  * Get the state of the MSI defined by the given devhandle and msinum.
1911  * If not initialized, return HV_MSISTATE_IDLE.
1912  */
1913 #define HV_FAST_PCI_MSI_GETSTATE        0xcd
1914
1915 /* pci_msi_setstate()
1916  * TRAP:        HV_FAST_TRAP
1917  * FUNCTION:    HV_FAST_PCI_MSI_SETSTATE
1918  * ARG0:        devhandle
1919  * ARG1:        msinum
1920  * ARG2:        msistate
1921  * RET0:        status
1922  * ERRORS:      EINVAL          Invalid devhandle or msinum or msistate
1923  *
1924  * Set the state of the MSI defined by the given devhandle and msinum.
1925  */
1926 #define HV_FAST_PCI_MSI_SETSTATE        0xce
1927
1928 /* pci_msg_getmsiq()
1929  * TRAP:        HV_FAST_TRAP
1930  * FUNCTION:    HV_FAST_PCI_MSG_GETMSIQ
1931  * ARG0:        devhandle
1932  * ARG1:        msgtype
1933  * RET0:        status
1934  * RET1:        msiqid
1935  * ERRORS:      EINVAL          Invalid devhandle or msgtype
1936  *
1937  * Get the MSI EQ of the MSG defined by the given devhandle and msgtype.
1938  */
1939 #define HV_FAST_PCI_MSG_GETMSIQ         0xd0
1940
1941 /* pci_msg_setmsiq()
1942  * TRAP:        HV_FAST_TRAP
1943  * FUNCTION:    HV_FAST_PCI_MSG_SETMSIQ
1944  * ARG0:        devhandle
1945  * ARG1:        msgtype
1946  * ARG2:        msiqid
1947  * RET0:        status
1948  * ERRORS:      EINVAL          Invalid devhandle, msgtype, or msiqid
1949  *
1950  * Set the MSI EQ of the MSG defined by the given devhandle and msgtype.
1951  */
1952 #define HV_FAST_PCI_MSG_SETMSIQ         0xd1
1953
1954 /* pci_msg_getvalid()
1955  * TRAP:        HV_FAST_TRAP
1956  * FUNCTION:    HV_FAST_PCI_MSG_GETVALID
1957  * ARG0:        devhandle
1958  * ARG1:        msgtype
1959  * RET0:        status
1960  * RET1:        msgvalidstate
1961  * ERRORS:      EINVAL          Invalid devhandle or msgtype
1962  *
1963  * Get the valid/enabled state of the MSG defined by the given
1964  * devhandle and msgtype.
1965  */
1966 #define HV_FAST_PCI_MSG_GETVALID        0xd2
1967
1968 /* pci_msg_setvalid()
1969  * TRAP:        HV_FAST_TRAP
1970  * FUNCTION:    HV_FAST_PCI_MSG_SETVALID
1971  * ARG0:        devhandle
1972  * ARG1:        msgtype
1973  * ARG2:        msgvalidstate
1974  * RET0:        status
1975  * ERRORS:      EINVAL          Invalid devhandle or msgtype or msgvalidstate
1976  *
1977  * Set the valid/enabled state of the MSG defined by the given
1978  * devhandle and msgtype.
1979  */
1980 #define HV_FAST_PCI_MSG_SETVALID        0xd3
1981
1982 /* Performance counter services.  */
1983
1984 #define HV_PERF_JBUS_PERF_CTRL_REG      0x00
1985 #define HV_PERF_JBUS_PERF_CNT_REG       0x01
1986 #define HV_PERF_DRAM_PERF_CTRL_REG_0    0x02
1987 #define HV_PERF_DRAM_PERF_CNT_REG_0     0x03
1988 #define HV_PERF_DRAM_PERF_CTRL_REG_1    0x04
1989 #define HV_PERF_DRAM_PERF_CNT_REG_1     0x05
1990 #define HV_PERF_DRAM_PERF_CTRL_REG_2    0x06
1991 #define HV_PERF_DRAM_PERF_CNT_REG_2     0x07
1992 #define HV_PERF_DRAM_PERF_CTRL_REG_3    0x08
1993 #define HV_PERF_DRAM_PERF_CNT_REG_3     0x09
1994
1995 /* get_perfreg()
1996  * TRAP:        HV_FAST_TRAP
1997  * FUNCTION:    HV_FAST_GET_PERFREG
1998  * ARG0:        performance reg number
1999  * RET0:        status
2000  * RET1:        performance reg value
2001  * ERRORS:      EINVAL          Invalid performance register number
2002  *              ENOACCESS       No access allowed to performance counters
2003  *
2004  * Read the value of the given DRAM/JBUS performance counter/control register.
2005  */
2006 #define HV_FAST_GET_PERFREG             0x100
2007
2008 /* set_perfreg()
2009  * TRAP:        HV_FAST_TRAP
2010  * FUNCTION:    HV_FAST_SET_PERFREG
2011  * ARG0:        performance reg number
2012  * ARG1:        performance reg value
2013  * RET0:        status
2014  * ERRORS:      EINVAL          Invalid performance register number
2015  *              ENOACCESS       No access allowed to performance counters
2016  *
2017  * Write the given performance reg value to the given DRAM/JBUS
2018  * performance counter/control register.
2019  */
2020 #define HV_FAST_SET_PERFREG             0x101
2021
2022 /* MMU statistics services.
2023  *
2024  * The hypervisor maintains MMU statistics and privileged code provides
2025  * a buffer where these statistics can be collected.  It is continually
2026  * updated once configured.  The layout is as follows:
2027  */
2028 #ifndef __ASSEMBLY__
2029 struct hv_mmu_statistics {
2030         unsigned long immu_tsb_hits_ctx0_8k_tte;
2031         unsigned long immu_tsb_ticks_ctx0_8k_tte;
2032         unsigned long immu_tsb_hits_ctx0_64k_tte;
2033         unsigned long immu_tsb_ticks_ctx0_64k_tte;
2034         unsigned long __reserved1[2];
2035         unsigned long immu_tsb_hits_ctx0_4mb_tte;
2036         unsigned long immu_tsb_ticks_ctx0_4mb_tte;
2037         unsigned long __reserved2[2];
2038         unsigned long immu_tsb_hits_ctx0_256mb_tte;
2039         unsigned long immu_tsb_ticks_ctx0_256mb_tte;
2040         unsigned long __reserved3[4];
2041         unsigned long immu_tsb_hits_ctxnon0_8k_tte;
2042         unsigned long immu_tsb_ticks_ctxnon0_8k_tte;
2043         unsigned long immu_tsb_hits_ctxnon0_64k_tte;
2044         unsigned long immu_tsb_ticks_ctxnon0_64k_tte;
2045         unsigned long __reserved4[2];
2046         unsigned long immu_tsb_hits_ctxnon0_4mb_tte;
2047         unsigned long immu_tsb_ticks_ctxnon0_4mb_tte;
2048         unsigned long __reserved5[2];
2049         unsigned long immu_tsb_hits_ctxnon0_256mb_tte;
2050         unsigned long immu_tsb_ticks_ctxnon0_256mb_tte;
2051         unsigned long __reserved6[4];
2052         unsigned long dmmu_tsb_hits_ctx0_8k_tte;
2053         unsigned long dmmu_tsb_ticks_ctx0_8k_tte;
2054         unsigned long dmmu_tsb_hits_ctx0_64k_tte;
2055         unsigned long dmmu_tsb_ticks_ctx0_64k_tte;
2056         unsigned long __reserved7[2];
2057         unsigned long dmmu_tsb_hits_ctx0_4mb_tte;
2058         unsigned long dmmu_tsb_ticks_ctx0_4mb_tte;
2059         unsigned long __reserved8[2];
2060         unsigned long dmmu_tsb_hits_ctx0_256mb_tte;
2061         unsigned long dmmu_tsb_ticks_ctx0_256mb_tte;
2062         unsigned long __reserved9[4];
2063         unsigned long dmmu_tsb_hits_ctxnon0_8k_tte;
2064         unsigned long dmmu_tsb_ticks_ctxnon0_8k_tte;
2065         unsigned long dmmu_tsb_hits_ctxnon0_64k_tte;
2066         unsigned long dmmu_tsb_ticks_ctxnon0_64k_tte;
2067         unsigned long __reserved10[2];
2068         unsigned long dmmu_tsb_hits_ctxnon0_4mb_tte;
2069         unsigned long dmmu_tsb_ticks_ctxnon0_4mb_tte;
2070         unsigned long __reserved11[2];
2071         unsigned long dmmu_tsb_hits_ctxnon0_256mb_tte;
2072         unsigned long dmmu_tsb_ticks_ctxnon0_256mb_tte;
2073         unsigned long __reserved12[4];
2074 };
2075 #endif
2076
2077 /* mmustat_conf()
2078  * TRAP:        HV_FAST_TRAP
2079  * FUNCTION:    HV_FAST_MMUSTAT_CONF
2080  * ARG0:        real address
2081  * RET0:        status
2082  * RET1:        real address
2083  * ERRORS:      ENORADDR        Invalid real address
2084  *              EBADALIGN       Real address not aligned on 64-byte boundary
2085  *              EBADTRAP        API not supported on this processor
2086  *
2087  * Enable MMU statistic gathering using the buffer at the given real
2088  * address on the current virtual CPU.  The new buffer real address
2089  * is given in ARG1, and the previously specified buffer real address
2090  * is returned in RET1, or is returned as zero for the first invocation.
2091  *
2092  * If the passed in real address argument is zero, this will disable
2093  * MMU statistic collection on the current virtual CPU.  If an error is
2094  * returned then no statistics are collected.
2095  *
2096  * The buffer contents should be initialized to all zeros before being
2097  * given to the hypervisor or else the statistics will be meaningless.
2098  */
2099 #define HV_FAST_MMUSTAT_CONF            0x102
2100
2101 /* mmustat_info()
2102  * TRAP:        HV_FAST_TRAP
2103  * FUNCTION:    HV_FAST_MMUSTAT_INFO
2104  * RET0:        status
2105  * RET1:        real address
2106  * ERRORS:      EBADTRAP        API not supported on this processor
2107  *
2108  * Return the current state and real address of the currently configured
2109  * MMU statistics buffer on the current virtual CPU.
2110  */
2111 #define HV_FAST_MMUSTAT_INFO            0x103
2112
2113 /* Function numbers for HV_CORE_TRAP.  */
2114 #define HV_CORE_VER                     0x00
2115 #define HV_CORE_PUTCHAR                 0x01
2116 #define HV_CORE_EXIT                    0x02
2117
2118 #endif /* !(_SPARC64_HYPERVISOR_H) */