1*f2989396SDave Jiang // SPDX-License-Identifier: GPL-2.0 2*f2989396SDave Jiang /* Copyright(c) 2018 Intel Corporation. All rights reserved. */ 3*f2989396SDave Jiang #include <linux/libnvdimm.h> 4*f2989396SDave Jiang #include <linux/ndctl.h> 5*f2989396SDave Jiang #include <linux/acpi.h> 6*f2989396SDave Jiang #include "intel.h" 7*f2989396SDave Jiang #include "nfit.h" 8*f2989396SDave Jiang 9*f2989396SDave Jiang static enum nvdimm_security_state intel_security_state(struct nvdimm *nvdimm) 10*f2989396SDave Jiang { 11*f2989396SDave Jiang struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm); 12*f2989396SDave Jiang struct { 13*f2989396SDave Jiang struct nd_cmd_pkg pkg; 14*f2989396SDave Jiang struct nd_intel_get_security_state cmd; 15*f2989396SDave Jiang } nd_cmd = { 16*f2989396SDave Jiang .pkg = { 17*f2989396SDave Jiang .nd_command = NVDIMM_INTEL_GET_SECURITY_STATE, 18*f2989396SDave Jiang .nd_family = NVDIMM_FAMILY_INTEL, 19*f2989396SDave Jiang .nd_size_out = 20*f2989396SDave Jiang sizeof(struct nd_intel_get_security_state), 21*f2989396SDave Jiang .nd_fw_size = 22*f2989396SDave Jiang sizeof(struct nd_intel_get_security_state), 23*f2989396SDave Jiang }, 24*f2989396SDave Jiang }; 25*f2989396SDave Jiang int rc; 26*f2989396SDave Jiang 27*f2989396SDave Jiang if (!test_bit(NVDIMM_INTEL_GET_SECURITY_STATE, &nfit_mem->dsm_mask)) 28*f2989396SDave Jiang return -ENXIO; 29*f2989396SDave Jiang 30*f2989396SDave Jiang rc = nvdimm_ctl(nvdimm, ND_CMD_CALL, &nd_cmd, sizeof(nd_cmd), NULL); 31*f2989396SDave Jiang if (rc < 0) 32*f2989396SDave Jiang return rc; 33*f2989396SDave Jiang if (nd_cmd.cmd.status) 34*f2989396SDave Jiang return -EIO; 35*f2989396SDave Jiang 36*f2989396SDave Jiang /* check and see if security is enabled and locked */ 37*f2989396SDave Jiang if (nd_cmd.cmd.state & ND_INTEL_SEC_STATE_UNSUPPORTED) 38*f2989396SDave Jiang return -ENXIO; 39*f2989396SDave Jiang else if (nd_cmd.cmd.state & ND_INTEL_SEC_STATE_ENABLED) { 40*f2989396SDave Jiang if (nd_cmd.cmd.state & ND_INTEL_SEC_STATE_LOCKED) 41*f2989396SDave Jiang return NVDIMM_SECURITY_LOCKED; 42*f2989396SDave Jiang else if (nd_cmd.cmd.state & ND_INTEL_SEC_STATE_FROZEN || 43*f2989396SDave Jiang nd_cmd.cmd.state & ND_INTEL_SEC_STATE_PLIMIT) 44*f2989396SDave Jiang return NVDIMM_SECURITY_FROZEN; 45*f2989396SDave Jiang else 46*f2989396SDave Jiang return NVDIMM_SECURITY_UNLOCKED; 47*f2989396SDave Jiang } 48*f2989396SDave Jiang return NVDIMM_SECURITY_DISABLED; 49*f2989396SDave Jiang } 50*f2989396SDave Jiang 51*f2989396SDave Jiang static const struct nvdimm_security_ops __intel_security_ops = { 52*f2989396SDave Jiang .state = intel_security_state, 53*f2989396SDave Jiang }; 54*f2989396SDave Jiang const struct nvdimm_security_ops *intel_security_ops = &__intel_security_ops; 55