gsgx_main.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * (C) Copyright 2015 Intel Corporation
  3. * Author: Chia-Che Tsai <chiache-che.tsai@intel.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; version 2
  8. * of the License.
  9. */
  10. #include <linux/module.h>
  11. #include <linux/kernel.h>
  12. #include <linux/version.h>
  13. #include <linux/fs.h>
  14. #include <linux/miscdevice.h>
  15. #include "gsgx.h"
  16. #define DRV_DESCRIPTION "Graphene SGX Driver"
  17. #define DRV_VERSION "0.10-" SDK_DRIVER_VERSION_STRING
  18. MODULE_DESCRIPTION(DRV_DESCRIPTION);
  19. MODULE_AUTHOR("Chia-Che Tsai <chia-che.tsai@intel.com>");
  20. MODULE_VERSION(DRV_VERSION);
  21. static const struct file_operations gsgx_fops = {
  22. .owner = THIS_MODULE,
  23. .open = gsgx_open,
  24. #if SDK_DRIVER_VERSION < KERNEL_VERSION(1, 8, 0)
  25. .unlocked_ioctl = gsgx_ioctl,
  26. #ifdef CONFIG_COMPAT
  27. .compat_ioctl = gsgx_ioctl,
  28. #endif
  29. .mmap = gsgx_mmap,
  30. .get_unmapped_area = gsgx_get_unmapped_area,
  31. #endif
  32. };
  33. static struct miscdevice gsgx_dev = {
  34. .minor = GSGX_MINOR,
  35. .name = "gsgx",
  36. .fops = &gsgx_fops,
  37. .mode = S_IRUGO | S_IWUGO,
  38. };
  39. static int gsgx_setup(void)
  40. {
  41. int ret;
  42. ret = misc_register(&gsgx_dev);
  43. if (ret) {
  44. pr_err("gsgx: misc_register() failed\n");
  45. gsgx_dev.this_device = NULL;
  46. return ret;
  47. }
  48. #if SDK_DRIVER_VERSION < KERNEL_VERSION(1, 8, 0)
  49. isgx_dev = filp_open("/dev/isgx", O_RDONLY, 0);
  50. if (!isgx_dev) {
  51. return PTR_ERR(isgx_dev);
  52. }
  53. ret = gsgx_lookup_ksyms();
  54. if (ret) {
  55. pr_err("gsgx: lookup kernel symbols failed\n");
  56. return ret;
  57. }
  58. #endif
  59. return 0;
  60. }
  61. static void gsgx_teardown(void)
  62. {
  63. if (gsgx_dev.this_device)
  64. misc_deregister(&gsgx_dev);
  65. #if SDK_DRIVER_VERSION < KERNEL_VERSION(1, 8, 0)
  66. if (isgx_dev)
  67. filp_close(isgx_dev, NULL);
  68. #endif
  69. }
  70. static int __init gsgx_init(void)
  71. {
  72. int ret;
  73. pr_info("gsgx: " DRV_DESCRIPTION " v" DRV_VERSION "\n");
  74. ret = gsgx_setup();
  75. if (ret) {
  76. gsgx_teardown();
  77. return ret;
  78. }
  79. return 0;
  80. }
  81. static void __exit gsgx_exit(void)
  82. {
  83. gsgx_teardown();
  84. }
  85. module_init(gsgx_init);
  86. module_exit(gsgx_exit);
  87. MODULE_LICENSE("GPL");