vpe-cmp.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 2004, 2005 MIPS Technologies, Inc. All rights reserved.
  7. * Copyright (C) 2013 Imagination Technologies Ltd.
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/device.h>
  11. #include <linux/fs.h>
  12. #include <linux/slab.h>
  13. #include <linux/export.h>
  14. #include <asm/vpe.h>
  15. static int major;
  16. void cleanup_tc(struct tc *tc)
  17. {
  18. }
  19. static ssize_t store_kill(struct device *dev, struct device_attribute *attr,
  20. const char *buf, size_t len)
  21. {
  22. struct vpe *vpe = get_vpe(aprp_cpu_index());
  23. struct vpe_notifications *notifier;
  24. list_for_each_entry(notifier, &vpe->notify, list)
  25. notifier->stop(aprp_cpu_index());
  26. release_progmem(vpe->load_addr);
  27. vpe->state = VPE_STATE_UNUSED;
  28. return len;
  29. }
  30. static DEVICE_ATTR(kill, S_IWUSR, NULL, store_kill);
  31. static ssize_t ntcs_show(struct device *cd, struct device_attribute *attr,
  32. char *buf)
  33. {
  34. struct vpe *vpe = get_vpe(aprp_cpu_index());
  35. return sprintf(buf, "%d\n", vpe->ntcs);
  36. }
  37. static ssize_t ntcs_store(struct device *dev, struct device_attribute *attr,
  38. const char *buf, size_t len)
  39. {
  40. struct vpe *vpe = get_vpe(aprp_cpu_index());
  41. unsigned long new;
  42. int ret;
  43. ret = kstrtoul(buf, 0, &new);
  44. if (ret < 0)
  45. return ret;
  46. /* APRP can only reserve one TC in a VPE and no more. */
  47. if (new != 1)
  48. return -EINVAL;
  49. vpe->ntcs = new;
  50. return len;
  51. }
  52. static DEVICE_ATTR_RW(ntcs);
  53. static struct attribute *vpe_attrs[] = {
  54. &dev_attr_kill.attr,
  55. &dev_attr_ntcs.attr,
  56. NULL,
  57. };
  58. ATTRIBUTE_GROUPS(vpe);
  59. static void vpe_device_release(struct device *cd)
  60. {
  61. }
  62. static struct class vpe_class = {
  63. .name = "vpe",
  64. .owner = THIS_MODULE,
  65. .dev_release = vpe_device_release,
  66. .dev_groups = vpe_groups,
  67. };
  68. static struct device vpe_device;
  69. int __init vpe_module_init(void)
  70. {
  71. struct vpe *v = NULL;
  72. struct tc *t;
  73. int err;
  74. if (!cpu_has_mipsmt) {
  75. pr_warn("VPE loader: not a MIPS MT capable processor\n");
  76. return -ENODEV;
  77. }
  78. if (num_possible_cpus() - aprp_cpu_index() < 1) {
  79. pr_warn("No VPEs reserved for AP/SP, not initialize VPE loader\n"
  80. "Pass maxcpus=<n> argument as kernel argument\n");
  81. return -ENODEV;
  82. }
  83. major = register_chrdev(0, VPE_MODULE_NAME, &vpe_fops);
  84. if (major < 0) {
  85. pr_warn("VPE loader: unable to register character device\n");
  86. return major;
  87. }
  88. err = class_register(&vpe_class);
  89. if (err) {
  90. pr_err("vpe_class registration failed\n");
  91. goto out_chrdev;
  92. }
  93. device_initialize(&vpe_device);
  94. vpe_device.class = &vpe_class;
  95. vpe_device.parent = NULL;
  96. dev_set_name(&vpe_device, "vpe_sp");
  97. vpe_device.devt = MKDEV(major, VPE_MODULE_MINOR);
  98. err = device_add(&vpe_device);
  99. if (err) {
  100. pr_err("Adding vpe_device failed\n");
  101. goto out_class;
  102. }
  103. t = alloc_tc(aprp_cpu_index());
  104. if (!t) {
  105. pr_warn("VPE: unable to allocate TC\n");
  106. err = -ENOMEM;
  107. goto out_dev;
  108. }
  109. /* VPE */
  110. v = alloc_vpe(aprp_cpu_index());
  111. if (v == NULL) {
  112. pr_warn("VPE: unable to allocate VPE\n");
  113. kfree(t);
  114. err = -ENOMEM;
  115. goto out_dev;
  116. }
  117. v->ntcs = 1;
  118. /* add the tc to the list of this vpe's tc's. */
  119. list_add(&t->tc, &v->tc);
  120. /* TC */
  121. t->pvpe = v; /* set the parent vpe */
  122. return 0;
  123. out_dev:
  124. device_del(&vpe_device);
  125. out_class:
  126. put_device(&vpe_device);
  127. class_unregister(&vpe_class);
  128. out_chrdev:
  129. unregister_chrdev(major, VPE_MODULE_NAME);
  130. return err;
  131. }
  132. void __exit vpe_module_exit(void)
  133. {
  134. struct vpe *v, *n;
  135. device_unregister(&vpe_device);
  136. class_unregister(&vpe_class);
  137. unregister_chrdev(major, VPE_MODULE_NAME);
  138. /* No locking needed here */
  139. list_for_each_entry_safe(v, n, &vpecontrol.vpe_list, list)
  140. if (v->state != VPE_STATE_UNUSED)
  141. release_vpe(v);
  142. }