xref: /OK3568_Linux_fs/kernel/tools/testing/nvdimm/dimm_devs.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun /* Copyright Intel Corp. 2018 */
3*4882a593Smuzhiyun #include <linux/init.h>
4*4882a593Smuzhiyun #include <linux/module.h>
5*4882a593Smuzhiyun #include <linux/moduleparam.h>
6*4882a593Smuzhiyun #include <linux/nd.h>
7*4882a593Smuzhiyun #include "pmem.h"
8*4882a593Smuzhiyun #include "pfn.h"
9*4882a593Smuzhiyun #include "nd.h"
10*4882a593Smuzhiyun #include "nd-core.h"
11*4882a593Smuzhiyun 
security_show(struct device * dev,struct device_attribute * attr,char * buf)12*4882a593Smuzhiyun ssize_t security_show(struct device *dev,
13*4882a593Smuzhiyun 		struct device_attribute *attr, char *buf)
14*4882a593Smuzhiyun {
15*4882a593Smuzhiyun 	struct nvdimm *nvdimm = to_nvdimm(dev);
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun 	/*
18*4882a593Smuzhiyun 	 * For the test version we need to poll the "hardware" in order
19*4882a593Smuzhiyun 	 * to get the updated status for unlock testing.
20*4882a593Smuzhiyun 	 */
21*4882a593Smuzhiyun 	nvdimm->sec.flags = nvdimm_security_flags(nvdimm, NVDIMM_USER);
22*4882a593Smuzhiyun 
23*4882a593Smuzhiyun 	if (test_bit(NVDIMM_SECURITY_DISABLED, &nvdimm->sec.flags))
24*4882a593Smuzhiyun 		return sprintf(buf, "disabled\n");
25*4882a593Smuzhiyun 	if (test_bit(NVDIMM_SECURITY_UNLOCKED, &nvdimm->sec.flags))
26*4882a593Smuzhiyun 		return sprintf(buf, "unlocked\n");
27*4882a593Smuzhiyun 	if (test_bit(NVDIMM_SECURITY_LOCKED, &nvdimm->sec.flags))
28*4882a593Smuzhiyun 		return sprintf(buf, "locked\n");
29*4882a593Smuzhiyun 	return -ENOTTY;
30*4882a593Smuzhiyun }
31