salinfo.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:3k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * salinfo.c
  3.  *
  4.  * Creates entries in /proc/sal for various system features.
  5.  *
  6.  * Copyright (c) 2001 Silicon Graphics, Inc.  All rights reserved.
  7.  *
  8.  * 10/30/2001 jbarnes@sgi.com copied much of Stephane's palinfo
  9.  * code to create this file
  10.  */
  11. #include <linux/types.h>
  12. #include <linux/proc_fs.h>
  13. #include <linux/module.h>
  14. #include <asm/sal.h>
  15. MODULE_AUTHOR("Jesse Barnes <jbarnes@sgi.com>");
  16. MODULE_DESCRIPTION("/proc interface to IA-64 SAL features");
  17. MODULE_LICENSE("GPL");
  18. static int salinfo_read(char *page, char **start, off_t off, int count, int *eof, void *data);
  19. typedef struct {
  20. const char *name; /* name of the proc entry */
  21. unsigned long           feature;        /* feature bit */
  22. struct proc_dir_entry *entry; /* registered entry (removal) */
  23. } salinfo_entry_t;
  24. /*
  25.  * List {name,feature} pairs for every entry in /proc/sal/<feature>
  26.  * that this module exports
  27.  */
  28. static salinfo_entry_t salinfo_entries[]={
  29. { "bus_lock",           IA64_SAL_PLATFORM_FEATURE_BUS_LOCK, },
  30. { "irq_redirection", IA64_SAL_PLATFORM_FEATURE_IRQ_REDIR_HINT, },
  31. { "ipi_redirection", IA64_SAL_PLATFORM_FEATURE_IPI_REDIR_HINT, },
  32. { "itc_drift", IA64_SAL_PLATFORM_FEATURE_ITC_DRIFT, },
  33. };
  34. #define NR_SALINFO_ENTRIES (sizeof(salinfo_entries)/sizeof(salinfo_entry_t))
  35. /*
  36.  * One for each feature and one more for the directory entry...
  37.  */
  38. static struct proc_dir_entry *salinfo_proc_entries[NR_SALINFO_ENTRIES + 1];
  39. static int __init
  40. salinfo_init(void)
  41. {
  42. struct proc_dir_entry *salinfo_dir; /* /proc/sal dir entry */
  43. struct proc_dir_entry **sdir = salinfo_proc_entries; /* keeps track of every entry */
  44. int i;
  45. salinfo_dir = proc_mkdir("sal", NULL);
  46. for (i=0; i < NR_SALINFO_ENTRIES; i++) {
  47. /* pass the feature bit in question as misc data */
  48. *sdir++ = create_proc_read_entry (salinfo_entries[i].name, 0, salinfo_dir,
  49.   salinfo_read, (void *)salinfo_entries[i].feature);
  50. }
  51. *sdir++ = salinfo_dir;
  52. return 0;
  53. }
  54. static void __exit
  55. salinfo_exit(void)
  56. {
  57. int i = 0;
  58. for (i = 0; i < NR_SALINFO_ENTRIES ; i++) {
  59. if (salinfo_proc_entries[i])
  60. remove_proc_entry (salinfo_proc_entries[i]->name, NULL);
  61. }
  62. }
  63. /*
  64.  * 'data' contains an integer that corresponds to the feature we're
  65.  * testing
  66.  */
  67. static int
  68. salinfo_read(char *page, char **start, off_t off, int count, int *eof, void *data)
  69. {
  70. int len = 0;
  71. MOD_INC_USE_COUNT;
  72. len = sprintf(page, (sal_platform_features & (unsigned long)data) ? "1n" : "0n");
  73. if (len <= off+count) *eof = 1;
  74. *start = page + off;
  75. len   -= off;
  76. if (len>count) len = count;
  77. if (len<0) len = 0;
  78. MOD_DEC_USE_COUNT;
  79. return len;
  80. }
  81. module_init(salinfo_init);
  82. module_exit(salinfo_exit);