aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mca
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mca')
-rw-r--r--drivers/mca/Kconfig14
-rw-r--r--drivers/mca/Makefile7
-rw-r--r--drivers/mca/mca-bus.c169
-rw-r--r--drivers/mca/mca-device.c218
-rw-r--r--drivers/mca/mca-driver.c63
-rw-r--r--drivers/mca/mca-legacy.c329
-rw-r--r--drivers/mca/mca-proc.c249
7 files changed, 1049 insertions, 0 deletions
diff --git a/drivers/mca/Kconfig b/drivers/mca/Kconfig
new file mode 100644
index 00000000000..a7a0220ab4b
--- /dev/null
+++ b/drivers/mca/Kconfig
@@ -0,0 +1,14 @@
1config MCA_LEGACY
2 bool "Legacy MCA API Support"
3 depends on MCA
4 help
5 This compiles in support for the old slot based MCA API. If you
6 have an unconverted MCA driver, you will need to say Y here. It
7 is safe to say Y anyway.
8
9config MCA_PROC_FS
10 bool "Support for the mca entry in /proc"
11 depends on MCA_LEGACY && PROC_FS
12 help
13 If you want the old style /proc/mca directory in addition to the
14 new style sysfs say Y here.
diff --git a/drivers/mca/Makefile b/drivers/mca/Makefile
new file mode 100644
index 00000000000..0794b122520
--- /dev/null
+++ b/drivers/mca/Makefile
@@ -0,0 +1,7 @@
1# Makefile for the Linux MCA bus support
2
3obj-y := mca-bus.o mca-device.o mca-driver.o
4
5obj-$(CONFIG_MCA_PROC_FS) += mca-proc.o
6obj-$(CONFIG_MCA_LEGACY) += mca-legacy.o
7
diff --git a/drivers/mca/mca-bus.c b/drivers/mca/mca-bus.c
new file mode 100644
index 00000000000..ada5ebbaa25
--- /dev/null
+++ b/drivers/mca/mca-bus.c
@@ -0,0 +1,169 @@
1/* -*- mode: c; c-basic-offset: 8 -*- */
2
3/*
4 * MCA bus support functions for sysfs.
5 *
6 * (C) 2002 James Bottomley <James.Bottomley@HansenPartnership.com>
7 *
8**-----------------------------------------------------------------------------
9**
10** This program is free software; you can redistribute it and/or modify
11** it under the terms of the GNU General Public License as published by
12** the Free Software Foundation; either version 2 of the License, or
13** (at your option) any later version.
14**
15** This program is distributed in the hope that it will be useful,
16** but WITHOUT ANY WARRANTY; without even the implied warranty of
17** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18** GNU General Public License for more details.
19**
20** You should have received a copy of the GNU General Public License
21** along with this program; if not, write to the Free Software
22** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23**
24**-----------------------------------------------------------------------------
25 */
26
27#include <linux/kernel.h>
28#include <linux/device.h>
29#include <linux/mca.h>
30#include <linux/module.h>
31#include <linux/init.h>
32#include <linux/slab.h>
33
34/* Very few machines have more than one MCA bus. However, there are
35 * those that do (Voyager 35xx/5xxx), so we do it this way for future
36 * expansion. None that I know have more than 2 */
37static struct mca_bus *mca_root_busses[MAX_MCA_BUSSES];
38
39#define MCA_DEVINFO(i,s) { .pos = i, .name = s }
40
41struct mca_device_info {
42 short pos_id; /* the 2 byte pos id for this card */
43 char name[50];
44};
45
46static int mca_bus_match (struct device *dev, struct device_driver *drv)
47{
48 struct mca_device *mca_dev = to_mca_device (dev);
49 struct mca_driver *mca_drv = to_mca_driver (drv);
50 const unsigned short *mca_ids = mca_drv->id_table;
51 int i = 0;
52
53 if (mca_ids) {
54 for(i = 0; mca_ids[i]; i++) {
55 if (mca_ids[i] == mca_dev->pos_id) {
56 mca_dev->index = i;
57 return 1;
58 }
59 }
60 }
61 /* If the integrated id is present, treat it as though it were an
62 * additional id in the id_table (it can't be because by definition,
63 * integrated id's overflow a short */
64 if (mca_drv->integrated_id && mca_dev->pos_id ==
65 mca_drv->integrated_id) {
66 mca_dev->index = i;
67 return 1;
68 }
69 return 0;
70}
71
72struct bus_type mca_bus_type = {
73 .name = "MCA",
74 .match = mca_bus_match,
75};
76EXPORT_SYMBOL (mca_bus_type);
77
78static ssize_t mca_show_pos_id(struct device *dev, struct device_attribute *attr, char *buf)
79{
80 /* four digits, \n and trailing \0 */
81 struct mca_device *mca_dev = to_mca_device(dev);
82 int len;
83
84 if(mca_dev->pos_id < MCA_DUMMY_POS_START)
85 len = sprintf(buf, "%04x\n", mca_dev->pos_id);
86 else
87 len = sprintf(buf, "none\n");
88 return len;
89}
90static ssize_t mca_show_pos(struct device *dev, struct device_attribute *attr, char *buf)
91{
92 /* enough for 8 two byte hex chars plus space and new line */
93 int j, len=0;
94 struct mca_device *mca_dev = to_mca_device(dev);
95
96 for(j=0; j<8; j++)
97 len += sprintf(buf+len, "%02x ", mca_dev->pos[j]);
98 /* change last trailing space to new line */
99 buf[len-1] = '\n';
100 return len;
101}
102
103static DEVICE_ATTR(id, S_IRUGO, mca_show_pos_id, NULL);
104static DEVICE_ATTR(pos, S_IRUGO, mca_show_pos, NULL);
105
106int __init mca_register_device(int bus, struct mca_device *mca_dev)
107{
108 struct mca_bus *mca_bus = mca_root_busses[bus];
109 int rc;
110
111 mca_dev->dev.parent = &mca_bus->dev;
112 mca_dev->dev.bus = &mca_bus_type;
113 dev_set_name(&mca_dev->dev, "%02d:%02X", bus, mca_dev->slot);
114 mca_dev->dma_mask = mca_bus->default_dma_mask;
115 mca_dev->dev.dma_mask = &mca_dev->dma_mask;
116 mca_dev->dev.coherent_dma_mask = mca_dev->dma_mask;
117
118 rc = device_register(&mca_dev->dev);
119 if (rc)
120 goto err_out;
121
122 rc = device_create_file(&mca_dev->dev, &dev_attr_id);
123 if (rc) goto err_out_devreg;
124 rc = device_create_file(&mca_dev->dev, &dev_attr_pos);
125 if (rc) goto err_out_id;
126
127 return 1;
128
129err_out_id:
130 device_remove_file(&mca_dev->dev, &dev_attr_id);
131err_out_devreg:
132 device_unregister(&mca_dev->dev);
133err_out:
134 return 0;
135}
136
137/* */
138struct mca_bus * __devinit mca_attach_bus(int bus)
139{
140 struct mca_bus *mca_bus;
141
142 if (unlikely(mca_root_busses[bus] != NULL)) {
143 /* This should never happen, but just in case */
144 printk(KERN_EMERG "MCA tried to add already existing bus %d\n",
145 bus);
146 dump_stack();
147 return NULL;
148 }
149
150 mca_bus = kzalloc(sizeof(struct mca_bus), GFP_KERNEL);
151 if (!mca_bus)
152 return NULL;
153
154 dev_set_name(&mca_bus->dev, "mca%d", bus);
155 sprintf(mca_bus->name,"Host %s MCA Bridge", bus ? "Secondary" : "Primary");
156 if (device_register(&mca_bus->dev)) {
157 kfree(mca_bus);
158 return NULL;
159 }
160
161 mca_root_busses[bus] = mca_bus;
162
163 return mca_bus;
164}
165
166int __init mca_system_init (void)
167{
168 return bus_register(&mca_bus_type);
169}
diff --git a/drivers/mca/mca-device.c b/drivers/mca/mca-device.c
new file mode 100644
index 00000000000..e7adf89fae4
--- /dev/null
+++ b/drivers/mca/mca-device.c
@@ -0,0 +1,218 @@
1/* -*- mode: c; c-basic-offset: 8 -*- */
2
3/*
4 * MCA device support functions
5 *
6 * These functions support the ongoing device access API.
7 *
8 * (C) 2002 James Bottomley <James.Bottomley@HansenPartnership.com>
9 *
10**-----------------------------------------------------------------------------
11**
12** This program is free software; you can redistribute it and/or modify
13** it under the terms of the GNU General Public License as published by
14** the Free Software Foundation; either version 2 of the License, or
15** (at your option) any later version.
16**
17** This program is distributed in the hope that it will be useful,
18** but WITHOUT ANY WARRANTY; without even the implied warranty of
19** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20** GNU General Public License for more details.
21**
22** You should have received a copy of the GNU General Public License
23** along with this program; if not, write to the Free Software
24** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25**
26**-----------------------------------------------------------------------------
27 */
28
29#include <linux/module.h>
30#include <linux/device.h>
31#include <linux/mca.h>
32#include <linux/string.h>
33
34/**
35 * mca_device_read_stored_pos - read POS register from stored data
36 * @mca_dev: device to read from
37 * @reg: register to read from
38 *
39 * Fetch a POS value that was stored at boot time by the kernel
40 * when it scanned the MCA space. The register value is returned.
41 * Missing or invalid registers report 0.
42 */
43unsigned char mca_device_read_stored_pos(struct mca_device *mca_dev, int reg)
44{
45 if(reg < 0 || reg >= 8)
46 return 0;
47
48 return mca_dev->pos[reg];
49}
50EXPORT_SYMBOL(mca_device_read_stored_pos);
51
52/**
53 * mca_device_read_pos - read POS register from card
54 * @mca_dev: device to read from
55 * @reg: register to read from
56 *
57 * Fetch a POS value directly from the hardware to obtain the
58 * current value. This is much slower than
59 * mca_device_read_stored_pos and may not be invoked from
60 * interrupt context. It handles the deep magic required for
61 * onboard devices transparently.
62 */
63unsigned char mca_device_read_pos(struct mca_device *mca_dev, int reg)
64{
65 struct mca_bus *mca_bus = to_mca_bus(mca_dev->dev.parent);
66
67 return mca_bus->f.mca_read_pos(mca_dev, reg);
68
69 return mca_dev->pos[reg];
70}
71EXPORT_SYMBOL(mca_device_read_pos);
72
73
74/**
75 * mca_device_write_pos - read POS register from card
76 * @mca_dev: device to write pos register to
77 * @reg: register to write to
78 * @byte: byte to write to the POS registers
79 *
80 * Store a POS value directly to the hardware. You should not
81 * normally need to use this function and should have a very good
82 * knowledge of MCA bus before you do so. Doing this wrongly can
83 * damage the hardware.
84 *
85 * This function may not be used from interrupt context.
86 *
87 */
88void mca_device_write_pos(struct mca_device *mca_dev, int reg,
89 unsigned char byte)
90{
91 struct mca_bus *mca_bus = to_mca_bus(mca_dev->dev.parent);
92
93 mca_bus->f.mca_write_pos(mca_dev, reg, byte);
94}
95EXPORT_SYMBOL(mca_device_write_pos);
96
97/**
98 * mca_device_transform_irq - transform the ADF obtained IRQ
99 * @mca_device: device whose irq needs transforming
100 * @irq: input irq from ADF
101 *
102 * MCA Adapter Definition Files (ADF) contain irq, ioport, memory
103 * etc. definitions. In systems with more than one bus, these need
104 * to be transformed through bus mapping functions to get the real
105 * system global quantities.
106 *
107 * This function transforms the interrupt number and returns the
108 * transformed system global interrupt
109 */
110int mca_device_transform_irq(struct mca_device *mca_dev, int irq)
111{
112 struct mca_bus *mca_bus = to_mca_bus(mca_dev->dev.parent);
113
114 return mca_bus->f.mca_transform_irq(mca_dev, irq);
115}
116EXPORT_SYMBOL(mca_device_transform_irq);
117
118/**
119 * mca_device_transform_ioport - transform the ADF obtained I/O port
120 * @mca_device: device whose port needs transforming
121 * @ioport: input I/O port from ADF
122 *
123 * MCA Adapter Definition Files (ADF) contain irq, ioport, memory
124 * etc. definitions. In systems with more than one bus, these need
125 * to be transformed through bus mapping functions to get the real
126 * system global quantities.
127 *
128 * This function transforms the I/O port number and returns the
129 * transformed system global port number.
130 *
131 * This transformation can be assumed to be linear for port ranges.
132 */
133int mca_device_transform_ioport(struct mca_device *mca_dev, int port)
134{
135 struct mca_bus *mca_bus = to_mca_bus(mca_dev->dev.parent);
136
137 return mca_bus->f.mca_transform_ioport(mca_dev, port);
138}
139EXPORT_SYMBOL(mca_device_transform_ioport);
140
141/**
142 * mca_device_transform_memory - transform the ADF obtained memory
143 * @mca_device: device whose memory region needs transforming
144 * @mem: memory region start from ADF
145 *
146 * MCA Adapter Definition Files (ADF) contain irq, ioport, memory
147 * etc. definitions. In systems with more than one bus, these need
148 * to be transformed through bus mapping functions to get the real
149 * system global quantities.
150 *
151 * This function transforms the memory region start and returns the
152 * transformed system global memory region (physical).
153 *
154 * This transformation can be assumed to be linear for region ranges.
155 */
156void *mca_device_transform_memory(struct mca_device *mca_dev, void *mem)
157{
158 struct mca_bus *mca_bus = to_mca_bus(mca_dev->dev.parent);
159
160 return mca_bus->f.mca_transform_memory(mca_dev, mem);
161}
162EXPORT_SYMBOL(mca_device_transform_memory);
163
164
165/**
166 * mca_device_claimed - check if claimed by driver
167 * @mca_dev: device to check
168 *
169 * Returns 1 if the slot has been claimed by a driver
170 */
171
172int mca_device_claimed(struct mca_device *mca_dev)
173{
174 return mca_dev->driver_loaded;
175}
176EXPORT_SYMBOL(mca_device_claimed);
177
178/**
179 * mca_device_set_claim - set the claim value of the driver
180 * @mca_dev: device to set value for
181 * @val: claim value to set (1 claimed, 0 unclaimed)
182 */
183void mca_device_set_claim(struct mca_device *mca_dev, int val)
184{
185 mca_dev->driver_loaded = val;
186}
187EXPORT_SYMBOL(mca_device_set_claim);
188
189/**
190 * mca_device_status - get the status of the device
191 * @mca_device: device to get
192 *
193 * returns an enumeration of the device status:
194 *
195 * MCA_ADAPTER_NORMAL adapter is OK.
196 * MCA_ADAPTER_NONE no adapter at device (should never happen).
197 * MCA_ADAPTER_DISABLED adapter is disabled.
198 * MCA_ADAPTER_ERROR adapter cannot be initialised.
199 */
200enum MCA_AdapterStatus mca_device_status(struct mca_device *mca_dev)
201{
202 return mca_dev->status;
203}
204EXPORT_SYMBOL(mca_device_status);
205
206/**
207 * mca_device_set_name - set the name of the device
208 * @mca_device: device to set the name of
209 * @name: name to set
210 */
211void mca_device_set_name(struct mca_device *mca_dev, const char *name)
212{
213 if(!mca_dev)
214 return;
215
216 strlcpy(mca_dev->name, name, sizeof(mca_dev->name));
217}
218EXPORT_SYMBOL(mca_device_set_name);
diff --git a/drivers/mca/mca-driver.c b/drivers/mca/mca-driver.c
new file mode 100644
index 00000000000..32cd39bcc71
--- /dev/null
+++ b/drivers/mca/mca-driver.c
@@ -0,0 +1,63 @@
1/* -*- mode: c; c-basic-offset: 8 -*- */
2
3/*
4 * MCA driver support functions for sysfs.
5 *
6 * (C) 2002 James Bottomley <James.Bottomley@HansenPartnership.com>
7 *
8**-----------------------------------------------------------------------------
9**
10** This program is free software; you can redistribute it and/or modify
11** it under the terms of the GNU General Public License as published by
12** the Free Software Foundation; either version 2 of the License, or
13** (at your option) any later version.
14**
15** This program is distributed in the hope that it will be useful,
16** but WITHOUT ANY WARRANTY; without even the implied warranty of
17** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18** GNU General Public License for more details.
19**
20** You should have received a copy of the GNU General Public License
21** along with this program; if not, write to the Free Software
22** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23**
24**-----------------------------------------------------------------------------
25 */
26
27#include <linux/device.h>
28#include <linux/mca.h>
29#include <linux/module.h>
30
31int mca_register_driver(struct mca_driver *mca_drv)
32{
33 int r;
34
35 if (MCA_bus) {
36 mca_drv->driver.bus = &mca_bus_type;
37 if ((r = driver_register(&mca_drv->driver)) < 0)
38 return r;
39 mca_drv->integrated_id = 0;
40 }
41
42 return 0;
43}
44EXPORT_SYMBOL(mca_register_driver);
45
46int mca_register_driver_integrated(struct mca_driver *mca_driver,
47 int integrated_id)
48{
49 int r = mca_register_driver(mca_driver);
50
51 if (!r)
52 mca_driver->integrated_id = integrated_id;
53
54 return r;
55}
56EXPORT_SYMBOL(mca_register_driver_integrated);
57
58void mca_unregister_driver(struct mca_driver *mca_drv)
59{
60 if (MCA_bus)
61 driver_unregister(&mca_drv->driver);
62}
63EXPORT_SYMBOL(mca_unregister_driver);
diff --git a/drivers/mca/mca-legacy.c b/drivers/mca/mca-legacy.c
new file mode 100644
index 00000000000..494f0c2001f
--- /dev/null
+++ b/drivers/mca/mca-legacy.c
@@ -0,0 +1,329 @@
1/* -*- mode: c; c-basic-offset: 8 -*- */
2
3/*
4 * MCA bus support functions for legacy (2.4) API.
5 *
6 * Legacy API means the API that operates in terms of MCA slot number
7 *
8 * (C) 2002 James Bottomley <James.Bottomley@HansenPartnership.com>
9 *
10**-----------------------------------------------------------------------------
11**
12** This program is free software; you can redistribute it and/or modify
13** it under the terms of the GNU General Public License as published by
14** the Free Software Foundation; either version 2 of the License, or
15** (at your option) any later version.
16**
17** This program is distributed in the hope that it will be useful,
18** but WITHOUT ANY WARRANTY; without even the implied warranty of
19** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20** GNU General Public License for more details.
21**
22** You should have received a copy of the GNU General Public License
23** along with this program; if not, write to the Free Software
24** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25**
26**-----------------------------------------------------------------------------
27 */
28
29#include <linux/module.h>
30#include <linux/device.h>
31#include <linux/mca-legacy.h>
32#include <asm/io.h>
33
34/* NOTE: This structure is stack allocated */
35struct mca_find_adapter_info {
36 int id;
37 int slot;
38 struct mca_device *mca_dev;
39};
40
41/* The purpose of this iterator is to loop over all the devices and
42 * find the one with the smallest slot number that's just greater than
43 * or equal to the required slot with a matching id */
44static int mca_find_adapter_callback(struct device *dev, void *data)
45{
46 struct mca_find_adapter_info *info = data;
47 struct mca_device *mca_dev = to_mca_device(dev);
48
49 if(mca_dev->pos_id != info->id)
50 return 0;
51
52 if(mca_dev->slot < info->slot)
53 return 0;
54
55 if(!info->mca_dev || info->mca_dev->slot >= mca_dev->slot)
56 info->mca_dev = mca_dev;
57
58 return 0;
59}
60
61/**
62 * mca_find_adapter - scan for adapters
63 * @id: MCA identification to search for
64 * @start: starting slot
65 *
66 * Search the MCA configuration for adapters matching the 16bit
67 * ID given. The first time it should be called with start as zero
68 * and then further calls made passing the return value of the
69 * previous call until %MCA_NOTFOUND is returned.
70 *
71 * Disabled adapters are not reported.
72 */
73
74int mca_find_adapter(int id, int start)
75{
76 struct mca_find_adapter_info info;
77
78 if(id == 0xffff)
79 return MCA_NOTFOUND;
80
81 info.slot = start;
82 info.id = id;
83 info.mca_dev = NULL;
84
85 for(;;) {
86 bus_for_each_dev(&mca_bus_type, NULL, &info, mca_find_adapter_callback);
87
88 if(info.mca_dev == NULL)
89 return MCA_NOTFOUND;
90
91 if(info.mca_dev->status != MCA_ADAPTER_DISABLED)
92 break;
93
94 /* OK, found adapter but it was disabled. Go around
95 * again, excluding the slot we just found */
96
97 info.slot = info.mca_dev->slot + 1;
98 info.mca_dev = NULL;
99 }
100
101 return info.mca_dev->slot;
102}
103EXPORT_SYMBOL(mca_find_adapter);
104
105/*--------------------------------------------------------------------*/
106
107/**
108 * mca_find_unused_adapter - scan for unused adapters
109 * @id: MCA identification to search for
110 * @start: starting slot
111 *
112 * Search the MCA configuration for adapters matching the 16bit
113 * ID given. The first time it should be called with start as zero
114 * and then further calls made passing the return value of the
115 * previous call until %MCA_NOTFOUND is returned.
116 *
117 * Adapters that have been claimed by drivers and those that
118 * are disabled are not reported. This function thus allows a driver
119 * to scan for further cards when some may already be driven.
120 */
121
122int mca_find_unused_adapter(int id, int start)
123{
124 struct mca_find_adapter_info info = { 0 };
125
126 if (!MCA_bus || id == 0xffff)
127 return MCA_NOTFOUND;
128
129 info.slot = start;
130 info.id = id;
131 info.mca_dev = NULL;
132
133 for(;;) {
134 bus_for_each_dev(&mca_bus_type, NULL, &info, mca_find_adapter_callback);
135
136 if(info.mca_dev == NULL)
137 return MCA_NOTFOUND;
138
139 if(info.mca_dev->status != MCA_ADAPTER_DISABLED
140 && !info.mca_dev->driver_loaded)
141 break;
142
143 /* OK, found adapter but it was disabled or already in
144 * use. Go around again, excluding the slot we just
145 * found */
146
147 info.slot = info.mca_dev->slot + 1;
148 info.mca_dev = NULL;
149 }
150
151 return info.mca_dev->slot;
152}
153EXPORT_SYMBOL(mca_find_unused_adapter);
154
155/* NOTE: stack allocated structure */
156struct mca_find_device_by_slot_info {
157 int slot;
158 struct mca_device *mca_dev;
159};
160
161static int mca_find_device_by_slot_callback(struct device *dev, void *data)
162{
163 struct mca_find_device_by_slot_info *info = data;
164 struct mca_device *mca_dev = to_mca_device(dev);
165
166 if(mca_dev->slot == info->slot)
167 info->mca_dev = mca_dev;
168
169 return 0;
170}
171
172struct mca_device *mca_find_device_by_slot(int slot)
173{
174 struct mca_find_device_by_slot_info info;
175
176 info.slot = slot;
177 info.mca_dev = NULL;
178
179 bus_for_each_dev(&mca_bus_type, NULL, &info, mca_find_device_by_slot_callback);
180
181 return info.mca_dev;
182}
183
184/**
185 * mca_read_stored_pos - read POS register from boot data
186 * @slot: slot number to read from
187 * @reg: register to read from
188 *
189 * Fetch a POS value that was stored at boot time by the kernel
190 * when it scanned the MCA space. The register value is returned.
191 * Missing or invalid registers report 0.
192 */
193unsigned char mca_read_stored_pos(int slot, int reg)
194{
195 struct mca_device *mca_dev = mca_find_device_by_slot(slot);
196
197 if(!mca_dev)
198 return 0;
199
200 return mca_device_read_stored_pos(mca_dev, reg);
201}
202EXPORT_SYMBOL(mca_read_stored_pos);
203
204
205/**
206 * mca_read_pos - read POS register from card
207 * @slot: slot number to read from
208 * @reg: register to read from
209 *
210 * Fetch a POS value directly from the hardware to obtain the
211 * current value. This is much slower than mca_read_stored_pos and
212 * may not be invoked from interrupt context. It handles the
213 * deep magic required for onboard devices transparently.
214 */
215
216unsigned char mca_read_pos(int slot, int reg)
217{
218 struct mca_device *mca_dev = mca_find_device_by_slot(slot);
219
220 if(!mca_dev)
221 return 0;
222
223 return mca_device_read_pos(mca_dev, reg);
224}
225EXPORT_SYMBOL(mca_read_pos);
226
227
228/**
229 * mca_write_pos - read POS register from card
230 * @slot: slot number to read from
231 * @reg: register to read from
232 * @byte: byte to write to the POS registers
233 *
234 * Store a POS value directly from the hardware. You should not
235 * normally need to use this function and should have a very good
236 * knowledge of MCA bus before you do so. Doing this wrongly can
237 * damage the hardware.
238 *
239 * This function may not be used from interrupt context.
240 *
241 * Note that this a technically a Bad Thing, as IBM tech stuff says
242 * you should only set POS values through their utilities.
243 * However, some devices such as the 3c523 recommend that you write
244 * back some data to make sure the configuration is consistent.
245 * I'd say that IBM is right, but I like my drivers to work.
246 *
247 * This function can't do checks to see if multiple devices end up
248 * with the same resources, so you might see magic smoke if someone
249 * screws up.
250 */
251
252void mca_write_pos(int slot, int reg, unsigned char byte)
253{
254 struct mca_device *mca_dev = mca_find_device_by_slot(slot);
255
256 if(!mca_dev)
257 return;
258
259 mca_device_write_pos(mca_dev, reg, byte);
260}
261EXPORT_SYMBOL(mca_write_pos);
262
263/**
264 * mca_set_adapter_name - Set the description of the card
265 * @slot: slot to name
266 * @name: text string for the namen
267 *
268 * This function sets the name reported via /proc for this
269 * adapter slot. This is for user information only. Setting a
270 * name deletes any previous name.
271 */
272
273void mca_set_adapter_name(int slot, char* name)
274{
275 struct mca_device *mca_dev = mca_find_device_by_slot(slot);
276
277 if(!mca_dev)
278 return;
279
280 mca_device_set_name(mca_dev, name);
281}
282EXPORT_SYMBOL(mca_set_adapter_name);
283
284/**
285 * mca_mark_as_used - claim an MCA device
286 * @slot: slot to claim
287 * FIXME: should we make this threadsafe
288 *
289 * Claim an MCA slot for a device driver. If the
290 * slot is already taken the function returns 1,
291 * if it is not taken it is claimed and 0 is
292 * returned.
293 */
294
295int mca_mark_as_used(int slot)
296{
297 struct mca_device *mca_dev = mca_find_device_by_slot(slot);
298
299 if(!mca_dev)
300 /* FIXME: this is actually a severe error */
301 return 1;
302
303 if(mca_device_claimed(mca_dev))
304 return 1;
305
306 mca_device_set_claim(mca_dev, 1);
307
308 return 0;
309}
310EXPORT_SYMBOL(mca_mark_as_used);
311
312/**
313 * mca_mark_as_unused - release an MCA device
314 * @slot: slot to claim
315 *
316 * Release the slot for other drives to use.
317 */
318
319void mca_mark_as_unused(int slot)
320{
321 struct mca_device *mca_dev = mca_find_device_by_slot(slot);
322
323 if(!mca_dev)
324 return;
325
326 mca_device_set_claim(mca_dev, 0);
327}
328EXPORT_SYMBOL(mca_mark_as_unused);
329
diff --git a/drivers/mca/mca-proc.c b/drivers/mca/mca-proc.c
new file mode 100644
index 00000000000..81ea0d377bf
--- /dev/null
+++ b/drivers/mca/mca-proc.c
@@ -0,0 +1,249 @@
1/* -*- mode: c; c-basic-offset: 8 -*- */
2
3/*
4 * MCA bus support functions for the proc fs.
5 *
6 * NOTE: this code *requires* the legacy MCA api.
7 *
8 * Legacy API means the API that operates in terms of MCA slot number
9 *
10 * (C) 2002 James Bottomley <James.Bottomley@HansenPartnership.com>
11 *
12**-----------------------------------------------------------------------------
13**
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.
18**
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.
23**
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.
27**
28**-----------------------------------------------------------------------------
29 */
30#include <linux/module.h>
31#include <linux/init.h>
32#include <linux/proc_fs.h>
33#include <linux/mca.h>
34
35static int get_mca_info_helper(struct mca_device *mca_dev, char *page, int len)
36{
37 int j;
38
39 for(j=0; j<8; j++)
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 : "");
43 return len;
44}
45
46static int get_mca_info(char *page, char **start, off_t off,
47 int count, int *eof, void *data)
48{
49 int i, len = 0;
50
51 if(MCA_bus) {
52 struct mca_device *mca_dev;
53 /* Format POS registers of eight MCA slots */
54
55 for(i=0; i<MCA_MAX_SLOT_NR; i++) {
56 mca_dev = mca_find_device_by_slot(i);
57
58 len += sprintf(page+len, "Slot %d: ", i+1);
59 len = get_mca_info_helper(mca_dev, page, len);
60 }
61
62 /* Format POS registers of integrated video subsystem */
63
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);
67
68 /* Format POS registers of integrated SCSI subsystem */
69
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);
73
74 /* Format POS registers of motherboard */
75
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);
79 } else {
80 /* Leave it empty if MCA not detected - this should *never*
81 * happen!
82 */
83 }
84
85 if (len <= off+count) *eof = 1;
86 *start = page + off;
87 len -= off;
88 if (len>count) len = count;
89 if (len<0) len = 0;
90 return len;
91}
92
93/*--------------------------------------------------------------------*/
94
95static int mca_default_procfn(char* buf, struct mca_device *mca_dev)
96{
97 int len = 0, i;
98 int slot = mca_dev->slot;
99
100 /* Print out the basic information */
101
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");
110 }
111 if (mca_dev->name[0]) {
112
113 /* Drivers might register a name without /proc handler... */
114
115 len += sprintf(buf+len, "Adapter Name: %s\n",
116 mca_dev->name);
117 } else {
118 len += sprintf(buf+len, "Adapter Name: Unknown\n");
119 }
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 ?
124 "Yes" : "No");
125 for(i=0; i<8; i++) {
126 len += sprintf(buf+len, "%02x ", mca_dev->pos[i]);
127 }
128 len += sprintf(buf+len, "\nDriver Installed: %s",
129 mca_device_claimed(mca_dev) ? "Yes" : "No");
130 buf[len++] = '\n';
131 buf[len] = 0;
132
133 return len;
134} /* mca_default_procfn() */
135
136static int get_mca_machine_info(char* page, char **start, off_t off,
137 int count, int *eof, void *data)
138{
139 int len = 0;
140
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);
144
145 if (len <= off+count) *eof = 1;
146 *start = page + off;
147 len -= off;
148 if (len>count) len = count;
149 if (len<0) len = 0;
150 return len;
151}
152
153static int mca_read_proc(char *page, char **start, off_t off,
154 int count, int *eof, void *data)
155{
156 struct mca_device *mca_dev = (struct mca_device *)data;
157 int len = 0;
158
159 /* Get the standard info */
160
161 len = mca_default_procfn(page, mca_dev);
162
163 /* Do any device-specific processing, if there is any */
164
165 if(mca_dev->procfn) {
166 len += mca_dev->procfn(page+len, mca_dev->slot,
167 mca_dev->proc_dev);
168 }
169 if (len <= off+count) *eof = 1;
170 *start = page + off;
171 len -= off;
172 if (len>count) len = count;
173 if (len<0) len = 0;
174 return len;
175} /* mca_read_proc() */
176
177/*--------------------------------------------------------------------*/
178
179void __init mca_do_proc_init(void)
180{
181 int i;
182 struct proc_dir_entry *proc_mca;
183 struct proc_dir_entry* node = NULL;
184 struct mca_device *mca_dev;
185
186 proc_mca = proc_mkdir("mca", NULL);
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);
189
190 /* Initialize /proc/mca entries for existing adapters */
191
192 for(i = 0; i < MCA_NUMADAPTERS; i++) {
193 enum MCA_AdapterStatus status;
194 mca_dev = mca_find_device_by_slot(i);
195 if(!mca_dev)
196 continue;
197
198 mca_dev->procfn = NULL;
199
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");
204
205 status = mca_device_status(mca_dev);
206 if (status != MCA_ADAPTER_NORMAL &&
207 status != MCA_ADAPTER_DISABLED)
208 continue;
209
210 node = create_proc_read_entry(mca_dev->procname, 0, proc_mca,
211 mca_read_proc, (void *)mca_dev);
212
213 if(node == NULL) {
214 printk("Failed to allocate memory for MCA proc-entries!");
215 return;
216 }
217 }
218
219} /* mca_do_proc_init() */
220
221/**
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
226 *
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.
233 *
234 * This should be called with a %NULL @procfn when a module
235 * unregisters, thus preventing kernel crashes and other such
236 * nastiness.
237 */
238
239void mca_set_adapter_procfn(int slot, MCA_ProcFn procfn, void* proc_dev)
240{
241 struct mca_device *mca_dev = mca_find_device_by_slot(slot);
242
243 if(!mca_dev)
244 return;
245
246 mca_dev->procfn = procfn;
247 mca_dev->proc_dev = proc_dev;
248}
249EXPORT_SYMBOL(mca_set_adapter_procfn);