1 /*
2  * Copyright(c) 2013-2015 Intel Corporation. All rights reserved.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of version 2 of the GNU General Public License as
6  * published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  */
13 #ifndef __NFIT_TEST_H__
14 #define __NFIT_TEST_H__
15 #include <linux/list.h>
16 #include <linux/uuid.h>
17 #include <linux/ioport.h>
18 #include <linux/spinlock_types.h>
19 
20 struct nfit_test_request {
21 	struct list_head list;
22 	struct resource res;
23 };
24 
25 struct nfit_test_resource {
26 	struct list_head requests;
27 	struct list_head list;
28 	struct resource res;
29 	struct device *dev;
30 	spinlock_t lock;
31 	int req_count;
32 	void *buf;
33 };
34 
35 #define ND_TRANSLATE_SPA_STATUS_INVALID_SPA  2
36 #define NFIT_ARS_INJECT_INVALID 2
37 
38 enum err_inj_options {
39 	ND_ARS_ERR_INJ_OPT_NOTIFY = 0,
40 };
41 
42 /* nfit commands */
43 enum nfit_cmd_num {
44 	NFIT_CMD_TRANSLATE_SPA = 5,
45 	NFIT_CMD_ARS_INJECT_SET = 7,
46 	NFIT_CMD_ARS_INJECT_CLEAR = 8,
47 	NFIT_CMD_ARS_INJECT_GET = 9,
48 };
49 
50 struct nd_cmd_translate_spa {
51 	__u64 spa;
52 	__u32 status;
53 	__u8  flags;
54 	__u8  _reserved[3];
55 	__u64 translate_length;
56 	__u32 num_nvdimms;
57 	struct nd_nvdimm_device {
58 		__u32 nfit_device_handle;
59 		__u32 _reserved;
60 		__u64 dpa;
61 	} __packed devices[0];
62 
63 } __packed;
64 
65 struct nd_cmd_ars_err_inj {
66 	__u64 err_inj_spa_range_base;
67 	__u64 err_inj_spa_range_length;
68 	__u8  err_inj_options;
69 	__u32 status;
70 } __packed;
71 
72 struct nd_cmd_ars_err_inj_clr {
73 	__u64 err_inj_clr_spa_range_base;
74 	__u64 err_inj_clr_spa_range_length;
75 	__u32 status;
76 } __packed;
77 
78 struct nd_cmd_ars_err_inj_stat {
79 	__u32 status;
80 	__u32 inj_err_rec_count;
81 	struct nd_error_stat_query_record {
82 		__u64 err_inj_stat_spa_range_base;
83 		__u64 err_inj_stat_spa_range_length;
84 	} __packed record[0];
85 } __packed;
86 
87 union acpi_object;
88 typedef void *acpi_handle;
89 
90 typedef struct nfit_test_resource *(*nfit_test_lookup_fn)(resource_size_t);
91 typedef union acpi_object *(*nfit_test_evaluate_dsm_fn)(acpi_handle handle,
92 		 const guid_t *guid, u64 rev, u64 func,
93 		 union acpi_object *argv4);
94 void __iomem *__wrap_ioremap_nocache(resource_size_t offset,
95 		unsigned long size);
96 void __wrap_iounmap(volatile void __iomem *addr);
97 void nfit_test_setup(nfit_test_lookup_fn lookup,
98 		nfit_test_evaluate_dsm_fn evaluate);
99 void nfit_test_teardown(void);
100 struct nfit_test_resource *get_nfit_res(resource_size_t resource);
101 #endif
102