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