Commit 231bf117 authored by Dan Williams's avatar Dan Williams

tools/testing/nvdimm: unit test for acpi_nvdimm_notify()

Trigger an nmemX/nfit/flags attribute to fire an event whenever a
smart-threshold DSM is received.
Reviewed-by: default avatarVishal Verma <vishal.l.verma@intel.com>
Acked-by: default avatarRafael J. Wysocki <rafael@kernel.org>
Signed-off-by: default avatarDan Williams <dan.j.williams@intel.com>
parent ba9c8dd3
...@@ -1248,7 +1248,7 @@ static struct nvdimm *acpi_nfit_dimm_by_handle(struct acpi_nfit_desc *acpi_desc, ...@@ -1248,7 +1248,7 @@ static struct nvdimm *acpi_nfit_dimm_by_handle(struct acpi_nfit_desc *acpi_desc,
return NULL; return NULL;
} }
static void __acpi_nvdimm_notify(struct device *dev, u32 event) void __acpi_nvdimm_notify(struct device *dev, u32 event)
{ {
struct nfit_mem *nfit_mem; struct nfit_mem *nfit_mem;
struct acpi_nfit_desc *acpi_desc; struct acpi_nfit_desc *acpi_desc;
...@@ -1274,6 +1274,7 @@ static void __acpi_nvdimm_notify(struct device *dev, u32 event) ...@@ -1274,6 +1274,7 @@ static void __acpi_nvdimm_notify(struct device *dev, u32 event)
if (nfit_mem && nfit_mem->flags_attr) if (nfit_mem && nfit_mem->flags_attr)
sysfs_notify_dirent(nfit_mem->flags_attr); sysfs_notify_dirent(nfit_mem->flags_attr);
} }
EXPORT_SYMBOL_GPL(__acpi_nvdimm_notify);
static void acpi_nvdimm_notify(acpi_handle handle, u32 event, void *data) static void acpi_nvdimm_notify(acpi_handle handle, u32 event, void *data)
{ {
...@@ -1365,12 +1366,15 @@ static void shutdown_dimm_notify(void *data) ...@@ -1365,12 +1366,15 @@ static void shutdown_dimm_notify(void *data)
* notifications. * notifications.
*/ */
list_for_each_entry(nfit_mem, &acpi_desc->dimms, list) { list_for_each_entry(nfit_mem, &acpi_desc->dimms, list) {
struct acpi_device *adev_dimm = nfit_mem->adev;
if (nfit_mem->flags_attr) { if (nfit_mem->flags_attr) {
sysfs_put(nfit_mem->flags_attr); sysfs_put(nfit_mem->flags_attr);
nfit_mem->flags_attr = NULL; nfit_mem->flags_attr = NULL;
} }
acpi_remove_notify_handler(nfit_mem->adev->handle, if (adev_dimm)
ACPI_DEVICE_NOTIFY, acpi_nvdimm_notify); acpi_remove_notify_handler(adev_dimm->handle,
ACPI_DEVICE_NOTIFY, acpi_nvdimm_notify);
} }
mutex_unlock(&acpi_desc->init_mutex); mutex_unlock(&acpi_desc->init_mutex);
} }
......
...@@ -233,5 +233,6 @@ static inline struct acpi_nfit_desc *to_acpi_desc( ...@@ -233,5 +233,6 @@ static inline struct acpi_nfit_desc *to_acpi_desc(
const u8 *to_nfit_uuid(enum nfit_uuids id); const u8 *to_nfit_uuid(enum nfit_uuids id);
int acpi_nfit_init(struct acpi_nfit_desc *acpi_desc, void *nfit, acpi_size sz); int acpi_nfit_init(struct acpi_nfit_desc *acpi_desc, void *nfit, acpi_size sz);
void __acpi_nfit_notify(struct device *dev, acpi_handle handle, u32 event); void __acpi_nfit_notify(struct device *dev, acpi_handle handle, u32 event);
void __acpi_nvdimm_notify(struct device *dev, u32 event);
void acpi_nfit_desc_init(struct acpi_nfit_desc *acpi_desc, struct device *dev); void acpi_nfit_desc_init(struct acpi_nfit_desc *acpi_desc, struct device *dev);
#endif /* __NFIT_H__ */ #endif /* __NFIT_H__ */
...@@ -161,6 +161,7 @@ struct nfit_test { ...@@ -161,6 +161,7 @@ struct nfit_test {
unsigned long deadline; unsigned long deadline;
spinlock_t lock; spinlock_t lock;
} ars_state; } ars_state;
struct device *dimm_dev[NUM_DCR];
}; };
static struct nfit_test *to_nfit_test(struct device *dev) static struct nfit_test *to_nfit_test(struct device *dev)
...@@ -430,6 +431,9 @@ static int nfit_test_ctl(struct nvdimm_bus_descriptor *nd_desc, ...@@ -430,6 +431,9 @@ static int nfit_test_ctl(struct nvdimm_bus_descriptor *nd_desc,
break; break;
case ND_CMD_SMART_THRESHOLD: case ND_CMD_SMART_THRESHOLD:
rc = nfit_test_cmd_smart_threshold(buf, buf_len); rc = nfit_test_cmd_smart_threshold(buf, buf_len);
device_lock(&t->pdev.dev);
__acpi_nvdimm_notify(t->dimm_dev[i], 0x81);
device_unlock(&t->pdev.dev);
break; break;
default: default:
return -ENOTTY; return -ENOTTY;
...@@ -566,6 +570,18 @@ static int ars_state_init(struct device *dev, struct ars_state *ars_state) ...@@ -566,6 +570,18 @@ static int ars_state_init(struct device *dev, struct ars_state *ars_state)
return 0; return 0;
} }
static void put_dimms(void *data)
{
struct device **dimm_dev = data;
int i;
for (i = 0; i < NUM_DCR; i++)
if (dimm_dev[i])
device_unregister(dimm_dev[i]);
}
static struct class *nfit_test_dimm;
static int nfit_test0_alloc(struct nfit_test *t) static int nfit_test0_alloc(struct nfit_test *t)
{ {
size_t nfit_size = sizeof(struct acpi_nfit_system_address) * NUM_SPA size_t nfit_size = sizeof(struct acpi_nfit_system_address) * NUM_SPA
...@@ -621,6 +637,15 @@ static int nfit_test0_alloc(struct nfit_test *t) ...@@ -621,6 +637,15 @@ static int nfit_test0_alloc(struct nfit_test *t)
if (!t->_fit) if (!t->_fit)
return -ENOMEM; return -ENOMEM;
if (devm_add_action_or_reset(&t->pdev.dev, put_dimms, t->dimm_dev))
return -ENOMEM;
for (i = 0; i < NUM_DCR; i++) {
t->dimm_dev[i] = device_create(nfit_test_dimm, &t->pdev.dev, 0,
NULL, "test_dimm%d", i);
if (!t->dimm_dev[i])
return -ENOMEM;
}
return ars_state_init(&t->pdev.dev, &t->ars_state); return ars_state_init(&t->pdev.dev, &t->ars_state);
} }
...@@ -1414,6 +1439,7 @@ static int nfit_test_probe(struct platform_device *pdev) ...@@ -1414,6 +1439,7 @@ static int nfit_test_probe(struct platform_device *pdev)
struct acpi_nfit_desc *acpi_desc; struct acpi_nfit_desc *acpi_desc;
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct nfit_test *nfit_test; struct nfit_test *nfit_test;
struct nfit_mem *nfit_mem;
union acpi_object *obj; union acpi_object *obj;
int rc; int rc;
...@@ -1493,6 +1519,20 @@ static int nfit_test_probe(struct platform_device *pdev) ...@@ -1493,6 +1519,20 @@ static int nfit_test_probe(struct platform_device *pdev)
obj->buffer.pointer = nfit_test->nfit_buf; obj->buffer.pointer = nfit_test->nfit_buf;
*(nfit_test->_fit) = obj; *(nfit_test->_fit) = obj;
__acpi_nfit_notify(&pdev->dev, nfit_test, 0x80); __acpi_nfit_notify(&pdev->dev, nfit_test, 0x80);
/* associate dimm devices with nfit_mem data for notification testing */
mutex_lock(&acpi_desc->init_mutex);
list_for_each_entry(nfit_mem, &acpi_desc->dimms, list) {
u32 nfit_handle = __to_nfit_memdev(nfit_mem)->device_handle;
int i;
for (i = 0; i < NUM_DCR; i++)
if (nfit_handle == handle[i])
dev_set_drvdata(nfit_test->dimm_dev[i],
nfit_mem);
}
mutex_unlock(&acpi_desc->init_mutex);
return 0; return 0;
} }
...@@ -1526,6 +1566,10 @@ static __init int nfit_test_init(void) ...@@ -1526,6 +1566,10 @@ static __init int nfit_test_init(void)
{ {
int rc, i; int rc, i;
nfit_test_dimm = class_create(THIS_MODULE, "nfit_test_dimm");
if (IS_ERR(nfit_test_dimm))
return PTR_ERR(nfit_test_dimm);
nfit_test_setup(nfit_test_lookup); nfit_test_setup(nfit_test_lookup);
for (i = 0; i < NUM_NFITS; i++) { for (i = 0; i < NUM_NFITS; i++) {
...@@ -1592,6 +1636,7 @@ static __exit void nfit_test_exit(void) ...@@ -1592,6 +1636,7 @@ static __exit void nfit_test_exit(void)
for (i = 0; i < NUM_NFITS; i++) for (i = 0; i < NUM_NFITS; i++)
platform_device_unregister(&instances[i]->pdev); platform_device_unregister(&instances[i]->pdev);
nfit_test_teardown(); nfit_test_teardown();
class_destroy(nfit_test_dimm);
} }
module_init(nfit_test_init); module_init(nfit_test_init);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment