blob: 49a32b4fe5172bea0a6427af42ca4b290b2ed1da [file] [log] [blame]
Richard Henderson7886cef2019-09-19 13:30:29 -07001/*
Richard Henderson6670d4d2021-03-22 12:24:24 +01002 * Variable page size handling -- target specific part.
Richard Henderson7886cef2019-09-19 13:30:29 -07003 *
4 * Copyright (c) 2003 Fabrice Bellard
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
Chetan Pant61f3c912020-10-23 12:44:24 +00009 * version 2.1 of the License, or (at your option) any later version.
Richard Henderson7886cef2019-09-19 13:30:29 -070010 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 */
19
Richard Henderson44b99a62021-03-22 12:24:26 +010020#define IN_PAGE_VARY 1
21
Richard Henderson7886cef2019-09-19 13:30:29 -070022#include "qemu/osdep.h"
Marc-André Lureauec5f7ca2022-03-23 19:57:34 +040023#include "exec/page-vary.h"
Pierrick Bouvier2ec0dc22025-03-17 11:34:05 -070024#include "exec/target_page.h"
Richard Henderson7886cef2019-09-19 13:30:29 -070025
Richard Hendersond11bf642025-03-28 14:28:06 -050026
27/*
28 * For system mode, the minimum comes from the number of bits
29 * required for maximum alignment (6) and the number of bits
30 * required for TLB_FLAGS_MASK (3).
31 *
32 * For user mode, TARGET_PAGE_BITS_VARY is a hack to allow the target
33 * page size to match the host page size. Mostly, this reduces the
34 * ordinary target page size to run on a host with 4KiB pages (i.e. x86).
35 * There is no true minimum required by the implementation, but keep the
36 * same minimum as for system mode for sanity.
37 * See linux-user/mmap.c, mmap_h_lt_g and mmap_h_gt_g.
38 */
39#define TARGET_PAGE_BITS_MIN 9
40
41#ifndef TARGET_PAGE_BITS_VARY
42QEMU_BUILD_BUG_ON(TARGET_PAGE_BITS < TARGET_PAGE_BITS_MIN);
43#endif
44
45#ifndef CONFIG_USER_ONLY
46#include "exec/tlb-flags.h"
47
48QEMU_BUILD_BUG_ON(TLB_FLAGS_MASK & ((1u < TARGET_PAGE_BITS_MIN) - 1));
49
Richard Henderson12eeb042025-03-27 18:52:13 -050050int migration_legacy_page_bits(void)
51{
52#ifdef TARGET_PAGE_BITS_VARY
Richard Hendersond11bf642025-03-28 14:28:06 -050053 QEMU_BUILD_BUG_ON(TARGET_PAGE_BITS_LEGACY < TARGET_PAGE_BITS_MIN);
54 return TARGET_PAGE_BITS_LEGACY;
Richard Henderson12eeb042025-03-27 18:52:13 -050055#else
56 return TARGET_PAGE_BITS;
57#endif
58}
Richard Hendersond11bf642025-03-28 14:28:06 -050059#endif
Richard Henderson12eeb042025-03-27 18:52:13 -050060
Richard Henderson7886cef2019-09-19 13:30:29 -070061bool set_preferred_target_page_bits(int bits)
62{
Richard Henderson7886cef2019-09-19 13:30:29 -070063 assert(bits >= TARGET_PAGE_BITS_MIN);
Richard Hendersond11bf642025-03-28 14:28:06 -050064#ifdef TARGET_PAGE_BITS_VARY
Richard Henderson44b99a62021-03-22 12:24:26 +010065 return set_preferred_target_page_bits_common(bits);
66#else
Richard Henderson7886cef2019-09-19 13:30:29 -070067 return true;
Richard Henderson44b99a62021-03-22 12:24:26 +010068#endif
Richard Henderson7886cef2019-09-19 13:30:29 -070069}
70
71void finalize_target_page_bits(void)
72{
Richard Hendersond11bf642025-03-28 14:28:06 -050073#ifndef TARGET_PAGE_BITS_VARY
74 finalize_target_page_bits_common(TARGET_PAGE_BITS);
75#elif defined(CONFIG_USER_ONLY)
76 assert(target_page.bits != 0);
77 finalize_target_page_bits_common(target_page.bits);
78#else
79 finalize_target_page_bits_common(TARGET_PAGE_BITS_LEGACY);
80#endif
Richard Henderson7886cef2019-09-19 13:30:29 -070081}