18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci/* Copyright Intel Corp. 2018 */ 38c2ecf20Sopenharmony_ci#include <linux/init.h> 48c2ecf20Sopenharmony_ci#include <linux/module.h> 58c2ecf20Sopenharmony_ci#include <linux/moduleparam.h> 68c2ecf20Sopenharmony_ci#include <linux/nd.h> 78c2ecf20Sopenharmony_ci#include "pmem.h" 88c2ecf20Sopenharmony_ci#include "pfn.h" 98c2ecf20Sopenharmony_ci#include "nd.h" 108c2ecf20Sopenharmony_ci#include "nd-core.h" 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_cissize_t security_show(struct device *dev, 138c2ecf20Sopenharmony_ci struct device_attribute *attr, char *buf) 148c2ecf20Sopenharmony_ci{ 158c2ecf20Sopenharmony_ci struct nvdimm *nvdimm = to_nvdimm(dev); 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci /* 188c2ecf20Sopenharmony_ci * For the test version we need to poll the "hardware" in order 198c2ecf20Sopenharmony_ci * to get the updated status for unlock testing. 208c2ecf20Sopenharmony_ci */ 218c2ecf20Sopenharmony_ci nvdimm->sec.flags = nvdimm_security_flags(nvdimm, NVDIMM_USER); 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci if (test_bit(NVDIMM_SECURITY_DISABLED, &nvdimm->sec.flags)) 248c2ecf20Sopenharmony_ci return sprintf(buf, "disabled\n"); 258c2ecf20Sopenharmony_ci if (test_bit(NVDIMM_SECURITY_UNLOCKED, &nvdimm->sec.flags)) 268c2ecf20Sopenharmony_ci return sprintf(buf, "unlocked\n"); 278c2ecf20Sopenharmony_ci if (test_bit(NVDIMM_SECURITY_LOCKED, &nvdimm->sec.flags)) 288c2ecf20Sopenharmony_ci return sprintf(buf, "locked\n"); 298c2ecf20Sopenharmony_ci return -ENOTTY; 308c2ecf20Sopenharmony_ci} 31