1 /* SPDX-License-Identifier: ((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) */
2 /*
3  * Freescale hypervisor ioctl and kernel interface
4  *
5  * Copyright (C) 2008-2011 Freescale Semiconductor, Inc.
6  * Author: Timur Tabi <timur@freescale.com>
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are met:
10  *     * Redistributions of source code must retain the above copyright
11  *       notice, this list of conditions and the following disclaimer.
12  *     * Redistributions in binary form must reproduce the above copyright
13  *       notice, this list of conditions and the following disclaimer in the
14  *       documentation and/or other materials provided with the distribution.
15  *     * Neither the name of Freescale Semiconductor nor the
16  *       names of its contributors may be used to endorse or promote products
17  *       derived from this software without specific prior written permission.
18  *
19  *
20  * ALTERNATIVELY, this software may be distributed under the terms of the
21  * GNU General Public License ("GPL") as published by the Free Software
22  * Foundation, either version 2 of that License or (at your option) any
23  * later version.
24  *
25  * This software is provided by Freescale Semiconductor "as is" and any
26  * express or implied warranties, including, but not limited to, the implied
27  * warranties of merchantability and fitness for a particular purpose are
28  * disclaimed. In no event shall Freescale Semiconductor be liable for any
29  * direct, indirect, incidental, special, exemplary, or consequential damages
30  * (including, but not limited to, procurement of substitute goods or services;
31  * loss of use, data, or profits; or business interruption) however caused and
32  * on any theory of liability, whether in contract, strict liability, or tort
33  * (including negligence or otherwise) arising in any way out of the use of this
34  * software, even if advised of the possibility of such damage.
35  *
36  * This file is used by the Freescale hypervisor management driver.  It can
37  * also be included by applications that need to communicate with the driver
38  * via the ioctl interface.
39  */
40 
41 #ifndef _UAPIFSL_HYPERVISOR_H
42 #define _UAPIFSL_HYPERVISOR_H
43 
44 #include <linux/types.h>
45 
46 /**
47  * struct fsl_hv_ioctl_restart - restart a partition
48  * @ret: return error code from the hypervisor
49  * @partition: the ID of the partition to restart, or -1 for the
50  *             calling partition
51  *
52  * Used by FSL_HV_IOCTL_PARTITION_RESTART
53  */
54 struct fsl_hv_ioctl_restart {
55 	__u32 ret;
56 	__u32 partition;
57 };
58 
59 /**
60  * struct fsl_hv_ioctl_status - get a partition's status
61  * @ret: return error code from the hypervisor
62  * @partition: the ID of the partition to query, or -1 for the
63  *             calling partition
64  * @status: The returned status of the partition
65  *
66  * Used by FSL_HV_IOCTL_PARTITION_GET_STATUS
67  *
68  * Values of 'status':
69  *    0 = Stopped
70  *    1 = Running
71  *    2 = Starting
72  *    3 = Stopping
73  */
74 struct fsl_hv_ioctl_status {
75 	__u32 ret;
76 	__u32 partition;
77 	__u32 status;
78 };
79 
80 /**
81  * struct fsl_hv_ioctl_start - start a partition
82  * @ret: return error code from the hypervisor
83  * @partition: the ID of the partition to control
84  * @entry_point: The offset within the guest IMA to start execution
85  * @load: If non-zero, reload the partition's images before starting
86  *
87  * Used by FSL_HV_IOCTL_PARTITION_START
88  */
89 struct fsl_hv_ioctl_start {
90 	__u32 ret;
91 	__u32 partition;
92 	__u32 entry_point;
93 	__u32 load;
94 };
95 
96 /**
97  * struct fsl_hv_ioctl_stop - stop a partition
98  * @ret: return error code from the hypervisor
99  * @partition: the ID of the partition to stop, or -1 for the calling
100  *             partition
101  *
102  * Used by FSL_HV_IOCTL_PARTITION_STOP
103  */
104 struct fsl_hv_ioctl_stop {
105 	__u32 ret;
106 	__u32 partition;
107 };
108 
109 /**
110  * struct fsl_hv_ioctl_memcpy - copy memory between partitions
111  * @ret: return error code from the hypervisor
112  * @source: the partition ID of the source partition, or -1 for this
113  *          partition
114  * @target: the partition ID of the target partition, or -1 for this
115  *          partition
116  * @reserved: reserved, must be set to 0
117  * @local_addr: user-space virtual address of a buffer in the local
118  *              partition
119  * @remote_addr: guest physical address of a buffer in the
120  *           remote partition
121  * @count: the number of bytes to copy.  Both the local and remote
122  *         buffers must be at least 'count' bytes long
123  *
124  * Used by FSL_HV_IOCTL_MEMCPY
125  *
126  * The 'local' partition is the partition that calls this ioctl.  The
127  * 'remote' partition is a different partition.  The data is copied from
128  * the 'source' paritition' to the 'target' partition.
129  *
130  * The buffer in the remote partition must be guest physically
131  * contiguous.
132  *
133  * This ioctl does not support copying memory between two remote
134  * partitions or within the same partition, so either 'source' or
135  * 'target' (but not both) must be -1.  In other words, either
136  *
137  *      source == local and target == remote
138  * or
139  *      source == remote and target == local
140  */
141 struct fsl_hv_ioctl_memcpy {
142 	__u32 ret;
143 	__u32 source;
144 	__u32 target;
145 	__u32 reserved;	/* padding to ensure local_vaddr is aligned */
146 	__u64 local_vaddr;
147 	__u64 remote_paddr;
148 	__u64 count;
149 };
150 
151 /**
152  * struct fsl_hv_ioctl_doorbell - ring a doorbell
153  * @ret: return error code from the hypervisor
154  * @doorbell: the handle of the doorbell to ring doorbell
155  *
156  * Used by FSL_HV_IOCTL_DOORBELL
157  */
158 struct fsl_hv_ioctl_doorbell {
159 	__u32 ret;
160 	__u32 doorbell;
161 };
162 
163 /**
164  * struct fsl_hv_ioctl_prop - get/set a device tree property
165  * @ret: return error code from the hypervisor
166  * @handle: handle of partition whose tree to access
167  * @path: virtual address of path name of node to access
168  * @propname: virtual address of name of property to access
169  * @propval: virtual address of property data buffer
170  * @proplen: Size of property data buffer
171  * @reserved: reserved, must be set to 0
172  *
173  * Used by FSL_HV_IOCTL_DOORBELL
174  */
175 struct fsl_hv_ioctl_prop {
176 	__u32 ret;
177 	__u32 handle;
178 	__u64 path;
179 	__u64 propname;
180 	__u64 propval;
181 	__u32 proplen;
182 	__u32 reserved;	/* padding to ensure structure is aligned */
183 };
184 
185 /* The ioctl type, documented in ioctl-number.txt */
186 #define FSL_HV_IOCTL_TYPE	0xAF
187 
188 /* Restart another partition */
189 #define FSL_HV_IOCTL_PARTITION_RESTART \
190 	_IOWR(FSL_HV_IOCTL_TYPE, 1, struct fsl_hv_ioctl_restart)
191 
192 /* Get a partition's status */
193 #define FSL_HV_IOCTL_PARTITION_GET_STATUS \
194 	_IOWR(FSL_HV_IOCTL_TYPE, 2, struct fsl_hv_ioctl_status)
195 
196 /* Boot another partition */
197 #define FSL_HV_IOCTL_PARTITION_START \
198 	_IOWR(FSL_HV_IOCTL_TYPE, 3, struct fsl_hv_ioctl_start)
199 
200 /* Stop this or another partition */
201 #define FSL_HV_IOCTL_PARTITION_STOP \
202 	_IOWR(FSL_HV_IOCTL_TYPE, 4, struct fsl_hv_ioctl_stop)
203 
204 /* Copy data from one partition to another */
205 #define FSL_HV_IOCTL_MEMCPY \
206 	_IOWR(FSL_HV_IOCTL_TYPE, 5, struct fsl_hv_ioctl_memcpy)
207 
208 /* Ring a doorbell */
209 #define FSL_HV_IOCTL_DOORBELL \
210 	_IOWR(FSL_HV_IOCTL_TYPE, 6, struct fsl_hv_ioctl_doorbell)
211 
212 /* Get a property from another guest's device tree */
213 #define FSL_HV_IOCTL_GETPROP \
214 	_IOWR(FSL_HV_IOCTL_TYPE, 7, struct fsl_hv_ioctl_prop)
215 
216 /* Set a property in another guest's device tree */
217 #define FSL_HV_IOCTL_SETPROP \
218 	_IOWR(FSL_HV_IOCTL_TYPE, 8, struct fsl_hv_ioctl_prop)
219 
220 
221 #endif /* _UAPIFSL_HYPERVISOR_H */
222