sysctl.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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/sysctl.h>
  12. #include <linux/proc_fs.h>
  13. #include <linux/init.h>
  14. #include <asm/uaccess.h>
  15. static const char frv_cache_wback[] = "wback";
  16. static const char frv_cache_wthru[] = "wthru";
  17. static void frv_change_dcache_mode(unsigned long newmode)
  18. {
  19. unsigned long flags, hsr0;
  20. local_irq_save(flags);
  21. hsr0 = __get_HSR(0);
  22. hsr0 &= ~HSR0_DCE;
  23. __set_HSR(0, hsr0);
  24. asm volatile(" dcef @(gr0,gr0),#1 \n"
  25. " membar \n"
  26. : : : "memory"
  27. );
  28. hsr0 = (hsr0 & ~HSR0_CBM) | newmode;
  29. __set_HSR(0, hsr0);
  30. hsr0 |= HSR0_DCE;
  31. __set_HSR(0, hsr0);
  32. local_irq_restore(flags);
  33. //printk("HSR0 now %08lx\n", hsr0);
  34. }
  35. /*****************************************************************************/
  36. /*
  37. * handle requests to dynamically switch the write caching mode delivered by /proc
  38. */
  39. static int procctl_frv_cachemode(ctl_table *table, int write,
  40. void __user *buffer, size_t *lenp,
  41. 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 (*ppos > 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. *ppos = 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,
  101. void __user *buffer, size_t *lenp,
  102. loff_t *ppos)
  103. {
  104. pid_t pid;
  105. char buff[16], *p;
  106. int len;
  107. len = *lenp;
  108. if (write) {
  109. /* potential state change */
  110. if (len <= 1 || len > sizeof(buff) - 1)
  111. return -EINVAL;
  112. if (copy_from_user(buff, buffer, len) != 0)
  113. return -EFAULT;
  114. if (buff[len - 1] == '\n')
  115. buff[len - 1] = '\0';
  116. else
  117. buff[len] = '\0';
  118. pid = simple_strtoul(buff, &p, 10);
  119. if (*p)
  120. return -EINVAL;
  121. return cxn_pin_by_pid(pid);
  122. }
  123. /* read the currently pinned CXN */
  124. if (*ppos > 0) {
  125. *lenp = 0;
  126. return 0;
  127. }
  128. len = snprintf(buff, sizeof(buff), "%d\n", cxn_pinned);
  129. if (len > *lenp)
  130. len = *lenp;
  131. if (copy_to_user(buffer, buff, len) != 0)
  132. return -EFAULT;
  133. *lenp = len;
  134. *ppos = len;
  135. return 0;
  136. } /* end procctl_frv_pin_cxnr() */
  137. #endif
  138. /*
  139. * FR-V specific sysctls
  140. */
  141. static struct ctl_table frv_table[] =
  142. {
  143. {
  144. .procname = "cache-mode",
  145. .data = NULL,
  146. .maxlen = 0,
  147. .mode = 0644,
  148. .proc_handler = procctl_frv_cachemode,
  149. },
  150. #ifdef CONFIG_MMU
  151. {
  152. .procname = "pin-cxnr",
  153. .data = NULL,
  154. .maxlen = 0,
  155. .mode = 0644,
  156. .proc_handler = procctl_frv_pin_cxnr
  157. },
  158. #endif
  159. {}
  160. };
  161. /*
  162. * Use a temporary sysctl number. Horrid, but will be cleaned up in 2.6
  163. * when all the PM interfaces exist nicely.
  164. */
  165. static struct ctl_table frv_dir_table[] =
  166. {
  167. {
  168. .procname = "frv",
  169. .mode = 0555,
  170. .child = frv_table
  171. },
  172. {}
  173. };
  174. /*
  175. * Initialize power interface
  176. */
  177. static int __init frv_sysctl_init(void)
  178. {
  179. register_sysctl_table(frv_dir_table);
  180. return 0;
  181. }
  182. __initcall(frv_sysctl_init);