linux/tools/testing/nvdimm/dimm_devs.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0
   2/* Copyright Intel Corp. 2018 */
   3#include <linux/init.h>
   4#include <linux/module.h>
   5#include <linux/moduleparam.h>
   6#include <linux/nd.h>
   7#include "pmem.h"
   8#include "pfn.h"
   9#include "nd.h"
  10#include "nd-core.h"
  11
  12ssize_t security_show(struct device *dev,
  13                struct device_attribute *attr, char *buf)
  14{
  15        struct nvdimm *nvdimm = to_nvdimm(dev);
  16
  17        /*
  18         * For the test version we need to poll the "hardware" in order
  19         * to get the updated status for unlock testing.
  20         */
  21        nvdimm->sec.state = nvdimm_security_state(nvdimm, NVDIMM_USER);
  22        nvdimm->sec.ext_state = nvdimm_security_state(nvdimm, NVDIMM_MASTER);
  23
  24        switch (nvdimm->sec.state) {
  25        case NVDIMM_SECURITY_DISABLED:
  26                return sprintf(buf, "disabled\n");
  27        case NVDIMM_SECURITY_UNLOCKED:
  28                return sprintf(buf, "unlocked\n");
  29        case NVDIMM_SECURITY_LOCKED:
  30                return sprintf(buf, "locked\n");
  31        case NVDIMM_SECURITY_FROZEN:
  32                return sprintf(buf, "frozen\n");
  33        case NVDIMM_SECURITY_OVERWRITE:
  34                return sprintf(buf, "overwrite\n");
  35        default:
  36                return -ENOTTY;
  37        }
  38
  39        return -ENOTTY;
  40}
  41
  42