diff options
Diffstat (limited to 'drivers/pcmcia')
29 files changed, 3007 insertions, 2824 deletions
diff --git a/drivers/pcmcia/Kconfig b/drivers/pcmcia/Kconfig index 9f3adbd9f700..d189e4743e69 100644 --- a/drivers/pcmcia/Kconfig +++ b/drivers/pcmcia/Kconfig | |||
@@ -51,17 +51,23 @@ config PCMCIA_LOAD_CIS | |||
51 | 51 | ||
52 | config PCMCIA_IOCTL | 52 | config PCMCIA_IOCTL |
53 | bool "PCMCIA control ioctl (obsolete)" | 53 | bool "PCMCIA control ioctl (obsolete)" |
54 | depends on PCMCIA | 54 | depends on PCMCIA && ARM && !SMP && !PREEMPT |
55 | default y | 55 | default y |
56 | help | 56 | help |
57 | If you say Y here, the deprecated ioctl interface to the PCMCIA | 57 | If you say Y here, the deprecated ioctl interface to the PCMCIA |
58 | subsystem will be built. It is needed by cardmgr and cardctl | 58 | subsystem will be built. It is needed by the deprecated pcmcia-cs |
59 | (pcmcia-cs) to function properly. | 59 | tools (cardmgr, cardctl) to function properly. |
60 | 60 | ||
61 | You should use the new pcmciautils package instead (see | 61 | You should use the new pcmciautils package instead (see |
62 | <file:Documentation/Changes> for location and details). | 62 | <file:Documentation/Changes> for location and details). |
63 | 63 | ||
64 | If unsure, say Y. | 64 | This config option will most likely be removed from kernel 2.6.35, |
65 | the associated code from kernel 2.6.36. | ||
66 | |||
67 | As the PCMCIA ioctl is not locking safe, it depends on !SMP and | ||
68 | !PREEMPT. | ||
69 | |||
70 | If unsure, say N. | ||
65 | 71 | ||
66 | config CARDBUS | 72 | config CARDBUS |
67 | bool "32-bit CardBus support" | 73 | bool "32-bit CardBus support" |
@@ -84,7 +90,7 @@ config YENTA | |||
84 | tristate "CardBus yenta-compatible bridge support" | 90 | tristate "CardBus yenta-compatible bridge support" |
85 | depends on PCI | 91 | depends on PCI |
86 | select CARDBUS if !EMBEDDED | 92 | select CARDBUS if !EMBEDDED |
87 | select PCCARD_NONSTATIC | 93 | select PCCARD_NONSTATIC if PCMCIA != n |
88 | ---help--- | 94 | ---help--- |
89 | This option enables support for CardBus host bridges. Virtually | 95 | This option enables support for CardBus host bridges. Virtually |
90 | all modern PCMCIA bridges are CardBus compatible. A "bridge" is | 96 | all modern PCMCIA bridges are CardBus compatible. A "bridge" is |
@@ -161,9 +167,8 @@ config TCIC | |||
161 | 167 | ||
162 | config PCMCIA_M8XX | 168 | config PCMCIA_M8XX |
163 | tristate "MPC8xx PCMCIA support" | 169 | tristate "MPC8xx PCMCIA support" |
164 | depends on PCMCIA && PPC && 8xx | 170 | depends on PCCARD && PPC && 8xx |
165 | select PCCARD_IODYN | 171 | select PCCARD_IODYN if PCMCIA != n |
166 | select PCCARD_NONSTATIC | ||
167 | help | 172 | help |
168 | Say Y here to include support for PowerPC 8xx series PCMCIA | 173 | Say Y here to include support for PowerPC 8xx series PCMCIA |
169 | controller. | 174 | controller. |
@@ -174,6 +179,27 @@ config PCMCIA_AU1X00 | |||
174 | tristate "Au1x00 pcmcia support" | 179 | tristate "Au1x00 pcmcia support" |
175 | depends on SOC_AU1X00 && PCMCIA | 180 | depends on SOC_AU1X00 && PCMCIA |
176 | 181 | ||
182 | config PCMCIA_ALCHEMY_DEVBOARD | ||
183 | tristate "Alchemy Db/Pb1xxx PCMCIA socket services" | ||
184 | depends on SOC_AU1X00 && PCMCIA | ||
185 | select 64BIT_PHYS_ADDR | ||
186 | help | ||
187 | Enable this driver of you want PCMCIA support on your Alchemy | ||
188 | Db1000, Db/Pb1100, Db/Pb1500, Db/Pb1550, Db/Pb1200 board. | ||
189 | NOT suitable for the PB1000! | ||
190 | |||
191 | This driver is also available as a module called db1xxx_ss.ko | ||
192 | |||
193 | config PCMCIA_XXS1500 | ||
194 | tristate "MyCable XXS1500 PCMCIA socket support" | ||
195 | depends on PCMCIA && MIPS_XXS1500 | ||
196 | select 64BIT_PHYS_ADDR | ||
197 | help | ||
198 | Support for the PCMCIA/CF socket interface on MyCable XXS1500 | ||
199 | systems. | ||
200 | |||
201 | This driver is also available as a module called xxs1500_ss.ko | ||
202 | |||
177 | config PCMCIA_BCM63XX | 203 | config PCMCIA_BCM63XX |
178 | tristate "bcm63xx pcmcia support" | 204 | tristate "bcm63xx pcmcia support" |
179 | depends on BCM63XX && PCMCIA | 205 | depends on BCM63XX && PCMCIA |
@@ -238,14 +264,12 @@ config PCMCIA_PROBE | |||
238 | config M32R_PCC | 264 | config M32R_PCC |
239 | bool "M32R PCMCIA I/F" | 265 | bool "M32R PCMCIA I/F" |
240 | depends on M32R && CHIP_M32700 && PCMCIA | 266 | depends on M32R && CHIP_M32700 && PCMCIA |
241 | select PCCARD_NONSTATIC | ||
242 | help | 267 | help |
243 | Say Y here to use the M32R PCMCIA controller. | 268 | Say Y here to use the M32R PCMCIA controller. |
244 | 269 | ||
245 | config M32R_CFC | 270 | config M32R_CFC |
246 | bool "M32R CF I/F Controller" | 271 | bool "M32R CF I/F Controller" |
247 | depends on M32R && (PLAT_USRV || PLAT_M32700UT || PLAT_MAPPI2 || PLAT_MAPPI3 || PLAT_OPSPUT) | 272 | depends on M32R && (PLAT_USRV || PLAT_M32700UT || PLAT_MAPPI2 || PLAT_MAPPI3 || PLAT_OPSPUT) |
248 | select PCCARD_NONSTATIC | ||
249 | help | 273 | help |
250 | Say Y here to use the M32R CompactFlash controller. | 274 | Say Y here to use the M32R CompactFlash controller. |
251 | 275 | ||
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..e6ab2a47d8cb 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; |
@@ -222,7 +71,7 @@ int __ref cb_alloc(struct pcmcia_socket *s) | |||
222 | unsigned int max, pass; | 71 | unsigned int max, pass; |
223 | 72 | ||
224 | s->functions = pci_scan_slot(bus, PCI_DEVFN(0, 0)); | 73 | s->functions = pci_scan_slot(bus, PCI_DEVFN(0, 0)); |
225 | pci_fixup_cardbus(bus); | 74 | pci_fixup_cardbus(bus); |
226 | 75 | ||
227 | max = bus->secondary; | 76 | max = bus->secondary; |
228 | for (pass = 0; pass < 2; pass++) | 77 | for (pass = 0; pass < 2; pass++) |
@@ -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..f230f6543bff 100644 --- a/drivers/pcmcia/cistpl.c +++ b/drivers/pcmcia/cistpl.c | |||
@@ -54,43 +54,44 @@ static const u_int exponent[] = { | |||
54 | /* Upper limit on reasonable # of tuples */ | 54 | /* Upper limit on reasonable # of tuples */ |
55 | #define MAX_TUPLES 200 | 55 | #define MAX_TUPLES 200 |
56 | 56 | ||
57 | /*====================================================================*/ | ||
58 | |||
59 | /* Parameters that can be set with 'insmod' */ | ||
60 | |||
61 | /* 16-bit CIS? */ | 57 | /* 16-bit CIS? */ |
62 | static int cis_width; | 58 | static int cis_width; |
63 | module_param(cis_width, int, 0444); | 59 | module_param(cis_width, int, 0444); |
64 | 60 | ||
65 | void release_cis_mem(struct pcmcia_socket *s) | 61 | void release_cis_mem(struct pcmcia_socket *s) |
66 | { | 62 | { |
67 | if (s->cis_mem.flags & MAP_ACTIVE) { | 63 | mutex_lock(&s->ops_mutex); |
68 | s->cis_mem.flags &= ~MAP_ACTIVE; | 64 | if (s->cis_mem.flags & MAP_ACTIVE) { |
69 | s->ops->set_mem_map(s, &s->cis_mem); | 65 | s->cis_mem.flags &= ~MAP_ACTIVE; |
70 | if (s->cis_mem.res) { | 66 | s->ops->set_mem_map(s, &s->cis_mem); |
71 | release_resource(s->cis_mem.res); | 67 | if (s->cis_mem.res) { |
72 | kfree(s->cis_mem.res); | 68 | release_resource(s->cis_mem.res); |
73 | s->cis_mem.res = NULL; | 69 | kfree(s->cis_mem.res); |
70 | s->cis_mem.res = NULL; | ||
71 | } | ||
72 | iounmap(s->cis_virt); | ||
73 | s->cis_virt = NULL; | ||
74 | } | 74 | } |
75 | iounmap(s->cis_virt); | 75 | mutex_unlock(&s->ops_mutex); |
76 | s->cis_virt = NULL; | ||
77 | } | ||
78 | } | 76 | } |
79 | EXPORT_SYMBOL(release_cis_mem); | ||
80 | 77 | ||
81 | /* | 78 | /** |
82 | * Map the card memory at "card_offset" into virtual space. | 79 | * set_cis_map() - map the card memory at "card_offset" into virtual space. |
80 | * | ||
83 | * If flags & MAP_ATTRIB, map the attribute space, otherwise | 81 | * If flags & MAP_ATTRIB, map the attribute space, otherwise |
84 | * map the memory space. | 82 | * map the memory space. |
83 | * | ||
84 | * Must be called with ops_mutex held. | ||
85 | */ | 85 | */ |
86 | static void __iomem * | 86 | static void __iomem *set_cis_map(struct pcmcia_socket *s, |
87 | set_cis_map(struct pcmcia_socket *s, unsigned int card_offset, unsigned int flags) | 87 | unsigned int card_offset, unsigned int flags) |
88 | { | 88 | { |
89 | pccard_mem_map *mem = &s->cis_mem; | 89 | pccard_mem_map *mem = &s->cis_mem; |
90 | int ret; | 90 | int ret; |
91 | 91 | ||
92 | if (!(s->features & SS_CAP_STATIC_MAP) && (mem->res == NULL)) { | 92 | if (!(s->features & SS_CAP_STATIC_MAP) && (mem->res == NULL)) { |
93 | mem->res = pcmcia_find_mem_region(0, s->map_size, s->map_size, 0, s); | 93 | mem->res = pcmcia_find_mem_region(0, s->map_size, |
94 | s->map_size, 0, s); | ||
94 | if (mem->res == NULL) { | 95 | if (mem->res == NULL) { |
95 | dev_printk(KERN_NOTICE, &s->dev, | 96 | dev_printk(KERN_NOTICE, &s->dev, |
96 | "cs: unable to map card memory!\n"); | 97 | "cs: unable to map card memory!\n"); |
@@ -121,176 +122,200 @@ set_cis_map(struct pcmcia_socket *s, unsigned int card_offset, unsigned int flag | |||
121 | return s->cis_virt; | 122 | return s->cis_virt; |
122 | } | 123 | } |
123 | 124 | ||
124 | /*====================================================================== | ||
125 | |||
126 | Low-level functions to read and write CIS memory. I think the | ||
127 | write routine is only useful for writing one-byte registers. | ||
128 | |||
129 | ======================================================================*/ | ||
130 | 125 | ||
131 | /* Bits in attr field */ | 126 | /* Bits in attr field */ |
132 | #define IS_ATTR 1 | 127 | #define IS_ATTR 1 |
133 | #define IS_INDIRECT 8 | 128 | #define IS_INDIRECT 8 |
134 | 129 | ||
130 | /** | ||
131 | * pcmcia_read_cis_mem() - low-level function to read CIS memory | ||
132 | */ | ||
135 | int pcmcia_read_cis_mem(struct pcmcia_socket *s, int attr, u_int addr, | 133 | int pcmcia_read_cis_mem(struct pcmcia_socket *s, int attr, u_int addr, |
136 | u_int len, void *ptr) | 134 | u_int len, void *ptr) |
137 | { | 135 | { |
138 | void __iomem *sys, *end; | 136 | void __iomem *sys, *end; |
139 | unsigned char *buf = ptr; | 137 | unsigned char *buf = ptr; |
140 | 138 | ||
141 | dev_dbg(&s->dev, "pcmcia_read_cis_mem(%d, %#x, %u)\n", attr, addr, len); | 139 | dev_dbg(&s->dev, "pcmcia_read_cis_mem(%d, %#x, %u)\n", attr, addr, len); |
142 | 140 | ||
143 | if (attr & IS_INDIRECT) { | 141 | mutex_lock(&s->ops_mutex); |
144 | /* Indirect accesses use a bunch of special registers at fixed | 142 | if (attr & IS_INDIRECT) { |
145 | locations in common memory */ | 143 | /* Indirect accesses use a bunch of special registers at fixed |
146 | u_char flags = ICTRL0_COMMON|ICTRL0_AUTOINC|ICTRL0_BYTEGRAN; | 144 | locations in common memory */ |
147 | if (attr & IS_ATTR) { | 145 | u_char flags = ICTRL0_COMMON|ICTRL0_AUTOINC|ICTRL0_BYTEGRAN; |
148 | addr *= 2; | 146 | if (attr & IS_ATTR) { |
149 | flags = ICTRL0_AUTOINC; | 147 | addr *= 2; |
150 | } | 148 | flags = ICTRL0_AUTOINC; |
149 | } | ||
151 | 150 | ||
152 | sys = set_cis_map(s, 0, MAP_ACTIVE | ((cis_width) ? MAP_16BIT : 0)); | 151 | sys = set_cis_map(s, 0, MAP_ACTIVE | |
153 | if (!sys) { | 152 | ((cis_width) ? MAP_16BIT : 0)); |
154 | memset(ptr, 0xff, len); | 153 | if (!sys) { |
155 | return -1; | 154 | dev_dbg(&s->dev, "could not map memory\n"); |
156 | } | 155 | memset(ptr, 0xff, len); |
156 | mutex_unlock(&s->ops_mutex); | ||
157 | return -1; | ||
158 | } | ||
157 | 159 | ||
158 | writeb(flags, sys+CISREG_ICTRL0); | 160 | writeb(flags, sys+CISREG_ICTRL0); |
159 | writeb(addr & 0xff, sys+CISREG_IADDR0); | 161 | writeb(addr & 0xff, sys+CISREG_IADDR0); |
160 | writeb((addr>>8) & 0xff, sys+CISREG_IADDR1); | 162 | writeb((addr>>8) & 0xff, sys+CISREG_IADDR1); |
161 | writeb((addr>>16) & 0xff, sys+CISREG_IADDR2); | 163 | writeb((addr>>16) & 0xff, sys+CISREG_IADDR2); |
162 | writeb((addr>>24) & 0xff, sys+CISREG_IADDR3); | 164 | writeb((addr>>24) & 0xff, sys+CISREG_IADDR3); |
163 | for ( ; len > 0; len--, buf++) | 165 | for ( ; len > 0; len--, buf++) |
164 | *buf = readb(sys+CISREG_IDATA0); | 166 | *buf = readb(sys+CISREG_IDATA0); |
165 | } else { | 167 | } else { |
166 | u_int inc = 1, card_offset, flags; | 168 | u_int inc = 1, card_offset, flags; |
167 | |||
168 | flags = MAP_ACTIVE | ((cis_width) ? MAP_16BIT : 0); | ||
169 | if (attr) { | ||
170 | flags |= MAP_ATTRIB; | ||
171 | inc++; | ||
172 | addr *= 2; | ||
173 | } | ||
174 | 169 | ||
175 | card_offset = addr & ~(s->map_size-1); | 170 | if (addr > CISTPL_MAX_CIS_SIZE) |
176 | while (len) { | 171 | dev_dbg(&s->dev, |
177 | sys = set_cis_map(s, card_offset, flags); | 172 | "attempt to read CIS mem at addr %#x", addr); |
178 | if (!sys) { | 173 | |
179 | memset(ptr, 0xff, len); | 174 | flags = MAP_ACTIVE | ((cis_width) ? MAP_16BIT : 0); |
180 | return -1; | 175 | if (attr) { |
181 | } | 176 | flags |= MAP_ATTRIB; |
182 | end = sys + s->map_size; | 177 | inc++; |
183 | sys = sys + (addr & (s->map_size-1)); | 178 | addr *= 2; |
184 | for ( ; len > 0; len--, buf++, sys += inc) { | 179 | } |
185 | if (sys == end) | 180 | |
186 | break; | 181 | card_offset = addr & ~(s->map_size-1); |
187 | *buf = readb(sys); | 182 | while (len) { |
188 | } | 183 | sys = set_cis_map(s, card_offset, flags); |
189 | card_offset += s->map_size; | 184 | if (!sys) { |
190 | addr = 0; | 185 | dev_dbg(&s->dev, "could not map memory\n"); |
186 | memset(ptr, 0xff, len); | ||
187 | mutex_unlock(&s->ops_mutex); | ||
188 | return -1; | ||
189 | } | ||
190 | end = sys + s->map_size; | ||
191 | sys = sys + (addr & (s->map_size-1)); | ||
192 | for ( ; len > 0; len--, buf++, sys += inc) { | ||
193 | if (sys == end) | ||
194 | break; | ||
195 | *buf = readb(sys); | ||
196 | } | ||
197 | card_offset += s->map_size; | ||
198 | addr = 0; | ||
199 | } | ||
191 | } | 200 | } |
192 | } | 201 | mutex_unlock(&s->ops_mutex); |
193 | dev_dbg(&s->dev, " %#2.2x %#2.2x %#2.2x %#2.2x ...\n", | 202 | dev_dbg(&s->dev, " %#2.2x %#2.2x %#2.2x %#2.2x ...\n", |
194 | *(u_char *)(ptr+0), *(u_char *)(ptr+1), | 203 | *(u_char *)(ptr+0), *(u_char *)(ptr+1), |
195 | *(u_char *)(ptr+2), *(u_char *)(ptr+3)); | 204 | *(u_char *)(ptr+2), *(u_char *)(ptr+3)); |
196 | return 0; | 205 | return 0; |
197 | } | 206 | } |
198 | EXPORT_SYMBOL(pcmcia_read_cis_mem); | ||
199 | 207 | ||
200 | 208 | ||
209 | /** | ||
210 | * pcmcia_write_cis_mem() - low-level function to write CIS memory | ||
211 | * | ||
212 | * Probably only useful for writing one-byte registers. | ||
213 | */ | ||
201 | void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr, u_int addr, | 214 | void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr, u_int addr, |
202 | u_int len, void *ptr) | 215 | u_int len, void *ptr) |
203 | { | 216 | { |
204 | void __iomem *sys, *end; | 217 | void __iomem *sys, *end; |
205 | unsigned char *buf = ptr; | 218 | unsigned char *buf = ptr; |
206 | 219 | ||
207 | dev_dbg(&s->dev, "pcmcia_write_cis_mem(%d, %#x, %u)\n", attr, addr, len); | 220 | dev_dbg(&s->dev, |
208 | 221 | "pcmcia_write_cis_mem(%d, %#x, %u)\n", attr, addr, len); | |
209 | if (attr & IS_INDIRECT) { | 222 | |
210 | /* Indirect accesses use a bunch of special registers at fixed | 223 | mutex_lock(&s->ops_mutex); |
211 | locations in common memory */ | 224 | if (attr & IS_INDIRECT) { |
212 | u_char flags = ICTRL0_COMMON|ICTRL0_AUTOINC|ICTRL0_BYTEGRAN; | 225 | /* Indirect accesses use a bunch of special registers at fixed |
213 | if (attr & IS_ATTR) { | 226 | locations in common memory */ |
214 | addr *= 2; | 227 | u_char flags = ICTRL0_COMMON|ICTRL0_AUTOINC|ICTRL0_BYTEGRAN; |
215 | flags = ICTRL0_AUTOINC; | 228 | if (attr & IS_ATTR) { |
216 | } | 229 | addr *= 2; |
230 | flags = ICTRL0_AUTOINC; | ||
231 | } | ||
217 | 232 | ||
218 | sys = set_cis_map(s, 0, MAP_ACTIVE | ((cis_width) ? MAP_16BIT : 0)); | 233 | sys = set_cis_map(s, 0, MAP_ACTIVE | |
219 | if (!sys) | 234 | ((cis_width) ? MAP_16BIT : 0)); |
220 | return; /* FIXME: Error */ | 235 | if (!sys) { |
221 | 236 | dev_dbg(&s->dev, "could not map memory\n"); | |
222 | writeb(flags, sys+CISREG_ICTRL0); | 237 | mutex_unlock(&s->ops_mutex); |
223 | writeb(addr & 0xff, sys+CISREG_IADDR0); | 238 | return; /* FIXME: Error */ |
224 | writeb((addr>>8) & 0xff, sys+CISREG_IADDR1); | 239 | } |
225 | writeb((addr>>16) & 0xff, sys+CISREG_IADDR2); | 240 | |
226 | writeb((addr>>24) & 0xff, sys+CISREG_IADDR3); | 241 | writeb(flags, sys+CISREG_ICTRL0); |
227 | for ( ; len > 0; len--, buf++) | 242 | writeb(addr & 0xff, sys+CISREG_IADDR0); |
228 | writeb(*buf, sys+CISREG_IDATA0); | 243 | writeb((addr>>8) & 0xff, sys+CISREG_IADDR1); |
229 | } else { | 244 | writeb((addr>>16) & 0xff, sys+CISREG_IADDR2); |
230 | u_int inc = 1, card_offset, flags; | 245 | writeb((addr>>24) & 0xff, sys+CISREG_IADDR3); |
231 | 246 | for ( ; len > 0; len--, buf++) | |
232 | flags = MAP_ACTIVE | ((cis_width) ? MAP_16BIT : 0); | 247 | writeb(*buf, sys+CISREG_IDATA0); |
233 | if (attr & IS_ATTR) { | 248 | } else { |
234 | flags |= MAP_ATTRIB; | 249 | u_int inc = 1, card_offset, flags; |
235 | inc++; | 250 | |
236 | addr *= 2; | 251 | flags = MAP_ACTIVE | ((cis_width) ? MAP_16BIT : 0); |
237 | } | 252 | if (attr & IS_ATTR) { |
253 | flags |= MAP_ATTRIB; | ||
254 | inc++; | ||
255 | addr *= 2; | ||
256 | } | ||
238 | 257 | ||
239 | card_offset = addr & ~(s->map_size-1); | 258 | card_offset = addr & ~(s->map_size-1); |
240 | while (len) { | 259 | while (len) { |
241 | sys = set_cis_map(s, card_offset, flags); | 260 | sys = set_cis_map(s, card_offset, flags); |
242 | if (!sys) | 261 | if (!sys) { |
243 | return; /* FIXME: error */ | 262 | dev_dbg(&s->dev, "could not map memory\n"); |
244 | 263 | mutex_unlock(&s->ops_mutex); | |
245 | end = sys + s->map_size; | 264 | return; /* FIXME: error */ |
246 | sys = sys + (addr & (s->map_size-1)); | 265 | } |
247 | for ( ; len > 0; len--, buf++, sys += inc) { | 266 | |
248 | if (sys == end) | 267 | end = sys + s->map_size; |
249 | break; | 268 | sys = sys + (addr & (s->map_size-1)); |
250 | writeb(*buf, sys); | 269 | for ( ; len > 0; len--, buf++, sys += inc) { |
251 | } | 270 | if (sys == end) |
252 | card_offset += s->map_size; | 271 | break; |
253 | addr = 0; | 272 | writeb(*buf, sys); |
273 | } | ||
274 | card_offset += s->map_size; | ||
275 | addr = 0; | ||
276 | } | ||
254 | } | 277 | } |
255 | } | 278 | mutex_unlock(&s->ops_mutex); |
256 | } | 279 | } |
257 | EXPORT_SYMBOL(pcmcia_write_cis_mem); | ||
258 | 280 | ||
259 | 281 | ||
260 | /*====================================================================== | 282 | /** |
283 | * read_cis_cache() - read CIS memory or its associated cache | ||
284 | * | ||
285 | * This is a wrapper around read_cis_mem, with the same interface, | ||
286 | * but which caches information, for cards whose CIS may not be | ||
287 | * readable all the time. | ||
288 | */ | ||
289 | static int read_cis_cache(struct pcmcia_socket *s, int attr, u_int addr, | ||
290 | size_t len, void *ptr) | ||
291 | { | ||
292 | struct cis_cache_entry *cis; | ||
293 | int ret = 0; | ||
261 | 294 | ||
262 | This is a wrapper around read_cis_mem, with the same interface, | 295 | if (s->state & SOCKET_CARDBUS) |
263 | but which caches information, for cards whose CIS may not be | 296 | return -EINVAL; |
264 | readable all the time. | ||
265 | 297 | ||
266 | ======================================================================*/ | 298 | mutex_lock(&s->ops_mutex); |
299 | if (s->fake_cis) { | ||
300 | if (s->fake_cis_len >= addr+len) | ||
301 | memcpy(ptr, s->fake_cis+addr, len); | ||
302 | else { | ||
303 | memset(ptr, 0xff, len); | ||
304 | ret = -EINVAL; | ||
305 | } | ||
306 | mutex_unlock(&s->ops_mutex); | ||
307 | return ret; | ||
308 | } | ||
267 | 309 | ||
268 | static void read_cis_cache(struct pcmcia_socket *s, int attr, u_int addr, | 310 | list_for_each_entry(cis, &s->cis_cache, node) { |
269 | size_t len, void *ptr) | 311 | if (cis->addr == addr && cis->len == len && cis->attr == attr) { |
270 | { | 312 | memcpy(ptr, cis->cache, len); |
271 | struct cis_cache_entry *cis; | 313 | mutex_unlock(&s->ops_mutex); |
272 | int ret; | 314 | return 0; |
273 | 315 | } | |
274 | if (s->fake_cis) { | ||
275 | if (s->fake_cis_len >= addr+len) | ||
276 | memcpy(ptr, s->fake_cis+addr, len); | ||
277 | else | ||
278 | memset(ptr, 0xff, len); | ||
279 | return; | ||
280 | } | ||
281 | |||
282 | list_for_each_entry(cis, &s->cis_cache, node) { | ||
283 | if (cis->addr == addr && cis->len == len && cis->attr == attr) { | ||
284 | memcpy(ptr, cis->cache, len); | ||
285 | return; | ||
286 | } | 316 | } |
287 | } | 317 | mutex_unlock(&s->ops_mutex); |
288 | 318 | ||
289 | #ifdef CONFIG_CARDBUS | ||
290 | if (s->state & SOCKET_CARDBUS) | ||
291 | ret = read_cb_mem(s, attr, addr, len, ptr); | ||
292 | else | ||
293 | #endif | ||
294 | ret = pcmcia_read_cis_mem(s, attr, addr, len, ptr); | 319 | ret = pcmcia_read_cis_mem(s, attr, addr, len, ptr); |
295 | 320 | ||
296 | if (ret == 0) { | 321 | if (ret == 0) { |
@@ -301,9 +326,12 @@ static void read_cis_cache(struct pcmcia_socket *s, int attr, u_int addr, | |||
301 | cis->len = len; | 326 | cis->len = len; |
302 | cis->attr = attr; | 327 | cis->attr = attr; |
303 | memcpy(cis->cache, ptr, len); | 328 | memcpy(cis->cache, ptr, len); |
329 | mutex_lock(&s->ops_mutex); | ||
304 | list_add(&cis->node, &s->cis_cache); | 330 | list_add(&cis->node, &s->cis_cache); |
331 | mutex_unlock(&s->ops_mutex); | ||
305 | } | 332 | } |
306 | } | 333 | } |
334 | return ret; | ||
307 | } | 335 | } |
308 | 336 | ||
309 | static void | 337 | static void |
@@ -311,44 +339,46 @@ remove_cis_cache(struct pcmcia_socket *s, int attr, u_int addr, u_int len) | |||
311 | { | 339 | { |
312 | struct cis_cache_entry *cis; | 340 | struct cis_cache_entry *cis; |
313 | 341 | ||
342 | mutex_lock(&s->ops_mutex); | ||
314 | list_for_each_entry(cis, &s->cis_cache, node) | 343 | list_for_each_entry(cis, &s->cis_cache, node) |
315 | if (cis->addr == addr && cis->len == len && cis->attr == attr) { | 344 | if (cis->addr == addr && cis->len == len && cis->attr == attr) { |
316 | list_del(&cis->node); | 345 | list_del(&cis->node); |
317 | kfree(cis); | 346 | kfree(cis); |
318 | break; | 347 | break; |
319 | } | 348 | } |
349 | mutex_unlock(&s->ops_mutex); | ||
320 | } | 350 | } |
321 | 351 | ||
352 | /** | ||
353 | * destroy_cis_cache() - destroy the CIS cache | ||
354 | * @s: pcmcia_socket for which CIS cache shall be destroyed | ||
355 | * | ||
356 | * This destroys the CIS cache but keeps any fake CIS alive. Must be | ||
357 | * called with ops_mutex held. | ||
358 | */ | ||
322 | void destroy_cis_cache(struct pcmcia_socket *s) | 359 | void destroy_cis_cache(struct pcmcia_socket *s) |
323 | { | 360 | { |
324 | struct list_head *l, *n; | 361 | struct list_head *l, *n; |
362 | struct cis_cache_entry *cis; | ||
325 | 363 | ||
326 | list_for_each_safe(l, n, &s->cis_cache) { | 364 | list_for_each_safe(l, n, &s->cis_cache) { |
327 | struct cis_cache_entry *cis = list_entry(l, struct cis_cache_entry, node); | 365 | cis = list_entry(l, struct cis_cache_entry, node); |
328 | |||
329 | list_del(&cis->node); | 366 | list_del(&cis->node); |
330 | kfree(cis); | 367 | kfree(cis); |
331 | } | 368 | } |
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 | } | 369 | } |
339 | EXPORT_SYMBOL(destroy_cis_cache); | ||
340 | |||
341 | /*====================================================================== | ||
342 | |||
343 | This verifies if the CIS of a card matches what is in the CIS | ||
344 | cache. | ||
345 | |||
346 | ======================================================================*/ | ||
347 | 370 | ||
371 | /** | ||
372 | * verify_cis_cache() - does the CIS match what is in the CIS cache? | ||
373 | */ | ||
348 | int verify_cis_cache(struct pcmcia_socket *s) | 374 | int verify_cis_cache(struct pcmcia_socket *s) |
349 | { | 375 | { |
350 | struct cis_cache_entry *cis; | 376 | struct cis_cache_entry *cis; |
351 | char *buf; | 377 | char *buf; |
378 | int ret; | ||
379 | |||
380 | if (s->state & SOCKET_CARDBUS) | ||
381 | return -EINVAL; | ||
352 | 382 | ||
353 | buf = kmalloc(256, GFP_KERNEL); | 383 | buf = kmalloc(256, GFP_KERNEL); |
354 | if (buf == NULL) { | 384 | if (buf == NULL) { |
@@ -361,14 +391,9 @@ int verify_cis_cache(struct pcmcia_socket *s) | |||
361 | 391 | ||
362 | if (len > 256) | 392 | if (len > 256) |
363 | len = 256; | 393 | len = 256; |
364 | #ifdef CONFIG_CARDBUS | 394 | |
365 | if (s->state & SOCKET_CARDBUS) | 395 | ret = pcmcia_read_cis_mem(s, cis->attr, cis->addr, len, buf); |
366 | read_cb_mem(s, cis->attr, cis->addr, len, buf); | 396 | if (ret || memcmp(buf, cis->cache, len) != 0) { |
367 | else | ||
368 | #endif | ||
369 | pcmcia_read_cis_mem(s, cis->attr, cis->addr, len, buf); | ||
370 | |||
371 | if (memcmp(buf, cis->cache, len) != 0) { | ||
372 | kfree(buf); | 397 | kfree(buf); |
373 | return -1; | 398 | return -1; |
374 | } | 399 | } |
@@ -377,13 +402,12 @@ int verify_cis_cache(struct pcmcia_socket *s) | |||
377 | return 0; | 402 | return 0; |
378 | } | 403 | } |
379 | 404 | ||
380 | /*====================================================================== | 405 | /** |
381 | 406 | * pcmcia_replace_cis() - use a replacement CIS instead of the card's CIS | |
382 | For really bad cards, we provide a facility for uploading a | 407 | * |
383 | replacement CIS. | 408 | * For really bad cards, we provide a facility for uploading a |
384 | 409 | * replacement CIS. | |
385 | ======================================================================*/ | 410 | */ |
386 | |||
387 | int pcmcia_replace_cis(struct pcmcia_socket *s, | 411 | int pcmcia_replace_cis(struct pcmcia_socket *s, |
388 | const u8 *data, const size_t len) | 412 | const u8 *data, const size_t len) |
389 | { | 413 | { |
@@ -391,29 +415,28 @@ int pcmcia_replace_cis(struct pcmcia_socket *s, | |||
391 | dev_printk(KERN_WARNING, &s->dev, "replacement CIS too big\n"); | 415 | dev_printk(KERN_WARNING, &s->dev, "replacement CIS too big\n"); |
392 | return -EINVAL; | 416 | return -EINVAL; |
393 | } | 417 | } |
418 | mutex_lock(&s->ops_mutex); | ||
394 | kfree(s->fake_cis); | 419 | kfree(s->fake_cis); |
395 | s->fake_cis = kmalloc(len, GFP_KERNEL); | 420 | s->fake_cis = kmalloc(len, GFP_KERNEL); |
396 | if (s->fake_cis == NULL) { | 421 | if (s->fake_cis == NULL) { |
397 | dev_printk(KERN_WARNING, &s->dev, "no memory to replace CIS\n"); | 422 | dev_printk(KERN_WARNING, &s->dev, "no memory to replace CIS\n"); |
423 | mutex_unlock(&s->ops_mutex); | ||
398 | return -ENOMEM; | 424 | return -ENOMEM; |
399 | } | 425 | } |
400 | s->fake_cis_len = len; | 426 | s->fake_cis_len = len; |
401 | memcpy(s->fake_cis, data, len); | 427 | memcpy(s->fake_cis, data, len); |
428 | dev_info(&s->dev, "Using replacement CIS\n"); | ||
429 | mutex_unlock(&s->ops_mutex); | ||
402 | return 0; | 430 | return 0; |
403 | } | 431 | } |
404 | EXPORT_SYMBOL(pcmcia_replace_cis); | ||
405 | 432 | ||
406 | /*====================================================================== | 433 | /* The high-level CIS tuple services */ |
407 | |||
408 | The high-level CIS tuple services | ||
409 | |||
410 | ======================================================================*/ | ||
411 | 434 | ||
412 | typedef struct tuple_flags { | 435 | typedef struct tuple_flags { |
413 | u_int link_space:4; | 436 | u_int link_space:4; |
414 | u_int has_link:1; | 437 | u_int has_link:1; |
415 | u_int mfc_fn:3; | 438 | u_int mfc_fn:3; |
416 | u_int space:4; | 439 | u_int space:4; |
417 | } tuple_flags; | 440 | } tuple_flags; |
418 | 441 | ||
419 | #define LINK_SPACE(f) (((tuple_flags *)(&(f)))->link_space) | 442 | #define LINK_SPACE(f) (((tuple_flags *)(&(f)))->link_space) |
@@ -421,1099 +444,962 @@ typedef struct tuple_flags { | |||
421 | #define MFC_FN(f) (((tuple_flags *)(&(f)))->mfc_fn) | 444 | #define MFC_FN(f) (((tuple_flags *)(&(f)))->mfc_fn) |
422 | #define SPACE(f) (((tuple_flags *)(&(f)))->space) | 445 | #define SPACE(f) (((tuple_flags *)(&(f)))->space) |
423 | 446 | ||
424 | int pccard_get_first_tuple(struct pcmcia_socket *s, unsigned int function, tuple_t *tuple) | 447 | int pccard_get_first_tuple(struct pcmcia_socket *s, unsigned int function, |
448 | tuple_t *tuple) | ||
425 | { | 449 | { |
426 | if (!s) | 450 | if (!s) |
427 | return -EINVAL; | 451 | return -EINVAL; |
428 | if (!(s->state & SOCKET_PRESENT)) | 452 | |
429 | return -ENODEV; | 453 | if (!(s->state & SOCKET_PRESENT) || (s->state & SOCKET_CARDBUS)) |
430 | tuple->TupleLink = tuple->Flags = 0; | 454 | return -ENODEV; |
431 | #ifdef CONFIG_CARDBUS | 455 | tuple->TupleLink = tuple->Flags = 0; |
432 | if (s->state & SOCKET_CARDBUS) { | 456 | |
433 | struct pci_dev *dev = s->cb_dev; | ||
434 | u_int ptr; | ||
435 | pci_bus_read_config_dword(dev->subordinate, 0, PCI_CARDBUS_CIS, &ptr); | ||
436 | tuple->CISOffset = ptr & ~7; | ||
437 | SPACE(tuple->Flags) = (ptr & 7); | ||
438 | } else | ||
439 | #endif | ||
440 | { | ||
441 | /* Assume presence of a LONGLINK_C to address 0 */ | 457 | /* Assume presence of a LONGLINK_C to address 0 */ |
442 | tuple->CISOffset = tuple->LinkOffset = 0; | 458 | tuple->CISOffset = tuple->LinkOffset = 0; |
443 | SPACE(tuple->Flags) = HAS_LINK(tuple->Flags) = 1; | 459 | SPACE(tuple->Flags) = HAS_LINK(tuple->Flags) = 1; |
444 | } | 460 | |
445 | if (!(s->state & SOCKET_CARDBUS) && (s->functions > 1) && | 461 | if ((s->functions > 1) && !(tuple->Attributes & TUPLE_RETURN_COMMON)) { |
446 | !(tuple->Attributes & TUPLE_RETURN_COMMON)) { | 462 | cisdata_t req = tuple->DesiredTuple; |
447 | cisdata_t req = tuple->DesiredTuple; | 463 | tuple->DesiredTuple = CISTPL_LONGLINK_MFC; |
448 | tuple->DesiredTuple = CISTPL_LONGLINK_MFC; | 464 | if (pccard_get_next_tuple(s, function, tuple) == 0) { |
449 | if (pccard_get_next_tuple(s, function, tuple) == 0) { | 465 | tuple->DesiredTuple = CISTPL_LINKTARGET; |
450 | tuple->DesiredTuple = CISTPL_LINKTARGET; | 466 | if (pccard_get_next_tuple(s, function, tuple) != 0) |
451 | if (pccard_get_next_tuple(s, function, tuple) != 0) | 467 | return -ENOSPC; |
452 | return -ENOSPC; | 468 | } else |
453 | } else | 469 | tuple->CISOffset = tuple->TupleLink = 0; |
454 | tuple->CISOffset = tuple->TupleLink = 0; | 470 | tuple->DesiredTuple = req; |
455 | tuple->DesiredTuple = req; | 471 | } |
456 | } | 472 | return pccard_get_next_tuple(s, function, tuple); |
457 | return pccard_get_next_tuple(s, function, tuple); | ||
458 | } | 473 | } |
459 | EXPORT_SYMBOL(pccard_get_first_tuple); | ||
460 | 474 | ||
461 | static int follow_link(struct pcmcia_socket *s, tuple_t *tuple) | 475 | static int follow_link(struct pcmcia_socket *s, tuple_t *tuple) |
462 | { | 476 | { |
463 | u_char link[5]; | 477 | u_char link[5]; |
464 | u_int ofs; | 478 | u_int ofs; |
465 | 479 | int ret; | |
466 | if (MFC_FN(tuple->Flags)) { | 480 | |
467 | /* Get indirect link from the MFC tuple */ | 481 | if (MFC_FN(tuple->Flags)) { |
468 | read_cis_cache(s, LINK_SPACE(tuple->Flags), | 482 | /* Get indirect link from the MFC tuple */ |
469 | tuple->LinkOffset, 5, link); | 483 | ret = read_cis_cache(s, LINK_SPACE(tuple->Flags), |
470 | ofs = get_unaligned_le32(link + 1); | 484 | tuple->LinkOffset, 5, link); |
471 | SPACE(tuple->Flags) = (link[0] == CISTPL_MFC_ATTR); | 485 | if (ret) |
472 | /* Move to the next indirect link */ | 486 | return -1; |
473 | tuple->LinkOffset += 5; | 487 | ofs = get_unaligned_le32(link + 1); |
474 | MFC_FN(tuple->Flags)--; | 488 | SPACE(tuple->Flags) = (link[0] == CISTPL_MFC_ATTR); |
475 | } else if (HAS_LINK(tuple->Flags)) { | 489 | /* Move to the next indirect link */ |
476 | ofs = tuple->LinkOffset; | 490 | tuple->LinkOffset += 5; |
477 | SPACE(tuple->Flags) = LINK_SPACE(tuple->Flags); | 491 | MFC_FN(tuple->Flags)--; |
478 | HAS_LINK(tuple->Flags) = 0; | 492 | } else if (HAS_LINK(tuple->Flags)) { |
479 | } else { | 493 | ofs = tuple->LinkOffset; |
480 | return -1; | 494 | SPACE(tuple->Flags) = LINK_SPACE(tuple->Flags); |
481 | } | 495 | HAS_LINK(tuple->Flags) = 0; |
482 | if (!(s->state & SOCKET_CARDBUS) && SPACE(tuple->Flags)) { | 496 | } else |
483 | /* This is ugly, but a common CIS error is to code the long | 497 | return -1; |
484 | link offset incorrectly, so we check the right spot... */ | 498 | |
485 | read_cis_cache(s, SPACE(tuple->Flags), ofs, 5, link); | 499 | if (SPACE(tuple->Flags)) { |
500 | /* This is ugly, but a common CIS error is to code the long | ||
501 | link offset incorrectly, so we check the right spot... */ | ||
502 | ret = read_cis_cache(s, SPACE(tuple->Flags), ofs, 5, link); | ||
503 | if (ret) | ||
504 | return -1; | ||
505 | if ((link[0] == CISTPL_LINKTARGET) && (link[1] >= 3) && | ||
506 | (strncmp(link+2, "CIS", 3) == 0)) | ||
507 | return ofs; | ||
508 | remove_cis_cache(s, SPACE(tuple->Flags), ofs, 5); | ||
509 | /* Then, we try the wrong spot... */ | ||
510 | ofs = ofs >> 1; | ||
511 | } | ||
512 | ret = read_cis_cache(s, SPACE(tuple->Flags), ofs, 5, link); | ||
513 | if (ret) | ||
514 | return -1; | ||
486 | if ((link[0] == CISTPL_LINKTARGET) && (link[1] >= 3) && | 515 | if ((link[0] == CISTPL_LINKTARGET) && (link[1] >= 3) && |
487 | (strncmp(link+2, "CIS", 3) == 0)) | 516 | (strncmp(link+2, "CIS", 3) == 0)) |
488 | return ofs; | 517 | return ofs; |
489 | remove_cis_cache(s, SPACE(tuple->Flags), ofs, 5); | 518 | remove_cis_cache(s, SPACE(tuple->Flags), ofs, 5); |
490 | /* Then, we try the wrong spot... */ | 519 | return -1; |
491 | ofs = ofs >> 1; | ||
492 | } | ||
493 | read_cis_cache(s, SPACE(tuple->Flags), ofs, 5, link); | ||
494 | if ((link[0] == CISTPL_LINKTARGET) && (link[1] >= 3) && | ||
495 | (strncmp(link+2, "CIS", 3) == 0)) | ||
496 | return ofs; | ||
497 | remove_cis_cache(s, SPACE(tuple->Flags), ofs, 5); | ||
498 | return -1; | ||
499 | } | 520 | } |
500 | 521 | ||
501 | int pccard_get_next_tuple(struct pcmcia_socket *s, unsigned int function, tuple_t *tuple) | 522 | int pccard_get_next_tuple(struct pcmcia_socket *s, unsigned int function, |
523 | tuple_t *tuple) | ||
502 | { | 524 | { |
503 | u_char link[2], tmp; | 525 | u_char link[2], tmp; |
504 | int ofs, i, attr; | 526 | int ofs, i, attr; |
527 | int ret; | ||
505 | 528 | ||
506 | if (!s) | 529 | if (!s) |
507 | return -EINVAL; | 530 | return -EINVAL; |
508 | if (!(s->state & SOCKET_PRESENT)) | 531 | if (!(s->state & SOCKET_PRESENT) || (s->state & SOCKET_CARDBUS)) |
509 | return -ENODEV; | 532 | return -ENODEV; |
533 | |||
534 | link[1] = tuple->TupleLink; | ||
535 | ofs = tuple->CISOffset + tuple->TupleLink; | ||
536 | attr = SPACE(tuple->Flags); | ||
537 | |||
538 | for (i = 0; i < MAX_TUPLES; i++) { | ||
539 | if (link[1] == 0xff) | ||
540 | link[0] = CISTPL_END; | ||
541 | else { | ||
542 | ret = read_cis_cache(s, attr, ofs, 2, link); | ||
543 | if (ret) | ||
544 | return -1; | ||
545 | if (link[0] == CISTPL_NULL) { | ||
546 | ofs++; | ||
547 | continue; | ||
548 | } | ||
549 | } | ||
510 | 550 | ||
511 | link[1] = tuple->TupleLink; | 551 | /* End of chain? Follow long link if possible */ |
512 | ofs = tuple->CISOffset + tuple->TupleLink; | 552 | if (link[0] == CISTPL_END) { |
513 | attr = SPACE(tuple->Flags); | 553 | ofs = follow_link(s, tuple); |
554 | if (ofs < 0) | ||
555 | return -ENOSPC; | ||
556 | attr = SPACE(tuple->Flags); | ||
557 | ret = read_cis_cache(s, attr, ofs, 2, link); | ||
558 | if (ret) | ||
559 | return -1; | ||
560 | } | ||
514 | 561 | ||
515 | for (i = 0; i < MAX_TUPLES; i++) { | 562 | /* Is this a link tuple? Make a note of it */ |
516 | if (link[1] == 0xff) { | 563 | if ((link[0] == CISTPL_LONGLINK_A) || |
517 | link[0] = CISTPL_END; | 564 | (link[0] == CISTPL_LONGLINK_C) || |
518 | } else { | 565 | (link[0] == CISTPL_LONGLINK_MFC) || |
519 | read_cis_cache(s, attr, ofs, 2, link); | 566 | (link[0] == CISTPL_LINKTARGET) || |
520 | if (link[0] == CISTPL_NULL) { | 567 | (link[0] == CISTPL_INDIRECT) || |
521 | ofs++; continue; | 568 | (link[0] == CISTPL_NO_LINK)) { |
522 | } | 569 | switch (link[0]) { |
570 | case CISTPL_LONGLINK_A: | ||
571 | HAS_LINK(tuple->Flags) = 1; | ||
572 | LINK_SPACE(tuple->Flags) = attr | IS_ATTR; | ||
573 | ret = read_cis_cache(s, attr, ofs+2, 4, | ||
574 | &tuple->LinkOffset); | ||
575 | if (ret) | ||
576 | return -1; | ||
577 | break; | ||
578 | case CISTPL_LONGLINK_C: | ||
579 | HAS_LINK(tuple->Flags) = 1; | ||
580 | LINK_SPACE(tuple->Flags) = attr & ~IS_ATTR; | ||
581 | ret = read_cis_cache(s, attr, ofs+2, 4, | ||
582 | &tuple->LinkOffset); | ||
583 | if (ret) | ||
584 | return -1; | ||
585 | break; | ||
586 | case CISTPL_INDIRECT: | ||
587 | HAS_LINK(tuple->Flags) = 1; | ||
588 | LINK_SPACE(tuple->Flags) = IS_ATTR | | ||
589 | IS_INDIRECT; | ||
590 | tuple->LinkOffset = 0; | ||
591 | break; | ||
592 | case CISTPL_LONGLINK_MFC: | ||
593 | tuple->LinkOffset = ofs + 3; | ||
594 | LINK_SPACE(tuple->Flags) = attr; | ||
595 | if (function == BIND_FN_ALL) { | ||
596 | /* Follow all the MFC links */ | ||
597 | ret = read_cis_cache(s, attr, ofs+2, | ||
598 | 1, &tmp); | ||
599 | if (ret) | ||
600 | return -1; | ||
601 | MFC_FN(tuple->Flags) = tmp; | ||
602 | } else { | ||
603 | /* Follow exactly one of the links */ | ||
604 | MFC_FN(tuple->Flags) = 1; | ||
605 | tuple->LinkOffset += function * 5; | ||
606 | } | ||
607 | break; | ||
608 | case CISTPL_NO_LINK: | ||
609 | HAS_LINK(tuple->Flags) = 0; | ||
610 | break; | ||
611 | } | ||
612 | if ((tuple->Attributes & TUPLE_RETURN_LINK) && | ||
613 | (tuple->DesiredTuple == RETURN_FIRST_TUPLE)) | ||
614 | break; | ||
615 | } else | ||
616 | if (tuple->DesiredTuple == RETURN_FIRST_TUPLE) | ||
617 | break; | ||
618 | |||
619 | if (link[0] == tuple->DesiredTuple) | ||
620 | break; | ||
621 | ofs += link[1] + 2; | ||
523 | } | 622 | } |
524 | 623 | if (i == MAX_TUPLES) { | |
525 | /* End of chain? Follow long link if possible */ | 624 | dev_dbg(&s->dev, "cs: overrun in pcmcia_get_next_tuple\n"); |
526 | if (link[0] == CISTPL_END) { | ||
527 | ofs = follow_link(s, tuple); | ||
528 | if (ofs < 0) | ||
529 | return -ENOSPC; | 625 | return -ENOSPC; |
530 | attr = SPACE(tuple->Flags); | ||
531 | read_cis_cache(s, attr, ofs, 2, link); | ||
532 | } | 626 | } |
533 | 627 | ||
534 | /* Is this a link tuple? Make a note of it */ | 628 | tuple->TupleCode = link[0]; |
535 | if ((link[0] == CISTPL_LONGLINK_A) || | 629 | tuple->TupleLink = link[1]; |
536 | (link[0] == CISTPL_LONGLINK_C) || | 630 | tuple->CISOffset = ofs + 2; |
537 | (link[0] == CISTPL_LONGLINK_MFC) || | 631 | return 0; |
538 | (link[0] == CISTPL_LINKTARGET) || | ||
539 | (link[0] == CISTPL_INDIRECT) || | ||
540 | (link[0] == CISTPL_NO_LINK)) { | ||
541 | switch (link[0]) { | ||
542 | case CISTPL_LONGLINK_A: | ||
543 | HAS_LINK(tuple->Flags) = 1; | ||
544 | LINK_SPACE(tuple->Flags) = attr | IS_ATTR; | ||
545 | read_cis_cache(s, attr, ofs+2, 4, &tuple->LinkOffset); | ||
546 | break; | ||
547 | case CISTPL_LONGLINK_C: | ||
548 | HAS_LINK(tuple->Flags) = 1; | ||
549 | LINK_SPACE(tuple->Flags) = attr & ~IS_ATTR; | ||
550 | read_cis_cache(s, attr, ofs+2, 4, &tuple->LinkOffset); | ||
551 | break; | ||
552 | case CISTPL_INDIRECT: | ||
553 | HAS_LINK(tuple->Flags) = 1; | ||
554 | LINK_SPACE(tuple->Flags) = IS_ATTR | IS_INDIRECT; | ||
555 | tuple->LinkOffset = 0; | ||
556 | break; | ||
557 | case CISTPL_LONGLINK_MFC: | ||
558 | tuple->LinkOffset = ofs + 3; | ||
559 | LINK_SPACE(tuple->Flags) = attr; | ||
560 | if (function == BIND_FN_ALL) { | ||
561 | /* Follow all the MFC links */ | ||
562 | read_cis_cache(s, attr, ofs+2, 1, &tmp); | ||
563 | MFC_FN(tuple->Flags) = tmp; | ||
564 | } else { | ||
565 | /* Follow exactly one of the links */ | ||
566 | MFC_FN(tuple->Flags) = 1; | ||
567 | tuple->LinkOffset += function * 5; | ||
568 | } | ||
569 | break; | ||
570 | case CISTPL_NO_LINK: | ||
571 | HAS_LINK(tuple->Flags) = 0; | ||
572 | break; | ||
573 | } | ||
574 | if ((tuple->Attributes & TUPLE_RETURN_LINK) && | ||
575 | (tuple->DesiredTuple == RETURN_FIRST_TUPLE)) | ||
576 | break; | ||
577 | } else | ||
578 | if (tuple->DesiredTuple == RETURN_FIRST_TUPLE) | ||
579 | break; | ||
580 | |||
581 | if (link[0] == tuple->DesiredTuple) | ||
582 | break; | ||
583 | ofs += link[1] + 2; | ||
584 | } | ||
585 | if (i == MAX_TUPLES) { | ||
586 | dev_dbg(&s->dev, "cs: overrun in pcmcia_get_next_tuple\n"); | ||
587 | return -ENOSPC; | ||
588 | } | ||
589 | |||
590 | tuple->TupleCode = link[0]; | ||
591 | tuple->TupleLink = link[1]; | ||
592 | tuple->CISOffset = ofs + 2; | ||
593 | return 0; | ||
594 | } | 632 | } |
595 | EXPORT_SYMBOL(pccard_get_next_tuple); | ||
596 | |||
597 | /*====================================================================*/ | ||
598 | |||
599 | #define _MIN(a, b) (((a) < (b)) ? (a) : (b)) | ||
600 | 633 | ||
601 | int pccard_get_tuple_data(struct pcmcia_socket *s, tuple_t *tuple) | 634 | int pccard_get_tuple_data(struct pcmcia_socket *s, tuple_t *tuple) |
602 | { | 635 | { |
603 | u_int len; | 636 | u_int len; |
637 | int ret; | ||
604 | 638 | ||
605 | if (!s) | 639 | if (!s) |
606 | return -EINVAL; | 640 | return -EINVAL; |
607 | 641 | ||
608 | if (tuple->TupleLink < tuple->TupleOffset) | 642 | if (tuple->TupleLink < tuple->TupleOffset) |
609 | return -ENOSPC; | 643 | return -ENOSPC; |
610 | len = tuple->TupleLink - tuple->TupleOffset; | 644 | len = tuple->TupleLink - tuple->TupleOffset; |
611 | tuple->TupleDataLen = tuple->TupleLink; | 645 | tuple->TupleDataLen = tuple->TupleLink; |
612 | if (len == 0) | 646 | if (len == 0) |
647 | return 0; | ||
648 | ret = read_cis_cache(s, SPACE(tuple->Flags), | ||
649 | tuple->CISOffset + tuple->TupleOffset, | ||
650 | min(len, (u_int) tuple->TupleDataMax), | ||
651 | tuple->TupleData); | ||
652 | if (ret) | ||
653 | return -1; | ||
613 | return 0; | 654 | return 0; |
614 | read_cis_cache(s, SPACE(tuple->Flags), | ||
615 | tuple->CISOffset + tuple->TupleOffset, | ||
616 | _MIN(len, tuple->TupleDataMax), tuple->TupleData); | ||
617 | return 0; | ||
618 | } | 655 | } |
619 | EXPORT_SYMBOL(pccard_get_tuple_data); | ||
620 | 656 | ||
621 | 657 | ||
622 | /*====================================================================== | 658 | /* Parsing routines for individual tuples */ |
623 | |||
624 | Parsing routines for individual tuples | ||
625 | |||
626 | ======================================================================*/ | ||
627 | 659 | ||
628 | static int parse_device(tuple_t *tuple, cistpl_device_t *device) | 660 | static int parse_device(tuple_t *tuple, cistpl_device_t *device) |
629 | { | 661 | { |
630 | int i; | 662 | int i; |
631 | u_char scale; | 663 | u_char scale; |
632 | u_char *p, *q; | 664 | u_char *p, *q; |
633 | 665 | ||
634 | p = (u_char *)tuple->TupleData; | 666 | p = (u_char *)tuple->TupleData; |
635 | q = p + tuple->TupleDataLen; | 667 | q = p + tuple->TupleDataLen; |
636 | 668 | ||
637 | device->ndev = 0; | 669 | device->ndev = 0; |
638 | for (i = 0; i < CISTPL_MAX_DEVICES; i++) { | 670 | for (i = 0; i < CISTPL_MAX_DEVICES; i++) { |
639 | 671 | ||
640 | if (*p == 0xff) | 672 | if (*p == 0xff) |
641 | break; | 673 | break; |
642 | device->dev[i].type = (*p >> 4); | 674 | device->dev[i].type = (*p >> 4); |
643 | device->dev[i].wp = (*p & 0x08) ? 1 : 0; | 675 | device->dev[i].wp = (*p & 0x08) ? 1 : 0; |
644 | switch (*p & 0x07) { | 676 | switch (*p & 0x07) { |
645 | case 0: | 677 | case 0: |
646 | device->dev[i].speed = 0; | 678 | device->dev[i].speed = 0; |
647 | break; | 679 | break; |
648 | case 1: | 680 | case 1: |
649 | device->dev[i].speed = 250; | 681 | device->dev[i].speed = 250; |
650 | break; | 682 | break; |
651 | case 2: | 683 | case 2: |
652 | device->dev[i].speed = 200; | 684 | device->dev[i].speed = 200; |
653 | break; | 685 | break; |
654 | case 3: | 686 | case 3: |
655 | device->dev[i].speed = 150; | 687 | device->dev[i].speed = 150; |
656 | break; | 688 | break; |
657 | case 4: | 689 | case 4: |
658 | device->dev[i].speed = 100; | 690 | device->dev[i].speed = 100; |
659 | break; | 691 | break; |
660 | case 7: | 692 | case 7: |
661 | if (++p == q) | ||
662 | return -EINVAL; | ||
663 | device->dev[i].speed = SPEED_CVT(*p); | ||
664 | while (*p & 0x80) | ||
665 | if (++p == q) | 693 | if (++p == q) |
666 | return -EINVAL; | 694 | return -EINVAL; |
667 | break; | 695 | device->dev[i].speed = SPEED_CVT(*p); |
668 | default: | 696 | while (*p & 0x80) |
669 | return -EINVAL; | 697 | if (++p == q) |
670 | } | 698 | return -EINVAL; |
699 | break; | ||
700 | default: | ||
701 | return -EINVAL; | ||
702 | } | ||
671 | 703 | ||
672 | if (++p == q) | 704 | if (++p == q) |
673 | return -EINVAL; | 705 | return -EINVAL; |
674 | if (*p == 0xff) | 706 | if (*p == 0xff) |
675 | break; | 707 | break; |
676 | scale = *p & 7; | 708 | scale = *p & 7; |
677 | if (scale == 7) | 709 | if (scale == 7) |
678 | return -EINVAL; | 710 | return -EINVAL; |
679 | device->dev[i].size = ((*p >> 3) + 1) * (512 << (scale*2)); | 711 | device->dev[i].size = ((*p >> 3) + 1) * (512 << (scale*2)); |
680 | device->ndev++; | 712 | device->ndev++; |
681 | if (++p == q) | 713 | if (++p == q) |
682 | break; | 714 | break; |
683 | } | 715 | } |
684 | 716 | ||
685 | return 0; | 717 | return 0; |
686 | } | 718 | } |
687 | 719 | ||
688 | /*====================================================================*/ | ||
689 | 720 | ||
690 | static int parse_checksum(tuple_t *tuple, cistpl_checksum_t *csum) | 721 | static int parse_checksum(tuple_t *tuple, cistpl_checksum_t *csum) |
691 | { | 722 | { |
692 | u_char *p; | 723 | u_char *p; |
693 | if (tuple->TupleDataLen < 5) | 724 | if (tuple->TupleDataLen < 5) |
694 | return -EINVAL; | 725 | return -EINVAL; |
695 | p = (u_char *) tuple->TupleData; | 726 | p = (u_char *) tuple->TupleData; |
696 | csum->addr = tuple->CISOffset + get_unaligned_le16(p) - 2; | 727 | csum->addr = tuple->CISOffset + get_unaligned_le16(p) - 2; |
697 | csum->len = get_unaligned_le16(p + 2); | 728 | csum->len = get_unaligned_le16(p + 2); |
698 | csum->sum = *(p + 4); | 729 | csum->sum = *(p + 4); |
699 | return 0; | 730 | return 0; |
700 | } | 731 | } |
701 | 732 | ||
702 | /*====================================================================*/ | ||
703 | 733 | ||
704 | static int parse_longlink(tuple_t *tuple, cistpl_longlink_t *link) | 734 | static int parse_longlink(tuple_t *tuple, cistpl_longlink_t *link) |
705 | { | 735 | { |
706 | if (tuple->TupleDataLen < 4) | 736 | if (tuple->TupleDataLen < 4) |
707 | return -EINVAL; | 737 | return -EINVAL; |
708 | link->addr = get_unaligned_le32(tuple->TupleData); | 738 | link->addr = get_unaligned_le32(tuple->TupleData); |
709 | return 0; | 739 | return 0; |
710 | } | 740 | } |
711 | 741 | ||
712 | /*====================================================================*/ | ||
713 | 742 | ||
714 | static int parse_longlink_mfc(tuple_t *tuple, | 743 | static int parse_longlink_mfc(tuple_t *tuple, cistpl_longlink_mfc_t *link) |
715 | cistpl_longlink_mfc_t *link) | ||
716 | { | 744 | { |
717 | u_char *p; | 745 | u_char *p; |
718 | int i; | 746 | int i; |
719 | 747 | ||
720 | p = (u_char *)tuple->TupleData; | 748 | p = (u_char *)tuple->TupleData; |
721 | 749 | ||
722 | link->nfn = *p; p++; | 750 | link->nfn = *p; p++; |
723 | if (tuple->TupleDataLen <= link->nfn*5) | 751 | if (tuple->TupleDataLen <= link->nfn*5) |
724 | return -EINVAL; | 752 | return -EINVAL; |
725 | for (i = 0; i < link->nfn; i++) { | 753 | for (i = 0; i < link->nfn; i++) { |
726 | link->fn[i].space = *p; p++; | 754 | link->fn[i].space = *p; p++; |
727 | link->fn[i].addr = get_unaligned_le32(p); | 755 | link->fn[i].addr = get_unaligned_le32(p); |
728 | p += 4; | 756 | p += 4; |
729 | } | 757 | } |
730 | return 0; | 758 | return 0; |
731 | } | 759 | } |
732 | 760 | ||
733 | /*====================================================================*/ | ||
734 | 761 | ||
735 | static int parse_strings(u_char *p, u_char *q, int max, | 762 | static int parse_strings(u_char *p, u_char *q, int max, |
736 | char *s, u_char *ofs, u_char *found) | 763 | char *s, u_char *ofs, u_char *found) |
737 | { | 764 | { |
738 | int i, j, ns; | 765 | int i, j, ns; |
739 | 766 | ||
740 | if (p == q) | 767 | if (p == q) |
741 | return -EINVAL; | 768 | return -EINVAL; |
742 | ns = 0; j = 0; | 769 | ns = 0; j = 0; |
743 | for (i = 0; i < max; i++) { | 770 | for (i = 0; i < max; i++) { |
744 | if (*p == 0xff) | 771 | if (*p == 0xff) |
745 | break; | 772 | break; |
746 | ofs[i] = j; | 773 | ofs[i] = j; |
747 | ns++; | 774 | ns++; |
748 | for (;;) { | 775 | for (;;) { |
749 | s[j++] = (*p == 0xff) ? '\0' : *p; | 776 | s[j++] = (*p == 0xff) ? '\0' : *p; |
750 | if ((*p == '\0') || (*p == 0xff)) | 777 | if ((*p == '\0') || (*p == 0xff)) |
751 | break; | 778 | break; |
752 | if (++p == q) | 779 | if (++p == q) |
753 | return -EINVAL; | 780 | return -EINVAL; |
781 | } | ||
782 | if ((*p == 0xff) || (++p == q)) | ||
783 | break; | ||
754 | } | 784 | } |
755 | if ((*p == 0xff) || (++p == q)) | 785 | if (found) { |
756 | break; | 786 | *found = ns; |
757 | } | 787 | return 0; |
758 | if (found) { | 788 | } |
759 | *found = ns; | 789 | |
760 | return 0; | ||
761 | } else { | ||
762 | return (ns == max) ? 0 : -EINVAL; | 790 | return (ns == max) ? 0 : -EINVAL; |
763 | } | ||
764 | } | 791 | } |
765 | 792 | ||
766 | /*====================================================================*/ | ||
767 | 793 | ||
768 | static int parse_vers_1(tuple_t *tuple, cistpl_vers_1_t *vers_1) | 794 | static int parse_vers_1(tuple_t *tuple, cistpl_vers_1_t *vers_1) |
769 | { | 795 | { |
770 | u_char *p, *q; | 796 | u_char *p, *q; |
771 | 797 | ||
772 | p = (u_char *)tuple->TupleData; | 798 | p = (u_char *)tuple->TupleData; |
773 | q = p + tuple->TupleDataLen; | 799 | q = p + tuple->TupleDataLen; |
774 | 800 | ||
775 | vers_1->major = *p; p++; | 801 | vers_1->major = *p; p++; |
776 | vers_1->minor = *p; p++; | 802 | vers_1->minor = *p; p++; |
777 | if (p >= q) | 803 | if (p >= q) |
778 | return -EINVAL; | 804 | return -EINVAL; |
779 | 805 | ||
780 | return parse_strings(p, q, CISTPL_VERS_1_MAX_PROD_STRINGS, | 806 | return parse_strings(p, q, CISTPL_VERS_1_MAX_PROD_STRINGS, |
781 | vers_1->str, vers_1->ofs, &vers_1->ns); | 807 | vers_1->str, vers_1->ofs, &vers_1->ns); |
782 | } | 808 | } |
783 | 809 | ||
784 | /*====================================================================*/ | ||
785 | 810 | ||
786 | static int parse_altstr(tuple_t *tuple, cistpl_altstr_t *altstr) | 811 | static int parse_altstr(tuple_t *tuple, cistpl_altstr_t *altstr) |
787 | { | 812 | { |
788 | u_char *p, *q; | 813 | u_char *p, *q; |
789 | 814 | ||
790 | p = (u_char *)tuple->TupleData; | 815 | p = (u_char *)tuple->TupleData; |
791 | q = p + tuple->TupleDataLen; | 816 | q = p + tuple->TupleDataLen; |
792 | 817 | ||
793 | return parse_strings(p, q, CISTPL_MAX_ALTSTR_STRINGS, | 818 | return parse_strings(p, q, CISTPL_MAX_ALTSTR_STRINGS, |
794 | altstr->str, altstr->ofs, &altstr->ns); | 819 | altstr->str, altstr->ofs, &altstr->ns); |
795 | } | 820 | } |
796 | 821 | ||
797 | /*====================================================================*/ | ||
798 | 822 | ||
799 | static int parse_jedec(tuple_t *tuple, cistpl_jedec_t *jedec) | 823 | static int parse_jedec(tuple_t *tuple, cistpl_jedec_t *jedec) |
800 | { | 824 | { |
801 | u_char *p, *q; | 825 | u_char *p, *q; |
802 | int nid; | 826 | int nid; |
803 | 827 | ||
804 | p = (u_char *)tuple->TupleData; | 828 | p = (u_char *)tuple->TupleData; |
805 | q = p + tuple->TupleDataLen; | 829 | q = p + tuple->TupleDataLen; |
806 | 830 | ||
807 | for (nid = 0; nid < CISTPL_MAX_DEVICES; nid++) { | 831 | for (nid = 0; nid < CISTPL_MAX_DEVICES; nid++) { |
808 | if (p > q-2) | 832 | if (p > q-2) |
809 | break; | 833 | break; |
810 | jedec->id[nid].mfr = p[0]; | 834 | jedec->id[nid].mfr = p[0]; |
811 | jedec->id[nid].info = p[1]; | 835 | jedec->id[nid].info = p[1]; |
812 | p += 2; | 836 | p += 2; |
813 | } | 837 | } |
814 | jedec->nid = nid; | 838 | jedec->nid = nid; |
815 | return 0; | 839 | return 0; |
816 | } | 840 | } |
817 | 841 | ||
818 | /*====================================================================*/ | ||
819 | 842 | ||
820 | static int parse_manfid(tuple_t *tuple, cistpl_manfid_t *m) | 843 | static int parse_manfid(tuple_t *tuple, cistpl_manfid_t *m) |
821 | { | 844 | { |
822 | if (tuple->TupleDataLen < 4) | 845 | if (tuple->TupleDataLen < 4) |
823 | return -EINVAL; | 846 | return -EINVAL; |
824 | m->manf = get_unaligned_le16(tuple->TupleData); | 847 | m->manf = get_unaligned_le16(tuple->TupleData); |
825 | m->card = get_unaligned_le16(tuple->TupleData + 2); | 848 | m->card = get_unaligned_le16(tuple->TupleData + 2); |
826 | return 0; | 849 | return 0; |
827 | } | 850 | } |
828 | 851 | ||
829 | /*====================================================================*/ | ||
830 | 852 | ||
831 | static int parse_funcid(tuple_t *tuple, cistpl_funcid_t *f) | 853 | static int parse_funcid(tuple_t *tuple, cistpl_funcid_t *f) |
832 | { | 854 | { |
833 | u_char *p; | 855 | u_char *p; |
834 | if (tuple->TupleDataLen < 2) | 856 | if (tuple->TupleDataLen < 2) |
835 | return -EINVAL; | 857 | return -EINVAL; |
836 | p = (u_char *)tuple->TupleData; | 858 | p = (u_char *)tuple->TupleData; |
837 | f->func = p[0]; | 859 | f->func = p[0]; |
838 | f->sysinit = p[1]; | 860 | f->sysinit = p[1]; |
839 | return 0; | 861 | return 0; |
840 | } | 862 | } |
841 | 863 | ||
842 | /*====================================================================*/ | ||
843 | 864 | ||
844 | static int parse_funce(tuple_t *tuple, cistpl_funce_t *f) | 865 | static int parse_funce(tuple_t *tuple, cistpl_funce_t *f) |
845 | { | 866 | { |
846 | u_char *p; | 867 | u_char *p; |
847 | int i; | 868 | int i; |
848 | if (tuple->TupleDataLen < 1) | 869 | if (tuple->TupleDataLen < 1) |
849 | return -EINVAL; | 870 | return -EINVAL; |
850 | p = (u_char *)tuple->TupleData; | 871 | p = (u_char *)tuple->TupleData; |
851 | f->type = p[0]; | 872 | f->type = p[0]; |
852 | for (i = 1; i < tuple->TupleDataLen; i++) | 873 | for (i = 1; i < tuple->TupleDataLen; i++) |
853 | f->data[i-1] = p[i]; | 874 | f->data[i-1] = p[i]; |
854 | return 0; | 875 | return 0; |
855 | } | 876 | } |
856 | 877 | ||
857 | /*====================================================================*/ | ||
858 | 878 | ||
859 | static int parse_config(tuple_t *tuple, cistpl_config_t *config) | 879 | static int parse_config(tuple_t *tuple, cistpl_config_t *config) |
860 | { | 880 | { |
861 | int rasz, rmsz, i; | 881 | int rasz, rmsz, i; |
862 | u_char *p; | 882 | u_char *p; |
863 | 883 | ||
864 | p = (u_char *)tuple->TupleData; | 884 | p = (u_char *)tuple->TupleData; |
865 | rasz = *p & 0x03; | 885 | rasz = *p & 0x03; |
866 | rmsz = (*p & 0x3c) >> 2; | 886 | rmsz = (*p & 0x3c) >> 2; |
867 | if (tuple->TupleDataLen < rasz+rmsz+4) | 887 | if (tuple->TupleDataLen < rasz+rmsz+4) |
868 | return -EINVAL; | 888 | return -EINVAL; |
869 | config->last_idx = *(++p); | 889 | config->last_idx = *(++p); |
870 | p++; | 890 | p++; |
871 | config->base = 0; | 891 | config->base = 0; |
872 | for (i = 0; i <= rasz; i++) | 892 | for (i = 0; i <= rasz; i++) |
873 | config->base += p[i] << (8*i); | 893 | config->base += p[i] << (8*i); |
874 | p += rasz+1; | 894 | p += rasz+1; |
875 | for (i = 0; i < 4; i++) | 895 | for (i = 0; i < 4; i++) |
876 | config->rmask[i] = 0; | 896 | config->rmask[i] = 0; |
877 | for (i = 0; i <= rmsz; i++) | 897 | for (i = 0; i <= rmsz; i++) |
878 | config->rmask[i>>2] += p[i] << (8*(i%4)); | 898 | config->rmask[i>>2] += p[i] << (8*(i%4)); |
879 | config->subtuples = tuple->TupleDataLen - (rasz+rmsz+4); | 899 | config->subtuples = tuple->TupleDataLen - (rasz+rmsz+4); |
880 | return 0; | 900 | return 0; |
881 | } | 901 | } |
882 | 902 | ||
883 | /*====================================================================== | 903 | /* The following routines are all used to parse the nightmarish |
904 | * config table entries. | ||
905 | */ | ||
906 | |||
907 | static u_char *parse_power(u_char *p, u_char *q, cistpl_power_t *pwr) | ||
908 | { | ||
909 | int i; | ||
910 | u_int scale; | ||
884 | 911 | ||
885 | The following routines are all used to parse the nightmarish | 912 | if (p == q) |
886 | config table entries. | 913 | return NULL; |
914 | pwr->present = *p; | ||
915 | pwr->flags = 0; | ||
916 | p++; | ||
917 | for (i = 0; i < 7; i++) | ||
918 | if (pwr->present & (1<<i)) { | ||
919 | if (p == q) | ||
920 | return NULL; | ||
921 | pwr->param[i] = POWER_CVT(*p); | ||
922 | scale = POWER_SCALE(*p); | ||
923 | while (*p & 0x80) { | ||
924 | if (++p == q) | ||
925 | return NULL; | ||
926 | if ((*p & 0x7f) < 100) | ||
927 | pwr->param[i] += | ||
928 | (*p & 0x7f) * scale / 100; | ||
929 | else if (*p == 0x7d) | ||
930 | pwr->flags |= CISTPL_POWER_HIGHZ_OK; | ||
931 | else if (*p == 0x7e) | ||
932 | pwr->param[i] = 0; | ||
933 | else if (*p == 0x7f) | ||
934 | pwr->flags |= CISTPL_POWER_HIGHZ_REQ; | ||
935 | else | ||
936 | return NULL; | ||
937 | } | ||
938 | p++; | ||
939 | } | ||
940 | return p; | ||
941 | } | ||
887 | 942 | ||
888 | ======================================================================*/ | ||
889 | 943 | ||
890 | static u_char *parse_power(u_char *p, u_char *q, | 944 | static u_char *parse_timing(u_char *p, u_char *q, cistpl_timing_t *timing) |
891 | cistpl_power_t *pwr) | ||
892 | { | 945 | { |
893 | int i; | 946 | u_char scale; |
894 | u_int scale; | 947 | |
895 | 948 | if (p == q) | |
896 | if (p == q) | 949 | return NULL; |
897 | return NULL; | 950 | scale = *p; |
898 | pwr->present = *p; | 951 | if ((scale & 3) != 3) { |
899 | pwr->flags = 0; | ||
900 | p++; | ||
901 | for (i = 0; i < 7; i++) | ||
902 | if (pwr->present & (1<<i)) { | ||
903 | if (p == q) | ||
904 | return NULL; | ||
905 | pwr->param[i] = POWER_CVT(*p); | ||
906 | scale = POWER_SCALE(*p); | ||
907 | while (*p & 0x80) { | ||
908 | if (++p == q) | 952 | if (++p == q) |
909 | return NULL; | 953 | return NULL; |
910 | if ((*p & 0x7f) < 100) | 954 | timing->wait = SPEED_CVT(*p); |
911 | pwr->param[i] += (*p & 0x7f) * scale / 100; | 955 | timing->waitscale = exponent[scale & 3]; |
912 | else if (*p == 0x7d) | 956 | } else |
913 | pwr->flags |= CISTPL_POWER_HIGHZ_OK; | 957 | timing->wait = 0; |
914 | else if (*p == 0x7e) | 958 | scale >>= 2; |
915 | pwr->param[i] = 0; | 959 | if ((scale & 7) != 7) { |
916 | else if (*p == 0x7f) | 960 | if (++p == q) |
917 | pwr->flags |= CISTPL_POWER_HIGHZ_REQ; | 961 | return NULL; |
918 | else | 962 | timing->ready = SPEED_CVT(*p); |
919 | return NULL; | 963 | timing->rdyscale = exponent[scale & 7]; |
920 | } | 964 | } else |
921 | p++; | 965 | timing->ready = 0; |
922 | } | 966 | scale >>= 3; |
923 | return p; | 967 | if (scale != 7) { |
968 | if (++p == q) | ||
969 | return NULL; | ||
970 | timing->reserved = SPEED_CVT(*p); | ||
971 | timing->rsvscale = exponent[scale]; | ||
972 | } else | ||
973 | timing->reserved = 0; | ||
974 | p++; | ||
975 | return p; | ||
924 | } | 976 | } |
925 | 977 | ||
926 | /*====================================================================*/ | ||
927 | 978 | ||
928 | static u_char *parse_timing(u_char *p, u_char *q, | 979 | static u_char *parse_io(u_char *p, u_char *q, cistpl_io_t *io) |
929 | cistpl_timing_t *timing) | ||
930 | { | 980 | { |
931 | u_char scale; | 981 | int i, j, bsz, lsz; |
932 | 982 | ||
933 | if (p == q) | 983 | if (p == q) |
934 | return NULL; | ||
935 | scale = *p; | ||
936 | if ((scale & 3) != 3) { | ||
937 | if (++p == q) | ||
938 | return NULL; | ||
939 | timing->wait = SPEED_CVT(*p); | ||
940 | timing->waitscale = exponent[scale & 3]; | ||
941 | } else | ||
942 | timing->wait = 0; | ||
943 | scale >>= 2; | ||
944 | if ((scale & 7) != 7) { | ||
945 | if (++p == q) | ||
946 | return NULL; | 984 | return NULL; |
947 | timing->ready = SPEED_CVT(*p); | 985 | io->flags = *p; |
948 | timing->rdyscale = exponent[scale & 7]; | 986 | |
949 | } else | 987 | if (!(*p & 0x80)) { |
950 | timing->ready = 0; | 988 | io->nwin = 1; |
951 | scale >>= 3; | 989 | io->win[0].base = 0; |
952 | if (scale != 7) { | 990 | io->win[0].len = (1 << (io->flags & CISTPL_IO_LINES_MASK)); |
991 | return p+1; | ||
992 | } | ||
993 | |||
953 | if (++p == q) | 994 | if (++p == q) |
954 | return NULL; | 995 | return NULL; |
955 | timing->reserved = SPEED_CVT(*p); | 996 | io->nwin = (*p & 0x0f) + 1; |
956 | timing->rsvscale = exponent[scale]; | 997 | bsz = (*p & 0x30) >> 4; |
957 | } else | 998 | if (bsz == 3) |
958 | timing->reserved = 0; | 999 | bsz++; |
959 | p++; | 1000 | lsz = (*p & 0xc0) >> 6; |
960 | return p; | 1001 | if (lsz == 3) |
961 | } | 1002 | lsz++; |
962 | 1003 | p++; | |
963 | /*====================================================================*/ | ||
964 | 1004 | ||
965 | static u_char *parse_io(u_char *p, u_char *q, cistpl_io_t *io) | 1005 | for (i = 0; i < io->nwin; i++) { |
966 | { | 1006 | io->win[i].base = 0; |
967 | int i, j, bsz, lsz; | 1007 | io->win[i].len = 1; |
968 | 1008 | for (j = 0; j < bsz; j++, p++) { | |
969 | if (p == q) | 1009 | if (p == q) |
970 | return NULL; | 1010 | return NULL; |
971 | io->flags = *p; | 1011 | io->win[i].base += *p << (j*8); |
972 | 1012 | } | |
973 | if (!(*p & 0x80)) { | 1013 | for (j = 0; j < lsz; j++, p++) { |
974 | io->nwin = 1; | 1014 | if (p == q) |
975 | io->win[0].base = 0; | 1015 | return NULL; |
976 | io->win[0].len = (1 << (io->flags & CISTPL_IO_LINES_MASK)); | 1016 | io->win[i].len += *p << (j*8); |
977 | return p+1; | 1017 | } |
978 | } | ||
979 | |||
980 | if (++p == q) | ||
981 | return NULL; | ||
982 | io->nwin = (*p & 0x0f) + 1; | ||
983 | bsz = (*p & 0x30) >> 4; | ||
984 | if (bsz == 3) | ||
985 | bsz++; | ||
986 | lsz = (*p & 0xc0) >> 6; | ||
987 | if (lsz == 3) | ||
988 | lsz++; | ||
989 | p++; | ||
990 | |||
991 | for (i = 0; i < io->nwin; i++) { | ||
992 | io->win[i].base = 0; | ||
993 | io->win[i].len = 1; | ||
994 | for (j = 0; j < bsz; j++, p++) { | ||
995 | if (p == q) | ||
996 | return NULL; | ||
997 | io->win[i].base += *p << (j*8); | ||
998 | } | ||
999 | for (j = 0; j < lsz; j++, p++) { | ||
1000 | if (p == q) | ||
1001 | return NULL; | ||
1002 | io->win[i].len += *p << (j*8); | ||
1003 | } | 1018 | } |
1004 | } | 1019 | return p; |
1005 | return p; | ||
1006 | } | 1020 | } |
1007 | 1021 | ||
1008 | /*====================================================================*/ | ||
1009 | 1022 | ||
1010 | static u_char *parse_mem(u_char *p, u_char *q, cistpl_mem_t *mem) | 1023 | static u_char *parse_mem(u_char *p, u_char *q, cistpl_mem_t *mem) |
1011 | { | 1024 | { |
1012 | int i, j, asz, lsz, has_ha; | 1025 | int i, j, asz, lsz, has_ha; |
1013 | u_int len, ca, ha; | 1026 | u_int len, ca, ha; |
1014 | 1027 | ||
1015 | if (p == q) | 1028 | if (p == q) |
1016 | return NULL; | 1029 | return NULL; |
1017 | 1030 | ||
1018 | mem->nwin = (*p & 0x07) + 1; | 1031 | mem->nwin = (*p & 0x07) + 1; |
1019 | lsz = (*p & 0x18) >> 3; | 1032 | lsz = (*p & 0x18) >> 3; |
1020 | asz = (*p & 0x60) >> 5; | 1033 | asz = (*p & 0x60) >> 5; |
1021 | has_ha = (*p & 0x80); | 1034 | has_ha = (*p & 0x80); |
1022 | if (++p == q) | 1035 | if (++p == q) |
1023 | return NULL; | 1036 | return NULL; |
1024 | 1037 | ||
1025 | for (i = 0; i < mem->nwin; i++) { | 1038 | for (i = 0; i < mem->nwin; i++) { |
1026 | len = ca = ha = 0; | 1039 | len = ca = ha = 0; |
1027 | for (j = 0; j < lsz; j++, p++) { | 1040 | for (j = 0; j < lsz; j++, p++) { |
1028 | if (p == q) | 1041 | if (p == q) |
1029 | return NULL; | 1042 | return NULL; |
1030 | len += *p << (j*8); | 1043 | len += *p << (j*8); |
1031 | } | 1044 | } |
1032 | for (j = 0; j < asz; j++, p++) { | 1045 | for (j = 0; j < asz; j++, p++) { |
1033 | if (p == q) | 1046 | if (p == q) |
1034 | return NULL; | 1047 | return NULL; |
1035 | ca += *p << (j*8); | 1048 | ca += *p << (j*8); |
1049 | } | ||
1050 | if (has_ha) | ||
1051 | for (j = 0; j < asz; j++, p++) { | ||
1052 | if (p == q) | ||
1053 | return NULL; | ||
1054 | ha += *p << (j*8); | ||
1055 | } | ||
1056 | mem->win[i].len = len << 8; | ||
1057 | mem->win[i].card_addr = ca << 8; | ||
1058 | mem->win[i].host_addr = ha << 8; | ||
1036 | } | 1059 | } |
1037 | if (has_ha) | 1060 | return p; |
1038 | for (j = 0; j < asz; j++, p++) { | ||
1039 | if (p == q) | ||
1040 | return NULL; | ||
1041 | ha += *p << (j*8); | ||
1042 | } | ||
1043 | mem->win[i].len = len << 8; | ||
1044 | mem->win[i].card_addr = ca << 8; | ||
1045 | mem->win[i].host_addr = ha << 8; | ||
1046 | } | ||
1047 | return p; | ||
1048 | } | 1061 | } |
1049 | 1062 | ||
1050 | /*====================================================================*/ | ||
1051 | 1063 | ||
1052 | static u_char *parse_irq(u_char *p, u_char *q, cistpl_irq_t *irq) | 1064 | static u_char *parse_irq(u_char *p, u_char *q, cistpl_irq_t *irq) |
1053 | { | 1065 | { |
1054 | if (p == q) | 1066 | if (p == q) |
1055 | return NULL; | ||
1056 | irq->IRQInfo1 = *p; p++; | ||
1057 | if (irq->IRQInfo1 & IRQ_INFO2_VALID) { | ||
1058 | if (p+2 > q) | ||
1059 | return NULL; | 1067 | return NULL; |
1060 | irq->IRQInfo2 = (p[1]<<8) + p[0]; | 1068 | irq->IRQInfo1 = *p; p++; |
1061 | p += 2; | 1069 | if (irq->IRQInfo1 & IRQ_INFO2_VALID) { |
1062 | } | 1070 | if (p+2 > q) |
1063 | return p; | 1071 | return NULL; |
1072 | irq->IRQInfo2 = (p[1]<<8) + p[0]; | ||
1073 | p += 2; | ||
1074 | } | ||
1075 | return p; | ||
1064 | } | 1076 | } |
1065 | 1077 | ||
1066 | /*====================================================================*/ | ||
1067 | 1078 | ||
1068 | static int parse_cftable_entry(tuple_t *tuple, | 1079 | static int parse_cftable_entry(tuple_t *tuple, |
1069 | cistpl_cftable_entry_t *entry) | 1080 | cistpl_cftable_entry_t *entry) |
1070 | { | 1081 | { |
1071 | u_char *p, *q, features; | 1082 | u_char *p, *q, features; |
1072 | |||
1073 | p = tuple->TupleData; | ||
1074 | q = p + tuple->TupleDataLen; | ||
1075 | entry->index = *p & 0x3f; | ||
1076 | entry->flags = 0; | ||
1077 | if (*p & 0x40) | ||
1078 | entry->flags |= CISTPL_CFTABLE_DEFAULT; | ||
1079 | if (*p & 0x80) { | ||
1080 | if (++p == q) | ||
1081 | return -EINVAL; | ||
1082 | if (*p & 0x10) | ||
1083 | entry->flags |= CISTPL_CFTABLE_BVDS; | ||
1084 | if (*p & 0x20) | ||
1085 | entry->flags |= CISTPL_CFTABLE_WP; | ||
1086 | if (*p & 0x40) | ||
1087 | entry->flags |= CISTPL_CFTABLE_RDYBSY; | ||
1088 | if (*p & 0x80) | ||
1089 | entry->flags |= CISTPL_CFTABLE_MWAIT; | ||
1090 | entry->interface = *p & 0x0f; | ||
1091 | } else | ||
1092 | entry->interface = 0; | ||
1093 | |||
1094 | /* Process optional features */ | ||
1095 | if (++p == q) | ||
1096 | return -EINVAL; | ||
1097 | features = *p; p++; | ||
1098 | |||
1099 | /* Power options */ | ||
1100 | if ((features & 3) > 0) { | ||
1101 | p = parse_power(p, q, &entry->vcc); | ||
1102 | if (p == NULL) | ||
1103 | return -EINVAL; | ||
1104 | } else | ||
1105 | entry->vcc.present = 0; | ||
1106 | if ((features & 3) > 1) { | ||
1107 | p = parse_power(p, q, &entry->vpp1); | ||
1108 | if (p == NULL) | ||
1109 | return -EINVAL; | ||
1110 | } else | ||
1111 | entry->vpp1.present = 0; | ||
1112 | if ((features & 3) > 2) { | ||
1113 | p = parse_power(p, q, &entry->vpp2); | ||
1114 | if (p == NULL) | ||
1115 | return -EINVAL; | ||
1116 | } else | ||
1117 | entry->vpp2.present = 0; | ||
1118 | |||
1119 | /* Timing options */ | ||
1120 | if (features & 0x04) { | ||
1121 | p = parse_timing(p, q, &entry->timing); | ||
1122 | if (p == NULL) | ||
1123 | return -EINVAL; | ||
1124 | } else { | ||
1125 | entry->timing.wait = 0; | ||
1126 | entry->timing.ready = 0; | ||
1127 | entry->timing.reserved = 0; | ||
1128 | } | ||
1129 | |||
1130 | /* I/O window options */ | ||
1131 | if (features & 0x08) { | ||
1132 | p = parse_io(p, q, &entry->io); | ||
1133 | if (p == NULL) | ||
1134 | return -EINVAL; | ||
1135 | } else | ||
1136 | entry->io.nwin = 0; | ||
1137 | 1083 | ||
1138 | /* Interrupt options */ | 1084 | p = tuple->TupleData; |
1139 | if (features & 0x10) { | 1085 | q = p + tuple->TupleDataLen; |
1140 | p = parse_irq(p, q, &entry->irq); | 1086 | entry->index = *p & 0x3f; |
1141 | if (p == NULL) | 1087 | entry->flags = 0; |
1142 | return -EINVAL; | 1088 | if (*p & 0x40) |
1143 | } else | 1089 | entry->flags |= CISTPL_CFTABLE_DEFAULT; |
1144 | entry->irq.IRQInfo1 = 0; | 1090 | if (*p & 0x80) { |
1145 | 1091 | if (++p == q) | |
1146 | switch (features & 0x60) { | 1092 | return -EINVAL; |
1147 | case 0x00: | 1093 | if (*p & 0x10) |
1148 | entry->mem.nwin = 0; | 1094 | entry->flags |= CISTPL_CFTABLE_BVDS; |
1149 | break; | 1095 | if (*p & 0x20) |
1150 | case 0x20: | 1096 | entry->flags |= CISTPL_CFTABLE_WP; |
1151 | entry->mem.nwin = 1; | 1097 | if (*p & 0x40) |
1152 | entry->mem.win[0].len = get_unaligned_le16(p) << 8; | 1098 | entry->flags |= CISTPL_CFTABLE_RDYBSY; |
1153 | entry->mem.win[0].card_addr = 0; | 1099 | if (*p & 0x80) |
1154 | entry->mem.win[0].host_addr = 0; | 1100 | entry->flags |= CISTPL_CFTABLE_MWAIT; |
1155 | p += 2; | 1101 | entry->interface = *p & 0x0f; |
1156 | if (p > q) | 1102 | } else |
1157 | return -EINVAL; | 1103 | entry->interface = 0; |
1158 | break; | ||
1159 | case 0x40: | ||
1160 | entry->mem.nwin = 1; | ||
1161 | entry->mem.win[0].len = get_unaligned_le16(p) << 8; | ||
1162 | entry->mem.win[0].card_addr = get_unaligned_le16(p + 2) << 8; | ||
1163 | entry->mem.win[0].host_addr = 0; | ||
1164 | p += 4; | ||
1165 | if (p > q) | ||
1166 | return -EINVAL; | ||
1167 | break; | ||
1168 | case 0x60: | ||
1169 | p = parse_mem(p, q, &entry->mem); | ||
1170 | if (p == NULL) | ||
1171 | return -EINVAL; | ||
1172 | break; | ||
1173 | } | ||
1174 | 1104 | ||
1175 | /* Misc features */ | 1105 | /* Process optional features */ |
1176 | if (features & 0x80) { | 1106 | if (++p == q) |
1177 | if (p == q) | ||
1178 | return -EINVAL; | 1107 | return -EINVAL; |
1179 | entry->flags |= (*p << 8); | 1108 | features = *p; p++; |
1180 | while (*p & 0x80) | ||
1181 | if (++p == q) | ||
1182 | return -EINVAL; | ||
1183 | p++; | ||
1184 | } | ||
1185 | 1109 | ||
1186 | entry->subtuples = q-p; | 1110 | /* Power options */ |
1187 | 1111 | if ((features & 3) > 0) { | |
1188 | return 0; | 1112 | p = parse_power(p, q, &entry->vcc); |
1189 | } | 1113 | if (p == NULL) |
1190 | 1114 | return -EINVAL; | |
1191 | /*====================================================================*/ | 1115 | } else |
1192 | 1116 | entry->vcc.present = 0; | |
1193 | #ifdef CONFIG_CARDBUS | 1117 | if ((features & 3) > 1) { |
1194 | 1118 | p = parse_power(p, q, &entry->vpp1); | |
1195 | static int parse_bar(tuple_t *tuple, cistpl_bar_t *bar) | 1119 | if (p == NULL) |
1196 | { | 1120 | return -EINVAL; |
1197 | u_char *p; | 1121 | } else |
1198 | if (tuple->TupleDataLen < 6) | 1122 | entry->vpp1.present = 0; |
1199 | return -EINVAL; | 1123 | if ((features & 3) > 2) { |
1200 | p = (u_char *)tuple->TupleData; | 1124 | p = parse_power(p, q, &entry->vpp2); |
1201 | bar->attr = *p; | 1125 | if (p == NULL) |
1202 | p += 2; | 1126 | return -EINVAL; |
1203 | bar->size = get_unaligned_le32(p); | 1127 | } else |
1204 | return 0; | 1128 | entry->vpp2.present = 0; |
1205 | } | ||
1206 | 1129 | ||
1207 | static int parse_config_cb(tuple_t *tuple, cistpl_config_t *config) | 1130 | /* Timing options */ |
1208 | { | 1131 | if (features & 0x04) { |
1209 | u_char *p; | 1132 | p = parse_timing(p, q, &entry->timing); |
1210 | 1133 | if (p == NULL) | |
1211 | p = (u_char *)tuple->TupleData; | 1134 | return -EINVAL; |
1212 | if ((*p != 3) || (tuple->TupleDataLen < 6)) | 1135 | } else { |
1213 | return -EINVAL; | 1136 | entry->timing.wait = 0; |
1214 | config->last_idx = *(++p); | 1137 | entry->timing.ready = 0; |
1215 | p++; | 1138 | entry->timing.reserved = 0; |
1216 | config->base = get_unaligned_le32(p); | 1139 | } |
1217 | config->subtuples = tuple->TupleDataLen - 6; | ||
1218 | return 0; | ||
1219 | } | ||
1220 | 1140 | ||
1221 | static int parse_cftable_entry_cb(tuple_t *tuple, | 1141 | /* I/O window options */ |
1222 | cistpl_cftable_entry_cb_t *entry) | 1142 | if (features & 0x08) { |
1223 | { | 1143 | p = parse_io(p, q, &entry->io); |
1224 | u_char *p, *q, features; | 1144 | if (p == NULL) |
1225 | 1145 | return -EINVAL; | |
1226 | p = tuple->TupleData; | 1146 | } else |
1227 | q = p + tuple->TupleDataLen; | 1147 | entry->io.nwin = 0; |
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 | 1148 | ||
1258 | /* I/O window options */ | 1149 | /* Interrupt options */ |
1259 | if (features & 0x08) { | 1150 | if (features & 0x10) { |
1260 | if (p == q) | 1151 | p = parse_irq(p, q, &entry->irq); |
1261 | return -EINVAL; | 1152 | if (p == NULL) |
1262 | entry->io = *p; p++; | 1153 | return -EINVAL; |
1263 | } else | 1154 | } else |
1264 | entry->io = 0; | 1155 | entry->irq.IRQInfo1 = 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 | 1156 | ||
1274 | if (features & 0x20) { | 1157 | switch (features & 0x60) { |
1275 | if (p == q) | 1158 | case 0x00: |
1276 | return -EINVAL; | 1159 | entry->mem.nwin = 0; |
1277 | entry->mem = *p; p++; | 1160 | break; |
1278 | } else | 1161 | case 0x20: |
1279 | entry->mem = 0; | 1162 | entry->mem.nwin = 1; |
1163 | entry->mem.win[0].len = get_unaligned_le16(p) << 8; | ||
1164 | entry->mem.win[0].card_addr = 0; | ||
1165 | entry->mem.win[0].host_addr = 0; | ||
1166 | p += 2; | ||
1167 | if (p > q) | ||
1168 | return -EINVAL; | ||
1169 | break; | ||
1170 | case 0x40: | ||
1171 | entry->mem.nwin = 1; | ||
1172 | entry->mem.win[0].len = get_unaligned_le16(p) << 8; | ||
1173 | entry->mem.win[0].card_addr = get_unaligned_le16(p + 2) << 8; | ||
1174 | entry->mem.win[0].host_addr = 0; | ||
1175 | p += 4; | ||
1176 | if (p > q) | ||
1177 | return -EINVAL; | ||
1178 | break; | ||
1179 | case 0x60: | ||
1180 | p = parse_mem(p, q, &entry->mem); | ||
1181 | if (p == NULL) | ||
1182 | return -EINVAL; | ||
1183 | break; | ||
1184 | } | ||
1280 | 1185 | ||
1281 | /* Misc features */ | 1186 | /* Misc features */ |
1282 | if (features & 0x80) { | 1187 | if (features & 0x80) { |
1283 | if (p == q) | 1188 | if (p == q) |
1284 | return -EINVAL; | 1189 | return -EINVAL; |
1285 | entry->flags |= (*p << 8); | 1190 | entry->flags |= (*p << 8); |
1286 | if (*p & 0x80) { | 1191 | while (*p & 0x80) |
1287 | if (++p == q) | 1192 | if (++p == q) |
1288 | return -EINVAL; | 1193 | return -EINVAL; |
1289 | entry->flags |= (*p << 16); | 1194 | p++; |
1290 | } | 1195 | } |
1291 | while (*p & 0x80) | ||
1292 | if (++p == q) | ||
1293 | return -EINVAL; | ||
1294 | p++; | ||
1295 | } | ||
1296 | 1196 | ||
1297 | entry->subtuples = q-p; | 1197 | entry->subtuples = q-p; |
1298 | 1198 | ||
1299 | return 0; | 1199 | return 0; |
1300 | } | 1200 | } |
1301 | 1201 | ||
1302 | #endif | ||
1303 | |||
1304 | /*====================================================================*/ | ||
1305 | 1202 | ||
1306 | static int parse_device_geo(tuple_t *tuple, cistpl_device_geo_t *geo) | 1203 | static int parse_device_geo(tuple_t *tuple, cistpl_device_geo_t *geo) |
1307 | { | 1204 | { |
1308 | u_char *p, *q; | 1205 | u_char *p, *q; |
1309 | int n; | 1206 | int n; |
1310 | 1207 | ||
1311 | p = (u_char *)tuple->TupleData; | 1208 | p = (u_char *)tuple->TupleData; |
1312 | q = p + tuple->TupleDataLen; | 1209 | q = p + tuple->TupleDataLen; |
1313 | 1210 | ||
1314 | for (n = 0; n < CISTPL_MAX_DEVICES; n++) { | 1211 | for (n = 0; n < CISTPL_MAX_DEVICES; n++) { |
1315 | if (p > q-6) | 1212 | if (p > q-6) |
1316 | break; | 1213 | break; |
1317 | geo->geo[n].buswidth = p[0]; | 1214 | geo->geo[n].buswidth = p[0]; |
1318 | geo->geo[n].erase_block = 1 << (p[1]-1); | 1215 | geo->geo[n].erase_block = 1 << (p[1]-1); |
1319 | geo->geo[n].read_block = 1 << (p[2]-1); | 1216 | geo->geo[n].read_block = 1 << (p[2]-1); |
1320 | geo->geo[n].write_block = 1 << (p[3]-1); | 1217 | geo->geo[n].write_block = 1 << (p[3]-1); |
1321 | geo->geo[n].partition = 1 << (p[4]-1); | 1218 | geo->geo[n].partition = 1 << (p[4]-1); |
1322 | geo->geo[n].interleave = 1 << (p[5]-1); | 1219 | geo->geo[n].interleave = 1 << (p[5]-1); |
1323 | p += 6; | 1220 | p += 6; |
1324 | } | 1221 | } |
1325 | geo->ngeo = n; | 1222 | geo->ngeo = n; |
1326 | return 0; | 1223 | return 0; |
1327 | } | 1224 | } |
1328 | 1225 | ||
1329 | /*====================================================================*/ | ||
1330 | 1226 | ||
1331 | static int parse_vers_2(tuple_t *tuple, cistpl_vers_2_t *v2) | 1227 | static int parse_vers_2(tuple_t *tuple, cistpl_vers_2_t *v2) |
1332 | { | 1228 | { |
1333 | u_char *p, *q; | 1229 | u_char *p, *q; |
1334 | 1230 | ||
1335 | if (tuple->TupleDataLen < 10) | 1231 | if (tuple->TupleDataLen < 10) |
1336 | return -EINVAL; | 1232 | return -EINVAL; |
1337 | 1233 | ||
1338 | p = tuple->TupleData; | 1234 | p = tuple->TupleData; |
1339 | q = p + tuple->TupleDataLen; | 1235 | q = p + tuple->TupleDataLen; |
1340 | 1236 | ||
1341 | v2->vers = p[0]; | 1237 | v2->vers = p[0]; |
1342 | v2->comply = p[1]; | 1238 | v2->comply = p[1]; |
1343 | v2->dindex = get_unaligned_le16(p + 2); | 1239 | v2->dindex = get_unaligned_le16(p + 2); |
1344 | v2->vspec8 = p[6]; | 1240 | v2->vspec8 = p[6]; |
1345 | v2->vspec9 = p[7]; | 1241 | v2->vspec9 = p[7]; |
1346 | v2->nhdr = p[8]; | 1242 | v2->nhdr = p[8]; |
1347 | p += 9; | 1243 | p += 9; |
1348 | return parse_strings(p, q, 2, v2->str, &v2->vendor, NULL); | 1244 | return parse_strings(p, q, 2, v2->str, &v2->vendor, NULL); |
1349 | } | 1245 | } |
1350 | 1246 | ||
1351 | /*====================================================================*/ | ||
1352 | 1247 | ||
1353 | static int parse_org(tuple_t *tuple, cistpl_org_t *org) | 1248 | static int parse_org(tuple_t *tuple, cistpl_org_t *org) |
1354 | { | 1249 | { |
1355 | u_char *p, *q; | 1250 | u_char *p, *q; |
1356 | int i; | 1251 | int i; |
1357 | 1252 | ||
1358 | p = tuple->TupleData; | 1253 | p = tuple->TupleData; |
1359 | q = p + tuple->TupleDataLen; | 1254 | q = p + tuple->TupleDataLen; |
1360 | if (p == q) | 1255 | if (p == q) |
1361 | return -EINVAL; | 1256 | return -EINVAL; |
1362 | org->data_org = *p; | 1257 | org->data_org = *p; |
1363 | if (++p == q) | ||
1364 | return -EINVAL; | ||
1365 | for (i = 0; i < 30; i++) { | ||
1366 | org->desc[i] = *p; | ||
1367 | if (*p == '\0') | ||
1368 | break; | ||
1369 | if (++p == q) | 1258 | if (++p == q) |
1370 | return -EINVAL; | 1259 | return -EINVAL; |
1371 | } | 1260 | for (i = 0; i < 30; i++) { |
1372 | return 0; | 1261 | org->desc[i] = *p; |
1262 | if (*p == '\0') | ||
1263 | break; | ||
1264 | if (++p == q) | ||
1265 | return -EINVAL; | ||
1266 | } | ||
1267 | return 0; | ||
1373 | } | 1268 | } |
1374 | 1269 | ||
1375 | /*====================================================================*/ | ||
1376 | 1270 | ||
1377 | static int parse_format(tuple_t *tuple, cistpl_format_t *fmt) | 1271 | static int parse_format(tuple_t *tuple, cistpl_format_t *fmt) |
1378 | { | 1272 | { |
1379 | u_char *p; | 1273 | u_char *p; |
1380 | 1274 | ||
1381 | if (tuple->TupleDataLen < 10) | 1275 | if (tuple->TupleDataLen < 10) |
1382 | return -EINVAL; | 1276 | return -EINVAL; |
1383 | 1277 | ||
1384 | p = tuple->TupleData; | 1278 | p = tuple->TupleData; |
1385 | 1279 | ||
1386 | fmt->type = p[0]; | 1280 | fmt->type = p[0]; |
1387 | fmt->edc = p[1]; | 1281 | fmt->edc = p[1]; |
1388 | fmt->offset = get_unaligned_le32(p + 2); | 1282 | fmt->offset = get_unaligned_le32(p + 2); |
1389 | fmt->length = get_unaligned_le32(p + 6); | 1283 | fmt->length = get_unaligned_le32(p + 6); |
1390 | 1284 | ||
1391 | return 0; | 1285 | return 0; |
1392 | } | 1286 | } |
1393 | 1287 | ||
1394 | /*====================================================================*/ | ||
1395 | 1288 | ||
1396 | int pcmcia_parse_tuple(tuple_t *tuple, cisparse_t *parse) | 1289 | int pcmcia_parse_tuple(tuple_t *tuple, cisparse_t *parse) |
1397 | { | 1290 | { |
1398 | int ret = 0; | 1291 | int ret = 0; |
1399 | 1292 | ||
1400 | if (tuple->TupleDataLen > tuple->TupleDataMax) | 1293 | if (tuple->TupleDataLen > tuple->TupleDataMax) |
1401 | return -EINVAL; | 1294 | return -EINVAL; |
1402 | switch (tuple->TupleCode) { | 1295 | switch (tuple->TupleCode) { |
1403 | case CISTPL_DEVICE: | 1296 | case CISTPL_DEVICE: |
1404 | case CISTPL_DEVICE_A: | 1297 | case CISTPL_DEVICE_A: |
1405 | ret = parse_device(tuple, &parse->device); | 1298 | ret = parse_device(tuple, &parse->device); |
1406 | break; | 1299 | break; |
1407 | #ifdef CONFIG_CARDBUS | 1300 | case CISTPL_CHECKSUM: |
1408 | case CISTPL_BAR: | 1301 | ret = parse_checksum(tuple, &parse->checksum); |
1409 | ret = parse_bar(tuple, &parse->bar); | 1302 | break; |
1410 | break; | 1303 | case CISTPL_LONGLINK_A: |
1411 | case CISTPL_CONFIG_CB: | 1304 | case CISTPL_LONGLINK_C: |
1412 | ret = parse_config_cb(tuple, &parse->config); | 1305 | ret = parse_longlink(tuple, &parse->longlink); |
1413 | break; | 1306 | break; |
1414 | case CISTPL_CFTABLE_ENTRY_CB: | 1307 | case CISTPL_LONGLINK_MFC: |
1415 | ret = parse_cftable_entry_cb(tuple, &parse->cftable_entry_cb); | 1308 | ret = parse_longlink_mfc(tuple, &parse->longlink_mfc); |
1416 | break; | 1309 | break; |
1417 | #endif | 1310 | case CISTPL_VERS_1: |
1418 | case CISTPL_CHECKSUM: | 1311 | ret = parse_vers_1(tuple, &parse->version_1); |
1419 | ret = parse_checksum(tuple, &parse->checksum); | 1312 | break; |
1420 | break; | 1313 | case CISTPL_ALTSTR: |
1421 | case CISTPL_LONGLINK_A: | 1314 | ret = parse_altstr(tuple, &parse->altstr); |
1422 | case CISTPL_LONGLINK_C: | 1315 | break; |
1423 | ret = parse_longlink(tuple, &parse->longlink); | 1316 | case CISTPL_JEDEC_A: |
1424 | break; | 1317 | case CISTPL_JEDEC_C: |
1425 | case CISTPL_LONGLINK_MFC: | 1318 | ret = parse_jedec(tuple, &parse->jedec); |
1426 | ret = parse_longlink_mfc(tuple, &parse->longlink_mfc); | 1319 | break; |
1427 | break; | 1320 | case CISTPL_MANFID: |
1428 | case CISTPL_VERS_1: | 1321 | ret = parse_manfid(tuple, &parse->manfid); |
1429 | ret = parse_vers_1(tuple, &parse->version_1); | 1322 | break; |
1430 | break; | 1323 | case CISTPL_FUNCID: |
1431 | case CISTPL_ALTSTR: | 1324 | ret = parse_funcid(tuple, &parse->funcid); |
1432 | ret = parse_altstr(tuple, &parse->altstr); | 1325 | break; |
1433 | break; | 1326 | case CISTPL_FUNCE: |
1434 | case CISTPL_JEDEC_A: | 1327 | ret = parse_funce(tuple, &parse->funce); |
1435 | case CISTPL_JEDEC_C: | 1328 | break; |
1436 | ret = parse_jedec(tuple, &parse->jedec); | 1329 | case CISTPL_CONFIG: |
1437 | break; | 1330 | ret = parse_config(tuple, &parse->config); |
1438 | case CISTPL_MANFID: | 1331 | break; |
1439 | ret = parse_manfid(tuple, &parse->manfid); | 1332 | case CISTPL_CFTABLE_ENTRY: |
1440 | break; | 1333 | ret = parse_cftable_entry(tuple, &parse->cftable_entry); |
1441 | case CISTPL_FUNCID: | 1334 | break; |
1442 | ret = parse_funcid(tuple, &parse->funcid); | 1335 | case CISTPL_DEVICE_GEO: |
1443 | break; | 1336 | case CISTPL_DEVICE_GEO_A: |
1444 | case CISTPL_FUNCE: | 1337 | ret = parse_device_geo(tuple, &parse->device_geo); |
1445 | ret = parse_funce(tuple, &parse->funce); | 1338 | break; |
1446 | break; | 1339 | case CISTPL_VERS_2: |
1447 | case CISTPL_CONFIG: | 1340 | ret = parse_vers_2(tuple, &parse->vers_2); |
1448 | ret = parse_config(tuple, &parse->config); | 1341 | break; |
1449 | break; | 1342 | case CISTPL_ORG: |
1450 | case CISTPL_CFTABLE_ENTRY: | 1343 | ret = parse_org(tuple, &parse->org); |
1451 | ret = parse_cftable_entry(tuple, &parse->cftable_entry); | 1344 | break; |
1452 | break; | 1345 | case CISTPL_FORMAT: |
1453 | case CISTPL_DEVICE_GEO: | 1346 | case CISTPL_FORMAT_A: |
1454 | case CISTPL_DEVICE_GEO_A: | 1347 | ret = parse_format(tuple, &parse->format); |
1455 | ret = parse_device_geo(tuple, &parse->device_geo); | 1348 | break; |
1456 | break; | 1349 | case CISTPL_NO_LINK: |
1457 | case CISTPL_VERS_2: | 1350 | case CISTPL_LINKTARGET: |
1458 | ret = parse_vers_2(tuple, &parse->vers_2); | 1351 | ret = 0; |
1459 | break; | 1352 | break; |
1460 | case CISTPL_ORG: | 1353 | default: |
1461 | ret = parse_org(tuple, &parse->org); | 1354 | ret = -EINVAL; |
1462 | break; | 1355 | break; |
1463 | case CISTPL_FORMAT: | 1356 | } |
1464 | case CISTPL_FORMAT_A: | 1357 | if (ret) |
1465 | ret = parse_format(tuple, &parse->format); | 1358 | pr_debug("parse_tuple failed %d\n", ret); |
1466 | break; | 1359 | return ret; |
1467 | case CISTPL_NO_LINK: | ||
1468 | case CISTPL_LINKTARGET: | ||
1469 | ret = 0; | ||
1470 | break; | ||
1471 | default: | ||
1472 | ret = -EINVAL; | ||
1473 | break; | ||
1474 | } | ||
1475 | if (ret) | ||
1476 | pr_debug("parse_tuple failed %d\n", ret); | ||
1477 | return ret; | ||
1478 | } | 1360 | } |
1479 | EXPORT_SYMBOL(pcmcia_parse_tuple); | 1361 | EXPORT_SYMBOL(pcmcia_parse_tuple); |
1480 | 1362 | ||
1481 | /*====================================================================== | ||
1482 | 1363 | ||
1483 | This is used internally by Card Services to look up CIS stuff. | 1364 | /** |
1484 | 1365 | * pccard_read_tuple() - internal CIS tuple access | |
1485 | ======================================================================*/ | 1366 | * @s: the struct pcmcia_socket where the card is inserted |
1486 | 1367 | * @function: the device function we loop for | |
1487 | int pccard_read_tuple(struct pcmcia_socket *s, unsigned int function, cisdata_t code, void *parse) | 1368 | * @code: which CIS code shall we look for? |
1369 | * @parse: buffer where the tuple shall be parsed (or NULL, if no parse) | ||
1370 | * | ||
1371 | * pccard_read_tuple() reads out one tuple and attempts to parse it | ||
1372 | */ | ||
1373 | int pccard_read_tuple(struct pcmcia_socket *s, unsigned int function, | ||
1374 | cisdata_t code, void *parse) | ||
1488 | { | 1375 | { |
1489 | tuple_t tuple; | 1376 | tuple_t tuple; |
1490 | cisdata_t *buf; | 1377 | cisdata_t *buf; |
1491 | int ret; | 1378 | int ret; |
1492 | 1379 | ||
1493 | buf = kmalloc(256, GFP_KERNEL); | 1380 | buf = kmalloc(256, GFP_KERNEL); |
1494 | if (buf == NULL) { | 1381 | if (buf == NULL) { |
1495 | dev_printk(KERN_WARNING, &s->dev, "no memory to read tuple\n"); | 1382 | dev_printk(KERN_WARNING, &s->dev, "no memory to read tuple\n"); |
1496 | return -ENOMEM; | 1383 | return -ENOMEM; |
1497 | } | 1384 | } |
1498 | tuple.DesiredTuple = code; | 1385 | tuple.DesiredTuple = code; |
1499 | tuple.Attributes = 0; | 1386 | tuple.Attributes = 0; |
1500 | if (function == BIND_FN_ALL) | 1387 | if (function == BIND_FN_ALL) |
1501 | tuple.Attributes = TUPLE_RETURN_COMMON; | 1388 | tuple.Attributes = TUPLE_RETURN_COMMON; |
1502 | ret = pccard_get_first_tuple(s, function, &tuple); | 1389 | ret = pccard_get_first_tuple(s, function, &tuple); |
1503 | if (ret != 0) | 1390 | if (ret != 0) |
1504 | goto done; | 1391 | goto done; |
1505 | tuple.TupleData = buf; | 1392 | tuple.TupleData = buf; |
1506 | tuple.TupleOffset = 0; | 1393 | tuple.TupleOffset = 0; |
1507 | tuple.TupleDataMax = 255; | 1394 | tuple.TupleDataMax = 255; |
1508 | ret = pccard_get_tuple_data(s, &tuple); | 1395 | ret = pccard_get_tuple_data(s, &tuple); |
1509 | if (ret != 0) | 1396 | if (ret != 0) |
1510 | goto done; | 1397 | goto done; |
1511 | ret = pcmcia_parse_tuple(&tuple, parse); | 1398 | ret = pcmcia_parse_tuple(&tuple, parse); |
1512 | done: | 1399 | done: |
1513 | kfree(buf); | 1400 | kfree(buf); |
1514 | return ret; | 1401 | return ret; |
1515 | } | 1402 | } |
1516 | EXPORT_SYMBOL(pccard_read_tuple); | ||
1517 | 1403 | ||
1518 | 1404 | ||
1519 | /** | 1405 | /** |
@@ -1573,84 +1459,238 @@ next_entry: | |||
1573 | kfree(buf); | 1459 | kfree(buf); |
1574 | return ret; | 1460 | return ret; |
1575 | } | 1461 | } |
1576 | EXPORT_SYMBOL(pccard_loop_tuple); | ||
1577 | 1462 | ||
1578 | 1463 | ||
1579 | /*====================================================================== | 1464 | /** |
1465 | * pccard_validate_cis() - check whether card has a sensible CIS | ||
1466 | * @s: the struct pcmcia_socket we are to check | ||
1467 | * @info: returns the number of tuples in the (valid) CIS, or 0 | ||
1468 | * | ||
1469 | * This tries to determine if a card has a sensible CIS. In @info, it | ||
1470 | * returns the number of tuples in the CIS, or 0 if the CIS looks bad. The | ||
1471 | * checks include making sure several critical tuples are present and | ||
1472 | * valid; seeing if the total number of tuples is reasonable; and | ||
1473 | * looking for tuples that use reserved codes. | ||
1474 | * | ||
1475 | * The function returns 0 on success. | ||
1476 | */ | ||
1477 | int pccard_validate_cis(struct pcmcia_socket *s, unsigned int *info) | ||
1478 | { | ||
1479 | tuple_t *tuple; | ||
1480 | cisparse_t *p; | ||
1481 | unsigned int count = 0; | ||
1482 | int ret, reserved, dev_ok = 0, ident_ok = 0; | ||
1580 | 1483 | ||
1581 | This tries to determine if a card has a sensible CIS. It returns | 1484 | if (!s) |
1582 | the number of tuples in the CIS, or 0 if the CIS looks bad. The | 1485 | return -EINVAL; |
1583 | checks include making sure several critical tuples are present and | ||
1584 | valid; seeing if the total number of tuples is reasonable; and | ||
1585 | looking for tuples that use reserved codes. | ||
1586 | 1486 | ||
1587 | ======================================================================*/ | 1487 | /* We do not want to validate the CIS cache... */ |
1488 | mutex_lock(&s->ops_mutex); | ||
1489 | destroy_cis_cache(s); | ||
1490 | mutex_unlock(&s->ops_mutex); | ||
1588 | 1491 | ||
1589 | int pccard_validate_cis(struct pcmcia_socket *s, unsigned int *info) | 1492 | tuple = kmalloc(sizeof(*tuple), GFP_KERNEL); |
1590 | { | 1493 | if (tuple == NULL) { |
1591 | tuple_t *tuple; | 1494 | dev_warn(&s->dev, "no memory to validate CIS\n"); |
1592 | cisparse_t *p; | 1495 | return -ENOMEM; |
1593 | unsigned int count = 0; | 1496 | } |
1594 | int ret, reserved, dev_ok = 0, ident_ok = 0; | 1497 | p = kmalloc(sizeof(*p), GFP_KERNEL); |
1595 | 1498 | if (p == NULL) { | |
1596 | if (!s) | 1499 | kfree(tuple); |
1597 | return -EINVAL; | 1500 | dev_warn(&s->dev, "no memory to validate CIS\n"); |
1598 | 1501 | return -ENOMEM; | |
1599 | tuple = kmalloc(sizeof(*tuple), GFP_KERNEL); | 1502 | } |
1600 | if (tuple == NULL) { | 1503 | |
1601 | dev_printk(KERN_WARNING, &s->dev, "no memory to validate CIS\n"); | 1504 | count = reserved = 0; |
1602 | return -ENOMEM; | 1505 | tuple->DesiredTuple = RETURN_FIRST_TUPLE; |
1603 | } | 1506 | tuple->Attributes = TUPLE_RETURN_COMMON; |
1604 | p = kmalloc(sizeof(*p), GFP_KERNEL); | 1507 | ret = pccard_get_first_tuple(s, BIND_FN_ALL, tuple); |
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 | |||
1611 | count = reserved = 0; | ||
1612 | tuple->DesiredTuple = RETURN_FIRST_TUPLE; | ||
1613 | tuple->Attributes = TUPLE_RETURN_COMMON; | ||
1614 | ret = pccard_get_first_tuple(s, BIND_FN_ALL, tuple); | ||
1615 | if (ret != 0) | ||
1616 | goto done; | ||
1617 | |||
1618 | /* First tuple should be DEVICE; we should really have either that | ||
1619 | or a CFTABLE_ENTRY of some sort */ | ||
1620 | if ((tuple->TupleCode == CISTPL_DEVICE) || | ||
1621 | (pccard_read_tuple(s, BIND_FN_ALL, CISTPL_CFTABLE_ENTRY, p) == 0) || | ||
1622 | (pccard_read_tuple(s, BIND_FN_ALL, CISTPL_CFTABLE_ENTRY_CB, p) == 0)) | ||
1623 | dev_ok++; | ||
1624 | |||
1625 | /* All cards should have a MANFID tuple, and/or a VERS_1 or VERS_2 | ||
1626 | tuple, for card identification. Certain old D-Link and Linksys | ||
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) | 1508 | if (ret != 0) |
1639 | break; | 1509 | goto done; |
1640 | if (((tuple->TupleCode > 0x23) && (tuple->TupleCode < 0x40)) || | 1510 | |
1641 | ((tuple->TupleCode > 0x47) && (tuple->TupleCode < 0x80)) || | 1511 | /* First tuple should be DEVICE; we should really have either that |
1642 | ((tuple->TupleCode > 0x90) && (tuple->TupleCode < 0xff))) | 1512 | or a CFTABLE_ENTRY of some sort */ |
1643 | reserved++; | 1513 | if ((tuple->TupleCode == CISTPL_DEVICE) || |
1644 | } | 1514 | (!pccard_read_tuple(s, BIND_FN_ALL, CISTPL_CFTABLE_ENTRY, p)) || |
1645 | if ((count == MAX_TUPLES) || (reserved > 5) || | 1515 | (!pccard_read_tuple(s, BIND_FN_ALL, CISTPL_CFTABLE_ENTRY_CB, p))) |
1646 | ((!dev_ok || !ident_ok) && (count > 10))) | 1516 | dev_ok++; |
1647 | count = 0; | 1517 | |
1518 | /* All cards should have a MANFID tuple, and/or a VERS_1 or VERS_2 | ||
1519 | tuple, for card identification. Certain old D-Link and Linksys | ||
1520 | cards have only a broken VERS_2 tuple; hence the bogus test. */ | ||
1521 | if ((pccard_read_tuple(s, BIND_FN_ALL, CISTPL_MANFID, p) == 0) || | ||
1522 | (pccard_read_tuple(s, BIND_FN_ALL, CISTPL_VERS_1, p) == 0) || | ||
1523 | (pccard_read_tuple(s, BIND_FN_ALL, CISTPL_VERS_2, p) != -ENOSPC)) | ||
1524 | ident_ok++; | ||
1525 | |||
1526 | if (!dev_ok && !ident_ok) | ||
1527 | goto done; | ||
1528 | |||
1529 | for (count = 1; count < MAX_TUPLES; count++) { | ||
1530 | ret = pccard_get_next_tuple(s, BIND_FN_ALL, tuple); | ||
1531 | if (ret != 0) | ||
1532 | break; | ||
1533 | if (((tuple->TupleCode > 0x23) && (tuple->TupleCode < 0x40)) || | ||
1534 | ((tuple->TupleCode > 0x47) && (tuple->TupleCode < 0x80)) || | ||
1535 | ((tuple->TupleCode > 0x90) && (tuple->TupleCode < 0xff))) | ||
1536 | reserved++; | ||
1537 | } | ||
1538 | if ((count == MAX_TUPLES) || (reserved > 5) || | ||
1539 | ((!dev_ok || !ident_ok) && (count > 10))) | ||
1540 | count = 0; | ||
1541 | |||
1542 | ret = 0; | ||
1648 | 1543 | ||
1649 | done: | 1544 | done: |
1650 | if (info) | 1545 | /* invalidate CIS cache on failure */ |
1651 | *info = count; | 1546 | if (!dev_ok || !ident_ok || !count) { |
1652 | kfree(tuple); | 1547 | mutex_lock(&s->ops_mutex); |
1653 | kfree(p); | 1548 | destroy_cis_cache(s); |
1654 | return 0; | 1549 | mutex_unlock(&s->ops_mutex); |
1550 | ret = -EIO; | ||
1551 | } | ||
1552 | |||
1553 | if (info) | ||
1554 | *info = count; | ||
1555 | kfree(tuple); | ||
1556 | kfree(p); | ||
1557 | return ret; | ||
1655 | } | 1558 | } |
1656 | EXPORT_SYMBOL(pccard_validate_cis); | 1559 | |
1560 | |||
1561 | #define to_socket(_dev) container_of(_dev, struct pcmcia_socket, dev) | ||
1562 | |||
1563 | static ssize_t pccard_extract_cis(struct pcmcia_socket *s, char *buf, | ||
1564 | loff_t off, size_t count) | ||
1565 | { | ||
1566 | tuple_t tuple; | ||
1567 | int status, i; | ||
1568 | loff_t pointer = 0; | ||
1569 | ssize_t ret = 0; | ||
1570 | u_char *tuplebuffer; | ||
1571 | u_char *tempbuffer; | ||
1572 | |||
1573 | tuplebuffer = kmalloc(sizeof(u_char) * 256, GFP_KERNEL); | ||
1574 | if (!tuplebuffer) | ||
1575 | return -ENOMEM; | ||
1576 | |||
1577 | tempbuffer = kmalloc(sizeof(u_char) * 258, GFP_KERNEL); | ||
1578 | if (!tempbuffer) { | ||
1579 | ret = -ENOMEM; | ||
1580 | goto free_tuple; | ||
1581 | } | ||
1582 | |||
1583 | memset(&tuple, 0, sizeof(tuple_t)); | ||
1584 | |||
1585 | tuple.Attributes = TUPLE_RETURN_LINK | TUPLE_RETURN_COMMON; | ||
1586 | tuple.DesiredTuple = RETURN_FIRST_TUPLE; | ||
1587 | tuple.TupleOffset = 0; | ||
1588 | |||
1589 | status = pccard_get_first_tuple(s, BIND_FN_ALL, &tuple); | ||
1590 | while (!status) { | ||
1591 | tuple.TupleData = tuplebuffer; | ||
1592 | tuple.TupleDataMax = 255; | ||
1593 | memset(tuplebuffer, 0, sizeof(u_char) * 255); | ||
1594 | |||
1595 | status = pccard_get_tuple_data(s, &tuple); | ||
1596 | if (status) | ||
1597 | break; | ||
1598 | |||
1599 | if (off < (pointer + 2 + tuple.TupleDataLen)) { | ||
1600 | tempbuffer[0] = tuple.TupleCode & 0xff; | ||
1601 | tempbuffer[1] = tuple.TupleLink & 0xff; | ||
1602 | for (i = 0; i < tuple.TupleDataLen; i++) | ||
1603 | tempbuffer[i + 2] = tuplebuffer[i] & 0xff; | ||
1604 | |||
1605 | for (i = 0; i < (2 + tuple.TupleDataLen); i++) { | ||
1606 | if (((i + pointer) >= off) && | ||
1607 | (i + pointer) < (off + count)) { | ||
1608 | buf[ret] = tempbuffer[i]; | ||
1609 | ret++; | ||
1610 | } | ||
1611 | } | ||
1612 | } | ||
1613 | |||
1614 | pointer += 2 + tuple.TupleDataLen; | ||
1615 | |||
1616 | if (pointer >= (off + count)) | ||
1617 | break; | ||
1618 | |||
1619 | if (tuple.TupleCode == CISTPL_END) | ||
1620 | break; | ||
1621 | status = pccard_get_next_tuple(s, BIND_FN_ALL, &tuple); | ||
1622 | } | ||
1623 | |||
1624 | kfree(tempbuffer); | ||
1625 | free_tuple: | ||
1626 | kfree(tuplebuffer); | ||
1627 | |||
1628 | return ret; | ||
1629 | } | ||
1630 | |||
1631 | |||
1632 | static ssize_t pccard_show_cis(struct kobject *kobj, | ||
1633 | struct bin_attribute *bin_attr, | ||
1634 | char *buf, loff_t off, size_t count) | ||
1635 | { | ||
1636 | unsigned int size = 0x200; | ||
1637 | |||
1638 | if (off >= size) | ||
1639 | count = 0; | ||
1640 | else { | ||
1641 | struct pcmcia_socket *s; | ||
1642 | unsigned int chains; | ||
1643 | |||
1644 | if (off + count > size) | ||
1645 | count = size - off; | ||
1646 | |||
1647 | s = to_socket(container_of(kobj, struct device, kobj)); | ||
1648 | |||
1649 | if (!(s->state & SOCKET_PRESENT)) | ||
1650 | return -ENODEV; | ||
1651 | if (pccard_validate_cis(s, &chains)) | ||
1652 | return -EIO; | ||
1653 | if (!chains) | ||
1654 | return -ENODATA; | ||
1655 | |||
1656 | count = pccard_extract_cis(s, buf, off, count); | ||
1657 | } | ||
1658 | |||
1659 | return count; | ||
1660 | } | ||
1661 | |||
1662 | |||
1663 | static ssize_t pccard_store_cis(struct kobject *kobj, | ||
1664 | struct bin_attribute *bin_attr, | ||
1665 | char *buf, loff_t off, size_t count) | ||
1666 | { | ||
1667 | struct pcmcia_socket *s; | ||
1668 | int error; | ||
1669 | |||
1670 | s = to_socket(container_of(kobj, struct device, kobj)); | ||
1671 | |||
1672 | if (off) | ||
1673 | return -EINVAL; | ||
1674 | |||
1675 | if (count >= CISTPL_MAX_CIS_SIZE) | ||
1676 | return -EINVAL; | ||
1677 | |||
1678 | if (!(s->state & SOCKET_PRESENT)) | ||
1679 | return -ENODEV; | ||
1680 | |||
1681 | error = pcmcia_replace_cis(s, buf, count); | ||
1682 | if (error) | ||
1683 | return -EIO; | ||
1684 | |||
1685 | pcmcia_parse_uevents(s, PCMCIA_UEVENT_REQUERY); | ||
1686 | |||
1687 | return count; | ||
1688 | } | ||
1689 | |||
1690 | |||
1691 | struct bin_attribute pccard_cis_attr = { | ||
1692 | .attr = { .name = "cis", .mode = S_IRUGO | S_IWUSR }, | ||
1693 | .size = 0x200, | ||
1694 | .read = pccard_show_cis, | ||
1695 | .write = pccard_store_cis, | ||
1696 | }; | ||
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..9254ab0b29b1 --- /dev/null +++ b/drivers/pcmcia/db1xxx_ss.c | |||
@@ -0,0 +1,612 @@ | |||
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 | phys_addr_t phys_io; | ||
46 | phys_addr_t phys_attr; | ||
47 | phys_addr_t phys_mem; | ||
48 | |||
49 | /* previous flags for set_socket() */ | ||
50 | unsigned int old_flags; | ||
51 | |||
52 | /* interrupt sources: linux irq numbers! */ | ||
53 | int insert_irq; /* default carddetect irq */ | ||
54 | int stschg_irq; /* card-status-change irq */ | ||
55 | int card_irq; /* card irq */ | ||
56 | int eject_irq; /* db1200/pb1200 have these */ | ||
57 | |||
58 | #define BOARD_TYPE_DEFAULT 0 /* most boards */ | ||
59 | #define BOARD_TYPE_DB1200 1 /* IRQs aren't gpios */ | ||
60 | #define BOARD_TYPE_PB1100 2 /* VS bits slightly different */ | ||
61 | int board_type; | ||
62 | }; | ||
63 | |||
64 | #define to_db1x_socket(x) container_of(x, struct db1x_pcmcia_sock, socket) | ||
65 | |||
66 | /* DB/PB1200: check CPLD SIGSTATUS register bit 10/12 */ | ||
67 | static int db1200_card_inserted(struct db1x_pcmcia_sock *sock) | ||
68 | { | ||
69 | unsigned short sigstat; | ||
70 | |||
71 | sigstat = bcsr_read(BCSR_SIGSTAT); | ||
72 | return sigstat & 1 << (8 + 2 * sock->nr); | ||
73 | } | ||
74 | |||
75 | /* carddetect gpio: low-active */ | ||
76 | static int db1000_card_inserted(struct db1x_pcmcia_sock *sock) | ||
77 | { | ||
78 | return !gpio_get_value(irq_to_gpio(sock->insert_irq)); | ||
79 | } | ||
80 | |||
81 | static int db1x_card_inserted(struct db1x_pcmcia_sock *sock) | ||
82 | { | ||
83 | switch (sock->board_type) { | ||
84 | case BOARD_TYPE_DB1200: | ||
85 | return db1200_card_inserted(sock); | ||
86 | default: | ||
87 | return db1000_card_inserted(sock); | ||
88 | } | ||
89 | } | ||
90 | |||
91 | /* STSCHG tends to bounce heavily when cards are inserted/ejected. | ||
92 | * To avoid this, the interrupt is normally disabled and only enabled | ||
93 | * after reset to a card has been de-asserted. | ||
94 | */ | ||
95 | static inline void set_stschg(struct db1x_pcmcia_sock *sock, int en) | ||
96 | { | ||
97 | if (sock->stschg_irq != -1) { | ||
98 | if (en) | ||
99 | enable_irq(sock->stschg_irq); | ||
100 | else | ||
101 | disable_irq(sock->stschg_irq); | ||
102 | } | ||
103 | } | ||
104 | |||
105 | static irqreturn_t db1000_pcmcia_cdirq(int irq, void *data) | ||
106 | { | ||
107 | struct db1x_pcmcia_sock *sock = data; | ||
108 | |||
109 | pcmcia_parse_events(&sock->socket, SS_DETECT); | ||
110 | |||
111 | return IRQ_HANDLED; | ||
112 | } | ||
113 | |||
114 | static irqreturn_t db1000_pcmcia_stschgirq(int irq, void *data) | ||
115 | { | ||
116 | struct db1x_pcmcia_sock *sock = data; | ||
117 | |||
118 | pcmcia_parse_events(&sock->socket, SS_STSCHG); | ||
119 | |||
120 | return IRQ_HANDLED; | ||
121 | } | ||
122 | |||
123 | static irqreturn_t db1200_pcmcia_cdirq(int irq, void *data) | ||
124 | { | ||
125 | struct db1x_pcmcia_sock *sock = data; | ||
126 | |||
127 | /* Db/Pb1200 have separate per-socket insertion and ejection | ||
128 | * interrupts which stay asserted as long as the card is | ||
129 | * inserted/missing. The one which caused us to be called | ||
130 | * needs to be disabled and the other one enabled. | ||
131 | */ | ||
132 | if (irq == sock->insert_irq) { | ||
133 | disable_irq_nosync(sock->insert_irq); | ||
134 | enable_irq(sock->eject_irq); | ||
135 | } else { | ||
136 | disable_irq_nosync(sock->eject_irq); | ||
137 | enable_irq(sock->insert_irq); | ||
138 | } | ||
139 | |||
140 | pcmcia_parse_events(&sock->socket, SS_DETECT); | ||
141 | |||
142 | return IRQ_HANDLED; | ||
143 | } | ||
144 | |||
145 | static int db1x_pcmcia_setup_irqs(struct db1x_pcmcia_sock *sock) | ||
146 | { | ||
147 | int ret; | ||
148 | unsigned long flags; | ||
149 | |||
150 | if (sock->stschg_irq != -1) { | ||
151 | ret = request_irq(sock->stschg_irq, db1000_pcmcia_stschgirq, | ||
152 | 0, "pcmcia_stschg", sock); | ||
153 | if (ret) | ||
154 | return ret; | ||
155 | } | ||
156 | |||
157 | /* Db/Pb1200 have separate per-socket insertion and ejection | ||
158 | * interrupts, which should show edge behaviour but don't. | ||
159 | * So interrupts are disabled until both insertion and | ||
160 | * ejection handler have been registered and the currently | ||
161 | * active one disabled. | ||
162 | */ | ||
163 | if (sock->board_type == BOARD_TYPE_DB1200) { | ||
164 | local_irq_save(flags); | ||
165 | |||
166 | ret = request_irq(sock->insert_irq, db1200_pcmcia_cdirq, | ||
167 | IRQF_DISABLED, "pcmcia_insert", sock); | ||
168 | if (ret) | ||
169 | goto out1; | ||
170 | |||
171 | ret = request_irq(sock->eject_irq, db1200_pcmcia_cdirq, | ||
172 | IRQF_DISABLED, "pcmcia_eject", sock); | ||
173 | if (ret) { | ||
174 | free_irq(sock->insert_irq, sock); | ||
175 | local_irq_restore(flags); | ||
176 | goto out1; | ||
177 | } | ||
178 | |||
179 | /* disable the currently active one */ | ||
180 | if (db1200_card_inserted(sock)) | ||
181 | disable_irq_nosync(sock->insert_irq); | ||
182 | else | ||
183 | disable_irq_nosync(sock->eject_irq); | ||
184 | |||
185 | local_irq_restore(flags); | ||
186 | } else { | ||
187 | /* all other (older) Db1x00 boards use a GPIO to show | ||
188 | * card detection status: use both-edge triggers. | ||
189 | */ | ||
190 | set_irq_type(sock->insert_irq, IRQ_TYPE_EDGE_BOTH); | ||
191 | ret = request_irq(sock->insert_irq, db1000_pcmcia_cdirq, | ||
192 | 0, "pcmcia_carddetect", sock); | ||
193 | |||
194 | if (ret) | ||
195 | goto out1; | ||
196 | } | ||
197 | |||
198 | return 0; /* all done */ | ||
199 | |||
200 | out1: | ||
201 | if (sock->stschg_irq != -1) | ||
202 | free_irq(sock->stschg_irq, sock); | ||
203 | |||
204 | return ret; | ||
205 | } | ||
206 | |||
207 | static void db1x_pcmcia_free_irqs(struct db1x_pcmcia_sock *sock) | ||
208 | { | ||
209 | if (sock->stschg_irq != -1) | ||
210 | free_irq(sock->stschg_irq, sock); | ||
211 | |||
212 | free_irq(sock->insert_irq, sock); | ||
213 | if (sock->eject_irq != -1) | ||
214 | free_irq(sock->eject_irq, sock); | ||
215 | } | ||
216 | |||
217 | /* | ||
218 | * configure a PCMCIA socket on the Db1x00 series of boards (and | ||
219 | * compatibles). | ||
220 | * | ||
221 | * 2 external registers are involved: | ||
222 | * pcmcia_status (offset 0x04): bits [0:1/2:3]: read card voltage id | ||
223 | * pcmcia_control(offset 0x10): | ||
224 | * bits[0:1] set vcc for card | ||
225 | * bits[2:3] set vpp for card | ||
226 | * bit 4: enable data buffers | ||
227 | * bit 7: reset# for card | ||
228 | * add 8 for second socket. | ||
229 | */ | ||
230 | static int db1x_pcmcia_configure(struct pcmcia_socket *skt, | ||
231 | struct socket_state_t *state) | ||
232 | { | ||
233 | struct db1x_pcmcia_sock *sock = to_db1x_socket(skt); | ||
234 | unsigned short cr_clr, cr_set; | ||
235 | unsigned int changed; | ||
236 | int v, p, ret; | ||
237 | |||
238 | /* card voltage setup */ | ||
239 | cr_clr = (0xf << (sock->nr * 8)); /* clear voltage settings */ | ||
240 | cr_set = 0; | ||
241 | v = p = ret = 0; | ||
242 | |||
243 | switch (state->Vcc) { | ||
244 | case 50: | ||
245 | ++v; | ||
246 | case 33: | ||
247 | ++v; | ||
248 | case 0: | ||
249 | break; | ||
250 | default: | ||
251 | printk(KERN_INFO "pcmcia%d unsupported Vcc %d\n", | ||
252 | sock->nr, state->Vcc); | ||
253 | } | ||
254 | |||
255 | switch (state->Vpp) { | ||
256 | case 12: | ||
257 | ++p; | ||
258 | case 33: | ||
259 | case 50: | ||
260 | ++p; | ||
261 | case 0: | ||
262 | break; | ||
263 | default: | ||
264 | printk(KERN_INFO "pcmcia%d unsupported Vpp %d\n", | ||
265 | sock->nr, state->Vpp); | ||
266 | } | ||
267 | |||
268 | /* sanity check: Vpp must be 0, 12, or Vcc */ | ||
269 | if (((state->Vcc == 33) && (state->Vpp == 50)) || | ||
270 | ((state->Vcc == 50) && (state->Vpp == 33))) { | ||
271 | printk(KERN_INFO "pcmcia%d bad Vcc/Vpp combo (%d %d)\n", | ||
272 | sock->nr, state->Vcc, state->Vpp); | ||
273 | v = p = 0; | ||
274 | ret = -EINVAL; | ||
275 | } | ||
276 | |||
277 | /* create new voltage code */ | ||
278 | cr_set |= ((v << 2) | p) << (sock->nr * 8); | ||
279 | |||
280 | changed = state->flags ^ sock->old_flags; | ||
281 | |||
282 | if (changed & SS_RESET) { | ||
283 | if (state->flags & SS_RESET) { | ||
284 | set_stschg(sock, 0); | ||
285 | /* assert reset, disable io buffers */ | ||
286 | cr_clr |= (1 << (7 + (sock->nr * 8))); | ||
287 | cr_clr |= (1 << (4 + (sock->nr * 8))); | ||
288 | } else { | ||
289 | /* de-assert reset, enable io buffers */ | ||
290 | cr_set |= 1 << (7 + (sock->nr * 8)); | ||
291 | cr_set |= 1 << (4 + (sock->nr * 8)); | ||
292 | } | ||
293 | } | ||
294 | |||
295 | /* update PCMCIA configuration */ | ||
296 | bcsr_mod(BCSR_PCMCIA, cr_clr, cr_set); | ||
297 | |||
298 | sock->old_flags = state->flags; | ||
299 | |||
300 | /* reset was taken away: give card time to initialize properly */ | ||
301 | if ((changed & SS_RESET) && !(state->flags & SS_RESET)) { | ||
302 | msleep(500); | ||
303 | set_stschg(sock, 1); | ||
304 | } | ||
305 | |||
306 | return ret; | ||
307 | } | ||
308 | |||
309 | /* VCC bits at [3:2]/[11:10] */ | ||
310 | #define GET_VCC(cr, socknr) \ | ||
311 | ((((cr) >> 2) >> ((socknr) * 8)) & 3) | ||
312 | |||
313 | /* VS bits at [0:1]/[3:2] */ | ||
314 | #define GET_VS(sr, socknr) \ | ||
315 | (((sr) >> (2 * (socknr))) & 3) | ||
316 | |||
317 | /* reset bits at [7]/[15] */ | ||
318 | #define GET_RESET(cr, socknr) \ | ||
319 | ((cr) & (1 << (7 + (8 * (socknr))))) | ||
320 | |||
321 | static int db1x_pcmcia_get_status(struct pcmcia_socket *skt, | ||
322 | unsigned int *value) | ||
323 | { | ||
324 | struct db1x_pcmcia_sock *sock = to_db1x_socket(skt); | ||
325 | unsigned short cr, sr; | ||
326 | unsigned int status; | ||
327 | |||
328 | status = db1x_card_inserted(sock) ? SS_DETECT : 0; | ||
329 | |||
330 | cr = bcsr_read(BCSR_PCMCIA); | ||
331 | sr = bcsr_read(BCSR_STATUS); | ||
332 | |||
333 | /* PB1100/PB1500: voltage key bits are at [5:4] */ | ||
334 | if (sock->board_type == BOARD_TYPE_PB1100) | ||
335 | sr >>= 4; | ||
336 | |||
337 | /* determine card type */ | ||
338 | switch (GET_VS(sr, sock->nr)) { | ||
339 | case 0: | ||
340 | case 2: | ||
341 | status |= SS_3VCARD; /* 3V card */ | ||
342 | case 3: | ||
343 | break; /* 5V card: set nothing */ | ||
344 | default: | ||
345 | status |= SS_XVCARD; /* treated as unsupported in core */ | ||
346 | } | ||
347 | |||
348 | /* if Vcc is not zero, we have applied power to a card */ | ||
349 | status |= GET_VCC(cr, sock->nr) ? SS_POWERON : 0; | ||
350 | |||
351 | /* reset de-asserted? then we're ready */ | ||
352 | status |= (GET_RESET(cr, sock->nr)) ? SS_READY : SS_RESET; | ||
353 | |||
354 | *value = status; | ||
355 | |||
356 | return 0; | ||
357 | } | ||
358 | |||
359 | static int db1x_pcmcia_sock_init(struct pcmcia_socket *skt) | ||
360 | { | ||
361 | return 0; | ||
362 | } | ||
363 | |||
364 | static int db1x_pcmcia_sock_suspend(struct pcmcia_socket *skt) | ||
365 | { | ||
366 | return 0; | ||
367 | } | ||
368 | |||
369 | static int au1x00_pcmcia_set_io_map(struct pcmcia_socket *skt, | ||
370 | struct pccard_io_map *map) | ||
371 | { | ||
372 | struct db1x_pcmcia_sock *sock = to_db1x_socket(skt); | ||
373 | |||
374 | map->start = (u32)sock->virt_io; | ||
375 | map->stop = map->start + IO_MAP_SIZE; | ||
376 | |||
377 | return 0; | ||
378 | } | ||
379 | |||
380 | static int au1x00_pcmcia_set_mem_map(struct pcmcia_socket *skt, | ||
381 | struct pccard_mem_map *map) | ||
382 | { | ||
383 | struct db1x_pcmcia_sock *sock = to_db1x_socket(skt); | ||
384 | |||
385 | if (map->flags & MAP_ATTRIB) | ||
386 | map->static_start = sock->phys_attr + map->card_start; | ||
387 | else | ||
388 | map->static_start = sock->phys_mem + map->card_start; | ||
389 | |||
390 | return 0; | ||
391 | } | ||
392 | |||
393 | static struct pccard_operations db1x_pcmcia_operations = { | ||
394 | .init = db1x_pcmcia_sock_init, | ||
395 | .suspend = db1x_pcmcia_sock_suspend, | ||
396 | .get_status = db1x_pcmcia_get_status, | ||
397 | .set_socket = db1x_pcmcia_configure, | ||
398 | .set_io_map = au1x00_pcmcia_set_io_map, | ||
399 | .set_mem_map = au1x00_pcmcia_set_mem_map, | ||
400 | }; | ||
401 | |||
402 | static int __devinit db1x_pcmcia_socket_probe(struct platform_device *pdev) | ||
403 | { | ||
404 | struct db1x_pcmcia_sock *sock; | ||
405 | struct resource *r; | ||
406 | int ret, bid; | ||
407 | |||
408 | sock = kzalloc(sizeof(struct db1x_pcmcia_sock), GFP_KERNEL); | ||
409 | if (!sock) | ||
410 | return -ENOMEM; | ||
411 | |||
412 | sock->nr = pdev->id; | ||
413 | |||
414 | bid = BCSR_WHOAMI_BOARD(bcsr_read(BCSR_WHOAMI)); | ||
415 | switch (bid) { | ||
416 | case BCSR_WHOAMI_PB1500: | ||
417 | case BCSR_WHOAMI_PB1500R2: | ||
418 | case BCSR_WHOAMI_PB1100: | ||
419 | sock->board_type = BOARD_TYPE_PB1100; | ||
420 | break; | ||
421 | case BCSR_WHOAMI_DB1000 ... BCSR_WHOAMI_PB1550_SDR: | ||
422 | sock->board_type = BOARD_TYPE_DEFAULT; | ||
423 | break; | ||
424 | case BCSR_WHOAMI_PB1200 ... BCSR_WHOAMI_DB1200: | ||
425 | sock->board_type = BOARD_TYPE_DB1200; | ||
426 | break; | ||
427 | default: | ||
428 | printk(KERN_INFO "db1xxx-ss: unknown board %d!\n", bid); | ||
429 | ret = -ENODEV; | ||
430 | goto out0; | ||
431 | }; | ||
432 | |||
433 | /* | ||
434 | * gather resources necessary and optional nice-to-haves to | ||
435 | * operate a socket: | ||
436 | * This includes IRQs for Carddetection/ejection, the card | ||
437 | * itself and optional status change detection. | ||
438 | * Also, the memory areas covered by a socket. For these | ||
439 | * we require the real 36bit addresses (see the au1000.h | ||
440 | * header for more information). | ||
441 | */ | ||
442 | |||
443 | /* card: irq assigned to the card itself. */ | ||
444 | r = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "card"); | ||
445 | sock->card_irq = r ? r->start : 0; | ||
446 | |||
447 | /* insert: irq which triggers on card insertion/ejection */ | ||
448 | r = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "insert"); | ||
449 | sock->insert_irq = r ? r->start : -1; | ||
450 | |||
451 | /* stschg: irq which trigger on card status change (optional) */ | ||
452 | r = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "stschg"); | ||
453 | sock->stschg_irq = r ? r->start : -1; | ||
454 | |||
455 | /* eject: irq which triggers on ejection (DB1200/PB1200 only) */ | ||
456 | r = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "eject"); | ||
457 | sock->eject_irq = r ? r->start : -1; | ||
458 | |||
459 | ret = -ENODEV; | ||
460 | |||
461 | /* 36bit PCMCIA Attribute area address */ | ||
462 | r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pcmcia-attr"); | ||
463 | if (!r) { | ||
464 | printk(KERN_ERR "pcmcia%d has no 'pseudo-attr' resource!\n", | ||
465 | sock->nr); | ||
466 | goto out0; | ||
467 | } | ||
468 | sock->phys_attr = r->start; | ||
469 | |||
470 | /* 36bit PCMCIA Memory area address */ | ||
471 | r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pcmcia-mem"); | ||
472 | if (!r) { | ||
473 | printk(KERN_ERR "pcmcia%d has no 'pseudo-mem' resource!\n", | ||
474 | sock->nr); | ||
475 | goto out0; | ||
476 | } | ||
477 | sock->phys_mem = r->start; | ||
478 | |||
479 | /* 36bit PCMCIA IO area address */ | ||
480 | r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pcmcia-io"); | ||
481 | if (!r) { | ||
482 | printk(KERN_ERR "pcmcia%d has no 'pseudo-io' resource!\n", | ||
483 | sock->nr); | ||
484 | goto out0; | ||
485 | } | ||
486 | sock->phys_io = r->start; | ||
487 | |||
488 | /* | ||
489 | * PCMCIA client drivers use the inb/outb macros to access | ||
490 | * the IO registers. Since mips_io_port_base is added | ||
491 | * to the access address of the mips implementation of | ||
492 | * inb/outb, we need to subtract it here because we want | ||
493 | * to access the I/O or MEM address directly, without | ||
494 | * going through this "mips_io_port_base" mechanism. | ||
495 | */ | ||
496 | sock->virt_io = (void *)(ioremap(sock->phys_io, IO_MAP_SIZE) - | ||
497 | mips_io_port_base); | ||
498 | |||
499 | if (!sock->virt_io) { | ||
500 | printk(KERN_ERR "pcmcia%d: cannot remap IO area\n", | ||
501 | sock->nr); | ||
502 | ret = -ENOMEM; | ||
503 | goto out0; | ||
504 | } | ||
505 | |||
506 | sock->socket.ops = &db1x_pcmcia_operations; | ||
507 | sock->socket.owner = THIS_MODULE; | ||
508 | sock->socket.pci_irq = sock->card_irq; | ||
509 | sock->socket.features = SS_CAP_STATIC_MAP | SS_CAP_PCCARD; | ||
510 | sock->socket.map_size = MEM_MAP_SIZE; | ||
511 | sock->socket.io_offset = (unsigned long)sock->virt_io; | ||
512 | sock->socket.dev.parent = &pdev->dev; | ||
513 | sock->socket.resource_ops = &pccard_static_ops; | ||
514 | |||
515 | platform_set_drvdata(pdev, sock); | ||
516 | |||
517 | ret = db1x_pcmcia_setup_irqs(sock); | ||
518 | if (ret) { | ||
519 | printk(KERN_ERR "pcmcia%d cannot setup interrupts\n", | ||
520 | sock->nr); | ||
521 | goto out1; | ||
522 | } | ||
523 | |||
524 | set_stschg(sock, 0); | ||
525 | |||
526 | ret = pcmcia_register_socket(&sock->socket); | ||
527 | if (ret) { | ||
528 | printk(KERN_ERR "pcmcia%d failed to register\n", sock->nr); | ||
529 | goto out2; | ||
530 | } | ||
531 | |||
532 | printk(KERN_INFO "Alchemy Db/Pb1xxx pcmcia%d @ io/attr/mem %09llx" | ||
533 | "(%p) %09llx %09llx card/insert/stschg/eject irqs @ %d " | ||
534 | "%d %d %d\n", sock->nr, sock->phys_io, sock->virt_io, | ||
535 | sock->phys_attr, sock->phys_mem, sock->card_irq, | ||
536 | sock->insert_irq, sock->stschg_irq, sock->eject_irq); | ||
537 | |||
538 | return 0; | ||
539 | |||
540 | out2: | ||
541 | db1x_pcmcia_free_irqs(sock); | ||
542 | out1: | ||
543 | iounmap((void *)(sock->virt_io + (u32)mips_io_port_base)); | ||
544 | out0: | ||
545 | kfree(sock); | ||
546 | return ret; | ||
547 | } | ||
548 | |||
549 | static int __devexit db1x_pcmcia_socket_remove(struct platform_device *pdev) | ||
550 | { | ||
551 | struct db1x_pcmcia_sock *sock = platform_get_drvdata(pdev); | ||
552 | |||
553 | db1x_pcmcia_free_irqs(sock); | ||
554 | pcmcia_unregister_socket(&sock->socket); | ||
555 | iounmap((void *)(sock->virt_io + (u32)mips_io_port_base)); | ||
556 | kfree(sock); | ||
557 | |||
558 | return 0; | ||
559 | } | ||
560 | |||
561 | #ifdef CONFIG_PM | ||
562 | static int db1x_pcmcia_suspend(struct device *dev) | ||
563 | { | ||
564 | return pcmcia_socket_dev_suspend(dev); | ||
565 | } | ||
566 | |||
567 | static int db1x_pcmcia_resume(struct device *dev) | ||
568 | { | ||
569 | return pcmcia_socket_dev_resume(dev); | ||
570 | } | ||
571 | |||
572 | static struct dev_pm_ops db1x_pcmcia_pmops = { | ||
573 | .resume = db1x_pcmcia_resume, | ||
574 | .suspend = db1x_pcmcia_suspend, | ||
575 | .thaw = db1x_pcmcia_resume, | ||
576 | .freeze = db1x_pcmcia_suspend, | ||
577 | }; | ||
578 | |||
579 | #define DB1XXX_SS_PMOPS &db1x_pcmcia_pmops | ||
580 | |||
581 | #else | ||
582 | |||
583 | #define DB1XXX_SS_PMOPS NULL | ||
584 | |||
585 | #endif | ||
586 | |||
587 | static struct platform_driver db1x_pcmcia_socket_driver = { | ||
588 | .driver = { | ||
589 | .name = "db1xxx_pcmcia", | ||
590 | .owner = THIS_MODULE, | ||
591 | .pm = DB1XXX_SS_PMOPS | ||
592 | }, | ||
593 | .probe = db1x_pcmcia_socket_probe, | ||
594 | .remove = __devexit_p(db1x_pcmcia_socket_remove), | ||
595 | }; | ||
596 | |||
597 | int __init db1x_pcmcia_socket_load(void) | ||
598 | { | ||
599 | return platform_driver_register(&db1x_pcmcia_socket_driver); | ||
600 | } | ||
601 | |||
602 | void __exit db1x_pcmcia_socket_unload(void) | ||
603 | { | ||
604 | platform_driver_unregister(&db1x_pcmcia_socket_driver); | ||
605 | } | ||
606 | |||
607 | module_init(db1x_pcmcia_socket_load); | ||
608 | module_exit(db1x_pcmcia_socket_unload); | ||
609 | |||
610 | MODULE_LICENSE("GPL"); | ||
611 | MODULE_DESCRIPTION("PCMCIA Socket Services for Alchemy Db/Pb1x00 boards"); | ||
612 | 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/pd6729.c b/drivers/pcmcia/pd6729.c index e1741cd875aa..7c204910a777 100644 --- a/drivers/pcmcia/pd6729.c +++ b/drivers/pcmcia/pd6729.c | |||
@@ -48,23 +48,13 @@ MODULE_AUTHOR("Jun Komuro <komurojun-mbn@nifty.com>"); | |||
48 | * Specifies the interrupt delivery mode. The default (1) is to use PCI | 48 | * Specifies the interrupt delivery mode. The default (1) is to use PCI |
49 | * interrupts; a value of 0 selects ISA interrupts. This must be set for | 49 | * interrupts; a value of 0 selects ISA interrupts. This must be set for |
50 | * correct operation of PCI card readers. | 50 | * correct operation of PCI card readers. |
51 | * | ||
52 | * irq_list=i,j,... | ||
53 | * This list limits the set of interrupts that can be used by PCMCIA | ||
54 | * cards. | ||
55 | * The default list is 3,4,5,7,9,10,11. | ||
56 | * (irq_list parameter is not used, if irq_mode = 1) | ||
57 | */ | 51 | */ |
58 | 52 | ||
59 | static int irq_mode = 1; /* 0 = ISA interrupt, 1 = PCI interrupt */ | 53 | static int irq_mode = 1; /* 0 = ISA interrupt, 1 = PCI interrupt */ |
60 | static int irq_list[16]; | ||
61 | static unsigned int irq_list_count = 0; | ||
62 | 54 | ||
63 | module_param(irq_mode, int, 0444); | 55 | module_param(irq_mode, int, 0444); |
64 | module_param_array(irq_list, int, &irq_list_count, 0444); | ||
65 | MODULE_PARM_DESC(irq_mode, | 56 | MODULE_PARM_DESC(irq_mode, |
66 | "interrupt delivery mode. 0 = ISA, 1 = PCI. default is 1"); | 57 | "interrupt delivery mode. 0 = ISA, 1 = PCI. default is 1"); |
67 | MODULE_PARM_DESC(irq_list, "interrupts that can be used by PCMCIA cards"); | ||
68 | 58 | ||
69 | static DEFINE_SPINLOCK(port_lock); | 59 | static DEFINE_SPINLOCK(port_lock); |
70 | 60 | ||
@@ -605,13 +595,7 @@ static u_int __devinit pd6729_isa_scan(void) | |||
605 | return 0; | 595 | return 0; |
606 | } | 596 | } |
607 | 597 | ||
608 | if (irq_list_count == 0) | 598 | mask0 = PD67_MASK; |
609 | mask0 = 0xffff; | ||
610 | else | ||
611 | for (i = mask0 = 0; i < irq_list_count; i++) | ||
612 | mask0 |= (1<<irq_list[i]); | ||
613 | |||
614 | mask0 &= PD67_MASK; | ||
615 | 599 | ||
616 | /* just find interrupts that aren't in use */ | 600 | /* just find interrupts that aren't in use */ |
617 | for (i = 0; i < 16; i++) | 601 | for (i = 0; i < 16; i++) |
diff --git a/drivers/pcmcia/rsrc_mgr.c b/drivers/pcmcia/rsrc_mgr.c index 52db17263d8b..452c83b512c4 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,32 +66,32 @@ 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 | } | ||
134 | } | 84 | } |
135 | #endif | 85 | #endif |
136 | 86 | ||
137 | #ifdef CONFIG_M68K | 87 | #ifdef CONFIG_M68K |
138 | if (res->flags & IORESOURCE_IO) { | 88 | if (res->flags & IORESOURCE_IO) { |
139 | if ((res->start + size - 1) >= 1024) | 89 | if ((res->start + size - 1) >= 1024) |
140 | res->start = res->end; | 90 | start = res->end; |
141 | } | 91 | } |
142 | #endif | 92 | #endif |
93 | |||
94 | return start; | ||
143 | } | 95 | } |
144 | 96 | ||
145 | 97 | ||
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..f9009d34254b --- /dev/null +++ b/drivers/pcmcia/xxs1500_ss.c | |||
@@ -0,0 +1,340 @@ | |||
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 | /* 36bit PCMCIA Attribute area address */ | ||
222 | r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pcmcia-attr"); | ||
223 | if (!r) { | ||
224 | dev_err(&pdev->dev, "missing 'pcmcia-attr' resource!\n"); | ||
225 | goto out0; | ||
226 | } | ||
227 | sock->phys_attr = r->start; | ||
228 | |||
229 | /* 36bit PCMCIA Memory area address */ | ||
230 | r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pcmcia-mem"); | ||
231 | if (!r) { | ||
232 | dev_err(&pdev->dev, "missing 'pcmcia-mem' resource!\n"); | ||
233 | goto out0; | ||
234 | } | ||
235 | sock->phys_mem = r->start; | ||
236 | |||
237 | /* 36bit PCMCIA IO area address */ | ||
238 | r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pcmcia-io"); | ||
239 | if (!r) { | ||
240 | dev_err(&pdev->dev, "missing 'pcmcia-io' resource!\n"); | ||
241 | goto out0; | ||
242 | } | ||
243 | sock->phys_io = r->start; | ||
244 | |||
245 | |||
246 | /* | ||
247 | * PCMCIA client drivers use the inb/outb macros to access | ||
248 | * the IO registers. Since mips_io_port_base is added | ||
249 | * to the access address of the mips implementation of | ||
250 | * inb/outb, we need to subtract it here because we want | ||
251 | * to access the I/O or MEM address directly, without | ||
252 | * going through this "mips_io_port_base" mechanism. | ||
253 | */ | ||
254 | sock->virt_io = (void *)(ioremap(sock->phys_io, IO_MAP_SIZE) - | ||
255 | mips_io_port_base); | ||
256 | |||
257 | if (!sock->virt_io) { | ||
258 | dev_err(&pdev->dev, "cannot remap IO area\n"); | ||
259 | ret = -ENOMEM; | ||
260 | goto out0; | ||
261 | } | ||
262 | |||
263 | sock->socket.ops = &xxs1500_pcmcia_operations; | ||
264 | sock->socket.owner = THIS_MODULE; | ||
265 | sock->socket.pci_irq = gpio_to_irq(GPIO_CARDIRQ); | ||
266 | sock->socket.features = SS_CAP_STATIC_MAP | SS_CAP_PCCARD; | ||
267 | sock->socket.map_size = MEM_MAP_SIZE; | ||
268 | sock->socket.io_offset = (unsigned long)sock->virt_io; | ||
269 | sock->socket.dev.parent = &pdev->dev; | ||
270 | sock->socket.resource_ops = &pccard_static_ops; | ||
271 | |||
272 | platform_set_drvdata(pdev, sock); | ||
273 | |||
274 | /* setup carddetect irq: use one of the 2 GPIOs as an | ||
275 | * edge detector. | ||
276 | */ | ||
277 | irq = gpio_to_irq(GPIO_CDA); | ||
278 | set_irq_type(irq, IRQ_TYPE_EDGE_BOTH); | ||
279 | ret = request_irq(irq, cdirq, 0, "pcmcia_carddetect", sock); | ||
280 | if (ret) { | ||
281 | dev_err(&pdev->dev, "cannot setup cd irq\n"); | ||
282 | goto out1; | ||
283 | } | ||
284 | |||
285 | ret = pcmcia_register_socket(&sock->socket); | ||
286 | if (ret) { | ||
287 | dev_err(&pdev->dev, "failed to register\n"); | ||
288 | goto out2; | ||
289 | } | ||
290 | |||
291 | printk(KERN_INFO "MyCable XXS1500 PCMCIA socket services\n"); | ||
292 | |||
293 | return 0; | ||
294 | |||
295 | out2: | ||
296 | free_irq(gpio_to_irq(GPIO_CDA), sock); | ||
297 | out1: | ||
298 | iounmap((void *)(sock->virt_io + (u32)mips_io_port_base)); | ||
299 | out0: | ||
300 | kfree(sock); | ||
301 | return ret; | ||
302 | } | ||
303 | |||
304 | static int __devexit xxs1500_pcmcia_remove(struct platform_device *pdev) | ||
305 | { | ||
306 | struct xxs1500_pcmcia_sock *sock = platform_get_drvdata(pdev); | ||
307 | |||
308 | pcmcia_unregister_socket(&sock->socket); | ||
309 | free_irq(gpio_to_irq(GPIO_CDA), sock); | ||
310 | iounmap((void *)(sock->virt_io + (u32)mips_io_port_base)); | ||
311 | kfree(sock); | ||
312 | |||
313 | return 0; | ||
314 | } | ||
315 | |||
316 | static struct platform_driver xxs1500_pcmcia_socket_driver = { | ||
317 | .driver = { | ||
318 | .name = "xxs1500_pcmcia", | ||
319 | .owner = THIS_MODULE, | ||
320 | }, | ||
321 | .probe = xxs1500_pcmcia_probe, | ||
322 | .remove = __devexit_p(xxs1500_pcmcia_remove), | ||
323 | }; | ||
324 | |||
325 | int __init xxs1500_pcmcia_socket_load(void) | ||
326 | { | ||
327 | return platform_driver_register(&xxs1500_pcmcia_socket_driver); | ||
328 | } | ||
329 | |||
330 | void __exit xxs1500_pcmcia_socket_unload(void) | ||
331 | { | ||
332 | platform_driver_unregister(&xxs1500_pcmcia_socket_driver); | ||
333 | } | ||
334 | |||
335 | module_init(xxs1500_pcmcia_socket_load); | ||
336 | module_exit(xxs1500_pcmcia_socket_unload); | ||
337 | |||
338 | MODULE_LICENSE("GPL"); | ||
339 | MODULE_DESCRIPTION("PCMCIA Socket Services for MyCable XXS1500 systems"); | ||
340 | MODULE_AUTHOR("Manuel Lauss"); | ||
diff --git a/drivers/pcmcia/yenta_socket.c b/drivers/pcmcia/yenta_socket.c index e4d12acdd525..967c766f53ba 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 | ||
@@ -1402,10 +1408,10 @@ static struct pci_device_id yenta_table[] = { | |||
1402 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_7510, TI12XX), | 1408 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_7510, TI12XX), |
1403 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_7610, TI12XX), | 1409 | CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_7610, TI12XX), |
1404 | 1410 | ||
1405 | CB_ID(PCI_VENDOR_ID_ENE, PCI_DEVICE_ID_ENE_710, TI12XX), | 1411 | CB_ID(PCI_VENDOR_ID_ENE, PCI_DEVICE_ID_ENE_710, ENE), |
1406 | CB_ID(PCI_VENDOR_ID_ENE, PCI_DEVICE_ID_ENE_712, TI12XX), | 1412 | CB_ID(PCI_VENDOR_ID_ENE, PCI_DEVICE_ID_ENE_712, ENE), |
1407 | CB_ID(PCI_VENDOR_ID_ENE, PCI_DEVICE_ID_ENE_720, TI12XX), | 1413 | CB_ID(PCI_VENDOR_ID_ENE, PCI_DEVICE_ID_ENE_720, ENE), |
1408 | CB_ID(PCI_VENDOR_ID_ENE, PCI_DEVICE_ID_ENE_722, TI12XX), | 1414 | CB_ID(PCI_VENDOR_ID_ENE, PCI_DEVICE_ID_ENE_722, ENE), |
1409 | CB_ID(PCI_VENDOR_ID_ENE, PCI_DEVICE_ID_ENE_1211, ENE), | 1415 | CB_ID(PCI_VENDOR_ID_ENE, PCI_DEVICE_ID_ENE_1211, ENE), |
1410 | CB_ID(PCI_VENDOR_ID_ENE, PCI_DEVICE_ID_ENE_1225, ENE), | 1416 | CB_ID(PCI_VENDOR_ID_ENE, PCI_DEVICE_ID_ENE_1225, ENE), |
1411 | CB_ID(PCI_VENDOR_ID_ENE, PCI_DEVICE_ID_ENE_1410, ENE), | 1417 | CB_ID(PCI_VENDOR_ID_ENE, PCI_DEVICE_ID_ENE_1410, ENE), |