sn_proc_fs.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. #ifdef CONFIG_PROC_FS
  10. #include <linux/proc_fs.h>
  11. #include <linux/seq_file.h>
  12. #include <asm/uaccess.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
  77. *sn_procfs_create_entry(const char *name, struct proc_dir_entry *parent,
  78. int (*openfunc)(struct inode *, struct file *),
  79. int (*releasefunc)(struct inode *, struct file *),
  80. ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *))
  81. {
  82. struct proc_dir_entry *e = create_proc_entry(name, 0444, parent);
  83. if (e) {
  84. struct file_operations *f;
  85. f = kzalloc(sizeof(*f), GFP_KERNEL);
  86. if (f) {
  87. f->open = openfunc;
  88. f->read = seq_read;
  89. f->llseek = seq_lseek;
  90. f->release = releasefunc;
  91. f->write = write;
  92. e->proc_fops = f;
  93. }
  94. }
  95. return e;
  96. }
  97. /* /proc/sgi_sn/sn_topology uses seq_file, see sn_hwperf.c */
  98. extern int sn_topology_open(struct inode *, struct file *);
  99. extern int sn_topology_release(struct inode *, struct file *);
  100. void register_sn_procfs(void)
  101. {
  102. static struct proc_dir_entry *sgi_proc_dir = NULL;
  103. BUG_ON(sgi_proc_dir != NULL);
  104. if (!(sgi_proc_dir = proc_mkdir("sgi_sn", NULL)))
  105. return;
  106. sn_procfs_create_entry("partition_id", sgi_proc_dir,
  107. partition_id_open, single_release, NULL);
  108. sn_procfs_create_entry("system_serial_number", sgi_proc_dir,
  109. system_serial_number_open, single_release, NULL);
  110. sn_procfs_create_entry("licenseID", sgi_proc_dir,
  111. licenseID_open, single_release, NULL);
  112. sn_procfs_create_entry("sn_force_interrupt", sgi_proc_dir,
  113. sn_force_interrupt_open, single_release,
  114. sn_force_interrupt_write_proc);
  115. sn_procfs_create_entry("coherence_id", sgi_proc_dir,
  116. coherence_id_open, single_release, NULL);
  117. sn_procfs_create_entry("sn_topology", sgi_proc_dir,
  118. sn_topology_open, sn_topology_release, NULL);
  119. }
  120. #endif /* CONFIG_PROC_FS */