3 * 1.) Inject errors to a processor.
4 * 2.) Query error injection capabilities.
5 * This driver along with user space code can be acting as an error
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
16 * NON INFRINGEMENT. See the GNU General Public License for more
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 * Written by: Fenghua Yu <fenghua.yu@intel.com>, Intel Corporation
24 * Copyright (C) 2006, Intel Corp. All rights reserved.
27 #include <linux/sysdev.h>
28 #include <linux/init.h>
30 #include <linux/cpu.h>
31 #include <linux/module.h>
35 #define ERR_DATA_BUFFER_SIZE 3 // Three 8-byte;
37 #define define_one_ro(name) \
38 static SYSDEV_ATTR(name, 0444, show_##name, NULL)
40 #define define_one_rw(name) \
41 static SYSDEV_ATTR(name, 0644, show_##name, store_##name)
43 static u64 call_start[NR_CPUS];
44 static u64 phys_addr[NR_CPUS];
45 static u64 err_type_info[NR_CPUS];
46 static u64 err_struct_info[NR_CPUS];
51 } __attribute__((__aligned__(16))) err_data_buffer[NR_CPUS];
52 static s64 status[NR_CPUS];
53 static u64 capabilities[NR_CPUS];
54 static u64 resources[NR_CPUS];
58 show_##name(struct sys_device *dev, struct sysdev_attribute *attr, \
62 return sprintf(buf, "%lx\n", name[cpu]); \
67 store_##name(struct sys_device *dev, struct sysdev_attribute *attr, \
68 const char *buf, size_t size) \
70 unsigned int cpu=dev->id; \
71 name[cpu] = simple_strtoull(buf, NULL, 16); \
77 /* It's user's responsibility to call the PAL procedure on a specific
78 * processor. The cpu number in driver is only used for storing data.
81 store_call_start(struct sys_device *dev, struct sysdev_attribute *attr,
82 const char *buf, size_t size)
84 unsigned int cpu=dev->id;
85 unsigned long call_start = simple_strtoull(buf, NULL, 16);
88 printk(KERN_DEBUG "pal_mc_err_inject for cpu%d:\n", cpu);
89 printk(KERN_DEBUG "err_type_info=%lx,\n", err_type_info[cpu]);
90 printk(KERN_DEBUG "err_struct_info=%lx,\n", err_struct_info[cpu]);
91 printk(KERN_DEBUG "err_data_buffer=%lx, %lx, %lx.\n",
92 err_data_buffer[cpu].data1,
93 err_data_buffer[cpu].data2,
94 err_data_buffer[cpu].data3);
97 case 0: /* Do nothing. */
99 case 1: /* Call pal_mc_error_inject in physical mode. */
100 status[cpu]=ia64_pal_mc_error_inject_phys(err_type_info[cpu],
101 err_struct_info[cpu],
102 ia64_tpa(&err_data_buffer[cpu]),
106 case 2: /* Call pal_mc_error_inject in virtual mode. */
107 status[cpu]=ia64_pal_mc_error_inject_virt(err_type_info[cpu],
108 err_struct_info[cpu],
109 ia64_tpa(&err_data_buffer[cpu]),
114 status[cpu] = -EINVAL;
119 printk(KERN_DEBUG "Returns: status=%d,\n", (int)status[cpu]);
120 printk(KERN_DEBUG "capapbilities=%lx,\n", capabilities[cpu]);
121 printk(KERN_DEBUG "resources=%lx\n", resources[cpu]);
130 show_virtual_to_phys(struct sys_device *dev, struct sysdev_attribute *attr,
133 unsigned int cpu=dev->id;
134 return sprintf(buf, "%lx\n", phys_addr[cpu]);
138 store_virtual_to_phys(struct sys_device *dev, struct sysdev_attribute *attr,
139 const char *buf, size_t size)
141 unsigned int cpu=dev->id;
142 u64 virt_addr=simple_strtoull(buf, NULL, 16);
145 ret = get_user_pages(current, current->mm, virt_addr,
146 1, VM_READ, 0, NULL, NULL);
149 printk("Virtual address %lx is not existing.\n",virt_addr);
154 phys_addr[cpu] = ia64_tpa(virt_addr);
158 show(err_struct_info)
159 store(err_struct_info)
162 show_err_data_buffer(struct sys_device *dev,
163 struct sysdev_attribute *attr, char *buf)
165 unsigned int cpu=dev->id;
167 return sprintf(buf, "%lx, %lx, %lx\n",
168 err_data_buffer[cpu].data1,
169 err_data_buffer[cpu].data2,
170 err_data_buffer[cpu].data3);
174 store_err_data_buffer(struct sys_device *dev,
175 struct sysdev_attribute *attr,
176 const char *buf, size_t size)
178 unsigned int cpu=dev->id;
182 printk("write err_data_buffer=[%lx,%lx,%lx] on cpu%d\n",
183 err_data_buffer[cpu].data1,
184 err_data_buffer[cpu].data2,
185 err_data_buffer[cpu].data3,
188 ret=sscanf(buf, "%lx, %lx, %lx",
189 &err_data_buffer[cpu].data1,
190 &err_data_buffer[cpu].data2,
191 &err_data_buffer[cpu].data3);
192 if (ret!=ERR_DATA_BUFFER_SIZE)
202 define_one_rw(call_start);
203 define_one_rw(err_type_info);
204 define_one_rw(err_struct_info);
205 define_one_rw(err_data_buffer);
206 define_one_rw(virtual_to_phys);
207 define_one_ro(status);
208 define_one_ro(capabilities);
209 define_one_ro(resources);
211 static struct attribute *default_attrs[] = {
212 &attr_call_start.attr,
213 &attr_virtual_to_phys.attr,
214 &attr_err_type_info.attr,
215 &attr_err_struct_info.attr,
216 &attr_err_data_buffer.attr,
218 &attr_capabilities.attr,
219 &attr_resources.attr,
223 static struct attribute_group err_inject_attr_group = {
224 .attrs = default_attrs,
227 /* Add/Remove err_inject interface for CPU device */
228 static int __cpuinit err_inject_add_dev(struct sys_device * sys_dev)
230 return sysfs_create_group(&sys_dev->kobj, &err_inject_attr_group);
233 static int __cpuinit err_inject_remove_dev(struct sys_device * sys_dev)
235 sysfs_remove_group(&sys_dev->kobj, &err_inject_attr_group);
238 static int __cpuinit err_inject_cpu_callback(struct notifier_block *nfb,
239 unsigned long action, void *hcpu)
241 unsigned int cpu = (unsigned long)hcpu;
242 struct sys_device *sys_dev;
244 sys_dev = get_cpu_sysdev(cpu);
247 case CPU_ONLINE_FROZEN:
248 err_inject_add_dev(sys_dev);
251 case CPU_DEAD_FROZEN:
252 err_inject_remove_dev(sys_dev);
259 static struct notifier_block __cpuinitdata err_inject_cpu_notifier =
261 .notifier_call = err_inject_cpu_callback,
265 err_inject_init(void)
270 printk(KERN_INFO "Enter error injection driver.\n");
272 for_each_online_cpu(i) {
273 err_inject_cpu_callback(&err_inject_cpu_notifier, CPU_ONLINE,
277 register_hotcpu_notifier(&err_inject_cpu_notifier);
283 err_inject_exit(void)
286 struct sys_device *sys_dev;
289 printk(KERN_INFO "Exit error injection driver.\n");
291 for_each_online_cpu(i) {
292 sys_dev = get_cpu_sysdev(i);
293 sysfs_remove_group(&sys_dev->kobj, &err_inject_attr_group);
295 unregister_hotcpu_notifier(&err_inject_cpu_notifier);
298 module_init(err_inject_init);
299 module_exit(err_inject_exit);
301 MODULE_AUTHOR("Fenghua Yu <fenghua.yu@intel.com>");
302 MODULE_DESCRIPTION("MC error injection kernel sysfs interface");
303 MODULE_LICENSE("GPL");