xref: /freebsd/lib/libkvm/kvm_powerpc64.h (revision b3e7694832e81d7a904a10f525f8797b753bf0d3)
1d3c34fc0SLeandro Lupori /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3d3c34fc0SLeandro Lupori  *
4d3c34fc0SLeandro Lupori  * Copyright (c) 2019 Leandro Lupori
5d3c34fc0SLeandro Lupori  *
6d3c34fc0SLeandro Lupori  * Redistribution and use in source and binary forms, with or without
7d3c34fc0SLeandro Lupori  * modification, are permitted provided that the following conditions
8d3c34fc0SLeandro Lupori  * are met:
9d3c34fc0SLeandro Lupori  * 1. Redistributions of source code must retain the above copyright
10d3c34fc0SLeandro Lupori  *    notice, this list of conditions and the following disclaimer.
11d3c34fc0SLeandro Lupori  * 2. Redistributions in binary form must reproduce the above copyright
12d3c34fc0SLeandro Lupori  *    notice, this list of conditions and the following disclaimer in the
13d3c34fc0SLeandro Lupori  *    documentation and/or other materials provided with the distribution.
14d3c34fc0SLeandro Lupori  *
15d3c34fc0SLeandro Lupori  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16d3c34fc0SLeandro Lupori  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17d3c34fc0SLeandro Lupori  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18d3c34fc0SLeandro Lupori  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19d3c34fc0SLeandro Lupori  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20d3c34fc0SLeandro Lupori  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21d3c34fc0SLeandro Lupori  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22d3c34fc0SLeandro Lupori  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23d3c34fc0SLeandro Lupori  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24d3c34fc0SLeandro Lupori  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25d3c34fc0SLeandro Lupori  * SUCH DAMAGE.
26d3c34fc0SLeandro Lupori  */
27d3c34fc0SLeandro Lupori 
28d3c34fc0SLeandro Lupori #ifndef	__KVM_POWERPC64_H__
29d3c34fc0SLeandro Lupori #define	__KVM_POWERPC64_H__
30d3c34fc0SLeandro Lupori 
31d3c34fc0SLeandro Lupori /* Debug stuff */
32d3c34fc0SLeandro Lupori #define	KVM_PPC64_DBG	0
33d3c34fc0SLeandro Lupori #if	KVM_PPC64_DBG
34d3c34fc0SLeandro Lupori #include <stdio.h>
35d3c34fc0SLeandro Lupori #define	dprintf(fmt, ...)	printf(fmt, ## __VA_ARGS__)
36d3c34fc0SLeandro Lupori #else
37d3c34fc0SLeandro Lupori #define	dprintf(fmt, ...)
38d3c34fc0SLeandro Lupori #endif
39d3c34fc0SLeandro Lupori 
40d3c34fc0SLeandro Lupori 
41d3c34fc0SLeandro Lupori #define	PPC64_KERNBASE		0x100100ULL
42d3c34fc0SLeandro Lupori 
43d3c34fc0SLeandro Lupori /* Page params */
44d3c34fc0SLeandro Lupori #define	PPC64_PAGE_SHIFT	12
45d3c34fc0SLeandro Lupori #define	PPC64_PAGE_SIZE		(1ULL << PPC64_PAGE_SHIFT)
46d3c34fc0SLeandro Lupori #define	PPC64_PAGE_MASK		(PPC64_PAGE_SIZE - 1)
47d3c34fc0SLeandro Lupori 
48d3c34fc0SLeandro Lupori #define	ppc64_round_page(x)	roundup2((kvaddr_t)(x), PPC64_PAGE_SIZE)
49d3c34fc0SLeandro Lupori 
50d3c34fc0SLeandro Lupori #define	PPC64_MMU_G5		"mmu_g5"
51d3c34fc0SLeandro Lupori #define	PPC64_MMU_PHYP		"mmu_phyp"
52d3c34fc0SLeandro Lupori 
53d3c34fc0SLeandro Lupori /* MMU interface */
54d3c34fc0SLeandro Lupori #define	PPC64_MMU_OPS(kd)	(kd)->vmst->mmu.ops
55d3c34fc0SLeandro Lupori #define	PPC64_MMU_OP(kd, op, ...) PPC64_MMU_OPS(kd)->op((kd), ## __VA_ARGS__)
56d3c34fc0SLeandro Lupori #define	PPC64_MMU_DATA(kd)	(kd)->vmst->mmu.data
57d3c34fc0SLeandro Lupori 
58d3c34fc0SLeandro Lupori struct ppc64_mmu_ops {
59d3c34fc0SLeandro Lupori 	int (*init)(kvm_t *);
60d3c34fc0SLeandro Lupori 	void (*cleanup)(kvm_t *);
61d3c34fc0SLeandro Lupori 	int (*kvatop)(kvm_t *, kvaddr_t, off_t *);
62d3c34fc0SLeandro Lupori 	int (*walk_pages)(kvm_t *, kvm_walk_pages_cb_t *, void *);
63d3c34fc0SLeandro Lupori };
64d3c34fc0SLeandro Lupori 
65d3c34fc0SLeandro Lupori struct ppc64_mmu {
66d3c34fc0SLeandro Lupori 	struct ppc64_mmu_ops *ops;
67d3c34fc0SLeandro Lupori 	void *data;
68d3c34fc0SLeandro Lupori };
69d3c34fc0SLeandro Lupori 
70d3c34fc0SLeandro Lupori struct vmstate {
71d3c34fc0SLeandro Lupori 	struct minidumphdr hdr;
72d3c34fc0SLeandro Lupori 	uint64_t kimg_start;
73d3c34fc0SLeandro Lupori 	uint64_t kimg_end;
74d3c34fc0SLeandro Lupori 	struct ppc64_mmu mmu;
75d3c34fc0SLeandro Lupori };
76d3c34fc0SLeandro Lupori 
77d3c34fc0SLeandro Lupori extern struct ppc64_mmu_ops *ppc64_mmu_ops_hpt;
78d3c34fc0SLeandro Lupori 
79d3c34fc0SLeandro Lupori #endif /* !__KVM_POWERPC64_H__ */
80