mca-proc.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /* -*- mode: c; c-basic-offset: 8 -*- */
  2. /*
  3. * MCA bus support functions for the proc fs.
  4. *
  5. * NOTE: this code *requires* the legacy MCA api.
  6. *
  7. * Legacy API means the API that operates in terms of MCA slot number
  8. *
  9. * (C) 2002 James Bottomley <James.Bottomley@HansenPartnership.com>
  10. *
  11. **-----------------------------------------------------------------------------
  12. **
  13. ** This program is free software; you can redistribute it and/or modify
  14. ** it under the terms of the GNU General Public License as published by
  15. ** the Free Software Foundation; either version 2 of the License, or
  16. ** (at your option) any later version.
  17. **
  18. ** This program is distributed in the hope that it will be useful,
  19. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. ** GNU General Public License for more details.
  22. **
  23. ** You should have received a copy of the GNU General Public License
  24. ** along with this program; if not, write to the Free Software
  25. ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  26. **
  27. **-----------------------------------------------------------------------------
  28. */
  29. #include <linux/module.h>
  30. #include <linux/init.h>
  31. #include <linux/proc_fs.h>
  32. #include <linux/mca.h>
  33. static int get_mca_info_helper(struct mca_device *mca_dev, char *page, int len)
  34. {
  35. int j;
  36. for(j=0; j<8; j++)
  37. len += sprintf(page+len, "%02x ",
  38. mca_dev ? mca_dev->pos[j] : 0xff);
  39. len += sprintf(page+len, " %s\n", mca_dev ? mca_dev->name : "");
  40. return len;
  41. }
  42. static int get_mca_info(char *page, char **start, off_t off,
  43. int count, int *eof, void *data)
  44. {
  45. int i, len = 0;
  46. if(MCA_bus) {
  47. struct mca_device *mca_dev;
  48. /* Format POS registers of eight MCA slots */
  49. for(i=0; i<MCA_MAX_SLOT_NR; i++) {
  50. mca_dev = mca_find_device_by_slot(i);
  51. len += sprintf(page+len, "Slot %d: ", i+1);
  52. len = get_mca_info_helper(mca_dev, page, len);
  53. }
  54. /* Format POS registers of integrated video subsystem */
  55. mca_dev = mca_find_device_by_slot(MCA_INTEGVIDEO);
  56. len += sprintf(page+len, "Video : ");
  57. len = get_mca_info_helper(mca_dev, page, len);
  58. /* Format POS registers of integrated SCSI subsystem */
  59. mca_dev = mca_find_device_by_slot(MCA_INTEGSCSI);
  60. len += sprintf(page+len, "SCSI : ");
  61. len = get_mca_info_helper(mca_dev, page, len);
  62. /* Format POS registers of motherboard */
  63. mca_dev = mca_find_device_by_slot(MCA_MOTHERBOARD);
  64. len += sprintf(page+len, "Planar: ");
  65. len = get_mca_info_helper(mca_dev, page, len);
  66. } else {
  67. /* Leave it empty if MCA not detected - this should *never*
  68. * happen!
  69. */
  70. }
  71. if (len <= off+count) *eof = 1;
  72. *start = page + off;
  73. len -= off;
  74. if (len>count) len = count;
  75. if (len<0) len = 0;
  76. return len;
  77. }
  78. /*--------------------------------------------------------------------*/
  79. static int mca_default_procfn(char* buf, struct mca_device *mca_dev)
  80. {
  81. int len = 0, i;
  82. int slot = mca_dev->slot;
  83. /* Print out the basic information */
  84. if(slot < MCA_MAX_SLOT_NR) {
  85. len += sprintf(buf+len, "Slot: %d\n", slot+1);
  86. } else if(slot == MCA_INTEGSCSI) {
  87. len += sprintf(buf+len, "Integrated SCSI Adapter\n");
  88. } else if(slot == MCA_INTEGVIDEO) {
  89. len += sprintf(buf+len, "Integrated Video Adapter\n");
  90. } else if(slot == MCA_MOTHERBOARD) {
  91. len += sprintf(buf+len, "Motherboard\n");
  92. }
  93. if (mca_dev->name[0]) {
  94. /* Drivers might register a name without /proc handler... */
  95. len += sprintf(buf+len, "Adapter Name: %s\n",
  96. mca_dev->name);
  97. } else {
  98. len += sprintf(buf+len, "Adapter Name: Unknown\n");
  99. }
  100. len += sprintf(buf+len, "Id: %02x%02x\n",
  101. mca_dev->pos[1], mca_dev->pos[0]);
  102. len += sprintf(buf+len, "Enabled: %s\nPOS: ",
  103. mca_device_status(mca_dev) == MCA_ADAPTER_NORMAL ?
  104. "Yes" : "No");
  105. for(i=0; i<8; i++) {
  106. len += sprintf(buf+len, "%02x ", mca_dev->pos[i]);
  107. }
  108. len += sprintf(buf+len, "\nDriver Installed: %s",
  109. mca_device_claimed(mca_dev) ? "Yes" : "No");
  110. buf[len++] = '\n';
  111. buf[len] = 0;
  112. return len;
  113. } /* mca_default_procfn() */
  114. static int get_mca_machine_info(char* page, char **start, off_t off,
  115. int count, int *eof, void *data)
  116. {
  117. int len = 0;
  118. len += sprintf(page+len, "Model Id: 0x%x\n", machine_id);
  119. len += sprintf(page+len, "Submodel Id: 0x%x\n", machine_submodel_id);
  120. len += sprintf(page+len, "BIOS Revision: 0x%x\n", BIOS_revision);
  121. if (len <= off+count) *eof = 1;
  122. *start = page + off;
  123. len -= off;
  124. if (len>count) len = count;
  125. if (len<0) len = 0;
  126. return len;
  127. }
  128. static int mca_read_proc(char *page, char **start, off_t off,
  129. int count, int *eof, void *data)
  130. {
  131. struct mca_device *mca_dev = (struct mca_device *)data;
  132. int len = 0;
  133. /* Get the standard info */
  134. len = mca_default_procfn(page, mca_dev);
  135. /* Do any device-specific processing, if there is any */
  136. if(mca_dev->procfn) {
  137. len += mca_dev->procfn(page+len, mca_dev->slot,
  138. mca_dev->proc_dev);
  139. }
  140. if (len <= off+count) *eof = 1;
  141. *start = page + off;
  142. len -= off;
  143. if (len>count) len = count;
  144. if (len<0) len = 0;
  145. return len;
  146. } /* mca_read_proc() */
  147. /*--------------------------------------------------------------------*/
  148. void __init mca_do_proc_init(void)
  149. {
  150. int i;
  151. struct proc_dir_entry *proc_mca;
  152. struct proc_dir_entry* node = NULL;
  153. struct mca_device *mca_dev;
  154. proc_mca = proc_mkdir("mca", NULL);
  155. create_proc_read_entry("pos",0,proc_mca,get_mca_info,NULL);
  156. create_proc_read_entry("machine",0,proc_mca,get_mca_machine_info,NULL);
  157. /* Initialize /proc/mca entries for existing adapters */
  158. for(i = 0; i < MCA_NUMADAPTERS; i++) {
  159. enum MCA_AdapterStatus status;
  160. mca_dev = mca_find_device_by_slot(i);
  161. if(!mca_dev)
  162. continue;
  163. mca_dev->procfn = NULL;
  164. if(i < MCA_MAX_SLOT_NR) sprintf(mca_dev->procname,"slot%d", i+1);
  165. else if(i == MCA_INTEGVIDEO) sprintf(mca_dev->procname,"video");
  166. else if(i == MCA_INTEGSCSI) sprintf(mca_dev->procname,"scsi");
  167. else if(i == MCA_MOTHERBOARD) sprintf(mca_dev->procname,"planar");
  168. status = mca_device_status(mca_dev);
  169. if (status != MCA_ADAPTER_NORMAL &&
  170. status != MCA_ADAPTER_DISABLED)
  171. continue;
  172. node = create_proc_read_entry(mca_dev->procname, 0, proc_mca,
  173. mca_read_proc, (void *)mca_dev);
  174. if(node == NULL) {
  175. printk("Failed to allocate memory for MCA proc-entries!");
  176. return;
  177. }
  178. }
  179. } /* mca_do_proc_init() */
  180. /**
  181. * mca_set_adapter_procfn - Set the /proc callback
  182. * @slot: slot to configure
  183. * @procfn: callback function to call for /proc
  184. * @dev: device information passed to the callback
  185. *
  186. * This sets up an information callback for /proc/mca/slot?. The
  187. * function is called with the buffer, slot, and device pointer (or
  188. * some equally informative context information, or nothing, if you
  189. * prefer), and is expected to put useful information into the
  190. * buffer. The adapter name, ID, and POS registers get printed
  191. * before this is called though, so don't do it again.
  192. *
  193. * This should be called with a %NULL @procfn when a module
  194. * unregisters, thus preventing kernel crashes and other such
  195. * nastiness.
  196. */
  197. void mca_set_adapter_procfn(int slot, MCA_ProcFn procfn, void* proc_dev)
  198. {
  199. struct mca_device *mca_dev = mca_find_device_by_slot(slot);
  200. if(!mca_dev)
  201. return;
  202. mca_dev->procfn = procfn;
  203. mca_dev->proc_dev = proc_dev;
  204. }
  205. EXPORT_SYMBOL(mca_set_adapter_procfn);