sysctl.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /* sysctl.c: implementation of /proc/sys files relating to FRV specifically
  2. *
  3. * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #include <linux/slab.h>
  12. #include <linux/sysctl.h>
  13. #include <linux/proc_fs.h>
  14. #include <linux/init.h>
  15. #include <asm/uaccess.h>
  16. static const char frv_cache_wback[] = "wback";
  17. static const char frv_cache_wthru[] = "wthru";
  18. static void frv_change_dcache_mode(unsigned long newmode)
  19. {
  20. unsigned long flags, hsr0;
  21. local_irq_save(flags);
  22. hsr0 = __get_HSR(0);
  23. hsr0 &= ~HSR0_DCE;
  24. __set_HSR(0, hsr0);
  25. asm volatile(" dcef @(gr0,gr0),#1 \n"
  26. " membar \n"
  27. : : : "memory"
  28. );
  29. hsr0 = (hsr0 & ~HSR0_CBM) | newmode;
  30. __set_HSR(0, hsr0);
  31. hsr0 |= HSR0_DCE;
  32. __set_HSR(0, hsr0);
  33. local_irq_restore(flags);
  34. //printk("HSR0 now %08lx\n", hsr0);
  35. }
  36. /*****************************************************************************/
  37. /*
  38. * handle requests to dynamically switch the write caching mode delivered by /proc
  39. */
  40. static int procctl_frv_cachemode(ctl_table *table, int write, struct file *filp,
  41. void __user *buffer, size_t *lenp, loff_t *ppos)
  42. {
  43. unsigned long hsr0;
  44. char buff[8];
  45. int len;
  46. len = *lenp;
  47. if (write) {
  48. /* potential state change */
  49. if (len <= 1 || len > sizeof(buff) - 1)
  50. return -EINVAL;
  51. if (copy_from_user(buff, buffer, len) != 0)
  52. return -EFAULT;
  53. if (buff[len - 1] == '\n')
  54. buff[len - 1] = '\0';
  55. else
  56. buff[len] = '\0';
  57. if (strcmp(buff, frv_cache_wback) == 0) {
  58. /* switch dcache into write-back mode */
  59. frv_change_dcache_mode(HSR0_CBM_COPY_BACK);
  60. return 0;
  61. }
  62. if (strcmp(buff, frv_cache_wthru) == 0) {
  63. /* switch dcache into write-through mode */
  64. frv_change_dcache_mode(HSR0_CBM_WRITE_THRU);
  65. return 0;
  66. }
  67. return -EINVAL;
  68. }
  69. /* read the state */
  70. if (filp->f_pos > 0) {
  71. *lenp = 0;
  72. return 0;
  73. }
  74. hsr0 = __get_HSR(0);
  75. switch (hsr0 & HSR0_CBM) {
  76. case HSR0_CBM_WRITE_THRU:
  77. memcpy(buff, frv_cache_wthru, sizeof(frv_cache_wthru) - 1);
  78. buff[sizeof(frv_cache_wthru) - 1] = '\n';
  79. len = sizeof(frv_cache_wthru);
  80. break;
  81. default:
  82. memcpy(buff, frv_cache_wback, sizeof(frv_cache_wback) - 1);
  83. buff[sizeof(frv_cache_wback) - 1] = '\n';
  84. len = sizeof(frv_cache_wback);
  85. break;
  86. }
  87. if (len > *lenp)
  88. len = *lenp;
  89. if (copy_to_user(buffer, buff, len) != 0)
  90. return -EFAULT;
  91. *lenp = len;
  92. filp->f_pos = len;
  93. return 0;
  94. } /* end procctl_frv_cachemode() */
  95. /*****************************************************************************/
  96. /*
  97. * permit the mm_struct the nominated process is using have its MMU context ID pinned
  98. */
  99. #ifdef CONFIG_MMU
  100. static int procctl_frv_pin_cxnr(ctl_table *table, int write, struct file *filp,
  101. void __user *buffer, size_t *lenp, loff_t *ppos)
  102. {
  103. pid_t pid;
  104. char buff[16], *p;
  105. int len;
  106. len = *lenp;
  107. if (write) {
  108. /* potential state change */
  109. if (len <= 1 || len > sizeof(buff) - 1)
  110. return -EINVAL;
  111. if (copy_from_user(buff, buffer, len) != 0)
  112. return -EFAULT;
  113. if (buff[len - 1] == '\n')
  114. buff[len - 1] = '\0';
  115. else
  116. buff[len] = '\0';
  117. pid = simple_strtoul(buff, &p, 10);
  118. if (*p)
  119. return -EINVAL;
  120. return cxn_pin_by_pid(pid);
  121. }
  122. /* read the currently pinned CXN */
  123. if (filp->f_pos > 0) {
  124. *lenp = 0;
  125. return 0;
  126. }
  127. len = snprintf(buff, sizeof(buff), "%d\n", cxn_pinned);
  128. if (len > *lenp)
  129. len = *lenp;
  130. if (copy_to_user(buffer, buff, len) != 0)
  131. return -EFAULT;
  132. *lenp = len;
  133. filp->f_pos = len;
  134. return 0;
  135. } /* end procctl_frv_pin_cxnr() */
  136. #endif
  137. /*
  138. * FR-V specific sysctls
  139. */
  140. static struct ctl_table frv_table[] =
  141. {
  142. { 1, "cache-mode", NULL, 0, 0644, NULL, &procctl_frv_cachemode },
  143. #ifdef CONFIG_MMU
  144. { 2, "pin-cxnr", NULL, 0, 0644, NULL, &procctl_frv_pin_cxnr },
  145. #endif
  146. { 0 }
  147. };
  148. /*
  149. * Use a temporary sysctl number. Horrid, but will be cleaned up in 2.6
  150. * when all the PM interfaces exist nicely.
  151. */
  152. #define CTL_FRV 9898
  153. static struct ctl_table frv_dir_table[] =
  154. {
  155. {CTL_FRV, "frv", NULL, 0, 0555, frv_table},
  156. {0}
  157. };
  158. /*
  159. * Initialize power interface
  160. */
  161. static int __init frv_sysctl_init(void)
  162. {
  163. register_sysctl_table(frv_dir_table, 1);
  164. return 0;
  165. }
  166. __initcall(frv_sysctl_init);