diff options
Diffstat (limited to 'drivers/pcmcia')
28 files changed, 2134 insertions, 1891 deletions
diff --git a/drivers/pcmcia/Kconfig b/drivers/pcmcia/Kconfig index 9f3adbd9f700..0a6601c76809 100644 --- a/drivers/pcmcia/Kconfig +++ b/drivers/pcmcia/Kconfig | |||
@@ -84,7 +84,7 @@ config YENTA | |||
84 | tristate "CardBus yenta-compatible bridge support" | 84 | tristate "CardBus yenta-compatible bridge support" |
85 | depends on PCI | 85 | depends on PCI |
86 | select CARDBUS if !EMBEDDED | 86 | select CARDBUS if !EMBEDDED |
87 | select PCCARD_NONSTATIC | 87 | select PCCARD_NONSTATIC if PCMCIA != n |
88 | ---help--- | 88 | ---help--- |
89 | This option enables support for CardBus host bridges. Virtually | 89 | This option enables support for CardBus host bridges. Virtually |
90 | all modern PCMCIA bridges are CardBus compatible. A "bridge" is | 90 | all modern PCMCIA bridges are CardBus compatible. A "bridge" is |
@@ -161,9 +161,8 @@ config TCIC | |||
161 | 161 | ||
162 | config PCMCIA_M8XX | 162 | config PCMCIA_M8XX |
163 | tristate "MPC8xx PCMCIA support" | 163 | tristate "MPC8xx PCMCIA support" |
164 | depends on PCMCIA && PPC && 8xx | 164 | depends on PCCARD && PPC && 8xx |
165 | select PCCARD_IODYN | 165 | select PCCARD_IODYN if PCMCIA != n |
166 | select PCCARD_NONSTATIC | ||
167 | help | 166 | help |
168 | Say Y here to include support for PowerPC 8xx series PCMCIA | 167 | Say Y here to include support for PowerPC 8xx series PCMCIA |
169 | controller. | 168 | controller. |
@@ -174,6 +173,27 @@ config PCMCIA_AU1X00 | |||
174 | tristate "Au1x00 pcmcia support" | 173 | tristate "Au1x00 pcmcia support" |
175 | depends on SOC_AU1X00 && PCMCIA | 174 | depends on SOC_AU1X00 && PCMCIA |
176 | 175 | ||
176 | config PCMCIA_ALCHEMY_DEVBOARD | ||
177 | tristate "Alchemy Db/Pb1xxx PCMCIA socket services" | ||
178 | depends on SOC_AU1X00 && PCMCIA | ||
179 | select 64BIT_PHYS_ADDR | ||
180 | help | ||
181 | Enable this driver of you want PCMCIA support on your Alchemy | ||
182 | Db1000, Db/Pb1100, Db/Pb1500, Db/Pb1550, Db/Pb1200 board. | ||
183 | NOT suitable for the PB1000! | ||
184 | |||
185 | This driver is also available as a module called db1xxx_ss.ko | ||
186 | |||
187 | config PCMCIA_XXS1500 | ||
188 | tristate "MyCable XXS1500 PCMCIA socket support" | ||
189 | depends on PCMCIA && MIPS_XXS1500 | ||
190 | select 64BIT_PHYS_ADDR | ||
191 | help | ||
192 | Support for the PCMCIA/CF socket interface on MyCable XXS1500 | ||
193 | systems. | ||
194 | |||
195 | This driver is also available as a module called xxs1500_ss.ko | ||
196 | |||
177 | config PCMCIA_BCM63XX | 197 | config PCMCIA_BCM63XX |
178 | tristate "bcm63xx pcmcia support" | 198 | tristate "bcm63xx pcmcia support" |
179 | depends on BCM63XX && PCMCIA | 199 | depends on BCM63XX && PCMCIA |
@@ -238,14 +258,12 @@ config PCMCIA_PROBE | |||
238 | config M32R_PCC | 258 | config M32R_PCC |
239 | bool "M32R PCMCIA I/F" | 259 | bool "M32R PCMCIA I/F" |
240 | depends on M32R && CHIP_M32700 && PCMCIA | 260 | depends on M32R && CHIP_M32700 && PCMCIA |
241 | select PCCARD_NONSTATIC | ||
242 | help | 261 | help |
243 | Say Y here to use the M32R PCMCIA controller. | 262 | Say Y here to use the M32R PCMCIA controller. |
244 | 263 | ||
245 | config M32R_CFC | 264 | config M32R_CFC |
246 | bool "M32R CF I/F Controller" | 265 | bool "M32R CF I/F Controller" |
247 | depends on M32R && (PLAT_USRV || PLAT_M32700UT || PLAT_MAPPI2 || PLAT_MAPPI3 || PLAT_OPSPUT) | 266 | depends on M32R && (PLAT_USRV || PLAT_M32700UT || PLAT_MAPPI2 || PLAT_MAPPI3 || PLAT_OPSPUT) |
248 | select PCCARD_NONSTATIC | ||
249 | help | 267 | help |
250 | Say Y here to use the M32R CompactFlash controller. | 268 | Say Y here to use the M32R CompactFlash controller. |
251 | 269 | ||
diff --git a/drivers/pcmcia/Makefile b/drivers/pcmcia/Makefile index 83ff802de544..381b031d9d75 100644 --- a/drivers/pcmcia/Makefile +++ b/drivers/pcmcia/Makefile | |||
@@ -2,11 +2,11 @@ | |||
2 | # Makefile for the kernel pcmcia subsystem (c/o David Hinds) | 2 | # Makefile for the kernel pcmcia subsystem (c/o David Hinds) |
3 | # | 3 | # |
4 | 4 | ||
5 | pcmcia_core-y += cs.o cistpl.o rsrc_mgr.o socket_sysfs.o | 5 | pcmcia_core-y += cs.o rsrc_mgr.o socket_sysfs.o |
6 | pcmcia_core-$(CONFIG_CARDBUS) += cardbus.o | 6 | pcmcia_core-$(CONFIG_CARDBUS) += cardbus.o |
7 | obj-$(CONFIG_PCCARD) += pcmcia_core.o | 7 | obj-$(CONFIG_PCCARD) += pcmcia_core.o |
8 | 8 | ||
9 | pcmcia-y += ds.o pcmcia_resource.o | 9 | pcmcia-y += ds.o pcmcia_resource.o cistpl.o |
10 | pcmcia-$(CONFIG_PCMCIA_IOCTL) += pcmcia_ioctl.o | 10 | pcmcia-$(CONFIG_PCMCIA_IOCTL) += pcmcia_ioctl.o |
11 | obj-$(CONFIG_PCMCIA) += pcmcia.o | 11 | obj-$(CONFIG_PCMCIA) += pcmcia.o |
12 | 12 | ||
@@ -35,18 +35,10 @@ obj-$(CONFIG_OMAP_CF) += omap_cf.o | |||
35 | obj-$(CONFIG_BFIN_CFPCMCIA) += bfin_cf_pcmcia.o | 35 | obj-$(CONFIG_BFIN_CFPCMCIA) += bfin_cf_pcmcia.o |
36 | obj-$(CONFIG_AT91_CF) += at91_cf.o | 36 | obj-$(CONFIG_AT91_CF) += at91_cf.o |
37 | obj-$(CONFIG_ELECTRA_CF) += electra_cf.o | 37 | obj-$(CONFIG_ELECTRA_CF) += electra_cf.o |
38 | obj-$(CONFIG_PCMCIA_ALCHEMY_DEVBOARD) += db1xxx_ss.o | ||
38 | 39 | ||
39 | au1x00_ss-y += au1000_generic.o | 40 | au1x00_ss-y += au1000_generic.o |
40 | au1x00_ss-$(CONFIG_MIPS_PB1000) += au1000_pb1x00.o | 41 | au1x00_ss-$(CONFIG_MIPS_PB1000) += au1000_pb1x00.o |
41 | au1x00_ss-$(CONFIG_MIPS_PB1100) += au1000_pb1x00.o | ||
42 | au1x00_ss-$(CONFIG_MIPS_PB1200) += au1000_db1x00.o | ||
43 | au1x00_ss-$(CONFIG_MIPS_PB1500) += au1000_pb1x00.o | ||
44 | au1x00_ss-$(CONFIG_MIPS_DB1000) += au1000_db1x00.o | ||
45 | au1x00_ss-$(CONFIG_MIPS_DB1100) += au1000_db1x00.o | ||
46 | au1x00_ss-$(CONFIG_MIPS_DB1200) += au1000_db1x00.o | ||
47 | au1x00_ss-$(CONFIG_MIPS_DB1500) += au1000_db1x00.o | ||
48 | au1x00_ss-$(CONFIG_MIPS_DB1550) += au1000_db1x00.o | ||
49 | au1x00_ss-$(CONFIG_MIPS_XXS1500) += au1000_xxs1500.o | ||
50 | 42 | ||
51 | sa1111_cs-y += sa1111_generic.o | 43 | sa1111_cs-y += sa1111_generic.o |
52 | sa1111_cs-$(CONFIG_ASSABET_NEPONSET) += sa1100_neponset.o | 44 | sa1111_cs-$(CONFIG_ASSABET_NEPONSET) += sa1100_neponset.o |
@@ -76,3 +68,5 @@ pxa2xx-obj-$(CONFIG_MACH_E740) += pxa2xx_e740.o | |||
76 | pxa2xx-obj-$(CONFIG_MACH_STARGATE2) += pxa2xx_stargate2.o | 68 | pxa2xx-obj-$(CONFIG_MACH_STARGATE2) += pxa2xx_stargate2.o |
77 | 69 | ||
78 | obj-$(CONFIG_PCMCIA_PXA2XX) += pxa2xx_base.o $(pxa2xx-obj-y) | 70 | obj-$(CONFIG_PCMCIA_PXA2XX) += pxa2xx_base.o $(pxa2xx-obj-y) |
71 | |||
72 | obj-$(CONFIG_PCMCIA_XXS1500) += xxs1500_ss.o | ||
diff --git a/drivers/pcmcia/at91_cf.c b/drivers/pcmcia/at91_cf.c index e1dccedc5960..5d228071ec69 100644 --- a/drivers/pcmcia/at91_cf.c +++ b/drivers/pcmcia/at91_cf.c | |||
@@ -52,8 +52,6 @@ struct at91_cf_socket { | |||
52 | unsigned long phys_baseaddr; | 52 | unsigned long phys_baseaddr; |
53 | }; | 53 | }; |
54 | 54 | ||
55 | #define SZ_2K (2 * SZ_1K) | ||
56 | |||
57 | static inline int at91_cf_present(struct at91_cf_socket *cf) | 55 | static inline int at91_cf_present(struct at91_cf_socket *cf) |
58 | { | 56 | { |
59 | return !gpio_get_value(cf->board->det_pin); | 57 | return !gpio_get_value(cf->board->det_pin); |
diff --git a/drivers/pcmcia/au1000_db1x00.c b/drivers/pcmcia/au1000_db1x00.c deleted file mode 100644 index c78d77fd7e3b..000000000000 --- a/drivers/pcmcia/au1000_db1x00.c +++ /dev/null | |||
@@ -1,305 +0,0 @@ | |||
1 | /* | ||
2 | * | ||
3 | * Alchemy Semi Db1x00 boards specific pcmcia routines. | ||
4 | * | ||
5 | * Copyright 2002 MontaVista Software Inc. | ||
6 | * Author: MontaVista Software, Inc. | ||
7 | * ppopov@mvista.com or source@mvista.com | ||
8 | * | ||
9 | * Copyright 2004 Pete Popov, updated the driver to 2.6. | ||
10 | * Followed the sa11xx API and largely copied many of the hardware | ||
11 | * independent functions. | ||
12 | * | ||
13 | * ######################################################################## | ||
14 | * | ||
15 | * This program is free software; you can distribute it and/or modify it | ||
16 | * under the terms of the GNU General Public License (Version 2) as | ||
17 | * published by the Free Software Foundation. | ||
18 | * | ||
19 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
20 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
21 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
22 | * for more details. | ||
23 | * | ||
24 | * You should have received a copy of the GNU General Public License along | ||
25 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
26 | * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. | ||
27 | * | ||
28 | * ######################################################################## | ||
29 | * | ||
30 | * | ||
31 | */ | ||
32 | |||
33 | #include <linux/module.h> | ||
34 | #include <linux/kernel.h> | ||
35 | #include <linux/errno.h> | ||
36 | #include <linux/interrupt.h> | ||
37 | #include <linux/device.h> | ||
38 | #include <linux/init.h> | ||
39 | |||
40 | #include <asm/irq.h> | ||
41 | #include <asm/signal.h> | ||
42 | #include <asm/mach-au1x00/au1000.h> | ||
43 | |||
44 | #if defined(CONFIG_MIPS_DB1200) | ||
45 | #include <db1200.h> | ||
46 | #elif defined(CONFIG_MIPS_PB1200) | ||
47 | #include <pb1200.h> | ||
48 | #else | ||
49 | #include <asm/mach-db1x00/db1x00.h> | ||
50 | static BCSR * const bcsr = (BCSR *)BCSR_KSEG1_ADDR; | ||
51 | #endif | ||
52 | |||
53 | #include "au1000_generic.h" | ||
54 | |||
55 | #if 0 | ||
56 | #define debug(x,args...) printk(KERN_DEBUG "%s: " x, __func__ , ##args) | ||
57 | #else | ||
58 | #define debug(x,args...) | ||
59 | #endif | ||
60 | |||
61 | |||
62 | struct au1000_pcmcia_socket au1000_pcmcia_socket[PCMCIA_NUM_SOCKS]; | ||
63 | extern int au1x00_pcmcia_socket_probe(struct device *, struct pcmcia_low_level *, int, int); | ||
64 | |||
65 | static int db1x00_pcmcia_hw_init(struct au1000_pcmcia_socket *skt) | ||
66 | { | ||
67 | #ifdef CONFIG_MIPS_DB1550 | ||
68 | skt->irq = skt->nr ? AU1000_GPIO_5 : AU1000_GPIO_3; | ||
69 | #elif defined(CONFIG_MIPS_DB1200) || defined(CONFIG_MIPS_PB1200) | ||
70 | skt->irq = skt->nr ? BOARD_PC1_INT : BOARD_PC0_INT; | ||
71 | #else | ||
72 | skt->irq = skt->nr ? AU1000_GPIO_5 : AU1000_GPIO_2; | ||
73 | #endif | ||
74 | return 0; | ||
75 | } | ||
76 | |||
77 | static void db1x00_pcmcia_shutdown(struct au1000_pcmcia_socket *skt) | ||
78 | { | ||
79 | bcsr->pcmcia = 0; /* turn off power */ | ||
80 | au_sync_delay(2); | ||
81 | } | ||
82 | |||
83 | static void | ||
84 | db1x00_pcmcia_socket_state(struct au1000_pcmcia_socket *skt, struct pcmcia_state *state) | ||
85 | { | ||
86 | u32 inserted; | ||
87 | unsigned char vs; | ||
88 | |||
89 | state->ready = 0; | ||
90 | state->vs_Xv = 0; | ||
91 | state->vs_3v = 0; | ||
92 | state->detect = 0; | ||
93 | |||
94 | switch (skt->nr) { | ||
95 | case 0: | ||
96 | vs = bcsr->status & 0x3; | ||
97 | #if defined(CONFIG_MIPS_DB1200) || defined(CONFIG_MIPS_PB1200) | ||
98 | inserted = BOARD_CARD_INSERTED(0); | ||
99 | #else | ||
100 | inserted = !(bcsr->status & (1<<4)); | ||
101 | #endif | ||
102 | break; | ||
103 | case 1: | ||
104 | vs = (bcsr->status & 0xC)>>2; | ||
105 | #if defined(CONFIG_MIPS_DB1200) || defined(CONFIG_MIPS_PB1200) | ||
106 | inserted = BOARD_CARD_INSERTED(1); | ||
107 | #else | ||
108 | inserted = !(bcsr->status & (1<<5)); | ||
109 | #endif | ||
110 | break; | ||
111 | default:/* should never happen */ | ||
112 | return; | ||
113 | } | ||
114 | |||
115 | if (inserted) | ||
116 | debug("db1x00 socket %d: inserted %d, vs %d pcmcia %x\n", | ||
117 | skt->nr, inserted, vs, bcsr->pcmcia); | ||
118 | |||
119 | if (inserted) { | ||
120 | switch (vs) { | ||
121 | case 0: | ||
122 | case 2: | ||
123 | state->vs_3v=1; | ||
124 | break; | ||
125 | case 3: /* 5V */ | ||
126 | break; | ||
127 | default: | ||
128 | /* return without setting 'detect' */ | ||
129 | printk(KERN_ERR "db1x00 bad VS (%d)\n", | ||
130 | vs); | ||
131 | } | ||
132 | state->detect = 1; | ||
133 | state->ready = 1; | ||
134 | } | ||
135 | else { | ||
136 | /* if the card was previously inserted and then ejected, | ||
137 | * we should turn off power to it | ||
138 | */ | ||
139 | if ((skt->nr == 0) && (bcsr->pcmcia & BCSR_PCMCIA_PC0RST)) { | ||
140 | bcsr->pcmcia &= ~(BCSR_PCMCIA_PC0RST | | ||
141 | BCSR_PCMCIA_PC0DRVEN | | ||
142 | BCSR_PCMCIA_PC0VPP | | ||
143 | BCSR_PCMCIA_PC0VCC); | ||
144 | au_sync_delay(10); | ||
145 | } | ||
146 | else if ((skt->nr == 1) && bcsr->pcmcia & BCSR_PCMCIA_PC1RST) { | ||
147 | bcsr->pcmcia &= ~(BCSR_PCMCIA_PC1RST | | ||
148 | BCSR_PCMCIA_PC1DRVEN | | ||
149 | BCSR_PCMCIA_PC1VPP | | ||
150 | BCSR_PCMCIA_PC1VCC); | ||
151 | au_sync_delay(10); | ||
152 | } | ||
153 | } | ||
154 | |||
155 | state->bvd1=1; | ||
156 | state->bvd2=1; | ||
157 | state->wrprot=0; | ||
158 | } | ||
159 | |||
160 | static int | ||
161 | db1x00_pcmcia_configure_socket(struct au1000_pcmcia_socket *skt, struct socket_state_t *state) | ||
162 | { | ||
163 | u16 pwr; | ||
164 | int sock = skt->nr; | ||
165 | |||
166 | debug("config_skt %d Vcc %dV Vpp %dV, reset %d\n", | ||
167 | sock, state->Vcc, state->Vpp, | ||
168 | state->flags & SS_RESET); | ||
169 | |||
170 | /* pcmcia reg was set to zero at init time. Be careful when | ||
171 | * initializing a socket not to wipe out the settings of the | ||
172 | * other socket. | ||
173 | */ | ||
174 | pwr = bcsr->pcmcia; | ||
175 | pwr &= ~(0xf << sock*8); /* clear voltage settings */ | ||
176 | |||
177 | state->Vpp = 0; | ||
178 | switch(state->Vcc){ | ||
179 | case 0: /* Vcc 0 */ | ||
180 | pwr |= SET_VCC_VPP(0,0,sock); | ||
181 | break; | ||
182 | case 50: /* Vcc 5V */ | ||
183 | switch(state->Vpp) { | ||
184 | case 0: | ||
185 | pwr |= SET_VCC_VPP(2,0,sock); | ||
186 | break; | ||
187 | case 50: | ||
188 | pwr |= SET_VCC_VPP(2,1,sock); | ||
189 | break; | ||
190 | case 12: | ||
191 | pwr |= SET_VCC_VPP(2,2,sock); | ||
192 | break; | ||
193 | case 33: | ||
194 | default: | ||
195 | pwr |= SET_VCC_VPP(0,0,sock); | ||
196 | printk("%s: bad Vcc/Vpp (%d:%d)\n", | ||
197 | __func__, | ||
198 | state->Vcc, | ||
199 | state->Vpp); | ||
200 | break; | ||
201 | } | ||
202 | break; | ||
203 | case 33: /* Vcc 3.3V */ | ||
204 | switch(state->Vpp) { | ||
205 | case 0: | ||
206 | pwr |= SET_VCC_VPP(1,0,sock); | ||
207 | break; | ||
208 | case 12: | ||
209 | pwr |= SET_VCC_VPP(1,2,sock); | ||
210 | break; | ||
211 | case 33: | ||
212 | pwr |= SET_VCC_VPP(1,1,sock); | ||
213 | break; | ||
214 | case 50: | ||
215 | default: | ||
216 | pwr |= SET_VCC_VPP(0,0,sock); | ||
217 | printk("%s: bad Vcc/Vpp (%d:%d)\n", | ||
218 | __func__, | ||
219 | state->Vcc, | ||
220 | state->Vpp); | ||
221 | break; | ||
222 | } | ||
223 | break; | ||
224 | default: /* what's this ? */ | ||
225 | pwr |= SET_VCC_VPP(0,0,sock); | ||
226 | printk(KERN_ERR "%s: bad Vcc %d\n", | ||
227 | __func__, state->Vcc); | ||
228 | break; | ||
229 | } | ||
230 | |||
231 | bcsr->pcmcia = pwr; | ||
232 | au_sync_delay(300); | ||
233 | |||
234 | if (sock == 0) { | ||
235 | if (!(state->flags & SS_RESET)) { | ||
236 | pwr |= BCSR_PCMCIA_PC0DRVEN; | ||
237 | bcsr->pcmcia = pwr; | ||
238 | au_sync_delay(300); | ||
239 | pwr |= BCSR_PCMCIA_PC0RST; | ||
240 | bcsr->pcmcia = pwr; | ||
241 | au_sync_delay(100); | ||
242 | } | ||
243 | else { | ||
244 | pwr &= ~(BCSR_PCMCIA_PC0RST | BCSR_PCMCIA_PC0DRVEN); | ||
245 | bcsr->pcmcia = pwr; | ||
246 | au_sync_delay(100); | ||
247 | } | ||
248 | } | ||
249 | else { | ||
250 | if (!(state->flags & SS_RESET)) { | ||
251 | pwr |= BCSR_PCMCIA_PC1DRVEN; | ||
252 | bcsr->pcmcia = pwr; | ||
253 | au_sync_delay(300); | ||
254 | pwr |= BCSR_PCMCIA_PC1RST; | ||
255 | bcsr->pcmcia = pwr; | ||
256 | au_sync_delay(100); | ||
257 | } | ||
258 | else { | ||
259 | pwr &= ~(BCSR_PCMCIA_PC1RST | BCSR_PCMCIA_PC1DRVEN); | ||
260 | bcsr->pcmcia = pwr; | ||
261 | au_sync_delay(100); | ||
262 | } | ||
263 | } | ||
264 | return 0; | ||
265 | } | ||
266 | |||
267 | /* | ||
268 | * Enable card status IRQs on (re-)initialisation. This can | ||
269 | * be called at initialisation, power management event, or | ||
270 | * pcmcia event. | ||
271 | */ | ||
272 | void db1x00_socket_init(struct au1000_pcmcia_socket *skt) | ||
273 | { | ||
274 | /* nothing to do for now */ | ||
275 | } | ||
276 | |||
277 | /* | ||
278 | * Disable card status IRQs and PCMCIA bus on suspend. | ||
279 | */ | ||
280 | void db1x00_socket_suspend(struct au1000_pcmcia_socket *skt) | ||
281 | { | ||
282 | /* nothing to do for now */ | ||
283 | } | ||
284 | |||
285 | struct pcmcia_low_level db1x00_pcmcia_ops = { | ||
286 | .owner = THIS_MODULE, | ||
287 | |||
288 | .hw_init = db1x00_pcmcia_hw_init, | ||
289 | .hw_shutdown = db1x00_pcmcia_shutdown, | ||
290 | |||
291 | .socket_state = db1x00_pcmcia_socket_state, | ||
292 | .configure_socket = db1x00_pcmcia_configure_socket, | ||
293 | |||
294 | .socket_init = db1x00_socket_init, | ||
295 | .socket_suspend = db1x00_socket_suspend | ||
296 | }; | ||
297 | |||
298 | int au1x_board_init(struct device *dev) | ||
299 | { | ||
300 | int ret = -ENODEV; | ||
301 | bcsr->pcmcia = 0; /* turn off power, if it's not already off */ | ||
302 | au_sync_delay(2); | ||
303 | ret = au1x00_pcmcia_socket_probe(dev, &db1x00_pcmcia_ops, 0, 2); | ||
304 | return ret; | ||
305 | } | ||
diff --git a/drivers/pcmcia/au1000_generic.c b/drivers/pcmcia/au1000_generic.c index 02088704ac2c..171c8a654887 100644 --- a/drivers/pcmcia/au1000_generic.c +++ b/drivers/pcmcia/au1000_generic.c | |||
@@ -405,18 +405,16 @@ int au1x00_pcmcia_socket_probe(struct device *dev, struct pcmcia_low_level *ops, | |||
405 | skt->virt_io = (void *) | 405 | skt->virt_io = (void *) |
406 | (ioremap((phys_t)AU1X_SOCK0_IO, 0x1000) - | 406 | (ioremap((phys_t)AU1X_SOCK0_IO, 0x1000) - |
407 | (u32)mips_io_port_base); | 407 | (u32)mips_io_port_base); |
408 | skt->phys_attr = AU1X_SOCK0_PSEUDO_PHYS_ATTR; | 408 | skt->phys_attr = AU1X_SOCK0_PHYS_ATTR; |
409 | skt->phys_mem = AU1X_SOCK0_PSEUDO_PHYS_MEM; | 409 | skt->phys_mem = AU1X_SOCK0_PHYS_MEM; |
410 | } | 410 | } |
411 | #ifndef CONFIG_MIPS_XXS1500 | ||
412 | else { | 411 | else { |
413 | skt->virt_io = (void *) | 412 | skt->virt_io = (void *) |
414 | (ioremap((phys_t)AU1X_SOCK1_IO, 0x1000) - | 413 | (ioremap((phys_t)AU1X_SOCK1_IO, 0x1000) - |
415 | (u32)mips_io_port_base); | 414 | (u32)mips_io_port_base); |
416 | skt->phys_attr = AU1X_SOCK1_PSEUDO_PHYS_ATTR; | 415 | skt->phys_attr = AU1X_SOCK1_PHYS_ATTR; |
417 | skt->phys_mem = AU1X_SOCK1_PSEUDO_PHYS_MEM; | 416 | skt->phys_mem = AU1X_SOCK1_PHYS_MEM; |
418 | } | 417 | } |
419 | #endif | ||
420 | pcmcia_base_vaddrs[i] = (u32 *)skt->virt_io; | 418 | pcmcia_base_vaddrs[i] = (u32 *)skt->virt_io; |
421 | ret = ops->hw_init(skt); | 419 | ret = ops->hw_init(skt); |
422 | 420 | ||
diff --git a/drivers/pcmcia/au1000_generic.h b/drivers/pcmcia/au1000_generic.h index 13a4fbc58711..a324d329dea6 100644 --- a/drivers/pcmcia/au1000_generic.h +++ b/drivers/pcmcia/au1000_generic.h | |||
@@ -36,30 +36,14 @@ | |||
36 | #define AU1X_SOCK0_IO 0xF00000000ULL | 36 | #define AU1X_SOCK0_IO 0xF00000000ULL |
37 | #define AU1X_SOCK0_PHYS_ATTR 0xF40000000ULL | 37 | #define AU1X_SOCK0_PHYS_ATTR 0xF40000000ULL |
38 | #define AU1X_SOCK0_PHYS_MEM 0xF80000000ULL | 38 | #define AU1X_SOCK0_PHYS_MEM 0xF80000000ULL |
39 | /* pseudo 32 bit phys addresses, which get fixed up to the | ||
40 | * real 36 bit address in fixup_bigphys_addr() */ | ||
41 | #define AU1X_SOCK0_PSEUDO_PHYS_ATTR 0xF4000000 | ||
42 | #define AU1X_SOCK0_PSEUDO_PHYS_MEM 0xF8000000 | ||
43 | 39 | ||
44 | /* pcmcia socket 1 needs external glue logic so the memory map | 40 | /* pcmcia socket 1 needs external glue logic so the memory map |
45 | * differs from board to board. | 41 | * differs from board to board. |
46 | */ | 42 | */ |
47 | #if defined(CONFIG_MIPS_PB1000) || defined(CONFIG_MIPS_PB1100) || \ | 43 | #if defined(CONFIG_MIPS_PB1000) |
48 | defined(CONFIG_MIPS_PB1500) || defined(CONFIG_MIPS_PB1550) || \ | ||
49 | defined(CONFIG_MIPS_PB1200) | ||
50 | #define AU1X_SOCK1_IO 0xF08000000ULL | 44 | #define AU1X_SOCK1_IO 0xF08000000ULL |
51 | #define AU1X_SOCK1_PHYS_ATTR 0xF48000000ULL | 45 | #define AU1X_SOCK1_PHYS_ATTR 0xF48000000ULL |
52 | #define AU1X_SOCK1_PHYS_MEM 0xF88000000ULL | 46 | #define AU1X_SOCK1_PHYS_MEM 0xF88000000ULL |
53 | #define AU1X_SOCK1_PSEUDO_PHYS_ATTR 0xF4800000 | ||
54 | #define AU1X_SOCK1_PSEUDO_PHYS_MEM 0xF8800000 | ||
55 | #elif defined(CONFIG_MIPS_DB1000) || defined(CONFIG_MIPS_DB1100) || \ | ||
56 | defined(CONFIG_MIPS_DB1500) || defined(CONFIG_MIPS_DB1550) || \ | ||
57 | defined(CONFIG_MIPS_DB1200) | ||
58 | #define AU1X_SOCK1_IO 0xF04000000ULL | ||
59 | #define AU1X_SOCK1_PHYS_ATTR 0xF44000000ULL | ||
60 | #define AU1X_SOCK1_PHYS_MEM 0xF84000000ULL | ||
61 | #define AU1X_SOCK1_PSEUDO_PHYS_ATTR 0xF4400000 | ||
62 | #define AU1X_SOCK1_PSEUDO_PHYS_MEM 0xF8400000 | ||
63 | #endif | 47 | #endif |
64 | 48 | ||
65 | struct pcmcia_state { | 49 | struct pcmcia_state { |
diff --git a/drivers/pcmcia/au1000_pb1x00.c b/drivers/pcmcia/au1000_pb1x00.c index b1984ed72d1d..5a979cb8f3e6 100644 --- a/drivers/pcmcia/au1000_pb1x00.c +++ b/drivers/pcmcia/au1000_pb1x00.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | * | 2 | * |
3 | * Alchemy Semi Pb1x00 boards specific pcmcia routines. | 3 | * Alchemy Semi Pb1000 boards specific pcmcia routines. |
4 | * | 4 | * |
5 | * Copyright 2002 MontaVista Software Inc. | 5 | * Copyright 2002 MontaVista Software Inc. |
6 | * Author: MontaVista Software, Inc. | 6 | * Author: MontaVista Software, Inc. |
@@ -46,20 +46,11 @@ | |||
46 | 46 | ||
47 | #define debug(fmt, arg...) do { } while (0) | 47 | #define debug(fmt, arg...) do { } while (0) |
48 | 48 | ||
49 | #ifdef CONFIG_MIPS_PB1000 | ||
50 | #include <asm/pb1000.h> | 49 | #include <asm/pb1000.h> |
51 | #define PCMCIA_IRQ AU1000_GPIO_15 | 50 | #define PCMCIA_IRQ AU1000_GPIO_15 |
52 | #elif defined (CONFIG_MIPS_PB1500) | ||
53 | #include <asm/pb1500.h> | ||
54 | #define PCMCIA_IRQ AU1500_GPIO_203 | ||
55 | #elif defined (CONFIG_MIPS_PB1100) | ||
56 | #include <asm/pb1100.h> | ||
57 | #define PCMCIA_IRQ AU1000_GPIO_11 | ||
58 | #endif | ||
59 | 51 | ||
60 | static int pb1x00_pcmcia_init(struct pcmcia_init *init) | 52 | static int pb1x00_pcmcia_init(struct pcmcia_init *init) |
61 | { | 53 | { |
62 | #ifdef CONFIG_MIPS_PB1000 | ||
63 | u16 pcr; | 54 | u16 pcr; |
64 | pcr = PCR_SLOT_0_RST | PCR_SLOT_1_RST; | 55 | pcr = PCR_SLOT_0_RST | PCR_SLOT_1_RST; |
65 | 56 | ||
@@ -74,21 +65,10 @@ static int pb1x00_pcmcia_init(struct pcmcia_init *init) | |||
74 | au_sync_delay(20); | 65 | au_sync_delay(20); |
75 | 66 | ||
76 | return PCMCIA_NUM_SOCKS; | 67 | return PCMCIA_NUM_SOCKS; |
77 | |||
78 | #else /* fixme -- take care of the Pb1500 at some point */ | ||
79 | |||
80 | u16 pcr; | ||
81 | pcr = au_readw(PCMCIA_BOARD_REG) & ~0xf; /* turn off power */ | ||
82 | pcr &= ~(PC_DEASSERT_RST | PC_DRV_EN); | ||
83 | au_writew(pcr, PCMCIA_BOARD_REG); | ||
84 | au_sync_delay(500); | ||
85 | return PCMCIA_NUM_SOCKS; | ||
86 | #endif | ||
87 | } | 68 | } |
88 | 69 | ||
89 | static int pb1x00_pcmcia_shutdown(void) | 70 | static int pb1x00_pcmcia_shutdown(void) |
90 | { | 71 | { |
91 | #ifdef CONFIG_MIPS_PB1000 | ||
92 | u16 pcr; | 72 | u16 pcr; |
93 | pcr = PCR_SLOT_0_RST | PCR_SLOT_1_RST; | 73 | pcr = PCR_SLOT_0_RST | PCR_SLOT_1_RST; |
94 | pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,0); | 74 | pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,0); |
@@ -96,14 +76,6 @@ static int pb1x00_pcmcia_shutdown(void) | |||
96 | au_writel(pcr, PB1000_PCR); | 76 | au_writel(pcr, PB1000_PCR); |
97 | au_sync_delay(20); | 77 | au_sync_delay(20); |
98 | return 0; | 78 | return 0; |
99 | #else | ||
100 | u16 pcr; | ||
101 | pcr = au_readw(PCMCIA_BOARD_REG) & ~0xf; /* turn off power */ | ||
102 | pcr &= ~(PC_DEASSERT_RST | PC_DRV_EN); | ||
103 | au_writew(pcr, PCMCIA_BOARD_REG); | ||
104 | au_sync_delay(2); | ||
105 | return 0; | ||
106 | #endif | ||
107 | } | 79 | } |
108 | 80 | ||
109 | static int | 81 | static int |
@@ -112,21 +84,11 @@ pb1x00_pcmcia_socket_state(unsigned sock, struct pcmcia_state *state) | |||
112 | u32 inserted0, inserted1; | 84 | u32 inserted0, inserted1; |
113 | u16 vs0, vs1; | 85 | u16 vs0, vs1; |
114 | 86 | ||
115 | #ifdef CONFIG_MIPS_PB1000 | ||
116 | vs0 = vs1 = (u16)au_readl(PB1000_ACR1); | 87 | vs0 = vs1 = (u16)au_readl(PB1000_ACR1); |
117 | inserted0 = !(vs0 & (ACR1_SLOT_0_CD1 | ACR1_SLOT_0_CD2)); | 88 | inserted0 = !(vs0 & (ACR1_SLOT_0_CD1 | ACR1_SLOT_0_CD2)); |
118 | inserted1 = !(vs1 & (ACR1_SLOT_1_CD1 | ACR1_SLOT_1_CD2)); | 89 | inserted1 = !(vs1 & (ACR1_SLOT_1_CD1 | ACR1_SLOT_1_CD2)); |
119 | vs0 = (vs0 >> 4) & 0x3; | 90 | vs0 = (vs0 >> 4) & 0x3; |
120 | vs1 = (vs1 >> 12) & 0x3; | 91 | vs1 = (vs1 >> 12) & 0x3; |
121 | #else | ||
122 | vs0 = (au_readw(BOARD_STATUS_REG) >> 4) & 0x3; | ||
123 | #ifdef CONFIG_MIPS_PB1500 | ||
124 | inserted0 = !((au_readl(GPIO2_PINSTATE) >> 1) & 0x1); /* gpio 201 */ | ||
125 | #else /* Pb1100 */ | ||
126 | inserted0 = !((au_readl(SYS_PINSTATERD) >> 9) & 0x1); /* gpio 9 */ | ||
127 | #endif | ||
128 | inserted1 = 0; | ||
129 | #endif | ||
130 | 92 | ||
131 | state->ready = 0; | 93 | state->ready = 0; |
132 | state->vs_Xv = 0; | 94 | state->vs_Xv = 0; |
@@ -203,7 +165,6 @@ pb1x00_pcmcia_configure_socket(const struct pcmcia_configure *configure) | |||
203 | 165 | ||
204 | if(configure->sock > PCMCIA_MAX_SOCK) return -1; | 166 | if(configure->sock > PCMCIA_MAX_SOCK) return -1; |
205 | 167 | ||
206 | #ifdef CONFIG_MIPS_PB1000 | ||
207 | pcr = au_readl(PB1000_PCR); | 168 | pcr = au_readl(PB1000_PCR); |
208 | 169 | ||
209 | if (configure->sock == 0) { | 170 | if (configure->sock == 0) { |
@@ -323,84 +284,6 @@ pb1x00_pcmcia_configure_socket(const struct pcmcia_configure *configure) | |||
323 | au_writel(pcr, PB1000_PCR); | 284 | au_writel(pcr, PB1000_PCR); |
324 | au_sync_delay(300); | 285 | au_sync_delay(300); |
325 | 286 | ||
326 | #else | ||
327 | |||
328 | pcr = au_readw(PCMCIA_BOARD_REG) & ~0xf; | ||
329 | |||
330 | debug("Vcc %dV Vpp %dV, pcr %x, reset %d\n", | ||
331 | configure->vcc, configure->vpp, pcr, configure->reset); | ||
332 | |||
333 | |||
334 | switch(configure->vcc){ | ||
335 | case 0: /* Vcc 0 */ | ||
336 | pcr |= SET_VCC_VPP(0,0); | ||
337 | break; | ||
338 | case 50: /* Vcc 5V */ | ||
339 | switch(configure->vpp) { | ||
340 | case 0: | ||
341 | pcr |= SET_VCC_VPP(2,0); | ||
342 | break; | ||
343 | case 50: | ||
344 | pcr |= SET_VCC_VPP(2,1); | ||
345 | break; | ||
346 | case 12: | ||
347 | pcr |= SET_VCC_VPP(2,2); | ||
348 | break; | ||
349 | case 33: | ||
350 | default: | ||
351 | pcr |= SET_VCC_VPP(0,0); | ||
352 | printk("%s: bad Vcc/Vpp (%d:%d)\n", | ||
353 | __func__, | ||
354 | configure->vcc, | ||
355 | configure->vpp); | ||
356 | break; | ||
357 | } | ||
358 | break; | ||
359 | case 33: /* Vcc 3.3V */ | ||
360 | switch(configure->vpp) { | ||
361 | case 0: | ||
362 | pcr |= SET_VCC_VPP(1,0); | ||
363 | break; | ||
364 | case 12: | ||
365 | pcr |= SET_VCC_VPP(1,2); | ||
366 | break; | ||
367 | case 33: | ||
368 | pcr |= SET_VCC_VPP(1,1); | ||
369 | break; | ||
370 | case 50: | ||
371 | default: | ||
372 | pcr |= SET_VCC_VPP(0,0); | ||
373 | printk("%s: bad Vcc/Vpp (%d:%d)\n", | ||
374 | __func__, | ||
375 | configure->vcc, | ||
376 | configure->vpp); | ||
377 | break; | ||
378 | } | ||
379 | break; | ||
380 | default: /* what's this ? */ | ||
381 | pcr |= SET_VCC_VPP(0,0); | ||
382 | printk(KERN_ERR "%s: bad Vcc %d\n", | ||
383 | __func__, configure->vcc); | ||
384 | break; | ||
385 | } | ||
386 | |||
387 | au_writew(pcr, PCMCIA_BOARD_REG); | ||
388 | au_sync_delay(300); | ||
389 | |||
390 | if (!configure->reset) { | ||
391 | pcr |= PC_DRV_EN; | ||
392 | au_writew(pcr, PCMCIA_BOARD_REG); | ||
393 | au_sync_delay(100); | ||
394 | pcr |= PC_DEASSERT_RST; | ||
395 | au_writew(pcr, PCMCIA_BOARD_REG); | ||
396 | au_sync_delay(100); | ||
397 | } | ||
398 | else { | ||
399 | pcr &= ~(PC_DEASSERT_RST | PC_DRV_EN); | ||
400 | au_writew(pcr, PCMCIA_BOARD_REG); | ||
401 | au_sync_delay(100); | ||
402 | } | ||
403 | #endif | ||
404 | return 0; | 287 | return 0; |
405 | } | 288 | } |
406 | 289 | ||
diff --git a/drivers/pcmcia/au1000_xxs1500.c b/drivers/pcmcia/au1000_xxs1500.c deleted file mode 100644 index b43d47b50819..000000000000 --- a/drivers/pcmcia/au1000_xxs1500.c +++ /dev/null | |||
@@ -1,188 +0,0 @@ | |||
1 | /* | ||
2 | * | ||
3 | * MyCable board specific pcmcia routines. | ||
4 | * | ||
5 | * Copyright 2003 MontaVista Software Inc. | ||
6 | * Author: Pete Popov, MontaVista Software, Inc. | ||
7 | * ppopov@mvista.com or source@mvista.com | ||
8 | * | ||
9 | * ######################################################################## | ||
10 | * | ||
11 | * This program is free software; you can distribute it and/or modify it | ||
12 | * under the terms of the GNU General Public License (Version 2) as | ||
13 | * published by the Free Software Foundation. | ||
14 | * | ||
15 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
16 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
17 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
18 | * for more details. | ||
19 | * | ||
20 | * You should have received a copy of the GNU General Public License along | ||
21 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
22 | * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. | ||
23 | * | ||
24 | * ######################################################################## | ||
25 | * | ||
26 | * | ||
27 | */ | ||
28 | #include <linux/module.h> | ||
29 | #include <linux/init.h> | ||
30 | #include <linux/delay.h> | ||
31 | #include <linux/ioport.h> | ||
32 | #include <linux/kernel.h> | ||
33 | #include <linux/timer.h> | ||
34 | #include <linux/mm.h> | ||
35 | #include <linux/proc_fs.h> | ||
36 | #include <linux/types.h> | ||
37 | |||
38 | #include <pcmcia/cs_types.h> | ||
39 | #include <pcmcia/cs.h> | ||
40 | #include <pcmcia/ss.h> | ||
41 | #include <pcmcia/cistpl.h> | ||
42 | #include <pcmcia/bus_ops.h> | ||
43 | |||
44 | #include <asm/io.h> | ||
45 | #include <asm/irq.h> | ||
46 | #include <asm/system.h> | ||
47 | |||
48 | #include <asm/au1000.h> | ||
49 | #include <asm/au1000_pcmcia.h> | ||
50 | |||
51 | #define PCMCIA_MAX_SOCK 0 | ||
52 | #define PCMCIA_NUM_SOCKS (PCMCIA_MAX_SOCK + 1) | ||
53 | #define PCMCIA_IRQ AU1000_GPIO_4 | ||
54 | |||
55 | #if 0 | ||
56 | #define DEBUG(x, args...) printk(__func__ ": " x, ##args) | ||
57 | #else | ||
58 | #define DEBUG(x,args...) | ||
59 | #endif | ||
60 | |||
61 | static int xxs1500_pcmcia_init(struct pcmcia_init *init) | ||
62 | { | ||
63 | return PCMCIA_NUM_SOCKS; | ||
64 | } | ||
65 | |||
66 | static int xxs1500_pcmcia_shutdown(void) | ||
67 | { | ||
68 | /* turn off power */ | ||
69 | au_writel(au_readl(GPIO2_PINSTATE) | (1<<14)|(1<<30), | ||
70 | GPIO2_OUTPUT); | ||
71 | au_sync_delay(100); | ||
72 | |||
73 | /* assert reset */ | ||
74 | au_writel(au_readl(GPIO2_PINSTATE) | (1<<4)|(1<<20), | ||
75 | GPIO2_OUTPUT); | ||
76 | au_sync_delay(100); | ||
77 | return 0; | ||
78 | } | ||
79 | |||
80 | |||
81 | static int | ||
82 | xxs1500_pcmcia_socket_state(unsigned sock, struct pcmcia_state *state) | ||
83 | { | ||
84 | u32 inserted; u32 vs; | ||
85 | unsigned long gpio, gpio2; | ||
86 | |||
87 | if(sock > PCMCIA_MAX_SOCK) return -1; | ||
88 | |||
89 | gpio = au_readl(SYS_PINSTATERD); | ||
90 | gpio2 = au_readl(GPIO2_PINSTATE); | ||
91 | |||
92 | vs = gpio2 & ((1<<8) | (1<<9)); | ||
93 | inserted = (!(gpio & 0x1) && !(gpio & 0x2)); | ||
94 | |||
95 | state->ready = 0; | ||
96 | state->vs_Xv = 0; | ||
97 | state->vs_3v = 0; | ||
98 | state->detect = 0; | ||
99 | |||
100 | if (inserted) { | ||
101 | switch (vs) { | ||
102 | case 0: | ||
103 | case 1: | ||
104 | case 2: | ||
105 | state->vs_3v=1; | ||
106 | break; | ||
107 | case 3: /* 5V */ | ||
108 | default: | ||
109 | /* return without setting 'detect' */ | ||
110 | printk(KERN_ERR "au1x00_cs: unsupported VS\n", | ||
111 | vs); | ||
112 | return; | ||
113 | } | ||
114 | state->detect = 1; | ||
115 | } | ||
116 | |||
117 | if (state->detect) { | ||
118 | state->ready = 1; | ||
119 | } | ||
120 | |||
121 | state->bvd1= gpio2 & (1<<10); | ||
122 | state->bvd2 = gpio2 & (1<<11); | ||
123 | state->wrprot=0; | ||
124 | return 1; | ||
125 | } | ||
126 | |||
127 | |||
128 | static int xxs1500_pcmcia_get_irq_info(struct pcmcia_irq_info *info) | ||
129 | { | ||
130 | |||
131 | if(info->sock > PCMCIA_MAX_SOCK) return -1; | ||
132 | info->irq = PCMCIA_IRQ; | ||
133 | return 0; | ||
134 | } | ||
135 | |||
136 | |||
137 | static int | ||
138 | xxs1500_pcmcia_configure_socket(const struct pcmcia_configure *configure) | ||
139 | { | ||
140 | |||
141 | if(configure->sock > PCMCIA_MAX_SOCK) return -1; | ||
142 | |||
143 | DEBUG("Vcc %dV Vpp %dV, reset %d\n", | ||
144 | configure->vcc, configure->vpp, configure->reset); | ||
145 | |||
146 | switch(configure->vcc){ | ||
147 | case 33: /* Vcc 3.3V */ | ||
148 | /* turn on power */ | ||
149 | DEBUG("turn on power\n"); | ||
150 | au_writel((au_readl(GPIO2_PINSTATE) & ~(1<<14))|(1<<30), | ||
151 | GPIO2_OUTPUT); | ||
152 | au_sync_delay(100); | ||
153 | break; | ||
154 | case 50: /* Vcc 5V */ | ||
155 | default: /* what's this ? */ | ||
156 | printk(KERN_ERR "au1x00_cs: unsupported VCC\n"); | ||
157 | case 0: /* Vcc 0 */ | ||
158 | /* turn off power */ | ||
159 | au_sync_delay(100); | ||
160 | au_writel(au_readl(GPIO2_PINSTATE) | (1<<14)|(1<<30), | ||
161 | GPIO2_OUTPUT); | ||
162 | break; | ||
163 | } | ||
164 | |||
165 | if (!configure->reset) { | ||
166 | DEBUG("deassert reset\n"); | ||
167 | au_writel((au_readl(GPIO2_PINSTATE) & ~(1<<4))|(1<<20), | ||
168 | GPIO2_OUTPUT); | ||
169 | au_sync_delay(100); | ||
170 | au_writel((au_readl(GPIO2_PINSTATE) & ~(1<<5))|(1<<21), | ||
171 | GPIO2_OUTPUT); | ||
172 | } | ||
173 | else { | ||
174 | DEBUG("assert reset\n"); | ||
175 | au_writel(au_readl(GPIO2_PINSTATE) | (1<<4)|(1<<20), | ||
176 | GPIO2_OUTPUT); | ||
177 | } | ||
178 | au_sync_delay(100); | ||
179 | return 0; | ||
180 | } | ||
181 | |||
182 | struct pcmcia_low_level xxs1500_pcmcia_ops = { | ||
183 | xxs1500_pcmcia_init, | ||
184 | xxs1500_pcmcia_shutdown, | ||
185 | xxs1500_pcmcia_socket_state, | ||
186 | xxs1500_pcmcia_get_irq_info, | ||
187 | xxs1500_pcmcia_configure_socket | ||
188 | }; | ||
diff --git a/drivers/pcmcia/bfin_cf_pcmcia.c b/drivers/pcmcia/bfin_cf_pcmcia.c index 300b368605c9..2482ce7ac6dc 100644 --- a/drivers/pcmcia/bfin_cf_pcmcia.c +++ b/drivers/pcmcia/bfin_cf_pcmcia.c | |||
@@ -205,7 +205,7 @@ static int __devinit bfin_cf_probe(struct platform_device *pdev) | |||
205 | dev_info(&pdev->dev, "Blackfin CompactFlash/PCMCIA Socket Driver\n"); | 205 | dev_info(&pdev->dev, "Blackfin CompactFlash/PCMCIA Socket Driver\n"); |
206 | 206 | ||
207 | irq = platform_get_irq(pdev, 0); | 207 | irq = platform_get_irq(pdev, 0); |
208 | if (!irq) | 208 | if (irq <= 0) |
209 | return -EINVAL; | 209 | return -EINVAL; |
210 | 210 | ||
211 | cd_pfx = platform_get_irq(pdev, 1); /*Card Detect GPIO PIN */ | 211 | cd_pfx = platform_get_irq(pdev, 1); /*Card Detect GPIO PIN */ |
diff --git a/drivers/pcmcia/cardbus.c b/drivers/pcmcia/cardbus.c index d99f846451a3..ac0686efbf75 100644 --- a/drivers/pcmcia/cardbus.c +++ b/drivers/pcmcia/cardbus.c | |||
@@ -20,170 +20,12 @@ | |||
20 | */ | 20 | */ |
21 | 21 | ||
22 | 22 | ||
23 | #include <linux/module.h> | ||
24 | #include <linux/kernel.h> | 23 | #include <linux/kernel.h> |
25 | #include <linux/string.h> | 24 | #include <linux/module.h> |
26 | #include <linux/slab.h> | ||
27 | #include <linux/mm.h> | ||
28 | #include <linux/pci.h> | 25 | #include <linux/pci.h> |
29 | #include <linux/ioport.h> | ||
30 | #include <linux/io.h> | ||
31 | #include <asm/irq.h> | ||
32 | 26 | ||
33 | #include <pcmcia/cs_types.h> | ||
34 | #include <pcmcia/ss.h> | 27 | #include <pcmcia/ss.h> |
35 | #include <pcmcia/cs.h> | ||
36 | #include <pcmcia/cistpl.h> | ||
37 | #include "cs_internal.h" | ||
38 | |||
39 | /*====================================================================*/ | ||
40 | |||
41 | /* Offsets in the Expansion ROM Image Header */ | ||
42 | #define ROM_SIGNATURE 0x0000 /* 2 bytes */ | ||
43 | #define ROM_DATA_PTR 0x0018 /* 2 bytes */ | ||
44 | |||
45 | /* Offsets in the CardBus PC Card Data Structure */ | ||
46 | #define PCDATA_SIGNATURE 0x0000 /* 4 bytes */ | ||
47 | #define PCDATA_VPD_PTR 0x0008 /* 2 bytes */ | ||
48 | #define PCDATA_LENGTH 0x000a /* 2 bytes */ | ||
49 | #define PCDATA_REVISION 0x000c | ||
50 | #define PCDATA_IMAGE_SZ 0x0010 /* 2 bytes */ | ||
51 | #define PCDATA_ROM_LEVEL 0x0012 /* 2 bytes */ | ||
52 | #define PCDATA_CODE_TYPE 0x0014 | ||
53 | #define PCDATA_INDICATOR 0x0015 | ||
54 | |||
55 | /*===================================================================== | ||
56 | |||
57 | Expansion ROM's have a special layout, and pointers specify an | ||
58 | image number and an offset within that image. xlate_rom_addr() | ||
59 | converts an image/offset address to an absolute offset from the | ||
60 | ROM's base address. | ||
61 | |||
62 | =====================================================================*/ | ||
63 | |||
64 | static u_int xlate_rom_addr(void __iomem *b, u_int addr) | ||
65 | { | ||
66 | u_int img = 0, ofs = 0, sz; | ||
67 | u_short data; | ||
68 | while ((readb(b) == 0x55) && (readb(b + 1) == 0xaa)) { | ||
69 | if (img == (addr >> 28)) | ||
70 | return (addr & 0x0fffffff) + ofs; | ||
71 | data = readb(b + ROM_DATA_PTR) + (readb(b + ROM_DATA_PTR + 1) << 8); | ||
72 | sz = 512 * (readb(b + data + PCDATA_IMAGE_SZ) + | ||
73 | (readb(b + data + PCDATA_IMAGE_SZ + 1) << 8)); | ||
74 | if ((sz == 0) || (readb(b + data + PCDATA_INDICATOR) & 0x80)) | ||
75 | break; | ||
76 | b += sz; | ||
77 | ofs += sz; | ||
78 | img++; | ||
79 | } | ||
80 | return 0; | ||
81 | } | ||
82 | |||
83 | /*===================================================================== | ||
84 | |||
85 | These are similar to setup_cis_mem and release_cis_mem for 16-bit | ||
86 | cards. The "result" that is used externally is the cb_cis_virt | ||
87 | pointer in the struct pcmcia_socket structure. | ||
88 | |||
89 | =====================================================================*/ | ||
90 | |||
91 | static void cb_release_cis_mem(struct pcmcia_socket *s) | ||
92 | { | ||
93 | if (s->cb_cis_virt) { | ||
94 | dev_dbg(&s->dev, "cb_release_cis_mem()\n"); | ||
95 | iounmap(s->cb_cis_virt); | ||
96 | s->cb_cis_virt = NULL; | ||
97 | s->cb_cis_res = NULL; | ||
98 | } | ||
99 | } | ||
100 | |||
101 | static int cb_setup_cis_mem(struct pcmcia_socket *s, struct resource *res) | ||
102 | { | ||
103 | unsigned int start, size; | ||
104 | |||
105 | if (res == s->cb_cis_res) | ||
106 | return 0; | ||
107 | |||
108 | if (s->cb_cis_res) | ||
109 | cb_release_cis_mem(s); | ||
110 | |||
111 | start = res->start; | ||
112 | size = res->end - start + 1; | ||
113 | s->cb_cis_virt = ioremap(start, size); | ||
114 | |||
115 | if (!s->cb_cis_virt) | ||
116 | return -1; | ||
117 | |||
118 | s->cb_cis_res = res; | ||
119 | |||
120 | return 0; | ||
121 | } | ||
122 | |||
123 | /*===================================================================== | ||
124 | |||
125 | This is used by the CIS processing code to read CIS information | ||
126 | from a CardBus device. | ||
127 | |||
128 | =====================================================================*/ | ||
129 | |||
130 | int read_cb_mem(struct pcmcia_socket *s, int space, u_int addr, u_int len, | ||
131 | void *ptr) | ||
132 | { | ||
133 | struct pci_dev *dev; | ||
134 | struct resource *res; | ||
135 | |||
136 | dev_dbg(&s->dev, "read_cb_mem(%d, %#x, %u)\n", space, addr, len); | ||
137 | 28 | ||
138 | dev = pci_get_slot(s->cb_dev->subordinate, 0); | ||
139 | if (!dev) | ||
140 | goto fail; | ||
141 | |||
142 | /* Config space? */ | ||
143 | if (space == 0) { | ||
144 | if (addr + len > 0x100) | ||
145 | goto failput; | ||
146 | for (; len; addr++, ptr++, len--) | ||
147 | pci_read_config_byte(dev, addr, ptr); | ||
148 | return 0; | ||
149 | } | ||
150 | |||
151 | res = dev->resource + space - 1; | ||
152 | |||
153 | pci_dev_put(dev); | ||
154 | |||
155 | if (!res->flags) | ||
156 | goto fail; | ||
157 | |||
158 | if (cb_setup_cis_mem(s, res) != 0) | ||
159 | goto fail; | ||
160 | |||
161 | if (space == 7) { | ||
162 | addr = xlate_rom_addr(s->cb_cis_virt, addr); | ||
163 | if (addr == 0) | ||
164 | goto fail; | ||
165 | } | ||
166 | |||
167 | if (addr + len > res->end - res->start) | ||
168 | goto fail; | ||
169 | |||
170 | memcpy_fromio(ptr, s->cb_cis_virt + addr, len); | ||
171 | return 0; | ||
172 | |||
173 | failput: | ||
174 | pci_dev_put(dev); | ||
175 | fail: | ||
176 | memset(ptr, 0xff, len); | ||
177 | return -1; | ||
178 | } | ||
179 | |||
180 | /*===================================================================== | ||
181 | |||
182 | cb_alloc() and cb_free() allocate and free the kernel data | ||
183 | structures for a Cardbus device, and handle the lowest level PCI | ||
184 | device setup issues. | ||
185 | |||
186 | =====================================================================*/ | ||
187 | 29 | ||
188 | static void cardbus_config_irq_and_cls(struct pci_bus *bus, int irq) | 30 | static void cardbus_config_irq_and_cls(struct pci_bus *bus, int irq) |
189 | { | 31 | { |
@@ -215,6 +57,13 @@ static void cardbus_config_irq_and_cls(struct pci_bus *bus, int irq) | |||
215 | } | 57 | } |
216 | } | 58 | } |
217 | 59 | ||
60 | /** | ||
61 | * cb_alloc() - add CardBus device | ||
62 | * @s: the pcmcia_socket where the CardBus device is located | ||
63 | * | ||
64 | * cb_alloc() allocates the kernel data structures for a Cardbus device | ||
65 | * and handles the lowest level PCI device setup issues. | ||
66 | */ | ||
218 | int __ref cb_alloc(struct pcmcia_socket *s) | 67 | int __ref cb_alloc(struct pcmcia_socket *s) |
219 | { | 68 | { |
220 | struct pci_bus *bus = s->cb_dev->subordinate; | 69 | struct pci_bus *bus = s->cb_dev->subordinate; |
@@ -249,12 +98,16 @@ int __ref cb_alloc(struct pcmcia_socket *s) | |||
249 | return 0; | 98 | return 0; |
250 | } | 99 | } |
251 | 100 | ||
101 | /** | ||
102 | * cb_free() - remove CardBus device | ||
103 | * @s: the pcmcia_socket where the CardBus device was located | ||
104 | * | ||
105 | * cb_free() handles the lowest level PCI device cleanup. | ||
106 | */ | ||
252 | void cb_free(struct pcmcia_socket *s) | 107 | void cb_free(struct pcmcia_socket *s) |
253 | { | 108 | { |
254 | struct pci_dev *bridge = s->cb_dev; | 109 | struct pci_dev *bridge = s->cb_dev; |
255 | 110 | ||
256 | cb_release_cis_mem(s); | ||
257 | |||
258 | if (bridge) | 111 | if (bridge) |
259 | pci_remove_behind_bridge(bridge); | 112 | pci_remove_behind_bridge(bridge); |
260 | } | 113 | } |
diff --git a/drivers/pcmcia/cistpl.c b/drivers/pcmcia/cistpl.c index 25b1cd219e37..2f3622dd4b69 100644 --- a/drivers/pcmcia/cistpl.c +++ b/drivers/pcmcia/cistpl.c | |||
@@ -64,6 +64,7 @@ module_param(cis_width, int, 0444); | |||
64 | 64 | ||
65 | void release_cis_mem(struct pcmcia_socket *s) | 65 | void release_cis_mem(struct pcmcia_socket *s) |
66 | { | 66 | { |
67 | mutex_lock(&s->ops_mutex); | ||
67 | if (s->cis_mem.flags & MAP_ACTIVE) { | 68 | if (s->cis_mem.flags & MAP_ACTIVE) { |
68 | s->cis_mem.flags &= ~MAP_ACTIVE; | 69 | s->cis_mem.flags &= ~MAP_ACTIVE; |
69 | s->ops->set_mem_map(s, &s->cis_mem); | 70 | s->ops->set_mem_map(s, &s->cis_mem); |
@@ -75,13 +76,15 @@ void release_cis_mem(struct pcmcia_socket *s) | |||
75 | iounmap(s->cis_virt); | 76 | iounmap(s->cis_virt); |
76 | s->cis_virt = NULL; | 77 | s->cis_virt = NULL; |
77 | } | 78 | } |
79 | mutex_unlock(&s->ops_mutex); | ||
78 | } | 80 | } |
79 | EXPORT_SYMBOL(release_cis_mem); | ||
80 | 81 | ||
81 | /* | 82 | /* |
82 | * Map the card memory at "card_offset" into virtual space. | 83 | * Map the card memory at "card_offset" into virtual space. |
83 | * If flags & MAP_ATTRIB, map the attribute space, otherwise | 84 | * If flags & MAP_ATTRIB, map the attribute space, otherwise |
84 | * map the memory space. | 85 | * map the memory space. |
86 | * | ||
87 | * Must be called with ops_mutex held. | ||
85 | */ | 88 | */ |
86 | static void __iomem * | 89 | static void __iomem * |
87 | set_cis_map(struct pcmcia_socket *s, unsigned int card_offset, unsigned int flags) | 90 | set_cis_map(struct pcmcia_socket *s, unsigned int card_offset, unsigned int flags) |
@@ -140,6 +143,7 @@ int pcmcia_read_cis_mem(struct pcmcia_socket *s, int attr, u_int addr, | |||
140 | 143 | ||
141 | dev_dbg(&s->dev, "pcmcia_read_cis_mem(%d, %#x, %u)\n", attr, addr, len); | 144 | dev_dbg(&s->dev, "pcmcia_read_cis_mem(%d, %#x, %u)\n", attr, addr, len); |
142 | 145 | ||
146 | mutex_lock(&s->ops_mutex); | ||
143 | if (attr & IS_INDIRECT) { | 147 | if (attr & IS_INDIRECT) { |
144 | /* Indirect accesses use a bunch of special registers at fixed | 148 | /* Indirect accesses use a bunch of special registers at fixed |
145 | locations in common memory */ | 149 | locations in common memory */ |
@@ -151,7 +155,9 @@ int pcmcia_read_cis_mem(struct pcmcia_socket *s, int attr, u_int addr, | |||
151 | 155 | ||
152 | sys = set_cis_map(s, 0, MAP_ACTIVE | ((cis_width) ? MAP_16BIT : 0)); | 156 | sys = set_cis_map(s, 0, MAP_ACTIVE | ((cis_width) ? MAP_16BIT : 0)); |
153 | if (!sys) { | 157 | if (!sys) { |
158 | dev_dbg(&s->dev, "could not map memory\n"); | ||
154 | memset(ptr, 0xff, len); | 159 | memset(ptr, 0xff, len); |
160 | mutex_unlock(&s->ops_mutex); | ||
155 | return -1; | 161 | return -1; |
156 | } | 162 | } |
157 | 163 | ||
@@ -165,6 +171,9 @@ int pcmcia_read_cis_mem(struct pcmcia_socket *s, int attr, u_int addr, | |||
165 | } else { | 171 | } else { |
166 | u_int inc = 1, card_offset, flags; | 172 | u_int inc = 1, card_offset, flags; |
167 | 173 | ||
174 | if (addr > CISTPL_MAX_CIS_SIZE) | ||
175 | dev_dbg(&s->dev, "attempt to read CIS mem at addr %#x", addr); | ||
176 | |||
168 | flags = MAP_ACTIVE | ((cis_width) ? MAP_16BIT : 0); | 177 | flags = MAP_ACTIVE | ((cis_width) ? MAP_16BIT : 0); |
169 | if (attr) { | 178 | if (attr) { |
170 | flags |= MAP_ATTRIB; | 179 | flags |= MAP_ATTRIB; |
@@ -176,7 +185,9 @@ int pcmcia_read_cis_mem(struct pcmcia_socket *s, int attr, u_int addr, | |||
176 | while (len) { | 185 | while (len) { |
177 | sys = set_cis_map(s, card_offset, flags); | 186 | sys = set_cis_map(s, card_offset, flags); |
178 | if (!sys) { | 187 | if (!sys) { |
188 | dev_dbg(&s->dev, "could not map memory\n"); | ||
179 | memset(ptr, 0xff, len); | 189 | memset(ptr, 0xff, len); |
190 | mutex_unlock(&s->ops_mutex); | ||
180 | return -1; | 191 | return -1; |
181 | } | 192 | } |
182 | end = sys + s->map_size; | 193 | end = sys + s->map_size; |
@@ -190,12 +201,12 @@ int pcmcia_read_cis_mem(struct pcmcia_socket *s, int attr, u_int addr, | |||
190 | addr = 0; | 201 | addr = 0; |
191 | } | 202 | } |
192 | } | 203 | } |
204 | mutex_unlock(&s->ops_mutex); | ||
193 | dev_dbg(&s->dev, " %#2.2x %#2.2x %#2.2x %#2.2x ...\n", | 205 | dev_dbg(&s->dev, " %#2.2x %#2.2x %#2.2x %#2.2x ...\n", |
194 | *(u_char *)(ptr+0), *(u_char *)(ptr+1), | 206 | *(u_char *)(ptr+0), *(u_char *)(ptr+1), |
195 | *(u_char *)(ptr+2), *(u_char *)(ptr+3)); | 207 | *(u_char *)(ptr+2), *(u_char *)(ptr+3)); |
196 | return 0; | 208 | return 0; |
197 | } | 209 | } |
198 | EXPORT_SYMBOL(pcmcia_read_cis_mem); | ||
199 | 210 | ||
200 | 211 | ||
201 | void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr, u_int addr, | 212 | void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr, u_int addr, |
@@ -206,6 +217,7 @@ void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr, u_int addr, | |||
206 | 217 | ||
207 | dev_dbg(&s->dev, "pcmcia_write_cis_mem(%d, %#x, %u)\n", attr, addr, len); | 218 | dev_dbg(&s->dev, "pcmcia_write_cis_mem(%d, %#x, %u)\n", attr, addr, len); |
208 | 219 | ||
220 | mutex_lock(&s->ops_mutex); | ||
209 | if (attr & IS_INDIRECT) { | 221 | if (attr & IS_INDIRECT) { |
210 | /* Indirect accesses use a bunch of special registers at fixed | 222 | /* Indirect accesses use a bunch of special registers at fixed |
211 | locations in common memory */ | 223 | locations in common memory */ |
@@ -216,8 +228,11 @@ void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr, u_int addr, | |||
216 | } | 228 | } |
217 | 229 | ||
218 | sys = set_cis_map(s, 0, MAP_ACTIVE | ((cis_width) ? MAP_16BIT : 0)); | 230 | sys = set_cis_map(s, 0, MAP_ACTIVE | ((cis_width) ? MAP_16BIT : 0)); |
219 | if (!sys) | 231 | if (!sys) { |
232 | dev_dbg(&s->dev, "could not map memory\n"); | ||
233 | mutex_unlock(&s->ops_mutex); | ||
220 | return; /* FIXME: Error */ | 234 | return; /* FIXME: Error */ |
235 | } | ||
221 | 236 | ||
222 | writeb(flags, sys+CISREG_ICTRL0); | 237 | writeb(flags, sys+CISREG_ICTRL0); |
223 | writeb(addr & 0xff, sys+CISREG_IADDR0); | 238 | writeb(addr & 0xff, sys+CISREG_IADDR0); |
@@ -239,8 +254,11 @@ void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr, u_int addr, | |||
239 | card_offset = addr & ~(s->map_size-1); | 254 | card_offset = addr & ~(s->map_size-1); |
240 | while (len) { | 255 | while (len) { |
241 | sys = set_cis_map(s, card_offset, flags); | 256 | sys = set_cis_map(s, card_offset, flags); |
242 | if (!sys) | 257 | if (!sys) { |
258 | dev_dbg(&s->dev, "could not map memory\n"); | ||
259 | mutex_unlock(&s->ops_mutex); | ||
243 | return; /* FIXME: error */ | 260 | return; /* FIXME: error */ |
261 | } | ||
244 | 262 | ||
245 | end = sys + s->map_size; | 263 | end = sys + s->map_size; |
246 | sys = sys + (addr & (s->map_size-1)); | 264 | sys = sys + (addr & (s->map_size-1)); |
@@ -253,8 +271,8 @@ void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr, u_int addr, | |||
253 | addr = 0; | 271 | addr = 0; |
254 | } | 272 | } |
255 | } | 273 | } |
274 | mutex_unlock(&s->ops_mutex); | ||
256 | } | 275 | } |
257 | EXPORT_SYMBOL(pcmcia_write_cis_mem); | ||
258 | 276 | ||
259 | 277 | ||
260 | /*====================================================================== | 278 | /*====================================================================== |
@@ -265,32 +283,36 @@ EXPORT_SYMBOL(pcmcia_write_cis_mem); | |||
265 | 283 | ||
266 | ======================================================================*/ | 284 | ======================================================================*/ |
267 | 285 | ||
268 | static void read_cis_cache(struct pcmcia_socket *s, int attr, u_int addr, | 286 | static int read_cis_cache(struct pcmcia_socket *s, int attr, u_int addr, |
269 | size_t len, void *ptr) | 287 | size_t len, void *ptr) |
270 | { | 288 | { |
271 | struct cis_cache_entry *cis; | 289 | struct cis_cache_entry *cis; |
272 | int ret; | 290 | int ret = 0; |
273 | 291 | ||
274 | if (s->fake_cis) { | 292 | if (s->state & SOCKET_CARDBUS) |
275 | if (s->fake_cis_len >= addr+len) | 293 | return -EINVAL; |
276 | memcpy(ptr, s->fake_cis+addr, len); | ||
277 | else | ||
278 | memset(ptr, 0xff, len); | ||
279 | return; | ||
280 | } | ||
281 | 294 | ||
282 | list_for_each_entry(cis, &s->cis_cache, node) { | 295 | mutex_lock(&s->ops_mutex); |
283 | if (cis->addr == addr && cis->len == len && cis->attr == attr) { | 296 | if (s->fake_cis) { |
284 | memcpy(ptr, cis->cache, len); | 297 | if (s->fake_cis_len >= addr+len) |
285 | return; | 298 | memcpy(ptr, s->fake_cis+addr, len); |
299 | else { | ||
300 | memset(ptr, 0xff, len); | ||
301 | ret = -EINVAL; | ||
302 | } | ||
303 | mutex_unlock(&s->ops_mutex); | ||
304 | return ret; | ||
286 | } | 305 | } |
287 | } | ||
288 | 306 | ||
289 | #ifdef CONFIG_CARDBUS | 307 | list_for_each_entry(cis, &s->cis_cache, node) { |
290 | if (s->state & SOCKET_CARDBUS) | 308 | if (cis->addr == addr && cis->len == len && cis->attr == attr) { |
291 | ret = read_cb_mem(s, attr, addr, len, ptr); | 309 | memcpy(ptr, cis->cache, len); |
292 | else | 310 | mutex_unlock(&s->ops_mutex); |
293 | #endif | 311 | return 0; |
312 | } | ||
313 | } | ||
314 | mutex_unlock(&s->ops_mutex); | ||
315 | |||
294 | ret = pcmcia_read_cis_mem(s, attr, addr, len, ptr); | 316 | ret = pcmcia_read_cis_mem(s, attr, addr, len, ptr); |
295 | 317 | ||
296 | if (ret == 0) { | 318 | if (ret == 0) { |
@@ -301,9 +323,12 @@ static void read_cis_cache(struct pcmcia_socket *s, int attr, u_int addr, | |||
301 | cis->len = len; | 323 | cis->len = len; |
302 | cis->attr = attr; | 324 | cis->attr = attr; |
303 | memcpy(cis->cache, ptr, len); | 325 | memcpy(cis->cache, ptr, len); |
326 | mutex_lock(&s->ops_mutex); | ||
304 | list_add(&cis->node, &s->cis_cache); | 327 | list_add(&cis->node, &s->cis_cache); |
328 | mutex_unlock(&s->ops_mutex); | ||
305 | } | 329 | } |
306 | } | 330 | } |
331 | return ret; | ||
307 | } | 332 | } |
308 | 333 | ||
309 | static void | 334 | static void |
@@ -311,32 +336,35 @@ remove_cis_cache(struct pcmcia_socket *s, int attr, u_int addr, u_int len) | |||
311 | { | 336 | { |
312 | struct cis_cache_entry *cis; | 337 | struct cis_cache_entry *cis; |
313 | 338 | ||
339 | mutex_lock(&s->ops_mutex); | ||
314 | list_for_each_entry(cis, &s->cis_cache, node) | 340 | list_for_each_entry(cis, &s->cis_cache, node) |
315 | if (cis->addr == addr && cis->len == len && cis->attr == attr) { | 341 | if (cis->addr == addr && cis->len == len && cis->attr == attr) { |
316 | list_del(&cis->node); | 342 | list_del(&cis->node); |
317 | kfree(cis); | 343 | kfree(cis); |
318 | break; | 344 | break; |
319 | } | 345 | } |
346 | mutex_unlock(&s->ops_mutex); | ||
320 | } | 347 | } |
321 | 348 | ||
349 | /** | ||
350 | * destroy_cis_cache() - destroy the CIS cache | ||
351 | * @s: pcmcia_socket for which CIS cache shall be destroyed | ||
352 | * | ||
353 | * This destroys the CIS cache but keeps any fake CIS alive. Must be | ||
354 | * called with ops_mutex held. | ||
355 | */ | ||
356 | |||
322 | void destroy_cis_cache(struct pcmcia_socket *s) | 357 | void destroy_cis_cache(struct pcmcia_socket *s) |
323 | { | 358 | { |
324 | struct list_head *l, *n; | 359 | struct list_head *l, *n; |
360 | struct cis_cache_entry *cis; | ||
325 | 361 | ||
326 | list_for_each_safe(l, n, &s->cis_cache) { | 362 | list_for_each_safe(l, n, &s->cis_cache) { |
327 | struct cis_cache_entry *cis = list_entry(l, struct cis_cache_entry, node); | 363 | cis = list_entry(l, struct cis_cache_entry, node); |
328 | |||
329 | list_del(&cis->node); | 364 | list_del(&cis->node); |
330 | kfree(cis); | 365 | kfree(cis); |
331 | } | 366 | } |
332 | |||
333 | /* | ||
334 | * If there was a fake CIS, destroy that as well. | ||
335 | */ | ||
336 | kfree(s->fake_cis); | ||
337 | s->fake_cis = NULL; | ||
338 | } | 367 | } |
339 | EXPORT_SYMBOL(destroy_cis_cache); | ||
340 | 368 | ||
341 | /*====================================================================== | 369 | /*====================================================================== |
342 | 370 | ||
@@ -349,6 +377,10 @@ int verify_cis_cache(struct pcmcia_socket *s) | |||
349 | { | 377 | { |
350 | struct cis_cache_entry *cis; | 378 | struct cis_cache_entry *cis; |
351 | char *buf; | 379 | char *buf; |
380 | int ret; | ||
381 | |||
382 | if (s->state & SOCKET_CARDBUS) | ||
383 | return -EINVAL; | ||
352 | 384 | ||
353 | buf = kmalloc(256, GFP_KERNEL); | 385 | buf = kmalloc(256, GFP_KERNEL); |
354 | if (buf == NULL) { | 386 | if (buf == NULL) { |
@@ -361,14 +393,9 @@ int verify_cis_cache(struct pcmcia_socket *s) | |||
361 | 393 | ||
362 | if (len > 256) | 394 | if (len > 256) |
363 | len = 256; | 395 | len = 256; |
364 | #ifdef CONFIG_CARDBUS | ||
365 | if (s->state & SOCKET_CARDBUS) | ||
366 | read_cb_mem(s, cis->attr, cis->addr, len, buf); | ||
367 | else | ||
368 | #endif | ||
369 | pcmcia_read_cis_mem(s, cis->attr, cis->addr, len, buf); | ||
370 | 396 | ||
371 | if (memcmp(buf, cis->cache, len) != 0) { | 397 | ret = pcmcia_read_cis_mem(s, cis->attr, cis->addr, len, buf); |
398 | if (ret || memcmp(buf, cis->cache, len) != 0) { | ||
372 | kfree(buf); | 399 | kfree(buf); |
373 | return -1; | 400 | return -1; |
374 | } | 401 | } |
@@ -391,17 +418,20 @@ int pcmcia_replace_cis(struct pcmcia_socket *s, | |||
391 | dev_printk(KERN_WARNING, &s->dev, "replacement CIS too big\n"); | 418 | dev_printk(KERN_WARNING, &s->dev, "replacement CIS too big\n"); |
392 | return -EINVAL; | 419 | return -EINVAL; |
393 | } | 420 | } |
421 | mutex_lock(&s->ops_mutex); | ||
394 | kfree(s->fake_cis); | 422 | kfree(s->fake_cis); |
395 | s->fake_cis = kmalloc(len, GFP_KERNEL); | 423 | s->fake_cis = kmalloc(len, GFP_KERNEL); |
396 | if (s->fake_cis == NULL) { | 424 | if (s->fake_cis == NULL) { |
397 | dev_printk(KERN_WARNING, &s->dev, "no memory to replace CIS\n"); | 425 | dev_printk(KERN_WARNING, &s->dev, "no memory to replace CIS\n"); |
426 | mutex_unlock(&s->ops_mutex); | ||
398 | return -ENOMEM; | 427 | return -ENOMEM; |
399 | } | 428 | } |
400 | s->fake_cis_len = len; | 429 | s->fake_cis_len = len; |
401 | memcpy(s->fake_cis, data, len); | 430 | memcpy(s->fake_cis, data, len); |
431 | dev_info(&s->dev, "Using replacement CIS\n"); | ||
432 | mutex_unlock(&s->ops_mutex); | ||
402 | return 0; | 433 | return 0; |
403 | } | 434 | } |
404 | EXPORT_SYMBOL(pcmcia_replace_cis); | ||
405 | 435 | ||
406 | /*====================================================================== | 436 | /*====================================================================== |
407 | 437 | ||
@@ -425,25 +455,16 @@ int pccard_get_first_tuple(struct pcmcia_socket *s, unsigned int function, tuple | |||
425 | { | 455 | { |
426 | if (!s) | 456 | if (!s) |
427 | return -EINVAL; | 457 | return -EINVAL; |
428 | if (!(s->state & SOCKET_PRESENT)) | 458 | |
459 | if (!(s->state & SOCKET_PRESENT) || (s->state & SOCKET_CARDBUS)) | ||
429 | return -ENODEV; | 460 | return -ENODEV; |
430 | tuple->TupleLink = tuple->Flags = 0; | 461 | tuple->TupleLink = tuple->Flags = 0; |
431 | #ifdef CONFIG_CARDBUS | 462 | |
432 | if (s->state & SOCKET_CARDBUS) { | 463 | /* Assume presence of a LONGLINK_C to address 0 */ |
433 | struct pci_dev *dev = s->cb_dev; | 464 | tuple->CISOffset = tuple->LinkOffset = 0; |
434 | u_int ptr; | 465 | SPACE(tuple->Flags) = HAS_LINK(tuple->Flags) = 1; |
435 | pci_bus_read_config_dword(dev->subordinate, 0, PCI_CARDBUS_CIS, &ptr); | 466 | |
436 | tuple->CISOffset = ptr & ~7; | 467 | if ((s->functions > 1) && !(tuple->Attributes & TUPLE_RETURN_COMMON)) { |
437 | SPACE(tuple->Flags) = (ptr & 7); | ||
438 | } else | ||
439 | #endif | ||
440 | { | ||
441 | /* Assume presence of a LONGLINK_C to address 0 */ | ||
442 | tuple->CISOffset = tuple->LinkOffset = 0; | ||
443 | SPACE(tuple->Flags) = HAS_LINK(tuple->Flags) = 1; | ||
444 | } | ||
445 | if (!(s->state & SOCKET_CARDBUS) && (s->functions > 1) && | ||
446 | !(tuple->Attributes & TUPLE_RETURN_COMMON)) { | ||
447 | cisdata_t req = tuple->DesiredTuple; | 468 | cisdata_t req = tuple->DesiredTuple; |
448 | tuple->DesiredTuple = CISTPL_LONGLINK_MFC; | 469 | tuple->DesiredTuple = CISTPL_LONGLINK_MFC; |
449 | if (pccard_get_next_tuple(s, function, tuple) == 0) { | 470 | if (pccard_get_next_tuple(s, function, tuple) == 0) { |
@@ -456,17 +477,19 @@ int pccard_get_first_tuple(struct pcmcia_socket *s, unsigned int function, tuple | |||
456 | } | 477 | } |
457 | return pccard_get_next_tuple(s, function, tuple); | 478 | return pccard_get_next_tuple(s, function, tuple); |
458 | } | 479 | } |
459 | EXPORT_SYMBOL(pccard_get_first_tuple); | ||
460 | 480 | ||
461 | static int follow_link(struct pcmcia_socket *s, tuple_t *tuple) | 481 | static int follow_link(struct pcmcia_socket *s, tuple_t *tuple) |
462 | { | 482 | { |
463 | u_char link[5]; | 483 | u_char link[5]; |
464 | u_int ofs; | 484 | u_int ofs; |
485 | int ret; | ||
465 | 486 | ||
466 | if (MFC_FN(tuple->Flags)) { | 487 | if (MFC_FN(tuple->Flags)) { |
467 | /* Get indirect link from the MFC tuple */ | 488 | /* Get indirect link from the MFC tuple */ |
468 | read_cis_cache(s, LINK_SPACE(tuple->Flags), | 489 | ret = read_cis_cache(s, LINK_SPACE(tuple->Flags), |
469 | tuple->LinkOffset, 5, link); | 490 | tuple->LinkOffset, 5, link); |
491 | if (ret) | ||
492 | return -1; | ||
470 | ofs = get_unaligned_le32(link + 1); | 493 | ofs = get_unaligned_le32(link + 1); |
471 | SPACE(tuple->Flags) = (link[0] == CISTPL_MFC_ATTR); | 494 | SPACE(tuple->Flags) = (link[0] == CISTPL_MFC_ATTR); |
472 | /* Move to the next indirect link */ | 495 | /* Move to the next indirect link */ |
@@ -479,10 +502,12 @@ static int follow_link(struct pcmcia_socket *s, tuple_t *tuple) | |||
479 | } else { | 502 | } else { |
480 | return -1; | 503 | return -1; |
481 | } | 504 | } |
482 | if (!(s->state & SOCKET_CARDBUS) && SPACE(tuple->Flags)) { | 505 | if (SPACE(tuple->Flags)) { |
483 | /* This is ugly, but a common CIS error is to code the long | 506 | /* This is ugly, but a common CIS error is to code the long |
484 | link offset incorrectly, so we check the right spot... */ | 507 | link offset incorrectly, so we check the right spot... */ |
485 | read_cis_cache(s, SPACE(tuple->Flags), ofs, 5, link); | 508 | ret = read_cis_cache(s, SPACE(tuple->Flags), ofs, 5, link); |
509 | if (ret) | ||
510 | return -1; | ||
486 | if ((link[0] == CISTPL_LINKTARGET) && (link[1] >= 3) && | 511 | if ((link[0] == CISTPL_LINKTARGET) && (link[1] >= 3) && |
487 | (strncmp(link+2, "CIS", 3) == 0)) | 512 | (strncmp(link+2, "CIS", 3) == 0)) |
488 | return ofs; | 513 | return ofs; |
@@ -490,7 +515,9 @@ static int follow_link(struct pcmcia_socket *s, tuple_t *tuple) | |||
490 | /* Then, we try the wrong spot... */ | 515 | /* Then, we try the wrong spot... */ |
491 | ofs = ofs >> 1; | 516 | ofs = ofs >> 1; |
492 | } | 517 | } |
493 | read_cis_cache(s, SPACE(tuple->Flags), ofs, 5, link); | 518 | ret = read_cis_cache(s, SPACE(tuple->Flags), ofs, 5, link); |
519 | if (ret) | ||
520 | return -1; | ||
494 | if ((link[0] == CISTPL_LINKTARGET) && (link[1] >= 3) && | 521 | if ((link[0] == CISTPL_LINKTARGET) && (link[1] >= 3) && |
495 | (strncmp(link+2, "CIS", 3) == 0)) | 522 | (strncmp(link+2, "CIS", 3) == 0)) |
496 | return ofs; | 523 | return ofs; |
@@ -502,10 +529,11 @@ int pccard_get_next_tuple(struct pcmcia_socket *s, unsigned int function, tuple_ | |||
502 | { | 529 | { |
503 | u_char link[2], tmp; | 530 | u_char link[2], tmp; |
504 | int ofs, i, attr; | 531 | int ofs, i, attr; |
532 | int ret; | ||
505 | 533 | ||
506 | if (!s) | 534 | if (!s) |
507 | return -EINVAL; | 535 | return -EINVAL; |
508 | if (!(s->state & SOCKET_PRESENT)) | 536 | if (!(s->state & SOCKET_PRESENT) || (s->state & SOCKET_CARDBUS)) |
509 | return -ENODEV; | 537 | return -ENODEV; |
510 | 538 | ||
511 | link[1] = tuple->TupleLink; | 539 | link[1] = tuple->TupleLink; |
@@ -516,7 +544,9 @@ int pccard_get_next_tuple(struct pcmcia_socket *s, unsigned int function, tuple_ | |||
516 | if (link[1] == 0xff) { | 544 | if (link[1] == 0xff) { |
517 | link[0] = CISTPL_END; | 545 | link[0] = CISTPL_END; |
518 | } else { | 546 | } else { |
519 | read_cis_cache(s, attr, ofs, 2, link); | 547 | ret = read_cis_cache(s, attr, ofs, 2, link); |
548 | if (ret) | ||
549 | return -1; | ||
520 | if (link[0] == CISTPL_NULL) { | 550 | if (link[0] == CISTPL_NULL) { |
521 | ofs++; continue; | 551 | ofs++; continue; |
522 | } | 552 | } |
@@ -528,7 +558,9 @@ int pccard_get_next_tuple(struct pcmcia_socket *s, unsigned int function, tuple_ | |||
528 | if (ofs < 0) | 558 | if (ofs < 0) |
529 | return -ENOSPC; | 559 | return -ENOSPC; |
530 | attr = SPACE(tuple->Flags); | 560 | attr = SPACE(tuple->Flags); |
531 | read_cis_cache(s, attr, ofs, 2, link); | 561 | ret = read_cis_cache(s, attr, ofs, 2, link); |
562 | if (ret) | ||
563 | return -1; | ||
532 | } | 564 | } |
533 | 565 | ||
534 | /* Is this a link tuple? Make a note of it */ | 566 | /* Is this a link tuple? Make a note of it */ |
@@ -542,12 +574,16 @@ int pccard_get_next_tuple(struct pcmcia_socket *s, unsigned int function, tuple_ | |||
542 | case CISTPL_LONGLINK_A: | 574 | case CISTPL_LONGLINK_A: |
543 | HAS_LINK(tuple->Flags) = 1; | 575 | HAS_LINK(tuple->Flags) = 1; |
544 | LINK_SPACE(tuple->Flags) = attr | IS_ATTR; | 576 | LINK_SPACE(tuple->Flags) = attr | IS_ATTR; |
545 | read_cis_cache(s, attr, ofs+2, 4, &tuple->LinkOffset); | 577 | ret = read_cis_cache(s, attr, ofs+2, 4, &tuple->LinkOffset); |
578 | if (ret) | ||
579 | return -1; | ||
546 | break; | 580 | break; |
547 | case CISTPL_LONGLINK_C: | 581 | case CISTPL_LONGLINK_C: |
548 | HAS_LINK(tuple->Flags) = 1; | 582 | HAS_LINK(tuple->Flags) = 1; |
549 | LINK_SPACE(tuple->Flags) = attr & ~IS_ATTR; | 583 | LINK_SPACE(tuple->Flags) = attr & ~IS_ATTR; |
550 | read_cis_cache(s, attr, ofs+2, 4, &tuple->LinkOffset); | 584 | ret = read_cis_cache(s, attr, ofs+2, 4, &tuple->LinkOffset); |
585 | if (ret) | ||
586 | return -1; | ||
551 | break; | 587 | break; |
552 | case CISTPL_INDIRECT: | 588 | case CISTPL_INDIRECT: |
553 | HAS_LINK(tuple->Flags) = 1; | 589 | HAS_LINK(tuple->Flags) = 1; |
@@ -559,7 +595,9 @@ int pccard_get_next_tuple(struct pcmcia_socket *s, unsigned int function, tuple_ | |||
559 | LINK_SPACE(tuple->Flags) = attr; | 595 | LINK_SPACE(tuple->Flags) = attr; |
560 | if (function == BIND_FN_ALL) { | 596 | if (function == BIND_FN_ALL) { |
561 | /* Follow all the MFC links */ | 597 | /* Follow all the MFC links */ |
562 | read_cis_cache(s, attr, ofs+2, 1, &tmp); | 598 | ret = read_cis_cache(s, attr, ofs+2, 1, &tmp); |
599 | if (ret) | ||
600 | return -1; | ||
563 | MFC_FN(tuple->Flags) = tmp; | 601 | MFC_FN(tuple->Flags) = tmp; |
564 | } else { | 602 | } else { |
565 | /* Follow exactly one of the links */ | 603 | /* Follow exactly one of the links */ |
@@ -592,7 +630,6 @@ int pccard_get_next_tuple(struct pcmcia_socket *s, unsigned int function, tuple_ | |||
592 | tuple->CISOffset = ofs + 2; | 630 | tuple->CISOffset = ofs + 2; |
593 | return 0; | 631 | return 0; |
594 | } | 632 | } |
595 | EXPORT_SYMBOL(pccard_get_next_tuple); | ||
596 | 633 | ||
597 | /*====================================================================*/ | 634 | /*====================================================================*/ |
598 | 635 | ||
@@ -601,6 +638,7 @@ EXPORT_SYMBOL(pccard_get_next_tuple); | |||
601 | int pccard_get_tuple_data(struct pcmcia_socket *s, tuple_t *tuple) | 638 | int pccard_get_tuple_data(struct pcmcia_socket *s, tuple_t *tuple) |
602 | { | 639 | { |
603 | u_int len; | 640 | u_int len; |
641 | int ret; | ||
604 | 642 | ||
605 | if (!s) | 643 | if (!s) |
606 | return -EINVAL; | 644 | return -EINVAL; |
@@ -611,12 +649,13 @@ int pccard_get_tuple_data(struct pcmcia_socket *s, tuple_t *tuple) | |||
611 | tuple->TupleDataLen = tuple->TupleLink; | 649 | tuple->TupleDataLen = tuple->TupleLink; |
612 | if (len == 0) | 650 | if (len == 0) |
613 | return 0; | 651 | return 0; |
614 | read_cis_cache(s, SPACE(tuple->Flags), | 652 | ret = read_cis_cache(s, SPACE(tuple->Flags), |
615 | tuple->CISOffset + tuple->TupleOffset, | 653 | tuple->CISOffset + tuple->TupleOffset, |
616 | _MIN(len, tuple->TupleDataMax), tuple->TupleData); | 654 | _MIN(len, tuple->TupleDataMax), tuple->TupleData); |
655 | if (ret) | ||
656 | return -1; | ||
617 | return 0; | 657 | return 0; |
618 | } | 658 | } |
619 | EXPORT_SYMBOL(pccard_get_tuple_data); | ||
620 | 659 | ||
621 | 660 | ||
622 | /*====================================================================== | 661 | /*====================================================================== |
@@ -1190,119 +1229,6 @@ static int parse_cftable_entry(tuple_t *tuple, | |||
1190 | 1229 | ||
1191 | /*====================================================================*/ | 1230 | /*====================================================================*/ |
1192 | 1231 | ||
1193 | #ifdef CONFIG_CARDBUS | ||
1194 | |||
1195 | static int parse_bar(tuple_t *tuple, cistpl_bar_t *bar) | ||
1196 | { | ||
1197 | u_char *p; | ||
1198 | if (tuple->TupleDataLen < 6) | ||
1199 | return -EINVAL; | ||
1200 | p = (u_char *)tuple->TupleData; | ||
1201 | bar->attr = *p; | ||
1202 | p += 2; | ||
1203 | bar->size = get_unaligned_le32(p); | ||
1204 | return 0; | ||
1205 | } | ||
1206 | |||
1207 | static int parse_config_cb(tuple_t *tuple, cistpl_config_t *config) | ||
1208 | { | ||
1209 | u_char *p; | ||
1210 | |||
1211 | p = (u_char *)tuple->TupleData; | ||
1212 | if ((*p != 3) || (tuple->TupleDataLen < 6)) | ||
1213 | return -EINVAL; | ||
1214 | config->last_idx = *(++p); | ||
1215 | p++; | ||
1216 | config->base = get_unaligned_le32(p); | ||
1217 | config->subtuples = tuple->TupleDataLen - 6; | ||
1218 | return 0; | ||
1219 | } | ||
1220 | |||
1221 | static int parse_cftable_entry_cb(tuple_t *tuple, | ||
1222 | cistpl_cftable_entry_cb_t *entry) | ||
1223 | { | ||
1224 | u_char *p, *q, features; | ||
1225 | |||
1226 | p = tuple->TupleData; | ||
1227 | q = p + tuple->TupleDataLen; | ||
1228 | entry->index = *p & 0x3f; | ||
1229 | entry->flags = 0; | ||
1230 | if (*p & 0x40) | ||
1231 | entry->flags |= CISTPL_CFTABLE_DEFAULT; | ||
1232 | |||
1233 | /* Process optional features */ | ||
1234 | if (++p == q) | ||
1235 | return -EINVAL; | ||
1236 | features = *p; p++; | ||
1237 | |||
1238 | /* Power options */ | ||
1239 | if ((features & 3) > 0) { | ||
1240 | p = parse_power(p, q, &entry->vcc); | ||
1241 | if (p == NULL) | ||
1242 | return -EINVAL; | ||
1243 | } else | ||
1244 | entry->vcc.present = 0; | ||
1245 | if ((features & 3) > 1) { | ||
1246 | p = parse_power(p, q, &entry->vpp1); | ||
1247 | if (p == NULL) | ||
1248 | return -EINVAL; | ||
1249 | } else | ||
1250 | entry->vpp1.present = 0; | ||
1251 | if ((features & 3) > 2) { | ||
1252 | p = parse_power(p, q, &entry->vpp2); | ||
1253 | if (p == NULL) | ||
1254 | return -EINVAL; | ||
1255 | } else | ||
1256 | entry->vpp2.present = 0; | ||
1257 | |||
1258 | /* I/O window options */ | ||
1259 | if (features & 0x08) { | ||
1260 | if (p == q) | ||
1261 | return -EINVAL; | ||
1262 | entry->io = *p; p++; | ||
1263 | } else | ||
1264 | entry->io = 0; | ||
1265 | |||
1266 | /* Interrupt options */ | ||
1267 | if (features & 0x10) { | ||
1268 | p = parse_irq(p, q, &entry->irq); | ||
1269 | if (p == NULL) | ||
1270 | return -EINVAL; | ||
1271 | } else | ||
1272 | entry->irq.IRQInfo1 = 0; | ||
1273 | |||
1274 | if (features & 0x20) { | ||
1275 | if (p == q) | ||
1276 | return -EINVAL; | ||
1277 | entry->mem = *p; p++; | ||
1278 | } else | ||
1279 | entry->mem = 0; | ||
1280 | |||
1281 | /* Misc features */ | ||
1282 | if (features & 0x80) { | ||
1283 | if (p == q) | ||
1284 | return -EINVAL; | ||
1285 | entry->flags |= (*p << 8); | ||
1286 | if (*p & 0x80) { | ||
1287 | if (++p == q) | ||
1288 | return -EINVAL; | ||
1289 | entry->flags |= (*p << 16); | ||
1290 | } | ||
1291 | while (*p & 0x80) | ||
1292 | if (++p == q) | ||
1293 | return -EINVAL; | ||
1294 | p++; | ||
1295 | } | ||
1296 | |||
1297 | entry->subtuples = q-p; | ||
1298 | |||
1299 | return 0; | ||
1300 | } | ||
1301 | |||
1302 | #endif | ||
1303 | |||
1304 | /*====================================================================*/ | ||
1305 | |||
1306 | static int parse_device_geo(tuple_t *tuple, cistpl_device_geo_t *geo) | 1232 | static int parse_device_geo(tuple_t *tuple, cistpl_device_geo_t *geo) |
1307 | { | 1233 | { |
1308 | u_char *p, *q; | 1234 | u_char *p, *q; |
@@ -1404,17 +1330,6 @@ int pcmcia_parse_tuple(tuple_t *tuple, cisparse_t *parse) | |||
1404 | case CISTPL_DEVICE_A: | 1330 | case CISTPL_DEVICE_A: |
1405 | ret = parse_device(tuple, &parse->device); | 1331 | ret = parse_device(tuple, &parse->device); |
1406 | break; | 1332 | break; |
1407 | #ifdef CONFIG_CARDBUS | ||
1408 | case CISTPL_BAR: | ||
1409 | ret = parse_bar(tuple, &parse->bar); | ||
1410 | break; | ||
1411 | case CISTPL_CONFIG_CB: | ||
1412 | ret = parse_config_cb(tuple, &parse->config); | ||
1413 | break; | ||
1414 | case CISTPL_CFTABLE_ENTRY_CB: | ||
1415 | ret = parse_cftable_entry_cb(tuple, &parse->cftable_entry_cb); | ||
1416 | break; | ||
1417 | #endif | ||
1418 | case CISTPL_CHECKSUM: | 1333 | case CISTPL_CHECKSUM: |
1419 | ret = parse_checksum(tuple, &parse->checksum); | 1334 | ret = parse_checksum(tuple, &parse->checksum); |
1420 | break; | 1335 | break; |
@@ -1513,7 +1428,6 @@ done: | |||
1513 | kfree(buf); | 1428 | kfree(buf); |
1514 | return ret; | 1429 | return ret; |
1515 | } | 1430 | } |
1516 | EXPORT_SYMBOL(pccard_read_tuple); | ||
1517 | 1431 | ||
1518 | 1432 | ||
1519 | /** | 1433 | /** |
@@ -1573,84 +1487,238 @@ next_entry: | |||
1573 | kfree(buf); | 1487 | kfree(buf); |
1574 | return ret; | 1488 | return ret; |
1575 | } | 1489 | } |
1576 | EXPORT_SYMBOL(pccard_loop_tuple); | ||
1577 | 1490 | ||
1578 | 1491 | ||
1579 | /*====================================================================== | 1492 | /** |
1580 | 1493 | * pccard_validate_cis() - check whether card has a sensible CIS | |
1581 | This tries to determine if a card has a sensible CIS. It returns | 1494 | * @s: the struct pcmcia_socket we are to check |
1582 | the number of tuples in the CIS, or 0 if the CIS looks bad. The | 1495 | * @info: returns the number of tuples in the (valid) CIS, or 0 |
1583 | checks include making sure several critical tuples are present and | 1496 | * |
1584 | valid; seeing if the total number of tuples is reasonable; and | 1497 | * This tries to determine if a card has a sensible CIS. In @info, it |
1585 | looking for tuples that use reserved codes. | 1498 | * returns the number of tuples in the CIS, or 0 if the CIS looks bad. The |
1586 | 1499 | * checks include making sure several critical tuples are present and | |
1587 | ======================================================================*/ | 1500 | * valid; seeing if the total number of tuples is reasonable; and |
1588 | 1501 | * looking for tuples that use reserved codes. | |
1502 | * | ||
1503 | * The function returns 0 on success. | ||
1504 | */ | ||
1589 | int pccard_validate_cis(struct pcmcia_socket *s, unsigned int *info) | 1505 | int pccard_validate_cis(struct pcmcia_socket *s, unsigned int *info) |
1590 | { | 1506 | { |
1591 | tuple_t *tuple; | 1507 | tuple_t *tuple; |
1592 | cisparse_t *p; | 1508 | cisparse_t *p; |
1593 | unsigned int count = 0; | 1509 | unsigned int count = 0; |
1594 | int ret, reserved, dev_ok = 0, ident_ok = 0; | 1510 | int ret, reserved, dev_ok = 0, ident_ok = 0; |
1595 | 1511 | ||
1596 | if (!s) | 1512 | if (!s) |
1597 | return -EINVAL; | 1513 | return -EINVAL; |
1598 | 1514 | ||
1599 | tuple = kmalloc(sizeof(*tuple), GFP_KERNEL); | 1515 | /* We do not want to validate the CIS cache... */ |
1600 | if (tuple == NULL) { | 1516 | mutex_lock(&s->ops_mutex); |
1601 | dev_printk(KERN_WARNING, &s->dev, "no memory to validate CIS\n"); | 1517 | destroy_cis_cache(s); |
1602 | return -ENOMEM; | 1518 | mutex_unlock(&s->ops_mutex); |
1603 | } | ||
1604 | p = kmalloc(sizeof(*p), GFP_KERNEL); | ||
1605 | if (p == NULL) { | ||
1606 | kfree(tuple); | ||
1607 | dev_printk(KERN_WARNING, &s->dev, "no memory to validate CIS\n"); | ||
1608 | return -ENOMEM; | ||
1609 | } | ||
1610 | 1519 | ||
1611 | count = reserved = 0; | 1520 | tuple = kmalloc(sizeof(*tuple), GFP_KERNEL); |
1612 | tuple->DesiredTuple = RETURN_FIRST_TUPLE; | 1521 | if (tuple == NULL) { |
1613 | tuple->Attributes = TUPLE_RETURN_COMMON; | 1522 | dev_warn(&s->dev, "no memory to validate CIS\n"); |
1614 | ret = pccard_get_first_tuple(s, BIND_FN_ALL, tuple); | 1523 | return -ENOMEM; |
1615 | if (ret != 0) | 1524 | } |
1616 | goto done; | 1525 | p = kmalloc(sizeof(*p), GFP_KERNEL); |
1617 | 1526 | if (p == NULL) { | |
1618 | /* First tuple should be DEVICE; we should really have either that | 1527 | kfree(tuple); |
1619 | or a CFTABLE_ENTRY of some sort */ | 1528 | dev_warn(&s->dev, "no memory to validate CIS\n"); |
1620 | if ((tuple->TupleCode == CISTPL_DEVICE) || | 1529 | return -ENOMEM; |
1621 | (pccard_read_tuple(s, BIND_FN_ALL, CISTPL_CFTABLE_ENTRY, p) == 0) || | 1530 | } |
1622 | (pccard_read_tuple(s, BIND_FN_ALL, CISTPL_CFTABLE_ENTRY_CB, p) == 0)) | 1531 | |
1623 | dev_ok++; | 1532 | count = reserved = 0; |
1624 | 1533 | tuple->DesiredTuple = RETURN_FIRST_TUPLE; | |
1625 | /* All cards should have a MANFID tuple, and/or a VERS_1 or VERS_2 | 1534 | tuple->Attributes = TUPLE_RETURN_COMMON; |
1626 | tuple, for card identification. Certain old D-Link and Linksys | 1535 | ret = pccard_get_first_tuple(s, BIND_FN_ALL, tuple); |
1627 | cards have only a broken VERS_2 tuple; hence the bogus test. */ | ||
1628 | if ((pccard_read_tuple(s, BIND_FN_ALL, CISTPL_MANFID, p) == 0) || | ||
1629 | (pccard_read_tuple(s, BIND_FN_ALL, CISTPL_VERS_1, p) == 0) || | ||
1630 | (pccard_read_tuple(s, BIND_FN_ALL, CISTPL_VERS_2, p) != -ENOSPC)) | ||
1631 | ident_ok++; | ||
1632 | |||
1633 | if (!dev_ok && !ident_ok) | ||
1634 | goto done; | ||
1635 | |||
1636 | for (count = 1; count < MAX_TUPLES; count++) { | ||
1637 | ret = pccard_get_next_tuple(s, BIND_FN_ALL, tuple); | ||
1638 | if (ret != 0) | 1536 | if (ret != 0) |
1639 | break; | 1537 | goto done; |
1640 | if (((tuple->TupleCode > 0x23) && (tuple->TupleCode < 0x40)) || | 1538 | |
1641 | ((tuple->TupleCode > 0x47) && (tuple->TupleCode < 0x80)) || | 1539 | /* First tuple should be DEVICE; we should really have either that |
1642 | ((tuple->TupleCode > 0x90) && (tuple->TupleCode < 0xff))) | 1540 | or a CFTABLE_ENTRY of some sort */ |
1643 | reserved++; | 1541 | if ((tuple->TupleCode == CISTPL_DEVICE) || |
1644 | } | 1542 | (!pccard_read_tuple(s, BIND_FN_ALL, CISTPL_CFTABLE_ENTRY, p)) || |
1645 | if ((count == MAX_TUPLES) || (reserved > 5) || | 1543 | (!pccard_read_tuple(s, BIND_FN_ALL, CISTPL_CFTABLE_ENTRY_CB, p))) |
1646 | ((!dev_ok || !ident_ok) && (count > 10))) | 1544 | dev_ok++; |
1647 | count = 0; | 1545 | |
1546 | /* All cards should have a MANFID tuple, and/or a VERS_1 or VERS_2 | ||
1547 | tuple, for card identification. Certain old D-Link and Linksys | ||
1548 | cards have only a broken VERS_2 tuple; hence the bogus test. */ | ||
1549 | if ((pccard_read_tuple(s, BIND_FN_ALL, CISTPL_MANFID, p) == 0) || | ||
1550 | (pccard_read_tuple(s, BIND_FN_ALL, CISTPL_VERS_1, p) == 0) || | ||
1551 | (pccard_read_tuple(s, BIND_FN_ALL, CISTPL_VERS_2, p) != -ENOSPC)) | ||
1552 | ident_ok++; | ||
1553 | |||
1554 | if (!dev_ok && !ident_ok) | ||
1555 | goto done; | ||
1556 | |||
1557 | for (count = 1; count < MAX_TUPLES; count++) { | ||
1558 | ret = pccard_get_next_tuple(s, BIND_FN_ALL, tuple); | ||
1559 | if (ret != 0) | ||
1560 | break; | ||
1561 | if (((tuple->TupleCode > 0x23) && (tuple->TupleCode < 0x40)) || | ||
1562 | ((tuple->TupleCode > 0x47) && (tuple->TupleCode < 0x80)) || | ||
1563 | ((tuple->TupleCode > 0x90) && (tuple->TupleCode < 0xff))) | ||
1564 | reserved++; | ||
1565 | } | ||
1566 | if ((count == MAX_TUPLES) || (reserved > 5) || | ||
1567 | ((!dev_ok || !ident_ok) && (count > 10))) | ||
1568 | count = 0; | ||
1569 | |||
1570 | ret = 0; | ||
1648 | 1571 | ||
1649 | done: | 1572 | done: |
1650 | if (info) | 1573 | /* invalidate CIS cache on failure */ |
1651 | *info = count; | 1574 | if (!dev_ok || !ident_ok || !count) { |
1652 | kfree(tuple); | 1575 | mutex_lock(&s->ops_mutex); |
1653 | kfree(p); | 1576 | destroy_cis_cache(s); |
1654 | return 0; | 1577 | mutex_unlock(&s->ops_mutex); |
1578 | ret = -EIO; | ||
1579 | } | ||
1580 | |||
1581 | if (info) | ||
1582 | *info = count; | ||
1583 | kfree(tuple); | ||
1584 | kfree(p); | ||
1585 | return ret; | ||
1655 | } | 1586 | } |
1656 | EXPORT_SYMBOL(pccard_validate_cis); | 1587 | |
1588 | |||
1589 | #define to_socket(_dev) container_of(_dev, struct pcmcia_socket, dev) | ||
1590 | |||
1591 | static ssize_t pccard_extract_cis(struct pcmcia_socket *s, char *buf, | ||
1592 | loff_t off, size_t count) | ||
1593 | { | ||
1594 | tuple_t tuple; | ||
1595 | int status, i; | ||
1596 | loff_t pointer = 0; | ||
1597 | ssize_t ret = 0; | ||
1598 | u_char *tuplebuffer; | ||
1599 | u_char *tempbuffer; | ||
1600 | |||
1601 | tuplebuffer = kmalloc(sizeof(u_char) * 256, GFP_KERNEL); | ||
1602 | if (!tuplebuffer) | ||
1603 | return -ENOMEM; | ||
1604 | |||
1605 | tempbuffer = kmalloc(sizeof(u_char) * 258, GFP_KERNEL); | ||
1606 | if (!tempbuffer) { | ||
1607 | ret = -ENOMEM; | ||
1608 | goto free_tuple; | ||
1609 | } | ||
1610 | |||
1611 | memset(&tuple, 0, sizeof(tuple_t)); | ||
1612 | |||
1613 | tuple.Attributes = TUPLE_RETURN_LINK | TUPLE_RETURN_COMMON; | ||
1614 | tuple.DesiredTuple = RETURN_FIRST_TUPLE; | ||
1615 | tuple.TupleOffset = 0; | ||
1616 | |||
1617 | status = pccard_get_first_tuple(s, BIND_FN_ALL, &tuple); | ||
1618 | while (!status) { | ||
1619 | tuple.TupleData = tuplebuffer; | ||
1620 | tuple.TupleDataMax = 255; | ||
1621 | memset(tuplebuffer, 0, sizeof(u_char) * 255); | ||
1622 | |||
1623 | status = pccard_get_tuple_data(s, &tuple); | ||
1624 | if (status) | ||
1625 | break; | ||
1626 | |||
1627 | if (off < (pointer + 2 + tuple.TupleDataLen)) { | ||
1628 | tempbuffer[0] = tuple.TupleCode & 0xff; | ||
1629 | tempbuffer[1] = tuple.TupleLink & 0xff; | ||
1630 | for (i = 0; i < tuple.TupleDataLen; i++) | ||
1631 | tempbuffer[i + 2] = tuplebuffer[i] & 0xff; | ||
1632 | |||
1633 | for (i = 0; i < (2 + tuple.TupleDataLen); i++) { | ||
1634 | if (((i + pointer) >= off) && | ||
1635 | (i + pointer) < (off + count)) { | ||
1636 | buf[ret] = tempbuffer[i]; | ||
1637 | ret++; | ||
1638 | } | ||
1639 | } | ||
1640 | } | ||
1641 | |||
1642 | pointer += 2 + tuple.TupleDataLen; | ||
1643 | |||
1644 | if (pointer >= (off + count)) | ||
1645 | break; | ||
1646 | |||
1647 | if (tuple.TupleCode == CISTPL_END) | ||
1648 | break; | ||
1649 | status = pccard_get_next_tuple(s, BIND_FN_ALL, &tuple); | ||
1650 | } | ||
1651 | |||
1652 | kfree(tempbuffer); | ||
1653 | free_tuple: | ||
1654 | kfree(tuplebuffer); | ||
1655 | |||
1656 | return ret; | ||
1657 | } | ||
1658 | |||
1659 | |||
1660 | static ssize_t pccard_show_cis(struct kobject *kobj, | ||
1661 | struct bin_attribute *bin_attr, | ||
1662 | char *buf, loff_t off, size_t count) | ||
1663 | { | ||
1664 | unsigned int size = 0x200; | ||
1665 | |||
1666 | if (off >= size) | ||
1667 | count = 0; | ||
1668 | else { | ||
1669 | struct pcmcia_socket *s; | ||
1670 | unsigned int chains; | ||
1671 | |||
1672 | if (off + count > size) | ||
1673 | count = size - off; | ||
1674 | |||
1675 | s = to_socket(container_of(kobj, struct device, kobj)); | ||
1676 | |||
1677 | if (!(s->state & SOCKET_PRESENT)) | ||
1678 | return -ENODEV; | ||
1679 | if (pccard_validate_cis(s, &chains)) | ||
1680 | return -EIO; | ||
1681 | if (!chains) | ||
1682 | return -ENODATA; | ||
1683 | |||
1684 | count = pccard_extract_cis(s, buf, off, count); | ||
1685 | } | ||
1686 | |||
1687 | return count; | ||
1688 | } | ||
1689 | |||
1690 | |||
1691 | static ssize_t pccard_store_cis(struct kobject *kobj, | ||
1692 | struct bin_attribute *bin_attr, | ||
1693 | char *buf, loff_t off, size_t count) | ||
1694 | { | ||
1695 | struct pcmcia_socket *s; | ||
1696 | int error; | ||
1697 | |||
1698 | s = to_socket(container_of(kobj, struct device, kobj)); | ||
1699 | |||
1700 | if (off) | ||
1701 | return -EINVAL; | ||
1702 | |||
1703 | if (count >= CISTPL_MAX_CIS_SIZE) | ||
1704 | return -EINVAL; | ||
1705 | |||
1706 | if (!(s->state & SOCKET_PRESENT)) | ||
1707 | return -ENODEV; | ||
1708 | |||
1709 | error = pcmcia_replace_cis(s, buf, count); | ||
1710 | if (error) | ||
1711 | return -EIO; | ||
1712 | |||
1713 | pcmcia_parse_uevents(s, PCMCIA_UEVENT_REQUERY); | ||
1714 | |||
1715 | return count; | ||
1716 | } | ||
1717 | |||
1718 | |||
1719 | struct bin_attribute pccard_cis_attr = { | ||
1720 | .attr = { .name = "cis", .mode = S_IRUGO | S_IWUSR }, | ||
1721 | .size = 0x200, | ||
1722 | .read = pccard_show_cis, | ||
1723 | .write = pccard_store_cis, | ||
1724 | }; | ||
diff --git a/drivers/pcmcia/cs.c b/drivers/pcmcia/cs.c index 6d6f82b38a68..e679e708db63 100644 --- a/drivers/pcmcia/cs.c +++ b/drivers/pcmcia/cs.c | |||
@@ -140,19 +140,13 @@ struct pcmcia_socket *pcmcia_get_socket(struct pcmcia_socket *skt) | |||
140 | struct device *dev = get_device(&skt->dev); | 140 | struct device *dev = get_device(&skt->dev); |
141 | if (!dev) | 141 | if (!dev) |
142 | return NULL; | 142 | return NULL; |
143 | skt = dev_get_drvdata(dev); | 143 | return dev_get_drvdata(dev); |
144 | if (!try_module_get(skt->owner)) { | ||
145 | put_device(&skt->dev); | ||
146 | return NULL; | ||
147 | } | ||
148 | return skt; | ||
149 | } | 144 | } |
150 | EXPORT_SYMBOL(pcmcia_get_socket); | 145 | EXPORT_SYMBOL(pcmcia_get_socket); |
151 | 146 | ||
152 | 147 | ||
153 | void pcmcia_put_socket(struct pcmcia_socket *skt) | 148 | void pcmcia_put_socket(struct pcmcia_socket *skt) |
154 | { | 149 | { |
155 | module_put(skt->owner); | ||
156 | put_device(&skt->dev); | 150 | put_device(&skt->dev); |
157 | } | 151 | } |
158 | EXPORT_SYMBOL(pcmcia_put_socket); | 152 | EXPORT_SYMBOL(pcmcia_put_socket); |
@@ -181,8 +175,6 @@ int pcmcia_register_socket(struct pcmcia_socket *socket) | |||
181 | 175 | ||
182 | dev_dbg(&socket->dev, "pcmcia_register_socket(0x%p)\n", socket->ops); | 176 | dev_dbg(&socket->dev, "pcmcia_register_socket(0x%p)\n", socket->ops); |
183 | 177 | ||
184 | spin_lock_init(&socket->lock); | ||
185 | |||
186 | /* try to obtain a socket number [yes, it gets ugly if we | 178 | /* try to obtain a socket number [yes, it gets ugly if we |
187 | * register more than 2^sizeof(unsigned int) pcmcia | 179 | * register more than 2^sizeof(unsigned int) pcmcia |
188 | * sockets... but the socket number is deprecated | 180 | * sockets... but the socket number is deprecated |
@@ -228,10 +220,13 @@ int pcmcia_register_socket(struct pcmcia_socket *socket) | |||
228 | init_completion(&socket->socket_released); | 220 | init_completion(&socket->socket_released); |
229 | init_completion(&socket->thread_done); | 221 | init_completion(&socket->thread_done); |
230 | mutex_init(&socket->skt_mutex); | 222 | mutex_init(&socket->skt_mutex); |
223 | mutex_init(&socket->ops_mutex); | ||
231 | spin_lock_init(&socket->thread_lock); | 224 | spin_lock_init(&socket->thread_lock); |
232 | 225 | ||
233 | if (socket->resource_ops->init) { | 226 | if (socket->resource_ops->init) { |
227 | mutex_lock(&socket->ops_mutex); | ||
234 | ret = socket->resource_ops->init(socket); | 228 | ret = socket->resource_ops->init(socket); |
229 | mutex_unlock(&socket->ops_mutex); | ||
235 | if (ret) | 230 | if (ret) |
236 | goto err; | 231 | goto err; |
237 | } | 232 | } |
@@ -283,15 +278,17 @@ void pcmcia_unregister_socket(struct pcmcia_socket *socket) | |||
283 | if (socket->thread) | 278 | if (socket->thread) |
284 | kthread_stop(socket->thread); | 279 | kthread_stop(socket->thread); |
285 | 280 | ||
286 | release_cis_mem(socket); | ||
287 | |||
288 | /* remove from our own list */ | 281 | /* remove from our own list */ |
289 | down_write(&pcmcia_socket_list_rwsem); | 282 | down_write(&pcmcia_socket_list_rwsem); |
290 | list_del(&socket->socket_list); | 283 | list_del(&socket->socket_list); |
291 | up_write(&pcmcia_socket_list_rwsem); | 284 | up_write(&pcmcia_socket_list_rwsem); |
292 | 285 | ||
293 | /* wait for sysfs to drop all references */ | 286 | /* wait for sysfs to drop all references */ |
294 | release_resource_db(socket); | 287 | if (socket->resource_ops->exit) { |
288 | mutex_lock(&socket->ops_mutex); | ||
289 | socket->resource_ops->exit(socket); | ||
290 | mutex_unlock(&socket->ops_mutex); | ||
291 | } | ||
295 | wait_for_completion(&socket->socket_released); | 292 | wait_for_completion(&socket->socket_released); |
296 | } /* pcmcia_unregister_socket */ | 293 | } /* pcmcia_unregister_socket */ |
297 | EXPORT_SYMBOL(pcmcia_unregister_socket); | 294 | EXPORT_SYMBOL(pcmcia_unregister_socket); |
@@ -328,7 +325,7 @@ static int send_event(struct pcmcia_socket *s, event_t event, int priority) | |||
328 | { | 325 | { |
329 | int ret; | 326 | int ret; |
330 | 327 | ||
331 | if (s->state & SOCKET_CARDBUS) | 328 | if ((s->state & SOCKET_CARDBUS) && (event != CS_EVENT_CARD_REMOVAL)) |
332 | return 0; | 329 | return 0; |
333 | 330 | ||
334 | dev_dbg(&s->dev, "send_event(event %d, pri %d, callback 0x%p)\n", | 331 | dev_dbg(&s->dev, "send_event(event %d, pri %d, callback 0x%p)\n", |
@@ -346,13 +343,6 @@ static int send_event(struct pcmcia_socket *s, event_t event, int priority) | |||
346 | return ret; | 343 | return ret; |
347 | } | 344 | } |
348 | 345 | ||
349 | static void socket_remove_drivers(struct pcmcia_socket *skt) | ||
350 | { | ||
351 | dev_dbg(&skt->dev, "remove_drivers\n"); | ||
352 | |||
353 | send_event(skt, CS_EVENT_CARD_REMOVAL, CS_EVENT_PRI_HIGH); | ||
354 | } | ||
355 | |||
356 | static int socket_reset(struct pcmcia_socket *skt) | 346 | static int socket_reset(struct pcmcia_socket *skt) |
357 | { | 347 | { |
358 | int status, i; | 348 | int status, i; |
@@ -395,7 +385,9 @@ static void socket_shutdown(struct pcmcia_socket *s) | |||
395 | 385 | ||
396 | dev_dbg(&s->dev, "shutdown\n"); | 386 | dev_dbg(&s->dev, "shutdown\n"); |
397 | 387 | ||
398 | socket_remove_drivers(s); | 388 | send_event(s, CS_EVENT_CARD_REMOVAL, CS_EVENT_PRI_HIGH); |
389 | |||
390 | mutex_lock(&s->ops_mutex); | ||
399 | s->state &= SOCKET_INUSE | SOCKET_PRESENT; | 391 | s->state &= SOCKET_INUSE | SOCKET_PRESENT; |
400 | msleep(shutdown_delay * 10); | 392 | msleep(shutdown_delay * 10); |
401 | s->state &= SOCKET_INUSE; | 393 | s->state &= SOCKET_INUSE; |
@@ -406,11 +398,21 @@ static void socket_shutdown(struct pcmcia_socket *s) | |||
406 | s->ops->set_socket(s, &s->socket); | 398 | s->ops->set_socket(s, &s->socket); |
407 | s->irq.AssignedIRQ = s->irq.Config = 0; | 399 | s->irq.AssignedIRQ = s->irq.Config = 0; |
408 | s->lock_count = 0; | 400 | s->lock_count = 0; |
409 | destroy_cis_cache(s); | 401 | kfree(s->fake_cis); |
402 | s->fake_cis = NULL; | ||
403 | s->functions = 0; | ||
404 | |||
405 | /* From here on we can be sure that only we (that is, the | ||
406 | * pccardd thread) accesses this socket, and all (16-bit) | ||
407 | * PCMCIA interactions are gone. Therefore, release | ||
408 | * ops_mutex so that we don't get a sysfs-related lockdep | ||
409 | * warning. | ||
410 | */ | ||
411 | mutex_unlock(&s->ops_mutex); | ||
412 | |||
410 | #ifdef CONFIG_CARDBUS | 413 | #ifdef CONFIG_CARDBUS |
411 | cb_free(s); | 414 | cb_free(s); |
412 | #endif | 415 | #endif |
413 | s->functions = 0; | ||
414 | 416 | ||
415 | /* give socket some time to power down */ | 417 | /* give socket some time to power down */ |
416 | msleep(100); | 418 | msleep(100); |
@@ -421,7 +423,7 @@ static void socket_shutdown(struct pcmcia_socket *s) | |||
421 | "*** DANGER *** unable to remove socket power\n"); | 423 | "*** DANGER *** unable to remove socket power\n"); |
422 | } | 424 | } |
423 | 425 | ||
424 | cs_socket_put(s); | 426 | s->state &= ~SOCKET_INUSE; |
425 | } | 427 | } |
426 | 428 | ||
427 | static int socket_setup(struct pcmcia_socket *skt, int initial_delay) | 429 | static int socket_setup(struct pcmcia_socket *skt, int initial_delay) |
@@ -460,7 +462,8 @@ static int socket_setup(struct pcmcia_socket *skt, int initial_delay) | |||
460 | return -EINVAL; | 462 | return -EINVAL; |
461 | } | 463 | } |
462 | skt->state |= SOCKET_CARDBUS; | 464 | skt->state |= SOCKET_CARDBUS; |
463 | } | 465 | } else |
466 | skt->state &= ~SOCKET_CARDBUS; | ||
464 | 467 | ||
465 | /* | 468 | /* |
466 | * Decode the card voltage requirements, and apply power to the card. | 469 | * Decode the card voltage requirements, and apply power to the card. |
@@ -509,8 +512,12 @@ static int socket_insert(struct pcmcia_socket *skt) | |||
509 | 512 | ||
510 | dev_dbg(&skt->dev, "insert\n"); | 513 | dev_dbg(&skt->dev, "insert\n"); |
511 | 514 | ||
512 | if (!cs_socket_get(skt)) | 515 | mutex_lock(&skt->ops_mutex); |
513 | return -ENODEV; | 516 | if (skt->state & SOCKET_INUSE) { |
517 | mutex_unlock(&skt->ops_mutex); | ||
518 | return -EINVAL; | ||
519 | } | ||
520 | skt->state |= SOCKET_INUSE; | ||
514 | 521 | ||
515 | ret = socket_setup(skt, setup_delay); | 522 | ret = socket_setup(skt, setup_delay); |
516 | if (ret == 0) { | 523 | if (ret == 0) { |
@@ -528,9 +535,11 @@ static int socket_insert(struct pcmcia_socket *skt) | |||
528 | } | 535 | } |
529 | #endif | 536 | #endif |
530 | dev_dbg(&skt->dev, "insert done\n"); | 537 | dev_dbg(&skt->dev, "insert done\n"); |
538 | mutex_unlock(&skt->ops_mutex); | ||
531 | 539 | ||
532 | send_event(skt, CS_EVENT_CARD_INSERTION, CS_EVENT_PRI_LOW); | 540 | send_event(skt, CS_EVENT_CARD_INSERTION, CS_EVENT_PRI_LOW); |
533 | } else { | 541 | } else { |
542 | mutex_unlock(&skt->ops_mutex); | ||
534 | socket_shutdown(skt); | 543 | socket_shutdown(skt); |
535 | } | 544 | } |
536 | 545 | ||
@@ -542,58 +551,66 @@ static int socket_suspend(struct pcmcia_socket *skt) | |||
542 | if (skt->state & SOCKET_SUSPEND) | 551 | if (skt->state & SOCKET_SUSPEND) |
543 | return -EBUSY; | 552 | return -EBUSY; |
544 | 553 | ||
554 | mutex_lock(&skt->ops_mutex); | ||
555 | skt->suspended_state = skt->state; | ||
556 | |||
545 | send_event(skt, CS_EVENT_PM_SUSPEND, CS_EVENT_PRI_LOW); | 557 | send_event(skt, CS_EVENT_PM_SUSPEND, CS_EVENT_PRI_LOW); |
546 | skt->socket = dead_socket; | 558 | skt->socket = dead_socket; |
547 | skt->ops->set_socket(skt, &skt->socket); | 559 | skt->ops->set_socket(skt, &skt->socket); |
548 | if (skt->ops->suspend) | 560 | if (skt->ops->suspend) |
549 | skt->ops->suspend(skt); | 561 | skt->ops->suspend(skt); |
550 | skt->state |= SOCKET_SUSPEND; | 562 | skt->state |= SOCKET_SUSPEND; |
551 | 563 | mutex_unlock(&skt->ops_mutex); | |
552 | return 0; | 564 | return 0; |
553 | } | 565 | } |
554 | 566 | ||
555 | static int socket_early_resume(struct pcmcia_socket *skt) | 567 | static int socket_early_resume(struct pcmcia_socket *skt) |
556 | { | 568 | { |
569 | mutex_lock(&skt->ops_mutex); | ||
557 | skt->socket = dead_socket; | 570 | skt->socket = dead_socket; |
558 | skt->ops->init(skt); | 571 | skt->ops->init(skt); |
559 | skt->ops->set_socket(skt, &skt->socket); | 572 | skt->ops->set_socket(skt, &skt->socket); |
560 | if (skt->state & SOCKET_PRESENT) | 573 | if (skt->state & SOCKET_PRESENT) |
561 | skt->resume_status = socket_setup(skt, resume_delay); | 574 | skt->resume_status = socket_setup(skt, resume_delay); |
575 | mutex_unlock(&skt->ops_mutex); | ||
562 | return 0; | 576 | return 0; |
563 | } | 577 | } |
564 | 578 | ||
565 | static int socket_late_resume(struct pcmcia_socket *skt) | 579 | static int socket_late_resume(struct pcmcia_socket *skt) |
566 | { | 580 | { |
567 | if (!(skt->state & SOCKET_PRESENT)) { | 581 | mutex_lock(&skt->ops_mutex); |
568 | skt->state &= ~SOCKET_SUSPEND; | 582 | skt->state &= ~SOCKET_SUSPEND; |
583 | mutex_unlock(&skt->ops_mutex); | ||
584 | |||
585 | if (!(skt->state & SOCKET_PRESENT)) | ||
569 | return socket_insert(skt); | 586 | return socket_insert(skt); |
587 | |||
588 | if (skt->resume_status) { | ||
589 | socket_shutdown(skt); | ||
590 | return 0; | ||
570 | } | 591 | } |
571 | 592 | ||
572 | if (skt->resume_status == 0) { | 593 | if (skt->suspended_state != skt->state) { |
573 | /* | 594 | dev_dbg(&skt->dev, |
574 | * FIXME: need a better check here for cardbus cards. | 595 | "suspend state 0x%x != resume state 0x%x\n", |
575 | */ | 596 | skt->suspended_state, skt->state); |
576 | if (verify_cis_cache(skt) != 0) { | 597 | |
577 | dev_dbg(&skt->dev, "cis mismatch - different card\n"); | ||
578 | socket_remove_drivers(skt); | ||
579 | destroy_cis_cache(skt); | ||
580 | /* | ||
581 | * Workaround: give DS time to schedule removal. | ||
582 | * Remove me once the 100ms delay is eliminated | ||
583 | * in ds.c | ||
584 | */ | ||
585 | msleep(200); | ||
586 | send_event(skt, CS_EVENT_CARD_INSERTION, CS_EVENT_PRI_LOW); | ||
587 | } else { | ||
588 | dev_dbg(&skt->dev, "cis matches cache\n"); | ||
589 | send_event(skt, CS_EVENT_PM_RESUME, CS_EVENT_PRI_LOW); | ||
590 | } | ||
591 | } else { | ||
592 | socket_shutdown(skt); | 598 | socket_shutdown(skt); |
599 | return socket_insert(skt); | ||
593 | } | 600 | } |
594 | 601 | ||
595 | skt->state &= ~SOCKET_SUSPEND; | 602 | #ifdef CONFIG_CARDBUS |
603 | if (skt->state & SOCKET_CARDBUS) { | ||
604 | /* We can't be sure the CardBus card is the same | ||
605 | * as the one previously inserted. Therefore, remove | ||
606 | * and re-add... */ | ||
607 | cb_free(skt); | ||
608 | cb_alloc(skt); | ||
609 | return 0; | ||
610 | } | ||
611 | #endif | ||
596 | 612 | ||
613 | send_event(skt, CS_EVENT_PM_RESUME, CS_EVENT_PRI_LOW); | ||
597 | return 0; | 614 | return 0; |
598 | } | 615 | } |
599 | 616 | ||
@@ -672,20 +689,26 @@ static int pccardd(void *__skt) | |||
672 | 689 | ||
673 | complete(&skt->thread_done); | 690 | complete(&skt->thread_done); |
674 | 691 | ||
692 | /* wait for userspace to catch up */ | ||
693 | msleep(250); | ||
694 | |||
675 | set_freezable(); | 695 | set_freezable(); |
676 | for (;;) { | 696 | for (;;) { |
677 | unsigned long flags; | 697 | unsigned long flags; |
678 | unsigned int events; | 698 | unsigned int events; |
699 | unsigned int sysfs_events; | ||
679 | 700 | ||
680 | set_current_state(TASK_INTERRUPTIBLE); | 701 | set_current_state(TASK_INTERRUPTIBLE); |
681 | 702 | ||
682 | spin_lock_irqsave(&skt->thread_lock, flags); | 703 | spin_lock_irqsave(&skt->thread_lock, flags); |
683 | events = skt->thread_events; | 704 | events = skt->thread_events; |
684 | skt->thread_events = 0; | 705 | skt->thread_events = 0; |
706 | sysfs_events = skt->sysfs_events; | ||
707 | skt->sysfs_events = 0; | ||
685 | spin_unlock_irqrestore(&skt->thread_lock, flags); | 708 | spin_unlock_irqrestore(&skt->thread_lock, flags); |
686 | 709 | ||
710 | mutex_lock(&skt->skt_mutex); | ||
687 | if (events) { | 711 | if (events) { |
688 | mutex_lock(&skt->skt_mutex); | ||
689 | if (events & SS_DETECT) | 712 | if (events & SS_DETECT) |
690 | socket_detect_change(skt); | 713 | socket_detect_change(skt); |
691 | if (events & SS_BATDEAD) | 714 | if (events & SS_BATDEAD) |
@@ -694,10 +717,39 @@ static int pccardd(void *__skt) | |||
694 | send_event(skt, CS_EVENT_BATTERY_LOW, CS_EVENT_PRI_LOW); | 717 | send_event(skt, CS_EVENT_BATTERY_LOW, CS_EVENT_PRI_LOW); |
695 | if (events & SS_READY) | 718 | if (events & SS_READY) |
696 | send_event(skt, CS_EVENT_READY_CHANGE, CS_EVENT_PRI_LOW); | 719 | send_event(skt, CS_EVENT_READY_CHANGE, CS_EVENT_PRI_LOW); |
697 | mutex_unlock(&skt->skt_mutex); | ||
698 | continue; | ||
699 | } | 720 | } |
700 | 721 | ||
722 | if (sysfs_events) { | ||
723 | if (sysfs_events & PCMCIA_UEVENT_EJECT) | ||
724 | socket_remove(skt); | ||
725 | if (sysfs_events & PCMCIA_UEVENT_INSERT) | ||
726 | socket_insert(skt); | ||
727 | if ((sysfs_events & PCMCIA_UEVENT_RESUME) && | ||
728 | !(skt->state & SOCKET_CARDBUS)) { | ||
729 | ret = socket_resume(skt); | ||
730 | if (!ret && skt->callback) | ||
731 | skt->callback->resume(skt); | ||
732 | } | ||
733 | if ((sysfs_events & PCMCIA_UEVENT_SUSPEND) && | ||
734 | !(skt->state & SOCKET_CARDBUS)) { | ||
735 | if (skt->callback) | ||
736 | ret = skt->callback->suspend(skt); | ||
737 | else | ||
738 | ret = 0; | ||
739 | if (!ret) | ||
740 | socket_suspend(skt); | ||
741 | } | ||
742 | if ((sysfs_events & PCMCIA_UEVENT_REQUERY) && | ||
743 | !(skt->state & SOCKET_CARDBUS)) { | ||
744 | if (!ret && skt->callback) | ||
745 | skt->callback->requery(skt); | ||
746 | } | ||
747 | } | ||
748 | mutex_unlock(&skt->skt_mutex); | ||
749 | |||
750 | if (events || sysfs_events) | ||
751 | continue; | ||
752 | |||
701 | if (kthread_should_stop()) | 753 | if (kthread_should_stop()) |
702 | break; | 754 | break; |
703 | 755 | ||
@@ -707,6 +759,13 @@ static int pccardd(void *__skt) | |||
707 | /* make sure we are running before we exit */ | 759 | /* make sure we are running before we exit */ |
708 | set_current_state(TASK_RUNNING); | 760 | set_current_state(TASK_RUNNING); |
709 | 761 | ||
762 | /* shut down socket, if a device is still present */ | ||
763 | if (skt->state & SOCKET_PRESENT) { | ||
764 | mutex_lock(&skt->skt_mutex); | ||
765 | socket_remove(skt); | ||
766 | mutex_unlock(&skt->skt_mutex); | ||
767 | } | ||
768 | |||
710 | /* remove from the device core */ | 769 | /* remove from the device core */ |
711 | pccard_sysfs_remove_socket(&skt->dev); | 770 | pccard_sysfs_remove_socket(&skt->dev); |
712 | device_unregister(&skt->dev); | 771 | device_unregister(&skt->dev); |
@@ -732,6 +791,31 @@ void pcmcia_parse_events(struct pcmcia_socket *s, u_int events) | |||
732 | } /* pcmcia_parse_events */ | 791 | } /* pcmcia_parse_events */ |
733 | EXPORT_SYMBOL(pcmcia_parse_events); | 792 | EXPORT_SYMBOL(pcmcia_parse_events); |
734 | 793 | ||
794 | /** | ||
795 | * pcmcia_parse_uevents() - tell pccardd to issue manual commands | ||
796 | * @s: the PCMCIA socket we wan't to command | ||
797 | * @events: events to pass to pccardd | ||
798 | * | ||
799 | * userspace-issued insert, eject, suspend and resume commands must be | ||
800 | * handled by pccardd to avoid any sysfs-related deadlocks. Valid events | ||
801 | * are PCMCIA_UEVENT_EJECT (for eject), PCMCIA_UEVENT__INSERT (for insert), | ||
802 | * PCMCIA_UEVENT_RESUME (for resume), PCMCIA_UEVENT_SUSPEND (for suspend) | ||
803 | * and PCMCIA_UEVENT_REQUERY (for re-querying the PCMCIA card). | ||
804 | */ | ||
805 | void pcmcia_parse_uevents(struct pcmcia_socket *s, u_int events) | ||
806 | { | ||
807 | unsigned long flags; | ||
808 | dev_dbg(&s->dev, "parse_uevents: events %08x\n", events); | ||
809 | if (s->thread) { | ||
810 | spin_lock_irqsave(&s->thread_lock, flags); | ||
811 | s->sysfs_events |= events; | ||
812 | spin_unlock_irqrestore(&s->thread_lock, flags); | ||
813 | |||
814 | wake_up_process(s->thread); | ||
815 | } | ||
816 | } | ||
817 | EXPORT_SYMBOL(pcmcia_parse_uevents); | ||
818 | |||
735 | 819 | ||
736 | /* register pcmcia_callback */ | 820 | /* register pcmcia_callback */ |
737 | int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c) | 821 | int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c) |
@@ -796,7 +880,10 @@ int pcmcia_reset_card(struct pcmcia_socket *skt) | |||
796 | send_event(skt, CS_EVENT_RESET_PHYSICAL, CS_EVENT_PRI_LOW); | 880 | send_event(skt, CS_EVENT_RESET_PHYSICAL, CS_EVENT_PRI_LOW); |
797 | if (skt->callback) | 881 | if (skt->callback) |
798 | skt->callback->suspend(skt); | 882 | skt->callback->suspend(skt); |
799 | if (socket_reset(skt) == 0) { | 883 | mutex_lock(&skt->ops_mutex); |
884 | ret = socket_reset(skt); | ||
885 | mutex_unlock(&skt->ops_mutex); | ||
886 | if (ret == 0) { | ||
800 | send_event(skt, CS_EVENT_CARD_RESET, CS_EVENT_PRI_LOW); | 887 | send_event(skt, CS_EVENT_CARD_RESET, CS_EVENT_PRI_LOW); |
801 | if (skt->callback) | 888 | if (skt->callback) |
802 | skt->callback->resume(skt); | 889 | skt->callback->resume(skt); |
@@ -812,121 +899,6 @@ int pcmcia_reset_card(struct pcmcia_socket *skt) | |||
812 | EXPORT_SYMBOL(pcmcia_reset_card); | 899 | EXPORT_SYMBOL(pcmcia_reset_card); |
813 | 900 | ||
814 | 901 | ||
815 | /* These shut down or wake up a socket. They are sort of user | ||
816 | * initiated versions of the APM suspend and resume actions. | ||
817 | */ | ||
818 | int pcmcia_suspend_card(struct pcmcia_socket *skt) | ||
819 | { | ||
820 | int ret; | ||
821 | |||
822 | dev_dbg(&skt->dev, "suspending socket\n"); | ||
823 | |||
824 | mutex_lock(&skt->skt_mutex); | ||
825 | do { | ||
826 | if (!(skt->state & SOCKET_PRESENT)) { | ||
827 | ret = -ENODEV; | ||
828 | break; | ||
829 | } | ||
830 | if (skt->state & SOCKET_CARDBUS) { | ||
831 | ret = -EPERM; | ||
832 | break; | ||
833 | } | ||
834 | if (skt->callback) { | ||
835 | ret = skt->callback->suspend(skt); | ||
836 | if (ret) | ||
837 | break; | ||
838 | } | ||
839 | ret = socket_suspend(skt); | ||
840 | } while (0); | ||
841 | mutex_unlock(&skt->skt_mutex); | ||
842 | |||
843 | return ret; | ||
844 | } /* suspend_card */ | ||
845 | EXPORT_SYMBOL(pcmcia_suspend_card); | ||
846 | |||
847 | |||
848 | int pcmcia_resume_card(struct pcmcia_socket *skt) | ||
849 | { | ||
850 | int ret; | ||
851 | |||
852 | dev_dbg(&skt->dev, "waking up socket\n"); | ||
853 | |||
854 | mutex_lock(&skt->skt_mutex); | ||
855 | do { | ||
856 | if (!(skt->state & SOCKET_PRESENT)) { | ||
857 | ret = -ENODEV; | ||
858 | break; | ||
859 | } | ||
860 | if (skt->state & SOCKET_CARDBUS) { | ||
861 | ret = -EPERM; | ||
862 | break; | ||
863 | } | ||
864 | ret = socket_resume(skt); | ||
865 | if (!ret && skt->callback) | ||
866 | skt->callback->resume(skt); | ||
867 | } while (0); | ||
868 | mutex_unlock(&skt->skt_mutex); | ||
869 | |||
870 | return ret; | ||
871 | } /* resume_card */ | ||
872 | EXPORT_SYMBOL(pcmcia_resume_card); | ||
873 | |||
874 | |||
875 | /* These handle user requests to eject or insert a card. */ | ||
876 | int pcmcia_eject_card(struct pcmcia_socket *skt) | ||
877 | { | ||
878 | int ret; | ||
879 | |||
880 | dev_dbg(&skt->dev, "user eject request\n"); | ||
881 | |||
882 | mutex_lock(&skt->skt_mutex); | ||
883 | do { | ||
884 | if (!(skt->state & SOCKET_PRESENT)) { | ||
885 | ret = -ENODEV; | ||
886 | break; | ||
887 | } | ||
888 | |||
889 | ret = send_event(skt, CS_EVENT_EJECTION_REQUEST, CS_EVENT_PRI_LOW); | ||
890 | if (ret != 0) { | ||
891 | ret = -EINVAL; | ||
892 | break; | ||
893 | } | ||
894 | |||
895 | socket_remove(skt); | ||
896 | ret = 0; | ||
897 | } while (0); | ||
898 | mutex_unlock(&skt->skt_mutex); | ||
899 | |||
900 | return ret; | ||
901 | } /* eject_card */ | ||
902 | EXPORT_SYMBOL(pcmcia_eject_card); | ||
903 | |||
904 | |||
905 | int pcmcia_insert_card(struct pcmcia_socket *skt) | ||
906 | { | ||
907 | int ret; | ||
908 | |||
909 | dev_dbg(&skt->dev, "user insert request\n"); | ||
910 | |||
911 | mutex_lock(&skt->skt_mutex); | ||
912 | do { | ||
913 | if (skt->state & SOCKET_PRESENT) { | ||
914 | ret = -EBUSY; | ||
915 | break; | ||
916 | } | ||
917 | if (socket_insert(skt) == -ENODEV) { | ||
918 | ret = -ENODEV; | ||
919 | break; | ||
920 | } | ||
921 | ret = 0; | ||
922 | } while (0); | ||
923 | mutex_unlock(&skt->skt_mutex); | ||
924 | |||
925 | return ret; | ||
926 | } /* insert_card */ | ||
927 | EXPORT_SYMBOL(pcmcia_insert_card); | ||
928 | |||
929 | |||
930 | static int pcmcia_socket_uevent(struct device *dev, | 902 | static int pcmcia_socket_uevent(struct device *dev, |
931 | struct kobj_uevent_env *env) | 903 | struct kobj_uevent_env *env) |
932 | { | 904 | { |
diff --git a/drivers/pcmcia/cs_internal.h b/drivers/pcmcia/cs_internal.h index 3bc02d53a3a3..f95864c2191e 100644 --- a/drivers/pcmcia/cs_internal.h +++ b/drivers/pcmcia/cs_internal.h | |||
@@ -87,37 +87,11 @@ struct pccard_resource_ops { | |||
87 | #define SOCKET_CARDBUS 0x8000 | 87 | #define SOCKET_CARDBUS 0x8000 |
88 | #define SOCKET_CARDBUS_CONFIG 0x10000 | 88 | #define SOCKET_CARDBUS_CONFIG 0x10000 |
89 | 89 | ||
90 | static inline int cs_socket_get(struct pcmcia_socket *skt) | ||
91 | { | ||
92 | int ret; | ||
93 | |||
94 | WARN_ON(skt->state & SOCKET_INUSE); | ||
95 | |||
96 | ret = try_module_get(skt->owner); | ||
97 | if (ret) | ||
98 | skt->state |= SOCKET_INUSE; | ||
99 | return ret; | ||
100 | } | ||
101 | |||
102 | static inline void cs_socket_put(struct pcmcia_socket *skt) | ||
103 | { | ||
104 | if (skt->state & SOCKET_INUSE) { | ||
105 | skt->state &= ~SOCKET_INUSE; | ||
106 | module_put(skt->owner); | ||
107 | } | ||
108 | } | ||
109 | |||
110 | 90 | ||
111 | /* | 91 | /* |
112 | * Stuff internal to module "pcmcia_core": | 92 | * Stuff internal to module "pcmcia_core": |
113 | */ | 93 | */ |
114 | 94 | ||
115 | /* cistpl.c */ | ||
116 | int verify_cis_cache(struct pcmcia_socket *s); | ||
117 | |||
118 | /* rsrc_mgr.c */ | ||
119 | void release_resource_db(struct pcmcia_socket *s); | ||
120 | |||
121 | /* socket_sysfs.c */ | 95 | /* socket_sysfs.c */ |
122 | extern int pccard_sysfs_add_socket(struct device *dev); | 96 | extern int pccard_sysfs_add_socket(struct device *dev); |
123 | extern void pccard_sysfs_remove_socket(struct device *dev); | 97 | extern void pccard_sysfs_remove_socket(struct device *dev); |
@@ -125,8 +99,6 @@ extern void pccard_sysfs_remove_socket(struct device *dev); | |||
125 | /* cardbus.c */ | 99 | /* cardbus.c */ |
126 | int cb_alloc(struct pcmcia_socket *s); | 100 | int cb_alloc(struct pcmcia_socket *s); |
127 | void cb_free(struct pcmcia_socket *s); | 101 | void cb_free(struct pcmcia_socket *s); |
128 | int read_cb_mem(struct pcmcia_socket *s, int space, u_int addr, u_int len, | ||
129 | void *ptr); | ||
130 | 102 | ||
131 | 103 | ||
132 | 104 | ||
@@ -138,7 +110,8 @@ struct pcmcia_callback{ | |||
138 | struct module *owner; | 110 | struct module *owner; |
139 | int (*event) (struct pcmcia_socket *s, | 111 | int (*event) (struct pcmcia_socket *s, |
140 | event_t event, int priority); | 112 | event_t event, int priority); |
141 | void (*requery) (struct pcmcia_socket *s, int new_cis); | 113 | void (*requery) (struct pcmcia_socket *s); |
114 | int (*validate) (struct pcmcia_socket *s, unsigned int *i); | ||
142 | int (*suspend) (struct pcmcia_socket *s); | 115 | int (*suspend) (struct pcmcia_socket *s); |
143 | int (*resume) (struct pcmcia_socket *s); | 116 | int (*resume) (struct pcmcia_socket *s); |
144 | }; | 117 | }; |
@@ -151,16 +124,35 @@ extern struct class pcmcia_socket_class; | |||
151 | int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c); | 124 | int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c); |
152 | struct pcmcia_socket *pcmcia_get_socket_by_nr(unsigned int nr); | 125 | struct pcmcia_socket *pcmcia_get_socket_by_nr(unsigned int nr); |
153 | 126 | ||
154 | int pcmcia_suspend_card(struct pcmcia_socket *skt); | 127 | void pcmcia_parse_uevents(struct pcmcia_socket *socket, unsigned int events); |
155 | int pcmcia_resume_card(struct pcmcia_socket *skt); | 128 | #define PCMCIA_UEVENT_EJECT 0x0001 |
156 | 129 | #define PCMCIA_UEVENT_INSERT 0x0002 | |
157 | int pcmcia_eject_card(struct pcmcia_socket *skt); | 130 | #define PCMCIA_UEVENT_SUSPEND 0x0004 |
158 | int pcmcia_insert_card(struct pcmcia_socket *skt); | 131 | #define PCMCIA_UEVENT_RESUME 0x0008 |
132 | #define PCMCIA_UEVENT_REQUERY 0x0010 | ||
159 | 133 | ||
160 | struct pcmcia_socket *pcmcia_get_socket(struct pcmcia_socket *skt); | 134 | struct pcmcia_socket *pcmcia_get_socket(struct pcmcia_socket *skt); |
161 | void pcmcia_put_socket(struct pcmcia_socket *skt); | 135 | void pcmcia_put_socket(struct pcmcia_socket *skt); |
162 | 136 | ||
137 | /* | ||
138 | * Stuff internal to module "pcmcia". | ||
139 | */ | ||
140 | /* ds.c */ | ||
141 | extern struct bus_type pcmcia_bus_type; | ||
142 | |||
143 | /* pcmcia_resource.c */ | ||
144 | extern int pcmcia_release_configuration(struct pcmcia_device *p_dev); | ||
145 | extern int pcmcia_validate_mem(struct pcmcia_socket *s); | ||
146 | extern struct resource *pcmcia_find_mem_region(u_long base, | ||
147 | u_long num, | ||
148 | u_long align, | ||
149 | int low, | ||
150 | struct pcmcia_socket *s); | ||
151 | |||
152 | |||
163 | /* cistpl.c */ | 153 | /* cistpl.c */ |
154 | extern struct bin_attribute pccard_cis_attr; | ||
155 | |||
164 | int pcmcia_read_cis_mem(struct pcmcia_socket *s, int attr, | 156 | int pcmcia_read_cis_mem(struct pcmcia_socket *s, int attr, |
165 | u_int addr, u_int len, void *ptr); | 157 | u_int addr, u_int len, void *ptr); |
166 | void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr, | 158 | void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr, |
@@ -172,8 +164,8 @@ int pccard_read_tuple(struct pcmcia_socket *s, unsigned int function, | |||
172 | int pcmcia_replace_cis(struct pcmcia_socket *s, | 164 | int pcmcia_replace_cis(struct pcmcia_socket *s, |
173 | const u8 *data, const size_t len); | 165 | const u8 *data, const size_t len); |
174 | int pccard_validate_cis(struct pcmcia_socket *s, unsigned int *count); | 166 | int pccard_validate_cis(struct pcmcia_socket *s, unsigned int *count); |
167 | int verify_cis_cache(struct pcmcia_socket *s); | ||
175 | 168 | ||
176 | /* loop over CIS entries */ | ||
177 | int pccard_loop_tuple(struct pcmcia_socket *s, unsigned int function, | 169 | int pccard_loop_tuple(struct pcmcia_socket *s, unsigned int function, |
178 | cisdata_t code, cisparse_t *parse, void *priv_data, | 170 | cisdata_t code, cisparse_t *parse, void *priv_data, |
179 | int (*loop_tuple) (tuple_t *tuple, | 171 | int (*loop_tuple) (tuple_t *tuple, |
@@ -189,35 +181,8 @@ int pccard_get_next_tuple(struct pcmcia_socket *s, unsigned int function, | |||
189 | int pccard_get_tuple_data(struct pcmcia_socket *s, tuple_t *tuple); | 181 | int pccard_get_tuple_data(struct pcmcia_socket *s, tuple_t *tuple); |
190 | 182 | ||
191 | 183 | ||
192 | /* rsrc_mgr.c */ | ||
193 | int pcmcia_validate_mem(struct pcmcia_socket *s); | ||
194 | struct resource *pcmcia_find_io_region(unsigned long base, | ||
195 | int num, | ||
196 | unsigned long align, | ||
197 | struct pcmcia_socket *s); | ||
198 | int pcmcia_adjust_io_region(struct resource *res, | ||
199 | unsigned long r_start, | ||
200 | unsigned long r_end, | ||
201 | struct pcmcia_socket *s); | ||
202 | struct resource *pcmcia_find_mem_region(u_long base, | ||
203 | u_long num, | ||
204 | u_long align, | ||
205 | int low, | ||
206 | struct pcmcia_socket *s); | ||
207 | |||
208 | /* | ||
209 | * Stuff internal to module "pcmcia". | ||
210 | */ | ||
211 | /* ds.c */ | ||
212 | extern struct bus_type pcmcia_bus_type; | ||
213 | |||
214 | /* pcmcia_resource.c */ | ||
215 | extern int pcmcia_release_configuration(struct pcmcia_device *p_dev); | ||
216 | |||
217 | #ifdef CONFIG_PCMCIA_IOCTL | 184 | #ifdef CONFIG_PCMCIA_IOCTL |
218 | /* ds.c */ | 185 | /* ds.c */ |
219 | extern spinlock_t pcmcia_dev_list_lock; | ||
220 | |||
221 | extern struct pcmcia_device *pcmcia_get_dev(struct pcmcia_device *p_dev); | 186 | extern struct pcmcia_device *pcmcia_get_dev(struct pcmcia_device *p_dev); |
222 | extern void pcmcia_put_dev(struct pcmcia_device *p_dev); | 187 | extern void pcmcia_put_dev(struct pcmcia_device *p_dev); |
223 | 188 | ||
diff --git a/drivers/pcmcia/db1xxx_ss.c b/drivers/pcmcia/db1xxx_ss.c new file mode 100644 index 000000000000..3889cf07d6ce --- /dev/null +++ b/drivers/pcmcia/db1xxx_ss.c | |||
@@ -0,0 +1,623 @@ | |||
1 | /* | ||
2 | * PCMCIA socket code for the Alchemy Db1xxx/Pb1xxx boards. | ||
3 | * | ||
4 | * Copyright (c) 2009 Manuel Lauss <manuel.lauss@gmail.com> | ||
5 | * | ||
6 | */ | ||
7 | |||
8 | /* This is a fairly generic PCMCIA socket driver suitable for the | ||
9 | * following Alchemy Development boards: | ||
10 | * Db1000, Db/Pb1500, Db/Pb1100, Db/Pb1550, Db/Pb1200. | ||
11 | * | ||
12 | * The Db1000 is used as a reference: Per-socket card-, carddetect- and | ||
13 | * statuschange IRQs connected to SoC GPIOs, control and status register | ||
14 | * bits arranged in per-socket groups in an external PLD. All boards | ||
15 | * listed here use this layout, including bit positions and meanings. | ||
16 | * Of course there are exceptions in later boards: | ||
17 | * | ||
18 | * - Pb1100/Pb1500: single socket only; voltage key bits VS are | ||
19 | * at STATUS[5:4] (instead of STATUS[1:0]). | ||
20 | * - Au1200-based: additional card-eject irqs, irqs not gpios! | ||
21 | */ | ||
22 | |||
23 | #include <linux/delay.h> | ||
24 | #include <linux/gpio.h> | ||
25 | #include <linux/interrupt.h> | ||
26 | #include <linux/pm.h> | ||
27 | #include <linux/platform_device.h> | ||
28 | #include <linux/resource.h> | ||
29 | #include <linux/spinlock.h> | ||
30 | |||
31 | #include <pcmcia/cs_types.h> | ||
32 | #include <pcmcia/ss.h> | ||
33 | |||
34 | #include <asm/mach-au1x00/au1000.h> | ||
35 | #include <asm/mach-db1x00/bcsr.h> | ||
36 | |||
37 | #define MEM_MAP_SIZE 0x400000 | ||
38 | #define IO_MAP_SIZE 0x1000 | ||
39 | |||
40 | struct db1x_pcmcia_sock { | ||
41 | struct pcmcia_socket socket; | ||
42 | int nr; /* socket number */ | ||
43 | void *virt_io; | ||
44 | |||
45 | /* the "pseudo" addresses of the PCMCIA space. */ | ||
46 | phys_addr_t phys_io; | ||
47 | phys_addr_t phys_attr; | ||
48 | phys_addr_t phys_mem; | ||
49 | |||
50 | /* previous flags for set_socket() */ | ||
51 | unsigned int old_flags; | ||
52 | |||
53 | /* interrupt sources: linux irq numbers! */ | ||
54 | int insert_irq; /* default carddetect irq */ | ||
55 | int stschg_irq; /* card-status-change irq */ | ||
56 | int card_irq; /* card irq */ | ||
57 | int eject_irq; /* db1200/pb1200 have these */ | ||
58 | |||
59 | #define BOARD_TYPE_DEFAULT 0 /* most boards */ | ||
60 | #define BOARD_TYPE_DB1200 1 /* IRQs aren't gpios */ | ||
61 | #define BOARD_TYPE_PB1100 2 /* VS bits slightly different */ | ||
62 | int board_type; | ||
63 | }; | ||
64 | |||
65 | #define to_db1x_socket(x) container_of(x, struct db1x_pcmcia_sock, socket) | ||
66 | |||
67 | /* DB/PB1200: check CPLD SIGSTATUS register bit 10/12 */ | ||
68 | static int db1200_card_inserted(struct db1x_pcmcia_sock *sock) | ||
69 | { | ||
70 | unsigned short sigstat; | ||
71 | |||
72 | sigstat = bcsr_read(BCSR_SIGSTAT); | ||
73 | return sigstat & 1 << (8 + 2 * sock->nr); | ||
74 | } | ||
75 | |||
76 | /* carddetect gpio: low-active */ | ||
77 | static int db1000_card_inserted(struct db1x_pcmcia_sock *sock) | ||
78 | { | ||
79 | return !gpio_get_value(irq_to_gpio(sock->insert_irq)); | ||
80 | } | ||
81 | |||
82 | static int db1x_card_inserted(struct db1x_pcmcia_sock *sock) | ||
83 | { | ||
84 | switch (sock->board_type) { | ||
85 | case BOARD_TYPE_DB1200: | ||
86 | return db1200_card_inserted(sock); | ||
87 | default: | ||
88 | return db1000_card_inserted(sock); | ||
89 | } | ||
90 | } | ||
91 | |||
92 | /* STSCHG tends to bounce heavily when cards are inserted/ejected. | ||
93 | * To avoid this, the interrupt is normally disabled and only enabled | ||
94 | * after reset to a card has been de-asserted. | ||
95 | */ | ||
96 | static inline void set_stschg(struct db1x_pcmcia_sock *sock, int en) | ||
97 | { | ||
98 | if (sock->stschg_irq != -1) { | ||
99 | if (en) | ||
100 | enable_irq(sock->stschg_irq); | ||
101 | else | ||
102 | disable_irq(sock->stschg_irq); | ||
103 | } | ||
104 | } | ||
105 | |||
106 | static irqreturn_t db1000_pcmcia_cdirq(int irq, void *data) | ||
107 | { | ||
108 | struct db1x_pcmcia_sock *sock = data; | ||
109 | |||
110 | pcmcia_parse_events(&sock->socket, SS_DETECT); | ||
111 | |||
112 | return IRQ_HANDLED; | ||
113 | } | ||
114 | |||
115 | static irqreturn_t db1000_pcmcia_stschgirq(int irq, void *data) | ||
116 | { | ||
117 | struct db1x_pcmcia_sock *sock = data; | ||
118 | |||
119 | pcmcia_parse_events(&sock->socket, SS_STSCHG); | ||
120 | |||
121 | return IRQ_HANDLED; | ||
122 | } | ||
123 | |||
124 | static irqreturn_t db1200_pcmcia_cdirq(int irq, void *data) | ||
125 | { | ||
126 | struct db1x_pcmcia_sock *sock = data; | ||
127 | |||
128 | /* Db/Pb1200 have separate per-socket insertion and ejection | ||
129 | * interrupts which stay asserted as long as the card is | ||
130 | * inserted/missing. The one which caused us to be called | ||
131 | * needs to be disabled and the other one enabled. | ||
132 | */ | ||
133 | if (irq == sock->insert_irq) { | ||
134 | disable_irq_nosync(sock->insert_irq); | ||
135 | enable_irq(sock->eject_irq); | ||
136 | } else { | ||
137 | disable_irq_nosync(sock->eject_irq); | ||
138 | enable_irq(sock->insert_irq); | ||
139 | } | ||
140 | |||
141 | pcmcia_parse_events(&sock->socket, SS_DETECT); | ||
142 | |||
143 | return IRQ_HANDLED; | ||
144 | } | ||
145 | |||
146 | static int db1x_pcmcia_setup_irqs(struct db1x_pcmcia_sock *sock) | ||
147 | { | ||
148 | int ret; | ||
149 | unsigned long flags; | ||
150 | |||
151 | if (sock->stschg_irq != -1) { | ||
152 | ret = request_irq(sock->stschg_irq, db1000_pcmcia_stschgirq, | ||
153 | 0, "pcmcia_stschg", sock); | ||
154 | if (ret) | ||
155 | return ret; | ||
156 | } | ||
157 | |||
158 | /* Db/Pb1200 have separate per-socket insertion and ejection | ||
159 | * interrupts, which should show edge behaviour but don't. | ||
160 | * So interrupts are disabled until both insertion and | ||
161 | * ejection handler have been registered and the currently | ||
162 | * active one disabled. | ||
163 | */ | ||
164 | if (sock->board_type == BOARD_TYPE_DB1200) { | ||
165 | local_irq_save(flags); | ||
166 | |||
167 | ret = request_irq(sock->insert_irq, db1200_pcmcia_cdirq, | ||
168 | IRQF_DISABLED, "pcmcia_insert", sock); | ||
169 | if (ret) | ||
170 | goto out1; | ||
171 | |||
172 | ret = request_irq(sock->eject_irq, db1200_pcmcia_cdirq, | ||
173 | IRQF_DISABLED, "pcmcia_eject", sock); | ||
174 | if (ret) { | ||
175 | free_irq(sock->insert_irq, sock); | ||
176 | local_irq_restore(flags); | ||
177 | goto out1; | ||
178 | } | ||
179 | |||
180 | /* disable the currently active one */ | ||
181 | if (db1200_card_inserted(sock)) | ||
182 | disable_irq_nosync(sock->insert_irq); | ||
183 | else | ||
184 | disable_irq_nosync(sock->eject_irq); | ||
185 | |||
186 | local_irq_restore(flags); | ||
187 | } else { | ||
188 | /* all other (older) Db1x00 boards use a GPIO to show | ||
189 | * card detection status: use both-edge triggers. | ||
190 | */ | ||
191 | set_irq_type(sock->insert_irq, IRQ_TYPE_EDGE_BOTH); | ||
192 | ret = request_irq(sock->insert_irq, db1000_pcmcia_cdirq, | ||
193 | 0, "pcmcia_carddetect", sock); | ||
194 | |||
195 | if (ret) | ||
196 | goto out1; | ||
197 | } | ||
198 | |||
199 | return 0; /* all done */ | ||
200 | |||
201 | out1: | ||
202 | if (sock->stschg_irq != -1) | ||
203 | free_irq(sock->stschg_irq, sock); | ||
204 | |||
205 | return ret; | ||
206 | } | ||
207 | |||
208 | static void db1x_pcmcia_free_irqs(struct db1x_pcmcia_sock *sock) | ||
209 | { | ||
210 | if (sock->stschg_irq != -1) | ||
211 | free_irq(sock->stschg_irq, sock); | ||
212 | |||
213 | free_irq(sock->insert_irq, sock); | ||
214 | if (sock->eject_irq != -1) | ||
215 | free_irq(sock->eject_irq, sock); | ||
216 | } | ||
217 | |||
218 | /* | ||
219 | * configure a PCMCIA socket on the Db1x00 series of boards (and | ||
220 | * compatibles). | ||
221 | * | ||
222 | * 2 external registers are involved: | ||
223 | * pcmcia_status (offset 0x04): bits [0:1/2:3]: read card voltage id | ||
224 | * pcmcia_control(offset 0x10): | ||
225 | * bits[0:1] set vcc for card | ||
226 | * bits[2:3] set vpp for card | ||
227 | * bit 4: enable data buffers | ||
228 | * bit 7: reset# for card | ||
229 | * add 8 for second socket. | ||
230 | */ | ||
231 | static int db1x_pcmcia_configure(struct pcmcia_socket *skt, | ||
232 | struct socket_state_t *state) | ||
233 | { | ||
234 | struct db1x_pcmcia_sock *sock = to_db1x_socket(skt); | ||
235 | unsigned short cr_clr, cr_set; | ||
236 | unsigned int changed; | ||
237 | int v, p, ret; | ||
238 | |||
239 | /* card voltage setup */ | ||
240 | cr_clr = (0xf << (sock->nr * 8)); /* clear voltage settings */ | ||
241 | cr_set = 0; | ||
242 | v = p = ret = 0; | ||
243 | |||
244 | switch (state->Vcc) { | ||
245 | case 50: | ||
246 | ++v; | ||
247 | case 33: | ||
248 | ++v; | ||
249 | case 0: | ||
250 | break; | ||
251 | default: | ||
252 | printk(KERN_INFO "pcmcia%d unsupported Vcc %d\n", | ||
253 | sock->nr, state->Vcc); | ||
254 | } | ||
255 | |||
256 | switch (state->Vpp) { | ||
257 | case 12: | ||
258 | ++p; | ||
259 | case 33: | ||
260 | case 50: | ||
261 | ++p; | ||
262 | case 0: | ||
263 | break; | ||
264 | default: | ||
265 | printk(KERN_INFO "pcmcia%d unsupported Vpp %d\n", | ||
266 | sock->nr, state->Vpp); | ||
267 | } | ||
268 | |||
269 | /* sanity check: Vpp must be 0, 12, or Vcc */ | ||
270 | if (((state->Vcc == 33) && (state->Vpp == 50)) || | ||
271 | ((state->Vcc == 50) && (state->Vpp == 33))) { | ||
272 | printk(KERN_INFO "pcmcia%d bad Vcc/Vpp combo (%d %d)\n", | ||
273 | sock->nr, state->Vcc, state->Vpp); | ||
274 | v = p = 0; | ||
275 | ret = -EINVAL; | ||
276 | } | ||
277 | |||
278 | /* create new voltage code */ | ||
279 | cr_set |= ((v << 2) | p) << (sock->nr * 8); | ||
280 | |||
281 | changed = state->flags ^ sock->old_flags; | ||
282 | |||
283 | if (changed & SS_RESET) { | ||
284 | if (state->flags & SS_RESET) { | ||
285 | set_stschg(sock, 0); | ||
286 | /* assert reset, disable io buffers */ | ||
287 | cr_clr |= (1 << (7 + (sock->nr * 8))); | ||
288 | cr_clr |= (1 << (4 + (sock->nr * 8))); | ||
289 | } else { | ||
290 | /* de-assert reset, enable io buffers */ | ||
291 | cr_set |= 1 << (7 + (sock->nr * 8)); | ||
292 | cr_set |= 1 << (4 + (sock->nr * 8)); | ||
293 | } | ||
294 | } | ||
295 | |||
296 | /* update PCMCIA configuration */ | ||
297 | bcsr_mod(BCSR_PCMCIA, cr_clr, cr_set); | ||
298 | |||
299 | sock->old_flags = state->flags; | ||
300 | |||
301 | /* reset was taken away: give card time to initialize properly */ | ||
302 | if ((changed & SS_RESET) && !(state->flags & SS_RESET)) { | ||
303 | msleep(500); | ||
304 | set_stschg(sock, 1); | ||
305 | } | ||
306 | |||
307 | return ret; | ||
308 | } | ||
309 | |||
310 | /* VCC bits at [3:2]/[11:10] */ | ||
311 | #define GET_VCC(cr, socknr) \ | ||
312 | ((((cr) >> 2) >> ((socknr) * 8)) & 3) | ||
313 | |||
314 | /* VS bits at [0:1]/[3:2] */ | ||
315 | #define GET_VS(sr, socknr) \ | ||
316 | (((sr) >> (2 * (socknr))) & 3) | ||
317 | |||
318 | /* reset bits at [7]/[15] */ | ||
319 | #define GET_RESET(cr, socknr) \ | ||
320 | ((cr) & (1 << (7 + (8 * (socknr))))) | ||
321 | |||
322 | static int db1x_pcmcia_get_status(struct pcmcia_socket *skt, | ||
323 | unsigned int *value) | ||
324 | { | ||
325 | struct db1x_pcmcia_sock *sock = to_db1x_socket(skt); | ||
326 | unsigned short cr, sr; | ||
327 | unsigned int status; | ||
328 | |||
329 | status = db1x_card_inserted(sock) ? SS_DETECT : 0; | ||
330 | |||
331 | cr = bcsr_read(BCSR_PCMCIA); | ||
332 | sr = bcsr_read(BCSR_STATUS); | ||
333 | |||
334 | /* PB1100/PB1500: voltage key bits are at [5:4] */ | ||
335 | if (sock->board_type == BOARD_TYPE_PB1100) | ||
336 | sr >>= 4; | ||
337 | |||
338 | /* determine card type */ | ||
339 | switch (GET_VS(sr, sock->nr)) { | ||
340 | case 0: | ||
341 | case 2: | ||
342 | status |= SS_3VCARD; /* 3V card */ | ||
343 | case 3: | ||
344 | break; /* 5V card: set nothing */ | ||
345 | default: | ||
346 | status |= SS_XVCARD; /* treated as unsupported in core */ | ||
347 | } | ||
348 | |||
349 | /* if Vcc is not zero, we have applied power to a card */ | ||
350 | status |= GET_VCC(cr, sock->nr) ? SS_POWERON : 0; | ||
351 | |||
352 | /* reset de-asserted? then we're ready */ | ||
353 | status |= (GET_RESET(cr, sock->nr)) ? SS_READY : SS_RESET; | ||
354 | |||
355 | *value = status; | ||
356 | |||
357 | return 0; | ||
358 | } | ||
359 | |||
360 | static int db1x_pcmcia_sock_init(struct pcmcia_socket *skt) | ||
361 | { | ||
362 | return 0; | ||
363 | } | ||
364 | |||
365 | static int db1x_pcmcia_sock_suspend(struct pcmcia_socket *skt) | ||
366 | { | ||
367 | return 0; | ||
368 | } | ||
369 | |||
370 | static int au1x00_pcmcia_set_io_map(struct pcmcia_socket *skt, | ||
371 | struct pccard_io_map *map) | ||
372 | { | ||
373 | struct db1x_pcmcia_sock *sock = to_db1x_socket(skt); | ||
374 | |||
375 | map->start = (u32)sock->virt_io; | ||
376 | map->stop = map->start + IO_MAP_SIZE; | ||
377 | |||
378 | return 0; | ||
379 | } | ||
380 | |||
381 | static int au1x00_pcmcia_set_mem_map(struct pcmcia_socket *skt, | ||
382 | struct pccard_mem_map *map) | ||
383 | { | ||
384 | struct db1x_pcmcia_sock *sock = to_db1x_socket(skt); | ||
385 | |||
386 | if (map->flags & MAP_ATTRIB) | ||
387 | map->static_start = sock->phys_attr + map->card_start; | ||
388 | else | ||
389 | map->static_start = sock->phys_mem + map->card_start; | ||
390 | |||
391 | return 0; | ||
392 | } | ||
393 | |||
394 | static struct pccard_operations db1x_pcmcia_operations = { | ||
395 | .init = db1x_pcmcia_sock_init, | ||
396 | .suspend = db1x_pcmcia_sock_suspend, | ||
397 | .get_status = db1x_pcmcia_get_status, | ||
398 | .set_socket = db1x_pcmcia_configure, | ||
399 | .set_io_map = au1x00_pcmcia_set_io_map, | ||
400 | .set_mem_map = au1x00_pcmcia_set_mem_map, | ||
401 | }; | ||
402 | |||
403 | static int __devinit db1x_pcmcia_socket_probe(struct platform_device *pdev) | ||
404 | { | ||
405 | struct db1x_pcmcia_sock *sock; | ||
406 | struct resource *r; | ||
407 | int ret, bid; | ||
408 | |||
409 | sock = kzalloc(sizeof(struct db1x_pcmcia_sock), GFP_KERNEL); | ||
410 | if (!sock) | ||
411 | return -ENOMEM; | ||
412 | |||
413 | sock->nr = pdev->id; | ||
414 | |||
415 | bid = BCSR_WHOAMI_BOARD(bcsr_read(BCSR_WHOAMI)); | ||
416 | switch (bid) { | ||
417 | case BCSR_WHOAMI_PB1500: | ||
418 | case BCSR_WHOAMI_PB1500R2: | ||
419 | case BCSR_WHOAMI_PB1100: | ||
420 | sock->board_type = BOARD_TYPE_PB1100; | ||
421 | break; | ||
422 | case BCSR_WHOAMI_DB1000 ... BCSR_WHOAMI_PB1550_SDR: | ||
423 | sock->board_type = BOARD_TYPE_DEFAULT; | ||
424 | break; | ||
425 | case BCSR_WHOAMI_PB1200 ... BCSR_WHOAMI_DB1200: | ||
426 | sock->board_type = BOARD_TYPE_DB1200; | ||
427 | break; | ||
428 | default: | ||
429 | printk(KERN_INFO "db1xxx-ss: unknown board %d!\n", bid); | ||
430 | ret = -ENODEV; | ||
431 | goto out0; | ||
432 | }; | ||
433 | |||
434 | /* | ||
435 | * gather resources necessary and optional nice-to-haves to | ||
436 | * operate a socket: | ||
437 | * This includes IRQs for Carddetection/ejection, the card | ||
438 | * itself and optional status change detection. | ||
439 | * Also, the memory areas covered by a socket. For these | ||
440 | * we require the 32bit "pseudo" addresses (see the au1000.h | ||
441 | * header for more information). | ||
442 | */ | ||
443 | |||
444 | /* card: irq assigned to the card itself. */ | ||
445 | r = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "card"); | ||
446 | sock->card_irq = r ? r->start : 0; | ||
447 | |||
448 | /* insert: irq which triggers on card insertion/ejection */ | ||
449 | r = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "insert"); | ||
450 | sock->insert_irq = r ? r->start : -1; | ||
451 | |||
452 | /* stschg: irq which trigger on card status change (optional) */ | ||
453 | r = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "stschg"); | ||
454 | sock->stschg_irq = r ? r->start : -1; | ||
455 | |||
456 | /* eject: irq which triggers on ejection (DB1200/PB1200 only) */ | ||
457 | r = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "eject"); | ||
458 | sock->eject_irq = r ? r->start : -1; | ||
459 | |||
460 | ret = -ENODEV; | ||
461 | |||
462 | /* | ||
463 | * pseudo-attr: The 32bit address of the PCMCIA attribute space | ||
464 | * for this socket (usually the 36bit address shifted 4 to the | ||
465 | * right). | ||
466 | */ | ||
467 | r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pcmcia-attr"); | ||
468 | if (!r) { | ||
469 | printk(KERN_ERR "pcmcia%d has no 'pseudo-attr' resource!\n", | ||
470 | sock->nr); | ||
471 | goto out0; | ||
472 | } | ||
473 | sock->phys_attr = r->start; | ||
474 | |||
475 | /* | ||
476 | * pseudo-mem: The 32bit address of the PCMCIA memory space for | ||
477 | * this socket (usually the 36bit address shifted 4 to the right) | ||
478 | */ | ||
479 | r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pcmcia-mem"); | ||
480 | if (!r) { | ||
481 | printk(KERN_ERR "pcmcia%d has no 'pseudo-mem' resource!\n", | ||
482 | sock->nr); | ||
483 | goto out0; | ||
484 | } | ||
485 | sock->phys_mem = r->start; | ||
486 | |||
487 | /* | ||
488 | * pseudo-io: The 32bit address of the PCMCIA IO space for this | ||
489 | * socket (usually the 36bit address shifted 4 to the right). | ||
490 | */ | ||
491 | r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pcmcia-io"); | ||
492 | if (!r) { | ||
493 | printk(KERN_ERR "pcmcia%d has no 'pseudo-io' resource!\n", | ||
494 | sock->nr); | ||
495 | goto out0; | ||
496 | } | ||
497 | sock->phys_io = r->start; | ||
498 | |||
499 | /* | ||
500 | * PCMCIA client drivers use the inb/outb macros to access | ||
501 | * the IO registers. Since mips_io_port_base is added | ||
502 | * to the access address of the mips implementation of | ||
503 | * inb/outb, we need to subtract it here because we want | ||
504 | * to access the I/O or MEM address directly, without | ||
505 | * going through this "mips_io_port_base" mechanism. | ||
506 | */ | ||
507 | sock->virt_io = (void *)(ioremap(sock->phys_io, IO_MAP_SIZE) - | ||
508 | mips_io_port_base); | ||
509 | |||
510 | if (!sock->virt_io) { | ||
511 | printk(KERN_ERR "pcmcia%d: cannot remap IO area\n", | ||
512 | sock->nr); | ||
513 | ret = -ENOMEM; | ||
514 | goto out0; | ||
515 | } | ||
516 | |||
517 | sock->socket.ops = &db1x_pcmcia_operations; | ||
518 | sock->socket.owner = THIS_MODULE; | ||
519 | sock->socket.pci_irq = sock->card_irq; | ||
520 | sock->socket.features = SS_CAP_STATIC_MAP | SS_CAP_PCCARD; | ||
521 | sock->socket.map_size = MEM_MAP_SIZE; | ||
522 | sock->socket.io_offset = (unsigned long)sock->virt_io; | ||
523 | sock->socket.dev.parent = &pdev->dev; | ||
524 | sock->socket.resource_ops = &pccard_static_ops; | ||
525 | |||
526 | platform_set_drvdata(pdev, sock); | ||
527 | |||
528 | ret = db1x_pcmcia_setup_irqs(sock); | ||
529 | if (ret) { | ||
530 | printk(KERN_ERR "pcmcia%d cannot setup interrupts\n", | ||
531 | sock->nr); | ||
532 | goto out1; | ||
533 | } | ||
534 | |||
535 | set_stschg(sock, 0); | ||
536 | |||
537 | ret = pcmcia_register_socket(&sock->socket); | ||
538 | if (ret) { | ||
539 | printk(KERN_ERR "pcmcia%d failed to register\n", sock->nr); | ||
540 | goto out2; | ||
541 | } | ||
542 | |||
543 | printk(KERN_INFO "Alchemy Db/Pb1xxx pcmcia%d @ io/attr/mem %09llx" | ||
544 | "(%p) %09llx %09llx card/insert/stschg/eject irqs @ %d " | ||
545 | "%d %d %d\n", sock->nr, sock->phys_io, sock->virt_io, | ||
546 | sock->phys_attr, sock->phys_mem, sock->card_irq, | ||
547 | sock->insert_irq, sock->stschg_irq, sock->eject_irq); | ||
548 | |||
549 | return 0; | ||
550 | |||
551 | out2: | ||
552 | db1x_pcmcia_free_irqs(sock); | ||
553 | out1: | ||
554 | iounmap((void *)(sock->virt_io + (u32)mips_io_port_base)); | ||
555 | out0: | ||
556 | kfree(sock); | ||
557 | return ret; | ||
558 | } | ||
559 | |||
560 | static int __devexit db1x_pcmcia_socket_remove(struct platform_device *pdev) | ||
561 | { | ||
562 | struct db1x_pcmcia_sock *sock = platform_get_drvdata(pdev); | ||
563 | |||
564 | db1x_pcmcia_free_irqs(sock); | ||
565 | pcmcia_unregister_socket(&sock->socket); | ||
566 | iounmap((void *)(sock->virt_io + (u32)mips_io_port_base)); | ||
567 | kfree(sock); | ||
568 | |||
569 | return 0; | ||
570 | } | ||
571 | |||
572 | #ifdef CONFIG_PM | ||
573 | static int db1x_pcmcia_suspend(struct device *dev) | ||
574 | { | ||
575 | return pcmcia_socket_dev_suspend(dev); | ||
576 | } | ||
577 | |||
578 | static int db1x_pcmcia_resume(struct device *dev) | ||
579 | { | ||
580 | return pcmcia_socket_dev_resume(dev); | ||
581 | } | ||
582 | |||
583 | static struct dev_pm_ops db1x_pcmcia_pmops = { | ||
584 | .resume = db1x_pcmcia_resume, | ||
585 | .suspend = db1x_pcmcia_suspend, | ||
586 | .thaw = db1x_pcmcia_resume, | ||
587 | .freeze = db1x_pcmcia_suspend, | ||
588 | }; | ||
589 | |||
590 | #define DB1XXX_SS_PMOPS &db1x_pcmcia_pmops | ||
591 | |||
592 | #else | ||
593 | |||
594 | #define DB1XXX_SS_PMOPS NULL | ||
595 | |||
596 | #endif | ||
597 | |||
598 | static struct platform_driver db1x_pcmcia_socket_driver = { | ||
599 | .driver = { | ||
600 | .name = "db1xxx_pcmcia", | ||
601 | .owner = THIS_MODULE, | ||
602 | .pm = DB1XXX_SS_PMOPS | ||
603 | }, | ||
604 | .probe = db1x_pcmcia_socket_probe, | ||
605 | .remove = __devexit_p(db1x_pcmcia_socket_remove), | ||
606 | }; | ||
607 | |||
608 | int __init db1x_pcmcia_socket_load(void) | ||
609 | { | ||
610 | return platform_driver_register(&db1x_pcmcia_socket_driver); | ||
611 | } | ||
612 | |||
613 | void __exit db1x_pcmcia_socket_unload(void) | ||
614 | { | ||
615 | platform_driver_unregister(&db1x_pcmcia_socket_driver); | ||
616 | } | ||
617 | |||
618 | module_init(db1x_pcmcia_socket_load); | ||
619 | module_exit(db1x_pcmcia_socket_unload); | ||
620 | |||
621 | MODULE_LICENSE("GPL"); | ||
622 | MODULE_DESCRIPTION("PCMCIA Socket Services for Alchemy Db/Pb1x00 boards"); | ||
623 | MODULE_AUTHOR("Manuel Lauss"); | ||
diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c index 1a4a3c49cc15..0f98be4450b7 100644 --- a/drivers/pcmcia/ds.c +++ b/drivers/pcmcia/ds.c | |||
@@ -42,8 +42,6 @@ MODULE_DESCRIPTION("PCMCIA Driver Services"); | |||
42 | MODULE_LICENSE("GPL"); | 42 | MODULE_LICENSE("GPL"); |
43 | 43 | ||
44 | 44 | ||
45 | spinlock_t pcmcia_dev_list_lock; | ||
46 | |||
47 | /*====================================================================*/ | 45 | /*====================================================================*/ |
48 | 46 | ||
49 | static void pcmcia_check_driver(struct pcmcia_driver *p_drv) | 47 | static void pcmcia_check_driver(struct pcmcia_driver *p_drv) |
@@ -126,9 +124,9 @@ pcmcia_store_new_id(struct device_driver *driver, const char *buf, size_t count) | |||
126 | dynid->id.device_no = device_no; | 124 | dynid->id.device_no = device_no; |
127 | memcpy(dynid->id.prod_id_hash, prod_id_hash, sizeof(__u32) * 4); | 125 | memcpy(dynid->id.prod_id_hash, prod_id_hash, sizeof(__u32) * 4); |
128 | 126 | ||
129 | spin_lock(&pdrv->dynids.lock); | 127 | mutex_lock(&pdrv->dynids.lock); |
130 | list_add_tail(&dynid->node, &pdrv->dynids.list); | 128 | list_add_tail(&dynid->node, &pdrv->dynids.list); |
131 | spin_unlock(&pdrv->dynids.lock); | 129 | mutex_unlock(&pdrv->dynids.lock); |
132 | 130 | ||
133 | if (get_driver(&pdrv->drv)) { | 131 | if (get_driver(&pdrv->drv)) { |
134 | retval = driver_attach(&pdrv->drv); | 132 | retval = driver_attach(&pdrv->drv); |
@@ -146,12 +144,12 @@ pcmcia_free_dynids(struct pcmcia_driver *drv) | |||
146 | { | 144 | { |
147 | struct pcmcia_dynid *dynid, *n; | 145 | struct pcmcia_dynid *dynid, *n; |
148 | 146 | ||
149 | spin_lock(&drv->dynids.lock); | 147 | mutex_lock(&drv->dynids.lock); |
150 | list_for_each_entry_safe(dynid, n, &drv->dynids.list, node) { | 148 | list_for_each_entry_safe(dynid, n, &drv->dynids.list, node) { |
151 | list_del(&dynid->node); | 149 | list_del(&dynid->node); |
152 | kfree(dynid); | 150 | kfree(dynid); |
153 | } | 151 | } |
154 | spin_unlock(&drv->dynids.lock); | 152 | mutex_unlock(&drv->dynids.lock); |
155 | } | 153 | } |
156 | 154 | ||
157 | static int | 155 | static int |
@@ -182,7 +180,7 @@ int pcmcia_register_driver(struct pcmcia_driver *driver) | |||
182 | /* initialize common fields */ | 180 | /* initialize common fields */ |
183 | driver->drv.bus = &pcmcia_bus_type; | 181 | driver->drv.bus = &pcmcia_bus_type; |
184 | driver->drv.owner = driver->owner; | 182 | driver->drv.owner = driver->owner; |
185 | spin_lock_init(&driver->dynids.lock); | 183 | mutex_init(&driver->dynids.lock); |
186 | INIT_LIST_HEAD(&driver->dynids.list); | 184 | INIT_LIST_HEAD(&driver->dynids.list); |
187 | 185 | ||
188 | pr_debug("registering driver %s\n", driver->drv.name); | 186 | pr_debug("registering driver %s\n", driver->drv.name); |
@@ -239,30 +237,21 @@ static void pcmcia_release_function(struct kref *ref) | |||
239 | static void pcmcia_release_dev(struct device *dev) | 237 | static void pcmcia_release_dev(struct device *dev) |
240 | { | 238 | { |
241 | struct pcmcia_device *p_dev = to_pcmcia_dev(dev); | 239 | struct pcmcia_device *p_dev = to_pcmcia_dev(dev); |
240 | int i; | ||
242 | dev_dbg(dev, "releasing device\n"); | 241 | dev_dbg(dev, "releasing device\n"); |
243 | pcmcia_put_socket(p_dev->socket); | 242 | pcmcia_put_socket(p_dev->socket); |
243 | for (i = 0; i < 4; i++) | ||
244 | kfree(p_dev->prod_id[i]); | ||
244 | kfree(p_dev->devname); | 245 | kfree(p_dev->devname); |
245 | kref_put(&p_dev->function_config->ref, pcmcia_release_function); | 246 | kref_put(&p_dev->function_config->ref, pcmcia_release_function); |
246 | kfree(p_dev); | 247 | kfree(p_dev); |
247 | } | 248 | } |
248 | 249 | ||
249 | static void pcmcia_add_device_later(struct pcmcia_socket *s, int mfc) | ||
250 | { | ||
251 | if (!s->pcmcia_state.device_add_pending) { | ||
252 | dev_dbg(&s->dev, "scheduling to add %s secondary" | ||
253 | " device to %d\n", mfc ? "mfc" : "pfc", s->sock); | ||
254 | s->pcmcia_state.device_add_pending = 1; | ||
255 | s->pcmcia_state.mfc_pfc = mfc; | ||
256 | schedule_work(&s->device_add); | ||
257 | } | ||
258 | return; | ||
259 | } | ||
260 | 250 | ||
261 | static int pcmcia_device_probe(struct device *dev) | 251 | static int pcmcia_device_probe(struct device *dev) |
262 | { | 252 | { |
263 | struct pcmcia_device *p_dev; | 253 | struct pcmcia_device *p_dev; |
264 | struct pcmcia_driver *p_drv; | 254 | struct pcmcia_driver *p_drv; |
265 | struct pcmcia_device_id *did; | ||
266 | struct pcmcia_socket *s; | 255 | struct pcmcia_socket *s; |
267 | cistpl_config_t cis_config; | 256 | cistpl_config_t cis_config; |
268 | int ret = 0; | 257 | int ret = 0; |
@@ -275,18 +264,6 @@ static int pcmcia_device_probe(struct device *dev) | |||
275 | p_drv = to_pcmcia_drv(dev->driver); | 264 | p_drv = to_pcmcia_drv(dev->driver); |
276 | s = p_dev->socket; | 265 | s = p_dev->socket; |
277 | 266 | ||
278 | /* The PCMCIA code passes the match data in via dev_set_drvdata(dev) | ||
279 | * which is an ugly hack. Once the driver probe is called it may | ||
280 | * and often will overwrite the match data so we must save it first | ||
281 | * | ||
282 | * handle pseudo multifunction devices: | ||
283 | * there are at most two pseudo multifunction devices. | ||
284 | * if we're matching against the first, schedule a | ||
285 | * call which will then check whether there are two | ||
286 | * pseudo devices, and if not, add the second one. | ||
287 | */ | ||
288 | did = dev_get_drvdata(&p_dev->dev); | ||
289 | |||
290 | dev_dbg(dev, "trying to bind to %s\n", p_drv->drv.name); | 267 | dev_dbg(dev, "trying to bind to %s\n", p_drv->drv.name); |
291 | 268 | ||
292 | if ((!p_drv->probe) || (!p_dev->function_config) || | 269 | if ((!p_drv->probe) || (!p_dev->function_config) || |
@@ -315,9 +292,11 @@ static int pcmcia_device_probe(struct device *dev) | |||
315 | goto put_module; | 292 | goto put_module; |
316 | } | 293 | } |
317 | 294 | ||
318 | if (did && (did->match_flags & PCMCIA_DEV_ID_MATCH_DEVICE_NO) && | 295 | mutex_lock(&s->ops_mutex); |
296 | if ((s->pcmcia_state.has_pfc) && | ||
319 | (p_dev->socket->device_count == 1) && (p_dev->device_no == 0)) | 297 | (p_dev->socket->device_count == 1) && (p_dev->device_no == 0)) |
320 | pcmcia_add_device_later(p_dev->socket, 0); | 298 | pcmcia_parse_uevents(s, PCMCIA_UEVENT_REQUERY); |
299 | mutex_unlock(&s->ops_mutex); | ||
321 | 300 | ||
322 | put_module: | 301 | put_module: |
323 | if (ret) | 302 | if (ret) |
@@ -336,26 +315,27 @@ static void pcmcia_card_remove(struct pcmcia_socket *s, struct pcmcia_device *le | |||
336 | { | 315 | { |
337 | struct pcmcia_device *p_dev; | 316 | struct pcmcia_device *p_dev; |
338 | struct pcmcia_device *tmp; | 317 | struct pcmcia_device *tmp; |
339 | unsigned long flags; | ||
340 | 318 | ||
341 | dev_dbg(leftover ? &leftover->dev : &s->dev, | 319 | dev_dbg(leftover ? &leftover->dev : &s->dev, |
342 | "pcmcia_card_remove(%d) %s\n", s->sock, | 320 | "pcmcia_card_remove(%d) %s\n", s->sock, |
343 | leftover ? leftover->devname : ""); | 321 | leftover ? leftover->devname : ""); |
344 | 322 | ||
323 | mutex_lock(&s->ops_mutex); | ||
345 | if (!leftover) | 324 | if (!leftover) |
346 | s->device_count = 0; | 325 | s->device_count = 0; |
347 | else | 326 | else |
348 | s->device_count = 1; | 327 | s->device_count = 1; |
328 | mutex_unlock(&s->ops_mutex); | ||
349 | 329 | ||
350 | /* unregister all pcmcia_devices registered with this socket, except leftover */ | 330 | /* unregister all pcmcia_devices registered with this socket, except leftover */ |
351 | list_for_each_entry_safe(p_dev, tmp, &s->devices_list, socket_device_list) { | 331 | list_for_each_entry_safe(p_dev, tmp, &s->devices_list, socket_device_list) { |
352 | if (p_dev == leftover) | 332 | if (p_dev == leftover) |
353 | continue; | 333 | continue; |
354 | 334 | ||
355 | spin_lock_irqsave(&pcmcia_dev_list_lock, flags); | 335 | mutex_lock(&s->ops_mutex); |
356 | list_del(&p_dev->socket_device_list); | 336 | list_del(&p_dev->socket_device_list); |
357 | p_dev->_removed = 1; | 337 | p_dev->_removed = 1; |
358 | spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); | 338 | mutex_unlock(&s->ops_mutex); |
359 | 339 | ||
360 | dev_dbg(&p_dev->dev, "unregistering device\n"); | 340 | dev_dbg(&p_dev->dev, "unregistering device\n"); |
361 | device_unregister(&p_dev->dev); | 341 | device_unregister(&p_dev->dev); |
@@ -368,7 +348,6 @@ static int pcmcia_device_remove(struct device *dev) | |||
368 | { | 348 | { |
369 | struct pcmcia_device *p_dev; | 349 | struct pcmcia_device *p_dev; |
370 | struct pcmcia_driver *p_drv; | 350 | struct pcmcia_driver *p_drv; |
371 | struct pcmcia_device_id *did; | ||
372 | int i; | 351 | int i; |
373 | 352 | ||
374 | p_dev = to_pcmcia_dev(dev); | 353 | p_dev = to_pcmcia_dev(dev); |
@@ -380,9 +359,8 @@ static int pcmcia_device_remove(struct device *dev) | |||
380 | * pseudo multi-function card, we need to unbind | 359 | * pseudo multi-function card, we need to unbind |
381 | * all devices | 360 | * all devices |
382 | */ | 361 | */ |
383 | did = dev_get_drvdata(&p_dev->dev); | 362 | if ((p_dev->socket->pcmcia_state.has_pfc) && |
384 | if (did && (did->match_flags & PCMCIA_DEV_ID_MATCH_DEVICE_NO) && | 363 | (p_dev->socket->device_count > 0) && |
385 | (p_dev->socket->device_count != 0) && | ||
386 | (p_dev->device_no == 0)) | 364 | (p_dev->device_no == 0)) |
387 | pcmcia_card_remove(p_dev->socket, p_dev); | 365 | pcmcia_card_remove(p_dev->socket, p_dev); |
388 | 366 | ||
@@ -431,16 +409,20 @@ static int pcmcia_device_query(struct pcmcia_device *p_dev) | |||
431 | 409 | ||
432 | if (!pccard_read_tuple(p_dev->socket, BIND_FN_ALL, | 410 | if (!pccard_read_tuple(p_dev->socket, BIND_FN_ALL, |
433 | CISTPL_MANFID, &manf_id)) { | 411 | CISTPL_MANFID, &manf_id)) { |
412 | mutex_lock(&p_dev->socket->ops_mutex); | ||
434 | p_dev->manf_id = manf_id.manf; | 413 | p_dev->manf_id = manf_id.manf; |
435 | p_dev->card_id = manf_id.card; | 414 | p_dev->card_id = manf_id.card; |
436 | p_dev->has_manf_id = 1; | 415 | p_dev->has_manf_id = 1; |
437 | p_dev->has_card_id = 1; | 416 | p_dev->has_card_id = 1; |
417 | mutex_unlock(&p_dev->socket->ops_mutex); | ||
438 | } | 418 | } |
439 | 419 | ||
440 | if (!pccard_read_tuple(p_dev->socket, p_dev->func, | 420 | if (!pccard_read_tuple(p_dev->socket, p_dev->func, |
441 | CISTPL_FUNCID, &func_id)) { | 421 | CISTPL_FUNCID, &func_id)) { |
422 | mutex_lock(&p_dev->socket->ops_mutex); | ||
442 | p_dev->func_id = func_id.func; | 423 | p_dev->func_id = func_id.func; |
443 | p_dev->has_func_id = 1; | 424 | p_dev->has_func_id = 1; |
425 | mutex_unlock(&p_dev->socket->ops_mutex); | ||
444 | } else { | 426 | } else { |
445 | /* rule of thumb: cards with no FUNCID, but with | 427 | /* rule of thumb: cards with no FUNCID, but with |
446 | * common memory device geometry information, are | 428 | * common memory device geometry information, are |
@@ -457,17 +439,21 @@ static int pcmcia_device_query(struct pcmcia_device *p_dev) | |||
457 | dev_dbg(&p_dev->dev, | 439 | dev_dbg(&p_dev->dev, |
458 | "mem device geometry probably means " | 440 | "mem device geometry probably means " |
459 | "FUNCID_MEMORY\n"); | 441 | "FUNCID_MEMORY\n"); |
442 | mutex_lock(&p_dev->socket->ops_mutex); | ||
460 | p_dev->func_id = CISTPL_FUNCID_MEMORY; | 443 | p_dev->func_id = CISTPL_FUNCID_MEMORY; |
461 | p_dev->has_func_id = 1; | 444 | p_dev->has_func_id = 1; |
445 | mutex_unlock(&p_dev->socket->ops_mutex); | ||
462 | } | 446 | } |
463 | kfree(devgeo); | 447 | kfree(devgeo); |
464 | } | 448 | } |
465 | 449 | ||
466 | if (!pccard_read_tuple(p_dev->socket, BIND_FN_ALL, CISTPL_VERS_1, | 450 | if (!pccard_read_tuple(p_dev->socket, BIND_FN_ALL, CISTPL_VERS_1, |
467 | vers1)) { | 451 | vers1)) { |
452 | mutex_lock(&p_dev->socket->ops_mutex); | ||
468 | for (i = 0; i < min_t(unsigned int, 4, vers1->ns); i++) { | 453 | for (i = 0; i < min_t(unsigned int, 4, vers1->ns); i++) { |
469 | char *tmp; | 454 | char *tmp; |
470 | unsigned int length; | 455 | unsigned int length; |
456 | char *new; | ||
471 | 457 | ||
472 | tmp = vers1->str + vers1->ofs[i]; | 458 | tmp = vers1->str + vers1->ofs[i]; |
473 | 459 | ||
@@ -475,14 +461,17 @@ static int pcmcia_device_query(struct pcmcia_device *p_dev) | |||
475 | if ((length < 2) || (length > 255)) | 461 | if ((length < 2) || (length > 255)) |
476 | continue; | 462 | continue; |
477 | 463 | ||
478 | p_dev->prod_id[i] = kmalloc(sizeof(char) * length, | 464 | new = kmalloc(sizeof(char) * length, GFP_KERNEL); |
479 | GFP_KERNEL); | 465 | if (!new) |
480 | if (!p_dev->prod_id[i]) | ||
481 | continue; | 466 | continue; |
482 | 467 | ||
483 | p_dev->prod_id[i] = strncpy(p_dev->prod_id[i], | 468 | new = strncpy(new, tmp, length); |
484 | tmp, length); | 469 | |
470 | tmp = p_dev->prod_id[i]; | ||
471 | p_dev->prod_id[i] = new; | ||
472 | kfree(tmp); | ||
485 | } | 473 | } |
474 | mutex_unlock(&p_dev->socket->ops_mutex); | ||
486 | } | 475 | } |
487 | 476 | ||
488 | kfree(vers1); | 477 | kfree(vers1); |
@@ -502,7 +491,7 @@ static DEFINE_MUTEX(device_add_lock); | |||
502 | struct pcmcia_device *pcmcia_device_add(struct pcmcia_socket *s, unsigned int function) | 491 | struct pcmcia_device *pcmcia_device_add(struct pcmcia_socket *s, unsigned int function) |
503 | { | 492 | { |
504 | struct pcmcia_device *p_dev, *tmp_dev; | 493 | struct pcmcia_device *p_dev, *tmp_dev; |
505 | unsigned long flags; | 494 | int i; |
506 | 495 | ||
507 | s = pcmcia_get_socket(s); | 496 | s = pcmcia_get_socket(s); |
508 | if (!s) | 497 | if (!s) |
@@ -512,16 +501,19 @@ struct pcmcia_device *pcmcia_device_add(struct pcmcia_socket *s, unsigned int fu | |||
512 | 501 | ||
513 | pr_debug("adding device to %d, function %d\n", s->sock, function); | 502 | pr_debug("adding device to %d, function %d\n", s->sock, function); |
514 | 503 | ||
515 | /* max of 4 devices per card */ | ||
516 | if (s->device_count == 4) | ||
517 | goto err_put; | ||
518 | |||
519 | p_dev = kzalloc(sizeof(struct pcmcia_device), GFP_KERNEL); | 504 | p_dev = kzalloc(sizeof(struct pcmcia_device), GFP_KERNEL); |
520 | if (!p_dev) | 505 | if (!p_dev) |
521 | goto err_put; | 506 | goto err_put; |
522 | 507 | ||
523 | p_dev->socket = s; | 508 | mutex_lock(&s->ops_mutex); |
524 | p_dev->device_no = (s->device_count++); | 509 | p_dev->device_no = (s->device_count++); |
510 | mutex_unlock(&s->ops_mutex); | ||
511 | |||
512 | /* max of 2 devices per card */ | ||
513 | if (p_dev->device_no >= 2) | ||
514 | goto err_free; | ||
515 | |||
516 | p_dev->socket = s; | ||
525 | p_dev->func = function; | 517 | p_dev->func = function; |
526 | 518 | ||
527 | p_dev->dev.bus = &pcmcia_bus_type; | 519 | p_dev->dev.bus = &pcmcia_bus_type; |
@@ -538,7 +530,7 @@ struct pcmcia_device *pcmcia_device_add(struct pcmcia_socket *s, unsigned int fu | |||
538 | goto err_free; | 530 | goto err_free; |
539 | dev_dbg(&p_dev->dev, "devname is %s\n", p_dev->devname); | 531 | dev_dbg(&p_dev->dev, "devname is %s\n", p_dev->devname); |
540 | 532 | ||
541 | spin_lock_irqsave(&pcmcia_dev_list_lock, flags); | 533 | mutex_lock(&s->ops_mutex); |
542 | 534 | ||
543 | /* | 535 | /* |
544 | * p_dev->function_config must be the same for all card functions. | 536 | * p_dev->function_config must be the same for all card functions. |
@@ -556,7 +548,7 @@ struct pcmcia_device *pcmcia_device_add(struct pcmcia_socket *s, unsigned int fu | |||
556 | /* Add to the list in pcmcia_bus_socket */ | 548 | /* Add to the list in pcmcia_bus_socket */ |
557 | list_add(&p_dev->socket_device_list, &s->devices_list); | 549 | list_add(&p_dev->socket_device_list, &s->devices_list); |
558 | 550 | ||
559 | spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); | 551 | mutex_unlock(&s->ops_mutex); |
560 | 552 | ||
561 | if (!p_dev->function_config) { | 553 | if (!p_dev->function_config) { |
562 | dev_dbg(&p_dev->dev, "creating config_t\n"); | 554 | dev_dbg(&p_dev->dev, "creating config_t\n"); |
@@ -581,14 +573,19 @@ struct pcmcia_device *pcmcia_device_add(struct pcmcia_socket *s, unsigned int fu | |||
581 | return p_dev; | 573 | return p_dev; |
582 | 574 | ||
583 | err_unreg: | 575 | err_unreg: |
584 | spin_lock_irqsave(&pcmcia_dev_list_lock, flags); | 576 | mutex_lock(&s->ops_mutex); |
585 | list_del(&p_dev->socket_device_list); | 577 | list_del(&p_dev->socket_device_list); |
586 | spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); | 578 | mutex_unlock(&s->ops_mutex); |
587 | 579 | ||
588 | err_free: | 580 | err_free: |
581 | mutex_lock(&s->ops_mutex); | ||
582 | s->device_count--; | ||
583 | mutex_unlock(&s->ops_mutex); | ||
584 | |||
585 | for (i = 0; i < 4; i++) | ||
586 | kfree(p_dev->prod_id[i]); | ||
589 | kfree(p_dev->devname); | 587 | kfree(p_dev->devname); |
590 | kfree(p_dev); | 588 | kfree(p_dev); |
591 | s->device_count--; | ||
592 | err_put: | 589 | err_put: |
593 | mutex_unlock(&device_add_lock); | 590 | mutex_unlock(&device_add_lock); |
594 | pcmcia_put_socket(s); | 591 | pcmcia_put_socket(s); |
@@ -601,19 +598,23 @@ static int pcmcia_card_add(struct pcmcia_socket *s) | |||
601 | { | 598 | { |
602 | cistpl_longlink_mfc_t mfc; | 599 | cistpl_longlink_mfc_t mfc; |
603 | unsigned int no_funcs, i, no_chains; | 600 | unsigned int no_funcs, i, no_chains; |
604 | int ret = 0; | 601 | int ret = -EAGAIN; |
605 | 602 | ||
603 | mutex_lock(&s->ops_mutex); | ||
606 | if (!(s->resource_setup_done)) { | 604 | if (!(s->resource_setup_done)) { |
607 | dev_dbg(&s->dev, | 605 | dev_dbg(&s->dev, |
608 | "no resources available, delaying card_add\n"); | 606 | "no resources available, delaying card_add\n"); |
607 | mutex_unlock(&s->ops_mutex); | ||
609 | return -EAGAIN; /* try again, but later... */ | 608 | return -EAGAIN; /* try again, but later... */ |
610 | } | 609 | } |
611 | 610 | ||
612 | if (pcmcia_validate_mem(s)) { | 611 | if (pcmcia_validate_mem(s)) { |
613 | dev_dbg(&s->dev, "validating mem resources failed, " | 612 | dev_dbg(&s->dev, "validating mem resources failed, " |
614 | "delaying card_add\n"); | 613 | "delaying card_add\n"); |
614 | mutex_unlock(&s->ops_mutex); | ||
615 | return -EAGAIN; /* try again, but later... */ | 615 | return -EAGAIN; /* try again, but later... */ |
616 | } | 616 | } |
617 | mutex_unlock(&s->ops_mutex); | ||
617 | 618 | ||
618 | ret = pccard_validate_cis(s, &no_chains); | 619 | ret = pccard_validate_cis(s, &no_chains); |
619 | if (ret || !no_chains) { | 620 | if (ret || !no_chains) { |
@@ -634,17 +635,7 @@ static int pcmcia_card_add(struct pcmcia_socket *s) | |||
634 | } | 635 | } |
635 | 636 | ||
636 | 637 | ||
637 | static void pcmcia_delayed_add_device(struct work_struct *work) | 638 | static int pcmcia_requery_callback(struct device *dev, void * _data) |
638 | { | ||
639 | struct pcmcia_socket *s = | ||
640 | container_of(work, struct pcmcia_socket, device_add); | ||
641 | dev_dbg(&s->dev, "adding additional device to %d\n", s->sock); | ||
642 | pcmcia_device_add(s, s->pcmcia_state.mfc_pfc); | ||
643 | s->pcmcia_state.device_add_pending = 0; | ||
644 | s->pcmcia_state.mfc_pfc = 0; | ||
645 | } | ||
646 | |||
647 | static int pcmcia_requery(struct device *dev, void * _data) | ||
648 | { | 639 | { |
649 | struct pcmcia_device *p_dev = to_pcmcia_dev(dev); | 640 | struct pcmcia_device *p_dev = to_pcmcia_dev(dev); |
650 | if (!p_dev->dev.driver) { | 641 | if (!p_dev->dev.driver) { |
@@ -655,45 +646,67 @@ static int pcmcia_requery(struct device *dev, void * _data) | |||
655 | return 0; | 646 | return 0; |
656 | } | 647 | } |
657 | 648 | ||
658 | static void pcmcia_bus_rescan(struct pcmcia_socket *skt, int new_cis) | ||
659 | { | ||
660 | int no_devices = 0; | ||
661 | int ret = 0; | ||
662 | unsigned long flags; | ||
663 | 649 | ||
664 | /* must be called with skt_mutex held */ | 650 | static void pcmcia_requery(struct pcmcia_socket *s) |
665 | dev_dbg(&skt->dev, "re-scanning socket %d\n", skt->sock); | 651 | { |
652 | int present, has_pfc; | ||
666 | 653 | ||
667 | spin_lock_irqsave(&pcmcia_dev_list_lock, flags); | 654 | mutex_lock(&s->ops_mutex); |
668 | if (list_empty(&skt->devices_list)) | 655 | present = s->pcmcia_state.present; |
669 | no_devices = 1; | 656 | mutex_unlock(&s->ops_mutex); |
670 | spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); | ||
671 | 657 | ||
672 | /* If this is because of a CIS override, start over */ | 658 | if (!present) |
673 | if (new_cis && !no_devices) | 659 | return; |
674 | pcmcia_card_remove(skt, NULL); | ||
675 | 660 | ||
676 | /* if no devices were added for this socket yet because of | 661 | if (s->functions == 0) { |
677 | * missing resource information or other trouble, we need to | 662 | pcmcia_card_add(s); |
678 | * do this now. */ | 663 | return; |
679 | if (no_devices || new_cis) { | ||
680 | ret = pcmcia_card_add(skt); | ||
681 | if (ret) | ||
682 | return; | ||
683 | } | 664 | } |
684 | 665 | ||
685 | /* some device information might have changed because of a CIS | 666 | /* some device information might have changed because of a CIS |
686 | * update or because we can finally read it correctly... so | 667 | * update or because we can finally read it correctly... so |
687 | * determine it again, overwriting old values if necessary. */ | 668 | * determine it again, overwriting old values if necessary. */ |
688 | bus_for_each_dev(&pcmcia_bus_type, NULL, NULL, pcmcia_requery); | 669 | bus_for_each_dev(&pcmcia_bus_type, NULL, NULL, pcmcia_requery_callback); |
670 | |||
671 | /* if the CIS changed, we need to check whether the number of | ||
672 | * functions changed. */ | ||
673 | if (s->fake_cis) { | ||
674 | int old_funcs, new_funcs; | ||
675 | cistpl_longlink_mfc_t mfc; | ||
676 | |||
677 | /* does this cis override add or remove functions? */ | ||
678 | old_funcs = s->functions; | ||
679 | |||
680 | if (!pccard_read_tuple(s, BIND_FN_ALL, CISTPL_LONGLINK_MFC, | ||
681 | &mfc)) | ||
682 | new_funcs = mfc.nfn; | ||
683 | else | ||
684 | new_funcs = 1; | ||
685 | if (old_funcs > new_funcs) { | ||
686 | pcmcia_card_remove(s, NULL); | ||
687 | pcmcia_card_add(s); | ||
688 | } else if (new_funcs > old_funcs) { | ||
689 | s->functions = new_funcs; | ||
690 | pcmcia_device_add(s, 1); | ||
691 | } | ||
692 | } | ||
693 | |||
694 | /* If the PCMCIA device consists of two pseudo devices, | ||
695 | * call pcmcia_device_add() -- which will fail if both | ||
696 | * devices are already registered. */ | ||
697 | mutex_lock(&s->ops_mutex); | ||
698 | has_pfc = s->pcmcia_state.has_pfc; | ||
699 | mutex_unlock(&s->ops_mutex); | ||
700 | if (has_pfc) | ||
701 | pcmcia_device_add(s, 0); | ||
689 | 702 | ||
690 | /* we re-scan all devices, not just the ones connected to this | 703 | /* we re-scan all devices, not just the ones connected to this |
691 | * socket. This does not matter, though. */ | 704 | * socket. This does not matter, though. */ |
692 | ret = bus_rescan_devices(&pcmcia_bus_type); | 705 | if (bus_rescan_devices(&pcmcia_bus_type)) |
693 | if (ret) | 706 | dev_warn(&s->dev, "rescanning the bus failed\n"); |
694 | printk(KERN_INFO "pcmcia: bus_rescan_devices failed\n"); | ||
695 | } | 707 | } |
696 | 708 | ||
709 | |||
697 | #ifdef CONFIG_PCMCIA_LOAD_CIS | 710 | #ifdef CONFIG_PCMCIA_LOAD_CIS |
698 | 711 | ||
699 | /** | 712 | /** |
@@ -710,9 +723,6 @@ static int pcmcia_load_firmware(struct pcmcia_device *dev, char * filename) | |||
710 | struct pcmcia_socket *s = dev->socket; | 723 | struct pcmcia_socket *s = dev->socket; |
711 | const struct firmware *fw; | 724 | const struct firmware *fw; |
712 | int ret = -ENOMEM; | 725 | int ret = -ENOMEM; |
713 | int no_funcs; | ||
714 | int old_funcs; | ||
715 | cistpl_longlink_mfc_t mfc; | ||
716 | 726 | ||
717 | if (!filename) | 727 | if (!filename) |
718 | return -EINVAL; | 728 | return -EINVAL; |
@@ -739,19 +749,8 @@ static int pcmcia_load_firmware(struct pcmcia_device *dev, char * filename) | |||
739 | /* update information */ | 749 | /* update information */ |
740 | pcmcia_device_query(dev); | 750 | pcmcia_device_query(dev); |
741 | 751 | ||
742 | /* does this cis override add or remove functions? */ | 752 | /* requery (as number of functions might have changed) */ |
743 | old_funcs = s->functions; | 753 | pcmcia_parse_uevents(s, PCMCIA_UEVENT_REQUERY); |
744 | |||
745 | if (!pccard_read_tuple(s, BIND_FN_ALL, CISTPL_LONGLINK_MFC, &mfc)) | ||
746 | no_funcs = mfc.nfn; | ||
747 | else | ||
748 | no_funcs = 1; | ||
749 | s->functions = no_funcs; | ||
750 | |||
751 | if (old_funcs > no_funcs) | ||
752 | pcmcia_card_remove(s, dev); | ||
753 | else if (no_funcs > old_funcs) | ||
754 | pcmcia_add_device_later(s, 1); | ||
755 | } | 754 | } |
756 | release: | 755 | release: |
757 | release_firmware(fw); | 756 | release_firmware(fw); |
@@ -818,9 +817,14 @@ static inline int pcmcia_devmatch(struct pcmcia_device *dev, | |||
818 | if (did->match_flags & PCMCIA_DEV_ID_MATCH_DEVICE_NO) { | 817 | if (did->match_flags & PCMCIA_DEV_ID_MATCH_DEVICE_NO) { |
819 | if (dev->device_no != did->device_no) | 818 | if (dev->device_no != did->device_no) |
820 | return 0; | 819 | return 0; |
820 | mutex_lock(&dev->socket->ops_mutex); | ||
821 | dev->socket->pcmcia_state.has_pfc = 1; | ||
822 | mutex_unlock(&dev->socket->ops_mutex); | ||
821 | } | 823 | } |
822 | 824 | ||
823 | if (did->match_flags & PCMCIA_DEV_ID_MATCH_FUNC_ID) { | 825 | if (did->match_flags & PCMCIA_DEV_ID_MATCH_FUNC_ID) { |
826 | int ret; | ||
827 | |||
824 | if ((!dev->has_func_id) || (dev->func_id != did->func_id)) | 828 | if ((!dev->has_func_id) || (dev->func_id != did->func_id)) |
825 | return 0; | 829 | return 0; |
826 | 830 | ||
@@ -835,10 +839,15 @@ static inline int pcmcia_devmatch(struct pcmcia_device *dev, | |||
835 | * after it has re-checked that there is no possible module | 839 | * after it has re-checked that there is no possible module |
836 | * with a prod_id/manf_id/card_id match. | 840 | * with a prod_id/manf_id/card_id match. |
837 | */ | 841 | */ |
838 | dev_dbg(&dev->dev, | 842 | mutex_lock(&dev->socket->ops_mutex); |
839 | "skipping FUNC_ID match until userspace interaction\n"); | 843 | ret = dev->allow_func_id_match; |
840 | if (!dev->allow_func_id_match) | 844 | mutex_unlock(&dev->socket->ops_mutex); |
845 | |||
846 | if (!ret) { | ||
847 | dev_dbg(&dev->dev, | ||
848 | "skipping FUNC_ID match until userspace ACK\n"); | ||
841 | return 0; | 849 | return 0; |
850 | } | ||
842 | } | 851 | } |
843 | 852 | ||
844 | if (did->match_flags & PCMCIA_DEV_ID_MATCH_FAKE_CIS) { | 853 | if (did->match_flags & PCMCIA_DEV_ID_MATCH_FAKE_CIS) { |
@@ -859,8 +868,6 @@ static inline int pcmcia_devmatch(struct pcmcia_device *dev, | |||
859 | return 0; | 868 | return 0; |
860 | } | 869 | } |
861 | 870 | ||
862 | dev_set_drvdata(&dev->dev, did); | ||
863 | |||
864 | return 1; | 871 | return 1; |
865 | } | 872 | } |
866 | 873 | ||
@@ -873,16 +880,16 @@ static int pcmcia_bus_match(struct device *dev, struct device_driver *drv) | |||
873 | struct pcmcia_dynid *dynid; | 880 | struct pcmcia_dynid *dynid; |
874 | 881 | ||
875 | /* match dynamic devices first */ | 882 | /* match dynamic devices first */ |
876 | spin_lock(&p_drv->dynids.lock); | 883 | mutex_lock(&p_drv->dynids.lock); |
877 | list_for_each_entry(dynid, &p_drv->dynids.list, node) { | 884 | list_for_each_entry(dynid, &p_drv->dynids.list, node) { |
878 | dev_dbg(dev, "trying to match to %s\n", drv->name); | 885 | dev_dbg(dev, "trying to match to %s\n", drv->name); |
879 | if (pcmcia_devmatch(p_dev, &dynid->id)) { | 886 | if (pcmcia_devmatch(p_dev, &dynid->id)) { |
880 | dev_dbg(dev, "matched to %s\n", drv->name); | 887 | dev_dbg(dev, "matched to %s\n", drv->name); |
881 | spin_unlock(&p_drv->dynids.lock); | 888 | mutex_unlock(&p_drv->dynids.lock); |
882 | return 1; | 889 | return 1; |
883 | } | 890 | } |
884 | } | 891 | } |
885 | spin_unlock(&p_drv->dynids.lock); | 892 | mutex_unlock(&p_drv->dynids.lock); |
886 | 893 | ||
887 | #ifdef CONFIG_PCMCIA_IOCTL | 894 | #ifdef CONFIG_PCMCIA_IOCTL |
888 | /* matching by cardmgr */ | 895 | /* matching by cardmgr */ |
@@ -970,13 +977,14 @@ static int runtime_suspend(struct device *dev) | |||
970 | return rc; | 977 | return rc; |
971 | } | 978 | } |
972 | 979 | ||
973 | static void runtime_resume(struct device *dev) | 980 | static int runtime_resume(struct device *dev) |
974 | { | 981 | { |
975 | int rc; | 982 | int rc; |
976 | 983 | ||
977 | down(&dev->sem); | 984 | down(&dev->sem); |
978 | rc = pcmcia_dev_resume(dev); | 985 | rc = pcmcia_dev_resume(dev); |
979 | up(&dev->sem); | 986 | up(&dev->sem); |
987 | return rc; | ||
980 | } | 988 | } |
981 | 989 | ||
982 | /************************ per-device sysfs output ***************************/ | 990 | /************************ per-device sysfs output ***************************/ |
@@ -1027,7 +1035,7 @@ static ssize_t pcmcia_store_pm_state(struct device *dev, struct device_attribute | |||
1027 | if ((!p_dev->suspended) && !strncmp(buf, "off", 3)) | 1035 | if ((!p_dev->suspended) && !strncmp(buf, "off", 3)) |
1028 | ret = runtime_suspend(dev); | 1036 | ret = runtime_suspend(dev); |
1029 | else if (p_dev->suspended && !strncmp(buf, "on", 2)) | 1037 | else if (p_dev->suspended && !strncmp(buf, "on", 2)) |
1030 | runtime_resume(dev); | 1038 | ret = runtime_resume(dev); |
1031 | 1039 | ||
1032 | return ret ? ret : count; | 1040 | return ret ? ret : count; |
1033 | } | 1041 | } |
@@ -1059,19 +1067,14 @@ static ssize_t pcmcia_store_allow_func_id_match(struct device *dev, | |||
1059 | struct device_attribute *attr, const char *buf, size_t count) | 1067 | struct device_attribute *attr, const char *buf, size_t count) |
1060 | { | 1068 | { |
1061 | struct pcmcia_device *p_dev = to_pcmcia_dev(dev); | 1069 | struct pcmcia_device *p_dev = to_pcmcia_dev(dev); |
1062 | int ret; | ||
1063 | 1070 | ||
1064 | if (!count) | 1071 | if (!count) |
1065 | return -EINVAL; | 1072 | return -EINVAL; |
1066 | 1073 | ||
1067 | mutex_lock(&p_dev->socket->skt_mutex); | 1074 | mutex_lock(&p_dev->socket->ops_mutex); |
1068 | p_dev->allow_func_id_match = 1; | 1075 | p_dev->allow_func_id_match = 1; |
1069 | mutex_unlock(&p_dev->socket->skt_mutex); | 1076 | mutex_unlock(&p_dev->socket->ops_mutex); |
1070 | 1077 | pcmcia_parse_uevents(p_dev->socket, PCMCIA_UEVENT_REQUERY); | |
1071 | ret = bus_rescan_devices(&pcmcia_bus_type); | ||
1072 | if (ret) | ||
1073 | printk(KERN_INFO "pcmcia: bus_rescan_devices failed after " | ||
1074 | "allowing func_id matches\n"); | ||
1075 | 1078 | ||
1076 | return count; | 1079 | return count; |
1077 | } | 1080 | } |
@@ -1099,8 +1102,13 @@ static int pcmcia_dev_suspend(struct device *dev, pm_message_t state) | |||
1099 | struct pcmcia_driver *p_drv = NULL; | 1102 | struct pcmcia_driver *p_drv = NULL; |
1100 | int ret = 0; | 1103 | int ret = 0; |
1101 | 1104 | ||
1102 | if (p_dev->suspended) | 1105 | mutex_lock(&p_dev->socket->ops_mutex); |
1106 | if (p_dev->suspended) { | ||
1107 | mutex_unlock(&p_dev->socket->ops_mutex); | ||
1103 | return 0; | 1108 | return 0; |
1109 | } | ||
1110 | p_dev->suspended = 1; | ||
1111 | mutex_unlock(&p_dev->socket->ops_mutex); | ||
1104 | 1112 | ||
1105 | dev_dbg(dev, "suspending\n"); | 1113 | dev_dbg(dev, "suspending\n"); |
1106 | 1114 | ||
@@ -1117,6 +1125,9 @@ static int pcmcia_dev_suspend(struct device *dev, pm_message_t state) | |||
1117 | "pcmcia: device %s (driver %s) did " | 1125 | "pcmcia: device %s (driver %s) did " |
1118 | "not want to go to sleep (%d)\n", | 1126 | "not want to go to sleep (%d)\n", |
1119 | p_dev->devname, p_drv->drv.name, ret); | 1127 | p_dev->devname, p_drv->drv.name, ret); |
1128 | mutex_lock(&p_dev->socket->ops_mutex); | ||
1129 | p_dev->suspended = 0; | ||
1130 | mutex_unlock(&p_dev->socket->ops_mutex); | ||
1120 | goto out; | 1131 | goto out; |
1121 | } | 1132 | } |
1122 | } | 1133 | } |
@@ -1127,8 +1138,6 @@ static int pcmcia_dev_suspend(struct device *dev, pm_message_t state) | |||
1127 | } | 1138 | } |
1128 | 1139 | ||
1129 | out: | 1140 | out: |
1130 | if (!ret) | ||
1131 | p_dev->suspended = 1; | ||
1132 | return ret; | 1141 | return ret; |
1133 | } | 1142 | } |
1134 | 1143 | ||
@@ -1139,8 +1148,13 @@ static int pcmcia_dev_resume(struct device *dev) | |||
1139 | struct pcmcia_driver *p_drv = NULL; | 1148 | struct pcmcia_driver *p_drv = NULL; |
1140 | int ret = 0; | 1149 | int ret = 0; |
1141 | 1150 | ||
1142 | if (!p_dev->suspended) | 1151 | mutex_lock(&p_dev->socket->ops_mutex); |
1152 | if (!p_dev->suspended) { | ||
1153 | mutex_unlock(&p_dev->socket->ops_mutex); | ||
1143 | return 0; | 1154 | return 0; |
1155 | } | ||
1156 | p_dev->suspended = 0; | ||
1157 | mutex_unlock(&p_dev->socket->ops_mutex); | ||
1144 | 1158 | ||
1145 | dev_dbg(dev, "resuming\n"); | 1159 | dev_dbg(dev, "resuming\n"); |
1146 | 1160 | ||
@@ -1161,8 +1175,6 @@ static int pcmcia_dev_resume(struct device *dev) | |||
1161 | ret = p_drv->resume(p_dev); | 1175 | ret = p_drv->resume(p_dev); |
1162 | 1176 | ||
1163 | out: | 1177 | out: |
1164 | if (!ret) | ||
1165 | p_dev->suspended = 0; | ||
1166 | return ret; | 1178 | return ret; |
1167 | } | 1179 | } |
1168 | 1180 | ||
@@ -1237,13 +1249,22 @@ static int ds_event(struct pcmcia_socket *skt, event_t event, int priority) | |||
1237 | 1249 | ||
1238 | switch (event) { | 1250 | switch (event) { |
1239 | case CS_EVENT_CARD_REMOVAL: | 1251 | case CS_EVENT_CARD_REMOVAL: |
1252 | mutex_lock(&s->ops_mutex); | ||
1240 | s->pcmcia_state.present = 0; | 1253 | s->pcmcia_state.present = 0; |
1254 | mutex_unlock(&s->ops_mutex); | ||
1241 | pcmcia_card_remove(skt, NULL); | 1255 | pcmcia_card_remove(skt, NULL); |
1242 | handle_event(skt, event); | 1256 | handle_event(skt, event); |
1257 | mutex_lock(&s->ops_mutex); | ||
1258 | destroy_cis_cache(s); | ||
1259 | mutex_unlock(&s->ops_mutex); | ||
1243 | break; | 1260 | break; |
1244 | 1261 | ||
1245 | case CS_EVENT_CARD_INSERTION: | 1262 | case CS_EVENT_CARD_INSERTION: |
1263 | mutex_lock(&s->ops_mutex); | ||
1264 | s->pcmcia_state.has_pfc = 0; | ||
1246 | s->pcmcia_state.present = 1; | 1265 | s->pcmcia_state.present = 1; |
1266 | destroy_cis_cache(s); /* to be on the safe side... */ | ||
1267 | mutex_unlock(&s->ops_mutex); | ||
1247 | pcmcia_card_add(skt); | 1268 | pcmcia_card_add(skt); |
1248 | handle_event(skt, event); | 1269 | handle_event(skt, event); |
1249 | break; | 1270 | break; |
@@ -1251,8 +1272,24 @@ static int ds_event(struct pcmcia_socket *skt, event_t event, int priority) | |||
1251 | case CS_EVENT_EJECTION_REQUEST: | 1272 | case CS_EVENT_EJECTION_REQUEST: |
1252 | break; | 1273 | break; |
1253 | 1274 | ||
1254 | case CS_EVENT_PM_SUSPEND: | ||
1255 | case CS_EVENT_PM_RESUME: | 1275 | case CS_EVENT_PM_RESUME: |
1276 | if (verify_cis_cache(skt) != 0) { | ||
1277 | dev_dbg(&skt->dev, "cis mismatch - different card\n"); | ||
1278 | /* first, remove the card */ | ||
1279 | ds_event(skt, CS_EVENT_CARD_REMOVAL, CS_EVENT_PRI_HIGH); | ||
1280 | mutex_lock(&s->ops_mutex); | ||
1281 | destroy_cis_cache(skt); | ||
1282 | kfree(skt->fake_cis); | ||
1283 | skt->fake_cis = NULL; | ||
1284 | mutex_unlock(&s->ops_mutex); | ||
1285 | /* now, add the new card */ | ||
1286 | ds_event(skt, CS_EVENT_CARD_INSERTION, | ||
1287 | CS_EVENT_PRI_LOW); | ||
1288 | } | ||
1289 | handle_event(skt, event); | ||
1290 | break; | ||
1291 | |||
1292 | case CS_EVENT_PM_SUSPEND: | ||
1256 | case CS_EVENT_RESET_PHYSICAL: | 1293 | case CS_EVENT_RESET_PHYSICAL: |
1257 | case CS_EVENT_CARD_RESET: | 1294 | case CS_EVENT_CARD_RESET: |
1258 | default: | 1295 | default: |
@@ -1275,9 +1312,13 @@ struct pcmcia_device *pcmcia_dev_present(struct pcmcia_device *_p_dev) | |||
1275 | if (!p_dev) | 1312 | if (!p_dev) |
1276 | return NULL; | 1313 | return NULL; |
1277 | 1314 | ||
1315 | mutex_lock(&p_dev->socket->ops_mutex); | ||
1278 | if (!p_dev->socket->pcmcia_state.present) | 1316 | if (!p_dev->socket->pcmcia_state.present) |
1279 | goto out; | 1317 | goto out; |
1280 | 1318 | ||
1319 | if (p_dev->socket->pcmcia_state.dead) | ||
1320 | goto out; | ||
1321 | |||
1281 | if (p_dev->_removed) | 1322 | if (p_dev->_removed) |
1282 | goto out; | 1323 | goto out; |
1283 | 1324 | ||
@@ -1286,6 +1327,7 @@ struct pcmcia_device *pcmcia_dev_present(struct pcmcia_device *_p_dev) | |||
1286 | 1327 | ||
1287 | ret = p_dev; | 1328 | ret = p_dev; |
1288 | out: | 1329 | out: |
1330 | mutex_unlock(&p_dev->socket->ops_mutex); | ||
1289 | pcmcia_put_dev(p_dev); | 1331 | pcmcia_put_dev(p_dev); |
1290 | return ret; | 1332 | return ret; |
1291 | } | 1333 | } |
@@ -1295,7 +1337,8 @@ EXPORT_SYMBOL(pcmcia_dev_present); | |||
1295 | static struct pcmcia_callback pcmcia_bus_callback = { | 1337 | static struct pcmcia_callback pcmcia_bus_callback = { |
1296 | .owner = THIS_MODULE, | 1338 | .owner = THIS_MODULE, |
1297 | .event = ds_event, | 1339 | .event = ds_event, |
1298 | .requery = pcmcia_bus_rescan, | 1340 | .requery = pcmcia_requery, |
1341 | .validate = pccard_validate_cis, | ||
1299 | .suspend = pcmcia_bus_suspend, | 1342 | .suspend = pcmcia_bus_suspend, |
1300 | .resume = pcmcia_bus_resume, | 1343 | .resume = pcmcia_bus_resume, |
1301 | }; | 1344 | }; |
@@ -1313,17 +1356,17 @@ static int __devinit pcmcia_bus_add_socket(struct device *dev, | |||
1313 | return -ENODEV; | 1356 | return -ENODEV; |
1314 | } | 1357 | } |
1315 | 1358 | ||
1316 | /* | 1359 | ret = sysfs_create_bin_file(&dev->kobj, &pccard_cis_attr); |
1317 | * Ugly. But we want to wait for the socket threads to have started up. | 1360 | if (ret) { |
1318 | * We really should let the drivers themselves drive some of this.. | 1361 | dev_printk(KERN_ERR, dev, "PCMCIA registration failed\n"); |
1319 | */ | 1362 | pcmcia_put_socket(socket); |
1320 | msleep(250); | 1363 | return ret; |
1364 | } | ||
1321 | 1365 | ||
1322 | #ifdef CONFIG_PCMCIA_IOCTL | 1366 | #ifdef CONFIG_PCMCIA_IOCTL |
1323 | init_waitqueue_head(&socket->queue); | 1367 | init_waitqueue_head(&socket->queue); |
1324 | #endif | 1368 | #endif |
1325 | INIT_LIST_HEAD(&socket->devices_list); | 1369 | INIT_LIST_HEAD(&socket->devices_list); |
1326 | INIT_WORK(&socket->device_add, pcmcia_delayed_add_device); | ||
1327 | memset(&socket->pcmcia_state, 0, sizeof(u8)); | 1370 | memset(&socket->pcmcia_state, 0, sizeof(u8)); |
1328 | socket->device_count = 0; | 1371 | socket->device_count = 0; |
1329 | 1372 | ||
@@ -1345,14 +1388,20 @@ static void pcmcia_bus_remove_socket(struct device *dev, | |||
1345 | if (!socket) | 1388 | if (!socket) |
1346 | return; | 1389 | return; |
1347 | 1390 | ||
1391 | mutex_lock(&socket->ops_mutex); | ||
1348 | socket->pcmcia_state.dead = 1; | 1392 | socket->pcmcia_state.dead = 1; |
1393 | mutex_unlock(&socket->ops_mutex); | ||
1394 | |||
1349 | pccard_register_pcmcia(socket, NULL); | 1395 | pccard_register_pcmcia(socket, NULL); |
1350 | 1396 | ||
1351 | /* unregister any unbound devices */ | 1397 | /* unregister any unbound devices */ |
1352 | mutex_lock(&socket->skt_mutex); | 1398 | mutex_lock(&socket->skt_mutex); |
1353 | pcmcia_card_remove(socket, NULL); | 1399 | pcmcia_card_remove(socket, NULL); |
1400 | release_cis_mem(socket); | ||
1354 | mutex_unlock(&socket->skt_mutex); | 1401 | mutex_unlock(&socket->skt_mutex); |
1355 | 1402 | ||
1403 | sysfs_remove_bin_file(&dev->kobj, &pccard_cis_attr); | ||
1404 | |||
1356 | pcmcia_put_socket(socket); | 1405 | pcmcia_put_socket(socket); |
1357 | 1406 | ||
1358 | return; | 1407 | return; |
@@ -1383,8 +1432,6 @@ static int __init init_pcmcia_bus(void) | |||
1383 | { | 1432 | { |
1384 | int ret; | 1433 | int ret; |
1385 | 1434 | ||
1386 | spin_lock_init(&pcmcia_dev_list_lock); | ||
1387 | |||
1388 | ret = bus_register(&pcmcia_bus_type); | 1435 | ret = bus_register(&pcmcia_bus_type); |
1389 | if (ret < 0) { | 1436 | if (ret < 0) { |
1390 | printk(KERN_WARNING "pcmcia: bus_register error: %d\n", ret); | 1437 | printk(KERN_WARNING "pcmcia: bus_register error: %d\n", ret); |
diff --git a/drivers/pcmcia/electra_cf.c b/drivers/pcmcia/electra_cf.c index d187ba4c5e0e..89cfddca089a 100644 --- a/drivers/pcmcia/electra_cf.c +++ b/drivers/pcmcia/electra_cf.c | |||
@@ -347,7 +347,7 @@ static int __devexit electra_cf_remove(struct of_device *ofdev) | |||
347 | return 0; | 347 | return 0; |
348 | } | 348 | } |
349 | 349 | ||
350 | static struct of_device_id electra_cf_match[] = { | 350 | static const struct of_device_id electra_cf_match[] = { |
351 | { | 351 | { |
352 | .compatible = "electra-cf", | 352 | .compatible = "electra-cf", |
353 | }, | 353 | }, |
diff --git a/drivers/pcmcia/i82365.h b/drivers/pcmcia/i82365.h index 622860c689d9..849ef1b5d687 100644 --- a/drivers/pcmcia/i82365.h +++ b/drivers/pcmcia/i82365.h | |||
@@ -77,8 +77,8 @@ | |||
77 | #define I365_VPP2_5V 0x04 /* Vpp2 = 5.0v */ | 77 | #define I365_VPP2_5V 0x04 /* Vpp2 = 5.0v */ |
78 | #define I365_VPP2_12V 0x08 /* Vpp2 = 12.0v */ | 78 | #define I365_VPP2_12V 0x08 /* Vpp2 = 12.0v */ |
79 | #define I365_VPP1_MASK 0x03 /* Mask for turning off Vpp1 */ | 79 | #define I365_VPP1_MASK 0x03 /* Mask for turning off Vpp1 */ |
80 | #define I365_VPP1_5V 0x01 /* Vpp2 = 5.0v */ | 80 | #define I365_VPP1_5V 0x01 /* Vpp1 = 5.0v */ |
81 | #define I365_VPP1_12V 0x02 /* Vpp2 = 12.0v */ | 81 | #define I365_VPP1_12V 0x02 /* Vpp1 = 12.0v */ |
82 | 82 | ||
83 | /* Flags for I365_INTCTL */ | 83 | /* Flags for I365_INTCTL */ |
84 | #define I365_RING_ENA 0x80 | 84 | #define I365_RING_ENA 0x80 |
diff --git a/drivers/pcmcia/m32r_cfc.c b/drivers/pcmcia/m32r_cfc.c index 26a621c9e2fc..0ece2cd4a85e 100644 --- a/drivers/pcmcia/m32r_cfc.c +++ b/drivers/pcmcia/m32r_cfc.c | |||
@@ -764,7 +764,7 @@ static int __init init_m32r_pcc(void) | |||
764 | for (i = 0 ; i < pcc_sockets ; i++) { | 764 | for (i = 0 ; i < pcc_sockets ; i++) { |
765 | socket[i].socket.dev.parent = &pcc_device.dev; | 765 | socket[i].socket.dev.parent = &pcc_device.dev; |
766 | socket[i].socket.ops = &pcc_operations; | 766 | socket[i].socket.ops = &pcc_operations; |
767 | socket[i].socket.resource_ops = &pccard_nonstatic_ops; | 767 | socket[i].socket.resource_ops = &pccard_static_ops; |
768 | socket[i].socket.owner = THIS_MODULE; | 768 | socket[i].socket.owner = THIS_MODULE; |
769 | socket[i].number = i; | 769 | socket[i].number = i; |
770 | ret = pcmcia_register_socket(&socket[i].socket); | 770 | ret = pcmcia_register_socket(&socket[i].socket); |
diff --git a/drivers/pcmcia/m8xx_pcmcia.c b/drivers/pcmcia/m8xx_pcmcia.c index 7f79c4e169ae..61c215918128 100644 --- a/drivers/pcmcia/m8xx_pcmcia.c +++ b/drivers/pcmcia/m8xx_pcmcia.c | |||
@@ -1233,7 +1233,7 @@ static int __init m8xx_probe(struct of_device *ofdev, | |||
1233 | socket[i].socket.io_offset = 0; | 1233 | socket[i].socket.io_offset = 0; |
1234 | socket[i].socket.pci_irq = pcmcia_schlvl; | 1234 | socket[i].socket.pci_irq = pcmcia_schlvl; |
1235 | socket[i].socket.ops = &m8xx_services; | 1235 | socket[i].socket.ops = &m8xx_services; |
1236 | socket[i].socket.resource_ops = &pccard_nonstatic_ops; | 1236 | socket[i].socket.resource_ops = &pccard_iodyn_ops; |
1237 | socket[i].socket.cb_dev = NULL; | 1237 | socket[i].socket.cb_dev = NULL; |
1238 | socket[i].socket.dev.parent = &ofdev->dev; | 1238 | socket[i].socket.dev.parent = &ofdev->dev; |
1239 | socket[i].pcmcia = pcmcia; | 1239 | socket[i].pcmcia = pcmcia; |
@@ -1303,7 +1303,7 @@ static int m8xx_resume(struct platform_device *pdev) | |||
1303 | #define m8xx_resume NULL | 1303 | #define m8xx_resume NULL |
1304 | #endif | 1304 | #endif |
1305 | 1305 | ||
1306 | static struct of_device_id m8xx_pcmcia_match[] = { | 1306 | static const struct of_device_id m8xx_pcmcia_match[] = { |
1307 | { | 1307 | { |
1308 | .type = "pcmcia", | 1308 | .type = "pcmcia", |
1309 | .compatible = "fsl,pq-pcmcia", | 1309 | .compatible = "fsl,pq-pcmcia", |
diff --git a/drivers/pcmcia/o2micro.h b/drivers/pcmcia/o2micro.h index 624442fc0d35..e74bebac2695 100644 --- a/drivers/pcmcia/o2micro.h +++ b/drivers/pcmcia/o2micro.h | |||
@@ -116,13 +116,12 @@ static int o2micro_override(struct yenta_socket *socket) | |||
116 | * from Eric Still, 02Micro. | 116 | * from Eric Still, 02Micro. |
117 | */ | 117 | */ |
118 | u8 a, b; | 118 | u8 a, b; |
119 | bool use_speedup; | ||
119 | 120 | ||
120 | if (PCI_FUNC(socket->dev->devfn) == 0) { | 121 | if (PCI_FUNC(socket->dev->devfn) == 0) { |
121 | a = config_readb(socket, O2_RESERVED1); | 122 | a = config_readb(socket, O2_RESERVED1); |
122 | b = config_readb(socket, O2_RESERVED2); | 123 | b = config_readb(socket, O2_RESERVED2); |
123 | 124 | dev_dbg(&socket->dev->dev, "O2: 0x94/0xD4: %02x/%02x\n", a, b); | |
124 | dev_printk(KERN_INFO, &socket->dev->dev, | ||
125 | "O2: res at 0x94/0xD4: %02x/%02x\n", a, b); | ||
126 | 125 | ||
127 | switch (socket->dev->device) { | 126 | switch (socket->dev->device) { |
128 | /* | 127 | /* |
@@ -135,23 +134,37 @@ static int o2micro_override(struct yenta_socket *socket) | |||
135 | case PCI_DEVICE_ID_O2_6812: | 134 | case PCI_DEVICE_ID_O2_6812: |
136 | case PCI_DEVICE_ID_O2_6832: | 135 | case PCI_DEVICE_ID_O2_6832: |
137 | case PCI_DEVICE_ID_O2_6836: | 136 | case PCI_DEVICE_ID_O2_6836: |
138 | case PCI_DEVICE_ID_O2_6933: | 137 | case PCI_DEVICE_ID_O2_6933: |
139 | dev_printk(KERN_INFO, &socket->dev->dev, | 138 | use_speedup = false; |
140 | "Yenta O2: old bridge, disabling read " | ||
141 | "prefetch/write burst\n"); | ||
142 | config_writeb(socket, O2_RESERVED1, | ||
143 | a & ~(O2_RES_READ_PREFETCH | O2_RES_WRITE_BURST)); | ||
144 | config_writeb(socket, O2_RESERVED2, | ||
145 | b & ~(O2_RES_READ_PREFETCH | O2_RES_WRITE_BURST)); | ||
146 | break; | 139 | break; |
147 | |||
148 | default: | 140 | default: |
149 | dev_printk(KERN_INFO , &socket->dev->dev, | 141 | use_speedup = true; |
150 | "O2: enabling read prefetch/write burst\n"); | 142 | break; |
143 | } | ||
144 | |||
145 | /* the user may override our decision */ | ||
146 | if (strcasecmp(o2_speedup, "on") == 0) | ||
147 | use_speedup = true; | ||
148 | else if (strcasecmp(o2_speedup, "off") == 0) | ||
149 | use_speedup = false; | ||
150 | else if (strcasecmp(o2_speedup, "default") != 0) | ||
151 | dev_warn(&socket->dev->dev, | ||
152 | "O2: Unknown parameter, using 'default'"); | ||
153 | |||
154 | if (use_speedup) { | ||
155 | dev_info(&socket->dev->dev, | ||
156 | "O2: enabling read prefetch/write burst\n"); | ||
157 | config_writeb(socket, O2_RESERVED1, | ||
158 | a | O2_RES_READ_PREFETCH | O2_RES_WRITE_BURST); | ||
159 | config_writeb(socket, O2_RESERVED2, | ||
160 | b | O2_RES_READ_PREFETCH | O2_RES_WRITE_BURST); | ||
161 | } else { | ||
162 | dev_info(&socket->dev->dev, | ||
163 | "O2: disabling read prefetch/write burst\n"); | ||
151 | config_writeb(socket, O2_RESERVED1, | 164 | config_writeb(socket, O2_RESERVED1, |
152 | a | O2_RES_READ_PREFETCH | O2_RES_WRITE_BURST); | 165 | a & ~(O2_RES_READ_PREFETCH | O2_RES_WRITE_BURST)); |
153 | config_writeb(socket, O2_RESERVED2, | 166 | config_writeb(socket, O2_RESERVED2, |
154 | b | O2_RES_READ_PREFETCH | O2_RES_WRITE_BURST); | 167 | b & ~(O2_RES_READ_PREFETCH | O2_RES_WRITE_BURST)); |
155 | } | 168 | } |
156 | } | 169 | } |
157 | 170 | ||
diff --git a/drivers/pcmcia/omap_cf.c b/drivers/pcmcia/omap_cf.c index 663781d20129..3ef991552398 100644 --- a/drivers/pcmcia/omap_cf.c +++ b/drivers/pcmcia/omap_cf.c | |||
@@ -71,8 +71,6 @@ struct omap_cf_socket { | |||
71 | 71 | ||
72 | #define POLL_INTERVAL (2 * HZ) | 72 | #define POLL_INTERVAL (2 * HZ) |
73 | 73 | ||
74 | #define SZ_2K (2 * SZ_1K) | ||
75 | |||
76 | /*--------------------------------------------------------------------------*/ | 74 | /*--------------------------------------------------------------------------*/ |
77 | 75 | ||
78 | static int omap_cf_ss_init(struct pcmcia_socket *s) | 76 | static int omap_cf_ss_init(struct pcmcia_socket *s) |
diff --git a/drivers/pcmcia/pcmcia_ioctl.c b/drivers/pcmcia/pcmcia_ioctl.c index f73fd5beaa37..13a7132cf688 100644 --- a/drivers/pcmcia/pcmcia_ioctl.c +++ b/drivers/pcmcia/pcmcia_ioctl.c | |||
@@ -62,16 +62,15 @@ static struct pcmcia_device *get_pcmcia_device(struct pcmcia_socket *s, | |||
62 | unsigned int function) | 62 | unsigned int function) |
63 | { | 63 | { |
64 | struct pcmcia_device *p_dev = NULL; | 64 | struct pcmcia_device *p_dev = NULL; |
65 | unsigned long flags; | ||
66 | 65 | ||
67 | spin_lock_irqsave(&pcmcia_dev_list_lock, flags); | 66 | mutex_lock(&s->ops_mutex); |
68 | list_for_each_entry(p_dev, &s->devices_list, socket_device_list) { | 67 | list_for_each_entry(p_dev, &s->devices_list, socket_device_list) { |
69 | if (p_dev->func == function) { | 68 | if (p_dev->func == function) { |
70 | spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); | 69 | mutex_unlock(&s->ops_mutex); |
71 | return pcmcia_get_dev(p_dev); | 70 | return pcmcia_get_dev(p_dev); |
72 | } | 71 | } |
73 | } | 72 | } |
74 | spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); | 73 | mutex_unlock(&s->ops_mutex); |
75 | return NULL; | 74 | return NULL; |
76 | } | 75 | } |
77 | 76 | ||
@@ -169,7 +168,6 @@ static int pcmcia_adjust_resource_info(adjust_t *adj) | |||
169 | { | 168 | { |
170 | struct pcmcia_socket *s; | 169 | struct pcmcia_socket *s; |
171 | int ret = -ENOSYS; | 170 | int ret = -ENOSYS; |
172 | unsigned long flags; | ||
173 | 171 | ||
174 | down_read(&pcmcia_socket_list_rwsem); | 172 | down_read(&pcmcia_socket_list_rwsem); |
175 | list_for_each_entry(s, &pcmcia_socket_list, socket_list) { | 173 | list_for_each_entry(s, &pcmcia_socket_list, socket_list) { |
@@ -182,14 +180,13 @@ static int pcmcia_adjust_resource_info(adjust_t *adj) | |||
182 | 180 | ||
183 | /* you can't use the old interface if the new | 181 | /* you can't use the old interface if the new |
184 | * one was used before */ | 182 | * one was used before */ |
185 | spin_lock_irqsave(&s->lock, flags); | 183 | mutex_lock(&s->ops_mutex); |
186 | if ((s->resource_setup_new) && | 184 | if ((s->resource_setup_new) && |
187 | !(s->resource_setup_old)) { | 185 | !(s->resource_setup_old)) { |
188 | spin_unlock_irqrestore(&s->lock, flags); | 186 | mutex_unlock(&s->ops_mutex); |
189 | continue; | 187 | continue; |
190 | } else if (!(s->resource_setup_old)) | 188 | } else if (!(s->resource_setup_old)) |
191 | s->resource_setup_old = 1; | 189 | s->resource_setup_old = 1; |
192 | spin_unlock_irqrestore(&s->lock, flags); | ||
193 | 190 | ||
194 | switch (adj->Resource) { | 191 | switch (adj->Resource) { |
195 | case RES_MEMORY_RANGE: | 192 | case RES_MEMORY_RANGE: |
@@ -208,10 +205,9 @@ static int pcmcia_adjust_resource_info(adjust_t *adj) | |||
208 | * last call to adjust_resource_info, we | 205 | * last call to adjust_resource_info, we |
209 | * always need to assume this is the latest | 206 | * always need to assume this is the latest |
210 | * one... */ | 207 | * one... */ |
211 | spin_lock_irqsave(&s->lock, flags); | ||
212 | s->resource_setup_done = 1; | 208 | s->resource_setup_done = 1; |
213 | spin_unlock_irqrestore(&s->lock, flags); | ||
214 | } | 209 | } |
210 | mutex_unlock(&s->ops_mutex); | ||
215 | } | 211 | } |
216 | } | 212 | } |
217 | up_read(&pcmcia_socket_list_rwsem); | 213 | up_read(&pcmcia_socket_list_rwsem); |
@@ -470,7 +466,6 @@ static int bind_request(struct pcmcia_socket *s, bind_info_t *bind_info) | |||
470 | struct pcmcia_driver *p_drv; | 466 | struct pcmcia_driver *p_drv; |
471 | struct pcmcia_device *p_dev; | 467 | struct pcmcia_device *p_dev; |
472 | int ret = 0; | 468 | int ret = 0; |
473 | unsigned long flags; | ||
474 | 469 | ||
475 | s = pcmcia_get_socket(s); | 470 | s = pcmcia_get_socket(s); |
476 | if (!s) | 471 | if (!s) |
@@ -490,7 +485,7 @@ static int bind_request(struct pcmcia_socket *s, bind_info_t *bind_info) | |||
490 | goto err_put_driver; | 485 | goto err_put_driver; |
491 | } | 486 | } |
492 | 487 | ||
493 | spin_lock_irqsave(&pcmcia_dev_list_lock, flags); | 488 | mutex_lock(&s->ops_mutex); |
494 | list_for_each_entry(p_dev, &s->devices_list, socket_device_list) { | 489 | list_for_each_entry(p_dev, &s->devices_list, socket_device_list) { |
495 | if (p_dev->func == bind_info->function) { | 490 | if (p_dev->func == bind_info->function) { |
496 | if ((p_dev->dev.driver == &p_drv->drv)) { | 491 | if ((p_dev->dev.driver == &p_drv->drv)) { |
@@ -499,7 +494,7 @@ static int bind_request(struct pcmcia_socket *s, bind_info_t *bind_info) | |||
499 | * registered, and it was registered | 494 | * registered, and it was registered |
500 | * by userspace before, we need to | 495 | * by userspace before, we need to |
501 | * return the "instance". */ | 496 | * return the "instance". */ |
502 | spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); | 497 | mutex_unlock(&s->ops_mutex); |
503 | bind_info->instance = p_dev; | 498 | bind_info->instance = p_dev; |
504 | ret = -EBUSY; | 499 | ret = -EBUSY; |
505 | goto err_put_module; | 500 | goto err_put_module; |
@@ -507,7 +502,7 @@ static int bind_request(struct pcmcia_socket *s, bind_info_t *bind_info) | |||
507 | /* the correct driver managed to bind | 502 | /* the correct driver managed to bind |
508 | * itself magically to the correct | 503 | * itself magically to the correct |
509 | * device. */ | 504 | * device. */ |
510 | spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); | 505 | mutex_unlock(&s->ops_mutex); |
511 | p_dev->cardmgr = p_drv; | 506 | p_dev->cardmgr = p_drv; |
512 | ret = 0; | 507 | ret = 0; |
513 | goto err_put_module; | 508 | goto err_put_module; |
@@ -516,12 +511,12 @@ static int bind_request(struct pcmcia_socket *s, bind_info_t *bind_info) | |||
516 | /* there's already a device available where | 511 | /* there's already a device available where |
517 | * no device has been bound to yet. So we don't | 512 | * no device has been bound to yet. So we don't |
518 | * need to register a device! */ | 513 | * need to register a device! */ |
519 | spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); | 514 | mutex_unlock(&s->ops_mutex); |
520 | goto rescan; | 515 | goto rescan; |
521 | } | 516 | } |
522 | } | 517 | } |
523 | } | 518 | } |
524 | spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); | 519 | mutex_unlock(&s->ops_mutex); |
525 | 520 | ||
526 | p_dev = pcmcia_device_add(s, bind_info->function); | 521 | p_dev = pcmcia_device_add(s, bind_info->function); |
527 | if (!p_dev) { | 522 | if (!p_dev) { |
@@ -578,7 +573,6 @@ static int get_device_info(struct pcmcia_socket *s, bind_info_t *bind_info, int | |||
578 | dev_node_t *node; | 573 | dev_node_t *node; |
579 | struct pcmcia_device *p_dev; | 574 | struct pcmcia_device *p_dev; |
580 | struct pcmcia_driver *p_drv; | 575 | struct pcmcia_driver *p_drv; |
581 | unsigned long flags; | ||
582 | int ret = 0; | 576 | int ret = 0; |
583 | 577 | ||
584 | #ifdef CONFIG_CARDBUS | 578 | #ifdef CONFIG_CARDBUS |
@@ -617,7 +611,7 @@ static int get_device_info(struct pcmcia_socket *s, bind_info_t *bind_info, int | |||
617 | } | 611 | } |
618 | #endif | 612 | #endif |
619 | 613 | ||
620 | spin_lock_irqsave(&pcmcia_dev_list_lock, flags); | 614 | mutex_lock(&s->ops_mutex); |
621 | list_for_each_entry(p_dev, &s->devices_list, socket_device_list) { | 615 | list_for_each_entry(p_dev, &s->devices_list, socket_device_list) { |
622 | if (p_dev->func == bind_info->function) { | 616 | if (p_dev->func == bind_info->function) { |
623 | p_dev = pcmcia_get_dev(p_dev); | 617 | p_dev = pcmcia_get_dev(p_dev); |
@@ -626,11 +620,11 @@ static int get_device_info(struct pcmcia_socket *s, bind_info_t *bind_info, int | |||
626 | goto found; | 620 | goto found; |
627 | } | 621 | } |
628 | } | 622 | } |
629 | spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); | 623 | mutex_unlock(&s->ops_mutex); |
630 | return -ENODEV; | 624 | return -ENODEV; |
631 | 625 | ||
632 | found: | 626 | found: |
633 | spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); | 627 | mutex_unlock(&s->ops_mutex); |
634 | 628 | ||
635 | p_drv = to_pcmcia_drv(p_dev->dev.driver); | 629 | p_drv = to_pcmcia_drv(p_dev->dev.driver); |
636 | if (p_drv && !p_dev->_locked) { | 630 | if (p_drv && !p_dev->_locked) { |
@@ -931,16 +925,16 @@ static int ds_ioctl(struct inode *inode, struct file *file, | |||
931 | ret = pccard_validate_cis(s, &buf->cisinfo.Chains); | 925 | ret = pccard_validate_cis(s, &buf->cisinfo.Chains); |
932 | break; | 926 | break; |
933 | case DS_SUSPEND_CARD: | 927 | case DS_SUSPEND_CARD: |
934 | ret = pcmcia_suspend_card(s); | 928 | pcmcia_parse_uevents(s, PCMCIA_UEVENT_SUSPEND); |
935 | break; | 929 | break; |
936 | case DS_RESUME_CARD: | 930 | case DS_RESUME_CARD: |
937 | ret = pcmcia_resume_card(s); | 931 | pcmcia_parse_uevents(s, PCMCIA_UEVENT_RESUME); |
938 | break; | 932 | break; |
939 | case DS_EJECT_CARD: | 933 | case DS_EJECT_CARD: |
940 | err = pcmcia_eject_card(s); | 934 | pcmcia_parse_uevents(s, PCMCIA_UEVENT_EJECT); |
941 | break; | 935 | break; |
942 | case DS_INSERT_CARD: | 936 | case DS_INSERT_CARD: |
943 | err = pcmcia_insert_card(s); | 937 | pcmcia_parse_uevents(s, PCMCIA_UEVENT_INSERT); |
944 | break; | 938 | break; |
945 | case DS_ACCESS_CONFIGURATION_REGISTER: | 939 | case DS_ACCESS_CONFIGURATION_REGISTER: |
946 | if ((buf->conf_reg.Action == CS_WRITE) && !capable(CAP_SYS_ADMIN)) { | 940 | if ((buf->conf_reg.Action == CS_WRITE) && !capable(CAP_SYS_ADMIN)) { |
diff --git a/drivers/pcmcia/pcmcia_resource.c b/drivers/pcmcia/pcmcia_resource.c index d5db95644b64..b2df04199a21 100644 --- a/drivers/pcmcia/pcmcia_resource.c +++ b/drivers/pcmcia/pcmcia_resource.c | |||
@@ -43,6 +43,39 @@ module_param(io_speed, int, 0444); | |||
43 | static u8 pcmcia_used_irq[NR_IRQS]; | 43 | static u8 pcmcia_used_irq[NR_IRQS]; |
44 | #endif | 44 | #endif |
45 | 45 | ||
46 | static int pcmcia_adjust_io_region(struct resource *res, unsigned long start, | ||
47 | unsigned long end, struct pcmcia_socket *s) | ||
48 | { | ||
49 | if (s->resource_ops->adjust_io_region) | ||
50 | return s->resource_ops->adjust_io_region(res, start, end, s); | ||
51 | return -ENOMEM; | ||
52 | } | ||
53 | |||
54 | static struct resource *pcmcia_find_io_region(unsigned long base, int num, | ||
55 | unsigned long align, | ||
56 | struct pcmcia_socket *s) | ||
57 | { | ||
58 | if (s->resource_ops->find_io) | ||
59 | return s->resource_ops->find_io(base, num, align, s); | ||
60 | return NULL; | ||
61 | } | ||
62 | |||
63 | int pcmcia_validate_mem(struct pcmcia_socket *s) | ||
64 | { | ||
65 | if (s->resource_ops->validate_mem) | ||
66 | return s->resource_ops->validate_mem(s); | ||
67 | /* if there is no callback, we can assume that everything is OK */ | ||
68 | return 0; | ||
69 | } | ||
70 | |||
71 | struct resource *pcmcia_find_mem_region(u_long base, u_long num, u_long align, | ||
72 | int low, struct pcmcia_socket *s) | ||
73 | { | ||
74 | if (s->resource_ops->find_mem) | ||
75 | return s->resource_ops->find_mem(base, num, align, low, s); | ||
76 | return NULL; | ||
77 | } | ||
78 | |||
46 | 79 | ||
47 | /** alloc_io_space | 80 | /** alloc_io_space |
48 | * | 81 | * |
@@ -158,14 +191,18 @@ int pcmcia_access_configuration_register(struct pcmcia_device *p_dev, | |||
158 | return -EINVAL; | 191 | return -EINVAL; |
159 | 192 | ||
160 | s = p_dev->socket; | 193 | s = p_dev->socket; |
194 | |||
195 | mutex_lock(&s->ops_mutex); | ||
161 | c = p_dev->function_config; | 196 | c = p_dev->function_config; |
162 | 197 | ||
163 | if (!(c->state & CONFIG_LOCKED)) { | 198 | if (!(c->state & CONFIG_LOCKED)) { |
164 | dev_dbg(&s->dev, "Configuration isnt't locked\n"); | 199 | dev_dbg(&s->dev, "Configuration isnt't locked\n"); |
200 | mutex_unlock(&s->ops_mutex); | ||
165 | return -EACCES; | 201 | return -EACCES; |
166 | } | 202 | } |
167 | 203 | ||
168 | addr = (c->ConfigBase + reg->Offset) >> 1; | 204 | addr = (c->ConfigBase + reg->Offset) >> 1; |
205 | mutex_unlock(&s->ops_mutex); | ||
169 | 206 | ||
170 | switch (reg->Action) { | 207 | switch (reg->Action) { |
171 | case CS_READ: | 208 | case CS_READ: |
@@ -190,6 +227,7 @@ int pcmcia_map_mem_page(struct pcmcia_device *p_dev, window_handle_t wh, | |||
190 | memreq_t *req) | 227 | memreq_t *req) |
191 | { | 228 | { |
192 | struct pcmcia_socket *s = p_dev->socket; | 229 | struct pcmcia_socket *s = p_dev->socket; |
230 | int ret; | ||
193 | 231 | ||
194 | wh--; | 232 | wh--; |
195 | if (wh >= MAX_WIN) | 233 | if (wh >= MAX_WIN) |
@@ -198,12 +236,13 @@ int pcmcia_map_mem_page(struct pcmcia_device *p_dev, window_handle_t wh, | |||
198 | dev_dbg(&s->dev, "failure: requested page is zero\n"); | 236 | dev_dbg(&s->dev, "failure: requested page is zero\n"); |
199 | return -EINVAL; | 237 | return -EINVAL; |
200 | } | 238 | } |
239 | mutex_lock(&s->ops_mutex); | ||
201 | s->win[wh].card_start = req->CardOffset; | 240 | s->win[wh].card_start = req->CardOffset; |
202 | if (s->ops->set_mem_map(s, &s->win[wh]) != 0) { | 241 | ret = s->ops->set_mem_map(s, &s->win[wh]); |
203 | dev_dbg(&s->dev, "failed to set_mem_map\n"); | 242 | if (ret) |
204 | return -EIO; | 243 | dev_warn(&s->dev, "failed to set_mem_map\n"); |
205 | } | 244 | mutex_unlock(&s->ops_mutex); |
206 | return 0; | 245 | return ret; |
207 | } /* pcmcia_map_mem_page */ | 246 | } /* pcmcia_map_mem_page */ |
208 | EXPORT_SYMBOL(pcmcia_map_mem_page); | 247 | EXPORT_SYMBOL(pcmcia_map_mem_page); |
209 | 248 | ||
@@ -219,14 +258,18 @@ int pcmcia_modify_configuration(struct pcmcia_device *p_dev, | |||
219 | config_t *c; | 258 | config_t *c; |
220 | 259 | ||
221 | s = p_dev->socket; | 260 | s = p_dev->socket; |
261 | |||
262 | mutex_lock(&s->ops_mutex); | ||
222 | c = p_dev->function_config; | 263 | c = p_dev->function_config; |
223 | 264 | ||
224 | if (!(s->state & SOCKET_PRESENT)) { | 265 | if (!(s->state & SOCKET_PRESENT)) { |
225 | dev_dbg(&s->dev, "No card present\n"); | 266 | dev_dbg(&s->dev, "No card present\n"); |
267 | mutex_unlock(&s->ops_mutex); | ||
226 | return -ENODEV; | 268 | return -ENODEV; |
227 | } | 269 | } |
228 | if (!(c->state & CONFIG_LOCKED)) { | 270 | if (!(c->state & CONFIG_LOCKED)) { |
229 | dev_dbg(&s->dev, "Configuration isnt't locked\n"); | 271 | dev_dbg(&s->dev, "Configuration isnt't locked\n"); |
272 | mutex_unlock(&s->ops_mutex); | ||
230 | return -EACCES; | 273 | return -EACCES; |
231 | } | 274 | } |
232 | 275 | ||
@@ -251,10 +294,12 @@ int pcmcia_modify_configuration(struct pcmcia_device *p_dev, | |||
251 | (mod->Attributes & CONF_VPP2_CHANGE_VALID)) { | 294 | (mod->Attributes & CONF_VPP2_CHANGE_VALID)) { |
252 | if (mod->Vpp1 != mod->Vpp2) { | 295 | if (mod->Vpp1 != mod->Vpp2) { |
253 | dev_dbg(&s->dev, "Vpp1 and Vpp2 must be the same\n"); | 296 | dev_dbg(&s->dev, "Vpp1 and Vpp2 must be the same\n"); |
297 | mutex_unlock(&s->ops_mutex); | ||
254 | return -EINVAL; | 298 | return -EINVAL; |
255 | } | 299 | } |
256 | s->socket.Vpp = mod->Vpp1; | 300 | s->socket.Vpp = mod->Vpp1; |
257 | if (s->ops->set_socket(s, &s->socket)) { | 301 | if (s->ops->set_socket(s, &s->socket)) { |
302 | mutex_unlock(&s->ops_mutex); | ||
258 | dev_printk(KERN_WARNING, &s->dev, | 303 | dev_printk(KERN_WARNING, &s->dev, |
259 | "Unable to set VPP\n"); | 304 | "Unable to set VPP\n"); |
260 | return -EIO; | 305 | return -EIO; |
@@ -262,6 +307,7 @@ int pcmcia_modify_configuration(struct pcmcia_device *p_dev, | |||
262 | } else if ((mod->Attributes & CONF_VPP1_CHANGE_VALID) || | 307 | } else if ((mod->Attributes & CONF_VPP1_CHANGE_VALID) || |
263 | (mod->Attributes & CONF_VPP2_CHANGE_VALID)) { | 308 | (mod->Attributes & CONF_VPP2_CHANGE_VALID)) { |
264 | dev_dbg(&s->dev, "changing Vcc is not allowed at this time\n"); | 309 | dev_dbg(&s->dev, "changing Vcc is not allowed at this time\n"); |
310 | mutex_unlock(&s->ops_mutex); | ||
265 | return -EINVAL; | 311 | return -EINVAL; |
266 | } | 312 | } |
267 | 313 | ||
@@ -286,6 +332,7 @@ int pcmcia_modify_configuration(struct pcmcia_device *p_dev, | |||
286 | s->ops->set_io_map(s, &io_on); | 332 | s->ops->set_io_map(s, &io_on); |
287 | } | 333 | } |
288 | } | 334 | } |
335 | mutex_unlock(&s->ops_mutex); | ||
289 | 336 | ||
290 | return 0; | 337 | return 0; |
291 | } /* modify_configuration */ | 338 | } /* modify_configuration */ |
@@ -296,9 +343,11 @@ int pcmcia_release_configuration(struct pcmcia_device *p_dev) | |||
296 | { | 343 | { |
297 | pccard_io_map io = { 0, 0, 0, 0, 1 }; | 344 | pccard_io_map io = { 0, 0, 0, 0, 1 }; |
298 | struct pcmcia_socket *s = p_dev->socket; | 345 | struct pcmcia_socket *s = p_dev->socket; |
299 | config_t *c = p_dev->function_config; | 346 | config_t *c; |
300 | int i; | 347 | int i; |
301 | 348 | ||
349 | mutex_lock(&s->ops_mutex); | ||
350 | c = p_dev->function_config; | ||
302 | if (p_dev->_locked) { | 351 | if (p_dev->_locked) { |
303 | p_dev->_locked = 0; | 352 | p_dev->_locked = 0; |
304 | if (--(s->lock_count) == 0) { | 353 | if (--(s->lock_count) == 0) { |
@@ -321,6 +370,7 @@ int pcmcia_release_configuration(struct pcmcia_device *p_dev) | |||
321 | s->ops->set_io_map(s, &io); | 370 | s->ops->set_io_map(s, &io); |
322 | } | 371 | } |
323 | } | 372 | } |
373 | mutex_unlock(&s->ops_mutex); | ||
324 | 374 | ||
325 | return 0; | 375 | return 0; |
326 | } /* pcmcia_release_configuration */ | 376 | } /* pcmcia_release_configuration */ |
@@ -337,10 +387,14 @@ int pcmcia_release_configuration(struct pcmcia_device *p_dev) | |||
337 | static int pcmcia_release_io(struct pcmcia_device *p_dev, io_req_t *req) | 387 | static int pcmcia_release_io(struct pcmcia_device *p_dev, io_req_t *req) |
338 | { | 388 | { |
339 | struct pcmcia_socket *s = p_dev->socket; | 389 | struct pcmcia_socket *s = p_dev->socket; |
340 | config_t *c = p_dev->function_config; | 390 | int ret = -EINVAL; |
391 | config_t *c; | ||
392 | |||
393 | mutex_lock(&s->ops_mutex); | ||
394 | c = p_dev->function_config; | ||
341 | 395 | ||
342 | if (!p_dev->_io) | 396 | if (!p_dev->_io) |
343 | return -EINVAL; | 397 | goto out; |
344 | 398 | ||
345 | p_dev->_io = 0; | 399 | p_dev->_io = 0; |
346 | 400 | ||
@@ -348,7 +402,7 @@ static int pcmcia_release_io(struct pcmcia_device *p_dev, io_req_t *req) | |||
348 | (c->io.NumPorts1 != req->NumPorts1) || | 402 | (c->io.NumPorts1 != req->NumPorts1) || |
349 | (c->io.BasePort2 != req->BasePort2) || | 403 | (c->io.BasePort2 != req->BasePort2) || |
350 | (c->io.NumPorts2 != req->NumPorts2)) | 404 | (c->io.NumPorts2 != req->NumPorts2)) |
351 | return -EINVAL; | 405 | goto out; |
352 | 406 | ||
353 | c->state &= ~CONFIG_IO_REQ; | 407 | c->state &= ~CONFIG_IO_REQ; |
354 | 408 | ||
@@ -356,28 +410,38 @@ static int pcmcia_release_io(struct pcmcia_device *p_dev, io_req_t *req) | |||
356 | if (req->NumPorts2) | 410 | if (req->NumPorts2) |
357 | release_io_space(s, req->BasePort2, req->NumPorts2); | 411 | release_io_space(s, req->BasePort2, req->NumPorts2); |
358 | 412 | ||
359 | return 0; | 413 | out: |
414 | mutex_unlock(&s->ops_mutex); | ||
415 | |||
416 | return ret; | ||
360 | } /* pcmcia_release_io */ | 417 | } /* pcmcia_release_io */ |
361 | 418 | ||
362 | 419 | ||
363 | static int pcmcia_release_irq(struct pcmcia_device *p_dev, irq_req_t *req) | 420 | static int pcmcia_release_irq(struct pcmcia_device *p_dev, irq_req_t *req) |
364 | { | 421 | { |
365 | struct pcmcia_socket *s = p_dev->socket; | 422 | struct pcmcia_socket *s = p_dev->socket; |
366 | config_t *c = p_dev->function_config; | 423 | config_t *c; |
424 | int ret = -EINVAL; | ||
425 | |||
426 | mutex_lock(&s->ops_mutex); | ||
427 | |||
428 | c = p_dev->function_config; | ||
367 | 429 | ||
368 | if (!p_dev->_irq) | 430 | if (!p_dev->_irq) |
369 | return -EINVAL; | 431 | goto out; |
432 | |||
370 | p_dev->_irq = 0; | 433 | p_dev->_irq = 0; |
371 | 434 | ||
372 | if (c->state & CONFIG_LOCKED) | 435 | if (c->state & CONFIG_LOCKED) |
373 | return -EACCES; | 436 | goto out; |
437 | |||
374 | if (c->irq.Attributes != req->Attributes) { | 438 | if (c->irq.Attributes != req->Attributes) { |
375 | dev_dbg(&s->dev, "IRQ attributes must match assigned ones\n"); | 439 | dev_dbg(&s->dev, "IRQ attributes must match assigned ones\n"); |
376 | return -EINVAL; | 440 | goto out; |
377 | } | 441 | } |
378 | if (s->irq.AssignedIRQ != req->AssignedIRQ) { | 442 | if (s->irq.AssignedIRQ != req->AssignedIRQ) { |
379 | dev_dbg(&s->dev, "IRQ must match assigned one\n"); | 443 | dev_dbg(&s->dev, "IRQ must match assigned one\n"); |
380 | return -EINVAL; | 444 | goto out; |
381 | } | 445 | } |
382 | if (--s->irq.Config == 0) { | 446 | if (--s->irq.Config == 0) { |
383 | c->state &= ~CONFIG_IRQ_REQ; | 447 | c->state &= ~CONFIG_IRQ_REQ; |
@@ -390,8 +454,12 @@ static int pcmcia_release_irq(struct pcmcia_device *p_dev, irq_req_t *req) | |||
390 | #ifdef CONFIG_PCMCIA_PROBE | 454 | #ifdef CONFIG_PCMCIA_PROBE |
391 | pcmcia_used_irq[req->AssignedIRQ]--; | 455 | pcmcia_used_irq[req->AssignedIRQ]--; |
392 | #endif | 456 | #endif |
457 | ret = 0; | ||
393 | 458 | ||
394 | return 0; | 459 | out: |
460 | mutex_unlock(&s->ops_mutex); | ||
461 | |||
462 | return ret; | ||
395 | } /* pcmcia_release_irq */ | 463 | } /* pcmcia_release_irq */ |
396 | 464 | ||
397 | 465 | ||
@@ -404,10 +472,12 @@ int pcmcia_release_window(struct pcmcia_device *p_dev, window_handle_t wh) | |||
404 | if (wh >= MAX_WIN) | 472 | if (wh >= MAX_WIN) |
405 | return -EINVAL; | 473 | return -EINVAL; |
406 | 474 | ||
475 | mutex_lock(&s->ops_mutex); | ||
407 | win = &s->win[wh]; | 476 | win = &s->win[wh]; |
408 | 477 | ||
409 | if (!(p_dev->_win & CLIENT_WIN_REQ(wh))) { | 478 | if (!(p_dev->_win & CLIENT_WIN_REQ(wh))) { |
410 | dev_dbg(&s->dev, "not releasing unknown window\n"); | 479 | dev_dbg(&s->dev, "not releasing unknown window\n"); |
480 | mutex_unlock(&s->ops_mutex); | ||
411 | return -EINVAL; | 481 | return -EINVAL; |
412 | } | 482 | } |
413 | 483 | ||
@@ -423,6 +493,7 @@ int pcmcia_release_window(struct pcmcia_device *p_dev, window_handle_t wh) | |||
423 | win->res = NULL; | 493 | win->res = NULL; |
424 | } | 494 | } |
425 | p_dev->_win &= ~CLIENT_WIN_REQ(wh); | 495 | p_dev->_win &= ~CLIENT_WIN_REQ(wh); |
496 | mutex_unlock(&s->ops_mutex); | ||
426 | 497 | ||
427 | return 0; | 498 | return 0; |
428 | } /* pcmcia_release_window */ | 499 | } /* pcmcia_release_window */ |
@@ -445,8 +516,11 @@ int pcmcia_request_configuration(struct pcmcia_device *p_dev, | |||
445 | dev_dbg(&s->dev, "IntType may not be INT_CARDBUS\n"); | 516 | dev_dbg(&s->dev, "IntType may not be INT_CARDBUS\n"); |
446 | return -EINVAL; | 517 | return -EINVAL; |
447 | } | 518 | } |
519 | |||
520 | mutex_lock(&s->ops_mutex); | ||
448 | c = p_dev->function_config; | 521 | c = p_dev->function_config; |
449 | if (c->state & CONFIG_LOCKED) { | 522 | if (c->state & CONFIG_LOCKED) { |
523 | mutex_unlock(&s->ops_mutex); | ||
450 | dev_dbg(&s->dev, "Configuration is locked\n"); | 524 | dev_dbg(&s->dev, "Configuration is locked\n"); |
451 | return -EACCES; | 525 | return -EACCES; |
452 | } | 526 | } |
@@ -454,6 +528,7 @@ int pcmcia_request_configuration(struct pcmcia_device *p_dev, | |||
454 | /* Do power control. We don't allow changes in Vcc. */ | 528 | /* Do power control. We don't allow changes in Vcc. */ |
455 | s->socket.Vpp = req->Vpp; | 529 | s->socket.Vpp = req->Vpp; |
456 | if (s->ops->set_socket(s, &s->socket)) { | 530 | if (s->ops->set_socket(s, &s->socket)) { |
531 | mutex_unlock(&s->ops_mutex); | ||
457 | dev_printk(KERN_WARNING, &s->dev, | 532 | dev_printk(KERN_WARNING, &s->dev, |
458 | "Unable to set socket state\n"); | 533 | "Unable to set socket state\n"); |
459 | return -EINVAL; | 534 | return -EINVAL; |
@@ -476,6 +551,7 @@ int pcmcia_request_configuration(struct pcmcia_device *p_dev, | |||
476 | s->socket.io_irq = 0; | 551 | s->socket.io_irq = 0; |
477 | s->ops->set_socket(s, &s->socket); | 552 | s->ops->set_socket(s, &s->socket); |
478 | s->lock_count++; | 553 | s->lock_count++; |
554 | mutex_unlock(&s->ops_mutex); | ||
479 | 555 | ||
480 | /* Set up CIS configuration registers */ | 556 | /* Set up CIS configuration registers */ |
481 | base = c->ConfigBase = req->ConfigBase; | 557 | base = c->ConfigBase = req->ConfigBase; |
@@ -524,6 +600,7 @@ int pcmcia_request_configuration(struct pcmcia_device *p_dev, | |||
524 | 600 | ||
525 | /* Configure I/O windows */ | 601 | /* Configure I/O windows */ |
526 | if (c->state & CONFIG_IO_REQ) { | 602 | if (c->state & CONFIG_IO_REQ) { |
603 | mutex_lock(&s->ops_mutex); | ||
527 | iomap.speed = io_speed; | 604 | iomap.speed = io_speed; |
528 | for (i = 0; i < MAX_IO_WIN; i++) | 605 | for (i = 0; i < MAX_IO_WIN; i++) |
529 | if (s->io[i].res) { | 606 | if (s->io[i].res) { |
@@ -542,6 +619,7 @@ int pcmcia_request_configuration(struct pcmcia_device *p_dev, | |||
542 | s->ops->set_io_map(s, &iomap); | 619 | s->ops->set_io_map(s, &iomap); |
543 | s->io[i].Config++; | 620 | s->io[i].Config++; |
544 | } | 621 | } |
622 | mutex_unlock(&s->ops_mutex); | ||
545 | } | 623 | } |
546 | 624 | ||
547 | c->state |= CONFIG_LOCKED; | 625 | c->state |= CONFIG_LOCKED; |
@@ -560,54 +638,65 @@ int pcmcia_request_io(struct pcmcia_device *p_dev, io_req_t *req) | |||
560 | { | 638 | { |
561 | struct pcmcia_socket *s = p_dev->socket; | 639 | struct pcmcia_socket *s = p_dev->socket; |
562 | config_t *c; | 640 | config_t *c; |
641 | int ret = -EINVAL; | ||
642 | |||
643 | mutex_lock(&s->ops_mutex); | ||
563 | 644 | ||
564 | if (!(s->state & SOCKET_PRESENT)) { | 645 | if (!(s->state & SOCKET_PRESENT)) { |
565 | dev_dbg(&s->dev, "No card present\n"); | 646 | dev_dbg(&s->dev, "No card present\n"); |
566 | return -ENODEV; | 647 | goto out; |
567 | } | 648 | } |
568 | 649 | ||
569 | if (!req) | 650 | if (!req) |
570 | return -EINVAL; | 651 | goto out; |
652 | |||
571 | c = p_dev->function_config; | 653 | c = p_dev->function_config; |
572 | if (c->state & CONFIG_LOCKED) { | 654 | if (c->state & CONFIG_LOCKED) { |
573 | dev_dbg(&s->dev, "Configuration is locked\n"); | 655 | dev_dbg(&s->dev, "Configuration is locked\n"); |
574 | return -EACCES; | 656 | goto out; |
575 | } | 657 | } |
576 | if (c->state & CONFIG_IO_REQ) { | 658 | if (c->state & CONFIG_IO_REQ) { |
577 | dev_dbg(&s->dev, "IO already configured\n"); | 659 | dev_dbg(&s->dev, "IO already configured\n"); |
578 | return -EBUSY; | 660 | goto out; |
579 | } | 661 | } |
580 | if (req->Attributes1 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS)) { | 662 | if (req->Attributes1 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS)) { |
581 | dev_dbg(&s->dev, "bad attribute setting for IO region 1\n"); | 663 | dev_dbg(&s->dev, "bad attribute setting for IO region 1\n"); |
582 | return -EINVAL; | 664 | goto out; |
583 | } | 665 | } |
584 | if ((req->NumPorts2 > 0) && | 666 | if ((req->NumPorts2 > 0) && |
585 | (req->Attributes2 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS))) { | 667 | (req->Attributes2 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS))) { |
586 | dev_dbg(&s->dev, "bad attribute setting for IO region 2\n"); | 668 | dev_dbg(&s->dev, "bad attribute setting for IO region 2\n"); |
587 | return -EINVAL; | 669 | goto out; |
588 | } | 670 | } |
589 | 671 | ||
590 | dev_dbg(&s->dev, "trying to allocate resource 1\n"); | 672 | dev_dbg(&s->dev, "trying to allocate resource 1\n"); |
591 | if (alloc_io_space(s, req->Attributes1, &req->BasePort1, | 673 | ret = alloc_io_space(s, req->Attributes1, &req->BasePort1, |
592 | req->NumPorts1, req->IOAddrLines)) { | 674 | req->NumPorts1, req->IOAddrLines); |
675 | if (ret) { | ||
593 | dev_dbg(&s->dev, "allocation of resource 1 failed\n"); | 676 | dev_dbg(&s->dev, "allocation of resource 1 failed\n"); |
594 | return -EBUSY; | 677 | goto out; |
595 | } | 678 | } |
596 | 679 | ||
597 | if (req->NumPorts2) { | 680 | if (req->NumPorts2) { |
598 | dev_dbg(&s->dev, "trying to allocate resource 2\n"); | 681 | dev_dbg(&s->dev, "trying to allocate resource 2\n"); |
599 | if (alloc_io_space(s, req->Attributes2, &req->BasePort2, | 682 | ret = alloc_io_space(s, req->Attributes2, &req->BasePort2, |
600 | req->NumPorts2, req->IOAddrLines)) { | 683 | req->NumPorts2, req->IOAddrLines); |
684 | if (ret) { | ||
601 | dev_dbg(&s->dev, "allocation of resource 2 failed\n"); | 685 | dev_dbg(&s->dev, "allocation of resource 2 failed\n"); |
602 | release_io_space(s, req->BasePort1, req->NumPorts1); | 686 | release_io_space(s, req->BasePort1, req->NumPorts1); |
603 | return -EBUSY; | 687 | goto out; |
604 | } | 688 | } |
605 | } | 689 | } |
606 | 690 | ||
607 | c->io = *req; | 691 | c->io = *req; |
608 | c->state |= CONFIG_IO_REQ; | 692 | c->state |= CONFIG_IO_REQ; |
609 | p_dev->_io = 1; | 693 | p_dev->_io = 1; |
610 | return 0; | 694 | dev_dbg(&s->dev, "allocating resources succeeded: %d\n", ret); |
695 | |||
696 | out: | ||
697 | mutex_unlock(&s->ops_mutex); | ||
698 | |||
699 | return ret; | ||
611 | } /* pcmcia_request_io */ | 700 | } /* pcmcia_request_io */ |
612 | EXPORT_SYMBOL(pcmcia_request_io); | 701 | EXPORT_SYMBOL(pcmcia_request_io); |
613 | 702 | ||
@@ -636,18 +725,20 @@ int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req) | |||
636 | int ret = -EINVAL, irq = 0; | 725 | int ret = -EINVAL, irq = 0; |
637 | int type; | 726 | int type; |
638 | 727 | ||
728 | mutex_lock(&s->ops_mutex); | ||
729 | |||
639 | if (!(s->state & SOCKET_PRESENT)) { | 730 | if (!(s->state & SOCKET_PRESENT)) { |
640 | dev_dbg(&s->dev, "No card present\n"); | 731 | dev_dbg(&s->dev, "No card present\n"); |
641 | return -ENODEV; | 732 | goto out; |
642 | } | 733 | } |
643 | c = p_dev->function_config; | 734 | c = p_dev->function_config; |
644 | if (c->state & CONFIG_LOCKED) { | 735 | if (c->state & CONFIG_LOCKED) { |
645 | dev_dbg(&s->dev, "Configuration is locked\n"); | 736 | dev_dbg(&s->dev, "Configuration is locked\n"); |
646 | return -EACCES; | 737 | goto out; |
647 | } | 738 | } |
648 | if (c->state & CONFIG_IRQ_REQ) { | 739 | if (c->state & CONFIG_IRQ_REQ) { |
649 | dev_dbg(&s->dev, "IRQ already configured\n"); | 740 | dev_dbg(&s->dev, "IRQ already configured\n"); |
650 | return -EBUSY; | 741 | goto out; |
651 | } | 742 | } |
652 | 743 | ||
653 | /* Decide what type of interrupt we are registering */ | 744 | /* Decide what type of interrupt we are registering */ |
@@ -708,7 +799,7 @@ int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req) | |||
708 | if (ret && !s->irq.AssignedIRQ) { | 799 | if (ret && !s->irq.AssignedIRQ) { |
709 | if (!s->pci_irq) { | 800 | if (!s->pci_irq) { |
710 | dev_printk(KERN_INFO, &s->dev, "no IRQ found\n"); | 801 | dev_printk(KERN_INFO, &s->dev, "no IRQ found\n"); |
711 | return ret; | 802 | goto out; |
712 | } | 803 | } |
713 | type = IRQF_SHARED; | 804 | type = IRQF_SHARED; |
714 | irq = s->pci_irq; | 805 | irq = s->pci_irq; |
@@ -720,7 +811,7 @@ int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req) | |||
720 | if (ret) { | 811 | if (ret) { |
721 | dev_printk(KERN_INFO, &s->dev, | 812 | dev_printk(KERN_INFO, &s->dev, |
722 | "request_irq() failed\n"); | 813 | "request_irq() failed\n"); |
723 | return ret; | 814 | goto out; |
724 | } | 815 | } |
725 | } | 816 | } |
726 | 817 | ||
@@ -743,7 +834,10 @@ int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req) | |||
743 | pcmcia_used_irq[irq]++; | 834 | pcmcia_used_irq[irq]++; |
744 | #endif | 835 | #endif |
745 | 836 | ||
746 | return 0; | 837 | ret = 0; |
838 | out: | ||
839 | mutex_unlock(&s->ops_mutex); | ||
840 | return ret; | ||
747 | } /* pcmcia_request_irq */ | 841 | } /* pcmcia_request_irq */ |
748 | EXPORT_SYMBOL(pcmcia_request_irq); | 842 | EXPORT_SYMBOL(pcmcia_request_irq); |
749 | 843 | ||
@@ -796,6 +890,7 @@ int pcmcia_request_window(struct pcmcia_device *p_dev, win_req_t *req, window_ha | |||
796 | return -EINVAL; | 890 | return -EINVAL; |
797 | } | 891 | } |
798 | 892 | ||
893 | mutex_lock(&s->ops_mutex); | ||
799 | win = &s->win[w]; | 894 | win = &s->win[w]; |
800 | 895 | ||
801 | if (!(s->features & SS_CAP_STATIC_MAP)) { | 896 | if (!(s->features & SS_CAP_STATIC_MAP)) { |
@@ -803,6 +898,7 @@ int pcmcia_request_window(struct pcmcia_device *p_dev, win_req_t *req, window_ha | |||
803 | (req->Attributes & WIN_MAP_BELOW_1MB), s); | 898 | (req->Attributes & WIN_MAP_BELOW_1MB), s); |
804 | if (!win->res) { | 899 | if (!win->res) { |
805 | dev_dbg(&s->dev, "allocating mem region failed\n"); | 900 | dev_dbg(&s->dev, "allocating mem region failed\n"); |
901 | mutex_unlock(&s->ops_mutex); | ||
806 | return -EINVAL; | 902 | return -EINVAL; |
807 | } | 903 | } |
808 | } | 904 | } |
@@ -821,8 +917,10 @@ int pcmcia_request_window(struct pcmcia_device *p_dev, win_req_t *req, window_ha | |||
821 | if (req->Attributes & WIN_USE_WAIT) | 917 | if (req->Attributes & WIN_USE_WAIT) |
822 | win->flags |= MAP_USE_WAIT; | 918 | win->flags |= MAP_USE_WAIT; |
823 | win->card_start = 0; | 919 | win->card_start = 0; |
920 | |||
824 | if (s->ops->set_mem_map(s, win) != 0) { | 921 | if (s->ops->set_mem_map(s, win) != 0) { |
825 | dev_dbg(&s->dev, "failed to set memory mapping\n"); | 922 | dev_dbg(&s->dev, "failed to set memory mapping\n"); |
923 | mutex_unlock(&s->ops_mutex); | ||
826 | return -EIO; | 924 | return -EIO; |
827 | } | 925 | } |
828 | s->state |= SOCKET_WIN_REQ(w); | 926 | s->state |= SOCKET_WIN_REQ(w); |
@@ -833,6 +931,7 @@ int pcmcia_request_window(struct pcmcia_device *p_dev, win_req_t *req, window_ha | |||
833 | else | 931 | else |
834 | req->Base = win->res->start; | 932 | req->Base = win->res->start; |
835 | 933 | ||
934 | mutex_unlock(&s->ops_mutex); | ||
836 | *wh = w + 1; | 935 | *wh = w + 1; |
837 | 936 | ||
838 | return 0; | 937 | return 0; |
diff --git a/drivers/pcmcia/rsrc_mgr.c b/drivers/pcmcia/rsrc_mgr.c index 52db17263d8b..e6f7d410aed6 100644 --- a/drivers/pcmcia/rsrc_mgr.c +++ b/drivers/pcmcia/rsrc_mgr.c | |||
@@ -21,60 +21,12 @@ | |||
21 | #include <pcmcia/cistpl.h> | 21 | #include <pcmcia/cistpl.h> |
22 | #include "cs_internal.h" | 22 | #include "cs_internal.h" |
23 | 23 | ||
24 | |||
25 | int pcmcia_validate_mem(struct pcmcia_socket *s) | ||
26 | { | ||
27 | if (s->resource_ops->validate_mem) | ||
28 | return s->resource_ops->validate_mem(s); | ||
29 | /* if there is no callback, we can assume that everything is OK */ | ||
30 | return 0; | ||
31 | } | ||
32 | EXPORT_SYMBOL(pcmcia_validate_mem); | ||
33 | |||
34 | int pcmcia_adjust_io_region(struct resource *res, unsigned long r_start, | ||
35 | unsigned long r_end, struct pcmcia_socket *s) | ||
36 | { | ||
37 | if (s->resource_ops->adjust_io_region) | ||
38 | return s->resource_ops->adjust_io_region(res, r_start, r_end, s); | ||
39 | return -ENOMEM; | ||
40 | } | ||
41 | EXPORT_SYMBOL(pcmcia_adjust_io_region); | ||
42 | |||
43 | struct resource *pcmcia_find_io_region(unsigned long base, int num, | ||
44 | unsigned long align, struct pcmcia_socket *s) | ||
45 | { | ||
46 | if (s->resource_ops->find_io) | ||
47 | return s->resource_ops->find_io(base, num, align, s); | ||
48 | return NULL; | ||
49 | } | ||
50 | EXPORT_SYMBOL(pcmcia_find_io_region); | ||
51 | |||
52 | struct resource *pcmcia_find_mem_region(u_long base, u_long num, u_long align, | ||
53 | int low, struct pcmcia_socket *s) | ||
54 | { | ||
55 | if (s->resource_ops->find_mem) | ||
56 | return s->resource_ops->find_mem(base, num, align, low, s); | ||
57 | return NULL; | ||
58 | } | ||
59 | EXPORT_SYMBOL(pcmcia_find_mem_region); | ||
60 | |||
61 | void release_resource_db(struct pcmcia_socket *s) | ||
62 | { | ||
63 | if (s->resource_ops->exit) | ||
64 | s->resource_ops->exit(s); | ||
65 | } | ||
66 | |||
67 | |||
68 | static int static_init(struct pcmcia_socket *s) | 24 | static int static_init(struct pcmcia_socket *s) |
69 | { | 25 | { |
70 | unsigned long flags; | ||
71 | |||
72 | /* the good thing about SS_CAP_STATIC_MAP sockets is | 26 | /* the good thing about SS_CAP_STATIC_MAP sockets is |
73 | * that they don't need a resource database */ | 27 | * that they don't need a resource database */ |
74 | 28 | ||
75 | spin_lock_irqsave(&s->lock, flags); | ||
76 | s->resource_setup_done = 1; | 29 | s->resource_setup_done = 1; |
77 | spin_unlock_irqrestore(&s->lock, flags); | ||
78 | 30 | ||
79 | return 0; | 31 | return 0; |
80 | } | 32 | } |
@@ -114,22 +66,21 @@ struct pcmcia_align_data { | |||
114 | unsigned long offset; | 66 | unsigned long offset; |
115 | }; | 67 | }; |
116 | 68 | ||
117 | static void pcmcia_align(void *align_data, struct resource *res, | 69 | static resource_size_t pcmcia_align(void *align_data, |
118 | unsigned long size, unsigned long align) | 70 | const struct resource *res, |
71 | resource_size_t size, resource_size_t align) | ||
119 | { | 72 | { |
120 | struct pcmcia_align_data *data = align_data; | 73 | struct pcmcia_align_data *data = align_data; |
121 | unsigned long start; | 74 | resource_size_t start; |
122 | 75 | ||
123 | start = (res->start & ~data->mask) + data->offset; | 76 | start = (res->start & ~data->mask) + data->offset; |
124 | if (start < res->start) | 77 | if (start < res->start) |
125 | start += data->mask + 1; | 78 | start += data->mask + 1; |
126 | res->start = start; | ||
127 | 79 | ||
128 | #ifdef CONFIG_X86 | 80 | #ifdef CONFIG_X86 |
129 | if (res->flags & IORESOURCE_IO) { | 81 | if (res->flags & IORESOURCE_IO) { |
130 | if (start & 0x300) { | 82 | if (start & 0x300) { |
131 | start = (start + 0x3ff) & ~0x3ff; | 83 | start = (start + 0x3ff) & ~0x3ff; |
132 | res->start = start; | ||
133 | } | 84 | } |
134 | } | 85 | } |
135 | #endif | 86 | #endif |
@@ -137,9 +88,11 @@ static void pcmcia_align(void *align_data, struct resource *res, | |||
137 | #ifdef CONFIG_M68K | 88 | #ifdef CONFIG_M68K |
138 | if (res->flags & IORESOURCE_IO) { | 89 | if (res->flags & IORESOURCE_IO) { |
139 | if ((res->start + size - 1) >= 1024) | 90 | if ((res->start + size - 1) >= 1024) |
140 | res->start = res->end; | 91 | start = res->end; |
141 | } | 92 | } |
142 | #endif | 93 | #endif |
94 | |||
95 | return start; | ||
143 | } | 96 | } |
144 | 97 | ||
145 | 98 | ||
diff --git a/drivers/pcmcia/rsrc_nonstatic.c b/drivers/pcmcia/rsrc_nonstatic.c index 9b0dc433a8c3..4663b3fa9f96 100644 --- a/drivers/pcmcia/rsrc_nonstatic.c +++ b/drivers/pcmcia/rsrc_nonstatic.c | |||
@@ -55,11 +55,10 @@ struct resource_map { | |||
55 | 55 | ||
56 | struct socket_data { | 56 | struct socket_data { |
57 | struct resource_map mem_db; | 57 | struct resource_map mem_db; |
58 | struct resource_map mem_db_valid; | ||
58 | struct resource_map io_db; | 59 | struct resource_map io_db; |
59 | unsigned int rsrc_mem_probe; | ||
60 | }; | 60 | }; |
61 | 61 | ||
62 | static DEFINE_MUTEX(rsrc_mutex); | ||
63 | #define MEM_PROBE_LOW (1 << 0) | 62 | #define MEM_PROBE_LOW (1 << 0) |
64 | #define MEM_PROBE_HIGH (1 << 1) | 63 | #define MEM_PROBE_HIGH (1 << 1) |
65 | 64 | ||
@@ -125,8 +124,10 @@ static int add_interval(struct resource_map *map, u_long base, u_long num) | |||
125 | struct resource_map *p, *q; | 124 | struct resource_map *p, *q; |
126 | 125 | ||
127 | for (p = map; ; p = p->next) { | 126 | for (p = map; ; p = p->next) { |
128 | if ((p != map) && (p->base+p->num-1 >= base)) | 127 | if ((p != map) && (p->base+p->num >= base)) { |
129 | return -1; | 128 | p->num = max(num + base - p->base, p->num); |
129 | return 0; | ||
130 | } | ||
130 | if ((p->next == map) || (p->next->base > base+num-1)) | 131 | if ((p->next == map) || (p->next->base > base+num-1)) |
131 | break; | 132 | break; |
132 | } | 133 | } |
@@ -264,36 +265,44 @@ static void do_io_probe(struct pcmcia_socket *s, unsigned int base, | |||
264 | } | 265 | } |
265 | #endif | 266 | #endif |
266 | 267 | ||
267 | /*====================================================================== | 268 | /*======================================================================*/ |
268 | |||
269 | This is tricky... when we set up CIS memory, we try to validate | ||
270 | the memory window space allocations. | ||
271 | |||
272 | ======================================================================*/ | ||
273 | 269 | ||
274 | /* Validation function for cards with a valid CIS */ | 270 | /** |
271 | * readable() - iomem validation function for cards with a valid CIS | ||
272 | */ | ||
275 | static int readable(struct pcmcia_socket *s, struct resource *res, | 273 | static int readable(struct pcmcia_socket *s, struct resource *res, |
276 | unsigned int *count) | 274 | unsigned int *count) |
277 | { | 275 | { |
278 | int ret = -1; | 276 | int ret = -EINVAL; |
277 | |||
278 | if (s->fake_cis) { | ||
279 | dev_dbg(&s->dev, "fake CIS is being used: can't validate mem\n"); | ||
280 | return 0; | ||
281 | } | ||
279 | 282 | ||
280 | s->cis_mem.res = res; | 283 | s->cis_mem.res = res; |
281 | s->cis_virt = ioremap(res->start, s->map_size); | 284 | s->cis_virt = ioremap(res->start, s->map_size); |
282 | if (s->cis_virt) { | 285 | if (s->cis_virt) { |
283 | ret = pccard_validate_cis(s, count); | 286 | mutex_unlock(&s->ops_mutex); |
284 | /* invalidate mapping and CIS cache */ | 287 | /* as we're only called from pcmcia.c, we're safe */ |
288 | if (s->callback->validate) | ||
289 | ret = s->callback->validate(s, count); | ||
290 | /* invalidate mapping */ | ||
291 | mutex_lock(&s->ops_mutex); | ||
285 | iounmap(s->cis_virt); | 292 | iounmap(s->cis_virt); |
286 | s->cis_virt = NULL; | 293 | s->cis_virt = NULL; |
287 | destroy_cis_cache(s); | ||
288 | } | 294 | } |
289 | s->cis_mem.res = NULL; | 295 | s->cis_mem.res = NULL; |
290 | if ((ret != 0) || (*count == 0)) | 296 | if ((ret) || (*count == 0)) |
291 | return 0; | 297 | return -EINVAL; |
292 | return 1; | 298 | return 0; |
293 | } | 299 | } |
294 | 300 | ||
295 | /* Validation function for simple memory cards */ | 301 | /** |
296 | static int checksum(struct pcmcia_socket *s, struct resource *res) | 302 | * checksum() - iomem validation function for simple memory cards |
303 | */ | ||
304 | static int checksum(struct pcmcia_socket *s, struct resource *res, | ||
305 | unsigned int *value) | ||
297 | { | 306 | { |
298 | pccard_mem_map map; | 307 | pccard_mem_map map; |
299 | int i, a = 0, b = -1, d; | 308 | int i, a = 0, b = -1, d; |
@@ -321,61 +330,90 @@ static int checksum(struct pcmcia_socket *s, struct resource *res) | |||
321 | iounmap(virt); | 330 | iounmap(virt); |
322 | } | 331 | } |
323 | 332 | ||
324 | return (b == -1) ? -1 : (a>>1); | 333 | if (b == -1) |
334 | return -EINVAL; | ||
335 | |||
336 | *value = a; | ||
337 | |||
338 | return 0; | ||
325 | } | 339 | } |
326 | 340 | ||
327 | static int | 341 | /** |
328 | cis_readable(struct pcmcia_socket *s, unsigned long base, unsigned long size) | 342 | * do_validate_mem() - low level validate a memory region for PCMCIA use |
343 | * @s: PCMCIA socket to validate | ||
344 | * @base: start address of resource to check | ||
345 | * @size: size of resource to check | ||
346 | * @validate: validation function to use | ||
347 | * | ||
348 | * do_validate_mem() splits up the memory region which is to be checked | ||
349 | * into two parts. Both are passed to the @validate() function. If | ||
350 | * @validate() returns non-zero, or the value parameter to @validate() | ||
351 | * is zero, or the value parameter is different between both calls, | ||
352 | * the check fails, and -EINVAL is returned. Else, 0 is returned. | ||
353 | */ | ||
354 | static int do_validate_mem(struct pcmcia_socket *s, | ||
355 | unsigned long base, unsigned long size, | ||
356 | int validate (struct pcmcia_socket *s, | ||
357 | struct resource *res, | ||
358 | unsigned int *value)) | ||
329 | { | 359 | { |
360 | struct socket_data *s_data = s->resource_data; | ||
330 | struct resource *res1, *res2; | 361 | struct resource *res1, *res2; |
331 | unsigned int info1, info2; | 362 | unsigned int info1 = 1, info2 = 1; |
332 | int ret = 0; | 363 | int ret = -EINVAL; |
333 | 364 | ||
334 | res1 = claim_region(s, base, size/2, IORESOURCE_MEM, "PCMCIA memprobe"); | 365 | res1 = claim_region(s, base, size/2, IORESOURCE_MEM, "PCMCIA memprobe"); |
335 | res2 = claim_region(s, base + size/2, size/2, IORESOURCE_MEM, | 366 | res2 = claim_region(s, base + size/2, size/2, IORESOURCE_MEM, |
336 | "PCMCIA memprobe"); | 367 | "PCMCIA memprobe"); |
337 | 368 | ||
338 | if (res1 && res2) { | 369 | if (res1 && res2) { |
339 | ret = readable(s, res1, &info1); | 370 | ret = 0; |
340 | ret += readable(s, res2, &info2); | 371 | if (validate) { |
372 | ret = validate(s, res1, &info1); | ||
373 | ret += validate(s, res2, &info2); | ||
374 | } | ||
341 | } | 375 | } |
342 | 376 | ||
343 | free_region(res2); | 377 | free_region(res2); |
344 | free_region(res1); | 378 | free_region(res1); |
345 | 379 | ||
346 | return (ret == 2) && (info1 == info2); | 380 | dev_dbg(&s->dev, "cs: memory probe 0x%06lx-0x%06lx: %p %p %u %u %u", |
347 | } | 381 | base, base+size-1, res1, res2, ret, info1, info2); |
348 | |||
349 | static int | ||
350 | checksum_match(struct pcmcia_socket *s, unsigned long base, unsigned long size) | ||
351 | { | ||
352 | struct resource *res1, *res2; | ||
353 | int a = -1, b = -1; | ||
354 | 382 | ||
355 | res1 = claim_region(s, base, size/2, IORESOURCE_MEM, "PCMCIA memprobe"); | 383 | if ((ret) || (info1 != info2) || (info1 == 0)) |
356 | res2 = claim_region(s, base + size/2, size/2, IORESOURCE_MEM, | 384 | return -EINVAL; |
357 | "PCMCIA memprobe"); | ||
358 | 385 | ||
359 | if (res1 && res2) { | 386 | if (validate && !s->fake_cis) { |
360 | a = checksum(s, res1); | 387 | /* move it to the validated data set */ |
361 | b = checksum(s, res2); | 388 | add_interval(&s_data->mem_db_valid, base, size); |
389 | sub_interval(&s_data->mem_db, base, size); | ||
362 | } | 390 | } |
363 | 391 | ||
364 | free_region(res2); | 392 | return 0; |
365 | free_region(res1); | ||
366 | |||
367 | return (a == b) && (a >= 0); | ||
368 | } | 393 | } |
369 | 394 | ||
370 | /*====================================================================== | ||
371 | |||
372 | The memory probe. If the memory list includes a 64K-aligned block | ||
373 | below 1MB, we probe in 64K chunks, and as soon as we accumulate at | ||
374 | least mem_limit free space, we quit. | ||
375 | 395 | ||
376 | ======================================================================*/ | 396 | /** |
377 | 397 | * do_mem_probe() - validate a memory region for PCMCIA use | |
378 | static int do_mem_probe(u_long base, u_long num, struct pcmcia_socket *s) | 398 | * @s: PCMCIA socket to validate |
399 | * @base: start address of resource to check | ||
400 | * @num: size of resource to check | ||
401 | * @validate: validation function to use | ||
402 | * @fallback: validation function to use if validate fails | ||
403 | * | ||
404 | * do_mem_probe() checks a memory region for use by the PCMCIA subsystem. | ||
405 | * To do so, the area is split up into sensible parts, and then passed | ||
406 | * into the @validate() function. Only if @validate() and @fallback() fail, | ||
407 | * the area is marked as unavaibale for use by the PCMCIA subsystem. The | ||
408 | * function returns the size of the usable memory area. | ||
409 | */ | ||
410 | static int do_mem_probe(struct pcmcia_socket *s, u_long base, u_long num, | ||
411 | int validate (struct pcmcia_socket *s, | ||
412 | struct resource *res, | ||
413 | unsigned int *value), | ||
414 | int fallback (struct pcmcia_socket *s, | ||
415 | struct resource *res, | ||
416 | unsigned int *value)) | ||
379 | { | 417 | { |
380 | struct socket_data *s_data = s->resource_data; | 418 | struct socket_data *s_data = s->resource_data; |
381 | u_long i, j, bad, fail, step; | 419 | u_long i, j, bad, fail, step; |
@@ -393,15 +431,14 @@ static int do_mem_probe(u_long base, u_long num, struct pcmcia_socket *s) | |||
393 | for (i = j = base; i < base+num; i = j + step) { | 431 | for (i = j = base; i < base+num; i = j + step) { |
394 | if (!fail) { | 432 | if (!fail) { |
395 | for (j = i; j < base+num; j += step) { | 433 | for (j = i; j < base+num; j += step) { |
396 | if (cis_readable(s, j, step)) | 434 | if (!do_validate_mem(s, j, step, validate)) |
397 | break; | 435 | break; |
398 | } | 436 | } |
399 | fail = ((i == base) && (j == base+num)); | 437 | fail = ((i == base) && (j == base+num)); |
400 | } | 438 | } |
401 | if (fail) { | 439 | if ((fail) && (fallback)) { |
402 | for (j = i; j < base+num; j += 2*step) | 440 | for (j = i; j < base+num; j += step) |
403 | if (checksum_match(s, j, step) && | 441 | if (!do_validate_mem(s, j, step, fallback)) |
404 | checksum_match(s, j + step, step)) | ||
405 | break; | 442 | break; |
406 | } | 443 | } |
407 | if (i != j) { | 444 | if (i != j) { |
@@ -416,8 +453,14 @@ static int do_mem_probe(u_long base, u_long num, struct pcmcia_socket *s) | |||
416 | return num - bad; | 453 | return num - bad; |
417 | } | 454 | } |
418 | 455 | ||
456 | |||
419 | #ifdef CONFIG_PCMCIA_PROBE | 457 | #ifdef CONFIG_PCMCIA_PROBE |
420 | 458 | ||
459 | /** | ||
460 | * inv_probe() - top-to-bottom search for one usuable high memory area | ||
461 | * @s: PCMCIA socket to validate | ||
462 | * @m: resource_map to check | ||
463 | */ | ||
421 | static u_long inv_probe(struct resource_map *m, struct pcmcia_socket *s) | 464 | static u_long inv_probe(struct resource_map *m, struct pcmcia_socket *s) |
422 | { | 465 | { |
423 | struct socket_data *s_data = s->resource_data; | 466 | struct socket_data *s_data = s->resource_data; |
@@ -432,9 +475,18 @@ static u_long inv_probe(struct resource_map *m, struct pcmcia_socket *s) | |||
432 | } | 475 | } |
433 | if (m->base < 0x100000) | 476 | if (m->base < 0x100000) |
434 | return 0; | 477 | return 0; |
435 | return do_mem_probe(m->base, m->num, s); | 478 | return do_mem_probe(s, m->base, m->num, readable, checksum); |
436 | } | 479 | } |
437 | 480 | ||
481 | /** | ||
482 | * validate_mem() - memory probe function | ||
483 | * @s: PCMCIA socket to validate | ||
484 | * @probe_mask: MEM_PROBE_LOW | MEM_PROBE_HIGH | ||
485 | * | ||
486 | * The memory probe. If the memory list includes a 64K-aligned block | ||
487 | * below 1MB, we probe in 64K chunks, and as soon as we accumulate at | ||
488 | * least mem_limit free space, we quit. Returns 0 on usuable ports. | ||
489 | */ | ||
438 | static int validate_mem(struct pcmcia_socket *s, unsigned int probe_mask) | 490 | static int validate_mem(struct pcmcia_socket *s, unsigned int probe_mask) |
439 | { | 491 | { |
440 | struct resource_map *m, mm; | 492 | struct resource_map *m, mm; |
@@ -446,6 +498,8 @@ static int validate_mem(struct pcmcia_socket *s, unsigned int probe_mask) | |||
446 | if (probe_mask & MEM_PROBE_HIGH) { | 498 | if (probe_mask & MEM_PROBE_HIGH) { |
447 | if (inv_probe(s_data->mem_db.next, s) > 0) | 499 | if (inv_probe(s_data->mem_db.next, s) > 0) |
448 | return 0; | 500 | return 0; |
501 | if (s_data->mem_db_valid.next != &s_data->mem_db_valid) | ||
502 | return 0; | ||
449 | dev_printk(KERN_NOTICE, &s->dev, | 503 | dev_printk(KERN_NOTICE, &s->dev, |
450 | "cs: warning: no high memory space available!\n"); | 504 | "cs: warning: no high memory space available!\n"); |
451 | return -ENODEV; | 505 | return -ENODEV; |
@@ -457,7 +511,8 @@ static int validate_mem(struct pcmcia_socket *s, unsigned int probe_mask) | |||
457 | if (mm.base >= 0x100000) | 511 | if (mm.base >= 0x100000) |
458 | continue; | 512 | continue; |
459 | if ((mm.base | mm.num) & 0xffff) { | 513 | if ((mm.base | mm.num) & 0xffff) { |
460 | ok += do_mem_probe(mm.base, mm.num, s); | 514 | ok += do_mem_probe(s, mm.base, mm.num, readable, |
515 | checksum); | ||
461 | continue; | 516 | continue; |
462 | } | 517 | } |
463 | /* Special probe for 64K-aligned block */ | 518 | /* Special probe for 64K-aligned block */ |
@@ -467,7 +522,8 @@ static int validate_mem(struct pcmcia_socket *s, unsigned int probe_mask) | |||
467 | if (ok >= mem_limit) | 522 | if (ok >= mem_limit) |
468 | sub_interval(&s_data->mem_db, b, 0x10000); | 523 | sub_interval(&s_data->mem_db, b, 0x10000); |
469 | else | 524 | else |
470 | ok += do_mem_probe(b, 0x10000, s); | 525 | ok += do_mem_probe(s, b, 0x10000, |
526 | readable, checksum); | ||
471 | } | 527 | } |
472 | } | 528 | } |
473 | } | 529 | } |
@@ -480,6 +536,13 @@ static int validate_mem(struct pcmcia_socket *s, unsigned int probe_mask) | |||
480 | 536 | ||
481 | #else /* CONFIG_PCMCIA_PROBE */ | 537 | #else /* CONFIG_PCMCIA_PROBE */ |
482 | 538 | ||
539 | /** | ||
540 | * validate_mem() - memory probe function | ||
541 | * @s: PCMCIA socket to validate | ||
542 | * @probe_mask: ignored | ||
543 | * | ||
544 | * Returns 0 on usuable ports. | ||
545 | */ | ||
483 | static int validate_mem(struct pcmcia_socket *s, unsigned int probe_mask) | 546 | static int validate_mem(struct pcmcia_socket *s, unsigned int probe_mask) |
484 | { | 547 | { |
485 | struct resource_map *m, mm; | 548 | struct resource_map *m, mm; |
@@ -488,7 +551,7 @@ static int validate_mem(struct pcmcia_socket *s, unsigned int probe_mask) | |||
488 | 551 | ||
489 | for (m = s_data->mem_db.next; m != &s_data->mem_db; m = mm.next) { | 552 | for (m = s_data->mem_db.next; m != &s_data->mem_db; m = mm.next) { |
490 | mm = *m; | 553 | mm = *m; |
491 | ok += do_mem_probe(mm.base, mm.num, s); | 554 | ok += do_mem_probe(s, mm.base, mm.num, readable, checksum); |
492 | } | 555 | } |
493 | if (ok > 0) | 556 | if (ok > 0) |
494 | return 0; | 557 | return 0; |
@@ -498,31 +561,31 @@ static int validate_mem(struct pcmcia_socket *s, unsigned int probe_mask) | |||
498 | #endif /* CONFIG_PCMCIA_PROBE */ | 561 | #endif /* CONFIG_PCMCIA_PROBE */ |
499 | 562 | ||
500 | 563 | ||
501 | /* | 564 | /** |
565 | * pcmcia_nonstatic_validate_mem() - try to validate iomem for PCMCIA use | ||
566 | * @s: PCMCIA socket to validate | ||
567 | * | ||
568 | * This is tricky... when we set up CIS memory, we try to validate | ||
569 | * the memory window space allocations. | ||
570 | * | ||
502 | * Locking note: Must be called with skt_mutex held! | 571 | * Locking note: Must be called with skt_mutex held! |
503 | */ | 572 | */ |
504 | static int pcmcia_nonstatic_validate_mem(struct pcmcia_socket *s) | 573 | static int pcmcia_nonstatic_validate_mem(struct pcmcia_socket *s) |
505 | { | 574 | { |
506 | struct socket_data *s_data = s->resource_data; | 575 | struct socket_data *s_data = s->resource_data; |
507 | unsigned int probe_mask = MEM_PROBE_LOW; | 576 | unsigned int probe_mask = MEM_PROBE_LOW; |
508 | int ret = 0; | 577 | int ret; |
509 | 578 | ||
510 | if (!probe_mem) | 579 | if (!probe_mem || !(s->state & SOCKET_PRESENT)) |
511 | return 0; | 580 | return 0; |
512 | 581 | ||
513 | mutex_lock(&rsrc_mutex); | ||
514 | |||
515 | if (s->features & SS_CAP_PAGE_REGS) | 582 | if (s->features & SS_CAP_PAGE_REGS) |
516 | probe_mask = MEM_PROBE_HIGH; | 583 | probe_mask = MEM_PROBE_HIGH; |
517 | 584 | ||
518 | if (probe_mask & ~s_data->rsrc_mem_probe) { | 585 | ret = validate_mem(s, probe_mask); |
519 | if (s->state & SOCKET_PRESENT) | ||
520 | ret = validate_mem(s, probe_mask); | ||
521 | if (!ret) | ||
522 | s_data->rsrc_mem_probe |= probe_mask; | ||
523 | } | ||
524 | 586 | ||
525 | mutex_unlock(&rsrc_mutex); | 587 | if (s_data->mem_db_valid.next != &s_data->mem_db_valid) |
588 | return 0; | ||
526 | 589 | ||
527 | return ret; | 590 | return ret; |
528 | } | 591 | } |
@@ -533,8 +596,8 @@ struct pcmcia_align_data { | |||
533 | struct resource_map *map; | 596 | struct resource_map *map; |
534 | }; | 597 | }; |
535 | 598 | ||
536 | static void | 599 | static resource_size_t |
537 | pcmcia_common_align(void *align_data, struct resource *res, | 600 | pcmcia_common_align(void *align_data, const struct resource *res, |
538 | resource_size_t size, resource_size_t align) | 601 | resource_size_t size, resource_size_t align) |
539 | { | 602 | { |
540 | struct pcmcia_align_data *data = align_data; | 603 | struct pcmcia_align_data *data = align_data; |
@@ -545,17 +608,18 @@ pcmcia_common_align(void *align_data, struct resource *res, | |||
545 | start = (res->start & ~data->mask) + data->offset; | 608 | start = (res->start & ~data->mask) + data->offset; |
546 | if (start < res->start) | 609 | if (start < res->start) |
547 | start += data->mask + 1; | 610 | start += data->mask + 1; |
548 | res->start = start; | 611 | return start; |
549 | } | 612 | } |
550 | 613 | ||
551 | static void | 614 | static resource_size_t |
552 | pcmcia_align(void *align_data, struct resource *res, resource_size_t size, | 615 | pcmcia_align(void *align_data, const struct resource *res, |
553 | resource_size_t align) | 616 | resource_size_t size, resource_size_t align) |
554 | { | 617 | { |
555 | struct pcmcia_align_data *data = align_data; | 618 | struct pcmcia_align_data *data = align_data; |
556 | struct resource_map *m; | 619 | struct resource_map *m; |
620 | resource_size_t start; | ||
557 | 621 | ||
558 | pcmcia_common_align(data, res, size, align); | 622 | start = pcmcia_common_align(data, res, size, align); |
559 | 623 | ||
560 | for (m = data->map->next; m != data->map; m = m->next) { | 624 | for (m = data->map->next; m != data->map; m = m->next) { |
561 | unsigned long start = m->base; | 625 | unsigned long start = m->base; |
@@ -567,8 +631,7 @@ pcmcia_align(void *align_data, struct resource *res, resource_size_t size, | |||
567 | * fit here. | 631 | * fit here. |
568 | */ | 632 | */ |
569 | if (res->start < start) { | 633 | if (res->start < start) { |
570 | res->start = start; | 634 | start = pcmcia_common_align(data, res, size, align); |
571 | pcmcia_common_align(data, res, size, align); | ||
572 | } | 635 | } |
573 | 636 | ||
574 | /* | 637 | /* |
@@ -586,7 +649,9 @@ pcmcia_align(void *align_data, struct resource *res, resource_size_t size, | |||
586 | * If we failed to find something suitable, ensure we fail. | 649 | * If we failed to find something suitable, ensure we fail. |
587 | */ | 650 | */ |
588 | if (m == data->map) | 651 | if (m == data->map) |
589 | res->start = res->end; | 652 | start = res->end; |
653 | |||
654 | return start; | ||
590 | } | 655 | } |
591 | 656 | ||
592 | /* | 657 | /* |
@@ -600,7 +665,6 @@ static int nonstatic_adjust_io_region(struct resource *res, unsigned long r_star | |||
600 | struct socket_data *s_data = s->resource_data; | 665 | struct socket_data *s_data = s->resource_data; |
601 | int ret = -ENOMEM; | 666 | int ret = -ENOMEM; |
602 | 667 | ||
603 | mutex_lock(&rsrc_mutex); | ||
604 | for (m = s_data->io_db.next; m != &s_data->io_db; m = m->next) { | 668 | for (m = s_data->io_db.next; m != &s_data->io_db; m = m->next) { |
605 | unsigned long start = m->base; | 669 | unsigned long start = m->base; |
606 | unsigned long end = m->base + m->num - 1; | 670 | unsigned long end = m->base + m->num - 1; |
@@ -611,7 +675,6 @@ static int nonstatic_adjust_io_region(struct resource *res, unsigned long r_star | |||
611 | ret = adjust_resource(res, r_start, r_end - r_start + 1); | 675 | ret = adjust_resource(res, r_start, r_end - r_start + 1); |
612 | break; | 676 | break; |
613 | } | 677 | } |
614 | mutex_unlock(&rsrc_mutex); | ||
615 | 678 | ||
616 | return ret; | 679 | return ret; |
617 | } | 680 | } |
@@ -645,7 +708,6 @@ static struct resource *nonstatic_find_io_region(unsigned long base, int num, | |||
645 | data.offset = base & data.mask; | 708 | data.offset = base & data.mask; |
646 | data.map = &s_data->io_db; | 709 | data.map = &s_data->io_db; |
647 | 710 | ||
648 | mutex_lock(&rsrc_mutex); | ||
649 | #ifdef CONFIG_PCI | 711 | #ifdef CONFIG_PCI |
650 | if (s->cb_dev) { | 712 | if (s->cb_dev) { |
651 | ret = pci_bus_alloc_resource(s->cb_dev->bus, res, num, 1, | 713 | ret = pci_bus_alloc_resource(s->cb_dev->bus, res, num, 1, |
@@ -654,7 +716,6 @@ static struct resource *nonstatic_find_io_region(unsigned long base, int num, | |||
654 | #endif | 716 | #endif |
655 | ret = allocate_resource(&ioport_resource, res, num, min, ~0UL, | 717 | ret = allocate_resource(&ioport_resource, res, num, min, ~0UL, |
656 | 1, pcmcia_align, &data); | 718 | 1, pcmcia_align, &data); |
657 | mutex_unlock(&rsrc_mutex); | ||
658 | 719 | ||
659 | if (ret != 0) { | 720 | if (ret != 0) { |
660 | kfree(res); | 721 | kfree(res); |
@@ -670,15 +731,15 @@ static struct resource *nonstatic_find_mem_region(u_long base, u_long num, | |||
670 | struct socket_data *s_data = s->resource_data; | 731 | struct socket_data *s_data = s->resource_data; |
671 | struct pcmcia_align_data data; | 732 | struct pcmcia_align_data data; |
672 | unsigned long min, max; | 733 | unsigned long min, max; |
673 | int ret, i; | 734 | int ret, i, j; |
674 | 735 | ||
675 | low = low || !(s->features & SS_CAP_PAGE_REGS); | 736 | low = low || !(s->features & SS_CAP_PAGE_REGS); |
676 | 737 | ||
677 | data.mask = align - 1; | 738 | data.mask = align - 1; |
678 | data.offset = base & data.mask; | 739 | data.offset = base & data.mask; |
679 | data.map = &s_data->mem_db; | ||
680 | 740 | ||
681 | for (i = 0; i < 2; i++) { | 741 | for (i = 0; i < 2; i++) { |
742 | data.map = &s_data->mem_db_valid; | ||
682 | if (low) { | 743 | if (low) { |
683 | max = 0x100000UL; | 744 | max = 0x100000UL; |
684 | min = base < max ? base : 0; | 745 | min = base < max ? base : 0; |
@@ -687,17 +748,23 @@ static struct resource *nonstatic_find_mem_region(u_long base, u_long num, | |||
687 | min = 0x100000UL + base; | 748 | min = 0x100000UL + base; |
688 | } | 749 | } |
689 | 750 | ||
690 | mutex_lock(&rsrc_mutex); | 751 | for (j = 0; j < 2; j++) { |
691 | #ifdef CONFIG_PCI | 752 | #ifdef CONFIG_PCI |
692 | if (s->cb_dev) { | 753 | if (s->cb_dev) { |
693 | ret = pci_bus_alloc_resource(s->cb_dev->bus, res, num, | 754 | ret = pci_bus_alloc_resource(s->cb_dev->bus, |
694 | 1, min, 0, | 755 | res, num, 1, min, 0, |
695 | pcmcia_align, &data); | 756 | pcmcia_align, &data); |
696 | } else | 757 | } else |
697 | #endif | 758 | #endif |
698 | ret = allocate_resource(&iomem_resource, res, num, min, | 759 | { |
699 | max, 1, pcmcia_align, &data); | 760 | ret = allocate_resource(&iomem_resource, |
700 | mutex_unlock(&rsrc_mutex); | 761 | res, num, min, max, 1, |
762 | pcmcia_align, &data); | ||
763 | } | ||
764 | if (ret == 0) | ||
765 | break; | ||
766 | data.map = &s_data->mem_db; | ||
767 | } | ||
701 | if (ret == 0 || low) | 768 | if (ret == 0 || low) |
702 | break; | 769 | break; |
703 | low = 1; | 770 | low = 1; |
@@ -720,25 +787,18 @@ static int adjust_memory(struct pcmcia_socket *s, unsigned int action, unsigned | |||
720 | if (end < start) | 787 | if (end < start) |
721 | return -EINVAL; | 788 | return -EINVAL; |
722 | 789 | ||
723 | mutex_lock(&rsrc_mutex); | ||
724 | switch (action) { | 790 | switch (action) { |
725 | case ADD_MANAGED_RESOURCE: | 791 | case ADD_MANAGED_RESOURCE: |
726 | ret = add_interval(&data->mem_db, start, size); | 792 | ret = add_interval(&data->mem_db, start, size); |
793 | if (!ret) | ||
794 | do_mem_probe(s, start, size, NULL, NULL); | ||
727 | break; | 795 | break; |
728 | case REMOVE_MANAGED_RESOURCE: | 796 | case REMOVE_MANAGED_RESOURCE: |
729 | ret = sub_interval(&data->mem_db, start, size); | 797 | ret = sub_interval(&data->mem_db, start, size); |
730 | if (!ret) { | ||
731 | struct pcmcia_socket *socket; | ||
732 | down_read(&pcmcia_socket_list_rwsem); | ||
733 | list_for_each_entry(socket, &pcmcia_socket_list, socket_list) | ||
734 | release_cis_mem(socket); | ||
735 | up_read(&pcmcia_socket_list_rwsem); | ||
736 | } | ||
737 | break; | 798 | break; |
738 | default: | 799 | default: |
739 | ret = -EINVAL; | 800 | ret = -EINVAL; |
740 | } | 801 | } |
741 | mutex_unlock(&rsrc_mutex); | ||
742 | 802 | ||
743 | return ret; | 803 | return ret; |
744 | } | 804 | } |
@@ -756,7 +816,6 @@ static int adjust_io(struct pcmcia_socket *s, unsigned int action, unsigned long | |||
756 | if (end > IO_SPACE_LIMIT) | 816 | if (end > IO_SPACE_LIMIT) |
757 | return -EINVAL; | 817 | return -EINVAL; |
758 | 818 | ||
759 | mutex_lock(&rsrc_mutex); | ||
760 | switch (action) { | 819 | switch (action) { |
761 | case ADD_MANAGED_RESOURCE: | 820 | case ADD_MANAGED_RESOURCE: |
762 | if (add_interval(&data->io_db, start, size) != 0) { | 821 | if (add_interval(&data->io_db, start, size) != 0) { |
@@ -775,7 +834,6 @@ static int adjust_io(struct pcmcia_socket *s, unsigned int action, unsigned long | |||
775 | ret = -EINVAL; | 834 | ret = -EINVAL; |
776 | break; | 835 | break; |
777 | } | 836 | } |
778 | mutex_unlock(&rsrc_mutex); | ||
779 | 837 | ||
780 | return ret; | 838 | return ret; |
781 | } | 839 | } |
@@ -801,8 +859,7 @@ static int nonstatic_autoadd_resources(struct pcmcia_socket *s) | |||
801 | return -EINVAL; | 859 | return -EINVAL; |
802 | #endif | 860 | #endif |
803 | 861 | ||
804 | for (i = 0; i < PCI_BUS_NUM_RESOURCES; i++) { | 862 | pci_bus_for_each_resource(s->cb_dev->bus, res, i) { |
805 | res = s->cb_dev->bus->resource[i]; | ||
806 | if (!res) | 863 | if (!res) |
807 | continue; | 864 | continue; |
808 | 865 | ||
@@ -859,6 +916,7 @@ static int nonstatic_init(struct pcmcia_socket *s) | |||
859 | return -ENOMEM; | 916 | return -ENOMEM; |
860 | 917 | ||
861 | data->mem_db.next = &data->mem_db; | 918 | data->mem_db.next = &data->mem_db; |
919 | data->mem_db_valid.next = &data->mem_db_valid; | ||
862 | data->io_db.next = &data->io_db; | 920 | data->io_db.next = &data->io_db; |
863 | 921 | ||
864 | s->resource_data = (void *) data; | 922 | s->resource_data = (void *) data; |
@@ -873,7 +931,10 @@ static void nonstatic_release_resource_db(struct pcmcia_socket *s) | |||
873 | struct socket_data *data = s->resource_data; | 931 | struct socket_data *data = s->resource_data; |
874 | struct resource_map *p, *q; | 932 | struct resource_map *p, *q; |
875 | 933 | ||
876 | mutex_lock(&rsrc_mutex); | 934 | for (p = data->mem_db_valid.next; p != &data->mem_db_valid; p = q) { |
935 | q = p->next; | ||
936 | kfree(p); | ||
937 | } | ||
877 | for (p = data->mem_db.next; p != &data->mem_db; p = q) { | 938 | for (p = data->mem_db.next; p != &data->mem_db; p = q) { |
878 | q = p->next; | 939 | q = p->next; |
879 | kfree(p); | 940 | kfree(p); |
@@ -882,7 +943,6 @@ static void nonstatic_release_resource_db(struct pcmcia_socket *s) | |||
882 | q = p->next; | 943 | q = p->next; |
883 | kfree(p); | 944 | kfree(p); |
884 | } | 945 | } |
885 | mutex_unlock(&rsrc_mutex); | ||
886 | } | 946 | } |
887 | 947 | ||
888 | 948 | ||
@@ -909,7 +969,7 @@ static ssize_t show_io_db(struct device *dev, | |||
909 | struct resource_map *p; | 969 | struct resource_map *p; |
910 | ssize_t ret = 0; | 970 | ssize_t ret = 0; |
911 | 971 | ||
912 | mutex_lock(&rsrc_mutex); | 972 | mutex_lock(&s->ops_mutex); |
913 | data = s->resource_data; | 973 | data = s->resource_data; |
914 | 974 | ||
915 | for (p = data->io_db.next; p != &data->io_db; p = p->next) { | 975 | for (p = data->io_db.next; p != &data->io_db; p = p->next) { |
@@ -921,7 +981,7 @@ static ssize_t show_io_db(struct device *dev, | |||
921 | ((unsigned long) p->base + p->num - 1)); | 981 | ((unsigned long) p->base + p->num - 1)); |
922 | } | 982 | } |
923 | 983 | ||
924 | mutex_unlock(&rsrc_mutex); | 984 | mutex_unlock(&s->ops_mutex); |
925 | return ret; | 985 | return ret; |
926 | } | 986 | } |
927 | 987 | ||
@@ -949,9 +1009,11 @@ static ssize_t store_io_db(struct device *dev, | |||
949 | if (end_addr < start_addr) | 1009 | if (end_addr < start_addr) |
950 | return -EINVAL; | 1010 | return -EINVAL; |
951 | 1011 | ||
1012 | mutex_lock(&s->ops_mutex); | ||
952 | ret = adjust_io(s, add, start_addr, end_addr); | 1013 | ret = adjust_io(s, add, start_addr, end_addr); |
953 | if (!ret) | 1014 | if (!ret) |
954 | s->resource_setup_new = 1; | 1015 | s->resource_setup_new = 1; |
1016 | mutex_unlock(&s->ops_mutex); | ||
955 | 1017 | ||
956 | return ret ? ret : count; | 1018 | return ret ? ret : count; |
957 | } | 1019 | } |
@@ -965,9 +1027,19 @@ static ssize_t show_mem_db(struct device *dev, | |||
965 | struct resource_map *p; | 1027 | struct resource_map *p; |
966 | ssize_t ret = 0; | 1028 | ssize_t ret = 0; |
967 | 1029 | ||
968 | mutex_lock(&rsrc_mutex); | 1030 | mutex_lock(&s->ops_mutex); |
969 | data = s->resource_data; | 1031 | data = s->resource_data; |
970 | 1032 | ||
1033 | for (p = data->mem_db_valid.next; p != &data->mem_db_valid; | ||
1034 | p = p->next) { | ||
1035 | if (ret > (PAGE_SIZE - 10)) | ||
1036 | continue; | ||
1037 | ret += snprintf(&buf[ret], (PAGE_SIZE - ret - 1), | ||
1038 | "0x%08lx - 0x%08lx\n", | ||
1039 | ((unsigned long) p->base), | ||
1040 | ((unsigned long) p->base + p->num - 1)); | ||
1041 | } | ||
1042 | |||
971 | for (p = data->mem_db.next; p != &data->mem_db; p = p->next) { | 1043 | for (p = data->mem_db.next; p != &data->mem_db; p = p->next) { |
972 | if (ret > (PAGE_SIZE - 10)) | 1044 | if (ret > (PAGE_SIZE - 10)) |
973 | continue; | 1045 | continue; |
@@ -977,7 +1049,7 @@ static ssize_t show_mem_db(struct device *dev, | |||
977 | ((unsigned long) p->base + p->num - 1)); | 1049 | ((unsigned long) p->base + p->num - 1)); |
978 | } | 1050 | } |
979 | 1051 | ||
980 | mutex_unlock(&rsrc_mutex); | 1052 | mutex_unlock(&s->ops_mutex); |
981 | return ret; | 1053 | return ret; |
982 | } | 1054 | } |
983 | 1055 | ||
@@ -1005,9 +1077,11 @@ static ssize_t store_mem_db(struct device *dev, | |||
1005 | if (end_addr < start_addr) | 1077 | if (end_addr < start_addr) |
1006 | return -EINVAL; | 1078 | return -EINVAL; |
1007 | 1079 | ||
1080 | mutex_lock(&s->ops_mutex); | ||
1008 | ret = adjust_memory(s, add, start_addr, end_addr); | 1081 | ret = adjust_memory(s, add, start_addr, end_addr); |
1009 | if (!ret) | 1082 | if (!ret) |
1010 | s->resource_setup_new = 1; | 1083 | s->resource_setup_new = 1; |
1084 | mutex_unlock(&s->ops_mutex); | ||
1011 | 1085 | ||
1012 | return ret ? ret : count; | 1086 | return ret ? ret : count; |
1013 | } | 1087 | } |
diff --git a/drivers/pcmcia/socket_sysfs.c b/drivers/pcmcia/socket_sysfs.c index 7a456000332a..08278016e58d 100644 --- a/drivers/pcmcia/socket_sysfs.c +++ b/drivers/pcmcia/socket_sysfs.c | |||
@@ -88,15 +88,14 @@ static DEVICE_ATTR(card_vcc, 0444, pccard_show_vcc, NULL); | |||
88 | static ssize_t pccard_store_insert(struct device *dev, struct device_attribute *attr, | 88 | static ssize_t pccard_store_insert(struct device *dev, struct device_attribute *attr, |
89 | const char *buf, size_t count) | 89 | const char *buf, size_t count) |
90 | { | 90 | { |
91 | ssize_t ret; | ||
92 | struct pcmcia_socket *s = to_socket(dev); | 91 | struct pcmcia_socket *s = to_socket(dev); |
93 | 92 | ||
94 | if (!count) | 93 | if (!count) |
95 | return -EINVAL; | 94 | return -EINVAL; |
96 | 95 | ||
97 | ret = pcmcia_insert_card(s); | 96 | pcmcia_parse_uevents(s, PCMCIA_UEVENT_INSERT); |
98 | 97 | ||
99 | return ret ? ret : count; | 98 | return count; |
100 | } | 99 | } |
101 | static DEVICE_ATTR(card_insert, 0200, NULL, pccard_store_insert); | 100 | static DEVICE_ATTR(card_insert, 0200, NULL, pccard_store_insert); |
102 | 101 | ||
@@ -113,18 +112,22 @@ static ssize_t pccard_store_card_pm_state(struct device *dev, | |||
113 | struct device_attribute *attr, | 112 | struct device_attribute *attr, |
114 | const char *buf, size_t count) | 113 | const char *buf, size_t count) |
115 | { | 114 | { |
116 | ssize_t ret = -EINVAL; | ||
117 | struct pcmcia_socket *s = to_socket(dev); | 115 | struct pcmcia_socket *s = to_socket(dev); |
116 | ssize_t ret = count; | ||
118 | 117 | ||
119 | if (!count) | 118 | if (!count) |
120 | return -EINVAL; | 119 | return -EINVAL; |
121 | 120 | ||
122 | if (!(s->state & SOCKET_SUSPEND) && !strncmp(buf, "off", 3)) | 121 | if (!strncmp(buf, "off", 3)) |
123 | ret = pcmcia_suspend_card(s); | 122 | pcmcia_parse_uevents(s, PCMCIA_UEVENT_SUSPEND); |
124 | else if ((s->state & SOCKET_SUSPEND) && !strncmp(buf, "on", 2)) | 123 | else { |
125 | ret = pcmcia_resume_card(s); | 124 | if (!strncmp(buf, "on", 2)) |
125 | pcmcia_parse_uevents(s, PCMCIA_UEVENT_RESUME); | ||
126 | else | ||
127 | ret = -EINVAL; | ||
128 | } | ||
126 | 129 | ||
127 | return ret ? -ENODEV : count; | 130 | return ret; |
128 | } | 131 | } |
129 | static DEVICE_ATTR(card_pm_state, 0644, pccard_show_card_pm_state, pccard_store_card_pm_state); | 132 | static DEVICE_ATTR(card_pm_state, 0644, pccard_show_card_pm_state, pccard_store_card_pm_state); |
130 | 133 | ||
@@ -132,15 +135,14 @@ static ssize_t pccard_store_eject(struct device *dev, | |||
132 | struct device_attribute *attr, | 135 | struct device_attribute *attr, |
133 | const char *buf, size_t count) | 136 | const char *buf, size_t count) |
134 | { | 137 | { |
135 | ssize_t ret; | ||
136 | struct pcmcia_socket *s = to_socket(dev); | 138 | struct pcmcia_socket *s = to_socket(dev); |
137 | 139 | ||
138 | if (!count) | 140 | if (!count) |
139 | return -EINVAL; | 141 | return -EINVAL; |
140 | 142 | ||
141 | ret = pcmcia_eject_card(s); | 143 | pcmcia_parse_uevents(s, PCMCIA_UEVENT_EJECT); |
142 | 144 | ||
143 | return ret ? ret : count; | 145 | return count; |
144 | } | 146 | } |
145 | static DEVICE_ATTR(card_eject, 0200, NULL, pccard_store_eject); | 147 | static DEVICE_ATTR(card_eject, 0200, NULL, pccard_store_eject); |
146 | 148 | ||
@@ -167,7 +169,9 @@ static ssize_t pccard_store_irq_mask(struct device *dev, | |||
167 | ret = sscanf(buf, "0x%x\n", &mask); | 169 | ret = sscanf(buf, "0x%x\n", &mask); |
168 | 170 | ||
169 | if (ret == 1) { | 171 | if (ret == 1) { |
172 | mutex_lock(&s->ops_mutex); | ||
170 | s->irq_mask &= mask; | 173 | s->irq_mask &= mask; |
174 | mutex_unlock(&s->ops_mutex); | ||
171 | ret = 0; | 175 | ret = 0; |
172 | } | 176 | } |
173 | 177 | ||
@@ -187,163 +191,21 @@ static ssize_t pccard_store_resource(struct device *dev, | |||
187 | struct device_attribute *attr, | 191 | struct device_attribute *attr, |
188 | const char *buf, size_t count) | 192 | const char *buf, size_t count) |
189 | { | 193 | { |
190 | unsigned long flags; | ||
191 | struct pcmcia_socket *s = to_socket(dev); | 194 | struct pcmcia_socket *s = to_socket(dev); |
192 | 195 | ||
193 | if (!count) | 196 | if (!count) |
194 | return -EINVAL; | 197 | return -EINVAL; |
195 | 198 | ||
196 | spin_lock_irqsave(&s->lock, flags); | 199 | mutex_lock(&s->ops_mutex); |
197 | if (!s->resource_setup_done) | 200 | if (!s->resource_setup_done) |
198 | s->resource_setup_done = 1; | 201 | s->resource_setup_done = 1; |
199 | spin_unlock_irqrestore(&s->lock, flags); | 202 | mutex_unlock(&s->ops_mutex); |
200 | |||
201 | mutex_lock(&s->skt_mutex); | ||
202 | if ((s->callback) && | ||
203 | (s->state & SOCKET_PRESENT) && | ||
204 | !(s->state & SOCKET_CARDBUS)) { | ||
205 | if (try_module_get(s->callback->owner)) { | ||
206 | s->callback->requery(s, 0); | ||
207 | module_put(s->callback->owner); | ||
208 | } | ||
209 | } | ||
210 | mutex_unlock(&s->skt_mutex); | ||
211 | |||
212 | return count; | ||
213 | } | ||
214 | static DEVICE_ATTR(available_resources_setup_done, 0600, pccard_show_resource, pccard_store_resource); | ||
215 | 203 | ||
216 | 204 | pcmcia_parse_uevents(s, PCMCIA_UEVENT_REQUERY); | |
217 | static ssize_t pccard_extract_cis(struct pcmcia_socket *s, char *buf, loff_t off, size_t count) | ||
218 | { | ||
219 | tuple_t tuple; | ||
220 | int status, i; | ||
221 | loff_t pointer = 0; | ||
222 | ssize_t ret = 0; | ||
223 | u_char *tuplebuffer; | ||
224 | u_char *tempbuffer; | ||
225 | |||
226 | tuplebuffer = kmalloc(sizeof(u_char) * 256, GFP_KERNEL); | ||
227 | if (!tuplebuffer) | ||
228 | return -ENOMEM; | ||
229 | |||
230 | tempbuffer = kmalloc(sizeof(u_char) * 258, GFP_KERNEL); | ||
231 | if (!tempbuffer) { | ||
232 | ret = -ENOMEM; | ||
233 | goto free_tuple; | ||
234 | } | ||
235 | |||
236 | memset(&tuple, 0, sizeof(tuple_t)); | ||
237 | |||
238 | tuple.Attributes = TUPLE_RETURN_LINK | TUPLE_RETURN_COMMON; | ||
239 | tuple.DesiredTuple = RETURN_FIRST_TUPLE; | ||
240 | tuple.TupleOffset = 0; | ||
241 | |||
242 | status = pccard_get_first_tuple(s, BIND_FN_ALL, &tuple); | ||
243 | while (!status) { | ||
244 | tuple.TupleData = tuplebuffer; | ||
245 | tuple.TupleDataMax = 255; | ||
246 | memset(tuplebuffer, 0, sizeof(u_char) * 255); | ||
247 | |||
248 | status = pccard_get_tuple_data(s, &tuple); | ||
249 | if (status) | ||
250 | break; | ||
251 | |||
252 | if (off < (pointer + 2 + tuple.TupleDataLen)) { | ||
253 | tempbuffer[0] = tuple.TupleCode & 0xff; | ||
254 | tempbuffer[1] = tuple.TupleLink & 0xff; | ||
255 | for (i = 0; i < tuple.TupleDataLen; i++) | ||
256 | tempbuffer[i + 2] = tuplebuffer[i] & 0xff; | ||
257 | |||
258 | for (i = 0; i < (2 + tuple.TupleDataLen); i++) { | ||
259 | if (((i + pointer) >= off) && | ||
260 | (i + pointer) < (off + count)) { | ||
261 | buf[ret] = tempbuffer[i]; | ||
262 | ret++; | ||
263 | } | ||
264 | } | ||
265 | } | ||
266 | |||
267 | pointer += 2 + tuple.TupleDataLen; | ||
268 | |||
269 | if (pointer >= (off + count)) | ||
270 | break; | ||
271 | |||
272 | if (tuple.TupleCode == CISTPL_END) | ||
273 | break; | ||
274 | status = pccard_get_next_tuple(s, BIND_FN_ALL, &tuple); | ||
275 | } | ||
276 | |||
277 | kfree(tempbuffer); | ||
278 | free_tuple: | ||
279 | kfree(tuplebuffer); | ||
280 | |||
281 | return ret; | ||
282 | } | ||
283 | |||
284 | static ssize_t pccard_show_cis(struct kobject *kobj, | ||
285 | struct bin_attribute *bin_attr, | ||
286 | char *buf, loff_t off, size_t count) | ||
287 | { | ||
288 | unsigned int size = 0x200; | ||
289 | |||
290 | if (off >= size) | ||
291 | count = 0; | ||
292 | else { | ||
293 | struct pcmcia_socket *s; | ||
294 | unsigned int chains; | ||
295 | |||
296 | if (off + count > size) | ||
297 | count = size - off; | ||
298 | |||
299 | s = to_socket(container_of(kobj, struct device, kobj)); | ||
300 | |||
301 | if (!(s->state & SOCKET_PRESENT)) | ||
302 | return -ENODEV; | ||
303 | if (pccard_validate_cis(s, &chains)) | ||
304 | return -EIO; | ||
305 | if (!chains) | ||
306 | return -ENODATA; | ||
307 | |||
308 | count = pccard_extract_cis(s, buf, off, count); | ||
309 | } | ||
310 | |||
311 | return count; | ||
312 | } | ||
313 | |||
314 | static ssize_t pccard_store_cis(struct kobject *kobj, | ||
315 | struct bin_attribute *bin_attr, | ||
316 | char *buf, loff_t off, size_t count) | ||
317 | { | ||
318 | struct pcmcia_socket *s = to_socket(container_of(kobj, struct device, kobj)); | ||
319 | int error; | ||
320 | |||
321 | if (off) | ||
322 | return -EINVAL; | ||
323 | |||
324 | if (count >= CISTPL_MAX_CIS_SIZE) | ||
325 | return -EINVAL; | ||
326 | |||
327 | if (!(s->state & SOCKET_PRESENT)) | ||
328 | return -ENODEV; | ||
329 | |||
330 | error = pcmcia_replace_cis(s, buf, count); | ||
331 | if (error) | ||
332 | return -EIO; | ||
333 | |||
334 | mutex_lock(&s->skt_mutex); | ||
335 | if ((s->callback) && (s->state & SOCKET_PRESENT) && | ||
336 | !(s->state & SOCKET_CARDBUS)) { | ||
337 | if (try_module_get(s->callback->owner)) { | ||
338 | s->callback->requery(s, 1); | ||
339 | module_put(s->callback->owner); | ||
340 | } | ||
341 | } | ||
342 | mutex_unlock(&s->skt_mutex); | ||
343 | 205 | ||
344 | return count; | 206 | return count; |
345 | } | 207 | } |
346 | 208 | static DEVICE_ATTR(available_resources_setup_done, 0600, pccard_show_resource, pccard_store_resource); | |
347 | 209 | ||
348 | static struct attribute *pccard_socket_attributes[] = { | 210 | static struct attribute *pccard_socket_attributes[] = { |
349 | &dev_attr_card_type.attr, | 211 | &dev_attr_card_type.attr, |
@@ -362,28 +224,12 @@ static const struct attribute_group socket_attrs = { | |||
362 | .attrs = pccard_socket_attributes, | 224 | .attrs = pccard_socket_attributes, |
363 | }; | 225 | }; |
364 | 226 | ||
365 | static struct bin_attribute pccard_cis_attr = { | ||
366 | .attr = { .name = "cis", .mode = S_IRUGO | S_IWUSR }, | ||
367 | .size = 0x200, | ||
368 | .read = pccard_show_cis, | ||
369 | .write = pccard_store_cis, | ||
370 | }; | ||
371 | |||
372 | int pccard_sysfs_add_socket(struct device *dev) | 227 | int pccard_sysfs_add_socket(struct device *dev) |
373 | { | 228 | { |
374 | int ret = 0; | 229 | return sysfs_create_group(&dev->kobj, &socket_attrs); |
375 | |||
376 | ret = sysfs_create_group(&dev->kobj, &socket_attrs); | ||
377 | if (!ret) { | ||
378 | ret = sysfs_create_bin_file(&dev->kobj, &pccard_cis_attr); | ||
379 | if (ret) | ||
380 | sysfs_remove_group(&dev->kobj, &socket_attrs); | ||
381 | } | ||
382 | return ret; | ||
383 | } | 230 | } |
384 | 231 | ||
385 | void pccard_sysfs_remove_socket(struct device *dev) | 232 | void pccard_sysfs_remove_socket(struct device *dev) |
386 | { | 233 | { |
387 | sysfs_remove_bin_file(&dev->kobj, &pccard_cis_attr); | ||
388 | sysfs_remove_group(&dev->kobj, &socket_attrs); | 234 | sysfs_remove_group(&dev->kobj, &socket_attrs); |
389 | } | 235 | } |
diff --git a/drivers/pcmcia/xxs1500_ss.c b/drivers/pcmcia/xxs1500_ss.c new file mode 100644 index 000000000000..61560cd6e287 --- /dev/null +++ b/drivers/pcmcia/xxs1500_ss.c | |||
@@ -0,0 +1,350 @@ | |||
1 | /* | ||
2 | * PCMCIA socket code for the MyCable XXS1500 system. | ||
3 | * | ||
4 | * Copyright (c) 2009 Manuel Lauss <manuel.lauss@gmail.com> | ||
5 | * | ||
6 | */ | ||
7 | |||
8 | #include <linux/delay.h> | ||
9 | #include <linux/gpio.h> | ||
10 | #include <linux/interrupt.h> | ||
11 | #include <linux/io.h> | ||
12 | #include <linux/ioport.h> | ||
13 | #include <linux/mm.h> | ||
14 | #include <linux/platform_device.h> | ||
15 | #include <linux/pm.h> | ||
16 | #include <linux/resource.h> | ||
17 | #include <linux/spinlock.h> | ||
18 | |||
19 | #include <pcmcia/cs_types.h> | ||
20 | #include <pcmcia/cs.h> | ||
21 | #include <pcmcia/ss.h> | ||
22 | #include <pcmcia/cistpl.h> | ||
23 | |||
24 | #include <asm/irq.h> | ||
25 | #include <asm/system.h> | ||
26 | #include <asm/mach-au1x00/au1000.h> | ||
27 | |||
28 | #define MEM_MAP_SIZE 0x400000 | ||
29 | #define IO_MAP_SIZE 0x1000 | ||
30 | |||
31 | |||
32 | /* | ||
33 | * 3.3V cards only; all interfacing is done via gpios: | ||
34 | * | ||
35 | * 0/1: carddetect (00 = card present, xx = huh) | ||
36 | * 4: card irq | ||
37 | * 204: reset (high-act) | ||
38 | * 205: buffer enable (low-act) | ||
39 | * 208/209: card voltage key (00,01,10,11) | ||
40 | * 210: battwarn | ||
41 | * 211: batdead | ||
42 | * 214: power (low-act) | ||
43 | */ | ||
44 | #define GPIO_CDA 0 | ||
45 | #define GPIO_CDB 1 | ||
46 | #define GPIO_CARDIRQ 4 | ||
47 | #define GPIO_RESET 204 | ||
48 | #define GPIO_OUTEN 205 | ||
49 | #define GPIO_VSL 208 | ||
50 | #define GPIO_VSH 209 | ||
51 | #define GPIO_BATTDEAD 210 | ||
52 | #define GPIO_BATTWARN 211 | ||
53 | #define GPIO_POWER 214 | ||
54 | |||
55 | struct xxs1500_pcmcia_sock { | ||
56 | struct pcmcia_socket socket; | ||
57 | void *virt_io; | ||
58 | |||
59 | phys_addr_t phys_io; | ||
60 | phys_addr_t phys_attr; | ||
61 | phys_addr_t phys_mem; | ||
62 | |||
63 | /* previous flags for set_socket() */ | ||
64 | unsigned int old_flags; | ||
65 | }; | ||
66 | |||
67 | #define to_xxs_socket(x) container_of(x, struct xxs1500_pcmcia_sock, socket) | ||
68 | |||
69 | static irqreturn_t cdirq(int irq, void *data) | ||
70 | { | ||
71 | struct xxs1500_pcmcia_sock *sock = data; | ||
72 | |||
73 | pcmcia_parse_events(&sock->socket, SS_DETECT); | ||
74 | |||
75 | return IRQ_HANDLED; | ||
76 | } | ||
77 | |||
78 | static int xxs1500_pcmcia_configure(struct pcmcia_socket *skt, | ||
79 | struct socket_state_t *state) | ||
80 | { | ||
81 | struct xxs1500_pcmcia_sock *sock = to_xxs_socket(skt); | ||
82 | unsigned int changed; | ||
83 | |||
84 | /* power control */ | ||
85 | switch (state->Vcc) { | ||
86 | case 0: | ||
87 | gpio_set_value(GPIO_POWER, 1); /* power off */ | ||
88 | break; | ||
89 | case 33: | ||
90 | gpio_set_value(GPIO_POWER, 0); /* power on */ | ||
91 | break; | ||
92 | case 50: | ||
93 | default: | ||
94 | return -EINVAL; | ||
95 | } | ||
96 | |||
97 | changed = state->flags ^ sock->old_flags; | ||
98 | |||
99 | if (changed & SS_RESET) { | ||
100 | if (state->flags & SS_RESET) { | ||
101 | gpio_set_value(GPIO_RESET, 1); /* assert reset */ | ||
102 | gpio_set_value(GPIO_OUTEN, 1); /* buffers off */ | ||
103 | } else { | ||
104 | gpio_set_value(GPIO_RESET, 0); /* deassert reset */ | ||
105 | gpio_set_value(GPIO_OUTEN, 0); /* buffers on */ | ||
106 | msleep(500); | ||
107 | } | ||
108 | } | ||
109 | |||
110 | sock->old_flags = state->flags; | ||
111 | |||
112 | return 0; | ||
113 | } | ||
114 | |||
115 | static int xxs1500_pcmcia_get_status(struct pcmcia_socket *skt, | ||
116 | unsigned int *value) | ||
117 | { | ||
118 | unsigned int status; | ||
119 | int i; | ||
120 | |||
121 | status = 0; | ||
122 | |||
123 | /* check carddetects: GPIO[0:1] must both be low */ | ||
124 | if (!gpio_get_value(GPIO_CDA) && !gpio_get_value(GPIO_CDB)) | ||
125 | status |= SS_DETECT; | ||
126 | |||
127 | /* determine card voltage: GPIO[208:209] binary value */ | ||
128 | i = (!!gpio_get_value(GPIO_VSL)) | ((!!gpio_get_value(GPIO_VSH)) << 1); | ||
129 | |||
130 | switch (i) { | ||
131 | case 0: | ||
132 | case 1: | ||
133 | case 2: | ||
134 | status |= SS_3VCARD; /* 3V card */ | ||
135 | break; | ||
136 | case 3: /* 5V card, unsupported */ | ||
137 | default: | ||
138 | status |= SS_XVCARD; /* treated as unsupported in core */ | ||
139 | } | ||
140 | |||
141 | /* GPIO214: low active power switch */ | ||
142 | status |= gpio_get_value(GPIO_POWER) ? 0 : SS_POWERON; | ||
143 | |||
144 | /* GPIO204: high-active reset line */ | ||
145 | status |= gpio_get_value(GPIO_RESET) ? SS_RESET : SS_READY; | ||
146 | |||
147 | /* other stuff */ | ||
148 | status |= gpio_get_value(GPIO_BATTDEAD) ? 0 : SS_BATDEAD; | ||
149 | status |= gpio_get_value(GPIO_BATTWARN) ? 0 : SS_BATWARN; | ||
150 | |||
151 | *value = status; | ||
152 | |||
153 | return 0; | ||
154 | } | ||
155 | |||
156 | static int xxs1500_pcmcia_sock_init(struct pcmcia_socket *skt) | ||
157 | { | ||
158 | gpio_direction_input(GPIO_CDA); | ||
159 | gpio_direction_input(GPIO_CDB); | ||
160 | gpio_direction_input(GPIO_VSL); | ||
161 | gpio_direction_input(GPIO_VSH); | ||
162 | gpio_direction_input(GPIO_BATTDEAD); | ||
163 | gpio_direction_input(GPIO_BATTWARN); | ||
164 | gpio_direction_output(GPIO_RESET, 1); /* assert reset */ | ||
165 | gpio_direction_output(GPIO_OUTEN, 1); /* disable buffers */ | ||
166 | gpio_direction_output(GPIO_POWER, 1); /* power off */ | ||
167 | |||
168 | return 0; | ||
169 | } | ||
170 | |||
171 | static int xxs1500_pcmcia_sock_suspend(struct pcmcia_socket *skt) | ||
172 | { | ||
173 | return 0; | ||
174 | } | ||
175 | |||
176 | static int au1x00_pcmcia_set_io_map(struct pcmcia_socket *skt, | ||
177 | struct pccard_io_map *map) | ||
178 | { | ||
179 | struct xxs1500_pcmcia_sock *sock = to_xxs_socket(skt); | ||
180 | |||
181 | map->start = (u32)sock->virt_io; | ||
182 | map->stop = map->start + IO_MAP_SIZE; | ||
183 | |||
184 | return 0; | ||
185 | } | ||
186 | |||
187 | static int au1x00_pcmcia_set_mem_map(struct pcmcia_socket *skt, | ||
188 | struct pccard_mem_map *map) | ||
189 | { | ||
190 | struct xxs1500_pcmcia_sock *sock = to_xxs_socket(skt); | ||
191 | |||
192 | if (map->flags & MAP_ATTRIB) | ||
193 | map->static_start = sock->phys_attr + map->card_start; | ||
194 | else | ||
195 | map->static_start = sock->phys_mem + map->card_start; | ||
196 | |||
197 | return 0; | ||
198 | } | ||
199 | |||
200 | static struct pccard_operations xxs1500_pcmcia_operations = { | ||
201 | .init = xxs1500_pcmcia_sock_init, | ||
202 | .suspend = xxs1500_pcmcia_sock_suspend, | ||
203 | .get_status = xxs1500_pcmcia_get_status, | ||
204 | .set_socket = xxs1500_pcmcia_configure, | ||
205 | .set_io_map = au1x00_pcmcia_set_io_map, | ||
206 | .set_mem_map = au1x00_pcmcia_set_mem_map, | ||
207 | }; | ||
208 | |||
209 | static int __devinit xxs1500_pcmcia_probe(struct platform_device *pdev) | ||
210 | { | ||
211 | struct xxs1500_pcmcia_sock *sock; | ||
212 | struct resource *r; | ||
213 | int ret, irq; | ||
214 | |||
215 | sock = kzalloc(sizeof(struct xxs1500_pcmcia_sock), GFP_KERNEL); | ||
216 | if (!sock) | ||
217 | return -ENOMEM; | ||
218 | |||
219 | ret = -ENODEV; | ||
220 | |||
221 | /* | ||
222 | * pseudo-attr: The 32bit address of the PCMCIA attribute space | ||
223 | * for this socket (usually the 36bit address shifted 4 to the | ||
224 | * right). | ||
225 | */ | ||
226 | r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pcmcia-attr"); | ||
227 | if (!r) { | ||
228 | dev_err(&pdev->dev, "missing 'pcmcia-attr' resource!\n"); | ||
229 | goto out0; | ||
230 | } | ||
231 | sock->phys_attr = r->start; | ||
232 | |||
233 | /* | ||
234 | * pseudo-mem: The 32bit address of the PCMCIA memory space for | ||
235 | * this socket (usually the 36bit address shifted 4 to the right) | ||
236 | */ | ||
237 | r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pcmcia-mem"); | ||
238 | if (!r) { | ||
239 | dev_err(&pdev->dev, "missing 'pcmcia-mem' resource!\n"); | ||
240 | goto out0; | ||
241 | } | ||
242 | sock->phys_mem = r->start; | ||
243 | |||
244 | /* | ||
245 | * pseudo-io: The 32bit address of the PCMCIA IO space for this | ||
246 | * socket (usually the 36bit address shifted 4 to the right). | ||
247 | */ | ||
248 | r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pcmcia-io"); | ||
249 | if (!r) { | ||
250 | dev_err(&pdev->dev, "missing 'pcmcia-io' resource!\n"); | ||
251 | goto out0; | ||
252 | } | ||
253 | sock->phys_io = r->start; | ||
254 | |||
255 | |||
256 | /* | ||
257 | * PCMCIA client drivers use the inb/outb macros to access | ||
258 | * the IO registers. Since mips_io_port_base is added | ||
259 | * to the access address of the mips implementation of | ||
260 | * inb/outb, we need to subtract it here because we want | ||
261 | * to access the I/O or MEM address directly, without | ||
262 | * going through this "mips_io_port_base" mechanism. | ||
263 | */ | ||
264 | sock->virt_io = (void *)(ioremap(sock->phys_io, IO_MAP_SIZE) - | ||
265 | mips_io_port_base); | ||
266 | |||
267 | if (!sock->virt_io) { | ||
268 | dev_err(&pdev->dev, "cannot remap IO area\n"); | ||
269 | ret = -ENOMEM; | ||
270 | goto out0; | ||
271 | } | ||
272 | |||
273 | sock->socket.ops = &xxs1500_pcmcia_operations; | ||
274 | sock->socket.owner = THIS_MODULE; | ||
275 | sock->socket.pci_irq = gpio_to_irq(GPIO_CARDIRQ); | ||
276 | sock->socket.features = SS_CAP_STATIC_MAP | SS_CAP_PCCARD; | ||
277 | sock->socket.map_size = MEM_MAP_SIZE; | ||
278 | sock->socket.io_offset = (unsigned long)sock->virt_io; | ||
279 | sock->socket.dev.parent = &pdev->dev; | ||
280 | sock->socket.resource_ops = &pccard_static_ops; | ||
281 | |||
282 | platform_set_drvdata(pdev, sock); | ||
283 | |||
284 | /* setup carddetect irq: use one of the 2 GPIOs as an | ||
285 | * edge detector. | ||
286 | */ | ||
287 | irq = gpio_to_irq(GPIO_CDA); | ||
288 | set_irq_type(irq, IRQ_TYPE_EDGE_BOTH); | ||
289 | ret = request_irq(irq, cdirq, 0, "pcmcia_carddetect", sock); | ||
290 | if (ret) { | ||
291 | dev_err(&pdev->dev, "cannot setup cd irq\n"); | ||
292 | goto out1; | ||
293 | } | ||
294 | |||
295 | ret = pcmcia_register_socket(&sock->socket); | ||
296 | if (ret) { | ||
297 | dev_err(&pdev->dev, "failed to register\n"); | ||
298 | goto out2; | ||
299 | } | ||
300 | |||
301 | printk(KERN_INFO "MyCable XXS1500 PCMCIA socket services\n"); | ||
302 | |||
303 | return 0; | ||
304 | |||
305 | out2: | ||
306 | free_irq(gpio_to_irq(GPIO_CDA), sock); | ||
307 | out1: | ||
308 | iounmap((void *)(sock->virt_io + (u32)mips_io_port_base)); | ||
309 | out0: | ||
310 | kfree(sock); | ||
311 | return ret; | ||
312 | } | ||
313 | |||
314 | static int __devexit xxs1500_pcmcia_remove(struct platform_device *pdev) | ||
315 | { | ||
316 | struct xxs1500_pcmcia_sock *sock = platform_get_drvdata(pdev); | ||
317 | |||
318 | pcmcia_unregister_socket(&sock->socket); | ||
319 | free_irq(gpio_to_irq(GPIO_CDA), sock); | ||
320 | iounmap((void *)(sock->virt_io + (u32)mips_io_port_base)); | ||
321 | kfree(sock); | ||
322 | |||
323 | return 0; | ||
324 | } | ||
325 | |||
326 | static struct platform_driver xxs1500_pcmcia_socket_driver = { | ||
327 | .driver = { | ||
328 | .name = "xxs1500_pcmcia", | ||
329 | .owner = THIS_MODULE, | ||
330 | }, | ||
331 | .probe = xxs1500_pcmcia_probe, | ||
332 | .remove = __devexit_p(xxs1500_pcmcia_remove), | ||
333 | }; | ||
334 | |||
335 | int __init xxs1500_pcmcia_socket_load(void) | ||
336 | { | ||
337 | return platform_driver_register(&xxs1500_pcmcia_socket_driver); | ||
338 | } | ||
339 | |||
340 | void __exit xxs1500_pcmcia_socket_unload(void) | ||
341 | { | ||
342 | platform_driver_unregister(&xxs1500_pcmcia_socket_driver); | ||
343 | } | ||
344 | |||
345 | module_init(xxs1500_pcmcia_socket_load); | ||
346 | module_exit(xxs1500_pcmcia_socket_unload); | ||
347 | |||
348 | MODULE_LICENSE("GPL"); | ||
349 | MODULE_DESCRIPTION("PCMCIA Socket Services for MyCable XXS1500 systems"); | ||
350 | MODULE_AUTHOR("Manuel Lauss"); | ||
diff --git a/drivers/pcmcia/yenta_socket.c b/drivers/pcmcia/yenta_socket.c index e4d12acdd525..b85375f87622 100644 --- a/drivers/pcmcia/yenta_socket.c +++ b/drivers/pcmcia/yenta_socket.c | |||
@@ -37,6 +37,11 @@ static int pwr_irqs_off; | |||
37 | module_param(pwr_irqs_off, bool, 0644); | 37 | module_param(pwr_irqs_off, bool, 0644); |
38 | MODULE_PARM_DESC(pwr_irqs_off, "Force IRQs off during power-on of slot. Use only when seeing IRQ storms!"); | 38 | MODULE_PARM_DESC(pwr_irqs_off, "Force IRQs off during power-on of slot. Use only when seeing IRQ storms!"); |
39 | 39 | ||
40 | static char o2_speedup[] = "default"; | ||
41 | module_param_string(o2_speedup, o2_speedup, sizeof(o2_speedup), 0444); | ||
42 | MODULE_PARM_DESC(o2_speedup, "Use prefetch/burst for O2-bridges: 'on', 'off' " | ||
43 | "or 'default' (uses recommended behaviour for the detected bridge)"); | ||
44 | |||
40 | #define debug(x, s, args...) dev_dbg(&s->dev->dev, x, ##args) | 45 | #define debug(x, s, args...) dev_dbg(&s->dev->dev, x, ##args) |
41 | 46 | ||
42 | /* Don't ask.. */ | 47 | /* Don't ask.. */ |
@@ -649,9 +654,10 @@ static int yenta_search_one_res(struct resource *root, struct resource *res, | |||
649 | static int yenta_search_res(struct yenta_socket *socket, struct resource *res, | 654 | static int yenta_search_res(struct yenta_socket *socket, struct resource *res, |
650 | u32 min) | 655 | u32 min) |
651 | { | 656 | { |
657 | struct resource *root; | ||
652 | int i; | 658 | int i; |
653 | for (i = 0; i < PCI_BUS_NUM_RESOURCES; i++) { | 659 | |
654 | struct resource *root = socket->dev->bus->resource[i]; | 660 | pci_bus_for_each_resource(socket->dev->bus, root, i) { |
655 | if (!root) | 661 | if (!root) |
656 | continue; | 662 | continue; |
657 | 663 | ||