1 /*
2  * Definitions and utilities for save / restore.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation;
7  * version 2.1 of the License.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include "xc_private.h"
19 
20 #include <xen/foreign/x86_32.h>
21 #include <xen/foreign/x86_64.h>
22 
23 /*
24 ** We process save/restore/migrate in batches of pages; the below
25 ** determines how many pages we (at maximum) deal with in each batch.
26 */
27 #define MAX_BATCH_SIZE 1024   /* up to 1024 pages (4MB) at a time */
28 
29 /* When pinning page tables at the end of restore, we also use batching. */
30 #define MAX_PIN_BATCH  1024
31 
32 
33 /*
34 ** Save/restore deal with the mfn_to_pfn (M2P) and pfn_to_mfn (P2M) tables.
35 ** The M2P simply holds the corresponding PFN, while the top bit of a P2M
36 ** entry tell us whether or not the the PFN is currently mapped.
37 */
38 
39 #define PFN_TO_KB(_pfn) ((_pfn) << (PAGE_SHIFT - 10))
40 
41 
42 #define MEMCPY_FIELD(_d, _s, _f, _w) do {                          \
43     if ((_w) == 8)                                                 \
44         memcpy(&(_d)->x64._f, &(_s)->x64._f,sizeof((_d)->x64._f)); \
45     else                                                           \
46         memcpy(&(_d)->x32._f, &(_s)->x32._f,sizeof((_d)->x32._f)); \
47 } while (0)
48 
49 #define MEMSET_ARRAY_FIELD(_p, _f, _v, _w) do {                    \
50     if ((_w) == 8)                                                 \
51         memset(&(_p)->x64._f[0], (_v), sizeof((_p)->x64._f));      \
52     else                                                           \
53         memset(&(_p)->x32._f[0], (_v), sizeof((_p)->x32._f));      \
54 } while (0)
55