aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/system.c
diff options
context:
space:
mode:
authorLen Brown <len.brown@intel.com>2008-02-06 01:26:55 -0500
committerLen Brown <len.brown@intel.com>2008-02-06 22:27:06 -0500
commit5229e87d59cef33539322948bd8e3b5a537f7c97 (patch)
tree711a5708474fc79dbe599fae35f3e50d0a037ca0 /drivers/acpi/system.c
parent21511abd0a248a3f225d3b611cfabb93124605a7 (diff)
ACPI: create /sys/firmware/acpi/interrupts
See Documentation/ABI/testing/sysfs-firmware-acpi Based-on-original-patch-by: Luming Yu <luming.yu@intel.com> Acked-by: Greg Kroah-Hartman <gregkh@suse.de> Signed-off-by: Len Brown <len.brown@intel.com>
Diffstat (limited to 'drivers/acpi/system.c')
-rw-r--r--drivers/acpi/system.c208
1 files changed, 208 insertions, 0 deletions
diff --git a/drivers/acpi/system.c b/drivers/acpi/system.c
index 5ffe0ea18967..ce881713f7a6 100644
--- a/drivers/acpi/system.c
+++ b/drivers/acpi/system.c
@@ -40,6 +40,8 @@ ACPI_MODULE_NAME("system");
40#define ACPI_SYSTEM_CLASS "system" 40#define ACPI_SYSTEM_CLASS "system"
41#define ACPI_SYSTEM_DEVICE_NAME "System" 41#define ACPI_SYSTEM_DEVICE_NAME "System"
42 42
43u32 acpi_irq_handled;
44
43/* 45/*
44 * Make ACPICA version work as module param 46 * Make ACPICA version work as module param
45 */ 47 */
@@ -166,6 +168,212 @@ static int acpi_system_sysfs_init(void)
166 return 0; 168 return 0;
167} 169}
168 170
171/*
172 * Detailed ACPI IRQ counters in /sys/firmware/acpi/interrupts/
173 * See Documentation/ABI/testing/sysfs-firmware-acpi
174 */
175
176#define COUNT_GPE 0
177#define COUNT_SCI 1 /* acpi_irq_handled */
178#define COUNT_ERROR 2 /* other */
179#define NUM_COUNTERS_EXTRA 3
180
181static u32 *all_counters;
182static u32 num_gpes;
183static u32 num_counters;
184static struct attribute **all_attrs;
185static u32 acpi_gpe_count;
186
187static struct attribute_group interrupt_stats_attr_group = {
188 .name = "interrupts",
189};
190static struct kobj_attribute *counter_attrs;
191
192static int count_num_gpes(void)
193{
194 int count = 0;
195 struct acpi_gpe_xrupt_info *gpe_xrupt_info;
196 struct acpi_gpe_block_info *gpe_block;
197 acpi_cpu_flags flags;
198
199 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
200
201 gpe_xrupt_info = acpi_gbl_gpe_xrupt_list_head;
202 while (gpe_xrupt_info) {
203 gpe_block = gpe_xrupt_info->gpe_block_list_head;
204 while (gpe_block) {
205 count += gpe_block->register_count *
206 ACPI_GPE_REGISTER_WIDTH;
207 gpe_block = gpe_block->next;
208 }
209 gpe_xrupt_info = gpe_xrupt_info->next;
210 }
211 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
212
213 return count;
214}
215
216static void delete_gpe_attr_array(void)
217{
218 u32 *tmp = all_counters;
219
220 all_counters = NULL;
221 kfree(tmp);
222
223 if (counter_attrs) {
224 int i;
225
226 for (i = 0; i < num_gpes; i++)
227 kfree(counter_attrs[i].attr.name);
228
229 kfree(counter_attrs);
230 }
231 kfree(all_attrs);
232
233 return;
234}
235
236void acpi_os_gpe_count(u32 gpe_number)
237{
238 acpi_gpe_count++;
239
240 if (!all_counters)
241 return;
242
243 if (gpe_number < num_gpes)
244 all_counters[gpe_number]++;
245 else
246 all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_ERROR]++;
247
248 return;
249}
250
251void acpi_os_fixed_event_count(u32 event_number)
252{
253 if (!all_counters)
254 return;
255
256 if (event_number < ACPI_NUM_FIXED_EVENTS)
257 all_counters[num_gpes + event_number]++;
258 else
259 all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_ERROR]++;
260
261 return;
262}
263
264static ssize_t counter_show(struct kobject *kobj,
265 struct kobj_attribute *attr, char *buf)
266{
267 all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI] =
268 acpi_irq_handled;
269 all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_GPE] =
270 acpi_gpe_count;
271
272 return sprintf(buf, "%d\n", all_counters[attr - counter_attrs]);
273}
274
275/*
276 * counter_set() sets the specified counter.
277 * setting the total "sci" file to any value clears all counters.
278 */
279static ssize_t counter_set(struct kobject *kobj,
280 struct kobj_attribute *attr, const char *buf, size_t size)
281{
282 int index = attr - counter_attrs;
283
284 if (index == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI) {
285 int i;
286 for (i = 0; i < num_counters; ++i)
287 all_counters[i] = 0;
288 acpi_gpe_count = 0;
289 acpi_irq_handled = 0;
290
291 } else
292 all_counters[index] = strtoul(buf, NULL, 0);
293
294 return size;
295}
296
297void acpi_irq_stats_init(void)
298{
299 int i;
300
301 if (all_counters)
302 return;
303
304 num_gpes = count_num_gpes();
305 num_counters = num_gpes + ACPI_NUM_FIXED_EVENTS + NUM_COUNTERS_EXTRA;
306
307 all_attrs = kzalloc(sizeof(struct attribute *) * (num_counters + 1),
308 GFP_KERNEL);
309 if (all_attrs == NULL)
310 return;
311
312 all_counters = kzalloc(sizeof(u32) * (num_counters), GFP_KERNEL);
313 if (all_counters == NULL)
314 goto fail;
315
316 counter_attrs = kzalloc(sizeof(struct kobj_attribute) * (num_counters),
317 GFP_KERNEL);
318 if (counter_attrs == NULL)
319 goto fail;
320
321 for (i = 0; i < num_counters; ++i) {
322 char buffer[10];
323 char *name;
324
325 if (i < num_gpes)
326 sprintf(buffer, "gpe%02X", i);
327 else if (i == num_gpes + ACPI_EVENT_PMTIMER)
328 sprintf(buffer, "ff_pmtimer");
329 else if (i == num_gpes + ACPI_EVENT_GLOBAL)
330 sprintf(buffer, "ff_gbl_lock");
331 else if (i == num_gpes + ACPI_EVENT_POWER_BUTTON)
332 sprintf(buffer, "ff_pwr_btn");
333 else if (i == num_gpes + ACPI_EVENT_SLEEP_BUTTON)
334 sprintf(buffer, "ff_slp_btn");
335 else if (i == num_gpes + ACPI_EVENT_RTC)
336 sprintf(buffer, "ff_rt_clk");
337 else if (i == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_GPE)
338 sprintf(buffer, "gpe_all");
339 else if (i == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI)
340 sprintf(buffer, "sci");
341 else if (i == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_ERROR)
342 sprintf(buffer, "error");
343 else
344 sprintf(buffer, "bug%02X", i);
345
346 name = kzalloc(strlen(buffer) + 1, GFP_KERNEL);
347 if (name == NULL)
348 goto fail;
349 strncpy(name, buffer, strlen(buffer) + 1);
350
351 counter_attrs[i].attr.name = name;
352 counter_attrs[i].attr.mode = 0644;
353 counter_attrs[i].show = counter_show;
354 counter_attrs[i].store = counter_set;
355
356 all_attrs[i] = &counter_attrs[i].attr;
357 }
358
359 interrupt_stats_attr_group.attrs = all_attrs;
360 sysfs_create_group(acpi_kobj, &interrupt_stats_attr_group);
361 return;
362
363fail:
364 delete_gpe_attr_array();
365 return;
366}
367
368static void __exit interrupt_stats_exit(void)
369{
370 sysfs_remove_group(acpi_kobj, &interrupt_stats_attr_group);
371
372 delete_gpe_attr_array();
373
374 return;
375}
376
169/* -------------------------------------------------------------------------- 377/* --------------------------------------------------------------------------
170 FS Interface (/proc) 378 FS Interface (/proc)
171 -------------------------------------------------------------------------- */ 379 -------------------------------------------------------------------------- */