scm_drv.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Device driver for s390 storage class memory.
  3. *
  4. * Copyright IBM Corp. 2012
  5. * Author(s): Sebastian Ott <sebott@linux.vnet.ibm.com>
  6. */
  7. #define KMSG_COMPONENT "scm_block"
  8. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  9. #include <linux/module.h>
  10. #include <linux/spinlock.h>
  11. #include <linux/slab.h>
  12. #include <asm/eadm.h>
  13. #include "scm_blk.h"
  14. static void notify(struct scm_device *scmdev)
  15. {
  16. pr_info("%lu: The capabilities of the SCM increment changed\n",
  17. (unsigned long) scmdev->address);
  18. SCM_LOG(2, "State changed");
  19. SCM_LOG_STATE(2, scmdev);
  20. }
  21. static int scm_probe(struct scm_device *scmdev)
  22. {
  23. struct scm_blk_dev *bdev;
  24. int ret;
  25. SCM_LOG(2, "probe");
  26. SCM_LOG_STATE(2, scmdev);
  27. if (scmdev->attrs.oper_state != OP_STATE_GOOD)
  28. return -EINVAL;
  29. bdev = kzalloc(sizeof(*bdev), GFP_KERNEL);
  30. if (!bdev)
  31. return -ENOMEM;
  32. spin_lock_irq(&scmdev->lock);
  33. dev_set_drvdata(&scmdev->dev, bdev);
  34. spin_unlock_irq(&scmdev->lock);
  35. ret = scm_blk_dev_setup(bdev, scmdev);
  36. if (ret) {
  37. spin_lock_irq(&scmdev->lock);
  38. dev_set_drvdata(&scmdev->dev, NULL);
  39. spin_unlock_irq(&scmdev->lock);
  40. kfree(bdev);
  41. goto out;
  42. }
  43. out:
  44. return ret;
  45. }
  46. static int scm_remove(struct scm_device *scmdev)
  47. {
  48. struct scm_blk_dev *bdev;
  49. spin_lock_irq(&scmdev->lock);
  50. bdev = dev_get_drvdata(&scmdev->dev);
  51. dev_set_drvdata(&scmdev->dev, NULL);
  52. spin_unlock_irq(&scmdev->lock);
  53. scm_blk_dev_cleanup(bdev);
  54. kfree(bdev);
  55. return 0;
  56. }
  57. static struct scm_driver scm_drv = {
  58. .drv = {
  59. .name = "scm_block",
  60. .owner = THIS_MODULE,
  61. },
  62. .notify = notify,
  63. .probe = scm_probe,
  64. .remove = scm_remove,
  65. .handler = scm_blk_irq,
  66. };
  67. int __init scm_drv_init(void)
  68. {
  69. return scm_driver_register(&scm_drv);
  70. }
  71. void scm_drv_cleanup(void)
  72. {
  73. scm_driver_unregister(&scm_drv);
  74. }