1 /* -*- mode: c; c-basic-offset: 8 -*- */
 
   4  * MCA bus support functions for the proc fs.
 
   6  * NOTE: this code *requires* the legacy MCA api.
 
   8  * Legacy API means the API that operates in terms of MCA slot number
 
  10  * (C) 2002 James Bottomley <James.Bottomley@HansenPartnership.com>
 
  12 **-----------------------------------------------------------------------------
 
  14 **  This program is free software; you can redistribute it and/or modify
 
  15 **  it under the terms of the GNU General Public License as published by
 
  16 **  the Free Software Foundation; either version 2 of the License, or
 
  17 **  (at your option) any later version.
 
  19 **  This program is distributed in the hope that it will be useful,
 
  20 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
  21 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  22 **  GNU General Public License for more details.
 
  24 **  You should have received a copy of the GNU General Public License
 
  25 **  along with this program; if not, write to the Free Software
 
  26 **  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
  28 **-----------------------------------------------------------------------------
 
  30 #include <linux/module.h>
 
  31 #include <linux/init.h>
 
  32 #include <linux/proc_fs.h>
 
  33 #include <linux/mca.h>
 
  35 static int get_mca_info_helper(struct mca_device *mca_dev, char *page, int len)
 
  40                 len += sprintf(page+len, "%02x ",
 
  41                                mca_dev ? mca_dev->pos[j] : 0xff);
 
  42         len += sprintf(page+len, " %s\n", mca_dev ? mca_dev->name : "");
 
  46 static int get_mca_info(char *page, char **start, off_t off,
 
  47                         int count, int *eof, void *data)
 
  52                 struct mca_device *mca_dev;
 
  53                 /* Format POS registers of eight MCA slots */
 
  55                 for(i=0; i<MCA_MAX_SLOT_NR; i++) {
 
  56                         mca_dev = mca_find_device_by_slot(i);
 
  58                         len += sprintf(page+len, "Slot %d: ", i+1);
 
  59                         len = get_mca_info_helper(mca_dev, page, len);
 
  62                 /* Format POS registers of integrated video subsystem */
 
  64                 mca_dev = mca_find_device_by_slot(MCA_INTEGVIDEO);
 
  65                 len += sprintf(page+len, "Video : ");
 
  66                 len = get_mca_info_helper(mca_dev, page, len);
 
  68                 /* Format POS registers of integrated SCSI subsystem */
 
  70                 mca_dev = mca_find_device_by_slot(MCA_INTEGSCSI);
 
  71                 len += sprintf(page+len, "SCSI  : ");
 
  72                 len = get_mca_info_helper(mca_dev, page, len);
 
  74                 /* Format POS registers of motherboard */
 
  76                 mca_dev = mca_find_device_by_slot(MCA_MOTHERBOARD);
 
  77                 len += sprintf(page+len, "Planar: ");
 
  78                 len = get_mca_info_helper(mca_dev, page, len);
 
  80                 /* Leave it empty if MCA not detected - this should *never*
 
  85         if (len <= off+count) *eof = 1;
 
  88         if (len>count) len = count;
 
  93 /*--------------------------------------------------------------------*/
 
  95 static int mca_default_procfn(char* buf, struct mca_device *mca_dev)
 
  98         int slot = mca_dev->slot;
 
 100         /* Print out the basic information */
 
 102         if(slot < MCA_MAX_SLOT_NR) {
 
 103                 len += sprintf(buf+len, "Slot: %d\n", slot+1);
 
 104         } else if(slot == MCA_INTEGSCSI) {
 
 105                 len += sprintf(buf+len, "Integrated SCSI Adapter\n");
 
 106         } else if(slot == MCA_INTEGVIDEO) {
 
 107                 len += sprintf(buf+len, "Integrated Video Adapter\n");
 
 108         } else if(slot == MCA_MOTHERBOARD) {
 
 109                 len += sprintf(buf+len, "Motherboard\n");
 
 111         if (mca_dev->name[0]) {
 
 113                 /* Drivers might register a name without /proc handler... */
 
 115                 len += sprintf(buf+len, "Adapter Name: %s\n",
 
 118                 len += sprintf(buf+len, "Adapter Name: Unknown\n");
 
 120         len += sprintf(buf+len, "Id: %02x%02x\n",
 
 121                 mca_dev->pos[1], mca_dev->pos[0]);
 
 122         len += sprintf(buf+len, "Enabled: %s\nPOS: ",
 
 123                 mca_device_status(mca_dev) == MCA_ADAPTER_NORMAL ?
 
 126                 len += sprintf(buf+len, "%02x ", mca_dev->pos[i]);
 
 128         len += sprintf(buf+len, "\nDriver Installed: %s",
 
 129                 mca_device_claimed(mca_dev) ? "Yes" : "No");
 
 134 } /* mca_default_procfn() */
 
 136 static int get_mca_machine_info(char* page, char **start, off_t off,
 
 137                                  int count, int *eof, void *data)
 
 141         len += sprintf(page+len, "Model Id: 0x%x\n", machine_id);
 
 142         len += sprintf(page+len, "Submodel Id: 0x%x\n", machine_submodel_id);
 
 143         len += sprintf(page+len, "BIOS Revision: 0x%x\n", BIOS_revision);
 
 145         if (len <= off+count) *eof = 1;
 
 148         if (len>count) len = count;
 
 153 static int mca_read_proc(char *page, char **start, off_t off,
 
 154                                  int count, int *eof, void *data)
 
 156         struct mca_device *mca_dev = (struct mca_device *)data;
 
 159         /* Get the standard info */
 
 161         len = mca_default_procfn(page, mca_dev);
 
 163         /* Do any device-specific processing, if there is any */
 
 165         if(mca_dev->procfn) {
 
 166                 len += mca_dev->procfn(page+len, mca_dev->slot,
 
 169         if (len <= off+count) *eof = 1;
 
 172         if (len>count) len = count;
 
 175 } /* mca_read_proc() */
 
 177 /*--------------------------------------------------------------------*/
 
 179 void __init mca_do_proc_init(void)
 
 182         struct proc_dir_entry *proc_mca;
 
 183         struct proc_dir_entry* node = NULL;
 
 184         struct mca_device *mca_dev;
 
 186         proc_mca = proc_mkdir("mca", &proc_root);
 
 187         create_proc_read_entry("pos",0,proc_mca,get_mca_info,NULL);
 
 188         create_proc_read_entry("machine",0,proc_mca,get_mca_machine_info,NULL);
 
 190         /* Initialize /proc/mca entries for existing adapters */
 
 192         for(i = 0; i < MCA_NUMADAPTERS; i++) {
 
 193                 enum MCA_AdapterStatus status;
 
 194                 mca_dev = mca_find_device_by_slot(i);
 
 198                 mca_dev->procfn = NULL;
 
 200                 if(i < MCA_MAX_SLOT_NR) sprintf(mca_dev->procname,"slot%d", i+1);
 
 201                 else if(i == MCA_INTEGVIDEO) sprintf(mca_dev->procname,"video");
 
 202                 else if(i == MCA_INTEGSCSI) sprintf(mca_dev->procname,"scsi");
 
 203                 else if(i == MCA_MOTHERBOARD) sprintf(mca_dev->procname,"planar");
 
 205                 status = mca_device_status(mca_dev);
 
 206                 if (status != MCA_ADAPTER_NORMAL &&
 
 207                     status != MCA_ADAPTER_DISABLED)
 
 210                 node = create_proc_read_entry(mca_dev->procname, 0, proc_mca,
 
 211                                               mca_read_proc, (void *)mca_dev);
 
 214                         printk("Failed to allocate memory for MCA proc-entries!");
 
 219 } /* mca_do_proc_init() */
 
 222  *      mca_set_adapter_procfn - Set the /proc callback
 
 223  *      @slot: slot to configure
 
 224  *      @procfn: callback function to call for /proc
 
 225  *      @dev: device information passed to the callback
 
 227  *      This sets up an information callback for /proc/mca/slot?.  The
 
 228  *      function is called with the buffer, slot, and device pointer (or
 
 229  *      some equally informative context information, or nothing, if you
 
 230  *      prefer), and is expected to put useful information into the
 
 231  *      buffer.  The adapter name, ID, and POS registers get printed
 
 232  *      before this is called though, so don't do it again.
 
 234  *      This should be called with a %NULL @procfn when a module
 
 235  *      unregisters, thus preventing kernel crashes and other such
 
 239 void mca_set_adapter_procfn(int slot, MCA_ProcFn procfn, void* proc_dev)
 
 241         struct mca_device *mca_dev = mca_find_device_by_slot(slot);
 
 246         mca_dev->procfn = procfn;
 
 247         mca_dev->proc_dev = proc_dev;
 
 249 EXPORT_SYMBOL(mca_set_adapter_procfn);