xref: /freebsd/lib/libkvm/kvm_powerpc64.h (revision 4d846d260e2b9a3d4d0a701462568268cbfe7a5b)
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  * $FreeBSD$
28d3c34fc0SLeandro Lupori  */
29d3c34fc0SLeandro Lupori 
30d3c34fc0SLeandro Lupori #ifndef	__KVM_POWERPC64_H__
31d3c34fc0SLeandro Lupori #define	__KVM_POWERPC64_H__
32d3c34fc0SLeandro Lupori 
33d3c34fc0SLeandro Lupori /* Debug stuff */
34d3c34fc0SLeandro Lupori #define	KVM_PPC64_DBG	0
35d3c34fc0SLeandro Lupori #if	KVM_PPC64_DBG
36d3c34fc0SLeandro Lupori #include <stdio.h>
37d3c34fc0SLeandro Lupori #define	dprintf(fmt, ...)	printf(fmt, ## __VA_ARGS__)
38d3c34fc0SLeandro Lupori #else
39d3c34fc0SLeandro Lupori #define	dprintf(fmt, ...)
40d3c34fc0SLeandro Lupori #endif
41d3c34fc0SLeandro Lupori 
42d3c34fc0SLeandro Lupori 
43d3c34fc0SLeandro Lupori #define	PPC64_KERNBASE		0x100100ULL
44d3c34fc0SLeandro Lupori 
45d3c34fc0SLeandro Lupori /* Page params */
46d3c34fc0SLeandro Lupori #define	PPC64_PAGE_SHIFT	12
47d3c34fc0SLeandro Lupori #define	PPC64_PAGE_SIZE		(1ULL << PPC64_PAGE_SHIFT)
48d3c34fc0SLeandro Lupori #define	PPC64_PAGE_MASK		(PPC64_PAGE_SIZE - 1)
49d3c34fc0SLeandro Lupori 
50d3c34fc0SLeandro Lupori #define	ppc64_round_page(x)	roundup2((kvaddr_t)(x), PPC64_PAGE_SIZE)
51d3c34fc0SLeandro Lupori 
52d3c34fc0SLeandro Lupori #define	PPC64_MMU_G5		"mmu_g5"
53d3c34fc0SLeandro Lupori #define	PPC64_MMU_PHYP		"mmu_phyp"
54d3c34fc0SLeandro Lupori 
55d3c34fc0SLeandro Lupori /* MMU interface */
56d3c34fc0SLeandro Lupori #define	PPC64_MMU_OPS(kd)	(kd)->vmst->mmu.ops
57d3c34fc0SLeandro Lupori #define	PPC64_MMU_OP(kd, op, ...) PPC64_MMU_OPS(kd)->op((kd), ## __VA_ARGS__)
58d3c34fc0SLeandro Lupori #define	PPC64_MMU_DATA(kd)	(kd)->vmst->mmu.data
59d3c34fc0SLeandro Lupori 
60d3c34fc0SLeandro Lupori struct ppc64_mmu_ops {
61d3c34fc0SLeandro Lupori 	int (*init)(kvm_t *);
62d3c34fc0SLeandro Lupori 	void (*cleanup)(kvm_t *);
63d3c34fc0SLeandro Lupori 	int (*kvatop)(kvm_t *, kvaddr_t, off_t *);
64d3c34fc0SLeandro Lupori 	int (*walk_pages)(kvm_t *, kvm_walk_pages_cb_t *, void *);
65d3c34fc0SLeandro Lupori };
66d3c34fc0SLeandro Lupori 
67d3c34fc0SLeandro Lupori struct ppc64_mmu {
68d3c34fc0SLeandro Lupori 	struct ppc64_mmu_ops *ops;
69d3c34fc0SLeandro Lupori 	void *data;
70d3c34fc0SLeandro Lupori };
71d3c34fc0SLeandro Lupori 
72d3c34fc0SLeandro Lupori struct vmstate {
73d3c34fc0SLeandro Lupori 	struct minidumphdr hdr;
74d3c34fc0SLeandro Lupori 	uint64_t kimg_start;
75d3c34fc0SLeandro Lupori 	uint64_t kimg_end;
76d3c34fc0SLeandro Lupori 	struct ppc64_mmu mmu;
77d3c34fc0SLeandro Lupori };
78d3c34fc0SLeandro Lupori 
79d3c34fc0SLeandro Lupori extern struct ppc64_mmu_ops *ppc64_mmu_ops_hpt;
80d3c34fc0SLeandro Lupori 
81d3c34fc0SLeandro Lupori #endif /* !__KVM_POWERPC64_H__ */
82