sn_proc_fs.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 2000-2005 Silicon Graphics, Inc. All rights reserved.
  7. */
  8. #ifdef CONFIG_PROC_FS
  9. #include <linux/proc_fs.h>
  10. #include <linux/seq_file.h>
  11. #include <asm/uaccess.h>
  12. #include <asm/sn/sn_sal.h>
  13. static int partition_id_show(struct seq_file *s, void *p)
  14. {
  15. seq_printf(s, "%d\n", sn_partition_id);
  16. return 0;
  17. }
  18. static int partition_id_open(struct inode *inode, struct file *file)
  19. {
  20. return single_open(file, partition_id_show, NULL);
  21. }
  22. static int system_serial_number_show(struct seq_file *s, void *p)
  23. {
  24. seq_printf(s, "%s\n", sn_system_serial_number());
  25. return 0;
  26. }
  27. static int system_serial_number_open(struct inode *inode, struct file *file)
  28. {
  29. return single_open(file, system_serial_number_show, NULL);
  30. }
  31. static int licenseID_show(struct seq_file *s, void *p)
  32. {
  33. seq_printf(s, "0x%lx\n", sn_partition_serial_number_val());
  34. return 0;
  35. }
  36. static int licenseID_open(struct inode *inode, struct file *file)
  37. {
  38. return single_open(file, licenseID_show, NULL);
  39. }
  40. /*
  41. * Enable forced interrupt by default.
  42. * When set, the sn interrupt handler writes the force interrupt register on
  43. * the bridge chip. The hardware will then send an interrupt message if the
  44. * interrupt line is active. This mimics a level sensitive interrupt.
  45. */
  46. extern int sn_force_interrupt_flag;
  47. static int sn_force_interrupt_show(struct seq_file *s, void *p)
  48. {
  49. seq_printf(s, "Force interrupt is %s\n",
  50. sn_force_interrupt_flag ? "enabled" : "disabled");
  51. return 0;
  52. }
  53. static ssize_t sn_force_interrupt_write_proc(struct file *file,
  54. const char __user *buffer, size_t count, loff_t *data)
  55. {
  56. char val;
  57. if (copy_from_user(&val, buffer, 1))
  58. return -EFAULT;
  59. sn_force_interrupt_flag = (val == '0') ? 0 : 1;
  60. return count;
  61. }
  62. static int sn_force_interrupt_open(struct inode *inode, struct file *file)
  63. {
  64. return single_open(file, sn_force_interrupt_show, NULL);
  65. }
  66. static int coherence_id_show(struct seq_file *s, void *p)
  67. {
  68. seq_printf(s, "%d\n", partition_coherence_id());
  69. return 0;
  70. }
  71. static int coherence_id_open(struct inode *inode, struct file *file)
  72. {
  73. return single_open(file, coherence_id_show, NULL);
  74. }
  75. static struct proc_dir_entry
  76. *sn_procfs_create_entry(const char *name, struct proc_dir_entry *parent,
  77. int (*openfunc)(struct inode *, struct file *),
  78. int (*releasefunc)(struct inode *, struct file *),
  79. ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *))
  80. {
  81. struct proc_dir_entry *e = create_proc_entry(name, 0444, parent);
  82. if (e) {
  83. struct file_operations *f;
  84. f = kzalloc(sizeof(*f), GFP_KERNEL);
  85. if (f) {
  86. f->open = openfunc;
  87. f->read = seq_read;
  88. f->llseek = seq_lseek;
  89. f->release = releasefunc;
  90. f->write = write;
  91. e->proc_fops = f;
  92. }
  93. }
  94. return e;
  95. }
  96. /* /proc/sgi_sn/sn_topology uses seq_file, see sn_hwperf.c */
  97. extern int sn_topology_open(struct inode *, struct file *);
  98. extern int sn_topology_release(struct inode *, struct file *);
  99. void register_sn_procfs(void)
  100. {
  101. static struct proc_dir_entry *sgi_proc_dir = NULL;
  102. BUG_ON(sgi_proc_dir != NULL);
  103. if (!(sgi_proc_dir = proc_mkdir("sgi_sn", NULL)))
  104. return;
  105. sn_procfs_create_entry("partition_id", sgi_proc_dir,
  106. partition_id_open, single_release, NULL);
  107. sn_procfs_create_entry("system_serial_number", sgi_proc_dir,
  108. system_serial_number_open, single_release, NULL);
  109. sn_procfs_create_entry("licenseID", sgi_proc_dir,
  110. licenseID_open, single_release, NULL);
  111. sn_procfs_create_entry("sn_force_interrupt", sgi_proc_dir,
  112. sn_force_interrupt_open, single_release,
  113. sn_force_interrupt_write_proc);
  114. sn_procfs_create_entry("coherence_id", sgi_proc_dir,
  115. coherence_id_open, single_release, NULL);
  116. sn_procfs_create_entry("sn_topology", sgi_proc_dir,
  117. sn_topology_open, sn_topology_release, NULL);
  118. }
  119. #endif /* CONFIG_PROC_FS */