sysctl.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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/config.h>
  12. #include <linux/slab.h>
  13. #include <linux/sysctl.h>
  14. #include <linux/proc_fs.h>
  15. #include <linux/init.h>
  16. #include <asm/uaccess.h>
  17. static const char frv_cache_wback[] = "wback";
  18. static const char frv_cache_wthru[] = "wthru";
  19. static void frv_change_dcache_mode(unsigned long newmode)
  20. {
  21. unsigned long flags, hsr0;
  22. local_irq_save(flags);
  23. hsr0 = __get_HSR(0);
  24. hsr0 &= ~HSR0_DCE;
  25. __set_HSR(0, hsr0);
  26. asm volatile(" dcef @(gr0,gr0),#1 \n"
  27. " membar \n"
  28. : : : "memory"
  29. );
  30. hsr0 = (hsr0 & ~HSR0_CBM) | newmode;
  31. __set_HSR(0, hsr0);
  32. hsr0 |= HSR0_DCE;
  33. __set_HSR(0, hsr0);
  34. local_irq_restore(flags);
  35. //printk("HSR0 now %08lx\n", hsr0);
  36. }
  37. /*****************************************************************************/
  38. /*
  39. * handle requests to dynamically switch the write caching mode delivered by /proc
  40. */
  41. static int procctl_frv_cachemode(ctl_table *table, int write, struct file *filp,
  42. void *buffer, size_t *lenp, loff_t *ppos)
  43. {
  44. unsigned long hsr0;
  45. char buff[8];
  46. int len;
  47. len = *lenp;
  48. if (write) {
  49. /* potential state change */
  50. if (len <= 1 || len > sizeof(buff) - 1)
  51. return -EINVAL;
  52. if (copy_from_user(buff, buffer, len) != 0)
  53. return -EFAULT;
  54. if (buff[len - 1] == '\n')
  55. buff[len - 1] = '\0';
  56. else
  57. buff[len] = '\0';
  58. if (strcmp(buff, frv_cache_wback) == 0) {
  59. /* switch dcache into write-back mode */
  60. frv_change_dcache_mode(HSR0_CBM_COPY_BACK);
  61. return 0;
  62. }
  63. if (strcmp(buff, frv_cache_wthru) == 0) {
  64. /* switch dcache into write-through mode */
  65. frv_change_dcache_mode(HSR0_CBM_WRITE_THRU);
  66. return 0;
  67. }
  68. return -EINVAL;
  69. }
  70. /* read the state */
  71. if (filp->f_pos > 0) {
  72. *lenp = 0;
  73. return 0;
  74. }
  75. hsr0 = __get_HSR(0);
  76. switch (hsr0 & HSR0_CBM) {
  77. case HSR0_CBM_WRITE_THRU:
  78. memcpy(buff, frv_cache_wthru, sizeof(frv_cache_wthru) - 1);
  79. buff[sizeof(frv_cache_wthru) - 1] = '\n';
  80. len = sizeof(frv_cache_wthru);
  81. break;
  82. default:
  83. memcpy(buff, frv_cache_wback, sizeof(frv_cache_wback) - 1);
  84. buff[sizeof(frv_cache_wback) - 1] = '\n';
  85. len = sizeof(frv_cache_wback);
  86. break;
  87. }
  88. if (len > *lenp)
  89. len = *lenp;
  90. if (copy_to_user(buffer, buff, len) != 0)
  91. return -EFAULT;
  92. *lenp = len;
  93. filp->f_pos = len;
  94. return 0;
  95. } /* end procctl_frv_cachemode() */
  96. /*****************************************************************************/
  97. /*
  98. * permit the mm_struct the nominated process is using have its MMU context ID pinned
  99. */
  100. #ifdef CONFIG_MMU
  101. static int procctl_frv_pin_cxnr(ctl_table *table, int write, struct file *filp,
  102. void *buffer, size_t *lenp, 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 (filp->f_pos > 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. filp->f_pos = 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. { 1, "cache-mode", NULL, 0, 0644, NULL, &procctl_frv_cachemode },
  144. #ifdef CONFIG_MMU
  145. { 2, "pin-cxnr", NULL, 0, 0644, NULL, &procctl_frv_pin_cxnr },
  146. #endif
  147. { 0 }
  148. };
  149. /*
  150. * Use a temporary sysctl number. Horrid, but will be cleaned up in 2.6
  151. * when all the PM interfaces exist nicely.
  152. */
  153. #define CTL_FRV 9898
  154. static struct ctl_table frv_dir_table[] =
  155. {
  156. {CTL_FRV, "frv", NULL, 0, 0555, frv_table},
  157. {0}
  158. };
  159. /*
  160. * Initialize power interface
  161. */
  162. static int __init frv_sysctl_init(void)
  163. {
  164. register_sysctl_table(frv_dir_table, 1);
  165. return 0;
  166. }
  167. __initcall(frv_sysctl_init);