1 /* sysctl.c: implementation of /proc/sys files relating to FRV specifically
3 * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
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.
12 #include <linux/config.h>
13 #include <linux/slab.h>
14 #include <linux/sysctl.h>
15 #include <linux/proc_fs.h>
16 #include <linux/init.h>
17 #include <asm/uaccess.h>
19 static const char frv_cache_wback[] = "wback";
20 static const char frv_cache_wthru[] = "wthru";
22 static void frv_change_dcache_mode(unsigned long newmode)
24 unsigned long flags, hsr0;
26 local_irq_save(flags);
32 asm volatile(" dcef @(gr0,gr0),#1 \n"
37 hsr0 = (hsr0 & ~HSR0_CBM) | newmode;
42 local_irq_restore(flags);
44 //printk("HSR0 now %08lx\n", hsr0);
47 /*****************************************************************************/
49 * handle requests to dynamically switch the write caching mode delivered by /proc
51 static int procctl_frv_cachemode(ctl_table *table, int write, struct file *filp,
52 void *buffer, size_t *lenp, loff_t *ppos)
61 /* potential state change */
62 if (len <= 1 || len > sizeof(buff) - 1)
65 if (copy_from_user(buff, buffer, len) != 0)
68 if (buff[len - 1] == '\n')
73 if (strcmp(buff, frv_cache_wback) == 0) {
74 /* switch dcache into write-back mode */
75 frv_change_dcache_mode(HSR0_CBM_COPY_BACK);
79 if (strcmp(buff, frv_cache_wthru) == 0) {
80 /* switch dcache into write-through mode */
81 frv_change_dcache_mode(HSR0_CBM_WRITE_THRU);
89 if (filp->f_pos > 0) {
95 switch (hsr0 & HSR0_CBM) {
96 case HSR0_CBM_WRITE_THRU:
97 memcpy(buff, frv_cache_wthru, sizeof(frv_cache_wthru) - 1);
98 buff[sizeof(frv_cache_wthru) - 1] = '\n';
99 len = sizeof(frv_cache_wthru);
102 memcpy(buff, frv_cache_wback, sizeof(frv_cache_wback) - 1);
103 buff[sizeof(frv_cache_wback) - 1] = '\n';
104 len = sizeof(frv_cache_wback);
111 if (copy_to_user(buffer, buff, len) != 0)
118 } /* end procctl_frv_cachemode() */
120 /*****************************************************************************/
122 * permit the mm_struct the nominated process is using have its MMU context ID pinned
125 static int procctl_frv_pin_cxnr(ctl_table *table, int write, struct file *filp,
126 void *buffer, size_t *lenp, loff_t *ppos)
135 /* potential state change */
136 if (len <= 1 || len > sizeof(buff) - 1)
139 if (copy_from_user(buff, buffer, len) != 0)
142 if (buff[len - 1] == '\n')
143 buff[len - 1] = '\0';
147 pid = simple_strtoul(buff, &p, 10);
151 return cxn_pin_by_pid(pid);
154 /* read the currently pinned CXN */
155 if (filp->f_pos > 0) {
160 len = snprintf(buff, sizeof(buff), "%d\n", cxn_pinned);
164 if (copy_to_user(buffer, buff, len) != 0)
171 } /* end procctl_frv_pin_cxnr() */
175 * FR-V specific sysctls
177 static struct ctl_table frv_table[] =
179 { 1, "cache-mode", NULL, 0, 0644, NULL, &procctl_frv_cachemode },
181 { 2, "pin-cxnr", NULL, 0, 0644, NULL, &procctl_frv_pin_cxnr },
187 * Use a temporary sysctl number. Horrid, but will be cleaned up in 2.6
188 * when all the PM interfaces exist nicely.
191 static struct ctl_table frv_dir_table[] =
193 {CTL_FRV, "frv", NULL, 0, 0555, frv_table},
198 * Initialize power interface
200 static int __init frv_sysctl_init(void)
202 register_sysctl_table(frv_dir_table, 1);
206 __initcall(frv_sysctl_init);