| 1 | /*	$OpenBSD: hibernate_var.h,v 1.2 2026/09/19 17:27:09 kettenis 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 | #ifndef _LOCORE |
| 20 | extern vaddr_t global_piglet_va; |
| 21 | extern paddr_t global_piglet_pa; |
| 22 | #endif |
| 23 | |
| 24 | #define PIGLET_PAGE_MASK	(~((1ULL << 21) - 1)) |
| 25 | |
| 26 | /* |
| 27 | * On arm64 the resume page tables use both TTBR0 and TTBR1. The |
| 28 | * TTBR0 (PT0) page tables start at L0 and cover the first 4MB of the |
| 29 | * piglet with 4KB pages (such that pages in the piglet can be |
| 30 | * accessed using their offset) and also covers identy mappings for |
| 31 | * the pig, the piglet and kernel using 2MB mappings. The TTBR1 (PT1) |
| 32 | * page tables covers mappings for the piglet and kernel using normal |
| 33 | * kernel VAs. |
| 34 | */ |
| 35 | #define HIBERNATE_PT0_L0_PAGE	(PAGE_SIZE * 512)	/* TTBR0 root */ |
| 36 | #define HIBERNATE_PT0_L1_LOW	(PAGE_SIZE * 513) |
| 37 | #define HIBERNATE_PT0_L2_LOW	(PAGE_SIZE * 514) |
| 38 | #define HIBERNATE_PT0_L3_LOW	(PAGE_SIZE * 515)	/* 2 pages */ |
| 39 | #define HIBERNATE_PT0_L1_HI	(PAGE_SIZE * 517) |
| 40 | #define HIBERNATE_PT1_L1_PAGE	(PAGE_SIZE * 518)	/* TTBR1 root */ |
| 41 | |
| 42 | /* Pool of L2 pages per distinct PT0_L1_LOW/PT0_L1_HI/PT1_L1 slot */ |
| 43 | #define HIBERNATE_PT0_L2_LOW_POOL	(PAGE_SIZE * 520) |
| 44 | #define HIBERNATE_PT0_L2_LOW_POOL_COUNT	16 |
| 45 | #define HIBERNATE_PT0_L2_HI_POOL	(PAGE_SIZE * 536) |
| 46 | #define HIBERNATE_PT0_L2_HI_POOL_COUNT	16 |
| 47 | #define HIBERNATE_PT1_L2_POOL		(PAGE_SIZE * 552) |
| 48 | #define HIBERNATE_PT1_L2_POOL_COUNT	16 |
| 49 | |
| 50 | /* 3 pages for stack */ |
| 51 | #define HIBERNATE_STACK_PAGE	(PAGE_SIZE * 570) |
| 52 | |
| 53 | #define HIBERNATE_INFLATE_PAGE	(PAGE_SIZE * 571) |
| 54 | |
| 55 | /* |
| 56 | * On arm64 we can't access low VA using the normal kernel page |
| 57 | * tables. Since the hiballoc page is used before we install the |
| 58 | * resume page tables, use the normal kernel VA for access. |
| 59 | */ |
| 60 | #define HIBERNATE_HIBALLOC_PAGE	(global_piglet_va + PAGE_SIZE * 572) |
| 61 | |
| 62 | /* Use 4MB hibernation chunks */ |
| 63 | #define HIBERNATE_CHUNK_SIZE		0x400000 |
| 64 | |
| 65 | #define HIBERNATE_CHUNK_TABLE_SIZE	0x200000 |
| 66 | |
| 67 | #define HIBERNATE_STACK_OFFSET		0x0F00 |
| 68 | |
| 69 | /* |
| 70 | * Minimum amount of memory for hibernate support. This is used in early boot |
| 71 | * when deciding if we can preallocate the piglet. If the machine does not |
| 72 | * have at least HIBERNATE_MIN_MEMORY RAM, we won't support hibernate. This |
| 73 | * avoids late allocation issues due to fragmented memory and failure to |
| 74 | * hibernate. We need to be able to allocate 32MB contiguous memory, aligned |
| 75 | * to 2MB. |
| 76 | * |
| 77 | * The default minimum required memory is 512MB (1ULL << 29). |
| 78 | */ |
| 79 | #define HIBERNATE_MIN_MEMORY	(1ULL << 29) |