0001
0002
0003
0004
0005
0006
0007
0008
0009 #define KMSG_COMPONENT "scm_block"
0010 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
0011
0012 #include <linux/module.h>
0013 #include <linux/slab.h>
0014 #include <asm/eadm.h>
0015 #include "scm_blk.h"
0016
0017 static void scm_notify(struct scm_device *scmdev, enum scm_event event)
0018 {
0019 struct scm_blk_dev *bdev = dev_get_drvdata(&scmdev->dev);
0020
0021 switch (event) {
0022 case SCM_CHANGE:
0023 pr_info("%lx: The capabilities of the SCM increment changed\n",
0024 (unsigned long) scmdev->address);
0025 SCM_LOG(2, "State changed");
0026 SCM_LOG_STATE(2, scmdev);
0027 break;
0028 case SCM_AVAIL:
0029 SCM_LOG(2, "Increment available");
0030 SCM_LOG_STATE(2, scmdev);
0031 scm_blk_set_available(bdev);
0032 break;
0033 }
0034 }
0035
0036 static int scm_probe(struct scm_device *scmdev)
0037 {
0038 struct scm_blk_dev *bdev;
0039 int ret;
0040
0041 SCM_LOG(2, "probe");
0042 SCM_LOG_STATE(2, scmdev);
0043
0044 if (scmdev->attrs.oper_state != OP_STATE_GOOD)
0045 return -EINVAL;
0046
0047 bdev = kzalloc(sizeof(*bdev), GFP_KERNEL);
0048 if (!bdev)
0049 return -ENOMEM;
0050
0051 dev_set_drvdata(&scmdev->dev, bdev);
0052 ret = scm_blk_dev_setup(bdev, scmdev);
0053 if (ret) {
0054 dev_set_drvdata(&scmdev->dev, NULL);
0055 kfree(bdev);
0056 goto out;
0057 }
0058
0059 out:
0060 return ret;
0061 }
0062
0063 static void scm_remove(struct scm_device *scmdev)
0064 {
0065 struct scm_blk_dev *bdev = dev_get_drvdata(&scmdev->dev);
0066
0067 scm_blk_dev_cleanup(bdev);
0068 dev_set_drvdata(&scmdev->dev, NULL);
0069 kfree(bdev);
0070 }
0071
0072 static struct scm_driver scm_drv = {
0073 .drv = {
0074 .name = "scm_block",
0075 .owner = THIS_MODULE,
0076 },
0077 .notify = scm_notify,
0078 .probe = scm_probe,
0079 .remove = scm_remove,
0080 .handler = scm_blk_irq,
0081 };
0082
0083 int __init scm_drv_init(void)
0084 {
0085 return scm_driver_register(&scm_drv);
0086 }
0087
0088 void scm_drv_cleanup(void)
0089 {
0090 scm_driver_unregister(&scm_drv);
0091 }