1 // SPDX-License-Identifier: GPL-2.0-only
3 * srm_env.c - Access to SRM environment
4 * variables through linux' procfs
6 * (C) 2001,2002,2006 by Jan-Benedict Glaw <jbglaw@lug-owl.de>
8 * This driver is a modified version of Erik Mouw's example proc
9 * interface, so: thank you, Erik! He can be reached via email at
10 * <J.A.K.Mouw@its.tudelft.nl>. It is based on an idea
11 * provided by DEC^WCompaq^WIntel's "Jumpstart" CD. They
12 * included a patch like this as well. Thanks for idea!
15 #include <linux/kernel.h>
16 #include <linux/gfp.h>
17 #include <linux/module.h>
18 #include <linux/init.h>
19 #include <linux/proc_fs.h>
20 #include <linux/seq_file.h>
21 #include <asm/console.h>
22 #include <linux/uaccess.h>
23 #include <asm/machvec.h>
25 #define BASE_DIR "srm_environment" /* Subdir in /proc/ */
26 #define NAMED_DIR "named_variables" /* Subdir for known variables */
27 #define NUMBERED_DIR "numbered_variables" /* Subdir for all variables */
28 #define VERSION "0.0.6" /* Module version */
29 #define NAME "srm_env" /* Module name */
31 MODULE_AUTHOR("Jan-Benedict Glaw <jbglaw@lug-owl.de>");
32 MODULE_DESCRIPTION("Accessing Alpha SRM environment through procfs interface");
33 MODULE_LICENSE("GPL");
35 typedef struct _srm_env
{
40 static struct proc_dir_entry
*base_dir
;
41 static struct proc_dir_entry
*named_dir
;
42 static struct proc_dir_entry
*numbered_dir
;
44 static srm_env_t srm_named_entries
[] = {
45 { "auto_action", ENV_AUTO_ACTION
},
46 { "boot_dev", ENV_BOOT_DEV
},
47 { "bootdef_dev", ENV_BOOTDEF_DEV
},
48 { "booted_dev", ENV_BOOTED_DEV
},
49 { "boot_file", ENV_BOOT_FILE
},
50 { "booted_file", ENV_BOOTED_FILE
},
51 { "boot_osflags", ENV_BOOT_OSFLAGS
},
52 { "booted_osflags", ENV_BOOTED_OSFLAGS
},
53 { "boot_reset", ENV_BOOT_RESET
},
54 { "dump_dev", ENV_DUMP_DEV
},
55 { "enable_audit", ENV_ENABLE_AUDIT
},
56 { "license", ENV_LICENSE
},
57 { "char_set", ENV_CHAR_SET
},
58 { "language", ENV_LANGUAGE
},
59 { "tty_dev", ENV_TTY_DEV
},
63 static int srm_env_proc_show(struct seq_file
*m
, void *v
)
66 unsigned long id
= (unsigned long)m
->private;
69 page
= (char *)__get_free_page(GFP_USER
);
73 ret
= callback_getenv(id
, page
, PAGE_SIZE
);
75 if ((ret
>> 61) == 0) {
76 seq_write(m
, page
, ret
);
80 free_page((unsigned long)page
);
84 static int srm_env_proc_open(struct inode
*inode
, struct file
*file
)
86 return single_open(file
, srm_env_proc_show
, PDE_DATA(inode
));
89 static ssize_t
srm_env_proc_write(struct file
*file
, const char __user
*buffer
,
90 size_t count
, loff_t
*pos
)
93 unsigned long id
= (unsigned long)PDE_DATA(file_inode(file
));
94 char *buf
= (char *) __get_free_page(GFP_USER
);
95 unsigned long ret1
, ret2
;
101 if (count
>= PAGE_SIZE
)
105 if (copy_from_user(buf
, buffer
, count
))
109 ret1
= callback_setenv(id
, buf
, count
);
110 if ((ret1
>> 61) == 0) {
112 ret2
= callback_save_env();
113 while((ret2
>> 61) == 1);
118 free_page((unsigned long)buf
);
122 static const struct proc_ops srm_env_proc_ops
= {
123 .proc_open
= srm_env_proc_open
,
124 .proc_read
= seq_read
,
125 .proc_lseek
= seq_lseek
,
126 .proc_release
= single_release
,
127 .proc_write
= srm_env_proc_write
,
134 unsigned long var_num
;
139 if (!alpha_using_srm
) {
140 printk(KERN_INFO
"%s: This Alpha system doesn't "
141 "know about SRM (or you've booted "
142 "SRM->MILO->Linux, which gets "
143 "misdetected)...\n", __func__
);
148 * Create base directory
150 base_dir
= proc_mkdir(BASE_DIR
, NULL
);
152 printk(KERN_ERR
"Couldn't create base dir /proc/%s\n",
158 * Create per-name subdirectory
160 named_dir
= proc_mkdir(NAMED_DIR
, base_dir
);
162 printk(KERN_ERR
"Couldn't create dir /proc/%s/%s\n",
163 BASE_DIR
, NAMED_DIR
);
168 * Create per-number subdirectory
170 numbered_dir
= proc_mkdir(NUMBERED_DIR
, base_dir
);
172 printk(KERN_ERR
"Couldn't create dir /proc/%s/%s\n",
173 BASE_DIR
, NUMBERED_DIR
);
179 * Create all named nodes
181 entry
= srm_named_entries
;
182 while (entry
->name
&& entry
->id
) {
183 if (!proc_create_data(entry
->name
, 0644, named_dir
,
184 &srm_env_proc_ops
, (void *)entry
->id
))
190 * Create all numbered nodes
192 for (var_num
= 0; var_num
<= 255; var_num
++) {
194 sprintf(name
, "%ld", var_num
);
195 if (!proc_create_data(name
, 0644, numbered_dir
,
196 &srm_env_proc_ops
, (void *)var_num
))
200 printk(KERN_INFO
"%s: version %s loaded successfully\n", NAME
,
206 remove_proc_subtree(BASE_DIR
, NULL
);
213 remove_proc_subtree(BASE_DIR
, NULL
);
214 printk(KERN_INFO
"%s: unloaded successfully\n", NAME
);
217 module_init(srm_env_init
);
218 module_exit(srm_env_exit
);