xref: /freebsd/sys/dev/nvdimm/nvdimm_var.h (revision 28f4385e45a2681c14bd04b83fe1796eaefe8265)
1 /*-
2  * Copyright (c) 2017 The FreeBSD Foundation
3  * All rights reserved.
4  * Copyright (c) 2018, 2019 Intel Corporation
5  *
6  * This software was developed by Konstantin Belousov <kib@FreeBSD.org>
7  * under sponsorship from the FreeBSD Foundation.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  *
30  * $FreeBSD$
31  */
32 
33 #ifndef __DEV_NVDIMM_VAR_H__
34 #define	__DEV_NVDIMM_VAR_H__
35 
36 typedef uint32_t nfit_handle_t;
37 
38 enum nvdimm_root_ivar {
39 	NVDIMM_ROOT_IVAR_ACPI_HANDLE,
40 	NVDIMM_ROOT_IVAR_DEVICE_HANDLE,
41 	NVDIMM_ROOT_IVAR_MAX,
42 };
43 __BUS_ACCESSOR(nvdimm_root, acpi_handle, NVDIMM_ROOT, ACPI_HANDLE, ACPI_HANDLE)
44 __BUS_ACCESSOR(nvdimm_root, device_handle, NVDIMM_ROOT, DEVICE_HANDLE,
45     nfit_handle_t)
46 
47 struct nvdimm_dev {
48 	device_t	nv_dev;
49 	nfit_handle_t	nv_handle;
50 	uint64_t	**nv_flush_addr;
51 	int		nv_flush_addr_cnt;
52 };
53 
54 enum SPA_mapping_type {
55 	SPA_TYPE_VOLATILE_MEMORY	= 0,
56 	SPA_TYPE_PERSISTENT_MEMORY	= 1,
57 	SPA_TYPE_CONTROL_REGION		= 2,
58 	SPA_TYPE_DATA_REGION		= 3,
59 	SPA_TYPE_VOLATILE_VIRTUAL_DISK	= 4,
60 	SPA_TYPE_VOLATILE_VIRTUAL_CD	= 5,
61 	SPA_TYPE_PERSISTENT_VIRTUAL_DISK= 6,
62 	SPA_TYPE_PERSISTENT_VIRTUAL_CD	= 7,
63 	SPA_TYPE_UNKNOWN		= 127,
64 };
65 
66 struct SPA_mapping {
67 	enum SPA_mapping_type	spa_type;
68 	int			spa_domain;
69 	int			spa_nfit_idx;
70 	uint64_t		spa_phys_base;
71 	uint64_t		spa_len;
72 	uint64_t		spa_efi_mem_flags;
73 	void			*spa_kva;
74 	struct cdev		*spa_dev;
75 	struct g_geom		*spa_g;
76 	struct g_provider	*spa_p;
77 	struct bio_queue_head	spa_g_queue;
78 	struct mtx		spa_g_mtx;
79 	struct mtx		spa_g_stat_mtx;
80 	struct devstat		*spa_g_devstat;
81 	struct proc		*spa_g_proc;
82 	struct vm_object	*spa_obj;
83 	bool			spa_g_proc_run;
84 	bool			spa_g_proc_exiting;
85 };
86 
87 extern struct SPA_mapping *spa_mappings;
88 extern int spa_mappings_cnt;
89 
90 MALLOC_DECLARE(M_NVDIMM);
91 
92 enum SPA_mapping_type nvdimm_spa_type_from_uuid(struct uuid *);
93 struct nvdimm_dev *nvdimm_find_by_handle(nfit_handle_t nv_handle);
94 int nvdimm_iterate_nfit(ACPI_TABLE_NFIT *nfitbl, enum AcpiNfitType type,
95     int (*cb)(void *, void *), void *arg);
96 
97 #endif		/* __DEV_NVDIMM_VAR_H__ */
98