| 1 | /*	$OpenBSD: hibernate_var.h,v 1.14 2025/09/13 13:43:47 mlarkin Exp $	*/ |
| 2 | |
| 3 | /* |
| 4 | * Copyright (c) 2011 Mike Larkin <mlarkin@openbsd.org> |
| 5 | * |
| 6 | * Permission to use, copy, modify, and distribute this software for any |
| 7 | * purpose with or without fee is hereby granted, provided that the above |
| 8 | * copyright notice and this permission notice appear in all copies. |
| 9 | * |
| 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 17 | */ |
| 18 | |
| 19 | #define PIGLET_PAGE_MASK (L2_FRAME) |
| 20 | |
| 21 | /* |
| 22 | * PML4 table for resume |
| 23 | */ |
| 24 | #define HIBERNATE_PML4T		(PAGE_SIZE * 21) |
| 25 | |
| 26 | /* |
| 27 | * amd64 uses a PDPT to map the first 512GB phys mem plus one more |
| 28 | * to map any ranges of phys mem past 512GB (if needed) |
| 29 | */ |
| 30 | #define HIBERNATE_PDPT_LOW	(PAGE_SIZE * 22) |
| 31 | #define HIBERNATE_PDPT_HI	(PAGE_SIZE * 23) |
| 32 | |
| 33 | /* |
| 34 | * amd64 uses one PD to map the first 1GB phys mem plus one more to map any |
| 35 | * other 1GB ranges within the first 512GB phys, plus one more to map any |
| 36 | * 1GB range in any subsequent 512GB range |
| 37 | */ |
| 38 | #define HIBERNATE_PD_LOW	(PAGE_SIZE * 24) |
| 39 | #define HIBERNATE_PD_LOW2	(PAGE_SIZE * 25) |
| 40 | #define HIBERNATE_PD_HI		(PAGE_SIZE * 26) |
| 41 | |
| 42 | /* |
| 43 | * amd64 uses one PT to map the first 2MB phys mem plus one more to map any |
| 44 | * other 2MB range within the first 1GB, plus one more to map any 2MB range |
| 45 | * in any subsequent 512GB range. |
| 46 | */ |
| 47 | #define HIBERNATE_PT_LOW	(PAGE_SIZE * 27) |
| 48 | #define HIBERNATE_PT_LOW2	(PAGE_SIZE * 28) |
| 49 | #define HIBERNATE_PT_HI		(PAGE_SIZE * 29) |
| 50 | |
| 51 | /* 3 pages for stack */ |
| 52 | #define HIBERNATE_STACK_PAGE	(PAGE_SIZE * 32) |
| 53 | |
| 54 | #define HIBERNATE_INFLATE_PAGE	(PAGE_SIZE * 33) |
| 55 | /* HIBERNATE_HIBALLOC_PAGE must be the last stolen page (see machdep.c) */ |
| 56 | #define HIBERNATE_HIBALLOC_PAGE	(PAGE_SIZE * 34) |
| 57 | |
| 58 | /* Use 4MB hibernation chunks */ |
| 59 | #define HIBERNATE_CHUNK_SIZE		0x400000 |
| 60 | |
| 61 | #define HIBERNATE_CHUNK_TABLE_SIZE	0x200000 |
| 62 | |
| 63 | #define HIBERNATE_STACK_OFFSET	0x0F00 |
| 64 | |
| 65 | /* |
| 66 | * Minimum amount of memory for hibernate support. This is used in early boot |
| 67 | * when deciding if we can preallocate the piglet. If the machine does not |
| 68 | * have at least HIBERNATE_MIN_MEMORY RAM, we won't support hibernate. This |
| 69 | * avoids late allocation issues due to fragmented memory and failure to |
| 70 | * hibernate. We need to be able to allocate 16MB contiguous memory, aligned |
| 71 | * to 2MB. |
| 72 | * |
| 73 | * The default minimum required memory is 512MB (1ULL << 29). |
| 74 | */ |
| 75 | #define HIBERNATE_MIN_MEMORY	(1ULL << 29) |