1 /* -*- mode: c; c-basic-offset: 8 -*- */
4 * MCA device support functions
6 * These functions support the ongoing device access API.
8 * (C) 2002 James Bottomley <James.Bottomley@HansenPartnership.com>
10 **-----------------------------------------------------------------------------
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.
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.
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.
26 **-----------------------------------------------------------------------------
29 #include <linux/module.h>
30 #include <linux/device.h>
31 #include <linux/mca.h>
34 * mca_device_read_stored_pos - read POS register from stored data
35 * @mca_dev: device to read from
36 * @reg: register to read from
38 * Fetch a POS value that was stored at boot time by the kernel
39 * when it scanned the MCA space. The register value is returned.
40 * Missing or invalid registers report 0.
42 unsigned char mca_device_read_stored_pos(struct mca_device *mca_dev, int reg)
44 if(reg < 0 || reg >= 8)
47 return mca_dev->pos[reg];
49 EXPORT_SYMBOL(mca_device_read_stored_pos);
52 * mca_device_read_pos - read POS register from card
53 * @mca_dev: device to read from
54 * @reg: register to read from
56 * Fetch a POS value directly from the hardware to obtain the
57 * current value. This is much slower than
58 * mca_device_read_stored_pos and may not be invoked from
59 * interrupt context. It handles the deep magic required for
60 * onboard devices transparently.
62 unsigned char mca_device_read_pos(struct mca_device *mca_dev, int reg)
64 struct mca_bus *mca_bus = to_mca_bus(mca_dev->dev.parent);
66 return mca_bus->f.mca_read_pos(mca_dev, reg);
68 return mca_dev->pos[reg];
70 EXPORT_SYMBOL(mca_device_read_pos);
74 * mca_device_write_pos - read POS register from card
75 * @mca_dev: device to write pos register to
76 * @reg: register to write to
77 * @byte: byte to write to the POS registers
79 * Store a POS value directly to the hardware. You should not
80 * normally need to use this function and should have a very good
81 * knowledge of MCA bus before you do so. Doing this wrongly can
82 * damage the hardware.
84 * This function may not be used from interrupt context.
87 void mca_device_write_pos(struct mca_device *mca_dev, int reg,
90 struct mca_bus *mca_bus = to_mca_bus(mca_dev->dev.parent);
92 mca_bus->f.mca_write_pos(mca_dev, reg, byte);
94 EXPORT_SYMBOL(mca_device_write_pos);
97 * mca_device_transform_irq - transform the ADF obtained IRQ
98 * @mca_device: device whose irq needs transforming
99 * @irq: input irq from ADF
101 * MCA Adapter Definition Files (ADF) contain irq, ioport, memory
102 * etc. definitions. In systems with more than one bus, these need
103 * to be transformed through bus mapping functions to get the real
104 * system global quantities.
106 * This function transforms the interrupt number and returns the
107 * transformed system global interrupt
109 int mca_device_transform_irq(struct mca_device *mca_dev, int irq)
111 struct mca_bus *mca_bus = to_mca_bus(mca_dev->dev.parent);
113 return mca_bus->f.mca_transform_irq(mca_dev, irq);
115 EXPORT_SYMBOL(mca_device_transform_irq);
118 * mca_device_transform_ioport - transform the ADF obtained I/O port
119 * @mca_device: device whose port needs transforming
120 * @ioport: input I/O port from ADF
122 * MCA Adapter Definition Files (ADF) contain irq, ioport, memory
123 * etc. definitions. In systems with more than one bus, these need
124 * to be transformed through bus mapping functions to get the real
125 * system global quantities.
127 * This function transforms the I/O port number and returns the
128 * transformed system global port number.
130 * This transformation can be assumed to be linear for port ranges.
132 int mca_device_transform_ioport(struct mca_device *mca_dev, int port)
134 struct mca_bus *mca_bus = to_mca_bus(mca_dev->dev.parent);
136 return mca_bus->f.mca_transform_ioport(mca_dev, port);
138 EXPORT_SYMBOL(mca_device_transform_ioport);
141 * mca_device_transform_memory - transform the ADF obtained memory
142 * @mca_device: device whose memory region needs transforming
143 * @mem: memory region start from ADF
145 * MCA Adapter Definition Files (ADF) contain irq, ioport, memory
146 * etc. definitions. In systems with more than one bus, these need
147 * to be transformed through bus mapping functions to get the real
148 * system global quantities.
150 * This function transforms the memory region start and returns the
151 * transformed system global memory region (physical).
153 * This transformation can be assumed to be linear for region ranges.
155 void *mca_device_transform_memory(struct mca_device *mca_dev, void *mem)
157 struct mca_bus *mca_bus = to_mca_bus(mca_dev->dev.parent);
159 return mca_bus->f.mca_transform_memory(mca_dev, mem);
161 EXPORT_SYMBOL(mca_device_transform_memory);
165 * mca_device_claimed - check if claimed by driver
166 * @mca_dev: device to check
168 * Returns 1 if the slot has been claimed by a driver
171 int mca_device_claimed(struct mca_device *mca_dev)
173 return mca_dev->driver_loaded;
175 EXPORT_SYMBOL(mca_device_claimed);
178 * mca_device_set_claim - set the claim value of the driver
179 * @mca_dev: device to set value for
180 * @val: claim value to set (1 claimed, 0 unclaimed)
182 void mca_device_set_claim(struct mca_device *mca_dev, int val)
184 mca_dev->driver_loaded = val;
186 EXPORT_SYMBOL(mca_device_set_claim);
189 * mca_device_status - get the status of the device
190 * @mca_device: device to get
192 * returns an enumeration of the device status:
194 * MCA_ADAPTER_NORMAL adapter is OK.
195 * MCA_ADAPTER_NONE no adapter at device (should never happen).
196 * MCA_ADAPTER_DISABLED adapter is disabled.
197 * MCA_ADAPTER_ERROR adapter cannot be initialised.
199 enum MCA_AdapterStatus mca_device_status(struct mca_device *mca_dev)
201 return mca_dev->status;
203 EXPORT_SYMBOL(mca_device_status);
206 * mca_device_set_name - set the name of the device
207 * @mca_device: device to set the name of
210 void mca_device_set_name(struct mca_device *mca_dev, const char *name)
215 strlcpy(mca_dev->name, name, sizeof(mca_dev->name));
217 EXPORT_SYMBOL(mca_device_set_name);