vpe-cmp.c 3.6 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. kfree(cd);
  62. }
  63. static struct class vpe_class = {
  64. .name = "vpe",
  65. .owner = THIS_MODULE,
  66. .dev_release = vpe_device_release,
  67. .dev_groups = vpe_groups,
  68. };
  69. static struct device vpe_device;
  70. int __init vpe_module_init(void)
  71. {
  72. struct vpe *v = NULL;
  73. struct tc *t;
  74. int err;
  75. if (!cpu_has_mipsmt) {
  76. pr_warn("VPE loader: not a MIPS MT capable processor\n");
  77. return -ENODEV;
  78. }
  79. if (num_possible_cpus() - aprp_cpu_index() < 1) {
  80. pr_warn("No VPEs reserved for AP/SP, not initialize VPE loader\n"
  81. "Pass maxcpus=<n> argument as kernel argument\n");
  82. return -ENODEV;
  83. }
  84. major = register_chrdev(0, VPE_MODULE_NAME, &vpe_fops);
  85. if (major < 0) {
  86. pr_warn("VPE loader: unable to register character device\n");
  87. return major;
  88. }
  89. err = class_register(&vpe_class);
  90. if (err) {
  91. pr_err("vpe_class registration failed\n");
  92. goto out_chrdev;
  93. }
  94. device_initialize(&vpe_device);
  95. vpe_device.class = &vpe_class,
  96. vpe_device.parent = NULL,
  97. dev_set_name(&vpe_device, "vpe_sp");
  98. vpe_device.devt = MKDEV(major, VPE_MODULE_MINOR);
  99. err = device_add(&vpe_device);
  100. if (err) {
  101. pr_err("Adding vpe_device failed\n");
  102. goto out_class;
  103. }
  104. t = alloc_tc(aprp_cpu_index());
  105. if (!t) {
  106. pr_warn("VPE: unable to allocate TC\n");
  107. err = -ENOMEM;
  108. goto out_dev;
  109. }
  110. /* VPE */
  111. v = alloc_vpe(aprp_cpu_index());
  112. if (v == NULL) {
  113. pr_warn("VPE: unable to allocate VPE\n");
  114. kfree(t);
  115. err = -ENOMEM;
  116. goto out_dev;
  117. }
  118. v->ntcs = 1;
  119. /* add the tc to the list of this vpe's tc's. */
  120. list_add(&t->tc, &v->tc);
  121. /* TC */
  122. t->pvpe = v; /* set the parent vpe */
  123. return 0;
  124. out_dev:
  125. device_del(&vpe_device);
  126. out_class:
  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_del(&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. }