aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mca/mca-device.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/mca/mca-device.c
Linux-2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'drivers/mca/mca-device.c')
-rw-r--r--drivers/mca/mca-device.c217
1 files changed, 217 insertions, 0 deletions
diff --git a/drivers/mca/mca-device.c b/drivers/mca/mca-device.c
new file mode 100644
index 00000000000..76d430aa243
--- /dev/null
+++ b/drivers/mca/mca-device.c
@@ -0,0 +1,217 @@
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
33/**
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
37 *
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.
41 */
42unsigned char mca_device_read_stored_pos(struct mca_device *mca_dev, int reg)
43{
44 if(reg < 0 || reg >= 8)
45 return 0;
46
47 return mca_dev->pos[reg];
48}
49EXPORT_SYMBOL(mca_device_read_stored_pos);
50
51/**
52 * mca_device_read_pos - read POS register from card
53 * @mca_dev: device to read from
54 * @reg: register to read from
55 *
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.
61 */
62unsigned char mca_device_read_pos(struct mca_device *mca_dev, int reg)
63{
64 struct mca_bus *mca_bus = to_mca_bus(mca_dev->dev.parent);
65
66 return mca_bus->f.mca_read_pos(mca_dev, reg);
67
68 return mca_dev->pos[reg];
69}
70EXPORT_SYMBOL(mca_device_read_pos);
71
72
73/**
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
78 *
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.
83 *
84 * This function may not be used from interrupt context.
85 *
86 */
87void mca_device_write_pos(struct mca_device *mca_dev, int reg,
88 unsigned char byte)
89{
90 struct mca_bus *mca_bus = to_mca_bus(mca_dev->dev.parent);
91
92 mca_bus->f.mca_write_pos(mca_dev, reg, byte);
93}
94EXPORT_SYMBOL(mca_device_write_pos);
95
96/**
97 * mca_device_transform_irq - transform the ADF obtained IRQ
98 * @mca_device: device whose irq needs transforming
99 * @irq: input irq from ADF
100 *
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.
105 *
106 * This function transforms the interrupt number and returns the
107 * transformed system global interrupt
108 */
109int mca_device_transform_irq(struct mca_device *mca_dev, int irq)
110{
111 struct mca_bus *mca_bus = to_mca_bus(mca_dev->dev.parent);
112
113 return mca_bus->f.mca_transform_irq(mca_dev, irq);
114}
115EXPORT_SYMBOL(mca_device_transform_irq);
116
117/**
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
121 *
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.
126 *
127 * This function transforms the I/O port number and returns the
128 * transformed system global port number.
129 *
130 * This transformation can be assumed to be linear for port ranges.
131 */
132int mca_device_transform_ioport(struct mca_device *mca_dev, int port)
133{
134 struct mca_bus *mca_bus = to_mca_bus(mca_dev->dev.parent);
135
136 return mca_bus->f.mca_transform_ioport(mca_dev, port);
137}
138EXPORT_SYMBOL(mca_device_transform_ioport);
139
140/**
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
144 *
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.
149 *
150 * This function transforms the memory region start and returns the
151 * transformed system global memory region (physical).
152 *
153 * This transformation can be assumed to be linear for region ranges.
154 */
155void *mca_device_transform_memory(struct mca_device *mca_dev, void *mem)
156{
157 struct mca_bus *mca_bus = to_mca_bus(mca_dev->dev.parent);
158
159 return mca_bus->f.mca_transform_memory(mca_dev, mem);
160}
161EXPORT_SYMBOL(mca_device_transform_memory);
162
163
164/**
165 * mca_device_claimed - check if claimed by driver
166 * @mca_dev: device to check
167 *
168 * Returns 1 if the slot has been claimed by a driver
169 */
170
171int mca_device_claimed(struct mca_device *mca_dev)
172{
173 return mca_dev->driver_loaded;
174}
175EXPORT_SYMBOL(mca_device_claimed);
176
177/**
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)
181 */
182void mca_device_set_claim(struct mca_device *mca_dev, int val)
183{
184 mca_dev->driver_loaded = val;
185}
186EXPORT_SYMBOL(mca_device_set_claim);
187
188/**
189 * mca_device_status - get the status of the device
190 * @mca_device: device to get
191 *
192 * returns an enumeration of the device status:
193 *
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.
198 */
199enum MCA_AdapterStatus mca_device_status(struct mca_device *mca_dev)
200{
201 return mca_dev->status;
202}
203EXPORT_SYMBOL(mca_device_status);
204
205/**
206 * mca_device_set_name - set the name of the device
207 * @mca_device: device to set the name of
208 * @name: name to set
209 */
210void mca_device_set_name(struct mca_device *mca_dev, const char *name)
211{
212 if(!mca_dev)
213 return;
214
215 strlcpy(mca_dev->name, name, sizeof(mca_dev->name));
216}
217EXPORT_SYMBOL(mca_device_set_name);