sysctl.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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, struct file *filp,
  40. void __user *buffer, size_t *lenp, loff_t *ppos)
  41. {
  42. unsigned long hsr0;
  43. char buff[8];
  44. int len;
  45. len = *lenp;
  46. if (write) {
  47. /* potential state change */
  48. if (len <= 1 || len > sizeof(buff) - 1)
  49. return -EINVAL;
  50. if (copy_from_user(buff, buffer, len) != 0)
  51. return -EFAULT;
  52. if (buff[len - 1] == '\n')
  53. buff[len - 1] = '\0';
  54. else
  55. buff[len] = '\0';
  56. if (strcmp(buff, frv_cache_wback) == 0) {
  57. /* switch dcache into write-back mode */
  58. frv_change_dcache_mode(HSR0_CBM_COPY_BACK);
  59. return 0;
  60. }
  61. if (strcmp(buff, frv_cache_wthru) == 0) {
  62. /* switch dcache into write-through mode */
  63. frv_change_dcache_mode(HSR0_CBM_WRITE_THRU);
  64. return 0;
  65. }
  66. return -EINVAL;
  67. }
  68. /* read the state */
  69. if (filp->f_pos > 0) {
  70. *lenp = 0;
  71. return 0;
  72. }
  73. hsr0 = __get_HSR(0);
  74. switch (hsr0 & HSR0_CBM) {
  75. case HSR0_CBM_WRITE_THRU:
  76. memcpy(buff, frv_cache_wthru, sizeof(frv_cache_wthru) - 1);
  77. buff[sizeof(frv_cache_wthru) - 1] = '\n';
  78. len = sizeof(frv_cache_wthru);
  79. break;
  80. default:
  81. memcpy(buff, frv_cache_wback, sizeof(frv_cache_wback) - 1);
  82. buff[sizeof(frv_cache_wback) - 1] = '\n';
  83. len = sizeof(frv_cache_wback);
  84. break;
  85. }
  86. if (len > *lenp)
  87. len = *lenp;
  88. if (copy_to_user(buffer, buff, len) != 0)
  89. return -EFAULT;
  90. *lenp = len;
  91. filp->f_pos = len;
  92. return 0;
  93. } /* end procctl_frv_cachemode() */
  94. /*****************************************************************************/
  95. /*
  96. * permit the mm_struct the nominated process is using have its MMU context ID pinned
  97. */
  98. #ifdef CONFIG_MMU
  99. static int procctl_frv_pin_cxnr(ctl_table *table, int write, struct file *filp,
  100. void __user *buffer, size_t *lenp, loff_t *ppos)
  101. {
  102. pid_t pid;
  103. char buff[16], *p;
  104. int len;
  105. len = *lenp;
  106. if (write) {
  107. /* potential state change */
  108. if (len <= 1 || len > sizeof(buff) - 1)
  109. return -EINVAL;
  110. if (copy_from_user(buff, buffer, len) != 0)
  111. return -EFAULT;
  112. if (buff[len - 1] == '\n')
  113. buff[len - 1] = '\0';
  114. else
  115. buff[len] = '\0';
  116. pid = simple_strtoul(buff, &p, 10);
  117. if (*p)
  118. return -EINVAL;
  119. return cxn_pin_by_pid(pid);
  120. }
  121. /* read the currently pinned CXN */
  122. if (filp->f_pos > 0) {
  123. *lenp = 0;
  124. return 0;
  125. }
  126. len = snprintf(buff, sizeof(buff), "%d\n", cxn_pinned);
  127. if (len > *lenp)
  128. len = *lenp;
  129. if (copy_to_user(buffer, buff, len) != 0)
  130. return -EFAULT;
  131. *lenp = len;
  132. filp->f_pos = len;
  133. return 0;
  134. } /* end procctl_frv_pin_cxnr() */
  135. #endif
  136. /*
  137. * FR-V specific sysctls
  138. */
  139. static struct ctl_table frv_table[] =
  140. {
  141. {
  142. .procname = "cache-mode",
  143. .data = NULL,
  144. .maxlen = 0,
  145. .mode = 0644,
  146. .proc_handler = procctl_frv_cachemode,
  147. },
  148. #ifdef CONFIG_MMU
  149. {
  150. .procname = "pin-cxnr",
  151. .data = NULL,
  152. .maxlen = 0,
  153. .mode = 0644,
  154. .proc_handler = procctl_frv_pin_cxnr
  155. },
  156. #endif
  157. {}
  158. };
  159. /*
  160. * Use a temporary sysctl number. Horrid, but will be cleaned up in 2.6
  161. * when all the PM interfaces exist nicely.
  162. */
  163. static struct ctl_table frv_dir_table[] =
  164. {
  165. {
  166. .procname = "frv",
  167. .mode = 0555,
  168. .child = frv_table
  169. },
  170. {}
  171. };
  172. /*
  173. * Initialize power interface
  174. */
  175. static int __init frv_sysctl_init(void)
  176. {
  177. register_sysctl_table(frv_dir_table);
  178. return 0;
  179. }
  180. __initcall(frv_sysctl_init);